blob: bad1900c71dd686431f622fafc2862abc52dee72 [file] [log] [blame]
Daniel Vetter26409812017-04-04 11:52:57 +02001/*
Dave Airlie9a186642005-06-23 21:29:18 +10002 * \file drm_ioc32.c
3 *
4 * 32-bit ioctl compatibility routines for the DRM.
5 *
6 * \author Paul Mackerras <paulus@samba.org>
7 *
8 * Copyright (C) Paul Mackerras 2005.
9 * All Rights Reserved.
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the next
19 * paragraph) shall be included in all copies or substantial portions of the
20 * Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 * IN THE SOFTWARE.
29 */
30#include <linux/compat.h>
Christian Dietrichcafe8d82011-06-04 15:36:43 +000031#include <linux/ratelimit.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040032#include <linux/export.h>
Dave Airlie9a186642005-06-23 21:29:18 +100033
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
Al Viroff22ff92017-05-24 13:42:27 -040035#include "drm_legacy.h"
Al Viro012c6742017-05-24 14:11:03 -040036#include "drm_internal.h"
Al Virod6c56612017-05-25 15:45:04 -040037#include "drm_crtc_internal.h"
Dave Airlie9a186642005-06-23 21:29:18 +100038
39#define DRM_IOCTL_VERSION32 DRM_IOWR(0x00, drm_version32_t)
40#define DRM_IOCTL_GET_UNIQUE32 DRM_IOWR(0x01, drm_unique32_t)
41#define DRM_IOCTL_GET_MAP32 DRM_IOWR(0x04, drm_map32_t)
42#define DRM_IOCTL_GET_CLIENT32 DRM_IOWR(0x05, drm_client32_t)
43#define DRM_IOCTL_GET_STATS32 DRM_IOR( 0x06, drm_stats32_t)
44
45#define DRM_IOCTL_SET_UNIQUE32 DRM_IOW( 0x10, drm_unique32_t)
46#define DRM_IOCTL_ADD_MAP32 DRM_IOWR(0x15, drm_map32_t)
47#define DRM_IOCTL_ADD_BUFS32 DRM_IOWR(0x16, drm_buf_desc32_t)
48#define DRM_IOCTL_MARK_BUFS32 DRM_IOW( 0x17, drm_buf_desc32_t)
49#define DRM_IOCTL_INFO_BUFS32 DRM_IOWR(0x18, drm_buf_info32_t)
50#define DRM_IOCTL_MAP_BUFS32 DRM_IOWR(0x19, drm_buf_map32_t)
51#define DRM_IOCTL_FREE_BUFS32 DRM_IOW( 0x1a, drm_buf_free32_t)
52
53#define DRM_IOCTL_RM_MAP32 DRM_IOW( 0x1b, drm_map32_t)
54
55#define DRM_IOCTL_SET_SAREA_CTX32 DRM_IOW( 0x1c, drm_ctx_priv_map32_t)
56#define DRM_IOCTL_GET_SAREA_CTX32 DRM_IOWR(0x1d, drm_ctx_priv_map32_t)
57
58#define DRM_IOCTL_RES_CTX32 DRM_IOWR(0x26, drm_ctx_res32_t)
59#define DRM_IOCTL_DMA32 DRM_IOWR(0x29, drm_dma32_t)
60
61#define DRM_IOCTL_AGP_ENABLE32 DRM_IOW( 0x32, drm_agp_mode32_t)
62#define DRM_IOCTL_AGP_INFO32 DRM_IOR( 0x33, drm_agp_info32_t)
63#define DRM_IOCTL_AGP_ALLOC32 DRM_IOWR(0x34, drm_agp_buffer32_t)
64#define DRM_IOCTL_AGP_FREE32 DRM_IOW( 0x35, drm_agp_buffer32_t)
65#define DRM_IOCTL_AGP_BIND32 DRM_IOW( 0x36, drm_agp_binding32_t)
66#define DRM_IOCTL_AGP_UNBIND32 DRM_IOW( 0x37, drm_agp_binding32_t)
67
68#define DRM_IOCTL_SG_ALLOC32 DRM_IOW( 0x38, drm_scatter_gather32_t)
69#define DRM_IOCTL_SG_FREE32 DRM_IOW( 0x39, drm_scatter_gather32_t)
70
Eric Anholt49568872008-10-21 11:38:50 -070071#define DRM_IOCTL_UPDATE_DRAW32 DRM_IOW( 0x3f, drm_update_draw32_t)
72
Dave Airlie9a186642005-06-23 21:29:18 +100073#define DRM_IOCTL_WAIT_VBLANK32 DRM_IOWR(0x3a, drm_wait_vblank32_t)
74
Tvrtko Ursulinc631d5f2015-07-14 11:13:08 +010075#define DRM_IOCTL_MODE_ADDFB232 DRM_IOWR(0xb8, drm_mode_fb_cmd232_t)
76
Dave Airlie9a186642005-06-23 21:29:18 +100077typedef struct drm_version_32 {
Daniel Vetter26409812017-04-04 11:52:57 +020078 int version_major; /* Major version */
79 int version_minor; /* Minor version */
80 int version_patchlevel; /* Patch level */
81 u32 name_len; /* Length of name buffer */
82 u32 name; /* Name of driver */
83 u32 date_len; /* Length of date buffer */
84 u32 date; /* User-space buffer to hold date */
85 u32 desc_len; /* Length of desc buffer */
86 u32 desc; /* User-space buffer to hold desc */
Dave Airlie9a186642005-06-23 21:29:18 +100087} drm_version32_t;
88
89static int compat_drm_version(struct file *file, unsigned int cmd,
90 unsigned long arg)
91{
92 drm_version32_t v32;
Al Viro012c6742017-05-24 14:11:03 -040093 struct drm_version v;
Dave Airlie9a186642005-06-23 21:29:18 +100094 int err;
95
Dave Airlieb5e89ed2005-09-25 14:28:13 +100096 if (copy_from_user(&v32, (void __user *)arg, sizeof(v32)))
Dave Airlie9a186642005-06-23 21:29:18 +100097 return -EFAULT;
98
Al Viro012c6742017-05-24 14:11:03 -040099 v = (struct drm_version) {
100 .name_len = v32.name_len,
101 .name = compat_ptr(v32.name),
102 .date_len = v32.date_len,
103 .date = compat_ptr(v32.date),
104 .desc_len = v32.desc_len,
105 .desc = compat_ptr(v32.desc),
106 };
107 err = drm_ioctl_kernel(file, drm_version, &v,
108 DRM_UNLOCKED|DRM_RENDER_ALLOW|DRM_CONTROL_ALLOW);
Dave Airlie9a186642005-06-23 21:29:18 +1000109 if (err)
110 return err;
111
Al Viro012c6742017-05-24 14:11:03 -0400112 v32.version_major = v.version_major;
113 v32.version_minor = v.version_minor;
114 v32.version_patchlevel = v.version_patchlevel;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000115 if (copy_to_user((void __user *)arg, &v32, sizeof(v32)))
Dave Airlie9a186642005-06-23 21:29:18 +1000116 return -EFAULT;
117 return 0;
118}
119
120typedef struct drm_unique32 {
Daniel Vetter26409812017-04-04 11:52:57 +0200121 u32 unique_len; /* Length of unique */
122 u32 unique; /* Unique name for driver instantiation */
Dave Airlie9a186642005-06-23 21:29:18 +1000123} drm_unique32_t;
124
125static int compat_drm_getunique(struct file *file, unsigned int cmd,
126 unsigned long arg)
127{
128 drm_unique32_t uq32;
Al Viro17e3dad2017-05-24 14:15:20 -0400129 struct drm_unique uq;
Dave Airlie9a186642005-06-23 21:29:18 +1000130 int err;
131
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000132 if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32)))
Dave Airlie9a186642005-06-23 21:29:18 +1000133 return -EFAULT;
Al Viro17e3dad2017-05-24 14:15:20 -0400134 uq = (struct drm_unique){
135 .unique_len = uq32.unique_len,
136 .unique = compat_ptr(uq32.unique),
137 };
Dave Airlie9a186642005-06-23 21:29:18 +1000138
Al Viro17e3dad2017-05-24 14:15:20 -0400139 err = drm_ioctl_kernel(file, drm_getunique, &uq, DRM_UNLOCKED);
Dave Airlie9a186642005-06-23 21:29:18 +1000140 if (err)
141 return err;
142
Al Viro17e3dad2017-05-24 14:15:20 -0400143 uq32.unique_len = uq.unique_len;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000144 if (copy_to_user((void __user *)arg, &uq32, sizeof(uq32)))
Dave Airlie9a186642005-06-23 21:29:18 +1000145 return -EFAULT;
146 return 0;
147}
148
149static int compat_drm_setunique(struct file *file, unsigned int cmd,
150 unsigned long arg)
151{
Al Viro56c275c2017-05-24 14:20:21 -0400152 /* it's dead */
153 return -EINVAL;
Dave Airlie9a186642005-06-23 21:29:18 +1000154}
155
156typedef struct drm_map32 {
Daniel Vetter26409812017-04-04 11:52:57 +0200157 u32 offset; /* Requested physical address (0 for SAREA) */
158 u32 size; /* Requested physical size (bytes) */
159 enum drm_map_type type; /* Type of memory to map */
160 enum drm_map_flags flags; /* Flags */
161 u32 handle; /* User-space: "Handle" to pass to mmap() */
162 int mtrr; /* MTRR slot used */
Dave Airlie9a186642005-06-23 21:29:18 +1000163} drm_map32_t;
164
165static int compat_drm_getmap(struct file *file, unsigned int cmd,
166 unsigned long arg)
167{
168 drm_map32_t __user *argp = (void __user *)arg;
169 drm_map32_t m32;
Al Viro8c4fe492017-05-24 14:26:39 -0400170 struct drm_map map;
171 int err;
Dave Airlie9a186642005-06-23 21:29:18 +1000172
Al Viro8c4fe492017-05-24 14:26:39 -0400173 if (copy_from_user(&m32, argp, sizeof(m32)))
Dave Airlie9a186642005-06-23 21:29:18 +1000174 return -EFAULT;
175
Al Viro8c4fe492017-05-24 14:26:39 -0400176 map.offset = m32.offset;
177 err = drm_ioctl_kernel(file, drm_legacy_getmap_ioctl, &map, DRM_UNLOCKED);
Dave Airlie9a186642005-06-23 21:29:18 +1000178 if (err)
179 return err;
180
Al Viro8c4fe492017-05-24 14:26:39 -0400181 m32.offset = map.offset;
182 m32.size = map.size;
183 m32.type = map.type;
184 m32.flags = map.flags;
185 m32.handle = ptr_to_compat(map.handle);
186 m32.mtrr = map.mtrr;
Dave Airlie9a186642005-06-23 21:29:18 +1000187 if (copy_to_user(argp, &m32, sizeof(m32)))
188 return -EFAULT;
189 return 0;
190
191}
192
193static int compat_drm_addmap(struct file *file, unsigned int cmd,
194 unsigned long arg)
195{
196 drm_map32_t __user *argp = (void __user *)arg;
197 drm_map32_t m32;
Al Virob36180a2017-05-24 19:27:36 -0400198 struct drm_map map;
Dave Airlie9a186642005-06-23 21:29:18 +1000199 int err;
Dave Airlie9a186642005-06-23 21:29:18 +1000200
201 if (copy_from_user(&m32, argp, sizeof(m32)))
202 return -EFAULT;
203
Al Virob36180a2017-05-24 19:27:36 -0400204 map.offset = m32.offset;
205 map.size = m32.size;
206 map.type = m32.type;
207 map.flags = m32.flags;
Dave Airlie9a186642005-06-23 21:29:18 +1000208
Al Virob36180a2017-05-24 19:27:36 -0400209 err = drm_ioctl_kernel(file, drm_legacy_addmap_ioctl, &map,
210 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000211 if (err)
212 return err;
213
Al Virob36180a2017-05-24 19:27:36 -0400214 m32.offset = map.offset;
215 m32.mtrr = map.mtrr;
216 m32.handle = ptr_to_compat(map.handle);
217 if (map.handle != compat_ptr(m32.handle))
Joe Perches499447d2017-02-28 04:55:53 -0800218 pr_err_ratelimited("compat_drm_addmap truncated handle %p for type %d offset %x\n",
Al Virob36180a2017-05-24 19:27:36 -0400219 map.handle, m32.type, m32.offset);
Dave Airlie9a186642005-06-23 21:29:18 +1000220
221 if (copy_to_user(argp, &m32, sizeof(m32)))
222 return -EFAULT;
223
224 return 0;
225}
226
227static int compat_drm_rmmap(struct file *file, unsigned int cmd,
228 unsigned long arg)
229{
230 drm_map32_t __user *argp = (void __user *)arg;
Dave Airlieff4135a2007-07-16 13:53:57 +1000231 struct drm_map __user *map;
Dave Airlie9a186642005-06-23 21:29:18 +1000232 u32 handle;
233
234 if (get_user(handle, &argp->handle))
235 return -EFAULT;
236
237 map = compat_alloc_user_space(sizeof(*map));
Jarkko Sakkinen1f96bee2015-07-03 14:17:29 +0300238 if (!map)
Dave Airlie9a186642005-06-23 21:29:18 +1000239 return -EFAULT;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000240 if (__put_user((void *)(unsigned long)handle, &map->handle))
Dave Airlie9a186642005-06-23 21:29:18 +1000241 return -EFAULT;
242
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000243 return drm_ioctl(file, DRM_IOCTL_RM_MAP, (unsigned long)map);
Dave Airlie9a186642005-06-23 21:29:18 +1000244}
245
246typedef struct drm_client32 {
Daniel Vetter26409812017-04-04 11:52:57 +0200247 int idx; /* Which client desired? */
248 int auth; /* Is client authenticated? */
249 u32 pid; /* Process ID */
250 u32 uid; /* User ID */
251 u32 magic; /* Magic */
252 u32 iocs; /* Ioctl count */
Dave Airlie9a186642005-06-23 21:29:18 +1000253} drm_client32_t;
254
255static int compat_drm_getclient(struct file *file, unsigned int cmd,
256 unsigned long arg)
257{
258 drm_client32_t c32;
259 drm_client32_t __user *argp = (void __user *)arg;
Al Viro9e926622017-05-24 19:10:32 -0400260 struct drm_client client;
261 int err;
Dave Airlie9a186642005-06-23 21:29:18 +1000262
Al Viro9e926622017-05-24 19:10:32 -0400263 if (copy_from_user(&c32, argp, sizeof(c32)))
Dave Airlie9a186642005-06-23 21:29:18 +1000264 return -EFAULT;
265
Al Viro9e926622017-05-24 19:10:32 -0400266 client.idx = c32.idx;
Dave Airlie9a186642005-06-23 21:29:18 +1000267
Al Viro9e926622017-05-24 19:10:32 -0400268 err = drm_ioctl_kernel(file, drm_getclient, &client, DRM_UNLOCKED);
Dave Airlie9a186642005-06-23 21:29:18 +1000269 if (err)
270 return err;
271
Al Viro9e926622017-05-24 19:10:32 -0400272 c32.idx = client.idx;
273 c32.auth = client.auth;
274 c32.pid = client.pid;
275 c32.uid = client.uid;
276 c32.magic = client.magic;
277 c32.iocs = client.iocs;
Dave Airlie9a186642005-06-23 21:29:18 +1000278
279 if (copy_to_user(argp, &c32, sizeof(c32)))
280 return -EFAULT;
281 return 0;
282}
283
284typedef struct drm_stats32 {
285 u32 count;
286 struct {
287 u32 value;
Dave Airlieff4135a2007-07-16 13:53:57 +1000288 enum drm_stat_type type;
Dave Airlie9a186642005-06-23 21:29:18 +1000289 } data[15];
290} drm_stats32_t;
291
292static int compat_drm_getstats(struct file *file, unsigned int cmd,
293 unsigned long arg)
294{
Dave Airlie9a186642005-06-23 21:29:18 +1000295 drm_stats32_t __user *argp = (void __user *)arg;
Al Viro8547ee92017-05-24 19:18:06 -0400296 int err;
Dave Airlie9a186642005-06-23 21:29:18 +1000297
Al Viro8547ee92017-05-24 19:18:06 -0400298 err = drm_ioctl_kernel(file, drm_noop, NULL, DRM_UNLOCKED);
Dave Airlie9a186642005-06-23 21:29:18 +1000299 if (err)
300 return err;
301
Al Viro8547ee92017-05-24 19:18:06 -0400302 if (clear_user(argp, sizeof(drm_stats32_t)))
Dave Airlie9a186642005-06-23 21:29:18 +1000303 return -EFAULT;
304 return 0;
305}
306
307typedef struct drm_buf_desc32 {
Daniel Vetter26409812017-04-04 11:52:57 +0200308 int count; /* Number of buffers of this size */
309 int size; /* Size in bytes */
310 int low_mark; /* Low water mark */
311 int high_mark; /* High water mark */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000312 int flags;
Daniel Vetter26409812017-04-04 11:52:57 +0200313 u32 agp_start; /* Start address in the AGP aperture */
Dave Airlie9a186642005-06-23 21:29:18 +1000314} drm_buf_desc32_t;
315
316static int compat_drm_addbufs(struct file *file, unsigned int cmd,
317 unsigned long arg)
318{
319 drm_buf_desc32_t __user *argp = (void __user *)arg;
Al Viroff22ff92017-05-24 13:42:27 -0400320 drm_buf_desc32_t desc32;
321 struct drm_buf_desc desc;
Dave Airlie9a186642005-06-23 21:29:18 +1000322 int err;
Dave Airlie9a186642005-06-23 21:29:18 +1000323
Al Viroff22ff92017-05-24 13:42:27 -0400324 if (copy_from_user(&desc32, argp, sizeof(drm_buf_desc32_t)))
Dave Airlie9a186642005-06-23 21:29:18 +1000325 return -EFAULT;
326
Al Viroff22ff92017-05-24 13:42:27 -0400327 desc = (struct drm_buf_desc){
328 desc32.count, desc32.size, desc32.low_mark, desc32.high_mark,
329 desc32.flags, desc32.agp_start
330 };
Dave Airlie9a186642005-06-23 21:29:18 +1000331
Al Viroff22ff92017-05-24 13:42:27 -0400332 err = drm_ioctl_kernel(file, drm_legacy_addbufs, &desc,
333 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000334 if (err)
335 return err;
336
Al Viroff22ff92017-05-24 13:42:27 -0400337 desc32 = (drm_buf_desc32_t){
338 desc.count, desc.size, desc.low_mark, desc.high_mark,
339 desc.flags, desc.agp_start
340 };
341 if (copy_to_user(argp, &desc32, sizeof(drm_buf_desc32_t)))
Dave Airlie9a186642005-06-23 21:29:18 +1000342 return -EFAULT;
343
344 return 0;
345}
346
347static int compat_drm_markbufs(struct file *file, unsigned int cmd,
348 unsigned long arg)
349{
350 drm_buf_desc32_t b32;
351 drm_buf_desc32_t __user *argp = (void __user *)arg;
Al Virodbae7402017-05-24 19:30:28 -0400352 struct drm_buf_desc __user buf;
Dave Airlie9a186642005-06-23 21:29:18 +1000353
354 if (copy_from_user(&b32, argp, sizeof(b32)))
355 return -EFAULT;
356
Al Virodbae7402017-05-24 19:30:28 -0400357 buf.size = b32.size;
358 buf.low_mark = b32.low_mark;
359 buf.high_mark = b32.high_mark;
Dave Airlie9a186642005-06-23 21:29:18 +1000360
Al Virodbae7402017-05-24 19:30:28 -0400361 return drm_ioctl_kernel(file, drm_legacy_markbufs, &buf,
362 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000363}
364
365typedef struct drm_buf_info32 {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000366 int count; /**< Entries in list */
367 u32 list;
Dave Airlie9a186642005-06-23 21:29:18 +1000368} drm_buf_info32_t;
369
Al Viro5c7640a2017-05-24 17:54:09 -0400370static int copy_one_buf32(void *data, int count, struct drm_buf_entry *from)
371{
372 drm_buf_info32_t *request = data;
373 drm_buf_desc32_t __user *to = compat_ptr(request->list);
374 drm_buf_desc32_t v = {.count = from->buf_count,
375 .size = from->buf_size,
376 .low_mark = from->low_mark,
377 .high_mark = from->high_mark};
378 return copy_to_user(to + count, &v, offsetof(drm_buf_desc32_t, flags));
379}
380
381static int drm_legacy_infobufs32(struct drm_device *dev, void *data,
382 struct drm_file *file_priv)
383{
384 drm_buf_info32_t *request = data;
385 return __drm_legacy_infobufs(dev, data, &request->count, copy_one_buf32);
386}
387
Dave Airlie9a186642005-06-23 21:29:18 +1000388static int compat_drm_infobufs(struct file *file, unsigned int cmd,
389 unsigned long arg)
390{
391 drm_buf_info32_t req32;
392 drm_buf_info32_t __user *argp = (void __user *)arg;
Al Viro5c7640a2017-05-24 17:54:09 -0400393 int err;
Dave Airlie9a186642005-06-23 21:29:18 +1000394
395 if (copy_from_user(&req32, argp, sizeof(req32)))
396 return -EFAULT;
397
Al Viro5c7640a2017-05-24 17:54:09 -0400398 if (req32.count < 0)
399 req32.count = 0;
Dave Airlie9a186642005-06-23 21:29:18 +1000400
Al Viro5c7640a2017-05-24 17:54:09 -0400401 err = drm_ioctl_kernel(file, drm_legacy_infobufs32, &req32, DRM_AUTH);
Dave Airlie9a186642005-06-23 21:29:18 +1000402 if (err)
403 return err;
404
Al Viro5c7640a2017-05-24 17:54:09 -0400405 if (put_user(req32.count, &argp->count))
Dave Airlie9a186642005-06-23 21:29:18 +1000406 return -EFAULT;
407
408 return 0;
409}
410
411typedef struct drm_buf_pub32 {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000412 int idx; /**< Index into the master buffer list */
413 int total; /**< Buffer size */
414 int used; /**< Amount of buffer in use (for DMA) */
415 u32 address; /**< Address of buffer */
Dave Airlie9a186642005-06-23 21:29:18 +1000416} drm_buf_pub32_t;
417
418typedef struct drm_buf_map32 {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000419 int count; /**< Length of the buffer list */
420 u32 virtual; /**< Mmap'd area in user-virtual */
421 u32 list; /**< Buffer information */
Dave Airlie9a186642005-06-23 21:29:18 +1000422} drm_buf_map32_t;
423
424static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
425 unsigned long arg)
426{
427 drm_buf_map32_t __user *argp = (void __user *)arg;
428 drm_buf_map32_t req32;
429 drm_buf_pub32_t __user *list32;
Dave Airlieff4135a2007-07-16 13:53:57 +1000430 struct drm_buf_map __user *request;
431 struct drm_buf_pub __user *list;
Dave Airlie9a186642005-06-23 21:29:18 +1000432 int i, err;
433 int count, actual;
434 size_t nbytes;
435 void __user *addr;
436
437 if (copy_from_user(&req32, argp, sizeof(req32)))
438 return -EFAULT;
439 count = req32.count;
440 list32 = (void __user *)(unsigned long)req32.list;
441
442 if (count < 0)
443 return -EINVAL;
Dave Airlieff4135a2007-07-16 13:53:57 +1000444 nbytes = sizeof(*request) + count * sizeof(struct drm_buf_pub);
Dave Airlie9a186642005-06-23 21:29:18 +1000445 request = compat_alloc_user_space(nbytes);
Jarkko Sakkinen1f96bee2015-07-03 14:17:29 +0300446 if (!request)
Dave Airlie9a186642005-06-23 21:29:18 +1000447 return -EFAULT;
Dave Airlieff4135a2007-07-16 13:53:57 +1000448 list = (struct drm_buf_pub *) (request + 1);
Dave Airlie9a186642005-06-23 21:29:18 +1000449
450 if (__put_user(count, &request->count)
451 || __put_user(list, &request->list))
452 return -EFAULT;
453
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000454 err = drm_ioctl(file, DRM_IOCTL_MAP_BUFS, (unsigned long)request);
Dave Airlie9a186642005-06-23 21:29:18 +1000455 if (err)
456 return err;
457
458 if (__get_user(actual, &request->count))
459 return -EFAULT;
460 if (count >= actual)
461 for (i = 0; i < actual; ++i)
462 if (__copy_in_user(&list32[i], &list[i],
Dave Airlieff4135a2007-07-16 13:53:57 +1000463 offsetof(struct drm_buf_pub, address))
Dave Airlie9a186642005-06-23 21:29:18 +1000464 || __get_user(addr, &list[i].address)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000465 || __put_user((unsigned long)addr,
Dave Airlie9a186642005-06-23 21:29:18 +1000466 &list32[i].address))
467 return -EFAULT;
468
469 if (__put_user(actual, &argp->count)
470 || __get_user(addr, &request->virtual)
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000471 || __put_user((unsigned long)addr, &argp->virtual))
Dave Airlie9a186642005-06-23 21:29:18 +1000472 return -EFAULT;
473
474 return 0;
475}
476
477typedef struct drm_buf_free32 {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000478 int count;
479 u32 list;
Dave Airlie9a186642005-06-23 21:29:18 +1000480} drm_buf_free32_t;
481
482static int compat_drm_freebufs(struct file *file, unsigned int cmd,
483 unsigned long arg)
484{
485 drm_buf_free32_t req32;
Al Viro8c9e4cf2017-05-25 12:44:05 -0400486 struct drm_buf_free request;
Dave Airlie9a186642005-06-23 21:29:18 +1000487 drm_buf_free32_t __user *argp = (void __user *)arg;
488
489 if (copy_from_user(&req32, argp, sizeof(req32)))
490 return -EFAULT;
491
Al Viro8c9e4cf2017-05-25 12:44:05 -0400492 request.count = req32.count;
493 request.list = compat_ptr(req32.list);
494 return drm_ioctl_kernel(file, drm_legacy_freebufs, &request, DRM_AUTH);
Dave Airlie9a186642005-06-23 21:29:18 +1000495}
496
497typedef struct drm_ctx_priv_map32 {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000498 unsigned int ctx_id; /**< Context requesting private mapping */
499 u32 handle; /**< Handle of map */
Dave Airlie9a186642005-06-23 21:29:18 +1000500} drm_ctx_priv_map32_t;
501
502static int compat_drm_setsareactx(struct file *file, unsigned int cmd,
503 unsigned long arg)
504{
505 drm_ctx_priv_map32_t req32;
Al Viro7900c602017-05-25 12:47:00 -0400506 struct drm_ctx_priv_map request;
Dave Airlie9a186642005-06-23 21:29:18 +1000507 drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
508
509 if (copy_from_user(&req32, argp, sizeof(req32)))
510 return -EFAULT;
511
Al Viro7900c602017-05-25 12:47:00 -0400512 request.ctx_id = req32.ctx_id;
513 request.handle = compat_ptr(req32.handle);
514 return drm_ioctl_kernel(file, drm_legacy_setsareactx, &request,
515 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000516}
517
518static int compat_drm_getsareactx(struct file *file, unsigned int cmd,
519 unsigned long arg)
520{
Al Virod7631e32017-05-25 12:50:51 -0400521 struct drm_ctx_priv_map req;
522 drm_ctx_priv_map32_t req32;
Dave Airlie9a186642005-06-23 21:29:18 +1000523 drm_ctx_priv_map32_t __user *argp = (void __user *)arg;
524 int err;
Dave Airlie9a186642005-06-23 21:29:18 +1000525
Al Virod7631e32017-05-25 12:50:51 -0400526 if (copy_from_user(&req32, argp, sizeof(req32)))
Dave Airlie9a186642005-06-23 21:29:18 +1000527 return -EFAULT;
528
Al Virod7631e32017-05-25 12:50:51 -0400529 req.ctx_id = req32.ctx_id;
530 err = drm_ioctl_kernel(file, drm_legacy_getsareactx, &req, DRM_AUTH);
Dave Airlie9a186642005-06-23 21:29:18 +1000531 if (err)
532 return err;
533
Al Virod7631e32017-05-25 12:50:51 -0400534 req32.handle = ptr_to_compat(req.handle);
535 if (copy_to_user(argp, &req32, sizeof(req32)))
Dave Airlie9a186642005-06-23 21:29:18 +1000536 return -EFAULT;
537
538 return 0;
539}
540
541typedef struct drm_ctx_res32 {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000542 int count;
543 u32 contexts;
Dave Airlie9a186642005-06-23 21:29:18 +1000544} drm_ctx_res32_t;
545
546static int compat_drm_resctx(struct file *file, unsigned int cmd,
547 unsigned long arg)
548{
549 drm_ctx_res32_t __user *argp = (void __user *)arg;
550 drm_ctx_res32_t res32;
Al Viro9e075682017-05-25 12:53:59 -0400551 struct drm_ctx_res res;
Dave Airlie9a186642005-06-23 21:29:18 +1000552 int err;
553
554 if (copy_from_user(&res32, argp, sizeof(res32)))
555 return -EFAULT;
556
Al Viro9e075682017-05-25 12:53:59 -0400557 res.count = res32.count;
558 res.contexts = compat_ptr(res32.contexts);
559 err = drm_ioctl_kernel(file, drm_legacy_resctx, &res, DRM_AUTH);
Dave Airlie9a186642005-06-23 21:29:18 +1000560 if (err)
561 return err;
562
Al Viro9e075682017-05-25 12:53:59 -0400563 res32.count = res.count;
564 if (copy_to_user(argp, &res32, sizeof(res32)))
Dave Airlie9a186642005-06-23 21:29:18 +1000565 return -EFAULT;
566
567 return 0;
568}
569
570typedef struct drm_dma32 {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000571 int context; /**< Context handle */
572 int send_count; /**< Number of buffers to send */
573 u32 send_indices; /**< List of handles to buffers */
574 u32 send_sizes; /**< Lengths of data to send */
Dave Airlieff4135a2007-07-16 13:53:57 +1000575 enum drm_dma_flags flags; /**< Flags */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000576 int request_count; /**< Number of buffers requested */
577 int request_size; /**< Desired size for buffers */
578 u32 request_indices; /**< Buffer information */
579 u32 request_sizes;
580 int granted_count; /**< Number of buffers granted */
Dave Airlie9a186642005-06-23 21:29:18 +1000581} drm_dma32_t;
582
583static int compat_drm_dma(struct file *file, unsigned int cmd,
584 unsigned long arg)
585{
586 drm_dma32_t d32;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000587 drm_dma32_t __user *argp = (void __user *)arg;
Al Viroc6f08962017-05-25 12:58:47 -0400588 struct drm_dma d;
Dave Airlie9a186642005-06-23 21:29:18 +1000589 int err;
590
591 if (copy_from_user(&d32, argp, sizeof(d32)))
592 return -EFAULT;
593
Al Viroc6f08962017-05-25 12:58:47 -0400594 d.context = d32.context;
595 d.send_count = d32.send_count;
596 d.send_indices = compat_ptr(d32.send_indices);
597 d.send_sizes = compat_ptr(d32.send_sizes);
598 d.flags = d32.flags;
599 d.request_count = d32.request_count;
600 d.request_indices = compat_ptr(d32.request_indices);
601 d.request_sizes = compat_ptr(d32.request_sizes);
602 err = drm_ioctl_kernel(file, drm_legacy_dma_ioctl, &d, DRM_AUTH);
Dave Airlie9a186642005-06-23 21:29:18 +1000603 if (err)
604 return err;
605
Al Viroc6f08962017-05-25 12:58:47 -0400606 if (put_user(d.request_size, &argp->request_size)
607 || put_user(d.granted_count, &argp->granted_count))
Dave Airlie9a186642005-06-23 21:29:18 +1000608 return -EFAULT;
609
610 return 0;
611}
612
Daniel Vettera7fb8a22015-09-09 16:45:52 +0200613#if IS_ENABLED(CONFIG_AGP)
Dave Airlie9a186642005-06-23 21:29:18 +1000614typedef struct drm_agp_mode32 {
615 u32 mode; /**< AGP mode */
616} drm_agp_mode32_t;
617
618static int compat_drm_agp_enable(struct file *file, unsigned int cmd,
619 unsigned long arg)
620{
621 drm_agp_mode32_t __user *argp = (void __user *)arg;
Al Viroe92673e2017-05-25 13:17:17 -0400622 struct drm_agp_mode mode;
Dave Airlie9a186642005-06-23 21:29:18 +1000623
Al Viroe92673e2017-05-25 13:17:17 -0400624 if (get_user(mode.mode, &argp->mode))
Dave Airlie9a186642005-06-23 21:29:18 +1000625 return -EFAULT;
626
Al Viroe92673e2017-05-25 13:17:17 -0400627 return drm_ioctl_kernel(file, drm_agp_enable_ioctl, &mode,
628 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000629}
630
631typedef struct drm_agp_info32 {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000632 int agp_version_major;
633 int agp_version_minor;
634 u32 mode;
635 u32 aperture_base; /* physical address */
636 u32 aperture_size; /* bytes */
637 u32 memory_allowed; /* bytes */
638 u32 memory_used;
Dave Airlie9a186642005-06-23 21:29:18 +1000639
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000640 /* PCI information */
Dave Airlie9a186642005-06-23 21:29:18 +1000641 unsigned short id_vendor;
642 unsigned short id_device;
643} drm_agp_info32_t;
644
645static int compat_drm_agp_info(struct file *file, unsigned int cmd,
646 unsigned long arg)
647{
648 drm_agp_info32_t __user *argp = (void __user *)arg;
649 drm_agp_info32_t i32;
Al Viroe92673e2017-05-25 13:17:17 -0400650 struct drm_agp_info info;
Dave Airlie9a186642005-06-23 21:29:18 +1000651 int err;
652
Al Viroe92673e2017-05-25 13:17:17 -0400653 err = drm_ioctl_kernel(file, drm_agp_info_ioctl, &info, DRM_AUTH);
Dave Airlie9a186642005-06-23 21:29:18 +1000654 if (err)
655 return err;
656
Al Viroe92673e2017-05-25 13:17:17 -0400657 i32.agp_version_major = info.agp_version_major;
658 i32.agp_version_minor = info.agp_version_minor;
659 i32.mode = info.mode;
660 i32.aperture_base = info.aperture_base;
661 i32.aperture_size = info.aperture_size;
662 i32.memory_allowed = info.memory_allowed;
663 i32.memory_used = info.memory_used;
664 i32.id_vendor = info.id_vendor;
665 i32.id_device = info.id_device;
Dave Airlie9a186642005-06-23 21:29:18 +1000666 if (copy_to_user(argp, &i32, sizeof(i32)))
667 return -EFAULT;
668
669 return 0;
670}
671
672typedef struct drm_agp_buffer32 {
673 u32 size; /**< In bytes -- will round to page boundary */
674 u32 handle; /**< Used for binding / unbinding */
675 u32 type; /**< Type of memory to allocate */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000676 u32 physical; /**< Physical used by i810 */
Dave Airlie9a186642005-06-23 21:29:18 +1000677} drm_agp_buffer32_t;
678
679static int compat_drm_agp_alloc(struct file *file, unsigned int cmd,
680 unsigned long arg)
681{
682 drm_agp_buffer32_t __user *argp = (void __user *)arg;
683 drm_agp_buffer32_t req32;
Al Viroe92673e2017-05-25 13:17:17 -0400684 struct drm_agp_buffer request;
Dave Airlie9a186642005-06-23 21:29:18 +1000685 int err;
686
687 if (copy_from_user(&req32, argp, sizeof(req32)))
688 return -EFAULT;
689
Al Viroe92673e2017-05-25 13:17:17 -0400690 request.size = req32.size;
691 request.type = req32.type;
692 err = drm_ioctl_kernel(file, drm_agp_alloc_ioctl, &request,
693 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000694 if (err)
695 return err;
696
Al Viroe92673e2017-05-25 13:17:17 -0400697 req32.handle = request.handle;
698 req32.physical = request.physical;
699 if (copy_to_user(argp, &req32, sizeof(req32))) {
700 drm_ioctl_kernel(file, drm_agp_free_ioctl, &request,
701 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000702 return -EFAULT;
703 }
704
705 return 0;
706}
707
708static int compat_drm_agp_free(struct file *file, unsigned int cmd,
709 unsigned long arg)
710{
711 drm_agp_buffer32_t __user *argp = (void __user *)arg;
Al Viroe92673e2017-05-25 13:17:17 -0400712 struct drm_agp_buffer request;
Dave Airlie9a186642005-06-23 21:29:18 +1000713
Al Viroe92673e2017-05-25 13:17:17 -0400714 if (get_user(request.handle, &argp->handle))
Dave Airlie9a186642005-06-23 21:29:18 +1000715 return -EFAULT;
716
Al Viroe92673e2017-05-25 13:17:17 -0400717 return drm_ioctl_kernel(file, drm_agp_free_ioctl, &request,
718 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000719}
720
721typedef struct drm_agp_binding32 {
722 u32 handle; /**< From drm_agp_buffer */
723 u32 offset; /**< In bytes -- will round to page boundary */
724} drm_agp_binding32_t;
725
726static int compat_drm_agp_bind(struct file *file, unsigned int cmd,
727 unsigned long arg)
728{
729 drm_agp_binding32_t __user *argp = (void __user *)arg;
730 drm_agp_binding32_t req32;
Al Viroe92673e2017-05-25 13:17:17 -0400731 struct drm_agp_binding request;
Dave Airlie9a186642005-06-23 21:29:18 +1000732
733 if (copy_from_user(&req32, argp, sizeof(req32)))
734 return -EFAULT;
735
Al Viroe92673e2017-05-25 13:17:17 -0400736 request.handle = req32.handle;
737 request.offset = req32.offset;
738 return drm_ioctl_kernel(file, drm_agp_bind_ioctl, &request,
739 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000740}
741
742static int compat_drm_agp_unbind(struct file *file, unsigned int cmd,
743 unsigned long arg)
744{
745 drm_agp_binding32_t __user *argp = (void __user *)arg;
Al Viroe92673e2017-05-25 13:17:17 -0400746 struct drm_agp_binding request;
Dave Airlie9a186642005-06-23 21:29:18 +1000747
Al Viroe92673e2017-05-25 13:17:17 -0400748 if (get_user(request.handle, &argp->handle))
Dave Airlie9a186642005-06-23 21:29:18 +1000749 return -EFAULT;
750
Al Viroe92673e2017-05-25 13:17:17 -0400751 return drm_ioctl_kernel(file, drm_agp_unbind_ioctl, &request,
752 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000753}
Daniel Vettera7fb8a22015-09-09 16:45:52 +0200754#endif /* CONFIG_AGP */
Dave Airlie9a186642005-06-23 21:29:18 +1000755
756typedef struct drm_scatter_gather32 {
757 u32 size; /**< In bytes -- will round to page boundary */
758 u32 handle; /**< Used for mapping / unmapping */
759} drm_scatter_gather32_t;
760
761static int compat_drm_sg_alloc(struct file *file, unsigned int cmd,
762 unsigned long arg)
763{
764 drm_scatter_gather32_t __user *argp = (void __user *)arg;
Al Viro314ed732017-05-25 13:24:59 -0400765 struct drm_scatter_gather request;
Dave Airlie9a186642005-06-23 21:29:18 +1000766 int err;
Dave Airlie9a186642005-06-23 21:29:18 +1000767
Al Viro314ed732017-05-25 13:24:59 -0400768 if (get_user(request.size, &argp->size))
Dave Airlie9a186642005-06-23 21:29:18 +1000769 return -EFAULT;
770
Al Viro314ed732017-05-25 13:24:59 -0400771 err = drm_ioctl_kernel(file, drm_legacy_sg_alloc, &request,
772 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000773 if (err)
774 return err;
775
776 /* XXX not sure about the handle conversion here... */
Al Viro314ed732017-05-25 13:24:59 -0400777 if (put_user(request.handle >> PAGE_SHIFT, &argp->handle))
Dave Airlie9a186642005-06-23 21:29:18 +1000778 return -EFAULT;
779
780 return 0;
781}
782
783static int compat_drm_sg_free(struct file *file, unsigned int cmd,
784 unsigned long arg)
785{
786 drm_scatter_gather32_t __user *argp = (void __user *)arg;
Al Viro314ed732017-05-25 13:24:59 -0400787 struct drm_scatter_gather request;
Dave Airlie9a186642005-06-23 21:29:18 +1000788 unsigned long x;
789
Al Viro314ed732017-05-25 13:24:59 -0400790 if (get_user(x, &argp->handle))
Dave Airlie9a186642005-06-23 21:29:18 +1000791 return -EFAULT;
Al Viro314ed732017-05-25 13:24:59 -0400792 request.handle = x << PAGE_SHIFT;
793 return drm_ioctl_kernel(file, drm_legacy_sg_free, &request,
794 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Dave Airlie9a186642005-06-23 21:29:18 +1000795}
796
David Miller09e40d62009-02-18 01:35:21 -0800797#if defined(CONFIG_X86) || defined(CONFIG_IA64)
Eric Anholt49568872008-10-21 11:38:50 -0700798typedef struct drm_update_draw32 {
799 drm_drawable_t handle;
800 unsigned int type;
801 unsigned int num;
802 /* 64-bit version has a 32-bit pad here */
803 u64 data; /**< Pointer */
804} __attribute__((packed)) drm_update_draw32_t;
805
806static int compat_drm_update_draw(struct file *file, unsigned int cmd,
807 unsigned long arg)
808{
809 drm_update_draw32_t update32;
Eric Anholt49568872008-10-21 11:38:50 -0700810 if (copy_from_user(&update32, (void __user *)arg, sizeof(update32)))
811 return -EFAULT;
812
Al Viro1a36bf12017-05-25 13:28:51 -0400813 return drm_ioctl_kernel(file, drm_noop, NULL,
814 DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY);
Eric Anholt49568872008-10-21 11:38:50 -0700815}
David Miller09e40d62009-02-18 01:35:21 -0800816#endif
Eric Anholt49568872008-10-21 11:38:50 -0700817
Dave Airlie9a186642005-06-23 21:29:18 +1000818struct drm_wait_vblank_request32 {
Dave Airlieff4135a2007-07-16 13:53:57 +1000819 enum drm_vblank_seq_type type;
Dave Airlie9a186642005-06-23 21:29:18 +1000820 unsigned int sequence;
821 u32 signal;
822};
823
824struct drm_wait_vblank_reply32 {
Dave Airlieff4135a2007-07-16 13:53:57 +1000825 enum drm_vblank_seq_type type;
Dave Airlie9a186642005-06-23 21:29:18 +1000826 unsigned int sequence;
827 s32 tval_sec;
828 s32 tval_usec;
829};
830
831typedef union drm_wait_vblank32 {
832 struct drm_wait_vblank_request32 request;
833 struct drm_wait_vblank_reply32 reply;
834} drm_wait_vblank32_t;
835
836static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
837 unsigned long arg)
838{
839 drm_wait_vblank32_t __user *argp = (void __user *)arg;
840 drm_wait_vblank32_t req32;
Al Virod5288c82017-05-25 13:33:11 -0400841 union drm_wait_vblank req;
Dave Airlie9a186642005-06-23 21:29:18 +1000842 int err;
843
844 if (copy_from_user(&req32, argp, sizeof(req32)))
845 return -EFAULT;
846
Al Virod5288c82017-05-25 13:33:11 -0400847 req.request.type = req32.request.type;
848 req.request.sequence = req32.request.sequence;
849 req.request.signal = req32.request.signal;
850 err = drm_ioctl_kernel(file, drm_wait_vblank, &req, DRM_UNLOCKED);
Dave Airlie9a186642005-06-23 21:29:18 +1000851 if (err)
852 return err;
853
Al Virod5288c82017-05-25 13:33:11 -0400854 req32.reply.type = req.reply.type;
855 req32.reply.sequence = req.reply.sequence;
856 req32.reply.tval_sec = req.reply.tval_sec;
857 req32.reply.tval_usec = req.reply.tval_usec;
Dave Airlie9a186642005-06-23 21:29:18 +1000858 if (copy_to_user(argp, &req32, sizeof(req32)))
859 return -EFAULT;
860
861 return 0;
862}
863
Kristian H. Kristensena9885882016-09-13 14:20:45 -0700864#if defined(CONFIG_X86) || defined(CONFIG_IA64)
Tvrtko Ursulinc631d5f2015-07-14 11:13:08 +0100865typedef struct drm_mode_fb_cmd232 {
866 u32 fb_id;
867 u32 width;
868 u32 height;
869 u32 pixel_format;
870 u32 flags;
871 u32 handles[4];
872 u32 pitches[4];
873 u32 offsets[4];
874 u64 modifier[4];
875} __attribute__((packed)) drm_mode_fb_cmd232_t;
876
877static int compat_drm_mode_addfb2(struct file *file, unsigned int cmd,
878 unsigned long arg)
879{
880 struct drm_mode_fb_cmd232 __user *argp = (void __user *)arg;
Al Virod6c56612017-05-25 15:45:04 -0400881 struct drm_mode_fb_cmd2 __user req64;
Tvrtko Ursulinc631d5f2015-07-14 11:13:08 +0100882 int err;
883
Al Virod6c56612017-05-25 15:45:04 -0400884 if (copy_from_user(&req64, argp,
885 offsetof(drm_mode_fb_cmd232_t, modifier)))
Tvrtko Ursulinc631d5f2015-07-14 11:13:08 +0100886 return -EFAULT;
887
Al Virod6c56612017-05-25 15:45:04 -0400888 if (copy_from_user(&req64.modifier, &argp->modifier,
889 sizeof(req64.modifier)))
Tvrtko Ursulinc631d5f2015-07-14 11:13:08 +0100890 return -EFAULT;
891
Al Virod6c56612017-05-25 15:45:04 -0400892 err = drm_ioctl_kernel(file, drm_mode_addfb2, &req64,
893 DRM_CONTROL_ALLOW|DRM_UNLOCKED);
Tvrtko Ursulinc631d5f2015-07-14 11:13:08 +0100894 if (err)
895 return err;
896
Al Virod6c56612017-05-25 15:45:04 -0400897 if (put_user(req64.fb_id, &argp->fb_id))
Tvrtko Ursulinc631d5f2015-07-14 11:13:08 +0100898 return -EFAULT;
899
900 return 0;
901}
Kristian H. Kristensena9885882016-09-13 14:20:45 -0700902#endif
Tvrtko Ursulinc631d5f2015-07-14 11:13:08 +0100903
Al Viro9f43e542017-05-24 13:59:22 -0400904static struct {
905 drm_ioctl_compat_t *fn;
906 char *name;
907} drm_compat_ioctls[] = {
Al Viroff22ff92017-05-24 13:42:27 -0400908#define DRM_IOCTL32_DEF(n, f) [DRM_IOCTL_NR(n##32)] = {.fn = f, .name = #n}
Al Viro012c6742017-05-24 14:11:03 -0400909 DRM_IOCTL32_DEF(DRM_IOCTL_VERSION, compat_drm_version),
Al Viro17e3dad2017-05-24 14:15:20 -0400910 DRM_IOCTL32_DEF(DRM_IOCTL_GET_UNIQUE, compat_drm_getunique),
Al Viro8c4fe492017-05-24 14:26:39 -0400911 DRM_IOCTL32_DEF(DRM_IOCTL_GET_MAP, compat_drm_getmap),
Al Viro9e926622017-05-24 19:10:32 -0400912 DRM_IOCTL32_DEF(DRM_IOCTL_GET_CLIENT, compat_drm_getclient),
Al Viro8547ee92017-05-24 19:18:06 -0400913 DRM_IOCTL32_DEF(DRM_IOCTL_GET_STATS, compat_drm_getstats),
Al Viro56c275c2017-05-24 14:20:21 -0400914 DRM_IOCTL32_DEF(DRM_IOCTL_SET_UNIQUE, compat_drm_setunique),
Al Virob36180a2017-05-24 19:27:36 -0400915 DRM_IOCTL32_DEF(DRM_IOCTL_ADD_MAP, compat_drm_addmap),
Al Viroff22ff92017-05-24 13:42:27 -0400916 DRM_IOCTL32_DEF(DRM_IOCTL_ADD_BUFS, compat_drm_addbufs),
Al Virodbae7402017-05-24 19:30:28 -0400917 DRM_IOCTL32_DEF(DRM_IOCTL_MARK_BUFS, compat_drm_markbufs),
Al Viro5c7640a2017-05-24 17:54:09 -0400918 DRM_IOCTL32_DEF(DRM_IOCTL_INFO_BUFS, compat_drm_infobufs),
Al Viro9f43e542017-05-24 13:59:22 -0400919 [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS32)].fn = compat_drm_mapbufs,
Al Viro8c9e4cf2017-05-25 12:44:05 -0400920 DRM_IOCTL32_DEF(DRM_IOCTL_FREE_BUFS, compat_drm_freebufs),
Al Viro9f43e542017-05-24 13:59:22 -0400921 [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP32)].fn = compat_drm_rmmap,
Al Viro7900c602017-05-25 12:47:00 -0400922 DRM_IOCTL32_DEF(DRM_IOCTL_SET_SAREA_CTX, compat_drm_setsareactx),
Al Virod7631e32017-05-25 12:50:51 -0400923 DRM_IOCTL32_DEF(DRM_IOCTL_GET_SAREA_CTX, compat_drm_getsareactx),
Al Viro9e075682017-05-25 12:53:59 -0400924 DRM_IOCTL32_DEF(DRM_IOCTL_RES_CTX, compat_drm_resctx),
Al Viroc6f08962017-05-25 12:58:47 -0400925 DRM_IOCTL32_DEF(DRM_IOCTL_DMA, compat_drm_dma),
Daniel Vettera7fb8a22015-09-09 16:45:52 +0200926#if IS_ENABLED(CONFIG_AGP)
Al Viroe92673e2017-05-25 13:17:17 -0400927 DRM_IOCTL32_DEF(DRM_IOCTL_AGP_ENABLE, compat_drm_agp_enable),
928 DRM_IOCTL32_DEF(DRM_IOCTL_AGP_INFO, compat_drm_agp_info),
929 DRM_IOCTL32_DEF(DRM_IOCTL_AGP_ALLOC, compat_drm_agp_alloc),
930 DRM_IOCTL32_DEF(DRM_IOCTL_AGP_FREE, compat_drm_agp_free),
931 DRM_IOCTL32_DEF(DRM_IOCTL_AGP_BIND, compat_drm_agp_bind),
932 DRM_IOCTL32_DEF(DRM_IOCTL_AGP_UNBIND, compat_drm_agp_unbind),
Dave Airlie9a186642005-06-23 21:29:18 +1000933#endif
Al Viro314ed732017-05-25 13:24:59 -0400934 DRM_IOCTL32_DEF(DRM_IOCTL_SG_ALLOC, compat_drm_sg_alloc),
935 DRM_IOCTL32_DEF(DRM_IOCTL_SG_FREE, compat_drm_sg_free),
David Miller09e40d62009-02-18 01:35:21 -0800936#if defined(CONFIG_X86) || defined(CONFIG_IA64)
Al Viro1a36bf12017-05-25 13:28:51 -0400937 DRM_IOCTL32_DEF(DRM_IOCTL_UPDATE_DRAW, compat_drm_update_draw),
David Miller09e40d62009-02-18 01:35:21 -0800938#endif
Al Virod5288c82017-05-25 13:33:11 -0400939 DRM_IOCTL32_DEF(DRM_IOCTL_WAIT_VBLANK, compat_drm_wait_vblank),
Kristian H. Kristensena9885882016-09-13 14:20:45 -0700940#if defined(CONFIG_X86) || defined(CONFIG_IA64)
Al Virod6c56612017-05-25 15:45:04 -0400941 DRM_IOCTL32_DEF(DRM_IOCTL_MODE_ADDFB2, compat_drm_mode_addfb2),
Kristian H. Kristensena9885882016-09-13 14:20:45 -0700942#endif
Dave Airlie9a186642005-06-23 21:29:18 +1000943};
944
945/**
Daniel Vetter26409812017-04-04 11:52:57 +0200946 * drm_compat_ioctl - 32bit IOCTL compatibility handler for DRM drivers
947 * @filp: file this ioctl is called on
948 * @cmd: ioctl cmd number
949 * @arg: user argument
Dave Airlie9a186642005-06-23 21:29:18 +1000950 *
Daniel Vetter26409812017-04-04 11:52:57 +0200951 * Compatibility handler for 32 bit userspace running on 64 kernels. All actual
952 * IOCTL handling is forwarded to drm_ioctl(), while marshalling structures as
953 * appropriate. Note that this only handles DRM core IOCTLs, if the driver has
954 * botched IOCTL itself, it must handle those by wrapping this function.
955 *
956 * Returns:
957 * Zero on success, negative error code on failure.
Dave Airlie9a186642005-06-23 21:29:18 +1000958 */
959long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
960{
961 unsigned int nr = DRM_IOCTL_NR(cmd);
962 drm_ioctl_compat_t *fn;
963 int ret;
964
Ian Romanick7ffa05e2007-11-22 17:02:08 +1000965 /* Assume that ioctls without an explicit compat routine will just
966 * work. This may not always be a good assumption, but it's better
967 * than always failing.
968 */
Dave Airlie3d774612006-08-07 20:07:43 +1000969 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
Arnd Bergmanned8b6702009-12-16 22:17:09 +0000970 return drm_ioctl(filp, cmd, arg);
Dave Airlie9a186642005-06-23 21:29:18 +1000971
Al Viro9f43e542017-05-24 13:59:22 -0400972 fn = drm_compat_ioctls[nr].fn;
973 if (!fn)
974 return drm_ioctl(filp, cmd, arg);
Dave Airlie9a186642005-06-23 21:29:18 +1000975
Al Viro9f43e542017-05-24 13:59:22 -0400976 if (drm_compat_ioctls[nr].name) {
977 struct drm_file *file_priv = filp->private_data;
978 DRM_DEBUG("pid=%d, dev=0x%lx, auth=%d, %s\n",
979 task_pid_nr(current),
980 (long)old_encode_dev(file_priv->minor->kdev->devt),
981 file_priv->authenticated,
982 drm_compat_ioctls[nr].name);
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000983 ret = (*fn) (filp, cmd, arg);
Al Viro9f43e542017-05-24 13:59:22 -0400984 if (ret)
985 DRM_DEBUG("ret = %d\n", ret);
986 } else {
987 ret = (*fn) (filp, cmd, arg);
988 }
Dave Airlie9a186642005-06-23 21:29:18 +1000989 return ret;
990}
Dave Airlie9a186642005-06-23 21:29:18 +1000991EXPORT_SYMBOL(drm_compat_ioctl);