rv515.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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. "resetting 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. "resetting 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->vga_render_control = RREG32(R_000300_VGA_RENDER_CONTROL);
  260. save->vga_hdp_control = RREG32(R_000328_VGA_HDP_CONTROL);
  261. /* Stop all video */
  262. WREG32(R_0068E8_D2CRTC_UPDATE_LOCK, 0);
  263. WREG32(R_000300_VGA_RENDER_CONTROL, 0);
  264. WREG32(R_0060E8_D1CRTC_UPDATE_LOCK, 1);
  265. WREG32(R_0068E8_D2CRTC_UPDATE_LOCK, 1);
  266. WREG32(R_006080_D1CRTC_CONTROL, 0);
  267. WREG32(R_006880_D2CRTC_CONTROL, 0);
  268. WREG32(R_0060E8_D1CRTC_UPDATE_LOCK, 0);
  269. WREG32(R_0068E8_D2CRTC_UPDATE_LOCK, 0);
  270. WREG32(R_000330_D1VGA_CONTROL, 0);
  271. WREG32(R_000338_D2VGA_CONTROL, 0);
  272. }
  273. void rv515_mc_resume(struct radeon_device *rdev, struct rv515_mc_save *save)
  274. {
  275. WREG32(R_006110_D1GRPH_PRIMARY_SURFACE_ADDRESS, rdev->mc.vram_start);
  276. WREG32(R_006118_D1GRPH_SECONDARY_SURFACE_ADDRESS, rdev->mc.vram_start);
  277. WREG32(R_006910_D2GRPH_PRIMARY_SURFACE_ADDRESS, rdev->mc.vram_start);
  278. WREG32(R_006918_D2GRPH_SECONDARY_SURFACE_ADDRESS, rdev->mc.vram_start);
  279. WREG32(R_000310_VGA_MEMORY_BASE_ADDRESS, rdev->mc.vram_start);
  280. /* Unlock host access */
  281. WREG32(R_000328_VGA_HDP_CONTROL, save->vga_hdp_control);
  282. mdelay(1);
  283. WREG32(R_000300_VGA_RENDER_CONTROL, save->vga_render_control);
  284. }
  285. void rv515_mc_program(struct radeon_device *rdev)
  286. {
  287. struct rv515_mc_save save;
  288. /* Stops all mc clients */
  289. rv515_mc_stop(rdev, &save);
  290. /* Wait for mc idle */
  291. if (rv515_mc_wait_for_idle(rdev))
  292. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  293. /* Write VRAM size in case we are limiting it */
  294. WREG32(R_0000F8_CONFIG_MEMSIZE, rdev->mc.real_vram_size);
  295. /* Program MC, should be a 32bits limited address space */
  296. WREG32_MC(R_000001_MC_FB_LOCATION,
  297. S_000001_MC_FB_START(rdev->mc.vram_start >> 16) |
  298. S_000001_MC_FB_TOP(rdev->mc.vram_end >> 16));
  299. WREG32(R_000134_HDP_FB_LOCATION,
  300. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  301. if (rdev->flags & RADEON_IS_AGP) {
  302. WREG32_MC(R_000002_MC_AGP_LOCATION,
  303. S_000002_MC_AGP_START(rdev->mc.gtt_start >> 16) |
  304. S_000002_MC_AGP_TOP(rdev->mc.gtt_end >> 16));
  305. WREG32_MC(R_000003_MC_AGP_BASE, lower_32_bits(rdev->mc.agp_base));
  306. WREG32_MC(R_000004_MC_AGP_BASE_2,
  307. S_000004_AGP_BASE_ADDR_2(upper_32_bits(rdev->mc.agp_base)));
  308. } else {
  309. WREG32_MC(R_000002_MC_AGP_LOCATION, 0xFFFFFFFF);
  310. WREG32_MC(R_000003_MC_AGP_BASE, 0);
  311. WREG32_MC(R_000004_MC_AGP_BASE_2, 0);
  312. }
  313. rv515_mc_resume(rdev, &save);
  314. }
  315. void rv515_clock_startup(struct radeon_device *rdev)
  316. {
  317. if (radeon_dynclks != -1 && radeon_dynclks)
  318. radeon_atom_set_clock_gating(rdev, 1);
  319. /* We need to force on some of the block */
  320. WREG32_PLL(R_00000F_CP_DYN_CNTL,
  321. RREG32_PLL(R_00000F_CP_DYN_CNTL) | S_00000F_CP_FORCEON(1));
  322. WREG32_PLL(R_000011_E2_DYN_CNTL,
  323. RREG32_PLL(R_000011_E2_DYN_CNTL) | S_000011_E2_FORCEON(1));
  324. WREG32_PLL(R_000013_IDCT_DYN_CNTL,
  325. RREG32_PLL(R_000013_IDCT_DYN_CNTL) | S_000013_IDCT_FORCEON(1));
  326. }
  327. static int rv515_startup(struct radeon_device *rdev)
  328. {
  329. int r;
  330. rv515_mc_program(rdev);
  331. /* Resume clock */
  332. rv515_clock_startup(rdev);
  333. /* Initialize GPU configuration (# pipes, ...) */
  334. rv515_gpu_init(rdev);
  335. /* Initialize GART (initialize after TTM so we can allocate
  336. * memory through TTM but finalize after TTM) */
  337. if (rdev->flags & RADEON_IS_PCIE) {
  338. r = rv370_pcie_gart_enable(rdev);
  339. if (r)
  340. return r;
  341. }
  342. /* allocate wb buffer */
  343. r = radeon_wb_init(rdev);
  344. if (r)
  345. return r;
  346. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  347. if (r) {
  348. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  349. return r;
  350. }
  351. /* Enable IRQ */
  352. if (!rdev->irq.installed) {
  353. r = radeon_irq_kms_init(rdev);
  354. if (r)
  355. return r;
  356. }
  357. rs600_irq_set(rdev);
  358. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  359. /* 1M ring buffer */
  360. r = r100_cp_init(rdev, 1024 * 1024);
  361. if (r) {
  362. dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
  363. return r;
  364. }
  365. r = radeon_ib_pool_start(rdev);
  366. if (r)
  367. return r;
  368. r = radeon_ib_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  369. if (r) {
  370. dev_err(rdev->dev, "failed testing IB (%d).\n", r);
  371. rdev->accel_working = false;
  372. return r;
  373. }
  374. return 0;
  375. }
  376. int rv515_resume(struct radeon_device *rdev)
  377. {
  378. int r;
  379. /* Make sur GART are not working */
  380. if (rdev->flags & RADEON_IS_PCIE)
  381. rv370_pcie_gart_disable(rdev);
  382. /* Resume clock before doing reset */
  383. rv515_clock_startup(rdev);
  384. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  385. if (radeon_asic_reset(rdev)) {
  386. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  387. RREG32(R_000E40_RBBM_STATUS),
  388. RREG32(R_0007C0_CP_STAT));
  389. }
  390. /* post */
  391. atom_asic_init(rdev->mode_info.atom_context);
  392. /* Resume clock after posting */
  393. rv515_clock_startup(rdev);
  394. /* Initialize surface registers */
  395. radeon_surface_init(rdev);
  396. rdev->accel_working = true;
  397. r = rv515_startup(rdev);
  398. if (r) {
  399. rdev->accel_working = false;
  400. }
  401. return r;
  402. }
  403. int rv515_suspend(struct radeon_device *rdev)
  404. {
  405. r100_cp_disable(rdev);
  406. radeon_wb_disable(rdev);
  407. rs600_irq_disable(rdev);
  408. if (rdev->flags & RADEON_IS_PCIE)
  409. rv370_pcie_gart_disable(rdev);
  410. return 0;
  411. }
  412. void rv515_set_safe_registers(struct radeon_device *rdev)
  413. {
  414. rdev->config.r300.reg_safe_bm = rv515_reg_safe_bm;
  415. rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(rv515_reg_safe_bm);
  416. }
  417. void rv515_fini(struct radeon_device *rdev)
  418. {
  419. r100_cp_fini(rdev);
  420. radeon_wb_fini(rdev);
  421. r100_ib_fini(rdev);
  422. radeon_gem_fini(rdev);
  423. rv370_pcie_gart_fini(rdev);
  424. radeon_agp_fini(rdev);
  425. radeon_irq_kms_fini(rdev);
  426. radeon_fence_driver_fini(rdev);
  427. radeon_bo_fini(rdev);
  428. radeon_atombios_fini(rdev);
  429. kfree(rdev->bios);
  430. rdev->bios = NULL;
  431. }
  432. int rv515_init(struct radeon_device *rdev)
  433. {
  434. int r;
  435. /* Initialize scratch registers */
  436. radeon_scratch_init(rdev);
  437. /* Initialize surface registers */
  438. radeon_surface_init(rdev);
  439. /* TODO: disable VGA need to use VGA request */
  440. /* restore some register to sane defaults */
  441. r100_restore_sanity(rdev);
  442. /* BIOS*/
  443. if (!radeon_get_bios(rdev)) {
  444. if (ASIC_IS_AVIVO(rdev))
  445. return -EINVAL;
  446. }
  447. if (rdev->is_atom_bios) {
  448. r = radeon_atombios_init(rdev);
  449. if (r)
  450. return r;
  451. } else {
  452. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  453. return -EINVAL;
  454. }
  455. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  456. if (radeon_asic_reset(rdev)) {
  457. dev_warn(rdev->dev,
  458. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  459. RREG32(R_000E40_RBBM_STATUS),
  460. RREG32(R_0007C0_CP_STAT));
  461. }
  462. /* check if cards are posted or not */
  463. if (radeon_boot_test_post_card(rdev) == false)
  464. return -EINVAL;
  465. /* Initialize clocks */
  466. radeon_get_clock_info(rdev->ddev);
  467. /* initialize AGP */
  468. if (rdev->flags & RADEON_IS_AGP) {
  469. r = radeon_agp_init(rdev);
  470. if (r) {
  471. radeon_agp_disable(rdev);
  472. }
  473. }
  474. /* initialize memory controller */
  475. rv515_mc_init(rdev);
  476. rv515_debugfs(rdev);
  477. /* Fence driver */
  478. r = radeon_fence_driver_init(rdev);
  479. if (r)
  480. return r;
  481. /* Memory manager */
  482. r = radeon_bo_init(rdev);
  483. if (r)
  484. return r;
  485. r = rv370_pcie_gart_init(rdev);
  486. if (r)
  487. return r;
  488. rv515_set_safe_registers(rdev);
  489. r = radeon_ib_pool_init(rdev);
  490. rdev->accel_working = true;
  491. if (r) {
  492. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  493. rdev->accel_working = false;
  494. }
  495. r = rv515_startup(rdev);
  496. if (r) {
  497. /* Somethings want wront with the accel init stop accel */
  498. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  499. r100_cp_fini(rdev);
  500. radeon_wb_fini(rdev);
  501. r100_ib_fini(rdev);
  502. radeon_irq_kms_fini(rdev);
  503. rv370_pcie_gart_fini(rdev);
  504. radeon_agp_fini(rdev);
  505. rdev->accel_working = false;
  506. }
  507. return 0;
  508. }
  509. void atom_rv515_force_tv_scaler(struct radeon_device *rdev, struct radeon_crtc *crtc)
  510. {
  511. int index_reg = 0x6578 + crtc->crtc_offset;
  512. int data_reg = 0x657c + crtc->crtc_offset;
  513. WREG32(0x659C + crtc->crtc_offset, 0x0);
  514. WREG32(0x6594 + crtc->crtc_offset, 0x705);
  515. WREG32(0x65A4 + crtc->crtc_offset, 0x10001);
  516. WREG32(0x65D8 + crtc->crtc_offset, 0x0);
  517. WREG32(0x65B0 + crtc->crtc_offset, 0x0);
  518. WREG32(0x65C0 + crtc->crtc_offset, 0x0);
  519. WREG32(0x65D4 + crtc->crtc_offset, 0x0);
  520. WREG32(index_reg, 0x0);
  521. WREG32(data_reg, 0x841880A8);
  522. WREG32(index_reg, 0x1);
  523. WREG32(data_reg, 0x84208680);
  524. WREG32(index_reg, 0x2);
  525. WREG32(data_reg, 0xBFF880B0);
  526. WREG32(index_reg, 0x100);
  527. WREG32(data_reg, 0x83D88088);
  528. WREG32(index_reg, 0x101);
  529. WREG32(data_reg, 0x84608680);
  530. WREG32(index_reg, 0x102);
  531. WREG32(data_reg, 0xBFF080D0);
  532. WREG32(index_reg, 0x200);
  533. WREG32(data_reg, 0x83988068);
  534. WREG32(index_reg, 0x201);
  535. WREG32(data_reg, 0x84A08680);
  536. WREG32(index_reg, 0x202);
  537. WREG32(data_reg, 0xBFF080F8);
  538. WREG32(index_reg, 0x300);
  539. WREG32(data_reg, 0x83588058);
  540. WREG32(index_reg, 0x301);
  541. WREG32(data_reg, 0x84E08660);
  542. WREG32(index_reg, 0x302);
  543. WREG32(data_reg, 0xBFF88120);
  544. WREG32(index_reg, 0x400);
  545. WREG32(data_reg, 0x83188040);
  546. WREG32(index_reg, 0x401);
  547. WREG32(data_reg, 0x85008660);
  548. WREG32(index_reg, 0x402);
  549. WREG32(data_reg, 0xBFF88150);
  550. WREG32(index_reg, 0x500);
  551. WREG32(data_reg, 0x82D88030);
  552. WREG32(index_reg, 0x501);
  553. WREG32(data_reg, 0x85408640);
  554. WREG32(index_reg, 0x502);
  555. WREG32(data_reg, 0xBFF88180);
  556. WREG32(index_reg, 0x600);
  557. WREG32(data_reg, 0x82A08018);
  558. WREG32(index_reg, 0x601);
  559. WREG32(data_reg, 0x85808620);
  560. WREG32(index_reg, 0x602);
  561. WREG32(data_reg, 0xBFF081B8);
  562. WREG32(index_reg, 0x700);
  563. WREG32(data_reg, 0x82608010);
  564. WREG32(index_reg, 0x701);
  565. WREG32(data_reg, 0x85A08600);
  566. WREG32(index_reg, 0x702);
  567. WREG32(data_reg, 0x800081F0);
  568. WREG32(index_reg, 0x800);
  569. WREG32(data_reg, 0x8228BFF8);
  570. WREG32(index_reg, 0x801);
  571. WREG32(data_reg, 0x85E085E0);
  572. WREG32(index_reg, 0x802);
  573. WREG32(data_reg, 0xBFF88228);
  574. WREG32(index_reg, 0x10000);
  575. WREG32(data_reg, 0x82A8BF00);
  576. WREG32(index_reg, 0x10001);
  577. WREG32(data_reg, 0x82A08CC0);
  578. WREG32(index_reg, 0x10002);
  579. WREG32(data_reg, 0x8008BEF8);
  580. WREG32(index_reg, 0x10100);
  581. WREG32(data_reg, 0x81F0BF28);
  582. WREG32(index_reg, 0x10101);
  583. WREG32(data_reg, 0x83608CA0);
  584. WREG32(index_reg, 0x10102);
  585. WREG32(data_reg, 0x8018BED0);
  586. WREG32(index_reg, 0x10200);
  587. WREG32(data_reg, 0x8148BF38);
  588. WREG32(index_reg, 0x10201);
  589. WREG32(data_reg, 0x84408C80);
  590. WREG32(index_reg, 0x10202);
  591. WREG32(data_reg, 0x8008BEB8);
  592. WREG32(index_reg, 0x10300);
  593. WREG32(data_reg, 0x80B0BF78);
  594. WREG32(index_reg, 0x10301);
  595. WREG32(data_reg, 0x85008C20);
  596. WREG32(index_reg, 0x10302);
  597. WREG32(data_reg, 0x8020BEA0);
  598. WREG32(index_reg, 0x10400);
  599. WREG32(data_reg, 0x8028BF90);
  600. WREG32(index_reg, 0x10401);
  601. WREG32(data_reg, 0x85E08BC0);
  602. WREG32(index_reg, 0x10402);
  603. WREG32(data_reg, 0x8018BE90);
  604. WREG32(index_reg, 0x10500);
  605. WREG32(data_reg, 0xBFB8BFB0);
  606. WREG32(index_reg, 0x10501);
  607. WREG32(data_reg, 0x86C08B40);
  608. WREG32(index_reg, 0x10502);
  609. WREG32(data_reg, 0x8010BE90);
  610. WREG32(index_reg, 0x10600);
  611. WREG32(data_reg, 0xBF58BFC8);
  612. WREG32(index_reg, 0x10601);
  613. WREG32(data_reg, 0x87A08AA0);
  614. WREG32(index_reg, 0x10602);
  615. WREG32(data_reg, 0x8010BE98);
  616. WREG32(index_reg, 0x10700);
  617. WREG32(data_reg, 0xBF10BFF0);
  618. WREG32(index_reg, 0x10701);
  619. WREG32(data_reg, 0x886089E0);
  620. WREG32(index_reg, 0x10702);
  621. WREG32(data_reg, 0x8018BEB0);
  622. WREG32(index_reg, 0x10800);
  623. WREG32(data_reg, 0xBED8BFE8);
  624. WREG32(index_reg, 0x10801);
  625. WREG32(data_reg, 0x89408940);
  626. WREG32(index_reg, 0x10802);
  627. WREG32(data_reg, 0xBFE8BED8);
  628. WREG32(index_reg, 0x20000);
  629. WREG32(data_reg, 0x80008000);
  630. WREG32(index_reg, 0x20001);
  631. WREG32(data_reg, 0x90008000);
  632. WREG32(index_reg, 0x20002);
  633. WREG32(data_reg, 0x80008000);
  634. WREG32(index_reg, 0x20003);
  635. WREG32(data_reg, 0x80008000);
  636. WREG32(index_reg, 0x20100);
  637. WREG32(data_reg, 0x80108000);
  638. WREG32(index_reg, 0x20101);
  639. WREG32(data_reg, 0x8FE0BF70);
  640. WREG32(index_reg, 0x20102);
  641. WREG32(data_reg, 0xBFE880C0);
  642. WREG32(index_reg, 0x20103);
  643. WREG32(data_reg, 0x80008000);
  644. WREG32(index_reg, 0x20200);
  645. WREG32(data_reg, 0x8018BFF8);
  646. WREG32(index_reg, 0x20201);
  647. WREG32(data_reg, 0x8F80BF08);
  648. WREG32(index_reg, 0x20202);
  649. WREG32(data_reg, 0xBFD081A0);
  650. WREG32(index_reg, 0x20203);
  651. WREG32(data_reg, 0xBFF88000);
  652. WREG32(index_reg, 0x20300);
  653. WREG32(data_reg, 0x80188000);
  654. WREG32(index_reg, 0x20301);
  655. WREG32(data_reg, 0x8EE0BEC0);
  656. WREG32(index_reg, 0x20302);
  657. WREG32(data_reg, 0xBFB082A0);
  658. WREG32(index_reg, 0x20303);
  659. WREG32(data_reg, 0x80008000);
  660. WREG32(index_reg, 0x20400);
  661. WREG32(data_reg, 0x80188000);
  662. WREG32(index_reg, 0x20401);
  663. WREG32(data_reg, 0x8E00BEA0);
  664. WREG32(index_reg, 0x20402);
  665. WREG32(data_reg, 0xBF8883C0);
  666. WREG32(index_reg, 0x20403);
  667. WREG32(data_reg, 0x80008000);
  668. WREG32(index_reg, 0x20500);
  669. WREG32(data_reg, 0x80188000);
  670. WREG32(index_reg, 0x20501);
  671. WREG32(data_reg, 0x8D00BE90);
  672. WREG32(index_reg, 0x20502);
  673. WREG32(data_reg, 0xBF588500);
  674. WREG32(index_reg, 0x20503);
  675. WREG32(data_reg, 0x80008008);
  676. WREG32(index_reg, 0x20600);
  677. WREG32(data_reg, 0x80188000);
  678. WREG32(index_reg, 0x20601);
  679. WREG32(data_reg, 0x8BC0BE98);
  680. WREG32(index_reg, 0x20602);
  681. WREG32(data_reg, 0xBF308660);
  682. WREG32(index_reg, 0x20603);
  683. WREG32(data_reg, 0x80008008);
  684. WREG32(index_reg, 0x20700);
  685. WREG32(data_reg, 0x80108000);
  686. WREG32(index_reg, 0x20701);
  687. WREG32(data_reg, 0x8A80BEB0);
  688. WREG32(index_reg, 0x20702);
  689. WREG32(data_reg, 0xBF0087C0);
  690. WREG32(index_reg, 0x20703);
  691. WREG32(data_reg, 0x80008008);
  692. WREG32(index_reg, 0x20800);
  693. WREG32(data_reg, 0x80108000);
  694. WREG32(index_reg, 0x20801);
  695. WREG32(data_reg, 0x8920BED0);
  696. WREG32(index_reg, 0x20802);
  697. WREG32(data_reg, 0xBED08920);
  698. WREG32(index_reg, 0x20803);
  699. WREG32(data_reg, 0x80008010);
  700. WREG32(index_reg, 0x30000);
  701. WREG32(data_reg, 0x90008000);
  702. WREG32(index_reg, 0x30001);
  703. WREG32(data_reg, 0x80008000);
  704. WREG32(index_reg, 0x30100);
  705. WREG32(data_reg, 0x8FE0BF90);
  706. WREG32(index_reg, 0x30101);
  707. WREG32(data_reg, 0xBFF880A0);
  708. WREG32(index_reg, 0x30200);
  709. WREG32(data_reg, 0x8F60BF40);
  710. WREG32(index_reg, 0x30201);
  711. WREG32(data_reg, 0xBFE88180);
  712. WREG32(index_reg, 0x30300);
  713. WREG32(data_reg, 0x8EC0BF00);
  714. WREG32(index_reg, 0x30301);
  715. WREG32(data_reg, 0xBFC88280);
  716. WREG32(index_reg, 0x30400);
  717. WREG32(data_reg, 0x8DE0BEE0);
  718. WREG32(index_reg, 0x30401);
  719. WREG32(data_reg, 0xBFA083A0);
  720. WREG32(index_reg, 0x30500);
  721. WREG32(data_reg, 0x8CE0BED0);
  722. WREG32(index_reg, 0x30501);
  723. WREG32(data_reg, 0xBF7884E0);
  724. WREG32(index_reg, 0x30600);
  725. WREG32(data_reg, 0x8BA0BED8);
  726. WREG32(index_reg, 0x30601);
  727. WREG32(data_reg, 0xBF508640);
  728. WREG32(index_reg, 0x30700);
  729. WREG32(data_reg, 0x8A60BEE8);
  730. WREG32(index_reg, 0x30701);
  731. WREG32(data_reg, 0xBF2087A0);
  732. WREG32(index_reg, 0x30800);
  733. WREG32(data_reg, 0x8900BF00);
  734. WREG32(index_reg, 0x30801);
  735. WREG32(data_reg, 0xBF008900);
  736. }
  737. struct rv515_watermark {
  738. u32 lb_request_fifo_depth;
  739. fixed20_12 num_line_pair;
  740. fixed20_12 estimated_width;
  741. fixed20_12 worst_case_latency;
  742. fixed20_12 consumption_rate;
  743. fixed20_12 active_time;
  744. fixed20_12 dbpp;
  745. fixed20_12 priority_mark_max;
  746. fixed20_12 priority_mark;
  747. fixed20_12 sclk;
  748. };
  749. void rv515_crtc_bandwidth_compute(struct radeon_device *rdev,
  750. struct radeon_crtc *crtc,
  751. struct rv515_watermark *wm)
  752. {
  753. struct drm_display_mode *mode = &crtc->base.mode;
  754. fixed20_12 a, b, c;
  755. fixed20_12 pclk, request_fifo_depth, tolerable_latency, estimated_width;
  756. fixed20_12 consumption_time, line_time, chunk_time, read_delay_latency;
  757. if (!crtc->base.enabled) {
  758. /* FIXME: wouldn't it better to set priority mark to maximum */
  759. wm->lb_request_fifo_depth = 4;
  760. return;
  761. }
  762. if (crtc->vsc.full > dfixed_const(2))
  763. wm->num_line_pair.full = dfixed_const(2);
  764. else
  765. wm->num_line_pair.full = dfixed_const(1);
  766. b.full = dfixed_const(mode->crtc_hdisplay);
  767. c.full = dfixed_const(256);
  768. a.full = dfixed_div(b, c);
  769. request_fifo_depth.full = dfixed_mul(a, wm->num_line_pair);
  770. request_fifo_depth.full = dfixed_ceil(request_fifo_depth);
  771. if (a.full < dfixed_const(4)) {
  772. wm->lb_request_fifo_depth = 4;
  773. } else {
  774. wm->lb_request_fifo_depth = dfixed_trunc(request_fifo_depth);
  775. }
  776. /* Determine consumption rate
  777. * pclk = pixel clock period(ns) = 1000 / (mode.clock / 1000)
  778. * vtaps = number of vertical taps,
  779. * vsc = vertical scaling ratio, defined as source/destination
  780. * hsc = horizontal scaling ration, defined as source/destination
  781. */
  782. a.full = dfixed_const(mode->clock);
  783. b.full = dfixed_const(1000);
  784. a.full = dfixed_div(a, b);
  785. pclk.full = dfixed_div(b, a);
  786. if (crtc->rmx_type != RMX_OFF) {
  787. b.full = dfixed_const(2);
  788. if (crtc->vsc.full > b.full)
  789. b.full = crtc->vsc.full;
  790. b.full = dfixed_mul(b, crtc->hsc);
  791. c.full = dfixed_const(2);
  792. b.full = dfixed_div(b, c);
  793. consumption_time.full = dfixed_div(pclk, b);
  794. } else {
  795. consumption_time.full = pclk.full;
  796. }
  797. a.full = dfixed_const(1);
  798. wm->consumption_rate.full = dfixed_div(a, consumption_time);
  799. /* Determine line time
  800. * LineTime = total time for one line of displayhtotal
  801. * LineTime = total number of horizontal pixels
  802. * pclk = pixel clock period(ns)
  803. */
  804. a.full = dfixed_const(crtc->base.mode.crtc_htotal);
  805. line_time.full = dfixed_mul(a, pclk);
  806. /* Determine active time
  807. * ActiveTime = time of active region of display within one line,
  808. * hactive = total number of horizontal active pixels
  809. * htotal = total number of horizontal pixels
  810. */
  811. a.full = dfixed_const(crtc->base.mode.crtc_htotal);
  812. b.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
  813. wm->active_time.full = dfixed_mul(line_time, b);
  814. wm->active_time.full = dfixed_div(wm->active_time, a);
  815. /* Determine chunk time
  816. * ChunkTime = the time it takes the DCP to send one chunk of data
  817. * to the LB which consists of pipeline delay and inter chunk gap
  818. * sclk = system clock(Mhz)
  819. */
  820. a.full = dfixed_const(600 * 1000);
  821. chunk_time.full = dfixed_div(a, rdev->pm.sclk);
  822. read_delay_latency.full = dfixed_const(1000);
  823. /* Determine the worst case latency
  824. * NumLinePair = Number of line pairs to request(1=2 lines, 2=4 lines)
  825. * WorstCaseLatency = worst case time from urgent to when the MC starts
  826. * to return data
  827. * READ_DELAY_IDLE_MAX = constant of 1us
  828. * ChunkTime = time it takes the DCP to send one chunk of data to the LB
  829. * which consists of pipeline delay and inter chunk gap
  830. */
  831. if (dfixed_trunc(wm->num_line_pair) > 1) {
  832. a.full = dfixed_const(3);
  833. wm->worst_case_latency.full = dfixed_mul(a, chunk_time);
  834. wm->worst_case_latency.full += read_delay_latency.full;
  835. } else {
  836. wm->worst_case_latency.full = chunk_time.full + read_delay_latency.full;
  837. }
  838. /* Determine the tolerable latency
  839. * TolerableLatency = Any given request has only 1 line time
  840. * for the data to be returned
  841. * LBRequestFifoDepth = Number of chunk requests the LB can
  842. * put into the request FIFO for a display
  843. * LineTime = total time for one line of display
  844. * ChunkTime = the time it takes the DCP to send one chunk
  845. * of data to the LB which consists of
  846. * pipeline delay and inter chunk gap
  847. */
  848. if ((2+wm->lb_request_fifo_depth) >= dfixed_trunc(request_fifo_depth)) {
  849. tolerable_latency.full = line_time.full;
  850. } else {
  851. tolerable_latency.full = dfixed_const(wm->lb_request_fifo_depth - 2);
  852. tolerable_latency.full = request_fifo_depth.full - tolerable_latency.full;
  853. tolerable_latency.full = dfixed_mul(tolerable_latency, chunk_time);
  854. tolerable_latency.full = line_time.full - tolerable_latency.full;
  855. }
  856. /* We assume worst case 32bits (4 bytes) */
  857. wm->dbpp.full = dfixed_const(2 * 16);
  858. /* Determine the maximum priority mark
  859. * width = viewport width in pixels
  860. */
  861. a.full = dfixed_const(16);
  862. wm->priority_mark_max.full = dfixed_const(crtc->base.mode.crtc_hdisplay);
  863. wm->priority_mark_max.full = dfixed_div(wm->priority_mark_max, a);
  864. wm->priority_mark_max.full = dfixed_ceil(wm->priority_mark_max);
  865. /* Determine estimated width */
  866. estimated_width.full = tolerable_latency.full - wm->worst_case_latency.full;
  867. estimated_width.full = dfixed_div(estimated_width, consumption_time);
  868. if (dfixed_trunc(estimated_width) > crtc->base.mode.crtc_hdisplay) {
  869. wm->priority_mark.full = wm->priority_mark_max.full;
  870. } else {
  871. a.full = dfixed_const(16);
  872. wm->priority_mark.full = dfixed_div(estimated_width, a);
  873. wm->priority_mark.full = dfixed_ceil(wm->priority_mark);
  874. wm->priority_mark.full = wm->priority_mark_max.full - wm->priority_mark.full;
  875. }
  876. }
  877. void rv515_bandwidth_avivo_update(struct radeon_device *rdev)
  878. {
  879. struct drm_display_mode *mode0 = NULL;
  880. struct drm_display_mode *mode1 = NULL;
  881. struct rv515_watermark wm0;
  882. struct rv515_watermark wm1;
  883. u32 tmp;
  884. u32 d1mode_priority_a_cnt = MODE_PRIORITY_OFF;
  885. u32 d2mode_priority_a_cnt = MODE_PRIORITY_OFF;
  886. fixed20_12 priority_mark02, priority_mark12, fill_rate;
  887. fixed20_12 a, b;
  888. if (rdev->mode_info.crtcs[0]->base.enabled)
  889. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  890. if (rdev->mode_info.crtcs[1]->base.enabled)
  891. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  892. rs690_line_buffer_adjust(rdev, mode0, mode1);
  893. rv515_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[0], &wm0);
  894. rv515_crtc_bandwidth_compute(rdev, rdev->mode_info.crtcs[1], &wm1);
  895. tmp = wm0.lb_request_fifo_depth;
  896. tmp |= wm1.lb_request_fifo_depth << 16;
  897. WREG32(LB_MAX_REQ_OUTSTANDING, tmp);
  898. if (mode0 && mode1) {
  899. if (dfixed_trunc(wm0.dbpp) > 64)
  900. a.full = dfixed_div(wm0.dbpp, wm0.num_line_pair);
  901. else
  902. a.full = wm0.num_line_pair.full;
  903. if (dfixed_trunc(wm1.dbpp) > 64)
  904. b.full = dfixed_div(wm1.dbpp, wm1.num_line_pair);
  905. else
  906. b.full = wm1.num_line_pair.full;
  907. a.full += b.full;
  908. fill_rate.full = dfixed_div(wm0.sclk, a);
  909. if (wm0.consumption_rate.full > fill_rate.full) {
  910. b.full = wm0.consumption_rate.full - fill_rate.full;
  911. b.full = dfixed_mul(b, wm0.active_time);
  912. a.full = dfixed_const(16);
  913. b.full = dfixed_div(b, a);
  914. a.full = dfixed_mul(wm0.worst_case_latency,
  915. wm0.consumption_rate);
  916. priority_mark02.full = a.full + b.full;
  917. } else {
  918. a.full = dfixed_mul(wm0.worst_case_latency,
  919. wm0.consumption_rate);
  920. b.full = dfixed_const(16 * 1000);
  921. priority_mark02.full = dfixed_div(a, b);
  922. }
  923. if (wm1.consumption_rate.full > fill_rate.full) {
  924. b.full = wm1.consumption_rate.full - fill_rate.full;
  925. b.full = dfixed_mul(b, wm1.active_time);
  926. a.full = dfixed_const(16);
  927. b.full = dfixed_div(b, a);
  928. a.full = dfixed_mul(wm1.worst_case_latency,
  929. wm1.consumption_rate);
  930. priority_mark12.full = a.full + b.full;
  931. } else {
  932. a.full = dfixed_mul(wm1.worst_case_latency,
  933. wm1.consumption_rate);
  934. b.full = dfixed_const(16 * 1000);
  935. priority_mark12.full = dfixed_div(a, b);
  936. }
  937. if (wm0.priority_mark.full > priority_mark02.full)
  938. priority_mark02.full = wm0.priority_mark.full;
  939. if (dfixed_trunc(priority_mark02) < 0)
  940. priority_mark02.full = 0;
  941. if (wm0.priority_mark_max.full > priority_mark02.full)
  942. priority_mark02.full = wm0.priority_mark_max.full;
  943. if (wm1.priority_mark.full > priority_mark12.full)
  944. priority_mark12.full = wm1.priority_mark.full;
  945. if (dfixed_trunc(priority_mark12) < 0)
  946. priority_mark12.full = 0;
  947. if (wm1.priority_mark_max.full > priority_mark12.full)
  948. priority_mark12.full = wm1.priority_mark_max.full;
  949. d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
  950. d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
  951. if (rdev->disp_priority == 2) {
  952. d1mode_priority_a_cnt |= MODE_PRIORITY_ALWAYS_ON;
  953. d2mode_priority_a_cnt |= MODE_PRIORITY_ALWAYS_ON;
  954. }
  955. } else if (mode0) {
  956. if (dfixed_trunc(wm0.dbpp) > 64)
  957. a.full = dfixed_div(wm0.dbpp, wm0.num_line_pair);
  958. else
  959. a.full = wm0.num_line_pair.full;
  960. fill_rate.full = dfixed_div(wm0.sclk, a);
  961. if (wm0.consumption_rate.full > fill_rate.full) {
  962. b.full = wm0.consumption_rate.full - fill_rate.full;
  963. b.full = dfixed_mul(b, wm0.active_time);
  964. a.full = dfixed_const(16);
  965. b.full = dfixed_div(b, a);
  966. a.full = dfixed_mul(wm0.worst_case_latency,
  967. wm0.consumption_rate);
  968. priority_mark02.full = a.full + b.full;
  969. } else {
  970. a.full = dfixed_mul(wm0.worst_case_latency,
  971. wm0.consumption_rate);
  972. b.full = dfixed_const(16);
  973. priority_mark02.full = dfixed_div(a, b);
  974. }
  975. if (wm0.priority_mark.full > priority_mark02.full)
  976. priority_mark02.full = wm0.priority_mark.full;
  977. if (dfixed_trunc(priority_mark02) < 0)
  978. priority_mark02.full = 0;
  979. if (wm0.priority_mark_max.full > priority_mark02.full)
  980. priority_mark02.full = wm0.priority_mark_max.full;
  981. d1mode_priority_a_cnt = dfixed_trunc(priority_mark02);
  982. if (rdev->disp_priority == 2)
  983. d1mode_priority_a_cnt |= MODE_PRIORITY_ALWAYS_ON;
  984. } else if (mode1) {
  985. if (dfixed_trunc(wm1.dbpp) > 64)
  986. a.full = dfixed_div(wm1.dbpp, wm1.num_line_pair);
  987. else
  988. a.full = wm1.num_line_pair.full;
  989. fill_rate.full = dfixed_div(wm1.sclk, a);
  990. if (wm1.consumption_rate.full > fill_rate.full) {
  991. b.full = wm1.consumption_rate.full - fill_rate.full;
  992. b.full = dfixed_mul(b, wm1.active_time);
  993. a.full = dfixed_const(16);
  994. b.full = dfixed_div(b, a);
  995. a.full = dfixed_mul(wm1.worst_case_latency,
  996. wm1.consumption_rate);
  997. priority_mark12.full = a.full + b.full;
  998. } else {
  999. a.full = dfixed_mul(wm1.worst_case_latency,
  1000. wm1.consumption_rate);
  1001. b.full = dfixed_const(16 * 1000);
  1002. priority_mark12.full = dfixed_div(a, b);
  1003. }
  1004. if (wm1.priority_mark.full > priority_mark12.full)
  1005. priority_mark12.full = wm1.priority_mark.full;
  1006. if (dfixed_trunc(priority_mark12) < 0)
  1007. priority_mark12.full = 0;
  1008. if (wm1.priority_mark_max.full > priority_mark12.full)
  1009. priority_mark12.full = wm1.priority_mark_max.full;
  1010. d2mode_priority_a_cnt = dfixed_trunc(priority_mark12);
  1011. if (rdev->disp_priority == 2)
  1012. d2mode_priority_a_cnt |= MODE_PRIORITY_ALWAYS_ON;
  1013. }
  1014. WREG32(D1MODE_PRIORITY_A_CNT, d1mode_priority_a_cnt);
  1015. WREG32(D1MODE_PRIORITY_B_CNT, d1mode_priority_a_cnt);
  1016. WREG32(D2MODE_PRIORITY_A_CNT, d2mode_priority_a_cnt);
  1017. WREG32(D2MODE_PRIORITY_B_CNT, d2mode_priority_a_cnt);
  1018. }
  1019. void rv515_bandwidth_update(struct radeon_device *rdev)
  1020. {
  1021. uint32_t tmp;
  1022. struct drm_display_mode *mode0 = NULL;
  1023. struct drm_display_mode *mode1 = NULL;
  1024. radeon_update_display_priority(rdev);
  1025. if (rdev->mode_info.crtcs[0]->base.enabled)
  1026. mode0 = &rdev->mode_info.crtcs[0]->base.mode;
  1027. if (rdev->mode_info.crtcs[1]->base.enabled)
  1028. mode1 = &rdev->mode_info.crtcs[1]->base.mode;
  1029. /*
  1030. * Set display0/1 priority up in the memory controller for
  1031. * modes if the user specifies HIGH for displaypriority
  1032. * option.
  1033. */
  1034. if ((rdev->disp_priority == 2) &&
  1035. (rdev->family == CHIP_RV515)) {
  1036. tmp = RREG32_MC(MC_MISC_LAT_TIMER);
  1037. tmp &= ~MC_DISP1R_INIT_LAT_MASK;
  1038. tmp &= ~MC_DISP0R_INIT_LAT_MASK;
  1039. if (mode1)
  1040. tmp |= (1 << MC_DISP1R_INIT_LAT_SHIFT);
  1041. if (mode0)
  1042. tmp |= (1 << MC_DISP0R_INIT_LAT_SHIFT);
  1043. WREG32_MC(MC_MISC_LAT_TIMER, tmp);
  1044. }
  1045. rv515_bandwidth_avivo_update(rdev);
  1046. }