amdgpu_device.c 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849
  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/kthread.h>
  29. #include <linux/console.h>
  30. #include <linux/slab.h>
  31. #include <drm/drmP.h>
  32. #include <drm/drm_crtc_helper.h>
  33. #include <drm/drm_atomic_helper.h>
  34. #include <drm/amdgpu_drm.h>
  35. #include <linux/vgaarb.h>
  36. #include <linux/vga_switcheroo.h>
  37. #include <linux/efi.h>
  38. #include "amdgpu.h"
  39. #include "amdgpu_trace.h"
  40. #include "amdgpu_i2c.h"
  41. #include "atom.h"
  42. #include "amdgpu_atombios.h"
  43. #include "amdgpu_atomfirmware.h"
  44. #include "amd_pcie.h"
  45. #ifdef CONFIG_DRM_AMDGPU_SI
  46. #include "si.h"
  47. #endif
  48. #ifdef CONFIG_DRM_AMDGPU_CIK
  49. #include "cik.h"
  50. #endif
  51. #include "vi.h"
  52. #include "soc15.h"
  53. #include "bif/bif_4_1_d.h"
  54. #include <linux/pci.h>
  55. #include <linux/firmware.h>
  56. #include "amdgpu_vf_error.h"
  57. #include "amdgpu_amdkfd.h"
  58. #include "amdgpu_pm.h"
  59. MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin");
  60. MODULE_FIRMWARE("amdgpu/raven_gpu_info.bin");
  61. #define AMDGPU_RESUME_MS 2000
  62. static const char *amdgpu_asic_name[] = {
  63. "TAHITI",
  64. "PITCAIRN",
  65. "VERDE",
  66. "OLAND",
  67. "HAINAN",
  68. "BONAIRE",
  69. "KAVERI",
  70. "KABINI",
  71. "HAWAII",
  72. "MULLINS",
  73. "TOPAZ",
  74. "TONGA",
  75. "FIJI",
  76. "CARRIZO",
  77. "STONEY",
  78. "POLARIS10",
  79. "POLARIS11",
  80. "POLARIS12",
  81. "VEGA10",
  82. "RAVEN",
  83. "LAST",
  84. };
  85. bool amdgpu_device_is_px(struct drm_device *dev)
  86. {
  87. struct amdgpu_device *adev = dev->dev_private;
  88. if (adev->flags & AMD_IS_PX)
  89. return true;
  90. return false;
  91. }
  92. /*
  93. * MMIO register access helper functions.
  94. */
  95. uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
  96. uint32_t acc_flags)
  97. {
  98. uint32_t ret;
  99. if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
  100. return amdgpu_virt_kiq_rreg(adev, reg);
  101. if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
  102. ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
  103. else {
  104. unsigned long flags;
  105. spin_lock_irqsave(&adev->mmio_idx_lock, flags);
  106. writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
  107. ret = readl(((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
  108. spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
  109. }
  110. trace_amdgpu_mm_rreg(adev->pdev->device, reg, ret);
  111. return ret;
  112. }
  113. void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
  114. uint32_t acc_flags)
  115. {
  116. trace_amdgpu_mm_wreg(adev->pdev->device, reg, v);
  117. if (adev->asic_type >= CHIP_VEGA10 && reg == 0) {
  118. adev->last_mm_index = v;
  119. }
  120. if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
  121. return amdgpu_virt_kiq_wreg(adev, reg, v);
  122. if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
  123. writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
  124. else {
  125. unsigned long flags;
  126. spin_lock_irqsave(&adev->mmio_idx_lock, flags);
  127. writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
  128. writel(v, ((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
  129. spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
  130. }
  131. if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) {
  132. udelay(500);
  133. }
  134. }
  135. u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg)
  136. {
  137. if ((reg * 4) < adev->rio_mem_size)
  138. return ioread32(adev->rio_mem + (reg * 4));
  139. else {
  140. iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
  141. return ioread32(adev->rio_mem + (mmMM_DATA * 4));
  142. }
  143. }
  144. void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  145. {
  146. if (adev->asic_type >= CHIP_VEGA10 && reg == 0) {
  147. adev->last_mm_index = v;
  148. }
  149. if ((reg * 4) < adev->rio_mem_size)
  150. iowrite32(v, adev->rio_mem + (reg * 4));
  151. else {
  152. iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
  153. iowrite32(v, adev->rio_mem + (mmMM_DATA * 4));
  154. }
  155. if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) {
  156. udelay(500);
  157. }
  158. }
  159. /**
  160. * amdgpu_mm_rdoorbell - read a doorbell dword
  161. *
  162. * @adev: amdgpu_device pointer
  163. * @index: doorbell index
  164. *
  165. * Returns the value in the doorbell aperture at the
  166. * requested doorbell index (CIK).
  167. */
  168. u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index)
  169. {
  170. if (index < adev->doorbell.num_doorbells) {
  171. return readl(adev->doorbell.ptr + index);
  172. } else {
  173. DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
  174. return 0;
  175. }
  176. }
  177. /**
  178. * amdgpu_mm_wdoorbell - write a doorbell dword
  179. *
  180. * @adev: amdgpu_device pointer
  181. * @index: doorbell index
  182. * @v: value to write
  183. *
  184. * Writes @v to the doorbell aperture at the
  185. * requested doorbell index (CIK).
  186. */
  187. void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v)
  188. {
  189. if (index < adev->doorbell.num_doorbells) {
  190. writel(v, adev->doorbell.ptr + index);
  191. } else {
  192. DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
  193. }
  194. }
  195. /**
  196. * amdgpu_mm_rdoorbell64 - read a doorbell Qword
  197. *
  198. * @adev: amdgpu_device pointer
  199. * @index: doorbell index
  200. *
  201. * Returns the value in the doorbell aperture at the
  202. * requested doorbell index (VEGA10+).
  203. */
  204. u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index)
  205. {
  206. if (index < adev->doorbell.num_doorbells) {
  207. return atomic64_read((atomic64_t *)(adev->doorbell.ptr + index));
  208. } else {
  209. DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
  210. return 0;
  211. }
  212. }
  213. /**
  214. * amdgpu_mm_wdoorbell64 - write a doorbell Qword
  215. *
  216. * @adev: amdgpu_device pointer
  217. * @index: doorbell index
  218. * @v: value to write
  219. *
  220. * Writes @v to the doorbell aperture at the
  221. * requested doorbell index (VEGA10+).
  222. */
  223. void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v)
  224. {
  225. if (index < adev->doorbell.num_doorbells) {
  226. atomic64_set((atomic64_t *)(adev->doorbell.ptr + index), v);
  227. } else {
  228. DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
  229. }
  230. }
  231. /**
  232. * amdgpu_invalid_rreg - dummy reg read function
  233. *
  234. * @adev: amdgpu device pointer
  235. * @reg: offset of register
  236. *
  237. * Dummy register read function. Used for register blocks
  238. * that certain asics don't have (all asics).
  239. * Returns the value in the register.
  240. */
  241. static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg)
  242. {
  243. DRM_ERROR("Invalid callback to read register 0x%04X\n", reg);
  244. BUG();
  245. return 0;
  246. }
  247. /**
  248. * amdgpu_invalid_wreg - dummy reg write function
  249. *
  250. * @adev: amdgpu device pointer
  251. * @reg: offset of register
  252. * @v: value to write to the register
  253. *
  254. * Dummy register read function. Used for register blocks
  255. * that certain asics don't have (all asics).
  256. */
  257. static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
  258. {
  259. DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n",
  260. reg, v);
  261. BUG();
  262. }
  263. /**
  264. * amdgpu_block_invalid_rreg - dummy reg read function
  265. *
  266. * @adev: amdgpu device pointer
  267. * @block: offset of instance
  268. * @reg: offset of register
  269. *
  270. * Dummy register read function. Used for register blocks
  271. * that certain asics don't have (all asics).
  272. * Returns the value in the register.
  273. */
  274. static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev,
  275. uint32_t block, uint32_t reg)
  276. {
  277. DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n",
  278. reg, block);
  279. BUG();
  280. return 0;
  281. }
  282. /**
  283. * amdgpu_block_invalid_wreg - dummy reg write function
  284. *
  285. * @adev: amdgpu device pointer
  286. * @block: offset of instance
  287. * @reg: offset of register
  288. * @v: value to write to the register
  289. *
  290. * Dummy register read function. Used for register blocks
  291. * that certain asics don't have (all asics).
  292. */
  293. static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev,
  294. uint32_t block,
  295. uint32_t reg, uint32_t v)
  296. {
  297. DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n",
  298. reg, block, v);
  299. BUG();
  300. }
  301. static int amdgpu_device_vram_scratch_init(struct amdgpu_device *adev)
  302. {
  303. return amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE,
  304. PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
  305. &adev->vram_scratch.robj,
  306. &adev->vram_scratch.gpu_addr,
  307. (void **)&adev->vram_scratch.ptr);
  308. }
  309. static void amdgpu_device_vram_scratch_fini(struct amdgpu_device *adev)
  310. {
  311. amdgpu_bo_free_kernel(&adev->vram_scratch.robj, NULL, NULL);
  312. }
  313. /**
  314. * amdgpu_device_program_register_sequence - program an array of registers.
  315. *
  316. * @adev: amdgpu_device pointer
  317. * @registers: pointer to the register array
  318. * @array_size: size of the register array
  319. *
  320. * Programs an array or registers with and and or masks.
  321. * This is a helper for setting golden registers.
  322. */
  323. void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
  324. const u32 *registers,
  325. const u32 array_size)
  326. {
  327. u32 tmp, reg, and_mask, or_mask;
  328. int i;
  329. if (array_size % 3)
  330. return;
  331. for (i = 0; i < array_size; i +=3) {
  332. reg = registers[i + 0];
  333. and_mask = registers[i + 1];
  334. or_mask = registers[i + 2];
  335. if (and_mask == 0xffffffff) {
  336. tmp = or_mask;
  337. } else {
  338. tmp = RREG32(reg);
  339. tmp &= ~and_mask;
  340. tmp |= or_mask;
  341. }
  342. WREG32(reg, tmp);
  343. }
  344. }
  345. void amdgpu_device_pci_config_reset(struct amdgpu_device *adev)
  346. {
  347. pci_write_config_dword(adev->pdev, 0x7c, AMDGPU_ASIC_RESET_DATA);
  348. }
  349. /*
  350. * GPU doorbell aperture helpers function.
  351. */
  352. /**
  353. * amdgpu_device_doorbell_init - Init doorbell driver information.
  354. *
  355. * @adev: amdgpu_device pointer
  356. *
  357. * Init doorbell driver information (CIK)
  358. * Returns 0 on success, error on failure.
  359. */
  360. static int amdgpu_device_doorbell_init(struct amdgpu_device *adev)
  361. {
  362. /* No doorbell on SI hardware generation */
  363. if (adev->asic_type < CHIP_BONAIRE) {
  364. adev->doorbell.base = 0;
  365. adev->doorbell.size = 0;
  366. adev->doorbell.num_doorbells = 0;
  367. adev->doorbell.ptr = NULL;
  368. return 0;
  369. }
  370. if (pci_resource_flags(adev->pdev, 2) & IORESOURCE_UNSET)
  371. return -EINVAL;
  372. /* doorbell bar mapping */
  373. adev->doorbell.base = pci_resource_start(adev->pdev, 2);
  374. adev->doorbell.size = pci_resource_len(adev->pdev, 2);
  375. adev->doorbell.num_doorbells = min_t(u32, adev->doorbell.size / sizeof(u32),
  376. AMDGPU_DOORBELL_MAX_ASSIGNMENT+1);
  377. if (adev->doorbell.num_doorbells == 0)
  378. return -EINVAL;
  379. adev->doorbell.ptr = ioremap(adev->doorbell.base,
  380. adev->doorbell.num_doorbells *
  381. sizeof(u32));
  382. if (adev->doorbell.ptr == NULL)
  383. return -ENOMEM;
  384. return 0;
  385. }
  386. /**
  387. * amdgpu_device_doorbell_fini - Tear down doorbell driver information.
  388. *
  389. * @adev: amdgpu_device pointer
  390. *
  391. * Tear down doorbell driver information (CIK)
  392. */
  393. static void amdgpu_device_doorbell_fini(struct amdgpu_device *adev)
  394. {
  395. iounmap(adev->doorbell.ptr);
  396. adev->doorbell.ptr = NULL;
  397. }
  398. /*
  399. * amdgpu_device_wb_*()
  400. * Writeback is the method by which the GPU updates special pages in memory
  401. * with the status of certain GPU events (fences, ring pointers,etc.).
  402. */
  403. /**
  404. * amdgpu_device_wb_fini - Disable Writeback and free memory
  405. *
  406. * @adev: amdgpu_device pointer
  407. *
  408. * Disables Writeback and frees the Writeback memory (all asics).
  409. * Used at driver shutdown.
  410. */
  411. static void amdgpu_device_wb_fini(struct amdgpu_device *adev)
  412. {
  413. if (adev->wb.wb_obj) {
  414. amdgpu_bo_free_kernel(&adev->wb.wb_obj,
  415. &adev->wb.gpu_addr,
  416. (void **)&adev->wb.wb);
  417. adev->wb.wb_obj = NULL;
  418. }
  419. }
  420. /**
  421. * amdgpu_device_wb_init- Init Writeback driver info and allocate memory
  422. *
  423. * @adev: amdgpu_device pointer
  424. *
  425. * Initializes writeback and allocates writeback memory (all asics).
  426. * Used at driver startup.
  427. * Returns 0 on success or an -error on failure.
  428. */
  429. static int amdgpu_device_wb_init(struct amdgpu_device *adev)
  430. {
  431. int r;
  432. if (adev->wb.wb_obj == NULL) {
  433. /* AMDGPU_MAX_WB * sizeof(uint32_t) * 8 = AMDGPU_MAX_WB 256bit slots */
  434. r = amdgpu_bo_create_kernel(adev, AMDGPU_MAX_WB * sizeof(uint32_t) * 8,
  435. PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
  436. &adev->wb.wb_obj, &adev->wb.gpu_addr,
  437. (void **)&adev->wb.wb);
  438. if (r) {
  439. dev_warn(adev->dev, "(%d) create WB bo failed\n", r);
  440. return r;
  441. }
  442. adev->wb.num_wb = AMDGPU_MAX_WB;
  443. memset(&adev->wb.used, 0, sizeof(adev->wb.used));
  444. /* clear wb memory */
  445. memset((char *)adev->wb.wb, 0, AMDGPU_MAX_WB * sizeof(uint32_t) * 8);
  446. }
  447. return 0;
  448. }
  449. /**
  450. * amdgpu_device_wb_get - Allocate a wb entry
  451. *
  452. * @adev: amdgpu_device pointer
  453. * @wb: wb index
  454. *
  455. * Allocate a wb slot for use by the driver (all asics).
  456. * Returns 0 on success or -EINVAL on failure.
  457. */
  458. int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb)
  459. {
  460. unsigned long offset = find_first_zero_bit(adev->wb.used, adev->wb.num_wb);
  461. if (offset < adev->wb.num_wb) {
  462. __set_bit(offset, adev->wb.used);
  463. *wb = offset << 3; /* convert to dw offset */
  464. return 0;
  465. } else {
  466. return -EINVAL;
  467. }
  468. }
  469. /**
  470. * amdgpu_device_wb_free - Free a wb entry
  471. *
  472. * @adev: amdgpu_device pointer
  473. * @wb: wb index
  474. *
  475. * Free a wb slot allocated for use by the driver (all asics)
  476. */
  477. void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb)
  478. {
  479. wb >>= 3;
  480. if (wb < adev->wb.num_wb)
  481. __clear_bit(wb, adev->wb.used);
  482. }
  483. /**
  484. * amdgpu_device_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 try to place VRAM at base address provided
  490. * as parameter.
  491. */
  492. void amdgpu_device_vram_location(struct amdgpu_device *adev,
  493. struct amdgpu_gmc *mc, u64 base)
  494. {
  495. uint64_t limit = (uint64_t)amdgpu_vram_limit << 20;
  496. mc->vram_start = base;
  497. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  498. if (limit && limit < mc->real_vram_size)
  499. mc->real_vram_size = limit;
  500. dev_info(adev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
  501. mc->mc_vram_size >> 20, mc->vram_start,
  502. mc->vram_end, mc->real_vram_size >> 20);
  503. }
  504. /**
  505. * amdgpu_device_gart_location - try to find GTT location
  506. * @adev: amdgpu device structure holding all necessary informations
  507. * @mc: memory controller structure holding memory informations
  508. *
  509. * Function will place try to place GTT before or after VRAM.
  510. *
  511. * If GTT size is bigger than space left then we ajust GTT size.
  512. * Thus function will never fails.
  513. *
  514. * FIXME: when reducing GTT size align new size on power of 2.
  515. */
  516. void amdgpu_device_gart_location(struct amdgpu_device *adev,
  517. struct amdgpu_gmc *mc)
  518. {
  519. u64 size_af, size_bf;
  520. size_af = adev->gmc.mc_mask - mc->vram_end;
  521. size_bf = mc->vram_start;
  522. if (size_bf > size_af) {
  523. if (mc->gart_size > size_bf) {
  524. dev_warn(adev->dev, "limiting GTT\n");
  525. mc->gart_size = size_bf;
  526. }
  527. mc->gart_start = 0;
  528. } else {
  529. if (mc->gart_size > size_af) {
  530. dev_warn(adev->dev, "limiting GTT\n");
  531. mc->gart_size = size_af;
  532. }
  533. /* VCE doesn't like it when BOs cross a 4GB segment, so align
  534. * the GART base on a 4GB boundary as well.
  535. */
  536. mc->gart_start = ALIGN(mc->vram_end + 1, 0x100000000ULL);
  537. }
  538. mc->gart_end = mc->gart_start + mc->gart_size - 1;
  539. dev_info(adev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
  540. mc->gart_size >> 20, mc->gart_start, mc->gart_end);
  541. }
  542. /**
  543. * amdgpu_device_resize_fb_bar - try to resize FB BAR
  544. *
  545. * @adev: amdgpu_device pointer
  546. *
  547. * Try to resize FB BAR to make all VRAM CPU accessible. We try very hard not
  548. * to fail, but if any of the BARs is not accessible after the size we abort
  549. * driver loading by returning -ENODEV.
  550. */
  551. int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
  552. {
  553. u64 space_needed = roundup_pow_of_two(adev->gmc.real_vram_size);
  554. u32 rbar_size = order_base_2(((space_needed >> 20) | 1)) - 1;
  555. struct pci_bus *root;
  556. struct resource *res;
  557. unsigned i;
  558. u16 cmd;
  559. int r;
  560. /* Bypass for VF */
  561. if (amdgpu_sriov_vf(adev))
  562. return 0;
  563. /* Check if the root BUS has 64bit memory resources */
  564. root = adev->pdev->bus;
  565. while (root->parent)
  566. root = root->parent;
  567. pci_bus_for_each_resource(root, res, i) {
  568. if (res && res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
  569. res->start > 0x100000000ull)
  570. break;
  571. }
  572. /* Trying to resize is pointless without a root hub window above 4GB */
  573. if (!res)
  574. return 0;
  575. /* Disable memory decoding while we change the BAR addresses and size */
  576. pci_read_config_word(adev->pdev, PCI_COMMAND, &cmd);
  577. pci_write_config_word(adev->pdev, PCI_COMMAND,
  578. cmd & ~PCI_COMMAND_MEMORY);
  579. /* Free the VRAM and doorbell BAR, we most likely need to move both. */
  580. amdgpu_device_doorbell_fini(adev);
  581. if (adev->asic_type >= CHIP_BONAIRE)
  582. pci_release_resource(adev->pdev, 2);
  583. pci_release_resource(adev->pdev, 0);
  584. r = pci_resize_resource(adev->pdev, 0, rbar_size);
  585. if (r == -ENOSPC)
  586. DRM_INFO("Not enough PCI address space for a large BAR.");
  587. else if (r && r != -ENOTSUPP)
  588. DRM_ERROR("Problem resizing BAR0 (%d).", r);
  589. pci_assign_unassigned_bus_resources(adev->pdev->bus);
  590. /* When the doorbell or fb BAR isn't available we have no chance of
  591. * using the device.
  592. */
  593. r = amdgpu_device_doorbell_init(adev);
  594. if (r || (pci_resource_flags(adev->pdev, 0) & IORESOURCE_UNSET))
  595. return -ENODEV;
  596. pci_write_config_word(adev->pdev, PCI_COMMAND, cmd);
  597. return 0;
  598. }
  599. /*
  600. * GPU helpers function.
  601. */
  602. /**
  603. * amdgpu_device_need_post - check if the hw need post or not
  604. *
  605. * @adev: amdgpu_device pointer
  606. *
  607. * Check if the asic has been initialized (all asics) at driver startup
  608. * or post is needed if hw reset is performed.
  609. * Returns true if need or false if not.
  610. */
  611. bool amdgpu_device_need_post(struct amdgpu_device *adev)
  612. {
  613. uint32_t reg;
  614. if (amdgpu_sriov_vf(adev))
  615. return false;
  616. if (amdgpu_passthrough(adev)) {
  617. /* for FIJI: In whole GPU pass-through virtualization case, after VM reboot
  618. * some old smc fw still need driver do vPost otherwise gpu hang, while
  619. * those smc fw version above 22.15 doesn't have this flaw, so we force
  620. * vpost executed for smc version below 22.15
  621. */
  622. if (adev->asic_type == CHIP_FIJI) {
  623. int err;
  624. uint32_t fw_ver;
  625. err = request_firmware(&adev->pm.fw, "amdgpu/fiji_smc.bin", adev->dev);
  626. /* force vPost if error occured */
  627. if (err)
  628. return true;
  629. fw_ver = *((uint32_t *)adev->pm.fw->data + 69);
  630. if (fw_ver < 0x00160e00)
  631. return true;
  632. }
  633. }
  634. if (adev->has_hw_reset) {
  635. adev->has_hw_reset = false;
  636. return true;
  637. }
  638. /* bios scratch used on CIK+ */
  639. if (adev->asic_type >= CHIP_BONAIRE)
  640. return amdgpu_atombios_scratch_need_asic_init(adev);
  641. /* check MEM_SIZE for older asics */
  642. reg = amdgpu_asic_get_config_memsize(adev);
  643. if ((reg != 0) && (reg != 0xffffffff))
  644. return false;
  645. return true;
  646. }
  647. /* if we get transitioned to only one device, take VGA back */
  648. /**
  649. * amdgpu_device_vga_set_decode - enable/disable vga decode
  650. *
  651. * @cookie: amdgpu_device pointer
  652. * @state: enable/disable vga decode
  653. *
  654. * Enable/disable vga decode (all asics).
  655. * Returns VGA resource flags.
  656. */
  657. static unsigned int amdgpu_device_vga_set_decode(void *cookie, bool state)
  658. {
  659. struct amdgpu_device *adev = cookie;
  660. amdgpu_asic_set_vga_state(adev, state);
  661. if (state)
  662. return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
  663. VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  664. else
  665. return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  666. }
  667. static void amdgpu_device_check_block_size(struct amdgpu_device *adev)
  668. {
  669. /* defines number of bits in page table versus page directory,
  670. * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
  671. * page table and the remaining bits are in the page directory */
  672. if (amdgpu_vm_block_size == -1)
  673. return;
  674. if (amdgpu_vm_block_size < 9) {
  675. dev_warn(adev->dev, "VM page table size (%d) too small\n",
  676. amdgpu_vm_block_size);
  677. amdgpu_vm_block_size = -1;
  678. }
  679. }
  680. static void amdgpu_device_check_vm_size(struct amdgpu_device *adev)
  681. {
  682. /* no need to check the default value */
  683. if (amdgpu_vm_size == -1)
  684. return;
  685. if (amdgpu_vm_size < 1) {
  686. dev_warn(adev->dev, "VM size (%d) too small, min is 1GB\n",
  687. amdgpu_vm_size);
  688. amdgpu_vm_size = -1;
  689. }
  690. }
  691. /**
  692. * amdgpu_device_check_arguments - validate module params
  693. *
  694. * @adev: amdgpu_device pointer
  695. *
  696. * Validates certain module parameters and updates
  697. * the associated values used by the driver (all asics).
  698. */
  699. static void amdgpu_device_check_arguments(struct amdgpu_device *adev)
  700. {
  701. if (amdgpu_sched_jobs < 4) {
  702. dev_warn(adev->dev, "sched jobs (%d) must be at least 4\n",
  703. amdgpu_sched_jobs);
  704. amdgpu_sched_jobs = 4;
  705. } else if (!is_power_of_2(amdgpu_sched_jobs)){
  706. dev_warn(adev->dev, "sched jobs (%d) must be a power of 2\n",
  707. amdgpu_sched_jobs);
  708. amdgpu_sched_jobs = roundup_pow_of_two(amdgpu_sched_jobs);
  709. }
  710. if (amdgpu_gart_size != -1 && amdgpu_gart_size < 32) {
  711. /* gart size must be greater or equal to 32M */
  712. dev_warn(adev->dev, "gart size (%d) too small\n",
  713. amdgpu_gart_size);
  714. amdgpu_gart_size = -1;
  715. }
  716. if (amdgpu_gtt_size != -1 && amdgpu_gtt_size < 32) {
  717. /* gtt size must be greater or equal to 32M */
  718. dev_warn(adev->dev, "gtt size (%d) too small\n",
  719. amdgpu_gtt_size);
  720. amdgpu_gtt_size = -1;
  721. }
  722. /* valid range is between 4 and 9 inclusive */
  723. if (amdgpu_vm_fragment_size != -1 &&
  724. (amdgpu_vm_fragment_size > 9 || amdgpu_vm_fragment_size < 4)) {
  725. dev_warn(adev->dev, "valid range is between 4 and 9\n");
  726. amdgpu_vm_fragment_size = -1;
  727. }
  728. amdgpu_device_check_vm_size(adev);
  729. amdgpu_device_check_block_size(adev);
  730. if (amdgpu_vram_page_split != -1 && (amdgpu_vram_page_split < 16 ||
  731. !is_power_of_2(amdgpu_vram_page_split))) {
  732. dev_warn(adev->dev, "invalid VRAM page split (%d)\n",
  733. amdgpu_vram_page_split);
  734. amdgpu_vram_page_split = 1024;
  735. }
  736. if (amdgpu_lockup_timeout == 0) {
  737. dev_warn(adev->dev, "lockup_timeout msut be > 0, adjusting to 10000\n");
  738. amdgpu_lockup_timeout = 10000;
  739. }
  740. }
  741. /**
  742. * amdgpu_switcheroo_set_state - set switcheroo state
  743. *
  744. * @pdev: pci dev pointer
  745. * @state: vga_switcheroo state
  746. *
  747. * Callback for the switcheroo driver. Suspends or resumes the
  748. * the asics before or after it is powered up using ACPI methods.
  749. */
  750. static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
  751. {
  752. struct drm_device *dev = pci_get_drvdata(pdev);
  753. if (amdgpu_device_is_px(dev) && state == VGA_SWITCHEROO_OFF)
  754. return;
  755. if (state == VGA_SWITCHEROO_ON) {
  756. pr_info("amdgpu: switched on\n");
  757. /* don't suspend or resume card normally */
  758. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  759. amdgpu_device_resume(dev, true, true);
  760. dev->switch_power_state = DRM_SWITCH_POWER_ON;
  761. drm_kms_helper_poll_enable(dev);
  762. } else {
  763. pr_info("amdgpu: switched off\n");
  764. drm_kms_helper_poll_disable(dev);
  765. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  766. amdgpu_device_suspend(dev, true, true);
  767. dev->switch_power_state = DRM_SWITCH_POWER_OFF;
  768. }
  769. }
  770. /**
  771. * amdgpu_switcheroo_can_switch - see if switcheroo state can change
  772. *
  773. * @pdev: pci dev pointer
  774. *
  775. * Callback for the switcheroo driver. Check of the switcheroo
  776. * state can be changed.
  777. * Returns true if the state can be changed, false if not.
  778. */
  779. static bool amdgpu_switcheroo_can_switch(struct pci_dev *pdev)
  780. {
  781. struct drm_device *dev = pci_get_drvdata(pdev);
  782. /*
  783. * FIXME: open_count is protected by drm_global_mutex but that would lead to
  784. * locking inversion with the driver load path. And the access here is
  785. * completely racy anyway. So don't bother with locking for now.
  786. */
  787. return dev->open_count == 0;
  788. }
  789. static const struct vga_switcheroo_client_ops amdgpu_switcheroo_ops = {
  790. .set_gpu_state = amdgpu_switcheroo_set_state,
  791. .reprobe = NULL,
  792. .can_switch = amdgpu_switcheroo_can_switch,
  793. };
  794. int amdgpu_device_ip_set_clockgating_state(struct amdgpu_device *adev,
  795. enum amd_ip_block_type block_type,
  796. enum amd_clockgating_state state)
  797. {
  798. int i, r = 0;
  799. for (i = 0; i < adev->num_ip_blocks; i++) {
  800. if (!adev->ip_blocks[i].status.valid)
  801. continue;
  802. if (adev->ip_blocks[i].version->type != block_type)
  803. continue;
  804. if (!adev->ip_blocks[i].version->funcs->set_clockgating_state)
  805. continue;
  806. r = adev->ip_blocks[i].version->funcs->set_clockgating_state(
  807. (void *)adev, state);
  808. if (r)
  809. DRM_ERROR("set_clockgating_state of IP block <%s> failed %d\n",
  810. adev->ip_blocks[i].version->funcs->name, r);
  811. }
  812. return r;
  813. }
  814. int amdgpu_device_ip_set_powergating_state(struct amdgpu_device *adev,
  815. enum amd_ip_block_type block_type,
  816. enum amd_powergating_state state)
  817. {
  818. int i, r = 0;
  819. for (i = 0; i < adev->num_ip_blocks; i++) {
  820. if (!adev->ip_blocks[i].status.valid)
  821. continue;
  822. if (adev->ip_blocks[i].version->type != block_type)
  823. continue;
  824. if (!adev->ip_blocks[i].version->funcs->set_powergating_state)
  825. continue;
  826. r = adev->ip_blocks[i].version->funcs->set_powergating_state(
  827. (void *)adev, state);
  828. if (r)
  829. DRM_ERROR("set_powergating_state of IP block <%s> failed %d\n",
  830. adev->ip_blocks[i].version->funcs->name, r);
  831. }
  832. return r;
  833. }
  834. void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
  835. u32 *flags)
  836. {
  837. int i;
  838. for (i = 0; i < adev->num_ip_blocks; i++) {
  839. if (!adev->ip_blocks[i].status.valid)
  840. continue;
  841. if (adev->ip_blocks[i].version->funcs->get_clockgating_state)
  842. adev->ip_blocks[i].version->funcs->get_clockgating_state((void *)adev, flags);
  843. }
  844. }
  845. int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
  846. enum amd_ip_block_type block_type)
  847. {
  848. int i, r;
  849. for (i = 0; i < adev->num_ip_blocks; i++) {
  850. if (!adev->ip_blocks[i].status.valid)
  851. continue;
  852. if (adev->ip_blocks[i].version->type == block_type) {
  853. r = adev->ip_blocks[i].version->funcs->wait_for_idle((void *)adev);
  854. if (r)
  855. return r;
  856. break;
  857. }
  858. }
  859. return 0;
  860. }
  861. bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
  862. enum amd_ip_block_type block_type)
  863. {
  864. int i;
  865. for (i = 0; i < adev->num_ip_blocks; i++) {
  866. if (!adev->ip_blocks[i].status.valid)
  867. continue;
  868. if (adev->ip_blocks[i].version->type == block_type)
  869. return adev->ip_blocks[i].version->funcs->is_idle((void *)adev);
  870. }
  871. return true;
  872. }
  873. struct amdgpu_ip_block *
  874. amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
  875. enum amd_ip_block_type type)
  876. {
  877. int i;
  878. for (i = 0; i < adev->num_ip_blocks; i++)
  879. if (adev->ip_blocks[i].version->type == type)
  880. return &adev->ip_blocks[i];
  881. return NULL;
  882. }
  883. /**
  884. * amdgpu_device_ip_block_version_cmp
  885. *
  886. * @adev: amdgpu_device pointer
  887. * @type: enum amd_ip_block_type
  888. * @major: major version
  889. * @minor: minor version
  890. *
  891. * return 0 if equal or greater
  892. * return 1 if smaller or the ip_block doesn't exist
  893. */
  894. int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
  895. enum amd_ip_block_type type,
  896. u32 major, u32 minor)
  897. {
  898. struct amdgpu_ip_block *ip_block = amdgpu_device_ip_get_ip_block(adev, type);
  899. if (ip_block && ((ip_block->version->major > major) ||
  900. ((ip_block->version->major == major) &&
  901. (ip_block->version->minor >= minor))))
  902. return 0;
  903. return 1;
  904. }
  905. /**
  906. * amdgpu_device_ip_block_add
  907. *
  908. * @adev: amdgpu_device pointer
  909. * @ip_block_version: pointer to the IP to add
  910. *
  911. * Adds the IP block driver information to the collection of IPs
  912. * on the asic.
  913. */
  914. int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
  915. const struct amdgpu_ip_block_version *ip_block_version)
  916. {
  917. if (!ip_block_version)
  918. return -EINVAL;
  919. DRM_INFO("add ip block number %d <%s>\n", adev->num_ip_blocks,
  920. ip_block_version->funcs->name);
  921. adev->ip_blocks[adev->num_ip_blocks++].version = ip_block_version;
  922. return 0;
  923. }
  924. static void amdgpu_device_enable_virtual_display(struct amdgpu_device *adev)
  925. {
  926. adev->enable_virtual_display = false;
  927. if (amdgpu_virtual_display) {
  928. struct drm_device *ddev = adev->ddev;
  929. const char *pci_address_name = pci_name(ddev->pdev);
  930. char *pciaddstr, *pciaddstr_tmp, *pciaddname_tmp, *pciaddname;
  931. pciaddstr = kstrdup(amdgpu_virtual_display, GFP_KERNEL);
  932. pciaddstr_tmp = pciaddstr;
  933. while ((pciaddname_tmp = strsep(&pciaddstr_tmp, ";"))) {
  934. pciaddname = strsep(&pciaddname_tmp, ",");
  935. if (!strcmp("all", pciaddname)
  936. || !strcmp(pci_address_name, pciaddname)) {
  937. long num_crtc;
  938. int res = -1;
  939. adev->enable_virtual_display = true;
  940. if (pciaddname_tmp)
  941. res = kstrtol(pciaddname_tmp, 10,
  942. &num_crtc);
  943. if (!res) {
  944. if (num_crtc < 1)
  945. num_crtc = 1;
  946. if (num_crtc > 6)
  947. num_crtc = 6;
  948. adev->mode_info.num_crtc = num_crtc;
  949. } else {
  950. adev->mode_info.num_crtc = 1;
  951. }
  952. break;
  953. }
  954. }
  955. DRM_INFO("virtual display string:%s, %s:virtual_display:%d, num_crtc:%d\n",
  956. amdgpu_virtual_display, pci_address_name,
  957. adev->enable_virtual_display, adev->mode_info.num_crtc);
  958. kfree(pciaddstr);
  959. }
  960. }
  961. static int amdgpu_device_parse_gpu_info_fw(struct amdgpu_device *adev)
  962. {
  963. const char *chip_name;
  964. char fw_name[30];
  965. int err;
  966. const struct gpu_info_firmware_header_v1_0 *hdr;
  967. adev->firmware.gpu_info_fw = NULL;
  968. switch (adev->asic_type) {
  969. case CHIP_TOPAZ:
  970. case CHIP_TONGA:
  971. case CHIP_FIJI:
  972. case CHIP_POLARIS11:
  973. case CHIP_POLARIS10:
  974. case CHIP_POLARIS12:
  975. case CHIP_CARRIZO:
  976. case CHIP_STONEY:
  977. #ifdef CONFIG_DRM_AMDGPU_SI
  978. case CHIP_VERDE:
  979. case CHIP_TAHITI:
  980. case CHIP_PITCAIRN:
  981. case CHIP_OLAND:
  982. case CHIP_HAINAN:
  983. #endif
  984. #ifdef CONFIG_DRM_AMDGPU_CIK
  985. case CHIP_BONAIRE:
  986. case CHIP_HAWAII:
  987. case CHIP_KAVERI:
  988. case CHIP_KABINI:
  989. case CHIP_MULLINS:
  990. #endif
  991. default:
  992. return 0;
  993. case CHIP_VEGA10:
  994. chip_name = "vega10";
  995. break;
  996. case CHIP_RAVEN:
  997. chip_name = "raven";
  998. break;
  999. }
  1000. snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_gpu_info.bin", chip_name);
  1001. err = request_firmware(&adev->firmware.gpu_info_fw, fw_name, adev->dev);
  1002. if (err) {
  1003. dev_err(adev->dev,
  1004. "Failed to load gpu_info firmware \"%s\"\n",
  1005. fw_name);
  1006. goto out;
  1007. }
  1008. err = amdgpu_ucode_validate(adev->firmware.gpu_info_fw);
  1009. if (err) {
  1010. dev_err(adev->dev,
  1011. "Failed to validate gpu_info firmware \"%s\"\n",
  1012. fw_name);
  1013. goto out;
  1014. }
  1015. hdr = (const struct gpu_info_firmware_header_v1_0 *)adev->firmware.gpu_info_fw->data;
  1016. amdgpu_ucode_print_gpu_info_hdr(&hdr->header);
  1017. switch (hdr->version_major) {
  1018. case 1:
  1019. {
  1020. const struct gpu_info_firmware_v1_0 *gpu_info_fw =
  1021. (const struct gpu_info_firmware_v1_0 *)(adev->firmware.gpu_info_fw->data +
  1022. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  1023. adev->gfx.config.max_shader_engines = le32_to_cpu(gpu_info_fw->gc_num_se);
  1024. adev->gfx.config.max_cu_per_sh = le32_to_cpu(gpu_info_fw->gc_num_cu_per_sh);
  1025. adev->gfx.config.max_sh_per_se = le32_to_cpu(gpu_info_fw->gc_num_sh_per_se);
  1026. adev->gfx.config.max_backends_per_se = le32_to_cpu(gpu_info_fw->gc_num_rb_per_se);
  1027. adev->gfx.config.max_texture_channel_caches =
  1028. le32_to_cpu(gpu_info_fw->gc_num_tccs);
  1029. adev->gfx.config.max_gprs = le32_to_cpu(gpu_info_fw->gc_num_gprs);
  1030. adev->gfx.config.max_gs_threads = le32_to_cpu(gpu_info_fw->gc_num_max_gs_thds);
  1031. adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gpu_info_fw->gc_gs_table_depth);
  1032. adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gpu_info_fw->gc_gsprim_buff_depth);
  1033. adev->gfx.config.double_offchip_lds_buf =
  1034. le32_to_cpu(gpu_info_fw->gc_double_offchip_lds_buffer);
  1035. adev->gfx.cu_info.wave_front_size = le32_to_cpu(gpu_info_fw->gc_wave_size);
  1036. adev->gfx.cu_info.max_waves_per_simd =
  1037. le32_to_cpu(gpu_info_fw->gc_max_waves_per_simd);
  1038. adev->gfx.cu_info.max_scratch_slots_per_cu =
  1039. le32_to_cpu(gpu_info_fw->gc_max_scratch_slots_per_cu);
  1040. adev->gfx.cu_info.lds_size = le32_to_cpu(gpu_info_fw->gc_lds_size);
  1041. break;
  1042. }
  1043. default:
  1044. dev_err(adev->dev,
  1045. "Unsupported gpu_info table %d\n", hdr->header.ucode_version);
  1046. err = -EINVAL;
  1047. goto out;
  1048. }
  1049. out:
  1050. return err;
  1051. }
  1052. static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  1053. {
  1054. int i, r;
  1055. amdgpu_device_enable_virtual_display(adev);
  1056. switch (adev->asic_type) {
  1057. case CHIP_TOPAZ:
  1058. case CHIP_TONGA:
  1059. case CHIP_FIJI:
  1060. case CHIP_POLARIS11:
  1061. case CHIP_POLARIS10:
  1062. case CHIP_POLARIS12:
  1063. case CHIP_CARRIZO:
  1064. case CHIP_STONEY:
  1065. if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY)
  1066. adev->family = AMDGPU_FAMILY_CZ;
  1067. else
  1068. adev->family = AMDGPU_FAMILY_VI;
  1069. r = vi_set_ip_blocks(adev);
  1070. if (r)
  1071. return r;
  1072. break;
  1073. #ifdef CONFIG_DRM_AMDGPU_SI
  1074. case CHIP_VERDE:
  1075. case CHIP_TAHITI:
  1076. case CHIP_PITCAIRN:
  1077. case CHIP_OLAND:
  1078. case CHIP_HAINAN:
  1079. adev->family = AMDGPU_FAMILY_SI;
  1080. r = si_set_ip_blocks(adev);
  1081. if (r)
  1082. return r;
  1083. break;
  1084. #endif
  1085. #ifdef CONFIG_DRM_AMDGPU_CIK
  1086. case CHIP_BONAIRE:
  1087. case CHIP_HAWAII:
  1088. case CHIP_KAVERI:
  1089. case CHIP_KABINI:
  1090. case CHIP_MULLINS:
  1091. if ((adev->asic_type == CHIP_BONAIRE) || (adev->asic_type == CHIP_HAWAII))
  1092. adev->family = AMDGPU_FAMILY_CI;
  1093. else
  1094. adev->family = AMDGPU_FAMILY_KV;
  1095. r = cik_set_ip_blocks(adev);
  1096. if (r)
  1097. return r;
  1098. break;
  1099. #endif
  1100. case CHIP_VEGA10:
  1101. case CHIP_RAVEN:
  1102. if (adev->asic_type == CHIP_RAVEN)
  1103. adev->family = AMDGPU_FAMILY_RV;
  1104. else
  1105. adev->family = AMDGPU_FAMILY_AI;
  1106. r = soc15_set_ip_blocks(adev);
  1107. if (r)
  1108. return r;
  1109. break;
  1110. default:
  1111. /* FIXME: not supported yet */
  1112. return -EINVAL;
  1113. }
  1114. r = amdgpu_device_parse_gpu_info_fw(adev);
  1115. if (r)
  1116. return r;
  1117. amdgpu_amdkfd_device_probe(adev);
  1118. if (amdgpu_sriov_vf(adev)) {
  1119. r = amdgpu_virt_request_full_gpu(adev, true);
  1120. if (r)
  1121. return -EAGAIN;
  1122. }
  1123. for (i = 0; i < adev->num_ip_blocks; i++) {
  1124. if ((amdgpu_ip_block_mask & (1 << i)) == 0) {
  1125. DRM_ERROR("disabled ip block: %d <%s>\n",
  1126. i, adev->ip_blocks[i].version->funcs->name);
  1127. adev->ip_blocks[i].status.valid = false;
  1128. } else {
  1129. if (adev->ip_blocks[i].version->funcs->early_init) {
  1130. r = adev->ip_blocks[i].version->funcs->early_init((void *)adev);
  1131. if (r == -ENOENT) {
  1132. adev->ip_blocks[i].status.valid = false;
  1133. } else if (r) {
  1134. DRM_ERROR("early_init of IP block <%s> failed %d\n",
  1135. adev->ip_blocks[i].version->funcs->name, r);
  1136. return r;
  1137. } else {
  1138. adev->ip_blocks[i].status.valid = true;
  1139. }
  1140. } else {
  1141. adev->ip_blocks[i].status.valid = true;
  1142. }
  1143. }
  1144. }
  1145. adev->cg_flags &= amdgpu_cg_mask;
  1146. adev->pg_flags &= amdgpu_pg_mask;
  1147. return 0;
  1148. }
  1149. static int amdgpu_device_ip_init(struct amdgpu_device *adev)
  1150. {
  1151. int i, r;
  1152. for (i = 0; i < adev->num_ip_blocks; i++) {
  1153. if (!adev->ip_blocks[i].status.valid)
  1154. continue;
  1155. r = adev->ip_blocks[i].version->funcs->sw_init((void *)adev);
  1156. if (r) {
  1157. DRM_ERROR("sw_init of IP block <%s> failed %d\n",
  1158. adev->ip_blocks[i].version->funcs->name, r);
  1159. return r;
  1160. }
  1161. adev->ip_blocks[i].status.sw = true;
  1162. /* need to do gmc hw init early so we can allocate gpu mem */
  1163. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
  1164. r = amdgpu_device_vram_scratch_init(adev);
  1165. if (r) {
  1166. DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r);
  1167. return r;
  1168. }
  1169. r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev);
  1170. if (r) {
  1171. DRM_ERROR("hw_init %d failed %d\n", i, r);
  1172. return r;
  1173. }
  1174. r = amdgpu_device_wb_init(adev);
  1175. if (r) {
  1176. DRM_ERROR("amdgpu_device_wb_init failed %d\n", r);
  1177. return r;
  1178. }
  1179. adev->ip_blocks[i].status.hw = true;
  1180. /* right after GMC hw init, we create CSA */
  1181. if (amdgpu_sriov_vf(adev)) {
  1182. r = amdgpu_allocate_static_csa(adev);
  1183. if (r) {
  1184. DRM_ERROR("allocate CSA failed %d\n", r);
  1185. return r;
  1186. }
  1187. }
  1188. }
  1189. }
  1190. for (i = 0; i < adev->num_ip_blocks; i++) {
  1191. if (!adev->ip_blocks[i].status.sw)
  1192. continue;
  1193. if (adev->ip_blocks[i].status.hw)
  1194. continue;
  1195. r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev);
  1196. if (r) {
  1197. DRM_ERROR("hw_init of IP block <%s> failed %d\n",
  1198. adev->ip_blocks[i].version->funcs->name, r);
  1199. return r;
  1200. }
  1201. adev->ip_blocks[i].status.hw = true;
  1202. }
  1203. amdgpu_amdkfd_device_init(adev);
  1204. if (amdgpu_sriov_vf(adev))
  1205. amdgpu_virt_release_full_gpu(adev, true);
  1206. return 0;
  1207. }
  1208. static void amdgpu_device_fill_reset_magic(struct amdgpu_device *adev)
  1209. {
  1210. memcpy(adev->reset_magic, adev->gart.ptr, AMDGPU_RESET_MAGIC_NUM);
  1211. }
  1212. static bool amdgpu_device_check_vram_lost(struct amdgpu_device *adev)
  1213. {
  1214. return !!memcmp(adev->gart.ptr, adev->reset_magic,
  1215. AMDGPU_RESET_MAGIC_NUM);
  1216. }
  1217. static int amdgpu_device_ip_late_set_cg_state(struct amdgpu_device *adev)
  1218. {
  1219. int i = 0, r;
  1220. if (amdgpu_emu_mode == 1)
  1221. return 0;
  1222. for (i = 0; i < adev->num_ip_blocks; i++) {
  1223. if (!adev->ip_blocks[i].status.valid)
  1224. continue;
  1225. /* skip CG for VCE/UVD, it's handled specially */
  1226. if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
  1227. adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) {
  1228. /* enable clockgating to save power */
  1229. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1230. AMD_CG_STATE_GATE);
  1231. if (r) {
  1232. DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n",
  1233. adev->ip_blocks[i].version->funcs->name, r);
  1234. return r;
  1235. }
  1236. }
  1237. }
  1238. return 0;
  1239. }
  1240. static int amdgpu_device_ip_late_init(struct amdgpu_device *adev)
  1241. {
  1242. int i = 0, r;
  1243. for (i = 0; i < adev->num_ip_blocks; i++) {
  1244. if (!adev->ip_blocks[i].status.valid)
  1245. continue;
  1246. if (adev->ip_blocks[i].version->funcs->late_init) {
  1247. r = adev->ip_blocks[i].version->funcs->late_init((void *)adev);
  1248. if (r) {
  1249. DRM_ERROR("late_init of IP block <%s> failed %d\n",
  1250. adev->ip_blocks[i].version->funcs->name, r);
  1251. return r;
  1252. }
  1253. adev->ip_blocks[i].status.late_initialized = true;
  1254. }
  1255. }
  1256. mod_delayed_work(system_wq, &adev->late_init_work,
  1257. msecs_to_jiffies(AMDGPU_RESUME_MS));
  1258. amdgpu_device_fill_reset_magic(adev);
  1259. return 0;
  1260. }
  1261. static int amdgpu_device_ip_fini(struct amdgpu_device *adev)
  1262. {
  1263. int i, r;
  1264. amdgpu_amdkfd_device_fini(adev);
  1265. /* need to disable SMC first */
  1266. for (i = 0; i < adev->num_ip_blocks; i++) {
  1267. if (!adev->ip_blocks[i].status.hw)
  1268. continue;
  1269. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) {
  1270. /* ungate blocks before hw fini so that we can shutdown the blocks safely */
  1271. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1272. AMD_CG_STATE_UNGATE);
  1273. if (r) {
  1274. DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
  1275. adev->ip_blocks[i].version->funcs->name, r);
  1276. return r;
  1277. }
  1278. r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev);
  1279. /* XXX handle errors */
  1280. if (r) {
  1281. DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
  1282. adev->ip_blocks[i].version->funcs->name, r);
  1283. }
  1284. adev->ip_blocks[i].status.hw = false;
  1285. break;
  1286. }
  1287. }
  1288. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1289. if (!adev->ip_blocks[i].status.hw)
  1290. continue;
  1291. if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
  1292. adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) {
  1293. /* ungate blocks before hw fini so that we can shutdown the blocks safely */
  1294. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1295. AMD_CG_STATE_UNGATE);
  1296. if (r) {
  1297. DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
  1298. adev->ip_blocks[i].version->funcs->name, r);
  1299. return r;
  1300. }
  1301. }
  1302. r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev);
  1303. /* XXX handle errors */
  1304. if (r) {
  1305. DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
  1306. adev->ip_blocks[i].version->funcs->name, r);
  1307. }
  1308. adev->ip_blocks[i].status.hw = false;
  1309. }
  1310. /* disable all interrupts */
  1311. amdgpu_irq_disable_all(adev);
  1312. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1313. if (!adev->ip_blocks[i].status.sw)
  1314. continue;
  1315. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
  1316. amdgpu_free_static_csa(adev);
  1317. amdgpu_device_wb_fini(adev);
  1318. amdgpu_device_vram_scratch_fini(adev);
  1319. }
  1320. r = adev->ip_blocks[i].version->funcs->sw_fini((void *)adev);
  1321. /* XXX handle errors */
  1322. if (r) {
  1323. DRM_DEBUG("sw_fini of IP block <%s> failed %d\n",
  1324. adev->ip_blocks[i].version->funcs->name, r);
  1325. }
  1326. adev->ip_blocks[i].status.sw = false;
  1327. adev->ip_blocks[i].status.valid = false;
  1328. }
  1329. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1330. if (!adev->ip_blocks[i].status.late_initialized)
  1331. continue;
  1332. if (adev->ip_blocks[i].version->funcs->late_fini)
  1333. adev->ip_blocks[i].version->funcs->late_fini((void *)adev);
  1334. adev->ip_blocks[i].status.late_initialized = false;
  1335. }
  1336. if (amdgpu_sriov_vf(adev))
  1337. if (amdgpu_virt_release_full_gpu(adev, false))
  1338. DRM_ERROR("failed to release exclusive mode on fini\n");
  1339. return 0;
  1340. }
  1341. static void amdgpu_device_ip_late_init_func_handler(struct work_struct *work)
  1342. {
  1343. struct amdgpu_device *adev =
  1344. container_of(work, struct amdgpu_device, late_init_work.work);
  1345. amdgpu_device_ip_late_set_cg_state(adev);
  1346. }
  1347. int amdgpu_device_ip_suspend(struct amdgpu_device *adev)
  1348. {
  1349. int i, r;
  1350. if (amdgpu_sriov_vf(adev))
  1351. amdgpu_virt_request_full_gpu(adev, false);
  1352. /* ungate SMC block first */
  1353. r = amdgpu_device_ip_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_SMC,
  1354. AMD_CG_STATE_UNGATE);
  1355. if (r) {
  1356. DRM_ERROR("set_clockgating_state(ungate) SMC failed %d\n", r);
  1357. }
  1358. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1359. if (!adev->ip_blocks[i].status.valid)
  1360. continue;
  1361. /* ungate blocks so that suspend can properly shut them down */
  1362. if (i != AMD_IP_BLOCK_TYPE_SMC) {
  1363. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1364. AMD_CG_STATE_UNGATE);
  1365. if (r) {
  1366. DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
  1367. adev->ip_blocks[i].version->funcs->name, r);
  1368. }
  1369. }
  1370. /* XXX handle errors */
  1371. r = adev->ip_blocks[i].version->funcs->suspend(adev);
  1372. /* XXX handle errors */
  1373. if (r) {
  1374. DRM_ERROR("suspend of IP block <%s> failed %d\n",
  1375. adev->ip_blocks[i].version->funcs->name, r);
  1376. }
  1377. }
  1378. if (amdgpu_sriov_vf(adev))
  1379. amdgpu_virt_release_full_gpu(adev, false);
  1380. return 0;
  1381. }
  1382. static int amdgpu_device_ip_reinit_early_sriov(struct amdgpu_device *adev)
  1383. {
  1384. int i, r;
  1385. static enum amd_ip_block_type ip_order[] = {
  1386. AMD_IP_BLOCK_TYPE_GMC,
  1387. AMD_IP_BLOCK_TYPE_COMMON,
  1388. AMD_IP_BLOCK_TYPE_IH,
  1389. };
  1390. for (i = 0; i < ARRAY_SIZE(ip_order); i++) {
  1391. int j;
  1392. struct amdgpu_ip_block *block;
  1393. for (j = 0; j < adev->num_ip_blocks; j++) {
  1394. block = &adev->ip_blocks[j];
  1395. if (block->version->type != ip_order[i] ||
  1396. !block->status.valid)
  1397. continue;
  1398. r = block->version->funcs->hw_init(adev);
  1399. DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed");
  1400. if (r)
  1401. return r;
  1402. }
  1403. }
  1404. return 0;
  1405. }
  1406. static int amdgpu_device_ip_reinit_late_sriov(struct amdgpu_device *adev)
  1407. {
  1408. int i, r;
  1409. static enum amd_ip_block_type ip_order[] = {
  1410. AMD_IP_BLOCK_TYPE_SMC,
  1411. AMD_IP_BLOCK_TYPE_PSP,
  1412. AMD_IP_BLOCK_TYPE_DCE,
  1413. AMD_IP_BLOCK_TYPE_GFX,
  1414. AMD_IP_BLOCK_TYPE_SDMA,
  1415. AMD_IP_BLOCK_TYPE_UVD,
  1416. AMD_IP_BLOCK_TYPE_VCE
  1417. };
  1418. for (i = 0; i < ARRAY_SIZE(ip_order); i++) {
  1419. int j;
  1420. struct amdgpu_ip_block *block;
  1421. for (j = 0; j < adev->num_ip_blocks; j++) {
  1422. block = &adev->ip_blocks[j];
  1423. if (block->version->type != ip_order[i] ||
  1424. !block->status.valid)
  1425. continue;
  1426. r = block->version->funcs->hw_init(adev);
  1427. DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed");
  1428. if (r)
  1429. return r;
  1430. }
  1431. }
  1432. return 0;
  1433. }
  1434. static int amdgpu_device_ip_resume_phase1(struct amdgpu_device *adev)
  1435. {
  1436. int i, r;
  1437. for (i = 0; i < adev->num_ip_blocks; i++) {
  1438. if (!adev->ip_blocks[i].status.valid)
  1439. continue;
  1440. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
  1441. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
  1442. adev->ip_blocks[i].version->type ==
  1443. AMD_IP_BLOCK_TYPE_IH) {
  1444. r = adev->ip_blocks[i].version->funcs->resume(adev);
  1445. if (r) {
  1446. DRM_ERROR("resume of IP block <%s> failed %d\n",
  1447. adev->ip_blocks[i].version->funcs->name, r);
  1448. return r;
  1449. }
  1450. }
  1451. }
  1452. return 0;
  1453. }
  1454. static int amdgpu_device_ip_resume_phase2(struct amdgpu_device *adev)
  1455. {
  1456. int i, r;
  1457. for (i = 0; i < adev->num_ip_blocks; i++) {
  1458. if (!adev->ip_blocks[i].status.valid)
  1459. continue;
  1460. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
  1461. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
  1462. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH )
  1463. continue;
  1464. r = adev->ip_blocks[i].version->funcs->resume(adev);
  1465. if (r) {
  1466. DRM_ERROR("resume of IP block <%s> failed %d\n",
  1467. adev->ip_blocks[i].version->funcs->name, r);
  1468. return r;
  1469. }
  1470. }
  1471. return 0;
  1472. }
  1473. static int amdgpu_device_ip_resume(struct amdgpu_device *adev)
  1474. {
  1475. int r;
  1476. r = amdgpu_device_ip_resume_phase1(adev);
  1477. if (r)
  1478. return r;
  1479. r = amdgpu_device_ip_resume_phase2(adev);
  1480. return r;
  1481. }
  1482. static void amdgpu_device_detect_sriov_bios(struct amdgpu_device *adev)
  1483. {
  1484. if (amdgpu_sriov_vf(adev)) {
  1485. if (adev->is_atom_fw) {
  1486. if (amdgpu_atomfirmware_gpu_supports_virtualization(adev))
  1487. adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
  1488. } else {
  1489. if (amdgpu_atombios_has_gpu_virtualization_table(adev))
  1490. adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
  1491. }
  1492. if (!(adev->virt.caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS))
  1493. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_NO_VBIOS, 0, 0);
  1494. }
  1495. }
  1496. bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type)
  1497. {
  1498. switch (asic_type) {
  1499. #if defined(CONFIG_DRM_AMD_DC)
  1500. case CHIP_BONAIRE:
  1501. case CHIP_HAWAII:
  1502. case CHIP_KAVERI:
  1503. case CHIP_KABINI:
  1504. case CHIP_MULLINS:
  1505. case CHIP_CARRIZO:
  1506. case CHIP_STONEY:
  1507. case CHIP_POLARIS11:
  1508. case CHIP_POLARIS10:
  1509. case CHIP_POLARIS12:
  1510. case CHIP_TONGA:
  1511. case CHIP_FIJI:
  1512. #if defined(CONFIG_DRM_AMD_DC_PRE_VEGA)
  1513. return amdgpu_dc != 0;
  1514. #endif
  1515. case CHIP_VEGA10:
  1516. #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
  1517. case CHIP_RAVEN:
  1518. #endif
  1519. return amdgpu_dc != 0;
  1520. #endif
  1521. default:
  1522. return false;
  1523. }
  1524. }
  1525. /**
  1526. * amdgpu_device_has_dc_support - check if dc is supported
  1527. *
  1528. * @adev: amdgpu_device_pointer
  1529. *
  1530. * Returns true for supported, false for not supported
  1531. */
  1532. bool amdgpu_device_has_dc_support(struct amdgpu_device *adev)
  1533. {
  1534. if (amdgpu_sriov_vf(adev))
  1535. return false;
  1536. return amdgpu_device_asic_has_dc_support(adev->asic_type);
  1537. }
  1538. /**
  1539. * amdgpu_device_init - initialize the driver
  1540. *
  1541. * @adev: amdgpu_device pointer
  1542. * @pdev: drm dev pointer
  1543. * @pdev: pci dev pointer
  1544. * @flags: driver flags
  1545. *
  1546. * Initializes the driver info and hw (all asics).
  1547. * Returns 0 for success or an error on failure.
  1548. * Called at driver startup.
  1549. */
  1550. int amdgpu_device_init(struct amdgpu_device *adev,
  1551. struct drm_device *ddev,
  1552. struct pci_dev *pdev,
  1553. uint32_t flags)
  1554. {
  1555. int r, i;
  1556. bool runtime = false;
  1557. u32 max_MBps;
  1558. adev->shutdown = false;
  1559. adev->dev = &pdev->dev;
  1560. adev->ddev = ddev;
  1561. adev->pdev = pdev;
  1562. adev->flags = flags;
  1563. adev->asic_type = flags & AMD_ASIC_MASK;
  1564. adev->usec_timeout = AMDGPU_MAX_USEC_TIMEOUT;
  1565. if (amdgpu_emu_mode == 1)
  1566. adev->usec_timeout *= 2;
  1567. adev->gmc.gart_size = 512 * 1024 * 1024;
  1568. adev->accel_working = false;
  1569. adev->num_rings = 0;
  1570. adev->mman.buffer_funcs = NULL;
  1571. adev->mman.buffer_funcs_ring = NULL;
  1572. adev->vm_manager.vm_pte_funcs = NULL;
  1573. adev->vm_manager.vm_pte_num_rings = 0;
  1574. adev->gmc.gmc_funcs = NULL;
  1575. adev->fence_context = dma_fence_context_alloc(AMDGPU_MAX_RINGS);
  1576. bitmap_zero(adev->gfx.pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
  1577. adev->smc_rreg = &amdgpu_invalid_rreg;
  1578. adev->smc_wreg = &amdgpu_invalid_wreg;
  1579. adev->pcie_rreg = &amdgpu_invalid_rreg;
  1580. adev->pcie_wreg = &amdgpu_invalid_wreg;
  1581. adev->pciep_rreg = &amdgpu_invalid_rreg;
  1582. adev->pciep_wreg = &amdgpu_invalid_wreg;
  1583. adev->uvd_ctx_rreg = &amdgpu_invalid_rreg;
  1584. adev->uvd_ctx_wreg = &amdgpu_invalid_wreg;
  1585. adev->didt_rreg = &amdgpu_invalid_rreg;
  1586. adev->didt_wreg = &amdgpu_invalid_wreg;
  1587. adev->gc_cac_rreg = &amdgpu_invalid_rreg;
  1588. adev->gc_cac_wreg = &amdgpu_invalid_wreg;
  1589. adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg;
  1590. adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg;
  1591. DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n",
  1592. amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device,
  1593. pdev->subsystem_vendor, pdev->subsystem_device, pdev->revision);
  1594. /* mutex initialization are all done here so we
  1595. * can recall function without having locking issues */
  1596. atomic_set(&adev->irq.ih.lock, 0);
  1597. mutex_init(&adev->firmware.mutex);
  1598. mutex_init(&adev->pm.mutex);
  1599. mutex_init(&adev->gfx.gpu_clock_mutex);
  1600. mutex_init(&adev->srbm_mutex);
  1601. mutex_init(&adev->gfx.pipe_reserve_mutex);
  1602. mutex_init(&adev->grbm_idx_mutex);
  1603. mutex_init(&adev->mn_lock);
  1604. mutex_init(&adev->virt.vf_errors.lock);
  1605. hash_init(adev->mn_hash);
  1606. mutex_init(&adev->lock_reset);
  1607. amdgpu_device_check_arguments(adev);
  1608. spin_lock_init(&adev->mmio_idx_lock);
  1609. spin_lock_init(&adev->smc_idx_lock);
  1610. spin_lock_init(&adev->pcie_idx_lock);
  1611. spin_lock_init(&adev->uvd_ctx_idx_lock);
  1612. spin_lock_init(&adev->didt_idx_lock);
  1613. spin_lock_init(&adev->gc_cac_idx_lock);
  1614. spin_lock_init(&adev->se_cac_idx_lock);
  1615. spin_lock_init(&adev->audio_endpt_idx_lock);
  1616. spin_lock_init(&adev->mm_stats.lock);
  1617. INIT_LIST_HEAD(&adev->shadow_list);
  1618. mutex_init(&adev->shadow_list_lock);
  1619. INIT_LIST_HEAD(&adev->ring_lru_list);
  1620. spin_lock_init(&adev->ring_lru_list_lock);
  1621. INIT_DELAYED_WORK(&adev->late_init_work,
  1622. amdgpu_device_ip_late_init_func_handler);
  1623. /* Registers mapping */
  1624. /* TODO: block userspace mapping of io register */
  1625. if (adev->asic_type >= CHIP_BONAIRE) {
  1626. adev->rmmio_base = pci_resource_start(adev->pdev, 5);
  1627. adev->rmmio_size = pci_resource_len(adev->pdev, 5);
  1628. } else {
  1629. adev->rmmio_base = pci_resource_start(adev->pdev, 2);
  1630. adev->rmmio_size = pci_resource_len(adev->pdev, 2);
  1631. }
  1632. adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
  1633. if (adev->rmmio == NULL) {
  1634. return -ENOMEM;
  1635. }
  1636. DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
  1637. DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size);
  1638. /* doorbell bar mapping */
  1639. amdgpu_device_doorbell_init(adev);
  1640. /* io port mapping */
  1641. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  1642. if (pci_resource_flags(adev->pdev, i) & IORESOURCE_IO) {
  1643. adev->rio_mem_size = pci_resource_len(adev->pdev, i);
  1644. adev->rio_mem = pci_iomap(adev->pdev, i, adev->rio_mem_size);
  1645. break;
  1646. }
  1647. }
  1648. if (adev->rio_mem == NULL)
  1649. DRM_INFO("PCI I/O BAR is not found.\n");
  1650. /* early init functions */
  1651. r = amdgpu_device_ip_early_init(adev);
  1652. if (r)
  1653. return r;
  1654. /* if we have > 1 VGA cards, then disable the amdgpu VGA resources */
  1655. /* this will fail for cards that aren't VGA class devices, just
  1656. * ignore it */
  1657. vga_client_register(adev->pdev, adev, NULL, amdgpu_device_vga_set_decode);
  1658. if (amdgpu_device_is_px(ddev))
  1659. runtime = true;
  1660. if (!pci_is_thunderbolt_attached(adev->pdev))
  1661. vga_switcheroo_register_client(adev->pdev,
  1662. &amdgpu_switcheroo_ops, runtime);
  1663. if (runtime)
  1664. vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain);
  1665. if (amdgpu_emu_mode == 1) {
  1666. /* post the asic on emulation mode */
  1667. emu_soc_asic_init(adev);
  1668. goto fence_driver_init;
  1669. }
  1670. /* Read BIOS */
  1671. if (!amdgpu_get_bios(adev)) {
  1672. r = -EINVAL;
  1673. goto failed;
  1674. }
  1675. r = amdgpu_atombios_init(adev);
  1676. if (r) {
  1677. dev_err(adev->dev, "amdgpu_atombios_init failed\n");
  1678. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL, 0, 0);
  1679. goto failed;
  1680. }
  1681. /* detect if we are with an SRIOV vbios */
  1682. amdgpu_device_detect_sriov_bios(adev);
  1683. /* Post card if necessary */
  1684. if (amdgpu_device_need_post(adev)) {
  1685. if (!adev->bios) {
  1686. dev_err(adev->dev, "no vBIOS found\n");
  1687. r = -EINVAL;
  1688. goto failed;
  1689. }
  1690. DRM_INFO("GPU posting now...\n");
  1691. r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
  1692. if (r) {
  1693. dev_err(adev->dev, "gpu post error!\n");
  1694. goto failed;
  1695. }
  1696. }
  1697. if (adev->is_atom_fw) {
  1698. /* Initialize clocks */
  1699. r = amdgpu_atomfirmware_get_clock_info(adev);
  1700. if (r) {
  1701. dev_err(adev->dev, "amdgpu_atomfirmware_get_clock_info failed\n");
  1702. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
  1703. goto failed;
  1704. }
  1705. } else {
  1706. /* Initialize clocks */
  1707. r = amdgpu_atombios_get_clock_info(adev);
  1708. if (r) {
  1709. dev_err(adev->dev, "amdgpu_atombios_get_clock_info failed\n");
  1710. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
  1711. goto failed;
  1712. }
  1713. /* init i2c buses */
  1714. if (!amdgpu_device_has_dc_support(adev))
  1715. amdgpu_atombios_i2c_init(adev);
  1716. }
  1717. fence_driver_init:
  1718. /* Fence driver */
  1719. r = amdgpu_fence_driver_init(adev);
  1720. if (r) {
  1721. dev_err(adev->dev, "amdgpu_fence_driver_init failed\n");
  1722. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_FENCE_INIT_FAIL, 0, 0);
  1723. goto failed;
  1724. }
  1725. /* init the mode config */
  1726. drm_mode_config_init(adev->ddev);
  1727. r = amdgpu_device_ip_init(adev);
  1728. if (r) {
  1729. /* failed in exclusive mode due to timeout */
  1730. if (amdgpu_sriov_vf(adev) &&
  1731. !amdgpu_sriov_runtime(adev) &&
  1732. amdgpu_virt_mmio_blocked(adev) &&
  1733. !amdgpu_virt_wait_reset(adev)) {
  1734. dev_err(adev->dev, "VF exclusive mode timeout\n");
  1735. /* Don't send request since VF is inactive. */
  1736. adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
  1737. adev->virt.ops = NULL;
  1738. r = -EAGAIN;
  1739. goto failed;
  1740. }
  1741. dev_err(adev->dev, "amdgpu_device_ip_init failed\n");
  1742. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_INIT_FAIL, 0, 0);
  1743. amdgpu_device_ip_fini(adev);
  1744. goto failed;
  1745. }
  1746. adev->accel_working = true;
  1747. amdgpu_vm_check_compute_bug(adev);
  1748. /* Initialize the buffer migration limit. */
  1749. if (amdgpu_moverate >= 0)
  1750. max_MBps = amdgpu_moverate;
  1751. else
  1752. max_MBps = 8; /* Allow 8 MB/s. */
  1753. /* Get a log2 for easy divisions. */
  1754. adev->mm_stats.log2_max_MBps = ilog2(max(1u, max_MBps));
  1755. r = amdgpu_ib_pool_init(adev);
  1756. if (r) {
  1757. dev_err(adev->dev, "IB initialization failed (%d).\n", r);
  1758. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_IB_INIT_FAIL, 0, r);
  1759. goto failed;
  1760. }
  1761. r = amdgpu_ib_ring_tests(adev);
  1762. if (r)
  1763. DRM_ERROR("ib ring test failed (%d).\n", r);
  1764. if (amdgpu_sriov_vf(adev))
  1765. amdgpu_virt_init_data_exchange(adev);
  1766. amdgpu_fbdev_init(adev);
  1767. r = amdgpu_pm_sysfs_init(adev);
  1768. if (r)
  1769. DRM_ERROR("registering pm debugfs failed (%d).\n", r);
  1770. r = amdgpu_debugfs_gem_init(adev);
  1771. if (r)
  1772. DRM_ERROR("registering gem debugfs failed (%d).\n", r);
  1773. r = amdgpu_debugfs_regs_init(adev);
  1774. if (r)
  1775. DRM_ERROR("registering register debugfs failed (%d).\n", r);
  1776. r = amdgpu_debugfs_firmware_init(adev);
  1777. if (r)
  1778. DRM_ERROR("registering firmware debugfs failed (%d).\n", r);
  1779. r = amdgpu_debugfs_init(adev);
  1780. if (r)
  1781. DRM_ERROR("Creating debugfs files failed (%d).\n", r);
  1782. if ((amdgpu_testing & 1)) {
  1783. if (adev->accel_working)
  1784. amdgpu_test_moves(adev);
  1785. else
  1786. DRM_INFO("amdgpu: acceleration disabled, skipping move tests\n");
  1787. }
  1788. if (amdgpu_benchmarking) {
  1789. if (adev->accel_working)
  1790. amdgpu_benchmark(adev, amdgpu_benchmarking);
  1791. else
  1792. DRM_INFO("amdgpu: acceleration disabled, skipping benchmarks\n");
  1793. }
  1794. /* enable clockgating, etc. after ib tests, etc. since some blocks require
  1795. * explicit gating rather than handling it automatically.
  1796. */
  1797. r = amdgpu_device_ip_late_init(adev);
  1798. if (r) {
  1799. dev_err(adev->dev, "amdgpu_device_ip_late_init failed\n");
  1800. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_LATE_INIT_FAIL, 0, r);
  1801. goto failed;
  1802. }
  1803. return 0;
  1804. failed:
  1805. amdgpu_vf_error_trans_all(adev);
  1806. if (runtime)
  1807. vga_switcheroo_fini_domain_pm_ops(adev->dev);
  1808. return r;
  1809. }
  1810. /**
  1811. * amdgpu_device_fini - tear down the driver
  1812. *
  1813. * @adev: amdgpu_device pointer
  1814. *
  1815. * Tear down the driver info (all asics).
  1816. * Called at driver shutdown.
  1817. */
  1818. void amdgpu_device_fini(struct amdgpu_device *adev)
  1819. {
  1820. int r;
  1821. DRM_INFO("amdgpu: finishing device.\n");
  1822. adev->shutdown = true;
  1823. if (adev->mode_info.mode_config_initialized)
  1824. drm_crtc_force_disable_all(adev->ddev);
  1825. amdgpu_ib_pool_fini(adev);
  1826. amdgpu_fence_driver_fini(adev);
  1827. amdgpu_fbdev_fini(adev);
  1828. r = amdgpu_device_ip_fini(adev);
  1829. if (adev->firmware.gpu_info_fw) {
  1830. release_firmware(adev->firmware.gpu_info_fw);
  1831. adev->firmware.gpu_info_fw = NULL;
  1832. }
  1833. adev->accel_working = false;
  1834. cancel_delayed_work_sync(&adev->late_init_work);
  1835. /* free i2c buses */
  1836. if (!amdgpu_device_has_dc_support(adev))
  1837. amdgpu_i2c_fini(adev);
  1838. if (amdgpu_emu_mode != 1)
  1839. amdgpu_atombios_fini(adev);
  1840. kfree(adev->bios);
  1841. adev->bios = NULL;
  1842. if (!pci_is_thunderbolt_attached(adev->pdev))
  1843. vga_switcheroo_unregister_client(adev->pdev);
  1844. if (adev->flags & AMD_IS_PX)
  1845. vga_switcheroo_fini_domain_pm_ops(adev->dev);
  1846. vga_client_register(adev->pdev, NULL, NULL, NULL);
  1847. if (adev->rio_mem)
  1848. pci_iounmap(adev->pdev, adev->rio_mem);
  1849. adev->rio_mem = NULL;
  1850. iounmap(adev->rmmio);
  1851. adev->rmmio = NULL;
  1852. amdgpu_device_doorbell_fini(adev);
  1853. amdgpu_pm_sysfs_fini(adev);
  1854. amdgpu_debugfs_regs_cleanup(adev);
  1855. }
  1856. /*
  1857. * Suspend & resume.
  1858. */
  1859. /**
  1860. * amdgpu_device_suspend - initiate device suspend
  1861. *
  1862. * @pdev: drm dev pointer
  1863. * @state: suspend state
  1864. *
  1865. * Puts the hw in the suspend state (all asics).
  1866. * Returns 0 for success or an error on failure.
  1867. * Called at driver suspend.
  1868. */
  1869. int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
  1870. {
  1871. struct amdgpu_device *adev;
  1872. struct drm_crtc *crtc;
  1873. struct drm_connector *connector;
  1874. int r;
  1875. if (dev == NULL || dev->dev_private == NULL) {
  1876. return -ENODEV;
  1877. }
  1878. adev = dev->dev_private;
  1879. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1880. return 0;
  1881. drm_kms_helper_poll_disable(dev);
  1882. if (!amdgpu_device_has_dc_support(adev)) {
  1883. /* turn off display hw */
  1884. drm_modeset_lock_all(dev);
  1885. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1886. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
  1887. }
  1888. drm_modeset_unlock_all(dev);
  1889. }
  1890. amdgpu_amdkfd_suspend(adev);
  1891. /* unpin the front buffers and cursors */
  1892. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1893. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1894. struct amdgpu_framebuffer *rfb = to_amdgpu_framebuffer(crtc->primary->fb);
  1895. struct amdgpu_bo *robj;
  1896. if (amdgpu_crtc->cursor_bo) {
  1897. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  1898. r = amdgpu_bo_reserve(aobj, true);
  1899. if (r == 0) {
  1900. amdgpu_bo_unpin(aobj);
  1901. amdgpu_bo_unreserve(aobj);
  1902. }
  1903. }
  1904. if (rfb == NULL || rfb->obj == NULL) {
  1905. continue;
  1906. }
  1907. robj = gem_to_amdgpu_bo(rfb->obj);
  1908. /* don't unpin kernel fb objects */
  1909. if (!amdgpu_fbdev_robj_is_fb(adev, robj)) {
  1910. r = amdgpu_bo_reserve(robj, true);
  1911. if (r == 0) {
  1912. amdgpu_bo_unpin(robj);
  1913. amdgpu_bo_unreserve(robj);
  1914. }
  1915. }
  1916. }
  1917. /* evict vram memory */
  1918. amdgpu_bo_evict_vram(adev);
  1919. amdgpu_fence_driver_suspend(adev);
  1920. r = amdgpu_device_ip_suspend(adev);
  1921. /* evict remaining vram memory
  1922. * This second call to evict vram is to evict the gart page table
  1923. * using the CPU.
  1924. */
  1925. amdgpu_bo_evict_vram(adev);
  1926. pci_save_state(dev->pdev);
  1927. if (suspend) {
  1928. /* Shut down the device */
  1929. pci_disable_device(dev->pdev);
  1930. pci_set_power_state(dev->pdev, PCI_D3hot);
  1931. } else {
  1932. r = amdgpu_asic_reset(adev);
  1933. if (r)
  1934. DRM_ERROR("amdgpu asic reset failed\n");
  1935. }
  1936. if (fbcon) {
  1937. console_lock();
  1938. amdgpu_fbdev_set_suspend(adev, 1);
  1939. console_unlock();
  1940. }
  1941. return 0;
  1942. }
  1943. /**
  1944. * amdgpu_device_resume - initiate device resume
  1945. *
  1946. * @pdev: drm dev pointer
  1947. *
  1948. * Bring the hw back to operating state (all asics).
  1949. * Returns 0 for success or an error on failure.
  1950. * Called at driver resume.
  1951. */
  1952. int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon)
  1953. {
  1954. struct drm_connector *connector;
  1955. struct amdgpu_device *adev = dev->dev_private;
  1956. struct drm_crtc *crtc;
  1957. int r = 0;
  1958. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1959. return 0;
  1960. if (fbcon)
  1961. console_lock();
  1962. if (resume) {
  1963. pci_set_power_state(dev->pdev, PCI_D0);
  1964. pci_restore_state(dev->pdev);
  1965. r = pci_enable_device(dev->pdev);
  1966. if (r)
  1967. goto unlock;
  1968. }
  1969. /* post card */
  1970. if (amdgpu_device_need_post(adev)) {
  1971. r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
  1972. if (r)
  1973. DRM_ERROR("amdgpu asic init failed\n");
  1974. }
  1975. r = amdgpu_device_ip_resume(adev);
  1976. if (r) {
  1977. DRM_ERROR("amdgpu_device_ip_resume failed (%d).\n", r);
  1978. goto unlock;
  1979. }
  1980. amdgpu_fence_driver_resume(adev);
  1981. if (resume) {
  1982. r = amdgpu_ib_ring_tests(adev);
  1983. if (r)
  1984. DRM_ERROR("ib ring test failed (%d).\n", r);
  1985. }
  1986. r = amdgpu_device_ip_late_init(adev);
  1987. if (r)
  1988. goto unlock;
  1989. /* pin cursors */
  1990. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1991. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1992. if (amdgpu_crtc->cursor_bo) {
  1993. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  1994. r = amdgpu_bo_reserve(aobj, true);
  1995. if (r == 0) {
  1996. r = amdgpu_bo_pin(aobj,
  1997. AMDGPU_GEM_DOMAIN_VRAM,
  1998. &amdgpu_crtc->cursor_addr);
  1999. if (r != 0)
  2000. DRM_ERROR("Failed to pin cursor BO (%d)\n", r);
  2001. amdgpu_bo_unreserve(aobj);
  2002. }
  2003. }
  2004. }
  2005. r = amdgpu_amdkfd_resume(adev);
  2006. if (r)
  2007. return r;
  2008. /* blat the mode back in */
  2009. if (fbcon) {
  2010. if (!amdgpu_device_has_dc_support(adev)) {
  2011. /* pre DCE11 */
  2012. drm_helper_resume_force_mode(dev);
  2013. /* turn on display hw */
  2014. drm_modeset_lock_all(dev);
  2015. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  2016. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
  2017. }
  2018. drm_modeset_unlock_all(dev);
  2019. }
  2020. }
  2021. drm_kms_helper_poll_enable(dev);
  2022. /*
  2023. * Most of the connector probing functions try to acquire runtime pm
  2024. * refs to ensure that the GPU is powered on when connector polling is
  2025. * performed. Since we're calling this from a runtime PM callback,
  2026. * trying to acquire rpm refs will cause us to deadlock.
  2027. *
  2028. * Since we're guaranteed to be holding the rpm lock, it's safe to
  2029. * temporarily disable the rpm helpers so this doesn't deadlock us.
  2030. */
  2031. #ifdef CONFIG_PM
  2032. dev->dev->power.disable_depth++;
  2033. #endif
  2034. if (!amdgpu_device_has_dc_support(adev))
  2035. drm_helper_hpd_irq_event(dev);
  2036. else
  2037. drm_kms_helper_hotplug_event(dev);
  2038. #ifdef CONFIG_PM
  2039. dev->dev->power.disable_depth--;
  2040. #endif
  2041. if (fbcon)
  2042. amdgpu_fbdev_set_suspend(adev, 0);
  2043. unlock:
  2044. if (fbcon)
  2045. console_unlock();
  2046. return r;
  2047. }
  2048. static bool amdgpu_device_ip_check_soft_reset(struct amdgpu_device *adev)
  2049. {
  2050. int i;
  2051. bool asic_hang = false;
  2052. if (amdgpu_sriov_vf(adev))
  2053. return true;
  2054. for (i = 0; i < adev->num_ip_blocks; i++) {
  2055. if (!adev->ip_blocks[i].status.valid)
  2056. continue;
  2057. if (adev->ip_blocks[i].version->funcs->check_soft_reset)
  2058. adev->ip_blocks[i].status.hang =
  2059. adev->ip_blocks[i].version->funcs->check_soft_reset(adev);
  2060. if (adev->ip_blocks[i].status.hang) {
  2061. DRM_INFO("IP block:%s is hung!\n", adev->ip_blocks[i].version->funcs->name);
  2062. asic_hang = true;
  2063. }
  2064. }
  2065. return asic_hang;
  2066. }
  2067. static int amdgpu_device_ip_pre_soft_reset(struct amdgpu_device *adev)
  2068. {
  2069. int i, r = 0;
  2070. for (i = 0; i < adev->num_ip_blocks; i++) {
  2071. if (!adev->ip_blocks[i].status.valid)
  2072. continue;
  2073. if (adev->ip_blocks[i].status.hang &&
  2074. adev->ip_blocks[i].version->funcs->pre_soft_reset) {
  2075. r = adev->ip_blocks[i].version->funcs->pre_soft_reset(adev);
  2076. if (r)
  2077. return r;
  2078. }
  2079. }
  2080. return 0;
  2081. }
  2082. static bool amdgpu_device_ip_need_full_reset(struct amdgpu_device *adev)
  2083. {
  2084. int i;
  2085. for (i = 0; i < adev->num_ip_blocks; i++) {
  2086. if (!adev->ip_blocks[i].status.valid)
  2087. continue;
  2088. if ((adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) ||
  2089. (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) ||
  2090. (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_ACP) ||
  2091. (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE) ||
  2092. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP) {
  2093. if (adev->ip_blocks[i].status.hang) {
  2094. DRM_INFO("Some block need full reset!\n");
  2095. return true;
  2096. }
  2097. }
  2098. }
  2099. return false;
  2100. }
  2101. static int amdgpu_device_ip_soft_reset(struct amdgpu_device *adev)
  2102. {
  2103. int i, r = 0;
  2104. for (i = 0; i < adev->num_ip_blocks; i++) {
  2105. if (!adev->ip_blocks[i].status.valid)
  2106. continue;
  2107. if (adev->ip_blocks[i].status.hang &&
  2108. adev->ip_blocks[i].version->funcs->soft_reset) {
  2109. r = adev->ip_blocks[i].version->funcs->soft_reset(adev);
  2110. if (r)
  2111. return r;
  2112. }
  2113. }
  2114. return 0;
  2115. }
  2116. static int amdgpu_device_ip_post_soft_reset(struct amdgpu_device *adev)
  2117. {
  2118. int i, r = 0;
  2119. for (i = 0; i < adev->num_ip_blocks; i++) {
  2120. if (!adev->ip_blocks[i].status.valid)
  2121. continue;
  2122. if (adev->ip_blocks[i].status.hang &&
  2123. adev->ip_blocks[i].version->funcs->post_soft_reset)
  2124. r = adev->ip_blocks[i].version->funcs->post_soft_reset(adev);
  2125. if (r)
  2126. return r;
  2127. }
  2128. return 0;
  2129. }
  2130. static int amdgpu_device_recover_vram_from_shadow(struct amdgpu_device *adev,
  2131. struct amdgpu_ring *ring,
  2132. struct amdgpu_bo *bo,
  2133. struct dma_fence **fence)
  2134. {
  2135. uint32_t domain;
  2136. int r;
  2137. if (!bo->shadow)
  2138. return 0;
  2139. r = amdgpu_bo_reserve(bo, true);
  2140. if (r)
  2141. return r;
  2142. domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
  2143. /* if bo has been evicted, then no need to recover */
  2144. if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
  2145. r = amdgpu_bo_validate(bo->shadow);
  2146. if (r) {
  2147. DRM_ERROR("bo validate failed!\n");
  2148. goto err;
  2149. }
  2150. r = amdgpu_bo_restore_from_shadow(adev, ring, bo,
  2151. NULL, fence, true);
  2152. if (r) {
  2153. DRM_ERROR("recover page table failed!\n");
  2154. goto err;
  2155. }
  2156. }
  2157. err:
  2158. amdgpu_bo_unreserve(bo);
  2159. return r;
  2160. }
  2161. static int amdgpu_device_handle_vram_lost(struct amdgpu_device *adev)
  2162. {
  2163. struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
  2164. struct amdgpu_bo *bo, *tmp;
  2165. struct dma_fence *fence = NULL, *next = NULL;
  2166. long r = 1;
  2167. int i = 0;
  2168. long tmo;
  2169. if (amdgpu_sriov_runtime(adev))
  2170. tmo = msecs_to_jiffies(amdgpu_lockup_timeout);
  2171. else
  2172. tmo = msecs_to_jiffies(100);
  2173. DRM_INFO("recover vram bo from shadow start\n");
  2174. mutex_lock(&adev->shadow_list_lock);
  2175. list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list) {
  2176. next = NULL;
  2177. amdgpu_device_recover_vram_from_shadow(adev, ring, bo, &next);
  2178. if (fence) {
  2179. r = dma_fence_wait_timeout(fence, false, tmo);
  2180. if (r == 0)
  2181. pr_err("wait fence %p[%d] timeout\n", fence, i);
  2182. else if (r < 0)
  2183. pr_err("wait fence %p[%d] interrupted\n", fence, i);
  2184. if (r < 1) {
  2185. dma_fence_put(fence);
  2186. fence = next;
  2187. break;
  2188. }
  2189. i++;
  2190. }
  2191. dma_fence_put(fence);
  2192. fence = next;
  2193. }
  2194. mutex_unlock(&adev->shadow_list_lock);
  2195. if (fence) {
  2196. r = dma_fence_wait_timeout(fence, false, tmo);
  2197. if (r == 0)
  2198. pr_err("wait fence %p[%d] timeout\n", fence, i);
  2199. else if (r < 0)
  2200. pr_err("wait fence %p[%d] interrupted\n", fence, i);
  2201. }
  2202. dma_fence_put(fence);
  2203. if (r > 0)
  2204. DRM_INFO("recover vram bo from shadow done\n");
  2205. else
  2206. DRM_ERROR("recover vram bo from shadow failed\n");
  2207. return (r > 0?0:1);
  2208. }
  2209. /*
  2210. * amdgpu_device_reset - reset ASIC/GPU for bare-metal or passthrough
  2211. *
  2212. * @adev: amdgpu device pointer
  2213. *
  2214. * attempt to do soft-reset or full-reset and reinitialize Asic
  2215. * return 0 means successed otherwise failed
  2216. */
  2217. static int amdgpu_device_reset(struct amdgpu_device *adev)
  2218. {
  2219. bool need_full_reset, vram_lost = 0;
  2220. int r;
  2221. need_full_reset = amdgpu_device_ip_need_full_reset(adev);
  2222. if (!need_full_reset) {
  2223. amdgpu_device_ip_pre_soft_reset(adev);
  2224. r = amdgpu_device_ip_soft_reset(adev);
  2225. amdgpu_device_ip_post_soft_reset(adev);
  2226. if (r || amdgpu_device_ip_check_soft_reset(adev)) {
  2227. DRM_INFO("soft reset failed, will fallback to full reset!\n");
  2228. need_full_reset = true;
  2229. }
  2230. }
  2231. if (need_full_reset) {
  2232. r = amdgpu_device_ip_suspend(adev);
  2233. retry:
  2234. r = amdgpu_asic_reset(adev);
  2235. /* post card */
  2236. amdgpu_atom_asic_init(adev->mode_info.atom_context);
  2237. if (!r) {
  2238. dev_info(adev->dev, "GPU reset succeeded, trying to resume\n");
  2239. r = amdgpu_device_ip_resume_phase1(adev);
  2240. if (r)
  2241. goto out;
  2242. vram_lost = amdgpu_device_check_vram_lost(adev);
  2243. if (vram_lost) {
  2244. DRM_ERROR("VRAM is lost!\n");
  2245. atomic_inc(&adev->vram_lost_counter);
  2246. }
  2247. r = amdgpu_gtt_mgr_recover(
  2248. &adev->mman.bdev.man[TTM_PL_TT]);
  2249. if (r)
  2250. goto out;
  2251. r = amdgpu_device_ip_resume_phase2(adev);
  2252. if (r)
  2253. goto out;
  2254. if (vram_lost)
  2255. amdgpu_device_fill_reset_magic(adev);
  2256. }
  2257. }
  2258. out:
  2259. if (!r) {
  2260. amdgpu_irq_gpu_reset_resume_helper(adev);
  2261. r = amdgpu_ib_ring_tests(adev);
  2262. if (r) {
  2263. dev_err(adev->dev, "ib ring test failed (%d).\n", r);
  2264. r = amdgpu_device_ip_suspend(adev);
  2265. need_full_reset = true;
  2266. goto retry;
  2267. }
  2268. }
  2269. if (!r && ((need_full_reset && !(adev->flags & AMD_IS_APU)) || vram_lost))
  2270. r = amdgpu_device_handle_vram_lost(adev);
  2271. return r;
  2272. }
  2273. /*
  2274. * amdgpu_device_reset_sriov - reset ASIC for SR-IOV vf
  2275. *
  2276. * @adev: amdgpu device pointer
  2277. *
  2278. * do VF FLR and reinitialize Asic
  2279. * return 0 means successed otherwise failed
  2280. */
  2281. static int amdgpu_device_reset_sriov(struct amdgpu_device *adev, bool from_hypervisor)
  2282. {
  2283. int r;
  2284. if (from_hypervisor)
  2285. r = amdgpu_virt_request_full_gpu(adev, true);
  2286. else
  2287. r = amdgpu_virt_reset_gpu(adev);
  2288. if (r)
  2289. return r;
  2290. /* Resume IP prior to SMC */
  2291. r = amdgpu_device_ip_reinit_early_sriov(adev);
  2292. if (r)
  2293. goto error;
  2294. /* we need recover gart prior to run SMC/CP/SDMA resume */
  2295. amdgpu_gtt_mgr_recover(&adev->mman.bdev.man[TTM_PL_TT]);
  2296. /* now we are okay to resume SMC/CP/SDMA */
  2297. r = amdgpu_device_ip_reinit_late_sriov(adev);
  2298. amdgpu_virt_release_full_gpu(adev, true);
  2299. if (r)
  2300. goto error;
  2301. amdgpu_irq_gpu_reset_resume_helper(adev);
  2302. r = amdgpu_ib_ring_tests(adev);
  2303. if (!r && adev->virt.gim_feature & AMDGIM_FEATURE_GIM_FLR_VRAMLOST) {
  2304. atomic_inc(&adev->vram_lost_counter);
  2305. r = amdgpu_device_handle_vram_lost(adev);
  2306. }
  2307. error:
  2308. return r;
  2309. }
  2310. /**
  2311. * amdgpu_device_gpu_recover - reset the asic and recover scheduler
  2312. *
  2313. * @adev: amdgpu device pointer
  2314. * @job: which job trigger hang
  2315. * @force forces reset regardless of amdgpu_gpu_recovery
  2316. *
  2317. * Attempt to reset the GPU if it has hung (all asics).
  2318. * Returns 0 for success or an error on failure.
  2319. */
  2320. int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  2321. struct amdgpu_job *job, bool force)
  2322. {
  2323. struct drm_atomic_state *state = NULL;
  2324. int i, r, resched;
  2325. if (!force && !amdgpu_device_ip_check_soft_reset(adev)) {
  2326. DRM_INFO("No hardware hang detected. Did some blocks stall?\n");
  2327. return 0;
  2328. }
  2329. if (!force && (amdgpu_gpu_recovery == 0 ||
  2330. (amdgpu_gpu_recovery == -1 && !amdgpu_sriov_vf(adev)))) {
  2331. DRM_INFO("GPU recovery disabled.\n");
  2332. return 0;
  2333. }
  2334. dev_info(adev->dev, "GPU reset begin!\n");
  2335. mutex_lock(&adev->lock_reset);
  2336. atomic_inc(&adev->gpu_reset_counter);
  2337. adev->in_gpu_reset = 1;
  2338. /* block TTM */
  2339. resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
  2340. /* store modesetting */
  2341. if (amdgpu_device_has_dc_support(adev))
  2342. state = drm_atomic_helper_suspend(adev->ddev);
  2343. /* block all schedulers and reset given job's ring */
  2344. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  2345. struct amdgpu_ring *ring = adev->rings[i];
  2346. if (!ring || !ring->sched.thread)
  2347. continue;
  2348. kthread_park(ring->sched.thread);
  2349. if (job && job->ring->idx != i)
  2350. continue;
  2351. drm_sched_hw_job_reset(&ring->sched, &job->base);
  2352. /* after all hw jobs are reset, hw fence is meaningless, so force_completion */
  2353. amdgpu_fence_driver_force_completion(ring);
  2354. }
  2355. if (amdgpu_sriov_vf(adev))
  2356. r = amdgpu_device_reset_sriov(adev, job ? false : true);
  2357. else
  2358. r = amdgpu_device_reset(adev);
  2359. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  2360. struct amdgpu_ring *ring = adev->rings[i];
  2361. if (!ring || !ring->sched.thread)
  2362. continue;
  2363. /* only need recovery sched of the given job's ring
  2364. * or all rings (in the case @job is NULL)
  2365. * after above amdgpu_reset accomplished
  2366. */
  2367. if ((!job || job->ring->idx == i) && !r)
  2368. drm_sched_job_recovery(&ring->sched);
  2369. kthread_unpark(ring->sched.thread);
  2370. }
  2371. if (amdgpu_device_has_dc_support(adev)) {
  2372. if (drm_atomic_helper_resume(adev->ddev, state))
  2373. dev_info(adev->dev, "drm resume failed:%d\n", r);
  2374. } else {
  2375. drm_helper_resume_force_mode(adev->ddev);
  2376. }
  2377. ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched);
  2378. if (r) {
  2379. /* bad news, how to tell it to userspace ? */
  2380. dev_info(adev->dev, "GPU reset(%d) failed\n", atomic_read(&adev->gpu_reset_counter));
  2381. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_GPU_RESET_FAIL, 0, r);
  2382. } else {
  2383. dev_info(adev->dev, "GPU reset(%d) successed!\n",atomic_read(&adev->gpu_reset_counter));
  2384. }
  2385. amdgpu_vf_error_trans_all(adev);
  2386. adev->in_gpu_reset = 0;
  2387. mutex_unlock(&adev->lock_reset);
  2388. return r;
  2389. }
  2390. void amdgpu_device_get_pcie_info(struct amdgpu_device *adev)
  2391. {
  2392. u32 mask;
  2393. int ret;
  2394. if (amdgpu_pcie_gen_cap)
  2395. adev->pm.pcie_gen_mask = amdgpu_pcie_gen_cap;
  2396. if (amdgpu_pcie_lane_cap)
  2397. adev->pm.pcie_mlw_mask = amdgpu_pcie_lane_cap;
  2398. /* covers APUs as well */
  2399. if (pci_is_root_bus(adev->pdev->bus)) {
  2400. if (adev->pm.pcie_gen_mask == 0)
  2401. adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
  2402. if (adev->pm.pcie_mlw_mask == 0)
  2403. adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
  2404. return;
  2405. }
  2406. if (adev->pm.pcie_gen_mask == 0) {
  2407. ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask);
  2408. if (!ret) {
  2409. adev->pm.pcie_gen_mask = (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
  2410. CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
  2411. CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3);
  2412. if (mask & DRM_PCIE_SPEED_25)
  2413. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1;
  2414. if (mask & DRM_PCIE_SPEED_50)
  2415. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2;
  2416. if (mask & DRM_PCIE_SPEED_80)
  2417. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3;
  2418. } else {
  2419. adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
  2420. }
  2421. }
  2422. if (adev->pm.pcie_mlw_mask == 0) {
  2423. ret = drm_pcie_get_max_link_width(adev->ddev, &mask);
  2424. if (!ret) {
  2425. switch (mask) {
  2426. case 32:
  2427. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 |
  2428. CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
  2429. CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  2430. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2431. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2432. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2433. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2434. break;
  2435. case 16:
  2436. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
  2437. CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  2438. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2439. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2440. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2441. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2442. break;
  2443. case 12:
  2444. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  2445. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2446. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2447. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2448. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2449. break;
  2450. case 8:
  2451. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2452. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2453. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2454. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2455. break;
  2456. case 4:
  2457. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2458. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2459. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2460. break;
  2461. case 2:
  2462. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2463. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2464. break;
  2465. case 1:
  2466. adev->pm.pcie_mlw_mask = CAIL_PCIE_LINK_WIDTH_SUPPORT_X1;
  2467. break;
  2468. default:
  2469. break;
  2470. }
  2471. } else {
  2472. adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
  2473. }
  2474. }
  2475. }