amdgpu_device.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835
  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 <drm/drmP.h>
  32. #include <drm/drm_crtc_helper.h>
  33. #include <drm/drm_atomic_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_vf_error.h"
  57. #include "amdgpu_amdkfd.h"
  58. #include "amdgpu_pm.h"
  59. MODULE_FIRMWARE("amdgpu/vega10_gpu_info.bin");
  60. MODULE_FIRMWARE("amdgpu/raven_gpu_info.bin");
  61. #define AMDGPU_RESUME_MS 2000
  62. static const char *amdgpu_asic_name[] = {
  63. "TAHITI",
  64. "PITCAIRN",
  65. "VERDE",
  66. "OLAND",
  67. "HAINAN",
  68. "BONAIRE",
  69. "KAVERI",
  70. "KABINI",
  71. "HAWAII",
  72. "MULLINS",
  73. "TOPAZ",
  74. "TONGA",
  75. "FIJI",
  76. "CARRIZO",
  77. "STONEY",
  78. "POLARIS10",
  79. "POLARIS11",
  80. "POLARIS12",
  81. "VEGA10",
  82. "RAVEN",
  83. "LAST",
  84. };
  85. bool amdgpu_device_is_px(struct drm_device *dev)
  86. {
  87. struct amdgpu_device *adev = dev->dev_private;
  88. if (adev->flags & AMD_IS_PX)
  89. return true;
  90. return false;
  91. }
  92. /*
  93. * MMIO register access helper functions.
  94. */
  95. uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
  96. uint32_t acc_flags)
  97. {
  98. uint32_t ret;
  99. if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
  100. return amdgpu_virt_kiq_rreg(adev, reg);
  101. if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
  102. ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
  103. else {
  104. unsigned long flags;
  105. spin_lock_irqsave(&adev->mmio_idx_lock, flags);
  106. writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
  107. ret = readl(((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
  108. spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
  109. }
  110. trace_amdgpu_mm_rreg(adev->pdev->device, reg, ret);
  111. return ret;
  112. }
  113. void amdgpu_mm_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v,
  114. uint32_t acc_flags)
  115. {
  116. trace_amdgpu_mm_wreg(adev->pdev->device, reg, v);
  117. if (adev->asic_type >= CHIP_VEGA10 && reg == 0) {
  118. adev->last_mm_index = v;
  119. }
  120. if (!(acc_flags & AMDGPU_REGS_NO_KIQ) && amdgpu_sriov_runtime(adev))
  121. return amdgpu_virt_kiq_wreg(adev, reg, v);
  122. if ((reg * 4) < adev->rmmio_size && !(acc_flags & AMDGPU_REGS_IDX))
  123. writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
  124. else {
  125. unsigned long flags;
  126. spin_lock_irqsave(&adev->mmio_idx_lock, flags);
  127. writel((reg * 4), ((void __iomem *)adev->rmmio) + (mmMM_INDEX * 4));
  128. writel(v, ((void __iomem *)adev->rmmio) + (mmMM_DATA * 4));
  129. spin_unlock_irqrestore(&adev->mmio_idx_lock, flags);
  130. }
  131. if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) {
  132. udelay(500);
  133. }
  134. }
  135. u32 amdgpu_io_rreg(struct amdgpu_device *adev, u32 reg)
  136. {
  137. if ((reg * 4) < adev->rio_mem_size)
  138. return ioread32(adev->rio_mem + (reg * 4));
  139. else {
  140. iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
  141. return ioread32(adev->rio_mem + (mmMM_DATA * 4));
  142. }
  143. }
  144. void amdgpu_io_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  145. {
  146. if (adev->asic_type >= CHIP_VEGA10 && reg == 0) {
  147. adev->last_mm_index = v;
  148. }
  149. if ((reg * 4) < adev->rio_mem_size)
  150. iowrite32(v, adev->rio_mem + (reg * 4));
  151. else {
  152. iowrite32((reg * 4), adev->rio_mem + (mmMM_INDEX * 4));
  153. iowrite32(v, adev->rio_mem + (mmMM_DATA * 4));
  154. }
  155. if (adev->asic_type >= CHIP_VEGA10 && reg == 1 && adev->last_mm_index == 0x5702C) {
  156. udelay(500);
  157. }
  158. }
  159. /**
  160. * amdgpu_mm_rdoorbell - read a doorbell dword
  161. *
  162. * @adev: amdgpu_device pointer
  163. * @index: doorbell index
  164. *
  165. * Returns the value in the doorbell aperture at the
  166. * requested doorbell index (CIK).
  167. */
  168. u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index)
  169. {
  170. if (index < adev->doorbell.num_doorbells) {
  171. return readl(adev->doorbell.ptr + index);
  172. } else {
  173. DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
  174. return 0;
  175. }
  176. }
  177. /**
  178. * amdgpu_mm_wdoorbell - write a doorbell dword
  179. *
  180. * @adev: amdgpu_device pointer
  181. * @index: doorbell index
  182. * @v: value to write
  183. *
  184. * Writes @v to the doorbell aperture at the
  185. * requested doorbell index (CIK).
  186. */
  187. void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v)
  188. {
  189. if (index < adev->doorbell.num_doorbells) {
  190. writel(v, adev->doorbell.ptr + index);
  191. } else {
  192. DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
  193. }
  194. }
  195. /**
  196. * amdgpu_mm_rdoorbell64 - read a doorbell Qword
  197. *
  198. * @adev: amdgpu_device pointer
  199. * @index: doorbell index
  200. *
  201. * Returns the value in the doorbell aperture at the
  202. * requested doorbell index (VEGA10+).
  203. */
  204. u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index)
  205. {
  206. if (index < adev->doorbell.num_doorbells) {
  207. return atomic64_read((atomic64_t *)(adev->doorbell.ptr + index));
  208. } else {
  209. DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
  210. return 0;
  211. }
  212. }
  213. /**
  214. * amdgpu_mm_wdoorbell64 - write a doorbell Qword
  215. *
  216. * @adev: amdgpu_device pointer
  217. * @index: doorbell index
  218. * @v: value to write
  219. *
  220. * Writes @v to the doorbell aperture at the
  221. * requested doorbell index (VEGA10+).
  222. */
  223. void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v)
  224. {
  225. if (index < adev->doorbell.num_doorbells) {
  226. atomic64_set((atomic64_t *)(adev->doorbell.ptr + index), v);
  227. } else {
  228. DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
  229. }
  230. }
  231. /**
  232. * amdgpu_invalid_rreg - dummy reg read function
  233. *
  234. * @adev: amdgpu device pointer
  235. * @reg: offset of register
  236. *
  237. * Dummy register read function. Used for register blocks
  238. * that certain asics don't have (all asics).
  239. * Returns the value in the register.
  240. */
  241. static uint32_t amdgpu_invalid_rreg(struct amdgpu_device *adev, uint32_t reg)
  242. {
  243. DRM_ERROR("Invalid callback to read register 0x%04X\n", reg);
  244. BUG();
  245. return 0;
  246. }
  247. /**
  248. * amdgpu_invalid_wreg - dummy reg write function
  249. *
  250. * @adev: amdgpu device pointer
  251. * @reg: offset of register
  252. * @v: value to write to the register
  253. *
  254. * Dummy register read function. Used for register blocks
  255. * that certain asics don't have (all asics).
  256. */
  257. static void amdgpu_invalid_wreg(struct amdgpu_device *adev, uint32_t reg, uint32_t v)
  258. {
  259. DRM_ERROR("Invalid callback to write register 0x%04X with 0x%08X\n",
  260. reg, v);
  261. BUG();
  262. }
  263. /**
  264. * amdgpu_block_invalid_rreg - dummy reg read function
  265. *
  266. * @adev: amdgpu device pointer
  267. * @block: offset of instance
  268. * @reg: offset of register
  269. *
  270. * Dummy register read function. Used for register blocks
  271. * that certain asics don't have (all asics).
  272. * Returns the value in the register.
  273. */
  274. static uint32_t amdgpu_block_invalid_rreg(struct amdgpu_device *adev,
  275. uint32_t block, uint32_t reg)
  276. {
  277. DRM_ERROR("Invalid callback to read register 0x%04X in block 0x%04X\n",
  278. reg, block);
  279. BUG();
  280. return 0;
  281. }
  282. /**
  283. * amdgpu_block_invalid_wreg - dummy reg write function
  284. *
  285. * @adev: amdgpu device pointer
  286. * @block: offset of instance
  287. * @reg: offset of register
  288. * @v: value to write to the register
  289. *
  290. * Dummy register read function. Used for register blocks
  291. * that certain asics don't have (all asics).
  292. */
  293. static void amdgpu_block_invalid_wreg(struct amdgpu_device *adev,
  294. uint32_t block,
  295. uint32_t reg, uint32_t v)
  296. {
  297. DRM_ERROR("Invalid block callback to write register 0x%04X in block 0x%04X with 0x%08X\n",
  298. reg, block, v);
  299. BUG();
  300. }
  301. static int amdgpu_device_vram_scratch_init(struct amdgpu_device *adev)
  302. {
  303. return amdgpu_bo_create_kernel(adev, AMDGPU_GPU_PAGE_SIZE,
  304. PAGE_SIZE, AMDGPU_GEM_DOMAIN_VRAM,
  305. &adev->vram_scratch.robj,
  306. &adev->vram_scratch.gpu_addr,
  307. (void **)&adev->vram_scratch.ptr);
  308. }
  309. static void amdgpu_device_vram_scratch_fini(struct amdgpu_device *adev)
  310. {
  311. amdgpu_bo_free_kernel(&adev->vram_scratch.robj, NULL, NULL);
  312. }
  313. /**
  314. * amdgpu_device_program_register_sequence - program an array of registers.
  315. *
  316. * @adev: amdgpu_device pointer
  317. * @registers: pointer to the register array
  318. * @array_size: size of the register array
  319. *
  320. * Programs an array or registers with and and or masks.
  321. * This is a helper for setting golden registers.
  322. */
  323. void amdgpu_device_program_register_sequence(struct amdgpu_device *adev,
  324. const u32 *registers,
  325. const u32 array_size)
  326. {
  327. u32 tmp, reg, and_mask, or_mask;
  328. int i;
  329. if (array_size % 3)
  330. return;
  331. for (i = 0; i < array_size; i +=3) {
  332. reg = registers[i + 0];
  333. and_mask = registers[i + 1];
  334. or_mask = registers[i + 2];
  335. if (and_mask == 0xffffffff) {
  336. tmp = or_mask;
  337. } else {
  338. tmp = RREG32(reg);
  339. tmp &= ~and_mask;
  340. tmp |= or_mask;
  341. }
  342. WREG32(reg, tmp);
  343. }
  344. }
  345. void amdgpu_device_pci_config_reset(struct amdgpu_device *adev)
  346. {
  347. pci_write_config_dword(adev->pdev, 0x7c, AMDGPU_ASIC_RESET_DATA);
  348. }
  349. /*
  350. * GPU doorbell aperture helpers function.
  351. */
  352. /**
  353. * amdgpu_device_doorbell_init - Init doorbell driver information.
  354. *
  355. * @adev: amdgpu_device pointer
  356. *
  357. * Init doorbell driver information (CIK)
  358. * Returns 0 on success, error on failure.
  359. */
  360. static int amdgpu_device_doorbell_init(struct amdgpu_device *adev)
  361. {
  362. /* No doorbell on SI hardware generation */
  363. if (adev->asic_type < CHIP_BONAIRE) {
  364. adev->doorbell.base = 0;
  365. adev->doorbell.size = 0;
  366. adev->doorbell.num_doorbells = 0;
  367. adev->doorbell.ptr = NULL;
  368. return 0;
  369. }
  370. if (pci_resource_flags(adev->pdev, 2) & IORESOURCE_UNSET)
  371. return -EINVAL;
  372. /* doorbell bar mapping */
  373. adev->doorbell.base = pci_resource_start(adev->pdev, 2);
  374. adev->doorbell.size = pci_resource_len(adev->pdev, 2);
  375. adev->doorbell.num_doorbells = min_t(u32, adev->doorbell.size / sizeof(u32),
  376. AMDGPU_DOORBELL_MAX_ASSIGNMENT+1);
  377. if (adev->doorbell.num_doorbells == 0)
  378. return -EINVAL;
  379. adev->doorbell.ptr = ioremap(adev->doorbell.base,
  380. adev->doorbell.num_doorbells *
  381. sizeof(u32));
  382. if (adev->doorbell.ptr == NULL)
  383. return -ENOMEM;
  384. return 0;
  385. }
  386. /**
  387. * amdgpu_device_doorbell_fini - Tear down doorbell driver information.
  388. *
  389. * @adev: amdgpu_device pointer
  390. *
  391. * Tear down doorbell driver information (CIK)
  392. */
  393. static void amdgpu_device_doorbell_fini(struct amdgpu_device *adev)
  394. {
  395. iounmap(adev->doorbell.ptr);
  396. adev->doorbell.ptr = NULL;
  397. }
  398. /*
  399. * amdgpu_device_wb_*()
  400. * Writeback is the method by which the GPU updates special pages in memory
  401. * with the status of certain GPU events (fences, ring pointers,etc.).
  402. */
  403. /**
  404. * amdgpu_device_wb_fini - Disable Writeback and free memory
  405. *
  406. * @adev: amdgpu_device pointer
  407. *
  408. * Disables Writeback and frees the Writeback memory (all asics).
  409. * Used at driver shutdown.
  410. */
  411. static void amdgpu_device_wb_fini(struct amdgpu_device *adev)
  412. {
  413. if (adev->wb.wb_obj) {
  414. amdgpu_bo_free_kernel(&adev->wb.wb_obj,
  415. &adev->wb.gpu_addr,
  416. (void **)&adev->wb.wb);
  417. adev->wb.wb_obj = NULL;
  418. }
  419. }
  420. /**
  421. * amdgpu_device_wb_init- Init Writeback driver info and allocate memory
  422. *
  423. * @adev: amdgpu_device pointer
  424. *
  425. * Initializes writeback and allocates writeback memory (all asics).
  426. * Used at driver startup.
  427. * Returns 0 on success or an -error on failure.
  428. */
  429. static int amdgpu_device_wb_init(struct amdgpu_device *adev)
  430. {
  431. int r;
  432. if (adev->wb.wb_obj == NULL) {
  433. /* AMDGPU_MAX_WB * sizeof(uint32_t) * 8 = AMDGPU_MAX_WB 256bit slots */
  434. r = amdgpu_bo_create_kernel(adev, AMDGPU_MAX_WB * sizeof(uint32_t) * 8,
  435. PAGE_SIZE, AMDGPU_GEM_DOMAIN_GTT,
  436. &adev->wb.wb_obj, &adev->wb.gpu_addr,
  437. (void **)&adev->wb.wb);
  438. if (r) {
  439. dev_warn(adev->dev, "(%d) create WB bo failed\n", r);
  440. return r;
  441. }
  442. adev->wb.num_wb = AMDGPU_MAX_WB;
  443. memset(&adev->wb.used, 0, sizeof(adev->wb.used));
  444. /* clear wb memory */
  445. memset((char *)adev->wb.wb, 0, AMDGPU_MAX_WB * sizeof(uint32_t) * 8);
  446. }
  447. return 0;
  448. }
  449. /**
  450. * amdgpu_device_wb_get - Allocate a wb entry
  451. *
  452. * @adev: amdgpu_device pointer
  453. * @wb: wb index
  454. *
  455. * Allocate a wb slot for use by the driver (all asics).
  456. * Returns 0 on success or -EINVAL on failure.
  457. */
  458. int amdgpu_device_wb_get(struct amdgpu_device *adev, u32 *wb)
  459. {
  460. unsigned long offset = find_first_zero_bit(adev->wb.used, adev->wb.num_wb);
  461. if (offset < adev->wb.num_wb) {
  462. __set_bit(offset, adev->wb.used);
  463. *wb = offset << 3; /* convert to dw offset */
  464. return 0;
  465. } else {
  466. return -EINVAL;
  467. }
  468. }
  469. /**
  470. * amdgpu_device_wb_free - Free a wb entry
  471. *
  472. * @adev: amdgpu_device pointer
  473. * @wb: wb index
  474. *
  475. * Free a wb slot allocated for use by the driver (all asics)
  476. */
  477. void amdgpu_device_wb_free(struct amdgpu_device *adev, u32 wb)
  478. {
  479. wb >>= 3;
  480. if (wb < adev->wb.num_wb)
  481. __clear_bit(wb, adev->wb.used);
  482. }
  483. /**
  484. * amdgpu_device_vram_location - try to find VRAM location
  485. * @adev: amdgpu device structure holding all necessary informations
  486. * @mc: memory controller structure holding memory informations
  487. * @base: base address at which to put VRAM
  488. *
  489. * Function will try to place VRAM at base address provided
  490. * as parameter.
  491. */
  492. void amdgpu_device_vram_location(struct amdgpu_device *adev,
  493. struct amdgpu_mc *mc, u64 base)
  494. {
  495. uint64_t limit = (uint64_t)amdgpu_vram_limit << 20;
  496. mc->vram_start = base;
  497. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  498. if (limit && limit < mc->real_vram_size)
  499. mc->real_vram_size = limit;
  500. dev_info(adev->dev, "VRAM: %lluM 0x%016llX - 0x%016llX (%lluM used)\n",
  501. mc->mc_vram_size >> 20, mc->vram_start,
  502. mc->vram_end, mc->real_vram_size >> 20);
  503. }
  504. /**
  505. * amdgpu_device_gart_location - try to find GTT location
  506. * @adev: amdgpu device structure holding all necessary informations
  507. * @mc: memory controller structure holding memory informations
  508. *
  509. * Function will place try to place GTT before or after VRAM.
  510. *
  511. * If GTT size is bigger than space left then we ajust GTT size.
  512. * Thus function will never fails.
  513. *
  514. * FIXME: when reducing GTT size align new size on power of 2.
  515. */
  516. void amdgpu_device_gart_location(struct amdgpu_device *adev,
  517. struct amdgpu_mc *mc)
  518. {
  519. u64 size_af, size_bf;
  520. size_af = adev->mc.mc_mask - mc->vram_end;
  521. size_bf = mc->vram_start;
  522. if (size_bf > size_af) {
  523. if (mc->gart_size > size_bf) {
  524. dev_warn(adev->dev, "limiting GTT\n");
  525. mc->gart_size = size_bf;
  526. }
  527. mc->gart_start = 0;
  528. } else {
  529. if (mc->gart_size > size_af) {
  530. dev_warn(adev->dev, "limiting GTT\n");
  531. mc->gart_size = size_af;
  532. }
  533. /* VCE doesn't like it when BOs cross a 4GB segment, so align
  534. * the GART base on a 4GB boundary as well.
  535. */
  536. mc->gart_start = ALIGN(mc->vram_end + 1, 0x100000000ULL);
  537. }
  538. mc->gart_end = mc->gart_start + mc->gart_size - 1;
  539. dev_info(adev->dev, "GTT: %lluM 0x%016llX - 0x%016llX\n",
  540. mc->gart_size >> 20, mc->gart_start, mc->gart_end);
  541. }
  542. /**
  543. * amdgpu_device_resize_fb_bar - try to resize FB BAR
  544. *
  545. * @adev: amdgpu_device pointer
  546. *
  547. * Try to resize FB BAR to make all VRAM CPU accessible. We try very hard not
  548. * to fail, but if any of the BARs is not accessible after the size we abort
  549. * driver loading by returning -ENODEV.
  550. */
  551. int amdgpu_device_resize_fb_bar(struct amdgpu_device *adev)
  552. {
  553. u64 space_needed = roundup_pow_of_two(adev->mc.real_vram_size);
  554. u32 rbar_size = order_base_2(((space_needed >> 20) | 1)) - 1;
  555. struct pci_bus *root;
  556. struct resource *res;
  557. unsigned i;
  558. u16 cmd;
  559. int r;
  560. /* Bypass for VF */
  561. if (amdgpu_sriov_vf(adev))
  562. return 0;
  563. /* Check if the root BUS has 64bit memory resources */
  564. root = adev->pdev->bus;
  565. while (root->parent)
  566. root = root->parent;
  567. pci_bus_for_each_resource(root, res, i) {
  568. if (res && res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
  569. res->start > 0x100000000ull)
  570. break;
  571. }
  572. /* Trying to resize is pointless without a root hub window above 4GB */
  573. if (!res)
  574. return 0;
  575. /* Disable memory decoding while we change the BAR addresses and size */
  576. pci_read_config_word(adev->pdev, PCI_COMMAND, &cmd);
  577. pci_write_config_word(adev->pdev, PCI_COMMAND,
  578. cmd & ~PCI_COMMAND_MEMORY);
  579. /* Free the VRAM and doorbell BAR, we most likely need to move both. */
  580. amdgpu_device_doorbell_fini(adev);
  581. if (adev->asic_type >= CHIP_BONAIRE)
  582. pci_release_resource(adev->pdev, 2);
  583. pci_release_resource(adev->pdev, 0);
  584. r = pci_resize_resource(adev->pdev, 0, rbar_size);
  585. if (r == -ENOSPC)
  586. DRM_INFO("Not enough PCI address space for a large BAR.");
  587. else if (r && r != -ENOTSUPP)
  588. DRM_ERROR("Problem resizing BAR0 (%d).", r);
  589. pci_assign_unassigned_bus_resources(adev->pdev->bus);
  590. /* When the doorbell or fb BAR isn't available we have no chance of
  591. * using the device.
  592. */
  593. r = amdgpu_device_doorbell_init(adev);
  594. if (r || (pci_resource_flags(adev->pdev, 0) & IORESOURCE_UNSET))
  595. return -ENODEV;
  596. pci_write_config_word(adev->pdev, PCI_COMMAND, cmd);
  597. return 0;
  598. }
  599. /*
  600. * GPU helpers function.
  601. */
  602. /**
  603. * amdgpu_device_need_post - check if the hw need post or not
  604. *
  605. * @adev: amdgpu_device pointer
  606. *
  607. * Check if the asic has been initialized (all asics) at driver startup
  608. * or post is needed if hw reset is performed.
  609. * Returns true if need or false if not.
  610. */
  611. bool amdgpu_device_need_post(struct amdgpu_device *adev)
  612. {
  613. uint32_t reg;
  614. if (amdgpu_sriov_vf(adev))
  615. return false;
  616. if (amdgpu_passthrough(adev)) {
  617. /* for FIJI: In whole GPU pass-through virtualization case, after VM reboot
  618. * some old smc fw still need driver do vPost otherwise gpu hang, while
  619. * those smc fw version above 22.15 doesn't have this flaw, so we force
  620. * vpost executed for smc version below 22.15
  621. */
  622. if (adev->asic_type == CHIP_FIJI) {
  623. int err;
  624. uint32_t fw_ver;
  625. err = request_firmware(&adev->pm.fw, "amdgpu/fiji_smc.bin", adev->dev);
  626. /* force vPost if error occured */
  627. if (err)
  628. return true;
  629. fw_ver = *((uint32_t *)adev->pm.fw->data + 69);
  630. if (fw_ver < 0x00160e00)
  631. return true;
  632. }
  633. }
  634. if (adev->has_hw_reset) {
  635. adev->has_hw_reset = false;
  636. return true;
  637. }
  638. /* bios scratch used on CIK+ */
  639. if (adev->asic_type >= CHIP_BONAIRE)
  640. return amdgpu_atombios_scratch_need_asic_init(adev);
  641. /* check MEM_SIZE for older asics */
  642. reg = amdgpu_asic_get_config_memsize(adev);
  643. if ((reg != 0) && (reg != 0xffffffff))
  644. return false;
  645. return true;
  646. }
  647. /* if we get transitioned to only one device, take VGA back */
  648. /**
  649. * amdgpu_device_vga_set_decode - enable/disable vga decode
  650. *
  651. * @cookie: amdgpu_device pointer
  652. * @state: enable/disable vga decode
  653. *
  654. * Enable/disable vga decode (all asics).
  655. * Returns VGA resource flags.
  656. */
  657. static unsigned int amdgpu_device_vga_set_decode(void *cookie, bool state)
  658. {
  659. struct amdgpu_device *adev = cookie;
  660. amdgpu_asic_set_vga_state(adev, state);
  661. if (state)
  662. return VGA_RSRC_LEGACY_IO | VGA_RSRC_LEGACY_MEM |
  663. VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  664. else
  665. return VGA_RSRC_NORMAL_IO | VGA_RSRC_NORMAL_MEM;
  666. }
  667. static void amdgpu_device_check_block_size(struct amdgpu_device *adev)
  668. {
  669. /* defines number of bits in page table versus page directory,
  670. * a page is 4KB so we have 12 bits offset, minimum 9 bits in the
  671. * page table and the remaining bits are in the page directory */
  672. if (amdgpu_vm_block_size == -1)
  673. return;
  674. if (amdgpu_vm_block_size < 9) {
  675. dev_warn(adev->dev, "VM page table size (%d) too small\n",
  676. amdgpu_vm_block_size);
  677. amdgpu_vm_block_size = -1;
  678. }
  679. }
  680. static void amdgpu_device_check_vm_size(struct amdgpu_device *adev)
  681. {
  682. /* no need to check the default value */
  683. if (amdgpu_vm_size == -1)
  684. return;
  685. if (amdgpu_vm_size < 1) {
  686. dev_warn(adev->dev, "VM size (%d) too small, min is 1GB\n",
  687. amdgpu_vm_size);
  688. amdgpu_vm_size = -1;
  689. }
  690. }
  691. /**
  692. * amdgpu_device_check_arguments - validate module params
  693. *
  694. * @adev: amdgpu_device pointer
  695. *
  696. * Validates certain module parameters and updates
  697. * the associated values used by the driver (all asics).
  698. */
  699. static void amdgpu_device_check_arguments(struct amdgpu_device *adev)
  700. {
  701. if (amdgpu_sched_jobs < 4) {
  702. dev_warn(adev->dev, "sched jobs (%d) must be at least 4\n",
  703. amdgpu_sched_jobs);
  704. amdgpu_sched_jobs = 4;
  705. } else if (!is_power_of_2(amdgpu_sched_jobs)){
  706. dev_warn(adev->dev, "sched jobs (%d) must be a power of 2\n",
  707. amdgpu_sched_jobs);
  708. amdgpu_sched_jobs = roundup_pow_of_two(amdgpu_sched_jobs);
  709. }
  710. if (amdgpu_gart_size != -1 && amdgpu_gart_size < 32) {
  711. /* gart size must be greater or equal to 32M */
  712. dev_warn(adev->dev, "gart size (%d) too small\n",
  713. amdgpu_gart_size);
  714. amdgpu_gart_size = -1;
  715. }
  716. if (amdgpu_gtt_size != -1 && amdgpu_gtt_size < 32) {
  717. /* gtt size must be greater or equal to 32M */
  718. dev_warn(adev->dev, "gtt size (%d) too small\n",
  719. amdgpu_gtt_size);
  720. amdgpu_gtt_size = -1;
  721. }
  722. /* valid range is between 4 and 9 inclusive */
  723. if (amdgpu_vm_fragment_size != -1 &&
  724. (amdgpu_vm_fragment_size > 9 || amdgpu_vm_fragment_size < 4)) {
  725. dev_warn(adev->dev, "valid range is between 4 and 9\n");
  726. amdgpu_vm_fragment_size = -1;
  727. }
  728. amdgpu_device_check_vm_size(adev);
  729. amdgpu_device_check_block_size(adev);
  730. if (amdgpu_vram_page_split != -1 && (amdgpu_vram_page_split < 16 ||
  731. !is_power_of_2(amdgpu_vram_page_split))) {
  732. dev_warn(adev->dev, "invalid VRAM page split (%d)\n",
  733. amdgpu_vram_page_split);
  734. amdgpu_vram_page_split = 1024;
  735. }
  736. if (amdgpu_lockup_timeout == 0) {
  737. dev_warn(adev->dev, "lockup_timeout msut be > 0, adjusting to 10000\n");
  738. amdgpu_lockup_timeout = 10000;
  739. }
  740. }
  741. /**
  742. * amdgpu_switcheroo_set_state - set switcheroo state
  743. *
  744. * @pdev: pci dev pointer
  745. * @state: vga_switcheroo state
  746. *
  747. * Callback for the switcheroo driver. Suspends or resumes the
  748. * the asics before or after it is powered up using ACPI methods.
  749. */
  750. static void amdgpu_switcheroo_set_state(struct pci_dev *pdev, enum vga_switcheroo_state state)
  751. {
  752. struct drm_device *dev = pci_get_drvdata(pdev);
  753. if (amdgpu_device_is_px(dev) && state == VGA_SWITCHEROO_OFF)
  754. return;
  755. if (state == VGA_SWITCHEROO_ON) {
  756. pr_info("amdgpu: switched on\n");
  757. /* don't suspend or resume card normally */
  758. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  759. amdgpu_device_resume(dev, true, true);
  760. dev->switch_power_state = DRM_SWITCH_POWER_ON;
  761. drm_kms_helper_poll_enable(dev);
  762. } else {
  763. pr_info("amdgpu: switched off\n");
  764. drm_kms_helper_poll_disable(dev);
  765. dev->switch_power_state = DRM_SWITCH_POWER_CHANGING;
  766. amdgpu_device_suspend(dev, true, true);
  767. dev->switch_power_state = DRM_SWITCH_POWER_OFF;
  768. }
  769. }
  770. /**
  771. * amdgpu_switcheroo_can_switch - see if switcheroo state can change
  772. *
  773. * @pdev: pci dev pointer
  774. *
  775. * Callback for the switcheroo driver. Check of the switcheroo
  776. * state can be changed.
  777. * Returns true if the state can be changed, false if not.
  778. */
  779. static bool amdgpu_switcheroo_can_switch(struct pci_dev *pdev)
  780. {
  781. struct drm_device *dev = pci_get_drvdata(pdev);
  782. /*
  783. * FIXME: open_count is protected by drm_global_mutex but that would lead to
  784. * locking inversion with the driver load path. And the access here is
  785. * completely racy anyway. So don't bother with locking for now.
  786. */
  787. return dev->open_count == 0;
  788. }
  789. static const struct vga_switcheroo_client_ops amdgpu_switcheroo_ops = {
  790. .set_gpu_state = amdgpu_switcheroo_set_state,
  791. .reprobe = NULL,
  792. .can_switch = amdgpu_switcheroo_can_switch,
  793. };
  794. int amdgpu_device_ip_set_clockgating_state(struct amdgpu_device *adev,
  795. enum amd_ip_block_type block_type,
  796. enum amd_clockgating_state state)
  797. {
  798. int i, r = 0;
  799. for (i = 0; i < adev->num_ip_blocks; i++) {
  800. if (!adev->ip_blocks[i].status.valid)
  801. continue;
  802. if (adev->ip_blocks[i].version->type != block_type)
  803. continue;
  804. if (!adev->ip_blocks[i].version->funcs->set_clockgating_state)
  805. continue;
  806. r = adev->ip_blocks[i].version->funcs->set_clockgating_state(
  807. (void *)adev, state);
  808. if (r)
  809. DRM_ERROR("set_clockgating_state of IP block <%s> failed %d\n",
  810. adev->ip_blocks[i].version->funcs->name, r);
  811. }
  812. return r;
  813. }
  814. int amdgpu_device_ip_set_powergating_state(struct amdgpu_device *adev,
  815. enum amd_ip_block_type block_type,
  816. enum amd_powergating_state state)
  817. {
  818. int i, r = 0;
  819. for (i = 0; i < adev->num_ip_blocks; i++) {
  820. if (!adev->ip_blocks[i].status.valid)
  821. continue;
  822. if (adev->ip_blocks[i].version->type != block_type)
  823. continue;
  824. if (!adev->ip_blocks[i].version->funcs->set_powergating_state)
  825. continue;
  826. r = adev->ip_blocks[i].version->funcs->set_powergating_state(
  827. (void *)adev, state);
  828. if (r)
  829. DRM_ERROR("set_powergating_state of IP block <%s> failed %d\n",
  830. adev->ip_blocks[i].version->funcs->name, r);
  831. }
  832. return r;
  833. }
  834. void amdgpu_device_ip_get_clockgating_state(struct amdgpu_device *adev,
  835. u32 *flags)
  836. {
  837. int i;
  838. for (i = 0; i < adev->num_ip_blocks; i++) {
  839. if (!adev->ip_blocks[i].status.valid)
  840. continue;
  841. if (adev->ip_blocks[i].version->funcs->get_clockgating_state)
  842. adev->ip_blocks[i].version->funcs->get_clockgating_state((void *)adev, flags);
  843. }
  844. }
  845. int amdgpu_device_ip_wait_for_idle(struct amdgpu_device *adev,
  846. enum amd_ip_block_type block_type)
  847. {
  848. int i, r;
  849. for (i = 0; i < adev->num_ip_blocks; i++) {
  850. if (!adev->ip_blocks[i].status.valid)
  851. continue;
  852. if (adev->ip_blocks[i].version->type == block_type) {
  853. r = adev->ip_blocks[i].version->funcs->wait_for_idle((void *)adev);
  854. if (r)
  855. return r;
  856. break;
  857. }
  858. }
  859. return 0;
  860. }
  861. bool amdgpu_device_ip_is_idle(struct amdgpu_device *adev,
  862. enum amd_ip_block_type block_type)
  863. {
  864. int i;
  865. for (i = 0; i < adev->num_ip_blocks; i++) {
  866. if (!adev->ip_blocks[i].status.valid)
  867. continue;
  868. if (adev->ip_blocks[i].version->type == block_type)
  869. return adev->ip_blocks[i].version->funcs->is_idle((void *)adev);
  870. }
  871. return true;
  872. }
  873. struct amdgpu_ip_block *
  874. amdgpu_device_ip_get_ip_block(struct amdgpu_device *adev,
  875. enum amd_ip_block_type type)
  876. {
  877. int i;
  878. for (i = 0; i < adev->num_ip_blocks; i++)
  879. if (adev->ip_blocks[i].version->type == type)
  880. return &adev->ip_blocks[i];
  881. return NULL;
  882. }
  883. /**
  884. * amdgpu_device_ip_block_version_cmp
  885. *
  886. * @adev: amdgpu_device pointer
  887. * @type: enum amd_ip_block_type
  888. * @major: major version
  889. * @minor: minor version
  890. *
  891. * return 0 if equal or greater
  892. * return 1 if smaller or the ip_block doesn't exist
  893. */
  894. int amdgpu_device_ip_block_version_cmp(struct amdgpu_device *adev,
  895. enum amd_ip_block_type type,
  896. u32 major, u32 minor)
  897. {
  898. struct amdgpu_ip_block *ip_block = amdgpu_device_ip_get_ip_block(adev, type);
  899. if (ip_block && ((ip_block->version->major > major) ||
  900. ((ip_block->version->major == major) &&
  901. (ip_block->version->minor >= minor))))
  902. return 0;
  903. return 1;
  904. }
  905. /**
  906. * amdgpu_device_ip_block_add
  907. *
  908. * @adev: amdgpu_device pointer
  909. * @ip_block_version: pointer to the IP to add
  910. *
  911. * Adds the IP block driver information to the collection of IPs
  912. * on the asic.
  913. */
  914. int amdgpu_device_ip_block_add(struct amdgpu_device *adev,
  915. const struct amdgpu_ip_block_version *ip_block_version)
  916. {
  917. if (!ip_block_version)
  918. return -EINVAL;
  919. DRM_DEBUG("add ip block number %d <%s>\n", adev->num_ip_blocks,
  920. ip_block_version->funcs->name);
  921. adev->ip_blocks[adev->num_ip_blocks++].version = ip_block_version;
  922. return 0;
  923. }
  924. static void amdgpu_device_enable_virtual_display(struct amdgpu_device *adev)
  925. {
  926. adev->enable_virtual_display = false;
  927. if (amdgpu_virtual_display) {
  928. struct drm_device *ddev = adev->ddev;
  929. const char *pci_address_name = pci_name(ddev->pdev);
  930. char *pciaddstr, *pciaddstr_tmp, *pciaddname_tmp, *pciaddname;
  931. pciaddstr = kstrdup(amdgpu_virtual_display, GFP_KERNEL);
  932. pciaddstr_tmp = pciaddstr;
  933. while ((pciaddname_tmp = strsep(&pciaddstr_tmp, ";"))) {
  934. pciaddname = strsep(&pciaddname_tmp, ",");
  935. if (!strcmp("all", pciaddname)
  936. || !strcmp(pci_address_name, pciaddname)) {
  937. long num_crtc;
  938. int res = -1;
  939. adev->enable_virtual_display = true;
  940. if (pciaddname_tmp)
  941. res = kstrtol(pciaddname_tmp, 10,
  942. &num_crtc);
  943. if (!res) {
  944. if (num_crtc < 1)
  945. num_crtc = 1;
  946. if (num_crtc > 6)
  947. num_crtc = 6;
  948. adev->mode_info.num_crtc = num_crtc;
  949. } else {
  950. adev->mode_info.num_crtc = 1;
  951. }
  952. break;
  953. }
  954. }
  955. DRM_INFO("virtual display string:%s, %s:virtual_display:%d, num_crtc:%d\n",
  956. amdgpu_virtual_display, pci_address_name,
  957. adev->enable_virtual_display, adev->mode_info.num_crtc);
  958. kfree(pciaddstr);
  959. }
  960. }
  961. static int amdgpu_device_parse_gpu_info_fw(struct amdgpu_device *adev)
  962. {
  963. const char *chip_name;
  964. char fw_name[30];
  965. int err;
  966. const struct gpu_info_firmware_header_v1_0 *hdr;
  967. adev->firmware.gpu_info_fw = NULL;
  968. switch (adev->asic_type) {
  969. case CHIP_TOPAZ:
  970. case CHIP_TONGA:
  971. case CHIP_FIJI:
  972. case CHIP_POLARIS11:
  973. case CHIP_POLARIS10:
  974. case CHIP_POLARIS12:
  975. case CHIP_CARRIZO:
  976. case CHIP_STONEY:
  977. #ifdef CONFIG_DRM_AMDGPU_SI
  978. case CHIP_VERDE:
  979. case CHIP_TAHITI:
  980. case CHIP_PITCAIRN:
  981. case CHIP_OLAND:
  982. case CHIP_HAINAN:
  983. #endif
  984. #ifdef CONFIG_DRM_AMDGPU_CIK
  985. case CHIP_BONAIRE:
  986. case CHIP_HAWAII:
  987. case CHIP_KAVERI:
  988. case CHIP_KABINI:
  989. case CHIP_MULLINS:
  990. #endif
  991. default:
  992. return 0;
  993. case CHIP_VEGA10:
  994. chip_name = "vega10";
  995. break;
  996. case CHIP_RAVEN:
  997. chip_name = "raven";
  998. break;
  999. }
  1000. snprintf(fw_name, sizeof(fw_name), "amdgpu/%s_gpu_info.bin", chip_name);
  1001. err = request_firmware(&adev->firmware.gpu_info_fw, fw_name, adev->dev);
  1002. if (err) {
  1003. dev_err(adev->dev,
  1004. "Failed to load gpu_info firmware \"%s\"\n",
  1005. fw_name);
  1006. goto out;
  1007. }
  1008. err = amdgpu_ucode_validate(adev->firmware.gpu_info_fw);
  1009. if (err) {
  1010. dev_err(adev->dev,
  1011. "Failed to validate gpu_info firmware \"%s\"\n",
  1012. fw_name);
  1013. goto out;
  1014. }
  1015. hdr = (const struct gpu_info_firmware_header_v1_0 *)adev->firmware.gpu_info_fw->data;
  1016. amdgpu_ucode_print_gpu_info_hdr(&hdr->header);
  1017. switch (hdr->version_major) {
  1018. case 1:
  1019. {
  1020. const struct gpu_info_firmware_v1_0 *gpu_info_fw =
  1021. (const struct gpu_info_firmware_v1_0 *)(adev->firmware.gpu_info_fw->data +
  1022. le32_to_cpu(hdr->header.ucode_array_offset_bytes));
  1023. adev->gfx.config.max_shader_engines = le32_to_cpu(gpu_info_fw->gc_num_se);
  1024. adev->gfx.config.max_cu_per_sh = le32_to_cpu(gpu_info_fw->gc_num_cu_per_sh);
  1025. adev->gfx.config.max_sh_per_se = le32_to_cpu(gpu_info_fw->gc_num_sh_per_se);
  1026. adev->gfx.config.max_backends_per_se = le32_to_cpu(gpu_info_fw->gc_num_rb_per_se);
  1027. adev->gfx.config.max_texture_channel_caches =
  1028. le32_to_cpu(gpu_info_fw->gc_num_tccs);
  1029. adev->gfx.config.max_gprs = le32_to_cpu(gpu_info_fw->gc_num_gprs);
  1030. adev->gfx.config.max_gs_threads = le32_to_cpu(gpu_info_fw->gc_num_max_gs_thds);
  1031. adev->gfx.config.gs_vgt_table_depth = le32_to_cpu(gpu_info_fw->gc_gs_table_depth);
  1032. adev->gfx.config.gs_prim_buffer_depth = le32_to_cpu(gpu_info_fw->gc_gsprim_buff_depth);
  1033. adev->gfx.config.double_offchip_lds_buf =
  1034. le32_to_cpu(gpu_info_fw->gc_double_offchip_lds_buffer);
  1035. adev->gfx.cu_info.wave_front_size = le32_to_cpu(gpu_info_fw->gc_wave_size);
  1036. adev->gfx.cu_info.max_waves_per_simd =
  1037. le32_to_cpu(gpu_info_fw->gc_max_waves_per_simd);
  1038. adev->gfx.cu_info.max_scratch_slots_per_cu =
  1039. le32_to_cpu(gpu_info_fw->gc_max_scratch_slots_per_cu);
  1040. adev->gfx.cu_info.lds_size = le32_to_cpu(gpu_info_fw->gc_lds_size);
  1041. break;
  1042. }
  1043. default:
  1044. dev_err(adev->dev,
  1045. "Unsupported gpu_info table %d\n", hdr->header.ucode_version);
  1046. err = -EINVAL;
  1047. goto out;
  1048. }
  1049. out:
  1050. return err;
  1051. }
  1052. static int amdgpu_device_ip_early_init(struct amdgpu_device *adev)
  1053. {
  1054. int i, r;
  1055. amdgpu_device_enable_virtual_display(adev);
  1056. switch (adev->asic_type) {
  1057. case CHIP_TOPAZ:
  1058. case CHIP_TONGA:
  1059. case CHIP_FIJI:
  1060. case CHIP_POLARIS11:
  1061. case CHIP_POLARIS10:
  1062. case CHIP_POLARIS12:
  1063. case CHIP_CARRIZO:
  1064. case CHIP_STONEY:
  1065. if (adev->asic_type == CHIP_CARRIZO || adev->asic_type == CHIP_STONEY)
  1066. adev->family = AMDGPU_FAMILY_CZ;
  1067. else
  1068. adev->family = AMDGPU_FAMILY_VI;
  1069. r = vi_set_ip_blocks(adev);
  1070. if (r)
  1071. return r;
  1072. break;
  1073. #ifdef CONFIG_DRM_AMDGPU_SI
  1074. case CHIP_VERDE:
  1075. case CHIP_TAHITI:
  1076. case CHIP_PITCAIRN:
  1077. case CHIP_OLAND:
  1078. case CHIP_HAINAN:
  1079. adev->family = AMDGPU_FAMILY_SI;
  1080. r = si_set_ip_blocks(adev);
  1081. if (r)
  1082. return r;
  1083. break;
  1084. #endif
  1085. #ifdef CONFIG_DRM_AMDGPU_CIK
  1086. case CHIP_BONAIRE:
  1087. case CHIP_HAWAII:
  1088. case CHIP_KAVERI:
  1089. case CHIP_KABINI:
  1090. case CHIP_MULLINS:
  1091. if ((adev->asic_type == CHIP_BONAIRE) || (adev->asic_type == CHIP_HAWAII))
  1092. adev->family = AMDGPU_FAMILY_CI;
  1093. else
  1094. adev->family = AMDGPU_FAMILY_KV;
  1095. r = cik_set_ip_blocks(adev);
  1096. if (r)
  1097. return r;
  1098. break;
  1099. #endif
  1100. case CHIP_VEGA10:
  1101. case CHIP_RAVEN:
  1102. if (adev->asic_type == CHIP_RAVEN)
  1103. adev->family = AMDGPU_FAMILY_RV;
  1104. else
  1105. adev->family = AMDGPU_FAMILY_AI;
  1106. r = soc15_set_ip_blocks(adev);
  1107. if (r)
  1108. return r;
  1109. break;
  1110. default:
  1111. /* FIXME: not supported yet */
  1112. return -EINVAL;
  1113. }
  1114. r = amdgpu_device_parse_gpu_info_fw(adev);
  1115. if (r)
  1116. return r;
  1117. amdgpu_amdkfd_device_probe(adev);
  1118. if (amdgpu_sriov_vf(adev)) {
  1119. r = amdgpu_virt_request_full_gpu(adev, true);
  1120. if (r)
  1121. return -EAGAIN;
  1122. }
  1123. for (i = 0; i < adev->num_ip_blocks; i++) {
  1124. if ((amdgpu_ip_block_mask & (1 << i)) == 0) {
  1125. DRM_ERROR("disabled ip block: %d <%s>\n",
  1126. i, adev->ip_blocks[i].version->funcs->name);
  1127. adev->ip_blocks[i].status.valid = false;
  1128. } else {
  1129. if (adev->ip_blocks[i].version->funcs->early_init) {
  1130. r = adev->ip_blocks[i].version->funcs->early_init((void *)adev);
  1131. if (r == -ENOENT) {
  1132. adev->ip_blocks[i].status.valid = false;
  1133. } else if (r) {
  1134. DRM_ERROR("early_init of IP block <%s> failed %d\n",
  1135. adev->ip_blocks[i].version->funcs->name, r);
  1136. return r;
  1137. } else {
  1138. adev->ip_blocks[i].status.valid = true;
  1139. }
  1140. } else {
  1141. adev->ip_blocks[i].status.valid = true;
  1142. }
  1143. }
  1144. }
  1145. adev->cg_flags &= amdgpu_cg_mask;
  1146. adev->pg_flags &= amdgpu_pg_mask;
  1147. return 0;
  1148. }
  1149. static int amdgpu_device_ip_init(struct amdgpu_device *adev)
  1150. {
  1151. int i, r;
  1152. for (i = 0; i < adev->num_ip_blocks; i++) {
  1153. if (!adev->ip_blocks[i].status.valid)
  1154. continue;
  1155. r = adev->ip_blocks[i].version->funcs->sw_init((void *)adev);
  1156. if (r) {
  1157. DRM_ERROR("sw_init of IP block <%s> failed %d\n",
  1158. adev->ip_blocks[i].version->funcs->name, r);
  1159. return r;
  1160. }
  1161. adev->ip_blocks[i].status.sw = true;
  1162. /* need to do gmc hw init early so we can allocate gpu mem */
  1163. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
  1164. r = amdgpu_device_vram_scratch_init(adev);
  1165. if (r) {
  1166. DRM_ERROR("amdgpu_vram_scratch_init failed %d\n", r);
  1167. return r;
  1168. }
  1169. r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev);
  1170. if (r) {
  1171. DRM_ERROR("hw_init %d failed %d\n", i, r);
  1172. return r;
  1173. }
  1174. r = amdgpu_device_wb_init(adev);
  1175. if (r) {
  1176. DRM_ERROR("amdgpu_device_wb_init failed %d\n", r);
  1177. return r;
  1178. }
  1179. adev->ip_blocks[i].status.hw = true;
  1180. /* right after GMC hw init, we create CSA */
  1181. if (amdgpu_sriov_vf(adev)) {
  1182. r = amdgpu_allocate_static_csa(adev);
  1183. if (r) {
  1184. DRM_ERROR("allocate CSA failed %d\n", r);
  1185. return r;
  1186. }
  1187. }
  1188. }
  1189. }
  1190. for (i = 0; i < adev->num_ip_blocks; i++) {
  1191. if (!adev->ip_blocks[i].status.sw)
  1192. continue;
  1193. /* gmc hw init is done early */
  1194. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC)
  1195. continue;
  1196. r = adev->ip_blocks[i].version->funcs->hw_init((void *)adev);
  1197. if (r) {
  1198. DRM_ERROR("hw_init of IP block <%s> failed %d\n",
  1199. adev->ip_blocks[i].version->funcs->name, r);
  1200. return r;
  1201. }
  1202. adev->ip_blocks[i].status.hw = true;
  1203. }
  1204. amdgpu_amdkfd_device_init(adev);
  1205. if (amdgpu_sriov_vf(adev))
  1206. amdgpu_virt_release_full_gpu(adev, true);
  1207. return 0;
  1208. }
  1209. static void amdgpu_device_fill_reset_magic(struct amdgpu_device *adev)
  1210. {
  1211. memcpy(adev->reset_magic, adev->gart.ptr, AMDGPU_RESET_MAGIC_NUM);
  1212. }
  1213. static bool amdgpu_device_check_vram_lost(struct amdgpu_device *adev)
  1214. {
  1215. return !!memcmp(adev->gart.ptr, adev->reset_magic,
  1216. AMDGPU_RESET_MAGIC_NUM);
  1217. }
  1218. static int amdgpu_device_ip_late_set_cg_state(struct amdgpu_device *adev)
  1219. {
  1220. int i = 0, r;
  1221. for (i = 0; i < adev->num_ip_blocks; i++) {
  1222. if (!adev->ip_blocks[i].status.valid)
  1223. continue;
  1224. /* skip CG for VCE/UVD, it's handled specially */
  1225. if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
  1226. adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) {
  1227. /* enable clockgating to save power */
  1228. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1229. AMD_CG_STATE_GATE);
  1230. if (r) {
  1231. DRM_ERROR("set_clockgating_state(gate) of IP block <%s> failed %d\n",
  1232. adev->ip_blocks[i].version->funcs->name, r);
  1233. return r;
  1234. }
  1235. }
  1236. }
  1237. return 0;
  1238. }
  1239. static int amdgpu_device_ip_late_init(struct amdgpu_device *adev)
  1240. {
  1241. int i = 0, r;
  1242. for (i = 0; i < adev->num_ip_blocks; i++) {
  1243. if (!adev->ip_blocks[i].status.valid)
  1244. continue;
  1245. if (adev->ip_blocks[i].version->funcs->late_init) {
  1246. r = adev->ip_blocks[i].version->funcs->late_init((void *)adev);
  1247. if (r) {
  1248. DRM_ERROR("late_init of IP block <%s> failed %d\n",
  1249. adev->ip_blocks[i].version->funcs->name, r);
  1250. return r;
  1251. }
  1252. adev->ip_blocks[i].status.late_initialized = true;
  1253. }
  1254. }
  1255. mod_delayed_work(system_wq, &adev->late_init_work,
  1256. msecs_to_jiffies(AMDGPU_RESUME_MS));
  1257. amdgpu_device_fill_reset_magic(adev);
  1258. return 0;
  1259. }
  1260. static int amdgpu_device_ip_fini(struct amdgpu_device *adev)
  1261. {
  1262. int i, r;
  1263. amdgpu_amdkfd_device_fini(adev);
  1264. /* need to disable SMC first */
  1265. for (i = 0; i < adev->num_ip_blocks; i++) {
  1266. if (!adev->ip_blocks[i].status.hw)
  1267. continue;
  1268. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) {
  1269. /* ungate blocks before hw fini so that we can shutdown the blocks safely */
  1270. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1271. AMD_CG_STATE_UNGATE);
  1272. if (r) {
  1273. DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
  1274. adev->ip_blocks[i].version->funcs->name, r);
  1275. return r;
  1276. }
  1277. r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev);
  1278. /* XXX handle errors */
  1279. if (r) {
  1280. DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
  1281. adev->ip_blocks[i].version->funcs->name, r);
  1282. }
  1283. adev->ip_blocks[i].status.hw = false;
  1284. break;
  1285. }
  1286. }
  1287. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1288. if (!adev->ip_blocks[i].status.hw)
  1289. continue;
  1290. if (adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_UVD &&
  1291. adev->ip_blocks[i].version->type != AMD_IP_BLOCK_TYPE_VCE) {
  1292. /* ungate blocks before hw fini so that we can shutdown the blocks safely */
  1293. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1294. AMD_CG_STATE_UNGATE);
  1295. if (r) {
  1296. DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
  1297. adev->ip_blocks[i].version->funcs->name, r);
  1298. return r;
  1299. }
  1300. }
  1301. r = adev->ip_blocks[i].version->funcs->hw_fini((void *)adev);
  1302. /* XXX handle errors */
  1303. if (r) {
  1304. DRM_DEBUG("hw_fini of IP block <%s> failed %d\n",
  1305. adev->ip_blocks[i].version->funcs->name, r);
  1306. }
  1307. adev->ip_blocks[i].status.hw = false;
  1308. }
  1309. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1310. if (!adev->ip_blocks[i].status.sw)
  1311. continue;
  1312. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) {
  1313. amdgpu_free_static_csa(adev);
  1314. amdgpu_device_wb_fini(adev);
  1315. amdgpu_device_vram_scratch_fini(adev);
  1316. }
  1317. r = adev->ip_blocks[i].version->funcs->sw_fini((void *)adev);
  1318. /* XXX handle errors */
  1319. if (r) {
  1320. DRM_DEBUG("sw_fini of IP block <%s> failed %d\n",
  1321. adev->ip_blocks[i].version->funcs->name, r);
  1322. }
  1323. adev->ip_blocks[i].status.sw = false;
  1324. adev->ip_blocks[i].status.valid = false;
  1325. }
  1326. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1327. if (!adev->ip_blocks[i].status.late_initialized)
  1328. continue;
  1329. if (adev->ip_blocks[i].version->funcs->late_fini)
  1330. adev->ip_blocks[i].version->funcs->late_fini((void *)adev);
  1331. adev->ip_blocks[i].status.late_initialized = false;
  1332. }
  1333. if (amdgpu_sriov_vf(adev))
  1334. if (amdgpu_virt_release_full_gpu(adev, false))
  1335. DRM_ERROR("failed to release exclusive mode on fini\n");
  1336. return 0;
  1337. }
  1338. static void amdgpu_device_ip_late_init_func_handler(struct work_struct *work)
  1339. {
  1340. struct amdgpu_device *adev =
  1341. container_of(work, struct amdgpu_device, late_init_work.work);
  1342. amdgpu_device_ip_late_set_cg_state(adev);
  1343. }
  1344. int amdgpu_device_ip_suspend(struct amdgpu_device *adev)
  1345. {
  1346. int i, r;
  1347. if (amdgpu_sriov_vf(adev))
  1348. amdgpu_virt_request_full_gpu(adev, false);
  1349. /* ungate SMC block first */
  1350. r = amdgpu_device_ip_set_clockgating_state(adev, AMD_IP_BLOCK_TYPE_SMC,
  1351. AMD_CG_STATE_UNGATE);
  1352. if (r) {
  1353. DRM_ERROR("set_clockgating_state(ungate) SMC failed %d\n", r);
  1354. }
  1355. for (i = adev->num_ip_blocks - 1; i >= 0; i--) {
  1356. if (!adev->ip_blocks[i].status.valid)
  1357. continue;
  1358. /* ungate blocks so that suspend can properly shut them down */
  1359. if (i != AMD_IP_BLOCK_TYPE_SMC) {
  1360. r = adev->ip_blocks[i].version->funcs->set_clockgating_state((void *)adev,
  1361. AMD_CG_STATE_UNGATE);
  1362. if (r) {
  1363. DRM_ERROR("set_clockgating_state(ungate) of IP block <%s> failed %d\n",
  1364. adev->ip_blocks[i].version->funcs->name, r);
  1365. }
  1366. }
  1367. /* XXX handle errors */
  1368. r = adev->ip_blocks[i].version->funcs->suspend(adev);
  1369. /* XXX handle errors */
  1370. if (r) {
  1371. DRM_ERROR("suspend of IP block <%s> failed %d\n",
  1372. adev->ip_blocks[i].version->funcs->name, r);
  1373. }
  1374. }
  1375. if (amdgpu_sriov_vf(adev))
  1376. amdgpu_virt_release_full_gpu(adev, false);
  1377. return 0;
  1378. }
  1379. static int amdgpu_device_ip_reinit_early_sriov(struct amdgpu_device *adev)
  1380. {
  1381. int i, r;
  1382. static enum amd_ip_block_type ip_order[] = {
  1383. AMD_IP_BLOCK_TYPE_GMC,
  1384. AMD_IP_BLOCK_TYPE_COMMON,
  1385. AMD_IP_BLOCK_TYPE_IH,
  1386. };
  1387. for (i = 0; i < ARRAY_SIZE(ip_order); i++) {
  1388. int j;
  1389. struct amdgpu_ip_block *block;
  1390. for (j = 0; j < adev->num_ip_blocks; j++) {
  1391. block = &adev->ip_blocks[j];
  1392. if (block->version->type != ip_order[i] ||
  1393. !block->status.valid)
  1394. continue;
  1395. r = block->version->funcs->hw_init(adev);
  1396. DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed");
  1397. }
  1398. }
  1399. return 0;
  1400. }
  1401. static int amdgpu_device_ip_reinit_late_sriov(struct amdgpu_device *adev)
  1402. {
  1403. int i, r;
  1404. static enum amd_ip_block_type ip_order[] = {
  1405. AMD_IP_BLOCK_TYPE_SMC,
  1406. AMD_IP_BLOCK_TYPE_PSP,
  1407. AMD_IP_BLOCK_TYPE_DCE,
  1408. AMD_IP_BLOCK_TYPE_GFX,
  1409. AMD_IP_BLOCK_TYPE_SDMA,
  1410. AMD_IP_BLOCK_TYPE_UVD,
  1411. AMD_IP_BLOCK_TYPE_VCE
  1412. };
  1413. for (i = 0; i < ARRAY_SIZE(ip_order); i++) {
  1414. int j;
  1415. struct amdgpu_ip_block *block;
  1416. for (j = 0; j < adev->num_ip_blocks; j++) {
  1417. block = &adev->ip_blocks[j];
  1418. if (block->version->type != ip_order[i] ||
  1419. !block->status.valid)
  1420. continue;
  1421. r = block->version->funcs->hw_init(adev);
  1422. DRM_INFO("RE-INIT: %s %s\n", block->version->funcs->name, r?"failed":"successed");
  1423. }
  1424. }
  1425. return 0;
  1426. }
  1427. static int amdgpu_device_ip_resume_phase1(struct amdgpu_device *adev)
  1428. {
  1429. int i, r;
  1430. for (i = 0; i < adev->num_ip_blocks; i++) {
  1431. if (!adev->ip_blocks[i].status.valid)
  1432. continue;
  1433. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
  1434. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
  1435. adev->ip_blocks[i].version->type ==
  1436. AMD_IP_BLOCK_TYPE_IH) {
  1437. r = adev->ip_blocks[i].version->funcs->resume(adev);
  1438. if (r) {
  1439. DRM_ERROR("resume of IP block <%s> failed %d\n",
  1440. adev->ip_blocks[i].version->funcs->name, r);
  1441. return r;
  1442. }
  1443. }
  1444. }
  1445. return 0;
  1446. }
  1447. static int amdgpu_device_ip_resume_phase2(struct amdgpu_device *adev)
  1448. {
  1449. int i, r;
  1450. for (i = 0; i < adev->num_ip_blocks; i++) {
  1451. if (!adev->ip_blocks[i].status.valid)
  1452. continue;
  1453. if (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_COMMON ||
  1454. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC ||
  1455. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_IH )
  1456. continue;
  1457. r = adev->ip_blocks[i].version->funcs->resume(adev);
  1458. if (r) {
  1459. DRM_ERROR("resume of IP block <%s> failed %d\n",
  1460. adev->ip_blocks[i].version->funcs->name, r);
  1461. return r;
  1462. }
  1463. }
  1464. return 0;
  1465. }
  1466. static int amdgpu_device_ip_resume(struct amdgpu_device *adev)
  1467. {
  1468. int r;
  1469. r = amdgpu_device_ip_resume_phase1(adev);
  1470. if (r)
  1471. return r;
  1472. r = amdgpu_device_ip_resume_phase2(adev);
  1473. return r;
  1474. }
  1475. static void amdgpu_device_detect_sriov_bios(struct amdgpu_device *adev)
  1476. {
  1477. if (amdgpu_sriov_vf(adev)) {
  1478. if (adev->is_atom_fw) {
  1479. if (amdgpu_atomfirmware_gpu_supports_virtualization(adev))
  1480. adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
  1481. } else {
  1482. if (amdgpu_atombios_has_gpu_virtualization_table(adev))
  1483. adev->virt.caps |= AMDGPU_SRIOV_CAPS_SRIOV_VBIOS;
  1484. }
  1485. if (!(adev->virt.caps & AMDGPU_SRIOV_CAPS_SRIOV_VBIOS))
  1486. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_NO_VBIOS, 0, 0);
  1487. }
  1488. }
  1489. bool amdgpu_device_asic_has_dc_support(enum amd_asic_type asic_type)
  1490. {
  1491. switch (asic_type) {
  1492. #if defined(CONFIG_DRM_AMD_DC)
  1493. case CHIP_BONAIRE:
  1494. case CHIP_HAWAII:
  1495. case CHIP_KAVERI:
  1496. case CHIP_CARRIZO:
  1497. case CHIP_STONEY:
  1498. case CHIP_POLARIS11:
  1499. case CHIP_POLARIS10:
  1500. case CHIP_POLARIS12:
  1501. case CHIP_TONGA:
  1502. case CHIP_FIJI:
  1503. #if defined(CONFIG_DRM_AMD_DC_PRE_VEGA)
  1504. return amdgpu_dc != 0;
  1505. #endif
  1506. case CHIP_KABINI:
  1507. case CHIP_MULLINS:
  1508. return amdgpu_dc > 0;
  1509. case CHIP_VEGA10:
  1510. #if defined(CONFIG_DRM_AMD_DC_DCN1_0)
  1511. case CHIP_RAVEN:
  1512. #endif
  1513. return amdgpu_dc != 0;
  1514. #endif
  1515. default:
  1516. return false;
  1517. }
  1518. }
  1519. /**
  1520. * amdgpu_device_has_dc_support - check if dc is supported
  1521. *
  1522. * @adev: amdgpu_device_pointer
  1523. *
  1524. * Returns true for supported, false for not supported
  1525. */
  1526. bool amdgpu_device_has_dc_support(struct amdgpu_device *adev)
  1527. {
  1528. if (amdgpu_sriov_vf(adev))
  1529. return false;
  1530. return amdgpu_device_asic_has_dc_support(adev->asic_type);
  1531. }
  1532. /**
  1533. * amdgpu_device_init - initialize the driver
  1534. *
  1535. * @adev: amdgpu_device pointer
  1536. * @pdev: drm dev pointer
  1537. * @pdev: pci dev pointer
  1538. * @flags: driver flags
  1539. *
  1540. * Initializes the driver info and hw (all asics).
  1541. * Returns 0 for success or an error on failure.
  1542. * Called at driver startup.
  1543. */
  1544. int amdgpu_device_init(struct amdgpu_device *adev,
  1545. struct drm_device *ddev,
  1546. struct pci_dev *pdev,
  1547. uint32_t flags)
  1548. {
  1549. int r, i;
  1550. bool runtime = false;
  1551. u32 max_MBps;
  1552. adev->shutdown = false;
  1553. adev->dev = &pdev->dev;
  1554. adev->ddev = ddev;
  1555. adev->pdev = pdev;
  1556. adev->flags = flags;
  1557. adev->asic_type = flags & AMD_ASIC_MASK;
  1558. adev->usec_timeout = AMDGPU_MAX_USEC_TIMEOUT;
  1559. adev->mc.gart_size = 512 * 1024 * 1024;
  1560. adev->accel_working = false;
  1561. adev->num_rings = 0;
  1562. adev->mman.buffer_funcs = NULL;
  1563. adev->mman.buffer_funcs_ring = NULL;
  1564. adev->vm_manager.vm_pte_funcs = NULL;
  1565. adev->vm_manager.vm_pte_num_rings = 0;
  1566. adev->gart.gart_funcs = NULL;
  1567. adev->fence_context = dma_fence_context_alloc(AMDGPU_MAX_RINGS);
  1568. bitmap_zero(adev->gfx.pipe_reserve_bitmap, AMDGPU_MAX_COMPUTE_QUEUES);
  1569. adev->smc_rreg = &amdgpu_invalid_rreg;
  1570. adev->smc_wreg = &amdgpu_invalid_wreg;
  1571. adev->pcie_rreg = &amdgpu_invalid_rreg;
  1572. adev->pcie_wreg = &amdgpu_invalid_wreg;
  1573. adev->pciep_rreg = &amdgpu_invalid_rreg;
  1574. adev->pciep_wreg = &amdgpu_invalid_wreg;
  1575. adev->uvd_ctx_rreg = &amdgpu_invalid_rreg;
  1576. adev->uvd_ctx_wreg = &amdgpu_invalid_wreg;
  1577. adev->didt_rreg = &amdgpu_invalid_rreg;
  1578. adev->didt_wreg = &amdgpu_invalid_wreg;
  1579. adev->gc_cac_rreg = &amdgpu_invalid_rreg;
  1580. adev->gc_cac_wreg = &amdgpu_invalid_wreg;
  1581. adev->audio_endpt_rreg = &amdgpu_block_invalid_rreg;
  1582. adev->audio_endpt_wreg = &amdgpu_block_invalid_wreg;
  1583. DRM_INFO("initializing kernel modesetting (%s 0x%04X:0x%04X 0x%04X:0x%04X 0x%02X).\n",
  1584. amdgpu_asic_name[adev->asic_type], pdev->vendor, pdev->device,
  1585. pdev->subsystem_vendor, pdev->subsystem_device, pdev->revision);
  1586. /* mutex initialization are all done here so we
  1587. * can recall function without having locking issues */
  1588. atomic_set(&adev->irq.ih.lock, 0);
  1589. mutex_init(&adev->firmware.mutex);
  1590. mutex_init(&adev->pm.mutex);
  1591. mutex_init(&adev->gfx.gpu_clock_mutex);
  1592. mutex_init(&adev->srbm_mutex);
  1593. mutex_init(&adev->gfx.pipe_reserve_mutex);
  1594. mutex_init(&adev->grbm_idx_mutex);
  1595. mutex_init(&adev->mn_lock);
  1596. mutex_init(&adev->virt.vf_errors.lock);
  1597. hash_init(adev->mn_hash);
  1598. mutex_init(&adev->lock_reset);
  1599. amdgpu_device_check_arguments(adev);
  1600. spin_lock_init(&adev->mmio_idx_lock);
  1601. spin_lock_init(&adev->smc_idx_lock);
  1602. spin_lock_init(&adev->pcie_idx_lock);
  1603. spin_lock_init(&adev->uvd_ctx_idx_lock);
  1604. spin_lock_init(&adev->didt_idx_lock);
  1605. spin_lock_init(&adev->gc_cac_idx_lock);
  1606. spin_lock_init(&adev->se_cac_idx_lock);
  1607. spin_lock_init(&adev->audio_endpt_idx_lock);
  1608. spin_lock_init(&adev->mm_stats.lock);
  1609. INIT_LIST_HEAD(&adev->shadow_list);
  1610. mutex_init(&adev->shadow_list_lock);
  1611. INIT_LIST_HEAD(&adev->ring_lru_list);
  1612. spin_lock_init(&adev->ring_lru_list_lock);
  1613. INIT_DELAYED_WORK(&adev->late_init_work,
  1614. amdgpu_device_ip_late_init_func_handler);
  1615. /* Registers mapping */
  1616. /* TODO: block userspace mapping of io register */
  1617. if (adev->asic_type >= CHIP_BONAIRE) {
  1618. adev->rmmio_base = pci_resource_start(adev->pdev, 5);
  1619. adev->rmmio_size = pci_resource_len(adev->pdev, 5);
  1620. } else {
  1621. adev->rmmio_base = pci_resource_start(adev->pdev, 2);
  1622. adev->rmmio_size = pci_resource_len(adev->pdev, 2);
  1623. }
  1624. adev->rmmio = ioremap(adev->rmmio_base, adev->rmmio_size);
  1625. if (adev->rmmio == NULL) {
  1626. return -ENOMEM;
  1627. }
  1628. DRM_INFO("register mmio base: 0x%08X\n", (uint32_t)adev->rmmio_base);
  1629. DRM_INFO("register mmio size: %u\n", (unsigned)adev->rmmio_size);
  1630. /* doorbell bar mapping */
  1631. amdgpu_device_doorbell_init(adev);
  1632. /* io port mapping */
  1633. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  1634. if (pci_resource_flags(adev->pdev, i) & IORESOURCE_IO) {
  1635. adev->rio_mem_size = pci_resource_len(adev->pdev, i);
  1636. adev->rio_mem = pci_iomap(adev->pdev, i, adev->rio_mem_size);
  1637. break;
  1638. }
  1639. }
  1640. if (adev->rio_mem == NULL)
  1641. DRM_INFO("PCI I/O BAR is not found.\n");
  1642. /* early init functions */
  1643. r = amdgpu_device_ip_early_init(adev);
  1644. if (r)
  1645. return r;
  1646. /* if we have > 1 VGA cards, then disable the amdgpu VGA resources */
  1647. /* this will fail for cards that aren't VGA class devices, just
  1648. * ignore it */
  1649. vga_client_register(adev->pdev, adev, NULL, amdgpu_device_vga_set_decode);
  1650. if (amdgpu_device_is_px(ddev))
  1651. runtime = true;
  1652. if (!pci_is_thunderbolt_attached(adev->pdev))
  1653. vga_switcheroo_register_client(adev->pdev,
  1654. &amdgpu_switcheroo_ops, runtime);
  1655. if (runtime)
  1656. vga_switcheroo_init_domain_pm_ops(adev->dev, &adev->vga_pm_domain);
  1657. /* Read BIOS */
  1658. if (!amdgpu_get_bios(adev)) {
  1659. r = -EINVAL;
  1660. goto failed;
  1661. }
  1662. r = amdgpu_atombios_init(adev);
  1663. if (r) {
  1664. dev_err(adev->dev, "amdgpu_atombios_init failed\n");
  1665. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_INIT_FAIL, 0, 0);
  1666. goto failed;
  1667. }
  1668. /* detect if we are with an SRIOV vbios */
  1669. amdgpu_device_detect_sriov_bios(adev);
  1670. /* Post card if necessary */
  1671. if (amdgpu_device_need_post(adev)) {
  1672. if (!adev->bios) {
  1673. dev_err(adev->dev, "no vBIOS found\n");
  1674. r = -EINVAL;
  1675. goto failed;
  1676. }
  1677. DRM_INFO("GPU posting now...\n");
  1678. r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
  1679. if (r) {
  1680. dev_err(adev->dev, "gpu post error!\n");
  1681. goto failed;
  1682. }
  1683. }
  1684. if (adev->is_atom_fw) {
  1685. /* Initialize clocks */
  1686. r = amdgpu_atomfirmware_get_clock_info(adev);
  1687. if (r) {
  1688. dev_err(adev->dev, "amdgpu_atomfirmware_get_clock_info failed\n");
  1689. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
  1690. goto failed;
  1691. }
  1692. } else {
  1693. /* Initialize clocks */
  1694. r = amdgpu_atombios_get_clock_info(adev);
  1695. if (r) {
  1696. dev_err(adev->dev, "amdgpu_atombios_get_clock_info failed\n");
  1697. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_ATOMBIOS_GET_CLOCK_FAIL, 0, 0);
  1698. goto failed;
  1699. }
  1700. /* init i2c buses */
  1701. if (!amdgpu_device_has_dc_support(adev))
  1702. amdgpu_atombios_i2c_init(adev);
  1703. }
  1704. /* Fence driver */
  1705. r = amdgpu_fence_driver_init(adev);
  1706. if (r) {
  1707. dev_err(adev->dev, "amdgpu_fence_driver_init failed\n");
  1708. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_FENCE_INIT_FAIL, 0, 0);
  1709. goto failed;
  1710. }
  1711. /* init the mode config */
  1712. drm_mode_config_init(adev->ddev);
  1713. r = amdgpu_device_ip_init(adev);
  1714. if (r) {
  1715. /* failed in exclusive mode due to timeout */
  1716. if (amdgpu_sriov_vf(adev) &&
  1717. !amdgpu_sriov_runtime(adev) &&
  1718. amdgpu_virt_mmio_blocked(adev) &&
  1719. !amdgpu_virt_wait_reset(adev)) {
  1720. dev_err(adev->dev, "VF exclusive mode timeout\n");
  1721. /* Don't send request since VF is inactive. */
  1722. adev->virt.caps &= ~AMDGPU_SRIOV_CAPS_RUNTIME;
  1723. adev->virt.ops = NULL;
  1724. r = -EAGAIN;
  1725. goto failed;
  1726. }
  1727. dev_err(adev->dev, "amdgpu_device_ip_init failed\n");
  1728. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_INIT_FAIL, 0, 0);
  1729. amdgpu_device_ip_fini(adev);
  1730. goto failed;
  1731. }
  1732. adev->accel_working = true;
  1733. amdgpu_vm_check_compute_bug(adev);
  1734. /* Initialize the buffer migration limit. */
  1735. if (amdgpu_moverate >= 0)
  1736. max_MBps = amdgpu_moverate;
  1737. else
  1738. max_MBps = 8; /* Allow 8 MB/s. */
  1739. /* Get a log2 for easy divisions. */
  1740. adev->mm_stats.log2_max_MBps = ilog2(max(1u, max_MBps));
  1741. r = amdgpu_ib_pool_init(adev);
  1742. if (r) {
  1743. dev_err(adev->dev, "IB initialization failed (%d).\n", r);
  1744. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_IB_INIT_FAIL, 0, r);
  1745. goto failed;
  1746. }
  1747. r = amdgpu_ib_ring_tests(adev);
  1748. if (r)
  1749. DRM_ERROR("ib ring test failed (%d).\n", r);
  1750. if (amdgpu_sriov_vf(adev))
  1751. amdgpu_virt_init_data_exchange(adev);
  1752. amdgpu_fbdev_init(adev);
  1753. r = amdgpu_pm_sysfs_init(adev);
  1754. if (r)
  1755. DRM_ERROR("registering pm debugfs failed (%d).\n", r);
  1756. r = amdgpu_debugfs_gem_init(adev);
  1757. if (r)
  1758. DRM_ERROR("registering gem debugfs failed (%d).\n", r);
  1759. r = amdgpu_debugfs_regs_init(adev);
  1760. if (r)
  1761. DRM_ERROR("registering register debugfs failed (%d).\n", r);
  1762. r = amdgpu_debugfs_firmware_init(adev);
  1763. if (r)
  1764. DRM_ERROR("registering firmware debugfs failed (%d).\n", r);
  1765. r = amdgpu_debugfs_init(adev);
  1766. if (r)
  1767. DRM_ERROR("Creating debugfs files failed (%d).\n", r);
  1768. if ((amdgpu_testing & 1)) {
  1769. if (adev->accel_working)
  1770. amdgpu_test_moves(adev);
  1771. else
  1772. DRM_INFO("amdgpu: acceleration disabled, skipping move tests\n");
  1773. }
  1774. if (amdgpu_benchmarking) {
  1775. if (adev->accel_working)
  1776. amdgpu_benchmark(adev, amdgpu_benchmarking);
  1777. else
  1778. DRM_INFO("amdgpu: acceleration disabled, skipping benchmarks\n");
  1779. }
  1780. /* enable clockgating, etc. after ib tests, etc. since some blocks require
  1781. * explicit gating rather than handling it automatically.
  1782. */
  1783. r = amdgpu_device_ip_late_init(adev);
  1784. if (r) {
  1785. dev_err(adev->dev, "amdgpu_device_ip_late_init failed\n");
  1786. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_AMDGPU_LATE_INIT_FAIL, 0, r);
  1787. goto failed;
  1788. }
  1789. return 0;
  1790. failed:
  1791. amdgpu_vf_error_trans_all(adev);
  1792. if (runtime)
  1793. vga_switcheroo_fini_domain_pm_ops(adev->dev);
  1794. return r;
  1795. }
  1796. /**
  1797. * amdgpu_device_fini - tear down the driver
  1798. *
  1799. * @adev: amdgpu_device pointer
  1800. *
  1801. * Tear down the driver info (all asics).
  1802. * Called at driver shutdown.
  1803. */
  1804. void amdgpu_device_fini(struct amdgpu_device *adev)
  1805. {
  1806. int r;
  1807. DRM_INFO("amdgpu: finishing device.\n");
  1808. adev->shutdown = true;
  1809. if (adev->mode_info.mode_config_initialized)
  1810. drm_crtc_force_disable_all(adev->ddev);
  1811. amdgpu_ib_pool_fini(adev);
  1812. amdgpu_fence_driver_fini(adev);
  1813. amdgpu_fbdev_fini(adev);
  1814. r = amdgpu_device_ip_fini(adev);
  1815. if (adev->firmware.gpu_info_fw) {
  1816. release_firmware(adev->firmware.gpu_info_fw);
  1817. adev->firmware.gpu_info_fw = NULL;
  1818. }
  1819. adev->accel_working = false;
  1820. cancel_delayed_work_sync(&adev->late_init_work);
  1821. /* free i2c buses */
  1822. if (!amdgpu_device_has_dc_support(adev))
  1823. amdgpu_i2c_fini(adev);
  1824. amdgpu_atombios_fini(adev);
  1825. kfree(adev->bios);
  1826. adev->bios = NULL;
  1827. if (!pci_is_thunderbolt_attached(adev->pdev))
  1828. vga_switcheroo_unregister_client(adev->pdev);
  1829. if (adev->flags & AMD_IS_PX)
  1830. vga_switcheroo_fini_domain_pm_ops(adev->dev);
  1831. vga_client_register(adev->pdev, NULL, NULL, NULL);
  1832. if (adev->rio_mem)
  1833. pci_iounmap(adev->pdev, adev->rio_mem);
  1834. adev->rio_mem = NULL;
  1835. iounmap(adev->rmmio);
  1836. adev->rmmio = NULL;
  1837. amdgpu_device_doorbell_fini(adev);
  1838. amdgpu_pm_sysfs_fini(adev);
  1839. amdgpu_debugfs_regs_cleanup(adev);
  1840. }
  1841. /*
  1842. * Suspend & resume.
  1843. */
  1844. /**
  1845. * amdgpu_device_suspend - initiate device suspend
  1846. *
  1847. * @pdev: drm dev pointer
  1848. * @state: suspend state
  1849. *
  1850. * Puts the hw in the suspend state (all asics).
  1851. * Returns 0 for success or an error on failure.
  1852. * Called at driver suspend.
  1853. */
  1854. int amdgpu_device_suspend(struct drm_device *dev, bool suspend, bool fbcon)
  1855. {
  1856. struct amdgpu_device *adev;
  1857. struct drm_crtc *crtc;
  1858. struct drm_connector *connector;
  1859. int r;
  1860. if (dev == NULL || dev->dev_private == NULL) {
  1861. return -ENODEV;
  1862. }
  1863. adev = dev->dev_private;
  1864. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1865. return 0;
  1866. drm_kms_helper_poll_disable(dev);
  1867. if (!amdgpu_device_has_dc_support(adev)) {
  1868. /* turn off display hw */
  1869. drm_modeset_lock_all(dev);
  1870. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1871. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_OFF);
  1872. }
  1873. drm_modeset_unlock_all(dev);
  1874. }
  1875. amdgpu_amdkfd_suspend(adev);
  1876. /* unpin the front buffers and cursors */
  1877. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1878. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1879. struct amdgpu_framebuffer *rfb = to_amdgpu_framebuffer(crtc->primary->fb);
  1880. struct amdgpu_bo *robj;
  1881. if (amdgpu_crtc->cursor_bo) {
  1882. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  1883. r = amdgpu_bo_reserve(aobj, true);
  1884. if (r == 0) {
  1885. amdgpu_bo_unpin(aobj);
  1886. amdgpu_bo_unreserve(aobj);
  1887. }
  1888. }
  1889. if (rfb == NULL || rfb->obj == NULL) {
  1890. continue;
  1891. }
  1892. robj = gem_to_amdgpu_bo(rfb->obj);
  1893. /* don't unpin kernel fb objects */
  1894. if (!amdgpu_fbdev_robj_is_fb(adev, robj)) {
  1895. r = amdgpu_bo_reserve(robj, true);
  1896. if (r == 0) {
  1897. amdgpu_bo_unpin(robj);
  1898. amdgpu_bo_unreserve(robj);
  1899. }
  1900. }
  1901. }
  1902. /* evict vram memory */
  1903. amdgpu_bo_evict_vram(adev);
  1904. amdgpu_fence_driver_suspend(adev);
  1905. r = amdgpu_device_ip_suspend(adev);
  1906. /* evict remaining vram memory
  1907. * This second call to evict vram is to evict the gart page table
  1908. * using the CPU.
  1909. */
  1910. amdgpu_bo_evict_vram(adev);
  1911. pci_save_state(dev->pdev);
  1912. if (suspend) {
  1913. /* Shut down the device */
  1914. pci_disable_device(dev->pdev);
  1915. pci_set_power_state(dev->pdev, PCI_D3hot);
  1916. } else {
  1917. r = amdgpu_asic_reset(adev);
  1918. if (r)
  1919. DRM_ERROR("amdgpu asic reset failed\n");
  1920. }
  1921. if (fbcon) {
  1922. console_lock();
  1923. amdgpu_fbdev_set_suspend(adev, 1);
  1924. console_unlock();
  1925. }
  1926. return 0;
  1927. }
  1928. /**
  1929. * amdgpu_device_resume - initiate device resume
  1930. *
  1931. * @pdev: drm dev pointer
  1932. *
  1933. * Bring the hw back to operating state (all asics).
  1934. * Returns 0 for success or an error on failure.
  1935. * Called at driver resume.
  1936. */
  1937. int amdgpu_device_resume(struct drm_device *dev, bool resume, bool fbcon)
  1938. {
  1939. struct drm_connector *connector;
  1940. struct amdgpu_device *adev = dev->dev_private;
  1941. struct drm_crtc *crtc;
  1942. int r = 0;
  1943. if (dev->switch_power_state == DRM_SWITCH_POWER_OFF)
  1944. return 0;
  1945. if (fbcon)
  1946. console_lock();
  1947. if (resume) {
  1948. pci_set_power_state(dev->pdev, PCI_D0);
  1949. pci_restore_state(dev->pdev);
  1950. r = pci_enable_device(dev->pdev);
  1951. if (r)
  1952. goto unlock;
  1953. }
  1954. /* post card */
  1955. if (amdgpu_device_need_post(adev)) {
  1956. r = amdgpu_atom_asic_init(adev->mode_info.atom_context);
  1957. if (r)
  1958. DRM_ERROR("amdgpu asic init failed\n");
  1959. }
  1960. r = amdgpu_device_ip_resume(adev);
  1961. if (r) {
  1962. DRM_ERROR("amdgpu_device_ip_resume failed (%d).\n", r);
  1963. goto unlock;
  1964. }
  1965. amdgpu_fence_driver_resume(adev);
  1966. if (resume) {
  1967. r = amdgpu_ib_ring_tests(adev);
  1968. if (r)
  1969. DRM_ERROR("ib ring test failed (%d).\n", r);
  1970. }
  1971. r = amdgpu_device_ip_late_init(adev);
  1972. if (r)
  1973. goto unlock;
  1974. /* pin cursors */
  1975. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1976. struct amdgpu_crtc *amdgpu_crtc = to_amdgpu_crtc(crtc);
  1977. if (amdgpu_crtc->cursor_bo) {
  1978. struct amdgpu_bo *aobj = gem_to_amdgpu_bo(amdgpu_crtc->cursor_bo);
  1979. r = amdgpu_bo_reserve(aobj, true);
  1980. if (r == 0) {
  1981. r = amdgpu_bo_pin(aobj,
  1982. AMDGPU_GEM_DOMAIN_VRAM,
  1983. &amdgpu_crtc->cursor_addr);
  1984. if (r != 0)
  1985. DRM_ERROR("Failed to pin cursor BO (%d)\n", r);
  1986. amdgpu_bo_unreserve(aobj);
  1987. }
  1988. }
  1989. }
  1990. r = amdgpu_amdkfd_resume(adev);
  1991. if (r)
  1992. return r;
  1993. /* blat the mode back in */
  1994. if (fbcon) {
  1995. if (!amdgpu_device_has_dc_support(adev)) {
  1996. /* pre DCE11 */
  1997. drm_helper_resume_force_mode(dev);
  1998. /* turn on display hw */
  1999. drm_modeset_lock_all(dev);
  2000. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  2001. drm_helper_connector_dpms(connector, DRM_MODE_DPMS_ON);
  2002. }
  2003. drm_modeset_unlock_all(dev);
  2004. }
  2005. }
  2006. drm_kms_helper_poll_enable(dev);
  2007. /*
  2008. * Most of the connector probing functions try to acquire runtime pm
  2009. * refs to ensure that the GPU is powered on when connector polling is
  2010. * performed. Since we're calling this from a runtime PM callback,
  2011. * trying to acquire rpm refs will cause us to deadlock.
  2012. *
  2013. * Since we're guaranteed to be holding the rpm lock, it's safe to
  2014. * temporarily disable the rpm helpers so this doesn't deadlock us.
  2015. */
  2016. #ifdef CONFIG_PM
  2017. dev->dev->power.disable_depth++;
  2018. #endif
  2019. if (!amdgpu_device_has_dc_support(adev))
  2020. drm_helper_hpd_irq_event(dev);
  2021. else
  2022. drm_kms_helper_hotplug_event(dev);
  2023. #ifdef CONFIG_PM
  2024. dev->dev->power.disable_depth--;
  2025. #endif
  2026. if (fbcon)
  2027. amdgpu_fbdev_set_suspend(adev, 0);
  2028. unlock:
  2029. if (fbcon)
  2030. console_unlock();
  2031. return r;
  2032. }
  2033. static bool amdgpu_device_ip_check_soft_reset(struct amdgpu_device *adev)
  2034. {
  2035. int i;
  2036. bool asic_hang = false;
  2037. if (amdgpu_sriov_vf(adev))
  2038. return true;
  2039. for (i = 0; i < adev->num_ip_blocks; i++) {
  2040. if (!adev->ip_blocks[i].status.valid)
  2041. continue;
  2042. if (adev->ip_blocks[i].version->funcs->check_soft_reset)
  2043. adev->ip_blocks[i].status.hang =
  2044. adev->ip_blocks[i].version->funcs->check_soft_reset(adev);
  2045. if (adev->ip_blocks[i].status.hang) {
  2046. DRM_INFO("IP block:%s is hung!\n", adev->ip_blocks[i].version->funcs->name);
  2047. asic_hang = true;
  2048. }
  2049. }
  2050. return asic_hang;
  2051. }
  2052. static int amdgpu_device_ip_pre_soft_reset(struct amdgpu_device *adev)
  2053. {
  2054. int i, r = 0;
  2055. for (i = 0; i < adev->num_ip_blocks; i++) {
  2056. if (!adev->ip_blocks[i].status.valid)
  2057. continue;
  2058. if (adev->ip_blocks[i].status.hang &&
  2059. adev->ip_blocks[i].version->funcs->pre_soft_reset) {
  2060. r = adev->ip_blocks[i].version->funcs->pre_soft_reset(adev);
  2061. if (r)
  2062. return r;
  2063. }
  2064. }
  2065. return 0;
  2066. }
  2067. static bool amdgpu_device_ip_need_full_reset(struct amdgpu_device *adev)
  2068. {
  2069. int i;
  2070. for (i = 0; i < adev->num_ip_blocks; i++) {
  2071. if (!adev->ip_blocks[i].status.valid)
  2072. continue;
  2073. if ((adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_GMC) ||
  2074. (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_SMC) ||
  2075. (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_ACP) ||
  2076. (adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_DCE) ||
  2077. adev->ip_blocks[i].version->type == AMD_IP_BLOCK_TYPE_PSP) {
  2078. if (adev->ip_blocks[i].status.hang) {
  2079. DRM_INFO("Some block need full reset!\n");
  2080. return true;
  2081. }
  2082. }
  2083. }
  2084. return false;
  2085. }
  2086. static int amdgpu_device_ip_soft_reset(struct amdgpu_device *adev)
  2087. {
  2088. int i, r = 0;
  2089. for (i = 0; i < adev->num_ip_blocks; i++) {
  2090. if (!adev->ip_blocks[i].status.valid)
  2091. continue;
  2092. if (adev->ip_blocks[i].status.hang &&
  2093. adev->ip_blocks[i].version->funcs->soft_reset) {
  2094. r = adev->ip_blocks[i].version->funcs->soft_reset(adev);
  2095. if (r)
  2096. return r;
  2097. }
  2098. }
  2099. return 0;
  2100. }
  2101. static int amdgpu_device_ip_post_soft_reset(struct amdgpu_device *adev)
  2102. {
  2103. int i, r = 0;
  2104. for (i = 0; i < adev->num_ip_blocks; i++) {
  2105. if (!adev->ip_blocks[i].status.valid)
  2106. continue;
  2107. if (adev->ip_blocks[i].status.hang &&
  2108. adev->ip_blocks[i].version->funcs->post_soft_reset)
  2109. r = adev->ip_blocks[i].version->funcs->post_soft_reset(adev);
  2110. if (r)
  2111. return r;
  2112. }
  2113. return 0;
  2114. }
  2115. static int amdgpu_device_recover_vram_from_shadow(struct amdgpu_device *adev,
  2116. struct amdgpu_ring *ring,
  2117. struct amdgpu_bo *bo,
  2118. struct dma_fence **fence)
  2119. {
  2120. uint32_t domain;
  2121. int r;
  2122. if (!bo->shadow)
  2123. return 0;
  2124. r = amdgpu_bo_reserve(bo, true);
  2125. if (r)
  2126. return r;
  2127. domain = amdgpu_mem_type_to_domain(bo->tbo.mem.mem_type);
  2128. /* if bo has been evicted, then no need to recover */
  2129. if (domain == AMDGPU_GEM_DOMAIN_VRAM) {
  2130. r = amdgpu_bo_validate(bo->shadow);
  2131. if (r) {
  2132. DRM_ERROR("bo validate failed!\n");
  2133. goto err;
  2134. }
  2135. r = amdgpu_bo_restore_from_shadow(adev, ring, bo,
  2136. NULL, fence, true);
  2137. if (r) {
  2138. DRM_ERROR("recover page table failed!\n");
  2139. goto err;
  2140. }
  2141. }
  2142. err:
  2143. amdgpu_bo_unreserve(bo);
  2144. return r;
  2145. }
  2146. /*
  2147. * amdgpu_device_reset - reset ASIC/GPU for bare-metal or passthrough
  2148. *
  2149. * @adev: amdgpu device pointer
  2150. * @reset_flags: output param tells caller the reset result
  2151. *
  2152. * attempt to do soft-reset or full-reset and reinitialize Asic
  2153. * return 0 means successed otherwise failed
  2154. */
  2155. static int amdgpu_device_reset(struct amdgpu_device *adev,
  2156. uint64_t* reset_flags)
  2157. {
  2158. bool need_full_reset, vram_lost = 0;
  2159. int r;
  2160. need_full_reset = amdgpu_device_ip_need_full_reset(adev);
  2161. if (!need_full_reset) {
  2162. amdgpu_device_ip_pre_soft_reset(adev);
  2163. r = amdgpu_device_ip_soft_reset(adev);
  2164. amdgpu_device_ip_post_soft_reset(adev);
  2165. if (r || amdgpu_device_ip_check_soft_reset(adev)) {
  2166. DRM_INFO("soft reset failed, will fallback to full reset!\n");
  2167. need_full_reset = true;
  2168. }
  2169. }
  2170. if (need_full_reset) {
  2171. r = amdgpu_device_ip_suspend(adev);
  2172. retry:
  2173. r = amdgpu_asic_reset(adev);
  2174. /* post card */
  2175. amdgpu_atom_asic_init(adev->mode_info.atom_context);
  2176. if (!r) {
  2177. dev_info(adev->dev, "GPU reset succeeded, trying to resume\n");
  2178. r = amdgpu_device_ip_resume_phase1(adev);
  2179. if (r)
  2180. goto out;
  2181. vram_lost = amdgpu_device_check_vram_lost(adev);
  2182. if (vram_lost) {
  2183. DRM_ERROR("VRAM is lost!\n");
  2184. atomic_inc(&adev->vram_lost_counter);
  2185. }
  2186. r = amdgpu_gtt_mgr_recover(
  2187. &adev->mman.bdev.man[TTM_PL_TT]);
  2188. if (r)
  2189. goto out;
  2190. r = amdgpu_device_ip_resume_phase2(adev);
  2191. if (r)
  2192. goto out;
  2193. if (vram_lost)
  2194. amdgpu_device_fill_reset_magic(adev);
  2195. }
  2196. }
  2197. out:
  2198. if (!r) {
  2199. amdgpu_irq_gpu_reset_resume_helper(adev);
  2200. r = amdgpu_ib_ring_tests(adev);
  2201. if (r) {
  2202. dev_err(adev->dev, "ib ring test failed (%d).\n", r);
  2203. r = amdgpu_device_ip_suspend(adev);
  2204. need_full_reset = true;
  2205. goto retry;
  2206. }
  2207. }
  2208. if (reset_flags) {
  2209. if (vram_lost)
  2210. (*reset_flags) |= AMDGPU_RESET_INFO_VRAM_LOST;
  2211. if (need_full_reset)
  2212. (*reset_flags) |= AMDGPU_RESET_INFO_FULLRESET;
  2213. }
  2214. return r;
  2215. }
  2216. /*
  2217. * amdgpu_device_reset_sriov - reset ASIC for SR-IOV vf
  2218. *
  2219. * @adev: amdgpu device pointer
  2220. * @reset_flags: output param tells caller the reset result
  2221. *
  2222. * do VF FLR and reinitialize Asic
  2223. * return 0 means successed otherwise failed
  2224. */
  2225. static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
  2226. uint64_t *reset_flags,
  2227. bool from_hypervisor)
  2228. {
  2229. int r;
  2230. if (from_hypervisor)
  2231. r = amdgpu_virt_request_full_gpu(adev, true);
  2232. else
  2233. r = amdgpu_virt_reset_gpu(adev);
  2234. if (r)
  2235. return r;
  2236. /* Resume IP prior to SMC */
  2237. r = amdgpu_device_ip_reinit_early_sriov(adev);
  2238. if (r)
  2239. goto error;
  2240. /* we need recover gart prior to run SMC/CP/SDMA resume */
  2241. amdgpu_gtt_mgr_recover(&adev->mman.bdev.man[TTM_PL_TT]);
  2242. /* now we are okay to resume SMC/CP/SDMA */
  2243. r = amdgpu_device_ip_reinit_late_sriov(adev);
  2244. if (r)
  2245. goto error;
  2246. amdgpu_irq_gpu_reset_resume_helper(adev);
  2247. r = amdgpu_ib_ring_tests(adev);
  2248. if (r)
  2249. dev_err(adev->dev, "[GPU_RESET] ib ring test failed (%d).\n", r);
  2250. error:
  2251. /* release full control of GPU after ib test */
  2252. amdgpu_virt_release_full_gpu(adev, true);
  2253. if (reset_flags) {
  2254. if (adev->virt.gim_feature & AMDGIM_FEATURE_GIM_FLR_VRAMLOST) {
  2255. (*reset_flags) |= AMDGPU_RESET_INFO_VRAM_LOST;
  2256. atomic_inc(&adev->vram_lost_counter);
  2257. }
  2258. /* VF FLR or hotlink reset is always full-reset */
  2259. (*reset_flags) |= AMDGPU_RESET_INFO_FULLRESET;
  2260. }
  2261. return r;
  2262. }
  2263. /**
  2264. * amdgpu_device_gpu_recover - reset the asic and recover scheduler
  2265. *
  2266. * @adev: amdgpu device pointer
  2267. * @job: which job trigger hang
  2268. * @force forces reset regardless of amdgpu_gpu_recovery
  2269. *
  2270. * Attempt to reset the GPU if it has hung (all asics).
  2271. * Returns 0 for success or an error on failure.
  2272. */
  2273. int amdgpu_device_gpu_recover(struct amdgpu_device *adev,
  2274. struct amdgpu_job *job, bool force)
  2275. {
  2276. struct drm_atomic_state *state = NULL;
  2277. uint64_t reset_flags = 0;
  2278. int i, r, resched;
  2279. if (!force && !amdgpu_device_ip_check_soft_reset(adev)) {
  2280. DRM_INFO("No hardware hang detected. Did some blocks stall?\n");
  2281. return 0;
  2282. }
  2283. if (!force && (amdgpu_gpu_recovery == 0 ||
  2284. (amdgpu_gpu_recovery == -1 && !amdgpu_sriov_vf(adev)))) {
  2285. DRM_INFO("GPU recovery disabled.\n");
  2286. return 0;
  2287. }
  2288. dev_info(adev->dev, "GPU reset begin!\n");
  2289. mutex_lock(&adev->lock_reset);
  2290. atomic_inc(&adev->gpu_reset_counter);
  2291. adev->in_gpu_reset = 1;
  2292. /* block TTM */
  2293. resched = ttm_bo_lock_delayed_workqueue(&adev->mman.bdev);
  2294. /* store modesetting */
  2295. if (amdgpu_device_has_dc_support(adev))
  2296. state = drm_atomic_helper_suspend(adev->ddev);
  2297. /* block scheduler */
  2298. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  2299. struct amdgpu_ring *ring = adev->rings[i];
  2300. if (!ring || !ring->sched.thread)
  2301. continue;
  2302. /* only focus on the ring hit timeout if &job not NULL */
  2303. if (job && job->ring->idx != i)
  2304. continue;
  2305. kthread_park(ring->sched.thread);
  2306. drm_sched_hw_job_reset(&ring->sched, &job->base);
  2307. /* after all hw jobs are reset, hw fence is meaningless, so force_completion */
  2308. amdgpu_fence_driver_force_completion(ring);
  2309. }
  2310. if (amdgpu_sriov_vf(adev))
  2311. r = amdgpu_device_reset_sriov(adev, &reset_flags, job ? false : true);
  2312. else
  2313. r = amdgpu_device_reset(adev, &reset_flags);
  2314. if (!r) {
  2315. if (((reset_flags & AMDGPU_RESET_INFO_FULLRESET) && !(adev->flags & AMD_IS_APU)) ||
  2316. (reset_flags & AMDGPU_RESET_INFO_VRAM_LOST)) {
  2317. struct amdgpu_ring *ring = adev->mman.buffer_funcs_ring;
  2318. struct amdgpu_bo *bo, *tmp;
  2319. struct dma_fence *fence = NULL, *next = NULL;
  2320. DRM_INFO("recover vram bo from shadow\n");
  2321. mutex_lock(&adev->shadow_list_lock);
  2322. list_for_each_entry_safe(bo, tmp, &adev->shadow_list, shadow_list) {
  2323. next = NULL;
  2324. amdgpu_device_recover_vram_from_shadow(adev, ring, bo, &next);
  2325. if (fence) {
  2326. r = dma_fence_wait(fence, false);
  2327. if (r) {
  2328. WARN(r, "recovery from shadow isn't completed\n");
  2329. break;
  2330. }
  2331. }
  2332. dma_fence_put(fence);
  2333. fence = next;
  2334. }
  2335. mutex_unlock(&adev->shadow_list_lock);
  2336. if (fence) {
  2337. r = dma_fence_wait(fence, false);
  2338. if (r)
  2339. WARN(r, "recovery from shadow isn't completed\n");
  2340. }
  2341. dma_fence_put(fence);
  2342. }
  2343. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  2344. struct amdgpu_ring *ring = adev->rings[i];
  2345. if (!ring || !ring->sched.thread)
  2346. continue;
  2347. /* only focus on the ring hit timeout if &job not NULL */
  2348. if (job && job->ring->idx != i)
  2349. continue;
  2350. drm_sched_job_recovery(&ring->sched);
  2351. kthread_unpark(ring->sched.thread);
  2352. }
  2353. } else {
  2354. for (i = 0; i < AMDGPU_MAX_RINGS; ++i) {
  2355. struct amdgpu_ring *ring = adev->rings[i];
  2356. if (!ring || !ring->sched.thread)
  2357. continue;
  2358. /* only focus on the ring hit timeout if &job not NULL */
  2359. if (job && job->ring->idx != i)
  2360. continue;
  2361. kthread_unpark(adev->rings[i]->sched.thread);
  2362. }
  2363. }
  2364. if (amdgpu_device_has_dc_support(adev)) {
  2365. if (drm_atomic_helper_resume(adev->ddev, state))
  2366. dev_info(adev->dev, "drm resume failed:%d\n", r);
  2367. } else {
  2368. drm_helper_resume_force_mode(adev->ddev);
  2369. }
  2370. ttm_bo_unlock_delayed_workqueue(&adev->mman.bdev, resched);
  2371. if (r) {
  2372. /* bad news, how to tell it to userspace ? */
  2373. dev_info(adev->dev, "GPU reset(%d) failed\n", atomic_read(&adev->gpu_reset_counter));
  2374. amdgpu_vf_error_put(adev, AMDGIM_ERROR_VF_GPU_RESET_FAIL, 0, r);
  2375. } else {
  2376. dev_info(adev->dev, "GPU reset(%d) successed!\n",atomic_read(&adev->gpu_reset_counter));
  2377. }
  2378. amdgpu_vf_error_trans_all(adev);
  2379. adev->in_gpu_reset = 0;
  2380. mutex_unlock(&adev->lock_reset);
  2381. return r;
  2382. }
  2383. void amdgpu_device_get_pcie_info(struct amdgpu_device *adev)
  2384. {
  2385. u32 mask;
  2386. int ret;
  2387. if (amdgpu_pcie_gen_cap)
  2388. adev->pm.pcie_gen_mask = amdgpu_pcie_gen_cap;
  2389. if (amdgpu_pcie_lane_cap)
  2390. adev->pm.pcie_mlw_mask = amdgpu_pcie_lane_cap;
  2391. /* covers APUs as well */
  2392. if (pci_is_root_bus(adev->pdev->bus)) {
  2393. if (adev->pm.pcie_gen_mask == 0)
  2394. adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
  2395. if (adev->pm.pcie_mlw_mask == 0)
  2396. adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
  2397. return;
  2398. }
  2399. if (adev->pm.pcie_gen_mask == 0) {
  2400. ret = drm_pcie_get_speed_cap_mask(adev->ddev, &mask);
  2401. if (!ret) {
  2402. adev->pm.pcie_gen_mask = (CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN1 |
  2403. CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN2 |
  2404. CAIL_ASIC_PCIE_LINK_SPEED_SUPPORT_GEN3);
  2405. if (mask & DRM_PCIE_SPEED_25)
  2406. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN1;
  2407. if (mask & DRM_PCIE_SPEED_50)
  2408. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2;
  2409. if (mask & DRM_PCIE_SPEED_80)
  2410. adev->pm.pcie_gen_mask |= CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3;
  2411. } else {
  2412. adev->pm.pcie_gen_mask = AMDGPU_DEFAULT_PCIE_GEN_MASK;
  2413. }
  2414. }
  2415. if (adev->pm.pcie_mlw_mask == 0) {
  2416. ret = drm_pcie_get_max_link_width(adev->ddev, &mask);
  2417. if (!ret) {
  2418. switch (mask) {
  2419. case 32:
  2420. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X32 |
  2421. CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
  2422. CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  2423. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2424. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2425. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2426. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2427. break;
  2428. case 16:
  2429. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X16 |
  2430. CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  2431. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2432. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2433. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2434. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2435. break;
  2436. case 12:
  2437. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X12 |
  2438. CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2439. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2440. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2441. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2442. break;
  2443. case 8:
  2444. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X8 |
  2445. CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2446. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2447. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2448. break;
  2449. case 4:
  2450. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X4 |
  2451. CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2452. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2453. break;
  2454. case 2:
  2455. adev->pm.pcie_mlw_mask = (CAIL_PCIE_LINK_WIDTH_SUPPORT_X2 |
  2456. CAIL_PCIE_LINK_WIDTH_SUPPORT_X1);
  2457. break;
  2458. case 1:
  2459. adev->pm.pcie_mlw_mask = CAIL_PCIE_LINK_WIDTH_SUPPORT_X1;
  2460. break;
  2461. default:
  2462. break;
  2463. }
  2464. } else {
  2465. adev->pm.pcie_mlw_mask = AMDGPU_DEFAULT_PCIE_MLW_MASK;
  2466. }
  2467. }
  2468. }