drivers/gpu/drm/drm_ioctl.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_ioctl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_ioctl.c- Extension
.c- Size
- 30798 bytes
- Lines
- 948
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/nospec.hlinux/pci.hlinux/uaccess.hdrm/drm_auth.hdrm/drm_crtc.hdrm/drm_drv.hdrm/drm_file.hdrm/drm_ioctl.hdrm/drm_print.hdrm_crtc_internal.hdrm_internal.h
Detected Declarations
function filesfunction drm_unset_busidfunction drm_set_busidfunction drm_getclientfunction clientsfunction drm_getstatsfunction drm_getcapfunction drm_for_each_crtcfunction drm_setclientcapfunction drm_setversionfunction drm_noopfunction drm_invalid_opfunction drm_copy_fieldfunction drm_versionfunction drm_validate_value_stringfunction drm_set_client_namefunction drm_ioctl_permitfunction drm_ioctl_kernelfunction drm_ioctl_permitfunction drm_ioctl_flagsexport drm_noopexport drm_invalid_opexport drm_ioctl_kernelexport drm_ioctlexport drm_ioctl_flags
Annotated Snippet
if (copy_to_user(u->unique, master->unique, master->unique_len)) {
mutex_unlock(&dev->master_mutex);
return -EFAULT;
}
}
u->unique_len = master->unique_len;
mutex_unlock(&dev->master_mutex);
return 0;
}
static void
drm_unset_busid(struct drm_device *dev,
struct drm_master *master)
{
kfree(master->unique);
master->unique = NULL;
master->unique_len = 0;
}
static int drm_set_busid(struct drm_device *dev, struct drm_file *file_priv)
{
struct drm_master *master = file_priv->master;
int ret;
if (master->unique != NULL)
drm_unset_busid(dev, master);
if (dev->dev && dev_is_pci(dev->dev)) {
ret = drm_pci_set_busid(dev, master);
if (ret) {
drm_unset_busid(dev, master);
return ret;
}
} else {
WARN_ON(!dev->unique);
master->unique = kstrdup(dev->unique, GFP_KERNEL);
if (master->unique)
master->unique_len = strlen(dev->unique);
}
return 0;
}
/*
* Get client information.
*
* \param inode device inode.
* \param file_priv DRM file private.
* \param cmd command.
* \param arg user argument, pointing to a drm_client structure.
*
* \return zero on success or a negative number on failure.
*
* Searches for the client with the specified index and copies its information
* into userspace
*/
int drm_getclient(struct drm_device *dev, void *data,
struct drm_file *file_priv)
{
struct drm_client *client = data;
/*
* Hollowed-out getclient ioctl to keep some dead old drm tests/tools
* not breaking completely. Userspace tools stop enumerating one they
* get -EINVAL, hence this is the return value we need to hand back for
* no clients tracked.
*
* Unfortunately some clients (*cough* libva *cough*) use this in a fun
* attempt to figure out whether they're authenticated or not. Since
* that's the only thing they care about, give it to the directly
* instead of walking one giant list.
*/
if (client->idx == 0) {
client->auth = file_priv->authenticated;
client->pid = task_pid_vnr(current);
client->uid = overflowuid;
client->magic = 0;
client->iocs = 0;
return 0;
} else {
return -EINVAL;
}
}
/*
* Get statistics information.
*
* \param inode device inode.
Annotation
- Immediate include surface: `linux/export.h`, `linux/nospec.h`, `linux/pci.h`, `linux/uaccess.h`, `drm/drm_auth.h`, `drm/drm_crtc.h`, `drm/drm_drv.h`, `drm/drm_file.h`.
- Detected declarations: `function files`, `function drm_unset_busid`, `function drm_set_busid`, `function drm_getclient`, `function clients`, `function drm_getstats`, `function drm_getcap`, `function drm_for_each_crtc`, `function drm_setclientcap`, `function drm_setversion`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.