mga_state.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. /* mga_state.c -- State support for MGA G200/G400 -*- linux-c -*-
  2. * Created: Thu Jan 27 02:53:43 2000 by jhartmann@precisioninsight.com
  3. *
  4. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  5. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  6. * All Rights Reserved.
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice (including the next
  16. * paragraph) shall be included in all copies or substantial portions of the
  17. * Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  22. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  23. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  24. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  25. * OTHER DEALINGS IN THE SOFTWARE.
  26. *
  27. * Authors:
  28. * Jeff Hartmann <jhartmann@valinux.com>
  29. * Keith Whitwell <keith@tungstengraphics.com>
  30. *
  31. * Rewritten by:
  32. * Gareth Hughes <gareth@valinux.com>
  33. */
  34. #include "drmP.h"
  35. #include "drm.h"
  36. #include "mga_drm.h"
  37. #include "mga_drv.h"
  38. /* ================================================================
  39. * DMA hardware state programming functions
  40. */
  41. static void mga_emit_clip_rect( drm_mga_private_t *dev_priv,
  42. drm_clip_rect_t *box )
  43. {
  44. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  45. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  46. unsigned int pitch = dev_priv->front_pitch;
  47. DMA_LOCALS;
  48. BEGIN_DMA( 2 );
  49. /* Force reset of DWGCTL on G400 (eliminates clip disable bit).
  50. */
  51. if ( dev_priv->chipset == MGA_CARD_TYPE_G400 ) {
  52. DMA_BLOCK( MGA_DWGCTL, ctx->dwgctl,
  53. MGA_LEN + MGA_EXEC, 0x80000000,
  54. MGA_DWGCTL, ctx->dwgctl,
  55. MGA_LEN + MGA_EXEC, 0x80000000 );
  56. }
  57. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  58. MGA_CXBNDRY, (box->x2 << 16) | box->x1,
  59. MGA_YTOP, box->y1 * pitch,
  60. MGA_YBOT, box->y2 * pitch );
  61. ADVANCE_DMA();
  62. }
  63. static __inline__ void mga_g200_emit_context( drm_mga_private_t *dev_priv )
  64. {
  65. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  66. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  67. DMA_LOCALS;
  68. BEGIN_DMA( 3 );
  69. DMA_BLOCK( MGA_DSTORG, ctx->dstorg,
  70. MGA_MACCESS, ctx->maccess,
  71. MGA_PLNWT, ctx->plnwt,
  72. MGA_DWGCTL, ctx->dwgctl );
  73. DMA_BLOCK( MGA_ALPHACTRL, ctx->alphactrl,
  74. MGA_FOGCOL, ctx->fogcolor,
  75. MGA_WFLAG, ctx->wflag,
  76. MGA_ZORG, dev_priv->depth_offset );
  77. DMA_BLOCK( MGA_FCOL, ctx->fcol,
  78. MGA_DMAPAD, 0x00000000,
  79. MGA_DMAPAD, 0x00000000,
  80. MGA_DMAPAD, 0x00000000 );
  81. ADVANCE_DMA();
  82. }
  83. static __inline__ void mga_g400_emit_context( drm_mga_private_t *dev_priv )
  84. {
  85. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  86. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  87. DMA_LOCALS;
  88. BEGIN_DMA( 4 );
  89. DMA_BLOCK( MGA_DSTORG, ctx->dstorg,
  90. MGA_MACCESS, ctx->maccess,
  91. MGA_PLNWT, ctx->plnwt,
  92. MGA_DWGCTL, ctx->dwgctl );
  93. DMA_BLOCK( MGA_ALPHACTRL, ctx->alphactrl,
  94. MGA_FOGCOL, ctx->fogcolor,
  95. MGA_WFLAG, ctx->wflag,
  96. MGA_ZORG, dev_priv->depth_offset );
  97. DMA_BLOCK( MGA_WFLAG1, ctx->wflag,
  98. MGA_TDUALSTAGE0, ctx->tdualstage0,
  99. MGA_TDUALSTAGE1, ctx->tdualstage1,
  100. MGA_FCOL, ctx->fcol );
  101. DMA_BLOCK( MGA_STENCIL, ctx->stencil,
  102. MGA_STENCILCTL, ctx->stencilctl,
  103. MGA_DMAPAD, 0x00000000,
  104. MGA_DMAPAD, 0x00000000 );
  105. ADVANCE_DMA();
  106. }
  107. static __inline__ void mga_g200_emit_tex0( drm_mga_private_t *dev_priv )
  108. {
  109. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  110. drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
  111. DMA_LOCALS;
  112. BEGIN_DMA( 4 );
  113. DMA_BLOCK( MGA_TEXCTL2, tex->texctl2,
  114. MGA_TEXCTL, tex->texctl,
  115. MGA_TEXFILTER, tex->texfilter,
  116. MGA_TEXBORDERCOL, tex->texbordercol );
  117. DMA_BLOCK( MGA_TEXORG, tex->texorg,
  118. MGA_TEXORG1, tex->texorg1,
  119. MGA_TEXORG2, tex->texorg2,
  120. MGA_TEXORG3, tex->texorg3 );
  121. DMA_BLOCK( MGA_TEXORG4, tex->texorg4,
  122. MGA_TEXWIDTH, tex->texwidth,
  123. MGA_TEXHEIGHT, tex->texheight,
  124. MGA_WR24, tex->texwidth );
  125. DMA_BLOCK( MGA_WR34, tex->texheight,
  126. MGA_TEXTRANS, 0x0000ffff,
  127. MGA_TEXTRANSHIGH, 0x0000ffff,
  128. MGA_DMAPAD, 0x00000000 );
  129. ADVANCE_DMA();
  130. }
  131. static __inline__ void mga_g400_emit_tex0( drm_mga_private_t *dev_priv )
  132. {
  133. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  134. drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
  135. DMA_LOCALS;
  136. /* printk("mga_g400_emit_tex0 %x %x %x\n", tex->texorg, */
  137. /* tex->texctl, tex->texctl2); */
  138. BEGIN_DMA( 6 );
  139. DMA_BLOCK( MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC,
  140. MGA_TEXCTL, tex->texctl,
  141. MGA_TEXFILTER, tex->texfilter,
  142. MGA_TEXBORDERCOL, tex->texbordercol );
  143. DMA_BLOCK( MGA_TEXORG, tex->texorg,
  144. MGA_TEXORG1, tex->texorg1,
  145. MGA_TEXORG2, tex->texorg2,
  146. MGA_TEXORG3, tex->texorg3 );
  147. DMA_BLOCK( MGA_TEXORG4, tex->texorg4,
  148. MGA_TEXWIDTH, tex->texwidth,
  149. MGA_TEXHEIGHT, tex->texheight,
  150. MGA_WR49, 0x00000000 );
  151. DMA_BLOCK( MGA_WR57, 0x00000000,
  152. MGA_WR53, 0x00000000,
  153. MGA_WR61, 0x00000000,
  154. MGA_WR52, MGA_G400_WR_MAGIC );
  155. DMA_BLOCK( MGA_WR60, MGA_G400_WR_MAGIC,
  156. MGA_WR54, tex->texwidth | MGA_G400_WR_MAGIC,
  157. MGA_WR62, tex->texheight | MGA_G400_WR_MAGIC,
  158. MGA_DMAPAD, 0x00000000 );
  159. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  160. MGA_DMAPAD, 0x00000000,
  161. MGA_TEXTRANS, 0x0000ffff,
  162. MGA_TEXTRANSHIGH, 0x0000ffff );
  163. ADVANCE_DMA();
  164. }
  165. static __inline__ void mga_g400_emit_tex1( drm_mga_private_t *dev_priv )
  166. {
  167. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  168. drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[1];
  169. DMA_LOCALS;
  170. /* printk("mga_g400_emit_tex1 %x %x %x\n", tex->texorg, */
  171. /* tex->texctl, tex->texctl2); */
  172. BEGIN_DMA( 5 );
  173. DMA_BLOCK( MGA_TEXCTL2, (tex->texctl2 |
  174. MGA_MAP1_ENABLE |
  175. MGA_G400_TC2_MAGIC),
  176. MGA_TEXCTL, tex->texctl,
  177. MGA_TEXFILTER, tex->texfilter,
  178. MGA_TEXBORDERCOL, tex->texbordercol );
  179. DMA_BLOCK( MGA_TEXORG, tex->texorg,
  180. MGA_TEXORG1, tex->texorg1,
  181. MGA_TEXORG2, tex->texorg2,
  182. MGA_TEXORG3, tex->texorg3 );
  183. DMA_BLOCK( MGA_TEXORG4, tex->texorg4,
  184. MGA_TEXWIDTH, tex->texwidth,
  185. MGA_TEXHEIGHT, tex->texheight,
  186. MGA_WR49, 0x00000000 );
  187. DMA_BLOCK( MGA_WR57, 0x00000000,
  188. MGA_WR53, 0x00000000,
  189. MGA_WR61, 0x00000000,
  190. MGA_WR52, tex->texwidth | MGA_G400_WR_MAGIC );
  191. DMA_BLOCK( MGA_WR60, tex->texheight | MGA_G400_WR_MAGIC,
  192. MGA_TEXTRANS, 0x0000ffff,
  193. MGA_TEXTRANSHIGH, 0x0000ffff,
  194. MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC );
  195. ADVANCE_DMA();
  196. }
  197. static __inline__ void mga_g200_emit_pipe( drm_mga_private_t *dev_priv )
  198. {
  199. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  200. unsigned int pipe = sarea_priv->warp_pipe;
  201. DMA_LOCALS;
  202. BEGIN_DMA( 3 );
  203. DMA_BLOCK( MGA_WIADDR, MGA_WMODE_SUSPEND,
  204. MGA_WVRTXSZ, 0x00000007,
  205. MGA_WFLAG, 0x00000000,
  206. MGA_WR24, 0x00000000 );
  207. DMA_BLOCK( MGA_WR25, 0x00000100,
  208. MGA_WR34, 0x00000000,
  209. MGA_WR42, 0x0000ffff,
  210. MGA_WR60, 0x0000ffff );
  211. /* Padding required to to hardware bug.
  212. */
  213. DMA_BLOCK( MGA_DMAPAD, 0xffffffff,
  214. MGA_DMAPAD, 0xffffffff,
  215. MGA_DMAPAD, 0xffffffff,
  216. MGA_WIADDR, (dev_priv->warp_pipe_phys[pipe] |
  217. MGA_WMODE_START |
  218. MGA_WAGP_ENABLE) );
  219. ADVANCE_DMA();
  220. }
  221. static __inline__ void mga_g400_emit_pipe( drm_mga_private_t *dev_priv )
  222. {
  223. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  224. unsigned int pipe = sarea_priv->warp_pipe;
  225. DMA_LOCALS;
  226. /* printk("mga_g400_emit_pipe %x\n", pipe); */
  227. BEGIN_DMA( 10 );
  228. DMA_BLOCK( MGA_WIADDR2, MGA_WMODE_SUSPEND,
  229. MGA_DMAPAD, 0x00000000,
  230. MGA_DMAPAD, 0x00000000,
  231. MGA_DMAPAD, 0x00000000 );
  232. if ( pipe & MGA_T2 ) {
  233. DMA_BLOCK( MGA_WVRTXSZ, 0x00001e09,
  234. MGA_DMAPAD, 0x00000000,
  235. MGA_DMAPAD, 0x00000000,
  236. MGA_DMAPAD, 0x00000000 );
  237. DMA_BLOCK( MGA_WACCEPTSEQ, 0x00000000,
  238. MGA_WACCEPTSEQ, 0x00000000,
  239. MGA_WACCEPTSEQ, 0x00000000,
  240. MGA_WACCEPTSEQ, 0x1e000000 );
  241. } else {
  242. if ( dev_priv->warp_pipe & MGA_T2 ) {
  243. /* Flush the WARP pipe */
  244. DMA_BLOCK( MGA_YDST, 0x00000000,
  245. MGA_FXLEFT, 0x00000000,
  246. MGA_FXRIGHT, 0x00000001,
  247. MGA_DWGCTL, MGA_DWGCTL_FLUSH );
  248. DMA_BLOCK( MGA_LEN + MGA_EXEC, 0x00000001,
  249. MGA_DWGSYNC, 0x00007000,
  250. MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
  251. MGA_LEN + MGA_EXEC, 0x00000000 );
  252. DMA_BLOCK( MGA_TEXCTL2, (MGA_DUALTEX |
  253. MGA_G400_TC2_MAGIC),
  254. MGA_LEN + MGA_EXEC, 0x00000000,
  255. MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
  256. MGA_DMAPAD, 0x00000000 );
  257. }
  258. DMA_BLOCK( MGA_WVRTXSZ, 0x00001807,
  259. MGA_DMAPAD, 0x00000000,
  260. MGA_DMAPAD, 0x00000000,
  261. MGA_DMAPAD, 0x00000000 );
  262. DMA_BLOCK( MGA_WACCEPTSEQ, 0x00000000,
  263. MGA_WACCEPTSEQ, 0x00000000,
  264. MGA_WACCEPTSEQ, 0x00000000,
  265. MGA_WACCEPTSEQ, 0x18000000 );
  266. }
  267. DMA_BLOCK( MGA_WFLAG, 0x00000000,
  268. MGA_WFLAG1, 0x00000000,
  269. MGA_WR56, MGA_G400_WR56_MAGIC,
  270. MGA_DMAPAD, 0x00000000 );
  271. DMA_BLOCK( MGA_WR49, 0x00000000, /* tex0 */
  272. MGA_WR57, 0x00000000, /* tex0 */
  273. MGA_WR53, 0x00000000, /* tex1 */
  274. MGA_WR61, 0x00000000 ); /* tex1 */
  275. DMA_BLOCK( MGA_WR54, MGA_G400_WR_MAGIC, /* tex0 width */
  276. MGA_WR62, MGA_G400_WR_MAGIC, /* tex0 height */
  277. MGA_WR52, MGA_G400_WR_MAGIC, /* tex1 width */
  278. MGA_WR60, MGA_G400_WR_MAGIC ); /* tex1 height */
  279. /* Padding required to to hardware bug */
  280. DMA_BLOCK( MGA_DMAPAD, 0xffffffff,
  281. MGA_DMAPAD, 0xffffffff,
  282. MGA_DMAPAD, 0xffffffff,
  283. MGA_WIADDR2, (dev_priv->warp_pipe_phys[pipe] |
  284. MGA_WMODE_START |
  285. MGA_WAGP_ENABLE) );
  286. ADVANCE_DMA();
  287. }
  288. static void mga_g200_emit_state( drm_mga_private_t *dev_priv )
  289. {
  290. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  291. unsigned int dirty = sarea_priv->dirty;
  292. if ( sarea_priv->warp_pipe != dev_priv->warp_pipe ) {
  293. mga_g200_emit_pipe( dev_priv );
  294. dev_priv->warp_pipe = sarea_priv->warp_pipe;
  295. }
  296. if ( dirty & MGA_UPLOAD_CONTEXT ) {
  297. mga_g200_emit_context( dev_priv );
  298. sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
  299. }
  300. if ( dirty & MGA_UPLOAD_TEX0 ) {
  301. mga_g200_emit_tex0( dev_priv );
  302. sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
  303. }
  304. }
  305. static void mga_g400_emit_state( drm_mga_private_t *dev_priv )
  306. {
  307. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  308. unsigned int dirty = sarea_priv->dirty;
  309. int multitex = sarea_priv->warp_pipe & MGA_T2;
  310. if ( sarea_priv->warp_pipe != dev_priv->warp_pipe ) {
  311. mga_g400_emit_pipe( dev_priv );
  312. dev_priv->warp_pipe = sarea_priv->warp_pipe;
  313. }
  314. if ( dirty & MGA_UPLOAD_CONTEXT ) {
  315. mga_g400_emit_context( dev_priv );
  316. sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
  317. }
  318. if ( dirty & MGA_UPLOAD_TEX0 ) {
  319. mga_g400_emit_tex0( dev_priv );
  320. sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
  321. }
  322. if ( (dirty & MGA_UPLOAD_TEX1) && multitex ) {
  323. mga_g400_emit_tex1( dev_priv );
  324. sarea_priv->dirty &= ~MGA_UPLOAD_TEX1;
  325. }
  326. }
  327. /* ================================================================
  328. * SAREA state verification
  329. */
  330. /* Disallow all write destinations except the front and backbuffer.
  331. */
  332. static int mga_verify_context( drm_mga_private_t *dev_priv )
  333. {
  334. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  335. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  336. if ( ctx->dstorg != dev_priv->front_offset &&
  337. ctx->dstorg != dev_priv->back_offset ) {
  338. DRM_ERROR( "*** bad DSTORG: %x (front %x, back %x)\n\n",
  339. ctx->dstorg, dev_priv->front_offset,
  340. dev_priv->back_offset );
  341. ctx->dstorg = 0;
  342. return DRM_ERR(EINVAL);
  343. }
  344. return 0;
  345. }
  346. /* Disallow texture reads from PCI space.
  347. */
  348. static int mga_verify_tex( drm_mga_private_t *dev_priv, int unit )
  349. {
  350. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  351. drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[unit];
  352. unsigned int org;
  353. org = tex->texorg & (MGA_TEXORGMAP_MASK | MGA_TEXORGACC_MASK);
  354. if ( org == (MGA_TEXORGMAP_SYSMEM | MGA_TEXORGACC_PCI) ) {
  355. DRM_ERROR( "*** bad TEXORG: 0x%x, unit %d\n",
  356. tex->texorg, unit );
  357. tex->texorg = 0;
  358. return DRM_ERR(EINVAL);
  359. }
  360. return 0;
  361. }
  362. static int mga_verify_state( drm_mga_private_t *dev_priv )
  363. {
  364. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  365. unsigned int dirty = sarea_priv->dirty;
  366. int ret = 0;
  367. if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
  368. sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
  369. if ( dirty & MGA_UPLOAD_CONTEXT )
  370. ret |= mga_verify_context( dev_priv );
  371. if ( dirty & MGA_UPLOAD_TEX0 )
  372. ret |= mga_verify_tex( dev_priv, 0 );
  373. if ( dev_priv->chipset == MGA_CARD_TYPE_G400 ) {
  374. if ( dirty & MGA_UPLOAD_TEX1 )
  375. ret |= mga_verify_tex( dev_priv, 1 );
  376. if ( dirty & MGA_UPLOAD_PIPE )
  377. ret |= ( sarea_priv->warp_pipe > MGA_MAX_G400_PIPES );
  378. } else {
  379. if ( dirty & MGA_UPLOAD_PIPE )
  380. ret |= ( sarea_priv->warp_pipe > MGA_MAX_G200_PIPES );
  381. }
  382. return ( ret == 0 );
  383. }
  384. static int mga_verify_iload( drm_mga_private_t *dev_priv,
  385. unsigned int dstorg, unsigned int length )
  386. {
  387. if ( dstorg < dev_priv->texture_offset ||
  388. dstorg + length > (dev_priv->texture_offset +
  389. dev_priv->texture_size) ) {
  390. DRM_ERROR( "*** bad iload DSTORG: 0x%x\n", dstorg );
  391. return DRM_ERR(EINVAL);
  392. }
  393. if ( length & MGA_ILOAD_MASK ) {
  394. DRM_ERROR( "*** bad iload length: 0x%x\n",
  395. length & MGA_ILOAD_MASK );
  396. return DRM_ERR(EINVAL);
  397. }
  398. return 0;
  399. }
  400. static int mga_verify_blit( drm_mga_private_t *dev_priv,
  401. unsigned int srcorg, unsigned int dstorg )
  402. {
  403. if ( (srcorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM) ||
  404. (dstorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM) ) {
  405. DRM_ERROR( "*** bad blit: src=0x%x dst=0x%x\n",
  406. srcorg, dstorg );
  407. return DRM_ERR(EINVAL);
  408. }
  409. return 0;
  410. }
  411. /* ================================================================
  412. *
  413. */
  414. static void mga_dma_dispatch_clear( drm_device_t *dev,
  415. drm_mga_clear_t *clear )
  416. {
  417. drm_mga_private_t *dev_priv = dev->dev_private;
  418. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  419. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  420. drm_clip_rect_t *pbox = sarea_priv->boxes;
  421. int nbox = sarea_priv->nbox;
  422. int i;
  423. DMA_LOCALS;
  424. DRM_DEBUG( "\n" );
  425. BEGIN_DMA( 1 );
  426. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  427. MGA_DMAPAD, 0x00000000,
  428. MGA_DWGSYNC, 0x00007100,
  429. MGA_DWGSYNC, 0x00007000 );
  430. ADVANCE_DMA();
  431. for ( i = 0 ; i < nbox ; i++ ) {
  432. drm_clip_rect_t *box = &pbox[i];
  433. u32 height = box->y2 - box->y1;
  434. DRM_DEBUG( " from=%d,%d to=%d,%d\n",
  435. box->x1, box->y1, box->x2, box->y2 );
  436. if ( clear->flags & MGA_FRONT ) {
  437. BEGIN_DMA( 2 );
  438. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  439. MGA_PLNWT, clear->color_mask,
  440. MGA_YDSTLEN, (box->y1 << 16) | height,
  441. MGA_FXBNDRY, (box->x2 << 16) | box->x1 );
  442. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  443. MGA_FCOL, clear->clear_color,
  444. MGA_DSTORG, dev_priv->front_offset,
  445. MGA_DWGCTL + MGA_EXEC,
  446. dev_priv->clear_cmd );
  447. ADVANCE_DMA();
  448. }
  449. if ( clear->flags & MGA_BACK ) {
  450. BEGIN_DMA( 2 );
  451. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  452. MGA_PLNWT, clear->color_mask,
  453. MGA_YDSTLEN, (box->y1 << 16) | height,
  454. MGA_FXBNDRY, (box->x2 << 16) | box->x1 );
  455. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  456. MGA_FCOL, clear->clear_color,
  457. MGA_DSTORG, dev_priv->back_offset,
  458. MGA_DWGCTL + MGA_EXEC,
  459. dev_priv->clear_cmd );
  460. ADVANCE_DMA();
  461. }
  462. if ( clear->flags & MGA_DEPTH ) {
  463. BEGIN_DMA( 2 );
  464. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  465. MGA_PLNWT, clear->depth_mask,
  466. MGA_YDSTLEN, (box->y1 << 16) | height,
  467. MGA_FXBNDRY, (box->x2 << 16) | box->x1 );
  468. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  469. MGA_FCOL, clear->clear_depth,
  470. MGA_DSTORG, dev_priv->depth_offset,
  471. MGA_DWGCTL + MGA_EXEC,
  472. dev_priv->clear_cmd );
  473. ADVANCE_DMA();
  474. }
  475. }
  476. BEGIN_DMA( 1 );
  477. /* Force reset of DWGCTL */
  478. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  479. MGA_DMAPAD, 0x00000000,
  480. MGA_PLNWT, ctx->plnwt,
  481. MGA_DWGCTL, ctx->dwgctl );
  482. ADVANCE_DMA();
  483. FLUSH_DMA();
  484. }
  485. static void mga_dma_dispatch_swap( drm_device_t *dev )
  486. {
  487. drm_mga_private_t *dev_priv = dev->dev_private;
  488. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  489. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  490. drm_clip_rect_t *pbox = sarea_priv->boxes;
  491. int nbox = sarea_priv->nbox;
  492. int i;
  493. DMA_LOCALS;
  494. DRM_DEBUG( "\n" );
  495. sarea_priv->last_frame.head = dev_priv->prim.tail;
  496. sarea_priv->last_frame.wrap = dev_priv->prim.last_wrap;
  497. BEGIN_DMA( 4 + nbox );
  498. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  499. MGA_DMAPAD, 0x00000000,
  500. MGA_DWGSYNC, 0x00007100,
  501. MGA_DWGSYNC, 0x00007000 );
  502. DMA_BLOCK( MGA_DSTORG, dev_priv->front_offset,
  503. MGA_MACCESS, dev_priv->maccess,
  504. MGA_SRCORG, dev_priv->back_offset,
  505. MGA_AR5, dev_priv->front_pitch );
  506. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  507. MGA_DMAPAD, 0x00000000,
  508. MGA_PLNWT, 0xffffffff,
  509. MGA_DWGCTL, MGA_DWGCTL_COPY );
  510. for ( i = 0 ; i < nbox ; i++ ) {
  511. drm_clip_rect_t *box = &pbox[i];
  512. u32 height = box->y2 - box->y1;
  513. u32 start = box->y1 * dev_priv->front_pitch;
  514. DRM_DEBUG( " from=%d,%d to=%d,%d\n",
  515. box->x1, box->y1, box->x2, box->y2 );
  516. DMA_BLOCK( MGA_AR0, start + box->x2 - 1,
  517. MGA_AR3, start + box->x1,
  518. MGA_FXBNDRY, ((box->x2 - 1) << 16) | box->x1,
  519. MGA_YDSTLEN + MGA_EXEC,
  520. (box->y1 << 16) | height );
  521. }
  522. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  523. MGA_PLNWT, ctx->plnwt,
  524. MGA_SRCORG, dev_priv->front_offset,
  525. MGA_DWGCTL, ctx->dwgctl );
  526. ADVANCE_DMA();
  527. FLUSH_DMA();
  528. DRM_DEBUG( "%s... done.\n", __FUNCTION__ );
  529. }
  530. static void mga_dma_dispatch_vertex( drm_device_t *dev, drm_buf_t *buf )
  531. {
  532. drm_mga_private_t *dev_priv = dev->dev_private;
  533. drm_mga_buf_priv_t *buf_priv = buf->dev_private;
  534. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  535. u32 address = (u32) buf->bus_address;
  536. u32 length = (u32) buf->used;
  537. int i = 0;
  538. DMA_LOCALS;
  539. DRM_DEBUG( "vertex: buf=%d used=%d\n", buf->idx, buf->used );
  540. if ( buf->used ) {
  541. buf_priv->dispatched = 1;
  542. MGA_EMIT_STATE( dev_priv, sarea_priv->dirty );
  543. do {
  544. if ( i < sarea_priv->nbox ) {
  545. mga_emit_clip_rect( dev_priv,
  546. &sarea_priv->boxes[i] );
  547. }
  548. BEGIN_DMA( 1 );
  549. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  550. MGA_DMAPAD, 0x00000000,
  551. MGA_SECADDRESS, (address |
  552. MGA_DMA_VERTEX),
  553. MGA_SECEND, ((address + length) |
  554. MGA_PAGPXFER) );
  555. ADVANCE_DMA();
  556. } while ( ++i < sarea_priv->nbox );
  557. }
  558. if ( buf_priv->discard ) {
  559. AGE_BUFFER( buf_priv );
  560. buf->pending = 0;
  561. buf->used = 0;
  562. buf_priv->dispatched = 0;
  563. mga_freelist_put( dev, buf );
  564. }
  565. FLUSH_DMA();
  566. }
  567. static void mga_dma_dispatch_indices( drm_device_t *dev, drm_buf_t *buf,
  568. unsigned int start, unsigned int end )
  569. {
  570. drm_mga_private_t *dev_priv = dev->dev_private;
  571. drm_mga_buf_priv_t *buf_priv = buf->dev_private;
  572. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  573. u32 address = (u32) buf->bus_address;
  574. int i = 0;
  575. DMA_LOCALS;
  576. DRM_DEBUG( "indices: buf=%d start=%d end=%d\n", buf->idx, start, end );
  577. if ( start != end ) {
  578. buf_priv->dispatched = 1;
  579. MGA_EMIT_STATE( dev_priv, sarea_priv->dirty );
  580. do {
  581. if ( i < sarea_priv->nbox ) {
  582. mga_emit_clip_rect( dev_priv,
  583. &sarea_priv->boxes[i] );
  584. }
  585. BEGIN_DMA( 1 );
  586. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  587. MGA_DMAPAD, 0x00000000,
  588. MGA_SETUPADDRESS, address + start,
  589. MGA_SETUPEND, ((address + end) |
  590. MGA_PAGPXFER) );
  591. ADVANCE_DMA();
  592. } while ( ++i < sarea_priv->nbox );
  593. }
  594. if ( buf_priv->discard ) {
  595. AGE_BUFFER( buf_priv );
  596. buf->pending = 0;
  597. buf->used = 0;
  598. buf_priv->dispatched = 0;
  599. mga_freelist_put( dev, buf );
  600. }
  601. FLUSH_DMA();
  602. }
  603. /* This copies a 64 byte aligned agp region to the frambuffer with a
  604. * standard blit, the ioctl needs to do checking.
  605. */
  606. static void mga_dma_dispatch_iload( drm_device_t *dev, drm_buf_t *buf,
  607. unsigned int dstorg, unsigned int length )
  608. {
  609. drm_mga_private_t *dev_priv = dev->dev_private;
  610. drm_mga_buf_priv_t *buf_priv = buf->dev_private;
  611. drm_mga_context_regs_t *ctx = &dev_priv->sarea_priv->context_state;
  612. u32 srcorg = buf->bus_address | MGA_SRCACC_AGP | MGA_SRCMAP_SYSMEM;
  613. u32 y2;
  614. DMA_LOCALS;
  615. DRM_DEBUG( "buf=%d used=%d\n", buf->idx, buf->used );
  616. y2 = length / 64;
  617. BEGIN_DMA( 5 );
  618. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  619. MGA_DMAPAD, 0x00000000,
  620. MGA_DWGSYNC, 0x00007100,
  621. MGA_DWGSYNC, 0x00007000 );
  622. DMA_BLOCK( MGA_DSTORG, dstorg,
  623. MGA_MACCESS, 0x00000000,
  624. MGA_SRCORG, srcorg,
  625. MGA_AR5, 64 );
  626. DMA_BLOCK( MGA_PITCH, 64,
  627. MGA_PLNWT, 0xffffffff,
  628. MGA_DMAPAD, 0x00000000,
  629. MGA_DWGCTL, MGA_DWGCTL_COPY );
  630. DMA_BLOCK( MGA_AR0, 63,
  631. MGA_AR3, 0,
  632. MGA_FXBNDRY, (63 << 16) | 0,
  633. MGA_YDSTLEN + MGA_EXEC, y2 );
  634. DMA_BLOCK( MGA_PLNWT, ctx->plnwt,
  635. MGA_SRCORG, dev_priv->front_offset,
  636. MGA_PITCH, dev_priv->front_pitch,
  637. MGA_DWGSYNC, 0x00007000 );
  638. ADVANCE_DMA();
  639. AGE_BUFFER( buf_priv );
  640. buf->pending = 0;
  641. buf->used = 0;
  642. buf_priv->dispatched = 0;
  643. mga_freelist_put( dev, buf );
  644. FLUSH_DMA();
  645. }
  646. static void mga_dma_dispatch_blit( drm_device_t *dev,
  647. drm_mga_blit_t *blit )
  648. {
  649. drm_mga_private_t *dev_priv = dev->dev_private;
  650. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  651. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  652. drm_clip_rect_t *pbox = sarea_priv->boxes;
  653. int nbox = sarea_priv->nbox;
  654. u32 scandir = 0, i;
  655. DMA_LOCALS;
  656. DRM_DEBUG( "\n" );
  657. BEGIN_DMA( 4 + nbox );
  658. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  659. MGA_DMAPAD, 0x00000000,
  660. MGA_DWGSYNC, 0x00007100,
  661. MGA_DWGSYNC, 0x00007000 );
  662. DMA_BLOCK( MGA_DWGCTL, MGA_DWGCTL_COPY,
  663. MGA_PLNWT, blit->planemask,
  664. MGA_SRCORG, blit->srcorg,
  665. MGA_DSTORG, blit->dstorg );
  666. DMA_BLOCK( MGA_SGN, scandir,
  667. MGA_MACCESS, dev_priv->maccess,
  668. MGA_AR5, blit->ydir * blit->src_pitch,
  669. MGA_PITCH, blit->dst_pitch );
  670. for ( i = 0 ; i < nbox ; i++ ) {
  671. int srcx = pbox[i].x1 + blit->delta_sx;
  672. int srcy = pbox[i].y1 + blit->delta_sy;
  673. int dstx = pbox[i].x1 + blit->delta_dx;
  674. int dsty = pbox[i].y1 + blit->delta_dy;
  675. int h = pbox[i].y2 - pbox[i].y1;
  676. int w = pbox[i].x2 - pbox[i].x1 - 1;
  677. int start;
  678. if ( blit->ydir == -1 ) {
  679. srcy = blit->height - srcy - 1;
  680. }
  681. start = srcy * blit->src_pitch + srcx;
  682. DMA_BLOCK( MGA_AR0, start + w,
  683. MGA_AR3, start,
  684. MGA_FXBNDRY, ((dstx + w) << 16) | (dstx & 0xffff),
  685. MGA_YDSTLEN + MGA_EXEC, (dsty << 16) | h );
  686. }
  687. /* Do something to flush AGP?
  688. */
  689. /* Force reset of DWGCTL */
  690. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  691. MGA_PLNWT, ctx->plnwt,
  692. MGA_PITCH, dev_priv->front_pitch,
  693. MGA_DWGCTL, ctx->dwgctl );
  694. ADVANCE_DMA();
  695. }
  696. /* ================================================================
  697. *
  698. */
  699. static int mga_dma_clear( DRM_IOCTL_ARGS )
  700. {
  701. DRM_DEVICE;
  702. drm_mga_private_t *dev_priv = dev->dev_private;
  703. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  704. drm_mga_clear_t clear;
  705. LOCK_TEST_WITH_RETURN( dev, filp );
  706. DRM_COPY_FROM_USER_IOCTL( clear, (drm_mga_clear_t __user *)data, sizeof(clear) );
  707. if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
  708. sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
  709. WRAP_TEST_WITH_RETURN( dev_priv );
  710. mga_dma_dispatch_clear( dev, &clear );
  711. /* Make sure we restore the 3D state next time.
  712. */
  713. dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
  714. return 0;
  715. }
  716. static int mga_dma_swap( DRM_IOCTL_ARGS )
  717. {
  718. DRM_DEVICE;
  719. drm_mga_private_t *dev_priv = dev->dev_private;
  720. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  721. LOCK_TEST_WITH_RETURN( dev, filp );
  722. if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
  723. sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
  724. WRAP_TEST_WITH_RETURN( dev_priv );
  725. mga_dma_dispatch_swap( dev );
  726. /* Make sure we restore the 3D state next time.
  727. */
  728. dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
  729. return 0;
  730. }
  731. static int mga_dma_vertex( DRM_IOCTL_ARGS )
  732. {
  733. DRM_DEVICE;
  734. drm_mga_private_t *dev_priv = dev->dev_private;
  735. drm_device_dma_t *dma = dev->dma;
  736. drm_buf_t *buf;
  737. drm_mga_buf_priv_t *buf_priv;
  738. drm_mga_vertex_t vertex;
  739. LOCK_TEST_WITH_RETURN( dev, filp );
  740. DRM_COPY_FROM_USER_IOCTL( vertex,
  741. (drm_mga_vertex_t __user *)data,
  742. sizeof(vertex) );
  743. if(vertex.idx < 0 || vertex.idx > dma->buf_count) return DRM_ERR(EINVAL);
  744. buf = dma->buflist[vertex.idx];
  745. buf_priv = buf->dev_private;
  746. buf->used = vertex.used;
  747. buf_priv->discard = vertex.discard;
  748. if ( !mga_verify_state( dev_priv ) ) {
  749. if ( vertex.discard ) {
  750. if ( buf_priv->dispatched == 1 )
  751. AGE_BUFFER( buf_priv );
  752. buf_priv->dispatched = 0;
  753. mga_freelist_put( dev, buf );
  754. }
  755. return DRM_ERR(EINVAL);
  756. }
  757. WRAP_TEST_WITH_RETURN( dev_priv );
  758. mga_dma_dispatch_vertex( dev, buf );
  759. return 0;
  760. }
  761. static int mga_dma_indices( DRM_IOCTL_ARGS )
  762. {
  763. DRM_DEVICE;
  764. drm_mga_private_t *dev_priv = dev->dev_private;
  765. drm_device_dma_t *dma = dev->dma;
  766. drm_buf_t *buf;
  767. drm_mga_buf_priv_t *buf_priv;
  768. drm_mga_indices_t indices;
  769. LOCK_TEST_WITH_RETURN( dev, filp );
  770. DRM_COPY_FROM_USER_IOCTL( indices,
  771. (drm_mga_indices_t __user *)data,
  772. sizeof(indices) );
  773. if(indices.idx < 0 || indices.idx > dma->buf_count) return DRM_ERR(EINVAL);
  774. buf = dma->buflist[indices.idx];
  775. buf_priv = buf->dev_private;
  776. buf_priv->discard = indices.discard;
  777. if ( !mga_verify_state( dev_priv ) ) {
  778. if ( indices.discard ) {
  779. if ( buf_priv->dispatched == 1 )
  780. AGE_BUFFER( buf_priv );
  781. buf_priv->dispatched = 0;
  782. mga_freelist_put( dev, buf );
  783. }
  784. return DRM_ERR(EINVAL);
  785. }
  786. WRAP_TEST_WITH_RETURN( dev_priv );
  787. mga_dma_dispatch_indices( dev, buf, indices.start, indices.end );
  788. return 0;
  789. }
  790. static int mga_dma_iload( DRM_IOCTL_ARGS )
  791. {
  792. DRM_DEVICE;
  793. drm_device_dma_t *dma = dev->dma;
  794. drm_mga_private_t *dev_priv = dev->dev_private;
  795. drm_buf_t *buf;
  796. drm_mga_buf_priv_t *buf_priv;
  797. drm_mga_iload_t iload;
  798. DRM_DEBUG( "\n" );
  799. LOCK_TEST_WITH_RETURN( dev, filp );
  800. DRM_COPY_FROM_USER_IOCTL( iload, (drm_mga_iload_t __user *)data, sizeof(iload) );
  801. #if 0
  802. if ( mga_do_wait_for_idle( dev_priv ) < 0 ) {
  803. if ( MGA_DMA_DEBUG )
  804. DRM_INFO( "%s: -EBUSY\n", __FUNCTION__ );
  805. return DRM_ERR(EBUSY);
  806. }
  807. #endif
  808. if(iload.idx < 0 || iload.idx > dma->buf_count) return DRM_ERR(EINVAL);
  809. buf = dma->buflist[iload.idx];
  810. buf_priv = buf->dev_private;
  811. if ( mga_verify_iload( dev_priv, iload.dstorg, iload.length ) ) {
  812. mga_freelist_put( dev, buf );
  813. return DRM_ERR(EINVAL);
  814. }
  815. WRAP_TEST_WITH_RETURN( dev_priv );
  816. mga_dma_dispatch_iload( dev, buf, iload.dstorg, iload.length );
  817. /* Make sure we restore the 3D state next time.
  818. */
  819. dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
  820. return 0;
  821. }
  822. static int mga_dma_blit( DRM_IOCTL_ARGS )
  823. {
  824. DRM_DEVICE;
  825. drm_mga_private_t *dev_priv = dev->dev_private;
  826. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  827. drm_mga_blit_t blit;
  828. DRM_DEBUG( "\n" );
  829. LOCK_TEST_WITH_RETURN( dev, filp );
  830. DRM_COPY_FROM_USER_IOCTL( blit, (drm_mga_blit_t __user *)data, sizeof(blit) );
  831. if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
  832. sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
  833. if ( mga_verify_blit( dev_priv, blit.srcorg, blit.dstorg ) )
  834. return DRM_ERR(EINVAL);
  835. WRAP_TEST_WITH_RETURN( dev_priv );
  836. mga_dma_dispatch_blit( dev, &blit );
  837. /* Make sure we restore the 3D state next time.
  838. */
  839. dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
  840. return 0;
  841. }
  842. static int mga_getparam( DRM_IOCTL_ARGS )
  843. {
  844. DRM_DEVICE;
  845. drm_mga_private_t *dev_priv = dev->dev_private;
  846. drm_mga_getparam_t param;
  847. int value;
  848. if ( !dev_priv ) {
  849. DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
  850. return DRM_ERR(EINVAL);
  851. }
  852. DRM_COPY_FROM_USER_IOCTL( param, (drm_mga_getparam_t __user *)data,
  853. sizeof(param) );
  854. DRM_DEBUG( "pid=%d\n", DRM_CURRENTPID );
  855. switch( param.param ) {
  856. case MGA_PARAM_IRQ_NR:
  857. value = dev->irq;
  858. break;
  859. default:
  860. return DRM_ERR(EINVAL);
  861. }
  862. if ( DRM_COPY_TO_USER( param.value, &value, sizeof(int) ) ) {
  863. DRM_ERROR( "copy_to_user\n" );
  864. return DRM_ERR(EFAULT);
  865. }
  866. return 0;
  867. }
  868. drm_ioctl_desc_t mga_ioctls[] = {
  869. [DRM_IOCTL_NR(DRM_MGA_INIT)] = { mga_dma_init, 1, 1 },
  870. [DRM_IOCTL_NR(DRM_MGA_FLUSH)] = { mga_dma_flush, 1, 0 },
  871. [DRM_IOCTL_NR(DRM_MGA_RESET)] = { mga_dma_reset, 1, 0 },
  872. [DRM_IOCTL_NR(DRM_MGA_SWAP)] = { mga_dma_swap, 1, 0 },
  873. [DRM_IOCTL_NR(DRM_MGA_CLEAR)] = { mga_dma_clear, 1, 0 },
  874. [DRM_IOCTL_NR(DRM_MGA_VERTEX)] = { mga_dma_vertex, 1, 0 },
  875. [DRM_IOCTL_NR(DRM_MGA_INDICES)] = { mga_dma_indices, 1, 0 },
  876. [DRM_IOCTL_NR(DRM_MGA_ILOAD)] = { mga_dma_iload, 1, 0 },
  877. [DRM_IOCTL_NR(DRM_MGA_BLIT)] = { mga_dma_blit, 1, 0 },
  878. [DRM_IOCTL_NR(DRM_MGA_GETPARAM)]= { mga_getparam, 1, 0 },
  879. };
  880. int mga_max_ioctl = DRM_ARRAY_SIZE(mga_ioctls);