amdgpu_device.c 103 KB

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