rv515.c 35 KB

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