]> git.ipfire.org Git - thirdparty/linux.git/commit
drm/dumb-buffers: Provide helper to set pitch and size
authorThomas Zimmermann <tzimmermann@suse.de>
Thu, 21 Aug 2025 08:17:09 +0000 (10:17 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Mon, 29 Sep 2025 11:57:43 +0000 (13:57 +0200)
commitfb24aaf5415cc686fb0473eb782a7c8a7bab0469
treee052c5619ad117a5530cf41135e27662d7317269
parent5ae38389636d5e081c905019aa37082535173da4
drm/dumb-buffers: Provide helper to set pitch and size

Add drm_modes_size_dumb(), a helper to calculate the dumb-buffer
scanline pitch and allocation size. Implementations of struct
drm_driver.dumb_create can call the new helper for their size
computations.

There is currently quite a bit of code duplication among DRM's
memory managers. Each calculates scanline pitch and buffer size
from the given arguments, but the implementations are inconsistent
in how they treat alignment and format support. Later patches will
unify this code on top of drm_mode_size_dumb() as much as possible.

drm_mode_size_dumb() uses existing 4CC format helpers to interpret
the given color mode. This makes the dumb-buffer interface behave
similar the kernel's video= parameter. Current per-driver implementations
again likely have subtle differences or bugs in how they support color
modes.

The dumb-buffer UAPI is only specified for known color modes. These
values describe linear, single-plane RGB color formats or legacy index
formats. Other values should not be specified. But some user space
still does. So for unknown color modes, there are a number of known
exceptions for which drm_mode_size_dumb() calculates the pitch from
the bpp value, as before. All other values work the same but print
an error.

v6:
- document additional use cases for DUMB_CREATE2 in TODO list (Tomi)
- fix typos in documentation (Tomi)
v5:
- check for overflows with check_mul_overflow() (Tomi)
v4:
- use %u conversion specifier (Geert)
- list DRM_FORMAT_Dn in UAPI docs (Geert)
- avoid dmesg spamming with drm_warn_once() (Sima)
- add more information about bpp special case (Sima)
- clarify parameters for hardware alignment
- add a TODO item for DUMB_CREATE2
v3:
- document the UAPI semantics
- compute scanline pitch from for unknown color modes (Andy, Tomi)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ideasonboard.com>
Link: https://lore.kernel.org/r/20250821081918.79786-3-tzimmermann@suse.de
Documentation/gpu/todo.rst
drivers/gpu/drm/drm_dumb_buffers.c
include/drm/drm_dumb_buffers.h [new file with mode: 0644]
include/uapi/drm/drm_mode.h