DRIVER SPECIFIC IOCTLS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… driver specific ioctls πŸ’…

okay bestie, welcome to driver specific ioctls β€” that's the page, section 9 of the Kernel API Manual, and it's genuinely all about how render drivers get their own private IOCTLs. buckle up πŸŽ€


✨ the whole vibe (aka where we're at)

first things first, periodt: driver private IOCTLs should only be needed for drivers that support rendering. kernel modesetting is all standardized, and it gets extended through properties. there are a few exceptions floating around in some existing drivers β€” they define IOCTLs for use by the display DRM master β€” but ngl they all predate properties. old money, not new money πŸ’€

so, if you do have a render driver, you always have to support it through driver private properties. there's a few steps needed to wire all the things up 🧚


🌸 step one: define the struct

you need to define the structure for your IOCTL in your driver private UAPI header, include/uapi/drm/my_driver_drm.h:

struct my_driver_operation {
        u32 some_thing;
        u32 another_thing;
};

please make sure you follow all the best practices from Documentation/process/botching-up-ioctls.rst πŸ™

⚠️ heads up bestie: drm_ioctl automatically zero-extends structures, so make sure you can add more stuff at the end β€” i.e. don't put a variable sized array there. don't do it. i'm serious. 😭

πŸ¦‹ step two: define your IOCTL number

then you need to define your IOCTL number, using one of DRM_IO, DRM_IOR, DRM_IOW or DRM_IOWR. it must start with the DRM_IOCTL_ prefix ✨

##define DRM_IOCTL_MY_DRIVER_OPERATION         DRM_IOW(DRM_COMMAND_BASE, struct my_driver_operation)

DRM driver private IOCTL must be in the range from DRM_COMMAND_BASE to DRM_COMMAND_END. no cap, that's the whole range, stay in it πŸ’…


πŸ’– step three: wire up the handlers

finally you need an array of struct drm_ioctl_desc to wire up the handlers and set the access rights:

static const struct drm_ioctl_desc my_driver_ioctls[] = {
    DRM_IOCTL_DEF_DRV(MY_DRIVER_OPERATION, my_driver_operation,
            DRM_AUTH|DRM_RENDER_ALLOW),
};

and then assign this to the drm_driver.ioctls field in your driver structure. slay, you're basically done πŸ‘‘


🌈 one more thing

see the separate chapter on file operations<drm_driver_fops> (:ref: β€” yk the ref markup) for how the driver-specific IOCTLs are wired up 🫢


⭐ SEE ALSO ⭐


aaand that's the page!! πŸŽ€ this iconic little number lives at ./drivers/gpu/drm, dated October 2026 β€” go off, kernel docs, you ate πŸ’œπŸŒΈ

πŸ“¦ where this page comes from