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