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