36 if (EFI_ERROR (Status)) {
46 ASSERT (UFS_PEIM_MEM_UNIT * 8 <= EFI_PAGE_SIZE);
50 Block->BitsLen = Block->BufLen / (UFS_PEIM_MEM_UNIT * 8);
53 if (EFI_ERROR (Status)) {
59 Block->Bits = (UINT8 *)(
UINTN)TempPtr;
67 if (EFI_ERROR (Status)) {
73 Block->BufHost = (UINT8 *)(
UINTN)BufHost;
74 Block->Buf = (UINT8 *)(
UINTN)MappedAddr;
75 Block->Mapping = Mapping;
94 ASSERT ((Pool !=
NULL) && (Block !=
NULL));
122 ASSERT ((Block != 0) && (Units != 0));
128 for (Byte = 0, Bit = 0; Byte < Block->BitsLen;) {
134 if (!UFS_PEIM_MEM_BIT_IS_SET (Block->Bits[Byte], Bit)) {
137 if (Available >= Units) {
141 UFS_PEIM_NEXT_BIT (Byte, Bit);
143 UFS_PEIM_NEXT_BIT (Byte, Bit);
151 if (Available < Units) {
161 for (Count = 0; Count < Units; Count++) {
162 ASSERT (!UFS_PEIM_MEM_BIT_IS_SET (Block->Bits[Byte], Bit));
164 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] | (UINT8)UFS_PEIM_MEM_BIT (Bit));
165 UFS_PEIM_NEXT_BIT (Byte, Bit);
168 return Block->Buf + (StartByte * 8 + StartBit) * UFS_PEIM_MEM_UNIT;
184 ASSERT ((Head !=
NULL) && (Block !=
NULL));
185 Block->Next = Head->Next;
205 for (Index = 0; Index < Block->BitsLen; Index++) {
206 if (Block->Bits[Index] != 0) {
236 if (EFI_ERROR (Status)) {
237 return EFI_OUT_OF_RESOURCES;
246 if (Pool->Head ==
NULL) {
247 return EFI_OUT_OF_RESOURCES;
250 Private->Pool = Pool;
270 ASSERT (Pool->Head !=
NULL);
275 for (Block = Pool->Head->Next; Block !=
NULL; Block = Pool->Head->Next) {
308 AllocSize = UFS_PEIM_MEM_ROUND (Size);
310 ASSERT (Head !=
NULL);
315 for (Block = Head; Block !=
NULL; Block = Block->Next) {
337 Pages = UFS_PEIM_MEM_DEFAULT_PAGES;
341 if (NewBlock ==
NULL) {
382 AllocSize = UFS_PEIM_MEM_ROUND (Size);
383 ToFree = (UINT8 *)Mem;
385 for (Block = Head; Block !=
NULL; Block = Block->Next) {
390 if ((Block->Buf <= ToFree) && ((ToFree + AllocSize) <= (Block->Buf + Block->BufLen))) {
394 Byte = ((ToFree - Block->Buf) / UFS_PEIM_MEM_UNIT) / 8;
395 Bit = ((ToFree - Block->Buf) / UFS_PEIM_MEM_UNIT) % 8;
400 for (Count = 0; Count < (AllocSize / UFS_PEIM_MEM_UNIT); Count++) {
401 ASSERT (UFS_PEIM_MEM_BIT_IS_SET (Block->Bits[Byte], Bit));
403 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] ^ UFS_PEIM_MEM_BIT (Bit));
404 UFS_PEIM_NEXT_BIT (Byte, Bit);
416 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)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
VOID * UfsPeimAllocateMem(IN UFS_PEIM_MEM_POOL *Pool, IN UINTN Size)
VOID UfsPeimFreeMem(IN UFS_PEIM_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size)
UFS_PEIM_MEM_BLOCK * UfsPeimAllocMemBlock(IN UINTN Pages)
EFI_STATUS UfsPeimFreeMemPool(IN UFS_PEIM_MEM_POOL *Pool)
VOID UfsPeimFreeMemBlock(IN UFS_PEIM_MEM_POOL *Pool, IN UFS_PEIM_MEM_BLOCK *Block)
BOOLEAN UfsPeimIsMemBlockEmpty(IN UFS_PEIM_MEM_BLOCK *Block)
EFI_STATUS UfsPeimInitMemPool(IN UFS_PEIM_HC_PRIVATE_DATA *Private)
VOID UfsPeimInsertMemBlockToPool(IN UFS_PEIM_MEM_BLOCK *Head, IN UFS_PEIM_MEM_BLOCK *Block)
VOID * UfsPeimAllocMemFromBlock(IN UFS_PEIM_MEM_BLOCK *Block, IN UINTN Units)