amdgpu_device.c 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043
  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 <linux/debugfs.h>
  32. #include <drm/drmP.h>
  33. #include <drm/drm_crtc_helper.h>
  34. #include <drm/drm_atomic_helper.h>
  35. #include <drm/amdgpu_drm.h>
  36. #include <linux/vgaarb.h>
  37. #include <linux/vga_switcheroo.h>
  38. #include <linux/efi.h>
  39. #include "amdgpu.h"
  40. #include "amdgpu_trace.h"
  41. #include "amdgpu_i2c.h"
  42. #include "atom.h"
  43. #include "amdgpu_atombios.h"
  44. #include "amdgpu_atomfirmware.h"
  45. #include "amd_pcie.h"
  46. #ifdef CONFIG_DRM_AMDGPU_SI
  47. #include "si.h"
  48. #endif
  49. #ifdef CONFIG_DRM_AMDGPU_CIK
  50. #include "cik.h"
  51. #endif
  52. #include "vi.h"
  53. #include "soc15.h"
  54. #include "bif/bif_4_1_d.h"
  55. #include <linux/pci.h>
  56. #include <linux/firmware.h>
  57. #include "amdgpu_vf_error.h"
  58. #include "amdgpu_amdkfd.h"
  59. #include "amdgpu_pm.h"
  60. MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin");
  61. MODULE_FIRMWARE("amdgpu/raven_gpu_info.bin");
  62. #define AMDGPU_RESUME_MS 2000
  63. static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev);
  64. static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev);
  65. static int amdgpu_debugfs_test_ib_ring_init(struct amdgpu_device *adev);
  66. static int amdgpu_debugfs_vbios_dump_init(struct amdgpu_device *adev);
  67. static const char *amdgpu_asic_name[] = {
  68. "TAHITI",
  69. "PITCAIRN",
  70. "VERDE",
  71. "OLAND",
  72. "HAINAN",
  73. "BONAIRE",
  74. "KAVERI",
  75. "KABINI",
  76. "HAWAII",
  77. "MULLINS",
  78. "TOPAZ",
  79. "TONGA",
  80. "FIJI",
  81. "CARRIZO",
  82. "STONEY",
  83. "POLARIS10",
  84. "POLARIS11",
  85. "POLARIS12",
  86. "VEGA10",
  87. "RAVEN",
  88. "LAST",
  89. };
  90. bool amdgpu_device_is_px(struct drm_device *dev)
  91. {
  92. struct amdgpu_device *adev = dev->dev_private;
  93. if (adev->flags & AMD_IS_PX)
  94. return true;
  95. return false;
  96. }
  97. /*
  98. * MMIO register access helper functions.
  99. */
  100. uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
  101. uint32_t acc_flags)
  102. {
  103. uint32_t ret;
  104. if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
  105. return amdgpu_virt_kiq_rreg(adev, reg);
  106. if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
  107. ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
  108. else {
  109. unsigned long flags;
  110. spin_lock_irqsave(&adev->mmio_idx_lock, flags);
  111. writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
  112. ret = readl(((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
  113. spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
  114. }
  115. trace_amdgpu_mm_rreg(adev->pdev->device, reg, ret);
  116. return ret;
  117. }
  118. void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
  119. uint32_t acc_flags)
  120. {
  121. trace_amdgpu_mm_wreg(adev->pdev->device, reg, v);
  122. if (adev->asic_type >= CHIP_VEGA10 && reg == 0) {
  123. adev->last_mm_index = v;
  124. }
  125. if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
  126. return amdgpu_virt_kiq_wreg(adev, reg, v);
  127. if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
  128. writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
  129. else {
  130. unsigned long flags;
  131. spin_lock_irqsave(&adev->mmio_idx_lock, flags);
  132. writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
  133. writel(v, ((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
  134. spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
  135. }
  136. if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) {
  137. udelay(500);
  138. }
  139. }
  140. u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg)
  141. {
  142. if ((reg * 4) < adev->rio_mem_size)
  143. return ioread32(adev->rio_mem + (reg * 4));
  144. else {
  145. iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
  146. return ioread32(adev->rio_mem + (mmMM_DATA * 4));
  147. }
  148. }
  149. void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  150. {
  151. if (adev->asic_type >= CHIP_VEGA10 && reg == 0) {
  152. adev->last_mm_index = v;
  153. }
  154. if ((reg * 4) < adev->rio_mem_size)
  155. iowrite32(v, adev->rio_mem + (reg * 4));
  156. else {
  157. iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
  158. iowrite32(v, adev->rio_mem + (mmMM_DATA * 4));
  159. }
  160. if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) {
  161. udelay(500);
  162. }
  163. }
  164. /**
  165. * amdgpu_mm_rdoorbell - read a doorbell dword
  166. *
  167. * @adev: amdgpu_device pointer
  168. * @index: doorbell index
  169. *
  170. * Returns the value in the doorbell aperture at the
  171. * requested doorbell index (CIK).
  172. */
  173. u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index)
  174. {
  175. if (index < adev->doorbell.num_doorbells) {
  176. return readl(adev->doorbell.ptr + index);
  177. } else {
  178. DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
  179. return 0;
  180. }
  181. }
  182. /**
  183. * amdgpu_mm_wdoorbell - write a doorbell dword
  184. *
  185. * @adev: amdgpu_device pointer
  186. * @index: doorbell index
  187. * @v: value to write
  188. *
  189. * Writes @v to the doorbell aperture at the
  190. * requested doorbell index (CIK).
  191. */
  192. void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v)
  193. {
  194. if (index < adev->doorbell.num_doorbells) {
  195. writel(v, adev->doorbell.ptr + index);
  196. } else {
  197. DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
  198. }
  199. }
  200. /**
  201. * amdgpu_mm_rdoorbell64 - read a doorbell Qword
  202. *
  203. * @adev: amdgpu_device pointer
  204. * @index: doorbell index
  205. *
  206. * Returns the value in the doorbell aperture at the
  207. * requested doorbell index (VEGA10+).
  208. */
  209. u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index)
  210. {
  211. if (index < adev->doorbell.num_doorbells) {
  212. return atomic64_read((atomic64_t *)(adev->doorbell.ptr + index));
  213. } else {
  214. DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
  215. return 0;
  216. }
  217. }
  218. /**
  219. * amdgpu_mm_wdoorbell64 - write a doorbell Qword
  220. *
  221. * @adev: amdgpu_device pointer
  222. * @index: doorbell index
  223. * @v: value to write
  224. *
  225. * Writes @v to the doorbell aperture at the
  226. * requested doorbell index (VEGA10+).
  227. */
  228. void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v)
  229. {
  230. if (index < adev->doorbell.num_doorbells) {
  231. atomic64_set((atomic64_t *)(adev->doorbell.ptr + index), v);
  232. } else {
  233. DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
  234. }
  235. }
  236. /**
  237. * amdgpu_invalid_rreg - dummy reg read function
  238. *
  239. * @adev: amdgpu device pointer
  240. * @reg: offset of register
  241. *
  242. * Dummy register read function. Used for register blocks
  243. * that certain asics don't have (all asics).
  244. * Returns the value in the register.
  245. */
  246. static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg)
  247. {
  248. DRM_ERROR("Invalid callback to read register 0x%04X\n", reg);
  249. BUG();
  250. return 0;
  251. }
  252. /**
  253. * amdgpu_invalid_wreg - dummy reg write function
  254. *
  255. * @adev: amdgpu device pointer
  256. * @reg: offset of register
  257. * @v: value to write to the register
  258. *
  259. * Dummy register read function. Used for register blocks
  260. * that certain asics don't have (all asics).
  261. */
  262. static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
  263. {
  264. DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n",
  265. reg, v);
  266. BUG();
  267. }
  268. /**
  269. * amdgpu_block_invalid_rreg - dummy reg read function
  270. *
  271. * @adev: amdgpu device pointer
  272. * @block: offset of instance
  273. * @reg: offset of register
  274. *
  275. * Dummy register read function. Used for register blocks
  276. * that certain asics don't have (all asics).
  277. * Returns the value in the register.
  278. */
  279. static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev,
  280. uint32_t block, uint32_t reg)
  281. {
  282. DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n",
  283. reg, block);
  284. BUG();
  285. return 0;
  286. }
  287. /**
  288. * amdgpu_block_invalid_wreg - dummy reg write function
  289. *
  290. * @adev: amdgpu device pointer
  291. * @block: offset of instance
  292. * @reg: offset of register
  293. * @v: value to write to the register
  294. *
  295. * Dummy register read function. Used for register blocks
  296. * that certain asics don't have (all asics).
  297. */
  298. static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev,
  299. uint32_t block,
  300. uint32_t reg, uint32_t v)
  301. {
  302. DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n",
  303. reg, block, v);
  304. BUG();
  305. }
  306. static int amdgpu_vram_scratch_init(struct amdgpu_device *adev)
  307. {
  308. return amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE,
  309. PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
  310. &adev->vram_scratch.robj,
  311. &adev->vram_scratch.gpu_addr,
  312. (void **)&adev->vram_scratch.ptr);
  313. }
  314. static void amdgpu_vram_scratch_fini(struct amdgpu_device *adev)
  315. {
  316. amdgpu_bo_free_kernel(&adev->vram_scratch.robj, NULL, NULL);
  317. }
  318. /**
  319. * amdgpu_program_register_sequence - program an array of registers.
  320. *
  321. * @adev: amdgpu_device pointer
  322. * @registers: pointer to the register array
  323. * @array_size: size of the register array
  324. *
  325. * Programs an array or registers with and and or masks.
  326. * This is a helper for setting golden registers.
  327. */
  328. void amdgpu_program_register_sequence(struct amdgpu_device *adev,
  329. const u32 *registers,
  330. const u32 array_size)
  331. {
  332. u32 tmp, reg, and_mask, or_mask;
  333. int i;
  334. if (array_size % 3)
  335. return;
  336. for (i = 0; i < array_size; i +=3) {
  337. reg = registers[i + 0];
  338. and_mask = registers[i + 1];
  339. or_mask = registers[i + 2];
  340. if (and_mask == 0xffffffff) {
  341. tmp = or_mask;
  342. } else {
  343. tmp = RREG32(reg);
  344. tmp &= ~and_mask;
  345. tmp |= or_mask;
  346. }
  347. WREG32(reg, tmp);
  348. }
  349. }
  350. void amdgpu_pci_config_reset(struct amdgpu_device *adev)
  351. {
  352. pci_write_config_dword(adev->pdev, 0x7c, AMDGPU_ASIC_RESET_DATA);
  353. }
  354. /*
  355. * GPU doorbell aperture helpers function.
  356. */
  357. /**
  358. * amdgpu_doorbell_init - Init doorbell driver information.
  359. *
  360. * @adev: amdgpu_device pointer
  361. *
  362. * Init doorbell driver information (CIK)
  363. * Returns 0 on success, error on failure.
  364. */
  365. static int amdgpu_doorbell_init(struct amdgpu_device *adev)
  366. {
  367. /* No doorbell on SI hardware generation */
  368. if (adev->asic_type < CHIP_BONAIRE) {
  369. adev->doorbell.base = 0;
  370. adev->doorbell.size = 0;
  371. adev->doorbell.num_doorbells = 0;
  372. adev->doorbell.ptr = NULL;
  373. return 0;
  374. }
  375. if (pci_resource_flags(adev->pdev, 2) & IORESOURCE_UNSET)
  376. return -EINVAL;
  377. /* doorbell bar mapping */
  378. adev->doorbell.base = pci_resource_start(adev->pdev, 2);
  379. adev->doorbell.size = pci_resource_len(adev->pdev, 2);
  380. adev->doorbell.num_doorbells = min_t(u32, adev->doorbell.size / sizeof(u32),
  381. AMDGPU_DOORBELL_MAX_ASSIGNMENT+1);
  382. if (adev->doorbell.num_doorbells == 0)
  383. return -EINVAL;
  384. adev->doorbell.ptr = ioremap(adev->doorbell.base,
  385. adev->doorbell.num_doorbells *
  386. sizeof(u32));
  387. if (adev->doorbell.ptr == NULL)
  388. return -ENOMEM;
  389. return 0;
  390. }
  391. /**
  392. * amdgpu_doorbell_fini - Tear down doorbell driver information.
  393. *
  394. * @adev: amdgpu_device pointer
  395. *
  396. * Tear down doorbell driver information (CIK)
  397. */
  398. static void amdgpu_doorbell_fini(struct amdgpu_device *adev)
  399. {
  400. iounmap(adev->doorbell.ptr);
  401. adev->doorbell.ptr = NULL;
  402. }
  403. /**
  404. * amdgpu_doorbell_get_kfd_info - Report doorbell configuration required to
  405. * setup amdkfd
  406. *
  407. * @adev: amdgpu_device pointer
  408. * @aperture_base: output returning doorbell aperture base physical address
  409. * @aperture_size: output returning doorbell aperture size in bytes
  410. * @start_offset: output returning # of doorbell bytes reserved for amdgpu.
  411. *
  412. * amdgpu and amdkfd share the doorbell aperture. amdgpu sets it up,
  413. * takes doorbells required for its own rings and reports the setup to amdkfd.
  414. * amdgpu reserved doorbells are at the start of the doorbell aperture.
  415. */
  416. void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
  417. phys_addr_t *aperture_base,
  418. size_t *aperture_size,
  419. size_t *start_offset)
  420. {
  421. /*
  422. * The first num_doorbells are used by amdgpu.
  423. * amdkfd takes whatever's left in the aperture.
  424. */
  425. if (adev->doorbell.size > adev->doorbell.num_doorbells * sizeof(u32)) {
  426. *aperture_base = adev->doorbell.base;
  427. *aperture_size = adev->doorbell.size;
  428. *start_offset = adev->doorbell.num_doorbells * sizeof(u32);
  429. } else {
  430. *aperture_base = 0;
  431. *aperture_size = 0;
  432. *start_offset = 0;
  433. }
  434. }
  435. /*
  436. * amdgpu_wb_*()
  437. * Writeback is the method by which the GPU updates special pages in memory
  438. * with the status of certain GPU events (fences, ring pointers,etc.).
  439. */
  440. /**
  441. * amdgpu_wb_fini - Disable Writeback and free memory
  442. *
  443. * @adev: amdgpu_device pointer
  444. *
  445. * Disables Writeback and frees the Writeback memory (all asics).
  446. * Used at driver shutdown.
  447. */
  448. static void amdgpu_wb_fini(struct amdgpu_device *adev)
  449. {
  450. if (adev->wb.wb_obj) {
  451. amdgpu_bo_free_kernel(&adev->wb.wb_obj,
  452. &adev->wb.gpu_addr,
  453. (void **)&adev->wb.wb);
  454. adev->wb.wb_obj = NULL;
  455. }
  456. }
  457. /**
  458. * amdgpu_wb_init- Init Writeback driver info and allocate memory
  459. *
  460. * @adev: amdgpu_device pointer
  461. *
  462. * Initializes writeback and allocates writeback memory (all asics).
  463. * Used at driver startup.
  464. * Returns 0 on success or an -error on failure.
  465. */
  466. static int amdgpu_wb_init(struct amdgpu_device *adev)
  467. {
  468. int r;
  469. if (adev->wb.wb_obj == NULL) {
  470. /* AMDGPU_MAX_WB * sizeof(uint32_t) * 8 = AMDGPU_MAX_WB 256bit slots */
  471. r = amdgpu_bo_create_kernel(adev, AMDGPU_MAX_WB * sizeof(uint32_t) * 8,
  472. PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
  473. &adev->wb.wb_obj, &adev->wb.gpu_addr,
  474. (void **)&adev->wb.wb);
  475. if (r) {
  476. dev_warn(adev->dev, "(%d) create WB bo failed\n", r);
  477. return r;
  478. }
  479. adev->wb.num_wb = AMDGPU_MAX_WB;
  480. memset(&adev->wb.used, 0, sizeof(adev->wb.used));
  481. /* clear wb memory */
  482. memset((char *)adev->wb.wb, 0, AMDGPU_MAX_WB * sizeof(uint32_t));
  483. }
  484. return 0;
  485. }
  486. /**
  487. * amdgpu_wb_get - Allocate a wb entry
  488. *
  489. * @adev: amdgpu_device pointer
  490. * @wb: wb index
  491. *
  492. * Allocate a wb slot for use by the driver (all asics).
  493. * Returns 0 on success or -EINVAL on failure.
  494. */
  495. int amdgpu_wb_get(struct amdgpu_device *adev, u32 *wb)
  496. {
  497. unsigned long offset = find_first_zero_bit(adev->wb.used, adev->wb.num_wb);
  498. if (offset < adev->wb.num_wb) {
  499. __set_bit(offset, adev->wb.used);
  500. *wb = offset << 3; /* convert to dw offset */
  501. return 0;
  502. } else {
  503. return -EINVAL;
  504. }
  505. }
  506. /**
  507. * amdgpu_wb_free - Free a wb entry
  508. *
  509. * @adev: amdgpu_device pointer
  510. * @wb: wb index
  511. *
  512. * Free a wb slot allocated for use by the driver (all asics)
  513. */
  514. void amdgpu_wb_free(struct amdgpu_device *adev, u32 wb)
  515. {
  516. if (wb < adev->wb.num_wb)
  517. __clear_bit(wb >> 3, adev->wb.used);
  518. }
  519. /**
  520. * amdgpu_vram_location - try to find VRAM location
  521. * @adev: amdgpu device structure holding all necessary informations
  522. * @mc: memory controller structure holding memory informations
  523. * @base: base address at which to put VRAM
  524. *
  525. * Function will try to place VRAM at base address provided
  526. * as parameter.
  527. */
  528. void amdgpu_vram_location(struct amdgpu_device *adev, struct amdgpu_mc *mc, u64 base)
  529. {
  530. uint64_t limit = (uint64_t)amdgpu_vram_limit << 20;
  531. mc->vram_start = base;
  532. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  533. if (limit && limit < mc->real_vram_size)
  534. mc->real_vram_size = limit;
  535. dev_info(adev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
  536. mc->mc_vram_size >> 20, mc->vram_start,
  537. mc->vram_end, mc->real_vram_size >> 20);
  538. }
  539. /**
  540. * amdgpu_gart_location - try to find GTT location
  541. * @adev: amdgpu device structure holding all necessary informations
  542. * @mc: memory controller structure holding memory informations
  543. *
  544. * Function will place try to place GTT before or after VRAM.
  545. *
  546. * If GTT size is bigger than space left then we ajust GTT size.
  547. * Thus function will never fails.
  548. *
  549. * FIXME: when reducing GTT size align new size on power of 2.
  550. */
  551. void amdgpu_gart_location(struct amdgpu_device *adev, struct amdgpu_mc *mc)
  552. {
  553. u64 size_af, size_bf;
  554. size_af = adev->mc.mc_mask - mc->vram_end;
  555. size_bf = mc->vram_start;
  556. if (size_bf > size_af) {
  557. if (mc->gart_size > size_bf) {
  558. dev_warn(adev->dev, "limiting GTT\n");
  559. mc->gart_size = size_bf;
  560. }
  561. mc->gart_start = 0;
  562. } else {
  563. if (mc->gart_size > size_af) {
  564. dev_warn(adev->dev, "limiting GTT\n");
  565. mc->gart_size = size_af;
  566. }
  567. /* VCE doesn't like it when BOs cross a 4GB segment, so align
  568. * the GART base on a 4GB boundary as well.
  569. */
  570. mc->gart_start = ALIGN(mc->vram_end + 1, 0x100000000ULL);
  571. }
  572. mc->gart_end = mc->gart_start + mc->gart_size - 1;
  573. dev_info(adev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
  574. mc->gart_size >> 20, mc->gart_start, mc->gart_end);
  575. }
  576. /*
  577. * Firmware Reservation functions
  578. */
  579. /**
  580. * amdgpu_fw_reserve_vram_fini - free fw reserved vram
  581. *
  582. * @adev: amdgpu_device pointer
  583. *
  584. * free fw reserved vram if it has been reserved.
  585. */
  586. void amdgpu_fw_reserve_vram_fini(struct amdgpu_device *adev)
  587. {
  588. amdgpu_bo_free_kernel(&adev->fw_vram_usage.reserved_bo,
  589. NULL, &adev->fw_vram_usage.va);
  590. }
  591. /**
  592. * amdgpu_fw_reserve_vram_init - create bo vram reservation from fw
  593. *
  594. * @adev: amdgpu_device pointer
  595. *
  596. * create bo vram reservation from fw.
  597. */
  598. int amdgpu_fw_reserve_vram_init(struct amdgpu_device *adev)
  599. {
  600. struct ttm_operation_ctx ctx = { false, false };
  601. int r = 0;
  602. int i;
  603. u64 vram_size = adev->mc.visible_vram_size;
  604. u64 offset = adev->fw_vram_usage.start_offset;
  605. u64 size = adev->fw_vram_usage.size;
  606. struct amdgpu_bo *bo;
  607. adev->fw_vram_usage.va = NULL;
  608. adev->fw_vram_usage.reserved_bo = NULL;
  609. if (adev->fw_vram_usage.size > 0 &&
  610. adev->fw_vram_usage.size <= vram_size) {
  611. r = amdgpu_bo_create(adev, adev->fw_vram_usage.size,
  612. PAGE_SIZE, true, AMDGPU_GEM_DOMAIN_VRAM,
  613. AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
  614. AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS, NULL, NULL, 0,
  615. &adev->fw_vram_usage.reserved_bo);
  616. if (r)
  617. goto error_create;
  618. r = amdgpu_bo_reserve(adev->fw_vram_usage.reserved_bo, false);
  619. if (r)
  620. goto error_reserve;
  621. /* remove the original mem node and create a new one at the
  622. * request position
  623. */
  624. bo = adev->fw_vram_usage.reserved_bo;
  625. offset = ALIGN(offset, PAGE_SIZE);
  626. for (i = 0; i < bo->placement.num_placement; ++i) {
  627. bo->placements[i].fpfn = offset >> PAGE_SHIFT;
  628. bo->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;
  629. }
  630. ttm_bo_mem_put(&bo->tbo, &bo->tbo.mem);
  631. r = ttm_bo_mem_space(&bo->tbo, &bo->placement,
  632. &bo->tbo.mem, &ctx);
  633. if (r)
  634. goto error_pin;
  635. r = amdgpu_bo_pin_restricted(adev->fw_vram_usage.reserved_bo,
  636. AMDGPU_GEM_DOMAIN_VRAM,
  637. adev->fw_vram_usage.start_offset,
  638. (adev->fw_vram_usage.start_offset +
  639. adev->fw_vram_usage.size), NULL);
  640. if (r)
  641. goto error_pin;
  642. r = amdgpu_bo_kmap(adev->fw_vram_usage.reserved_bo,
  643. &adev->fw_vram_usage.va);
  644. if (r)
  645. goto error_kmap;
  646. amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);
  647. }
  648. return r;
  649. error_kmap:
  650. amdgpu_bo_unpin(adev->fw_vram_usage.reserved_bo);
  651. error_pin:
  652. amdgpu_bo_unreserve(adev->fw_vram_usage.reserved_bo);
  653. error_reserve:
  654. amdgpu_bo_unref(&adev->fw_vram_usage.reserved_bo);
  655. error_create:
  656. adev->fw_vram_usage.va = NULL;
  657. adev->fw_vram_usage.reserved_bo = NULL;
  658. return r;
  659. }
  660. /**
  661. * amdgpu_device_resize_fb_bar - try to resize FB BAR
  662. *
  663. * @adev: amdgpu_device pointer
  664. *
  665. * Try to resize FB BAR to make all VRAM CPU accessible. We try very hard not
  666. * to fail, but if any of the BARs is not accessible after the size we abort
  667. * driver loading by returning -ENODEV.
  668. */
  669. int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
  670. {
  671. u64 space_needed = roundup_pow_of_two(adev->mc.real_vram_size);
  672. u32 rbar_size = order_base_2(((space_needed >> 20) | 1)) - 1;
  673. struct pci_bus *root;
  674. struct resource *res;
  675. unsigned i;
  676. u16 cmd;
  677. int r;
  678. /* Bypass for VF */
  679. if (amdgpu_sriov_vf(adev))
  680. return 0;
  681. /* Check if the root BUS has 64bit memory resources */
  682. root = adev->pdev->bus;
  683. while (root->parent)
  684. root = root->parent;
  685. pci_bus_for_each_resource(root, res, i) {
  686. if (res && res->flags & IORESOURCE_MEM_64 &&
  687. res->start > 0x100000000ull)
  688. break;
  689. }
  690. /* Trying to resize is pointless without a root hub window above 4GB */
  691. if (!res)
  692. return 0;
  693. /* Disable memory decoding while we change the BAR addresses and size */
  694. pci_read_config_word(adev->pdev, PCI_COMMAND, &cmd);
  695. pci_write_config_word(adev->pdev, PCI_COMMAND,
  696. cmd & ~PCI_COMMAND_MEMORY);
  697. /* Free the VRAM and doorbell BAR, we most likely need to move both. */
  698. amdgpu_doorbell_fini(adev);
  699. if (adev->asic_type >= CHIP_BONAIRE)
  700. pci_release_resource(adev->pdev, 2);
  701. pci_release_resource(adev->pdev, 0);
  702. r = pci_resize_resource(adev->pdev, 0, rbar_size);
  703. if (r == -ENOSPC)
  704. DRM_INFO("Not enough PCI address space for a large BAR.");
  705. else if (r && r != -ENOTSUPP)
  706. DRM_ERROR("Problem resizing BAR0 (%d).", r);
  707. pci_assign_unassigned_bus_resources(adev->pdev->bus);
  708. /* When the doorbell or fb BAR isn't available we have no chance of
  709. * using the device.
  710. */
  711. r = amdgpu_doorbell_init(adev);
  712. if (r || (pci_resource_flags(adev->pdev, 0) & IORESOURCE_UNSET))
  713. return -ENODEV;
  714. pci_write_config_word(adev->pdev, PCI_COMMAND, cmd);
  715. return 0;
  716. }
  717. /*
  718. * GPU helpers function.
  719. */
  720. /**
  721. * amdgpu_need_post - check if the hw need post or not
  722. *
  723. * @adev: amdgpu_device pointer
  724. *
  725. * Check if the asic has been initialized (all asics) at driver startup
  726. * or post is needed if hw reset is performed.
  727. * Returns true if need or false if not.
  728. */
  729. bool amdgpu_need_post(struct amdgpu_device *adev)
  730. {
  731. uint32_t reg;
  732. if (amdgpu_sriov_vf(adev))
  733. return false;
  734. if (amdgpu_passthrough(adev)) {
  735. /* for FIJI: In whole GPU pass-through virtualization case, after VM reboot
  736. * some old smc fw still need driver do vPost otherwise gpu hang, while
  737. * those smc fw version above 22.15 doesn't have this flaw, so we force
  738. * vpost executed for smc version below 22.15
  739. */
  740. if (adev->asic_type == CHIP_FIJI) {
  741. int err;
  742. uint32_t fw_ver;
  743. err = request_firmware(&adev->pm.fw, "amdgpu/fiji_smc.bin", adev->dev);
  744. /* force vPost if error occured */
  745. if (err)
  746. return true;
  747. fw_ver = *((uint32_t *)adev->pm.fw->data + 69);
  748. if (fw_ver < 0x00160e00)
  749. return true;
  750. }
  751. }
  752. if (adev->has_hw_reset) {
  753. adev->has_hw_reset = false;
  754. return true;
  755. }
  756. /* bios scratch used on CIK+ */
  757. if (adev->asic_type >= CHIP_BONAIRE)
  758. return amdgpu_atombios_scratch_need_asic_init(adev);
  759. /* check MEM_SIZE for older asics */
  760. reg = amdgpu_asic_get_config_memsize(adev);
  761. if ((reg != 0) && (reg != 0xffffffff))
  762. return false;
  763. return true;
  764. }
  765. /**
  766. * amdgpu_dummy_page_init - init dummy page used by the driver
  767. *
  768. * @adev: amdgpu_device pointer
  769. *
  770. * Allocate the dummy page used by the driver (all asics).
  771. * This dummy page is used by the driver as a filler for gart entries
  772. * when pages are taken out of the GART
  773. * Returns 0 on sucess, -ENOMEM on failure.
  774. */
  775. int amdgpu_dummy_page_init(struct amdgpu_device *adev)
  776. {
  777. if (adev->dummy_page.page)
  778. return 0;
  779. adev->dummy_page.page = alloc_page(GFP_DMA32 | GFP_KERNEL | __GFP_ZERO);
  780. if (adev->dummy_page.page == NULL)
  781. return -ENOMEM;
  782. adev->dummy_page.addr = pci_map_page(adev->pdev, adev->dummy_page.page,
  783. 0, PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  784. if (pci_dma_mapping_error(adev->pdev, adev->dummy_page.addr)) {
  785. dev_err(&adev->pdev->dev, "Failed to DMA MAP the dummy page\n");
  786. __free_page(adev->dummy_page.page);
  787. adev->dummy_page.page = NULL;
  788. return -ENOMEM;
  789. }
  790. return 0;
  791. }
  792. /**
  793. * amdgpu_dummy_page_fini - free dummy page used by the driver
  794. *
  795. * @adev: amdgpu_device pointer
  796. *
  797. * Frees the dummy page used by the driver (all asics).
  798. */
  799. void amdgpu_dummy_page_fini(struct amdgpu_device *adev)
  800. {
  801. if (adev->dummy_page.page == NULL)
  802. return;
  803. pci_unmap_page(adev->pdev, adev->dummy_page.addr,
  804. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  805. __free_page(adev->dummy_page.page);
  806. adev->dummy_page.page = NULL;
  807. }
  808. /* ATOM accessor methods */
  809. /*
  810. * ATOM is an interpreted byte code stored in tables in the vbios. The
  811. * driver registers callbacks to access registers and the interpreter
  812. * in the driver parses the tables and executes then to program specific
  813. * actions (set display modes, asic init, etc.). See amdgpu_atombios.c,
  814. * atombios.h, and atom.c
  815. */
  816. /**
  817. * cail_pll_read - read PLL register
  818. *
  819. * @info: atom card_info pointer
  820. * @reg: PLL register offset
  821. *
  822. * Provides a PLL register accessor for the atom interpreter (r4xx+).
  823. * Returns the value of the PLL register.
  824. */
  825. static uint32_t cail_pll_read(struct card_info *info, uint32_t reg)
  826. {
  827. return 0;
  828. }
  829. /**
  830. * cail_pll_write - write PLL register
  831. *
  832. * @info: atom card_info pointer
  833. * @reg: PLL register offset
  834. * @val: value to write to the pll register
  835. *
  836. * Provides a PLL register accessor for the atom interpreter (r4xx+).
  837. */
  838. static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val)
  839. {
  840. }
  841. /**
  842. * cail_mc_read - read MC (Memory Controller) register
  843. *
  844. * @info: atom card_info pointer
  845. * @reg: MC register offset
  846. *
  847. * Provides an MC register accessor for the atom interpreter (r4xx+).
  848. * Returns the value of the MC register.
  849. */
  850. static uint32_t cail_mc_read(struct card_info *info, uint32_t reg)
  851. {
  852. return 0;
  853. }
  854. /**
  855. * cail_mc_write - write MC (Memory Controller) register
  856. *
  857. * @info: atom card_info pointer
  858. * @reg: MC register offset
  859. * @val: value to write to the pll register
  860. *
  861. * Provides a MC register accessor for the atom interpreter (r4xx+).
  862. */
  863. static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val)
  864. {
  865. }
  866. /**
  867. * cail_reg_write - write MMIO register
  868. *
  869. * @info: atom card_info pointer
  870. * @reg: MMIO register offset
  871. * @val: value to write to the pll register
  872. *
  873. * Provides a MMIO register accessor for the atom interpreter (r4xx+).
  874. */
  875. static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val)
  876. {
  877. struct amdgpu_device *adev = info->dev->dev_private;
  878. WREG32(reg, val);
  879. }
  880. /**
  881. * cail_reg_read - read MMIO register
  882. *
  883. * @info: atom card_info pointer
  884. * @reg: MMIO register offset
  885. *
  886. * Provides an MMIO register accessor for the atom interpreter (r4xx+).
  887. * Returns the value of the MMIO register.
  888. */
  889. static uint32_t cail_reg_read(struct card_info *info, uint32_t reg)
  890. {
  891. struct amdgpu_device *adev = info->dev->dev_private;
  892. uint32_t r;
  893. r = RREG32(reg);
  894. return r;
  895. }
  896. /**
  897. * cail_ioreg_write - write IO register
  898. *
  899. * @info: atom card_info pointer
  900. * @reg: IO register offset
  901. * @val: value to write to the pll register
  902. *
  903. * Provides a IO register accessor for the atom interpreter (r4xx+).
  904. */
  905. static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val)
  906. {
  907. struct amdgpu_device *adev = info->dev->dev_private;
  908. WREG32_IO(reg, val);
  909. }
  910. /**
  911. * cail_ioreg_read - read IO register
  912. *
  913. * @info: atom card_info pointer
  914. * @reg: IO register offset
  915. *
  916. * Provides an IO register accessor for the atom interpreter (r4xx+).
  917. * Returns the value of the IO register.
  918. */
  919. static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg)
  920. {
  921. struct amdgpu_device *adev = info->dev->dev_private;
  922. uint32_t r;
  923. r = RREG32_IO(reg);
  924. return r;
  925. }
  926. static ssize_t amdgpu_atombios_get_vbios_version(struct device *dev,
  927. struct device_attribute *attr,
  928. char *buf)
  929. {
  930. struct drm_device *ddev = dev_get_drvdata(dev);
  931. struct amdgpu_device *adev = ddev->dev_private;
  932. struct atom_context *ctx = adev->mode_info.atom_context;
  933. return snprintf(buf, PAGE_SIZE, "%s\n", ctx->vbios_version);
  934. }
  935. static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version,
  936. NULL);
  937. /**
  938. * amdgpu_atombios_fini - free the driver info and callbacks for atombios
  939. *
  940. * @adev: amdgpu_device pointer
  941. *
  942. * Frees the driver info and register access callbacks for the ATOM
  943. * interpreter (r4xx+).
  944. * Called at driver shutdown.
  945. */
  946. static void amdgpu_atombios_fini(struct amdgpu_device *adev)
  947. {
  948. if (adev->mode_info.atom_context) {
  949. kfree(adev->mode_info.atom_context->scratch);
  950. kfree(adev->mode_info.atom_context->iio);
  951. }
  952. kfree(adev->mode_info.atom_context);
  953. adev->mode_info.atom_context = NULL;
  954. kfree(adev->mode_info.atom_card_info);
  955. adev->mode_info.atom_card_info = NULL;
  956. device_remove_file(adev->dev, &dev_attr_vbios_version);
  957. }
  958. /**
  959. * amdgpu_atombios_init - init the driver info and callbacks for atombios
  960. *
  961. * @adev: amdgpu_device pointer
  962. *
  963. * Initializes the driver info and register access callbacks for the
  964. * ATOM interpreter (r4xx+).
  965. * Returns 0 on sucess, -ENOMEM on failure.
  966. * Called at driver startup.
  967. */
  968. static int amdgpu_atombios_init(struct amdgpu_device *adev)
  969. {
  970. struct card_info *atom_card_info =
  971. kzalloc(sizeof(struct card_info), GFP_KERNEL);
  972. int ret;
  973. if (!atom_card_info)
  974. return -ENOMEM;
  975. adev->mode_info.atom_card_info = atom_card_info;
  976. atom_card_info->dev = adev->ddev;
  977. atom_card_info->reg_read = cail_reg_read;
  978. atom_card_info->reg_write = cail_reg_write;
  979. /* needed for iio ops */
  980. if (adev->rio_mem) {
  981. atom_card_info->ioreg_read = cail_ioreg_read;
  982. atom_card_info->ioreg_write = cail_ioreg_write;
  983. } else {
  984. DRM_DEBUG("PCI I/O BAR is not found. Using MMIO to access ATOM BIOS\n");
  985. atom_card_info->ioreg_read = cail_reg_read;
  986. atom_card_info->ioreg_write = cail_reg_write;
  987. }
  988. atom_card_info->mc_read = cail_mc_read;
  989. atom_card_info->mc_write = cail_mc_write;
  990. atom_card_info->pll_read = cail_pll_read;
  991. atom_card_info->pll_write = cail_pll_write;
  992. adev->mode_info.atom_context = amdgpu_atom_parse(atom_card_info, adev->bios);
  993. if (!adev->mode_info.atom_context) {
  994. amdgpu_atombios_fini(adev);
  995. return -ENOMEM;
  996. }
  997. mutex_init(&adev->mode_info.atom_context->mutex);
  998. if (adev->is_atom_fw) {
  999. amdgpu_atomfirmware_scratch_regs_init(adev);
  1000. amdgpu_atomfirmware_allocate_fb_scratch(adev);
  1001. } else {
  1002. amdgpu_atombios_scratch_regs_init(adev);
  1003. amdgpu_atombios_allocate_fb_scratch(adev);
  1004. }
  1005. ret = device_create_file(adev->dev, &dev_attr_vbios_version);
  1006. if (ret) {
  1007. DRM_ERROR("Failed to create device file for VBIOS version\n");
  1008. return ret;
  1009. }
  1010. return 0;
  1011. }
  1012. /* if we get transitioned to only one device, take VGA back */
  1013. /**
  1014. * amdgpu_vga_set_decode - enable/disable vga decode
  1015. *
  1016. * @cookie: amdgpu_device pointer
  1017. * @state: enable/disable vga decode
  1018. *
  1019. * Enable/disable vga decode (all asics).
  1020. * Returns VGA resource flags.
  1021. */
  1022. static unsigned int amdgpu_vga_set_decode(void *cookie, bool state)
  1023. {
  1024. struct amdgpu_device *adev = cookie;
  1025. amdgpu_asic_set_vga_state(adev, state);
  1026. if (state)
  1027. return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
  1028. VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  1029. else
  1030. return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  1031. }
  1032. static void amdgpu_check_block_size(struct amdgpu_device *adev)
  1033. {
  1034. /* defines number of bits in page table versus page directory,
  1035. * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
  1036. * page table and the remaining bits are in the page directory */
  1037. if (amdgpu_vm_block_size == -1)
  1038. return;
  1039. if (amdgpu_vm_block_size < 9) {
  1040. dev_warn(adev->dev, "VM page table size (%d) too small\n",
  1041. amdgpu_vm_block_size);
  1042. goto def_value;
  1043. }
  1044. if (amdgpu_vm_block_size > 24 ||
  1045. (amdgpu_vm_size * 1024) < (1ull << amdgpu_vm_block_size)) {
  1046. dev_warn(adev->dev, "VM page table size (%d) too large\n",
  1047. amdgpu_vm_block_size);
  1048. goto def_value;
  1049. }
  1050. return;
  1051. def_value:
  1052. amdgpu_vm_block_size = -1;
  1053. }
  1054. static void amdgpu_check_vm_size(struct amdgpu_device *adev)
  1055. {
  1056. /* no need to check the default value */
  1057. if (amdgpu_vm_size == -1)
  1058. return;
  1059. if (amdgpu_vm_size < 1) {
  1060. dev_warn(adev->dev, "VM size (%d) too small, min is 1GB\n",
  1061. amdgpu_vm_size);
  1062. goto def_value;
  1063. }
  1064. /*
  1065. * Max GPUVM size for Cayman, SI, CI VI are 40 bits.
  1066. */
  1067. if (amdgpu_vm_size > 1024) {
  1068. dev_warn(adev->dev, "VM size (%d) too large, max is 1TB\n",
  1069. amdgpu_vm_size);
  1070. goto def_value;
  1071. }
  1072. return;
  1073. def_value:
  1074. amdgpu_vm_size = -1;
  1075. }
  1076. /**
  1077. * amdgpu_check_arguments - validate module params
  1078. *
  1079. * @adev: amdgpu_device pointer
  1080. *
  1081. * Validates certain module parameters and updates
  1082. * the associated values used by the driver (all asics).
  1083. */
  1084. static void amdgpu_check_arguments(struct amdgpu_device *adev)
  1085. {
  1086. if (amdgpu_sched_jobs < 4) {
  1087. dev_warn(adev->dev, "sched jobs (%d) must be at least 4\n",
  1088. amdgpu_sched_jobs);
  1089. amdgpu_sched_jobs = 4;
  1090. } else if (!is_power_of_2(amdgpu_sched_jobs)){
  1091. dev_warn(adev->dev, "sched jobs (%d) must be a power of 2\n",
  1092. amdgpu_sched_jobs);
  1093. amdgpu_sched_jobs = roundup_pow_of_two(amdgpu_sched_jobs);
  1094. }
  1095. if (amdgpu_gart_size != -1 && amdgpu_gart_size < 32) {
  1096. /* gart size must be greater or equal to 32M */
  1097. dev_warn(adev->dev, "gart size (%d) too small\n",
  1098. amdgpu_gart_size);
  1099. amdgpu_gart_size = -1;
  1100. }
  1101. if (amdgpu_gtt_size != -1 && amdgpu_gtt_size < 32) {
  1102. /* gtt size must be greater or equal to 32M */
  1103. dev_warn(adev->dev, "gtt size (%d) too small\n",
  1104. amdgpu_gtt_size);
  1105. amdgpu_gtt_size = -1;
  1106. }
  1107. /* valid range is between 4 and 9 inclusive */
  1108. if (amdgpu_vm_fragment_size != -1 &&
  1109. (amdgpu_vm_fragment_size > 9 || amdgpu_vm_fragment_size < 4)) {
  1110. dev_warn(adev->dev, "valid range is between 4 and 9\n");
  1111. amdgpu_vm_fragment_size = -1;
  1112. }
  1113. amdgpu_check_vm_size(adev);
  1114. amdgpu_check_block_size(adev);
  1115. if (amdgpu_vram_page_split != -1 && (amdgpu_vram_page_split < 16 ||
  1116. !is_power_of_2(amdgpu_vram_page_split))) {
  1117. dev_warn(adev->dev, "invalid VRAM page split (%d)\n",
  1118. amdgpu_vram_page_split);
  1119. amdgpu_vram_page_split = 1024;
  1120. }
  1121. }
  1122. /**
  1123. * amdgpu_switcheroo_set_state - set switcheroo state
  1124. *
  1125. * @pdev: pci dev pointer
  1126. * @state: vga_switcheroo state
  1127. *
  1128. * Callback for the switcheroo driver. Suspends or resumes the
  1129. * the asics before or after it is powered up using ACPI methods.
  1130. */
  1131. static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
  1132. {
  1133. struct drm_device *dev = pci_get_drvdata(pdev);
  1134. if (amdgpu_device_is_px(dev) && state == VGA_SWITCHEROO_OFF)
  1135. return;
  1136. if (state == VGA_SWITCHEROO_ON) {
  1137. pr_info("amdgpu: switched on\n");
  1138. /* don't suspend or resume card normally */
  1139. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  1140. amdgpu_device_resume(dev, true, true);
  1141. dev->switch_power_state = DRM_SWITCH_POWER_ON;
  1142. drm_kms_helper_poll_enable(dev);
  1143. } else {
  1144. pr_info("amdgpu: switched off\n");
  1145. drm_kms_helper_poll_disable(dev);
  1146. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  1147. amdgpu_device_suspend(dev, true, true);
  1148. dev->switch_power_state = DRM_SWITCH_POWER_OFF;
  1149. }
  1150. }
  1151. /**
  1152. * amdgpu_switcheroo_can_switch - see if switcheroo state can change
  1153. *
  1154. * @pdev: pci dev pointer
  1155. *
  1156. * Callback for the switcheroo driver. Check of the switcheroo
  1157. * state can be changed.
  1158. * Returns true if the state can be changed, false if not.
  1159. */
  1160. static bool amdgpu_switcheroo_can_switch(struct pci_dev *pdev)
  1161. {
  1162. struct drm_device *dev = pci_get_drvdata(pdev);
  1163. /*
  1164. * FIXME: open_count is protected by drm_global_mutex but that would lead to
  1165. * locking inversion with the driver load path. And the access here is
  1166. * completely racy anyway. So don't bother with locking for now.
  1167. */
  1168. return dev->open_count == 0;
  1169. }
  1170. static const struct vga_switcheroo_client_ops amdgpu_switcheroo_ops = {
  1171. .set_gpu_state = amdgpu_switcheroo_set_state,
  1172. .reprobe = NULL,
  1173. .can_switch = amdgpu_switcheroo_can_switch,
  1174. };
  1175. int amdgpu_set_clockgating_state(struct amdgpu_device *adev,
  1176. enum amd_ip_block_type block_type,
  1177. enum amd_clockgating_state state)
  1178. {
  1179. int i, r = 0;
  1180. for (i = 0; i < adev->num_ip_blocks; i++) {
  1181. if (!adev->ip_blocks[i].status.valid)
  1182. continue;
  1183. if (adev->ip_blocks[i].version->type != block_type)
  1184. continue;
  1185. if (!adev->ip_blocks[i].version->funcs->set_clockgating_state)
  1186. continue;
  1187. r = adev->ip_blocks[i].version->funcs->set_clockgating_state(
  1188. (void *)adev, state);
  1189. if (r)
  1190. DRM_ERROR("set_clockgating_state of IP block <%s> failed %d\n",
  1191. adev->ip_blocks[i].version->funcs->name, r);
  1192. }
  1193. return r;
  1194. }
  1195. int amdgpu_set_powergating_state(struct amdgpu_device *adev,
  1196. enum amd_ip_block_type block_type,
  1197. enum amd_powergating_state state)
  1198. {
  1199. int i, r = 0;
  1200. for (i = 0; i < adev->num_ip_blocks; i++) {
  1201. if (!adev->ip_blocks[i].status.valid)
  1202. continue;
  1203. if (adev->ip_blocks[i].version->type != block_type)
  1204. continue;
  1205. if (!adev->ip_blocks[i].version->funcs->set_powergating_state)
  1206. continue;
  1207. r = adev->ip_blocks[i].version->funcs->set_powergating_state(
  1208. (void *)adev, state);
  1209. if (r)
  1210. DRM_ERROR("set_powergating_state of IP block <%s> failed %d\n",
  1211. adev->ip_blocks[i].version->funcs->name, r);
  1212. }
  1213. return r;
  1214. }
  1215. void amdgpu_get_clockgating_state(struct amdgpu_device *adev, u32 *flags)
  1216. {
  1217. int i;
  1218. for (i = 0; i < adev->num_ip_blocks; i++) {
  1219. if (!adev->ip_blocks[i].status.valid)
  1220. continue;
  1221. if (adev->ip_blocks[i].version->funcs->get_clockgating_state)
  1222. adev->ip_blocks[i].version->funcs->get_clockgating_state((void *)adev, flags);
  1223. }
  1224. }
  1225. int amdgpu_wait_for_idle(struct amdgpu_device *adev,
  1226. enum amd_ip_block_type block_type)
  1227. {
  1228. int i, r;
  1229. for (i = 0; i < adev->num_ip_blocks; i++) {
  1230. if (!adev->ip_blocks[i].status.valid)
  1231. continue;
  1232. if (adev->ip_blocks[i].version->type == block_type) {
  1233. r = adev->ip_blocks[i].version->funcs->wait_for_idle((void *)adev);
  1234. if (r)
  1235. return r;
  1236. break;
  1237. }
  1238. }
  1239. return 0;
  1240. }
  1241. bool amdgpu_is_idle(struct amdgpu_device *adev,
  1242. enum amd_ip_block_type block_type)
  1243. {
  1244. int i;
  1245. for (i = 0; i < adev->num_ip_blocks; i++) {
  1246. if (!adev->ip_blocks[i].status.valid)
  1247. continue;
  1248. if (adev->ip_blocks[i].version->type == block_type)
  1249. return adev->ip_blocks[i].version->funcs->is_idle((void *)adev);
  1250. }
  1251. return true;
  1252. }
  1253. struct amdgpu_ip_block * amdgpu_get_ip_block(struct amdgpu_device *adev,
  1254. enum amd_ip_block_type type)
  1255. {
  1256. int i;
  1257. for (i = 0; i < adev->num_ip_blocks; i++)
  1258. if (adev->ip_blocks[i].version->type == type)
  1259. return &adev->ip_blocks[i];
  1260. return NULL;
  1261. }
  1262. /**
  1263. * amdgpu_ip_block_version_cmp
  1264. *
  1265. * @adev: amdgpu_device pointer
  1266. * @type: enum amd_ip_block_type
  1267. * @major: major version
  1268. * @minor: minor version
  1269. *
  1270. * return 0 if equal or greater
  1271. * return 1 if smaller or the ip_block doesn't exist
  1272. */
  1273. int amdgpu_ip_block_version_cmp(struct amdgpu_device *adev,
  1274. enum amd_ip_block_type type,
  1275. u32 major, u32 minor)
  1276. {
  1277. struct amdgpu_ip_block *ip_block = amdgpu_get_ip_block(adev, type);
  1278. if (ip_block && ((ip_block->version->major > major) ||
  1279. ((ip_block->version->major == major) &&
  1280. (ip_block->version->minor >= minor))))
  1281. return 0;
  1282. return 1;
  1283. }
  1284. /**
  1285. * amdgpu_ip_block_add
  1286. *
  1287. * @adev: amdgpu_device pointer
  1288. * @ip_block_version: pointer to the IP to add
  1289. *
  1290. * Adds the IP block driver information to the collection of IPs
  1291. * on the asic.
  1292. */
  1293. int amdgpu_ip_block_add(struct amdgpu_device *adev,
  1294. const struct amdgpu_ip_block_version *ip_block_version)
  1295. {
  1296. if (!ip_block_version)
  1297. return -EINVAL;
  1298. DRM_DEBUG("add ip block number %d <%s>\n", adev->num_ip_blocks,
  1299. ip_block_version->funcs->name);
  1300. adev->ip_blocks[adev->num_ip_blocks++].version = ip_block_version;
  1301. return 0;
  1302. }
  1303. static void amdgpu_device_enable_virtual_display(struct amdgpu_device *adev)
  1304. {
  1305. adev->enable_virtual_display = false;
  1306. if (amdgpu_virtual_display) {
  1307. struct drm_device *ddev = adev->ddev;
  1308. const char *pci_address_name = pci_name(ddev->pdev);
  1309. char *pciaddstr, *pciaddstr_tmp, *pciaddname_tmp, *pciaddname;
  1310. pciaddstr = kstrdup(amdgpu_virtual_display, GFP_KERNEL);
  1311. pciaddstr_tmp = pciaddstr;
  1312. while ((pciaddname_tmp = strsep(&pciaddstr_tmp, ";"))) {
  1313. pciaddname = strsep(&pciaddname_tmp, ",");
  1314. if (!strcmp("all", pciaddname)
  1315. || !strcmp(pci_address_name, pciaddname)) {
  1316. long num_crtc;
  1317. int res = -1;
  1318. adev->enable_virtual_display = true;
  1319. if (pciaddname_tmp)
  1320. res = kstrtol(pciaddname_tmp, 10,
  1321. &num_crtc);
  1322. if (!res) {
  1323. if (num_crtc < 1)
  1324. num_crtc = 1;
  1325. if (num_crtc > 6)
  1326. num_crtc = 6;
  1327. adev->mode_info.num_crtc = num_crtc;
  1328. } else {
  1329. adev->mode_info.num_crtc = 1;
  1330. }
  1331. break;
  1332. }
  1333. }
  1334. DRM_INFO("virtual display string:%s, %s:virtual_display:%d, num_crtc:%d\n",
  1335. amdgpu_virtual_display, pci_address_name,
  1336. adev->enable_virtual_display, adev->mode_info.num_crtc);
  1337. kfree(pciaddstr);
  1338. }
  1339. }
  1340. static int amdgpu_device_parse_gpu_info_fw(struct amdgpu_device *adev)
  1341. {
  1342. const char *chip_name;
  1343. char fw_name[30];
  1344. int err;
  1345. const struct gpu_info_firmware_header_v1_0 *hdr;
  1346. adev->firmware.gpu_info_fw = NULL;
  1347. switch (adev->asic_type) {
  1348. case CHIP_TOPAZ:
  1349. case CHIP_TONGA:
  1350. case CHIP_FIJI:
  1351. case CHIP_POLARIS11:
  1352. case CHIP_POLARIS10:
  1353. case CHIP_POLARIS12:
  1354. case CHIP_CARRIZO:
  1355. case CHIP_STONEY:
  1356. #ifdef CONFIG_DRM_AMDGPU_SI
  1357. case CHIP_VERDE:
  1358. case CHIP_TAHITI:
  1359. case CHIP_PITCAIRN:
  1360. case CHIP_OLAND:
  1361. case CHIP_HAINAN:
  1362. #endif
  1363. #ifdef CONFIG_DRM_AMDGPU_CIK
  1364. case CHIP_BONAIRE:
  1365. case CHIP_HAWAII:
  1366. case CHIP_KAVERI:
  1367. case CHIP_KABINI:
  1368. case CHIP_MULLINS:
  1369. #endif
  1370. default:
  1371. return 0;
  1372. case CHIP_VEGA10:
  1373. chip_name = "vega10";
  1374. break;
  1375. case CHIP_RAVEN:
  1376. chip_name = "raven";
  1377. break;
  1378. }
  1379. snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_gpu_info.bin", chip_name);
  1380. err = request_firmware(&adev->firmware.gpu_info_fw, fw_name, adev->dev);
  1381. if (err) {
  1382. dev_err(adev->dev,
  1383. "Failed to load gpu_info firmware \"%s\"\n",
  1384. fw_name);
  1385. goto out;
  1386. }
  1387. err = amdgpu_ucode_validate(adev->firmware.gpu_info_fw);
  1388. if (err) {
  1389. dev_err(adev->dev,
  1390. "Failed to validate gpu_info firmware \"%s\"\n",
  1391. fw_name);
  1392. goto out;
  1393. }
  1394. hdr = (const struct gpu_info_firmware_header_v1_0 *)adev->firmware.gpu_info_fw->data;
  1395. amdgpu_ucode_print_gpu_info_hdr(&hdr->header);
  1396. switch (hdr->version_major) {
  1397. case 1:
  1398. {
  1399. const struct gpu_info_firmware_v1_0 *gpu_info_fw =
  1400. (const struct gpu_info_firmware_v1_0 *)(adev->firmware.gpu_info_fw->data +
  1401. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  1402. adev->gfx.config.max_shader_engines = le32_to_cpu(gpu_info_fw->gc_num_se);
  1403. adev->gfx.config.max_cu_per_sh = le32_to_cpu(gpu_info_fw->gc_num_cu_per_sh);
  1404. adev->gfx.config.max_sh_per_se = le32_to_cpu(gpu_info_fw->gc_num_sh_per_se);
  1405. adev->gfx.config.max_backends_per_se = le32_to_cpu(gpu_info_fw->gc_num_rb_per_se);
  1406. adev->gfx.config.max_texture_channel_caches =
  1407. le32_to_cpu(gpu_info_fw->gc_num_tccs);
  1408. adev->gfx.config.max_gprs = le32_to_cpu(gpu_info_fw->gc_num_gprs);
  1409. adev->gfx.config.max_gs_threads = le32_to_cpu(gpu_info_fw->gc_num_max_gs_thds);
  1410. adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gpu_info_fw->gc_gs_table_depth);
  1411. adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gpu_info_fw->gc_gsprim_buff_depth);
  1412. adev->gfx.config.double_offchip_lds_buf =
  1413. le32_to_cpu(gpu_info_fw->gc_double_offchip_lds_buffer);
  1414. adev->gfx.cu_info.wave_front_size = le32_to_cpu(gpu_info_fw->gc_wave_size);
  1415. adev->gfx.cu_info.max_waves_per_simd =
  1416. le32_to_cpu(gpu_info_fw->gc_max_waves_per_simd);
  1417. adev->gfx.cu_info.max_scratch_slots_per_cu =
  1418. le32_to_cpu(gpu_info_fw->gc_max_scratch_slots_per_cu);
  1419. adev->gfx.cu_info.lds_size = le32_to_cpu(gpu_info_fw->gc_lds_size);
  1420. break;
  1421. }
  1422. default:
  1423. dev_err(adev->dev,
  1424. "Unsupported gpu_info table %d\n", hdr->header.ucode_version);
  1425. err = -EINVAL;
  1426. goto out;
  1427. }
  1428. out:
  1429. return err;
  1430. }
  1431. static int amdgpu_early_init(struct amdgpu_device *adev)
  1432. {
  1433. int i, r;
  1434. amdgpu_device_enable_virtual_display(adev);
  1435. switch (adev->asic_type) {
  1436. case CHIP_TOPAZ:
  1437. case CHIP_TONGA:
  1438. case CHIP_FIJI:
  1439. case CHIP_POLARIS11:
  1440. case CHIP_POLARIS10:
  1441. case CHIP_POLARIS12:
  1442. case CHIP_CARRIZO:
  1443. case CHIP_STONEY:
  1444. if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY)
  1445. adev->family = AMDGPU_FAMILY_CZ;
  1446. else
  1447. adev->family = AMDGPU_FAMILY_VI;
  1448. r = vi_set_ip_blocks(adev);
  1449. if (r)
  1450. return r;
  1451. break;
  1452. #ifdef CONFIG_DRM_AMDGPU_SI
  1453. case CHIP_VERDE:
  1454. case CHIP_TAHITI:
  1455. case CHIP_PITCAIRN:
  1456. case CHIP_OLAND:
  1457. case CHIP_HAINAN:
  1458. adev->family = AMDGPU_FAMILY_SI;
  1459. r = si_set_ip_blocks(adev);
  1460. if (r)
  1461. return r;
  1462. break;
  1463. #endif
  1464. #ifdef CONFIG_DRM_AMDGPU_CIK
  1465. case CHIP_BONAIRE:
  1466. case CHIP_HAWAII:
  1467. case CHIP_KAVERI:
  1468. case CHIP_KABINI:
  1469. case CHIP_MULLINS:
  1470. if ((adev->asic_type == CHIP_BONAIRE) || (adev->asic_type == CHIP_HAWAII))
  1471. adev->family = AMDGPU_FAMILY_CI;
  1472. else
  1473. adev->family = AMDGPU_FAMILY_KV;
  1474. r = cik_set_ip_blocks(adev);
  1475. if (r)
  1476. return r;
  1477. break;
  1478. #endif
  1479. case CHIP_VEGA10:
  1480. case CHIP_RAVEN:
  1481. if (adev->asic_type == CHIP_RAVEN)
  1482. adev->family = AMDGPU_FAMILY_RV;
  1483. else
  1484. adev->family = AMDGPU_FAMILY_AI;
  1485. r = soc15_set_ip_blocks(adev);
  1486. if (r)
  1487. return r;
  1488. break;
  1489. default:
  1490. /* FIXME: not supported yet */
  1491. return -EINVAL;
  1492. }
  1493. r = amdgpu_device_parse_gpu_info_fw(adev);
  1494. if (r)
  1495. return r;
  1496. amdgpu_amdkfd_device_probe(adev);
  1497. if (amdgpu_sriov_vf(adev)) {
  1498. r = amdgpu_virt_request_full_gpu(adev, true);
  1499. if (r)
  1500. return -EAGAIN;
  1501. }
  1502. for (i = 0; i < adev->num_ip_blocks; i++) {
  1503. if ((amdgpu_ip_block_mask & (1 << i)) == 0) {
  1504. DRM_ERROR("disabled ip block: %d <%s>\n",
  1505. i, adev->ip_blocks[i].version->funcs->name);
  1506. adev->ip_blocks[i].status.valid = false;
  1507. } else {
  1508. if (adev->ip_blocks[i].version->funcs->early_init) {
  1509. r = adev->ip_blocks[i].version->funcs->early_init((void *)adev);
  1510. if (r == -ENOENT) {
  1511. adev->ip_blocks[i].status.valid = false;
  1512. } else if (r) {
  1513. DRM_ERROR("early_init of IP block <%s> failed %d\n",
  1514. adev->ip_blocks[i].version->funcs->name, r);
  1515. return r;
  1516. } else {
  1517. adev->ip_blocks[i].status.valid = true;
  1518. }
  1519. } else {
  1520. adev->ip_blocks[i].status.valid = true;
  1521. }
  1522. }
  1523. }
  1524. adev->cg_flags &= amdgpu_cg_mask;
  1525. adev->pg_flags &= amdgpu_pg_mask;
  1526. return 0;
  1527. }
  1528. static int amdgpu_init(struct amdgpu_device *adev)
  1529. {
  1530. int i, r;
  1531. for (i = 0; i < adev->num_ip_blocks; i++) {
  1532. if (!adev->ip_blocks[i].status.valid)
  1533. continue;
  1534. r = adev->ip_blocks[i].version->funcs->sw_init((void *)adev);
  1535. if (r) {
  1536. DRM_ERROR("sw_init of IP block <%s> failed %d\n",
  1537. adev->ip_blocks[i].version->funcs->name, r);
  1538. return r;
  1539. }
  1540. adev->ip_blocks[i].status.sw = true;
  1541. /* need to do gmc hw init early so we can allocate gpu mem */
  1542. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
  1543. r = amdgpu_vram_scratch_init(adev);
  1544. if (r) {
  1545. DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r);
  1546. return r;
  1547. }
  1548. r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev);
  1549. if (r) {
  1550. DRM_ERROR("hw_init %d failed %d\n", i, r);
  1551. return r;
  1552. }
  1553. r = amdgpu_wb_init(adev);
  1554. if (r) {
  1555. DRM_ERROR("amdgpu_wb_init failed %d\n", r);
  1556. return r;
  1557. }
  1558. adev->ip_blocks[i].status.hw = true;
  1559. /* right after GMC hw init, we create CSA */
  1560. if (amdgpu_sriov_vf(adev)) {
  1561. r = amdgpu_allocate_static_csa(adev);
  1562. if (r) {
  1563. DRM_ERROR("allocate CSA failed %d\n", r);
  1564. return r;
  1565. }
  1566. }
  1567. }
  1568. }
  1569. for (i = 0; i < adev->num_ip_blocks; i++) {
  1570. if (!adev->ip_blocks[i].status.sw)
  1571. continue;
  1572. /* gmc hw init is done early */
  1573. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC)
  1574. continue;
  1575. r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev);
  1576. if (r) {
  1577. DRM_ERROR("hw_init of IP block <%s> failed %d\n",
  1578. adev->ip_blocks[i].version->funcs->name, r);
  1579. return r;
  1580. }
  1581. adev->ip_blocks[i].status.hw = true;
  1582. }
  1583. amdgpu_amdkfd_device_init(adev);
  1584. if (amdgpu_sriov_vf(adev))
  1585. amdgpu_virt_release_full_gpu(adev, true);
  1586. return 0;
  1587. }
  1588. static void amdgpu_fill_reset_magic(struct amdgpu_device *adev)
  1589. {
  1590. memcpy(adev->reset_magic, adev->gart.ptr, AMDGPU_RESET_MAGIC_NUM);
  1591. }
  1592. static bool amdgpu_check_vram_lost(struct amdgpu_device *adev)
  1593. {
  1594. return !!memcmp(adev->gart.ptr, adev->reset_magic,
  1595. AMDGPU_RESET_MAGIC_NUM);
  1596. }
  1597. static int amdgpu_late_set_cg_state(struct amdgpu_device *adev)
  1598. {
  1599. int i = 0, r;
  1600. for (i = 0; i < adev->num_ip_blocks; i++) {
  1601. if (!adev->ip_blocks[i].status.valid)
  1602. continue;
  1603. /* skip CG for VCE/UVD, it's handled specially */
  1604. if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
  1605. adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) {
  1606. /* enable clockgating to save power */
  1607. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1608. AMD_CG_STATE_GATE);
  1609. if (r) {
  1610. DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n",
  1611. adev->ip_blocks[i].version->funcs->name, r);
  1612. return r;
  1613. }
  1614. }
  1615. }
  1616. return 0;
  1617. }
  1618. static int amdgpu_late_init(struct amdgpu_device *adev)
  1619. {
  1620. int i = 0, r;
  1621. for (i = 0; i < adev->num_ip_blocks; i++) {
  1622. if (!adev->ip_blocks[i].status.valid)
  1623. continue;
  1624. if (adev->ip_blocks[i].version->funcs->late_init) {
  1625. r = adev->ip_blocks[i].version->funcs->late_init((void *)adev);
  1626. if (r) {
  1627. DRM_ERROR("late_init of IP block <%s> failed %d\n",
  1628. adev->ip_blocks[i].version->funcs->name, r);
  1629. return r;
  1630. }
  1631. adev->ip_blocks[i].status.late_initialized = true;
  1632. }
  1633. }
  1634. mod_delayed_work(system_wq, &adev->late_init_work,
  1635. msecs_to_jiffies(AMDGPU_RESUME_MS));
  1636. amdgpu_fill_reset_magic(adev);
  1637. return 0;
  1638. }
  1639. static int amdgpu_fini(struct amdgpu_device *adev)
  1640. {
  1641. int i, r;
  1642. amdgpu_amdkfd_device_fini(adev);
  1643. /* need to disable SMC first */
  1644. for (i = 0; i < adev->num_ip_blocks; i++) {
  1645. if (!adev->ip_blocks[i].status.hw)
  1646. continue;
  1647. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) {
  1648. /* ungate blocks before hw fini so that we can shutdown the blocks safely */
  1649. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1650. AMD_CG_STATE_UNGATE);
  1651. if (r) {
  1652. DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
  1653. adev->ip_blocks[i].version->funcs->name, r);
  1654. return r;
  1655. }
  1656. r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev);
  1657. /* XXX handle errors */
  1658. if (r) {
  1659. DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
  1660. adev->ip_blocks[i].version->funcs->name, r);
  1661. }
  1662. adev->ip_blocks[i].status.hw = false;
  1663. break;
  1664. }
  1665. }
  1666. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1667. if (!adev->ip_blocks[i].status.hw)
  1668. continue;
  1669. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
  1670. amdgpu_free_static_csa(adev);
  1671. amdgpu_wb_fini(adev);
  1672. amdgpu_vram_scratch_fini(adev);
  1673. }
  1674. if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
  1675. adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) {
  1676. /* ungate blocks before hw fini so that we can shutdown the blocks safely */
  1677. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1678. AMD_CG_STATE_UNGATE);
  1679. if (r) {
  1680. DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
  1681. adev->ip_blocks[i].version->funcs->name, r);
  1682. return r;
  1683. }
  1684. }
  1685. r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev);
  1686. /* XXX handle errors */
  1687. if (r) {
  1688. DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
  1689. adev->ip_blocks[i].version->funcs->name, r);
  1690. }
  1691. adev->ip_blocks[i].status.hw = false;
  1692. }
  1693. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1694. if (!adev->ip_blocks[i].status.sw)
  1695. continue;
  1696. r = adev->ip_blocks[i].version->funcs->sw_fini((void *)adev);
  1697. /* XXX handle errors */
  1698. if (r) {
  1699. DRM_DEBUG("sw_fini of IP block <%s> failed %d\n",
  1700. adev->ip_blocks[i].version->funcs->name, r);
  1701. }
  1702. adev->ip_blocks[i].status.sw = false;
  1703. adev->ip_blocks[i].status.valid = false;
  1704. }
  1705. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1706. if (!adev->ip_blocks[i].status.late_initialized)
  1707. continue;
  1708. if (adev->ip_blocks[i].version->funcs->late_fini)
  1709. adev->ip_blocks[i].version->funcs->late_fini((void *)adev);
  1710. adev->ip_blocks[i].status.late_initialized = false;
  1711. }
  1712. if (amdgpu_sriov_vf(adev))
  1713. if (amdgpu_virt_release_full_gpu(adev, false))
  1714. DRM_ERROR("failed to release exclusive mode on fini\n");
  1715. return 0;
  1716. }
  1717. static void amdgpu_late_init_func_handler(struct work_struct *work)
  1718. {
  1719. struct amdgpu_device *adev =
  1720. container_of(work, struct amdgpu_device, late_init_work.work);
  1721. amdgpu_late_set_cg_state(adev);
  1722. }
  1723. int amdgpu_suspend(struct amdgpu_device *adev)
  1724. {
  1725. int i, r;
  1726. if (amdgpu_sriov_vf(adev))
  1727. amdgpu_virt_request_full_gpu(adev, false);
  1728. /* ungate SMC block first */
  1729. r = amdgpu_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_SMC,
  1730. AMD_CG_STATE_UNGATE);
  1731. if (r) {
  1732. DRM_ERROR("set_clockgating_state(ungate) SMC failed %d\n",r);
  1733. }
  1734. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1735. if (!adev->ip_blocks[i].status.valid)
  1736. continue;
  1737. /* ungate blocks so that suspend can properly shut them down */
  1738. if (i != AMD_IP_BLOCK_TYPE_SMC) {
  1739. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1740. AMD_CG_STATE_UNGATE);
  1741. if (r) {
  1742. DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
  1743. adev->ip_blocks[i].version->funcs->name, r);
  1744. }
  1745. }
  1746. /* XXX handle errors */
  1747. r = adev->ip_blocks[i].version->funcs->suspend(adev);
  1748. /* XXX handle errors */
  1749. if (r) {
  1750. DRM_ERROR("suspend of IP block <%s> failed %d\n",
  1751. adev->ip_blocks[i].version->funcs->name, r);
  1752. }
  1753. }
  1754. if (amdgpu_sriov_vf(adev))
  1755. amdgpu_virt_release_full_gpu(adev, false);
  1756. return 0;
  1757. }
  1758. static int amdgpu_sriov_reinit_early(struct amdgpu_device *adev)
  1759. {
  1760. int i, r;
  1761. static enum amd_ip_block_type ip_order[] = {
  1762. AMD_IP_BLOCK_TYPE_GMC,
  1763. AMD_IP_BLOCK_TYPE_COMMON,
  1764. AMD_IP_BLOCK_TYPE_IH,
  1765. };
  1766. for (i = 0; i < ARRAY_SIZE(ip_order); i++) {
  1767. int j;
  1768. struct amdgpu_ip_block *block;
  1769. for (j = 0; j < adev->num_ip_blocks; j++) {
  1770. block = &adev->ip_blocks[j];
  1771. if (block->version->type != ip_order[i] ||
  1772. !block->status.valid)
  1773. continue;
  1774. r = block->version->funcs->hw_init(adev);
  1775. DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed");
  1776. }
  1777. }
  1778. return 0;
  1779. }
  1780. static int amdgpu_sriov_reinit_late(struct amdgpu_device *adev)
  1781. {
  1782. int i, r;
  1783. static enum amd_ip_block_type ip_order[] = {
  1784. AMD_IP_BLOCK_TYPE_SMC,
  1785. AMD_IP_BLOCK_TYPE_PSP,
  1786. AMD_IP_BLOCK_TYPE_DCE,
  1787. AMD_IP_BLOCK_TYPE_GFX,
  1788. AMD_IP_BLOCK_TYPE_SDMA,
  1789. AMD_IP_BLOCK_TYPE_UVD,
  1790. AMD_IP_BLOCK_TYPE_VCE
  1791. };
  1792. for (i = 0; i < ARRAY_SIZE(ip_order); i++) {
  1793. int j;
  1794. struct amdgpu_ip_block *block;
  1795. for (j = 0; j < adev->num_ip_blocks; j++) {
  1796. block = &adev->ip_blocks[j];
  1797. if (block->version->type != ip_order[i] ||
  1798. !block->status.valid)
  1799. continue;
  1800. r = block->version->funcs->hw_init(adev);
  1801. DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed");
  1802. }
  1803. }
  1804. return 0;
  1805. }
  1806. static int amdgpu_resume_phase1(struct amdgpu_device *adev)
  1807. {
  1808. int i, r;
  1809. for (i = 0; i < adev->num_ip_blocks; i++) {
  1810. if (!adev->ip_blocks[i].status.valid)
  1811. continue;
  1812. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
  1813. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
  1814. adev->ip_blocks[i].version->type ==
  1815. AMD_IP_BLOCK_TYPE_IH) {
  1816. r = adev->ip_blocks[i].version->funcs->resume(adev);
  1817. if (r) {
  1818. DRM_ERROR("resume of IP block <%s> failed %d\n",
  1819. adev->ip_blocks[i].version->funcs->name, r);
  1820. return r;
  1821. }
  1822. }
  1823. }
  1824. return 0;
  1825. }
  1826. static int amdgpu_resume_phase2(struct amdgpu_device *adev)
  1827. {
  1828. int i, r;
  1829. for (i = 0; i < adev->num_ip_blocks; i++) {
  1830. if (!adev->ip_blocks[i].status.valid)
  1831. continue;
  1832. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
  1833. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
  1834. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH )
  1835. continue;
  1836. r = adev->ip_blocks[i].version->funcs->resume(adev);
  1837. if (r) {
  1838. DRM_ERROR("resume of IP block <%s> failed %d\n",
  1839. adev->ip_blocks[i].version->funcs->name, r);
  1840. return r;
  1841. }
  1842. }
  1843. return 0;
  1844. }
  1845. static int amdgpu_resume(struct amdgpu_device *adev)
  1846. {
  1847. int r;
  1848. r = amdgpu_resume_phase1(adev);
  1849. if (r)
  1850. return r;
  1851. r = amdgpu_resume_phase2(adev);
  1852. return r;
  1853. }
  1854. static void amdgpu_device_detect_sriov_bios(struct amdgpu_device *adev)
  1855. {
  1856. if (amdgpu_sriov_vf(adev)) {
  1857. if (adev->is_atom_fw) {
  1858. if (amdgpu_atomfirmware_gpu_supports_virtualization(adev))
  1859. adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
  1860. } else {
  1861. if (amdgpu_atombios_has_gpu_virtualization_table(adev))
  1862. adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
  1863. }
  1864. if (!(adev->virt.caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS))
  1865. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_NO_VBIOS, 0, 0);
  1866. }
  1867. }
  1868. bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type)
  1869. {
  1870. switch (asic_type) {
  1871. #if defined(CONFIG_DRM_AMD_DC)
  1872. case CHIP_BONAIRE:
  1873. case CHIP_HAWAII:
  1874. case CHIP_KAVERI:
  1875. case CHIP_CARRIZO:
  1876. case CHIP_STONEY:
  1877. case CHIP_POLARIS11:
  1878. case CHIP_POLARIS10:
  1879. case CHIP_POLARIS12:
  1880. case CHIP_TONGA:
  1881. case CHIP_FIJI:
  1882. #if defined(CONFIG_DRM_AMD_DC_PRE_VEGA)
  1883. return amdgpu_dc != 0;
  1884. #endif
  1885. case CHIP_KABINI:
  1886. case CHIP_MULLINS:
  1887. return amdgpu_dc > 0;
  1888. case CHIP_VEGA10:
  1889. #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
  1890. case CHIP_RAVEN:
  1891. #endif
  1892. return amdgpu_dc != 0;
  1893. #endif
  1894. default:
  1895. return false;
  1896. }
  1897. }
  1898. /**
  1899. * amdgpu_device_has_dc_support - check if dc is supported
  1900. *
  1901. * @adev: amdgpu_device_pointer
  1902. *
  1903. * Returns true for supported, false for not supported
  1904. */
  1905. bool amdgpu_device_has_dc_support(struct amdgpu_device *adev)
  1906. {
  1907. if (amdgpu_sriov_vf(adev))
  1908. return false;
  1909. return amdgpu_device_asic_has_dc_support(adev->asic_type);
  1910. }
  1911. /**
  1912. * amdgpu_device_init - initialize the driver
  1913. *
  1914. * @adev: amdgpu_device pointer
  1915. * @pdev: drm dev pointer
  1916. * @pdev: pci dev pointer
  1917. * @flags: driver flags
  1918. *
  1919. * Initializes the driver info and hw (all asics).
  1920. * Returns 0 for success or an error on failure.
  1921. * Called at driver startup.
  1922. */
  1923. int amdgpu_device_init(struct amdgpu_device *adev,
  1924. struct drm_device *ddev,
  1925. struct pci_dev *pdev,
  1926. uint32_t flags)
  1927. {
  1928. int r, i;
  1929. bool runtime = false;
  1930. u32 max_MBps;
  1931. adev->shutdown = false;
  1932. adev->dev = &pdev->dev;
  1933. adev->ddev = ddev;
  1934. adev->pdev = pdev;
  1935. adev->flags = flags;
  1936. adev->asic_type = flags & AMD_ASIC_MASK;
  1937. adev->usec_timeout = AMDGPU_MAX_USEC_TIMEOUT;
  1938. adev->mc.gart_size = 512 * 1024 * 1024;
  1939. adev->accel_working = false;
  1940. adev->num_rings = 0;
  1941. adev->mman.buffer_funcs = NULL;
  1942. adev->mman.buffer_funcs_ring = NULL;
  1943. adev->vm_manager.vm_pte_funcs = NULL;
  1944. adev->vm_manager.vm_pte_num_rings = 0;
  1945. adev->gart.gart_funcs = NULL;
  1946. adev->fence_context = dma_fence_context_alloc(AMDGPU_MAX_RINGS);
  1947. bitmap_zero(adev->gfx.pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
  1948. adev->smc_rreg = &amdgpu_invalid_rreg;
  1949. adev->smc_wreg = &amdgpu_invalid_wreg;
  1950. adev->pcie_rreg = &amdgpu_invalid_rreg;
  1951. adev->pcie_wreg = &amdgpu_invalid_wreg;
  1952. adev->pciep_rreg = &amdgpu_invalid_rreg;
  1953. adev->pciep_wreg = &amdgpu_invalid_wreg;
  1954. adev->uvd_ctx_rreg = &amdgpu_invalid_rreg;
  1955. adev->uvd_ctx_wreg = &amdgpu_invalid_wreg;
  1956. adev->didt_rreg = &amdgpu_invalid_rreg;
  1957. adev->didt_wreg = &amdgpu_invalid_wreg;
  1958. adev->gc_cac_rreg = &amdgpu_invalid_rreg;
  1959. adev->gc_cac_wreg = &amdgpu_invalid_wreg;
  1960. adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg;
  1961. adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg;
  1962. DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n",
  1963. amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device,
  1964. pdev->subsystem_vendor, pdev->subsystem_device, pdev->revision);
  1965. /* mutex initialization are all done here so we
  1966. * can recall function without having locking issues */
  1967. atomic_set(&adev->irq.ih.lock, 0);
  1968. mutex_init(&adev->firmware.mutex);
  1969. mutex_init(&adev->pm.mutex);
  1970. mutex_init(&adev->gfx.gpu_clock_mutex);
  1971. mutex_init(&adev->srbm_mutex);
  1972. mutex_init(&adev->gfx.pipe_reserve_mutex);
  1973. mutex_init(&adev->grbm_idx_mutex);
  1974. mutex_init(&adev->mn_lock);
  1975. mutex_init(&adev->virt.vf_errors.lock);
  1976. hash_init(adev->mn_hash);
  1977. mutex_init(&adev->lock_reset);
  1978. amdgpu_check_arguments(adev);
  1979. spin_lock_init(&adev->mmio_idx_lock);
  1980. spin_lock_init(&adev->smc_idx_lock);
  1981. spin_lock_init(&adev->pcie_idx_lock);
  1982. spin_lock_init(&adev->uvd_ctx_idx_lock);
  1983. spin_lock_init(&adev->didt_idx_lock);
  1984. spin_lock_init(&adev->gc_cac_idx_lock);
  1985. spin_lock_init(&adev->se_cac_idx_lock);
  1986. spin_lock_init(&adev->audio_endpt_idx_lock);
  1987. spin_lock_init(&adev->mm_stats.lock);
  1988. INIT_LIST_HEAD(&adev->shadow_list);
  1989. mutex_init(&adev->shadow_list_lock);
  1990. INIT_LIST_HEAD(&adev->ring_lru_list);
  1991. spin_lock_init(&adev->ring_lru_list_lock);
  1992. INIT_DELAYED_WORK(&adev->late_init_work, amdgpu_late_init_func_handler);
  1993. /* Registers mapping */
  1994. /* TODO: block userspace mapping of io register */
  1995. if (adev->asic_type >= CHIP_BONAIRE) {
  1996. adev->rmmio_base = pci_resource_start(adev->pdev, 5);
  1997. adev->rmmio_size = pci_resource_len(adev->pdev, 5);
  1998. } else {
  1999. adev->rmmio_base = pci_resource_start(adev->pdev, 2);
  2000. adev->rmmio_size = pci_resource_len(adev->pdev, 2);
  2001. }
  2002. adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
  2003. if (adev->rmmio == NULL) {
  2004. return -ENOMEM;
  2005. }
  2006. DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
  2007. DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size);
  2008. /* doorbell bar mapping */
  2009. amdgpu_doorbell_init(adev);
  2010. /* io port mapping */
  2011. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  2012. if (pci_resource_flags(adev->pdev, i) & IORESOURCE_IO) {
  2013. adev->rio_mem_size = pci_resource_len(adev->pdev, i);
  2014. adev->rio_mem = pci_iomap(adev->pdev, i, adev->rio_mem_size);
  2015. break;
  2016. }
  2017. }
  2018. if (adev->rio_mem == NULL)
  2019. DRM_INFO("PCI I/O BAR is not found.\n");
  2020. /* early init functions */
  2021. r = amdgpu_early_init(adev);
  2022. if (r)
  2023. return r;
  2024. /* if we have > 1 VGA cards, then disable the amdgpu VGA resources */
  2025. /* this will fail for cards that aren't VGA class devices, just
  2026. * ignore it */
  2027. vga_client_register(adev->pdev, adev, NULL, amdgpu_vga_set_decode);
  2028. if (amdgpu_runtime_pm == 1)
  2029. runtime = true;
  2030. if (amdgpu_device_is_px(ddev))
  2031. runtime = true;
  2032. if (!pci_is_thunderbolt_attached(adev->pdev))
  2033. vga_switcheroo_register_client(adev->pdev,
  2034. &amdgpu_switcheroo_ops, runtime);
  2035. if (runtime)
  2036. vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain);
  2037. /* Read BIOS */
  2038. if (!amdgpu_get_bios(adev)) {
  2039. r = -EINVAL;
  2040. goto failed;
  2041. }
  2042. r = amdgpu_atombios_init(adev);
  2043. if (r) {
  2044. dev_err(adev->dev, "amdgpu_atombios_init failed\n");
  2045. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL, 0, 0);
  2046. goto failed;
  2047. }
  2048. /* detect if we are with an SRIOV vbios */
  2049. amdgpu_device_detect_sriov_bios(adev);
  2050. /* Post card if necessary */
  2051. if (amdgpu_need_post(adev)) {
  2052. if (!adev->bios) {
  2053. dev_err(adev->dev, "no vBIOS found\n");
  2054. r = -EINVAL;
  2055. goto failed;
  2056. }
  2057. DRM_INFO("GPU posting now...\n");
  2058. r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
  2059. if (r) {
  2060. dev_err(adev->dev, "gpu post error!\n");
  2061. goto failed;
  2062. }
  2063. }
  2064. if (adev->is_atom_fw) {
  2065. /* Initialize clocks */
  2066. r = amdgpu_atomfirmware_get_clock_info(adev);
  2067. if (r) {
  2068. dev_err(adev->dev, "amdgpu_atomfirmware_get_clock_info failed\n");
  2069. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
  2070. goto failed;
  2071. }
  2072. } else {
  2073. /* Initialize clocks */
  2074. r = amdgpu_atombios_get_clock_info(adev);
  2075. if (r) {
  2076. dev_err(adev->dev, "amdgpu_atombios_get_clock_info failed\n");
  2077. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
  2078. goto failed;
  2079. }
  2080. /* init i2c buses */
  2081. if (!amdgpu_device_has_dc_support(adev))
  2082. amdgpu_atombios_i2c_init(adev);
  2083. }
  2084. /* Fence driver */
  2085. r = amdgpu_fence_driver_init(adev);
  2086. if (r) {
  2087. dev_err(adev->dev, "amdgpu_fence_driver_init failed\n");
  2088. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_FENCE_INIT_FAIL, 0, 0);
  2089. goto failed;
  2090. }
  2091. /* init the mode config */
  2092. drm_mode_config_init(adev->ddev);
  2093. r = amdgpu_init(adev);
  2094. if (r) {
  2095. /* failed in exclusive mode due to timeout */
  2096. if (amdgpu_sriov_vf(adev) &&
  2097. !amdgpu_sriov_runtime(adev) &&
  2098. amdgpu_virt_mmio_blocked(adev) &&
  2099. !amdgpu_virt_wait_reset(adev)) {
  2100. dev_err(adev->dev, "VF exclusive mode timeout\n");
  2101. /* Don't send request since VF is inactive. */
  2102. adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
  2103. adev->virt.ops = NULL;
  2104. r = -EAGAIN;
  2105. goto failed;
  2106. }
  2107. dev_err(adev->dev, "amdgpu_init failed\n");
  2108. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_INIT_FAIL, 0, 0);
  2109. amdgpu_fini(adev);
  2110. goto failed;
  2111. }
  2112. adev->accel_working = true;
  2113. amdgpu_vm_check_compute_bug(adev);
  2114. /* Initialize the buffer migration limit. */
  2115. if (amdgpu_moverate >= 0)
  2116. max_MBps = amdgpu_moverate;
  2117. else
  2118. max_MBps = 8; /* Allow 8 MB/s. */
  2119. /* Get a log2 for easy divisions. */
  2120. adev->mm_stats.log2_max_MBps = ilog2(max(1u, max_MBps));
  2121. r = amdgpu_ib_pool_init(adev);
  2122. if (r) {
  2123. dev_err(adev->dev, "IB initialization failed (%d).\n", r);
  2124. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_IB_INIT_FAIL, 0, r);
  2125. goto failed;
  2126. }
  2127. r = amdgpu_ib_ring_tests(adev);
  2128. if (r)
  2129. DRM_ERROR("ib ring test failed (%d).\n", r);
  2130. if (amdgpu_sriov_vf(adev))
  2131. amdgpu_virt_init_data_exchange(adev);
  2132. amdgpu_fbdev_init(adev);
  2133. r = amdgpu_pm_sysfs_init(adev);
  2134. if (r)
  2135. DRM_ERROR("registering pm debugfs failed (%d).\n", r);
  2136. r = amdgpu_gem_debugfs_init(adev);
  2137. if (r)
  2138. DRM_ERROR("registering gem debugfs failed (%d).\n", r);
  2139. r = amdgpu_debugfs_regs_init(adev);
  2140. if (r)
  2141. DRM_ERROR("registering register debugfs failed (%d).\n", r);
  2142. r = amdgpu_debugfs_test_ib_ring_init(adev);
  2143. if (r)
  2144. DRM_ERROR("registering register test ib ring debugfs failed (%d).\n", r);
  2145. r = amdgpu_debugfs_firmware_init(adev);
  2146. if (r)
  2147. DRM_ERROR("registering firmware debugfs failed (%d).\n", r);
  2148. r = amdgpu_debugfs_vbios_dump_init(adev);
  2149. if (r)
  2150. DRM_ERROR("Creating vbios dump debugfs failed (%d).\n", r);
  2151. if ((amdgpu_testing & 1)) {
  2152. if (adev->accel_working)
  2153. amdgpu_test_moves(adev);
  2154. else
  2155. DRM_INFO("amdgpu: acceleration disabled, skipping move tests\n");
  2156. }
  2157. if (amdgpu_benchmarking) {
  2158. if (adev->accel_working)
  2159. amdgpu_benchmark(adev, amdgpu_benchmarking);
  2160. else
  2161. DRM_INFO("amdgpu: acceleration disabled, skipping benchmarks\n");
  2162. }
  2163. /* enable clockgating, etc. after ib tests, etc. since some blocks require
  2164. * explicit gating rather than handling it automatically.
  2165. */
  2166. r = amdgpu_late_init(adev);
  2167. if (r) {
  2168. dev_err(adev->dev, "amdgpu_late_init failed\n");
  2169. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_LATE_INIT_FAIL, 0, r);
  2170. goto failed;
  2171. }
  2172. return 0;
  2173. failed:
  2174. amdgpu_vf_error_trans_all(adev);
  2175. if (runtime)
  2176. vga_switcheroo_fini_domain_pm_ops(adev->dev);
  2177. return r;
  2178. }
  2179. /**
  2180. * amdgpu_device_fini - tear down the driver
  2181. *
  2182. * @adev: amdgpu_device pointer
  2183. *
  2184. * Tear down the driver info (all asics).
  2185. * Called at driver shutdown.
  2186. */
  2187. void amdgpu_device_fini(struct amdgpu_device *adev)
  2188. {
  2189. int r;
  2190. DRM_INFO("amdgpu: finishing device.\n");
  2191. adev->shutdown = true;
  2192. if (adev->mode_info.mode_config_initialized)
  2193. drm_crtc_force_disable_all(adev->ddev);
  2194. /* evict vram memory */
  2195. amdgpu_bo_evict_vram(adev);
  2196. amdgpu_ib_pool_fini(adev);
  2197. amdgpu_fence_driver_fini(adev);
  2198. amdgpu_fbdev_fini(adev);
  2199. r = amdgpu_fini(adev);
  2200. if (adev->firmware.gpu_info_fw) {
  2201. release_firmware(adev->firmware.gpu_info_fw);
  2202. adev->firmware.gpu_info_fw = NULL;
  2203. }
  2204. adev->accel_working = false;
  2205. cancel_delayed_work_sync(&adev->late_init_work);
  2206. /* free i2c buses */
  2207. if (!amdgpu_device_has_dc_support(adev))
  2208. amdgpu_i2c_fini(adev);
  2209. amdgpu_atombios_fini(adev);
  2210. kfree(adev->bios);
  2211. adev->bios = NULL;
  2212. if (!pci_is_thunderbolt_attached(adev->pdev))
  2213. vga_switcheroo_unregister_client(adev->pdev);
  2214. if (adev->flags & AMD_IS_PX)
  2215. vga_switcheroo_fini_domain_pm_ops(adev->dev);
  2216. vga_client_register(adev->pdev, NULL, NULL, NULL);
  2217. if (adev->rio_mem)
  2218. pci_iounmap(adev->pdev, adev->rio_mem);
  2219. adev->rio_mem = NULL;
  2220. iounmap(adev->rmmio);
  2221. adev->rmmio = NULL;
  2222. amdgpu_doorbell_fini(adev);
  2223. amdgpu_pm_sysfs_fini(adev);
  2224. amdgpu_debugfs_regs_cleanup(adev);
  2225. }
  2226. /*
  2227. * Suspend & resume.
  2228. */
  2229. /**
  2230. * amdgpu_device_suspend - initiate device suspend
  2231. *
  2232. * @pdev: drm dev pointer
  2233. * @state: suspend state
  2234. *
  2235. * Puts the hw in the suspend state (all asics).
  2236. * Returns 0 for success or an error on failure.
  2237. * Called at driver suspend.
  2238. */
  2239. int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
  2240. {
  2241. struct amdgpu_device *adev;
  2242. struct drm_crtc *crtc;
  2243. struct drm_connector *connector;
  2244. int r;
  2245. if (dev == NULL || dev->dev_private == NULL) {
  2246. return -ENODEV;
  2247. }
  2248. adev = dev->dev_private;
  2249. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  2250. return 0;
  2251. drm_kms_helper_poll_disable(dev);
  2252. if (!amdgpu_device_has_dc_support(adev)) {
  2253. /* turn off display hw */
  2254. drm_modeset_lock_all(dev);
  2255. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  2256. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
  2257. }
  2258. drm_modeset_unlock_all(dev);
  2259. }
  2260. amdgpu_amdkfd_suspend(adev);
  2261. /* unpin the front buffers and cursors */
  2262. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  2263. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2264. struct amdgpu_framebuffer *rfb = to_amdgpu_framebuffer(crtc->primary->fb);
  2265. struct amdgpu_bo *robj;
  2266. if (amdgpu_crtc->cursor_bo) {
  2267. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  2268. r = amdgpu_bo_reserve(aobj, true);
  2269. if (r == 0) {
  2270. amdgpu_bo_unpin(aobj);
  2271. amdgpu_bo_unreserve(aobj);
  2272. }
  2273. }
  2274. if (rfb == NULL || rfb->obj == NULL) {
  2275. continue;
  2276. }
  2277. robj = gem_to_amdgpu_bo(rfb->obj);
  2278. /* don't unpin kernel fb objects */
  2279. if (!amdgpu_fbdev_robj_is_fb(adev, robj)) {
  2280. r = amdgpu_bo_reserve(robj, true);
  2281. if (r == 0) {
  2282. amdgpu_bo_unpin(robj);
  2283. amdgpu_bo_unreserve(robj);
  2284. }
  2285. }
  2286. }
  2287. /* evict vram memory */
  2288. amdgpu_bo_evict_vram(adev);
  2289. amdgpu_fence_driver_suspend(adev);
  2290. r = amdgpu_suspend(adev);
  2291. /* evict remaining vram memory
  2292. * This second call to evict vram is to evict the gart page table
  2293. * using the CPU.
  2294. */
  2295. amdgpu_bo_evict_vram(adev);
  2296. amdgpu_atombios_scratch_regs_save(adev);
  2297. pci_save_state(dev->pdev);
  2298. if (suspend) {
  2299. /* Shut down the device */
  2300. pci_disable_device(dev->pdev);
  2301. pci_set_power_state(dev->pdev, PCI_D3hot);
  2302. } else {
  2303. r = amdgpu_asic_reset(adev);
  2304. if (r)
  2305. DRM_ERROR("amdgpu asic reset failed\n");
  2306. }
  2307. if (fbcon) {
  2308. console_lock();
  2309. amdgpu_fbdev_set_suspend(adev, 1);
  2310. console_unlock();
  2311. }
  2312. return 0;
  2313. }
  2314. /**
  2315. * amdgpu_device_resume - initiate device resume
  2316. *
  2317. * @pdev: drm dev pointer
  2318. *
  2319. * Bring the hw back to operating state (all asics).
  2320. * Returns 0 for success or an error on failure.
  2321. * Called at driver resume.
  2322. */
  2323. int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon)
  2324. {
  2325. struct drm_connector *connector;
  2326. struct amdgpu_device *adev = dev->dev_private;
  2327. struct drm_crtc *crtc;
  2328. int r = 0;
  2329. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  2330. return 0;
  2331. if (fbcon)
  2332. console_lock();
  2333. if (resume) {
  2334. pci_set_power_state(dev->pdev, PCI_D0);
  2335. pci_restore_state(dev->pdev);
  2336. r = pci_enable_device(dev->pdev);
  2337. if (r)
  2338. goto unlock;
  2339. }
  2340. amdgpu_atombios_scratch_regs_restore(adev);
  2341. /* post card */
  2342. if (amdgpu_need_post(adev)) {
  2343. r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
  2344. if (r)
  2345. DRM_ERROR("amdgpu asic init failed\n");
  2346. }
  2347. r = amdgpu_resume(adev);
  2348. if (r) {
  2349. DRM_ERROR("amdgpu_resume failed (%d).\n", r);
  2350. goto unlock;
  2351. }
  2352. amdgpu_fence_driver_resume(adev);
  2353. if (resume) {
  2354. r = amdgpu_ib_ring_tests(adev);
  2355. if (r)
  2356. DRM_ERROR("ib ring test failed (%d).\n", r);
  2357. }
  2358. r = amdgpu_late_init(adev);
  2359. if (r)
  2360. goto unlock;
  2361. /* pin cursors */
  2362. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  2363. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  2364. if (amdgpu_crtc->cursor_bo) {
  2365. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  2366. r = amdgpu_bo_reserve(aobj, true);
  2367. if (r == 0) {
  2368. r = amdgpu_bo_pin(aobj,
  2369. AMDGPU_GEM_DOMAIN_VRAM,
  2370. &amdgpu_crtc->cursor_addr);
  2371. if (r != 0)
  2372. DRM_ERROR("Failed to pin cursor BO (%d)\n", r);
  2373. amdgpu_bo_unreserve(aobj);
  2374. }
  2375. }
  2376. }
  2377. r = amdgpu_amdkfd_resume(adev);
  2378. if (r)
  2379. return r;
  2380. /* blat the mode back in */
  2381. if (fbcon) {
  2382. if (!amdgpu_device_has_dc_support(adev)) {
  2383. /* pre DCE11 */
  2384. drm_helper_resume_force_mode(dev);
  2385. /* turn on display hw */
  2386. drm_modeset_lock_all(dev);
  2387. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  2388. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
  2389. }
  2390. drm_modeset_unlock_all(dev);
  2391. } else {
  2392. /*
  2393. * There is no equivalent atomic helper to turn on
  2394. * display, so we defined our own function for this,
  2395. * once suspend resume is supported by the atomic
  2396. * framework this will be reworked
  2397. */
  2398. amdgpu_dm_display_resume(adev);
  2399. }
  2400. }
  2401. drm_kms_helper_poll_enable(dev);
  2402. /*
  2403. * Most of the connector probing functions try to acquire runtime pm
  2404. * refs to ensure that the GPU is powered on when connector polling is
  2405. * performed. Since we're calling this from a runtime PM callback,
  2406. * trying to acquire rpm refs will cause us to deadlock.
  2407. *
  2408. * Since we're guaranteed to be holding the rpm lock, it's safe to
  2409. * temporarily disable the rpm helpers so this doesn't deadlock us.
  2410. */
  2411. #ifdef CONFIG_PM
  2412. dev->dev->power.disable_depth++;
  2413. #endif
  2414. if (!amdgpu_device_has_dc_support(adev))
  2415. drm_helper_hpd_irq_event(dev);
  2416. else
  2417. drm_kms_helper_hotplug_event(dev);
  2418. #ifdef CONFIG_PM
  2419. dev->dev->power.disable_depth--;
  2420. #endif
  2421. if (fbcon)
  2422. amdgpu_fbdev_set_suspend(adev, 0);
  2423. unlock:
  2424. if (fbcon)
  2425. console_unlock();
  2426. return r;
  2427. }
  2428. static bool amdgpu_check_soft_reset(struct amdgpu_device *adev)
  2429. {
  2430. int i;
  2431. bool asic_hang = false;
  2432. if (amdgpu_sriov_vf(adev))
  2433. return true;
  2434. for (i = 0; i < adev->num_ip_blocks; i++) {
  2435. if (!adev->ip_blocks[i].status.valid)
  2436. continue;
  2437. if (adev->ip_blocks[i].version->funcs->check_soft_reset)
  2438. adev->ip_blocks[i].status.hang =
  2439. adev->ip_blocks[i].version->funcs->check_soft_reset(adev);
  2440. if (adev->ip_blocks[i].status.hang) {
  2441. DRM_INFO("IP block:%s is hung!\n", adev->ip_blocks[i].version->funcs->name);
  2442. asic_hang = true;
  2443. }
  2444. }
  2445. return asic_hang;
  2446. }
  2447. static int amdgpu_pre_soft_reset(struct amdgpu_device *adev)
  2448. {
  2449. int i, r = 0;
  2450. for (i = 0; i < adev->num_ip_blocks; i++) {
  2451. if (!adev->ip_blocks[i].status.valid)
  2452. continue;
  2453. if (adev->ip_blocks[i].status.hang &&
  2454. adev->ip_blocks[i].version->funcs->pre_soft_reset) {
  2455. r = adev->ip_blocks[i].version->funcs->pre_soft_reset(adev);
  2456. if (r)
  2457. return r;
  2458. }
  2459. }
  2460. return 0;
  2461. }
  2462. static bool amdgpu_need_full_reset(struct amdgpu_device *adev)
  2463. {
  2464. int i;
  2465. for (i = 0; i < adev->num_ip_blocks; i++) {
  2466. if (!adev->ip_blocks[i].status.valid)
  2467. continue;
  2468. if ((adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) ||
  2469. (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) ||
  2470. (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_ACP) ||
  2471. (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE) ||
  2472. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP) {
  2473. if (adev->ip_blocks[i].status.hang) {
  2474. DRM_INFO("Some block need full reset!\n");
  2475. return true;
  2476. }
  2477. }
  2478. }
  2479. return false;
  2480. }
  2481. static int amdgpu_soft_reset(struct amdgpu_device *adev)
  2482. {
  2483. int i, r = 0;
  2484. for (i = 0; i < adev->num_ip_blocks; i++) {
  2485. if (!adev->ip_blocks[i].status.valid)
  2486. continue;
  2487. if (adev->ip_blocks[i].status.hang &&
  2488. adev->ip_blocks[i].version->funcs->soft_reset) {
  2489. r = adev->ip_blocks[i].version->funcs->soft_reset(adev);
  2490. if (r)
  2491. return r;
  2492. }
  2493. }
  2494. return 0;
  2495. }
  2496. static int amdgpu_post_soft_reset(struct amdgpu_device *adev)
  2497. {
  2498. int i, r = 0;
  2499. for (i = 0; i < adev->num_ip_blocks; i++) {
  2500. if (!adev->ip_blocks[i].status.valid)
  2501. continue;
  2502. if (adev->ip_blocks[i].status.hang &&
  2503. adev->ip_blocks[i].version->funcs->post_soft_reset)
  2504. r = adev->ip_blocks[i].version->funcs->post_soft_reset(adev);
  2505. if (r)
  2506. return r;
  2507. }
  2508. return 0;
  2509. }
  2510. bool amdgpu_need_backup(struct amdgpu_device *adev)
  2511. {
  2512. if (adev->flags & AMD_IS_APU)
  2513. return false;
  2514. return amdgpu_lockup_timeout > 0 ? true : false;
  2515. }
  2516. static int amdgpu_recover_vram_from_shadow(struct amdgpu_device *adev,
  2517. struct amdgpu_ring *ring,
  2518. struct amdgpu_bo *bo,
  2519. struct dma_fence **fence)
  2520. {
  2521. uint32_t domain;
  2522. int r;
  2523. if (!bo->shadow)
  2524. return 0;
  2525. r = amdgpu_bo_reserve(bo, true);
  2526. if (r)
  2527. return r;
  2528. domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
  2529. /* if bo has been evicted, then no need to recover */
  2530. if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
  2531. r = amdgpu_bo_validate(bo->shadow);
  2532. if (r) {
  2533. DRM_ERROR("bo validate failed!\n");
  2534. goto err;
  2535. }
  2536. r = amdgpu_bo_restore_from_shadow(adev, ring, bo,
  2537. NULL, fence, true);
  2538. if (r) {
  2539. DRM_ERROR("recover page table failed!\n");
  2540. goto err;
  2541. }
  2542. }
  2543. err:
  2544. amdgpu_bo_unreserve(bo);
  2545. return r;
  2546. }
  2547. /*
  2548. * amdgpu_reset - reset ASIC/GPU for bare-metal or passthrough
  2549. *
  2550. * @adev: amdgpu device pointer
  2551. * @reset_flags: output param tells caller the reset result
  2552. *
  2553. * attempt to do soft-reset or full-reset and reinitialize Asic
  2554. * return 0 means successed otherwise failed
  2555. */
  2556. static int amdgpu_reset(struct amdgpu_device *adev, uint64_t* reset_flags)
  2557. {
  2558. bool need_full_reset, vram_lost = 0;
  2559. int r;
  2560. need_full_reset = amdgpu_need_full_reset(adev);
  2561. if (!need_full_reset) {
  2562. amdgpu_pre_soft_reset(adev);
  2563. r = amdgpu_soft_reset(adev);
  2564. amdgpu_post_soft_reset(adev);
  2565. if (r || amdgpu_check_soft_reset(adev)) {
  2566. DRM_INFO("soft reset failed, will fallback to full reset!\n");
  2567. need_full_reset = true;
  2568. }
  2569. }
  2570. if (need_full_reset) {
  2571. r = amdgpu_suspend(adev);
  2572. retry:
  2573. amdgpu_atombios_scratch_regs_save(adev);
  2574. r = amdgpu_asic_reset(adev);
  2575. amdgpu_atombios_scratch_regs_restore(adev);
  2576. /* post card */
  2577. amdgpu_atom_asic_init(adev->mode_info.atom_context);
  2578. if (!r) {
  2579. dev_info(adev->dev, "GPU reset succeeded, trying to resume\n");
  2580. r = amdgpu_resume_phase1(adev);
  2581. if (r)
  2582. goto out;
  2583. vram_lost = amdgpu_check_vram_lost(adev);
  2584. if (vram_lost) {
  2585. DRM_ERROR("VRAM is lost!\n");
  2586. atomic_inc(&adev->vram_lost_counter);
  2587. }
  2588. r = amdgpu_gtt_mgr_recover(
  2589. &adev->mman.bdev.man[TTM_PL_TT]);
  2590. if (r)
  2591. goto out;
  2592. r = amdgpu_resume_phase2(adev);
  2593. if (r)
  2594. goto out;
  2595. if (vram_lost)
  2596. amdgpu_fill_reset_magic(adev);
  2597. }
  2598. }
  2599. out:
  2600. if (!r) {
  2601. amdgpu_irq_gpu_reset_resume_helper(adev);
  2602. r = amdgpu_ib_ring_tests(adev);
  2603. if (r) {
  2604. dev_err(adev->dev, "ib ring test failed (%d).\n", r);
  2605. r = amdgpu_suspend(adev);
  2606. need_full_reset = true;
  2607. goto retry;
  2608. }
  2609. }
  2610. if (reset_flags) {
  2611. if (vram_lost)
  2612. (*reset_flags) |= AMDGPU_RESET_INFO_VRAM_LOST;
  2613. if (need_full_reset)
  2614. (*reset_flags) |= AMDGPU_RESET_INFO_FULLRESET;
  2615. }
  2616. return r;
  2617. }
  2618. /*
  2619. * amdgpu_reset_sriov - reset ASIC for SR-IOV vf
  2620. *
  2621. * @adev: amdgpu device pointer
  2622. * @reset_flags: output param tells caller the reset result
  2623. *
  2624. * do VF FLR and reinitialize Asic
  2625. * return 0 means successed otherwise failed
  2626. */
  2627. static int amdgpu_reset_sriov(struct amdgpu_device *adev, uint64_t *reset_flags, bool from_hypervisor)
  2628. {
  2629. int r;
  2630. if (from_hypervisor)
  2631. r = amdgpu_virt_request_full_gpu(adev, true);
  2632. else
  2633. r = amdgpu_virt_reset_gpu(adev);
  2634. if (r)
  2635. return r;
  2636. /* Resume IP prior to SMC */
  2637. r = amdgpu_sriov_reinit_early(adev);
  2638. if (r)
  2639. goto error;
  2640. /* we need recover gart prior to run SMC/CP/SDMA resume */
  2641. amdgpu_gtt_mgr_recover(&adev->mman.bdev.man[TTM_PL_TT]);
  2642. /* now we are okay to resume SMC/CP/SDMA */
  2643. r = amdgpu_sriov_reinit_late(adev);
  2644. if (r)
  2645. goto error;
  2646. amdgpu_irq_gpu_reset_resume_helper(adev);
  2647. r = amdgpu_ib_ring_tests(adev);
  2648. if (r)
  2649. dev_err(adev->dev, "[GPU_RESET] ib ring test failed (%d).\n", r);
  2650. error:
  2651. /* release full control of GPU after ib test */
  2652. amdgpu_virt_release_full_gpu(adev, true);
  2653. if (reset_flags) {
  2654. if (adev->virt.gim_feature & AMDGIM_FEATURE_GIM_FLR_VRAMLOST) {
  2655. (*reset_flags) |= AMDGPU_RESET_INFO_VRAM_LOST;
  2656. atomic_inc(&adev->vram_lost_counter);
  2657. }
  2658. /* VF FLR or hotlink reset is always full-reset */
  2659. (*reset_flags) |= AMDGPU_RESET_INFO_FULLRESET;
  2660. }
  2661. return r;
  2662. }
  2663. /**
  2664. * amdgpu_gpu_recover - reset the asic and recover scheduler
  2665. *
  2666. * @adev: amdgpu device pointer
  2667. * @job: which job trigger hang
  2668. *
  2669. * Attempt to reset the GPU if it has hung (all asics).
  2670. * Returns 0 for success or an error on failure.
  2671. */
  2672. int amdgpu_gpu_recover(struct amdgpu_device *adev, struct amdgpu_job *job)
  2673. {
  2674. struct drm_atomic_state *state = NULL;
  2675. uint64_t reset_flags = 0;
  2676. int i, r, resched;
  2677. if (!amdgpu_check_soft_reset(adev)) {
  2678. DRM_INFO("No hardware hang detected. Did some blocks stall?\n");
  2679. return 0;
  2680. }
  2681. dev_info(adev->dev, "GPU reset begin!\n");
  2682. mutex_lock(&adev->lock_reset);
  2683. atomic_inc(&adev->gpu_reset_counter);
  2684. adev->in_gpu_reset = 1;
  2685. /* block TTM */
  2686. resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
  2687. /* store modesetting */
  2688. if (amdgpu_device_has_dc_support(adev))
  2689. state = drm_atomic_helper_suspend(adev->ddev);
  2690. /* block scheduler */
  2691. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  2692. struct amdgpu_ring *ring = adev->rings[i];
  2693. if (!ring || !ring->sched.thread)
  2694. continue;
  2695. /* only focus on the ring hit timeout if &job not NULL */
  2696. if (job && job->ring->idx != i)
  2697. continue;
  2698. kthread_park(ring->sched.thread);
  2699. amd_sched_hw_job_reset(&ring->sched, &job->base);
  2700. /* after all hw jobs are reset, hw fence is meaningless, so force_completion */
  2701. amdgpu_fence_driver_force_completion(ring);
  2702. }
  2703. if (amdgpu_sriov_vf(adev))
  2704. r = amdgpu_reset_sriov(adev, &reset_flags, job ? false : true);
  2705. else
  2706. r = amdgpu_reset(adev, &reset_flags);
  2707. if (!r) {
  2708. if (((reset_flags & AMDGPU_RESET_INFO_FULLRESET) && !(adev->flags & AMD_IS_APU)) ||
  2709. (reset_flags & AMDGPU_RESET_INFO_VRAM_LOST)) {
  2710. struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
  2711. struct amdgpu_bo *bo, *tmp;
  2712. struct dma_fence *fence = NULL, *next = NULL;
  2713. DRM_INFO("recover vram bo from shadow\n");
  2714. mutex_lock(&adev->shadow_list_lock);
  2715. list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list) {
  2716. next = NULL;
  2717. amdgpu_recover_vram_from_shadow(adev, ring, bo, &next);
  2718. if (fence) {
  2719. r = dma_fence_wait(fence, false);
  2720. if (r) {
  2721. WARN(r, "recovery from shadow isn't completed\n");
  2722. break;
  2723. }
  2724. }
  2725. dma_fence_put(fence);
  2726. fence = next;
  2727. }
  2728. mutex_unlock(&adev->shadow_list_lock);
  2729. if (fence) {
  2730. r = dma_fence_wait(fence, false);
  2731. if (r)
  2732. WARN(r, "recovery from shadow isn't completed\n");
  2733. }
  2734. dma_fence_put(fence);
  2735. }
  2736. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  2737. struct amdgpu_ring *ring = adev->rings[i];
  2738. if (!ring || !ring->sched.thread)
  2739. continue;
  2740. /* only focus on the ring hit timeout if &job not NULL */
  2741. if (job && job->ring->idx != i)
  2742. continue;
  2743. amd_sched_job_recovery(&ring->sched);
  2744. kthread_unpark(ring->sched.thread);
  2745. }
  2746. } else {
  2747. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  2748. struct amdgpu_ring *ring = adev->rings[i];
  2749. if (!ring || !ring->sched.thread)
  2750. continue;
  2751. /* only focus on the ring hit timeout if &job not NULL */
  2752. if (job && job->ring->idx != i)
  2753. continue;
  2754. kthread_unpark(adev->rings[i]->sched.thread);
  2755. }
  2756. }
  2757. if (amdgpu_device_has_dc_support(adev)) {
  2758. if (drm_atomic_helper_resume(adev->ddev, state))
  2759. dev_info(adev->dev, "drm resume failed:%d\n", r);
  2760. amdgpu_dm_display_resume(adev);
  2761. } else {
  2762. drm_helper_resume_force_mode(adev->ddev);
  2763. }
  2764. ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched);
  2765. if (r) {
  2766. /* bad news, how to tell it to userspace ? */
  2767. dev_info(adev->dev, "GPU reset(%d) failed\n", atomic_read(&adev->gpu_reset_counter));
  2768. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_GPU_RESET_FAIL, 0, r);
  2769. } else {
  2770. dev_info(adev->dev, "GPU reset(%d) successed!\n",atomic_read(&adev->gpu_reset_counter));
  2771. }
  2772. amdgpu_vf_error_trans_all(adev);
  2773. adev->in_gpu_reset = 0;
  2774. mutex_unlock(&adev->lock_reset);
  2775. return r;
  2776. }
  2777. void amdgpu_get_pcie_info(struct amdgpu_device *adev)
  2778. {
  2779. u32 mask;
  2780. int ret;
  2781. if (amdgpu_pcie_gen_cap)
  2782. adev->pm.pcie_gen_mask = amdgpu_pcie_gen_cap;
  2783. if (amdgpu_pcie_lane_cap)
  2784. adev->pm.pcie_mlw_mask = amdgpu_pcie_lane_cap;
  2785. /* covers APUs as well */
  2786. if (pci_is_root_bus(adev->pdev->bus)) {
  2787. if (adev->pm.pcie_gen_mask == 0)
  2788. adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
  2789. if (adev->pm.pcie_mlw_mask == 0)
  2790. adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
  2791. return;
  2792. }
  2793. if (adev->pm.pcie_gen_mask == 0) {
  2794. ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask);
  2795. if (!ret) {
  2796. adev->pm.pcie_gen_mask = (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
  2797. CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
  2798. CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3);
  2799. if (mask & DRM_PCIE_SPEED_25)
  2800. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1;
  2801. if (mask & DRM_PCIE_SPEED_50)
  2802. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2;
  2803. if (mask & DRM_PCIE_SPEED_80)
  2804. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3;
  2805. } else {
  2806. adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
  2807. }
  2808. }
  2809. if (adev->pm.pcie_mlw_mask == 0) {
  2810. ret = drm_pcie_get_max_link_width(adev->ddev, &mask);
  2811. if (!ret) {
  2812. switch (mask) {
  2813. case 32:
  2814. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 |
  2815. CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
  2816. CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  2817. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2818. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2819. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2820. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2821. break;
  2822. case 16:
  2823. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
  2824. CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  2825. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2826. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2827. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2828. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2829. break;
  2830. case 12:
  2831. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  2832. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2833. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2834. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2835. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2836. break;
  2837. case 8:
  2838. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2839. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2840. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2841. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2842. break;
  2843. case 4:
  2844. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2845. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2846. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2847. break;
  2848. case 2:
  2849. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2850. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2851. break;
  2852. case 1:
  2853. adev->pm.pcie_mlw_mask = CAIL_PCIE_LINK_WIDTH_SUPPORT_X1;
  2854. break;
  2855. default:
  2856. break;
  2857. }
  2858. } else {
  2859. adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
  2860. }
  2861. }
  2862. }
  2863. /*
  2864. * Debugfs
  2865. */
  2866. int amdgpu_debugfs_add_files(struct amdgpu_device *adev,
  2867. const struct drm_info_list *files,
  2868. unsigned nfiles)
  2869. {
  2870. unsigned i;
  2871. for (i = 0; i < adev->debugfs_count; i++) {
  2872. if (adev->debugfs[i].files == files) {
  2873. /* Already registered */
  2874. return 0;
  2875. }
  2876. }
  2877. i = adev->debugfs_count + 1;
  2878. if (i > AMDGPU_DEBUGFS_MAX_COMPONENTS) {
  2879. DRM_ERROR("Reached maximum number of debugfs components.\n");
  2880. DRM_ERROR("Report so we increase "
  2881. "AMDGPU_DEBUGFS_MAX_COMPONENTS.\n");
  2882. return -EINVAL;
  2883. }
  2884. adev->debugfs[adev->debugfs_count].files = files;
  2885. adev->debugfs[adev->debugfs_count].num_files = nfiles;
  2886. adev->debugfs_count = i;
  2887. #if defined(CONFIG_DEBUG_FS)
  2888. drm_debugfs_create_files(files, nfiles,
  2889. adev->ddev->primary->debugfs_root,
  2890. adev->ddev->primary);
  2891. #endif
  2892. return 0;
  2893. }
  2894. #if defined(CONFIG_DEBUG_FS)
  2895. static ssize_t amdgpu_debugfs_regs_read(struct file *f, char __user *buf,
  2896. size_t size, loff_t *pos)
  2897. {
  2898. struct amdgpu_device *adev = file_inode(f)->i_private;
  2899. ssize_t result = 0;
  2900. int r;
  2901. bool pm_pg_lock, use_bank;
  2902. unsigned instance_bank, sh_bank, se_bank;
  2903. if (size & 0x3 || *pos & 0x3)
  2904. return -EINVAL;
  2905. /* are we reading registers for which a PG lock is necessary? */
  2906. pm_pg_lock = (*pos >> 23) & 1;
  2907. if (*pos & (1ULL << 62)) {
  2908. se_bank = (*pos & GENMASK_ULL(33, 24)) >> 24;
  2909. sh_bank = (*pos & GENMASK_ULL(43, 34)) >> 34;
  2910. instance_bank = (*pos & GENMASK_ULL(53, 44)) >> 44;
  2911. if (se_bank == 0x3FF)
  2912. se_bank = 0xFFFFFFFF;
  2913. if (sh_bank == 0x3FF)
  2914. sh_bank = 0xFFFFFFFF;
  2915. if (instance_bank == 0x3FF)
  2916. instance_bank = 0xFFFFFFFF;
  2917. use_bank = 1;
  2918. } else {
  2919. use_bank = 0;
  2920. }
  2921. *pos &= (1UL << 22) - 1;
  2922. if (use_bank) {
  2923. if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) ||
  2924. (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines))
  2925. return -EINVAL;
  2926. mutex_lock(&adev->grbm_idx_mutex);
  2927. amdgpu_gfx_select_se_sh(adev, se_bank,
  2928. sh_bank, instance_bank);
  2929. }
  2930. if (pm_pg_lock)
  2931. mutex_lock(&adev->pm.mutex);
  2932. while (size) {
  2933. uint32_t value;
  2934. if (*pos > adev->rmmio_size)
  2935. goto end;
  2936. value = RREG32(*pos >> 2);
  2937. r = put_user(value, (uint32_t *)buf);
  2938. if (r) {
  2939. result = r;
  2940. goto end;
  2941. }
  2942. result += 4;
  2943. buf += 4;
  2944. *pos += 4;
  2945. size -= 4;
  2946. }
  2947. end:
  2948. if (use_bank) {
  2949. amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  2950. mutex_unlock(&adev->grbm_idx_mutex);
  2951. }
  2952. if (pm_pg_lock)
  2953. mutex_unlock(&adev->pm.mutex);
  2954. return result;
  2955. }
  2956. static ssize_t amdgpu_debugfs_regs_write(struct file *f, const char __user *buf,
  2957. size_t size, loff_t *pos)
  2958. {
  2959. struct amdgpu_device *adev = file_inode(f)->i_private;
  2960. ssize_t result = 0;
  2961. int r;
  2962. bool pm_pg_lock, use_bank;
  2963. unsigned instance_bank, sh_bank, se_bank;
  2964. if (size & 0x3 || *pos & 0x3)
  2965. return -EINVAL;
  2966. /* are we reading registers for which a PG lock is necessary? */
  2967. pm_pg_lock = (*pos >> 23) & 1;
  2968. if (*pos & (1ULL << 62)) {
  2969. se_bank = (*pos & GENMASK_ULL(33, 24)) >> 24;
  2970. sh_bank = (*pos & GENMASK_ULL(43, 34)) >> 34;
  2971. instance_bank = (*pos & GENMASK_ULL(53, 44)) >> 44;
  2972. if (se_bank == 0x3FF)
  2973. se_bank = 0xFFFFFFFF;
  2974. if (sh_bank == 0x3FF)
  2975. sh_bank = 0xFFFFFFFF;
  2976. if (instance_bank == 0x3FF)
  2977. instance_bank = 0xFFFFFFFF;
  2978. use_bank = 1;
  2979. } else {
  2980. use_bank = 0;
  2981. }
  2982. *pos &= (1UL << 22) - 1;
  2983. if (use_bank) {
  2984. if ((sh_bank != 0xFFFFFFFF && sh_bank >= adev->gfx.config.max_sh_per_se) ||
  2985. (se_bank != 0xFFFFFFFF && se_bank >= adev->gfx.config.max_shader_engines))
  2986. return -EINVAL;
  2987. mutex_lock(&adev->grbm_idx_mutex);
  2988. amdgpu_gfx_select_se_sh(adev, se_bank,
  2989. sh_bank, instance_bank);
  2990. }
  2991. if (pm_pg_lock)
  2992. mutex_lock(&adev->pm.mutex);
  2993. while (size) {
  2994. uint32_t value;
  2995. if (*pos > adev->rmmio_size)
  2996. return result;
  2997. r = get_user(value, (uint32_t *)buf);
  2998. if (r)
  2999. return r;
  3000. WREG32(*pos >> 2, value);
  3001. result += 4;
  3002. buf += 4;
  3003. *pos += 4;
  3004. size -= 4;
  3005. }
  3006. if (use_bank) {
  3007. amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff);
  3008. mutex_unlock(&adev->grbm_idx_mutex);
  3009. }
  3010. if (pm_pg_lock)
  3011. mutex_unlock(&adev->pm.mutex);
  3012. return result;
  3013. }
  3014. static ssize_t amdgpu_debugfs_regs_pcie_read(struct file *f, char __user *buf,
  3015. size_t size, loff_t *pos)
  3016. {
  3017. struct amdgpu_device *adev = file_inode(f)->i_private;
  3018. ssize_t result = 0;
  3019. int r;
  3020. if (size & 0x3 || *pos & 0x3)
  3021. return -EINVAL;
  3022. while (size) {
  3023. uint32_t value;
  3024. value = RREG32_PCIE(*pos >> 2);
  3025. r = put_user(value, (uint32_t *)buf);
  3026. if (r)
  3027. return r;
  3028. result += 4;
  3029. buf += 4;
  3030. *pos += 4;
  3031. size -= 4;
  3032. }
  3033. return result;
  3034. }
  3035. static ssize_t amdgpu_debugfs_regs_pcie_write(struct file *f, const char __user *buf,
  3036. size_t size, loff_t *pos)
  3037. {
  3038. struct amdgpu_device *adev = file_inode(f)->i_private;
  3039. ssize_t result = 0;
  3040. int r;
  3041. if (size & 0x3 || *pos & 0x3)
  3042. return -EINVAL;
  3043. while (size) {
  3044. uint32_t value;
  3045. r = get_user(value, (uint32_t *)buf);
  3046. if (r)
  3047. return r;
  3048. WREG32_PCIE(*pos >> 2, value);
  3049. result += 4;
  3050. buf += 4;
  3051. *pos += 4;
  3052. size -= 4;
  3053. }
  3054. return result;
  3055. }
  3056. static ssize_t amdgpu_debugfs_regs_didt_read(struct file *f, char __user *buf,
  3057. size_t size, loff_t *pos)
  3058. {
  3059. struct amdgpu_device *adev = file_inode(f)->i_private;
  3060. ssize_t result = 0;
  3061. int r;
  3062. if (size & 0x3 || *pos & 0x3)
  3063. return -EINVAL;
  3064. while (size) {
  3065. uint32_t value;
  3066. value = RREG32_DIDT(*pos >> 2);
  3067. r = put_user(value, (uint32_t *)buf);
  3068. if (r)
  3069. return r;
  3070. result += 4;
  3071. buf += 4;
  3072. *pos += 4;
  3073. size -= 4;
  3074. }
  3075. return result;
  3076. }
  3077. static ssize_t amdgpu_debugfs_regs_didt_write(struct file *f, const char __user *buf,
  3078. size_t size, loff_t *pos)
  3079. {
  3080. struct amdgpu_device *adev = file_inode(f)->i_private;
  3081. ssize_t result = 0;
  3082. int r;
  3083. if (size & 0x3 || *pos & 0x3)
  3084. return -EINVAL;
  3085. while (size) {
  3086. uint32_t value;
  3087. r = get_user(value, (uint32_t *)buf);
  3088. if (r)
  3089. return r;
  3090. WREG32_DIDT(*pos >> 2, value);
  3091. result += 4;
  3092. buf += 4;
  3093. *pos += 4;
  3094. size -= 4;
  3095. }
  3096. return result;
  3097. }
  3098. static ssize_t amdgpu_debugfs_regs_smc_read(struct file *f, char __user *buf,
  3099. size_t size, loff_t *pos)
  3100. {
  3101. struct amdgpu_device *adev = file_inode(f)->i_private;
  3102. ssize_t result = 0;
  3103. int r;
  3104. if (size & 0x3 || *pos & 0x3)
  3105. return -EINVAL;
  3106. while (size) {
  3107. uint32_t value;
  3108. value = RREG32_SMC(*pos);
  3109. r = put_user(value, (uint32_t *)buf);
  3110. if (r)
  3111. return r;
  3112. result += 4;
  3113. buf += 4;
  3114. *pos += 4;
  3115. size -= 4;
  3116. }
  3117. return result;
  3118. }
  3119. static ssize_t amdgpu_debugfs_regs_smc_write(struct file *f, const char __user *buf,
  3120. size_t size, loff_t *pos)
  3121. {
  3122. struct amdgpu_device *adev = file_inode(f)->i_private;
  3123. ssize_t result = 0;
  3124. int r;
  3125. if (size & 0x3 || *pos & 0x3)
  3126. return -EINVAL;
  3127. while (size) {
  3128. uint32_t value;
  3129. r = get_user(value, (uint32_t *)buf);
  3130. if (r)
  3131. return r;
  3132. WREG32_SMC(*pos, value);
  3133. result += 4;
  3134. buf += 4;
  3135. *pos += 4;
  3136. size -= 4;
  3137. }
  3138. return result;
  3139. }
  3140. static ssize_t amdgpu_debugfs_gca_config_read(struct file *f, char __user *buf,
  3141. size_t size, loff_t *pos)
  3142. {
  3143. struct amdgpu_device *adev = file_inode(f)->i_private;
  3144. ssize_t result = 0;
  3145. int r;
  3146. uint32_t *config, no_regs = 0;
  3147. if (size & 0x3 || *pos & 0x3)
  3148. return -EINVAL;
  3149. config = kmalloc_array(256, sizeof(*config), GFP_KERNEL);
  3150. if (!config)
  3151. return -ENOMEM;
  3152. /* version, increment each time something is added */
  3153. config[no_regs++] = 3;
  3154. config[no_regs++] = adev->gfx.config.max_shader_engines;
  3155. config[no_regs++] = adev->gfx.config.max_tile_pipes;
  3156. config[no_regs++] = adev->gfx.config.max_cu_per_sh;
  3157. config[no_regs++] = adev->gfx.config.max_sh_per_se;
  3158. config[no_regs++] = adev->gfx.config.max_backends_per_se;
  3159. config[no_regs++] = adev->gfx.config.max_texture_channel_caches;
  3160. config[no_regs++] = adev->gfx.config.max_gprs;
  3161. config[no_regs++] = adev->gfx.config.max_gs_threads;
  3162. config[no_regs++] = adev->gfx.config.max_hw_contexts;
  3163. config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_frontend;
  3164. config[no_regs++] = adev->gfx.config.sc_prim_fifo_size_backend;
  3165. config[no_regs++] = adev->gfx.config.sc_hiz_tile_fifo_size;
  3166. config[no_regs++] = adev->gfx.config.sc_earlyz_tile_fifo_size;
  3167. config[no_regs++] = adev->gfx.config.num_tile_pipes;
  3168. config[no_regs++] = adev->gfx.config.backend_enable_mask;
  3169. config[no_regs++] = adev->gfx.config.mem_max_burst_length_bytes;
  3170. config[no_regs++] = adev->gfx.config.mem_row_size_in_kb;
  3171. config[no_regs++] = adev->gfx.config.shader_engine_tile_size;
  3172. config[no_regs++] = adev->gfx.config.num_gpus;
  3173. config[no_regs++] = adev->gfx.config.multi_gpu_tile_size;
  3174. config[no_regs++] = adev->gfx.config.mc_arb_ramcfg;
  3175. config[no_regs++] = adev->gfx.config.gb_addr_config;
  3176. config[no_regs++] = adev->gfx.config.num_rbs;
  3177. /* rev==1 */
  3178. config[no_regs++] = adev->rev_id;
  3179. config[no_regs++] = adev->pg_flags;
  3180. config[no_regs++] = adev->cg_flags;
  3181. /* rev==2 */
  3182. config[no_regs++] = adev->family;
  3183. config[no_regs++] = adev->external_rev_id;
  3184. /* rev==3 */
  3185. config[no_regs++] = adev->pdev->device;
  3186. config[no_regs++] = adev->pdev->revision;
  3187. config[no_regs++] = adev->pdev->subsystem_device;
  3188. config[no_regs++] = adev->pdev->subsystem_vendor;
  3189. while (size && (*pos < no_regs * 4)) {
  3190. uint32_t value;
  3191. value = config[*pos >> 2];
  3192. r = put_user(value, (uint32_t *)buf);
  3193. if (r) {
  3194. kfree(config);
  3195. return r;
  3196. }
  3197. result += 4;
  3198. buf += 4;
  3199. *pos += 4;
  3200. size -= 4;
  3201. }
  3202. kfree(config);
  3203. return result;
  3204. }
  3205. static ssize_t amdgpu_debugfs_sensor_read(struct file *f, char __user *buf,
  3206. size_t size, loff_t *pos)
  3207. {
  3208. struct amdgpu_device *adev = file_inode(f)->i_private;
  3209. int idx, x, outsize, r, valuesize;
  3210. uint32_t values[16];
  3211. if (size & 3 || *pos & 0x3)
  3212. return -EINVAL;
  3213. if (amdgpu_dpm == 0)
  3214. return -EINVAL;
  3215. /* convert offset to sensor number */
  3216. idx = *pos >> 2;
  3217. valuesize = sizeof(values);
  3218. if (adev->powerplay.pp_funcs && adev->powerplay.pp_funcs->read_sensor)
  3219. r = amdgpu_dpm_read_sensor(adev, idx, &values[0], &valuesize);
  3220. else
  3221. return -EINVAL;
  3222. if (size > valuesize)
  3223. return -EINVAL;
  3224. outsize = 0;
  3225. x = 0;
  3226. if (!r) {
  3227. while (size) {
  3228. r = put_user(values[x++], (int32_t *)buf);
  3229. buf += 4;
  3230. size -= 4;
  3231. outsize += 4;
  3232. }
  3233. }
  3234. return !r ? outsize : r;
  3235. }
  3236. static ssize_t amdgpu_debugfs_wave_read(struct file *f, char __user *buf,
  3237. size_t size, loff_t *pos)
  3238. {
  3239. struct amdgpu_device *adev = f->f_inode->i_private;
  3240. int r, x;
  3241. ssize_t result=0;
  3242. uint32_t offset, se, sh, cu, wave, simd, data[32];
  3243. if (size & 3 || *pos & 3)
  3244. return -EINVAL;
  3245. /* decode offset */
  3246. offset = (*pos & GENMASK_ULL(6, 0));
  3247. se = (*pos & GENMASK_ULL(14, 7)) >> 7;
  3248. sh = (*pos & GENMASK_ULL(22, 15)) >> 15;
  3249. cu = (*pos & GENMASK_ULL(30, 23)) >> 23;
  3250. wave = (*pos & GENMASK_ULL(36, 31)) >> 31;
  3251. simd = (*pos & GENMASK_ULL(44, 37)) >> 37;
  3252. /* switch to the specific se/sh/cu */
  3253. mutex_lock(&adev->grbm_idx_mutex);
  3254. amdgpu_gfx_select_se_sh(adev, se, sh, cu);
  3255. x = 0;
  3256. if (adev->gfx.funcs->read_wave_data)
  3257. adev->gfx.funcs->read_wave_data(adev, simd, wave, data, &x);
  3258. amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
  3259. mutex_unlock(&adev->grbm_idx_mutex);
  3260. if (!x)
  3261. return -EINVAL;
  3262. while (size && (offset < x * 4)) {
  3263. uint32_t value;
  3264. value = data[offset >> 2];
  3265. r = put_user(value, (uint32_t *)buf);
  3266. if (r)
  3267. return r;
  3268. result += 4;
  3269. buf += 4;
  3270. offset += 4;
  3271. size -= 4;
  3272. }
  3273. return result;
  3274. }
  3275. static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
  3276. size_t size, loff_t *pos)
  3277. {
  3278. struct amdgpu_device *adev = f->f_inode->i_private;
  3279. int r;
  3280. ssize_t result = 0;
  3281. uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
  3282. if (size & 3 || *pos & 3)
  3283. return -EINVAL;
  3284. /* decode offset */
  3285. offset = *pos & GENMASK_ULL(11, 0);
  3286. se = (*pos & GENMASK_ULL(19, 12)) >> 12;
  3287. sh = (*pos & GENMASK_ULL(27, 20)) >> 20;
  3288. cu = (*pos & GENMASK_ULL(35, 28)) >> 28;
  3289. wave = (*pos & GENMASK_ULL(43, 36)) >> 36;
  3290. simd = (*pos & GENMASK_ULL(51, 44)) >> 44;
  3291. thread = (*pos & GENMASK_ULL(59, 52)) >> 52;
  3292. bank = (*pos & GENMASK_ULL(61, 60)) >> 60;
  3293. data = kmalloc_array(1024, sizeof(*data), GFP_KERNEL);
  3294. if (!data)
  3295. return -ENOMEM;
  3296. /* switch to the specific se/sh/cu */
  3297. mutex_lock(&adev->grbm_idx_mutex);
  3298. amdgpu_gfx_select_se_sh(adev, se, sh, cu);
  3299. if (bank == 0) {
  3300. if (adev->gfx.funcs->read_wave_vgprs)
  3301. adev->gfx.funcs->read_wave_vgprs(adev, simd, wave, thread, offset, size>>2, data);
  3302. } else {
  3303. if (adev->gfx.funcs->read_wave_sgprs)
  3304. adev->gfx.funcs->read_wave_sgprs(adev, simd, wave, offset, size>>2, data);
  3305. }
  3306. amdgpu_gfx_select_se_sh(adev, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
  3307. mutex_unlock(&adev->grbm_idx_mutex);
  3308. while (size) {
  3309. uint32_t value;
  3310. value = data[offset++];
  3311. r = put_user(value, (uint32_t *)buf);
  3312. if (r) {
  3313. result = r;
  3314. goto err;
  3315. }
  3316. result += 4;
  3317. buf += 4;
  3318. size -= 4;
  3319. }
  3320. err:
  3321. kfree(data);
  3322. return result;
  3323. }
  3324. static const struct file_operations amdgpu_debugfs_regs_fops = {
  3325. .owner = THIS_MODULE,
  3326. .read = amdgpu_debugfs_regs_read,
  3327. .write = amdgpu_debugfs_regs_write,
  3328. .llseek = default_llseek
  3329. };
  3330. static const struct file_operations amdgpu_debugfs_regs_didt_fops = {
  3331. .owner = THIS_MODULE,
  3332. .read = amdgpu_debugfs_regs_didt_read,
  3333. .write = amdgpu_debugfs_regs_didt_write,
  3334. .llseek = default_llseek
  3335. };
  3336. static const struct file_operations amdgpu_debugfs_regs_pcie_fops = {
  3337. .owner = THIS_MODULE,
  3338. .read = amdgpu_debugfs_regs_pcie_read,
  3339. .write = amdgpu_debugfs_regs_pcie_write,
  3340. .llseek = default_llseek
  3341. };
  3342. static const struct file_operations amdgpu_debugfs_regs_smc_fops = {
  3343. .owner = THIS_MODULE,
  3344. .read = amdgpu_debugfs_regs_smc_read,
  3345. .write = amdgpu_debugfs_regs_smc_write,
  3346. .llseek = default_llseek
  3347. };
  3348. static const struct file_operations amdgpu_debugfs_gca_config_fops = {
  3349. .owner = THIS_MODULE,
  3350. .read = amdgpu_debugfs_gca_config_read,
  3351. .llseek = default_llseek
  3352. };
  3353. static const struct file_operations amdgpu_debugfs_sensors_fops = {
  3354. .owner = THIS_MODULE,
  3355. .read = amdgpu_debugfs_sensor_read,
  3356. .llseek = default_llseek
  3357. };
  3358. static const struct file_operations amdgpu_debugfs_wave_fops = {
  3359. .owner = THIS_MODULE,
  3360. .read = amdgpu_debugfs_wave_read,
  3361. .llseek = default_llseek
  3362. };
  3363. static const struct file_operations amdgpu_debugfs_gpr_fops = {
  3364. .owner = THIS_MODULE,
  3365. .read = amdgpu_debugfs_gpr_read,
  3366. .llseek = default_llseek
  3367. };
  3368. static const struct file_operations *debugfs_regs[] = {
  3369. &amdgpu_debugfs_regs_fops,
  3370. &amdgpu_debugfs_regs_didt_fops,
  3371. &amdgpu_debugfs_regs_pcie_fops,
  3372. &amdgpu_debugfs_regs_smc_fops,
  3373. &amdgpu_debugfs_gca_config_fops,
  3374. &amdgpu_debugfs_sensors_fops,
  3375. &amdgpu_debugfs_wave_fops,
  3376. &amdgpu_debugfs_gpr_fops,
  3377. };
  3378. static const char *debugfs_regs_names[] = {
  3379. "amdgpu_regs",
  3380. "amdgpu_regs_didt",
  3381. "amdgpu_regs_pcie",
  3382. "amdgpu_regs_smc",
  3383. "amdgpu_gca_config",
  3384. "amdgpu_sensors",
  3385. "amdgpu_wave",
  3386. "amdgpu_gpr",
  3387. };
  3388. static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
  3389. {
  3390. struct drm_minor *minor = adev->ddev->primary;
  3391. struct dentry *ent, *root = minor->debugfs_root;
  3392. unsigned i, j;
  3393. for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
  3394. ent = debugfs_create_file(debugfs_regs_names[i],
  3395. S_IFREG | S_IRUGO, root,
  3396. adev, debugfs_regs[i]);
  3397. if (IS_ERR(ent)) {
  3398. for (j = 0; j < i; j++) {
  3399. debugfs_remove(adev->debugfs_regs[i]);
  3400. adev->debugfs_regs[i] = NULL;
  3401. }
  3402. return PTR_ERR(ent);
  3403. }
  3404. if (!i)
  3405. i_size_write(ent->d_inode, adev->rmmio_size);
  3406. adev->debugfs_regs[i] = ent;
  3407. }
  3408. return 0;
  3409. }
  3410. static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev)
  3411. {
  3412. unsigned i;
  3413. for (i = 0; i < ARRAY_SIZE(debugfs_regs); i++) {
  3414. if (adev->debugfs_regs[i]) {
  3415. debugfs_remove(adev->debugfs_regs[i]);
  3416. adev->debugfs_regs[i] = NULL;
  3417. }
  3418. }
  3419. }
  3420. static int amdgpu_debugfs_test_ib(struct seq_file *m, void *data)
  3421. {
  3422. struct drm_info_node *node = (struct drm_info_node *) m->private;
  3423. struct drm_device *dev = node->minor->dev;
  3424. struct amdgpu_device *adev = dev->dev_private;
  3425. int r = 0, i;
  3426. /* hold on the scheduler */
  3427. for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
  3428. struct amdgpu_ring *ring = adev->rings[i];
  3429. if (!ring || !ring->sched.thread)
  3430. continue;
  3431. kthread_park(ring->sched.thread);
  3432. }
  3433. seq_printf(m, "run ib test:\n");
  3434. r = amdgpu_ib_ring_tests(adev);
  3435. if (r)
  3436. seq_printf(m, "ib ring tests failed (%d).\n", r);
  3437. else
  3438. seq_printf(m, "ib ring tests passed.\n");
  3439. /* go on the scheduler */
  3440. for (i = 0; i < AMDGPU_MAX_RINGS; i++) {
  3441. struct amdgpu_ring *ring = adev->rings[i];
  3442. if (!ring || !ring->sched.thread)
  3443. continue;
  3444. kthread_unpark(ring->sched.thread);
  3445. }
  3446. return 0;
  3447. }
  3448. static const struct drm_info_list amdgpu_debugfs_test_ib_ring_list[] = {
  3449. {"amdgpu_test_ib", &amdgpu_debugfs_test_ib}
  3450. };
  3451. static int amdgpu_debugfs_test_ib_ring_init(struct amdgpu_device *adev)
  3452. {
  3453. return amdgpu_debugfs_add_files(adev,
  3454. amdgpu_debugfs_test_ib_ring_list, 1);
  3455. }
  3456. int amdgpu_debugfs_init(struct drm_minor *minor)
  3457. {
  3458. return 0;
  3459. }
  3460. static int amdgpu_debugfs_get_vbios_dump(struct seq_file *m, void *data)
  3461. {
  3462. struct drm_info_node *node = (struct drm_info_node *) m->private;
  3463. struct drm_device *dev = node->minor->dev;
  3464. struct amdgpu_device *adev = dev->dev_private;
  3465. seq_write(m, adev->bios, adev->bios_size);
  3466. return 0;
  3467. }
  3468. static const struct drm_info_list amdgpu_vbios_dump_list[] = {
  3469. {"amdgpu_vbios",
  3470. amdgpu_debugfs_get_vbios_dump,
  3471. 0, NULL},
  3472. };
  3473. static int amdgpu_debugfs_vbios_dump_init(struct amdgpu_device *adev)
  3474. {
  3475. return amdgpu_debugfs_add_files(adev,
  3476. amdgpu_vbios_dump_list, 1);
  3477. }
  3478. #else
  3479. static int amdgpu_debugfs_test_ib_ring_init(struct amdgpu_device *adev)
  3480. {
  3481. return 0;
  3482. }
  3483. static int amdgpu_debugfs_regs_init(struct amdgpu_device *adev)
  3484. {
  3485. return 0;
  3486. }
  3487. static int amdgpu_debugfs_vbios_dump_init(struct amdgpu_device *adev)
  3488. {
  3489. return 0;
  3490. }
  3491. static void amdgpu_debugfs_regs_cleanup(struct amdgpu_device *adev) { }
  3492. #endif