nv20_graph.c 24 KB

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