162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * 32-bit ioctl compatibility routines for the i915 DRM. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (C) Paul Mackerras 2005 562306a36Sopenharmony_ci * Copyright (C) Alan Hourihane 2005 662306a36Sopenharmony_ci * All Rights Reserved. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 962306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 1062306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 1162306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1262306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 1362306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the next 1662306a36Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 1762306a36Sopenharmony_ci * Software. 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2062306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2162306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2262306a36Sopenharmony_ci * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 2362306a36Sopenharmony_ci * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2462306a36Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 2562306a36Sopenharmony_ci * IN THE SOFTWARE. 2662306a36Sopenharmony_ci * 2762306a36Sopenharmony_ci * Author: Alan Hourihane <alanh@fairlite.demon.co.uk> 2862306a36Sopenharmony_ci */ 2962306a36Sopenharmony_ci#include <linux/compat.h> 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#include <drm/drm_ioctl.h> 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_ci#include "i915_drv.h" 3462306a36Sopenharmony_ci#include "i915_getparam.h" 3562306a36Sopenharmony_ci#include "i915_ioc32.h" 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_cistruct drm_i915_getparam32 { 3862306a36Sopenharmony_ci s32 param; 3962306a36Sopenharmony_ci /* 4062306a36Sopenharmony_ci * We screwed up the generic ioctl struct here and used a variable-sized 4162306a36Sopenharmony_ci * pointer. Use u32 in the compat struct to match the 32bit pointer 4262306a36Sopenharmony_ci * userspace expects. 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_ci u32 value; 4562306a36Sopenharmony_ci}; 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_cistatic int compat_i915_getparam(struct file *file, unsigned int cmd, 4862306a36Sopenharmony_ci unsigned long arg) 4962306a36Sopenharmony_ci{ 5062306a36Sopenharmony_ci struct drm_i915_getparam32 req32; 5162306a36Sopenharmony_ci struct drm_i915_getparam req; 5262306a36Sopenharmony_ci 5362306a36Sopenharmony_ci if (copy_from_user(&req32, (void __user *)arg, sizeof(req32))) 5462306a36Sopenharmony_ci return -EFAULT; 5562306a36Sopenharmony_ci 5662306a36Sopenharmony_ci req.param = req32.param; 5762306a36Sopenharmony_ci req.value = compat_ptr(req32.value); 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci return drm_ioctl_kernel(file, i915_getparam_ioctl, &req, 6062306a36Sopenharmony_ci DRM_RENDER_ALLOW); 6162306a36Sopenharmony_ci} 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_cistatic drm_ioctl_compat_t *i915_compat_ioctls[] = { 6462306a36Sopenharmony_ci [DRM_I915_GETPARAM] = compat_i915_getparam, 6562306a36Sopenharmony_ci}; 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci/** 6862306a36Sopenharmony_ci * i915_ioc32_compat_ioctl - handle the mistakes of the past 6962306a36Sopenharmony_ci * @filp: the file pointer 7062306a36Sopenharmony_ci * @cmd: the ioctl command (and encoded flags) 7162306a36Sopenharmony_ci * @arg: the ioctl argument (from userspace) 7262306a36Sopenharmony_ci * 7362306a36Sopenharmony_ci * Called whenever a 32-bit process running under a 64-bit kernel 7462306a36Sopenharmony_ci * performs an ioctl on /dev/dri/card<n>. 7562306a36Sopenharmony_ci */ 7662306a36Sopenharmony_cilong i915_ioc32_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 7762306a36Sopenharmony_ci{ 7862306a36Sopenharmony_ci unsigned int nr = DRM_IOCTL_NR(cmd); 7962306a36Sopenharmony_ci drm_ioctl_compat_t *fn = NULL; 8062306a36Sopenharmony_ci int ret; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END) 8362306a36Sopenharmony_ci return drm_compat_ioctl(filp, cmd, arg); 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) 8662306a36Sopenharmony_ci fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE]; 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci if (fn != NULL) 8962306a36Sopenharmony_ci ret = (*fn) (filp, cmd, arg); 9062306a36Sopenharmony_ci else 9162306a36Sopenharmony_ci ret = drm_ioctl(filp, cmd, arg); 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci return ret; 9462306a36Sopenharmony_ci} 95