Skip to content

Commit

Permalink
Create ARM platform library function for customizing PEI memory (#63)
Browse files Browse the repository at this point in the history
## Description

Creates a new function in the ARM platform library to allow the platform
to customize the location of the initial PEI memory installation region.

- [ ] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [x] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

Tested against the SBSA platform with custom memory initialization
logic.

## Integration Instructions

Platforms with their own arm platform package will need to add
implementation of ArmPlatformGetPeiMemory that returns FALSE to be
unaffected.
  • Loading branch information
cfernald authored and kenlautner committed May 12, 2023
1 parent c96eb7d commit dec90b2
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
20 changes: 20 additions & 0 deletions ArmPlatformPkg/Include/Library/ArmPlatformLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,24 @@ ArmPlatformGetPlatformPpiList (
OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
);

// MU_CHANGE START: Allow platform to customize initial memory region.

/**
Checks if the platform requires a special initial EFI memory region.
@param[out] EfiMemoryBase The custom memory base, will be unchanged if FALSE is returned.
@param[out] EfiMemorySize The custom memory size, will be unchanged if FALSE is returned.
@retval TRUE A custom memory region was set.
@retval FALSE A custom memory region was not set.
**/
BOOLEAN
EFIAPI
ArmPlatformGetPeiMemory (
OUT UINTN *EfiMemoryBase,
OUT UINT32 *EfiMemorySize
);

// MU_CHANGE END

#endif
23 changes: 23 additions & 0 deletions ArmPlatformPkg/Library/ArmPlatformLibNull/ArmPlatformLibNullMem.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,26 @@ ArmPlatformGetVirtualMemoryMap (
{
ASSERT (0);
}

// MU_CHANGE START

/**
Checks if the platform requires a special initial EFI memory region.
@param[out] EfiMemoryBase The custom memory base, will be unchanged if FALSE is returned.
@param[out] EfiMemorySize The custom memory size, will be unchanged if FALSE is returned.
@retval TRUE A custom memory region was set.
@retval FALSE A custom memory region was not set.
**/
BOOLEAN
EFIAPI
ArmPlatformGetPeiMemory (
OUT UINTN *EfiMemoryBase,
OUT UINT32 *EfiMemorySize
)
{
return FALSE;
}

// MU_CHANGE END
15 changes: 12 additions & 3 deletions ArmPlatformPkg/MemoryInitPei/MemoryInitPeim.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ InitializeMemory (
UINTN FdBase;
UINTN FdTop;
UINTN UefiMemoryBase;
UINT32 UefiMemorySize; // MU_CHANGE

DEBUG ((DEBUG_LOAD | DEBUG_INFO, "Memory Init PEIM Loaded\n"));

Expand All @@ -114,8 +115,16 @@ InitializeMemory (
// Declare the UEFI memory to PEI
//

// In case the firmware has been shadowed in the System Memory
if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) {
// MU_CHANGE START: Allow platform to customize initial memory region.
UefiMemorySize = FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);
if (ArmPlatformGetPeiMemory (&UefiMemoryBase, &UefiMemorySize)) {
// Check the Firmware does not intersect with the provided memory region.
ASSERT ((FdBase < UefiMemoryBase) || (FdBase >= (UefiMemoryBase + UefiMemorySize)));
ASSERT ((FdTop <= UefiMemoryBase) || (FdTop > (UefiMemoryBase + UefiMemorySize)));
} else if ((FdBase >= SystemMemoryBase) && (FdTop <= SystemMemoryTop)) {
// In case the firmware has been shadowed in the System Memory
// MU_CHANGE END

// Check if there is enough space between the top of the system memory and the top of the
// firmware to place the UEFI memory (for PEI & DXE phases)
if (SystemMemoryTop - FdTop >= FixedPcdGet32 (PcdSystemMemoryUefiRegionSize)) {
Expand All @@ -134,7 +143,7 @@ InitializeMemory (
UefiMemoryBase = SystemMemoryTop - FixedPcdGet32 (PcdSystemMemoryUefiRegionSize);
}

Status = PeiServicesInstallPeiMemory (UefiMemoryBase, FixedPcdGet32 (PcdSystemMemoryUefiRegionSize));
Status = PeiServicesInstallPeiMemory (UefiMemoryBase, UefiMemorySize); // MU_CHANGE: Allow platform to customize initial memory region.
ASSERT_EFI_ERROR (Status);

// Initialize MMU and Memory HOBs (Resource Descriptor HOBs)
Expand Down

0 comments on commit dec90b2

Please sign in to comment.