amdgpu_device.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387
  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/console.h>
  29. #include <linux/slab.h>
  30. #include <linux/debugfs.h>
  31. #include <drm/drmP.h>
  32. #include <drm/drm_crtc_helper.h>
  33. #include <drm/amdgpu_drm.h>
  34. #include <linux/vgaarb.h>
  35. #include <linux/vga_switcheroo.h>
  36. #include <linux/efi.h>
  37. #include "amdgpu.h"
  38. #include "amdgpu_i2c.h"
  39. #include "atom.h"
  40. #include "amdgpu_atombios.h"
  41. #include "amd_pcie.h"
  42. #ifdef CONFIG_DRM_AMDGPU_CIK
  43. #include "cik.h"
  44. #endif
  45. #include "vi.h"
  46. #include "bif/bif_4_1_d.h"
  47. static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev);
  48. static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev);
  49. static const char *amdgpu_asic_name[] = {
  50. "BONAIRE",
  51. "KAVERI",
  52. "KABINI",
  53. "HAWAII",
  54. "MULLINS",
  55. "TOPAZ",
  56. "TONGA",
  57. "FIJI",
  58. "CARRIZO",
  59. "STONEY",
  60. "POLARIS10",
  61. "POLARIS11",
  62. "LAST",
  63. };
  64. bool amdgpu_device_is_px(struct drm_device *dev)
  65. {
  66. struct amdgpu_device *adev = dev->dev_private;
  67. if (adev->flags & AMD_IS_PX)
  68. return true;
  69. return false;
  70. }
  71. /*
  72. * MMIO register access helper functions.
  73. */
  74. uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
  75. bool always_indirect)
  76. {
  77. if ((reg * 4) < adev->rmmio_size && !always_indirect)
  78. return readl(((void __iomem *)adev->rmmio) + (reg * 4));
  79. else {
  80. unsigned long flags;
  81. uint32_t ret;
  82. spin_lock_irqsave(&adev->mmio_idx_lock, flags);
  83. writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
  84. ret = readl(((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
  85. spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
  86. return ret;
  87. }
  88. }
  89. void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
  90. bool always_indirect)
  91. {
  92. if ((reg * 4) < adev->rmmio_size && !always_indirect)
  93. writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
  94. else {
  95. unsigned long flags;
  96. spin_lock_irqsave(&adev->mmio_idx_lock, flags);
  97. writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
  98. writel(v, ((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
  99. spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
  100. }
  101. }
  102. u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg)
  103. {
  104. if ((reg * 4) < adev->rio_mem_size)
  105. return ioread32(adev->rio_mem + (reg * 4));
  106. else {
  107. iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
  108. return ioread32(adev->rio_mem + (mmMM_DATA * 4));
  109. }
  110. }
  111. void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  112. {
  113. if ((reg * 4) < adev->rio_mem_size)
  114. iowrite32(v, adev->rio_mem + (reg * 4));
  115. else {
  116. iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
  117. iowrite32(v, adev->rio_mem + (mmMM_DATA * 4));
  118. }
  119. }
  120. /**
  121. * amdgpu_mm_rdoorbell - read a doorbell dword
  122. *
  123. * @adev: amdgpu_device pointer
  124. * @index: doorbell index
  125. *
  126. * Returns the value in the doorbell aperture at the
  127. * requested doorbell index (CIK).
  128. */
  129. u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index)
  130. {
  131. if (index < adev->doorbell.num_doorbells) {
  132. return readl(adev->doorbell.ptr + index);
  133. } else {
  134. DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
  135. return 0;
  136. }
  137. }
  138. /**
  139. * amdgpu_mm_wdoorbell - write a doorbell dword
  140. *
  141. * @adev: amdgpu_device pointer
  142. * @index: doorbell index
  143. * @v: value to write
  144. *
  145. * Writes @v to the doorbell aperture at the
  146. * requested doorbell index (CIK).
  147. */
  148. void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v)
  149. {
  150. if (index < adev->doorbell.num_doorbells) {
  151. writel(v, adev->doorbell.ptr + index);
  152. } else {
  153. DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
  154. }
  155. }
  156. /**
  157. * amdgpu_invalid_rreg - dummy reg read function
  158. *
  159. * @adev: amdgpu device pointer
  160. * @reg: offset of register
  161. *
  162. * Dummy register read function. Used for register blocks
  163. * that certain asics don't have (all asics).
  164. * Returns the value in the register.
  165. */
  166. static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg)
  167. {
  168. DRM_ERROR("Invalid callback to read register 0x%04X\n", reg);
  169. BUG();
  170. return 0;
  171. }
  172. /**
  173. * amdgpu_invalid_wreg - dummy reg write function
  174. *
  175. * @adev: amdgpu device pointer
  176. * @reg: offset of register
  177. * @v: value to write to the register
  178. *
  179. * Dummy register read function. Used for register blocks
  180. * that certain asics don't have (all asics).
  181. */
  182. static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
  183. {
  184. DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n",
  185. reg, v);
  186. BUG();
  187. }
  188. /**
  189. * amdgpu_block_invalid_rreg - dummy reg read function
  190. *
  191. * @adev: amdgpu device pointer
  192. * @block: offset of instance
  193. * @reg: offset of register
  194. *
  195. * Dummy register read function. Used for register blocks
  196. * that certain asics don't have (all asics).
  197. * Returns the value in the register.
  198. */
  199. static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev,
  200. uint32_t block, uint32_t reg)
  201. {
  202. DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n",
  203. reg, block);
  204. BUG();
  205. return 0;
  206. }
  207. /**
  208. * amdgpu_block_invalid_wreg - dummy reg write function
  209. *
  210. * @adev: amdgpu device pointer
  211. * @block: offset of instance
  212. * @reg: offset of register
  213. * @v: value to write to the register
  214. *
  215. * Dummy register read function. Used for register blocks
  216. * that certain asics don't have (all asics).
  217. */
  218. static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev,
  219. uint32_t block,
  220. uint32_t reg, uint32_t v)
  221. {
  222. DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n",
  223. reg, block, v);
  224. BUG();
  225. }
  226. static int amdgpu_vram_scratch_init(struct amdgpu_device *adev)
  227. {
  228. int r;
  229. if (adev->vram_scratch.robj == NULL) {
  230. r = amdgpu_bo_create(adev, AMDGPU_GPU_PAGE_SIZE,
  231. PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM,
  232. AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED,
  233. NULL, NULL, &adev->vram_scratch.robj);
  234. if (r) {
  235. return r;
  236. }
  237. }
  238. r = amdgpu_bo_reserve(adev->vram_scratch.robj, false);
  239. if (unlikely(r != 0))
  240. return r;
  241. r = amdgpu_bo_pin(adev->vram_scratch.robj,
  242. AMDGPU_GEM_DOMAIN_VRAM, &adev->vram_scratch.gpu_addr);
  243. if (r) {
  244. amdgpu_bo_unreserve(adev->vram_scratch.robj);
  245. return r;
  246. }
  247. r = amdgpu_bo_kmap(adev->vram_scratch.robj,
  248. (void **)&adev->vram_scratch.ptr);
  249. if (r)
  250. amdgpu_bo_unpin(adev->vram_scratch.robj);
  251. amdgpu_bo_unreserve(adev->vram_scratch.robj);
  252. return r;
  253. }
  254. static void amdgpu_vram_scratch_fini(struct amdgpu_device *adev)
  255. {
  256. int r;
  257. if (adev->vram_scratch.robj == NULL) {
  258. return;
  259. }
  260. r = amdgpu_bo_reserve(adev->vram_scratch.robj, false);
  261. if (likely(r == 0)) {
  262. amdgpu_bo_kunmap(adev->vram_scratch.robj);
  263. amdgpu_bo_unpin(adev->vram_scratch.robj);
  264. amdgpu_bo_unreserve(adev->vram_scratch.robj);
  265. }
  266. amdgpu_bo_unref(&adev->vram_scratch.robj);
  267. }
  268. /**
  269. * amdgpu_program_register_sequence - program an array of registers.
  270. *
  271. * @adev: amdgpu_device pointer
  272. * @registers: pointer to the register array
  273. * @array_size: size of the register array
  274. *
  275. * Programs an array or registers with and and or masks.
  276. * This is a helper for setting golden registers.
  277. */
  278. void amdgpu_program_register_sequence(struct amdgpu_device *adev,
  279. const u32 *registers,
  280. const u32 array_size)
  281. {
  282. u32 tmp, reg, and_mask, or_mask;
  283. int i;
  284. if (array_size % 3)
  285. return;
  286. for (i = 0; i < array_size; i +=3) {
  287. reg = registers[i + 0];
  288. and_mask = registers[i + 1];
  289. or_mask = registers[i + 2];
  290. if (and_mask == 0xffffffff) {
  291. tmp = or_mask;
  292. } else {
  293. tmp = RREG32(reg);
  294. tmp &= ~and_mask;
  295. tmp |= or_mask;
  296. }
  297. WREG32(reg, tmp);
  298. }
  299. }
  300. void amdgpu_pci_config_reset(struct amdgpu_device *adev)
  301. {
  302. pci_write_config_dword(adev->pdev, 0x7c, AMDGPU_ASIC_RESET_DATA);
  303. }
  304. /*
  305. * GPU doorbell aperture helpers function.
  306. */
  307. /**
  308. * amdgpu_doorbell_init - Init doorbell driver information.
  309. *
  310. * @adev: amdgpu_device pointer
  311. *
  312. * Init doorbell driver information (CIK)
  313. * Returns 0 on success, error on failure.
  314. */
  315. static int amdgpu_doorbell_init(struct amdgpu_device *adev)
  316. {
  317. /* doorbell bar mapping */
  318. adev->doorbell.base = pci_resource_start(adev->pdev, 2);
  319. adev->doorbell.size = pci_resource_len(adev->pdev, 2);
  320. adev->doorbell.num_doorbells = min_t(u32, adev->doorbell.size / sizeof(u32),
  321. AMDGPU_DOORBELL_MAX_ASSIGNMENT+1);
  322. if (adev->doorbell.num_doorbells == 0)
  323. return -EINVAL;
  324. adev->doorbell.ptr = ioremap(adev->doorbell.base, adev->doorbell.num_doorbells * sizeof(u32));
  325. if (adev->doorbell.ptr == NULL) {
  326. return -ENOMEM;
  327. }
  328. DRM_INFO("doorbell mmio base: 0x%08X\n", (uint32_t)adev->doorbell.base);
  329. DRM_INFO("doorbell mmio size: %u\n", (unsigned)adev->doorbell.size);
  330. return 0;
  331. }
  332. /**
  333. * amdgpu_doorbell_fini - Tear down doorbell driver information.
  334. *
  335. * @adev: amdgpu_device pointer
  336. *
  337. * Tear down doorbell driver information (CIK)
  338. */
  339. static void amdgpu_doorbell_fini(struct amdgpu_device *adev)
  340. {
  341. iounmap(adev->doorbell.ptr);
  342. adev->doorbell.ptr = NULL;
  343. }
  344. /**
  345. * amdgpu_doorbell_get_kfd_info - Report doorbell configuration required to
  346. * setup amdkfd
  347. *
  348. * @adev: amdgpu_device pointer
  349. * @aperture_base: output returning doorbell aperture base physical address
  350. * @aperture_size: output returning doorbell aperture size in bytes
  351. * @start_offset: output returning # of doorbell bytes reserved for amdgpu.
  352. *
  353. * amdgpu and amdkfd share the doorbell aperture. amdgpu sets it up,
  354. * takes doorbells required for its own rings and reports the setup to amdkfd.
  355. * amdgpu reserved doorbells are at the start of the doorbell aperture.
  356. */
  357. void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
  358. phys_addr_t *aperture_base,
  359. size_t *aperture_size,
  360. size_t *start_offset)
  361. {
  362. /*
  363. * The first num_doorbells are used by amdgpu.
  364. * amdkfd takes whatever's left in the aperture.
  365. */
  366. if (adev->doorbell.size > adev->doorbell.num_doorbells * sizeof(u32)) {
  367. *aperture_base = adev->doorbell.base;
  368. *aperture_size = adev->doorbell.size;
  369. *start_offset = adev->doorbell.num_doorbells * sizeof(u32);
  370. } else {
  371. *aperture_base = 0;
  372. *aperture_size = 0;
  373. *start_offset = 0;
  374. }
  375. }
  376. /*
  377. * amdgpu_wb_*()
  378. * Writeback is the the method by which the the GPU updates special pages
  379. * in memory with the status of certain GPU events (fences, ring pointers,
  380. * etc.).
  381. */
  382. /**
  383. * amdgpu_wb_fini - Disable Writeback and free memory
  384. *
  385. * @adev: amdgpu_device pointer
  386. *
  387. * Disables Writeback and frees the Writeback memory (all asics).
  388. * Used at driver shutdown.
  389. */
  390. static void amdgpu_wb_fini(struct amdgpu_device *adev)
  391. {
  392. if (adev->wb.wb_obj) {
  393. if (!amdgpu_bo_reserve(adev->wb.wb_obj, false)) {
  394. amdgpu_bo_kunmap(adev->wb.wb_obj);
  395. amdgpu_bo_unpin(adev->wb.wb_obj);
  396. amdgpu_bo_unreserve(adev->wb.wb_obj);
  397. }
  398. amdgpu_bo_unref(&adev->wb.wb_obj);
  399. adev->wb.wb = NULL;
  400. adev->wb.wb_obj = NULL;
  401. }
  402. }
  403. /**
  404. * amdgpu_wb_init- Init Writeback driver info and allocate memory
  405. *
  406. * @adev: amdgpu_device pointer
  407. *
  408. * Disables Writeback and frees the Writeback memory (all asics).
  409. * Used at driver startup.
  410. * Returns 0 on success or an -error on failure.
  411. */
  412. static int amdgpu_wb_init(struct amdgpu_device *adev)
  413. {
  414. int r;
  415. if (adev->wb.wb_obj == NULL) {
  416. r = amdgpu_bo_create(adev, AMDGPU_MAX_WB * 4, PAGE_SIZE, true,
  417. AMDGPU_GEM_DOMAIN_GTT, 0, NULL, NULL,
  418. &adev->wb.wb_obj);
  419. if (r) {
  420. dev_warn(adev->dev, "(%d) create WB bo failed\n", r);
  421. return r;
  422. }
  423. r = amdgpu_bo_reserve(adev->wb.wb_obj, false);
  424. if (unlikely(r != 0)) {
  425. amdgpu_wb_fini(adev);
  426. return r;
  427. }
  428. r = amdgpu_bo_pin(adev->wb.wb_obj, AMDGPU_GEM_DOMAIN_GTT,
  429. &adev->wb.gpu_addr);
  430. if (r) {
  431. amdgpu_bo_unreserve(adev->wb.wb_obj);
  432. dev_warn(adev->dev, "(%d) pin WB bo failed\n", r);
  433. amdgpu_wb_fini(adev);
  434. return r;
  435. }
  436. r = amdgpu_bo_kmap(adev->wb.wb_obj, (void **)&adev->wb.wb);
  437. amdgpu_bo_unreserve(adev->wb.wb_obj);
  438. if (r) {
  439. dev_warn(adev->dev, "(%d) map WB bo failed\n", r);
  440. amdgpu_wb_fini(adev);
  441. return r;
  442. }
  443. adev->wb.num_wb = AMDGPU_MAX_WB;
  444. memset(&adev->wb.used, 0, sizeof(adev->wb.used));
  445. /* clear wb memory */
  446. memset((char *)adev->wb.wb, 0, AMDGPU_GPU_PAGE_SIZE);
  447. }
  448. return 0;
  449. }
  450. /**
  451. * amdgpu_wb_get - Allocate a wb entry
  452. *
  453. * @adev: amdgpu_device pointer
  454. * @wb: wb index
  455. *
  456. * Allocate a wb slot for use by the driver (all asics).
  457. * Returns 0 on success or -EINVAL on failure.
  458. */
  459. int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb)
  460. {
  461. unsigned long offset = find_first_zero_bit(adev->wb.used, adev->wb.num_wb);
  462. if (offset < adev->wb.num_wb) {
  463. __set_bit(offset, adev->wb.used);
  464. *wb = offset;
  465. return 0;
  466. } else {
  467. return -EINVAL;
  468. }
  469. }
  470. /**
  471. * amdgpu_wb_free - Free a wb entry
  472. *
  473. * @adev: amdgpu_device pointer
  474. * @wb: wb index
  475. *
  476. * Free a wb slot allocated for use by the driver (all asics)
  477. */
  478. void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb)
  479. {
  480. if (wb < adev->wb.num_wb)
  481. __clear_bit(wb, adev->wb.used);
  482. }
  483. /**
  484. * amdgpu_vram_location - try to find VRAM location
  485. * @adev: amdgpu device structure holding all necessary informations
  486. * @mc: memory controller structure holding memory informations
  487. * @base: base address at which to put VRAM
  488. *
  489. * Function will place try to place VRAM at base address provided
  490. * as parameter (which is so far either PCI aperture address or
  491. * for IGP TOM base address).
  492. *
  493. * If there is not enough space to fit the unvisible VRAM in the 32bits
  494. * address space then we limit the VRAM size to the aperture.
  495. *
  496. * Note: We don't explicitly enforce VRAM start to be aligned on VRAM size,
  497. * this shouldn't be a problem as we are using the PCI aperture as a reference.
  498. * Otherwise this would be needed for rv280, all r3xx, and all r4xx, but
  499. * not IGP.
  500. *
  501. * Note: we use mc_vram_size as on some board we need to program the mc to
  502. * cover the whole aperture even if VRAM size is inferior to aperture size
  503. * Novell bug 204882 + along with lots of ubuntu ones
  504. *
  505. * Note: when limiting vram it's safe to overwritte real_vram_size because
  506. * we are not in case where real_vram_size is inferior to mc_vram_size (ie
  507. * note afected by bogus hw of Novell bug 204882 + along with lots of ubuntu
  508. * ones)
  509. *
  510. * Note: IGP TOM addr should be the same as the aperture addr, we don't
  511. * explicitly check for that thought.
  512. *
  513. * FIXME: when reducing VRAM size align new size on power of 2.
  514. */
  515. void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base)
  516. {
  517. uint64_t limit = (uint64_t)amdgpu_vram_limit << 20;
  518. mc->vram_start = base;
  519. if (mc->mc_vram_size > (adev->mc.mc_mask - base + 1)) {
  520. dev_warn(adev->dev, "limiting VRAM to PCI aperture size\n");
  521. mc->real_vram_size = mc->aper_size;
  522. mc->mc_vram_size = mc->aper_size;
  523. }
  524. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  525. if (limit && limit < mc->real_vram_size)
  526. mc->real_vram_size = limit;
  527. dev_info(adev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
  528. mc->mc_vram_size >> 20, mc->vram_start,
  529. mc->vram_end, mc->real_vram_size >> 20);
  530. }
  531. /**
  532. * amdgpu_gtt_location - try to find GTT location
  533. * @adev: amdgpu device structure holding all necessary informations
  534. * @mc: memory controller structure holding memory informations
  535. *
  536. * Function will place try to place GTT before or after VRAM.
  537. *
  538. * If GTT size is bigger than space left then we ajust GTT size.
  539. * Thus function will never fails.
  540. *
  541. * FIXME: when reducing GTT size align new size on power of 2.
  542. */
  543. void amdgpu_gtt_location(struct amdgpu_device *adev, struct amdgpu_mc *mc)
  544. {
  545. u64 size_af, size_bf;
  546. size_af = ((adev->mc.mc_mask - mc->vram_end) + mc->gtt_base_align) & ~mc->gtt_base_align;
  547. size_bf = mc->vram_start & ~mc->gtt_base_align;
  548. if (size_bf > size_af) {
  549. if (mc->gtt_size > size_bf) {
  550. dev_warn(adev->dev, "limiting GTT\n");
  551. mc->gtt_size = size_bf;
  552. }
  553. mc->gtt_start = (mc->vram_start & ~mc->gtt_base_align) - mc->gtt_size;
  554. } else {
  555. if (mc->gtt_size > size_af) {
  556. dev_warn(adev->dev, "limiting GTT\n");
  557. mc->gtt_size = size_af;
  558. }
  559. mc->gtt_start = (mc->vram_end + 1 + mc->gtt_base_align) & ~mc->gtt_base_align;
  560. }
  561. mc->gtt_end = mc->gtt_start + mc->gtt_size - 1;
  562. dev_info(adev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
  563. mc->gtt_size >> 20, mc->gtt_start, mc->gtt_end);
  564. }
  565. /*
  566. * GPU helpers function.
  567. */
  568. /**
  569. * amdgpu_card_posted - check if the hw has already been initialized
  570. *
  571. * @adev: amdgpu_device pointer
  572. *
  573. * Check if the asic has been initialized (all asics).
  574. * Used at driver startup.
  575. * Returns true if initialized or false if not.
  576. */
  577. bool amdgpu_card_posted(struct amdgpu_device *adev)
  578. {
  579. uint32_t reg;
  580. /* then check MEM_SIZE, in case the crtcs are off */
  581. reg = RREG32(mmCONFIG_MEMSIZE);
  582. if (reg)
  583. return true;
  584. return false;
  585. }
  586. /**
  587. * amdgpu_dummy_page_init - init dummy page used by the driver
  588. *
  589. * @adev: amdgpu_device pointer
  590. *
  591. * Allocate the dummy page used by the driver (all asics).
  592. * This dummy page is used by the driver as a filler for gart entries
  593. * when pages are taken out of the GART
  594. * Returns 0 on sucess, -ENOMEM on failure.
  595. */
  596. int amdgpu_dummy_page_init(struct amdgpu_device *adev)
  597. {
  598. if (adev->dummy_page.page)
  599. return 0;
  600. adev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO);
  601. if (adev->dummy_page.page == NULL)
  602. return -ENOMEM;
  603. adev->dummy_page.addr = pci_map_page(adev->pdev, adev->dummy_page.page,
  604. 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  605. if (pci_dma_mapping_error(adev->pdev, adev->dummy_page.addr)) {
  606. dev_err(&adev->pdev->dev, "Failed to DMA MAP the dummy page\n");
  607. __free_page(adev->dummy_page.page);
  608. adev->dummy_page.page = NULL;
  609. return -ENOMEM;
  610. }
  611. return 0;
  612. }
  613. /**
  614. * amdgpu_dummy_page_fini - free dummy page used by the driver
  615. *
  616. * @adev: amdgpu_device pointer
  617. *
  618. * Frees the dummy page used by the driver (all asics).
  619. */
  620. void amdgpu_dummy_page_fini(struct amdgpu_device *adev)
  621. {
  622. if (adev->dummy_page.page == NULL)
  623. return;
  624. pci_unmap_page(adev->pdev, adev->dummy_page.addr,
  625. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  626. __free_page(adev->dummy_page.page);
  627. adev->dummy_page.page = NULL;
  628. }
  629. /* ATOM accessor methods */
  630. /*
  631. * ATOM is an interpreted byte code stored in tables in the vbios. The
  632. * driver registers callbacks to access registers and the interpreter
  633. * in the driver parses the tables and executes then to program specific
  634. * actions (set display modes, asic init, etc.). See amdgpu_atombios.c,
  635. * atombios.h, and atom.c
  636. */
  637. /**
  638. * cail_pll_read - read PLL register
  639. *
  640. * @info: atom card_info pointer
  641. * @reg: PLL register offset
  642. *
  643. * Provides a PLL register accessor for the atom interpreter (r4xx+).
  644. * Returns the value of the PLL register.
  645. */
  646. static uint32_t cail_pll_read(struct card_info *info, uint32_t reg)
  647. {
  648. return 0;
  649. }
  650. /**
  651. * cail_pll_write - write PLL register
  652. *
  653. * @info: atom card_info pointer
  654. * @reg: PLL register offset
  655. * @val: value to write to the pll register
  656. *
  657. * Provides a PLL register accessor for the atom interpreter (r4xx+).
  658. */
  659. static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val)
  660. {
  661. }
  662. /**
  663. * cail_mc_read - read MC (Memory Controller) register
  664. *
  665. * @info: atom card_info pointer
  666. * @reg: MC register offset
  667. *
  668. * Provides an MC register accessor for the atom interpreter (r4xx+).
  669. * Returns the value of the MC register.
  670. */
  671. static uint32_t cail_mc_read(struct card_info *info, uint32_t reg)
  672. {
  673. return 0;
  674. }
  675. /**
  676. * cail_mc_write - write MC (Memory Controller) register
  677. *
  678. * @info: atom card_info pointer
  679. * @reg: MC register offset
  680. * @val: value to write to the pll register
  681. *
  682. * Provides a MC register accessor for the atom interpreter (r4xx+).
  683. */
  684. static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val)
  685. {
  686. }
  687. /**
  688. * cail_reg_write - write MMIO register
  689. *
  690. * @info: atom card_info pointer
  691. * @reg: MMIO register offset
  692. * @val: value to write to the pll register
  693. *
  694. * Provides a MMIO register accessor for the atom interpreter (r4xx+).
  695. */
  696. static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val)
  697. {
  698. struct amdgpu_device *adev = info->dev->dev_private;
  699. WREG32(reg, val);
  700. }
  701. /**
  702. * cail_reg_read - read MMIO register
  703. *
  704. * @info: atom card_info pointer
  705. * @reg: MMIO register offset
  706. *
  707. * Provides an MMIO register accessor for the atom interpreter (r4xx+).
  708. * Returns the value of the MMIO register.
  709. */
  710. static uint32_t cail_reg_read(struct card_info *info, uint32_t reg)
  711. {
  712. struct amdgpu_device *adev = info->dev->dev_private;
  713. uint32_t r;
  714. r = RREG32(reg);
  715. return r;
  716. }
  717. /**
  718. * cail_ioreg_write - write IO register
  719. *
  720. * @info: atom card_info pointer
  721. * @reg: IO register offset
  722. * @val: value to write to the pll register
  723. *
  724. * Provides a IO register accessor for the atom interpreter (r4xx+).
  725. */
  726. static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val)
  727. {
  728. struct amdgpu_device *adev = info->dev->dev_private;
  729. WREG32_IO(reg, val);
  730. }
  731. /**
  732. * cail_ioreg_read - read IO register
  733. *
  734. * @info: atom card_info pointer
  735. * @reg: IO register offset
  736. *
  737. * Provides an IO register accessor for the atom interpreter (r4xx+).
  738. * Returns the value of the IO register.
  739. */
  740. static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg)
  741. {
  742. struct amdgpu_device *adev = info->dev->dev_private;
  743. uint32_t r;
  744. r = RREG32_IO(reg);
  745. return r;
  746. }
  747. /**
  748. * amdgpu_atombios_fini - free the driver info and callbacks for atombios
  749. *
  750. * @adev: amdgpu_device pointer
  751. *
  752. * Frees the driver info and register access callbacks for the ATOM
  753. * interpreter (r4xx+).
  754. * Called at driver shutdown.
  755. */
  756. static void amdgpu_atombios_fini(struct amdgpu_device *adev)
  757. {
  758. if (adev->mode_info.atom_context)
  759. kfree(adev->mode_info.atom_context->scratch);
  760. kfree(adev->mode_info.atom_context);
  761. adev->mode_info.atom_context = NULL;
  762. kfree(adev->mode_info.atom_card_info);
  763. adev->mode_info.atom_card_info = NULL;
  764. }
  765. /**
  766. * amdgpu_atombios_init - init the driver info and callbacks for atombios
  767. *
  768. * @adev: amdgpu_device pointer
  769. *
  770. * Initializes the driver info and register access callbacks for the
  771. * ATOM interpreter (r4xx+).
  772. * Returns 0 on sucess, -ENOMEM on failure.
  773. * Called at driver startup.
  774. */
  775. static int amdgpu_atombios_init(struct amdgpu_device *adev)
  776. {
  777. struct card_info *atom_card_info =
  778. kzalloc(sizeof(struct card_info), GFP_KERNEL);
  779. if (!atom_card_info)
  780. return -ENOMEM;
  781. adev->mode_info.atom_card_info = atom_card_info;
  782. atom_card_info->dev = adev->ddev;
  783. atom_card_info->reg_read = cail_reg_read;
  784. atom_card_info->reg_write = cail_reg_write;
  785. /* needed for iio ops */
  786. if (adev->rio_mem) {
  787. atom_card_info->ioreg_read = cail_ioreg_read;
  788. atom_card_info->ioreg_write = cail_ioreg_write;
  789. } else {
  790. DRM_ERROR("Unable to find PCI I/O BAR; using MMIO for ATOM IIO\n");
  791. atom_card_info->ioreg_read = cail_reg_read;
  792. atom_card_info->ioreg_write = cail_reg_write;
  793. }
  794. atom_card_info->mc_read = cail_mc_read;
  795. atom_card_info->mc_write = cail_mc_write;
  796. atom_card_info->pll_read = cail_pll_read;
  797. atom_card_info->pll_write = cail_pll_write;
  798. adev->mode_info.atom_context = amdgpu_atom_parse(atom_card_info, adev->bios);
  799. if (!adev->mode_info.atom_context) {
  800. amdgpu_atombios_fini(adev);
  801. return -ENOMEM;
  802. }
  803. mutex_init(&adev->mode_info.atom_context->mutex);
  804. amdgpu_atombios_scratch_regs_init(adev);
  805. amdgpu_atom_allocate_fb_scratch(adev->mode_info.atom_context);
  806. return 0;
  807. }
  808. /* if we get transitioned to only one device, take VGA back */
  809. /**
  810. * amdgpu_vga_set_decode - enable/disable vga decode
  811. *
  812. * @cookie: amdgpu_device pointer
  813. * @state: enable/disable vga decode
  814. *
  815. * Enable/disable vga decode (all asics).
  816. * Returns VGA resource flags.
  817. */
  818. static unsigned int amdgpu_vga_set_decode(void *cookie, bool state)
  819. {
  820. struct amdgpu_device *adev = cookie;
  821. amdgpu_asic_set_vga_state(adev, state);
  822. if (state)
  823. return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
  824. VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  825. else
  826. return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  827. }
  828. /**
  829. * amdgpu_check_pot_argument - check that argument is a power of two
  830. *
  831. * @arg: value to check
  832. *
  833. * Validates that a certain argument is a power of two (all asics).
  834. * Returns true if argument is valid.
  835. */
  836. static bool amdgpu_check_pot_argument(int arg)
  837. {
  838. return (arg & (arg - 1)) == 0;
  839. }
  840. /**
  841. * amdgpu_check_arguments - validate module params
  842. *
  843. * @adev: amdgpu_device pointer
  844. *
  845. * Validates certain module parameters and updates
  846. * the associated values used by the driver (all asics).
  847. */
  848. static void amdgpu_check_arguments(struct amdgpu_device *adev)
  849. {
  850. if (amdgpu_sched_jobs < 4) {
  851. dev_warn(adev->dev, "sched jobs (%d) must be at least 4\n",
  852. amdgpu_sched_jobs);
  853. amdgpu_sched_jobs = 4;
  854. } else if (!amdgpu_check_pot_argument(amdgpu_sched_jobs)){
  855. dev_warn(adev->dev, "sched jobs (%d) must be a power of 2\n",
  856. amdgpu_sched_jobs);
  857. amdgpu_sched_jobs = roundup_pow_of_two(amdgpu_sched_jobs);
  858. }
  859. if (amdgpu_gart_size != -1) {
  860. /* gtt size must be greater or equal to 32M */
  861. if (amdgpu_gart_size < 32) {
  862. dev_warn(adev->dev, "gart size (%d) too small\n",
  863. amdgpu_gart_size);
  864. amdgpu_gart_size = -1;
  865. }
  866. }
  867. if (!amdgpu_check_pot_argument(amdgpu_vm_size)) {
  868. dev_warn(adev->dev, "VM size (%d) must be a power of 2\n",
  869. amdgpu_vm_size);
  870. amdgpu_vm_size = 8;
  871. }
  872. if (amdgpu_vm_size < 1) {
  873. dev_warn(adev->dev, "VM size (%d) too small, min is 1GB\n",
  874. amdgpu_vm_size);
  875. amdgpu_vm_size = 8;
  876. }
  877. /*
  878. * Max GPUVM size for Cayman, SI and CI are 40 bits.
  879. */
  880. if (amdgpu_vm_size > 1024) {
  881. dev_warn(adev->dev, "VM size (%d) too large, max is 1TB\n",
  882. amdgpu_vm_size);
  883. amdgpu_vm_size = 8;
  884. }
  885. /* defines number of bits in page table versus page directory,
  886. * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
  887. * page table and the remaining bits are in the page directory */
  888. if (amdgpu_vm_block_size == -1) {
  889. /* Total bits covered by PD + PTs */
  890. unsigned bits = ilog2(amdgpu_vm_size) + 18;
  891. /* Make sure the PD is 4K in size up to 8GB address space.
  892. Above that split equal between PD and PTs */
  893. if (amdgpu_vm_size <= 8)
  894. amdgpu_vm_block_size = bits - 9;
  895. else
  896. amdgpu_vm_block_size = (bits + 3) / 2;
  897. } else if (amdgpu_vm_block_size < 9) {
  898. dev_warn(adev->dev, "VM page table size (%d) too small\n",
  899. amdgpu_vm_block_size);
  900. amdgpu_vm_block_size = 9;
  901. }
  902. if (amdgpu_vm_block_size > 24 ||
  903. (amdgpu_vm_size * 1024) < (1ull << amdgpu_vm_block_size)) {
  904. dev_warn(adev->dev, "VM page table size (%d) too large\n",
  905. amdgpu_vm_block_size);
  906. amdgpu_vm_block_size = 9;
  907. }
  908. }
  909. /**
  910. * amdgpu_switcheroo_set_state - set switcheroo state
  911. *
  912. * @pdev: pci dev pointer
  913. * @state: vga_switcheroo state
  914. *
  915. * Callback for the switcheroo driver. Suspends or resumes the
  916. * the asics before or after it is powered up using ACPI methods.
  917. */
  918. static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
  919. {
  920. struct drm_device *dev = pci_get_drvdata(pdev);
  921. if (amdgpu_device_is_px(dev) && state == VGA_SWITCHEROO_OFF)
  922. return;
  923. if (state == VGA_SWITCHEROO_ON) {
  924. unsigned d3_delay = dev->pdev->d3_delay;
  925. printk(KERN_INFO "amdgpu: switched on\n");
  926. /* don't suspend or resume card normally */
  927. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  928. amdgpu_resume_kms(dev, true, true);
  929. dev->pdev->d3_delay = d3_delay;
  930. dev->switch_power_state = DRM_SWITCH_POWER_ON;
  931. drm_kms_helper_poll_enable(dev);
  932. } else {
  933. printk(KERN_INFO "amdgpu: switched off\n");
  934. drm_kms_helper_poll_disable(dev);
  935. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  936. amdgpu_suspend_kms(dev, true, true);
  937. dev->switch_power_state = DRM_SWITCH_POWER_OFF;
  938. }
  939. }
  940. /**
  941. * amdgpu_switcheroo_can_switch - see if switcheroo state can change
  942. *
  943. * @pdev: pci dev pointer
  944. *
  945. * Callback for the switcheroo driver. Check of the switcheroo
  946. * state can be changed.
  947. * Returns true if the state can be changed, false if not.
  948. */
  949. static bool amdgpu_switcheroo_can_switch(struct pci_dev *pdev)
  950. {
  951. struct drm_device *dev = pci_get_drvdata(pdev);
  952. /*
  953. * FIXME: open_count is protected by drm_global_mutex but that would lead to
  954. * locking inversion with the driver load path. And the access here is
  955. * completely racy anyway. So don't bother with locking for now.
  956. */
  957. return dev->open_count == 0;
  958. }
  959. static const struct vga_switcheroo_client_ops amdgpu_switcheroo_ops = {
  960. .set_gpu_state = amdgpu_switcheroo_set_state,
  961. .reprobe = NULL,
  962. .can_switch = amdgpu_switcheroo_can_switch,
  963. };
  964. int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
  965. enum amd_ip_block_type block_type,
  966. enum amd_clockgating_state state)
  967. {
  968. int i, r = 0;
  969. for (i = 0; i < adev->num_ip_blocks; i++) {
  970. if (adev->ip_blocks[i].type == block_type) {
  971. r = adev->ip_blocks[i].funcs->set_clockgating_state((void *)adev,
  972. state);
  973. if (r)
  974. return r;
  975. }
  976. }
  977. return r;
  978. }
  979. int amdgpu_set_powergating_state(struct amdgpu_device *adev,
  980. enum amd_ip_block_type block_type,
  981. enum amd_powergating_state state)
  982. {
  983. int i, r = 0;
  984. for (i = 0; i < adev->num_ip_blocks; i++) {
  985. if (adev->ip_blocks[i].type == block_type) {
  986. r = adev->ip_blocks[i].funcs->set_powergating_state((void *)adev,
  987. state);
  988. if (r)
  989. return r;
  990. }
  991. }
  992. return r;
  993. }
  994. const struct amdgpu_ip_block_version * amdgpu_get_ip_block(
  995. struct amdgpu_device *adev,
  996. enum amd_ip_block_type type)
  997. {
  998. int i;
  999. for (i = 0; i < adev->num_ip_blocks; i++)
  1000. if (adev->ip_blocks[i].type == type)
  1001. return &adev->ip_blocks[i];
  1002. return NULL;
  1003. }
  1004. /**
  1005. * amdgpu_ip_block_version_cmp
  1006. *
  1007. * @adev: amdgpu_device pointer
  1008. * @type: enum amd_ip_block_type
  1009. * @major: major version
  1010. * @minor: minor version
  1011. *
  1012. * return 0 if equal or greater
  1013. * return 1 if smaller or the ip_block doesn't exist
  1014. */
  1015. int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
  1016. enum amd_ip_block_type type,
  1017. u32 major, u32 minor)
  1018. {
  1019. const struct amdgpu_ip_block_version *ip_block;
  1020. ip_block = amdgpu_get_ip_block(adev, type);
  1021. if (ip_block && ((ip_block->major > major) ||
  1022. ((ip_block->major == major) &&
  1023. (ip_block->minor >= minor))))
  1024. return 0;
  1025. return 1;
  1026. }
  1027. static int amdgpu_early_init(struct amdgpu_device *adev)
  1028. {
  1029. int i, r;
  1030. switch (adev->asic_type) {
  1031. case CHIP_TOPAZ:
  1032. case CHIP_TONGA:
  1033. case CHIP_FIJI:
  1034. case CHIP_POLARIS11:
  1035. case CHIP_POLARIS10:
  1036. case CHIP_CARRIZO:
  1037. case CHIP_STONEY:
  1038. if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY)
  1039. adev->family = AMDGPU_FAMILY_CZ;
  1040. else
  1041. adev->family = AMDGPU_FAMILY_VI;
  1042. r = vi_set_ip_blocks(adev);
  1043. if (r)
  1044. return r;
  1045. break;
  1046. #ifdef CONFIG_DRM_AMDGPU_CIK
  1047. case CHIP_BONAIRE:
  1048. case CHIP_HAWAII:
  1049. case CHIP_KAVERI:
  1050. case CHIP_KABINI:
  1051. case CHIP_MULLINS:
  1052. if ((adev->asic_type == CHIP_BONAIRE) || (adev->asic_type == CHIP_HAWAII))
  1053. adev->family = AMDGPU_FAMILY_CI;
  1054. else
  1055. adev->family = AMDGPU_FAMILY_KV;
  1056. r = cik_set_ip_blocks(adev);
  1057. if (r)
  1058. return r;
  1059. break;
  1060. #endif
  1061. default:
  1062. /* FIXME: not supported yet */
  1063. return -EINVAL;
  1064. }
  1065. adev->ip_block_status = kcalloc(adev->num_ip_blocks,
  1066. sizeof(struct amdgpu_ip_block_status), GFP_KERNEL);
  1067. if (adev->ip_block_status == NULL)
  1068. return -ENOMEM;
  1069. if (adev->ip_blocks == NULL) {
  1070. DRM_ERROR("No IP blocks found!\n");
  1071. return r;
  1072. }
  1073. for (i = 0; i < adev->num_ip_blocks; i++) {
  1074. if ((amdgpu_ip_block_mask & (1 << i)) == 0) {
  1075. DRM_ERROR("disabled ip block: %d\n", i);
  1076. adev->ip_block_status[i].valid = false;
  1077. } else {
  1078. if (adev->ip_blocks[i].funcs->early_init) {
  1079. r = adev->ip_blocks[i].funcs->early_init((void *)adev);
  1080. if (r == -ENOENT) {
  1081. adev->ip_block_status[i].valid = false;
  1082. } else if (r) {
  1083. DRM_ERROR("early_init of IP block <%s> failed %d\n", adev->ip_blocks[i].funcs->name, r);
  1084. return r;
  1085. } else {
  1086. adev->ip_block_status[i].valid = true;
  1087. }
  1088. } else {
  1089. adev->ip_block_status[i].valid = true;
  1090. }
  1091. }
  1092. }
  1093. return 0;
  1094. }
  1095. static int amdgpu_init(struct amdgpu_device *adev)
  1096. {
  1097. int i, r;
  1098. for (i = 0; i < adev->num_ip_blocks; i++) {
  1099. if (!adev->ip_block_status[i].valid)
  1100. continue;
  1101. r = adev->ip_blocks[i].funcs->sw_init((void *)adev);
  1102. if (r) {
  1103. DRM_ERROR("sw_init %d failed %d\n", i, r);
  1104. return r;
  1105. }
  1106. adev->ip_block_status[i].sw = true;
  1107. /* need to do gmc hw init early so we can allocate gpu mem */
  1108. if (adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_GMC) {
  1109. r = amdgpu_vram_scratch_init(adev);
  1110. if (r) {
  1111. DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r);
  1112. return r;
  1113. }
  1114. r = adev->ip_blocks[i].funcs->hw_init((void *)adev);
  1115. if (r) {
  1116. DRM_ERROR("hw_init %d failed %d\n", i, r);
  1117. return r;
  1118. }
  1119. r = amdgpu_wb_init(adev);
  1120. if (r) {
  1121. DRM_ERROR("amdgpu_wb_init failed %d\n", r);
  1122. return r;
  1123. }
  1124. adev->ip_block_status[i].hw = true;
  1125. }
  1126. }
  1127. for (i = 0; i < adev->num_ip_blocks; i++) {
  1128. if (!adev->ip_block_status[i].sw)
  1129. continue;
  1130. /* gmc hw init is done early */
  1131. if (adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_GMC)
  1132. continue;
  1133. r = adev->ip_blocks[i].funcs->hw_init((void *)adev);
  1134. if (r) {
  1135. DRM_ERROR("hw_init %d failed %d\n", i, r);
  1136. return r;
  1137. }
  1138. adev->ip_block_status[i].hw = true;
  1139. }
  1140. return 0;
  1141. }
  1142. static int amdgpu_late_init(struct amdgpu_device *adev)
  1143. {
  1144. int i = 0, r;
  1145. for (i = 0; i < adev->num_ip_blocks; i++) {
  1146. if (!adev->ip_block_status[i].valid)
  1147. continue;
  1148. /* enable clockgating to save power */
  1149. r = adev->ip_blocks[i].funcs->set_clockgating_state((void *)adev,
  1150. AMD_CG_STATE_GATE);
  1151. if (r) {
  1152. DRM_ERROR("set_clockgating_state(gate) %d failed %d\n", i, r);
  1153. return r;
  1154. }
  1155. if (adev->ip_blocks[i].funcs->late_init) {
  1156. r = adev->ip_blocks[i].funcs->late_init((void *)adev);
  1157. if (r) {
  1158. DRM_ERROR("late_init %d failed %d\n", i, r);
  1159. return r;
  1160. }
  1161. }
  1162. }
  1163. return 0;
  1164. }
  1165. static int amdgpu_fini(struct amdgpu_device *adev)
  1166. {
  1167. int i, r;
  1168. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1169. if (!adev->ip_block_status[i].hw)
  1170. continue;
  1171. if (adev->ip_blocks[i].type == AMD_IP_BLOCK_TYPE_GMC) {
  1172. amdgpu_wb_fini(adev);
  1173. amdgpu_vram_scratch_fini(adev);
  1174. }
  1175. /* ungate blocks before hw fini so that we can shutdown the blocks safely */
  1176. r = adev->ip_blocks[i].funcs->set_clockgating_state((void *)adev,
  1177. AMD_CG_STATE_UNGATE);
  1178. if (r) {
  1179. DRM_ERROR("set_clockgating_state(ungate) %d failed %d\n", i, r);
  1180. return r;
  1181. }
  1182. r = adev->ip_blocks[i].funcs->hw_fini((void *)adev);
  1183. /* XXX handle errors */
  1184. if (r) {
  1185. DRM_DEBUG("hw_fini %d failed %d\n", i, r);
  1186. }
  1187. adev->ip_block_status[i].hw = false;
  1188. }
  1189. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1190. if (!adev->ip_block_status[i].sw)
  1191. continue;
  1192. r = adev->ip_blocks[i].funcs->sw_fini((void *)adev);
  1193. /* XXX handle errors */
  1194. if (r) {
  1195. DRM_DEBUG("sw_fini %d failed %d\n", i, r);
  1196. }
  1197. adev->ip_block_status[i].sw = false;
  1198. adev->ip_block_status[i].valid = false;
  1199. }
  1200. return 0;
  1201. }
  1202. static int amdgpu_suspend(struct amdgpu_device *adev)
  1203. {
  1204. int i, r;
  1205. /* ungate SMC block first */
  1206. r = amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_SMC,
  1207. AMD_CG_STATE_UNGATE);
  1208. if (r) {
  1209. DRM_ERROR("set_clockgating_state(ungate) SMC failed %d\n",r);
  1210. }
  1211. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1212. if (!adev->ip_block_status[i].valid)
  1213. continue;
  1214. /* ungate blocks so that suspend can properly shut them down */
  1215. if (i != AMD_IP_BLOCK_TYPE_SMC) {
  1216. r = adev->ip_blocks[i].funcs->set_clockgating_state((void *)adev,
  1217. AMD_CG_STATE_UNGATE);
  1218. if (r) {
  1219. DRM_ERROR("set_clockgating_state(ungate) %d failed %d\n", i, r);
  1220. }
  1221. }
  1222. /* XXX handle errors */
  1223. r = adev->ip_blocks[i].funcs->suspend(adev);
  1224. /* XXX handle errors */
  1225. if (r) {
  1226. DRM_ERROR("suspend %d failed %d\n", i, r);
  1227. }
  1228. }
  1229. return 0;
  1230. }
  1231. static int amdgpu_resume(struct amdgpu_device *adev)
  1232. {
  1233. int i, r;
  1234. for (i = 0; i < adev->num_ip_blocks; i++) {
  1235. if (!adev->ip_block_status[i].valid)
  1236. continue;
  1237. r = adev->ip_blocks[i].funcs->resume(adev);
  1238. if (r) {
  1239. DRM_ERROR("resume %d failed %d\n", i, r);
  1240. return r;
  1241. }
  1242. }
  1243. return 0;
  1244. }
  1245. /**
  1246. * amdgpu_device_init - initialize the driver
  1247. *
  1248. * @adev: amdgpu_device pointer
  1249. * @pdev: drm dev pointer
  1250. * @pdev: pci dev pointer
  1251. * @flags: driver flags
  1252. *
  1253. * Initializes the driver info and hw (all asics).
  1254. * Returns 0 for success or an error on failure.
  1255. * Called at driver startup.
  1256. */
  1257. int amdgpu_device_init(struct amdgpu_device *adev,
  1258. struct drm_device *ddev,
  1259. struct pci_dev *pdev,
  1260. uint32_t flags)
  1261. {
  1262. int r, i;
  1263. bool runtime = false;
  1264. adev->shutdown = false;
  1265. adev->dev = &pdev->dev;
  1266. adev->ddev = ddev;
  1267. adev->pdev = pdev;
  1268. adev->flags = flags;
  1269. adev->asic_type = flags & AMD_ASIC_MASK;
  1270. adev->is_atom_bios = false;
  1271. adev->usec_timeout = AMDGPU_MAX_USEC_TIMEOUT;
  1272. adev->mc.gtt_size = 512 * 1024 * 1024;
  1273. adev->accel_working = false;
  1274. adev->num_rings = 0;
  1275. adev->mman.buffer_funcs = NULL;
  1276. adev->mman.buffer_funcs_ring = NULL;
  1277. adev->vm_manager.vm_pte_funcs = NULL;
  1278. adev->vm_manager.vm_pte_num_rings = 0;
  1279. adev->gart.gart_funcs = NULL;
  1280. adev->fence_context = fence_context_alloc(AMDGPU_MAX_RINGS);
  1281. adev->smc_rreg = &amdgpu_invalid_rreg;
  1282. adev->smc_wreg = &amdgpu_invalid_wreg;
  1283. adev->pcie_rreg = &amdgpu_invalid_rreg;
  1284. adev->pcie_wreg = &amdgpu_invalid_wreg;
  1285. adev->uvd_ctx_rreg = &amdgpu_invalid_rreg;
  1286. adev->uvd_ctx_wreg = &amdgpu_invalid_wreg;
  1287. adev->didt_rreg = &amdgpu_invalid_rreg;
  1288. adev->didt_wreg = &amdgpu_invalid_wreg;
  1289. adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg;
  1290. adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg;
  1291. DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n",
  1292. amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device,
  1293. pdev->subsystem_vendor, pdev->subsystem_device, pdev->revision);
  1294. /* mutex initialization are all done here so we
  1295. * can recall function without having locking issues */
  1296. mutex_init(&adev->vm_manager.lock);
  1297. atomic_set(&adev->irq.ih.lock, 0);
  1298. mutex_init(&adev->pm.mutex);
  1299. mutex_init(&adev->gfx.gpu_clock_mutex);
  1300. mutex_init(&adev->srbm_mutex);
  1301. mutex_init(&adev->grbm_idx_mutex);
  1302. mutex_init(&adev->mn_lock);
  1303. hash_init(adev->mn_hash);
  1304. amdgpu_check_arguments(adev);
  1305. /* Registers mapping */
  1306. /* TODO: block userspace mapping of io register */
  1307. spin_lock_init(&adev->mmio_idx_lock);
  1308. spin_lock_init(&adev->smc_idx_lock);
  1309. spin_lock_init(&adev->pcie_idx_lock);
  1310. spin_lock_init(&adev->uvd_ctx_idx_lock);
  1311. spin_lock_init(&adev->didt_idx_lock);
  1312. spin_lock_init(&adev->audio_endpt_idx_lock);
  1313. adev->rmmio_base = pci_resource_start(adev->pdev, 5);
  1314. adev->rmmio_size = pci_resource_len(adev->pdev, 5);
  1315. adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
  1316. if (adev->rmmio == NULL) {
  1317. return -ENOMEM;
  1318. }
  1319. DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
  1320. DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size);
  1321. /* doorbell bar mapping */
  1322. amdgpu_doorbell_init(adev);
  1323. /* io port mapping */
  1324. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  1325. if (pci_resource_flags(adev->pdev, i) & IORESOURCE_IO) {
  1326. adev->rio_mem_size = pci_resource_len(adev->pdev, i);
  1327. adev->rio_mem = pci_iomap(adev->pdev, i, adev->rio_mem_size);
  1328. break;
  1329. }
  1330. }
  1331. if (adev->rio_mem == NULL)
  1332. DRM_ERROR("Unable to find PCI I/O BAR\n");
  1333. /* early init functions */
  1334. r = amdgpu_early_init(adev);
  1335. if (r)
  1336. return r;
  1337. /* if we have > 1 VGA cards, then disable the amdgpu VGA resources */
  1338. /* this will fail for cards that aren't VGA class devices, just
  1339. * ignore it */
  1340. vga_client_register(adev->pdev, adev, NULL, amdgpu_vga_set_decode);
  1341. if (amdgpu_runtime_pm == 1)
  1342. runtime = true;
  1343. if (amdgpu_device_is_px(ddev))
  1344. runtime = true;
  1345. vga_switcheroo_register_client(adev->pdev, &amdgpu_switcheroo_ops, runtime);
  1346. if (runtime)
  1347. vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain);
  1348. /* Read BIOS */
  1349. if (!amdgpu_get_bios(adev))
  1350. return -EINVAL;
  1351. /* Must be an ATOMBIOS */
  1352. if (!adev->is_atom_bios) {
  1353. dev_err(adev->dev, "Expecting atombios for GPU\n");
  1354. return -EINVAL;
  1355. }
  1356. r = amdgpu_atombios_init(adev);
  1357. if (r) {
  1358. dev_err(adev->dev, "amdgpu_atombios_init failed\n");
  1359. return r;
  1360. }
  1361. /* See if the asic supports SR-IOV */
  1362. adev->virtualization.supports_sr_iov =
  1363. amdgpu_atombios_has_gpu_virtualization_table(adev);
  1364. /* Post card if necessary */
  1365. if (!amdgpu_card_posted(adev) ||
  1366. adev->virtualization.supports_sr_iov) {
  1367. if (!adev->bios) {
  1368. dev_err(adev->dev, "Card not posted and no BIOS - ignoring\n");
  1369. return -EINVAL;
  1370. }
  1371. DRM_INFO("GPU not posted. posting now...\n");
  1372. amdgpu_atom_asic_init(adev->mode_info.atom_context);
  1373. }
  1374. /* Initialize clocks */
  1375. r = amdgpu_atombios_get_clock_info(adev);
  1376. if (r) {
  1377. dev_err(adev->dev, "amdgpu_atombios_get_clock_info failed\n");
  1378. return r;
  1379. }
  1380. /* init i2c buses */
  1381. amdgpu_atombios_i2c_init(adev);
  1382. /* Fence driver */
  1383. r = amdgpu_fence_driver_init(adev);
  1384. if (r) {
  1385. dev_err(adev->dev, "amdgpu_fence_driver_init failed\n");
  1386. return r;
  1387. }
  1388. /* init the mode config */
  1389. drm_mode_config_init(adev->ddev);
  1390. r = amdgpu_init(adev);
  1391. if (r) {
  1392. dev_err(adev->dev, "amdgpu_init failed\n");
  1393. amdgpu_fini(adev);
  1394. return r;
  1395. }
  1396. adev->accel_working = true;
  1397. amdgpu_fbdev_init(adev);
  1398. r = amdgpu_ib_pool_init(adev);
  1399. if (r) {
  1400. dev_err(adev->dev, "IB initialization failed (%d).\n", r);
  1401. return r;
  1402. }
  1403. r = amdgpu_ib_ring_tests(adev);
  1404. if (r)
  1405. DRM_ERROR("ib ring test failed (%d).\n", r);
  1406. r = amdgpu_gem_debugfs_init(adev);
  1407. if (r) {
  1408. DRM_ERROR("registering gem debugfs failed (%d).\n", r);
  1409. }
  1410. r = amdgpu_debugfs_regs_init(adev);
  1411. if (r) {
  1412. DRM_ERROR("registering register debugfs failed (%d).\n", r);
  1413. }
  1414. if ((amdgpu_testing & 1)) {
  1415. if (adev->accel_working)
  1416. amdgpu_test_moves(adev);
  1417. else
  1418. DRM_INFO("amdgpu: acceleration disabled, skipping move tests\n");
  1419. }
  1420. if ((amdgpu_testing & 2)) {
  1421. if (adev->accel_working)
  1422. amdgpu_test_syncing(adev);
  1423. else
  1424. DRM_INFO("amdgpu: acceleration disabled, skipping sync tests\n");
  1425. }
  1426. if (amdgpu_benchmarking) {
  1427. if (adev->accel_working)
  1428. amdgpu_benchmark(adev, amdgpu_benchmarking);
  1429. else
  1430. DRM_INFO("amdgpu: acceleration disabled, skipping benchmarks\n");
  1431. }
  1432. /* enable clockgating, etc. after ib tests, etc. since some blocks require
  1433. * explicit gating rather than handling it automatically.
  1434. */
  1435. r = amdgpu_late_init(adev);
  1436. if (r) {
  1437. dev_err(adev->dev, "amdgpu_late_init failed\n");
  1438. return r;
  1439. }
  1440. return 0;
  1441. }
  1442. static void amdgpu_debugfs_remove_files(struct amdgpu_device *adev);
  1443. /**
  1444. * amdgpu_device_fini - tear down the driver
  1445. *
  1446. * @adev: amdgpu_device pointer
  1447. *
  1448. * Tear down the driver info (all asics).
  1449. * Called at driver shutdown.
  1450. */
  1451. void amdgpu_device_fini(struct amdgpu_device *adev)
  1452. {
  1453. int r;
  1454. DRM_INFO("amdgpu: finishing device.\n");
  1455. adev->shutdown = true;
  1456. /* evict vram memory */
  1457. amdgpu_bo_evict_vram(adev);
  1458. amdgpu_ib_pool_fini(adev);
  1459. amdgpu_fence_driver_fini(adev);
  1460. amdgpu_fbdev_fini(adev);
  1461. r = amdgpu_fini(adev);
  1462. kfree(adev->ip_block_status);
  1463. adev->ip_block_status = NULL;
  1464. adev->accel_working = false;
  1465. /* free i2c buses */
  1466. amdgpu_i2c_fini(adev);
  1467. amdgpu_atombios_fini(adev);
  1468. kfree(adev->bios);
  1469. adev->bios = NULL;
  1470. vga_switcheroo_unregister_client(adev->pdev);
  1471. vga_client_register(adev->pdev, NULL, NULL, NULL);
  1472. if (adev->rio_mem)
  1473. pci_iounmap(adev->pdev, adev->rio_mem);
  1474. adev->rio_mem = NULL;
  1475. iounmap(adev->rmmio);
  1476. adev->rmmio = NULL;
  1477. amdgpu_doorbell_fini(adev);
  1478. amdgpu_debugfs_regs_cleanup(adev);
  1479. amdgpu_debugfs_remove_files(adev);
  1480. }
  1481. /*
  1482. * Suspend & resume.
  1483. */
  1484. /**
  1485. * amdgpu_suspend_kms - initiate device suspend
  1486. *
  1487. * @pdev: drm dev pointer
  1488. * @state: suspend state
  1489. *
  1490. * Puts the hw in the suspend state (all asics).
  1491. * Returns 0 for success or an error on failure.
  1492. * Called at driver suspend.
  1493. */
  1494. int amdgpu_suspend_kms(struct drm_device *dev, bool suspend, bool fbcon)
  1495. {
  1496. struct amdgpu_device *adev;
  1497. struct drm_crtc *crtc;
  1498. struct drm_connector *connector;
  1499. int r;
  1500. if (dev == NULL || dev->dev_private == NULL) {
  1501. return -ENODEV;
  1502. }
  1503. adev = dev->dev_private;
  1504. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1505. return 0;
  1506. drm_kms_helper_poll_disable(dev);
  1507. /* turn off display hw */
  1508. drm_modeset_lock_all(dev);
  1509. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1510. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
  1511. }
  1512. drm_modeset_unlock_all(dev);
  1513. /* unpin the front buffers and cursors */
  1514. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1515. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1516. struct amdgpu_framebuffer *rfb = to_amdgpu_framebuffer(crtc->primary->fb);
  1517. struct amdgpu_bo *robj;
  1518. if (amdgpu_crtc->cursor_bo) {
  1519. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  1520. r = amdgpu_bo_reserve(aobj, false);
  1521. if (r == 0) {
  1522. amdgpu_bo_unpin(aobj);
  1523. amdgpu_bo_unreserve(aobj);
  1524. }
  1525. }
  1526. if (rfb == NULL || rfb->obj == NULL) {
  1527. continue;
  1528. }
  1529. robj = gem_to_amdgpu_bo(rfb->obj);
  1530. /* don't unpin kernel fb objects */
  1531. if (!amdgpu_fbdev_robj_is_fb(adev, robj)) {
  1532. r = amdgpu_bo_reserve(robj, false);
  1533. if (r == 0) {
  1534. amdgpu_bo_unpin(robj);
  1535. amdgpu_bo_unreserve(robj);
  1536. }
  1537. }
  1538. }
  1539. /* evict vram memory */
  1540. amdgpu_bo_evict_vram(adev);
  1541. amdgpu_fence_driver_suspend(adev);
  1542. r = amdgpu_suspend(adev);
  1543. /* evict remaining vram memory */
  1544. amdgpu_bo_evict_vram(adev);
  1545. pci_save_state(dev->pdev);
  1546. if (suspend) {
  1547. /* Shut down the device */
  1548. pci_disable_device(dev->pdev);
  1549. pci_set_power_state(dev->pdev, PCI_D3hot);
  1550. }
  1551. if (fbcon) {
  1552. console_lock();
  1553. amdgpu_fbdev_set_suspend(adev, 1);
  1554. console_unlock();
  1555. }
  1556. return 0;
  1557. }
  1558. /**
  1559. * amdgpu_resume_kms - initiate device resume
  1560. *
  1561. * @pdev: drm dev pointer
  1562. *
  1563. * Bring the hw back to operating state (all asics).
  1564. * Returns 0 for success or an error on failure.
  1565. * Called at driver resume.
  1566. */
  1567. int amdgpu_resume_kms(struct drm_device *dev, bool resume, bool fbcon)
  1568. {
  1569. struct drm_connector *connector;
  1570. struct amdgpu_device *adev = dev->dev_private;
  1571. struct drm_crtc *crtc;
  1572. int r;
  1573. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1574. return 0;
  1575. if (fbcon) {
  1576. console_lock();
  1577. }
  1578. if (resume) {
  1579. pci_set_power_state(dev->pdev, PCI_D0);
  1580. pci_restore_state(dev->pdev);
  1581. if (pci_enable_device(dev->pdev)) {
  1582. if (fbcon)
  1583. console_unlock();
  1584. return -1;
  1585. }
  1586. }
  1587. /* post card */
  1588. if (!amdgpu_card_posted(adev))
  1589. amdgpu_atom_asic_init(adev->mode_info.atom_context);
  1590. r = amdgpu_resume(adev);
  1591. if (r)
  1592. DRM_ERROR("amdgpu_resume failed (%d).\n", r);
  1593. amdgpu_fence_driver_resume(adev);
  1594. if (resume) {
  1595. r = amdgpu_ib_ring_tests(adev);
  1596. if (r)
  1597. DRM_ERROR("ib ring test failed (%d).\n", r);
  1598. }
  1599. r = amdgpu_late_init(adev);
  1600. if (r)
  1601. return r;
  1602. /* pin cursors */
  1603. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1604. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1605. if (amdgpu_crtc->cursor_bo) {
  1606. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  1607. r = amdgpu_bo_reserve(aobj, false);
  1608. if (r == 0) {
  1609. r = amdgpu_bo_pin(aobj,
  1610. AMDGPU_GEM_DOMAIN_VRAM,
  1611. &amdgpu_crtc->cursor_addr);
  1612. if (r != 0)
  1613. DRM_ERROR("Failed to pin cursor BO (%d)\n", r);
  1614. amdgpu_bo_unreserve(aobj);
  1615. }
  1616. }
  1617. }
  1618. /* blat the mode back in */
  1619. if (fbcon) {
  1620. drm_helper_resume_force_mode(dev);
  1621. /* turn on display hw */
  1622. drm_modeset_lock_all(dev);
  1623. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1624. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
  1625. }
  1626. drm_modeset_unlock_all(dev);
  1627. }
  1628. drm_kms_helper_poll_enable(dev);
  1629. drm_helper_hpd_irq_event(dev);
  1630. if (fbcon) {
  1631. amdgpu_fbdev_set_suspend(adev, 0);
  1632. console_unlock();
  1633. }
  1634. return 0;
  1635. }
  1636. /**
  1637. * amdgpu_gpu_reset - reset the asic
  1638. *
  1639. * @adev: amdgpu device pointer
  1640. *
  1641. * Attempt the reset the GPU if it has hung (all asics).
  1642. * Returns 0 for success or an error on failure.
  1643. */
  1644. int amdgpu_gpu_reset(struct amdgpu_device *adev)
  1645. {
  1646. unsigned ring_sizes[AMDGPU_MAX_RINGS];
  1647. uint32_t *ring_data[AMDGPU_MAX_RINGS];
  1648. bool saved = false;
  1649. int i, r;
  1650. int resched;
  1651. atomic_inc(&adev->gpu_reset_counter);
  1652. /* block TTM */
  1653. resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
  1654. r = amdgpu_suspend(adev);
  1655. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  1656. struct amdgpu_ring *ring = adev->rings[i];
  1657. if (!ring)
  1658. continue;
  1659. ring_sizes[i] = amdgpu_ring_backup(ring, &ring_data[i]);
  1660. if (ring_sizes[i]) {
  1661. saved = true;
  1662. dev_info(adev->dev, "Saved %d dwords of commands "
  1663. "on ring %d.\n", ring_sizes[i], i);
  1664. }
  1665. }
  1666. retry:
  1667. r = amdgpu_asic_reset(adev);
  1668. /* post card */
  1669. amdgpu_atom_asic_init(adev->mode_info.atom_context);
  1670. if (!r) {
  1671. dev_info(adev->dev, "GPU reset succeeded, trying to resume\n");
  1672. r = amdgpu_resume(adev);
  1673. }
  1674. if (!r) {
  1675. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  1676. struct amdgpu_ring *ring = adev->rings[i];
  1677. if (!ring)
  1678. continue;
  1679. amdgpu_ring_restore(ring, ring_sizes[i], ring_data[i]);
  1680. ring_sizes[i] = 0;
  1681. ring_data[i] = NULL;
  1682. }
  1683. r = amdgpu_ib_ring_tests(adev);
  1684. if (r) {
  1685. dev_err(adev->dev, "ib ring test failed (%d).\n", r);
  1686. if (saved) {
  1687. saved = false;
  1688. r = amdgpu_suspend(adev);
  1689. goto retry;
  1690. }
  1691. }
  1692. } else {
  1693. amdgpu_fence_driver_force_completion(adev);
  1694. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  1695. if (adev->rings[i])
  1696. kfree(ring_data[i]);
  1697. }
  1698. }
  1699. drm_helper_resume_force_mode(adev->ddev);
  1700. ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched);
  1701. if (r) {
  1702. /* bad news, how to tell it to userspace ? */
  1703. dev_info(adev->dev, "GPU reset failed\n");
  1704. }
  1705. return r;
  1706. }
  1707. #define AMDGPU_DEFAULT_PCIE_GEN_MASK 0x30007 /* gen: chipset 1/2, asic 1/2/3 */
  1708. #define AMDGPU_DEFAULT_PCIE_MLW_MASK 0x2f0000 /* 1/2/4/8/16 lanes */
  1709. void amdgpu_get_pcie_info(struct amdgpu_device *adev)
  1710. {
  1711. u32 mask;
  1712. int ret;
  1713. if (amdgpu_pcie_gen_cap)
  1714. adev->pm.pcie_gen_mask = amdgpu_pcie_gen_cap;
  1715. if (amdgpu_pcie_lane_cap)
  1716. adev->pm.pcie_mlw_mask = amdgpu_pcie_lane_cap;
  1717. /* covers APUs as well */
  1718. if (pci_is_root_bus(adev->pdev->bus)) {
  1719. if (adev->pm.pcie_gen_mask == 0)
  1720. adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
  1721. if (adev->pm.pcie_mlw_mask == 0)
  1722. adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
  1723. return;
  1724. }
  1725. if (adev->pm.pcie_gen_mask == 0) {
  1726. ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask);
  1727. if (!ret) {
  1728. adev->pm.pcie_gen_mask = (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
  1729. CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
  1730. CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3);
  1731. if (mask & DRM_PCIE_SPEED_25)
  1732. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1;
  1733. if (mask & DRM_PCIE_SPEED_50)
  1734. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2;
  1735. if (mask & DRM_PCIE_SPEED_80)
  1736. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3;
  1737. } else {
  1738. adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
  1739. }
  1740. }
  1741. if (adev->pm.pcie_mlw_mask == 0) {
  1742. ret = drm_pcie_get_max_link_width(adev->ddev, &mask);
  1743. if (!ret) {
  1744. switch (mask) {
  1745. case 32:
  1746. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 |
  1747. CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
  1748. CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  1749. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  1750. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  1751. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  1752. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  1753. break;
  1754. case 16:
  1755. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
  1756. CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  1757. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  1758. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  1759. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  1760. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  1761. break;
  1762. case 12:
  1763. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  1764. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  1765. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  1766. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  1767. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  1768. break;
  1769. case 8:
  1770. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  1771. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  1772. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  1773. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  1774. break;
  1775. case 4:
  1776. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  1777. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  1778. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  1779. break;
  1780. case 2:
  1781. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  1782. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  1783. break;
  1784. case 1:
  1785. adev->pm.pcie_mlw_mask = CAIL_PCIE_LINK_WIDTH_SUPPORT_X1;
  1786. break;
  1787. default:
  1788. break;
  1789. }
  1790. } else {
  1791. adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
  1792. }
  1793. }
  1794. }
  1795. /*
  1796. * Debugfs
  1797. */
  1798. int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
  1799. const struct drm_info_list *files,
  1800. unsigned nfiles)
  1801. {
  1802. unsigned i;
  1803. for (i = 0; i < adev->debugfs_count; i++) {
  1804. if (adev->debugfs[i].files == files) {
  1805. /* Already registered */
  1806. return 0;
  1807. }
  1808. }
  1809. i = adev->debugfs_count + 1;
  1810. if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) {
  1811. DRM_ERROR("Reached maximum number of debugfs components.\n");
  1812. DRM_ERROR("Report so we increase "
  1813. "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n");
  1814. return -EINVAL;
  1815. }
  1816. adev->debugfs[adev->debugfs_count].files = files;
  1817. adev->debugfs[adev->debugfs_count].num_files = nfiles;
  1818. adev->debugfs_count = i;
  1819. #if defined(CONFIG_DEBUG_FS)
  1820. drm_debugfs_create_files(files, nfiles,
  1821. adev->ddev->control->debugfs_root,
  1822. adev->ddev->control);
  1823. drm_debugfs_create_files(files, nfiles,
  1824. adev->ddev->primary->debugfs_root,
  1825. adev->ddev->primary);
  1826. #endif
  1827. return 0;
  1828. }
  1829. static void amdgpu_debugfs_remove_files(struct amdgpu_device *adev)
  1830. {
  1831. #if defined(CONFIG_DEBUG_FS)
  1832. unsigned i;
  1833. for (i = 0; i < adev->debugfs_count; i++) {
  1834. drm_debugfs_remove_files(adev->debugfs[i].files,
  1835. adev->debugfs[i].num_files,
  1836. adev->ddev->control);
  1837. drm_debugfs_remove_files(adev->debugfs[i].files,
  1838. adev->debugfs[i].num_files,
  1839. adev->ddev->primary);
  1840. }
  1841. #endif
  1842. }
  1843. #if defined(CONFIG_DEBUG_FS)
  1844. static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf,
  1845. size_t size, loff_t *pos)
  1846. {
  1847. struct amdgpu_device *adev = f->f_inode->i_private;
  1848. ssize_t result = 0;
  1849. int r;
  1850. if (size & 0x3 || *pos & 0x3)
  1851. return -EINVAL;
  1852. while (size) {
  1853. uint32_t value;
  1854. if (*pos > adev->rmmio_size)
  1855. return result;
  1856. value = RREG32(*pos >> 2);
  1857. r = put_user(value, (uint32_t *)buf);
  1858. if (r)
  1859. return r;
  1860. result += 4;
  1861. buf += 4;
  1862. *pos += 4;
  1863. size -= 4;
  1864. }
  1865. return result;
  1866. }
  1867. static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf,
  1868. size_t size, loff_t *pos)
  1869. {
  1870. struct amdgpu_device *adev = f->f_inode->i_private;
  1871. ssize_t result = 0;
  1872. int r;
  1873. if (size & 0x3 || *pos & 0x3)
  1874. return -EINVAL;
  1875. while (size) {
  1876. uint32_t value;
  1877. if (*pos > adev->rmmio_size)
  1878. return result;
  1879. r = get_user(value, (uint32_t *)buf);
  1880. if (r)
  1881. return r;
  1882. WREG32(*pos >> 2, value);
  1883. result += 4;
  1884. buf += 4;
  1885. *pos += 4;
  1886. size -= 4;
  1887. }
  1888. return result;
  1889. }
  1890. static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf,
  1891. size_t size, loff_t *pos)
  1892. {
  1893. struct amdgpu_device *adev = f->f_inode->i_private;
  1894. ssize_t result = 0;
  1895. int r;
  1896. if (size & 0x3 || *pos & 0x3)
  1897. return -EINVAL;
  1898. while (size) {
  1899. uint32_t value;
  1900. value = RREG32_PCIE(*pos >> 2);
  1901. r = put_user(value, (uint32_t *)buf);
  1902. if (r)
  1903. return r;
  1904. result += 4;
  1905. buf += 4;
  1906. *pos += 4;
  1907. size -= 4;
  1908. }
  1909. return result;
  1910. }
  1911. static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user *buf,
  1912. size_t size, loff_t *pos)
  1913. {
  1914. struct amdgpu_device *adev = f->f_inode->i_private;
  1915. ssize_t result = 0;
  1916. int r;
  1917. if (size & 0x3 || *pos & 0x3)
  1918. return -EINVAL;
  1919. while (size) {
  1920. uint32_t value;
  1921. r = get_user(value, (uint32_t *)buf);
  1922. if (r)
  1923. return r;
  1924. WREG32_PCIE(*pos >> 2, value);
  1925. result += 4;
  1926. buf += 4;
  1927. *pos += 4;
  1928. size -= 4;
  1929. }
  1930. return result;
  1931. }
  1932. static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf,
  1933. size_t size, loff_t *pos)
  1934. {
  1935. struct amdgpu_device *adev = f->f_inode->i_private;
  1936. ssize_t result = 0;
  1937. int r;
  1938. if (size & 0x3 || *pos & 0x3)
  1939. return -EINVAL;
  1940. while (size) {
  1941. uint32_t value;
  1942. value = RREG32_DIDT(*pos >> 2);
  1943. r = put_user(value, (uint32_t *)buf);
  1944. if (r)
  1945. return r;
  1946. result += 4;
  1947. buf += 4;
  1948. *pos += 4;
  1949. size -= 4;
  1950. }
  1951. return result;
  1952. }
  1953. static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user *buf,
  1954. size_t size, loff_t *pos)
  1955. {
  1956. struct amdgpu_device *adev = f->f_inode->i_private;
  1957. ssize_t result = 0;
  1958. int r;
  1959. if (size & 0x3 || *pos & 0x3)
  1960. return -EINVAL;
  1961. while (size) {
  1962. uint32_t value;
  1963. r = get_user(value, (uint32_t *)buf);
  1964. if (r)
  1965. return r;
  1966. WREG32_DIDT(*pos >> 2, value);
  1967. result += 4;
  1968. buf += 4;
  1969. *pos += 4;
  1970. size -= 4;
  1971. }
  1972. return result;
  1973. }
  1974. static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf,
  1975. size_t size, loff_t *pos)
  1976. {
  1977. struct amdgpu_device *adev = f->f_inode->i_private;
  1978. ssize_t result = 0;
  1979. int r;
  1980. if (size & 0x3 || *pos & 0x3)
  1981. return -EINVAL;
  1982. while (size) {
  1983. uint32_t value;
  1984. value = RREG32_SMC(*pos >> 2);
  1985. r = put_user(value, (uint32_t *)buf);
  1986. if (r)
  1987. return r;
  1988. result += 4;
  1989. buf += 4;
  1990. *pos += 4;
  1991. size -= 4;
  1992. }
  1993. return result;
  1994. }
  1995. static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *buf,
  1996. size_t size, loff_t *pos)
  1997. {
  1998. struct amdgpu_device *adev = f->f_inode->i_private;
  1999. ssize_t result = 0;
  2000. int r;
  2001. if (size & 0x3 || *pos & 0x3)
  2002. return -EINVAL;
  2003. while (size) {
  2004. uint32_t value;
  2005. r = get_user(value, (uint32_t *)buf);
  2006. if (r)
  2007. return r;
  2008. WREG32_SMC(*pos >> 2, value);
  2009. result += 4;
  2010. buf += 4;
  2011. *pos += 4;
  2012. size -= 4;
  2013. }
  2014. return result;
  2015. }
  2016. static const struct file_operations amdgpu_debugfs_regs_fops = {
  2017. .owner = THIS_MODULE,
  2018. .read = amdgpu_debugfs_regs_read,
  2019. .write = amdgpu_debugfs_regs_write,
  2020. .llseek = default_llseek
  2021. };
  2022. static const struct file_operations amdgpu_debugfs_regs_didt_fops = {
  2023. .owner = THIS_MODULE,
  2024. .read = amdgpu_debugfs_regs_didt_read,
  2025. .write = amdgpu_debugfs_regs_didt_write,
  2026. .llseek = default_llseek
  2027. };
  2028. static const struct file_operations amdgpu_debugfs_regs_pcie_fops = {
  2029. .owner = THIS_MODULE,
  2030. .read = amdgpu_debugfs_regs_pcie_read,
  2031. .write = amdgpu_debugfs_regs_pcie_write,
  2032. .llseek = default_llseek
  2033. };
  2034. static const struct file_operations amdgpu_debugfs_regs_smc_fops = {
  2035. .owner = THIS_MODULE,
  2036. .read = amdgpu_debugfs_regs_smc_read,
  2037. .write = amdgpu_debugfs_regs_smc_write,
  2038. .llseek = default_llseek
  2039. };
  2040. static const struct file_operations *debugfs_regs[] = {
  2041. &amdgpu_debugfs_regs_fops,
  2042. &amdgpu_debugfs_regs_didt_fops,
  2043. &amdgpu_debugfs_regs_pcie_fops,
  2044. &amdgpu_debugfs_regs_smc_fops,
  2045. };
  2046. static const char *debugfs_regs_names[] = {
  2047. "amdgpu_regs",
  2048. "amdgpu_regs_didt",
  2049. "amdgpu_regs_pcie",
  2050. "amdgpu_regs_smc",
  2051. };
  2052. static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
  2053. {
  2054. struct drm_minor *minor = adev->ddev->primary;
  2055. struct dentry *ent, *root = minor->debugfs_root;
  2056. unsigned i, j;
  2057. for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
  2058. ent = debugfs_create_file(debugfs_regs_names[i],
  2059. S_IFREG | S_IRUGO, root,
  2060. adev, debugfs_regs[i]);
  2061. if (IS_ERR(ent)) {
  2062. for (j = 0; j < i; j++) {
  2063. debugfs_remove(adev->debugfs_regs[i]);
  2064. adev->debugfs_regs[i] = NULL;
  2065. }
  2066. return PTR_ERR(ent);
  2067. }
  2068. if (!i)
  2069. i_size_write(ent->d_inode, adev->rmmio_size);
  2070. adev->debugfs_regs[i] = ent;
  2071. }
  2072. return 0;
  2073. }
  2074. static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev)
  2075. {
  2076. unsigned i;
  2077. for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
  2078. if (adev->debugfs_regs[i]) {
  2079. debugfs_remove(adev->debugfs_regs[i]);
  2080. adev->debugfs_regs[i] = NULL;
  2081. }
  2082. }
  2083. }
  2084. int amdgpu_debugfs_init(struct drm_minor *minor)
  2085. {
  2086. return 0;
  2087. }
  2088. void amdgpu_debugfs_cleanup(struct drm_minor *minor)
  2089. {
  2090. }
  2091. #else
  2092. static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
  2093. {
  2094. return 0;
  2095. }
  2096. static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev) { }
  2097. #endif