mga_state.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  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 - 1) << 16) | box->x1,
  59. MGA_YTOP, box->y1 * pitch,
  60. MGA_YBOT, (box->y2 - 1) * 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 | dev_priv->wagp_enable));
  218. ADVANCE_DMA();
  219. }
  220. static __inline__ void mga_g400_emit_pipe( drm_mga_private_t *dev_priv )
  221. {
  222. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  223. unsigned int pipe = sarea_priv->warp_pipe;
  224. DMA_LOCALS;
  225. /* printk("mga_g400_emit_pipe %x\n", pipe); */
  226. BEGIN_DMA( 10 );
  227. DMA_BLOCK( MGA_WIADDR2, MGA_WMODE_SUSPEND,
  228. MGA_DMAPAD, 0x00000000,
  229. MGA_DMAPAD, 0x00000000,
  230. MGA_DMAPAD, 0x00000000 );
  231. if ( pipe & MGA_T2 ) {
  232. DMA_BLOCK( MGA_WVRTXSZ, 0x00001e09,
  233. MGA_DMAPAD, 0x00000000,
  234. MGA_DMAPAD, 0x00000000,
  235. MGA_DMAPAD, 0x00000000 );
  236. DMA_BLOCK( MGA_WACCEPTSEQ, 0x00000000,
  237. MGA_WACCEPTSEQ, 0x00000000,
  238. MGA_WACCEPTSEQ, 0x00000000,
  239. MGA_WACCEPTSEQ, 0x1e000000 );
  240. } else {
  241. if ( dev_priv->warp_pipe & MGA_T2 ) {
  242. /* Flush the WARP pipe */
  243. DMA_BLOCK( MGA_YDST, 0x00000000,
  244. MGA_FXLEFT, 0x00000000,
  245. MGA_FXRIGHT, 0x00000001,
  246. MGA_DWGCTL, MGA_DWGCTL_FLUSH );
  247. DMA_BLOCK( MGA_LEN + MGA_EXEC, 0x00000001,
  248. MGA_DWGSYNC, 0x00007000,
  249. MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
  250. MGA_LEN + MGA_EXEC, 0x00000000 );
  251. DMA_BLOCK( MGA_TEXCTL2, (MGA_DUALTEX |
  252. MGA_G400_TC2_MAGIC),
  253. MGA_LEN + MGA_EXEC, 0x00000000,
  254. MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
  255. MGA_DMAPAD, 0x00000000 );
  256. }
  257. DMA_BLOCK( MGA_WVRTXSZ, 0x00001807,
  258. MGA_DMAPAD, 0x00000000,
  259. MGA_DMAPAD, 0x00000000,
  260. MGA_DMAPAD, 0x00000000 );
  261. DMA_BLOCK( MGA_WACCEPTSEQ, 0x00000000,
  262. MGA_WACCEPTSEQ, 0x00000000,
  263. MGA_WACCEPTSEQ, 0x00000000,
  264. MGA_WACCEPTSEQ, 0x18000000 );
  265. }
  266. DMA_BLOCK( MGA_WFLAG, 0x00000000,
  267. MGA_WFLAG1, 0x00000000,
  268. MGA_WR56, MGA_G400_WR56_MAGIC,
  269. MGA_DMAPAD, 0x00000000 );
  270. DMA_BLOCK( MGA_WR49, 0x00000000, /* tex0 */
  271. MGA_WR57, 0x00000000, /* tex0 */
  272. MGA_WR53, 0x00000000, /* tex1 */
  273. MGA_WR61, 0x00000000 ); /* tex1 */
  274. DMA_BLOCK( MGA_WR54, MGA_G400_WR_MAGIC, /* tex0 width */
  275. MGA_WR62, MGA_G400_WR_MAGIC, /* tex0 height */
  276. MGA_WR52, MGA_G400_WR_MAGIC, /* tex1 width */
  277. MGA_WR60, MGA_G400_WR_MAGIC ); /* tex1 height */
  278. /* Padding required to to hardware bug */
  279. DMA_BLOCK(MGA_DMAPAD, 0xffffffff,
  280. MGA_DMAPAD, 0xffffffff,
  281. MGA_DMAPAD, 0xffffffff,
  282. MGA_WIADDR2, (dev_priv->warp_pipe_phys[pipe] |
  283. MGA_WMODE_START | dev_priv->wagp_enable));
  284. ADVANCE_DMA();
  285. }
  286. static void mga_g200_emit_state( drm_mga_private_t *dev_priv )
  287. {
  288. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  289. unsigned int dirty = sarea_priv->dirty;
  290. if ( sarea_priv->warp_pipe != dev_priv->warp_pipe ) {
  291. mga_g200_emit_pipe( dev_priv );
  292. dev_priv->warp_pipe = sarea_priv->warp_pipe;
  293. }
  294. if ( dirty & MGA_UPLOAD_CONTEXT ) {
  295. mga_g200_emit_context( dev_priv );
  296. sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
  297. }
  298. if ( dirty & MGA_UPLOAD_TEX0 ) {
  299. mga_g200_emit_tex0( dev_priv );
  300. sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
  301. }
  302. }
  303. static void mga_g400_emit_state( drm_mga_private_t *dev_priv )
  304. {
  305. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  306. unsigned int dirty = sarea_priv->dirty;
  307. int multitex = sarea_priv->warp_pipe & MGA_T2;
  308. if ( sarea_priv->warp_pipe != dev_priv->warp_pipe ) {
  309. mga_g400_emit_pipe( dev_priv );
  310. dev_priv->warp_pipe = sarea_priv->warp_pipe;
  311. }
  312. if ( dirty & MGA_UPLOAD_CONTEXT ) {
  313. mga_g400_emit_context( dev_priv );
  314. sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
  315. }
  316. if ( dirty & MGA_UPLOAD_TEX0 ) {
  317. mga_g400_emit_tex0( dev_priv );
  318. sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
  319. }
  320. if ( (dirty & MGA_UPLOAD_TEX1) && multitex ) {
  321. mga_g400_emit_tex1( dev_priv );
  322. sarea_priv->dirty &= ~MGA_UPLOAD_TEX1;
  323. }
  324. }
  325. /* ================================================================
  326. * SAREA state verification
  327. */
  328. /* Disallow all write destinations except the front and backbuffer.
  329. */
  330. static int mga_verify_context( drm_mga_private_t *dev_priv )
  331. {
  332. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  333. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  334. if ( ctx->dstorg != dev_priv->front_offset &&
  335. ctx->dstorg != dev_priv->back_offset ) {
  336. DRM_ERROR( "*** bad DSTORG: %x (front %x, back %x)\n\n",
  337. ctx->dstorg, dev_priv->front_offset,
  338. dev_priv->back_offset );
  339. ctx->dstorg = 0;
  340. return DRM_ERR(EINVAL);
  341. }
  342. return 0;
  343. }
  344. /* Disallow texture reads from PCI space.
  345. */
  346. static int mga_verify_tex( drm_mga_private_t *dev_priv, int unit )
  347. {
  348. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  349. drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[unit];
  350. unsigned int org;
  351. org = tex->texorg & (MGA_TEXORGMAP_MASK | MGA_TEXORGACC_MASK);
  352. if ( org == (MGA_TEXORGMAP_SYSMEM | MGA_TEXORGACC_PCI) ) {
  353. DRM_ERROR( "*** bad TEXORG: 0x%x, unit %d\n",
  354. tex->texorg, unit );
  355. tex->texorg = 0;
  356. return DRM_ERR(EINVAL);
  357. }
  358. return 0;
  359. }
  360. static int mga_verify_state( drm_mga_private_t *dev_priv )
  361. {
  362. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  363. unsigned int dirty = sarea_priv->dirty;
  364. int ret = 0;
  365. if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
  366. sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
  367. if ( dirty & MGA_UPLOAD_CONTEXT )
  368. ret |= mga_verify_context( dev_priv );
  369. if ( dirty & MGA_UPLOAD_TEX0 )
  370. ret |= mga_verify_tex( dev_priv, 0 );
  371. if (dev_priv->chipset >= MGA_CARD_TYPE_G400) {
  372. if (dirty & MGA_UPLOAD_TEX1)
  373. ret |= mga_verify_tex(dev_priv, 1);
  374. if ( dirty & MGA_UPLOAD_PIPE )
  375. ret |= ( sarea_priv->warp_pipe > MGA_MAX_G400_PIPES );
  376. } else {
  377. if ( dirty & MGA_UPLOAD_PIPE )
  378. ret |= ( sarea_priv->warp_pipe > MGA_MAX_G200_PIPES );
  379. }
  380. return ( ret == 0 );
  381. }
  382. static int mga_verify_iload( drm_mga_private_t *dev_priv,
  383. unsigned int dstorg, unsigned int length )
  384. {
  385. if ( dstorg < dev_priv->texture_offset ||
  386. dstorg + length > (dev_priv->texture_offset +
  387. dev_priv->texture_size) ) {
  388. DRM_ERROR( "*** bad iload DSTORG: 0x%x\n", dstorg );
  389. return DRM_ERR(EINVAL);
  390. }
  391. if ( length & MGA_ILOAD_MASK ) {
  392. DRM_ERROR( "*** bad iload length: 0x%x\n",
  393. length & MGA_ILOAD_MASK );
  394. return DRM_ERR(EINVAL);
  395. }
  396. return 0;
  397. }
  398. static int mga_verify_blit( drm_mga_private_t *dev_priv,
  399. unsigned int srcorg, unsigned int dstorg )
  400. {
  401. if ( (srcorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM) ||
  402. (dstorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM) ) {
  403. DRM_ERROR( "*** bad blit: src=0x%x dst=0x%x\n",
  404. srcorg, dstorg );
  405. return DRM_ERR(EINVAL);
  406. }
  407. return 0;
  408. }
  409. /* ================================================================
  410. *
  411. */
  412. static void mga_dma_dispatch_clear( drm_device_t *dev,
  413. drm_mga_clear_t *clear )
  414. {
  415. drm_mga_private_t *dev_priv = dev->dev_private;
  416. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  417. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  418. drm_clip_rect_t *pbox = sarea_priv->boxes;
  419. int nbox = sarea_priv->nbox;
  420. int i;
  421. DMA_LOCALS;
  422. DRM_DEBUG( "\n" );
  423. BEGIN_DMA( 1 );
  424. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  425. MGA_DMAPAD, 0x00000000,
  426. MGA_DWGSYNC, 0x00007100,
  427. MGA_DWGSYNC, 0x00007000 );
  428. ADVANCE_DMA();
  429. for ( i = 0 ; i < nbox ; i++ ) {
  430. drm_clip_rect_t *box = &pbox[i];
  431. u32 height = box->y2 - box->y1;
  432. DRM_DEBUG( " from=%d,%d to=%d,%d\n",
  433. box->x1, box->y1, box->x2, box->y2 );
  434. if ( clear->flags & MGA_FRONT ) {
  435. BEGIN_DMA( 2 );
  436. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  437. MGA_PLNWT, clear->color_mask,
  438. MGA_YDSTLEN, (box->y1 << 16) | height,
  439. MGA_FXBNDRY, (box->x2 << 16) | box->x1 );
  440. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  441. MGA_FCOL, clear->clear_color,
  442. MGA_DSTORG, dev_priv->front_offset,
  443. MGA_DWGCTL + MGA_EXEC,
  444. dev_priv->clear_cmd );
  445. ADVANCE_DMA();
  446. }
  447. if ( clear->flags & MGA_BACK ) {
  448. BEGIN_DMA( 2 );
  449. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  450. MGA_PLNWT, clear->color_mask,
  451. MGA_YDSTLEN, (box->y1 << 16) | height,
  452. MGA_FXBNDRY, (box->x2 << 16) | box->x1 );
  453. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  454. MGA_FCOL, clear->clear_color,
  455. MGA_DSTORG, dev_priv->back_offset,
  456. MGA_DWGCTL + MGA_EXEC,
  457. dev_priv->clear_cmd );
  458. ADVANCE_DMA();
  459. }
  460. if ( clear->flags & MGA_DEPTH ) {
  461. BEGIN_DMA( 2 );
  462. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  463. MGA_PLNWT, clear->depth_mask,
  464. MGA_YDSTLEN, (box->y1 << 16) | height,
  465. MGA_FXBNDRY, (box->x2 << 16) | box->x1 );
  466. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  467. MGA_FCOL, clear->clear_depth,
  468. MGA_DSTORG, dev_priv->depth_offset,
  469. MGA_DWGCTL + MGA_EXEC,
  470. dev_priv->clear_cmd );
  471. ADVANCE_DMA();
  472. }
  473. }
  474. BEGIN_DMA( 1 );
  475. /* Force reset of DWGCTL */
  476. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  477. MGA_DMAPAD, 0x00000000,
  478. MGA_PLNWT, ctx->plnwt,
  479. MGA_DWGCTL, ctx->dwgctl );
  480. ADVANCE_DMA();
  481. FLUSH_DMA();
  482. }
  483. static void mga_dma_dispatch_swap( drm_device_t *dev )
  484. {
  485. drm_mga_private_t *dev_priv = dev->dev_private;
  486. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  487. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  488. drm_clip_rect_t *pbox = sarea_priv->boxes;
  489. int nbox = sarea_priv->nbox;
  490. int i;
  491. DMA_LOCALS;
  492. DRM_DEBUG( "\n" );
  493. sarea_priv->last_frame.head = dev_priv->prim.tail;
  494. sarea_priv->last_frame.wrap = dev_priv->prim.last_wrap;
  495. BEGIN_DMA( 4 + nbox );
  496. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  497. MGA_DMAPAD, 0x00000000,
  498. MGA_DWGSYNC, 0x00007100,
  499. MGA_DWGSYNC, 0x00007000 );
  500. DMA_BLOCK( MGA_DSTORG, dev_priv->front_offset,
  501. MGA_MACCESS, dev_priv->maccess,
  502. MGA_SRCORG, dev_priv->back_offset,
  503. MGA_AR5, dev_priv->front_pitch );
  504. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  505. MGA_DMAPAD, 0x00000000,
  506. MGA_PLNWT, 0xffffffff,
  507. MGA_DWGCTL, MGA_DWGCTL_COPY );
  508. for ( i = 0 ; i < nbox ; i++ ) {
  509. drm_clip_rect_t *box = &pbox[i];
  510. u32 height = box->y2 - box->y1;
  511. u32 start = box->y1 * dev_priv->front_pitch;
  512. DRM_DEBUG( " from=%d,%d to=%d,%d\n",
  513. box->x1, box->y1, box->x2, box->y2 );
  514. DMA_BLOCK( MGA_AR0, start + box->x2 - 1,
  515. MGA_AR3, start + box->x1,
  516. MGA_FXBNDRY, ((box->x2 - 1) << 16) | box->x1,
  517. MGA_YDSTLEN + MGA_EXEC,
  518. (box->y1 << 16) | height );
  519. }
  520. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  521. MGA_PLNWT, ctx->plnwt,
  522. MGA_SRCORG, dev_priv->front_offset,
  523. MGA_DWGCTL, ctx->dwgctl );
  524. ADVANCE_DMA();
  525. FLUSH_DMA();
  526. DRM_DEBUG( "%s... done.\n", __FUNCTION__ );
  527. }
  528. static void mga_dma_dispatch_vertex( drm_device_t *dev, drm_buf_t *buf )
  529. {
  530. drm_mga_private_t *dev_priv = dev->dev_private;
  531. drm_mga_buf_priv_t *buf_priv = buf->dev_private;
  532. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  533. u32 address = (u32) buf->bus_address;
  534. u32 length = (u32) buf->used;
  535. int i = 0;
  536. DMA_LOCALS;
  537. DRM_DEBUG( "vertex: buf=%d used=%d\n", buf->idx, buf->used );
  538. if ( buf->used ) {
  539. buf_priv->dispatched = 1;
  540. MGA_EMIT_STATE( dev_priv, sarea_priv->dirty );
  541. do {
  542. if ( i < sarea_priv->nbox ) {
  543. mga_emit_clip_rect( dev_priv,
  544. &sarea_priv->boxes[i] );
  545. }
  546. BEGIN_DMA( 1 );
  547. DMA_BLOCK(MGA_DMAPAD, 0x00000000,
  548. MGA_DMAPAD, 0x00000000,
  549. MGA_SECADDRESS, (address |
  550. MGA_DMA_VERTEX),
  551. MGA_SECEND, ((address + length) |
  552. dev_priv->dma_access));
  553. ADVANCE_DMA();
  554. } while ( ++i < sarea_priv->nbox );
  555. }
  556. if ( buf_priv->discard ) {
  557. AGE_BUFFER( buf_priv );
  558. buf->pending = 0;
  559. buf->used = 0;
  560. buf_priv->dispatched = 0;
  561. mga_freelist_put( dev, buf );
  562. }
  563. FLUSH_DMA();
  564. }
  565. static void mga_dma_dispatch_indices( drm_device_t *dev, drm_buf_t *buf,
  566. unsigned int start, unsigned int end )
  567. {
  568. drm_mga_private_t *dev_priv = dev->dev_private;
  569. drm_mga_buf_priv_t *buf_priv = buf->dev_private;
  570. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  571. u32 address = (u32) buf->bus_address;
  572. int i = 0;
  573. DMA_LOCALS;
  574. DRM_DEBUG( "indices: buf=%d start=%d end=%d\n", buf->idx, start, end );
  575. if ( start != end ) {
  576. buf_priv->dispatched = 1;
  577. MGA_EMIT_STATE( dev_priv, sarea_priv->dirty );
  578. do {
  579. if ( i < sarea_priv->nbox ) {
  580. mga_emit_clip_rect( dev_priv,
  581. &sarea_priv->boxes[i] );
  582. }
  583. BEGIN_DMA( 1 );
  584. DMA_BLOCK(MGA_DMAPAD, 0x00000000,
  585. MGA_DMAPAD, 0x00000000,
  586. MGA_SETUPADDRESS, address + start,
  587. MGA_SETUPEND, ((address + end) |
  588. dev_priv->dma_access));
  589. ADVANCE_DMA();
  590. } while ( ++i < sarea_priv->nbox );
  591. }
  592. if ( buf_priv->discard ) {
  593. AGE_BUFFER( buf_priv );
  594. buf->pending = 0;
  595. buf->used = 0;
  596. buf_priv->dispatched = 0;
  597. mga_freelist_put( dev, buf );
  598. }
  599. FLUSH_DMA();
  600. }
  601. /* This copies a 64 byte aligned agp region to the frambuffer with a
  602. * standard blit, the ioctl needs to do checking.
  603. */
  604. static void mga_dma_dispatch_iload( drm_device_t *dev, drm_buf_t *buf,
  605. unsigned int dstorg, unsigned int length )
  606. {
  607. drm_mga_private_t *dev_priv = dev->dev_private;
  608. drm_mga_buf_priv_t *buf_priv = buf->dev_private;
  609. drm_mga_context_regs_t *ctx = &dev_priv->sarea_priv->context_state;
  610. u32 srcorg = buf->bus_address | dev_priv->dma_access | MGA_SRCMAP_SYSMEM;
  611. u32 y2;
  612. DMA_LOCALS;
  613. DRM_DEBUG( "buf=%d used=%d\n", buf->idx, buf->used );
  614. y2 = length / 64;
  615. BEGIN_DMA( 5 );
  616. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  617. MGA_DMAPAD, 0x00000000,
  618. MGA_DWGSYNC, 0x00007100,
  619. MGA_DWGSYNC, 0x00007000 );
  620. DMA_BLOCK( MGA_DSTORG, dstorg,
  621. MGA_MACCESS, 0x00000000,
  622. MGA_SRCORG, srcorg,
  623. MGA_AR5, 64 );
  624. DMA_BLOCK( MGA_PITCH, 64,
  625. MGA_PLNWT, 0xffffffff,
  626. MGA_DMAPAD, 0x00000000,
  627. MGA_DWGCTL, MGA_DWGCTL_COPY );
  628. DMA_BLOCK( MGA_AR0, 63,
  629. MGA_AR3, 0,
  630. MGA_FXBNDRY, (63 << 16) | 0,
  631. MGA_YDSTLEN + MGA_EXEC, y2 );
  632. DMA_BLOCK( MGA_PLNWT, ctx->plnwt,
  633. MGA_SRCORG, dev_priv->front_offset,
  634. MGA_PITCH, dev_priv->front_pitch,
  635. MGA_DWGSYNC, 0x00007000 );
  636. ADVANCE_DMA();
  637. AGE_BUFFER( buf_priv );
  638. buf->pending = 0;
  639. buf->used = 0;
  640. buf_priv->dispatched = 0;
  641. mga_freelist_put( dev, buf );
  642. FLUSH_DMA();
  643. }
  644. static void mga_dma_dispatch_blit( drm_device_t *dev,
  645. drm_mga_blit_t *blit )
  646. {
  647. drm_mga_private_t *dev_priv = dev->dev_private;
  648. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  649. drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
  650. drm_clip_rect_t *pbox = sarea_priv->boxes;
  651. int nbox = sarea_priv->nbox;
  652. u32 scandir = 0, i;
  653. DMA_LOCALS;
  654. DRM_DEBUG( "\n" );
  655. BEGIN_DMA( 4 + nbox );
  656. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  657. MGA_DMAPAD, 0x00000000,
  658. MGA_DWGSYNC, 0x00007100,
  659. MGA_DWGSYNC, 0x00007000 );
  660. DMA_BLOCK( MGA_DWGCTL, MGA_DWGCTL_COPY,
  661. MGA_PLNWT, blit->planemask,
  662. MGA_SRCORG, blit->srcorg,
  663. MGA_DSTORG, blit->dstorg );
  664. DMA_BLOCK( MGA_SGN, scandir,
  665. MGA_MACCESS, dev_priv->maccess,
  666. MGA_AR5, blit->ydir * blit->src_pitch,
  667. MGA_PITCH, blit->dst_pitch );
  668. for ( i = 0 ; i < nbox ; i++ ) {
  669. int srcx = pbox[i].x1 + blit->delta_sx;
  670. int srcy = pbox[i].y1 + blit->delta_sy;
  671. int dstx = pbox[i].x1 + blit->delta_dx;
  672. int dsty = pbox[i].y1 + blit->delta_dy;
  673. int h = pbox[i].y2 - pbox[i].y1;
  674. int w = pbox[i].x2 - pbox[i].x1 - 1;
  675. int start;
  676. if ( blit->ydir == -1 ) {
  677. srcy = blit->height - srcy - 1;
  678. }
  679. start = srcy * blit->src_pitch + srcx;
  680. DMA_BLOCK( MGA_AR0, start + w,
  681. MGA_AR3, start,
  682. MGA_FXBNDRY, ((dstx + w) << 16) | (dstx & 0xffff),
  683. MGA_YDSTLEN + MGA_EXEC, (dsty << 16) | h );
  684. }
  685. /* Do something to flush AGP?
  686. */
  687. /* Force reset of DWGCTL */
  688. DMA_BLOCK( MGA_DMAPAD, 0x00000000,
  689. MGA_PLNWT, ctx->plnwt,
  690. MGA_PITCH, dev_priv->front_pitch,
  691. MGA_DWGCTL, ctx->dwgctl );
  692. ADVANCE_DMA();
  693. }
  694. /* ================================================================
  695. *
  696. */
  697. static int mga_dma_clear( DRM_IOCTL_ARGS )
  698. {
  699. DRM_DEVICE;
  700. drm_mga_private_t *dev_priv = dev->dev_private;
  701. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  702. drm_mga_clear_t clear;
  703. LOCK_TEST_WITH_RETURN( dev, filp );
  704. DRM_COPY_FROM_USER_IOCTL( clear, (drm_mga_clear_t __user *)data, sizeof(clear) );
  705. if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
  706. sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
  707. WRAP_TEST_WITH_RETURN( dev_priv );
  708. mga_dma_dispatch_clear( dev, &clear );
  709. /* Make sure we restore the 3D state next time.
  710. */
  711. dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
  712. return 0;
  713. }
  714. static int mga_dma_swap( DRM_IOCTL_ARGS )
  715. {
  716. DRM_DEVICE;
  717. drm_mga_private_t *dev_priv = dev->dev_private;
  718. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  719. LOCK_TEST_WITH_RETURN( dev, filp );
  720. if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
  721. sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
  722. WRAP_TEST_WITH_RETURN( dev_priv );
  723. mga_dma_dispatch_swap( dev );
  724. /* Make sure we restore the 3D state next time.
  725. */
  726. dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
  727. return 0;
  728. }
  729. static int mga_dma_vertex( DRM_IOCTL_ARGS )
  730. {
  731. DRM_DEVICE;
  732. drm_mga_private_t *dev_priv = dev->dev_private;
  733. drm_device_dma_t *dma = dev->dma;
  734. drm_buf_t *buf;
  735. drm_mga_buf_priv_t *buf_priv;
  736. drm_mga_vertex_t vertex;
  737. LOCK_TEST_WITH_RETURN( dev, filp );
  738. DRM_COPY_FROM_USER_IOCTL( vertex,
  739. (drm_mga_vertex_t __user *)data,
  740. sizeof(vertex) );
  741. if(vertex.idx < 0 || vertex.idx > dma->buf_count) return DRM_ERR(EINVAL);
  742. buf = dma->buflist[vertex.idx];
  743. buf_priv = buf->dev_private;
  744. buf->used = vertex.used;
  745. buf_priv->discard = vertex.discard;
  746. if ( !mga_verify_state( dev_priv ) ) {
  747. if ( vertex.discard ) {
  748. if ( buf_priv->dispatched == 1 )
  749. AGE_BUFFER( buf_priv );
  750. buf_priv->dispatched = 0;
  751. mga_freelist_put( dev, buf );
  752. }
  753. return DRM_ERR(EINVAL);
  754. }
  755. WRAP_TEST_WITH_RETURN( dev_priv );
  756. mga_dma_dispatch_vertex( dev, buf );
  757. return 0;
  758. }
  759. static int mga_dma_indices( DRM_IOCTL_ARGS )
  760. {
  761. DRM_DEVICE;
  762. drm_mga_private_t *dev_priv = dev->dev_private;
  763. drm_device_dma_t *dma = dev->dma;
  764. drm_buf_t *buf;
  765. drm_mga_buf_priv_t *buf_priv;
  766. drm_mga_indices_t indices;
  767. LOCK_TEST_WITH_RETURN( dev, filp );
  768. DRM_COPY_FROM_USER_IOCTL( indices,
  769. (drm_mga_indices_t __user *)data,
  770. sizeof(indices) );
  771. if(indices.idx < 0 || indices.idx > dma->buf_count) return DRM_ERR(EINVAL);
  772. buf = dma->buflist[indices.idx];
  773. buf_priv = buf->dev_private;
  774. buf_priv->discard = indices.discard;
  775. if ( !mga_verify_state( dev_priv ) ) {
  776. if ( indices.discard ) {
  777. if ( buf_priv->dispatched == 1 )
  778. AGE_BUFFER( buf_priv );
  779. buf_priv->dispatched = 0;
  780. mga_freelist_put( dev, buf );
  781. }
  782. return DRM_ERR(EINVAL);
  783. }
  784. WRAP_TEST_WITH_RETURN( dev_priv );
  785. mga_dma_dispatch_indices( dev, buf, indices.start, indices.end );
  786. return 0;
  787. }
  788. static int mga_dma_iload( DRM_IOCTL_ARGS )
  789. {
  790. DRM_DEVICE;
  791. drm_device_dma_t *dma = dev->dma;
  792. drm_mga_private_t *dev_priv = dev->dev_private;
  793. drm_buf_t *buf;
  794. drm_mga_buf_priv_t *buf_priv;
  795. drm_mga_iload_t iload;
  796. DRM_DEBUG( "\n" );
  797. LOCK_TEST_WITH_RETURN( dev, filp );
  798. DRM_COPY_FROM_USER_IOCTL( iload, (drm_mga_iload_t __user *)data, sizeof(iload) );
  799. #if 0
  800. if ( mga_do_wait_for_idle( dev_priv ) < 0 ) {
  801. if ( MGA_DMA_DEBUG )
  802. DRM_INFO( "%s: -EBUSY\n", __FUNCTION__ );
  803. return DRM_ERR(EBUSY);
  804. }
  805. #endif
  806. if(iload.idx < 0 || iload.idx > dma->buf_count) return DRM_ERR(EINVAL);
  807. buf = dma->buflist[iload.idx];
  808. buf_priv = buf->dev_private;
  809. if ( mga_verify_iload( dev_priv, iload.dstorg, iload.length ) ) {
  810. mga_freelist_put( dev, buf );
  811. return DRM_ERR(EINVAL);
  812. }
  813. WRAP_TEST_WITH_RETURN( dev_priv );
  814. mga_dma_dispatch_iload( dev, buf, iload.dstorg, iload.length );
  815. /* Make sure we restore the 3D state next time.
  816. */
  817. dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
  818. return 0;
  819. }
  820. static int mga_dma_blit( DRM_IOCTL_ARGS )
  821. {
  822. DRM_DEVICE;
  823. drm_mga_private_t *dev_priv = dev->dev_private;
  824. drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
  825. drm_mga_blit_t blit;
  826. DRM_DEBUG( "\n" );
  827. LOCK_TEST_WITH_RETURN( dev, filp );
  828. DRM_COPY_FROM_USER_IOCTL( blit, (drm_mga_blit_t __user *)data, sizeof(blit) );
  829. if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
  830. sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
  831. if ( mga_verify_blit( dev_priv, blit.srcorg, blit.dstorg ) )
  832. return DRM_ERR(EINVAL);
  833. WRAP_TEST_WITH_RETURN( dev_priv );
  834. mga_dma_dispatch_blit( dev, &blit );
  835. /* Make sure we restore the 3D state next time.
  836. */
  837. dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
  838. return 0;
  839. }
  840. static int mga_getparam( DRM_IOCTL_ARGS )
  841. {
  842. DRM_DEVICE;
  843. drm_mga_private_t *dev_priv = dev->dev_private;
  844. drm_mga_getparam_t param;
  845. int value;
  846. if ( !dev_priv ) {
  847. DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
  848. return DRM_ERR(EINVAL);
  849. }
  850. DRM_COPY_FROM_USER_IOCTL( param, (drm_mga_getparam_t __user *)data,
  851. sizeof(param) );
  852. DRM_DEBUG( "pid=%d\n", DRM_CURRENTPID );
  853. switch( param.param ) {
  854. case MGA_PARAM_IRQ_NR:
  855. value = dev->irq;
  856. break;
  857. case MGA_PARAM_CARD_TYPE:
  858. value = dev_priv->chipset;
  859. break;
  860. default:
  861. return DRM_ERR(EINVAL);
  862. }
  863. if ( DRM_COPY_TO_USER( param.value, &value, sizeof(int) ) ) {
  864. DRM_ERROR( "copy_to_user\n" );
  865. return DRM_ERR(EFAULT);
  866. }
  867. return 0;
  868. }
  869. static int mga_set_fence(DRM_IOCTL_ARGS)
  870. {
  871. DRM_DEVICE;
  872. drm_mga_private_t *dev_priv = dev->dev_private;
  873. u32 temp;
  874. DMA_LOCALS;
  875. if (!dev_priv) {
  876. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  877. return DRM_ERR(EINVAL);
  878. }
  879. DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
  880. /* I would normal do this assignment in the declaration of temp,
  881. * but dev_priv may be NULL.
  882. */
  883. temp = dev_priv->next_fence_to_post;
  884. dev_priv->next_fence_to_post++;
  885. BEGIN_DMA(1);
  886. DMA_BLOCK(MGA_DMAPAD, 0x00000000,
  887. MGA_DMAPAD, 0x00000000,
  888. MGA_DMAPAD, 0x00000000,
  889. MGA_SOFTRAP, 0x00000000);
  890. ADVANCE_DMA();
  891. if (DRM_COPY_TO_USER( (u32 __user *) data, & temp, sizeof(u32))) {
  892. DRM_ERROR("copy_to_user\n");
  893. return DRM_ERR(EFAULT);
  894. }
  895. return 0;
  896. }
  897. static int mga_wait_fence(DRM_IOCTL_ARGS)
  898. {
  899. DRM_DEVICE;
  900. drm_mga_private_t *dev_priv = dev->dev_private;
  901. u32 fence;
  902. if (!dev_priv) {
  903. DRM_ERROR("%s called with no initialization\n", __FUNCTION__);
  904. return DRM_ERR(EINVAL);
  905. }
  906. DRM_COPY_FROM_USER_IOCTL(fence, (u32 __user *) data, sizeof(u32));
  907. DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
  908. mga_driver_fence_wait(dev, & fence);
  909. if (DRM_COPY_TO_USER( (u32 __user *) data, & fence, sizeof(u32))) {
  910. DRM_ERROR("copy_to_user\n");
  911. return DRM_ERR(EFAULT);
  912. }
  913. return 0;
  914. }
  915. drm_ioctl_desc_t mga_ioctls[] = {
  916. [DRM_IOCTL_NR(DRM_MGA_INIT)] = {mga_dma_init, 1, 1},
  917. [DRM_IOCTL_NR(DRM_MGA_FLUSH)] = {mga_dma_flush, 1, 0},
  918. [DRM_IOCTL_NR(DRM_MGA_RESET)] = {mga_dma_reset, 1, 0},
  919. [DRM_IOCTL_NR(DRM_MGA_SWAP)] = {mga_dma_swap, 1, 0},
  920. [DRM_IOCTL_NR(DRM_MGA_CLEAR)] = {mga_dma_clear, 1, 0},
  921. [DRM_IOCTL_NR(DRM_MGA_VERTEX)] = {mga_dma_vertex, 1, 0},
  922. [DRM_IOCTL_NR(DRM_MGA_INDICES)] = {mga_dma_indices, 1, 0},
  923. [DRM_IOCTL_NR(DRM_MGA_ILOAD)] = {mga_dma_iload, 1, 0},
  924. [DRM_IOCTL_NR(DRM_MGA_BLIT)] = {mga_dma_blit, 1, 0},
  925. [DRM_IOCTL_NR(DRM_MGA_GETPARAM)] = {mga_getparam, 1, 0},
  926. [DRM_IOCTL_NR(DRM_MGA_SET_FENCE)] = {mga_set_fence, 1, 0},
  927. [DRM_IOCTL_NR(DRM_MGA_WAIT_FENCE)] = {mga_wait_fence, 1, 0},
  928. [DRM_IOCTL_NR(DRM_MGA_DMA_BOOTSTRAP)] = {mga_dma_bootstrap, 1, 1},
  929. };
  930. int mga_max_ioctl = DRM_ARRAY_SIZE(mga_ioctls);