i915_ioc32.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * 32-bit ioctl compatibility routines for the i915 DRM.
  3. *
  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.
  26. *
  27. * Author: Alan Hourihane <alanh@fairlite.demon.co.uk>
  28. */
  29. #include <linux/compat.h>
  30. #include <drm/drmP.h>
  31. #include <drm/i915_drm.h>
  32. #include "i915_drv.h"
  33. struct drm_i915_getparam32 {
  34. s32 param;
  35. /*
  36. * We screwed up the generic ioctl struct here and used a variable-sized
  37. * pointer. Use u32 in the compat struct to match the 32bit pointer
  38. * userspace expects.
  39. */
  40. u32 value;
  41. };
  42. static int compat_i915_getparam(struct file *file, unsigned int cmd,
  43. unsigned long arg)
  44. {
  45. struct drm_i915_getparam32 req32;
  46. drm_i915_getparam_t __user *request;
  47. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  48. return -EFAULT;
  49. request = compat_alloc_user_space(sizeof(*request));
  50. if (!access_ok(VERIFY_WRITE, request, sizeof(*request)) ||
  51. __put_user(req32.param, &request->param) ||
  52. __put_user((void __user *)(unsigned long)req32.value,
  53. &request->value))
  54. return -EFAULT;
  55. return drm_ioctl(file, DRM_IOCTL_I915_GETPARAM,
  56. (unsigned long)request);
  57. }
  58. static drm_ioctl_compat_t *i915_compat_ioctls[] = {
  59. [DRM_I915_GETPARAM] = compat_i915_getparam,
  60. };
  61. /**
  62. * i915_compat_ioctl - handle the mistakes of the past
  63. * @filp: the file pointer
  64. * @cmd: the ioctl command (and encoded flags)
  65. * @arg: the ioctl argument (from userspace)
  66. *
  67. * Called whenever a 32-bit process running under a 64-bit kernel
  68. * performs an ioctl on /dev/dri/card<n>.
  69. */
  70. long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  71. {
  72. unsigned int nr = DRM_IOCTL_NR(cmd);
  73. drm_ioctl_compat_t *fn = NULL;
  74. int ret;
  75. if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END)
  76. return drm_compat_ioctl(filp, cmd, arg);
  77. if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
  78. fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
  79. if (fn != NULL)
  80. ret = (*fn) (filp, cmd, arg);
  81. else
  82. ret = drm_ioctl(filp, cmd, arg);
  83. return ret;
  84. }