From 931fa9c01d9fb191635f3b0435cb58b41f2e96f1 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Tue, 18 Nov 2025 08:30:34 +0000 Subject: [PATCH] memlayout: Introduce PRERAM and POSTRAM DMA coherent regions Refactor the DMA coherent memory region definition to support stage-specific allocations. In some boot flows, it is necessary to define separate DMA coherent buffers for the early boot stage (e.g., romstage/bootblock) and the later stage (ramstage). It allows the firmware to use only the memory it needs, where it needs it, and prevents small-scale memory constraints from crippling the overall boot flow. The arch-specific, and now redundant, definitions of DMA_COHERENT are removed from arm/memlayout.h and arm64/memlayout.h. BUG=b:456953373 TEST=Able to build google/quenbi. Change-Id: Ic32d14dda6cda0f731233dd3d86f3215c6af3637 Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/90049 Reviewed-by: Kapil Porwal Reviewed-by: Julius Werner Tested-by: build bot (Jenkins) --- src/arch/arm/include/arch/memlayout.h | 5 ----- src/arch/arm64/include/arch/memlayout.h | 5 ----- src/include/memlayout.h | 26 +++++++++++++++++++++++++ src/include/symbols.h | 2 ++ 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/arch/arm/include/arch/memlayout.h b/src/arch/arm/include/arch/memlayout.h index 408443f1ba..991cbb78c6 100644 --- a/src/arch/arm/include/arch/memlayout.h +++ b/src/arch/arm/include/arch/memlayout.h @@ -22,11 +22,6 @@ REGION(stack, addr, size, 8) \ _ = ASSERT(size >= 2K, "stack should be >= 2K, see toolchain.mk"); -#define DMA_COHERENT(addr, size) \ - REGION(dma_coherent, addr, size, SUPERPAGE_SIZE) \ - _ = ASSERT(size % SUPERPAGE_SIZE == 0, \ - "DMA coherency buffer must fit exactly in full superpages!"); - #define FRAMEBUFFER(addr, size) \ REGION(framebuffer, addr, size, SUPERPAGE_SIZE) \ _ = ASSERT(size % SUPERPAGE_SIZE == 0, \ diff --git a/src/arch/arm64/include/arch/memlayout.h b/src/arch/arm64/include/arch/memlayout.h index 69e4731a12..5c648b36f0 100644 --- a/src/arch/arm64/include/arch/memlayout.h +++ b/src/arch/arm64/include/arch/memlayout.h @@ -9,11 +9,6 @@ REGION(ttb, addr, size, 4K) \ _ = ASSERT(size % 4K == 0, "TTB size must be divisible by 4K!"); -#define DMA_COHERENT(addr, size) \ - REGION(dma_coherent, addr, size, 4K) \ - _ = ASSERT(size % 4K == 0, \ - "DMA buffer should be multiple of smallest page size (4K)!"); - #define FRAMEBUFFER(addr, size) \ REGION(framebuffer, addr, size, 1M) \ _ = ASSERT(size % 1M == 0, \ diff --git a/src/include/memlayout.h b/src/include/memlayout.h index 07addbbcde..85f2959434 100644 --- a/src/include/memlayout.h +++ b/src/include/memlayout.h @@ -101,6 +101,32 @@ ALIAS_REGION(postram_cbfs_cache, cbfs_cache) #endif +/* Use either DMA_COHERENT (unified) or both (PRERAM|POSTRAM)_DMA_COHERENT */ +#define DMA_COHERENT(addr, size) \ + REGION(dma_coherent, addr, size, 4K) \ + _ = ASSERT(size % 4K == 0, \ + "DMA buffer should be multiple of smallest page size (4K)!"); \ + ALIAS_REGION(dma_coherent, preram_dma_coherent) \ + ALIAS_REGION(dma_coherent, postram_dma_coherent) + +#if ENV_ROMSTAGE_OR_BEFORE + #define PRERAM_DMA_COHERENT(addr, size) \ + REGION(preram_dma_coherent, addr, size, 4K) \ + _ = ASSERT(size % 4K == 0, \ + "Pre-RAM DMA buffer should be multiple of smallest page size (4K)!"); \ + ALIAS_REGION(preram_dma_coherent, dma_coherent) + #define POSTRAM_DMA_COHERENT(addr, size) \ + REGION(postram_dma_coherent, addr, size, 4K) +#else + #define PRERAM_DMA_COHERENT(addr, size) \ + REGION(preram_dma_coherent, addr, size, 4K) + #define POSTRAM_DMA_COHERENT(addr, size) \ + REGION(postram_dma_coherent, addr, size, 4K) \ + _ = ASSERT(size % 4K == 0, \ + "Post-RAM DMA buffer should be multiple of smallest page size (4K)!"); \ + ALIAS_REGION(postram_dma_coherent, dma_coherent) +#endif + /* Careful: 'INCLUDE ' must always be at the end of the output line */ #if ENV_DECOMPRESSOR #define DECOMPRESSOR(addr, sz) \ diff --git a/src/include/symbols.h b/src/include/symbols.h index ad8231c089..c46b6ff9ef 100644 --- a/src/include/symbols.h +++ b/src/include/symbols.h @@ -73,6 +73,8 @@ DECLARE_REGION(ramstage) DECLARE_REGION(pagetables) DECLARE_REGION(ttb) DECLARE_OPTIONAL_REGION(ttb_subtables) +DECLARE_OPTIONAL_REGION(preram_dma_coherent) +DECLARE_OPTIONAL_REGION(postram_dma_coherent) DECLARE_REGION(dma_coherent) DECLARE_REGION(soc_registers) DECLARE_OPTIONAL_REGION(framebuffer)