rs690.c 25 KB

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