rs690.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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_reg.h"
  30. #include "radeon.h"
  31. #include "rs690r.h"
  32. #include "atom.h"
  33. #include "atom-bits.h"
  34. /* rs690,rs740 depends on : */
  35. void r100_hdp_reset(struct radeon_device *rdev);
  36. int r300_mc_wait_for_idle(struct radeon_device *rdev);
  37. void r420_pipes_init(struct radeon_device *rdev);
  38. void rs400_gart_disable(struct radeon_device *rdev);
  39. int rs400_gart_enable(struct radeon_device *rdev);
  40. void rs400_gart_adjust_size(struct radeon_device *rdev);
  41. void rs600_mc_disable_clients(struct radeon_device *rdev);
  42. /* This files gather functions specifics to :
  43. * rs690,rs740
  44. *
  45. * Some of these functions might be used by newer ASICs.
  46. */
  47. void rs690_gpu_init(struct radeon_device *rdev);
  48. int rs690_mc_wait_for_idle(struct radeon_device *rdev);
  49. /*
  50. * MC functions.
  51. */
  52. int rs690_mc_init(struct radeon_device *rdev)
  53. {
  54. uint32_t tmp;
  55. int r;
  56. if (r100_debugfs_rbbm_init(rdev)) {
  57. DRM_ERROR("Failed to register debugfs file for RBBM !\n");
  58. }
  59. rs690_gpu_init(rdev);
  60. rs400_gart_disable(rdev);
  61. /* Setup GPU memory space */
  62. rdev->mc.gtt_location = rdev->mc.mc_vram_size;
  63. rdev->mc.gtt_location += (rdev->mc.gtt_size - 1);
  64. rdev->mc.gtt_location &= ~(rdev->mc.gtt_size - 1);
  65. rdev->mc.vram_location = 0xFFFFFFFFUL;
  66. r = radeon_mc_setup(rdev);
  67. if (r) {
  68. return r;
  69. }
  70. /* Program GPU memory space */
  71. rs600_mc_disable_clients(rdev);
  72. if (rs690_mc_wait_for_idle(rdev)) {
  73. printk(KERN_WARNING "Failed to wait MC idle while "
  74. "programming pipes. Bad things might happen.\n");
  75. }
  76. tmp = rdev->mc.vram_location + rdev->mc.mc_vram_size - 1;
  77. tmp = REG_SET(RS690_MC_FB_TOP, tmp >> 16);
  78. tmp |= REG_SET(RS690_MC_FB_START, rdev->mc.vram_location >> 16);
  79. WREG32_MC(RS690_MCCFG_FB_LOCATION, tmp);
  80. /* FIXME: Does this reg exist on RS480,RS740 ? */
  81. WREG32(0x310, rdev->mc.vram_location);
  82. WREG32(RS690_HDP_FB_LOCATION, rdev->mc.vram_location >> 16);
  83. return 0;
  84. }
  85. void rs690_mc_fini(struct radeon_device *rdev)
  86. {
  87. }
  88. /*
  89. * Global GPU functions
  90. */
  91. int rs690_mc_wait_for_idle(struct radeon_device *rdev)
  92. {
  93. unsigned i;
  94. uint32_t tmp;
  95. for (i = 0; i < rdev->usec_timeout; i++) {
  96. /* read MC_STATUS */
  97. tmp = RREG32_MC(RS690_MC_STATUS);
  98. if (tmp & RS690_MC_STATUS_IDLE) {
  99. return 0;
  100. }
  101. DRM_UDELAY(1);
  102. }
  103. return -1;
  104. }
  105. void rs690_errata(struct radeon_device *rdev)
  106. {
  107. rdev->pll_errata = 0;
  108. }
  109. void rs690_gpu_init(struct radeon_device *rdev)
  110. {
  111. /* FIXME: HDP same place on rs690 ? */
  112. r100_hdp_reset(rdev);
  113. rv515_vga_render_disable(rdev);
  114. /* FIXME: is this correct ? */
  115. r420_pipes_init(rdev);
  116. if (rs690_mc_wait_for_idle(rdev)) {
  117. printk(KERN_WARNING "Failed to wait MC idle while "
  118. "programming pipes. Bad things might happen.\n");
  119. }
  120. }
  121. /*
  122. * VRAM info.
  123. */
  124. void rs690_pm_info(struct radeon_device *rdev)
  125. {
  126. int index = GetIndexIntoMasterTable(DATA, IntegratedSystemInfo);
  127. struct _ATOM_INTEGRATED_SYSTEM_INFO *info;
  128. struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 *info_v2;
  129. void *ptr;
  130. uint16_t data_offset;
  131. uint8_t frev, crev;
  132. fixed20_12 tmp;
  133. atom_parse_data_header(rdev->mode_info.atom_context, index, NULL,
  134. &frev, &crev, &data_offset);
  135. ptr = rdev->mode_info.atom_context->bios + data_offset;
  136. info = (struct _ATOM_INTEGRATED_SYSTEM_INFO *)ptr;
  137. info_v2 = (struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 *)ptr;
  138. /* Get various system informations from bios */
  139. switch (crev) {
  140. case 1:
  141. tmp.full = rfixed_const(100);
  142. rdev->pm.igp_sideport_mclk.full = rfixed_const(info->ulBootUpMemoryClock);
  143. rdev->pm.igp_sideport_mclk.full = rfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  144. rdev->pm.igp_system_mclk.full = rfixed_const(le16_to_cpu(info->usK8MemoryClock));
  145. rdev->pm.igp_ht_link_clk.full = rfixed_const(le16_to_cpu(info->usFSBClock));
  146. rdev->pm.igp_ht_link_width.full = rfixed_const(info->ucHTLinkWidth);
  147. break;
  148. case 2:
  149. tmp.full = rfixed_const(100);
  150. rdev->pm.igp_sideport_mclk.full = rfixed_const(info_v2->ulBootUpSidePortClock);
  151. rdev->pm.igp_sideport_mclk.full = rfixed_div(rdev->pm.igp_sideport_mclk, tmp);
  152. rdev->pm.igp_system_mclk.full = rfixed_const(info_v2->ulBootUpUMAClock);
  153. rdev->pm.igp_system_mclk.full = rfixed_div(rdev->pm.igp_system_mclk, tmp);
  154. rdev->pm.igp_ht_link_clk.full = rfixed_const(info_v2->ulHTLinkFreq);
  155. rdev->pm.igp_ht_link_clk.full = rfixed_div(rdev->pm.igp_ht_link_clk, tmp);
  156. rdev->pm.igp_ht_link_width.full = rfixed_const(le16_to_cpu(info_v2->usMinHTLinkWidth));
  157. break;
  158. default:
  159. tmp.full = rfixed_const(100);
  160. /* We assume the slower possible clock ie worst case */
  161. /* DDR 333Mhz */
  162. rdev->pm.igp_sideport_mclk.full = rfixed_const(333);
  163. /* FIXME: system clock ? */
  164. rdev->pm.igp_system_mclk.full = rfixed_const(100);
  165. rdev->pm.igp_system_mclk.full = rfixed_div(rdev->pm.igp_system_mclk, tmp);
  166. rdev->pm.igp_ht_link_clk.full = rfixed_const(200);
  167. rdev->pm.igp_ht_link_width.full = rfixed_const(8);
  168. DRM_ERROR("No integrated system info for your GPU, using safe default\n");
  169. break;
  170. }
  171. /* Compute various bandwidth */
  172. /* k8_bandwidth = (memory_clk / 2) * 2 * 8 * 0.5 = memory_clk * 4 */
  173. tmp.full = rfixed_const(4);
  174. rdev->pm.k8_bandwidth.full = rfixed_mul(rdev->pm.igp_system_mclk, tmp);
  175. /* ht_bandwidth = ht_clk * 2 * ht_width / 8 * 0.8
  176. * = ht_clk * ht_width / 5
  177. */
  178. tmp.full = rfixed_const(5);
  179. rdev->pm.ht_bandwidth.full = rfixed_mul(rdev->pm.igp_ht_link_clk,
  180. rdev->pm.igp_ht_link_width);
  181. rdev->pm.ht_bandwidth.full = rfixed_div(rdev->pm.ht_bandwidth, tmp);
  182. if (tmp.full < rdev->pm.max_bandwidth.full) {
  183. /* HT link is a limiting factor */
  184. rdev->pm.max_bandwidth.full = tmp.full;
  185. }
  186. /* sideport_bandwidth = (sideport_clk / 2) * 2 * 2 * 0.7
  187. * = (sideport_clk * 14) / 10
  188. */
  189. tmp.full = rfixed_const(14);
  190. rdev->pm.sideport_bandwidth.full = rfixed_mul(rdev->pm.igp_sideport_mclk, tmp);
  191. tmp.full = rfixed_const(10);
  192. rdev->pm.sideport_bandwidth.full = rfixed_div(rdev->pm.sideport_bandwidth, tmp);
  193. }
  194. void rs690_vram_info(struct radeon_device *rdev)
  195. {
  196. uint32_t tmp;
  197. fixed20_12 a;
  198. rs400_gart_adjust_size(rdev);
  199. /* DDR for all card after R300 & IGP */
  200. rdev->mc.vram_is_ddr = true;
  201. /* FIXME: is this correct for RS690/RS740 ? */
  202. tmp = RREG32(RADEON_MEM_CNTL);
  203. if (tmp & R300_MEM_NUM_CHANNELS_MASK) {
  204. rdev->mc.vram_width = 128;
  205. } else {
  206. rdev->mc.vram_width = 64;
  207. }
  208. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  209. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  210. rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
  211. rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
  212. rs690_pm_info(rdev);
  213. /* FIXME: we should enforce default clock in case GPU is not in
  214. * default setup
  215. */
  216. a.full = rfixed_const(100);
  217. rdev->pm.sclk.full = rfixed_const(rdev->clock.default_sclk);
  218. rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a);
  219. a.full = rfixed_const(16);
  220. /* core_bandwidth = sclk(Mhz) * 16 */
  221. rdev->pm.core_bandwidth.full = rfixed_div(rdev->pm.sclk, a);
  222. }
  223. void rs690_line_buffer_adjust(struct radeon_device *rdev,
  224. struct drm_display_mode *mode1,
  225. struct drm_display_mode *mode2)
  226. {
  227. u32 tmp;
  228. /*
  229. * Line Buffer Setup
  230. * There is a single line buffer shared by both display controllers.
  231. * DC_LB_MEMORY_SPLIT controls how that line buffer is shared between
  232. * the display controllers. The paritioning can either be done
  233. * manually or via one of four preset allocations specified in bits 1:0:
  234. * 0 - line buffer is divided in half and shared between crtc
  235. * 1 - D1 gets 3/4 of the line buffer, D2 gets 1/4
  236. * 2 - D1 gets the whole buffer
  237. * 3 - D1 gets 1/4 of the line buffer, D2 gets 3/4
  238. * Setting bit 2 of DC_LB_MEMORY_SPLIT controls switches to manual
  239. * allocation mode. In manual allocation mode, D1 always starts at 0,
  240. * D1 end/2 is specified in bits 14:4; D2 allocation follows D1.
  241. */
  242. tmp = RREG32(DC_LB_MEMORY_SPLIT) & ~DC_LB_MEMORY_SPLIT_MASK;
  243. tmp &= ~DC_LB_MEMORY_SPLIT_SHIFT_MODE;
  244. /* auto */
  245. if (mode1 && mode2) {
  246. if (mode1->hdisplay > mode2->hdisplay) {
  247. if (mode1->hdisplay > 2560)
  248. tmp |= DC_LB_MEMORY_SPLIT_D1_3Q_D2_1Q;
  249. else
  250. tmp |= DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  251. } else if (mode2->hdisplay > mode1->hdisplay) {
  252. if (mode2->hdisplay > 2560)
  253. tmp |= DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  254. else
  255. tmp |= DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  256. } else
  257. tmp |= AVIVO_DC_LB_MEMORY_SPLIT_D1HALF_D2HALF;
  258. } else if (mode1) {
  259. tmp |= DC_LB_MEMORY_SPLIT_D1_ONLY;
  260. } else if (mode2) {
  261. tmp |= DC_LB_MEMORY_SPLIT_D1_1Q_D2_3Q;
  262. }
  263. WREG32(DC_LB_MEMORY_SPLIT, tmp);
  264. }
  265. struct rs690_watermark {
  266. u32 lb_request_fifo_depth;
  267. fixed20_12 num_line_pair;
  268. fixed20_12 estimated_width;
  269. fixed20_12 worst_case_latency;
  270. fixed20_12 consumption_rate;
  271. fixed20_12 active_time;
  272. fixed20_12 dbpp;
  273. fixed20_12 priority_mark_max;
  274. fixed20_12 priority_mark;
  275. fixed20_12 sclk;
  276. };
  277. void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
  278. struct radeon_crtc *crtc,
  279. struct rs690_watermark *wm)
  280. {
  281. struct drm_display_mode *mode = &crtc->base.mode;
  282. fixed20_12 a, b, c;
  283. fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
  284. fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
  285. /* FIXME: detect IGP with sideport memory, i don't think there is any
  286. * such product available
  287. */
  288. bool sideport = false;
  289. if (!crtc->base.enabled) {
  290. /* FIXME: wouldn't it better to set priority mark to maximum */
  291. wm->lb_request_fifo_depth = 4;
  292. return;
  293. }
  294. if (crtc->vsc.full > rfixed_const(2))
  295. wm->num_line_pair.full = rfixed_const(2);
  296. else
  297. wm->num_line_pair.full = rfixed_const(1);
  298. b.full = rfixed_const(mode->crtc_hdisplay);
  299. c.full = rfixed_const(256);
  300. a.full = rfixed_mul(wm->num_line_pair, b);
  301. request_fifo_depth.full = rfixed_div(a, c);
  302. if (a.full < rfixed_const(4)) {
  303. wm->lb_request_fifo_depth = 4;
  304. } else {
  305. wm->lb_request_fifo_depth = rfixed_trunc(request_fifo_depth);
  306. }
  307. /* Determine consumption rate
  308. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  309. * vtaps = number of vertical taps,
  310. * vsc = vertical scaling ratio, defined as source/destination
  311. * hsc = horizontal scaling ration, defined as source/destination
  312. */
  313. a.full = rfixed_const(mode->clock);
  314. b.full = rfixed_const(1000);
  315. a.full = rfixed_div(a, b);
  316. pclk.full = rfixed_div(b, a);
  317. if (crtc->rmx_type != RMX_OFF) {
  318. b.full = rfixed_const(2);
  319. if (crtc->vsc.full > b.full)
  320. b.full = crtc->vsc.full;
  321. b.full = rfixed_mul(b, crtc->hsc);
  322. c.full = rfixed_const(2);
  323. b.full = rfixed_div(b, c);
  324. consumption_time.full = rfixed_div(pclk, b);
  325. } else {
  326. consumption_time.full = pclk.full;
  327. }
  328. a.full = rfixed_const(1);
  329. wm->consumption_rate.full = rfixed_div(a, consumption_time);
  330. /* Determine line time
  331. * LineTime = total time for one line of displayhtotal
  332. * LineTime = total number of horizontal pixels
  333. * pclk = pixel clock period(ns)
  334. */
  335. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  336. line_time.full = rfixed_mul(a, pclk);
  337. /* Determine active time
  338. * ActiveTime = time of active region of display within one line,
  339. * hactive = total number of horizontal active pixels
  340. * htotal = total number of horizontal pixels
  341. */
  342. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  343. b.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  344. wm->active_time.full = rfixed_mul(line_time, b);
  345. wm->active_time.full = rfixed_div(wm->active_time, a);
  346. /* Maximun bandwidth is the minimun bandwidth of all component */
  347. rdev->pm.max_bandwidth = rdev->pm.core_bandwidth;
  348. if (sideport) {
  349. if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
  350. rdev->pm.sideport_bandwidth.full)
  351. rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
  352. read_delay_latency.full = rfixed_const(370 * 800 * 1000);
  353. read_delay_latency.full = rfixed_div(read_delay_latency,
  354. rdev->pm.igp_sideport_mclk);
  355. } else {
  356. if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
  357. rdev->pm.k8_bandwidth.full)
  358. rdev->pm.max_bandwidth = rdev->pm.k8_bandwidth;
  359. if (rdev->pm.max_bandwidth.full > rdev->pm.ht_bandwidth.full &&
  360. rdev->pm.ht_bandwidth.full)
  361. rdev->pm.max_bandwidth = rdev->pm.ht_bandwidth;
  362. read_delay_latency.full = rfixed_const(5000);
  363. }
  364. /* sclk = system clocks(ns) = 1000 / max_bandwidth / 16 */
  365. a.full = rfixed_const(16);
  366. rdev->pm.sclk.full = rfixed_mul(rdev->pm.max_bandwidth, a);
  367. a.full = rfixed_const(1000);
  368. rdev->pm.sclk.full = rfixed_div(a, rdev->pm.sclk);
  369. /* Determine chunk time
  370. * ChunkTime = the time it takes the DCP to send one chunk of data
  371. * to the LB which consists of pipeline delay and inter chunk gap
  372. * sclk = system clock(ns)
  373. */
  374. a.full = rfixed_const(256 * 13);
  375. chunk_time.full = rfixed_mul(rdev->pm.sclk, a);
  376. a.full = rfixed_const(10);
  377. chunk_time.full = rfixed_div(chunk_time, a);
  378. /* Determine the worst case latency
  379. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  380. * WorstCaseLatency = worst case time from urgent to when the MC starts
  381. * to return data
  382. * READ_DELAY_IDLE_MAX = constant of 1us
  383. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  384. * which consists of pipeline delay and inter chunk gap
  385. */
  386. if (rfixed_trunc(wm->num_line_pair) > 1) {
  387. a.full = rfixed_const(3);
  388. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  389. wm->worst_case_latency.full += read_delay_latency.full;
  390. } else {
  391. a.full = rfixed_const(2);
  392. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  393. wm->worst_case_latency.full += read_delay_latency.full;
  394. }
  395. /* Determine the tolerable latency
  396. * TolerableLatency = Any given request has only 1 line time
  397. * for the data to be returned
  398. * LBRequestFifoDepth = Number of chunk requests the LB can
  399. * put into the request FIFO for a display
  400. * LineTime = total time for one line of display
  401. * ChunkTime = the time it takes the DCP to send one chunk
  402. * of data to the LB which consists of
  403. * pipeline delay and inter chunk gap
  404. */
  405. if ((2+wm->lb_request_fifo_depth) >= rfixed_trunc(request_fifo_depth)) {
  406. tolerable_latency.full = line_time.full;
  407. } else {
  408. tolerable_latency.full = rfixed_const(wm->lb_request_fifo_depth - 2);
  409. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  410. tolerable_latency.full = rfixed_mul(tolerable_latency, chunk_time);
  411. tolerable_latency.full = line_time.full - tolerable_latency.full;
  412. }
  413. /* We assume worst case 32bits (4 bytes) */
  414. wm->dbpp.full = rfixed_const(4 * 8);
  415. /* Determine the maximum priority mark
  416. * width = viewport width in pixels
  417. */
  418. a.full = rfixed_const(16);
  419. wm->priority_mark_max.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  420. wm->priority_mark_max.full = rfixed_div(wm->priority_mark_max, a);
  421. /* Determine estimated width */
  422. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  423. estimated_width.full = rfixed_div(estimated_width, consumption_time);
  424. if (rfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  425. wm->priority_mark.full = rfixed_const(10);
  426. } else {
  427. a.full = rfixed_const(16);
  428. wm->priority_mark.full = rfixed_div(estimated_width, a);
  429. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  430. }
  431. }
  432. void rs690_bandwidth_update(struct radeon_device *rdev)
  433. {
  434. struct drm_display_mode *mode0 = NULL;
  435. struct drm_display_mode *mode1 = NULL;
  436. struct rs690_watermark wm0;
  437. struct rs690_watermark wm1;
  438. u32 tmp;
  439. fixed20_12 priority_mark02, priority_mark12, fill_rate;
  440. fixed20_12 a, b;
  441. if (rdev->mode_info.crtcs[0]->base.enabled)
  442. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  443. if (rdev->mode_info.crtcs[1]->base.enabled)
  444. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  445. /*
  446. * Set display0/1 priority up in the memory controller for
  447. * modes if the user specifies HIGH for displaypriority
  448. * option.
  449. */
  450. if (rdev->disp_priority == 2) {
  451. tmp = RREG32_MC(MC_INIT_MISC_LAT_TIMER);
  452. tmp &= ~MC_DISP1R_INIT_LAT_MASK;
  453. tmp &= ~MC_DISP0R_INIT_LAT_MASK;
  454. if (mode1)
  455. tmp |= (1 << MC_DISP1R_INIT_LAT_SHIFT);
  456. if (mode0)
  457. tmp |= (1 << MC_DISP0R_INIT_LAT_SHIFT);
  458. WREG32_MC(MC_INIT_MISC_LAT_TIMER, tmp);
  459. }
  460. rs690_line_buffer_adjust(rdev, mode0, mode1);
  461. if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740))
  462. WREG32(DCP_CONTROL, 0);
  463. if ((rdev->family == CHIP_RS780) || (rdev->family == CHIP_RS880))
  464. WREG32(DCP_CONTROL, 2);
  465. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0);
  466. rs690_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1);
  467. tmp = (wm0.lb_request_fifo_depth - 1);
  468. tmp |= (wm1.lb_request_fifo_depth - 1) << 16;
  469. WREG32(LB_MAX_REQ_OUTSTANDING, tmp);
  470. if (mode0 && mode1) {
  471. if (rfixed_trunc(wm0.dbpp) > 64)
  472. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  473. else
  474. a.full = wm0.num_line_pair.full;
  475. if (rfixed_trunc(wm1.dbpp) > 64)
  476. b.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  477. else
  478. b.full = wm1.num_line_pair.full;
  479. a.full += b.full;
  480. fill_rate.full = rfixed_div(wm0.sclk, a);
  481. if (wm0.consumption_rate.full > fill_rate.full) {
  482. b.full = wm0.consumption_rate.full - fill_rate.full;
  483. b.full = rfixed_mul(b, wm0.active_time);
  484. a.full = rfixed_mul(wm0.worst_case_latency,
  485. wm0.consumption_rate);
  486. a.full = a.full + b.full;
  487. b.full = rfixed_const(16 * 1000);
  488. priority_mark02.full = rfixed_div(a, b);
  489. } else {
  490. a.full = rfixed_mul(wm0.worst_case_latency,
  491. wm0.consumption_rate);
  492. b.full = rfixed_const(16 * 1000);
  493. priority_mark02.full = rfixed_div(a, b);
  494. }
  495. if (wm1.consumption_rate.full > fill_rate.full) {
  496. b.full = wm1.consumption_rate.full - fill_rate.full;
  497. b.full = rfixed_mul(b, wm1.active_time);
  498. a.full = rfixed_mul(wm1.worst_case_latency,
  499. wm1.consumption_rate);
  500. a.full = a.full + b.full;
  501. b.full = rfixed_const(16 * 1000);
  502. priority_mark12.full = rfixed_div(a, b);
  503. } else {
  504. a.full = rfixed_mul(wm1.worst_case_latency,
  505. wm1.consumption_rate);
  506. b.full = rfixed_const(16 * 1000);
  507. priority_mark12.full = rfixed_div(a, b);
  508. }
  509. if (wm0.priority_mark.full > priority_mark02.full)
  510. priority_mark02.full = wm0.priority_mark.full;
  511. if (rfixed_trunc(priority_mark02) < 0)
  512. priority_mark02.full = 0;
  513. if (wm0.priority_mark_max.full > priority_mark02.full)
  514. priority_mark02.full = wm0.priority_mark_max.full;
  515. if (wm1.priority_mark.full > priority_mark12.full)
  516. priority_mark12.full = wm1.priority_mark.full;
  517. if (rfixed_trunc(priority_mark12) < 0)
  518. priority_mark12.full = 0;
  519. if (wm1.priority_mark_max.full > priority_mark12.full)
  520. priority_mark12.full = wm1.priority_mark_max.full;
  521. WREG32(D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  522. WREG32(D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  523. WREG32(D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  524. WREG32(D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  525. } else if (mode0) {
  526. if (rfixed_trunc(wm0.dbpp) > 64)
  527. a.full = rfixed_mul(wm0.dbpp, wm0.num_line_pair);
  528. else
  529. a.full = wm0.num_line_pair.full;
  530. fill_rate.full = rfixed_div(wm0.sclk, a);
  531. if (wm0.consumption_rate.full > fill_rate.full) {
  532. b.full = wm0.consumption_rate.full - fill_rate.full;
  533. b.full = rfixed_mul(b, wm0.active_time);
  534. a.full = rfixed_mul(wm0.worst_case_latency,
  535. wm0.consumption_rate);
  536. a.full = a.full + b.full;
  537. b.full = rfixed_const(16 * 1000);
  538. priority_mark02.full = rfixed_div(a, b);
  539. } else {
  540. a.full = rfixed_mul(wm0.worst_case_latency,
  541. wm0.consumption_rate);
  542. b.full = rfixed_const(16 * 1000);
  543. priority_mark02.full = rfixed_div(a, b);
  544. }
  545. if (wm0.priority_mark.full > priority_mark02.full)
  546. priority_mark02.full = wm0.priority_mark.full;
  547. if (rfixed_trunc(priority_mark02) < 0)
  548. priority_mark02.full = 0;
  549. if (wm0.priority_mark_max.full > priority_mark02.full)
  550. priority_mark02.full = wm0.priority_mark_max.full;
  551. WREG32(D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  552. WREG32(D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  553. WREG32(D2MODE_PRIORITY_A_CNT, MODE_PRIORITY_OFF);
  554. WREG32(D2MODE_PRIORITY_B_CNT, MODE_PRIORITY_OFF);
  555. } else {
  556. if (rfixed_trunc(wm1.dbpp) > 64)
  557. a.full = rfixed_mul(wm1.dbpp, wm1.num_line_pair);
  558. else
  559. a.full = wm1.num_line_pair.full;
  560. fill_rate.full = rfixed_div(wm1.sclk, a);
  561. if (wm1.consumption_rate.full > fill_rate.full) {
  562. b.full = wm1.consumption_rate.full - fill_rate.full;
  563. b.full = rfixed_mul(b, wm1.active_time);
  564. a.full = rfixed_mul(wm1.worst_case_latency,
  565. wm1.consumption_rate);
  566. a.full = a.full + b.full;
  567. b.full = rfixed_const(16 * 1000);
  568. priority_mark12.full = rfixed_div(a, b);
  569. } else {
  570. a.full = rfixed_mul(wm1.worst_case_latency,
  571. wm1.consumption_rate);
  572. b.full = rfixed_const(16 * 1000);
  573. priority_mark12.full = rfixed_div(a, b);
  574. }
  575. if (wm1.priority_mark.full > priority_mark12.full)
  576. priority_mark12.full = wm1.priority_mark.full;
  577. if (rfixed_trunc(priority_mark12) < 0)
  578. priority_mark12.full = 0;
  579. if (wm1.priority_mark_max.full > priority_mark12.full)
  580. priority_mark12.full = wm1.priority_mark_max.full;
  581. WREG32(D1MODE_PRIORITY_A_CNT, MODE_PRIORITY_OFF);
  582. WREG32(D1MODE_PRIORITY_B_CNT, MODE_PRIORITY_OFF);
  583. WREG32(D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  584. WREG32(D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  585. }
  586. }
  587. /*
  588. * Indirect registers accessor
  589. */
  590. uint32_t rs690_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  591. {
  592. uint32_t r;
  593. WREG32(RS690_MC_INDEX, (reg & RS690_MC_INDEX_MASK));
  594. r = RREG32(RS690_MC_DATA);
  595. WREG32(RS690_MC_INDEX, RS690_MC_INDEX_MASK);
  596. return r;
  597. }
  598. void rs690_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  599. {
  600. WREG32(RS690_MC_INDEX,
  601. RS690_MC_INDEX_WR_EN | ((reg) & RS690_MC_INDEX_MASK));
  602. WREG32(RS690_MC_DATA, v);
  603. WREG32(RS690_MC_INDEX, RS690_MC_INDEX_WR_ACK);
  604. }