nv04_graph.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. /*
  2. * Copyright 2007 Stephane Marchesin
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. */
  24. #include "drmP.h"
  25. #include "drm.h"
  26. #include "nouveau_drm.h"
  27. #include "nouveau_drv.h"
  28. #include "nouveau_hw.h"
  29. #include "nouveau_util.h"
  30. #include "nouveau_ramht.h"
  31. struct nv04_graph_engine {
  32. struct nouveau_exec_engine base;
  33. };
  34. static uint32_t nv04_graph_ctx_regs[] = {
  35. 0x0040053c,
  36. 0x00400544,
  37. 0x00400540,
  38. 0x00400548,
  39. NV04_PGRAPH_CTX_SWITCH1,
  40. NV04_PGRAPH_CTX_SWITCH2,
  41. NV04_PGRAPH_CTX_SWITCH3,
  42. NV04_PGRAPH_CTX_SWITCH4,
  43. NV04_PGRAPH_CTX_CACHE1,
  44. NV04_PGRAPH_CTX_CACHE2,
  45. NV04_PGRAPH_CTX_CACHE3,
  46. NV04_PGRAPH_CTX_CACHE4,
  47. 0x00400184,
  48. 0x004001a4,
  49. 0x004001c4,
  50. 0x004001e4,
  51. 0x00400188,
  52. 0x004001a8,
  53. 0x004001c8,
  54. 0x004001e8,
  55. 0x0040018c,
  56. 0x004001ac,
  57. 0x004001cc,
  58. 0x004001ec,
  59. 0x00400190,
  60. 0x004001b0,
  61. 0x004001d0,
  62. 0x004001f0,
  63. 0x00400194,
  64. 0x004001b4,
  65. 0x004001d4,
  66. 0x004001f4,
  67. 0x00400198,
  68. 0x004001b8,
  69. 0x004001d8,
  70. 0x004001f8,
  71. 0x0040019c,
  72. 0x004001bc,
  73. 0x004001dc,
  74. 0x004001fc,
  75. 0x00400174,
  76. NV04_PGRAPH_DMA_START_0,
  77. NV04_PGRAPH_DMA_START_1,
  78. NV04_PGRAPH_DMA_LENGTH,
  79. NV04_PGRAPH_DMA_MISC,
  80. NV04_PGRAPH_DMA_PITCH,
  81. NV04_PGRAPH_BOFFSET0,
  82. NV04_PGRAPH_BBASE0,
  83. NV04_PGRAPH_BLIMIT0,
  84. NV04_PGRAPH_BOFFSET1,
  85. NV04_PGRAPH_BBASE1,
  86. NV04_PGRAPH_BLIMIT1,
  87. NV04_PGRAPH_BOFFSET2,
  88. NV04_PGRAPH_BBASE2,
  89. NV04_PGRAPH_BLIMIT2,
  90. NV04_PGRAPH_BOFFSET3,
  91. NV04_PGRAPH_BBASE3,
  92. NV04_PGRAPH_BLIMIT3,
  93. NV04_PGRAPH_BOFFSET4,
  94. NV04_PGRAPH_BBASE4,
  95. NV04_PGRAPH_BLIMIT4,
  96. NV04_PGRAPH_BOFFSET5,
  97. NV04_PGRAPH_BBASE5,
  98. NV04_PGRAPH_BLIMIT5,
  99. NV04_PGRAPH_BPITCH0,
  100. NV04_PGRAPH_BPITCH1,
  101. NV04_PGRAPH_BPITCH2,
  102. NV04_PGRAPH_BPITCH3,
  103. NV04_PGRAPH_BPITCH4,
  104. NV04_PGRAPH_SURFACE,
  105. NV04_PGRAPH_STATE,
  106. NV04_PGRAPH_BSWIZZLE2,
  107. NV04_PGRAPH_BSWIZZLE5,
  108. NV04_PGRAPH_BPIXEL,
  109. NV04_PGRAPH_NOTIFY,
  110. NV04_PGRAPH_PATT_COLOR0,
  111. NV04_PGRAPH_PATT_COLOR1,
  112. NV04_PGRAPH_PATT_COLORRAM+0x00,
  113. NV04_PGRAPH_PATT_COLORRAM+0x04,
  114. NV04_PGRAPH_PATT_COLORRAM+0x08,
  115. NV04_PGRAPH_PATT_COLORRAM+0x0c,
  116. NV04_PGRAPH_PATT_COLORRAM+0x10,
  117. NV04_PGRAPH_PATT_COLORRAM+0x14,
  118. NV04_PGRAPH_PATT_COLORRAM+0x18,
  119. NV04_PGRAPH_PATT_COLORRAM+0x1c,
  120. NV04_PGRAPH_PATT_COLORRAM+0x20,
  121. NV04_PGRAPH_PATT_COLORRAM+0x24,
  122. NV04_PGRAPH_PATT_COLORRAM+0x28,
  123. NV04_PGRAPH_PATT_COLORRAM+0x2c,
  124. NV04_PGRAPH_PATT_COLORRAM+0x30,
  125. NV04_PGRAPH_PATT_COLORRAM+0x34,
  126. NV04_PGRAPH_PATT_COLORRAM+0x38,
  127. NV04_PGRAPH_PATT_COLORRAM+0x3c,
  128. NV04_PGRAPH_PATT_COLORRAM+0x40,
  129. NV04_PGRAPH_PATT_COLORRAM+0x44,
  130. NV04_PGRAPH_PATT_COLORRAM+0x48,
  131. NV04_PGRAPH_PATT_COLORRAM+0x4c,
  132. NV04_PGRAPH_PATT_COLORRAM+0x50,
  133. NV04_PGRAPH_PATT_COLORRAM+0x54,
  134. NV04_PGRAPH_PATT_COLORRAM+0x58,
  135. NV04_PGRAPH_PATT_COLORRAM+0x5c,
  136. NV04_PGRAPH_PATT_COLORRAM+0x60,
  137. NV04_PGRAPH_PATT_COLORRAM+0x64,
  138. NV04_PGRAPH_PATT_COLORRAM+0x68,
  139. NV04_PGRAPH_PATT_COLORRAM+0x6c,
  140. NV04_PGRAPH_PATT_COLORRAM+0x70,
  141. NV04_PGRAPH_PATT_COLORRAM+0x74,
  142. NV04_PGRAPH_PATT_COLORRAM+0x78,
  143. NV04_PGRAPH_PATT_COLORRAM+0x7c,
  144. NV04_PGRAPH_PATT_COLORRAM+0x80,
  145. NV04_PGRAPH_PATT_COLORRAM+0x84,
  146. NV04_PGRAPH_PATT_COLORRAM+0x88,
  147. NV04_PGRAPH_PATT_COLORRAM+0x8c,
  148. NV04_PGRAPH_PATT_COLORRAM+0x90,
  149. NV04_PGRAPH_PATT_COLORRAM+0x94,
  150. NV04_PGRAPH_PATT_COLORRAM+0x98,
  151. NV04_PGRAPH_PATT_COLORRAM+0x9c,
  152. NV04_PGRAPH_PATT_COLORRAM+0xa0,
  153. NV04_PGRAPH_PATT_COLORRAM+0xa4,
  154. NV04_PGRAPH_PATT_COLORRAM+0xa8,
  155. NV04_PGRAPH_PATT_COLORRAM+0xac,
  156. NV04_PGRAPH_PATT_COLORRAM+0xb0,
  157. NV04_PGRAPH_PATT_COLORRAM+0xb4,
  158. NV04_PGRAPH_PATT_COLORRAM+0xb8,
  159. NV04_PGRAPH_PATT_COLORRAM+0xbc,
  160. NV04_PGRAPH_PATT_COLORRAM+0xc0,
  161. NV04_PGRAPH_PATT_COLORRAM+0xc4,
  162. NV04_PGRAPH_PATT_COLORRAM+0xc8,
  163. NV04_PGRAPH_PATT_COLORRAM+0xcc,
  164. NV04_PGRAPH_PATT_COLORRAM+0xd0,
  165. NV04_PGRAPH_PATT_COLORRAM+0xd4,
  166. NV04_PGRAPH_PATT_COLORRAM+0xd8,
  167. NV04_PGRAPH_PATT_COLORRAM+0xdc,
  168. NV04_PGRAPH_PATT_COLORRAM+0xe0,
  169. NV04_PGRAPH_PATT_COLORRAM+0xe4,
  170. NV04_PGRAPH_PATT_COLORRAM+0xe8,
  171. NV04_PGRAPH_PATT_COLORRAM+0xec,
  172. NV04_PGRAPH_PATT_COLORRAM+0xf0,
  173. NV04_PGRAPH_PATT_COLORRAM+0xf4,
  174. NV04_PGRAPH_PATT_COLORRAM+0xf8,
  175. NV04_PGRAPH_PATT_COLORRAM+0xfc,
  176. NV04_PGRAPH_PATTERN,
  177. 0x0040080c,
  178. NV04_PGRAPH_PATTERN_SHAPE,
  179. 0x00400600,
  180. NV04_PGRAPH_ROP3,
  181. NV04_PGRAPH_CHROMA,
  182. NV04_PGRAPH_BETA_AND,
  183. NV04_PGRAPH_BETA_PREMULT,
  184. NV04_PGRAPH_CONTROL0,
  185. NV04_PGRAPH_CONTROL1,
  186. NV04_PGRAPH_CONTROL2,
  187. NV04_PGRAPH_BLEND,
  188. NV04_PGRAPH_STORED_FMT,
  189. NV04_PGRAPH_SOURCE_COLOR,
  190. 0x00400560,
  191. 0x00400568,
  192. 0x00400564,
  193. 0x0040056c,
  194. 0x00400400,
  195. 0x00400480,
  196. 0x00400404,
  197. 0x00400484,
  198. 0x00400408,
  199. 0x00400488,
  200. 0x0040040c,
  201. 0x0040048c,
  202. 0x00400410,
  203. 0x00400490,
  204. 0x00400414,
  205. 0x00400494,
  206. 0x00400418,
  207. 0x00400498,
  208. 0x0040041c,
  209. 0x0040049c,
  210. 0x00400420,
  211. 0x004004a0,
  212. 0x00400424,
  213. 0x004004a4,
  214. 0x00400428,
  215. 0x004004a8,
  216. 0x0040042c,
  217. 0x004004ac,
  218. 0x00400430,
  219. 0x004004b0,
  220. 0x00400434,
  221. 0x004004b4,
  222. 0x00400438,
  223. 0x004004b8,
  224. 0x0040043c,
  225. 0x004004bc,
  226. 0x00400440,
  227. 0x004004c0,
  228. 0x00400444,
  229. 0x004004c4,
  230. 0x00400448,
  231. 0x004004c8,
  232. 0x0040044c,
  233. 0x004004cc,
  234. 0x00400450,
  235. 0x004004d0,
  236. 0x00400454,
  237. 0x004004d4,
  238. 0x00400458,
  239. 0x004004d8,
  240. 0x0040045c,
  241. 0x004004dc,
  242. 0x00400460,
  243. 0x004004e0,
  244. 0x00400464,
  245. 0x004004e4,
  246. 0x00400468,
  247. 0x004004e8,
  248. 0x0040046c,
  249. 0x004004ec,
  250. 0x00400470,
  251. 0x004004f0,
  252. 0x00400474,
  253. 0x004004f4,
  254. 0x00400478,
  255. 0x004004f8,
  256. 0x0040047c,
  257. 0x004004fc,
  258. 0x00400534,
  259. 0x00400538,
  260. 0x00400514,
  261. 0x00400518,
  262. 0x0040051c,
  263. 0x00400520,
  264. 0x00400524,
  265. 0x00400528,
  266. 0x0040052c,
  267. 0x00400530,
  268. 0x00400d00,
  269. 0x00400d40,
  270. 0x00400d80,
  271. 0x00400d04,
  272. 0x00400d44,
  273. 0x00400d84,
  274. 0x00400d08,
  275. 0x00400d48,
  276. 0x00400d88,
  277. 0x00400d0c,
  278. 0x00400d4c,
  279. 0x00400d8c,
  280. 0x00400d10,
  281. 0x00400d50,
  282. 0x00400d90,
  283. 0x00400d14,
  284. 0x00400d54,
  285. 0x00400d94,
  286. 0x00400d18,
  287. 0x00400d58,
  288. 0x00400d98,
  289. 0x00400d1c,
  290. 0x00400d5c,
  291. 0x00400d9c,
  292. 0x00400d20,
  293. 0x00400d60,
  294. 0x00400da0,
  295. 0x00400d24,
  296. 0x00400d64,
  297. 0x00400da4,
  298. 0x00400d28,
  299. 0x00400d68,
  300. 0x00400da8,
  301. 0x00400d2c,
  302. 0x00400d6c,
  303. 0x00400dac,
  304. 0x00400d30,
  305. 0x00400d70,
  306. 0x00400db0,
  307. 0x00400d34,
  308. 0x00400d74,
  309. 0x00400db4,
  310. 0x00400d38,
  311. 0x00400d78,
  312. 0x00400db8,
  313. 0x00400d3c,
  314. 0x00400d7c,
  315. 0x00400dbc,
  316. 0x00400590,
  317. 0x00400594,
  318. 0x00400598,
  319. 0x0040059c,
  320. 0x004005a8,
  321. 0x004005ac,
  322. 0x004005b0,
  323. 0x004005b4,
  324. 0x004005c0,
  325. 0x004005c4,
  326. 0x004005c8,
  327. 0x004005cc,
  328. 0x004005d0,
  329. 0x004005d4,
  330. 0x004005d8,
  331. 0x004005dc,
  332. 0x004005e0,
  333. NV04_PGRAPH_PASSTHRU_0,
  334. NV04_PGRAPH_PASSTHRU_1,
  335. NV04_PGRAPH_PASSTHRU_2,
  336. NV04_PGRAPH_DVD_COLORFMT,
  337. NV04_PGRAPH_SCALED_FORMAT,
  338. NV04_PGRAPH_MISC24_0,
  339. NV04_PGRAPH_MISC24_1,
  340. NV04_PGRAPH_MISC24_2,
  341. 0x00400500,
  342. 0x00400504,
  343. NV04_PGRAPH_VALID1,
  344. NV04_PGRAPH_VALID2,
  345. NV04_PGRAPH_DEBUG_3
  346. };
  347. struct graph_state {
  348. uint32_t nv04[ARRAY_SIZE(nv04_graph_ctx_regs)];
  349. };
  350. static struct nouveau_channel *
  351. nv04_graph_channel(struct drm_device *dev)
  352. {
  353. struct drm_nouveau_private *dev_priv = dev->dev_private;
  354. int chid = dev_priv->engine.fifo.channels;
  355. if (nv_rd32(dev, NV04_PGRAPH_CTX_CONTROL) & 0x00010000)
  356. chid = nv_rd32(dev, NV04_PGRAPH_CTX_USER) >> 24;
  357. if (chid >= dev_priv->engine.fifo.channels)
  358. return NULL;
  359. return dev_priv->channels.ptr[chid];
  360. }
  361. static uint32_t *ctx_reg(struct graph_state *ctx, uint32_t reg)
  362. {
  363. int i;
  364. for (i = 0; i < ARRAY_SIZE(nv04_graph_ctx_regs); i++) {
  365. if (nv04_graph_ctx_regs[i] == reg)
  366. return &ctx->nv04[i];
  367. }
  368. return NULL;
  369. }
  370. static int
  371. nv04_graph_load_context(struct nouveau_channel *chan)
  372. {
  373. struct graph_state *pgraph_ctx = chan->engctx[NVOBJ_ENGINE_GR];
  374. struct drm_device *dev = chan->dev;
  375. uint32_t tmp;
  376. int i;
  377. for (i = 0; i < ARRAY_SIZE(nv04_graph_ctx_regs); i++)
  378. nv_wr32(dev, nv04_graph_ctx_regs[i], pgraph_ctx->nv04[i]);
  379. nv_wr32(dev, NV04_PGRAPH_CTX_CONTROL, 0x10010100);
  380. tmp = nv_rd32(dev, NV04_PGRAPH_CTX_USER) & 0x00ffffff;
  381. nv_wr32(dev, NV04_PGRAPH_CTX_USER, tmp | chan->id << 24);
  382. tmp = nv_rd32(dev, NV04_PGRAPH_FFINTFC_ST2);
  383. nv_wr32(dev, NV04_PGRAPH_FFINTFC_ST2, tmp & 0x000fffff);
  384. return 0;
  385. }
  386. static int
  387. nv04_graph_unload_context(struct drm_device *dev)
  388. {
  389. struct drm_nouveau_private *dev_priv = dev->dev_private;
  390. struct nouveau_channel *chan = NULL;
  391. struct graph_state *ctx;
  392. uint32_t tmp;
  393. int i;
  394. chan = nv04_graph_channel(dev);
  395. if (!chan)
  396. return 0;
  397. ctx = chan->engctx[NVOBJ_ENGINE_GR];
  398. for (i = 0; i < ARRAY_SIZE(nv04_graph_ctx_regs); i++)
  399. ctx->nv04[i] = nv_rd32(dev, nv04_graph_ctx_regs[i]);
  400. nv_wr32(dev, NV04_PGRAPH_CTX_CONTROL, 0x10000000);
  401. tmp = nv_rd32(dev, NV04_PGRAPH_CTX_USER) & 0x00ffffff;
  402. tmp |= (dev_priv->engine.fifo.channels - 1) << 24;
  403. nv_wr32(dev, NV04_PGRAPH_CTX_USER, tmp);
  404. return 0;
  405. }
  406. static int
  407. nv04_graph_context_new(struct nouveau_channel *chan, int engine)
  408. {
  409. struct graph_state *pgraph_ctx;
  410. NV_DEBUG(chan->dev, "nv04_graph_context_create %d\n", chan->id);
  411. pgraph_ctx = kzalloc(sizeof(*pgraph_ctx), GFP_KERNEL);
  412. if (pgraph_ctx == NULL)
  413. return -ENOMEM;
  414. *ctx_reg(pgraph_ctx, NV04_PGRAPH_DEBUG_3) = 0xfad4ff31;
  415. chan->engctx[engine] = pgraph_ctx;
  416. return 0;
  417. }
  418. static void
  419. nv04_graph_context_del(struct nouveau_channel *chan, int engine)
  420. {
  421. struct drm_device *dev = chan->dev;
  422. struct drm_nouveau_private *dev_priv = dev->dev_private;
  423. struct graph_state *pgraph_ctx = chan->engctx[engine];
  424. unsigned long flags;
  425. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  426. nv_mask(dev, NV04_PGRAPH_FIFO, 0x00000001, 0x00000000);
  427. /* Unload the context if it's the currently active one */
  428. if (nv04_graph_channel(dev) == chan)
  429. nv04_graph_unload_context(dev);
  430. nv_mask(dev, NV04_PGRAPH_FIFO, 0x00000001, 0x00000001);
  431. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  432. /* Free the context resources */
  433. kfree(pgraph_ctx);
  434. chan->engctx[engine] = NULL;
  435. }
  436. int
  437. nv04_graph_object_new(struct nouveau_channel *chan, int engine,
  438. u32 handle, u16 class)
  439. {
  440. struct drm_device *dev = chan->dev;
  441. struct nouveau_gpuobj *obj = NULL;
  442. int ret;
  443. ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
  444. if (ret)
  445. return ret;
  446. obj->engine = 1;
  447. obj->class = class;
  448. #ifdef __BIG_ENDIAN
  449. nv_wo32(obj, 0x00, 0x00080000 | class);
  450. #else
  451. nv_wo32(obj, 0x00, class);
  452. #endif
  453. nv_wo32(obj, 0x04, 0x00000000);
  454. nv_wo32(obj, 0x08, 0x00000000);
  455. nv_wo32(obj, 0x0c, 0x00000000);
  456. ret = nouveau_ramht_insert(chan, handle, obj);
  457. nouveau_gpuobj_ref(NULL, &obj);
  458. return ret;
  459. }
  460. static int
  461. nv04_graph_init(struct drm_device *dev, int engine)
  462. {
  463. struct drm_nouveau_private *dev_priv = dev->dev_private;
  464. uint32_t tmp;
  465. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) &
  466. ~NV_PMC_ENABLE_PGRAPH);
  467. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) |
  468. NV_PMC_ENABLE_PGRAPH);
  469. /* Enable PGRAPH interrupts */
  470. nv_wr32(dev, NV03_PGRAPH_INTR, 0xFFFFFFFF);
  471. nv_wr32(dev, NV03_PGRAPH_INTR_EN, 0xFFFFFFFF);
  472. nv_wr32(dev, NV04_PGRAPH_VALID1, 0);
  473. nv_wr32(dev, NV04_PGRAPH_VALID2, 0);
  474. /*nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x000001FF);
  475. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x001FFFFF);*/
  476. nv_wr32(dev, NV04_PGRAPH_DEBUG_0, 0x1231c000);
  477. /*1231C000 blob, 001 haiku*/
  478. /*V_WRITE(NV04_PGRAPH_DEBUG_1, 0xf2d91100);*/
  479. nv_wr32(dev, NV04_PGRAPH_DEBUG_1, 0x72111100);
  480. /*0x72111100 blob , 01 haiku*/
  481. /*nv_wr32(dev, NV04_PGRAPH_DEBUG_2, 0x11d5f870);*/
  482. nv_wr32(dev, NV04_PGRAPH_DEBUG_2, 0x11d5f071);
  483. /*haiku same*/
  484. /*nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xfad4ff31);*/
  485. nv_wr32(dev, NV04_PGRAPH_DEBUG_3, 0xf0d4ff31);
  486. /*haiku and blob 10d4*/
  487. nv_wr32(dev, NV04_PGRAPH_STATE , 0xFFFFFFFF);
  488. nv_wr32(dev, NV04_PGRAPH_CTX_CONTROL , 0x10000100);
  489. tmp = nv_rd32(dev, NV04_PGRAPH_CTX_USER) & 0x00ffffff;
  490. tmp |= (dev_priv->engine.fifo.channels - 1) << 24;
  491. nv_wr32(dev, NV04_PGRAPH_CTX_USER, tmp);
  492. /* These don't belong here, they're part of a per-channel context */
  493. nv_wr32(dev, NV04_PGRAPH_PATTERN_SHAPE, 0x00000000);
  494. nv_wr32(dev, NV04_PGRAPH_BETA_AND , 0xFFFFFFFF);
  495. return 0;
  496. }
  497. static int
  498. nv04_graph_fini(struct drm_device *dev, int engine, bool suspend)
  499. {
  500. nv_mask(dev, NV04_PGRAPH_FIFO, 0x00000001, 0x00000000);
  501. if (!nv_wait(dev, NV04_PGRAPH_STATUS, ~0, 0) && suspend) {
  502. nv_mask(dev, NV04_PGRAPH_FIFO, 0x00000001, 0x00000001);
  503. return -EBUSY;
  504. }
  505. nv04_graph_unload_context(dev);
  506. nv_wr32(dev, NV03_PGRAPH_INTR_EN, 0x00000000);
  507. return 0;
  508. }
  509. static int
  510. nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
  511. u32 class, u32 mthd, u32 data)
  512. {
  513. atomic_set(&chan->fence.last_sequence_irq, data);
  514. return 0;
  515. }
  516. int
  517. nv04_graph_mthd_page_flip(struct nouveau_channel *chan,
  518. u32 class, u32 mthd, u32 data)
  519. {
  520. struct drm_device *dev = chan->dev;
  521. struct nouveau_page_flip_state s;
  522. if (!nouveau_finish_page_flip(chan, &s))
  523. nv_set_crtc_base(dev, s.crtc,
  524. s.offset + s.y * s.pitch + s.x * s.bpp / 8);
  525. return 0;
  526. }
  527. /*
  528. * Software methods, why they are needed, and how they all work:
  529. *
  530. * NV04 and NV05 keep most of the state in PGRAPH context itself, but some
  531. * 2d engine settings are kept inside the grobjs themselves. The grobjs are
  532. * 3 words long on both. grobj format on NV04 is:
  533. *
  534. * word 0:
  535. * - bits 0-7: class
  536. * - bit 12: color key active
  537. * - bit 13: clip rect active
  538. * - bit 14: if set, destination surface is swizzled and taken from buffer 5
  539. * [set by NV04_SWIZZLED_SURFACE], otherwise it's linear and taken
  540. * from buffer 0 [set by NV04_CONTEXT_SURFACES_2D or
  541. * NV03_CONTEXT_SURFACE_DST].
  542. * - bits 15-17: 2d operation [aka patch config]
  543. * - bit 24: patch valid [enables rendering using this object]
  544. * - bit 25: surf3d valid [for tex_tri and multitex_tri only]
  545. * word 1:
  546. * - bits 0-1: mono format
  547. * - bits 8-13: color format
  548. * - bits 16-31: DMA_NOTIFY instance
  549. * word 2:
  550. * - bits 0-15: DMA_A instance
  551. * - bits 16-31: DMA_B instance
  552. *
  553. * On NV05 it's:
  554. *
  555. * word 0:
  556. * - bits 0-7: class
  557. * - bit 12: color key active
  558. * - bit 13: clip rect active
  559. * - bit 14: if set, destination surface is swizzled and taken from buffer 5
  560. * [set by NV04_SWIZZLED_SURFACE], otherwise it's linear and taken
  561. * from buffer 0 [set by NV04_CONTEXT_SURFACES_2D or
  562. * NV03_CONTEXT_SURFACE_DST].
  563. * - bits 15-17: 2d operation [aka patch config]
  564. * - bits 20-22: dither mode
  565. * - bit 24: patch valid [enables rendering using this object]
  566. * - bit 25: surface_dst/surface_color/surf2d/surf3d valid
  567. * - bit 26: surface_src/surface_zeta valid
  568. * - bit 27: pattern valid
  569. * - bit 28: rop valid
  570. * - bit 29: beta1 valid
  571. * - bit 30: beta4 valid
  572. * word 1:
  573. * - bits 0-1: mono format
  574. * - bits 8-13: color format
  575. * - bits 16-31: DMA_NOTIFY instance
  576. * word 2:
  577. * - bits 0-15: DMA_A instance
  578. * - bits 16-31: DMA_B instance
  579. *
  580. * NV05 will set/unset the relevant valid bits when you poke the relevant
  581. * object-binding methods with object of the proper type, or with the NULL
  582. * type. It'll only allow rendering using the grobj if all needed objects
  583. * are bound. The needed set of objects depends on selected operation: for
  584. * example rop object is needed by ROP_AND, but not by SRCCOPY_AND.
  585. *
  586. * NV04 doesn't have these methods implemented at all, and doesn't have the
  587. * relevant bits in grobj. Instead, it'll allow rendering whenever bit 24
  588. * is set. So we have to emulate them in software, internally keeping the
  589. * same bits as NV05 does. Since grobjs are aligned to 16 bytes on nv04,
  590. * but the last word isn't actually used for anything, we abuse it for this
  591. * purpose.
  592. *
  593. * Actually, NV05 can optionally check bit 24 too, but we disable this since
  594. * there's no use for it.
  595. *
  596. * For unknown reasons, NV04 implements surf3d binding in hardware as an
  597. * exception. Also for unknown reasons, NV04 doesn't implement the clipping
  598. * methods on the surf3d object, so we have to emulate them too.
  599. */
  600. static void
  601. nv04_graph_set_ctx1(struct nouveau_channel *chan, u32 mask, u32 value)
  602. {
  603. struct drm_device *dev = chan->dev;
  604. u32 instance = (nv_rd32(dev, NV04_PGRAPH_CTX_SWITCH4) & 0xffff) << 4;
  605. int subc = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 13) & 0x7;
  606. u32 tmp;
  607. tmp = nv_ri32(dev, instance);
  608. tmp &= ~mask;
  609. tmp |= value;
  610. nv_wi32(dev, instance, tmp);
  611. nv_wr32(dev, NV04_PGRAPH_CTX_SWITCH1, tmp);
  612. nv_wr32(dev, NV04_PGRAPH_CTX_CACHE1 + (subc<<2), tmp);
  613. }
  614. static void
  615. nv04_graph_set_ctx_val(struct nouveau_channel *chan, u32 mask, u32 value)
  616. {
  617. struct drm_device *dev = chan->dev;
  618. u32 instance = (nv_rd32(dev, NV04_PGRAPH_CTX_SWITCH4) & 0xffff) << 4;
  619. u32 tmp, ctx1;
  620. int class, op, valid = 1;
  621. ctx1 = nv_ri32(dev, instance);
  622. class = ctx1 & 0xff;
  623. op = (ctx1 >> 15) & 7;
  624. tmp = nv_ri32(dev, instance + 0xc);
  625. tmp &= ~mask;
  626. tmp |= value;
  627. nv_wi32(dev, instance + 0xc, tmp);
  628. /* check for valid surf2d/surf_dst/surf_color */
  629. if (!(tmp & 0x02000000))
  630. valid = 0;
  631. /* check for valid surf_src/surf_zeta */
  632. if ((class == 0x1f || class == 0x48) && !(tmp & 0x04000000))
  633. valid = 0;
  634. switch (op) {
  635. /* SRCCOPY_AND, SRCCOPY: no extra objects required */
  636. case 0:
  637. case 3:
  638. break;
  639. /* ROP_AND: requires pattern and rop */
  640. case 1:
  641. if (!(tmp & 0x18000000))
  642. valid = 0;
  643. break;
  644. /* BLEND_AND: requires beta1 */
  645. case 2:
  646. if (!(tmp & 0x20000000))
  647. valid = 0;
  648. break;
  649. /* SRCCOPY_PREMULT, BLEND_PREMULT: beta4 required */
  650. case 4:
  651. case 5:
  652. if (!(tmp & 0x40000000))
  653. valid = 0;
  654. break;
  655. }
  656. nv04_graph_set_ctx1(chan, 0x01000000, valid << 24);
  657. }
  658. static int
  659. nv04_graph_mthd_set_operation(struct nouveau_channel *chan,
  660. u32 class, u32 mthd, u32 data)
  661. {
  662. if (data > 5)
  663. return 1;
  664. /* Old versions of the objects only accept first three operations. */
  665. if (data > 2 && class < 0x40)
  666. return 1;
  667. nv04_graph_set_ctx1(chan, 0x00038000, data << 15);
  668. /* changing operation changes set of objects needed for validation */
  669. nv04_graph_set_ctx_val(chan, 0, 0);
  670. return 0;
  671. }
  672. static int
  673. nv04_graph_mthd_surf3d_clip_h(struct nouveau_channel *chan,
  674. u32 class, u32 mthd, u32 data)
  675. {
  676. uint32_t min = data & 0xffff, max;
  677. uint32_t w = data >> 16;
  678. if (min & 0x8000)
  679. /* too large */
  680. return 1;
  681. if (w & 0x8000)
  682. /* yes, it accepts negative for some reason. */
  683. w |= 0xffff0000;
  684. max = min + w;
  685. max &= 0x3ffff;
  686. nv_wr32(chan->dev, 0x40053c, min);
  687. nv_wr32(chan->dev, 0x400544, max);
  688. return 0;
  689. }
  690. static int
  691. nv04_graph_mthd_surf3d_clip_v(struct nouveau_channel *chan,
  692. u32 class, u32 mthd, u32 data)
  693. {
  694. uint32_t min = data & 0xffff, max;
  695. uint32_t w = data >> 16;
  696. if (min & 0x8000)
  697. /* too large */
  698. return 1;
  699. if (w & 0x8000)
  700. /* yes, it accepts negative for some reason. */
  701. w |= 0xffff0000;
  702. max = min + w;
  703. max &= 0x3ffff;
  704. nv_wr32(chan->dev, 0x400540, min);
  705. nv_wr32(chan->dev, 0x400548, max);
  706. return 0;
  707. }
  708. static int
  709. nv04_graph_mthd_bind_surf2d(struct nouveau_channel *chan,
  710. u32 class, u32 mthd, u32 data)
  711. {
  712. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  713. case 0x30:
  714. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  715. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  716. return 0;
  717. case 0x42:
  718. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  719. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  720. return 0;
  721. }
  722. return 1;
  723. }
  724. static int
  725. nv04_graph_mthd_bind_surf2d_swzsurf(struct nouveau_channel *chan,
  726. u32 class, u32 mthd, u32 data)
  727. {
  728. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  729. case 0x30:
  730. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  731. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  732. return 0;
  733. case 0x42:
  734. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  735. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  736. return 0;
  737. case 0x52:
  738. nv04_graph_set_ctx1(chan, 0x00004000, 0x00004000);
  739. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  740. return 0;
  741. }
  742. return 1;
  743. }
  744. static int
  745. nv04_graph_mthd_bind_nv01_patt(struct nouveau_channel *chan,
  746. u32 class, u32 mthd, u32 data)
  747. {
  748. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  749. case 0x30:
  750. nv04_graph_set_ctx_val(chan, 0x08000000, 0);
  751. return 0;
  752. case 0x18:
  753. nv04_graph_set_ctx_val(chan, 0x08000000, 0x08000000);
  754. return 0;
  755. }
  756. return 1;
  757. }
  758. static int
  759. nv04_graph_mthd_bind_nv04_patt(struct nouveau_channel *chan,
  760. u32 class, u32 mthd, u32 data)
  761. {
  762. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  763. case 0x30:
  764. nv04_graph_set_ctx_val(chan, 0x08000000, 0);
  765. return 0;
  766. case 0x44:
  767. nv04_graph_set_ctx_val(chan, 0x08000000, 0x08000000);
  768. return 0;
  769. }
  770. return 1;
  771. }
  772. static int
  773. nv04_graph_mthd_bind_rop(struct nouveau_channel *chan,
  774. u32 class, u32 mthd, u32 data)
  775. {
  776. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  777. case 0x30:
  778. nv04_graph_set_ctx_val(chan, 0x10000000, 0);
  779. return 0;
  780. case 0x43:
  781. nv04_graph_set_ctx_val(chan, 0x10000000, 0x10000000);
  782. return 0;
  783. }
  784. return 1;
  785. }
  786. static int
  787. nv04_graph_mthd_bind_beta1(struct nouveau_channel *chan,
  788. u32 class, u32 mthd, u32 data)
  789. {
  790. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  791. case 0x30:
  792. nv04_graph_set_ctx_val(chan, 0x20000000, 0);
  793. return 0;
  794. case 0x12:
  795. nv04_graph_set_ctx_val(chan, 0x20000000, 0x20000000);
  796. return 0;
  797. }
  798. return 1;
  799. }
  800. static int
  801. nv04_graph_mthd_bind_beta4(struct nouveau_channel *chan,
  802. u32 class, u32 mthd, u32 data)
  803. {
  804. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  805. case 0x30:
  806. nv04_graph_set_ctx_val(chan, 0x40000000, 0);
  807. return 0;
  808. case 0x72:
  809. nv04_graph_set_ctx_val(chan, 0x40000000, 0x40000000);
  810. return 0;
  811. }
  812. return 1;
  813. }
  814. static int
  815. nv04_graph_mthd_bind_surf_dst(struct nouveau_channel *chan,
  816. u32 class, u32 mthd, u32 data)
  817. {
  818. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  819. case 0x30:
  820. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  821. return 0;
  822. case 0x58:
  823. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  824. return 0;
  825. }
  826. return 1;
  827. }
  828. static int
  829. nv04_graph_mthd_bind_surf_src(struct nouveau_channel *chan,
  830. u32 class, u32 mthd, u32 data)
  831. {
  832. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  833. case 0x30:
  834. nv04_graph_set_ctx_val(chan, 0x04000000, 0);
  835. return 0;
  836. case 0x59:
  837. nv04_graph_set_ctx_val(chan, 0x04000000, 0x04000000);
  838. return 0;
  839. }
  840. return 1;
  841. }
  842. static int
  843. nv04_graph_mthd_bind_surf_color(struct nouveau_channel *chan,
  844. u32 class, u32 mthd, u32 data)
  845. {
  846. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  847. case 0x30:
  848. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  849. return 0;
  850. case 0x5a:
  851. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  852. return 0;
  853. }
  854. return 1;
  855. }
  856. static int
  857. nv04_graph_mthd_bind_surf_zeta(struct nouveau_channel *chan,
  858. u32 class, u32 mthd, u32 data)
  859. {
  860. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  861. case 0x30:
  862. nv04_graph_set_ctx_val(chan, 0x04000000, 0);
  863. return 0;
  864. case 0x5b:
  865. nv04_graph_set_ctx_val(chan, 0x04000000, 0x04000000);
  866. return 0;
  867. }
  868. return 1;
  869. }
  870. static int
  871. nv04_graph_mthd_bind_clip(struct nouveau_channel *chan,
  872. u32 class, u32 mthd, u32 data)
  873. {
  874. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  875. case 0x30:
  876. nv04_graph_set_ctx1(chan, 0x2000, 0);
  877. return 0;
  878. case 0x19:
  879. nv04_graph_set_ctx1(chan, 0x2000, 0x2000);
  880. return 0;
  881. }
  882. return 1;
  883. }
  884. static int
  885. nv04_graph_mthd_bind_chroma(struct nouveau_channel *chan,
  886. u32 class, u32 mthd, u32 data)
  887. {
  888. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  889. case 0x30:
  890. nv04_graph_set_ctx1(chan, 0x1000, 0);
  891. return 0;
  892. /* Yes, for some reason even the old versions of objects
  893. * accept 0x57 and not 0x17. Consistency be damned.
  894. */
  895. case 0x57:
  896. nv04_graph_set_ctx1(chan, 0x1000, 0x1000);
  897. return 0;
  898. }
  899. return 1;
  900. }
  901. static struct nouveau_bitfield nv04_graph_intr[] = {
  902. { NV_PGRAPH_INTR_NOTIFY, "NOTIFY" },
  903. {}
  904. };
  905. static struct nouveau_bitfield nv04_graph_nstatus[] = {
  906. { NV04_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
  907. { NV04_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
  908. { NV04_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
  909. { NV04_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" },
  910. {}
  911. };
  912. struct nouveau_bitfield nv04_graph_nsource[] = {
  913. { NV03_PGRAPH_NSOURCE_NOTIFICATION, "NOTIFICATION" },
  914. { NV03_PGRAPH_NSOURCE_DATA_ERROR, "DATA_ERROR" },
  915. { NV03_PGRAPH_NSOURCE_PROTECTION_ERROR, "PROTECTION_ERROR" },
  916. { NV03_PGRAPH_NSOURCE_RANGE_EXCEPTION, "RANGE_EXCEPTION" },
  917. { NV03_PGRAPH_NSOURCE_LIMIT_COLOR, "LIMIT_COLOR" },
  918. { NV03_PGRAPH_NSOURCE_LIMIT_ZETA, "LIMIT_ZETA" },
  919. { NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD, "ILLEGAL_MTHD" },
  920. { NV03_PGRAPH_NSOURCE_DMA_R_PROTECTION, "DMA_R_PROTECTION" },
  921. { NV03_PGRAPH_NSOURCE_DMA_W_PROTECTION, "DMA_W_PROTECTION" },
  922. { NV03_PGRAPH_NSOURCE_FORMAT_EXCEPTION, "FORMAT_EXCEPTION" },
  923. { NV03_PGRAPH_NSOURCE_PATCH_EXCEPTION, "PATCH_EXCEPTION" },
  924. { NV03_PGRAPH_NSOURCE_STATE_INVALID, "STATE_INVALID" },
  925. { NV03_PGRAPH_NSOURCE_DOUBLE_NOTIFY, "DOUBLE_NOTIFY" },
  926. { NV03_PGRAPH_NSOURCE_NOTIFY_IN_USE, "NOTIFY_IN_USE" },
  927. { NV03_PGRAPH_NSOURCE_METHOD_CNT, "METHOD_CNT" },
  928. { NV03_PGRAPH_NSOURCE_BFR_NOTIFICATION, "BFR_NOTIFICATION" },
  929. { NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION, "DMA_VTX_PROTECTION" },
  930. { NV03_PGRAPH_NSOURCE_DMA_WIDTH_A, "DMA_WIDTH_A" },
  931. { NV03_PGRAPH_NSOURCE_DMA_WIDTH_B, "DMA_WIDTH_B" },
  932. {}
  933. };
  934. static void
  935. nv04_graph_context_switch(struct drm_device *dev)
  936. {
  937. struct drm_nouveau_private *dev_priv = dev->dev_private;
  938. struct nouveau_channel *chan = NULL;
  939. int chid;
  940. nouveau_wait_for_idle(dev);
  941. /* If previous context is valid, we need to save it */
  942. nv04_graph_unload_context(dev);
  943. /* Load context for next channel */
  944. chid = dev_priv->engine.fifo.channel_id(dev);
  945. chan = dev_priv->channels.ptr[chid];
  946. if (chan)
  947. nv04_graph_load_context(chan);
  948. }
  949. static void
  950. nv04_graph_isr(struct drm_device *dev)
  951. {
  952. u32 stat;
  953. while ((stat = nv_rd32(dev, NV03_PGRAPH_INTR))) {
  954. u32 nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
  955. u32 nstatus = nv_rd32(dev, NV03_PGRAPH_NSTATUS);
  956. u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
  957. u32 chid = (addr & 0x0f000000) >> 24;
  958. u32 subc = (addr & 0x0000e000) >> 13;
  959. u32 mthd = (addr & 0x00001ffc);
  960. u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
  961. u32 class = nv_rd32(dev, 0x400180 + subc * 4) & 0xff;
  962. u32 show = stat;
  963. if (stat & NV_PGRAPH_INTR_NOTIFY) {
  964. if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) {
  965. if (!nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data))
  966. show &= ~NV_PGRAPH_INTR_NOTIFY;
  967. }
  968. }
  969. if (stat & NV_PGRAPH_INTR_CONTEXT_SWITCH) {
  970. nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_CONTEXT_SWITCH);
  971. stat &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
  972. show &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
  973. nv04_graph_context_switch(dev);
  974. }
  975. nv_wr32(dev, NV03_PGRAPH_INTR, stat);
  976. nv_wr32(dev, NV04_PGRAPH_FIFO, 0x00000001);
  977. if (show && nouveau_ratelimit()) {
  978. NV_INFO(dev, "PGRAPH -");
  979. nouveau_bitfield_print(nv04_graph_intr, show);
  980. printk(" nsource:");
  981. nouveau_bitfield_print(nv04_graph_nsource, nsource);
  982. printk(" nstatus:");
  983. nouveau_bitfield_print(nv04_graph_nstatus, nstatus);
  984. printk("\n");
  985. NV_INFO(dev, "PGRAPH - ch %d/%d class 0x%04x "
  986. "mthd 0x%04x data 0x%08x\n",
  987. chid, subc, class, mthd, data);
  988. }
  989. }
  990. }
  991. static void
  992. nv04_graph_destroy(struct drm_device *dev, int engine)
  993. {
  994. struct nv04_graph_engine *pgraph = nv_engine(dev, engine);
  995. nouveau_irq_unregister(dev, 12);
  996. NVOBJ_ENGINE_DEL(dev, GR);
  997. kfree(pgraph);
  998. }
  999. int
  1000. nv04_graph_create(struct drm_device *dev)
  1001. {
  1002. struct nv04_graph_engine *pgraph;
  1003. pgraph = kzalloc(sizeof(*pgraph), GFP_KERNEL);
  1004. if (!pgraph)
  1005. return -ENOMEM;
  1006. pgraph->base.destroy = nv04_graph_destroy;
  1007. pgraph->base.init = nv04_graph_init;
  1008. pgraph->base.fini = nv04_graph_fini;
  1009. pgraph->base.context_new = nv04_graph_context_new;
  1010. pgraph->base.context_del = nv04_graph_context_del;
  1011. pgraph->base.object_new = nv04_graph_object_new;
  1012. NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
  1013. nouveau_irq_register(dev, 12, nv04_graph_isr);
  1014. /* dvd subpicture */
  1015. NVOBJ_CLASS(dev, 0x0038, GR);
  1016. /* m2mf */
  1017. NVOBJ_CLASS(dev, 0x0039, GR);
  1018. /* nv03 gdirect */
  1019. NVOBJ_CLASS(dev, 0x004b, GR);
  1020. NVOBJ_MTHD (dev, 0x004b, 0x0184, nv04_graph_mthd_bind_nv01_patt);
  1021. NVOBJ_MTHD (dev, 0x004b, 0x0188, nv04_graph_mthd_bind_rop);
  1022. NVOBJ_MTHD (dev, 0x004b, 0x018c, nv04_graph_mthd_bind_beta1);
  1023. NVOBJ_MTHD (dev, 0x004b, 0x0190, nv04_graph_mthd_bind_surf_dst);
  1024. NVOBJ_MTHD (dev, 0x004b, 0x02fc, nv04_graph_mthd_set_operation);
  1025. /* nv04 gdirect */
  1026. NVOBJ_CLASS(dev, 0x004a, GR);
  1027. NVOBJ_MTHD (dev, 0x004a, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1028. NVOBJ_MTHD (dev, 0x004a, 0x018c, nv04_graph_mthd_bind_rop);
  1029. NVOBJ_MTHD (dev, 0x004a, 0x0190, nv04_graph_mthd_bind_beta1);
  1030. NVOBJ_MTHD (dev, 0x004a, 0x0194, nv04_graph_mthd_bind_beta4);
  1031. NVOBJ_MTHD (dev, 0x004a, 0x0198, nv04_graph_mthd_bind_surf2d);
  1032. NVOBJ_MTHD (dev, 0x004a, 0x02fc, nv04_graph_mthd_set_operation);
  1033. /* nv01 imageblit */
  1034. NVOBJ_CLASS(dev, 0x001f, GR);
  1035. NVOBJ_MTHD (dev, 0x001f, 0x0184, nv04_graph_mthd_bind_chroma);
  1036. NVOBJ_MTHD (dev, 0x001f, 0x0188, nv04_graph_mthd_bind_clip);
  1037. NVOBJ_MTHD (dev, 0x001f, 0x018c, nv04_graph_mthd_bind_nv01_patt);
  1038. NVOBJ_MTHD (dev, 0x001f, 0x0190, nv04_graph_mthd_bind_rop);
  1039. NVOBJ_MTHD (dev, 0x001f, 0x0194, nv04_graph_mthd_bind_beta1);
  1040. NVOBJ_MTHD (dev, 0x001f, 0x0198, nv04_graph_mthd_bind_surf_dst);
  1041. NVOBJ_MTHD (dev, 0x001f, 0x019c, nv04_graph_mthd_bind_surf_src);
  1042. NVOBJ_MTHD (dev, 0x001f, 0x02fc, nv04_graph_mthd_set_operation);
  1043. /* nv04 imageblit */
  1044. NVOBJ_CLASS(dev, 0x005f, GR);
  1045. NVOBJ_MTHD (dev, 0x005f, 0x0184, nv04_graph_mthd_bind_chroma);
  1046. NVOBJ_MTHD (dev, 0x005f, 0x0188, nv04_graph_mthd_bind_clip);
  1047. NVOBJ_MTHD (dev, 0x005f, 0x018c, nv04_graph_mthd_bind_nv04_patt);
  1048. NVOBJ_MTHD (dev, 0x005f, 0x0190, nv04_graph_mthd_bind_rop);
  1049. NVOBJ_MTHD (dev, 0x005f, 0x0194, nv04_graph_mthd_bind_beta1);
  1050. NVOBJ_MTHD (dev, 0x005f, 0x0198, nv04_graph_mthd_bind_beta4);
  1051. NVOBJ_MTHD (dev, 0x005f, 0x019c, nv04_graph_mthd_bind_surf2d);
  1052. NVOBJ_MTHD (dev, 0x005f, 0x02fc, nv04_graph_mthd_set_operation);
  1053. /* nv04 iifc */
  1054. NVOBJ_CLASS(dev, 0x0060, GR);
  1055. NVOBJ_MTHD (dev, 0x0060, 0x0188, nv04_graph_mthd_bind_chroma);
  1056. NVOBJ_MTHD (dev, 0x0060, 0x018c, nv04_graph_mthd_bind_clip);
  1057. NVOBJ_MTHD (dev, 0x0060, 0x0190, nv04_graph_mthd_bind_nv04_patt);
  1058. NVOBJ_MTHD (dev, 0x0060, 0x0194, nv04_graph_mthd_bind_rop);
  1059. NVOBJ_MTHD (dev, 0x0060, 0x0198, nv04_graph_mthd_bind_beta1);
  1060. NVOBJ_MTHD (dev, 0x0060, 0x019c, nv04_graph_mthd_bind_beta4);
  1061. NVOBJ_MTHD (dev, 0x0060, 0x01a0, nv04_graph_mthd_bind_surf2d_swzsurf);
  1062. NVOBJ_MTHD (dev, 0x0060, 0x03e4, nv04_graph_mthd_set_operation);
  1063. /* nv05 iifc */
  1064. NVOBJ_CLASS(dev, 0x0064, GR);
  1065. /* nv01 ifc */
  1066. NVOBJ_CLASS(dev, 0x0021, GR);
  1067. NVOBJ_MTHD (dev, 0x0021, 0x0184, nv04_graph_mthd_bind_chroma);
  1068. NVOBJ_MTHD (dev, 0x0021, 0x0188, nv04_graph_mthd_bind_clip);
  1069. NVOBJ_MTHD (dev, 0x0021, 0x018c, nv04_graph_mthd_bind_nv01_patt);
  1070. NVOBJ_MTHD (dev, 0x0021, 0x0190, nv04_graph_mthd_bind_rop);
  1071. NVOBJ_MTHD (dev, 0x0021, 0x0194, nv04_graph_mthd_bind_beta1);
  1072. NVOBJ_MTHD (dev, 0x0021, 0x0198, nv04_graph_mthd_bind_surf_dst);
  1073. NVOBJ_MTHD (dev, 0x0021, 0x02fc, nv04_graph_mthd_set_operation);
  1074. /* nv04 ifc */
  1075. NVOBJ_CLASS(dev, 0x0061, GR);
  1076. NVOBJ_MTHD (dev, 0x0061, 0x0184, nv04_graph_mthd_bind_chroma);
  1077. NVOBJ_MTHD (dev, 0x0061, 0x0188, nv04_graph_mthd_bind_clip);
  1078. NVOBJ_MTHD (dev, 0x0061, 0x018c, nv04_graph_mthd_bind_nv04_patt);
  1079. NVOBJ_MTHD (dev, 0x0061, 0x0190, nv04_graph_mthd_bind_rop);
  1080. NVOBJ_MTHD (dev, 0x0061, 0x0194, nv04_graph_mthd_bind_beta1);
  1081. NVOBJ_MTHD (dev, 0x0061, 0x0198, nv04_graph_mthd_bind_beta4);
  1082. NVOBJ_MTHD (dev, 0x0061, 0x019c, nv04_graph_mthd_bind_surf2d);
  1083. NVOBJ_MTHD (dev, 0x0061, 0x02fc, nv04_graph_mthd_set_operation);
  1084. /* nv05 ifc */
  1085. NVOBJ_CLASS(dev, 0x0065, GR);
  1086. /* nv03 sifc */
  1087. NVOBJ_CLASS(dev, 0x0036, GR);
  1088. NVOBJ_MTHD (dev, 0x0036, 0x0184, nv04_graph_mthd_bind_chroma);
  1089. NVOBJ_MTHD (dev, 0x0036, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1090. NVOBJ_MTHD (dev, 0x0036, 0x018c, nv04_graph_mthd_bind_rop);
  1091. NVOBJ_MTHD (dev, 0x0036, 0x0190, nv04_graph_mthd_bind_beta1);
  1092. NVOBJ_MTHD (dev, 0x0036, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1093. NVOBJ_MTHD (dev, 0x0036, 0x02fc, nv04_graph_mthd_set_operation);
  1094. /* nv04 sifc */
  1095. NVOBJ_CLASS(dev, 0x0076, GR);
  1096. NVOBJ_MTHD (dev, 0x0076, 0x0184, nv04_graph_mthd_bind_chroma);
  1097. NVOBJ_MTHD (dev, 0x0076, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1098. NVOBJ_MTHD (dev, 0x0076, 0x018c, nv04_graph_mthd_bind_rop);
  1099. NVOBJ_MTHD (dev, 0x0076, 0x0190, nv04_graph_mthd_bind_beta1);
  1100. NVOBJ_MTHD (dev, 0x0076, 0x0194, nv04_graph_mthd_bind_beta4);
  1101. NVOBJ_MTHD (dev, 0x0076, 0x0198, nv04_graph_mthd_bind_surf2d);
  1102. NVOBJ_MTHD (dev, 0x0076, 0x02fc, nv04_graph_mthd_set_operation);
  1103. /* nv05 sifc */
  1104. NVOBJ_CLASS(dev, 0x0066, GR);
  1105. /* nv03 sifm */
  1106. NVOBJ_CLASS(dev, 0x0037, GR);
  1107. NVOBJ_MTHD (dev, 0x0037, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1108. NVOBJ_MTHD (dev, 0x0037, 0x018c, nv04_graph_mthd_bind_rop);
  1109. NVOBJ_MTHD (dev, 0x0037, 0x0190, nv04_graph_mthd_bind_beta1);
  1110. NVOBJ_MTHD (dev, 0x0037, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1111. NVOBJ_MTHD (dev, 0x0037, 0x0304, nv04_graph_mthd_set_operation);
  1112. /* nv04 sifm */
  1113. NVOBJ_CLASS(dev, 0x0077, GR);
  1114. NVOBJ_MTHD (dev, 0x0077, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1115. NVOBJ_MTHD (dev, 0x0077, 0x018c, nv04_graph_mthd_bind_rop);
  1116. NVOBJ_MTHD (dev, 0x0077, 0x0190, nv04_graph_mthd_bind_beta1);
  1117. NVOBJ_MTHD (dev, 0x0077, 0x0194, nv04_graph_mthd_bind_beta4);
  1118. NVOBJ_MTHD (dev, 0x0077, 0x0198, nv04_graph_mthd_bind_surf2d_swzsurf);
  1119. NVOBJ_MTHD (dev, 0x0077, 0x0304, nv04_graph_mthd_set_operation);
  1120. /* null */
  1121. NVOBJ_CLASS(dev, 0x0030, GR);
  1122. /* surf2d */
  1123. NVOBJ_CLASS(dev, 0x0042, GR);
  1124. /* rop */
  1125. NVOBJ_CLASS(dev, 0x0043, GR);
  1126. /* beta1 */
  1127. NVOBJ_CLASS(dev, 0x0012, GR);
  1128. /* beta4 */
  1129. NVOBJ_CLASS(dev, 0x0072, GR);
  1130. /* cliprect */
  1131. NVOBJ_CLASS(dev, 0x0019, GR);
  1132. /* nv01 pattern */
  1133. NVOBJ_CLASS(dev, 0x0018, GR);
  1134. /* nv04 pattern */
  1135. NVOBJ_CLASS(dev, 0x0044, GR);
  1136. /* swzsurf */
  1137. NVOBJ_CLASS(dev, 0x0052, GR);
  1138. /* surf3d */
  1139. NVOBJ_CLASS(dev, 0x0053, GR);
  1140. NVOBJ_MTHD (dev, 0x0053, 0x02f8, nv04_graph_mthd_surf3d_clip_h);
  1141. NVOBJ_MTHD (dev, 0x0053, 0x02fc, nv04_graph_mthd_surf3d_clip_v);
  1142. /* nv03 tex_tri */
  1143. NVOBJ_CLASS(dev, 0x0048, GR);
  1144. NVOBJ_MTHD (dev, 0x0048, 0x0188, nv04_graph_mthd_bind_clip);
  1145. NVOBJ_MTHD (dev, 0x0048, 0x018c, nv04_graph_mthd_bind_surf_color);
  1146. NVOBJ_MTHD (dev, 0x0048, 0x0190, nv04_graph_mthd_bind_surf_zeta);
  1147. /* tex_tri */
  1148. NVOBJ_CLASS(dev, 0x0054, GR);
  1149. /* multitex_tri */
  1150. NVOBJ_CLASS(dev, 0x0055, GR);
  1151. /* nv01 chroma */
  1152. NVOBJ_CLASS(dev, 0x0017, GR);
  1153. /* nv04 chroma */
  1154. NVOBJ_CLASS(dev, 0x0057, GR);
  1155. /* surf_dst */
  1156. NVOBJ_CLASS(dev, 0x0058, GR);
  1157. /* surf_src */
  1158. NVOBJ_CLASS(dev, 0x0059, GR);
  1159. /* surf_color */
  1160. NVOBJ_CLASS(dev, 0x005a, GR);
  1161. /* surf_zeta */
  1162. NVOBJ_CLASS(dev, 0x005b, GR);
  1163. /* nv01 line */
  1164. NVOBJ_CLASS(dev, 0x001c, GR);
  1165. NVOBJ_MTHD (dev, 0x001c, 0x0184, nv04_graph_mthd_bind_clip);
  1166. NVOBJ_MTHD (dev, 0x001c, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1167. NVOBJ_MTHD (dev, 0x001c, 0x018c, nv04_graph_mthd_bind_rop);
  1168. NVOBJ_MTHD (dev, 0x001c, 0x0190, nv04_graph_mthd_bind_beta1);
  1169. NVOBJ_MTHD (dev, 0x001c, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1170. NVOBJ_MTHD (dev, 0x001c, 0x02fc, nv04_graph_mthd_set_operation);
  1171. /* nv04 line */
  1172. NVOBJ_CLASS(dev, 0x005c, GR);
  1173. NVOBJ_MTHD (dev, 0x005c, 0x0184, nv04_graph_mthd_bind_clip);
  1174. NVOBJ_MTHD (dev, 0x005c, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1175. NVOBJ_MTHD (dev, 0x005c, 0x018c, nv04_graph_mthd_bind_rop);
  1176. NVOBJ_MTHD (dev, 0x005c, 0x0190, nv04_graph_mthd_bind_beta1);
  1177. NVOBJ_MTHD (dev, 0x005c, 0x0194, nv04_graph_mthd_bind_beta4);
  1178. NVOBJ_MTHD (dev, 0x005c, 0x0198, nv04_graph_mthd_bind_surf2d);
  1179. NVOBJ_MTHD (dev, 0x005c, 0x02fc, nv04_graph_mthd_set_operation);
  1180. /* nv01 tri */
  1181. NVOBJ_CLASS(dev, 0x001d, GR);
  1182. NVOBJ_MTHD (dev, 0x001d, 0x0184, nv04_graph_mthd_bind_clip);
  1183. NVOBJ_MTHD (dev, 0x001d, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1184. NVOBJ_MTHD (dev, 0x001d, 0x018c, nv04_graph_mthd_bind_rop);
  1185. NVOBJ_MTHD (dev, 0x001d, 0x0190, nv04_graph_mthd_bind_beta1);
  1186. NVOBJ_MTHD (dev, 0x001d, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1187. NVOBJ_MTHD (dev, 0x001d, 0x02fc, nv04_graph_mthd_set_operation);
  1188. /* nv04 tri */
  1189. NVOBJ_CLASS(dev, 0x005d, GR);
  1190. NVOBJ_MTHD (dev, 0x005d, 0x0184, nv04_graph_mthd_bind_clip);
  1191. NVOBJ_MTHD (dev, 0x005d, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1192. NVOBJ_MTHD (dev, 0x005d, 0x018c, nv04_graph_mthd_bind_rop);
  1193. NVOBJ_MTHD (dev, 0x005d, 0x0190, nv04_graph_mthd_bind_beta1);
  1194. NVOBJ_MTHD (dev, 0x005d, 0x0194, nv04_graph_mthd_bind_beta4);
  1195. NVOBJ_MTHD (dev, 0x005d, 0x0198, nv04_graph_mthd_bind_surf2d);
  1196. NVOBJ_MTHD (dev, 0x005d, 0x02fc, nv04_graph_mthd_set_operation);
  1197. /* nv01 rect */
  1198. NVOBJ_CLASS(dev, 0x001e, GR);
  1199. NVOBJ_MTHD (dev, 0x001e, 0x0184, nv04_graph_mthd_bind_clip);
  1200. NVOBJ_MTHD (dev, 0x001e, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1201. NVOBJ_MTHD (dev, 0x001e, 0x018c, nv04_graph_mthd_bind_rop);
  1202. NVOBJ_MTHD (dev, 0x001e, 0x0190, nv04_graph_mthd_bind_beta1);
  1203. NVOBJ_MTHD (dev, 0x001e, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1204. NVOBJ_MTHD (dev, 0x001e, 0x02fc, nv04_graph_mthd_set_operation);
  1205. /* nv04 rect */
  1206. NVOBJ_CLASS(dev, 0x005e, GR);
  1207. NVOBJ_MTHD (dev, 0x005e, 0x0184, nv04_graph_mthd_bind_clip);
  1208. NVOBJ_MTHD (dev, 0x005e, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1209. NVOBJ_MTHD (dev, 0x005e, 0x018c, nv04_graph_mthd_bind_rop);
  1210. NVOBJ_MTHD (dev, 0x005e, 0x0190, nv04_graph_mthd_bind_beta1);
  1211. NVOBJ_MTHD (dev, 0x005e, 0x0194, nv04_graph_mthd_bind_beta4);
  1212. NVOBJ_MTHD (dev, 0x005e, 0x0198, nv04_graph_mthd_bind_surf2d);
  1213. NVOBJ_MTHD (dev, 0x005e, 0x02fc, nv04_graph_mthd_set_operation);
  1214. /* nvsw */
  1215. NVOBJ_CLASS(dev, 0x506e, SW);
  1216. NVOBJ_MTHD (dev, 0x506e, 0x0150, nv04_graph_mthd_set_ref);
  1217. NVOBJ_MTHD (dev, 0x506e, 0x0500, nv04_graph_mthd_page_flip);
  1218. return 0;
  1219. }