rs690.c 22 KB

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