ni.c 71 KB

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