radeon_cp.c 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172
  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->flags & CHIP_IS_AGP) {
  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->flags & CHIP_IS_AGP) {
  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;
  1194. if (dev_priv->flags & CHIP_IS_PCIE) {
  1195. radeon_set_pciegart(dev_priv, on);
  1196. return;
  1197. }
  1198. tmp = RADEON_READ(RADEON_AIC_CNTL);
  1199. if (on) {
  1200. RADEON_WRITE(RADEON_AIC_CNTL,
  1201. tmp | RADEON_PCIGART_TRANSLATE_EN);
  1202. /* set PCI GART page-table base address
  1203. */
  1204. RADEON_WRITE(RADEON_AIC_PT_BASE, dev_priv->gart_info.bus_addr);
  1205. /* set address range for PCI address translate
  1206. */
  1207. RADEON_WRITE(RADEON_AIC_LO_ADDR, dev_priv->gart_vm_start);
  1208. RADEON_WRITE(RADEON_AIC_HI_ADDR, dev_priv->gart_vm_start
  1209. + dev_priv->gart_size - 1);
  1210. /* Turn off AGP aperture -- is this required for PCI GART?
  1211. */
  1212. RADEON_WRITE(RADEON_MC_AGP_LOCATION, 0xffffffc0); /* ?? */
  1213. RADEON_WRITE(RADEON_AGP_COMMAND, 0); /* clear AGP_COMMAND */
  1214. } else {
  1215. RADEON_WRITE(RADEON_AIC_CNTL,
  1216. tmp & ~RADEON_PCIGART_TRANSLATE_EN);
  1217. }
  1218. }
  1219. static int radeon_do_init_cp(drm_device_t * dev, drm_radeon_init_t * init)
  1220. {
  1221. drm_radeon_private_t *dev_priv = dev->dev_private;
  1222. DRM_DEBUG("\n");
  1223. if (init->is_pci && (dev_priv->flags & CHIP_IS_AGP))
  1224. {
  1225. DRM_DEBUG("Forcing AGP card to PCI mode\n");
  1226. dev_priv->flags &= ~CHIP_IS_AGP;
  1227. }
  1228. if ((!(dev_priv->flags & CHIP_IS_AGP)) && !dev->sg) {
  1229. DRM_ERROR("PCI GART memory not allocated!\n");
  1230. radeon_do_cleanup_cp(dev);
  1231. return DRM_ERR(EINVAL);
  1232. }
  1233. dev_priv->usec_timeout = init->usec_timeout;
  1234. if (dev_priv->usec_timeout < 1 ||
  1235. dev_priv->usec_timeout > RADEON_MAX_USEC_TIMEOUT) {
  1236. DRM_DEBUG("TIMEOUT problem!\n");
  1237. radeon_do_cleanup_cp(dev);
  1238. return DRM_ERR(EINVAL);
  1239. }
  1240. switch(init->func) {
  1241. case RADEON_INIT_R200_CP:
  1242. dev_priv->microcode_version = UCODE_R200;
  1243. break;
  1244. case RADEON_INIT_R300_CP:
  1245. dev_priv->microcode_version = UCODE_R300;
  1246. break;
  1247. default:
  1248. dev_priv->microcode_version = UCODE_R100;
  1249. }
  1250. dev_priv->do_boxes = 0;
  1251. dev_priv->cp_mode = init->cp_mode;
  1252. /* We don't support anything other than bus-mastering ring mode,
  1253. * but the ring can be in either AGP or PCI space for the ring
  1254. * read pointer.
  1255. */
  1256. if ((init->cp_mode != RADEON_CSQ_PRIBM_INDDIS) &&
  1257. (init->cp_mode != RADEON_CSQ_PRIBM_INDBM)) {
  1258. DRM_DEBUG("BAD cp_mode (%x)!\n", init->cp_mode);
  1259. radeon_do_cleanup_cp(dev);
  1260. return DRM_ERR(EINVAL);
  1261. }
  1262. switch (init->fb_bpp) {
  1263. case 16:
  1264. dev_priv->color_fmt = RADEON_COLOR_FORMAT_RGB565;
  1265. break;
  1266. case 32:
  1267. default:
  1268. dev_priv->color_fmt = RADEON_COLOR_FORMAT_ARGB8888;
  1269. break;
  1270. }
  1271. dev_priv->front_offset = init->front_offset;
  1272. dev_priv->front_pitch = init->front_pitch;
  1273. dev_priv->back_offset = init->back_offset;
  1274. dev_priv->back_pitch = init->back_pitch;
  1275. switch (init->depth_bpp) {
  1276. case 16:
  1277. dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
  1278. break;
  1279. case 32:
  1280. default:
  1281. dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
  1282. break;
  1283. }
  1284. dev_priv->depth_offset = init->depth_offset;
  1285. dev_priv->depth_pitch = init->depth_pitch;
  1286. /* Hardware state for depth clears. Remove this if/when we no
  1287. * longer clear the depth buffer with a 3D rectangle. Hard-code
  1288. * all values to prevent unwanted 3D state from slipping through
  1289. * and screwing with the clear operation.
  1290. */
  1291. dev_priv->depth_clear.rb3d_cntl = (RADEON_PLANE_MASK_ENABLE |
  1292. (dev_priv->color_fmt << 10) |
  1293. (dev_priv->microcode_version ==
  1294. UCODE_R100 ? RADEON_ZBLOCK16 : 0));
  1295. dev_priv->depth_clear.rb3d_zstencilcntl =
  1296. (dev_priv->depth_fmt |
  1297. RADEON_Z_TEST_ALWAYS |
  1298. RADEON_STENCIL_TEST_ALWAYS |
  1299. RADEON_STENCIL_S_FAIL_REPLACE |
  1300. RADEON_STENCIL_ZPASS_REPLACE |
  1301. RADEON_STENCIL_ZFAIL_REPLACE | RADEON_Z_WRITE_ENABLE);
  1302. dev_priv->depth_clear.se_cntl = (RADEON_FFACE_CULL_CW |
  1303. RADEON_BFACE_SOLID |
  1304. RADEON_FFACE_SOLID |
  1305. RADEON_FLAT_SHADE_VTX_LAST |
  1306. RADEON_DIFFUSE_SHADE_FLAT |
  1307. RADEON_ALPHA_SHADE_FLAT |
  1308. RADEON_SPECULAR_SHADE_FLAT |
  1309. RADEON_FOG_SHADE_FLAT |
  1310. RADEON_VTX_PIX_CENTER_OGL |
  1311. RADEON_ROUND_MODE_TRUNC |
  1312. RADEON_ROUND_PREC_8TH_PIX);
  1313. DRM_GETSAREA();
  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. radeon_do_cleanup_cp(dev);
  1321. return DRM_ERR(EINVAL);
  1322. }
  1323. dev_priv->cp_ring = drm_core_findmap(dev, init->ring_offset);
  1324. if (!dev_priv->cp_ring) {
  1325. DRM_ERROR("could not find cp ring region!\n");
  1326. radeon_do_cleanup_cp(dev);
  1327. return DRM_ERR(EINVAL);
  1328. }
  1329. dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset);
  1330. if (!dev_priv->ring_rptr) {
  1331. DRM_ERROR("could not find ring read pointer!\n");
  1332. radeon_do_cleanup_cp(dev);
  1333. return DRM_ERR(EINVAL);
  1334. }
  1335. dev->agp_buffer_token = init->buffers_offset;
  1336. dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
  1337. if (!dev->agp_buffer_map) {
  1338. DRM_ERROR("could not find dma buffer region!\n");
  1339. radeon_do_cleanup_cp(dev);
  1340. return DRM_ERR(EINVAL);
  1341. }
  1342. if (init->gart_textures_offset) {
  1343. dev_priv->gart_textures =
  1344. drm_core_findmap(dev, init->gart_textures_offset);
  1345. if (!dev_priv->gart_textures) {
  1346. DRM_ERROR("could not find GART texture region!\n");
  1347. radeon_do_cleanup_cp(dev);
  1348. return DRM_ERR(EINVAL);
  1349. }
  1350. }
  1351. dev_priv->sarea_priv =
  1352. (drm_radeon_sarea_t *) ((u8 *) dev_priv->sarea->handle +
  1353. init->sarea_priv_offset);
  1354. #if __OS_HAS_AGP
  1355. if (dev_priv->flags & CHIP_IS_AGP) {
  1356. drm_core_ioremap(dev_priv->cp_ring, dev);
  1357. drm_core_ioremap(dev_priv->ring_rptr, dev);
  1358. drm_core_ioremap(dev->agp_buffer_map, dev);
  1359. if (!dev_priv->cp_ring->handle ||
  1360. !dev_priv->ring_rptr->handle ||
  1361. !dev->agp_buffer_map->handle) {
  1362. DRM_ERROR("could not find ioremap agp regions!\n");
  1363. radeon_do_cleanup_cp(dev);
  1364. return DRM_ERR(EINVAL);
  1365. }
  1366. } else
  1367. #endif
  1368. {
  1369. dev_priv->cp_ring->handle = (void *)dev_priv->cp_ring->offset;
  1370. dev_priv->ring_rptr->handle =
  1371. (void *)dev_priv->ring_rptr->offset;
  1372. dev->agp_buffer_map->handle =
  1373. (void *)dev->agp_buffer_map->offset;
  1374. DRM_DEBUG("dev_priv->cp_ring->handle %p\n",
  1375. dev_priv->cp_ring->handle);
  1376. DRM_DEBUG("dev_priv->ring_rptr->handle %p\n",
  1377. dev_priv->ring_rptr->handle);
  1378. DRM_DEBUG("dev->agp_buffer_map->handle %p\n",
  1379. dev->agp_buffer_map->handle);
  1380. }
  1381. dev_priv->fb_location = (RADEON_READ(RADEON_MC_FB_LOCATION)
  1382. & 0xffff) << 16;
  1383. dev_priv->front_pitch_offset = (((dev_priv->front_pitch / 64) << 22) |
  1384. ((dev_priv->front_offset
  1385. + dev_priv->fb_location) >> 10));
  1386. dev_priv->back_pitch_offset = (((dev_priv->back_pitch / 64) << 22) |
  1387. ((dev_priv->back_offset
  1388. + dev_priv->fb_location) >> 10));
  1389. dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch / 64) << 22) |
  1390. ((dev_priv->depth_offset
  1391. + dev_priv->fb_location) >> 10));
  1392. dev_priv->gart_size = init->gart_size;
  1393. dev_priv->gart_vm_start = dev_priv->fb_location
  1394. + RADEON_READ(RADEON_CONFIG_APER_SIZE);
  1395. #if __OS_HAS_AGP
  1396. if (dev_priv->flags & CHIP_IS_AGP)
  1397. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1398. - dev->agp->base
  1399. + dev_priv->gart_vm_start);
  1400. else
  1401. #endif
  1402. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1403. - (unsigned long)dev->sg->virtual
  1404. + dev_priv->gart_vm_start);
  1405. DRM_DEBUG("dev_priv->gart_size %d\n", dev_priv->gart_size);
  1406. DRM_DEBUG("dev_priv->gart_vm_start 0x%x\n", dev_priv->gart_vm_start);
  1407. DRM_DEBUG("dev_priv->gart_buffers_offset 0x%lx\n",
  1408. dev_priv->gart_buffers_offset);
  1409. dev_priv->ring.start = (u32 *) dev_priv->cp_ring->handle;
  1410. dev_priv->ring.end = ((u32 *) dev_priv->cp_ring->handle
  1411. + init->ring_size / sizeof(u32));
  1412. dev_priv->ring.size = init->ring_size;
  1413. dev_priv->ring.size_l2qw = drm_order(init->ring_size / 8);
  1414. dev_priv->ring.tail_mask = (dev_priv->ring.size / sizeof(u32)) - 1;
  1415. dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK;
  1416. #if __OS_HAS_AGP
  1417. if (dev_priv->flags & CHIP_IS_AGP) {
  1418. /* Turn off PCI GART */
  1419. radeon_set_pcigart(dev_priv, 0);
  1420. } else
  1421. #endif
  1422. {
  1423. /* if we have an offset set from userspace */
  1424. if (dev_priv->pcigart_offset) {
  1425. dev_priv->gart_info.bus_addr =
  1426. dev_priv->pcigart_offset + dev_priv->fb_location;
  1427. dev_priv->gart_info.mapping.offset =
  1428. dev_priv->gart_info.bus_addr;
  1429. dev_priv->gart_info.mapping.size =
  1430. RADEON_PCIGART_TABLE_SIZE;
  1431. drm_core_ioremap(&dev_priv->gart_info.mapping, dev);
  1432. dev_priv->gart_info.addr =
  1433. dev_priv->gart_info.mapping.handle;
  1434. dev_priv->gart_info.is_pcie =
  1435. !!(dev_priv->flags & CHIP_IS_PCIE);
  1436. dev_priv->gart_info.gart_table_location =
  1437. DRM_ATI_GART_FB;
  1438. DRM_DEBUG("Setting phys_pci_gart to %p %08lX\n",
  1439. dev_priv->gart_info.addr,
  1440. dev_priv->pcigart_offset);
  1441. } else {
  1442. dev_priv->gart_info.gart_table_location =
  1443. DRM_ATI_GART_MAIN;
  1444. dev_priv->gart_info.addr = NULL;
  1445. dev_priv->gart_info.bus_addr = 0;
  1446. if (dev_priv->flags & CHIP_IS_PCIE) {
  1447. DRM_ERROR
  1448. ("Cannot use PCI Express without GART in FB memory\n");
  1449. radeon_do_cleanup_cp(dev);
  1450. return DRM_ERR(EINVAL);
  1451. }
  1452. }
  1453. if (!drm_ati_pcigart_init(dev, &dev_priv->gart_info)) {
  1454. DRM_ERROR("failed to init PCI GART!\n");
  1455. radeon_do_cleanup_cp(dev);
  1456. return DRM_ERR(ENOMEM);
  1457. }
  1458. /* Turn on PCI GART */
  1459. radeon_set_pcigart(dev_priv, 1);
  1460. }
  1461. radeon_cp_load_microcode(dev_priv);
  1462. radeon_cp_init_ring_buffer(dev, dev_priv);
  1463. dev_priv->last_buf = 0;
  1464. radeon_do_engine_reset(dev);
  1465. return 0;
  1466. }
  1467. static int radeon_do_cleanup_cp(drm_device_t * dev)
  1468. {
  1469. drm_radeon_private_t *dev_priv = dev->dev_private;
  1470. DRM_DEBUG("\n");
  1471. /* Make sure interrupts are disabled here because the uninstall ioctl
  1472. * may not have been called from userspace and after dev_private
  1473. * is freed, it's too late.
  1474. */
  1475. if (dev->irq_enabled)
  1476. drm_irq_uninstall(dev);
  1477. #if __OS_HAS_AGP
  1478. if (dev_priv->flags & CHIP_IS_AGP) {
  1479. if (dev_priv->cp_ring != NULL) {
  1480. drm_core_ioremapfree(dev_priv->cp_ring, dev);
  1481. dev_priv->cp_ring = NULL;
  1482. }
  1483. if (dev_priv->ring_rptr != NULL) {
  1484. drm_core_ioremapfree(dev_priv->ring_rptr, dev);
  1485. dev_priv->ring_rptr = NULL;
  1486. }
  1487. if (dev->agp_buffer_map != NULL) {
  1488. drm_core_ioremapfree(dev->agp_buffer_map, dev);
  1489. dev->agp_buffer_map = NULL;
  1490. }
  1491. } else
  1492. #endif
  1493. {
  1494. if (dev_priv->gart_info.bus_addr) {
  1495. /* Turn off PCI GART */
  1496. radeon_set_pcigart(dev_priv, 0);
  1497. if (!drm_ati_pcigart_cleanup(dev, &dev_priv->gart_info))
  1498. DRM_ERROR("failed to cleanup PCI GART!\n");
  1499. }
  1500. if (dev_priv->gart_info.gart_table_location == DRM_ATI_GART_FB)
  1501. {
  1502. drm_core_ioremapfree(&dev_priv->gart_info.mapping, dev);
  1503. dev_priv->gart_info.addr = NULL;
  1504. }
  1505. }
  1506. /* only clear to the start of flags */
  1507. memset(dev_priv, 0, offsetof(drm_radeon_private_t, flags));
  1508. return 0;
  1509. }
  1510. /* This code will reinit the Radeon CP hardware after a resume from disc.
  1511. * AFAIK, it would be very difficult to pickle the state at suspend time, so
  1512. * here we make sure that all Radeon hardware initialisation is re-done without
  1513. * affecting running applications.
  1514. *
  1515. * Charl P. Botha <http://cpbotha.net>
  1516. */
  1517. static int radeon_do_resume_cp(drm_device_t * dev)
  1518. {
  1519. drm_radeon_private_t *dev_priv = dev->dev_private;
  1520. if (!dev_priv) {
  1521. DRM_ERROR("Called with no initialization\n");
  1522. return DRM_ERR(EINVAL);
  1523. }
  1524. DRM_DEBUG("Starting radeon_do_resume_cp()\n");
  1525. #if __OS_HAS_AGP
  1526. if (dev_priv->flags & CHIP_IS_AGP) {
  1527. /* Turn off PCI GART */
  1528. radeon_set_pcigart(dev_priv, 0);
  1529. } else
  1530. #endif
  1531. {
  1532. /* Turn on PCI GART */
  1533. radeon_set_pcigart(dev_priv, 1);
  1534. }
  1535. radeon_cp_load_microcode(dev_priv);
  1536. radeon_cp_init_ring_buffer(dev, dev_priv);
  1537. radeon_do_engine_reset(dev);
  1538. DRM_DEBUG("radeon_do_resume_cp() complete\n");
  1539. return 0;
  1540. }
  1541. int radeon_cp_init(DRM_IOCTL_ARGS)
  1542. {
  1543. DRM_DEVICE;
  1544. drm_radeon_init_t init;
  1545. LOCK_TEST_WITH_RETURN(dev, filp);
  1546. DRM_COPY_FROM_USER_IOCTL(init, (drm_radeon_init_t __user *) data,
  1547. sizeof(init));
  1548. if (init.func == RADEON_INIT_R300_CP)
  1549. r300_init_reg_flags();
  1550. switch (init.func) {
  1551. case RADEON_INIT_CP:
  1552. case RADEON_INIT_R200_CP:
  1553. case RADEON_INIT_R300_CP:
  1554. return radeon_do_init_cp(dev, &init);
  1555. case RADEON_CLEANUP_CP:
  1556. return radeon_do_cleanup_cp(dev);
  1557. }
  1558. return DRM_ERR(EINVAL);
  1559. }
  1560. int radeon_cp_start(DRM_IOCTL_ARGS)
  1561. {
  1562. DRM_DEVICE;
  1563. drm_radeon_private_t *dev_priv = dev->dev_private;
  1564. DRM_DEBUG("\n");
  1565. LOCK_TEST_WITH_RETURN(dev, filp);
  1566. if (dev_priv->cp_running) {
  1567. DRM_DEBUG("%s while CP running\n", __FUNCTION__);
  1568. return 0;
  1569. }
  1570. if (dev_priv->cp_mode == RADEON_CSQ_PRIDIS_INDDIS) {
  1571. DRM_DEBUG("%s called with bogus CP mode (%d)\n",
  1572. __FUNCTION__, dev_priv->cp_mode);
  1573. return 0;
  1574. }
  1575. radeon_do_cp_start(dev_priv);
  1576. return 0;
  1577. }
  1578. /* Stop the CP. The engine must have been idled before calling this
  1579. * routine.
  1580. */
  1581. int radeon_cp_stop(DRM_IOCTL_ARGS)
  1582. {
  1583. DRM_DEVICE;
  1584. drm_radeon_private_t *dev_priv = dev->dev_private;
  1585. drm_radeon_cp_stop_t stop;
  1586. int ret;
  1587. DRM_DEBUG("\n");
  1588. LOCK_TEST_WITH_RETURN(dev, filp);
  1589. DRM_COPY_FROM_USER_IOCTL(stop, (drm_radeon_cp_stop_t __user *) data,
  1590. sizeof(stop));
  1591. if (!dev_priv->cp_running)
  1592. return 0;
  1593. /* Flush any pending CP commands. This ensures any outstanding
  1594. * commands are exectuted by the engine before we turn it off.
  1595. */
  1596. if (stop.flush) {
  1597. radeon_do_cp_flush(dev_priv);
  1598. }
  1599. /* If we fail to make the engine go idle, we return an error
  1600. * code so that the DRM ioctl wrapper can try again.
  1601. */
  1602. if (stop.idle) {
  1603. ret = radeon_do_cp_idle(dev_priv);
  1604. if (ret)
  1605. return ret;
  1606. }
  1607. /* Finally, we can turn off the CP. If the engine isn't idle,
  1608. * we will get some dropped triangles as they won't be fully
  1609. * rendered before the CP is shut down.
  1610. */
  1611. radeon_do_cp_stop(dev_priv);
  1612. /* Reset the engine */
  1613. radeon_do_engine_reset(dev);
  1614. return 0;
  1615. }
  1616. void radeon_do_release(drm_device_t * dev)
  1617. {
  1618. drm_radeon_private_t *dev_priv = dev->dev_private;
  1619. int i, ret;
  1620. if (dev_priv) {
  1621. if (dev_priv->cp_running) {
  1622. /* Stop the cp */
  1623. while ((ret = radeon_do_cp_idle(dev_priv)) != 0) {
  1624. DRM_DEBUG("radeon_do_cp_idle %d\n", ret);
  1625. #ifdef __linux__
  1626. schedule();
  1627. #else
  1628. tsleep(&ret, PZERO, "rdnrel", 1);
  1629. #endif
  1630. }
  1631. radeon_do_cp_stop(dev_priv);
  1632. radeon_do_engine_reset(dev);
  1633. }
  1634. /* Disable *all* interrupts */
  1635. if (dev_priv->mmio) /* remove this after permanent addmaps */
  1636. RADEON_WRITE(RADEON_GEN_INT_CNTL, 0);
  1637. if (dev_priv->mmio) { /* remove all surfaces */
  1638. for (i = 0; i < RADEON_MAX_SURFACES; i++) {
  1639. RADEON_WRITE(RADEON_SURFACE0_INFO + 16 * i, 0);
  1640. RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND +
  1641. 16 * i, 0);
  1642. RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND +
  1643. 16 * i, 0);
  1644. }
  1645. }
  1646. /* Free memory heap structures */
  1647. radeon_mem_takedown(&(dev_priv->gart_heap));
  1648. radeon_mem_takedown(&(dev_priv->fb_heap));
  1649. /* deallocate kernel resources */
  1650. radeon_do_cleanup_cp(dev);
  1651. }
  1652. }
  1653. /* Just reset the CP ring. Called as part of an X Server engine reset.
  1654. */
  1655. int radeon_cp_reset(DRM_IOCTL_ARGS)
  1656. {
  1657. DRM_DEVICE;
  1658. drm_radeon_private_t *dev_priv = dev->dev_private;
  1659. DRM_DEBUG("\n");
  1660. LOCK_TEST_WITH_RETURN(dev, filp);
  1661. if (!dev_priv) {
  1662. DRM_DEBUG("%s called before init done\n", __FUNCTION__);
  1663. return DRM_ERR(EINVAL);
  1664. }
  1665. radeon_do_cp_reset(dev_priv);
  1666. /* The CP is no longer running after an engine reset */
  1667. dev_priv->cp_running = 0;
  1668. return 0;
  1669. }
  1670. int radeon_cp_idle(DRM_IOCTL_ARGS)
  1671. {
  1672. DRM_DEVICE;
  1673. drm_radeon_private_t *dev_priv = dev->dev_private;
  1674. DRM_DEBUG("\n");
  1675. LOCK_TEST_WITH_RETURN(dev, filp);
  1676. return radeon_do_cp_idle(dev_priv);
  1677. }
  1678. /* Added by Charl P. Botha to call radeon_do_resume_cp().
  1679. */
  1680. int radeon_cp_resume(DRM_IOCTL_ARGS)
  1681. {
  1682. DRM_DEVICE;
  1683. return radeon_do_resume_cp(dev);
  1684. }
  1685. int radeon_engine_reset(DRM_IOCTL_ARGS)
  1686. {
  1687. DRM_DEVICE;
  1688. DRM_DEBUG("\n");
  1689. LOCK_TEST_WITH_RETURN(dev, filp);
  1690. return radeon_do_engine_reset(dev);
  1691. }
  1692. /* ================================================================
  1693. * Fullscreen mode
  1694. */
  1695. /* KW: Deprecated to say the least:
  1696. */
  1697. int radeon_fullscreen(DRM_IOCTL_ARGS)
  1698. {
  1699. return 0;
  1700. }
  1701. /* ================================================================
  1702. * Freelist management
  1703. */
  1704. /* Original comment: FIXME: ROTATE_BUFS is a hack to cycle through
  1705. * bufs until freelist code is used. Note this hides a problem with
  1706. * the scratch register * (used to keep track of last buffer
  1707. * completed) being written to before * the last buffer has actually
  1708. * completed rendering.
  1709. *
  1710. * KW: It's also a good way to find free buffers quickly.
  1711. *
  1712. * KW: Ideally this loop wouldn't exist, and freelist_get wouldn't
  1713. * sleep. However, bugs in older versions of radeon_accel.c mean that
  1714. * we essentially have to do this, else old clients will break.
  1715. *
  1716. * However, it does leave open a potential deadlock where all the
  1717. * buffers are held by other clients, which can't release them because
  1718. * they can't get the lock.
  1719. */
  1720. drm_buf_t *radeon_freelist_get(drm_device_t * dev)
  1721. {
  1722. drm_device_dma_t *dma = dev->dma;
  1723. drm_radeon_private_t *dev_priv = dev->dev_private;
  1724. drm_radeon_buf_priv_t *buf_priv;
  1725. drm_buf_t *buf;
  1726. int i, t;
  1727. int start;
  1728. if (++dev_priv->last_buf >= dma->buf_count)
  1729. dev_priv->last_buf = 0;
  1730. start = dev_priv->last_buf;
  1731. for (t = 0; t < dev_priv->usec_timeout; t++) {
  1732. u32 done_age = GET_SCRATCH(1);
  1733. DRM_DEBUG("done_age = %d\n", done_age);
  1734. for (i = start; i < dma->buf_count; i++) {
  1735. buf = dma->buflist[i];
  1736. buf_priv = buf->dev_private;
  1737. if (buf->filp == 0 || (buf->pending &&
  1738. buf_priv->age <= done_age)) {
  1739. dev_priv->stats.requested_bufs++;
  1740. buf->pending = 0;
  1741. return buf;
  1742. }
  1743. start = 0;
  1744. }
  1745. if (t) {
  1746. DRM_UDELAY(1);
  1747. dev_priv->stats.freelist_loops++;
  1748. }
  1749. }
  1750. DRM_DEBUG("returning NULL!\n");
  1751. return NULL;
  1752. }
  1753. #if 0
  1754. drm_buf_t *radeon_freelist_get(drm_device_t * dev)
  1755. {
  1756. drm_device_dma_t *dma = dev->dma;
  1757. drm_radeon_private_t *dev_priv = dev->dev_private;
  1758. drm_radeon_buf_priv_t *buf_priv;
  1759. drm_buf_t *buf;
  1760. int i, t;
  1761. int start;
  1762. u32 done_age = DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1));
  1763. if (++dev_priv->last_buf >= dma->buf_count)
  1764. dev_priv->last_buf = 0;
  1765. start = dev_priv->last_buf;
  1766. dev_priv->stats.freelist_loops++;
  1767. for (t = 0; t < 2; t++) {
  1768. for (i = start; i < dma->buf_count; i++) {
  1769. buf = dma->buflist[i];
  1770. buf_priv = buf->dev_private;
  1771. if (buf->filp == 0 || (buf->pending &&
  1772. buf_priv->age <= done_age)) {
  1773. dev_priv->stats.requested_bufs++;
  1774. buf->pending = 0;
  1775. return buf;
  1776. }
  1777. }
  1778. start = 0;
  1779. }
  1780. return NULL;
  1781. }
  1782. #endif
  1783. void radeon_freelist_reset(drm_device_t * dev)
  1784. {
  1785. drm_device_dma_t *dma = dev->dma;
  1786. drm_radeon_private_t *dev_priv = dev->dev_private;
  1787. int i;
  1788. dev_priv->last_buf = 0;
  1789. for (i = 0; i < dma->buf_count; i++) {
  1790. drm_buf_t *buf = dma->buflist[i];
  1791. drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
  1792. buf_priv->age = 0;
  1793. }
  1794. }
  1795. /* ================================================================
  1796. * CP command submission
  1797. */
  1798. int radeon_wait_ring(drm_radeon_private_t * dev_priv, int n)
  1799. {
  1800. drm_radeon_ring_buffer_t *ring = &dev_priv->ring;
  1801. int i;
  1802. u32 last_head = GET_RING_HEAD(dev_priv);
  1803. for (i = 0; i < dev_priv->usec_timeout; i++) {
  1804. u32 head = GET_RING_HEAD(dev_priv);
  1805. ring->space = (head - ring->tail) * sizeof(u32);
  1806. if (ring->space <= 0)
  1807. ring->space += ring->size;
  1808. if (ring->space > n)
  1809. return 0;
  1810. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  1811. if (head != last_head)
  1812. i = 0;
  1813. last_head = head;
  1814. DRM_UDELAY(1);
  1815. }
  1816. /* FIXME: This return value is ignored in the BEGIN_RING macro! */
  1817. #if RADEON_FIFO_DEBUG
  1818. radeon_status(dev_priv);
  1819. DRM_ERROR("failed!\n");
  1820. #endif
  1821. return DRM_ERR(EBUSY);
  1822. }
  1823. static int radeon_cp_get_buffers(DRMFILE filp, drm_device_t * dev,
  1824. drm_dma_t * d)
  1825. {
  1826. int i;
  1827. drm_buf_t *buf;
  1828. for (i = d->granted_count; i < d->request_count; i++) {
  1829. buf = radeon_freelist_get(dev);
  1830. if (!buf)
  1831. return DRM_ERR(EBUSY); /* NOTE: broken client */
  1832. buf->filp = filp;
  1833. if (DRM_COPY_TO_USER(&d->request_indices[i], &buf->idx,
  1834. sizeof(buf->idx)))
  1835. return DRM_ERR(EFAULT);
  1836. if (DRM_COPY_TO_USER(&d->request_sizes[i], &buf->total,
  1837. sizeof(buf->total)))
  1838. return DRM_ERR(EFAULT);
  1839. d->granted_count++;
  1840. }
  1841. return 0;
  1842. }
  1843. int radeon_cp_buffers(DRM_IOCTL_ARGS)
  1844. {
  1845. DRM_DEVICE;
  1846. drm_device_dma_t *dma = dev->dma;
  1847. int ret = 0;
  1848. drm_dma_t __user *argp = (void __user *)data;
  1849. drm_dma_t d;
  1850. LOCK_TEST_WITH_RETURN(dev, filp);
  1851. DRM_COPY_FROM_USER_IOCTL(d, argp, sizeof(d));
  1852. /* Please don't send us buffers.
  1853. */
  1854. if (d.send_count != 0) {
  1855. DRM_ERROR("Process %d trying to send %d buffers via drmDMA\n",
  1856. DRM_CURRENTPID, d.send_count);
  1857. return DRM_ERR(EINVAL);
  1858. }
  1859. /* We'll send you buffers.
  1860. */
  1861. if (d.request_count < 0 || d.request_count > dma->buf_count) {
  1862. DRM_ERROR("Process %d trying to get %d buffers (of %d max)\n",
  1863. DRM_CURRENTPID, d.request_count, dma->buf_count);
  1864. return DRM_ERR(EINVAL);
  1865. }
  1866. d.granted_count = 0;
  1867. if (d.request_count) {
  1868. ret = radeon_cp_get_buffers(filp, dev, &d);
  1869. }
  1870. DRM_COPY_TO_USER_IOCTL(argp, d, sizeof(d));
  1871. return ret;
  1872. }
  1873. int radeon_driver_load(struct drm_device *dev, unsigned long flags)
  1874. {
  1875. drm_radeon_private_t *dev_priv;
  1876. int ret = 0;
  1877. dev_priv = drm_alloc(sizeof(drm_radeon_private_t), DRM_MEM_DRIVER);
  1878. if (dev_priv == NULL)
  1879. return DRM_ERR(ENOMEM);
  1880. memset(dev_priv, 0, sizeof(drm_radeon_private_t));
  1881. dev->dev_private = (void *)dev_priv;
  1882. dev_priv->flags = flags;
  1883. switch (flags & CHIP_FAMILY_MASK) {
  1884. case CHIP_R100:
  1885. case CHIP_RV200:
  1886. case CHIP_R200:
  1887. case CHIP_R300:
  1888. case CHIP_R420:
  1889. dev_priv->flags |= CHIP_HAS_HIERZ;
  1890. break;
  1891. default:
  1892. /* all other chips have no hierarchical z buffer */
  1893. break;
  1894. }
  1895. if (drm_device_is_agp(dev))
  1896. dev_priv->flags |= CHIP_IS_AGP;
  1897. if (drm_device_is_pcie(dev))
  1898. dev_priv->flags |= CHIP_IS_PCIE;
  1899. DRM_DEBUG("%s card detected\n",
  1900. ((dev_priv->flags & CHIP_IS_AGP) ? "AGP" : (((dev_priv->flags & CHIP_IS_PCIE) ? "PCIE" : "PCI"))));
  1901. return ret;
  1902. }
  1903. /* Create mappings for registers and framebuffer so userland doesn't necessarily
  1904. * have to find them.
  1905. */
  1906. int radeon_driver_firstopen(struct drm_device *dev)
  1907. {
  1908. int ret;
  1909. drm_local_map_t *map;
  1910. drm_radeon_private_t *dev_priv = dev->dev_private;
  1911. ret = drm_addmap(dev, drm_get_resource_start(dev, 2),
  1912. drm_get_resource_len(dev, 2), _DRM_REGISTERS,
  1913. _DRM_READ_ONLY, &dev_priv->mmio);
  1914. if (ret != 0)
  1915. return ret;
  1916. ret = drm_addmap(dev, drm_get_resource_start(dev, 0),
  1917. drm_get_resource_len(dev, 0), _DRM_FRAME_BUFFER,
  1918. _DRM_WRITE_COMBINING, &map);
  1919. if (ret != 0)
  1920. return ret;
  1921. return 0;
  1922. }
  1923. int radeon_driver_unload(struct drm_device *dev)
  1924. {
  1925. drm_radeon_private_t *dev_priv = dev->dev_private;
  1926. DRM_DEBUG("\n");
  1927. drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
  1928. dev->dev_private = NULL;
  1929. return 0;
  1930. }