nv40_grctx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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. * - document unimplemented bits compared to nvidia
  114. * - nsource handling
  115. * - R0 & 0x0200 handling
  116. * - single-vs handling
  117. * - 400314 bit 0
  118. */
  119. static int
  120. nv40_graph_4097(struct drm_device *dev)
  121. {
  122. struct drm_nouveau_private *dev_priv = dev->dev_private;
  123. if ((dev_priv->chipset & 0xf0) == 0x60)
  124. return 0;
  125. return !!(0x0baf & (1 << dev_priv->chipset));
  126. }
  127. static int
  128. nv40_graph_vs_count(struct drm_device *dev)
  129. {
  130. struct drm_nouveau_private *dev_priv = dev->dev_private;
  131. switch (dev_priv->chipset) {
  132. case 0x47:
  133. case 0x49:
  134. case 0x4b:
  135. return 8;
  136. case 0x40:
  137. return 6;
  138. case 0x41:
  139. case 0x42:
  140. return 5;
  141. case 0x43:
  142. case 0x44:
  143. case 0x46:
  144. case 0x4a:
  145. return 3;
  146. case 0x4c:
  147. case 0x4e:
  148. case 0x67:
  149. default:
  150. return 1;
  151. }
  152. }
  153. enum cp_label {
  154. cp_check_load = 1,
  155. cp_setup_auto_load,
  156. cp_setup_load,
  157. cp_setup_save,
  158. cp_swap_state,
  159. cp_swap_state3d_3_is_save,
  160. cp_prepare_exit,
  161. cp_exit,
  162. };
  163. static void
  164. nv40_graph_construct_general(struct nouveau_grctx *ctx)
  165. {
  166. struct drm_nouveau_private *dev_priv = ctx->dev->dev_private;
  167. int i;
  168. cp_ctx(ctx, 0x4000a4, 1);
  169. gr_def(ctx, 0x4000a4, 0x00000008);
  170. cp_ctx(ctx, 0x400144, 58);
  171. gr_def(ctx, 0x400144, 0x00000001);
  172. cp_ctx(ctx, 0x400314, 1);
  173. gr_def(ctx, 0x400314, 0x00000000);
  174. cp_ctx(ctx, 0x400400, 10);
  175. cp_ctx(ctx, 0x400480, 10);
  176. cp_ctx(ctx, 0x400500, 19);
  177. gr_def(ctx, 0x400514, 0x00040000);
  178. gr_def(ctx, 0x400524, 0x55555555);
  179. gr_def(ctx, 0x400528, 0x55555555);
  180. gr_def(ctx, 0x40052c, 0x55555555);
  181. gr_def(ctx, 0x400530, 0x55555555);
  182. cp_ctx(ctx, 0x400560, 6);
  183. gr_def(ctx, 0x400568, 0x0000ffff);
  184. gr_def(ctx, 0x40056c, 0x0000ffff);
  185. cp_ctx(ctx, 0x40057c, 5);
  186. cp_ctx(ctx, 0x400710, 3);
  187. gr_def(ctx, 0x400710, 0x20010001);
  188. gr_def(ctx, 0x400714, 0x0f73ef00);
  189. cp_ctx(ctx, 0x400724, 1);
  190. gr_def(ctx, 0x400724, 0x02008821);
  191. cp_ctx(ctx, 0x400770, 3);
  192. if (dev_priv->chipset == 0x40) {
  193. cp_ctx(ctx, 0x400814, 4);
  194. cp_ctx(ctx, 0x400828, 5);
  195. cp_ctx(ctx, 0x400840, 5);
  196. gr_def(ctx, 0x400850, 0x00000040);
  197. cp_ctx(ctx, 0x400858, 4);
  198. gr_def(ctx, 0x400858, 0x00000040);
  199. gr_def(ctx, 0x40085c, 0x00000040);
  200. gr_def(ctx, 0x400864, 0x80000000);
  201. cp_ctx(ctx, 0x40086c, 9);
  202. gr_def(ctx, 0x40086c, 0x80000000);
  203. gr_def(ctx, 0x400870, 0x80000000);
  204. gr_def(ctx, 0x400874, 0x80000000);
  205. gr_def(ctx, 0x400878, 0x80000000);
  206. gr_def(ctx, 0x400888, 0x00000040);
  207. gr_def(ctx, 0x40088c, 0x80000000);
  208. cp_ctx(ctx, 0x4009c0, 8);
  209. gr_def(ctx, 0x4009cc, 0x80000000);
  210. gr_def(ctx, 0x4009dc, 0x80000000);
  211. } else {
  212. cp_ctx(ctx, 0x400840, 20);
  213. if (!nv40_graph_4097(ctx->dev)) {
  214. for (i = 0; i < 8; i++)
  215. gr_def(ctx, 0x400860 + (i * 4), 0x00000001);
  216. }
  217. gr_def(ctx, 0x400880, 0x00000040);
  218. gr_def(ctx, 0x400884, 0x00000040);
  219. gr_def(ctx, 0x400888, 0x00000040);
  220. cp_ctx(ctx, 0x400894, 11);
  221. gr_def(ctx, 0x400894, 0x00000040);
  222. if (nv40_graph_4097(ctx->dev)) {
  223. for (i = 0; i < 8; i++)
  224. gr_def(ctx, 0x4008a0 + (i * 4), 0x80000000);
  225. }
  226. cp_ctx(ctx, 0x4008e0, 2);
  227. cp_ctx(ctx, 0x4008f8, 2);
  228. if (dev_priv->chipset == 0x4c ||
  229. (dev_priv->chipset & 0xf0) == 0x60)
  230. cp_ctx(ctx, 0x4009f8, 1);
  231. }
  232. cp_ctx(ctx, 0x400a00, 73);
  233. gr_def(ctx, 0x400b0c, 0x0b0b0b0c);
  234. cp_ctx(ctx, 0x401000, 4);
  235. cp_ctx(ctx, 0x405004, 1);
  236. switch (dev_priv->chipset) {
  237. case 0x47:
  238. case 0x49:
  239. case 0x4b:
  240. cp_ctx(ctx, 0x403448, 1);
  241. gr_def(ctx, 0x403448, 0x00001010);
  242. break;
  243. default:
  244. cp_ctx(ctx, 0x403440, 1);
  245. switch (dev_priv->chipset) {
  246. case 0x40:
  247. gr_def(ctx, 0x403440, 0x00000010);
  248. break;
  249. case 0x44:
  250. case 0x46:
  251. case 0x4a:
  252. gr_def(ctx, 0x403440, 0x00003010);
  253. break;
  254. case 0x41:
  255. case 0x42:
  256. case 0x43:
  257. case 0x4c:
  258. case 0x4e:
  259. case 0x67:
  260. default:
  261. gr_def(ctx, 0x403440, 0x00001010);
  262. break;
  263. }
  264. break;
  265. }
  266. }
  267. static void
  268. nv40_graph_construct_state3d(struct nouveau_grctx *ctx)
  269. {
  270. struct drm_nouveau_private *dev_priv = ctx->dev->dev_private;
  271. int i;
  272. if (dev_priv->chipset == 0x40) {
  273. cp_ctx(ctx, 0x401880, 51);
  274. gr_def(ctx, 0x401940, 0x00000100);
  275. } else
  276. if (dev_priv->chipset == 0x46 || dev_priv->chipset == 0x47 ||
  277. dev_priv->chipset == 0x49 || dev_priv->chipset == 0x4b) {
  278. cp_ctx(ctx, 0x401880, 32);
  279. for (i = 0; i < 16; i++)
  280. gr_def(ctx, 0x401880 + (i * 4), 0x00000111);
  281. if (dev_priv->chipset == 0x46)
  282. cp_ctx(ctx, 0x401900, 16);
  283. cp_ctx(ctx, 0x401940, 3);
  284. }
  285. cp_ctx(ctx, 0x40194c, 18);
  286. gr_def(ctx, 0x401954, 0x00000111);
  287. gr_def(ctx, 0x401958, 0x00080060);
  288. gr_def(ctx, 0x401974, 0x00000080);
  289. gr_def(ctx, 0x401978, 0xffff0000);
  290. gr_def(ctx, 0x40197c, 0x00000001);
  291. gr_def(ctx, 0x401990, 0x46400000);
  292. if (dev_priv->chipset == 0x40) {
  293. cp_ctx(ctx, 0x4019a0, 2);
  294. cp_ctx(ctx, 0x4019ac, 5);
  295. } else {
  296. cp_ctx(ctx, 0x4019a0, 1);
  297. cp_ctx(ctx, 0x4019b4, 3);
  298. }
  299. gr_def(ctx, 0x4019bc, 0xffff0000);
  300. switch (dev_priv->chipset) {
  301. case 0x46:
  302. case 0x47:
  303. case 0x49:
  304. case 0x4b:
  305. cp_ctx(ctx, 0x4019c0, 18);
  306. for (i = 0; i < 16; i++)
  307. gr_def(ctx, 0x4019c0 + (i * 4), 0x88888888);
  308. break;
  309. }
  310. cp_ctx(ctx, 0x401a08, 8);
  311. gr_def(ctx, 0x401a10, 0x0fff0000);
  312. gr_def(ctx, 0x401a14, 0x0fff0000);
  313. gr_def(ctx, 0x401a1c, 0x00011100);
  314. cp_ctx(ctx, 0x401a2c, 4);
  315. cp_ctx(ctx, 0x401a44, 26);
  316. for (i = 0; i < 16; i++)
  317. gr_def(ctx, 0x401a44 + (i * 4), 0x07ff0000);
  318. gr_def(ctx, 0x401a8c, 0x4b7fffff);
  319. if (dev_priv->chipset == 0x40) {
  320. cp_ctx(ctx, 0x401ab8, 3);
  321. } else {
  322. cp_ctx(ctx, 0x401ab8, 1);
  323. cp_ctx(ctx, 0x401ac0, 1);
  324. }
  325. cp_ctx(ctx, 0x401ad0, 8);
  326. gr_def(ctx, 0x401ad0, 0x30201000);
  327. gr_def(ctx, 0x401ad4, 0x70605040);
  328. gr_def(ctx, 0x401ad8, 0xb8a89888);
  329. gr_def(ctx, 0x401adc, 0xf8e8d8c8);
  330. cp_ctx(ctx, 0x401b10, dev_priv->chipset == 0x40 ? 2 : 1);
  331. gr_def(ctx, 0x401b10, 0x40100000);
  332. cp_ctx(ctx, 0x401b18, dev_priv->chipset == 0x40 ? 6 : 5);
  333. gr_def(ctx, 0x401b28, dev_priv->chipset == 0x40 ?
  334. 0x00000004 : 0x00000000);
  335. cp_ctx(ctx, 0x401b30, 25);
  336. gr_def(ctx, 0x401b34, 0x0000ffff);
  337. gr_def(ctx, 0x401b68, 0x435185d6);
  338. gr_def(ctx, 0x401b6c, 0x2155b699);
  339. gr_def(ctx, 0x401b70, 0xfedcba98);
  340. gr_def(ctx, 0x401b74, 0x00000098);
  341. gr_def(ctx, 0x401b84, 0xffffffff);
  342. gr_def(ctx, 0x401b88, 0x00ff7000);
  343. gr_def(ctx, 0x401b8c, 0x0000ffff);
  344. if (dev_priv->chipset != 0x44 && dev_priv->chipset != 0x4a &&
  345. dev_priv->chipset != 0x4e)
  346. cp_ctx(ctx, 0x401b94, 1);
  347. cp_ctx(ctx, 0x401b98, 8);
  348. gr_def(ctx, 0x401b9c, 0x00ff0000);
  349. cp_ctx(ctx, 0x401bc0, 9);
  350. gr_def(ctx, 0x401be0, 0x00ffff00);
  351. cp_ctx(ctx, 0x401c00, 192);
  352. for (i = 0; i < 16; i++) { /* fragment texture units */
  353. gr_def(ctx, 0x401c40 + (i * 4), 0x00018488);
  354. gr_def(ctx, 0x401c80 + (i * 4), 0x00028202);
  355. gr_def(ctx, 0x401d00 + (i * 4), 0x0000aae4);
  356. gr_def(ctx, 0x401d40 + (i * 4), 0x01012000);
  357. gr_def(ctx, 0x401d80 + (i * 4), 0x00080008);
  358. gr_def(ctx, 0x401e00 + (i * 4), 0x00100008);
  359. }
  360. for (i = 0; i < 4; i++) { /* vertex texture units */
  361. gr_def(ctx, 0x401e90 + (i * 4), 0x0001bc80);
  362. gr_def(ctx, 0x401ea0 + (i * 4), 0x00000202);
  363. gr_def(ctx, 0x401ec0 + (i * 4), 0x00000008);
  364. gr_def(ctx, 0x401ee0 + (i * 4), 0x00080008);
  365. }
  366. cp_ctx(ctx, 0x400f5c, 3);
  367. gr_def(ctx, 0x400f5c, 0x00000002);
  368. cp_ctx(ctx, 0x400f84, 1);
  369. }
  370. static void
  371. nv40_graph_construct_state3d_2(struct nouveau_grctx *ctx)
  372. {
  373. struct drm_nouveau_private *dev_priv = ctx->dev->dev_private;
  374. int i;
  375. cp_ctx(ctx, 0x402000, 1);
  376. cp_ctx(ctx, 0x402404, dev_priv->chipset == 0x40 ? 1 : 2);
  377. switch (dev_priv->chipset) {
  378. case 0x40:
  379. gr_def(ctx, 0x402404, 0x00000001);
  380. break;
  381. case 0x4c:
  382. case 0x4e:
  383. case 0x67:
  384. gr_def(ctx, 0x402404, 0x00000020);
  385. break;
  386. case 0x46:
  387. case 0x49:
  388. case 0x4b:
  389. gr_def(ctx, 0x402404, 0x00000421);
  390. break;
  391. default:
  392. gr_def(ctx, 0x402404, 0x00000021);
  393. }
  394. if (dev_priv->chipset != 0x40)
  395. gr_def(ctx, 0x402408, 0x030c30c3);
  396. switch (dev_priv->chipset) {
  397. case 0x44:
  398. case 0x46:
  399. case 0x4a:
  400. case 0x4c:
  401. case 0x4e:
  402. case 0x67:
  403. cp_ctx(ctx, 0x402440, 1);
  404. gr_def(ctx, 0x402440, 0x00011001);
  405. break;
  406. default:
  407. break;
  408. }
  409. cp_ctx(ctx, 0x402480, dev_priv->chipset == 0x40 ? 8 : 9);
  410. gr_def(ctx, 0x402488, 0x3e020200);
  411. gr_def(ctx, 0x40248c, 0x00ffffff);
  412. switch (dev_priv->chipset) {
  413. case 0x40:
  414. gr_def(ctx, 0x402490, 0x60103f00);
  415. break;
  416. case 0x47:
  417. gr_def(ctx, 0x402490, 0x40103f00);
  418. break;
  419. case 0x41:
  420. case 0x42:
  421. case 0x49:
  422. case 0x4b:
  423. gr_def(ctx, 0x402490, 0x20103f00);
  424. break;
  425. default:
  426. gr_def(ctx, 0x402490, 0x0c103f00);
  427. break;
  428. }
  429. gr_def(ctx, 0x40249c, dev_priv->chipset <= 0x43 ?
  430. 0x00020000 : 0x00040000);
  431. cp_ctx(ctx, 0x402500, 31);
  432. gr_def(ctx, 0x402530, 0x00008100);
  433. if (dev_priv->chipset == 0x40)
  434. cp_ctx(ctx, 0x40257c, 6);
  435. cp_ctx(ctx, 0x402594, 16);
  436. cp_ctx(ctx, 0x402800, 17);
  437. gr_def(ctx, 0x402800, 0x00000001);
  438. switch (dev_priv->chipset) {
  439. case 0x47:
  440. case 0x49:
  441. case 0x4b:
  442. cp_ctx(ctx, 0x402864, 1);
  443. gr_def(ctx, 0x402864, 0x00001001);
  444. cp_ctx(ctx, 0x402870, 3);
  445. gr_def(ctx, 0x402878, 0x00000003);
  446. if (dev_priv->chipset != 0x47) { /* belong at end!! */
  447. cp_ctx(ctx, 0x402900, 1);
  448. cp_ctx(ctx, 0x402940, 1);
  449. cp_ctx(ctx, 0x402980, 1);
  450. cp_ctx(ctx, 0x4029c0, 1);
  451. cp_ctx(ctx, 0x402a00, 1);
  452. cp_ctx(ctx, 0x402a40, 1);
  453. cp_ctx(ctx, 0x402a80, 1);
  454. cp_ctx(ctx, 0x402ac0, 1);
  455. }
  456. break;
  457. case 0x40:
  458. cp_ctx(ctx, 0x402844, 1);
  459. gr_def(ctx, 0x402844, 0x00000001);
  460. cp_ctx(ctx, 0x402850, 1);
  461. break;
  462. default:
  463. cp_ctx(ctx, 0x402844, 1);
  464. gr_def(ctx, 0x402844, 0x00001001);
  465. cp_ctx(ctx, 0x402850, 2);
  466. gr_def(ctx, 0x402854, 0x00000003);
  467. break;
  468. }
  469. cp_ctx(ctx, 0x402c00, 4);
  470. gr_def(ctx, 0x402c00, dev_priv->chipset == 0x40 ?
  471. 0x80800001 : 0x00888001);
  472. switch (dev_priv->chipset) {
  473. case 0x47:
  474. case 0x49:
  475. case 0x4b:
  476. cp_ctx(ctx, 0x402c20, 40);
  477. for (i = 0; i < 32; i++)
  478. gr_def(ctx, 0x402c40 + (i * 4), 0xffffffff);
  479. cp_ctx(ctx, 0x4030b8, 13);
  480. gr_def(ctx, 0x4030dc, 0x00000005);
  481. gr_def(ctx, 0x4030e8, 0x0000ffff);
  482. break;
  483. default:
  484. cp_ctx(ctx, 0x402c10, 4);
  485. if (dev_priv->chipset == 0x40)
  486. cp_ctx(ctx, 0x402c20, 36);
  487. else
  488. if (dev_priv->chipset <= 0x42)
  489. cp_ctx(ctx, 0x402c20, 24);
  490. else
  491. if (dev_priv->chipset <= 0x4a)
  492. cp_ctx(ctx, 0x402c20, 16);
  493. else
  494. cp_ctx(ctx, 0x402c20, 8);
  495. cp_ctx(ctx, 0x402cb0, dev_priv->chipset == 0x40 ? 12 : 13);
  496. gr_def(ctx, 0x402cd4, 0x00000005);
  497. if (dev_priv->chipset != 0x40)
  498. gr_def(ctx, 0x402ce0, 0x0000ffff);
  499. break;
  500. }
  501. cp_ctx(ctx, 0x403400, dev_priv->chipset == 0x40 ? 4 : 3);
  502. cp_ctx(ctx, 0x403410, dev_priv->chipset == 0x40 ? 4 : 3);
  503. cp_ctx(ctx, 0x403420, nv40_graph_vs_count(ctx->dev));
  504. for (i = 0; i < nv40_graph_vs_count(ctx->dev); i++)
  505. gr_def(ctx, 0x403420 + (i * 4), 0x00005555);
  506. if (dev_priv->chipset != 0x40) {
  507. cp_ctx(ctx, 0x403600, 1);
  508. gr_def(ctx, 0x403600, 0x00000001);
  509. }
  510. cp_ctx(ctx, 0x403800, 1);
  511. cp_ctx(ctx, 0x403c18, 1);
  512. gr_def(ctx, 0x403c18, 0x00000001);
  513. switch (dev_priv->chipset) {
  514. case 0x46:
  515. case 0x47:
  516. case 0x49:
  517. case 0x4b:
  518. cp_ctx(ctx, 0x405018, 1);
  519. gr_def(ctx, 0x405018, 0x08e00001);
  520. cp_ctx(ctx, 0x405c24, 1);
  521. gr_def(ctx, 0x405c24, 0x000e3000);
  522. break;
  523. }
  524. if (dev_priv->chipset != 0x4e)
  525. cp_ctx(ctx, 0x405800, 11);
  526. cp_ctx(ctx, 0x407000, 1);
  527. }
  528. static void
  529. nv40_graph_construct_state3d_3(struct nouveau_grctx *ctx)
  530. {
  531. int len = nv40_graph_4097(ctx->dev) ? 0x0684 : 0x0084;
  532. cp_out (ctx, 0x300000);
  533. cp_lsr (ctx, len - 4);
  534. cp_bra (ctx, SWAP_DIRECTION, SAVE, cp_swap_state3d_3_is_save);
  535. cp_lsr (ctx, len);
  536. cp_name(ctx, cp_swap_state3d_3_is_save);
  537. cp_out (ctx, 0x800001);
  538. ctx->ctxvals_pos += len;
  539. }
  540. static void
  541. nv40_graph_construct_shader(struct nouveau_grctx *ctx)
  542. {
  543. struct drm_device *dev = ctx->dev;
  544. struct drm_nouveau_private *dev_priv = dev->dev_private;
  545. struct nouveau_gpuobj *obj = ctx->data;
  546. int vs, vs_nr, vs_len, vs_nr_b0, vs_nr_b1, b0_offset, b1_offset;
  547. int offset, i;
  548. vs_nr = nv40_graph_vs_count(ctx->dev);
  549. vs_nr_b0 = 363;
  550. vs_nr_b1 = dev_priv->chipset == 0x40 ? 128 : 64;
  551. if (dev_priv->chipset == 0x40) {
  552. b0_offset = 0x2200/4; /* 33a0 */
  553. b1_offset = 0x55a0/4; /* 1500 */
  554. vs_len = 0x6aa0/4;
  555. } else
  556. if (dev_priv->chipset == 0x41 || dev_priv->chipset == 0x42) {
  557. b0_offset = 0x2200/4; /* 2200 */
  558. b1_offset = 0x4400/4; /* 0b00 */
  559. vs_len = 0x4f00/4;
  560. } else {
  561. b0_offset = 0x1d40/4; /* 2200 */
  562. b1_offset = 0x3f40/4; /* 0b00 : 0a40 */
  563. vs_len = nv40_graph_4097(dev) ? 0x4a40/4 : 0x4980/4;
  564. }
  565. cp_lsr(ctx, vs_len * vs_nr + 0x300/4);
  566. cp_out(ctx, nv40_graph_4097(dev) ? 0x800041 : 0x800029);
  567. offset = ctx->ctxvals_pos;
  568. ctx->ctxvals_pos += (0x0300/4 + (vs_nr * vs_len));
  569. if (ctx->mode != NOUVEAU_GRCTX_VALS)
  570. return;
  571. offset += 0x0280/4;
  572. for (i = 0; i < 16; i++, offset += 2)
  573. nv_wo32(dev, obj, offset, 0x3f800000);
  574. for (vs = 0; vs < vs_nr; vs++, offset += vs_len) {
  575. for (i = 0; i < vs_nr_b0 * 6; i += 6)
  576. nv_wo32(dev, obj, offset + b0_offset + i, 0x00000001);
  577. for (i = 0; i < vs_nr_b1 * 4; i += 4)
  578. nv_wo32(dev, obj, offset + b1_offset + i, 0x3f800000);
  579. }
  580. }
  581. void
  582. nv40_grctx_init(struct nouveau_grctx *ctx)
  583. {
  584. /* decide whether we're loading/unloading the context */
  585. cp_bra (ctx, AUTO_SAVE, PENDING, cp_setup_save);
  586. cp_bra (ctx, USER_SAVE, PENDING, cp_setup_save);
  587. cp_name(ctx, cp_check_load);
  588. cp_bra (ctx, AUTO_LOAD, PENDING, cp_setup_auto_load);
  589. cp_bra (ctx, USER_LOAD, PENDING, cp_setup_load);
  590. cp_bra (ctx, ALWAYS, TRUE, cp_exit);
  591. /* setup for context load */
  592. cp_name(ctx, cp_setup_auto_load);
  593. cp_wait(ctx, STATUS, IDLE);
  594. cp_out (ctx, CP_NEXT_TO_SWAP);
  595. cp_name(ctx, cp_setup_load);
  596. cp_wait(ctx, STATUS, IDLE);
  597. cp_set (ctx, SWAP_DIRECTION, LOAD);
  598. cp_out (ctx, 0x00910880); /* ?? */
  599. cp_out (ctx, 0x00901ffe); /* ?? */
  600. cp_out (ctx, 0x01940000); /* ?? */
  601. cp_lsr (ctx, 0x20);
  602. cp_out (ctx, 0x0060000b); /* ?? */
  603. cp_wait(ctx, UNK57, CLEAR);
  604. cp_out (ctx, 0x0060000c); /* ?? */
  605. cp_bra (ctx, ALWAYS, TRUE, cp_swap_state);
  606. /* setup for context save */
  607. cp_name(ctx, cp_setup_save);
  608. cp_set (ctx, SWAP_DIRECTION, SAVE);
  609. /* general PGRAPH state */
  610. cp_name(ctx, cp_swap_state);
  611. cp_pos (ctx, 0x00020/4);
  612. nv40_graph_construct_general(ctx);
  613. cp_wait(ctx, STATUS, IDLE);
  614. /* 3D state, block 1 */
  615. cp_bra (ctx, UNK54, CLEAR, cp_prepare_exit);
  616. nv40_graph_construct_state3d(ctx);
  617. cp_wait(ctx, STATUS, IDLE);
  618. /* 3D state, block 2 */
  619. nv40_graph_construct_state3d_2(ctx);
  620. /* Some other block of "random" state */
  621. nv40_graph_construct_state3d_3(ctx);
  622. /* Per-vertex shader state */
  623. cp_pos (ctx, ctx->ctxvals_pos);
  624. nv40_graph_construct_shader(ctx);
  625. /* pre-exit state updates */
  626. cp_name(ctx, cp_prepare_exit);
  627. cp_bra (ctx, SWAP_DIRECTION, SAVE, cp_check_load);
  628. cp_bra (ctx, USER_SAVE, PENDING, cp_exit);
  629. cp_out (ctx, CP_NEXT_TO_CURRENT);
  630. cp_name(ctx, cp_exit);
  631. cp_set (ctx, USER_SAVE, NOT_PENDING);
  632. cp_set (ctx, USER_LOAD, NOT_PENDING);
  633. cp_out (ctx, CP_END);
  634. }