r520.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 "atom.h"
  31. #include "r520d.h"
  32. /* This files gather functions specifics to: r520,rv530,rv560,rv570,r580 */
  33. static 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. DRM_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. r100_hdp_reset(rdev);
  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_vram_info(struct radeon_device *rdev)
  115. {
  116. fixed20_12 a;
  117. r520_vram_get_type(rdev);
  118. r100_vram_init_sizes(rdev);
  119. /* FIXME: we should enforce default clock in case GPU is not in
  120. * default setup
  121. */
  122. a.full = rfixed_const(100);
  123. rdev->pm.sclk.full = rfixed_const(rdev->clock.default_sclk);
  124. rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a);
  125. }
  126. void r520_mc_program(struct radeon_device *rdev)
  127. {
  128. struct rv515_mc_save save;
  129. /* Stops all mc clients */
  130. rv515_mc_stop(rdev, &save);
  131. /* Wait for mc idle */
  132. if (r520_mc_wait_for_idle(rdev))
  133. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  134. /* Write VRAM size in case we are limiting it */
  135. WREG32(R_0000F8_CONFIG_MEMSIZE, rdev->mc.real_vram_size);
  136. /* Program MC, should be a 32bits limited address space */
  137. WREG32_MC(R_000004_MC_FB_LOCATION,
  138. S_000004_MC_FB_START(rdev->mc.vram_start >> 16) |
  139. S_000004_MC_FB_TOP(rdev->mc.vram_end >> 16));
  140. WREG32(R_000134_HDP_FB_LOCATION,
  141. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  142. if (rdev->flags & RADEON_IS_AGP) {
  143. WREG32_MC(R_000005_MC_AGP_LOCATION,
  144. S_000005_MC_AGP_START(rdev->mc.gtt_start >> 16) |
  145. S_000005_MC_AGP_TOP(rdev->mc.gtt_end >> 16));
  146. WREG32_MC(R_000006_AGP_BASE, lower_32_bits(rdev->mc.agp_base));
  147. WREG32_MC(R_000007_AGP_BASE_2,
  148. S_000007_AGP_BASE_ADDR_2(upper_32_bits(rdev->mc.agp_base)));
  149. } else {
  150. WREG32_MC(R_000005_MC_AGP_LOCATION, 0xFFFFFFFF);
  151. WREG32_MC(R_000006_AGP_BASE, 0);
  152. WREG32_MC(R_000007_AGP_BASE_2, 0);
  153. }
  154. rv515_mc_resume(rdev, &save);
  155. }
  156. static int r520_startup(struct radeon_device *rdev)
  157. {
  158. int r;
  159. r520_mc_program(rdev);
  160. /* Resume clock */
  161. rv515_clock_startup(rdev);
  162. /* Initialize GPU configuration (# pipes, ...) */
  163. r520_gpu_init(rdev);
  164. /* Initialize GART (initialize after TTM so we can allocate
  165. * memory through TTM but finalize after TTM) */
  166. if (rdev->flags & RADEON_IS_PCIE) {
  167. r = rv370_pcie_gart_enable(rdev);
  168. if (r)
  169. return r;
  170. }
  171. /* Enable IRQ */
  172. rs600_irq_set(rdev);
  173. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  174. /* 1M ring buffer */
  175. r = r100_cp_init(rdev, 1024 * 1024);
  176. if (r) {
  177. dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
  178. return r;
  179. }
  180. r = r100_wb_init(rdev);
  181. if (r)
  182. dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
  183. r = r100_ib_init(rdev);
  184. if (r) {
  185. dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
  186. return r;
  187. }
  188. return 0;
  189. }
  190. int r520_resume(struct radeon_device *rdev)
  191. {
  192. /* Make sur GART are not working */
  193. if (rdev->flags & RADEON_IS_PCIE)
  194. rv370_pcie_gart_disable(rdev);
  195. /* Resume clock before doing reset */
  196. rv515_clock_startup(rdev);
  197. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  198. if (radeon_gpu_reset(rdev)) {
  199. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  200. RREG32(R_000E40_RBBM_STATUS),
  201. RREG32(R_0007C0_CP_STAT));
  202. }
  203. /* post */
  204. atom_asic_init(rdev->mode_info.atom_context);
  205. /* Resume clock after posting */
  206. rv515_clock_startup(rdev);
  207. /* Initialize surface registers */
  208. radeon_surface_init(rdev);
  209. return r520_startup(rdev);
  210. }
  211. int r520_init(struct radeon_device *rdev)
  212. {
  213. int r;
  214. /* Initialize scratch registers */
  215. radeon_scratch_init(rdev);
  216. /* Initialize surface registers */
  217. radeon_surface_init(rdev);
  218. /* TODO: disable VGA need to use VGA request */
  219. /* BIOS*/
  220. if (!radeon_get_bios(rdev)) {
  221. if (ASIC_IS_AVIVO(rdev))
  222. return -EINVAL;
  223. }
  224. if (rdev->is_atom_bios) {
  225. r = radeon_atombios_init(rdev);
  226. if (r)
  227. return r;
  228. } else {
  229. dev_err(rdev->dev, "Expecting atombios for RV515 GPU\n");
  230. return -EINVAL;
  231. }
  232. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  233. if (radeon_gpu_reset(rdev)) {
  234. dev_warn(rdev->dev,
  235. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  236. RREG32(R_000E40_RBBM_STATUS),
  237. RREG32(R_0007C0_CP_STAT));
  238. }
  239. /* check if cards are posted or not */
  240. if (radeon_boot_test_post_card(rdev) == false)
  241. return -EINVAL;
  242. if (!radeon_card_posted(rdev) && rdev->bios) {
  243. DRM_INFO("GPU not posted. posting now...\n");
  244. atom_asic_init(rdev->mode_info.atom_context);
  245. }
  246. /* Initialize clocks */
  247. radeon_get_clock_info(rdev->ddev);
  248. /* Initialize power management */
  249. radeon_pm_init(rdev);
  250. /* Get vram informations */
  251. r520_vram_info(rdev);
  252. /* Initialize memory controller (also test AGP) */
  253. r = r420_mc_init(rdev);
  254. if (r)
  255. return r;
  256. rv515_debugfs(rdev);
  257. /* Fence driver */
  258. r = radeon_fence_driver_init(rdev);
  259. if (r)
  260. return r;
  261. r = radeon_irq_kms_init(rdev);
  262. if (r)
  263. return r;
  264. /* Memory manager */
  265. r = radeon_bo_init(rdev);
  266. if (r)
  267. return r;
  268. r = rv370_pcie_gart_init(rdev);
  269. if (r)
  270. return r;
  271. rv515_set_safe_registers(rdev);
  272. rdev->accel_working = true;
  273. r = r520_startup(rdev);
  274. if (r) {
  275. /* Somethings want wront with the accel init stop accel */
  276. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  277. rv515_suspend(rdev);
  278. r100_cp_fini(rdev);
  279. r100_wb_fini(rdev);
  280. r100_ib_fini(rdev);
  281. rv370_pcie_gart_fini(rdev);
  282. radeon_agp_fini(rdev);
  283. radeon_irq_kms_fini(rdev);
  284. rdev->accel_working = false;
  285. }
  286. return 0;
  287. }