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