Re: [RFC v3 01/33] rust: drm: Add a small handful of fourcc bindings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Wed, Mar 05, 2025 at 05:59:17PM -0500, Lyude Paul wrote:
> This adds some very basic rust bindings for fourcc. We only have a single
> format code added for the moment, but this is enough to get a driver
> registered.
> 
> Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
> 
> ---
> V3:
> * Drop FormatList and ModifierList
>   These aren't actually needed as pointed out by Louis Chauvet
> * Add a constant for FORMAT_MOD_INVALID
>   I realized that we actually need this because the format list isn't
>   terminated with a 0 like I thought, and we can't pick this up
>   automatically through bindgen
> * Split out the FormatInfo WIP
>   We'll want this someday, but not yet.
> 
> Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
> ---
>  rust/kernel/drm/fourcc.rs | 21 +++++++++++++++++++++
>  rust/kernel/drm/mod.rs    |  1 +
>  2 files changed, 22 insertions(+)
>  create mode 100644 rust/kernel/drm/fourcc.rs
> 
> diff --git a/rust/kernel/drm/fourcc.rs b/rust/kernel/drm/fourcc.rs
> new file mode 100644
> index 0000000000000..62203478b5955
> --- /dev/null
> +++ b/rust/kernel/drm/fourcc.rs
> @@ -0,0 +1,21 @@
> +// SPDX-License-Identifier: GPL-2.0 OR MIT
> +
> +//! DRM fourcc bindings.
> +//!
> +//! C header: [`include/uapi/drm/drm_fourcc.h`](srctree/include/uapi/drm/drm_fourcc.h)
> +
> +/// Return a fourcc format code.
> +const fn fourcc_code(a: u8, b: u8, c: u8, d: u8) -> u32 {
> +    (a as u32) | (b as u32) << 8 | (c as u32) << 16 | (d as u32) << 24
> +}
> +
> +// TODO: We manually import this because we don't have a reasonable way of getting constants from
> +// function-like macros in bindgen yet.
> +#[allow(dead_code)]
> +pub(crate) const FORMAT_MOD_INVALID: u64 = 0xffffffffffffff;
> +
> +// TODO: We need to automate importing all of these. For the time being, just add the single one
> +// that we need
> +
> +/// 32 bpp RGB
> +pub const XRGB888: u32 = fourcc_code(b'X', b'R', b'2', b'4');

It would be nice to keep the DRM prefix still. Fourccs aren't quite
standardized and the ones from v4l2 and DRM don't match for the same
formats.

The rest looks good to me

Maxime

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux