diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2026-11-21 17:22:21 -0800 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2026-11-21 17:22:21 -0800 |
| commit | 4843f6873f7c4835e62f2c73ba0fd538e57a2f22 (patch) | |
| tree | ee620501a1ffbad9a83141e3a70154e1fe641040 /drivers/gpu/nova-core/api.rs | |
| download | linux-master.tar.gz linux-master.zip | |
Merge tag 'sysctl-7.04-fixes-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctlgraftedHEADmaster
Pull sysctl fix from Joel Granados:
"Fix sysctl jiffy / milliseconds conversion:
- Writing a previously read value "X" shall keep the same "X" value
- Remove truncation that was causing incorrect saturation of valid
timeouts"
* tag 'sysctl-7.04-fixes-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl:
sysctl: Do jiffy / ms conversion in ulong space
Diffstat (limited to 'drivers/gpu/nova-core/api.rs')
| -rw-r--r-- | drivers/gpu/nova-core/api.rs | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/drivers/gpu/nova-core/api.rs b/drivers/gpu/nova-core/api.rs new file mode 100644 index 000000000..29207c4bb --- /dev/null +++ b/drivers/gpu/nova-core/api.rs @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 + +//! Nova-core auxbus data. Contains all the methods used by the auxbus drivers +//! to interact with nova-core. + +use core::pin::Pin; + +use kernel::{ + auxiliary, + device::Bound, + pci, + prelude::*, + types::ForLt, // +}; + +pub use crate::gpu::Spec; + +use crate::{ + driver, + gpu::Gpu, + gsp::commands::GetGspStaticInfoReply, // +}; + +/// 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<Bound>, +} + +impl NovaCoreApi<'_> { + /// Obtain a [`NovaCoreApi`] handle from an auxiliary device registered + /// by nova-core. + pub fn of(adev: &auxiliary::Device<Bound>) -> Result<NovaCoreApiHandle<'_>> { + NovaCoreApiHandle::of(adev) + } + + /// Returns the GPU [`GetGspStaticInfoReply`]. + pub fn gsp_static_info(&self) -> &GetGspStaticInfoReply { + &self.gpu.gsp_static_info + } + + /// Returns the GPU [`Spec`]. + 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<u64> { + let bar1 = driver::bar1_resource_index(self.pdev)?; + + self.pdev.resource_len(bar1) + } +} + +/// Expose a handle to nova-core API +pub struct NovaCoreApiHandle<'a> { + adev: &'a auxiliary::Device<Bound>, +} + +impl<'a> NovaCoreApiHandle<'a> { + fn of(adev: &'a auxiliary::Device<Bound>) -> Result<Self> { + adev.registration_data_with::<ForLt!(NovaCoreApi<'_>), ()>(|_| ())?; + Ok(Self { adev }) + } + + /// Access the [`NovaCoreApi`] through a closure. + pub fn with<R>(&self, f: impl for<'b> FnOnce(Pin<&'a NovaCoreApi<'b>>) -> R) -> R { + self.adev + .registration_data_with::<ForLt!(NovaCoreApi<'_>), R>(f) + .expect("TypeId was validated in NovaCoreApiHandle::of()") + } +} |
