rs400.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 <drm/drmP.h>
  30. #include "radeon_reg.h"
  31. #include "radeon.h"
  32. /* rs400,rs480 depends on : */
  33. void r100_hdp_reset(struct radeon_device *rdev);
  34. void r100_mc_disable_clients(struct radeon_device *rdev);
  35. int r300_mc_wait_for_idle(struct radeon_device *rdev);
  36. void r420_pipes_init(struct radeon_device *rdev);
  37. /* This files gather functions specifics to :
  38. * rs400,rs480
  39. *
  40. * Some of these functions might be used by newer ASICs.
  41. */
  42. void rs400_gpu_init(struct radeon_device *rdev);
  43. int rs400_debugfs_pcie_gart_info_init(struct radeon_device *rdev);
  44. /*
  45. * GART functions.
  46. */
  47. void rs400_gart_adjust_size(struct radeon_device *rdev)
  48. {
  49. /* Check gart size */
  50. switch (rdev->mc.gtt_size/(1024*1024)) {
  51. case 32:
  52. case 64:
  53. case 128:
  54. case 256:
  55. case 512:
  56. case 1024:
  57. case 2048:
  58. break;
  59. default:
  60. DRM_ERROR("Unable to use IGP GART size %uM\n",
  61. rdev->mc.gtt_size >> 20);
  62. DRM_ERROR("Valid GART size for IGP are 32M,64M,128M,256M,512M,1G,2G\n");
  63. DRM_ERROR("Forcing to 32M GART size\n");
  64. rdev->mc.gtt_size = 32 * 1024 * 1024;
  65. return;
  66. }
  67. if (rdev->family == CHIP_RS400 || rdev->family == CHIP_RS480) {
  68. /* FIXME: RS400 & RS480 seems to have issue with GART size
  69. * if 4G of system memory (needs more testing) */
  70. rdev->mc.gtt_size = 32 * 1024 * 1024;
  71. DRM_ERROR("Forcing to 32M GART size (because of ASIC bug ?)\n");
  72. }
  73. }
  74. void rs400_gart_tlb_flush(struct radeon_device *rdev)
  75. {
  76. uint32_t tmp;
  77. unsigned int timeout = rdev->usec_timeout;
  78. WREG32_MC(RS480_GART_CACHE_CNTRL, RS480_GART_CACHE_INVALIDATE);
  79. do {
  80. tmp = RREG32_MC(RS480_GART_CACHE_CNTRL);
  81. if ((tmp & RS480_GART_CACHE_INVALIDATE) == 0)
  82. break;
  83. DRM_UDELAY(1);
  84. timeout--;
  85. } while (timeout > 0);
  86. WREG32_MC(RS480_GART_CACHE_CNTRL, 0);
  87. }
  88. int rs400_gart_enable(struct radeon_device *rdev)
  89. {
  90. uint32_t size_reg;
  91. uint32_t tmp;
  92. int r;
  93. /* Initialize common gart structure */
  94. r = radeon_gart_init(rdev);
  95. if (r) {
  96. return r;
  97. }
  98. if (rs400_debugfs_pcie_gart_info_init(rdev)) {
  99. DRM_ERROR("Failed to register debugfs file for RS400 GART !\n");
  100. }
  101. tmp = RREG32_MC(RS690_AIC_CTRL_SCRATCH);
  102. tmp |= RS690_DIS_OUT_OF_PCI_GART_ACCESS;
  103. WREG32_MC(RS690_AIC_CTRL_SCRATCH, tmp);
  104. /* Check gart size */
  105. switch(rdev->mc.gtt_size / (1024 * 1024)) {
  106. case 32:
  107. size_reg = RS480_VA_SIZE_32MB;
  108. break;
  109. case 64:
  110. size_reg = RS480_VA_SIZE_64MB;
  111. break;
  112. case 128:
  113. size_reg = RS480_VA_SIZE_128MB;
  114. break;
  115. case 256:
  116. size_reg = RS480_VA_SIZE_256MB;
  117. break;
  118. case 512:
  119. size_reg = RS480_VA_SIZE_512MB;
  120. break;
  121. case 1024:
  122. size_reg = RS480_VA_SIZE_1GB;
  123. break;
  124. case 2048:
  125. size_reg = RS480_VA_SIZE_2GB;
  126. break;
  127. default:
  128. return -EINVAL;
  129. }
  130. if (rdev->gart.table.ram.ptr == NULL) {
  131. rdev->gart.table_size = rdev->gart.num_gpu_pages * 4;
  132. r = radeon_gart_table_ram_alloc(rdev);
  133. if (r) {
  134. return r;
  135. }
  136. }
  137. /* It should be fine to program it to max value */
  138. if (rdev->family == CHIP_RS690 || (rdev->family == CHIP_RS740)) {
  139. WREG32_MC(RS690_MCCFG_AGP_BASE, 0xFFFFFFFF);
  140. WREG32_MC(RS690_MCCFG_AGP_BASE_2, 0);
  141. } else {
  142. WREG32(RADEON_AGP_BASE, 0xFFFFFFFF);
  143. WREG32(RS480_AGP_BASE_2, 0);
  144. }
  145. tmp = rdev->mc.gtt_location + rdev->mc.gtt_size - 1;
  146. tmp = REG_SET(RS690_MC_AGP_TOP, tmp >> 16);
  147. tmp |= REG_SET(RS690_MC_AGP_START, rdev->mc.gtt_location >> 16);
  148. if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740)) {
  149. WREG32_MC(RS690_MCCFG_AGP_LOCATION, tmp);
  150. tmp = RREG32(RADEON_BUS_CNTL) & ~RS600_BUS_MASTER_DIS;
  151. WREG32(RADEON_BUS_CNTL, tmp);
  152. } else {
  153. WREG32(RADEON_MC_AGP_LOCATION, tmp);
  154. tmp = RREG32(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS;
  155. WREG32(RADEON_BUS_CNTL, tmp);
  156. }
  157. /* Table should be in 32bits address space so ignore bits above. */
  158. tmp = rdev->gart.table_addr & 0xfffff000;
  159. WREG32_MC(RS480_GART_BASE, tmp);
  160. /* TODO: more tweaking here */
  161. WREG32_MC(RS480_GART_FEATURE_ID,
  162. (RS480_TLB_ENABLE |
  163. RS480_GTW_LAC_EN | RS480_1LEVEL_GART));
  164. /* Disable snooping */
  165. WREG32_MC(RS480_AGP_MODE_CNTL,
  166. (1 << RS480_REQ_TYPE_SNOOP_SHIFT) | RS480_REQ_TYPE_SNOOP_DIS);
  167. /* Disable AGP mode */
  168. /* FIXME: according to doc we should set HIDE_MMCFG_BAR=0,
  169. * AGPMODE30=0 & AGP30ENHANCED=0 in NB_CNTL */
  170. if ((rdev->family == CHIP_RS690) || (rdev->family == CHIP_RS740)) {
  171. WREG32_MC(RS480_MC_MISC_CNTL,
  172. (RS480_GART_INDEX_REG_EN | RS690_BLOCK_GFX_D3_EN));
  173. } else {
  174. WREG32_MC(RS480_MC_MISC_CNTL, RS480_GART_INDEX_REG_EN);
  175. }
  176. /* Enable gart */
  177. WREG32_MC(RS480_AGP_ADDRESS_SPACE_SIZE, (RS480_GART_EN | size_reg));
  178. rs400_gart_tlb_flush(rdev);
  179. rdev->gart.ready = true;
  180. return 0;
  181. }
  182. void rs400_gart_disable(struct radeon_device *rdev)
  183. {
  184. uint32_t tmp;
  185. tmp = RREG32_MC(RS690_AIC_CTRL_SCRATCH);
  186. tmp |= RS690_DIS_OUT_OF_PCI_GART_ACCESS;
  187. WREG32_MC(RS690_AIC_CTRL_SCRATCH, tmp);
  188. WREG32_MC(RS480_AGP_ADDRESS_SPACE_SIZE, 0);
  189. }
  190. int rs400_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
  191. {
  192. if (i < 0 || i > rdev->gart.num_gpu_pages) {
  193. return -EINVAL;
  194. }
  195. rdev->gart.table.ram.ptr[i] = cpu_to_le32(((uint32_t)addr) | 0xC);
  196. return 0;
  197. }
  198. /*
  199. * MC functions.
  200. */
  201. int rs400_mc_init(struct radeon_device *rdev)
  202. {
  203. uint32_t tmp;
  204. int r;
  205. if (r100_debugfs_rbbm_init(rdev)) {
  206. DRM_ERROR("Failed to register debugfs file for RBBM !\n");
  207. }
  208. rs400_gpu_init(rdev);
  209. rs400_gart_disable(rdev);
  210. rdev->mc.gtt_location = rdev->mc.vram_size;
  211. rdev->mc.gtt_location += (rdev->mc.gtt_size - 1);
  212. rdev->mc.gtt_location &= ~(rdev->mc.gtt_size - 1);
  213. rdev->mc.vram_location = 0xFFFFFFFFUL;
  214. r = radeon_mc_setup(rdev);
  215. if (r) {
  216. return r;
  217. }
  218. r100_mc_disable_clients(rdev);
  219. if (r300_mc_wait_for_idle(rdev)) {
  220. printk(KERN_WARNING "Failed to wait MC idle while "
  221. "programming pipes. Bad things might happen.\n");
  222. }
  223. tmp = rdev->mc.vram_location + rdev->mc.vram_size - 1;
  224. tmp = REG_SET(RADEON_MC_FB_TOP, tmp >> 16);
  225. tmp |= REG_SET(RADEON_MC_FB_START, rdev->mc.vram_location >> 16);
  226. WREG32(RADEON_MC_FB_LOCATION, tmp);
  227. tmp = RREG32(RADEON_HOST_PATH_CNTL) | RADEON_HP_LIN_RD_CACHE_DIS;
  228. WREG32(RADEON_HOST_PATH_CNTL, tmp | RADEON_HDP_SOFT_RESET | RADEON_HDP_READ_BUFFER_INVALIDATE);
  229. (void)RREG32(RADEON_HOST_PATH_CNTL);
  230. WREG32(RADEON_HOST_PATH_CNTL, tmp);
  231. (void)RREG32(RADEON_HOST_PATH_CNTL);
  232. return 0;
  233. }
  234. void rs400_mc_fini(struct radeon_device *rdev)
  235. {
  236. rs400_gart_disable(rdev);
  237. radeon_gart_table_ram_free(rdev);
  238. radeon_gart_fini(rdev);
  239. }
  240. /*
  241. * Global GPU functions
  242. */
  243. void rs400_errata(struct radeon_device *rdev)
  244. {
  245. rdev->pll_errata = 0;
  246. }
  247. void rs400_gpu_init(struct radeon_device *rdev)
  248. {
  249. /* FIXME: HDP same place on rs400 ? */
  250. r100_hdp_reset(rdev);
  251. /* FIXME: is this correct ? */
  252. r420_pipes_init(rdev);
  253. if (r300_mc_wait_for_idle(rdev)) {
  254. printk(KERN_WARNING "Failed to wait MC idle while "
  255. "programming pipes. Bad things might happen.\n");
  256. }
  257. }
  258. /*
  259. * VRAM info.
  260. */
  261. void rs400_vram_info(struct radeon_device *rdev)
  262. {
  263. uint32_t tom;
  264. rs400_gart_adjust_size(rdev);
  265. /* DDR for all card after R300 & IGP */
  266. rdev->mc.vram_is_ddr = true;
  267. rdev->mc.vram_width = 128;
  268. /* read NB_TOM to get the amount of ram stolen for the GPU */
  269. tom = RREG32(RADEON_NB_TOM);
  270. rdev->mc.vram_size = (((tom >> 16) - (tom & 0xffff) + 1) << 16);
  271. WREG32(RADEON_CONFIG_MEMSIZE, rdev->mc.vram_size);
  272. /* Could aper size report 0 ? */
  273. rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
  274. rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
  275. }
  276. /*
  277. * Indirect registers accessor
  278. */
  279. uint32_t rs400_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  280. {
  281. uint32_t r;
  282. WREG32(RS480_NB_MC_INDEX, reg & 0xff);
  283. r = RREG32(RS480_NB_MC_DATA);
  284. WREG32(RS480_NB_MC_INDEX, 0xff);
  285. return r;
  286. }
  287. void rs400_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  288. {
  289. WREG32(RS480_NB_MC_INDEX, ((reg) & 0xff) | RS480_NB_MC_IND_WR_EN);
  290. WREG32(RS480_NB_MC_DATA, (v));
  291. WREG32(RS480_NB_MC_INDEX, 0xff);
  292. }
  293. /*
  294. * Debugfs info
  295. */
  296. #if defined(CONFIG_DEBUG_FS)
  297. static int rs400_debugfs_gart_info(struct seq_file *m, void *data)
  298. {
  299. struct drm_info_node *node = (struct drm_info_node *) m->private;
  300. struct drm_device *dev = node->minor->dev;
  301. struct radeon_device *rdev = dev->dev_private;
  302. uint32_t tmp;
  303. tmp = RREG32(RADEON_HOST_PATH_CNTL);
  304. seq_printf(m, "HOST_PATH_CNTL 0x%08x\n", tmp);
  305. tmp = RREG32(RADEON_BUS_CNTL);
  306. seq_printf(m, "BUS_CNTL 0x%08x\n", tmp);
  307. tmp = RREG32_MC(RS690_AIC_CTRL_SCRATCH);
  308. seq_printf(m, "AIC_CTRL_SCRATCH 0x%08x\n", tmp);
  309. if (rdev->family == CHIP_RS690 || (rdev->family == CHIP_RS740)) {
  310. tmp = RREG32_MC(RS690_MCCFG_AGP_BASE);
  311. seq_printf(m, "MCCFG_AGP_BASE 0x%08x\n", tmp);
  312. tmp = RREG32_MC(RS690_MCCFG_AGP_BASE_2);
  313. seq_printf(m, "MCCFG_AGP_BASE_2 0x%08x\n", tmp);
  314. tmp = RREG32_MC(RS690_MCCFG_AGP_LOCATION);
  315. seq_printf(m, "MCCFG_AGP_LOCATION 0x%08x\n", tmp);
  316. tmp = RREG32_MC(0x100);
  317. seq_printf(m, "MCCFG_FB_LOCATION 0x%08x\n", tmp);
  318. tmp = RREG32(0x134);
  319. seq_printf(m, "HDP_FB_LOCATION 0x%08x\n", tmp);
  320. } else {
  321. tmp = RREG32(RADEON_AGP_BASE);
  322. seq_printf(m, "AGP_BASE 0x%08x\n", tmp);
  323. tmp = RREG32(RS480_AGP_BASE_2);
  324. seq_printf(m, "AGP_BASE_2 0x%08x\n", tmp);
  325. tmp = RREG32(RADEON_MC_AGP_LOCATION);
  326. seq_printf(m, "MC_AGP_LOCATION 0x%08x\n", tmp);
  327. }
  328. tmp = RREG32_MC(RS480_GART_BASE);
  329. seq_printf(m, "GART_BASE 0x%08x\n", tmp);
  330. tmp = RREG32_MC(RS480_GART_FEATURE_ID);
  331. seq_printf(m, "GART_FEATURE_ID 0x%08x\n", tmp);
  332. tmp = RREG32_MC(RS480_AGP_MODE_CNTL);
  333. seq_printf(m, "AGP_MODE_CONTROL 0x%08x\n", tmp);
  334. tmp = RREG32_MC(RS480_MC_MISC_CNTL);
  335. seq_printf(m, "MC_MISC_CNTL 0x%08x\n", tmp);
  336. tmp = RREG32_MC(0x5F);
  337. seq_printf(m, "MC_MISC_UMA_CNTL 0x%08x\n", tmp);
  338. tmp = RREG32_MC(RS480_AGP_ADDRESS_SPACE_SIZE);
  339. seq_printf(m, "AGP_ADDRESS_SPACE_SIZE 0x%08x\n", tmp);
  340. tmp = RREG32_MC(RS480_GART_CACHE_CNTRL);
  341. seq_printf(m, "GART_CACHE_CNTRL 0x%08x\n", tmp);
  342. tmp = RREG32_MC(0x3B);
  343. seq_printf(m, "MC_GART_ERROR_ADDRESS 0x%08x\n", tmp);
  344. tmp = RREG32_MC(0x3C);
  345. seq_printf(m, "MC_GART_ERROR_ADDRESS_HI 0x%08x\n", tmp);
  346. tmp = RREG32_MC(0x30);
  347. seq_printf(m, "GART_ERROR_0 0x%08x\n", tmp);
  348. tmp = RREG32_MC(0x31);
  349. seq_printf(m, "GART_ERROR_1 0x%08x\n", tmp);
  350. tmp = RREG32_MC(0x32);
  351. seq_printf(m, "GART_ERROR_2 0x%08x\n", tmp);
  352. tmp = RREG32_MC(0x33);
  353. seq_printf(m, "GART_ERROR_3 0x%08x\n", tmp);
  354. tmp = RREG32_MC(0x34);
  355. seq_printf(m, "GART_ERROR_4 0x%08x\n", tmp);
  356. tmp = RREG32_MC(0x35);
  357. seq_printf(m, "GART_ERROR_5 0x%08x\n", tmp);
  358. tmp = RREG32_MC(0x36);
  359. seq_printf(m, "GART_ERROR_6 0x%08x\n", tmp);
  360. tmp = RREG32_MC(0x37);
  361. seq_printf(m, "GART_ERROR_7 0x%08x\n", tmp);
  362. return 0;
  363. }
  364. static struct drm_info_list rs400_gart_info_list[] = {
  365. {"rs400_gart_info", rs400_debugfs_gart_info, 0, NULL},
  366. };
  367. #endif
  368. int rs400_debugfs_pcie_gart_info_init(struct radeon_device *rdev)
  369. {
  370. #if defined(CONFIG_DEBUG_FS)
  371. return radeon_debugfs_add_files(rdev, rs400_gart_info_list, 1);
  372. #else
  373. return 0;
  374. #endif
  375. }