rs690.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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. 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. void rs690_mc_init(struct radeon_device *rdev)
  141. {
  142. u64 base;
  143. rs400_gart_adjust_size(rdev);
  144. rdev->mc.vram_is_ddr = true;
  145. rdev->mc.vram_width = 128;
  146. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  147. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  148. rdev->mc.aper_base = pci_resource_start(rdev->pdev, 0);
  149. rdev->mc.aper_size = pci_resource_len(rdev->pdev, 0);
  150. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  151. base = RREG32_MC(R_000100_MCCFG_FB_LOCATION);
  152. base = G_000100_MC_FB_START(base) << 16;
  153. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  154. rs690_pm_info(rdev);
  155. radeon_vram_location(rdev, &rdev->mc, base);
  156. rdev->mc.gtt_base_align = rdev->mc.gtt_size - 1;
  157. radeon_gtt_location(rdev, &rdev->mc);
  158. radeon_update_bandwidth_info(rdev);
  159. }
  160. void rs690_line_buffer_adjust(struct radeon_device *rdev,
  161. struct drm_display_mode *mode1,
  162. struct drm_display_mode *mode2)
  163. {
  164. u32 tmp;
  165. /*
  166. * Line Buffer Setup
  167. * There is a single line buffer shared by both display controllers.
  168. * R_006520_DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  169. * the display controllers. The paritioning can either be done
  170. * manually or via one of four preset allocations specified in bits 1:0:
  171. * 0 - line buffer is divided in half and shared between crtc
  172. * 1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
  173. * 2 - D1 gets the whole buffer
  174. * 3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
  175. * Setting bit 2 of R_006520_DC_LB_MEMORY_SPLIT controls switches to manual
  176. * allocation mode. In manual allocation mode, D1 always starts at 0,
  177. * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
  178. */
  179. tmp = RREG32(R_006520_DC_LB_MEMORY_SPLIT) & C_006520_DC_LB_MEMORY_SPLIT;
  180. tmp &= ~C_006520_DC_LB_MEMORY_SPLIT_MODE;
  181. /* auto */
  182. if (mode1 && mode2) {
  183. if (mode1->hdisplay > mode2->hdisplay) {
  184. if (mode1->hdisplay > 2560)
  185. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
  186. else
  187. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  188. } else if (mode2->hdisplay > mode1->hdisplay) {
  189. if (mode2->hdisplay > 2560)
  190. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  191. else
  192. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  193. } else
  194. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  195. } else if (mode1) {
  196. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_ONLY;
  197. } else if (mode2) {
  198. tmp |= V_006520_DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  199. }
  200. WREG32(R_006520_DC_LB_MEMORY_SPLIT, tmp);
  201. }
  202. struct rs690_watermark {
  203. u32 lb_request_fifo_depth;
  204. fixed20_12 num_line_pair;
  205. fixed20_12 estimated_width;
  206. fixed20_12 worst_case_latency;
  207. fixed20_12 consumption_rate;
  208. fixed20_12 active_time;
  209. fixed20_12 dbpp;
  210. fixed20_12 priority_mark_max;
  211. fixed20_12 priority_mark;
  212. fixed20_12 sclk;
  213. };
  214. void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
  215. struct radeon_crtc *crtc,
  216. struct rs690_watermark *wm)
  217. {
  218. struct drm_display_mode *mode = &crtc->base.mode;
  219. fixed20_12 a, b, c;
  220. fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
  221. fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
  222. if (!crtc->base.enabled) {
  223. /* FIXME: wouldn't it better to set priority mark to maximum */
  224. wm->lb_request_fifo_depth = 4;
  225. return;
  226. }
  227. if (crtc->vsc.full > dfixed_const(2))
  228. wm->num_line_pair.full = dfixed_const(2);
  229. else
  230. wm->num_line_pair.full = dfixed_const(1);
  231. b.full = dfixed_const(mode->crtc_hdisplay);
  232. c.full = dfixed_const(256);
  233. a.full = dfixed_div(b, c);
  234. request_fifo_depth.full = dfixed_mul(a, wm->num_line_pair);
  235. request_fifo_depth.full = dfixed_ceil(request_fifo_depth);
  236. if (a.full < dfixed_const(4)) {
  237. wm->lb_request_fifo_depth = 4;
  238. } else {
  239. wm->lb_request_fifo_depth = dfixed_trunc(request_fifo_depth);
  240. }
  241. /* Determine consumption rate
  242. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  243. * vtaps = number of vertical taps,
  244. * vsc = vertical scaling ratio, defined as source/destination
  245. * hsc = horizontal scaling ration, defined as source/destination
  246. */
  247. a.full = dfixed_const(mode->clock);
  248. b.full = dfixed_const(1000);
  249. a.full = dfixed_div(a, b);
  250. pclk.full = dfixed_div(b, a);
  251. if (crtc->rmx_type != RMX_OFF) {
  252. b.full = dfixed_const(2);
  253. if (crtc->vsc.full > b.full)
  254. b.full = crtc->vsc.full;
  255. b.full = dfixed_mul(b, crtc->hsc);
  256. c.full = dfixed_const(2);
  257. b.full = dfixed_div(b, c);
  258. consumption_time.full = dfixed_div(pclk, b);
  259. } else {
  260. consumption_time.full = pclk.full;
  261. }
  262. a.full = dfixed_const(1);
  263. wm->consumption_rate.full = dfixed_div(a, consumption_time);
  264. /* Determine line time
  265. * LineTime = total time for one line of displayhtotal
  266. * LineTime = total number of horizontal pixels
  267. * pclk = pixel clock period(ns)
  268. */
  269. a.full = dfixed_const(crtc->base.mode.crtc_htotal);
  270. line_time.full = dfixed_mul(a, pclk);
  271. /* Determine active time
  272. * ActiveTime = time of active region of display within one line,
  273. * hactive = total number of horizontal active pixels
  274. * htotal = total number of horizontal pixels
  275. */
  276. a.full = dfixed_const(crtc->base.mode.crtc_htotal);
  277. b.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
  278. wm->active_time.full = dfixed_mul(line_time, b);
  279. wm->active_time.full = dfixed_div(wm->active_time, a);
  280. /* Maximun bandwidth is the minimun bandwidth of all component */
  281. rdev->pm.max_bandwidth = rdev->pm.core_bandwidth;
  282. if (rdev->mc.igp_sideport_enabled) {
  283. if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
  284. rdev->pm.sideport_bandwidth.full)
  285. rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
  286. read_delay_latency.full = dfixed_const(370 * 800 * 1000);
  287. read_delay_latency.full = dfixed_div(read_delay_latency,
  288. rdev->pm.igp_sideport_mclk);
  289. } else {
  290. if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
  291. rdev->pm.k8_bandwidth.full)
  292. rdev->pm.max_bandwidth = rdev->pm.k8_bandwidth;
  293. if (rdev->pm.max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
  294. rdev->pm.ht_bandwidth.full)
  295. rdev->pm.max_bandwidth = rdev->pm.ht_bandwidth;
  296. read_delay_latency.full = dfixed_const(5000);
  297. }
  298. /* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
  299. a.full = dfixed_const(16);
  300. rdev->pm.sclk.full = dfixed_mul(rdev->pm.max_bandwidth, a);
  301. a.full = dfixed_const(1000);
  302. rdev->pm.sclk.full = dfixed_div(a, rdev->pm.sclk);
  303. /* Determine chunk time
  304. * ChunkTime = the time it takes the DCP to send one chunk of data
  305. * to the LB which consists of pipeline delay and inter chunk gap
  306. * sclk = system clock(ns)
  307. */
  308. a.full = dfixed_const(256 * 13);
  309. chunk_time.full = dfixed_mul(rdev->pm.sclk, a);
  310. a.full = dfixed_const(10);
  311. chunk_time.full = dfixed_div(chunk_time, a);
  312. /* Determine the worst case latency
  313. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  314. * WorstCaseLatency = worst case time from urgent to when the MC starts
  315. * to return data
  316. * READ_DELAY_IDLE_MAX = constant of 1us
  317. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  318. * which consists of pipeline delay and inter chunk gap
  319. */
  320. if (dfixed_trunc(wm->num_line_pair) > 1) {
  321. a.full = dfixed_const(3);
  322. wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
  323. wm->worst_case_latency.full += read_delay_latency.full;
  324. } else {
  325. a.full = dfixed_const(2);
  326. wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
  327. wm->worst_case_latency.full += read_delay_latency.full;
  328. }
  329. /* Determine the tolerable latency
  330. * TolerableLatency = Any given request has only 1 line time
  331. * for the data to be returned
  332. * LBRequestFifoDepth = Number of chunk requests the LB can
  333. * put into the request FIFO for a display
  334. * LineTime = total time for one line of display
  335. * ChunkTime = the time it takes the DCP to send one chunk
  336. * of data to the LB which consists of
  337. * pipeline delay and inter chunk gap
  338. */
  339. if ((2+wm->lb_request_fifo_depth) >= dfixed_trunc(request_fifo_depth)) {
  340. tolerable_latency.full = line_time.full;
  341. } else {
  342. tolerable_latency.full = dfixed_const(wm->lb_request_fifo_depth - 2);
  343. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  344. tolerable_latency.full = dfixed_mul(tolerable_latency, chunk_time);
  345. tolerable_latency.full = line_time.full - tolerable_latency.full;
  346. }
  347. /* We assume worst case 32bits (4 bytes) */
  348. wm->dbpp.full = dfixed_const(4 * 8);
  349. /* Determine the maximum priority mark
  350. * width = viewport width in pixels
  351. */
  352. a.full = dfixed_const(16);
  353. wm->priority_mark_max.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
  354. wm->priority_mark_max.full = dfixed_div(wm->priority_mark_max, a);
  355. wm->priority_mark_max.full = dfixed_ceil(wm->priority_mark_max);
  356. /* Determine estimated width */
  357. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  358. estimated_width.full = dfixed_div(estimated_width, consumption_time);
  359. if (dfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  360. wm->priority_mark.full = dfixed_const(10);
  361. } else {
  362. a.full = dfixed_const(16);
  363. wm->priority_mark.full = dfixed_div(estimated_width, a);
  364. wm->priority_mark.full = dfixed_ceil(wm->priority_mark);
  365. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  366. }
  367. }
  368. void rs690_bandwidth_update(struct radeon_device *rdev)
  369. {
  370. struct drm_display_mode *mode0 = NULL;
  371. struct drm_display_mode *mode1 = NULL;
  372. struct rs690_watermark wm0;
  373. struct rs690_watermark wm1;
  374. u32 tmp;
  375. u32 d1mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
  376. u32 d2mode_priority_a_cnt = S_006548_D1MODE_PRIORITY_A_OFF(1);
  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 (dfixed_trunc(wm0.dbpp) > 64)
  412. a.full = dfixed_mul(wm0.dbpp, wm0.num_line_pair);
  413. else
  414. a.full = wm0.num_line_pair.full;
  415. if (dfixed_trunc(wm1.dbpp) > 64)
  416. b.full = dfixed_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 = dfixed_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 = dfixed_mul(b, wm0.active_time);
  424. a.full = dfixed_mul(wm0.worst_case_latency,
  425. wm0.consumption_rate);
  426. a.full = a.full + b.full;
  427. b.full = dfixed_const(16 * 1000);
  428. priority_mark02.full = dfixed_div(a, b);
  429. } else {
  430. a.full = dfixed_mul(wm0.worst_case_latency,
  431. wm0.consumption_rate);
  432. b.full = dfixed_const(16 * 1000);
  433. priority_mark02.full = dfixed_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 = dfixed_mul(b, wm1.active_time);
  438. a.full = dfixed_mul(wm1.worst_case_latency,
  439. wm1.consumption_rate);
  440. a.full = a.full + b.full;
  441. b.full = dfixed_const(16 * 1000);
  442. priority_mark12.full = dfixed_div(a, b);
  443. } else {
  444. a.full = dfixed_mul(wm1.worst_case_latency,
  445. wm1.consumption_rate);
  446. b.full = dfixed_const(16 * 1000);
  447. priority_mark12.full = dfixed_div(a, b);
  448. }
  449. if (wm0.priority_mark.full > priority_mark02.full)
  450. priority_mark02.full = wm0.priority_mark.full;
  451. if (dfixed_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 (dfixed_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 = dfixed_trunc(priority_mark02);
  462. d2mode_priority_a_cnt = dfixed_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. } else if (mode0) {
  468. if (dfixed_trunc(wm0.dbpp) > 64)
  469. a.full = dfixed_mul(wm0.dbpp, wm0.num_line_pair);
  470. else
  471. a.full = wm0.num_line_pair.full;
  472. fill_rate.full = dfixed_div(wm0.sclk, a);
  473. if (wm0.consumption_rate.full > fill_rate.full) {
  474. b.full = wm0.consumption_rate.full - fill_rate.full;
  475. b.full = dfixed_mul(b, wm0.active_time);
  476. a.full = dfixed_mul(wm0.worst_case_latency,
  477. wm0.consumption_rate);
  478. a.full = a.full + b.full;
  479. b.full = dfixed_const(16 * 1000);
  480. priority_mark02.full = dfixed_div(a, b);
  481. } else {
  482. a.full = dfixed_mul(wm0.worst_case_latency,
  483. wm0.consumption_rate);
  484. b.full = dfixed_const(16 * 1000);
  485. priority_mark02.full = dfixed_div(a, b);
  486. }
  487. if (wm0.priority_mark.full > priority_mark02.full)
  488. priority_mark02.full = wm0.priority_mark.full;
  489. if (dfixed_trunc(priority_mark02) < 0)
  490. priority_mark02.full = 0;
  491. if (wm0.priority_mark_max.full > priority_mark02.full)
  492. priority_mark02.full = wm0.priority_mark_max.full;
  493. d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
  494. if (rdev->disp_priority == 2)
  495. d1mode_priority_a_cnt |= S_006548_D1MODE_PRIORITY_A_ALWAYS_ON(1);
  496. } else if (mode1) {
  497. if (dfixed_trunc(wm1.dbpp) > 64)
  498. a.full = dfixed_mul(wm1.dbpp, wm1.num_line_pair);
  499. else
  500. a.full = wm1.num_line_pair.full;
  501. fill_rate.full = dfixed_div(wm1.sclk, a);
  502. if (wm1.consumption_rate.full > fill_rate.full) {
  503. b.full = wm1.consumption_rate.full - fill_rate.full;
  504. b.full = dfixed_mul(b, wm1.active_time);
  505. a.full = dfixed_mul(wm1.worst_case_latency,
  506. wm1.consumption_rate);
  507. a.full = a.full + b.full;
  508. b.full = dfixed_const(16 * 1000);
  509. priority_mark12.full = dfixed_div(a, b);
  510. } else {
  511. a.full = dfixed_mul(wm1.worst_case_latency,
  512. wm1.consumption_rate);
  513. b.full = dfixed_const(16 * 1000);
  514. priority_mark12.full = dfixed_div(a, b);
  515. }
  516. if (wm1.priority_mark.full > priority_mark12.full)
  517. priority_mark12.full = wm1.priority_mark.full;
  518. if (dfixed_trunc(priority_mark12) < 0)
  519. priority_mark12.full = 0;
  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. WREG32(R_006548_D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
  527. WREG32(R_00654C_D1MODE_PRIORITY_B_CNT, d1mode_priority_a_cnt);
  528. WREG32(R_006D48_D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
  529. WREG32(R_006D4C_D2MODE_PRIORITY_B_CNT, d2mode_priority_a_cnt);
  530. }
  531. uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  532. {
  533. uint32_t r;
  534. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg));
  535. r = RREG32(R_00007C_MC_DATA);
  536. WREG32(R_000078_MC_INDEX, ~C_000078_MC_IND_ADDR);
  537. return r;
  538. }
  539. void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  540. {
  541. WREG32(R_000078_MC_INDEX, S_000078_MC_IND_ADDR(reg) |
  542. S_000078_MC_IND_WR_EN(1));
  543. WREG32(R_00007C_MC_DATA, v);
  544. WREG32(R_000078_MC_INDEX, 0x7F);
  545. }
  546. void rs690_mc_program(struct radeon_device *rdev)
  547. {
  548. struct rv515_mc_save save;
  549. /* Stops all mc clients */
  550. rv515_mc_stop(rdev, &save);
  551. /* Wait for mc idle */
  552. if (rs690_mc_wait_for_idle(rdev))
  553. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  554. /* Program MC, should be a 32bits limited address space */
  555. WREG32_MC(R_000100_MCCFG_FB_LOCATION,
  556. S_000100_MC_FB_START(rdev->mc.vram_start >> 16) |
  557. S_000100_MC_FB_TOP(rdev->mc.vram_end >> 16));
  558. WREG32(R_000134_HDP_FB_LOCATION,
  559. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  560. rv515_mc_resume(rdev, &save);
  561. }
  562. static int rs690_startup(struct radeon_device *rdev)
  563. {
  564. int r;
  565. rs690_mc_program(rdev);
  566. /* Resume clock */
  567. rv515_clock_startup(rdev);
  568. /* Initialize GPU configuration (# pipes, ...) */
  569. rs690_gpu_init(rdev);
  570. /* Initialize GART (initialize after TTM so we can allocate
  571. * memory through TTM but finalize after TTM) */
  572. r = rs400_gart_enable(rdev);
  573. if (r)
  574. return r;
  575. /* allocate wb buffer */
  576. r = radeon_wb_init(rdev);
  577. if (r)
  578. return r;
  579. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  580. if (r) {
  581. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  582. return r;
  583. }
  584. /* Enable IRQ */
  585. if (!rdev->irq.installed) {
  586. r = radeon_irq_kms_init(rdev);
  587. if (r)
  588. return r;
  589. }
  590. rs600_irq_set(rdev);
  591. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  592. /* 1M ring buffer */
  593. r = r100_cp_init(rdev, 1024 * 1024);
  594. if (r) {
  595. dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
  596. return r;
  597. }
  598. r = r600_audio_init(rdev);
  599. if (r) {
  600. dev_err(rdev->dev, "failed initializing audio\n");
  601. return r;
  602. }
  603. r = radeon_ib_pool_start(rdev);
  604. if (r)
  605. return r;
  606. r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  607. if (r) {
  608. dev_err(rdev->dev, "failed testing IB (%d).\n", r);
  609. rdev->accel_working = false;
  610. return r;
  611. }
  612. return 0;
  613. }
  614. int rs690_resume(struct radeon_device *rdev)
  615. {
  616. int r;
  617. /* Make sur GART are not working */
  618. rs400_gart_disable(rdev);
  619. /* Resume clock before doing reset */
  620. rv515_clock_startup(rdev);
  621. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  622. if (radeon_asic_reset(rdev)) {
  623. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  624. RREG32(R_000E40_RBBM_STATUS),
  625. RREG32(R_0007C0_CP_STAT));
  626. }
  627. /* post */
  628. atom_asic_init(rdev->mode_info.atom_context);
  629. /* Resume clock after posting */
  630. rv515_clock_startup(rdev);
  631. /* Initialize surface registers */
  632. radeon_surface_init(rdev);
  633. rdev->accel_working = true;
  634. r = rs690_startup(rdev);
  635. if (r) {
  636. rdev->accel_working = false;
  637. }
  638. return r;
  639. }
  640. int rs690_suspend(struct radeon_device *rdev)
  641. {
  642. radeon_ib_pool_suspend(rdev);
  643. r600_audio_fini(rdev);
  644. r100_cp_disable(rdev);
  645. radeon_wb_disable(rdev);
  646. rs600_irq_disable(rdev);
  647. rs400_gart_disable(rdev);
  648. return 0;
  649. }
  650. void rs690_fini(struct radeon_device *rdev)
  651. {
  652. r600_audio_fini(rdev);
  653. r100_cp_fini(rdev);
  654. radeon_wb_fini(rdev);
  655. r100_ib_fini(rdev);
  656. radeon_gem_fini(rdev);
  657. rs400_gart_fini(rdev);
  658. radeon_irq_kms_fini(rdev);
  659. radeon_fence_driver_fini(rdev);
  660. radeon_bo_fini(rdev);
  661. radeon_atombios_fini(rdev);
  662. kfree(rdev->bios);
  663. rdev->bios = NULL;
  664. }
  665. int rs690_init(struct radeon_device *rdev)
  666. {
  667. int r;
  668. /* Disable VGA */
  669. rv515_vga_render_disable(rdev);
  670. /* Initialize scratch registers */
  671. radeon_scratch_init(rdev);
  672. /* Initialize surface registers */
  673. radeon_surface_init(rdev);
  674. /* restore some register to sane defaults */
  675. r100_restore_sanity(rdev);
  676. /* TODO: disable VGA need to use VGA request */
  677. /* BIOS*/
  678. if (!radeon_get_bios(rdev)) {
  679. if (ASIC_IS_AVIVO(rdev))
  680. return -EINVAL;
  681. }
  682. if (rdev->is_atom_bios) {
  683. r = radeon_atombios_init(rdev);
  684. if (r)
  685. return r;
  686. } else {
  687. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  688. return -EINVAL;
  689. }
  690. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  691. if (radeon_asic_reset(rdev)) {
  692. dev_warn(rdev->dev,
  693. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  694. RREG32(R_000E40_RBBM_STATUS),
  695. RREG32(R_0007C0_CP_STAT));
  696. }
  697. /* check if cards are posted or not */
  698. if (radeon_boot_test_post_card(rdev) == false)
  699. return -EINVAL;
  700. /* Initialize clocks */
  701. radeon_get_clock_info(rdev->ddev);
  702. /* initialize memory controller */
  703. rs690_mc_init(rdev);
  704. rv515_debugfs(rdev);
  705. /* Fence driver */
  706. r = radeon_fence_driver_init(rdev);
  707. if (r)
  708. return r;
  709. /* Memory manager */
  710. r = radeon_bo_init(rdev);
  711. if (r)
  712. return r;
  713. r = rs400_gart_init(rdev);
  714. if (r)
  715. return r;
  716. rs600_set_safe_registers(rdev);
  717. r = radeon_ib_pool_init(rdev);
  718. rdev->accel_working = true;
  719. if (r) {
  720. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  721. rdev->accel_working = false;
  722. }
  723. r = rs690_startup(rdev);
  724. if (r) {
  725. /* Somethings want wront with the accel init stop accel */
  726. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  727. r100_cp_fini(rdev);
  728. radeon_wb_fini(rdev);
  729. r100_ib_fini(rdev);
  730. rs400_gart_fini(rdev);
  731. radeon_irq_kms_fini(rdev);
  732. rdev->accel_working = false;
  733. }
  734. return 0;
  735. }