^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Created: Fri Jan 8 09:01:26 1999 by faith@valinux.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Author Rickard E. (Rik) Faith <faith@valinux.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Author Gareth Hughes <gareth@valinux.com>
^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) * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * OTHER DEALINGS IN THE SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/nospec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <drm/drm_agpsupport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <drm/drm_auth.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <drm/drm_crtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <drm/drm_drv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <drm/drm_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <drm/drm_ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <drm/drm_print.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include "drm_crtc_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include "drm_internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include "drm_legacy.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * DOC: getunique and setversion story
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * BEWARE THE DRAGONS! MIND THE TRAPDOORS!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * In an attempt to warn anyone else who's trying to figure out what's going
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * on here, I'll try to summarize the story. First things first, let's clear up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * the names, because the kernel internals, libdrm and the ioctls are all named
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * differently:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * - GET_UNIQUE ioctl, implemented by drm_getunique is wrapped up in libdrm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * through the drmGetBusid function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * - The libdrm drmSetBusid function is backed by the SET_UNIQUE ioctl. All
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * that code is nerved in the kernel with drm_invalid_op().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * - The internal set_busid kernel functions and driver callbacks are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * exclusively use by the SET_VERSION ioctl, because only drm 1.0 (which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * nerved) allowed userspace to set the busid through the above ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * - Other ioctls and functions involved are named consistently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * For anyone wondering what's the difference between drm 1.1 and 1.4: Correctly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * handling pci domains in the busid on ppc. Doing this correctly was only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * implemented in libdrm in 2010, hence can't be nerved yet. No one knows what's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * special with drm 1.2 and 1.3.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * Now the actual horror story of how device lookup in drm works. At large,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * there's 2 different ways, either by busid, or by device driver name.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * Opening by busid is fairly simple:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * 1. First call SET_VERSION to make sure pci domains are handled properly. As a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * side-effect this fills out the unique name in the master structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * 2. Call GET_UNIQUE to read out the unique name from the master structure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * which matches the busid thanks to step 1. If it doesn't, proceed to try
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * the next device node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Opening by name is slightly different:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * 1. Directly call VERSION to get the version and to match against the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * name returned by that ioctl. Note that SET_VERSION is not called, which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * means the the unique name for the master node just opening is _not_ filled
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * out. This despite that with current drm device nodes are always bound to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * one device, and can't be runtime assigned like with drm 1.0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * 2. Match driver name. If it mismatches, proceed to the next device node.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * 3. Call GET_UNIQUE, and check whether the unique name has length zero (by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * checking that the first byte in the string is 0). If that's not the case
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * libdrm skips and proceeds to the next device node. Probably this is just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * copypasta from drm 1.0 times where a set unique name meant that the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * was in use already, but that's just conjecture.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Long story short: To keep the open by name logic working, GET_UNIQUE must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * _not_ return a unique string when SET_VERSION hasn't been called yet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * otherwise libdrm breaks. Even when that unique string can't ever change, and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * is totally irrelevant for actually opening the device because runtime
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * assignable device instances were only support in drm 1.0, which is long dead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * But the libdrm code in drmOpenByName somehow survived, hence this can't be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * broken.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * Get the bus id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * \param inode device inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * \param file_priv DRM file private.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * \param cmd command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * \param arg user argument, pointing to a drm_unique structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) * \return zero on success or a negative number on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * Copies the bus id from drm_device::unique into user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) int drm_getunique(struct drm_device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) struct drm_unique *u = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct drm_master *master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) mutex_lock(&dev->master_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) master = file_priv->master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (u->unique_len >= master->unique_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) if (copy_to_user(u->unique, master->unique, master->unique_len)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) mutex_unlock(&dev->master_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) u->unique_len = master->unique_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) mutex_unlock(&dev->master_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) drm_unset_busid(struct drm_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct drm_master *master)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) kfree(master->unique);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) master->unique = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) master->unique_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) struct drm_master *master = file_priv->master;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (master->unique != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) drm_unset_busid(dev, master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (dev->dev && dev_is_pci(dev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ret = drm_pci_set_busid(dev, master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) drm_unset_busid(dev, master);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) WARN_ON(!dev->unique);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) master->unique = kstrdup(dev->unique, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (master->unique)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) master->unique_len = strlen(dev->unique);
^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) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * Get client information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * \param inode device inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * \param file_priv DRM file private.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * \param cmd command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * \param arg user argument, pointing to a drm_client structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * \return zero on success or a negative number on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) * Searches for the client with the specified index and copies its information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * into userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) int drm_getclient(struct drm_device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) struct drm_client *client = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * Hollowed-out getclient ioctl to keep some dead old drm tests/tools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * not breaking completely. Userspace tools stop enumerating one they
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * get -EINVAL, hence this is the return value we need to hand back for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) * no clients tracked.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * Unfortunately some clients (*cough* libva *cough*) use this in a fun
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) * attempt to figure out whether they're authenticated or not. Since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) * that's the only thing they care about, give it to the directly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * instead of walking one giant list.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (client->idx == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) client->auth = file_priv->authenticated;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) client->pid = task_pid_vnr(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) client->uid = overflowuid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) client->magic = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) client->iocs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * Get statistics information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * \param inode device inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * \param file_priv DRM file private.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * \param cmd command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * \param arg user argument, pointing to a drm_stats structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * \return zero on success or a negative number on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) static int drm_getstats(struct drm_device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct drm_stats *stats = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* Clear stats to prevent userspace from eating its stack garbage. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) memset(stats, 0, sizeof(*stats));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * Get device/driver capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static int drm_getcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct drm_get_cap *req = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct drm_crtc *crtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) req->value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* Only some caps make sense with UMS/render-only drivers. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) switch (req->capability) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) case DRM_CAP_TIMESTAMP_MONOTONIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) req->value = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) case DRM_CAP_PRIME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) req->value |= dev->driver->prime_fd_to_handle ? DRM_PRIME_CAP_IMPORT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) req->value |= dev->driver->prime_handle_to_fd ? DRM_PRIME_CAP_EXPORT : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) case DRM_CAP_SYNCOBJ:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) req->value = drm_core_check_feature(dev, DRIVER_SYNCOBJ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) case DRM_CAP_SYNCOBJ_TIMELINE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) req->value = drm_core_check_feature(dev, DRIVER_SYNCOBJ_TIMELINE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* Other caps only work with KMS drivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) switch (req->capability) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) case DRM_CAP_DUMB_BUFFER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (dev->driver->dumb_create)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) req->value = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) case DRM_CAP_VBLANK_HIGH_CRTC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) req->value = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) case DRM_CAP_DUMB_PREFERRED_DEPTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) req->value = dev->mode_config.preferred_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) case DRM_CAP_DUMB_PREFER_SHADOW:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) req->value = dev->mode_config.prefer_shadow;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) case DRM_CAP_ASYNC_PAGE_FLIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) req->value = dev->mode_config.async_page_flip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) case DRM_CAP_PAGE_FLIP_TARGET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) req->value = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) drm_for_each_crtc(crtc, dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (!crtc->funcs->page_flip_target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) req->value = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) case DRM_CAP_CURSOR_WIDTH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (dev->mode_config.cursor_width)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) req->value = dev->mode_config.cursor_width;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) req->value = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) case DRM_CAP_CURSOR_HEIGHT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (dev->mode_config.cursor_height)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) req->value = dev->mode_config.cursor_height;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) req->value = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) case DRM_CAP_ADDFB2_MODIFIERS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) req->value = dev->mode_config.allow_fb_modifiers;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) case DRM_CAP_CRTC_IN_VBLANK_EVENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) req->value = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * Set device/driver capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct drm_set_client_cap *req = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /* No render-only settable capabilities for now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) /* Below caps that only works with KMS drivers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (!drm_core_check_feature(dev, DRIVER_MODESET))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) switch (req->capability) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) case DRM_CLIENT_CAP_STEREO_3D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (req->value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) file_priv->stereo_allowed = req->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) case DRM_CLIENT_CAP_UNIVERSAL_PLANES:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (req->value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) file_priv->universal_planes = req->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) case DRM_CLIENT_CAP_ATOMIC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /* The modesetting DDX has a totally broken idea of atomic. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (current->comm[0] == 'X' && req->value == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) pr_info("broken atomic modeset userspace detected, disabling atomic\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (req->value > 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) file_priv->atomic = req->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) file_priv->universal_planes = req->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * No atomic user-space blows up on aspect ratio mode bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) file_priv->aspect_ratio_allowed = req->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) case DRM_CLIENT_CAP_ASPECT_RATIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (req->value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) file_priv->aspect_ratio_allowed = req->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) case DRM_CLIENT_CAP_WRITEBACK_CONNECTORS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (!file_priv->atomic)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) if (req->value > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) file_priv->writeback_connectors = req->value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) * Setversion ioctl.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) * \param inode device inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * \param file_priv DRM file private.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * \param cmd command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * \param arg user argument, pointing to a drm_lock structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) * \return zero on success or negative number on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) * Sets the requested interface version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) static int drm_setversion(struct drm_device *dev, void *data, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) struct drm_set_version *sv = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) int if_version, retcode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) mutex_lock(&dev->master_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (sv->drm_di_major != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) if (sv->drm_di_major != DRM_IF_MAJOR ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) sv->drm_di_minor < 0 || sv->drm_di_minor > DRM_IF_MINOR) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) retcode = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if_version = DRM_IF_VERSION(sv->drm_di_major,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) sv->drm_di_minor);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) dev->if_version = max(if_version, dev->if_version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (sv->drm_di_minor >= 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) * Version 1.1 includes tying of DRM to specific device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) * Version 1.4 has proper PCI domain support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) retcode = drm_set_busid(dev, file_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (retcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (sv->drm_dd_major != -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (sv->drm_dd_major != dev->driver->major ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) sv->drm_dd_minor < 0 || sv->drm_dd_minor >
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) dev->driver->minor) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) retcode = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) sv->drm_di_major = DRM_IF_MAJOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) sv->drm_di_minor = DRM_IF_MINOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) sv->drm_dd_major = dev->driver->major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) sv->drm_dd_minor = dev->driver->minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) mutex_unlock(&dev->master_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) return retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * drm_noop - DRM no-op ioctl implemntation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) * @dev: DRM device for the ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) * @data: data pointer for the ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) * @file_priv: DRM file for the ioctl call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) * This no-op implementation for drm ioctls is useful for deprecated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * functionality where we can't return a failure code because existing userspace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) * checks the result of the ioctl, but doesn't care about the action.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * Always returns successfully with 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int drm_noop(struct drm_device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) DRM_DEBUG("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) EXPORT_SYMBOL(drm_noop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * drm_invalid_op - DRM invalid ioctl implemntation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * @dev: DRM device for the ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * @data: data pointer for the ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) * @file_priv: DRM file for the ioctl call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * This no-op implementation for drm ioctls is useful for deprecated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * functionality where we really don't want to allow userspace to call the ioctl
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * any more. This is the case for old ums interfaces for drivers that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) * transitioned to kms gradually and so kept the old legacy tables around. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) * only applies to radeon and i915 kms drivers, other drivers shouldn't need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) * use this function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) * Always fails with a return value of -EINVAL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) int drm_invalid_op(struct drm_device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) EXPORT_SYMBOL(drm_invalid_op);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * Copy and IOCTL return string to user space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) /* don't overflow userbuf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) len = strlen(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) if (len > *buf_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) len = *buf_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) /* let userspace know exact length of driver value (which could be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * larger than the userspace-supplied buffer) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) *buf_len = strlen(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /* finally, try filling in the userbuf */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if (len && buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (copy_to_user(buf, value, len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * Get version information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * \param inode device inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * \param filp file pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * \param cmd command.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * \param arg user argument, pointing to a drm_version structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * \return zero on success or negative number on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * Fills in the version information in \p arg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) int drm_version(struct drm_device *dev, void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) struct drm_version *version = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) version->version_major = dev->driver->major;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) version->version_minor = dev->driver->minor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) version->version_patchlevel = dev->driver->patchlevel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) err = drm_copy_field(version->name, &version->name_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) dev->driver->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) err = drm_copy_field(version->date, &version->date_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) dev->driver->date);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) err = drm_copy_field(version->desc, &version->desc_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) dev->driver->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) * drm_ioctl_permit - Check ioctl permissions against caller
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * @flags: ioctl permission flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * @file_priv: Pointer to struct drm_file identifying the caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * Checks whether the caller is allowed to run an ioctl with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * indicated permissions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * Zero if allowed, -EACCES otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) int drm_ioctl_permit(u32 flags, struct drm_file *file_priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) #ifndef CONFIG_DRM_IGNORE_IOTCL_PERMIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) /* ROOT_ONLY is only for CAP_SYS_ADMIN */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) if (unlikely((flags & DRM_ROOT_ONLY) && !capable(CAP_SYS_ADMIN)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) /* AUTH is only for authenticated or render client */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (unlikely((flags & DRM_AUTH) && !drm_is_render_client(file_priv) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) !file_priv->authenticated))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /* MASTER is only for master or control clients */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) if (unlikely((flags & DRM_MASTER) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) !drm_is_current_master(file_priv)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) /* Render clients must be explicitly allowed */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (unlikely(!(flags & DRM_RENDER_ALLOW) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) drm_is_render_client(file_priv)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) return -EACCES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) EXPORT_SYMBOL(drm_ioctl_permit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) #define DRM_IOCTL_DEF(ioctl, _func, _flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) [DRM_IOCTL_NR(ioctl)] = { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) .cmd = ioctl, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) .func = _func, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) .flags = _flags, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) .name = #ioctl \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) #if IS_ENABLED(CONFIG_DRM_LEGACY)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) #define DRM_LEGACY_IOCTL_DEF(ioctl, _func, _flags) DRM_IOCTL_DEF(ioctl, _func, _flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) #define DRM_LEGACY_IOCTL_DEF(ioctl, _func, _flags) DRM_IOCTL_DEF(ioctl, drm_invalid_op, _flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) /* Ioctl table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static const struct drm_ioctl_desc drm_ioctls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) DRM_IOCTL_DEF(DRM_IOCTL_VERSION, drm_version, DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) DRM_IOCTL_DEF(DRM_IOCTL_GET_UNIQUE, drm_getunique, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) DRM_IOCTL_DEF(DRM_IOCTL_GET_MAGIC, drm_getmagic, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) DRM_IOCTL_DEF(DRM_IOCTL_IRQ_BUSID, drm_irq_by_busid, DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_GET_MAP, drm_legacy_getmap_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) DRM_IOCTL_DEF(DRM_IOCTL_GET_CLIENT, drm_getclient, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) DRM_IOCTL_DEF(DRM_IOCTL_GET_STATS, drm_getstats, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) DRM_IOCTL_DEF(DRM_IOCTL_GET_CAP, drm_getcap, DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) DRM_IOCTL_DEF(DRM_IOCTL_SET_CLIENT_CAP, drm_setclientcap, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) DRM_IOCTL_DEF(DRM_IOCTL_SET_VERSION, drm_setversion, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) DRM_IOCTL_DEF(DRM_IOCTL_SET_UNIQUE, drm_invalid_op, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) DRM_IOCTL_DEF(DRM_IOCTL_BLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) DRM_IOCTL_DEF(DRM_IOCTL_UNBLOCK, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) DRM_IOCTL_DEF(DRM_IOCTL_AUTH_MAGIC, drm_authmagic, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_ADD_MAP, drm_legacy_addmap_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_RM_MAP, drm_legacy_rmmap_ioctl, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_SET_SAREA_CTX, drm_legacy_setsareactx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_GET_SAREA_CTX, drm_legacy_getsareactx, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) DRM_IOCTL_DEF(DRM_IOCTL_SET_MASTER, drm_setmaster_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) DRM_IOCTL_DEF(DRM_IOCTL_DROP_MASTER, drm_dropmaster_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_ADD_CTX, drm_legacy_addctx, DRM_AUTH|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_RM_CTX, drm_legacy_rmctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_MOD_CTX, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_GET_CTX, drm_legacy_getctx, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_SWITCH_CTX, drm_legacy_switchctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_NEW_CTX, drm_legacy_newctx, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_RES_CTX, drm_legacy_resctx, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) DRM_IOCTL_DEF(DRM_IOCTL_ADD_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) DRM_IOCTL_DEF(DRM_IOCTL_RM_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_LOCK, drm_legacy_lock, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_UNLOCK, drm_legacy_unlock, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) DRM_IOCTL_DEF(DRM_IOCTL_FINISH, drm_noop, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_ADD_BUFS, drm_legacy_addbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_MARK_BUFS, drm_legacy_markbufs, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_INFO_BUFS, drm_legacy_infobufs, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_MAP_BUFS, drm_legacy_mapbufs, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_FREE_BUFS, drm_legacy_freebufs, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_DMA, drm_legacy_dma_ioctl, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_CONTROL, drm_legacy_irq_control, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) #if IS_ENABLED(CONFIG_AGP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) DRM_IOCTL_DEF(DRM_IOCTL_AGP_ACQUIRE, drm_agp_acquire_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) DRM_IOCTL_DEF(DRM_IOCTL_AGP_RELEASE, drm_agp_release_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) DRM_IOCTL_DEF(DRM_IOCTL_AGP_ENABLE, drm_agp_enable_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) DRM_IOCTL_DEF(DRM_IOCTL_AGP_INFO, drm_agp_info_ioctl, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) DRM_IOCTL_DEF(DRM_IOCTL_AGP_ALLOC, drm_agp_alloc_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) DRM_IOCTL_DEF(DRM_IOCTL_AGP_FREE, drm_agp_free_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) DRM_IOCTL_DEF(DRM_IOCTL_AGP_BIND, drm_agp_bind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) DRM_IOCTL_DEF(DRM_IOCTL_AGP_UNBIND, drm_agp_unbind_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_SG_ALLOC, drm_legacy_sg_alloc, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) DRM_LEGACY_IOCTL_DEF(DRM_IOCTL_SG_FREE, drm_legacy_sg_free, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) DRM_IOCTL_DEF(DRM_IOCTL_WAIT_VBLANK, drm_wait_vblank_ioctl, DRM_UNLOCKED),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) DRM_IOCTL_DEF(DRM_IOCTL_MODESET_CTL, drm_legacy_modeset_ctl_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_noop, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) DRM_IOCTL_DEF(DRM_IOCTL_GEM_CLOSE, drm_gem_close_ioctl, DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) DRM_IOCTL_DEF(DRM_IOCTL_GEM_FLINK, drm_gem_flink_ioctl, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) DRM_IOCTL_DEF(DRM_IOCTL_PRIME_HANDLE_TO_FD, drm_prime_handle_to_fd_ioctl, DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) DRM_IOCTL_DEF(DRM_IOCTL_PRIME_FD_TO_HANDLE, drm_prime_fd_to_handle_ioctl, DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANERESOURCES, drm_mode_getplane_res, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETCRTC, drm_mode_setcrtc, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPLANE, drm_mode_getplane, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPLANE, drm_mode_setplane, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR, drm_mode_cursor_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETGAMMA, drm_mode_gamma_get_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETGAMMA, drm_mode_gamma_set_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETENCODER, drm_mode_getencoder, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCONNECTOR, drm_mode_getconnector, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) DRM_IOCTL_DEF(DRM_IOCTL_MODE_ATTACHMODE, drm_noop, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) DRM_IOCTL_DEF(DRM_IOCTL_MODE_DETACHMODE, drm_noop, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPERTY, drm_mode_getproperty_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY, drm_connector_property_set_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB2, drm_mode_getfb2_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB2, drm_mode_addfb2_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) DRM_IOCTL_DEF(DRM_IOCTL_MODE_PAGE_FLIP, drm_mode_page_flip_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_DUMB, drm_mode_create_dumb_ioctl, DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) DRM_IOCTL_DEF(DRM_IOCTL_MODE_MAP_DUMB, drm_mode_mmap_dumb_ioctl, DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) DRM_IOCTL_DEF(DRM_IOCTL_MODE_DESTROY_DUMB, drm_mode_destroy_dumb_ioctl, DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_GETPROPERTIES, drm_mode_obj_get_properties_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_SETPROPERTY, drm_mode_obj_set_property_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR2, drm_mode_cursor2_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) DRM_IOCTL_DEF(DRM_IOCTL_MODE_ATOMIC, drm_mode_atomic_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATEPROPBLOB, drm_mode_createblob_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) DRM_IOCTL_DEF(DRM_IOCTL_MODE_DESTROYPROPBLOB, drm_mode_destroyblob_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_CREATE, drm_syncobj_create_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_DESTROY, drm_syncobj_destroy_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_HANDLE_TO_FD, drm_syncobj_handle_to_fd_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_FD_TO_HANDLE, drm_syncobj_fd_to_handle_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TRANSFER, drm_syncobj_transfer_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_WAIT, drm_syncobj_wait_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_WAIT, drm_syncobj_timeline_wait_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_RESET, drm_syncobj_reset_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_SIGNAL, drm_syncobj_signal_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_TIMELINE_SIGNAL, drm_syncobj_timeline_signal_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) DRM_IOCTL_DEF(DRM_IOCTL_SYNCOBJ_QUERY, drm_syncobj_query_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) DRM_IOCTL_DEF(DRM_IOCTL_CRTC_GET_SEQUENCE, drm_crtc_get_sequence_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) DRM_IOCTL_DEF(DRM_IOCTL_CRTC_QUEUE_SEQUENCE, drm_crtc_queue_sequence_ioctl, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) DRM_IOCTL_DEF(DRM_IOCTL_MODE_CREATE_LEASE, drm_mode_create_lease_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) DRM_IOCTL_DEF(DRM_IOCTL_MODE_LIST_LESSEES, drm_mode_list_lessees_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) DRM_IOCTL_DEF(DRM_IOCTL_MODE_GET_LEASE, drm_mode_get_lease_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) DRM_IOCTL_DEF(DRM_IOCTL_MODE_REVOKE_LEASE, drm_mode_revoke_lease_ioctl, DRM_MASTER),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) * DOC: driver specific ioctls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) * First things first, driver private IOCTLs should only be needed for drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) * supporting rendering. Kernel modesetting is all standardized, and extended
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) * through properties. There are a few exceptions in some existing drivers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) * which define IOCTL for use by the display DRM master, but they all predate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) * properties.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) * Now if you do have a render driver you always have to support it through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) * driver private properties. There's a few steps needed to wire all the things
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) * up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) * First you need to define the structure for your IOCTL in your driver private
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) * UAPI header in ``include/uapi/drm/my_driver_drm.h``::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) * struct my_driver_operation {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) * u32 some_thing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) * u32 another_thing;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) * Please make sure that you follow all the best practices from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) * ``Documentation/process/botching-up-ioctls.rst``. Note that drm_ioctl()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) * automatically zero-extends structures, hence make sure you can add more stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) * at the end, i.e. don't put a variable sized array there.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) * Then you need to define your IOCTL number, using one of DRM_IO(), DRM_IOR(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) * DRM_IOW() or DRM_IOWR(). It must start with the DRM_IOCTL\_ prefix::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) * ##define DRM_IOCTL_MY_DRIVER_OPERATION \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) * DRM_IOW(DRM_COMMAND_BASE, struct my_driver_operation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) * DRM driver private IOCTL must be in the range from DRM_COMMAND_BASE to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) * DRM_COMMAND_END. Finally you need an array of &struct drm_ioctl_desc to wire
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * up the handlers and set the access rights::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) * static const struct drm_ioctl_desc my_driver_ioctls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) * DRM_IOCTL_DEF_DRV(MY_DRIVER_OPERATION, my_driver_operation,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) * DRM_AUTH|DRM_RENDER_ALLOW),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) * };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) * And then assign this to the &drm_driver.ioctls field in your driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) * structure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) * See the separate chapter on :ref:`file operations<drm_driver_fops>` for how
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) * the driver-specific IOCTLs are wired up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) long drm_ioctl_kernel(struct file *file, drm_ioctl_t *func, void *kdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) u32 flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) struct drm_file *file_priv = file->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) struct drm_device *dev = file_priv->minor->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) int retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (drm_dev_is_unplugged(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) retcode = drm_ioctl_permit(flags, file_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) if (unlikely(retcode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) return retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) /* Enforce sane locking for modern driver ioctls. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) if (likely(!drm_core_check_feature(dev, DRIVER_LEGACY)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) (flags & DRM_UNLOCKED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) retcode = func(dev, kdata, file_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) mutex_lock(&drm_global_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) retcode = func(dev, kdata, file_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) mutex_unlock(&drm_global_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) return retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) EXPORT_SYMBOL(drm_ioctl_kernel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) * drm_ioctl - ioctl callback implementation for DRM drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) * @filp: file this ioctl is called on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) * @cmd: ioctl cmd number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) * @arg: user argument
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) * Looks up the ioctl function in the DRM core and the driver dispatch table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * stored in &drm_driver.ioctls. It checks for necessary permission by calling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * drm_ioctl_permit(), and dispatches to the respective function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * Zero on success, negative error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) long drm_ioctl(struct file *filp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) struct drm_file *file_priv = filp->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) struct drm_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) const struct drm_ioctl_desc *ioctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) drm_ioctl_t *func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) unsigned int nr = DRM_IOCTL_NR(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) int retcode = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) char stack_kdata[128];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) char *kdata = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) unsigned int in_size, out_size, drv_size, ksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) bool is_driver_ioctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) dev = file_priv->minor->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) if (drm_dev_is_unplugged(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) if (DRM_IOCTL_TYPE(cmd) != DRM_IOCTL_BASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) is_driver_ioctl = nr >= DRM_COMMAND_BASE && nr < DRM_COMMAND_END;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (is_driver_ioctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) /* driver ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) unsigned int index = nr - DRM_COMMAND_BASE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) if (index >= dev->driver->num_ioctls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) goto err_i1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) index = array_index_nospec(index, dev->driver->num_ioctls);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) ioctl = &dev->driver->ioctls[index];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) /* core ioctl */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) if (nr >= DRM_CORE_IOCTL_COUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) goto err_i1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) nr = array_index_nospec(nr, DRM_CORE_IOCTL_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) ioctl = &drm_ioctls[nr];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) drv_size = _IOC_SIZE(ioctl->cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) out_size = in_size = _IOC_SIZE(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) if ((cmd & ioctl->cmd & IOC_IN) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) in_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) if ((cmd & ioctl->cmd & IOC_OUT) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) out_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) ksize = max(max(in_size, out_size), drv_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) DRM_DEBUG("comm=\"%s\" pid=%d, dev=0x%lx, auth=%d, %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) current->comm, task_pid_nr(current),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) (long)old_encode_dev(file_priv->minor->kdev->devt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) file_priv->authenticated, ioctl->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) /* Do not trust userspace, use our own definition */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) func = ioctl->func;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) if (unlikely(!func)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) DRM_DEBUG("no function\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) retcode = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) goto err_i1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) if (ksize <= sizeof(stack_kdata)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) kdata = stack_kdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) kdata = kmalloc(ksize, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) if (!kdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) retcode = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) goto err_i1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) if (copy_from_user(kdata, (void __user *)arg, in_size) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) retcode = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) goto err_i1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) if (ksize > in_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) memset(kdata + in_size, 0, ksize - in_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) retcode = drm_ioctl_kernel(filp, func, kdata, ioctl->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) if (copy_to_user((void __user *)arg, kdata, out_size) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) retcode = -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) err_i1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) if (!ioctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) DRM_DEBUG("invalid ioctl: comm=\"%s\", pid=%d, dev=0x%lx, auth=%d, cmd=0x%02x, nr=0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) current->comm, task_pid_nr(current),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) (long)old_encode_dev(file_priv->minor->kdev->devt),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) file_priv->authenticated, cmd, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) if (kdata != stack_kdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) kfree(kdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) if (retcode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) DRM_DEBUG("comm=\"%s\", pid=%d, ret=%d\n", current->comm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) task_pid_nr(current), retcode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) return retcode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) EXPORT_SYMBOL(drm_ioctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) * drm_ioctl_flags - Check for core ioctl and return ioctl permission flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) * @nr: ioctl number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) * @flags: where to return the ioctl permission flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) * This ioctl is only used by the vmwgfx driver to augment the access checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) * done by the drm core and insofar a pretty decent layering violation. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) * shouldn't be used by any drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) * Returns:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) * True if the @nr corresponds to a DRM core ioctl number, false otherwise.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) bool drm_ioctl_flags(unsigned int nr, unsigned int *flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (nr >= DRM_COMMAND_BASE && nr < DRM_COMMAND_END)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) if (nr >= DRM_CORE_IOCTL_COUNT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) nr = array_index_nospec(nr, DRM_CORE_IOCTL_COUNT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) *flags = drm_ioctls[nr].flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) EXPORT_SYMBOL(drm_ioctl_flags);