ni.c 71 KB

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