cik.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256
  1. /*
  2. * Copyright 2012 Advanced Micro Devices, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Alex Deucher
  23. */
  24. #include <linux/firmware.h>
  25. #include <linux/slab.h>
  26. #include <linux/module.h>
  27. #include "drmP.h"
  28. #include "amdgpu.h"
  29. #include "amdgpu_atombios.h"
  30. #include "amdgpu_ih.h"
  31. #include "amdgpu_uvd.h"
  32. #include "amdgpu_vce.h"
  33. #include "cikd.h"
  34. #include "atom.h"
  35. #include "amd_pcie.h"
  36. #include "cik.h"
  37. #include "gmc_v7_0.h"
  38. #include "cik_ih.h"
  39. #include "dce_v8_0.h"
  40. #include "gfx_v7_0.h"
  41. #include "cik_sdma.h"
  42. #include "uvd_v4_2.h"
  43. #include "vce_v2_0.h"
  44. #include "cik_dpm.h"
  45. #include "uvd/uvd_4_2_d.h"
  46. #include "smu/smu_7_0_1_d.h"
  47. #include "smu/smu_7_0_1_sh_mask.h"
  48. #include "dce/dce_8_0_d.h"
  49. #include "dce/dce_8_0_sh_mask.h"
  50. #include "bif/bif_4_1_d.h"
  51. #include "bif/bif_4_1_sh_mask.h"
  52. #include "gca/gfx_7_2_d.h"
  53. #include "gca/gfx_7_2_enum.h"
  54. #include "gca/gfx_7_2_sh_mask.h"
  55. #include "gmc/gmc_7_1_d.h"
  56. #include "gmc/gmc_7_1_sh_mask.h"
  57. #include "oss/oss_2_0_d.h"
  58. #include "oss/oss_2_0_sh_mask.h"
  59. #include "amdgpu_amdkfd.h"
  60. #include "amdgpu_powerplay.h"
  61. /*
  62. * Indirect registers accessor
  63. */
  64. static u32 cik_pcie_rreg(struct amdgpu_device *adev, u32 reg)
  65. {
  66. unsigned long flags;
  67. u32 r;
  68. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  69. WREG32(mmPCIE_INDEX, reg);
  70. (void)RREG32(mmPCIE_INDEX);
  71. r = RREG32(mmPCIE_DATA);
  72. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  73. return r;
  74. }
  75. static void cik_pcie_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  76. {
  77. unsigned long flags;
  78. spin_lock_irqsave(&adev->pcie_idx_lock, flags);
  79. WREG32(mmPCIE_INDEX, reg);
  80. (void)RREG32(mmPCIE_INDEX);
  81. WREG32(mmPCIE_DATA, v);
  82. (void)RREG32(mmPCIE_DATA);
  83. spin_unlock_irqrestore(&adev->pcie_idx_lock, flags);
  84. }
  85. static u32 cik_smc_rreg(struct amdgpu_device *adev, u32 reg)
  86. {
  87. unsigned long flags;
  88. u32 r;
  89. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  90. WREG32(mmSMC_IND_INDEX_0, (reg));
  91. r = RREG32(mmSMC_IND_DATA_0);
  92. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  93. return r;
  94. }
  95. static void cik_smc_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  96. {
  97. unsigned long flags;
  98. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  99. WREG32(mmSMC_IND_INDEX_0, (reg));
  100. WREG32(mmSMC_IND_DATA_0, (v));
  101. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  102. }
  103. static u32 cik_uvd_ctx_rreg(struct amdgpu_device *adev, u32 reg)
  104. {
  105. unsigned long flags;
  106. u32 r;
  107. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  108. WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
  109. r = RREG32(mmUVD_CTX_DATA);
  110. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  111. return r;
  112. }
  113. static void cik_uvd_ctx_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  114. {
  115. unsigned long flags;
  116. spin_lock_irqsave(&adev->uvd_ctx_idx_lock, flags);
  117. WREG32(mmUVD_CTX_INDEX, ((reg) & 0x1ff));
  118. WREG32(mmUVD_CTX_DATA, (v));
  119. spin_unlock_irqrestore(&adev->uvd_ctx_idx_lock, flags);
  120. }
  121. static u32 cik_didt_rreg(struct amdgpu_device *adev, u32 reg)
  122. {
  123. unsigned long flags;
  124. u32 r;
  125. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  126. WREG32(mmDIDT_IND_INDEX, (reg));
  127. r = RREG32(mmDIDT_IND_DATA);
  128. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  129. return r;
  130. }
  131. static void cik_didt_wreg(struct amdgpu_device *adev, u32 reg, u32 v)
  132. {
  133. unsigned long flags;
  134. spin_lock_irqsave(&adev->didt_idx_lock, flags);
  135. WREG32(mmDIDT_IND_INDEX, (reg));
  136. WREG32(mmDIDT_IND_DATA, (v));
  137. spin_unlock_irqrestore(&adev->didt_idx_lock, flags);
  138. }
  139. static const u32 bonaire_golden_spm_registers[] =
  140. {
  141. 0xc200, 0xe0ffffff, 0xe0000000
  142. };
  143. static const u32 bonaire_golden_common_registers[] =
  144. {
  145. 0x31dc, 0xffffffff, 0x00000800,
  146. 0x31dd, 0xffffffff, 0x00000800,
  147. 0x31e6, 0xffffffff, 0x00007fbf,
  148. 0x31e7, 0xffffffff, 0x00007faf
  149. };
  150. static const u32 bonaire_golden_registers[] =
  151. {
  152. 0xcd5, 0x00000333, 0x00000333,
  153. 0xcd4, 0x000c0fc0, 0x00040200,
  154. 0x2684, 0x00010000, 0x00058208,
  155. 0xf000, 0xffff1fff, 0x00140000,
  156. 0xf080, 0xfdfc0fff, 0x00000100,
  157. 0xf08d, 0x40000000, 0x40000200,
  158. 0x260c, 0xffffffff, 0x00000000,
  159. 0x260d, 0xf00fffff, 0x00000400,
  160. 0x260e, 0x0002021c, 0x00020200,
  161. 0x31e, 0x00000080, 0x00000000,
  162. 0x16ec, 0x000000f0, 0x00000070,
  163. 0x16f0, 0xf0311fff, 0x80300000,
  164. 0x263e, 0x73773777, 0x12010001,
  165. 0xd43, 0x00810000, 0x408af000,
  166. 0x1c0c, 0x31000111, 0x00000011,
  167. 0xbd2, 0x73773777, 0x12010001,
  168. 0x883, 0x00007fb6, 0x0021a1b1,
  169. 0x884, 0x00007fb6, 0x002021b1,
  170. 0x860, 0x00007fb6, 0x00002191,
  171. 0x886, 0x00007fb6, 0x002121b1,
  172. 0x887, 0x00007fb6, 0x002021b1,
  173. 0x877, 0x00007fb6, 0x00002191,
  174. 0x878, 0x00007fb6, 0x00002191,
  175. 0xd8a, 0x0000003f, 0x0000000a,
  176. 0xd8b, 0x0000003f, 0x0000000a,
  177. 0xab9, 0x00073ffe, 0x000022a2,
  178. 0x903, 0x000007ff, 0x00000000,
  179. 0x2285, 0xf000003f, 0x00000007,
  180. 0x22fc, 0x00002001, 0x00000001,
  181. 0x22c9, 0xffffffff, 0x00ffffff,
  182. 0xc281, 0x0000ff0f, 0x00000000,
  183. 0xa293, 0x07ffffff, 0x06000000,
  184. 0x136, 0x00000fff, 0x00000100,
  185. 0xf9e, 0x00000001, 0x00000002,
  186. 0x2440, 0x03000000, 0x0362c688,
  187. 0x2300, 0x000000ff, 0x00000001,
  188. 0x390, 0x00001fff, 0x00001fff,
  189. 0x2418, 0x0000007f, 0x00000020,
  190. 0x2542, 0x00010000, 0x00010000,
  191. 0x2b05, 0x000003ff, 0x000000f3,
  192. 0x2b03, 0xffffffff, 0x00001032
  193. };
  194. static const u32 bonaire_mgcg_cgcg_init[] =
  195. {
  196. 0x3108, 0xffffffff, 0xfffffffc,
  197. 0xc200, 0xffffffff, 0xe0000000,
  198. 0xf0a8, 0xffffffff, 0x00000100,
  199. 0xf082, 0xffffffff, 0x00000100,
  200. 0xf0b0, 0xffffffff, 0xc0000100,
  201. 0xf0b2, 0xffffffff, 0xc0000100,
  202. 0xf0b1, 0xffffffff, 0xc0000100,
  203. 0x1579, 0xffffffff, 0x00600100,
  204. 0xf0a0, 0xffffffff, 0x00000100,
  205. 0xf085, 0xffffffff, 0x06000100,
  206. 0xf088, 0xffffffff, 0x00000100,
  207. 0xf086, 0xffffffff, 0x06000100,
  208. 0xf081, 0xffffffff, 0x00000100,
  209. 0xf0b8, 0xffffffff, 0x00000100,
  210. 0xf089, 0xffffffff, 0x00000100,
  211. 0xf080, 0xffffffff, 0x00000100,
  212. 0xf08c, 0xffffffff, 0x00000100,
  213. 0xf08d, 0xffffffff, 0x00000100,
  214. 0xf094, 0xffffffff, 0x00000100,
  215. 0xf095, 0xffffffff, 0x00000100,
  216. 0xf096, 0xffffffff, 0x00000100,
  217. 0xf097, 0xffffffff, 0x00000100,
  218. 0xf098, 0xffffffff, 0x00000100,
  219. 0xf09f, 0xffffffff, 0x00000100,
  220. 0xf09e, 0xffffffff, 0x00000100,
  221. 0xf084, 0xffffffff, 0x06000100,
  222. 0xf0a4, 0xffffffff, 0x00000100,
  223. 0xf09d, 0xffffffff, 0x00000100,
  224. 0xf0ad, 0xffffffff, 0x00000100,
  225. 0xf0ac, 0xffffffff, 0x00000100,
  226. 0xf09c, 0xffffffff, 0x00000100,
  227. 0xc200, 0xffffffff, 0xe0000000,
  228. 0xf008, 0xffffffff, 0x00010000,
  229. 0xf009, 0xffffffff, 0x00030002,
  230. 0xf00a, 0xffffffff, 0x00040007,
  231. 0xf00b, 0xffffffff, 0x00060005,
  232. 0xf00c, 0xffffffff, 0x00090008,
  233. 0xf00d, 0xffffffff, 0x00010000,
  234. 0xf00e, 0xffffffff, 0x00030002,
  235. 0xf00f, 0xffffffff, 0x00040007,
  236. 0xf010, 0xffffffff, 0x00060005,
  237. 0xf011, 0xffffffff, 0x00090008,
  238. 0xf012, 0xffffffff, 0x00010000,
  239. 0xf013, 0xffffffff, 0x00030002,
  240. 0xf014, 0xffffffff, 0x00040007,
  241. 0xf015, 0xffffffff, 0x00060005,
  242. 0xf016, 0xffffffff, 0x00090008,
  243. 0xf017, 0xffffffff, 0x00010000,
  244. 0xf018, 0xffffffff, 0x00030002,
  245. 0xf019, 0xffffffff, 0x00040007,
  246. 0xf01a, 0xffffffff, 0x00060005,
  247. 0xf01b, 0xffffffff, 0x00090008,
  248. 0xf01c, 0xffffffff, 0x00010000,
  249. 0xf01d, 0xffffffff, 0x00030002,
  250. 0xf01e, 0xffffffff, 0x00040007,
  251. 0xf01f, 0xffffffff, 0x00060005,
  252. 0xf020, 0xffffffff, 0x00090008,
  253. 0xf021, 0xffffffff, 0x00010000,
  254. 0xf022, 0xffffffff, 0x00030002,
  255. 0xf023, 0xffffffff, 0x00040007,
  256. 0xf024, 0xffffffff, 0x00060005,
  257. 0xf025, 0xffffffff, 0x00090008,
  258. 0xf026, 0xffffffff, 0x00010000,
  259. 0xf027, 0xffffffff, 0x00030002,
  260. 0xf028, 0xffffffff, 0x00040007,
  261. 0xf029, 0xffffffff, 0x00060005,
  262. 0xf02a, 0xffffffff, 0x00090008,
  263. 0xf000, 0xffffffff, 0x96e00200,
  264. 0x21c2, 0xffffffff, 0x00900100,
  265. 0x3109, 0xffffffff, 0x0020003f,
  266. 0xe, 0xffffffff, 0x0140001c,
  267. 0xf, 0x000f0000, 0x000f0000,
  268. 0x88, 0xffffffff, 0xc060000c,
  269. 0x89, 0xc0000fff, 0x00000100,
  270. 0x3e4, 0xffffffff, 0x00000100,
  271. 0x3e6, 0x00000101, 0x00000000,
  272. 0x82a, 0xffffffff, 0x00000104,
  273. 0x1579, 0xff000fff, 0x00000100,
  274. 0xc33, 0xc0000fff, 0x00000104,
  275. 0x3079, 0x00000001, 0x00000001,
  276. 0x3403, 0xff000ff0, 0x00000100,
  277. 0x3603, 0xff000ff0, 0x00000100
  278. };
  279. static const u32 spectre_golden_spm_registers[] =
  280. {
  281. 0xc200, 0xe0ffffff, 0xe0000000
  282. };
  283. static const u32 spectre_golden_common_registers[] =
  284. {
  285. 0x31dc, 0xffffffff, 0x00000800,
  286. 0x31dd, 0xffffffff, 0x00000800,
  287. 0x31e6, 0xffffffff, 0x00007fbf,
  288. 0x31e7, 0xffffffff, 0x00007faf
  289. };
  290. static const u32 spectre_golden_registers[] =
  291. {
  292. 0xf000, 0xffff1fff, 0x96940200,
  293. 0xf003, 0xffff0001, 0xff000000,
  294. 0xf080, 0xfffc0fff, 0x00000100,
  295. 0x1bb6, 0x00010101, 0x00010000,
  296. 0x260d, 0xf00fffff, 0x00000400,
  297. 0x260e, 0xfffffffc, 0x00020200,
  298. 0x16ec, 0x000000f0, 0x00000070,
  299. 0x16f0, 0xf0311fff, 0x80300000,
  300. 0x263e, 0x73773777, 0x12010001,
  301. 0x26df, 0x00ff0000, 0x00fc0000,
  302. 0xbd2, 0x73773777, 0x12010001,
  303. 0x2285, 0xf000003f, 0x00000007,
  304. 0x22c9, 0xffffffff, 0x00ffffff,
  305. 0xa0d4, 0x3f3f3fff, 0x00000082,
  306. 0xa0d5, 0x0000003f, 0x00000000,
  307. 0xf9e, 0x00000001, 0x00000002,
  308. 0x244f, 0xffff03df, 0x00000004,
  309. 0x31da, 0x00000008, 0x00000008,
  310. 0x2300, 0x000008ff, 0x00000800,
  311. 0x2542, 0x00010000, 0x00010000,
  312. 0x2b03, 0xffffffff, 0x54763210,
  313. 0x853e, 0x01ff01ff, 0x00000002,
  314. 0x8526, 0x007ff800, 0x00200000,
  315. 0x8057, 0xffffffff, 0x00000f40,
  316. 0xc24d, 0xffffffff, 0x00000001
  317. };
  318. static const u32 spectre_mgcg_cgcg_init[] =
  319. {
  320. 0x3108, 0xffffffff, 0xfffffffc,
  321. 0xc200, 0xffffffff, 0xe0000000,
  322. 0xf0a8, 0xffffffff, 0x00000100,
  323. 0xf082, 0xffffffff, 0x00000100,
  324. 0xf0b0, 0xffffffff, 0x00000100,
  325. 0xf0b2, 0xffffffff, 0x00000100,
  326. 0xf0b1, 0xffffffff, 0x00000100,
  327. 0x1579, 0xffffffff, 0x00600100,
  328. 0xf0a0, 0xffffffff, 0x00000100,
  329. 0xf085, 0xffffffff, 0x06000100,
  330. 0xf088, 0xffffffff, 0x00000100,
  331. 0xf086, 0xffffffff, 0x06000100,
  332. 0xf081, 0xffffffff, 0x00000100,
  333. 0xf0b8, 0xffffffff, 0x00000100,
  334. 0xf089, 0xffffffff, 0x00000100,
  335. 0xf080, 0xffffffff, 0x00000100,
  336. 0xf08c, 0xffffffff, 0x00000100,
  337. 0xf08d, 0xffffffff, 0x00000100,
  338. 0xf094, 0xffffffff, 0x00000100,
  339. 0xf095, 0xffffffff, 0x00000100,
  340. 0xf096, 0xffffffff, 0x00000100,
  341. 0xf097, 0xffffffff, 0x00000100,
  342. 0xf098, 0xffffffff, 0x00000100,
  343. 0xf09f, 0xffffffff, 0x00000100,
  344. 0xf09e, 0xffffffff, 0x00000100,
  345. 0xf084, 0xffffffff, 0x06000100,
  346. 0xf0a4, 0xffffffff, 0x00000100,
  347. 0xf09d, 0xffffffff, 0x00000100,
  348. 0xf0ad, 0xffffffff, 0x00000100,
  349. 0xf0ac, 0xffffffff, 0x00000100,
  350. 0xf09c, 0xffffffff, 0x00000100,
  351. 0xc200, 0xffffffff, 0xe0000000,
  352. 0xf008, 0xffffffff, 0x00010000,
  353. 0xf009, 0xffffffff, 0x00030002,
  354. 0xf00a, 0xffffffff, 0x00040007,
  355. 0xf00b, 0xffffffff, 0x00060005,
  356. 0xf00c, 0xffffffff, 0x00090008,
  357. 0xf00d, 0xffffffff, 0x00010000,
  358. 0xf00e, 0xffffffff, 0x00030002,
  359. 0xf00f, 0xffffffff, 0x00040007,
  360. 0xf010, 0xffffffff, 0x00060005,
  361. 0xf011, 0xffffffff, 0x00090008,
  362. 0xf012, 0xffffffff, 0x00010000,
  363. 0xf013, 0xffffffff, 0x00030002,
  364. 0xf014, 0xffffffff, 0x00040007,
  365. 0xf015, 0xffffffff, 0x00060005,
  366. 0xf016, 0xffffffff, 0x00090008,
  367. 0xf017, 0xffffffff, 0x00010000,
  368. 0xf018, 0xffffffff, 0x00030002,
  369. 0xf019, 0xffffffff, 0x00040007,
  370. 0xf01a, 0xffffffff, 0x00060005,
  371. 0xf01b, 0xffffffff, 0x00090008,
  372. 0xf01c, 0xffffffff, 0x00010000,
  373. 0xf01d, 0xffffffff, 0x00030002,
  374. 0xf01e, 0xffffffff, 0x00040007,
  375. 0xf01f, 0xffffffff, 0x00060005,
  376. 0xf020, 0xffffffff, 0x00090008,
  377. 0xf021, 0xffffffff, 0x00010000,
  378. 0xf022, 0xffffffff, 0x00030002,
  379. 0xf023, 0xffffffff, 0x00040007,
  380. 0xf024, 0xffffffff, 0x00060005,
  381. 0xf025, 0xffffffff, 0x00090008,
  382. 0xf026, 0xffffffff, 0x00010000,
  383. 0xf027, 0xffffffff, 0x00030002,
  384. 0xf028, 0xffffffff, 0x00040007,
  385. 0xf029, 0xffffffff, 0x00060005,
  386. 0xf02a, 0xffffffff, 0x00090008,
  387. 0xf02b, 0xffffffff, 0x00010000,
  388. 0xf02c, 0xffffffff, 0x00030002,
  389. 0xf02d, 0xffffffff, 0x00040007,
  390. 0xf02e, 0xffffffff, 0x00060005,
  391. 0xf02f, 0xffffffff, 0x00090008,
  392. 0xf000, 0xffffffff, 0x96e00200,
  393. 0x21c2, 0xffffffff, 0x00900100,
  394. 0x3109, 0xffffffff, 0x0020003f,
  395. 0xe, 0xffffffff, 0x0140001c,
  396. 0xf, 0x000f0000, 0x000f0000,
  397. 0x88, 0xffffffff, 0xc060000c,
  398. 0x89, 0xc0000fff, 0x00000100,
  399. 0x3e4, 0xffffffff, 0x00000100,
  400. 0x3e6, 0x00000101, 0x00000000,
  401. 0x82a, 0xffffffff, 0x00000104,
  402. 0x1579, 0xff000fff, 0x00000100,
  403. 0xc33, 0xc0000fff, 0x00000104,
  404. 0x3079, 0x00000001, 0x00000001,
  405. 0x3403, 0xff000ff0, 0x00000100,
  406. 0x3603, 0xff000ff0, 0x00000100
  407. };
  408. static const u32 kalindi_golden_spm_registers[] =
  409. {
  410. 0xc200, 0xe0ffffff, 0xe0000000
  411. };
  412. static const u32 kalindi_golden_common_registers[] =
  413. {
  414. 0x31dc, 0xffffffff, 0x00000800,
  415. 0x31dd, 0xffffffff, 0x00000800,
  416. 0x31e6, 0xffffffff, 0x00007fbf,
  417. 0x31e7, 0xffffffff, 0x00007faf
  418. };
  419. static const u32 kalindi_golden_registers[] =
  420. {
  421. 0xf000, 0xffffdfff, 0x6e944040,
  422. 0x1579, 0xff607fff, 0xfc000100,
  423. 0xf088, 0xff000fff, 0x00000100,
  424. 0xf089, 0xff000fff, 0x00000100,
  425. 0xf080, 0xfffc0fff, 0x00000100,
  426. 0x1bb6, 0x00010101, 0x00010000,
  427. 0x260c, 0xffffffff, 0x00000000,
  428. 0x260d, 0xf00fffff, 0x00000400,
  429. 0x16ec, 0x000000f0, 0x00000070,
  430. 0x16f0, 0xf0311fff, 0x80300000,
  431. 0x263e, 0x73773777, 0x12010001,
  432. 0x263f, 0xffffffff, 0x00000010,
  433. 0x26df, 0x00ff0000, 0x00fc0000,
  434. 0x200c, 0x00001f0f, 0x0000100a,
  435. 0xbd2, 0x73773777, 0x12010001,
  436. 0x902, 0x000fffff, 0x000c007f,
  437. 0x2285, 0xf000003f, 0x00000007,
  438. 0x22c9, 0x3fff3fff, 0x00ffcfff,
  439. 0xc281, 0x0000ff0f, 0x00000000,
  440. 0xa293, 0x07ffffff, 0x06000000,
  441. 0x136, 0x00000fff, 0x00000100,
  442. 0xf9e, 0x00000001, 0x00000002,
  443. 0x31da, 0x00000008, 0x00000008,
  444. 0x2300, 0x000000ff, 0x00000003,
  445. 0x853e, 0x01ff01ff, 0x00000002,
  446. 0x8526, 0x007ff800, 0x00200000,
  447. 0x8057, 0xffffffff, 0x00000f40,
  448. 0x2231, 0x001f3ae3, 0x00000082,
  449. 0x2235, 0x0000001f, 0x00000010,
  450. 0xc24d, 0xffffffff, 0x00000000
  451. };
  452. static const u32 kalindi_mgcg_cgcg_init[] =
  453. {
  454. 0x3108, 0xffffffff, 0xfffffffc,
  455. 0xc200, 0xffffffff, 0xe0000000,
  456. 0xf0a8, 0xffffffff, 0x00000100,
  457. 0xf082, 0xffffffff, 0x00000100,
  458. 0xf0b0, 0xffffffff, 0x00000100,
  459. 0xf0b2, 0xffffffff, 0x00000100,
  460. 0xf0b1, 0xffffffff, 0x00000100,
  461. 0x1579, 0xffffffff, 0x00600100,
  462. 0xf0a0, 0xffffffff, 0x00000100,
  463. 0xf085, 0xffffffff, 0x06000100,
  464. 0xf088, 0xffffffff, 0x00000100,
  465. 0xf086, 0xffffffff, 0x06000100,
  466. 0xf081, 0xffffffff, 0x00000100,
  467. 0xf0b8, 0xffffffff, 0x00000100,
  468. 0xf089, 0xffffffff, 0x00000100,
  469. 0xf080, 0xffffffff, 0x00000100,
  470. 0xf08c, 0xffffffff, 0x00000100,
  471. 0xf08d, 0xffffffff, 0x00000100,
  472. 0xf094, 0xffffffff, 0x00000100,
  473. 0xf095, 0xffffffff, 0x00000100,
  474. 0xf096, 0xffffffff, 0x00000100,
  475. 0xf097, 0xffffffff, 0x00000100,
  476. 0xf098, 0xffffffff, 0x00000100,
  477. 0xf09f, 0xffffffff, 0x00000100,
  478. 0xf09e, 0xffffffff, 0x00000100,
  479. 0xf084, 0xffffffff, 0x06000100,
  480. 0xf0a4, 0xffffffff, 0x00000100,
  481. 0xf09d, 0xffffffff, 0x00000100,
  482. 0xf0ad, 0xffffffff, 0x00000100,
  483. 0xf0ac, 0xffffffff, 0x00000100,
  484. 0xf09c, 0xffffffff, 0x00000100,
  485. 0xc200, 0xffffffff, 0xe0000000,
  486. 0xf008, 0xffffffff, 0x00010000,
  487. 0xf009, 0xffffffff, 0x00030002,
  488. 0xf00a, 0xffffffff, 0x00040007,
  489. 0xf00b, 0xffffffff, 0x00060005,
  490. 0xf00c, 0xffffffff, 0x00090008,
  491. 0xf00d, 0xffffffff, 0x00010000,
  492. 0xf00e, 0xffffffff, 0x00030002,
  493. 0xf00f, 0xffffffff, 0x00040007,
  494. 0xf010, 0xffffffff, 0x00060005,
  495. 0xf011, 0xffffffff, 0x00090008,
  496. 0xf000, 0xffffffff, 0x96e00200,
  497. 0x21c2, 0xffffffff, 0x00900100,
  498. 0x3109, 0xffffffff, 0x0020003f,
  499. 0xe, 0xffffffff, 0x0140001c,
  500. 0xf, 0x000f0000, 0x000f0000,
  501. 0x88, 0xffffffff, 0xc060000c,
  502. 0x89, 0xc0000fff, 0x00000100,
  503. 0x82a, 0xffffffff, 0x00000104,
  504. 0x1579, 0xff000fff, 0x00000100,
  505. 0xc33, 0xc0000fff, 0x00000104,
  506. 0x3079, 0x00000001, 0x00000001,
  507. 0x3403, 0xff000ff0, 0x00000100,
  508. 0x3603, 0xff000ff0, 0x00000100
  509. };
  510. static const u32 hawaii_golden_spm_registers[] =
  511. {
  512. 0xc200, 0xe0ffffff, 0xe0000000
  513. };
  514. static const u32 hawaii_golden_common_registers[] =
  515. {
  516. 0xc200, 0xffffffff, 0xe0000000,
  517. 0xa0d4, 0xffffffff, 0x3a00161a,
  518. 0xa0d5, 0xffffffff, 0x0000002e,
  519. 0x2684, 0xffffffff, 0x00018208,
  520. 0x263e, 0xffffffff, 0x12011003
  521. };
  522. static const u32 hawaii_golden_registers[] =
  523. {
  524. 0xcd5, 0x00000333, 0x00000333,
  525. 0x2684, 0x00010000, 0x00058208,
  526. 0x260c, 0xffffffff, 0x00000000,
  527. 0x260d, 0xf00fffff, 0x00000400,
  528. 0x260e, 0x0002021c, 0x00020200,
  529. 0x31e, 0x00000080, 0x00000000,
  530. 0x16ec, 0x000000f0, 0x00000070,
  531. 0x16f0, 0xf0311fff, 0x80300000,
  532. 0xd43, 0x00810000, 0x408af000,
  533. 0x1c0c, 0x31000111, 0x00000011,
  534. 0xbd2, 0x73773777, 0x12010001,
  535. 0x848, 0x0000007f, 0x0000001b,
  536. 0x877, 0x00007fb6, 0x00002191,
  537. 0xd8a, 0x0000003f, 0x0000000a,
  538. 0xd8b, 0x0000003f, 0x0000000a,
  539. 0xab9, 0x00073ffe, 0x000022a2,
  540. 0x903, 0x000007ff, 0x00000000,
  541. 0x22fc, 0x00002001, 0x00000001,
  542. 0x22c9, 0xffffffff, 0x00ffffff,
  543. 0xc281, 0x0000ff0f, 0x00000000,
  544. 0xa293, 0x07ffffff, 0x06000000,
  545. 0xf9e, 0x00000001, 0x00000002,
  546. 0x31da, 0x00000008, 0x00000008,
  547. 0x31dc, 0x00000f00, 0x00000800,
  548. 0x31dd, 0x00000f00, 0x00000800,
  549. 0x31e6, 0x00ffffff, 0x00ff7fbf,
  550. 0x31e7, 0x00ffffff, 0x00ff7faf,
  551. 0x2300, 0x000000ff, 0x00000800,
  552. 0x390, 0x00001fff, 0x00001fff,
  553. 0x2418, 0x0000007f, 0x00000020,
  554. 0x2542, 0x00010000, 0x00010000,
  555. 0x2b80, 0x00100000, 0x000ff07c,
  556. 0x2b05, 0x000003ff, 0x0000000f,
  557. 0x2b04, 0xffffffff, 0x7564fdec,
  558. 0x2b03, 0xffffffff, 0x3120b9a8,
  559. 0x2b02, 0x20000000, 0x0f9c0000
  560. };
  561. static const u32 hawaii_mgcg_cgcg_init[] =
  562. {
  563. 0x3108, 0xffffffff, 0xfffffffd,
  564. 0xc200, 0xffffffff, 0xe0000000,
  565. 0xf0a8, 0xffffffff, 0x00000100,
  566. 0xf082, 0xffffffff, 0x00000100,
  567. 0xf0b0, 0xffffffff, 0x00000100,
  568. 0xf0b2, 0xffffffff, 0x00000100,
  569. 0xf0b1, 0xffffffff, 0x00000100,
  570. 0x1579, 0xffffffff, 0x00200100,
  571. 0xf0a0, 0xffffffff, 0x00000100,
  572. 0xf085, 0xffffffff, 0x06000100,
  573. 0xf088, 0xffffffff, 0x00000100,
  574. 0xf086, 0xffffffff, 0x06000100,
  575. 0xf081, 0xffffffff, 0x00000100,
  576. 0xf0b8, 0xffffffff, 0x00000100,
  577. 0xf089, 0xffffffff, 0x00000100,
  578. 0xf080, 0xffffffff, 0x00000100,
  579. 0xf08c, 0xffffffff, 0x00000100,
  580. 0xf08d, 0xffffffff, 0x00000100,
  581. 0xf094, 0xffffffff, 0x00000100,
  582. 0xf095, 0xffffffff, 0x00000100,
  583. 0xf096, 0xffffffff, 0x00000100,
  584. 0xf097, 0xffffffff, 0x00000100,
  585. 0xf098, 0xffffffff, 0x00000100,
  586. 0xf09f, 0xffffffff, 0x00000100,
  587. 0xf09e, 0xffffffff, 0x00000100,
  588. 0xf084, 0xffffffff, 0x06000100,
  589. 0xf0a4, 0xffffffff, 0x00000100,
  590. 0xf09d, 0xffffffff, 0x00000100,
  591. 0xf0ad, 0xffffffff, 0x00000100,
  592. 0xf0ac, 0xffffffff, 0x00000100,
  593. 0xf09c, 0xffffffff, 0x00000100,
  594. 0xc200, 0xffffffff, 0xe0000000,
  595. 0xf008, 0xffffffff, 0x00010000,
  596. 0xf009, 0xffffffff, 0x00030002,
  597. 0xf00a, 0xffffffff, 0x00040007,
  598. 0xf00b, 0xffffffff, 0x00060005,
  599. 0xf00c, 0xffffffff, 0x00090008,
  600. 0xf00d, 0xffffffff, 0x00010000,
  601. 0xf00e, 0xffffffff, 0x00030002,
  602. 0xf00f, 0xffffffff, 0x00040007,
  603. 0xf010, 0xffffffff, 0x00060005,
  604. 0xf011, 0xffffffff, 0x00090008,
  605. 0xf012, 0xffffffff, 0x00010000,
  606. 0xf013, 0xffffffff, 0x00030002,
  607. 0xf014, 0xffffffff, 0x00040007,
  608. 0xf015, 0xffffffff, 0x00060005,
  609. 0xf016, 0xffffffff, 0x00090008,
  610. 0xf017, 0xffffffff, 0x00010000,
  611. 0xf018, 0xffffffff, 0x00030002,
  612. 0xf019, 0xffffffff, 0x00040007,
  613. 0xf01a, 0xffffffff, 0x00060005,
  614. 0xf01b, 0xffffffff, 0x00090008,
  615. 0xf01c, 0xffffffff, 0x00010000,
  616. 0xf01d, 0xffffffff, 0x00030002,
  617. 0xf01e, 0xffffffff, 0x00040007,
  618. 0xf01f, 0xffffffff, 0x00060005,
  619. 0xf020, 0xffffffff, 0x00090008,
  620. 0xf021, 0xffffffff, 0x00010000,
  621. 0xf022, 0xffffffff, 0x00030002,
  622. 0xf023, 0xffffffff, 0x00040007,
  623. 0xf024, 0xffffffff, 0x00060005,
  624. 0xf025, 0xffffffff, 0x00090008,
  625. 0xf026, 0xffffffff, 0x00010000,
  626. 0xf027, 0xffffffff, 0x00030002,
  627. 0xf028, 0xffffffff, 0x00040007,
  628. 0xf029, 0xffffffff, 0x00060005,
  629. 0xf02a, 0xffffffff, 0x00090008,
  630. 0xf02b, 0xffffffff, 0x00010000,
  631. 0xf02c, 0xffffffff, 0x00030002,
  632. 0xf02d, 0xffffffff, 0x00040007,
  633. 0xf02e, 0xffffffff, 0x00060005,
  634. 0xf02f, 0xffffffff, 0x00090008,
  635. 0xf030, 0xffffffff, 0x00010000,
  636. 0xf031, 0xffffffff, 0x00030002,
  637. 0xf032, 0xffffffff, 0x00040007,
  638. 0xf033, 0xffffffff, 0x00060005,
  639. 0xf034, 0xffffffff, 0x00090008,
  640. 0xf035, 0xffffffff, 0x00010000,
  641. 0xf036, 0xffffffff, 0x00030002,
  642. 0xf037, 0xffffffff, 0x00040007,
  643. 0xf038, 0xffffffff, 0x00060005,
  644. 0xf039, 0xffffffff, 0x00090008,
  645. 0xf03a, 0xffffffff, 0x00010000,
  646. 0xf03b, 0xffffffff, 0x00030002,
  647. 0xf03c, 0xffffffff, 0x00040007,
  648. 0xf03d, 0xffffffff, 0x00060005,
  649. 0xf03e, 0xffffffff, 0x00090008,
  650. 0x30c6, 0xffffffff, 0x00020200,
  651. 0xcd4, 0xffffffff, 0x00000200,
  652. 0x570, 0xffffffff, 0x00000400,
  653. 0x157a, 0xffffffff, 0x00000000,
  654. 0xbd4, 0xffffffff, 0x00000902,
  655. 0xf000, 0xffffffff, 0x96940200,
  656. 0x21c2, 0xffffffff, 0x00900100,
  657. 0x3109, 0xffffffff, 0x0020003f,
  658. 0xe, 0xffffffff, 0x0140001c,
  659. 0xf, 0x000f0000, 0x000f0000,
  660. 0x88, 0xffffffff, 0xc060000c,
  661. 0x89, 0xc0000fff, 0x00000100,
  662. 0x3e4, 0xffffffff, 0x00000100,
  663. 0x3e6, 0x00000101, 0x00000000,
  664. 0x82a, 0xffffffff, 0x00000104,
  665. 0x1579, 0xff000fff, 0x00000100,
  666. 0xc33, 0xc0000fff, 0x00000104,
  667. 0x3079, 0x00000001, 0x00000001,
  668. 0x3403, 0xff000ff0, 0x00000100,
  669. 0x3603, 0xff000ff0, 0x00000100
  670. };
  671. static const u32 godavari_golden_registers[] =
  672. {
  673. 0x1579, 0xff607fff, 0xfc000100,
  674. 0x1bb6, 0x00010101, 0x00010000,
  675. 0x260c, 0xffffffff, 0x00000000,
  676. 0x260c0, 0xf00fffff, 0x00000400,
  677. 0x184c, 0xffffffff, 0x00010000,
  678. 0x16ec, 0x000000f0, 0x00000070,
  679. 0x16f0, 0xf0311fff, 0x80300000,
  680. 0x263e, 0x73773777, 0x12010001,
  681. 0x263f, 0xffffffff, 0x00000010,
  682. 0x200c, 0x00001f0f, 0x0000100a,
  683. 0xbd2, 0x73773777, 0x12010001,
  684. 0x902, 0x000fffff, 0x000c007f,
  685. 0x2285, 0xf000003f, 0x00000007,
  686. 0x22c9, 0xffffffff, 0x00ff0fff,
  687. 0xc281, 0x0000ff0f, 0x00000000,
  688. 0xa293, 0x07ffffff, 0x06000000,
  689. 0x136, 0x00000fff, 0x00000100,
  690. 0x3405, 0x00010000, 0x00810001,
  691. 0x3605, 0x00010000, 0x00810001,
  692. 0xf9e, 0x00000001, 0x00000002,
  693. 0x31da, 0x00000008, 0x00000008,
  694. 0x31dc, 0x00000f00, 0x00000800,
  695. 0x31dd, 0x00000f00, 0x00000800,
  696. 0x31e6, 0x00ffffff, 0x00ff7fbf,
  697. 0x31e7, 0x00ffffff, 0x00ff7faf,
  698. 0x2300, 0x000000ff, 0x00000001,
  699. 0x853e, 0x01ff01ff, 0x00000002,
  700. 0x8526, 0x007ff800, 0x00200000,
  701. 0x8057, 0xffffffff, 0x00000f40,
  702. 0x2231, 0x001f3ae3, 0x00000082,
  703. 0x2235, 0x0000001f, 0x00000010,
  704. 0xc24d, 0xffffffff, 0x00000000
  705. };
  706. static void cik_init_golden_registers(struct amdgpu_device *adev)
  707. {
  708. /* Some of the registers might be dependent on GRBM_GFX_INDEX */
  709. mutex_lock(&adev->grbm_idx_mutex);
  710. switch (adev->asic_type) {
  711. case CHIP_BONAIRE:
  712. amdgpu_program_register_sequence(adev,
  713. bonaire_mgcg_cgcg_init,
  714. (const u32)ARRAY_SIZE(bonaire_mgcg_cgcg_init));
  715. amdgpu_program_register_sequence(adev,
  716. bonaire_golden_registers,
  717. (const u32)ARRAY_SIZE(bonaire_golden_registers));
  718. amdgpu_program_register_sequence(adev,
  719. bonaire_golden_common_registers,
  720. (const u32)ARRAY_SIZE(bonaire_golden_common_registers));
  721. amdgpu_program_register_sequence(adev,
  722. bonaire_golden_spm_registers,
  723. (const u32)ARRAY_SIZE(bonaire_golden_spm_registers));
  724. break;
  725. case CHIP_KABINI:
  726. amdgpu_program_register_sequence(adev,
  727. kalindi_mgcg_cgcg_init,
  728. (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
  729. amdgpu_program_register_sequence(adev,
  730. kalindi_golden_registers,
  731. (const u32)ARRAY_SIZE(kalindi_golden_registers));
  732. amdgpu_program_register_sequence(adev,
  733. kalindi_golden_common_registers,
  734. (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
  735. amdgpu_program_register_sequence(adev,
  736. kalindi_golden_spm_registers,
  737. (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
  738. break;
  739. case CHIP_MULLINS:
  740. amdgpu_program_register_sequence(adev,
  741. kalindi_mgcg_cgcg_init,
  742. (const u32)ARRAY_SIZE(kalindi_mgcg_cgcg_init));
  743. amdgpu_program_register_sequence(adev,
  744. godavari_golden_registers,
  745. (const u32)ARRAY_SIZE(godavari_golden_registers));
  746. amdgpu_program_register_sequence(adev,
  747. kalindi_golden_common_registers,
  748. (const u32)ARRAY_SIZE(kalindi_golden_common_registers));
  749. amdgpu_program_register_sequence(adev,
  750. kalindi_golden_spm_registers,
  751. (const u32)ARRAY_SIZE(kalindi_golden_spm_registers));
  752. break;
  753. case CHIP_KAVERI:
  754. amdgpu_program_register_sequence(adev,
  755. spectre_mgcg_cgcg_init,
  756. (const u32)ARRAY_SIZE(spectre_mgcg_cgcg_init));
  757. amdgpu_program_register_sequence(adev,
  758. spectre_golden_registers,
  759. (const u32)ARRAY_SIZE(spectre_golden_registers));
  760. amdgpu_program_register_sequence(adev,
  761. spectre_golden_common_registers,
  762. (const u32)ARRAY_SIZE(spectre_golden_common_registers));
  763. amdgpu_program_register_sequence(adev,
  764. spectre_golden_spm_registers,
  765. (const u32)ARRAY_SIZE(spectre_golden_spm_registers));
  766. break;
  767. case CHIP_HAWAII:
  768. amdgpu_program_register_sequence(adev,
  769. hawaii_mgcg_cgcg_init,
  770. (const u32)ARRAY_SIZE(hawaii_mgcg_cgcg_init));
  771. amdgpu_program_register_sequence(adev,
  772. hawaii_golden_registers,
  773. (const u32)ARRAY_SIZE(hawaii_golden_registers));
  774. amdgpu_program_register_sequence(adev,
  775. hawaii_golden_common_registers,
  776. (const u32)ARRAY_SIZE(hawaii_golden_common_registers));
  777. amdgpu_program_register_sequence(adev,
  778. hawaii_golden_spm_registers,
  779. (const u32)ARRAY_SIZE(hawaii_golden_spm_registers));
  780. break;
  781. default:
  782. break;
  783. }
  784. mutex_unlock(&adev->grbm_idx_mutex);
  785. }
  786. /**
  787. * cik_get_xclk - get the xclk
  788. *
  789. * @adev: amdgpu_device pointer
  790. *
  791. * Returns the reference clock used by the gfx engine
  792. * (CIK).
  793. */
  794. static u32 cik_get_xclk(struct amdgpu_device *adev)
  795. {
  796. u32 reference_clock = adev->clock.spll.reference_freq;
  797. if (adev->flags & AMD_IS_APU) {
  798. if (RREG32_SMC(ixGENERAL_PWRMGT) & GENERAL_PWRMGT__GPU_COUNTER_CLK_MASK)
  799. return reference_clock / 2;
  800. } else {
  801. if (RREG32_SMC(ixCG_CLKPIN_CNTL) & CG_CLKPIN_CNTL__XTALIN_DIVIDE_MASK)
  802. return reference_clock / 4;
  803. }
  804. return reference_clock;
  805. }
  806. /**
  807. * cik_srbm_select - select specific register instances
  808. *
  809. * @adev: amdgpu_device pointer
  810. * @me: selected ME (micro engine)
  811. * @pipe: pipe
  812. * @queue: queue
  813. * @vmid: VMID
  814. *
  815. * Switches the currently active registers instances. Some
  816. * registers are instanced per VMID, others are instanced per
  817. * me/pipe/queue combination.
  818. */
  819. void cik_srbm_select(struct amdgpu_device *adev,
  820. u32 me, u32 pipe, u32 queue, u32 vmid)
  821. {
  822. u32 srbm_gfx_cntl =
  823. (((pipe << SRBM_GFX_CNTL__PIPEID__SHIFT) & SRBM_GFX_CNTL__PIPEID_MASK)|
  824. ((me << SRBM_GFX_CNTL__MEID__SHIFT) & SRBM_GFX_CNTL__MEID_MASK)|
  825. ((vmid << SRBM_GFX_CNTL__VMID__SHIFT) & SRBM_GFX_CNTL__VMID_MASK)|
  826. ((queue << SRBM_GFX_CNTL__QUEUEID__SHIFT) & SRBM_GFX_CNTL__QUEUEID_MASK));
  827. WREG32(mmSRBM_GFX_CNTL, srbm_gfx_cntl);
  828. }
  829. static void cik_vga_set_state(struct amdgpu_device *adev, bool state)
  830. {
  831. uint32_t tmp;
  832. tmp = RREG32(mmCONFIG_CNTL);
  833. if (state == false)
  834. tmp |= CONFIG_CNTL__VGA_DIS_MASK;
  835. else
  836. tmp &= ~CONFIG_CNTL__VGA_DIS_MASK;
  837. WREG32(mmCONFIG_CNTL, tmp);
  838. }
  839. static bool cik_read_disabled_bios(struct amdgpu_device *adev)
  840. {
  841. u32 bus_cntl;
  842. u32 d1vga_control = 0;
  843. u32 d2vga_control = 0;
  844. u32 vga_render_control = 0;
  845. u32 rom_cntl;
  846. bool r;
  847. bus_cntl = RREG32(mmBUS_CNTL);
  848. if (adev->mode_info.num_crtc) {
  849. d1vga_control = RREG32(mmD1VGA_CONTROL);
  850. d2vga_control = RREG32(mmD2VGA_CONTROL);
  851. vga_render_control = RREG32(mmVGA_RENDER_CONTROL);
  852. }
  853. rom_cntl = RREG32_SMC(ixROM_CNTL);
  854. /* enable the rom */
  855. WREG32(mmBUS_CNTL, (bus_cntl & ~BUS_CNTL__BIOS_ROM_DIS_MASK));
  856. if (adev->mode_info.num_crtc) {
  857. /* Disable VGA mode */
  858. WREG32(mmD1VGA_CONTROL,
  859. (d1vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
  860. D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
  861. WREG32(mmD2VGA_CONTROL,
  862. (d2vga_control & ~(D1VGA_CONTROL__D1VGA_MODE_ENABLE_MASK |
  863. D1VGA_CONTROL__D1VGA_TIMING_SELECT_MASK)));
  864. WREG32(mmVGA_RENDER_CONTROL,
  865. (vga_render_control & ~VGA_RENDER_CONTROL__VGA_VSTATUS_CNTL_MASK));
  866. }
  867. WREG32_SMC(ixROM_CNTL, rom_cntl | ROM_CNTL__SCK_OVERWRITE_MASK);
  868. r = amdgpu_read_bios(adev);
  869. /* restore regs */
  870. WREG32(mmBUS_CNTL, bus_cntl);
  871. if (adev->mode_info.num_crtc) {
  872. WREG32(mmD1VGA_CONTROL, d1vga_control);
  873. WREG32(mmD2VGA_CONTROL, d2vga_control);
  874. WREG32(mmVGA_RENDER_CONTROL, vga_render_control);
  875. }
  876. WREG32_SMC(ixROM_CNTL, rom_cntl);
  877. return r;
  878. }
  879. static bool cik_read_bios_from_rom(struct amdgpu_device *adev,
  880. u8 *bios, u32 length_bytes)
  881. {
  882. u32 *dw_ptr;
  883. unsigned long flags;
  884. u32 i, length_dw;
  885. if (bios == NULL)
  886. return false;
  887. if (length_bytes == 0)
  888. return false;
  889. /* APU vbios image is part of sbios image */
  890. if (adev->flags & AMD_IS_APU)
  891. return false;
  892. dw_ptr = (u32 *)bios;
  893. length_dw = ALIGN(length_bytes, 4) / 4;
  894. /* take the smc lock since we are using the smc index */
  895. spin_lock_irqsave(&adev->smc_idx_lock, flags);
  896. /* set rom index to 0 */
  897. WREG32(mmSMC_IND_INDEX_0, ixROM_INDEX);
  898. WREG32(mmSMC_IND_DATA_0, 0);
  899. /* set index to data for continous read */
  900. WREG32(mmSMC_IND_INDEX_0, ixROM_DATA);
  901. for (i = 0; i < length_dw; i++)
  902. dw_ptr[i] = RREG32(mmSMC_IND_DATA_0);
  903. spin_unlock_irqrestore(&adev->smc_idx_lock, flags);
  904. return true;
  905. }
  906. static u32 cik_get_virtual_caps(struct amdgpu_device *adev)
  907. {
  908. /* CIK does not support SR-IOV */
  909. return 0;
  910. }
  911. static const struct amdgpu_allowed_register_entry cik_allowed_read_registers[] = {
  912. {mmGRBM_STATUS, false},
  913. {mmGB_ADDR_CONFIG, false},
  914. {mmMC_ARB_RAMCFG, false},
  915. {mmGB_TILE_MODE0, false},
  916. {mmGB_TILE_MODE1, false},
  917. {mmGB_TILE_MODE2, false},
  918. {mmGB_TILE_MODE3, false},
  919. {mmGB_TILE_MODE4, false},
  920. {mmGB_TILE_MODE5, false},
  921. {mmGB_TILE_MODE6, false},
  922. {mmGB_TILE_MODE7, false},
  923. {mmGB_TILE_MODE8, false},
  924. {mmGB_TILE_MODE9, false},
  925. {mmGB_TILE_MODE10, false},
  926. {mmGB_TILE_MODE11, false},
  927. {mmGB_TILE_MODE12, false},
  928. {mmGB_TILE_MODE13, false},
  929. {mmGB_TILE_MODE14, false},
  930. {mmGB_TILE_MODE15, false},
  931. {mmGB_TILE_MODE16, false},
  932. {mmGB_TILE_MODE17, false},
  933. {mmGB_TILE_MODE18, false},
  934. {mmGB_TILE_MODE19, false},
  935. {mmGB_TILE_MODE20, false},
  936. {mmGB_TILE_MODE21, false},
  937. {mmGB_TILE_MODE22, false},
  938. {mmGB_TILE_MODE23, false},
  939. {mmGB_TILE_MODE24, false},
  940. {mmGB_TILE_MODE25, false},
  941. {mmGB_TILE_MODE26, false},
  942. {mmGB_TILE_MODE27, false},
  943. {mmGB_TILE_MODE28, false},
  944. {mmGB_TILE_MODE29, false},
  945. {mmGB_TILE_MODE30, false},
  946. {mmGB_TILE_MODE31, false},
  947. {mmGB_MACROTILE_MODE0, false},
  948. {mmGB_MACROTILE_MODE1, false},
  949. {mmGB_MACROTILE_MODE2, false},
  950. {mmGB_MACROTILE_MODE3, false},
  951. {mmGB_MACROTILE_MODE4, false},
  952. {mmGB_MACROTILE_MODE5, false},
  953. {mmGB_MACROTILE_MODE6, false},
  954. {mmGB_MACROTILE_MODE7, false},
  955. {mmGB_MACROTILE_MODE8, false},
  956. {mmGB_MACROTILE_MODE9, false},
  957. {mmGB_MACROTILE_MODE10, false},
  958. {mmGB_MACROTILE_MODE11, false},
  959. {mmGB_MACROTILE_MODE12, false},
  960. {mmGB_MACROTILE_MODE13, false},
  961. {mmGB_MACROTILE_MODE14, false},
  962. {mmGB_MACROTILE_MODE15, false},
  963. {mmCC_RB_BACKEND_DISABLE, false, true},
  964. {mmGC_USER_RB_BACKEND_DISABLE, false, true},
  965. {mmGB_BACKEND_MAP, false, false},
  966. {mmPA_SC_RASTER_CONFIG, false, true},
  967. {mmPA_SC_RASTER_CONFIG_1, false, true},
  968. };
  969. static uint32_t cik_read_indexed_register(struct amdgpu_device *adev,
  970. u32 se_num, u32 sh_num,
  971. u32 reg_offset)
  972. {
  973. uint32_t val;
  974. mutex_lock(&adev->grbm_idx_mutex);
  975. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  976. gfx_v7_0_select_se_sh(adev, se_num, sh_num);
  977. val = RREG32(reg_offset);
  978. if (se_num != 0xffffffff || sh_num != 0xffffffff)
  979. gfx_v7_0_select_se_sh(adev, 0xffffffff, 0xffffffff);
  980. mutex_unlock(&adev->grbm_idx_mutex);
  981. return val;
  982. }
  983. static int cik_read_register(struct amdgpu_device *adev, u32 se_num,
  984. u32 sh_num, u32 reg_offset, u32 *value)
  985. {
  986. uint32_t i;
  987. *value = 0;
  988. for (i = 0; i < ARRAY_SIZE(cik_allowed_read_registers); i++) {
  989. if (reg_offset != cik_allowed_read_registers[i].reg_offset)
  990. continue;
  991. if (!cik_allowed_read_registers[i].untouched)
  992. *value = cik_allowed_read_registers[i].grbm_indexed ?
  993. cik_read_indexed_register(adev, se_num,
  994. sh_num, reg_offset) :
  995. RREG32(reg_offset);
  996. return 0;
  997. }
  998. return -EINVAL;
  999. }
  1000. struct kv_reset_save_regs {
  1001. u32 gmcon_reng_execute;
  1002. u32 gmcon_misc;
  1003. u32 gmcon_misc3;
  1004. };
  1005. static void kv_save_regs_for_reset(struct amdgpu_device *adev,
  1006. struct kv_reset_save_regs *save)
  1007. {
  1008. save->gmcon_reng_execute = RREG32(mmGMCON_RENG_EXECUTE);
  1009. save->gmcon_misc = RREG32(mmGMCON_MISC);
  1010. save->gmcon_misc3 = RREG32(mmGMCON_MISC3);
  1011. WREG32(mmGMCON_RENG_EXECUTE, save->gmcon_reng_execute &
  1012. ~GMCON_RENG_EXECUTE__RENG_EXECUTE_ON_PWR_UP_MASK);
  1013. WREG32(mmGMCON_MISC, save->gmcon_misc &
  1014. ~(GMCON_MISC__RENG_EXECUTE_ON_REG_UPDATE_MASK |
  1015. GMCON_MISC__STCTRL_STUTTER_EN_MASK));
  1016. }
  1017. static void kv_restore_regs_for_reset(struct amdgpu_device *adev,
  1018. struct kv_reset_save_regs *save)
  1019. {
  1020. int i;
  1021. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1022. WREG32(mmGMCON_PGFSM_CONFIG, 0x200010ff);
  1023. for (i = 0; i < 5; i++)
  1024. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1025. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1026. WREG32(mmGMCON_PGFSM_CONFIG, 0x300010ff);
  1027. for (i = 0; i < 5; i++)
  1028. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1029. WREG32(mmGMCON_PGFSM_WRITE, 0x210000);
  1030. WREG32(mmGMCON_PGFSM_CONFIG, 0xa00010ff);
  1031. for (i = 0; i < 5; i++)
  1032. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1033. WREG32(mmGMCON_PGFSM_WRITE, 0x21003);
  1034. WREG32(mmGMCON_PGFSM_CONFIG, 0xb00010ff);
  1035. for (i = 0; i < 5; i++)
  1036. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1037. WREG32(mmGMCON_PGFSM_WRITE, 0x2b00);
  1038. WREG32(mmGMCON_PGFSM_CONFIG, 0xc00010ff);
  1039. for (i = 0; i < 5; i++)
  1040. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1041. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1042. WREG32(mmGMCON_PGFSM_CONFIG, 0xd00010ff);
  1043. for (i = 0; i < 5; i++)
  1044. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1045. WREG32(mmGMCON_PGFSM_WRITE, 0x420000);
  1046. WREG32(mmGMCON_PGFSM_CONFIG, 0x100010ff);
  1047. for (i = 0; i < 5; i++)
  1048. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1049. WREG32(mmGMCON_PGFSM_WRITE, 0x120202);
  1050. WREG32(mmGMCON_PGFSM_CONFIG, 0x500010ff);
  1051. for (i = 0; i < 5; i++)
  1052. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1053. WREG32(mmGMCON_PGFSM_WRITE, 0x3e3e36);
  1054. WREG32(mmGMCON_PGFSM_CONFIG, 0x600010ff);
  1055. for (i = 0; i < 5; i++)
  1056. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1057. WREG32(mmGMCON_PGFSM_WRITE, 0x373f3e);
  1058. WREG32(mmGMCON_PGFSM_CONFIG, 0x700010ff);
  1059. for (i = 0; i < 5; i++)
  1060. WREG32(mmGMCON_PGFSM_WRITE, 0);
  1061. WREG32(mmGMCON_PGFSM_WRITE, 0x3e1332);
  1062. WREG32(mmGMCON_PGFSM_CONFIG, 0xe00010ff);
  1063. WREG32(mmGMCON_MISC3, save->gmcon_misc3);
  1064. WREG32(mmGMCON_MISC, save->gmcon_misc);
  1065. WREG32(mmGMCON_RENG_EXECUTE, save->gmcon_reng_execute);
  1066. }
  1067. static void cik_gpu_pci_config_reset(struct amdgpu_device *adev)
  1068. {
  1069. struct kv_reset_save_regs kv_save = { 0 };
  1070. u32 i;
  1071. dev_info(adev->dev, "GPU pci config reset\n");
  1072. if (adev->flags & AMD_IS_APU)
  1073. kv_save_regs_for_reset(adev, &kv_save);
  1074. /* disable BM */
  1075. pci_clear_master(adev->pdev);
  1076. /* reset */
  1077. amdgpu_pci_config_reset(adev);
  1078. udelay(100);
  1079. /* wait for asic to come out of reset */
  1080. for (i = 0; i < adev->usec_timeout; i++) {
  1081. if (RREG32(mmCONFIG_MEMSIZE) != 0xffffffff)
  1082. break;
  1083. udelay(1);
  1084. }
  1085. /* does asic init need to be run first??? */
  1086. if (adev->flags & AMD_IS_APU)
  1087. kv_restore_regs_for_reset(adev, &kv_save);
  1088. }
  1089. static void cik_set_bios_scratch_engine_hung(struct amdgpu_device *adev, bool hung)
  1090. {
  1091. u32 tmp = RREG32(mmBIOS_SCRATCH_3);
  1092. if (hung)
  1093. tmp |= ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  1094. else
  1095. tmp &= ~ATOM_S3_ASIC_GUI_ENGINE_HUNG;
  1096. WREG32(mmBIOS_SCRATCH_3, tmp);
  1097. }
  1098. /**
  1099. * cik_asic_reset - soft reset GPU
  1100. *
  1101. * @adev: amdgpu_device pointer
  1102. *
  1103. * Look up which blocks are hung and attempt
  1104. * to reset them.
  1105. * Returns 0 for success.
  1106. */
  1107. static int cik_asic_reset(struct amdgpu_device *adev)
  1108. {
  1109. cik_set_bios_scratch_engine_hung(adev, true);
  1110. cik_gpu_pci_config_reset(adev);
  1111. cik_set_bios_scratch_engine_hung(adev, false);
  1112. return 0;
  1113. }
  1114. static int cik_set_uvd_clock(struct amdgpu_device *adev, u32 clock,
  1115. u32 cntl_reg, u32 status_reg)
  1116. {
  1117. int r, i;
  1118. struct atom_clock_dividers dividers;
  1119. uint32_t tmp;
  1120. r = amdgpu_atombios_get_clock_dividers(adev,
  1121. COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
  1122. clock, false, &dividers);
  1123. if (r)
  1124. return r;
  1125. tmp = RREG32_SMC(cntl_reg);
  1126. tmp &= ~(CG_DCLK_CNTL__DCLK_DIR_CNTL_EN_MASK |
  1127. CG_DCLK_CNTL__DCLK_DIVIDER_MASK);
  1128. tmp |= dividers.post_divider;
  1129. WREG32_SMC(cntl_reg, tmp);
  1130. for (i = 0; i < 100; i++) {
  1131. if (RREG32_SMC(status_reg) & CG_DCLK_STATUS__DCLK_STATUS_MASK)
  1132. break;
  1133. mdelay(10);
  1134. }
  1135. if (i == 100)
  1136. return -ETIMEDOUT;
  1137. return 0;
  1138. }
  1139. static int cik_set_uvd_clocks(struct amdgpu_device *adev, u32 vclk, u32 dclk)
  1140. {
  1141. int r = 0;
  1142. r = cik_set_uvd_clock(adev, vclk, ixCG_VCLK_CNTL, ixCG_VCLK_STATUS);
  1143. if (r)
  1144. return r;
  1145. r = cik_set_uvd_clock(adev, dclk, ixCG_DCLK_CNTL, ixCG_DCLK_STATUS);
  1146. return r;
  1147. }
  1148. static int cik_set_vce_clocks(struct amdgpu_device *adev, u32 evclk, u32 ecclk)
  1149. {
  1150. int r, i;
  1151. struct atom_clock_dividers dividers;
  1152. u32 tmp;
  1153. r = amdgpu_atombios_get_clock_dividers(adev,
  1154. COMPUTE_GPUCLK_INPUT_FLAG_DEFAULT_GPUCLK,
  1155. ecclk, false, &dividers);
  1156. if (r)
  1157. return r;
  1158. for (i = 0; i < 100; i++) {
  1159. if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
  1160. break;
  1161. mdelay(10);
  1162. }
  1163. if (i == 100)
  1164. return -ETIMEDOUT;
  1165. tmp = RREG32_SMC(ixCG_ECLK_CNTL);
  1166. tmp &= ~(CG_ECLK_CNTL__ECLK_DIR_CNTL_EN_MASK |
  1167. CG_ECLK_CNTL__ECLK_DIVIDER_MASK);
  1168. tmp |= dividers.post_divider;
  1169. WREG32_SMC(ixCG_ECLK_CNTL, tmp);
  1170. for (i = 0; i < 100; i++) {
  1171. if (RREG32_SMC(ixCG_ECLK_STATUS) & CG_ECLK_STATUS__ECLK_STATUS_MASK)
  1172. break;
  1173. mdelay(10);
  1174. }
  1175. if (i == 100)
  1176. return -ETIMEDOUT;
  1177. return 0;
  1178. }
  1179. static void cik_pcie_gen3_enable(struct amdgpu_device *adev)
  1180. {
  1181. struct pci_dev *root = adev->pdev->bus->self;
  1182. int bridge_pos, gpu_pos;
  1183. u32 speed_cntl, current_data_rate;
  1184. int i;
  1185. u16 tmp16;
  1186. if (pci_is_root_bus(adev->pdev->bus))
  1187. return;
  1188. if (amdgpu_pcie_gen2 == 0)
  1189. return;
  1190. if (adev->flags & AMD_IS_APU)
  1191. return;
  1192. if (!(adev->pm.pcie_gen_mask & (CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2 |
  1193. CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)))
  1194. return;
  1195. speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
  1196. current_data_rate = (speed_cntl & PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE_MASK) >>
  1197. PCIE_LC_SPEED_CNTL__LC_CURRENT_DATA_RATE__SHIFT;
  1198. if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) {
  1199. if (current_data_rate == 2) {
  1200. DRM_INFO("PCIE gen 3 link speeds already enabled\n");
  1201. return;
  1202. }
  1203. DRM_INFO("enabling PCIE gen 3 link speeds, disable with amdgpu.pcie_gen2=0\n");
  1204. } else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2) {
  1205. if (current_data_rate == 1) {
  1206. DRM_INFO("PCIE gen 2 link speeds already enabled\n");
  1207. return;
  1208. }
  1209. DRM_INFO("enabling PCIE gen 2 link speeds, disable with amdgpu.pcie_gen2=0\n");
  1210. }
  1211. bridge_pos = pci_pcie_cap(root);
  1212. if (!bridge_pos)
  1213. return;
  1214. gpu_pos = pci_pcie_cap(adev->pdev);
  1215. if (!gpu_pos)
  1216. return;
  1217. if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3) {
  1218. /* re-try equalization if gen3 is not already enabled */
  1219. if (current_data_rate != 2) {
  1220. u16 bridge_cfg, gpu_cfg;
  1221. u16 bridge_cfg2, gpu_cfg2;
  1222. u32 max_lw, current_lw, tmp;
  1223. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  1224. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  1225. tmp16 = bridge_cfg | PCI_EXP_LNKCTL_HAWD;
  1226. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  1227. tmp16 = gpu_cfg | PCI_EXP_LNKCTL_HAWD;
  1228. pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  1229. tmp = RREG32_PCIE(ixPCIE_LC_STATUS1);
  1230. max_lw = (tmp & PCIE_LC_STATUS1__LC_DETECTED_LINK_WIDTH_MASK) >>
  1231. PCIE_LC_STATUS1__LC_DETECTED_LINK_WIDTH__SHIFT;
  1232. current_lw = (tmp & PCIE_LC_STATUS1__LC_OPERATING_LINK_WIDTH_MASK)
  1233. >> PCIE_LC_STATUS1__LC_OPERATING_LINK_WIDTH__SHIFT;
  1234. if (current_lw < max_lw) {
  1235. tmp = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL);
  1236. if (tmp & PCIE_LC_LINK_WIDTH_CNTL__LC_RENEGOTIATION_SUPPORT_MASK) {
  1237. tmp &= ~(PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH_MASK |
  1238. PCIE_LC_LINK_WIDTH_CNTL__LC_UPCONFIGURE_DIS_MASK);
  1239. tmp |= (max_lw <<
  1240. PCIE_LC_LINK_WIDTH_CNTL__LC_LINK_WIDTH__SHIFT);
  1241. tmp |= PCIE_LC_LINK_WIDTH_CNTL__LC_UPCONFIGURE_SUPPORT_MASK |
  1242. PCIE_LC_LINK_WIDTH_CNTL__LC_RENEGOTIATE_EN_MASK |
  1243. PCIE_LC_LINK_WIDTH_CNTL__LC_RECONFIG_NOW_MASK;
  1244. WREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL, tmp);
  1245. }
  1246. }
  1247. for (i = 0; i < 10; i++) {
  1248. /* check status */
  1249. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_DEVSTA, &tmp16);
  1250. if (tmp16 & PCI_EXP_DEVSTA_TRPND)
  1251. break;
  1252. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &bridge_cfg);
  1253. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &gpu_cfg);
  1254. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &bridge_cfg2);
  1255. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &gpu_cfg2);
  1256. tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
  1257. tmp |= PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK;
  1258. WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
  1259. tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
  1260. tmp |= PCIE_LC_CNTL4__LC_REDO_EQ_MASK;
  1261. WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
  1262. mdelay(100);
  1263. /* linkctl */
  1264. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL, &tmp16);
  1265. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  1266. tmp16 |= (bridge_cfg & PCI_EXP_LNKCTL_HAWD);
  1267. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL, tmp16);
  1268. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, &tmp16);
  1269. tmp16 &= ~PCI_EXP_LNKCTL_HAWD;
  1270. tmp16 |= (gpu_cfg & PCI_EXP_LNKCTL_HAWD);
  1271. pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL, tmp16);
  1272. /* linkctl2 */
  1273. pci_read_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, &tmp16);
  1274. tmp16 &= ~((1 << 4) | (7 << 9));
  1275. tmp16 |= (bridge_cfg2 & ((1 << 4) | (7 << 9)));
  1276. pci_write_config_word(root, bridge_pos + PCI_EXP_LNKCTL2, tmp16);
  1277. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  1278. tmp16 &= ~((1 << 4) | (7 << 9));
  1279. tmp16 |= (gpu_cfg2 & ((1 << 4) | (7 << 9)));
  1280. pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  1281. tmp = RREG32_PCIE(ixPCIE_LC_CNTL4);
  1282. tmp &= ~PCIE_LC_CNTL4__LC_SET_QUIESCE_MASK;
  1283. WREG32_PCIE(ixPCIE_LC_CNTL4, tmp);
  1284. }
  1285. }
  1286. }
  1287. /* set the link speed */
  1288. speed_cntl |= PCIE_LC_SPEED_CNTL__LC_FORCE_EN_SW_SPEED_CHANGE_MASK |
  1289. PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_HW_SPEED_CHANGE_MASK;
  1290. speed_cntl &= ~PCIE_LC_SPEED_CNTL__LC_FORCE_DIS_SW_SPEED_CHANGE_MASK;
  1291. WREG32_PCIE(ixPCIE_LC_SPEED_CNTL, speed_cntl);
  1292. pci_read_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, &tmp16);
  1293. tmp16 &= ~0xf;
  1294. if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN3)
  1295. tmp16 |= 3; /* gen3 */
  1296. else if (adev->pm.pcie_gen_mask & CAIL_PCIE_LINK_SPEED_SUPPORT_GEN2)
  1297. tmp16 |= 2; /* gen2 */
  1298. else
  1299. tmp16 |= 1; /* gen1 */
  1300. pci_write_config_word(adev->pdev, gpu_pos + PCI_EXP_LNKCTL2, tmp16);
  1301. speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
  1302. speed_cntl |= PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK;
  1303. WREG32_PCIE(ixPCIE_LC_SPEED_CNTL, speed_cntl);
  1304. for (i = 0; i < adev->usec_timeout; i++) {
  1305. speed_cntl = RREG32_PCIE(ixPCIE_LC_SPEED_CNTL);
  1306. if ((speed_cntl & PCIE_LC_SPEED_CNTL__LC_INITIATE_LINK_SPEED_CHANGE_MASK) == 0)
  1307. break;
  1308. udelay(1);
  1309. }
  1310. }
  1311. static void cik_program_aspm(struct amdgpu_device *adev)
  1312. {
  1313. u32 data, orig;
  1314. bool disable_l0s = false, disable_l1 = false, disable_plloff_in_l1 = false;
  1315. bool disable_clkreq = false;
  1316. if (amdgpu_aspm == 0)
  1317. return;
  1318. if (pci_is_root_bus(adev->pdev->bus))
  1319. return;
  1320. /* XXX double check APUs */
  1321. if (adev->flags & AMD_IS_APU)
  1322. return;
  1323. orig = data = RREG32_PCIE(ixPCIE_LC_N_FTS_CNTL);
  1324. data &= ~PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS_MASK;
  1325. data |= (0x24 << PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS__SHIFT) |
  1326. PCIE_LC_N_FTS_CNTL__LC_XMIT_N_FTS_OVERRIDE_EN_MASK;
  1327. if (orig != data)
  1328. WREG32_PCIE(ixPCIE_LC_N_FTS_CNTL, data);
  1329. orig = data = RREG32_PCIE(ixPCIE_LC_CNTL3);
  1330. data |= PCIE_LC_CNTL3__LC_GO_TO_RECOVERY_MASK;
  1331. if (orig != data)
  1332. WREG32_PCIE(ixPCIE_LC_CNTL3, data);
  1333. orig = data = RREG32_PCIE(ixPCIE_P_CNTL);
  1334. data |= PCIE_P_CNTL__P_IGNORE_EDB_ERR_MASK;
  1335. if (orig != data)
  1336. WREG32_PCIE(ixPCIE_P_CNTL, data);
  1337. orig = data = RREG32_PCIE(ixPCIE_LC_CNTL);
  1338. data &= ~(PCIE_LC_CNTL__LC_L0S_INACTIVITY_MASK |
  1339. PCIE_LC_CNTL__LC_L1_INACTIVITY_MASK);
  1340. data |= PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
  1341. if (!disable_l0s)
  1342. data |= (7 << PCIE_LC_CNTL__LC_L0S_INACTIVITY__SHIFT);
  1343. if (!disable_l1) {
  1344. data |= (7 << PCIE_LC_CNTL__LC_L1_INACTIVITY__SHIFT);
  1345. data &= ~PCIE_LC_CNTL__LC_PMI_TO_L1_DIS_MASK;
  1346. if (orig != data)
  1347. WREG32_PCIE(ixPCIE_LC_CNTL, data);
  1348. if (!disable_plloff_in_l1) {
  1349. bool clk_req_support;
  1350. orig = data = RREG32_PCIE(ixPB0_PIF_PWRDOWN_0);
  1351. data &= ~(PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0_MASK |
  1352. PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0_MASK);
  1353. data |= (7 << PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0__SHIFT) |
  1354. (7 << PB0_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0__SHIFT);
  1355. if (orig != data)
  1356. WREG32_PCIE(ixPB0_PIF_PWRDOWN_0, data);
  1357. orig = data = RREG32_PCIE(ixPB0_PIF_PWRDOWN_1);
  1358. data &= ~(PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1_MASK |
  1359. PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1_MASK);
  1360. data |= (7 << PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1__SHIFT) |
  1361. (7 << PB0_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1__SHIFT);
  1362. if (orig != data)
  1363. WREG32_PCIE(ixPB0_PIF_PWRDOWN_1, data);
  1364. orig = data = RREG32_PCIE(ixPB1_PIF_PWRDOWN_0);
  1365. data &= ~(PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0_MASK |
  1366. PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0_MASK);
  1367. data |= (7 << PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_OFF_0__SHIFT) |
  1368. (7 << PB1_PIF_PWRDOWN_0__PLL_POWER_STATE_IN_TXS2_0__SHIFT);
  1369. if (orig != data)
  1370. WREG32_PCIE(ixPB1_PIF_PWRDOWN_0, data);
  1371. orig = data = RREG32_PCIE(ixPB1_PIF_PWRDOWN_1);
  1372. data &= ~(PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1_MASK |
  1373. PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1_MASK);
  1374. data |= (7 << PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_OFF_1__SHIFT) |
  1375. (7 << PB1_PIF_PWRDOWN_1__PLL_POWER_STATE_IN_TXS2_1__SHIFT);
  1376. if (orig != data)
  1377. WREG32_PCIE(ixPB1_PIF_PWRDOWN_1, data);
  1378. orig = data = RREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL);
  1379. data &= ~PCIE_LC_LINK_WIDTH_CNTL__LC_DYN_LANES_PWR_STATE_MASK;
  1380. data |= ~(3 << PCIE_LC_LINK_WIDTH_CNTL__LC_DYN_LANES_PWR_STATE__SHIFT);
  1381. if (orig != data)
  1382. WREG32_PCIE(ixPCIE_LC_LINK_WIDTH_CNTL, data);
  1383. if (!disable_clkreq) {
  1384. struct pci_dev *root = adev->pdev->bus->self;
  1385. u32 lnkcap;
  1386. clk_req_support = false;
  1387. pcie_capability_read_dword(root, PCI_EXP_LNKCAP, &lnkcap);
  1388. if (lnkcap & PCI_EXP_LNKCAP_CLKPM)
  1389. clk_req_support = true;
  1390. } else {
  1391. clk_req_support = false;
  1392. }
  1393. if (clk_req_support) {
  1394. orig = data = RREG32_PCIE(ixPCIE_LC_CNTL2);
  1395. data |= PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L1_MASK |
  1396. PCIE_LC_CNTL2__LC_ALLOW_PDWN_IN_L23_MASK;
  1397. if (orig != data)
  1398. WREG32_PCIE(ixPCIE_LC_CNTL2, data);
  1399. orig = data = RREG32_SMC(ixTHM_CLK_CNTL);
  1400. data &= ~(THM_CLK_CNTL__CMON_CLK_SEL_MASK |
  1401. THM_CLK_CNTL__TMON_CLK_SEL_MASK);
  1402. data |= (1 << THM_CLK_CNTL__CMON_CLK_SEL__SHIFT) |
  1403. (1 << THM_CLK_CNTL__TMON_CLK_SEL__SHIFT);
  1404. if (orig != data)
  1405. WREG32_SMC(ixTHM_CLK_CNTL, data);
  1406. orig = data = RREG32_SMC(ixMISC_CLK_CTRL);
  1407. data &= ~(MISC_CLK_CTRL__DEEP_SLEEP_CLK_SEL_MASK |
  1408. MISC_CLK_CTRL__ZCLK_SEL_MASK);
  1409. data |= (1 << MISC_CLK_CTRL__DEEP_SLEEP_CLK_SEL__SHIFT) |
  1410. (1 << MISC_CLK_CTRL__ZCLK_SEL__SHIFT);
  1411. if (orig != data)
  1412. WREG32_SMC(ixMISC_CLK_CTRL, data);
  1413. orig = data = RREG32_SMC(ixCG_CLKPIN_CNTL);
  1414. data &= ~CG_CLKPIN_CNTL__BCLK_AS_XCLK_MASK;
  1415. if (orig != data)
  1416. WREG32_SMC(ixCG_CLKPIN_CNTL, data);
  1417. orig = data = RREG32_SMC(ixCG_CLKPIN_CNTL_2);
  1418. data &= ~CG_CLKPIN_CNTL_2__FORCE_BIF_REFCLK_EN_MASK;
  1419. if (orig != data)
  1420. WREG32_SMC(ixCG_CLKPIN_CNTL_2, data);
  1421. orig = data = RREG32_SMC(ixMPLL_BYPASSCLK_SEL);
  1422. data &= ~MPLL_BYPASSCLK_SEL__MPLL_CLKOUT_SEL_MASK;
  1423. data |= (4 << MPLL_BYPASSCLK_SEL__MPLL_CLKOUT_SEL__SHIFT);
  1424. if (orig != data)
  1425. WREG32_SMC(ixMPLL_BYPASSCLK_SEL, data);
  1426. }
  1427. }
  1428. } else {
  1429. if (orig != data)
  1430. WREG32_PCIE(ixPCIE_LC_CNTL, data);
  1431. }
  1432. orig = data = RREG32_PCIE(ixPCIE_CNTL2);
  1433. data |= PCIE_CNTL2__SLV_MEM_LS_EN_MASK |
  1434. PCIE_CNTL2__MST_MEM_LS_EN_MASK |
  1435. PCIE_CNTL2__REPLAY_MEM_LS_EN_MASK;
  1436. if (orig != data)
  1437. WREG32_PCIE(ixPCIE_CNTL2, data);
  1438. if (!disable_l0s) {
  1439. data = RREG32_PCIE(ixPCIE_LC_N_FTS_CNTL);
  1440. if ((data & PCIE_LC_N_FTS_CNTL__LC_N_FTS_MASK) ==
  1441. PCIE_LC_N_FTS_CNTL__LC_N_FTS_MASK) {
  1442. data = RREG32_PCIE(ixPCIE_LC_STATUS1);
  1443. if ((data & PCIE_LC_STATUS1__LC_REVERSE_XMIT_MASK) &&
  1444. (data & PCIE_LC_STATUS1__LC_REVERSE_RCVR_MASK)) {
  1445. orig = data = RREG32_PCIE(ixPCIE_LC_CNTL);
  1446. data &= ~PCIE_LC_CNTL__LC_L0S_INACTIVITY_MASK;
  1447. if (orig != data)
  1448. WREG32_PCIE(ixPCIE_LC_CNTL, data);
  1449. }
  1450. }
  1451. }
  1452. }
  1453. static uint32_t cik_get_rev_id(struct amdgpu_device *adev)
  1454. {
  1455. return (RREG32(mmCC_DRM_ID_STRAPS) & CC_DRM_ID_STRAPS__ATI_REV_ID_MASK)
  1456. >> CC_DRM_ID_STRAPS__ATI_REV_ID__SHIFT;
  1457. }
  1458. static const struct amdgpu_ip_block_version bonaire_ip_blocks[] =
  1459. {
  1460. /* ORDER MATTERS! */
  1461. {
  1462. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1463. .major = 1,
  1464. .minor = 0,
  1465. .rev = 0,
  1466. .funcs = &cik_common_ip_funcs,
  1467. },
  1468. {
  1469. .type = AMD_IP_BLOCK_TYPE_GMC,
  1470. .major = 7,
  1471. .minor = 0,
  1472. .rev = 0,
  1473. .funcs = &gmc_v7_0_ip_funcs,
  1474. },
  1475. {
  1476. .type = AMD_IP_BLOCK_TYPE_IH,
  1477. .major = 2,
  1478. .minor = 0,
  1479. .rev = 0,
  1480. .funcs = &cik_ih_ip_funcs,
  1481. },
  1482. {
  1483. .type = AMD_IP_BLOCK_TYPE_SMC,
  1484. .major = 7,
  1485. .minor = 0,
  1486. .rev = 0,
  1487. .funcs = &amdgpu_pp_ip_funcs,
  1488. },
  1489. {
  1490. .type = AMD_IP_BLOCK_TYPE_DCE,
  1491. .major = 8,
  1492. .minor = 2,
  1493. .rev = 0,
  1494. .funcs = &dce_v8_0_ip_funcs,
  1495. },
  1496. {
  1497. .type = AMD_IP_BLOCK_TYPE_GFX,
  1498. .major = 7,
  1499. .minor = 2,
  1500. .rev = 0,
  1501. .funcs = &gfx_v7_0_ip_funcs,
  1502. },
  1503. {
  1504. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1505. .major = 2,
  1506. .minor = 0,
  1507. .rev = 0,
  1508. .funcs = &cik_sdma_ip_funcs,
  1509. },
  1510. {
  1511. .type = AMD_IP_BLOCK_TYPE_UVD,
  1512. .major = 4,
  1513. .minor = 2,
  1514. .rev = 0,
  1515. .funcs = &uvd_v4_2_ip_funcs,
  1516. },
  1517. {
  1518. .type = AMD_IP_BLOCK_TYPE_VCE,
  1519. .major = 2,
  1520. .minor = 0,
  1521. .rev = 0,
  1522. .funcs = &vce_v2_0_ip_funcs,
  1523. },
  1524. };
  1525. static const struct amdgpu_ip_block_version hawaii_ip_blocks[] =
  1526. {
  1527. /* ORDER MATTERS! */
  1528. {
  1529. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1530. .major = 1,
  1531. .minor = 0,
  1532. .rev = 0,
  1533. .funcs = &cik_common_ip_funcs,
  1534. },
  1535. {
  1536. .type = AMD_IP_BLOCK_TYPE_GMC,
  1537. .major = 7,
  1538. .minor = 0,
  1539. .rev = 0,
  1540. .funcs = &gmc_v7_0_ip_funcs,
  1541. },
  1542. {
  1543. .type = AMD_IP_BLOCK_TYPE_IH,
  1544. .major = 2,
  1545. .minor = 0,
  1546. .rev = 0,
  1547. .funcs = &cik_ih_ip_funcs,
  1548. },
  1549. {
  1550. .type = AMD_IP_BLOCK_TYPE_SMC,
  1551. .major = 7,
  1552. .minor = 0,
  1553. .rev = 0,
  1554. .funcs = &amdgpu_pp_ip_funcs,
  1555. },
  1556. {
  1557. .type = AMD_IP_BLOCK_TYPE_DCE,
  1558. .major = 8,
  1559. .minor = 5,
  1560. .rev = 0,
  1561. .funcs = &dce_v8_0_ip_funcs,
  1562. },
  1563. {
  1564. .type = AMD_IP_BLOCK_TYPE_GFX,
  1565. .major = 7,
  1566. .minor = 3,
  1567. .rev = 0,
  1568. .funcs = &gfx_v7_0_ip_funcs,
  1569. },
  1570. {
  1571. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1572. .major = 2,
  1573. .minor = 0,
  1574. .rev = 0,
  1575. .funcs = &cik_sdma_ip_funcs,
  1576. },
  1577. {
  1578. .type = AMD_IP_BLOCK_TYPE_UVD,
  1579. .major = 4,
  1580. .minor = 2,
  1581. .rev = 0,
  1582. .funcs = &uvd_v4_2_ip_funcs,
  1583. },
  1584. {
  1585. .type = AMD_IP_BLOCK_TYPE_VCE,
  1586. .major = 2,
  1587. .minor = 0,
  1588. .rev = 0,
  1589. .funcs = &vce_v2_0_ip_funcs,
  1590. },
  1591. };
  1592. static const struct amdgpu_ip_block_version kabini_ip_blocks[] =
  1593. {
  1594. /* ORDER MATTERS! */
  1595. {
  1596. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1597. .major = 1,
  1598. .minor = 0,
  1599. .rev = 0,
  1600. .funcs = &cik_common_ip_funcs,
  1601. },
  1602. {
  1603. .type = AMD_IP_BLOCK_TYPE_GMC,
  1604. .major = 7,
  1605. .minor = 0,
  1606. .rev = 0,
  1607. .funcs = &gmc_v7_0_ip_funcs,
  1608. },
  1609. {
  1610. .type = AMD_IP_BLOCK_TYPE_IH,
  1611. .major = 2,
  1612. .minor = 0,
  1613. .rev = 0,
  1614. .funcs = &cik_ih_ip_funcs,
  1615. },
  1616. {
  1617. .type = AMD_IP_BLOCK_TYPE_SMC,
  1618. .major = 7,
  1619. .minor = 0,
  1620. .rev = 0,
  1621. .funcs = &amdgpu_pp_ip_funcs,
  1622. },
  1623. {
  1624. .type = AMD_IP_BLOCK_TYPE_DCE,
  1625. .major = 8,
  1626. .minor = 3,
  1627. .rev = 0,
  1628. .funcs = &dce_v8_0_ip_funcs,
  1629. },
  1630. {
  1631. .type = AMD_IP_BLOCK_TYPE_GFX,
  1632. .major = 7,
  1633. .minor = 2,
  1634. .rev = 0,
  1635. .funcs = &gfx_v7_0_ip_funcs,
  1636. },
  1637. {
  1638. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1639. .major = 2,
  1640. .minor = 0,
  1641. .rev = 0,
  1642. .funcs = &cik_sdma_ip_funcs,
  1643. },
  1644. {
  1645. .type = AMD_IP_BLOCK_TYPE_UVD,
  1646. .major = 4,
  1647. .minor = 2,
  1648. .rev = 0,
  1649. .funcs = &uvd_v4_2_ip_funcs,
  1650. },
  1651. {
  1652. .type = AMD_IP_BLOCK_TYPE_VCE,
  1653. .major = 2,
  1654. .minor = 0,
  1655. .rev = 0,
  1656. .funcs = &vce_v2_0_ip_funcs,
  1657. },
  1658. };
  1659. static const struct amdgpu_ip_block_version mullins_ip_blocks[] =
  1660. {
  1661. /* ORDER MATTERS! */
  1662. {
  1663. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1664. .major = 1,
  1665. .minor = 0,
  1666. .rev = 0,
  1667. .funcs = &cik_common_ip_funcs,
  1668. },
  1669. {
  1670. .type = AMD_IP_BLOCK_TYPE_GMC,
  1671. .major = 7,
  1672. .minor = 0,
  1673. .rev = 0,
  1674. .funcs = &gmc_v7_0_ip_funcs,
  1675. },
  1676. {
  1677. .type = AMD_IP_BLOCK_TYPE_IH,
  1678. .major = 2,
  1679. .minor = 0,
  1680. .rev = 0,
  1681. .funcs = &cik_ih_ip_funcs,
  1682. },
  1683. {
  1684. .type = AMD_IP_BLOCK_TYPE_SMC,
  1685. .major = 7,
  1686. .minor = 0,
  1687. .rev = 0,
  1688. .funcs = &amdgpu_pp_ip_funcs,
  1689. },
  1690. {
  1691. .type = AMD_IP_BLOCK_TYPE_DCE,
  1692. .major = 8,
  1693. .minor = 3,
  1694. .rev = 0,
  1695. .funcs = &dce_v8_0_ip_funcs,
  1696. },
  1697. {
  1698. .type = AMD_IP_BLOCK_TYPE_GFX,
  1699. .major = 7,
  1700. .minor = 2,
  1701. .rev = 0,
  1702. .funcs = &gfx_v7_0_ip_funcs,
  1703. },
  1704. {
  1705. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1706. .major = 2,
  1707. .minor = 0,
  1708. .rev = 0,
  1709. .funcs = &cik_sdma_ip_funcs,
  1710. },
  1711. {
  1712. .type = AMD_IP_BLOCK_TYPE_UVD,
  1713. .major = 4,
  1714. .minor = 2,
  1715. .rev = 0,
  1716. .funcs = &uvd_v4_2_ip_funcs,
  1717. },
  1718. {
  1719. .type = AMD_IP_BLOCK_TYPE_VCE,
  1720. .major = 2,
  1721. .minor = 0,
  1722. .rev = 0,
  1723. .funcs = &vce_v2_0_ip_funcs,
  1724. },
  1725. };
  1726. static const struct amdgpu_ip_block_version kaveri_ip_blocks[] =
  1727. {
  1728. /* ORDER MATTERS! */
  1729. {
  1730. .type = AMD_IP_BLOCK_TYPE_COMMON,
  1731. .major = 1,
  1732. .minor = 0,
  1733. .rev = 0,
  1734. .funcs = &cik_common_ip_funcs,
  1735. },
  1736. {
  1737. .type = AMD_IP_BLOCK_TYPE_GMC,
  1738. .major = 7,
  1739. .minor = 0,
  1740. .rev = 0,
  1741. .funcs = &gmc_v7_0_ip_funcs,
  1742. },
  1743. {
  1744. .type = AMD_IP_BLOCK_TYPE_IH,
  1745. .major = 2,
  1746. .minor = 0,
  1747. .rev = 0,
  1748. .funcs = &cik_ih_ip_funcs,
  1749. },
  1750. {
  1751. .type = AMD_IP_BLOCK_TYPE_SMC,
  1752. .major = 7,
  1753. .minor = 0,
  1754. .rev = 0,
  1755. .funcs = &amdgpu_pp_ip_funcs,
  1756. },
  1757. {
  1758. .type = AMD_IP_BLOCK_TYPE_DCE,
  1759. .major = 8,
  1760. .minor = 1,
  1761. .rev = 0,
  1762. .funcs = &dce_v8_0_ip_funcs,
  1763. },
  1764. {
  1765. .type = AMD_IP_BLOCK_TYPE_GFX,
  1766. .major = 7,
  1767. .minor = 1,
  1768. .rev = 0,
  1769. .funcs = &gfx_v7_0_ip_funcs,
  1770. },
  1771. {
  1772. .type = AMD_IP_BLOCK_TYPE_SDMA,
  1773. .major = 2,
  1774. .minor = 0,
  1775. .rev = 0,
  1776. .funcs = &cik_sdma_ip_funcs,
  1777. },
  1778. {
  1779. .type = AMD_IP_BLOCK_TYPE_UVD,
  1780. .major = 4,
  1781. .minor = 2,
  1782. .rev = 0,
  1783. .funcs = &uvd_v4_2_ip_funcs,
  1784. },
  1785. {
  1786. .type = AMD_IP_BLOCK_TYPE_VCE,
  1787. .major = 2,
  1788. .minor = 0,
  1789. .rev = 0,
  1790. .funcs = &vce_v2_0_ip_funcs,
  1791. },
  1792. };
  1793. int cik_set_ip_blocks(struct amdgpu_device *adev)
  1794. {
  1795. switch (adev->asic_type) {
  1796. case CHIP_BONAIRE:
  1797. adev->ip_blocks = bonaire_ip_blocks;
  1798. adev->num_ip_blocks = ARRAY_SIZE(bonaire_ip_blocks);
  1799. break;
  1800. case CHIP_HAWAII:
  1801. adev->ip_blocks = hawaii_ip_blocks;
  1802. adev->num_ip_blocks = ARRAY_SIZE(hawaii_ip_blocks);
  1803. break;
  1804. case CHIP_KAVERI:
  1805. adev->ip_blocks = kaveri_ip_blocks;
  1806. adev->num_ip_blocks = ARRAY_SIZE(kaveri_ip_blocks);
  1807. break;
  1808. case CHIP_KABINI:
  1809. adev->ip_blocks = kabini_ip_blocks;
  1810. adev->num_ip_blocks = ARRAY_SIZE(kabini_ip_blocks);
  1811. break;
  1812. case CHIP_MULLINS:
  1813. adev->ip_blocks = mullins_ip_blocks;
  1814. adev->num_ip_blocks = ARRAY_SIZE(mullins_ip_blocks);
  1815. break;
  1816. default:
  1817. /* FIXME: not supported yet */
  1818. return -EINVAL;
  1819. }
  1820. return 0;
  1821. }
  1822. static const struct amdgpu_asic_funcs cik_asic_funcs =
  1823. {
  1824. .read_disabled_bios = &cik_read_disabled_bios,
  1825. .read_bios_from_rom = &cik_read_bios_from_rom,
  1826. .read_register = &cik_read_register,
  1827. .reset = &cik_asic_reset,
  1828. .set_vga_state = &cik_vga_set_state,
  1829. .get_xclk = &cik_get_xclk,
  1830. .set_uvd_clocks = &cik_set_uvd_clocks,
  1831. .set_vce_clocks = &cik_set_vce_clocks,
  1832. .get_virtual_caps = &cik_get_virtual_caps,
  1833. /* these should be moved to their own ip modules */
  1834. .get_gpu_clock_counter = &gfx_v7_0_get_gpu_clock_counter,
  1835. .wait_for_mc_idle = &gmc_v7_0_mc_wait_for_idle,
  1836. };
  1837. static int cik_common_early_init(void *handle)
  1838. {
  1839. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1840. adev->smc_rreg = &cik_smc_rreg;
  1841. adev->smc_wreg = &cik_smc_wreg;
  1842. adev->pcie_rreg = &cik_pcie_rreg;
  1843. adev->pcie_wreg = &cik_pcie_wreg;
  1844. adev->uvd_ctx_rreg = &cik_uvd_ctx_rreg;
  1845. adev->uvd_ctx_wreg = &cik_uvd_ctx_wreg;
  1846. adev->didt_rreg = &cik_didt_rreg;
  1847. adev->didt_wreg = &cik_didt_wreg;
  1848. adev->asic_funcs = &cik_asic_funcs;
  1849. adev->rev_id = cik_get_rev_id(adev);
  1850. adev->external_rev_id = 0xFF;
  1851. switch (adev->asic_type) {
  1852. case CHIP_BONAIRE:
  1853. adev->cg_flags =
  1854. AMD_CG_SUPPORT_GFX_MGCG |
  1855. AMD_CG_SUPPORT_GFX_MGLS |
  1856. /*AMD_CG_SUPPORT_GFX_CGCG |*/
  1857. AMD_CG_SUPPORT_GFX_CGLS |
  1858. AMD_CG_SUPPORT_GFX_CGTS |
  1859. AMD_CG_SUPPORT_GFX_CGTS_LS |
  1860. AMD_CG_SUPPORT_GFX_CP_LS |
  1861. AMD_CG_SUPPORT_MC_LS |
  1862. AMD_CG_SUPPORT_MC_MGCG |
  1863. AMD_CG_SUPPORT_SDMA_MGCG |
  1864. AMD_CG_SUPPORT_SDMA_LS |
  1865. AMD_CG_SUPPORT_BIF_LS |
  1866. AMD_CG_SUPPORT_VCE_MGCG |
  1867. AMD_CG_SUPPORT_UVD_MGCG |
  1868. AMD_CG_SUPPORT_HDP_LS |
  1869. AMD_CG_SUPPORT_HDP_MGCG;
  1870. adev->pg_flags = 0;
  1871. adev->external_rev_id = adev->rev_id + 0x14;
  1872. break;
  1873. case CHIP_HAWAII:
  1874. adev->cg_flags =
  1875. AMD_CG_SUPPORT_GFX_MGCG |
  1876. AMD_CG_SUPPORT_GFX_MGLS |
  1877. /*AMD_CG_SUPPORT_GFX_CGCG |*/
  1878. AMD_CG_SUPPORT_GFX_CGLS |
  1879. AMD_CG_SUPPORT_GFX_CGTS |
  1880. AMD_CG_SUPPORT_GFX_CP_LS |
  1881. AMD_CG_SUPPORT_MC_LS |
  1882. AMD_CG_SUPPORT_MC_MGCG |
  1883. AMD_CG_SUPPORT_SDMA_MGCG |
  1884. AMD_CG_SUPPORT_SDMA_LS |
  1885. AMD_CG_SUPPORT_BIF_LS |
  1886. AMD_CG_SUPPORT_VCE_MGCG |
  1887. AMD_CG_SUPPORT_UVD_MGCG |
  1888. AMD_CG_SUPPORT_HDP_LS |
  1889. AMD_CG_SUPPORT_HDP_MGCG;
  1890. adev->pg_flags = 0;
  1891. adev->external_rev_id = 0x28;
  1892. break;
  1893. case CHIP_KAVERI:
  1894. adev->cg_flags =
  1895. AMD_CG_SUPPORT_GFX_MGCG |
  1896. AMD_CG_SUPPORT_GFX_MGLS |
  1897. /*AMD_CG_SUPPORT_GFX_CGCG |*/
  1898. AMD_CG_SUPPORT_GFX_CGLS |
  1899. AMD_CG_SUPPORT_GFX_CGTS |
  1900. AMD_CG_SUPPORT_GFX_CGTS_LS |
  1901. AMD_CG_SUPPORT_GFX_CP_LS |
  1902. AMD_CG_SUPPORT_SDMA_MGCG |
  1903. AMD_CG_SUPPORT_SDMA_LS |
  1904. AMD_CG_SUPPORT_BIF_LS |
  1905. AMD_CG_SUPPORT_VCE_MGCG |
  1906. AMD_CG_SUPPORT_UVD_MGCG |
  1907. AMD_CG_SUPPORT_HDP_LS |
  1908. AMD_CG_SUPPORT_HDP_MGCG;
  1909. adev->pg_flags =
  1910. /*AMD_PG_SUPPORT_GFX_PG |
  1911. AMD_PG_SUPPORT_GFX_SMG |
  1912. AMD_PG_SUPPORT_GFX_DMG |*/
  1913. AMD_PG_SUPPORT_UVD |
  1914. /*AMD_PG_SUPPORT_VCE |
  1915. AMD_PG_SUPPORT_CP |
  1916. AMD_PG_SUPPORT_GDS |
  1917. AMD_PG_SUPPORT_RLC_SMU_HS |
  1918. AMD_PG_SUPPORT_ACP |
  1919. AMD_PG_SUPPORT_SAMU |*/
  1920. 0;
  1921. if (adev->pdev->device == 0x1312 ||
  1922. adev->pdev->device == 0x1316 ||
  1923. adev->pdev->device == 0x1317)
  1924. adev->external_rev_id = 0x41;
  1925. else
  1926. adev->external_rev_id = 0x1;
  1927. break;
  1928. case CHIP_KABINI:
  1929. case CHIP_MULLINS:
  1930. adev->cg_flags =
  1931. AMD_CG_SUPPORT_GFX_MGCG |
  1932. AMD_CG_SUPPORT_GFX_MGLS |
  1933. /*AMD_CG_SUPPORT_GFX_CGCG |*/
  1934. AMD_CG_SUPPORT_GFX_CGLS |
  1935. AMD_CG_SUPPORT_GFX_CGTS |
  1936. AMD_CG_SUPPORT_GFX_CGTS_LS |
  1937. AMD_CG_SUPPORT_GFX_CP_LS |
  1938. AMD_CG_SUPPORT_SDMA_MGCG |
  1939. AMD_CG_SUPPORT_SDMA_LS |
  1940. AMD_CG_SUPPORT_BIF_LS |
  1941. AMD_CG_SUPPORT_VCE_MGCG |
  1942. AMD_CG_SUPPORT_UVD_MGCG |
  1943. AMD_CG_SUPPORT_HDP_LS |
  1944. AMD_CG_SUPPORT_HDP_MGCG;
  1945. adev->pg_flags =
  1946. /*AMD_PG_SUPPORT_GFX_PG |
  1947. AMD_PG_SUPPORT_GFX_SMG | */
  1948. AMD_PG_SUPPORT_UVD |
  1949. /*AMD_PG_SUPPORT_VCE |
  1950. AMD_PG_SUPPORT_CP |
  1951. AMD_PG_SUPPORT_GDS |
  1952. AMD_PG_SUPPORT_RLC_SMU_HS |
  1953. AMD_PG_SUPPORT_SAMU |*/
  1954. 0;
  1955. if (adev->asic_type == CHIP_KABINI) {
  1956. if (adev->rev_id == 0)
  1957. adev->external_rev_id = 0x81;
  1958. else if (adev->rev_id == 1)
  1959. adev->external_rev_id = 0x82;
  1960. else if (adev->rev_id == 2)
  1961. adev->external_rev_id = 0x85;
  1962. } else
  1963. adev->external_rev_id = adev->rev_id + 0xa1;
  1964. break;
  1965. default:
  1966. /* FIXME: not supported yet */
  1967. return -EINVAL;
  1968. }
  1969. amdgpu_get_pcie_info(adev);
  1970. return 0;
  1971. }
  1972. static int cik_common_sw_init(void *handle)
  1973. {
  1974. return 0;
  1975. }
  1976. static int cik_common_sw_fini(void *handle)
  1977. {
  1978. return 0;
  1979. }
  1980. static int cik_common_hw_init(void *handle)
  1981. {
  1982. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1983. /* move the golden regs per IP block */
  1984. cik_init_golden_registers(adev);
  1985. /* enable pcie gen2/3 link */
  1986. cik_pcie_gen3_enable(adev);
  1987. /* enable aspm */
  1988. cik_program_aspm(adev);
  1989. return 0;
  1990. }
  1991. static int cik_common_hw_fini(void *handle)
  1992. {
  1993. return 0;
  1994. }
  1995. static int cik_common_suspend(void *handle)
  1996. {
  1997. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  1998. amdgpu_amdkfd_suspend(adev);
  1999. return cik_common_hw_fini(adev);
  2000. }
  2001. static int cik_common_resume(void *handle)
  2002. {
  2003. int r;
  2004. struct amdgpu_device *adev = (struct amdgpu_device *)handle;
  2005. r = cik_common_hw_init(adev);
  2006. if (r)
  2007. return r;
  2008. return amdgpu_amdkfd_resume(adev);
  2009. }
  2010. static bool cik_common_is_idle(void *handle)
  2011. {
  2012. return true;
  2013. }
  2014. static int cik_common_wait_for_idle(void *handle)
  2015. {
  2016. return 0;
  2017. }
  2018. static int cik_common_soft_reset(void *handle)
  2019. {
  2020. /* XXX hard reset?? */
  2021. return 0;
  2022. }
  2023. static int cik_common_set_clockgating_state(void *handle,
  2024. enum amd_clockgating_state state)
  2025. {
  2026. return 0;
  2027. }
  2028. static int cik_common_set_powergating_state(void *handle,
  2029. enum amd_powergating_state state)
  2030. {
  2031. return 0;
  2032. }
  2033. const struct amd_ip_funcs cik_common_ip_funcs = {
  2034. .name = "cik_common",
  2035. .early_init = cik_common_early_init,
  2036. .late_init = NULL,
  2037. .sw_init = cik_common_sw_init,
  2038. .sw_fini = cik_common_sw_fini,
  2039. .hw_init = cik_common_hw_init,
  2040. .hw_fini = cik_common_hw_fini,
  2041. .suspend = cik_common_suspend,
  2042. .resume = cik_common_resume,
  2043. .is_idle = cik_common_is_idle,
  2044. .wait_for_idle = cik_common_wait_for_idle,
  2045. .soft_reset = cik_common_soft_reset,
  2046. .set_clockgating_state = cik_common_set_clockgating_state,
  2047. .set_powergating_state = cik_common_set_powergating_state,
  2048. };