[RFC PATCH 0/5] lib: utils: add a PMA framework and set PMA regions from the DT
Randolph Lin
randolph at andestech.com
Fri Nov 13 01:32:07 PST 2026
SoCs from several vendors use Andes cores with programmable physical
memory attributes (PMA), and each sets its boot-time regions in its own
platform code: RZ/Five from Renesas and MT2824 from Metanoia from C
tables, and QiLai from Andes with andes_sbi_set_pma() calls. So each new
board needs its own platform file. This series adds a small PMA
framework in lib/utils/pma, and lets a board describe the regions in a
"riscv,pma-regions" DT node instead. The Andes AE350 platform is the
first user.
Patch 1 adds the framework: a platform registers a PMA device, the cold
boot hart adds the regions, and every hart sets them. Patch 2 parses the
DT node and calls the framework from generic_final_init(). Patch 3 adds
a PMA device for Andes PPMA, and patch 4 registers it on AE350. Patch 5
documents the DT node.
The attributes reuse the encoding of the flags in the
"riscv,physical-memory-regions" DT binding that Samuel Holland proposed
for Linux [1], limited to the memory type bits. Each vendor encodes PMAs
differently, so the PMA device maps the attributes to its own format and
rejects the ones it cannot set. Bits 19:16, which that encoding does not
use, choose among the memory types that a device offers for the same
attributes: bufferable, write-through, and the allocation. With them,
the Andes PPMA device can select every MTYP of pmaxcfg.
I tested the framework on QEMU virt, with 4 harts and a test PMA device:
every hart sets the regions, and an invalid, overlapping or extra region
stops the boot.
Open questions:
1. Should the framework live in lib/utils, or stay in the Andes
platform code until another vendor needs a PMA device?
2. The DT node uses the "riscv,pma-regions" compatible, but no RISC-V
specification defines it. Would "opensbi,pma-regions" be better?
3. "attr" reuses bits 15:8 of the flags in the proposed
"riscv,physical-memory-regions" binding [1], and adds bits 19:16 for
bufferable, write-through and allocation. Is it fine to reuse an
encoding that Linux has not merged yet, and to extend it?
[1] https://lore.kernel.org/all/20251113014656.2605447-20-samuel.holland@sifive.com/
Randolph Lin (5):
lib: utils: add a PMA framework
lib: utils/pma: set PMA regions from the device tree
platform: generic/andes: add a PMA device for PPMA
platform: generic/andes: ae350: register the Andes PMA device
docs: describe the PMA regions DT node
docs/opensbi_config.md | 85 +++++++++++
docs/platform/andes-ae350.md | 39 +++++
include/sbi_utils/pma/fdt_pma.h | 33 ++++
include/sbi_utils/pma/pma.h | 119 +++++++++++++++
lib/utils/Kconfig | 2 +
lib/utils/pma/Kconfig | 15 ++
lib/utils/pma/fdt_pma.c | 167 +++++++++++++++++++++
lib/utils/pma/objects.mk | 9 ++
lib/utils/pma/pma.c | 80 ++++++++++
platform/generic/andes/Kconfig | 1 +
platform/generic/andes/ae350.c | 4 +-
platform/generic/andes/andes_pma.c | 111 ++++++++++++++
platform/generic/configs/defconfig | 1 +
platform/generic/include/andes/andes_pma.h | 11 ++
platform/generic/platform.c | 6 +
15 files changed, 682 insertions(+), 1 deletion(-)
create mode 100644 include/sbi_utils/pma/fdt_pma.h
create mode 100644 include/sbi_utils/pma/pma.h
create mode 100644 lib/utils/pma/Kconfig
create mode 100644 lib/utils/pma/fdt_pma.c
create mode 100644 lib/utils/pma/objects.mk
create mode 100644 lib/utils/pma/pma.c
base-commit: 332798211e7232da60158b0545b23c61b5338516
--
2.34.1
More information about the opensbi
mailing list