gpu: nova-core: avoid repeated calls to pci::Device::as_ref

Add a local `Device` reference created from the `pci::Device` in the
`Gpu` constructor to avoid repeatedly calling `as_ref`.

Reviewed-by: Eliot Courtney <ecourtney@nvidia.com>
Link: https://patch.msgid.link/20260709-nova-bootcontext-v6-10-520cbf8b9b50@nvidia.com
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
This commit is contained in:
Alexandre Courbot 2026-07-09 15:53:03 +09:00
parent 691f6bc891
commit f1aab4b1ab

View File

@ -317,9 +317,11 @@ pub(crate) fn new(
pdev: &'gpu pci::Device<device::Core<'_>>,
bar: Bar0<'gpu>,
) -> impl PinInit<Self, Error> + 'gpu {
let dev = pdev.as_ref();
try_pin_init!(Self {
spec: Spec::new(pdev.as_ref(), bar).inspect(|spec| {
dev_info!(pdev,"NVIDIA ({})\n", spec);
spec: Spec::new(dev, bar).inspect(|spec| {
dev_info!(dev,"NVIDIA ({})\n", spec);
})?,
// We must wait for GFW_BOOT completion before doing any significant setup on the GPU.
@ -332,11 +334,11 @@ pub(crate) fn new(
unsafe { pdev.dma_set_mask_and_coherent(dma_mask)? };
hal.wait_gfw_boot_completion(bar)
.inspect_err(|_| dev_err!(pdev, "GFW boot did not complete\n"))?;
.inspect_err(|_| dev_err!(dev, "GFW boot did not complete\n"))?;
},
// Initialize this early because `gsp_resources` depends on it.
sysmem_flush: SysmemFlush::register(pdev.as_ref(), bar, spec.chipset)?,
sysmem_flush: SysmemFlush::register(dev, bar, spec.chipset)?,
gsp_resources <- try_pin_init!(GspResources {
device: pdev,
@ -346,13 +348,13 @@ pub(crate) fn new(
bar,
gsp_falcon: Falcon::new(
pdev.as_ref(),
dev,
spec.chipset,
bar
)
.inspect(|falcon| falcon.clear_swgen0_intr())?,
sec2_falcon: Falcon::new(pdev.as_ref(), spec.chipset, bar)?,
sec2_falcon: Falcon::new(dev, spec.chipset, bar)?,
gsp <- Gsp::new(pdev),
@ -372,18 +374,18 @@ pub(crate) fn new(
// Obtain and display basic GPU information.
let info = gsp_resources.gsp.get_static_info(bar)?;
match info.gpu_name() {
Ok(name) => dev_info!(pdev, "GPU name: {}\n", name),
Err(e) => dev_warn!(pdev, "GPU name unavailable: {:?}\n", e),
Ok(name) => dev_info!(dev, "GPU name: {}\n", name),
Err(e) => dev_warn!(dev, "GPU name unavailable: {:?}\n", e),
}
if !info.usable_fb_regions.is_empty() {
dev_dbg!(pdev, "Usable FB regions:\n");
dev_dbg!(dev, "Usable FB regions:\n");
for region in &info.usable_fb_regions {
dev_dbg!(pdev, " - {:#x?}\n", region);
dev_dbg!(dev, " - {:#x?}\n", region);
}
dev_dbg!(
pdev,
dev,
"Total usable VRAM: {} MiB\n",
info.usable_fb_regions.iter().fold(0u64, |res, region| res
.saturating_add(region.end - region.start))