rs690.c 23 KB

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