r420.c 13 KB

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