amdgpu_device.c 102 KB

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