rs600.c 19 KB

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