r420.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. /* r420,r423,rv410 depends on : */
  33. void r100_pci_gart_disable(struct radeon_device *rdev);
  34. void r100_hdp_reset(struct radeon_device *rdev);
  35. void r100_mc_setup(struct radeon_device *rdev);
  36. int r100_gui_wait_for_idle(struct radeon_device *rdev);
  37. void r100_mc_disable_clients(struct radeon_device *rdev);
  38. void r300_vram_info(struct radeon_device *rdev);
  39. int r300_mc_wait_for_idle(struct radeon_device *rdev);
  40. int rv370_pcie_gart_enable(struct radeon_device *rdev);
  41. void rv370_pcie_gart_disable(struct radeon_device *rdev);
  42. /* This files gather functions specifics to :
  43. * r420,r423,rv410
  44. *
  45. * Some of these functions might be used by newer ASICs.
  46. */
  47. void r420_gpu_init(struct radeon_device *rdev);
  48. int r420_debugfs_pipes_info_init(struct radeon_device *rdev);
  49. /*
  50. * MC
  51. */
  52. int r420_mc_init(struct radeon_device *rdev)
  53. {
  54. int r;
  55. if (r100_debugfs_rbbm_init(rdev)) {
  56. DRM_ERROR("Failed to register debugfs file for RBBM !\n");
  57. }
  58. if (r420_debugfs_pipes_info_init(rdev)) {
  59. DRM_ERROR("Failed to register debugfs file for pipes !\n");
  60. }
  61. r420_gpu_init(rdev);
  62. r100_pci_gart_disable(rdev);
  63. if (rdev->flags & RADEON_IS_PCIE) {
  64. rv370_pcie_gart_disable(rdev);
  65. }
  66. /* Setup GPU memory space */
  67. rdev->mc.vram_location = 0xFFFFFFFFUL;
  68. rdev->mc.gtt_location = 0xFFFFFFFFUL;
  69. if (rdev->flags & RADEON_IS_AGP) {
  70. r = radeon_agp_init(rdev);
  71. if (r) {
  72. printk(KERN_WARNING "[drm] Disabling AGP\n");
  73. rdev->flags &= ~RADEON_IS_AGP;
  74. rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024;
  75. } else {
  76. rdev->mc.gtt_location = rdev->mc.agp_base;
  77. }
  78. }
  79. r = radeon_mc_setup(rdev);
  80. if (r) {
  81. return r;
  82. }
  83. /* Program GPU memory space */
  84. r100_mc_disable_clients(rdev);
  85. if (r300_mc_wait_for_idle(rdev)) {
  86. printk(KERN_WARNING "Failed to wait MC idle while "
  87. "programming pipes. Bad things might happen.\n");
  88. }
  89. r100_mc_setup(rdev);
  90. return 0;
  91. }
  92. void r420_mc_fini(struct radeon_device *rdev)
  93. {
  94. rv370_pcie_gart_disable(rdev);
  95. radeon_gart_table_vram_free(rdev);
  96. radeon_gart_fini(rdev);
  97. }
  98. /*
  99. * Global GPU functions
  100. */
  101. void r420_errata(struct radeon_device *rdev)
  102. {
  103. rdev->pll_errata = 0;
  104. }
  105. void r420_pipes_init(struct radeon_device *rdev)
  106. {
  107. unsigned tmp;
  108. unsigned gb_pipe_select;
  109. unsigned num_pipes;
  110. /* GA_ENHANCE workaround TCL deadlock issue */
  111. WREG32(0x4274, (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
  112. /* get max number of pipes */
  113. gb_pipe_select = RREG32(0x402C);
  114. num_pipes = ((gb_pipe_select >> 12) & 3) + 1;
  115. rdev->num_gb_pipes = num_pipes;
  116. tmp = 0;
  117. switch (num_pipes) {
  118. default:
  119. /* force to 1 pipe */
  120. num_pipes = 1;
  121. case 1:
  122. tmp = (0 << 1);
  123. break;
  124. case 2:
  125. tmp = (3 << 1);
  126. break;
  127. case 3:
  128. tmp = (6 << 1);
  129. break;
  130. case 4:
  131. tmp = (7 << 1);
  132. break;
  133. }
  134. WREG32(0x42C8, (1 << num_pipes) - 1);
  135. /* Sub pixel 1/12 so we can have 4K rendering according to doc */
  136. tmp |= (1 << 4) | (1 << 0);
  137. WREG32(0x4018, tmp);
  138. if (r100_gui_wait_for_idle(rdev)) {
  139. printk(KERN_WARNING "Failed to wait GUI idle while "
  140. "programming pipes. Bad things might happen.\n");
  141. }
  142. tmp = RREG32(0x170C);
  143. WREG32(0x170C, tmp | (1 << 31));
  144. WREG32(R300_RB2D_DSTCACHE_MODE,
  145. RREG32(R300_RB2D_DSTCACHE_MODE) |
  146. R300_DC_AUTOFLUSH_ENABLE |
  147. R300_DC_DC_DISABLE_IGNORE_PE);
  148. if (r100_gui_wait_for_idle(rdev)) {
  149. printk(KERN_WARNING "Failed to wait GUI idle while "
  150. "programming pipes. Bad things might happen.\n");
  151. }
  152. if (rdev->family == CHIP_RV530) {
  153. tmp = RREG32(RV530_GB_PIPE_SELECT2);
  154. if ((tmp & 3) == 3)
  155. rdev->num_z_pipes = 2;
  156. else
  157. rdev->num_z_pipes = 1;
  158. } else
  159. rdev->num_z_pipes = 1;
  160. DRM_INFO("radeon: %d quad pipes, %d z pipes initialized.\n",
  161. rdev->num_gb_pipes, rdev->num_z_pipes);
  162. }
  163. void r420_gpu_init(struct radeon_device *rdev)
  164. {
  165. r100_hdp_reset(rdev);
  166. r420_pipes_init(rdev);
  167. if (r300_mc_wait_for_idle(rdev)) {
  168. printk(KERN_WARNING "Failed to wait MC idle while "
  169. "programming pipes. Bad things might happen.\n");
  170. }
  171. }
  172. /*
  173. * r420,r423,rv410 VRAM info
  174. */
  175. void r420_vram_info(struct radeon_device *rdev)
  176. {
  177. r300_vram_info(rdev);
  178. }
  179. /*
  180. * Debugfs info
  181. */
  182. #if defined(CONFIG_DEBUG_FS)
  183. static int r420_debugfs_pipes_info(struct seq_file *m, void *data)
  184. {
  185. struct drm_info_node *node = (struct drm_info_node *) m->private;
  186. struct drm_device *dev = node->minor->dev;
  187. struct radeon_device *rdev = dev->dev_private;
  188. uint32_t tmp;
  189. tmp = RREG32(R400_GB_PIPE_SELECT);
  190. seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
  191. tmp = RREG32(R300_GB_TILE_CONFIG);
  192. seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
  193. tmp = RREG32(R300_DST_PIPE_CONFIG);
  194. seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
  195. return 0;
  196. }
  197. static struct drm_info_list r420_pipes_info_list[] = {
  198. {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL},
  199. };
  200. #endif
  201. int r420_debugfs_pipes_info_init(struct radeon_device *rdev)
  202. {
  203. #if defined(CONFIG_DEBUG_FS)
  204. return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1);
  205. #else
  206. return 0;
  207. #endif
  208. }