123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711 |
- /*++
- Copyright (c) 2013 Minoca Corp. All Rights Reserved
- Module Name:
- memory.h
- Abstract:
- This header contains definitions for UEFI core memory services.
- Author:
- Evan Green 27-Feb-2014
- --*/
- //
- // ------------------------------------------------------------------- Includes
- //
- //
- // ---------------------------------------------------------------- Definitions
- //
- //
- // Define the expansion size of pool and memory descriptor allocations.
- //
- #define EFI_MEMORY_EXPANSION_SIZE EFI_PAGE_SIZE
- //
- // ------------------------------------------------------ Data Type Definitions
- //
- //
- // -------------------------------------------------------------------- Globals
- //
- extern EFI_LOCK EfiMemoryLock;
- //
- // -------------------------------------------------------- Function Prototypes
- //
- EFIAPI
- EFI_STATUS
- EfiCoreAllocatePages (
- EFI_ALLOCATE_TYPE Type,
- EFI_MEMORY_TYPE MemoryType,
- UINTN Pages,
- EFI_PHYSICAL_ADDRESS *Memory
- );
- /*++
- Routine Description:
- This routine allocates memory pages from the system.
- Arguments:
- Type - Supplies the allocation strategy to use.
- MemoryType - Supplies the memory type of the allocation.
- Pages - Supplies the number of contiguous EFI_PAGE_SIZE pages.
- Memory - Supplies a pointer that on input contains a physical address whose
- use depends on the allocation strategy. On output, the physical address
- of the allocation will be returned.
- Return Value:
- EFI_SUCCESS on success.
- EFI_INVALID_PARAMETER if the Type or MemoryType are invalid, or Memory is
- NULL.
- EFI_OUT_OF_RESOURCES if the pages could not be allocated.
- EFI_NOT_FOUND if the requested pages could not be found.
- --*/
- EFIAPI
- EFI_STATUS
- EfiCoreFreePages (
- EFI_PHYSICAL_ADDRESS Memory,
- UINTN Pages
- );
- /*++
- Routine Description:
- This routine frees memory pages back to the system.
- Arguments:
- Memory - Supplies the base physical address of the allocation to free.
- Pages - Supplies the number of pages to free.
- Return Value:
- EFI_SUCCESS on success.
- EFI_INVALID_PARAMETER if the memory is not page aligned or is invalid.
- EFI_NOT_FOUND if the requested pages were not allocated.
- --*/
- EFIAPI
- EFI_STATUS
- EfiCoreGetMemoryMap (
- UINTN *MemoryMapSize,
- EFI_MEMORY_DESCRIPTOR *MemoryMap,
- UINTN *MapKey,
- UINTN *DescriptorSize,
- UINT32 *DescriptorVersion
- );
- /*++
- Routine Description:
- This routine returns the current memory map.
- Arguments:
- MemoryMapSize - Supplies a pointer to the size, in bytes, of the memory
- map buffer. On input, this is the size of the buffer allocated by the
- caller. On output, this is the size of the buffer returned by the
- firmware if the buffer was large enough, or the size of the buffer
- needed if the buffer was too small.
- MemoryMap - Supplies a pointer to a caller-allocated buffer where the
- memory map will be written on success.
- MapKey - Supplies a pointer where the firmware returns the map key.
- DescriptorSize - Supplies a pointer where the firmware returns the size of
- the EFI_MEMORY_DESCRIPTOR structure.
- DescriptorVersion - Supplies a pointer where the firmware returns the
- version number associated with the EFI_MEMORY_DESCRIPTOR structure.
- Return Value:
- EFI_SUCCESS on success.
- EFI_BUFFER_TOO_SMALL if the supplied buffer was too small. The size needed
- is returned in the size parameter.
- EFI_INVALID_PARAMETER if the supplied size or memory map pointers are NULL.
- --*/
- VOID *
- EfiCoreAllocatePoolPages (
- EFI_MEMORY_TYPE PoolType,
- UINTN PageCount,
- UINTN Alignment
- );
- /*++
- Routine Description:
- This routine allocates pages to back pool allocations and memory map
- descriptors.
- Arguments:
- PoolType - Supplies the memory type of the allocation.
- PageCount - Supplies the number of pages to allocate.
- Alignment - Supplies the required alignment.
- Return Value:
- Returns a pointer to the allocated memory on success.
- NULL on allocation failure.
- --*/
- VOID
- EfiCoreFreePoolPages (
- EFI_PHYSICAL_ADDRESS Memory,
- UINTN PageCount
- );
- /*++
- Routine Description:
- This routine frees pages allocated for pool or descriptor.
- Arguments:
- Memory - Supplies the address of the allocation.
- PageCount - Supplies the number of pages to free.
- Return Value:
- None.
- --*/
- EFI_STATUS
- EfiCoreInitializeMemoryServices (
- VOID *FirmwareLowestAddress,
- UINTN FirmwareSize,
- VOID *StackBase,
- UINTN StackSize
- );
- /*++
- Routine Description:
- This routine initializes core UEFI memory services.
- Arguments:
- FirmwareLowestAddress - Supplies the lowest address where the firmware was
- loaded into memory.
- FirmwareSize - Supplies the size of the firmware image in memory, in bytes.
- StackBase - Supplies the base (lowest) address of the stack.
- StackSize - Supplies the size in bytes of the stack. This should be at
- least 0x4000 bytes (16kB).
- Return Value:
- EFI status code.
- --*/
- EFI_STATUS
- EfiCoreTerminateMemoryServices (
- UINTN MapKey
- );
- /*++
- Routine Description:
- This routine terminates memory services.
- Arguments:
- MapKey - Supplies the map key reported by the boot application. This is
- checked against the current map key to ensure the boot application has
- an up to date view of the world.
- Return Value:
- EFI_SUCCESS on success.
- EFI_INVALID_PARAMETER if the map key is not valid or the memory map is
- not consistent.
- --*/
- EFIAPI
- VOID
- EfiCoreEmptyCallbackFunction (
- EFI_EVENT Event,
- VOID *Context
- );
- /*++
- Routine Description:
- This routine does nothing but return. It conforms to the event notification
- function prototype.
- Arguments:
- Event - Supplies an unused event.
- Context - Supplies an unused context pointer.
- Return Value:
- None.
- --*/
- EFIAPI
- VOID
- EfiCoreCopyMemory (
- VOID *Destination,
- VOID *Source,
- UINTN Length
- );
- /*++
- Routine Description:
- This routine copies the contents of one buffer to another.
- Arguments:
- Destination - Supplies a pointer to the destination of the copy.
- Source - Supplies a pointer to the source of the copy.
- Length - Supplies the number of bytes to copy.
- Return Value:
- None.
- --*/
- EFIAPI
- VOID
- EfiCoreSetMemory (
- VOID *Buffer,
- UINTN Size,
- UINT8 Value
- );
- /*++
- Routine Description:
- This routine fills a buffer with a specified value.
- Arguments:
- Buffer - Supplies a pointer to the buffer to fill.
- Size - Supplies the size of the buffer in bytes.
- Value - Supplies the value to fill the buffer with.
- Return Value:
- None.
- --*/
- INTN
- EfiCoreCompareMemory (
- VOID *FirstBuffer,
- VOID *SecondBuffer,
- UINTN Length
- );
- /*++
- Routine Description:
- This routine compares the contents of two buffers for equality.
- Arguments:
- FirstBuffer - Supplies a pointer to the first buffer to compare.
- SecondBuffer - Supplies a pointer to the second buffer to compare.
- Length - Supplies the number of bytes to compare.
- Return Value:
- 0 if the buffers are identical.
- Returns the first mismatched byte as
- First[MismatchIndex] - Second[MismatchIndex].
- --*/
- BOOLEAN
- EfiCoreCompareGuids (
- EFI_GUID *FirstGuid,
- EFI_GUID *SecondGuid
- );
- /*++
- Routine Description:
- This routine compares two GUIDs.
- Arguments:
- FirstGuid - Supplies a pointer to the first GUID.
- SecondGuid - Supplies a pointer to the second GUID.
- Return Value:
- TRUE if the GUIDs are equal.
- FALSE if the GUIDs are different.
- --*/
- VOID *
- EfiCoreAllocateBootPool (
- UINTN Size
- );
- /*++
- Routine Description:
- This routine allocates pool from boot services data.
- Arguments:
- Size - Supplies the size of the allocation in bytes.
- Return Value:
- Returns a pointer to the allocation on success.
- NULL on allocation failure.
- --*/
- VOID *
- EfiCoreAllocateRuntimePool (
- UINTN Size
- );
- /*++
- Routine Description:
- This routine allocates pool from runtime services data.
- Arguments:
- Size - Supplies the size of the allocation in bytes.
- Return Value:
- Returns a pointer to the allocation on success.
- NULL on allocation failure.
- --*/
- INTN
- EfiCoreFindHighBitSet64 (
- UINT64 Value
- );
- /*++
- Routine Description:
- This routine returns the bit position of the highest bit set in a 64-bit
- value.
- Arguments:
- Value - Supplies the input value.
- Return Value:
- Returns the index of the highest bit set, between 0 and 63. If the value is
- zero, then -1 is returned.
- --*/
- INTN
- EfiCoreFindHighBitSet32 (
- UINT32 Value
- );
- /*++
- Routine Description:
- This routine returns the bit position of the highest bit set in a 32-bit
- value.
- Arguments:
- Value - Supplies the input value.
- Return Value:
- Returns the index of the highest bit set, between 0 and 31. If the value is
- zero, then -1 is returned.
- --*/
- VOID
- EfiCoreCalculateTableCrc32 (
- EFI_TABLE_HEADER *Header
- );
- /*++
- Routine Description:
- This routine recalculates the CRC32 of a given EFI table.
- Arguments:
- Header - Supplies a pointer to the header. The size member will be used to
- determine the size of the entire table.
- Return Value:
- None. The CRC is set in the header.
- --*/
- EFIAPI
- EFI_EVENT
- EfiCoreCreateProtocolNotifyEvent (
- EFI_GUID *ProtocolGuid,
- EFI_TPL NotifyTpl,
- EFI_EVENT_NOTIFY NotifyFunction,
- VOID *NotifyContext,
- VOID **Registration
- );
- /*++
- Routine Description:
- This routine creates an event, then registers that event to be notified
- whenever the given protocol appears. Finally, it signals the event so that
- any pre-existing protocols will be found.
- Arguments:
- ProtocolGuid - Supplies a pointer to the GUID of the protocol to watch.
- NotifyTpl - Supplies the Task Priority Level of the callback function.
- NotifyFunction - Supplies a pointer to the function to call when a new
- protocol with the given GUID crops up.
- NotifyContext - Supplies a pointer to pass into the notify function.
- Registration - Supplies a pointer where the registration token for the
- event will be returned.
- Return Value:
- Returns the notification event that was created.
- NULL on failure.
- --*/
- UINTN
- EfiCoreStringLength (
- CHAR16 *String
- );
- /*++
- Routine Description:
- This routine returns the length of the given string, in characters (not
- bytes).
- Arguments:
- String - Supplies a pointer to the string.
- Return Value:
- Returns the number of characters in the string.
- --*/
- VOID
- EfiCoreCopyString (
- CHAR16 *Destination,
- CHAR16 *Source
- );
- /*++
- Routine Description:
- This routine copies one string over to another buffer.
- Arguments:
- Destination - Supplies a pointer to the destination buffer where the
- string will be copied to.
- Source - Supplies a pointer to the string to copy.
- Return Value:
- None.
- --*/
- EFI_TPL
- EfiCoreGetCurrentTpl (
- VOID
- );
- /*++
- Routine Description:
- This routine returns the current TPL.
- Arguments:
- None.
- Return Value:
- Returns the current TPL.
- --*/
- EFI_STATUS
- EfiCoreInitializePool (
- VOID
- );
- /*++
- Routine Description:
- This routine initializes EFI core pool services.
- Arguments:
- None.
- Return Value:
- EFI status code.
- --*/
- EFIAPI
- EFI_STATUS
- EfiCoreAllocatePool (
- EFI_MEMORY_TYPE PoolType,
- UINTN Size,
- VOID **Buffer
- );
- /*++
- Routine Description:
- This routine allocates memory from the heap.
- Arguments:
- PoolType - Supplies the type of pool to allocate.
- Size - Supplies the number of bytes to allocate from the pool.
- Buffer - Supplies a pointer where a pointer to the allocated buffer will
- be returned on success.
- Return Value:
- EFI_SUCCESS on success.
- EFI_OUT_OF_RESOURCES if memory could not be allocated.
- EFI_INVALID_PARAMETER if the pool type was invalid or the buffer is NULL.
- --*/
- EFIAPI
- EFI_STATUS
- EfiCoreFreePool (
- VOID *Buffer
- );
- /*++
- Routine Description:
- This routine frees heap allocated memory.
- Arguments:
- Buffer - Supplies a pointer to the buffer to free.
- Return Value:
- EFI_SUCCESS on success.
- EFI_INVALID_PARAMETER if the buffer was invalid.
- --*/
|