11. PEI Physical Memory Usage

11.1. Introduction

This section describes how physical system memory is used during PEI. The rules for using physical system memory are different before and after permanent memory registration within the PEI execution.

11.2. Before Permanent Memory Is Installed

11.2.1. Discovering Physical Memory

Before permanent memory is installed, the minimum exit condition for the PEI phase is that it has enough physical system memory to run PEIMs and the DXE IPL PPI that require permanent memory. These memory-aware PEIMs may discover and initialize additional system memory, but in doing so they must not cause loss of data in the physical system memory initialized during the earlier phase. The required amount of memory initialized and tested by PEIMs in these two phases is platform dependent.

Before permanent memory is installed, a PEIM may not assume any area of physical memory is present and initialized. During this early phase, a PEIM—usually one specific to the chipset memory controller—will initialize and test physical memory. When this PEIM has initialized and tested the physical memory, it will register the memory using the PEI Memory Service InstallPeiMemory(), which in turn will cause the PEI Foundation to create an initial Hand- Off Block (HOB) list and describe the memory. The memory that is present, initialized, and tested will reside in resource descriptor HOBs in the initial HOB list (see Volume 3 for more information). This memory allocation PEIM may also choose to allocate some of the physical memory by doing the following:

    • Creating memory allocation HOBs, as described in :ref: allocating-memory-using-guid-extension-hobs on page 227 to allocate the memory outside the region registered with InstallPeiMemory() .

  • Using the memory allocation services AllocatePages() and AllocatePool() to allocate the memory within the region registered with InstallPeiMemory() . Once permanent memory has been installed, the resources described in the HOB list are considered permanent system memory.

Once permanent memory has been installed, the resources described in the HOB list are considered permanent system memory.

11.2.2. Using Physical Memory

A PEIM that requires permanent, fixed memory allocation must schedule itself to run after EFI_PEI_PERMANENT_MEMORY_INSTALLED_PPI is installed. To schedule itself, the PEIM can do one of the following:

  • Put this PPI’s GUID into the depex of the PEIM.

  • Register for a notification.

The PEIM can then allocate Hand-Off Blocks (HOBs) and other memory using the same mechanisms described in Allocating Physical Memory.

The AllocatePool() service can be invoked at any time during the boot phase to discover temporary memory that will have its location translated, even before permanent memory is installed.

11.3. After Permanent Memory Is Installed

11.3.1. Allocating Physical Memory

After permanent memory is installed, PEIMs may allocate memory in two ways:

  • Using a GUID Extension HOB

  • Within the PEI free memory space

11.3.2. Allocating Memory Using GUID Extension HOBs

A PEIM may allocate memory for its private use by constructing a GUID Extension HOB and using the private data area defined by the GUIDed name of the HOB for private data storage. See Volume 3 for HOB construction rules.

Note

Memory region allocated with GUID Extension HOB must not overlap with the memory region registered with the PEI Foundation using IntelPeiMemory() service. The boundaries of the latter region are described by the EfiMemoryBottom and EfiMemoryTop values of the PHIT HOB. Refer to Volume 3 for a full PHIT HOB format description.

11.3.3. Allocating Memory Using PEI Service

A PEIM may allocate memory using the PEI Service AllocatePages() . Use the EFI_MEMORY_TYPE values to specify the type of memory to allocate; type EFI_MEMORY_TYPE is defined is defined in AllocatePages() in the UEFI 2.0 specification.