r520.c 8.6 KB

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