lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1b358a4b-855d-4d4d-ac2d-9941461848ba@bootlin.com>
Date: Tue, 13 May 2025 09:11:58 +0200
From: Louis Chauvet <louis.chauvet@...tlin.com>
To: Lyude Paul <lyude@...hat.com>
Cc: dri-devel@...ts.freedesktop.org, rust-for-linux@...r.kernel.org,
 Danilo Krummrich <dakr@...nel.org>, mcanal@...lia.com,
 Alice Ryhl <aliceryhl@...gle.com>, Maxime Ripard <mripard@...nel.org>,
 Simona Vetter <sima@...ll.ch>, Daniel Almeida
 <daniel.almeida@...labora.com>, Miguel Ojeda <ojeda@...nel.org>,
 Alex Gaynor <alex.gaynor@...il.com>, Boqun Feng <boqun.feng@...il.com>,
 Gary Guo <gary@...yguo.net>, Björn Roy Baron
 <bjorn3_gh@...tonmail.com>, Benno Lossin <benno.lossin@...ton.me>,
 Andreas Hindborg <a.hindborg@...nel.org>, Trevor Gross <tmgross@...ch.edu>,
 Asahi Lina <lina@...hilina.net>, open list <linux-kernel@...r.kernel.org>
Subject: Re: [RFC v3 01/33] rust: drm: Add a small handful of fourcc bindings

On 05/03/25 - 17:59, 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@...hat.com>
> 
> ---
> 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@...hat.com>
> ---
>  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');

Two questions:
- Can we implement fourcc_code(b"XR24"), so XR24 can be found with grep 
without knowing the internals of rust bindings.
- This is maybe "too much abstraction", I don't know what is the 
expectation for the kernel, why not creating a FourCC type? This could 
avoid confusion with other FourCC code from v4l2? This could also be 
complex to automate the generation, so it is maybe a bad idea.

#[repr(transparent)]
struct FourCC(u32);

and then implement From<[u8; 4]> and From<u32>?

Thanks,
Louis Chauvet

> diff --git a/rust/kernel/drm/mod.rs b/rust/kernel/drm/mod.rs
> index c44760a1332fa..2c12dbd181997 100644
> --- a/rust/kernel/drm/mod.rs
> +++ b/rust/kernel/drm/mod.rs
> @@ -5,5 +5,6 @@
>  pub mod device;
>  pub mod drv;
>  pub mod file;
> +pub mod fourcc;
>  pub mod gem;
>  pub mod ioctl;
> -- 
> 2.48.1
> 
> 

-- 
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ