ni.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721
  1. /*
  2. * Copyright 2010 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/module.h>
  26. #include <linux/pci.h>
  27. #include <linux/slab.h>
  28. #include <drm/radeon_drm.h>
  29. #include "atom.h"
  30. #include "cayman_blit_shaders.h"
  31. #include "clearstate_cayman.h"
  32. #include "evergreen.h"
  33. #include "ni.h"
  34. #include "ni_reg.h"
  35. #include "nid.h"
  36. #include "radeon.h"
  37. #include "radeon_asic.h"
  38. #include "radeon_audio.h"
  39. #include "radeon_ucode.h"
  40. /*
  41. * Indirect registers accessor
  42. */
  43. u32 tn_smc_rreg(struct radeon_device *rdev, u32 reg)
  44. {
  45. unsigned long flags;
  46. u32 r;
  47. spin_lock_irqsave(&rdev->smc_idx_lock, flags);
  48. WREG32(TN_SMC_IND_INDEX_0, (reg));
  49. r = RREG32(TN_SMC_IND_DATA_0);
  50. spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
  51. return r;
  52. }
  53. void tn_smc_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  54. {
  55. unsigned long flags;
  56. spin_lock_irqsave(&rdev->smc_idx_lock, flags);
  57. WREG32(TN_SMC_IND_INDEX_0, (reg));
  58. WREG32(TN_SMC_IND_DATA_0, (v));
  59. spin_unlock_irqrestore(&rdev->smc_idx_lock, flags);
  60. }
  61. static const u32 tn_rlc_save_restore_register_list[] = {
  62. 0x98fc,
  63. 0x98f0,
  64. 0x9834,
  65. 0x9838,
  66. 0x9870,
  67. 0x9874,
  68. 0x8a14,
  69. 0x8b24,
  70. 0x8bcc,
  71. 0x8b10,
  72. 0x8c30,
  73. 0x8d00,
  74. 0x8d04,
  75. 0x8c00,
  76. 0x8c04,
  77. 0x8c10,
  78. 0x8c14,
  79. 0x8d8c,
  80. 0x8cf0,
  81. 0x8e38,
  82. 0x9508,
  83. 0x9688,
  84. 0x9608,
  85. 0x960c,
  86. 0x9610,
  87. 0x9614,
  88. 0x88c4,
  89. 0x8978,
  90. 0x88d4,
  91. 0x900c,
  92. 0x9100,
  93. 0x913c,
  94. 0x90e8,
  95. 0x9354,
  96. 0xa008,
  97. 0x98f8,
  98. 0x9148,
  99. 0x914c,
  100. 0x3f94,
  101. 0x98f4,
  102. 0x9b7c,
  103. 0x3f8c,
  104. 0x8950,
  105. 0x8954,
  106. 0x8a18,
  107. 0x8b28,
  108. 0x9144,
  109. 0x3f90,
  110. 0x915c,
  111. 0x9160,
  112. 0x9178,
  113. 0x917c,
  114. 0x9180,
  115. 0x918c,
  116. 0x9190,
  117. 0x9194,
  118. 0x9198,
  119. 0x919c,
  120. 0x91a8,
  121. 0x91ac,
  122. 0x91b0,
  123. 0x91b4,
  124. 0x91b8,
  125. 0x91c4,
  126. 0x91c8,
  127. 0x91cc,
  128. 0x91d0,
  129. 0x91d4,
  130. 0x91e0,
  131. 0x91e4,
  132. 0x91ec,
  133. 0x91f0,
  134. 0x91f4,
  135. 0x9200,
  136. 0x9204,
  137. 0x929c,
  138. 0x8030,
  139. 0x9150,
  140. 0x9a60,
  141. 0x920c,
  142. 0x9210,
  143. 0x9228,
  144. 0x922c,
  145. 0x9244,
  146. 0x9248,
  147. 0x91e8,
  148. 0x9294,
  149. 0x9208,
  150. 0x9224,
  151. 0x9240,
  152. 0x9220,
  153. 0x923c,
  154. 0x9258,
  155. 0x9744,
  156. 0xa200,
  157. 0xa204,
  158. 0xa208,
  159. 0xa20c,
  160. 0x8d58,
  161. 0x9030,
  162. 0x9034,
  163. 0x9038,
  164. 0x903c,
  165. 0x9040,
  166. 0x9654,
  167. 0x897c,
  168. 0xa210,
  169. 0xa214,
  170. 0x9868,
  171. 0xa02c,
  172. 0x9664,
  173. 0x9698,
  174. 0x949c,
  175. 0x8e10,
  176. 0x8e18,
  177. 0x8c50,
  178. 0x8c58,
  179. 0x8c60,
  180. 0x8c68,
  181. 0x89b4,
  182. 0x9830,
  183. 0x802c,
  184. };
  185. /* Firmware Names */
  186. MODULE_FIRMWARE("radeon/BARTS_pfp.bin");
  187. MODULE_FIRMWARE("radeon/BARTS_me.bin");
  188. MODULE_FIRMWARE("radeon/BARTS_mc.bin");
  189. MODULE_FIRMWARE("radeon/BARTS_smc.bin");
  190. MODULE_FIRMWARE("radeon/BTC_rlc.bin");
  191. MODULE_FIRMWARE("radeon/TURKS_pfp.bin");
  192. MODULE_FIRMWARE("radeon/TURKS_me.bin");
  193. MODULE_FIRMWARE("radeon/TURKS_mc.bin");
  194. MODULE_FIRMWARE("radeon/TURKS_smc.bin");
  195. MODULE_FIRMWARE("radeon/CAICOS_pfp.bin");
  196. MODULE_FIRMWARE("radeon/CAICOS_me.bin");
  197. MODULE_FIRMWARE("radeon/CAICOS_mc.bin");
  198. MODULE_FIRMWARE("radeon/CAICOS_smc.bin");
  199. MODULE_FIRMWARE("radeon/CAYMAN_pfp.bin");
  200. MODULE_FIRMWARE("radeon/CAYMAN_me.bin");
  201. MODULE_FIRMWARE("radeon/CAYMAN_mc.bin");
  202. MODULE_FIRMWARE("radeon/CAYMAN_rlc.bin");
  203. MODULE_FIRMWARE("radeon/CAYMAN_smc.bin");
  204. MODULE_FIRMWARE("radeon/ARUBA_pfp.bin");
  205. MODULE_FIRMWARE("radeon/ARUBA_me.bin");
  206. MODULE_FIRMWARE("radeon/ARUBA_rlc.bin");
  207. static const u32 cayman_golden_registers2[] = {
  208. 0x3e5c, 0xffffffff, 0x00000000,
  209. 0x3e48, 0xffffffff, 0x00000000,
  210. 0x3e4c, 0xffffffff, 0x00000000,
  211. 0x3e64, 0xffffffff, 0x00000000,
  212. 0x3e50, 0xffffffff, 0x00000000,
  213. 0x3e60, 0xffffffff, 0x00000000
  214. };
  215. static const u32 cayman_golden_registers[] = {
  216. 0x5eb4, 0xffffffff, 0x00000002,
  217. 0x5e78, 0x8f311ff1, 0x001000f0,
  218. 0x3f90, 0xffff0000, 0xff000000,
  219. 0x9148, 0xffff0000, 0xff000000,
  220. 0x3f94, 0xffff0000, 0xff000000,
  221. 0x914c, 0xffff0000, 0xff000000,
  222. 0xc78, 0x00000080, 0x00000080,
  223. 0xbd4, 0x70073777, 0x00011003,
  224. 0xd02c, 0xbfffff1f, 0x08421000,
  225. 0xd0b8, 0x73773777, 0x02011003,
  226. 0x5bc0, 0x00200000, 0x50100000,
  227. 0x98f8, 0x33773777, 0x02011003,
  228. 0x98fc, 0xffffffff, 0x76541032,
  229. 0x7030, 0x31000311, 0x00000011,
  230. 0x2f48, 0x33773777, 0x42010001,
  231. 0x6b28, 0x00000010, 0x00000012,
  232. 0x7728, 0x00000010, 0x00000012,
  233. 0x10328, 0x00000010, 0x00000012,
  234. 0x10f28, 0x00000010, 0x00000012,
  235. 0x11b28, 0x00000010, 0x00000012,
  236. 0x12728, 0x00000010, 0x00000012,
  237. 0x240c, 0x000007ff, 0x00000000,
  238. 0x8a14, 0xf000001f, 0x00000007,
  239. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  240. 0x8b10, 0x0000ff0f, 0x00000000,
  241. 0x28a4c, 0x07ffffff, 0x06000000,
  242. 0x10c, 0x00000001, 0x00010003,
  243. 0xa02c, 0xffffffff, 0x0000009b,
  244. 0x913c, 0x0000010f, 0x01000100,
  245. 0x8c04, 0xf8ff00ff, 0x40600060,
  246. 0x28350, 0x00000f01, 0x00000000,
  247. 0x9508, 0x3700001f, 0x00000002,
  248. 0x960c, 0xffffffff, 0x54763210,
  249. 0x88c4, 0x001f3ae3, 0x00000082,
  250. 0x88d0, 0xffffffff, 0x0f40df40,
  251. 0x88d4, 0x0000001f, 0x00000010,
  252. 0x8974, 0xffffffff, 0x00000000
  253. };
  254. static const u32 dvst_golden_registers2[] = {
  255. 0x8f8, 0xffffffff, 0,
  256. 0x8fc, 0x00380000, 0,
  257. 0x8f8, 0xffffffff, 1,
  258. 0x8fc, 0x0e000000, 0
  259. };
  260. static const u32 dvst_golden_registers[] = {
  261. 0x690, 0x3fff3fff, 0x20c00033,
  262. 0x918c, 0x0fff0fff, 0x00010006,
  263. 0x91a8, 0x0fff0fff, 0x00010006,
  264. 0x9150, 0xffffdfff, 0x6e944040,
  265. 0x917c, 0x0fff0fff, 0x00030002,
  266. 0x9198, 0x0fff0fff, 0x00030002,
  267. 0x915c, 0x0fff0fff, 0x00010000,
  268. 0x3f90, 0xffff0001, 0xff000000,
  269. 0x9178, 0x0fff0fff, 0x00070000,
  270. 0x9194, 0x0fff0fff, 0x00070000,
  271. 0x9148, 0xffff0001, 0xff000000,
  272. 0x9190, 0x0fff0fff, 0x00090008,
  273. 0x91ac, 0x0fff0fff, 0x00090008,
  274. 0x3f94, 0xffff0000, 0xff000000,
  275. 0x914c, 0xffff0000, 0xff000000,
  276. 0x929c, 0x00000fff, 0x00000001,
  277. 0x55e4, 0xff607fff, 0xfc000100,
  278. 0x8a18, 0xff000fff, 0x00000100,
  279. 0x8b28, 0xff000fff, 0x00000100,
  280. 0x9144, 0xfffc0fff, 0x00000100,
  281. 0x6ed8, 0x00010101, 0x00010000,
  282. 0x9830, 0xffffffff, 0x00000000,
  283. 0x9834, 0xf00fffff, 0x00000400,
  284. 0x9838, 0xfffffffe, 0x00000000,
  285. 0xd0c0, 0xff000fff, 0x00000100,
  286. 0xd02c, 0xbfffff1f, 0x08421000,
  287. 0xd0b8, 0x73773777, 0x12010001,
  288. 0x5bb0, 0x000000f0, 0x00000070,
  289. 0x98f8, 0x73773777, 0x12010001,
  290. 0x98fc, 0xffffffff, 0x00000010,
  291. 0x9b7c, 0x00ff0000, 0x00fc0000,
  292. 0x8030, 0x00001f0f, 0x0000100a,
  293. 0x2f48, 0x73773777, 0x12010001,
  294. 0x2408, 0x00030000, 0x000c007f,
  295. 0x8a14, 0xf000003f, 0x00000007,
  296. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  297. 0x8b10, 0x0000ff0f, 0x00000000,
  298. 0x28a4c, 0x07ffffff, 0x06000000,
  299. 0x4d8, 0x00000fff, 0x00000100,
  300. 0xa008, 0xffffffff, 0x00010000,
  301. 0x913c, 0xffff03ff, 0x01000100,
  302. 0x8c00, 0x000000ff, 0x00000003,
  303. 0x8c04, 0xf8ff00ff, 0x40600060,
  304. 0x8cf0, 0x1fff1fff, 0x08e00410,
  305. 0x28350, 0x00000f01, 0x00000000,
  306. 0x9508, 0xf700071f, 0x00000002,
  307. 0x960c, 0xffffffff, 0x54763210,
  308. 0x20ef8, 0x01ff01ff, 0x00000002,
  309. 0x20e98, 0xfffffbff, 0x00200000,
  310. 0x2015c, 0xffffffff, 0x00000f40,
  311. 0x88c4, 0x001f3ae3, 0x00000082,
  312. 0x8978, 0x3fffffff, 0x04050140,
  313. 0x88d4, 0x0000001f, 0x00000010,
  314. 0x8974, 0xffffffff, 0x00000000
  315. };
  316. static const u32 scrapper_golden_registers[] = {
  317. 0x690, 0x3fff3fff, 0x20c00033,
  318. 0x918c, 0x0fff0fff, 0x00010006,
  319. 0x918c, 0x0fff0fff, 0x00010006,
  320. 0x91a8, 0x0fff0fff, 0x00010006,
  321. 0x91a8, 0x0fff0fff, 0x00010006,
  322. 0x9150, 0xffffdfff, 0x6e944040,
  323. 0x9150, 0xffffdfff, 0x6e944040,
  324. 0x917c, 0x0fff0fff, 0x00030002,
  325. 0x917c, 0x0fff0fff, 0x00030002,
  326. 0x9198, 0x0fff0fff, 0x00030002,
  327. 0x9198, 0x0fff0fff, 0x00030002,
  328. 0x915c, 0x0fff0fff, 0x00010000,
  329. 0x915c, 0x0fff0fff, 0x00010000,
  330. 0x3f90, 0xffff0001, 0xff000000,
  331. 0x3f90, 0xffff0001, 0xff000000,
  332. 0x9178, 0x0fff0fff, 0x00070000,
  333. 0x9178, 0x0fff0fff, 0x00070000,
  334. 0x9194, 0x0fff0fff, 0x00070000,
  335. 0x9194, 0x0fff0fff, 0x00070000,
  336. 0x9148, 0xffff0001, 0xff000000,
  337. 0x9148, 0xffff0001, 0xff000000,
  338. 0x9190, 0x0fff0fff, 0x00090008,
  339. 0x9190, 0x0fff0fff, 0x00090008,
  340. 0x91ac, 0x0fff0fff, 0x00090008,
  341. 0x91ac, 0x0fff0fff, 0x00090008,
  342. 0x3f94, 0xffff0000, 0xff000000,
  343. 0x3f94, 0xffff0000, 0xff000000,
  344. 0x914c, 0xffff0000, 0xff000000,
  345. 0x914c, 0xffff0000, 0xff000000,
  346. 0x929c, 0x00000fff, 0x00000001,
  347. 0x929c, 0x00000fff, 0x00000001,
  348. 0x55e4, 0xff607fff, 0xfc000100,
  349. 0x8a18, 0xff000fff, 0x00000100,
  350. 0x8a18, 0xff000fff, 0x00000100,
  351. 0x8b28, 0xff000fff, 0x00000100,
  352. 0x8b28, 0xff000fff, 0x00000100,
  353. 0x9144, 0xfffc0fff, 0x00000100,
  354. 0x9144, 0xfffc0fff, 0x00000100,
  355. 0x6ed8, 0x00010101, 0x00010000,
  356. 0x9830, 0xffffffff, 0x00000000,
  357. 0x9830, 0xffffffff, 0x00000000,
  358. 0x9834, 0xf00fffff, 0x00000400,
  359. 0x9834, 0xf00fffff, 0x00000400,
  360. 0x9838, 0xfffffffe, 0x00000000,
  361. 0x9838, 0xfffffffe, 0x00000000,
  362. 0xd0c0, 0xff000fff, 0x00000100,
  363. 0xd02c, 0xbfffff1f, 0x08421000,
  364. 0xd02c, 0xbfffff1f, 0x08421000,
  365. 0xd0b8, 0x73773777, 0x12010001,
  366. 0xd0b8, 0x73773777, 0x12010001,
  367. 0x5bb0, 0x000000f0, 0x00000070,
  368. 0x98f8, 0x73773777, 0x12010001,
  369. 0x98f8, 0x73773777, 0x12010001,
  370. 0x98fc, 0xffffffff, 0x00000010,
  371. 0x98fc, 0xffffffff, 0x00000010,
  372. 0x9b7c, 0x00ff0000, 0x00fc0000,
  373. 0x9b7c, 0x00ff0000, 0x00fc0000,
  374. 0x8030, 0x00001f0f, 0x0000100a,
  375. 0x8030, 0x00001f0f, 0x0000100a,
  376. 0x2f48, 0x73773777, 0x12010001,
  377. 0x2f48, 0x73773777, 0x12010001,
  378. 0x2408, 0x00030000, 0x000c007f,
  379. 0x8a14, 0xf000003f, 0x00000007,
  380. 0x8a14, 0xf000003f, 0x00000007,
  381. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  382. 0x8b24, 0x3fff3fff, 0x00ff0fff,
  383. 0x8b10, 0x0000ff0f, 0x00000000,
  384. 0x8b10, 0x0000ff0f, 0x00000000,
  385. 0x28a4c, 0x07ffffff, 0x06000000,
  386. 0x28a4c, 0x07ffffff, 0x06000000,
  387. 0x4d8, 0x00000fff, 0x00000100,
  388. 0x4d8, 0x00000fff, 0x00000100,
  389. 0xa008, 0xffffffff, 0x00010000,
  390. 0xa008, 0xffffffff, 0x00010000,
  391. 0x913c, 0xffff03ff, 0x01000100,
  392. 0x913c, 0xffff03ff, 0x01000100,
  393. 0x90e8, 0x001fffff, 0x010400c0,
  394. 0x8c00, 0x000000ff, 0x00000003,
  395. 0x8c00, 0x000000ff, 0x00000003,
  396. 0x8c04, 0xf8ff00ff, 0x40600060,
  397. 0x8c04, 0xf8ff00ff, 0x40600060,
  398. 0x8c30, 0x0000000f, 0x00040005,
  399. 0x8cf0, 0x1fff1fff, 0x08e00410,
  400. 0x8cf0, 0x1fff1fff, 0x08e00410,
  401. 0x900c, 0x00ffffff, 0x0017071f,
  402. 0x28350, 0x00000f01, 0x00000000,
  403. 0x28350, 0x00000f01, 0x00000000,
  404. 0x9508, 0xf700071f, 0x00000002,
  405. 0x9508, 0xf700071f, 0x00000002,
  406. 0x9688, 0x00300000, 0x0017000f,
  407. 0x960c, 0xffffffff, 0x54763210,
  408. 0x960c, 0xffffffff, 0x54763210,
  409. 0x20ef8, 0x01ff01ff, 0x00000002,
  410. 0x20e98, 0xfffffbff, 0x00200000,
  411. 0x2015c, 0xffffffff, 0x00000f40,
  412. 0x88c4, 0x001f3ae3, 0x00000082,
  413. 0x88c4, 0x001f3ae3, 0x00000082,
  414. 0x8978, 0x3fffffff, 0x04050140,
  415. 0x8978, 0x3fffffff, 0x04050140,
  416. 0x88d4, 0x0000001f, 0x00000010,
  417. 0x88d4, 0x0000001f, 0x00000010,
  418. 0x8974, 0xffffffff, 0x00000000,
  419. 0x8974, 0xffffffff, 0x00000000
  420. };
  421. static void ni_init_golden_registers(struct radeon_device *rdev)
  422. {
  423. switch (rdev->family) {
  424. case CHIP_CAYMAN:
  425. radeon_program_register_sequence(rdev,
  426. cayman_golden_registers,
  427. (const u32)ARRAY_SIZE(cayman_golden_registers));
  428. radeon_program_register_sequence(rdev,
  429. cayman_golden_registers2,
  430. (const u32)ARRAY_SIZE(cayman_golden_registers2));
  431. break;
  432. case CHIP_ARUBA:
  433. if ((rdev->pdev->device == 0x9900) ||
  434. (rdev->pdev->device == 0x9901) ||
  435. (rdev->pdev->device == 0x9903) ||
  436. (rdev->pdev->device == 0x9904) ||
  437. (rdev->pdev->device == 0x9905) ||
  438. (rdev->pdev->device == 0x9906) ||
  439. (rdev->pdev->device == 0x9907) ||
  440. (rdev->pdev->device == 0x9908) ||
  441. (rdev->pdev->device == 0x9909) ||
  442. (rdev->pdev->device == 0x990A) ||
  443. (rdev->pdev->device == 0x990B) ||
  444. (rdev->pdev->device == 0x990C) ||
  445. (rdev->pdev->device == 0x990D) ||
  446. (rdev->pdev->device == 0x990E) ||
  447. (rdev->pdev->device == 0x990F) ||
  448. (rdev->pdev->device == 0x9910) ||
  449. (rdev->pdev->device == 0x9913) ||
  450. (rdev->pdev->device == 0x9917) ||
  451. (rdev->pdev->device == 0x9918)) {
  452. radeon_program_register_sequence(rdev,
  453. dvst_golden_registers,
  454. (const u32)ARRAY_SIZE(dvst_golden_registers));
  455. radeon_program_register_sequence(rdev,
  456. dvst_golden_registers2,
  457. (const u32)ARRAY_SIZE(dvst_golden_registers2));
  458. } else {
  459. radeon_program_register_sequence(rdev,
  460. scrapper_golden_registers,
  461. (const u32)ARRAY_SIZE(scrapper_golden_registers));
  462. radeon_program_register_sequence(rdev,
  463. dvst_golden_registers2,
  464. (const u32)ARRAY_SIZE(dvst_golden_registers2));
  465. }
  466. break;
  467. default:
  468. break;
  469. }
  470. }
  471. #define BTC_IO_MC_REGS_SIZE 29
  472. static const u32 barts_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  473. {0x00000077, 0xff010100},
  474. {0x00000078, 0x00000000},
  475. {0x00000079, 0x00001434},
  476. {0x0000007a, 0xcc08ec08},
  477. {0x0000007b, 0x00040000},
  478. {0x0000007c, 0x000080c0},
  479. {0x0000007d, 0x09000000},
  480. {0x0000007e, 0x00210404},
  481. {0x00000081, 0x08a8e800},
  482. {0x00000082, 0x00030444},
  483. {0x00000083, 0x00000000},
  484. {0x00000085, 0x00000001},
  485. {0x00000086, 0x00000002},
  486. {0x00000087, 0x48490000},
  487. {0x00000088, 0x20244647},
  488. {0x00000089, 0x00000005},
  489. {0x0000008b, 0x66030000},
  490. {0x0000008c, 0x00006603},
  491. {0x0000008d, 0x00000100},
  492. {0x0000008f, 0x00001c0a},
  493. {0x00000090, 0xff000001},
  494. {0x00000094, 0x00101101},
  495. {0x00000095, 0x00000fff},
  496. {0x00000096, 0x00116fff},
  497. {0x00000097, 0x60010000},
  498. {0x00000098, 0x10010000},
  499. {0x00000099, 0x00006000},
  500. {0x0000009a, 0x00001000},
  501. {0x0000009f, 0x00946a00}
  502. };
  503. static const u32 turks_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  504. {0x00000077, 0xff010100},
  505. {0x00000078, 0x00000000},
  506. {0x00000079, 0x00001434},
  507. {0x0000007a, 0xcc08ec08},
  508. {0x0000007b, 0x00040000},
  509. {0x0000007c, 0x000080c0},
  510. {0x0000007d, 0x09000000},
  511. {0x0000007e, 0x00210404},
  512. {0x00000081, 0x08a8e800},
  513. {0x00000082, 0x00030444},
  514. {0x00000083, 0x00000000},
  515. {0x00000085, 0x00000001},
  516. {0x00000086, 0x00000002},
  517. {0x00000087, 0x48490000},
  518. {0x00000088, 0x20244647},
  519. {0x00000089, 0x00000005},
  520. {0x0000008b, 0x66030000},
  521. {0x0000008c, 0x00006603},
  522. {0x0000008d, 0x00000100},
  523. {0x0000008f, 0x00001c0a},
  524. {0x00000090, 0xff000001},
  525. {0x00000094, 0x00101101},
  526. {0x00000095, 0x00000fff},
  527. {0x00000096, 0x00116fff},
  528. {0x00000097, 0x60010000},
  529. {0x00000098, 0x10010000},
  530. {0x00000099, 0x00006000},
  531. {0x0000009a, 0x00001000},
  532. {0x0000009f, 0x00936a00}
  533. };
  534. static const u32 caicos_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  535. {0x00000077, 0xff010100},
  536. {0x00000078, 0x00000000},
  537. {0x00000079, 0x00001434},
  538. {0x0000007a, 0xcc08ec08},
  539. {0x0000007b, 0x00040000},
  540. {0x0000007c, 0x000080c0},
  541. {0x0000007d, 0x09000000},
  542. {0x0000007e, 0x00210404},
  543. {0x00000081, 0x08a8e800},
  544. {0x00000082, 0x00030444},
  545. {0x00000083, 0x00000000},
  546. {0x00000085, 0x00000001},
  547. {0x00000086, 0x00000002},
  548. {0x00000087, 0x48490000},
  549. {0x00000088, 0x20244647},
  550. {0x00000089, 0x00000005},
  551. {0x0000008b, 0x66030000},
  552. {0x0000008c, 0x00006603},
  553. {0x0000008d, 0x00000100},
  554. {0x0000008f, 0x00001c0a},
  555. {0x00000090, 0xff000001},
  556. {0x00000094, 0x00101101},
  557. {0x00000095, 0x00000fff},
  558. {0x00000096, 0x00116fff},
  559. {0x00000097, 0x60010000},
  560. {0x00000098, 0x10010000},
  561. {0x00000099, 0x00006000},
  562. {0x0000009a, 0x00001000},
  563. {0x0000009f, 0x00916a00}
  564. };
  565. static const u32 cayman_io_mc_regs[BTC_IO_MC_REGS_SIZE][2] = {
  566. {0x00000077, 0xff010100},
  567. {0x00000078, 0x00000000},
  568. {0x00000079, 0x00001434},
  569. {0x0000007a, 0xcc08ec08},
  570. {0x0000007b, 0x00040000},
  571. {0x0000007c, 0x000080c0},
  572. {0x0000007d, 0x09000000},
  573. {0x0000007e, 0x00210404},
  574. {0x00000081, 0x08a8e800},
  575. {0x00000082, 0x00030444},
  576. {0x00000083, 0x00000000},
  577. {0x00000085, 0x00000001},
  578. {0x00000086, 0x00000002},
  579. {0x00000087, 0x48490000},
  580. {0x00000088, 0x20244647},
  581. {0x00000089, 0x00000005},
  582. {0x0000008b, 0x66030000},
  583. {0x0000008c, 0x00006603},
  584. {0x0000008d, 0x00000100},
  585. {0x0000008f, 0x00001c0a},
  586. {0x00000090, 0xff000001},
  587. {0x00000094, 0x00101101},
  588. {0x00000095, 0x00000fff},
  589. {0x00000096, 0x00116fff},
  590. {0x00000097, 0x60010000},
  591. {0x00000098, 0x10010000},
  592. {0x00000099, 0x00006000},
  593. {0x0000009a, 0x00001000},
  594. {0x0000009f, 0x00976b00}
  595. };
  596. int ni_mc_load_microcode(struct radeon_device *rdev)
  597. {
  598. const __be32 *fw_data;
  599. u32 mem_type, running;
  600. u32 *io_mc_regs;
  601. int i, ucode_size, regs_size;
  602. if (!rdev->mc_fw)
  603. return -EINVAL;
  604. switch (rdev->family) {
  605. case CHIP_BARTS:
  606. io_mc_regs = (u32 *)&barts_io_mc_regs;
  607. ucode_size = BTC_MC_UCODE_SIZE;
  608. regs_size = BTC_IO_MC_REGS_SIZE;
  609. break;
  610. case CHIP_TURKS:
  611. io_mc_regs = (u32 *)&turks_io_mc_regs;
  612. ucode_size = BTC_MC_UCODE_SIZE;
  613. regs_size = BTC_IO_MC_REGS_SIZE;
  614. break;
  615. case CHIP_CAICOS:
  616. default:
  617. io_mc_regs = (u32 *)&caicos_io_mc_regs;
  618. ucode_size = BTC_MC_UCODE_SIZE;
  619. regs_size = BTC_IO_MC_REGS_SIZE;
  620. break;
  621. case CHIP_CAYMAN:
  622. io_mc_regs = (u32 *)&cayman_io_mc_regs;
  623. ucode_size = CAYMAN_MC_UCODE_SIZE;
  624. regs_size = BTC_IO_MC_REGS_SIZE;
  625. break;
  626. }
  627. mem_type = (RREG32(MC_SEQ_MISC0) & MC_SEQ_MISC0_GDDR5_MASK) >> MC_SEQ_MISC0_GDDR5_SHIFT;
  628. running = RREG32(MC_SEQ_SUP_CNTL) & RUN_MASK;
  629. if ((mem_type == MC_SEQ_MISC0_GDDR5_VALUE) && (running == 0)) {
  630. /* reset the engine and set to writable */
  631. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  632. WREG32(MC_SEQ_SUP_CNTL, 0x00000010);
  633. /* load mc io regs */
  634. for (i = 0; i < regs_size; i++) {
  635. WREG32(MC_SEQ_IO_DEBUG_INDEX, io_mc_regs[(i << 1)]);
  636. WREG32(MC_SEQ_IO_DEBUG_DATA, io_mc_regs[(i << 1) + 1]);
  637. }
  638. /* load the MC ucode */
  639. fw_data = (const __be32 *)rdev->mc_fw->data;
  640. for (i = 0; i < ucode_size; i++)
  641. WREG32(MC_SEQ_SUP_PGM, be32_to_cpup(fw_data++));
  642. /* put the engine back into the active state */
  643. WREG32(MC_SEQ_SUP_CNTL, 0x00000008);
  644. WREG32(MC_SEQ_SUP_CNTL, 0x00000004);
  645. WREG32(MC_SEQ_SUP_CNTL, 0x00000001);
  646. /* wait for training to complete */
  647. for (i = 0; i < rdev->usec_timeout; i++) {
  648. if (RREG32(MC_IO_PAD_CNTL_D0) & MEM_FALL_OUT_CMD)
  649. break;
  650. udelay(1);
  651. }
  652. }
  653. return 0;
  654. }
  655. int ni_init_microcode(struct radeon_device *rdev)
  656. {
  657. const char *chip_name;
  658. const char *rlc_chip_name;
  659. size_t pfp_req_size, me_req_size, rlc_req_size, mc_req_size;
  660. size_t smc_req_size = 0;
  661. char fw_name[30];
  662. int err;
  663. DRM_DEBUG("\n");
  664. switch (rdev->family) {
  665. case CHIP_BARTS:
  666. chip_name = "BARTS";
  667. rlc_chip_name = "BTC";
  668. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  669. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  670. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  671. mc_req_size = BTC_MC_UCODE_SIZE * 4;
  672. smc_req_size = ALIGN(BARTS_SMC_UCODE_SIZE, 4);
  673. break;
  674. case CHIP_TURKS:
  675. chip_name = "TURKS";
  676. rlc_chip_name = "BTC";
  677. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  678. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  679. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  680. mc_req_size = BTC_MC_UCODE_SIZE * 4;
  681. smc_req_size = ALIGN(TURKS_SMC_UCODE_SIZE, 4);
  682. break;
  683. case CHIP_CAICOS:
  684. chip_name = "CAICOS";
  685. rlc_chip_name = "BTC";
  686. pfp_req_size = EVERGREEN_PFP_UCODE_SIZE * 4;
  687. me_req_size = EVERGREEN_PM4_UCODE_SIZE * 4;
  688. rlc_req_size = EVERGREEN_RLC_UCODE_SIZE * 4;
  689. mc_req_size = BTC_MC_UCODE_SIZE * 4;
  690. smc_req_size = ALIGN(CAICOS_SMC_UCODE_SIZE, 4);
  691. break;
  692. case CHIP_CAYMAN:
  693. chip_name = "CAYMAN";
  694. rlc_chip_name = "CAYMAN";
  695. pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
  696. me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
  697. rlc_req_size = CAYMAN_RLC_UCODE_SIZE * 4;
  698. mc_req_size = CAYMAN_MC_UCODE_SIZE * 4;
  699. smc_req_size = ALIGN(CAYMAN_SMC_UCODE_SIZE, 4);
  700. break;
  701. case CHIP_ARUBA:
  702. chip_name = "ARUBA";
  703. rlc_chip_name = "ARUBA";
  704. /* pfp/me same size as CAYMAN */
  705. pfp_req_size = CAYMAN_PFP_UCODE_SIZE * 4;
  706. me_req_size = CAYMAN_PM4_UCODE_SIZE * 4;
  707. rlc_req_size = ARUBA_RLC_UCODE_SIZE * 4;
  708. mc_req_size = 0;
  709. break;
  710. default:
  711. BUG();
  712. }
  713. DRM_INFO("Loading %s Microcode\n", chip_name);
  714. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  715. err = request_firmware(&rdev->pfp_fw, fw_name, rdev->dev);
  716. if (err)
  717. goto out;
  718. if (rdev->pfp_fw->size != pfp_req_size) {
  719. pr_err("ni_cp: Bogus length %zu in firmware \"%s\"\n",
  720. rdev->pfp_fw->size, fw_name);
  721. err = -EINVAL;
  722. goto out;
  723. }
  724. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  725. err = request_firmware(&rdev->me_fw, fw_name, rdev->dev);
  726. if (err)
  727. goto out;
  728. if (rdev->me_fw->size != me_req_size) {
  729. pr_err("ni_cp: Bogus length %zu in firmware \"%s\"\n",
  730. rdev->me_fw->size, fw_name);
  731. err = -EINVAL;
  732. }
  733. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  734. err = request_firmware(&rdev->rlc_fw, fw_name, rdev->dev);
  735. if (err)
  736. goto out;
  737. if (rdev->rlc_fw->size != rlc_req_size) {
  738. pr_err("ni_rlc: Bogus length %zu in firmware \"%s\"\n",
  739. rdev->rlc_fw->size, fw_name);
  740. err = -EINVAL;
  741. }
  742. /* no MC ucode on TN */
  743. if (!(rdev->flags & RADEON_IS_IGP)) {
  744. snprintf(fw_name, sizeof(fw_name), "radeon/%s_mc.bin", chip_name);
  745. err = request_firmware(&rdev->mc_fw, fw_name, rdev->dev);
  746. if (err)
  747. goto out;
  748. if (rdev->mc_fw->size != mc_req_size) {
  749. pr_err("ni_mc: Bogus length %zu in firmware \"%s\"\n",
  750. rdev->mc_fw->size, fw_name);
  751. err = -EINVAL;
  752. }
  753. }
  754. if ((rdev->family >= CHIP_BARTS) && (rdev->family <= CHIP_CAYMAN)) {
  755. snprintf(fw_name, sizeof(fw_name), "radeon/%s_smc.bin", chip_name);
  756. err = request_firmware(&rdev->smc_fw, fw_name, rdev->dev);
  757. if (err) {
  758. pr_err("smc: error loading firmware \"%s\"\n", fw_name);
  759. release_firmware(rdev->smc_fw);
  760. rdev->smc_fw = NULL;
  761. err = 0;
  762. } else if (rdev->smc_fw->size != smc_req_size) {
  763. pr_err("ni_mc: Bogus length %zu in firmware \"%s\"\n",
  764. rdev->smc_fw->size, fw_name);
  765. err = -EINVAL;
  766. }
  767. }
  768. out:
  769. if (err) {
  770. if (err != -EINVAL)
  771. pr_err("ni_cp: Failed to load firmware \"%s\"\n",
  772. fw_name);
  773. release_firmware(rdev->pfp_fw);
  774. rdev->pfp_fw = NULL;
  775. release_firmware(rdev->me_fw);
  776. rdev->me_fw = NULL;
  777. release_firmware(rdev->rlc_fw);
  778. rdev->rlc_fw = NULL;
  779. release_firmware(rdev->mc_fw);
  780. rdev->mc_fw = NULL;
  781. }
  782. return err;
  783. }
  784. /**
  785. * cayman_get_allowed_info_register - fetch the register for the info ioctl
  786. *
  787. * @rdev: radeon_device pointer
  788. * @reg: register offset in bytes
  789. * @val: register value
  790. *
  791. * Returns 0 for success or -EINVAL for an invalid register
  792. *
  793. */
  794. int cayman_get_allowed_info_register(struct radeon_device *rdev,
  795. u32 reg, u32 *val)
  796. {
  797. switch (reg) {
  798. case GRBM_STATUS:
  799. case GRBM_STATUS_SE0:
  800. case GRBM_STATUS_SE1:
  801. case SRBM_STATUS:
  802. case SRBM_STATUS2:
  803. case (DMA_STATUS_REG + DMA0_REGISTER_OFFSET):
  804. case (DMA_STATUS_REG + DMA1_REGISTER_OFFSET):
  805. case UVD_STATUS:
  806. *val = RREG32(reg);
  807. return 0;
  808. default:
  809. return -EINVAL;
  810. }
  811. }
  812. int tn_get_temp(struct radeon_device *rdev)
  813. {
  814. u32 temp = RREG32_SMC(TN_CURRENT_GNB_TEMP) & 0x7ff;
  815. int actual_temp = (temp / 8) - 49;
  816. return actual_temp * 1000;
  817. }
  818. /*
  819. * Core functions
  820. */
  821. static void cayman_gpu_init(struct radeon_device *rdev)
  822. {
  823. u32 gb_addr_config = 0;
  824. u32 mc_arb_ramcfg;
  825. u32 cgts_tcc_disable;
  826. u32 sx_debug_1;
  827. u32 smx_dc_ctl0;
  828. u32 cgts_sm_ctrl_reg;
  829. u32 hdp_host_path_cntl;
  830. u32 tmp;
  831. u32 disabled_rb_mask;
  832. int i, j;
  833. switch (rdev->family) {
  834. case CHIP_CAYMAN:
  835. rdev->config.cayman.max_shader_engines = 2;
  836. rdev->config.cayman.max_pipes_per_simd = 4;
  837. rdev->config.cayman.max_tile_pipes = 8;
  838. rdev->config.cayman.max_simds_per_se = 12;
  839. rdev->config.cayman.max_backends_per_se = 4;
  840. rdev->config.cayman.max_texture_channel_caches = 8;
  841. rdev->config.cayman.max_gprs = 256;
  842. rdev->config.cayman.max_threads = 256;
  843. rdev->config.cayman.max_gs_threads = 32;
  844. rdev->config.cayman.max_stack_entries = 512;
  845. rdev->config.cayman.sx_num_of_sets = 8;
  846. rdev->config.cayman.sx_max_export_size = 256;
  847. rdev->config.cayman.sx_max_export_pos_size = 64;
  848. rdev->config.cayman.sx_max_export_smx_size = 192;
  849. rdev->config.cayman.max_hw_contexts = 8;
  850. rdev->config.cayman.sq_num_cf_insts = 2;
  851. rdev->config.cayman.sc_prim_fifo_size = 0x100;
  852. rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
  853. rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
  854. gb_addr_config = CAYMAN_GB_ADDR_CONFIG_GOLDEN;
  855. break;
  856. case CHIP_ARUBA:
  857. default:
  858. rdev->config.cayman.max_shader_engines = 1;
  859. rdev->config.cayman.max_pipes_per_simd = 4;
  860. rdev->config.cayman.max_tile_pipes = 2;
  861. if ((rdev->pdev->device == 0x9900) ||
  862. (rdev->pdev->device == 0x9901) ||
  863. (rdev->pdev->device == 0x9905) ||
  864. (rdev->pdev->device == 0x9906) ||
  865. (rdev->pdev->device == 0x9907) ||
  866. (rdev->pdev->device == 0x9908) ||
  867. (rdev->pdev->device == 0x9909) ||
  868. (rdev->pdev->device == 0x990B) ||
  869. (rdev->pdev->device == 0x990C) ||
  870. (rdev->pdev->device == 0x990F) ||
  871. (rdev->pdev->device == 0x9910) ||
  872. (rdev->pdev->device == 0x9917) ||
  873. (rdev->pdev->device == 0x9999) ||
  874. (rdev->pdev->device == 0x999C)) {
  875. rdev->config.cayman.max_simds_per_se = 6;
  876. rdev->config.cayman.max_backends_per_se = 2;
  877. rdev->config.cayman.max_hw_contexts = 8;
  878. rdev->config.cayman.sx_max_export_size = 256;
  879. rdev->config.cayman.sx_max_export_pos_size = 64;
  880. rdev->config.cayman.sx_max_export_smx_size = 192;
  881. } else if ((rdev->pdev->device == 0x9903) ||
  882. (rdev->pdev->device == 0x9904) ||
  883. (rdev->pdev->device == 0x990A) ||
  884. (rdev->pdev->device == 0x990D) ||
  885. (rdev->pdev->device == 0x990E) ||
  886. (rdev->pdev->device == 0x9913) ||
  887. (rdev->pdev->device == 0x9918) ||
  888. (rdev->pdev->device == 0x999D)) {
  889. rdev->config.cayman.max_simds_per_se = 4;
  890. rdev->config.cayman.max_backends_per_se = 2;
  891. rdev->config.cayman.max_hw_contexts = 8;
  892. rdev->config.cayman.sx_max_export_size = 256;
  893. rdev->config.cayman.sx_max_export_pos_size = 64;
  894. rdev->config.cayman.sx_max_export_smx_size = 192;
  895. } else if ((rdev->pdev->device == 0x9919) ||
  896. (rdev->pdev->device == 0x9990) ||
  897. (rdev->pdev->device == 0x9991) ||
  898. (rdev->pdev->device == 0x9994) ||
  899. (rdev->pdev->device == 0x9995) ||
  900. (rdev->pdev->device == 0x9996) ||
  901. (rdev->pdev->device == 0x999A) ||
  902. (rdev->pdev->device == 0x99A0)) {
  903. rdev->config.cayman.max_simds_per_se = 3;
  904. rdev->config.cayman.max_backends_per_se = 1;
  905. rdev->config.cayman.max_hw_contexts = 4;
  906. rdev->config.cayman.sx_max_export_size = 128;
  907. rdev->config.cayman.sx_max_export_pos_size = 32;
  908. rdev->config.cayman.sx_max_export_smx_size = 96;
  909. } else {
  910. rdev->config.cayman.max_simds_per_se = 2;
  911. rdev->config.cayman.max_backends_per_se = 1;
  912. rdev->config.cayman.max_hw_contexts = 4;
  913. rdev->config.cayman.sx_max_export_size = 128;
  914. rdev->config.cayman.sx_max_export_pos_size = 32;
  915. rdev->config.cayman.sx_max_export_smx_size = 96;
  916. }
  917. rdev->config.cayman.max_texture_channel_caches = 2;
  918. rdev->config.cayman.max_gprs = 256;
  919. rdev->config.cayman.max_threads = 256;
  920. rdev->config.cayman.max_gs_threads = 32;
  921. rdev->config.cayman.max_stack_entries = 512;
  922. rdev->config.cayman.sx_num_of_sets = 8;
  923. rdev->config.cayman.sq_num_cf_insts = 2;
  924. rdev->config.cayman.sc_prim_fifo_size = 0x40;
  925. rdev->config.cayman.sc_hiz_tile_fifo_size = 0x30;
  926. rdev->config.cayman.sc_earlyz_tile_fifo_size = 0x130;
  927. gb_addr_config = ARUBA_GB_ADDR_CONFIG_GOLDEN;
  928. break;
  929. }
  930. /* Initialize HDP */
  931. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  932. WREG32((0x2c14 + j), 0x00000000);
  933. WREG32((0x2c18 + j), 0x00000000);
  934. WREG32((0x2c1c + j), 0x00000000);
  935. WREG32((0x2c20 + j), 0x00000000);
  936. WREG32((0x2c24 + j), 0x00000000);
  937. }
  938. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  939. WREG32(SRBM_INT_CNTL, 0x1);
  940. WREG32(SRBM_INT_ACK, 0x1);
  941. evergreen_fix_pci_max_read_req_size(rdev);
  942. RREG32(MC_SHARED_CHMAP);
  943. mc_arb_ramcfg = RREG32(MC_ARB_RAMCFG);
  944. tmp = (mc_arb_ramcfg & NOOFCOLS_MASK) >> NOOFCOLS_SHIFT;
  945. rdev->config.cayman.mem_row_size_in_kb = (4 * (1 << (8 + tmp))) / 1024;
  946. if (rdev->config.cayman.mem_row_size_in_kb > 4)
  947. rdev->config.cayman.mem_row_size_in_kb = 4;
  948. /* XXX use MC settings? */
  949. rdev->config.cayman.shader_engine_tile_size = 32;
  950. rdev->config.cayman.num_gpus = 1;
  951. rdev->config.cayman.multi_gpu_tile_size = 64;
  952. tmp = (gb_addr_config & NUM_PIPES_MASK) >> NUM_PIPES_SHIFT;
  953. rdev->config.cayman.num_tile_pipes = (1 << tmp);
  954. tmp = (gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT;
  955. rdev->config.cayman.mem_max_burst_length_bytes = (tmp + 1) * 256;
  956. tmp = (gb_addr_config & NUM_SHADER_ENGINES_MASK) >> NUM_SHADER_ENGINES_SHIFT;
  957. rdev->config.cayman.num_shader_engines = tmp + 1;
  958. tmp = (gb_addr_config & NUM_GPUS_MASK) >> NUM_GPUS_SHIFT;
  959. rdev->config.cayman.num_gpus = tmp + 1;
  960. tmp = (gb_addr_config & MULTI_GPU_TILE_SIZE_MASK) >> MULTI_GPU_TILE_SIZE_SHIFT;
  961. rdev->config.cayman.multi_gpu_tile_size = 1 << tmp;
  962. tmp = (gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT;
  963. rdev->config.cayman.mem_row_size_in_kb = 1 << tmp;
  964. /* setup tiling info dword. gb_addr_config is not adequate since it does
  965. * not have bank info, so create a custom tiling dword.
  966. * bits 3:0 num_pipes
  967. * bits 7:4 num_banks
  968. * bits 11:8 group_size
  969. * bits 15:12 row_size
  970. */
  971. rdev->config.cayman.tile_config = 0;
  972. switch (rdev->config.cayman.num_tile_pipes) {
  973. case 1:
  974. default:
  975. rdev->config.cayman.tile_config |= (0 << 0);
  976. break;
  977. case 2:
  978. rdev->config.cayman.tile_config |= (1 << 0);
  979. break;
  980. case 4:
  981. rdev->config.cayman.tile_config |= (2 << 0);
  982. break;
  983. case 8:
  984. rdev->config.cayman.tile_config |= (3 << 0);
  985. break;
  986. }
  987. /* num banks is 8 on all fusion asics. 0 = 4, 1 = 8, 2 = 16 */
  988. if (rdev->flags & RADEON_IS_IGP)
  989. rdev->config.cayman.tile_config |= 1 << 4;
  990. else {
  991. switch ((mc_arb_ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT) {
  992. case 0: /* four banks */
  993. rdev->config.cayman.tile_config |= 0 << 4;
  994. break;
  995. case 1: /* eight banks */
  996. rdev->config.cayman.tile_config |= 1 << 4;
  997. break;
  998. case 2: /* sixteen banks */
  999. default:
  1000. rdev->config.cayman.tile_config |= 2 << 4;
  1001. break;
  1002. }
  1003. }
  1004. rdev->config.cayman.tile_config |=
  1005. ((gb_addr_config & PIPE_INTERLEAVE_SIZE_MASK) >> PIPE_INTERLEAVE_SIZE_SHIFT) << 8;
  1006. rdev->config.cayman.tile_config |=
  1007. ((gb_addr_config & ROW_SIZE_MASK) >> ROW_SIZE_SHIFT) << 12;
  1008. tmp = 0;
  1009. for (i = (rdev->config.cayman.max_shader_engines - 1); i >= 0; i--) {
  1010. u32 rb_disable_bitmap;
  1011. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  1012. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  1013. rb_disable_bitmap = (RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000) >> 16;
  1014. tmp <<= 4;
  1015. tmp |= rb_disable_bitmap;
  1016. }
  1017. /* enabled rb are just the one not disabled :) */
  1018. disabled_rb_mask = tmp;
  1019. tmp = 0;
  1020. for (i = 0; i < (rdev->config.cayman.max_backends_per_se * rdev->config.cayman.max_shader_engines); i++)
  1021. tmp |= (1 << i);
  1022. /* if all the backends are disabled, fix it up here */
  1023. if ((disabled_rb_mask & tmp) == tmp) {
  1024. for (i = 0; i < (rdev->config.cayman.max_backends_per_se * rdev->config.cayman.max_shader_engines); i++)
  1025. disabled_rb_mask &= ~(1 << i);
  1026. }
  1027. for (i = 0; i < rdev->config.cayman.max_shader_engines; i++) {
  1028. u32 simd_disable_bitmap;
  1029. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  1030. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_INDEX(i));
  1031. simd_disable_bitmap = (RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffff0000) >> 16;
  1032. simd_disable_bitmap |= 0xffffffff << rdev->config.cayman.max_simds_per_se;
  1033. tmp <<= 16;
  1034. tmp |= simd_disable_bitmap;
  1035. }
  1036. rdev->config.cayman.active_simds = hweight32(~tmp);
  1037. WREG32(GRBM_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  1038. WREG32(RLC_GFX_INDEX, INSTANCE_BROADCAST_WRITES | SE_BROADCAST_WRITES);
  1039. WREG32(GB_ADDR_CONFIG, gb_addr_config);
  1040. WREG32(DMIF_ADDR_CONFIG, gb_addr_config);
  1041. if (ASIC_IS_DCE6(rdev))
  1042. WREG32(DMIF_ADDR_CALC, gb_addr_config);
  1043. WREG32(HDP_ADDR_CONFIG, gb_addr_config);
  1044. WREG32(DMA_TILING_CONFIG + DMA0_REGISTER_OFFSET, gb_addr_config);
  1045. WREG32(DMA_TILING_CONFIG + DMA1_REGISTER_OFFSET, gb_addr_config);
  1046. WREG32(UVD_UDEC_ADDR_CONFIG, gb_addr_config);
  1047. WREG32(UVD_UDEC_DB_ADDR_CONFIG, gb_addr_config);
  1048. WREG32(UVD_UDEC_DBW_ADDR_CONFIG, gb_addr_config);
  1049. if ((rdev->config.cayman.max_backends_per_se == 1) &&
  1050. (rdev->flags & RADEON_IS_IGP)) {
  1051. if ((disabled_rb_mask & 3) == 2) {
  1052. /* RB1 disabled, RB0 enabled */
  1053. tmp = 0x00000000;
  1054. } else {
  1055. /* RB0 disabled, RB1 enabled */
  1056. tmp = 0x11111111;
  1057. }
  1058. } else {
  1059. tmp = gb_addr_config & NUM_PIPES_MASK;
  1060. tmp = r6xx_remap_render_backend(rdev, tmp,
  1061. rdev->config.cayman.max_backends_per_se *
  1062. rdev->config.cayman.max_shader_engines,
  1063. CAYMAN_MAX_BACKENDS, disabled_rb_mask);
  1064. }
  1065. rdev->config.cayman.backend_map = tmp;
  1066. WREG32(GB_BACKEND_MAP, tmp);
  1067. cgts_tcc_disable = 0xffff0000;
  1068. for (i = 0; i < rdev->config.cayman.max_texture_channel_caches; i++)
  1069. cgts_tcc_disable &= ~(1 << (16 + i));
  1070. WREG32(CGTS_TCC_DISABLE, cgts_tcc_disable);
  1071. WREG32(CGTS_SYS_TCC_DISABLE, cgts_tcc_disable);
  1072. WREG32(CGTS_USER_SYS_TCC_DISABLE, cgts_tcc_disable);
  1073. WREG32(CGTS_USER_TCC_DISABLE, cgts_tcc_disable);
  1074. /* reprogram the shader complex */
  1075. cgts_sm_ctrl_reg = RREG32(CGTS_SM_CTRL_REG);
  1076. for (i = 0; i < 16; i++)
  1077. WREG32(CGTS_SM_CTRL_REG, OVERRIDE);
  1078. WREG32(CGTS_SM_CTRL_REG, cgts_sm_ctrl_reg);
  1079. /* set HW defaults for 3D engine */
  1080. WREG32(CP_MEQ_THRESHOLDS, MEQ1_START(0x30) | MEQ2_START(0x60));
  1081. sx_debug_1 = RREG32(SX_DEBUG_1);
  1082. sx_debug_1 |= ENABLE_NEW_SMX_ADDRESS;
  1083. WREG32(SX_DEBUG_1, sx_debug_1);
  1084. smx_dc_ctl0 = RREG32(SMX_DC_CTL0);
  1085. smx_dc_ctl0 &= ~NUMBER_OF_SETS(0x1ff);
  1086. smx_dc_ctl0 |= NUMBER_OF_SETS(rdev->config.cayman.sx_num_of_sets);
  1087. WREG32(SMX_DC_CTL0, smx_dc_ctl0);
  1088. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(4) | CRC_SIMD_ID_WADDR_DISABLE);
  1089. /* need to be explicitly zero-ed */
  1090. WREG32(VGT_OFFCHIP_LDS_BASE, 0);
  1091. WREG32(SQ_LSTMP_RING_BASE, 0);
  1092. WREG32(SQ_HSTMP_RING_BASE, 0);
  1093. WREG32(SQ_ESTMP_RING_BASE, 0);
  1094. WREG32(SQ_GSTMP_RING_BASE, 0);
  1095. WREG32(SQ_VSTMP_RING_BASE, 0);
  1096. WREG32(SQ_PSTMP_RING_BASE, 0);
  1097. WREG32(TA_CNTL_AUX, DISABLE_CUBE_ANISO);
  1098. WREG32(SX_EXPORT_BUFFER_SIZES, (COLOR_BUFFER_SIZE((rdev->config.cayman.sx_max_export_size / 4) - 1) |
  1099. POSITION_BUFFER_SIZE((rdev->config.cayman.sx_max_export_pos_size / 4) - 1) |
  1100. SMX_BUFFER_SIZE((rdev->config.cayman.sx_max_export_smx_size / 4) - 1)));
  1101. WREG32(PA_SC_FIFO_SIZE, (SC_PRIM_FIFO_SIZE(rdev->config.cayman.sc_prim_fifo_size) |
  1102. SC_HIZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_hiz_tile_fifo_size) |
  1103. SC_EARLYZ_TILE_FIFO_SIZE(rdev->config.cayman.sc_earlyz_tile_fifo_size)));
  1104. WREG32(VGT_NUM_INSTANCES, 1);
  1105. WREG32(CP_PERFMON_CNTL, 0);
  1106. WREG32(SQ_MS_FIFO_SIZES, (CACHE_FIFO_SIZE(16 * rdev->config.cayman.sq_num_cf_insts) |
  1107. FETCH_FIFO_HIWATER(0x4) |
  1108. DONE_FIFO_HIWATER(0xe0) |
  1109. ALU_UPDATE_FIFO_HIWATER(0x8)));
  1110. WREG32(SQ_GPR_RESOURCE_MGMT_1, NUM_CLAUSE_TEMP_GPRS(4));
  1111. WREG32(SQ_CONFIG, (VC_ENABLE |
  1112. EXPORT_SRC_C |
  1113. GFX_PRIO(0) |
  1114. CS1_PRIO(0) |
  1115. CS2_PRIO(1)));
  1116. WREG32(SQ_DYN_GPR_CNTL_PS_FLUSH_REQ, DYN_GPR_ENABLE);
  1117. WREG32(PA_SC_FORCE_EOV_MAX_CNTS, (FORCE_EOV_MAX_CLK_CNT(4095) |
  1118. FORCE_EOV_MAX_REZ_CNT(255)));
  1119. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC) |
  1120. AUTO_INVLD_EN(ES_AND_GS_AUTO));
  1121. WREG32(VGT_GS_VERTEX_REUSE, 16);
  1122. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  1123. WREG32(CB_PERF_CTR0_SEL_0, 0);
  1124. WREG32(CB_PERF_CTR0_SEL_1, 0);
  1125. WREG32(CB_PERF_CTR1_SEL_0, 0);
  1126. WREG32(CB_PERF_CTR1_SEL_1, 0);
  1127. WREG32(CB_PERF_CTR2_SEL_0, 0);
  1128. WREG32(CB_PERF_CTR2_SEL_1, 0);
  1129. WREG32(CB_PERF_CTR3_SEL_0, 0);
  1130. WREG32(CB_PERF_CTR3_SEL_1, 0);
  1131. tmp = RREG32(HDP_MISC_CNTL);
  1132. tmp |= HDP_FLUSH_INVALIDATE_CACHE;
  1133. WREG32(HDP_MISC_CNTL, tmp);
  1134. hdp_host_path_cntl = RREG32(HDP_HOST_PATH_CNTL);
  1135. WREG32(HDP_HOST_PATH_CNTL, hdp_host_path_cntl);
  1136. WREG32(PA_CL_ENHANCE, CLIP_VTX_REORDER_ENA | NUM_CLIP_SEQ(3));
  1137. udelay(50);
  1138. /* set clockgating golden values on TN */
  1139. if (rdev->family == CHIP_ARUBA) {
  1140. tmp = RREG32_CG(CG_CGTT_LOCAL_0);
  1141. tmp &= ~0x00380000;
  1142. WREG32_CG(CG_CGTT_LOCAL_0, tmp);
  1143. tmp = RREG32_CG(CG_CGTT_LOCAL_1);
  1144. tmp &= ~0x0e000000;
  1145. WREG32_CG(CG_CGTT_LOCAL_1, tmp);
  1146. }
  1147. }
  1148. /*
  1149. * GART
  1150. */
  1151. void cayman_pcie_gart_tlb_flush(struct radeon_device *rdev)
  1152. {
  1153. /* flush hdp cache */
  1154. WREG32(HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  1155. /* bits 0-7 are the VM contexts0-7 */
  1156. WREG32(VM_INVALIDATE_REQUEST, 1);
  1157. }
  1158. static int cayman_pcie_gart_enable(struct radeon_device *rdev)
  1159. {
  1160. int i, r;
  1161. if (rdev->gart.robj == NULL) {
  1162. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  1163. return -EINVAL;
  1164. }
  1165. r = radeon_gart_table_vram_pin(rdev);
  1166. if (r)
  1167. return r;
  1168. /* Setup TLB control */
  1169. WREG32(MC_VM_MX_L1_TLB_CNTL,
  1170. (0xA << 7) |
  1171. ENABLE_L1_TLB |
  1172. ENABLE_L1_FRAGMENT_PROCESSING |
  1173. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  1174. ENABLE_ADVANCED_DRIVER_MODEL |
  1175. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  1176. /* Setup L2 cache */
  1177. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE |
  1178. ENABLE_L2_FRAGMENT_PROCESSING |
  1179. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  1180. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  1181. EFFECTIVE_L2_QUEUE_SIZE(7) |
  1182. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  1183. WREG32(VM_L2_CNTL2, INVALIDATE_ALL_L1_TLBS | INVALIDATE_L2_CACHE);
  1184. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  1185. BANK_SELECT(6) |
  1186. L2_CACHE_BIGK_FRAGMENT_SIZE(6));
  1187. /* setup context0 */
  1188. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  1189. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  1190. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  1191. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  1192. (u32)(rdev->dummy_page.addr >> 12));
  1193. WREG32(VM_CONTEXT0_CNTL2, 0);
  1194. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  1195. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  1196. WREG32(0x15D4, 0);
  1197. WREG32(0x15D8, 0);
  1198. WREG32(0x15DC, 0);
  1199. /* empty context1-7 */
  1200. /* Assign the pt base to something valid for now; the pts used for
  1201. * the VMs are determined by the application and setup and assigned
  1202. * on the fly in the vm part of radeon_gart.c
  1203. */
  1204. for (i = 1; i < 8; i++) {
  1205. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR + (i << 2), 0);
  1206. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR + (i << 2),
  1207. rdev->vm_manager.max_pfn - 1);
  1208. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2),
  1209. rdev->vm_manager.saved_table_addr[i]);
  1210. }
  1211. /* enable context1-7 */
  1212. WREG32(VM_CONTEXT1_PROTECTION_FAULT_DEFAULT_ADDR,
  1213. (u32)(rdev->dummy_page.addr >> 12));
  1214. WREG32(VM_CONTEXT1_CNTL2, 4);
  1215. WREG32(VM_CONTEXT1_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(1) |
  1216. PAGE_TABLE_BLOCK_SIZE(radeon_vm_block_size - 9) |
  1217. RANGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  1218. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  1219. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  1220. DUMMY_PAGE_PROTECTION_FAULT_ENABLE_DEFAULT |
  1221. PDE0_PROTECTION_FAULT_ENABLE_INTERRUPT |
  1222. PDE0_PROTECTION_FAULT_ENABLE_DEFAULT |
  1223. VALID_PROTECTION_FAULT_ENABLE_INTERRUPT |
  1224. VALID_PROTECTION_FAULT_ENABLE_DEFAULT |
  1225. READ_PROTECTION_FAULT_ENABLE_INTERRUPT |
  1226. READ_PROTECTION_FAULT_ENABLE_DEFAULT |
  1227. WRITE_PROTECTION_FAULT_ENABLE_INTERRUPT |
  1228. WRITE_PROTECTION_FAULT_ENABLE_DEFAULT);
  1229. cayman_pcie_gart_tlb_flush(rdev);
  1230. DRM_INFO("PCIE GART of %uM enabled (table at 0x%016llX).\n",
  1231. (unsigned)(rdev->mc.gtt_size >> 20),
  1232. (unsigned long long)rdev->gart.table_addr);
  1233. rdev->gart.ready = true;
  1234. return 0;
  1235. }
  1236. static void cayman_pcie_gart_disable(struct radeon_device *rdev)
  1237. {
  1238. unsigned i;
  1239. for (i = 1; i < 8; ++i) {
  1240. rdev->vm_manager.saved_table_addr[i] = RREG32(
  1241. VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (i << 2));
  1242. }
  1243. /* Disable all tables */
  1244. WREG32(VM_CONTEXT0_CNTL, 0);
  1245. WREG32(VM_CONTEXT1_CNTL, 0);
  1246. /* Setup TLB control */
  1247. WREG32(MC_VM_MX_L1_TLB_CNTL, ENABLE_L1_FRAGMENT_PROCESSING |
  1248. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  1249. SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU);
  1250. /* Setup L2 cache */
  1251. WREG32(VM_L2_CNTL, ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  1252. ENABLE_L2_PDE0_CACHE_LRU_UPDATE_BY_WRITE |
  1253. EFFECTIVE_L2_QUEUE_SIZE(7) |
  1254. CONTEXT1_IDENTITY_ACCESS_MODE(1));
  1255. WREG32(VM_L2_CNTL2, 0);
  1256. WREG32(VM_L2_CNTL3, L2_CACHE_BIGK_ASSOCIATIVITY |
  1257. L2_CACHE_BIGK_FRAGMENT_SIZE(6));
  1258. radeon_gart_table_vram_unpin(rdev);
  1259. }
  1260. static void cayman_pcie_gart_fini(struct radeon_device *rdev)
  1261. {
  1262. cayman_pcie_gart_disable(rdev);
  1263. radeon_gart_table_vram_free(rdev);
  1264. radeon_gart_fini(rdev);
  1265. }
  1266. void cayman_cp_int_cntl_setup(struct radeon_device *rdev,
  1267. int ring, u32 cp_int_cntl)
  1268. {
  1269. WREG32(SRBM_GFX_CNTL, RINGID(ring));
  1270. WREG32(CP_INT_CNTL, cp_int_cntl);
  1271. }
  1272. /*
  1273. * CP.
  1274. */
  1275. void cayman_fence_ring_emit(struct radeon_device *rdev,
  1276. struct radeon_fence *fence)
  1277. {
  1278. struct radeon_ring *ring = &rdev->ring[fence->ring];
  1279. u64 addr = rdev->fence_drv[fence->ring].gpu_addr;
  1280. u32 cp_coher_cntl = PACKET3_FULL_CACHE_ENA | PACKET3_TC_ACTION_ENA |
  1281. PACKET3_SH_ACTION_ENA;
  1282. /* flush read cache over gart for this vmid */
  1283. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  1284. radeon_ring_write(ring, PACKET3_ENGINE_ME | cp_coher_cntl);
  1285. radeon_ring_write(ring, 0xFFFFFFFF);
  1286. radeon_ring_write(ring, 0);
  1287. radeon_ring_write(ring, 10); /* poll interval */
  1288. /* EVENT_WRITE_EOP - flush caches, send int */
  1289. radeon_ring_write(ring, PACKET3(PACKET3_EVENT_WRITE_EOP, 4));
  1290. radeon_ring_write(ring, EVENT_TYPE(CACHE_FLUSH_AND_INV_EVENT_TS) | EVENT_INDEX(5));
  1291. radeon_ring_write(ring, lower_32_bits(addr));
  1292. radeon_ring_write(ring, (upper_32_bits(addr) & 0xff) | DATA_SEL(1) | INT_SEL(2));
  1293. radeon_ring_write(ring, fence->seq);
  1294. radeon_ring_write(ring, 0);
  1295. }
  1296. void cayman_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  1297. {
  1298. struct radeon_ring *ring = &rdev->ring[ib->ring];
  1299. unsigned vm_id = ib->vm ? ib->vm->ids[ib->ring].id : 0;
  1300. u32 cp_coher_cntl = PACKET3_FULL_CACHE_ENA | PACKET3_TC_ACTION_ENA |
  1301. PACKET3_SH_ACTION_ENA;
  1302. /* set to DX10/11 mode */
  1303. radeon_ring_write(ring, PACKET3(PACKET3_MODE_CONTROL, 0));
  1304. radeon_ring_write(ring, 1);
  1305. if (ring->rptr_save_reg) {
  1306. uint32_t next_rptr = ring->wptr + 3 + 4 + 8;
  1307. radeon_ring_write(ring, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1308. radeon_ring_write(ring, ((ring->rptr_save_reg -
  1309. PACKET3_SET_CONFIG_REG_START) >> 2));
  1310. radeon_ring_write(ring, next_rptr);
  1311. }
  1312. radeon_ring_write(ring, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  1313. radeon_ring_write(ring,
  1314. #ifdef __BIG_ENDIAN
  1315. (2 << 0) |
  1316. #endif
  1317. (ib->gpu_addr & 0xFFFFFFFC));
  1318. radeon_ring_write(ring, upper_32_bits(ib->gpu_addr) & 0xFF);
  1319. radeon_ring_write(ring, ib->length_dw | (vm_id << 24));
  1320. /* flush read cache over gart for this vmid */
  1321. radeon_ring_write(ring, PACKET3(PACKET3_SURFACE_SYNC, 3));
  1322. radeon_ring_write(ring, PACKET3_ENGINE_ME | cp_coher_cntl);
  1323. radeon_ring_write(ring, 0xFFFFFFFF);
  1324. radeon_ring_write(ring, 0);
  1325. radeon_ring_write(ring, (vm_id << 24) | 10); /* poll interval */
  1326. }
  1327. static void cayman_cp_enable(struct radeon_device *rdev, bool enable)
  1328. {
  1329. if (enable)
  1330. WREG32(CP_ME_CNTL, 0);
  1331. else {
  1332. if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
  1333. radeon_ttm_set_active_vram_size(rdev, rdev->mc.visible_vram_size);
  1334. WREG32(CP_ME_CNTL, (CP_ME_HALT | CP_PFP_HALT));
  1335. WREG32(SCRATCH_UMSK, 0);
  1336. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  1337. }
  1338. }
  1339. u32 cayman_gfx_get_rptr(struct radeon_device *rdev,
  1340. struct radeon_ring *ring)
  1341. {
  1342. u32 rptr;
  1343. if (rdev->wb.enabled)
  1344. rptr = rdev->wb.wb[ring->rptr_offs/4];
  1345. else {
  1346. if (ring->idx == RADEON_RING_TYPE_GFX_INDEX)
  1347. rptr = RREG32(CP_RB0_RPTR);
  1348. else if (ring->idx == CAYMAN_RING_TYPE_CP1_INDEX)
  1349. rptr = RREG32(CP_RB1_RPTR);
  1350. else
  1351. rptr = RREG32(CP_RB2_RPTR);
  1352. }
  1353. return rptr;
  1354. }
  1355. u32 cayman_gfx_get_wptr(struct radeon_device *rdev,
  1356. struct radeon_ring *ring)
  1357. {
  1358. u32 wptr;
  1359. if (ring->idx == RADEON_RING_TYPE_GFX_INDEX)
  1360. wptr = RREG32(CP_RB0_WPTR);
  1361. else if (ring->idx == CAYMAN_RING_TYPE_CP1_INDEX)
  1362. wptr = RREG32(CP_RB1_WPTR);
  1363. else
  1364. wptr = RREG32(CP_RB2_WPTR);
  1365. return wptr;
  1366. }
  1367. void cayman_gfx_set_wptr(struct radeon_device *rdev,
  1368. struct radeon_ring *ring)
  1369. {
  1370. if (ring->idx == RADEON_RING_TYPE_GFX_INDEX) {
  1371. WREG32(CP_RB0_WPTR, ring->wptr);
  1372. (void)RREG32(CP_RB0_WPTR);
  1373. } else if (ring->idx == CAYMAN_RING_TYPE_CP1_INDEX) {
  1374. WREG32(CP_RB1_WPTR, ring->wptr);
  1375. (void)RREG32(CP_RB1_WPTR);
  1376. } else {
  1377. WREG32(CP_RB2_WPTR, ring->wptr);
  1378. (void)RREG32(CP_RB2_WPTR);
  1379. }
  1380. }
  1381. static int cayman_cp_load_microcode(struct radeon_device *rdev)
  1382. {
  1383. const __be32 *fw_data;
  1384. int i;
  1385. if (!rdev->me_fw || !rdev->pfp_fw)
  1386. return -EINVAL;
  1387. cayman_cp_enable(rdev, false);
  1388. fw_data = (const __be32 *)rdev->pfp_fw->data;
  1389. WREG32(CP_PFP_UCODE_ADDR, 0);
  1390. for (i = 0; i < CAYMAN_PFP_UCODE_SIZE; i++)
  1391. WREG32(CP_PFP_UCODE_DATA, be32_to_cpup(fw_data++));
  1392. WREG32(CP_PFP_UCODE_ADDR, 0);
  1393. fw_data = (const __be32 *)rdev->me_fw->data;
  1394. WREG32(CP_ME_RAM_WADDR, 0);
  1395. for (i = 0; i < CAYMAN_PM4_UCODE_SIZE; i++)
  1396. WREG32(CP_ME_RAM_DATA, be32_to_cpup(fw_data++));
  1397. WREG32(CP_PFP_UCODE_ADDR, 0);
  1398. WREG32(CP_ME_RAM_WADDR, 0);
  1399. WREG32(CP_ME_RAM_RADDR, 0);
  1400. return 0;
  1401. }
  1402. static int cayman_cp_start(struct radeon_device *rdev)
  1403. {
  1404. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1405. int r, i;
  1406. r = radeon_ring_lock(rdev, ring, 7);
  1407. if (r) {
  1408. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1409. return r;
  1410. }
  1411. radeon_ring_write(ring, PACKET3(PACKET3_ME_INITIALIZE, 5));
  1412. radeon_ring_write(ring, 0x1);
  1413. radeon_ring_write(ring, 0x0);
  1414. radeon_ring_write(ring, rdev->config.cayman.max_hw_contexts - 1);
  1415. radeon_ring_write(ring, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  1416. radeon_ring_write(ring, 0);
  1417. radeon_ring_write(ring, 0);
  1418. radeon_ring_unlock_commit(rdev, ring, false);
  1419. cayman_cp_enable(rdev, true);
  1420. r = radeon_ring_lock(rdev, ring, cayman_default_size + 19);
  1421. if (r) {
  1422. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1423. return r;
  1424. }
  1425. /* setup clear context state */
  1426. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  1427. radeon_ring_write(ring, PACKET3_PREAMBLE_BEGIN_CLEAR_STATE);
  1428. for (i = 0; i < cayman_default_size; i++)
  1429. radeon_ring_write(ring, cayman_default_state[i]);
  1430. radeon_ring_write(ring, PACKET3(PACKET3_PREAMBLE_CNTL, 0));
  1431. radeon_ring_write(ring, PACKET3_PREAMBLE_END_CLEAR_STATE);
  1432. /* set clear context state */
  1433. radeon_ring_write(ring, PACKET3(PACKET3_CLEAR_STATE, 0));
  1434. radeon_ring_write(ring, 0);
  1435. /* SQ_VTX_BASE_VTX_LOC */
  1436. radeon_ring_write(ring, 0xc0026f00);
  1437. radeon_ring_write(ring, 0x00000000);
  1438. radeon_ring_write(ring, 0x00000000);
  1439. radeon_ring_write(ring, 0x00000000);
  1440. /* Clear consts */
  1441. radeon_ring_write(ring, 0xc0036f00);
  1442. radeon_ring_write(ring, 0x00000bc4);
  1443. radeon_ring_write(ring, 0xffffffff);
  1444. radeon_ring_write(ring, 0xffffffff);
  1445. radeon_ring_write(ring, 0xffffffff);
  1446. radeon_ring_write(ring, 0xc0026900);
  1447. radeon_ring_write(ring, 0x00000316);
  1448. radeon_ring_write(ring, 0x0000000e); /* VGT_VERTEX_REUSE_BLOCK_CNTL */
  1449. radeon_ring_write(ring, 0x00000010); /* */
  1450. radeon_ring_unlock_commit(rdev, ring, false);
  1451. /* XXX init other rings */
  1452. return 0;
  1453. }
  1454. static void cayman_cp_fini(struct radeon_device *rdev)
  1455. {
  1456. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1457. cayman_cp_enable(rdev, false);
  1458. radeon_ring_fini(rdev, ring);
  1459. radeon_scratch_free(rdev, ring->rptr_save_reg);
  1460. }
  1461. static int cayman_cp_resume(struct radeon_device *rdev)
  1462. {
  1463. static const int ridx[] = {
  1464. RADEON_RING_TYPE_GFX_INDEX,
  1465. CAYMAN_RING_TYPE_CP1_INDEX,
  1466. CAYMAN_RING_TYPE_CP2_INDEX
  1467. };
  1468. static const unsigned cp_rb_cntl[] = {
  1469. CP_RB0_CNTL,
  1470. CP_RB1_CNTL,
  1471. CP_RB2_CNTL,
  1472. };
  1473. static const unsigned cp_rb_rptr_addr[] = {
  1474. CP_RB0_RPTR_ADDR,
  1475. CP_RB1_RPTR_ADDR,
  1476. CP_RB2_RPTR_ADDR
  1477. };
  1478. static const unsigned cp_rb_rptr_addr_hi[] = {
  1479. CP_RB0_RPTR_ADDR_HI,
  1480. CP_RB1_RPTR_ADDR_HI,
  1481. CP_RB2_RPTR_ADDR_HI
  1482. };
  1483. static const unsigned cp_rb_base[] = {
  1484. CP_RB0_BASE,
  1485. CP_RB1_BASE,
  1486. CP_RB2_BASE
  1487. };
  1488. static const unsigned cp_rb_rptr[] = {
  1489. CP_RB0_RPTR,
  1490. CP_RB1_RPTR,
  1491. CP_RB2_RPTR
  1492. };
  1493. static const unsigned cp_rb_wptr[] = {
  1494. CP_RB0_WPTR,
  1495. CP_RB1_WPTR,
  1496. CP_RB2_WPTR
  1497. };
  1498. struct radeon_ring *ring;
  1499. int i, r;
  1500. /* Reset cp; if cp is reset, then PA, SH, VGT also need to be reset */
  1501. WREG32(GRBM_SOFT_RESET, (SOFT_RESET_CP |
  1502. SOFT_RESET_PA |
  1503. SOFT_RESET_SH |
  1504. SOFT_RESET_VGT |
  1505. SOFT_RESET_SPI |
  1506. SOFT_RESET_SX));
  1507. RREG32(GRBM_SOFT_RESET);
  1508. mdelay(15);
  1509. WREG32(GRBM_SOFT_RESET, 0);
  1510. RREG32(GRBM_SOFT_RESET);
  1511. WREG32(CP_SEM_WAIT_TIMER, 0x0);
  1512. WREG32(CP_SEM_INCOMPLETE_TIMER_CNTL, 0x0);
  1513. /* Set the write pointer delay */
  1514. WREG32(CP_RB_WPTR_DELAY, 0);
  1515. WREG32(CP_DEBUG, (1 << 27));
  1516. /* set the wb address whether it's enabled or not */
  1517. WREG32(SCRATCH_ADDR, ((rdev->wb.gpu_addr + RADEON_WB_SCRATCH_OFFSET) >> 8) & 0xFFFFFFFF);
  1518. WREG32(SCRATCH_UMSK, 0xff);
  1519. for (i = 0; i < 3; ++i) {
  1520. uint32_t rb_cntl;
  1521. uint64_t addr;
  1522. /* Set ring buffer size */
  1523. ring = &rdev->ring[ridx[i]];
  1524. rb_cntl = order_base_2(ring->ring_size / 8);
  1525. rb_cntl |= order_base_2(RADEON_GPU_PAGE_SIZE/8) << 8;
  1526. #ifdef __BIG_ENDIAN
  1527. rb_cntl |= BUF_SWAP_32BIT;
  1528. #endif
  1529. WREG32(cp_rb_cntl[i], rb_cntl);
  1530. /* set the wb address whether it's enabled or not */
  1531. addr = rdev->wb.gpu_addr + RADEON_WB_CP_RPTR_OFFSET;
  1532. WREG32(cp_rb_rptr_addr[i], addr & 0xFFFFFFFC);
  1533. WREG32(cp_rb_rptr_addr_hi[i], upper_32_bits(addr) & 0xFF);
  1534. }
  1535. /* set the rb base addr, this causes an internal reset of ALL rings */
  1536. for (i = 0; i < 3; ++i) {
  1537. ring = &rdev->ring[ridx[i]];
  1538. WREG32(cp_rb_base[i], ring->gpu_addr >> 8);
  1539. }
  1540. for (i = 0; i < 3; ++i) {
  1541. /* Initialize the ring buffer's read and write pointers */
  1542. ring = &rdev->ring[ridx[i]];
  1543. WREG32_P(cp_rb_cntl[i], RB_RPTR_WR_ENA, ~RB_RPTR_WR_ENA);
  1544. ring->wptr = 0;
  1545. WREG32(cp_rb_rptr[i], 0);
  1546. WREG32(cp_rb_wptr[i], ring->wptr);
  1547. mdelay(1);
  1548. WREG32_P(cp_rb_cntl[i], 0, ~RB_RPTR_WR_ENA);
  1549. }
  1550. /* start the rings */
  1551. cayman_cp_start(rdev);
  1552. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = true;
  1553. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  1554. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  1555. /* this only test cp0 */
  1556. r = radeon_ring_test(rdev, RADEON_RING_TYPE_GFX_INDEX, &rdev->ring[RADEON_RING_TYPE_GFX_INDEX]);
  1557. if (r) {
  1558. rdev->ring[RADEON_RING_TYPE_GFX_INDEX].ready = false;
  1559. rdev->ring[CAYMAN_RING_TYPE_CP1_INDEX].ready = false;
  1560. rdev->ring[CAYMAN_RING_TYPE_CP2_INDEX].ready = false;
  1561. return r;
  1562. }
  1563. if (rdev->asic->copy.copy_ring_index == RADEON_RING_TYPE_GFX_INDEX)
  1564. radeon_ttm_set_active_vram_size(rdev, rdev->mc.real_vram_size);
  1565. return 0;
  1566. }
  1567. u32 cayman_gpu_check_soft_reset(struct radeon_device *rdev)
  1568. {
  1569. u32 reset_mask = 0;
  1570. u32 tmp;
  1571. /* GRBM_STATUS */
  1572. tmp = RREG32(GRBM_STATUS);
  1573. if (tmp & (PA_BUSY | SC_BUSY |
  1574. SH_BUSY | SX_BUSY |
  1575. TA_BUSY | VGT_BUSY |
  1576. DB_BUSY | CB_BUSY |
  1577. GDS_BUSY | SPI_BUSY |
  1578. IA_BUSY | IA_BUSY_NO_DMA))
  1579. reset_mask |= RADEON_RESET_GFX;
  1580. if (tmp & (CF_RQ_PENDING | PF_RQ_PENDING |
  1581. CP_BUSY | CP_COHERENCY_BUSY))
  1582. reset_mask |= RADEON_RESET_CP;
  1583. if (tmp & GRBM_EE_BUSY)
  1584. reset_mask |= RADEON_RESET_GRBM | RADEON_RESET_GFX | RADEON_RESET_CP;
  1585. /* DMA_STATUS_REG 0 */
  1586. tmp = RREG32(DMA_STATUS_REG + DMA0_REGISTER_OFFSET);
  1587. if (!(tmp & DMA_IDLE))
  1588. reset_mask |= RADEON_RESET_DMA;
  1589. /* DMA_STATUS_REG 1 */
  1590. tmp = RREG32(DMA_STATUS_REG + DMA1_REGISTER_OFFSET);
  1591. if (!(tmp & DMA_IDLE))
  1592. reset_mask |= RADEON_RESET_DMA1;
  1593. /* SRBM_STATUS2 */
  1594. tmp = RREG32(SRBM_STATUS2);
  1595. if (tmp & DMA_BUSY)
  1596. reset_mask |= RADEON_RESET_DMA;
  1597. if (tmp & DMA1_BUSY)
  1598. reset_mask |= RADEON_RESET_DMA1;
  1599. /* SRBM_STATUS */
  1600. tmp = RREG32(SRBM_STATUS);
  1601. if (tmp & (RLC_RQ_PENDING | RLC_BUSY))
  1602. reset_mask |= RADEON_RESET_RLC;
  1603. if (tmp & IH_BUSY)
  1604. reset_mask |= RADEON_RESET_IH;
  1605. if (tmp & SEM_BUSY)
  1606. reset_mask |= RADEON_RESET_SEM;
  1607. if (tmp & GRBM_RQ_PENDING)
  1608. reset_mask |= RADEON_RESET_GRBM;
  1609. if (tmp & VMC_BUSY)
  1610. reset_mask |= RADEON_RESET_VMC;
  1611. if (tmp & (MCB_BUSY | MCB_NON_DISPLAY_BUSY |
  1612. MCC_BUSY | MCD_BUSY))
  1613. reset_mask |= RADEON_RESET_MC;
  1614. if (evergreen_is_display_hung(rdev))
  1615. reset_mask |= RADEON_RESET_DISPLAY;
  1616. /* VM_L2_STATUS */
  1617. tmp = RREG32(VM_L2_STATUS);
  1618. if (tmp & L2_BUSY)
  1619. reset_mask |= RADEON_RESET_VMC;
  1620. /* Skip MC reset as it's mostly likely not hung, just busy */
  1621. if (reset_mask & RADEON_RESET_MC) {
  1622. DRM_DEBUG("MC busy: 0x%08X, clearing.\n", reset_mask);
  1623. reset_mask &= ~RADEON_RESET_MC;
  1624. }
  1625. return reset_mask;
  1626. }
  1627. static void cayman_gpu_soft_reset(struct radeon_device *rdev, u32 reset_mask)
  1628. {
  1629. struct evergreen_mc_save save;
  1630. u32 grbm_soft_reset = 0, srbm_soft_reset = 0;
  1631. u32 tmp;
  1632. if (reset_mask == 0)
  1633. return;
  1634. dev_info(rdev->dev, "GPU softreset: 0x%08X\n", reset_mask);
  1635. evergreen_print_gpu_status_regs(rdev);
  1636. dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_ADDR 0x%08X\n",
  1637. RREG32(0x14F8));
  1638. dev_info(rdev->dev, " VM_CONTEXT0_PROTECTION_FAULT_STATUS 0x%08X\n",
  1639. RREG32(0x14D8));
  1640. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_ADDR 0x%08X\n",
  1641. RREG32(0x14FC));
  1642. dev_info(rdev->dev, " VM_CONTEXT1_PROTECTION_FAULT_STATUS 0x%08X\n",
  1643. RREG32(0x14DC));
  1644. /* Disable CP parsing/prefetching */
  1645. WREG32(CP_ME_CNTL, CP_ME_HALT | CP_PFP_HALT);
  1646. if (reset_mask & RADEON_RESET_DMA) {
  1647. /* dma0 */
  1648. tmp = RREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET);
  1649. tmp &= ~DMA_RB_ENABLE;
  1650. WREG32(DMA_RB_CNTL + DMA0_REGISTER_OFFSET, tmp);
  1651. }
  1652. if (reset_mask & RADEON_RESET_DMA1) {
  1653. /* dma1 */
  1654. tmp = RREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET);
  1655. tmp &= ~DMA_RB_ENABLE;
  1656. WREG32(DMA_RB_CNTL + DMA1_REGISTER_OFFSET, tmp);
  1657. }
  1658. udelay(50);
  1659. evergreen_mc_stop(rdev, &save);
  1660. if (evergreen_mc_wait_for_idle(rdev)) {
  1661. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  1662. }
  1663. if (reset_mask & (RADEON_RESET_GFX | RADEON_RESET_COMPUTE)) {
  1664. grbm_soft_reset = SOFT_RESET_CB |
  1665. SOFT_RESET_DB |
  1666. SOFT_RESET_GDS |
  1667. SOFT_RESET_PA |
  1668. SOFT_RESET_SC |
  1669. SOFT_RESET_SPI |
  1670. SOFT_RESET_SH |
  1671. SOFT_RESET_SX |
  1672. SOFT_RESET_TC |
  1673. SOFT_RESET_TA |
  1674. SOFT_RESET_VGT |
  1675. SOFT_RESET_IA;
  1676. }
  1677. if (reset_mask & RADEON_RESET_CP) {
  1678. grbm_soft_reset |= SOFT_RESET_CP | SOFT_RESET_VGT;
  1679. srbm_soft_reset |= SOFT_RESET_GRBM;
  1680. }
  1681. if (reset_mask & RADEON_RESET_DMA)
  1682. srbm_soft_reset |= SOFT_RESET_DMA;
  1683. if (reset_mask & RADEON_RESET_DMA1)
  1684. srbm_soft_reset |= SOFT_RESET_DMA1;
  1685. if (reset_mask & RADEON_RESET_DISPLAY)
  1686. srbm_soft_reset |= SOFT_RESET_DC;
  1687. if (reset_mask & RADEON_RESET_RLC)
  1688. srbm_soft_reset |= SOFT_RESET_RLC;
  1689. if (reset_mask & RADEON_RESET_SEM)
  1690. srbm_soft_reset |= SOFT_RESET_SEM;
  1691. if (reset_mask & RADEON_RESET_IH)
  1692. srbm_soft_reset |= SOFT_RESET_IH;
  1693. if (reset_mask & RADEON_RESET_GRBM)
  1694. srbm_soft_reset |= SOFT_RESET_GRBM;
  1695. if (reset_mask & RADEON_RESET_VMC)
  1696. srbm_soft_reset |= SOFT_RESET_VMC;
  1697. if (!(rdev->flags & RADEON_IS_IGP)) {
  1698. if (reset_mask & RADEON_RESET_MC)
  1699. srbm_soft_reset |= SOFT_RESET_MC;
  1700. }
  1701. if (grbm_soft_reset) {
  1702. tmp = RREG32(GRBM_SOFT_RESET);
  1703. tmp |= grbm_soft_reset;
  1704. dev_info(rdev->dev, "GRBM_SOFT_RESET=0x%08X\n", tmp);
  1705. WREG32(GRBM_SOFT_RESET, tmp);
  1706. tmp = RREG32(GRBM_SOFT_RESET);
  1707. udelay(50);
  1708. tmp &= ~grbm_soft_reset;
  1709. WREG32(GRBM_SOFT_RESET, tmp);
  1710. tmp = RREG32(GRBM_SOFT_RESET);
  1711. }
  1712. if (srbm_soft_reset) {
  1713. tmp = RREG32(SRBM_SOFT_RESET);
  1714. tmp |= srbm_soft_reset;
  1715. dev_info(rdev->dev, "SRBM_SOFT_RESET=0x%08X\n", tmp);
  1716. WREG32(SRBM_SOFT_RESET, tmp);
  1717. tmp = RREG32(SRBM_SOFT_RESET);
  1718. udelay(50);
  1719. tmp &= ~srbm_soft_reset;
  1720. WREG32(SRBM_SOFT_RESET, tmp);
  1721. tmp = RREG32(SRBM_SOFT_RESET);
  1722. }
  1723. /* Wait a little for things to settle down */
  1724. udelay(50);
  1725. evergreen_mc_resume(rdev, &save);
  1726. udelay(50);
  1727. evergreen_print_gpu_status_regs(rdev);
  1728. }
  1729. int cayman_asic_reset(struct radeon_device *rdev, bool hard)
  1730. {
  1731. u32 reset_mask;
  1732. if (hard) {
  1733. evergreen_gpu_pci_config_reset(rdev);
  1734. return 0;
  1735. }
  1736. reset_mask = cayman_gpu_check_soft_reset(rdev);
  1737. if (reset_mask)
  1738. r600_set_bios_scratch_engine_hung(rdev, true);
  1739. cayman_gpu_soft_reset(rdev, reset_mask);
  1740. reset_mask = cayman_gpu_check_soft_reset(rdev);
  1741. if (reset_mask)
  1742. evergreen_gpu_pci_config_reset(rdev);
  1743. r600_set_bios_scratch_engine_hung(rdev, false);
  1744. return 0;
  1745. }
  1746. /**
  1747. * cayman_gfx_is_lockup - Check if the GFX engine is locked up
  1748. *
  1749. * @rdev: radeon_device pointer
  1750. * @ring: radeon_ring structure holding ring information
  1751. *
  1752. * Check if the GFX engine is locked up.
  1753. * Returns true if the engine appears to be locked up, false if not.
  1754. */
  1755. bool cayman_gfx_is_lockup(struct radeon_device *rdev, struct radeon_ring *ring)
  1756. {
  1757. u32 reset_mask = cayman_gpu_check_soft_reset(rdev);
  1758. if (!(reset_mask & (RADEON_RESET_GFX |
  1759. RADEON_RESET_COMPUTE |
  1760. RADEON_RESET_CP))) {
  1761. radeon_ring_lockup_update(rdev, ring);
  1762. return false;
  1763. }
  1764. return radeon_ring_test_lockup(rdev, ring);
  1765. }
  1766. static void cayman_uvd_init(struct radeon_device *rdev)
  1767. {
  1768. int r;
  1769. if (!rdev->has_uvd)
  1770. return;
  1771. r = radeon_uvd_init(rdev);
  1772. if (r) {
  1773. dev_err(rdev->dev, "failed UVD (%d) init.\n", r);
  1774. /*
  1775. * At this point rdev->uvd.vcpu_bo is NULL which trickles down
  1776. * to early fails uvd_v2_2_resume() and thus nothing happens
  1777. * there. So it is pointless to try to go through that code
  1778. * hence why we disable uvd here.
  1779. */
  1780. rdev->has_uvd = false;
  1781. return;
  1782. }
  1783. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_obj = NULL;
  1784. r600_ring_init(rdev, &rdev->ring[R600_RING_TYPE_UVD_INDEX], 4096);
  1785. }
  1786. static void cayman_uvd_start(struct radeon_device *rdev)
  1787. {
  1788. int r;
  1789. if (!rdev->has_uvd)
  1790. return;
  1791. r = uvd_v2_2_resume(rdev);
  1792. if (r) {
  1793. dev_err(rdev->dev, "failed UVD resume (%d).\n", r);
  1794. goto error;
  1795. }
  1796. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_UVD_INDEX);
  1797. if (r) {
  1798. dev_err(rdev->dev, "failed initializing UVD fences (%d).\n", r);
  1799. goto error;
  1800. }
  1801. return;
  1802. error:
  1803. rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size = 0;
  1804. }
  1805. static void cayman_uvd_resume(struct radeon_device *rdev)
  1806. {
  1807. struct radeon_ring *ring;
  1808. int r;
  1809. if (!rdev->has_uvd || !rdev->ring[R600_RING_TYPE_UVD_INDEX].ring_size)
  1810. return;
  1811. ring = &rdev->ring[R600_RING_TYPE_UVD_INDEX];
  1812. r = radeon_ring_init(rdev, ring, ring->ring_size, 0, PACKET0(UVD_NO_OP, 0));
  1813. if (r) {
  1814. dev_err(rdev->dev, "failed initializing UVD ring (%d).\n", r);
  1815. return;
  1816. }
  1817. r = uvd_v1_0_init(rdev);
  1818. if (r) {
  1819. dev_err(rdev->dev, "failed initializing UVD (%d).\n", r);
  1820. return;
  1821. }
  1822. }
  1823. static void cayman_vce_init(struct radeon_device *rdev)
  1824. {
  1825. int r;
  1826. /* Only set for CHIP_ARUBA */
  1827. if (!rdev->has_vce)
  1828. return;
  1829. r = radeon_vce_init(rdev);
  1830. if (r) {
  1831. dev_err(rdev->dev, "failed VCE (%d) init.\n", r);
  1832. /*
  1833. * At this point rdev->vce.vcpu_bo is NULL which trickles down
  1834. * to early fails cayman_vce_start() and thus nothing happens
  1835. * there. So it is pointless to try to go through that code
  1836. * hence why we disable vce here.
  1837. */
  1838. rdev->has_vce = false;
  1839. return;
  1840. }
  1841. rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_obj = NULL;
  1842. r600_ring_init(rdev, &rdev->ring[TN_RING_TYPE_VCE1_INDEX], 4096);
  1843. rdev->ring[TN_RING_TYPE_VCE2_INDEX].ring_obj = NULL;
  1844. r600_ring_init(rdev, &rdev->ring[TN_RING_TYPE_VCE2_INDEX], 4096);
  1845. }
  1846. static void cayman_vce_start(struct radeon_device *rdev)
  1847. {
  1848. int r;
  1849. if (!rdev->has_vce)
  1850. return;
  1851. r = radeon_vce_resume(rdev);
  1852. if (r) {
  1853. dev_err(rdev->dev, "failed VCE resume (%d).\n", r);
  1854. goto error;
  1855. }
  1856. r = vce_v1_0_resume(rdev);
  1857. if (r) {
  1858. dev_err(rdev->dev, "failed VCE resume (%d).\n", r);
  1859. goto error;
  1860. }
  1861. r = radeon_fence_driver_start_ring(rdev, TN_RING_TYPE_VCE1_INDEX);
  1862. if (r) {
  1863. dev_err(rdev->dev, "failed initializing VCE1 fences (%d).\n", r);
  1864. goto error;
  1865. }
  1866. r = radeon_fence_driver_start_ring(rdev, TN_RING_TYPE_VCE2_INDEX);
  1867. if (r) {
  1868. dev_err(rdev->dev, "failed initializing VCE2 fences (%d).\n", r);
  1869. goto error;
  1870. }
  1871. return;
  1872. error:
  1873. rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_size = 0;
  1874. rdev->ring[TN_RING_TYPE_VCE2_INDEX].ring_size = 0;
  1875. }
  1876. static void cayman_vce_resume(struct radeon_device *rdev)
  1877. {
  1878. struct radeon_ring *ring;
  1879. int r;
  1880. if (!rdev->has_vce || !rdev->ring[TN_RING_TYPE_VCE1_INDEX].ring_size)
  1881. return;
  1882. ring = &rdev->ring[TN_RING_TYPE_VCE1_INDEX];
  1883. r = radeon_ring_init(rdev, ring, ring->ring_size, 0, 0x0);
  1884. if (r) {
  1885. dev_err(rdev->dev, "failed initializing VCE1 ring (%d).\n", r);
  1886. return;
  1887. }
  1888. ring = &rdev->ring[TN_RING_TYPE_VCE2_INDEX];
  1889. r = radeon_ring_init(rdev, ring, ring->ring_size, 0, 0x0);
  1890. if (r) {
  1891. dev_err(rdev->dev, "failed initializing VCE1 ring (%d).\n", r);
  1892. return;
  1893. }
  1894. r = vce_v1_0_init(rdev);
  1895. if (r) {
  1896. dev_err(rdev->dev, "failed initializing VCE (%d).\n", r);
  1897. return;
  1898. }
  1899. }
  1900. static int cayman_startup(struct radeon_device *rdev)
  1901. {
  1902. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  1903. int r;
  1904. /* enable pcie gen2 link */
  1905. evergreen_pcie_gen2_enable(rdev);
  1906. /* enable aspm */
  1907. evergreen_program_aspm(rdev);
  1908. /* scratch needs to be initialized before MC */
  1909. r = r600_vram_scratch_init(rdev);
  1910. if (r)
  1911. return r;
  1912. evergreen_mc_program(rdev);
  1913. if (!(rdev->flags & RADEON_IS_IGP) && !rdev->pm.dpm_enabled) {
  1914. r = ni_mc_load_microcode(rdev);
  1915. if (r) {
  1916. DRM_ERROR("Failed to load MC firmware!\n");
  1917. return r;
  1918. }
  1919. }
  1920. r = cayman_pcie_gart_enable(rdev);
  1921. if (r)
  1922. return r;
  1923. cayman_gpu_init(rdev);
  1924. /* allocate rlc buffers */
  1925. if (rdev->flags & RADEON_IS_IGP) {
  1926. rdev->rlc.reg_list = tn_rlc_save_restore_register_list;
  1927. rdev->rlc.reg_list_size =
  1928. (u32)ARRAY_SIZE(tn_rlc_save_restore_register_list);
  1929. rdev->rlc.cs_data = cayman_cs_data;
  1930. r = sumo_rlc_init(rdev);
  1931. if (r) {
  1932. DRM_ERROR("Failed to init rlc BOs!\n");
  1933. return r;
  1934. }
  1935. }
  1936. /* allocate wb buffer */
  1937. r = radeon_wb_init(rdev);
  1938. if (r)
  1939. return r;
  1940. r = radeon_fence_driver_start_ring(rdev, RADEON_RING_TYPE_GFX_INDEX);
  1941. if (r) {
  1942. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  1943. return r;
  1944. }
  1945. cayman_uvd_start(rdev);
  1946. cayman_vce_start(rdev);
  1947. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP1_INDEX);
  1948. if (r) {
  1949. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  1950. return r;
  1951. }
  1952. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_CP2_INDEX);
  1953. if (r) {
  1954. dev_err(rdev->dev, "failed initializing CP fences (%d).\n", r);
  1955. return r;
  1956. }
  1957. r = radeon_fence_driver_start_ring(rdev, R600_RING_TYPE_DMA_INDEX);
  1958. if (r) {
  1959. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  1960. return r;
  1961. }
  1962. r = radeon_fence_driver_start_ring(rdev, CAYMAN_RING_TYPE_DMA1_INDEX);
  1963. if (r) {
  1964. dev_err(rdev->dev, "failed initializing DMA fences (%d).\n", r);
  1965. return r;
  1966. }
  1967. /* Enable IRQ */
  1968. if (!rdev->irq.installed) {
  1969. r = radeon_irq_kms_init(rdev);
  1970. if (r)
  1971. return r;
  1972. }
  1973. r = r600_irq_init(rdev);
  1974. if (r) {
  1975. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  1976. radeon_irq_kms_fini(rdev);
  1977. return r;
  1978. }
  1979. evergreen_irq_set(rdev);
  1980. r = radeon_ring_init(rdev, ring, ring->ring_size, RADEON_WB_CP_RPTR_OFFSET,
  1981. RADEON_CP_PACKET2);
  1982. if (r)
  1983. return r;
  1984. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  1985. r = radeon_ring_init(rdev, ring, ring->ring_size, R600_WB_DMA_RPTR_OFFSET,
  1986. DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
  1987. if (r)
  1988. return r;
  1989. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  1990. r = radeon_ring_init(rdev, ring, ring->ring_size, CAYMAN_WB_DMA1_RPTR_OFFSET,
  1991. DMA_PACKET(DMA_PACKET_NOP, 0, 0, 0));
  1992. if (r)
  1993. return r;
  1994. r = cayman_cp_load_microcode(rdev);
  1995. if (r)
  1996. return r;
  1997. r = cayman_cp_resume(rdev);
  1998. if (r)
  1999. return r;
  2000. r = cayman_dma_resume(rdev);
  2001. if (r)
  2002. return r;
  2003. cayman_uvd_resume(rdev);
  2004. cayman_vce_resume(rdev);
  2005. r = radeon_ib_pool_init(rdev);
  2006. if (r) {
  2007. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  2008. return r;
  2009. }
  2010. r = radeon_vm_manager_init(rdev);
  2011. if (r) {
  2012. dev_err(rdev->dev, "vm manager initialization failed (%d).\n", r);
  2013. return r;
  2014. }
  2015. r = radeon_audio_init(rdev);
  2016. if (r)
  2017. return r;
  2018. return 0;
  2019. }
  2020. int cayman_resume(struct radeon_device *rdev)
  2021. {
  2022. int r;
  2023. /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw,
  2024. * posting will perform necessary task to bring back GPU into good
  2025. * shape.
  2026. */
  2027. /* post card */
  2028. atom_asic_init(rdev->mode_info.atom_context);
  2029. /* init golden registers */
  2030. ni_init_golden_registers(rdev);
  2031. if (rdev->pm.pm_method == PM_METHOD_DPM)
  2032. radeon_pm_resume(rdev);
  2033. rdev->accel_working = true;
  2034. r = cayman_startup(rdev);
  2035. if (r) {
  2036. DRM_ERROR("cayman startup failed on resume\n");
  2037. rdev->accel_working = false;
  2038. return r;
  2039. }
  2040. return r;
  2041. }
  2042. int cayman_suspend(struct radeon_device *rdev)
  2043. {
  2044. radeon_pm_suspend(rdev);
  2045. radeon_audio_fini(rdev);
  2046. radeon_vm_manager_fini(rdev);
  2047. cayman_cp_enable(rdev, false);
  2048. cayman_dma_stop(rdev);
  2049. if (rdev->has_uvd) {
  2050. radeon_uvd_suspend(rdev);
  2051. uvd_v1_0_fini(rdev);
  2052. }
  2053. evergreen_irq_suspend(rdev);
  2054. radeon_wb_disable(rdev);
  2055. cayman_pcie_gart_disable(rdev);
  2056. return 0;
  2057. }
  2058. /* Plan is to move initialization in that function and use
  2059. * helper function so that radeon_device_init pretty much
  2060. * do nothing more than calling asic specific function. This
  2061. * should also allow to remove a bunch of callback function
  2062. * like vram_info.
  2063. */
  2064. int cayman_init(struct radeon_device *rdev)
  2065. {
  2066. struct radeon_ring *ring = &rdev->ring[RADEON_RING_TYPE_GFX_INDEX];
  2067. int r;
  2068. /* Read BIOS */
  2069. if (!radeon_get_bios(rdev)) {
  2070. if (ASIC_IS_AVIVO(rdev))
  2071. return -EINVAL;
  2072. }
  2073. /* Must be an ATOMBIOS */
  2074. if (!rdev->is_atom_bios) {
  2075. dev_err(rdev->dev, "Expecting atombios for cayman GPU\n");
  2076. return -EINVAL;
  2077. }
  2078. r = radeon_atombios_init(rdev);
  2079. if (r)
  2080. return r;
  2081. /* Post card if necessary */
  2082. if (!radeon_card_posted(rdev)) {
  2083. if (!rdev->bios) {
  2084. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  2085. return -EINVAL;
  2086. }
  2087. DRM_INFO("GPU not posted. posting now...\n");
  2088. atom_asic_init(rdev->mode_info.atom_context);
  2089. }
  2090. /* init golden registers */
  2091. ni_init_golden_registers(rdev);
  2092. /* Initialize scratch registers */
  2093. r600_scratch_init(rdev);
  2094. /* Initialize surface registers */
  2095. radeon_surface_init(rdev);
  2096. /* Initialize clocks */
  2097. radeon_get_clock_info(rdev_to_drm(rdev));
  2098. /* Fence driver */
  2099. radeon_fence_driver_init(rdev);
  2100. /* initialize memory controller */
  2101. r = evergreen_mc_init(rdev);
  2102. if (r)
  2103. return r;
  2104. /* Memory manager */
  2105. r = radeon_bo_init(rdev);
  2106. if (r)
  2107. return r;
  2108. if (rdev->flags & RADEON_IS_IGP) {
  2109. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  2110. r = ni_init_microcode(rdev);
  2111. if (r) {
  2112. DRM_ERROR("Failed to load firmware!\n");
  2113. return r;
  2114. }
  2115. }
  2116. } else {
  2117. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw || !rdev->mc_fw) {
  2118. r = ni_init_microcode(rdev);
  2119. if (r) {
  2120. DRM_ERROR("Failed to load firmware!\n");
  2121. return r;
  2122. }
  2123. }
  2124. }
  2125. /* Initialize power management */
  2126. radeon_pm_init(rdev);
  2127. ring->ring_obj = NULL;
  2128. r600_ring_init(rdev, ring, 1024 * 1024);
  2129. ring = &rdev->ring[R600_RING_TYPE_DMA_INDEX];
  2130. ring->ring_obj = NULL;
  2131. r600_ring_init(rdev, ring, 64 * 1024);
  2132. ring = &rdev->ring[CAYMAN_RING_TYPE_DMA1_INDEX];
  2133. ring->ring_obj = NULL;
  2134. r600_ring_init(rdev, ring, 64 * 1024);
  2135. cayman_uvd_init(rdev);
  2136. cayman_vce_init(rdev);
  2137. rdev->ih.ring_obj = NULL;
  2138. r600_ih_ring_init(rdev, 64 * 1024);
  2139. r = r600_pcie_gart_init(rdev);
  2140. if (r)
  2141. return r;
  2142. rdev->accel_working = true;
  2143. r = cayman_startup(rdev);
  2144. if (r) {
  2145. dev_err(rdev->dev, "disabling GPU acceleration\n");
  2146. cayman_cp_fini(rdev);
  2147. cayman_dma_fini(rdev);
  2148. r600_irq_fini(rdev);
  2149. if (rdev->flags & RADEON_IS_IGP)
  2150. sumo_rlc_fini(rdev);
  2151. radeon_wb_fini(rdev);
  2152. radeon_ib_pool_fini(rdev);
  2153. radeon_vm_manager_fini(rdev);
  2154. radeon_irq_kms_fini(rdev);
  2155. cayman_pcie_gart_fini(rdev);
  2156. rdev->accel_working = false;
  2157. }
  2158. /* Don't start up if the MC ucode is missing.
  2159. * The default clocks and voltages before the MC ucode
  2160. * is loaded are not suffient for advanced operations.
  2161. *
  2162. * We can skip this check for TN, because there is no MC
  2163. * ucode.
  2164. */
  2165. if (!rdev->mc_fw && !(rdev->flags & RADEON_IS_IGP)) {
  2166. DRM_ERROR("radeon: MC ucode required for NI+.\n");
  2167. return -EINVAL;
  2168. }
  2169. return 0;
  2170. }
  2171. void cayman_fini(struct radeon_device *rdev)
  2172. {
  2173. radeon_pm_fini(rdev);
  2174. cayman_cp_fini(rdev);
  2175. cayman_dma_fini(rdev);
  2176. r600_irq_fini(rdev);
  2177. if (rdev->flags & RADEON_IS_IGP)
  2178. sumo_rlc_fini(rdev);
  2179. radeon_wb_fini(rdev);
  2180. radeon_vm_manager_fini(rdev);
  2181. radeon_ib_pool_fini(rdev);
  2182. radeon_irq_kms_fini(rdev);
  2183. uvd_v1_0_fini(rdev);
  2184. radeon_uvd_fini(rdev);
  2185. if (rdev->has_vce)
  2186. radeon_vce_fini(rdev);
  2187. cayman_pcie_gart_fini(rdev);
  2188. r600_vram_scratch_fini(rdev);
  2189. radeon_gem_fini(rdev);
  2190. radeon_fence_driver_fini(rdev);
  2191. radeon_bo_fini(rdev);
  2192. radeon_atombios_fini(rdev);
  2193. kfree(rdev->bios);
  2194. rdev->bios = NULL;
  2195. }
  2196. /*
  2197. * vm
  2198. */
  2199. int cayman_vm_init(struct radeon_device *rdev)
  2200. {
  2201. /* number of VMs */
  2202. rdev->vm_manager.nvm = 8;
  2203. /* base offset of vram pages */
  2204. if (rdev->flags & RADEON_IS_IGP) {
  2205. u64 tmp = RREG32(FUS_MC_VM_FB_OFFSET);
  2206. tmp <<= 22;
  2207. rdev->vm_manager.vram_base_offset = tmp;
  2208. } else
  2209. rdev->vm_manager.vram_base_offset = 0;
  2210. return 0;
  2211. }
  2212. void cayman_vm_fini(struct radeon_device *rdev)
  2213. {
  2214. }
  2215. /**
  2216. * cayman_vm_decode_fault - print human readable fault info
  2217. *
  2218. * @rdev: radeon_device pointer
  2219. * @status: VM_CONTEXT1_PROTECTION_FAULT_STATUS register value
  2220. * @addr: VM_CONTEXT1_PROTECTION_FAULT_ADDR register value
  2221. *
  2222. * Print human readable fault information (cayman/TN).
  2223. */
  2224. void cayman_vm_decode_fault(struct radeon_device *rdev,
  2225. u32 status, u32 addr)
  2226. {
  2227. u32 mc_id = (status & MEMORY_CLIENT_ID_MASK) >> MEMORY_CLIENT_ID_SHIFT;
  2228. u32 vmid = (status & FAULT_VMID_MASK) >> FAULT_VMID_SHIFT;
  2229. u32 protections = (status & PROTECTIONS_MASK) >> PROTECTIONS_SHIFT;
  2230. char *block;
  2231. switch (mc_id) {
  2232. case 32:
  2233. case 16:
  2234. case 96:
  2235. case 80:
  2236. case 160:
  2237. case 144:
  2238. case 224:
  2239. case 208:
  2240. block = "CB";
  2241. break;
  2242. case 33:
  2243. case 17:
  2244. case 97:
  2245. case 81:
  2246. case 161:
  2247. case 145:
  2248. case 225:
  2249. case 209:
  2250. block = "CB_FMASK";
  2251. break;
  2252. case 34:
  2253. case 18:
  2254. case 98:
  2255. case 82:
  2256. case 162:
  2257. case 146:
  2258. case 226:
  2259. case 210:
  2260. block = "CB_CMASK";
  2261. break;
  2262. case 35:
  2263. case 19:
  2264. case 99:
  2265. case 83:
  2266. case 163:
  2267. case 147:
  2268. case 227:
  2269. case 211:
  2270. block = "CB_IMMED";
  2271. break;
  2272. case 36:
  2273. case 20:
  2274. case 100:
  2275. case 84:
  2276. case 164:
  2277. case 148:
  2278. case 228:
  2279. case 212:
  2280. block = "DB";
  2281. break;
  2282. case 37:
  2283. case 21:
  2284. case 101:
  2285. case 85:
  2286. case 165:
  2287. case 149:
  2288. case 229:
  2289. case 213:
  2290. block = "DB_HTILE";
  2291. break;
  2292. case 38:
  2293. case 22:
  2294. case 102:
  2295. case 86:
  2296. case 166:
  2297. case 150:
  2298. case 230:
  2299. case 214:
  2300. block = "SX";
  2301. break;
  2302. case 39:
  2303. case 23:
  2304. case 103:
  2305. case 87:
  2306. case 167:
  2307. case 151:
  2308. case 231:
  2309. case 215:
  2310. block = "DB_STEN";
  2311. break;
  2312. case 40:
  2313. case 24:
  2314. case 104:
  2315. case 88:
  2316. case 232:
  2317. case 216:
  2318. case 168:
  2319. case 152:
  2320. block = "TC_TFETCH";
  2321. break;
  2322. case 41:
  2323. case 25:
  2324. case 105:
  2325. case 89:
  2326. case 233:
  2327. case 217:
  2328. case 169:
  2329. case 153:
  2330. block = "TC_VFETCH";
  2331. break;
  2332. case 42:
  2333. case 26:
  2334. case 106:
  2335. case 90:
  2336. case 234:
  2337. case 218:
  2338. case 170:
  2339. case 154:
  2340. block = "VC";
  2341. break;
  2342. case 112:
  2343. block = "CP";
  2344. break;
  2345. case 113:
  2346. case 114:
  2347. block = "SH";
  2348. break;
  2349. case 115:
  2350. block = "VGT";
  2351. break;
  2352. case 178:
  2353. block = "IH";
  2354. break;
  2355. case 51:
  2356. block = "RLC";
  2357. break;
  2358. case 55:
  2359. block = "DMA";
  2360. break;
  2361. case 56:
  2362. block = "HDP";
  2363. break;
  2364. default:
  2365. block = "unknown";
  2366. break;
  2367. }
  2368. printk("VM fault (0x%02x, vmid %d) at page %u, %s from %s (%d)\n",
  2369. protections, vmid, addr,
  2370. (status & MEMORY_CLIENT_RW_MASK) ? "write" : "read",
  2371. block, mc_id);
  2372. }
  2373. /*
  2374. * cayman_vm_flush - vm flush using the CP
  2375. *
  2376. * Update the page table base and flush the VM TLB
  2377. * using the CP (cayman-si).
  2378. */
  2379. void cayman_vm_flush(struct radeon_device *rdev, struct radeon_ring *ring,
  2380. unsigned vm_id, uint64_t pd_addr)
  2381. {
  2382. radeon_ring_write(ring, PACKET0(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR + (vm_id << 2), 0));
  2383. radeon_ring_write(ring, pd_addr >> 12);
  2384. /* flush hdp cache */
  2385. radeon_ring_write(ring, PACKET0(HDP_MEM_COHERENCY_FLUSH_CNTL, 0));
  2386. radeon_ring_write(ring, 0x1);
  2387. /* bits 0-7 are the VM contexts0-7 */
  2388. radeon_ring_write(ring, PACKET0(VM_INVALIDATE_REQUEST, 0));
  2389. radeon_ring_write(ring, 1 << vm_id);
  2390. /* wait for the invalidate to complete */
  2391. radeon_ring_write(ring, PACKET3(PACKET3_WAIT_REG_MEM, 5));
  2392. radeon_ring_write(ring, (WAIT_REG_MEM_FUNCTION(0) | /* always */
  2393. WAIT_REG_MEM_ENGINE(0))); /* me */
  2394. radeon_ring_write(ring, VM_INVALIDATE_REQUEST >> 2);
  2395. radeon_ring_write(ring, 0);
  2396. radeon_ring_write(ring, 0); /* ref */
  2397. radeon_ring_write(ring, 0); /* mask */
  2398. radeon_ring_write(ring, 0x20); /* poll interval */
  2399. /* sync PFP to ME, otherwise we might get invalid PFP reads */
  2400. radeon_ring_write(ring, PACKET3(PACKET3_PFP_SYNC_ME, 0));
  2401. radeon_ring_write(ring, 0x0);
  2402. }
  2403. int tn_set_vce_clocks(struct radeon_device *rdev, u32 evclk, u32 ecclk)
  2404. {
  2405. struct atom_clock_dividers dividers;
  2406. int r, i;
  2407. r = radeon_atom_get_clock_dividers(rdev, COMPUTE_ENGINE_PLL_PARAM,
  2408. ecclk, false, &dividers);
  2409. if (r)
  2410. return r;
  2411. for (i = 0; i < 100; i++) {
  2412. if (RREG32(CG_ECLK_STATUS) & ECLK_STATUS)
  2413. break;
  2414. mdelay(10);
  2415. }
  2416. if (i == 100)
  2417. return -ETIMEDOUT;
  2418. WREG32_P(CG_ECLK_CNTL, dividers.post_div, ~(ECLK_DIR_CNTL_EN|ECLK_DIVIDER_MASK));
  2419. for (i = 0; i < 100; i++) {
  2420. if (RREG32(CG_ECLK_STATUS) & ECLK_STATUS)
  2421. break;
  2422. mdelay(10);
  2423. }
  2424. if (i == 100)
  2425. return -ETIMEDOUT;
  2426. return 0;
  2427. }