Chris Wilson | cc32909 | 2018-02-14 16:07:20 +0000 | [diff] [blame] | 1 | /* |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 2 | * 32-bit ioctl compatibility routines for the i915 DRM. |
| 3 | * |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 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. |
Chris Wilson | cc32909 | 2018-02-14 16:07:20 +0000 | [diff] [blame] | 26 | * |
| 27 | * Author: Alan Hourihane <alanh@fairlite.demon.co.uk> |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 28 | */ |
| 29 | #include <linux/compat.h> |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 30 | |
Daniel Vetter | fcd70cd | 2019-01-17 22:03:34 +0100 | [diff] [blame] | 31 | #include <drm/drm_ioctl.h> |
Jani Nikula | 062705b | 2020-02-27 19:00:45 +0200 | [diff] [blame] | 32 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 33 | #include "i915_drv.h" |
Jani Nikula | 062705b | 2020-02-27 19:00:45 +0200 | [diff] [blame] | 34 | #include "i915_ioc32.h" |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 35 | |
Daniel Vetter | 346add7 | 2015-07-14 18:07:30 +0200 | [diff] [blame] | 36 | struct 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 Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 43 | u32 value; |
Daniel Vetter | 346add7 | 2015-07-14 18:07:30 +0200 | [diff] [blame] | 44 | }; |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 45 | |
| 46 | static int compat_i915_getparam(struct file *file, unsigned int cmd, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 47 | unsigned long arg) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 48 | { |
Daniel Vetter | 346add7 | 2015-07-14 18:07:30 +0200 | [diff] [blame] | 49 | struct drm_i915_getparam32 req32; |
Al Viro | fd7cd8d | 2020-02-19 11:20:34 -0500 | [diff] [blame] | 50 | struct drm_i915_getparam req; |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 51 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 52 | if (copy_from_user(&req32, (void __user *)arg, sizeof(req32))) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 53 | return -EFAULT; |
| 54 | |
Al Viro | fd7cd8d | 2020-02-19 11:20:34 -0500 | [diff] [blame] | 55 | req.param = req32.param; |
| 56 | req.value = compat_ptr(req32.value); |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 57 | |
Al Viro | fd7cd8d | 2020-02-19 11:20:34 -0500 | [diff] [blame] | 58 | return drm_ioctl_kernel(file, i915_getparam_ioctl, &req, |
| 59 | DRM_RENDER_ALLOW); |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 60 | } |
| 61 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 62 | static drm_ioctl_compat_t *i915_compat_ioctls[] = { |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 63 | [DRM_I915_GETPARAM] = compat_i915_getparam, |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | /** |
Jani Nikula | 062705b | 2020-02-27 19:00:45 +0200 | [diff] [blame] | 67 | * i915_ioc32_compat_ioctl - handle the mistakes of the past |
Chris Wilson | cc32909 | 2018-02-14 16:07:20 +0000 | [diff] [blame] | 68 | * @filp: the file pointer |
| 69 | * @cmd: the ioctl command (and encoded flags) |
| 70 | * @arg: the ioctl argument (from userspace) |
| 71 | * |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 72 | * Called whenever a 32-bit process running under a 64-bit kernel |
| 73 | * performs an ioctl on /dev/dri/card<n>. |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 74 | */ |
Jani Nikula | 062705b | 2020-02-27 19:00:45 +0200 | [diff] [blame] | 75 | long i915_ioc32_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 76 | { |
| 77 | unsigned int nr = DRM_IOCTL_NR(cmd); |
| 78 | drm_ioctl_compat_t *fn = NULL; |
| 79 | int ret; |
| 80 | |
Tvrtko Ursulin | ac7e7ab | 2015-07-13 16:51:39 +0100 | [diff] [blame] | 81 | if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 82 | return drm_compat_ioctl(filp, cmd, arg); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 83 | |
Damien Lespiau | f95aeb1 | 2014-06-09 14:39:49 +0100 | [diff] [blame] | 84 | if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 85 | fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE]; |
| 86 | |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 87 | if (fn != NULL) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 88 | ret = (*fn) (filp, cmd, arg); |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 89 | else |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 90 | ret = drm_ioctl(filp, cmd, arg); |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 91 | |
| 92 | return ret; |
| 93 | } |