rs600.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511
  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. /* RS600 / Radeon X1250/X1270 integrated GPU
  29. *
  30. * This file gather function specific to RS600 which is the IGP of
  31. * the X1250/X1270 family supporting intel CPU (while RS690/RS740
  32. * is the X1250/X1270 supporting AMD CPU). The display engine are
  33. * the avivo one, bios is an atombios, 3D block are the one of the
  34. * R4XX family. The GART is different from the RS400 one and is very
  35. * close to the one of the R600 family (R600 likely being an evolution
  36. * of the RS600 GART block).
  37. */
  38. #include "drmP.h"
  39. #include "radeon.h"
  40. #include "atom.h"
  41. #include "rs600d.h"
  42. #include "rs600_reg_safe.h"
  43. void rs600_gpu_init(struct radeon_device *rdev);
  44. int rs600_mc_wait_for_idle(struct radeon_device *rdev);
  45. /*
  46. * GART.
  47. */
  48. void rs600_gart_tlb_flush(struct radeon_device *rdev)
  49. {
  50. uint32_t tmp;
  51. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  52. tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
  53. WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
  54. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  55. tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) & S_000100_INVALIDATE_L2_CACHE(1);
  56. WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
  57. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  58. tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
  59. WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
  60. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  61. }
  62. int rs600_gart_init(struct radeon_device *rdev)
  63. {
  64. int r;
  65. if (rdev->gart.table.vram.robj) {
  66. WARN(1, "RS600 GART already initialized.\n");
  67. return 0;
  68. }
  69. /* Initialize common gart structure */
  70. r = radeon_gart_init(rdev);
  71. if (r) {
  72. return r;
  73. }
  74. rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
  75. return radeon_gart_table_vram_alloc(rdev);
  76. }
  77. int rs600_gart_enable(struct radeon_device *rdev)
  78. {
  79. u32 tmp;
  80. int r, i;
  81. if (rdev->gart.table.vram.robj == NULL) {
  82. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  83. return -EINVAL;
  84. }
  85. r = radeon_gart_table_vram_pin(rdev);
  86. if (r)
  87. return r;
  88. /* Enable bus master */
  89. tmp = RREG32(R_00004C_BUS_CNTL) & C_00004C_BUS_MASTER_DIS;
  90. WREG32(R_00004C_BUS_CNTL, tmp);
  91. /* FIXME: setup default page */
  92. WREG32_MC(R_000100_MC_PT0_CNTL,
  93. (S_000100_EFFECTIVE_L2_CACHE_SIZE(6) |
  94. S_000100_EFFECTIVE_L2_QUEUE_SIZE(6)));
  95. for (i = 0; i < 19; i++) {
  96. WREG32_MC(R_00016C_MC_PT0_CLIENT0_CNTL + i,
  97. S_00016C_ENABLE_TRANSLATION_MODE_OVERRIDE(1) |
  98. S_00016C_SYSTEM_ACCESS_MODE_MASK(
  99. V_00016C_SYSTEM_ACCESS_MODE_IN_SYS) |
  100. S_00016C_SYSTEM_APERTURE_UNMAPPED_ACCESS(
  101. V_00016C_SYSTEM_APERTURE_UNMAPPED_DEFAULT_PAGE) |
  102. S_00016C_EFFECTIVE_L1_CACHE_SIZE(1) |
  103. S_00016C_ENABLE_FRAGMENT_PROCESSING(1) |
  104. S_00016C_EFFECTIVE_L1_QUEUE_SIZE(1));
  105. }
  106. /* System context map to GART space */
  107. WREG32_MC(R_000112_MC_PT0_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.gtt_start);
  108. WREG32_MC(R_000114_MC_PT0_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.gtt_end);
  109. /* enable first context */
  110. WREG32_MC(R_00013C_MC_PT0_CONTEXT0_FLAT_START_ADDR, rdev->mc.gtt_start);
  111. WREG32_MC(R_00014C_MC_PT0_CONTEXT0_FLAT_END_ADDR, rdev->mc.gtt_end);
  112. WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL,
  113. S_000102_ENABLE_PAGE_TABLE(1) |
  114. S_000102_PAGE_TABLE_DEPTH(V_000102_PAGE_TABLE_FLAT));
  115. /* disable all other contexts */
  116. for (i = 1; i < 8; i++) {
  117. WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL + i, 0);
  118. }
  119. /* setup the page table */
  120. WREG32_MC(R_00012C_MC_PT0_CONTEXT0_FLAT_BASE_ADDR,
  121. rdev->gart.table_addr);
  122. WREG32_MC(R_00011C_MC_PT0_CONTEXT0_DEFAULT_READ_ADDR, 0);
  123. /* enable page tables */
  124. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  125. WREG32_MC(R_000100_MC_PT0_CNTL, (tmp | S_000100_ENABLE_PT(1)));
  126. tmp = RREG32_MC(R_000009_MC_CNTL1);
  127. WREG32_MC(R_000009_MC_CNTL1, (tmp | S_000009_ENABLE_PAGE_TABLES(1)));
  128. rs600_gart_tlb_flush(rdev);
  129. rdev->gart.ready = true;
  130. return 0;
  131. }
  132. void rs600_gart_disable(struct radeon_device *rdev)
  133. {
  134. uint32_t tmp;
  135. /* FIXME: disable out of gart access */
  136. WREG32_MC(R_000100_MC_PT0_CNTL, 0);
  137. tmp = RREG32_MC(R_000009_MC_CNTL1);
  138. WREG32_MC(R_000009_MC_CNTL1, tmp & C_000009_ENABLE_PAGE_TABLES);
  139. if (rdev->gart.table.vram.robj) {
  140. radeon_object_kunmap(rdev->gart.table.vram.robj);
  141. radeon_object_unpin(rdev->gart.table.vram.robj);
  142. }
  143. }
  144. void rs600_gart_fini(struct radeon_device *rdev)
  145. {
  146. rs600_gart_disable(rdev);
  147. radeon_gart_table_vram_free(rdev);
  148. radeon_gart_fini(rdev);
  149. }
  150. #define R600_PTE_VALID (1 << 0)
  151. #define R600_PTE_SYSTEM (1 << 1)
  152. #define R600_PTE_SNOOPED (1 << 2)
  153. #define R600_PTE_READABLE (1 << 5)
  154. #define R600_PTE_WRITEABLE (1 << 6)
  155. int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
  156. {
  157. void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
  158. if (i < 0 || i > rdev->gart.num_gpu_pages) {
  159. return -EINVAL;
  160. }
  161. addr = addr & 0xFFFFFFFFFFFFF000ULL;
  162. addr |= R600_PTE_VALID | R600_PTE_SYSTEM | R600_PTE_SNOOPED;
  163. addr |= R600_PTE_READABLE | R600_PTE_WRITEABLE;
  164. writeq(addr, ((void __iomem *)ptr) + (i * 8));
  165. return 0;
  166. }
  167. int rs600_irq_set(struct radeon_device *rdev)
  168. {
  169. uint32_t tmp = 0;
  170. uint32_t mode_int = 0;
  171. if (rdev->irq.sw_int) {
  172. tmp |= S_000040_SW_INT_EN(1);
  173. }
  174. if (rdev->irq.crtc_vblank_int[0]) {
  175. mode_int |= S_006540_D1MODE_VBLANK_INT_MASK(1);
  176. }
  177. if (rdev->irq.crtc_vblank_int[1]) {
  178. mode_int |= S_006540_D2MODE_VBLANK_INT_MASK(1);
  179. }
  180. WREG32(R_000040_GEN_INT_CNTL, tmp);
  181. WREG32(R_006540_DxMODE_INT_MASK, mode_int);
  182. return 0;
  183. }
  184. static inline uint32_t rs600_irq_ack(struct radeon_device *rdev, u32 *r500_disp_int)
  185. {
  186. uint32_t irqs = RREG32(R_000044_GEN_INT_STATUS);
  187. uint32_t irq_mask = ~C_000044_SW_INT;
  188. if (G_000044_DISPLAY_INT_STAT(irqs)) {
  189. *r500_disp_int = RREG32(R_007EDC_DISP_INTERRUPT_STATUS);
  190. if (G_007EDC_LB_D1_VBLANK_INTERRUPT(*r500_disp_int)) {
  191. WREG32(R_006534_D1MODE_VBLANK_STATUS,
  192. S_006534_D1MODE_VBLANK_ACK(1));
  193. }
  194. if (G_007EDC_LB_D2_VBLANK_INTERRUPT(*r500_disp_int)) {
  195. WREG32(R_006D34_D2MODE_VBLANK_STATUS,
  196. S_006D34_D2MODE_VBLANK_ACK(1));
  197. }
  198. } else {
  199. *r500_disp_int = 0;
  200. }
  201. if (irqs) {
  202. WREG32(R_000044_GEN_INT_STATUS, irqs);
  203. }
  204. return irqs & irq_mask;
  205. }
  206. void rs600_irq_disable(struct radeon_device *rdev)
  207. {
  208. u32 tmp;
  209. WREG32(R_000040_GEN_INT_CNTL, 0);
  210. WREG32(R_006540_DxMODE_INT_MASK, 0);
  211. /* Wait and acknowledge irq */
  212. mdelay(1);
  213. rs600_irq_ack(rdev, &tmp);
  214. }
  215. int rs600_irq_process(struct radeon_device *rdev)
  216. {
  217. uint32_t status;
  218. uint32_t r500_disp_int;
  219. status = rs600_irq_ack(rdev, &r500_disp_int);
  220. if (!status && !r500_disp_int) {
  221. return IRQ_NONE;
  222. }
  223. while (status || r500_disp_int) {
  224. /* SW interrupt */
  225. if (G_000040_SW_INT_EN(status))
  226. radeon_fence_process(rdev);
  227. /* Vertical blank interrupts */
  228. if (G_007EDC_LB_D1_VBLANK_INTERRUPT(r500_disp_int))
  229. drm_handle_vblank(rdev->ddev, 0);
  230. if (G_007EDC_LB_D2_VBLANK_INTERRUPT(r500_disp_int))
  231. drm_handle_vblank(rdev->ddev, 1);
  232. status = rs600_irq_ack(rdev, &r500_disp_int);
  233. }
  234. return IRQ_HANDLED;
  235. }
  236. u32 rs600_get_vblank_counter(struct radeon_device *rdev, int crtc)
  237. {
  238. if (crtc == 0)
  239. return RREG32(R_0060A4_D1CRTC_STATUS_FRAME_COUNT);
  240. else
  241. return RREG32(R_0068A4_D2CRTC_STATUS_FRAME_COUNT);
  242. }
  243. int rs600_mc_wait_for_idle(struct radeon_device *rdev)
  244. {
  245. unsigned i;
  246. for (i = 0; i < rdev->usec_timeout; i++) {
  247. if (G_000000_MC_IDLE(RREG32_MC(R_000000_MC_STATUS)))
  248. return 0;
  249. udelay(1);
  250. }
  251. return -1;
  252. }
  253. void rs600_gpu_init(struct radeon_device *rdev)
  254. {
  255. /* FIXME: HDP same place on rs600 ? */
  256. r100_hdp_reset(rdev);
  257. /* FIXME: is this correct ? */
  258. r420_pipes_init(rdev);
  259. /* Wait for mc idle */
  260. if (rs600_mc_wait_for_idle(rdev))
  261. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  262. }
  263. void rs600_vram_info(struct radeon_device *rdev)
  264. {
  265. /* FIXME: to do or is these values sane ? */
  266. rdev->mc.vram_is_ddr = true;
  267. rdev->mc.vram_width = 128;
  268. }
  269. void rs600_bandwidth_update(struct radeon_device *rdev)
  270. {
  271. /* FIXME: implement, should this be like rs690 ? */
  272. }
  273. uint32_t rs600_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  274. {
  275. WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
  276. S_000070_MC_IND_CITF_ARB0(1));
  277. return RREG32(R_000074_MC_IND_DATA);
  278. }
  279. void rs600_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  280. {
  281. WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
  282. S_000070_MC_IND_CITF_ARB0(1) | S_000070_MC_IND_WR_EN(1));
  283. WREG32(R_000074_MC_IND_DATA, v);
  284. }
  285. void rs600_debugfs(struct radeon_device *rdev)
  286. {
  287. if (r100_debugfs_rbbm_init(rdev))
  288. DRM_ERROR("Failed to register debugfs file for RBBM !\n");
  289. }
  290. void rs600_set_safe_registers(struct radeon_device *rdev)
  291. {
  292. rdev->config.r300.reg_safe_bm = rs600_reg_safe_bm;
  293. rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(rs600_reg_safe_bm);
  294. }
  295. static void rs600_mc_program(struct radeon_device *rdev)
  296. {
  297. struct rv515_mc_save save;
  298. /* Stops all mc clients */
  299. rv515_mc_stop(rdev, &save);
  300. /* Wait for mc idle */
  301. if (rs600_mc_wait_for_idle(rdev))
  302. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  303. /* FIXME: What does AGP means for such chipset ? */
  304. WREG32_MC(R_000005_MC_AGP_LOCATION, 0x0FFFFFFF);
  305. WREG32_MC(R_000006_AGP_BASE, 0);
  306. WREG32_MC(R_000007_AGP_BASE_2, 0);
  307. /* Program MC */
  308. WREG32_MC(R_000004_MC_FB_LOCATION,
  309. S_000004_MC_FB_START(rdev->mc.vram_start >> 16) |
  310. S_000004_MC_FB_TOP(rdev->mc.vram_end >> 16));
  311. WREG32(R_000134_HDP_FB_LOCATION,
  312. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  313. rv515_mc_resume(rdev, &save);
  314. }
  315. static int rs600_startup(struct radeon_device *rdev)
  316. {
  317. int r;
  318. rs600_mc_program(rdev);
  319. /* Resume clock */
  320. rv515_clock_startup(rdev);
  321. /* Initialize GPU configuration (# pipes, ...) */
  322. rs600_gpu_init(rdev);
  323. /* Initialize GART (initialize after TTM so we can allocate
  324. * memory through TTM but finalize after TTM) */
  325. r = rs600_gart_enable(rdev);
  326. if (r)
  327. return r;
  328. /* Enable IRQ */
  329. rdev->irq.sw_int = true;
  330. rs600_irq_set(rdev);
  331. /* 1M ring buffer */
  332. r = r100_cp_init(rdev, 1024 * 1024);
  333. if (r) {
  334. dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
  335. return r;
  336. }
  337. r = r100_wb_init(rdev);
  338. if (r)
  339. dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
  340. r = r100_ib_init(rdev);
  341. if (r) {
  342. dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
  343. return r;
  344. }
  345. return 0;
  346. }
  347. int rs600_resume(struct radeon_device *rdev)
  348. {
  349. /* Make sur GART are not working */
  350. rs600_gart_disable(rdev);
  351. /* Resume clock before doing reset */
  352. rv515_clock_startup(rdev);
  353. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  354. if (radeon_gpu_reset(rdev)) {
  355. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  356. RREG32(R_000E40_RBBM_STATUS),
  357. RREG32(R_0007C0_CP_STAT));
  358. }
  359. /* post */
  360. atom_asic_init(rdev->mode_info.atom_context);
  361. /* Resume clock after posting */
  362. rv515_clock_startup(rdev);
  363. return rs600_startup(rdev);
  364. }
  365. int rs600_suspend(struct radeon_device *rdev)
  366. {
  367. r100_cp_disable(rdev);
  368. r100_wb_disable(rdev);
  369. rs600_irq_disable(rdev);
  370. rs600_gart_disable(rdev);
  371. return 0;
  372. }
  373. void rs600_fini(struct radeon_device *rdev)
  374. {
  375. rs600_suspend(rdev);
  376. r100_cp_fini(rdev);
  377. r100_wb_fini(rdev);
  378. r100_ib_fini(rdev);
  379. radeon_gem_fini(rdev);
  380. rs600_gart_fini(rdev);
  381. radeon_irq_kms_fini(rdev);
  382. radeon_fence_driver_fini(rdev);
  383. radeon_object_fini(rdev);
  384. radeon_atombios_fini(rdev);
  385. kfree(rdev->bios);
  386. rdev->bios = NULL;
  387. }
  388. int rs600_init(struct radeon_device *rdev)
  389. {
  390. int r;
  391. /* Disable VGA */
  392. rv515_vga_render_disable(rdev);
  393. /* Initialize scratch registers */
  394. radeon_scratch_init(rdev);
  395. /* Initialize surface registers */
  396. radeon_surface_init(rdev);
  397. /* BIOS */
  398. if (!radeon_get_bios(rdev)) {
  399. if (ASIC_IS_AVIVO(rdev))
  400. return -EINVAL;
  401. }
  402. if (rdev->is_atom_bios) {
  403. r = radeon_atombios_init(rdev);
  404. if (r)
  405. return r;
  406. } else {
  407. dev_err(rdev->dev, "Expecting atombios for RS600 GPU\n");
  408. return -EINVAL;
  409. }
  410. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  411. if (radeon_gpu_reset(rdev)) {
  412. dev_warn(rdev->dev,
  413. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  414. RREG32(R_000E40_RBBM_STATUS),
  415. RREG32(R_0007C0_CP_STAT));
  416. }
  417. /* check if cards are posted or not */
  418. if (!radeon_card_posted(rdev) && rdev->bios) {
  419. DRM_INFO("GPU not posted. posting now...\n");
  420. atom_asic_init(rdev->mode_info.atom_context);
  421. }
  422. /* Initialize clocks */
  423. radeon_get_clock_info(rdev->ddev);
  424. /* Get vram informations */
  425. rs600_vram_info(rdev);
  426. /* Initialize memory controller (also test AGP) */
  427. r = r420_mc_init(rdev);
  428. if (r)
  429. return r;
  430. rs600_debugfs(rdev);
  431. /* Fence driver */
  432. r = radeon_fence_driver_init(rdev);
  433. if (r)
  434. return r;
  435. r = radeon_irq_kms_init(rdev);
  436. if (r)
  437. return r;
  438. /* Memory manager */
  439. r = radeon_object_init(rdev);
  440. if (r)
  441. return r;
  442. r = rs600_gart_init(rdev);
  443. if (r)
  444. return r;
  445. rs600_set_safe_registers(rdev);
  446. rdev->accel_working = true;
  447. r = rs600_startup(rdev);
  448. if (r) {
  449. /* Somethings want wront with the accel init stop accel */
  450. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  451. rs600_suspend(rdev);
  452. r100_cp_fini(rdev);
  453. r100_wb_fini(rdev);
  454. r100_ib_fini(rdev);
  455. rs600_gart_fini(rdev);
  456. radeon_irq_kms_fini(rdev);
  457. rdev->accel_working = false;
  458. }
  459. return 0;
  460. }