ffb_context.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:17k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /* $Id: ffb_context.c,v 1.5 2001/08/09 17:47:51 davem Exp $
  2.  * ffb_context.c: Creator/Creator3D DRI/DRM context switching.
  3.  *
  4.  * Copyright (C) 2000 David S. Miller (davem@redhat.com)
  5.  *
  6.  * Almost entirely stolen from tdfx_context.c, see there
  7.  * for authors.
  8.  */
  9. #include <linux/sched.h>
  10. #include <asm/upa.h>
  11. #include "ffb.h"
  12. #include "drmP.h"
  13. #include "ffb_drv.h"
  14. static int DRM(alloc_queue)(drm_device_t *dev, int is_2d_only)
  15. {
  16. ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
  17. int i;
  18. for (i = 0; i < FFB_MAX_CTXS; i++) {
  19. if (fpriv->hw_state[i] == NULL)
  20. break;
  21. }
  22. if (i == FFB_MAX_CTXS)
  23. return -1;
  24. fpriv->hw_state[i] = kmalloc(sizeof(struct ffb_hw_context), GFP_KERNEL);
  25. if (fpriv->hw_state[i] == NULL)
  26. return -1;
  27. fpriv->hw_state[i]->is_2d_only = is_2d_only;
  28. /* Plus one because 0 is the special DRM_KERNEL_CONTEXT. */
  29. return i + 1;
  30. }
  31. static void ffb_save_context(ffb_dev_priv_t *fpriv, int idx)
  32. {
  33. ffb_fbcPtr ffb = fpriv->regs;
  34. struct ffb_hw_context *ctx;
  35. int i;
  36. ctx = fpriv->hw_state[idx - 1];
  37. if (idx == 0 || ctx == NULL)
  38. return;
  39. if (ctx->is_2d_only) {
  40. /* 2D applications only care about certain pieces
  41.  * of state.
  42.  */
  43. ctx->drawop = upa_readl(&ffb->drawop);
  44. ctx->ppc = upa_readl(&ffb->ppc);
  45. ctx->wid = upa_readl(&ffb->wid);
  46. ctx->fg = upa_readl(&ffb->fg);
  47. ctx->bg = upa_readl(&ffb->bg);
  48. ctx->xclip = upa_readl(&ffb->xclip);
  49. ctx->fbc = upa_readl(&ffb->fbc);
  50. ctx->rop = upa_readl(&ffb->rop);
  51. ctx->cmp = upa_readl(&ffb->cmp);
  52. ctx->matchab = upa_readl(&ffb->matchab);
  53. ctx->magnab = upa_readl(&ffb->magnab);
  54. ctx->pmask = upa_readl(&ffb->pmask);
  55. ctx->xpmask = upa_readl(&ffb->xpmask);
  56. ctx->lpat = upa_readl(&ffb->lpat);
  57. ctx->fontxy = upa_readl(&ffb->fontxy);
  58. ctx->fontw = upa_readl(&ffb->fontw);
  59. ctx->fontinc = upa_readl(&ffb->fontinc);
  60. /* stencil/stencilctl only exists on FFB2+ and later
  61.  * due to the introduction of 3DRAM-III.
  62.  */
  63. if (fpriv->ffb_type == ffb2_vertical_plus ||
  64.     fpriv->ffb_type == ffb2_horizontal_plus) {
  65. ctx->stencil = upa_readl(&ffb->stencil);
  66. ctx->stencilctl = upa_readl(&ffb->stencilctl);
  67. }
  68. for (i = 0; i < 32; i++)
  69. ctx->area_pattern[i] = upa_readl(&ffb->pattern[i]);
  70. ctx->ucsr = upa_readl(&ffb->ucsr);
  71. return;
  72. }
  73. /* Fetch drawop. */
  74. ctx->drawop = upa_readl(&ffb->drawop);
  75. /* If we were saving the vertex registers, this is where
  76.  * we would do it.  We would save 32 32-bit words starting
  77.  * at ffb->suvtx.
  78.  */
  79. /* Capture rendering attributes. */
  80. ctx->ppc = upa_readl(&ffb->ppc); /* Pixel Processor Control */
  81. ctx->wid = upa_readl(&ffb->wid); /* Current WID */
  82. ctx->fg = upa_readl(&ffb->fg); /* Constant FG color */
  83. ctx->bg = upa_readl(&ffb->bg); /* Constant BG color */
  84. ctx->consty = upa_readl(&ffb->consty); /* Constant Y */
  85. ctx->constz = upa_readl(&ffb->constz); /* Constant Z */
  86. ctx->xclip = upa_readl(&ffb->xclip); /* X plane clip */
  87. ctx->dcss = upa_readl(&ffb->dcss); /* Depth Cue Scale Slope */
  88. ctx->vclipmin = upa_readl(&ffb->vclipmin); /* Primary XY clip, minimum */
  89. ctx->vclipmax = upa_readl(&ffb->vclipmax); /* Primary XY clip, maximum */
  90. ctx->vclipzmin = upa_readl(&ffb->vclipzmin); /* Primary Z clip, minimum */
  91. ctx->vclipzmax = upa_readl(&ffb->vclipzmax); /* Primary Z clip, maximum */
  92. ctx->dcsf = upa_readl(&ffb->dcsf); /* Depth Cue Scale Front Bound */
  93. ctx->dcsb = upa_readl(&ffb->dcsb); /* Depth Cue Scale Back Bound */
  94. ctx->dczf = upa_readl(&ffb->dczf); /* Depth Cue Scale Z Front */
  95. ctx->dczb = upa_readl(&ffb->dczb); /* Depth Cue Scale Z Back */
  96. ctx->blendc = upa_readl(&ffb->blendc); /* Alpha Blend Control */
  97. ctx->blendc1 = upa_readl(&ffb->blendc1); /* Alpha Blend Color 1 */
  98. ctx->blendc2 = upa_readl(&ffb->blendc2); /* Alpha Blend Color 2 */
  99. ctx->fbc = upa_readl(&ffb->fbc); /* Frame Buffer Control */
  100. ctx->rop = upa_readl(&ffb->rop); /* Raster Operation */
  101. ctx->cmp = upa_readl(&ffb->cmp); /* Compare Controls */
  102. ctx->matchab = upa_readl(&ffb->matchab); /* Buffer A/B Match Ops */
  103. ctx->matchc = upa_readl(&ffb->matchc); /* Buffer C Match Ops */
  104. ctx->magnab = upa_readl(&ffb->magnab); /* Buffer A/B Magnitude Ops */
  105. ctx->magnc = upa_readl(&ffb->magnc); /* Buffer C Magnitude Ops */
  106. ctx->pmask = upa_readl(&ffb->pmask); /* RGB Plane Mask */
  107. ctx->xpmask = upa_readl(&ffb->xpmask); /* X Plane Mask */
  108. ctx->ypmask = upa_readl(&ffb->ypmask); /* Y Plane Mask */
  109. ctx->zpmask = upa_readl(&ffb->zpmask); /* Z Plane Mask */
  110. /* Auxiliary Clips. */
  111. ctx->auxclip0min = upa_readl(&ffb->auxclip[0].min);
  112. ctx->auxclip0max = upa_readl(&ffb->auxclip[0].max);
  113. ctx->auxclip1min = upa_readl(&ffb->auxclip[1].min);
  114. ctx->auxclip1max = upa_readl(&ffb->auxclip[1].max);
  115. ctx->auxclip2min = upa_readl(&ffb->auxclip[2].min);
  116. ctx->auxclip2max = upa_readl(&ffb->auxclip[2].max);
  117. ctx->auxclip3min = upa_readl(&ffb->auxclip[3].min);
  118. ctx->auxclip3max = upa_readl(&ffb->auxclip[3].max);
  119. ctx->lpat = upa_readl(&ffb->lpat); /* Line Pattern */
  120. ctx->fontxy = upa_readl(&ffb->fontxy); /* XY Font Coordinate */
  121. ctx->fontw = upa_readl(&ffb->fontw); /* Font Width */
  122. ctx->fontinc = upa_readl(&ffb->fontinc); /* Font X/Y Increment */
  123. /* These registers/features only exist on FFB2 and later chips. */
  124. if (fpriv->ffb_type >= ffb2_prototype) {
  125. ctx->dcss1 = upa_readl(&ffb->dcss1); /* Depth Cue Scale Slope 1 */
  126. ctx->dcss2 = upa_readl(&ffb->dcss2); /* Depth Cue Scale Slope 2 */
  127. ctx->dcss2 = upa_readl(&ffb->dcss3); /* Depth Cue Scale Slope 3 */
  128. ctx->dcs2  = upa_readl(&ffb->dcs2); /* Depth Cue Scale 2 */
  129. ctx->dcs3  = upa_readl(&ffb->dcs3); /* Depth Cue Scale 3 */
  130. ctx->dcs4  = upa_readl(&ffb->dcs4); /* Depth Cue Scale 4 */
  131. ctx->dcd2  = upa_readl(&ffb->dcd2); /* Depth Cue Depth 2 */
  132. ctx->dcd3  = upa_readl(&ffb->dcd3); /* Depth Cue Depth 3 */
  133. ctx->dcd4  = upa_readl(&ffb->dcd4); /* Depth Cue Depth 4 */
  134. /* And stencil/stencilctl only exists on FFB2+ and later
  135.  * due to the introduction of 3DRAM-III.
  136.  */
  137. if (fpriv->ffb_type == ffb2_vertical_plus ||
  138.     fpriv->ffb_type == ffb2_horizontal_plus) {
  139. ctx->stencil = upa_readl(&ffb->stencil);
  140. ctx->stencilctl = upa_readl(&ffb->stencilctl);
  141. }
  142. }
  143. /* Save the 32x32 area pattern. */
  144. for (i = 0; i < 32; i++)
  145. ctx->area_pattern[i] = upa_readl(&ffb->pattern[i]);
  146. /* Finally, stash away the User Constol/Status Register. */
  147. ctx->ucsr = upa_readl(&ffb->ucsr);
  148. }
  149. static void ffb_restore_context(ffb_dev_priv_t *fpriv, int old, int idx)
  150. {
  151. ffb_fbcPtr ffb = fpriv->regs;
  152. struct ffb_hw_context *ctx;
  153. int i;
  154. ctx = fpriv->hw_state[idx - 1];
  155. if (idx == 0 || ctx == NULL)
  156. return;
  157. if (ctx->is_2d_only) {
  158. /* 2D applications only care about certain pieces
  159.  * of state.
  160.  */
  161. upa_writel(ctx->drawop, &ffb->drawop);
  162. /* If we were restoring the vertex registers, this is where
  163.  * we would do it.  We would restore 32 32-bit words starting
  164.  * at ffb->suvtx.
  165.  */
  166. upa_writel(ctx->ppc, &ffb->ppc);
  167. upa_writel(ctx->wid, &ffb->wid);
  168. upa_writel(ctx->fg,  &ffb->fg);
  169. upa_writel(ctx->bg, &ffb->bg);
  170. upa_writel(ctx->xclip, &ffb->xclip);
  171. upa_writel(ctx->fbc, &ffb->fbc);
  172. upa_writel(ctx->rop, &ffb->rop);
  173. upa_writel(ctx->cmp, &ffb->cmp);
  174. upa_writel(ctx->matchab, &ffb->matchab);
  175. upa_writel(ctx->magnab, &ffb->magnab);
  176. upa_writel(ctx->pmask, &ffb->pmask);
  177. upa_writel(ctx->xpmask, &ffb->xpmask);
  178. upa_writel(ctx->lpat, &ffb->lpat);
  179. upa_writel(ctx->fontxy, &ffb->fontxy);
  180. upa_writel(ctx->fontw, &ffb->fontw);
  181. upa_writel(ctx->fontinc, &ffb->fontinc);
  182. /* stencil/stencilctl only exists on FFB2+ and later
  183.  * due to the introduction of 3DRAM-III.
  184.  */
  185. if (fpriv->ffb_type == ffb2_vertical_plus ||
  186.     fpriv->ffb_type == ffb2_horizontal_plus) {
  187. upa_writel(ctx->stencil, &ffb->stencil);
  188. upa_writel(ctx->stencilctl, &ffb->stencilctl);
  189. upa_writel(0x80000000, &ffb->fbc);
  190. upa_writel((ctx->stencilctl | 0x80000),
  191.    &ffb->rawstencilctl);
  192. upa_writel(ctx->fbc, &ffb->fbc);
  193. }
  194. for (i = 0; i < 32; i++)
  195. upa_writel(ctx->area_pattern[i], &ffb->pattern[i]);
  196. upa_writel((ctx->ucsr & 0xf0000), &ffb->ucsr);
  197. return;
  198. }
  199. /* Restore drawop. */
  200. upa_writel(ctx->drawop, &ffb->drawop);
  201. /* If we were restoring the vertex registers, this is where
  202.  * we would do it.  We would restore 32 32-bit words starting
  203.  * at ffb->suvtx.
  204.  */
  205. /* Restore rendering attributes. */
  206. upa_writel(ctx->ppc, &ffb->ppc); /* Pixel Processor Control */
  207. upa_writel(ctx->wid, &ffb->wid); /* Current WID */
  208. upa_writel(ctx->fg, &ffb->fg); /* Constant FG color */
  209. upa_writel(ctx->bg, &ffb->bg); /* Constant BG color */
  210. upa_writel(ctx->consty, &ffb->consty); /* Constant Y */
  211. upa_writel(ctx->constz, &ffb->constz); /* Constant Z */
  212. upa_writel(ctx->xclip, &ffb->xclip); /* X plane clip */
  213. upa_writel(ctx->dcss, &ffb->dcss); /* Depth Cue Scale Slope */
  214. upa_writel(ctx->vclipmin, &ffb->vclipmin); /* Primary XY clip, minimum */
  215. upa_writel(ctx->vclipmax, &ffb->vclipmax); /* Primary XY clip, maximum */
  216. upa_writel(ctx->vclipzmin, &ffb->vclipzmin); /* Primary Z clip, minimum */
  217. upa_writel(ctx->vclipzmax, &ffb->vclipzmax); /* Primary Z clip, maximum */
  218. upa_writel(ctx->dcsf, &ffb->dcsf); /* Depth Cue Scale Front Bound */
  219. upa_writel(ctx->dcsb, &ffb->dcsb); /* Depth Cue Scale Back Bound */
  220. upa_writel(ctx->dczf, &ffb->dczf); /* Depth Cue Scale Z Front */
  221. upa_writel(ctx->dczb, &ffb->dczb); /* Depth Cue Scale Z Back */
  222. upa_writel(ctx->blendc, &ffb->blendc); /* Alpha Blend Control */
  223. upa_writel(ctx->blendc1, &ffb->blendc1); /* Alpha Blend Color 1 */
  224. upa_writel(ctx->blendc2, &ffb->blendc2); /* Alpha Blend Color 2 */
  225. upa_writel(ctx->fbc, &ffb->fbc); /* Frame Buffer Control */
  226. upa_writel(ctx->rop, &ffb->rop); /* Raster Operation */
  227. upa_writel(ctx->cmp, &ffb->cmp); /* Compare Controls */
  228. upa_writel(ctx->matchab, &ffb->matchab); /* Buffer A/B Match Ops */
  229. upa_writel(ctx->matchc, &ffb->matchc); /* Buffer C Match Ops */
  230. upa_writel(ctx->magnab, &ffb->magnab); /* Buffer A/B Magnitude Ops */
  231. upa_writel(ctx->magnc, &ffb->magnc); /* Buffer C Magnitude Ops */
  232. upa_writel(ctx->pmask, &ffb->pmask); /* RGB Plane Mask */
  233. upa_writel(ctx->xpmask, &ffb->xpmask); /* X Plane Mask */
  234. upa_writel(ctx->ypmask, &ffb->ypmask); /* Y Plane Mask */
  235. upa_writel(ctx->zpmask, &ffb->zpmask); /* Z Plane Mask */
  236. /* Auxiliary Clips. */
  237. upa_writel(ctx->auxclip0min, &ffb->auxclip[0].min);
  238. upa_writel(ctx->auxclip0max, &ffb->auxclip[0].max);
  239. upa_writel(ctx->auxclip1min, &ffb->auxclip[1].min);
  240. upa_writel(ctx->auxclip1max, &ffb->auxclip[1].max);
  241. upa_writel(ctx->auxclip2min, &ffb->auxclip[2].min);
  242. upa_writel(ctx->auxclip2max, &ffb->auxclip[2].max);
  243. upa_writel(ctx->auxclip3min, &ffb->auxclip[3].min);
  244. upa_writel(ctx->auxclip3max, &ffb->auxclip[3].max);
  245. upa_writel(ctx->lpat, &ffb->lpat); /* Line Pattern */
  246. upa_writel(ctx->fontxy, &ffb->fontxy); /* XY Font Coordinate */
  247. upa_writel(ctx->fontw, &ffb->fontw); /* Font Width */
  248. upa_writel(ctx->fontinc, &ffb->fontinc); /* Font X/Y Increment */
  249. /* These registers/features only exist on FFB2 and later chips. */
  250. if (fpriv->ffb_type >= ffb2_prototype) {
  251. upa_writel(ctx->dcss1, &ffb->dcss1); /* Depth Cue Scale Slope 1 */
  252. upa_writel(ctx->dcss2, &ffb->dcss2); /* Depth Cue Scale Slope 2 */
  253. upa_writel(ctx->dcss3, &ffb->dcss2); /* Depth Cue Scale Slope 3 */
  254. upa_writel(ctx->dcs2, &ffb->dcs2); /* Depth Cue Scale 2 */
  255. upa_writel(ctx->dcs3, &ffb->dcs3); /* Depth Cue Scale 3 */
  256. upa_writel(ctx->dcs4, &ffb->dcs4); /* Depth Cue Scale 4 */
  257. upa_writel(ctx->dcd2, &ffb->dcd2); /* Depth Cue Depth 2 */
  258. upa_writel(ctx->dcd3, &ffb->dcd3); /* Depth Cue Depth 3 */
  259. upa_writel(ctx->dcd4, &ffb->dcd4); /* Depth Cue Depth 4 */
  260. /* And stencil/stencilctl only exists on FFB2+ and later
  261.  * due to the introduction of 3DRAM-III.
  262.  */
  263. if (fpriv->ffb_type == ffb2_vertical_plus ||
  264.     fpriv->ffb_type == ffb2_horizontal_plus) {
  265. /* Unfortunately, there is a hardware bug on
  266.  * the FFB2+ chips which prevents a normal write
  267.  * to the stencil control register from working
  268.  * as it should.
  269.  *
  270.  * The state controlled by the FFB stencilctl register
  271.  * really gets transferred to the per-buffer instances
  272.  * of the stencilctl register in the 3DRAM chips.
  273.  *
  274.  * The bug is that FFB does not update buffer C correctly,
  275.  * so we have to do it by hand for them.
  276.  */
  277. /* This will update buffers A and B. */
  278. upa_writel(ctx->stencil, &ffb->stencil);
  279. upa_writel(ctx->stencilctl, &ffb->stencilctl);
  280. /* Force FFB to use buffer C 3dram regs. */
  281. upa_writel(0x80000000, &ffb->fbc);
  282. upa_writel((ctx->stencilctl | 0x80000),
  283.    &ffb->rawstencilctl);
  284. /* Now restore the correct FBC controls. */
  285. upa_writel(ctx->fbc, &ffb->fbc);
  286. }
  287. }
  288. /* Restore the 32x32 area pattern. */
  289. for (i = 0; i < 32; i++)
  290. upa_writel(ctx->area_pattern[i], &ffb->pattern[i]);
  291. /* Finally, stash away the User Constol/Status Register.
  292.  * The only state we really preserve here is the picking
  293.  * control.
  294.  */
  295. upa_writel((ctx->ucsr & 0xf0000), &ffb->ucsr);
  296. }
  297. #define FFB_UCSR_FB_BUSY       0x01000000
  298. #define FFB_UCSR_RP_BUSY       0x02000000
  299. #define FFB_UCSR_ALL_BUSY      (FFB_UCSR_RP_BUSY|FFB_UCSR_FB_BUSY)
  300. static void FFBWait(ffb_fbcPtr ffb)
  301. {
  302. int limit = 100000;
  303. do {
  304. u32 regval = upa_readl(&ffb->ucsr);
  305. if ((regval & FFB_UCSR_ALL_BUSY) == 0)
  306. break;
  307. } while (--limit);
  308. }
  309. int DRM(context_switch)(drm_device_t *dev, int old, int new)
  310. {
  311. ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
  312. #if DRM_DMA_HISTOGRAM
  313.         dev->ctx_start = get_cycles();
  314. #endif
  315.         
  316.         DRM_DEBUG("Context switch from %d to %dn", old, new);
  317.         if (new == dev->last_context ||
  318.     dev->last_context == 0) {
  319. dev->last_context = new;
  320.                 return 0;
  321. }
  322.         
  323. FFBWait(fpriv->regs);
  324. ffb_save_context(fpriv, old);
  325. ffb_restore_context(fpriv, old, new);
  326. FFBWait(fpriv->regs);
  327.         
  328. dev->last_context = new;
  329.         return 0;
  330. }
  331. int DRM(resctx)(struct inode *inode, struct file *filp, unsigned int cmd,
  332. unsigned long arg)
  333. {
  334. drm_ctx_res_t res;
  335. drm_ctx_t ctx;
  336. int i;
  337. DRM_DEBUG("%dn", DRM_RESERVED_CONTEXTS);
  338. if (copy_from_user(&res, (drm_ctx_res_t *)arg, sizeof(res)))
  339. return -EFAULT;
  340. if (res.count >= DRM_RESERVED_CONTEXTS) {
  341. memset(&ctx, 0, sizeof(ctx));
  342. for (i = 0; i < DRM_RESERVED_CONTEXTS; i++) {
  343. ctx.handle = i;
  344. if (copy_to_user(&res.contexts[i],
  345.  &i,
  346.  sizeof(i)))
  347. return -EFAULT;
  348. }
  349. }
  350. res.count = DRM_RESERVED_CONTEXTS;
  351. if (copy_to_user((drm_ctx_res_t *)arg, &res, sizeof(res)))
  352. return -EFAULT;
  353. return 0;
  354. }
  355. int DRM(addctx)(struct inode *inode, struct file *filp, unsigned int cmd,
  356. unsigned long arg)
  357. {
  358. drm_file_t *priv = filp->private_data;
  359. drm_device_t *dev = priv->dev;
  360. drm_ctx_t ctx;
  361. int idx;
  362. if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx)))
  363. return -EFAULT;
  364. idx = DRM(alloc_queue)(dev, (ctx.flags & _DRM_CONTEXT_2DONLY));
  365. if (idx < 0)
  366. return -ENFILE;
  367. DRM_DEBUG("%dn", ctx.handle);
  368. ctx.handle = idx;
  369. if (copy_to_user((drm_ctx_t *)arg, &ctx, sizeof(ctx)))
  370. return -EFAULT;
  371. return 0;
  372. }
  373. int DRM(modctx)(struct inode *inode, struct file *filp, unsigned int cmd,
  374. unsigned long arg)
  375. {
  376. drm_file_t *priv = filp->private_data;
  377. drm_device_t *dev = priv->dev;
  378. ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
  379. struct ffb_hw_context *hwctx;
  380. drm_ctx_t ctx;
  381. int idx;
  382. if (copy_from_user(&ctx, (drm_ctx_t*)arg, sizeof(ctx)))
  383. return -EFAULT;
  384. idx = ctx.handle;
  385. if (idx <= 0 || idx >= FFB_MAX_CTXS)
  386. return -EINVAL;
  387. hwctx = fpriv->hw_state[idx - 1];
  388. if (hwctx == NULL)
  389. return -EINVAL;
  390. if ((ctx.flags & _DRM_CONTEXT_2DONLY) == 0)
  391. hwctx->is_2d_only = 0;
  392. else
  393. hwctx->is_2d_only = 1;
  394. return 0;
  395. }
  396. int DRM(getctx)(struct inode *inode, struct file *filp, unsigned int cmd,
  397. unsigned long arg)
  398. {
  399. drm_file_t *priv = filp->private_data;
  400. drm_device_t *dev = priv->dev;
  401. ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
  402. struct ffb_hw_context *hwctx;
  403. drm_ctx_t ctx;
  404. int idx;
  405. if (copy_from_user(&ctx, (drm_ctx_t*)arg, sizeof(ctx)))
  406. return -EFAULT;
  407. idx = ctx.handle;
  408. if (idx <= 0 || idx >= FFB_MAX_CTXS)
  409. return -EINVAL;
  410. hwctx = fpriv->hw_state[idx - 1];
  411. if (hwctx == NULL)
  412. return -EINVAL;
  413. if (hwctx->is_2d_only != 0)
  414. ctx.flags = _DRM_CONTEXT_2DONLY;
  415. else
  416. ctx.flags = 0;
  417. if (copy_to_user((drm_ctx_t*)arg, &ctx, sizeof(ctx)))
  418. return -EFAULT;
  419. return 0;
  420. }
  421. int DRM(switchctx)(struct inode *inode, struct file *filp, unsigned int cmd,
  422.    unsigned long arg)
  423. {
  424. drm_file_t *priv = filp->private_data;
  425. drm_device_t *dev = priv->dev;
  426. drm_ctx_t ctx;
  427. if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx)))
  428. return -EFAULT;
  429. DRM_DEBUG("%dn", ctx.handle);
  430. return DRM(context_switch)(dev, dev->last_context, ctx.handle);
  431. }
  432. int DRM(newctx)(struct inode *inode, struct file *filp, unsigned int cmd,
  433. unsigned long arg)
  434. {
  435. drm_ctx_t ctx;
  436. if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx)))
  437. return -EFAULT;
  438. DRM_DEBUG("%dn", ctx.handle);
  439. return 0;
  440. }
  441. int DRM(rmctx)(struct inode *inode, struct file *filp, unsigned int cmd,
  442.        unsigned long arg)
  443. {
  444. drm_ctx_t ctx;
  445. drm_file_t *priv = filp->private_data;
  446. drm_device_t *dev = priv->dev;
  447. ffb_dev_priv_t *fpriv = (ffb_dev_priv_t *) dev->dev_private;
  448. int idx;
  449. if (copy_from_user(&ctx, (drm_ctx_t *)arg, sizeof(ctx)))
  450. return -EFAULT;
  451. DRM_DEBUG("%dn", ctx.handle);
  452. idx = ctx.handle - 1;
  453. if (idx < 0 || idx >= FFB_MAX_CTXS)
  454. return -EINVAL;
  455. if (fpriv->hw_state[idx] != NULL) {
  456. kfree(fpriv->hw_state[idx]);
  457. fpriv->hw_state[idx] = NULL;
  458. }
  459. return 0;
  460. }