From: Rhys Lloyd <krakow20@gmail.com>
To: acourbot@nvidia.com, dakr@kernel.org
Cc: Rhys Lloyd <krakow20@gmail.com>,
rust-for-linux@vger.kernel.org, airlied@gmail.com,
simona@ffwll.ch, nouveau@lists.freedesktop.org,
dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH] gpu: nova-core: vbios: split out PmuLookupTableHeader from PmuLookupTable
Date: Mon, 14 Jul 2025 03:43:13 -0700 [thread overview]
Message-ID: <20250714104322.100511-2-krakow20@gmail.com> (raw)
In-Reply-To: <20250714104322.100511-1-krakow20@gmail.com>
Separating the header allows the use of `size_of::<PmuLookupTableHeader>()`
instead of the magic number 4.
Signed-off-by: Rhys Lloyd <krakow20@gmail.com>
---
drivers/gpu/nova-core/vbios.rs | 56 +++++++++++++++++++++-------------
1 file changed, 35 insertions(+), 21 deletions(-)
diff --git a/drivers/gpu/nova-core/vbios.rs b/drivers/gpu/nova-core/vbios.rs
index 663fc50e8b66..20011c5c9bbc 100644
--- a/drivers/gpu/nova-core/vbios.rs
+++ b/drivers/gpu/nova-core/vbios.rs
@@ -889,6 +889,32 @@ fn try_from(base: BiosImageBase) -> Result<Self> {
}
}
+/// The [`PmuLookupTableHeader`] structure is header information for [`PmuLookupTable`].
+///
+/// See the [`PmuLookupTable`] description for more information.
+#[expect(dead_code)]
+struct PmuLookupTableHeader {
+ version: u8,
+ header_len: u8,
+ entry_len: u8,
+ entry_count: u8,
+}
+
+impl PmuLookupTableHeader {
+ fn new(data: &[u8]) -> Result<Self> {
+ if data.len() < core::mem::size_of::<Self>() {
+ return Err(EINVAL);
+ }
+
+ Ok(PmuLookupTableHeader {
+ version: data[0],
+ header_len: data[1],
+ entry_len: data[2],
+ entry_count: data[3],
+ })
+ }
+}
+
/// The [`PmuLookupTableEntry`] structure is a single entry in the [`PmuLookupTable`].
///
/// See the [`PmuLookupTable`] description for more information.
@@ -918,24 +944,18 @@ fn new(data: &[u8]) -> Result<Self> {
///
/// The table of entries is pointed to by the falcon data pointer in the BIT table, and is used to
/// locate the Falcon Ucode.
-#[expect(dead_code)]
struct PmuLookupTable {
- version: u8,
- header_len: u8,
- entry_len: u8,
- entry_count: u8,
+ header: PmuLookupTableHeader,
table_data: KVec<u8>,
}
impl PmuLookupTable {
fn new(pdev: &pci::Device, data: &[u8]) -> Result<Self> {
- if data.len() < 4 {
- return Err(EINVAL);
- }
+ let header = PmuLookupTableHeader::new(data)?;
- let header_len = data[1] as usize;
- let entry_len = data[2] as usize;
- let entry_count = data[3] as usize;
+ let header_len = header.header_len as usize;
+ let entry_len = header.entry_len as usize;
+ let entry_count = header.entry_count as usize;
let required_bytes = header_len + (entry_count * entry_len);
@@ -963,27 +983,21 @@ fn new(pdev: &pci::Device, data: &[u8]) -> Result<Self> {
);
}
- Ok(PmuLookupTable {
- version: data[0],
- header_len: header_len as u8,
- entry_len: entry_len as u8,
- entry_count: entry_count as u8,
- table_data,
- })
+ Ok(PmuLookupTable { header, table_data })
}
fn lookup_index(&self, idx: u8) -> Result<PmuLookupTableEntry> {
- if idx >= self.entry_count {
+ if idx >= self.header.entry_count {
return Err(EINVAL);
}
- let index = (idx as usize) * self.entry_len as usize;
+ let index = (idx as usize) * self.header.entry_len as usize;
PmuLookupTableEntry::new(&self.table_data[index..])
}
// find entry by type value
fn find_entry_by_type(&self, entry_type: u8) -> Result<PmuLookupTableEntry> {
- for i in 0..self.entry_count {
+ for i in 0..self.header.entry_count {
let entry = self.lookup_index(i)?;
if entry.application_id == entry_type {
return Ok(entry);
base-commit: 215a3f91713383a3c0d2da82d223a608a3c17ac1
--
2.50.1
next prev parent reply other threads:[~2025-12-13 12:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-14 10:43 [PATCH] gpu: nova-core: vbios: change PmuLookupTableEntry to relax alignment Rhys Lloyd
2025-07-14 10:43 ` Rhys Lloyd [this message]
2025-07-16 1:40 ` [PATCH] gpu: nova-core: vbios: split out PmuLookupTableHeader from PmuLookupTable Alexandre Courbot
2025-07-14 10:43 ` [PATCH] gpu: nova-core: vbios: use size_of instead of magic number Rhys Lloyd
2025-07-16 1:43 ` Alexandre Courbot
2025-07-14 10:51 ` [PATCH] gpu: nova-core: vbios: change PmuLookupTableEntry to relax alignment Benno Lossin
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=20250714104322.100511-2-krakow20@gmail.com \
--to=krakow20@gmail.com \
--cc=acourbot@nvidia.com \
--cc=airlied@gmail.com \
--cc=dakr@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=simona@ffwll.ch \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.