nv40_grctx.c 19 KB

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