r600.c 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935
  1. /*
  2. * Copyright 2008 Advanced Micro Devices, Inc.
  3. * Copyright 2008 Red Hat Inc.
  4. * Copyright 2009 Jerome Glisse.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. * OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors: Dave Airlie
  25. * Alex Deucher
  26. * Jerome Glisse
  27. */
  28. #include <linux/seq_file.h>
  29. #include <linux/firmware.h>
  30. #include <linux/platform_device.h>
  31. #include "drmP.h"
  32. #include "radeon_drm.h"
  33. #include "radeon.h"
  34. #include "radeon_asic.h"
  35. #include "radeon_mode.h"
  36. #include "r600d.h"
  37. #include "atom.h"
  38. #include "avivod.h"
  39. #define PFP_UCODE_SIZE 576
  40. #define PM4_UCODE_SIZE 1792
  41. #define RLC_UCODE_SIZE 768
  42. #define R700_PFP_UCODE_SIZE 848
  43. #define R700_PM4_UCODE_SIZE 1360
  44. #define R700_RLC_UCODE_SIZE 1024
  45. /* Firmware Names */
  46. MODULE_FIRMWARE("radeon/R600_pfp.bin");
  47. MODULE_FIRMWARE("radeon/R600_me.bin");
  48. MODULE_FIRMWARE("radeon/RV610_pfp.bin");
  49. MODULE_FIRMWARE("radeon/RV610_me.bin");
  50. MODULE_FIRMWARE("radeon/RV630_pfp.bin");
  51. MODULE_FIRMWARE("radeon/RV630_me.bin");
  52. MODULE_FIRMWARE("radeon/RV620_pfp.bin");
  53. MODULE_FIRMWARE("radeon/RV620_me.bin");
  54. MODULE_FIRMWARE("radeon/RV635_pfp.bin");
  55. MODULE_FIRMWARE("radeon/RV635_me.bin");
  56. MODULE_FIRMWARE("radeon/RV670_pfp.bin");
  57. MODULE_FIRMWARE("radeon/RV670_me.bin");
  58. MODULE_FIRMWARE("radeon/RS780_pfp.bin");
  59. MODULE_FIRMWARE("radeon/RS780_me.bin");
  60. MODULE_FIRMWARE("radeon/RV770_pfp.bin");
  61. MODULE_FIRMWARE("radeon/RV770_me.bin");
  62. MODULE_FIRMWARE("radeon/RV730_pfp.bin");
  63. MODULE_FIRMWARE("radeon/RV730_me.bin");
  64. MODULE_FIRMWARE("radeon/RV710_pfp.bin");
  65. MODULE_FIRMWARE("radeon/RV710_me.bin");
  66. MODULE_FIRMWARE("radeon/R600_rlc.bin");
  67. MODULE_FIRMWARE("radeon/R700_rlc.bin");
  68. int r600_debugfs_mc_info_init(struct radeon_device *rdev);
  69. /* r600,rv610,rv630,rv620,rv635,rv670 */
  70. int r600_mc_wait_for_idle(struct radeon_device *rdev);
  71. void r600_gpu_init(struct radeon_device *rdev);
  72. void r600_fini(struct radeon_device *rdev);
  73. /* hpd for digital panel detect/disconnect */
  74. bool r600_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd)
  75. {
  76. bool connected = false;
  77. if (ASIC_IS_DCE3(rdev)) {
  78. switch (hpd) {
  79. case RADEON_HPD_1:
  80. if (RREG32(DC_HPD1_INT_STATUS) & DC_HPDx_SENSE)
  81. connected = true;
  82. break;
  83. case RADEON_HPD_2:
  84. if (RREG32(DC_HPD2_INT_STATUS) & DC_HPDx_SENSE)
  85. connected = true;
  86. break;
  87. case RADEON_HPD_3:
  88. if (RREG32(DC_HPD3_INT_STATUS) & DC_HPDx_SENSE)
  89. connected = true;
  90. break;
  91. case RADEON_HPD_4:
  92. if (RREG32(DC_HPD4_INT_STATUS) & DC_HPDx_SENSE)
  93. connected = true;
  94. break;
  95. /* DCE 3.2 */
  96. case RADEON_HPD_5:
  97. if (RREG32(DC_HPD5_INT_STATUS) & DC_HPDx_SENSE)
  98. connected = true;
  99. break;
  100. case RADEON_HPD_6:
  101. if (RREG32(DC_HPD6_INT_STATUS) & DC_HPDx_SENSE)
  102. connected = true;
  103. break;
  104. default:
  105. break;
  106. }
  107. } else {
  108. switch (hpd) {
  109. case RADEON_HPD_1:
  110. if (RREG32(DC_HOT_PLUG_DETECT1_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  111. connected = true;
  112. break;
  113. case RADEON_HPD_2:
  114. if (RREG32(DC_HOT_PLUG_DETECT2_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  115. connected = true;
  116. break;
  117. case RADEON_HPD_3:
  118. if (RREG32(DC_HOT_PLUG_DETECT3_INT_STATUS) & DC_HOT_PLUG_DETECTx_SENSE)
  119. connected = true;
  120. break;
  121. default:
  122. break;
  123. }
  124. }
  125. return connected;
  126. }
  127. void r600_hpd_set_polarity(struct radeon_device *rdev,
  128. enum radeon_hpd_id hpd)
  129. {
  130. u32 tmp;
  131. bool connected = r600_hpd_sense(rdev, hpd);
  132. if (ASIC_IS_DCE3(rdev)) {
  133. switch (hpd) {
  134. case RADEON_HPD_1:
  135. tmp = RREG32(DC_HPD1_INT_CONTROL);
  136. if (connected)
  137. tmp &= ~DC_HPDx_INT_POLARITY;
  138. else
  139. tmp |= DC_HPDx_INT_POLARITY;
  140. WREG32(DC_HPD1_INT_CONTROL, tmp);
  141. break;
  142. case RADEON_HPD_2:
  143. tmp = RREG32(DC_HPD2_INT_CONTROL);
  144. if (connected)
  145. tmp &= ~DC_HPDx_INT_POLARITY;
  146. else
  147. tmp |= DC_HPDx_INT_POLARITY;
  148. WREG32(DC_HPD2_INT_CONTROL, tmp);
  149. break;
  150. case RADEON_HPD_3:
  151. tmp = RREG32(DC_HPD3_INT_CONTROL);
  152. if (connected)
  153. tmp &= ~DC_HPDx_INT_POLARITY;
  154. else
  155. tmp |= DC_HPDx_INT_POLARITY;
  156. WREG32(DC_HPD3_INT_CONTROL, tmp);
  157. break;
  158. case RADEON_HPD_4:
  159. tmp = RREG32(DC_HPD4_INT_CONTROL);
  160. if (connected)
  161. tmp &= ~DC_HPDx_INT_POLARITY;
  162. else
  163. tmp |= DC_HPDx_INT_POLARITY;
  164. WREG32(DC_HPD4_INT_CONTROL, tmp);
  165. break;
  166. case RADEON_HPD_5:
  167. tmp = RREG32(DC_HPD5_INT_CONTROL);
  168. if (connected)
  169. tmp &= ~DC_HPDx_INT_POLARITY;
  170. else
  171. tmp |= DC_HPDx_INT_POLARITY;
  172. WREG32(DC_HPD5_INT_CONTROL, tmp);
  173. break;
  174. /* DCE 3.2 */
  175. case RADEON_HPD_6:
  176. tmp = RREG32(DC_HPD6_INT_CONTROL);
  177. if (connected)
  178. tmp &= ~DC_HPDx_INT_POLARITY;
  179. else
  180. tmp |= DC_HPDx_INT_POLARITY;
  181. WREG32(DC_HPD6_INT_CONTROL, tmp);
  182. break;
  183. default:
  184. break;
  185. }
  186. } else {
  187. switch (hpd) {
  188. case RADEON_HPD_1:
  189. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
  190. if (connected)
  191. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  192. else
  193. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  194. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  195. break;
  196. case RADEON_HPD_2:
  197. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
  198. if (connected)
  199. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  200. else
  201. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  202. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  203. break;
  204. case RADEON_HPD_3:
  205. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
  206. if (connected)
  207. tmp &= ~DC_HOT_PLUG_DETECTx_INT_POLARITY;
  208. else
  209. tmp |= DC_HOT_PLUG_DETECTx_INT_POLARITY;
  210. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  211. break;
  212. default:
  213. break;
  214. }
  215. }
  216. }
  217. void r600_hpd_init(struct radeon_device *rdev)
  218. {
  219. struct drm_device *dev = rdev->ddev;
  220. struct drm_connector *connector;
  221. if (ASIC_IS_DCE3(rdev)) {
  222. u32 tmp = DC_HPDx_CONNECTION_TIMER(0x9c4) | DC_HPDx_RX_INT_TIMER(0xfa);
  223. if (ASIC_IS_DCE32(rdev))
  224. tmp |= DC_HPDx_EN;
  225. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  226. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  227. switch (radeon_connector->hpd.hpd) {
  228. case RADEON_HPD_1:
  229. WREG32(DC_HPD1_CONTROL, tmp);
  230. rdev->irq.hpd[0] = true;
  231. break;
  232. case RADEON_HPD_2:
  233. WREG32(DC_HPD2_CONTROL, tmp);
  234. rdev->irq.hpd[1] = true;
  235. break;
  236. case RADEON_HPD_3:
  237. WREG32(DC_HPD3_CONTROL, tmp);
  238. rdev->irq.hpd[2] = true;
  239. break;
  240. case RADEON_HPD_4:
  241. WREG32(DC_HPD4_CONTROL, tmp);
  242. rdev->irq.hpd[3] = true;
  243. break;
  244. /* DCE 3.2 */
  245. case RADEON_HPD_5:
  246. WREG32(DC_HPD5_CONTROL, tmp);
  247. rdev->irq.hpd[4] = true;
  248. break;
  249. case RADEON_HPD_6:
  250. WREG32(DC_HPD6_CONTROL, tmp);
  251. rdev->irq.hpd[5] = true;
  252. break;
  253. default:
  254. break;
  255. }
  256. }
  257. } else {
  258. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  259. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  260. switch (radeon_connector->hpd.hpd) {
  261. case RADEON_HPD_1:
  262. WREG32(DC_HOT_PLUG_DETECT1_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  263. rdev->irq.hpd[0] = true;
  264. break;
  265. case RADEON_HPD_2:
  266. WREG32(DC_HOT_PLUG_DETECT2_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  267. rdev->irq.hpd[1] = true;
  268. break;
  269. case RADEON_HPD_3:
  270. WREG32(DC_HOT_PLUG_DETECT3_CONTROL, DC_HOT_PLUG_DETECTx_EN);
  271. rdev->irq.hpd[2] = true;
  272. break;
  273. default:
  274. break;
  275. }
  276. }
  277. }
  278. if (rdev->irq.installed)
  279. r600_irq_set(rdev);
  280. }
  281. void r600_hpd_fini(struct radeon_device *rdev)
  282. {
  283. struct drm_device *dev = rdev->ddev;
  284. struct drm_connector *connector;
  285. if (ASIC_IS_DCE3(rdev)) {
  286. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  287. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  288. switch (radeon_connector->hpd.hpd) {
  289. case RADEON_HPD_1:
  290. WREG32(DC_HPD1_CONTROL, 0);
  291. rdev->irq.hpd[0] = false;
  292. break;
  293. case RADEON_HPD_2:
  294. WREG32(DC_HPD2_CONTROL, 0);
  295. rdev->irq.hpd[1] = false;
  296. break;
  297. case RADEON_HPD_3:
  298. WREG32(DC_HPD3_CONTROL, 0);
  299. rdev->irq.hpd[2] = false;
  300. break;
  301. case RADEON_HPD_4:
  302. WREG32(DC_HPD4_CONTROL, 0);
  303. rdev->irq.hpd[3] = false;
  304. break;
  305. /* DCE 3.2 */
  306. case RADEON_HPD_5:
  307. WREG32(DC_HPD5_CONTROL, 0);
  308. rdev->irq.hpd[4] = false;
  309. break;
  310. case RADEON_HPD_6:
  311. WREG32(DC_HPD6_CONTROL, 0);
  312. rdev->irq.hpd[5] = false;
  313. break;
  314. default:
  315. break;
  316. }
  317. }
  318. } else {
  319. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  320. struct radeon_connector *radeon_connector = to_radeon_connector(connector);
  321. switch (radeon_connector->hpd.hpd) {
  322. case RADEON_HPD_1:
  323. WREG32(DC_HOT_PLUG_DETECT1_CONTROL, 0);
  324. rdev->irq.hpd[0] = false;
  325. break;
  326. case RADEON_HPD_2:
  327. WREG32(DC_HOT_PLUG_DETECT2_CONTROL, 0);
  328. rdev->irq.hpd[1] = false;
  329. break;
  330. case RADEON_HPD_3:
  331. WREG32(DC_HOT_PLUG_DETECT3_CONTROL, 0);
  332. rdev->irq.hpd[2] = false;
  333. break;
  334. default:
  335. break;
  336. }
  337. }
  338. }
  339. }
  340. /*
  341. * R600 PCIE GART
  342. */
  343. void r600_pcie_gart_tlb_flush(struct radeon_device *rdev)
  344. {
  345. unsigned i;
  346. u32 tmp;
  347. /* flush hdp cache so updates hit vram */
  348. WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  349. WREG32(VM_CONTEXT0_INVALIDATION_LOW_ADDR, rdev->mc.gtt_start >> 12);
  350. WREG32(VM_CONTEXT0_INVALIDATION_HIGH_ADDR, (rdev->mc.gtt_end - 1) >> 12);
  351. WREG32(VM_CONTEXT0_REQUEST_RESPONSE, REQUEST_TYPE(1));
  352. for (i = 0; i < rdev->usec_timeout; i++) {
  353. /* read MC_STATUS */
  354. tmp = RREG32(VM_CONTEXT0_REQUEST_RESPONSE);
  355. tmp = (tmp & RESPONSE_TYPE_MASK) >> RESPONSE_TYPE_SHIFT;
  356. if (tmp == 2) {
  357. printk(KERN_WARNING "[drm] r600 flush TLB failed\n");
  358. return;
  359. }
  360. if (tmp) {
  361. return;
  362. }
  363. udelay(1);
  364. }
  365. }
  366. int r600_pcie_gart_init(struct radeon_device *rdev)
  367. {
  368. int r;
  369. if (rdev->gart.table.vram.robj) {
  370. WARN(1, "R600 PCIE GART already initialized.\n");
  371. return 0;
  372. }
  373. /* Initialize common gart structure */
  374. r = radeon_gart_init(rdev);
  375. if (r)
  376. return r;
  377. rdev->gart.table_size = rdev->gart.num_gpu_pages * 8;
  378. return radeon_gart_table_vram_alloc(rdev);
  379. }
  380. int r600_pcie_gart_enable(struct radeon_device *rdev)
  381. {
  382. u32 tmp;
  383. int r, i;
  384. if (rdev->gart.table.vram.robj == NULL) {
  385. dev_err(rdev->dev, "No VRAM object for PCIE GART.\n");
  386. return -EINVAL;
  387. }
  388. r = radeon_gart_table_vram_pin(rdev);
  389. if (r)
  390. return r;
  391. radeon_gart_restore(rdev);
  392. /* Setup L2 cache */
  393. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  394. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  395. EFFECTIVE_L2_QUEUE_SIZE(7));
  396. WREG32(VM_L2_CNTL2, 0);
  397. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  398. /* Setup TLB control */
  399. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  400. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  401. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  402. ENABLE_WAIT_L2_QUERY;
  403. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  404. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  405. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
  406. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  407. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  408. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  409. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  410. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  411. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  412. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  413. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  414. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  415. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  416. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  417. WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12);
  418. WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12);
  419. WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12);
  420. WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) |
  421. RANGE_PROTECTION_FAULT_ENABLE_DEFAULT);
  422. WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR,
  423. (u32)(rdev->dummy_page.addr >> 12));
  424. for (i = 1; i < 7; i++)
  425. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  426. r600_pcie_gart_tlb_flush(rdev);
  427. rdev->gart.ready = true;
  428. return 0;
  429. }
  430. void r600_pcie_gart_disable(struct radeon_device *rdev)
  431. {
  432. u32 tmp;
  433. int i, r;
  434. /* Disable all tables */
  435. for (i = 0; i < 7; i++)
  436. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  437. /* Disable L2 cache */
  438. WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING |
  439. EFFECTIVE_L2_QUEUE_SIZE(7));
  440. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  441. /* Setup L1 TLB control */
  442. tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  443. ENABLE_WAIT_L2_QUERY;
  444. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  445. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  446. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  447. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  448. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  449. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  450. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  451. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  452. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp);
  453. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp);
  454. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  455. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  456. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp);
  457. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  458. if (rdev->gart.table.vram.robj) {
  459. r = radeon_bo_reserve(rdev->gart.table.vram.robj, false);
  460. if (likely(r == 0)) {
  461. radeon_bo_kunmap(rdev->gart.table.vram.robj);
  462. radeon_bo_unpin(rdev->gart.table.vram.robj);
  463. radeon_bo_unreserve(rdev->gart.table.vram.robj);
  464. }
  465. }
  466. }
  467. void r600_pcie_gart_fini(struct radeon_device *rdev)
  468. {
  469. radeon_gart_fini(rdev);
  470. r600_pcie_gart_disable(rdev);
  471. radeon_gart_table_vram_free(rdev);
  472. }
  473. void r600_agp_enable(struct radeon_device *rdev)
  474. {
  475. u32 tmp;
  476. int i;
  477. /* Setup L2 cache */
  478. WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING |
  479. ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE |
  480. EFFECTIVE_L2_QUEUE_SIZE(7));
  481. WREG32(VM_L2_CNTL2, 0);
  482. WREG32(VM_L2_CNTL3, BANK_SELECT_0(0) | BANK_SELECT_1(1));
  483. /* Setup TLB control */
  484. tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING |
  485. SYSTEM_ACCESS_MODE_NOT_IN_SYS |
  486. EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5) |
  487. ENABLE_WAIT_L2_QUERY;
  488. WREG32(MC_VM_L1_TLB_MCB_RD_SYS_CNTL, tmp);
  489. WREG32(MC_VM_L1_TLB_MCB_WR_SYS_CNTL, tmp);
  490. WREG32(MC_VM_L1_TLB_MCB_RD_HDP_CNTL, tmp | ENABLE_L1_STRICT_ORDERING);
  491. WREG32(MC_VM_L1_TLB_MCB_WR_HDP_CNTL, tmp);
  492. WREG32(MC_VM_L1_TLB_MCD_RD_A_CNTL, tmp);
  493. WREG32(MC_VM_L1_TLB_MCD_WR_A_CNTL, tmp);
  494. WREG32(MC_VM_L1_TLB_MCD_RD_B_CNTL, tmp);
  495. WREG32(MC_VM_L1_TLB_MCD_WR_B_CNTL, tmp);
  496. WREG32(MC_VM_L1_TLB_MCB_RD_GFX_CNTL, tmp);
  497. WREG32(MC_VM_L1_TLB_MCB_WR_GFX_CNTL, tmp);
  498. WREG32(MC_VM_L1_TLB_MCB_RD_PDMA_CNTL, tmp);
  499. WREG32(MC_VM_L1_TLB_MCB_WR_PDMA_CNTL, tmp);
  500. WREG32(MC_VM_L1_TLB_MCB_RD_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  501. WREG32(MC_VM_L1_TLB_MCB_WR_SEM_CNTL, tmp | ENABLE_SEMAPHORE_MODE);
  502. for (i = 0; i < 7; i++)
  503. WREG32(VM_CONTEXT0_CNTL + (i * 4), 0);
  504. }
  505. int r600_mc_wait_for_idle(struct radeon_device *rdev)
  506. {
  507. unsigned i;
  508. u32 tmp;
  509. for (i = 0; i < rdev->usec_timeout; i++) {
  510. /* read MC_STATUS */
  511. tmp = RREG32(R_000E50_SRBM_STATUS) & 0x3F00;
  512. if (!tmp)
  513. return 0;
  514. udelay(1);
  515. }
  516. return -1;
  517. }
  518. static void r600_mc_program(struct radeon_device *rdev)
  519. {
  520. struct rv515_mc_save save;
  521. u32 tmp;
  522. int i, j;
  523. /* Initialize HDP */
  524. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  525. WREG32((0x2c14 + j), 0x00000000);
  526. WREG32((0x2c18 + j), 0x00000000);
  527. WREG32((0x2c1c + j), 0x00000000);
  528. WREG32((0x2c20 + j), 0x00000000);
  529. WREG32((0x2c24 + j), 0x00000000);
  530. }
  531. WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0);
  532. rv515_mc_stop(rdev, &save);
  533. if (r600_mc_wait_for_idle(rdev)) {
  534. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  535. }
  536. /* Lockout access through VGA aperture (doesn't exist before R600) */
  537. WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE);
  538. /* Update configuration */
  539. if (rdev->flags & RADEON_IS_AGP) {
  540. if (rdev->mc.vram_start < rdev->mc.gtt_start) {
  541. /* VRAM before AGP */
  542. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  543. rdev->mc.vram_start >> 12);
  544. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  545. rdev->mc.gtt_end >> 12);
  546. } else {
  547. /* VRAM after AGP */
  548. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR,
  549. rdev->mc.gtt_start >> 12);
  550. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR,
  551. rdev->mc.vram_end >> 12);
  552. }
  553. } else {
  554. WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, rdev->mc.vram_start >> 12);
  555. WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, rdev->mc.vram_end >> 12);
  556. }
  557. WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0);
  558. tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16;
  559. tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF);
  560. WREG32(MC_VM_FB_LOCATION, tmp);
  561. WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8));
  562. WREG32(HDP_NONSURFACE_INFO, (2 << 7));
  563. WREG32(HDP_NONSURFACE_SIZE, rdev->mc.mc_vram_size | 0x3FF);
  564. if (rdev->flags & RADEON_IS_AGP) {
  565. WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 22);
  566. WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 22);
  567. WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22);
  568. } else {
  569. WREG32(MC_VM_AGP_BASE, 0);
  570. WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF);
  571. WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF);
  572. }
  573. if (r600_mc_wait_for_idle(rdev)) {
  574. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  575. }
  576. rv515_mc_resume(rdev, &save);
  577. /* we need to own VRAM, so turn off the VGA renderer here
  578. * to stop it overwriting our objects */
  579. rv515_vga_render_disable(rdev);
  580. }
  581. /**
  582. * r600_vram_gtt_location - try to find VRAM & GTT location
  583. * @rdev: radeon device structure holding all necessary informations
  584. * @mc: memory controller structure holding memory informations
  585. *
  586. * Function will place try to place VRAM at same place as in CPU (PCI)
  587. * address space as some GPU seems to have issue when we reprogram at
  588. * different address space.
  589. *
  590. * If there is not enough space to fit the unvisible VRAM after the
  591. * aperture then we limit the VRAM size to the aperture.
  592. *
  593. * If we are using AGP then place VRAM adjacent to AGP aperture are we need
  594. * them to be in one from GPU point of view so that we can program GPU to
  595. * catch access outside them (weird GPU policy see ??).
  596. *
  597. * This function will never fails, worst case are limiting VRAM or GTT.
  598. *
  599. * Note: GTT start, end, size should be initialized before calling this
  600. * function on AGP platform.
  601. */
  602. void r600_vram_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc)
  603. {
  604. u64 size_bf, size_af;
  605. if (mc->mc_vram_size > 0xE0000000) {
  606. /* leave room for at least 512M GTT */
  607. dev_warn(rdev->dev, "limiting VRAM\n");
  608. mc->real_vram_size = 0xE0000000;
  609. mc->mc_vram_size = 0xE0000000;
  610. }
  611. if (rdev->flags & RADEON_IS_AGP) {
  612. size_bf = mc->gtt_start;
  613. size_af = 0xFFFFFFFF - mc->gtt_end + 1;
  614. if (size_bf > size_af) {
  615. if (mc->mc_vram_size > size_bf) {
  616. dev_warn(rdev->dev, "limiting VRAM\n");
  617. mc->real_vram_size = size_bf;
  618. mc->mc_vram_size = size_bf;
  619. }
  620. mc->vram_start = mc->gtt_start - mc->mc_vram_size;
  621. } else {
  622. if (mc->mc_vram_size > size_af) {
  623. dev_warn(rdev->dev, "limiting VRAM\n");
  624. mc->real_vram_size = size_af;
  625. mc->mc_vram_size = size_af;
  626. }
  627. mc->vram_start = mc->gtt_end;
  628. }
  629. mc->vram_end = mc->vram_start + mc->mc_vram_size - 1;
  630. dev_info(rdev->dev, "VRAM: %lluM 0x%08llX - 0x%08llX (%lluM used)\n",
  631. mc->mc_vram_size >> 20, mc->vram_start,
  632. mc->vram_end, mc->real_vram_size >> 20);
  633. } else {
  634. u64 base = 0;
  635. if (rdev->flags & RADEON_IS_IGP)
  636. base = (RREG32(MC_VM_FB_LOCATION) & 0xFFFF) << 24;
  637. radeon_vram_location(rdev, &rdev->mc, base);
  638. radeon_gtt_location(rdev, mc);
  639. }
  640. }
  641. int r600_mc_init(struct radeon_device *rdev)
  642. {
  643. u32 tmp;
  644. int chansize, numchan;
  645. /* Get VRAM informations */
  646. rdev->mc.vram_is_ddr = true;
  647. tmp = RREG32(RAMCFG);
  648. if (tmp & CHANSIZE_OVERRIDE) {
  649. chansize = 16;
  650. } else if (tmp & CHANSIZE_MASK) {
  651. chansize = 64;
  652. } else {
  653. chansize = 32;
  654. }
  655. tmp = RREG32(CHMAP);
  656. switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) {
  657. case 0:
  658. default:
  659. numchan = 1;
  660. break;
  661. case 1:
  662. numchan = 2;
  663. break;
  664. case 2:
  665. numchan = 4;
  666. break;
  667. case 3:
  668. numchan = 8;
  669. break;
  670. }
  671. rdev->mc.vram_width = numchan * chansize;
  672. /* Could aper size report 0 ? */
  673. rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0);
  674. rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0);
  675. /* Setup GPU memory space */
  676. rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE);
  677. rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE);
  678. rdev->mc.visible_vram_size = rdev->mc.aper_size;
  679. /* FIXME remove this once we support unmappable VRAM */
  680. if (rdev->mc.mc_vram_size > rdev->mc.aper_size) {
  681. rdev->mc.mc_vram_size = rdev->mc.aper_size;
  682. rdev->mc.real_vram_size = rdev->mc.aper_size;
  683. }
  684. r600_vram_gtt_location(rdev, &rdev->mc);
  685. if (rdev->flags & RADEON_IS_IGP)
  686. rdev->mc.igp_sideport_enabled = radeon_atombios_sideport_present(rdev);
  687. radeon_update_bandwidth_info(rdev);
  688. return 0;
  689. }
  690. /* We doesn't check that the GPU really needs a reset we simply do the
  691. * reset, it's up to the caller to determine if the GPU needs one. We
  692. * might add an helper function to check that.
  693. */
  694. int r600_gpu_soft_reset(struct radeon_device *rdev)
  695. {
  696. struct rv515_mc_save save;
  697. u32 grbm_busy_mask = S_008010_VC_BUSY(1) | S_008010_VGT_BUSY_NO_DMA(1) |
  698. S_008010_VGT_BUSY(1) | S_008010_TA03_BUSY(1) |
  699. S_008010_TC_BUSY(1) | S_008010_SX_BUSY(1) |
  700. S_008010_SH_BUSY(1) | S_008010_SPI03_BUSY(1) |
  701. S_008010_SMX_BUSY(1) | S_008010_SC_BUSY(1) |
  702. S_008010_PA_BUSY(1) | S_008010_DB03_BUSY(1) |
  703. S_008010_CR_BUSY(1) | S_008010_CB03_BUSY(1) |
  704. S_008010_GUI_ACTIVE(1);
  705. u32 grbm2_busy_mask = S_008014_SPI0_BUSY(1) | S_008014_SPI1_BUSY(1) |
  706. S_008014_SPI2_BUSY(1) | S_008014_SPI3_BUSY(1) |
  707. S_008014_TA0_BUSY(1) | S_008014_TA1_BUSY(1) |
  708. S_008014_TA2_BUSY(1) | S_008014_TA3_BUSY(1) |
  709. S_008014_DB0_BUSY(1) | S_008014_DB1_BUSY(1) |
  710. S_008014_DB2_BUSY(1) | S_008014_DB3_BUSY(1) |
  711. S_008014_CB0_BUSY(1) | S_008014_CB1_BUSY(1) |
  712. S_008014_CB2_BUSY(1) | S_008014_CB3_BUSY(1);
  713. u32 tmp;
  714. dev_info(rdev->dev, "GPU softreset \n");
  715. dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
  716. RREG32(R_008010_GRBM_STATUS));
  717. dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
  718. RREG32(R_008014_GRBM_STATUS2));
  719. dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
  720. RREG32(R_000E50_SRBM_STATUS));
  721. rv515_mc_stop(rdev, &save);
  722. if (r600_mc_wait_for_idle(rdev)) {
  723. dev_warn(rdev->dev, "Wait for MC idle timedout !\n");
  724. }
  725. /* Disable CP parsing/prefetching */
  726. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
  727. /* Check if any of the rendering block is busy and reset it */
  728. if ((RREG32(R_008010_GRBM_STATUS) & grbm_busy_mask) ||
  729. (RREG32(R_008014_GRBM_STATUS2) & grbm2_busy_mask)) {
  730. tmp = S_008020_SOFT_RESET_CR(1) |
  731. S_008020_SOFT_RESET_DB(1) |
  732. S_008020_SOFT_RESET_CB(1) |
  733. S_008020_SOFT_RESET_PA(1) |
  734. S_008020_SOFT_RESET_SC(1) |
  735. S_008020_SOFT_RESET_SMX(1) |
  736. S_008020_SOFT_RESET_SPI(1) |
  737. S_008020_SOFT_RESET_SX(1) |
  738. S_008020_SOFT_RESET_SH(1) |
  739. S_008020_SOFT_RESET_TC(1) |
  740. S_008020_SOFT_RESET_TA(1) |
  741. S_008020_SOFT_RESET_VC(1) |
  742. S_008020_SOFT_RESET_VGT(1);
  743. dev_info(rdev->dev, " R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
  744. WREG32(R_008020_GRBM_SOFT_RESET, tmp);
  745. RREG32(R_008020_GRBM_SOFT_RESET);
  746. mdelay(15);
  747. WREG32(R_008020_GRBM_SOFT_RESET, 0);
  748. }
  749. /* Reset CP (we always reset CP) */
  750. tmp = S_008020_SOFT_RESET_CP(1);
  751. dev_info(rdev->dev, "R_008020_GRBM_SOFT_RESET=0x%08X\n", tmp);
  752. WREG32(R_008020_GRBM_SOFT_RESET, tmp);
  753. RREG32(R_008020_GRBM_SOFT_RESET);
  754. mdelay(15);
  755. WREG32(R_008020_GRBM_SOFT_RESET, 0);
  756. /* Wait a little for things to settle down */
  757. mdelay(1);
  758. dev_info(rdev->dev, " R_008010_GRBM_STATUS=0x%08X\n",
  759. RREG32(R_008010_GRBM_STATUS));
  760. dev_info(rdev->dev, " R_008014_GRBM_STATUS2=0x%08X\n",
  761. RREG32(R_008014_GRBM_STATUS2));
  762. dev_info(rdev->dev, " R_000E50_SRBM_STATUS=0x%08X\n",
  763. RREG32(R_000E50_SRBM_STATUS));
  764. rv515_mc_resume(rdev, &save);
  765. return 0;
  766. }
  767. bool r600_gpu_is_lockup(struct radeon_device *rdev)
  768. {
  769. u32 srbm_status;
  770. u32 grbm_status;
  771. u32 grbm_status2;
  772. int r;
  773. srbm_status = RREG32(R_000E50_SRBM_STATUS);
  774. grbm_status = RREG32(R_008010_GRBM_STATUS);
  775. grbm_status2 = RREG32(R_008014_GRBM_STATUS2);
  776. if (!G_008010_GUI_ACTIVE(grbm_status)) {
  777. r100_gpu_lockup_update(&rdev->config.r300.lockup, &rdev->cp);
  778. return false;
  779. }
  780. /* force CP activities */
  781. r = radeon_ring_lock(rdev, 2);
  782. if (!r) {
  783. /* PACKET2 NOP */
  784. radeon_ring_write(rdev, 0x80000000);
  785. radeon_ring_write(rdev, 0x80000000);
  786. radeon_ring_unlock_commit(rdev);
  787. }
  788. rdev->cp.rptr = RREG32(R600_CP_RB_RPTR);
  789. return r100_gpu_cp_is_lockup(rdev, &rdev->config.r300.lockup, &rdev->cp);
  790. }
  791. int r600_asic_reset(struct radeon_device *rdev)
  792. {
  793. return r600_gpu_soft_reset(rdev);
  794. }
  795. static u32 r600_get_tile_pipe_to_backend_map(u32 num_tile_pipes,
  796. u32 num_backends,
  797. u32 backend_disable_mask)
  798. {
  799. u32 backend_map = 0;
  800. u32 enabled_backends_mask;
  801. u32 enabled_backends_count;
  802. u32 cur_pipe;
  803. u32 swizzle_pipe[R6XX_MAX_PIPES];
  804. u32 cur_backend;
  805. u32 i;
  806. if (num_tile_pipes > R6XX_MAX_PIPES)
  807. num_tile_pipes = R6XX_MAX_PIPES;
  808. if (num_tile_pipes < 1)
  809. num_tile_pipes = 1;
  810. if (num_backends > R6XX_MAX_BACKENDS)
  811. num_backends = R6XX_MAX_BACKENDS;
  812. if (num_backends < 1)
  813. num_backends = 1;
  814. enabled_backends_mask = 0;
  815. enabled_backends_count = 0;
  816. for (i = 0; i < R6XX_MAX_BACKENDS; ++i) {
  817. if (((backend_disable_mask >> i) & 1) == 0) {
  818. enabled_backends_mask |= (1 << i);
  819. ++enabled_backends_count;
  820. }
  821. if (enabled_backends_count == num_backends)
  822. break;
  823. }
  824. if (enabled_backends_count == 0) {
  825. enabled_backends_mask = 1;
  826. enabled_backends_count = 1;
  827. }
  828. if (enabled_backends_count != num_backends)
  829. num_backends = enabled_backends_count;
  830. memset((uint8_t *)&swizzle_pipe[0], 0, sizeof(u32) * R6XX_MAX_PIPES);
  831. switch (num_tile_pipes) {
  832. case 1:
  833. swizzle_pipe[0] = 0;
  834. break;
  835. case 2:
  836. swizzle_pipe[0] = 0;
  837. swizzle_pipe[1] = 1;
  838. break;
  839. case 3:
  840. swizzle_pipe[0] = 0;
  841. swizzle_pipe[1] = 1;
  842. swizzle_pipe[2] = 2;
  843. break;
  844. case 4:
  845. swizzle_pipe[0] = 0;
  846. swizzle_pipe[1] = 1;
  847. swizzle_pipe[2] = 2;
  848. swizzle_pipe[3] = 3;
  849. break;
  850. case 5:
  851. swizzle_pipe[0] = 0;
  852. swizzle_pipe[1] = 1;
  853. swizzle_pipe[2] = 2;
  854. swizzle_pipe[3] = 3;
  855. swizzle_pipe[4] = 4;
  856. break;
  857. case 6:
  858. swizzle_pipe[0] = 0;
  859. swizzle_pipe[1] = 2;
  860. swizzle_pipe[2] = 4;
  861. swizzle_pipe[3] = 5;
  862. swizzle_pipe[4] = 1;
  863. swizzle_pipe[5] = 3;
  864. break;
  865. case 7:
  866. swizzle_pipe[0] = 0;
  867. swizzle_pipe[1] = 2;
  868. swizzle_pipe[2] = 4;
  869. swizzle_pipe[3] = 6;
  870. swizzle_pipe[4] = 1;
  871. swizzle_pipe[5] = 3;
  872. swizzle_pipe[6] = 5;
  873. break;
  874. case 8:
  875. swizzle_pipe[0] = 0;
  876. swizzle_pipe[1] = 2;
  877. swizzle_pipe[2] = 4;
  878. swizzle_pipe[3] = 6;
  879. swizzle_pipe[4] = 1;
  880. swizzle_pipe[5] = 3;
  881. swizzle_pipe[6] = 5;
  882. swizzle_pipe[7] = 7;
  883. break;
  884. }
  885. cur_backend = 0;
  886. for (cur_pipe = 0; cur_pipe < num_tile_pipes; ++cur_pipe) {
  887. while (((1 << cur_backend) & enabled_backends_mask) == 0)
  888. cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
  889. backend_map |= (u32)(((cur_backend & 3) << (swizzle_pipe[cur_pipe] * 2)));
  890. cur_backend = (cur_backend + 1) % R6XX_MAX_BACKENDS;
  891. }
  892. return backend_map;
  893. }
  894. int r600_count_pipe_bits(uint32_t val)
  895. {
  896. int i, ret = 0;
  897. for (i = 0; i < 32; i++) {
  898. ret += val & 1;
  899. val >>= 1;
  900. }
  901. return ret;
  902. }
  903. void r600_gpu_init(struct radeon_device *rdev)
  904. {
  905. u32 tiling_config;
  906. u32 ramcfg;
  907. u32 backend_map;
  908. u32 cc_rb_backend_disable;
  909. u32 cc_gc_shader_pipe_config;
  910. u32 tmp;
  911. int i, j;
  912. u32 sq_config;
  913. u32 sq_gpr_resource_mgmt_1 = 0;
  914. u32 sq_gpr_resource_mgmt_2 = 0;
  915. u32 sq_thread_resource_mgmt = 0;
  916. u32 sq_stack_resource_mgmt_1 = 0;
  917. u32 sq_stack_resource_mgmt_2 = 0;
  918. /* FIXME: implement */
  919. switch (rdev->family) {
  920. case CHIP_R600:
  921. rdev->config.r600.max_pipes = 4;
  922. rdev->config.r600.max_tile_pipes = 8;
  923. rdev->config.r600.max_simds = 4;
  924. rdev->config.r600.max_backends = 4;
  925. rdev->config.r600.max_gprs = 256;
  926. rdev->config.r600.max_threads = 192;
  927. rdev->config.r600.max_stack_entries = 256;
  928. rdev->config.r600.max_hw_contexts = 8;
  929. rdev->config.r600.max_gs_threads = 16;
  930. rdev->config.r600.sx_max_export_size = 128;
  931. rdev->config.r600.sx_max_export_pos_size = 16;
  932. rdev->config.r600.sx_max_export_smx_size = 128;
  933. rdev->config.r600.sq_num_cf_insts = 2;
  934. break;
  935. case CHIP_RV630:
  936. case CHIP_RV635:
  937. rdev->config.r600.max_pipes = 2;
  938. rdev->config.r600.max_tile_pipes = 2;
  939. rdev->config.r600.max_simds = 3;
  940. rdev->config.r600.max_backends = 1;
  941. rdev->config.r600.max_gprs = 128;
  942. rdev->config.r600.max_threads = 192;
  943. rdev->config.r600.max_stack_entries = 128;
  944. rdev->config.r600.max_hw_contexts = 8;
  945. rdev->config.r600.max_gs_threads = 4;
  946. rdev->config.r600.sx_max_export_size = 128;
  947. rdev->config.r600.sx_max_export_pos_size = 16;
  948. rdev->config.r600.sx_max_export_smx_size = 128;
  949. rdev->config.r600.sq_num_cf_insts = 2;
  950. break;
  951. case CHIP_RV610:
  952. case CHIP_RV620:
  953. case CHIP_RS780:
  954. case CHIP_RS880:
  955. rdev->config.r600.max_pipes = 1;
  956. rdev->config.r600.max_tile_pipes = 1;
  957. rdev->config.r600.max_simds = 2;
  958. rdev->config.r600.max_backends = 1;
  959. rdev->config.r600.max_gprs = 128;
  960. rdev->config.r600.max_threads = 192;
  961. rdev->config.r600.max_stack_entries = 128;
  962. rdev->config.r600.max_hw_contexts = 4;
  963. rdev->config.r600.max_gs_threads = 4;
  964. rdev->config.r600.sx_max_export_size = 128;
  965. rdev->config.r600.sx_max_export_pos_size = 16;
  966. rdev->config.r600.sx_max_export_smx_size = 128;
  967. rdev->config.r600.sq_num_cf_insts = 1;
  968. break;
  969. case CHIP_RV670:
  970. rdev->config.r600.max_pipes = 4;
  971. rdev->config.r600.max_tile_pipes = 4;
  972. rdev->config.r600.max_simds = 4;
  973. rdev->config.r600.max_backends = 4;
  974. rdev->config.r600.max_gprs = 192;
  975. rdev->config.r600.max_threads = 192;
  976. rdev->config.r600.max_stack_entries = 256;
  977. rdev->config.r600.max_hw_contexts = 8;
  978. rdev->config.r600.max_gs_threads = 16;
  979. rdev->config.r600.sx_max_export_size = 128;
  980. rdev->config.r600.sx_max_export_pos_size = 16;
  981. rdev->config.r600.sx_max_export_smx_size = 128;
  982. rdev->config.r600.sq_num_cf_insts = 2;
  983. break;
  984. default:
  985. break;
  986. }
  987. /* Initialize HDP */
  988. for (i = 0, j = 0; i < 32; i++, j += 0x18) {
  989. WREG32((0x2c14 + j), 0x00000000);
  990. WREG32((0x2c18 + j), 0x00000000);
  991. WREG32((0x2c1c + j), 0x00000000);
  992. WREG32((0x2c20 + j), 0x00000000);
  993. WREG32((0x2c24 + j), 0x00000000);
  994. }
  995. WREG32(GRBM_CNTL, GRBM_READ_TIMEOUT(0xff));
  996. /* Setup tiling */
  997. tiling_config = 0;
  998. ramcfg = RREG32(RAMCFG);
  999. switch (rdev->config.r600.max_tile_pipes) {
  1000. case 1:
  1001. tiling_config |= PIPE_TILING(0);
  1002. break;
  1003. case 2:
  1004. tiling_config |= PIPE_TILING(1);
  1005. break;
  1006. case 4:
  1007. tiling_config |= PIPE_TILING(2);
  1008. break;
  1009. case 8:
  1010. tiling_config |= PIPE_TILING(3);
  1011. break;
  1012. default:
  1013. break;
  1014. }
  1015. rdev->config.r600.tiling_npipes = rdev->config.r600.max_tile_pipes;
  1016. rdev->config.r600.tiling_nbanks = 4 << ((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
  1017. tiling_config |= BANK_TILING((ramcfg & NOOFBANK_MASK) >> NOOFBANK_SHIFT);
  1018. tiling_config |= GROUP_SIZE(0);
  1019. rdev->config.r600.tiling_group_size = 256;
  1020. tmp = (ramcfg & NOOFROWS_MASK) >> NOOFROWS_SHIFT;
  1021. if (tmp > 3) {
  1022. tiling_config |= ROW_TILING(3);
  1023. tiling_config |= SAMPLE_SPLIT(3);
  1024. } else {
  1025. tiling_config |= ROW_TILING(tmp);
  1026. tiling_config |= SAMPLE_SPLIT(tmp);
  1027. }
  1028. tiling_config |= BANK_SWAPS(1);
  1029. cc_rb_backend_disable = RREG32(CC_RB_BACKEND_DISABLE) & 0x00ff0000;
  1030. cc_rb_backend_disable |=
  1031. BACKEND_DISABLE((R6XX_MAX_BACKENDS_MASK << rdev->config.r600.max_backends) & R6XX_MAX_BACKENDS_MASK);
  1032. cc_gc_shader_pipe_config = RREG32(CC_GC_SHADER_PIPE_CONFIG) & 0xffffff00;
  1033. cc_gc_shader_pipe_config |=
  1034. INACTIVE_QD_PIPES((R6XX_MAX_PIPES_MASK << rdev->config.r600.max_pipes) & R6XX_MAX_PIPES_MASK);
  1035. cc_gc_shader_pipe_config |=
  1036. INACTIVE_SIMDS((R6XX_MAX_SIMDS_MASK << rdev->config.r600.max_simds) & R6XX_MAX_SIMDS_MASK);
  1037. backend_map = r600_get_tile_pipe_to_backend_map(rdev->config.r600.max_tile_pipes,
  1038. (R6XX_MAX_BACKENDS -
  1039. r600_count_pipe_bits((cc_rb_backend_disable &
  1040. R6XX_MAX_BACKENDS_MASK) >> 16)),
  1041. (cc_rb_backend_disable >> 16));
  1042. tiling_config |= BACKEND_MAP(backend_map);
  1043. WREG32(GB_TILING_CONFIG, tiling_config);
  1044. WREG32(DCP_TILING_CONFIG, tiling_config & 0xffff);
  1045. WREG32(HDP_TILING_CONFIG, tiling_config & 0xffff);
  1046. /* Setup pipes */
  1047. WREG32(CC_RB_BACKEND_DISABLE, cc_rb_backend_disable);
  1048. WREG32(CC_GC_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  1049. WREG32(GC_USER_SHADER_PIPE_CONFIG, cc_gc_shader_pipe_config);
  1050. tmp = R6XX_MAX_PIPES - r600_count_pipe_bits((cc_gc_shader_pipe_config & INACTIVE_QD_PIPES_MASK) >> 8);
  1051. WREG32(VGT_OUT_DEALLOC_CNTL, (tmp * 4) & DEALLOC_DIST_MASK);
  1052. WREG32(VGT_VERTEX_REUSE_BLOCK_CNTL, ((tmp * 4) - 2) & VTX_REUSE_DEPTH_MASK);
  1053. /* Setup some CP states */
  1054. WREG32(CP_QUEUE_THRESHOLDS, (ROQ_IB1_START(0x16) | ROQ_IB2_START(0x2b)));
  1055. WREG32(CP_MEQ_THRESHOLDS, (MEQ_END(0x40) | ROQ_END(0x40)));
  1056. WREG32(TA_CNTL_AUX, (DISABLE_CUBE_ANISO | SYNC_GRADIENT |
  1057. SYNC_WALKER | SYNC_ALIGNER));
  1058. /* Setup various GPU states */
  1059. if (rdev->family == CHIP_RV670)
  1060. WREG32(ARB_GDEC_RD_CNTL, 0x00000021);
  1061. tmp = RREG32(SX_DEBUG_1);
  1062. tmp |= SMX_EVENT_RELEASE;
  1063. if ((rdev->family > CHIP_R600))
  1064. tmp |= ENABLE_NEW_SMX_ADDRESS;
  1065. WREG32(SX_DEBUG_1, tmp);
  1066. if (((rdev->family) == CHIP_R600) ||
  1067. ((rdev->family) == CHIP_RV630) ||
  1068. ((rdev->family) == CHIP_RV610) ||
  1069. ((rdev->family) == CHIP_RV620) ||
  1070. ((rdev->family) == CHIP_RS780) ||
  1071. ((rdev->family) == CHIP_RS880)) {
  1072. WREG32(DB_DEBUG, PREZ_MUST_WAIT_FOR_POSTZ_DONE);
  1073. } else {
  1074. WREG32(DB_DEBUG, 0);
  1075. }
  1076. WREG32(DB_WATERMARKS, (DEPTH_FREE(4) | DEPTH_CACHELINE_FREE(16) |
  1077. DEPTH_FLUSH(16) | DEPTH_PENDING_FREE(4)));
  1078. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  1079. WREG32(VGT_NUM_INSTANCES, 0);
  1080. WREG32(SPI_CONFIG_CNTL, GPR_WRITE_PRIORITY(0));
  1081. WREG32(SPI_CONFIG_CNTL_1, VTX_DONE_DELAY(0));
  1082. tmp = RREG32(SQ_MS_FIFO_SIZES);
  1083. if (((rdev->family) == CHIP_RV610) ||
  1084. ((rdev->family) == CHIP_RV620) ||
  1085. ((rdev->family) == CHIP_RS780) ||
  1086. ((rdev->family) == CHIP_RS880)) {
  1087. tmp = (CACHE_FIFO_SIZE(0xa) |
  1088. FETCH_FIFO_HIWATER(0xa) |
  1089. DONE_FIFO_HIWATER(0xe0) |
  1090. ALU_UPDATE_FIFO_HIWATER(0x8));
  1091. } else if (((rdev->family) == CHIP_R600) ||
  1092. ((rdev->family) == CHIP_RV630)) {
  1093. tmp &= ~DONE_FIFO_HIWATER(0xff);
  1094. tmp |= DONE_FIFO_HIWATER(0x4);
  1095. }
  1096. WREG32(SQ_MS_FIFO_SIZES, tmp);
  1097. /* SQ_CONFIG, SQ_GPR_RESOURCE_MGMT, SQ_THREAD_RESOURCE_MGMT, SQ_STACK_RESOURCE_MGMT
  1098. * should be adjusted as needed by the 2D/3D drivers. This just sets default values
  1099. */
  1100. sq_config = RREG32(SQ_CONFIG);
  1101. sq_config &= ~(PS_PRIO(3) |
  1102. VS_PRIO(3) |
  1103. GS_PRIO(3) |
  1104. ES_PRIO(3));
  1105. sq_config |= (DX9_CONSTS |
  1106. VC_ENABLE |
  1107. PS_PRIO(0) |
  1108. VS_PRIO(1) |
  1109. GS_PRIO(2) |
  1110. ES_PRIO(3));
  1111. if ((rdev->family) == CHIP_R600) {
  1112. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(124) |
  1113. NUM_VS_GPRS(124) |
  1114. NUM_CLAUSE_TEMP_GPRS(4));
  1115. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(0) |
  1116. NUM_ES_GPRS(0));
  1117. sq_thread_resource_mgmt = (NUM_PS_THREADS(136) |
  1118. NUM_VS_THREADS(48) |
  1119. NUM_GS_THREADS(4) |
  1120. NUM_ES_THREADS(4));
  1121. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(128) |
  1122. NUM_VS_STACK_ENTRIES(128));
  1123. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(0) |
  1124. NUM_ES_STACK_ENTRIES(0));
  1125. } else if (((rdev->family) == CHIP_RV610) ||
  1126. ((rdev->family) == CHIP_RV620) ||
  1127. ((rdev->family) == CHIP_RS780) ||
  1128. ((rdev->family) == CHIP_RS880)) {
  1129. /* no vertex cache */
  1130. sq_config &= ~VC_ENABLE;
  1131. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  1132. NUM_VS_GPRS(44) |
  1133. NUM_CLAUSE_TEMP_GPRS(2));
  1134. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
  1135. NUM_ES_GPRS(17));
  1136. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  1137. NUM_VS_THREADS(78) |
  1138. NUM_GS_THREADS(4) |
  1139. NUM_ES_THREADS(31));
  1140. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
  1141. NUM_VS_STACK_ENTRIES(40));
  1142. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
  1143. NUM_ES_STACK_ENTRIES(16));
  1144. } else if (((rdev->family) == CHIP_RV630) ||
  1145. ((rdev->family) == CHIP_RV635)) {
  1146. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  1147. NUM_VS_GPRS(44) |
  1148. NUM_CLAUSE_TEMP_GPRS(2));
  1149. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(18) |
  1150. NUM_ES_GPRS(18));
  1151. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  1152. NUM_VS_THREADS(78) |
  1153. NUM_GS_THREADS(4) |
  1154. NUM_ES_THREADS(31));
  1155. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(40) |
  1156. NUM_VS_STACK_ENTRIES(40));
  1157. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(32) |
  1158. NUM_ES_STACK_ENTRIES(16));
  1159. } else if ((rdev->family) == CHIP_RV670) {
  1160. sq_gpr_resource_mgmt_1 = (NUM_PS_GPRS(44) |
  1161. NUM_VS_GPRS(44) |
  1162. NUM_CLAUSE_TEMP_GPRS(2));
  1163. sq_gpr_resource_mgmt_2 = (NUM_GS_GPRS(17) |
  1164. NUM_ES_GPRS(17));
  1165. sq_thread_resource_mgmt = (NUM_PS_THREADS(79) |
  1166. NUM_VS_THREADS(78) |
  1167. NUM_GS_THREADS(4) |
  1168. NUM_ES_THREADS(31));
  1169. sq_stack_resource_mgmt_1 = (NUM_PS_STACK_ENTRIES(64) |
  1170. NUM_VS_STACK_ENTRIES(64));
  1171. sq_stack_resource_mgmt_2 = (NUM_GS_STACK_ENTRIES(64) |
  1172. NUM_ES_STACK_ENTRIES(64));
  1173. }
  1174. WREG32(SQ_CONFIG, sq_config);
  1175. WREG32(SQ_GPR_RESOURCE_MGMT_1, sq_gpr_resource_mgmt_1);
  1176. WREG32(SQ_GPR_RESOURCE_MGMT_2, sq_gpr_resource_mgmt_2);
  1177. WREG32(SQ_THREAD_RESOURCE_MGMT, sq_thread_resource_mgmt);
  1178. WREG32(SQ_STACK_RESOURCE_MGMT_1, sq_stack_resource_mgmt_1);
  1179. WREG32(SQ_STACK_RESOURCE_MGMT_2, sq_stack_resource_mgmt_2);
  1180. if (((rdev->family) == CHIP_RV610) ||
  1181. ((rdev->family) == CHIP_RV620) ||
  1182. ((rdev->family) == CHIP_RS780) ||
  1183. ((rdev->family) == CHIP_RS880)) {
  1184. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(TC_ONLY));
  1185. } else {
  1186. WREG32(VGT_CACHE_INVALIDATION, CACHE_INVALIDATION(VC_AND_TC));
  1187. }
  1188. /* More default values. 2D/3D driver should adjust as needed */
  1189. WREG32(PA_SC_AA_SAMPLE_LOCS_2S, (S0_X(0xc) | S0_Y(0x4) |
  1190. S1_X(0x4) | S1_Y(0xc)));
  1191. WREG32(PA_SC_AA_SAMPLE_LOCS_4S, (S0_X(0xe) | S0_Y(0xe) |
  1192. S1_X(0x2) | S1_Y(0x2) |
  1193. S2_X(0xa) | S2_Y(0x6) |
  1194. S3_X(0x6) | S3_Y(0xa)));
  1195. WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD0, (S0_X(0xe) | S0_Y(0xb) |
  1196. S1_X(0x4) | S1_Y(0xc) |
  1197. S2_X(0x1) | S2_Y(0x6) |
  1198. S3_X(0xa) | S3_Y(0xe)));
  1199. WREG32(PA_SC_AA_SAMPLE_LOCS_8S_WD1, (S4_X(0x6) | S4_Y(0x1) |
  1200. S5_X(0x0) | S5_Y(0x0) |
  1201. S6_X(0xb) | S6_Y(0x4) |
  1202. S7_X(0x7) | S7_Y(0x8)));
  1203. WREG32(VGT_STRMOUT_EN, 0);
  1204. tmp = rdev->config.r600.max_pipes * 16;
  1205. switch (rdev->family) {
  1206. case CHIP_RV610:
  1207. case CHIP_RV620:
  1208. case CHIP_RS780:
  1209. case CHIP_RS880:
  1210. tmp += 32;
  1211. break;
  1212. case CHIP_RV670:
  1213. tmp += 128;
  1214. break;
  1215. default:
  1216. break;
  1217. }
  1218. if (tmp > 256) {
  1219. tmp = 256;
  1220. }
  1221. WREG32(VGT_ES_PER_GS, 128);
  1222. WREG32(VGT_GS_PER_ES, tmp);
  1223. WREG32(VGT_GS_PER_VS, 2);
  1224. WREG32(VGT_GS_VERTEX_REUSE, 16);
  1225. /* more default values. 2D/3D driver should adjust as needed */
  1226. WREG32(PA_SC_LINE_STIPPLE_STATE, 0);
  1227. WREG32(VGT_STRMOUT_EN, 0);
  1228. WREG32(SX_MISC, 0);
  1229. WREG32(PA_SC_MODE_CNTL, 0);
  1230. WREG32(PA_SC_AA_CONFIG, 0);
  1231. WREG32(PA_SC_LINE_STIPPLE, 0);
  1232. WREG32(SPI_INPUT_Z, 0);
  1233. WREG32(SPI_PS_IN_CONTROL_0, NUM_INTERP(2));
  1234. WREG32(CB_COLOR7_FRAG, 0);
  1235. /* Clear render buffer base addresses */
  1236. WREG32(CB_COLOR0_BASE, 0);
  1237. WREG32(CB_COLOR1_BASE, 0);
  1238. WREG32(CB_COLOR2_BASE, 0);
  1239. WREG32(CB_COLOR3_BASE, 0);
  1240. WREG32(CB_COLOR4_BASE, 0);
  1241. WREG32(CB_COLOR5_BASE, 0);
  1242. WREG32(CB_COLOR6_BASE, 0);
  1243. WREG32(CB_COLOR7_BASE, 0);
  1244. WREG32(CB_COLOR7_FRAG, 0);
  1245. switch (rdev->family) {
  1246. case CHIP_RV610:
  1247. case CHIP_RV620:
  1248. case CHIP_RS780:
  1249. case CHIP_RS880:
  1250. tmp = TC_L2_SIZE(8);
  1251. break;
  1252. case CHIP_RV630:
  1253. case CHIP_RV635:
  1254. tmp = TC_L2_SIZE(4);
  1255. break;
  1256. case CHIP_R600:
  1257. tmp = TC_L2_SIZE(0) | L2_DISABLE_LATE_HIT;
  1258. break;
  1259. default:
  1260. tmp = TC_L2_SIZE(0);
  1261. break;
  1262. }
  1263. WREG32(TC_CNTL, tmp);
  1264. tmp = RREG32(HDP_HOST_PATH_CNTL);
  1265. WREG32(HDP_HOST_PATH_CNTL, tmp);
  1266. tmp = RREG32(ARB_POP);
  1267. tmp |= ENABLE_TC128;
  1268. WREG32(ARB_POP, tmp);
  1269. WREG32(PA_SC_MULTI_CHIP_CNTL, 0);
  1270. WREG32(PA_CL_ENHANCE, (CLIP_VTX_REORDER_ENA |
  1271. NUM_CLIP_SEQ(3)));
  1272. WREG32(PA_SC_ENHANCE, FORCE_EOV_MAX_CLK_CNT(4095));
  1273. }
  1274. /*
  1275. * Indirect registers accessor
  1276. */
  1277. u32 r600_pciep_rreg(struct radeon_device *rdev, u32 reg)
  1278. {
  1279. u32 r;
  1280. WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
  1281. (void)RREG32(PCIE_PORT_INDEX);
  1282. r = RREG32(PCIE_PORT_DATA);
  1283. return r;
  1284. }
  1285. void r600_pciep_wreg(struct radeon_device *rdev, u32 reg, u32 v)
  1286. {
  1287. WREG32(PCIE_PORT_INDEX, ((reg) & 0xff));
  1288. (void)RREG32(PCIE_PORT_INDEX);
  1289. WREG32(PCIE_PORT_DATA, (v));
  1290. (void)RREG32(PCIE_PORT_DATA);
  1291. }
  1292. /*
  1293. * CP & Ring
  1294. */
  1295. void r600_cp_stop(struct radeon_device *rdev)
  1296. {
  1297. WREG32(R_0086D8_CP_ME_CNTL, S_0086D8_CP_ME_HALT(1));
  1298. }
  1299. int r600_init_microcode(struct radeon_device *rdev)
  1300. {
  1301. struct platform_device *pdev;
  1302. const char *chip_name;
  1303. const char *rlc_chip_name;
  1304. size_t pfp_req_size, me_req_size, rlc_req_size;
  1305. char fw_name[30];
  1306. int err;
  1307. DRM_DEBUG("\n");
  1308. pdev = platform_device_register_simple("radeon_cp", 0, NULL, 0);
  1309. err = IS_ERR(pdev);
  1310. if (err) {
  1311. printk(KERN_ERR "radeon_cp: Failed to register firmware\n");
  1312. return -EINVAL;
  1313. }
  1314. switch (rdev->family) {
  1315. case CHIP_R600:
  1316. chip_name = "R600";
  1317. rlc_chip_name = "R600";
  1318. break;
  1319. case CHIP_RV610:
  1320. chip_name = "RV610";
  1321. rlc_chip_name = "R600";
  1322. break;
  1323. case CHIP_RV630:
  1324. chip_name = "RV630";
  1325. rlc_chip_name = "R600";
  1326. break;
  1327. case CHIP_RV620:
  1328. chip_name = "RV620";
  1329. rlc_chip_name = "R600";
  1330. break;
  1331. case CHIP_RV635:
  1332. chip_name = "RV635";
  1333. rlc_chip_name = "R600";
  1334. break;
  1335. case CHIP_RV670:
  1336. chip_name = "RV670";
  1337. rlc_chip_name = "R600";
  1338. break;
  1339. case CHIP_RS780:
  1340. case CHIP_RS880:
  1341. chip_name = "RS780";
  1342. rlc_chip_name = "R600";
  1343. break;
  1344. case CHIP_RV770:
  1345. chip_name = "RV770";
  1346. rlc_chip_name = "R700";
  1347. break;
  1348. case CHIP_RV730:
  1349. case CHIP_RV740:
  1350. chip_name = "RV730";
  1351. rlc_chip_name = "R700";
  1352. break;
  1353. case CHIP_RV710:
  1354. chip_name = "RV710";
  1355. rlc_chip_name = "R700";
  1356. break;
  1357. default: BUG();
  1358. }
  1359. if (rdev->family >= CHIP_RV770) {
  1360. pfp_req_size = R700_PFP_UCODE_SIZE * 4;
  1361. me_req_size = R700_PM4_UCODE_SIZE * 4;
  1362. rlc_req_size = R700_RLC_UCODE_SIZE * 4;
  1363. } else {
  1364. pfp_req_size = PFP_UCODE_SIZE * 4;
  1365. me_req_size = PM4_UCODE_SIZE * 12;
  1366. rlc_req_size = RLC_UCODE_SIZE * 4;
  1367. }
  1368. DRM_INFO("Loading %s Microcode\n", chip_name);
  1369. snprintf(fw_name, sizeof(fw_name), "radeon/%s_pfp.bin", chip_name);
  1370. err = request_firmware(&rdev->pfp_fw, fw_name, &pdev->dev);
  1371. if (err)
  1372. goto out;
  1373. if (rdev->pfp_fw->size != pfp_req_size) {
  1374. printk(KERN_ERR
  1375. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  1376. rdev->pfp_fw->size, fw_name);
  1377. err = -EINVAL;
  1378. goto out;
  1379. }
  1380. snprintf(fw_name, sizeof(fw_name), "radeon/%s_me.bin", chip_name);
  1381. err = request_firmware(&rdev->me_fw, fw_name, &pdev->dev);
  1382. if (err)
  1383. goto out;
  1384. if (rdev->me_fw->size != me_req_size) {
  1385. printk(KERN_ERR
  1386. "r600_cp: Bogus length %zu in firmware \"%s\"\n",
  1387. rdev->me_fw->size, fw_name);
  1388. err = -EINVAL;
  1389. }
  1390. snprintf(fw_name, sizeof(fw_name), "radeon/%s_rlc.bin", rlc_chip_name);
  1391. err = request_firmware(&rdev->rlc_fw, fw_name, &pdev->dev);
  1392. if (err)
  1393. goto out;
  1394. if (rdev->rlc_fw->size != rlc_req_size) {
  1395. printk(KERN_ERR
  1396. "r600_rlc: Bogus length %zu in firmware \"%s\"\n",
  1397. rdev->rlc_fw->size, fw_name);
  1398. err = -EINVAL;
  1399. }
  1400. out:
  1401. platform_device_unregister(pdev);
  1402. if (err) {
  1403. if (err != -EINVAL)
  1404. printk(KERN_ERR
  1405. "r600_cp: Failed to load firmware \"%s\"\n",
  1406. fw_name);
  1407. release_firmware(rdev->pfp_fw);
  1408. rdev->pfp_fw = NULL;
  1409. release_firmware(rdev->me_fw);
  1410. rdev->me_fw = NULL;
  1411. release_firmware(rdev->rlc_fw);
  1412. rdev->rlc_fw = NULL;
  1413. }
  1414. return err;
  1415. }
  1416. static int r600_cp_load_microcode(struct radeon_device *rdev)
  1417. {
  1418. const __be32 *fw_data;
  1419. int i;
  1420. if (!rdev->me_fw || !rdev->pfp_fw)
  1421. return -EINVAL;
  1422. r600_cp_stop(rdev);
  1423. WREG32(CP_RB_CNTL, RB_NO_UPDATE | RB_BLKSZ(15) | RB_BUFSZ(3));
  1424. /* Reset cp */
  1425. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  1426. RREG32(GRBM_SOFT_RESET);
  1427. mdelay(15);
  1428. WREG32(GRBM_SOFT_RESET, 0);
  1429. WREG32(CP_ME_RAM_WADDR, 0);
  1430. fw_data = (const __be32 *)rdev->me_fw->data;
  1431. WREG32(CP_ME_RAM_WADDR, 0);
  1432. for (i = 0; i < PM4_UCODE_SIZE * 3; i++)
  1433. WREG32(CP_ME_RAM_DATA,
  1434. be32_to_cpup(fw_data++));
  1435. fw_data = (const __be32 *)rdev->pfp_fw->data;
  1436. WREG32(CP_PFP_UCODE_ADDR, 0);
  1437. for (i = 0; i < PFP_UCODE_SIZE; i++)
  1438. WREG32(CP_PFP_UCODE_DATA,
  1439. be32_to_cpup(fw_data++));
  1440. WREG32(CP_PFP_UCODE_ADDR, 0);
  1441. WREG32(CP_ME_RAM_WADDR, 0);
  1442. WREG32(CP_ME_RAM_RADDR, 0);
  1443. return 0;
  1444. }
  1445. int r600_cp_start(struct radeon_device *rdev)
  1446. {
  1447. int r;
  1448. uint32_t cp_me;
  1449. r = radeon_ring_lock(rdev, 7);
  1450. if (r) {
  1451. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1452. return r;
  1453. }
  1454. radeon_ring_write(rdev, PACKET3(PACKET3_ME_INITIALIZE, 5));
  1455. radeon_ring_write(rdev, 0x1);
  1456. if (rdev->family < CHIP_RV770) {
  1457. radeon_ring_write(rdev, 0x3);
  1458. radeon_ring_write(rdev, rdev->config.r600.max_hw_contexts - 1);
  1459. } else {
  1460. radeon_ring_write(rdev, 0x0);
  1461. radeon_ring_write(rdev, rdev->config.rv770.max_hw_contexts - 1);
  1462. }
  1463. radeon_ring_write(rdev, PACKET3_ME_INITIALIZE_DEVICE_ID(1));
  1464. radeon_ring_write(rdev, 0);
  1465. radeon_ring_write(rdev, 0);
  1466. radeon_ring_unlock_commit(rdev);
  1467. cp_me = 0xff;
  1468. WREG32(R_0086D8_CP_ME_CNTL, cp_me);
  1469. return 0;
  1470. }
  1471. int r600_cp_resume(struct radeon_device *rdev)
  1472. {
  1473. u32 tmp;
  1474. u32 rb_bufsz;
  1475. int r;
  1476. /* Reset cp */
  1477. WREG32(GRBM_SOFT_RESET, SOFT_RESET_CP);
  1478. RREG32(GRBM_SOFT_RESET);
  1479. mdelay(15);
  1480. WREG32(GRBM_SOFT_RESET, 0);
  1481. /* Set ring buffer size */
  1482. rb_bufsz = drm_order(rdev->cp.ring_size / 8);
  1483. tmp = RB_NO_UPDATE | (drm_order(RADEON_GPU_PAGE_SIZE/8) << 8) | rb_bufsz;
  1484. #ifdef __BIG_ENDIAN
  1485. tmp |= BUF_SWAP_32BIT;
  1486. #endif
  1487. WREG32(CP_RB_CNTL, tmp);
  1488. WREG32(CP_SEM_WAIT_TIMER, 0x4);
  1489. /* Set the write pointer delay */
  1490. WREG32(CP_RB_WPTR_DELAY, 0);
  1491. /* Initialize the ring buffer's read and write pointers */
  1492. WREG32(CP_RB_CNTL, tmp | RB_RPTR_WR_ENA);
  1493. WREG32(CP_RB_RPTR_WR, 0);
  1494. WREG32(CP_RB_WPTR, 0);
  1495. WREG32(CP_RB_RPTR_ADDR, rdev->cp.gpu_addr & 0xFFFFFFFF);
  1496. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->cp.gpu_addr));
  1497. mdelay(1);
  1498. WREG32(CP_RB_CNTL, tmp);
  1499. WREG32(CP_RB_BASE, rdev->cp.gpu_addr >> 8);
  1500. WREG32(CP_DEBUG, (1 << 27) | (1 << 28));
  1501. rdev->cp.rptr = RREG32(CP_RB_RPTR);
  1502. rdev->cp.wptr = RREG32(CP_RB_WPTR);
  1503. r600_cp_start(rdev);
  1504. rdev->cp.ready = true;
  1505. r = radeon_ring_test(rdev);
  1506. if (r) {
  1507. rdev->cp.ready = false;
  1508. return r;
  1509. }
  1510. return 0;
  1511. }
  1512. void r600_cp_commit(struct radeon_device *rdev)
  1513. {
  1514. WREG32(CP_RB_WPTR, rdev->cp.wptr);
  1515. (void)RREG32(CP_RB_WPTR);
  1516. }
  1517. void r600_ring_init(struct radeon_device *rdev, unsigned ring_size)
  1518. {
  1519. u32 rb_bufsz;
  1520. /* Align ring size */
  1521. rb_bufsz = drm_order(ring_size / 8);
  1522. ring_size = (1 << (rb_bufsz + 1)) * 4;
  1523. rdev->cp.ring_size = ring_size;
  1524. rdev->cp.align_mask = 16 - 1;
  1525. }
  1526. void r600_cp_fini(struct radeon_device *rdev)
  1527. {
  1528. r600_cp_stop(rdev);
  1529. radeon_ring_fini(rdev);
  1530. }
  1531. /*
  1532. * GPU scratch registers helpers function.
  1533. */
  1534. void r600_scratch_init(struct radeon_device *rdev)
  1535. {
  1536. int i;
  1537. rdev->scratch.num_reg = 7;
  1538. for (i = 0; i < rdev->scratch.num_reg; i++) {
  1539. rdev->scratch.free[i] = true;
  1540. rdev->scratch.reg[i] = SCRATCH_REG0 + (i * 4);
  1541. }
  1542. }
  1543. int r600_ring_test(struct radeon_device *rdev)
  1544. {
  1545. uint32_t scratch;
  1546. uint32_t tmp = 0;
  1547. unsigned i;
  1548. int r;
  1549. r = radeon_scratch_get(rdev, &scratch);
  1550. if (r) {
  1551. DRM_ERROR("radeon: cp failed to get scratch reg (%d).\n", r);
  1552. return r;
  1553. }
  1554. WREG32(scratch, 0xCAFEDEAD);
  1555. r = radeon_ring_lock(rdev, 3);
  1556. if (r) {
  1557. DRM_ERROR("radeon: cp failed to lock ring (%d).\n", r);
  1558. radeon_scratch_free(rdev, scratch);
  1559. return r;
  1560. }
  1561. radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1562. radeon_ring_write(rdev, ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
  1563. radeon_ring_write(rdev, 0xDEADBEEF);
  1564. radeon_ring_unlock_commit(rdev);
  1565. for (i = 0; i < rdev->usec_timeout; i++) {
  1566. tmp = RREG32(scratch);
  1567. if (tmp == 0xDEADBEEF)
  1568. break;
  1569. DRM_UDELAY(1);
  1570. }
  1571. if (i < rdev->usec_timeout) {
  1572. DRM_INFO("ring test succeeded in %d usecs\n", i);
  1573. } else {
  1574. DRM_ERROR("radeon: ring test failed (scratch(0x%04X)=0x%08X)\n",
  1575. scratch, tmp);
  1576. r = -EINVAL;
  1577. }
  1578. radeon_scratch_free(rdev, scratch);
  1579. return r;
  1580. }
  1581. void r600_wb_disable(struct radeon_device *rdev)
  1582. {
  1583. int r;
  1584. WREG32(SCRATCH_UMSK, 0);
  1585. if (rdev->wb.wb_obj) {
  1586. r = radeon_bo_reserve(rdev->wb.wb_obj, false);
  1587. if (unlikely(r != 0))
  1588. return;
  1589. radeon_bo_kunmap(rdev->wb.wb_obj);
  1590. radeon_bo_unpin(rdev->wb.wb_obj);
  1591. radeon_bo_unreserve(rdev->wb.wb_obj);
  1592. }
  1593. }
  1594. void r600_wb_fini(struct radeon_device *rdev)
  1595. {
  1596. r600_wb_disable(rdev);
  1597. if (rdev->wb.wb_obj) {
  1598. radeon_bo_unref(&rdev->wb.wb_obj);
  1599. rdev->wb.wb = NULL;
  1600. rdev->wb.wb_obj = NULL;
  1601. }
  1602. }
  1603. int r600_wb_enable(struct radeon_device *rdev)
  1604. {
  1605. int r;
  1606. if (rdev->wb.wb_obj == NULL) {
  1607. r = radeon_bo_create(rdev, NULL, RADEON_GPU_PAGE_SIZE, true,
  1608. RADEON_GEM_DOMAIN_GTT, &rdev->wb.wb_obj);
  1609. if (r) {
  1610. dev_warn(rdev->dev, "(%d) create WB bo failed\n", r);
  1611. return r;
  1612. }
  1613. r = radeon_bo_reserve(rdev->wb.wb_obj, false);
  1614. if (unlikely(r != 0)) {
  1615. r600_wb_fini(rdev);
  1616. return r;
  1617. }
  1618. r = radeon_bo_pin(rdev->wb.wb_obj, RADEON_GEM_DOMAIN_GTT,
  1619. &rdev->wb.gpu_addr);
  1620. if (r) {
  1621. radeon_bo_unreserve(rdev->wb.wb_obj);
  1622. dev_warn(rdev->dev, "(%d) pin WB bo failed\n", r);
  1623. r600_wb_fini(rdev);
  1624. return r;
  1625. }
  1626. r = radeon_bo_kmap(rdev->wb.wb_obj, (void **)&rdev->wb.wb);
  1627. radeon_bo_unreserve(rdev->wb.wb_obj);
  1628. if (r) {
  1629. dev_warn(rdev->dev, "(%d) map WB bo failed\n", r);
  1630. r600_wb_fini(rdev);
  1631. return r;
  1632. }
  1633. }
  1634. WREG32(SCRATCH_ADDR, (rdev->wb.gpu_addr >> 8) & 0xFFFFFFFF);
  1635. WREG32(CP_RB_RPTR_ADDR, (rdev->wb.gpu_addr + 1024) & 0xFFFFFFFC);
  1636. WREG32(CP_RB_RPTR_ADDR_HI, upper_32_bits(rdev->wb.gpu_addr + 1024) & 0xFF);
  1637. WREG32(SCRATCH_UMSK, 0xff);
  1638. return 0;
  1639. }
  1640. void r600_fence_ring_emit(struct radeon_device *rdev,
  1641. struct radeon_fence *fence)
  1642. {
  1643. /* Also consider EVENT_WRITE_EOP. it handles the interrupts + timestamps + events */
  1644. radeon_ring_write(rdev, PACKET3(PACKET3_EVENT_WRITE, 0));
  1645. radeon_ring_write(rdev, CACHE_FLUSH_AND_INV_EVENT);
  1646. /* wait for 3D idle clean */
  1647. radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1648. radeon_ring_write(rdev, (WAIT_UNTIL - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  1649. radeon_ring_write(rdev, WAIT_3D_IDLE_bit | WAIT_3D_IDLECLEAN_bit);
  1650. /* Emit fence sequence & fire IRQ */
  1651. radeon_ring_write(rdev, PACKET3(PACKET3_SET_CONFIG_REG, 1));
  1652. radeon_ring_write(rdev, ((rdev->fence_drv.scratch_reg - PACKET3_SET_CONFIG_REG_OFFSET) >> 2));
  1653. radeon_ring_write(rdev, fence->seq);
  1654. /* CP_INTERRUPT packet 3 no longer exists, use packet 0 */
  1655. radeon_ring_write(rdev, PACKET0(CP_INT_STATUS, 0));
  1656. radeon_ring_write(rdev, RB_INT_STAT);
  1657. }
  1658. int r600_copy_blit(struct radeon_device *rdev,
  1659. uint64_t src_offset, uint64_t dst_offset,
  1660. unsigned num_pages, struct radeon_fence *fence)
  1661. {
  1662. int r;
  1663. mutex_lock(&rdev->r600_blit.mutex);
  1664. rdev->r600_blit.vb_ib = NULL;
  1665. r = r600_blit_prepare_copy(rdev, num_pages * RADEON_GPU_PAGE_SIZE);
  1666. if (r) {
  1667. if (rdev->r600_blit.vb_ib)
  1668. radeon_ib_free(rdev, &rdev->r600_blit.vb_ib);
  1669. mutex_unlock(&rdev->r600_blit.mutex);
  1670. return r;
  1671. }
  1672. r600_kms_blit_copy(rdev, src_offset, dst_offset, num_pages * RADEON_GPU_PAGE_SIZE);
  1673. r600_blit_done_copy(rdev, fence);
  1674. mutex_unlock(&rdev->r600_blit.mutex);
  1675. return 0;
  1676. }
  1677. int r600_set_surface_reg(struct radeon_device *rdev, int reg,
  1678. uint32_t tiling_flags, uint32_t pitch,
  1679. uint32_t offset, uint32_t obj_size)
  1680. {
  1681. /* FIXME: implement */
  1682. return 0;
  1683. }
  1684. void r600_clear_surface_reg(struct radeon_device *rdev, int reg)
  1685. {
  1686. /* FIXME: implement */
  1687. }
  1688. bool r600_card_posted(struct radeon_device *rdev)
  1689. {
  1690. uint32_t reg;
  1691. /* first check CRTCs */
  1692. reg = RREG32(D1CRTC_CONTROL) |
  1693. RREG32(D2CRTC_CONTROL);
  1694. if (reg & CRTC_EN)
  1695. return true;
  1696. /* then check MEM_SIZE, in case the crtcs are off */
  1697. if (RREG32(CONFIG_MEMSIZE))
  1698. return true;
  1699. return false;
  1700. }
  1701. int r600_startup(struct radeon_device *rdev)
  1702. {
  1703. int r;
  1704. if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) {
  1705. r = r600_init_microcode(rdev);
  1706. if (r) {
  1707. DRM_ERROR("Failed to load firmware!\n");
  1708. return r;
  1709. }
  1710. }
  1711. r600_mc_program(rdev);
  1712. if (rdev->flags & RADEON_IS_AGP) {
  1713. r600_agp_enable(rdev);
  1714. } else {
  1715. r = r600_pcie_gart_enable(rdev);
  1716. if (r)
  1717. return r;
  1718. }
  1719. r600_gpu_init(rdev);
  1720. r = r600_blit_init(rdev);
  1721. if (r) {
  1722. r600_blit_fini(rdev);
  1723. rdev->asic->copy = NULL;
  1724. dev_warn(rdev->dev, "failed blitter (%d) falling back to memcpy\n", r);
  1725. }
  1726. /* pin copy shader into vram */
  1727. if (rdev->r600_blit.shader_obj) {
  1728. r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
  1729. if (unlikely(r != 0))
  1730. return r;
  1731. r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM,
  1732. &rdev->r600_blit.shader_gpu_addr);
  1733. radeon_bo_unreserve(rdev->r600_blit.shader_obj);
  1734. if (r) {
  1735. dev_err(rdev->dev, "(%d) pin blit object failed\n", r);
  1736. return r;
  1737. }
  1738. }
  1739. /* Enable IRQ */
  1740. r = r600_irq_init(rdev);
  1741. if (r) {
  1742. DRM_ERROR("radeon: IH init failed (%d).\n", r);
  1743. radeon_irq_kms_fini(rdev);
  1744. return r;
  1745. }
  1746. r600_irq_set(rdev);
  1747. r = radeon_ring_init(rdev, rdev->cp.ring_size);
  1748. if (r)
  1749. return r;
  1750. r = r600_cp_load_microcode(rdev);
  1751. if (r)
  1752. return r;
  1753. r = r600_cp_resume(rdev);
  1754. if (r)
  1755. return r;
  1756. /* write back buffer are not vital so don't worry about failure */
  1757. r600_wb_enable(rdev);
  1758. return 0;
  1759. }
  1760. void r600_vga_set_state(struct radeon_device *rdev, bool state)
  1761. {
  1762. uint32_t temp;
  1763. temp = RREG32(CONFIG_CNTL);
  1764. if (state == false) {
  1765. temp &= ~(1<<0);
  1766. temp |= (1<<1);
  1767. } else {
  1768. temp &= ~(1<<1);
  1769. }
  1770. WREG32(CONFIG_CNTL, temp);
  1771. }
  1772. int r600_resume(struct radeon_device *rdev)
  1773. {
  1774. int r;
  1775. /* Do not reset GPU before posting, on r600 hw unlike on r500 hw,
  1776. * posting will perform necessary task to bring back GPU into good
  1777. * shape.
  1778. */
  1779. /* post card */
  1780. atom_asic_init(rdev->mode_info.atom_context);
  1781. /* Initialize clocks */
  1782. r = radeon_clocks_init(rdev);
  1783. if (r) {
  1784. return r;
  1785. }
  1786. r = r600_startup(rdev);
  1787. if (r) {
  1788. DRM_ERROR("r600 startup failed on resume\n");
  1789. return r;
  1790. }
  1791. r = r600_ib_test(rdev);
  1792. if (r) {
  1793. DRM_ERROR("radeon: failled testing IB (%d).\n", r);
  1794. return r;
  1795. }
  1796. r = r600_audio_init(rdev);
  1797. if (r) {
  1798. DRM_ERROR("radeon: audio resume failed\n");
  1799. return r;
  1800. }
  1801. return r;
  1802. }
  1803. int r600_suspend(struct radeon_device *rdev)
  1804. {
  1805. int r;
  1806. r600_audio_fini(rdev);
  1807. /* FIXME: we should wait for ring to be empty */
  1808. r600_cp_stop(rdev);
  1809. rdev->cp.ready = false;
  1810. r600_irq_suspend(rdev);
  1811. r600_wb_disable(rdev);
  1812. r600_pcie_gart_disable(rdev);
  1813. /* unpin shaders bo */
  1814. if (rdev->r600_blit.shader_obj) {
  1815. r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false);
  1816. if (!r) {
  1817. radeon_bo_unpin(rdev->r600_blit.shader_obj);
  1818. radeon_bo_unreserve(rdev->r600_blit.shader_obj);
  1819. }
  1820. }
  1821. return 0;
  1822. }
  1823. /* Plan is to move initialization in that function and use
  1824. * helper function so that radeon_device_init pretty much
  1825. * do nothing more than calling asic specific function. This
  1826. * should also allow to remove a bunch of callback function
  1827. * like vram_info.
  1828. */
  1829. int r600_init(struct radeon_device *rdev)
  1830. {
  1831. int r;
  1832. r = radeon_dummy_page_init(rdev);
  1833. if (r)
  1834. return r;
  1835. if (r600_debugfs_mc_info_init(rdev)) {
  1836. DRM_ERROR("Failed to register debugfs file for mc !\n");
  1837. }
  1838. /* This don't do much */
  1839. r = radeon_gem_init(rdev);
  1840. if (r)
  1841. return r;
  1842. /* Read BIOS */
  1843. if (!radeon_get_bios(rdev)) {
  1844. if (ASIC_IS_AVIVO(rdev))
  1845. return -EINVAL;
  1846. }
  1847. /* Must be an ATOMBIOS */
  1848. if (!rdev->is_atom_bios) {
  1849. dev_err(rdev->dev, "Expecting atombios for R600 GPU\n");
  1850. return -EINVAL;
  1851. }
  1852. r = radeon_atombios_init(rdev);
  1853. if (r)
  1854. return r;
  1855. /* Post card if necessary */
  1856. if (!r600_card_posted(rdev)) {
  1857. if (!rdev->bios) {
  1858. dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n");
  1859. return -EINVAL;
  1860. }
  1861. DRM_INFO("GPU not posted. posting now...\n");
  1862. atom_asic_init(rdev->mode_info.atom_context);
  1863. }
  1864. /* Initialize scratch registers */
  1865. r600_scratch_init(rdev);
  1866. /* Initialize surface registers */
  1867. radeon_surface_init(rdev);
  1868. /* Initialize clocks */
  1869. radeon_get_clock_info(rdev->ddev);
  1870. r = radeon_clocks_init(rdev);
  1871. if (r)
  1872. return r;
  1873. /* Initialize power management */
  1874. radeon_pm_init(rdev);
  1875. /* Fence driver */
  1876. r = radeon_fence_driver_init(rdev);
  1877. if (r)
  1878. return r;
  1879. if (rdev->flags & RADEON_IS_AGP) {
  1880. r = radeon_agp_init(rdev);
  1881. if (r)
  1882. radeon_agp_disable(rdev);
  1883. }
  1884. r = r600_mc_init(rdev);
  1885. if (r)
  1886. return r;
  1887. /* Memory manager */
  1888. r = radeon_bo_init(rdev);
  1889. if (r)
  1890. return r;
  1891. r = radeon_irq_kms_init(rdev);
  1892. if (r)
  1893. return r;
  1894. rdev->cp.ring_obj = NULL;
  1895. r600_ring_init(rdev, 1024 * 1024);
  1896. rdev->ih.ring_obj = NULL;
  1897. r600_ih_ring_init(rdev, 64 * 1024);
  1898. r = r600_pcie_gart_init(rdev);
  1899. if (r)
  1900. return r;
  1901. rdev->accel_working = true;
  1902. r = r600_startup(rdev);
  1903. if (r) {
  1904. dev_err(rdev->dev, "disabling GPU acceleration\n");
  1905. r600_cp_fini(rdev);
  1906. r600_wb_fini(rdev);
  1907. r600_irq_fini(rdev);
  1908. radeon_irq_kms_fini(rdev);
  1909. r600_pcie_gart_fini(rdev);
  1910. rdev->accel_working = false;
  1911. }
  1912. if (rdev->accel_working) {
  1913. r = radeon_ib_pool_init(rdev);
  1914. if (r) {
  1915. dev_err(rdev->dev, "IB initialization failed (%d).\n", r);
  1916. rdev->accel_working = false;
  1917. } else {
  1918. r = r600_ib_test(rdev);
  1919. if (r) {
  1920. dev_err(rdev->dev, "IB test failed (%d).\n", r);
  1921. rdev->accel_working = false;
  1922. }
  1923. }
  1924. }
  1925. r = r600_audio_init(rdev);
  1926. if (r)
  1927. return r; /* TODO error handling */
  1928. return 0;
  1929. }
  1930. void r600_fini(struct radeon_device *rdev)
  1931. {
  1932. radeon_pm_fini(rdev);
  1933. r600_audio_fini(rdev);
  1934. r600_blit_fini(rdev);
  1935. r600_cp_fini(rdev);
  1936. r600_wb_fini(rdev);
  1937. r600_irq_fini(rdev);
  1938. radeon_irq_kms_fini(rdev);
  1939. r600_pcie_gart_fini(rdev);
  1940. radeon_agp_fini(rdev);
  1941. radeon_gem_fini(rdev);
  1942. radeon_fence_driver_fini(rdev);
  1943. radeon_clocks_fini(rdev);
  1944. radeon_bo_fini(rdev);
  1945. radeon_atombios_fini(rdev);
  1946. kfree(rdev->bios);
  1947. rdev->bios = NULL;
  1948. radeon_dummy_page_fini(rdev);
  1949. }
  1950. /*
  1951. * CS stuff
  1952. */
  1953. void r600_ring_ib_execute(struct radeon_device *rdev, struct radeon_ib *ib)
  1954. {
  1955. /* FIXME: implement */
  1956. radeon_ring_write(rdev, PACKET3(PACKET3_INDIRECT_BUFFER, 2));
  1957. radeon_ring_write(rdev, ib->gpu_addr & 0xFFFFFFFC);
  1958. radeon_ring_write(rdev, upper_32_bits(ib->gpu_addr) & 0xFF);
  1959. radeon_ring_write(rdev, ib->length_dw);
  1960. }
  1961. int r600_ib_test(struct radeon_device *rdev)
  1962. {
  1963. struct radeon_ib *ib;
  1964. uint32_t scratch;
  1965. uint32_t tmp = 0;
  1966. unsigned i;
  1967. int r;
  1968. r = radeon_scratch_get(rdev, &scratch);
  1969. if (r) {
  1970. DRM_ERROR("radeon: failed to get scratch reg (%d).\n", r);
  1971. return r;
  1972. }
  1973. WREG32(scratch, 0xCAFEDEAD);
  1974. r = radeon_ib_get(rdev, &ib);
  1975. if (r) {
  1976. DRM_ERROR("radeon: failed to get ib (%d).\n", r);
  1977. return r;
  1978. }
  1979. ib->ptr[0] = PACKET3(PACKET3_SET_CONFIG_REG, 1);
  1980. ib->ptr[1] = ((scratch - PACKET3_SET_CONFIG_REG_OFFSET) >> 2);
  1981. ib->ptr[2] = 0xDEADBEEF;
  1982. ib->ptr[3] = PACKET2(0);
  1983. ib->ptr[4] = PACKET2(0);
  1984. ib->ptr[5] = PACKET2(0);
  1985. ib->ptr[6] = PACKET2(0);
  1986. ib->ptr[7] = PACKET2(0);
  1987. ib->ptr[8] = PACKET2(0);
  1988. ib->ptr[9] = PACKET2(0);
  1989. ib->ptr[10] = PACKET2(0);
  1990. ib->ptr[11] = PACKET2(0);
  1991. ib->ptr[12] = PACKET2(0);
  1992. ib->ptr[13] = PACKET2(0);
  1993. ib->ptr[14] = PACKET2(0);
  1994. ib->ptr[15] = PACKET2(0);
  1995. ib->length_dw = 16;
  1996. r = radeon_ib_schedule(rdev, ib);
  1997. if (r) {
  1998. radeon_scratch_free(rdev, scratch);
  1999. radeon_ib_free(rdev, &ib);
  2000. DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
  2001. return r;
  2002. }
  2003. r = radeon_fence_wait(ib->fence, false);
  2004. if (r) {
  2005. DRM_ERROR("radeon: fence wait failed (%d).\n", r);
  2006. return r;
  2007. }
  2008. for (i = 0; i < rdev->usec_timeout; i++) {
  2009. tmp = RREG32(scratch);
  2010. if (tmp == 0xDEADBEEF)
  2011. break;
  2012. DRM_UDELAY(1);
  2013. }
  2014. if (i < rdev->usec_timeout) {
  2015. DRM_INFO("ib test succeeded in %u usecs\n", i);
  2016. } else {
  2017. DRM_ERROR("radeon: ib test failed (sracth(0x%04X)=0x%08X)\n",
  2018. scratch, tmp);
  2019. r = -EINVAL;
  2020. }
  2021. radeon_scratch_free(rdev, scratch);
  2022. radeon_ib_free(rdev, &ib);
  2023. return r;
  2024. }
  2025. /*
  2026. * Interrupts
  2027. *
  2028. * Interrupts use a ring buffer on r6xx/r7xx hardware. It works pretty
  2029. * the same as the CP ring buffer, but in reverse. Rather than the CPU
  2030. * writing to the ring and the GPU consuming, the GPU writes to the ring
  2031. * and host consumes. As the host irq handler processes interrupts, it
  2032. * increments the rptr. When the rptr catches up with the wptr, all the
  2033. * current interrupts have been processed.
  2034. */
  2035. void r600_ih_ring_init(struct radeon_device *rdev, unsigned ring_size)
  2036. {
  2037. u32 rb_bufsz;
  2038. /* Align ring size */
  2039. rb_bufsz = drm_order(ring_size / 4);
  2040. ring_size = (1 << rb_bufsz) * 4;
  2041. rdev->ih.ring_size = ring_size;
  2042. rdev->ih.ptr_mask = rdev->ih.ring_size - 1;
  2043. rdev->ih.rptr = 0;
  2044. }
  2045. static int r600_ih_ring_alloc(struct radeon_device *rdev)
  2046. {
  2047. int r;
  2048. /* Allocate ring buffer */
  2049. if (rdev->ih.ring_obj == NULL) {
  2050. r = radeon_bo_create(rdev, NULL, rdev->ih.ring_size,
  2051. true,
  2052. RADEON_GEM_DOMAIN_GTT,
  2053. &rdev->ih.ring_obj);
  2054. if (r) {
  2055. DRM_ERROR("radeon: failed to create ih ring buffer (%d).\n", r);
  2056. return r;
  2057. }
  2058. r = radeon_bo_reserve(rdev->ih.ring_obj, false);
  2059. if (unlikely(r != 0))
  2060. return r;
  2061. r = radeon_bo_pin(rdev->ih.ring_obj,
  2062. RADEON_GEM_DOMAIN_GTT,
  2063. &rdev->ih.gpu_addr);
  2064. if (r) {
  2065. radeon_bo_unreserve(rdev->ih.ring_obj);
  2066. DRM_ERROR("radeon: failed to pin ih ring buffer (%d).\n", r);
  2067. return r;
  2068. }
  2069. r = radeon_bo_kmap(rdev->ih.ring_obj,
  2070. (void **)&rdev->ih.ring);
  2071. radeon_bo_unreserve(rdev->ih.ring_obj);
  2072. if (r) {
  2073. DRM_ERROR("radeon: failed to map ih ring buffer (%d).\n", r);
  2074. return r;
  2075. }
  2076. }
  2077. return 0;
  2078. }
  2079. static void r600_ih_ring_fini(struct radeon_device *rdev)
  2080. {
  2081. int r;
  2082. if (rdev->ih.ring_obj) {
  2083. r = radeon_bo_reserve(rdev->ih.ring_obj, false);
  2084. if (likely(r == 0)) {
  2085. radeon_bo_kunmap(rdev->ih.ring_obj);
  2086. radeon_bo_unpin(rdev->ih.ring_obj);
  2087. radeon_bo_unreserve(rdev->ih.ring_obj);
  2088. }
  2089. radeon_bo_unref(&rdev->ih.ring_obj);
  2090. rdev->ih.ring = NULL;
  2091. rdev->ih.ring_obj = NULL;
  2092. }
  2093. }
  2094. static void r600_rlc_stop(struct radeon_device *rdev)
  2095. {
  2096. if (rdev->family >= CHIP_RV770) {
  2097. /* r7xx asics need to soft reset RLC before halting */
  2098. WREG32(SRBM_SOFT_RESET, SOFT_RESET_RLC);
  2099. RREG32(SRBM_SOFT_RESET);
  2100. udelay(15000);
  2101. WREG32(SRBM_SOFT_RESET, 0);
  2102. RREG32(SRBM_SOFT_RESET);
  2103. }
  2104. WREG32(RLC_CNTL, 0);
  2105. }
  2106. static void r600_rlc_start(struct radeon_device *rdev)
  2107. {
  2108. WREG32(RLC_CNTL, RLC_ENABLE);
  2109. }
  2110. static int r600_rlc_init(struct radeon_device *rdev)
  2111. {
  2112. u32 i;
  2113. const __be32 *fw_data;
  2114. if (!rdev->rlc_fw)
  2115. return -EINVAL;
  2116. r600_rlc_stop(rdev);
  2117. WREG32(RLC_HB_BASE, 0);
  2118. WREG32(RLC_HB_CNTL, 0);
  2119. WREG32(RLC_HB_RPTR, 0);
  2120. WREG32(RLC_HB_WPTR, 0);
  2121. WREG32(RLC_HB_WPTR_LSB_ADDR, 0);
  2122. WREG32(RLC_HB_WPTR_MSB_ADDR, 0);
  2123. WREG32(RLC_MC_CNTL, 0);
  2124. WREG32(RLC_UCODE_CNTL, 0);
  2125. fw_data = (const __be32 *)rdev->rlc_fw->data;
  2126. if (rdev->family >= CHIP_RV770) {
  2127. for (i = 0; i < R700_RLC_UCODE_SIZE; i++) {
  2128. WREG32(RLC_UCODE_ADDR, i);
  2129. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2130. }
  2131. } else {
  2132. for (i = 0; i < RLC_UCODE_SIZE; i++) {
  2133. WREG32(RLC_UCODE_ADDR, i);
  2134. WREG32(RLC_UCODE_DATA, be32_to_cpup(fw_data++));
  2135. }
  2136. }
  2137. WREG32(RLC_UCODE_ADDR, 0);
  2138. r600_rlc_start(rdev);
  2139. return 0;
  2140. }
  2141. static void r600_enable_interrupts(struct radeon_device *rdev)
  2142. {
  2143. u32 ih_cntl = RREG32(IH_CNTL);
  2144. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  2145. ih_cntl |= ENABLE_INTR;
  2146. ih_rb_cntl |= IH_RB_ENABLE;
  2147. WREG32(IH_CNTL, ih_cntl);
  2148. WREG32(IH_RB_CNTL, ih_rb_cntl);
  2149. rdev->ih.enabled = true;
  2150. }
  2151. static void r600_disable_interrupts(struct radeon_device *rdev)
  2152. {
  2153. u32 ih_rb_cntl = RREG32(IH_RB_CNTL);
  2154. u32 ih_cntl = RREG32(IH_CNTL);
  2155. ih_rb_cntl &= ~IH_RB_ENABLE;
  2156. ih_cntl &= ~ENABLE_INTR;
  2157. WREG32(IH_RB_CNTL, ih_rb_cntl);
  2158. WREG32(IH_CNTL, ih_cntl);
  2159. /* set rptr, wptr to 0 */
  2160. WREG32(IH_RB_RPTR, 0);
  2161. WREG32(IH_RB_WPTR, 0);
  2162. rdev->ih.enabled = false;
  2163. rdev->ih.wptr = 0;
  2164. rdev->ih.rptr = 0;
  2165. }
  2166. static void r600_disable_interrupt_state(struct radeon_device *rdev)
  2167. {
  2168. u32 tmp;
  2169. WREG32(CP_INT_CNTL, 0);
  2170. WREG32(GRBM_INT_CNTL, 0);
  2171. WREG32(DxMODE_INT_MASK, 0);
  2172. if (ASIC_IS_DCE3(rdev)) {
  2173. WREG32(DCE3_DACA_AUTODETECT_INT_CONTROL, 0);
  2174. WREG32(DCE3_DACB_AUTODETECT_INT_CONTROL, 0);
  2175. tmp = RREG32(DC_HPD1_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2176. WREG32(DC_HPD1_INT_CONTROL, tmp);
  2177. tmp = RREG32(DC_HPD2_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2178. WREG32(DC_HPD2_INT_CONTROL, tmp);
  2179. tmp = RREG32(DC_HPD3_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2180. WREG32(DC_HPD3_INT_CONTROL, tmp);
  2181. tmp = RREG32(DC_HPD4_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2182. WREG32(DC_HPD4_INT_CONTROL, tmp);
  2183. if (ASIC_IS_DCE32(rdev)) {
  2184. tmp = RREG32(DC_HPD5_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2185. WREG32(DC_HPD5_INT_CONTROL, tmp);
  2186. tmp = RREG32(DC_HPD6_INT_CONTROL) & DC_HPDx_INT_POLARITY;
  2187. WREG32(DC_HPD6_INT_CONTROL, tmp);
  2188. }
  2189. } else {
  2190. WREG32(DACA_AUTODETECT_INT_CONTROL, 0);
  2191. WREG32(DACB_AUTODETECT_INT_CONTROL, 0);
  2192. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  2193. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  2194. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  2195. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  2196. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & DC_HOT_PLUG_DETECTx_INT_POLARITY;
  2197. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  2198. }
  2199. }
  2200. int r600_irq_init(struct radeon_device *rdev)
  2201. {
  2202. int ret = 0;
  2203. int rb_bufsz;
  2204. u32 interrupt_cntl, ih_cntl, ih_rb_cntl;
  2205. /* allocate ring */
  2206. ret = r600_ih_ring_alloc(rdev);
  2207. if (ret)
  2208. return ret;
  2209. /* disable irqs */
  2210. r600_disable_interrupts(rdev);
  2211. /* init rlc */
  2212. ret = r600_rlc_init(rdev);
  2213. if (ret) {
  2214. r600_ih_ring_fini(rdev);
  2215. return ret;
  2216. }
  2217. /* setup interrupt control */
  2218. /* set dummy read address to ring address */
  2219. WREG32(INTERRUPT_CNTL2, rdev->ih.gpu_addr >> 8);
  2220. interrupt_cntl = RREG32(INTERRUPT_CNTL);
  2221. /* IH_DUMMY_RD_OVERRIDE=0 - dummy read disabled with msi, enabled without msi
  2222. * IH_DUMMY_RD_OVERRIDE=1 - dummy read controlled by IH_DUMMY_RD_EN
  2223. */
  2224. interrupt_cntl &= ~IH_DUMMY_RD_OVERRIDE;
  2225. /* IH_REQ_NONSNOOP_EN=1 if ring is in non-cacheable memory, e.g., vram */
  2226. interrupt_cntl &= ~IH_REQ_NONSNOOP_EN;
  2227. WREG32(INTERRUPT_CNTL, interrupt_cntl);
  2228. WREG32(IH_RB_BASE, rdev->ih.gpu_addr >> 8);
  2229. rb_bufsz = drm_order(rdev->ih.ring_size / 4);
  2230. ih_rb_cntl = (IH_WPTR_OVERFLOW_ENABLE |
  2231. IH_WPTR_OVERFLOW_CLEAR |
  2232. (rb_bufsz << 1));
  2233. /* WPTR writeback, not yet */
  2234. /*ih_rb_cntl |= IH_WPTR_WRITEBACK_ENABLE;*/
  2235. WREG32(IH_RB_WPTR_ADDR_LO, 0);
  2236. WREG32(IH_RB_WPTR_ADDR_HI, 0);
  2237. WREG32(IH_RB_CNTL, ih_rb_cntl);
  2238. /* set rptr, wptr to 0 */
  2239. WREG32(IH_RB_RPTR, 0);
  2240. WREG32(IH_RB_WPTR, 0);
  2241. /* Default settings for IH_CNTL (disabled at first) */
  2242. ih_cntl = MC_WRREQ_CREDIT(0x10) | MC_WR_CLEAN_CNT(0x10);
  2243. /* RPTR_REARM only works if msi's are enabled */
  2244. if (rdev->msi_enabled)
  2245. ih_cntl |= RPTR_REARM;
  2246. #ifdef __BIG_ENDIAN
  2247. ih_cntl |= IH_MC_SWAP(IH_MC_SWAP_32BIT);
  2248. #endif
  2249. WREG32(IH_CNTL, ih_cntl);
  2250. /* force the active interrupt state to all disabled */
  2251. r600_disable_interrupt_state(rdev);
  2252. /* enable irqs */
  2253. r600_enable_interrupts(rdev);
  2254. return ret;
  2255. }
  2256. void r600_irq_suspend(struct radeon_device *rdev)
  2257. {
  2258. r600_disable_interrupts(rdev);
  2259. r600_rlc_stop(rdev);
  2260. }
  2261. void r600_irq_fini(struct radeon_device *rdev)
  2262. {
  2263. r600_irq_suspend(rdev);
  2264. r600_ih_ring_fini(rdev);
  2265. }
  2266. int r600_irq_set(struct radeon_device *rdev)
  2267. {
  2268. u32 cp_int_cntl = CNTX_BUSY_INT_ENABLE | CNTX_EMPTY_INT_ENABLE;
  2269. u32 mode_int = 0;
  2270. u32 hpd1, hpd2, hpd3, hpd4 = 0, hpd5 = 0, hpd6 = 0;
  2271. if (!rdev->irq.installed) {
  2272. WARN(1, "Can't enable IRQ/MSI because no handler is installed.\n");
  2273. return -EINVAL;
  2274. }
  2275. /* don't enable anything if the ih is disabled */
  2276. if (!rdev->ih.enabled) {
  2277. r600_disable_interrupts(rdev);
  2278. /* force the active interrupt state to all disabled */
  2279. r600_disable_interrupt_state(rdev);
  2280. return 0;
  2281. }
  2282. if (ASIC_IS_DCE3(rdev)) {
  2283. hpd1 = RREG32(DC_HPD1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2284. hpd2 = RREG32(DC_HPD2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2285. hpd3 = RREG32(DC_HPD3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2286. hpd4 = RREG32(DC_HPD4_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2287. if (ASIC_IS_DCE32(rdev)) {
  2288. hpd5 = RREG32(DC_HPD5_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2289. hpd6 = RREG32(DC_HPD6_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2290. }
  2291. } else {
  2292. hpd1 = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2293. hpd2 = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2294. hpd3 = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL) & ~DC_HPDx_INT_EN;
  2295. }
  2296. if (rdev->irq.sw_int) {
  2297. DRM_DEBUG("r600_irq_set: sw int\n");
  2298. cp_int_cntl |= RB_INT_ENABLE;
  2299. }
  2300. if (rdev->irq.crtc_vblank_int[0]) {
  2301. DRM_DEBUG("r600_irq_set: vblank 0\n");
  2302. mode_int |= D1MODE_VBLANK_INT_MASK;
  2303. }
  2304. if (rdev->irq.crtc_vblank_int[1]) {
  2305. DRM_DEBUG("r600_irq_set: vblank 1\n");
  2306. mode_int |= D2MODE_VBLANK_INT_MASK;
  2307. }
  2308. if (rdev->irq.hpd[0]) {
  2309. DRM_DEBUG("r600_irq_set: hpd 1\n");
  2310. hpd1 |= DC_HPDx_INT_EN;
  2311. }
  2312. if (rdev->irq.hpd[1]) {
  2313. DRM_DEBUG("r600_irq_set: hpd 2\n");
  2314. hpd2 |= DC_HPDx_INT_EN;
  2315. }
  2316. if (rdev->irq.hpd[2]) {
  2317. DRM_DEBUG("r600_irq_set: hpd 3\n");
  2318. hpd3 |= DC_HPDx_INT_EN;
  2319. }
  2320. if (rdev->irq.hpd[3]) {
  2321. DRM_DEBUG("r600_irq_set: hpd 4\n");
  2322. hpd4 |= DC_HPDx_INT_EN;
  2323. }
  2324. if (rdev->irq.hpd[4]) {
  2325. DRM_DEBUG("r600_irq_set: hpd 5\n");
  2326. hpd5 |= DC_HPDx_INT_EN;
  2327. }
  2328. if (rdev->irq.hpd[5]) {
  2329. DRM_DEBUG("r600_irq_set: hpd 6\n");
  2330. hpd6 |= DC_HPDx_INT_EN;
  2331. }
  2332. WREG32(CP_INT_CNTL, cp_int_cntl);
  2333. WREG32(DxMODE_INT_MASK, mode_int);
  2334. if (ASIC_IS_DCE3(rdev)) {
  2335. WREG32(DC_HPD1_INT_CONTROL, hpd1);
  2336. WREG32(DC_HPD2_INT_CONTROL, hpd2);
  2337. WREG32(DC_HPD3_INT_CONTROL, hpd3);
  2338. WREG32(DC_HPD4_INT_CONTROL, hpd4);
  2339. if (ASIC_IS_DCE32(rdev)) {
  2340. WREG32(DC_HPD5_INT_CONTROL, hpd5);
  2341. WREG32(DC_HPD6_INT_CONTROL, hpd6);
  2342. }
  2343. } else {
  2344. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, hpd1);
  2345. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, hpd2);
  2346. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, hpd3);
  2347. }
  2348. return 0;
  2349. }
  2350. static inline void r600_irq_ack(struct radeon_device *rdev,
  2351. u32 *disp_int,
  2352. u32 *disp_int_cont,
  2353. u32 *disp_int_cont2)
  2354. {
  2355. u32 tmp;
  2356. if (ASIC_IS_DCE3(rdev)) {
  2357. *disp_int = RREG32(DCE3_DISP_INTERRUPT_STATUS);
  2358. *disp_int_cont = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE);
  2359. *disp_int_cont2 = RREG32(DCE3_DISP_INTERRUPT_STATUS_CONTINUE2);
  2360. } else {
  2361. *disp_int = RREG32(DISP_INTERRUPT_STATUS);
  2362. *disp_int_cont = RREG32(DISP_INTERRUPT_STATUS_CONTINUE);
  2363. *disp_int_cont2 = 0;
  2364. }
  2365. if (*disp_int & LB_D1_VBLANK_INTERRUPT)
  2366. WREG32(D1MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
  2367. if (*disp_int & LB_D1_VLINE_INTERRUPT)
  2368. WREG32(D1MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
  2369. if (*disp_int & LB_D2_VBLANK_INTERRUPT)
  2370. WREG32(D2MODE_VBLANK_STATUS, DxMODE_VBLANK_ACK);
  2371. if (*disp_int & LB_D2_VLINE_INTERRUPT)
  2372. WREG32(D2MODE_VLINE_STATUS, DxMODE_VLINE_ACK);
  2373. if (*disp_int & DC_HPD1_INTERRUPT) {
  2374. if (ASIC_IS_DCE3(rdev)) {
  2375. tmp = RREG32(DC_HPD1_INT_CONTROL);
  2376. tmp |= DC_HPDx_INT_ACK;
  2377. WREG32(DC_HPD1_INT_CONTROL, tmp);
  2378. } else {
  2379. tmp = RREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL);
  2380. tmp |= DC_HPDx_INT_ACK;
  2381. WREG32(DC_HOT_PLUG_DETECT1_INT_CONTROL, tmp);
  2382. }
  2383. }
  2384. if (*disp_int & DC_HPD2_INTERRUPT) {
  2385. if (ASIC_IS_DCE3(rdev)) {
  2386. tmp = RREG32(DC_HPD2_INT_CONTROL);
  2387. tmp |= DC_HPDx_INT_ACK;
  2388. WREG32(DC_HPD2_INT_CONTROL, tmp);
  2389. } else {
  2390. tmp = RREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL);
  2391. tmp |= DC_HPDx_INT_ACK;
  2392. WREG32(DC_HOT_PLUG_DETECT2_INT_CONTROL, tmp);
  2393. }
  2394. }
  2395. if (*disp_int_cont & DC_HPD3_INTERRUPT) {
  2396. if (ASIC_IS_DCE3(rdev)) {
  2397. tmp = RREG32(DC_HPD3_INT_CONTROL);
  2398. tmp |= DC_HPDx_INT_ACK;
  2399. WREG32(DC_HPD3_INT_CONTROL, tmp);
  2400. } else {
  2401. tmp = RREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL);
  2402. tmp |= DC_HPDx_INT_ACK;
  2403. WREG32(DC_HOT_PLUG_DETECT3_INT_CONTROL, tmp);
  2404. }
  2405. }
  2406. if (*disp_int_cont & DC_HPD4_INTERRUPT) {
  2407. tmp = RREG32(DC_HPD4_INT_CONTROL);
  2408. tmp |= DC_HPDx_INT_ACK;
  2409. WREG32(DC_HPD4_INT_CONTROL, tmp);
  2410. }
  2411. if (ASIC_IS_DCE32(rdev)) {
  2412. if (*disp_int_cont2 & DC_HPD5_INTERRUPT) {
  2413. tmp = RREG32(DC_HPD5_INT_CONTROL);
  2414. tmp |= DC_HPDx_INT_ACK;
  2415. WREG32(DC_HPD5_INT_CONTROL, tmp);
  2416. }
  2417. if (*disp_int_cont2 & DC_HPD6_INTERRUPT) {
  2418. tmp = RREG32(DC_HPD5_INT_CONTROL);
  2419. tmp |= DC_HPDx_INT_ACK;
  2420. WREG32(DC_HPD6_INT_CONTROL, tmp);
  2421. }
  2422. }
  2423. }
  2424. void r600_irq_disable(struct radeon_device *rdev)
  2425. {
  2426. u32 disp_int, disp_int_cont, disp_int_cont2;
  2427. r600_disable_interrupts(rdev);
  2428. /* Wait and acknowledge irq */
  2429. mdelay(1);
  2430. r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
  2431. r600_disable_interrupt_state(rdev);
  2432. }
  2433. static inline u32 r600_get_ih_wptr(struct radeon_device *rdev)
  2434. {
  2435. u32 wptr, tmp;
  2436. /* XXX use writeback */
  2437. wptr = RREG32(IH_RB_WPTR);
  2438. if (wptr & RB_OVERFLOW) {
  2439. /* When a ring buffer overflow happen start parsing interrupt
  2440. * from the last not overwritten vector (wptr + 16). Hopefully
  2441. * this should allow us to catchup.
  2442. */
  2443. dev_warn(rdev->dev, "IH ring buffer overflow (0x%08X, %d, %d)\n",
  2444. wptr, rdev->ih.rptr, (wptr + 16) + rdev->ih.ptr_mask);
  2445. rdev->ih.rptr = (wptr + 16) & rdev->ih.ptr_mask;
  2446. tmp = RREG32(IH_RB_CNTL);
  2447. tmp |= IH_WPTR_OVERFLOW_CLEAR;
  2448. WREG32(IH_RB_CNTL, tmp);
  2449. }
  2450. return (wptr & rdev->ih.ptr_mask);
  2451. }
  2452. /* r600 IV Ring
  2453. * Each IV ring entry is 128 bits:
  2454. * [7:0] - interrupt source id
  2455. * [31:8] - reserved
  2456. * [59:32] - interrupt source data
  2457. * [127:60] - reserved
  2458. *
  2459. * The basic interrupt vector entries
  2460. * are decoded as follows:
  2461. * src_id src_data description
  2462. * 1 0 D1 Vblank
  2463. * 1 1 D1 Vline
  2464. * 5 0 D2 Vblank
  2465. * 5 1 D2 Vline
  2466. * 19 0 FP Hot plug detection A
  2467. * 19 1 FP Hot plug detection B
  2468. * 19 2 DAC A auto-detection
  2469. * 19 3 DAC B auto-detection
  2470. * 176 - CP_INT RB
  2471. * 177 - CP_INT IB1
  2472. * 178 - CP_INT IB2
  2473. * 181 - EOP Interrupt
  2474. * 233 - GUI Idle
  2475. *
  2476. * Note, these are based on r600 and may need to be
  2477. * adjusted or added to on newer asics
  2478. */
  2479. int r600_irq_process(struct radeon_device *rdev)
  2480. {
  2481. u32 wptr = r600_get_ih_wptr(rdev);
  2482. u32 rptr = rdev->ih.rptr;
  2483. u32 src_id, src_data;
  2484. u32 ring_index, disp_int, disp_int_cont, disp_int_cont2;
  2485. unsigned long flags;
  2486. bool queue_hotplug = false;
  2487. DRM_DEBUG("r600_irq_process start: rptr %d, wptr %d\n", rptr, wptr);
  2488. if (!rdev->ih.enabled)
  2489. return IRQ_NONE;
  2490. spin_lock_irqsave(&rdev->ih.lock, flags);
  2491. if (rptr == wptr) {
  2492. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  2493. return IRQ_NONE;
  2494. }
  2495. if (rdev->shutdown) {
  2496. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  2497. return IRQ_NONE;
  2498. }
  2499. restart_ih:
  2500. /* display interrupts */
  2501. r600_irq_ack(rdev, &disp_int, &disp_int_cont, &disp_int_cont2);
  2502. rdev->ih.wptr = wptr;
  2503. while (rptr != wptr) {
  2504. /* wptr/rptr are in bytes! */
  2505. ring_index = rptr / 4;
  2506. src_id = rdev->ih.ring[ring_index] & 0xff;
  2507. src_data = rdev->ih.ring[ring_index + 1] & 0xfffffff;
  2508. switch (src_id) {
  2509. case 1: /* D1 vblank/vline */
  2510. switch (src_data) {
  2511. case 0: /* D1 vblank */
  2512. if (disp_int & LB_D1_VBLANK_INTERRUPT) {
  2513. drm_handle_vblank(rdev->ddev, 0);
  2514. rdev->pm.vblank_sync = true;
  2515. wake_up(&rdev->irq.vblank_queue);
  2516. disp_int &= ~LB_D1_VBLANK_INTERRUPT;
  2517. DRM_DEBUG("IH: D1 vblank\n");
  2518. }
  2519. break;
  2520. case 1: /* D1 vline */
  2521. if (disp_int & LB_D1_VLINE_INTERRUPT) {
  2522. disp_int &= ~LB_D1_VLINE_INTERRUPT;
  2523. DRM_DEBUG("IH: D1 vline\n");
  2524. }
  2525. break;
  2526. default:
  2527. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2528. break;
  2529. }
  2530. break;
  2531. case 5: /* D2 vblank/vline */
  2532. switch (src_data) {
  2533. case 0: /* D2 vblank */
  2534. if (disp_int & LB_D2_VBLANK_INTERRUPT) {
  2535. drm_handle_vblank(rdev->ddev, 1);
  2536. rdev->pm.vblank_sync = true;
  2537. wake_up(&rdev->irq.vblank_queue);
  2538. disp_int &= ~LB_D2_VBLANK_INTERRUPT;
  2539. DRM_DEBUG("IH: D2 vblank\n");
  2540. }
  2541. break;
  2542. case 1: /* D1 vline */
  2543. if (disp_int & LB_D2_VLINE_INTERRUPT) {
  2544. disp_int &= ~LB_D2_VLINE_INTERRUPT;
  2545. DRM_DEBUG("IH: D2 vline\n");
  2546. }
  2547. break;
  2548. default:
  2549. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2550. break;
  2551. }
  2552. break;
  2553. case 19: /* HPD/DAC hotplug */
  2554. switch (src_data) {
  2555. case 0:
  2556. if (disp_int & DC_HPD1_INTERRUPT) {
  2557. disp_int &= ~DC_HPD1_INTERRUPT;
  2558. queue_hotplug = true;
  2559. DRM_DEBUG("IH: HPD1\n");
  2560. }
  2561. break;
  2562. case 1:
  2563. if (disp_int & DC_HPD2_INTERRUPT) {
  2564. disp_int &= ~DC_HPD2_INTERRUPT;
  2565. queue_hotplug = true;
  2566. DRM_DEBUG("IH: HPD2\n");
  2567. }
  2568. break;
  2569. case 4:
  2570. if (disp_int_cont & DC_HPD3_INTERRUPT) {
  2571. disp_int_cont &= ~DC_HPD3_INTERRUPT;
  2572. queue_hotplug = true;
  2573. DRM_DEBUG("IH: HPD3\n");
  2574. }
  2575. break;
  2576. case 5:
  2577. if (disp_int_cont & DC_HPD4_INTERRUPT) {
  2578. disp_int_cont &= ~DC_HPD4_INTERRUPT;
  2579. queue_hotplug = true;
  2580. DRM_DEBUG("IH: HPD4\n");
  2581. }
  2582. break;
  2583. case 10:
  2584. if (disp_int_cont2 & DC_HPD5_INTERRUPT) {
  2585. disp_int_cont2 &= ~DC_HPD5_INTERRUPT;
  2586. queue_hotplug = true;
  2587. DRM_DEBUG("IH: HPD5\n");
  2588. }
  2589. break;
  2590. case 12:
  2591. if (disp_int_cont2 & DC_HPD6_INTERRUPT) {
  2592. disp_int_cont2 &= ~DC_HPD6_INTERRUPT;
  2593. queue_hotplug = true;
  2594. DRM_DEBUG("IH: HPD6\n");
  2595. }
  2596. break;
  2597. default:
  2598. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2599. break;
  2600. }
  2601. break;
  2602. case 176: /* CP_INT in ring buffer */
  2603. case 177: /* CP_INT in IB1 */
  2604. case 178: /* CP_INT in IB2 */
  2605. DRM_DEBUG("IH: CP int: 0x%08x\n", src_data);
  2606. radeon_fence_process(rdev);
  2607. break;
  2608. case 181: /* CP EOP event */
  2609. DRM_DEBUG("IH: CP EOP\n");
  2610. break;
  2611. default:
  2612. DRM_DEBUG("Unhandled interrupt: %d %d\n", src_id, src_data);
  2613. break;
  2614. }
  2615. /* wptr/rptr are in bytes! */
  2616. rptr += 16;
  2617. rptr &= rdev->ih.ptr_mask;
  2618. }
  2619. /* make sure wptr hasn't changed while processing */
  2620. wptr = r600_get_ih_wptr(rdev);
  2621. if (wptr != rdev->ih.wptr)
  2622. goto restart_ih;
  2623. if (queue_hotplug)
  2624. queue_work(rdev->wq, &rdev->hotplug_work);
  2625. rdev->ih.rptr = rptr;
  2626. WREG32(IH_RB_RPTR, rdev->ih.rptr);
  2627. spin_unlock_irqrestore(&rdev->ih.lock, flags);
  2628. return IRQ_HANDLED;
  2629. }
  2630. /*
  2631. * Debugfs info
  2632. */
  2633. #if defined(CONFIG_DEBUG_FS)
  2634. static int r600_debugfs_cp_ring_info(struct seq_file *m, void *data)
  2635. {
  2636. struct drm_info_node *node = (struct drm_info_node *) m->private;
  2637. struct drm_device *dev = node->minor->dev;
  2638. struct radeon_device *rdev = dev->dev_private;
  2639. unsigned count, i, j;
  2640. radeon_ring_free_size(rdev);
  2641. count = (rdev->cp.ring_size / 4) - rdev->cp.ring_free_dw;
  2642. seq_printf(m, "CP_STAT 0x%08x\n", RREG32(CP_STAT));
  2643. seq_printf(m, "CP_RB_WPTR 0x%08x\n", RREG32(CP_RB_WPTR));
  2644. seq_printf(m, "CP_RB_RPTR 0x%08x\n", RREG32(CP_RB_RPTR));
  2645. seq_printf(m, "driver's copy of the CP_RB_WPTR 0x%08x\n", rdev->cp.wptr);
  2646. seq_printf(m, "driver's copy of the CP_RB_RPTR 0x%08x\n", rdev->cp.rptr);
  2647. seq_printf(m, "%u free dwords in ring\n", rdev->cp.ring_free_dw);
  2648. seq_printf(m, "%u dwords in ring\n", count);
  2649. i = rdev->cp.rptr;
  2650. for (j = 0; j <= count; j++) {
  2651. seq_printf(m, "r[%04d]=0x%08x\n", i, rdev->cp.ring[i]);
  2652. i = (i + 1) & rdev->cp.ptr_mask;
  2653. }
  2654. return 0;
  2655. }
  2656. static int r600_debugfs_mc_info(struct seq_file *m, void *data)
  2657. {
  2658. struct drm_info_node *node = (struct drm_info_node *) m->private;
  2659. struct drm_device *dev = node->minor->dev;
  2660. struct radeon_device *rdev = dev->dev_private;
  2661. DREG32_SYS(m, rdev, R_000E50_SRBM_STATUS);
  2662. DREG32_SYS(m, rdev, VM_L2_STATUS);
  2663. return 0;
  2664. }
  2665. static struct drm_info_list r600_mc_info_list[] = {
  2666. {"r600_mc_info", r600_debugfs_mc_info, 0, NULL},
  2667. {"r600_ring_info", r600_debugfs_cp_ring_info, 0, NULL},
  2668. };
  2669. #endif
  2670. int r600_debugfs_mc_info_init(struct radeon_device *rdev)
  2671. {
  2672. #if defined(CONFIG_DEBUG_FS)
  2673. return radeon_debugfs_add_files(rdev, r600_mc_info_list, ARRAY_SIZE(r600_mc_info_list));
  2674. #else
  2675. return 0;
  2676. #endif
  2677. }
  2678. /**
  2679. * r600_ioctl_wait_idle - flush host path cache on wait idle ioctl
  2680. * rdev: radeon device structure
  2681. * bo: buffer object struct which userspace is waiting for idle
  2682. *
  2683. * Some R6XX/R7XX doesn't seems to take into account HDP flush performed
  2684. * through ring buffer, this leads to corruption in rendering, see
  2685. * http://bugzilla.kernel.org/show_bug.cgi?id=15186 to avoid this we
  2686. * directly perform HDP flush by writing register through MMIO.
  2687. */
  2688. void r600_ioctl_wait_idle(struct radeon_device *rdev, struct radeon_bo *bo)
  2689. {
  2690. WREG32(R_005480_HDP_MEM_COHERENCY_FLUSH_CNTL, 0x1);
  2691. }