Home | History | Annotate | Line # | Download | only in r128
r128_ioc32.c revision 1.2
      1 /*	$NetBSD: r128_ioc32.c,v 1.2 2018/08/27 04:58:35 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 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: r128_ioc32.c,v 1.2 2018/08/27 04:58:35 riastradh Exp $");
     36 
     37 #include <linux/compat.h>
     38 
     39 #include <drm/drmP.h>
     40 #include <drm/r128_drm.h>
     41 #include "r128_drv.h"
     42 
     43 typedef struct drm_r128_init32 {
     44 	int func;
     45 	unsigned int sarea_priv_offset;
     46 	int is_pci;
     47 	int cce_mode;
     48 	int cce_secure;
     49 	int ring_size;
     50 	int usec_timeout;
     51 
     52 	unsigned int fb_bpp;
     53 	unsigned int front_offset, front_pitch;
     54 	unsigned int back_offset, back_pitch;
     55 	unsigned int depth_bpp;
     56 	unsigned int depth_offset, depth_pitch;
     57 	unsigned int span_offset;
     58 
     59 	unsigned int fb_offset;
     60 	unsigned int mmio_offset;
     61 	unsigned int ring_offset;
     62 	unsigned int ring_rptr_offset;
     63 	unsigned int buffers_offset;
     64 	unsigned int agp_textures_offset;
     65 } drm_r128_init32_t;
     66 
     67 static int compat_r128_init(struct file *file, unsigned int cmd,
     68 			    unsigned long arg)
     69 {
     70 	drm_r128_init32_t init32;
     71 	drm_r128_init_t __user *init;
     72 
     73 	if (copy_from_user(&init32, (void __user *)arg, sizeof(init32)))
     74 		return -EFAULT;
     75 
     76 	init = compat_alloc_user_space(sizeof(*init));
     77 	if (!access_ok(VERIFY_WRITE, init, sizeof(*init))
     78 	    || __put_user(init32.func, &init->func)
     79 	    || __put_user(init32.sarea_priv_offset, &init->sarea_priv_offset)
     80 	    || __put_user(init32.is_pci, &init->is_pci)
     81 	    || __put_user(init32.cce_mode, &init->cce_mode)
     82 	    || __put_user(init32.cce_secure, &init->cce_secure)
     83 	    || __put_user(init32.ring_size, &init->ring_size)
     84 	    || __put_user(init32.usec_timeout, &init->usec_timeout)
     85 	    || __put_user(init32.fb_bpp, &init->fb_bpp)
     86 	    || __put_user(init32.front_offset, &init->front_offset)
     87 	    || __put_user(init32.front_pitch, &init->front_pitch)
     88 	    || __put_user(init32.back_offset, &init->back_offset)
     89 	    || __put_user(init32.back_pitch, &init->back_pitch)
     90 	    || __put_user(init32.depth_bpp, &init->depth_bpp)
     91 	    || __put_user(init32.depth_offset, &init->depth_offset)
     92 	    || __put_user(init32.depth_pitch, &init->depth_pitch)
     93 	    || __put_user(init32.span_offset, &init->span_offset)
     94 	    || __put_user(init32.fb_offset, &init->fb_offset)
     95 	    || __put_user(init32.mmio_offset, &init->mmio_offset)
     96 	    || __put_user(init32.ring_offset, &init->ring_offset)
     97 	    || __put_user(init32.ring_rptr_offset, &init->ring_rptr_offset)
     98 	    || __put_user(init32.buffers_offset, &init->buffers_offset)
     99 	    || __put_user(init32.agp_textures_offset,
    100 			  &init->agp_textures_offset))
    101 		return -EFAULT;
    102 
    103 	return drm_ioctl(file, DRM_IOCTL_R128_INIT, (unsigned long)init);
    104 }
    105 
    106 typedef struct drm_r128_depth32 {
    107 	int func;
    108 	int n;
    109 	u32 x;
    110 	u32 y;
    111 	u32 buffer;
    112 	u32 mask;
    113 } drm_r128_depth32_t;
    114 
    115 static int compat_r128_depth(struct file *file, unsigned int cmd,
    116 			     unsigned long arg)
    117 {
    118 	drm_r128_depth32_t depth32;
    119 	drm_r128_depth_t __user *depth;
    120 
    121 	if (copy_from_user(&depth32, (void __user *)arg, sizeof(depth32)))
    122 		return -EFAULT;
    123 
    124 	depth = compat_alloc_user_space(sizeof(*depth));
    125 	if (!access_ok(VERIFY_WRITE, depth, sizeof(*depth))
    126 	    || __put_user(depth32.func, &depth->func)
    127 	    || __put_user(depth32.n, &depth->n)
    128 	    || __put_user((int __user *)(unsigned long)depth32.x, &depth->x)
    129 	    || __put_user((int __user *)(unsigned long)depth32.y, &depth->y)
    130 	    || __put_user((unsigned int __user *)(unsigned long)depth32.buffer,
    131 			  &depth->buffer)
    132 	    || __put_user((unsigned char __user *)(unsigned long)depth32.mask,
    133 			  &depth->mask))
    134 		return -EFAULT;
    135 
    136 	return drm_ioctl(file, DRM_IOCTL_R128_DEPTH, (unsigned long)depth);
    137 
    138 }
    139 
    140 typedef struct drm_r128_stipple32 {
    141 	u32 mask;
    142 } drm_r128_stipple32_t;
    143 
    144 static int compat_r128_stipple(struct file *file, unsigned int cmd,
    145 			       unsigned long arg)
    146 {
    147 	drm_r128_stipple32_t stipple32;
    148 	drm_r128_stipple_t __user *stipple;
    149 
    150 	if (copy_from_user(&stipple32, (void __user *)arg, sizeof(stipple32)))
    151 		return -EFAULT;
    152 
    153 	stipple = compat_alloc_user_space(sizeof(*stipple));
    154 	if (!access_ok(VERIFY_WRITE, stipple, sizeof(*stipple))
    155 	    || __put_user((unsigned int __user *)(unsigned long)stipple32.mask,
    156 			  &stipple->mask))
    157 		return -EFAULT;
    158 
    159 	return drm_ioctl(file, DRM_IOCTL_R128_STIPPLE, (unsigned long)stipple);
    160 }
    161 
    162 typedef struct drm_r128_getparam32 {
    163 	int param;
    164 	u32 value;
    165 } drm_r128_getparam32_t;
    166 
    167 static int compat_r128_getparam(struct file *file, unsigned int cmd,
    168 				unsigned long arg)
    169 {
    170 	drm_r128_getparam32_t getparam32;
    171 	drm_r128_getparam_t __user *getparam;
    172 
    173 	if (copy_from_user(&getparam32, (void __user *)arg, sizeof(getparam32)))
    174 		return -EFAULT;
    175 
    176 	getparam = compat_alloc_user_space(sizeof(*getparam));
    177 	if (!access_ok(VERIFY_WRITE, getparam, sizeof(*getparam))
    178 	    || __put_user(getparam32.param, &getparam->param)
    179 	    || __put_user((void __user *)(unsigned long)getparam32.value,
    180 			  &getparam->value))
    181 		return -EFAULT;
    182 
    183 	return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
    184 }
    185 
    186 drm_ioctl_compat_t *r128_compat_ioctls[] = {
    187 	[DRM_R128_INIT] = compat_r128_init,
    188 	[DRM_R128_DEPTH] = compat_r128_depth,
    189 	[DRM_R128_STIPPLE] = compat_r128_stipple,
    190 	[DRM_R128_GETPARAM] = compat_r128_getparam,
    191 };
    192 
    193 /**
    194  * Called whenever a 32-bit process running under a 64-bit kernel
    195  * performs an ioctl on /dev/dri/card<n>.
    196  *
    197  * \param filp file pointer.
    198  * \param cmd command.
    199  * \param arg user argument.
    200  * \return zero on success or negative number on failure.
    201  */
    202 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
    203 {
    204 	unsigned int nr = DRM_IOCTL_NR(cmd);
    205 	drm_ioctl_compat_t *fn = NULL;
    206 	int ret;
    207 
    208 	if (nr < DRM_COMMAND_BASE)
    209 		return drm_compat_ioctl(filp, cmd, arg);
    210 
    211 	if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
    212 		fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
    213 
    214 	if (fn != NULL)
    215 		ret = (*fn) (filp, cmd, arg);
    216 	else
    217 		ret = drm_ioctl(filp, cmd, arg);
    218 
    219 	return ret;
    220 }
    221