* [PATCH 0/4] nova-core Improve pin initializer code
@ 2025-12-18 15:50 Danilo Krummrich
2025-12-18 15:50 ` [PATCH 1/4] gpu: nova-core: fw: get rid of redundant Result in GspFirmware::new() Danilo Krummrich
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Danilo Krummrich @ 2025-12-18 15:50 UTC (permalink / raw)
To: acourbot, jhubbard, apopple, joelagnelf, aliceryhl, lossin
Cc: nouveau, dri-devel, rust-for-linux, linux-kernel,
Danilo Krummrich
This is a minor series to improve some of the pin initializer code to:
1. Reduce redundancy caused by Result<impl PinInit<T, Error>> return
values with pin_init_scope().
2. Relocate code that technically fits in the pin initializer into the
initializer itself.
While, thanks to pin_init_scope(), it is also possible to keep it as is,
moving appropriate code into the initializer has the advantage that it
structures the dependencies of fields naturally.
For instance, intermediate data that is only needed for a single field goes
into the initializer block of this field, making it obvious that it is not
needed by anything else.
On the other hand, intermediate data that is needed for multiple fields to
initialize remains above the initializer, naturally indicating that it is
needed my multiple fields.
Danilo Krummrich (4):
gpu: nova-core: fw: get rid of redundant Result in GspFirmware::new()
gpu: nova-core: fw: move appropriate code into pin initializer
gpu: nova-core: gsp: get rid of redundant Result in Gsp::new()
gpu: nova-core: gsp: move appropriate code into pin initializer
drivers/gpu/nova-core/firmware/gsp.rs | 134 +++++++++++++-------------
drivers/gpu/nova-core/gpu.rs | 2 +-
drivers/gpu/nova-core/gsp.rs | 73 +++++++-------
drivers/gpu/nova-core/gsp/boot.rs | 5 +-
4 files changed, 106 insertions(+), 108 deletions(-)
base-commit: 97cf6bc0abd381fd84e5d8e978322a62a58fb00e
--
2.52.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] gpu: nova-core: fw: get rid of redundant Result in GspFirmware::new()
2025-12-18 15:50 [PATCH 0/4] nova-core Improve pin initializer code Danilo Krummrich
@ 2025-12-18 15:50 ` Danilo Krummrich
2025-12-18 15:50 ` [PATCH 2/4] gpu: nova-core: fw: move appropriate code into pin initializer Danilo Krummrich
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Danilo Krummrich @ 2025-12-18 15:50 UTC (permalink / raw)
To: acourbot, jhubbard, apopple, joelagnelf, aliceryhl, lossin
Cc: nouveau, dri-devel, rust-for-linux, linux-kernel,
Danilo Krummrich
In GspFirmware::new(), utilize pin_init_scope() to get rid of the Result
in the returned
Result<impl PinInit<T, Error>>
which is unnecessarily redundant.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
drivers/gpu/nova-core/firmware/gsp.rs | 132 +++++++++++++-------------
drivers/gpu/nova-core/gsp/boot.rs | 5 +-
2 files changed, 68 insertions(+), 69 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index 0549805282ab..e034268be3c5 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -153,82 +153,84 @@ pub(crate) struct GspFirmware {
impl GspFirmware {
/// Loads the GSP firmware binaries, map them into `dev`'s address-space, and creates the page
/// tables expected by the GSP bootloader to load it.
- pub(crate) fn new<'a, 'b>(
+ pub(crate) fn new<'a>(
dev: &'a device::Device<device::Bound>,
chipset: Chipset,
- ver: &'b str,
- ) -> Result<impl PinInit<Self, Error> + 'a> {
- let fw = super::request_firmware(dev, chipset, "gsp", ver)?;
+ ver: &'a str,
+ ) -> impl PinInit<Self, Error> + 'a {
+ pin_init::pin_init_scope(move || {
+ let fw = super::request_firmware(dev, chipset, "gsp", ver)?;
- let fw_section = elf::elf64_section(fw.data(), ".fwimage").ok_or(EINVAL)?;
+ let fw_section = elf::elf64_section(fw.data(), ".fwimage").ok_or(EINVAL)?;
- let sigs_section = match chipset.arch() {
- Architecture::Ampere => ".fwsignature_ga10x",
- Architecture::Ada => ".fwsignature_ad10x",
- _ => return Err(ENOTSUPP),
- };
- let signatures = elf::elf64_section(fw.data(), sigs_section)
- .ok_or(EINVAL)
- .and_then(|data| DmaObject::from_data(dev, data))?;
+ let sigs_section = match chipset.arch() {
+ Architecture::Ampere => ".fwsignature_ga10x",
+ Architecture::Ada => ".fwsignature_ad10x",
+ _ => return Err(ENOTSUPP),
+ };
+ let signatures = elf::elf64_section(fw.data(), sigs_section)
+ .ok_or(EINVAL)
+ .and_then(|data| DmaObject::from_data(dev, data))?;
- let size = fw_section.len();
+ let size = fw_section.len();
- // Move the firmware into a vmalloc'd vector and map it into the device address
- // space.
- let fw_vvec = VVec::with_capacity(fw_section.len(), GFP_KERNEL)
- .and_then(|mut v| {
- v.extend_from_slice(fw_section, GFP_KERNEL)?;
- Ok(v)
- })
- .map_err(|_| ENOMEM)?;
+ // Move the firmware into a vmalloc'd vector and map it into the device address
+ // space.
+ let fw_vvec = VVec::with_capacity(fw_section.len(), GFP_KERNEL)
+ .and_then(|mut v| {
+ v.extend_from_slice(fw_section, GFP_KERNEL)?;
+ Ok(v)
+ })
+ .map_err(|_| ENOMEM)?;
- let bl = super::request_firmware(dev, chipset, "bootloader", ver)?;
- let bootloader = RiscvFirmware::new(dev, &bl)?;
+ let bl = super::request_firmware(dev, chipset, "bootloader", ver)?;
+ let bootloader = RiscvFirmware::new(dev, &bl)?;
- Ok(try_pin_init!(Self {
- fw <- SGTable::new(dev, fw_vvec, DataDirection::ToDevice, GFP_KERNEL),
- level2 <- {
- // Allocate the level 2 page table, map the firmware onto it, and map it into the
- // device address space.
- VVec::<u8>::with_capacity(
- fw.iter().count() * core::mem::size_of::<u64>(),
- GFP_KERNEL,
- )
- .map_err(|_| ENOMEM)
- .and_then(|level2| map_into_lvl(&fw, level2))
- .map(|level2| SGTable::new(dev, level2, DataDirection::ToDevice, GFP_KERNEL))?
- },
- level1 <- {
- // Allocate the level 1 page table, map the level 2 page table onto it, and map it
- // into the device address space.
- VVec::<u8>::with_capacity(
- level2.iter().count() * core::mem::size_of::<u64>(),
- GFP_KERNEL,
- )
- .map_err(|_| ENOMEM)
- .and_then(|level1| map_into_lvl(&level2, level1))
- .map(|level1| SGTable::new(dev, level1, DataDirection::ToDevice, GFP_KERNEL))?
- },
- level0: {
- // Allocate the level 0 page table as a device-visible DMA object, and map the
- // level 1 page table onto it.
+ Ok(try_pin_init!(Self {
+ fw <- SGTable::new(dev, fw_vvec, DataDirection::ToDevice, GFP_KERNEL),
+ level2 <- {
+ // Allocate the level 2 page table, map the firmware onto it, and map it into
+ // the device address space.
+ VVec::<u8>::with_capacity(
+ fw.iter().count() * core::mem::size_of::<u64>(),
+ GFP_KERNEL,
+ )
+ .map_err(|_| ENOMEM)
+ .and_then(|level2| map_into_lvl(&fw, level2))
+ .map(|level2| SGTable::new(dev, level2, DataDirection::ToDevice, GFP_KERNEL))?
+ },
+ level1 <- {
+ // Allocate the level 1 page table, map the level 2 page table onto it, and map
+ // it into the device address space.
+ VVec::<u8>::with_capacity(
+ level2.iter().count() * core::mem::size_of::<u64>(),
+ GFP_KERNEL,
+ )
+ .map_err(|_| ENOMEM)
+ .and_then(|level1| map_into_lvl(&level2, level1))
+ .map(|level1| SGTable::new(dev, level1, DataDirection::ToDevice, GFP_KERNEL))?
+ },
+ level0: {
+ // Allocate the level 0 page table as a device-visible DMA object, and map the
+ // level 1 page table onto it.
- // Level 0 page table data.
- let mut level0_data = kvec![0u8; GSP_PAGE_SIZE]?;
+ // Level 0 page table data.
+ let mut level0_data = kvec![0u8; GSP_PAGE_SIZE]?;
- // Fill level 1 page entry.
- let level1_entry = level1.iter().next().ok_or(EINVAL)?;
- let level1_entry_addr = level1_entry.dma_address();
- let dst = &mut level0_data[..size_of_val(&level1_entry_addr)];
- dst.copy_from_slice(&level1_entry_addr.to_le_bytes());
+ // Fill level 1 page entry.
+ let level1_entry = level1.iter().next().ok_or(EINVAL)?;
+ let level1_entry_addr = level1_entry.dma_address();
+ let dst = &mut level0_data[..size_of_val(&level1_entry_addr)];
+ dst.copy_from_slice(&level1_entry_addr.to_le_bytes());
- // Turn the level0 page table into a [`DmaObject`].
- DmaObject::from_data(dev, &level0_data)?
- },
- size,
- signatures,
- bootloader,
- }))
+ // Turn the level0 page table into a [`DmaObject`].
+ DmaObject::from_data(dev, &level0_data)?
+ },
+ size,
+ signatures,
+ bootloader,
+ }))
+ })
}
/// Returns the DMA handle of the radix3 level 0 page table.
diff --git a/drivers/gpu/nova-core/gsp/boot.rs b/drivers/gpu/nova-core/gsp/boot.rs
index 54937606b5b0..a53d80620468 100644
--- a/drivers/gpu/nova-core/gsp/boot.rs
+++ b/drivers/gpu/nova-core/gsp/boot.rs
@@ -139,10 +139,7 @@ pub(crate) fn boot(
let bios = Vbios::new(dev, bar)?;
- let gsp_fw = KBox::pin_init(
- GspFirmware::new(dev, chipset, FIRMWARE_VERSION)?,
- GFP_KERNEL,
- )?;
+ let gsp_fw = KBox::pin_init(GspFirmware::new(dev, chipset, FIRMWARE_VERSION), GFP_KERNEL)?;
let fb_layout = FbLayout::new(chipset, bar, &gsp_fw)?;
dev_dbg!(dev, "{:#x?}\n", fb_layout);
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] gpu: nova-core: fw: move appropriate code into pin initializer
2025-12-18 15:50 [PATCH 0/4] nova-core Improve pin initializer code Danilo Krummrich
2025-12-18 15:50 ` [PATCH 1/4] gpu: nova-core: fw: get rid of redundant Result in GspFirmware::new() Danilo Krummrich
@ 2025-12-18 15:50 ` Danilo Krummrich
2025-12-18 15:50 ` [PATCH 3/4] gpu: nova-core: gsp: get rid of redundant Result in Gsp::new() Danilo Krummrich
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Danilo Krummrich @ 2025-12-18 15:50 UTC (permalink / raw)
To: acourbot, jhubbard, apopple, joelagnelf, aliceryhl, lossin
Cc: nouveau, dri-devel, rust-for-linux, linux-kernel,
Danilo Krummrich
Relocate the code that technically fits in the pin initializer into the
initializer itself.
While, thanks to pin_init_scope(), it is also possible to keep it as is,
moving appropriate code into the initializer has the advantage that it
structures the dependencies of fields naturally.
For instance, intermediate data that is only needed for a single field
goes into the initializer block of this field, making it obvious that it
is not needed by anything else.
On the other hand, intermediate data that is needed for multiple fields
to initialize remains above the initializer, naturally indicating that
it is needed my multiple fields.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
drivers/gpu/nova-core/firmware/gsp.rs | 34 ++++++++++++++-------------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/nova-core/firmware/gsp.rs b/drivers/gpu/nova-core/firmware/gsp.rs
index e034268be3c5..da97814cf859 100644
--- a/drivers/gpu/nova-core/firmware/gsp.rs
+++ b/drivers/gpu/nova-core/firmware/gsp.rs
@@ -159,18 +159,9 @@ pub(crate) fn new<'a>(
ver: &'a str,
) -> impl PinInit<Self, Error> + 'a {
pin_init::pin_init_scope(move || {
- let fw = super::request_firmware(dev, chipset, "gsp", ver)?;
+ let firmware = super::request_firmware(dev, chipset, "gsp", ver)?;
- let fw_section = elf::elf64_section(fw.data(), ".fwimage").ok_or(EINVAL)?;
-
- let sigs_section = match chipset.arch() {
- Architecture::Ampere => ".fwsignature_ga10x",
- Architecture::Ada => ".fwsignature_ad10x",
- _ => return Err(ENOTSUPP),
- };
- let signatures = elf::elf64_section(fw.data(), sigs_section)
- .ok_or(EINVAL)
- .and_then(|data| DmaObject::from_data(dev, data))?;
+ let fw_section = elf::elf64_section(firmware.data(), ".fwimage").ok_or(EINVAL)?;
let size = fw_section.len();
@@ -183,9 +174,6 @@ pub(crate) fn new<'a>(
})
.map_err(|_| ENOMEM)?;
- let bl = super::request_firmware(dev, chipset, "bootloader", ver)?;
- let bootloader = RiscvFirmware::new(dev, &bl)?;
-
Ok(try_pin_init!(Self {
fw <- SGTable::new(dev, fw_vvec, DataDirection::ToDevice, GFP_KERNEL),
level2 <- {
@@ -227,8 +215,22 @@ pub(crate) fn new<'a>(
DmaObject::from_data(dev, &level0_data)?
},
size,
- signatures,
- bootloader,
+ signatures: {
+ let sigs_section = match chipset.arch() {
+ Architecture::Ampere => ".fwsignature_ga10x",
+ Architecture::Ada => ".fwsignature_ad10x",
+ _ => return Err(ENOTSUPP),
+ };
+
+ elf::elf64_section(firmware.data(), sigs_section)
+ .ok_or(EINVAL)
+ .and_then(|data| DmaObject::from_data(dev, data))?
+ },
+ bootloader: {
+ let bl = super::request_firmware(dev, chipset, "bootloader", ver)?;
+
+ RiscvFirmware::new(dev, &bl)?
+ },
}))
})
}
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] gpu: nova-core: gsp: get rid of redundant Result in Gsp::new()
2025-12-18 15:50 [PATCH 0/4] nova-core Improve pin initializer code Danilo Krummrich
2025-12-18 15:50 ` [PATCH 1/4] gpu: nova-core: fw: get rid of redundant Result in GspFirmware::new() Danilo Krummrich
2025-12-18 15:50 ` [PATCH 2/4] gpu: nova-core: fw: move appropriate code into pin initializer Danilo Krummrich
@ 2025-12-18 15:50 ` Danilo Krummrich
2025-12-18 15:50 ` [PATCH 4/4] gpu: nova-core: gsp: move appropriate code into pin initializer Danilo Krummrich
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Danilo Krummrich @ 2025-12-18 15:50 UTC (permalink / raw)
To: acourbot, jhubbard, apopple, joelagnelf, aliceryhl, lossin
Cc: nouveau, dri-devel, rust-for-linux, linux-kernel,
Danilo Krummrich
In Gsp::new(), utilize pin_init_scope() to get rid of the Result in the
returned
Result<impl PinInit<T, Error>>
which is unnecessarily redundant.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
drivers/gpu/nova-core/gpu.rs | 2 +-
drivers/gpu/nova-core/gsp.rs | 78 ++++++++++++++++++------------------
2 files changed, 41 insertions(+), 39 deletions(-)
diff --git a/drivers/gpu/nova-core/gpu.rs b/drivers/gpu/nova-core/gpu.rs
index 629c9d2dc994..50d76092fbdd 100644
--- a/drivers/gpu/nova-core/gpu.rs
+++ b/drivers/gpu/nova-core/gpu.rs
@@ -281,7 +281,7 @@ pub(crate) fn new<'a>(
sec2_falcon: Falcon::new(pdev.as_ref(), spec.chipset)?,
- gsp <- Gsp::new(pdev)?,
+ gsp <- Gsp::new(pdev),
_: { gsp.boot(pdev, bar, spec.chipset, gsp_falcon, sec2_falcon)? },
diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index fb6f74797178..8bc86e1bcac5 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -119,43 +119,45 @@ pub(crate) struct Gsp {
impl Gsp {
// Creates an in-place initializer for a `Gsp` manager for `pdev`.
- pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> Result<impl PinInit<Self, Error>> {
- let dev = pdev.as_ref();
- let libos = CoherentAllocation::<LibosMemoryRegionInitArgument>::alloc_coherent(
- dev,
- GSP_PAGE_SIZE / size_of::<LibosMemoryRegionInitArgument>(),
- GFP_KERNEL | __GFP_ZERO,
- )?;
-
- // Initialise the logging structures. The OpenRM equivalents are in:
- // _kgspInitLibosLoggingStructures (allocates memory for buffers)
- // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
- let loginit = LogBuffer::new(dev)?;
- dma_write!(libos[0] = LibosMemoryRegionInitArgument::new("LOGINIT", &loginit.0))?;
-
- let logintr = LogBuffer::new(dev)?;
- dma_write!(libos[1] = LibosMemoryRegionInitArgument::new("LOGINTR", &logintr.0))?;
-
- let logrm = LogBuffer::new(dev)?;
- dma_write!(libos[2] = LibosMemoryRegionInitArgument::new("LOGRM", &logrm.0))?;
-
- let cmdq = Cmdq::new(dev)?;
-
- let rmargs = CoherentAllocation::<GspArgumentsCached>::alloc_coherent(
- dev,
- 1,
- GFP_KERNEL | __GFP_ZERO,
- )?;
- dma_write!(rmargs[0] = fw::GspArgumentsCached::new(&cmdq))?;
- dma_write!(libos[3] = LibosMemoryRegionInitArgument::new("RMARGS", &rmargs))?;
-
- Ok(try_pin_init!(Self {
- libos,
- loginit,
- logintr,
- logrm,
- rmargs,
- cmdq,
- }))
+ pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error> + '_ {
+ pin_init::pin_init_scope(move || {
+ let dev = pdev.as_ref();
+ let libos = CoherentAllocation::<LibosMemoryRegionInitArgument>::alloc_coherent(
+ dev,
+ GSP_PAGE_SIZE / size_of::<LibosMemoryRegionInitArgument>(),
+ GFP_KERNEL | __GFP_ZERO,
+ )?;
+
+ // Initialise the logging structures. The OpenRM equivalents are in:
+ // _kgspInitLibosLoggingStructures (allocates memory for buffers)
+ // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
+ let loginit = LogBuffer::new(dev)?;
+ dma_write!(libos[0] = LibosMemoryRegionInitArgument::new("LOGINIT", &loginit.0))?;
+
+ let logintr = LogBuffer::new(dev)?;
+ dma_write!(libos[1] = LibosMemoryRegionInitArgument::new("LOGINTR", &logintr.0))?;
+
+ let logrm = LogBuffer::new(dev)?;
+ dma_write!(libos[2] = LibosMemoryRegionInitArgument::new("LOGRM", &logrm.0))?;
+
+ let cmdq = Cmdq::new(dev)?;
+
+ let rmargs = CoherentAllocation::<GspArgumentsCached>::alloc_coherent(
+ dev,
+ 1,
+ GFP_KERNEL | __GFP_ZERO,
+ )?;
+ dma_write!(rmargs[0] = fw::GspArgumentsCached::new(&cmdq))?;
+ dma_write!(libos[3] = LibosMemoryRegionInitArgument::new("RMARGS", &rmargs))?;
+
+ Ok(try_pin_init!(Self {
+ libos,
+ loginit,
+ logintr,
+ logrm,
+ rmargs,
+ cmdq,
+ }))
+ })
}
}
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] gpu: nova-core: gsp: move appropriate code into pin initializer
2025-12-18 15:50 [PATCH 0/4] nova-core Improve pin initializer code Danilo Krummrich
` (2 preceding siblings ...)
2025-12-18 15:50 ` [PATCH 3/4] gpu: nova-core: gsp: get rid of redundant Result in Gsp::new() Danilo Krummrich
@ 2025-12-18 15:50 ` Danilo Krummrich
2025-12-18 21:06 ` [PATCH 0/4] nova-core Improve pin initializer code Joel Fernandes
2025-12-29 17:14 ` Danilo Krummrich
5 siblings, 0 replies; 7+ messages in thread
From: Danilo Krummrich @ 2025-12-18 15:50 UTC (permalink / raw)
To: acourbot, jhubbard, apopple, joelagnelf, aliceryhl, lossin
Cc: nouveau, dri-devel, rust-for-linux, linux-kernel,
Danilo Krummrich
Relocate the code that technically fits in the pin initializer into the
initializer itself.
While, thanks to pin_init_scope(), it is also possible to keep it as is,
moving appropriate code into the initializer has the advantage that it
structures the dependencies of fields naturally.
For instance, intermediate data that is only needed for a single field
goes into the initializer block of this field, making it obvious that it
is not needed by anything else.
On the other hand, intermediate data that is needed for multiple fields
to initialize remains above the initializer, naturally indicating that
it is needed my multiple fields.
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
---
drivers/gpu/nova-core/gsp.rs | 61 +++++++++++++++++-------------------
1 file changed, 28 insertions(+), 33 deletions(-)
diff --git a/drivers/gpu/nova-core/gsp.rs b/drivers/gpu/nova-core/gsp.rs
index 8bc86e1bcac5..766fd9905358 100644
--- a/drivers/gpu/nova-core/gsp.rs
+++ b/drivers/gpu/nova-core/gsp.rs
@@ -122,41 +122,36 @@ impl Gsp {
pub(crate) fn new(pdev: &pci::Device<device::Bound>) -> impl PinInit<Self, Error> + '_ {
pin_init::pin_init_scope(move || {
let dev = pdev.as_ref();
- let libos = CoherentAllocation::<LibosMemoryRegionInitArgument>::alloc_coherent(
- dev,
- GSP_PAGE_SIZE / size_of::<LibosMemoryRegionInitArgument>(),
- GFP_KERNEL | __GFP_ZERO,
- )?;
-
- // Initialise the logging structures. The OpenRM equivalents are in:
- // _kgspInitLibosLoggingStructures (allocates memory for buffers)
- // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
- let loginit = LogBuffer::new(dev)?;
- dma_write!(libos[0] = LibosMemoryRegionInitArgument::new("LOGINIT", &loginit.0))?;
-
- let logintr = LogBuffer::new(dev)?;
- dma_write!(libos[1] = LibosMemoryRegionInitArgument::new("LOGINTR", &logintr.0))?;
-
- let logrm = LogBuffer::new(dev)?;
- dma_write!(libos[2] = LibosMemoryRegionInitArgument::new("LOGRM", &logrm.0))?;
-
- let cmdq = Cmdq::new(dev)?;
-
- let rmargs = CoherentAllocation::<GspArgumentsCached>::alloc_coherent(
- dev,
- 1,
- GFP_KERNEL | __GFP_ZERO,
- )?;
- dma_write!(rmargs[0] = fw::GspArgumentsCached::new(&cmdq))?;
- dma_write!(libos[3] = LibosMemoryRegionInitArgument::new("RMARGS", &rmargs))?;
Ok(try_pin_init!(Self {
- libos,
- loginit,
- logintr,
- logrm,
- rmargs,
- cmdq,
+ libos: CoherentAllocation::<LibosMemoryRegionInitArgument>::alloc_coherent(
+ dev,
+ GSP_PAGE_SIZE / size_of::<LibosMemoryRegionInitArgument>(),
+ GFP_KERNEL | __GFP_ZERO,
+ )?,
+ loginit: LogBuffer::new(dev)?,
+ logintr: LogBuffer::new(dev)?,
+ logrm: LogBuffer::new(dev)?,
+ cmdq: Cmdq::new(dev)?,
+ rmargs: CoherentAllocation::<GspArgumentsCached>::alloc_coherent(
+ dev,
+ 1,
+ GFP_KERNEL | __GFP_ZERO,
+ )?,
+ _: {
+ // Initialise the logging structures. The OpenRM equivalents are in:
+ // _kgspInitLibosLoggingStructures (allocates memory for buffers)
+ // kgspSetupLibosInitArgs_IMPL (creates pLibosInitArgs[] array)
+ dma_write!(
+ libos[0] = LibosMemoryRegionInitArgument::new("LOGINIT", &loginit.0)
+ )?;
+ dma_write!(
+ libos[1] = LibosMemoryRegionInitArgument::new("LOGINTR", &logintr.0)
+ )?;
+ dma_write!(libos[2] = LibosMemoryRegionInitArgument::new("LOGRM", &logrm.0))?;
+ dma_write!(rmargs[0] = fw::GspArgumentsCached::new(cmdq))?;
+ dma_write!(libos[3] = LibosMemoryRegionInitArgument::new("RMARGS", rmargs))?;
+ },
}))
})
}
--
2.52.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] nova-core Improve pin initializer code
2025-12-18 15:50 [PATCH 0/4] nova-core Improve pin initializer code Danilo Krummrich
` (3 preceding siblings ...)
2025-12-18 15:50 ` [PATCH 4/4] gpu: nova-core: gsp: move appropriate code into pin initializer Danilo Krummrich
@ 2025-12-18 21:06 ` Joel Fernandes
2025-12-29 17:14 ` Danilo Krummrich
5 siblings, 0 replies; 7+ messages in thread
From: Joel Fernandes @ 2025-12-18 21:06 UTC (permalink / raw)
To: Danilo Krummrich
Cc: Alexandre Courbot, John Hubbard, Alistair Popple,
aliceryhl@google.com, lossin@kernel.org,
nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
Danilo Krummrich
> On Dec 18, 2025, at 10:52 AM, Danilo Krummrich <dakr@kernel.org> wrote:
>
> This is a minor series to improve some of the pin initializer code to:
>
> 1. Reduce redundancy caused by Result<impl PinInit<T, Error>> return
> values with pin_init_scope().
>
> 2. Relocate code that technically fits in the pin initializer into the
> initializer itself.
>
> While, thanks to pin_init_scope(), it is also possible to keep it as is,
> moving appropriate code into the initializer has the advantage that it
> structures the dependencies of fields naturally.
>
> For instance, intermediate data that is only needed for a single field goes
> into the initializer block of this field, making it obvious that it is not
> needed by anything else.
>
> On the other hand, intermediate data that is needed for multiple fields to
> initialize remains above the initializer, naturally indicating that it is
> needed my multiple fields.
>
> Danilo Krummrich (4):
> gpu: nova-core: fw: get rid of redundant Result in GspFirmware::new()
> gpu: nova-core: fw: move appropriate code into pin initializer
> gpu: nova-core: gsp: get rid of redundant Result in Gsp::new()
> gpu: nova-core: gsp: move appropriate code into pin initializer
Reviewed-by: Joel Fernandes <joelagnelf@nvidia.com>
thanks,
- Joel
>
> drivers/gpu/nova-core/firmware/gsp.rs | 134 +++++++++++++-------------
> drivers/gpu/nova-core/gpu.rs | 2 +-
> drivers/gpu/nova-core/gsp.rs | 73 +++++++-------
> drivers/gpu/nova-core/gsp/boot.rs | 5 +-
> 4 files changed, 106 insertions(+), 108 deletions(-)
>
>
> base-commit: 97cf6bc0abd381fd84e5d8e978322a62a58fb00e
> --
> 2.52.0
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] nova-core Improve pin initializer code
2025-12-18 15:50 [PATCH 0/4] nova-core Improve pin initializer code Danilo Krummrich
` (4 preceding siblings ...)
2025-12-18 21:06 ` [PATCH 0/4] nova-core Improve pin initializer code Joel Fernandes
@ 2025-12-29 17:14 ` Danilo Krummrich
5 siblings, 0 replies; 7+ messages in thread
From: Danilo Krummrich @ 2025-12-29 17:14 UTC (permalink / raw)
To: acourbot, jhubbard, apopple, joelagnelf, aliceryhl, lossin
Cc: nouveau, dri-devel, rust-for-linux, linux-kernel
On Thu Dec 18, 2025 at 4:50 PM CET, Danilo Krummrich wrote:
> This is a minor series to improve some of the pin initializer code to:
>
> 1. Reduce redundancy caused by Result<impl PinInit<T, Error>> return
> values with pin_init_scope().
>
> 2. Relocate code that technically fits in the pin initializer into the
> initializer itself.
Applied to drm-rust-next, thanks!
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-12-29 17:14 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-18 15:50 [PATCH 0/4] nova-core Improve pin initializer code Danilo Krummrich
2025-12-18 15:50 ` [PATCH 1/4] gpu: nova-core: fw: get rid of redundant Result in GspFirmware::new() Danilo Krummrich
2025-12-18 15:50 ` [PATCH 2/4] gpu: nova-core: fw: move appropriate code into pin initializer Danilo Krummrich
2025-12-18 15:50 ` [PATCH 3/4] gpu: nova-core: gsp: get rid of redundant Result in Gsp::new() Danilo Krummrich
2025-12-18 15:50 ` [PATCH 4/4] gpu: nova-core: gsp: move appropriate code into pin initializer Danilo Krummrich
2025-12-18 21:06 ` [PATCH 0/4] nova-core Improve pin initializer code Joel Fernandes
2025-12-29 17:14 ` Danilo Krummrich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).