1c349dbc7Sjsg /*
2c349dbc7Sjsg * 32-bit ioctl compatibility routines for the i915 DRM.
3c349dbc7Sjsg *
4c349dbc7Sjsg * Copyright (C) Paul Mackerras 2005
5c349dbc7Sjsg * Copyright (C) Alan Hourihane 2005
6c349dbc7Sjsg * All Rights Reserved.
7c349dbc7Sjsg *
8c349dbc7Sjsg * Permission is hereby granted, free of charge, to any person obtaining a
9c349dbc7Sjsg * copy of this software and associated documentation files (the "Software"),
10c349dbc7Sjsg * to deal in the Software without restriction, including without limitation
11c349dbc7Sjsg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12c349dbc7Sjsg * and/or sell copies of the Software, and to permit persons to whom the
13c349dbc7Sjsg * Software is furnished to do so, subject to the following conditions:
14c349dbc7Sjsg *
15c349dbc7Sjsg * The above copyright notice and this permission notice (including the next
16c349dbc7Sjsg * paragraph) shall be included in all copies or substantial portions of the
17c349dbc7Sjsg * Software.
18c349dbc7Sjsg *
19c349dbc7Sjsg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20c349dbc7Sjsg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21c349dbc7Sjsg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22c349dbc7Sjsg * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23c349dbc7Sjsg * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24c349dbc7Sjsg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25c349dbc7Sjsg * IN THE SOFTWARE.
26c349dbc7Sjsg *
27c349dbc7Sjsg * Author: Alan Hourihane <alanh@fairlite.demon.co.uk>
28c349dbc7Sjsg */
29c349dbc7Sjsg #include <linux/compat.h>
30c349dbc7Sjsg
31c349dbc7Sjsg #include <drm/drm_ioctl.h>
32c349dbc7Sjsg
33c349dbc7Sjsg #include "i915_drv.h"
34*1bb76ff1Sjsg #include "i915_getparam.h"
35c349dbc7Sjsg #include "i915_ioc32.h"
36c349dbc7Sjsg
37c349dbc7Sjsg struct drm_i915_getparam32 {
38c349dbc7Sjsg s32 param;
39c349dbc7Sjsg /*
40c349dbc7Sjsg * We screwed up the generic ioctl struct here and used a variable-sized
41c349dbc7Sjsg * pointer. Use u32 in the compat struct to match the 32bit pointer
42c349dbc7Sjsg * userspace expects.
43c349dbc7Sjsg */
44c349dbc7Sjsg u32 value;
45c349dbc7Sjsg };
46c349dbc7Sjsg
compat_i915_getparam(struct file * file,unsigned int cmd,unsigned long arg)47c349dbc7Sjsg static int compat_i915_getparam(struct file *file, unsigned int cmd,
48c349dbc7Sjsg unsigned long arg)
49c349dbc7Sjsg {
50c349dbc7Sjsg struct drm_i915_getparam32 req32;
51ad8b1aafSjsg struct drm_i915_getparam req;
52c349dbc7Sjsg
53c349dbc7Sjsg if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
54c349dbc7Sjsg return -EFAULT;
55c349dbc7Sjsg
56ad8b1aafSjsg req.param = req32.param;
57ad8b1aafSjsg req.value = compat_ptr(req32.value);
58c349dbc7Sjsg
59ad8b1aafSjsg return drm_ioctl_kernel(file, i915_getparam_ioctl, &req,
60ad8b1aafSjsg DRM_RENDER_ALLOW);
61c349dbc7Sjsg }
62c349dbc7Sjsg
63c349dbc7Sjsg static drm_ioctl_compat_t *i915_compat_ioctls[] = {
64c349dbc7Sjsg [DRM_I915_GETPARAM] = compat_i915_getparam,
65c349dbc7Sjsg };
66c349dbc7Sjsg
67c349dbc7Sjsg /**
68c349dbc7Sjsg * i915_ioc32_compat_ioctl - handle the mistakes of the past
69c349dbc7Sjsg * @filp: the file pointer
70c349dbc7Sjsg * @cmd: the ioctl command (and encoded flags)
71c349dbc7Sjsg * @arg: the ioctl argument (from userspace)
72c349dbc7Sjsg *
73c349dbc7Sjsg * Called whenever a 32-bit process running under a 64-bit kernel
74c349dbc7Sjsg * performs an ioctl on /dev/dri/card<n>.
75c349dbc7Sjsg */
i915_ioc32_compat_ioctl(struct file * filp,unsigned int cmd,unsigned long arg)76c349dbc7Sjsg long i915_ioc32_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
77c349dbc7Sjsg {
78c349dbc7Sjsg unsigned int nr = DRM_IOCTL_NR(cmd);
79c349dbc7Sjsg drm_ioctl_compat_t *fn = NULL;
80c349dbc7Sjsg int ret;
81c349dbc7Sjsg
82c349dbc7Sjsg if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END)
83c349dbc7Sjsg return drm_compat_ioctl(filp, cmd, arg);
84c349dbc7Sjsg
85c349dbc7Sjsg if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
86c349dbc7Sjsg fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
87c349dbc7Sjsg
88c349dbc7Sjsg if (fn != NULL)
89c349dbc7Sjsg ret = (*fn) (filp, cmd, arg);
90c349dbc7Sjsg else
91c349dbc7Sjsg ret = drm_ioctl(filp, cmd, arg);
92c349dbc7Sjsg
93c349dbc7Sjsg return ret;
94c349dbc7Sjsg }
95