blob: 55b97c3a3dde686e908bd39d87343797e968aa62 [file] [log] [blame]
Chris Wilsoncc329092018-02-14 16:07:20 +00001/*
Dave Airlie8ca7c1d2005-07-07 21:51:26 +10002 * 32-bit ioctl compatibility routines for the i915 DRM.
3 *
Dave Airlie8ca7c1d2005-07-07 21:51:26 +10004 * 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.
Chris Wilsoncc329092018-02-14 16:07:20 +000026 *
27 * Author: Alan Hourihane <alanh@fairlite.demon.co.uk>
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100028 */
29#include <linux/compat.h>
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100030
Daniel Vetterfcd70cd2019-01-17 22:03:34 +010031#include <drm/drm_ioctl.h>
Jani Nikula062705b2020-02-27 19:00:45 +020032
Ben Widawskyc43b5632012-04-16 14:07:40 -070033#include "i915_drv.h"
Jani Nikula062705b2020-02-27 19:00:45 +020034#include "i915_ioc32.h"
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100035
Daniel Vetter346add72015-07-14 18:07:30 +020036struct drm_i915_getparam32 {
37 s32 param;
38 /*
39 * We screwed up the generic ioctl struct here and used a variable-sized
40 * pointer. Use u32 in the compat struct to match the 32bit pointer
41 * userspace expects.
42 */
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100043 u32 value;
Daniel Vetter346add72015-07-14 18:07:30 +020044};
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100045
46static int compat_i915_getparam(struct file *file, unsigned int cmd,
Dave Airlieb5e89ed2005-09-25 14:28:13 +100047 unsigned long arg)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100048{
Daniel Vetter346add72015-07-14 18:07:30 +020049 struct drm_i915_getparam32 req32;
Al Virofd7cd8d2020-02-19 11:20:34 -050050 struct drm_i915_getparam req;
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100051
Dave Airlieb5e89ed2005-09-25 14:28:13 +100052 if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100053 return -EFAULT;
54
Al Virofd7cd8d2020-02-19 11:20:34 -050055 req.param = req32.param;
56 req.value = compat_ptr(req32.value);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100057
Al Virofd7cd8d2020-02-19 11:20:34 -050058 return drm_ioctl_kernel(file, i915_getparam_ioctl, &req,
59 DRM_RENDER_ALLOW);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100060}
61
Ben Widawskyc43b5632012-04-16 14:07:40 -070062static drm_ioctl_compat_t *i915_compat_ioctls[] = {
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100063 [DRM_I915_GETPARAM] = compat_i915_getparam,
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100064};
65
66/**
Jani Nikula062705b2020-02-27 19:00:45 +020067 * i915_ioc32_compat_ioctl - handle the mistakes of the past
Chris Wilsoncc329092018-02-14 16:07:20 +000068 * @filp: the file pointer
69 * @cmd: the ioctl command (and encoded flags)
70 * @arg: the ioctl argument (from userspace)
71 *
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100072 * Called whenever a 32-bit process running under a 64-bit kernel
73 * performs an ioctl on /dev/dri/card<n>.
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100074 */
Jani Nikula062705b2020-02-27 19:00:45 +020075long i915_ioc32_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100076{
77 unsigned int nr = DRM_IOCTL_NR(cmd);
78 drm_ioctl_compat_t *fn = NULL;
79 int ret;
80
Tvrtko Ursulinac7e7ab2015-07-13 16:51:39 +010081 if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END)
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100082 return drm_compat_ioctl(filp, cmd, arg);
Dave Airlieb5e89ed2005-09-25 14:28:13 +100083
Damien Lespiauf95aeb12014-06-09 14:39:49 +010084 if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100085 fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
86
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100087 if (fn != NULL)
Dave Airlieb5e89ed2005-09-25 14:28:13 +100088 ret = (*fn) (filp, cmd, arg);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100089 else
Arnd Bergmanned8b6702009-12-16 22:17:09 +000090 ret = drm_ioctl(filp, cmd, arg);
Dave Airlie8ca7c1d2005-07-07 21:51:26 +100091
92 return ret;
93}