Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 1 | /** |
| 2 | * \file i915_ioc32.c |
| 3 | * |
| 4 | * 32-bit ioctl compatibility routines for the i915 DRM. |
| 5 | * |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 6 | * \author Alan Hourihane <alanh@fairlite.demon.co.uk> |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 7 | * |
| 8 | * |
| 9 | * Copyright (C) Paul Mackerras 2005 |
| 10 | * Copyright (C) Alan Hourihane 2005 |
| 11 | * All Rights Reserved. |
| 12 | * |
| 13 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 14 | * copy of this software and associated documentation files (the "Software"), |
| 15 | * to deal in the Software without restriction, including without limitation |
| 16 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 17 | * and/or sell copies of the Software, and to permit persons to whom the |
| 18 | * Software is furnished to do so, subject to the following conditions: |
| 19 | * |
| 20 | * The above copyright notice and this permission notice (including the next |
| 21 | * paragraph) shall be included in all copies or substantial portions of the |
| 22 | * Software. |
| 23 | * |
| 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 25 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 26 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 27 | * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 28 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 29 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 30 | * IN THE SOFTWARE. |
| 31 | */ |
| 32 | #include <linux/compat.h> |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 33 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 34 | #include <drm/drmP.h> |
| 35 | #include <drm/i915_drm.h> |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 36 | #include "i915_drv.h" |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 37 | |
Daniel Vetter | 346add7 | 2015-07-14 18:07:30 +0200 | [diff] [blame] | 38 | struct drm_i915_getparam32 { |
| 39 | s32 param; |
| 40 | /* |
| 41 | * We screwed up the generic ioctl struct here and used a variable-sized |
| 42 | * pointer. Use u32 in the compat struct to match the 32bit pointer |
| 43 | * userspace expects. |
| 44 | */ |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 45 | u32 value; |
Daniel Vetter | 346add7 | 2015-07-14 18:07:30 +0200 | [diff] [blame] | 46 | }; |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 47 | |
| 48 | static int compat_i915_getparam(struct file *file, unsigned int cmd, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 49 | unsigned long arg) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 50 | { |
Daniel Vetter | 346add7 | 2015-07-14 18:07:30 +0200 | [diff] [blame] | 51 | struct drm_i915_getparam32 req32; |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 52 | drm_i915_getparam_t __user *request; |
| 53 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 54 | if (copy_from_user(&req32, (void __user *)arg, sizeof(req32))) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 55 | return -EFAULT; |
| 56 | |
| 57 | request = compat_alloc_user_space(sizeof(*request)); |
| 58 | if (!access_ok(VERIFY_WRITE, request, sizeof(*request)) |
| 59 | || __put_user(req32.param, &request->param) |
| 60 | || __put_user((void __user *)(unsigned long)req32.value, |
| 61 | &request->value)) |
| 62 | return -EFAULT; |
| 63 | |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 64 | return drm_ioctl(file, DRM_IOCTL_I915_GETPARAM, |
| 65 | (unsigned long)request); |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 66 | } |
| 67 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 68 | static drm_ioctl_compat_t *i915_compat_ioctls[] = { |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 69 | [DRM_I915_GETPARAM] = compat_i915_getparam, |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * Called whenever a 32-bit process running under a 64-bit kernel |
| 74 | * performs an ioctl on /dev/dri/card<n>. |
| 75 | * |
| 76 | * \param filp file pointer. |
| 77 | * \param cmd command. |
| 78 | * \param arg user argument. |
| 79 | * \return zero on success or negative number on failure. |
| 80 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 81 | long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 82 | { |
| 83 | unsigned int nr = DRM_IOCTL_NR(cmd); |
| 84 | drm_ioctl_compat_t *fn = NULL; |
| 85 | int ret; |
| 86 | |
Tvrtko Ursulin | ac7e7ab | 2015-07-13 16:51:39 +0100 | [diff] [blame] | 87 | if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 88 | return drm_compat_ioctl(filp, cmd, arg); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 89 | |
Damien Lespiau | f95aeb1 | 2014-06-09 14:39:49 +0100 | [diff] [blame] | 90 | if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 91 | fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE]; |
| 92 | |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 93 | if (fn != NULL) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 94 | ret = (*fn) (filp, cmd, arg); |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 95 | else |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 96 | ret = drm_ioctl(filp, cmd, arg); |
Dave Airlie | 8ca7c1d | 2005-07-07 21:51:26 +1000 | [diff] [blame] | 97 | |
| 98 | return ret; |
| 99 | } |