amdgpu_device.c 103 KB

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