rv515.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101
  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 <linux/seq_file.h>
  29. #include "drmP.h"
  30. #include "rv515r.h"
  31. #include "radeon.h"
  32. #include "radeon_share.h"
  33. /* rv515 depends on : */
  34. void r100_hdp_reset(struct radeon_device *rdev);
  35. int r100_cp_reset(struct radeon_device *rdev);
  36. int r100_rb2d_reset(struct radeon_device *rdev);
  37. int r100_gui_wait_for_idle(struct radeon_device *rdev);
  38. int r100_cp_init(struct radeon_device *rdev, unsigned ring_size);
  39. int rv370_pcie_gart_enable(struct radeon_device *rdev);
  40. void rv370_pcie_gart_disable(struct radeon_device *rdev);
  41. void r420_pipes_init(struct radeon_device *rdev);
  42. void rs600_mc_disable_clients(struct radeon_device *rdev);
  43. void rs600_disable_vga(struct radeon_device *rdev);
  44. /* This files gather functions specifics to:
  45. * rv515
  46. *
  47. * Some of these functions might be used by newer ASICs.
  48. */
  49. int rv515_debugfs_pipes_info_init(struct radeon_device *rdev);
  50. int rv515_debugfs_ga_info_init(struct radeon_device *rdev);
  51. void rv515_gpu_init(struct radeon_device *rdev);
  52. int rv515_mc_wait_for_idle(struct radeon_device *rdev);
  53. /*
  54. * MC
  55. */
  56. int rv515_mc_init(struct radeon_device *rdev)
  57. {
  58. uint32_t tmp;
  59. int r;
  60. if (r100_debugfs_rbbm_init(rdev)) {
  61. DRM_ERROR("Failed to register debugfs file for RBBM !\n");
  62. }
  63. if (rv515_debugfs_pipes_info_init(rdev)) {
  64. DRM_ERROR("Failed to register debugfs file for pipes !\n");
  65. }
  66. if (rv515_debugfs_ga_info_init(rdev)) {
  67. DRM_ERROR("Failed to register debugfs file for pipes !\n");
  68. }
  69. rv515_gpu_init(rdev);
  70. rv370_pcie_gart_disable(rdev);
  71. /* Setup GPU memory space */
  72. rdev->mc.vram_location = 0xFFFFFFFFUL;
  73. rdev->mc.gtt_location = 0xFFFFFFFFUL;
  74. if (rdev->flags & RADEON_IS_AGP) {
  75. r = radeon_agp_init(rdev);
  76. if (r) {
  77. printk(KERN_WARNING "[drm] Disabling AGP\n");
  78. rdev->flags &= ~RADEON_IS_AGP;
  79. rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
  80. } else {
  81. rdev->mc.gtt_location = rdev->mc.agp_base;
  82. }
  83. }
  84. r = radeon_mc_setup(rdev);
  85. if (r) {
  86. return r;
  87. }
  88. /* Program GPU memory space */
  89. rs600_mc_disable_clients(rdev);
  90. if (rv515_mc_wait_for_idle(rdev)) {
  91. printk(KERN_WARNING "Failed to wait MC idle while "
  92. "programming pipes. Bad things might happen.\n");
  93. }
  94. /* Write VRAM size in case we are limiting it */
  95. WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.real_vram_size);
  96. tmp = REG_SET(MC_FB_START, rdev->mc.vram_location >> 16);
  97. WREG32(0x134, tmp);
  98. tmp = rdev->mc.vram_location + rdev->mc.mc_vram_size - 1;
  99. tmp = REG_SET(MC_FB_TOP, tmp >> 16);
  100. tmp |= REG_SET(MC_FB_START, rdev->mc.vram_location >> 16);
  101. WREG32_MC(MC_FB_LOCATION, tmp);
  102. WREG32(HDP_FB_LOCATION, rdev->mc.vram_location >> 16);
  103. WREG32(0x310, rdev->mc.vram_location);
  104. if (rdev->flags & RADEON_IS_AGP) {
  105. tmp = rdev->mc.gtt_location + rdev->mc.gtt_size - 1;
  106. tmp = REG_SET(MC_AGP_TOP, tmp >> 16);
  107. tmp |= REG_SET(MC_AGP_START, rdev->mc.gtt_location >> 16);
  108. WREG32_MC(MC_AGP_LOCATION, tmp);
  109. WREG32_MC(MC_AGP_BASE, rdev->mc.agp_base);
  110. WREG32_MC(MC_AGP_BASE_2, 0);
  111. } else {
  112. WREG32_MC(MC_AGP_LOCATION, 0x0FFFFFFF);
  113. WREG32_MC(MC_AGP_BASE, 0);
  114. WREG32_MC(MC_AGP_BASE_2, 0);
  115. }
  116. return 0;
  117. }
  118. void rv515_mc_fini(struct radeon_device *rdev)
  119. {
  120. rv370_pcie_gart_disable(rdev);
  121. radeon_gart_table_vram_free(rdev);
  122. radeon_gart_fini(rdev);
  123. }
  124. /*
  125. * Global GPU functions
  126. */
  127. void rv515_ring_start(struct radeon_device *rdev)
  128. {
  129. int r;
  130. r = radeon_ring_lock(rdev, 64);
  131. if (r) {
  132. return;
  133. }
  134. radeon_ring_write(rdev, PACKET0(ISYNC_CNTL, 0));
  135. radeon_ring_write(rdev,
  136. ISYNC_ANY2D_IDLE3D |
  137. ISYNC_ANY3D_IDLE2D |
  138. ISYNC_WAIT_IDLEGUI |
  139. ISYNC_CPSCRATCH_IDLEGUI);
  140. radeon_ring_write(rdev, PACKET0(WAIT_UNTIL, 0));
  141. radeon_ring_write(rdev, WAIT_2D_IDLECLEAN | WAIT_3D_IDLECLEAN);
  142. radeon_ring_write(rdev, PACKET0(0x170C, 0));
  143. radeon_ring_write(rdev, 1 << 31);
  144. radeon_ring_write(rdev, PACKET0(GB_SELECT, 0));
  145. radeon_ring_write(rdev, 0);
  146. radeon_ring_write(rdev, PACKET0(GB_ENABLE, 0));
  147. radeon_ring_write(rdev, 0);
  148. radeon_ring_write(rdev, PACKET0(0x42C8, 0));
  149. radeon_ring_write(rdev, (1 << rdev->num_gb_pipes) - 1);
  150. radeon_ring_write(rdev, PACKET0(VAP_INDEX_OFFSET, 0));
  151. radeon_ring_write(rdev, 0);
  152. radeon_ring_write(rdev, PACKET0(RB3D_DSTCACHE_CTLSTAT, 0));
  153. radeon_ring_write(rdev, RB3D_DC_FLUSH | RB3D_DC_FREE);
  154. radeon_ring_write(rdev, PACKET0(ZB_ZCACHE_CTLSTAT, 0));
  155. radeon_ring_write(rdev, ZC_FLUSH | ZC_FREE);
  156. radeon_ring_write(rdev, PACKET0(WAIT_UNTIL, 0));
  157. radeon_ring_write(rdev, WAIT_2D_IDLECLEAN | WAIT_3D_IDLECLEAN);
  158. radeon_ring_write(rdev, PACKET0(GB_AA_CONFIG, 0));
  159. radeon_ring_write(rdev, 0);
  160. radeon_ring_write(rdev, PACKET0(RB3D_DSTCACHE_CTLSTAT, 0));
  161. radeon_ring_write(rdev, RB3D_DC_FLUSH | RB3D_DC_FREE);
  162. radeon_ring_write(rdev, PACKET0(ZB_ZCACHE_CTLSTAT, 0));
  163. radeon_ring_write(rdev, ZC_FLUSH | ZC_FREE);
  164. radeon_ring_write(rdev, PACKET0(GB_MSPOS0, 0));
  165. radeon_ring_write(rdev,
  166. ((6 << MS_X0_SHIFT) |
  167. (6 << MS_Y0_SHIFT) |
  168. (6 << MS_X1_SHIFT) |
  169. (6 << MS_Y1_SHIFT) |
  170. (6 << MS_X2_SHIFT) |
  171. (6 << MS_Y2_SHIFT) |
  172. (6 << MSBD0_Y_SHIFT) |
  173. (6 << MSBD0_X_SHIFT)));
  174. radeon_ring_write(rdev, PACKET0(GB_MSPOS1, 0));
  175. radeon_ring_write(rdev,
  176. ((6 << MS_X3_SHIFT) |
  177. (6 << MS_Y3_SHIFT) |
  178. (6 << MS_X4_SHIFT) |
  179. (6 << MS_Y4_SHIFT) |
  180. (6 << MS_X5_SHIFT) |
  181. (6 << MS_Y5_SHIFT) |
  182. (6 << MSBD1_SHIFT)));
  183. radeon_ring_write(rdev, PACKET0(GA_ENHANCE, 0));
  184. radeon_ring_write(rdev, GA_DEADLOCK_CNTL | GA_FASTSYNC_CNTL);
  185. radeon_ring_write(rdev, PACKET0(GA_POLY_MODE, 0));
  186. radeon_ring_write(rdev, FRONT_PTYPE_TRIANGE | BACK_PTYPE_TRIANGE);
  187. radeon_ring_write(rdev, PACKET0(GA_ROUND_MODE, 0));
  188. radeon_ring_write(rdev, GEOMETRY_ROUND_NEAREST | COLOR_ROUND_NEAREST);
  189. radeon_ring_write(rdev, PACKET0(0x20C8, 0));
  190. radeon_ring_write(rdev, 0);
  191. radeon_ring_unlock_commit(rdev);
  192. }
  193. void rv515_errata(struct radeon_device *rdev)
  194. {
  195. rdev->pll_errata = 0;
  196. }
  197. int rv515_mc_wait_for_idle(struct radeon_device *rdev)
  198. {
  199. unsigned i;
  200. uint32_t tmp;
  201. for (i = 0; i < rdev->usec_timeout; i++) {
  202. /* read MC_STATUS */
  203. tmp = RREG32_MC(MC_STATUS);
  204. if (tmp & MC_STATUS_IDLE) {
  205. return 0;
  206. }
  207. DRM_UDELAY(1);
  208. }
  209. return -1;
  210. }
  211. void rv515_gpu_init(struct radeon_device *rdev)
  212. {
  213. unsigned pipe_select_current, gb_pipe_select, tmp;
  214. r100_hdp_reset(rdev);
  215. r100_rb2d_reset(rdev);
  216. if (r100_gui_wait_for_idle(rdev)) {
  217. printk(KERN_WARNING "Failed to wait GUI idle while "
  218. "reseting GPU. Bad things might happen.\n");
  219. }
  220. rs600_disable_vga(rdev);
  221. r420_pipes_init(rdev);
  222. gb_pipe_select = RREG32(0x402C);
  223. tmp = RREG32(0x170C);
  224. pipe_select_current = (tmp >> 2) & 3;
  225. tmp = (1 << pipe_select_current) |
  226. (((gb_pipe_select >> 8) & 0xF) << 4);
  227. WREG32_PLL(0x000D, tmp);
  228. if (r100_gui_wait_for_idle(rdev)) {
  229. printk(KERN_WARNING "Failed to wait GUI idle while "
  230. "reseting GPU. Bad things might happen.\n");
  231. }
  232. if (rv515_mc_wait_for_idle(rdev)) {
  233. printk(KERN_WARNING "Failed to wait MC idle while "
  234. "programming pipes. Bad things might happen.\n");
  235. }
  236. }
  237. int rv515_ga_reset(struct radeon_device *rdev)
  238. {
  239. uint32_t tmp;
  240. bool reinit_cp;
  241. int i;
  242. reinit_cp = rdev->cp.ready;
  243. rdev->cp.ready = false;
  244. for (i = 0; i < rdev->usec_timeout; i++) {
  245. WREG32(CP_CSQ_MODE, 0);
  246. WREG32(CP_CSQ_CNTL, 0);
  247. WREG32(RBBM_SOFT_RESET, 0x32005);
  248. (void)RREG32(RBBM_SOFT_RESET);
  249. udelay(200);
  250. WREG32(RBBM_SOFT_RESET, 0);
  251. /* Wait to prevent race in RBBM_STATUS */
  252. mdelay(1);
  253. tmp = RREG32(RBBM_STATUS);
  254. if (tmp & ((1 << 20) | (1 << 26))) {
  255. DRM_ERROR("VAP & CP still busy (RBBM_STATUS=0x%08X)\n", tmp);
  256. /* GA still busy soft reset it */
  257. WREG32(0x429C, 0x200);
  258. WREG32(VAP_PVS_STATE_FLUSH_REG, 0);
  259. WREG32(0x43E0, 0);
  260. WREG32(0x43E4, 0);
  261. WREG32(0x24AC, 0);
  262. }
  263. /* Wait to prevent race in RBBM_STATUS */
  264. mdelay(1);
  265. tmp = RREG32(RBBM_STATUS);
  266. if (!(tmp & ((1 << 20) | (1 << 26)))) {
  267. break;
  268. }
  269. }
  270. for (i = 0; i < rdev->usec_timeout; i++) {
  271. tmp = RREG32(RBBM_STATUS);
  272. if (!(tmp & ((1 << 20) | (1 << 26)))) {
  273. DRM_INFO("GA reset succeed (RBBM_STATUS=0x%08X)\n",
  274. tmp);
  275. DRM_INFO("GA_IDLE=0x%08X\n", RREG32(0x425C));
  276. DRM_INFO("RB3D_RESET_STATUS=0x%08X\n", RREG32(0x46f0));
  277. DRM_INFO("ISYNC_CNTL=0x%08X\n", RREG32(0x1724));
  278. if (reinit_cp) {
  279. return r100_cp_init(rdev, rdev->cp.ring_size);
  280. }
  281. return 0;
  282. }
  283. DRM_UDELAY(1);
  284. }
  285. tmp = RREG32(RBBM_STATUS);
  286. DRM_ERROR("Failed to reset GA ! (RBBM_STATUS=0x%08X)\n", tmp);
  287. return -1;
  288. }
  289. int rv515_gpu_reset(struct radeon_device *rdev)
  290. {
  291. uint32_t status;
  292. /* reset order likely matter */
  293. status = RREG32(RBBM_STATUS);
  294. /* reset HDP */
  295. r100_hdp_reset(rdev);
  296. /* reset rb2d */
  297. if (status & ((1 << 17) | (1 << 18) | (1 << 27))) {
  298. r100_rb2d_reset(rdev);
  299. }
  300. /* reset GA */
  301. if (status & ((1 << 20) | (1 << 26))) {
  302. rv515_ga_reset(rdev);
  303. }
  304. /* reset CP */
  305. status = RREG32(RBBM_STATUS);
  306. if (status & (1 << 16)) {
  307. r100_cp_reset(rdev);
  308. }
  309. /* Check if GPU is idle */
  310. status = RREG32(RBBM_STATUS);
  311. if (status & (1 << 31)) {
  312. DRM_ERROR("Failed to reset GPU (RBBM_STATUS=0x%08X)\n", status);
  313. return -1;
  314. }
  315. DRM_INFO("GPU reset succeed (RBBM_STATUS=0x%08X)\n", status);
  316. return 0;
  317. }
  318. /*
  319. * VRAM info
  320. */
  321. static void rv515_vram_get_type(struct radeon_device *rdev)
  322. {
  323. uint32_t tmp;
  324. rdev->mc.vram_width = 128;
  325. rdev->mc.vram_is_ddr = true;
  326. tmp = RREG32_MC(RV515_MC_CNTL) & MEM_NUM_CHANNELS_MASK;
  327. switch (tmp) {
  328. case 0:
  329. rdev->mc.vram_width = 64;
  330. break;
  331. case 1:
  332. rdev->mc.vram_width = 128;
  333. break;
  334. default:
  335. rdev->mc.vram_width = 128;
  336. break;
  337. }
  338. }
  339. void rv515_vram_info(struct radeon_device *rdev)
  340. {
  341. fixed20_12 a;
  342. rv515_vram_get_type(rdev);
  343. r100_vram_init_sizes(rdev);
  344. /* FIXME: we should enforce default clock in case GPU is not in
  345. * default setup
  346. */
  347. a.full = rfixed_const(100);
  348. rdev->pm.sclk.full = rfixed_const(rdev->clock.default_sclk);
  349. rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a);
  350. }
  351. /*
  352. * Indirect registers accessor
  353. */
  354. uint32_t rv515_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  355. {
  356. uint32_t r;
  357. WREG32(MC_IND_INDEX, 0x7f0000 | (reg & 0xffff));
  358. r = RREG32(MC_IND_DATA);
  359. WREG32(MC_IND_INDEX, 0);
  360. return r;
  361. }
  362. void rv515_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  363. {
  364. WREG32(MC_IND_INDEX, 0xff0000 | ((reg) & 0xffff));
  365. WREG32(MC_IND_DATA, (v));
  366. WREG32(MC_IND_INDEX, 0);
  367. }
  368. uint32_t rv515_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  369. {
  370. uint32_t r;
  371. WREG32(PCIE_INDEX, ((reg) & 0x7ff));
  372. (void)RREG32(PCIE_INDEX);
  373. r = RREG32(PCIE_DATA);
  374. return r;
  375. }
  376. void rv515_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  377. {
  378. WREG32(PCIE_INDEX, ((reg) & 0x7ff));
  379. (void)RREG32(PCIE_INDEX);
  380. WREG32(PCIE_DATA, (v));
  381. (void)RREG32(PCIE_DATA);
  382. }
  383. /*
  384. * Debugfs info
  385. */
  386. #if defined(CONFIG_DEBUG_FS)
  387. static int rv515_debugfs_pipes_info(struct seq_file *m, void *data)
  388. {
  389. struct drm_info_node *node = (struct drm_info_node *) m->private;
  390. struct drm_device *dev = node->minor->dev;
  391. struct radeon_device *rdev = dev->dev_private;
  392. uint32_t tmp;
  393. tmp = RREG32(GB_PIPE_SELECT);
  394. seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
  395. tmp = RREG32(SU_REG_DEST);
  396. seq_printf(m, "SU_REG_DEST 0x%08x\n", tmp);
  397. tmp = RREG32(GB_TILE_CONFIG);
  398. seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
  399. tmp = RREG32(DST_PIPE_CONFIG);
  400. seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
  401. return 0;
  402. }
  403. static int rv515_debugfs_ga_info(struct seq_file *m, void *data)
  404. {
  405. struct drm_info_node *node = (struct drm_info_node *) m->private;
  406. struct drm_device *dev = node->minor->dev;
  407. struct radeon_device *rdev = dev->dev_private;
  408. uint32_t tmp;
  409. tmp = RREG32(0x2140);
  410. seq_printf(m, "VAP_CNTL_STATUS 0x%08x\n", tmp);
  411. radeon_gpu_reset(rdev);
  412. tmp = RREG32(0x425C);
  413. seq_printf(m, "GA_IDLE 0x%08x\n", tmp);
  414. return 0;
  415. }
  416. static struct drm_info_list rv515_pipes_info_list[] = {
  417. {"rv515_pipes_info", rv515_debugfs_pipes_info, 0, NULL},
  418. };
  419. static struct drm_info_list rv515_ga_info_list[] = {
  420. {"rv515_ga_info", rv515_debugfs_ga_info, 0, NULL},
  421. };
  422. #endif
  423. int rv515_debugfs_pipes_info_init(struct radeon_device *rdev)
  424. {
  425. #if defined(CONFIG_DEBUG_FS)
  426. return radeon_debugfs_add_files(rdev, rv515_pipes_info_list, 1);
  427. #else
  428. return 0;
  429. #endif
  430. }
  431. int rv515_debugfs_ga_info_init(struct radeon_device *rdev)
  432. {
  433. #if defined(CONFIG_DEBUG_FS)
  434. return radeon_debugfs_add_files(rdev, rv515_ga_info_list, 1);
  435. #else
  436. return 0;
  437. #endif
  438. }
  439. /*
  440. * Asic initialization
  441. */
  442. static const unsigned r500_reg_safe_bm[219] = {
  443. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  444. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  445. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  446. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  447. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  448. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  449. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  450. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  451. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  452. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  453. 0x17FF1FFF, 0xFFFFFFFC, 0xFFFFFFFF, 0xFF30FFBF,
  454. 0xFFFFFFF8, 0xC3E6FFFF, 0xFFFFF6DF, 0xFFFFFFFF,
  455. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  456. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  457. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFF03F,
  458. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  459. 0xFFFFFFFF, 0xFFFFEFCE, 0xF00EBFFF, 0x007C0000,
  460. 0xF0000038, 0xFF000009, 0xFFFFFFFF, 0xFFFFFFFF,
  461. 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0xFFFFFFFF,
  462. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  463. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  464. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  465. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  466. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  467. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  468. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  469. 0xFFFFF7FF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  470. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  471. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  472. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  473. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  474. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  475. 0x1FFFFC78, 0xFFFFE000, 0xFFFFFFFE, 0xFFFFFFFF,
  476. 0x38CF8F50, 0xFFF88082, 0xFF0000FC, 0xFAE009FF,
  477. 0x0000FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000,
  478. 0xFFFF8CFC, 0xFFFFC1FF, 0xFFFFFFFF, 0xFFFFFFFF,
  479. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  480. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFF80FFFF,
  481. 0x00000000, 0x00000000, 0x00000000, 0x00000000,
  482. 0x0003FC01, 0x3FFFFCF8, 0xFE800B19, 0xFFFFFFFF,
  483. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  484. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  485. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  486. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  487. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  488. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  489. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  490. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  491. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  492. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  493. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  494. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  495. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  496. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  497. 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF,
  498. };
  499. int rv515_init(struct radeon_device *rdev)
  500. {
  501. rdev->config.r300.reg_safe_bm = r500_reg_safe_bm;
  502. rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r500_reg_safe_bm);
  503. return 0;
  504. }
  505. void atom_rv515_force_tv_scaler(struct radeon_device *rdev)
  506. {
  507. WREG32(0x659C, 0x0);
  508. WREG32(0x6594, 0x705);
  509. WREG32(0x65A4, 0x10001);
  510. WREG32(0x65D8, 0x0);
  511. WREG32(0x65B0, 0x0);
  512. WREG32(0x65C0, 0x0);
  513. WREG32(0x65D4, 0x0);
  514. WREG32(0x6578, 0x0);
  515. WREG32(0x657C, 0x841880A8);
  516. WREG32(0x6578, 0x1);
  517. WREG32(0x657C, 0x84208680);
  518. WREG32(0x6578, 0x2);
  519. WREG32(0x657C, 0xBFF880B0);
  520. WREG32(0x6578, 0x100);
  521. WREG32(0x657C, 0x83D88088);
  522. WREG32(0x6578, 0x101);
  523. WREG32(0x657C, 0x84608680);
  524. WREG32(0x6578, 0x102);
  525. WREG32(0x657C, 0xBFF080D0);
  526. WREG32(0x6578, 0x200);
  527. WREG32(0x657C, 0x83988068);
  528. WREG32(0x6578, 0x201);
  529. WREG32(0x657C, 0x84A08680);
  530. WREG32(0x6578, 0x202);
  531. WREG32(0x657C, 0xBFF080F8);
  532. WREG32(0x6578, 0x300);
  533. WREG32(0x657C, 0x83588058);
  534. WREG32(0x6578, 0x301);
  535. WREG32(0x657C, 0x84E08660);
  536. WREG32(0x6578, 0x302);
  537. WREG32(0x657C, 0xBFF88120);
  538. WREG32(0x6578, 0x400);
  539. WREG32(0x657C, 0x83188040);
  540. WREG32(0x6578, 0x401);
  541. WREG32(0x657C, 0x85008660);
  542. WREG32(0x6578, 0x402);
  543. WREG32(0x657C, 0xBFF88150);
  544. WREG32(0x6578, 0x500);
  545. WREG32(0x657C, 0x82D88030);
  546. WREG32(0x6578, 0x501);
  547. WREG32(0x657C, 0x85408640);
  548. WREG32(0x6578, 0x502);
  549. WREG32(0x657C, 0xBFF88180);
  550. WREG32(0x6578, 0x600);
  551. WREG32(0x657C, 0x82A08018);
  552. WREG32(0x6578, 0x601);
  553. WREG32(0x657C, 0x85808620);
  554. WREG32(0x6578, 0x602);
  555. WREG32(0x657C, 0xBFF081B8);
  556. WREG32(0x6578, 0x700);
  557. WREG32(0x657C, 0x82608010);
  558. WREG32(0x6578, 0x701);
  559. WREG32(0x657C, 0x85A08600);
  560. WREG32(0x6578, 0x702);
  561. WREG32(0x657C, 0x800081F0);
  562. WREG32(0x6578, 0x800);
  563. WREG32(0x657C, 0x8228BFF8);
  564. WREG32(0x6578, 0x801);
  565. WREG32(0x657C, 0x85E085E0);
  566. WREG32(0x6578, 0x802);
  567. WREG32(0x657C, 0xBFF88228);
  568. WREG32(0x6578, 0x10000);
  569. WREG32(0x657C, 0x82A8BF00);
  570. WREG32(0x6578, 0x10001);
  571. WREG32(0x657C, 0x82A08CC0);
  572. WREG32(0x6578, 0x10002);
  573. WREG32(0x657C, 0x8008BEF8);
  574. WREG32(0x6578, 0x10100);
  575. WREG32(0x657C, 0x81F0BF28);
  576. WREG32(0x6578, 0x10101);
  577. WREG32(0x657C, 0x83608CA0);
  578. WREG32(0x6578, 0x10102);
  579. WREG32(0x657C, 0x8018BED0);
  580. WREG32(0x6578, 0x10200);
  581. WREG32(0x657C, 0x8148BF38);
  582. WREG32(0x6578, 0x10201);
  583. WREG32(0x657C, 0x84408C80);
  584. WREG32(0x6578, 0x10202);
  585. WREG32(0x657C, 0x8008BEB8);
  586. WREG32(0x6578, 0x10300);
  587. WREG32(0x657C, 0x80B0BF78);
  588. WREG32(0x6578, 0x10301);
  589. WREG32(0x657C, 0x85008C20);
  590. WREG32(0x6578, 0x10302);
  591. WREG32(0x657C, 0x8020BEA0);
  592. WREG32(0x6578, 0x10400);
  593. WREG32(0x657C, 0x8028BF90);
  594. WREG32(0x6578, 0x10401);
  595. WREG32(0x657C, 0x85E08BC0);
  596. WREG32(0x6578, 0x10402);
  597. WREG32(0x657C, 0x8018BE90);
  598. WREG32(0x6578, 0x10500);
  599. WREG32(0x657C, 0xBFB8BFB0);
  600. WREG32(0x6578, 0x10501);
  601. WREG32(0x657C, 0x86C08B40);
  602. WREG32(0x6578, 0x10502);
  603. WREG32(0x657C, 0x8010BE90);
  604. WREG32(0x6578, 0x10600);
  605. WREG32(0x657C, 0xBF58BFC8);
  606. WREG32(0x6578, 0x10601);
  607. WREG32(0x657C, 0x87A08AA0);
  608. WREG32(0x6578, 0x10602);
  609. WREG32(0x657C, 0x8010BE98);
  610. WREG32(0x6578, 0x10700);
  611. WREG32(0x657C, 0xBF10BFF0);
  612. WREG32(0x6578, 0x10701);
  613. WREG32(0x657C, 0x886089E0);
  614. WREG32(0x6578, 0x10702);
  615. WREG32(0x657C, 0x8018BEB0);
  616. WREG32(0x6578, 0x10800);
  617. WREG32(0x657C, 0xBED8BFE8);
  618. WREG32(0x6578, 0x10801);
  619. WREG32(0x657C, 0x89408940);
  620. WREG32(0x6578, 0x10802);
  621. WREG32(0x657C, 0xBFE8BED8);
  622. WREG32(0x6578, 0x20000);
  623. WREG32(0x657C, 0x80008000);
  624. WREG32(0x6578, 0x20001);
  625. WREG32(0x657C, 0x90008000);
  626. WREG32(0x6578, 0x20002);
  627. WREG32(0x657C, 0x80008000);
  628. WREG32(0x6578, 0x20003);
  629. WREG32(0x657C, 0x80008000);
  630. WREG32(0x6578, 0x20100);
  631. WREG32(0x657C, 0x80108000);
  632. WREG32(0x6578, 0x20101);
  633. WREG32(0x657C, 0x8FE0BF70);
  634. WREG32(0x6578, 0x20102);
  635. WREG32(0x657C, 0xBFE880C0);
  636. WREG32(0x6578, 0x20103);
  637. WREG32(0x657C, 0x80008000);
  638. WREG32(0x6578, 0x20200);
  639. WREG32(0x657C, 0x8018BFF8);
  640. WREG32(0x6578, 0x20201);
  641. WREG32(0x657C, 0x8F80BF08);
  642. WREG32(0x6578, 0x20202);
  643. WREG32(0x657C, 0xBFD081A0);
  644. WREG32(0x6578, 0x20203);
  645. WREG32(0x657C, 0xBFF88000);
  646. WREG32(0x6578, 0x20300);
  647. WREG32(0x657C, 0x80188000);
  648. WREG32(0x6578, 0x20301);
  649. WREG32(0x657C, 0x8EE0BEC0);
  650. WREG32(0x6578, 0x20302);
  651. WREG32(0x657C, 0xBFB082A0);
  652. WREG32(0x6578, 0x20303);
  653. WREG32(0x657C, 0x80008000);
  654. WREG32(0x6578, 0x20400);
  655. WREG32(0x657C, 0x80188000);
  656. WREG32(0x6578, 0x20401);
  657. WREG32(0x657C, 0x8E00BEA0);
  658. WREG32(0x6578, 0x20402);
  659. WREG32(0x657C, 0xBF8883C0);
  660. WREG32(0x6578, 0x20403);
  661. WREG32(0x657C, 0x80008000);
  662. WREG32(0x6578, 0x20500);
  663. WREG32(0x657C, 0x80188000);
  664. WREG32(0x6578, 0x20501);
  665. WREG32(0x657C, 0x8D00BE90);
  666. WREG32(0x6578, 0x20502);
  667. WREG32(0x657C, 0xBF588500);
  668. WREG32(0x6578, 0x20503);
  669. WREG32(0x657C, 0x80008008);
  670. WREG32(0x6578, 0x20600);
  671. WREG32(0x657C, 0x80188000);
  672. WREG32(0x6578, 0x20601);
  673. WREG32(0x657C, 0x8BC0BE98);
  674. WREG32(0x6578, 0x20602);
  675. WREG32(0x657C, 0xBF308660);
  676. WREG32(0x6578, 0x20603);
  677. WREG32(0x657C, 0x80008008);
  678. WREG32(0x6578, 0x20700);
  679. WREG32(0x657C, 0x80108000);
  680. WREG32(0x6578, 0x20701);
  681. WREG32(0x657C, 0x8A80BEB0);
  682. WREG32(0x6578, 0x20702);
  683. WREG32(0x657C, 0xBF0087C0);
  684. WREG32(0x6578, 0x20703);
  685. WREG32(0x657C, 0x80008008);
  686. WREG32(0x6578, 0x20800);
  687. WREG32(0x657C, 0x80108000);
  688. WREG32(0x6578, 0x20801);
  689. WREG32(0x657C, 0x8920BED0);
  690. WREG32(0x6578, 0x20802);
  691. WREG32(0x657C, 0xBED08920);
  692. WREG32(0x6578, 0x20803);
  693. WREG32(0x657C, 0x80008010);
  694. WREG32(0x6578, 0x30000);
  695. WREG32(0x657C, 0x90008000);
  696. WREG32(0x6578, 0x30001);
  697. WREG32(0x657C, 0x80008000);
  698. WREG32(0x6578, 0x30100);
  699. WREG32(0x657C, 0x8FE0BF90);
  700. WREG32(0x6578, 0x30101);
  701. WREG32(0x657C, 0xBFF880A0);
  702. WREG32(0x6578, 0x30200);
  703. WREG32(0x657C, 0x8F60BF40);
  704. WREG32(0x6578, 0x30201);
  705. WREG32(0x657C, 0xBFE88180);
  706. WREG32(0x6578, 0x30300);
  707. WREG32(0x657C, 0x8EC0BF00);
  708. WREG32(0x6578, 0x30301);
  709. WREG32(0x657C, 0xBFC88280);
  710. WREG32(0x6578, 0x30400);
  711. WREG32(0x657C, 0x8DE0BEE0);
  712. WREG32(0x6578, 0x30401);
  713. WREG32(0x657C, 0xBFA083A0);
  714. WREG32(0x6578, 0x30500);
  715. WREG32(0x657C, 0x8CE0BED0);
  716. WREG32(0x6578, 0x30501);
  717. WREG32(0x657C, 0xBF7884E0);
  718. WREG32(0x6578, 0x30600);
  719. WREG32(0x657C, 0x8BA0BED8);
  720. WREG32(0x6578, 0x30601);
  721. WREG32(0x657C, 0xBF508640);
  722. WREG32(0x6578, 0x30700);
  723. WREG32(0x657C, 0x8A60BEE8);
  724. WREG32(0x6578, 0x30701);
  725. WREG32(0x657C, 0xBF2087A0);
  726. WREG32(0x6578, 0x30800);
  727. WREG32(0x657C, 0x8900BF00);
  728. WREG32(0x6578, 0x30801);
  729. WREG32(0x657C, 0xBF008900);
  730. }
  731. struct rv515_watermark {
  732. u32 lb_request_fifo_depth;
  733. fixed20_12 num_line_pair;
  734. fixed20_12 estimated_width;
  735. fixed20_12 worst_case_latency;
  736. fixed20_12 consumption_rate;
  737. fixed20_12 active_time;
  738. fixed20_12 dbpp;
  739. fixed20_12 priority_mark_max;
  740. fixed20_12 priority_mark;
  741. fixed20_12 sclk;
  742. };
  743. void rv515_crtc_bandwidth_compute(struct radeon_device *rdev,
  744. struct radeon_crtc *crtc,
  745. struct rv515_watermark *wm)
  746. {
  747. struct drm_display_mode *mode = &crtc->base.mode;
  748. fixed20_12 a, b, c;
  749. fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
  750. fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
  751. if (!crtc->base.enabled) {
  752. /* FIXME: wouldn't it better to set priority mark to maximum */
  753. wm->lb_request_fifo_depth = 4;
  754. return;
  755. }
  756. if (crtc->vsc.full > rfixed_const(2))
  757. wm->num_line_pair.full = rfixed_const(2);
  758. else
  759. wm->num_line_pair.full = rfixed_const(1);
  760. b.full = rfixed_const(mode->crtc_hdisplay);
  761. c.full = rfixed_const(256);
  762. a.full = rfixed_mul(wm->num_line_pair, b);
  763. request_fifo_depth.full = rfixed_div(a, c);
  764. if (a.full < rfixed_const(4)) {
  765. wm->lb_request_fifo_depth = 4;
  766. } else {
  767. wm->lb_request_fifo_depth = rfixed_trunc(request_fifo_depth);
  768. }
  769. /* Determine consumption rate
  770. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  771. * vtaps = number of vertical taps,
  772. * vsc = vertical scaling ratio, defined as source/destination
  773. * hsc = horizontal scaling ration, defined as source/destination
  774. */
  775. a.full = rfixed_const(mode->clock);
  776. b.full = rfixed_const(1000);
  777. a.full = rfixed_div(a, b);
  778. pclk.full = rfixed_div(b, a);
  779. if (crtc->rmx_type != RMX_OFF) {
  780. b.full = rfixed_const(2);
  781. if (crtc->vsc.full > b.full)
  782. b.full = crtc->vsc.full;
  783. b.full = rfixed_mul(b, crtc->hsc);
  784. c.full = rfixed_const(2);
  785. b.full = rfixed_div(b, c);
  786. consumption_time.full = rfixed_div(pclk, b);
  787. } else {
  788. consumption_time.full = pclk.full;
  789. }
  790. a.full = rfixed_const(1);
  791. wm->consumption_rate.full = rfixed_div(a, consumption_time);
  792. /* Determine line time
  793. * LineTime = total time for one line of displayhtotal
  794. * LineTime = total number of horizontal pixels
  795. * pclk = pixel clock period(ns)
  796. */
  797. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  798. line_time.full = rfixed_mul(a, pclk);
  799. /* Determine active time
  800. * ActiveTime = time of active region of display within one line,
  801. * hactive = total number of horizontal active pixels
  802. * htotal = total number of horizontal pixels
  803. */
  804. a.full = rfixed_const(crtc->base.mode.crtc_htotal);
  805. b.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  806. wm->active_time.full = rfixed_mul(line_time, b);
  807. wm->active_time.full = rfixed_div(wm->active_time, a);
  808. /* Determine chunk time
  809. * ChunkTime = the time it takes the DCP to send one chunk of data
  810. * to the LB which consists of pipeline delay and inter chunk gap
  811. * sclk = system clock(Mhz)
  812. */
  813. a.full = rfixed_const(600 * 1000);
  814. chunk_time.full = rfixed_div(a, rdev->pm.sclk);
  815. read_delay_latency.full = rfixed_const(1000);
  816. /* Determine the worst case latency
  817. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  818. * WorstCaseLatency = worst case time from urgent to when the MC starts
  819. * to return data
  820. * READ_DELAY_IDLE_MAX = constant of 1us
  821. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  822. * which consists of pipeline delay and inter chunk gap
  823. */
  824. if (rfixed_trunc(wm->num_line_pair) > 1) {
  825. a.full = rfixed_const(3);
  826. wm->worst_case_latency.full = rfixed_mul(a, chunk_time);
  827. wm->worst_case_latency.full += read_delay_latency.full;
  828. } else {
  829. wm->worst_case_latency.full = chunk_time.full + read_delay_latency.full;
  830. }
  831. /* Determine the tolerable latency
  832. * TolerableLatency = Any given request has only 1 line time
  833. * for the data to be returned
  834. * LBRequestFifoDepth = Number of chunk requests the LB can
  835. * put into the request FIFO for a display
  836. * LineTime = total time for one line of display
  837. * ChunkTime = the time it takes the DCP to send one chunk
  838. * of data to the LB which consists of
  839. * pipeline delay and inter chunk gap
  840. */
  841. if ((2+wm->lb_request_fifo_depth) >= rfixed_trunc(request_fifo_depth)) {
  842. tolerable_latency.full = line_time.full;
  843. } else {
  844. tolerable_latency.full = rfixed_const(wm->lb_request_fifo_depth - 2);
  845. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  846. tolerable_latency.full = rfixed_mul(tolerable_latency, chunk_time);
  847. tolerable_latency.full = line_time.full - tolerable_latency.full;
  848. }
  849. /* We assume worst case 32bits (4 bytes) */
  850. wm->dbpp.full = rfixed_const(2 * 16);
  851. /* Determine the maximum priority mark
  852. * width = viewport width in pixels
  853. */
  854. a.full = rfixed_const(16);
  855. wm->priority_mark_max.full = rfixed_const(crtc->base.mode.crtc_hdisplay);
  856. wm->priority_mark_max.full = rfixed_div(wm->priority_mark_max, a);
  857. /* Determine estimated width */
  858. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  859. estimated_width.full = rfixed_div(estimated_width, consumption_time);
  860. if (rfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  861. wm->priority_mark.full = rfixed_const(10);
  862. } else {
  863. a.full = rfixed_const(16);
  864. wm->priority_mark.full = rfixed_div(estimated_width, a);
  865. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  866. }
  867. }
  868. void rv515_bandwidth_avivo_update(struct radeon_device *rdev)
  869. {
  870. struct drm_display_mode *mode0 = NULL;
  871. struct drm_display_mode *mode1 = NULL;
  872. struct rv515_watermark wm0;
  873. struct rv515_watermark wm1;
  874. u32 tmp;
  875. fixed20_12 priority_mark02, priority_mark12, fill_rate;
  876. fixed20_12 a, b;
  877. if (rdev->mode_info.crtcs[0]->base.enabled)
  878. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  879. if (rdev->mode_info.crtcs[1]->base.enabled)
  880. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  881. rs690_line_buffer_adjust(rdev, mode0, mode1);
  882. rv515_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0);
  883. rv515_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1);
  884. tmp = wm0.lb_request_fifo_depth;
  885. tmp |= wm1.lb_request_fifo_depth << 16;
  886. WREG32(LB_MAX_REQ_OUTSTANDING, tmp);
  887. if (mode0 && mode1) {
  888. if (rfixed_trunc(wm0.dbpp) > 64)
  889. a.full = rfixed_div(wm0.dbpp, wm0.num_line_pair);
  890. else
  891. a.full = wm0.num_line_pair.full;
  892. if (rfixed_trunc(wm1.dbpp) > 64)
  893. b.full = rfixed_div(wm1.dbpp, wm1.num_line_pair);
  894. else
  895. b.full = wm1.num_line_pair.full;
  896. a.full += b.full;
  897. fill_rate.full = rfixed_div(wm0.sclk, a);
  898. if (wm0.consumption_rate.full > fill_rate.full) {
  899. b.full = wm0.consumption_rate.full - fill_rate.full;
  900. b.full = rfixed_mul(b, wm0.active_time);
  901. a.full = rfixed_const(16);
  902. b.full = rfixed_div(b, a);
  903. a.full = rfixed_mul(wm0.worst_case_latency,
  904. wm0.consumption_rate);
  905. priority_mark02.full = a.full + b.full;
  906. } else {
  907. a.full = rfixed_mul(wm0.worst_case_latency,
  908. wm0.consumption_rate);
  909. b.full = rfixed_const(16 * 1000);
  910. priority_mark02.full = rfixed_div(a, b);
  911. }
  912. if (wm1.consumption_rate.full > fill_rate.full) {
  913. b.full = wm1.consumption_rate.full - fill_rate.full;
  914. b.full = rfixed_mul(b, wm1.active_time);
  915. a.full = rfixed_const(16);
  916. b.full = rfixed_div(b, a);
  917. a.full = rfixed_mul(wm1.worst_case_latency,
  918. wm1.consumption_rate);
  919. priority_mark12.full = a.full + b.full;
  920. } else {
  921. a.full = rfixed_mul(wm1.worst_case_latency,
  922. wm1.consumption_rate);
  923. b.full = rfixed_const(16 * 1000);
  924. priority_mark12.full = rfixed_div(a, b);
  925. }
  926. if (wm0.priority_mark.full > priority_mark02.full)
  927. priority_mark02.full = wm0.priority_mark.full;
  928. if (rfixed_trunc(priority_mark02) < 0)
  929. priority_mark02.full = 0;
  930. if (wm0.priority_mark_max.full > priority_mark02.full)
  931. priority_mark02.full = wm0.priority_mark_max.full;
  932. if (wm1.priority_mark.full > priority_mark12.full)
  933. priority_mark12.full = wm1.priority_mark.full;
  934. if (rfixed_trunc(priority_mark12) < 0)
  935. priority_mark12.full = 0;
  936. if (wm1.priority_mark_max.full > priority_mark12.full)
  937. priority_mark12.full = wm1.priority_mark_max.full;
  938. WREG32(D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  939. WREG32(D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  940. WREG32(D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  941. WREG32(D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  942. } else if (mode0) {
  943. if (rfixed_trunc(wm0.dbpp) > 64)
  944. a.full = rfixed_div(wm0.dbpp, wm0.num_line_pair);
  945. else
  946. a.full = wm0.num_line_pair.full;
  947. fill_rate.full = rfixed_div(wm0.sclk, a);
  948. if (wm0.consumption_rate.full > fill_rate.full) {
  949. b.full = wm0.consumption_rate.full - fill_rate.full;
  950. b.full = rfixed_mul(b, wm0.active_time);
  951. a.full = rfixed_const(16);
  952. b.full = rfixed_div(b, a);
  953. a.full = rfixed_mul(wm0.worst_case_latency,
  954. wm0.consumption_rate);
  955. priority_mark02.full = a.full + b.full;
  956. } else {
  957. a.full = rfixed_mul(wm0.worst_case_latency,
  958. wm0.consumption_rate);
  959. b.full = rfixed_const(16);
  960. priority_mark02.full = rfixed_div(a, b);
  961. }
  962. if (wm0.priority_mark.full > priority_mark02.full)
  963. priority_mark02.full = wm0.priority_mark.full;
  964. if (rfixed_trunc(priority_mark02) < 0)
  965. priority_mark02.full = 0;
  966. if (wm0.priority_mark_max.full > priority_mark02.full)
  967. priority_mark02.full = wm0.priority_mark_max.full;
  968. WREG32(D1MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark02));
  969. WREG32(D1MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark02));
  970. WREG32(D2MODE_PRIORITY_A_CNT, MODE_PRIORITY_OFF);
  971. WREG32(D2MODE_PRIORITY_B_CNT, MODE_PRIORITY_OFF);
  972. } else {
  973. if (rfixed_trunc(wm1.dbpp) > 64)
  974. a.full = rfixed_div(wm1.dbpp, wm1.num_line_pair);
  975. else
  976. a.full = wm1.num_line_pair.full;
  977. fill_rate.full = rfixed_div(wm1.sclk, a);
  978. if (wm1.consumption_rate.full > fill_rate.full) {
  979. b.full = wm1.consumption_rate.full - fill_rate.full;
  980. b.full = rfixed_mul(b, wm1.active_time);
  981. a.full = rfixed_const(16);
  982. b.full = rfixed_div(b, a);
  983. a.full = rfixed_mul(wm1.worst_case_latency,
  984. wm1.consumption_rate);
  985. priority_mark12.full = a.full + b.full;
  986. } else {
  987. a.full = rfixed_mul(wm1.worst_case_latency,
  988. wm1.consumption_rate);
  989. b.full = rfixed_const(16 * 1000);
  990. priority_mark12.full = rfixed_div(a, b);
  991. }
  992. if (wm1.priority_mark.full > priority_mark12.full)
  993. priority_mark12.full = wm1.priority_mark.full;
  994. if (rfixed_trunc(priority_mark12) < 0)
  995. priority_mark12.full = 0;
  996. if (wm1.priority_mark_max.full > priority_mark12.full)
  997. priority_mark12.full = wm1.priority_mark_max.full;
  998. WREG32(D1MODE_PRIORITY_A_CNT, MODE_PRIORITY_OFF);
  999. WREG32(D1MODE_PRIORITY_B_CNT, MODE_PRIORITY_OFF);
  1000. WREG32(D2MODE_PRIORITY_A_CNT, rfixed_trunc(priority_mark12));
  1001. WREG32(D2MODE_PRIORITY_B_CNT, rfixed_trunc(priority_mark12));
  1002. }
  1003. }
  1004. void rv515_bandwidth_update(struct radeon_device *rdev)
  1005. {
  1006. uint32_t tmp;
  1007. struct drm_display_mode *mode0 = NULL;
  1008. struct drm_display_mode *mode1 = NULL;
  1009. if (rdev->mode_info.crtcs[0]->base.enabled)
  1010. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  1011. if (rdev->mode_info.crtcs[1]->base.enabled)
  1012. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  1013. /*
  1014. * Set display0/1 priority up in the memory controller for
  1015. * modes if the user specifies HIGH for displaypriority
  1016. * option.
  1017. */
  1018. if (rdev->disp_priority == 2) {
  1019. tmp = RREG32_MC(MC_MISC_LAT_TIMER);
  1020. tmp &= ~MC_DISP1R_INIT_LAT_MASK;
  1021. tmp &= ~MC_DISP0R_INIT_LAT_MASK;
  1022. if (mode1)
  1023. tmp |= (1 << MC_DISP1R_INIT_LAT_SHIFT);
  1024. if (mode0)
  1025. tmp |= (1 << MC_DISP0R_INIT_LAT_SHIFT);
  1026. WREG32_MC(MC_MISC_LAT_TIMER, tmp);
  1027. }
  1028. rv515_bandwidth_avivo_update(rdev);
  1029. }