rs690.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <drm/drmP.h>
  29. #include "radeon.h"
  30. #include "radeon_asic.h"
  31. #include "atom.h"
  32. #include "rs690d.h"
  33. int rs690_mc_wait_for_idle(struct radeon_device *rdev)
  34. {
  35. unsigned i;
  36. uint32_t tmp;
  37. for (i = 0; i < rdev->usec_timeout; i++) {
  38. /* read MC_STATUS */
  39. tmp = RREG32_MC(R_000090_MC_SYSTEM_STATUS);
  40. if (G_000090_MC_SYSTEM_IDLE(tmp))
  41. return 0;
  42. udelay(1);
  43. }
  44. return -1;
  45. }
  46. static void rs690_gpu_init(struct radeon_device *rdev)
  47. {
  48. /* FIXME: is this correct ? */
  49. r420_pipes_init(rdev);
  50. if (rs690_mc_wait_for_idle(rdev)) {
  51. printk(KERN_WARNING "Failed to wait MC idle while "
  52. "programming pipes. Bad things might happen.\n");
  53. }
  54. }
  55. union igp_info {
  56. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  57. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_v2;
  58. };
  59. void rs690_pm_info(struct radeon_device *rdev)
  60. {
  61. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  62. union igp_info *info;
  63. uint16_t data_offset;
  64. uint8_t frev, crev;
  65. fixed20_12 tmp;
  66. if (atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
  67. &frev, &crev, &data_offset)) {
  68. info = (union igp_info *)(rdev->mode_info.atom_context->bios + data_offset);
  69. /* Get various system informations from bios */
  70. switch (crev) {
  71. case 1:
  72. tmp.full = dfixed_const(100);
  73. rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info.ulBootUpMemoryClock));
  74. rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  75. if (le16_to_cpu(info->info.usK8MemoryClock))
  76. rdev->pm.igp_system_mclk.full = dfixed_const(le16_to_cpu(info->info.usK8MemoryClock));
  77. else if (rdev->clock.default_mclk) {
  78. rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
  79. rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
  80. } else
  81. rdev->pm.igp_system_mclk.full = dfixed_const(400);
  82. rdev->pm.igp_ht_link_clk.full = dfixed_const(le16_to_cpu(info->info.usFSBClock));
  83. rdev->pm.igp_ht_link_width.full = dfixed_const(info->info.ucHTLinkWidth);
  84. break;
  85. case 2:
  86. tmp.full = dfixed_const(100);
  87. rdev->pm.igp_sideport_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpSidePortClock));
  88. rdev->pm.igp_sideport_mclk.full = dfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  89. if (le32_to_cpu(info->info_v2.ulBootUpUMAClock))
  90. rdev->pm.igp_system_mclk.full = dfixed_const(le32_to_cpu(info->info_v2.ulBootUpUMAClock));
  91. else if (rdev->clock.default_mclk)
  92. rdev->pm.igp_system_mclk.full = dfixed_const(rdev->clock.default_mclk);
  93. else
  94. rdev->pm.igp_system_mclk.full = dfixed_const(66700);
  95. rdev->pm.igp_system_mclk.full = dfixed_div(rdev->pm.igp_system_mclk, tmp);
  96. rdev->pm.igp_ht_link_clk.full = dfixed_const(le32_to_cpu(info->info_v2.ulHTLinkFreq));
  97. rdev->pm.igp_ht_link_clk.full = dfixed_div(rdev->pm.igp_ht_link_clk, tmp);
  98. rdev->pm.igp_ht_link_width.full = dfixed_const(le16_to_cpu(info->info_v2.usMinHTLinkWidth));
  99. break;
  100. default:
  101. /* We assume the slower possible clock ie worst case */
  102. rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
  103. rdev->pm.igp_system_mclk.full = dfixed_const(200);
  104. rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
  105. rdev->pm.igp_ht_link_width.full = dfixed_const(8);
  106. DRM_ERROR("No integrated system info for your GPU, using safe default\n");
  107. break;
  108. }
  109. } else {
  110. /* We assume the slower possible clock ie worst case */
  111. rdev->pm.igp_sideport_mclk.full = dfixed_const(200);
  112. rdev->pm.igp_system_mclk.full = dfixed_const(200);
  113. rdev->pm.igp_ht_link_clk.full = dfixed_const(1000);
  114. rdev->pm.igp_ht_link_width.full = dfixed_const(8);
  115. DRM_ERROR("No integrated system info for your GPU, using safe default\n");
  116. }
  117. /* Compute various bandwidth */
  118. /* k8_bandwidth = (memory_clk / 2) * 2 * 8 * 0.5 = memory_clk * 4 */
  119. tmp.full = dfixed_const(4);
  120. rdev->pm.k8_bandwidth.full = dfixed_mul(rdev->pm.igp_system_mclk, tmp);
  121. /* ht_bandwidth = ht_clk * 2 * ht_width / 8 * 0.8
  122. * = ht_clk * ht_width / 5
  123. */
  124. tmp.full = dfixed_const(5);
  125. rdev->pm.ht_bandwidth.full = dfixed_mul(rdev->pm.igp_ht_link_clk,
  126. rdev->pm.igp_ht_link_width);
  127. rdev->pm.ht_bandwidth.full = dfixed_div(rdev->pm.ht_bandwidth, tmp);
  128. if (tmp.full < rdev->pm.max_bandwidth.full) {
  129. /* HT link is a limiting factor */
  130. rdev->pm.max_bandwidth.full = tmp.full;
  131. }
  132. /* sideport_bandwidth = (sideport_clk / 2) * 2 * 2 * 0.7
  133. * = (sideport_clk * 14) / 10
  134. */
  135. tmp.full = dfixed_const(14);
  136. rdev->pm.sideport_bandwidth.full = dfixed_mul(rdev->pm.igp_sideport_mclk, tmp);
  137. tmp.full = dfixed_const(10);
  138. rdev->pm.sideport_bandwidth.full = dfixed_div(rdev->pm.sideport_bandwidth, tmp);
  139. }
  140. static void rs690_mc_init(struct radeon_device *rdev)
  141. {
  142. u64 base;
  143. uint32_t h_addr, l_addr;
  144. unsigned long long k8_addr;
  145. rs400_gart_adjust_size(rdev);
  146. rdev->mc.vram_is_ddr = true;
  147. rdev->mc.vram_width = 128;
  148. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  149. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  150. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  151. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  152. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  153. base = RREG32_MC(R_000100_MCCFG_FB_LOCATION);
  154. base = G_000100_MC_FB_START(base) << 16;
  155. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  156. /* Use K8 direct mapping for fast fb access. */
  157. rdev->fastfb_working = false;
  158. h_addr = G_00005F_K8_ADDR_EXT(RREG32_MC(R_00005F_MC_MISC_UMA_CNTL));
  159. l_addr = RREG32_MC(R_00001E_K8_FB_LOCATION);
  160. k8_addr = ((unsigned long long)h_addr) << 32 | l_addr;
  161. #if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
  162. if (k8_addr + rdev->mc.visible_vram_size < 0x100000000ULL)
  163. #endif
  164. {
  165. /* FastFB shall be used with UMA memory. Here it is simply disabled when sideport
  166. * memory is present.
  167. */
  168. if (rdev->mc.igp_sideport_enabled == false && radeon_fastfb == 1) {
  169. DRM_INFO("Direct mapping: aper base at 0x%llx, replaced by direct mapping base 0x%llx.\n",
  170. (unsigned long long)rdev->mc.aper_base, k8_addr);
  171. rdev->mc.aper_base = (resource_size_t)k8_addr;
  172. rdev->fastfb_working = true;
  173. }
  174. }
  175. rs690_pm_info(rdev);
  176. radeon_vram_location(rdev, &rdev->mc, base);
  177. rdev->mc.gtt_base_align = rdev->mc.gtt_size - 1;
  178. radeon_gtt_location(rdev, &rdev->mc);
  179. radeon_update_bandwidth_info(rdev);
  180. }
  181. void rs690_line_buffer_adjust(struct radeon_device *rdev,
  182. struct drm_display_mode *mode1,
  183. struct drm_display_mode *mode2)
  184. {
  185. u32 tmp;
  186. /*
  187. * Line Buffer Setup
  188. * There is a single line buffer shared by both display controllers.
  189. * R_006520_DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  190. * the display controllers. The paritioning can either be done
  191. * manually or via one of four preset allocations specified in bits 1:0:
  192. * 0 - line buffer is divided in half and shared between crtc
  193. * 1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
  194. * 2 - D1 gets the whole buffer
  195. * 3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
  196. * Setting bit 2 of R_006520_DC_LB_MEMORY_SPLIT controls switches to manual
  197. * allocation mode. In manual allocation mode, D1 always starts at 0,
  198. * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
  199. */
  200. tmp = RREG32(R_006520_DC_LB_MEMORY_SPLIT) & C_006520_DC_LB_MEMORY_SPLIT;
  201. tmp &= ~C_006520_DC_LB_MEMORY_SPLIT_MODE;
  202. /* auto */
  203. if (mode1 && mode2) {
  204. if (mode1->hdisplay > mode2->hdisplay) {
  205. if (mode1->hdisplay > 2560)
  206. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
  207. else
  208. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  209. } else if (mode2->hdisplay > mode1->hdisplay) {
  210. if (mode2->hdisplay > 2560)
  211. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  212. else
  213. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  214. } else
  215. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  216. } else if (mode1) {
  217. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_ONLY;
  218. } else if (mode2) {
  219. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  220. }
  221. WREG32(R_006520_DC_LB_MEMORY_SPLIT, tmp);
  222. }
  223. struct rs690_watermark {
  224. u32 lb_request_fifo_depth;
  225. fixed20_12 num_line_pair;
  226. fixed20_12 estimated_width;
  227. fixed20_12 worst_case_latency;
  228. fixed20_12 consumption_rate;
  229. fixed20_12 active_time;
  230. fixed20_12 dbpp;
  231. fixed20_12 priority_mark_max;
  232. fixed20_12 priority_mark;
  233. fixed20_12 sclk;
  234. };
  235. static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
  236. struct radeon_crtc *crtc,
  237. struct rs690_watermark *wm,
  238. bool low)
  239. {
  240. struct drm_display_mode *mode = &crtc->base.mode;
  241. fixed20_12 a, b, c;
  242. fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
  243. fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
  244. fixed20_12 sclk, core_bandwidth, max_bandwidth;
  245. u32 selected_sclk;
  246. if (!crtc->base.enabled) {
  247. /* FIXME: wouldn't it better to set priority mark to maximum */
  248. wm->lb_request_fifo_depth = 4;
  249. return;
  250. }
  251. if (((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880)) &&
  252. (rdev->pm.pm_method == PM_METHOD_DPM) && rdev->pm.dpm_enabled)
  253. selected_sclk = radeon_dpm_get_sclk(rdev, low);
  254. else
  255. selected_sclk = rdev->pm.current_sclk;
  256. /* sclk in Mhz */
  257. a.full = dfixed_const(100);
  258. sclk.full = dfixed_const(selected_sclk);
  259. sclk.full = dfixed_div(sclk, a);
  260. /* core_bandwidth = sclk(Mhz) * 16 */
  261. a.full = dfixed_const(16);
  262. core_bandwidth.full = dfixed_div(rdev->pm.sclk, a);
  263. if (crtc->vsc.full > dfixed_const(2))
  264. wm->num_line_pair.full = dfixed_const(2);
  265. else
  266. wm->num_line_pair.full = dfixed_const(1);
  267. b.full = dfixed_const(mode->crtc_hdisplay);
  268. c.full = dfixed_const(256);
  269. a.full = dfixed_div(b, c);
  270. request_fifo_depth.full = dfixed_mul(a, wm->num_line_pair);
  271. request_fifo_depth.full = dfixed_ceil(request_fifo_depth);
  272. if (a.full < dfixed_const(4)) {
  273. wm->lb_request_fifo_depth = 4;
  274. } else {
  275. wm->lb_request_fifo_depth = dfixed_trunc(request_fifo_depth);
  276. }
  277. /* Determine consumption rate
  278. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  279. * vtaps = number of vertical taps,
  280. * vsc = vertical scaling ratio, defined as source/destination
  281. * hsc = horizontal scaling ration, defined as source/destination
  282. */
  283. a.full = dfixed_const(mode->clock);
  284. b.full = dfixed_const(1000);
  285. a.full = dfixed_div(a, b);
  286. pclk.full = dfixed_div(b, a);
  287. if (crtc->rmx_type != RMX_OFF) {
  288. b.full = dfixed_const(2);
  289. if (crtc->vsc.full > b.full)
  290. b.full = crtc->vsc.full;
  291. b.full = dfixed_mul(b, crtc->hsc);
  292. c.full = dfixed_const(2);
  293. b.full = dfixed_div(b, c);
  294. consumption_time.full = dfixed_div(pclk, b);
  295. } else {
  296. consumption_time.full = pclk.full;
  297. }
  298. a.full = dfixed_const(1);
  299. wm->consumption_rate.full = dfixed_div(a, consumption_time);
  300. /* Determine line time
  301. * LineTime = total time for one line of displayhtotal
  302. * LineTime = total number of horizontal pixels
  303. * pclk = pixel clock period(ns)
  304. */
  305. a.full = dfixed_const(crtc->base.mode.crtc_htotal);
  306. line_time.full = dfixed_mul(a, pclk);
  307. /* Determine active time
  308. * ActiveTime = time of active region of display within one line,
  309. * hactive = total number of horizontal active pixels
  310. * htotal = total number of horizontal pixels
  311. */
  312. a.full = dfixed_const(crtc->base.mode.crtc_htotal);
  313. b.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
  314. wm->active_time.full = dfixed_mul(line_time, b);
  315. wm->active_time.full = dfixed_div(wm->active_time, a);
  316. /* Maximun bandwidth is the minimun bandwidth of all component */
  317. max_bandwidth = core_bandwidth;
  318. if (rdev->mc.igp_sideport_enabled) {
  319. if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
  320. rdev->pm.sideport_bandwidth.full)
  321. max_bandwidth = rdev->pm.sideport_bandwidth;
  322. read_delay_latency.full = dfixed_const(370 * 800);
  323. a.full = dfixed_const(1000);
  324. b.full = dfixed_div(rdev->pm.igp_sideport_mclk, a);
  325. read_delay_latency.full = dfixed_div(read_delay_latency, b);
  326. read_delay_latency.full = dfixed_mul(read_delay_latency, a);
  327. } else {
  328. if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
  329. rdev->pm.k8_bandwidth.full)
  330. max_bandwidth = rdev->pm.k8_bandwidth;
  331. if (max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
  332. rdev->pm.ht_bandwidth.full)
  333. max_bandwidth = rdev->pm.ht_bandwidth;
  334. read_delay_latency.full = dfixed_const(5000);
  335. }
  336. /* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
  337. a.full = dfixed_const(16);
  338. sclk.full = dfixed_mul(max_bandwidth, a);
  339. a.full = dfixed_const(1000);
  340. sclk.full = dfixed_div(a, sclk);
  341. /* Determine chunk time
  342. * ChunkTime = the time it takes the DCP to send one chunk of data
  343. * to the LB which consists of pipeline delay and inter chunk gap
  344. * sclk = system clock(ns)
  345. */
  346. a.full = dfixed_const(256 * 13);
  347. chunk_time.full = dfixed_mul(sclk, a);
  348. a.full = dfixed_const(10);
  349. chunk_time.full = dfixed_div(chunk_time, a);
  350. /* Determine the worst case latency
  351. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  352. * WorstCaseLatency = worst case time from urgent to when the MC starts
  353. * to return data
  354. * READ_DELAY_IDLE_MAX = constant of 1us
  355. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  356. * which consists of pipeline delay and inter chunk gap
  357. */
  358. if (dfixed_trunc(wm->num_line_pair) > 1) {
  359. a.full = dfixed_const(3);
  360. wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
  361. wm->worst_case_latency.full += read_delay_latency.full;
  362. } else {
  363. a.full = dfixed_const(2);
  364. wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
  365. wm->worst_case_latency.full += read_delay_latency.full;
  366. }
  367. /* Determine the tolerable latency
  368. * TolerableLatency = Any given request has only 1 line time
  369. * for the data to be returned
  370. * LBRequestFifoDepth = Number of chunk requests the LB can
  371. * put into the request FIFO for a display
  372. * LineTime = total time for one line of display
  373. * ChunkTime = the time it takes the DCP to send one chunk
  374. * of data to the LB which consists of
  375. * pipeline delay and inter chunk gap
  376. */
  377. if ((2+wm->lb_request_fifo_depth) >= dfixed_trunc(request_fifo_depth)) {
  378. tolerable_latency.full = line_time.full;
  379. } else {
  380. tolerable_latency.full = dfixed_const(wm->lb_request_fifo_depth - 2);
  381. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  382. tolerable_latency.full = dfixed_mul(tolerable_latency, chunk_time);
  383. tolerable_latency.full = line_time.full - tolerable_latency.full;
  384. }
  385. /* We assume worst case 32bits (4 bytes) */
  386. wm->dbpp.full = dfixed_const(4 * 8);
  387. /* Determine the maximum priority mark
  388. * width = viewport width in pixels
  389. */
  390. a.full = dfixed_const(16);
  391. wm->priority_mark_max.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
  392. wm->priority_mark_max.full = dfixed_div(wm->priority_mark_max, a);
  393. wm->priority_mark_max.full = dfixed_ceil(wm->priority_mark_max);
  394. /* Determine estimated width */
  395. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  396. estimated_width.full = dfixed_div(estimated_width, consumption_time);
  397. if (dfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  398. wm->priority_mark.full = dfixed_const(10);
  399. } else {
  400. a.full = dfixed_const(16);
  401. wm->priority_mark.full = dfixed_div(estimated_width, a);
  402. wm->priority_mark.full = dfixed_ceil(wm->priority_mark);
  403. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  404. }
  405. }
  406. static void rs690_compute_mode_priority(struct radeon_device *rdev,
  407. struct rs690_watermark *wm0,
  408. struct rs690_watermark *wm1,
  409. struct drm_display_mode *mode0,
  410. struct drm_display_mode *mode1,
  411. u32 *d1mode_priority_a_cnt,
  412. u32 *d2mode_priority_a_cnt)
  413. {
  414. fixed20_12 priority_mark02, priority_mark12, fill_rate;
  415. fixed20_12 a, b;
  416. *d1mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
  417. *d2mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
  418. if (mode0 && mode1) {
  419. if (dfixed_trunc(wm0->dbpp) > 64)
  420. a.full = dfixed_mul(wm0->dbpp, wm0->num_line_pair);
  421. else
  422. a.full = wm0->num_line_pair.full;
  423. if (dfixed_trunc(wm1->dbpp) > 64)
  424. b.full = dfixed_mul(wm1->dbpp, wm1->num_line_pair);
  425. else
  426. b.full = wm1->num_line_pair.full;
  427. a.full += b.full;
  428. fill_rate.full = dfixed_div(wm0->sclk, a);
  429. if (wm0->consumption_rate.full > fill_rate.full) {
  430. b.full = wm0->consumption_rate.full - fill_rate.full;
  431. b.full = dfixed_mul(b, wm0->active_time);
  432. a.full = dfixed_mul(wm0->worst_case_latency,
  433. wm0->consumption_rate);
  434. a.full = a.full + b.full;
  435. b.full = dfixed_const(16 * 1000);
  436. priority_mark02.full = dfixed_div(a, b);
  437. } else {
  438. a.full = dfixed_mul(wm0->worst_case_latency,
  439. wm0->consumption_rate);
  440. b.full = dfixed_const(16 * 1000);
  441. priority_mark02.full = dfixed_div(a, b);
  442. }
  443. if (wm1->consumption_rate.full > fill_rate.full) {
  444. b.full = wm1->consumption_rate.full - fill_rate.full;
  445. b.full = dfixed_mul(b, wm1->active_time);
  446. a.full = dfixed_mul(wm1->worst_case_latency,
  447. wm1->consumption_rate);
  448. a.full = a.full + b.full;
  449. b.full = dfixed_const(16 * 1000);
  450. priority_mark12.full = dfixed_div(a, b);
  451. } else {
  452. a.full = dfixed_mul(wm1->worst_case_latency,
  453. wm1->consumption_rate);
  454. b.full = dfixed_const(16 * 1000);
  455. priority_mark12.full = dfixed_div(a, b);
  456. }
  457. if (wm0->priority_mark.full > priority_mark02.full)
  458. priority_mark02.full = wm0->priority_mark.full;
  459. if (wm0->priority_mark_max.full > priority_mark02.full)
  460. priority_mark02.full = wm0->priority_mark_max.full;
  461. if (wm1->priority_mark.full > priority_mark12.full)
  462. priority_mark12.full = wm1->priority_mark.full;
  463. if (wm1->priority_mark_max.full > priority_mark12.full)
  464. priority_mark12.full = wm1->priority_mark_max.full;
  465. *d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
  466. *d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
  467. if (rdev->disp_priority == 2) {
  468. *d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
  469. *d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
  470. }
  471. } else if (mode0) {
  472. if (dfixed_trunc(wm0->dbpp) > 64)
  473. a.full = dfixed_mul(wm0->dbpp, wm0->num_line_pair);
  474. else
  475. a.full = wm0->num_line_pair.full;
  476. fill_rate.full = dfixed_div(wm0->sclk, a);
  477. if (wm0->consumption_rate.full > fill_rate.full) {
  478. b.full = wm0->consumption_rate.full - fill_rate.full;
  479. b.full = dfixed_mul(b, wm0->active_time);
  480. a.full = dfixed_mul(wm0->worst_case_latency,
  481. wm0->consumption_rate);
  482. a.full = a.full + b.full;
  483. b.full = dfixed_const(16 * 1000);
  484. priority_mark02.full = dfixed_div(a, b);
  485. } else {
  486. a.full = dfixed_mul(wm0->worst_case_latency,
  487. wm0->consumption_rate);
  488. b.full = dfixed_const(16 * 1000);
  489. priority_mark02.full = dfixed_div(a, b);
  490. }
  491. if (wm0->priority_mark.full > priority_mark02.full)
  492. priority_mark02.full = wm0->priority_mark.full;
  493. if (wm0->priority_mark_max.full > priority_mark02.full)
  494. priority_mark02.full = wm0->priority_mark_max.full;
  495. *d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
  496. if (rdev->disp_priority == 2)
  497. *d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
  498. } else if (mode1) {
  499. if (dfixed_trunc(wm1->dbpp) > 64)
  500. a.full = dfixed_mul(wm1->dbpp, wm1->num_line_pair);
  501. else
  502. a.full = wm1->num_line_pair.full;
  503. fill_rate.full = dfixed_div(wm1->sclk, a);
  504. if (wm1->consumption_rate.full > fill_rate.full) {
  505. b.full = wm1->consumption_rate.full - fill_rate.full;
  506. b.full = dfixed_mul(b, wm1->active_time);
  507. a.full = dfixed_mul(wm1->worst_case_latency,
  508. wm1->consumption_rate);
  509. a.full = a.full + b.full;
  510. b.full = dfixed_const(16 * 1000);
  511. priority_mark12.full = dfixed_div(a, b);
  512. } else {
  513. a.full = dfixed_mul(wm1->worst_case_latency,
  514. wm1->consumption_rate);
  515. b.full = dfixed_const(16 * 1000);
  516. priority_mark12.full = dfixed_div(a, b);
  517. }
  518. if (wm1->priority_mark.full > priority_mark12.full)
  519. priority_mark12.full = wm1->priority_mark.full;
  520. if (wm1->priority_mark_max.full > priority_mark12.full)
  521. priority_mark12.full = wm1->priority_mark_max.full;
  522. *d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
  523. if (rdev->disp_priority == 2)
  524. *d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
  525. }
  526. }
  527. void rs690_bandwidth_update(struct radeon_device *rdev)
  528. {
  529. struct drm_display_mode *mode0 = NULL;
  530. struct drm_display_mode *mode1 = NULL;
  531. struct rs690_watermark wm0_high, wm0_low;
  532. struct rs690_watermark wm1_high, wm1_low;
  533. u32 tmp;
  534. u32 d1mode_priority_a_cnt, d1mode_priority_b_cnt;
  535. u32 d2mode_priority_a_cnt, d2mode_priority_b_cnt;
  536. radeon_update_display_priority(rdev);
  537. if (rdev->mode_info.crtcs[0]->base.enabled)
  538. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  539. if (rdev->mode_info.crtcs[1]->base.enabled)
  540. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  541. /*
  542. * Set display0/1 priority up in the memory controller for
  543. * modes if the user specifies HIGH for displaypriority
  544. * option.
  545. */
  546. if ((rdev->disp_priority == 2) &&
  547. ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))) {
  548. tmp = RREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER);
  549. tmp &= C_000104_MC_DISP0R_INIT_LAT;
  550. tmp &= C_000104_MC_DISP1R_INIT_LAT;
  551. if (mode0)
  552. tmp |= S_000104_MC_DISP0R_INIT_LAT(1);
  553. if (mode1)
  554. tmp |= S_000104_MC_DISP1R_INIT_LAT(1);
  555. WREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER, tmp);
  556. }
  557. rs690_line_buffer_adjust(rdev, mode0, mode1);
  558. if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
  559. WREG32(R_006C9C_DCP_CONTROL, 0);
  560. if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
  561. WREG32(R_006C9C_DCP_CONTROL, 2);
  562. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0_high, false);
  563. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1_high, false);
  564. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0_low, true);
  565. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1_low, true);
  566. tmp = (wm0_high.lb_request_fifo_depth - 1);
  567. tmp |= (wm1_high.lb_request_fifo_depth - 1) << 16;
  568. WREG32(R_006D58_LB_MAX_REQ_OUTSTANDING, tmp);
  569. rs690_compute_mode_priority(rdev,
  570. &wm0_high, &wm1_high,
  571. mode0, mode1,
  572. &d1mode_priority_a_cnt, &d2mode_priority_a_cnt);
  573. rs690_compute_mode_priority(rdev,
  574. &wm0_low, &wm1_low,
  575. mode0, mode1,
  576. &d1mode_priority_b_cnt, &d2mode_priority_b_cnt);
  577. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
  578. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_b_cnt);
  579. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
  580. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_b_cnt);
  581. }
  582. uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  583. {
  584. unsigned long flags;
  585. uint32_t r;
  586. spin_lock_irqsave(&rdev->mc_idx_lock, flags);
  587. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
  588. r = RREG32(R_00007C_MC_DATA);
  589. WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
  590. spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
  591. return r;
  592. }
  593. void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  594. {
  595. unsigned long flags;
  596. spin_lock_irqsave(&rdev->mc_idx_lock, flags);
  597. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
  598. S_000078_MC_IND_WR_EN(1));
  599. WREG32(R_00007C_MC_DATA, v);
  600. WREG32(R_000078_MC_INDEX, 0x7F);
  601. spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
  602. }
  603. static void rs690_mc_program(struct radeon_device *rdev)
  604. {
  605. struct rv515_mc_save save;
  606. /* Stops all mc clients */
  607. rv515_mc_stop(rdev, &save);
  608. /* Wait for mc idle */
  609. if (rs690_mc_wait_for_idle(rdev))
  610. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  611. /* Program MC, should be a 32bits limited address space */
  612. WREG32_MC(R_000100_MCCFG_FB_LOCATION,
  613. S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
  614. S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
  615. WREG32(R_000134_HDP_FB_LOCATION,
  616. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  617. rv515_mc_resume(rdev, &save);
  618. }
  619. static int rs690_startup(struct radeon_device *rdev)
  620. {
  621. int r;
  622. rs690_mc_program(rdev);
  623. /* Resume clock */
  624. rv515_clock_startup(rdev);
  625. /* Initialize GPU configuration (# pipes, ...) */
  626. rs690_gpu_init(rdev);
  627. /* Initialize GART (initialize after TTM so we can allocate
  628. * memory through TTM but finalize after TTM) */
  629. r = rs400_gart_enable(rdev);
  630. if (r)
  631. return r;
  632. /* allocate wb buffer */
  633. r = radeon_wb_init(rdev);
  634. if (r)
  635. return r;
  636. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  637. if (r) {
  638. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  639. return r;
  640. }
  641. /* Enable IRQ */
  642. if (!rdev->irq.installed) {
  643. r = radeon_irq_kms_init(rdev);
  644. if (r)
  645. return r;
  646. }
  647. rs600_irq_set(rdev);
  648. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  649. /* 1M ring buffer */
  650. r = r100_cp_init(rdev, 1024 * 1024);
  651. if (r) {
  652. dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
  653. return r;
  654. }
  655. r = radeon_ib_pool_init(rdev);
  656. if (r) {
  657. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  658. return r;
  659. }
  660. r = r600_audio_init(rdev);
  661. if (r) {
  662. dev_err(rdev->dev, "failed initializing audio\n");
  663. return r;
  664. }
  665. return 0;
  666. }
  667. int rs690_resume(struct radeon_device *rdev)
  668. {
  669. int r;
  670. /* Make sur GART are not working */
  671. rs400_gart_disable(rdev);
  672. /* Resume clock before doing reset */
  673. rv515_clock_startup(rdev);
  674. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  675. if (radeon_asic_reset(rdev)) {
  676. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  677. RREG32(R_000E40_RBBM_STATUS),
  678. RREG32(R_0007C0_CP_STAT));
  679. }
  680. /* post */
  681. atom_asic_init(rdev->mode_info.atom_context);
  682. /* Resume clock after posting */
  683. rv515_clock_startup(rdev);
  684. /* Initialize surface registers */
  685. radeon_surface_init(rdev);
  686. rdev->accel_working = true;
  687. r = rs690_startup(rdev);
  688. if (r) {
  689. rdev->accel_working = false;
  690. }
  691. return r;
  692. }
  693. int rs690_suspend(struct radeon_device *rdev)
  694. {
  695. r600_audio_fini(rdev);
  696. r100_cp_disable(rdev);
  697. radeon_wb_disable(rdev);
  698. rs600_irq_disable(rdev);
  699. rs400_gart_disable(rdev);
  700. return 0;
  701. }
  702. void rs690_fini(struct radeon_device *rdev)
  703. {
  704. r600_audio_fini(rdev);
  705. r100_cp_fini(rdev);
  706. radeon_wb_fini(rdev);
  707. radeon_ib_pool_fini(rdev);
  708. radeon_gem_fini(rdev);
  709. rs400_gart_fini(rdev);
  710. radeon_irq_kms_fini(rdev);
  711. radeon_fence_driver_fini(rdev);
  712. radeon_bo_fini(rdev);
  713. radeon_atombios_fini(rdev);
  714. kfree(rdev->bios);
  715. rdev->bios = NULL;
  716. }
  717. int rs690_init(struct radeon_device *rdev)
  718. {
  719. int r;
  720. /* Disable VGA */
  721. rv515_vga_render_disable(rdev);
  722. /* Initialize scratch registers */
  723. radeon_scratch_init(rdev);
  724. /* Initialize surface registers */
  725. radeon_surface_init(rdev);
  726. /* restore some register to sane defaults */
  727. r100_restore_sanity(rdev);
  728. /* TODO: disable VGA need to use VGA request */
  729. /* BIOS*/
  730. if (!radeon_get_bios(rdev)) {
  731. if (ASIC_IS_AVIVO(rdev))
  732. return -EINVAL;
  733. }
  734. if (rdev->is_atom_bios) {
  735. r = radeon_atombios_init(rdev);
  736. if (r)
  737. return r;
  738. } else {
  739. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  740. return -EINVAL;
  741. }
  742. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  743. if (radeon_asic_reset(rdev)) {
  744. dev_warn(rdev->dev,
  745. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  746. RREG32(R_000E40_RBBM_STATUS),
  747. RREG32(R_0007C0_CP_STAT));
  748. }
  749. /* check if cards are posted or not */
  750. if (radeon_boot_test_post_card(rdev) == false)
  751. return -EINVAL;
  752. /* Initialize clocks */
  753. radeon_get_clock_info(rdev->ddev);
  754. /* initialize memory controller */
  755. rs690_mc_init(rdev);
  756. rv515_debugfs(rdev);
  757. /* Fence driver */
  758. r = radeon_fence_driver_init(rdev);
  759. if (r)
  760. return r;
  761. /* Memory manager */
  762. r = radeon_bo_init(rdev);
  763. if (r)
  764. return r;
  765. r = rs400_gart_init(rdev);
  766. if (r)
  767. return r;
  768. rs600_set_safe_registers(rdev);
  769. rdev->accel_working = true;
  770. r = rs690_startup(rdev);
  771. if (r) {
  772. /* Somethings want wront with the accel init stop accel */
  773. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  774. r100_cp_fini(rdev);
  775. radeon_wb_fini(rdev);
  776. radeon_ib_pool_fini(rdev);
  777. rs400_gart_fini(rdev);
  778. radeon_irq_kms_fini(rdev);
  779. rdev->accel_working = false;
  780. }
  781. return 0;
  782. }