radeon_cp.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353
  1. /* radeon_cp.c -- CP support for Radeon -*- linux-c -*- */
  2. /*
  3. * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
  4. * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
  5. * All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the next
  15. * paragraph) shall be included in all copies or substantial portions of the
  16. * Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  22. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  23. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  24. * DEALINGS IN THE SOFTWARE.
  25. *
  26. * Authors:
  27. * Kevin E. Martin <martin@valinux.com>
  28. * Gareth Hughes <gareth@valinux.com>
  29. */
  30. #include "drmP.h"
  31. #include "drm.h"
  32. #include "radeon_drm.h"
  33. #include "radeon_drv.h"
  34. #include "r300_reg.h"
  35. #define RADEON_FIFO_DEBUG 0
  36. static int radeon_do_cleanup_cp(struct drm_device * dev);
  37. /* CP microcode (from ATI) */
  38. static const u32 R200_cp_microcode[][2] = {
  39. {0x21007000, 0000000000},
  40. {0x20007000, 0000000000},
  41. {0x000000ab, 0x00000004},
  42. {0x000000af, 0x00000004},
  43. {0x66544a49, 0000000000},
  44. {0x49494174, 0000000000},
  45. {0x54517d83, 0000000000},
  46. {0x498d8b64, 0000000000},
  47. {0x49494949, 0000000000},
  48. {0x49da493c, 0000000000},
  49. {0x49989898, 0000000000},
  50. {0xd34949d5, 0000000000},
  51. {0x9dc90e11, 0000000000},
  52. {0xce9b9b9b, 0000000000},
  53. {0x000f0000, 0x00000016},
  54. {0x352e232c, 0000000000},
  55. {0x00000013, 0x00000004},
  56. {0x000f0000, 0x00000016},
  57. {0x352e272c, 0000000000},
  58. {0x000f0001, 0x00000016},
  59. {0x3239362f, 0000000000},
  60. {0x000077ef, 0x00000002},
  61. {0x00061000, 0x00000002},
  62. {0x00000020, 0x0000001a},
  63. {0x00004000, 0x0000001e},
  64. {0x00061000, 0x00000002},
  65. {0x00000020, 0x0000001a},
  66. {0x00004000, 0x0000001e},
  67. {0x00061000, 0x00000002},
  68. {0x00000020, 0x0000001a},
  69. {0x00004000, 0x0000001e},
  70. {0x00000016, 0x00000004},
  71. {0x0003802a, 0x00000002},
  72. {0x040067e0, 0x00000002},
  73. {0x00000016, 0x00000004},
  74. {0x000077e0, 0x00000002},
  75. {0x00065000, 0x00000002},
  76. {0x000037e1, 0x00000002},
  77. {0x040067e1, 0x00000006},
  78. {0x000077e0, 0x00000002},
  79. {0x000077e1, 0x00000002},
  80. {0x000077e1, 0x00000006},
  81. {0xffffffff, 0000000000},
  82. {0x10000000, 0000000000},
  83. {0x0003802a, 0x00000002},
  84. {0x040067e0, 0x00000006},
  85. {0x00007675, 0x00000002},
  86. {0x00007676, 0x00000002},
  87. {0x00007677, 0x00000002},
  88. {0x00007678, 0x00000006},
  89. {0x0003802b, 0x00000002},
  90. {0x04002676, 0x00000002},
  91. {0x00007677, 0x00000002},
  92. {0x00007678, 0x00000006},
  93. {0x0000002e, 0x00000018},
  94. {0x0000002e, 0x00000018},
  95. {0000000000, 0x00000006},
  96. {0x0000002f, 0x00000018},
  97. {0x0000002f, 0x00000018},
  98. {0000000000, 0x00000006},
  99. {0x01605000, 0x00000002},
  100. {0x00065000, 0x00000002},
  101. {0x00098000, 0x00000002},
  102. {0x00061000, 0x00000002},
  103. {0x64c0603d, 0x00000004},
  104. {0x00080000, 0x00000016},
  105. {0000000000, 0000000000},
  106. {0x0400251d, 0x00000002},
  107. {0x00007580, 0x00000002},
  108. {0x00067581, 0x00000002},
  109. {0x04002580, 0x00000002},
  110. {0x00067581, 0x00000002},
  111. {0x00000046, 0x00000004},
  112. {0x00005000, 0000000000},
  113. {0x00061000, 0x00000002},
  114. {0x0000750e, 0x00000002},
  115. {0x00019000, 0x00000002},
  116. {0x00011055, 0x00000014},
  117. {0x00000055, 0x00000012},
  118. {0x0400250f, 0x00000002},
  119. {0x0000504a, 0x00000004},
  120. {0x00007565, 0x00000002},
  121. {0x00007566, 0x00000002},
  122. {0x00000051, 0x00000004},
  123. {0x01e655b4, 0x00000002},
  124. {0x4401b0dc, 0x00000002},
  125. {0x01c110dc, 0x00000002},
  126. {0x2666705d, 0x00000018},
  127. {0x040c2565, 0x00000002},
  128. {0x0000005d, 0x00000018},
  129. {0x04002564, 0x00000002},
  130. {0x00007566, 0x00000002},
  131. {0x00000054, 0x00000004},
  132. {0x00401060, 0x00000008},
  133. {0x00101000, 0x00000002},
  134. {0x000d80ff, 0x00000002},
  135. {0x00800063, 0x00000008},
  136. {0x000f9000, 0x00000002},
  137. {0x000e00ff, 0x00000002},
  138. {0000000000, 0x00000006},
  139. {0x00000080, 0x00000018},
  140. {0x00000054, 0x00000004},
  141. {0x00007576, 0x00000002},
  142. {0x00065000, 0x00000002},
  143. {0x00009000, 0x00000002},
  144. {0x00041000, 0x00000002},
  145. {0x0c00350e, 0x00000002},
  146. {0x00049000, 0x00000002},
  147. {0x00051000, 0x00000002},
  148. {0x01e785f8, 0x00000002},
  149. {0x00200000, 0x00000002},
  150. {0x00600073, 0x0000000c},
  151. {0x00007563, 0x00000002},
  152. {0x006075f0, 0x00000021},
  153. {0x20007068, 0x00000004},
  154. {0x00005068, 0x00000004},
  155. {0x00007576, 0x00000002},
  156. {0x00007577, 0x00000002},
  157. {0x0000750e, 0x00000002},
  158. {0x0000750f, 0x00000002},
  159. {0x00a05000, 0x00000002},
  160. {0x00600076, 0x0000000c},
  161. {0x006075f0, 0x00000021},
  162. {0x000075f8, 0x00000002},
  163. {0x00000076, 0x00000004},
  164. {0x000a750e, 0x00000002},
  165. {0x0020750f, 0x00000002},
  166. {0x00600079, 0x00000004},
  167. {0x00007570, 0x00000002},
  168. {0x00007571, 0x00000002},
  169. {0x00007572, 0x00000006},
  170. {0x00005000, 0x00000002},
  171. {0x00a05000, 0x00000002},
  172. {0x00007568, 0x00000002},
  173. {0x00061000, 0x00000002},
  174. {0x00000084, 0x0000000c},
  175. {0x00058000, 0x00000002},
  176. {0x0c607562, 0x00000002},
  177. {0x00000086, 0x00000004},
  178. {0x00600085, 0x00000004},
  179. {0x400070dd, 0000000000},
  180. {0x000380dd, 0x00000002},
  181. {0x00000093, 0x0000001c},
  182. {0x00065095, 0x00000018},
  183. {0x040025bb, 0x00000002},
  184. {0x00061096, 0x00000018},
  185. {0x040075bc, 0000000000},
  186. {0x000075bb, 0x00000002},
  187. {0x000075bc, 0000000000},
  188. {0x00090000, 0x00000006},
  189. {0x00090000, 0x00000002},
  190. {0x000d8002, 0x00000006},
  191. {0x00005000, 0x00000002},
  192. {0x00007821, 0x00000002},
  193. {0x00007800, 0000000000},
  194. {0x00007821, 0x00000002},
  195. {0x00007800, 0000000000},
  196. {0x01665000, 0x00000002},
  197. {0x000a0000, 0x00000002},
  198. {0x000671cc, 0x00000002},
  199. {0x0286f1cd, 0x00000002},
  200. {0x000000a3, 0x00000010},
  201. {0x21007000, 0000000000},
  202. {0x000000aa, 0x0000001c},
  203. {0x00065000, 0x00000002},
  204. {0x000a0000, 0x00000002},
  205. {0x00061000, 0x00000002},
  206. {0x000b0000, 0x00000002},
  207. {0x38067000, 0x00000002},
  208. {0x000a00a6, 0x00000004},
  209. {0x20007000, 0000000000},
  210. {0x01200000, 0x00000002},
  211. {0x20077000, 0x00000002},
  212. {0x01200000, 0x00000002},
  213. {0x20007000, 0000000000},
  214. {0x00061000, 0x00000002},
  215. {0x0120751b, 0x00000002},
  216. {0x8040750a, 0x00000002},
  217. {0x8040750b, 0x00000002},
  218. {0x00110000, 0x00000002},
  219. {0x000380dd, 0x00000002},
  220. {0x000000bd, 0x0000001c},
  221. {0x00061096, 0x00000018},
  222. {0x844075bd, 0x00000002},
  223. {0x00061095, 0x00000018},
  224. {0x840075bb, 0x00000002},
  225. {0x00061096, 0x00000018},
  226. {0x844075bc, 0x00000002},
  227. {0x000000c0, 0x00000004},
  228. {0x804075bd, 0x00000002},
  229. {0x800075bb, 0x00000002},
  230. {0x804075bc, 0x00000002},
  231. {0x00108000, 0x00000002},
  232. {0x01400000, 0x00000002},
  233. {0x006000c4, 0x0000000c},
  234. {0x20c07000, 0x00000020},
  235. {0x000000c6, 0x00000012},
  236. {0x00800000, 0x00000006},
  237. {0x0080751d, 0x00000006},
  238. {0x000025bb, 0x00000002},
  239. {0x000040c0, 0x00000004},
  240. {0x0000775c, 0x00000002},
  241. {0x00a05000, 0x00000002},
  242. {0x00661000, 0x00000002},
  243. {0x0460275d, 0x00000020},
  244. {0x00004000, 0000000000},
  245. {0x00007999, 0x00000002},
  246. {0x00a05000, 0x00000002},
  247. {0x00661000, 0x00000002},
  248. {0x0460299b, 0x00000020},
  249. {0x00004000, 0000000000},
  250. {0x01e00830, 0x00000002},
  251. {0x21007000, 0000000000},
  252. {0x00005000, 0x00000002},
  253. {0x00038042, 0x00000002},
  254. {0x040025e0, 0x00000002},
  255. {0x000075e1, 0000000000},
  256. {0x00000001, 0000000000},
  257. {0x000380d9, 0x00000002},
  258. {0x04007394, 0000000000},
  259. {0000000000, 0000000000},
  260. {0000000000, 0000000000},
  261. {0000000000, 0000000000},
  262. {0000000000, 0000000000},
  263. {0000000000, 0000000000},
  264. {0000000000, 0000000000},
  265. {0000000000, 0000000000},
  266. {0000000000, 0000000000},
  267. {0000000000, 0000000000},
  268. {0000000000, 0000000000},
  269. {0000000000, 0000000000},
  270. {0000000000, 0000000000},
  271. {0000000000, 0000000000},
  272. {0000000000, 0000000000},
  273. {0000000000, 0000000000},
  274. {0000000000, 0000000000},
  275. {0000000000, 0000000000},
  276. {0000000000, 0000000000},
  277. {0000000000, 0000000000},
  278. {0000000000, 0000000000},
  279. {0000000000, 0000000000},
  280. {0000000000, 0000000000},
  281. {0000000000, 0000000000},
  282. {0000000000, 0000000000},
  283. {0000000000, 0000000000},
  284. {0000000000, 0000000000},
  285. {0000000000, 0000000000},
  286. {0000000000, 0000000000},
  287. {0000000000, 0000000000},
  288. {0000000000, 0000000000},
  289. {0000000000, 0000000000},
  290. {0000000000, 0000000000},
  291. {0000000000, 0000000000},
  292. {0000000000, 0000000000},
  293. {0000000000, 0000000000},
  294. {0000000000, 0000000000},
  295. };
  296. static const u32 radeon_cp_microcode[][2] = {
  297. {0x21007000, 0000000000},
  298. {0x20007000, 0000000000},
  299. {0x000000b4, 0x00000004},
  300. {0x000000b8, 0x00000004},
  301. {0x6f5b4d4c, 0000000000},
  302. {0x4c4c427f, 0000000000},
  303. {0x5b568a92, 0000000000},
  304. {0x4ca09c6d, 0000000000},
  305. {0xad4c4c4c, 0000000000},
  306. {0x4ce1af3d, 0000000000},
  307. {0xd8afafaf, 0000000000},
  308. {0xd64c4cdc, 0000000000},
  309. {0x4cd10d10, 0000000000},
  310. {0x000f0000, 0x00000016},
  311. {0x362f242d, 0000000000},
  312. {0x00000012, 0x00000004},
  313. {0x000f0000, 0x00000016},
  314. {0x362f282d, 0000000000},
  315. {0x000380e7, 0x00000002},
  316. {0x04002c97, 0x00000002},
  317. {0x000f0001, 0x00000016},
  318. {0x333a3730, 0000000000},
  319. {0x000077ef, 0x00000002},
  320. {0x00061000, 0x00000002},
  321. {0x00000021, 0x0000001a},
  322. {0x00004000, 0x0000001e},
  323. {0x00061000, 0x00000002},
  324. {0x00000021, 0x0000001a},
  325. {0x00004000, 0x0000001e},
  326. {0x00061000, 0x00000002},
  327. {0x00000021, 0x0000001a},
  328. {0x00004000, 0x0000001e},
  329. {0x00000017, 0x00000004},
  330. {0x0003802b, 0x00000002},
  331. {0x040067e0, 0x00000002},
  332. {0x00000017, 0x00000004},
  333. {0x000077e0, 0x00000002},
  334. {0x00065000, 0x00000002},
  335. {0x000037e1, 0x00000002},
  336. {0x040067e1, 0x00000006},
  337. {0x000077e0, 0x00000002},
  338. {0x000077e1, 0x00000002},
  339. {0x000077e1, 0x00000006},
  340. {0xffffffff, 0000000000},
  341. {0x10000000, 0000000000},
  342. {0x0003802b, 0x00000002},
  343. {0x040067e0, 0x00000006},
  344. {0x00007675, 0x00000002},
  345. {0x00007676, 0x00000002},
  346. {0x00007677, 0x00000002},
  347. {0x00007678, 0x00000006},
  348. {0x0003802c, 0x00000002},
  349. {0x04002676, 0x00000002},
  350. {0x00007677, 0x00000002},
  351. {0x00007678, 0x00000006},
  352. {0x0000002f, 0x00000018},
  353. {0x0000002f, 0x00000018},
  354. {0000000000, 0x00000006},
  355. {0x00000030, 0x00000018},
  356. {0x00000030, 0x00000018},
  357. {0000000000, 0x00000006},
  358. {0x01605000, 0x00000002},
  359. {0x00065000, 0x00000002},
  360. {0x00098000, 0x00000002},
  361. {0x00061000, 0x00000002},
  362. {0x64c0603e, 0x00000004},
  363. {0x000380e6, 0x00000002},
  364. {0x040025c5, 0x00000002},
  365. {0x00080000, 0x00000016},
  366. {0000000000, 0000000000},
  367. {0x0400251d, 0x00000002},
  368. {0x00007580, 0x00000002},
  369. {0x00067581, 0x00000002},
  370. {0x04002580, 0x00000002},
  371. {0x00067581, 0x00000002},
  372. {0x00000049, 0x00000004},
  373. {0x00005000, 0000000000},
  374. {0x000380e6, 0x00000002},
  375. {0x040025c5, 0x00000002},
  376. {0x00061000, 0x00000002},
  377. {0x0000750e, 0x00000002},
  378. {0x00019000, 0x00000002},
  379. {0x00011055, 0x00000014},
  380. {0x00000055, 0x00000012},
  381. {0x0400250f, 0x00000002},
  382. {0x0000504f, 0x00000004},
  383. {0x000380e6, 0x00000002},
  384. {0x040025c5, 0x00000002},
  385. {0x00007565, 0x00000002},
  386. {0x00007566, 0x00000002},
  387. {0x00000058, 0x00000004},
  388. {0x000380e6, 0x00000002},
  389. {0x040025c5, 0x00000002},
  390. {0x01e655b4, 0x00000002},
  391. {0x4401b0e4, 0x00000002},
  392. {0x01c110e4, 0x00000002},
  393. {0x26667066, 0x00000018},
  394. {0x040c2565, 0x00000002},
  395. {0x00000066, 0x00000018},
  396. {0x04002564, 0x00000002},
  397. {0x00007566, 0x00000002},
  398. {0x0000005d, 0x00000004},
  399. {0x00401069, 0x00000008},
  400. {0x00101000, 0x00000002},
  401. {0x000d80ff, 0x00000002},
  402. {0x0080006c, 0x00000008},
  403. {0x000f9000, 0x00000002},
  404. {0x000e00ff, 0x00000002},
  405. {0000000000, 0x00000006},
  406. {0x0000008f, 0x00000018},
  407. {0x0000005b, 0x00000004},
  408. {0x000380e6, 0x00000002},
  409. {0x040025c5, 0x00000002},
  410. {0x00007576, 0x00000002},
  411. {0x00065000, 0x00000002},
  412. {0x00009000, 0x00000002},
  413. {0x00041000, 0x00000002},
  414. {0x0c00350e, 0x00000002},
  415. {0x00049000, 0x00000002},
  416. {0x00051000, 0x00000002},
  417. {0x01e785f8, 0x00000002},
  418. {0x00200000, 0x00000002},
  419. {0x0060007e, 0x0000000c},
  420. {0x00007563, 0x00000002},
  421. {0x006075f0, 0x00000021},
  422. {0x20007073, 0x00000004},
  423. {0x00005073, 0x00000004},
  424. {0x000380e6, 0x00000002},
  425. {0x040025c5, 0x00000002},
  426. {0x00007576, 0x00000002},
  427. {0x00007577, 0x00000002},
  428. {0x0000750e, 0x00000002},
  429. {0x0000750f, 0x00000002},
  430. {0x00a05000, 0x00000002},
  431. {0x00600083, 0x0000000c},
  432. {0x006075f0, 0x00000021},
  433. {0x000075f8, 0x00000002},
  434. {0x00000083, 0x00000004},
  435. {0x000a750e, 0x00000002},
  436. {0x000380e6, 0x00000002},
  437. {0x040025c5, 0x00000002},
  438. {0x0020750f, 0x00000002},
  439. {0x00600086, 0x00000004},
  440. {0x00007570, 0x00000002},
  441. {0x00007571, 0x00000002},
  442. {0x00007572, 0x00000006},
  443. {0x000380e6, 0x00000002},
  444. {0x040025c5, 0x00000002},
  445. {0x00005000, 0x00000002},
  446. {0x00a05000, 0x00000002},
  447. {0x00007568, 0x00000002},
  448. {0x00061000, 0x00000002},
  449. {0x00000095, 0x0000000c},
  450. {0x00058000, 0x00000002},
  451. {0x0c607562, 0x00000002},
  452. {0x00000097, 0x00000004},
  453. {0x000380e6, 0x00000002},
  454. {0x040025c5, 0x00000002},
  455. {0x00600096, 0x00000004},
  456. {0x400070e5, 0000000000},
  457. {0x000380e6, 0x00000002},
  458. {0x040025c5, 0x00000002},
  459. {0x000380e5, 0x00000002},
  460. {0x000000a8, 0x0000001c},
  461. {0x000650aa, 0x00000018},
  462. {0x040025bb, 0x00000002},
  463. {0x000610ab, 0x00000018},
  464. {0x040075bc, 0000000000},
  465. {0x000075bb, 0x00000002},
  466. {0x000075bc, 0000000000},
  467. {0x00090000, 0x00000006},
  468. {0x00090000, 0x00000002},
  469. {0x000d8002, 0x00000006},
  470. {0x00007832, 0x00000002},
  471. {0x00005000, 0x00000002},
  472. {0x000380e7, 0x00000002},
  473. {0x04002c97, 0x00000002},
  474. {0x00007820, 0x00000002},
  475. {0x00007821, 0x00000002},
  476. {0x00007800, 0000000000},
  477. {0x01200000, 0x00000002},
  478. {0x20077000, 0x00000002},
  479. {0x01200000, 0x00000002},
  480. {0x20007000, 0x00000002},
  481. {0x00061000, 0x00000002},
  482. {0x0120751b, 0x00000002},
  483. {0x8040750a, 0x00000002},
  484. {0x8040750b, 0x00000002},
  485. {0x00110000, 0x00000002},
  486. {0x000380e5, 0x00000002},
  487. {0x000000c6, 0x0000001c},
  488. {0x000610ab, 0x00000018},
  489. {0x844075bd, 0x00000002},
  490. {0x000610aa, 0x00000018},
  491. {0x840075bb, 0x00000002},
  492. {0x000610ab, 0x00000018},
  493. {0x844075bc, 0x00000002},
  494. {0x000000c9, 0x00000004},
  495. {0x804075bd, 0x00000002},
  496. {0x800075bb, 0x00000002},
  497. {0x804075bc, 0x00000002},
  498. {0x00108000, 0x00000002},
  499. {0x01400000, 0x00000002},
  500. {0x006000cd, 0x0000000c},
  501. {0x20c07000, 0x00000020},
  502. {0x000000cf, 0x00000012},
  503. {0x00800000, 0x00000006},
  504. {0x0080751d, 0x00000006},
  505. {0000000000, 0000000000},
  506. {0x0000775c, 0x00000002},
  507. {0x00a05000, 0x00000002},
  508. {0x00661000, 0x00000002},
  509. {0x0460275d, 0x00000020},
  510. {0x00004000, 0000000000},
  511. {0x01e00830, 0x00000002},
  512. {0x21007000, 0000000000},
  513. {0x6464614d, 0000000000},
  514. {0x69687420, 0000000000},
  515. {0x00000073, 0000000000},
  516. {0000000000, 0000000000},
  517. {0x00005000, 0x00000002},
  518. {0x000380d0, 0x00000002},
  519. {0x040025e0, 0x00000002},
  520. {0x000075e1, 0000000000},
  521. {0x00000001, 0000000000},
  522. {0x000380e0, 0x00000002},
  523. {0x04002394, 0x00000002},
  524. {0x00005000, 0000000000},
  525. {0000000000, 0000000000},
  526. {0000000000, 0000000000},
  527. {0x00000008, 0000000000},
  528. {0x00000004, 0000000000},
  529. {0000000000, 0000000000},
  530. {0000000000, 0000000000},
  531. {0000000000, 0000000000},
  532. {0000000000, 0000000000},
  533. {0000000000, 0000000000},
  534. {0000000000, 0000000000},
  535. {0000000000, 0000000000},
  536. {0000000000, 0000000000},
  537. {0000000000, 0000000000},
  538. {0000000000, 0000000000},
  539. {0000000000, 0000000000},
  540. {0000000000, 0000000000},
  541. {0000000000, 0000000000},
  542. {0000000000, 0000000000},
  543. {0000000000, 0000000000},
  544. {0000000000, 0000000000},
  545. {0000000000, 0000000000},
  546. {0000000000, 0000000000},
  547. {0000000000, 0000000000},
  548. {0000000000, 0000000000},
  549. {0000000000, 0000000000},
  550. {0000000000, 0000000000},
  551. {0000000000, 0000000000},
  552. {0000000000, 0000000000},
  553. };
  554. static const u32 R300_cp_microcode[][2] = {
  555. {0x4200e000, 0000000000},
  556. {0x4000e000, 0000000000},
  557. {0x000000af, 0x00000008},
  558. {0x000000b3, 0x00000008},
  559. {0x6c5a504f, 0000000000},
  560. {0x4f4f497a, 0000000000},
  561. {0x5a578288, 0000000000},
  562. {0x4f91906a, 0000000000},
  563. {0x4f4f4f4f, 0000000000},
  564. {0x4fe24f44, 0000000000},
  565. {0x4f9c9c9c, 0000000000},
  566. {0xdc4f4fde, 0000000000},
  567. {0xa1cd4f4f, 0000000000},
  568. {0xd29d9d9d, 0000000000},
  569. {0x4f0f9fd7, 0000000000},
  570. {0x000ca000, 0x00000004},
  571. {0x000d0012, 0x00000038},
  572. {0x0000e8b4, 0x00000004},
  573. {0x000d0014, 0x00000038},
  574. {0x0000e8b6, 0x00000004},
  575. {0x000d0016, 0x00000038},
  576. {0x0000e854, 0x00000004},
  577. {0x000d0018, 0x00000038},
  578. {0x0000e855, 0x00000004},
  579. {0x000d001a, 0x00000038},
  580. {0x0000e856, 0x00000004},
  581. {0x000d001c, 0x00000038},
  582. {0x0000e857, 0x00000004},
  583. {0x000d001e, 0x00000038},
  584. {0x0000e824, 0x00000004},
  585. {0x000d0020, 0x00000038},
  586. {0x0000e825, 0x00000004},
  587. {0x000d0022, 0x00000038},
  588. {0x0000e830, 0x00000004},
  589. {0x000d0024, 0x00000038},
  590. {0x0000f0c0, 0x00000004},
  591. {0x000d0026, 0x00000038},
  592. {0x0000f0c1, 0x00000004},
  593. {0x000d0028, 0x00000038},
  594. {0x0000f041, 0x00000004},
  595. {0x000d002a, 0x00000038},
  596. {0x0000f184, 0x00000004},
  597. {0x000d002c, 0x00000038},
  598. {0x0000f185, 0x00000004},
  599. {0x000d002e, 0x00000038},
  600. {0x0000f186, 0x00000004},
  601. {0x000d0030, 0x00000038},
  602. {0x0000f187, 0x00000004},
  603. {0x000d0032, 0x00000038},
  604. {0x0000f180, 0x00000004},
  605. {0x000d0034, 0x00000038},
  606. {0x0000f393, 0x00000004},
  607. {0x000d0036, 0x00000038},
  608. {0x0000f38a, 0x00000004},
  609. {0x000d0038, 0x00000038},
  610. {0x0000f38e, 0x00000004},
  611. {0x0000e821, 0x00000004},
  612. {0x0140a000, 0x00000004},
  613. {0x00000043, 0x00000018},
  614. {0x00cce800, 0x00000004},
  615. {0x001b0001, 0x00000004},
  616. {0x08004800, 0x00000004},
  617. {0x001b0001, 0x00000004},
  618. {0x08004800, 0x00000004},
  619. {0x001b0001, 0x00000004},
  620. {0x08004800, 0x00000004},
  621. {0x0000003a, 0x00000008},
  622. {0x0000a000, 0000000000},
  623. {0x02c0a000, 0x00000004},
  624. {0x000ca000, 0x00000004},
  625. {0x00130000, 0x00000004},
  626. {0x000c2000, 0x00000004},
  627. {0xc980c045, 0x00000008},
  628. {0x2000451d, 0x00000004},
  629. {0x0000e580, 0x00000004},
  630. {0x000ce581, 0x00000004},
  631. {0x08004580, 0x00000004},
  632. {0x000ce581, 0x00000004},
  633. {0x0000004c, 0x00000008},
  634. {0x0000a000, 0000000000},
  635. {0x000c2000, 0x00000004},
  636. {0x0000e50e, 0x00000004},
  637. {0x00032000, 0x00000004},
  638. {0x00022056, 0x00000028},
  639. {0x00000056, 0x00000024},
  640. {0x0800450f, 0x00000004},
  641. {0x0000a050, 0x00000008},
  642. {0x0000e565, 0x00000004},
  643. {0x0000e566, 0x00000004},
  644. {0x00000057, 0x00000008},
  645. {0x03cca5b4, 0x00000004},
  646. {0x05432000, 0x00000004},
  647. {0x00022000, 0x00000004},
  648. {0x4ccce063, 0x00000030},
  649. {0x08274565, 0x00000004},
  650. {0x00000063, 0x00000030},
  651. {0x08004564, 0x00000004},
  652. {0x0000e566, 0x00000004},
  653. {0x0000005a, 0x00000008},
  654. {0x00802066, 0x00000010},
  655. {0x00202000, 0x00000004},
  656. {0x001b00ff, 0x00000004},
  657. {0x01000069, 0x00000010},
  658. {0x001f2000, 0x00000004},
  659. {0x001c00ff, 0x00000004},
  660. {0000000000, 0x0000000c},
  661. {0x00000085, 0x00000030},
  662. {0x0000005a, 0x00000008},
  663. {0x0000e576, 0x00000004},
  664. {0x000ca000, 0x00000004},
  665. {0x00012000, 0x00000004},
  666. {0x00082000, 0x00000004},
  667. {0x1800650e, 0x00000004},
  668. {0x00092000, 0x00000004},
  669. {0x000a2000, 0x00000004},
  670. {0x000f0000, 0x00000004},
  671. {0x00400000, 0x00000004},
  672. {0x00000079, 0x00000018},
  673. {0x0000e563, 0x00000004},
  674. {0x00c0e5f9, 0x000000c2},
  675. {0x0000006e, 0x00000008},
  676. {0x0000a06e, 0x00000008},
  677. {0x0000e576, 0x00000004},
  678. {0x0000e577, 0x00000004},
  679. {0x0000e50e, 0x00000004},
  680. {0x0000e50f, 0x00000004},
  681. {0x0140a000, 0x00000004},
  682. {0x0000007c, 0x00000018},
  683. {0x00c0e5f9, 0x000000c2},
  684. {0x0000007c, 0x00000008},
  685. {0x0014e50e, 0x00000004},
  686. {0x0040e50f, 0x00000004},
  687. {0x00c0007f, 0x00000008},
  688. {0x0000e570, 0x00000004},
  689. {0x0000e571, 0x00000004},
  690. {0x0000e572, 0x0000000c},
  691. {0x0000a000, 0x00000004},
  692. {0x0140a000, 0x00000004},
  693. {0x0000e568, 0x00000004},
  694. {0x000c2000, 0x00000004},
  695. {0x00000089, 0x00000018},
  696. {0x000b0000, 0x00000004},
  697. {0x18c0e562, 0x00000004},
  698. {0x0000008b, 0x00000008},
  699. {0x00c0008a, 0x00000008},
  700. {0x000700e4, 0x00000004},
  701. {0x00000097, 0x00000038},
  702. {0x000ca099, 0x00000030},
  703. {0x080045bb, 0x00000004},
  704. {0x000c209a, 0x00000030},
  705. {0x0800e5bc, 0000000000},
  706. {0x0000e5bb, 0x00000004},
  707. {0x0000e5bc, 0000000000},
  708. {0x00120000, 0x0000000c},
  709. {0x00120000, 0x00000004},
  710. {0x001b0002, 0x0000000c},
  711. {0x0000a000, 0x00000004},
  712. {0x0000e821, 0x00000004},
  713. {0x0000e800, 0000000000},
  714. {0x0000e821, 0x00000004},
  715. {0x0000e82e, 0000000000},
  716. {0x02cca000, 0x00000004},
  717. {0x00140000, 0x00000004},
  718. {0x000ce1cc, 0x00000004},
  719. {0x050de1cd, 0x00000004},
  720. {0x000000a7, 0x00000020},
  721. {0x4200e000, 0000000000},
  722. {0x000000ae, 0x00000038},
  723. {0x000ca000, 0x00000004},
  724. {0x00140000, 0x00000004},
  725. {0x000c2000, 0x00000004},
  726. {0x00160000, 0x00000004},
  727. {0x700ce000, 0x00000004},
  728. {0x001400aa, 0x00000008},
  729. {0x4000e000, 0000000000},
  730. {0x02400000, 0x00000004},
  731. {0x400ee000, 0x00000004},
  732. {0x02400000, 0x00000004},
  733. {0x4000e000, 0000000000},
  734. {0x000c2000, 0x00000004},
  735. {0x0240e51b, 0x00000004},
  736. {0x0080e50a, 0x00000005},
  737. {0x0080e50b, 0x00000005},
  738. {0x00220000, 0x00000004},
  739. {0x000700e4, 0x00000004},
  740. {0x000000c1, 0x00000038},
  741. {0x000c209a, 0x00000030},
  742. {0x0880e5bd, 0x00000005},
  743. {0x000c2099, 0x00000030},
  744. {0x0800e5bb, 0x00000005},
  745. {0x000c209a, 0x00000030},
  746. {0x0880e5bc, 0x00000005},
  747. {0x000000c4, 0x00000008},
  748. {0x0080e5bd, 0x00000005},
  749. {0x0000e5bb, 0x00000005},
  750. {0x0080e5bc, 0x00000005},
  751. {0x00210000, 0x00000004},
  752. {0x02800000, 0x00000004},
  753. {0x00c000c8, 0x00000018},
  754. {0x4180e000, 0x00000040},
  755. {0x000000ca, 0x00000024},
  756. {0x01000000, 0x0000000c},
  757. {0x0100e51d, 0x0000000c},
  758. {0x000045bb, 0x00000004},
  759. {0x000080c4, 0x00000008},
  760. {0x0000f3ce, 0x00000004},
  761. {0x0140a000, 0x00000004},
  762. {0x00cc2000, 0x00000004},
  763. {0x08c053cf, 0x00000040},
  764. {0x00008000, 0000000000},
  765. {0x0000f3d2, 0x00000004},
  766. {0x0140a000, 0x00000004},
  767. {0x00cc2000, 0x00000004},
  768. {0x08c053d3, 0x00000040},
  769. {0x00008000, 0000000000},
  770. {0x0000f39d, 0x00000004},
  771. {0x0140a000, 0x00000004},
  772. {0x00cc2000, 0x00000004},
  773. {0x08c0539e, 0x00000040},
  774. {0x00008000, 0000000000},
  775. {0x03c00830, 0x00000004},
  776. {0x4200e000, 0000000000},
  777. {0x0000a000, 0x00000004},
  778. {0x200045e0, 0x00000004},
  779. {0x0000e5e1, 0000000000},
  780. {0x00000001, 0000000000},
  781. {0x000700e1, 0x00000004},
  782. {0x0800e394, 0000000000},
  783. {0000000000, 0000000000},
  784. {0000000000, 0000000000},
  785. {0000000000, 0000000000},
  786. {0000000000, 0000000000},
  787. {0000000000, 0000000000},
  788. {0000000000, 0000000000},
  789. {0000000000, 0000000000},
  790. {0000000000, 0000000000},
  791. {0000000000, 0000000000},
  792. {0000000000, 0000000000},
  793. {0000000000, 0000000000},
  794. {0000000000, 0000000000},
  795. {0000000000, 0000000000},
  796. {0000000000, 0000000000},
  797. {0000000000, 0000000000},
  798. {0000000000, 0000000000},
  799. {0000000000, 0000000000},
  800. {0000000000, 0000000000},
  801. {0000000000, 0000000000},
  802. {0000000000, 0000000000},
  803. {0000000000, 0000000000},
  804. {0000000000, 0000000000},
  805. {0000000000, 0000000000},
  806. {0000000000, 0000000000},
  807. {0000000000, 0000000000},
  808. {0000000000, 0000000000},
  809. {0000000000, 0000000000},
  810. {0000000000, 0000000000},
  811. };
  812. static u32 RADEON_READ_MCIND(drm_radeon_private_t *dev_priv, int addr)
  813. {
  814. u32 ret;
  815. RADEON_WRITE(R520_MC_IND_INDEX, 0x7f0000 | (addr & 0xff));
  816. ret = RADEON_READ(R520_MC_IND_DATA);
  817. RADEON_WRITE(R520_MC_IND_INDEX, 0);
  818. return ret;
  819. }
  820. u32 radeon_read_fb_location(drm_radeon_private_t *dev_priv)
  821. {
  822. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515)
  823. return RADEON_READ_MCIND(dev_priv, RV515_MC_FB_LOCATION);
  824. else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515)
  825. return RADEON_READ_MCIND(dev_priv, R520_MC_FB_LOCATION);
  826. else
  827. return RADEON_READ(RADEON_MC_FB_LOCATION);
  828. }
  829. static void radeon_write_fb_location(drm_radeon_private_t *dev_priv, u32 fb_loc)
  830. {
  831. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515)
  832. RADEON_WRITE_MCIND(RV515_MC_FB_LOCATION, fb_loc);
  833. else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515)
  834. RADEON_WRITE_MCIND(R520_MC_FB_LOCATION, fb_loc);
  835. else
  836. RADEON_WRITE(RADEON_MC_FB_LOCATION, fb_loc);
  837. }
  838. static void radeon_write_agp_location(drm_radeon_private_t *dev_priv, u32 agp_loc)
  839. {
  840. if ((dev_priv->flags & RADEON_FAMILY_MASK) == CHIP_RV515)
  841. RADEON_WRITE_MCIND(RV515_MC_AGP_LOCATION, agp_loc);
  842. else if ((dev_priv->flags & RADEON_FAMILY_MASK) > CHIP_RV515)
  843. RADEON_WRITE_MCIND(R520_MC_AGP_LOCATION, agp_loc);
  844. else
  845. RADEON_WRITE(RADEON_MC_AGP_LOCATION, agp_loc);
  846. }
  847. static int RADEON_READ_PLL(struct drm_device * dev, int addr)
  848. {
  849. drm_radeon_private_t *dev_priv = dev->dev_private;
  850. RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX, addr & 0x1f);
  851. return RADEON_READ(RADEON_CLOCK_CNTL_DATA);
  852. }
  853. static u32 RADEON_READ_PCIE(drm_radeon_private_t *dev_priv, int addr)
  854. {
  855. RADEON_WRITE8(RADEON_PCIE_INDEX, addr & 0xff);
  856. return RADEON_READ(RADEON_PCIE_DATA);
  857. }
  858. static u32 RADEON_READ_IGPGART(drm_radeon_private_t *dev_priv, int addr)
  859. {
  860. u32 ret;
  861. RADEON_WRITE(RADEON_IGPGART_INDEX, addr & 0x7f);
  862. ret = RADEON_READ(RADEON_IGPGART_DATA);
  863. RADEON_WRITE(RADEON_IGPGART_INDEX, 0x7f);
  864. return ret;
  865. }
  866. #if RADEON_FIFO_DEBUG
  867. static void radeon_status(drm_radeon_private_t * dev_priv)
  868. {
  869. printk("%s:\n", __FUNCTION__);
  870. printk("RBBM_STATUS = 0x%08x\n",
  871. (unsigned int)RADEON_READ(RADEON_RBBM_STATUS));
  872. printk("CP_RB_RTPR = 0x%08x\n",
  873. (unsigned int)RADEON_READ(RADEON_CP_RB_RPTR));
  874. printk("CP_RB_WTPR = 0x%08x\n",
  875. (unsigned int)RADEON_READ(RADEON_CP_RB_WPTR));
  876. printk("AIC_CNTL = 0x%08x\n",
  877. (unsigned int)RADEON_READ(RADEON_AIC_CNTL));
  878. printk("AIC_STAT = 0x%08x\n",
  879. (unsigned int)RADEON_READ(RADEON_AIC_STAT));
  880. printk("AIC_PT_BASE = 0x%08x\n",
  881. (unsigned int)RADEON_READ(RADEON_AIC_PT_BASE));
  882. printk("TLB_ADDR = 0x%08x\n",
  883. (unsigned int)RADEON_READ(RADEON_AIC_TLB_ADDR));
  884. printk("TLB_DATA = 0x%08x\n",
  885. (unsigned int)RADEON_READ(RADEON_AIC_TLB_DATA));
  886. }
  887. #endif
  888. /* ================================================================
  889. * Engine, FIFO control
  890. */
  891. static int radeon_do_pixcache_flush(drm_radeon_private_t * dev_priv)
  892. {
  893. u32 tmp;
  894. int i;
  895. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  896. tmp = RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT);
  897. tmp |= RADEON_RB3D_DC_FLUSH_ALL;
  898. RADEON_WRITE(RADEON_RB3D_DSTCACHE_CTLSTAT, tmp);
  899. for (i = 0; i < dev_priv->usec_timeout; i++) {
  900. if (!(RADEON_READ(RADEON_RB3D_DSTCACHE_CTLSTAT)
  901. & RADEON_RB3D_DC_BUSY)) {
  902. return 0;
  903. }
  904. DRM_UDELAY(1);
  905. }
  906. #if RADEON_FIFO_DEBUG
  907. DRM_ERROR("failed!\n");
  908. radeon_status(dev_priv);
  909. #endif
  910. return -EBUSY;
  911. }
  912. static int radeon_do_wait_for_fifo(drm_radeon_private_t * dev_priv, int entries)
  913. {
  914. int i;
  915. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  916. for (i = 0; i < dev_priv->usec_timeout; i++) {
  917. int slots = (RADEON_READ(RADEON_RBBM_STATUS)
  918. & RADEON_RBBM_FIFOCNT_MASK);
  919. if (slots >= entries)
  920. return 0;
  921. DRM_UDELAY(1);
  922. }
  923. #if RADEON_FIFO_DEBUG
  924. DRM_ERROR("failed!\n");
  925. radeon_status(dev_priv);
  926. #endif
  927. return -EBUSY;
  928. }
  929. static int radeon_do_wait_for_idle(drm_radeon_private_t * dev_priv)
  930. {
  931. int i, ret;
  932. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  933. ret = radeon_do_wait_for_fifo(dev_priv, 64);
  934. if (ret)
  935. return ret;
  936. for (i = 0; i < dev_priv->usec_timeout; i++) {
  937. if (!(RADEON_READ(RADEON_RBBM_STATUS)
  938. & RADEON_RBBM_ACTIVE)) {
  939. radeon_do_pixcache_flush(dev_priv);
  940. return 0;
  941. }
  942. DRM_UDELAY(1);
  943. }
  944. #if RADEON_FIFO_DEBUG
  945. DRM_ERROR("failed!\n");
  946. radeon_status(dev_priv);
  947. #endif
  948. return -EBUSY;
  949. }
  950. /* ================================================================
  951. * CP control, initialization
  952. */
  953. /* Load the microcode for the CP */
  954. static void radeon_cp_load_microcode(drm_radeon_private_t * dev_priv)
  955. {
  956. int i;
  957. DRM_DEBUG("\n");
  958. radeon_do_wait_for_idle(dev_priv);
  959. RADEON_WRITE(RADEON_CP_ME_RAM_ADDR, 0);
  960. if (dev_priv->microcode_version == UCODE_R200) {
  961. DRM_INFO("Loading R200 Microcode\n");
  962. for (i = 0; i < 256; i++) {
  963. RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
  964. R200_cp_microcode[i][1]);
  965. RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
  966. R200_cp_microcode[i][0]);
  967. }
  968. } else if (dev_priv->microcode_version == UCODE_R300) {
  969. DRM_INFO("Loading R300 Microcode\n");
  970. for (i = 0; i < 256; i++) {
  971. RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
  972. R300_cp_microcode[i][1]);
  973. RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
  974. R300_cp_microcode[i][0]);
  975. }
  976. } else {
  977. for (i = 0; i < 256; i++) {
  978. RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
  979. radeon_cp_microcode[i][1]);
  980. RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
  981. radeon_cp_microcode[i][0]);
  982. }
  983. }
  984. }
  985. /* Flush any pending commands to the CP. This should only be used just
  986. * prior to a wait for idle, as it informs the engine that the command
  987. * stream is ending.
  988. */
  989. static void radeon_do_cp_flush(drm_radeon_private_t * dev_priv)
  990. {
  991. DRM_DEBUG("\n");
  992. #if 0
  993. u32 tmp;
  994. tmp = RADEON_READ(RADEON_CP_RB_WPTR) | (1 << 31);
  995. RADEON_WRITE(RADEON_CP_RB_WPTR, tmp);
  996. #endif
  997. }
  998. /* Wait for the CP to go idle.
  999. */
  1000. int radeon_do_cp_idle(drm_radeon_private_t * dev_priv)
  1001. {
  1002. RING_LOCALS;
  1003. DRM_DEBUG("\n");
  1004. BEGIN_RING(6);
  1005. RADEON_PURGE_CACHE();
  1006. RADEON_PURGE_ZCACHE();
  1007. RADEON_WAIT_UNTIL_IDLE();
  1008. ADVANCE_RING();
  1009. COMMIT_RING();
  1010. return radeon_do_wait_for_idle(dev_priv);
  1011. }
  1012. /* Start the Command Processor.
  1013. */
  1014. static void radeon_do_cp_start(drm_radeon_private_t * dev_priv)
  1015. {
  1016. RING_LOCALS;
  1017. DRM_DEBUG("\n");
  1018. radeon_do_wait_for_idle(dev_priv);
  1019. RADEON_WRITE(RADEON_CP_CSQ_CNTL, dev_priv->cp_mode);
  1020. dev_priv->cp_running = 1;
  1021. BEGIN_RING(6);
  1022. RADEON_PURGE_CACHE();
  1023. RADEON_PURGE_ZCACHE();
  1024. RADEON_WAIT_UNTIL_IDLE();
  1025. ADVANCE_RING();
  1026. COMMIT_RING();
  1027. }
  1028. /* Reset the Command Processor. This will not flush any pending
  1029. * commands, so you must wait for the CP command stream to complete
  1030. * before calling this routine.
  1031. */
  1032. static void radeon_do_cp_reset(drm_radeon_private_t * dev_priv)
  1033. {
  1034. u32 cur_read_ptr;
  1035. DRM_DEBUG("\n");
  1036. cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR);
  1037. RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr);
  1038. SET_RING_HEAD(dev_priv, cur_read_ptr);
  1039. dev_priv->ring.tail = cur_read_ptr;
  1040. }
  1041. /* Stop the Command Processor. This will not flush any pending
  1042. * commands, so you must flush the command stream and wait for the CP
  1043. * to go idle before calling this routine.
  1044. */
  1045. static void radeon_do_cp_stop(drm_radeon_private_t * dev_priv)
  1046. {
  1047. DRM_DEBUG("\n");
  1048. RADEON_WRITE(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIDIS_INDDIS);
  1049. dev_priv->cp_running = 0;
  1050. }
  1051. /* Reset the engine. This will stop the CP if it is running.
  1052. */
  1053. static int radeon_do_engine_reset(struct drm_device * dev)
  1054. {
  1055. drm_radeon_private_t *dev_priv = dev->dev_private;
  1056. u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
  1057. DRM_DEBUG("\n");
  1058. radeon_do_pixcache_flush(dev_priv);
  1059. if ((dev_priv->flags & RADEON_FAMILY_MASK) < CHIP_RV515) {
  1060. clock_cntl_index = RADEON_READ(RADEON_CLOCK_CNTL_INDEX);
  1061. mclk_cntl = RADEON_READ_PLL(dev, RADEON_MCLK_CNTL);
  1062. RADEON_WRITE_PLL(RADEON_MCLK_CNTL, (mclk_cntl |
  1063. RADEON_FORCEON_MCLKA |
  1064. RADEON_FORCEON_MCLKB |
  1065. RADEON_FORCEON_YCLKA |
  1066. RADEON_FORCEON_YCLKB |
  1067. RADEON_FORCEON_MC |
  1068. RADEON_FORCEON_AIC));
  1069. rbbm_soft_reset = RADEON_READ(RADEON_RBBM_SOFT_RESET);
  1070. RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset |
  1071. RADEON_SOFT_RESET_CP |
  1072. RADEON_SOFT_RESET_HI |
  1073. RADEON_SOFT_RESET_SE |
  1074. RADEON_SOFT_RESET_RE |
  1075. RADEON_SOFT_RESET_PP |
  1076. RADEON_SOFT_RESET_E2 |
  1077. RADEON_SOFT_RESET_RB));
  1078. RADEON_READ(RADEON_RBBM_SOFT_RESET);
  1079. RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset &
  1080. ~(RADEON_SOFT_RESET_CP |
  1081. RADEON_SOFT_RESET_HI |
  1082. RADEON_SOFT_RESET_SE |
  1083. RADEON_SOFT_RESET_RE |
  1084. RADEON_SOFT_RESET_PP |
  1085. RADEON_SOFT_RESET_E2 |
  1086. RADEON_SOFT_RESET_RB)));
  1087. RADEON_READ(RADEON_RBBM_SOFT_RESET);
  1088. RADEON_WRITE_PLL(RADEON_MCLK_CNTL, mclk_cntl);
  1089. RADEON_WRITE(RADEON_CLOCK_CNTL_INDEX, clock_cntl_index);
  1090. RADEON_WRITE(RADEON_RBBM_SOFT_RESET, rbbm_soft_reset);
  1091. }
  1092. /* Reset the CP ring */
  1093. radeon_do_cp_reset(dev_priv);
  1094. /* The CP is no longer running after an engine reset */
  1095. dev_priv->cp_running = 0;
  1096. /* Reset any pending vertex, indirect buffers */
  1097. radeon_freelist_reset(dev);
  1098. return 0;
  1099. }
  1100. static void radeon_cp_init_ring_buffer(struct drm_device * dev,
  1101. drm_radeon_private_t * dev_priv)
  1102. {
  1103. u32 ring_start, cur_read_ptr;
  1104. u32 tmp;
  1105. /* Initialize the memory controller. With new memory map, the fb location
  1106. * is not changed, it should have been properly initialized already. Part
  1107. * of the problem is that the code below is bogus, assuming the GART is
  1108. * always appended to the fb which is not necessarily the case
  1109. */
  1110. if (!dev_priv->new_memmap)
  1111. radeon_write_fb_location(dev_priv,
  1112. ((dev_priv->gart_vm_start - 1) & 0xffff0000)
  1113. | (dev_priv->fb_location >> 16));
  1114. #if __OS_HAS_AGP
  1115. if (dev_priv->flags & RADEON_IS_AGP) {
  1116. RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev->agp->base);
  1117. radeon_write_agp_location(dev_priv,
  1118. (((dev_priv->gart_vm_start - 1 +
  1119. dev_priv->gart_size) & 0xffff0000) |
  1120. (dev_priv->gart_vm_start >> 16)));
  1121. ring_start = (dev_priv->cp_ring->offset
  1122. - dev->agp->base
  1123. + dev_priv->gart_vm_start);
  1124. } else
  1125. #endif
  1126. ring_start = (dev_priv->cp_ring->offset
  1127. - (unsigned long)dev->sg->virtual
  1128. + dev_priv->gart_vm_start);
  1129. RADEON_WRITE(RADEON_CP_RB_BASE, ring_start);
  1130. /* Set the write pointer delay */
  1131. RADEON_WRITE(RADEON_CP_RB_WPTR_DELAY, 0);
  1132. /* Initialize the ring buffer's read and write pointers */
  1133. cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR);
  1134. RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr);
  1135. SET_RING_HEAD(dev_priv, cur_read_ptr);
  1136. dev_priv->ring.tail = cur_read_ptr;
  1137. #if __OS_HAS_AGP
  1138. if (dev_priv->flags & RADEON_IS_AGP) {
  1139. RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR,
  1140. dev_priv->ring_rptr->offset
  1141. - dev->agp->base + dev_priv->gart_vm_start);
  1142. } else
  1143. #endif
  1144. {
  1145. struct drm_sg_mem *entry = dev->sg;
  1146. unsigned long tmp_ofs, page_ofs;
  1147. tmp_ofs = dev_priv->ring_rptr->offset -
  1148. (unsigned long)dev->sg->virtual;
  1149. page_ofs = tmp_ofs >> PAGE_SHIFT;
  1150. RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, entry->busaddr[page_ofs]);
  1151. DRM_DEBUG("ring rptr: offset=0x%08lx handle=0x%08lx\n",
  1152. (unsigned long)entry->busaddr[page_ofs],
  1153. entry->handle + tmp_ofs);
  1154. }
  1155. /* Set ring buffer size */
  1156. #ifdef __BIG_ENDIAN
  1157. RADEON_WRITE(RADEON_CP_RB_CNTL,
  1158. RADEON_BUF_SWAP_32BIT |
  1159. (dev_priv->ring.fetch_size_l2ow << 18) |
  1160. (dev_priv->ring.rptr_update_l2qw << 8) |
  1161. dev_priv->ring.size_l2qw);
  1162. #else
  1163. RADEON_WRITE(RADEON_CP_RB_CNTL,
  1164. (dev_priv->ring.fetch_size_l2ow << 18) |
  1165. (dev_priv->ring.rptr_update_l2qw << 8) |
  1166. dev_priv->ring.size_l2qw);
  1167. #endif
  1168. /* Start with assuming that writeback doesn't work */
  1169. dev_priv->writeback_works = 0;
  1170. /* Initialize the scratch register pointer. This will cause
  1171. * the scratch register values to be written out to memory
  1172. * whenever they are updated.
  1173. *
  1174. * We simply put this behind the ring read pointer, this works
  1175. * with PCI GART as well as (whatever kind of) AGP GART
  1176. */
  1177. RADEON_WRITE(RADEON_SCRATCH_ADDR, RADEON_READ(RADEON_CP_RB_RPTR_ADDR)
  1178. + RADEON_SCRATCH_REG_OFFSET);
  1179. dev_priv->scratch = ((__volatile__ u32 *)
  1180. dev_priv->ring_rptr->handle +
  1181. (RADEON_SCRATCH_REG_OFFSET / sizeof(u32)));
  1182. RADEON_WRITE(RADEON_SCRATCH_UMSK, 0x7);
  1183. /* Turn on bus mastering */
  1184. tmp = RADEON_READ(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS;
  1185. RADEON_WRITE(RADEON_BUS_CNTL, tmp);
  1186. dev_priv->sarea_priv->last_frame = dev_priv->scratch[0] = 0;
  1187. RADEON_WRITE(RADEON_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame);
  1188. dev_priv->sarea_priv->last_dispatch = dev_priv->scratch[1] = 0;
  1189. RADEON_WRITE(RADEON_LAST_DISPATCH_REG,
  1190. dev_priv->sarea_priv->last_dispatch);
  1191. dev_priv->sarea_priv->last_clear = dev_priv->scratch[2] = 0;
  1192. RADEON_WRITE(RADEON_LAST_CLEAR_REG, dev_priv->sarea_priv->last_clear);
  1193. radeon_do_wait_for_idle(dev_priv);
  1194. /* Sync everything up */
  1195. RADEON_WRITE(RADEON_ISYNC_CNTL,
  1196. (RADEON_ISYNC_ANY2D_IDLE3D |
  1197. RADEON_ISYNC_ANY3D_IDLE2D |
  1198. RADEON_ISYNC_WAIT_IDLEGUI |
  1199. RADEON_ISYNC_CPSCRATCH_IDLEGUI));
  1200. }
  1201. static void radeon_test_writeback(drm_radeon_private_t * dev_priv)
  1202. {
  1203. u32 tmp;
  1204. /* Writeback doesn't seem to work everywhere, test it here and possibly
  1205. * enable it if it appears to work
  1206. */
  1207. DRM_WRITE32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1), 0);
  1208. RADEON_WRITE(RADEON_SCRATCH_REG1, 0xdeadbeef);
  1209. for (tmp = 0; tmp < dev_priv->usec_timeout; tmp++) {
  1210. if (DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1)) ==
  1211. 0xdeadbeef)
  1212. break;
  1213. DRM_UDELAY(1);
  1214. }
  1215. if (tmp < dev_priv->usec_timeout) {
  1216. dev_priv->writeback_works = 1;
  1217. DRM_INFO("writeback test succeeded in %d usecs\n", tmp);
  1218. } else {
  1219. dev_priv->writeback_works = 0;
  1220. DRM_INFO("writeback test failed\n");
  1221. }
  1222. if (radeon_no_wb == 1) {
  1223. dev_priv->writeback_works = 0;
  1224. DRM_INFO("writeback forced off\n");
  1225. }
  1226. if (!dev_priv->writeback_works) {
  1227. /* Disable writeback to avoid unnecessary bus master transfer */
  1228. RADEON_WRITE(RADEON_CP_RB_CNTL, RADEON_READ(RADEON_CP_RB_CNTL) |
  1229. RADEON_RB_NO_UPDATE);
  1230. RADEON_WRITE(RADEON_SCRATCH_UMSK, 0);
  1231. }
  1232. }
  1233. /* Enable or disable IGP GART on the chip */
  1234. static void radeon_set_igpgart(drm_radeon_private_t * dev_priv, int on)
  1235. {
  1236. u32 temp, tmp;
  1237. tmp = RADEON_READ(RADEON_AIC_CNTL);
  1238. if (on) {
  1239. DRM_DEBUG("programming igpgart %08X %08lX %08X\n",
  1240. dev_priv->gart_vm_start,
  1241. (long)dev_priv->gart_info.bus_addr,
  1242. dev_priv->gart_size);
  1243. RADEON_WRITE_IGPGART(RADEON_IGPGART_UNK_18, 0x1000);
  1244. RADEON_WRITE_IGPGART(RADEON_IGPGART_ENABLE, 0x1);
  1245. RADEON_WRITE_IGPGART(RADEON_IGPGART_CTRL, 0x42040800);
  1246. RADEON_WRITE_IGPGART(RADEON_IGPGART_BASE_ADDR,
  1247. dev_priv->gart_info.bus_addr);
  1248. temp = RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_UNK_39);
  1249. RADEON_WRITE_IGPGART(RADEON_IGPGART_UNK_39, temp);
  1250. RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev_priv->gart_vm_start);
  1251. dev_priv->gart_size = 32*1024*1024;
  1252. radeon_write_agp_location(dev_priv,
  1253. (((dev_priv->gart_vm_start - 1 +
  1254. dev_priv->gart_size) & 0xffff0000) |
  1255. (dev_priv->gart_vm_start >> 16)));
  1256. temp = RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_ENABLE);
  1257. RADEON_WRITE_IGPGART(RADEON_IGPGART_ENABLE, temp);
  1258. RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_FLUSH);
  1259. RADEON_WRITE_IGPGART(RADEON_IGPGART_FLUSH, 0x1);
  1260. RADEON_READ_IGPGART(dev_priv, RADEON_IGPGART_FLUSH);
  1261. RADEON_WRITE_IGPGART(RADEON_IGPGART_FLUSH, 0x0);
  1262. }
  1263. }
  1264. static void radeon_set_pciegart(drm_radeon_private_t * dev_priv, int on)
  1265. {
  1266. u32 tmp = RADEON_READ_PCIE(dev_priv, RADEON_PCIE_TX_GART_CNTL);
  1267. if (on) {
  1268. DRM_DEBUG("programming pcie %08X %08lX %08X\n",
  1269. dev_priv->gart_vm_start,
  1270. (long)dev_priv->gart_info.bus_addr,
  1271. dev_priv->gart_size);
  1272. RADEON_WRITE_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO,
  1273. dev_priv->gart_vm_start);
  1274. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_BASE,
  1275. dev_priv->gart_info.bus_addr);
  1276. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_START_LO,
  1277. dev_priv->gart_vm_start);
  1278. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_END_LO,
  1279. dev_priv->gart_vm_start +
  1280. dev_priv->gart_size - 1);
  1281. radeon_write_agp_location(dev_priv, 0xffffffc0); /* ?? */
  1282. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL,
  1283. RADEON_PCIE_TX_GART_EN);
  1284. } else {
  1285. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL,
  1286. tmp & ~RADEON_PCIE_TX_GART_EN);
  1287. }
  1288. }
  1289. /* Enable or disable PCI GART on the chip */
  1290. static void radeon_set_pcigart(drm_radeon_private_t * dev_priv, int on)
  1291. {
  1292. u32 tmp;
  1293. if (dev_priv->flags & RADEON_IS_IGPGART) {
  1294. radeon_set_igpgart(dev_priv, on);
  1295. return;
  1296. }
  1297. if (dev_priv->flags & RADEON_IS_PCIE) {
  1298. radeon_set_pciegart(dev_priv, on);
  1299. return;
  1300. }
  1301. tmp = RADEON_READ(RADEON_AIC_CNTL);
  1302. if (on) {
  1303. RADEON_WRITE(RADEON_AIC_CNTL,
  1304. tmp | RADEON_PCIGART_TRANSLATE_EN);
  1305. /* set PCI GART page-table base address
  1306. */
  1307. RADEON_WRITE(RADEON_AIC_PT_BASE, dev_priv->gart_info.bus_addr);
  1308. /* set address range for PCI address translate
  1309. */
  1310. RADEON_WRITE(RADEON_AIC_LO_ADDR, dev_priv->gart_vm_start);
  1311. RADEON_WRITE(RADEON_AIC_HI_ADDR, dev_priv->gart_vm_start
  1312. + dev_priv->gart_size - 1);
  1313. /* Turn off AGP aperture -- is this required for PCI GART?
  1314. */
  1315. radeon_write_agp_location(dev_priv, 0xffffffc0);
  1316. RADEON_WRITE(RADEON_AGP_COMMAND, 0); /* clear AGP_COMMAND */
  1317. } else {
  1318. RADEON_WRITE(RADEON_AIC_CNTL,
  1319. tmp & ~RADEON_PCIGART_TRANSLATE_EN);
  1320. }
  1321. }
  1322. static int radeon_do_init_cp(struct drm_device * dev, drm_radeon_init_t * init)
  1323. {
  1324. drm_radeon_private_t *dev_priv = dev->dev_private;
  1325. DRM_DEBUG("\n");
  1326. /* if we require new memory map but we don't have it fail */
  1327. if ((dev_priv->flags & RADEON_NEW_MEMMAP) && !dev_priv->new_memmap) {
  1328. DRM_ERROR("Cannot initialise DRM on this card\nThis card requires a new X.org DDX for 3D\n");
  1329. radeon_do_cleanup_cp(dev);
  1330. return -EINVAL;
  1331. }
  1332. if (init->is_pci && (dev_priv->flags & RADEON_IS_AGP)) {
  1333. DRM_DEBUG("Forcing AGP card to PCI mode\n");
  1334. dev_priv->flags &= ~RADEON_IS_AGP;
  1335. } else if (!(dev_priv->flags & (RADEON_IS_AGP | RADEON_IS_PCI | RADEON_IS_PCIE))
  1336. && !init->is_pci) {
  1337. DRM_DEBUG("Restoring AGP flag\n");
  1338. dev_priv->flags |= RADEON_IS_AGP;
  1339. }
  1340. if ((!(dev_priv->flags & RADEON_IS_AGP)) && !dev->sg) {
  1341. DRM_ERROR("PCI GART memory not allocated!\n");
  1342. radeon_do_cleanup_cp(dev);
  1343. return -EINVAL;
  1344. }
  1345. dev_priv->usec_timeout = init->usec_timeout;
  1346. if (dev_priv->usec_timeout < 1 ||
  1347. dev_priv->usec_timeout > RADEON_MAX_USEC_TIMEOUT) {
  1348. DRM_DEBUG("TIMEOUT problem!\n");
  1349. radeon_do_cleanup_cp(dev);
  1350. return -EINVAL;
  1351. }
  1352. /* Enable vblank on CRTC1 for older X servers
  1353. */
  1354. dev_priv->vblank_crtc = DRM_RADEON_VBLANK_CRTC1;
  1355. switch(init->func) {
  1356. case RADEON_INIT_R200_CP:
  1357. dev_priv->microcode_version = UCODE_R200;
  1358. break;
  1359. case RADEON_INIT_R300_CP:
  1360. dev_priv->microcode_version = UCODE_R300;
  1361. break;
  1362. default:
  1363. dev_priv->microcode_version = UCODE_R100;
  1364. }
  1365. dev_priv->do_boxes = 0;
  1366. dev_priv->cp_mode = init->cp_mode;
  1367. /* We don't support anything other than bus-mastering ring mode,
  1368. * but the ring can be in either AGP or PCI space for the ring
  1369. * read pointer.
  1370. */
  1371. if ((init->cp_mode != RADEON_CSQ_PRIBM_INDDIS) &&
  1372. (init->cp_mode != RADEON_CSQ_PRIBM_INDBM)) {
  1373. DRM_DEBUG("BAD cp_mode (%x)!\n", init->cp_mode);
  1374. radeon_do_cleanup_cp(dev);
  1375. return -EINVAL;
  1376. }
  1377. switch (init->fb_bpp) {
  1378. case 16:
  1379. dev_priv->color_fmt = RADEON_COLOR_FORMAT_RGB565;
  1380. break;
  1381. case 32:
  1382. default:
  1383. dev_priv->color_fmt = RADEON_COLOR_FORMAT_ARGB8888;
  1384. break;
  1385. }
  1386. dev_priv->front_offset = init->front_offset;
  1387. dev_priv->front_pitch = init->front_pitch;
  1388. dev_priv->back_offset = init->back_offset;
  1389. dev_priv->back_pitch = init->back_pitch;
  1390. switch (init->depth_bpp) {
  1391. case 16:
  1392. dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
  1393. break;
  1394. case 32:
  1395. default:
  1396. dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
  1397. break;
  1398. }
  1399. dev_priv->depth_offset = init->depth_offset;
  1400. dev_priv->depth_pitch = init->depth_pitch;
  1401. /* Hardware state for depth clears. Remove this if/when we no
  1402. * longer clear the depth buffer with a 3D rectangle. Hard-code
  1403. * all values to prevent unwanted 3D state from slipping through
  1404. * and screwing with the clear operation.
  1405. */
  1406. dev_priv->depth_clear.rb3d_cntl = (RADEON_PLANE_MASK_ENABLE |
  1407. (dev_priv->color_fmt << 10) |
  1408. (dev_priv->microcode_version ==
  1409. UCODE_R100 ? RADEON_ZBLOCK16 : 0));
  1410. dev_priv->depth_clear.rb3d_zstencilcntl =
  1411. (dev_priv->depth_fmt |
  1412. RADEON_Z_TEST_ALWAYS |
  1413. RADEON_STENCIL_TEST_ALWAYS |
  1414. RADEON_STENCIL_S_FAIL_REPLACE |
  1415. RADEON_STENCIL_ZPASS_REPLACE |
  1416. RADEON_STENCIL_ZFAIL_REPLACE | RADEON_Z_WRITE_ENABLE);
  1417. dev_priv->depth_clear.se_cntl = (RADEON_FFACE_CULL_CW |
  1418. RADEON_BFACE_SOLID |
  1419. RADEON_FFACE_SOLID |
  1420. RADEON_FLAT_SHADE_VTX_LAST |
  1421. RADEON_DIFFUSE_SHADE_FLAT |
  1422. RADEON_ALPHA_SHADE_FLAT |
  1423. RADEON_SPECULAR_SHADE_FLAT |
  1424. RADEON_FOG_SHADE_FLAT |
  1425. RADEON_VTX_PIX_CENTER_OGL |
  1426. RADEON_ROUND_MODE_TRUNC |
  1427. RADEON_ROUND_PREC_8TH_PIX);
  1428. dev_priv->ring_offset = init->ring_offset;
  1429. dev_priv->ring_rptr_offset = init->ring_rptr_offset;
  1430. dev_priv->buffers_offset = init->buffers_offset;
  1431. dev_priv->gart_textures_offset = init->gart_textures_offset;
  1432. dev_priv->sarea = drm_getsarea(dev);
  1433. if (!dev_priv->sarea) {
  1434. DRM_ERROR("could not find sarea!\n");
  1435. radeon_do_cleanup_cp(dev);
  1436. return -EINVAL;
  1437. }
  1438. dev_priv->cp_ring = drm_core_findmap(dev, init->ring_offset);
  1439. if (!dev_priv->cp_ring) {
  1440. DRM_ERROR("could not find cp ring region!\n");
  1441. radeon_do_cleanup_cp(dev);
  1442. return -EINVAL;
  1443. }
  1444. dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset);
  1445. if (!dev_priv->ring_rptr) {
  1446. DRM_ERROR("could not find ring read pointer!\n");
  1447. radeon_do_cleanup_cp(dev);
  1448. return -EINVAL;
  1449. }
  1450. dev->agp_buffer_token = init->buffers_offset;
  1451. dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
  1452. if (!dev->agp_buffer_map) {
  1453. DRM_ERROR("could not find dma buffer region!\n");
  1454. radeon_do_cleanup_cp(dev);
  1455. return -EINVAL;
  1456. }
  1457. if (init->gart_textures_offset) {
  1458. dev_priv->gart_textures =
  1459. drm_core_findmap(dev, init->gart_textures_offset);
  1460. if (!dev_priv->gart_textures) {
  1461. DRM_ERROR("could not find GART texture region!\n");
  1462. radeon_do_cleanup_cp(dev);
  1463. return -EINVAL;
  1464. }
  1465. }
  1466. dev_priv->sarea_priv =
  1467. (drm_radeon_sarea_t *) ((u8 *) dev_priv->sarea->handle +
  1468. init->sarea_priv_offset);
  1469. #if __OS_HAS_AGP
  1470. if (dev_priv->flags & RADEON_IS_AGP) {
  1471. drm_core_ioremap(dev_priv->cp_ring, dev);
  1472. drm_core_ioremap(dev_priv->ring_rptr, dev);
  1473. drm_core_ioremap(dev->agp_buffer_map, dev);
  1474. if (!dev_priv->cp_ring->handle ||
  1475. !dev_priv->ring_rptr->handle ||
  1476. !dev->agp_buffer_map->handle) {
  1477. DRM_ERROR("could not find ioremap agp regions!\n");
  1478. radeon_do_cleanup_cp(dev);
  1479. return -EINVAL;
  1480. }
  1481. } else
  1482. #endif
  1483. {
  1484. dev_priv->cp_ring->handle = (void *)dev_priv->cp_ring->offset;
  1485. dev_priv->ring_rptr->handle =
  1486. (void *)dev_priv->ring_rptr->offset;
  1487. dev->agp_buffer_map->handle =
  1488. (void *)dev->agp_buffer_map->offset;
  1489. DRM_DEBUG("dev_priv->cp_ring->handle %p\n",
  1490. dev_priv->cp_ring->handle);
  1491. DRM_DEBUG("dev_priv->ring_rptr->handle %p\n",
  1492. dev_priv->ring_rptr->handle);
  1493. DRM_DEBUG("dev->agp_buffer_map->handle %p\n",
  1494. dev->agp_buffer_map->handle);
  1495. }
  1496. dev_priv->fb_location = (radeon_read_fb_location(dev_priv) & 0xffff) << 16;
  1497. dev_priv->fb_size =
  1498. ((radeon_read_fb_location(dev_priv) & 0xffff0000u) + 0x10000)
  1499. - dev_priv->fb_location;
  1500. dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) |
  1501. ((dev_priv->front_offset
  1502. + dev_priv->fb_location) >> 10));
  1503. dev_priv->back_pitch_offset = (((dev_priv->back_pitch / 64) << 22) |
  1504. ((dev_priv->back_offset
  1505. + dev_priv->fb_location) >> 10));
  1506. dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch / 64) << 22) |
  1507. ((dev_priv->depth_offset
  1508. + dev_priv->fb_location) >> 10));
  1509. dev_priv->gart_size = init->gart_size;
  1510. /* New let's set the memory map ... */
  1511. if (dev_priv->new_memmap) {
  1512. u32 base = 0;
  1513. DRM_INFO("Setting GART location based on new memory map\n");
  1514. /* If using AGP, try to locate the AGP aperture at the same
  1515. * location in the card and on the bus, though we have to
  1516. * align it down.
  1517. */
  1518. #if __OS_HAS_AGP
  1519. if (dev_priv->flags & RADEON_IS_AGP) {
  1520. base = dev->agp->base;
  1521. /* Check if valid */
  1522. if ((base + dev_priv->gart_size - 1) >= dev_priv->fb_location &&
  1523. base < (dev_priv->fb_location + dev_priv->fb_size - 1)) {
  1524. DRM_INFO("Can't use AGP base @0x%08lx, won't fit\n",
  1525. dev->agp->base);
  1526. base = 0;
  1527. }
  1528. }
  1529. #endif
  1530. /* If not or if AGP is at 0 (Macs), try to put it elsewhere */
  1531. if (base == 0) {
  1532. base = dev_priv->fb_location + dev_priv->fb_size;
  1533. if (base < dev_priv->fb_location ||
  1534. ((base + dev_priv->gart_size) & 0xfffffffful) < base)
  1535. base = dev_priv->fb_location
  1536. - dev_priv->gart_size;
  1537. }
  1538. dev_priv->gart_vm_start = base & 0xffc00000u;
  1539. if (dev_priv->gart_vm_start != base)
  1540. DRM_INFO("GART aligned down from 0x%08x to 0x%08x\n",
  1541. base, dev_priv->gart_vm_start);
  1542. } else {
  1543. DRM_INFO("Setting GART location based on old memory map\n");
  1544. dev_priv->gart_vm_start = dev_priv->fb_location +
  1545. RADEON_READ(RADEON_CONFIG_APER_SIZE);
  1546. }
  1547. #if __OS_HAS_AGP
  1548. if (dev_priv->flags & RADEON_IS_AGP)
  1549. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1550. - dev->agp->base
  1551. + dev_priv->gart_vm_start);
  1552. else
  1553. #endif
  1554. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1555. - (unsigned long)dev->sg->virtual
  1556. + dev_priv->gart_vm_start);
  1557. DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv->gart_size);
  1558. DRM_DEBUG("dev_priv->gart_vm_start 0x%x\n", dev_priv->gart_vm_start);
  1559. DRM_DEBUG("dev_priv->gart_buffers_offset 0x%lx\n",
  1560. dev_priv->gart_buffers_offset);
  1561. dev_priv->ring.start = (u32 *) dev_priv->cp_ring->handle;
  1562. dev_priv->ring.end = ((u32 *) dev_priv->cp_ring->handle
  1563. + init->ring_size / sizeof(u32));
  1564. dev_priv->ring.size = init->ring_size;
  1565. dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8);
  1566. dev_priv->ring.rptr_update = /* init->rptr_update */ 4096;
  1567. dev_priv->ring.rptr_update_l2qw = drm_order( /* init->rptr_update */ 4096 / 8);
  1568. dev_priv->ring.fetch_size = /* init->fetch_size */ 32;
  1569. dev_priv->ring.fetch_size_l2ow = drm_order( /* init->fetch_size */ 32 / 16);
  1570. dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;
  1571. dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK;
  1572. #if __OS_HAS_AGP
  1573. if (dev_priv->flags & RADEON_IS_AGP) {
  1574. /* Turn off PCI GART */
  1575. radeon_set_pcigart(dev_priv, 0);
  1576. } else
  1577. #endif
  1578. {
  1579. /* if we have an offset set from userspace */
  1580. if (dev_priv->pcigart_offset_set) {
  1581. dev_priv->gart_info.bus_addr =
  1582. dev_priv->pcigart_offset + dev_priv->fb_location;
  1583. dev_priv->gart_info.mapping.offset =
  1584. dev_priv->pcigart_offset + dev_priv->fb_aper_offset;
  1585. dev_priv->gart_info.mapping.size =
  1586. dev_priv->gart_info.table_size;
  1587. drm_core_ioremap(&dev_priv->gart_info.mapping, dev);
  1588. dev_priv->gart_info.addr =
  1589. dev_priv->gart_info.mapping.handle;
  1590. if (dev_priv->flags & RADEON_IS_PCIE)
  1591. dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCIE;
  1592. else
  1593. dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
  1594. dev_priv->gart_info.gart_table_location =
  1595. DRM_ATI_GART_FB;
  1596. DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n",
  1597. dev_priv->gart_info.addr,
  1598. dev_priv->pcigart_offset);
  1599. } else {
  1600. if (dev_priv->flags & RADEON_IS_IGPGART)
  1601. dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_IGP;
  1602. else
  1603. dev_priv->gart_info.gart_reg_if = DRM_ATI_GART_PCI;
  1604. dev_priv->gart_info.gart_table_location =
  1605. DRM_ATI_GART_MAIN;
  1606. dev_priv->gart_info.addr = NULL;
  1607. dev_priv->gart_info.bus_addr = 0;
  1608. if (dev_priv->flags & RADEON_IS_PCIE) {
  1609. DRM_ERROR
  1610. ("Cannot use PCI Express without GART in FB memory\n");
  1611. radeon_do_cleanup_cp(dev);
  1612. return -EINVAL;
  1613. }
  1614. }
  1615. if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) {
  1616. DRM_ERROR("failed to init PCI GART!\n");
  1617. radeon_do_cleanup_cp(dev);
  1618. return -ENOMEM;
  1619. }
  1620. /* Turn on PCI GART */
  1621. radeon_set_pcigart(dev_priv, 1);
  1622. }
  1623. radeon_cp_load_microcode(dev_priv);
  1624. radeon_cp_init_ring_buffer(dev, dev_priv);
  1625. dev_priv->last_buf = 0;
  1626. radeon_do_engine_reset(dev);
  1627. radeon_test_writeback(dev_priv);
  1628. return 0;
  1629. }
  1630. static int radeon_do_cleanup_cp(struct drm_device * dev)
  1631. {
  1632. drm_radeon_private_t *dev_priv = dev->dev_private;
  1633. DRM_DEBUG("\n");
  1634. /* Make sure interrupts are disabled here because the uninstall ioctl
  1635. * may not have been called from userspace and after dev_private
  1636. * is freed, it's too late.
  1637. */
  1638. if (dev->irq_enabled)
  1639. drm_irq_uninstall(dev);
  1640. #if __OS_HAS_AGP
  1641. if (dev_priv->flags & RADEON_IS_AGP) {
  1642. if (dev_priv->cp_ring != NULL) {
  1643. drm_core_ioremapfree(dev_priv->cp_ring, dev);
  1644. dev_priv->cp_ring = NULL;
  1645. }
  1646. if (dev_priv->ring_rptr != NULL) {
  1647. drm_core_ioremapfree(dev_priv->ring_rptr, dev);
  1648. dev_priv->ring_rptr = NULL;
  1649. }
  1650. if (dev->agp_buffer_map != NULL) {
  1651. drm_core_ioremapfree(dev->agp_buffer_map, dev);
  1652. dev->agp_buffer_map = NULL;
  1653. }
  1654. } else
  1655. #endif
  1656. {
  1657. if (dev_priv->gart_info.bus_addr) {
  1658. /* Turn off PCI GART */
  1659. radeon_set_pcigart(dev_priv, 0);
  1660. if (!drm_ati_pcigart_cleanup(dev, &dev_priv->gart_info))
  1661. DRM_ERROR("failed to cleanup PCI GART!\n");
  1662. }
  1663. if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB)
  1664. {
  1665. drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev);
  1666. dev_priv->gart_info.addr = 0;
  1667. }
  1668. }
  1669. /* only clear to the start of flags */
  1670. memset(dev_priv, 0, offsetof(drm_radeon_private_t, flags));
  1671. return 0;
  1672. }
  1673. /* This code will reinit the Radeon CP hardware after a resume from disc.
  1674. * AFAIK, it would be very difficult to pickle the state at suspend time, so
  1675. * here we make sure that all Radeon hardware initialisation is re-done without
  1676. * affecting running applications.
  1677. *
  1678. * Charl P. Botha <http://cpbotha.net>
  1679. */
  1680. static int radeon_do_resume_cp(struct drm_device * dev)
  1681. {
  1682. drm_radeon_private_t *dev_priv = dev->dev_private;
  1683. if (!dev_priv) {
  1684. DRM_ERROR("Called with no initialization\n");
  1685. return -EINVAL;
  1686. }
  1687. DRM_DEBUG("Starting radeon_do_resume_cp()\n");
  1688. #if __OS_HAS_AGP
  1689. if (dev_priv->flags & RADEON_IS_AGP) {
  1690. /* Turn off PCI GART */
  1691. radeon_set_pcigart(dev_priv, 0);
  1692. } else
  1693. #endif
  1694. {
  1695. /* Turn on PCI GART */
  1696. radeon_set_pcigart(dev_priv, 1);
  1697. }
  1698. radeon_cp_load_microcode(dev_priv);
  1699. radeon_cp_init_ring_buffer(dev, dev_priv);
  1700. radeon_do_engine_reset(dev);
  1701. DRM_DEBUG("radeon_do_resume_cp() complete\n");
  1702. return 0;
  1703. }
  1704. int radeon_cp_init(struct drm_device *dev, void *data, struct drm_file *file_priv)
  1705. {
  1706. drm_radeon_init_t *init = data;
  1707. LOCK_TEST_WITH_RETURN(dev, file_priv);
  1708. if (init->func == RADEON_INIT_R300_CP)
  1709. r300_init_reg_flags(dev);
  1710. switch (init->func) {
  1711. case RADEON_INIT_CP:
  1712. case RADEON_INIT_R200_CP:
  1713. case RADEON_INIT_R300_CP:
  1714. return radeon_do_init_cp(dev, init);
  1715. case RADEON_CLEANUP_CP:
  1716. return radeon_do_cleanup_cp(dev);
  1717. }
  1718. return -EINVAL;
  1719. }
  1720. int radeon_cp_start(struct drm_device *dev, void *data, struct drm_file *file_priv)
  1721. {
  1722. drm_radeon_private_t *dev_priv = dev->dev_private;
  1723. DRM_DEBUG("\n");
  1724. LOCK_TEST_WITH_RETURN(dev, file_priv);
  1725. if (dev_priv->cp_running) {
  1726. DRM_DEBUG("while CP running\n");
  1727. return 0;
  1728. }
  1729. if (dev_priv->cp_mode == RADEON_CSQ_PRIDIS_INDDIS) {
  1730. DRM_DEBUG("called with bogus CP mode (%d)\n",
  1731. dev_priv->cp_mode);
  1732. return 0;
  1733. }
  1734. radeon_do_cp_start(dev_priv);
  1735. return 0;
  1736. }
  1737. /* Stop the CP. The engine must have been idled before calling this
  1738. * routine.
  1739. */
  1740. int radeon_cp_stop(struct drm_device *dev, void *data, struct drm_file *file_priv)
  1741. {
  1742. drm_radeon_private_t *dev_priv = dev->dev_private;
  1743. drm_radeon_cp_stop_t *stop = data;
  1744. int ret;
  1745. DRM_DEBUG("\n");
  1746. LOCK_TEST_WITH_RETURN(dev, file_priv);
  1747. if (!dev_priv->cp_running)
  1748. return 0;
  1749. /* Flush any pending CP commands. This ensures any outstanding
  1750. * commands are exectuted by the engine before we turn it off.
  1751. */
  1752. if (stop->flush) {
  1753. radeon_do_cp_flush(dev_priv);
  1754. }
  1755. /* If we fail to make the engine go idle, we return an error
  1756. * code so that the DRM ioctl wrapper can try again.
  1757. */
  1758. if (stop->idle) {
  1759. ret = radeon_do_cp_idle(dev_priv);
  1760. if (ret)
  1761. return ret;
  1762. }
  1763. /* Finally, we can turn off the CP. If the engine isn't idle,
  1764. * we will get some dropped triangles as they won't be fully
  1765. * rendered before the CP is shut down.
  1766. */
  1767. radeon_do_cp_stop(dev_priv);
  1768. /* Reset the engine */
  1769. radeon_do_engine_reset(dev);
  1770. return 0;
  1771. }
  1772. void radeon_do_release(struct drm_device * dev)
  1773. {
  1774. drm_radeon_private_t *dev_priv = dev->dev_private;
  1775. int i, ret;
  1776. if (dev_priv) {
  1777. if (dev_priv->cp_running) {
  1778. /* Stop the cp */
  1779. while ((ret = radeon_do_cp_idle(dev_priv)) != 0) {
  1780. DRM_DEBUG("radeon_do_cp_idle %d\n", ret);
  1781. #ifdef __linux__
  1782. schedule();
  1783. #else
  1784. tsleep(&ret, PZERO, "rdnrel", 1);
  1785. #endif
  1786. }
  1787. radeon_do_cp_stop(dev_priv);
  1788. radeon_do_engine_reset(dev);
  1789. }
  1790. /* Disable *all* interrupts */
  1791. if (dev_priv->mmio) /* remove this after permanent addmaps */
  1792. RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
  1793. if (dev_priv->mmio) { /* remove all surfaces */
  1794. for (i = 0; i < RADEON_MAX_SURFACES; i++) {
  1795. RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * i, 0);
  1796. RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND +
  1797. 16 * i, 0);
  1798. RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND +
  1799. 16 * i, 0);
  1800. }
  1801. }
  1802. /* Free memory heap structures */
  1803. radeon_mem_takedown(&(dev_priv->gart_heap));
  1804. radeon_mem_takedown(&(dev_priv->fb_heap));
  1805. /* deallocate kernel resources */
  1806. radeon_do_cleanup_cp(dev);
  1807. }
  1808. }
  1809. /* Just reset the CP ring. Called as part of an X Server engine reset.
  1810. */
  1811. int radeon_cp_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
  1812. {
  1813. drm_radeon_private_t *dev_priv = dev->dev_private;
  1814. DRM_DEBUG("\n");
  1815. LOCK_TEST_WITH_RETURN(dev, file_priv);
  1816. if (!dev_priv) {
  1817. DRM_DEBUG("called before init done\n");
  1818. return -EINVAL;
  1819. }
  1820. radeon_do_cp_reset(dev_priv);
  1821. /* The CP is no longer running after an engine reset */
  1822. dev_priv->cp_running = 0;
  1823. return 0;
  1824. }
  1825. int radeon_cp_idle(struct drm_device *dev, void *data, struct drm_file *file_priv)
  1826. {
  1827. drm_radeon_private_t *dev_priv = dev->dev_private;
  1828. DRM_DEBUG("\n");
  1829. LOCK_TEST_WITH_RETURN(dev, file_priv);
  1830. return radeon_do_cp_idle(dev_priv);
  1831. }
  1832. /* Added by Charl P. Botha to call radeon_do_resume_cp().
  1833. */
  1834. int radeon_cp_resume(struct drm_device *dev, void *data, struct drm_file *file_priv)
  1835. {
  1836. return radeon_do_resume_cp(dev);
  1837. }
  1838. int radeon_engine_reset(struct drm_device *dev, void *data, struct drm_file *file_priv)
  1839. {
  1840. DRM_DEBUG("\n");
  1841. LOCK_TEST_WITH_RETURN(dev, file_priv);
  1842. return radeon_do_engine_reset(dev);
  1843. }
  1844. /* ================================================================
  1845. * Fullscreen mode
  1846. */
  1847. /* KW: Deprecated to say the least:
  1848. */
  1849. int radeon_fullscreen(struct drm_device *dev, void *data, struct drm_file *file_priv)
  1850. {
  1851. return 0;
  1852. }
  1853. /* ================================================================
  1854. * Freelist management
  1855. */
  1856. /* Original comment: FIXME: ROTATE_BUFS is a hack to cycle through
  1857. * bufs until freelist code is used. Note this hides a problem with
  1858. * the scratch register * (used to keep track of last buffer
  1859. * completed) being written to before * the last buffer has actually
  1860. * completed rendering.
  1861. *
  1862. * KW: It's also a good way to find free buffers quickly.
  1863. *
  1864. * KW: Ideally this loop wouldn't exist, and freelist_get wouldn't
  1865. * sleep. However, bugs in older versions of radeon_accel.c mean that
  1866. * we essentially have to do this, else old clients will break.
  1867. *
  1868. * However, it does leave open a potential deadlock where all the
  1869. * buffers are held by other clients, which can't release them because
  1870. * they can't get the lock.
  1871. */
  1872. struct drm_buf *radeon_freelist_get(struct drm_device * dev)
  1873. {
  1874. struct drm_device_dma *dma = dev->dma;
  1875. drm_radeon_private_t *dev_priv = dev->dev_private;
  1876. drm_radeon_buf_priv_t *buf_priv;
  1877. struct drm_buf *buf;
  1878. int i, t;
  1879. int start;
  1880. if (++dev_priv->last_buf >= dma->buf_count)
  1881. dev_priv->last_buf = 0;
  1882. start = dev_priv->last_buf;
  1883. for (t = 0; t < dev_priv->usec_timeout; t++) {
  1884. u32 done_age = GET_SCRATCH(1);
  1885. DRM_DEBUG("done_age = %d\n", done_age);
  1886. for (i = start; i < dma->buf_count; i++) {
  1887. buf = dma->buflist[i];
  1888. buf_priv = buf->dev_private;
  1889. if (buf->file_priv == NULL || (buf->pending &&
  1890. buf_priv->age <=
  1891. done_age)) {
  1892. dev_priv->stats.requested_bufs++;
  1893. buf->pending = 0;
  1894. return buf;
  1895. }
  1896. start = 0;
  1897. }
  1898. if (t) {
  1899. DRM_UDELAY(1);
  1900. dev_priv->stats.freelist_loops++;
  1901. }
  1902. }
  1903. DRM_DEBUG("returning NULL!\n");
  1904. return NULL;
  1905. }
  1906. #if 0
  1907. struct drm_buf *radeon_freelist_get(struct drm_device * dev)
  1908. {
  1909. struct drm_device_dma *dma = dev->dma;
  1910. drm_radeon_private_t *dev_priv = dev->dev_private;
  1911. drm_radeon_buf_priv_t *buf_priv;
  1912. struct drm_buf *buf;
  1913. int i, t;
  1914. int start;
  1915. u32 done_age = DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1));
  1916. if (++dev_priv->last_buf >= dma->buf_count)
  1917. dev_priv->last_buf = 0;
  1918. start = dev_priv->last_buf;
  1919. dev_priv->stats.freelist_loops++;
  1920. for (t = 0; t < 2; t++) {
  1921. for (i = start; i < dma->buf_count; i++) {
  1922. buf = dma->buflist[i];
  1923. buf_priv = buf->dev_private;
  1924. if (buf->file_priv == 0 || (buf->pending &&
  1925. buf_priv->age <=
  1926. done_age)) {
  1927. dev_priv->stats.requested_bufs++;
  1928. buf->pending = 0;
  1929. return buf;
  1930. }
  1931. }
  1932. start = 0;
  1933. }
  1934. return NULL;
  1935. }
  1936. #endif
  1937. void radeon_freelist_reset(struct drm_device * dev)
  1938. {
  1939. struct drm_device_dma *dma = dev->dma;
  1940. drm_radeon_private_t *dev_priv = dev->dev_private;
  1941. int i;
  1942. dev_priv->last_buf = 0;
  1943. for (i = 0; i < dma->buf_count; i++) {
  1944. struct drm_buf *buf = dma->buflist[i];
  1945. drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
  1946. buf_priv->age = 0;
  1947. }
  1948. }
  1949. /* ================================================================
  1950. * CP command submission
  1951. */
  1952. int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n)
  1953. {
  1954. drm_radeon_ring_buffer_t *ring = &dev_priv->ring;
  1955. int i;
  1956. u32 last_head = GET_RING_HEAD(dev_priv);
  1957. for (i = 0; i < dev_priv->usec_timeout; i++) {
  1958. u32 head = GET_RING_HEAD(dev_priv);
  1959. ring->space = (head - ring->tail) * sizeof(u32);
  1960. if (ring->space <= 0)
  1961. ring->space += ring->size;
  1962. if (ring->space > n)
  1963. return 0;
  1964. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  1965. if (head != last_head)
  1966. i = 0;
  1967. last_head = head;
  1968. DRM_UDELAY(1);
  1969. }
  1970. /* FIXME: This return value is ignored in the BEGIN_RING macro! */
  1971. #if RADEON_FIFO_DEBUG
  1972. radeon_status(dev_priv);
  1973. DRM_ERROR("failed!\n");
  1974. #endif
  1975. return -EBUSY;
  1976. }
  1977. static int radeon_cp_get_buffers(struct drm_device *dev,
  1978. struct drm_file *file_priv,
  1979. struct drm_dma * d)
  1980. {
  1981. int i;
  1982. struct drm_buf *buf;
  1983. for (i = d->granted_count; i < d->request_count; i++) {
  1984. buf = radeon_freelist_get(dev);
  1985. if (!buf)
  1986. return -EBUSY; /* NOTE: broken client */
  1987. buf->file_priv = file_priv;
  1988. if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx,
  1989. sizeof(buf->idx)))
  1990. return -EFAULT;
  1991. if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total,
  1992. sizeof(buf->total)))
  1993. return -EFAULT;
  1994. d->granted_count++;
  1995. }
  1996. return 0;
  1997. }
  1998. int radeon_cp_buffers(struct drm_device *dev, void *data, struct drm_file *file_priv)
  1999. {
  2000. struct drm_device_dma *dma = dev->dma;
  2001. int ret = 0;
  2002. struct drm_dma *d = data;
  2003. LOCK_TEST_WITH_RETURN(dev, file_priv);
  2004. /* Please don't send us buffers.
  2005. */
  2006. if (d->send_count != 0) {
  2007. DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
  2008. DRM_CURRENTPID, d->send_count);
  2009. return -EINVAL;
  2010. }
  2011. /* We'll send you buffers.
  2012. */
  2013. if (d->request_count < 0 || d->request_count > dma->buf_count) {
  2014. DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
  2015. DRM_CURRENTPID, d->request_count, dma->buf_count);
  2016. return -EINVAL;
  2017. }
  2018. d->granted_count = 0;
  2019. if (d->request_count) {
  2020. ret = radeon_cp_get_buffers(dev, file_priv, d);
  2021. }
  2022. return ret;
  2023. }
  2024. int radeon_driver_load(struct drm_device *dev, unsigned long flags)
  2025. {
  2026. drm_radeon_private_t *dev_priv;
  2027. int ret = 0;
  2028. dev_priv = drm_alloc(sizeof(drm_radeon_private_t), DRM_MEM_DRIVER);
  2029. if (dev_priv == NULL)
  2030. return -ENOMEM;
  2031. memset(dev_priv, 0, sizeof(drm_radeon_private_t));
  2032. dev->dev_private = (void *)dev_priv;
  2033. dev_priv->flags = flags;
  2034. switch (flags & RADEON_FAMILY_MASK) {
  2035. case CHIP_R100:
  2036. case CHIP_RV200:
  2037. case CHIP_R200:
  2038. case CHIP_R300:
  2039. case CHIP_R350:
  2040. case CHIP_R420:
  2041. case CHIP_RV410:
  2042. case CHIP_RV515:
  2043. case CHIP_R520:
  2044. case CHIP_RV570:
  2045. case CHIP_R580:
  2046. dev_priv->flags |= RADEON_HAS_HIERZ;
  2047. break;
  2048. default:
  2049. /* all other chips have no hierarchical z buffer */
  2050. break;
  2051. }
  2052. if (drm_device_is_agp(dev))
  2053. dev_priv->flags |= RADEON_IS_AGP;
  2054. else if (drm_device_is_pcie(dev))
  2055. dev_priv->flags |= RADEON_IS_PCIE;
  2056. else
  2057. dev_priv->flags |= RADEON_IS_PCI;
  2058. DRM_DEBUG("%s card detected\n",
  2059. ((dev_priv->flags & RADEON_IS_AGP) ? "AGP" : (((dev_priv->flags & RADEON_IS_PCIE) ? "PCIE" : "PCI"))));
  2060. return ret;
  2061. }
  2062. /* Create mappings for registers and framebuffer so userland doesn't necessarily
  2063. * have to find them.
  2064. */
  2065. int radeon_driver_firstopen(struct drm_device *dev)
  2066. {
  2067. int ret;
  2068. drm_local_map_t *map;
  2069. drm_radeon_private_t *dev_priv = dev->dev_private;
  2070. dev_priv->gart_info.table_size = RADEON_PCIGART_TABLE_SIZE;
  2071. ret = drm_addmap(dev, drm_get_resource_start(dev, 2),
  2072. drm_get_resource_len(dev, 2), _DRM_REGISTERS,
  2073. _DRM_READ_ONLY, &dev_priv->mmio);
  2074. if (ret != 0)
  2075. return ret;
  2076. dev_priv->fb_aper_offset = drm_get_resource_start(dev, 0);
  2077. ret = drm_addmap(dev, dev_priv->fb_aper_offset,
  2078. drm_get_resource_len(dev, 0), _DRM_FRAME_BUFFER,
  2079. _DRM_WRITE_COMBINING, &map);
  2080. if (ret != 0)
  2081. return ret;
  2082. return 0;
  2083. }
  2084. int radeon_driver_unload(struct drm_device *dev)
  2085. {
  2086. drm_radeon_private_t *dev_priv = dev->dev_private;
  2087. DRM_DEBUG("\n");
  2088. drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
  2089. dev->dev_private = NULL;
  2090. return 0;
  2091. }