xref: /freebsd/sys/dev/drm2/drm_ioc32.c (revision 685dc743dc3b5645e34836464128e1c0558b404b)
1 /*-
2  * Copyright (C) Paul Mackerras 2005.
3  * All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the next
13  * paragraph) shall be included in all copies or substantial portions of the
14  * Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  */
24 
25 #include <sys/cdefs.h>
26 #ifdef COMPAT_FREEBSD32
27 
28 #include <dev/drm2/drmP.h>
29 #include <dev/drm2/drm.h>
30 
31 #define DRM_IOCTL_VERSION32		DRM_IOWR(0x00, drm_version32_t)
32 #define DRM_IOCTL_GET_UNIQUE32		DRM_IOWR(0x01, drm_unique32_t)
33 #define DRM_IOCTL_GET_MAP32		DRM_IOWR(0x04, drm_map32_t)
34 #define DRM_IOCTL_GET_CLIENT32		DRM_IOWR(0x05, drm_client32_t)
35 #define DRM_IOCTL_GET_STATS32		DRM_IOR( 0x06, drm_stats32_t)
36 
37 #define DRM_IOCTL_SET_UNIQUE32		DRM_IOW( 0x10, drm_unique32_t)
38 #define DRM_IOCTL_ADD_MAP32		DRM_IOWR(0x15, drm_map32_t)
39 #define DRM_IOCTL_ADD_BUFS32		DRM_IOWR(0x16, drm_buf_desc32_t)
40 #define DRM_IOCTL_MARK_BUFS32		DRM_IOW( 0x17, drm_buf_desc32_t)
41 #define DRM_IOCTL_INFO_BUFS32		DRM_IOWR(0x18, drm_buf_info32_t)
42 #define DRM_IOCTL_MAP_BUFS32		DRM_IOWR(0x19, drm_buf_map32_t)
43 #define DRM_IOCTL_FREE_BUFS32		DRM_IOW( 0x1a, drm_buf_free32_t)
44 
45 #define DRM_IOCTL_RM_MAP32		DRM_IOW( 0x1b, drm_map32_t)
46 
47 #define DRM_IOCTL_SET_SAREA_CTX32	DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
48 #define DRM_IOCTL_GET_SAREA_CTX32	DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
49 
50 #define DRM_IOCTL_RES_CTX32		DRM_IOWR(0x26, drm_ctx_res32_t)
51 #define DRM_IOCTL_DMA32			DRM_IOWR(0x29, drm_dma32_t)
52 
53 #define DRM_IOCTL_AGP_ENABLE32		DRM_IOW( 0x32, drm_agp_mode32_t)
54 #define DRM_IOCTL_AGP_INFO32		DRM_IOR( 0x33, drm_agp_info32_t)
55 #define DRM_IOCTL_AGP_ALLOC32		DRM_IOWR(0x34, drm_agp_buffer32_t)
56 #define DRM_IOCTL_AGP_FREE32		DRM_IOW( 0x35, drm_agp_buffer32_t)
57 #define DRM_IOCTL_AGP_BIND32		DRM_IOW( 0x36, drm_agp_binding32_t)
58 #define DRM_IOCTL_AGP_UNBIND32		DRM_IOW( 0x37, drm_agp_binding32_t)
59 
60 #define DRM_IOCTL_SG_ALLOC32		DRM_IOW( 0x38, drm_scatter_gather32_t)
61 #define DRM_IOCTL_SG_FREE32		DRM_IOW( 0x39, drm_scatter_gather32_t)
62 
63 #define DRM_IOCTL_UPDATE_DRAW32		DRM_IOW( 0x3f, drm_update_draw32_t)
64 
65 #define DRM_IOCTL_WAIT_VBLANK32		DRM_IOWR(0x3a, drm_wait_vblank32_t)
66 
67 typedef struct drm_version_32 {
68 	int version_major;	  /**< Major version */
69 	int version_minor;	  /**< Minor version */
70 	int version_patchlevel;	   /**< Patch level */
71 	u32 name_len;		  /**< Length of name buffer */
72 	u32 name;		  /**< Name of driver */
73 	u32 date_len;		  /**< Length of date buffer */
74 	u32 date;		  /**< User-space buffer to hold date */
75 	u32 desc_len;		  /**< Length of desc buffer */
76 	u32 desc;		  /**< User-space buffer to hold desc */
77 } drm_version32_t;
78 
compat_drm_version(struct drm_device * dev,void * data,struct drm_file * file_priv)79 static int compat_drm_version(struct drm_device *dev, void *data,
80     struct drm_file *file_priv)
81 {
82 	drm_version32_t *v32 = data;
83 	struct drm_version version;
84 	int err;
85 
86 	version.name_len = v32->name_len;
87 	version.name = (void *)(unsigned long)v32->name;
88 	version.date_len = v32->date_len;
89 	version.date = (void *)(unsigned long)v32->date;
90 	version.desc_len = v32->desc_len;
91 	version.desc = (void *)(unsigned long)v32->desc;
92 
93 	err = drm_version(dev, (void *)&version, file_priv);
94 	if (err)
95 		return err;
96 
97 	v32->version_major = version.version_major;
98 	v32->version_minor = version.version_minor;
99 	v32->version_patchlevel = version.version_patchlevel;
100 	v32->name_len = version.name_len;
101 	v32->date_len = version.date_len;
102 	v32->desc_len = version.desc_len;
103 
104 	return 0;
105 }
106 
107 typedef struct drm_unique32 {
108 	u32 unique_len;	/**< Length of unique */
109 	u32 unique;	/**< Unique name for driver instantiation */
110 } drm_unique32_t;
111 
compat_drm_getunique(struct drm_device * dev,void * data,struct drm_file * file_priv)112 static int compat_drm_getunique(struct drm_device *dev, void *data,
113     struct drm_file *file_priv)
114 {
115 	drm_unique32_t *uq32 = data;
116 	struct drm_unique u;
117 	int err;
118 
119 	u.unique_len = uq32->unique_len;
120 	u.unique = (void *)(unsigned long)uq32->unique;
121 
122 	err = drm_getunique(dev, (void *)&u, file_priv);
123 	if (err)
124 		return err;
125 
126 	uq32->unique_len = u.unique_len;
127 
128 	return 0;
129 }
130 
compat_drm_setunique(struct drm_device * dev,void * data,struct drm_file * file_priv)131 static int compat_drm_setunique(struct drm_device *dev, void *data,
132     struct drm_file *file_priv)
133 {
134 	drm_unique32_t *uq32 = data;
135 	struct drm_unique u;
136 
137 	u.unique_len = uq32->unique_len;
138 	u.unique = (void *)(unsigned long)uq32->unique;
139 
140 	return drm_setunique(dev, (void *)&u, file_priv);
141 }
142 
143 typedef struct drm_map32 {
144 	u32 offset;		/**< Requested physical address (0 for SAREA)*/
145 	u32 size;		/**< Requested physical size (bytes) */
146 	enum drm_map_type type;	/**< Type of memory to map */
147 	enum drm_map_flags flags;	/**< Flags */
148 	u32 handle;		/**< User-space: "Handle" to pass to mmap() */
149 	int mtrr;		/**< MTRR slot used */
150 } drm_map32_t;
151 
compat_drm_getmap(struct drm_device * dev,void * data,struct drm_file * file_priv)152 static int compat_drm_getmap(struct drm_device *dev, void *data,
153     struct drm_file *file_priv)
154 {
155 	drm_map32_t *m32 = data;
156 	struct drm_map map;
157 	int err;
158 	void *handle;
159 
160 	map.offset = (unsigned long)m32->offset;
161 
162 	err = drm_getmap(dev, (void *)&map, file_priv);
163 	if (err)
164 		return err;
165 
166 	m32->offset = map.offset;
167 	m32->size = map.size;
168 	m32->type = map.type;
169 	m32->flags = map.flags;
170 	handle = map.handle;
171 	m32->mtrr = map.mtrr;
172 
173 	m32->handle = (unsigned long)handle;
174 
175 	return 0;
176 
177 }
178 
compat_drm_addmap(struct drm_device * dev,void * data,struct drm_file * file_priv)179 static int compat_drm_addmap(struct drm_device *dev, void *data,
180     struct drm_file *file_priv)
181 {
182 	drm_map32_t *m32 = data;
183 	struct drm_map map;
184 	int err;
185 	void *handle;
186 
187 	map.offset = (unsigned long)m32->offset;
188 	map.size = (unsigned long)m32->size;
189 	map.type = m32->type;
190 	map.flags = m32->flags;
191 
192 	err = drm_addmap_ioctl(dev, (void *)&map, file_priv);
193 	if (err)
194 		return err;
195 
196 	m32->offset = map.offset;
197 	m32->mtrr = map.mtrr;
198 	handle = map.handle;
199 
200 	m32->handle = (unsigned long)handle;
201 	if (m32->handle != (unsigned long)handle)
202 		DRM_DEBUG("compat_drm_addmap truncated handle"
203 				   " %p for type %d offset %x\n",
204 				   handle, m32->type, m32->offset);
205 
206 	return 0;
207 }
208 
compat_drm_rmmap(struct drm_device * dev,void * data,struct drm_file * file_priv)209 static int compat_drm_rmmap(struct drm_device *dev, void *data,
210     struct drm_file *file_priv)
211 {
212 	drm_map32_t *m32 = data;
213 	struct drm_map map;
214 
215 	map.handle = (void *)(unsigned long)m32->handle;
216 
217 	return drm_rmmap_ioctl(dev, (void *)&map, file_priv);
218 }
219 
220 typedef struct drm_client32 {
221 	int idx;	/**< Which client desired? */
222 	int auth;	/**< Is client authenticated? */
223 	u32 pid;	/**< Process ID */
224 	u32 uid;	/**< User ID */
225 	u32 magic;	/**< Magic */
226 	u32 iocs;	/**< Ioctl count */
227 } drm_client32_t;
228 
compat_drm_getclient(struct drm_device * dev,void * data,struct drm_file * file_priv)229 static int compat_drm_getclient(struct drm_device *dev, void *data,
230     struct drm_file *file_priv)
231 {
232 	drm_client32_t *c32 = data;
233 	struct drm_client client;
234 	int err;
235 
236 	client.idx = c32->idx;
237 
238 	err = drm_getclient(dev, (void *)&client, file_priv);
239 	if (err)
240 		return err;
241 
242 	c32->idx = client.idx;
243 	c32->auth = client.auth;
244 	c32->pid = client.pid;
245 	c32->uid = client.uid;
246 	c32->magic = client.magic;
247 	c32->iocs = client.iocs;
248 
249 	return 0;
250 }
251 
252 typedef struct drm_stats32 {
253 	u32 count;
254 	struct {
255 		u32 value;
256 		enum drm_stat_type type;
257 	} data[15];
258 } drm_stats32_t;
259 
compat_drm_getstats(struct drm_device * dev,void * data,struct drm_file * file_priv)260 static int compat_drm_getstats(struct drm_device *dev, void *data,
261     struct drm_file *file_priv)
262 {
263 	drm_stats32_t *s32 = data;
264 	struct drm_stats stats;
265 	int i, err;
266 
267 	err = drm_getstats(dev, (void *)&stats, file_priv);
268 	if (err)
269 		return err;
270 
271 	s32->count = stats.count;
272 	for (i = 0; i < stats.count; i++) {
273 		s32->data[i].value = stats.data[i].value;
274 		s32->data[i].type = stats.data[i].type;
275 	}
276 
277 	return 0;
278 }
279 
280 typedef struct drm_buf_desc32 {
281 	int count;		 /**< Number of buffers of this size */
282 	int size;		 /**< Size in bytes */
283 	int low_mark;		 /**< Low water mark */
284 	int high_mark;		 /**< High water mark */
285 	int flags;
286 	u32 agp_start;		 /**< Start address in the AGP aperture */
287 } drm_buf_desc32_t;
288 
compat_drm_addbufs(struct drm_device * dev,void * data,struct drm_file * file_priv)289 static int compat_drm_addbufs(struct drm_device *dev, void *data,
290     struct drm_file *file_priv)
291 {
292 	drm_buf_desc32_t *b32 = data;
293 	struct drm_buf_desc buf;
294 	int err;
295 
296 	buf.count = b32->count;
297 	buf.size = b32->size;
298 	buf.low_mark = b32->low_mark;
299 	buf.high_mark = b32->high_mark;
300 	buf.flags = b32->flags;
301 	buf.agp_start = (unsigned long)b32->agp_start;
302 
303 	err = drm_addbufs(dev, (void *)&buf, file_priv);
304 	if (err)
305 		return err;
306 
307 	b32->count = buf.count;
308 	b32->size = buf.size;
309 	b32->low_mark = buf.low_mark;
310 	b32->high_mark = buf.high_mark;
311 	b32->flags = buf.flags;
312 	b32->agp_start = buf.agp_start;
313 
314 	return 0;
315 }
316 
compat_drm_markbufs(struct drm_device * dev,void * data,struct drm_file * file_priv)317 static int compat_drm_markbufs(struct drm_device *dev, void *data,
318     struct drm_file *file_priv)
319 {
320 	drm_buf_desc32_t *b32 = data;
321 	struct drm_buf_desc buf;
322 
323 	buf.size = b32->size;
324 	buf.low_mark = b32->low_mark;
325 	buf.high_mark = b32->high_mark;
326 
327 	return drm_markbufs(dev, (void *)&buf, file_priv);
328 }
329 
330 typedef struct drm_buf_info32 {
331 	int count;		/**< Entries in list */
332 	u32 list;
333 } drm_buf_info32_t;
334 
compat_drm_infobufs(struct drm_device * dev,void * data,struct drm_file * file_priv)335 static int compat_drm_infobufs(struct drm_device *dev, void *data,
336     struct drm_file *file_priv)
337 {
338 	drm_buf_info32_t *req32 = data;
339 	drm_buf_desc32_t *to;
340 	struct drm_buf_info *request;
341 	struct drm_buf_desc *list;
342 	size_t nbytes;
343 	int i, err;
344 	int count, actual;
345 
346 	count = req32->count;
347 	to = (drm_buf_desc32_t *)(unsigned long)req32->list;
348 	if (count < 0)
349 		count = 0;
350 
351 	nbytes = sizeof(*request) + count * sizeof(struct drm_buf_desc);
352 	request = malloc(nbytes, DRM_MEM_BUFLISTS, M_ZERO | M_NOWAIT);
353 	if (!request)
354 		return -ENOMEM;
355 	list = (struct drm_buf_desc *) (request + 1);
356 
357 	request->count = count;
358 	request->list = list;
359 
360 	err = drm_infobufs(dev, (void *)request, file_priv);
361 	if (err)
362 		return err;
363 
364 	actual = request->count;
365 	if (count >= actual)
366 		for (i = 0; i < actual; ++i) {
367 			to[i].count = list[i].count;
368 			to[i].size = list[i].size;
369 			to[i].low_mark = list[i].low_mark;
370 			to[i].high_mark = list[i].high_mark;
371 			to[i].flags = list[i].flags;
372 		}
373 
374 	req32->count = actual;
375 
376 	return 0;
377 }
378 
379 typedef struct drm_buf_pub32 {
380 	int idx;		/**< Index into the master buffer list */
381 	int total;		/**< Buffer size */
382 	int used;		/**< Amount of buffer in use (for DMA) */
383 	u32 address;		/**< Address of buffer */
384 } drm_buf_pub32_t;
385 
386 typedef struct drm_buf_map32 {
387 	int count;		/**< Length of the buffer list */
388 	u32 virtual;		/**< Mmap'd area in user-virtual */
389 	u32 list;		/**< Buffer information */
390 } drm_buf_map32_t;
391 
compat_drm_mapbufs(struct drm_device * dev,void * data,struct drm_file * file_priv)392 static int compat_drm_mapbufs(struct drm_device *dev, void *data,
393     struct drm_file *file_priv)
394 {
395 	drm_buf_map32_t *req32 = data;
396 	drm_buf_pub32_t *list32;
397 	struct drm_buf_map *request;
398 	struct drm_buf_pub *list;
399 	int i, err;
400 	int count, actual;
401 	size_t nbytes;
402 
403 	count = req32->count;
404 	list32 = (void *)(unsigned long)req32->list;
405 
406 	if (count < 0)
407 		return -EINVAL;
408 	nbytes = sizeof(*request) + count * sizeof(struct drm_buf_pub);
409 	request = malloc(nbytes, DRM_MEM_BUFLISTS, M_ZERO | M_NOWAIT);
410 	if (!request)
411 		return -ENOMEM;
412 	list = (struct drm_buf_pub *) (request + 1);
413 
414 	request->count = count;
415 	request->list = list;
416 
417 	err = drm_mapbufs(dev, (void *)request, file_priv);
418 	if (err)
419 		return err;
420 
421 	actual = request->count;
422 	if (count >= actual)
423 		for (i = 0; i < actual; ++i) {
424 			list32[i].idx = list[i].idx;
425 			list32[i].total = list[i].total;
426 			list32[i].used = list[i].used;
427 			list32[i].address = (unsigned long)list[i].address;
428 		}
429 
430 	req32->count = actual;
431 	req32->virtual = (unsigned long)request->virtual;
432 
433 	return 0;
434 }
435 
436 typedef struct drm_buf_free32 {
437 	int count;
438 	u32 list;
439 } drm_buf_free32_t;
440 
compat_drm_freebufs(struct drm_device * dev,void * data,struct drm_file * file_priv)441 static int compat_drm_freebufs(struct drm_device *dev, void *data,
442     struct drm_file *file_priv)
443 {
444 	drm_buf_free32_t *req32 = data;
445 	struct drm_buf_free request;
446 
447 	request.count = req32->count;
448 	request.list = (int *)(unsigned long)req32->list;
449 
450 	return drm_freebufs(dev, (void *)&request, file_priv);
451 }
452 
453 typedef struct drm_ctx_priv_map32 {
454 	unsigned int ctx_id;	 /**< Context requesting private mapping */
455 	u32 handle;		/**< Handle of map */
456 } drm_ctx_priv_map32_t;
457 
compat_drm_setsareactx(struct drm_device * dev,void * data,struct drm_file * file_priv)458 static int compat_drm_setsareactx(struct drm_device *dev, void *data,
459     struct drm_file *file_priv)
460 {
461 	drm_ctx_priv_map32_t *req32 = data;
462 	struct drm_ctx_priv_map request;
463 
464 	request.ctx_id = req32->ctx_id;
465 	request.handle = (void *)(unsigned long)req32->handle;
466 
467 	return drm_setsareactx(dev, (void *)&request, file_priv);
468 }
469 
compat_drm_getsareactx(struct drm_device * dev,void * data,struct drm_file * file_priv)470 static int compat_drm_getsareactx(struct drm_device *dev, void *data,
471     struct drm_file *file_priv)
472 {
473 	drm_ctx_priv_map32_t *req32 = data;
474 	struct drm_ctx_priv_map request;
475 	int err;
476 
477 	request.ctx_id = req32->ctx_id;
478 
479 	err = drm_getsareactx(dev, (void *)&request, file_priv);
480 	if (err)
481 		return err;
482 
483 	req32->handle = (unsigned long)request.handle;
484 
485 	return 0;
486 }
487 
488 typedef struct drm_ctx_res32 {
489 	int count;
490 	u32 contexts;
491 } drm_ctx_res32_t;
492 
compat_drm_resctx(struct drm_device * dev,void * data,struct drm_file * file_priv)493 static int compat_drm_resctx(struct drm_device *dev, void *data,
494     struct drm_file *file_priv)
495 {
496 	drm_ctx_res32_t *res32 = data;
497 	struct drm_ctx_res res;
498 	int err;
499 
500 	res.count = res32->count;
501 	res.contexts = (struct drm_ctx __user *)(unsigned long)res32->contexts;
502 
503 	err = drm_resctx(dev, (void *)&res, file_priv);
504 	if (err)
505 		return err;
506 
507 	res32->count = res.count;
508 
509 	return 0;
510 }
511 
512 typedef struct drm_dma32 {
513 	int context;		  /**< Context handle */
514 	int send_count;		  /**< Number of buffers to send */
515 	u32 send_indices;	  /**< List of handles to buffers */
516 	u32 send_sizes;		  /**< Lengths of data to send */
517 	enum drm_dma_flags flags;		  /**< Flags */
518 	int request_count;	  /**< Number of buffers requested */
519 	int request_size;	  /**< Desired size for buffers */
520 	u32 request_indices;	  /**< Buffer information */
521 	u32 request_sizes;
522 	int granted_count;	  /**< Number of buffers granted */
523 } drm_dma32_t;
524 
compat_drm_dma(struct drm_device * dev,void * data,struct drm_file * file_priv)525 static int compat_drm_dma(struct drm_device *dev, void *data,
526     struct drm_file *file_priv)
527 {
528 	drm_dma32_t *d32 = data;
529 	struct drm_dma d;
530 	int err;
531 
532 	if (!dev->driver->dma_ioctl) {
533 		DRM_DEBUG("DMA ioctl on driver with no dma handler\n");
534 		return -EINVAL;
535 	}
536 
537 	d.context = d32->context;
538 	d.send_count = d32->send_count;
539 	d.send_indices = (int *)(unsigned long)d32->send_indices;
540 	d.send_sizes = (int *)(unsigned long)d32->send_sizes;
541 	d.flags = d32->flags;
542 	d.request_count = d32->request_count;
543 	d.request_indices = (int *)(unsigned long)d32->request_indices;
544 	d.request_sizes = (int *)(unsigned long)d32->request_sizes;
545 
546 	err = dev->driver->dma_ioctl(dev, (void *)&d, file_priv);
547 	if (err)
548 		return err;
549 
550 	d32->request_size = d.request_size;
551 	d32->granted_count = d.granted_count;
552 
553 	return 0;
554 }
555 
556 #if __OS_HAS_AGP
557 typedef struct drm_agp_mode32 {
558 	u32 mode;	/**< AGP mode */
559 } drm_agp_mode32_t;
560 
compat_drm_agp_enable(struct drm_device * dev,void * data,struct drm_file * file_priv)561 static int compat_drm_agp_enable(struct drm_device *dev, void *data,
562     struct drm_file *file_priv)
563 {
564 	drm_agp_mode32_t *m32 = data;
565 	struct drm_agp_mode mode;
566 
567 	mode.mode = m32->mode;
568 
569 	return drm_agp_enable_ioctl(dev, (void *)&mode, file_priv);
570 }
571 
572 typedef struct drm_agp_info32 {
573 	int agp_version_major;
574 	int agp_version_minor;
575 	u32 mode;
576 	u32 aperture_base;	/* physical address */
577 	u32 aperture_size;	/* bytes */
578 	u32 memory_allowed;	/* bytes */
579 	u32 memory_used;
580 
581 	/* PCI information */
582 	unsigned short id_vendor;
583 	unsigned short id_device;
584 } drm_agp_info32_t;
585 
compat_drm_agp_info(struct drm_device * dev,void * data,struct drm_file * file_priv)586 static int compat_drm_agp_info(struct drm_device *dev, void *data,
587     struct drm_file *file_priv)
588 {
589 	drm_agp_info32_t *i32 = data;
590 	struct drm_agp_info info;
591 	int err;
592 
593 	err = drm_agp_info_ioctl(dev, (void *)&info, file_priv);
594 	if (err)
595 		return err;
596 
597 	i32->agp_version_major = info.agp_version_major;
598 	i32->agp_version_minor = info.agp_version_minor;
599 	i32->mode = info.mode;
600 	i32->aperture_base = info.aperture_base;
601 	i32->aperture_size = info.aperture_size;
602 	i32->memory_allowed = info.memory_allowed;
603 	i32->memory_used = info.memory_used;
604 	i32->id_vendor = info.id_vendor;
605 	i32->id_device = info.id_device;
606 
607 	return 0;
608 }
609 
610 typedef struct drm_agp_buffer32 {
611 	u32 size;	/**< In bytes -- will round to page boundary */
612 	u32 handle;	/**< Used for binding / unbinding */
613 	u32 type;	/**< Type of memory to allocate */
614 	u32 physical;	/**< Physical used by i810 */
615 } drm_agp_buffer32_t;
616 
compat_drm_agp_alloc(struct drm_device * dev,void * data,struct drm_file * file_priv)617 static int compat_drm_agp_alloc(struct drm_device *dev, void *data,
618     struct drm_file *file_priv)
619 {
620 	drm_agp_buffer32_t *req32 = data;
621 	struct drm_agp_buffer request;
622 	int err;
623 
624 	request.size = req32->size;
625 	request.type = req32->type;
626 
627 	err = drm_agp_alloc_ioctl(dev, (void *)&request, file_priv);
628 	if (err)
629 		return err;
630 
631 	req32->handle = request.handle;
632 	req32->physical = request.physical;
633 
634 	return 0;
635 }
636 
compat_drm_agp_free(struct drm_device * dev,void * data,struct drm_file * file_priv)637 static int compat_drm_agp_free(struct drm_device *dev, void *data,
638     struct drm_file *file_priv)
639 {
640 	drm_agp_buffer32_t *req32 = data;
641 	struct drm_agp_buffer request;
642 
643 	request.handle = req32->handle;
644 
645 	return drm_agp_free_ioctl(dev, (void *)&request, file_priv);
646 }
647 
648 typedef struct drm_agp_binding32 {
649 	u32 handle;	/**< From drm_agp_buffer */
650 	u32 offset;	/**< In bytes -- will round to page boundary */
651 } drm_agp_binding32_t;
652 
compat_drm_agp_bind(struct drm_device * dev,void * data,struct drm_file * file_priv)653 static int compat_drm_agp_bind(struct drm_device *dev, void *data,
654     struct drm_file *file_priv)
655 {
656 	drm_agp_binding32_t *req32 = data;
657 	struct drm_agp_binding request;
658 
659 	request.handle = req32->handle;
660 	request.offset = req32->offset;
661 
662 	return drm_agp_bind_ioctl(dev, (void *)&request, file_priv);
663 }
664 
compat_drm_agp_unbind(struct drm_device * dev,void * data,struct drm_file * file_priv)665 static int compat_drm_agp_unbind(struct drm_device *dev, void *data,
666     struct drm_file *file_priv)
667 {
668 	drm_agp_binding32_t *req32 = data;
669 	struct drm_agp_binding request;
670 
671 	request.handle = req32->handle;
672 
673 	return drm_agp_unbind_ioctl(dev, (void *)&request, file_priv);
674 }
675 #endif				/* __OS_HAS_AGP */
676 
677 typedef struct drm_scatter_gather32 {
678 	u32 size;	/**< In bytes -- will round to page boundary */
679 	u32 handle;	/**< Used for mapping / unmapping */
680 } drm_scatter_gather32_t;
681 
compat_drm_sg_alloc(struct drm_device * dev,void * data,struct drm_file * file_priv)682 static int compat_drm_sg_alloc(struct drm_device *dev, void *data,
683     struct drm_file *file_priv)
684 {
685 	drm_scatter_gather32_t *req32 = data;
686 	struct drm_scatter_gather request;
687 	int err;
688 
689 	request.size = (unsigned long)req32->size;
690 
691 	err = drm_sg_alloc_ioctl(dev, (void *)&request, file_priv);
692 	if (err)
693 		return err;
694 
695 	/* XXX not sure about the handle conversion here... */
696 	req32->handle = (unsigned long)request.handle >> PAGE_SHIFT;
697 
698 	return 0;
699 }
700 
compat_drm_sg_free(struct drm_device * dev,void * data,struct drm_file * file_priv)701 static int compat_drm_sg_free(struct drm_device *dev, void *data,
702     struct drm_file *file_priv)
703 {
704 	drm_scatter_gather32_t *req32 = data;
705 	struct drm_scatter_gather request;
706 
707 	request.handle = (unsigned long)req32->handle << PAGE_SHIFT;
708 
709 	return drm_sg_free(dev, (void *)&request, file_priv);
710 }
711 
712 #if defined(CONFIG_X86) || defined(CONFIG_IA64)
713 typedef struct drm_update_draw32 {
714 	drm_drawable_t handle;
715 	unsigned int type;
716 	unsigned int num;
717 	/* 64-bit version has a 32-bit pad here */
718 	u64 data;	/**< Pointer */
719 } __attribute__((packed)) drm_update_draw32_t;
720 #endif
721 
722 struct drm_wait_vblank_request32 {
723 	enum drm_vblank_seq_type type;
724 	unsigned int sequence;
725 	u32 signal;
726 };
727 
728 struct drm_wait_vblank_reply32 {
729 	enum drm_vblank_seq_type type;
730 	unsigned int sequence;
731 	s32 tval_sec;
732 	s32 tval_usec;
733 };
734 
735 typedef union drm_wait_vblank32 {
736 	struct drm_wait_vblank_request32 request;
737 	struct drm_wait_vblank_reply32 reply;
738 } drm_wait_vblank32_t;
739 
compat_drm_wait_vblank(struct drm_device * dev,void * data,struct drm_file * file_priv)740 static int compat_drm_wait_vblank(struct drm_device *dev, void *data,
741     struct drm_file *file_priv)
742 {
743 	drm_wait_vblank32_t *req32 = data;
744 	union drm_wait_vblank request;
745 	int err;
746 
747 	request.request.type = req32->request.type;
748 	request.request.sequence = req32->request.sequence;
749 	request.request.signal = req32->request.signal;
750 
751 	err = drm_wait_vblank(dev, (void *)&request, file_priv);
752 	if (err)
753 		return err;
754 
755 	req32->reply.type = request.reply.type;
756 	req32->reply.sequence = request.reply.sequence;
757 	req32->reply.tval_sec = request.reply.tval_sec;
758 	req32->reply.tval_usec = request.reply.tval_usec;
759 
760 	return 0;
761 }
762 
763 struct drm_ioctl_desc drm_compat_ioctls[256] = {
764 	DRM_IOCTL_DEF(DRM_IOCTL_VERSION32, compat_drm_version, DRM_UNLOCKED),
765 	DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE32, compat_drm_getunique, 0),
766 	DRM_IOCTL_DEF(DRM_IOCTL_GET_MAP32, compat_drm_getmap, DRM_UNLOCKED),
767 	DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT32, compat_drm_getclient, DRM_UNLOCKED),
768 	DRM_IOCTL_DEF(DRM_IOCTL_GET_STATS32, compat_drm_getstats, DRM_UNLOCKED),
769 	DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE32, compat_drm_setunique, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
770 	DRM_IOCTL_DEF(DRM_IOCTL_ADD_MAP32, compat_drm_addmap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
771 	DRM_IOCTL_DEF(DRM_IOCTL_ADD_BUFS32, compat_drm_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
772 	DRM_IOCTL_DEF(DRM_IOCTL_MARK_BUFS32, compat_drm_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
773 	DRM_IOCTL_DEF(DRM_IOCTL_INFO_BUFS32, compat_drm_infobufs, DRM_AUTH),
774 	DRM_IOCTL_DEF(DRM_IOCTL_MAP_BUFS32, compat_drm_mapbufs, DRM_AUTH),
775 	DRM_IOCTL_DEF(DRM_IOCTL_FREE_BUFS32, compat_drm_freebufs, DRM_AUTH),
776 	DRM_IOCTL_DEF(DRM_IOCTL_RM_MAP32, compat_drm_rmmap, DRM_AUTH),
777 	DRM_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX32, compat_drm_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
778 	DRM_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX32, compat_drm_getsareactx, DRM_AUTH),
779 	DRM_IOCTL_DEF(DRM_IOCTL_RES_CTX32, compat_drm_resctx, DRM_AUTH),
780 	DRM_IOCTL_DEF(DRM_IOCTL_DMA32, compat_drm_dma, DRM_AUTH),
781 #if __OS_HAS_AGP
782 	DRM_IOCTL_DEF(DRM_IOCTL_AGP_ENABLE32, compat_drm_agp_enable, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
783 	DRM_IOCTL_DEF(DRM_IOCTL_AGP_INFO32, compat_drm_agp_info, DRM_AUTH),
784 	DRM_IOCTL_DEF(DRM_IOCTL_AGP_ALLOC32, compat_drm_agp_alloc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
785 	DRM_IOCTL_DEF(DRM_IOCTL_AGP_FREE32, compat_drm_agp_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
786 	DRM_IOCTL_DEF(DRM_IOCTL_AGP_BIND32, compat_drm_agp_bind, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
787 	DRM_IOCTL_DEF(DRM_IOCTL_AGP_UNBIND32, compat_drm_agp_unbind, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
788 #endif
789 	DRM_IOCTL_DEF(DRM_IOCTL_SG_ALLOC32, compat_drm_sg_alloc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
790 	DRM_IOCTL_DEF(DRM_IOCTL_SG_FREE32, compat_drm_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
791 #if defined(CONFIG_X86) || defined(CONFIG_IA64)
792 	DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW32, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
793 #endif
794 	DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK32, compat_drm_wait_vblank, DRM_UNLOCKED),
795 };
796 
797 #endif
798