drm: nova: Add GPU architecture enum to nova-drm UAPI

The GPU architecture to be exposed to user-space. This adds a public
enum to the userspace headers for each chip architecture. Nova-core can
then use this enum to define its architectures.

This does create a coupling between nova-drm and nova-core whereby
nova-core depends on the values defined by the user-space API for
nova-drm. However this is entirely appropriate as nova-core must be
bound by the UAPI headers as the enum values are read by nova-core and
passed through to user-space.

It also requires a minor change to the bounded_enum! macro to match the
architecture values in an expression context.

Signed-off-by: Alistair Popple <apopple@nvidia.com>
Link: https://patch.msgid.link/20260909064506.910162-5-apopple@nvidia.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Alistair Popple 2026-09-09 16:44:57 +10:00 committed by Danilo Krummrich
parent ecedc604e0
commit 342aaa7bb3
3 changed files with 29 additions and 11 deletions

View File

@ -16,6 +16,7 @@
SizeConstants,
SZ_4K, //
},
uapi, //
};
use crate::{
@ -50,8 +51,9 @@
mod regs;
macro_rules! define_chipset {
({ $($variant:ident = $value:expr),* $(,)* }) =>
({ $($variant:ident = $value:literal),* $(,)* }) =>
{
::kernel::macros::paste!(
/// Enum representation of the GPU chipset.
#[derive(fmt::Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq)]
pub(crate) enum Chipset {
@ -63,7 +65,6 @@ impl Chipset {
$( Chipset::$variant, )*
];
::kernel::macros::paste!(
/// Returns the name of this chipset, in lowercase.
///
/// # Examples
@ -79,7 +80,6 @@ pub(crate) const fn name(&self) -> &'static str {
)*
}
}
);
}
// TODO[FPRI]: replace with something like derive(FromPrimitive)
@ -88,11 +88,14 @@ impl TryFrom<u32> for Chipset {
fn try_from(value: u32) -> Result<Self, Self::Error> {
match value {
$( $value => Ok(Chipset::$variant), )*
$(
$value => Ok(Chipset::$variant),
)*
_ => Err(ENODEV),
}
}
}
);
}
}
@ -177,13 +180,16 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
bounded_enum! {
/// Enum representation of the GPU generation.
#[derive(fmt::Debug, Copy, Clone)]
#[repr(u32)]
pub(crate) enum Architecture with TryFrom<Bounded<u32, 6>> {
Turing = 0x16,
Ampere = 0x17,
Hopper = 0x18,
Ada = 0x19,
BlackwellGB10x = 0x1a,
BlackwellGB20x = 0x1b,
Turing = uapi::drm_nova_architecture_NOVA_DRM_ARCHITECTURE_TURING,
Ampere = uapi::drm_nova_architecture_NOVA_DRM_ARCHITECTURE_AMPERE,
Hopper = uapi::drm_nova_architecture_NOVA_DRM_ARCHITECTURE_HOPPER,
Ada = uapi::drm_nova_architecture_NOVA_DRM_ARCHITECTURE_ADA,
BlackwellGB10x =
uapi::drm_nova_architecture_NOVA_DRM_ARCHITECTURE_BLACKWELL_GB10X,
BlackwellGB20x =
uapi::drm_nova_architecture_NOVA_DRM_ARCHITECTURE_BLACKWELL_GB20X,
}
}

View File

@ -263,7 +263,7 @@ fn try_from(
) -> kernel::error::Result<Self> {
match value.get() {
$(
$value => Ok($enum_type::$variant),
value if value == $value => Ok($enum_type::$variant),
)*
_ => Err(kernel::error::code::EINVAL),
}

View File

@ -25,6 +25,18 @@ extern "C" {
*/
#define NOVA_GETPARAM_VRAM_BAR_SIZE 0x1
/**
* enum drm_nova_architecture - GPU architecture identifier
*/
enum drm_nova_architecture {
NOVA_DRM_ARCHITECTURE_TURING = 0x16,
NOVA_DRM_ARCHITECTURE_AMPERE = 0x17,
NOVA_DRM_ARCHITECTURE_HOPPER = 0x18,
NOVA_DRM_ARCHITECTURE_ADA = 0x19,
NOVA_DRM_ARCHITECTURE_BLACKWELL_GB10X = 0x1a,
NOVA_DRM_ARCHITECTURE_BLACKWELL_GB20X = 0x1b,
};
/**
* struct drm_nova_getparam - query GPU and driver metadata
*/