amdgpu_device.c 103 KB

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