1 /* $NetBSD: r128_ioc32.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $ */ 2 3 /** 4 * \file r128_ioc32.c 5 * 6 * 32-bit ioctl compatibility routines for the R128 DRM. 7 * 8 * \author Dave Airlie <airlied (at) linux.ie> with code from patches by Egbert Eich 9 * 10 * Copyright (C) Paul Mackerras 2005 11 * Copyright (C) Egbert Eich 2003,2004 12 * Copyright (C) Dave Airlie 2005 13 * All Rights Reserved. 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining a 16 * copy of this software and associated documentation files (the "Software"), 17 * to deal in the Software without restriction, including without limitation 18 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 19 * and/or sell copies of the Software, and to permit persons to whom the 20 * Software is furnished to do so, subject to the following conditions: 21 * 22 * The above copyright notice and this permission notice (including the next 23 * paragraph) shall be included in all copies or substantial portions of the 24 * Software. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 29 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 30 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 32 * IN THE SOFTWARE. 33 */ 34 35 #include <sys/cdefs.h> 36 __KERNEL_RCSID(0, "$NetBSD: r128_ioc32.c,v 1.3 2021/12/18 23:45:42 riastradh Exp $"); 37 38 #include <linux/compat.h> 39 40 #include <drm/r128_drm.h> 41 42 #include "r128_drv.h" 43 44 typedef struct drm_r128_init32 { 45 int func; 46 unsigned int sarea_priv_offset; 47 int is_pci; 48 int cce_mode; 49 int cce_secure; 50 int ring_size; 51 int usec_timeout; 52 53 unsigned int fb_bpp; 54 unsigned int front_offset, front_pitch; 55 unsigned int back_offset, back_pitch; 56 unsigned int depth_bpp; 57 unsigned int depth_offset, depth_pitch; 58 unsigned int span_offset; 59 60 unsigned int fb_offset; 61 unsigned int mmio_offset; 62 unsigned int ring_offset; 63 unsigned int ring_rptr_offset; 64 unsigned int buffers_offset; 65 unsigned int agp_textures_offset; 66 } drm_r128_init32_t; 67 68 static int compat_r128_init(struct file *file, unsigned int cmd, 69 unsigned long arg) 70 { 71 drm_r128_init32_t init32; 72 drm_r128_init_t init; 73 74 if (copy_from_user(&init32, (void __user *)arg, sizeof(init32))) 75 return -EFAULT; 76 77 init.func = init32.func; 78 init.sarea_priv_offset = init32.sarea_priv_offset; 79 init.is_pci = init32.is_pci; 80 init.cce_mode = init32.cce_mode; 81 init.cce_secure = init32.cce_secure; 82 init.ring_size = init32.ring_size; 83 init.usec_timeout = init32.usec_timeout; 84 init.fb_bpp = init32.fb_bpp; 85 init.front_offset = init32.front_offset; 86 init.front_pitch = init32.front_pitch; 87 init.back_offset = init32.back_offset; 88 init.back_pitch = init32.back_pitch; 89 init.depth_bpp = init32.depth_bpp; 90 init.depth_offset = init32.depth_offset; 91 init.depth_pitch = init32.depth_pitch; 92 init.span_offset = init32.span_offset; 93 init.fb_offset = init32.fb_offset; 94 init.mmio_offset = init32.mmio_offset; 95 init.ring_offset = init32.ring_offset; 96 init.ring_rptr_offset = init32.ring_rptr_offset; 97 init.buffers_offset = init32.buffers_offset; 98 init.agp_textures_offset = init32.agp_textures_offset; 99 100 return drm_ioctl_kernel(file, r128_cce_init, &init, 101 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); 102 } 103 104 typedef struct drm_r128_depth32 { 105 int func; 106 int n; 107 u32 x; 108 u32 y; 109 u32 buffer; 110 u32 mask; 111 } drm_r128_depth32_t; 112 113 static int compat_r128_depth(struct file *file, unsigned int cmd, 114 unsigned long arg) 115 { 116 drm_r128_depth32_t depth32; 117 drm_r128_depth_t depth; 118 119 if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32))) 120 return -EFAULT; 121 122 depth.func = depth32.func; 123 depth.n = depth32.n; 124 depth.x = compat_ptr(depth32.x); 125 depth.y = compat_ptr(depth32.y); 126 depth.buffer = compat_ptr(depth32.buffer); 127 depth.mask = compat_ptr(depth32.mask); 128 129 return drm_ioctl_kernel(file, r128_cce_depth, &depth, DRM_AUTH); 130 } 131 132 typedef struct drm_r128_stipple32 { 133 u32 mask; 134 } drm_r128_stipple32_t; 135 136 static int compat_r128_stipple(struct file *file, unsigned int cmd, 137 unsigned long arg) 138 { 139 drm_r128_stipple32_t stipple32; 140 drm_r128_stipple_t stipple; 141 142 if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32))) 143 return -EFAULT; 144 145 stipple.mask = compat_ptr(stipple32.mask); 146 147 return drm_ioctl_kernel(file, r128_cce_stipple, &stipple, DRM_AUTH); 148 } 149 150 typedef struct drm_r128_getparam32 { 151 int param; 152 u32 value; 153 } drm_r128_getparam32_t; 154 155 static int compat_r128_getparam(struct file *file, unsigned int cmd, 156 unsigned long arg) 157 { 158 drm_r128_getparam32_t getparam32; 159 drm_r128_getparam_t getparam; 160 161 if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32))) 162 return -EFAULT; 163 164 getparam.param = getparam32.param; 165 getparam.value = compat_ptr(getparam32.value); 166 167 return drm_ioctl_kernel(file, r128_getparam, &getparam, DRM_AUTH); 168 } 169 170 drm_ioctl_compat_t *r128_compat_ioctls[] = { 171 [DRM_R128_INIT] = compat_r128_init, 172 [DRM_R128_DEPTH] = compat_r128_depth, 173 [DRM_R128_STIPPLE] = compat_r128_stipple, 174 [DRM_R128_GETPARAM] = compat_r128_getparam, 175 }; 176 177 /** 178 * Called whenever a 32-bit process running under a 64-bit kernel 179 * performs an ioctl on /dev/dri/card<n>. 180 * 181 * \param filp file pointer. 182 * \param cmd command. 183 * \param arg user argument. 184 * \return zero on success or negative number on failure. 185 */ 186 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 187 { 188 unsigned int nr = DRM_IOCTL_NR(cmd); 189 drm_ioctl_compat_t *fn = NULL; 190 int ret; 191 192 if (nr < DRM_COMMAND_BASE) 193 return drm_compat_ioctl(filp, cmd, arg); 194 195 if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) 196 fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE]; 197 198 if (fn != NULL) 199 ret = (*fn) (filp, cmd, arg); 200 else 201 ret = drm_ioctl(filp, cmd, arg); 202 203 return ret; 204 } 205