mirror of
https://github.com/torvalds/linux.git
synced 2026-07-27 17:47:41 +02:00
gpu: nova-core: vbios: read PMU lookup entries using FromBytes
This simplifies the construction of `PmuLookupTableEntry` and is allowed now that the driver can assume it is little endian. Reviewed-by: John Hubbard <jhubbard@nvidia.com> Signed-off-by: Eliot Courtney <ecourtney@nvidia.com> Link: https://patch.msgid.link/20260525-fix-vbios-v5-12-e5e455251537@nvidia.com Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
parent
99e110a368
commit
c22095fdda
|
|
@ -897,19 +897,8 @@ struct PmuLookupTableEntry {
|
|||
data: u32,
|
||||
}
|
||||
|
||||
impl PmuLookupTableEntry {
|
||||
fn new(data: &[u8]) -> Result<Self> {
|
||||
if data.len() < core::mem::size_of::<Self>() {
|
||||
return Err(EINVAL);
|
||||
}
|
||||
|
||||
Ok(PmuLookupTableEntry {
|
||||
application_id: data[0],
|
||||
target_id: data[1],
|
||||
data: u32::from_le_bytes(data[2..6].try_into().map_err(|_| EINVAL)?),
|
||||
})
|
||||
}
|
||||
}
|
||||
// SAFETY: all bit patterns are valid for `PmuLookupTableEntry`.
|
||||
unsafe impl FromBytes for PmuLookupTableEntry {}
|
||||
|
||||
#[repr(C)]
|
||||
struct PmuLookupTableHeader {
|
||||
|
|
@ -963,7 +952,13 @@ fn lookup_index(&self, idx: u8) -> Result<PmuLookupTableEntry> {
|
|||
}
|
||||
|
||||
let index = (usize::from(idx)) * usize::from(self.header.entry_len);
|
||||
PmuLookupTableEntry::new(&self.table_data[index..])
|
||||
let (entry, _) = self
|
||||
.table_data
|
||||
.get(index..)
|
||||
.and_then(PmuLookupTableEntry::from_bytes_copy_prefix)
|
||||
.ok_or(EINVAL)?;
|
||||
|
||||
Ok(entry)
|
||||
}
|
||||
|
||||
// find entry by type value
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user