]> Gentwo Git Trees - linux/.git/commitdiff
gpu: nova-core: prepare Spec and Revision types for boot0/boot42
authorJohn Hubbard <jhubbard@nvidia.com>
Sat, 15 Nov 2025 01:09:19 +0000 (17:09 -0800)
committerAlexandre Courbot <acourbot@nvidia.com>
Sat, 15 Nov 2025 13:57:37 +0000 (22:57 +0900)
Allow a both Revision and Spec to be constructed directly from a
NV_PMC_BOOT_0 register.

Also, slightly enhance the comment about Spec, to be more precise.

Cc: Alexandre Courbot <acourbot@nvidia.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: Timur Tabi <ttabi@nvidia.com>
Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Message-ID: <20251115010923.1192144-2-jhubbard@nvidia.com>

drivers/gpu/nova-core/gpu.rs

index dfeba9d5d8f634aa0fb76761e8ae70681791cb0d..57c20d1e72746924859c3260040377b8aa4f59dc 100644 (file)
@@ -147,8 +147,8 @@ pub(crate) struct Revision {
     minor: u8,
 }
 
-impl Revision {
-    fn from_boot0(boot0: regs::NV_PMC_BOOT_0) -> Self {
+impl From<regs::NV_PMC_BOOT_0> for Revision {
+    fn from(boot0: regs::NV_PMC_BOOT_0) -> Self {
         Self {
             major: boot0.major_revision(),
             minor: boot0.minor_revision(),
@@ -162,10 +162,9 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     }
 }
 
-/// Structure holding the metadata of the GPU.
+/// Structure holding a basic description of the GPU: `Chipset` and `Revision`.
 pub(crate) struct Spec {
     chipset: Chipset,
-    /// The revision of the chipset.
     revision: Revision,
 }
 
@@ -173,9 +172,17 @@ impl Spec {
     fn new(bar: &Bar0) -> Result<Spec> {
         let boot0 = regs::NV_PMC_BOOT_0::read(bar);
 
+        Spec::try_from(boot0)
+    }
+}
+
+impl TryFrom<regs::NV_PMC_BOOT_0> for Spec {
+    type Error = Error;
+
+    fn try_from(boot0: regs::NV_PMC_BOOT_0) -> Result<Self> {
         Ok(Self {
             chipset: boot0.chipset()?,
-            revision: Revision::from_boot0(boot0),
+            revision: boot0.into(),
         })
     }
 }