ni.c 70 KB

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