radeon_cp.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174
  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(drm_device_t * dev);
  37. /* CP microcode (from ATI) */
  38. static 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 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 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 int RADEON_READ_PLL(drm_device_t * dev, int addr)
  813. {
  814. drm_radeon_private_t *dev_priv = dev->dev_private;
  815. RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX, addr & 0x1f);
  816. return RADEON_READ(RADEON_CLOCK_CNTL_DATA);
  817. }
  818. static int RADEON_READ_PCIE(drm_radeon_private_t * dev_priv, int addr)
  819. {
  820. RADEON_WRITE8(RADEON_PCIE_INDEX, addr & 0xff);
  821. return RADEON_READ(RADEON_PCIE_DATA);
  822. }
  823. #if RADEON_FIFO_DEBUG
  824. static void radeon_status(drm_radeon_private_t * dev_priv)
  825. {
  826. printk("%s:\n", __FUNCTION__);
  827. printk("RBBM_STATUS = 0x%08x\n",
  828. (unsigned int)RADEON_READ(RADEON_RBBM_STATUS));
  829. printk("CP_RB_RTPR = 0x%08x\n",
  830. (unsigned int)RADEON_READ(RADEON_CP_RB_RPTR));
  831. printk("CP_RB_WTPR = 0x%08x\n",
  832. (unsigned int)RADEON_READ(RADEON_CP_RB_WPTR));
  833. printk("AIC_CNTL = 0x%08x\n",
  834. (unsigned int)RADEON_READ(RADEON_AIC_CNTL));
  835. printk("AIC_STAT = 0x%08x\n",
  836. (unsigned int)RADEON_READ(RADEON_AIC_STAT));
  837. printk("AIC_PT_BASE = 0x%08x\n",
  838. (unsigned int)RADEON_READ(RADEON_AIC_PT_BASE));
  839. printk("TLB_ADDR = 0x%08x\n",
  840. (unsigned int)RADEON_READ(RADEON_AIC_TLB_ADDR));
  841. printk("TLB_DATA = 0x%08x\n",
  842. (unsigned int)RADEON_READ(RADEON_AIC_TLB_DATA));
  843. }
  844. #endif
  845. /* ================================================================
  846. * Engine, FIFO control
  847. */
  848. static int radeon_do_pixcache_flush(drm_radeon_private_t * dev_priv)
  849. {
  850. u32 tmp;
  851. int i;
  852. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  853. tmp = RADEON_READ(RADEON_RB2D_DSTCACHE_CTLSTAT);
  854. tmp |= RADEON_RB2D_DC_FLUSH_ALL;
  855. RADEON_WRITE(RADEON_RB2D_DSTCACHE_CTLSTAT, tmp);
  856. for (i = 0; i < dev_priv->usec_timeout; i++) {
  857. if (!(RADEON_READ(RADEON_RB2D_DSTCACHE_CTLSTAT)
  858. & RADEON_RB2D_DC_BUSY)) {
  859. return 0;
  860. }
  861. DRM_UDELAY(1);
  862. }
  863. #if RADEON_FIFO_DEBUG
  864. DRM_ERROR("failed!\n");
  865. radeon_status(dev_priv);
  866. #endif
  867. return DRM_ERR(EBUSY);
  868. }
  869. static int radeon_do_wait_for_fifo(drm_radeon_private_t * dev_priv, int entries)
  870. {
  871. int i;
  872. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  873. for (i = 0; i < dev_priv->usec_timeout; i++) {
  874. int slots = (RADEON_READ(RADEON_RBBM_STATUS)
  875. & RADEON_RBBM_FIFOCNT_MASK);
  876. if (slots >= entries)
  877. return 0;
  878. DRM_UDELAY(1);
  879. }
  880. #if RADEON_FIFO_DEBUG
  881. DRM_ERROR("failed!\n");
  882. radeon_status(dev_priv);
  883. #endif
  884. return DRM_ERR(EBUSY);
  885. }
  886. static int radeon_do_wait_for_idle(drm_radeon_private_t * dev_priv)
  887. {
  888. int i, ret;
  889. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  890. ret = radeon_do_wait_for_fifo(dev_priv, 64);
  891. if (ret)
  892. return ret;
  893. for (i = 0; i < dev_priv->usec_timeout; i++) {
  894. if (!(RADEON_READ(RADEON_RBBM_STATUS)
  895. & RADEON_RBBM_ACTIVE)) {
  896. radeon_do_pixcache_flush(dev_priv);
  897. return 0;
  898. }
  899. DRM_UDELAY(1);
  900. }
  901. #if RADEON_FIFO_DEBUG
  902. DRM_ERROR("failed!\n");
  903. radeon_status(dev_priv);
  904. #endif
  905. return DRM_ERR(EBUSY);
  906. }
  907. /* ================================================================
  908. * CP control, initialization
  909. */
  910. /* Load the microcode for the CP */
  911. static void radeon_cp_load_microcode(drm_radeon_private_t * dev_priv)
  912. {
  913. int i;
  914. DRM_DEBUG("\n");
  915. radeon_do_wait_for_idle(dev_priv);
  916. RADEON_WRITE(RADEON_CP_ME_RAM_ADDR, 0);
  917. if (dev_priv->microcode_version == UCODE_R200) {
  918. DRM_INFO("Loading R200 Microcode\n");
  919. for (i = 0; i < 256; i++) {
  920. RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
  921. R200_cp_microcode[i][1]);
  922. RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
  923. R200_cp_microcode[i][0]);
  924. }
  925. } else if (dev_priv->microcode_version == UCODE_R300) {
  926. DRM_INFO("Loading R300 Microcode\n");
  927. for (i = 0; i < 256; i++) {
  928. RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
  929. R300_cp_microcode[i][1]);
  930. RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
  931. R300_cp_microcode[i][0]);
  932. }
  933. } else {
  934. for (i = 0; i < 256; i++) {
  935. RADEON_WRITE(RADEON_CP_ME_RAM_DATAH,
  936. radeon_cp_microcode[i][1]);
  937. RADEON_WRITE(RADEON_CP_ME_RAM_DATAL,
  938. radeon_cp_microcode[i][0]);
  939. }
  940. }
  941. }
  942. /* Flush any pending commands to the CP. This should only be used just
  943. * prior to a wait for idle, as it informs the engine that the command
  944. * stream is ending.
  945. */
  946. static void radeon_do_cp_flush(drm_radeon_private_t * dev_priv)
  947. {
  948. DRM_DEBUG("\n");
  949. #if 0
  950. u32 tmp;
  951. tmp = RADEON_READ(RADEON_CP_RB_WPTR) | (1 << 31);
  952. RADEON_WRITE(RADEON_CP_RB_WPTR, tmp);
  953. #endif
  954. }
  955. /* Wait for the CP to go idle.
  956. */
  957. int radeon_do_cp_idle(drm_radeon_private_t * dev_priv)
  958. {
  959. RING_LOCALS;
  960. DRM_DEBUG("\n");
  961. BEGIN_RING(6);
  962. RADEON_PURGE_CACHE();
  963. RADEON_PURGE_ZCACHE();
  964. RADEON_WAIT_UNTIL_IDLE();
  965. ADVANCE_RING();
  966. COMMIT_RING();
  967. return radeon_do_wait_for_idle(dev_priv);
  968. }
  969. /* Start the Command Processor.
  970. */
  971. static void radeon_do_cp_start(drm_radeon_private_t * dev_priv)
  972. {
  973. RING_LOCALS;
  974. DRM_DEBUG("\n");
  975. radeon_do_wait_for_idle(dev_priv);
  976. RADEON_WRITE(RADEON_CP_CSQ_CNTL, dev_priv->cp_mode);
  977. dev_priv->cp_running = 1;
  978. BEGIN_RING(6);
  979. RADEON_PURGE_CACHE();
  980. RADEON_PURGE_ZCACHE();
  981. RADEON_WAIT_UNTIL_IDLE();
  982. ADVANCE_RING();
  983. COMMIT_RING();
  984. }
  985. /* Reset the Command Processor. This will not flush any pending
  986. * commands, so you must wait for the CP command stream to complete
  987. * before calling this routine.
  988. */
  989. static void radeon_do_cp_reset(drm_radeon_private_t * dev_priv)
  990. {
  991. u32 cur_read_ptr;
  992. DRM_DEBUG("\n");
  993. cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR);
  994. RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr);
  995. SET_RING_HEAD(dev_priv, cur_read_ptr);
  996. dev_priv->ring.tail = cur_read_ptr;
  997. }
  998. /* Stop the Command Processor. This will not flush any pending
  999. * commands, so you must flush the command stream and wait for the CP
  1000. * to go idle before calling this routine.
  1001. */
  1002. static void radeon_do_cp_stop(drm_radeon_private_t * dev_priv)
  1003. {
  1004. DRM_DEBUG("\n");
  1005. RADEON_WRITE(RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIDIS_INDDIS);
  1006. dev_priv->cp_running = 0;
  1007. }
  1008. /* Reset the engine. This will stop the CP if it is running.
  1009. */
  1010. static int radeon_do_engine_reset(drm_device_t * dev)
  1011. {
  1012. drm_radeon_private_t *dev_priv = dev->dev_private;
  1013. u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
  1014. DRM_DEBUG("\n");
  1015. radeon_do_pixcache_flush(dev_priv);
  1016. clock_cntl_index = RADEON_READ(RADEON_CLOCK_CNTL_INDEX);
  1017. mclk_cntl = RADEON_READ_PLL(dev, RADEON_MCLK_CNTL);
  1018. RADEON_WRITE_PLL(RADEON_MCLK_CNTL, (mclk_cntl |
  1019. RADEON_FORCEON_MCLKA |
  1020. RADEON_FORCEON_MCLKB |
  1021. RADEON_FORCEON_YCLKA |
  1022. RADEON_FORCEON_YCLKB |
  1023. RADEON_FORCEON_MC |
  1024. RADEON_FORCEON_AIC));
  1025. rbbm_soft_reset = RADEON_READ(RADEON_RBBM_SOFT_RESET);
  1026. RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset |
  1027. RADEON_SOFT_RESET_CP |
  1028. RADEON_SOFT_RESET_HI |
  1029. RADEON_SOFT_RESET_SE |
  1030. RADEON_SOFT_RESET_RE |
  1031. RADEON_SOFT_RESET_PP |
  1032. RADEON_SOFT_RESET_E2 |
  1033. RADEON_SOFT_RESET_RB));
  1034. RADEON_READ(RADEON_RBBM_SOFT_RESET);
  1035. RADEON_WRITE(RADEON_RBBM_SOFT_RESET, (rbbm_soft_reset &
  1036. ~(RADEON_SOFT_RESET_CP |
  1037. RADEON_SOFT_RESET_HI |
  1038. RADEON_SOFT_RESET_SE |
  1039. RADEON_SOFT_RESET_RE |
  1040. RADEON_SOFT_RESET_PP |
  1041. RADEON_SOFT_RESET_E2 |
  1042. RADEON_SOFT_RESET_RB)));
  1043. RADEON_READ(RADEON_RBBM_SOFT_RESET);
  1044. RADEON_WRITE_PLL(RADEON_MCLK_CNTL, mclk_cntl);
  1045. RADEON_WRITE(RADEON_CLOCK_CNTL_INDEX, clock_cntl_index);
  1046. RADEON_WRITE(RADEON_RBBM_SOFT_RESET, rbbm_soft_reset);
  1047. /* Reset the CP ring */
  1048. radeon_do_cp_reset(dev_priv);
  1049. /* The CP is no longer running after an engine reset */
  1050. dev_priv->cp_running = 0;
  1051. /* Reset any pending vertex, indirect buffers */
  1052. radeon_freelist_reset(dev);
  1053. return 0;
  1054. }
  1055. static void radeon_cp_init_ring_buffer(drm_device_t * dev,
  1056. drm_radeon_private_t * dev_priv)
  1057. {
  1058. u32 ring_start, cur_read_ptr;
  1059. u32 tmp;
  1060. /* Initialize the memory controller */
  1061. RADEON_WRITE(RADEON_MC_FB_LOCATION,
  1062. ((dev_priv->gart_vm_start - 1) & 0xffff0000)
  1063. | (dev_priv->fb_location >> 16));
  1064. #if __OS_HAS_AGP
  1065. if (!dev_priv->is_pci) {
  1066. RADEON_WRITE(RADEON_MC_AGP_LOCATION,
  1067. (((dev_priv->gart_vm_start - 1 +
  1068. dev_priv->gart_size) & 0xffff0000) |
  1069. (dev_priv->gart_vm_start >> 16)));
  1070. ring_start = (dev_priv->cp_ring->offset
  1071. - dev->agp->base
  1072. + dev_priv->gart_vm_start);
  1073. } else
  1074. #endif
  1075. ring_start = (dev_priv->cp_ring->offset
  1076. - (unsigned long)dev->sg->virtual
  1077. + dev_priv->gart_vm_start);
  1078. RADEON_WRITE(RADEON_CP_RB_BASE, ring_start);
  1079. /* Set the write pointer delay */
  1080. RADEON_WRITE(RADEON_CP_RB_WPTR_DELAY, 0);
  1081. /* Initialize the ring buffer's read and write pointers */
  1082. cur_read_ptr = RADEON_READ(RADEON_CP_RB_RPTR);
  1083. RADEON_WRITE(RADEON_CP_RB_WPTR, cur_read_ptr);
  1084. SET_RING_HEAD(dev_priv, cur_read_ptr);
  1085. dev_priv->ring.tail = cur_read_ptr;
  1086. #if __OS_HAS_AGP
  1087. if (!dev_priv->is_pci) {
  1088. /* set RADEON_AGP_BASE here instead of relying on X from user space */
  1089. RADEON_WRITE(RADEON_AGP_BASE, (unsigned int)dev->agp->base);
  1090. RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR,
  1091. dev_priv->ring_rptr->offset
  1092. - dev->agp->base + dev_priv->gart_vm_start);
  1093. } else
  1094. #endif
  1095. {
  1096. drm_sg_mem_t *entry = dev->sg;
  1097. unsigned long tmp_ofs, page_ofs;
  1098. tmp_ofs = dev_priv->ring_rptr->offset -
  1099. (unsigned long)dev->sg->virtual;
  1100. page_ofs = tmp_ofs >> PAGE_SHIFT;
  1101. RADEON_WRITE(RADEON_CP_RB_RPTR_ADDR, entry->busaddr[page_ofs]);
  1102. DRM_DEBUG("ring rptr: offset=0x%08lx handle=0x%08lx\n",
  1103. (unsigned long)entry->busaddr[page_ofs],
  1104. entry->handle + tmp_ofs);
  1105. }
  1106. /* Initialize the scratch register pointer. This will cause
  1107. * the scratch register values to be written out to memory
  1108. * whenever they are updated.
  1109. *
  1110. * We simply put this behind the ring read pointer, this works
  1111. * with PCI GART as well as (whatever kind of) AGP GART
  1112. */
  1113. RADEON_WRITE(RADEON_SCRATCH_ADDR, RADEON_READ(RADEON_CP_RB_RPTR_ADDR)
  1114. + RADEON_SCRATCH_REG_OFFSET);
  1115. dev_priv->scratch = ((__volatile__ u32 *)
  1116. dev_priv->ring_rptr->handle +
  1117. (RADEON_SCRATCH_REG_OFFSET / sizeof(u32)));
  1118. RADEON_WRITE(RADEON_SCRATCH_UMSK, 0x7);
  1119. /* Writeback doesn't seem to work everywhere, test it first */
  1120. DRM_WRITE32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1), 0);
  1121. RADEON_WRITE(RADEON_SCRATCH_REG1, 0xdeadbeef);
  1122. for (tmp = 0; tmp < dev_priv->usec_timeout; tmp++) {
  1123. if (DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1)) ==
  1124. 0xdeadbeef)
  1125. break;
  1126. DRM_UDELAY(1);
  1127. }
  1128. if (tmp < dev_priv->usec_timeout) {
  1129. dev_priv->writeback_works = 1;
  1130. DRM_DEBUG("writeback test succeeded, tmp=%d\n", tmp);
  1131. } else {
  1132. dev_priv->writeback_works = 0;
  1133. DRM_DEBUG("writeback test failed\n");
  1134. }
  1135. if (radeon_no_wb == 1) {
  1136. dev_priv->writeback_works = 0;
  1137. DRM_DEBUG("writeback forced off\n");
  1138. }
  1139. dev_priv->sarea_priv->last_frame = dev_priv->scratch[0] = 0;
  1140. RADEON_WRITE(RADEON_LAST_FRAME_REG, dev_priv->sarea_priv->last_frame);
  1141. dev_priv->sarea_priv->last_dispatch = dev_priv->scratch[1] = 0;
  1142. RADEON_WRITE(RADEON_LAST_DISPATCH_REG,
  1143. dev_priv->sarea_priv->last_dispatch);
  1144. dev_priv->sarea_priv->last_clear = dev_priv->scratch[2] = 0;
  1145. RADEON_WRITE(RADEON_LAST_CLEAR_REG, dev_priv->sarea_priv->last_clear);
  1146. /* Set ring buffer size */
  1147. #ifdef __BIG_ENDIAN
  1148. RADEON_WRITE(RADEON_CP_RB_CNTL,
  1149. dev_priv->ring.size_l2qw | RADEON_BUF_SWAP_32BIT);
  1150. #else
  1151. RADEON_WRITE(RADEON_CP_RB_CNTL, dev_priv->ring.size_l2qw);
  1152. #endif
  1153. radeon_do_wait_for_idle(dev_priv);
  1154. /* Turn on bus mastering */
  1155. tmp = RADEON_READ(RADEON_BUS_CNTL) & ~RADEON_BUS_MASTER_DIS;
  1156. RADEON_WRITE(RADEON_BUS_CNTL, tmp);
  1157. /* Sync everything up */
  1158. RADEON_WRITE(RADEON_ISYNC_CNTL,
  1159. (RADEON_ISYNC_ANY2D_IDLE3D |
  1160. RADEON_ISYNC_ANY3D_IDLE2D |
  1161. RADEON_ISYNC_WAIT_IDLEGUI |
  1162. RADEON_ISYNC_CPSCRATCH_IDLEGUI));
  1163. }
  1164. /* Enable or disable PCI-E GART on the chip */
  1165. static void radeon_set_pciegart(drm_radeon_private_t * dev_priv, int on)
  1166. {
  1167. u32 tmp = RADEON_READ_PCIE(dev_priv, RADEON_PCIE_TX_GART_CNTL);
  1168. if (on) {
  1169. DRM_DEBUG("programming pcie %08X %08lX %08X\n",
  1170. dev_priv->gart_vm_start,
  1171. (long)dev_priv->gart_info.bus_addr,
  1172. dev_priv->gart_size);
  1173. RADEON_WRITE_PCIE(RADEON_PCIE_TX_DISCARD_RD_ADDR_LO,
  1174. dev_priv->gart_vm_start);
  1175. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_BASE,
  1176. dev_priv->gart_info.bus_addr);
  1177. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_START_LO,
  1178. dev_priv->gart_vm_start);
  1179. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_END_LO,
  1180. dev_priv->gart_vm_start +
  1181. dev_priv->gart_size - 1);
  1182. RADEON_WRITE(RADEON_MC_AGP_LOCATION, 0xffffffc0); /* ?? */
  1183. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL,
  1184. RADEON_PCIE_TX_GART_EN);
  1185. } else {
  1186. RADEON_WRITE_PCIE(RADEON_PCIE_TX_GART_CNTL,
  1187. tmp & ~RADEON_PCIE_TX_GART_EN);
  1188. }
  1189. }
  1190. /* Enable or disable PCI GART on the chip */
  1191. static void radeon_set_pcigart(drm_radeon_private_t * dev_priv, int on)
  1192. {
  1193. u32 tmp = RADEON_READ(RADEON_AIC_CNTL);
  1194. if (dev_priv->flags & CHIP_IS_PCIE) {
  1195. radeon_set_pciegart(dev_priv, on);
  1196. return;
  1197. }
  1198. if (on) {
  1199. RADEON_WRITE(RADEON_AIC_CNTL,
  1200. tmp | RADEON_PCIGART_TRANSLATE_EN);
  1201. /* set PCI GART page-table base address
  1202. */
  1203. RADEON_WRITE(RADEON_AIC_PT_BASE, dev_priv->gart_info.bus_addr);
  1204. /* set address range for PCI address translate
  1205. */
  1206. RADEON_WRITE(RADEON_AIC_LO_ADDR, dev_priv->gart_vm_start);
  1207. RADEON_WRITE(RADEON_AIC_HI_ADDR, dev_priv->gart_vm_start
  1208. + dev_priv->gart_size - 1);
  1209. /* Turn off AGP aperture -- is this required for PCI GART?
  1210. */
  1211. RADEON_WRITE(RADEON_MC_AGP_LOCATION, 0xffffffc0); /* ?? */
  1212. RADEON_WRITE(RADEON_AGP_COMMAND, 0); /* clear AGP_COMMAND */
  1213. } else {
  1214. RADEON_WRITE(RADEON_AIC_CNTL,
  1215. tmp & ~RADEON_PCIGART_TRANSLATE_EN);
  1216. }
  1217. }
  1218. static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
  1219. {
  1220. drm_radeon_private_t *dev_priv = dev->dev_private;
  1221. DRM_DEBUG("\n");
  1222. dev_priv->is_pci = init->is_pci;
  1223. if (dev_priv->is_pci && !dev->sg) {
  1224. DRM_ERROR("PCI GART memory not allocated!\n");
  1225. dev->dev_private = (void *)dev_priv;
  1226. radeon_do_cleanup_cp(dev);
  1227. return DRM_ERR(EINVAL);
  1228. }
  1229. dev_priv->usec_timeout = init->usec_timeout;
  1230. if (dev_priv->usec_timeout < 1 ||
  1231. dev_priv->usec_timeout > RADEON_MAX_USEC_TIMEOUT) {
  1232. DRM_DEBUG("TIMEOUT problem!\n");
  1233. dev->dev_private = (void *)dev_priv;
  1234. radeon_do_cleanup_cp(dev);
  1235. return DRM_ERR(EINVAL);
  1236. }
  1237. switch (init->func) {
  1238. case RADEON_INIT_R200_CP:
  1239. dev_priv->microcode_version = UCODE_R200;
  1240. break;
  1241. case RADEON_INIT_R300_CP:
  1242. dev_priv->microcode_version = UCODE_R300;
  1243. break;
  1244. default:
  1245. dev_priv->microcode_version = UCODE_R100;
  1246. }
  1247. dev_priv->do_boxes = 0;
  1248. dev_priv->cp_mode = init->cp_mode;
  1249. /* We don't support anything other than bus-mastering ring mode,
  1250. * but the ring can be in either AGP or PCI space for the ring
  1251. * read pointer.
  1252. */
  1253. if ((init->cp_mode != RADEON_CSQ_PRIBM_INDDIS) &&
  1254. (init->cp_mode != RADEON_CSQ_PRIBM_INDBM)) {
  1255. DRM_DEBUG("BAD cp_mode (%x)!\n", init->cp_mode);
  1256. dev->dev_private = (void *)dev_priv;
  1257. radeon_do_cleanup_cp(dev);
  1258. return DRM_ERR(EINVAL);
  1259. }
  1260. switch (init->fb_bpp) {
  1261. case 16:
  1262. dev_priv->color_fmt = RADEON_COLOR_FORMAT_RGB565;
  1263. break;
  1264. case 32:
  1265. default:
  1266. dev_priv->color_fmt = RADEON_COLOR_FORMAT_ARGB8888;
  1267. break;
  1268. }
  1269. dev_priv->front_offset = init->front_offset;
  1270. dev_priv->front_pitch = init->front_pitch;
  1271. dev_priv->back_offset = init->back_offset;
  1272. dev_priv->back_pitch = init->back_pitch;
  1273. switch (init->depth_bpp) {
  1274. case 16:
  1275. dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
  1276. break;
  1277. case 32:
  1278. default:
  1279. dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
  1280. break;
  1281. }
  1282. dev_priv->depth_offset = init->depth_offset;
  1283. dev_priv->depth_pitch = init->depth_pitch;
  1284. /* Hardware state for depth clears. Remove this if/when we no
  1285. * longer clear the depth buffer with a 3D rectangle. Hard-code
  1286. * all values to prevent unwanted 3D state from slipping through
  1287. * and screwing with the clear operation.
  1288. */
  1289. dev_priv->depth_clear.rb3d_cntl = (RADEON_PLANE_MASK_ENABLE |
  1290. (dev_priv->color_fmt << 10) |
  1291. (dev_priv->microcode_version ==
  1292. UCODE_R100 ? RADEON_ZBLOCK16 : 0));
  1293. dev_priv->depth_clear.rb3d_zstencilcntl =
  1294. (dev_priv->depth_fmt |
  1295. RADEON_Z_TEST_ALWAYS |
  1296. RADEON_STENCIL_TEST_ALWAYS |
  1297. RADEON_STENCIL_S_FAIL_REPLACE |
  1298. RADEON_STENCIL_ZPASS_REPLACE |
  1299. RADEON_STENCIL_ZFAIL_REPLACE | RADEON_Z_WRITE_ENABLE);
  1300. dev_priv->depth_clear.se_cntl = (RADEON_FFACE_CULL_CW |
  1301. RADEON_BFACE_SOLID |
  1302. RADEON_FFACE_SOLID |
  1303. RADEON_FLAT_SHADE_VTX_LAST |
  1304. RADEON_DIFFUSE_SHADE_FLAT |
  1305. RADEON_ALPHA_SHADE_FLAT |
  1306. RADEON_SPECULAR_SHADE_FLAT |
  1307. RADEON_FOG_SHADE_FLAT |
  1308. RADEON_VTX_PIX_CENTER_OGL |
  1309. RADEON_ROUND_MODE_TRUNC |
  1310. RADEON_ROUND_PREC_8TH_PIX);
  1311. DRM_GETSAREA();
  1312. dev_priv->fb_offset = init->fb_offset;
  1313. dev_priv->mmio_offset = init->mmio_offset;
  1314. dev_priv->ring_offset = init->ring_offset;
  1315. dev_priv->ring_rptr_offset = init->ring_rptr_offset;
  1316. dev_priv->buffers_offset = init->buffers_offset;
  1317. dev_priv->gart_textures_offset = init->gart_textures_offset;
  1318. if (!dev_priv->sarea) {
  1319. DRM_ERROR("could not find sarea!\n");
  1320. dev->dev_private = (void *)dev_priv;
  1321. radeon_do_cleanup_cp(dev);
  1322. return DRM_ERR(EINVAL);
  1323. }
  1324. dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
  1325. if (!dev_priv->mmio) {
  1326. DRM_ERROR("could not find mmio region!\n");
  1327. dev->dev_private = (void *)dev_priv;
  1328. radeon_do_cleanup_cp(dev);
  1329. return DRM_ERR(EINVAL);
  1330. }
  1331. dev_priv->cp_ring = drm_core_findmap(dev, init->ring_offset);
  1332. if (!dev_priv->cp_ring) {
  1333. DRM_ERROR("could not find cp ring region!\n");
  1334. dev->dev_private = (void *)dev_priv;
  1335. radeon_do_cleanup_cp(dev);
  1336. return DRM_ERR(EINVAL);
  1337. }
  1338. dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset);
  1339. if (!dev_priv->ring_rptr) {
  1340. DRM_ERROR("could not find ring read pointer!\n");
  1341. dev->dev_private = (void *)dev_priv;
  1342. radeon_do_cleanup_cp(dev);
  1343. return DRM_ERR(EINVAL);
  1344. }
  1345. dev->agp_buffer_token = init->buffers_offset;
  1346. dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
  1347. if (!dev->agp_buffer_map) {
  1348. DRM_ERROR("could not find dma buffer region!\n");
  1349. dev->dev_private = (void *)dev_priv;
  1350. radeon_do_cleanup_cp(dev);
  1351. return DRM_ERR(EINVAL);
  1352. }
  1353. if (init->gart_textures_offset) {
  1354. dev_priv->gart_textures =
  1355. drm_core_findmap(dev, init->gart_textures_offset);
  1356. if (!dev_priv->gart_textures) {
  1357. DRM_ERROR("could not find GART texture region!\n");
  1358. dev->dev_private = (void *)dev_priv;
  1359. radeon_do_cleanup_cp(dev);
  1360. return DRM_ERR(EINVAL);
  1361. }
  1362. }
  1363. dev_priv->sarea_priv =
  1364. (drm_radeon_sarea_t *) ((u8 *) dev_priv->sarea->handle +
  1365. init->sarea_priv_offset);
  1366. #if __OS_HAS_AGP
  1367. if (!dev_priv->is_pci) {
  1368. drm_core_ioremap(dev_priv->cp_ring, dev);
  1369. drm_core_ioremap(dev_priv->ring_rptr, dev);
  1370. drm_core_ioremap(dev->agp_buffer_map, dev);
  1371. if (!dev_priv->cp_ring->handle ||
  1372. !dev_priv->ring_rptr->handle ||
  1373. !dev->agp_buffer_map->handle) {
  1374. DRM_ERROR("could not find ioremap agp regions!\n");
  1375. dev->dev_private = (void *)dev_priv;
  1376. radeon_do_cleanup_cp(dev);
  1377. return DRM_ERR(EINVAL);
  1378. }
  1379. } else
  1380. #endif
  1381. {
  1382. dev_priv->cp_ring->handle = (void *)dev_priv->cp_ring->offset;
  1383. dev_priv->ring_rptr->handle =
  1384. (void *)dev_priv->ring_rptr->offset;
  1385. dev->agp_buffer_map->handle =
  1386. (void *)dev->agp_buffer_map->offset;
  1387. DRM_DEBUG("dev_priv->cp_ring->handle %p\n",
  1388. dev_priv->cp_ring->handle);
  1389. DRM_DEBUG("dev_priv->ring_rptr->handle %p\n",
  1390. dev_priv->ring_rptr->handle);
  1391. DRM_DEBUG("dev->agp_buffer_map->handle %p\n",
  1392. dev->agp_buffer_map->handle);
  1393. }
  1394. dev_priv->fb_location = (RADEON_READ(RADEON_MC_FB_LOCATION)
  1395. & 0xffff) << 16;
  1396. dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) |
  1397. ((dev_priv->front_offset
  1398. + dev_priv->fb_location) >> 10));
  1399. dev_priv->back_pitch_offset = (((dev_priv->back_pitch / 64) << 22) |
  1400. ((dev_priv->back_offset
  1401. + dev_priv->fb_location) >> 10));
  1402. dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch / 64) << 22) |
  1403. ((dev_priv->depth_offset
  1404. + dev_priv->fb_location) >> 10));
  1405. dev_priv->gart_size = init->gart_size;
  1406. dev_priv->gart_vm_start = dev_priv->fb_location
  1407. + RADEON_READ(RADEON_CONFIG_APER_SIZE);
  1408. #if __OS_HAS_AGP
  1409. if (!dev_priv->is_pci)
  1410. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1411. - dev->agp->base
  1412. + dev_priv->gart_vm_start);
  1413. else
  1414. #endif
  1415. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1416. - (unsigned long)dev->sg->virtual
  1417. + dev_priv->gart_vm_start);
  1418. DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv->gart_size);
  1419. DRM_DEBUG("dev_priv->gart_vm_start 0x%x\n", dev_priv->gart_vm_start);
  1420. DRM_DEBUG("dev_priv->gart_buffers_offset 0x%lx\n",
  1421. dev_priv->gart_buffers_offset);
  1422. dev_priv->ring.start = (u32 *) dev_priv->cp_ring->handle;
  1423. dev_priv->ring.end = ((u32 *) dev_priv->cp_ring->handle
  1424. + init->ring_size / sizeof(u32));
  1425. dev_priv->ring.size = init->ring_size;
  1426. dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8);
  1427. dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;
  1428. dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK;
  1429. #if __OS_HAS_AGP
  1430. if (!dev_priv->is_pci) {
  1431. /* Turn off PCI GART */
  1432. radeon_set_pcigart(dev_priv, 0);
  1433. } else
  1434. #endif
  1435. {
  1436. /* if we have an offset set from userspace */
  1437. if (dev_priv->pcigart_offset) {
  1438. dev_priv->gart_info.bus_addr =
  1439. dev_priv->pcigart_offset + dev_priv->fb_location;
  1440. dev_priv->gart_info.addr =
  1441. (unsigned long)drm_ioremap(dev_priv->gart_info.
  1442. bus_addr,
  1443. RADEON_PCIGART_TABLE_SIZE,
  1444. dev);
  1445. dev_priv->gart_info.is_pcie =
  1446. !!(dev_priv->flags & CHIP_IS_PCIE);
  1447. dev_priv->gart_info.gart_table_location =
  1448. DRM_ATI_GART_FB;
  1449. DRM_DEBUG("Setting phys_pci_gart to %08lX %08lX\n",
  1450. dev_priv->gart_info.addr,
  1451. dev_priv->pcigart_offset);
  1452. } else {
  1453. dev_priv->gart_info.gart_table_location =
  1454. DRM_ATI_GART_MAIN;
  1455. dev_priv->gart_info.addr =
  1456. dev_priv->gart_info.bus_addr = 0;
  1457. if (dev_priv->flags & CHIP_IS_PCIE) {
  1458. DRM_ERROR
  1459. ("Cannot use PCI Express without GART in FB memory\n");
  1460. radeon_do_cleanup_cp(dev);
  1461. return DRM_ERR(EINVAL);
  1462. }
  1463. }
  1464. if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) {
  1465. DRM_ERROR("failed to init PCI GART!\n");
  1466. dev->dev_private = (void *)dev_priv;
  1467. radeon_do_cleanup_cp(dev);
  1468. return DRM_ERR(ENOMEM);
  1469. }
  1470. /* Turn on PCI GART */
  1471. radeon_set_pcigart(dev_priv, 1);
  1472. }
  1473. radeon_cp_load_microcode(dev_priv);
  1474. radeon_cp_init_ring_buffer(dev, dev_priv);
  1475. dev_priv->last_buf = 0;
  1476. dev->dev_private = (void *)dev_priv;
  1477. radeon_do_engine_reset(dev);
  1478. return 0;
  1479. }
  1480. static int radeon_do_cleanup_cp(drm_device_t * dev)
  1481. {
  1482. drm_radeon_private_t *dev_priv = dev->dev_private;
  1483. DRM_DEBUG("\n");
  1484. /* Make sure interrupts are disabled here because the uninstall ioctl
  1485. * may not have been called from userspace and after dev_private
  1486. * is freed, it's too late.
  1487. */
  1488. if (dev->irq_enabled)
  1489. drm_irq_uninstall(dev);
  1490. #if __OS_HAS_AGP
  1491. if (!dev_priv->is_pci) {
  1492. if (dev_priv->cp_ring != NULL)
  1493. drm_core_ioremapfree(dev_priv->cp_ring, dev);
  1494. if (dev_priv->ring_rptr != NULL)
  1495. drm_core_ioremapfree(dev_priv->ring_rptr, dev);
  1496. if (dev->agp_buffer_map != NULL) {
  1497. drm_core_ioremapfree(dev->agp_buffer_map, dev);
  1498. dev->agp_buffer_map = NULL;
  1499. }
  1500. } else
  1501. #endif
  1502. {
  1503. if (dev_priv->gart_info.bus_addr)
  1504. if (!drm_ati_pcigart_cleanup(dev, &dev_priv->gart_info))
  1505. DRM_ERROR("failed to cleanup PCI GART!\n");
  1506. if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB) {
  1507. drm_ioremapfree((void *)dev_priv->gart_info.addr,
  1508. RADEON_PCIGART_TABLE_SIZE, dev);
  1509. dev_priv->gart_info.addr = 0;
  1510. }
  1511. }
  1512. /* only clear to the start of flags */
  1513. memset(dev_priv, 0, offsetof(drm_radeon_private_t, flags));
  1514. return 0;
  1515. }
  1516. /* This code will reinit the Radeon CP hardware after a resume from disc.
  1517. * AFAIK, it would be very difficult to pickle the state at suspend time, so
  1518. * here we make sure that all Radeon hardware initialisation is re-done without
  1519. * affecting running applications.
  1520. *
  1521. * Charl P. Botha <http://cpbotha.net>
  1522. */
  1523. static int radeon_do_resume_cp(drm_device_t * dev)
  1524. {
  1525. drm_radeon_private_t *dev_priv = dev->dev_private;
  1526. if (!dev_priv) {
  1527. DRM_ERROR("Called with no initialization\n");
  1528. return DRM_ERR(EINVAL);
  1529. }
  1530. DRM_DEBUG("Starting radeon_do_resume_cp()\n");
  1531. #if __OS_HAS_AGP
  1532. if (!dev_priv->is_pci) {
  1533. /* Turn off PCI GART */
  1534. radeon_set_pcigart(dev_priv, 0);
  1535. } else
  1536. #endif
  1537. {
  1538. /* Turn on PCI GART */
  1539. radeon_set_pcigart(dev_priv, 1);
  1540. }
  1541. radeon_cp_load_microcode(dev_priv);
  1542. radeon_cp_init_ring_buffer(dev, dev_priv);
  1543. radeon_do_engine_reset(dev);
  1544. DRM_DEBUG("radeon_do_resume_cp() complete\n");
  1545. return 0;
  1546. }
  1547. int radeon_cp_init(DRM_IOCTL_ARGS)
  1548. {
  1549. DRM_DEVICE;
  1550. drm_radeon_init_t init;
  1551. LOCK_TEST_WITH_RETURN(dev, filp);
  1552. DRM_COPY_FROM_USER_IOCTL(init, (drm_radeon_init_t __user *) data,
  1553. sizeof(init));
  1554. if (init.func == RADEON_INIT_R300_CP)
  1555. r300_init_reg_flags();
  1556. switch (init.func) {
  1557. case RADEON_INIT_CP:
  1558. case RADEON_INIT_R200_CP:
  1559. case RADEON_INIT_R300_CP:
  1560. return radeon_do_init_cp(dev, &init);
  1561. case RADEON_CLEANUP_CP:
  1562. return radeon_do_cleanup_cp(dev);
  1563. }
  1564. return DRM_ERR(EINVAL);
  1565. }
  1566. int radeon_cp_start(DRM_IOCTL_ARGS)
  1567. {
  1568. DRM_DEVICE;
  1569. drm_radeon_private_t *dev_priv = dev->dev_private;
  1570. DRM_DEBUG("\n");
  1571. LOCK_TEST_WITH_RETURN(dev, filp);
  1572. if (dev_priv->cp_running) {
  1573. DRM_DEBUG("%s while CP running\n", __FUNCTION__);
  1574. return 0;
  1575. }
  1576. if (dev_priv->cp_mode == RADEON_CSQ_PRIDIS_INDDIS) {
  1577. DRM_DEBUG("%s called with bogus CP mode (%d)\n",
  1578. __FUNCTION__, dev_priv->cp_mode);
  1579. return 0;
  1580. }
  1581. radeon_do_cp_start(dev_priv);
  1582. return 0;
  1583. }
  1584. /* Stop the CP. The engine must have been idled before calling this
  1585. * routine.
  1586. */
  1587. int radeon_cp_stop(DRM_IOCTL_ARGS)
  1588. {
  1589. DRM_DEVICE;
  1590. drm_radeon_private_t *dev_priv = dev->dev_private;
  1591. drm_radeon_cp_stop_t stop;
  1592. int ret;
  1593. DRM_DEBUG("\n");
  1594. LOCK_TEST_WITH_RETURN(dev, filp);
  1595. DRM_COPY_FROM_USER_IOCTL(stop, (drm_radeon_cp_stop_t __user *) data,
  1596. sizeof(stop));
  1597. if (!dev_priv->cp_running)
  1598. return 0;
  1599. /* Flush any pending CP commands. This ensures any outstanding
  1600. * commands are exectuted by the engine before we turn it off.
  1601. */
  1602. if (stop.flush) {
  1603. radeon_do_cp_flush(dev_priv);
  1604. }
  1605. /* If we fail to make the engine go idle, we return an error
  1606. * code so that the DRM ioctl wrapper can try again.
  1607. */
  1608. if (stop.idle) {
  1609. ret = radeon_do_cp_idle(dev_priv);
  1610. if (ret)
  1611. return ret;
  1612. }
  1613. /* Finally, we can turn off the CP. If the engine isn't idle,
  1614. * we will get some dropped triangles as they won't be fully
  1615. * rendered before the CP is shut down.
  1616. */
  1617. radeon_do_cp_stop(dev_priv);
  1618. /* Reset the engine */
  1619. radeon_do_engine_reset(dev);
  1620. return 0;
  1621. }
  1622. void radeon_do_release(drm_device_t * dev)
  1623. {
  1624. drm_radeon_private_t *dev_priv = dev->dev_private;
  1625. int i, ret;
  1626. if (dev_priv) {
  1627. if (dev_priv->cp_running) {
  1628. /* Stop the cp */
  1629. while ((ret = radeon_do_cp_idle(dev_priv)) != 0) {
  1630. DRM_DEBUG("radeon_do_cp_idle %d\n", ret);
  1631. #ifdef __linux__
  1632. schedule();
  1633. #else
  1634. tsleep(&ret, PZERO, "rdnrel", 1);
  1635. #endif
  1636. }
  1637. radeon_do_cp_stop(dev_priv);
  1638. radeon_do_engine_reset(dev);
  1639. }
  1640. /* Disable *all* interrupts */
  1641. if (dev_priv->mmio) /* remove this after permanent addmaps */
  1642. RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
  1643. if (dev_priv->mmio) { /* remove all surfaces */
  1644. for (i = 0; i < RADEON_MAX_SURFACES; i++) {
  1645. RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * i, 0);
  1646. RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND +
  1647. 16 * i, 0);
  1648. RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND +
  1649. 16 * i, 0);
  1650. }
  1651. }
  1652. /* Free memory heap structures */
  1653. radeon_mem_takedown(&(dev_priv->gart_heap));
  1654. radeon_mem_takedown(&(dev_priv->fb_heap));
  1655. /* deallocate kernel resources */
  1656. radeon_do_cleanup_cp(dev);
  1657. }
  1658. }
  1659. /* Just reset the CP ring. Called as part of an X Server engine reset.
  1660. */
  1661. int radeon_cp_reset(DRM_IOCTL_ARGS)
  1662. {
  1663. DRM_DEVICE;
  1664. drm_radeon_private_t *dev_priv = dev->dev_private;
  1665. DRM_DEBUG("\n");
  1666. LOCK_TEST_WITH_RETURN(dev, filp);
  1667. if (!dev_priv) {
  1668. DRM_DEBUG("%s called before init done\n", __FUNCTION__);
  1669. return DRM_ERR(EINVAL);
  1670. }
  1671. radeon_do_cp_reset(dev_priv);
  1672. /* The CP is no longer running after an engine reset */
  1673. dev_priv->cp_running = 0;
  1674. return 0;
  1675. }
  1676. int radeon_cp_idle(DRM_IOCTL_ARGS)
  1677. {
  1678. DRM_DEVICE;
  1679. drm_radeon_private_t *dev_priv = dev->dev_private;
  1680. DRM_DEBUG("\n");
  1681. LOCK_TEST_WITH_RETURN(dev, filp);
  1682. return radeon_do_cp_idle(dev_priv);
  1683. }
  1684. /* Added by Charl P. Botha to call radeon_do_resume_cp().
  1685. */
  1686. int radeon_cp_resume(DRM_IOCTL_ARGS)
  1687. {
  1688. DRM_DEVICE;
  1689. return radeon_do_resume_cp(dev);
  1690. }
  1691. int radeon_engine_reset(DRM_IOCTL_ARGS)
  1692. {
  1693. DRM_DEVICE;
  1694. DRM_DEBUG("\n");
  1695. LOCK_TEST_WITH_RETURN(dev, filp);
  1696. return radeon_do_engine_reset(dev);
  1697. }
  1698. /* ================================================================
  1699. * Fullscreen mode
  1700. */
  1701. /* KW: Deprecated to say the least:
  1702. */
  1703. int radeon_fullscreen(DRM_IOCTL_ARGS)
  1704. {
  1705. return 0;
  1706. }
  1707. /* ================================================================
  1708. * Freelist management
  1709. */
  1710. /* Original comment: FIXME: ROTATE_BUFS is a hack to cycle through
  1711. * bufs until freelist code is used. Note this hides a problem with
  1712. * the scratch register * (used to keep track of last buffer
  1713. * completed) being written to before * the last buffer has actually
  1714. * completed rendering.
  1715. *
  1716. * KW: It's also a good way to find free buffers quickly.
  1717. *
  1718. * KW: Ideally this loop wouldn't exist, and freelist_get wouldn't
  1719. * sleep. However, bugs in older versions of radeon_accel.c mean that
  1720. * we essentially have to do this, else old clients will break.
  1721. *
  1722. * However, it does leave open a potential deadlock where all the
  1723. * buffers are held by other clients, which can't release them because
  1724. * they can't get the lock.
  1725. */
  1726. drm_buf_t *radeon_freelist_get(drm_device_t * dev)
  1727. {
  1728. drm_device_dma_t *dma = dev->dma;
  1729. drm_radeon_private_t *dev_priv = dev->dev_private;
  1730. drm_radeon_buf_priv_t *buf_priv;
  1731. drm_buf_t *buf;
  1732. int i, t;
  1733. int start;
  1734. if (++dev_priv->last_buf >= dma->buf_count)
  1735. dev_priv->last_buf = 0;
  1736. start = dev_priv->last_buf;
  1737. for (t = 0; t < dev_priv->usec_timeout; t++) {
  1738. u32 done_age = GET_SCRATCH(1);
  1739. DRM_DEBUG("done_age = %d\n", done_age);
  1740. for (i = start; i < dma->buf_count; i++) {
  1741. buf = dma->buflist[i];
  1742. buf_priv = buf->dev_private;
  1743. if (buf->filp == 0 || (buf->pending &&
  1744. buf_priv->age <= done_age)) {
  1745. dev_priv->stats.requested_bufs++;
  1746. buf->pending = 0;
  1747. return buf;
  1748. }
  1749. start = 0;
  1750. }
  1751. if (t) {
  1752. DRM_UDELAY(1);
  1753. dev_priv->stats.freelist_loops++;
  1754. }
  1755. }
  1756. DRM_DEBUG("returning NULL!\n");
  1757. return NULL;
  1758. }
  1759. #if 0
  1760. drm_buf_t *radeon_freelist_get(drm_device_t * dev)
  1761. {
  1762. drm_device_dma_t *dma = dev->dma;
  1763. drm_radeon_private_t *dev_priv = dev->dev_private;
  1764. drm_radeon_buf_priv_t *buf_priv;
  1765. drm_buf_t *buf;
  1766. int i, t;
  1767. int start;
  1768. u32 done_age = DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1));
  1769. if (++dev_priv->last_buf >= dma->buf_count)
  1770. dev_priv->last_buf = 0;
  1771. start = dev_priv->last_buf;
  1772. dev_priv->stats.freelist_loops++;
  1773. for (t = 0; t < 2; t++) {
  1774. for (i = start; i < dma->buf_count; i++) {
  1775. buf = dma->buflist[i];
  1776. buf_priv = buf->dev_private;
  1777. if (buf->filp == 0 || (buf->pending &&
  1778. buf_priv->age <= done_age)) {
  1779. dev_priv->stats.requested_bufs++;
  1780. buf->pending = 0;
  1781. return buf;
  1782. }
  1783. }
  1784. start = 0;
  1785. }
  1786. return NULL;
  1787. }
  1788. #endif
  1789. void radeon_freelist_reset(drm_device_t * dev)
  1790. {
  1791. drm_device_dma_t *dma = dev->dma;
  1792. drm_radeon_private_t *dev_priv = dev->dev_private;
  1793. int i;
  1794. dev_priv->last_buf = 0;
  1795. for (i = 0; i < dma->buf_count; i++) {
  1796. drm_buf_t *buf = dma->buflist[i];
  1797. drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
  1798. buf_priv->age = 0;
  1799. }
  1800. }
  1801. /* ================================================================
  1802. * CP command submission
  1803. */
  1804. int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n)
  1805. {
  1806. drm_radeon_ring_buffer_t *ring = &dev_priv->ring;
  1807. int i;
  1808. u32 last_head = GET_RING_HEAD(dev_priv);
  1809. for (i = 0; i < dev_priv->usec_timeout; i++) {
  1810. u32 head = GET_RING_HEAD(dev_priv);
  1811. ring->space = (head - ring->tail) * sizeof(u32);
  1812. if (ring->space <= 0)
  1813. ring->space += ring->size;
  1814. if (ring->space > n)
  1815. return 0;
  1816. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  1817. if (head != last_head)
  1818. i = 0;
  1819. last_head = head;
  1820. DRM_UDELAY(1);
  1821. }
  1822. /* FIXME: This return value is ignored in the BEGIN_RING macro! */
  1823. #if RADEON_FIFO_DEBUG
  1824. radeon_status(dev_priv);
  1825. DRM_ERROR("failed!\n");
  1826. #endif
  1827. return DRM_ERR(EBUSY);
  1828. }
  1829. static int radeon_cp_get_buffers(DRMFILE filp, drm_device_t * dev,
  1830. drm_dma_t * d)
  1831. {
  1832. int i;
  1833. drm_buf_t *buf;
  1834. for (i = d->granted_count; i < d->request_count; i++) {
  1835. buf = radeon_freelist_get(dev);
  1836. if (!buf)
  1837. return DRM_ERR(EBUSY); /* NOTE: broken client */
  1838. buf->filp = filp;
  1839. if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx,
  1840. sizeof(buf->idx)))
  1841. return DRM_ERR(EFAULT);
  1842. if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total,
  1843. sizeof(buf->total)))
  1844. return DRM_ERR(EFAULT);
  1845. d->granted_count++;
  1846. }
  1847. return 0;
  1848. }
  1849. int radeon_cp_buffers(DRM_IOCTL_ARGS)
  1850. {
  1851. DRM_DEVICE;
  1852. drm_device_dma_t *dma = dev->dma;
  1853. int ret = 0;
  1854. drm_dma_t __user *argp = (void __user *)data;
  1855. drm_dma_t d;
  1856. LOCK_TEST_WITH_RETURN(dev, filp);
  1857. DRM_COPY_FROM_USER_IOCTL(d, argp, sizeof(d));
  1858. /* Please don't send us buffers.
  1859. */
  1860. if (d.send_count != 0) {
  1861. DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
  1862. DRM_CURRENTPID, d.send_count);
  1863. return DRM_ERR(EINVAL);
  1864. }
  1865. /* We'll send you buffers.
  1866. */
  1867. if (d.request_count < 0 || d.request_count > dma->buf_count) {
  1868. DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
  1869. DRM_CURRENTPID, d.request_count, dma->buf_count);
  1870. return DRM_ERR(EINVAL);
  1871. }
  1872. d.granted_count = 0;
  1873. if (d.request_count) {
  1874. ret = radeon_cp_get_buffers(filp, dev, &d);
  1875. }
  1876. DRM_COPY_TO_USER_IOCTL(argp, d, sizeof(d));
  1877. return ret;
  1878. }
  1879. int radeon_driver_preinit(struct drm_device *dev, unsigned long flags)
  1880. {
  1881. drm_radeon_private_t *dev_priv;
  1882. int ret = 0;
  1883. dev_priv = drm_alloc(sizeof(drm_radeon_private_t), DRM_MEM_DRIVER);
  1884. if (dev_priv == NULL)
  1885. return DRM_ERR(ENOMEM);
  1886. memset(dev_priv, 0, sizeof(drm_radeon_private_t));
  1887. dev->dev_private = (void *)dev_priv;
  1888. dev_priv->flags = flags;
  1889. switch (flags & CHIP_FAMILY_MASK) {
  1890. case CHIP_R100:
  1891. case CHIP_RV200:
  1892. case CHIP_R200:
  1893. case CHIP_R300:
  1894. case CHIP_R420:
  1895. dev_priv->flags |= CHIP_HAS_HIERZ;
  1896. break;
  1897. default:
  1898. /* all other chips have no hierarchical z buffer */
  1899. break;
  1900. }
  1901. if (drm_device_is_agp(dev))
  1902. dev_priv->flags |= CHIP_IS_AGP;
  1903. if (drm_device_is_pcie(dev))
  1904. dev_priv->flags |= CHIP_IS_PCIE;
  1905. DRM_DEBUG("%s card detected\n",
  1906. ((dev_priv->flags & CHIP_IS_AGP) ? "AGP" : "PCI"));
  1907. return ret;
  1908. }
  1909. int radeon_presetup(struct drm_device *dev)
  1910. {
  1911. int ret;
  1912. drm_local_map_t *map;
  1913. drm_radeon_private_t *dev_priv = dev->dev_private;
  1914. ret = drm_addmap(dev, drm_get_resource_start(dev, 2),
  1915. drm_get_resource_len(dev, 2), _DRM_REGISTERS,
  1916. _DRM_READ_ONLY, &dev_priv->mmio);
  1917. if (ret != 0)
  1918. return ret;
  1919. ret = drm_addmap(dev, drm_get_resource_start(dev, 0),
  1920. drm_get_resource_len(dev, 0), _DRM_FRAME_BUFFER,
  1921. _DRM_WRITE_COMBINING, &map);
  1922. if (ret != 0)
  1923. return ret;
  1924. return 0;
  1925. }
  1926. int radeon_driver_postcleanup(struct drm_device *dev)
  1927. {
  1928. drm_radeon_private_t *dev_priv = dev->dev_private;
  1929. DRM_DEBUG("\n");
  1930. drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
  1931. dev->dev_private = NULL;
  1932. return 0;
  1933. }