35 if (EFI_ERROR (Status)) {
45 ASSERT (SD_PEIM_MEM_UNIT * 8 <= EFI_PAGE_SIZE);
49 Block->BitsLen = Block->BufLen / (SD_PEIM_MEM_UNIT * 8);
52 if (EFI_ERROR (Status)) {
58 Block->Bits = (UINT8 *)(
UINTN)TempPtr;
66 if (EFI_ERROR (Status)) {
72 Block->BufHost = (UINT8 *)(
UINTN)BufHost;
73 Block->Buf = (UINT8 *)(
UINTN)MappedAddr;
74 Block->Mapping = Mapping;
93 ASSERT ((Pool !=
NULL) && (Block !=
NULL));
121 ASSERT ((Block != 0) && (Units != 0));
127 for (Byte = 0, Bit = 0; Byte < Block->BitsLen;) {
133 if (!SD_PEIM_MEM_BIT_IS_SET (Block->Bits[Byte], Bit)) {
136 if (Available >= Units) {
140 SD_PEIM_NEXT_BIT (Byte, Bit);
142 SD_PEIM_NEXT_BIT (Byte, Bit);
150 if (Available < Units) {
160 for (Count = 0; Count < Units; Count++) {
161 ASSERT (!SD_PEIM_MEM_BIT_IS_SET (Block->Bits[Byte], Bit));
163 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] | (UINT8)SD_PEIM_MEM_BIT (Bit));
164 SD_PEIM_NEXT_BIT (Byte, Bit);
167 return Block->Buf + (StartByte * 8 + StartBit) * SD_PEIM_MEM_UNIT;
183 ASSERT ((Head !=
NULL) && (Block !=
NULL));
184 Block->Next = Head->Next;
204 for (Index = 0; Index < Block->BitsLen; Index++) {
205 if (Block->Bits[Index] != 0) {
235 if (EFI_ERROR (Status)) {
236 return EFI_OUT_OF_RESOURCES;
245 if (Pool->Head ==
NULL) {
246 return EFI_OUT_OF_RESOURCES;
249 Private->Pool = Pool;
269 ASSERT (Pool->Head !=
NULL);
274 for (Block = Pool->Head->Next; Block !=
NULL; Block = Pool->Head->Next) {
307 AllocSize = SD_PEIM_MEM_ROUND (Size);
309 ASSERT (Head !=
NULL);
314 for (Block = Head; Block !=
NULL; Block = Block->Next) {
336 Pages = SD_PEIM_MEM_DEFAULT_PAGES;
340 if (NewBlock ==
NULL) {
381 AllocSize = SD_PEIM_MEM_ROUND (Size);
382 ToFree = (UINT8 *)Mem;
384 for (Block = Head; Block !=
NULL; Block = Block->Next) {
389 if ((Block->Buf <= ToFree) && ((ToFree + AllocSize) <= (Block->Buf + Block->BufLen))) {
393 Byte = ((ToFree - Block->Buf) / SD_PEIM_MEM_UNIT) / 8;
394 Bit = ((ToFree - Block->Buf) / SD_PEIM_MEM_UNIT) % 8;
399 for (Count = 0; Count < (AllocSize / SD_PEIM_MEM_UNIT); Count++) {
400 ASSERT (SD_PEIM_MEM_BIT_IS_SET (Block->Bits[Byte], Bit));
402 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] ^ SD_PEIM_MEM_BIT (Bit));
403 SD_PEIM_NEXT_BIT (Byte, Bit);
415 ASSERT (Block !=
NULL);
EFI_STATUS IoMmuAllocateBuffer(IN UINTN Pages, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
EFI_STATUS IoMmuFreeBuffer(IN UINTN Pages, IN VOID *HostAddress, IN VOID *Mapping)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI PeiServicesAllocatePool(IN UINTN Size, OUT VOID **Buffer)
BOOLEAN SdPeimIsMemBlockEmpty(IN SD_PEIM_MEM_BLOCK *Block)
VOID SdPeimFreeMem(IN SD_PEIM_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size)
VOID SdPeimInsertMemBlockToPool(IN SD_PEIM_MEM_BLOCK *Head, IN SD_PEIM_MEM_BLOCK *Block)
EFI_STATUS SdPeimFreeMemPool(IN SD_PEIM_MEM_POOL *Pool)
SD_PEIM_MEM_BLOCK * SdPeimAllocMemBlock(IN UINTN Pages)
EFI_STATUS SdPeimInitMemPool(IN SD_PEIM_HC_PRIVATE_DATA *Private)
VOID * SdPeimAllocMemFromBlock(IN SD_PEIM_MEM_BLOCK *Block, IN UINTN Units)
VOID * SdPeimAllocateMem(IN SD_PEIM_MEM_POOL *Pool, IN UINTN Size)
VOID SdPeimFreeMemBlock(IN SD_PEIM_MEM_POOL *Pool, IN SD_PEIM_MEM_BLOCK *Block)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)