Skip to content

Commit f598c25

Browse files
Gnurougregkh
authored andcommitted
gpu: nova-core: firmware: fix and explain v2 header offsets computations
[ Upstream commit 17d7c97 ] There are no offsets in `FalconUCodeDescV2` to give the non-secure and secure IMEM sections start offsets relative to the beginning of the firmware object. The start offsets for both sections were set to `0`, but that is obviously incorrect since two different sections cannot start at the same offset. Since these offsets were not used by the bootloader, this doesn't prevent proper function but is incorrect nonetheless. Fix this by computing the start of the secure IMEM section relatively to the start of the firmware object and setting it properly. Also add and improve comments to explain how the values are obtained. Fixes: dbfb5aa ("gpu: nova-core: add FalconUCodeDescV2 support") Reviewed-by: Eliot Courtney <ecourtney@nvidia.com> Link: https://patch.msgid.link/20260306-turing_prep-v11-9-8f0042c5d026@nvidia.com Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent a8efb5d commit f598c25

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

drivers/gpu/nova-core/firmware.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ pub(crate) struct FalconUCodeDescV2 {
6363
pub(crate) interface_offset: u32,
6464
/// Base address at which to load the code segment into 'IMEM'.
6565
pub(crate) imem_phys_base: u32,
66-
/// Size in bytes of the code to copy into 'IMEM'.
66+
/// Size in bytes of the code to copy into 'IMEM' (includes both secure and non-secure
67+
/// segments).
6768
pub(crate) imem_load_size: u32,
6869
/// Virtual 'IMEM' address (i.e. 'tag') at which the code should start.
6970
pub(crate) imem_virt_base: u32,
@@ -205,18 +206,25 @@ impl FalconUCodeDescriptor for FalconUCodeDescV2 {
205206
}
206207

207208
fn imem_sec_load_params(&self) -> FalconDmaLoadTarget {
209+
// `imem_sec_base` is the *virtual* start address of the secure IMEM segment, so subtract
210+
// `imem_virt_base` to get its physical offset.
211+
let imem_sec_start = self.imem_sec_base.saturating_sub(self.imem_virt_base);
212+
208213
FalconDmaLoadTarget {
209-
src_start: 0,
210-
dst_start: self.imem_sec_base,
214+
src_start: imem_sec_start,
215+
dst_start: self.imem_phys_base.saturating_add(imem_sec_start),
211216
len: self.imem_sec_size,
212217
}
213218
}
214219

215220
fn imem_ns_load_params(&self) -> Option<FalconDmaLoadTarget> {
216221
Some(FalconDmaLoadTarget {
222+
// Non-secure code always starts at offset 0.
217223
src_start: 0,
218224
dst_start: self.imem_phys_base,
219-
len: self.imem_load_size.checked_sub(self.imem_sec_size)?,
225+
// `imem_load_size` includes the size of the secure segment, so subtract it to
226+
// get the correct amount of data to copy.
227+
len: self.imem_load_size.saturating_sub(self.imem_sec_size),
220228
})
221229
}
222230

0 commit comments

Comments
 (0)