Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * 32-bit ioctl compatibility routines for the i915 DRM.
0003  *
0004  * Copyright (C) Paul Mackerras 2005
0005  * Copyright (C) Alan Hourihane 2005
0006  * All Rights Reserved.
0007  *
0008  * Permission is hereby granted, free of charge, to any person obtaining a
0009  * copy of this software and associated documentation files (the "Software"),
0010  * to deal in the Software without restriction, including without limitation
0011  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0012  * and/or sell copies of the Software, and to permit persons to whom the
0013  * Software is furnished to do so, subject to the following conditions:
0014  *
0015  * The above copyright notice and this permission notice (including the next
0016  * paragraph) shall be included in all copies or substantial portions of the
0017  * Software.
0018  *
0019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0020  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0022  * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
0023  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
0024  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
0025  * IN THE SOFTWARE.
0026  *
0027  * Author: Alan Hourihane <alanh@fairlite.demon.co.uk>
0028  */
0029 #include <linux/compat.h>
0030 
0031 #include <drm/drm_ioctl.h>
0032 
0033 #include "i915_drv.h"
0034 #include "i915_getparam.h"
0035 #include "i915_ioc32.h"
0036 
0037 struct drm_i915_getparam32 {
0038     s32 param;
0039     /*
0040      * We screwed up the generic ioctl struct here and used a variable-sized
0041      * pointer. Use u32 in the compat struct to match the 32bit pointer
0042      * userspace expects.
0043      */
0044     u32 value;
0045 };
0046 
0047 static int compat_i915_getparam(struct file *file, unsigned int cmd,
0048                 unsigned long arg)
0049 {
0050     struct drm_i915_getparam32 req32;
0051     struct drm_i915_getparam req;
0052 
0053     if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
0054         return -EFAULT;
0055 
0056     req.param = req32.param;
0057     req.value = compat_ptr(req32.value);
0058 
0059     return drm_ioctl_kernel(file, i915_getparam_ioctl, &req,
0060                 DRM_RENDER_ALLOW);
0061 }
0062 
0063 static drm_ioctl_compat_t *i915_compat_ioctls[] = {
0064     [DRM_I915_GETPARAM] = compat_i915_getparam,
0065 };
0066 
0067 /**
0068  * i915_ioc32_compat_ioctl - handle the mistakes of the past
0069  * @filp: the file pointer
0070  * @cmd: the ioctl command (and encoded flags)
0071  * @arg: the ioctl argument (from userspace)
0072  *
0073  * Called whenever a 32-bit process running under a 64-bit kernel
0074  * performs an ioctl on /dev/dri/card<n>.
0075  */
0076 long i915_ioc32_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
0077 {
0078     unsigned int nr = DRM_IOCTL_NR(cmd);
0079     drm_ioctl_compat_t *fn = NULL;
0080     int ret;
0081 
0082     if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END)
0083         return drm_compat_ioctl(filp, cmd, arg);
0084 
0085     if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
0086         fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
0087 
0088     if (fn != NULL)
0089         ret = (*fn) (filp, cmd, arg);
0090     else
0091         ret = drm_ioctl(filp, cmd, arg);
0092 
0093     return ret;
0094 }