Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_drm.c revision 1.3
      1  1.3  christos /*	$NetBSD: netbsd32_drm.c,v 1.3 2019/08/20 14:26:05 christos Exp $ */
      2  1.1  christos 
      3  1.1  christos /*
      4  1.2  christos  * Copyright (c) 2019 The NetBSD Foundation, Inc.
      5  1.2  christos  * All rights reserved.
      6  1.2  christos  *
      7  1.1  christos  * This code was written by Surya Shankar for GSoC 2019.
      8  1.1  christos  *
      9  1.1  christos  * Redistribution and use in source and binary forms, with or without
     10  1.1  christos  * modification, are permitted provided that the following conditions
     11  1.1  christos  * are met:
     12  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     13  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     14  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  christos  *    documentation and/or other materials provided with the distribution.
     17  1.1  christos  *
     18  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1  christos  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1  christos  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1  christos  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1  christos  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  1.1  christos  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  1.1  christos  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  1.1  christos  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  1.1  christos  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  1.1  christos  * SUCH DAMAGE.
     29  1.1  christos  */
     30  1.1  christos 
     31  1.1  christos #include <sys/cdefs.h>
     32  1.3  christos __KERNEL_RCSID(0, "$NetBSD: netbsd32_drm.c,v 1.3 2019/08/20 14:26:05 christos Exp $");
     33  1.1  christos 
     34  1.1  christos #include <compat/netbsd32/netbsd32.h>
     35  1.1  christos #include <compat/netbsd32/netbsd32_ioctl.h>
     36  1.1  christos 
     37  1.1  christos #include <linux/types.h>
     38  1.1  christos #include <drm/drmP.h>
     39  1.1  christos 
     40  1.1  christos #define DRM_IOCTL_VERSION32		DRM_IOWR(0x00, drm_version32_t)
     41  1.1  christos #define DRM_IOCTL_GET_UNIQUE32		DRM_IOWR(0x01, drm_unique32_t)
     42  1.1  christos #define DRM_IOCTL_GET_MAP32		DRM_IOWR(0x04, drm_map32_t)
     43  1.1  christos #define DRM_IOCTL_GET_CLIENT32		DRM_IOWR(0x05, drm_client32_t)
     44  1.1  christos #define DRM_IOCTL_GET_STATS32		DRM_IOR( 0x06, drm_stats32_t)
     45  1.1  christos 
     46  1.1  christos #define DRM_IOCTL_SET_UNIQUE32		DRM_IOW( 0x10, drm_unique32_t)
     47  1.1  christos #define DRM_IOCTL_ADD_MAP32		DRM_IOWR(0x15, drm_map32_t)
     48  1.1  christos #define DRM_IOCTL_ADD_BUFS32		DRM_IOWR(0x16, drm_buf_desc32_t)
     49  1.1  christos #define DRM_IOCTL_MARK_BUFS32		DRM_IOW( 0x17, drm_buf_desc32_t)
     50  1.1  christos #define DRM_IOCTL_INFO_BUFS32		DRM_IOWR(0x18, drm_buf_info32_t)
     51  1.1  christos #define DRM_IOCTL_MAP_BUFS32		DRM_IOWR(0x19, drm_buf_map32_t)
     52  1.1  christos #define DRM_IOCTL_FREE_BUFS32		DRM_IOW( 0x1a, drm_buf_free32_t)
     53  1.1  christos 
     54  1.1  christos #define DRM_IOCTL_RM_MAP32		DRM_IOW( 0x1b, drm_map32_t)
     55  1.1  christos 
     56  1.1  christos #define DRM_IOCTL_SET_SAREA_CTX32	DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
     57  1.1  christos #define DRM_IOCTL_GET_SAREA_CTX32	DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
     58  1.1  christos 
     59  1.1  christos #define DRM_IOCTL_RES_CTX32		DRM_IOWR(0x26, drm_ctx_res32_t)
     60  1.1  christos #define DRM_IOCTL_DMA32			DRM_IOWR(0x29, drm_dma32_t)
     61  1.1  christos 
     62  1.1  christos #define DRM_IOCTL_AGP_ENABLE32		DRM_IOW( 0x32, drm_agp_mode32_t)
     63  1.1  christos #define DRM_IOCTL_AGP_INFO32		DRM_IOR( 0x33, drm_agp_info32_t)
     64  1.1  christos #define DRM_IOCTL_AGP_ALLOC32		DRM_IOWR(0x34, drm_agp_buffer32_t)
     65  1.1  christos #define DRM_IOCTL_AGP_FREE32		DRM_IOW( 0x35, drm_agp_buffer32_t)
     66  1.1  christos #define DRM_IOCTL_AGP_BIND32		DRM_IOW( 0x36, drm_agp_binding32_t)
     67  1.1  christos #define DRM_IOCTL_AGP_UNBIND32		DRM_IOW( 0x37, drm_agp_binding32_t)
     68  1.1  christos 
     69  1.1  christos #define DRM_IOCTL_SG_ALLOC32		DRM_IOW( 0x38, drm_scatter_gather32_t)
     70  1.1  christos #define DRM_IOCTL_SG_FREE32		DRM_IOW( 0x39, drm_scatter_gather32_t)
     71  1.1  christos 
     72  1.1  christos #define DRM_IOCTL_UPDATE_DRAW32		DRM_IOW( 0x3f, drm_update_draw32_t)
     73  1.1  christos 
     74  1.1  christos #define DRM_IOCTL_WAIT_VBLANK32		DRM_IOWR(0x3a, drm_wait_vblank32_t)
     75  1.1  christos 
     76  1.1  christos #define DRM_IOCTL_MODE_ADDFB232		DRM_IOWR(0xb8, drm_mode_fb_cmd232_t)
     77  1.1  christos 
     78  1.1  christos // Compat DRM Version Implementation
     79  1.1  christos 
     80  1.1  christos typedef struct {
     81  1.1  christos 	int version_major;		/**< Major version */
     82  1.1  christos 	int version_minor;		/**< Minor version */
     83  1.1  christos 	int version_patchlevel;		/**< Patch level */
     84  1.1  christos 	uint32_t name_len;		/**< Length of name buffer */
     85  1.1  christos 	netbsd32_pointer_t name;	/**< Name of driver */
     86  1.1  christos 	uint32_t date_len;		/**< Length of date buffer */
     87  1.1  christos 	netbsd32_pointer_t date;	/**< User-space buffer to hold date */
     88  1.1  christos 	uint32_t desc_len;		/**< Length of desc buffer */
     89  1.1  christos 	netbsd32_pointer_t desc;	/**< User-space buffer to hold desc */
     90  1.1  christos } drm_version32_t;
     91  1.1  christos 
     92  1.1  christos static int
     93  1.1  christos compat_drm_version(struct file *file, void *arg)
     94  1.1  christos {
     95  1.1  christos 	drm_version32_t v32;
     96  1.1  christos 	struct drm_version v64;
     97  1.1  christos 	int error;
     98  1.1  christos 
     99  1.1  christos 	if ((error = copyin(&v32, arg, sizeof(v32))) != 0)
    100  1.1  christos 		return error;
    101  1.1  christos 
    102  1.1  christos 	v64.name_len = v32.name_len;
    103  1.1  christos 	v64.name = NETBSD32PTR64(v32.name);
    104  1.1  christos 	v64.date_len = v32.date_len;
    105  1.1  christos 	v64.date = NETBSD32PTR64(v32.date);
    106  1.1  christos 	v64.desc_len = v32.desc_len;
    107  1.1  christos 	v64.desc = NETBSD32PTR64(v32.desc);
    108  1.1  christos 
    109  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_VERSION, &v64);
    110  1.1  christos 	if (error)
    111  1.1  christos 		return error;
    112  1.1  christos 
    113  1.1  christos 	v32.version_major = v64.version_major;
    114  1.1  christos 	v32.version_minor = v64.version_minor;
    115  1.1  christos 	v32.version_patchlevel = v64.version_patchlevel;
    116  1.1  christos 	/* strings have already been copied in place */
    117  1.1  christos 	v32.name_len = v64.name_len;
    118  1.1  christos 	v32.date_len = v64.date_len;
    119  1.1  christos 	v32.desc_len = v64.desc_len;
    120  1.1  christos 
    121  1.1  christos 	return copyout(arg, &v32, sizeof(v32));
    122  1.1  christos }
    123  1.1  christos 
    124  1.1  christos typedef struct drm_unique32 {
    125  1.1  christos 	uint32_t unique_len;
    126  1.1  christos 	netbsd32_pointer_t unique;
    127  1.1  christos } drm_unique32_t;
    128  1.1  christos 
    129  1.1  christos static int
    130  1.1  christos compat_drm_getunique(struct file *file, void *arg)
    131  1.1  christos {
    132  1.1  christos 	drm_unique32_t uq32;
    133  1.1  christos 	struct drm_unique uq64;
    134  1.1  christos 	int error;
    135  1.1  christos 
    136  1.1  christos 	if ((error = copyin(&uq32, arg, sizeof(uq32))) != 0)
    137  1.1  christos 		return error;
    138  1.1  christos 
    139  1.1  christos 	uq64.unique_len = uq32.unique_len;
    140  1.1  christos 	uq64.unique = NETBSD32PTR64(uq32.unique);
    141  1.1  christos 
    142  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_GET_UNIQUE, &uq64);
    143  1.1  christos 	if (error)
    144  1.1  christos 		return error;
    145  1.1  christos 
    146  1.1  christos 	//unique should already be copied
    147  1.1  christos 	uq32.unique_len = uq64.unique_len;
    148  1.1  christos 
    149  1.1  christos 	if ((error = copyout(arg, &uq32, sizeof(uq32))) != 0)
    150  1.1  christos 		return error;
    151  1.1  christos 
    152  1.1  christos 	return 0;
    153  1.1  christos }
    154  1.1  christos 
    155  1.1  christos static int
    156  1.1  christos compat_drm_setunique(struct file *file, void *arg)
    157  1.1  christos {
    158  1.1  christos 	drm_unique32_t uq32;
    159  1.1  christos 	struct drm_unique uq64;
    160  1.1  christos 	int error;
    161  1.1  christos 
    162  1.1  christos 	if ((error = copyin(&uq32, arg, sizeof(uq32))) != 0)
    163  1.1  christos 		return error;
    164  1.1  christos 
    165  1.1  christos 	uq64.unique_len = uq32.unique_len;
    166  1.1  christos 	uq64.unique = NETBSD32PTR64(uq32.unique);
    167  1.1  christos 
    168  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_SET_UNIQUE, &uq64);
    169  1.1  christos 	if (error)
    170  1.1  christos 		return error;
    171  1.1  christos 
    172  1.1  christos 	// XXX: do we need copyout and copying the fields here?
    173  1.1  christos 	uq32.unique_len = uq64.unique_len;
    174  1.1  christos 	NETBSD32PTR32(uq32.unique, uq64.unique);
    175  1.1  christos 
    176  1.1  christos 	return error;
    177  1.1  christos }
    178  1.1  christos 
    179  1.1  christos typedef struct drm_map32 {
    180  1.1  christos 	uint32_t offset;	  /**< Req. physical address (0 for SAREA) */
    181  1.1  christos 	uint32_t size;		  /**< Requested physical size (bytes) */
    182  1.1  christos 	enum drm_map_type type;	  /**< Type of memory to map */
    183  1.1  christos 	enum drm_map_flags flags; /**< Flags */
    184  1.1  christos 	netbsd32_pointer_t handle;/**< User-space: "Handle" to pass to mmap() */
    185  1.1  christos 	int mtrr;		  /**< MTRR slot used */
    186  1.1  christos } drm_map32_t;
    187  1.1  christos 
    188  1.1  christos static void
    189  1.1  christos map32to64(struct drm_map *m64, const drm_map32_t *m32)
    190  1.1  christos {
    191  1.1  christos 	m64->offset = m32->offset;
    192  1.1  christos 	m64->size = m32->size;
    193  1.1  christos 	m64->type = m32->type;
    194  1.1  christos 	m64->flags = m32->flags;
    195  1.1  christos 	m64->handle = NETBSD32PTR64(m32->handle);
    196  1.1  christos 	m64->mtrr = m32->mtrr;
    197  1.1  christos }
    198  1.1  christos 
    199  1.1  christos static void
    200  1.1  christos map64to32(drm_map32_t *m32, const struct drm_map *m64)
    201  1.1  christos {
    202  1.1  christos 	m32->offset = m64->offset;
    203  1.1  christos 	m32->size = m64->size;
    204  1.1  christos 	m32->type = m64->type;
    205  1.1  christos 	m32->flags = m64->flags;
    206  1.1  christos 	NETBSD32PTR32(m32->handle, m64->handle);
    207  1.1  christos 	m32->mtrr = m64->mtrr;
    208  1.1  christos }
    209  1.1  christos 
    210  1.1  christos static int
    211  1.1  christos compat_drm_getmap(struct file *file, void *arg)
    212  1.1  christos {
    213  1.1  christos 	drm_map32_t m32;
    214  1.1  christos 	struct drm_map m64;
    215  1.1  christos 	int error;
    216  1.1  christos 
    217  1.1  christos 	if ((error = copyin(&m32, arg, sizeof(m32))) != 0)
    218  1.1  christos 		return error;
    219  1.1  christos 
    220  1.1  christos 	map32to64(&m64, &m32);
    221  1.1  christos 
    222  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_GET_MAP, &m64);
    223  1.1  christos 	if (error)
    224  1.1  christos 		return error;
    225  1.1  christos 
    226  1.1  christos 	map64to32(&m32, &m64);
    227  1.1  christos 
    228  1.1  christos 	return copyout(arg, &m32, sizeof(m32));
    229  1.1  christos }
    230  1.1  christos 
    231  1.1  christos static int
    232  1.1  christos compat_drm_addmap(struct file *file, void *arg)
    233  1.1  christos {
    234  1.1  christos 	drm_map32_t m32;
    235  1.1  christos 	struct drm_map m64;
    236  1.1  christos 	int error;
    237  1.1  christos 
    238  1.1  christos 	if ((error = copyin(&m32, arg, sizeof(m32))) != 0)
    239  1.1  christos 		return error;
    240  1.1  christos 
    241  1.1  christos 	map32to64(&m64, &m32);
    242  1.1  christos 
    243  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_ADD_MAP, &m64);
    244  1.1  christos 	if (error)
    245  1.1  christos 		return error;
    246  1.1  christos 
    247  1.1  christos 	map64to32(&m32, &m64);
    248  1.1  christos 
    249  1.1  christos 	return copyout(arg, &m32, sizeof(m32));
    250  1.1  christos }
    251  1.1  christos 
    252  1.1  christos 
    253  1.1  christos static int
    254  1.1  christos compat_drm_rmmap(struct file *file, void *arg)
    255  1.1  christos {
    256  1.1  christos 	drm_map32_t m32;
    257  1.1  christos 	struct drm_map m64;
    258  1.1  christos 	int error;
    259  1.1  christos 	if ((error = copyin(&m32, arg, sizeof(m32))) != 0)
    260  1.1  christos 		return error;
    261  1.1  christos 
    262  1.1  christos 	map32to64(&m64, &m32);
    263  1.1  christos 
    264  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_RM_MAP, &m64);
    265  1.1  christos 	if (error)
    266  1.1  christos 		return error;
    267  1.1  christos 
    268  1.1  christos 	map64to32(&m32, &m64);
    269  1.1  christos 
    270  1.1  christos 	return copyout(arg, &m32, sizeof(m32));
    271  1.1  christos }
    272  1.1  christos 
    273  1.1  christos typedef struct drm_client32 {
    274  1.1  christos 	int idx;	/**< Which client desired? */
    275  1.1  christos 	int auth;	/**< Is client authenticated? */
    276  1.1  christos 	uint32_t pid;	/**< Process ID */
    277  1.1  christos 	uint32_t uid;	/**< User ID */
    278  1.1  christos 	uint32_t magic; /**< Magic */
    279  1.1  christos 	uint32_t iocs;	/**< Ioctl count */
    280  1.1  christos } drm_client32_t;
    281  1.1  christos 
    282  1.1  christos static void
    283  1.1  christos client32to64(struct drm_client *c64, const drm_client32_t *c32)
    284  1.1  christos {
    285  1.1  christos 	c64->idx = c32->idx;
    286  1.1  christos 	c64->auth = c32->auth;
    287  1.1  christos 	c64->pid = c32->pid;
    288  1.1  christos 	c64->uid = c32->uid;
    289  1.1  christos 	c64->iocs = c64->iocs;
    290  1.1  christos }
    291  1.1  christos 
    292  1.1  christos static void
    293  1.1  christos client64to32(drm_client32_t *c32, const struct drm_client *c64)
    294  1.1  christos {
    295  1.1  christos 	c32->idx = c64->idx;
    296  1.1  christos 	c32->auth = c64->auth;
    297  1.1  christos 	c32->pid = c64->pid;
    298  1.1  christos 	c32->uid = c64->uid;
    299  1.1  christos 	c32->iocs = c64->iocs;
    300  1.1  christos }
    301  1.1  christos static int
    302  1.1  christos compat_drm_getclient(struct file *file, void *arg)
    303  1.1  christos {
    304  1.1  christos 	drm_client32_t c32;
    305  1.1  christos 	struct drm_client c64;
    306  1.1  christos 	int error;
    307  1.1  christos 
    308  1.1  christos 	if ((error = copyin(&c32, arg, sizeof(c32))) != 0)
    309  1.1  christos 		return error;
    310  1.1  christos 
    311  1.1  christos 	client32to64(&c64, &c32);
    312  1.1  christos 
    313  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_GET_CLIENT, &c64);
    314  1.1  christos 	if (error)
    315  1.1  christos 		return error;
    316  1.1  christos 
    317  1.1  christos 	client64to32(&c32, &c64);
    318  1.1  christos 
    319  1.1  christos 	return copyout(arg, &c32, sizeof(c32));
    320  1.1  christos }
    321  1.1  christos 
    322  1.1  christos typedef struct drm_stats32 {
    323  1.1  christos 	uint32_t count;
    324  1.1  christos 	struct {
    325  1.1  christos 		uint32_t value;
    326  1.1  christos 		enum drm_stat_type type;
    327  1.1  christos 	} data[15];
    328  1.1  christos } drm_stats32_t;
    329  1.1  christos 
    330  1.1  christos static int
    331  1.1  christos compat_drm_getstats(struct file *file, void *arg)
    332  1.1  christos {
    333  1.1  christos 	drm_stats32_t st32;
    334  1.1  christos 	struct drm_stats st64;
    335  1.1  christos 	int error;
    336  1.1  christos 
    337  1.1  christos 	if ((error = copyin(&st32, arg, sizeof(st32))) != 0)
    338  1.1  christos 		return error;
    339  1.1  christos 
    340  1.1  christos 	st64.count = st32.count;
    341  1.3  christos 	if (st64.count > __arraycount(st64.data))
    342  1.3  christos 		return EINVAL;
    343  1.1  christos 
    344  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_GET_STATS, &st64);
    345  1.1  christos 	if (error)
    346  1.1  christos 		return error;
    347  1.1  christos 
    348  1.3  christos 	for (int i = 0; i < st64.count; ++i) {
    349  1.3  christos 		st32.data[i].value = st64.data[i].value;
    350  1.3  christos 		st32.data[i].type = st64.data[i].type;
    351  1.1  christos 	}
    352  1.3  christos 	st32.count = st64.count;
    353  1.1  christos 
    354  1.1  christos 	return copyout(arg, &st32, sizeof(s32));
    355  1.1  christos }
    356  1.1  christos 
    357  1.1  christos typedef struct drm_buf_desc32 {
    358  1.1  christos 	int count;		 /**< Number of buffers of this size */
    359  1.1  christos 	int size;		 /**< Size in bytes */
    360  1.1  christos 	int low_mark;		 /**< Low water mark */
    361  1.1  christos 	int high_mark;		 /**< High water mark */
    362  1.1  christos 	int flags;
    363  1.1  christos 	netbsd32_pointer_t agp_start;
    364  1.1  christos 				/**< Start address in the AGP aperture */
    365  1.1  christos } drm_buf_desc32_t;
    366  1.1  christos 
    367  1.1  christos static int
    368  1.1  christos compat_drm_addbufs(struct file *file, void *arg)
    369  1.1  christos {
    370  1.1  christos 	drm_buf_desc32_t buf32;
    371  1.1  christos 	struct drm_buf_desc buf64;
    372  1.1  christos 	int error;
    373  1.1  christos 
    374  1.1  christos 	if ((error = copyin(&buf32, arg, sizeof(buf32))) != 0)
    375  1.1  christos 		return error;
    376  1.1  christos 
    377  1.1  christos 	// XXX: assign 32->64
    378  1.1  christos 	buf64.agp_start = (unsigned long)NETBSD32PTR64(buf32.agp_start);
    379  1.1  christos 
    380  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_ADD_BUFS, &buf64);
    381  1.1  christos 	if (error)
    382  1.1  christos 		return error;
    383  1.1  christos 
    384  1.1  christos 	// XXX assign 64->32
    385  1.1  christos 	NETBSD32PTR32(buf32.agp_start, (void *)buf64.agp_start);
    386  1.1  christos 
    387  1.1  christos 	return copyout(&buf32, arg, sizeof(buf32));
    388  1.1  christos }
    389  1.1  christos 
    390  1.1  christos static int
    391  1.1  christos compat_drm_markbufs(struct file *file, void *arg)
    392  1.1  christos {
    393  1.1  christos 	drm_buf_desc32_t b32;
    394  1.1  christos 	struct drm_buf_desc b64;
    395  1.1  christos 	int error;
    396  1.1  christos 
    397  1.1  christos 	if ((error = copyin(&b32, arg, sizeof(b32))) != 0)
    398  1.1  christos 		return error;
    399  1.1  christos 
    400  1.1  christos 	b64.size = b32.size;
    401  1.1  christos 	b64.low_mark = b32.low_mark;
    402  1.1  christos 	b64.high_mark = b32.high_mark;
    403  1.1  christos 	//XXX: more stuff?
    404  1.1  christos 
    405  1.1  christos 	return drm_ioctl(file, DRM_IOCTL_MARK_BUFS, &b64);
    406  1.1  christos }
    407  1.1  christos 
    408  1.1  christos typedef struct drm_buf_info32 {
    409  1.1  christos 	int count;		 /**< Entries in list */
    410  1.1  christos 	netbsd32_pointer_t list;
    411  1.1  christos } drm_buf_info32_t;
    412  1.1  christos 
    413  1.1  christos typedef struct drm_buf_pub32 {
    414  1.1  christos 	int idx;		 /**< Index into the master buffer list */
    415  1.1  christos 	int total;		 /**< Buffer size */
    416  1.1  christos 	int used;		 /**< Amount of buffer in use (for DMA) */
    417  1.1  christos 	uint32_t address;	 /**< Address of buffer */
    418  1.1  christos } drm_buf_pub32_t;
    419  1.1  christos 
    420  1.1  christos typedef struct drm_buf_map32 {
    421  1.1  christos 	int count;		 /**< Length of the buffer list */
    422  1.1  christos 	uint32_t virtual;	 /**< Mmap'd area in user-virtual */
    423  1.1  christos 	netbsd32_pointer_t list; /**< Buffer information */
    424  1.1  christos } drm_buf_map32_t;
    425  1.1  christos 
    426  1.1  christos 
    427  1.1  christos typedef struct drm_buf_free32 {
    428  1.1  christos 	int count;
    429  1.1  christos 	netbsd32_pointer_t list;
    430  1.1  christos } drm_buf_free32_t;
    431  1.1  christos 
    432  1.1  christos static int
    433  1.1  christos compat_drm_freebufs(struct file *file, void *arg)
    434  1.1  christos {
    435  1.1  christos 	drm_buf_free32_t req32;
    436  1.1  christos 	struct drm_buf_free req64;
    437  1.1  christos 	int error;
    438  1.1  christos 
    439  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
    440  1.1  christos 		return error;
    441  1.1  christos 
    442  1.1  christos 	req64.count = req32.count;
    443  1.1  christos 	req64.list = NETBSD32PTR64(req32.list);
    444  1.1  christos 
    445  1.1  christos 	return drm_ioctl(file, DRM_IOCTL_FREE_BUFS, &req64);
    446  1.1  christos }
    447  1.1  christos 
    448  1.1  christos typedef struct drm_ctx_priv_map32 {
    449  1.1  christos 	unsigned int ctx_id;		 /**< Context requesting private mapping */
    450  1.1  christos 	netbsd32_pointer_t handle;	 /**< Handle of map */
    451  1.1  christos } drm_ctx_priv_map32_t;
    452  1.1  christos 
    453  1.1  christos static int
    454  1.1  christos compat_drm_setsareactx(struct file *file, void *arg)
    455  1.1  christos {
    456  1.1  christos 	drm_ctx_priv_map32_t req32;
    457  1.1  christos 	struct drm_ctx_priv_map req64;
    458  1.1  christos 	int error;
    459  1.1  christos 
    460  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
    461  1.1  christos 		return error;
    462  1.1  christos 
    463  1.1  christos 	req64.ctx_id = req32.ctx_id;
    464  1.1  christos 	req64.handle = NETBSD32PTR64(req32.handle);
    465  1.1  christos 
    466  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_SET_SAREA_CTX, &req64);
    467  1.1  christos 	if(error)
    468  1.1  christos 		return error;
    469  1.1  christos 
    470  1.1  christos 	req32.ctx_id = req64.ctx_id;
    471  1.1  christos 	NETBSD32PTR32(req32.handle, req64.handle);
    472  1.1  christos 
    473  1.1  christos 	return 0;
    474  1.1  christos }
    475  1.1  christos 
    476  1.1  christos static int
    477  1.1  christos compat_drm_getsareactx(struct file *file, void *arg)
    478  1.1  christos {
    479  1.1  christos 	struct drm_ctx_priv_map req64;
    480  1.1  christos 	drm_ctx_priv_map32_t req32;
    481  1.1  christos 	int error;
    482  1.1  christos 
    483  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
    484  1.1  christos 		return error;
    485  1.1  christos 
    486  1.1  christos 	req64.ctx_id = req32.ctx_id;
    487  1.1  christos 
    488  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_GET_SAREA_CTX, &req64);
    489  1.1  christos 	if (error)
    490  1.1  christos 		return error;
    491  1.1  christos 
    492  1.1  christos 	NETBSD32PTR32(req32.handle, req64.handle);
    493  1.1  christos 	// XXX: missing copyout?
    494  1.1  christos 
    495  1.1  christos 	return copyout(arg, &req32, sizeof(req32));
    496  1.1  christos }
    497  1.1  christos 
    498  1.1  christos typedef struct drm_ctx_res32 {
    499  1.1  christos 	int count;
    500  1.1  christos 	netbsd32_pointer_t contexts;
    501  1.1  christos } drm_ctx_res32_t;
    502  1.1  christos 
    503  1.1  christos static int
    504  1.1  christos compat_drm_resctx(struct file *file, void *arg)
    505  1.1  christos {
    506  1.1  christos 	drm_ctx_res32_t res32;
    507  1.1  christos 	struct drm_ctx_res res64;
    508  1.1  christos 	int error;
    509  1.1  christos 
    510  1.1  christos 	if ((error = copyin(&res32, arg, sizeof(res32))) != 0)
    511  1.1  christos 		return error;
    512  1.1  christos 
    513  1.1  christos 	res64.count = res32.count;
    514  1.1  christos 	res64.contexts = NETBSD32PTR64(res32.contexts);
    515  1.1  christos 
    516  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_RES_CTX, &res64);
    517  1.1  christos 	if (error)
    518  1.1  christos 		return error;
    519  1.1  christos 
    520  1.1  christos 	res32.count = res64.count;
    521  1.1  christos 	NETBSD32PTR32(res32.contexts, res64.contexts);
    522  1.1  christos 	/* XXX: missing copyout */
    523  1.1  christos 
    524  1.1  christos 	return copyout(arg, &res32, sizeof(res32));
    525  1.1  christos }
    526  1.1  christos 
    527  1.1  christos typedef struct drm_dma32 {
    528  1.1  christos 	int context;			  /**< Context handle */
    529  1.1  christos 	int send_count;			  /**< Number of buffers to send */
    530  1.1  christos 	netbsd32_pointer_t send_indices;  /**< List of handles to buffers */
    531  1.1  christos 	netbsd32_pointer_t send_sizes;	  /**< Lengths of data to send */
    532  1.1  christos 	enum drm_dma_flags flags;	  /**< Flags */
    533  1.1  christos 	netbsd32_pointer_t request_count; /**< Number of buffers requested */
    534  1.1  christos 	int request_size;		  /**< Desired size for buffers */
    535  1.1  christos 	netbsd32_pointer_t request_indices; /**< Buffer information */
    536  1.1  christos 	netbsd32_pointer_t request_sizes;
    537  1.1  christos 	int granted_count;		  /**< Number of buffers granted */
    538  1.1  christos } drm_dma32_t;
    539  1.1  christos 
    540  1.1  christos static void
    541  1.1  christos dma64to32(drm_dma32_t *d32, const struct drm_dma *d64)
    542  1.1  christos {
    543  1.1  christos 	d32->send_count = d64->send_count;
    544  1.1  christos 	NETBSD32PTR32(d32->send_indices, d64->send_indices);
    545  1.1  christos 	NETBSD32PTR32(d32->send_sizes, d64->send_sizes);
    546  1.1  christos 	d32->flags = d64->flags;
    547  1.1  christos 	NETBSD32PTR32(d32->request_count, (void *)(long)d64->request_count);
    548  1.1  christos 	NETBSD32PTR32(d32->request_indices, d64->request_indices);
    549  1.1  christos 	NETBSD32PTR32(d32->request_sizes, d64->request_sizes);
    550  1.1  christos 
    551  1.1  christos }
    552  1.1  christos 
    553  1.1  christos static void
    554  1.1  christos dma32to64(struct drm_dma *d64, const drm_dma32_t *d32)
    555  1.1  christos {
    556  1.1  christos 	d64->request_size = d32->request_size;
    557  1.1  christos 	d64->granted_count = d32->granted_count;
    558  1.1  christos }
    559  1.1  christos 
    560  1.1  christos static int
    561  1.1  christos compat_drm_dma(struct file *file, void *arg)
    562  1.1  christos {
    563  1.1  christos 	drm_dma32_t d32;
    564  1.1  christos 	struct drm_dma d64;
    565  1.1  christos 	int error;
    566  1.1  christos 
    567  1.1  christos 	if ((error = copyin(&d32, arg, sizeof(d32))) != 0)
    568  1.1  christos 		return error;
    569  1.1  christos 
    570  1.3  christos 	dma32to64(&d64, &d32);
    571  1.1  christos 
    572  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_DMA, &d64);
    573  1.1  christos 	if (error)
    574  1.1  christos 		return error;
    575  1.1  christos 
    576  1.3  christos 	dma64to32(&d32, &d64);
    577  1.1  christos 
    578  1.3  christos 	return copyout(arg, &d32, sizeof(d32));
    579  1.1  christos }
    580  1.1  christos 
    581  1.1  christos //XXX:i commented the below line for later use
    582  1.1  christos #if IS_ENABLED(CONFIG_AGP)
    583  1.1  christos typedef struct drm_agp_mode32 {
    584  1.1  christos 	uint32_t mode;	/**< AGP mode */
    585  1.1  christos } drm_agp_mode32_t;
    586  1.1  christos 
    587  1.1  christos static int
    588  1.1  christos compat_drm_agp_enable(struct file *file, void *arg)
    589  1.1  christos {
    590  1.1  christos 	drm_agp_mode32_t m32;
    591  1.1  christos 	struct drm_agp_mode m64;
    592  1.1  christos 	int error;
    593  1.1  christos 
    594  1.1  christos 	if ((error = copyin(&m32, arg, sizeof(m32))) != 0)
    595  1.1  christos 		return error;
    596  1.1  christos 
    597  1.3  christos 	m64.mode = m32.mode;
    598  1.1  christos 
    599  1.1  christos 	return drm_ioctl(file, DRM_IOCTL_AGP_ENABLE, &m64);
    600  1.1  christos }
    601  1.1  christos 
    602  1.1  christos typedef struct drm_agp_info32 {
    603  1.1  christos 	int agp_version_major;
    604  1.1  christos 	int agp_version_minor;
    605  1.1  christos 	uint32_t mode;
    606  1.1  christos 	uint32_t aperture_base;		/* physical address */
    607  1.1  christos 	uint32_t aperture_size;		/* bytes */
    608  1.1  christos 	uint32_t memory_allowed;	/* bytes */
    609  1.1  christos 	uint32_t memory_used;
    610  1.1  christos 
    611  1.1  christos 	/* PCI information */
    612  1.1  christos 	unsigned short id_vendor;
    613  1.1  christos 	unsigned short id_device;
    614  1.1  christos } drm_agp_info32_t;
    615  1.1  christos 
    616  1.1  christos static void
    617  1.3  christos info64to32(drm_agp_info32_t *i32, const struct drm_agp_info *i64)
    618  1.1  christos {
    619  1.3  christos 	i32->agp_version_major = i64->agp_version_major;
    620  1.3  christos 	i32->agp_version_minor = i64->agp_version_minor;
    621  1.3  christos 	i32->mode = i64->mode;
    622  1.3  christos 	i32->aperture_base = i64->aperture_base;
    623  1.3  christos 	i32->aperture_size = i64->aperture_size;
    624  1.3  christos 	i32->memory_allowed = i64->memory_allowed;
    625  1.3  christos 	i32->memory_used = i64->memory_used;
    626  1.3  christos 	i32->id_vendor = i64->id_vendor;
    627  1.3  christos 	i32->id_device = i64->id_device;
    628  1.1  christos }
    629  1.1  christos 
    630  1.1  christos static int
    631  1.1  christos compat_drm_agp_info(struct file *file, void *arg)
    632  1.1  christos {
    633  1.1  christos 	drm_agp_info32_t i32;
    634  1.1  christos 	struct drm_agp_info i64;
    635  1.1  christos 	int error;
    636  1.1  christos 
    637  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_AGP_INFO, &i64);
    638  1.1  christos 	if (error)
    639  1.1  christos 		return error;
    640  1.1  christos 
    641  1.3  christos 	info64to32(&i32, &i64);
    642  1.1  christos 
    643  1.1  christos 	return copyout(arg, &i32, sizeof(i32));
    644  1.1  christos 
    645  1.1  christos }
    646  1.1  christos 
    647  1.1  christos typedef struct drm_agp_buffer32 {
    648  1.1  christos 	uint32_t size;		/**< In bytes -- will round to page boundary */
    649  1.1  christos 	uint32_t handle;	/**< Used for binding / unbinding */
    650  1.1  christos 	uint32_t type;		/**< Type of memory to allocate */
    651  1.1  christos 	uint32_t physical;	/**< Physical used by i810 */
    652  1.1  christos } drm_agp_buffer32_t;
    653  1.1  christos 
    654  1.1  christos static int
    655  1.1  christos compat_drm_agp_alloc(struct file *file, void *arg)
    656  1.1  christos {
    657  1.1  christos 	drm_agp_buffer32_t req32;
    658  1.1  christos 	struct drm_agp_buffer req64;
    659  1.1  christos 	int error;
    660  1.1  christos 
    661  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
    662  1.1  christos 		return error;
    663  1.1  christos 
    664  1.1  christos 	req64.size = req32.size;
    665  1.1  christos 	req64.type = req32.type;
    666  1.1  christos 
    667  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_AGP_ALLOC, &req64);
    668  1.1  christos 	if (error)
    669  1.1  christos 		return error;
    670  1.1  christos 
    671  1.1  christos 	req32.handle = req64.handle;
    672  1.1  christos 	req32.physical = req64.physical;
    673  1.1  christos 
    674  1.1  christos 	drm_ioctl(file, DRM_IOCTL_AGP_FREE, &req64);
    675  1.1  christos 
    676  1.1  christos 	return copyout(arg, &req32, sizeof(req32));
    677  1.1  christos }
    678  1.1  christos 
    679  1.1  christos static int
    680  1.1  christos compat_drm_agp_free(struct file *file, void *arg)
    681  1.1  christos {
    682  1.1  christos 	drm_agp_buffer32_t req32;
    683  1.1  christos 	struct drm_agp_buffer req64;
    684  1.1  christos 	int error;
    685  1.1  christos 	uint32_t handle;
    686  1.1  christos 
    687  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
    688  1.1  christos 		return error;
    689  1.1  christos 
    690  1.1  christos 	handle = req32.handle;
    691  1.1  christos 	req64.handle = handle;
    692  1.1  christos 
    693  1.1  christos 	return drm_ioctl(file, DRM_IOCTL_AGP_FREE, &req64);
    694  1.1  christos }
    695  1.1  christos 
    696  1.1  christos typedef struct drm_agp_binding32 {
    697  1.1  christos 	uint32_t handle;	/**< From drm_agp_buffer */
    698  1.1  christos 	uint32_t offset;	/**< In bytes -- will round to page boundary */
    699  1.1  christos } drm_agp_binding32_t;
    700  1.1  christos 
    701  1.1  christos static int
    702  1.1  christos compat_drm_agp_bind(struct file *file, void *arg)
    703  1.1  christos {
    704  1.1  christos 	drm_agp_binding32_t req32;
    705  1.1  christos 	struct drm_agp_binding req64;
    706  1.1  christos 	int error;
    707  1.1  christos 
    708  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) !=0 )
    709  1.1  christos 		return error;
    710  1.1  christos 
    711  1.1  christos 	req64.handle = req32.handle;
    712  1.1  christos 	req64.offset = req32.offset;
    713  1.1  christos 
    714  1.1  christos 	return drm_ioctl(file, DRM_IOCTL_AGP_BIND, &req64);
    715  1.1  christos }
    716  1.1  christos 
    717  1.1  christos static int
    718  1.1  christos compat_drm_agp_unbind(struct file *file, void *arg)
    719  1.1  christos {
    720  1.1  christos 	struct drm_agp_binding req64;
    721  1.1  christos 	drm_agp_binding32_t req32;
    722  1.1  christos 	uint32_t handle;
    723  1.1  christos 	int error;
    724  1.1  christos 
    725  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
    726  1.1  christos 		return error;
    727  1.1  christos 
    728  1.1  christos 	handle = req32.handle;
    729  1.1  christos 	req64.handle = handle;
    730  1.1  christos 
    731  1.1  christos 	return drm_ioctl(file, DRM_IOCTL_AGP_UNBIND, &req64);
    732  1.1  christos }
    733  1.1  christos #endif /* CONFIG_AGP */
    734  1.1  christos 
    735  1.1  christos typedef struct drm_scatter_gather32 {
    736  1.1  christos 	uint32_t size;		/**< In bytes -- will round to page boundary */
    737  1.1  christos 	uint32_t handle;	/**< Used for mapping / unmapping */
    738  1.1  christos } drm_scatter_gather32_t;
    739  1.1  christos 
    740  1.1  christos static int
    741  1.1  christos compat_drm_sg_alloc(struct file *file, void *arg)
    742  1.1  christos {
    743  1.1  christos 	struct drm_scatter_gather req64;
    744  1.1  christos 	drm_scatter_gather32_t req32;
    745  1.1  christos 	int error;
    746  1.1  christos 
    747  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
    748  1.1  christos 		return error;
    749  1.1  christos 
    750  1.1  christos 	req64.size = req32.size;
    751  1.1  christos 
    752  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_SG_ALLOC, &req64);
    753  1.1  christos 	if (error)
    754  1.1  christos 		return error;
    755  1.1  christos 
    756  1.1  christos 	/* XXX not sure about the handle conversion here... */
    757  1.1  christos 	req32.handle = req64.handle >> PAGE_SHIFT;
    758  1.1  christos 
    759  1.1  christos 	return 0;
    760  1.1  christos }
    761  1.1  christos 
    762  1.1  christos static int
    763  1.1  christos compat_drm_sg_free(struct file *file, void *arg)
    764  1.1  christos {
    765  1.1  christos 	struct drm_scatter_gather req64;
    766  1.1  christos 	unsigned long x;
    767  1.1  christos 	drm_scatter_gather32_t req32;
    768  1.1  christos 	int error;
    769  1.1  christos 
    770  1.1  christos 	if((error = copyin(&req32, arg, sizeof(req32))) != 0)
    771  1.1  christos 		return error;
    772  1.1  christos 
    773  1.1  christos 	x = req32.handle;
    774  1.1  christos 	req64.handle = x << PAGE_SHIFT;
    775  1.1  christos 
    776  1.1  christos 	return drm_ioctl(file, DRM_IOCTL_SG_FREE, &req64);
    777  1.1  christos }
    778  1.1  christos 
    779  1.1  christos #if defined(CONFIG_X86) || defined(CONFIG_IA64)
    780  1.1  christos typedef struct drm_update_draw32 {
    781  1.1  christos 	drm_drawable_t handle;
    782  1.1  christos 	unsigned int type;
    783  1.1  christos 	unsigned int num;
    784  1.1  christos 	/* 64-bit version has a 32-bit pad here */
    785  1.1  christos 	uint64_t data;	/**< Pointer */
    786  1.1  christos } __attribute__((__packed__)) drm_update_draw32_t;
    787  1.1  christos 
    788  1.1  christos static void
    789  1.1  christos update32to64(struct drm_update_draw *req64, const drm_update_draw32_t *update32)
    790  1.1  christos {
    791  1.1  christos 	req64->handle = update32->handle;
    792  1.1  christos 	req64->type = update32->type;
    793  1.1  christos 	req64->num = update32->num;
    794  1.1  christos 	req64->data = update32->data;
    795  1.1  christos }
    796  1.1  christos static int
    797  1.1  christos compat_drm_update_draw(struct file *file, void *arg)
    798  1.1  christos {
    799  1.1  christos 	drm_update_draw32_t update32;
    800  1.1  christos 	struct drm_update_draw req64;
    801  1.1  christos 	int error;
    802  1.1  christos 
    803  1.1  christos 	if ((error = copyin(&update32, arg, sizeof(update32))) !=0)
    804  1.1  christos 		return error;
    805  1.1  christos 
    806  1.1  christos 	update32to64(&req64, &update32);
    807  1.1  christos 
    808  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_UPDATE_DRAW, &req64);
    809  1.1  christos 	return error;
    810  1.1  christos }
    811  1.1  christos #endif
    812  1.1  christos 
    813  1.1  christos struct drm_wait_vblank_request32 {
    814  1.1  christos 	enum drm_vblank_seq_type type;
    815  1.1  christos 	unsigned int sequence;
    816  1.1  christos 	uint32_t signal;
    817  1.1  christos };
    818  1.1  christos 
    819  1.1  christos struct drm_wait_vblank_reply32 {
    820  1.1  christos 	enum drm_vblank_seq_type type;
    821  1.1  christos 	unsigned int sequence;
    822  1.1  christos 	s32 tval_sec;
    823  1.1  christos 	s32 tval_usec;
    824  1.1  christos };
    825  1.1  christos 
    826  1.1  christos typedef union drm_wait_vblank32 {
    827  1.1  christos 	struct drm_wait_vblank_request32 request;
    828  1.1  christos 	struct drm_wait_vblank_reply32 reply;
    829  1.1  christos } drm_wait_vblank32_t;
    830  1.1  christos 
    831  1.1  christos static void
    832  1.1  christos req32to64(union drm_wait_vblank *req64, const drm_wait_vblank32_t *req32)
    833  1.1  christos {
    834  1.1  christos 	req64->request.type = req32->request.type;
    835  1.1  christos 	req64->request.sequence = req32->request.sequence;
    836  1.1  christos 	req64->request.signal = req32->request.signal;
    837  1.1  christos }
    838  1.1  christos 
    839  1.1  christos static void
    840  1.1  christos req64to32(drm_wait_vblank32_t *req32, const union drm_wait_vblank *req64)
    841  1.1  christos {
    842  1.1  christos 	req32->reply.sequence = req64->reply.sequence;
    843  1.1  christos 	req32->reply.tval_sec = req64->reply.tval_sec;
    844  1.1  christos 	req32->reply.tval_usec = req64->reply.tval_usec;
    845  1.1  christos }
    846  1.1  christos 
    847  1.1  christos static int
    848  1.1  christos compat_drm_wait_vblank(struct file *file, void *arg)
    849  1.1  christos {
    850  1.1  christos 	drm_wait_vblank32_t req32;
    851  1.1  christos 	union drm_wait_vblank req64;
    852  1.1  christos 	int error;
    853  1.1  christos 
    854  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
    855  1.1  christos 		return error;
    856  1.1  christos 
    857  1.1  christos 	req32to64(&req64, &req32);
    858  1.1  christos 
    859  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_WAIT_VBLANK, &req64);
    860  1.1  christos 	if (error)
    861  1.1  christos 		return error;
    862  1.1  christos 
    863  1.1  christos 	req64to32(&req32, &req64);
    864  1.1  christos 
    865  1.1  christos 	return copyout(arg, &req32, sizeof(req32));
    866  1.1  christos }
    867  1.1  christos 
    868  1.1  christos #if defined(CONFIG_X86) || defined(CONFIG_IA64)
    869  1.1  christos typedef struct drm_mode_fb_cmd232 {
    870  1.1  christos 	uint32_t fb_id;
    871  1.1  christos 	uint32_t width;
    872  1.1  christos 	uint32_t height;
    873  1.1  christos 	uint32_t pixel_format;
    874  1.1  christos 	uint32_t flags;
    875  1.1  christos 	uint32_t handles[4];
    876  1.1  christos 	uint32_t pitches[4];
    877  1.1  christos 	uint32_t offsets[4];
    878  1.1  christos 	uint64_t modifier[4];
    879  1.1  christos } __attribute__((__packed__)) drm_mode_fb_cmd232_t;
    880  1.1  christos 
    881  1.1  christos static void
    882  1.1  christos map_req32to64(struct drm_mode_fb_cmd2 *req64, struct drm_mode_fb_cmd232 *req32)
    883  1.1  christos {
    884  1.1  christos 	req64->width = req32->width;
    885  1.1  christos 	req64->height = req32->height;
    886  1.1  christos 	req64->pixel_format = req32->pixel_format;
    887  1.1  christos 	req64->flags = req32->flags;
    888  1.1  christos }
    889  1.1  christos 
    890  1.1  christos static int
    891  1.1  christos compat_drm_mode_addfb2(struct file *file, void *arg)
    892  1.1  christos {
    893  1.1  christos 	struct drm_mode_fb_cmd232 req32;
    894  1.1  christos 	struct drm_mode_fb_cmd2 req64;
    895  1.1  christos 	int error;
    896  1.1  christos 
    897  1.1  christos 	if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
    898  1.1  christos 		return error;
    899  1.1  christos 
    900  1.1  christos 	map_req32to64(&req64, &req32);
    901  1.1  christos 
    902  1.1  christos 	for (int i = 0; i < 4; i++){
    903  1.1  christos 		req64.handles[i] = req32.handles[i];
    904  1.1  christos 		req64.pitches[i] = req32.pitches[i];
    905  1.1  christos 		req64.offsets[i] = req32.offsets[i];
    906  1.1  christos 		req64.modifier[i] = req32.modifier[i];
    907  1.1  christos 	}
    908  1.1  christos 
    909  1.1  christos 	error = drm_ioctl(file, DRM_IOCTL_MODE_ADDFB2, &req64);
    910  1.1  christos 	if (error)
    911  1.1  christos 		return error;
    912  1.1  christos 
    913  1.1  christos 	req32.fb_id = req64.fb_id;
    914  1.1  christos 
    915  1.1  christos 	return copyout(arg, &req32, sizeof(req32));
    916  1.1  christos }
    917  1.1  christos #endif
    918  1.1  christos 
    919  1.1  christos int
    920  1.1  christos netbsd32_drm_ioctl(struct file *file, unsigned long cmd, void *arg,
    921  1.1  christos     struct lwp *l)
    922  1.1  christos {
    923  1.1  christos 	switch (cmd) {
    924  1.1  christos 	case DRM_IOCTL_VERSION32:
    925  1.1  christos 		return compat_drm_version(file, arg);
    926  1.1  christos 	case DRM_IOCTL_GET_UNIQUE32:
    927  1.1  christos 		return compat_drm_getunique(file, arg);
    928  1.1  christos 	case DRM_IOCTL_SET_UNIQUE32:
    929  1.1  christos 		return compat_drm_setunique(file, arg);
    930  1.1  christos 	case DRM_IOCTL_GET_MAP32:
    931  1.1  christos 		return compat_drm_getmap(file, arg);
    932  1.1  christos 	case DRM_IOCTL_ADD_MAP32:
    933  1.1  christos 		return compat_drm_addmap(file, arg);
    934  1.1  christos 	case DRM_IOCTL_RM_MAP32:
    935  1.1  christos 		return compat_drm_rmmap(file, arg);
    936  1.1  christos 	case DRM_IOCTL_GET_CLIENT32:
    937  1.1  christos 		return compat_drm_getclient(file, arg);
    938  1.1  christos 	case DRM_IOCTL_GET_STATS32:
    939  1.1  christos 		return compat_drm_getstats(file, arg);
    940  1.1  christos 	case DRM_IOCTL_ADD_BUFS32:
    941  1.1  christos 		return compat_drm_addbufs(file, arg);
    942  1.1  christos 	case DRM_IOCTL_MARK_BUFS32:
    943  1.1  christos 		return compat_drm_markbufs(file, arg);
    944  1.1  christos 	case DRM_IOCTL_FREE_BUFS32:
    945  1.1  christos 		return compat_drm_freebufs(file, arg);
    946  1.1  christos 	case DRM_IOCTL_SET_SAREA_CTX32:
    947  1.1  christos 		return compat_drm_setsareactx(file, arg);
    948  1.1  christos 	case DRM_IOCTL_GET_SAREA_CTX32:
    949  1.1  christos 		return compat_drm_getsareactx(file, arg);
    950  1.1  christos 	case DRM_IOCTL_RES_CTX32:
    951  1.1  christos 		return compat_drm_resctx(file, arg);
    952  1.1  christos 	case DRM_IOCTL_DMA32:
    953  1.1  christos 		return compat_drm_dma(file, arg);
    954  1.1  christos 	case  DRM_IOCTL_AGP_ENABLE32:
    955  1.1  christos 		return compat_drm_agp_enable(file, arg);
    956  1.1  christos 	case DRM_IOCTL_AGP_INFO32:
    957  1.1  christos 		return compat_drm_agp_info(file, arg);
    958  1.1  christos 	case DRM_IOCTL_AGP_ALLOC32:
    959  1.1  christos 		return compat_drm_agp_alloc(file,arg);
    960  1.1  christos 	case DRM_IOCTL_AGP_UNBIND32:
    961  1.1  christos 		return compat_drm_agp_unbind(file, arg);
    962  1.1  christos 	case DRM_IOCTL_AGP_BIND32:
    963  1.1  christos 		return compat_drm_agp_bind(file, arg);
    964  1.1  christos 	case DRM_IOCTL_AGP_FREE32:
    965  1.1  christos 		return compat_drm_agp_free(file, arg);
    966  1.1  christos 	case DRM_IOCTL_SG_ALLOC32:
    967  1.1  christos 		return compat_drm_sg_alloc(file, arg);
    968  1.1  christos 	case  DRM_IOCTL_MODE_ADDFB232:
    969  1.1  christos 		return compat_drm_mode_addfb2(file, arg);
    970  1.1  christos 	case DRM_IOCTL_WAIT_VBLANK32:
    971  1.1  christos 		return compat_drm_wait_vblank(file, arg);
    972  1.1  christos 	case DRM_IOCTL_UPDATE_DRAW32:
    973  1.1  christos 		return compat_drm_update_draw(file, arg);
    974  1.1  christos 	case DRM_IOCTL_SG_FREE32:
    975  1.1  christos 		return compat_drm_sg_free(file, arg);
    976  1.1  christos 	default:
    977  1.1  christos 		return EINVAL;
    978  1.1  christos 	}
    979  1.1  christos }
    980