Skip to content

Commit 15a4bb8

Browse files
author
Danilo Krummrich
committed
gpu: nova-core: use sized array for GSP log buffers
Switch LogBuffer from Coherent<[u8]> (unsized) to Coherent<[u8; LOG_BUFFER_SIZE]> (sized). The buffer size is a compile-time constant (RM_LOG_BUFFER_NUM_PAGES * GSP_PAGE_SIZE), so a fixed-size array is more precise and avoids the need for the runtime length parameter of zeroed_slice(). Acked-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alexandre Courbot <acourbot@nvidia.com> Link: https://patch.msgid.link/20260325003921.3420-3-dakr@kernel.org Signed-off-by: Danilo Krummrich <dakr@kernel.org>
1 parent d1619a4 commit 15a4bb8

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

drivers/gpu/nova-core/gsp.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub(crate) const GSP_PAGE_SIZE: usize = 1 << GSP_PAGE_SHIFT;
4242

4343
/// Number of GSP pages to use in a RM log buffer.
4444
const RM_LOG_BUFFER_NUM_PAGES: usize = 0x10;
45+
const LOG_BUFFER_SIZE: usize = RM_LOG_BUFFER_NUM_PAGES * GSP_PAGE_SIZE;
4546

4647
/// Array of page table entries, as understood by the GSP bootloader.
4748
#[repr(C)]
@@ -77,24 +78,19 @@ impl<const NUM_PAGES: usize> PteArray<NUM_PAGES> {
7778
/// then pp points to index into the buffer where the next logging entry will
7879
/// be written. Therefore, the logging data is valid if:
7980
/// 1 <= pp < sizeof(buffer)/sizeof(u64)
80-
struct LogBuffer(Coherent<[u8]>);
81+
struct LogBuffer(Coherent<[u8; LOG_BUFFER_SIZE]>);
8182

8283
impl LogBuffer {
8384
/// Creates a new `LogBuffer` mapped on `dev`.
8485
fn new(dev: &device::Device<device::Bound>) -> Result<Self> {
85-
const NUM_PAGES: usize = RM_LOG_BUFFER_NUM_PAGES;
86-
87-
let obj = Self(Coherent::<u8>::zeroed_slice(
88-
dev,
89-
NUM_PAGES * GSP_PAGE_SIZE,
90-
GFP_KERNEL,
91-
)?);
86+
let obj = Self(Coherent::zeroed(dev, GFP_KERNEL)?);
9287

9388
let start_addr = obj.0.dma_handle();
9489

9590
// SAFETY: `obj` has just been created and we are its sole user.
96-
let pte_region =
97-
unsafe { &mut obj.0.as_mut()[size_of::<u64>()..][..NUM_PAGES * size_of::<u64>()] };
91+
let pte_region = unsafe {
92+
&mut obj.0.as_mut()[size_of::<u64>()..][..RM_LOG_BUFFER_NUM_PAGES * size_of::<u64>()]
93+
};
9894

9995
// Write values one by one to avoid an on-stack instance of `PteArray`.
10096
for (i, chunk) in pte_region.chunks_exact_mut(size_of::<u64>()).enumerate() {

0 commit comments

Comments
 (0)