radeon_cp.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061
  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. #define RADEON_FIFO_DEBUG 0
  35. static int radeon_do_cleanup_cp( drm_device_t *dev );
  36. /* CP microcode (from ATI) */
  37. static u32 R200_cp_microcode[][2] = {
  38. { 0x21007000, 0000000000 },
  39. { 0x20007000, 0000000000 },
  40. { 0x000000ab, 0x00000004 },
  41. { 0x000000af, 0x00000004 },
  42. { 0x66544a49, 0000000000 },
  43. { 0x49494174, 0000000000 },
  44. { 0x54517d83, 0000000000 },
  45. { 0x498d8b64, 0000000000 },
  46. { 0x49494949, 0000000000 },
  47. { 0x49da493c, 0000000000 },
  48. { 0x49989898, 0000000000 },
  49. { 0xd34949d5, 0000000000 },
  50. { 0x9dc90e11, 0000000000 },
  51. { 0xce9b9b9b, 0000000000 },
  52. { 0x000f0000, 0x00000016 },
  53. { 0x352e232c, 0000000000 },
  54. { 0x00000013, 0x00000004 },
  55. { 0x000f0000, 0x00000016 },
  56. { 0x352e272c, 0000000000 },
  57. { 0x000f0001, 0x00000016 },
  58. { 0x3239362f, 0000000000 },
  59. { 0x000077ef, 0x00000002 },
  60. { 0x00061000, 0x00000002 },
  61. { 0x00000020, 0x0000001a },
  62. { 0x00004000, 0x0000001e },
  63. { 0x00061000, 0x00000002 },
  64. { 0x00000020, 0x0000001a },
  65. { 0x00004000, 0x0000001e },
  66. { 0x00061000, 0x00000002 },
  67. { 0x00000020, 0x0000001a },
  68. { 0x00004000, 0x0000001e },
  69. { 0x00000016, 0x00000004 },
  70. { 0x0003802a, 0x00000002 },
  71. { 0x040067e0, 0x00000002 },
  72. { 0x00000016, 0x00000004 },
  73. { 0x000077e0, 0x00000002 },
  74. { 0x00065000, 0x00000002 },
  75. { 0x000037e1, 0x00000002 },
  76. { 0x040067e1, 0x00000006 },
  77. { 0x000077e0, 0x00000002 },
  78. { 0x000077e1, 0x00000002 },
  79. { 0x000077e1, 0x00000006 },
  80. { 0xffffffff, 0000000000 },
  81. { 0x10000000, 0000000000 },
  82. { 0x0003802a, 0x00000002 },
  83. { 0x040067e0, 0x00000006 },
  84. { 0x00007675, 0x00000002 },
  85. { 0x00007676, 0x00000002 },
  86. { 0x00007677, 0x00000002 },
  87. { 0x00007678, 0x00000006 },
  88. { 0x0003802b, 0x00000002 },
  89. { 0x04002676, 0x00000002 },
  90. { 0x00007677, 0x00000002 },
  91. { 0x00007678, 0x00000006 },
  92. { 0x0000002e, 0x00000018 },
  93. { 0x0000002e, 0x00000018 },
  94. { 0000000000, 0x00000006 },
  95. { 0x0000002f, 0x00000018 },
  96. { 0x0000002f, 0x00000018 },
  97. { 0000000000, 0x00000006 },
  98. { 0x01605000, 0x00000002 },
  99. { 0x00065000, 0x00000002 },
  100. { 0x00098000, 0x00000002 },
  101. { 0x00061000, 0x00000002 },
  102. { 0x64c0603d, 0x00000004 },
  103. { 0x00080000, 0x00000016 },
  104. { 0000000000, 0000000000 },
  105. { 0x0400251d, 0x00000002 },
  106. { 0x00007580, 0x00000002 },
  107. { 0x00067581, 0x00000002 },
  108. { 0x04002580, 0x00000002 },
  109. { 0x00067581, 0x00000002 },
  110. { 0x00000046, 0x00000004 },
  111. { 0x00005000, 0000000000 },
  112. { 0x00061000, 0x00000002 },
  113. { 0x0000750e, 0x00000002 },
  114. { 0x00019000, 0x00000002 },
  115. { 0x00011055, 0x00000014 },
  116. { 0x00000055, 0x00000012 },
  117. { 0x0400250f, 0x00000002 },
  118. { 0x0000504a, 0x00000004 },
  119. { 0x00007565, 0x00000002 },
  120. { 0x00007566, 0x00000002 },
  121. { 0x00000051, 0x00000004 },
  122. { 0x01e655b4, 0x00000002 },
  123. { 0x4401b0dc, 0x00000002 },
  124. { 0x01c110dc, 0x00000002 },
  125. { 0x2666705d, 0x00000018 },
  126. { 0x040c2565, 0x00000002 },
  127. { 0x0000005d, 0x00000018 },
  128. { 0x04002564, 0x00000002 },
  129. { 0x00007566, 0x00000002 },
  130. { 0x00000054, 0x00000004 },
  131. { 0x00401060, 0x00000008 },
  132. { 0x00101000, 0x00000002 },
  133. { 0x000d80ff, 0x00000002 },
  134. { 0x00800063, 0x00000008 },
  135. { 0x000f9000, 0x00000002 },
  136. { 0x000e00ff, 0x00000002 },
  137. { 0000000000, 0x00000006 },
  138. { 0x00000080, 0x00000018 },
  139. { 0x00000054, 0x00000004 },
  140. { 0x00007576, 0x00000002 },
  141. { 0x00065000, 0x00000002 },
  142. { 0x00009000, 0x00000002 },
  143. { 0x00041000, 0x00000002 },
  144. { 0x0c00350e, 0x00000002 },
  145. { 0x00049000, 0x00000002 },
  146. { 0x00051000, 0x00000002 },
  147. { 0x01e785f8, 0x00000002 },
  148. { 0x00200000, 0x00000002 },
  149. { 0x00600073, 0x0000000c },
  150. { 0x00007563, 0x00000002 },
  151. { 0x006075f0, 0x00000021 },
  152. { 0x20007068, 0x00000004 },
  153. { 0x00005068, 0x00000004 },
  154. { 0x00007576, 0x00000002 },
  155. { 0x00007577, 0x00000002 },
  156. { 0x0000750e, 0x00000002 },
  157. { 0x0000750f, 0x00000002 },
  158. { 0x00a05000, 0x00000002 },
  159. { 0x00600076, 0x0000000c },
  160. { 0x006075f0, 0x00000021 },
  161. { 0x000075f8, 0x00000002 },
  162. { 0x00000076, 0x00000004 },
  163. { 0x000a750e, 0x00000002 },
  164. { 0x0020750f, 0x00000002 },
  165. { 0x00600079, 0x00000004 },
  166. { 0x00007570, 0x00000002 },
  167. { 0x00007571, 0x00000002 },
  168. { 0x00007572, 0x00000006 },
  169. { 0x00005000, 0x00000002 },
  170. { 0x00a05000, 0x00000002 },
  171. { 0x00007568, 0x00000002 },
  172. { 0x00061000, 0x00000002 },
  173. { 0x00000084, 0x0000000c },
  174. { 0x00058000, 0x00000002 },
  175. { 0x0c607562, 0x00000002 },
  176. { 0x00000086, 0x00000004 },
  177. { 0x00600085, 0x00000004 },
  178. { 0x400070dd, 0000000000 },
  179. { 0x000380dd, 0x00000002 },
  180. { 0x00000093, 0x0000001c },
  181. { 0x00065095, 0x00000018 },
  182. { 0x040025bb, 0x00000002 },
  183. { 0x00061096, 0x00000018 },
  184. { 0x040075bc, 0000000000 },
  185. { 0x000075bb, 0x00000002 },
  186. { 0x000075bc, 0000000000 },
  187. { 0x00090000, 0x00000006 },
  188. { 0x00090000, 0x00000002 },
  189. { 0x000d8002, 0x00000006 },
  190. { 0x00005000, 0x00000002 },
  191. { 0x00007821, 0x00000002 },
  192. { 0x00007800, 0000000000 },
  193. { 0x00007821, 0x00000002 },
  194. { 0x00007800, 0000000000 },
  195. { 0x01665000, 0x00000002 },
  196. { 0x000a0000, 0x00000002 },
  197. { 0x000671cc, 0x00000002 },
  198. { 0x0286f1cd, 0x00000002 },
  199. { 0x000000a3, 0x00000010 },
  200. { 0x21007000, 0000000000 },
  201. { 0x000000aa, 0x0000001c },
  202. { 0x00065000, 0x00000002 },
  203. { 0x000a0000, 0x00000002 },
  204. { 0x00061000, 0x00000002 },
  205. { 0x000b0000, 0x00000002 },
  206. { 0x38067000, 0x00000002 },
  207. { 0x000a00a6, 0x00000004 },
  208. { 0x20007000, 0000000000 },
  209. { 0x01200000, 0x00000002 },
  210. { 0x20077000, 0x00000002 },
  211. { 0x01200000, 0x00000002 },
  212. { 0x20007000, 0000000000 },
  213. { 0x00061000, 0x00000002 },
  214. { 0x0120751b, 0x00000002 },
  215. { 0x8040750a, 0x00000002 },
  216. { 0x8040750b, 0x00000002 },
  217. { 0x00110000, 0x00000002 },
  218. { 0x000380dd, 0x00000002 },
  219. { 0x000000bd, 0x0000001c },
  220. { 0x00061096, 0x00000018 },
  221. { 0x844075bd, 0x00000002 },
  222. { 0x00061095, 0x00000018 },
  223. { 0x840075bb, 0x00000002 },
  224. { 0x00061096, 0x00000018 },
  225. { 0x844075bc, 0x00000002 },
  226. { 0x000000c0, 0x00000004 },
  227. { 0x804075bd, 0x00000002 },
  228. { 0x800075bb, 0x00000002 },
  229. { 0x804075bc, 0x00000002 },
  230. { 0x00108000, 0x00000002 },
  231. { 0x01400000, 0x00000002 },
  232. { 0x006000c4, 0x0000000c },
  233. { 0x20c07000, 0x00000020 },
  234. { 0x000000c6, 0x00000012 },
  235. { 0x00800000, 0x00000006 },
  236. { 0x0080751d, 0x00000006 },
  237. { 0x000025bb, 0x00000002 },
  238. { 0x000040c0, 0x00000004 },
  239. { 0x0000775c, 0x00000002 },
  240. { 0x00a05000, 0x00000002 },
  241. { 0x00661000, 0x00000002 },
  242. { 0x0460275d, 0x00000020 },
  243. { 0x00004000, 0000000000 },
  244. { 0x00007999, 0x00000002 },
  245. { 0x00a05000, 0x00000002 },
  246. { 0x00661000, 0x00000002 },
  247. { 0x0460299b, 0x00000020 },
  248. { 0x00004000, 0000000000 },
  249. { 0x01e00830, 0x00000002 },
  250. { 0x21007000, 0000000000 },
  251. { 0x00005000, 0x00000002 },
  252. { 0x00038042, 0x00000002 },
  253. { 0x040025e0, 0x00000002 },
  254. { 0x000075e1, 0000000000 },
  255. { 0x00000001, 0000000000 },
  256. { 0x000380d9, 0x00000002 },
  257. { 0x04007394, 0000000000 },
  258. { 0000000000, 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. };
  295. static u32 radeon_cp_microcode[][2] = {
  296. { 0x21007000, 0000000000 },
  297. { 0x20007000, 0000000000 },
  298. { 0x000000b4, 0x00000004 },
  299. { 0x000000b8, 0x00000004 },
  300. { 0x6f5b4d4c, 0000000000 },
  301. { 0x4c4c427f, 0000000000 },
  302. { 0x5b568a92, 0000000000 },
  303. { 0x4ca09c6d, 0000000000 },
  304. { 0xad4c4c4c, 0000000000 },
  305. { 0x4ce1af3d, 0000000000 },
  306. { 0xd8afafaf, 0000000000 },
  307. { 0xd64c4cdc, 0000000000 },
  308. { 0x4cd10d10, 0000000000 },
  309. { 0x000f0000, 0x00000016 },
  310. { 0x362f242d, 0000000000 },
  311. { 0x00000012, 0x00000004 },
  312. { 0x000f0000, 0x00000016 },
  313. { 0x362f282d, 0000000000 },
  314. { 0x000380e7, 0x00000002 },
  315. { 0x04002c97, 0x00000002 },
  316. { 0x000f0001, 0x00000016 },
  317. { 0x333a3730, 0000000000 },
  318. { 0x000077ef, 0x00000002 },
  319. { 0x00061000, 0x00000002 },
  320. { 0x00000021, 0x0000001a },
  321. { 0x00004000, 0x0000001e },
  322. { 0x00061000, 0x00000002 },
  323. { 0x00000021, 0x0000001a },
  324. { 0x00004000, 0x0000001e },
  325. { 0x00061000, 0x00000002 },
  326. { 0x00000021, 0x0000001a },
  327. { 0x00004000, 0x0000001e },
  328. { 0x00000017, 0x00000004 },
  329. { 0x0003802b, 0x00000002 },
  330. { 0x040067e0, 0x00000002 },
  331. { 0x00000017, 0x00000004 },
  332. { 0x000077e0, 0x00000002 },
  333. { 0x00065000, 0x00000002 },
  334. { 0x000037e1, 0x00000002 },
  335. { 0x040067e1, 0x00000006 },
  336. { 0x000077e0, 0x00000002 },
  337. { 0x000077e1, 0x00000002 },
  338. { 0x000077e1, 0x00000006 },
  339. { 0xffffffff, 0000000000 },
  340. { 0x10000000, 0000000000 },
  341. { 0x0003802b, 0x00000002 },
  342. { 0x040067e0, 0x00000006 },
  343. { 0x00007675, 0x00000002 },
  344. { 0x00007676, 0x00000002 },
  345. { 0x00007677, 0x00000002 },
  346. { 0x00007678, 0x00000006 },
  347. { 0x0003802c, 0x00000002 },
  348. { 0x04002676, 0x00000002 },
  349. { 0x00007677, 0x00000002 },
  350. { 0x00007678, 0x00000006 },
  351. { 0x0000002f, 0x00000018 },
  352. { 0x0000002f, 0x00000018 },
  353. { 0000000000, 0x00000006 },
  354. { 0x00000030, 0x00000018 },
  355. { 0x00000030, 0x00000018 },
  356. { 0000000000, 0x00000006 },
  357. { 0x01605000, 0x00000002 },
  358. { 0x00065000, 0x00000002 },
  359. { 0x00098000, 0x00000002 },
  360. { 0x00061000, 0x00000002 },
  361. { 0x64c0603e, 0x00000004 },
  362. { 0x000380e6, 0x00000002 },
  363. { 0x040025c5, 0x00000002 },
  364. { 0x00080000, 0x00000016 },
  365. { 0000000000, 0000000000 },
  366. { 0x0400251d, 0x00000002 },
  367. { 0x00007580, 0x00000002 },
  368. { 0x00067581, 0x00000002 },
  369. { 0x04002580, 0x00000002 },
  370. { 0x00067581, 0x00000002 },
  371. { 0x00000049, 0x00000004 },
  372. { 0x00005000, 0000000000 },
  373. { 0x000380e6, 0x00000002 },
  374. { 0x040025c5, 0x00000002 },
  375. { 0x00061000, 0x00000002 },
  376. { 0x0000750e, 0x00000002 },
  377. { 0x00019000, 0x00000002 },
  378. { 0x00011055, 0x00000014 },
  379. { 0x00000055, 0x00000012 },
  380. { 0x0400250f, 0x00000002 },
  381. { 0x0000504f, 0x00000004 },
  382. { 0x000380e6, 0x00000002 },
  383. { 0x040025c5, 0x00000002 },
  384. { 0x00007565, 0x00000002 },
  385. { 0x00007566, 0x00000002 },
  386. { 0x00000058, 0x00000004 },
  387. { 0x000380e6, 0x00000002 },
  388. { 0x040025c5, 0x00000002 },
  389. { 0x01e655b4, 0x00000002 },
  390. { 0x4401b0e4, 0x00000002 },
  391. { 0x01c110e4, 0x00000002 },
  392. { 0x26667066, 0x00000018 },
  393. { 0x040c2565, 0x00000002 },
  394. { 0x00000066, 0x00000018 },
  395. { 0x04002564, 0x00000002 },
  396. { 0x00007566, 0x00000002 },
  397. { 0x0000005d, 0x00000004 },
  398. { 0x00401069, 0x00000008 },
  399. { 0x00101000, 0x00000002 },
  400. { 0x000d80ff, 0x00000002 },
  401. { 0x0080006c, 0x00000008 },
  402. { 0x000f9000, 0x00000002 },
  403. { 0x000e00ff, 0x00000002 },
  404. { 0000000000, 0x00000006 },
  405. { 0x0000008f, 0x00000018 },
  406. { 0x0000005b, 0x00000004 },
  407. { 0x000380e6, 0x00000002 },
  408. { 0x040025c5, 0x00000002 },
  409. { 0x00007576, 0x00000002 },
  410. { 0x00065000, 0x00000002 },
  411. { 0x00009000, 0x00000002 },
  412. { 0x00041000, 0x00000002 },
  413. { 0x0c00350e, 0x00000002 },
  414. { 0x00049000, 0x00000002 },
  415. { 0x00051000, 0x00000002 },
  416. { 0x01e785f8, 0x00000002 },
  417. { 0x00200000, 0x00000002 },
  418. { 0x0060007e, 0x0000000c },
  419. { 0x00007563, 0x00000002 },
  420. { 0x006075f0, 0x00000021 },
  421. { 0x20007073, 0x00000004 },
  422. { 0x00005073, 0x00000004 },
  423. { 0x000380e6, 0x00000002 },
  424. { 0x040025c5, 0x00000002 },
  425. { 0x00007576, 0x00000002 },
  426. { 0x00007577, 0x00000002 },
  427. { 0x0000750e, 0x00000002 },
  428. { 0x0000750f, 0x00000002 },
  429. { 0x00a05000, 0x00000002 },
  430. { 0x00600083, 0x0000000c },
  431. { 0x006075f0, 0x00000021 },
  432. { 0x000075f8, 0x00000002 },
  433. { 0x00000083, 0x00000004 },
  434. { 0x000a750e, 0x00000002 },
  435. { 0x000380e6, 0x00000002 },
  436. { 0x040025c5, 0x00000002 },
  437. { 0x0020750f, 0x00000002 },
  438. { 0x00600086, 0x00000004 },
  439. { 0x00007570, 0x00000002 },
  440. { 0x00007571, 0x00000002 },
  441. { 0x00007572, 0x00000006 },
  442. { 0x000380e6, 0x00000002 },
  443. { 0x040025c5, 0x00000002 },
  444. { 0x00005000, 0x00000002 },
  445. { 0x00a05000, 0x00000002 },
  446. { 0x00007568, 0x00000002 },
  447. { 0x00061000, 0x00000002 },
  448. { 0x00000095, 0x0000000c },
  449. { 0x00058000, 0x00000002 },
  450. { 0x0c607562, 0x00000002 },
  451. { 0x00000097, 0x00000004 },
  452. { 0x000380e6, 0x00000002 },
  453. { 0x040025c5, 0x00000002 },
  454. { 0x00600096, 0x00000004 },
  455. { 0x400070e5, 0000000000 },
  456. { 0x000380e6, 0x00000002 },
  457. { 0x040025c5, 0x00000002 },
  458. { 0x000380e5, 0x00000002 },
  459. { 0x000000a8, 0x0000001c },
  460. { 0x000650aa, 0x00000018 },
  461. { 0x040025bb, 0x00000002 },
  462. { 0x000610ab, 0x00000018 },
  463. { 0x040075bc, 0000000000 },
  464. { 0x000075bb, 0x00000002 },
  465. { 0x000075bc, 0000000000 },
  466. { 0x00090000, 0x00000006 },
  467. { 0x00090000, 0x00000002 },
  468. { 0x000d8002, 0x00000006 },
  469. { 0x00007832, 0x00000002 },
  470. { 0x00005000, 0x00000002 },
  471. { 0x000380e7, 0x00000002 },
  472. { 0x04002c97, 0x00000002 },
  473. { 0x00007820, 0x00000002 },
  474. { 0x00007821, 0x00000002 },
  475. { 0x00007800, 0000000000 },
  476. { 0x01200000, 0x00000002 },
  477. { 0x20077000, 0x00000002 },
  478. { 0x01200000, 0x00000002 },
  479. { 0x20007000, 0x00000002 },
  480. { 0x00061000, 0x00000002 },
  481. { 0x0120751b, 0x00000002 },
  482. { 0x8040750a, 0x00000002 },
  483. { 0x8040750b, 0x00000002 },
  484. { 0x00110000, 0x00000002 },
  485. { 0x000380e5, 0x00000002 },
  486. { 0x000000c6, 0x0000001c },
  487. { 0x000610ab, 0x00000018 },
  488. { 0x844075bd, 0x00000002 },
  489. { 0x000610aa, 0x00000018 },
  490. { 0x840075bb, 0x00000002 },
  491. { 0x000610ab, 0x00000018 },
  492. { 0x844075bc, 0x00000002 },
  493. { 0x000000c9, 0x00000004 },
  494. { 0x804075bd, 0x00000002 },
  495. { 0x800075bb, 0x00000002 },
  496. { 0x804075bc, 0x00000002 },
  497. { 0x00108000, 0x00000002 },
  498. { 0x01400000, 0x00000002 },
  499. { 0x006000cd, 0x0000000c },
  500. { 0x20c07000, 0x00000020 },
  501. { 0x000000cf, 0x00000012 },
  502. { 0x00800000, 0x00000006 },
  503. { 0x0080751d, 0x00000006 },
  504. { 0000000000, 0000000000 },
  505. { 0x0000775c, 0x00000002 },
  506. { 0x00a05000, 0x00000002 },
  507. { 0x00661000, 0x00000002 },
  508. { 0x0460275d, 0x00000020 },
  509. { 0x00004000, 0000000000 },
  510. { 0x01e00830, 0x00000002 },
  511. { 0x21007000, 0000000000 },
  512. { 0x6464614d, 0000000000 },
  513. { 0x69687420, 0000000000 },
  514. { 0x00000073, 0000000000 },
  515. { 0000000000, 0000000000 },
  516. { 0x00005000, 0x00000002 },
  517. { 0x000380d0, 0x00000002 },
  518. { 0x040025e0, 0x00000002 },
  519. { 0x000075e1, 0000000000 },
  520. { 0x00000001, 0000000000 },
  521. { 0x000380e0, 0x00000002 },
  522. { 0x04002394, 0x00000002 },
  523. { 0x00005000, 0000000000 },
  524. { 0000000000, 0000000000 },
  525. { 0000000000, 0000000000 },
  526. { 0x00000008, 0000000000 },
  527. { 0x00000004, 0000000000 },
  528. { 0000000000, 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. };
  553. static u32 R300_cp_microcode[][2] = {
  554. { 0x4200e000, 0000000000 },
  555. { 0x4000e000, 0000000000 },
  556. { 0x000000af, 0x00000008 },
  557. { 0x000000b3, 0x00000008 },
  558. { 0x6c5a504f, 0000000000 },
  559. { 0x4f4f497a, 0000000000 },
  560. { 0x5a578288, 0000000000 },
  561. { 0x4f91906a, 0000000000 },
  562. { 0x4f4f4f4f, 0000000000 },
  563. { 0x4fe24f44, 0000000000 },
  564. { 0x4f9c9c9c, 0000000000 },
  565. { 0xdc4f4fde, 0000000000 },
  566. { 0xa1cd4f4f, 0000000000 },
  567. { 0xd29d9d9d, 0000000000 },
  568. { 0x4f0f9fd7, 0000000000 },
  569. { 0x000ca000, 0x00000004 },
  570. { 0x000d0012, 0x00000038 },
  571. { 0x0000e8b4, 0x00000004 },
  572. { 0x000d0014, 0x00000038 },
  573. { 0x0000e8b6, 0x00000004 },
  574. { 0x000d0016, 0x00000038 },
  575. { 0x0000e854, 0x00000004 },
  576. { 0x000d0018, 0x00000038 },
  577. { 0x0000e855, 0x00000004 },
  578. { 0x000d001a, 0x00000038 },
  579. { 0x0000e856, 0x00000004 },
  580. { 0x000d001c, 0x00000038 },
  581. { 0x0000e857, 0x00000004 },
  582. { 0x000d001e, 0x00000038 },
  583. { 0x0000e824, 0x00000004 },
  584. { 0x000d0020, 0x00000038 },
  585. { 0x0000e825, 0x00000004 },
  586. { 0x000d0022, 0x00000038 },
  587. { 0x0000e830, 0x00000004 },
  588. { 0x000d0024, 0x00000038 },
  589. { 0x0000f0c0, 0x00000004 },
  590. { 0x000d0026, 0x00000038 },
  591. { 0x0000f0c1, 0x00000004 },
  592. { 0x000d0028, 0x00000038 },
  593. { 0x0000f041, 0x00000004 },
  594. { 0x000d002a, 0x00000038 },
  595. { 0x0000f184, 0x00000004 },
  596. { 0x000d002c, 0x00000038 },
  597. { 0x0000f185, 0x00000004 },
  598. { 0x000d002e, 0x00000038 },
  599. { 0x0000f186, 0x00000004 },
  600. { 0x000d0030, 0x00000038 },
  601. { 0x0000f187, 0x00000004 },
  602. { 0x000d0032, 0x00000038 },
  603. { 0x0000f180, 0x00000004 },
  604. { 0x000d0034, 0x00000038 },
  605. { 0x0000f393, 0x00000004 },
  606. { 0x000d0036, 0x00000038 },
  607. { 0x0000f38a, 0x00000004 },
  608. { 0x000d0038, 0x00000038 },
  609. { 0x0000f38e, 0x00000004 },
  610. { 0x0000e821, 0x00000004 },
  611. { 0x0140a000, 0x00000004 },
  612. { 0x00000043, 0x00000018 },
  613. { 0x00cce800, 0x00000004 },
  614. { 0x001b0001, 0x00000004 },
  615. { 0x08004800, 0x00000004 },
  616. { 0x001b0001, 0x00000004 },
  617. { 0x08004800, 0x00000004 },
  618. { 0x001b0001, 0x00000004 },
  619. { 0x08004800, 0x00000004 },
  620. { 0x0000003a, 0x00000008 },
  621. { 0x0000a000, 0000000000 },
  622. { 0x02c0a000, 0x00000004 },
  623. { 0x000ca000, 0x00000004 },
  624. { 0x00130000, 0x00000004 },
  625. { 0x000c2000, 0x00000004 },
  626. { 0xc980c045, 0x00000008 },
  627. { 0x2000451d, 0x00000004 },
  628. { 0x0000e580, 0x00000004 },
  629. { 0x000ce581, 0x00000004 },
  630. { 0x08004580, 0x00000004 },
  631. { 0x000ce581, 0x00000004 },
  632. { 0x0000004c, 0x00000008 },
  633. { 0x0000a000, 0000000000 },
  634. { 0x000c2000, 0x00000004 },
  635. { 0x0000e50e, 0x00000004 },
  636. { 0x00032000, 0x00000004 },
  637. { 0x00022056, 0x00000028 },
  638. { 0x00000056, 0x00000024 },
  639. { 0x0800450f, 0x00000004 },
  640. { 0x0000a050, 0x00000008 },
  641. { 0x0000e565, 0x00000004 },
  642. { 0x0000e566, 0x00000004 },
  643. { 0x00000057, 0x00000008 },
  644. { 0x03cca5b4, 0x00000004 },
  645. { 0x05432000, 0x00000004 },
  646. { 0x00022000, 0x00000004 },
  647. { 0x4ccce063, 0x00000030 },
  648. { 0x08274565, 0x00000004 },
  649. { 0x00000063, 0x00000030 },
  650. { 0x08004564, 0x00000004 },
  651. { 0x0000e566, 0x00000004 },
  652. { 0x0000005a, 0x00000008 },
  653. { 0x00802066, 0x00000010 },
  654. { 0x00202000, 0x00000004 },
  655. { 0x001b00ff, 0x00000004 },
  656. { 0x01000069, 0x00000010 },
  657. { 0x001f2000, 0x00000004 },
  658. { 0x001c00ff, 0x00000004 },
  659. { 0000000000, 0x0000000c },
  660. { 0x00000085, 0x00000030 },
  661. { 0x0000005a, 0x00000008 },
  662. { 0x0000e576, 0x00000004 },
  663. { 0x000ca000, 0x00000004 },
  664. { 0x00012000, 0x00000004 },
  665. { 0x00082000, 0x00000004 },
  666. { 0x1800650e, 0x00000004 },
  667. { 0x00092000, 0x00000004 },
  668. { 0x000a2000, 0x00000004 },
  669. { 0x000f0000, 0x00000004 },
  670. { 0x00400000, 0x00000004 },
  671. { 0x00000079, 0x00000018 },
  672. { 0x0000e563, 0x00000004 },
  673. { 0x00c0e5f9, 0x000000c2 },
  674. { 0x0000006e, 0x00000008 },
  675. { 0x0000a06e, 0x00000008 },
  676. { 0x0000e576, 0x00000004 },
  677. { 0x0000e577, 0x00000004 },
  678. { 0x0000e50e, 0x00000004 },
  679. { 0x0000e50f, 0x00000004 },
  680. { 0x0140a000, 0x00000004 },
  681. { 0x0000007c, 0x00000018 },
  682. { 0x00c0e5f9, 0x000000c2 },
  683. { 0x0000007c, 0x00000008 },
  684. { 0x0014e50e, 0x00000004 },
  685. { 0x0040e50f, 0x00000004 },
  686. { 0x00c0007f, 0x00000008 },
  687. { 0x0000e570, 0x00000004 },
  688. { 0x0000e571, 0x00000004 },
  689. { 0x0000e572, 0x0000000c },
  690. { 0x0000a000, 0x00000004 },
  691. { 0x0140a000, 0x00000004 },
  692. { 0x0000e568, 0x00000004 },
  693. { 0x000c2000, 0x00000004 },
  694. { 0x00000089, 0x00000018 },
  695. { 0x000b0000, 0x00000004 },
  696. { 0x18c0e562, 0x00000004 },
  697. { 0x0000008b, 0x00000008 },
  698. { 0x00c0008a, 0x00000008 },
  699. { 0x000700e4, 0x00000004 },
  700. { 0x00000097, 0x00000038 },
  701. { 0x000ca099, 0x00000030 },
  702. { 0x080045bb, 0x00000004 },
  703. { 0x000c209a, 0x00000030 },
  704. { 0x0800e5bc, 0000000000 },
  705. { 0x0000e5bb, 0x00000004 },
  706. { 0x0000e5bc, 0000000000 },
  707. { 0x00120000, 0x0000000c },
  708. { 0x00120000, 0x00000004 },
  709. { 0x001b0002, 0x0000000c },
  710. { 0x0000a000, 0x00000004 },
  711. { 0x0000e821, 0x00000004 },
  712. { 0x0000e800, 0000000000 },
  713. { 0x0000e821, 0x00000004 },
  714. { 0x0000e82e, 0000000000 },
  715. { 0x02cca000, 0x00000004 },
  716. { 0x00140000, 0x00000004 },
  717. { 0x000ce1cc, 0x00000004 },
  718. { 0x050de1cd, 0x00000004 },
  719. { 0x000000a7, 0x00000020 },
  720. { 0x4200e000, 0000000000 },
  721. { 0x000000ae, 0x00000038 },
  722. { 0x000ca000, 0x00000004 },
  723. { 0x00140000, 0x00000004 },
  724. { 0x000c2000, 0x00000004 },
  725. { 0x00160000, 0x00000004 },
  726. { 0x700ce000, 0x00000004 },
  727. { 0x001400aa, 0x00000008 },
  728. { 0x4000e000, 0000000000 },
  729. { 0x02400000, 0x00000004 },
  730. { 0x400ee000, 0x00000004 },
  731. { 0x02400000, 0x00000004 },
  732. { 0x4000e000, 0000000000 },
  733. { 0x000c2000, 0x00000004 },
  734. { 0x0240e51b, 0x00000004 },
  735. { 0x0080e50a, 0x00000005 },
  736. { 0x0080e50b, 0x00000005 },
  737. { 0x00220000, 0x00000004 },
  738. { 0x000700e4, 0x00000004 },
  739. { 0x000000c1, 0x00000038 },
  740. { 0x000c209a, 0x00000030 },
  741. { 0x0880e5bd, 0x00000005 },
  742. { 0x000c2099, 0x00000030 },
  743. { 0x0800e5bb, 0x00000005 },
  744. { 0x000c209a, 0x00000030 },
  745. { 0x0880e5bc, 0x00000005 },
  746. { 0x000000c4, 0x00000008 },
  747. { 0x0080e5bd, 0x00000005 },
  748. { 0x0000e5bb, 0x00000005 },
  749. { 0x0080e5bc, 0x00000005 },
  750. { 0x00210000, 0x00000004 },
  751. { 0x02800000, 0x00000004 },
  752. { 0x00c000c8, 0x00000018 },
  753. { 0x4180e000, 0x00000040 },
  754. { 0x000000ca, 0x00000024 },
  755. { 0x01000000, 0x0000000c },
  756. { 0x0100e51d, 0x0000000c },
  757. { 0x000045bb, 0x00000004 },
  758. { 0x000080c4, 0x00000008 },
  759. { 0x0000f3ce, 0x00000004 },
  760. { 0x0140a000, 0x00000004 },
  761. { 0x00cc2000, 0x00000004 },
  762. { 0x08c053cf, 0x00000040 },
  763. { 0x00008000, 0000000000 },
  764. { 0x0000f3d2, 0x00000004 },
  765. { 0x0140a000, 0x00000004 },
  766. { 0x00cc2000, 0x00000004 },
  767. { 0x08c053d3, 0x00000040 },
  768. { 0x00008000, 0000000000 },
  769. { 0x0000f39d, 0x00000004 },
  770. { 0x0140a000, 0x00000004 },
  771. { 0x00cc2000, 0x00000004 },
  772. { 0x08c0539e, 0x00000040 },
  773. { 0x00008000, 0000000000 },
  774. { 0x03c00830, 0x00000004 },
  775. { 0x4200e000, 0000000000 },
  776. { 0x0000a000, 0x00000004 },
  777. { 0x200045e0, 0x00000004 },
  778. { 0x0000e5e1, 0000000000 },
  779. { 0x00000001, 0000000000 },
  780. { 0x000700e1, 0x00000004 },
  781. { 0x0800e394, 0000000000 },
  782. { 0000000000, 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. };
  811. static int RADEON_READ_PLL(drm_device_t *dev, int addr)
  812. {
  813. drm_radeon_private_t *dev_priv = dev->dev_private;
  814. RADEON_WRITE8(RADEON_CLOCK_CNTL_INDEX, addr & 0x1f);
  815. return RADEON_READ(RADEON_CLOCK_CNTL_DATA);
  816. }
  817. #if RADEON_FIFO_DEBUG
  818. static void radeon_status( drm_radeon_private_t *dev_priv )
  819. {
  820. printk( "%s:\n", __FUNCTION__ );
  821. printk( "RBBM_STATUS = 0x%08x\n",
  822. (unsigned int)RADEON_READ( RADEON_RBBM_STATUS ) );
  823. printk( "CP_RB_RTPR = 0x%08x\n",
  824. (unsigned int)RADEON_READ( RADEON_CP_RB_RPTR ) );
  825. printk( "CP_RB_WTPR = 0x%08x\n",
  826. (unsigned int)RADEON_READ( RADEON_CP_RB_WPTR ) );
  827. printk( "AIC_CNTL = 0x%08x\n",
  828. (unsigned int)RADEON_READ( RADEON_AIC_CNTL ) );
  829. printk( "AIC_STAT = 0x%08x\n",
  830. (unsigned int)RADEON_READ( RADEON_AIC_STAT ) );
  831. printk( "AIC_PT_BASE = 0x%08x\n",
  832. (unsigned int)RADEON_READ( RADEON_AIC_PT_BASE ) );
  833. printk( "TLB_ADDR = 0x%08x\n",
  834. (unsigned int)RADEON_READ( RADEON_AIC_TLB_ADDR ) );
  835. printk( "TLB_DATA = 0x%08x\n",
  836. (unsigned int)RADEON_READ( RADEON_AIC_TLB_DATA ) );
  837. }
  838. #endif
  839. /* ================================================================
  840. * Engine, FIFO control
  841. */
  842. static int radeon_do_pixcache_flush( drm_radeon_private_t *dev_priv )
  843. {
  844. u32 tmp;
  845. int i;
  846. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  847. tmp = RADEON_READ( RADEON_RB2D_DSTCACHE_CTLSTAT );
  848. tmp |= RADEON_RB2D_DC_FLUSH_ALL;
  849. RADEON_WRITE( RADEON_RB2D_DSTCACHE_CTLSTAT, tmp );
  850. for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) {
  851. if ( !(RADEON_READ( RADEON_RB2D_DSTCACHE_CTLSTAT )
  852. & RADEON_RB2D_DC_BUSY) ) {
  853. return 0;
  854. }
  855. DRM_UDELAY( 1 );
  856. }
  857. #if RADEON_FIFO_DEBUG
  858. DRM_ERROR( "failed!\n" );
  859. radeon_status( dev_priv );
  860. #endif
  861. return DRM_ERR(EBUSY);
  862. }
  863. static int radeon_do_wait_for_fifo( drm_radeon_private_t *dev_priv,
  864. int entries )
  865. {
  866. int i;
  867. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  868. for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) {
  869. int slots = ( RADEON_READ( RADEON_RBBM_STATUS )
  870. & RADEON_RBBM_FIFOCNT_MASK );
  871. if ( slots >= entries ) return 0;
  872. DRM_UDELAY( 1 );
  873. }
  874. #if RADEON_FIFO_DEBUG
  875. DRM_ERROR( "failed!\n" );
  876. radeon_status( dev_priv );
  877. #endif
  878. return DRM_ERR(EBUSY);
  879. }
  880. static int radeon_do_wait_for_idle( drm_radeon_private_t *dev_priv )
  881. {
  882. int i, ret;
  883. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  884. ret = radeon_do_wait_for_fifo( dev_priv, 64 );
  885. if ( ret ) return ret;
  886. for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) {
  887. if ( !(RADEON_READ( RADEON_RBBM_STATUS )
  888. & RADEON_RBBM_ACTIVE) ) {
  889. radeon_do_pixcache_flush( dev_priv );
  890. return 0;
  891. }
  892. DRM_UDELAY( 1 );
  893. }
  894. #if RADEON_FIFO_DEBUG
  895. DRM_ERROR( "failed!\n" );
  896. radeon_status( dev_priv );
  897. #endif
  898. return DRM_ERR(EBUSY);
  899. }
  900. /* ================================================================
  901. * CP control, initialization
  902. */
  903. /* Load the microcode for the CP */
  904. static void radeon_cp_load_microcode( drm_radeon_private_t *dev_priv )
  905. {
  906. int i;
  907. DRM_DEBUG( "\n" );
  908. radeon_do_wait_for_idle( dev_priv );
  909. RADEON_WRITE( RADEON_CP_ME_RAM_ADDR, 0 );
  910. if (dev_priv->microcode_version==UCODE_R200) {
  911. DRM_INFO("Loading R200 Microcode\n");
  912. for ( i = 0 ; i < 256 ; i++ )
  913. {
  914. RADEON_WRITE( RADEON_CP_ME_RAM_DATAH,
  915. R200_cp_microcode[i][1] );
  916. RADEON_WRITE( RADEON_CP_ME_RAM_DATAL,
  917. R200_cp_microcode[i][0] );
  918. }
  919. } else if (dev_priv->microcode_version==UCODE_R300) {
  920. DRM_INFO("Loading R300 Microcode\n");
  921. for ( i = 0 ; i < 256 ; i++ )
  922. {
  923. RADEON_WRITE( RADEON_CP_ME_RAM_DATAH,
  924. R300_cp_microcode[i][1] );
  925. RADEON_WRITE( RADEON_CP_ME_RAM_DATAL,
  926. R300_cp_microcode[i][0] );
  927. }
  928. } else {
  929. for ( i = 0 ; i < 256 ; i++ ) {
  930. RADEON_WRITE( RADEON_CP_ME_RAM_DATAH,
  931. radeon_cp_microcode[i][1] );
  932. RADEON_WRITE( RADEON_CP_ME_RAM_DATAL,
  933. radeon_cp_microcode[i][0] );
  934. }
  935. }
  936. }
  937. /* Flush any pending commands to the CP. This should only be used just
  938. * prior to a wait for idle, as it informs the engine that the command
  939. * stream is ending.
  940. */
  941. static void radeon_do_cp_flush( drm_radeon_private_t *dev_priv )
  942. {
  943. DRM_DEBUG( "\n" );
  944. #if 0
  945. u32 tmp;
  946. tmp = RADEON_READ( RADEON_CP_RB_WPTR ) | (1 << 31);
  947. RADEON_WRITE( RADEON_CP_RB_WPTR, tmp );
  948. #endif
  949. }
  950. /* Wait for the CP to go idle.
  951. */
  952. int radeon_do_cp_idle( drm_radeon_private_t *dev_priv )
  953. {
  954. RING_LOCALS;
  955. DRM_DEBUG( "\n" );
  956. BEGIN_RING( 6 );
  957. RADEON_PURGE_CACHE();
  958. RADEON_PURGE_ZCACHE();
  959. RADEON_WAIT_UNTIL_IDLE();
  960. ADVANCE_RING();
  961. COMMIT_RING();
  962. return radeon_do_wait_for_idle( dev_priv );
  963. }
  964. /* Start the Command Processor.
  965. */
  966. static void radeon_do_cp_start( drm_radeon_private_t *dev_priv )
  967. {
  968. RING_LOCALS;
  969. DRM_DEBUG( "\n" );
  970. radeon_do_wait_for_idle( dev_priv );
  971. RADEON_WRITE( RADEON_CP_CSQ_CNTL, dev_priv->cp_mode );
  972. dev_priv->cp_running = 1;
  973. BEGIN_RING( 6 );
  974. RADEON_PURGE_CACHE();
  975. RADEON_PURGE_ZCACHE();
  976. RADEON_WAIT_UNTIL_IDLE();
  977. ADVANCE_RING();
  978. COMMIT_RING();
  979. }
  980. /* Reset the Command Processor. This will not flush any pending
  981. * commands, so you must wait for the CP command stream to complete
  982. * before calling this routine.
  983. */
  984. static void radeon_do_cp_reset( drm_radeon_private_t *dev_priv )
  985. {
  986. u32 cur_read_ptr;
  987. DRM_DEBUG( "\n" );
  988. cur_read_ptr = RADEON_READ( RADEON_CP_RB_RPTR );
  989. RADEON_WRITE( RADEON_CP_RB_WPTR, cur_read_ptr );
  990. SET_RING_HEAD( dev_priv, cur_read_ptr );
  991. dev_priv->ring.tail = cur_read_ptr;
  992. }
  993. /* Stop the Command Processor. This will not flush any pending
  994. * commands, so you must flush the command stream and wait for the CP
  995. * to go idle before calling this routine.
  996. */
  997. static void radeon_do_cp_stop( drm_radeon_private_t *dev_priv )
  998. {
  999. DRM_DEBUG( "\n" );
  1000. RADEON_WRITE( RADEON_CP_CSQ_CNTL, RADEON_CSQ_PRIDIS_INDDIS );
  1001. dev_priv->cp_running = 0;
  1002. }
  1003. /* Reset the engine. This will stop the CP if it is running.
  1004. */
  1005. static int radeon_do_engine_reset( drm_device_t *dev )
  1006. {
  1007. drm_radeon_private_t *dev_priv = dev->dev_private;
  1008. u32 clock_cntl_index, mclk_cntl, rbbm_soft_reset;
  1009. DRM_DEBUG( "\n" );
  1010. radeon_do_pixcache_flush( dev_priv );
  1011. clock_cntl_index = RADEON_READ( RADEON_CLOCK_CNTL_INDEX );
  1012. mclk_cntl = RADEON_READ_PLL( dev, RADEON_MCLK_CNTL );
  1013. RADEON_WRITE_PLL( RADEON_MCLK_CNTL, ( mclk_cntl |
  1014. RADEON_FORCEON_MCLKA |
  1015. RADEON_FORCEON_MCLKB |
  1016. RADEON_FORCEON_YCLKA |
  1017. RADEON_FORCEON_YCLKB |
  1018. RADEON_FORCEON_MC |
  1019. RADEON_FORCEON_AIC ) );
  1020. rbbm_soft_reset = RADEON_READ( RADEON_RBBM_SOFT_RESET );
  1021. RADEON_WRITE( RADEON_RBBM_SOFT_RESET, ( rbbm_soft_reset |
  1022. RADEON_SOFT_RESET_CP |
  1023. RADEON_SOFT_RESET_HI |
  1024. RADEON_SOFT_RESET_SE |
  1025. RADEON_SOFT_RESET_RE |
  1026. RADEON_SOFT_RESET_PP |
  1027. RADEON_SOFT_RESET_E2 |
  1028. RADEON_SOFT_RESET_RB ) );
  1029. RADEON_READ( RADEON_RBBM_SOFT_RESET );
  1030. RADEON_WRITE( RADEON_RBBM_SOFT_RESET, ( rbbm_soft_reset &
  1031. ~( RADEON_SOFT_RESET_CP |
  1032. RADEON_SOFT_RESET_HI |
  1033. RADEON_SOFT_RESET_SE |
  1034. RADEON_SOFT_RESET_RE |
  1035. RADEON_SOFT_RESET_PP |
  1036. RADEON_SOFT_RESET_E2 |
  1037. RADEON_SOFT_RESET_RB ) ) );
  1038. RADEON_READ( RADEON_RBBM_SOFT_RESET );
  1039. RADEON_WRITE_PLL( RADEON_MCLK_CNTL, mclk_cntl );
  1040. RADEON_WRITE( RADEON_CLOCK_CNTL_INDEX, clock_cntl_index );
  1041. RADEON_WRITE( RADEON_RBBM_SOFT_RESET, rbbm_soft_reset );
  1042. /* Reset the CP ring */
  1043. radeon_do_cp_reset( dev_priv );
  1044. /* The CP is no longer running after an engine reset */
  1045. dev_priv->cp_running = 0;
  1046. /* Reset any pending vertex, indirect buffers */
  1047. radeon_freelist_reset( dev );
  1048. return 0;
  1049. }
  1050. static void radeon_cp_init_ring_buffer( drm_device_t *dev,
  1051. drm_radeon_private_t *dev_priv )
  1052. {
  1053. u32 ring_start, cur_read_ptr;
  1054. u32 tmp;
  1055. /* Initialize the memory controller */
  1056. RADEON_WRITE( RADEON_MC_FB_LOCATION,
  1057. ( ( dev_priv->gart_vm_start - 1 ) & 0xffff0000 )
  1058. | ( dev_priv->fb_location >> 16 ) );
  1059. #if __OS_HAS_AGP
  1060. if ( !dev_priv->is_pci ) {
  1061. RADEON_WRITE( RADEON_MC_AGP_LOCATION,
  1062. (((dev_priv->gart_vm_start - 1 +
  1063. dev_priv->gart_size) & 0xffff0000) |
  1064. (dev_priv->gart_vm_start >> 16)) );
  1065. ring_start = (dev_priv->cp_ring->offset
  1066. - dev->agp->base
  1067. + dev_priv->gart_vm_start);
  1068. } else
  1069. #endif
  1070. ring_start = (dev_priv->cp_ring->offset
  1071. - dev->sg->handle
  1072. + dev_priv->gart_vm_start);
  1073. RADEON_WRITE( RADEON_CP_RB_BASE, ring_start );
  1074. /* Set the write pointer delay */
  1075. RADEON_WRITE( RADEON_CP_RB_WPTR_DELAY, 0 );
  1076. /* Initialize the ring buffer's read and write pointers */
  1077. cur_read_ptr = RADEON_READ( RADEON_CP_RB_RPTR );
  1078. RADEON_WRITE( RADEON_CP_RB_WPTR, cur_read_ptr );
  1079. SET_RING_HEAD( dev_priv, cur_read_ptr );
  1080. dev_priv->ring.tail = cur_read_ptr;
  1081. #if __OS_HAS_AGP
  1082. if ( !dev_priv->is_pci ) {
  1083. RADEON_WRITE( RADEON_CP_RB_RPTR_ADDR,
  1084. dev_priv->ring_rptr->offset
  1085. - dev->agp->base
  1086. + dev_priv->gart_vm_start);
  1087. } else
  1088. #endif
  1089. {
  1090. drm_sg_mem_t *entry = dev->sg;
  1091. unsigned long tmp_ofs, page_ofs;
  1092. tmp_ofs = dev_priv->ring_rptr->offset - dev->sg->handle;
  1093. page_ofs = tmp_ofs >> PAGE_SHIFT;
  1094. RADEON_WRITE( RADEON_CP_RB_RPTR_ADDR,
  1095. entry->busaddr[page_ofs]);
  1096. DRM_DEBUG( "ring rptr: offset=0x%08lx handle=0x%08lx\n",
  1097. (unsigned long) entry->busaddr[page_ofs],
  1098. entry->handle + tmp_ofs );
  1099. }
  1100. /* Initialize the scratch register pointer. This will cause
  1101. * the scratch register values to be written out to memory
  1102. * whenever they are updated.
  1103. *
  1104. * We simply put this behind the ring read pointer, this works
  1105. * with PCI GART as well as (whatever kind of) AGP GART
  1106. */
  1107. RADEON_WRITE( RADEON_SCRATCH_ADDR, RADEON_READ( RADEON_CP_RB_RPTR_ADDR )
  1108. + RADEON_SCRATCH_REG_OFFSET );
  1109. dev_priv->scratch = ((__volatile__ u32 *)
  1110. dev_priv->ring_rptr->handle +
  1111. (RADEON_SCRATCH_REG_OFFSET / sizeof(u32)));
  1112. RADEON_WRITE( RADEON_SCRATCH_UMSK, 0x7 );
  1113. /* Writeback doesn't seem to work everywhere, test it first */
  1114. DRM_WRITE32( dev_priv->ring_rptr, RADEON_SCRATCHOFF(1), 0 );
  1115. RADEON_WRITE( RADEON_SCRATCH_REG1, 0xdeadbeef );
  1116. for ( tmp = 0 ; tmp < dev_priv->usec_timeout ; tmp++ ) {
  1117. if ( DRM_READ32( dev_priv->ring_rptr, RADEON_SCRATCHOFF(1) ) == 0xdeadbeef )
  1118. break;
  1119. DRM_UDELAY( 1 );
  1120. }
  1121. if ( tmp < dev_priv->usec_timeout ) {
  1122. dev_priv->writeback_works = 1;
  1123. DRM_DEBUG( "writeback test succeeded, tmp=%d\n", tmp );
  1124. } else {
  1125. dev_priv->writeback_works = 0;
  1126. DRM_DEBUG( "writeback test failed\n" );
  1127. }
  1128. dev_priv->sarea_priv->last_frame = dev_priv->scratch[0] = 0;
  1129. RADEON_WRITE( RADEON_LAST_FRAME_REG,
  1130. dev_priv->sarea_priv->last_frame );
  1131. dev_priv->sarea_priv->last_dispatch = dev_priv->scratch[1] = 0;
  1132. RADEON_WRITE( RADEON_LAST_DISPATCH_REG,
  1133. dev_priv->sarea_priv->last_dispatch );
  1134. dev_priv->sarea_priv->last_clear = dev_priv->scratch[2] = 0;
  1135. RADEON_WRITE( RADEON_LAST_CLEAR_REG,
  1136. dev_priv->sarea_priv->last_clear );
  1137. /* Set ring buffer size */
  1138. #ifdef __BIG_ENDIAN
  1139. RADEON_WRITE( RADEON_CP_RB_CNTL, dev_priv->ring.size_l2qw | RADEON_BUF_SWAP_32BIT );
  1140. #else
  1141. RADEON_WRITE( RADEON_CP_RB_CNTL, dev_priv->ring.size_l2qw );
  1142. #endif
  1143. radeon_do_wait_for_idle( dev_priv );
  1144. /* Turn on bus mastering */
  1145. tmp = RADEON_READ( RADEON_BUS_CNTL ) & ~RADEON_BUS_MASTER_DIS;
  1146. RADEON_WRITE( RADEON_BUS_CNTL, tmp );
  1147. /* Sync everything up */
  1148. RADEON_WRITE( RADEON_ISYNC_CNTL,
  1149. (RADEON_ISYNC_ANY2D_IDLE3D |
  1150. RADEON_ISYNC_ANY3D_IDLE2D |
  1151. RADEON_ISYNC_WAIT_IDLEGUI |
  1152. RADEON_ISYNC_CPSCRATCH_IDLEGUI) );
  1153. }
  1154. /* Enable or disable PCI GART on the chip */
  1155. static void radeon_set_pcigart( drm_radeon_private_t *dev_priv, int on )
  1156. {
  1157. u32 tmp = RADEON_READ( RADEON_AIC_CNTL );
  1158. if ( on ) {
  1159. RADEON_WRITE( RADEON_AIC_CNTL, tmp | RADEON_PCIGART_TRANSLATE_EN );
  1160. /* set PCI GART page-table base address
  1161. */
  1162. RADEON_WRITE( RADEON_AIC_PT_BASE, dev_priv->bus_pci_gart );
  1163. /* set address range for PCI address translate
  1164. */
  1165. RADEON_WRITE( RADEON_AIC_LO_ADDR, dev_priv->gart_vm_start );
  1166. RADEON_WRITE( RADEON_AIC_HI_ADDR, dev_priv->gart_vm_start
  1167. + dev_priv->gart_size - 1);
  1168. /* Turn off AGP aperture -- is this required for PCI GART?
  1169. */
  1170. RADEON_WRITE( RADEON_MC_AGP_LOCATION, 0xffffffc0 ); /* ?? */
  1171. RADEON_WRITE( RADEON_AGP_COMMAND, 0 ); /* clear AGP_COMMAND */
  1172. } else {
  1173. RADEON_WRITE( RADEON_AIC_CNTL, tmp & ~RADEON_PCIGART_TRANSLATE_EN );
  1174. }
  1175. }
  1176. static int radeon_do_init_cp( drm_device_t *dev, drm_radeon_init_t *init )
  1177. {
  1178. drm_radeon_private_t *dev_priv = dev->dev_private;;
  1179. DRM_DEBUG( "\n" );
  1180. dev_priv->is_pci = init->is_pci;
  1181. if ( dev_priv->is_pci && !dev->sg ) {
  1182. DRM_ERROR( "PCI GART memory not allocated!\n" );
  1183. dev->dev_private = (void *)dev_priv;
  1184. radeon_do_cleanup_cp(dev);
  1185. return DRM_ERR(EINVAL);
  1186. }
  1187. dev_priv->usec_timeout = init->usec_timeout;
  1188. if ( dev_priv->usec_timeout < 1 ||
  1189. dev_priv->usec_timeout > RADEON_MAX_USEC_TIMEOUT ) {
  1190. DRM_DEBUG( "TIMEOUT problem!\n" );
  1191. dev->dev_private = (void *)dev_priv;
  1192. radeon_do_cleanup_cp(dev);
  1193. return DRM_ERR(EINVAL);
  1194. }
  1195. switch(init->func) {
  1196. case RADEON_INIT_R200_CP:
  1197. dev_priv->microcode_version=UCODE_R200;
  1198. break;
  1199. case RADEON_INIT_R300_CP:
  1200. dev_priv->microcode_version=UCODE_R300;
  1201. break;
  1202. default:
  1203. dev_priv->microcode_version=UCODE_R100;
  1204. }
  1205. dev_priv->do_boxes = 0;
  1206. dev_priv->cp_mode = init->cp_mode;
  1207. /* We don't support anything other than bus-mastering ring mode,
  1208. * but the ring can be in either AGP or PCI space for the ring
  1209. * read pointer.
  1210. */
  1211. if ( ( init->cp_mode != RADEON_CSQ_PRIBM_INDDIS ) &&
  1212. ( init->cp_mode != RADEON_CSQ_PRIBM_INDBM ) ) {
  1213. DRM_DEBUG( "BAD cp_mode (%x)!\n", init->cp_mode );
  1214. dev->dev_private = (void *)dev_priv;
  1215. radeon_do_cleanup_cp(dev);
  1216. return DRM_ERR(EINVAL);
  1217. }
  1218. switch ( init->fb_bpp ) {
  1219. case 16:
  1220. dev_priv->color_fmt = RADEON_COLOR_FORMAT_RGB565;
  1221. break;
  1222. case 32:
  1223. default:
  1224. dev_priv->color_fmt = RADEON_COLOR_FORMAT_ARGB8888;
  1225. break;
  1226. }
  1227. dev_priv->front_offset = init->front_offset;
  1228. dev_priv->front_pitch = init->front_pitch;
  1229. dev_priv->back_offset = init->back_offset;
  1230. dev_priv->back_pitch = init->back_pitch;
  1231. switch ( init->depth_bpp ) {
  1232. case 16:
  1233. dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_16BIT_INT_Z;
  1234. break;
  1235. case 32:
  1236. default:
  1237. dev_priv->depth_fmt = RADEON_DEPTH_FORMAT_24BIT_INT_Z;
  1238. break;
  1239. }
  1240. dev_priv->depth_offset = init->depth_offset;
  1241. dev_priv->depth_pitch = init->depth_pitch;
  1242. /* Hardware state for depth clears. Remove this if/when we no
  1243. * longer clear the depth buffer with a 3D rectangle. Hard-code
  1244. * all values to prevent unwanted 3D state from slipping through
  1245. * and screwing with the clear operation.
  1246. */
  1247. dev_priv->depth_clear.rb3d_cntl = (RADEON_PLANE_MASK_ENABLE |
  1248. (dev_priv->color_fmt << 10) |
  1249. (dev_priv->microcode_version == UCODE_R100 ? RADEON_ZBLOCK16 : 0));
  1250. dev_priv->depth_clear.rb3d_zstencilcntl =
  1251. (dev_priv->depth_fmt |
  1252. RADEON_Z_TEST_ALWAYS |
  1253. RADEON_STENCIL_TEST_ALWAYS |
  1254. RADEON_STENCIL_S_FAIL_REPLACE |
  1255. RADEON_STENCIL_ZPASS_REPLACE |
  1256. RADEON_STENCIL_ZFAIL_REPLACE |
  1257. RADEON_Z_WRITE_ENABLE);
  1258. dev_priv->depth_clear.se_cntl = (RADEON_FFACE_CULL_CW |
  1259. RADEON_BFACE_SOLID |
  1260. RADEON_FFACE_SOLID |
  1261. RADEON_FLAT_SHADE_VTX_LAST |
  1262. RADEON_DIFFUSE_SHADE_FLAT |
  1263. RADEON_ALPHA_SHADE_FLAT |
  1264. RADEON_SPECULAR_SHADE_FLAT |
  1265. RADEON_FOG_SHADE_FLAT |
  1266. RADEON_VTX_PIX_CENTER_OGL |
  1267. RADEON_ROUND_MODE_TRUNC |
  1268. RADEON_ROUND_PREC_8TH_PIX);
  1269. DRM_GETSAREA();
  1270. dev_priv->fb_offset = init->fb_offset;
  1271. dev_priv->mmio_offset = init->mmio_offset;
  1272. dev_priv->ring_offset = init->ring_offset;
  1273. dev_priv->ring_rptr_offset = init->ring_rptr_offset;
  1274. dev_priv->buffers_offset = init->buffers_offset;
  1275. dev_priv->gart_textures_offset = init->gart_textures_offset;
  1276. if(!dev_priv->sarea) {
  1277. DRM_ERROR("could not find sarea!\n");
  1278. dev->dev_private = (void *)dev_priv;
  1279. radeon_do_cleanup_cp(dev);
  1280. return DRM_ERR(EINVAL);
  1281. }
  1282. dev_priv->mmio = drm_core_findmap(dev, init->mmio_offset);
  1283. if(!dev_priv->mmio) {
  1284. DRM_ERROR("could not find mmio region!\n");
  1285. dev->dev_private = (void *)dev_priv;
  1286. radeon_do_cleanup_cp(dev);
  1287. return DRM_ERR(EINVAL);
  1288. }
  1289. dev_priv->cp_ring = drm_core_findmap(dev, init->ring_offset);
  1290. if(!dev_priv->cp_ring) {
  1291. DRM_ERROR("could not find cp ring region!\n");
  1292. dev->dev_private = (void *)dev_priv;
  1293. radeon_do_cleanup_cp(dev);
  1294. return DRM_ERR(EINVAL);
  1295. }
  1296. dev_priv->ring_rptr = drm_core_findmap(dev, init->ring_rptr_offset);
  1297. if(!dev_priv->ring_rptr) {
  1298. DRM_ERROR("could not find ring read pointer!\n");
  1299. dev->dev_private = (void *)dev_priv;
  1300. radeon_do_cleanup_cp(dev);
  1301. return DRM_ERR(EINVAL);
  1302. }
  1303. dev->agp_buffer_map = drm_core_findmap(dev, init->buffers_offset);
  1304. if(!dev->agp_buffer_map) {
  1305. DRM_ERROR("could not find dma buffer region!\n");
  1306. dev->dev_private = (void *)dev_priv;
  1307. radeon_do_cleanup_cp(dev);
  1308. return DRM_ERR(EINVAL);
  1309. }
  1310. if ( init->gart_textures_offset ) {
  1311. dev_priv->gart_textures = drm_core_findmap(dev, init->gart_textures_offset);
  1312. if ( !dev_priv->gart_textures ) {
  1313. DRM_ERROR("could not find GART texture region!\n");
  1314. dev->dev_private = (void *)dev_priv;
  1315. radeon_do_cleanup_cp(dev);
  1316. return DRM_ERR(EINVAL);
  1317. }
  1318. }
  1319. dev_priv->sarea_priv =
  1320. (drm_radeon_sarea_t *)((u8 *)dev_priv->sarea->handle +
  1321. init->sarea_priv_offset);
  1322. #if __OS_HAS_AGP
  1323. if ( !dev_priv->is_pci ) {
  1324. drm_core_ioremap( dev_priv->cp_ring, dev );
  1325. drm_core_ioremap( dev_priv->ring_rptr, dev );
  1326. drm_core_ioremap( dev->agp_buffer_map, dev );
  1327. if(!dev_priv->cp_ring->handle ||
  1328. !dev_priv->ring_rptr->handle ||
  1329. !dev->agp_buffer_map->handle) {
  1330. DRM_ERROR("could not find ioremap agp regions!\n");
  1331. dev->dev_private = (void *)dev_priv;
  1332. radeon_do_cleanup_cp(dev);
  1333. return DRM_ERR(EINVAL);
  1334. }
  1335. } else
  1336. #endif
  1337. {
  1338. dev_priv->cp_ring->handle =
  1339. (void *)dev_priv->cp_ring->offset;
  1340. dev_priv->ring_rptr->handle =
  1341. (void *)dev_priv->ring_rptr->offset;
  1342. dev->agp_buffer_map->handle = (void *)dev->agp_buffer_map->offset;
  1343. DRM_DEBUG( "dev_priv->cp_ring->handle %p\n",
  1344. dev_priv->cp_ring->handle );
  1345. DRM_DEBUG( "dev_priv->ring_rptr->handle %p\n",
  1346. dev_priv->ring_rptr->handle );
  1347. DRM_DEBUG( "dev->agp_buffer_map->handle %p\n",
  1348. dev->agp_buffer_map->handle );
  1349. }
  1350. dev_priv->fb_location = ( RADEON_READ( RADEON_MC_FB_LOCATION )
  1351. & 0xffff ) << 16;
  1352. dev_priv->front_pitch_offset = (((dev_priv->front_pitch/64) << 22) |
  1353. ( ( dev_priv->front_offset
  1354. + dev_priv->fb_location ) >> 10 ) );
  1355. dev_priv->back_pitch_offset = (((dev_priv->back_pitch/64) << 22) |
  1356. ( ( dev_priv->back_offset
  1357. + dev_priv->fb_location ) >> 10 ) );
  1358. dev_priv->depth_pitch_offset = (((dev_priv->depth_pitch/64) << 22) |
  1359. ( ( dev_priv->depth_offset
  1360. + dev_priv->fb_location ) >> 10 ) );
  1361. dev_priv->gart_size = init->gart_size;
  1362. dev_priv->gart_vm_start = dev_priv->fb_location
  1363. + RADEON_READ( RADEON_CONFIG_APER_SIZE );
  1364. #if __OS_HAS_AGP
  1365. if ( !dev_priv->is_pci )
  1366. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1367. - dev->agp->base
  1368. + dev_priv->gart_vm_start);
  1369. else
  1370. #endif
  1371. dev_priv->gart_buffers_offset = (dev->agp_buffer_map->offset
  1372. - dev->sg->handle
  1373. + dev_priv->gart_vm_start);
  1374. DRM_DEBUG( "dev_priv->gart_size %d\n",
  1375. dev_priv->gart_size );
  1376. DRM_DEBUG( "dev_priv->gart_vm_start 0x%x\n",
  1377. dev_priv->gart_vm_start );
  1378. DRM_DEBUG( "dev_priv->gart_buffers_offset 0x%lx\n",
  1379. dev_priv->gart_buffers_offset );
  1380. dev_priv->ring.start = (u32 *)dev_priv->cp_ring->handle;
  1381. dev_priv->ring.end = ((u32 *)dev_priv->cp_ring->handle
  1382. + init->ring_size / sizeof(u32));
  1383. dev_priv->ring.size = init->ring_size;
  1384. dev_priv->ring.size_l2qw = drm_order( init->ring_size / 8 );
  1385. dev_priv->ring.tail_mask =
  1386. (dev_priv->ring.size / sizeof(u32)) - 1;
  1387. dev_priv->ring.high_mark = RADEON_RING_HIGH_MARK;
  1388. #if __OS_HAS_AGP
  1389. if ( !dev_priv->is_pci ) {
  1390. /* Turn off PCI GART */
  1391. radeon_set_pcigart( dev_priv, 0 );
  1392. } else
  1393. #endif
  1394. {
  1395. if (!drm_ati_pcigart_init( dev, &dev_priv->phys_pci_gart,
  1396. &dev_priv->bus_pci_gart)) {
  1397. DRM_ERROR( "failed to init PCI GART!\n" );
  1398. dev->dev_private = (void *)dev_priv;
  1399. radeon_do_cleanup_cp(dev);
  1400. return DRM_ERR(ENOMEM);
  1401. }
  1402. /* Turn on PCI GART */
  1403. radeon_set_pcigart( dev_priv, 1 );
  1404. }
  1405. radeon_cp_load_microcode( dev_priv );
  1406. radeon_cp_init_ring_buffer( dev, dev_priv );
  1407. dev_priv->last_buf = 0;
  1408. dev->dev_private = (void *)dev_priv;
  1409. radeon_do_engine_reset( dev );
  1410. return 0;
  1411. }
  1412. static int radeon_do_cleanup_cp( drm_device_t *dev )
  1413. {
  1414. drm_radeon_private_t *dev_priv = dev->dev_private;
  1415. DRM_DEBUG( "\n" );
  1416. /* Make sure interrupts are disabled here because the uninstall ioctl
  1417. * may not have been called from userspace and after dev_private
  1418. * is freed, it's too late.
  1419. */
  1420. if ( dev->irq_enabled ) drm_irq_uninstall(dev);
  1421. #if __OS_HAS_AGP
  1422. if ( !dev_priv->is_pci ) {
  1423. if ( dev_priv->cp_ring != NULL )
  1424. drm_core_ioremapfree( dev_priv->cp_ring, dev );
  1425. if ( dev_priv->ring_rptr != NULL )
  1426. drm_core_ioremapfree( dev_priv->ring_rptr, dev );
  1427. if ( dev->agp_buffer_map != NULL )
  1428. {
  1429. drm_core_ioremapfree( dev->agp_buffer_map, dev );
  1430. dev->agp_buffer_map = NULL;
  1431. }
  1432. } else
  1433. #endif
  1434. {
  1435. if (!drm_ati_pcigart_cleanup( dev,
  1436. dev_priv->phys_pci_gart,
  1437. dev_priv->bus_pci_gart ))
  1438. DRM_ERROR( "failed to cleanup PCI GART!\n" );
  1439. }
  1440. /* only clear to the start of flags */
  1441. memset(dev_priv, 0, offsetof(drm_radeon_private_t, flags));
  1442. return 0;
  1443. }
  1444. /* This code will reinit the Radeon CP hardware after a resume from disc.
  1445. * AFAIK, it would be very difficult to pickle the state at suspend time, so
  1446. * here we make sure that all Radeon hardware initialisation is re-done without
  1447. * affecting running applications.
  1448. *
  1449. * Charl P. Botha <http://cpbotha.net>
  1450. */
  1451. static int radeon_do_resume_cp( drm_device_t *dev )
  1452. {
  1453. drm_radeon_private_t *dev_priv = dev->dev_private;
  1454. if ( !dev_priv ) {
  1455. DRM_ERROR( "Called with no initialization\n" );
  1456. return DRM_ERR( EINVAL );
  1457. }
  1458. DRM_DEBUG("Starting radeon_do_resume_cp()\n");
  1459. #if __OS_HAS_AGP
  1460. if ( !dev_priv->is_pci ) {
  1461. /* Turn off PCI GART */
  1462. radeon_set_pcigart( dev_priv, 0 );
  1463. } else
  1464. #endif
  1465. {
  1466. /* Turn on PCI GART */
  1467. radeon_set_pcigart( dev_priv, 1 );
  1468. }
  1469. radeon_cp_load_microcode( dev_priv );
  1470. radeon_cp_init_ring_buffer( dev, dev_priv );
  1471. radeon_do_engine_reset( dev );
  1472. DRM_DEBUG("radeon_do_resume_cp() complete\n");
  1473. return 0;
  1474. }
  1475. int radeon_cp_init( DRM_IOCTL_ARGS )
  1476. {
  1477. DRM_DEVICE;
  1478. drm_radeon_init_t init;
  1479. LOCK_TEST_WITH_RETURN( dev, filp );
  1480. DRM_COPY_FROM_USER_IOCTL( init, (drm_radeon_init_t __user *)data, sizeof(init) );
  1481. switch ( init.func ) {
  1482. case RADEON_INIT_CP:
  1483. case RADEON_INIT_R200_CP:
  1484. case RADEON_INIT_R300_CP:
  1485. return radeon_do_init_cp( dev, &init );
  1486. case RADEON_CLEANUP_CP:
  1487. return radeon_do_cleanup_cp( dev );
  1488. }
  1489. return DRM_ERR(EINVAL);
  1490. }
  1491. int radeon_cp_start( DRM_IOCTL_ARGS )
  1492. {
  1493. DRM_DEVICE;
  1494. drm_radeon_private_t *dev_priv = dev->dev_private;
  1495. DRM_DEBUG( "\n" );
  1496. LOCK_TEST_WITH_RETURN( dev, filp );
  1497. if ( dev_priv->cp_running ) {
  1498. DRM_DEBUG( "%s while CP running\n", __FUNCTION__ );
  1499. return 0;
  1500. }
  1501. if ( dev_priv->cp_mode == RADEON_CSQ_PRIDIS_INDDIS ) {
  1502. DRM_DEBUG( "%s called with bogus CP mode (%d)\n",
  1503. __FUNCTION__, dev_priv->cp_mode );
  1504. return 0;
  1505. }
  1506. radeon_do_cp_start( dev_priv );
  1507. return 0;
  1508. }
  1509. /* Stop the CP. The engine must have been idled before calling this
  1510. * routine.
  1511. */
  1512. int radeon_cp_stop( DRM_IOCTL_ARGS )
  1513. {
  1514. DRM_DEVICE;
  1515. drm_radeon_private_t *dev_priv = dev->dev_private;
  1516. drm_radeon_cp_stop_t stop;
  1517. int ret;
  1518. DRM_DEBUG( "\n" );
  1519. LOCK_TEST_WITH_RETURN( dev, filp );
  1520. DRM_COPY_FROM_USER_IOCTL( stop, (drm_radeon_cp_stop_t __user *)data, sizeof(stop) );
  1521. if (!dev_priv->cp_running)
  1522. return 0;
  1523. /* Flush any pending CP commands. This ensures any outstanding
  1524. * commands are exectuted by the engine before we turn it off.
  1525. */
  1526. if ( stop.flush ) {
  1527. radeon_do_cp_flush( dev_priv );
  1528. }
  1529. /* If we fail to make the engine go idle, we return an error
  1530. * code so that the DRM ioctl wrapper can try again.
  1531. */
  1532. if ( stop.idle ) {
  1533. ret = radeon_do_cp_idle( dev_priv );
  1534. if ( ret ) return ret;
  1535. }
  1536. /* Finally, we can turn off the CP. If the engine isn't idle,
  1537. * we will get some dropped triangles as they won't be fully
  1538. * rendered before the CP is shut down.
  1539. */
  1540. radeon_do_cp_stop( dev_priv );
  1541. /* Reset the engine */
  1542. radeon_do_engine_reset( dev );
  1543. return 0;
  1544. }
  1545. void radeon_do_release( drm_device_t *dev )
  1546. {
  1547. drm_radeon_private_t *dev_priv = dev->dev_private;
  1548. int i, ret;
  1549. if (dev_priv) {
  1550. if (dev_priv->cp_running) {
  1551. /* Stop the cp */
  1552. while ((ret = radeon_do_cp_idle( dev_priv )) != 0) {
  1553. DRM_DEBUG("radeon_do_cp_idle %d\n", ret);
  1554. #ifdef __linux__
  1555. schedule();
  1556. #else
  1557. tsleep(&ret, PZERO, "rdnrel", 1);
  1558. #endif
  1559. }
  1560. radeon_do_cp_stop( dev_priv );
  1561. radeon_do_engine_reset( dev );
  1562. }
  1563. /* Disable *all* interrupts */
  1564. if (dev_priv->mmio) /* remove this after permanent addmaps */
  1565. RADEON_WRITE( RADEON_GEN_INT_CNTL, 0 );
  1566. if (dev_priv->mmio) {/* remove all surfaces */
  1567. for (i = 0; i < RADEON_MAX_SURFACES; i++) {
  1568. RADEON_WRITE(RADEON_SURFACE0_INFO + 16*i, 0);
  1569. RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND + 16*i, 0);
  1570. RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND + 16*i, 0);
  1571. }
  1572. }
  1573. /* Free memory heap structures */
  1574. radeon_mem_takedown( &(dev_priv->gart_heap) );
  1575. radeon_mem_takedown( &(dev_priv->fb_heap) );
  1576. /* deallocate kernel resources */
  1577. radeon_do_cleanup_cp( dev );
  1578. }
  1579. }
  1580. /* Just reset the CP ring. Called as part of an X Server engine reset.
  1581. */
  1582. int radeon_cp_reset( DRM_IOCTL_ARGS )
  1583. {
  1584. DRM_DEVICE;
  1585. drm_radeon_private_t *dev_priv = dev->dev_private;
  1586. DRM_DEBUG( "\n" );
  1587. LOCK_TEST_WITH_RETURN( dev, filp );
  1588. if ( !dev_priv ) {
  1589. DRM_DEBUG( "%s called before init done\n", __FUNCTION__ );
  1590. return DRM_ERR(EINVAL);
  1591. }
  1592. radeon_do_cp_reset( dev_priv );
  1593. /* The CP is no longer running after an engine reset */
  1594. dev_priv->cp_running = 0;
  1595. return 0;
  1596. }
  1597. int radeon_cp_idle( DRM_IOCTL_ARGS )
  1598. {
  1599. DRM_DEVICE;
  1600. drm_radeon_private_t *dev_priv = dev->dev_private;
  1601. DRM_DEBUG( "\n" );
  1602. LOCK_TEST_WITH_RETURN( dev, filp );
  1603. return radeon_do_cp_idle( dev_priv );
  1604. }
  1605. /* Added by Charl P. Botha to call radeon_do_resume_cp().
  1606. */
  1607. int radeon_cp_resume( DRM_IOCTL_ARGS )
  1608. {
  1609. DRM_DEVICE;
  1610. return radeon_do_resume_cp(dev);
  1611. }
  1612. int radeon_engine_reset( DRM_IOCTL_ARGS )
  1613. {
  1614. DRM_DEVICE;
  1615. DRM_DEBUG( "\n" );
  1616. LOCK_TEST_WITH_RETURN( dev, filp );
  1617. return radeon_do_engine_reset( dev );
  1618. }
  1619. /* ================================================================
  1620. * Fullscreen mode
  1621. */
  1622. /* KW: Deprecated to say the least:
  1623. */
  1624. int radeon_fullscreen( DRM_IOCTL_ARGS )
  1625. {
  1626. return 0;
  1627. }
  1628. /* ================================================================
  1629. * Freelist management
  1630. */
  1631. /* Original comment: FIXME: ROTATE_BUFS is a hack to cycle through
  1632. * bufs until freelist code is used. Note this hides a problem with
  1633. * the scratch register * (used to keep track of last buffer
  1634. * completed) being written to before * the last buffer has actually
  1635. * completed rendering.
  1636. *
  1637. * KW: It's also a good way to find free buffers quickly.
  1638. *
  1639. * KW: Ideally this loop wouldn't exist, and freelist_get wouldn't
  1640. * sleep. However, bugs in older versions of radeon_accel.c mean that
  1641. * we essentially have to do this, else old clients will break.
  1642. *
  1643. * However, it does leave open a potential deadlock where all the
  1644. * buffers are held by other clients, which can't release them because
  1645. * they can't get the lock.
  1646. */
  1647. drm_buf_t *radeon_freelist_get( drm_device_t *dev )
  1648. {
  1649. drm_device_dma_t *dma = dev->dma;
  1650. drm_radeon_private_t *dev_priv = dev->dev_private;
  1651. drm_radeon_buf_priv_t *buf_priv;
  1652. drm_buf_t *buf;
  1653. int i, t;
  1654. int start;
  1655. if ( ++dev_priv->last_buf >= dma->buf_count )
  1656. dev_priv->last_buf = 0;
  1657. start = dev_priv->last_buf;
  1658. for ( t = 0 ; t < dev_priv->usec_timeout ; t++ ) {
  1659. u32 done_age = GET_SCRATCH( 1 );
  1660. DRM_DEBUG("done_age = %d\n",done_age);
  1661. for ( i = start ; i < dma->buf_count ; i++ ) {
  1662. buf = dma->buflist[i];
  1663. buf_priv = buf->dev_private;
  1664. if ( buf->filp == 0 || (buf->pending &&
  1665. buf_priv->age <= done_age) ) {
  1666. dev_priv->stats.requested_bufs++;
  1667. buf->pending = 0;
  1668. return buf;
  1669. }
  1670. start = 0;
  1671. }
  1672. if (t) {
  1673. DRM_UDELAY( 1 );
  1674. dev_priv->stats.freelist_loops++;
  1675. }
  1676. }
  1677. DRM_DEBUG( "returning NULL!\n" );
  1678. return NULL;
  1679. }
  1680. #if 0
  1681. drm_buf_t *radeon_freelist_get( drm_device_t *dev )
  1682. {
  1683. drm_device_dma_t *dma = dev->dma;
  1684. drm_radeon_private_t *dev_priv = dev->dev_private;
  1685. drm_radeon_buf_priv_t *buf_priv;
  1686. drm_buf_t *buf;
  1687. int i, t;
  1688. int start;
  1689. u32 done_age = DRM_READ32(dev_priv->ring_rptr, RADEON_SCRATCHOFF(1));
  1690. if ( ++dev_priv->last_buf >= dma->buf_count )
  1691. dev_priv->last_buf = 0;
  1692. start = dev_priv->last_buf;
  1693. dev_priv->stats.freelist_loops++;
  1694. for ( t = 0 ; t < 2 ; t++ ) {
  1695. for ( i = start ; i < dma->buf_count ; i++ ) {
  1696. buf = dma->buflist[i];
  1697. buf_priv = buf->dev_private;
  1698. if ( buf->filp == 0 || (buf->pending &&
  1699. buf_priv->age <= done_age) ) {
  1700. dev_priv->stats.requested_bufs++;
  1701. buf->pending = 0;
  1702. return buf;
  1703. }
  1704. }
  1705. start = 0;
  1706. }
  1707. return NULL;
  1708. }
  1709. #endif
  1710. void radeon_freelist_reset( drm_device_t *dev )
  1711. {
  1712. drm_device_dma_t *dma = dev->dma;
  1713. drm_radeon_private_t *dev_priv = dev->dev_private;
  1714. int i;
  1715. dev_priv->last_buf = 0;
  1716. for ( i = 0 ; i < dma->buf_count ; i++ ) {
  1717. drm_buf_t *buf = dma->buflist[i];
  1718. drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
  1719. buf_priv->age = 0;
  1720. }
  1721. }
  1722. /* ================================================================
  1723. * CP command submission
  1724. */
  1725. int radeon_wait_ring( drm_radeon_private_t *dev_priv, int n )
  1726. {
  1727. drm_radeon_ring_buffer_t *ring = &dev_priv->ring;
  1728. int i;
  1729. u32 last_head = GET_RING_HEAD( dev_priv );
  1730. for ( i = 0 ; i < dev_priv->usec_timeout ; i++ ) {
  1731. u32 head = GET_RING_HEAD( dev_priv );
  1732. ring->space = (head - ring->tail) * sizeof(u32);
  1733. if ( ring->space <= 0 )
  1734. ring->space += ring->size;
  1735. if ( ring->space > n )
  1736. return 0;
  1737. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  1738. if (head != last_head)
  1739. i = 0;
  1740. last_head = head;
  1741. DRM_UDELAY( 1 );
  1742. }
  1743. /* FIXME: This return value is ignored in the BEGIN_RING macro! */
  1744. #if RADEON_FIFO_DEBUG
  1745. radeon_status( dev_priv );
  1746. DRM_ERROR( "failed!\n" );
  1747. #endif
  1748. return DRM_ERR(EBUSY);
  1749. }
  1750. static int radeon_cp_get_buffers( DRMFILE filp, drm_device_t *dev, drm_dma_t *d )
  1751. {
  1752. int i;
  1753. drm_buf_t *buf;
  1754. for ( i = d->granted_count ; i < d->request_count ; i++ ) {
  1755. buf = radeon_freelist_get( dev );
  1756. if ( !buf ) return DRM_ERR(EBUSY); /* NOTE: broken client */
  1757. buf->filp = filp;
  1758. if ( DRM_COPY_TO_USER( &d->request_indices[i], &buf->idx,
  1759. sizeof(buf->idx) ) )
  1760. return DRM_ERR(EFAULT);
  1761. if ( DRM_COPY_TO_USER( &d->request_sizes[i], &buf->total,
  1762. sizeof(buf->total) ) )
  1763. return DRM_ERR(EFAULT);
  1764. d->granted_count++;
  1765. }
  1766. return 0;
  1767. }
  1768. int radeon_cp_buffers( DRM_IOCTL_ARGS )
  1769. {
  1770. DRM_DEVICE;
  1771. drm_device_dma_t *dma = dev->dma;
  1772. int ret = 0;
  1773. drm_dma_t __user *argp = (void __user *)data;
  1774. drm_dma_t d;
  1775. LOCK_TEST_WITH_RETURN( dev, filp );
  1776. DRM_COPY_FROM_USER_IOCTL( d, argp, sizeof(d) );
  1777. /* Please don't send us buffers.
  1778. */
  1779. if ( d.send_count != 0 ) {
  1780. DRM_ERROR( "Process %d trying to send %d buffers via drmDMA\n",
  1781. DRM_CURRENTPID, d.send_count );
  1782. return DRM_ERR(EINVAL);
  1783. }
  1784. /* We'll send you buffers.
  1785. */
  1786. if ( d.request_count < 0 || d.request_count > dma->buf_count ) {
  1787. DRM_ERROR( "Process %d trying to get %d buffers (of %d max)\n",
  1788. DRM_CURRENTPID, d.request_count, dma->buf_count );
  1789. return DRM_ERR(EINVAL);
  1790. }
  1791. d.granted_count = 0;
  1792. if ( d.request_count ) {
  1793. ret = radeon_cp_get_buffers( filp, dev, &d );
  1794. }
  1795. DRM_COPY_TO_USER_IOCTL( argp, d, sizeof(d) );
  1796. return ret;
  1797. }
  1798. int radeon_driver_preinit(struct drm_device *dev, unsigned long flags)
  1799. {
  1800. drm_radeon_private_t *dev_priv;
  1801. int ret = 0;
  1802. dev_priv = drm_alloc(sizeof(drm_radeon_private_t), DRM_MEM_DRIVER);
  1803. if (dev_priv == NULL)
  1804. return DRM_ERR(ENOMEM);
  1805. memset(dev_priv, 0, sizeof(drm_radeon_private_t));
  1806. dev->dev_private = (void *)dev_priv;
  1807. dev_priv->flags = flags;
  1808. switch (flags & CHIP_FAMILY_MASK) {
  1809. case CHIP_R100:
  1810. case CHIP_RV200:
  1811. case CHIP_R200:
  1812. case CHIP_R300:
  1813. dev_priv->flags |= CHIP_HAS_HIERZ;
  1814. break;
  1815. default:
  1816. /* all other chips have no hierarchical z buffer */
  1817. break;
  1818. }
  1819. return ret;
  1820. }
  1821. int radeon_driver_postcleanup(struct drm_device *dev)
  1822. {
  1823. drm_radeon_private_t *dev_priv = dev->dev_private;
  1824. DRM_DEBUG("\n");
  1825. drm_free(dev_priv, sizeof(*dev_priv), DRM_MEM_DRIVER);
  1826. dev->dev_private = NULL;
  1827. return 0;
  1828. }