nv40_grctx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. /*
  2. * Copyright 2009 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. /* NVIDIA context programs handle a number of other conditions which are
  25. * not implemented in our versions. It's not clear why NVIDIA context
  26. * programs have this code, nor whether it's strictly necessary for
  27. * correct operation. We'll implement additional handling if/when we
  28. * discover it's necessary.
  29. *
  30. * - On context save, NVIDIA set 0x400314 bit 0 to 1 if the "3D state"
  31. * flag is set, this gets saved into the context.
  32. * - On context save, the context program for all cards load nsource
  33. * into a flag register and check for ILLEGAL_MTHD. If it's set,
  34. * opcode 0x60000d is called before resuming normal operation.
  35. * - Some context programs check more conditions than the above. NV44
  36. * checks: ((nsource & 0x0857) || (0x400718 & 0x0100) || (intr & 0x0001))
  37. * and calls 0x60000d before resuming normal operation.
  38. * - At the very beginning of NVIDIA's context programs, flag 9 is checked
  39. * and if true 0x800001 is called with count=0, pos=0, the flag is cleared
  40. * and then the ctxprog is aborted. It looks like a complicated NOP,
  41. * its purpose is unknown.
  42. * - In the section of code that loads the per-vs state, NVIDIA check
  43. * flag 10. If it's set, they only transfer the small 0x300 byte block
  44. * of state + the state for a single vs as opposed to the state for
  45. * all vs units. It doesn't seem likely that it'll occur in normal
  46. * operation, especially seeing as it appears NVIDIA may have screwed
  47. * up the ctxprogs for some cards and have an invalid instruction
  48. * rather than a cp_lsr(ctx, dwords_for_1_vs_unit) instruction.
  49. * - There's a number of places where context offset 0 (where we place
  50. * the PRAMIN offset of the context) is loaded into either 0x408000,
  51. * 0x408004 or 0x408008. Not sure what's up there either.
  52. * - The ctxprogs for some cards save 0x400a00 again during the cleanup
  53. * path for auto-loadctx.
  54. */
  55. #define CP_FLAG_CLEAR 0
  56. #define CP_FLAG_SET 1
  57. #define CP_FLAG_SWAP_DIRECTION ((0 * 32) + 0)
  58. #define CP_FLAG_SWAP_DIRECTION_LOAD 0
  59. #define CP_FLAG_SWAP_DIRECTION_SAVE 1
  60. #define CP_FLAG_USER_SAVE ((0 * 32) + 5)
  61. #define CP_FLAG_USER_SAVE_NOT_PENDING 0
  62. #define CP_FLAG_USER_SAVE_PENDING 1
  63. #define CP_FLAG_USER_LOAD ((0 * 32) + 6)
  64. #define CP_FLAG_USER_LOAD_NOT_PENDING 0
  65. #define CP_FLAG_USER_LOAD_PENDING 1
  66. #define CP_FLAG_STATUS ((3 * 32) + 0)
  67. #define CP_FLAG_STATUS_IDLE 0
  68. #define CP_FLAG_STATUS_BUSY 1
  69. #define CP_FLAG_AUTO_SAVE ((3 * 32) + 4)
  70. #define CP_FLAG_AUTO_SAVE_NOT_PENDING 0
  71. #define CP_FLAG_AUTO_SAVE_PENDING 1
  72. #define CP_FLAG_AUTO_LOAD ((3 * 32) + 5)
  73. #define CP_FLAG_AUTO_LOAD_NOT_PENDING 0
  74. #define CP_FLAG_AUTO_LOAD_PENDING 1
  75. #define CP_FLAG_UNK54 ((3 * 32) + 6)
  76. #define CP_FLAG_UNK54_CLEAR 0
  77. #define CP_FLAG_UNK54_SET 1
  78. #define CP_FLAG_ALWAYS ((3 * 32) + 8)
  79. #define CP_FLAG_ALWAYS_FALSE 0
  80. #define CP_FLAG_ALWAYS_TRUE 1
  81. #define CP_FLAG_UNK57 ((3 * 32) + 9)
  82. #define CP_FLAG_UNK57_CLEAR 0
  83. #define CP_FLAG_UNK57_SET 1
  84. #define CP_CTX 0x00100000
  85. #define CP_CTX_COUNT 0x000fc000
  86. #define CP_CTX_COUNT_SHIFT 14
  87. #define CP_CTX_REG 0x00003fff
  88. #define CP_LOAD_SR 0x00200000
  89. #define CP_LOAD_SR_VALUE 0x000fffff
  90. #define CP_BRA 0x00400000
  91. #define CP_BRA_IP 0x0000ff00
  92. #define CP_BRA_IP_SHIFT 8
  93. #define CP_BRA_IF_CLEAR 0x00000080
  94. #define CP_BRA_FLAG 0x0000007f
  95. #define CP_WAIT 0x00500000
  96. #define CP_WAIT_SET 0x00000080
  97. #define CP_WAIT_FLAG 0x0000007f
  98. #define CP_SET 0x00700000
  99. #define CP_SET_1 0x00000080
  100. #define CP_SET_FLAG 0x0000007f
  101. #define CP_NEXT_TO_SWAP 0x00600007
  102. #define CP_NEXT_TO_CURRENT 0x00600009
  103. #define CP_SET_CONTEXT_POINTER 0x0060000a
  104. #define CP_END 0x0060000e
  105. #define CP_LOAD_MAGIC_UNK01 0x00800001 /* unknown */
  106. #define CP_LOAD_MAGIC_NV44TCL 0x00800029 /* per-vs state (0x4497) */
  107. #define CP_LOAD_MAGIC_NV40TCL 0x00800041 /* per-vs state (0x4097) */
  108. #include "drmP.h"
  109. #include "nouveau_drv.h"
  110. #include "nouveau_grctx.h"
  111. /* TODO:
  112. * - get vs count from 0x1540
  113. */
  114. static int
  115. nv40_graph_4097(struct drm_device *dev)
  116. {
  117. struct drm_nouveau_private *dev_priv = dev->dev_private;
  118. if ((dev_priv->chipset & 0xf0) == 0x60)
  119. return 0;
  120. return !!(0x0baf & (1 << dev_priv->chipset));
  121. }
  122. static int
  123. nv40_graph_vs_count(struct drm_device *dev)
  124. {
  125. struct drm_nouveau_private *dev_priv = dev->dev_private;
  126. switch (dev_priv->chipset) {
  127. case 0x47:
  128. case 0x49:
  129. case 0x4b:
  130. return 8;
  131. case 0x40:
  132. return 6;
  133. case 0x41:
  134. case 0x42:
  135. return 5;
  136. case 0x43:
  137. case 0x44:
  138. case 0x46:
  139. case 0x4a:
  140. return 3;
  141. case 0x4c:
  142. case 0x4e:
  143. case 0x67:
  144. default:
  145. return 1;
  146. }
  147. }
  148. enum cp_label {
  149. cp_check_load = 1,
  150. cp_setup_auto_load,
  151. cp_setup_load,
  152. cp_setup_save,
  153. cp_swap_state,
  154. cp_swap_state3d_3_is_save,
  155. cp_prepare_exit,
  156. cp_exit,
  157. };
  158. static void
  159. nv40_graph_construct_general(struct nouveau_grctx *ctx)
  160. {
  161. struct drm_nouveau_private *dev_priv = ctx->dev->dev_private;
  162. int i;
  163. cp_ctx(ctx, 0x4000a4, 1);
  164. gr_def(ctx, 0x4000a4, 0x00000008);
  165. cp_ctx(ctx, 0x400144, 58);
  166. gr_def(ctx, 0x400144, 0x00000001);
  167. cp_ctx(ctx, 0x400314, 1);
  168. gr_def(ctx, 0x400314, 0x00000000);
  169. cp_ctx(ctx, 0x400400, 10);
  170. cp_ctx(ctx, 0x400480, 10);
  171. cp_ctx(ctx, 0x400500, 19);
  172. gr_def(ctx, 0x400514, 0x00040000);
  173. gr_def(ctx, 0x400524, 0x55555555);
  174. gr_def(ctx, 0x400528, 0x55555555);
  175. gr_def(ctx, 0x40052c, 0x55555555);
  176. gr_def(ctx, 0x400530, 0x55555555);
  177. cp_ctx(ctx, 0x400560, 6);
  178. gr_def(ctx, 0x400568, 0x0000ffff);
  179. gr_def(ctx, 0x40056c, 0x0000ffff);
  180. cp_ctx(ctx, 0x40057c, 5);
  181. cp_ctx(ctx, 0x400710, 3);
  182. gr_def(ctx, 0x400710, 0x20010001);
  183. gr_def(ctx, 0x400714, 0x0f73ef00);
  184. cp_ctx(ctx, 0x400724, 1);
  185. gr_def(ctx, 0x400724, 0x02008821);
  186. cp_ctx(ctx, 0x400770, 3);
  187. if (dev_priv->chipset == 0x40) {
  188. cp_ctx(ctx, 0x400814, 4);
  189. cp_ctx(ctx, 0x400828, 5);
  190. cp_ctx(ctx, 0x400840, 5);
  191. gr_def(ctx, 0x400850, 0x00000040);
  192. cp_ctx(ctx, 0x400858, 4);
  193. gr_def(ctx, 0x400858, 0x00000040);
  194. gr_def(ctx, 0x40085c, 0x00000040);
  195. gr_def(ctx, 0x400864, 0x80000000);
  196. cp_ctx(ctx, 0x40086c, 9);
  197. gr_def(ctx, 0x40086c, 0x80000000);
  198. gr_def(ctx, 0x400870, 0x80000000);
  199. gr_def(ctx, 0x400874, 0x80000000);
  200. gr_def(ctx, 0x400878, 0x80000000);
  201. gr_def(ctx, 0x400888, 0x00000040);
  202. gr_def(ctx, 0x40088c, 0x80000000);
  203. cp_ctx(ctx, 0x4009c0, 8);
  204. gr_def(ctx, 0x4009cc, 0x80000000);
  205. gr_def(ctx, 0x4009dc, 0x80000000);
  206. } else {
  207. cp_ctx(ctx, 0x400840, 20);
  208. if (!nv40_graph_4097(ctx->dev)) {
  209. for (i = 0; i < 8; i++)
  210. gr_def(ctx, 0x400860 + (i * 4), 0x00000001);
  211. }
  212. gr_def(ctx, 0x400880, 0x00000040);
  213. gr_def(ctx, 0x400884, 0x00000040);
  214. gr_def(ctx, 0x400888, 0x00000040);
  215. cp_ctx(ctx, 0x400894, 11);
  216. gr_def(ctx, 0x400894, 0x00000040);
  217. if (nv40_graph_4097(ctx->dev)) {
  218. for (i = 0; i < 8; i++)
  219. gr_def(ctx, 0x4008a0 + (i * 4), 0x80000000);
  220. }
  221. cp_ctx(ctx, 0x4008e0, 2);
  222. cp_ctx(ctx, 0x4008f8, 2);
  223. if (dev_priv->chipset == 0x4c ||
  224. (dev_priv->chipset & 0xf0) == 0x60)
  225. cp_ctx(ctx, 0x4009f8, 1);
  226. }
  227. cp_ctx(ctx, 0x400a00, 73);
  228. gr_def(ctx, 0x400b0c, 0x0b0b0b0c);
  229. cp_ctx(ctx, 0x401000, 4);
  230. cp_ctx(ctx, 0x405004, 1);
  231. switch (dev_priv->chipset) {
  232. case 0x47:
  233. case 0x49:
  234. case 0x4b:
  235. cp_ctx(ctx, 0x403448, 1);
  236. gr_def(ctx, 0x403448, 0x00001010);
  237. break;
  238. default:
  239. cp_ctx(ctx, 0x403440, 1);
  240. switch (dev_priv->chipset) {
  241. case 0x40:
  242. gr_def(ctx, 0x403440, 0x00000010);
  243. break;
  244. case 0x44:
  245. case 0x46:
  246. case 0x4a:
  247. gr_def(ctx, 0x403440, 0x00003010);
  248. break;
  249. case 0x41:
  250. case 0x42:
  251. case 0x43:
  252. case 0x4c:
  253. case 0x4e:
  254. case 0x67:
  255. default:
  256. gr_def(ctx, 0x403440, 0x00001010);
  257. break;
  258. }
  259. break;
  260. }
  261. }
  262. static void
  263. nv40_graph_construct_state3d(struct nouveau_grctx *ctx)
  264. {
  265. struct drm_nouveau_private *dev_priv = ctx->dev->dev_private;
  266. int i;
  267. if (dev_priv->chipset == 0x40) {
  268. cp_ctx(ctx, 0x401880, 51);
  269. gr_def(ctx, 0x401940, 0x00000100);
  270. } else
  271. if (dev_priv->chipset == 0x46 || dev_priv->chipset == 0x47 ||
  272. dev_priv->chipset == 0x49 || dev_priv->chipset == 0x4b) {
  273. cp_ctx(ctx, 0x401880, 32);
  274. for (i = 0; i < 16; i++)
  275. gr_def(ctx, 0x401880 + (i * 4), 0x00000111);
  276. if (dev_priv->chipset == 0x46)
  277. cp_ctx(ctx, 0x401900, 16);
  278. cp_ctx(ctx, 0x401940, 3);
  279. }
  280. cp_ctx(ctx, 0x40194c, 18);
  281. gr_def(ctx, 0x401954, 0x00000111);
  282. gr_def(ctx, 0x401958, 0x00080060);
  283. gr_def(ctx, 0x401974, 0x00000080);
  284. gr_def(ctx, 0x401978, 0xffff0000);
  285. gr_def(ctx, 0x40197c, 0x00000001);
  286. gr_def(ctx, 0x401990, 0x46400000);
  287. if (dev_priv->chipset == 0x40) {
  288. cp_ctx(ctx, 0x4019a0, 2);
  289. cp_ctx(ctx, 0x4019ac, 5);
  290. } else {
  291. cp_ctx(ctx, 0x4019a0, 1);
  292. cp_ctx(ctx, 0x4019b4, 3);
  293. }
  294. gr_def(ctx, 0x4019bc, 0xffff0000);
  295. switch (dev_priv->chipset) {
  296. case 0x46:
  297. case 0x47:
  298. case 0x49:
  299. case 0x4b:
  300. cp_ctx(ctx, 0x4019c0, 18);
  301. for (i = 0; i < 16; i++)
  302. gr_def(ctx, 0x4019c0 + (i * 4), 0x88888888);
  303. break;
  304. }
  305. cp_ctx(ctx, 0x401a08, 8);
  306. gr_def(ctx, 0x401a10, 0x0fff0000);
  307. gr_def(ctx, 0x401a14, 0x0fff0000);
  308. gr_def(ctx, 0x401a1c, 0x00011100);
  309. cp_ctx(ctx, 0x401a2c, 4);
  310. cp_ctx(ctx, 0x401a44, 26);
  311. for (i = 0; i < 16; i++)
  312. gr_def(ctx, 0x401a44 + (i * 4), 0x07ff0000);
  313. gr_def(ctx, 0x401a8c, 0x4b7fffff);
  314. if (dev_priv->chipset == 0x40) {
  315. cp_ctx(ctx, 0x401ab8, 3);
  316. } else {
  317. cp_ctx(ctx, 0x401ab8, 1);
  318. cp_ctx(ctx, 0x401ac0, 1);
  319. }
  320. cp_ctx(ctx, 0x401ad0, 8);
  321. gr_def(ctx, 0x401ad0, 0x30201000);
  322. gr_def(ctx, 0x401ad4, 0x70605040);
  323. gr_def(ctx, 0x401ad8, 0xb8a89888);
  324. gr_def(ctx, 0x401adc, 0xf8e8d8c8);
  325. cp_ctx(ctx, 0x401b10, dev_priv->chipset == 0x40 ? 2 : 1);
  326. gr_def(ctx, 0x401b10, 0x40100000);
  327. cp_ctx(ctx, 0x401b18, dev_priv->chipset == 0x40 ? 6 : 5);
  328. gr_def(ctx, 0x401b28, dev_priv->chipset == 0x40 ?
  329. 0x00000004 : 0x00000000);
  330. cp_ctx(ctx, 0x401b30, 25);
  331. gr_def(ctx, 0x401b34, 0x0000ffff);
  332. gr_def(ctx, 0x401b68, 0x435185d6);
  333. gr_def(ctx, 0x401b6c, 0x2155b699);
  334. gr_def(ctx, 0x401b70, 0xfedcba98);
  335. gr_def(ctx, 0x401b74, 0x00000098);
  336. gr_def(ctx, 0x401b84, 0xffffffff);
  337. gr_def(ctx, 0x401b88, 0x00ff7000);
  338. gr_def(ctx, 0x401b8c, 0x0000ffff);
  339. if (dev_priv->chipset != 0x44 && dev_priv->chipset != 0x4a &&
  340. dev_priv->chipset != 0x4e)
  341. cp_ctx(ctx, 0x401b94, 1);
  342. cp_ctx(ctx, 0x401b98, 8);
  343. gr_def(ctx, 0x401b9c, 0x00ff0000);
  344. cp_ctx(ctx, 0x401bc0, 9);
  345. gr_def(ctx, 0x401be0, 0x00ffff00);
  346. cp_ctx(ctx, 0x401c00, 192);
  347. for (i = 0; i < 16; i++) { /* fragment texture units */
  348. gr_def(ctx, 0x401c40 + (i * 4), 0x00018488);
  349. gr_def(ctx, 0x401c80 + (i * 4), 0x00028202);
  350. gr_def(ctx, 0x401d00 + (i * 4), 0x0000aae4);
  351. gr_def(ctx, 0x401d40 + (i * 4), 0x01012000);
  352. gr_def(ctx, 0x401d80 + (i * 4), 0x00080008);
  353. gr_def(ctx, 0x401e00 + (i * 4), 0x00100008);
  354. }
  355. for (i = 0; i < 4; i++) { /* vertex texture units */
  356. gr_def(ctx, 0x401e90 + (i * 4), 0x0001bc80);
  357. gr_def(ctx, 0x401ea0 + (i * 4), 0x00000202);
  358. gr_def(ctx, 0x401ec0 + (i * 4), 0x00000008);
  359. gr_def(ctx, 0x401ee0 + (i * 4), 0x00080008);
  360. }
  361. cp_ctx(ctx, 0x400f5c, 3);
  362. gr_def(ctx, 0x400f5c, 0x00000002);
  363. cp_ctx(ctx, 0x400f84, 1);
  364. }
  365. static void
  366. nv40_graph_construct_state3d_2(struct nouveau_grctx *ctx)
  367. {
  368. struct drm_nouveau_private *dev_priv = ctx->dev->dev_private;
  369. int i;
  370. cp_ctx(ctx, 0x402000, 1);
  371. cp_ctx(ctx, 0x402404, dev_priv->chipset == 0x40 ? 1 : 2);
  372. switch (dev_priv->chipset) {
  373. case 0x40:
  374. gr_def(ctx, 0x402404, 0x00000001);
  375. break;
  376. case 0x4c:
  377. case 0x4e:
  378. case 0x67:
  379. gr_def(ctx, 0x402404, 0x00000020);
  380. break;
  381. case 0x46:
  382. case 0x49:
  383. case 0x4b:
  384. gr_def(ctx, 0x402404, 0x00000421);
  385. break;
  386. default:
  387. gr_def(ctx, 0x402404, 0x00000021);
  388. }
  389. if (dev_priv->chipset != 0x40)
  390. gr_def(ctx, 0x402408, 0x030c30c3);
  391. switch (dev_priv->chipset) {
  392. case 0x44:
  393. case 0x46:
  394. case 0x4a:
  395. case 0x4c:
  396. case 0x4e:
  397. case 0x67:
  398. cp_ctx(ctx, 0x402440, 1);
  399. gr_def(ctx, 0x402440, 0x00011001);
  400. break;
  401. default:
  402. break;
  403. }
  404. cp_ctx(ctx, 0x402480, dev_priv->chipset == 0x40 ? 8 : 9);
  405. gr_def(ctx, 0x402488, 0x3e020200);
  406. gr_def(ctx, 0x40248c, 0x00ffffff);
  407. switch (dev_priv->chipset) {
  408. case 0x40:
  409. gr_def(ctx, 0x402490, 0x60103f00);
  410. break;
  411. case 0x47:
  412. gr_def(ctx, 0x402490, 0x40103f00);
  413. break;
  414. case 0x41:
  415. case 0x42:
  416. case 0x49:
  417. case 0x4b:
  418. gr_def(ctx, 0x402490, 0x20103f00);
  419. break;
  420. default:
  421. gr_def(ctx, 0x402490, 0x0c103f00);
  422. break;
  423. }
  424. gr_def(ctx, 0x40249c, dev_priv->chipset <= 0x43 ?
  425. 0x00020000 : 0x00040000);
  426. cp_ctx(ctx, 0x402500, 31);
  427. gr_def(ctx, 0x402530, 0x00008100);
  428. if (dev_priv->chipset == 0x40)
  429. cp_ctx(ctx, 0x40257c, 6);
  430. cp_ctx(ctx, 0x402594, 16);
  431. cp_ctx(ctx, 0x402800, 17);
  432. gr_def(ctx, 0x402800, 0x00000001);
  433. switch (dev_priv->chipset) {
  434. case 0x47:
  435. case 0x49:
  436. case 0x4b:
  437. cp_ctx(ctx, 0x402864, 1);
  438. gr_def(ctx, 0x402864, 0x00001001);
  439. cp_ctx(ctx, 0x402870, 3);
  440. gr_def(ctx, 0x402878, 0x00000003);
  441. if (dev_priv->chipset != 0x47) { /* belong at end!! */
  442. cp_ctx(ctx, 0x402900, 1);
  443. cp_ctx(ctx, 0x402940, 1);
  444. cp_ctx(ctx, 0x402980, 1);
  445. cp_ctx(ctx, 0x4029c0, 1);
  446. cp_ctx(ctx, 0x402a00, 1);
  447. cp_ctx(ctx, 0x402a40, 1);
  448. cp_ctx(ctx, 0x402a80, 1);
  449. cp_ctx(ctx, 0x402ac0, 1);
  450. }
  451. break;
  452. case 0x40:
  453. cp_ctx(ctx, 0x402844, 1);
  454. gr_def(ctx, 0x402844, 0x00000001);
  455. cp_ctx(ctx, 0x402850, 1);
  456. break;
  457. default:
  458. cp_ctx(ctx, 0x402844, 1);
  459. gr_def(ctx, 0x402844, 0x00001001);
  460. cp_ctx(ctx, 0x402850, 2);
  461. gr_def(ctx, 0x402854, 0x00000003);
  462. break;
  463. }
  464. cp_ctx(ctx, 0x402c00, 4);
  465. gr_def(ctx, 0x402c00, dev_priv->chipset == 0x40 ?
  466. 0x80800001 : 0x00888001);
  467. switch (dev_priv->chipset) {
  468. case 0x47:
  469. case 0x49:
  470. case 0x4b:
  471. cp_ctx(ctx, 0x402c20, 40);
  472. for (i = 0; i < 32; i++)
  473. gr_def(ctx, 0x402c40 + (i * 4), 0xffffffff);
  474. cp_ctx(ctx, 0x4030b8, 13);
  475. gr_def(ctx, 0x4030dc, 0x00000005);
  476. gr_def(ctx, 0x4030e8, 0x0000ffff);
  477. break;
  478. default:
  479. cp_ctx(ctx, 0x402c10, 4);
  480. if (dev_priv->chipset == 0x40)
  481. cp_ctx(ctx, 0x402c20, 36);
  482. else
  483. if (dev_priv->chipset <= 0x42)
  484. cp_ctx(ctx, 0x402c20, 24);
  485. else
  486. if (dev_priv->chipset <= 0x4a)
  487. cp_ctx(ctx, 0x402c20, 16);
  488. else
  489. cp_ctx(ctx, 0x402c20, 8);
  490. cp_ctx(ctx, 0x402cb0, dev_priv->chipset == 0x40 ? 12 : 13);
  491. gr_def(ctx, 0x402cd4, 0x00000005);
  492. if (dev_priv->chipset != 0x40)
  493. gr_def(ctx, 0x402ce0, 0x0000ffff);
  494. break;
  495. }
  496. cp_ctx(ctx, 0x403400, dev_priv->chipset == 0x40 ? 4 : 3);
  497. cp_ctx(ctx, 0x403410, dev_priv->chipset == 0x40 ? 4 : 3);
  498. cp_ctx(ctx, 0x403420, nv40_graph_vs_count(ctx->dev));
  499. for (i = 0; i < nv40_graph_vs_count(ctx->dev); i++)
  500. gr_def(ctx, 0x403420 + (i * 4), 0x00005555);
  501. if (dev_priv->chipset != 0x40) {
  502. cp_ctx(ctx, 0x403600, 1);
  503. gr_def(ctx, 0x403600, 0x00000001);
  504. }
  505. cp_ctx(ctx, 0x403800, 1);
  506. cp_ctx(ctx, 0x403c18, 1);
  507. gr_def(ctx, 0x403c18, 0x00000001);
  508. switch (dev_priv->chipset) {
  509. case 0x46:
  510. case 0x47:
  511. case 0x49:
  512. case 0x4b:
  513. cp_ctx(ctx, 0x405018, 1);
  514. gr_def(ctx, 0x405018, 0x08e00001);
  515. cp_ctx(ctx, 0x405c24, 1);
  516. gr_def(ctx, 0x405c24, 0x000e3000);
  517. break;
  518. }
  519. if (dev_priv->chipset != 0x4e)
  520. cp_ctx(ctx, 0x405800, 11);
  521. cp_ctx(ctx, 0x407000, 1);
  522. }
  523. static void
  524. nv40_graph_construct_state3d_3(struct nouveau_grctx *ctx)
  525. {
  526. int len = nv40_graph_4097(ctx->dev) ? 0x0684 : 0x0084;
  527. cp_out (ctx, 0x300000);
  528. cp_lsr (ctx, len - 4);
  529. cp_bra (ctx, SWAP_DIRECTION, SAVE, cp_swap_state3d_3_is_save);
  530. cp_lsr (ctx, len);
  531. cp_name(ctx, cp_swap_state3d_3_is_save);
  532. cp_out (ctx, 0x800001);
  533. ctx->ctxvals_pos += len;
  534. }
  535. static void
  536. nv40_graph_construct_shader(struct nouveau_grctx *ctx)
  537. {
  538. struct drm_device *dev = ctx->dev;
  539. struct drm_nouveau_private *dev_priv = dev->dev_private;
  540. struct nouveau_gpuobj *obj = ctx->data;
  541. int vs, vs_nr, vs_len, vs_nr_b0, vs_nr_b1, b0_offset, b1_offset;
  542. int offset, i;
  543. vs_nr = nv40_graph_vs_count(ctx->dev);
  544. vs_nr_b0 = 363;
  545. vs_nr_b1 = dev_priv->chipset == 0x40 ? 128 : 64;
  546. if (dev_priv->chipset == 0x40) {
  547. b0_offset = 0x2200/4; /* 33a0 */
  548. b1_offset = 0x55a0/4; /* 1500 */
  549. vs_len = 0x6aa0/4;
  550. } else
  551. if (dev_priv->chipset == 0x41 || dev_priv->chipset == 0x42) {
  552. b0_offset = 0x2200/4; /* 2200 */
  553. b1_offset = 0x4400/4; /* 0b00 */
  554. vs_len = 0x4f00/4;
  555. } else {
  556. b0_offset = 0x1d40/4; /* 2200 */
  557. b1_offset = 0x3f40/4; /* 0b00 : 0a40 */
  558. vs_len = nv40_graph_4097(dev) ? 0x4a40/4 : 0x4980/4;
  559. }
  560. cp_lsr(ctx, vs_len * vs_nr + 0x300/4);
  561. cp_out(ctx, nv40_graph_4097(dev) ? 0x800041 : 0x800029);
  562. offset = ctx->ctxvals_pos;
  563. ctx->ctxvals_pos += (0x0300/4 + (vs_nr * vs_len));
  564. if (ctx->mode != NOUVEAU_GRCTX_VALS)
  565. return;
  566. offset += 0x0280/4;
  567. for (i = 0; i < 16; i++, offset += 2)
  568. nv_wo32(obj, offset * 4, 0x3f800000);
  569. for (vs = 0; vs < vs_nr; vs++, offset += vs_len) {
  570. for (i = 0; i < vs_nr_b0 * 6; i += 6)
  571. nv_wo32(obj, (offset + b0_offset + i) * 4, 0x00000001);
  572. for (i = 0; i < vs_nr_b1 * 4; i += 4)
  573. nv_wo32(obj, (offset + b1_offset + i) * 4, 0x3f800000);
  574. }
  575. }
  576. void
  577. nv40_grctx_init(struct nouveau_grctx *ctx)
  578. {
  579. /* decide whether we're loading/unloading the context */
  580. cp_bra (ctx, AUTO_SAVE, PENDING, cp_setup_save);
  581. cp_bra (ctx, USER_SAVE, PENDING, cp_setup_save);
  582. cp_name(ctx, cp_check_load);
  583. cp_bra (ctx, AUTO_LOAD, PENDING, cp_setup_auto_load);
  584. cp_bra (ctx, USER_LOAD, PENDING, cp_setup_load);
  585. cp_bra (ctx, ALWAYS, TRUE, cp_exit);
  586. /* setup for context load */
  587. cp_name(ctx, cp_setup_auto_load);
  588. cp_wait(ctx, STATUS, IDLE);
  589. cp_out (ctx, CP_NEXT_TO_SWAP);
  590. cp_name(ctx, cp_setup_load);
  591. cp_wait(ctx, STATUS, IDLE);
  592. cp_set (ctx, SWAP_DIRECTION, LOAD);
  593. cp_out (ctx, 0x00910880); /* ?? */
  594. cp_out (ctx, 0x00901ffe); /* ?? */
  595. cp_out (ctx, 0x01940000); /* ?? */
  596. cp_lsr (ctx, 0x20);
  597. cp_out (ctx, 0x0060000b); /* ?? */
  598. cp_wait(ctx, UNK57, CLEAR);
  599. cp_out (ctx, 0x0060000c); /* ?? */
  600. cp_bra (ctx, ALWAYS, TRUE, cp_swap_state);
  601. /* setup for context save */
  602. cp_name(ctx, cp_setup_save);
  603. cp_set (ctx, SWAP_DIRECTION, SAVE);
  604. /* general PGRAPH state */
  605. cp_name(ctx, cp_swap_state);
  606. cp_pos (ctx, 0x00020/4);
  607. nv40_graph_construct_general(ctx);
  608. cp_wait(ctx, STATUS, IDLE);
  609. /* 3D state, block 1 */
  610. cp_bra (ctx, UNK54, CLEAR, cp_prepare_exit);
  611. nv40_graph_construct_state3d(ctx);
  612. cp_wait(ctx, STATUS, IDLE);
  613. /* 3D state, block 2 */
  614. nv40_graph_construct_state3d_2(ctx);
  615. /* Some other block of "random" state */
  616. nv40_graph_construct_state3d_3(ctx);
  617. /* Per-vertex shader state */
  618. cp_pos (ctx, ctx->ctxvals_pos);
  619. nv40_graph_construct_shader(ctx);
  620. /* pre-exit state updates */
  621. cp_name(ctx, cp_prepare_exit);
  622. cp_bra (ctx, SWAP_DIRECTION, SAVE, cp_check_load);
  623. cp_bra (ctx, USER_SAVE, PENDING, cp_exit);
  624. cp_out (ctx, CP_NEXT_TO_CURRENT);
  625. cp_name(ctx, cp_exit);
  626. cp_set (ctx, USER_SAVE, NOT_PENDING);
  627. cp_set (ctx, USER_LOAD, NOT_PENDING);
  628. cp_out (ctx, CP_END);
  629. }