Transition nova-core to use TLV variables for heap sizes
Subsystems (4)
v3 cover Transition nova-core to use TLV variables for heap sizes
Starting with r615, the GSP-RM firmware TLVs (i.e. gsp.tlv) contain an an additional six variables that that should be used to calculate the various heap sizes that GSP-RM needs in order to boot.
These values are specific to each GPU and RM version, and are obtained by scraping them from the OpenRM source tree.
Note that although this patch set is necessary to support r620 and later, there are other, unrelated changes necessary to complete that support.
This patch set is based on Alex's r000_rebase_all branch:
https://github.com/Gnurou/linux/tree/r000_rebase_all
v3:
- various minor fixes from Elliot's review
- added #[allow(dead_code)] to for rust 1.85 compatibility
Timur Tabi (7):
gpu: nova-core: add Tlv.get_u64
gpu: nova-core: read GSP heap variables from TLV
gpu: nova-core: use the TLV heap sizes for pmu and non-wpr
gpu: nova-core: remove heap size related HAL functions
gpu: nova-core: add TLV versions of WPR heap size functions
gpu: nova-core: change wpr2_heap_params to use TLV values
gpu: nova-core: remove LibosParams
drivers/gpu/nova-core/fb.rs | 40 +++++--- drivers/gpu/nova-core/fb/hal.rs | 6 -- drivers/gpu/nova-core/fb/hal/ga100.rs | 8 -- drivers/gpu/nova-core/fb/hal/ga102.rs | 8 -- drivers/gpu/nova-core/fb/hal/gb100.rs | 41 +------- drivers/gpu/nova-core/fb/hal/gb202.rs | 13 +-- drivers/gpu/nova-core/fb/hal/gh100.rs | 12 +-- drivers/gpu/nova-core/fb/hal/tu102.rs | 16 --- drivers/gpu/nova-core/firmware/gsp.rs | 8 +- drivers/gpu/nova-core/firmware/tlv.rs | 13 +++ drivers/gpu/nova-core/gsp.rs | 4 +- drivers/gpu/nova-core/gsp/fw.rs | 130 ++++++++----------------- drivers/gpu/nova-core/gsp/hal/gh100.rs | 2 +- 13 files changed, 93 insertions(+), 208 deletions(-)
Signature · 1 line
2.54.0
PATCH v3 1/7 gpu: nova-core: add Tlv.get_u64
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.
--- drivers/gpu/nova-core/firmware/tlv.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
drivers/gpu/nova-core/firmware/tlv.rs +14 -0
@@ -257,6 +257,20 @@ 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.find (tag)?.value; + +if let Ok (bytes) = <[u8 ;4 ]>::try_from (value) { +Ok (u64::from (u32::from_le_bytes (bytes))) + }else if let Ok (bytes) = <[u8 ;8 ]>::try_from (value) { +Ok (u64::from_le_bytes (bytes)) + }else { +Err (EINVAL ) + } + } +/// Return a string value. pub (crate )fn get_string (&self, tag: &[u8 ;4 ]) ->Result <&'astr > {let tlv = self.find (tag)?;
Signature · 1 line
2.54.0
PATCH v3 2/7 gpu: nova-core: read GSP heap variables from TLV
In reply to Timur TabiUpdate Nova-core to read and store the new heap size variables from gsp.tlv in a GspFwHeapParams struct, which is changed from an enum. Also provide a constructor (currently unused) to create a GspFwHeapParams object from the TLV.
GSP-RM firmware TLVs (specifically gsp.tlv) that are based on r615 and later contain an additional six variables that contain values used to specify various heap sizes that GSP-RM needs in order to boot. These values are specific to each GPU and RM version, and are obtained by scraping them from the OpenRM source tree, just like every other TLV variable.
--- drivers/gpu/nova-core/firmware/tlv.rs | 1 - drivers/gpu/nova-core/gsp/fw.rs | 33 ++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/firmware/tlv.rs +0 -1
@@ -258,7 +258,6 @@ pub(crate) fn load_file( }/// 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.find (tag)?.value;
drivers/gpu/nova-core/gsp/fw.rs +30 -3
@@ -37,7 +37,8 @@ }, firmware::{ bindata::UcodesImage, - gsp::GspFirmware, // + gsp::GspFirmware, + tlv::Tlv, // }, gpu::{Architecture ,
@@ -65,8 +66,21 @@/// build-time constant, so the driver chooses it, and this constant is the one copy. pub (crate )const GSP_MSG_QUEUE_ELEMENT_SIZE_MAX :usize =GSP_PAGE_SIZE *16 ; -/// Empty type to group methods related to heap parameters for running the GSP firmware. -enum GspFwHeapParams {} +/// Heap memory requirements and constraints for booting GSP-RM. +pub (crate )struct GspFwHeapParams { +#[expect(unused)] + tlv_gsp_fw_heap_base_size:u64 , +#[expect(unused)] + tlv_gsp_hw_heap_size_per_gb:u64 , +#[expect(unused)] + tlv_gsp_fw_heap_base_size_vgpu:u64 , +#[expect(unused)] + tlv_gsp_fw_heap_size_per_vm:u64 , +#[expect(unused)] + tlv_pmu_reserved_size:u32 , +#[expect(unused)] + tlv_non_wpr_heap_size:u64 , +}/// Minimum required alignment for the GSP heap. const GSP_HEAP_ALIGNMENT :Alignment =Alignment ::new ::<{1 <<20 }>();
@@ -85,6 +99,19 @@ fn base_rm_size(chipset: Chipset) -> u64 { } } +/// Returns the heap parameters from the TLV +#[expect(unused)] +pub (crate )fn from_tlv (tlv: &Tlv <'_>) ->Result <Self > { +Ok (Self { + tlv_gsp_fw_heap_base_size: tlv.get_u64 (b"HBSZ" )?, + tlv_gsp_hw_heap_size_per_gb: tlv.get_u64 (b"HSPG" )?, + tlv_gsp_fw_heap_base_size_vgpu: tlv.get_u64 (b"HBSV" )?, + tlv_gsp_fw_heap_size_per_vm: tlv.get_u64 (b"HSPV" )?, + tlv_pmu_reserved_size: tlv.get_u32 (b"PRSZ" )?, + tlv_non_wpr_heap_size: tlv.get_u64 (b"GNWH" )?, + }) + } +/// Returns the amount of heap memory required to support a single channel allocation. fn client_alloc_size () ->u64 { u64::from (bindings::GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE )
Signature · 1 line
2.54.0
Re: [PATCH v3 2/7] gpu: nova-core: read GSP heap variables from TLV
Quoted 56 lines · Timur Tabi
Update Nova-core to read and store the new heap size variables from gsp.tlv in a GspFwHeapParams struct, which is changed from an enum. Also provide a constructor (currently unused) to create a GspFwHeapParams object from the TLV.
GSP-RM firmware TLVs (specifically gsp.tlv) that are based on r615 and later contain an additional six variables that contain values used to specify various heap sizes that GSP-RM needs in order to boot. These values are specific to each GPU and RM version, and are obtained by scraping them from the OpenRM source tree, just like every other TLV variable.
Signed-off-by Timur Tabi <[email protected]>Reviewed-by Eliot Courtney <[email protected]>--- drivers/gpu/nova-core/firmware/tlv.rs | 1 - drivers/gpu/nova-core/gsp/fw.rs | 33 ++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-)drivers/gpu/nova-core/firmware/tlv.rs +0
-1@@ -258,7 +258,6 @@ pub(crate) fn load_file( }/// 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.find (tag)?.value;drivers/gpu/nova-core/gsp/fw.rs +7
-3@@ -37,7 +37,8 @@ }, firmware::{ bindata::UcodesImage, - gsp::GspFirmware, // + gsp::GspFirmware, + tlv::Tlv, // }, gpu::{Architecture ,@@ -65,8 +66,21 @@/// build-time constant, so the driver chooses it, and this constant is the one copy. pub (crate )const GSP_MSG_QUEUE_ELEMENT_SIZE_MAX :usize =GSP_PAGE_SIZE *16 ; -/// Empty type to group methods related to heap parameters for running the GSP firmware. -enum GspFwHeapParams {} +/// Heap memory requirements and constraints for booting GSP-RM. +pub (crate )struct GspFwHeapParams { +#[expect(unused)] + tlv_gsp_fw_heap_base_size:u64 , + #[expect(unused)]
drivers/gpu/nova-core/gsp/fw.rs line 83
Quoted 10 lines
drivers/gpu/nova-core/gsp/fw.rs +10
-0+ tlv_gsp_hw_heap_size_per_gb: u64, +#[expect(unused)] + tlv_gsp_fw_heap_base_size_vgpu: u64, +#[expect(unused)] + tlv_gsp_fw_heap_size_per_vm: u64, +#[expect(unused)] + tlv_pmu_reserved_size: u32, +#[expect(unused)] + tlv_non_wpr_heap_size: u64, +}
I would still drop the tlv_ and tlv_gsp_ prefixes here and go with what I suggested on the last series:
``` wpr2_heap_base_size wpr2_heap_size_per_gib vgpu_wpr2_heap_base_size vgpu_wpr2_heap_size_per_vf pmu_reserved_size non_wpr_heap_size ```
I don't think it matters to the code that uses this to notate each variable with where it came from (conceptually, these could come from somewhere other than TLV and still be used), plus the from_tlv function already shows where they come from. So I don't see the utility in coupling the provenance with the semantic meaning of the vars here.
w.r.t. naming, like you said, maybe later we store some calculated value here, plus e.g. pmu_reserved_size is already not heap related afaict, so a better name for the struct might be e.g. GspFbParams.
PATCH v3 3/7 gpu: nova-core: use the TLV heap sizes for pmu and non-wpr
In reply to Timur TabiInstead of using hard-coded per-GPU values for the Non-WPR heap size and the PMU reserved size, use the values from gsp.tlv instead.
This change will allow us to remove those HAL functions from FbHal.
--- drivers/gpu/nova-core/fb.rs | 21 +++++++++++++++------ drivers/gpu/nova-core/fb/hal.rs | 2 ++ drivers/gpu/nova-core/fb/hal/gb100.rs | 1 + drivers/gpu/nova-core/fb/hal/tu102.rs | 2 ++ drivers/gpu/nova-core/firmware/gsp.rs | 8 +++++++- drivers/gpu/nova-core/gsp.rs | 1 + drivers/gpu/nova-core/gsp/fw.rs | 7 ++----- drivers/gpu/nova-core/gsp/hal/gh100.rs | 2 +- 8 files changed, 31 insertions(+), 13 deletions(-)
drivers/gpu/nova-core/fb.rs +15 -6
@@ -264,8 +264,12 @@ pub(crate) fn new( };let non_wpr_heap = { -let non_wpr_heap_size = hal.non_wpr_heap_size (); -FbRange (wpr2.start - non_wpr_heap_size..wpr2.start) +let non_wpr_start = wpr2 + .start + .checked_sub (gsp_fw.heap_params.tlv_non_wpr_heap_size) + .ok_or (EOVERFLOW )?; + +FbRange (non_wpr_start..wpr2.start) };Ok (Self {
@@ -278,7 +282,7 @@ pub(crate) fn new( wpr2, non_wpr_heap, vf_partition_count, - pmu_reserved_size: hal.pmu_reserved_size(), + pmu_reserved_size: gsp_fw.heap_params.tlv_pmu_reserved_size, }) } }
@@ -328,7 +332,12 @@ pub(crate) struct FbSizes {impl FbSizes {/// Computes the framebuffer region sizes for GSP-FMC boot. -pub (crate )fn new (chipset:Chipset , bar:Bar0 <'_>, vgpu_state:VgpuState ) ->Result <Self > { +pub (crate )fn new ( + chipset:Chipset , + bar:Bar0 <'_>, + gsp_fw: &GspFirmware <'_>, + vgpu_state:VgpuState , + ) ->Result <Self > {let hal = hal::fb_hal (chipset);let fb_size = hal.vidmem_size (bar);let (vf_partition_count, wpr2_heap_size) =wpr2_heap_params (chipset, vgpu_state, fb_size)?;
@@ -336,8 +345,8 @@ pub(crate) fn new(chipset: Chipset, bar: Bar0<'_>, vgpu_state: VgpuState) -> ResOk (Self { frts_size: hal.frts_size (), wpr2_heap_size, - non_wpr_heap_size: hal.non_wpr_heap_size (), - pmu_reserved_size: hal.pmu_reserved_size (), + non_wpr_heap_size: gsp_fw.heap_params.tlv_non_wpr_heap_size, + pmu_reserved_size: gsp_fw.heap_params.tlv_pmu_reserved_size, vf_partition_count, }) }
drivers/gpu/nova-core/fb/hal.rs +2 -0
@@ -34,9 +34,11 @@ pub(crate) trait FbHal {fn vidmem_size (&self, bar:Bar0 <'_>) ->u64 ;/// Returns the amount of VRAM to reserve for the PMU. +#[expect(unused)] fn pmu_reserved_size (&self) ->u32 ;/// Returns the non-WPR heap size for this chipset, in bytes. +#[expect(unused)] fn non_wpr_heap_size (&self) ->u64 ;/// Returns the FRTS size, in bytes.
drivers/gpu/nova-core/fb/hal/gb100.rs +1 -0
@@ -99,6 +99,7 @@ fn write_sysmem_flush_page_gb100(hshub0: Mmio<'_, regs::Hshub0Registers>, addr: ) .unwrap(); +#[allow(dead_code)] pub (super )const fn pmu_reserved_size_gb100 () ->u32 {cv! (PMU_RESERVED_SIZE ) }
drivers/gpu/nova-core/fb/hal/tu102.rs +2 -0
@@ -42,10 +42,12 @@ pub(super) fn vidmem_size_gp102(bar: Bar0<'_>) -> u64 { .usable_fb_size() } +#[allow(dead_code)] pub (super )const fn pmu_reserved_size_tu102 () ->u32 {0 } +#[allow(dead_code)] pub (super )const fn non_wpr_heap_size_tu102 () ->u64 { u64::SZ_1M }
drivers/gpu/nova-core/firmware/gsp.rs +7 -1
@@ -18,7 +18,8 @@ Tlv, }, }, - gpu::Chipset, // + gpu::Chipset, + gsp::GspFwHeapParams, // };/// The GSP firmware image, its signatures, and the GSP bootloader.
@@ -31,6 +32,8 @@ pub(crate) struct GspFirmware<'a> { pub(crate) signatures: Coherent<'a, [u8]>,/// GSP bootloader, verifies the GSP firmware before loading and running it. pub(crate) bootloader: RiscvFirmware<'a>, +/// Heap sizing parameters reported by the firmware metadata. + pub(crate) heap_params: GspFwHeapParams, }impl <'a>GspFirmware <'a> {
@@ -49,6 +52,8 @@ pub(crate) fn new(let signatures =Coherent ::from_slice (dev, tlv.get_bytes (b"SIGN" )?,GFP_KERNEL )?; +let heap_params =GspFwHeapParams ::from_tlv (&tlv)?; + Ok(try_pin_init!(Self { radix3 <- Radix3::new(dev, fw_vvec), signatures,
@@ -57,6 +62,7 @@ pub(crate) fn new(RiscvFirmware ::new (dev, &bl)? }, + heap_params, })) }) }
drivers/gpu/nova-core/gsp.rs +1 -0
@@ -29,6 +29,7 @@pub (crate )use fw::{GspFmcBootParams , +GspFwHeapParams ,GspFwWprMeta ,LibosMemoryRegionInitArgument ,LibosParams ,//
drivers/gpu/nova-core/gsp/fw.rs +2 -5
@@ -76,10 +76,8 @@ pub(crate) struct GspFwHeapParams { tlv_gsp_fw_heap_base_size_vgpu: u64,#[expect(unused)] tlv_gsp_fw_heap_size_per_vm: u64, -#[expect(unused)] - tlv_pmu_reserved_size: u32, -#[expect(unused)] - tlv_non_wpr_heap_size: u64, + pub(crate) tlv_pmu_reserved_size: u32, + pub(crate) tlv_non_wpr_heap_size: u64, }/// Minimum required alignment for the GSP heap.
@@ -100,7 +98,6 @@ fn base_rm_size(chipset: Chipset) -> u64 { }/// Returns the heap parameters from the TLV -#[expect(unused)] pub (crate )fn from_tlv (tlv: &Tlv <'_>) ->Result <Self > {Ok (Self { tlv_gsp_fw_heap_base_size: tlv.get_u64 (b"HBSZ" )?,
drivers/gpu/nova-core/gsp/hal/gh100.rs +1 -1
@@ -151,7 +151,7 @@ fn boot<'gpu>(let chipset = ctx.chipset;let gsp_falcon = ctx.gsp_falcon; -let fb_sizes =FbSizes ::new (chipset, ctx.bar, ctx.vgpu.state ())?; +let fb_sizes =FbSizes ::new (chipset, ctx.bar, gsp_fw, ctx.vgpu.state ())?;dev_dbg! (dev,"{:#x?}\n" , fb_sizes); let wpr_meta =
Signature · 1 line
2.54.0
PATCH v3 4/7 gpu: nova-core: remove heap size related HAL functions
In reply to Timur TabiNow that Nova-core reads all heap size values from the TLVs, we can remove all of the HAL functions that used to provide that data.
--- drivers/gpu/nova-core/fb/hal.rs | 8 ----- drivers/gpu/nova-core/fb/hal/ga100.rs | 8 ----- drivers/gpu/nova-core/fb/hal/ga102.rs | 8 ----- drivers/gpu/nova-core/fb/hal/gb100.rs | 42 +-------------------------- drivers/gpu/nova-core/fb/hal/gb202.rs | 13 +-------- drivers/gpu/nova-core/fb/hal/gh100.rs | 12 +------- drivers/gpu/nova-core/fb/hal/tu102.rs | 18 ------------ 7 files changed, 3 insertions(+), 106 deletions(-)
drivers/gpu/nova-core/fb/hal.rs +0 -8
@@ -33,14 +33,6 @@ pub(crate) trait FbHal {/// Returns the VRAM size, in bytes. fn vidmem_size (&self, bar:Bar0 <'_>) ->u64 ; -/// Returns the amount of VRAM to reserve for the PMU. -#[expect(unused)] -fn pmu_reserved_size (&self) ->u32 ; - -/// Returns the non-WPR heap size for this chipset, in bytes. -#[expect(unused)] -fn non_wpr_heap_size (&self) ->u64 ; -/// Returns the FRTS size, in bytes. fn frts_size (&self) ->u64 ; }
drivers/gpu/nova-core/fb/hal/ga100.rs +0 -8
@@ -70,14 +70,6 @@ fn vidmem_size(&self, bar: Bar0<'_>) -> u64 {super ::tu102::vidmem_size_gp102 (bar) } -fn pmu_reserved_size (&self) ->u32 { -super ::tu102::pmu_reserved_size_tu102 () - } - -fn non_wpr_heap_size (&self) ->u64 { -super ::tu102::non_wpr_heap_size_tu102 () - } -// GA100 is a special case where its FRTS region exists, but is empty. We // return a size of 0 because we still need to record where the region starts. fn frts_size (&self) ->u64 {
drivers/gpu/nova-core/fb/hal/ga102.rs +0 -8
@@ -37,14 +37,6 @@ fn vidmem_size(&self, bar: Bar0<'_>) -> u64 {vidmem_size_ga102 (bar) } -fn pmu_reserved_size (&self) ->u32 { -super ::tu102::pmu_reserved_size_tu102 () - } - -fn non_wpr_heap_size (&self) ->u64 { -super ::tu102::non_wpr_heap_size_tu102 () - } -fn frts_size (&self) ->u64 {super ::tu102::frts_size_tu102 () }
drivers/gpu/nova-core/fb/hal/gb100.rs +1 -41
60 lines not on this page · raw message
drivers/gpu/nova-core/fb/hal/gb202.rs +1 -12
@@ -6,8 +6,7 @@use kernel::{ io::Io , num::Bounded , - prelude::*, - sizes::SizeConstants ,// + prelude::*,// };use crate ::{
@@ -67,16 +66,6 @@ fn vidmem_size(&self, bar: Bar0<'_>) -> u64 {super ::ga102::vidmem_size_ga102 (bar) } -fn pmu_reserved_size (&self) ->u32 { -super ::gb100::pmu_reserved_size_gb100 () - } - -fn non_wpr_heap_size (&self) ->u64 { -// Non-WPR heap for GB20x (see OpenRM: kgspGetNonWprHeapSize, GB202+). This size is -// r000-specific. -3 * u64::SZ_1M - } -fn frts_size (&self) ->u64 {super ::tu102::frts_size_tu102 () }
drivers/gpu/nova-core/fb/hal/gh100.rs +1 -11
@@ -4,8 +4,7 @@use kernel::{ io::Io , num::Bounded , - prelude::*, - sizes::SizeConstants ,// + prelude::*,// };use crate ::{
@@ -59,15 +58,6 @@ fn vidmem_size(&self, bar: Bar0<'_>) -> u64 {super ::ga102::vidmem_size_ga102 (bar) } -fn pmu_reserved_size (&self) ->u32 { -super ::tu102::pmu_reserved_size_tu102 () - } - -fn non_wpr_heap_size (&self) ->u64 { -// Non-WPR heap for Hopper (see Open RM: kgspCalculateFbLayout_GH100). - u64::SZ_2M - } -fn frts_size (&self) ->u64 {super ::tu102::frts_size_tu102 () }
drivers/gpu/nova-core/fb/hal/tu102.rs +0 -18
@@ -42,16 +42,6 @@ pub(super) fn vidmem_size_gp102(bar: Bar0<'_>) -> u64 { .usable_fb_size() } -#[allow(dead_code)] -pub (super )const fn pmu_reserved_size_tu102 () ->u32 { -0 -} - -#[allow(dead_code)] -pub (super )const fn non_wpr_heap_size_tu102 () ->u64 { - u64::SZ_1M -} -pub (super )const fn frts_size_tu102 () ->u64 { u64::SZ_1M }
@@ -75,14 +65,6 @@ fn vidmem_size(&self, bar: Bar0<'_>) -> u64 {vidmem_size_gp102 (bar) } -fn pmu_reserved_size (&self) ->u32 { -pmu_reserved_size_tu102 () - } - -fn non_wpr_heap_size (&self) ->u64 { -non_wpr_heap_size_tu102 () - } -fn frts_size (&self) ->u64 {frts_size_tu102 () }
Signature · 1 line
2.54.0
PATCH v3 5/7 gpu: nova-core: add TLV versions of WPR heap size functions
In reply to Timur TabiAdd TLV versions of vgpu_wpr_heap_size() and wpr_heap_size() to GspFwHeapParams. These complement the same functions in LibosParams. We add them to GspFwHeapParams because LibosParams will be removed in a future commit, and the driver will use the GspFwHeapParams version instead.
--- drivers/gpu/nova-core/gsp/fw.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +29 -4
@@ -68,13 +68,9 @@/// Heap memory requirements and constraints for booting GSP-RM. pub (crate )struct GspFwHeapParams { -#[expect(unused)] tlv_gsp_fw_heap_base_size:u64 , -#[expect(unused)] tlv_gsp_hw_heap_size_per_gb:u64 , -#[expect(unused)] tlv_gsp_fw_heap_base_size_vgpu:u64 , -#[expect(unused)] tlv_gsp_fw_heap_size_per_vm:u64 ,pub (crate ) tlv_pmu_reserved_size:u32 ,pub (crate ) tlv_non_wpr_heap_size:u64 ,
@@ -127,6 +123,35 @@ fn management_overhead(fb_size: u64) -> Result<u64> { .align_up(GSP_HEAP_ALIGNMENT) .ok_or (EINVAL ) } + +/// Returns the WPR heap size to reserve when vGPU is enabled. +#[expect(unused)] +pub (crate )fn vgpu_wpr_heap_size (&self, total_vfs:u16 ) ->Result <u64 > { +//u64::from(bindings::GSP_FW_HEAP_SIZE_VGPU_DEFAULT) +let vm_size = self + .tlv_gsp_fw_heap_size_per_vm + .checked_mul (u64::from (total_vfs)) + .and_then (|size| size.align_up (GSP_HEAP_ALIGNMENT )) + .ok_or (EINVAL )?; + +Ok (self.tlv_gsp_fw_heap_base_size_vgpu.saturating_add (vm_size)) + } + +/// Returns the amount of memory (in bytes) to allocate for the WPR heap for a framebuffer size +/// of `fb_size` (in bytes). +#[expect(unused)] +pub (crate )fn wpr_heap_size (&self, fb_size:u64 ) ->Result <u64 > { +let fb_size_gb = fb_size.div_ceil (u64::SZ_1G ); +let management_overhead = self + .tlv_gsp_hw_heap_size_per_gb + .checked_mul (fb_size_gb) + .and_then (|size| size.align_up (GSP_HEAP_ALIGNMENT )) + .ok_or (EINVAL )?; + + self.tlv_gsp_fw_heap_base_size + .checked_add (management_overhead) + .ok_or (EINVAL ) + } }/// Heap memory requirements and constraints for a given version of the GSP LIBOS.
Signature · 1 line
2.54.0
Re: [PATCH v3 5/7] gpu: nova-core: add TLV versions of WPR heap size functions
Quoted 30 lines · Timur Tabi
Add TLV versions of
vgpu_wpr_heap_size()andwpr_heap_size()to GspFwHeapParams. These complement the same functions in LibosParams. We add them to GspFwHeapParams because LibosParams will be removed in a future commit, and the driver will use the GspFwHeapParams version instead.Signed-off-by Timur Tabi <[email protected]>--- drivers/gpu/nova-core/gsp/fw.rs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)drivers/gpu/nova-core/gsp/fw.rs +0
-4@@ -68,13 +68,9 @@/// Heap memory requirements and constraints for booting GSP-RM. pub (crate )struct GspFwHeapParams { -#[expect(unused)] tlv_gsp_fw_heap_base_size:u64 , -#[expect(unused)] tlv_gsp_hw_heap_size_per_gb:u64 , -#[expect(unused)] tlv_gsp_fw_heap_base_size_vgpu:u64 , -#[expect(unused)] tlv_gsp_fw_heap_size_per_vm:u64 ,pub (crate ) tlv_pmu_reserved_size:u32 ,pub (crate ) tlv_non_wpr_heap_size:u64 ,
drivers/gpu/nova-core/gsp/fw.rs fn management_overhead(fb_size: u64) -> Result<u64> { · line 130
Quoted 8 lines
drivers/gpu/nova-core/gsp/fw.rs +5
-0@@ -127,6 +123,35 @@ fn management_overhead(fb_size: u64) -> Result<u64> { .align_up(GSP_HEAP_ALIGNMENT) .ok_or (EINVAL ) } + +/// Returns the WPR heap size to reserve when vGPU is enabled. +#[expect(unused)] +pub (crate )fn vgpu_wpr_heap_size (&self, total_vfs:u16 ) ->Result <u64 > { +//u64::from(bindings::GSP_FW_HEAP_SIZE_VGPU_DEFAULT)
nit: stray commented out code
drivers/gpu/nova-core/gsp/fw.rs fn management_overhead(fb_size: u64) -> Result<u64> { · line 137
Quoted 7 lines
drivers/gpu/nova-core/gsp/fw.rs +7
-0+let vm_size = self + .tlv_gsp_fw_heap_size_per_vm + .checked_mul (u64::from (total_vfs)) + .and_then (|size| size.align_up (GSP_HEAP_ALIGNMENT )) + .ok_or (EINVAL )?; + +Ok (self.tlv_gsp_fw_heap_base_size_vgpu.saturating_add (vm_size))
nit: pretty easy to checked_add here too imo
With above changes:
PATCH v3 6/7 gpu: nova-core: change wpr2_heap_params to use TLV values
In reply to Timur TabiNow that GspFwHeapParams has TLV-based implementations of wpr_heap_size() and vgpu_wpr_heap_size(), change wpr2_heap_params() to use those functions instead of the LibosParams versions. This renders LibosParams unused, and it is marked as such.
--- drivers/gpu/nova-core/fb.rs | 19 +++++++++++-------- drivers/gpu/nova-core/gsp.rs | 3 +-- drivers/gpu/nova-core/gsp/fw.rs | 3 +-- 3 files changed, 13 insertions(+), 12 deletions(-)
drivers/gpu/nova-core/fb.rs +11 -8
@@ -242,7 +242,8 @@ pub(crate) fn new(FbRange (fw_image_addr..fw_image_addr + fw_image_size) }; -let (vf_partition_count, wpr2_heap_size) =wpr2_heap_params (chipset, vgpu_state, fb.end)?; +let (vf_partition_count, wpr2_heap_size) = +wpr2_heap_params (&gsp_fw.heap_params, vgpu_state, fb.end)?;let wpr2_heap = {const WPR2_HEAP_DOWN_ALIGN :Alignment =Alignment ::new ::<SZ_1M >();
@@ -302,15 +303,16 @@ pub(crate) fn wpr2_range(bar: Bar0<'_>) -> Option<Range<u64>> { }/// Computes the number of VF partitions and the WPR2 heap size from the vGPU state. -fn wpr2_heap_params (chipset:Chipset , vgpu_state:VgpuState , fb_size:u64 ) ->Result <(u8 ,u64 )> { +fn wpr2_heap_params ( + heap_params: &gsp::GspFwHeapParams , + vgpu_state:VgpuState , + fb_size:u64 , +) ->Result <(u8 ,u64 )> {Ok (match vgpu_state { -VgpuState ::Disabled => ( -0 , - gsp::LibosParams ::from_chipset (chipset).wpr_heap_size (chipset, fb_size)?, - ), +VgpuState ::Disabled => (0 , heap_params.wpr_heap_size (fb_size)?),VgpuState ::Enabled { total_vfs } => ( u8::try_from (total_vfs.get ()).map_err (|_|EINVAL )?, - gsp::LibosParams ::vgpu_wpr_heap_size (), + heap_params.vgpu_wpr_heap_size (total_vfs.get ())?, ), }) }
@@ -340,7 +342,8 @@ pub(crate) fn new( ) -> Result<Self> {let hal = hal::fb_hal (chipset);let fb_size = hal.vidmem_size (bar); -let (vf_partition_count, wpr2_heap_size) =wpr2_heap_params (chipset, vgpu_state, fb_size)?; +let (vf_partition_count, wpr2_heap_size) = +wpr2_heap_params (&gsp_fw.heap_params, vgpu_state, fb_size)?;Ok (Self { frts_size: hal.frts_size (),
drivers/gpu/nova-core/gsp.rs +1 -2
@@ -31,8 +31,7 @@ GspFmcBootParams, GspFwHeapParams, GspFwWprMeta, - LibosMemoryRegionInitArgument, - LibosParams, // + LibosMemoryRegionInitArgument, // };pub (crate )use hal::boot_firmware_files;
drivers/gpu/nova-core/gsp/fw.rs +1 -2
@@ -125,7 +125,6 @@ fn management_overhead(fb_size: u64) -> Result<u64> { }/// Returns the WPR heap size to reserve when vGPU is enabled. -#[expect(unused)] pub (crate )fn vgpu_wpr_heap_size (&self, total_vfs:u16 ) ->Result <u64 > {//u64::from(bindings::GSP_FW_HEAP_SIZE_VGPU_DEFAULT) let vm_size = self
@@ -139,7 +138,6 @@ pub(crate) fn vgpu_wpr_heap_size(&self, total_vfs: u16) -> Result<u64> {/// Returns the amount of memory (in bytes) to allocate for the WPR heap for a framebuffer size /// of `fb_size` (in bytes). -#[expect(unused)] pub (crate )fn wpr_heap_size (&self, fb_size:u64 ) ->Result <u64 > {let fb_size_gb = fb_size.div_ceil (u64::SZ_1G );let management_overhead = self
@@ -162,6 +160,7 @@ pub(crate) struct LibosParams { allowed_heap_size: Range<u64>, } +#[expect(unused)] impl LibosParams {/// Version 2 of the GSP LIBOS (Turing and GA100) const LIBOS2: LibosParams = LibosParams {
Signature · 1 line
2.54.0
PATCH v3 7/7 gpu: nova-core: remove LibosParams
In reply to Timur TabiAll functionality that was provided by LibosParams has now been replaced with TLV-based implementations in GspFwHeapParams, so we can remove LibosParams and all its dependencies.
This also allows us to remove the legacy methods base_rm_size(), client_alloc_size(), and management_overhead(). These were used to calculate intermediate values that are now represented by TLV values.
LibosParams and GspFwHeapParams were two types used to hold data and/or methods for calculating the heap sides that GSP-RM needs for booting. Although they technically represent distinct parts of the equations, they were always used together, so it makes sense to merge LibosParams into GspFwHeapParams.
--- drivers/gpu/nova-core/gsp/fw.rs | 96 --------------------------------- 1 file changed, 96 deletions(-)
drivers/gpu/nova-core/gsp/fw.rs +0 -96
@@ -7,8 +7,6 @@// Alias to avoid repeating the version number with every use. use r000_00as bindings; -use core::ops::Range ; -use kernel::{ bitfield, dma::Coherent ,
@@ -40,10 +38,6 @@ gsp::GspFirmware, tlv::Tlv, // }, - gpu::{ - Architecture, - Chipset, // - }, gsp::{ cmdq::Cmdq, GSP_PAGE_SHIFT,
@@ -80,19 +74,6 @@ pub(crate) struct GspFwHeapParams {const GSP_HEAP_ALIGNMENT :Alignment =Alignment ::new ::<{1 <<20 }>();impl GspFwHeapParams { -/// Returns the amount of GSP-RM heap memory used during GSP-RM boot and initialization (up to -/// and including the first client subdevice allocation). -fn base_rm_size (chipset:Chipset ) ->u64 { -match chipset.arch () { -Architecture ::Turing |Architecture ::Ampere |Architecture ::Ada => { - u64::from (bindings::GSP_FW_HEAP_PARAM_BASE_RM_SIZE_TU10X ) - } -Architecture ::Hopper |Architecture ::BlackwellGB10x |Architecture ::BlackwellGB20x => { - u64::from (bindings::GSP_FW_HEAP_PARAM_BASE_RM_SIZE_GH100 ) - } - } - } -/// Returns the heap parameters from the TLV pub (crate )fn from_tlv (tlv: &Tlv <'_>) ->Result <Self > {Ok (Self {
@@ -105,25 +86,6 @@ pub(crate) fn from_tlv(tlv: &Tlv<'_>) -> Result<Self> { }) } -/// Returns the amount of heap memory required to support a single channel allocation. -fn client_alloc_size () ->u64 { - u64::from (bindings::GSP_FW_HEAP_PARAM_CLIENT_ALLOC_SIZE ) - .align_up (GSP_HEAP_ALIGNMENT ) - .unwrap_or (u64::MAX ) - } - -/// Returns the amount of memory to reserve for management purposes for a framebuffer of size -/// `fb_size`. -fn management_overhead (fb_size:u64 ) ->Result <u64 > { -let fb_size_gb = fb_size.div_ceil (u64::SZ_1G ); - - u64::from (bindings::GSP_FW_HEAP_PARAM_SIZE_PER_GB ) - .checked_mul (fb_size_gb) - .ok_or (EINVAL )? - .align_up (GSP_HEAP_ALIGNMENT ) - .ok_or (EINVAL ) - } -/// Returns the WPR heap size to reserve when vGPU is enabled. pub (crate )fn vgpu_wpr_heap_size (&self, total_vfs:u16 ) ->Result <u64 > {//u64::from(bindings::GSP_FW_HEAP_SIZE_VGPU_DEFAULT)
@@ -152,64 +114,6 @@ pub(crate) fn wpr_heap_size(&self, fb_size: u64) -> Result<u64> { } } -/// Heap memory requirements and constraints for a given version of the GSP LIBOS. -pub (crate )struct LibosParams { -/// The base amount of heap required by the GSP operating system, in bytes. - carveout_size:u64 , -/// The minimum and maximum sizes allowed for the GSP FW heap, in bytes. - allowed_heap_size:Range <u64 >, -} - -#[expect(unused)] -impl LibosParams { -/// Version 2 of the GSP LIBOS (Turing and GA100) -const LIBOS2 :LibosParams =LibosParams { - carveout_size:cv! (bindings::GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS2 ), - allowed_heap_size:cv! (bindings::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MIN_MB =>u64 ) - * u64::SZ_1M - ..cv! (bindings::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS2_MAX_MB =>u64 ) * u64::SZ_1M , - }; - -/// Version 3 of the GSP LIBOS (GA102+) -const LIBOS3 :LibosParams =LibosParams { - carveout_size:cv! (bindings::GSP_FW_HEAP_PARAM_OS_SIZE_LIBOS3_BAREMETAL ), - allowed_heap_size:cv! (bindings::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS3_BAREMETAL_MIN_MB =>u64 ) - * u64::SZ_1M - ..cv! (bindings::GSP_FW_HEAP_SIZE_OVERRIDE_LIBOS3_BAREMETAL_MAX_MB =>u64 ) * u64::SZ_1M , - }; - -/// Returns the libos parameters corresponding to `chipset`. -pub (crate )fn from_chipset (chipset:Chipset ) -> &'staticLibosParams { -if chipset <Chipset ::GA102 { - &Self ::LIBOS2 - }else { - &Self ::LIBOS3 - } - } - -/// Returns the WPR heap size to reserve when vGPU is enabled. -pub (crate )fn vgpu_wpr_heap_size () ->u64 { - u64::from (bindings::GSP_FW_HEAP_SIZE_VGPU_DEFAULT ) - } - -/// Returns the amount of memory (in bytes) to allocate for the WPR heap for a framebuffer size -/// of `fb_size` (in bytes) for `chipset`. -pub (crate )fn wpr_heap_size (&self, chipset:Chipset , fb_size:u64 ) ->Result <u64 > { -// The WPR heap will contain the following: -// LIBOS carveout, -Ok (self - .carveout_size -// RM boot working memory, - .saturating_add (GspFwHeapParams ::base_rm_size (chipset)) -// One RM client, - .saturating_add (GspFwHeapParams ::client_alloc_size ()) -// Overhead for memory management. - .saturating_add (GspFwHeapParams ::management_overhead (fb_size)?) -// Clamp to the supported heap sizes. - .clamp (self.allowed_heap_size.start, self.allowed_heap_size.end -1 )) - } -} -/// Structure passed to the GSP bootloader, containing the framebuffer layout as well as the DMA /// addresses of the GSP bootloader and firmware. #[repr(transparent)]
Signature · 1 line
2.54.0