nv04_graph.c 36 KB

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