nv20_graph.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. #include "drmP.h"
  2. #include "drm.h"
  3. #include "nouveau_drv.h"
  4. #include "nouveau_drm.h"
  5. /*
  6. * NV20
  7. * -----
  8. * There are 3 families :
  9. * NV20 is 0x10de:0x020*
  10. * NV25/28 is 0x10de:0x025* / 0x10de:0x028*
  11. * NV2A is 0x10de:0x02A0
  12. *
  13. * NV30
  14. * -----
  15. * There are 3 families :
  16. * NV30/31 is 0x10de:0x030* / 0x10de:0x031*
  17. * NV34 is 0x10de:0x032*
  18. * NV35/36 is 0x10de:0x033* / 0x10de:0x034*
  19. *
  20. * Not seen in the wild, no dumps (probably NV35) :
  21. * NV37 is 0x10de:0x00fc, 0x10de:0x00fd
  22. * NV38 is 0x10de:0x0333, 0x10de:0x00fe
  23. *
  24. */
  25. #define NV20_GRCTX_SIZE (3580*4)
  26. #define NV25_GRCTX_SIZE (3529*4)
  27. #define NV2A_GRCTX_SIZE (3500*4)
  28. #define NV30_31_GRCTX_SIZE (24392)
  29. #define NV34_GRCTX_SIZE (18140)
  30. #define NV35_36_GRCTX_SIZE (22396)
  31. static int nv20_graph_register(struct drm_device *);
  32. static int nv30_graph_register(struct drm_device *);
  33. static void
  34. nv20_graph_context_init(struct drm_device *dev, struct nouveau_gpuobj *ctx)
  35. {
  36. int i;
  37. nv_wo32(ctx, 0x033c, 0xffff0000);
  38. nv_wo32(ctx, 0x03a0, 0x0fff0000);
  39. nv_wo32(ctx, 0x03a4, 0x0fff0000);
  40. nv_wo32(ctx, 0x047c, 0x00000101);
  41. nv_wo32(ctx, 0x0490, 0x00000111);
  42. nv_wo32(ctx, 0x04a8, 0x44400000);
  43. for (i = 0x04d4; i <= 0x04e0; i += 4)
  44. nv_wo32(ctx, i, 0x00030303);
  45. for (i = 0x04f4; i <= 0x0500; i += 4)
  46. nv_wo32(ctx, i, 0x00080000);
  47. for (i = 0x050c; i <= 0x0518; i += 4)
  48. nv_wo32(ctx, i, 0x01012000);
  49. for (i = 0x051c; i <= 0x0528; i += 4)
  50. nv_wo32(ctx, i, 0x000105b8);
  51. for (i = 0x052c; i <= 0x0538; i += 4)
  52. nv_wo32(ctx, i, 0x00080008);
  53. for (i = 0x055c; i <= 0x0598; i += 4)
  54. nv_wo32(ctx, i, 0x07ff0000);
  55. nv_wo32(ctx, 0x05a4, 0x4b7fffff);
  56. nv_wo32(ctx, 0x05fc, 0x00000001);
  57. nv_wo32(ctx, 0x0604, 0x00004000);
  58. nv_wo32(ctx, 0x0610, 0x00000001);
  59. nv_wo32(ctx, 0x0618, 0x00040000);
  60. nv_wo32(ctx, 0x061c, 0x00010000);
  61. for (i = 0x1c1c; i <= 0x248c; i += 16) {
  62. nv_wo32(ctx, (i + 0), 0x10700ff9);
  63. nv_wo32(ctx, (i + 4), 0x0436086c);
  64. nv_wo32(ctx, (i + 8), 0x000c001b);
  65. }
  66. nv_wo32(ctx, 0x281c, 0x3f800000);
  67. nv_wo32(ctx, 0x2830, 0x3f800000);
  68. nv_wo32(ctx, 0x285c, 0x40000000);
  69. nv_wo32(ctx, 0x2860, 0x3f800000);
  70. nv_wo32(ctx, 0x2864, 0x3f000000);
  71. nv_wo32(ctx, 0x286c, 0x40000000);
  72. nv_wo32(ctx, 0x2870, 0x3f800000);
  73. nv_wo32(ctx, 0x2878, 0xbf800000);
  74. nv_wo32(ctx, 0x2880, 0xbf800000);
  75. nv_wo32(ctx, 0x34a4, 0x000fe000);
  76. nv_wo32(ctx, 0x3530, 0x000003f8);
  77. nv_wo32(ctx, 0x3540, 0x002fe000);
  78. for (i = 0x355c; i <= 0x3578; i += 4)
  79. nv_wo32(ctx, i, 0x001c527c);
  80. }
  81. static void
  82. nv25_graph_context_init(struct drm_device *dev, struct nouveau_gpuobj *ctx)
  83. {
  84. int i;
  85. nv_wo32(ctx, 0x035c, 0xffff0000);
  86. nv_wo32(ctx, 0x03c0, 0x0fff0000);
  87. nv_wo32(ctx, 0x03c4, 0x0fff0000);
  88. nv_wo32(ctx, 0x049c, 0x00000101);
  89. nv_wo32(ctx, 0x04b0, 0x00000111);
  90. nv_wo32(ctx, 0x04c8, 0x00000080);
  91. nv_wo32(ctx, 0x04cc, 0xffff0000);
  92. nv_wo32(ctx, 0x04d0, 0x00000001);
  93. nv_wo32(ctx, 0x04e4, 0x44400000);
  94. nv_wo32(ctx, 0x04fc, 0x4b800000);
  95. for (i = 0x0510; i <= 0x051c; i += 4)
  96. nv_wo32(ctx, i, 0x00030303);
  97. for (i = 0x0530; i <= 0x053c; i += 4)
  98. nv_wo32(ctx, i, 0x00080000);
  99. for (i = 0x0548; i <= 0x0554; i += 4)
  100. nv_wo32(ctx, i, 0x01012000);
  101. for (i = 0x0558; i <= 0x0564; i += 4)
  102. nv_wo32(ctx, i, 0x000105b8);
  103. for (i = 0x0568; i <= 0x0574; i += 4)
  104. nv_wo32(ctx, i, 0x00080008);
  105. for (i = 0x0598; i <= 0x05d4; i += 4)
  106. nv_wo32(ctx, i, 0x07ff0000);
  107. nv_wo32(ctx, 0x05e0, 0x4b7fffff);
  108. nv_wo32(ctx, 0x0620, 0x00000080);
  109. nv_wo32(ctx, 0x0624, 0x30201000);
  110. nv_wo32(ctx, 0x0628, 0x70605040);
  111. nv_wo32(ctx, 0x062c, 0xb0a09080);
  112. nv_wo32(ctx, 0x0630, 0xf0e0d0c0);
  113. nv_wo32(ctx, 0x0664, 0x00000001);
  114. nv_wo32(ctx, 0x066c, 0x00004000);
  115. nv_wo32(ctx, 0x0678, 0x00000001);
  116. nv_wo32(ctx, 0x0680, 0x00040000);
  117. nv_wo32(ctx, 0x0684, 0x00010000);
  118. for (i = 0x1b04; i <= 0x2374; i += 16) {
  119. nv_wo32(ctx, (i + 0), 0x10700ff9);
  120. nv_wo32(ctx, (i + 4), 0x0436086c);
  121. nv_wo32(ctx, (i + 8), 0x000c001b);
  122. }
  123. nv_wo32(ctx, 0x2704, 0x3f800000);
  124. nv_wo32(ctx, 0x2718, 0x3f800000);
  125. nv_wo32(ctx, 0x2744, 0x40000000);
  126. nv_wo32(ctx, 0x2748, 0x3f800000);
  127. nv_wo32(ctx, 0x274c, 0x3f000000);
  128. nv_wo32(ctx, 0x2754, 0x40000000);
  129. nv_wo32(ctx, 0x2758, 0x3f800000);
  130. nv_wo32(ctx, 0x2760, 0xbf800000);
  131. nv_wo32(ctx, 0x2768, 0xbf800000);
  132. nv_wo32(ctx, 0x308c, 0x000fe000);
  133. nv_wo32(ctx, 0x3108, 0x000003f8);
  134. nv_wo32(ctx, 0x3468, 0x002fe000);
  135. for (i = 0x3484; i <= 0x34a0; i += 4)
  136. nv_wo32(ctx, i, 0x001c527c);
  137. }
  138. static void
  139. nv2a_graph_context_init(struct drm_device *dev, struct nouveau_gpuobj *ctx)
  140. {
  141. int i;
  142. nv_wo32(ctx, 0x033c, 0xffff0000);
  143. nv_wo32(ctx, 0x03a0, 0x0fff0000);
  144. nv_wo32(ctx, 0x03a4, 0x0fff0000);
  145. nv_wo32(ctx, 0x047c, 0x00000101);
  146. nv_wo32(ctx, 0x0490, 0x00000111);
  147. nv_wo32(ctx, 0x04a8, 0x44400000);
  148. for (i = 0x04d4; i <= 0x04e0; i += 4)
  149. nv_wo32(ctx, i, 0x00030303);
  150. for (i = 0x04f4; i <= 0x0500; i += 4)
  151. nv_wo32(ctx, i, 0x00080000);
  152. for (i = 0x050c; i <= 0x0518; i += 4)
  153. nv_wo32(ctx, i, 0x01012000);
  154. for (i = 0x051c; i <= 0x0528; i += 4)
  155. nv_wo32(ctx, i, 0x000105b8);
  156. for (i = 0x052c; i <= 0x0538; i += 4)
  157. nv_wo32(ctx, i, 0x00080008);
  158. for (i = 0x055c; i <= 0x0598; i += 4)
  159. nv_wo32(ctx, i, 0x07ff0000);
  160. nv_wo32(ctx, 0x05a4, 0x4b7fffff);
  161. nv_wo32(ctx, 0x05fc, 0x00000001);
  162. nv_wo32(ctx, 0x0604, 0x00004000);
  163. nv_wo32(ctx, 0x0610, 0x00000001);
  164. nv_wo32(ctx, 0x0618, 0x00040000);
  165. nv_wo32(ctx, 0x061c, 0x00010000);
  166. for (i = 0x1a9c; i <= 0x22fc; i += 16) { /*XXX: check!! */
  167. nv_wo32(ctx, (i + 0), 0x10700ff9);
  168. nv_wo32(ctx, (i + 4), 0x0436086c);
  169. nv_wo32(ctx, (i + 8), 0x000c001b);
  170. }
  171. nv_wo32(ctx, 0x269c, 0x3f800000);
  172. nv_wo32(ctx, 0x26b0, 0x3f800000);
  173. nv_wo32(ctx, 0x26dc, 0x40000000);
  174. nv_wo32(ctx, 0x26e0, 0x3f800000);
  175. nv_wo32(ctx, 0x26e4, 0x3f000000);
  176. nv_wo32(ctx, 0x26ec, 0x40000000);
  177. nv_wo32(ctx, 0x26f0, 0x3f800000);
  178. nv_wo32(ctx, 0x26f8, 0xbf800000);
  179. nv_wo32(ctx, 0x2700, 0xbf800000);
  180. nv_wo32(ctx, 0x3024, 0x000fe000);
  181. nv_wo32(ctx, 0x30a0, 0x000003f8);
  182. nv_wo32(ctx, 0x33fc, 0x002fe000);
  183. for (i = 0x341c; i <= 0x3438; i += 4)
  184. nv_wo32(ctx, i, 0x001c527c);
  185. }
  186. static void
  187. nv30_31_graph_context_init(struct drm_device *dev, struct nouveau_gpuobj *ctx)
  188. {
  189. int i;
  190. nv_wo32(ctx, 0x0410, 0x00000101);
  191. nv_wo32(ctx, 0x0424, 0x00000111);
  192. nv_wo32(ctx, 0x0428, 0x00000060);
  193. nv_wo32(ctx, 0x0444, 0x00000080);
  194. nv_wo32(ctx, 0x0448, 0xffff0000);
  195. nv_wo32(ctx, 0x044c, 0x00000001);
  196. nv_wo32(ctx, 0x0460, 0x44400000);
  197. nv_wo32(ctx, 0x048c, 0xffff0000);
  198. for (i = 0x04e0; i < 0x04e8; i += 4)
  199. nv_wo32(ctx, i, 0x0fff0000);
  200. nv_wo32(ctx, 0x04ec, 0x00011100);
  201. for (i = 0x0508; i < 0x0548; i += 4)
  202. nv_wo32(ctx, i, 0x07ff0000);
  203. nv_wo32(ctx, 0x0550, 0x4b7fffff);
  204. nv_wo32(ctx, 0x058c, 0x00000080);
  205. nv_wo32(ctx, 0x0590, 0x30201000);
  206. nv_wo32(ctx, 0x0594, 0x70605040);
  207. nv_wo32(ctx, 0x0598, 0xb8a89888);
  208. nv_wo32(ctx, 0x059c, 0xf8e8d8c8);
  209. nv_wo32(ctx, 0x05b0, 0xb0000000);
  210. for (i = 0x0600; i < 0x0640; i += 4)
  211. nv_wo32(ctx, i, 0x00010588);
  212. for (i = 0x0640; i < 0x0680; i += 4)
  213. nv_wo32(ctx, i, 0x00030303);
  214. for (i = 0x06c0; i < 0x0700; i += 4)
  215. nv_wo32(ctx, i, 0x0008aae4);
  216. for (i = 0x0700; i < 0x0740; i += 4)
  217. nv_wo32(ctx, i, 0x01012000);
  218. for (i = 0x0740; i < 0x0780; i += 4)
  219. nv_wo32(ctx, i, 0x00080008);
  220. nv_wo32(ctx, 0x085c, 0x00040000);
  221. nv_wo32(ctx, 0x0860, 0x00010000);
  222. for (i = 0x0864; i < 0x0874; i += 4)
  223. nv_wo32(ctx, i, 0x00040004);
  224. for (i = 0x1f18; i <= 0x3088 ; i += 16) {
  225. nv_wo32(ctx, i + 0, 0x10700ff9);
  226. nv_wo32(ctx, i + 1, 0x0436086c);
  227. nv_wo32(ctx, i + 2, 0x000c001b);
  228. }
  229. for (i = 0x30b8; i < 0x30c8; i += 4)
  230. nv_wo32(ctx, i, 0x0000ffff);
  231. nv_wo32(ctx, 0x344c, 0x3f800000);
  232. nv_wo32(ctx, 0x3808, 0x3f800000);
  233. nv_wo32(ctx, 0x381c, 0x3f800000);
  234. nv_wo32(ctx, 0x3848, 0x40000000);
  235. nv_wo32(ctx, 0x384c, 0x3f800000);
  236. nv_wo32(ctx, 0x3850, 0x3f000000);
  237. nv_wo32(ctx, 0x3858, 0x40000000);
  238. nv_wo32(ctx, 0x385c, 0x3f800000);
  239. nv_wo32(ctx, 0x3864, 0xbf800000);
  240. nv_wo32(ctx, 0x386c, 0xbf800000);
  241. }
  242. static void
  243. nv34_graph_context_init(struct drm_device *dev, struct nouveau_gpuobj *ctx)
  244. {
  245. int i;
  246. nv_wo32(ctx, 0x040c, 0x01000101);
  247. nv_wo32(ctx, 0x0420, 0x00000111);
  248. nv_wo32(ctx, 0x0424, 0x00000060);
  249. nv_wo32(ctx, 0x0440, 0x00000080);
  250. nv_wo32(ctx, 0x0444, 0xffff0000);
  251. nv_wo32(ctx, 0x0448, 0x00000001);
  252. nv_wo32(ctx, 0x045c, 0x44400000);
  253. nv_wo32(ctx, 0x0480, 0xffff0000);
  254. for (i = 0x04d4; i < 0x04dc; i += 4)
  255. nv_wo32(ctx, i, 0x0fff0000);
  256. nv_wo32(ctx, 0x04e0, 0x00011100);
  257. for (i = 0x04fc; i < 0x053c; i += 4)
  258. nv_wo32(ctx, i, 0x07ff0000);
  259. nv_wo32(ctx, 0x0544, 0x4b7fffff);
  260. nv_wo32(ctx, 0x057c, 0x00000080);
  261. nv_wo32(ctx, 0x0580, 0x30201000);
  262. nv_wo32(ctx, 0x0584, 0x70605040);
  263. nv_wo32(ctx, 0x0588, 0xb8a89888);
  264. nv_wo32(ctx, 0x058c, 0xf8e8d8c8);
  265. nv_wo32(ctx, 0x05a0, 0xb0000000);
  266. for (i = 0x05f0; i < 0x0630; i += 4)
  267. nv_wo32(ctx, i, 0x00010588);
  268. for (i = 0x0630; i < 0x0670; i += 4)
  269. nv_wo32(ctx, i, 0x00030303);
  270. for (i = 0x06b0; i < 0x06f0; i += 4)
  271. nv_wo32(ctx, i, 0x0008aae4);
  272. for (i = 0x06f0; i < 0x0730; i += 4)
  273. nv_wo32(ctx, i, 0x01012000);
  274. for (i = 0x0730; i < 0x0770; i += 4)
  275. nv_wo32(ctx, i, 0x00080008);
  276. nv_wo32(ctx, 0x0850, 0x00040000);
  277. nv_wo32(ctx, 0x0854, 0x00010000);
  278. for (i = 0x0858; i < 0x0868; i += 4)
  279. nv_wo32(ctx, i, 0x00040004);
  280. for (i = 0x15ac; i <= 0x271c ; i += 16) {
  281. nv_wo32(ctx, i + 0, 0x10700ff9);
  282. nv_wo32(ctx, i + 1, 0x0436086c);
  283. nv_wo32(ctx, i + 2, 0x000c001b);
  284. }
  285. for (i = 0x274c; i < 0x275c; i += 4)
  286. nv_wo32(ctx, i, 0x0000ffff);
  287. nv_wo32(ctx, 0x2ae0, 0x3f800000);
  288. nv_wo32(ctx, 0x2e9c, 0x3f800000);
  289. nv_wo32(ctx, 0x2eb0, 0x3f800000);
  290. nv_wo32(ctx, 0x2edc, 0x40000000);
  291. nv_wo32(ctx, 0x2ee0, 0x3f800000);
  292. nv_wo32(ctx, 0x2ee4, 0x3f000000);
  293. nv_wo32(ctx, 0x2eec, 0x40000000);
  294. nv_wo32(ctx, 0x2ef0, 0x3f800000);
  295. nv_wo32(ctx, 0x2ef8, 0xbf800000);
  296. nv_wo32(ctx, 0x2f00, 0xbf800000);
  297. }
  298. static void
  299. nv35_36_graph_context_init(struct drm_device *dev, struct nouveau_gpuobj *ctx)
  300. {
  301. int i;
  302. nv_wo32(ctx, 0x040c, 0x00000101);
  303. nv_wo32(ctx, 0x0420, 0x00000111);
  304. nv_wo32(ctx, 0x0424, 0x00000060);
  305. nv_wo32(ctx, 0x0440, 0x00000080);
  306. nv_wo32(ctx, 0x0444, 0xffff0000);
  307. nv_wo32(ctx, 0x0448, 0x00000001);
  308. nv_wo32(ctx, 0x045c, 0x44400000);
  309. nv_wo32(ctx, 0x0488, 0xffff0000);
  310. for (i = 0x04dc; i < 0x04e4; i += 4)
  311. nv_wo32(ctx, i, 0x0fff0000);
  312. nv_wo32(ctx, 0x04e8, 0x00011100);
  313. for (i = 0x0504; i < 0x0544; i += 4)
  314. nv_wo32(ctx, i, 0x07ff0000);
  315. nv_wo32(ctx, 0x054c, 0x4b7fffff);
  316. nv_wo32(ctx, 0x0588, 0x00000080);
  317. nv_wo32(ctx, 0x058c, 0x30201000);
  318. nv_wo32(ctx, 0x0590, 0x70605040);
  319. nv_wo32(ctx, 0x0594, 0xb8a89888);
  320. nv_wo32(ctx, 0x0598, 0xf8e8d8c8);
  321. nv_wo32(ctx, 0x05ac, 0xb0000000);
  322. for (i = 0x0604; i < 0x0644; i += 4)
  323. nv_wo32(ctx, i, 0x00010588);
  324. for (i = 0x0644; i < 0x0684; i += 4)
  325. nv_wo32(ctx, i, 0x00030303);
  326. for (i = 0x06c4; i < 0x0704; i += 4)
  327. nv_wo32(ctx, i, 0x0008aae4);
  328. for (i = 0x0704; i < 0x0744; i += 4)
  329. nv_wo32(ctx, i, 0x01012000);
  330. for (i = 0x0744; i < 0x0784; i += 4)
  331. nv_wo32(ctx, i, 0x00080008);
  332. nv_wo32(ctx, 0x0860, 0x00040000);
  333. nv_wo32(ctx, 0x0864, 0x00010000);
  334. for (i = 0x0868; i < 0x0878; i += 4)
  335. nv_wo32(ctx, i, 0x00040004);
  336. for (i = 0x1f1c; i <= 0x308c ; i += 16) {
  337. nv_wo32(ctx, i + 0, 0x10700ff9);
  338. nv_wo32(ctx, i + 4, 0x0436086c);
  339. nv_wo32(ctx, i + 8, 0x000c001b);
  340. }
  341. for (i = 0x30bc; i < 0x30cc; i += 4)
  342. nv_wo32(ctx, i, 0x0000ffff);
  343. nv_wo32(ctx, 0x3450, 0x3f800000);
  344. nv_wo32(ctx, 0x380c, 0x3f800000);
  345. nv_wo32(ctx, 0x3820, 0x3f800000);
  346. nv_wo32(ctx, 0x384c, 0x40000000);
  347. nv_wo32(ctx, 0x3850, 0x3f800000);
  348. nv_wo32(ctx, 0x3854, 0x3f000000);
  349. nv_wo32(ctx, 0x385c, 0x40000000);
  350. nv_wo32(ctx, 0x3860, 0x3f800000);
  351. nv_wo32(ctx, 0x3868, 0xbf800000);
  352. nv_wo32(ctx, 0x3870, 0xbf800000);
  353. }
  354. int
  355. nv20_graph_create_context(struct nouveau_channel *chan)
  356. {
  357. struct drm_device *dev = chan->dev;
  358. struct drm_nouveau_private *dev_priv = dev->dev_private;
  359. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  360. void (*ctx_init)(struct drm_device *, struct nouveau_gpuobj *);
  361. unsigned int idoffs = 0x28;
  362. int ret;
  363. switch (dev_priv->chipset) {
  364. case 0x20:
  365. ctx_init = nv20_graph_context_init;
  366. idoffs = 0;
  367. break;
  368. case 0x25:
  369. case 0x28:
  370. ctx_init = nv25_graph_context_init;
  371. break;
  372. case 0x2a:
  373. ctx_init = nv2a_graph_context_init;
  374. idoffs = 0;
  375. break;
  376. case 0x30:
  377. case 0x31:
  378. ctx_init = nv30_31_graph_context_init;
  379. break;
  380. case 0x34:
  381. ctx_init = nv34_graph_context_init;
  382. break;
  383. case 0x35:
  384. case 0x36:
  385. ctx_init = nv35_36_graph_context_init;
  386. break;
  387. default:
  388. BUG_ON(1);
  389. }
  390. ret = nouveau_gpuobj_new(dev, chan, pgraph->grctx_size, 16,
  391. NVOBJ_FLAG_ZERO_ALLOC, &chan->ramin_grctx);
  392. if (ret)
  393. return ret;
  394. /* Initialise default context values */
  395. ctx_init(dev, chan->ramin_grctx);
  396. /* nv20: nv_wo32(dev, chan->ramin_grctx->gpuobj, 10, chan->id<<24); */
  397. nv_wo32(chan->ramin_grctx, idoffs,
  398. (chan->id << 24) | 0x1); /* CTX_USER */
  399. nv_wo32(pgraph->ctx_table, chan->id * 4, chan->ramin_grctx->pinst >> 4);
  400. return 0;
  401. }
  402. void
  403. nv20_graph_destroy_context(struct nouveau_channel *chan)
  404. {
  405. struct drm_device *dev = chan->dev;
  406. struct drm_nouveau_private *dev_priv = dev->dev_private;
  407. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  408. unsigned long flags;
  409. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  410. pgraph->fifo_access(dev, false);
  411. /* Unload the context if it's the currently active one */
  412. if (pgraph->channel(dev) == chan)
  413. pgraph->unload_context(dev);
  414. pgraph->fifo_access(dev, true);
  415. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  416. /* Free the context resources */
  417. nv_wo32(pgraph->ctx_table, chan->id * 4, 0);
  418. nouveau_gpuobj_ref(NULL, &chan->ramin_grctx);
  419. }
  420. int
  421. nv20_graph_load_context(struct nouveau_channel *chan)
  422. {
  423. struct drm_device *dev = chan->dev;
  424. uint32_t inst;
  425. if (!chan->ramin_grctx)
  426. return -EINVAL;
  427. inst = chan->ramin_grctx->pinst >> 4;
  428. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
  429. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_XFER,
  430. NV20_PGRAPH_CHANNEL_CTX_XFER_LOAD);
  431. nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10010100);
  432. nouveau_wait_for_idle(dev);
  433. return 0;
  434. }
  435. int
  436. nv20_graph_unload_context(struct drm_device *dev)
  437. {
  438. struct drm_nouveau_private *dev_priv = dev->dev_private;
  439. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  440. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  441. struct nouveau_channel *chan;
  442. uint32_t inst, tmp;
  443. chan = pgraph->channel(dev);
  444. if (!chan)
  445. return 0;
  446. inst = chan->ramin_grctx->pinst >> 4;
  447. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_POINTER, inst);
  448. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_XFER,
  449. NV20_PGRAPH_CHANNEL_CTX_XFER_SAVE);
  450. nouveau_wait_for_idle(dev);
  451. nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10000000);
  452. tmp = nv_rd32(dev, NV10_PGRAPH_CTX_USER) & 0x00ffffff;
  453. tmp |= (pfifo->channels - 1) << 24;
  454. nv_wr32(dev, NV10_PGRAPH_CTX_USER, tmp);
  455. return 0;
  456. }
  457. static void
  458. nv20_graph_rdi(struct drm_device *dev)
  459. {
  460. struct drm_nouveau_private *dev_priv = dev->dev_private;
  461. int i, writecount = 32;
  462. uint32_t rdi_index = 0x2c80000;
  463. if (dev_priv->chipset == 0x20) {
  464. rdi_index = 0x3d0000;
  465. writecount = 15;
  466. }
  467. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, rdi_index);
  468. for (i = 0; i < writecount; i++)
  469. nv_wr32(dev, NV10_PGRAPH_RDI_DATA, 0);
  470. nouveau_wait_for_idle(dev);
  471. }
  472. void
  473. nv20_graph_set_region_tiling(struct drm_device *dev, int i, uint32_t addr,
  474. uint32_t size, uint32_t pitch)
  475. {
  476. uint32_t limit = max(1u, addr + size) - 1;
  477. if (pitch)
  478. addr |= 1;
  479. nv_wr32(dev, NV20_PGRAPH_TLIMIT(i), limit);
  480. nv_wr32(dev, NV20_PGRAPH_TSIZE(i), pitch);
  481. nv_wr32(dev, NV20_PGRAPH_TILE(i), addr);
  482. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA0030 + 4 * i);
  483. nv_wr32(dev, NV10_PGRAPH_RDI_DATA, limit);
  484. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA0050 + 4 * i);
  485. nv_wr32(dev, NV10_PGRAPH_RDI_DATA, pitch);
  486. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA0010 + 4 * i);
  487. nv_wr32(dev, NV10_PGRAPH_RDI_DATA, addr);
  488. }
  489. int
  490. nv20_graph_init(struct drm_device *dev)
  491. {
  492. struct drm_nouveau_private *dev_priv = dev->dev_private;
  493. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  494. uint32_t tmp, vramsz;
  495. int ret, i;
  496. switch (dev_priv->chipset) {
  497. case 0x20:
  498. pgraph->grctx_size = NV20_GRCTX_SIZE;
  499. break;
  500. case 0x25:
  501. case 0x28:
  502. pgraph->grctx_size = NV25_GRCTX_SIZE;
  503. break;
  504. case 0x2a:
  505. pgraph->grctx_size = NV2A_GRCTX_SIZE;
  506. break;
  507. default:
  508. NV_ERROR(dev, "unknown chipset, disabling acceleration\n");
  509. pgraph->accel_blocked = true;
  510. return 0;
  511. }
  512. nv_wr32(dev, NV03_PMC_ENABLE,
  513. nv_rd32(dev, NV03_PMC_ENABLE) & ~NV_PMC_ENABLE_PGRAPH);
  514. nv_wr32(dev, NV03_PMC_ENABLE,
  515. nv_rd32(dev, NV03_PMC_ENABLE) | NV_PMC_ENABLE_PGRAPH);
  516. if (!pgraph->ctx_table) {
  517. /* Create Context Pointer Table */
  518. ret = nouveau_gpuobj_new(dev, NULL, 32 * 4, 16,
  519. NVOBJ_FLAG_ZERO_ALLOC,
  520. &pgraph->ctx_table);
  521. if (ret)
  522. return ret;
  523. }
  524. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_TABLE,
  525. pgraph->ctx_table->pinst >> 4);
  526. nv20_graph_rdi(dev);
  527. ret = nv20_graph_register(dev);
  528. if (ret) {
  529. nouveau_gpuobj_ref(NULL, &pgraph->ctx_table);
  530. return ret;
  531. }
  532. nv_wr32(dev, NV03_PGRAPH_INTR , 0xFFFFFFFF);
  533. nv_wr32(dev, NV03_PGRAPH_INTR_EN, 0xFFFFFFFF);
  534. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF);
  535. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x00000000);
  536. nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x00118700);
  537. nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xF3CE0475); /* 0x4 = auto ctx switch */
  538. nv_wr32(dev, NV10_PGRAPH_DEBUG_4, 0x00000000);
  539. nv_wr32(dev, 0x40009C , 0x00000040);
  540. if (dev_priv->chipset >= 0x25) {
  541. nv_wr32(dev, 0x400890, 0x00080000);
  542. nv_wr32(dev, 0x400610, 0x304B1FB6);
  543. nv_wr32(dev, 0x400B80, 0x18B82880);
  544. nv_wr32(dev, 0x400B84, 0x44000000);
  545. nv_wr32(dev, 0x400098, 0x40000080);
  546. nv_wr32(dev, 0x400B88, 0x000000ff);
  547. } else {
  548. nv_wr32(dev, 0x400880, 0x00080000); /* 0x0008c7df */
  549. nv_wr32(dev, 0x400094, 0x00000005);
  550. nv_wr32(dev, 0x400B80, 0x45CAA208); /* 0x45eae20e */
  551. nv_wr32(dev, 0x400B84, 0x24000000);
  552. nv_wr32(dev, 0x400098, 0x00000040);
  553. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00E00038);
  554. nv_wr32(dev, NV10_PGRAPH_RDI_DATA , 0x00000030);
  555. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00E10038);
  556. nv_wr32(dev, NV10_PGRAPH_RDI_DATA , 0x00000030);
  557. }
  558. /* Turn all the tiling regions off. */
  559. for (i = 0; i < NV10_PFB_TILE__SIZE; i++)
  560. nv20_graph_set_region_tiling(dev, i, 0, 0, 0);
  561. for (i = 0; i < 8; i++) {
  562. nv_wr32(dev, 0x400980 + i * 4, nv_rd32(dev, 0x100300 + i * 4));
  563. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA0090 + i * 4);
  564. nv_wr32(dev, NV10_PGRAPH_RDI_DATA,
  565. nv_rd32(dev, 0x100300 + i * 4));
  566. }
  567. nv_wr32(dev, 0x4009a0, nv_rd32(dev, 0x100324));
  568. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA000C);
  569. nv_wr32(dev, NV10_PGRAPH_RDI_DATA, nv_rd32(dev, 0x100324));
  570. nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10000100);
  571. nv_wr32(dev, NV10_PGRAPH_STATE , 0xFFFFFFFF);
  572. tmp = nv_rd32(dev, NV10_PGRAPH_SURFACE) & 0x0007ff00;
  573. nv_wr32(dev, NV10_PGRAPH_SURFACE, tmp);
  574. tmp = nv_rd32(dev, NV10_PGRAPH_SURFACE) | 0x00020100;
  575. nv_wr32(dev, NV10_PGRAPH_SURFACE, tmp);
  576. /* begin RAM config */
  577. vramsz = pci_resource_len(dev->pdev, 0) - 1;
  578. nv_wr32(dev, 0x4009A4, nv_rd32(dev, NV04_PFB_CFG0));
  579. nv_wr32(dev, 0x4009A8, nv_rd32(dev, NV04_PFB_CFG1));
  580. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA0000);
  581. nv_wr32(dev, NV10_PGRAPH_RDI_DATA , nv_rd32(dev, NV04_PFB_CFG0));
  582. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA0004);
  583. nv_wr32(dev, NV10_PGRAPH_RDI_DATA , nv_rd32(dev, NV04_PFB_CFG1));
  584. nv_wr32(dev, 0x400820, 0);
  585. nv_wr32(dev, 0x400824, 0);
  586. nv_wr32(dev, 0x400864, vramsz - 1);
  587. nv_wr32(dev, 0x400868, vramsz - 1);
  588. /* interesting.. the below overwrites some of the tile setup above.. */
  589. nv_wr32(dev, 0x400B20, 0x00000000);
  590. nv_wr32(dev, 0x400B04, 0xFFFFFFFF);
  591. nv_wr32(dev, NV03_PGRAPH_ABS_UCLIP_XMIN, 0);
  592. nv_wr32(dev, NV03_PGRAPH_ABS_UCLIP_YMIN, 0);
  593. nv_wr32(dev, NV03_PGRAPH_ABS_UCLIP_XMAX, 0x7fff);
  594. nv_wr32(dev, NV03_PGRAPH_ABS_UCLIP_YMAX, 0x7fff);
  595. return 0;
  596. }
  597. void
  598. nv20_graph_takedown(struct drm_device *dev)
  599. {
  600. struct drm_nouveau_private *dev_priv = dev->dev_private;
  601. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  602. nouveau_gpuobj_ref(NULL, &pgraph->ctx_table);
  603. }
  604. int
  605. nv30_graph_init(struct drm_device *dev)
  606. {
  607. struct drm_nouveau_private *dev_priv = dev->dev_private;
  608. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  609. int ret, i;
  610. switch (dev_priv->chipset) {
  611. case 0x30:
  612. case 0x31:
  613. pgraph->grctx_size = NV30_31_GRCTX_SIZE;
  614. break;
  615. case 0x34:
  616. pgraph->grctx_size = NV34_GRCTX_SIZE;
  617. break;
  618. case 0x35:
  619. case 0x36:
  620. pgraph->grctx_size = NV35_36_GRCTX_SIZE;
  621. break;
  622. default:
  623. NV_ERROR(dev, "unknown chipset, disabling acceleration\n");
  624. pgraph->accel_blocked = true;
  625. return 0;
  626. }
  627. nv_wr32(dev, NV03_PMC_ENABLE,
  628. nv_rd32(dev, NV03_PMC_ENABLE) & ~NV_PMC_ENABLE_PGRAPH);
  629. nv_wr32(dev, NV03_PMC_ENABLE,
  630. nv_rd32(dev, NV03_PMC_ENABLE) | NV_PMC_ENABLE_PGRAPH);
  631. if (!pgraph->ctx_table) {
  632. /* Create Context Pointer Table */
  633. ret = nouveau_gpuobj_new(dev, NULL, 32 * 4, 16,
  634. NVOBJ_FLAG_ZERO_ALLOC,
  635. &pgraph->ctx_table);
  636. if (ret)
  637. return ret;
  638. }
  639. ret = nv30_graph_register(dev);
  640. if (ret) {
  641. nouveau_gpuobj_ref(NULL, &pgraph->ctx_table);
  642. return ret;
  643. }
  644. nv_wr32(dev, NV20_PGRAPH_CHANNEL_CTX_TABLE,
  645. pgraph->ctx_table->pinst >> 4);
  646. nv_wr32(dev, NV03_PGRAPH_INTR , 0xFFFFFFFF);
  647. nv_wr32(dev, NV03_PGRAPH_INTR_EN, 0xFFFFFFFF);
  648. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0xFFFFFFFF);
  649. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x00000000);
  650. nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x401287c0);
  651. nv_wr32(dev, 0x400890, 0x01b463ff);
  652. nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xf2de0475);
  653. nv_wr32(dev, NV10_PGRAPH_DEBUG_4, 0x00008000);
  654. nv_wr32(dev, NV04_PGRAPH_LIMIT_VIOL_PIX, 0xf04bdff6);
  655. nv_wr32(dev, 0x400B80, 0x1003d888);
  656. nv_wr32(dev, 0x400B84, 0x0c000000);
  657. nv_wr32(dev, 0x400098, 0x00000000);
  658. nv_wr32(dev, 0x40009C, 0x0005ad00);
  659. nv_wr32(dev, 0x400B88, 0x62ff00ff); /* suspiciously like PGRAPH_DEBUG_2 */
  660. nv_wr32(dev, 0x4000a0, 0x00000000);
  661. nv_wr32(dev, 0x4000a4, 0x00000008);
  662. nv_wr32(dev, 0x4008a8, 0xb784a400);
  663. nv_wr32(dev, 0x400ba0, 0x002f8685);
  664. nv_wr32(dev, 0x400ba4, 0x00231f3f);
  665. nv_wr32(dev, 0x4008a4, 0x40000020);
  666. if (dev_priv->chipset == 0x34) {
  667. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA0004);
  668. nv_wr32(dev, NV10_PGRAPH_RDI_DATA , 0x00200201);
  669. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA0008);
  670. nv_wr32(dev, NV10_PGRAPH_RDI_DATA , 0x00000008);
  671. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00EA0000);
  672. nv_wr32(dev, NV10_PGRAPH_RDI_DATA , 0x00000032);
  673. nv_wr32(dev, NV10_PGRAPH_RDI_INDEX, 0x00E00004);
  674. nv_wr32(dev, NV10_PGRAPH_RDI_DATA , 0x00000002);
  675. }
  676. nv_wr32(dev, 0x4000c0, 0x00000016);
  677. /* Turn all the tiling regions off. */
  678. for (i = 0; i < NV10_PFB_TILE__SIZE; i++)
  679. nv20_graph_set_region_tiling(dev, i, 0, 0, 0);
  680. nv_wr32(dev, NV10_PGRAPH_CTX_CONTROL, 0x10000100);
  681. nv_wr32(dev, NV10_PGRAPH_STATE , 0xFFFFFFFF);
  682. nv_wr32(dev, 0x0040075c , 0x00000001);
  683. /* begin RAM config */
  684. /* vramsz = pci_resource_len(dev->pdev, 0) - 1; */
  685. nv_wr32(dev, 0x4009A4, nv_rd32(dev, NV04_PFB_CFG0));
  686. nv_wr32(dev, 0x4009A8, nv_rd32(dev, NV04_PFB_CFG1));
  687. if (dev_priv->chipset != 0x34) {
  688. nv_wr32(dev, 0x400750, 0x00EA0000);
  689. nv_wr32(dev, 0x400754, nv_rd32(dev, NV04_PFB_CFG0));
  690. nv_wr32(dev, 0x400750, 0x00EA0004);
  691. nv_wr32(dev, 0x400754, nv_rd32(dev, NV04_PFB_CFG1));
  692. }
  693. return 0;
  694. }
  695. static int
  696. nv20_graph_register(struct drm_device *dev)
  697. {
  698. struct drm_nouveau_private *dev_priv = dev->dev_private;
  699. if (dev_priv->engine.graph.registered)
  700. return 0;
  701. NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
  702. NVOBJ_CLASS(dev, 0x0030, GR); /* null */
  703. NVOBJ_CLASS(dev, 0x0039, GR); /* m2mf */
  704. NVOBJ_CLASS(dev, 0x004a, GR); /* gdirect */
  705. NVOBJ_CLASS(dev, 0x009f, GR); /* imageblit (nv12) */
  706. NVOBJ_CLASS(dev, 0x008a, GR); /* ifc */
  707. NVOBJ_CLASS(dev, 0x0089, GR); /* sifm */
  708. NVOBJ_CLASS(dev, 0x0062, GR); /* surf2d */
  709. NVOBJ_CLASS(dev, 0x0043, GR); /* rop */
  710. NVOBJ_CLASS(dev, 0x0012, GR); /* beta1 */
  711. NVOBJ_CLASS(dev, 0x0072, GR); /* beta4 */
  712. NVOBJ_CLASS(dev, 0x0019, GR); /* cliprect */
  713. NVOBJ_CLASS(dev, 0x0044, GR); /* pattern */
  714. NVOBJ_CLASS(dev, 0x009e, GR); /* swzsurf */
  715. NVOBJ_CLASS(dev, 0x0096, GR); /* celcius */
  716. /* kelvin */
  717. if (dev_priv->chipset < 0x25)
  718. NVOBJ_CLASS(dev, 0x0097, GR);
  719. else
  720. NVOBJ_CLASS(dev, 0x0597, GR);
  721. dev_priv->engine.graph.registered = true;
  722. return 0;
  723. }
  724. static int
  725. nv30_graph_register(struct drm_device *dev)
  726. {
  727. struct drm_nouveau_private *dev_priv = dev->dev_private;
  728. if (dev_priv->engine.graph.registered)
  729. return 0;
  730. NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
  731. NVOBJ_CLASS(dev, 0x0030, GR); /* null */
  732. NVOBJ_CLASS(dev, 0x0039, GR); /* m2mf */
  733. NVOBJ_CLASS(dev, 0x004a, GR); /* gdirect */
  734. NVOBJ_CLASS(dev, 0x009f, GR); /* imageblit (nv12) */
  735. NVOBJ_CLASS(dev, 0x008a, GR); /* ifc */
  736. NVOBJ_CLASS(dev, 0x038a, GR); /* ifc (nv30) */
  737. NVOBJ_CLASS(dev, 0x0089, GR); /* sifm */
  738. NVOBJ_CLASS(dev, 0x0389, GR); /* sifm (nv30) */
  739. NVOBJ_CLASS(dev, 0x0062, GR); /* surf2d */
  740. NVOBJ_CLASS(dev, 0x0362, GR); /* surf2d (nv30) */
  741. NVOBJ_CLASS(dev, 0x0043, GR); /* rop */
  742. NVOBJ_CLASS(dev, 0x0012, GR); /* beta1 */
  743. NVOBJ_CLASS(dev, 0x0072, GR); /* beta4 */
  744. NVOBJ_CLASS(dev, 0x0019, GR); /* cliprect */
  745. NVOBJ_CLASS(dev, 0x0044, GR); /* pattern */
  746. NVOBJ_CLASS(dev, 0x039e, GR); /* swzsurf */
  747. /* rankine */
  748. if (0x00000003 & (1 << (dev_priv->chipset & 0x0f)))
  749. NVOBJ_CLASS(dev, 0x0397, GR);
  750. else
  751. if (0x00000010 & (1 << (dev_priv->chipset & 0x0f)))
  752. NVOBJ_CLASS(dev, 0x0697, GR);
  753. else
  754. if (0x000001e0 & (1 << (dev_priv->chipset & 0x0f)))
  755. NVOBJ_CLASS(dev, 0x0497, GR);
  756. dev_priv->engine.graph.registered = true;
  757. return 0;
  758. }