microsoft/mu_feature_ffa
Publicmirrored from https://github.com/microsoft/mu_feature_ffaAvailable
FfaFeaturePkg/Library/SecurePartitionMemoryAllocationLib/SecurePartitionMemoryAllocationLib.h
166lines · modeblame
734c30acKun Qin1 years ago | 1 | /** @file |
| 2 | Support routines for memory allocation routines based on Standalone MM Core internal functions. | |
| 3 | | |
| 4 | Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> | |
| 5 | Copyright (c) 2016 - 2021, ARM Limited. All rights reserved.<BR> | |
| 6 | | |
| 7 | SPDX-License-Identifier: BSD-2-Clause-Patent | |
| 8 | | |
| 9 | **/ | |
| 10 | | |
| 11 | #ifndef SECURE_PARTITION_MEM_ALLOC_LIB_H_ | |
| 12 | #define SECURE_PARTITION_MEM_ALLOC_LIB_H_ | |
| 13 | | |
| 14 | /** | |
| 15 | Allocates pages from the memory map. | |
| 16 | | |
| 17 | @param Type The type of allocation to perform. | |
| 18 | @param MemoryType The type of memory to turn the allocated pages | |
| 19 | into. | |
| 20 | @param NumberOfPages The number of pages to allocate. | |
| 21 | @param Memory A pointer to receive the base allocated memory | |
| 22 | address. | |
| 23 | | |
| 24 | @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec. | |
| 25 | @retval EFI_NOT_FOUND Could not allocate pages match the requirement. | |
| 26 | @retval EFI_OUT_OF_RESOURCES No enough pages to allocate. | |
| 27 | @retval EFI_SUCCESS Pages successfully allocated. | |
| 28 | | |
| 29 | **/ | |
| 30 | EFI_STATUS | |
| 31 | EFIAPI | |
| 32 | MmAllocatePages ( | |
| 33 | IN EFI_ALLOCATE_TYPE Type, | |
| 34 | IN EFI_MEMORY_TYPE MemoryType, | |
| 35 | IN UINTN NumberOfPages, | |
| 36 | OUT EFI_PHYSICAL_ADDRESS *Memory | |
| 37 | ); | |
| 38 | | |
| 39 | /** | |
| 40 | Frees previous allocated pages. | |
| 41 | | |
| 42 | @param Memory Base address of memory being freed. | |
| 43 | @param NumberOfPages The number of pages to free. | |
| 44 | | |
| 45 | @retval EFI_NOT_FOUND Could not find the entry that covers the range. | |
| 46 | @retval EFI_INVALID_PARAMETER Address not aligned. | |
| 47 | @return EFI_SUCCESS Pages successfully freed. | |
| 48 | | |
| 49 | **/ | |
| 50 | EFI_STATUS | |
| 51 | EFIAPI | |
| 52 | MmFreePages ( | |
| 53 | IN EFI_PHYSICAL_ADDRESS Memory, | |
| 54 | IN UINTN NumberOfPages | |
| 55 | ); | |
| 56 | | |
| 57 | /** | |
| 58 | Allocate pool of a particular type. | |
| 59 | | |
| 60 | @param PoolType Type of pool to allocate. | |
| 61 | @param Size The amount of pool to allocate. | |
| 62 | @param Buffer The address to return a pointer to the allocated | |
| 63 | pool. | |
| 64 | | |
| 65 | @retval EFI_INVALID_PARAMETER PoolType not valid. | |
| 66 | @retval EFI_OUT_OF_RESOURCES Size exceeds max pool size or allocation failed. | |
| 67 | @retval EFI_SUCCESS Pool successfully allocated. | |
| 68 | | |
| 69 | **/ | |
| 70 | EFI_STATUS | |
| 71 | EFIAPI | |
| 72 | MmAllocatePool ( | |
| 73 | IN EFI_MEMORY_TYPE PoolType, | |
| 74 | IN UINTN Size, | |
| 75 | OUT VOID **Buffer | |
| 76 | ); | |
| 77 | | |
| 78 | /** | |
| 79 | Frees pool. | |
| 80 | | |
| 81 | @param Buffer The allocated pool entry to free. | |
| 82 | | |
| 83 | @retval EFI_INVALID_PARAMETER Buffer is not a valid value. | |
| 84 | @retval EFI_SUCCESS Pool successfully freed. | |
| 85 | | |
| 86 | **/ | |
| 87 | EFI_STATUS | |
| 88 | EFIAPI | |
| 89 | MmFreePool ( | |
| 90 | IN VOID *Buffer | |
| 91 | ); | |
| 92 | | |
| 93 | /** | |
| 94 | Allocates pages from the memory map. | |
| 95 | | |
| 96 | @param Type The type of allocation to perform. | |
| 97 | @param MemoryType The type of memory to turn the allocated pages | |
| 98 | into. | |
| 99 | @param NumberOfPages The number of pages to allocate. | |
| 100 | @param Memory A pointer to receive the base allocated memory | |
| 101 | address. | |
| 102 | | |
| 103 | @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in spec. | |
| 104 | @retval EFI_NOT_FOUND Could not allocate pages match the requirement. | |
| 105 | @retval EFI_OUT_OF_RESOURCES No enough pages to allocate. | |
| 106 | @retval EFI_SUCCESS Pages successfully allocated. | |
| 107 | | |
| 108 | **/ | |
| 109 | EFI_STATUS | |
| 110 | EFIAPI | |
| 111 | MmInternalAllocatePages ( | |
| 112 | IN EFI_ALLOCATE_TYPE Type, | |
| 113 | IN EFI_MEMORY_TYPE MemoryType, | |
| 114 | IN UINTN NumberOfPages, | |
| 115 | OUT EFI_PHYSICAL_ADDRESS *Memory | |
| 116 | ); | |
| 117 | | |
| 118 | /** | |
| 119 | Frees previous allocated pages. | |
| 120 | | |
| 121 | @param Memory Base address of memory being freed. | |
| 122 | @param NumberOfPages The number of pages to free. | |
| 123 | | |
| 124 | @retval EFI_NOT_FOUND Could not find the entry that covers the range. | |
| 125 | @retval EFI_INVALID_PARAMETER Address not aligned. | |
| 126 | @return EFI_SUCCESS Pages successfully freed. | |
| 127 | | |
| 128 | **/ | |
| 129 | EFI_STATUS | |
| 130 | EFIAPI | |
| 131 | MmInternalFreePages ( | |
| 132 | IN EFI_PHYSICAL_ADDRESS Memory, | |
| 133 | IN UINTN NumberOfPages | |
| 134 | ); | |
| 135 | | |
| 136 | /** | |
| 137 | Add free MMRAM region for use by memory service. | |
| 138 | | |
| 139 | @param MemBase Base address of memory region. | |
| 140 | @param MemLength Length of the memory region. | |
| 141 | @param Type Memory type. | |
| 142 | @param Attributes Memory region state. | |
| 143 | | |
| 144 | **/ | |
| 145 | VOID | |
| 146 | MmAddMemoryRegion ( | |
| 147 | IN EFI_PHYSICAL_ADDRESS MemBase, | |
| 148 | IN UINT64 MemLength, | |
| 149 | IN EFI_MEMORY_TYPE Type, | |
| 150 | IN UINT64 Attributes | |
| 151 | ); | |
| 152 | | |
| 153 | /** | |
| 154 | Called to initialize the memory service. | |
| 155 | | |
| 156 | @param MmramRangeCount Number of MMRAM Regions | |
| 157 | @param MmramRanges Pointer to MMRAM Descriptors | |
| 158 | | |
| 159 | **/ | |
| 160 | VOID | |
| 161 | MmInitializeMemoryServices ( | |
| 162 | IN UINTN MmramRangeCount, | |
| 163 | IN EFI_MMRAM_DESCRIPTOR *MmramRanges | |
| 164 | ); | |
| 165 | | |
| 166 | #endif // SECURE_PARTITION_MEM_ALLOC_LIB_H_ |