r420.c 11 KB

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