NVIDIA GPU driver infrastructure
 help / color / mirror / Atom feed
From: Timur Tabi <ttabi@nvidia.com>
To: Danilo Krummrich <dakr@kernel.org>,
	Alexandre Courbot <acourbot@nvidia.com>,
	John Hubbard <jhubbard@nvidia.com>,
	Eliot Courtney <ecourtney@nvidia.com>, <nova-gpu@lists.linux.dev>
Subject: [PATCH 1/5] gpu: nova-core: add Tlv.get_u64
Date: Tue, 10 Nov 2026 17:10:49 -0600	[thread overview]
Message-ID: <20261110231053.1352163-2-ttabi@nvidia.com> (raw)
In-Reply-To: <20261110231053.1352163-1-ttabi@nvidia.com>

Introduce get_u64() to support variable-sized TLV integers.  If the driver
expects that a particular tag might be a 64-bit value, it should use this
method read it.

TLVs can store unsigned integers in either 32-bit or 64-bit little-endian
format.  The script that generates TLV files is written in Python, and
Python integers are arbitrarily sized.  For any given integer, the script
will store it as a 32-bit integer if its value is less than 0x100000000,
without any regard to its purpose.  This means that the driver may not
know until runtime whether a given TLV integer is encoded as four bytes
or eight.

Signed-off-by: Timur Tabi <ttabi@nvidia.com>
---
 drivers/gpu/nova-core/firmware/tlv.rs | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/drivers/gpu/nova-core/firmware/tlv.rs b/drivers/gpu/nova-core/firmware/tlv.rs
index 7f278903dc8b..75d8f907421b 100644
--- a/drivers/gpu/nova-core/firmware/tlv.rs
+++ b/drivers/gpu/nova-core/firmware/tlv.rs
@@ -257,6 +257,23 @@ pub(crate) fn load_file(
             .ok_or(EINVAL)
     }
 
+    /// Return a u64, from either a 32-bit or 64-bit little-endian tag.
+    #[expect(unused)]
+    pub(crate) fn get_u64(&self, tag: &[u8; 4]) -> Result<u64> {
+        let value = self.get_bytes(tag)?;
+
+        match value.len() {
+            // `value` is an unsized slice, but from_le_bytes() requires a sized
+            // slice (&[u8; N]), so we need to convert.
+            4 => value
+                .first_chunk()
+                .map(|&b| u64::from(u32::from_le_bytes(b))),
+            8 => value.first_chunk().map(|&b| u64::from_le_bytes(b)),
+            _ => None,
+        }
+        .ok_or(EINVAL)
+    }
+
     /// Return a string value.
     pub(crate) fn get_string(&self, tag: &[u8; 4]) -> Result<&'a str> {
         let tlv = self.find(tag)?;
-- 
2.54.0


  reply	other threads:[~2026-11-10 23:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 23:10 [PATCH 0/5] Transition nova-core to use TLV variables for heap sizes Timur Tabi
2026-11-10 23:10 ` Timur Tabi [this message]
2026-11-11  0:20   ` [PATCH 1/5] gpu: nova-core: add Tlv.get_u64 John Hubbard
2026-11-11  2:59     ` Timur Tabi
2026-11-11  3:45       ` John Hubbard
2026-11-11  5:21         ` Eliot Courtney
2026-11-11  5:27   ` Eliot Courtney
2026-11-10 23:10 ` [PATCH 2/5] gpu: nova-core: merge LibosParams into GspFwHeapParams Timur Tabi
2026-11-11  6:30   ` Eliot Courtney
2026-11-10 23:10 ` [PATCH 3/5] gpu: nova-core: read GSP heap variables from TLV Timur Tabi
2026-11-10 23:10 ` [PATCH 4/5] gpu: nova-core: use the TLV heap sizes Timur Tabi
2026-11-10 23:10 ` [PATCH 5/5] gpu: nova-core: remove heap size related HAL functions Timur Tabi
2026-11-10 23:21 ` [PATCH 0/5] Transition nova-core to use TLV variables for heap sizes Timur Tabi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261110231053.1352163-2-ttabi@nvidia.com \
    --to=ttabi@nvidia.com \
    --cc=acourbot@nvidia.com \
    --cc=dakr@kernel.org \
    --cc=ecourtney@nvidia.com \
    --cc=jhubbard@nvidia.com \
    --cc=nova-gpu@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox