i915_ioc32.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * \file i915_ioc32.c
  3. *
  4. * 32-bit ioctl compatibility routines for the i915 DRM.
  5. *
  6. * \author Alan Hourihane <alanh@fairlite.demon.co.uk>
  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>
  33. #include <drm/drmP.h>
  34. #include <drm/i915_drm.h>
  35. #include "i915_drv.h"
  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. */
  43. u32 value;
  44. };
  45. static int compat_i915_getparam(struct file *file, unsigned int cmd,
  46. unsigned long arg)
  47. {
  48. struct drm_i915_getparam32 req32;
  49. drm_i915_getparam_t __user *request;
  50. if (copy_from_user(&req32, (void __user *)arg, sizeof(req32)))
  51. return -EFAULT;
  52. request = compat_alloc_user_space(sizeof(*request));
  53. if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
  54. || __put_user(req32.param, &request->param)
  55. || __put_user((void __user *)(unsigned long)req32.value,
  56. &request->value))
  57. return -EFAULT;
  58. return drm_ioctl(file, DRM_IOCTL_I915_GETPARAM,
  59. (unsigned long)request);
  60. }
  61. static drm_ioctl_compat_t *i915_compat_ioctls[] = {
  62. [DRM_I915_GETPARAM] = compat_i915_getparam,
  63. };
  64. /**
  65. * Called whenever a 32-bit process running under a 64-bit kernel
  66. * performs an ioctl on /dev/dri/card<n>.
  67. *
  68. * \param filp file pointer.
  69. * \param cmd command.
  70. * \param arg user argument.
  71. * \return zero on success or negative number on failure.
  72. */
  73. long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  74. {
  75. unsigned int nr = DRM_IOCTL_NR(cmd);
  76. drm_ioctl_compat_t *fn = NULL;
  77. int ret;
  78. if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END)
  79. return drm_compat_ioctl(filp, cmd, arg);
  80. if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
  81. fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
  82. if (fn != NULL)
  83. ret = (*fn) (filp, cmd, arg);
  84. else
  85. ret = drm_ioctl(filp, cmd, arg);
  86. return ret;
  87. }