r420.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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 <drm/drmP.h>
  31. #include "radeon_reg.h"
  32. #include "radeon.h"
  33. #include "radeon_asic.h"
  34. #include "atom.h"
  35. #include "r100d.h"
  36. #include "r420d.h"
  37. #include "r420_reg_safe.h"
  38. void r420_pm_init_profile(struct radeon_device *rdev)
  39. {
  40. /* default */
  41. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_ps_idx = rdev->pm.default_power_state_index;
  42. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  43. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_off_cm_idx = 0;
  44. rdev->pm.profiles[PM_PROFILE_DEFAULT_IDX].dpms_on_cm_idx = 0;
  45. /* low sh */
  46. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_ps_idx = 0;
  47. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_ps_idx = 0;
  48. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_off_cm_idx = 0;
  49. rdev->pm.profiles[PM_PROFILE_LOW_SH_IDX].dpms_on_cm_idx = 0;
  50. /* mid sh */
  51. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_ps_idx = 0;
  52. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_ps_idx = 1;
  53. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_off_cm_idx = 0;
  54. rdev->pm.profiles[PM_PROFILE_MID_SH_IDX].dpms_on_cm_idx = 0;
  55. /* high sh */
  56. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_ps_idx = 0;
  57. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  58. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_off_cm_idx = 0;
  59. rdev->pm.profiles[PM_PROFILE_HIGH_SH_IDX].dpms_on_cm_idx = 0;
  60. /* low mh */
  61. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_ps_idx = 0;
  62. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  63. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_off_cm_idx = 0;
  64. rdev->pm.profiles[PM_PROFILE_LOW_MH_IDX].dpms_on_cm_idx = 0;
  65. /* mid mh */
  66. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_ps_idx = 0;
  67. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  68. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_off_cm_idx = 0;
  69. rdev->pm.profiles[PM_PROFILE_MID_MH_IDX].dpms_on_cm_idx = 0;
  70. /* high mh */
  71. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_ps_idx = 0;
  72. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_ps_idx = rdev->pm.default_power_state_index;
  73. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_off_cm_idx = 0;
  74. rdev->pm.profiles[PM_PROFILE_HIGH_MH_IDX].dpms_on_cm_idx = 0;
  75. }
  76. static void r420_set_reg_safe(struct radeon_device *rdev)
  77. {
  78. rdev->config.r300.reg_safe_bm = r420_reg_safe_bm;
  79. rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r420_reg_safe_bm);
  80. }
  81. void r420_pipes_init(struct radeon_device *rdev)
  82. {
  83. unsigned tmp;
  84. unsigned gb_pipe_select;
  85. unsigned num_pipes;
  86. /* GA_ENHANCE workaround TCL deadlock issue */
  87. WREG32(R300_GA_ENHANCE, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL |
  88. (1 << 2) | (1 << 3));
  89. /* add idle wait as per freedesktop.org bug 24041 */
  90. if (r100_gui_wait_for_idle(rdev)) {
  91. pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n");
  92. }
  93. /* get max number of pipes */
  94. gb_pipe_select = RREG32(R400_GB_PIPE_SELECT);
  95. num_pipes = ((gb_pipe_select >> 12) & 3) + 1;
  96. /* SE chips have 1 pipe */
  97. if ((rdev->pdev->device == 0x5e4c) ||
  98. (rdev->pdev->device == 0x5e4f))
  99. num_pipes = 1;
  100. rdev->num_gb_pipes = num_pipes;
  101. tmp = 0;
  102. switch (num_pipes) {
  103. default:
  104. /* force to 1 pipe */
  105. num_pipes = 1;
  106. case 1:
  107. tmp = (0 << 1);
  108. break;
  109. case 2:
  110. tmp = (3 << 1);
  111. break;
  112. case 3:
  113. tmp = (6 << 1);
  114. break;
  115. case 4:
  116. tmp = (7 << 1);
  117. break;
  118. }
  119. WREG32(R500_SU_REG_DEST, (1 << num_pipes) - 1);
  120. /* Sub pixel 1/12 so we can have 4K rendering according to doc */
  121. tmp |= R300_TILE_SIZE_16 | R300_ENABLE_TILING;
  122. WREG32(R300_GB_TILE_CONFIG, tmp);
  123. if (r100_gui_wait_for_idle(rdev)) {
  124. pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n");
  125. }
  126. tmp = RREG32(R300_DST_PIPE_CONFIG);
  127. WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG);
  128. WREG32(R300_RB2D_DSTCACHE_MODE,
  129. RREG32(R300_RB2D_DSTCACHE_MODE) |
  130. R300_DC_AUTOFLUSH_ENABLE |
  131. R300_DC_DC_DISABLE_IGNORE_PE);
  132. if (r100_gui_wait_for_idle(rdev)) {
  133. pr_warn("Failed to wait GUI idle while programming pipes. Bad things might happen.\n");
  134. }
  135. if (rdev->family == CHIP_RV530) {
  136. tmp = RREG32(RV530_GB_PIPE_SELECT2);
  137. if ((tmp & 3) == 3)
  138. rdev->num_z_pipes = 2;
  139. else
  140. rdev->num_z_pipes = 1;
  141. } else
  142. rdev->num_z_pipes = 1;
  143. DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n",
  144. rdev->num_gb_pipes, rdev->num_z_pipes);
  145. }
  146. u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg)
  147. {
  148. unsigned long flags;
  149. u32 r;
  150. spin_lock_irqsave(&rdev->mc_idx_lock, flags);
  151. WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg));
  152. r = RREG32(R_0001FC_MC_IND_DATA);
  153. spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
  154. return r;
  155. }
  156. void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  157. {
  158. unsigned long flags;
  159. spin_lock_irqsave(&rdev->mc_idx_lock, flags);
  160. WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) |
  161. S_0001F8_MC_IND_WR_EN(1));
  162. WREG32(R_0001FC_MC_IND_DATA, v);
  163. spin_unlock_irqrestore(&rdev->mc_idx_lock, flags);
  164. }
  165. static void r420_debugfs(struct radeon_device *rdev)
  166. {
  167. if (r100_debugfs_rbbm_init(rdev)) {
  168. DRM_ERROR("Failed to register debugfs file for RBBM !\n");
  169. }
  170. if (r420_debugfs_pipes_info_init(rdev)) {
  171. DRM_ERROR("Failed to register debugfs file for pipes !\n");
  172. }
  173. }
  174. static void r420_clock_resume(struct radeon_device *rdev)
  175. {
  176. u32 sclk_cntl;
  177. if (radeon_dynclks != -1 && radeon_dynclks)
  178. radeon_atom_set_clock_gating(rdev, 1);
  179. sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL);
  180. sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
  181. if (rdev->family == CHIP_R420)
  182. sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1);
  183. WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl);
  184. }
  185. static void r420_cp_errata_init(struct radeon_device *rdev)
  186. {
  187. int r;
  188. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  189. /* RV410 and R420 can lock up if CP DMA to host memory happens
  190. * while the 2D engine is busy.
  191. *
  192. * The proper workaround is to queue a RESYNC at the beginning
  193. * of the CP init, apparently.
  194. */
  195. radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch);
  196. r = radeon_ring_lock(rdev, ring, 8);
  197. WARN_ON(r);
  198. radeon_ring_write(ring, PACKET0(R300_CP_RESYNC_ADDR, 1));
  199. radeon_ring_write(ring, rdev->config.r300.resync_scratch);
  200. radeon_ring_write(ring, 0xDEADBEEF);
  201. radeon_ring_unlock_commit(rdev, ring, false);
  202. }
  203. static void r420_cp_errata_fini(struct radeon_device *rdev)
  204. {
  205. int r;
  206. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  207. /* Catch the RESYNC we dispatched all the way back,
  208. * at the very beginning of the CP init.
  209. */
  210. r = radeon_ring_lock(rdev, ring, 8);
  211. WARN_ON(r);
  212. radeon_ring_write(ring, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
  213. radeon_ring_write(ring, R300_RB3D_DC_FINISH);
  214. radeon_ring_unlock_commit(rdev, ring, false);
  215. radeon_scratch_free(rdev, rdev->config.r300.resync_scratch);
  216. }
  217. static int r420_startup(struct radeon_device *rdev)
  218. {
  219. int r;
  220. /* set common regs */
  221. r100_set_common_regs(rdev);
  222. /* program mc */
  223. r300_mc_program(rdev);
  224. /* Resume clock */
  225. r420_clock_resume(rdev);
  226. /* Initialize GART (initialize after TTM so we can allocate
  227. * memory through TTM but finalize after TTM) */
  228. if (rdev->flags & RADEON_IS_PCIE) {
  229. r = rv370_pcie_gart_enable(rdev);
  230. if (r)
  231. return r;
  232. }
  233. if (rdev->flags & RADEON_IS_PCI) {
  234. r = r100_pci_gart_enable(rdev);
  235. if (r)
  236. return r;
  237. }
  238. r420_pipes_init(rdev);
  239. /* allocate wb buffer */
  240. r = radeon_wb_init(rdev);
  241. if (r)
  242. return r;
  243. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  244. if (r) {
  245. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  246. return r;
  247. }
  248. /* Enable IRQ */
  249. if (!rdev->irq.installed) {
  250. r = radeon_irq_kms_init(rdev);
  251. if (r)
  252. return r;
  253. }
  254. r100_irq_set(rdev);
  255. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  256. /* 1M ring buffer */
  257. r = r100_cp_init(rdev, 1024 * 1024);
  258. if (r) {
  259. dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
  260. return r;
  261. }
  262. r420_cp_errata_init(rdev);
  263. r = radeon_ib_pool_init(rdev);
  264. if (r) {
  265. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  266. return r;
  267. }
  268. return 0;
  269. }
  270. int r420_resume(struct radeon_device *rdev)
  271. {
  272. int r;
  273. /* Make sur GART are not working */
  274. if (rdev->flags & RADEON_IS_PCIE)
  275. rv370_pcie_gart_disable(rdev);
  276. if (rdev->flags & RADEON_IS_PCI)
  277. r100_pci_gart_disable(rdev);
  278. /* Resume clock before doing reset */
  279. r420_clock_resume(rdev);
  280. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  281. if (radeon_asic_reset(rdev)) {
  282. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  283. RREG32(R_000E40_RBBM_STATUS),
  284. RREG32(R_0007C0_CP_STAT));
  285. }
  286. /* check if cards are posted or not */
  287. if (rdev->is_atom_bios) {
  288. atom_asic_init(rdev->mode_info.atom_context);
  289. } else {
  290. radeon_combios_asic_init(rdev->ddev);
  291. }
  292. /* Resume clock after posting */
  293. r420_clock_resume(rdev);
  294. /* Initialize surface registers */
  295. radeon_surface_init(rdev);
  296. rdev->accel_working = true;
  297. r = r420_startup(rdev);
  298. if (r) {
  299. rdev->accel_working = false;
  300. }
  301. return r;
  302. }
  303. int r420_suspend(struct radeon_device *rdev)
  304. {
  305. radeon_pm_suspend(rdev);
  306. r420_cp_errata_fini(rdev);
  307. r100_cp_disable(rdev);
  308. radeon_wb_disable(rdev);
  309. r100_irq_disable(rdev);
  310. if (rdev->flags & RADEON_IS_PCIE)
  311. rv370_pcie_gart_disable(rdev);
  312. if (rdev->flags & RADEON_IS_PCI)
  313. r100_pci_gart_disable(rdev);
  314. return 0;
  315. }
  316. void r420_fini(struct radeon_device *rdev)
  317. {
  318. radeon_pm_fini(rdev);
  319. r100_cp_fini(rdev);
  320. radeon_wb_fini(rdev);
  321. radeon_ib_pool_fini(rdev);
  322. radeon_gem_fini(rdev);
  323. if (rdev->flags & RADEON_IS_PCIE)
  324. rv370_pcie_gart_fini(rdev);
  325. if (rdev->flags & RADEON_IS_PCI)
  326. r100_pci_gart_fini(rdev);
  327. radeon_agp_fini(rdev);
  328. radeon_irq_kms_fini(rdev);
  329. radeon_fence_driver_fini(rdev);
  330. radeon_bo_fini(rdev);
  331. if (rdev->is_atom_bios) {
  332. radeon_atombios_fini(rdev);
  333. } else {
  334. radeon_combios_fini(rdev);
  335. }
  336. kfree(rdev->bios);
  337. rdev->bios = NULL;
  338. }
  339. int r420_init(struct radeon_device *rdev)
  340. {
  341. int r;
  342. /* Initialize scratch registers */
  343. radeon_scratch_init(rdev);
  344. /* Initialize surface registers */
  345. radeon_surface_init(rdev);
  346. /* TODO: disable VGA need to use VGA request */
  347. /* restore some register to sane defaults */
  348. r100_restore_sanity(rdev);
  349. /* BIOS*/
  350. if (!radeon_get_bios(rdev)) {
  351. if (ASIC_IS_AVIVO(rdev))
  352. return -EINVAL;
  353. }
  354. if (rdev->is_atom_bios) {
  355. r = radeon_atombios_init(rdev);
  356. if (r) {
  357. return r;
  358. }
  359. } else {
  360. r = radeon_combios_init(rdev);
  361. if (r) {
  362. return r;
  363. }
  364. }
  365. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  366. if (radeon_asic_reset(rdev)) {
  367. dev_warn(rdev->dev,
  368. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  369. RREG32(R_000E40_RBBM_STATUS),
  370. RREG32(R_0007C0_CP_STAT));
  371. }
  372. /* check if cards are posted or not */
  373. if (radeon_boot_test_post_card(rdev) == false)
  374. return -EINVAL;
  375. /* Initialize clocks */
  376. radeon_get_clock_info(rdev->ddev);
  377. /* initialize AGP */
  378. if (rdev->flags & RADEON_IS_AGP) {
  379. r = radeon_agp_init(rdev);
  380. if (r) {
  381. radeon_agp_disable(rdev);
  382. }
  383. }
  384. /* initialize memory controller */
  385. r300_mc_init(rdev);
  386. r420_debugfs(rdev);
  387. /* Fence driver */
  388. r = radeon_fence_driver_init(rdev);
  389. if (r) {
  390. return r;
  391. }
  392. /* Memory manager */
  393. r = radeon_bo_init(rdev);
  394. if (r) {
  395. return r;
  396. }
  397. if (rdev->family == CHIP_R420)
  398. r100_enable_bm(rdev);
  399. if (rdev->flags & RADEON_IS_PCIE) {
  400. r = rv370_pcie_gart_init(rdev);
  401. if (r)
  402. return r;
  403. }
  404. if (rdev->flags & RADEON_IS_PCI) {
  405. r = r100_pci_gart_init(rdev);
  406. if (r)
  407. return r;
  408. }
  409. r420_set_reg_safe(rdev);
  410. /* Initialize power management */
  411. radeon_pm_init(rdev);
  412. rdev->accel_working = true;
  413. r = r420_startup(rdev);
  414. if (r) {
  415. /* Somethings want wront with the accel init stop accel */
  416. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  417. r100_cp_fini(rdev);
  418. radeon_wb_fini(rdev);
  419. radeon_ib_pool_fini(rdev);
  420. radeon_irq_kms_fini(rdev);
  421. if (rdev->flags & RADEON_IS_PCIE)
  422. rv370_pcie_gart_fini(rdev);
  423. if (rdev->flags & RADEON_IS_PCI)
  424. r100_pci_gart_fini(rdev);
  425. radeon_agp_fini(rdev);
  426. rdev->accel_working = false;
  427. }
  428. return 0;
  429. }
  430. /*
  431. * Debugfs info
  432. */
  433. #if defined(CONFIG_DEBUG_FS)
  434. static int r420_debugfs_pipes_info(struct seq_file *m, void *data)
  435. {
  436. struct drm_info_node *node = (struct drm_info_node *) m->private;
  437. struct drm_device *dev = node->minor->dev;
  438. struct radeon_device *rdev = dev->dev_private;
  439. uint32_t tmp;
  440. tmp = RREG32(R400_GB_PIPE_SELECT);
  441. seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
  442. tmp = RREG32(R300_GB_TILE_CONFIG);
  443. seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
  444. tmp = RREG32(R300_DST_PIPE_CONFIG);
  445. seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
  446. return 0;
  447. }
  448. static struct drm_info_list r420_pipes_info_list[] = {
  449. {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL},
  450. };
  451. #endif
  452. int r420_debugfs_pipes_info_init(struct radeon_device *rdev)
  453. {
  454. #if defined(CONFIG_DEBUG_FS)
  455. return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1);
  456. #else
  457. return 0;
  458. #endif
  459. }