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