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