In order to remove `FalconDmaLoadTarget`, remove usages of it in `FwsecFirmwareWithBl` and `BootloaderDmemDescV2`. `FalconDmaLoadTarget` ends up non-orthogonal with `FalconImage`, `FalconImemSegment`, `FalconDmemSegment` which are added in a following change. These three new types take over the job of denoting where code/data uploaded to a falcon is stored and where it is sent to. This is part of making the locations of where the falcon data/code is represented separate from how it is sent to the falcon. `FalconDmaLoadTarget` conflates those two things.
Signed-off-by: Eliot Courtney <[email protected]> --- drivers/gpu/nova-core/firmware/fwsec/bootloader.rs | 49 +++++++--------------- drivers/gpu/nova-core/firmware/gen_bootloader.rs | 42 ++++++++++--------- 2 files changed, 38 insertions(+), 53 deletions(-) diff --git a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs index 461e5e6f7899..1efcf7a8624d 100644 --- a/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs +++ b/drivers/gpu/nova-core/firmware/fwsec/bootloader.rs @@ -19,7 +19,6 @@ falcon::{ gsp::Gsp, Falcon, - FalconDmaLoadable, FalconFbifTarget, // }, firmware::{ @@ -28,6 +27,7 @@ BootloaderDmemDescV2, GenericBootloader, // }, + FalconUCodeDesc, // }, gpu::Chipset, num::FromSafeCast, // @@ -52,61 +52,44 @@ pub(crate) fn new( dev: &'a Device<device::Bound>, chipset: Chipset, ) -> Result<Self> { + let desc = match &firmware.desc { + FalconUCodeDesc::V2(desc) => desc, + FalconUCodeDesc::V3(_) => return Err(EINVAL), + }; + let bootloader = GenericBootloader::new(dev, chipset)?; // `BootloaderDmemDescV2` expects the source to be a mirror image of the destination and // uses the same offset parameter for both. // - // Thus, the start of the source object needs to be padded with the difference between the - // destination and source offsets. + // Thus, the start of the source object needs to be padded with `imem_phys_base`, the IMEM + // offset at which the code is loaded. // // In practice, this is expected to always be zero but is required for code correctness. - let (align_padding, firmware_dma) = { - let align_padding = { - let imem_sec = firmware.imem_sec_load_params(); - - imem_sec - .dst_start - .checked_sub(imem_sec.src_start) - .map(usize::from_safe_cast) - .ok_or(EOVERFLOW)? - }; + let align_padding = usize::from_safe_cast(desc.imem_phys_base); + let firmware_dma = { let mut firmware_obj = KVVec::zeroed(align_padding, GFP_KERNEL)?; firmware_obj.extend_from_slice(firmware.ucode.0.as_slice(), GFP_KERNEL)?; - ( - align_padding, - Coherent::from_slice(dev, firmware_obj.as_slice(), GFP_KERNEL)?, - ) + Coherent::from_slice(dev, firmware_obj.as_slice(), GFP_KERNEL)? }; let dmem_desc = { - let imem_sec = firmware.imem_sec_load_params(); - let imem_ns = firmware.imem_ns_load_params().ok_or(EINVAL)?; - let dmem = firmware.dmem_load_params(); - // The bootloader does not have a data destination offset field and copies the data at - // the start of DMEM, so it can only be used if the destination offset of the firmware - // is 0. - if dmem.dst_start != 0 { + // the start of DMEM, so it can only be used if `dmem_phys_base` is 0. + if desc.dmem_phys_base != 0 { return Err(EINVAL); } - // Start of data section is the added padding + the DMEM `src_start` field. + // Start of data section is the added padding + the `dmem_offset` field. let data_dma_base = firmware_dma .dma_address() .checked_add(u64::from_safe_cast(align_padding)) - .and_then(|offset| offset.checked_add(dmem.src_start.into())) + .and_then(|offset| offset.checked_add(desc.dmem_offset.into())) .ok_or(EOVERFLOW)?; - BootloaderDmemDescV2::new( - &imem_ns, - &imem_sec, - &dmem, - firmware_dma.dma_address(), - data_dma_base, - ) + BootloaderDmemDescV2::new(desc, firmware_dma.dma_address(), data_dma_base) }; Ok(Self { diff --git a/drivers/gpu/nova-core/firmware/gen_bootloader.rs b/drivers/gpu/nova-core/firmware/gen_bootloader.rs index cfc1b99c015c..5dea98220e9d 100644 --- a/drivers/gpu/nova-core/firmware/gen_bootloader.rs +++ b/drivers/gpu/nova-core/firmware/gen_bootloader.rs @@ -22,7 +22,6 @@ gsp::Gsp, Falcon, FalconBromParams, - FalconDmaLoadTarget, FalconFbifMemType, FalconFbifTarget, FalconFirmware, @@ -30,9 +29,12 @@ FalconPioImemLoadTarget, FalconPioLoadable, // }, - firmware::tlv::{ - request_tlv, // - Tlv, + firmware::{ + tlv::{ + request_tlv, // + Tlv, + }, + FalconUCodeDescV2, // }, gpu::Chipset, num::FromSafeCast, // @@ -91,29 +93,29 @@ impl BootloaderDmemDescV2 { /// Creates the descriptor of an image whose code is at `code_dma_base` and whose data is at /// `data_dma_base`. /// - /// `imem_ns` and `imem_sec` locate the non-secure and secure code in the image, and `dmem` - /// gives the size of its data. The code DMA object must be a mirror image of the target IMEM - /// layout, because the bootloader uses the destination offset of each code segment as its - /// source offset too. - pub(crate) fn new( - imem_ns: &FalconDmaLoadTarget, - imem_sec: &FalconDmaLoadTarget, - dmem: &FalconDmaLoadTarget, - code_dma_base: u64, - data_dma_base: u64, - ) -> Self { + /// The code DMA object must be a mirror image of the target IMEM layout, because the + /// bootloader uses the destination offset of each code segment as its source offset too. + pub(super) fn new(desc: &FalconUCodeDescV2, code_dma_base: u64, data_dma_base: u64) -> Self { + // `imem_sec_base` is the *virtual* start address of the secure IMEM segment, so subtract + // `imem_virt_base` to get its physical offset. + let imem_sec_start = desc.imem_sec_base.saturating_sub(desc.imem_virt_base); + Self { reserved: [0; 4], signature: [0; 4], ctx_dma: Self::FALCON_DMAIDX_PHYS_SYS_NCOH, code_dma_base, - non_sec_code_off: imem_ns.dst_start, - non_sec_code_size: imem_ns.len, - sec_code_off: imem_sec.dst_start, - sec_code_size: imem_sec.len, + // Non-secure code always starts at offset 0 of the image, so it is loaded at + // `imem_phys_base`. + non_sec_code_off: desc.imem_phys_base, + // `imem_load_size` includes the size of the secure segment, so subtract it to + // get the correct amount of data to copy. + non_sec_code_size: desc.imem_load_size.saturating_sub(desc.imem_sec_size), + sec_code_off: desc.imem_phys_base.saturating_add(imem_sec_start), + sec_code_size: desc.imem_sec_size, code_entry_point: 0, data_dma_base, - data_size: dmem.len, + data_size: desc.dmem_load_size, argc: 0, argv: 0, } -- 2.56.1
