nv20_graph.c 25 KB

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