r300.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  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 <linux/slab.h>
  30. #include <drm/drmP.h>
  31. #include <drm/drm.h>
  32. #include <drm/drm_crtc_helper.h>
  33. #include "radeon_reg.h"
  34. #include "radeon.h"
  35. #include "radeon_asic.h"
  36. #include <drm/radeon_drm.h>
  37. #include "r100_track.h"
  38. #include "r300d.h"
  39. #include "rv350d.h"
  40. #include "r300_reg_safe.h"
  41. /* This files gather functions specifics to: r300,r350,rv350,rv370,rv380
  42. *
  43. * GPU Errata:
  44. * - HOST_PATH_CNTL: r300 family seems to dislike write to HOST_PATH_CNTL
  45. * using MMIO to flush host path read cache, this lead to HARDLOCKUP.
  46. * However, scheduling such write to the ring seems harmless, i suspect
  47. * the CP read collide with the flush somehow, or maybe the MC, hard to
  48. * tell. (Jerome Glisse)
  49. */
  50. /*
  51. * Indirect registers accessor
  52. */
  53. uint32_t rv370_pcie_rreg(struct radeon_device *rdev, uint32_t reg)
  54. {
  55. unsigned long flags;
  56. uint32_t r;
  57. spin_lock_irqsave(&rdev->pcie_idx_lock, flags);
  58. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  59. r = RREG32(RADEON_PCIE_DATA);
  60. spin_unlock_irqrestore(&rdev->pcie_idx_lock, flags);
  61. return r;
  62. }
  63. void rv370_pcie_wreg(struct radeon_device *rdev, uint32_t reg, uint32_t v)
  64. {
  65. unsigned long flags;
  66. spin_lock_irqsave(&rdev->pcie_idx_lock, flags);
  67. WREG32(RADEON_PCIE_INDEX, ((reg) & rdev->pcie_reg_mask));
  68. WREG32(RADEON_PCIE_DATA, (v));
  69. spin_unlock_irqrestore(&rdev->pcie_idx_lock, flags);
  70. }
  71. /*
  72. * rv370,rv380 PCIE GART
  73. */
  74. static int rv370_debugfs_pcie_gart_info_init(struct radeon_device *rdev);
  75. void rv370_pcie_gart_tlb_flush(struct radeon_device *rdev)
  76. {
  77. uint32_t tmp;
  78. int i;
  79. /* Workaround HW bug do flush 2 times */
  80. for (i = 0; i < 2; i++) {
  81. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
  82. WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp | RADEON_PCIE_TX_GART_INVALIDATE_TLB);
  83. (void)RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
  84. WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp);
  85. }
  86. mb();
  87. }
  88. #define R300_PTE_UNSNOOPED (1 << 0)
  89. #define R300_PTE_WRITEABLE (1 << 2)
  90. #define R300_PTE_READABLE (1 << 3)
  91. uint64_t rv370_pcie_gart_get_page_entry(uint64_t addr, uint32_t flags)
  92. {
  93. addr = (lower_32_bits(addr) >> 8) |
  94. ((upper_32_bits(addr) & 0xff) << 24);
  95. if (flags & RADEON_GART_PAGE_READ)
  96. addr |= R300_PTE_READABLE;
  97. if (flags & RADEON_GART_PAGE_WRITE)
  98. addr |= R300_PTE_WRITEABLE;
  99. if (!(flags & RADEON_GART_PAGE_SNOOP))
  100. addr |= R300_PTE_UNSNOOPED;
  101. return addr;
  102. }
  103. void rv370_pcie_gart_set_page(struct radeon_device *rdev, unsigned i,
  104. uint64_t entry)
  105. {
  106. void __iomem *ptr = rdev->gart.ptr;
  107. /* on x86 we want this to be CPU endian, on powerpc
  108. * on powerpc without HW swappers, it'll get swapped on way
  109. * into VRAM - so no need for cpu_to_le32 on VRAM tables */
  110. writel(entry, ((void __iomem *)ptr) + (i * 4));
  111. }
  112. int rv370_pcie_gart_init(struct radeon_device *rdev)
  113. {
  114. int r;
  115. if (rdev->gart.robj) {
  116. WARN(1, "RV370 PCIE GART already initialized\n");
  117. return 0;
  118. }
  119. /* Initialize common gart structure */
  120. r = radeon_gart_init(rdev);
  121. if (r)
  122. return r;
  123. r = rv370_debugfs_pcie_gart_info_init(rdev);
  124. if (r)
  125. DRM_ERROR("Failed to register debugfs file for PCIE gart !\n");
  126. rdev->gart.table_size = rdev->gart.num_gpu_pages * 4;
  127. rdev->asic->gart.tlb_flush = &rv370_pcie_gart_tlb_flush;
  128. rdev->asic->gart.get_page_entry = &rv370_pcie_gart_get_page_entry;
  129. rdev->asic->gart.set_page = &rv370_pcie_gart_set_page;
  130. return radeon_gart_table_vram_alloc(rdev);
  131. }
  132. int rv370_pcie_gart_enable(struct radeon_device *rdev)
  133. {
  134. uint32_t table_addr;
  135. uint32_t tmp;
  136. int r;
  137. if (rdev->gart.robj == NULL) {
  138. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  139. return -EINVAL;
  140. }
  141. r = radeon_gart_table_vram_pin(rdev);
  142. if (r)
  143. return r;
  144. /* discard memory request outside of configured range */
  145. tmp = RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
  146. WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp);
  147. WREG32_PCIE(RADEON_PCIE_TX_GART_START_LO, rdev->mc.gtt_start);
  148. tmp = rdev->mc.gtt_end & ~RADEON_GPU_PAGE_MASK;
  149. WREG32_PCIE(RADEON_PCIE_TX_GART_END_LO, tmp);
  150. WREG32_PCIE(RADEON_PCIE_TX_GART_START_HI, 0);
  151. WREG32_PCIE(RADEON_PCIE_TX_GART_END_HI, 0);
  152. table_addr = rdev->gart.table_addr;
  153. WREG32_PCIE(RADEON_PCIE_TX_GART_BASE, table_addr);
  154. /* FIXME: setup default page */
  155. WREG32_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO, rdev->mc.vram_start);
  156. WREG32_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_HI, 0);
  157. /* Clear error */
  158. WREG32_PCIE(RADEON_PCIE_TX_GART_ERROR, 0);
  159. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
  160. tmp |= RADEON_PCIE_TX_GART_EN;
  161. tmp |= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
  162. WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp);
  163. rv370_pcie_gart_tlb_flush(rdev);
  164. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  165. (unsigned)(rdev->mc.gtt_size >> 20),
  166. (unsigned long long)table_addr);
  167. rdev->gart.ready = true;
  168. return 0;
  169. }
  170. void rv370_pcie_gart_disable(struct radeon_device *rdev)
  171. {
  172. u32 tmp;
  173. WREG32_PCIE(RADEON_PCIE_TX_GART_START_LO, 0);
  174. WREG32_PCIE(RADEON_PCIE_TX_GART_END_LO, 0);
  175. WREG32_PCIE(RADEON_PCIE_TX_GART_START_HI, 0);
  176. WREG32_PCIE(RADEON_PCIE_TX_GART_END_HI, 0);
  177. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
  178. tmp |= RADEON_PCIE_TX_GART_UNMAPPED_ACCESS_DISCARD;
  179. WREG32_PCIE(RADEON_PCIE_TX_GART_CNTL, tmp & ~RADEON_PCIE_TX_GART_EN);
  180. radeon_gart_table_vram_unpin(rdev);
  181. }
  182. void rv370_pcie_gart_fini(struct radeon_device *rdev)
  183. {
  184. radeon_gart_fini(rdev);
  185. rv370_pcie_gart_disable(rdev);
  186. radeon_gart_table_vram_free(rdev);
  187. }
  188. void r300_fence_ring_emit(struct radeon_device *rdev,
  189. struct radeon_fence *fence)
  190. {
  191. struct radeon_ring *ring = &rdev->ring[fence->ring];
  192. /* Who ever call radeon_fence_emit should call ring_lock and ask
  193. * for enough space (today caller are ib schedule and buffer move) */
  194. /* Write SC register so SC & US assert idle */
  195. radeon_ring_write(ring, PACKET0(R300_RE_SCISSORS_TL, 0));
  196. radeon_ring_write(ring, 0);
  197. radeon_ring_write(ring, PACKET0(R300_RE_SCISSORS_BR, 0));
  198. radeon_ring_write(ring, 0);
  199. /* Flush 3D cache */
  200. radeon_ring_write(ring, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
  201. radeon_ring_write(ring, R300_RB3D_DC_FLUSH);
  202. radeon_ring_write(ring, PACKET0(R300_RB3D_ZCACHE_CTLSTAT, 0));
  203. radeon_ring_write(ring, R300_ZC_FLUSH);
  204. /* Wait until IDLE & CLEAN */
  205. radeon_ring_write(ring, PACKET0(RADEON_WAIT_UNTIL, 0));
  206. radeon_ring_write(ring, (RADEON_WAIT_3D_IDLECLEAN |
  207. RADEON_WAIT_2D_IDLECLEAN |
  208. RADEON_WAIT_DMA_GUI_IDLE));
  209. radeon_ring_write(ring, PACKET0(RADEON_HOST_PATH_CNTL, 0));
  210. radeon_ring_write(ring, rdev->config.r300.hdp_cntl |
  211. RADEON_HDP_READ_BUFFER_INVALIDATE);
  212. radeon_ring_write(ring, PACKET0(RADEON_HOST_PATH_CNTL, 0));
  213. radeon_ring_write(ring, rdev->config.r300.hdp_cntl);
  214. /* Emit fence sequence & fire IRQ */
  215. radeon_ring_write(ring, PACKET0(rdev->fence_drv[fence->ring].scratch_reg, 0));
  216. radeon_ring_write(ring, fence->seq);
  217. radeon_ring_write(ring, PACKET0(RADEON_GEN_INT_STATUS, 0));
  218. radeon_ring_write(ring, RADEON_SW_INT_FIRE);
  219. }
  220. void r300_ring_start(struct radeon_device *rdev, struct radeon_ring *ring)
  221. {
  222. unsigned gb_tile_config;
  223. int r;
  224. /* Sub pixel 1/12 so we can have 4K rendering according to doc */
  225. gb_tile_config = (R300_ENABLE_TILING | R300_TILE_SIZE_16);
  226. switch(rdev->num_gb_pipes) {
  227. case 2:
  228. gb_tile_config |= R300_PIPE_COUNT_R300;
  229. break;
  230. case 3:
  231. gb_tile_config |= R300_PIPE_COUNT_R420_3P;
  232. break;
  233. case 4:
  234. gb_tile_config |= R300_PIPE_COUNT_R420;
  235. break;
  236. case 1:
  237. default:
  238. gb_tile_config |= R300_PIPE_COUNT_RV350;
  239. break;
  240. }
  241. r = radeon_ring_lock(rdev, ring, 64);
  242. if (r) {
  243. return;
  244. }
  245. radeon_ring_write(ring, PACKET0(RADEON_ISYNC_CNTL, 0));
  246. radeon_ring_write(ring,
  247. RADEON_ISYNC_ANY2D_IDLE3D |
  248. RADEON_ISYNC_ANY3D_IDLE2D |
  249. RADEON_ISYNC_WAIT_IDLEGUI |
  250. RADEON_ISYNC_CPSCRATCH_IDLEGUI);
  251. radeon_ring_write(ring, PACKET0(R300_GB_TILE_CONFIG, 0));
  252. radeon_ring_write(ring, gb_tile_config);
  253. radeon_ring_write(ring, PACKET0(RADEON_WAIT_UNTIL, 0));
  254. radeon_ring_write(ring,
  255. RADEON_WAIT_2D_IDLECLEAN |
  256. RADEON_WAIT_3D_IDLECLEAN);
  257. radeon_ring_write(ring, PACKET0(R300_DST_PIPE_CONFIG, 0));
  258. radeon_ring_write(ring, R300_PIPE_AUTO_CONFIG);
  259. radeon_ring_write(ring, PACKET0(R300_GB_SELECT, 0));
  260. radeon_ring_write(ring, 0);
  261. radeon_ring_write(ring, PACKET0(R300_GB_ENABLE, 0));
  262. radeon_ring_write(ring, 0);
  263. radeon_ring_write(ring, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
  264. radeon_ring_write(ring, R300_RB3D_DC_FLUSH | R300_RB3D_DC_FREE);
  265. radeon_ring_write(ring, PACKET0(R300_RB3D_ZCACHE_CTLSTAT, 0));
  266. radeon_ring_write(ring, R300_ZC_FLUSH | R300_ZC_FREE);
  267. radeon_ring_write(ring, PACKET0(RADEON_WAIT_UNTIL, 0));
  268. radeon_ring_write(ring,
  269. RADEON_WAIT_2D_IDLECLEAN |
  270. RADEON_WAIT_3D_IDLECLEAN);
  271. radeon_ring_write(ring, PACKET0(R300_GB_AA_CONFIG, 0));
  272. radeon_ring_write(ring, 0);
  273. radeon_ring_write(ring, PACKET0(R300_RB3D_DSTCACHE_CTLSTAT, 0));
  274. radeon_ring_write(ring, R300_RB3D_DC_FLUSH | R300_RB3D_DC_FREE);
  275. radeon_ring_write(ring, PACKET0(R300_RB3D_ZCACHE_CTLSTAT, 0));
  276. radeon_ring_write(ring, R300_ZC_FLUSH | R300_ZC_FREE);
  277. radeon_ring_write(ring, PACKET0(R300_GB_MSPOS0, 0));
  278. radeon_ring_write(ring,
  279. ((6 << R300_MS_X0_SHIFT) |
  280. (6 << R300_MS_Y0_SHIFT) |
  281. (6 << R300_MS_X1_SHIFT) |
  282. (6 << R300_MS_Y1_SHIFT) |
  283. (6 << R300_MS_X2_SHIFT) |
  284. (6 << R300_MS_Y2_SHIFT) |
  285. (6 << R300_MSBD0_Y_SHIFT) |
  286. (6 << R300_MSBD0_X_SHIFT)));
  287. radeon_ring_write(ring, PACKET0(R300_GB_MSPOS1, 0));
  288. radeon_ring_write(ring,
  289. ((6 << R300_MS_X3_SHIFT) |
  290. (6 << R300_MS_Y3_SHIFT) |
  291. (6 << R300_MS_X4_SHIFT) |
  292. (6 << R300_MS_Y4_SHIFT) |
  293. (6 << R300_MS_X5_SHIFT) |
  294. (6 << R300_MS_Y5_SHIFT) |
  295. (6 << R300_MSBD1_SHIFT)));
  296. radeon_ring_write(ring, PACKET0(R300_GA_ENHANCE, 0));
  297. radeon_ring_write(ring, R300_GA_DEADLOCK_CNTL | R300_GA_FASTSYNC_CNTL);
  298. radeon_ring_write(ring, PACKET0(R300_GA_POLY_MODE, 0));
  299. radeon_ring_write(ring,
  300. R300_FRONT_PTYPE_TRIANGE | R300_BACK_PTYPE_TRIANGE);
  301. radeon_ring_write(ring, PACKET0(R300_GA_ROUND_MODE, 0));
  302. radeon_ring_write(ring,
  303. R300_GEOMETRY_ROUND_NEAREST |
  304. R300_COLOR_ROUND_NEAREST);
  305. radeon_ring_unlock_commit(rdev, ring, false);
  306. }
  307. static void r300_errata(struct radeon_device *rdev)
  308. {
  309. rdev->pll_errata = 0;
  310. if (rdev->family == CHIP_R300 &&
  311. (RREG32(RADEON_CONFIG_CNTL) & RADEON_CFG_ATI_REV_ID_MASK) == RADEON_CFG_ATI_REV_A11) {
  312. rdev->pll_errata |= CHIP_ERRATA_R300_CG;
  313. }
  314. }
  315. int r300_mc_wait_for_idle(struct radeon_device *rdev)
  316. {
  317. unsigned i;
  318. uint32_t tmp;
  319. for (i = 0; i < rdev->usec_timeout; i++) {
  320. /* read MC_STATUS */
  321. tmp = RREG32(RADEON_MC_STATUS);
  322. if (tmp & R300_MC_IDLE) {
  323. return 0;
  324. }
  325. DRM_UDELAY(1);
  326. }
  327. return -1;
  328. }
  329. static void r300_gpu_init(struct radeon_device *rdev)
  330. {
  331. uint32_t gb_tile_config, tmp;
  332. if ((rdev->family == CHIP_R300 && rdev->pdev->device != 0x4144) ||
  333. (rdev->family == CHIP_R350 && rdev->pdev->device != 0x4148)) {
  334. /* r300,r350 */
  335. rdev->num_gb_pipes = 2;
  336. } else {
  337. /* rv350,rv370,rv380,r300 AD, r350 AH */
  338. rdev->num_gb_pipes = 1;
  339. }
  340. rdev->num_z_pipes = 1;
  341. gb_tile_config = (R300_ENABLE_TILING | R300_TILE_SIZE_16);
  342. switch (rdev->num_gb_pipes) {
  343. case 2:
  344. gb_tile_config |= R300_PIPE_COUNT_R300;
  345. break;
  346. case 3:
  347. gb_tile_config |= R300_PIPE_COUNT_R420_3P;
  348. break;
  349. case 4:
  350. gb_tile_config |= R300_PIPE_COUNT_R420;
  351. break;
  352. default:
  353. case 1:
  354. gb_tile_config |= R300_PIPE_COUNT_RV350;
  355. break;
  356. }
  357. WREG32(R300_GB_TILE_CONFIG, gb_tile_config);
  358. if (r100_gui_wait_for_idle(rdev)) {
  359. printk(KERN_WARNING "Failed to wait GUI idle while "
  360. "programming pipes. Bad things might happen.\n");
  361. }
  362. tmp = RREG32(R300_DST_PIPE_CONFIG);
  363. WREG32(R300_DST_PIPE_CONFIG, tmp | R300_PIPE_AUTO_CONFIG);
  364. WREG32(R300_RB2D_DSTCACHE_MODE,
  365. R300_DC_AUTOFLUSH_ENABLE |
  366. R300_DC_DC_DISABLE_IGNORE_PE);
  367. if (r100_gui_wait_for_idle(rdev)) {
  368. printk(KERN_WARNING "Failed to wait GUI idle while "
  369. "programming pipes. Bad things might happen.\n");
  370. }
  371. if (r300_mc_wait_for_idle(rdev)) {
  372. printk(KERN_WARNING "Failed to wait MC idle while "
  373. "programming pipes. Bad things might happen.\n");
  374. }
  375. DRM_INFO("radeon: %d quad pipes, %d Z pipes initialized.\n",
  376. rdev->num_gb_pipes, rdev->num_z_pipes);
  377. }
  378. int r300_asic_reset(struct radeon_device *rdev)
  379. {
  380. struct r100_mc_save save;
  381. u32 status, tmp;
  382. int ret = 0;
  383. status = RREG32(R_000E40_RBBM_STATUS);
  384. if (!G_000E40_GUI_ACTIVE(status)) {
  385. return 0;
  386. }
  387. r100_mc_stop(rdev, &save);
  388. status = RREG32(R_000E40_RBBM_STATUS);
  389. dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
  390. /* stop CP */
  391. WREG32(RADEON_CP_CSQ_CNTL, 0);
  392. tmp = RREG32(RADEON_CP_RB_CNTL);
  393. WREG32(RADEON_CP_RB_CNTL, tmp | RADEON_RB_RPTR_WR_ENA);
  394. WREG32(RADEON_CP_RB_RPTR_WR, 0);
  395. WREG32(RADEON_CP_RB_WPTR, 0);
  396. WREG32(RADEON_CP_RB_CNTL, tmp);
  397. /* save PCI state */
  398. pci_save_state(rdev->pdev);
  399. /* disable bus mastering */
  400. r100_bm_disable(rdev);
  401. WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_VAP(1) |
  402. S_0000F0_SOFT_RESET_GA(1));
  403. RREG32(R_0000F0_RBBM_SOFT_RESET);
  404. mdelay(500);
  405. WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
  406. mdelay(1);
  407. status = RREG32(R_000E40_RBBM_STATUS);
  408. dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
  409. /* resetting the CP seems to be problematic sometimes it end up
  410. * hard locking the computer, but it's necessary for successful
  411. * reset more test & playing is needed on R3XX/R4XX to find a
  412. * reliable (if any solution)
  413. */
  414. WREG32(R_0000F0_RBBM_SOFT_RESET, S_0000F0_SOFT_RESET_CP(1));
  415. RREG32(R_0000F0_RBBM_SOFT_RESET);
  416. mdelay(500);
  417. WREG32(R_0000F0_RBBM_SOFT_RESET, 0);
  418. mdelay(1);
  419. status = RREG32(R_000E40_RBBM_STATUS);
  420. dev_info(rdev->dev, "(%s:%d) RBBM_STATUS=0x%08X\n", __func__, __LINE__, status);
  421. /* restore PCI & busmastering */
  422. pci_restore_state(rdev->pdev);
  423. r100_enable_bm(rdev);
  424. /* Check if GPU is idle */
  425. if (G_000E40_GA_BUSY(status) || G_000E40_VAP_BUSY(status)) {
  426. dev_err(rdev->dev, "failed to reset GPU\n");
  427. ret = -1;
  428. } else
  429. dev_info(rdev->dev, "GPU reset succeed\n");
  430. r100_mc_resume(rdev, &save);
  431. return ret;
  432. }
  433. /*
  434. * r300,r350,rv350,rv380 VRAM info
  435. */
  436. void r300_mc_init(struct radeon_device *rdev)
  437. {
  438. u64 base;
  439. u32 tmp;
  440. /* DDR for all card after R300 & IGP */
  441. rdev->mc.vram_is_ddr = true;
  442. tmp = RREG32(RADEON_MEM_CNTL);
  443. tmp &= R300_MEM_NUM_CHANNELS_MASK;
  444. switch (tmp) {
  445. case 0: rdev->mc.vram_width = 64; break;
  446. case 1: rdev->mc.vram_width = 128; break;
  447. case 2: rdev->mc.vram_width = 256; break;
  448. default: rdev->mc.vram_width = 128; break;
  449. }
  450. r100_vram_init_sizes(rdev);
  451. base = rdev->mc.aper_base;
  452. if (rdev->flags & RADEON_IS_IGP)
  453. base = (RREG32(RADEON_NB_TOM) & 0xffff) << 16;
  454. radeon_vram_location(rdev, &rdev->mc, base);
  455. rdev->mc.gtt_base_align = 0;
  456. if (!(rdev->flags & RADEON_IS_AGP))
  457. radeon_gtt_location(rdev, &rdev->mc);
  458. radeon_update_bandwidth_info(rdev);
  459. }
  460. void rv370_set_pcie_lanes(struct radeon_device *rdev, int lanes)
  461. {
  462. uint32_t link_width_cntl, mask;
  463. if (rdev->flags & RADEON_IS_IGP)
  464. return;
  465. if (!(rdev->flags & RADEON_IS_PCIE))
  466. return;
  467. /* FIXME wait for idle */
  468. switch (lanes) {
  469. case 0:
  470. mask = RADEON_PCIE_LC_LINK_WIDTH_X0;
  471. break;
  472. case 1:
  473. mask = RADEON_PCIE_LC_LINK_WIDTH_X1;
  474. break;
  475. case 2:
  476. mask = RADEON_PCIE_LC_LINK_WIDTH_X2;
  477. break;
  478. case 4:
  479. mask = RADEON_PCIE_LC_LINK_WIDTH_X4;
  480. break;
  481. case 8:
  482. mask = RADEON_PCIE_LC_LINK_WIDTH_X8;
  483. break;
  484. case 12:
  485. mask = RADEON_PCIE_LC_LINK_WIDTH_X12;
  486. break;
  487. case 16:
  488. default:
  489. mask = RADEON_PCIE_LC_LINK_WIDTH_X16;
  490. break;
  491. }
  492. link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
  493. if ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) ==
  494. (mask << RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT))
  495. return;
  496. link_width_cntl &= ~(RADEON_PCIE_LC_LINK_WIDTH_MASK |
  497. RADEON_PCIE_LC_RECONFIG_NOW |
  498. RADEON_PCIE_LC_RECONFIG_LATER |
  499. RADEON_PCIE_LC_SHORT_RECONFIG_EN);
  500. link_width_cntl |= mask;
  501. WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL, link_width_cntl);
  502. WREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL, (link_width_cntl |
  503. RADEON_PCIE_LC_RECONFIG_NOW));
  504. /* wait for lane set to complete */
  505. link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
  506. while (link_width_cntl == 0xffffffff)
  507. link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
  508. }
  509. int rv370_get_pcie_lanes(struct radeon_device *rdev)
  510. {
  511. u32 link_width_cntl;
  512. if (rdev->flags & RADEON_IS_IGP)
  513. return 0;
  514. if (!(rdev->flags & RADEON_IS_PCIE))
  515. return 0;
  516. /* FIXME wait for idle */
  517. link_width_cntl = RREG32_PCIE(RADEON_PCIE_LC_LINK_WIDTH_CNTL);
  518. switch ((link_width_cntl & RADEON_PCIE_LC_LINK_WIDTH_RD_MASK) >> RADEON_PCIE_LC_LINK_WIDTH_RD_SHIFT) {
  519. case RADEON_PCIE_LC_LINK_WIDTH_X0:
  520. return 0;
  521. case RADEON_PCIE_LC_LINK_WIDTH_X1:
  522. return 1;
  523. case RADEON_PCIE_LC_LINK_WIDTH_X2:
  524. return 2;
  525. case RADEON_PCIE_LC_LINK_WIDTH_X4:
  526. return 4;
  527. case RADEON_PCIE_LC_LINK_WIDTH_X8:
  528. return 8;
  529. case RADEON_PCIE_LC_LINK_WIDTH_X16:
  530. default:
  531. return 16;
  532. }
  533. }
  534. #if defined(CONFIG_DEBUG_FS)
  535. static int rv370_debugfs_pcie_gart_info(struct seq_file *m, void *data)
  536. {
  537. struct drm_info_node *node = (struct drm_info_node *) m->private;
  538. struct drm_device *dev = node->minor->dev;
  539. struct radeon_device *rdev = dev->dev_private;
  540. uint32_t tmp;
  541. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_CNTL);
  542. seq_printf(m, "PCIE_TX_GART_CNTL 0x%08x\n", tmp);
  543. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_BASE);
  544. seq_printf(m, "PCIE_TX_GART_BASE 0x%08x\n", tmp);
  545. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_START_LO);
  546. seq_printf(m, "PCIE_TX_GART_START_LO 0x%08x\n", tmp);
  547. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_START_HI);
  548. seq_printf(m, "PCIE_TX_GART_START_HI 0x%08x\n", tmp);
  549. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_END_LO);
  550. seq_printf(m, "PCIE_TX_GART_END_LO 0x%08x\n", tmp);
  551. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_END_HI);
  552. seq_printf(m, "PCIE_TX_GART_END_HI 0x%08x\n", tmp);
  553. tmp = RREG32_PCIE(RADEON_PCIE_TX_GART_ERROR);
  554. seq_printf(m, "PCIE_TX_GART_ERROR 0x%08x\n", tmp);
  555. return 0;
  556. }
  557. static struct drm_info_list rv370_pcie_gart_info_list[] = {
  558. {"rv370_pcie_gart_info", rv370_debugfs_pcie_gart_info, 0, NULL},
  559. };
  560. #endif
  561. static int rv370_debugfs_pcie_gart_info_init(struct radeon_device *rdev)
  562. {
  563. #if defined(CONFIG_DEBUG_FS)
  564. return radeon_debugfs_add_files(rdev, rv370_pcie_gart_info_list, 1);
  565. #else
  566. return 0;
  567. #endif
  568. }
  569. static int r300_packet0_check(struct radeon_cs_parser *p,
  570. struct radeon_cs_packet *pkt,
  571. unsigned idx, unsigned reg)
  572. {
  573. struct radeon_bo_list *reloc;
  574. struct r100_cs_track *track;
  575. volatile uint32_t *ib;
  576. uint32_t tmp, tile_flags = 0;
  577. unsigned i;
  578. int r;
  579. u32 idx_value;
  580. ib = p->ib.ptr;
  581. track = (struct r100_cs_track *)p->track;
  582. idx_value = radeon_get_ib_value(p, idx);
  583. switch(reg) {
  584. case AVIVO_D1MODE_VLINE_START_END:
  585. case RADEON_CRTC_GUI_TRIG_VLINE:
  586. r = r100_cs_packet_parse_vline(p);
  587. if (r) {
  588. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  589. idx, reg);
  590. radeon_cs_dump_packet(p, pkt);
  591. return r;
  592. }
  593. break;
  594. case RADEON_DST_PITCH_OFFSET:
  595. case RADEON_SRC_PITCH_OFFSET:
  596. r = r100_reloc_pitch_offset(p, pkt, idx, reg);
  597. if (r)
  598. return r;
  599. break;
  600. case R300_RB3D_COLOROFFSET0:
  601. case R300_RB3D_COLOROFFSET1:
  602. case R300_RB3D_COLOROFFSET2:
  603. case R300_RB3D_COLOROFFSET3:
  604. i = (reg - R300_RB3D_COLOROFFSET0) >> 2;
  605. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  606. if (r) {
  607. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  608. idx, reg);
  609. radeon_cs_dump_packet(p, pkt);
  610. return r;
  611. }
  612. track->cb[i].robj = reloc->robj;
  613. track->cb[i].offset = idx_value;
  614. track->cb_dirty = true;
  615. ib[idx] = idx_value + ((u32)reloc->gpu_offset);
  616. break;
  617. case R300_ZB_DEPTHOFFSET:
  618. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  619. if (r) {
  620. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  621. idx, reg);
  622. radeon_cs_dump_packet(p, pkt);
  623. return r;
  624. }
  625. track->zb.robj = reloc->robj;
  626. track->zb.offset = idx_value;
  627. track->zb_dirty = true;
  628. ib[idx] = idx_value + ((u32)reloc->gpu_offset);
  629. break;
  630. case R300_TX_OFFSET_0:
  631. case R300_TX_OFFSET_0+4:
  632. case R300_TX_OFFSET_0+8:
  633. case R300_TX_OFFSET_0+12:
  634. case R300_TX_OFFSET_0+16:
  635. case R300_TX_OFFSET_0+20:
  636. case R300_TX_OFFSET_0+24:
  637. case R300_TX_OFFSET_0+28:
  638. case R300_TX_OFFSET_0+32:
  639. case R300_TX_OFFSET_0+36:
  640. case R300_TX_OFFSET_0+40:
  641. case R300_TX_OFFSET_0+44:
  642. case R300_TX_OFFSET_0+48:
  643. case R300_TX_OFFSET_0+52:
  644. case R300_TX_OFFSET_0+56:
  645. case R300_TX_OFFSET_0+60:
  646. i = (reg - R300_TX_OFFSET_0) >> 2;
  647. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  648. if (r) {
  649. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  650. idx, reg);
  651. radeon_cs_dump_packet(p, pkt);
  652. return r;
  653. }
  654. if (p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS) {
  655. ib[idx] = (idx_value & 31) | /* keep the 1st 5 bits */
  656. ((idx_value & ~31) + (u32)reloc->gpu_offset);
  657. } else {
  658. if (reloc->tiling_flags & RADEON_TILING_MACRO)
  659. tile_flags |= R300_TXO_MACRO_TILE;
  660. if (reloc->tiling_flags & RADEON_TILING_MICRO)
  661. tile_flags |= R300_TXO_MICRO_TILE;
  662. else if (reloc->tiling_flags & RADEON_TILING_MICRO_SQUARE)
  663. tile_flags |= R300_TXO_MICRO_TILE_SQUARE;
  664. tmp = idx_value + ((u32)reloc->gpu_offset);
  665. tmp |= tile_flags;
  666. ib[idx] = tmp;
  667. }
  668. track->textures[i].robj = reloc->robj;
  669. track->tex_dirty = true;
  670. break;
  671. /* Tracked registers */
  672. case 0x2084:
  673. /* VAP_VF_CNTL */
  674. track->vap_vf_cntl = idx_value;
  675. break;
  676. case 0x20B4:
  677. /* VAP_VTX_SIZE */
  678. track->vtx_size = idx_value & 0x7F;
  679. break;
  680. case 0x2134:
  681. /* VAP_VF_MAX_VTX_INDX */
  682. track->max_indx = idx_value & 0x00FFFFFFUL;
  683. break;
  684. case 0x2088:
  685. /* VAP_ALT_NUM_VERTICES - only valid on r500 */
  686. if (p->rdev->family < CHIP_RV515)
  687. goto fail;
  688. track->vap_alt_nverts = idx_value & 0xFFFFFF;
  689. break;
  690. case 0x43E4:
  691. /* SC_SCISSOR1 */
  692. track->maxy = ((idx_value >> 13) & 0x1FFF) + 1;
  693. if (p->rdev->family < CHIP_RV515) {
  694. track->maxy -= 1440;
  695. }
  696. track->cb_dirty = true;
  697. track->zb_dirty = true;
  698. break;
  699. case 0x4E00:
  700. /* RB3D_CCTL */
  701. if ((idx_value & (1 << 10)) && /* CMASK_ENABLE */
  702. p->rdev->cmask_filp != p->filp) {
  703. DRM_ERROR("Invalid RB3D_CCTL: Cannot enable CMASK.\n");
  704. return -EINVAL;
  705. }
  706. track->num_cb = ((idx_value >> 5) & 0x3) + 1;
  707. track->cb_dirty = true;
  708. break;
  709. case 0x4E38:
  710. case 0x4E3C:
  711. case 0x4E40:
  712. case 0x4E44:
  713. /* RB3D_COLORPITCH0 */
  714. /* RB3D_COLORPITCH1 */
  715. /* RB3D_COLORPITCH2 */
  716. /* RB3D_COLORPITCH3 */
  717. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  718. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  719. if (r) {
  720. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  721. idx, reg);
  722. radeon_cs_dump_packet(p, pkt);
  723. return r;
  724. }
  725. if (reloc->tiling_flags & RADEON_TILING_MACRO)
  726. tile_flags |= R300_COLOR_TILE_ENABLE;
  727. if (reloc->tiling_flags & RADEON_TILING_MICRO)
  728. tile_flags |= R300_COLOR_MICROTILE_ENABLE;
  729. else if (reloc->tiling_flags & RADEON_TILING_MICRO_SQUARE)
  730. tile_flags |= R300_COLOR_MICROTILE_SQUARE_ENABLE;
  731. tmp = idx_value & ~(0x7 << 16);
  732. tmp |= tile_flags;
  733. ib[idx] = tmp;
  734. }
  735. i = (reg - 0x4E38) >> 2;
  736. track->cb[i].pitch = idx_value & 0x3FFE;
  737. switch (((idx_value >> 21) & 0xF)) {
  738. case 9:
  739. case 11:
  740. case 12:
  741. track->cb[i].cpp = 1;
  742. break;
  743. case 3:
  744. case 4:
  745. case 13:
  746. case 15:
  747. track->cb[i].cpp = 2;
  748. break;
  749. case 5:
  750. if (p->rdev->family < CHIP_RV515) {
  751. DRM_ERROR("Invalid color buffer format (%d)!\n",
  752. ((idx_value >> 21) & 0xF));
  753. return -EINVAL;
  754. }
  755. /* Pass through. */
  756. case 6:
  757. track->cb[i].cpp = 4;
  758. break;
  759. case 10:
  760. track->cb[i].cpp = 8;
  761. break;
  762. case 7:
  763. track->cb[i].cpp = 16;
  764. break;
  765. default:
  766. DRM_ERROR("Invalid color buffer format (%d) !\n",
  767. ((idx_value >> 21) & 0xF));
  768. return -EINVAL;
  769. }
  770. track->cb_dirty = true;
  771. break;
  772. case 0x4F00:
  773. /* ZB_CNTL */
  774. if (idx_value & 2) {
  775. track->z_enabled = true;
  776. } else {
  777. track->z_enabled = false;
  778. }
  779. track->zb_dirty = true;
  780. break;
  781. case 0x4F10:
  782. /* ZB_FORMAT */
  783. switch ((idx_value & 0xF)) {
  784. case 0:
  785. case 1:
  786. track->zb.cpp = 2;
  787. break;
  788. case 2:
  789. track->zb.cpp = 4;
  790. break;
  791. default:
  792. DRM_ERROR("Invalid z buffer format (%d) !\n",
  793. (idx_value & 0xF));
  794. return -EINVAL;
  795. }
  796. track->zb_dirty = true;
  797. break;
  798. case 0x4F24:
  799. /* ZB_DEPTHPITCH */
  800. if (!(p->cs_flags & RADEON_CS_KEEP_TILING_FLAGS)) {
  801. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  802. if (r) {
  803. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  804. idx, reg);
  805. radeon_cs_dump_packet(p, pkt);
  806. return r;
  807. }
  808. if (reloc->tiling_flags & RADEON_TILING_MACRO)
  809. tile_flags |= R300_DEPTHMACROTILE_ENABLE;
  810. if (reloc->tiling_flags & RADEON_TILING_MICRO)
  811. tile_flags |= R300_DEPTHMICROTILE_TILED;
  812. else if (reloc->tiling_flags & RADEON_TILING_MICRO_SQUARE)
  813. tile_flags |= R300_DEPTHMICROTILE_TILED_SQUARE;
  814. tmp = idx_value & ~(0x7 << 16);
  815. tmp |= tile_flags;
  816. ib[idx] = tmp;
  817. }
  818. track->zb.pitch = idx_value & 0x3FFC;
  819. track->zb_dirty = true;
  820. break;
  821. case 0x4104:
  822. /* TX_ENABLE */
  823. for (i = 0; i < 16; i++) {
  824. bool enabled;
  825. enabled = !!(idx_value & (1 << i));
  826. track->textures[i].enabled = enabled;
  827. }
  828. track->tex_dirty = true;
  829. break;
  830. case 0x44C0:
  831. case 0x44C4:
  832. case 0x44C8:
  833. case 0x44CC:
  834. case 0x44D0:
  835. case 0x44D4:
  836. case 0x44D8:
  837. case 0x44DC:
  838. case 0x44E0:
  839. case 0x44E4:
  840. case 0x44E8:
  841. case 0x44EC:
  842. case 0x44F0:
  843. case 0x44F4:
  844. case 0x44F8:
  845. case 0x44FC:
  846. /* TX_FORMAT1_[0-15] */
  847. i = (reg - 0x44C0) >> 2;
  848. tmp = (idx_value >> 25) & 0x3;
  849. track->textures[i].tex_coord_type = tmp;
  850. switch ((idx_value & 0x1F)) {
  851. case R300_TX_FORMAT_X8:
  852. case R300_TX_FORMAT_Y4X4:
  853. case R300_TX_FORMAT_Z3Y3X2:
  854. track->textures[i].cpp = 1;
  855. track->textures[i].compress_format = R100_TRACK_COMP_NONE;
  856. break;
  857. case R300_TX_FORMAT_X16:
  858. case R300_TX_FORMAT_FL_I16:
  859. case R300_TX_FORMAT_Y8X8:
  860. case R300_TX_FORMAT_Z5Y6X5:
  861. case R300_TX_FORMAT_Z6Y5X5:
  862. case R300_TX_FORMAT_W4Z4Y4X4:
  863. case R300_TX_FORMAT_W1Z5Y5X5:
  864. case R300_TX_FORMAT_D3DMFT_CxV8U8:
  865. case R300_TX_FORMAT_B8G8_B8G8:
  866. case R300_TX_FORMAT_G8R8_G8B8:
  867. track->textures[i].cpp = 2;
  868. track->textures[i].compress_format = R100_TRACK_COMP_NONE;
  869. break;
  870. case R300_TX_FORMAT_Y16X16:
  871. case R300_TX_FORMAT_FL_I16A16:
  872. case R300_TX_FORMAT_Z11Y11X10:
  873. case R300_TX_FORMAT_Z10Y11X11:
  874. case R300_TX_FORMAT_W8Z8Y8X8:
  875. case R300_TX_FORMAT_W2Z10Y10X10:
  876. case 0x17:
  877. case R300_TX_FORMAT_FL_I32:
  878. case 0x1e:
  879. track->textures[i].cpp = 4;
  880. track->textures[i].compress_format = R100_TRACK_COMP_NONE;
  881. break;
  882. case R300_TX_FORMAT_W16Z16Y16X16:
  883. case R300_TX_FORMAT_FL_R16G16B16A16:
  884. case R300_TX_FORMAT_FL_I32A32:
  885. track->textures[i].cpp = 8;
  886. track->textures[i].compress_format = R100_TRACK_COMP_NONE;
  887. break;
  888. case R300_TX_FORMAT_FL_R32G32B32A32:
  889. track->textures[i].cpp = 16;
  890. track->textures[i].compress_format = R100_TRACK_COMP_NONE;
  891. break;
  892. case R300_TX_FORMAT_DXT1:
  893. track->textures[i].cpp = 1;
  894. track->textures[i].compress_format = R100_TRACK_COMP_DXT1;
  895. break;
  896. case R300_TX_FORMAT_ATI2N:
  897. if (p->rdev->family < CHIP_R420) {
  898. DRM_ERROR("Invalid texture format %u\n",
  899. (idx_value & 0x1F));
  900. return -EINVAL;
  901. }
  902. /* The same rules apply as for DXT3/5. */
  903. /* Pass through. */
  904. case R300_TX_FORMAT_DXT3:
  905. case R300_TX_FORMAT_DXT5:
  906. track->textures[i].cpp = 1;
  907. track->textures[i].compress_format = R100_TRACK_COMP_DXT35;
  908. break;
  909. default:
  910. DRM_ERROR("Invalid texture format %u\n",
  911. (idx_value & 0x1F));
  912. return -EINVAL;
  913. }
  914. track->tex_dirty = true;
  915. break;
  916. case 0x4400:
  917. case 0x4404:
  918. case 0x4408:
  919. case 0x440C:
  920. case 0x4410:
  921. case 0x4414:
  922. case 0x4418:
  923. case 0x441C:
  924. case 0x4420:
  925. case 0x4424:
  926. case 0x4428:
  927. case 0x442C:
  928. case 0x4430:
  929. case 0x4434:
  930. case 0x4438:
  931. case 0x443C:
  932. /* TX_FILTER0_[0-15] */
  933. i = (reg - 0x4400) >> 2;
  934. tmp = idx_value & 0x7;
  935. if (tmp == 2 || tmp == 4 || tmp == 6) {
  936. track->textures[i].roundup_w = false;
  937. }
  938. tmp = (idx_value >> 3) & 0x7;
  939. if (tmp == 2 || tmp == 4 || tmp == 6) {
  940. track->textures[i].roundup_h = false;
  941. }
  942. track->tex_dirty = true;
  943. break;
  944. case 0x4500:
  945. case 0x4504:
  946. case 0x4508:
  947. case 0x450C:
  948. case 0x4510:
  949. case 0x4514:
  950. case 0x4518:
  951. case 0x451C:
  952. case 0x4520:
  953. case 0x4524:
  954. case 0x4528:
  955. case 0x452C:
  956. case 0x4530:
  957. case 0x4534:
  958. case 0x4538:
  959. case 0x453C:
  960. /* TX_FORMAT2_[0-15] */
  961. i = (reg - 0x4500) >> 2;
  962. tmp = idx_value & 0x3FFF;
  963. track->textures[i].pitch = tmp + 1;
  964. if (p->rdev->family >= CHIP_RV515) {
  965. tmp = ((idx_value >> 15) & 1) << 11;
  966. track->textures[i].width_11 = tmp;
  967. tmp = ((idx_value >> 16) & 1) << 11;
  968. track->textures[i].height_11 = tmp;
  969. /* ATI1N */
  970. if (idx_value & (1 << 14)) {
  971. /* The same rules apply as for DXT1. */
  972. track->textures[i].compress_format =
  973. R100_TRACK_COMP_DXT1;
  974. }
  975. } else if (idx_value & (1 << 14)) {
  976. DRM_ERROR("Forbidden bit TXFORMAT_MSB\n");
  977. return -EINVAL;
  978. }
  979. track->tex_dirty = true;
  980. break;
  981. case 0x4480:
  982. case 0x4484:
  983. case 0x4488:
  984. case 0x448C:
  985. case 0x4490:
  986. case 0x4494:
  987. case 0x4498:
  988. case 0x449C:
  989. case 0x44A0:
  990. case 0x44A4:
  991. case 0x44A8:
  992. case 0x44AC:
  993. case 0x44B0:
  994. case 0x44B4:
  995. case 0x44B8:
  996. case 0x44BC:
  997. /* TX_FORMAT0_[0-15] */
  998. i = (reg - 0x4480) >> 2;
  999. tmp = idx_value & 0x7FF;
  1000. track->textures[i].width = tmp + 1;
  1001. tmp = (idx_value >> 11) & 0x7FF;
  1002. track->textures[i].height = tmp + 1;
  1003. tmp = (idx_value >> 26) & 0xF;
  1004. track->textures[i].num_levels = tmp;
  1005. tmp = idx_value & (1 << 31);
  1006. track->textures[i].use_pitch = !!tmp;
  1007. tmp = (idx_value >> 22) & 0xF;
  1008. track->textures[i].txdepth = tmp;
  1009. track->tex_dirty = true;
  1010. break;
  1011. case R300_ZB_ZPASS_ADDR:
  1012. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1013. if (r) {
  1014. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1015. idx, reg);
  1016. radeon_cs_dump_packet(p, pkt);
  1017. return r;
  1018. }
  1019. ib[idx] = idx_value + ((u32)reloc->gpu_offset);
  1020. break;
  1021. case 0x4e0c:
  1022. /* RB3D_COLOR_CHANNEL_MASK */
  1023. track->color_channel_mask = idx_value;
  1024. track->cb_dirty = true;
  1025. break;
  1026. case 0x43a4:
  1027. /* SC_HYPERZ_EN */
  1028. /* r300c emits this register - we need to disable hyperz for it
  1029. * without complaining */
  1030. if (p->rdev->hyperz_filp != p->filp) {
  1031. if (idx_value & 0x1)
  1032. ib[idx] = idx_value & ~1;
  1033. }
  1034. break;
  1035. case 0x4f1c:
  1036. /* ZB_BW_CNTL */
  1037. track->zb_cb_clear = !!(idx_value & (1 << 5));
  1038. track->cb_dirty = true;
  1039. track->zb_dirty = true;
  1040. if (p->rdev->hyperz_filp != p->filp) {
  1041. if (idx_value & (R300_HIZ_ENABLE |
  1042. R300_RD_COMP_ENABLE |
  1043. R300_WR_COMP_ENABLE |
  1044. R300_FAST_FILL_ENABLE))
  1045. goto fail;
  1046. }
  1047. break;
  1048. case 0x4e04:
  1049. /* RB3D_BLENDCNTL */
  1050. track->blend_read_enable = !!(idx_value & (1 << 2));
  1051. track->cb_dirty = true;
  1052. break;
  1053. case R300_RB3D_AARESOLVE_OFFSET:
  1054. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1055. if (r) {
  1056. DRM_ERROR("No reloc for ib[%d]=0x%04X\n",
  1057. idx, reg);
  1058. radeon_cs_dump_packet(p, pkt);
  1059. return r;
  1060. }
  1061. track->aa.robj = reloc->robj;
  1062. track->aa.offset = idx_value;
  1063. track->aa_dirty = true;
  1064. ib[idx] = idx_value + ((u32)reloc->gpu_offset);
  1065. break;
  1066. case R300_RB3D_AARESOLVE_PITCH:
  1067. track->aa.pitch = idx_value & 0x3FFE;
  1068. track->aa_dirty = true;
  1069. break;
  1070. case R300_RB3D_AARESOLVE_CTL:
  1071. track->aaresolve = idx_value & 0x1;
  1072. track->aa_dirty = true;
  1073. break;
  1074. case 0x4f30: /* ZB_MASK_OFFSET */
  1075. case 0x4f34: /* ZB_ZMASK_PITCH */
  1076. case 0x4f44: /* ZB_HIZ_OFFSET */
  1077. case 0x4f54: /* ZB_HIZ_PITCH */
  1078. if (idx_value && (p->rdev->hyperz_filp != p->filp))
  1079. goto fail;
  1080. break;
  1081. case 0x4028:
  1082. if (idx_value && (p->rdev->hyperz_filp != p->filp))
  1083. goto fail;
  1084. /* GB_Z_PEQ_CONFIG */
  1085. if (p->rdev->family >= CHIP_RV350)
  1086. break;
  1087. goto fail;
  1088. break;
  1089. case 0x4be8:
  1090. /* valid register only on RV530 */
  1091. if (p->rdev->family == CHIP_RV530)
  1092. break;
  1093. /* fallthrough do not move */
  1094. default:
  1095. goto fail;
  1096. }
  1097. return 0;
  1098. fail:
  1099. printk(KERN_ERR "Forbidden register 0x%04X in cs at %d (val=%08x)\n",
  1100. reg, idx, idx_value);
  1101. return -EINVAL;
  1102. }
  1103. static int r300_packet3_check(struct radeon_cs_parser *p,
  1104. struct radeon_cs_packet *pkt)
  1105. {
  1106. struct radeon_bo_list *reloc;
  1107. struct r100_cs_track *track;
  1108. volatile uint32_t *ib;
  1109. unsigned idx;
  1110. int r;
  1111. ib = p->ib.ptr;
  1112. idx = pkt->idx + 1;
  1113. track = (struct r100_cs_track *)p->track;
  1114. switch(pkt->opcode) {
  1115. case PACKET3_3D_LOAD_VBPNTR:
  1116. r = r100_packet3_load_vbpntr(p, pkt, idx);
  1117. if (r)
  1118. return r;
  1119. break;
  1120. case PACKET3_INDX_BUFFER:
  1121. r = radeon_cs_packet_next_reloc(p, &reloc, 0);
  1122. if (r) {
  1123. DRM_ERROR("No reloc for packet3 %d\n", pkt->opcode);
  1124. radeon_cs_dump_packet(p, pkt);
  1125. return r;
  1126. }
  1127. ib[idx+1] = radeon_get_ib_value(p, idx + 1) + ((u32)reloc->gpu_offset);
  1128. r = r100_cs_track_check_pkt3_indx_buffer(p, pkt, reloc->robj);
  1129. if (r) {
  1130. return r;
  1131. }
  1132. break;
  1133. /* Draw packet */
  1134. case PACKET3_3D_DRAW_IMMD:
  1135. /* Number of dwords is vtx_size * (num_vertices - 1)
  1136. * PRIM_WALK must be equal to 3 vertex data in embedded
  1137. * in cmd stream */
  1138. if (((radeon_get_ib_value(p, idx + 1) >> 4) & 0x3) != 3) {
  1139. DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
  1140. return -EINVAL;
  1141. }
  1142. track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
  1143. track->immd_dwords = pkt->count - 1;
  1144. r = r100_cs_track_check(p->rdev, track);
  1145. if (r) {
  1146. return r;
  1147. }
  1148. break;
  1149. case PACKET3_3D_DRAW_IMMD_2:
  1150. /* Number of dwords is vtx_size * (num_vertices - 1)
  1151. * PRIM_WALK must be equal to 3 vertex data in embedded
  1152. * in cmd stream */
  1153. if (((radeon_get_ib_value(p, idx) >> 4) & 0x3) != 3) {
  1154. DRM_ERROR("PRIM_WALK must be 3 for IMMD draw\n");
  1155. return -EINVAL;
  1156. }
  1157. track->vap_vf_cntl = radeon_get_ib_value(p, idx);
  1158. track->immd_dwords = pkt->count;
  1159. r = r100_cs_track_check(p->rdev, track);
  1160. if (r) {
  1161. return r;
  1162. }
  1163. break;
  1164. case PACKET3_3D_DRAW_VBUF:
  1165. track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
  1166. r = r100_cs_track_check(p->rdev, track);
  1167. if (r) {
  1168. return r;
  1169. }
  1170. break;
  1171. case PACKET3_3D_DRAW_VBUF_2:
  1172. track->vap_vf_cntl = radeon_get_ib_value(p, idx);
  1173. r = r100_cs_track_check(p->rdev, track);
  1174. if (r) {
  1175. return r;
  1176. }
  1177. break;
  1178. case PACKET3_3D_DRAW_INDX:
  1179. track->vap_vf_cntl = radeon_get_ib_value(p, idx + 1);
  1180. r = r100_cs_track_check(p->rdev, track);
  1181. if (r) {
  1182. return r;
  1183. }
  1184. break;
  1185. case PACKET3_3D_DRAW_INDX_2:
  1186. track->vap_vf_cntl = radeon_get_ib_value(p, idx);
  1187. r = r100_cs_track_check(p->rdev, track);
  1188. if (r) {
  1189. return r;
  1190. }
  1191. break;
  1192. case PACKET3_3D_CLEAR_HIZ:
  1193. case PACKET3_3D_CLEAR_ZMASK:
  1194. if (p->rdev->hyperz_filp != p->filp)
  1195. return -EINVAL;
  1196. break;
  1197. case PACKET3_3D_CLEAR_CMASK:
  1198. if (p->rdev->cmask_filp != p->filp)
  1199. return -EINVAL;
  1200. break;
  1201. case PACKET3_NOP:
  1202. break;
  1203. default:
  1204. DRM_ERROR("Packet3 opcode %x not supported\n", pkt->opcode);
  1205. return -EINVAL;
  1206. }
  1207. return 0;
  1208. }
  1209. int r300_cs_parse(struct radeon_cs_parser *p)
  1210. {
  1211. struct radeon_cs_packet pkt;
  1212. struct r100_cs_track *track;
  1213. int r;
  1214. track = kzalloc(sizeof(*track), GFP_KERNEL);
  1215. if (track == NULL)
  1216. return -ENOMEM;
  1217. r100_cs_track_clear(p->rdev, track);
  1218. p->track = track;
  1219. do {
  1220. r = radeon_cs_packet_parse(p, &pkt, p->idx);
  1221. if (r) {
  1222. return r;
  1223. }
  1224. p->idx += pkt.count + 2;
  1225. switch (pkt.type) {
  1226. case RADEON_PACKET_TYPE0:
  1227. r = r100_cs_parse_packet0(p, &pkt,
  1228. p->rdev->config.r300.reg_safe_bm,
  1229. p->rdev->config.r300.reg_safe_bm_size,
  1230. &r300_packet0_check);
  1231. break;
  1232. case RADEON_PACKET_TYPE2:
  1233. break;
  1234. case RADEON_PACKET_TYPE3:
  1235. r = r300_packet3_check(p, &pkt);
  1236. break;
  1237. default:
  1238. DRM_ERROR("Unknown packet type %d !\n", pkt.type);
  1239. return -EINVAL;
  1240. }
  1241. if (r) {
  1242. return r;
  1243. }
  1244. } while (p->idx < p->chunk_ib->length_dw);
  1245. return 0;
  1246. }
  1247. void r300_set_reg_safe(struct radeon_device *rdev)
  1248. {
  1249. rdev->config.r300.reg_safe_bm = r300_reg_safe_bm;
  1250. rdev->config.r300.reg_safe_bm_size = ARRAY_SIZE(r300_reg_safe_bm);
  1251. }
  1252. void r300_mc_program(struct radeon_device *rdev)
  1253. {
  1254. struct r100_mc_save save;
  1255. int r;
  1256. r = r100_debugfs_mc_info_init(rdev);
  1257. if (r) {
  1258. dev_err(rdev->dev, "Failed to create r100_mc debugfs file.\n");
  1259. }
  1260. /* Stops all mc clients */
  1261. r100_mc_stop(rdev, &save);
  1262. if (rdev->flags & RADEON_IS_AGP) {
  1263. WREG32(R_00014C_MC_AGP_LOCATION,
  1264. S_00014C_MC_AGP_START(rdev->mc.gtt_start >> 16) |
  1265. S_00014C_MC_AGP_TOP(rdev->mc.gtt_end >> 16));
  1266. WREG32(R_000170_AGP_BASE, lower_32_bits(rdev->mc.agp_base));
  1267. WREG32(R_00015C_AGP_BASE_2,
  1268. upper_32_bits(rdev->mc.agp_base) & 0xff);
  1269. } else {
  1270. WREG32(R_00014C_MC_AGP_LOCATION, 0x0FFFFFFF);
  1271. WREG32(R_000170_AGP_BASE, 0);
  1272. WREG32(R_00015C_AGP_BASE_2, 0);
  1273. }
  1274. /* Wait for mc idle */
  1275. if (r300_mc_wait_for_idle(rdev))
  1276. DRM_INFO("Failed to wait MC idle before programming MC.\n");
  1277. /* Program MC, should be a 32bits limited address space */
  1278. WREG32(R_000148_MC_FB_LOCATION,
  1279. S_000148_MC_FB_START(rdev->mc.vram_start >> 16) |
  1280. S_000148_MC_FB_TOP(rdev->mc.vram_end >> 16));
  1281. r100_mc_resume(rdev, &save);
  1282. }
  1283. void r300_clock_startup(struct radeon_device *rdev)
  1284. {
  1285. u32 tmp;
  1286. if (radeon_dynclks != -1 && radeon_dynclks)
  1287. radeon_legacy_set_clock_gating(rdev, 1);
  1288. /* We need to force on some of the block */
  1289. tmp = RREG32_PLL(R_00000D_SCLK_CNTL);
  1290. tmp |= S_00000D_FORCE_CP(1) | S_00000D_FORCE_VIP(1);
  1291. if ((rdev->family == CHIP_RV350) || (rdev->family == CHIP_RV380))
  1292. tmp |= S_00000D_FORCE_VAP(1);
  1293. WREG32_PLL(R_00000D_SCLK_CNTL, tmp);
  1294. }
  1295. static int r300_startup(struct radeon_device *rdev)
  1296. {
  1297. int r;
  1298. /* set common regs */
  1299. r100_set_common_regs(rdev);
  1300. /* program mc */
  1301. r300_mc_program(rdev);
  1302. /* Resume clock */
  1303. r300_clock_startup(rdev);
  1304. /* Initialize GPU configuration (# pipes, ...) */
  1305. r300_gpu_init(rdev);
  1306. /* Initialize GART (initialize after TTM so we can allocate
  1307. * memory through TTM but finalize after TTM) */
  1308. if (rdev->flags & RADEON_IS_PCIE) {
  1309. r = rv370_pcie_gart_enable(rdev);
  1310. if (r)
  1311. return r;
  1312. }
  1313. if (rdev->family == CHIP_R300 ||
  1314. rdev->family == CHIP_R350 ||
  1315. rdev->family == CHIP_RV350)
  1316. r100_enable_bm(rdev);
  1317. if (rdev->flags & RADEON_IS_PCI) {
  1318. r = r100_pci_gart_enable(rdev);
  1319. if (r)
  1320. return r;
  1321. }
  1322. /* allocate wb buffer */
  1323. r = radeon_wb_init(rdev);
  1324. if (r)
  1325. return r;
  1326. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  1327. if (r) {
  1328. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  1329. return r;
  1330. }
  1331. /* Enable IRQ */
  1332. if (!rdev->irq.installed) {
  1333. r = radeon_irq_kms_init(rdev);
  1334. if (r)
  1335. return r;
  1336. }
  1337. r100_irq_set(rdev);
  1338. rdev->config.r300.hdp_cntl = RREG32(RADEON_HOST_PATH_CNTL);
  1339. /* 1M ring buffer */
  1340. r = r100_cp_init(rdev, 1024 * 1024);
  1341. if (r) {
  1342. dev_err(rdev->dev, "failed initializing CP (%d).\n", r);
  1343. return r;
  1344. }
  1345. r = radeon_ib_pool_init(rdev);
  1346. if (r) {
  1347. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  1348. return r;
  1349. }
  1350. return 0;
  1351. }
  1352. int r300_resume(struct radeon_device *rdev)
  1353. {
  1354. int r;
  1355. /* Make sur GART are not working */
  1356. if (rdev->flags & RADEON_IS_PCIE)
  1357. rv370_pcie_gart_disable(rdev);
  1358. if (rdev->flags & RADEON_IS_PCI)
  1359. r100_pci_gart_disable(rdev);
  1360. /* Resume clock before doing reset */
  1361. r300_clock_startup(rdev);
  1362. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  1363. if (radeon_asic_reset(rdev)) {
  1364. dev_warn(rdev->dev, "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  1365. RREG32(R_000E40_RBBM_STATUS),
  1366. RREG32(R_0007C0_CP_STAT));
  1367. }
  1368. /* post */
  1369. radeon_combios_asic_init(rdev->ddev);
  1370. /* Resume clock after posting */
  1371. r300_clock_startup(rdev);
  1372. /* Initialize surface registers */
  1373. radeon_surface_init(rdev);
  1374. rdev->accel_working = true;
  1375. r = r300_startup(rdev);
  1376. if (r) {
  1377. rdev->accel_working = false;
  1378. }
  1379. return r;
  1380. }
  1381. int r300_suspend(struct radeon_device *rdev)
  1382. {
  1383. radeon_pm_suspend(rdev);
  1384. r100_cp_disable(rdev);
  1385. radeon_wb_disable(rdev);
  1386. r100_irq_disable(rdev);
  1387. if (rdev->flags & RADEON_IS_PCIE)
  1388. rv370_pcie_gart_disable(rdev);
  1389. if (rdev->flags & RADEON_IS_PCI)
  1390. r100_pci_gart_disable(rdev);
  1391. return 0;
  1392. }
  1393. void r300_fini(struct radeon_device *rdev)
  1394. {
  1395. radeon_pm_fini(rdev);
  1396. r100_cp_fini(rdev);
  1397. radeon_wb_fini(rdev);
  1398. radeon_ib_pool_fini(rdev);
  1399. radeon_gem_fini(rdev);
  1400. if (rdev->flags & RADEON_IS_PCIE)
  1401. rv370_pcie_gart_fini(rdev);
  1402. if (rdev->flags & RADEON_IS_PCI)
  1403. r100_pci_gart_fini(rdev);
  1404. radeon_agp_fini(rdev);
  1405. radeon_irq_kms_fini(rdev);
  1406. radeon_fence_driver_fini(rdev);
  1407. radeon_bo_fini(rdev);
  1408. radeon_atombios_fini(rdev);
  1409. kfree(rdev->bios);
  1410. rdev->bios = NULL;
  1411. }
  1412. int r300_init(struct radeon_device *rdev)
  1413. {
  1414. int r;
  1415. /* Disable VGA */
  1416. r100_vga_render_disable(rdev);
  1417. /* Initialize scratch registers */
  1418. radeon_scratch_init(rdev);
  1419. /* Initialize surface registers */
  1420. radeon_surface_init(rdev);
  1421. /* TODO: disable VGA need to use VGA request */
  1422. /* restore some register to sane defaults */
  1423. r100_restore_sanity(rdev);
  1424. /* BIOS*/
  1425. if (!radeon_get_bios(rdev)) {
  1426. if (ASIC_IS_AVIVO(rdev))
  1427. return -EINVAL;
  1428. }
  1429. if (rdev->is_atom_bios) {
  1430. dev_err(rdev->dev, "Expecting combios for RS400/RS480 GPU\n");
  1431. return -EINVAL;
  1432. } else {
  1433. r = radeon_combios_init(rdev);
  1434. if (r)
  1435. return r;
  1436. }
  1437. /* Reset gpu before posting otherwise ATOM will enter infinite loop */
  1438. if (radeon_asic_reset(rdev)) {
  1439. dev_warn(rdev->dev,
  1440. "GPU reset failed ! (0xE40=0x%08X, 0x7C0=0x%08X)\n",
  1441. RREG32(R_000E40_RBBM_STATUS),
  1442. RREG32(R_0007C0_CP_STAT));
  1443. }
  1444. /* check if cards are posted or not */
  1445. if (radeon_boot_test_post_card(rdev) == false)
  1446. return -EINVAL;
  1447. /* Set asic errata */
  1448. r300_errata(rdev);
  1449. /* Initialize clocks */
  1450. radeon_get_clock_info(rdev->ddev);
  1451. /* initialize AGP */
  1452. if (rdev->flags & RADEON_IS_AGP) {
  1453. r = radeon_agp_init(rdev);
  1454. if (r) {
  1455. radeon_agp_disable(rdev);
  1456. }
  1457. }
  1458. /* initialize memory controller */
  1459. r300_mc_init(rdev);
  1460. /* Fence driver */
  1461. r = radeon_fence_driver_init(rdev);
  1462. if (r)
  1463. return r;
  1464. /* Memory manager */
  1465. r = radeon_bo_init(rdev);
  1466. if (r)
  1467. return r;
  1468. if (rdev->flags & RADEON_IS_PCIE) {
  1469. r = rv370_pcie_gart_init(rdev);
  1470. if (r)
  1471. return r;
  1472. }
  1473. if (rdev->flags & RADEON_IS_PCI) {
  1474. r = r100_pci_gart_init(rdev);
  1475. if (r)
  1476. return r;
  1477. }
  1478. r300_set_reg_safe(rdev);
  1479. /* Initialize power management */
  1480. radeon_pm_init(rdev);
  1481. rdev->accel_working = true;
  1482. r = r300_startup(rdev);
  1483. if (r) {
  1484. /* Something went wrong with the accel init, so stop accel */
  1485. dev_err(rdev->dev, "Disabling GPU acceleration\n");
  1486. r100_cp_fini(rdev);
  1487. radeon_wb_fini(rdev);
  1488. radeon_ib_pool_fini(rdev);
  1489. radeon_irq_kms_fini(rdev);
  1490. if (rdev->flags & RADEON_IS_PCIE)
  1491. rv370_pcie_gart_fini(rdev);
  1492. if (rdev->flags & RADEON_IS_PCI)
  1493. r100_pci_gart_fini(rdev);
  1494. radeon_agp_fini(rdev);
  1495. rdev->accel_working = false;
  1496. }
  1497. return 0;
  1498. }