18c2ecf20Sopenharmony_ci/** 28c2ecf20Sopenharmony_ci * \file r128_ioc32.c 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * 32-bit ioctl compatibility routines for the R128 DRM. 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * \author Dave Airlie <airlied@linux.ie> with code from patches by Egbert Eich 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright (C) Paul Mackerras 2005 98c2ecf20Sopenharmony_ci * Copyright (C) Egbert Eich 2003,2004 108c2ecf20Sopenharmony_ci * Copyright (C) Dave Airlie 2005 118c2ecf20Sopenharmony_ci * All Rights Reserved. 128c2ecf20Sopenharmony_ci * 138c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 148c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 158c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 168c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 178c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 188c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next 218c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 228c2ecf20Sopenharmony_ci * Software. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 258c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 268c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 278c2ecf20Sopenharmony_ci * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 288c2ecf20Sopenharmony_ci * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 298c2ecf20Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 308c2ecf20Sopenharmony_ci * IN THE SOFTWARE. 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#include <linux/compat.h> 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci#include <drm/r128_drm.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#include "r128_drv.h" 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_citypedef struct drm_r128_init32 { 408c2ecf20Sopenharmony_ci int func; 418c2ecf20Sopenharmony_ci unsigned int sarea_priv_offset; 428c2ecf20Sopenharmony_ci int is_pci; 438c2ecf20Sopenharmony_ci int cce_mode; 448c2ecf20Sopenharmony_ci int cce_secure; 458c2ecf20Sopenharmony_ci int ring_size; 468c2ecf20Sopenharmony_ci int usec_timeout; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ci unsigned int fb_bpp; 498c2ecf20Sopenharmony_ci unsigned int front_offset, front_pitch; 508c2ecf20Sopenharmony_ci unsigned int back_offset, back_pitch; 518c2ecf20Sopenharmony_ci unsigned int depth_bpp; 528c2ecf20Sopenharmony_ci unsigned int depth_offset, depth_pitch; 538c2ecf20Sopenharmony_ci unsigned int span_offset; 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ci unsigned int fb_offset; 568c2ecf20Sopenharmony_ci unsigned int mmio_offset; 578c2ecf20Sopenharmony_ci unsigned int ring_offset; 588c2ecf20Sopenharmony_ci unsigned int ring_rptr_offset; 598c2ecf20Sopenharmony_ci unsigned int buffers_offset; 608c2ecf20Sopenharmony_ci unsigned int agp_textures_offset; 618c2ecf20Sopenharmony_ci} drm_r128_init32_t; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_cistatic int compat_r128_init(struct file *file, unsigned int cmd, 648c2ecf20Sopenharmony_ci unsigned long arg) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci drm_r128_init32_t init32; 678c2ecf20Sopenharmony_ci drm_r128_init_t init; 688c2ecf20Sopenharmony_ci 698c2ecf20Sopenharmony_ci if (copy_from_user(&init32, (void __user *)arg, sizeof(init32))) 708c2ecf20Sopenharmony_ci return -EFAULT; 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci init.func = init32.func; 738c2ecf20Sopenharmony_ci init.sarea_priv_offset = init32.sarea_priv_offset; 748c2ecf20Sopenharmony_ci init.is_pci = init32.is_pci; 758c2ecf20Sopenharmony_ci init.cce_mode = init32.cce_mode; 768c2ecf20Sopenharmony_ci init.cce_secure = init32.cce_secure; 778c2ecf20Sopenharmony_ci init.ring_size = init32.ring_size; 788c2ecf20Sopenharmony_ci init.usec_timeout = init32.usec_timeout; 798c2ecf20Sopenharmony_ci init.fb_bpp = init32.fb_bpp; 808c2ecf20Sopenharmony_ci init.front_offset = init32.front_offset; 818c2ecf20Sopenharmony_ci init.front_pitch = init32.front_pitch; 828c2ecf20Sopenharmony_ci init.back_offset = init32.back_offset; 838c2ecf20Sopenharmony_ci init.back_pitch = init32.back_pitch; 848c2ecf20Sopenharmony_ci init.depth_bpp = init32.depth_bpp; 858c2ecf20Sopenharmony_ci init.depth_offset = init32.depth_offset; 868c2ecf20Sopenharmony_ci init.depth_pitch = init32.depth_pitch; 878c2ecf20Sopenharmony_ci init.span_offset = init32.span_offset; 888c2ecf20Sopenharmony_ci init.fb_offset = init32.fb_offset; 898c2ecf20Sopenharmony_ci init.mmio_offset = init32.mmio_offset; 908c2ecf20Sopenharmony_ci init.ring_offset = init32.ring_offset; 918c2ecf20Sopenharmony_ci init.ring_rptr_offset = init32.ring_rptr_offset; 928c2ecf20Sopenharmony_ci init.buffers_offset = init32.buffers_offset; 938c2ecf20Sopenharmony_ci init.agp_textures_offset = init32.agp_textures_offset; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci return drm_ioctl_kernel(file, r128_cce_init, &init, 968c2ecf20Sopenharmony_ci DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); 978c2ecf20Sopenharmony_ci} 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_citypedef struct drm_r128_depth32 { 1008c2ecf20Sopenharmony_ci int func; 1018c2ecf20Sopenharmony_ci int n; 1028c2ecf20Sopenharmony_ci u32 x; 1038c2ecf20Sopenharmony_ci u32 y; 1048c2ecf20Sopenharmony_ci u32 buffer; 1058c2ecf20Sopenharmony_ci u32 mask; 1068c2ecf20Sopenharmony_ci} drm_r128_depth32_t; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_cistatic int compat_r128_depth(struct file *file, unsigned int cmd, 1098c2ecf20Sopenharmony_ci unsigned long arg) 1108c2ecf20Sopenharmony_ci{ 1118c2ecf20Sopenharmony_ci drm_r128_depth32_t depth32; 1128c2ecf20Sopenharmony_ci drm_r128_depth_t depth; 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32))) 1158c2ecf20Sopenharmony_ci return -EFAULT; 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci depth.func = depth32.func; 1188c2ecf20Sopenharmony_ci depth.n = depth32.n; 1198c2ecf20Sopenharmony_ci depth.x = compat_ptr(depth32.x); 1208c2ecf20Sopenharmony_ci depth.y = compat_ptr(depth32.y); 1218c2ecf20Sopenharmony_ci depth.buffer = compat_ptr(depth32.buffer); 1228c2ecf20Sopenharmony_ci depth.mask = compat_ptr(depth32.mask); 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci return drm_ioctl_kernel(file, r128_cce_depth, &depth, DRM_AUTH); 1258c2ecf20Sopenharmony_ci} 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_citypedef struct drm_r128_stipple32 { 1288c2ecf20Sopenharmony_ci u32 mask; 1298c2ecf20Sopenharmony_ci} drm_r128_stipple32_t; 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_cistatic int compat_r128_stipple(struct file *file, unsigned int cmd, 1328c2ecf20Sopenharmony_ci unsigned long arg) 1338c2ecf20Sopenharmony_ci{ 1348c2ecf20Sopenharmony_ci drm_r128_stipple32_t stipple32; 1358c2ecf20Sopenharmony_ci drm_r128_stipple_t stipple; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32))) 1388c2ecf20Sopenharmony_ci return -EFAULT; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci stipple.mask = compat_ptr(stipple32.mask); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci return drm_ioctl_kernel(file, r128_cce_stipple, &stipple, DRM_AUTH); 1438c2ecf20Sopenharmony_ci} 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_citypedef struct drm_r128_getparam32 { 1468c2ecf20Sopenharmony_ci int param; 1478c2ecf20Sopenharmony_ci u32 value; 1488c2ecf20Sopenharmony_ci} drm_r128_getparam32_t; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistatic int compat_r128_getparam(struct file *file, unsigned int cmd, 1518c2ecf20Sopenharmony_ci unsigned long arg) 1528c2ecf20Sopenharmony_ci{ 1538c2ecf20Sopenharmony_ci drm_r128_getparam32_t getparam32; 1548c2ecf20Sopenharmony_ci drm_r128_getparam_t getparam; 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32))) 1578c2ecf20Sopenharmony_ci return -EFAULT; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_ci getparam.param = getparam32.param; 1608c2ecf20Sopenharmony_ci getparam.value = compat_ptr(getparam32.value); 1618c2ecf20Sopenharmony_ci 1628c2ecf20Sopenharmony_ci return drm_ioctl_kernel(file, r128_getparam, &getparam, DRM_AUTH); 1638c2ecf20Sopenharmony_ci} 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_cidrm_ioctl_compat_t *r128_compat_ioctls[] = { 1668c2ecf20Sopenharmony_ci [DRM_R128_INIT] = compat_r128_init, 1678c2ecf20Sopenharmony_ci [DRM_R128_DEPTH] = compat_r128_depth, 1688c2ecf20Sopenharmony_ci [DRM_R128_STIPPLE] = compat_r128_stipple, 1698c2ecf20Sopenharmony_ci [DRM_R128_GETPARAM] = compat_r128_getparam, 1708c2ecf20Sopenharmony_ci}; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci/** 1738c2ecf20Sopenharmony_ci * Called whenever a 32-bit process running under a 64-bit kernel 1748c2ecf20Sopenharmony_ci * performs an ioctl on /dev/dri/card<n>. 1758c2ecf20Sopenharmony_ci * 1768c2ecf20Sopenharmony_ci * \param filp file pointer. 1778c2ecf20Sopenharmony_ci * \param cmd command. 1788c2ecf20Sopenharmony_ci * \param arg user argument. 1798c2ecf20Sopenharmony_ci * \return zero on success or negative number on failure. 1808c2ecf20Sopenharmony_ci */ 1818c2ecf20Sopenharmony_cilong r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 1828c2ecf20Sopenharmony_ci{ 1838c2ecf20Sopenharmony_ci unsigned int nr = DRM_IOCTL_NR(cmd); 1848c2ecf20Sopenharmony_ci drm_ioctl_compat_t *fn = NULL; 1858c2ecf20Sopenharmony_ci int ret; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci if (nr < DRM_COMMAND_BASE) 1888c2ecf20Sopenharmony_ci return drm_compat_ioctl(filp, cmd, arg); 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) 1918c2ecf20Sopenharmony_ci fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE]; 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_ci if (fn != NULL) 1948c2ecf20Sopenharmony_ci ret = (*fn) (filp, cmd, arg); 1958c2ecf20Sopenharmony_ci else 1968c2ecf20Sopenharmony_ci ret = drm_ioctl(filp, cmd, arg); 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci return ret; 1998c2ecf20Sopenharmony_ci} 200