r420.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. DRM_INFO("radeon: %d pipes initialized.\n", rdev->num_gb_pipes);
  153. }
  154. void r420_gpu_init(struct radeon_device *rdev)
  155. {
  156. r100_hdp_reset(rdev);
  157. r420_pipes_init(rdev);
  158. if (r300_mc_wait_for_idle(rdev)) {
  159. printk(KERN_WARNING "Failed to wait MC idle while "
  160. "programming pipes. Bad things might happen.\n");
  161. }
  162. }
  163. /*
  164. * r420,r423,rv410 VRAM info
  165. */
  166. void r420_vram_info(struct radeon_device *rdev)
  167. {
  168. r300_vram_info(rdev);
  169. }
  170. /*
  171. * Debugfs info
  172. */
  173. #if defined(CONFIG_DEBUG_FS)
  174. static int r420_debugfs_pipes_info(struct seq_file *m, void *data)
  175. {
  176. struct drm_info_node *node = (struct drm_info_node *) m->private;
  177. struct drm_device *dev = node->minor->dev;
  178. struct radeon_device *rdev = dev->dev_private;
  179. uint32_t tmp;
  180. tmp = RREG32(R400_GB_PIPE_SELECT);
  181. seq_printf(m, "GB_PIPE_SELECT 0x%08x\n", tmp);
  182. tmp = RREG32(R300_GB_TILE_CONFIG);
  183. seq_printf(m, "GB_TILE_CONFIG 0x%08x\n", tmp);
  184. tmp = RREG32(R300_DST_PIPE_CONFIG);
  185. seq_printf(m, "DST_PIPE_CONFIG 0x%08x\n", tmp);
  186. return 0;
  187. }
  188. static struct drm_info_list r420_pipes_info_list[] = {
  189. {"r420_pipes_info", r420_debugfs_pipes_info, 0, NULL},
  190. };
  191. #endif
  192. int r420_debugfs_pipes_info_init(struct radeon_device *rdev)
  193. {
  194. #if defined(CONFIG_DEBUG_FS)
  195. return radeon_debugfs_add_files(rdev, r420_pipes_info_list, 1);
  196. #else
  197. return 0;
  198. #endif
  199. }