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