From 043045cd6eb318451948f5fba7f9ef9e585a184f Mon Sep 17 00:00:00 2001 From: Dhaval Date: Wed, 5 Jun 2024 10:00:32 +0530 Subject: MdePkg: Add reserved mem fdt helpers Devicetree defines a short hand way of defining reserved memory ranges. Add APIs to access such nodes Signed-off-by: Dhaval Sharma --- MdePkg/Include/Library/FdtLib.h | 34 +++++++++++++++++++++++++++++++ MdePkg/Library/BaseFdtLib/FdtLib.c | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) (limited to 'MdePkg') diff --git a/MdePkg/Include/Library/FdtLib.h b/MdePkg/Include/Library/FdtLib.h index 89aa1e00f9..ffff40d8fe 100644 --- a/MdePkg/Include/Library/FdtLib.h +++ b/MdePkg/Include/Library/FdtLib.h @@ -247,6 +247,40 @@ FdtSubnodeOffsetNameLen ( IN INT32 NameLength ); +/** + Returns number of reserved ranges. + + @param[in] Fdt The pointer to FDT blob. + + @return The number of reserved ranges. + +**/ +INTN +EFIAPI +FdtNumRsv ( + IN CONST VOID *Fdt + ); + +/** + Returns reserved ranges. + + @param[in] *Fdt The pointer to FDT blob. + @param[in] Index Reserved entry index in the table. + @param[out] Addr Address returned + @param[out] *Size Pointer to size of the address range + + @return Returns reserved range. + +**/ +INTN +EFIAPI +FdtGetMemRsv ( + IN CONST VOID *Fdt, + IN INTN Index, + OUT UINT64 *Addr, + OUT UINT64 *Size + ); + /** Returns a offset of first node which includes the given property name and value. diff --git a/MdePkg/Library/BaseFdtLib/FdtLib.c b/MdePkg/Library/BaseFdtLib/FdtLib.c index 9b1ceac551..5ff06111b7 100644 --- a/MdePkg/Library/BaseFdtLib/FdtLib.c +++ b/MdePkg/Library/BaseFdtLib/FdtLib.c @@ -7,6 +7,7 @@ **/ #include +#include /** Convert UINT16 data of the FDT blob to little-endian @@ -205,6 +206,46 @@ FdtNextSubnode ( return fdt_next_subnode (Fdt, Offset); } +/** + Returns number of reserved mem nodes + + @param[in] Fdt The pointer to FDT blob. + + @return total reserved mem nodes + +**/ +INTN +EFIAPI +FdtNumRsv ( + IN CONST VOID *Fdt + ) +{ + return fdt_num_mem_rsv (Fdt); +} + +/** + Returns reserved ranges. + + @param[in] *Fdt The pointer to FDT blob. + @param[in] Index Reserved entry index in the table. + @param[out] Addr Address returned + @param[out] *Size Pointer to size of the address range + + @return Returns reserved range. + +**/ +INTN +EFIAPI +FdtGetMemRsv ( + IN CONST VOID *Fdt, + IN INTN Index, + OUT EFI_PHYSICAL_ADDRESS *Addr, + OUT UINT64 *Size + ) +{ + return fdt_get_mem_rsv (Fdt, Index, Addr, Size); +} + /** Returns a offset of first node which includes the given name. -- cgit v1.2.3