From 7edc491f6fca8e22f51e37a16d74914cd959274d Mon Sep 17 00:00:00 2001 From: Alistair Popple Date: Wed, 9 Sep 2026 16:45:02 +1000 Subject: [PATCH] drm: nova: Use nova-core to read VRAM_BAR_SIZE parameter Currently nova-drm reads the VRAM BAR size directly from the PCIe device which requires trying to cast the parent device into a PCIe device. This obviously requires the parent device to actually be a PCIe bus device. Whilst that is true today it may not always be the case, and there is no reason to make this assumption now that NovaCoreApi can hold a reference to the bound PCIe device. So convert nova-drm to using nova-core to obtain the VRAM_BAR_SIZE parameter. Suggested-by: Danilo Krummrich Signed-off-by: Alistair Popple Link: https://patch.msgid.link/20260909064506.910162-10-apopple@nvidia.com Signed-off-by: Danilo Krummrich --- drivers/gpu/drm/nova/file.rs | 12 +++--------- drivers/gpu/nova-core/api.rs | 8 ++++++++ drivers/gpu/nova-core/driver.rs | 2 +- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/nova/file.rs b/drivers/gpu/drm/nova/file.rs index 988f639af116..38aca1a1e3a4 100644 --- a/drivers/gpu/drm/nova/file.rs +++ b/drivers/gpu/drm/nova/file.rs @@ -8,8 +8,6 @@ use crate::gem::NovaObject; use kernel::{ alloc::flags::*, - auxiliary, - device::Bound, drm::{ self, gem::BaseObject, @@ -19,7 +17,6 @@ arch::IntoSafeCastArch, IntoSafeCast, // }, - pci, prelude::*, transmute::AsBytes, uaccess::UserSlice, @@ -85,16 +82,13 @@ fn open(_dev: &NovaDevice) -> Result>> { impl File { /// IOCTL: get_param: Query GPU / driver metadata. pub(crate) fn get_param( - dev: &NovaDevice, - _reg_data: &DrmRegData<'_>, + _dev: &NovaDevice, + reg_data: &DrmRegData<'_>, getparam: &mut uapi::drm_nova_getparam, _file: &drm::File, ) -> Result { - let adev: &auxiliary::Device = dev.as_ref(); - let pdev: &pci::Device = adev.parent().try_into()?; - let value = match getparam.param.try_into()? { - uapi::NOVA_GETPARAM_VRAM_BAR_SIZE => pdev.resource_len(1)?, + uapi::NOVA_GETPARAM_VRAM_BAR_SIZE => reg_data.api.with(|api| api.bar1_size())?, _ => return Err(EINVAL), }; diff --git a/drivers/gpu/nova-core/api.rs b/drivers/gpu/nova-core/api.rs index 64f9ea442278..f02c6c7c7e51 100644 --- a/drivers/gpu/nova-core/api.rs +++ b/drivers/gpu/nova-core/api.rs @@ -8,6 +8,7 @@ use kernel::{ auxiliary, device::Bound, + pci, prelude::*, types::ForLt, // }; @@ -20,6 +21,7 @@ /// API handle for the auxiliary bus child drivers to interact with nova-core. pub struct NovaCoreApi<'bound> { pub(crate) gpu: Pin<&'bound Gpu<'bound>>, + pub(crate) pdev: &'bound pci::Device, } impl NovaCoreApi<'_> { @@ -38,6 +40,12 @@ pub fn gsp_static_info(&self) -> &GetGspStaticInfoReply { pub fn spec(&self) -> &Spec { &self.gpu.spec } + + /// Returns the size of the PCIe BAR used for accessing VRAM, typically + /// BAR1. + pub fn bar1_size(&self) -> Result { + self.pdev.resource_len(1) + } } /// Expose a handle to nova-core API diff --git a/drivers/gpu/nova-core/driver.rs b/drivers/gpu/nova-core/driver.rs index d2f20943142d..bdaed5408a00 100644 --- a/drivers/gpu/nova-core/driver.rs +++ b/drivers/gpu/nova-core/driver.rs @@ -146,7 +146,7 @@ fn probe<'bound>( // never recycles IDs. AUXILIARY_ID_COUNTER.fetch_add(1, Relaxed), crate::MODULE_NAME, - NovaCoreApi { gpu }, + NovaCoreApi { gpu, pdev }, )? } },