nv20_graph.c 25 KB

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