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