r520.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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 "drmP.h"
  29. #include "radeon.h"
  30. #include "radeon_asic.h"
  31. #include "atom.h"
  32. #include "r520d.h"
  33. /* This files gather functions specifics to: r520,rv530,rv560,rv570,r580 */
  34. static int r520_mc_wait_for_idle(struct radeon_device *rdev)
  35. {
  36. unsigned i;
  37. uint32_t tmp;
  38. for (i = 0; i < rdev->usec_timeout; i++) {
  39. /* read MC_STATUS */
  40. tmp = RREG32_MC(R520_MC_STATUS);
  41. if (tmp & R520_MC_STATUS_IDLE) {
  42. return 0;
  43. }
  44. DRM_UDELAY(1);
  45. }
  46. return -1;
  47. }
  48. static void r520_gpu_init(struct radeon_device *rdev)
  49. {
  50. unsigned pipe_select_current, gb_pipe_select, tmp;
  51. rv515_vga_render_disable(rdev);
  52. /*
  53. * DST_PIPE_CONFIG 0x170C
  54. * GB_TILE_CONFIG 0x4018
  55. * GB_FIFO_SIZE 0x4024
  56. * GB_PIPE_SELECT 0x402C
  57. * GB_PIPE_SELECT2 0x4124
  58. * Z_PIPE_SHIFT 0
  59. * Z_PIPE_MASK 0x000000003
  60. * GB_FIFO_SIZE2 0x4128
  61. * SC_SFIFO_SIZE_SHIFT 0
  62. * SC_SFIFO_SIZE_MASK 0x000000003
  63. * SC_MFIFO_SIZE_SHIFT 2
  64. * SC_MFIFO_SIZE_MASK 0x00000000C
  65. * FG_SFIFO_SIZE_SHIFT 4
  66. * FG_SFIFO_SIZE_MASK 0x000000030
  67. * ZB_MFIFO_SIZE_SHIFT 6
  68. * ZB_MFIFO_SIZE_MASK 0x0000000C0
  69. * GA_ENHANCE 0x4274
  70. * SU_REG_DEST 0x42C8
  71. */
  72. /* workaround for RV530 */
  73. if (rdev->family == CHIP_RV530) {
  74. WREG32(0x4128, 0xFF);
  75. }
  76. r420_pipes_init(rdev);
  77. gb_pipe_select = RREG32(0x402C);
  78. tmp = RREG32(0x170C);
  79. pipe_select_current = (tmp >> 2) & 3;
  80. tmp = (1 << pipe_select_current) |
  81. (((gb_pipe_select >> 8) & 0xF) << 4);
  82. WREG32_PLL(0x000D, tmp);
  83. if (r520_mc_wait_for_idle(rdev)) {
  84. printk(KERN_WARNING "Failed to wait MC idle while "
  85. "programming pipes. Bad things might happen.\n");
  86. }
  87. }
  88. static void r520_vram_get_type(struct radeon_device *rdev)
  89. {
  90. uint32_t tmp;
  91. rdev->mc.vram_width = 128;
  92. rdev->mc.vram_is_ddr = true;
  93. tmp = RREG32_MC(R520_MC_CNTL0);
  94. switch ((tmp & R520_MEM_NUM_CHANNELS_MASK) >> R520_MEM_NUM_CHANNELS_SHIFT) {
  95. case 0:
  96. rdev->mc.vram_width = 32;
  97. break;
  98. case 1:
  99. rdev->mc.vram_width = 64;
  100. break;
  101. case 2:
  102. rdev->mc.vram_width = 128;
  103. break;
  104. case 3:
  105. rdev->mc.vram_width = 256;
  106. break;
  107. default:
  108. rdev->mc.vram_width = 128;
  109. break;
  110. }
  111. if (tmp & R520_MC_CHANNEL_SIZE)
  112. rdev->mc.vram_width *= 2;
  113. }
  114. void r520_mc_init(struct radeon_device *rdev)
  115. {
  116. r520_vram_get_type(rdev);
  117. r100_vram_init_sizes(rdev);
  118. radeon_vram_location(rdev, &rdev->mc, 0);
  119. if (!(rdev->flags & RADEON_IS_AGP))
  120. radeon_gtt_location(rdev, &rdev->mc);
  121. radeon_update_bandwidth_info(rdev);
  122. }
  123. void r520_mc_program(struct radeon_device *rdev)
  124. {
  125. struct rv515_mc_save save;
  126. /* Stops all mc clients */
  127. rv515_mc_stop(rdev, &save);
  128. /* Wait for mc idle */
  129. if (r520_mc_wait_for_idle(rdev))
  130. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  131. /* Write VRAM size in case we are limiting it */
  132. WREG32(R_0000F8_CONFIG_MEMSIZE, rdev->mc.real_vram_size);
  133. /* Program MC, should be a 32bits limited address space */
  134. WREG32_MC(R_000004_MC_FB_LOCATION,
  135. S_000004_MC_FB_START(rdev->mc.vram_start >> 16) |
  136. S_000004_MC_FB_TOP(rdev->mc.vram_end >> 16));
  137. WREG32(R_000134_HDP_FB_LOCATION,
  138. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  139. if (rdev->flags & RADEON_IS_AGP) {
  140. WREG32_MC(R_000005_MC_AGP_LOCATION,
  141. S_000005_MC_AGP_START(rdev->mc.gtt_start >> 16) |
  142. S_000005_MC_AGP_TOP(rdev->mc.gtt_end >> 16));
  143. WREG32_MC(R_000006_AGP_BASE, lower_32_bits(rdev->mc.agp_base));
  144. WREG32_MC(R_000007_AGP_BASE_2,
  145. S_000007_AGP_BASE_ADDR_2(upper_32_bits(rdev->mc.agp_base)));
  146. } else {
  147. WREG32_MC(R_000005_MC_AGP_LOCATION, 0xFFFFFFFF);
  148. WREG32_MC(R_000006_AGP_BASE, 0);
  149. WREG32_MC(R_000007_AGP_BASE_2, 0);
  150. }
  151. rv515_mc_resume(rdev, &save);
  152. }
  153. static int r520_startup(struct radeon_device *rdev)
  154. {
  155. int r;
  156. r520_mc_program(rdev);
  157. /* Resume clock */
  158. rv515_clock_startup(rdev);
  159. /* Initialize GPU configuration (# pipes, ...) */
  160. r520_gpu_init(rdev);
  161. /* Initialize GART (initialize after TTM so we can allocate
  162. * memory through TTM but finalize after TTM) */
  163. if (rdev->flags & RADEON_IS_PCIE) {
  164. r = rv370_pcie_gart_enable(rdev);
  165. if (r)
  166. return r;
  167. }
  168. /* Enable IRQ */
  169. rs600_irq_set(rdev);
  170. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  171. /* 1M ring buffer */
  172. r = r100_cp_init(rdev, 1024 * 1024);
  173. if (r) {
  174. dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
  175. return r;
  176. }
  177. r = r100_wb_init(rdev);
  178. if (r)
  179. dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
  180. r = r100_ib_init(rdev);
  181. if (r) {
  182. dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
  183. return r;
  184. }
  185. return 0;
  186. }
  187. int r520_resume(struct radeon_device *rdev)
  188. {
  189. /* Make sur GART are not working */
  190. if (rdev->flags & RADEON_IS_PCIE)
  191. rv370_pcie_gart_disable(rdev);
  192. /* Resume clock before doing reset */
  193. rv515_clock_startup(rdev);
  194. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  195. if (radeon_asic_reset(rdev)) {
  196. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  197. RREG32(R_000E40_RBBM_STATUS),
  198. RREG32(R_0007C0_CP_STAT));
  199. }
  200. /* post */
  201. atom_asic_init(rdev->mode_info.atom_context);
  202. /* Resume clock after posting */
  203. rv515_clock_startup(rdev);
  204. /* Initialize surface registers */
  205. radeon_surface_init(rdev);
  206. return r520_startup(rdev);
  207. }
  208. int r520_init(struct radeon_device *rdev)
  209. {
  210. int r;
  211. /* Initialize scratch registers */
  212. radeon_scratch_init(rdev);
  213. /* Initialize surface registers */
  214. radeon_surface_init(rdev);
  215. /* TODO: disable VGA need to use VGA request */
  216. /* BIOS*/
  217. if (!radeon_get_bios(rdev)) {
  218. if (ASIC_IS_AVIVO(rdev))
  219. return -EINVAL;
  220. }
  221. if (rdev->is_atom_bios) {
  222. r = radeon_atombios_init(rdev);
  223. if (r)
  224. return r;
  225. } else {
  226. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  227. return -EINVAL;
  228. }
  229. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  230. if (radeon_asic_reset(rdev)) {
  231. dev_warn(rdev->dev,
  232. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  233. RREG32(R_000E40_RBBM_STATUS),
  234. RREG32(R_0007C0_CP_STAT));
  235. }
  236. /* check if cards are posted or not */
  237. if (radeon_boot_test_post_card(rdev) == false)
  238. return -EINVAL;
  239. if (!radeon_card_posted(rdev) && rdev->bios) {
  240. DRM_INFO("GPU not posted. posting now...\n");
  241. atom_asic_init(rdev->mode_info.atom_context);
  242. }
  243. /* Initialize clocks */
  244. radeon_get_clock_info(rdev->ddev);
  245. /* initialize AGP */
  246. if (rdev->flags & RADEON_IS_AGP) {
  247. r = radeon_agp_init(rdev);
  248. if (r) {
  249. radeon_agp_disable(rdev);
  250. }
  251. }
  252. /* initialize memory controller */
  253. r520_mc_init(rdev);
  254. rv515_debugfs(rdev);
  255. /* Fence driver */
  256. r = radeon_fence_driver_init(rdev);
  257. if (r)
  258. return r;
  259. r = radeon_irq_kms_init(rdev);
  260. if (r)
  261. return r;
  262. /* Memory manager */
  263. r = radeon_bo_init(rdev);
  264. if (r)
  265. return r;
  266. r = rv370_pcie_gart_init(rdev);
  267. if (r)
  268. return r;
  269. rv515_set_safe_registers(rdev);
  270. rdev->accel_working = true;
  271. r = r520_startup(rdev);
  272. if (r) {
  273. /* Somethings want wront with the accel init stop accel */
  274. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  275. r100_cp_fini(rdev);
  276. r100_wb_fini(rdev);
  277. r100_ib_fini(rdev);
  278. radeon_irq_kms_fini(rdev);
  279. rv370_pcie_gart_fini(rdev);
  280. radeon_agp_fini(rdev);
  281. rdev->accel_working = false;
  282. }
  283. return 0;
  284. }