nv20_graph.c 25 KB

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