r420.c 11 KB

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