18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * 32-bit ioctl compatibility routines for the i915 DRM. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (C) Paul Mackerras 2005 58c2ecf20Sopenharmony_ci * Copyright (C) Alan Hourihane 2005 68c2ecf20Sopenharmony_ci * All Rights Reserved. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 98c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 108c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 118c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 128c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 138c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 168c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 178c2ecf20Sopenharmony_ci * Software. 188c2ecf20Sopenharmony_ci * 198c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 208c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 218c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 228c2ecf20Sopenharmony_ci * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 238c2ecf20Sopenharmony_ci * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 248c2ecf20Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 258c2ecf20Sopenharmony_ci * IN THE SOFTWARE. 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * Author: Alan Hourihane <alanh@fairlite.demon.co.uk> 288c2ecf20Sopenharmony_ci */ 298c2ecf20Sopenharmony_ci#include <linux/compat.h> 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#include <drm/drm_ioctl.h> 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include "i915_drv.h" 348c2ecf20Sopenharmony_ci#include "i915_ioc32.h" 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cistruct drm_i915_getparam32 { 378c2ecf20Sopenharmony_ci s32 param; 388c2ecf20Sopenharmony_ci /* 398c2ecf20Sopenharmony_ci * We screwed up the generic ioctl struct here and used a variable-sized 408c2ecf20Sopenharmony_ci * pointer. Use u32 in the compat struct to match the 32bit pointer 418c2ecf20Sopenharmony_ci * userspace expects. 428c2ecf20Sopenharmony_ci */ 438c2ecf20Sopenharmony_ci u32 value; 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic int compat_i915_getparam(struct file *file, unsigned int cmd, 478c2ecf20Sopenharmony_ci unsigned long arg) 488c2ecf20Sopenharmony_ci{ 498c2ecf20Sopenharmony_ci struct drm_i915_getparam32 req32; 508c2ecf20Sopenharmony_ci struct drm_i915_getparam req; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci if (copy_from_user(&req32, (void __user *)arg, sizeof(req32))) 538c2ecf20Sopenharmony_ci return -EFAULT; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci req.param = req32.param; 568c2ecf20Sopenharmony_ci req.value = compat_ptr(req32.value); 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci return drm_ioctl_kernel(file, i915_getparam_ioctl, &req, 598c2ecf20Sopenharmony_ci DRM_RENDER_ALLOW); 608c2ecf20Sopenharmony_ci} 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_cistatic drm_ioctl_compat_t *i915_compat_ioctls[] = { 638c2ecf20Sopenharmony_ci [DRM_I915_GETPARAM] = compat_i915_getparam, 648c2ecf20Sopenharmony_ci}; 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci/** 678c2ecf20Sopenharmony_ci * i915_ioc32_compat_ioctl - handle the mistakes of the past 688c2ecf20Sopenharmony_ci * @filp: the file pointer 698c2ecf20Sopenharmony_ci * @cmd: the ioctl command (and encoded flags) 708c2ecf20Sopenharmony_ci * @arg: the ioctl argument (from userspace) 718c2ecf20Sopenharmony_ci * 728c2ecf20Sopenharmony_ci * Called whenever a 32-bit process running under a 64-bit kernel 738c2ecf20Sopenharmony_ci * performs an ioctl on /dev/dri/card<n>. 748c2ecf20Sopenharmony_ci */ 758c2ecf20Sopenharmony_cilong i915_ioc32_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 768c2ecf20Sopenharmony_ci{ 778c2ecf20Sopenharmony_ci unsigned int nr = DRM_IOCTL_NR(cmd); 788c2ecf20Sopenharmony_ci drm_ioctl_compat_t *fn = NULL; 798c2ecf20Sopenharmony_ci int ret; 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci if (nr < DRM_COMMAND_BASE || nr >= DRM_COMMAND_END) 828c2ecf20Sopenharmony_ci return drm_compat_ioctl(filp, cmd, arg); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ci if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) 858c2ecf20Sopenharmony_ci fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE]; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci if (fn != NULL) 888c2ecf20Sopenharmony_ci ret = (*fn) (filp, cmd, arg); 898c2ecf20Sopenharmony_ci else 908c2ecf20Sopenharmony_ci ret = drm_ioctl(filp, cmd, arg); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci return ret; 938c2ecf20Sopenharmony_ci} 94