Skip to content

Commit

Permalink
MdePkg: Add reserved mem fdt helpers
Browse files Browse the repository at this point in the history
Devicetree defines a short hand way of defining reserved memory
ranges. Add APIs to access such nodes

Signed-off-by: Dhaval Sharma <[email protected]>
  • Loading branch information
dhaval-rivos authored and mergify[bot] committed Sep 14, 2024
1 parent 099aff9 commit 043045c
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
34 changes: 34 additions & 0 deletions MdePkg/Include/Library/FdtLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
41 changes: 41 additions & 0 deletions MdePkg/Library/BaseFdtLib/FdtLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
**/

#include <libfdt/libfdt/libfdt.h>
#include <Uefi/UefiBaseType.h>

/**
Convert UINT16 data of the FDT blob to little-endian
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 043045c

Please sign in to comment.