1*42ca6328Schristos /* $NetBSD: netbsd32_drm.c,v 1.4 2019/09/28 15:15:34 christos Exp $ */
2842abfeeSchristos
3842abfeeSchristos /*
439360c92Schristos * Copyright (c) 2019 The NetBSD Foundation, Inc.
539360c92Schristos * All rights reserved.
639360c92Schristos *
7842abfeeSchristos * This code was written by Surya Shankar for GSoC 2019.
8842abfeeSchristos *
9842abfeeSchristos * Redistribution and use in source and binary forms, with or without
10842abfeeSchristos * modification, are permitted provided that the following conditions
11842abfeeSchristos * are met:
12842abfeeSchristos * 1. Redistributions of source code must retain the above copyright
13842abfeeSchristos * notice, this list of conditions and the following disclaimer.
14842abfeeSchristos * 2. Redistributions in binary form must reproduce the above copyright
15842abfeeSchristos * notice, this list of conditions and the following disclaimer in the
16842abfeeSchristos * documentation and/or other materials provided with the distribution.
17842abfeeSchristos *
18842abfeeSchristos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19842abfeeSchristos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20842abfeeSchristos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21842abfeeSchristos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22842abfeeSchristos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23842abfeeSchristos * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24842abfeeSchristos * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25842abfeeSchristos * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26842abfeeSchristos * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27842abfeeSchristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28842abfeeSchristos * SUCH DAMAGE.
29842abfeeSchristos */
30842abfeeSchristos
31842abfeeSchristos #include <sys/cdefs.h>
32*42ca6328Schristos __KERNEL_RCSID(0, "$NetBSD: netbsd32_drm.c,v 1.4 2019/09/28 15:15:34 christos Exp $");
33842abfeeSchristos
34842abfeeSchristos #include <compat/netbsd32/netbsd32.h>
35842abfeeSchristos #include <compat/netbsd32/netbsd32_ioctl.h>
36842abfeeSchristos
37842abfeeSchristos #include <linux/types.h>
38842abfeeSchristos #include <drm/drmP.h>
39842abfeeSchristos
40842abfeeSchristos #define DRM_IOCTL_VERSION32 DRM_IOWR(0x00, drm_version32_t)
41842abfeeSchristos #define DRM_IOCTL_GET_UNIQUE32 DRM_IOWR(0x01, drm_unique32_t)
42842abfeeSchristos #define DRM_IOCTL_GET_MAP32 DRM_IOWR(0x04, drm_map32_t)
43842abfeeSchristos #define DRM_IOCTL_GET_CLIENT32 DRM_IOWR(0x05, drm_client32_t)
44842abfeeSchristos #define DRM_IOCTL_GET_STATS32 DRM_IOR( 0x06, drm_stats32_t)
45842abfeeSchristos
46842abfeeSchristos #define DRM_IOCTL_SET_UNIQUE32 DRM_IOW( 0x10, drm_unique32_t)
47842abfeeSchristos #define DRM_IOCTL_ADD_MAP32 DRM_IOWR(0x15, drm_map32_t)
48842abfeeSchristos #define DRM_IOCTL_ADD_BUFS32 DRM_IOWR(0x16, drm_buf_desc32_t)
49842abfeeSchristos #define DRM_IOCTL_MARK_BUFS32 DRM_IOW( 0x17, drm_buf_desc32_t)
50842abfeeSchristos #define DRM_IOCTL_INFO_BUFS32 DRM_IOWR(0x18, drm_buf_info32_t)
51842abfeeSchristos #define DRM_IOCTL_MAP_BUFS32 DRM_IOWR(0x19, drm_buf_map32_t)
52842abfeeSchristos #define DRM_IOCTL_FREE_BUFS32 DRM_IOW( 0x1a, drm_buf_free32_t)
53842abfeeSchristos
54842abfeeSchristos #define DRM_IOCTL_RM_MAP32 DRM_IOW( 0x1b, drm_map32_t)
55842abfeeSchristos
56842abfeeSchristos #define DRM_IOCTL_SET_SAREA_CTX32 DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
57842abfeeSchristos #define DRM_IOCTL_GET_SAREA_CTX32 DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
58842abfeeSchristos
59842abfeeSchristos #define DRM_IOCTL_RES_CTX32 DRM_IOWR(0x26, drm_ctx_res32_t)
60842abfeeSchristos #define DRM_IOCTL_DMA32 DRM_IOWR(0x29, drm_dma32_t)
61842abfeeSchristos
62842abfeeSchristos #define DRM_IOCTL_AGP_ENABLE32 DRM_IOW( 0x32, drm_agp_mode32_t)
63842abfeeSchristos #define DRM_IOCTL_AGP_INFO32 DRM_IOR( 0x33, drm_agp_info32_t)
64842abfeeSchristos #define DRM_IOCTL_AGP_ALLOC32 DRM_IOWR(0x34, drm_agp_buffer32_t)
65842abfeeSchristos #define DRM_IOCTL_AGP_FREE32 DRM_IOW( 0x35, drm_agp_buffer32_t)
66842abfeeSchristos #define DRM_IOCTL_AGP_BIND32 DRM_IOW( 0x36, drm_agp_binding32_t)
67842abfeeSchristos #define DRM_IOCTL_AGP_UNBIND32 DRM_IOW( 0x37, drm_agp_binding32_t)
68842abfeeSchristos
69842abfeeSchristos #define DRM_IOCTL_SG_ALLOC32 DRM_IOW( 0x38, drm_scatter_gather32_t)
70842abfeeSchristos #define DRM_IOCTL_SG_FREE32 DRM_IOW( 0x39, drm_scatter_gather32_t)
71842abfeeSchristos
72842abfeeSchristos #define DRM_IOCTL_UPDATE_DRAW32 DRM_IOW( 0x3f, drm_update_draw32_t)
73842abfeeSchristos
74842abfeeSchristos #define DRM_IOCTL_WAIT_VBLANK32 DRM_IOWR(0x3a, drm_wait_vblank32_t)
75842abfeeSchristos
76842abfeeSchristos #define DRM_IOCTL_MODE_ADDFB232 DRM_IOWR(0xb8, drm_mode_fb_cmd232_t)
77842abfeeSchristos
78842abfeeSchristos // Compat DRM Version Implementation
79842abfeeSchristos
80842abfeeSchristos typedef struct {
81842abfeeSchristos int version_major; /**< Major version */
82842abfeeSchristos int version_minor; /**< Minor version */
83842abfeeSchristos int version_patchlevel; /**< Patch level */
84842abfeeSchristos uint32_t name_len; /**< Length of name buffer */
85842abfeeSchristos netbsd32_pointer_t name; /**< Name of driver */
86842abfeeSchristos uint32_t date_len; /**< Length of date buffer */
87842abfeeSchristos netbsd32_pointer_t date; /**< User-space buffer to hold date */
88842abfeeSchristos uint32_t desc_len; /**< Length of desc buffer */
89842abfeeSchristos netbsd32_pointer_t desc; /**< User-space buffer to hold desc */
90842abfeeSchristos } drm_version32_t;
91842abfeeSchristos
92842abfeeSchristos static int
compat_drm_version(struct file * file,void * arg)93842abfeeSchristos compat_drm_version(struct file *file, void *arg)
94842abfeeSchristos {
95842abfeeSchristos drm_version32_t v32;
96842abfeeSchristos struct drm_version v64;
97842abfeeSchristos int error;
98842abfeeSchristos
99842abfeeSchristos if ((error = copyin(&v32, arg, sizeof(v32))) != 0)
100842abfeeSchristos return error;
101842abfeeSchristos
102842abfeeSchristos v64.name_len = v32.name_len;
103842abfeeSchristos v64.name = NETBSD32PTR64(v32.name);
104842abfeeSchristos v64.date_len = v32.date_len;
105842abfeeSchristos v64.date = NETBSD32PTR64(v32.date);
106842abfeeSchristos v64.desc_len = v32.desc_len;
107842abfeeSchristos v64.desc = NETBSD32PTR64(v32.desc);
108842abfeeSchristos
109842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_VERSION, &v64);
110842abfeeSchristos if (error)
111842abfeeSchristos return error;
112842abfeeSchristos
113842abfeeSchristos v32.version_major = v64.version_major;
114842abfeeSchristos v32.version_minor = v64.version_minor;
115842abfeeSchristos v32.version_patchlevel = v64.version_patchlevel;
116842abfeeSchristos /* strings have already been copied in place */
117842abfeeSchristos v32.name_len = v64.name_len;
118842abfeeSchristos v32.date_len = v64.date_len;
119842abfeeSchristos v32.desc_len = v64.desc_len;
120842abfeeSchristos
121842abfeeSchristos return copyout(arg, &v32, sizeof(v32));
122842abfeeSchristos }
123842abfeeSchristos
124842abfeeSchristos typedef struct drm_unique32 {
125842abfeeSchristos uint32_t unique_len;
126842abfeeSchristos netbsd32_pointer_t unique;
127842abfeeSchristos } drm_unique32_t;
128842abfeeSchristos
129842abfeeSchristos static int
compat_drm_getunique(struct file * file,void * arg)130842abfeeSchristos compat_drm_getunique(struct file *file, void *arg)
131842abfeeSchristos {
132842abfeeSchristos drm_unique32_t uq32;
133842abfeeSchristos struct drm_unique uq64;
134842abfeeSchristos int error;
135842abfeeSchristos
136842abfeeSchristos if ((error = copyin(&uq32, arg, sizeof(uq32))) != 0)
137842abfeeSchristos return error;
138842abfeeSchristos
139842abfeeSchristos uq64.unique_len = uq32.unique_len;
140842abfeeSchristos uq64.unique = NETBSD32PTR64(uq32.unique);
141842abfeeSchristos
142842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_GET_UNIQUE, &uq64);
143842abfeeSchristos if (error)
144842abfeeSchristos return error;
145842abfeeSchristos
146842abfeeSchristos //unique should already be copied
147842abfeeSchristos uq32.unique_len = uq64.unique_len;
148842abfeeSchristos
149842abfeeSchristos if ((error = copyout(arg, &uq32, sizeof(uq32))) != 0)
150842abfeeSchristos return error;
151842abfeeSchristos
152842abfeeSchristos return 0;
153842abfeeSchristos }
154842abfeeSchristos
155842abfeeSchristos static int
compat_drm_setunique(struct file * file,void * arg)156842abfeeSchristos compat_drm_setunique(struct file *file, void *arg)
157842abfeeSchristos {
158842abfeeSchristos drm_unique32_t uq32;
159842abfeeSchristos struct drm_unique uq64;
160842abfeeSchristos int error;
161842abfeeSchristos
162842abfeeSchristos if ((error = copyin(&uq32, arg, sizeof(uq32))) != 0)
163842abfeeSchristos return error;
164842abfeeSchristos
165842abfeeSchristos uq64.unique_len = uq32.unique_len;
166842abfeeSchristos uq64.unique = NETBSD32PTR64(uq32.unique);
167842abfeeSchristos
168842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_SET_UNIQUE, &uq64);
169842abfeeSchristos if (error)
170842abfeeSchristos return error;
171842abfeeSchristos
172842abfeeSchristos // XXX: do we need copyout and copying the fields here?
173842abfeeSchristos uq32.unique_len = uq64.unique_len;
174842abfeeSchristos NETBSD32PTR32(uq32.unique, uq64.unique);
175842abfeeSchristos
176842abfeeSchristos return error;
177842abfeeSchristos }
178842abfeeSchristos
179842abfeeSchristos typedef struct drm_map32 {
180842abfeeSchristos uint32_t offset; /**< Req. physical address (0 for SAREA) */
181842abfeeSchristos uint32_t size; /**< Requested physical size (bytes) */
182842abfeeSchristos enum drm_map_type type; /**< Type of memory to map */
183842abfeeSchristos enum drm_map_flags flags; /**< Flags */
184842abfeeSchristos netbsd32_pointer_t handle;/**< User-space: "Handle" to pass to mmap() */
185842abfeeSchristos int mtrr; /**< MTRR slot used */
186842abfeeSchristos } drm_map32_t;
187842abfeeSchristos
188842abfeeSchristos static void
map32to64(struct drm_map * m64,const drm_map32_t * m32)189842abfeeSchristos map32to64(struct drm_map *m64, const drm_map32_t *m32)
190842abfeeSchristos {
191842abfeeSchristos m64->offset = m32->offset;
192842abfeeSchristos m64->size = m32->size;
193842abfeeSchristos m64->type = m32->type;
194842abfeeSchristos m64->flags = m32->flags;
195842abfeeSchristos m64->handle = NETBSD32PTR64(m32->handle);
196842abfeeSchristos m64->mtrr = m32->mtrr;
197842abfeeSchristos }
198842abfeeSchristos
199842abfeeSchristos static void
map64to32(drm_map32_t * m32,const struct drm_map * m64)200842abfeeSchristos map64to32(drm_map32_t *m32, const struct drm_map *m64)
201842abfeeSchristos {
202842abfeeSchristos m32->offset = m64->offset;
203842abfeeSchristos m32->size = m64->size;
204842abfeeSchristos m32->type = m64->type;
205842abfeeSchristos m32->flags = m64->flags;
206842abfeeSchristos NETBSD32PTR32(m32->handle, m64->handle);
207842abfeeSchristos m32->mtrr = m64->mtrr;
208842abfeeSchristos }
209842abfeeSchristos
210842abfeeSchristos static int
compat_drm_getmap(struct file * file,void * arg)211842abfeeSchristos compat_drm_getmap(struct file *file, void *arg)
212842abfeeSchristos {
213842abfeeSchristos drm_map32_t m32;
214842abfeeSchristos struct drm_map m64;
215842abfeeSchristos int error;
216842abfeeSchristos
217842abfeeSchristos if ((error = copyin(&m32, arg, sizeof(m32))) != 0)
218842abfeeSchristos return error;
219842abfeeSchristos
220842abfeeSchristos map32to64(&m64, &m32);
221842abfeeSchristos
222842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_GET_MAP, &m64);
223842abfeeSchristos if (error)
224842abfeeSchristos return error;
225842abfeeSchristos
226842abfeeSchristos map64to32(&m32, &m64);
227842abfeeSchristos
228842abfeeSchristos return copyout(arg, &m32, sizeof(m32));
229842abfeeSchristos }
230842abfeeSchristos
231842abfeeSchristos static int
compat_drm_addmap(struct file * file,void * arg)232842abfeeSchristos compat_drm_addmap(struct file *file, void *arg)
233842abfeeSchristos {
234842abfeeSchristos drm_map32_t m32;
235842abfeeSchristos struct drm_map m64;
236842abfeeSchristos int error;
237842abfeeSchristos
238842abfeeSchristos if ((error = copyin(&m32, arg, sizeof(m32))) != 0)
239842abfeeSchristos return error;
240842abfeeSchristos
241842abfeeSchristos map32to64(&m64, &m32);
242842abfeeSchristos
243842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_ADD_MAP, &m64);
244842abfeeSchristos if (error)
245842abfeeSchristos return error;
246842abfeeSchristos
247842abfeeSchristos map64to32(&m32, &m64);
248842abfeeSchristos
249842abfeeSchristos return copyout(arg, &m32, sizeof(m32));
250842abfeeSchristos }
251842abfeeSchristos
252842abfeeSchristos
253842abfeeSchristos static int
compat_drm_rmmap(struct file * file,void * arg)254842abfeeSchristos compat_drm_rmmap(struct file *file, void *arg)
255842abfeeSchristos {
256842abfeeSchristos drm_map32_t m32;
257842abfeeSchristos struct drm_map m64;
258842abfeeSchristos int error;
259842abfeeSchristos if ((error = copyin(&m32, arg, sizeof(m32))) != 0)
260842abfeeSchristos return error;
261842abfeeSchristos
262842abfeeSchristos map32to64(&m64, &m32);
263842abfeeSchristos
264842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_RM_MAP, &m64);
265842abfeeSchristos if (error)
266842abfeeSchristos return error;
267842abfeeSchristos
268842abfeeSchristos map64to32(&m32, &m64);
269842abfeeSchristos
270842abfeeSchristos return copyout(arg, &m32, sizeof(m32));
271842abfeeSchristos }
272842abfeeSchristos
273842abfeeSchristos typedef struct drm_client32 {
274842abfeeSchristos int idx; /**< Which client desired? */
275842abfeeSchristos int auth; /**< Is client authenticated? */
276842abfeeSchristos uint32_t pid; /**< Process ID */
277842abfeeSchristos uint32_t uid; /**< User ID */
278842abfeeSchristos uint32_t magic; /**< Magic */
279842abfeeSchristos uint32_t iocs; /**< Ioctl count */
280842abfeeSchristos } drm_client32_t;
281842abfeeSchristos
282842abfeeSchristos static void
client32to64(struct drm_client * c64,const drm_client32_t * c32)283842abfeeSchristos client32to64(struct drm_client *c64, const drm_client32_t *c32)
284842abfeeSchristos {
285842abfeeSchristos c64->idx = c32->idx;
286842abfeeSchristos c64->auth = c32->auth;
287842abfeeSchristos c64->pid = c32->pid;
288842abfeeSchristos c64->uid = c32->uid;
289842abfeeSchristos c64->iocs = c64->iocs;
290842abfeeSchristos }
291842abfeeSchristos
292842abfeeSchristos static void
client64to32(drm_client32_t * c32,const struct drm_client * c64)293842abfeeSchristos client64to32(drm_client32_t *c32, const struct drm_client *c64)
294842abfeeSchristos {
295842abfeeSchristos c32->idx = c64->idx;
296842abfeeSchristos c32->auth = c64->auth;
297842abfeeSchristos c32->pid = c64->pid;
298842abfeeSchristos c32->uid = c64->uid;
299842abfeeSchristos c32->iocs = c64->iocs;
300842abfeeSchristos }
301842abfeeSchristos static int
compat_drm_getclient(struct file * file,void * arg)302842abfeeSchristos compat_drm_getclient(struct file *file, void *arg)
303842abfeeSchristos {
304842abfeeSchristos drm_client32_t c32;
305842abfeeSchristos struct drm_client c64;
306842abfeeSchristos int error;
307842abfeeSchristos
308842abfeeSchristos if ((error = copyin(&c32, arg, sizeof(c32))) != 0)
309842abfeeSchristos return error;
310842abfeeSchristos
311842abfeeSchristos client32to64(&c64, &c32);
312842abfeeSchristos
313842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_GET_CLIENT, &c64);
314842abfeeSchristos if (error)
315842abfeeSchristos return error;
316842abfeeSchristos
317842abfeeSchristos client64to32(&c32, &c64);
318842abfeeSchristos
319842abfeeSchristos return copyout(arg, &c32, sizeof(c32));
320842abfeeSchristos }
321842abfeeSchristos
322842abfeeSchristos typedef struct drm_stats32 {
323842abfeeSchristos uint32_t count;
324842abfeeSchristos struct {
325842abfeeSchristos uint32_t value;
326842abfeeSchristos enum drm_stat_type type;
327842abfeeSchristos } data[15];
328842abfeeSchristos } drm_stats32_t;
329842abfeeSchristos
330842abfeeSchristos static int
compat_drm_getstats(struct file * file,void * arg)331842abfeeSchristos compat_drm_getstats(struct file *file, void *arg)
332842abfeeSchristos {
333842abfeeSchristos drm_stats32_t st32;
334842abfeeSchristos struct drm_stats st64;
335842abfeeSchristos int error;
336842abfeeSchristos
337842abfeeSchristos if ((error = copyin(&st32, arg, sizeof(st32))) != 0)
338842abfeeSchristos return error;
339842abfeeSchristos
340842abfeeSchristos st64.count = st32.count;
341e1a89edaSchristos if (st64.count > __arraycount(st64.data))
342e1a89edaSchristos return EINVAL;
343842abfeeSchristos
344842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_GET_STATS, &st64);
345842abfeeSchristos if (error)
346842abfeeSchristos return error;
347842abfeeSchristos
348*42ca6328Schristos for (size_t i = 0; i < st64.count; ++i) {
349e1a89edaSchristos st32.data[i].value = st64.data[i].value;
350e1a89edaSchristos st32.data[i].type = st64.data[i].type;
351842abfeeSchristos }
352e1a89edaSchristos st32.count = st64.count;
353842abfeeSchristos
354842abfeeSchristos return copyout(arg, &st32, sizeof(s32));
355842abfeeSchristos }
356842abfeeSchristos
357842abfeeSchristos typedef struct drm_buf_desc32 {
358842abfeeSchristos int count; /**< Number of buffers of this size */
359842abfeeSchristos int size; /**< Size in bytes */
360842abfeeSchristos int low_mark; /**< Low water mark */
361842abfeeSchristos int high_mark; /**< High water mark */
362842abfeeSchristos int flags;
363842abfeeSchristos netbsd32_pointer_t agp_start;
364842abfeeSchristos /**< Start address in the AGP aperture */
365842abfeeSchristos } drm_buf_desc32_t;
366842abfeeSchristos
367842abfeeSchristos static int
compat_drm_addbufs(struct file * file,void * arg)368842abfeeSchristos compat_drm_addbufs(struct file *file, void *arg)
369842abfeeSchristos {
370842abfeeSchristos drm_buf_desc32_t buf32;
371842abfeeSchristos struct drm_buf_desc buf64;
372842abfeeSchristos int error;
373842abfeeSchristos
374842abfeeSchristos if ((error = copyin(&buf32, arg, sizeof(buf32))) != 0)
375842abfeeSchristos return error;
376842abfeeSchristos
377842abfeeSchristos // XXX: assign 32->64
378842abfeeSchristos buf64.agp_start = (unsigned long)NETBSD32PTR64(buf32.agp_start);
379842abfeeSchristos
380842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_ADD_BUFS, &buf64);
381842abfeeSchristos if (error)
382842abfeeSchristos return error;
383842abfeeSchristos
384842abfeeSchristos // XXX assign 64->32
385842abfeeSchristos NETBSD32PTR32(buf32.agp_start, (void *)buf64.agp_start);
386842abfeeSchristos
387842abfeeSchristos return copyout(&buf32, arg, sizeof(buf32));
388842abfeeSchristos }
389842abfeeSchristos
390842abfeeSchristos static int
compat_drm_markbufs(struct file * file,void * arg)391842abfeeSchristos compat_drm_markbufs(struct file *file, void *arg)
392842abfeeSchristos {
393842abfeeSchristos drm_buf_desc32_t b32;
394842abfeeSchristos struct drm_buf_desc b64;
395842abfeeSchristos int error;
396842abfeeSchristos
397842abfeeSchristos if ((error = copyin(&b32, arg, sizeof(b32))) != 0)
398842abfeeSchristos return error;
399842abfeeSchristos
400842abfeeSchristos b64.size = b32.size;
401842abfeeSchristos b64.low_mark = b32.low_mark;
402842abfeeSchristos b64.high_mark = b32.high_mark;
403842abfeeSchristos //XXX: more stuff?
404842abfeeSchristos
405842abfeeSchristos return drm_ioctl(file, DRM_IOCTL_MARK_BUFS, &b64);
406842abfeeSchristos }
407842abfeeSchristos
408842abfeeSchristos typedef struct drm_buf_info32 {
409842abfeeSchristos int count; /**< Entries in list */
410842abfeeSchristos netbsd32_pointer_t list;
411842abfeeSchristos } drm_buf_info32_t;
412842abfeeSchristos
413842abfeeSchristos typedef struct drm_buf_pub32 {
414842abfeeSchristos int idx; /**< Index into the master buffer list */
415842abfeeSchristos int total; /**< Buffer size */
416842abfeeSchristos int used; /**< Amount of buffer in use (for DMA) */
417842abfeeSchristos uint32_t address; /**< Address of buffer */
418842abfeeSchristos } drm_buf_pub32_t;
419842abfeeSchristos
420842abfeeSchristos typedef struct drm_buf_map32 {
421842abfeeSchristos int count; /**< Length of the buffer list */
422842abfeeSchristos uint32_t virtual; /**< Mmap'd area in user-virtual */
423842abfeeSchristos netbsd32_pointer_t list; /**< Buffer information */
424842abfeeSchristos } drm_buf_map32_t;
425842abfeeSchristos
426842abfeeSchristos
427842abfeeSchristos typedef struct drm_buf_free32 {
428842abfeeSchristos int count;
429842abfeeSchristos netbsd32_pointer_t list;
430842abfeeSchristos } drm_buf_free32_t;
431842abfeeSchristos
432842abfeeSchristos static int
compat_drm_freebufs(struct file * file,void * arg)433842abfeeSchristos compat_drm_freebufs(struct file *file, void *arg)
434842abfeeSchristos {
435842abfeeSchristos drm_buf_free32_t req32;
436842abfeeSchristos struct drm_buf_free req64;
437842abfeeSchristos int error;
438842abfeeSchristos
439842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
440842abfeeSchristos return error;
441842abfeeSchristos
442842abfeeSchristos req64.count = req32.count;
443842abfeeSchristos req64.list = NETBSD32PTR64(req32.list);
444842abfeeSchristos
445842abfeeSchristos return drm_ioctl(file, DRM_IOCTL_FREE_BUFS, &req64);
446842abfeeSchristos }
447842abfeeSchristos
448842abfeeSchristos typedef struct drm_ctx_priv_map32 {
449842abfeeSchristos unsigned int ctx_id; /**< Context requesting private mapping */
450842abfeeSchristos netbsd32_pointer_t handle; /**< Handle of map */
451842abfeeSchristos } drm_ctx_priv_map32_t;
452842abfeeSchristos
453842abfeeSchristos static int
compat_drm_setsareactx(struct file * file,void * arg)454842abfeeSchristos compat_drm_setsareactx(struct file *file, void *arg)
455842abfeeSchristos {
456842abfeeSchristos drm_ctx_priv_map32_t req32;
457842abfeeSchristos struct drm_ctx_priv_map req64;
458842abfeeSchristos int error;
459842abfeeSchristos
460842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
461842abfeeSchristos return error;
462842abfeeSchristos
463842abfeeSchristos req64.ctx_id = req32.ctx_id;
464842abfeeSchristos req64.handle = NETBSD32PTR64(req32.handle);
465842abfeeSchristos
466842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_SET_SAREA_CTX, &req64);
467842abfeeSchristos if(error)
468842abfeeSchristos return error;
469842abfeeSchristos
470842abfeeSchristos req32.ctx_id = req64.ctx_id;
471842abfeeSchristos NETBSD32PTR32(req32.handle, req64.handle);
472842abfeeSchristos
473842abfeeSchristos return 0;
474842abfeeSchristos }
475842abfeeSchristos
476842abfeeSchristos static int
compat_drm_getsareactx(struct file * file,void * arg)477842abfeeSchristos compat_drm_getsareactx(struct file *file, void *arg)
478842abfeeSchristos {
479842abfeeSchristos struct drm_ctx_priv_map req64;
480842abfeeSchristos drm_ctx_priv_map32_t req32;
481842abfeeSchristos int error;
482842abfeeSchristos
483842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
484842abfeeSchristos return error;
485842abfeeSchristos
486842abfeeSchristos req64.ctx_id = req32.ctx_id;
487842abfeeSchristos
488842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_GET_SAREA_CTX, &req64);
489842abfeeSchristos if (error)
490842abfeeSchristos return error;
491842abfeeSchristos
492842abfeeSchristos NETBSD32PTR32(req32.handle, req64.handle);
493842abfeeSchristos // XXX: missing copyout?
494842abfeeSchristos
495842abfeeSchristos return copyout(arg, &req32, sizeof(req32));
496842abfeeSchristos }
497842abfeeSchristos
498842abfeeSchristos typedef struct drm_ctx_res32 {
499842abfeeSchristos int count;
500842abfeeSchristos netbsd32_pointer_t contexts;
501842abfeeSchristos } drm_ctx_res32_t;
502842abfeeSchristos
503842abfeeSchristos static int
compat_drm_resctx(struct file * file,void * arg)504842abfeeSchristos compat_drm_resctx(struct file *file, void *arg)
505842abfeeSchristos {
506842abfeeSchristos drm_ctx_res32_t res32;
507842abfeeSchristos struct drm_ctx_res res64;
508842abfeeSchristos int error;
509842abfeeSchristos
510842abfeeSchristos if ((error = copyin(&res32, arg, sizeof(res32))) != 0)
511842abfeeSchristos return error;
512842abfeeSchristos
513842abfeeSchristos res64.count = res32.count;
514842abfeeSchristos res64.contexts = NETBSD32PTR64(res32.contexts);
515842abfeeSchristos
516842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_RES_CTX, &res64);
517842abfeeSchristos if (error)
518842abfeeSchristos return error;
519842abfeeSchristos
520842abfeeSchristos res32.count = res64.count;
521842abfeeSchristos NETBSD32PTR32(res32.contexts, res64.contexts);
522842abfeeSchristos /* XXX: missing copyout */
523842abfeeSchristos
524842abfeeSchristos return copyout(arg, &res32, sizeof(res32));
525842abfeeSchristos }
526842abfeeSchristos
527842abfeeSchristos typedef struct drm_dma32 {
528842abfeeSchristos int context; /**< Context handle */
529842abfeeSchristos int send_count; /**< Number of buffers to send */
530842abfeeSchristos netbsd32_pointer_t send_indices; /**< List of handles to buffers */
531842abfeeSchristos netbsd32_pointer_t send_sizes; /**< Lengths of data to send */
532842abfeeSchristos enum drm_dma_flags flags; /**< Flags */
533842abfeeSchristos netbsd32_pointer_t request_count; /**< Number of buffers requested */
534842abfeeSchristos int request_size; /**< Desired size for buffers */
535842abfeeSchristos netbsd32_pointer_t request_indices; /**< Buffer information */
536842abfeeSchristos netbsd32_pointer_t request_sizes;
537842abfeeSchristos int granted_count; /**< Number of buffers granted */
538842abfeeSchristos } drm_dma32_t;
539842abfeeSchristos
540842abfeeSchristos static void
dma64to32(drm_dma32_t * d32,const struct drm_dma * d64)541842abfeeSchristos dma64to32(drm_dma32_t *d32, const struct drm_dma *d64)
542842abfeeSchristos {
543842abfeeSchristos d32->send_count = d64->send_count;
544842abfeeSchristos NETBSD32PTR32(d32->send_indices, d64->send_indices);
545842abfeeSchristos NETBSD32PTR32(d32->send_sizes, d64->send_sizes);
546842abfeeSchristos d32->flags = d64->flags;
547842abfeeSchristos NETBSD32PTR32(d32->request_count, (void *)(long)d64->request_count);
548842abfeeSchristos NETBSD32PTR32(d32->request_indices, d64->request_indices);
549842abfeeSchristos NETBSD32PTR32(d32->request_sizes, d64->request_sizes);
550842abfeeSchristos
551842abfeeSchristos }
552842abfeeSchristos
553842abfeeSchristos static void
dma32to64(struct drm_dma * d64,const drm_dma32_t * d32)554842abfeeSchristos dma32to64(struct drm_dma *d64, const drm_dma32_t *d32)
555842abfeeSchristos {
556842abfeeSchristos d64->request_size = d32->request_size;
557842abfeeSchristos d64->granted_count = d32->granted_count;
558842abfeeSchristos }
559842abfeeSchristos
560842abfeeSchristos static int
compat_drm_dma(struct file * file,void * arg)561842abfeeSchristos compat_drm_dma(struct file *file, void *arg)
562842abfeeSchristos {
563842abfeeSchristos drm_dma32_t d32;
564842abfeeSchristos struct drm_dma d64;
565842abfeeSchristos int error;
566842abfeeSchristos
567842abfeeSchristos if ((error = copyin(&d32, arg, sizeof(d32))) != 0)
568842abfeeSchristos return error;
569842abfeeSchristos
570e1a89edaSchristos dma32to64(&d64, &d32);
571842abfeeSchristos
572842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_DMA, &d64);
573842abfeeSchristos if (error)
574842abfeeSchristos return error;
575842abfeeSchristos
576e1a89edaSchristos dma64to32(&d32, &d64);
577842abfeeSchristos
578e1a89edaSchristos return copyout(arg, &d32, sizeof(d32));
579842abfeeSchristos }
580842abfeeSchristos
581842abfeeSchristos //XXX:i commented the below line for later use
582842abfeeSchristos #if IS_ENABLED(CONFIG_AGP)
583842abfeeSchristos typedef struct drm_agp_mode32 {
584842abfeeSchristos uint32_t mode; /**< AGP mode */
585842abfeeSchristos } drm_agp_mode32_t;
586842abfeeSchristos
587842abfeeSchristos static int
compat_drm_agp_enable(struct file * file,void * arg)588842abfeeSchristos compat_drm_agp_enable(struct file *file, void *arg)
589842abfeeSchristos {
590842abfeeSchristos drm_agp_mode32_t m32;
591842abfeeSchristos struct drm_agp_mode m64;
592842abfeeSchristos int error;
593842abfeeSchristos
594842abfeeSchristos if ((error = copyin(&m32, arg, sizeof(m32))) != 0)
595842abfeeSchristos return error;
596842abfeeSchristos
597e1a89edaSchristos m64.mode = m32.mode;
598842abfeeSchristos
599842abfeeSchristos return drm_ioctl(file, DRM_IOCTL_AGP_ENABLE, &m64);
600842abfeeSchristos }
601842abfeeSchristos
602842abfeeSchristos typedef struct drm_agp_info32 {
603842abfeeSchristos int agp_version_major;
604842abfeeSchristos int agp_version_minor;
605842abfeeSchristos uint32_t mode;
606842abfeeSchristos uint32_t aperture_base; /* physical address */
607842abfeeSchristos uint32_t aperture_size; /* bytes */
608842abfeeSchristos uint32_t memory_allowed; /* bytes */
609842abfeeSchristos uint32_t memory_used;
610842abfeeSchristos
611842abfeeSchristos /* PCI information */
612842abfeeSchristos unsigned short id_vendor;
613842abfeeSchristos unsigned short id_device;
614842abfeeSchristos } drm_agp_info32_t;
615842abfeeSchristos
616842abfeeSchristos static void
info64to32(drm_agp_info32_t * i32,const struct drm_agp_info * i64)617e1a89edaSchristos info64to32(drm_agp_info32_t *i32, const struct drm_agp_info *i64)
618842abfeeSchristos {
619e1a89edaSchristos i32->agp_version_major = i64->agp_version_major;
620e1a89edaSchristos i32->agp_version_minor = i64->agp_version_minor;
621e1a89edaSchristos i32->mode = i64->mode;
622e1a89edaSchristos i32->aperture_base = i64->aperture_base;
623e1a89edaSchristos i32->aperture_size = i64->aperture_size;
624e1a89edaSchristos i32->memory_allowed = i64->memory_allowed;
625e1a89edaSchristos i32->memory_used = i64->memory_used;
626e1a89edaSchristos i32->id_vendor = i64->id_vendor;
627e1a89edaSchristos i32->id_device = i64->id_device;
628842abfeeSchristos }
629842abfeeSchristos
630842abfeeSchristos static int
compat_drm_agp_info(struct file * file,void * arg)631842abfeeSchristos compat_drm_agp_info(struct file *file, void *arg)
632842abfeeSchristos {
633842abfeeSchristos drm_agp_info32_t i32;
634842abfeeSchristos struct drm_agp_info i64;
635842abfeeSchristos int error;
636842abfeeSchristos
637842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_AGP_INFO, &i64);
638842abfeeSchristos if (error)
639842abfeeSchristos return error;
640842abfeeSchristos
641e1a89edaSchristos info64to32(&i32, &i64);
642842abfeeSchristos
643842abfeeSchristos return copyout(arg, &i32, sizeof(i32));
644842abfeeSchristos
645842abfeeSchristos }
646842abfeeSchristos
647842abfeeSchristos typedef struct drm_agp_buffer32 {
648842abfeeSchristos uint32_t size; /**< In bytes -- will round to page boundary */
649842abfeeSchristos uint32_t handle; /**< Used for binding / unbinding */
650842abfeeSchristos uint32_t type; /**< Type of memory to allocate */
651842abfeeSchristos uint32_t physical; /**< Physical used by i810 */
652842abfeeSchristos } drm_agp_buffer32_t;
653842abfeeSchristos
654842abfeeSchristos static int
compat_drm_agp_alloc(struct file * file,void * arg)655842abfeeSchristos compat_drm_agp_alloc(struct file *file, void *arg)
656842abfeeSchristos {
657842abfeeSchristos drm_agp_buffer32_t req32;
658842abfeeSchristos struct drm_agp_buffer req64;
659842abfeeSchristos int error;
660842abfeeSchristos
661842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
662842abfeeSchristos return error;
663842abfeeSchristos
664842abfeeSchristos req64.size = req32.size;
665842abfeeSchristos req64.type = req32.type;
666842abfeeSchristos
667842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_AGP_ALLOC, &req64);
668842abfeeSchristos if (error)
669842abfeeSchristos return error;
670842abfeeSchristos
671842abfeeSchristos req32.handle = req64.handle;
672842abfeeSchristos req32.physical = req64.physical;
673842abfeeSchristos
674842abfeeSchristos drm_ioctl(file, DRM_IOCTL_AGP_FREE, &req64);
675842abfeeSchristos
676842abfeeSchristos return copyout(arg, &req32, sizeof(req32));
677842abfeeSchristos }
678842abfeeSchristos
679842abfeeSchristos static int
compat_drm_agp_free(struct file * file,void * arg)680842abfeeSchristos compat_drm_agp_free(struct file *file, void *arg)
681842abfeeSchristos {
682842abfeeSchristos drm_agp_buffer32_t req32;
683842abfeeSchristos struct drm_agp_buffer req64;
684842abfeeSchristos int error;
685842abfeeSchristos uint32_t handle;
686842abfeeSchristos
687842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
688842abfeeSchristos return error;
689842abfeeSchristos
690842abfeeSchristos handle = req32.handle;
691842abfeeSchristos req64.handle = handle;
692842abfeeSchristos
693842abfeeSchristos return drm_ioctl(file, DRM_IOCTL_AGP_FREE, &req64);
694842abfeeSchristos }
695842abfeeSchristos
696842abfeeSchristos typedef struct drm_agp_binding32 {
697842abfeeSchristos uint32_t handle; /**< From drm_agp_buffer */
698842abfeeSchristos uint32_t offset; /**< In bytes -- will round to page boundary */
699842abfeeSchristos } drm_agp_binding32_t;
700842abfeeSchristos
701842abfeeSchristos static int
compat_drm_agp_bind(struct file * file,void * arg)702842abfeeSchristos compat_drm_agp_bind(struct file *file, void *arg)
703842abfeeSchristos {
704842abfeeSchristos drm_agp_binding32_t req32;
705842abfeeSchristos struct drm_agp_binding req64;
706842abfeeSchristos int error;
707842abfeeSchristos
708842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) !=0 )
709842abfeeSchristos return error;
710842abfeeSchristos
711842abfeeSchristos req64.handle = req32.handle;
712842abfeeSchristos req64.offset = req32.offset;
713842abfeeSchristos
714842abfeeSchristos return drm_ioctl(file, DRM_IOCTL_AGP_BIND, &req64);
715842abfeeSchristos }
716842abfeeSchristos
717842abfeeSchristos static int
compat_drm_agp_unbind(struct file * file,void * arg)718842abfeeSchristos compat_drm_agp_unbind(struct file *file, void *arg)
719842abfeeSchristos {
720842abfeeSchristos struct drm_agp_binding req64;
721842abfeeSchristos drm_agp_binding32_t req32;
722842abfeeSchristos uint32_t handle;
723842abfeeSchristos int error;
724842abfeeSchristos
725842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
726842abfeeSchristos return error;
727842abfeeSchristos
728842abfeeSchristos handle = req32.handle;
729842abfeeSchristos req64.handle = handle;
730842abfeeSchristos
731842abfeeSchristos return drm_ioctl(file, DRM_IOCTL_AGP_UNBIND, &req64);
732842abfeeSchristos }
733842abfeeSchristos #endif /* CONFIG_AGP */
734842abfeeSchristos
735842abfeeSchristos typedef struct drm_scatter_gather32 {
736842abfeeSchristos uint32_t size; /**< In bytes -- will round to page boundary */
737842abfeeSchristos uint32_t handle; /**< Used for mapping / unmapping */
738842abfeeSchristos } drm_scatter_gather32_t;
739842abfeeSchristos
740842abfeeSchristos static int
compat_drm_sg_alloc(struct file * file,void * arg)741842abfeeSchristos compat_drm_sg_alloc(struct file *file, void *arg)
742842abfeeSchristos {
743842abfeeSchristos struct drm_scatter_gather req64;
744842abfeeSchristos drm_scatter_gather32_t req32;
745842abfeeSchristos int error;
746842abfeeSchristos
747842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
748842abfeeSchristos return error;
749842abfeeSchristos
750842abfeeSchristos req64.size = req32.size;
751842abfeeSchristos
752842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_SG_ALLOC, &req64);
753842abfeeSchristos if (error)
754842abfeeSchristos return error;
755842abfeeSchristos
756842abfeeSchristos /* XXX not sure about the handle conversion here... */
757842abfeeSchristos req32.handle = req64.handle >> PAGE_SHIFT;
758842abfeeSchristos
759842abfeeSchristos return 0;
760842abfeeSchristos }
761842abfeeSchristos
762842abfeeSchristos static int
compat_drm_sg_free(struct file * file,void * arg)763842abfeeSchristos compat_drm_sg_free(struct file *file, void *arg)
764842abfeeSchristos {
765842abfeeSchristos struct drm_scatter_gather req64;
766842abfeeSchristos unsigned long x;
767842abfeeSchristos drm_scatter_gather32_t req32;
768842abfeeSchristos int error;
769842abfeeSchristos
770842abfeeSchristos if((error = copyin(&req32, arg, sizeof(req32))) != 0)
771842abfeeSchristos return error;
772842abfeeSchristos
773842abfeeSchristos x = req32.handle;
774842abfeeSchristos req64.handle = x << PAGE_SHIFT;
775842abfeeSchristos
776842abfeeSchristos return drm_ioctl(file, DRM_IOCTL_SG_FREE, &req64);
777842abfeeSchristos }
778842abfeeSchristos
779842abfeeSchristos #if defined(CONFIG_X86) || defined(CONFIG_IA64)
780842abfeeSchristos typedef struct drm_update_draw32 {
781842abfeeSchristos drm_drawable_t handle;
782842abfeeSchristos unsigned int type;
783842abfeeSchristos unsigned int num;
784842abfeeSchristos /* 64-bit version has a 32-bit pad here */
785842abfeeSchristos uint64_t data; /**< Pointer */
786842abfeeSchristos } __attribute__((__packed__)) drm_update_draw32_t;
787842abfeeSchristos
788842abfeeSchristos static void
update32to64(struct drm_update_draw * req64,const drm_update_draw32_t * update32)789842abfeeSchristos update32to64(struct drm_update_draw *req64, const drm_update_draw32_t *update32)
790842abfeeSchristos {
791842abfeeSchristos req64->handle = update32->handle;
792842abfeeSchristos req64->type = update32->type;
793842abfeeSchristos req64->num = update32->num;
794842abfeeSchristos req64->data = update32->data;
795842abfeeSchristos }
796842abfeeSchristos static int
compat_drm_update_draw(struct file * file,void * arg)797842abfeeSchristos compat_drm_update_draw(struct file *file, void *arg)
798842abfeeSchristos {
799842abfeeSchristos drm_update_draw32_t update32;
800842abfeeSchristos struct drm_update_draw req64;
801842abfeeSchristos int error;
802842abfeeSchristos
803842abfeeSchristos if ((error = copyin(&update32, arg, sizeof(update32))) !=0)
804842abfeeSchristos return error;
805842abfeeSchristos
806842abfeeSchristos update32to64(&req64, &update32);
807842abfeeSchristos
808842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_UPDATE_DRAW, &req64);
809842abfeeSchristos return error;
810842abfeeSchristos }
811842abfeeSchristos #endif
812842abfeeSchristos
813842abfeeSchristos struct drm_wait_vblank_request32 {
814842abfeeSchristos enum drm_vblank_seq_type type;
815842abfeeSchristos unsigned int sequence;
816842abfeeSchristos uint32_t signal;
817842abfeeSchristos };
818842abfeeSchristos
819842abfeeSchristos struct drm_wait_vblank_reply32 {
820842abfeeSchristos enum drm_vblank_seq_type type;
821842abfeeSchristos unsigned int sequence;
822842abfeeSchristos s32 tval_sec;
823842abfeeSchristos s32 tval_usec;
824842abfeeSchristos };
825842abfeeSchristos
826842abfeeSchristos typedef union drm_wait_vblank32 {
827842abfeeSchristos struct drm_wait_vblank_request32 request;
828842abfeeSchristos struct drm_wait_vblank_reply32 reply;
829842abfeeSchristos } drm_wait_vblank32_t;
830842abfeeSchristos
831842abfeeSchristos static void
req32to64(union drm_wait_vblank * req64,const drm_wait_vblank32_t * req32)832842abfeeSchristos req32to64(union drm_wait_vblank *req64, const drm_wait_vblank32_t *req32)
833842abfeeSchristos {
834842abfeeSchristos req64->request.type = req32->request.type;
835842abfeeSchristos req64->request.sequence = req32->request.sequence;
836842abfeeSchristos req64->request.signal = req32->request.signal;
837842abfeeSchristos }
838842abfeeSchristos
839842abfeeSchristos static void
req64to32(drm_wait_vblank32_t * req32,const union drm_wait_vblank * req64)840842abfeeSchristos req64to32(drm_wait_vblank32_t *req32, const union drm_wait_vblank *req64)
841842abfeeSchristos {
842842abfeeSchristos req32->reply.sequence = req64->reply.sequence;
843842abfeeSchristos req32->reply.tval_sec = req64->reply.tval_sec;
844842abfeeSchristos req32->reply.tval_usec = req64->reply.tval_usec;
845842abfeeSchristos }
846842abfeeSchristos
847842abfeeSchristos static int
compat_drm_wait_vblank(struct file * file,void * arg)848842abfeeSchristos compat_drm_wait_vblank(struct file *file, void *arg)
849842abfeeSchristos {
850842abfeeSchristos drm_wait_vblank32_t req32;
851842abfeeSchristos union drm_wait_vblank req64;
852842abfeeSchristos int error;
853842abfeeSchristos
854842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
855842abfeeSchristos return error;
856842abfeeSchristos
857842abfeeSchristos req32to64(&req64, &req32);
858842abfeeSchristos
859842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_WAIT_VBLANK, &req64);
860842abfeeSchristos if (error)
861842abfeeSchristos return error;
862842abfeeSchristos
863842abfeeSchristos req64to32(&req32, &req64);
864842abfeeSchristos
865842abfeeSchristos return copyout(arg, &req32, sizeof(req32));
866842abfeeSchristos }
867842abfeeSchristos
868842abfeeSchristos #if defined(CONFIG_X86) || defined(CONFIG_IA64)
869842abfeeSchristos typedef struct drm_mode_fb_cmd232 {
870842abfeeSchristos uint32_t fb_id;
871842abfeeSchristos uint32_t width;
872842abfeeSchristos uint32_t height;
873842abfeeSchristos uint32_t pixel_format;
874842abfeeSchristos uint32_t flags;
875842abfeeSchristos uint32_t handles[4];
876842abfeeSchristos uint32_t pitches[4];
877842abfeeSchristos uint32_t offsets[4];
878842abfeeSchristos uint64_t modifier[4];
879842abfeeSchristos } __attribute__((__packed__)) drm_mode_fb_cmd232_t;
880842abfeeSchristos
881842abfeeSchristos static void
map_req32to64(struct drm_mode_fb_cmd2 * req64,struct drm_mode_fb_cmd232 * req32)882842abfeeSchristos map_req32to64(struct drm_mode_fb_cmd2 *req64, struct drm_mode_fb_cmd232 *req32)
883842abfeeSchristos {
884842abfeeSchristos req64->width = req32->width;
885842abfeeSchristos req64->height = req32->height;
886842abfeeSchristos req64->pixel_format = req32->pixel_format;
887842abfeeSchristos req64->flags = req32->flags;
888842abfeeSchristos }
889842abfeeSchristos
890842abfeeSchristos static int
compat_drm_mode_addfb2(struct file * file,void * arg)891842abfeeSchristos compat_drm_mode_addfb2(struct file *file, void *arg)
892842abfeeSchristos {
893842abfeeSchristos struct drm_mode_fb_cmd232 req32;
894842abfeeSchristos struct drm_mode_fb_cmd2 req64;
895842abfeeSchristos int error;
896842abfeeSchristos
897842abfeeSchristos if ((error = copyin(&req32, arg, sizeof(req32))) != 0)
898842abfeeSchristos return error;
899842abfeeSchristos
900842abfeeSchristos map_req32to64(&req64, &req32);
901842abfeeSchristos
902842abfeeSchristos for (int i = 0; i < 4; i++){
903842abfeeSchristos req64.handles[i] = req32.handles[i];
904842abfeeSchristos req64.pitches[i] = req32.pitches[i];
905842abfeeSchristos req64.offsets[i] = req32.offsets[i];
906842abfeeSchristos req64.modifier[i] = req32.modifier[i];
907842abfeeSchristos }
908842abfeeSchristos
909842abfeeSchristos error = drm_ioctl(file, DRM_IOCTL_MODE_ADDFB2, &req64);
910842abfeeSchristos if (error)
911842abfeeSchristos return error;
912842abfeeSchristos
913842abfeeSchristos req32.fb_id = req64.fb_id;
914842abfeeSchristos
915842abfeeSchristos return copyout(arg, &req32, sizeof(req32));
916842abfeeSchristos }
917842abfeeSchristos #endif
918842abfeeSchristos
919842abfeeSchristos int
netbsd32_drm_ioctl(struct file * file,unsigned long cmd,void * arg,struct lwp * l)920842abfeeSchristos netbsd32_drm_ioctl(struct file *file, unsigned long cmd, void *arg,
921842abfeeSchristos struct lwp *l)
922842abfeeSchristos {
923842abfeeSchristos switch (cmd) {
924842abfeeSchristos case DRM_IOCTL_VERSION32:
925842abfeeSchristos return compat_drm_version(file, arg);
926842abfeeSchristos case DRM_IOCTL_GET_UNIQUE32:
927842abfeeSchristos return compat_drm_getunique(file, arg);
928842abfeeSchristos case DRM_IOCTL_SET_UNIQUE32:
929842abfeeSchristos return compat_drm_setunique(file, arg);
930842abfeeSchristos case DRM_IOCTL_GET_MAP32:
931842abfeeSchristos return compat_drm_getmap(file, arg);
932842abfeeSchristos case DRM_IOCTL_ADD_MAP32:
933842abfeeSchristos return compat_drm_addmap(file, arg);
934842abfeeSchristos case DRM_IOCTL_RM_MAP32:
935842abfeeSchristos return compat_drm_rmmap(file, arg);
936842abfeeSchristos case DRM_IOCTL_GET_CLIENT32:
937842abfeeSchristos return compat_drm_getclient(file, arg);
938842abfeeSchristos case DRM_IOCTL_GET_STATS32:
939842abfeeSchristos return compat_drm_getstats(file, arg);
940842abfeeSchristos case DRM_IOCTL_ADD_BUFS32:
941842abfeeSchristos return compat_drm_addbufs(file, arg);
942842abfeeSchristos case DRM_IOCTL_MARK_BUFS32:
943842abfeeSchristos return compat_drm_markbufs(file, arg);
944842abfeeSchristos case DRM_IOCTL_FREE_BUFS32:
945842abfeeSchristos return compat_drm_freebufs(file, arg);
946842abfeeSchristos case DRM_IOCTL_SET_SAREA_CTX32:
947842abfeeSchristos return compat_drm_setsareactx(file, arg);
948842abfeeSchristos case DRM_IOCTL_GET_SAREA_CTX32:
949842abfeeSchristos return compat_drm_getsareactx(file, arg);
950842abfeeSchristos case DRM_IOCTL_RES_CTX32:
951842abfeeSchristos return compat_drm_resctx(file, arg);
952842abfeeSchristos case DRM_IOCTL_DMA32:
953842abfeeSchristos return compat_drm_dma(file, arg);
954842abfeeSchristos case DRM_IOCTL_AGP_ENABLE32:
955842abfeeSchristos return compat_drm_agp_enable(file, arg);
956842abfeeSchristos case DRM_IOCTL_AGP_INFO32:
957842abfeeSchristos return compat_drm_agp_info(file, arg);
958842abfeeSchristos case DRM_IOCTL_AGP_ALLOC32:
959842abfeeSchristos return compat_drm_agp_alloc(file,arg);
960842abfeeSchristos case DRM_IOCTL_AGP_UNBIND32:
961842abfeeSchristos return compat_drm_agp_unbind(file, arg);
962842abfeeSchristos case DRM_IOCTL_AGP_BIND32:
963842abfeeSchristos return compat_drm_agp_bind(file, arg);
964842abfeeSchristos case DRM_IOCTL_AGP_FREE32:
965842abfeeSchristos return compat_drm_agp_free(file, arg);
966842abfeeSchristos case DRM_IOCTL_SG_ALLOC32:
967842abfeeSchristos return compat_drm_sg_alloc(file, arg);
968842abfeeSchristos case DRM_IOCTL_MODE_ADDFB232:
969842abfeeSchristos return compat_drm_mode_addfb2(file, arg);
970842abfeeSchristos case DRM_IOCTL_WAIT_VBLANK32:
971842abfeeSchristos return compat_drm_wait_vblank(file, arg);
972842abfeeSchristos case DRM_IOCTL_UPDATE_DRAW32:
973842abfeeSchristos return compat_drm_update_draw(file, arg);
974842abfeeSchristos case DRM_IOCTL_SG_FREE32:
975842abfeeSchristos return compat_drm_sg_free(file, arg);
976842abfeeSchristos default:
977842abfeeSchristos return EINVAL;
978842abfeeSchristos }
979842abfeeSchristos }
980