rs690.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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 "drmP.h"
  29. #include "radeon.h"
  30. #include "radeon_asic.h"
  31. #include "atom.h"
  32. #include "rs690d.h"
  33. static 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: HDP same place on rs690 ? */
  49. r100_hdp_reset(rdev);
  50. /* FIXME: is this correct ? */
  51. r420_pipes_init(rdev);
  52. if (rs690_mc_wait_for_idle(rdev)) {
  53. printk(KERN_WARNING "Failed to wait MC idle while "
  54. "programming pipes. Bad things might happen.\n");
  55. }
  56. }
  57. union igp_info {
  58. struct _ATOM_INTEGRATED_SYSTEM_INFO info;
  59. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 info_v2;
  60. };
  61. void rs690_pm_info(struct radeon_device *rdev)
  62. {
  63. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  64. union igp_info *info;
  65. uint16_t data_offset;
  66. uint8_t frev, crev;
  67. fixed20_12 tmp;
  68. if (atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
  69. &frev, &crev, &data_offset)) {
  70. info = (union igp_info *)(rdev->mode_info.atom_context->bios + data_offset);
  71. /* Get various system informations from bios */
  72. switch (crev) {
  73. case 1:
  74. tmp.full = rfixed_const(100);
  75. rdev->pm.igp_sideport_mclk.full = rfixed_const(info->info.ulBootUpMemoryClock);
  76. rdev->pm.igp_sideport_mclk.full = rfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  77. rdev->pm.igp_system_mclk.full = rfixed_const(le16_to_cpu(info->info.usK8MemoryClock));
  78. rdev->pm.igp_ht_link_clk.full = rfixed_const(le16_to_cpu(info->info.usFSBClock));
  79. rdev->pm.igp_ht_link_width.full = rfixed_const(info->info.ucHTLinkWidth);
  80. break;
  81. case 2:
  82. tmp.full = rfixed_const(100);
  83. rdev->pm.igp_sideport_mclk.full = rfixed_const(info->info_v2.ulBootUpSidePortClock);
  84. rdev->pm.igp_sideport_mclk.full = rfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  85. rdev->pm.igp_system_mclk.full = rfixed_const(info->info_v2.ulBootUpUMAClock);
  86. rdev->pm.igp_system_mclk.full = rfixed_div(rdev->pm.igp_system_mclk, tmp);
  87. rdev->pm.igp_ht_link_clk.full = rfixed_const(info->info_v2.ulHTLinkFreq);
  88. rdev->pm.igp_ht_link_clk.full = rfixed_div(rdev->pm.igp_ht_link_clk, tmp);
  89. rdev->pm.igp_ht_link_width.full = rfixed_const(le16_to_cpu(info->info_v2.usMinHTLinkWidth));
  90. break;
  91. default:
  92. tmp.full = rfixed_const(100);
  93. /* We assume the slower possible clock ie worst case */
  94. /* DDR 333Mhz */
  95. rdev->pm.igp_sideport_mclk.full = rfixed_const(333);
  96. /* FIXME: system clock ? */
  97. rdev->pm.igp_system_mclk.full = rfixed_const(100);
  98. rdev->pm.igp_system_mclk.full = rfixed_div(rdev->pm.igp_system_mclk, tmp);
  99. rdev->pm.igp_ht_link_clk.full = rfixed_const(200);
  100. rdev->pm.igp_ht_link_width.full = rfixed_const(8);
  101. DRM_ERROR("No integrated system info for your GPU, using safe default\n");
  102. break;
  103. }
  104. } else {
  105. tmp.full = rfixed_const(100);
  106. /* We assume the slower possible clock ie worst case */
  107. /* DDR 333Mhz */
  108. rdev->pm.igp_sideport_mclk.full = rfixed_const(333);
  109. /* FIXME: system clock ? */
  110. rdev->pm.igp_system_mclk.full = rfixed_const(100);
  111. rdev->pm.igp_system_mclk.full = rfixed_div(rdev->pm.igp_system_mclk, tmp);
  112. rdev->pm.igp_ht_link_clk.full = rfixed_const(200);
  113. rdev->pm.igp_ht_link_width.full = rfixed_const(8);
  114. DRM_ERROR("No integrated system info for your GPU, using safe default\n");
  115. }
  116. /* Compute various bandwidth */
  117. /* k8_bandwidth = (memory_clk / 2) * 2 * 8 * 0.5 = memory_clk * 4 */
  118. tmp.full = rfixed_const(4);
  119. rdev->pm.k8_bandwidth.full = rfixed_mul(rdev->pm.igp_system_mclk, tmp);
  120. /* ht_bandwidth = ht_clk * 2 * ht_width / 8 * 0.8
  121. * = ht_clk * ht_width / 5
  122. */
  123. tmp.full = rfixed_const(5);
  124. rdev->pm.ht_bandwidth.full = rfixed_mul(rdev->pm.igp_ht_link_clk,
  125. rdev->pm.igp_ht_link_width);
  126. rdev->pm.ht_bandwidth.full = rfixed_div(rdev->pm.ht_bandwidth, tmp);
  127. if (tmp.full < rdev->pm.max_bandwidth.full) {
  128. /* HT link is a limiting factor */
  129. rdev->pm.max_bandwidth.full = tmp.full;
  130. }
  131. /* sideport_bandwidth = (sideport_clk / 2) * 2 * 2 * 0.7
  132. * = (sideport_clk * 14) / 10
  133. */
  134. tmp.full = rfixed_const(14);
  135. rdev->pm.sideport_bandwidth.full = rfixed_mul(rdev->pm.igp_sideport_mclk, tmp);
  136. tmp.full = rfixed_const(10);
  137. rdev->pm.sideport_bandwidth.full = rfixed_div(rdev->pm.sideport_bandwidth, tmp);
  138. }
  139. void rs690_mc_init(struct radeon_device *rdev)
  140. {
  141. u64 base;
  142. rs400_gart_adjust_size(rdev);
  143. rdev->mc.vram_is_ddr = true;
  144. rdev->mc.vram_width = 128;
  145. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  146. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  147. rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
  148. rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
  149. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  150. base = RREG32_MC(R_000100_MCCFG_FB_LOCATION);
  151. base = G_000100_MC_FB_START(base) << 16;
  152. rs690_pm_info(rdev);
  153. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  154. radeon_vram_location(rdev, &rdev->mc, base);
  155. radeon_gtt_location(rdev, &rdev->mc);
  156. radeon_update_bandwidth_info(rdev);
  157. }
  158. void rs690_line_buffer_adjust(struct radeon_device *rdev,
  159. struct drm_display_mode *mode1,
  160. struct drm_display_mode *mode2)
  161. {
  162. u32 tmp;
  163. /*
  164. * Line Buffer Setup
  165. * There is a single line buffer shared by both display controllers.
  166. * R_006520_DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  167. * the display controllers. The paritioning can either be done
  168. * manually or via one of four preset allocations specified in bits 1:0:
  169. * 0 - line buffer is divided in half and shared between crtc
  170. * 1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
  171. * 2 - D1 gets the whole buffer
  172. * 3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
  173. * Setting bit 2 of R_006520_DC_LB_MEMORY_SPLIT controls switches to manual
  174. * allocation mode. In manual allocation mode, D1 always starts at 0,
  175. * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
  176. */
  177. tmp = RREG32(R_006520_DC_LB_MEMORY_SPLIT) & C_006520_DC_LB_MEMORY_SPLIT;
  178. tmp &= ~C_006520_DC_LB_MEMORY_SPLIT_MODE;
  179. /* auto */
  180. if (mode1 && mode2) {
  181. if (mode1->hdisplay > mode2->hdisplay) {
  182. if (mode1->hdisplay > 2560)
  183. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
  184. else
  185. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  186. } else if (mode2->hdisplay > mode1->hdisplay) {
  187. if (mode2->hdisplay > 2560)
  188. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  189. else
  190. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  191. } else
  192. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  193. } else if (mode1) {
  194. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_ONLY;
  195. } else if (mode2) {
  196. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  197. }
  198. WREG32(R_006520_DC_LB_MEMORY_SPLIT, tmp);
  199. }
  200. struct rs690_watermark {
  201. u32 lb_request_fifo_depth;
  202. fixed20_12 num_line_pair;
  203. fixed20_12 estimated_width;
  204. fixed20_12 worst_case_latency;
  205. fixed20_12 consumption_rate;
  206. fixed20_12 active_time;
  207. fixed20_12 dbpp;
  208. fixed20_12 priority_mark_max;
  209. fixed20_12 priority_mark;
  210. fixed20_12 sclk;
  211. };
  212. void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
  213. struct radeon_crtc *crtc,
  214. struct rs690_watermark *wm)
  215. {
  216. struct drm_display_mode *mode = &crtc->base.mode;
  217. fixed20_12 a, b, c;
  218. fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
  219. fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
  220. /* FIXME: detect IGP with sideport memory, i don't think there is any
  221. * such product available
  222. */
  223. bool sideport = false;
  224. if (!crtc->base.enabled) {
  225. /* FIXME: wouldn't it better to set priority mark to maximum */
  226. wm->lb_request_fifo_depth = 4;
  227. return;
  228. }
  229. if (crtc->vsc.full > rfixed_const(2))
  230. wm->num_line_pair.full = rfixed_const(2);
  231. else
  232. wm->num_line_pair.full = rfixed_const(1);
  233. b.full = rfixed_const(mode->crtc_hdisplay);
  234. c.full = rfixed_const(256);
  235. a.full = rfixed_div(b, c);
  236. request_fifo_depth.full = rfixed_mul(a, wm->num_line_pair);
  237. request_fifo_depth.full = rfixed_ceil(request_fifo_depth);
  238. if (a.full < rfixed_const(4)) {
  239. wm->lb_request_fifo_depth = 4;
  240. } else {
  241. wm->lb_request_fifo_depth = rfixed_trunc(request_fifo_depth);
  242. }
  243. /* Determine consumption rate
  244. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  245. * vtaps = number of vertical taps,
  246. * vsc = vertical scaling ratio, defined as source/destination
  247. * hsc = horizontal scaling ration, defined as source/destination
  248. */
  249. a.full = rfixed_const(mode->clock);
  250. b.full = rfixed_const(1000);
  251. a.full = rfixed_div(a, b);
  252. pclk.full = rfixed_div(b, a);
  253. if (crtc->rmx_type != RMX_OFF) {
  254. b.full = rfixed_const(2);
  255. if (crtc->vsc.full > b.full)
  256. b.full = crtc->vsc.full;
  257. b.full = rfixed_mul(b, crtc->hsc);
  258. c.full = rfixed_const(2);
  259. b.full = rfixed_div(b, c);
  260. consumption_time.full = rfixed_div(pclk, b);
  261. } else {
  262. consumption_time.full = pclk.full;
  263. }
  264. a.full = rfixed_const(1);
  265. wm->consumption_rate.full = rfixed_div(a, consumption_time);
  266. /* Determine line time
  267. * LineTime = total time for one line of displayhtotal
  268. * LineTime = total number of horizontal pixels
  269. * pclk = pixel clock period(ns)
  270. */
  271. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  272. line_time.full = rfixed_mul(a, pclk);
  273. /* Determine active time
  274. * ActiveTime = time of active region of display within one line,
  275. * hactive = total number of horizontal active pixels
  276. * htotal = total number of horizontal pixels
  277. */
  278. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  279. b.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  280. wm->active_time.full = rfixed_mul(line_time, b);
  281. wm->active_time.full = rfixed_div(wm->active_time, a);
  282. /* Maximun bandwidth is the minimun bandwidth of all component */
  283. rdev->pm.max_bandwidth = rdev->pm.core_bandwidth;
  284. if (sideport) {
  285. if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
  286. rdev->pm.sideport_bandwidth.full)
  287. rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
  288. read_delay_latency.full = rfixed_const(370 * 800 * 1000);
  289. read_delay_latency.full = rfixed_div(read_delay_latency,
  290. rdev->pm.igp_sideport_mclk);
  291. } else {
  292. if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
  293. rdev->pm.k8_bandwidth.full)
  294. rdev->pm.max_bandwidth = rdev->pm.k8_bandwidth;
  295. if (rdev->pm.max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
  296. rdev->pm.ht_bandwidth.full)
  297. rdev->pm.max_bandwidth = rdev->pm.ht_bandwidth;
  298. read_delay_latency.full = rfixed_const(5000);
  299. }
  300. /* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
  301. a.full = rfixed_const(16);
  302. rdev->pm.sclk.full = rfixed_mul(rdev->pm.max_bandwidth, a);
  303. a.full = rfixed_const(1000);
  304. rdev->pm.sclk.full = rfixed_div(a, rdev->pm.sclk);
  305. /* Determine chunk time
  306. * ChunkTime = the time it takes the DCP to send one chunk of data
  307. * to the LB which consists of pipeline delay and inter chunk gap
  308. * sclk = system clock(ns)
  309. */
  310. a.full = rfixed_const(256 * 13);
  311. chunk_time.full = rfixed_mul(rdev->pm.sclk, a);
  312. a.full = rfixed_const(10);
  313. chunk_time.full = rfixed_div(chunk_time, a);
  314. /* Determine the worst case latency
  315. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  316. * WorstCaseLatency = worst case time from urgent to when the MC starts
  317. * to return data
  318. * READ_DELAY_IDLE_MAX = constant of 1us
  319. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  320. * which consists of pipeline delay and inter chunk gap
  321. */
  322. if (rfixed_trunc(wm->num_line_pair) > 1) {
  323. a.full = rfixed_const(3);
  324. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  325. wm->worst_case_latency.full += read_delay_latency.full;
  326. } else {
  327. a.full = rfixed_const(2);
  328. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  329. wm->worst_case_latency.full += read_delay_latency.full;
  330. }
  331. /* Determine the tolerable latency
  332. * TolerableLatency = Any given request has only 1 line time
  333. * for the data to be returned
  334. * LBRequestFifoDepth = Number of chunk requests the LB can
  335. * put into the request FIFO for a display
  336. * LineTime = total time for one line of display
  337. * ChunkTime = the time it takes the DCP to send one chunk
  338. * of data to the LB which consists of
  339. * pipeline delay and inter chunk gap
  340. */
  341. if ((2+wm->lb_request_fifo_depth) >= rfixed_trunc(request_fifo_depth)) {
  342. tolerable_latency.full = line_time.full;
  343. } else {
  344. tolerable_latency.full = rfixed_const(wm->lb_request_fifo_depth - 2);
  345. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  346. tolerable_latency.full = rfixed_mul(tolerable_latency, chunk_time);
  347. tolerable_latency.full = line_time.full - tolerable_latency.full;
  348. }
  349. /* We assume worst case 32bits (4 bytes) */
  350. wm->dbpp.full = rfixed_const(4 * 8);
  351. /* Determine the maximum priority mark
  352. * width = viewport width in pixels
  353. */
  354. a.full = rfixed_const(16);
  355. wm->priority_mark_max.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  356. wm->priority_mark_max.full = rfixed_div(wm->priority_mark_max, a);
  357. wm->priority_mark_max.full = rfixed_ceil(wm->priority_mark_max);
  358. /* Determine estimated width */
  359. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  360. estimated_width.full = rfixed_div(estimated_width, consumption_time);
  361. if (rfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  362. wm->priority_mark.full = rfixed_const(10);
  363. } else {
  364. a.full = rfixed_const(16);
  365. wm->priority_mark.full = rfixed_div(estimated_width, a);
  366. wm->priority_mark.full = rfixed_ceil(wm->priority_mark);
  367. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  368. }
  369. }
  370. void rs690_bandwidth_update(struct radeon_device *rdev)
  371. {
  372. struct drm_display_mode *mode0 = NULL;
  373. struct drm_display_mode *mode1 = NULL;
  374. struct rs690_watermark wm0;
  375. struct rs690_watermark wm1;
  376. u32 tmp, d1mode_priority_a_cnt, d2mode_priority_a_cnt;
  377. fixed20_12 priority_mark02, priority_mark12, fill_rate;
  378. fixed20_12 a, b;
  379. radeon_update_display_priority(rdev);
  380. if (rdev->mode_info.crtcs[0]->base.enabled)
  381. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  382. if (rdev->mode_info.crtcs[1]->base.enabled)
  383. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  384. /*
  385. * Set display0/1 priority up in the memory controller for
  386. * modes if the user specifies HIGH for displaypriority
  387. * option.
  388. */
  389. if ((rdev->disp_priority == 2) &&
  390. ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))) {
  391. tmp = RREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER);
  392. tmp &= C_000104_MC_DISP0R_INIT_LAT;
  393. tmp &= C_000104_MC_DISP1R_INIT_LAT;
  394. if (mode0)
  395. tmp |= S_000104_MC_DISP0R_INIT_LAT(1);
  396. if (mode1)
  397. tmp |= S_000104_MC_DISP1R_INIT_LAT(1);
  398. WREG32_MC(R_000104_MC_INIT_MISC_LAT_TIMER, tmp);
  399. }
  400. rs690_line_buffer_adjust(rdev, mode0, mode1);
  401. if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
  402. WREG32(R_006C9C_DCP_CONTROL, 0);
  403. if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
  404. WREG32(R_006C9C_DCP_CONTROL, 2);
  405. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0);
  406. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1);
  407. tmp = (wm0.lb_request_fifo_depth - 1);
  408. tmp |= (wm1.lb_request_fifo_depth - 1) << 16;
  409. WREG32(R_006D58_LB_MAX_REQ_OUTSTANDING, tmp);
  410. if (mode0 && mode1) {
  411. if (rfixed_trunc(wm0.dbpp) > 64)
  412. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  413. else
  414. a.full = wm0.num_line_pair.full;
  415. if (rfixed_trunc(wm1.dbpp) > 64)
  416. b.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  417. else
  418. b.full = wm1.num_line_pair.full;
  419. a.full += b.full;
  420. fill_rate.full = rfixed_div(wm0.sclk, a);
  421. if (wm0.consumption_rate.full > fill_rate.full) {
  422. b.full = wm0.consumption_rate.full - fill_rate.full;
  423. b.full = rfixed_mul(b, wm0.active_time);
  424. a.full = rfixed_mul(wm0.worst_case_latency,
  425. wm0.consumption_rate);
  426. a.full = a.full + b.full;
  427. b.full = rfixed_const(16 * 1000);
  428. priority_mark02.full = rfixed_div(a, b);
  429. } else {
  430. a.full = rfixed_mul(wm0.worst_case_latency,
  431. wm0.consumption_rate);
  432. b.full = rfixed_const(16 * 1000);
  433. priority_mark02.full = rfixed_div(a, b);
  434. }
  435. if (wm1.consumption_rate.full > fill_rate.full) {
  436. b.full = wm1.consumption_rate.full - fill_rate.full;
  437. b.full = rfixed_mul(b, wm1.active_time);
  438. a.full = rfixed_mul(wm1.worst_case_latency,
  439. wm1.consumption_rate);
  440. a.full = a.full + b.full;
  441. b.full = rfixed_const(16 * 1000);
  442. priority_mark12.full = rfixed_div(a, b);
  443. } else {
  444. a.full = rfixed_mul(wm1.worst_case_latency,
  445. wm1.consumption_rate);
  446. b.full = rfixed_const(16 * 1000);
  447. priority_mark12.full = rfixed_div(a, b);
  448. }
  449. if (wm0.priority_mark.full > priority_mark02.full)
  450. priority_mark02.full = wm0.priority_mark.full;
  451. if (rfixed_trunc(priority_mark02) < 0)
  452. priority_mark02.full = 0;
  453. if (wm0.priority_mark_max.full > priority_mark02.full)
  454. priority_mark02.full = wm0.priority_mark_max.full;
  455. if (wm1.priority_mark.full > priority_mark12.full)
  456. priority_mark12.full = wm1.priority_mark.full;
  457. if (rfixed_trunc(priority_mark12) < 0)
  458. priority_mark12.full = 0;
  459. if (wm1.priority_mark_max.full > priority_mark12.full)
  460. priority_mark12.full = wm1.priority_mark_max.full;
  461. d1mode_priority_a_cnt = rfixed_trunc(priority_mark02);
  462. d2mode_priority_a_cnt = rfixed_trunc(priority_mark12);
  463. if (rdev->disp_priority == 2) {
  464. d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
  465. d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
  466. }
  467. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
  468. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_a_cnt);
  469. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
  470. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_a_cnt);
  471. } else if (mode0) {
  472. if (rfixed_trunc(wm0.dbpp) > 64)
  473. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  474. else
  475. a.full = wm0.num_line_pair.full;
  476. fill_rate.full = rfixed_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 = rfixed_mul(b, wm0.active_time);
  480. a.full = rfixed_mul(wm0.worst_case_latency,
  481. wm0.consumption_rate);
  482. a.full = a.full + b.full;
  483. b.full = rfixed_const(16 * 1000);
  484. priority_mark02.full = rfixed_div(a, b);
  485. } else {
  486. a.full = rfixed_mul(wm0.worst_case_latency,
  487. wm0.consumption_rate);
  488. b.full = rfixed_const(16 * 1000);
  489. priority_mark02.full = rfixed_div(a, b);
  490. }
  491. if (wm0.priority_mark.full > priority_mark02.full)
  492. priority_mark02.full = wm0.priority_mark.full;
  493. if (rfixed_trunc(priority_mark02) < 0)
  494. priority_mark02.full = 0;
  495. if (wm0.priority_mark_max.full > priority_mark02.full)
  496. priority_mark02.full = wm0.priority_mark_max.full;
  497. d1mode_priority_a_cnt = rfixed_trunc(priority_mark02);
  498. if (rdev->disp_priority == 2)
  499. d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
  500. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
  501. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_a_cnt);
  502. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT,
  503. S_006D48_D2MODE_PRIORITY_A_OFF(1));
  504. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT,
  505. S_006D4C_D2MODE_PRIORITY_B_OFF(1));
  506. } else {
  507. if (rfixed_trunc(wm1.dbpp) > 64)
  508. a.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  509. else
  510. a.full = wm1.num_line_pair.full;
  511. fill_rate.full = rfixed_div(wm1.sclk, a);
  512. if (wm1.consumption_rate.full > fill_rate.full) {
  513. b.full = wm1.consumption_rate.full - fill_rate.full;
  514. b.full = rfixed_mul(b, wm1.active_time);
  515. a.full = rfixed_mul(wm1.worst_case_latency,
  516. wm1.consumption_rate);
  517. a.full = a.full + b.full;
  518. b.full = rfixed_const(16 * 1000);
  519. priority_mark12.full = rfixed_div(a, b);
  520. } else {
  521. a.full = rfixed_mul(wm1.worst_case_latency,
  522. wm1.consumption_rate);
  523. b.full = rfixed_const(16 * 1000);
  524. priority_mark12.full = rfixed_div(a, b);
  525. }
  526. if (wm1.priority_mark.full > priority_mark12.full)
  527. priority_mark12.full = wm1.priority_mark.full;
  528. if (rfixed_trunc(priority_mark12) < 0)
  529. priority_mark12.full = 0;
  530. if (wm1.priority_mark_max.full > priority_mark12.full)
  531. priority_mark12.full = wm1.priority_mark_max.full;
  532. d2mode_priority_a_cnt = rfixed_trunc(priority_mark12);
  533. if (rdev->disp_priority == 2)
  534. d2mode_priority_a_cnt |= S_006D48_D2MODE_PRIORITY_A_ALWAYS_ON(1);
  535. WREG32(R_006548_D1MODE_PRIORITY_A_CNT,
  536. S_006548_D1MODE_PRIORITY_A_OFF(1));
  537. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT,
  538. S_00654C_D1MODE_PRIORITY_B_OFF(1));
  539. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
  540. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_a_cnt);
  541. }
  542. }
  543. uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  544. {
  545. uint32_t r;
  546. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
  547. r = RREG32(R_00007C_MC_DATA);
  548. WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
  549. return r;
  550. }
  551. void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  552. {
  553. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
  554. S_000078_MC_IND_WR_EN(1));
  555. WREG32(R_00007C_MC_DATA, v);
  556. WREG32(R_000078_MC_INDEX, 0x7F);
  557. }
  558. void rs690_mc_program(struct radeon_device *rdev)
  559. {
  560. struct rv515_mc_save save;
  561. /* Stops all mc clients */
  562. rv515_mc_stop(rdev, &save);
  563. /* Wait for mc idle */
  564. if (rs690_mc_wait_for_idle(rdev))
  565. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  566. /* Program MC, should be a 32bits limited address space */
  567. WREG32_MC(R_000100_MCCFG_FB_LOCATION,
  568. S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
  569. S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
  570. WREG32(R_000134_HDP_FB_LOCATION,
  571. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  572. rv515_mc_resume(rdev, &save);
  573. }
  574. static int rs690_startup(struct radeon_device *rdev)
  575. {
  576. int r;
  577. rs690_mc_program(rdev);
  578. /* Resume clock */
  579. rv515_clock_startup(rdev);
  580. /* Initialize GPU configuration (# pipes, ...) */
  581. rs690_gpu_init(rdev);
  582. /* Initialize GART (initialize after TTM so we can allocate
  583. * memory through TTM but finalize after TTM) */
  584. r = rs400_gart_enable(rdev);
  585. if (r)
  586. return r;
  587. /* Enable IRQ */
  588. rs600_irq_set(rdev);
  589. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  590. /* 1M ring buffer */
  591. r = r100_cp_init(rdev, 1024 * 1024);
  592. if (r) {
  593. dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
  594. return r;
  595. }
  596. r = r100_wb_init(rdev);
  597. if (r)
  598. dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
  599. r = r100_ib_init(rdev);
  600. if (r) {
  601. dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
  602. return r;
  603. }
  604. return 0;
  605. }
  606. int rs690_resume(struct radeon_device *rdev)
  607. {
  608. /* Make sur GART are not working */
  609. rs400_gart_disable(rdev);
  610. /* Resume clock before doing reset */
  611. rv515_clock_startup(rdev);
  612. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  613. if (radeon_gpu_reset(rdev)) {
  614. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  615. RREG32(R_000E40_RBBM_STATUS),
  616. RREG32(R_0007C0_CP_STAT));
  617. }
  618. /* post */
  619. atom_asic_init(rdev->mode_info.atom_context);
  620. /* Resume clock after posting */
  621. rv515_clock_startup(rdev);
  622. /* Initialize surface registers */
  623. radeon_surface_init(rdev);
  624. return rs690_startup(rdev);
  625. }
  626. int rs690_suspend(struct radeon_device *rdev)
  627. {
  628. r100_cp_disable(rdev);
  629. r100_wb_disable(rdev);
  630. rs600_irq_disable(rdev);
  631. rs400_gart_disable(rdev);
  632. return 0;
  633. }
  634. void rs690_fini(struct radeon_device *rdev)
  635. {
  636. radeon_pm_fini(rdev);
  637. r100_cp_fini(rdev);
  638. r100_wb_fini(rdev);
  639. r100_ib_fini(rdev);
  640. radeon_gem_fini(rdev);
  641. rs400_gart_fini(rdev);
  642. radeon_irq_kms_fini(rdev);
  643. radeon_fence_driver_fini(rdev);
  644. radeon_bo_fini(rdev);
  645. radeon_atombios_fini(rdev);
  646. kfree(rdev->bios);
  647. rdev->bios = NULL;
  648. }
  649. int rs690_init(struct radeon_device *rdev)
  650. {
  651. int r;
  652. /* Disable VGA */
  653. rv515_vga_render_disable(rdev);
  654. /* Initialize scratch registers */
  655. radeon_scratch_init(rdev);
  656. /* Initialize surface registers */
  657. radeon_surface_init(rdev);
  658. /* TODO: disable VGA need to use VGA request */
  659. /* BIOS*/
  660. if (!radeon_get_bios(rdev)) {
  661. if (ASIC_IS_AVIVO(rdev))
  662. return -EINVAL;
  663. }
  664. if (rdev->is_atom_bios) {
  665. r = radeon_atombios_init(rdev);
  666. if (r)
  667. return r;
  668. } else {
  669. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  670. return -EINVAL;
  671. }
  672. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  673. if (radeon_gpu_reset(rdev)) {
  674. dev_warn(rdev->dev,
  675. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  676. RREG32(R_000E40_RBBM_STATUS),
  677. RREG32(R_0007C0_CP_STAT));
  678. }
  679. /* check if cards are posted or not */
  680. if (radeon_boot_test_post_card(rdev) == false)
  681. return -EINVAL;
  682. /* Initialize clocks */
  683. radeon_get_clock_info(rdev->ddev);
  684. /* Initialize power management */
  685. radeon_pm_init(rdev);
  686. /* initialize memory controller */
  687. rs690_mc_init(rdev);
  688. rv515_debugfs(rdev);
  689. /* Fence driver */
  690. r = radeon_fence_driver_init(rdev);
  691. if (r)
  692. return r;
  693. r = radeon_irq_kms_init(rdev);
  694. if (r)
  695. return r;
  696. /* Memory manager */
  697. r = radeon_bo_init(rdev);
  698. if (r)
  699. return r;
  700. r = rs400_gart_init(rdev);
  701. if (r)
  702. return r;
  703. rs600_set_safe_registers(rdev);
  704. rdev->accel_working = true;
  705. r = rs690_startup(rdev);
  706. if (r) {
  707. /* Somethings want wront with the accel init stop accel */
  708. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  709. r100_cp_fini(rdev);
  710. r100_wb_fini(rdev);
  711. r100_ib_fini(rdev);
  712. rs400_gart_fini(rdev);
  713. radeon_irq_kms_fini(rdev);
  714. rdev->accel_working = false;
  715. }
  716. return 0;
  717. }