amdgpu_device.c 89 KB

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