rs600.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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 "radeon_asic.h"
  41. #include "atom.h"
  42. #include "rs600d.h"
  43. #include "rs600_reg_safe.h"
  44. void rs600_gpu_init(struct radeon_device *rdev);
  45. int rs600_mc_wait_for_idle(struct radeon_device *rdev);
  46. /* hpd for digital panel detect/disconnect */
  47. bool rs600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  48. {
  49. u32 tmp;
  50. bool connected = false;
  51. switch (hpd) {
  52. case RADEON_HPD_1:
  53. tmp = RREG32(R_007D04_DC_HOT_PLUG_DETECT1_INT_STATUS);
  54. if (G_007D04_DC_HOT_PLUG_DETECT1_SENSE(tmp))
  55. connected = true;
  56. break;
  57. case RADEON_HPD_2:
  58. tmp = RREG32(R_007D14_DC_HOT_PLUG_DETECT2_INT_STATUS);
  59. if (G_007D14_DC_HOT_PLUG_DETECT2_SENSE(tmp))
  60. connected = true;
  61. break;
  62. default:
  63. break;
  64. }
  65. return connected;
  66. }
  67. void rs600_hpd_set_polarity(struct radeon_device *rdev,
  68. enum radeon_hpd_id hpd)
  69. {
  70. u32 tmp;
  71. bool connected = rs600_hpd_sense(rdev, hpd);
  72. switch (hpd) {
  73. case RADEON_HPD_1:
  74. tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
  75. if (connected)
  76. tmp &= ~S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
  77. else
  78. tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_POLARITY(1);
  79. WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  80. break;
  81. case RADEON_HPD_2:
  82. tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
  83. if (connected)
  84. tmp &= ~S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
  85. else
  86. tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_POLARITY(1);
  87. WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  88. break;
  89. default:
  90. break;
  91. }
  92. }
  93. void rs600_hpd_init(struct radeon_device *rdev)
  94. {
  95. struct drm_device *dev = rdev->ddev;
  96. struct drm_connector *connector;
  97. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  98. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  99. switch (radeon_connector->hpd.hpd) {
  100. case RADEON_HPD_1:
  101. WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
  102. S_007D00_DC_HOT_PLUG_DETECT1_EN(1));
  103. rdev->irq.hpd[0] = true;
  104. break;
  105. case RADEON_HPD_2:
  106. WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
  107. S_007D10_DC_HOT_PLUG_DETECT2_EN(1));
  108. rdev->irq.hpd[1] = true;
  109. break;
  110. default:
  111. break;
  112. }
  113. }
  114. if (rdev->irq.installed)
  115. rs600_irq_set(rdev);
  116. }
  117. void rs600_hpd_fini(struct radeon_device *rdev)
  118. {
  119. struct drm_device *dev = rdev->ddev;
  120. struct drm_connector *connector;
  121. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  122. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  123. switch (radeon_connector->hpd.hpd) {
  124. case RADEON_HPD_1:
  125. WREG32(R_007D00_DC_HOT_PLUG_DETECT1_CONTROL,
  126. S_007D00_DC_HOT_PLUG_DETECT1_EN(0));
  127. rdev->irq.hpd[0] = false;
  128. break;
  129. case RADEON_HPD_2:
  130. WREG32(R_007D10_DC_HOT_PLUG_DETECT2_CONTROL,
  131. S_007D10_DC_HOT_PLUG_DETECT2_EN(0));
  132. rdev->irq.hpd[1] = false;
  133. break;
  134. default:
  135. break;
  136. }
  137. }
  138. }
  139. /*
  140. * GART.
  141. */
  142. void rs600_gart_tlb_flush(struct radeon_device *rdev)
  143. {
  144. uint32_t tmp;
  145. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  146. tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
  147. WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
  148. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  149. tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) & S_000100_INVALIDATE_L2_CACHE(1);
  150. WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
  151. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  152. tmp &= C_000100_INVALIDATE_ALL_L1_TLBS & C_000100_INVALIDATE_L2_CACHE;
  153. WREG32_MC(R_000100_MC_PT0_CNTL, tmp);
  154. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  155. }
  156. int rs600_gart_init(struct radeon_device *rdev)
  157. {
  158. int r;
  159. if (rdev->gart.table.vram.robj) {
  160. WARN(1, "RS600 GART already initialized.\n");
  161. return 0;
  162. }
  163. /* Initialize common gart structure */
  164. r = radeon_gart_init(rdev);
  165. if (r) {
  166. return r;
  167. }
  168. rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
  169. return radeon_gart_table_vram_alloc(rdev);
  170. }
  171. int rs600_gart_enable(struct radeon_device *rdev)
  172. {
  173. u32 tmp;
  174. int r, i;
  175. if (rdev->gart.table.vram.robj == NULL) {
  176. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  177. return -EINVAL;
  178. }
  179. r = radeon_gart_table_vram_pin(rdev);
  180. if (r)
  181. return r;
  182. radeon_gart_restore(rdev);
  183. /* Enable bus master */
  184. tmp = RREG32(R_00004C_BUS_CNTL) & C_00004C_BUS_MASTER_DIS;
  185. WREG32(R_00004C_BUS_CNTL, tmp);
  186. /* FIXME: setup default page */
  187. WREG32_MC(R_000100_MC_PT0_CNTL,
  188. (S_000100_EFFECTIVE_L2_CACHE_SIZE(6) |
  189. S_000100_EFFECTIVE_L2_QUEUE_SIZE(6)));
  190. for (i = 0; i < 19; i++) {
  191. WREG32_MC(R_00016C_MC_PT0_CLIENT0_CNTL + i,
  192. S_00016C_ENABLE_TRANSLATION_MODE_OVERRIDE(1) |
  193. S_00016C_SYSTEM_ACCESS_MODE_MASK(
  194. V_00016C_SYSTEM_ACCESS_MODE_NOT_IN_SYS) |
  195. S_00016C_SYSTEM_APERTURE_UNMAPPED_ACCESS(
  196. V_00016C_SYSTEM_APERTURE_UNMAPPED_PASSTHROUGH) |
  197. S_00016C_EFFECTIVE_L1_CACHE_SIZE(3) |
  198. S_00016C_ENABLE_FRAGMENT_PROCESSING(1) |
  199. S_00016C_EFFECTIVE_L1_QUEUE_SIZE(3));
  200. }
  201. /* enable first context */
  202. WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL,
  203. S_000102_ENABLE_PAGE_TABLE(1) |
  204. S_000102_PAGE_TABLE_DEPTH(V_000102_PAGE_TABLE_FLAT));
  205. /* disable all other contexts */
  206. for (i = 1; i < 8; i++)
  207. WREG32_MC(R_000102_MC_PT0_CONTEXT0_CNTL + i, 0);
  208. /* setup the page table */
  209. WREG32_MC(R_00012C_MC_PT0_CONTEXT0_FLAT_BASE_ADDR,
  210. rdev->gart.table_addr);
  211. WREG32_MC(R_00013C_MC_PT0_CONTEXT0_FLAT_START_ADDR, rdev->mc.gtt_start);
  212. WREG32_MC(R_00014C_MC_PT0_CONTEXT0_FLAT_END_ADDR, rdev->mc.gtt_end);
  213. WREG32_MC(R_00011C_MC_PT0_CONTEXT0_DEFAULT_READ_ADDR, 0);
  214. /* System context maps to VRAM space */
  215. WREG32_MC(R_000112_MC_PT0_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start);
  216. WREG32_MC(R_000114_MC_PT0_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end);
  217. /* enable page tables */
  218. tmp = RREG32_MC(R_000100_MC_PT0_CNTL);
  219. WREG32_MC(R_000100_MC_PT0_CNTL, (tmp | S_000100_ENABLE_PT(1)));
  220. tmp = RREG32_MC(R_000009_MC_CNTL1);
  221. WREG32_MC(R_000009_MC_CNTL1, (tmp | S_000009_ENABLE_PAGE_TABLES(1)));
  222. rs600_gart_tlb_flush(rdev);
  223. rdev->gart.ready = true;
  224. return 0;
  225. }
  226. void rs600_gart_disable(struct radeon_device *rdev)
  227. {
  228. u32 tmp;
  229. int r;
  230. /* FIXME: disable out of gart access */
  231. WREG32_MC(R_000100_MC_PT0_CNTL, 0);
  232. tmp = RREG32_MC(R_000009_MC_CNTL1);
  233. WREG32_MC(R_000009_MC_CNTL1, tmp & C_000009_ENABLE_PAGE_TABLES);
  234. if (rdev->gart.table.vram.robj) {
  235. r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
  236. if (r == 0) {
  237. radeon_bo_kunmap(rdev->gart.table.vram.robj);
  238. radeon_bo_unpin(rdev->gart.table.vram.robj);
  239. radeon_bo_unreserve(rdev->gart.table.vram.robj);
  240. }
  241. }
  242. }
  243. void rs600_gart_fini(struct radeon_device *rdev)
  244. {
  245. rs600_gart_disable(rdev);
  246. radeon_gart_table_vram_free(rdev);
  247. radeon_gart_fini(rdev);
  248. }
  249. #define R600_PTE_VALID (1 << 0)
  250. #define R600_PTE_SYSTEM (1 << 1)
  251. #define R600_PTE_SNOOPED (1 << 2)
  252. #define R600_PTE_READABLE (1 << 5)
  253. #define R600_PTE_WRITEABLE (1 << 6)
  254. int rs600_gart_set_page(struct radeon_device *rdev, int i, uint64_t addr)
  255. {
  256. void __iomem *ptr = (void *)rdev->gart.table.vram.ptr;
  257. if (i < 0 || i > rdev->gart.num_gpu_pages) {
  258. return -EINVAL;
  259. }
  260. addr = addr & 0xFFFFFFFFFFFFF000ULL;
  261. addr |= R600_PTE_VALID | R600_PTE_SYSTEM | R600_PTE_SNOOPED;
  262. addr |= R600_PTE_READABLE | R600_PTE_WRITEABLE;
  263. writeq(addr, ((void __iomem *)ptr) + (i * 8));
  264. return 0;
  265. }
  266. int rs600_irq_set(struct radeon_device *rdev)
  267. {
  268. uint32_t tmp = 0;
  269. uint32_t mode_int = 0;
  270. u32 hpd1 = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL) &
  271. ~S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
  272. u32 hpd2 = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL) &
  273. ~S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
  274. if (!rdev->irq.installed) {
  275. WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
  276. WREG32(R_000040_GEN_INT_CNTL, 0);
  277. return -EINVAL;
  278. }
  279. if (rdev->irq.sw_int) {
  280. tmp |= S_000040_SW_INT_EN(1);
  281. }
  282. if (rdev->irq.crtc_vblank_int[0]) {
  283. mode_int |= S_006540_D1MODE_VBLANK_INT_MASK(1);
  284. }
  285. if (rdev->irq.crtc_vblank_int[1]) {
  286. mode_int |= S_006540_D2MODE_VBLANK_INT_MASK(1);
  287. }
  288. if (rdev->irq.hpd[0]) {
  289. hpd1 |= S_007D08_DC_HOT_PLUG_DETECT1_INT_EN(1);
  290. }
  291. if (rdev->irq.hpd[1]) {
  292. hpd2 |= S_007D18_DC_HOT_PLUG_DETECT2_INT_EN(1);
  293. }
  294. WREG32(R_000040_GEN_INT_CNTL, tmp);
  295. WREG32(R_006540_DxMODE_INT_MASK, mode_int);
  296. WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
  297. WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
  298. return 0;
  299. }
  300. static inline uint32_t rs600_irq_ack(struct radeon_device *rdev, u32 *r500_disp_int)
  301. {
  302. uint32_t irqs = RREG32(R_000044_GEN_INT_STATUS);
  303. uint32_t irq_mask = ~C_000044_SW_INT;
  304. u32 tmp;
  305. if (G_000044_DISPLAY_INT_STAT(irqs)) {
  306. *r500_disp_int = RREG32(R_007EDC_DISP_INTERRUPT_STATUS);
  307. if (G_007EDC_LB_D1_VBLANK_INTERRUPT(*r500_disp_int)) {
  308. WREG32(R_006534_D1MODE_VBLANK_STATUS,
  309. S_006534_D1MODE_VBLANK_ACK(1));
  310. }
  311. if (G_007EDC_LB_D2_VBLANK_INTERRUPT(*r500_disp_int)) {
  312. WREG32(R_006D34_D2MODE_VBLANK_STATUS,
  313. S_006D34_D2MODE_VBLANK_ACK(1));
  314. }
  315. if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(*r500_disp_int)) {
  316. tmp = RREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL);
  317. tmp |= S_007D08_DC_HOT_PLUG_DETECT1_INT_ACK(1);
  318. WREG32(R_007D08_DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  319. }
  320. if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(*r500_disp_int)) {
  321. tmp = RREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL);
  322. tmp |= S_007D18_DC_HOT_PLUG_DETECT2_INT_ACK(1);
  323. WREG32(R_007D18_DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  324. }
  325. } else {
  326. *r500_disp_int = 0;
  327. }
  328. if (irqs) {
  329. WREG32(R_000044_GEN_INT_STATUS, irqs);
  330. }
  331. return irqs & irq_mask;
  332. }
  333. void rs600_irq_disable(struct radeon_device *rdev)
  334. {
  335. u32 tmp;
  336. WREG32(R_000040_GEN_INT_CNTL, 0);
  337. WREG32(R_006540_DxMODE_INT_MASK, 0);
  338. /* Wait and acknowledge irq */
  339. mdelay(1);
  340. rs600_irq_ack(rdev, &tmp);
  341. }
  342. int rs600_irq_process(struct radeon_device *rdev)
  343. {
  344. uint32_t status, msi_rearm;
  345. uint32_t r500_disp_int;
  346. bool queue_hotplug = false;
  347. status = rs600_irq_ack(rdev, &r500_disp_int);
  348. if (!status && !r500_disp_int) {
  349. return IRQ_NONE;
  350. }
  351. while (status || r500_disp_int) {
  352. /* SW interrupt */
  353. if (G_000044_SW_INT(status))
  354. radeon_fence_process(rdev);
  355. /* Vertical blank interrupts */
  356. if (G_007EDC_LB_D1_VBLANK_INTERRUPT(r500_disp_int)) {
  357. drm_handle_vblank(rdev->ddev, 0);
  358. rdev->pm.vblank_sync = true;
  359. wake_up(&rdev->irq.vblank_queue);
  360. }
  361. if (G_007EDC_LB_D2_VBLANK_INTERRUPT(r500_disp_int)) {
  362. drm_handle_vblank(rdev->ddev, 1);
  363. rdev->pm.vblank_sync = true;
  364. wake_up(&rdev->irq.vblank_queue);
  365. }
  366. if (G_007EDC_DC_HOT_PLUG_DETECT1_INTERRUPT(r500_disp_int)) {
  367. queue_hotplug = true;
  368. DRM_DEBUG("HPD1\n");
  369. }
  370. if (G_007EDC_DC_HOT_PLUG_DETECT2_INTERRUPT(r500_disp_int)) {
  371. queue_hotplug = true;
  372. DRM_DEBUG("HPD2\n");
  373. }
  374. status = rs600_irq_ack(rdev, &r500_disp_int);
  375. }
  376. if (queue_hotplug)
  377. queue_work(rdev->wq, &rdev->hotplug_work);
  378. if (rdev->msi_enabled) {
  379. switch (rdev->family) {
  380. case CHIP_RS600:
  381. case CHIP_RS690:
  382. case CHIP_RS740:
  383. msi_rearm = RREG32(RADEON_BUS_CNTL) & ~RS600_MSI_REARM;
  384. WREG32(RADEON_BUS_CNTL, msi_rearm);
  385. WREG32(RADEON_BUS_CNTL, msi_rearm | RS600_MSI_REARM);
  386. break;
  387. default:
  388. msi_rearm = RREG32(RADEON_MSI_REARM_EN) & ~RV370_MSI_REARM_EN;
  389. WREG32(RADEON_MSI_REARM_EN, msi_rearm);
  390. WREG32(RADEON_MSI_REARM_EN, msi_rearm | RV370_MSI_REARM_EN);
  391. break;
  392. }
  393. }
  394. return IRQ_HANDLED;
  395. }
  396. u32 rs600_get_vblank_counter(struct radeon_device *rdev, int crtc)
  397. {
  398. if (crtc == 0)
  399. return RREG32(R_0060A4_D1CRTC_STATUS_FRAME_COUNT);
  400. else
  401. return RREG32(R_0068A4_D2CRTC_STATUS_FRAME_COUNT);
  402. }
  403. int rs600_mc_wait_for_idle(struct radeon_device *rdev)
  404. {
  405. unsigned i;
  406. for (i = 0; i < rdev->usec_timeout; i++) {
  407. if (G_000000_MC_IDLE(RREG32_MC(R_000000_MC_STATUS)))
  408. return 0;
  409. udelay(1);
  410. }
  411. return -1;
  412. }
  413. void rs600_gpu_init(struct radeon_device *rdev)
  414. {
  415. r100_hdp_reset(rdev);
  416. r420_pipes_init(rdev);
  417. /* Wait for mc idle */
  418. if (rs600_mc_wait_for_idle(rdev))
  419. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  420. }
  421. void rs600_mc_init(struct radeon_device *rdev)
  422. {
  423. u64 base;
  424. rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
  425. rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
  426. rdev->mc.vram_is_ddr = true;
  427. rdev->mc.vram_width = 128;
  428. rdev->mc.real_vram_size = RREG32(RADEON_CONFIG_MEMSIZE);
  429. rdev->mc.mc_vram_size = rdev->mc.real_vram_size;
  430. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  431. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  432. base = RREG32_MC(R_000004_MC_FB_LOCATION);
  433. base = G_000004_MC_FB_START(base) << 16;
  434. radeon_vram_location(rdev, &rdev->mc, base);
  435. radeon_gtt_location(rdev, &rdev->mc);
  436. }
  437. void rs600_bandwidth_update(struct radeon_device *rdev)
  438. {
  439. /* FIXME: implement, should this be like rs690 ? */
  440. }
  441. uint32_t rs600_mc_rreg(struct radeon_device *rdev, uint32_t reg)
  442. {
  443. WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
  444. S_000070_MC_IND_CITF_ARB0(1));
  445. return RREG32(R_000074_MC_IND_DATA);
  446. }
  447. void rs600_mc_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  448. {
  449. WREG32(R_000070_MC_IND_INDEX, S_000070_MC_IND_ADDR(reg) |
  450. S_000070_MC_IND_CITF_ARB0(1) | S_000070_MC_IND_WR_EN(1));
  451. WREG32(R_000074_MC_IND_DATA, v);
  452. }
  453. void rs600_debugfs(struct radeon_device *rdev)
  454. {
  455. if (r100_debugfs_rbbm_init(rdev))
  456. DRM_ERROR("Failed to register debugfs file for RBBM !\n");
  457. }
  458. void rs600_set_safe_registers(struct radeon_device *rdev)
  459. {
  460. rdev->config.r300.reg_safe_bm = rs600_reg_safe_bm;
  461. rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(rs600_reg_safe_bm);
  462. }
  463. static void rs600_mc_program(struct radeon_device *rdev)
  464. {
  465. struct rv515_mc_save save;
  466. /* Stops all mc clients */
  467. rv515_mc_stop(rdev, &save);
  468. /* Wait for mc idle */
  469. if (rs600_mc_wait_for_idle(rdev))
  470. dev_warn(rdev->dev, "Wait MC idle timeout before updating MC.\n");
  471. /* FIXME: What does AGP means for such chipset ? */
  472. WREG32_MC(R_000005_MC_AGP_LOCATION, 0x0FFFFFFF);
  473. WREG32_MC(R_000006_AGP_BASE, 0);
  474. WREG32_MC(R_000007_AGP_BASE_2, 0);
  475. /* Program MC */
  476. WREG32_MC(R_000004_MC_FB_LOCATION,
  477. S_000004_MC_FB_START(rdev->mc.vram_start >> 16) |
  478. S_000004_MC_FB_TOP(rdev->mc.vram_end >> 16));
  479. WREG32(R_000134_HDP_FB_LOCATION,
  480. S_000134_HDP_FB_START(rdev->mc.vram_start >> 16));
  481. rv515_mc_resume(rdev, &save);
  482. }
  483. static int rs600_startup(struct radeon_device *rdev)
  484. {
  485. int r;
  486. rs600_mc_program(rdev);
  487. /* Resume clock */
  488. rv515_clock_startup(rdev);
  489. /* Initialize GPU configuration (# pipes, ...) */
  490. rs600_gpu_init(rdev);
  491. /* Initialize GART (initialize after TTM so we can allocate
  492. * memory through TTM but finalize after TTM) */
  493. r = rs600_gart_enable(rdev);
  494. if (r)
  495. return r;
  496. /* Enable IRQ */
  497. rs600_irq_set(rdev);
  498. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  499. /* 1M ring buffer */
  500. r = r100_cp_init(rdev, 1024 * 1024);
  501. if (r) {
  502. dev_err(rdev->dev, "failled initializing CP (%d).\n", r);
  503. return r;
  504. }
  505. r = r100_wb_init(rdev);
  506. if (r)
  507. dev_err(rdev->dev, "failled initializing WB (%d).\n", r);
  508. r = r100_ib_init(rdev);
  509. if (r) {
  510. dev_err(rdev->dev, "failled initializing IB (%d).\n", r);
  511. return r;
  512. }
  513. return 0;
  514. }
  515. int rs600_resume(struct radeon_device *rdev)
  516. {
  517. /* Make sur GART are not working */
  518. rs600_gart_disable(rdev);
  519. /* Resume clock before doing reset */
  520. rv515_clock_startup(rdev);
  521. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  522. if (radeon_gpu_reset(rdev)) {
  523. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  524. RREG32(R_000E40_RBBM_STATUS),
  525. RREG32(R_0007C0_CP_STAT));
  526. }
  527. /* post */
  528. atom_asic_init(rdev->mode_info.atom_context);
  529. /* Resume clock after posting */
  530. rv515_clock_startup(rdev);
  531. /* Initialize surface registers */
  532. radeon_surface_init(rdev);
  533. return rs600_startup(rdev);
  534. }
  535. int rs600_suspend(struct radeon_device *rdev)
  536. {
  537. r100_cp_disable(rdev);
  538. r100_wb_disable(rdev);
  539. rs600_irq_disable(rdev);
  540. rs600_gart_disable(rdev);
  541. return 0;
  542. }
  543. void rs600_fini(struct radeon_device *rdev)
  544. {
  545. radeon_pm_fini(rdev);
  546. r100_cp_fini(rdev);
  547. r100_wb_fini(rdev);
  548. r100_ib_fini(rdev);
  549. radeon_gem_fini(rdev);
  550. rs600_gart_fini(rdev);
  551. radeon_irq_kms_fini(rdev);
  552. radeon_fence_driver_fini(rdev);
  553. radeon_bo_fini(rdev);
  554. radeon_atombios_fini(rdev);
  555. kfree(rdev->bios);
  556. rdev->bios = NULL;
  557. }
  558. int rs600_init(struct radeon_device *rdev)
  559. {
  560. int r;
  561. /* Disable VGA */
  562. rv515_vga_render_disable(rdev);
  563. /* Initialize scratch registers */
  564. radeon_scratch_init(rdev);
  565. /* Initialize surface registers */
  566. radeon_surface_init(rdev);
  567. /* BIOS */
  568. if (!radeon_get_bios(rdev)) {
  569. if (ASIC_IS_AVIVO(rdev))
  570. return -EINVAL;
  571. }
  572. if (rdev->is_atom_bios) {
  573. r = radeon_atombios_init(rdev);
  574. if (r)
  575. return r;
  576. } else {
  577. dev_err(rdev->dev, "Expecting atombios for RS600 GPU\n");
  578. return -EINVAL;
  579. }
  580. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  581. if (radeon_gpu_reset(rdev)) {
  582. dev_warn(rdev->dev,
  583. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  584. RREG32(R_000E40_RBBM_STATUS),
  585. RREG32(R_0007C0_CP_STAT));
  586. }
  587. /* check if cards are posted or not */
  588. if (radeon_boot_test_post_card(rdev) == false)
  589. return -EINVAL;
  590. /* Initialize clocks */
  591. radeon_get_clock_info(rdev->ddev);
  592. /* Initialize power management */
  593. radeon_pm_init(rdev);
  594. /* initialize memory controller */
  595. rs600_mc_init(rdev);
  596. rs600_debugfs(rdev);
  597. /* Fence driver */
  598. r = radeon_fence_driver_init(rdev);
  599. if (r)
  600. return r;
  601. r = radeon_irq_kms_init(rdev);
  602. if (r)
  603. return r;
  604. /* Memory manager */
  605. r = radeon_bo_init(rdev);
  606. if (r)
  607. return r;
  608. r = rs600_gart_init(rdev);
  609. if (r)
  610. return r;
  611. rs600_set_safe_registers(rdev);
  612. rdev->accel_working = true;
  613. r = rs600_startup(rdev);
  614. if (r) {
  615. /* Somethings want wront with the accel init stop accel */
  616. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  617. r100_cp_fini(rdev);
  618. r100_wb_fini(rdev);
  619. r100_ib_fini(rdev);
  620. rs600_gart_fini(rdev);
  621. radeon_irq_kms_fini(rdev);
  622. rdev->accel_working = false;
  623. }
  624. return 0;
  625. }