amdgpu_device.c 103 KB

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