One of the first things a user needs to know about a GPU is its chipset, so add an ioctl to return that.
Signed-off-by: Alistair Popple <[email protected]> --- drivers/gpu/drm/nova/driver.rs | 1 - drivers/gpu/drm/nova/file.rs | 3 ++- drivers/gpu/nova-core/api.rs | 7 ++++++- drivers/gpu/nova-core/gpu.rs | 10 +++++----- include/uapi/drm/nova_drm.h | 7 +++++++ 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/nova/driver.rs b/drivers/gpu/drm/nova/driver.rs index 3ae719540e4d..42f8845ed6b4 100644 --- a/drivers/gpu/drm/nova/driver.rs +++ b/drivers/gpu/drm/nova/driver.rs @@ -31,7 +31,6 @@ pub(crate) struct Nova<'bound> { /// DRM registration data, accessible from ioctl handlers via the registration guard. pub(crate) struct DrmRegData<'bound> { - #[allow(dead_code)] pub(crate) api: Pin<&'bound NovaCoreApi<'bound>>, } diff --git a/drivers/gpu/drm/nova/file.rs b/drivers/gpu/drm/nova/file.rs index 855b6ffe696f..e573be34bb96 100644 --- a/drivers/gpu/drm/nova/file.rs +++ b/drivers/gpu/drm/nova/file.rs @@ -29,7 +29,7 @@ impl File { /// IOCTL: get_param: Query GPU / driver metadata. pub(crate) fn get_param( dev: &NovaDevice<Registered>, - _reg_data: &DrmRegData<'_>, + reg_data: &DrmRegData<'_>, getparam: &mut uapi::drm_nova_getparam, _file: &drm::File<File>, ) -> Result<u32> { @@ -38,6 +38,7 @@ pub(crate) fn get_param( let value = match getparam.param as u32 { uapi::NOVA_GETPARAM_VRAM_BAR_SIZE => pdev.resource_len(1)?, + uapi::NOVA_GETPARAM_GPU_CHIPSET => reg_data.api.chipset() as u64, _ => return Err(EINVAL), }; diff --git a/drivers/gpu/nova-core/api.rs b/drivers/gpu/nova-core/api.rs index 68ba8bda800a..14ca26e257d3 100644 --- a/drivers/gpu/nova-core/api.rs +++ b/drivers/gpu/nova-core/api.rs @@ -12,11 +12,11 @@ types::CovariantForLt, // }; +use crate::gpu::Chipset; use crate::gpu::Gpu; /// API handle for the auxiliary bus child drivers to interact with nova-core. pub struct NovaCoreApi<'bound> { - #[allow(dead_code)] pub(crate) gpu: Pin<&'bound Gpu<'bound>>, } @@ -26,4 +26,9 @@ impl NovaCoreApi<'_> { pub fn of(adev: &auxiliary::Device<Bound>) -> Result<Pin<&NovaCoreApi<'_>>> { adev.registration_data::<CovariantForLt!(NovaCoreApi<'_>)>() } + + /// Returns the chipset of this GPU. + pub fn chipset(&self) -> Chipset { + self.gpu.spec.chipset + } } diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs index 43c3f4f8df71..d4a71a1be6f1 100644 --- a/drivers/gpu/nova-core/gpu.rs +++ b/drivers/gpu/nova-core/gpu.rs @@ -38,7 +38,7 @@ macro_rules! define_chipset { { /// Enum representation of the GPU chipset. #[derive(fmt::Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq)] - pub(crate) enum Chipset { + pub enum Chipset { $($variant = $value),*, } @@ -114,7 +114,7 @@ fn try_from(value: u32) -> Result<Self, Self::Error> { }); impl Chipset { - pub(crate) const fn arch(self) -> Architecture { + pub const fn arch(self) -> Architecture { match self { Self::TU102 | Self::TU104 | Self::TU106 | Self::TU117 | Self::TU116 => { Architecture::Turing @@ -172,7 +172,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { bounded_enum! { /// Enum representation of the GPU generation. #[derive(fmt::Debug, Copy, Clone)] - pub(crate) enum Architecture with TryFrom<Bounded<u32, 6>> { + pub enum Architecture with TryFrom<Bounded<u32, 6>> { Turing = 0x16, Ampere = 0x17, Hopper = 0x18, @@ -206,7 +206,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { /// Structure holding a basic description of the GPU: `Chipset` and `Revision`. #[derive(Clone, Copy)] pub(crate) struct Spec { - chipset: Chipset, + pub(crate) chipset: Chipset, revision: Revision, } @@ -286,7 +286,7 @@ struct GspResources<'gpu> { /// Structure holding the resources required to operate the GPU. #[pin_data] pub(crate) struct Gpu<'gpu> { - spec: Spec, + pub(crate) spec: Spec, /// Static GPU information as provided by the GSP. gsp_static_info: GetGspStaticInfoReply, /// GSP and its resources. diff --git a/include/uapi/drm/nova_drm.h b/include/uapi/drm/nova_drm.h index 3ca90ed9d2bb..63440f5dca9b 100644 --- a/include/uapi/drm/nova_drm.h +++ b/include/uapi/drm/nova_drm.h @@ -25,6 +25,13 @@ extern "C" { */ #define NOVA_GETPARAM_VRAM_BAR_SIZE 0x1 +/* + * NOVA_GETPARAM_GPU_CHIPSET + * + * Query the GPU chipset architecture/implementation. + */ +#define NOVA_GETPARAM_GPU_CHIPSET 0x2 + /** * struct drm_nova_getparam - query GPU and driver metadata */ -- 2.54.0
