r420.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <linux/seq_file.h>
  29. #include "drmP.h"
  30. #include "radeon_reg.h"
  31. #include "radeon.h"
  32. #include "radeon_asic.h"
  33. #include "atom.h"
  34. #include "r100d.h"
  35. #include "r420d.h"
  36. #include "r420_reg_safe.h"
  37. static void r420_set_reg_safe(struct radeon_device *rdev)
  38. {
  39. rdev->config.r300.reg_safe_bm = r420_reg_safe_bm;
  40. rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r420_reg_safe_bm);
  41. }
  42. void r420_pipes_init(struct radeon_device *rdev)
  43. {
  44. unsigned tmp;
  45. unsigned gb_pipe_select;
  46. unsigned num_pipes;
  47. /* GA_ENHANCE workaround TCL deadlock issue */
  48. WREG32(R300_GA_ENHANCE, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL |
  49. (1 << 2) | (1 << 3));
  50. /* add idle wait as per freedesktop.org bug 24041 */
  51. if (r100_gui_wait_for_idle(rdev)) {
  52. printk(KERN_WARNING "Failed to wait GUI idle while "
  53. "programming pipes. Bad things might happen.\n");
  54. }
  55. /* get max number of pipes */
  56. gb_pipe_select = RREG32(0x402C);
  57. num_pipes = ((gb_pipe_select >> 12) & 3) + 1;
  58. rdev->num_gb_pipes = num_pipes;
  59. tmp = 0;
  60. switch (num_pipes) {
  61. default:
  62. /* force to 1 pipe */
  63. num_pipes = 1;
  64. case 1:
  65. tmp = (0 << 1);
  66. break;
  67. case 2:
  68. tmp = (3 << 1);
  69. break;
  70. case 3:
  71. tmp = (6 << 1);
  72. break;
  73. case 4:
  74. tmp = (7 << 1);
  75. break;
  76. }
  77. WREG32(R500_SU_REG_DEST, (1 << num_pipes) - 1);
  78. /* Sub pixel 1/12 so we can have 4K rendering according to doc */
  79. tmp |= R300_TILE_SIZE_16 | R300_ENABLE_TILING;
  80. WREG32(R300_GB_TILE_CONFIG, tmp);
  81. if (r100_gui_wait_for_idle(rdev)) {
  82. printk(KERN_WARNING "Failed to wait GUI idle while "
  83. "programming pipes. Bad things might happen.\n");
  84. }
  85. tmp = RREG32(R300_DST_PIPE_CONFIG);
  86. WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG);
  87. WREG32(R300_RB2D_DSTCACHE_MODE,
  88. RREG32(R300_RB2D_DSTCACHE_MODE) |
  89. R300_DC_AUTOFLUSH_ENABLE |
  90. R300_DC_DC_DISABLE_IGNORE_PE);
  91. if (r100_gui_wait_for_idle(rdev)) {
  92. printk(KERN_WARNING "Failed to wait GUI idle while "
  93. "programming pipes. Bad things might happen.\n");
  94. }
  95. if (rdev->family == CHIP_RV530) {
  96. tmp = RREG32(RV530_GB_PIPE_SELECT2);
  97. if ((tmp & 3) == 3)
  98. rdev->num_z_pipes = 2;
  99. else
  100. rdev->num_z_pipes = 1;
  101. } else
  102. rdev->num_z_pipes = 1;
  103. DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n",
  104. rdev->num_gb_pipes, rdev->num_z_pipes);
  105. }
  106. u32 r420_mc_rreg(struct radeon_device *rdev, u32 reg)
  107. {
  108. u32 r;
  109. WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg));
  110. r = RREG32(R_0001FC_MC_IND_DATA);
  111. return r;
  112. }
  113. void r420_mc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  114. {
  115. WREG32(R_0001F8_MC_IND_INDEX, S_0001F8_MC_IND_ADDR(reg) |
  116. S_0001F8_MC_IND_WR_EN(1));
  117. WREG32(R_0001FC_MC_IND_DATA, v);
  118. }
  119. static void r420_debugfs(struct radeon_device *rdev)
  120. {
  121. if (r100_debugfs_rbbm_init(rdev)) {
  122. DRM_ERROR("Failed to register debugfs file for RBBM !\n");
  123. }
  124. if (r420_debugfs_pipes_info_init(rdev)) {
  125. DRM_ERROR("Failed to register debugfs file for pipes !\n");
  126. }
  127. }
  128. static void r420_clock_resume(struct radeon_device *rdev)
  129. {
  130. u32 sclk_cntl;
  131. if (radeon_dynclks != -1 && radeon_dynclks)
  132. radeon_atom_set_clock_gating(rdev, 1);
  133. sclk_cntl = RREG32_PLL(R_00000D_SCLK_CNTL);
  134. sclk_cntl |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
  135. if (rdev->family == CHIP_R420)
  136. sclk_cntl |= S_00000D_FORCE_PX(1) | S_00000D_FORCE_TX(1);
  137. WREG32_PLL(R_00000D_SCLK_CNTL, sclk_cntl);
  138. }
  139. static void r420_cp_errata_init(struct radeon_device *rdev)
  140. {
  141. /* RV410 and R420 can lock up if CP DMA to host memory happens
  142. * while the 2D engine is busy.
  143. *
  144. * The proper workaround is to queue a RESYNC at the beginning
  145. * of the CP init, apparently.
  146. */
  147. radeon_scratch_get(rdev, &rdev->config.r300.resync_scratch);
  148. radeon_ring_lock(rdev, 8);
  149. radeon_ring_write(rdev, PACKET0(R300_CP_RESYNC_ADDR, 1));
  150. radeon_ring_write(rdev, rdev->config.r300.resync_scratch);
  151. radeon_ring_write(rdev, 0xDEADBEEF);
  152. radeon_ring_unlock_commit(rdev);
  153. }
  154. static void r420_cp_errata_fini(struct radeon_device *rdev)
  155. {
  156. /* Catch the RESYNC we dispatched all the way back,
  157. * at the very beginning of the CP init.
  158. */
  159. radeon_ring_lock(rdev, 8);
  160. radeon_ring_write(rdev, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
  161. radeon_ring_write(rdev, R300_RB3D_DC_FINISH);
  162. radeon_ring_unlock_commit(rdev);
  163. radeon_scratch_free(rdev, rdev->config.r300.resync_scratch);
  164. }
  165. static int r420_startup(struct radeon_device *rdev)
  166. {
  167. int r;
  168. /* set common regs */
  169. r100_set_common_regs(rdev);
  170. /* program mc */
  171. r300_mc_program(rdev);
  172. /* Resume clock */
  173. r420_clock_resume(rdev);
  174. /* Initialize GART (initialize after TTM so we can allocate
  175. * memory through TTM but finalize after TTM) */
  176. if (rdev->flags & RADEON_IS_PCIE) {
  177. r = rv370_pcie_gart_enable(rdev);
  178. if (r)
  179. return r;
  180. }
  181. if (rdev->flags & RADEON_IS_PCI) {
  182. r = r100_pci_gart_enable(rdev);
  183. if (r)
  184. return r;
  185. }
  186. r420_pipes_init(rdev);
  187. /* Enable IRQ */
  188. r100_irq_set(rdev);
  189. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  190. /* 1M ring buffer */
  191. r = r100_cp_init(rdev, 1024 * 1024);
  192. if (r) {
  193. dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
  194. return r;
  195. }
  196. r420_cp_errata_init(rdev);
  197. r = r100_wb_init(rdev);
  198. if (r) {
  199. dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
  200. }
  201. r = r100_ib_init(rdev);
  202. if (r) {
  203. dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
  204. return r;
  205. }
  206. return 0;
  207. }
  208. int r420_resume(struct radeon_device *rdev)
  209. {
  210. /* Make sur GART are not working */
  211. if (rdev->flags & RADEON_IS_PCIE)
  212. rv370_pcie_gart_disable(rdev);
  213. if (rdev->flags & RADEON_IS_PCI)
  214. r100_pci_gart_disable(rdev);
  215. /* Resume clock before doing reset */
  216. r420_clock_resume(rdev);
  217. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  218. if (radeon_gpu_reset(rdev)) {
  219. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  220. RREG32(R_000E40_RBBM_STATUS),
  221. RREG32(R_0007C0_CP_STAT));
  222. }
  223. /* check if cards are posted or not */
  224. if (rdev->is_atom_bios) {
  225. atom_asic_init(rdev->mode_info.atom_context);
  226. } else {
  227. radeon_combios_asic_init(rdev->ddev);
  228. }
  229. /* Resume clock after posting */
  230. r420_clock_resume(rdev);
  231. /* Initialize surface registers */
  232. radeon_surface_init(rdev);
  233. return r420_startup(rdev);
  234. }
  235. int r420_suspend(struct radeon_device *rdev)
  236. {
  237. r420_cp_errata_fini(rdev);
  238. r100_cp_disable(rdev);
  239. r100_wb_disable(rdev);
  240. r100_irq_disable(rdev);
  241. if (rdev->flags & RADEON_IS_PCIE)
  242. rv370_pcie_gart_disable(rdev);
  243. if (rdev->flags & RADEON_IS_PCI)
  244. r100_pci_gart_disable(rdev);
  245. return 0;
  246. }
  247. void r420_fini(struct radeon_device *rdev)
  248. {
  249. r100_cp_fini(rdev);
  250. r100_wb_fini(rdev);
  251. r100_ib_fini(rdev);
  252. radeon_gem_fini(rdev);
  253. if (rdev->flags & RADEON_IS_PCIE)
  254. rv370_pcie_gart_fini(rdev);
  255. if (rdev->flags & RADEON_IS_PCI)
  256. r100_pci_gart_fini(rdev);
  257. radeon_agp_fini(rdev);
  258. radeon_irq_kms_fini(rdev);
  259. radeon_fence_driver_fini(rdev);
  260. radeon_bo_fini(rdev);
  261. if (rdev->is_atom_bios) {
  262. radeon_atombios_fini(rdev);
  263. } else {
  264. radeon_combios_fini(rdev);
  265. }
  266. kfree(rdev->bios);
  267. rdev->bios = NULL;
  268. }
  269. int r420_init(struct radeon_device *rdev)
  270. {
  271. int r;
  272. /* Initialize scratch registers */
  273. radeon_scratch_init(rdev);
  274. /* Initialize surface registers */
  275. radeon_surface_init(rdev);
  276. /* TODO: disable VGA need to use VGA request */
  277. /* BIOS*/
  278. if (!radeon_get_bios(rdev)) {
  279. if (ASIC_IS_AVIVO(rdev))
  280. return -EINVAL;
  281. }
  282. if (rdev->is_atom_bios) {
  283. r = radeon_atombios_init(rdev);
  284. if (r) {
  285. return r;
  286. }
  287. } else {
  288. r = radeon_combios_init(rdev);
  289. if (r) {
  290. return r;
  291. }
  292. }
  293. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  294. if (radeon_gpu_reset(rdev)) {
  295. dev_warn(rdev->dev,
  296. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  297. RREG32(R_000E40_RBBM_STATUS),
  298. RREG32(R_0007C0_CP_STAT));
  299. }
  300. /* check if cards are posted or not */
  301. if (radeon_boot_test_post_card(rdev) == false)
  302. return -EINVAL;
  303. /* Initialize clocks */
  304. radeon_get_clock_info(rdev->ddev);
  305. /* Initialize power management */
  306. radeon_pm_init(rdev);
  307. /* initialize AGP */
  308. if (rdev->flags & RADEON_IS_AGP) {
  309. r = radeon_agp_init(rdev);
  310. if (r) {
  311. radeon_agp_disable(rdev);
  312. }
  313. }
  314. /* initialize memory controller */
  315. r300_mc_init(rdev);
  316. r420_debugfs(rdev);
  317. /* Fence driver */
  318. r = radeon_fence_driver_init(rdev);
  319. if (r) {
  320. return r;
  321. }
  322. r = radeon_irq_kms_init(rdev);
  323. if (r) {
  324. return r;
  325. }
  326. /* Memory manager */
  327. r = radeon_bo_init(rdev);
  328. if (r) {
  329. return r;
  330. }
  331. if (rdev->family == CHIP_R420)
  332. r100_enable_bm(rdev);
  333. if (rdev->flags & RADEON_IS_PCIE) {
  334. r = rv370_pcie_gart_init(rdev);
  335. if (r)
  336. return r;
  337. }
  338. if (rdev->flags & RADEON_IS_PCI) {
  339. r = r100_pci_gart_init(rdev);
  340. if (r)
  341. return r;
  342. }
  343. r420_set_reg_safe(rdev);
  344. rdev->accel_working = true;
  345. r = r420_startup(rdev);
  346. if (r) {
  347. /* Somethings want wront with the accel init stop accel */
  348. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  349. r100_cp_fini(rdev);
  350. r100_wb_fini(rdev);
  351. r100_ib_fini(rdev);
  352. radeon_irq_kms_fini(rdev);
  353. if (rdev->flags & RADEON_IS_PCIE)
  354. rv370_pcie_gart_fini(rdev);
  355. if (rdev->flags & RADEON_IS_PCI)
  356. r100_pci_gart_fini(rdev);
  357. radeon_agp_fini(rdev);
  358. rdev->accel_working = false;
  359. }
  360. return 0;
  361. }
  362. /*
  363. * Debugfs info
  364. */
  365. #if defined(CONFIG_DEBUG_FS)
  366. static int r420_debugfs_pipes_info(struct seq_file *m, void *data)
  367. {
  368. struct drm_info_node *node = (struct drm_info_node *) m->private;
  369. struct drm_device *dev = node->minor->dev;
  370. struct radeon_device *rdev = dev->dev_private;
  371. uint32_t tmp;
  372. tmp = RREG32(R400_GB_PIPE_SELECT);
  373. seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
  374. tmp = RREG32(R300_GB_TILE_CONFIG);
  375. seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
  376. tmp = RREG32(R300_DST_PIPE_CONFIG);
  377. seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
  378. return 0;
  379. }
  380. static struct drm_info_list r420_pipes_info_list[] = {
  381. {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL},
  382. };
  383. #endif
  384. int r420_debugfs_pipes_info_init(struct radeon_device *rdev)
  385. {
  386. #if defined(CONFIG_DEBUG_FS)
  387. return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1);
  388. #else
  389. return 0;
  390. #endif
  391. }