Daniel Vetter | 2640981 | 2017-04-04 11:52:57 +0200 | [diff] [blame] | 1 | /* |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 2 | * \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 Dietrich | cafe8d8 | 2011-06-04 15:36:43 +0000 | [diff] [blame] | 31 | #include <linux/ratelimit.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 32 | #include <linux/export.h> |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 33 | |
Sam Ravnborg | 0500c04 | 2019-05-26 19:35:35 +0200 | [diff] [blame] | 34 | #include <drm/drm_file.h> |
| 35 | #include <drm/drm_print.h> |
| 36 | |
Al Viro | d6c5661 | 2017-05-25 15:45:04 -0400 | [diff] [blame] | 37 | #include "drm_crtc_internal.h" |
Sam Ravnborg | 0500c04 | 2019-05-26 19:35:35 +0200 | [diff] [blame] | 38 | #include "drm_internal.h" |
| 39 | #include "drm_legacy.h" |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 40 | |
| 41 | #define DRM_IOCTL_VERSION32 DRM_IOWR(0x00, drm_version32_t) |
| 42 | #define DRM_IOCTL_GET_UNIQUE32 DRM_IOWR(0x01, drm_unique32_t) |
| 43 | #define DRM_IOCTL_GET_MAP32 DRM_IOWR(0x04, drm_map32_t) |
| 44 | #define DRM_IOCTL_GET_CLIENT32 DRM_IOWR(0x05, drm_client32_t) |
| 45 | #define DRM_IOCTL_GET_STATS32 DRM_IOR( 0x06, drm_stats32_t) |
| 46 | |
| 47 | #define DRM_IOCTL_SET_UNIQUE32 DRM_IOW( 0x10, drm_unique32_t) |
| 48 | #define DRM_IOCTL_ADD_MAP32 DRM_IOWR(0x15, drm_map32_t) |
| 49 | #define DRM_IOCTL_ADD_BUFS32 DRM_IOWR(0x16, drm_buf_desc32_t) |
| 50 | #define DRM_IOCTL_MARK_BUFS32 DRM_IOW( 0x17, drm_buf_desc32_t) |
| 51 | #define DRM_IOCTL_INFO_BUFS32 DRM_IOWR(0x18, drm_buf_info32_t) |
| 52 | #define DRM_IOCTL_MAP_BUFS32 DRM_IOWR(0x19, drm_buf_map32_t) |
| 53 | #define DRM_IOCTL_FREE_BUFS32 DRM_IOW( 0x1a, drm_buf_free32_t) |
| 54 | |
| 55 | #define DRM_IOCTL_RM_MAP32 DRM_IOW( 0x1b, drm_map32_t) |
| 56 | |
| 57 | #define DRM_IOCTL_SET_SAREA_CTX32 DRM_IOW( 0x1c, drm_ctx_priv_map32_t) |
| 58 | #define DRM_IOCTL_GET_SAREA_CTX32 DRM_IOWR(0x1d, drm_ctx_priv_map32_t) |
| 59 | |
| 60 | #define DRM_IOCTL_RES_CTX32 DRM_IOWR(0x26, drm_ctx_res32_t) |
| 61 | #define DRM_IOCTL_DMA32 DRM_IOWR(0x29, drm_dma32_t) |
| 62 | |
| 63 | #define DRM_IOCTL_AGP_ENABLE32 DRM_IOW( 0x32, drm_agp_mode32_t) |
| 64 | #define DRM_IOCTL_AGP_INFO32 DRM_IOR( 0x33, drm_agp_info32_t) |
| 65 | #define DRM_IOCTL_AGP_ALLOC32 DRM_IOWR(0x34, drm_agp_buffer32_t) |
| 66 | #define DRM_IOCTL_AGP_FREE32 DRM_IOW( 0x35, drm_agp_buffer32_t) |
| 67 | #define DRM_IOCTL_AGP_BIND32 DRM_IOW( 0x36, drm_agp_binding32_t) |
| 68 | #define DRM_IOCTL_AGP_UNBIND32 DRM_IOW( 0x37, drm_agp_binding32_t) |
| 69 | |
| 70 | #define DRM_IOCTL_SG_ALLOC32 DRM_IOW( 0x38, drm_scatter_gather32_t) |
| 71 | #define DRM_IOCTL_SG_FREE32 DRM_IOW( 0x39, drm_scatter_gather32_t) |
| 72 | |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 73 | #define DRM_IOCTL_UPDATE_DRAW32 DRM_IOW( 0x3f, drm_update_draw32_t) |
| 74 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 75 | #define DRM_IOCTL_WAIT_VBLANK32 DRM_IOWR(0x3a, drm_wait_vblank32_t) |
| 76 | |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 77 | #define DRM_IOCTL_MODE_ADDFB232 DRM_IOWR(0xb8, drm_mode_fb_cmd232_t) |
| 78 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 79 | typedef struct drm_version_32 { |
Daniel Vetter | 2640981 | 2017-04-04 11:52:57 +0200 | [diff] [blame] | 80 | int version_major; /* Major version */ |
| 81 | int version_minor; /* Minor version */ |
| 82 | int version_patchlevel; /* Patch level */ |
| 83 | u32 name_len; /* Length of name buffer */ |
| 84 | u32 name; /* Name of driver */ |
| 85 | u32 date_len; /* Length of date buffer */ |
| 86 | u32 date; /* User-space buffer to hold date */ |
| 87 | u32 desc_len; /* Length of desc buffer */ |
| 88 | u32 desc; /* User-space buffer to hold desc */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 89 | } drm_version32_t; |
| 90 | |
| 91 | static int compat_drm_version(struct file *file, unsigned int cmd, |
| 92 | unsigned long arg) |
| 93 | { |
| 94 | drm_version32_t v32; |
Al Viro | 012c674 | 2017-05-24 14:11:03 -0400 | [diff] [blame] | 95 | struct drm_version v; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 96 | int err; |
| 97 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 98 | if (copy_from_user(&v32, (void __user *)arg, sizeof(v32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 99 | return -EFAULT; |
| 100 | |
Daniel Vetter | e926c47 | 2021-02-22 11:06:43 +0100 | [diff] [blame] | 101 | memset(&v, 0, sizeof(v)); |
| 102 | |
Al Viro | 012c674 | 2017-05-24 14:11:03 -0400 | [diff] [blame] | 103 | v = (struct drm_version) { |
| 104 | .name_len = v32.name_len, |
| 105 | .name = compat_ptr(v32.name), |
| 106 | .date_len = v32.date_len, |
| 107 | .date = compat_ptr(v32.date), |
| 108 | .desc_len = v32.desc_len, |
| 109 | .desc = compat_ptr(v32.desc), |
| 110 | }; |
| 111 | err = drm_ioctl_kernel(file, drm_version, &v, |
Daniel Vetter | 7542636 | 2019-06-05 14:08:35 +0200 | [diff] [blame] | 112 | DRM_RENDER_ALLOW); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 113 | if (err) |
| 114 | return err; |
| 115 | |
Al Viro | 012c674 | 2017-05-24 14:11:03 -0400 | [diff] [blame] | 116 | v32.version_major = v.version_major; |
| 117 | v32.version_minor = v.version_minor; |
| 118 | v32.version_patchlevel = v.version_patchlevel; |
Jeffy Chen | 266530b | 2017-07-12 14:18:32 +0800 | [diff] [blame] | 119 | v32.name_len = v.name_len; |
| 120 | v32.date_len = v.date_len; |
| 121 | v32.desc_len = v.desc_len; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 122 | if (copy_to_user((void __user *)arg, &v32, sizeof(v32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 123 | return -EFAULT; |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | typedef struct drm_unique32 { |
Daniel Vetter | 2640981 | 2017-04-04 11:52:57 +0200 | [diff] [blame] | 128 | u32 unique_len; /* Length of unique */ |
| 129 | u32 unique; /* Unique name for driver instantiation */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 130 | } drm_unique32_t; |
| 131 | |
| 132 | static int compat_drm_getunique(struct file *file, unsigned int cmd, |
| 133 | unsigned long arg) |
| 134 | { |
| 135 | drm_unique32_t uq32; |
Al Viro | 17e3dad | 2017-05-24 14:15:20 -0400 | [diff] [blame] | 136 | struct drm_unique uq; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 137 | int err; |
| 138 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 139 | if (copy_from_user(&uq32, (void __user *)arg, sizeof(uq32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 140 | return -EFAULT; |
Daniel Vetter | e926c47 | 2021-02-22 11:06:43 +0100 | [diff] [blame] | 141 | |
| 142 | memset(&uq, 0, sizeof(uq)); |
| 143 | |
Al Viro | 17e3dad | 2017-05-24 14:15:20 -0400 | [diff] [blame] | 144 | uq = (struct drm_unique){ |
| 145 | .unique_len = uq32.unique_len, |
| 146 | .unique = compat_ptr(uq32.unique), |
| 147 | }; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 148 | |
Daniel Vetter | 7542636 | 2019-06-05 14:08:35 +0200 | [diff] [blame] | 149 | err = drm_ioctl_kernel(file, drm_getunique, &uq, 0); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 150 | if (err) |
| 151 | return err; |
| 152 | |
Al Viro | 17e3dad | 2017-05-24 14:15:20 -0400 | [diff] [blame] | 153 | uq32.unique_len = uq.unique_len; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 154 | if (copy_to_user((void __user *)arg, &uq32, sizeof(uq32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 155 | return -EFAULT; |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | static int compat_drm_setunique(struct file *file, unsigned int cmd, |
| 160 | unsigned long arg) |
| 161 | { |
Al Viro | 56c275c | 2017-05-24 14:20:21 -0400 | [diff] [blame] | 162 | /* it's dead */ |
| 163 | return -EINVAL; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 164 | } |
| 165 | |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 166 | #if IS_ENABLED(CONFIG_DRM_LEGACY) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 167 | typedef struct drm_map32 { |
Daniel Vetter | 2640981 | 2017-04-04 11:52:57 +0200 | [diff] [blame] | 168 | u32 offset; /* Requested physical address (0 for SAREA) */ |
| 169 | u32 size; /* Requested physical size (bytes) */ |
| 170 | enum drm_map_type type; /* Type of memory to map */ |
| 171 | enum drm_map_flags flags; /* Flags */ |
| 172 | u32 handle; /* User-space: "Handle" to pass to mmap() */ |
| 173 | int mtrr; /* MTRR slot used */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 174 | } drm_map32_t; |
| 175 | |
| 176 | static int compat_drm_getmap(struct file *file, unsigned int cmd, |
| 177 | unsigned long arg) |
| 178 | { |
| 179 | drm_map32_t __user *argp = (void __user *)arg; |
| 180 | drm_map32_t m32; |
Al Viro | 8c4fe49 | 2017-05-24 14:26:39 -0400 | [diff] [blame] | 181 | struct drm_map map; |
| 182 | int err; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 183 | |
Al Viro | 8c4fe49 | 2017-05-24 14:26:39 -0400 | [diff] [blame] | 184 | if (copy_from_user(&m32, argp, sizeof(m32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 185 | return -EFAULT; |
| 186 | |
Al Viro | 8c4fe49 | 2017-05-24 14:26:39 -0400 | [diff] [blame] | 187 | map.offset = m32.offset; |
Daniel Vetter | 7542636 | 2019-06-05 14:08:35 +0200 | [diff] [blame] | 188 | err = drm_ioctl_kernel(file, drm_legacy_getmap_ioctl, &map, 0); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 189 | if (err) |
| 190 | return err; |
| 191 | |
Al Viro | 8c4fe49 | 2017-05-24 14:26:39 -0400 | [diff] [blame] | 192 | m32.offset = map.offset; |
| 193 | m32.size = map.size; |
| 194 | m32.type = map.type; |
| 195 | m32.flags = map.flags; |
Ben Dooks | e552f08 | 2019-03-01 12:00:46 +0000 | [diff] [blame] | 196 | m32.handle = ptr_to_compat((void __user *)map.handle); |
Al Viro | 8c4fe49 | 2017-05-24 14:26:39 -0400 | [diff] [blame] | 197 | m32.mtrr = map.mtrr; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 198 | if (copy_to_user(argp, &m32, sizeof(m32))) |
| 199 | return -EFAULT; |
| 200 | return 0; |
| 201 | |
| 202 | } |
| 203 | |
| 204 | static int compat_drm_addmap(struct file *file, unsigned int cmd, |
| 205 | unsigned long arg) |
| 206 | { |
| 207 | drm_map32_t __user *argp = (void __user *)arg; |
| 208 | drm_map32_t m32; |
Al Viro | b36180a | 2017-05-24 19:27:36 -0400 | [diff] [blame] | 209 | struct drm_map map; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 210 | int err; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 211 | |
| 212 | if (copy_from_user(&m32, argp, sizeof(m32))) |
| 213 | return -EFAULT; |
| 214 | |
Al Viro | b36180a | 2017-05-24 19:27:36 -0400 | [diff] [blame] | 215 | map.offset = m32.offset; |
| 216 | map.size = m32.size; |
| 217 | map.type = m32.type; |
| 218 | map.flags = m32.flags; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 219 | |
Al Viro | b36180a | 2017-05-24 19:27:36 -0400 | [diff] [blame] | 220 | err = drm_ioctl_kernel(file, drm_legacy_addmap_ioctl, &map, |
| 221 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 222 | if (err) |
| 223 | return err; |
| 224 | |
Al Viro | b36180a | 2017-05-24 19:27:36 -0400 | [diff] [blame] | 225 | m32.offset = map.offset; |
| 226 | m32.mtrr = map.mtrr; |
Ben Dooks | e552f08 | 2019-03-01 12:00:46 +0000 | [diff] [blame] | 227 | m32.handle = ptr_to_compat((void __user *)map.handle); |
Al Viro | b36180a | 2017-05-24 19:27:36 -0400 | [diff] [blame] | 228 | if (map.handle != compat_ptr(m32.handle)) |
Joe Perches | 499447d | 2017-02-28 04:55:53 -0800 | [diff] [blame] | 229 | pr_err_ratelimited("compat_drm_addmap truncated handle %p for type %d offset %x\n", |
Al Viro | b36180a | 2017-05-24 19:27:36 -0400 | [diff] [blame] | 230 | map.handle, m32.type, m32.offset); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 231 | |
| 232 | if (copy_to_user(argp, &m32, sizeof(m32))) |
| 233 | return -EFAULT; |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static int compat_drm_rmmap(struct file *file, unsigned int cmd, |
| 239 | unsigned long arg) |
| 240 | { |
| 241 | drm_map32_t __user *argp = (void __user *)arg; |
Al Viro | 6113252 | 2017-05-25 15:47:44 -0400 | [diff] [blame] | 242 | struct drm_map map; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 243 | u32 handle; |
| 244 | |
| 245 | if (get_user(handle, &argp->handle)) |
| 246 | return -EFAULT; |
Al Viro | 6113252 | 2017-05-25 15:47:44 -0400 | [diff] [blame] | 247 | map.handle = compat_ptr(handle); |
| 248 | return drm_ioctl_kernel(file, drm_legacy_rmmap_ioctl, &map, DRM_AUTH); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 249 | } |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 250 | #endif |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 251 | |
| 252 | typedef struct drm_client32 { |
Daniel Vetter | 2640981 | 2017-04-04 11:52:57 +0200 | [diff] [blame] | 253 | int idx; /* Which client desired? */ |
| 254 | int auth; /* Is client authenticated? */ |
| 255 | u32 pid; /* Process ID */ |
| 256 | u32 uid; /* User ID */ |
| 257 | u32 magic; /* Magic */ |
| 258 | u32 iocs; /* Ioctl count */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 259 | } drm_client32_t; |
| 260 | |
| 261 | static int compat_drm_getclient(struct file *file, unsigned int cmd, |
| 262 | unsigned long arg) |
| 263 | { |
| 264 | drm_client32_t c32; |
| 265 | drm_client32_t __user *argp = (void __user *)arg; |
Al Viro | 9e92662 | 2017-05-24 19:10:32 -0400 | [diff] [blame] | 266 | struct drm_client client; |
| 267 | int err; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 268 | |
Al Viro | 9e92662 | 2017-05-24 19:10:32 -0400 | [diff] [blame] | 269 | if (copy_from_user(&c32, argp, sizeof(c32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 270 | return -EFAULT; |
| 271 | |
Daniel Vetter | e926c47 | 2021-02-22 11:06:43 +0100 | [diff] [blame] | 272 | memset(&client, 0, sizeof(client)); |
| 273 | |
Al Viro | 9e92662 | 2017-05-24 19:10:32 -0400 | [diff] [blame] | 274 | client.idx = c32.idx; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 275 | |
Daniel Vetter | 7542636 | 2019-06-05 14:08:35 +0200 | [diff] [blame] | 276 | err = drm_ioctl_kernel(file, drm_getclient, &client, 0); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 277 | if (err) |
| 278 | return err; |
| 279 | |
Al Viro | 9e92662 | 2017-05-24 19:10:32 -0400 | [diff] [blame] | 280 | c32.idx = client.idx; |
| 281 | c32.auth = client.auth; |
| 282 | c32.pid = client.pid; |
| 283 | c32.uid = client.uid; |
| 284 | c32.magic = client.magic; |
| 285 | c32.iocs = client.iocs; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 286 | |
| 287 | if (copy_to_user(argp, &c32, sizeof(c32))) |
| 288 | return -EFAULT; |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | typedef struct drm_stats32 { |
| 293 | u32 count; |
| 294 | struct { |
| 295 | u32 value; |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 296 | enum drm_stat_type type; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 297 | } data[15]; |
| 298 | } drm_stats32_t; |
| 299 | |
| 300 | static int compat_drm_getstats(struct file *file, unsigned int cmd, |
| 301 | unsigned long arg) |
| 302 | { |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 303 | drm_stats32_t __user *argp = (void __user *)arg; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 304 | |
Daniel Vetter | 2da9a1a | 2021-02-22 11:06:08 +0100 | [diff] [blame] | 305 | /* getstats is defunct, just clear */ |
Al Viro | 8547ee9 | 2017-05-24 19:18:06 -0400 | [diff] [blame] | 306 | if (clear_user(argp, sizeof(drm_stats32_t))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 307 | return -EFAULT; |
| 308 | return 0; |
| 309 | } |
| 310 | |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 311 | #if IS_ENABLED(CONFIG_DRM_LEGACY) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 312 | typedef struct drm_buf_desc32 { |
Daniel Vetter | 2640981 | 2017-04-04 11:52:57 +0200 | [diff] [blame] | 313 | int count; /* Number of buffers of this size */ |
| 314 | int size; /* Size in bytes */ |
| 315 | int low_mark; /* Low water mark */ |
| 316 | int high_mark; /* High water mark */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 317 | int flags; |
Daniel Vetter | 2640981 | 2017-04-04 11:52:57 +0200 | [diff] [blame] | 318 | u32 agp_start; /* Start address in the AGP aperture */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 319 | } drm_buf_desc32_t; |
| 320 | |
| 321 | static int compat_drm_addbufs(struct file *file, unsigned int cmd, |
| 322 | unsigned long arg) |
| 323 | { |
| 324 | drm_buf_desc32_t __user *argp = (void __user *)arg; |
Al Viro | ff22ff9 | 2017-05-24 13:42:27 -0400 | [diff] [blame] | 325 | drm_buf_desc32_t desc32; |
| 326 | struct drm_buf_desc desc; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 327 | int err; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 328 | |
Al Viro | ff22ff9 | 2017-05-24 13:42:27 -0400 | [diff] [blame] | 329 | if (copy_from_user(&desc32, argp, sizeof(drm_buf_desc32_t))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 330 | return -EFAULT; |
| 331 | |
Al Viro | ff22ff9 | 2017-05-24 13:42:27 -0400 | [diff] [blame] | 332 | desc = (struct drm_buf_desc){ |
| 333 | desc32.count, desc32.size, desc32.low_mark, desc32.high_mark, |
| 334 | desc32.flags, desc32.agp_start |
| 335 | }; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 336 | |
Al Viro | ff22ff9 | 2017-05-24 13:42:27 -0400 | [diff] [blame] | 337 | err = drm_ioctl_kernel(file, drm_legacy_addbufs, &desc, |
| 338 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 339 | if (err) |
| 340 | return err; |
| 341 | |
Al Viro | ff22ff9 | 2017-05-24 13:42:27 -0400 | [diff] [blame] | 342 | desc32 = (drm_buf_desc32_t){ |
| 343 | desc.count, desc.size, desc.low_mark, desc.high_mark, |
| 344 | desc.flags, desc.agp_start |
| 345 | }; |
| 346 | if (copy_to_user(argp, &desc32, sizeof(drm_buf_desc32_t))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 347 | return -EFAULT; |
| 348 | |
| 349 | return 0; |
| 350 | } |
| 351 | |
| 352 | static int compat_drm_markbufs(struct file *file, unsigned int cmd, |
| 353 | unsigned long arg) |
| 354 | { |
| 355 | drm_buf_desc32_t b32; |
| 356 | drm_buf_desc32_t __user *argp = (void __user *)arg; |
Al Viro | b87b786 | 2017-07-06 02:00:00 -0400 | [diff] [blame] | 357 | struct drm_buf_desc buf; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 358 | |
| 359 | if (copy_from_user(&b32, argp, sizeof(b32))) |
| 360 | return -EFAULT; |
| 361 | |
Al Viro | dbae740 | 2017-05-24 19:30:28 -0400 | [diff] [blame] | 362 | buf.size = b32.size; |
| 363 | buf.low_mark = b32.low_mark; |
| 364 | buf.high_mark = b32.high_mark; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 365 | |
Al Viro | dbae740 | 2017-05-24 19:30:28 -0400 | [diff] [blame] | 366 | return drm_ioctl_kernel(file, drm_legacy_markbufs, &buf, |
| 367 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | typedef struct drm_buf_info32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 371 | int count; /**< Entries in list */ |
| 372 | u32 list; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 373 | } drm_buf_info32_t; |
| 374 | |
Al Viro | 5c7640a | 2017-05-24 17:54:09 -0400 | [diff] [blame] | 375 | static int copy_one_buf32(void *data, int count, struct drm_buf_entry *from) |
| 376 | { |
| 377 | drm_buf_info32_t *request = data; |
| 378 | drm_buf_desc32_t __user *to = compat_ptr(request->list); |
| 379 | drm_buf_desc32_t v = {.count = from->buf_count, |
| 380 | .size = from->buf_size, |
| 381 | .low_mark = from->low_mark, |
| 382 | .high_mark = from->high_mark}; |
Dan Carpenter | 74b67ef | 2019-06-18 16:18:43 +0300 | [diff] [blame] | 383 | |
| 384 | if (copy_to_user(to + count, &v, offsetof(drm_buf_desc32_t, flags))) |
| 385 | return -EFAULT; |
| 386 | return 0; |
Al Viro | 5c7640a | 2017-05-24 17:54:09 -0400 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | static int drm_legacy_infobufs32(struct drm_device *dev, void *data, |
| 390 | struct drm_file *file_priv) |
| 391 | { |
| 392 | drm_buf_info32_t *request = data; |
Suraj Upadhyay | 948de842 | 2020-07-02 18:53:32 +0530 | [diff] [blame] | 393 | |
Al Viro | 5c7640a | 2017-05-24 17:54:09 -0400 | [diff] [blame] | 394 | return __drm_legacy_infobufs(dev, data, &request->count, copy_one_buf32); |
| 395 | } |
| 396 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 397 | static int compat_drm_infobufs(struct file *file, unsigned int cmd, |
| 398 | unsigned long arg) |
| 399 | { |
| 400 | drm_buf_info32_t req32; |
| 401 | drm_buf_info32_t __user *argp = (void __user *)arg; |
Al Viro | 5c7640a | 2017-05-24 17:54:09 -0400 | [diff] [blame] | 402 | int err; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 403 | |
| 404 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 405 | return -EFAULT; |
| 406 | |
Al Viro | 5c7640a | 2017-05-24 17:54:09 -0400 | [diff] [blame] | 407 | if (req32.count < 0) |
| 408 | req32.count = 0; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 409 | |
Al Viro | 5c7640a | 2017-05-24 17:54:09 -0400 | [diff] [blame] | 410 | err = drm_ioctl_kernel(file, drm_legacy_infobufs32, &req32, DRM_AUTH); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 411 | if (err) |
| 412 | return err; |
| 413 | |
Al Viro | 5c7640a | 2017-05-24 17:54:09 -0400 | [diff] [blame] | 414 | if (put_user(req32.count, &argp->count)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 415 | return -EFAULT; |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | typedef struct drm_buf_pub32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 421 | int idx; /**< Index into the master buffer list */ |
| 422 | int total; /**< Buffer size */ |
| 423 | int used; /**< Amount of buffer in use (for DMA) */ |
| 424 | u32 address; /**< Address of buffer */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 425 | } drm_buf_pub32_t; |
| 426 | |
| 427 | typedef struct drm_buf_map32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 428 | int count; /**< Length of the buffer list */ |
| 429 | u32 virtual; /**< Mmap'd area in user-virtual */ |
| 430 | u32 list; /**< Buffer information */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 431 | } drm_buf_map32_t; |
| 432 | |
Al Viro | 87d3ce1 | 2017-05-25 16:24:20 -0400 | [diff] [blame] | 433 | static int map_one_buf32(void *data, int idx, unsigned long virtual, |
| 434 | struct drm_buf *buf) |
| 435 | { |
| 436 | drm_buf_map32_t *request = data; |
| 437 | drm_buf_pub32_t __user *to = compat_ptr(request->list) + idx; |
| 438 | drm_buf_pub32_t v; |
| 439 | |
| 440 | v.idx = buf->idx; |
| 441 | v.total = buf->total; |
| 442 | v.used = 0; |
| 443 | v.address = virtual + buf->offset; |
| 444 | if (copy_to_user(to, &v, sizeof(v))) |
| 445 | return -EFAULT; |
| 446 | return 0; |
| 447 | } |
| 448 | |
| 449 | static int drm_legacy_mapbufs32(struct drm_device *dev, void *data, |
| 450 | struct drm_file *file_priv) |
| 451 | { |
| 452 | drm_buf_map32_t *request = data; |
| 453 | void __user *v; |
| 454 | int err = __drm_legacy_mapbufs(dev, data, &request->count, |
| 455 | &v, map_one_buf32, |
| 456 | file_priv); |
| 457 | request->virtual = ptr_to_compat(v); |
| 458 | return err; |
| 459 | } |
| 460 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 461 | static int compat_drm_mapbufs(struct file *file, unsigned int cmd, |
| 462 | unsigned long arg) |
| 463 | { |
| 464 | drm_buf_map32_t __user *argp = (void __user *)arg; |
| 465 | drm_buf_map32_t req32; |
Al Viro | 87d3ce1 | 2017-05-25 16:24:20 -0400 | [diff] [blame] | 466 | int err; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 467 | |
| 468 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 469 | return -EFAULT; |
Al Viro | 87d3ce1 | 2017-05-25 16:24:20 -0400 | [diff] [blame] | 470 | if (req32.count < 0) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 471 | return -EINVAL; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 472 | |
Al Viro | 87d3ce1 | 2017-05-25 16:24:20 -0400 | [diff] [blame] | 473 | err = drm_ioctl_kernel(file, drm_legacy_mapbufs32, &req32, DRM_AUTH); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 474 | if (err) |
| 475 | return err; |
| 476 | |
Al Viro | 87d3ce1 | 2017-05-25 16:24:20 -0400 | [diff] [blame] | 477 | if (put_user(req32.count, &argp->count) |
| 478 | || put_user(req32.virtual, &argp->virtual)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 479 | return -EFAULT; |
| 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | typedef struct drm_buf_free32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 485 | int count; |
| 486 | u32 list; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 487 | } drm_buf_free32_t; |
| 488 | |
| 489 | static int compat_drm_freebufs(struct file *file, unsigned int cmd, |
| 490 | unsigned long arg) |
| 491 | { |
| 492 | drm_buf_free32_t req32; |
Al Viro | 8c9e4cf | 2017-05-25 12:44:05 -0400 | [diff] [blame] | 493 | struct drm_buf_free request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 494 | drm_buf_free32_t __user *argp = (void __user *)arg; |
| 495 | |
| 496 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 497 | return -EFAULT; |
| 498 | |
Al Viro | 8c9e4cf | 2017-05-25 12:44:05 -0400 | [diff] [blame] | 499 | request.count = req32.count; |
| 500 | request.list = compat_ptr(req32.list); |
| 501 | return drm_ioctl_kernel(file, drm_legacy_freebufs, &request, DRM_AUTH); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | typedef struct drm_ctx_priv_map32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 505 | unsigned int ctx_id; /**< Context requesting private mapping */ |
| 506 | u32 handle; /**< Handle of map */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 507 | } drm_ctx_priv_map32_t; |
| 508 | |
| 509 | static int compat_drm_setsareactx(struct file *file, unsigned int cmd, |
| 510 | unsigned long arg) |
| 511 | { |
| 512 | drm_ctx_priv_map32_t req32; |
Al Viro | 7900c60 | 2017-05-25 12:47:00 -0400 | [diff] [blame] | 513 | struct drm_ctx_priv_map request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 514 | drm_ctx_priv_map32_t __user *argp = (void __user *)arg; |
| 515 | |
| 516 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 517 | return -EFAULT; |
| 518 | |
Al Viro | 7900c60 | 2017-05-25 12:47:00 -0400 | [diff] [blame] | 519 | request.ctx_id = req32.ctx_id; |
| 520 | request.handle = compat_ptr(req32.handle); |
| 521 | return drm_ioctl_kernel(file, drm_legacy_setsareactx, &request, |
| 522 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static int compat_drm_getsareactx(struct file *file, unsigned int cmd, |
| 526 | unsigned long arg) |
| 527 | { |
Al Viro | d7631e3 | 2017-05-25 12:50:51 -0400 | [diff] [blame] | 528 | struct drm_ctx_priv_map req; |
| 529 | drm_ctx_priv_map32_t req32; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 530 | drm_ctx_priv_map32_t __user *argp = (void __user *)arg; |
| 531 | int err; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 532 | |
Al Viro | d7631e3 | 2017-05-25 12:50:51 -0400 | [diff] [blame] | 533 | if (copy_from_user(&req32, argp, sizeof(req32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 534 | return -EFAULT; |
| 535 | |
Al Viro | d7631e3 | 2017-05-25 12:50:51 -0400 | [diff] [blame] | 536 | req.ctx_id = req32.ctx_id; |
| 537 | err = drm_ioctl_kernel(file, drm_legacy_getsareactx, &req, DRM_AUTH); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 538 | if (err) |
| 539 | return err; |
| 540 | |
Ben Dooks | e552f08 | 2019-03-01 12:00:46 +0000 | [diff] [blame] | 541 | req32.handle = ptr_to_compat((void __user *)req.handle); |
Al Viro | d7631e3 | 2017-05-25 12:50:51 -0400 | [diff] [blame] | 542 | if (copy_to_user(argp, &req32, sizeof(req32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 543 | return -EFAULT; |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
| 548 | typedef struct drm_ctx_res32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 549 | int count; |
| 550 | u32 contexts; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 551 | } drm_ctx_res32_t; |
| 552 | |
| 553 | static int compat_drm_resctx(struct file *file, unsigned int cmd, |
| 554 | unsigned long arg) |
| 555 | { |
| 556 | drm_ctx_res32_t __user *argp = (void __user *)arg; |
| 557 | drm_ctx_res32_t res32; |
Al Viro | 9e07568 | 2017-05-25 12:53:59 -0400 | [diff] [blame] | 558 | struct drm_ctx_res res; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 559 | int err; |
| 560 | |
| 561 | if (copy_from_user(&res32, argp, sizeof(res32))) |
| 562 | return -EFAULT; |
| 563 | |
Al Viro | 9e07568 | 2017-05-25 12:53:59 -0400 | [diff] [blame] | 564 | res.count = res32.count; |
| 565 | res.contexts = compat_ptr(res32.contexts); |
| 566 | err = drm_ioctl_kernel(file, drm_legacy_resctx, &res, DRM_AUTH); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 567 | if (err) |
| 568 | return err; |
| 569 | |
Al Viro | 9e07568 | 2017-05-25 12:53:59 -0400 | [diff] [blame] | 570 | res32.count = res.count; |
| 571 | if (copy_to_user(argp, &res32, sizeof(res32))) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 572 | return -EFAULT; |
| 573 | |
| 574 | return 0; |
| 575 | } |
| 576 | |
| 577 | typedef struct drm_dma32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 578 | int context; /**< Context handle */ |
| 579 | int send_count; /**< Number of buffers to send */ |
| 580 | u32 send_indices; /**< List of handles to buffers */ |
| 581 | u32 send_sizes; /**< Lengths of data to send */ |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 582 | enum drm_dma_flags flags; /**< Flags */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 583 | int request_count; /**< Number of buffers requested */ |
| 584 | int request_size; /**< Desired size for buffers */ |
| 585 | u32 request_indices; /**< Buffer information */ |
| 586 | u32 request_sizes; |
| 587 | int granted_count; /**< Number of buffers granted */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 588 | } drm_dma32_t; |
| 589 | |
| 590 | static int compat_drm_dma(struct file *file, unsigned int cmd, |
| 591 | unsigned long arg) |
| 592 | { |
| 593 | drm_dma32_t d32; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 594 | drm_dma32_t __user *argp = (void __user *)arg; |
Al Viro | c6f0896 | 2017-05-25 12:58:47 -0400 | [diff] [blame] | 595 | struct drm_dma d; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 596 | int err; |
| 597 | |
| 598 | if (copy_from_user(&d32, argp, sizeof(d32))) |
| 599 | return -EFAULT; |
| 600 | |
Al Viro | c6f0896 | 2017-05-25 12:58:47 -0400 | [diff] [blame] | 601 | d.context = d32.context; |
| 602 | d.send_count = d32.send_count; |
| 603 | d.send_indices = compat_ptr(d32.send_indices); |
| 604 | d.send_sizes = compat_ptr(d32.send_sizes); |
| 605 | d.flags = d32.flags; |
| 606 | d.request_count = d32.request_count; |
| 607 | d.request_indices = compat_ptr(d32.request_indices); |
| 608 | d.request_sizes = compat_ptr(d32.request_sizes); |
| 609 | err = drm_ioctl_kernel(file, drm_legacy_dma_ioctl, &d, DRM_AUTH); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 610 | if (err) |
| 611 | return err; |
| 612 | |
Al Viro | c6f0896 | 2017-05-25 12:58:47 -0400 | [diff] [blame] | 613 | if (put_user(d.request_size, &argp->request_size) |
| 614 | || put_user(d.granted_count, &argp->granted_count)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 615 | return -EFAULT; |
| 616 | |
| 617 | return 0; |
| 618 | } |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 619 | #endif |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 620 | |
Thomas Zimmermann | 04dfe19 | 2021-05-07 20:57:09 +0200 | [diff] [blame] | 621 | #if IS_ENABLED(CONFIG_DRM_LEGACY) |
Daniel Vetter | a7fb8a2 | 2015-09-09 16:45:52 +0200 | [diff] [blame] | 622 | #if IS_ENABLED(CONFIG_AGP) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 623 | typedef struct drm_agp_mode32 { |
| 624 | u32 mode; /**< AGP mode */ |
| 625 | } drm_agp_mode32_t; |
| 626 | |
| 627 | static int compat_drm_agp_enable(struct file *file, unsigned int cmd, |
| 628 | unsigned long arg) |
| 629 | { |
| 630 | drm_agp_mode32_t __user *argp = (void __user *)arg; |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 631 | struct drm_agp_mode mode; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 632 | |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 633 | if (get_user(mode.mode, &argp->mode)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 634 | return -EFAULT; |
| 635 | |
Thomas Zimmermann | 04dfe19 | 2021-05-07 20:57:09 +0200 | [diff] [blame] | 636 | return drm_ioctl_kernel(file, drm_legacy_agp_enable_ioctl, &mode, |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 637 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 638 | } |
| 639 | |
| 640 | typedef struct drm_agp_info32 { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 641 | int agp_version_major; |
| 642 | int agp_version_minor; |
| 643 | u32 mode; |
| 644 | u32 aperture_base; /* physical address */ |
| 645 | u32 aperture_size; /* bytes */ |
| 646 | u32 memory_allowed; /* bytes */ |
| 647 | u32 memory_used; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 648 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 649 | /* PCI information */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 650 | unsigned short id_vendor; |
| 651 | unsigned short id_device; |
| 652 | } drm_agp_info32_t; |
| 653 | |
| 654 | static int compat_drm_agp_info(struct file *file, unsigned int cmd, |
| 655 | unsigned long arg) |
| 656 | { |
| 657 | drm_agp_info32_t __user *argp = (void __user *)arg; |
| 658 | drm_agp_info32_t i32; |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 659 | struct drm_agp_info info; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 660 | int err; |
| 661 | |
Thomas Zimmermann | 04dfe19 | 2021-05-07 20:57:09 +0200 | [diff] [blame] | 662 | err = drm_ioctl_kernel(file, drm_legacy_agp_info_ioctl, &info, DRM_AUTH); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 663 | if (err) |
| 664 | return err; |
| 665 | |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 666 | i32.agp_version_major = info.agp_version_major; |
| 667 | i32.agp_version_minor = info.agp_version_minor; |
| 668 | i32.mode = info.mode; |
| 669 | i32.aperture_base = info.aperture_base; |
| 670 | i32.aperture_size = info.aperture_size; |
| 671 | i32.memory_allowed = info.memory_allowed; |
| 672 | i32.memory_used = info.memory_used; |
| 673 | i32.id_vendor = info.id_vendor; |
| 674 | i32.id_device = info.id_device; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 675 | if (copy_to_user(argp, &i32, sizeof(i32))) |
| 676 | return -EFAULT; |
| 677 | |
| 678 | return 0; |
| 679 | } |
| 680 | |
| 681 | typedef struct drm_agp_buffer32 { |
| 682 | u32 size; /**< In bytes -- will round to page boundary */ |
| 683 | u32 handle; /**< Used for binding / unbinding */ |
| 684 | u32 type; /**< Type of memory to allocate */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 685 | u32 physical; /**< Physical used by i810 */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 686 | } drm_agp_buffer32_t; |
| 687 | |
| 688 | static int compat_drm_agp_alloc(struct file *file, unsigned int cmd, |
| 689 | unsigned long arg) |
| 690 | { |
| 691 | drm_agp_buffer32_t __user *argp = (void __user *)arg; |
| 692 | drm_agp_buffer32_t req32; |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 693 | struct drm_agp_buffer request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 694 | int err; |
| 695 | |
| 696 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 697 | return -EFAULT; |
| 698 | |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 699 | request.size = req32.size; |
| 700 | request.type = req32.type; |
Thomas Zimmermann | 04dfe19 | 2021-05-07 20:57:09 +0200 | [diff] [blame] | 701 | err = drm_ioctl_kernel(file, drm_legacy_agp_alloc_ioctl, &request, |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 702 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 703 | if (err) |
| 704 | return err; |
| 705 | |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 706 | req32.handle = request.handle; |
| 707 | req32.physical = request.physical; |
| 708 | if (copy_to_user(argp, &req32, sizeof(req32))) { |
Thomas Zimmermann | 04dfe19 | 2021-05-07 20:57:09 +0200 | [diff] [blame] | 709 | drm_ioctl_kernel(file, drm_legacy_agp_free_ioctl, &request, |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 710 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 711 | return -EFAULT; |
| 712 | } |
| 713 | |
| 714 | return 0; |
| 715 | } |
| 716 | |
| 717 | static int compat_drm_agp_free(struct file *file, unsigned int cmd, |
| 718 | unsigned long arg) |
| 719 | { |
| 720 | drm_agp_buffer32_t __user *argp = (void __user *)arg; |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 721 | struct drm_agp_buffer request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 722 | |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 723 | if (get_user(request.handle, &argp->handle)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 724 | return -EFAULT; |
| 725 | |
Thomas Zimmermann | 04dfe19 | 2021-05-07 20:57:09 +0200 | [diff] [blame] | 726 | return drm_ioctl_kernel(file, drm_legacy_agp_free_ioctl, &request, |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 727 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | typedef struct drm_agp_binding32 { |
| 731 | u32 handle; /**< From drm_agp_buffer */ |
| 732 | u32 offset; /**< In bytes -- will round to page boundary */ |
| 733 | } drm_agp_binding32_t; |
| 734 | |
| 735 | static int compat_drm_agp_bind(struct file *file, unsigned int cmd, |
| 736 | unsigned long arg) |
| 737 | { |
| 738 | drm_agp_binding32_t __user *argp = (void __user *)arg; |
| 739 | drm_agp_binding32_t req32; |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 740 | struct drm_agp_binding request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 741 | |
| 742 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 743 | return -EFAULT; |
| 744 | |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 745 | request.handle = req32.handle; |
| 746 | request.offset = req32.offset; |
Thomas Zimmermann | 04dfe19 | 2021-05-07 20:57:09 +0200 | [diff] [blame] | 747 | return drm_ioctl_kernel(file, drm_legacy_agp_bind_ioctl, &request, |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 748 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | static int compat_drm_agp_unbind(struct file *file, unsigned int cmd, |
| 752 | unsigned long arg) |
| 753 | { |
| 754 | drm_agp_binding32_t __user *argp = (void __user *)arg; |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 755 | struct drm_agp_binding request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 756 | |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 757 | if (get_user(request.handle, &argp->handle)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 758 | return -EFAULT; |
| 759 | |
Thomas Zimmermann | 04dfe19 | 2021-05-07 20:57:09 +0200 | [diff] [blame] | 760 | return drm_ioctl_kernel(file, drm_legacy_agp_unbind_ioctl, &request, |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 761 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 762 | } |
Daniel Vetter | a7fb8a2 | 2015-09-09 16:45:52 +0200 | [diff] [blame] | 763 | #endif /* CONFIG_AGP */ |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 764 | |
| 765 | typedef struct drm_scatter_gather32 { |
| 766 | u32 size; /**< In bytes -- will round to page boundary */ |
| 767 | u32 handle; /**< Used for mapping / unmapping */ |
| 768 | } drm_scatter_gather32_t; |
| 769 | |
| 770 | static int compat_drm_sg_alloc(struct file *file, unsigned int cmd, |
| 771 | unsigned long arg) |
| 772 | { |
| 773 | drm_scatter_gather32_t __user *argp = (void __user *)arg; |
Al Viro | 314ed73 | 2017-05-25 13:24:59 -0400 | [diff] [blame] | 774 | struct drm_scatter_gather request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 775 | int err; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 776 | |
Al Viro | 314ed73 | 2017-05-25 13:24:59 -0400 | [diff] [blame] | 777 | if (get_user(request.size, &argp->size)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 778 | return -EFAULT; |
| 779 | |
Al Viro | 314ed73 | 2017-05-25 13:24:59 -0400 | [diff] [blame] | 780 | err = drm_ioctl_kernel(file, drm_legacy_sg_alloc, &request, |
| 781 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 782 | if (err) |
| 783 | return err; |
| 784 | |
| 785 | /* XXX not sure about the handle conversion here... */ |
Al Viro | 314ed73 | 2017-05-25 13:24:59 -0400 | [diff] [blame] | 786 | if (put_user(request.handle >> PAGE_SHIFT, &argp->handle)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 787 | return -EFAULT; |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | static int compat_drm_sg_free(struct file *file, unsigned int cmd, |
| 793 | unsigned long arg) |
| 794 | { |
| 795 | drm_scatter_gather32_t __user *argp = (void __user *)arg; |
Al Viro | 314ed73 | 2017-05-25 13:24:59 -0400 | [diff] [blame] | 796 | struct drm_scatter_gather request; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 797 | unsigned long x; |
| 798 | |
Al Viro | 314ed73 | 2017-05-25 13:24:59 -0400 | [diff] [blame] | 799 | if (get_user(x, &argp->handle)) |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 800 | return -EFAULT; |
Al Viro | 314ed73 | 2017-05-25 13:24:59 -0400 | [diff] [blame] | 801 | request.handle = x << PAGE_SHIFT; |
| 802 | return drm_ioctl_kernel(file, drm_legacy_sg_free, &request, |
| 803 | DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 804 | } |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 805 | #endif |
Al Viro | 9cc73ce | 2017-05-25 23:25:07 -0400 | [diff] [blame] | 806 | #if defined(CONFIG_X86) |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 807 | typedef struct drm_update_draw32 { |
| 808 | drm_drawable_t handle; |
| 809 | unsigned int type; |
| 810 | unsigned int num; |
| 811 | /* 64-bit version has a 32-bit pad here */ |
| 812 | u64 data; /**< Pointer */ |
| 813 | } __attribute__((packed)) drm_update_draw32_t; |
| 814 | |
| 815 | static int compat_drm_update_draw(struct file *file, unsigned int cmd, |
| 816 | unsigned long arg) |
| 817 | { |
Daniel Vetter | 2da9a1a | 2021-02-22 11:06:08 +0100 | [diff] [blame] | 818 | /* update_draw is defunct */ |
| 819 | return 0; |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 820 | } |
David Miller | 09e40d6 | 2009-02-18 01:35:21 -0800 | [diff] [blame] | 821 | #endif |
Eric Anholt | 4956887 | 2008-10-21 11:38:50 -0700 | [diff] [blame] | 822 | |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 823 | struct drm_wait_vblank_request32 { |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 824 | enum drm_vblank_seq_type type; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 825 | unsigned int sequence; |
| 826 | u32 signal; |
| 827 | }; |
| 828 | |
| 829 | struct drm_wait_vblank_reply32 { |
Dave Airlie | ff4135a | 2007-07-16 13:53:57 +1000 | [diff] [blame] | 830 | enum drm_vblank_seq_type type; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 831 | unsigned int sequence; |
| 832 | s32 tval_sec; |
| 833 | s32 tval_usec; |
| 834 | }; |
| 835 | |
| 836 | typedef union drm_wait_vblank32 { |
| 837 | struct drm_wait_vblank_request32 request; |
| 838 | struct drm_wait_vblank_reply32 reply; |
| 839 | } drm_wait_vblank32_t; |
| 840 | |
| 841 | static int compat_drm_wait_vblank(struct file *file, unsigned int cmd, |
| 842 | unsigned long arg) |
| 843 | { |
| 844 | drm_wait_vblank32_t __user *argp = (void __user *)arg; |
| 845 | drm_wait_vblank32_t req32; |
Al Viro | d5288c8 | 2017-05-25 13:33:11 -0400 | [diff] [blame] | 846 | union drm_wait_vblank req; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 847 | int err; |
| 848 | |
| 849 | if (copy_from_user(&req32, argp, sizeof(req32))) |
| 850 | return -EFAULT; |
| 851 | |
Daniel Vetter | e926c47 | 2021-02-22 11:06:43 +0100 | [diff] [blame] | 852 | memset(&req, 0, sizeof(req)); |
| 853 | |
Al Viro | d5288c8 | 2017-05-25 13:33:11 -0400 | [diff] [blame] | 854 | req.request.type = req32.request.type; |
| 855 | req.request.sequence = req32.request.sequence; |
| 856 | req.request.signal = req32.request.signal; |
Daniel Vetter | af05559 | 2017-07-26 13:23:10 +0200 | [diff] [blame] | 857 | err = drm_ioctl_kernel(file, drm_wait_vblank_ioctl, &req, DRM_UNLOCKED); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 858 | |
Al Viro | d5288c8 | 2017-05-25 13:33:11 -0400 | [diff] [blame] | 859 | req32.reply.type = req.reply.type; |
| 860 | req32.reply.sequence = req.reply.sequence; |
| 861 | req32.reply.tval_sec = req.reply.tval_sec; |
| 862 | req32.reply.tval_usec = req.reply.tval_usec; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 863 | if (copy_to_user(argp, &req32, sizeof(req32))) |
| 864 | return -EFAULT; |
| 865 | |
Mark Yacoub | fa0b1ef | 2021-08-12 15:49:17 -0400 | [diff] [blame] | 866 | return err; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 867 | } |
| 868 | |
Al Viro | 9cc73ce | 2017-05-25 23:25:07 -0400 | [diff] [blame] | 869 | #if defined(CONFIG_X86) |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 870 | typedef struct drm_mode_fb_cmd232 { |
| 871 | u32 fb_id; |
| 872 | u32 width; |
| 873 | u32 height; |
| 874 | u32 pixel_format; |
| 875 | u32 flags; |
| 876 | u32 handles[4]; |
| 877 | u32 pitches[4]; |
| 878 | u32 offsets[4]; |
| 879 | u64 modifier[4]; |
| 880 | } __attribute__((packed)) drm_mode_fb_cmd232_t; |
| 881 | |
| 882 | static int compat_drm_mode_addfb2(struct file *file, unsigned int cmd, |
| 883 | unsigned long arg) |
| 884 | { |
| 885 | struct drm_mode_fb_cmd232 __user *argp = (void __user *)arg; |
Al Viro | b87b786 | 2017-07-06 02:00:00 -0400 | [diff] [blame] | 886 | struct drm_mode_fb_cmd2 req64; |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 887 | int err; |
| 888 | |
Daniel Vetter | e926c47 | 2021-02-22 11:06:43 +0100 | [diff] [blame] | 889 | memset(&req64, 0, sizeof(req64)); |
| 890 | |
Al Viro | d6c5661 | 2017-05-25 15:45:04 -0400 | [diff] [blame] | 891 | if (copy_from_user(&req64, argp, |
| 892 | offsetof(drm_mode_fb_cmd232_t, modifier))) |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 893 | return -EFAULT; |
| 894 | |
Al Viro | d6c5661 | 2017-05-25 15:45:04 -0400 | [diff] [blame] | 895 | if (copy_from_user(&req64.modifier, &argp->modifier, |
| 896 | sizeof(req64.modifier))) |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 897 | return -EFAULT; |
| 898 | |
Daniel Vetter | 7542636 | 2019-06-05 14:08:35 +0200 | [diff] [blame] | 899 | err = drm_ioctl_kernel(file, drm_mode_addfb2, &req64, 0); |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 900 | if (err) |
| 901 | return err; |
| 902 | |
Al Viro | d6c5661 | 2017-05-25 15:45:04 -0400 | [diff] [blame] | 903 | if (put_user(req64.fb_id, &argp->fb_id)) |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 904 | return -EFAULT; |
| 905 | |
| 906 | return 0; |
| 907 | } |
Kristian H. Kristensen | a988588 | 2016-09-13 14:20:45 -0700 | [diff] [blame] | 908 | #endif |
Tvrtko Ursulin | c631d5f | 2015-07-14 11:13:08 +0100 | [diff] [blame] | 909 | |
Al Viro | 9f43e54 | 2017-05-24 13:59:22 -0400 | [diff] [blame] | 910 | static struct { |
| 911 | drm_ioctl_compat_t *fn; |
| 912 | char *name; |
| 913 | } drm_compat_ioctls[] = { |
Al Viro | ff22ff9 | 2017-05-24 13:42:27 -0400 | [diff] [blame] | 914 | #define DRM_IOCTL32_DEF(n, f) [DRM_IOCTL_NR(n##32)] = {.fn = f, .name = #n} |
Al Viro | 012c674 | 2017-05-24 14:11:03 -0400 | [diff] [blame] | 915 | DRM_IOCTL32_DEF(DRM_IOCTL_VERSION, compat_drm_version), |
Al Viro | 17e3dad | 2017-05-24 14:15:20 -0400 | [diff] [blame] | 916 | DRM_IOCTL32_DEF(DRM_IOCTL_GET_UNIQUE, compat_drm_getunique), |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 917 | #if IS_ENABLED(CONFIG_DRM_LEGACY) |
Al Viro | 8c4fe49 | 2017-05-24 14:26:39 -0400 | [diff] [blame] | 918 | DRM_IOCTL32_DEF(DRM_IOCTL_GET_MAP, compat_drm_getmap), |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 919 | #endif |
Al Viro | 9e92662 | 2017-05-24 19:10:32 -0400 | [diff] [blame] | 920 | DRM_IOCTL32_DEF(DRM_IOCTL_GET_CLIENT, compat_drm_getclient), |
Al Viro | 8547ee9 | 2017-05-24 19:18:06 -0400 | [diff] [blame] | 921 | DRM_IOCTL32_DEF(DRM_IOCTL_GET_STATS, compat_drm_getstats), |
Al Viro | 56c275c | 2017-05-24 14:20:21 -0400 | [diff] [blame] | 922 | DRM_IOCTL32_DEF(DRM_IOCTL_SET_UNIQUE, compat_drm_setunique), |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 923 | #if IS_ENABLED(CONFIG_DRM_LEGACY) |
Al Viro | b36180a | 2017-05-24 19:27:36 -0400 | [diff] [blame] | 924 | DRM_IOCTL32_DEF(DRM_IOCTL_ADD_MAP, compat_drm_addmap), |
Al Viro | ff22ff9 | 2017-05-24 13:42:27 -0400 | [diff] [blame] | 925 | DRM_IOCTL32_DEF(DRM_IOCTL_ADD_BUFS, compat_drm_addbufs), |
Al Viro | dbae740 | 2017-05-24 19:30:28 -0400 | [diff] [blame] | 926 | DRM_IOCTL32_DEF(DRM_IOCTL_MARK_BUFS, compat_drm_markbufs), |
Al Viro | 5c7640a | 2017-05-24 17:54:09 -0400 | [diff] [blame] | 927 | DRM_IOCTL32_DEF(DRM_IOCTL_INFO_BUFS, compat_drm_infobufs), |
Al Viro | 87d3ce1 | 2017-05-25 16:24:20 -0400 | [diff] [blame] | 928 | DRM_IOCTL32_DEF(DRM_IOCTL_MAP_BUFS, compat_drm_mapbufs), |
Al Viro | 8c9e4cf | 2017-05-25 12:44:05 -0400 | [diff] [blame] | 929 | DRM_IOCTL32_DEF(DRM_IOCTL_FREE_BUFS, compat_drm_freebufs), |
Al Viro | 6113252 | 2017-05-25 15:47:44 -0400 | [diff] [blame] | 930 | DRM_IOCTL32_DEF(DRM_IOCTL_RM_MAP, compat_drm_rmmap), |
Al Viro | 7900c60 | 2017-05-25 12:47:00 -0400 | [diff] [blame] | 931 | DRM_IOCTL32_DEF(DRM_IOCTL_SET_SAREA_CTX, compat_drm_setsareactx), |
Al Viro | d7631e3 | 2017-05-25 12:50:51 -0400 | [diff] [blame] | 932 | DRM_IOCTL32_DEF(DRM_IOCTL_GET_SAREA_CTX, compat_drm_getsareactx), |
Al Viro | 9e07568 | 2017-05-25 12:53:59 -0400 | [diff] [blame] | 933 | DRM_IOCTL32_DEF(DRM_IOCTL_RES_CTX, compat_drm_resctx), |
Al Viro | c6f0896 | 2017-05-25 12:58:47 -0400 | [diff] [blame] | 934 | DRM_IOCTL32_DEF(DRM_IOCTL_DMA, compat_drm_dma), |
Daniel Vetter | a7fb8a2 | 2015-09-09 16:45:52 +0200 | [diff] [blame] | 935 | #if IS_ENABLED(CONFIG_AGP) |
Al Viro | e92673e | 2017-05-25 13:17:17 -0400 | [diff] [blame] | 936 | DRM_IOCTL32_DEF(DRM_IOCTL_AGP_ENABLE, compat_drm_agp_enable), |
| 937 | DRM_IOCTL32_DEF(DRM_IOCTL_AGP_INFO, compat_drm_agp_info), |
| 938 | DRM_IOCTL32_DEF(DRM_IOCTL_AGP_ALLOC, compat_drm_agp_alloc), |
| 939 | DRM_IOCTL32_DEF(DRM_IOCTL_AGP_FREE, compat_drm_agp_free), |
| 940 | DRM_IOCTL32_DEF(DRM_IOCTL_AGP_BIND, compat_drm_agp_bind), |
| 941 | DRM_IOCTL32_DEF(DRM_IOCTL_AGP_UNBIND, compat_drm_agp_unbind), |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 942 | #endif |
Thomas Zimmermann | 04dfe19 | 2021-05-07 20:57:09 +0200 | [diff] [blame] | 943 | #endif |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 944 | #if IS_ENABLED(CONFIG_DRM_LEGACY) |
Al Viro | 314ed73 | 2017-05-25 13:24:59 -0400 | [diff] [blame] | 945 | DRM_IOCTL32_DEF(DRM_IOCTL_SG_ALLOC, compat_drm_sg_alloc), |
| 946 | DRM_IOCTL32_DEF(DRM_IOCTL_SG_FREE, compat_drm_sg_free), |
Dave Airlie | 61ae227 | 2019-04-18 17:10:40 +1000 | [diff] [blame] | 947 | #endif |
David Miller | 09e40d6 | 2009-02-18 01:35:21 -0800 | [diff] [blame] | 948 | #if defined(CONFIG_X86) || defined(CONFIG_IA64) |
Al Viro | 1a36bf1 | 2017-05-25 13:28:51 -0400 | [diff] [blame] | 949 | DRM_IOCTL32_DEF(DRM_IOCTL_UPDATE_DRAW, compat_drm_update_draw), |
David Miller | 09e40d6 | 2009-02-18 01:35:21 -0800 | [diff] [blame] | 950 | #endif |
Al Viro | d5288c8 | 2017-05-25 13:33:11 -0400 | [diff] [blame] | 951 | DRM_IOCTL32_DEF(DRM_IOCTL_WAIT_VBLANK, compat_drm_wait_vblank), |
Kristian H. Kristensen | a988588 | 2016-09-13 14:20:45 -0700 | [diff] [blame] | 952 | #if defined(CONFIG_X86) || defined(CONFIG_IA64) |
Al Viro | d6c5661 | 2017-05-25 15:45:04 -0400 | [diff] [blame] | 953 | DRM_IOCTL32_DEF(DRM_IOCTL_MODE_ADDFB2, compat_drm_mode_addfb2), |
Kristian H. Kristensen | a988588 | 2016-09-13 14:20:45 -0700 | [diff] [blame] | 954 | #endif |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 955 | }; |
| 956 | |
| 957 | /** |
Daniel Vetter | 2640981 | 2017-04-04 11:52:57 +0200 | [diff] [blame] | 958 | * drm_compat_ioctl - 32bit IOCTL compatibility handler for DRM drivers |
| 959 | * @filp: file this ioctl is called on |
| 960 | * @cmd: ioctl cmd number |
| 961 | * @arg: user argument |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 962 | * |
Daniel Vetter | 2640981 | 2017-04-04 11:52:57 +0200 | [diff] [blame] | 963 | * Compatibility handler for 32 bit userspace running on 64 kernels. All actual |
| 964 | * IOCTL handling is forwarded to drm_ioctl(), while marshalling structures as |
| 965 | * appropriate. Note that this only handles DRM core IOCTLs, if the driver has |
| 966 | * botched IOCTL itself, it must handle those by wrapping this function. |
| 967 | * |
| 968 | * Returns: |
| 969 | * Zero on success, negative error code on failure. |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 970 | */ |
| 971 | long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
| 972 | { |
| 973 | unsigned int nr = DRM_IOCTL_NR(cmd); |
Al Viro | 88e3cb0 | 2017-05-25 16:27:27 -0400 | [diff] [blame] | 974 | struct drm_file *file_priv = filp->private_data; |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 975 | drm_ioctl_compat_t *fn; |
| 976 | int ret; |
| 977 | |
Ian Romanick | 7ffa05e | 2007-11-22 17:02:08 +1000 | [diff] [blame] | 978 | /* Assume that ioctls without an explicit compat routine will just |
| 979 | * work. This may not always be a good assumption, but it's better |
| 980 | * than always failing. |
| 981 | */ |
Dave Airlie | 3d77461 | 2006-08-07 20:07:43 +1000 | [diff] [blame] | 982 | if (nr >= ARRAY_SIZE(drm_compat_ioctls)) |
Arnd Bergmann | ed8b670 | 2009-12-16 22:17:09 +0000 | [diff] [blame] | 983 | return drm_ioctl(filp, cmd, arg); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 984 | |
Al Viro | 9f43e54 | 2017-05-24 13:59:22 -0400 | [diff] [blame] | 985 | fn = drm_compat_ioctls[nr].fn; |
| 986 | if (!fn) |
| 987 | return drm_ioctl(filp, cmd, arg); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 988 | |
Emil Velikov | 5a2ba99 | 2020-05-18 09:33:15 +0100 | [diff] [blame] | 989 | DRM_DEBUG("comm=\"%s\", pid=%d, dev=0x%lx, auth=%d, %s\n", |
| 990 | current->comm, task_pid_nr(current), |
Al Viro | 88e3cb0 | 2017-05-25 16:27:27 -0400 | [diff] [blame] | 991 | (long)old_encode_dev(file_priv->minor->kdev->devt), |
| 992 | file_priv->authenticated, |
| 993 | drm_compat_ioctls[nr].name); |
| 994 | ret = (*fn)(filp, cmd, arg); |
| 995 | if (ret) |
| 996 | DRM_DEBUG("ret = %d\n", ret); |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 997 | return ret; |
| 998 | } |
Dave Airlie | 9a18664 | 2005-06-23 21:29:18 +1000 | [diff] [blame] | 999 | EXPORT_SYMBOL(drm_compat_ioctl); |