nv04_graph.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  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. nv04_graph_fifo_access(dev, false);
  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. nv04_graph_fifo_access(dev, true);
  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)
  499. {
  500. nv04_graph_unload_context(dev);
  501. nv_wr32(dev, NV03_PGRAPH_INTR_EN, 0x00000000);
  502. return 0;
  503. }
  504. void
  505. nv04_graph_fifo_access(struct drm_device *dev, bool enabled)
  506. {
  507. if (enabled)
  508. nv_wr32(dev, NV04_PGRAPH_FIFO,
  509. nv_rd32(dev, NV04_PGRAPH_FIFO) | 1);
  510. else
  511. nv_wr32(dev, NV04_PGRAPH_FIFO,
  512. nv_rd32(dev, NV04_PGRAPH_FIFO) & ~1);
  513. }
  514. static int
  515. nv04_graph_mthd_set_ref(struct nouveau_channel *chan,
  516. u32 class, u32 mthd, u32 data)
  517. {
  518. atomic_set(&chan->fence.last_sequence_irq, data);
  519. return 0;
  520. }
  521. int
  522. nv04_graph_mthd_page_flip(struct nouveau_channel *chan,
  523. u32 class, u32 mthd, u32 data)
  524. {
  525. struct drm_device *dev = chan->dev;
  526. struct nouveau_page_flip_state s;
  527. if (!nouveau_finish_page_flip(chan, &s))
  528. nv_set_crtc_base(dev, s.crtc,
  529. s.offset + s.y * s.pitch + s.x * s.bpp / 8);
  530. return 0;
  531. }
  532. /*
  533. * Software methods, why they are needed, and how they all work:
  534. *
  535. * NV04 and NV05 keep most of the state in PGRAPH context itself, but some
  536. * 2d engine settings are kept inside the grobjs themselves. The grobjs are
  537. * 3 words long on both. grobj format on NV04 is:
  538. *
  539. * word 0:
  540. * - bits 0-7: class
  541. * - bit 12: color key active
  542. * - bit 13: clip rect active
  543. * - bit 14: if set, destination surface is swizzled and taken from buffer 5
  544. * [set by NV04_SWIZZLED_SURFACE], otherwise it's linear and taken
  545. * from buffer 0 [set by NV04_CONTEXT_SURFACES_2D or
  546. * NV03_CONTEXT_SURFACE_DST].
  547. * - bits 15-17: 2d operation [aka patch config]
  548. * - bit 24: patch valid [enables rendering using this object]
  549. * - bit 25: surf3d valid [for tex_tri and multitex_tri only]
  550. * word 1:
  551. * - bits 0-1: mono format
  552. * - bits 8-13: color format
  553. * - bits 16-31: DMA_NOTIFY instance
  554. * word 2:
  555. * - bits 0-15: DMA_A instance
  556. * - bits 16-31: DMA_B instance
  557. *
  558. * On NV05 it's:
  559. *
  560. * word 0:
  561. * - bits 0-7: class
  562. * - bit 12: color key active
  563. * - bit 13: clip rect active
  564. * - bit 14: if set, destination surface is swizzled and taken from buffer 5
  565. * [set by NV04_SWIZZLED_SURFACE], otherwise it's linear and taken
  566. * from buffer 0 [set by NV04_CONTEXT_SURFACES_2D or
  567. * NV03_CONTEXT_SURFACE_DST].
  568. * - bits 15-17: 2d operation [aka patch config]
  569. * - bits 20-22: dither mode
  570. * - bit 24: patch valid [enables rendering using this object]
  571. * - bit 25: surface_dst/surface_color/surf2d/surf3d valid
  572. * - bit 26: surface_src/surface_zeta valid
  573. * - bit 27: pattern valid
  574. * - bit 28: rop valid
  575. * - bit 29: beta1 valid
  576. * - bit 30: beta4 valid
  577. * word 1:
  578. * - bits 0-1: mono format
  579. * - bits 8-13: color format
  580. * - bits 16-31: DMA_NOTIFY instance
  581. * word 2:
  582. * - bits 0-15: DMA_A instance
  583. * - bits 16-31: DMA_B instance
  584. *
  585. * NV05 will set/unset the relevant valid bits when you poke the relevant
  586. * object-binding methods with object of the proper type, or with the NULL
  587. * type. It'll only allow rendering using the grobj if all needed objects
  588. * are bound. The needed set of objects depends on selected operation: for
  589. * example rop object is needed by ROP_AND, but not by SRCCOPY_AND.
  590. *
  591. * NV04 doesn't have these methods implemented at all, and doesn't have the
  592. * relevant bits in grobj. Instead, it'll allow rendering whenever bit 24
  593. * is set. So we have to emulate them in software, internally keeping the
  594. * same bits as NV05 does. Since grobjs are aligned to 16 bytes on nv04,
  595. * but the last word isn't actually used for anything, we abuse it for this
  596. * purpose.
  597. *
  598. * Actually, NV05 can optionally check bit 24 too, but we disable this since
  599. * there's no use for it.
  600. *
  601. * For unknown reasons, NV04 implements surf3d binding in hardware as an
  602. * exception. Also for unknown reasons, NV04 doesn't implement the clipping
  603. * methods on the surf3d object, so we have to emulate them too.
  604. */
  605. static void
  606. nv04_graph_set_ctx1(struct nouveau_channel *chan, u32 mask, u32 value)
  607. {
  608. struct drm_device *dev = chan->dev;
  609. u32 instance = (nv_rd32(dev, NV04_PGRAPH_CTX_SWITCH4) & 0xffff) << 4;
  610. int subc = (nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR) >> 13) & 0x7;
  611. u32 tmp;
  612. tmp = nv_ri32(dev, instance);
  613. tmp &= ~mask;
  614. tmp |= value;
  615. nv_wi32(dev, instance, tmp);
  616. nv_wr32(dev, NV04_PGRAPH_CTX_SWITCH1, tmp);
  617. nv_wr32(dev, NV04_PGRAPH_CTX_CACHE1 + (subc<<2), tmp);
  618. }
  619. static void
  620. nv04_graph_set_ctx_val(struct nouveau_channel *chan, u32 mask, u32 value)
  621. {
  622. struct drm_device *dev = chan->dev;
  623. u32 instance = (nv_rd32(dev, NV04_PGRAPH_CTX_SWITCH4) & 0xffff) << 4;
  624. u32 tmp, ctx1;
  625. int class, op, valid = 1;
  626. ctx1 = nv_ri32(dev, instance);
  627. class = ctx1 & 0xff;
  628. op = (ctx1 >> 15) & 7;
  629. tmp = nv_ri32(dev, instance + 0xc);
  630. tmp &= ~mask;
  631. tmp |= value;
  632. nv_wi32(dev, instance + 0xc, tmp);
  633. /* check for valid surf2d/surf_dst/surf_color */
  634. if (!(tmp & 0x02000000))
  635. valid = 0;
  636. /* check for valid surf_src/surf_zeta */
  637. if ((class == 0x1f || class == 0x48) && !(tmp & 0x04000000))
  638. valid = 0;
  639. switch (op) {
  640. /* SRCCOPY_AND, SRCCOPY: no extra objects required */
  641. case 0:
  642. case 3:
  643. break;
  644. /* ROP_AND: requires pattern and rop */
  645. case 1:
  646. if (!(tmp & 0x18000000))
  647. valid = 0;
  648. break;
  649. /* BLEND_AND: requires beta1 */
  650. case 2:
  651. if (!(tmp & 0x20000000))
  652. valid = 0;
  653. break;
  654. /* SRCCOPY_PREMULT, BLEND_PREMULT: beta4 required */
  655. case 4:
  656. case 5:
  657. if (!(tmp & 0x40000000))
  658. valid = 0;
  659. break;
  660. }
  661. nv04_graph_set_ctx1(chan, 0x01000000, valid << 24);
  662. }
  663. static int
  664. nv04_graph_mthd_set_operation(struct nouveau_channel *chan,
  665. u32 class, u32 mthd, u32 data)
  666. {
  667. if (data > 5)
  668. return 1;
  669. /* Old versions of the objects only accept first three operations. */
  670. if (data > 2 && class < 0x40)
  671. return 1;
  672. nv04_graph_set_ctx1(chan, 0x00038000, data << 15);
  673. /* changing operation changes set of objects needed for validation */
  674. nv04_graph_set_ctx_val(chan, 0, 0);
  675. return 0;
  676. }
  677. static int
  678. nv04_graph_mthd_surf3d_clip_h(struct nouveau_channel *chan,
  679. u32 class, u32 mthd, u32 data)
  680. {
  681. uint32_t min = data & 0xffff, max;
  682. uint32_t w = data >> 16;
  683. if (min & 0x8000)
  684. /* too large */
  685. return 1;
  686. if (w & 0x8000)
  687. /* yes, it accepts negative for some reason. */
  688. w |= 0xffff0000;
  689. max = min + w;
  690. max &= 0x3ffff;
  691. nv_wr32(chan->dev, 0x40053c, min);
  692. nv_wr32(chan->dev, 0x400544, max);
  693. return 0;
  694. }
  695. static int
  696. nv04_graph_mthd_surf3d_clip_v(struct nouveau_channel *chan,
  697. u32 class, u32 mthd, u32 data)
  698. {
  699. uint32_t min = data & 0xffff, max;
  700. uint32_t w = data >> 16;
  701. if (min & 0x8000)
  702. /* too large */
  703. return 1;
  704. if (w & 0x8000)
  705. /* yes, it accepts negative for some reason. */
  706. w |= 0xffff0000;
  707. max = min + w;
  708. max &= 0x3ffff;
  709. nv_wr32(chan->dev, 0x400540, min);
  710. nv_wr32(chan->dev, 0x400548, max);
  711. return 0;
  712. }
  713. static int
  714. nv04_graph_mthd_bind_surf2d(struct nouveau_channel *chan,
  715. u32 class, u32 mthd, u32 data)
  716. {
  717. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  718. case 0x30:
  719. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  720. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  721. return 0;
  722. case 0x42:
  723. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  724. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  725. return 0;
  726. }
  727. return 1;
  728. }
  729. static int
  730. nv04_graph_mthd_bind_surf2d_swzsurf(struct nouveau_channel *chan,
  731. u32 class, u32 mthd, u32 data)
  732. {
  733. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  734. case 0x30:
  735. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  736. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  737. return 0;
  738. case 0x42:
  739. nv04_graph_set_ctx1(chan, 0x00004000, 0);
  740. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  741. return 0;
  742. case 0x52:
  743. nv04_graph_set_ctx1(chan, 0x00004000, 0x00004000);
  744. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  745. return 0;
  746. }
  747. return 1;
  748. }
  749. static int
  750. nv04_graph_mthd_bind_nv01_patt(struct nouveau_channel *chan,
  751. u32 class, u32 mthd, u32 data)
  752. {
  753. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  754. case 0x30:
  755. nv04_graph_set_ctx_val(chan, 0x08000000, 0);
  756. return 0;
  757. case 0x18:
  758. nv04_graph_set_ctx_val(chan, 0x08000000, 0x08000000);
  759. return 0;
  760. }
  761. return 1;
  762. }
  763. static int
  764. nv04_graph_mthd_bind_nv04_patt(struct nouveau_channel *chan,
  765. u32 class, u32 mthd, u32 data)
  766. {
  767. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  768. case 0x30:
  769. nv04_graph_set_ctx_val(chan, 0x08000000, 0);
  770. return 0;
  771. case 0x44:
  772. nv04_graph_set_ctx_val(chan, 0x08000000, 0x08000000);
  773. return 0;
  774. }
  775. return 1;
  776. }
  777. static int
  778. nv04_graph_mthd_bind_rop(struct nouveau_channel *chan,
  779. u32 class, u32 mthd, u32 data)
  780. {
  781. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  782. case 0x30:
  783. nv04_graph_set_ctx_val(chan, 0x10000000, 0);
  784. return 0;
  785. case 0x43:
  786. nv04_graph_set_ctx_val(chan, 0x10000000, 0x10000000);
  787. return 0;
  788. }
  789. return 1;
  790. }
  791. static int
  792. nv04_graph_mthd_bind_beta1(struct nouveau_channel *chan,
  793. u32 class, u32 mthd, u32 data)
  794. {
  795. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  796. case 0x30:
  797. nv04_graph_set_ctx_val(chan, 0x20000000, 0);
  798. return 0;
  799. case 0x12:
  800. nv04_graph_set_ctx_val(chan, 0x20000000, 0x20000000);
  801. return 0;
  802. }
  803. return 1;
  804. }
  805. static int
  806. nv04_graph_mthd_bind_beta4(struct nouveau_channel *chan,
  807. u32 class, u32 mthd, u32 data)
  808. {
  809. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  810. case 0x30:
  811. nv04_graph_set_ctx_val(chan, 0x40000000, 0);
  812. return 0;
  813. case 0x72:
  814. nv04_graph_set_ctx_val(chan, 0x40000000, 0x40000000);
  815. return 0;
  816. }
  817. return 1;
  818. }
  819. static int
  820. nv04_graph_mthd_bind_surf_dst(struct nouveau_channel *chan,
  821. u32 class, u32 mthd, u32 data)
  822. {
  823. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  824. case 0x30:
  825. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  826. return 0;
  827. case 0x58:
  828. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  829. return 0;
  830. }
  831. return 1;
  832. }
  833. static int
  834. nv04_graph_mthd_bind_surf_src(struct nouveau_channel *chan,
  835. u32 class, u32 mthd, u32 data)
  836. {
  837. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  838. case 0x30:
  839. nv04_graph_set_ctx_val(chan, 0x04000000, 0);
  840. return 0;
  841. case 0x59:
  842. nv04_graph_set_ctx_val(chan, 0x04000000, 0x04000000);
  843. return 0;
  844. }
  845. return 1;
  846. }
  847. static int
  848. nv04_graph_mthd_bind_surf_color(struct nouveau_channel *chan,
  849. u32 class, u32 mthd, u32 data)
  850. {
  851. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  852. case 0x30:
  853. nv04_graph_set_ctx_val(chan, 0x02000000, 0);
  854. return 0;
  855. case 0x5a:
  856. nv04_graph_set_ctx_val(chan, 0x02000000, 0x02000000);
  857. return 0;
  858. }
  859. return 1;
  860. }
  861. static int
  862. nv04_graph_mthd_bind_surf_zeta(struct nouveau_channel *chan,
  863. u32 class, u32 mthd, u32 data)
  864. {
  865. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  866. case 0x30:
  867. nv04_graph_set_ctx_val(chan, 0x04000000, 0);
  868. return 0;
  869. case 0x5b:
  870. nv04_graph_set_ctx_val(chan, 0x04000000, 0x04000000);
  871. return 0;
  872. }
  873. return 1;
  874. }
  875. static int
  876. nv04_graph_mthd_bind_clip(struct nouveau_channel *chan,
  877. u32 class, u32 mthd, u32 data)
  878. {
  879. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  880. case 0x30:
  881. nv04_graph_set_ctx1(chan, 0x2000, 0);
  882. return 0;
  883. case 0x19:
  884. nv04_graph_set_ctx1(chan, 0x2000, 0x2000);
  885. return 0;
  886. }
  887. return 1;
  888. }
  889. static int
  890. nv04_graph_mthd_bind_chroma(struct nouveau_channel *chan,
  891. u32 class, u32 mthd, u32 data)
  892. {
  893. switch (nv_ri32(chan->dev, data << 4) & 0xff) {
  894. case 0x30:
  895. nv04_graph_set_ctx1(chan, 0x1000, 0);
  896. return 0;
  897. /* Yes, for some reason even the old versions of objects
  898. * accept 0x57 and not 0x17. Consistency be damned.
  899. */
  900. case 0x57:
  901. nv04_graph_set_ctx1(chan, 0x1000, 0x1000);
  902. return 0;
  903. }
  904. return 1;
  905. }
  906. static struct nouveau_bitfield nv04_graph_intr[] = {
  907. { NV_PGRAPH_INTR_NOTIFY, "NOTIFY" },
  908. {}
  909. };
  910. static struct nouveau_bitfield nv04_graph_nstatus[] = {
  911. { NV04_PGRAPH_NSTATUS_STATE_IN_USE, "STATE_IN_USE" },
  912. { NV04_PGRAPH_NSTATUS_INVALID_STATE, "INVALID_STATE" },
  913. { NV04_PGRAPH_NSTATUS_BAD_ARGUMENT, "BAD_ARGUMENT" },
  914. { NV04_PGRAPH_NSTATUS_PROTECTION_FAULT, "PROTECTION_FAULT" },
  915. {}
  916. };
  917. struct nouveau_bitfield nv04_graph_nsource[] = {
  918. { NV03_PGRAPH_NSOURCE_NOTIFICATION, "NOTIFICATION" },
  919. { NV03_PGRAPH_NSOURCE_DATA_ERROR, "DATA_ERROR" },
  920. { NV03_PGRAPH_NSOURCE_PROTECTION_ERROR, "PROTECTION_ERROR" },
  921. { NV03_PGRAPH_NSOURCE_RANGE_EXCEPTION, "RANGE_EXCEPTION" },
  922. { NV03_PGRAPH_NSOURCE_LIMIT_COLOR, "LIMIT_COLOR" },
  923. { NV03_PGRAPH_NSOURCE_LIMIT_ZETA, "LIMIT_ZETA" },
  924. { NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD, "ILLEGAL_MTHD" },
  925. { NV03_PGRAPH_NSOURCE_DMA_R_PROTECTION, "DMA_R_PROTECTION" },
  926. { NV03_PGRAPH_NSOURCE_DMA_W_PROTECTION, "DMA_W_PROTECTION" },
  927. { NV03_PGRAPH_NSOURCE_FORMAT_EXCEPTION, "FORMAT_EXCEPTION" },
  928. { NV03_PGRAPH_NSOURCE_PATCH_EXCEPTION, "PATCH_EXCEPTION" },
  929. { NV03_PGRAPH_NSOURCE_STATE_INVALID, "STATE_INVALID" },
  930. { NV03_PGRAPH_NSOURCE_DOUBLE_NOTIFY, "DOUBLE_NOTIFY" },
  931. { NV03_PGRAPH_NSOURCE_NOTIFY_IN_USE, "NOTIFY_IN_USE" },
  932. { NV03_PGRAPH_NSOURCE_METHOD_CNT, "METHOD_CNT" },
  933. { NV03_PGRAPH_NSOURCE_BFR_NOTIFICATION, "BFR_NOTIFICATION" },
  934. { NV03_PGRAPH_NSOURCE_DMA_VTX_PROTECTION, "DMA_VTX_PROTECTION" },
  935. { NV03_PGRAPH_NSOURCE_DMA_WIDTH_A, "DMA_WIDTH_A" },
  936. { NV03_PGRAPH_NSOURCE_DMA_WIDTH_B, "DMA_WIDTH_B" },
  937. {}
  938. };
  939. static void
  940. nv04_graph_context_switch(struct drm_device *dev)
  941. {
  942. struct drm_nouveau_private *dev_priv = dev->dev_private;
  943. struct nouveau_channel *chan = NULL;
  944. int chid;
  945. nouveau_wait_for_idle(dev);
  946. /* If previous context is valid, we need to save it */
  947. nv04_graph_unload_context(dev);
  948. /* Load context for next channel */
  949. chid = dev_priv->engine.fifo.channel_id(dev);
  950. chan = dev_priv->channels.ptr[chid];
  951. if (chan)
  952. nv04_graph_load_context(chan);
  953. }
  954. static void
  955. nv04_graph_isr(struct drm_device *dev)
  956. {
  957. u32 stat;
  958. while ((stat = nv_rd32(dev, NV03_PGRAPH_INTR))) {
  959. u32 nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE);
  960. u32 nstatus = nv_rd32(dev, NV03_PGRAPH_NSTATUS);
  961. u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
  962. u32 chid = (addr & 0x0f000000) >> 24;
  963. u32 subc = (addr & 0x0000e000) >> 13;
  964. u32 mthd = (addr & 0x00001ffc);
  965. u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
  966. u32 class = nv_rd32(dev, 0x400180 + subc * 4) & 0xff;
  967. u32 show = stat;
  968. if (stat & NV_PGRAPH_INTR_NOTIFY) {
  969. if (nsource & NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD) {
  970. if (!nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data))
  971. show &= ~NV_PGRAPH_INTR_NOTIFY;
  972. }
  973. }
  974. if (stat & NV_PGRAPH_INTR_CONTEXT_SWITCH) {
  975. nv_wr32(dev, NV03_PGRAPH_INTR, NV_PGRAPH_INTR_CONTEXT_SWITCH);
  976. stat &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
  977. show &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH;
  978. nv04_graph_context_switch(dev);
  979. }
  980. nv_wr32(dev, NV03_PGRAPH_INTR, stat);
  981. nv_wr32(dev, NV04_PGRAPH_FIFO, 0x00000001);
  982. if (show && nouveau_ratelimit()) {
  983. NV_INFO(dev, "PGRAPH -");
  984. nouveau_bitfield_print(nv04_graph_intr, show);
  985. printk(" nsource:");
  986. nouveau_bitfield_print(nv04_graph_nsource, nsource);
  987. printk(" nstatus:");
  988. nouveau_bitfield_print(nv04_graph_nstatus, nstatus);
  989. printk("\n");
  990. NV_INFO(dev, "PGRAPH - ch %d/%d class 0x%04x "
  991. "mthd 0x%04x data 0x%08x\n",
  992. chid, subc, class, mthd, data);
  993. }
  994. }
  995. }
  996. static void
  997. nv04_graph_destroy(struct drm_device *dev, int engine)
  998. {
  999. struct nv04_graph_engine *pgraph = nv_engine(dev, engine);
  1000. nouveau_irq_unregister(dev, 12);
  1001. NVOBJ_ENGINE_DEL(dev, GR);
  1002. kfree(pgraph);
  1003. }
  1004. int
  1005. nv04_graph_create(struct drm_device *dev)
  1006. {
  1007. struct nv04_graph_engine *pgraph;
  1008. pgraph = kzalloc(sizeof(*pgraph), GFP_KERNEL);
  1009. if (!pgraph)
  1010. return -ENOMEM;
  1011. pgraph->base.destroy = nv04_graph_destroy;
  1012. pgraph->base.init = nv04_graph_init;
  1013. pgraph->base.fini = nv04_graph_fini;
  1014. pgraph->base.context_new = nv04_graph_context_new;
  1015. pgraph->base.context_del = nv04_graph_context_del;
  1016. pgraph->base.object_new = nv04_graph_object_new;
  1017. NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
  1018. nouveau_irq_register(dev, 12, nv04_graph_isr);
  1019. /* dvd subpicture */
  1020. NVOBJ_CLASS(dev, 0x0038, GR);
  1021. /* m2mf */
  1022. NVOBJ_CLASS(dev, 0x0039, GR);
  1023. /* nv03 gdirect */
  1024. NVOBJ_CLASS(dev, 0x004b, GR);
  1025. NVOBJ_MTHD (dev, 0x004b, 0x0184, nv04_graph_mthd_bind_nv01_patt);
  1026. NVOBJ_MTHD (dev, 0x004b, 0x0188, nv04_graph_mthd_bind_rop);
  1027. NVOBJ_MTHD (dev, 0x004b, 0x018c, nv04_graph_mthd_bind_beta1);
  1028. NVOBJ_MTHD (dev, 0x004b, 0x0190, nv04_graph_mthd_bind_surf_dst);
  1029. NVOBJ_MTHD (dev, 0x004b, 0x02fc, nv04_graph_mthd_set_operation);
  1030. /* nv04 gdirect */
  1031. NVOBJ_CLASS(dev, 0x004a, GR);
  1032. NVOBJ_MTHD (dev, 0x004a, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1033. NVOBJ_MTHD (dev, 0x004a, 0x018c, nv04_graph_mthd_bind_rop);
  1034. NVOBJ_MTHD (dev, 0x004a, 0x0190, nv04_graph_mthd_bind_beta1);
  1035. NVOBJ_MTHD (dev, 0x004a, 0x0194, nv04_graph_mthd_bind_beta4);
  1036. NVOBJ_MTHD (dev, 0x004a, 0x0198, nv04_graph_mthd_bind_surf2d);
  1037. NVOBJ_MTHD (dev, 0x004a, 0x02fc, nv04_graph_mthd_set_operation);
  1038. /* nv01 imageblit */
  1039. NVOBJ_CLASS(dev, 0x001f, GR);
  1040. NVOBJ_MTHD (dev, 0x001f, 0x0184, nv04_graph_mthd_bind_chroma);
  1041. NVOBJ_MTHD (dev, 0x001f, 0x0188, nv04_graph_mthd_bind_clip);
  1042. NVOBJ_MTHD (dev, 0x001f, 0x018c, nv04_graph_mthd_bind_nv01_patt);
  1043. NVOBJ_MTHD (dev, 0x001f, 0x0190, nv04_graph_mthd_bind_rop);
  1044. NVOBJ_MTHD (dev, 0x001f, 0x0194, nv04_graph_mthd_bind_beta1);
  1045. NVOBJ_MTHD (dev, 0x001f, 0x0198, nv04_graph_mthd_bind_surf_dst);
  1046. NVOBJ_MTHD (dev, 0x001f, 0x019c, nv04_graph_mthd_bind_surf_src);
  1047. NVOBJ_MTHD (dev, 0x001f, 0x02fc, nv04_graph_mthd_set_operation);
  1048. /* nv04 imageblit */
  1049. NVOBJ_CLASS(dev, 0x005f, GR);
  1050. NVOBJ_MTHD (dev, 0x005f, 0x0184, nv04_graph_mthd_bind_chroma);
  1051. NVOBJ_MTHD (dev, 0x005f, 0x0188, nv04_graph_mthd_bind_clip);
  1052. NVOBJ_MTHD (dev, 0x005f, 0x018c, nv04_graph_mthd_bind_nv04_patt);
  1053. NVOBJ_MTHD (dev, 0x005f, 0x0190, nv04_graph_mthd_bind_rop);
  1054. NVOBJ_MTHD (dev, 0x005f, 0x0194, nv04_graph_mthd_bind_beta1);
  1055. NVOBJ_MTHD (dev, 0x005f, 0x0198, nv04_graph_mthd_bind_beta4);
  1056. NVOBJ_MTHD (dev, 0x005f, 0x019c, nv04_graph_mthd_bind_surf2d);
  1057. NVOBJ_MTHD (dev, 0x005f, 0x02fc, nv04_graph_mthd_set_operation);
  1058. /* nv04 iifc */
  1059. NVOBJ_CLASS(dev, 0x0060, GR);
  1060. NVOBJ_MTHD (dev, 0x0060, 0x0188, nv04_graph_mthd_bind_chroma);
  1061. NVOBJ_MTHD (dev, 0x0060, 0x018c, nv04_graph_mthd_bind_clip);
  1062. NVOBJ_MTHD (dev, 0x0060, 0x0190, nv04_graph_mthd_bind_nv04_patt);
  1063. NVOBJ_MTHD (dev, 0x0060, 0x0194, nv04_graph_mthd_bind_rop);
  1064. NVOBJ_MTHD (dev, 0x0060, 0x0198, nv04_graph_mthd_bind_beta1);
  1065. NVOBJ_MTHD (dev, 0x0060, 0x019c, nv04_graph_mthd_bind_beta4);
  1066. NVOBJ_MTHD (dev, 0x0060, 0x01a0, nv04_graph_mthd_bind_surf2d_swzsurf);
  1067. NVOBJ_MTHD (dev, 0x0060, 0x03e4, nv04_graph_mthd_set_operation);
  1068. /* nv05 iifc */
  1069. NVOBJ_CLASS(dev, 0x0064, GR);
  1070. /* nv01 ifc */
  1071. NVOBJ_CLASS(dev, 0x0021, GR);
  1072. NVOBJ_MTHD (dev, 0x0021, 0x0184, nv04_graph_mthd_bind_chroma);
  1073. NVOBJ_MTHD (dev, 0x0021, 0x0188, nv04_graph_mthd_bind_clip);
  1074. NVOBJ_MTHD (dev, 0x0021, 0x018c, nv04_graph_mthd_bind_nv01_patt);
  1075. NVOBJ_MTHD (dev, 0x0021, 0x0190, nv04_graph_mthd_bind_rop);
  1076. NVOBJ_MTHD (dev, 0x0021, 0x0194, nv04_graph_mthd_bind_beta1);
  1077. NVOBJ_MTHD (dev, 0x0021, 0x0198, nv04_graph_mthd_bind_surf_dst);
  1078. NVOBJ_MTHD (dev, 0x0021, 0x02fc, nv04_graph_mthd_set_operation);
  1079. /* nv04 ifc */
  1080. NVOBJ_CLASS(dev, 0x0061, GR);
  1081. NVOBJ_MTHD (dev, 0x0061, 0x0184, nv04_graph_mthd_bind_chroma);
  1082. NVOBJ_MTHD (dev, 0x0061, 0x0188, nv04_graph_mthd_bind_clip);
  1083. NVOBJ_MTHD (dev, 0x0061, 0x018c, nv04_graph_mthd_bind_nv04_patt);
  1084. NVOBJ_MTHD (dev, 0x0061, 0x0190, nv04_graph_mthd_bind_rop);
  1085. NVOBJ_MTHD (dev, 0x0061, 0x0194, nv04_graph_mthd_bind_beta1);
  1086. NVOBJ_MTHD (dev, 0x0061, 0x0198, nv04_graph_mthd_bind_beta4);
  1087. NVOBJ_MTHD (dev, 0x0061, 0x019c, nv04_graph_mthd_bind_surf2d);
  1088. NVOBJ_MTHD (dev, 0x0061, 0x02fc, nv04_graph_mthd_set_operation);
  1089. /* nv05 ifc */
  1090. NVOBJ_CLASS(dev, 0x0065, GR);
  1091. /* nv03 sifc */
  1092. NVOBJ_CLASS(dev, 0x0036, GR);
  1093. NVOBJ_MTHD (dev, 0x0036, 0x0184, nv04_graph_mthd_bind_chroma);
  1094. NVOBJ_MTHD (dev, 0x0036, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1095. NVOBJ_MTHD (dev, 0x0036, 0x018c, nv04_graph_mthd_bind_rop);
  1096. NVOBJ_MTHD (dev, 0x0036, 0x0190, nv04_graph_mthd_bind_beta1);
  1097. NVOBJ_MTHD (dev, 0x0036, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1098. NVOBJ_MTHD (dev, 0x0036, 0x02fc, nv04_graph_mthd_set_operation);
  1099. /* nv04 sifc */
  1100. NVOBJ_CLASS(dev, 0x0076, GR);
  1101. NVOBJ_MTHD (dev, 0x0076, 0x0184, nv04_graph_mthd_bind_chroma);
  1102. NVOBJ_MTHD (dev, 0x0076, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1103. NVOBJ_MTHD (dev, 0x0076, 0x018c, nv04_graph_mthd_bind_rop);
  1104. NVOBJ_MTHD (dev, 0x0076, 0x0190, nv04_graph_mthd_bind_beta1);
  1105. NVOBJ_MTHD (dev, 0x0076, 0x0194, nv04_graph_mthd_bind_beta4);
  1106. NVOBJ_MTHD (dev, 0x0076, 0x0198, nv04_graph_mthd_bind_surf2d);
  1107. NVOBJ_MTHD (dev, 0x0076, 0x02fc, nv04_graph_mthd_set_operation);
  1108. /* nv05 sifc */
  1109. NVOBJ_CLASS(dev, 0x0066, GR);
  1110. /* nv03 sifm */
  1111. NVOBJ_CLASS(dev, 0x0037, GR);
  1112. NVOBJ_MTHD (dev, 0x0037, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1113. NVOBJ_MTHD (dev, 0x0037, 0x018c, nv04_graph_mthd_bind_rop);
  1114. NVOBJ_MTHD (dev, 0x0037, 0x0190, nv04_graph_mthd_bind_beta1);
  1115. NVOBJ_MTHD (dev, 0x0037, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1116. NVOBJ_MTHD (dev, 0x0037, 0x0304, nv04_graph_mthd_set_operation);
  1117. /* nv04 sifm */
  1118. NVOBJ_CLASS(dev, 0x0077, GR);
  1119. NVOBJ_MTHD (dev, 0x0077, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1120. NVOBJ_MTHD (dev, 0x0077, 0x018c, nv04_graph_mthd_bind_rop);
  1121. NVOBJ_MTHD (dev, 0x0077, 0x0190, nv04_graph_mthd_bind_beta1);
  1122. NVOBJ_MTHD (dev, 0x0077, 0x0194, nv04_graph_mthd_bind_beta4);
  1123. NVOBJ_MTHD (dev, 0x0077, 0x0198, nv04_graph_mthd_bind_surf2d_swzsurf);
  1124. NVOBJ_MTHD (dev, 0x0077, 0x0304, nv04_graph_mthd_set_operation);
  1125. /* null */
  1126. NVOBJ_CLASS(dev, 0x0030, GR);
  1127. /* surf2d */
  1128. NVOBJ_CLASS(dev, 0x0042, GR);
  1129. /* rop */
  1130. NVOBJ_CLASS(dev, 0x0043, GR);
  1131. /* beta1 */
  1132. NVOBJ_CLASS(dev, 0x0012, GR);
  1133. /* beta4 */
  1134. NVOBJ_CLASS(dev, 0x0072, GR);
  1135. /* cliprect */
  1136. NVOBJ_CLASS(dev, 0x0019, GR);
  1137. /* nv01 pattern */
  1138. NVOBJ_CLASS(dev, 0x0018, GR);
  1139. /* nv04 pattern */
  1140. NVOBJ_CLASS(dev, 0x0044, GR);
  1141. /* swzsurf */
  1142. NVOBJ_CLASS(dev, 0x0052, GR);
  1143. /* surf3d */
  1144. NVOBJ_CLASS(dev, 0x0053, GR);
  1145. NVOBJ_MTHD (dev, 0x0053, 0x02f8, nv04_graph_mthd_surf3d_clip_h);
  1146. NVOBJ_MTHD (dev, 0x0053, 0x02fc, nv04_graph_mthd_surf3d_clip_v);
  1147. /* nv03 tex_tri */
  1148. NVOBJ_CLASS(dev, 0x0048, GR);
  1149. NVOBJ_MTHD (dev, 0x0048, 0x0188, nv04_graph_mthd_bind_clip);
  1150. NVOBJ_MTHD (dev, 0x0048, 0x018c, nv04_graph_mthd_bind_surf_color);
  1151. NVOBJ_MTHD (dev, 0x0048, 0x0190, nv04_graph_mthd_bind_surf_zeta);
  1152. /* tex_tri */
  1153. NVOBJ_CLASS(dev, 0x0054, GR);
  1154. /* multitex_tri */
  1155. NVOBJ_CLASS(dev, 0x0055, GR);
  1156. /* nv01 chroma */
  1157. NVOBJ_CLASS(dev, 0x0017, GR);
  1158. /* nv04 chroma */
  1159. NVOBJ_CLASS(dev, 0x0057, GR);
  1160. /* surf_dst */
  1161. NVOBJ_CLASS(dev, 0x0058, GR);
  1162. /* surf_src */
  1163. NVOBJ_CLASS(dev, 0x0059, GR);
  1164. /* surf_color */
  1165. NVOBJ_CLASS(dev, 0x005a, GR);
  1166. /* surf_zeta */
  1167. NVOBJ_CLASS(dev, 0x005b, GR);
  1168. /* nv01 line */
  1169. NVOBJ_CLASS(dev, 0x001c, GR);
  1170. NVOBJ_MTHD (dev, 0x001c, 0x0184, nv04_graph_mthd_bind_clip);
  1171. NVOBJ_MTHD (dev, 0x001c, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1172. NVOBJ_MTHD (dev, 0x001c, 0x018c, nv04_graph_mthd_bind_rop);
  1173. NVOBJ_MTHD (dev, 0x001c, 0x0190, nv04_graph_mthd_bind_beta1);
  1174. NVOBJ_MTHD (dev, 0x001c, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1175. NVOBJ_MTHD (dev, 0x001c, 0x02fc, nv04_graph_mthd_set_operation);
  1176. /* nv04 line */
  1177. NVOBJ_CLASS(dev, 0x005c, GR);
  1178. NVOBJ_MTHD (dev, 0x005c, 0x0184, nv04_graph_mthd_bind_clip);
  1179. NVOBJ_MTHD (dev, 0x005c, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1180. NVOBJ_MTHD (dev, 0x005c, 0x018c, nv04_graph_mthd_bind_rop);
  1181. NVOBJ_MTHD (dev, 0x005c, 0x0190, nv04_graph_mthd_bind_beta1);
  1182. NVOBJ_MTHD (dev, 0x005c, 0x0194, nv04_graph_mthd_bind_beta4);
  1183. NVOBJ_MTHD (dev, 0x005c, 0x0198, nv04_graph_mthd_bind_surf2d);
  1184. NVOBJ_MTHD (dev, 0x005c, 0x02fc, nv04_graph_mthd_set_operation);
  1185. /* nv01 tri */
  1186. NVOBJ_CLASS(dev, 0x001d, GR);
  1187. NVOBJ_MTHD (dev, 0x001d, 0x0184, nv04_graph_mthd_bind_clip);
  1188. NVOBJ_MTHD (dev, 0x001d, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1189. NVOBJ_MTHD (dev, 0x001d, 0x018c, nv04_graph_mthd_bind_rop);
  1190. NVOBJ_MTHD (dev, 0x001d, 0x0190, nv04_graph_mthd_bind_beta1);
  1191. NVOBJ_MTHD (dev, 0x001d, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1192. NVOBJ_MTHD (dev, 0x001d, 0x02fc, nv04_graph_mthd_set_operation);
  1193. /* nv04 tri */
  1194. NVOBJ_CLASS(dev, 0x005d, GR);
  1195. NVOBJ_MTHD (dev, 0x005d, 0x0184, nv04_graph_mthd_bind_clip);
  1196. NVOBJ_MTHD (dev, 0x005d, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1197. NVOBJ_MTHD (dev, 0x005d, 0x018c, nv04_graph_mthd_bind_rop);
  1198. NVOBJ_MTHD (dev, 0x005d, 0x0190, nv04_graph_mthd_bind_beta1);
  1199. NVOBJ_MTHD (dev, 0x005d, 0x0194, nv04_graph_mthd_bind_beta4);
  1200. NVOBJ_MTHD (dev, 0x005d, 0x0198, nv04_graph_mthd_bind_surf2d);
  1201. NVOBJ_MTHD (dev, 0x005d, 0x02fc, nv04_graph_mthd_set_operation);
  1202. /* nv01 rect */
  1203. NVOBJ_CLASS(dev, 0x001e, GR);
  1204. NVOBJ_MTHD (dev, 0x001e, 0x0184, nv04_graph_mthd_bind_clip);
  1205. NVOBJ_MTHD (dev, 0x001e, 0x0188, nv04_graph_mthd_bind_nv01_patt);
  1206. NVOBJ_MTHD (dev, 0x001e, 0x018c, nv04_graph_mthd_bind_rop);
  1207. NVOBJ_MTHD (dev, 0x001e, 0x0190, nv04_graph_mthd_bind_beta1);
  1208. NVOBJ_MTHD (dev, 0x001e, 0x0194, nv04_graph_mthd_bind_surf_dst);
  1209. NVOBJ_MTHD (dev, 0x001e, 0x02fc, nv04_graph_mthd_set_operation);
  1210. /* nv04 rect */
  1211. NVOBJ_CLASS(dev, 0x005e, GR);
  1212. NVOBJ_MTHD (dev, 0x005e, 0x0184, nv04_graph_mthd_bind_clip);
  1213. NVOBJ_MTHD (dev, 0x005e, 0x0188, nv04_graph_mthd_bind_nv04_patt);
  1214. NVOBJ_MTHD (dev, 0x005e, 0x018c, nv04_graph_mthd_bind_rop);
  1215. NVOBJ_MTHD (dev, 0x005e, 0x0190, nv04_graph_mthd_bind_beta1);
  1216. NVOBJ_MTHD (dev, 0x005e, 0x0194, nv04_graph_mthd_bind_beta4);
  1217. NVOBJ_MTHD (dev, 0x005e, 0x0198, nv04_graph_mthd_bind_surf2d);
  1218. NVOBJ_MTHD (dev, 0x005e, 0x02fc, nv04_graph_mthd_set_operation);
  1219. /* nvsw */
  1220. NVOBJ_CLASS(dev, 0x506e, SW);
  1221. NVOBJ_MTHD (dev, 0x506e, 0x0150, nv04_graph_mthd_set_ref);
  1222. NVOBJ_MTHD (dev, 0x506e, 0x0500, nv04_graph_mthd_page_flip);
  1223. return 0;
  1224. }