r420.c 11 KB

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