On 02/16/16 07:26, Bhupesh Sharma wrote:
> Hi Experts,
> 
> I have a doubt regarding memory sharing between PEI and DXE phases.
> 
> Let's say I have a PEI library 'NorLib.c' and a DXE driver 'NorDxeDriver.c', 
> where
> the DXE driver uses some APIs of the PEI Library to obtain information and 
> provide
> functionalities to the upper layers.
> 
> Now, if I allocate some memory chunk (let's say for a pointer) in the PEI 
> phase,
> how can I use the same in the DXE phase (as normally the PEI pointer contents 
> become
> INVALID in the DXE phase).
> 
> Are there standard HOB mechanisms available for the same?
> 
> Thanks for the help.

In the PEI phase, use the MemoryAllocationLib API's to allocate memory.
The library class header is:

  MdePkg/Include/Library/MemoryAllocationLib.h

and the library instance you should resolve the class to is

  MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf

The memory release functions will not ASSERT(), but they are no-ops. You
can't free memory you allocate during PEI.

For each pool (i.e., non-pages) allocation, there is a size limit of a
bit less than 64KB. The reason is that such allocations are internally
handled with HOBs. If you need more memory, call AllocatePages().

The memory you allocate with AllocatePages() during PEI will survive
in-place into DXE, and it will be correctly reflected in the UEFI memmap
as well. HOBs will be migrated though, so you can't reference them from
DXE *by address*.

So, you have two options:
- If the data is small, create a vendor GUID HOB with the data in it, in
PEI. In DXE, look up the HOB by GUID.
- If the data is large, use AllocatePages() -- or one of its friends --
in PEI, then stash the address in a small vendor GUID HOB.

For the second option, a dynamic PCD could be considered as well, for
storing the base address of the allocated pages. However, storing the
address in a dynamic PCD is in a sense a bit more restricted than
storing the address in a vendor GUID HOB. For example, if you'd like to
access the allocated area in a library instance that gets linked into
the DXE core, then the dynamic PCD is a no-go.

Thanks
Laszlo
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to