Skip to contentSkip to conversation

gpu: nova-core: register definitions and basic timer and falcon devices

RFC PATCH In review Alexandre Courbot 3 participants 14 messages Mar 20, 2025 – Mar 24, 2025

Subsystems (5)
lore
Share & tools
lore

Alexandre Courbot

author maintainer
#0 lore raw

v3 cover gpu: nova-core: register definitions and basic timer and falcon devices

Hi everyone,

New RFC for the first steps towards bringing booting the GSP, with more complete Falcon code. This code has been successfully used to run the FECS-FRTS firmware from the bios and create the WPR2 region, although this series alone is not enough to reproduce this - the next revision will probably include the code required to extract that firmware from the BIOS.

As for the previous revisions, the goal is to get more eyes to look at the general direction of the driver and raise concerns if there are any, the main point of discussion being probably the register!() macro that is used to define register layouts.

The falcon code is still quite in a work-in-progress state, I am notably still thinking of the best way to implement the HAL for chip-dependent operations (right now we branch depending on the chipset, but that obviously won't scale). So the overall design is still very much flexible.

Dependencies:

- https://lore.kernel.org/rust-for-linux/20250318-topic-panthor-rs-genmask-v4-1-35004fca6ac5@collabora.com/
- https://lore.kernel.org/rust-for-linux/[email protected]/
- https://lore.kernel.org/rust-for-linux/[email protected]/
- https://lore.kernel.org/rust-for-linux/[email protected]/
- https://lore.kernel.org/rust-for-linux/[email protected]/

TODO:

- Document more registers and fields,
- Add BIOS extractor code to obtain the FWSEC-FRTS firmware,
- Complete FWSEC-FRTS execution to obtain WPR2 region.

---
Changes in v3:
- Fixed typo in Boot0 register definition that made probing fail.
- Moved the register definition macros to their own patch series.
- Used Revocable::try_access_with() when accessing registers.
- Added all the Falcon code required to boot FWSEC-FRTS.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Don't hold the Bar guard in methods that can sleep.
- Added a Timestamp type for Timer to safely and easily get durations between two measurements.
- Added a macro to make register definitions easier.
- Added a very basic falcon implementation to define more registers and exercise the register definition macro.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Alexandre Courbot (7):
rust: add useful ops for u64
rust: make ETIMEDOUT error available
gpu: nova-core: derive useful traits for Chipset
gpu: nova-core: add missing GA100 definition
gpu: nova-core: use register!() to define register layout
gpu: nova-core: add basic timer device
gpu: nova-core: add falcon register definitions and probe code

 drivers/gpu/nova-core/driver.rs    |   4 +-
 drivers/gpu/nova-core/falcon.rs    | 618 +++++++++++++++++++++++++++++++++++++
 drivers/gpu/nova-core/gpu.rs       |  78 ++++-
 drivers/gpu/nova-core/nova_core.rs |  14 +
 drivers/gpu/nova-core/regs.rs      | 261 ++++++++++++----
 drivers/gpu/nova-core/timer.rs     | 132 ++++++++
 rust/kernel/error.rs               |   1 +
 rust/kernel/lib.rs                 |   1 +
 rust/kernel/num.rs                 |  52 ++++
 9 files changed, 1101 insertions(+), 60 deletions(-)

---
base-commit: 1d53763dc16c9fc9329a4cdc14d691979d47568f
change-id: 20250216-nova_timer-c69430184f54
prerequisite-change-id: 20241023-topic-panthor-rs-genmask-fabc573fef43:v4
prerequisite-patch-id: 182945904fd914573eed9388a559ce8a642310ef
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 73f4047ae5d3e4d51cfa285bd8fd0f1c04d47409
prerequisite-patch-id: 5ad45352d9d457a45886eeea90a46cc21516356e
prerequisite-patch-id: 725e7d42309919c759fdd0585a97810b1eb72706
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: de15c0d16727e6af2d79f88f5b67be4c06212552
prerequisite-patch-id: f8bca95d983222da29508cc6e6886e4b0f992588
prerequisite-patch-id: 1ae8f68250fb43808342285a284bcf7b572263fe
prerequisite-patch-id: fa5ce1308e1dbc71374a381537ab3978babe20a0
prerequisite-patch-id: 7225e000f745bb5fd45fc43393d801d1d9adb767

Best regards,

Signature · 1 line
Alexandre Courbot <[email protected]>
author maintainer
#1 lore raw

RFC PATCH v3 1/7 rust: add useful ops for u64

It is common to build a u64 from its high and low parts obtained from two 32-bit registers. Conversely, it is also common to split a u64 into two u32s to write them into registers. Add an extension trait for u64 that implement these methods in a new num module.

It is expected that this trait will be extended with other useful operations, and similar extension traits implemented for other types.

---
 rust/kernel/lib.rs |  1 +
 rust/kernel/num.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)
rust/kernel/lib.rs +1 -0
index 2fe10df9a45ccd5fa24330f927abdf9dfb874d44..a9499597ed9650f8fae9b2f53fa9abeea05071f4 100644
@@ -62,6 +62,7 @@
 pub mod miscdevice;
 #[cfg(CONFIG_NET)]
 pub mod net;
+pub mod num;
 pub mod of;
 pub mod page;
 #[cfg(CONFIG_PCI)]
rust/kernel/num.rs new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.48.1
author maintainer
#2 lore raw

RFC PATCH v3 2/7 rust: make ETIMEDOUT error available

In reply to Alexandre Courbot
---
 rust/kernel/error.rs | 1 +
 1 file changed, 1 insertion(+)
rust/kernel/error.rs +1 -0
index 1e510181432cceae46219f7ed3597a88b85ebe0a..475d14a4830774aa7717d3b5e70c7ff9de203dc2 100644
@@ -65,6 +65,7 @@ macro_rules! declare_err {
     declare_err!(EDOM, "Math argument out of domain of func.");
     declare_err!(ERANGE, "Math result not representable.");
     declare_err!(EOVERFLOW, "Value too large for defined data type.");
+    declare_err!(ETIMEDOUT, "Connection timed out.");
     declare_err!(ERESTARTSYS, "Restart the system call.");
     declare_err!(ERESTARTNOINTR, "System call was interrupted by a signal and will be restarted.");
     declare_err!(ERESTARTNOHAND, "Restart if no handler.");
Signature · 1 line
2.48.1
author maintainer
#3 lore raw

RFC PATCH v3 3/7 gpu: nova-core: derive useful traits for Chipset

In reply to Alexandre Courbot

We will commonly need to compare chipset versions, so derive the ordering traits to make that possible. Also derive Copy and Clone since Chipsets are as cheap as an integer.

---
 drivers/gpu/nova-core/gpu.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/nova-core/gpu.rs +1 -1
index 17c9660da45034762edaa78e372d8821144cdeb7..4de67a2dc16302c00530026156d7264cbc7e5b32 100644
@@ -13,7 +13,7 @@ macro_rules! define_chipset {
     ({ $($variant:ident = $value:expr),* $(,)* }) =>
     {
         /// Enum representation of the GPU chipset.
-        #[derive(fmt::Debug)]
+        #[derive(fmt::Debug, Copy, Clone, PartialOrd, Ord, PartialEq, Eq)]
         pub(crate) enum Chipset {
             $($variant = $value),*,
         }
Signature · 1 line
2.48.1
author maintainer
#4 lore raw

RFC PATCH v3 4/7 gpu: nova-core: add missing GA100 definition

In reply to Alexandre Courbot

linux-firmware contains a directory for GA100, and it is a defined chipset in Nouveau.

---
 drivers/gpu/nova-core/gpu.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/nova-core/gpu.rs +2 -1
index 4de67a2dc16302c00530026156d7264cbc7e5b32..9fe6aedaa9563799c2624d461d4e37ee9b094909 100644
@@ -54,6 +54,7 @@ fn try_from(value: u32) -> Result<Self, Self::Error> {
     TU117 = 0x167,
     TU116 = 0x168,
     // Ampere
+    GA100 = 0x170,
     GA102 = 0x172,
     GA103 = 0x173,
     GA104 = 0x174,
@@ -73,7 +74,7 @@ pub(crate) fn arch(&self) -> Architecture {
             Self::TU102 | Self::TU104 | Self::TU106 | Self::TU117 | Self::TU116 => {
                 Architecture::Turing
             }
-            Self::GA102 | Self::GA103 | Self::GA104 | Self::GA106 | Self::GA107 => {
+            Self::GA100 | Self::GA102 | Self::GA103 | Self::GA104 | Self::GA106 | Self::GA107 => {
                 Architecture::Ampere
             }
             Self::AD102 | Self::AD103 | Self::AD104 | Self::AD106 | Self::AD107 => {
Signature · 1 line
2.48.1
author maintainer
#5 lore raw

RFC PATCH v3 5/7 gpu: nova-core: use register!() to define register layout

In reply to Alexandre Courbot

Use the register!() macro to define the layout for the Boot0 register and use its accessors through the use of the convenience with_bar!() macro, which uses Revocable::try_access() and converts its returned Option into the proper error as needed.

---
 drivers/gpu/nova-core/gpu.rs       |  5 ++--
 drivers/gpu/nova-core/nova_core.rs | 12 ++++++++
 drivers/gpu/nova-core/regs.rs      | 60 ++++++--------------------------------
 3 files changed, 23 insertions(+), 54 deletions(-)
drivers/gpu/nova-core/gpu.rs +2 -3
index 9fe6aedaa9563799c2624d461d4e37ee9b094909..d96901e5c8eace1e7c57c77da7def209e8149cd3 100644
@@ -135,11 +135,10 @@ pub(crate) struct Spec {
 
 impl Spec {
     fn new(bar: &Devres<Bar0>) -> Result<Spec> {
-        let bar = bar.try_access().ok_or(ENXIO)?;
-        let boot0 = regs::Boot0::read(&bar);
+        let boot0 = with_bar!(bar, |b| regs::Boot0::read(b))?;
 
         Ok(Self {
-            chipset: boot0.chipset().try_into()?,
+            chipset: boot0.chipset()?,
             revision: Revision::from_boot0(boot0),
         })
     }
drivers/gpu/nova-core/nova_core.rs +12 -0
index a91cd924054b49966937a8db6aab9cd0614f10de..94f4778c16f6a4d046c2f799129ed0cc68df6fd4 100644
@@ -2,6 +2,18 @@
 
 //! Nova Core GPU Driver
 
+#[macro_use]
+mod macros {
+    /// Convenience macro to run a closure while holding [`crate::driver::Bar0`].
+    ///
+    /// If the bar cannot be acquired, then `ENXIO` is returned.
+    macro_rules! with_bar {
+        ($bar:expr, $closure:expr) => {
+            $bar.try_access_with($closure).ok_or(ENXIO)
+        };
+    }
+}
+
 mod driver;
 mod firmware;
 mod gpu;
drivers/gpu/nova-core/regs.rs +9 -51

64 lines not on this page · raw message

Signature · 1 line
2.48.1
author maintainer
#6 lore raw

RFC PATCH v3 6/7 gpu: nova-core: add basic timer device

In reply to Alexandre Courbot

Add a basic timer device and exercise it during device probing. This first draft is probably very questionable.

One point in particular which should IMHO receive attention: the generic wait_on() method aims at providing similar functionality to Nouveau's nvkm_[num]sec() macros. Since this method will be heavily used with different conditions to test, I'd like to avoid monomorphizing it entirely with each instance ; that's something that is achieved in nvkm_xsec() using functions that the macros invoke.

I have tried achieving the same result in Rust using closures (kept as-is in the current code), but they seem to be monomorphized as well. Calling extra functions could work better, but looks also less elegant to me, so I am really open to suggestions here.

---
 drivers/gpu/nova-core/driver.rs    |   4 +-
 drivers/gpu/nova-core/gpu.rs       |  55 +++++++++++++++-
 drivers/gpu/nova-core/nova_core.rs |   1 +
 drivers/gpu/nova-core/regs.rs      |  11 ++++
 drivers/gpu/nova-core/timer.rs     | 132 +++++++++++++++++++++++++++++++++++++
 5 files changed, 201 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/driver.rs +3 -1
index 63c19f140fbdd65d8fccf81669ac590807cc120f..0cd23aa306e4082405f480afc0530a41131485e7 100644
@@ -10,7 +10,7 @@ pub(crate) struct NovaCore {
     pub(crate) gpu: Gpu,
 }
 
-const BAR0_SIZE: usize = 8;
+const BAR0_SIZE: usize = 0x9500;
 pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
 
 kernel::pci_device_table!(
@@ -42,6 +42,8 @@ fn probe(pdev: &mut pci::Device, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>
             GFP_KERNEL,
         )?;
 
+        let _ = this.gpu.test_timer();
+
         Ok(this)
     }
 }
drivers/gpu/nova-core/gpu.rs +54 -1

74 lines not on this page · raw message

drivers/gpu/nova-core/nova_core.rs +1 -0
index 94f4778c16f6a4d046c2f799129ed0cc68df6fd4..f54dcfc66490cb6b10090ef944ac14feca9f6972 100644
@@ -18,6 +18,7 @@ macro_rules! with_bar {
 mod firmware;
 mod gpu;
 mod regs;
+mod timer;
 mod util;
 
 kernel::module_pci_driver! {
drivers/gpu/nova-core/regs.rs +11 -0
index 7bfd2b575fe2184565d495012e55cd0829b0b1ad..0d06e09b1ba62d55688c633500f37d3fe1aeb30e 100644
@@ -11,3 +11,14 @@
     7:4     major_rev => as u8, "major revision of the chip";
     28:20   chipset => try_into Chipset, "chipset model"
 );
+
+/* PTIMER */
+
+register!(PtimerTime0@0x00009400;
+    31:0    lo => as u32, "low 32-bits of the timer"
+);
+
+register!(PtimerTime1@0x00009410;
+    31:0    hi => as u32, "high 32 bits of the timer"
+);
+
drivers/gpu/nova-core/timer.rs new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
2.48.1
#7 lore raw

Re: [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device

drivers/gpu/nova-core/timer.rs line 42

Quoted 13 lines · Alexandre Courbot
drivers/gpu/nova-core/timer.rs new file +13 -0
+impl Add<Duration> for Timestamp {
+    type Output = Self;
+
+    fn add(mut self, rhs: Duration) -> Self::Output {
+        let mut nanos = rhs.as_nanos();
+        while nanos > u64::MAX as u128 {
+            self.0 = self.0.wrapping_add(nanos as u64);
+            nanos -= u64::MAX as u128;
+        }
+
+        Timestamp(self.0.wrapping_add(nanos as u64))
+    }
+}

Perhaps I missed something, but couldn’t you simplify this method like this:

    fn add(mut self, rhs: Duration) -> Self::Output {
        let stamp = self.0 as u128;
        Timestamp(stamp.wrapping_add(rhs.as_nanos()) as u64)
    }

db48x

author maintainer
#8 lore raw

Re: [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device

Quoted 19 lines · Daniel Brooks

drivers/gpu/nova-core/timer.rs line 42

Quoted 13 lines · Alexandre Courbot
drivers/gpu/nova-core/timer.rs new file +13 -0
+impl Add<Duration> for Timestamp {
+    type Output = Self;
+
+    fn add(mut self, rhs: Duration) -> Self::Output {
+        let mut nanos = rhs.as_nanos();
+        while nanos > u64::MAX as u128 {
+            self.0 = self.0.wrapping_add(nanos as u64);
+            nanos -= u64::MAX as u128;
+        }
+
+        Timestamp(self.0.wrapping_add(nanos as u64))
+    }
+}

Perhaps I missed something, but couldn’t you simplify this method like this:

Quoted 4 lines
    fn add(mut self, rhs: Duration) -> Self::Output {
        let stamp = self.0 as u128;
        Timestamp(stamp.wrapping_add(rhs.as_nanos()) as u64)
    }

You are absolutely right, this loop will just wrap self.0 to the same value after the initial pass.

... or at least it would if there weren't two bugs in it. >_<

- It adds the lower part of nanos while substracting u64::MAX from rhs, which is completely wrong;
- Substracting u64::MAX is also wrong, it should be u64::MAX as u128 + 1.

So thanks a lot for pointing this out!

#9 lore raw

Re: [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device

In reply to Alexandre Courbot

Hi Alexandre,

Quoted 51 lines · Alexandre Courbot

Add a basic timer device and exercise it during device probing. This first draft is probably very questionable.

One point in particular which should IMHO receive attention: the generic wait_on() method aims at providing similar functionality to Nouveau's nvkm_[num]sec() macros. Since this method will be heavily used with different conditions to test, I'd like to avoid monomorphizing it entirely with each instance ; that's something that is achieved in nvkm_xsec() using functions that the macros invoke.

I have tried achieving the same result in Rust using closures (kept as-is in the current code), but they seem to be monomorphized as well. Calling extra functions could work better, but looks also less elegant to me, so I am really open to suggestions here.

---
 drivers/gpu/nova-core/driver.rs    |   4 +-
 drivers/gpu/nova-core/gpu.rs       |  55 +++++++++++++++-
 drivers/gpu/nova-core/nova_core.rs |   1 +
 drivers/gpu/nova-core/regs.rs      |  11 ++++
 drivers/gpu/nova-core/timer.rs     | 132 +++++++++++++++++++++++++++++++++++++
 5 files changed, 201 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/driver.rs +3 -1
index 63c19f140fbdd65d8fccf81669ac590807cc120f..0cd23aa306e4082405f480afc0530a41131485e7 100644
@@ -10,7 +10,7 @@ pub(crate) struct NovaCore {
     pub(crate) gpu: Gpu,
 }
 
-const BAR0_SIZE: usize = 8;
+const BAR0_SIZE: usize = 0x9500;
 pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
 
 kernel::pci_device_table!(
@@ -42,6 +42,8 @@ fn probe(pdev: &mut pci::Device, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>
             GFP_KERNEL,
         )?;
 
+        let _ = this.gpu.test_timer();
+
         Ok(this)
     }
 }
drivers/gpu/nova-core/gpu.rs +0 -0
index d96901e5c8eace1e7c57c77da7def209e8149cd3..f010d3152530b1cec032ca620e59de51a2fc1a13 100644

drivers/gpu/nova-core/gpu.rs line 13

Quoted 8 lines
drivers/gpu/nova-core/gpu.rs +2 -0
@@ -6,8 +6,10 @@
 
 use crate::driver::Bar0;
 use crate::regs;
+use crate::timer::Timer;
 use crate::util;
 use core::fmt;
+use core::time::Duration;
 

Since there is already a Delta type proposed to represent the timestamp difference in kernel:

	https://lore.kernel.org/rust-for-linux/[email protected]/

, could you please make your work based on that and avoid using core::time::Duration. Thanks!

Quoted 9 lines
drivers/gpu/nova-core/gpu.rs +1 -0
 macro_rules! define_chipset {
     ({ $($variant:ident = $value:expr),* $(,)* }) =>
@@ -179,6 +181,7 @@ pub(crate) struct Gpu {
     /// MMIO mapping of PCI BAR 0
     bar: Devres<Bar0>,
     fw: Firmware,
+    timer: Timer,
 }
 

[...]

drivers/gpu/nova-core/gpu.rs

Quoted 9 lines
drivers/gpu/nova-core/gpu.rs +9 -0
+
+/// A timestamp with nanosecond granularity obtained from the GPU timer.
+///
+/// A timestamp can also be substracted to another in order to obtain a [`Duration`].
+///
+/// TODO: add Kunit tests!
+#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
+pub(crate) struct Timestamp(u64);
+

Also an Instant type has been proposed and reviewed for a while:

	https://lore.kernel.org/rust-for-linux/[email protected]/

we should use that type instead of re-inventing the wheel here. Of course, it's currently not quite working because Instant is only for CLOCK_MONOTONIC. But there was a proposal to make Instant generic over clock:

	https://lore.kernel.org/rust-for-linux/[email protected]/

if you follow that design, you can implement a Instant<NovaGpu>, where

    ipml Now for NovaGpu {
        fn now() -> Instant<Self> {
	    // your Timer::read() implementation.
	}
    }

Thanks!

Regards,
Boqun

Quoted 47 lines
drivers/gpu/nova-core/gpu.rs +47 -0
+impl Display for Timestamp {
+    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(f, "{}", self.0)
+    }
+}
+
+impl Add<Duration> for Timestamp {
+    type Output = Self;
+
+    fn add(mut self, rhs: Duration) -> Self::Output {
+        let mut nanos = rhs.as_nanos();
+        while nanos > u64::MAX as u128 {
+            self.0 = self.0.wrapping_add(nanos as u64);
+            nanos -= u64::MAX as u128;
+        }
+
+        Timestamp(self.0.wrapping_add(nanos as u64))
+    }
+}
+
+impl Sub for Timestamp {
+    type Output = Duration;
+
+    fn sub(self, rhs: Self) -> Self::Output {
+        Duration::from_nanos(self.0.wrapping_sub(rhs.0))
+    }
+}
+
+pub(crate) struct Timer {}
+
+impl Timer {
+    pub(crate) fn new() -> Self {
+        Self {}
+    }
+
+    /// Read the current timer timestamp.
+    pub(crate) fn read(&self, bar: &Bar0) -> Timestamp {
+        loop {
+            let hi = regs::PtimerTime1::read(bar);
+            let lo = regs::PtimerTime0::read(bar);
+
+            if hi.hi() == regs::PtimerTime1::read(bar).hi() {
+                return Timestamp(u64::from_u32s(hi.hi(), lo.lo()));
+            }
+        }
+    }
+

[...]

author maintainer
#10 lore raw

Re: [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device

Hi Boqun,

Quoted 102 lines · Boqun Feng

Hi Alexandre,

Quoted 51 lines · Alexandre Courbot

Add a basic timer device and exercise it during device probing. This first draft is probably very questionable.

One point in particular which should IMHO receive attention: the generic wait_on() method aims at providing similar functionality to Nouveau's nvkm_[num]sec() macros. Since this method will be heavily used with different conditions to test, I'd like to avoid monomorphizing it entirely with each instance ; that's something that is achieved in nvkm_xsec() using functions that the macros invoke.

I have tried achieving the same result in Rust using closures (kept as-is in the current code), but they seem to be monomorphized as well. Calling extra functions could work better, but looks also less elegant to me, so I am really open to suggestions here.

---
 drivers/gpu/nova-core/driver.rs    |   4 +-
 drivers/gpu/nova-core/gpu.rs       |  55 +++++++++++++++-
 drivers/gpu/nova-core/nova_core.rs |   1 +
 drivers/gpu/nova-core/regs.rs      |  11 ++++
 drivers/gpu/nova-core/timer.rs     | 132 +++++++++++++++++++++++++++++++++++++
 5 files changed, 201 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/driver.rs +3 -1
index 63c19f140fbdd65d8fccf81669ac590807cc120f..0cd23aa306e4082405f480afc0530a41131485e7 100644
@@ -10,7 +10,7 @@ pub(crate) struct NovaCore {
     pub(crate) gpu: Gpu,
 }
 
-const BAR0_SIZE: usize = 8;
+const BAR0_SIZE: usize = 0x9500;
 pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
 
 kernel::pci_device_table!(
@@ -42,6 +42,8 @@ fn probe(pdev: &mut pci::Device, _info: &Self::IdInfo) -> Result<Pin<KBox<Self>>
             GFP_KERNEL,
         )?;
 
+        let _ = this.gpu.test_timer();
+
         Ok(this)
     }
 }
drivers/gpu/nova-core/gpu.rs +0 -0
index d96901e5c8eace1e7c57c77da7def209e8149cd3..f010d3152530b1cec032ca620e59de51a2fc1a13 100644

drivers/gpu/nova-core/gpu.rs line 13

Quoted 8 lines
drivers/gpu/nova-core/gpu.rs +2 -0
@@ -6,8 +6,10 @@
 
 use crate::driver::Bar0;
 use crate::regs;
+use crate::timer::Timer;
 use crate::util;
 use core::fmt;
+use core::time::Duration;
 

Since there is already a Delta type proposed to represent the timestamp difference in kernel:

	https://lore.kernel.org/rust-for-linux/[email protected]/

, could you please make your work based on that and avoid using core::time::Duration. Thanks!

Quoted 9 lines
drivers/gpu/nova-core/gpu.rs +1 -0
 macro_rules! define_chipset {
     ({ $($variant:ident = $value:expr),* $(,)* }) =>
@@ -179,6 +181,7 @@ pub(crate) struct Gpu {
     /// MMIO mapping of PCI BAR 0
     bar: Devres<Bar0>,
     fw: Firmware,
+    timer: Timer,
 }
 

[...]

drivers/gpu/nova-core/gpu.rs

Quoted 9 lines
drivers/gpu/nova-core/gpu.rs +9 -0
+
+/// A timestamp with nanosecond granularity obtained from the GPU timer.
+///
+/// A timestamp can also be substracted to another in order to obtain a [`Duration`].
+///
+/// TODO: add Kunit tests!
+#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
+pub(crate) struct Timestamp(u64);
+

Also an Instant type has been proposed and reviewed for a while:

	https://lore.kernel.org/rust-for-linux/[email protected]/

we should use that type instead of re-inventing the wheel here. Of course, it's currently not quite working because Instant is only for CLOCK_MONOTONIC. But there was a proposal to make Instant generic over clock:

	https://lore.kernel.org/rust-for-linux/[email protected]/
Quoted 7 lines

if you follow that design, you can implement a Instant<NovaGpu>, where

    ipml Now for NovaGpu {
        fn now() -> Instant<Self> {
	    // your Timer::read() implementation.
	}
    }

Ah, thanks for pointing this out. I'll keep track of these patches, hopefully they get merged soon!

#11 lore raw

Re: [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device

Quoted 16 lines · Alexandre Courbot

Hi Boqun,

Quoted 13 lines · Boqun Feng

Also an Instant type has been proposed and reviewed for a while:

	https://lore.kernel.org/rust-for-linux/[email protected]/

we should use that type instead of re-inventing the wheel here. Of course, it's currently not quite working because Instant is only for CLOCK_MONOTONIC. But there was a proposal to make Instant generic over clock:

	https://lore.kernel.org/rust-for-linux/[email protected]/

if you follow that design, you can implement a Instant<NovaGpu>, where

Quoted 8 lines
Quoted 5 lines
    ipml Now for NovaGpu {
        fn now() -> Instant<Self> {
	    // your Timer::read() implementation.
	}
    }

Ah, thanks for pointing this out. I'll keep track of these patches, hopefully they get merged soon!

Would that actually work though? Instant is a ktime_t, which is a signed i64 rather than a u64. When I read your patch I assumed that you had to add your own Timestamp because the value had to be whatever was read from the GPU, independent of the clock value kept by the system or other hardware.

db48x

author maintainer
#12 lore raw

Re: [PATCH RFC v3 6/7] gpu: nova-core: add basic timer device

Quoted 24 lines · Daniel Brooks
Quoted 22 lines · Alexandre Courbot

Hi Boqun,

Quoted 18 lines · Boqun Feng

Also an Instant type has been proposed and reviewed for a while:

	https://lore.kernel.org/rust-for-linux/[email protected]/

we should use that type instead of re-inventing the wheel here. Of course, it's currently not quite working because Instant is only for CLOCK_MONOTONIC. But there was a proposal to make Instant generic over clock:

	https://lore.kernel.org/rust-for-linux/[email protected]/

if you follow that design, you can implement a Instant<NovaGpu>, where

    ipml Now for NovaGpu {
        fn now() -> Instant<Self> {
	    // your Timer::read() implementation.
	}
    }
Quoted 8 lines
Quoted 2 lines

Ah, thanks for pointing this out. I'll keep track of these patches, hopefully they get merged soon!

Would that actually work though? Instant is a ktime_t, which is a signed i64 rather than a u64. When I read your patch I assumed that you had to add your own Timestamp because the value had to be whatever was read from the GPU, independent of the clock value kept by the system or other hardware.

That's correct, and honestly there would be little benefit in using an already existing type outside of not re-writing very similar code as GPU time stamps are only used locally anyway. I'll keep an eye on these patches though in case we can harmonize things a bit.

author maintainer
#13 lore raw

RFC PATCH v3 7/7 gpu: nova-core: add falcon register definitions and probe code

In reply to Alexandre Courbot

This is still very preliminary work, and is mostly designed to show how register fields can be turned into safe types that force us to handle invalid values.

---
 drivers/gpu/nova-core/driver.rs    |   2 +-
 drivers/gpu/nova-core/falcon.rs    | 618 +++++++++++++++++++++++++++++++++++++
 drivers/gpu/nova-core/gpu.rs       |  13 +
 drivers/gpu/nova-core/nova_core.rs |   1 +
 drivers/gpu/nova-core/regs.rs      | 188 ++++++++++-
 5 files changed, 820 insertions(+), 2 deletions(-)
drivers/gpu/nova-core/driver.rs +1 -1
index 0cd23aa306e4082405f480afc0530a41131485e7..dee5fd22eecb2ce1f4ea765338b0c1b68853b2d3 100644
@@ -10,7 +10,7 @@ pub(crate) struct NovaCore {
     pub(crate) gpu: Gpu,
 }
 
-const BAR0_SIZE: usize = 0x9500;
+const BAR0_SIZE: usize = 0x1000000;
 pub(crate) type Bar0 = pci::Bar<BAR0_SIZE>;
 
 kernel::pci_device_table!(
drivers/gpu/nova-core/falcon.rs new file +618 -0

618 lines not on this page · raw message

drivers/gpu/nova-core/gpu.rs +13 -0
index f010d3152530b1cec032ca620e59de51a2fc1a13..ec745dd8175bd3164ed1b865293a526b09c59ab3 100644
@@ -5,6 +5,7 @@
 };
 
 use crate::driver::Bar0;
+use crate::falcon::{GspFalcon, Sec2Falcon};
 use crate::regs;
 use crate::timer::Timer;
 use crate::util;
@@ -198,6 +199,18 @@ pub(crate) fn new(pdev: &pci::Device, bar: Devres<Bar0>) -> Result<impl PinInit<
         );
 
         let timer = Timer::new();
+        let _gsp_falcon = GspFalcon::new(
+            pdev,
+            spec.chipset,
+            &bar,
+            if spec.chipset > Chipset::GA100 {
+                true
+            } else {
+                false
+            },
+        )?;
+
+        let _sec2_falcon = Sec2Falcon::new(pdev, spec.chipset, &bar, false)?;
 
         Ok(pin_init!(Self {
             spec,
drivers/gpu/nova-core/nova_core.rs +1 -0
index f54dcfc66490cb6b10090ef944ac14feca9f6972..35c030485532633a5dd59a8a4a1f6d385cb46c98 100644
@@ -15,6 +15,7 @@ macro_rules! with_bar {
 }
 
 mod driver;
+mod falcon;
 mod firmware;
 mod gpu;
 mod regs;
drivers/gpu/nova-core/regs.rs +187 -1

198 lines not on this page · raw message

Signature · 1 line
2.48.1