Home | History | Annotate | Line # | Download | only in drm
drm_ioc32.c revision 1.2
      1  1.2  riastrad /*	$NetBSD: drm_ioc32.c,v 1.2 2018/08/27 04:58:19 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.1  riastrad /**
      4  1.1  riastrad  * \file drm_ioc32.c
      5  1.1  riastrad  *
      6  1.1  riastrad  * 32-bit ioctl compatibility routines for the DRM.
      7  1.1  riastrad  *
      8  1.1  riastrad  * \author Paul Mackerras <paulus (at) samba.org>
      9  1.1  riastrad  *
     10  1.1  riastrad  * Copyright (C) Paul Mackerras 2005.
     11  1.1  riastrad  * All Rights Reserved.
     12  1.1  riastrad  *
     13  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
     14  1.1  riastrad  * copy of this software and associated documentation files (the "Software"),
     15  1.1  riastrad  * to deal in the Software without restriction, including without limitation
     16  1.1  riastrad  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     17  1.1  riastrad  * and/or sell copies of the Software, and to permit persons to whom the
     18  1.1  riastrad  * Software is furnished to do so, subject to the following conditions:
     19  1.1  riastrad  *
     20  1.1  riastrad  * The above copyright notice and this permission notice (including the next
     21  1.1  riastrad  * paragraph) shall be included in all copies or substantial portions of the
     22  1.1  riastrad  * Software.
     23  1.1  riastrad  *
     24  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     25  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     26  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     27  1.1  riastrad  * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     28  1.1  riastrad  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     29  1.1  riastrad  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     30  1.1  riastrad  * IN THE SOFTWARE.
     31  1.1  riastrad  */
     32  1.2  riastrad #include <sys/cdefs.h>
     33  1.2  riastrad __KERNEL_RCSID(0, "$NetBSD: drm_ioc32.c,v 1.2 2018/08/27 04:58:19 riastradh Exp $");
     34  1.2  riastrad 
     35  1.1  riastrad #include <linux/compat.h>
     36  1.1  riastrad #include <linux/ratelimit.h>
     37  1.1  riastrad #include <linux/export.h>
     38  1.1  riastrad 
     39  1.1  riastrad #include <drm/drmP.h>
     40  1.1  riastrad #include <drm/drm_core.h>
     41  1.1  riastrad 
     42  1.1  riastrad #define DRM_IOCTL_VERSION32		DRM_IOWR(0x00, drm_version32_t)
     43  1.1  riastrad #define DRM_IOCTL_GET_UNIQUE32		DRM_IOWR(0x01, drm_unique32_t)
     44  1.1  riastrad #define DRM_IOCTL_GET_MAP32		DRM_IOWR(0x04, drm_map32_t)
     45  1.1  riastrad #define DRM_IOCTL_GET_CLIENT32		DRM_IOWR(0x05, drm_client32_t)
     46  1.1  riastrad #define DRM_IOCTL_GET_STATS32		DRM_IOR( 0x06, drm_stats32_t)
     47  1.1  riastrad 
     48  1.1  riastrad #define DRM_IOCTL_SET_UNIQUE32		DRM_IOW( 0x10, drm_unique32_t)
     49  1.1  riastrad #define DRM_IOCTL_ADD_MAP32		DRM_IOWR(0x15, drm_map32_t)
     50  1.1  riastrad #define DRM_IOCTL_ADD_BUFS32		DRM_IOWR(0x16, drm_buf_desc32_t)
     51  1.1  riastrad #define DRM_IOCTL_MARK_BUFS32		DRM_IOW( 0x17, drm_buf_desc32_t)
     52  1.1  riastrad #define DRM_IOCTL_INFO_BUFS32		DRM_IOWR(0x18, drm_buf_info32_t)
     53  1.1  riastrad #define DRM_IOCTL_MAP_BUFS32		DRM_IOWR(0x19, drm_buf_map32_t)
     54  1.1  riastrad #define DRM_IOCTL_FREE_BUFS32		DRM_IOW( 0x1a, drm_buf_free32_t)
     55  1.1  riastrad 
     56  1.1  riastrad #define DRM_IOCTL_RM_MAP32		DRM_IOW( 0x1b, drm_map32_t)
     57  1.1  riastrad 
     58  1.1  riastrad #define DRM_IOCTL_SET_SAREA_CTX32	DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
     59  1.1  riastrad #define DRM_IOCTL_GET_SAREA_CTX32	DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
     60  1.1  riastrad 
     61  1.1  riastrad #define DRM_IOCTL_RES_CTX32		DRM_IOWR(0x26, drm_ctx_res32_t)
     62  1.1  riastrad #define DRM_IOCTL_DMA32			DRM_IOWR(0x29, drm_dma32_t)
     63  1.1  riastrad 
     64  1.1  riastrad #define DRM_IOCTL_AGP_ENABLE32		DRM_IOW( 0x32, drm_agp_mode32_t)
     65  1.1  riastrad #define DRM_IOCTL_AGP_INFO32		DRM_IOR( 0x33, drm_agp_info32_t)
     66  1.1  riastrad #define DRM_IOCTL_AGP_ALLOC32		DRM_IOWR(0x34, drm_agp_buffer32_t)
     67  1.1  riastrad #define DRM_IOCTL_AGP_FREE32		DRM_IOW( 0x35, drm_agp_buffer32_t)
     68  1.1  riastrad #define DRM_IOCTL_AGP_BIND32		DRM_IOW( 0x36, drm_agp_binding32_t)
     69  1.1  riastrad #define DRM_IOCTL_AGP_UNBIND32		DRM_IOW( 0x37, drm_agp_binding32_t)
     70  1.1  riastrad 
     71  1.1  riastrad #define DRM_IOCTL_SG_ALLOC32		DRM_IOW( 0x38, drm_scatter_gather32_t)
     72  1.1  riastrad #define DRM_IOCTL_SG_FREE32		DRM_IOW( 0x39, drm_scatter_gather32_t)
     73  1.1  riastrad 
     74  1.1  riastrad #define DRM_IOCTL_UPDATE_DRAW32		DRM_IOW( 0x3f, drm_update_draw32_t)
     75  1.1  riastrad 
     76  1.1  riastrad #define DRM_IOCTL_WAIT_VBLANK32		DRM_IOWR(0x3a, drm_wait_vblank32_t)
     77  1.1  riastrad 
     78  1.2  riastrad #define DRM_IOCTL_MODE_ADDFB232		DRM_IOWR(0xb8, drm_mode_fb_cmd232_t)
     79  1.2  riastrad 
     80  1.1  riastrad typedef struct drm_version_32 {
     81  1.1  riastrad 	int version_major;	  /**< Major version */
     82  1.1  riastrad 	int version_minor;	  /**< Minor version */
     83  1.1  riastrad 	int version_patchlevel;	   /**< Patch level */
     84  1.1  riastrad 	u32 name_len;		  /**< Length of name buffer */
     85  1.1  riastrad 	u32 name;		  /**< Name of driver */
     86  1.1  riastrad 	u32 date_len;		  /**< Length of date buffer */
     87  1.1  riastrad 	u32 date;		  /**< User-space buffer to hold date */
     88  1.1  riastrad 	u32 desc_len;		  /**< Length of desc buffer */
     89  1.1  riastrad 	u32 desc;		  /**< User-space buffer to hold desc */
     90  1.1  riastrad } drm_version32_t;
     91  1.1  riastrad 
     92  1.1  riastrad static int compat_drm_version(struct file *file, unsigned int cmd,
     93  1.1  riastrad 			      unsigned long arg)
     94  1.1  riastrad {
     95  1.1  riastrad 	drm_version32_t v32;
     96  1.1  riastrad 	struct drm_version __user *version;
     97  1.1  riastrad 	int err;
     98  1.1  riastrad 
     99  1.1  riastrad 	if (copy_from_user(&v32, (void __user *)arg, sizeof(v32)))
    100  1.1  riastrad 		return -EFAULT;
    101  1.1  riastrad 
    102  1.1  riastrad 	version = compat_alloc_user_space(sizeof(*version));
    103  1.2  riastrad 	if (!version)
    104  1.1  riastrad 		return -EFAULT;
    105  1.1  riastrad 	if (__put_user(v32.name_len, &version->name_len)
    106  1.1  riastrad 	    || __put_user((void __user *)(unsigned long)v32.name,
    107  1.1  riastrad 			  &version->name)
    108  1.1  riastrad 	    || __put_user(v32.date_len, &version->date_len)
    109  1.1  riastrad 	    || __put_user((void __user *)(unsigned long)v32.date,
    110  1.1  riastrad 			  &version->date)
    111  1.1  riastrad 	    || __put_user(v32.desc_len, &version->desc_len)
    112  1.1  riastrad 	    || __put_user((void __user *)(unsigned long)v32.desc,
    113  1.1  riastrad 			  &version->desc))
    114  1.1  riastrad 		return -EFAULT;
    115  1.1  riastrad 
    116  1.1  riastrad 	err = drm_ioctl(file,
    117  1.1  riastrad 			DRM_IOCTL_VERSION, (unsigned long)version);
    118  1.1  riastrad 	if (err)
    119  1.1  riastrad 		return err;
    120  1.1  riastrad 
    121  1.1  riastrad 	if (__get_user(v32.version_major, &version->version_major)
    122  1.1  riastrad 	    || __get_user(v32.version_minor, &version->version_minor)
    123  1.1  riastrad 	    || __get_user(v32.version_patchlevel, &version->version_patchlevel)
    124  1.1  riastrad 	    || __get_user(v32.name_len, &version->name_len)
    125  1.1  riastrad 	    || __get_user(v32.date_len, &version->date_len)
    126  1.1  riastrad 	    || __get_user(v32.desc_len, &version->desc_len))
    127  1.1  riastrad 		return -EFAULT;
    128  1.1  riastrad 
    129  1.1  riastrad 	if (copy_to_user((void __user *)arg, &v32, sizeof(v32)))
    130  1.1  riastrad 		return -EFAULT;
    131  1.1  riastrad 	return 0;
    132  1.1  riastrad }
    133  1.1  riastrad 
    134  1.1  riastrad typedef struct drm_unique32 {
    135  1.1  riastrad 	u32 unique_len;	/**< Length of unique */
    136  1.1  riastrad 	u32 unique;	/**< Unique name for driver instantiation */
    137  1.1  riastrad } drm_unique32_t;
    138  1.1  riastrad 
    139  1.1  riastrad static int compat_drm_getunique(struct file *file, unsigned int cmd,
    140  1.1  riastrad 				unsigned long arg)
    141  1.1  riastrad {
    142  1.1  riastrad 	drm_unique32_t uq32;
    143  1.1  riastrad 	struct drm_unique __user *u;
    144  1.1  riastrad 	int err;
    145  1.1  riastrad 
    146  1.1  riastrad 	if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
    147  1.1  riastrad 		return -EFAULT;
    148  1.1  riastrad 
    149  1.1  riastrad 	u = compat_alloc_user_space(sizeof(*u));
    150  1.2  riastrad 	if (!u)
    151  1.1  riastrad 		return -EFAULT;
    152  1.1  riastrad 	if (__put_user(uq32.unique_len, &u->unique_len)
    153  1.1  riastrad 	    || __put_user((void __user *)(unsigned long)uq32.unique,
    154  1.1  riastrad 			  &u->unique))
    155  1.1  riastrad 		return -EFAULT;
    156  1.1  riastrad 
    157  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_GET_UNIQUE, (unsigned long)u);
    158  1.1  riastrad 	if (err)
    159  1.1  riastrad 		return err;
    160  1.1  riastrad 
    161  1.1  riastrad 	if (__get_user(uq32.unique_len, &u->unique_len))
    162  1.1  riastrad 		return -EFAULT;
    163  1.1  riastrad 	if (copy_to_user((void __user *)arg, &uq32, sizeof(uq32)))
    164  1.1  riastrad 		return -EFAULT;
    165  1.1  riastrad 	return 0;
    166  1.1  riastrad }
    167  1.1  riastrad 
    168  1.1  riastrad static int compat_drm_setunique(struct file *file, unsigned int cmd,
    169  1.1  riastrad 				unsigned long arg)
    170  1.1  riastrad {
    171  1.1  riastrad 	drm_unique32_t uq32;
    172  1.1  riastrad 	struct drm_unique __user *u;
    173  1.1  riastrad 
    174  1.1  riastrad 	if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
    175  1.1  riastrad 		return -EFAULT;
    176  1.1  riastrad 
    177  1.1  riastrad 	u = compat_alloc_user_space(sizeof(*u));
    178  1.2  riastrad 	if (!u)
    179  1.1  riastrad 		return -EFAULT;
    180  1.1  riastrad 	if (__put_user(uq32.unique_len, &u->unique_len)
    181  1.1  riastrad 	    || __put_user((void __user *)(unsigned long)uq32.unique,
    182  1.1  riastrad 			  &u->unique))
    183  1.1  riastrad 		return -EFAULT;
    184  1.1  riastrad 
    185  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_SET_UNIQUE, (unsigned long)u);
    186  1.1  riastrad }
    187  1.1  riastrad 
    188  1.1  riastrad typedef struct drm_map32 {
    189  1.1  riastrad 	u32 offset;		/**< Requested physical address (0 for SAREA)*/
    190  1.1  riastrad 	u32 size;		/**< Requested physical size (bytes) */
    191  1.1  riastrad 	enum drm_map_type type;	/**< Type of memory to map */
    192  1.1  riastrad 	enum drm_map_flags flags;	/**< Flags */
    193  1.1  riastrad 	u32 handle;		/**< User-space: "Handle" to pass to mmap() */
    194  1.1  riastrad 	int mtrr;		/**< MTRR slot used */
    195  1.1  riastrad } drm_map32_t;
    196  1.1  riastrad 
    197  1.1  riastrad static int compat_drm_getmap(struct file *file, unsigned int cmd,
    198  1.1  riastrad 			     unsigned long arg)
    199  1.1  riastrad {
    200  1.1  riastrad 	drm_map32_t __user *argp = (void __user *)arg;
    201  1.1  riastrad 	drm_map32_t m32;
    202  1.1  riastrad 	struct drm_map __user *map;
    203  1.1  riastrad 	int idx, err;
    204  1.1  riastrad 	void *handle;
    205  1.1  riastrad 
    206  1.1  riastrad 	if (get_user(idx, &argp->offset))
    207  1.1  riastrad 		return -EFAULT;
    208  1.1  riastrad 
    209  1.1  riastrad 	map = compat_alloc_user_space(sizeof(*map));
    210  1.2  riastrad 	if (!map)
    211  1.1  riastrad 		return -EFAULT;
    212  1.1  riastrad 	if (__put_user(idx, &map->offset))
    213  1.1  riastrad 		return -EFAULT;
    214  1.1  riastrad 
    215  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_GET_MAP, (unsigned long)map);
    216  1.1  riastrad 	if (err)
    217  1.1  riastrad 		return err;
    218  1.1  riastrad 
    219  1.1  riastrad 	if (__get_user(m32.offset, &map->offset)
    220  1.1  riastrad 	    || __get_user(m32.size, &map->size)
    221  1.1  riastrad 	    || __get_user(m32.type, &map->type)
    222  1.1  riastrad 	    || __get_user(m32.flags, &map->flags)
    223  1.1  riastrad 	    || __get_user(handle, &map->handle)
    224  1.1  riastrad 	    || __get_user(m32.mtrr, &map->mtrr))
    225  1.1  riastrad 		return -EFAULT;
    226  1.1  riastrad 
    227  1.1  riastrad 	m32.handle = (unsigned long)handle;
    228  1.1  riastrad 	if (copy_to_user(argp, &m32, sizeof(m32)))
    229  1.1  riastrad 		return -EFAULT;
    230  1.1  riastrad 	return 0;
    231  1.1  riastrad 
    232  1.1  riastrad }
    233  1.1  riastrad 
    234  1.1  riastrad static int compat_drm_addmap(struct file *file, unsigned int cmd,
    235  1.1  riastrad 			     unsigned long arg)
    236  1.1  riastrad {
    237  1.1  riastrad 	drm_map32_t __user *argp = (void __user *)arg;
    238  1.1  riastrad 	drm_map32_t m32;
    239  1.1  riastrad 	struct drm_map __user *map;
    240  1.1  riastrad 	int err;
    241  1.1  riastrad 	void *handle;
    242  1.1  riastrad 
    243  1.1  riastrad 	if (copy_from_user(&m32, argp, sizeof(m32)))
    244  1.1  riastrad 		return -EFAULT;
    245  1.1  riastrad 
    246  1.1  riastrad 	map = compat_alloc_user_space(sizeof(*map));
    247  1.2  riastrad 	if (!map)
    248  1.1  riastrad 		return -EFAULT;
    249  1.1  riastrad 	if (__put_user(m32.offset, &map->offset)
    250  1.1  riastrad 	    || __put_user(m32.size, &map->size)
    251  1.1  riastrad 	    || __put_user(m32.type, &map->type)
    252  1.1  riastrad 	    || __put_user(m32.flags, &map->flags))
    253  1.1  riastrad 		return -EFAULT;
    254  1.1  riastrad 
    255  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_ADD_MAP, (unsigned long)map);
    256  1.1  riastrad 	if (err)
    257  1.1  riastrad 		return err;
    258  1.1  riastrad 
    259  1.1  riastrad 	if (__get_user(m32.offset, &map->offset)
    260  1.1  riastrad 	    || __get_user(m32.mtrr, &map->mtrr)
    261  1.1  riastrad 	    || __get_user(handle, &map->handle))
    262  1.1  riastrad 		return -EFAULT;
    263  1.1  riastrad 
    264  1.1  riastrad 	m32.handle = (unsigned long)handle;
    265  1.1  riastrad 	if (m32.handle != (unsigned long)handle)
    266  1.1  riastrad 		printk_ratelimited(KERN_ERR "compat_drm_addmap truncated handle"
    267  1.1  riastrad 				   " %p for type %d offset %x\n",
    268  1.1  riastrad 				   handle, m32.type, m32.offset);
    269  1.1  riastrad 
    270  1.1  riastrad 	if (copy_to_user(argp, &m32, sizeof(m32)))
    271  1.1  riastrad 		return -EFAULT;
    272  1.1  riastrad 
    273  1.1  riastrad 	return 0;
    274  1.1  riastrad }
    275  1.1  riastrad 
    276  1.1  riastrad static int compat_drm_rmmap(struct file *file, unsigned int cmd,
    277  1.1  riastrad 			    unsigned long arg)
    278  1.1  riastrad {
    279  1.1  riastrad 	drm_map32_t __user *argp = (void __user *)arg;
    280  1.1  riastrad 	struct drm_map __user *map;
    281  1.1  riastrad 	u32 handle;
    282  1.1  riastrad 
    283  1.1  riastrad 	if (get_user(handle, &argp->handle))
    284  1.1  riastrad 		return -EFAULT;
    285  1.1  riastrad 
    286  1.1  riastrad 	map = compat_alloc_user_space(sizeof(*map));
    287  1.2  riastrad 	if (!map)
    288  1.1  riastrad 		return -EFAULT;
    289  1.1  riastrad 	if (__put_user((void *)(unsigned long)handle, &map->handle))
    290  1.1  riastrad 		return -EFAULT;
    291  1.1  riastrad 
    292  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_RM_MAP, (unsigned long)map);
    293  1.1  riastrad }
    294  1.1  riastrad 
    295  1.1  riastrad typedef struct drm_client32 {
    296  1.1  riastrad 	int idx;	/**< Which client desired? */
    297  1.1  riastrad 	int auth;	/**< Is client authenticated? */
    298  1.1  riastrad 	u32 pid;	/**< Process ID */
    299  1.1  riastrad 	u32 uid;	/**< User ID */
    300  1.1  riastrad 	u32 magic;	/**< Magic */
    301  1.1  riastrad 	u32 iocs;	/**< Ioctl count */
    302  1.1  riastrad } drm_client32_t;
    303  1.1  riastrad 
    304  1.1  riastrad static int compat_drm_getclient(struct file *file, unsigned int cmd,
    305  1.1  riastrad 				unsigned long arg)
    306  1.1  riastrad {
    307  1.1  riastrad 	drm_client32_t c32;
    308  1.1  riastrad 	drm_client32_t __user *argp = (void __user *)arg;
    309  1.1  riastrad 	struct drm_client __user *client;
    310  1.1  riastrad 	int idx, err;
    311  1.1  riastrad 
    312  1.1  riastrad 	if (get_user(idx, &argp->idx))
    313  1.1  riastrad 		return -EFAULT;
    314  1.1  riastrad 
    315  1.1  riastrad 	client = compat_alloc_user_space(sizeof(*client));
    316  1.2  riastrad 	if (!client)
    317  1.1  riastrad 		return -EFAULT;
    318  1.1  riastrad 	if (__put_user(idx, &client->idx))
    319  1.1  riastrad 		return -EFAULT;
    320  1.1  riastrad 
    321  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_GET_CLIENT, (unsigned long)client);
    322  1.1  riastrad 	if (err)
    323  1.1  riastrad 		return err;
    324  1.1  riastrad 
    325  1.1  riastrad 	if (__get_user(c32.idx, &client->idx)
    326  1.1  riastrad 	    || __get_user(c32.auth, &client->auth)
    327  1.1  riastrad 	    || __get_user(c32.pid, &client->pid)
    328  1.1  riastrad 	    || __get_user(c32.uid, &client->uid)
    329  1.1  riastrad 	    || __get_user(c32.magic, &client->magic)
    330  1.1  riastrad 	    || __get_user(c32.iocs, &client->iocs))
    331  1.1  riastrad 		return -EFAULT;
    332  1.1  riastrad 
    333  1.1  riastrad 	if (copy_to_user(argp, &c32, sizeof(c32)))
    334  1.1  riastrad 		return -EFAULT;
    335  1.1  riastrad 	return 0;
    336  1.1  riastrad }
    337  1.1  riastrad 
    338  1.1  riastrad typedef struct drm_stats32 {
    339  1.1  riastrad 	u32 count;
    340  1.1  riastrad 	struct {
    341  1.1  riastrad 		u32 value;
    342  1.1  riastrad 		enum drm_stat_type type;
    343  1.1  riastrad 	} data[15];
    344  1.1  riastrad } drm_stats32_t;
    345  1.1  riastrad 
    346  1.1  riastrad static int compat_drm_getstats(struct file *file, unsigned int cmd,
    347  1.1  riastrad 			       unsigned long arg)
    348  1.1  riastrad {
    349  1.1  riastrad 	drm_stats32_t s32;
    350  1.1  riastrad 	drm_stats32_t __user *argp = (void __user *)arg;
    351  1.1  riastrad 	struct drm_stats __user *stats;
    352  1.1  riastrad 	int i, err;
    353  1.1  riastrad 
    354  1.1  riastrad 	stats = compat_alloc_user_space(sizeof(*stats));
    355  1.2  riastrad 	if (!stats)
    356  1.1  riastrad 		return -EFAULT;
    357  1.1  riastrad 
    358  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_GET_STATS, (unsigned long)stats);
    359  1.1  riastrad 	if (err)
    360  1.1  riastrad 		return err;
    361  1.1  riastrad 
    362  1.1  riastrad 	if (__get_user(s32.count, &stats->count))
    363  1.1  riastrad 		return -EFAULT;
    364  1.1  riastrad 	for (i = 0; i < 15; ++i)
    365  1.1  riastrad 		if (__get_user(s32.data[i].value, &stats->data[i].value)
    366  1.1  riastrad 		    || __get_user(s32.data[i].type, &stats->data[i].type))
    367  1.1  riastrad 			return -EFAULT;
    368  1.1  riastrad 
    369  1.1  riastrad 	if (copy_to_user(argp, &s32, sizeof(s32)))
    370  1.1  riastrad 		return -EFAULT;
    371  1.1  riastrad 	return 0;
    372  1.1  riastrad }
    373  1.1  riastrad 
    374  1.1  riastrad typedef struct drm_buf_desc32 {
    375  1.1  riastrad 	int count;		 /**< Number of buffers of this size */
    376  1.1  riastrad 	int size;		 /**< Size in bytes */
    377  1.1  riastrad 	int low_mark;		 /**< Low water mark */
    378  1.1  riastrad 	int high_mark;		 /**< High water mark */
    379  1.1  riastrad 	int flags;
    380  1.1  riastrad 	u32 agp_start;		 /**< Start address in the AGP aperture */
    381  1.1  riastrad } drm_buf_desc32_t;
    382  1.1  riastrad 
    383  1.1  riastrad static int compat_drm_addbufs(struct file *file, unsigned int cmd,
    384  1.1  riastrad 			      unsigned long arg)
    385  1.1  riastrad {
    386  1.1  riastrad 	drm_buf_desc32_t __user *argp = (void __user *)arg;
    387  1.1  riastrad 	struct drm_buf_desc __user *buf;
    388  1.1  riastrad 	int err;
    389  1.1  riastrad 	unsigned long agp_start;
    390  1.1  riastrad 
    391  1.1  riastrad 	buf = compat_alloc_user_space(sizeof(*buf));
    392  1.2  riastrad 	if (!buf || !access_ok(VERIFY_WRITE, argp, sizeof(*argp)))
    393  1.1  riastrad 		return -EFAULT;
    394  1.1  riastrad 
    395  1.1  riastrad 	if (__copy_in_user(buf, argp, offsetof(drm_buf_desc32_t, agp_start))
    396  1.1  riastrad 	    || __get_user(agp_start, &argp->agp_start)
    397  1.1  riastrad 	    || __put_user(agp_start, &buf->agp_start))
    398  1.1  riastrad 		return -EFAULT;
    399  1.1  riastrad 
    400  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_ADD_BUFS, (unsigned long)buf);
    401  1.1  riastrad 	if (err)
    402  1.1  riastrad 		return err;
    403  1.1  riastrad 
    404  1.1  riastrad 	if (__copy_in_user(argp, buf, offsetof(drm_buf_desc32_t, agp_start))
    405  1.1  riastrad 	    || __get_user(agp_start, &buf->agp_start)
    406  1.1  riastrad 	    || __put_user(agp_start, &argp->agp_start))
    407  1.1  riastrad 		return -EFAULT;
    408  1.1  riastrad 
    409  1.1  riastrad 	return 0;
    410  1.1  riastrad }
    411  1.1  riastrad 
    412  1.1  riastrad static int compat_drm_markbufs(struct file *file, unsigned int cmd,
    413  1.1  riastrad 			       unsigned long arg)
    414  1.1  riastrad {
    415  1.1  riastrad 	drm_buf_desc32_t b32;
    416  1.1  riastrad 	drm_buf_desc32_t __user *argp = (void __user *)arg;
    417  1.1  riastrad 	struct drm_buf_desc __user *buf;
    418  1.1  riastrad 
    419  1.1  riastrad 	if (copy_from_user(&b32, argp, sizeof(b32)))
    420  1.1  riastrad 		return -EFAULT;
    421  1.1  riastrad 
    422  1.1  riastrad 	buf = compat_alloc_user_space(sizeof(*buf));
    423  1.2  riastrad 	if (!buf)
    424  1.1  riastrad 		return -EFAULT;
    425  1.1  riastrad 
    426  1.1  riastrad 	if (__put_user(b32.size, &buf->size)
    427  1.1  riastrad 	    || __put_user(b32.low_mark, &buf->low_mark)
    428  1.1  riastrad 	    || __put_user(b32.high_mark, &buf->high_mark))
    429  1.1  riastrad 		return -EFAULT;
    430  1.1  riastrad 
    431  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_MARK_BUFS, (unsigned long)buf);
    432  1.1  riastrad }
    433  1.1  riastrad 
    434  1.1  riastrad typedef struct drm_buf_info32 {
    435  1.1  riastrad 	int count;		/**< Entries in list */
    436  1.1  riastrad 	u32 list;
    437  1.1  riastrad } drm_buf_info32_t;
    438  1.1  riastrad 
    439  1.1  riastrad static int compat_drm_infobufs(struct file *file, unsigned int cmd,
    440  1.1  riastrad 			       unsigned long arg)
    441  1.1  riastrad {
    442  1.1  riastrad 	drm_buf_info32_t req32;
    443  1.1  riastrad 	drm_buf_info32_t __user *argp = (void __user *)arg;
    444  1.1  riastrad 	drm_buf_desc32_t __user *to;
    445  1.1  riastrad 	struct drm_buf_info __user *request;
    446  1.1  riastrad 	struct drm_buf_desc __user *list;
    447  1.1  riastrad 	size_t nbytes;
    448  1.1  riastrad 	int i, err;
    449  1.1  riastrad 	int count, actual;
    450  1.1  riastrad 
    451  1.1  riastrad 	if (copy_from_user(&req32, argp, sizeof(req32)))
    452  1.1  riastrad 		return -EFAULT;
    453  1.1  riastrad 
    454  1.1  riastrad 	count = req32.count;
    455  1.1  riastrad 	to = (drm_buf_desc32_t __user *) (unsigned long)req32.list;
    456  1.1  riastrad 	if (count < 0)
    457  1.1  riastrad 		count = 0;
    458  1.1  riastrad 	if (count > 0
    459  1.1  riastrad 	    && !access_ok(VERIFY_WRITE, to, count * sizeof(drm_buf_desc32_t)))
    460  1.1  riastrad 		return -EFAULT;
    461  1.1  riastrad 
    462  1.1  riastrad 	nbytes = sizeof(*request) + count * sizeof(struct drm_buf_desc);
    463  1.1  riastrad 	request = compat_alloc_user_space(nbytes);
    464  1.2  riastrad 	if (!request)
    465  1.1  riastrad 		return -EFAULT;
    466  1.1  riastrad 	list = (struct drm_buf_desc *) (request + 1);
    467  1.1  riastrad 
    468  1.1  riastrad 	if (__put_user(count, &request->count)
    469  1.1  riastrad 	    || __put_user(list, &request->list))
    470  1.1  riastrad 		return -EFAULT;
    471  1.1  riastrad 
    472  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_INFO_BUFS, (unsigned long)request);
    473  1.1  riastrad 	if (err)
    474  1.1  riastrad 		return err;
    475  1.1  riastrad 
    476  1.1  riastrad 	if (__get_user(actual, &request->count))
    477  1.1  riastrad 		return -EFAULT;
    478  1.1  riastrad 	if (count >= actual)
    479  1.1  riastrad 		for (i = 0; i < actual; ++i)
    480  1.1  riastrad 			if (__copy_in_user(&to[i], &list[i],
    481  1.1  riastrad 					   offsetof(struct drm_buf_desc, flags)))
    482  1.1  riastrad 				return -EFAULT;
    483  1.1  riastrad 
    484  1.1  riastrad 	if (__put_user(actual, &argp->count))
    485  1.1  riastrad 		return -EFAULT;
    486  1.1  riastrad 
    487  1.1  riastrad 	return 0;
    488  1.1  riastrad }
    489  1.1  riastrad 
    490  1.1  riastrad typedef struct drm_buf_pub32 {
    491  1.1  riastrad 	int idx;		/**< Index into the master buffer list */
    492  1.1  riastrad 	int total;		/**< Buffer size */
    493  1.1  riastrad 	int used;		/**< Amount of buffer in use (for DMA) */
    494  1.1  riastrad 	u32 address;		/**< Address of buffer */
    495  1.1  riastrad } drm_buf_pub32_t;
    496  1.1  riastrad 
    497  1.1  riastrad typedef struct drm_buf_map32 {
    498  1.1  riastrad 	int count;		/**< Length of the buffer list */
    499  1.1  riastrad 	u32 virtual;		/**< Mmap'd area in user-virtual */
    500  1.1  riastrad 	u32 list;		/**< Buffer information */
    501  1.1  riastrad } drm_buf_map32_t;
    502  1.1  riastrad 
    503  1.1  riastrad static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
    504  1.1  riastrad 			      unsigned long arg)
    505  1.1  riastrad {
    506  1.1  riastrad 	drm_buf_map32_t __user *argp = (void __user *)arg;
    507  1.1  riastrad 	drm_buf_map32_t req32;
    508  1.1  riastrad 	drm_buf_pub32_t __user *list32;
    509  1.1  riastrad 	struct drm_buf_map __user *request;
    510  1.1  riastrad 	struct drm_buf_pub __user *list;
    511  1.1  riastrad 	int i, err;
    512  1.1  riastrad 	int count, actual;
    513  1.1  riastrad 	size_t nbytes;
    514  1.1  riastrad 	void __user *addr;
    515  1.1  riastrad 
    516  1.1  riastrad 	if (copy_from_user(&req32, argp, sizeof(req32)))
    517  1.1  riastrad 		return -EFAULT;
    518  1.1  riastrad 	count = req32.count;
    519  1.1  riastrad 	list32 = (void __user *)(unsigned long)req32.list;
    520  1.1  riastrad 
    521  1.1  riastrad 	if (count < 0)
    522  1.1  riastrad 		return -EINVAL;
    523  1.1  riastrad 	nbytes = sizeof(*request) + count * sizeof(struct drm_buf_pub);
    524  1.1  riastrad 	request = compat_alloc_user_space(nbytes);
    525  1.2  riastrad 	if (!request)
    526  1.1  riastrad 		return -EFAULT;
    527  1.1  riastrad 	list = (struct drm_buf_pub *) (request + 1);
    528  1.1  riastrad 
    529  1.1  riastrad 	if (__put_user(count, &request->count)
    530  1.1  riastrad 	    || __put_user(list, &request->list))
    531  1.1  riastrad 		return -EFAULT;
    532  1.1  riastrad 
    533  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_MAP_BUFS, (unsigned long)request);
    534  1.1  riastrad 	if (err)
    535  1.1  riastrad 		return err;
    536  1.1  riastrad 
    537  1.1  riastrad 	if (__get_user(actual, &request->count))
    538  1.1  riastrad 		return -EFAULT;
    539  1.1  riastrad 	if (count >= actual)
    540  1.1  riastrad 		for (i = 0; i < actual; ++i)
    541  1.1  riastrad 			if (__copy_in_user(&list32[i], &list[i],
    542  1.1  riastrad 					   offsetof(struct drm_buf_pub, address))
    543  1.1  riastrad 			    || __get_user(addr, &list[i].address)
    544  1.1  riastrad 			    || __put_user((unsigned long)addr,
    545  1.1  riastrad 					  &list32[i].address))
    546  1.1  riastrad 				return -EFAULT;
    547  1.1  riastrad 
    548  1.1  riastrad 	if (__put_user(actual, &argp->count)
    549  1.1  riastrad 	    || __get_user(addr, &request->virtual)
    550  1.1  riastrad 	    || __put_user((unsigned long)addr, &argp->virtual))
    551  1.1  riastrad 		return -EFAULT;
    552  1.1  riastrad 
    553  1.1  riastrad 	return 0;
    554  1.1  riastrad }
    555  1.1  riastrad 
    556  1.1  riastrad typedef struct drm_buf_free32 {
    557  1.1  riastrad 	int count;
    558  1.1  riastrad 	u32 list;
    559  1.1  riastrad } drm_buf_free32_t;
    560  1.1  riastrad 
    561  1.1  riastrad static int compat_drm_freebufs(struct file *file, unsigned int cmd,
    562  1.1  riastrad 			       unsigned long arg)
    563  1.1  riastrad {
    564  1.1  riastrad 	drm_buf_free32_t req32;
    565  1.1  riastrad 	struct drm_buf_free __user *request;
    566  1.1  riastrad 	drm_buf_free32_t __user *argp = (void __user *)arg;
    567  1.1  riastrad 
    568  1.1  riastrad 	if (copy_from_user(&req32, argp, sizeof(req32)))
    569  1.1  riastrad 		return -EFAULT;
    570  1.1  riastrad 
    571  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    572  1.2  riastrad 	if (!request)
    573  1.1  riastrad 		return -EFAULT;
    574  1.1  riastrad 	if (__put_user(req32.count, &request->count)
    575  1.1  riastrad 	    || __put_user((int __user *)(unsigned long)req32.list,
    576  1.1  riastrad 			  &request->list))
    577  1.1  riastrad 		return -EFAULT;
    578  1.1  riastrad 
    579  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_FREE_BUFS, (unsigned long)request);
    580  1.1  riastrad }
    581  1.1  riastrad 
    582  1.1  riastrad typedef struct drm_ctx_priv_map32 {
    583  1.1  riastrad 	unsigned int ctx_id;	 /**< Context requesting private mapping */
    584  1.1  riastrad 	u32 handle;		/**< Handle of map */
    585  1.1  riastrad } drm_ctx_priv_map32_t;
    586  1.1  riastrad 
    587  1.1  riastrad static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
    588  1.1  riastrad 				  unsigned long arg)
    589  1.1  riastrad {
    590  1.1  riastrad 	drm_ctx_priv_map32_t req32;
    591  1.1  riastrad 	struct drm_ctx_priv_map __user *request;
    592  1.1  riastrad 	drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
    593  1.1  riastrad 
    594  1.1  riastrad 	if (copy_from_user(&req32, argp, sizeof(req32)))
    595  1.1  riastrad 		return -EFAULT;
    596  1.1  riastrad 
    597  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    598  1.2  riastrad 	if (!request)
    599  1.1  riastrad 		return -EFAULT;
    600  1.1  riastrad 	if (__put_user(req32.ctx_id, &request->ctx_id)
    601  1.1  riastrad 	    || __put_user((void *)(unsigned long)req32.handle,
    602  1.1  riastrad 			  &request->handle))
    603  1.1  riastrad 		return -EFAULT;
    604  1.1  riastrad 
    605  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_SET_SAREA_CTX, (unsigned long)request);
    606  1.1  riastrad }
    607  1.1  riastrad 
    608  1.1  riastrad static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
    609  1.1  riastrad 				  unsigned long arg)
    610  1.1  riastrad {
    611  1.1  riastrad 	struct drm_ctx_priv_map __user *request;
    612  1.1  riastrad 	drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
    613  1.1  riastrad 	int err;
    614  1.1  riastrad 	unsigned int ctx_id;
    615  1.1  riastrad 	void *handle;
    616  1.1  riastrad 
    617  1.1  riastrad 	if (!access_ok(VERIFY_WRITE, argp, sizeof(*argp))
    618  1.1  riastrad 	    || __get_user(ctx_id, &argp->ctx_id))
    619  1.1  riastrad 		return -EFAULT;
    620  1.1  riastrad 
    621  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    622  1.2  riastrad 	if (!request)
    623  1.1  riastrad 		return -EFAULT;
    624  1.1  riastrad 	if (__put_user(ctx_id, &request->ctx_id))
    625  1.1  riastrad 		return -EFAULT;
    626  1.1  riastrad 
    627  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_GET_SAREA_CTX, (unsigned long)request);
    628  1.1  riastrad 	if (err)
    629  1.1  riastrad 		return err;
    630  1.1  riastrad 
    631  1.1  riastrad 	if (__get_user(handle, &request->handle)
    632  1.1  riastrad 	    || __put_user((unsigned long)handle, &argp->handle))
    633  1.1  riastrad 		return -EFAULT;
    634  1.1  riastrad 
    635  1.1  riastrad 	return 0;
    636  1.1  riastrad }
    637  1.1  riastrad 
    638  1.1  riastrad typedef struct drm_ctx_res32 {
    639  1.1  riastrad 	int count;
    640  1.1  riastrad 	u32 contexts;
    641  1.1  riastrad } drm_ctx_res32_t;
    642  1.1  riastrad 
    643  1.1  riastrad static int compat_drm_resctx(struct file *file, unsigned int cmd,
    644  1.1  riastrad 			     unsigned long arg)
    645  1.1  riastrad {
    646  1.1  riastrad 	drm_ctx_res32_t __user *argp = (void __user *)arg;
    647  1.1  riastrad 	drm_ctx_res32_t res32;
    648  1.1  riastrad 	struct drm_ctx_res __user *res;
    649  1.1  riastrad 	int err;
    650  1.1  riastrad 
    651  1.1  riastrad 	if (copy_from_user(&res32, argp, sizeof(res32)))
    652  1.1  riastrad 		return -EFAULT;
    653  1.1  riastrad 
    654  1.1  riastrad 	res = compat_alloc_user_space(sizeof(*res));
    655  1.2  riastrad 	if (!res)
    656  1.1  riastrad 		return -EFAULT;
    657  1.1  riastrad 	if (__put_user(res32.count, &res->count)
    658  1.1  riastrad 	    || __put_user((struct drm_ctx __user *) (unsigned long)res32.contexts,
    659  1.1  riastrad 			  &res->contexts))
    660  1.1  riastrad 		return -EFAULT;
    661  1.1  riastrad 
    662  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_RES_CTX, (unsigned long)res);
    663  1.1  riastrad 	if (err)
    664  1.1  riastrad 		return err;
    665  1.1  riastrad 
    666  1.1  riastrad 	if (__get_user(res32.count, &res->count)
    667  1.1  riastrad 	    || __put_user(res32.count, &argp->count))
    668  1.1  riastrad 		return -EFAULT;
    669  1.1  riastrad 
    670  1.1  riastrad 	return 0;
    671  1.1  riastrad }
    672  1.1  riastrad 
    673  1.1  riastrad typedef struct drm_dma32 {
    674  1.1  riastrad 	int context;		  /**< Context handle */
    675  1.1  riastrad 	int send_count;		  /**< Number of buffers to send */
    676  1.1  riastrad 	u32 send_indices;	  /**< List of handles to buffers */
    677  1.1  riastrad 	u32 send_sizes;		  /**< Lengths of data to send */
    678  1.1  riastrad 	enum drm_dma_flags flags;		  /**< Flags */
    679  1.1  riastrad 	int request_count;	  /**< Number of buffers requested */
    680  1.1  riastrad 	int request_size;	  /**< Desired size for buffers */
    681  1.1  riastrad 	u32 request_indices;	  /**< Buffer information */
    682  1.1  riastrad 	u32 request_sizes;
    683  1.1  riastrad 	int granted_count;	  /**< Number of buffers granted */
    684  1.1  riastrad } drm_dma32_t;
    685  1.1  riastrad 
    686  1.1  riastrad static int compat_drm_dma(struct file *file, unsigned int cmd,
    687  1.1  riastrad 			  unsigned long arg)
    688  1.1  riastrad {
    689  1.1  riastrad 	drm_dma32_t d32;
    690  1.1  riastrad 	drm_dma32_t __user *argp = (void __user *)arg;
    691  1.1  riastrad 	struct drm_dma __user *d;
    692  1.1  riastrad 	int err;
    693  1.1  riastrad 
    694  1.1  riastrad 	if (copy_from_user(&d32, argp, sizeof(d32)))
    695  1.1  riastrad 		return -EFAULT;
    696  1.1  riastrad 
    697  1.1  riastrad 	d = compat_alloc_user_space(sizeof(*d));
    698  1.2  riastrad 	if (!d)
    699  1.1  riastrad 		return -EFAULT;
    700  1.1  riastrad 
    701  1.1  riastrad 	if (__put_user(d32.context, &d->context)
    702  1.1  riastrad 	    || __put_user(d32.send_count, &d->send_count)
    703  1.1  riastrad 	    || __put_user((int __user *)(unsigned long)d32.send_indices,
    704  1.1  riastrad 			  &d->send_indices)
    705  1.1  riastrad 	    || __put_user((int __user *)(unsigned long)d32.send_sizes,
    706  1.1  riastrad 			  &d->send_sizes)
    707  1.1  riastrad 	    || __put_user(d32.flags, &d->flags)
    708  1.1  riastrad 	    || __put_user(d32.request_count, &d->request_count)
    709  1.1  riastrad 	    || __put_user((int __user *)(unsigned long)d32.request_indices,
    710  1.1  riastrad 			  &d->request_indices)
    711  1.1  riastrad 	    || __put_user((int __user *)(unsigned long)d32.request_sizes,
    712  1.1  riastrad 			  &d->request_sizes))
    713  1.1  riastrad 		return -EFAULT;
    714  1.1  riastrad 
    715  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_DMA, (unsigned long)d);
    716  1.1  riastrad 	if (err)
    717  1.1  riastrad 		return err;
    718  1.1  riastrad 
    719  1.1  riastrad 	if (__get_user(d32.request_size, &d->request_size)
    720  1.1  riastrad 	    || __get_user(d32.granted_count, &d->granted_count)
    721  1.1  riastrad 	    || __put_user(d32.request_size, &argp->request_size)
    722  1.1  riastrad 	    || __put_user(d32.granted_count, &argp->granted_count))
    723  1.1  riastrad 		return -EFAULT;
    724  1.1  riastrad 
    725  1.1  riastrad 	return 0;
    726  1.1  riastrad }
    727  1.1  riastrad 
    728  1.2  riastrad #if IS_ENABLED(CONFIG_AGP)
    729  1.1  riastrad typedef struct drm_agp_mode32 {
    730  1.1  riastrad 	u32 mode;	/**< AGP mode */
    731  1.1  riastrad } drm_agp_mode32_t;
    732  1.1  riastrad 
    733  1.1  riastrad static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
    734  1.1  riastrad 				 unsigned long arg)
    735  1.1  riastrad {
    736  1.1  riastrad 	drm_agp_mode32_t __user *argp = (void __user *)arg;
    737  1.1  riastrad 	drm_agp_mode32_t m32;
    738  1.1  riastrad 	struct drm_agp_mode __user *mode;
    739  1.1  riastrad 
    740  1.1  riastrad 	if (get_user(m32.mode, &argp->mode))
    741  1.1  riastrad 		return -EFAULT;
    742  1.1  riastrad 
    743  1.1  riastrad 	mode = compat_alloc_user_space(sizeof(*mode));
    744  1.1  riastrad 	if (put_user(m32.mode, &mode->mode))
    745  1.1  riastrad 		return -EFAULT;
    746  1.1  riastrad 
    747  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_AGP_ENABLE, (unsigned long)mode);
    748  1.1  riastrad }
    749  1.1  riastrad 
    750  1.1  riastrad typedef struct drm_agp_info32 {
    751  1.1  riastrad 	int agp_version_major;
    752  1.1  riastrad 	int agp_version_minor;
    753  1.1  riastrad 	u32 mode;
    754  1.1  riastrad 	u32 aperture_base;	/* physical address */
    755  1.1  riastrad 	u32 aperture_size;	/* bytes */
    756  1.1  riastrad 	u32 memory_allowed;	/* bytes */
    757  1.1  riastrad 	u32 memory_used;
    758  1.1  riastrad 
    759  1.1  riastrad 	/* PCI information */
    760  1.1  riastrad 	unsigned short id_vendor;
    761  1.1  riastrad 	unsigned short id_device;
    762  1.1  riastrad } drm_agp_info32_t;
    763  1.1  riastrad 
    764  1.1  riastrad static int compat_drm_agp_info(struct file *file, unsigned int cmd,
    765  1.1  riastrad 			       unsigned long arg)
    766  1.1  riastrad {
    767  1.1  riastrad 	drm_agp_info32_t __user *argp = (void __user *)arg;
    768  1.1  riastrad 	drm_agp_info32_t i32;
    769  1.1  riastrad 	struct drm_agp_info __user *info;
    770  1.1  riastrad 	int err;
    771  1.1  riastrad 
    772  1.1  riastrad 	info = compat_alloc_user_space(sizeof(*info));
    773  1.2  riastrad 	if (!info)
    774  1.1  riastrad 		return -EFAULT;
    775  1.1  riastrad 
    776  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_AGP_INFO, (unsigned long)info);
    777  1.1  riastrad 	if (err)
    778  1.1  riastrad 		return err;
    779  1.1  riastrad 
    780  1.1  riastrad 	if (__get_user(i32.agp_version_major, &info->agp_version_major)
    781  1.1  riastrad 	    || __get_user(i32.agp_version_minor, &info->agp_version_minor)
    782  1.1  riastrad 	    || __get_user(i32.mode, &info->mode)
    783  1.1  riastrad 	    || __get_user(i32.aperture_base, &info->aperture_base)
    784  1.1  riastrad 	    || __get_user(i32.aperture_size, &info->aperture_size)
    785  1.1  riastrad 	    || __get_user(i32.memory_allowed, &info->memory_allowed)
    786  1.1  riastrad 	    || __get_user(i32.memory_used, &info->memory_used)
    787  1.1  riastrad 	    || __get_user(i32.id_vendor, &info->id_vendor)
    788  1.1  riastrad 	    || __get_user(i32.id_device, &info->id_device))
    789  1.1  riastrad 		return -EFAULT;
    790  1.1  riastrad 
    791  1.1  riastrad 	if (copy_to_user(argp, &i32, sizeof(i32)))
    792  1.1  riastrad 		return -EFAULT;
    793  1.1  riastrad 
    794  1.1  riastrad 	return 0;
    795  1.1  riastrad }
    796  1.1  riastrad 
    797  1.1  riastrad typedef struct drm_agp_buffer32 {
    798  1.1  riastrad 	u32 size;	/**< In bytes -- will round to page boundary */
    799  1.1  riastrad 	u32 handle;	/**< Used for binding / unbinding */
    800  1.1  riastrad 	u32 type;	/**< Type of memory to allocate */
    801  1.1  riastrad 	u32 physical;	/**< Physical used by i810 */
    802  1.1  riastrad } drm_agp_buffer32_t;
    803  1.1  riastrad 
    804  1.1  riastrad static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
    805  1.1  riastrad 				unsigned long arg)
    806  1.1  riastrad {
    807  1.1  riastrad 	drm_agp_buffer32_t __user *argp = (void __user *)arg;
    808  1.1  riastrad 	drm_agp_buffer32_t req32;
    809  1.1  riastrad 	struct drm_agp_buffer __user *request;
    810  1.1  riastrad 	int err;
    811  1.1  riastrad 
    812  1.1  riastrad 	if (copy_from_user(&req32, argp, sizeof(req32)))
    813  1.1  riastrad 		return -EFAULT;
    814  1.1  riastrad 
    815  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    816  1.2  riastrad 	if (!request
    817  1.1  riastrad 	    || __put_user(req32.size, &request->size)
    818  1.1  riastrad 	    || __put_user(req32.type, &request->type))
    819  1.1  riastrad 		return -EFAULT;
    820  1.1  riastrad 
    821  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_AGP_ALLOC, (unsigned long)request);
    822  1.1  riastrad 	if (err)
    823  1.1  riastrad 		return err;
    824  1.1  riastrad 
    825  1.1  riastrad 	if (__get_user(req32.handle, &request->handle)
    826  1.1  riastrad 	    || __get_user(req32.physical, &request->physical)
    827  1.1  riastrad 	    || copy_to_user(argp, &req32, sizeof(req32))) {
    828  1.1  riastrad 		drm_ioctl(file, DRM_IOCTL_AGP_FREE, (unsigned long)request);
    829  1.1  riastrad 		return -EFAULT;
    830  1.1  riastrad 	}
    831  1.1  riastrad 
    832  1.1  riastrad 	return 0;
    833  1.1  riastrad }
    834  1.1  riastrad 
    835  1.1  riastrad static int compat_drm_agp_free(struct file *file, unsigned int cmd,
    836  1.1  riastrad 			       unsigned long arg)
    837  1.1  riastrad {
    838  1.1  riastrad 	drm_agp_buffer32_t __user *argp = (void __user *)arg;
    839  1.1  riastrad 	struct drm_agp_buffer __user *request;
    840  1.1  riastrad 	u32 handle;
    841  1.1  riastrad 
    842  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    843  1.2  riastrad 	if (!request
    844  1.1  riastrad 	    || get_user(handle, &argp->handle)
    845  1.1  riastrad 	    || __put_user(handle, &request->handle))
    846  1.1  riastrad 		return -EFAULT;
    847  1.1  riastrad 
    848  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_AGP_FREE, (unsigned long)request);
    849  1.1  riastrad }
    850  1.1  riastrad 
    851  1.1  riastrad typedef struct drm_agp_binding32 {
    852  1.1  riastrad 	u32 handle;	/**< From drm_agp_buffer */
    853  1.1  riastrad 	u32 offset;	/**< In bytes -- will round to page boundary */
    854  1.1  riastrad } drm_agp_binding32_t;
    855  1.1  riastrad 
    856  1.1  riastrad static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
    857  1.1  riastrad 			       unsigned long arg)
    858  1.1  riastrad {
    859  1.1  riastrad 	drm_agp_binding32_t __user *argp = (void __user *)arg;
    860  1.1  riastrad 	drm_agp_binding32_t req32;
    861  1.1  riastrad 	struct drm_agp_binding __user *request;
    862  1.1  riastrad 
    863  1.1  riastrad 	if (copy_from_user(&req32, argp, sizeof(req32)))
    864  1.1  riastrad 		return -EFAULT;
    865  1.1  riastrad 
    866  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    867  1.2  riastrad 	if (!request
    868  1.1  riastrad 	    || __put_user(req32.handle, &request->handle)
    869  1.1  riastrad 	    || __put_user(req32.offset, &request->offset))
    870  1.1  riastrad 		return -EFAULT;
    871  1.1  riastrad 
    872  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_AGP_BIND, (unsigned long)request);
    873  1.1  riastrad }
    874  1.1  riastrad 
    875  1.1  riastrad static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
    876  1.1  riastrad 				 unsigned long arg)
    877  1.1  riastrad {
    878  1.1  riastrad 	drm_agp_binding32_t __user *argp = (void __user *)arg;
    879  1.1  riastrad 	struct drm_agp_binding __user *request;
    880  1.1  riastrad 	u32 handle;
    881  1.1  riastrad 
    882  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    883  1.2  riastrad 	if (!request
    884  1.1  riastrad 	    || get_user(handle, &argp->handle)
    885  1.1  riastrad 	    || __put_user(handle, &request->handle))
    886  1.1  riastrad 		return -EFAULT;
    887  1.1  riastrad 
    888  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_AGP_UNBIND, (unsigned long)request);
    889  1.1  riastrad }
    890  1.2  riastrad #endif /* CONFIG_AGP */
    891  1.1  riastrad 
    892  1.1  riastrad typedef struct drm_scatter_gather32 {
    893  1.1  riastrad 	u32 size;	/**< In bytes -- will round to page boundary */
    894  1.1  riastrad 	u32 handle;	/**< Used for mapping / unmapping */
    895  1.1  riastrad } drm_scatter_gather32_t;
    896  1.1  riastrad 
    897  1.1  riastrad static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
    898  1.1  riastrad 			       unsigned long arg)
    899  1.1  riastrad {
    900  1.1  riastrad 	drm_scatter_gather32_t __user *argp = (void __user *)arg;
    901  1.1  riastrad 	struct drm_scatter_gather __user *request;
    902  1.1  riastrad 	int err;
    903  1.1  riastrad 	unsigned long x;
    904  1.1  riastrad 
    905  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    906  1.2  riastrad 	if (!request || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
    907  1.1  riastrad 	    || __get_user(x, &argp->size)
    908  1.1  riastrad 	    || __put_user(x, &request->size))
    909  1.1  riastrad 		return -EFAULT;
    910  1.1  riastrad 
    911  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_SG_ALLOC, (unsigned long)request);
    912  1.1  riastrad 	if (err)
    913  1.1  riastrad 		return err;
    914  1.1  riastrad 
    915  1.1  riastrad 	/* XXX not sure about the handle conversion here... */
    916  1.1  riastrad 	if (__get_user(x, &request->handle)
    917  1.1  riastrad 	    || __put_user(x >> PAGE_SHIFT, &argp->handle))
    918  1.1  riastrad 		return -EFAULT;
    919  1.1  riastrad 
    920  1.1  riastrad 	return 0;
    921  1.1  riastrad }
    922  1.1  riastrad 
    923  1.1  riastrad static int compat_drm_sg_free(struct file *file, unsigned int cmd,
    924  1.1  riastrad 			      unsigned long arg)
    925  1.1  riastrad {
    926  1.1  riastrad 	drm_scatter_gather32_t __user *argp = (void __user *)arg;
    927  1.1  riastrad 	struct drm_scatter_gather __user *request;
    928  1.1  riastrad 	unsigned long x;
    929  1.1  riastrad 
    930  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    931  1.2  riastrad 	if (!request || !access_ok(VERIFY_WRITE, argp, sizeof(*argp))
    932  1.1  riastrad 	    || __get_user(x, &argp->handle)
    933  1.1  riastrad 	    || __put_user(x << PAGE_SHIFT, &request->handle))
    934  1.1  riastrad 		return -EFAULT;
    935  1.1  riastrad 
    936  1.1  riastrad 	return drm_ioctl(file, DRM_IOCTL_SG_FREE, (unsigned long)request);
    937  1.1  riastrad }
    938  1.1  riastrad 
    939  1.1  riastrad #if defined(CONFIG_X86) || defined(CONFIG_IA64)
    940  1.1  riastrad typedef struct drm_update_draw32 {
    941  1.1  riastrad 	drm_drawable_t handle;
    942  1.1  riastrad 	unsigned int type;
    943  1.1  riastrad 	unsigned int num;
    944  1.1  riastrad 	/* 64-bit version has a 32-bit pad here */
    945  1.1  riastrad 	u64 data;	/**< Pointer */
    946  1.1  riastrad } __attribute__((packed)) drm_update_draw32_t;
    947  1.1  riastrad 
    948  1.1  riastrad static int compat_drm_update_draw(struct file *file, unsigned int cmd,
    949  1.1  riastrad 				  unsigned long arg)
    950  1.1  riastrad {
    951  1.1  riastrad 	drm_update_draw32_t update32;
    952  1.1  riastrad 	struct drm_update_draw __user *request;
    953  1.1  riastrad 	int err;
    954  1.1  riastrad 
    955  1.1  riastrad 	if (copy_from_user(&update32, (void __user *)arg, sizeof(update32)))
    956  1.1  riastrad 		return -EFAULT;
    957  1.1  riastrad 
    958  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
    959  1.2  riastrad 	if (!request ||
    960  1.1  riastrad 	    __put_user(update32.handle, &request->handle) ||
    961  1.1  riastrad 	    __put_user(update32.type, &request->type) ||
    962  1.1  riastrad 	    __put_user(update32.num, &request->num) ||
    963  1.1  riastrad 	    __put_user(update32.data, &request->data))
    964  1.1  riastrad 		return -EFAULT;
    965  1.1  riastrad 
    966  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_UPDATE_DRAW, (unsigned long)request);
    967  1.1  riastrad 	return err;
    968  1.1  riastrad }
    969  1.1  riastrad #endif
    970  1.1  riastrad 
    971  1.1  riastrad struct drm_wait_vblank_request32 {
    972  1.1  riastrad 	enum drm_vblank_seq_type type;
    973  1.1  riastrad 	unsigned int sequence;
    974  1.1  riastrad 	u32 signal;
    975  1.1  riastrad };
    976  1.1  riastrad 
    977  1.1  riastrad struct drm_wait_vblank_reply32 {
    978  1.1  riastrad 	enum drm_vblank_seq_type type;
    979  1.1  riastrad 	unsigned int sequence;
    980  1.1  riastrad 	s32 tval_sec;
    981  1.1  riastrad 	s32 tval_usec;
    982  1.1  riastrad };
    983  1.1  riastrad 
    984  1.1  riastrad typedef union drm_wait_vblank32 {
    985  1.1  riastrad 	struct drm_wait_vblank_request32 request;
    986  1.1  riastrad 	struct drm_wait_vblank_reply32 reply;
    987  1.1  riastrad } drm_wait_vblank32_t;
    988  1.1  riastrad 
    989  1.1  riastrad static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
    990  1.1  riastrad 				  unsigned long arg)
    991  1.1  riastrad {
    992  1.1  riastrad 	drm_wait_vblank32_t __user *argp = (void __user *)arg;
    993  1.1  riastrad 	drm_wait_vblank32_t req32;
    994  1.1  riastrad 	union drm_wait_vblank __user *request;
    995  1.1  riastrad 	int err;
    996  1.1  riastrad 
    997  1.1  riastrad 	if (copy_from_user(&req32, argp, sizeof(req32)))
    998  1.1  riastrad 		return -EFAULT;
    999  1.1  riastrad 
   1000  1.1  riastrad 	request = compat_alloc_user_space(sizeof(*request));
   1001  1.2  riastrad 	if (!request
   1002  1.1  riastrad 	    || __put_user(req32.request.type, &request->request.type)
   1003  1.1  riastrad 	    || __put_user(req32.request.sequence, &request->request.sequence)
   1004  1.1  riastrad 	    || __put_user(req32.request.signal, &request->request.signal))
   1005  1.1  riastrad 		return -EFAULT;
   1006  1.1  riastrad 
   1007  1.1  riastrad 	err = drm_ioctl(file, DRM_IOCTL_WAIT_VBLANK, (unsigned long)request);
   1008  1.1  riastrad 	if (err)
   1009  1.1  riastrad 		return err;
   1010  1.1  riastrad 
   1011  1.1  riastrad 	if (__get_user(req32.reply.type, &request->reply.type)
   1012  1.1  riastrad 	    || __get_user(req32.reply.sequence, &request->reply.sequence)
   1013  1.1  riastrad 	    || __get_user(req32.reply.tval_sec, &request->reply.tval_sec)
   1014  1.1  riastrad 	    || __get_user(req32.reply.tval_usec, &request->reply.tval_usec))
   1015  1.1  riastrad 		return -EFAULT;
   1016  1.1  riastrad 
   1017  1.1  riastrad 	if (copy_to_user(argp, &req32, sizeof(req32)))
   1018  1.1  riastrad 		return -EFAULT;
   1019  1.1  riastrad 
   1020  1.1  riastrad 	return 0;
   1021  1.1  riastrad }
   1022  1.1  riastrad 
   1023  1.2  riastrad #if defined(CONFIG_X86) || defined(CONFIG_IA64)
   1024  1.2  riastrad typedef struct drm_mode_fb_cmd232 {
   1025  1.2  riastrad 	u32 fb_id;
   1026  1.2  riastrad 	u32 width;
   1027  1.2  riastrad 	u32 height;
   1028  1.2  riastrad 	u32 pixel_format;
   1029  1.2  riastrad 	u32 flags;
   1030  1.2  riastrad 	u32 handles[4];
   1031  1.2  riastrad 	u32 pitches[4];
   1032  1.2  riastrad 	u32 offsets[4];
   1033  1.2  riastrad 	u64 modifier[4];
   1034  1.2  riastrad } __attribute__((packed)) drm_mode_fb_cmd232_t;
   1035  1.2  riastrad 
   1036  1.2  riastrad static int compat_drm_mode_addfb2(struct file *file, unsigned int cmd,
   1037  1.2  riastrad 				  unsigned long arg)
   1038  1.2  riastrad {
   1039  1.2  riastrad 	struct drm_mode_fb_cmd232 __user *argp = (void __user *)arg;
   1040  1.2  riastrad 	struct drm_mode_fb_cmd232 req32;
   1041  1.2  riastrad 	struct drm_mode_fb_cmd2 __user *req64;
   1042  1.2  riastrad 	int i;
   1043  1.2  riastrad 	int err;
   1044  1.2  riastrad 
   1045  1.2  riastrad 	if (copy_from_user(&req32, argp, sizeof(req32)))
   1046  1.2  riastrad 		return -EFAULT;
   1047  1.2  riastrad 
   1048  1.2  riastrad 	req64 = compat_alloc_user_space(sizeof(*req64));
   1049  1.2  riastrad 
   1050  1.2  riastrad 	if (!access_ok(VERIFY_WRITE, req64, sizeof(*req64))
   1051  1.2  riastrad 	    || __put_user(req32.width, &req64->width)
   1052  1.2  riastrad 	    || __put_user(req32.height, &req64->height)
   1053  1.2  riastrad 	    || __put_user(req32.pixel_format, &req64->pixel_format)
   1054  1.2  riastrad 	    || __put_user(req32.flags, &req64->flags))
   1055  1.2  riastrad 		return -EFAULT;
   1056  1.2  riastrad 
   1057  1.2  riastrad 	for (i = 0; i < 4; i++) {
   1058  1.2  riastrad 		if (__put_user(req32.handles[i], &req64->handles[i]))
   1059  1.2  riastrad 			return -EFAULT;
   1060  1.2  riastrad 		if (__put_user(req32.pitches[i], &req64->pitches[i]))
   1061  1.2  riastrad 			return -EFAULT;
   1062  1.2  riastrad 		if (__put_user(req32.offsets[i], &req64->offsets[i]))
   1063  1.2  riastrad 			return -EFAULT;
   1064  1.2  riastrad 		if (__put_user(req32.modifier[i], &req64->modifier[i]))
   1065  1.2  riastrad 			return -EFAULT;
   1066  1.2  riastrad 	}
   1067  1.2  riastrad 
   1068  1.2  riastrad 	err = drm_ioctl(file, DRM_IOCTL_MODE_ADDFB2, (unsigned long)req64);
   1069  1.2  riastrad 	if (err)
   1070  1.2  riastrad 		return err;
   1071  1.2  riastrad 
   1072  1.2  riastrad 	if (__get_user(req32.fb_id, &req64->fb_id))
   1073  1.2  riastrad 		return -EFAULT;
   1074  1.2  riastrad 
   1075  1.2  riastrad 	if (copy_to_user(argp, &req32, sizeof(req32)))
   1076  1.2  riastrad 		return -EFAULT;
   1077  1.2  riastrad 
   1078  1.2  riastrad 	return 0;
   1079  1.2  riastrad }
   1080  1.2  riastrad #endif
   1081  1.2  riastrad 
   1082  1.2  riastrad static drm_ioctl_compat_t *drm_compat_ioctls[] = {
   1083  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
   1084  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
   1085  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
   1086  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT32)] = compat_drm_getclient,
   1087  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_GET_STATS32)] = compat_drm_getstats,
   1088  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE32)] = compat_drm_setunique,
   1089  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP32)] = compat_drm_addmap,
   1090  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS32)] = compat_drm_addbufs,
   1091  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS32)] = compat_drm_markbufs,
   1092  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS32)] = compat_drm_infobufs,
   1093  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS32)] = compat_drm_mapbufs,
   1094  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS32)] = compat_drm_freebufs,
   1095  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_RM_MAP32)] = compat_drm_rmmap,
   1096  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX32)] = compat_drm_setsareactx,
   1097  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX32)] = compat_drm_getsareactx,
   1098  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_RES_CTX32)] = compat_drm_resctx,
   1099  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_DMA32)] = compat_drm_dma,
   1100  1.2  riastrad #if IS_ENABLED(CONFIG_AGP)
   1101  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE32)] = compat_drm_agp_enable,
   1102  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO32)] = compat_drm_agp_info,
   1103  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC32)] = compat_drm_agp_alloc,
   1104  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE32)] = compat_drm_agp_free,
   1105  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND32)] = compat_drm_agp_bind,
   1106  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND32)] = compat_drm_agp_unbind,
   1107  1.1  riastrad #endif
   1108  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC32)] = compat_drm_sg_alloc,
   1109  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_SG_FREE32)] = compat_drm_sg_free,
   1110  1.1  riastrad #if defined(CONFIG_X86) || defined(CONFIG_IA64)
   1111  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_UPDATE_DRAW32)] = compat_drm_update_draw,
   1112  1.1  riastrad #endif
   1113  1.1  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK32)] = compat_drm_wait_vblank,
   1114  1.2  riastrad #if defined(CONFIG_X86) || defined(CONFIG_IA64)
   1115  1.2  riastrad 	[DRM_IOCTL_NR(DRM_IOCTL_MODE_ADDFB232)] = compat_drm_mode_addfb2,
   1116  1.2  riastrad #endif
   1117  1.1  riastrad };
   1118  1.1  riastrad 
   1119  1.1  riastrad /**
   1120  1.1  riastrad  * Called whenever a 32-bit process running under a 64-bit kernel
   1121  1.1  riastrad  * performs an ioctl on /dev/drm.
   1122  1.1  riastrad  *
   1123  1.1  riastrad  * \param file_priv DRM file private.
   1124  1.1  riastrad  * \param cmd command.
   1125  1.1  riastrad  * \param arg user argument.
   1126  1.1  riastrad  * \return zero on success or negative number on failure.
   1127  1.1  riastrad  */
   1128  1.1  riastrad long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
   1129  1.1  riastrad {
   1130  1.1  riastrad 	unsigned int nr = DRM_IOCTL_NR(cmd);
   1131  1.1  riastrad 	drm_ioctl_compat_t *fn;
   1132  1.1  riastrad 	int ret;
   1133  1.1  riastrad 
   1134  1.1  riastrad 	/* Assume that ioctls without an explicit compat routine will just
   1135  1.1  riastrad 	 * work.  This may not always be a good assumption, but it's better
   1136  1.1  riastrad 	 * than always failing.
   1137  1.1  riastrad 	 */
   1138  1.1  riastrad 	if (nr >= ARRAY_SIZE(drm_compat_ioctls))
   1139  1.1  riastrad 		return drm_ioctl(filp, cmd, arg);
   1140  1.1  riastrad 
   1141  1.1  riastrad 	fn = drm_compat_ioctls[nr];
   1142  1.1  riastrad 
   1143  1.1  riastrad 	if (fn != NULL)
   1144  1.1  riastrad 		ret = (*fn) (filp, cmd, arg);
   1145  1.1  riastrad 	else
   1146  1.1  riastrad 		ret = drm_ioctl(filp, cmd, arg);
   1147  1.1  riastrad 
   1148  1.1  riastrad 	return ret;
   1149  1.1  riastrad }
   1150  1.1  riastrad 
   1151  1.1  riastrad EXPORT_SYMBOL(drm_compat_ioctl);
   1152