46 if (EFI_ERROR (Status)) {
50 ZeroMem ((VOID *)(
UINTN)TempPtr, PageNumber*EFI_PAGE_SIZE);
56 ASSERT (USBHC_MEM_UNIT * 8 <= EFI_PAGE_SIZE);
60 Block->BitsLen = Block->BufLen / (USBHC_MEM_UNIT * 8);
62 PageNumber = (Block->BitsLen)/PAGESIZE +1;
69 if (EFI_ERROR (Status)) {
73 ZeroMem ((VOID *)(
UINTN)TempPtr, PageNumber*EFI_PAGE_SIZE);
75 Block->Bits = (UINT8 *)(
UINTN)TempPtr;
84 if (EFI_ERROR (Status)) {
88 ZeroMem (BufHost, Pages*EFI_PAGE_SIZE);
94 if (Pool->Check4G && (Pool->Which4G != USB_HC_HIGH_32BIT (MappedAddr))) {
98 Block->BufHost = BufHost;
99 Block->Buf = (UINT8 *)((
UINTN)MappedAddr);
100 Block->Mapping = Mapping;
121 ASSERT ((Pool !=
NULL) && (Block !=
NULL));
149 ASSERT ((Block != 0) && (Units != 0));
155 for (Byte = 0, Bit = 0; Byte < Block->BitsLen;) {
161 if (!USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit)) {
164 if (Available >= Units) {
168 NEXT_BIT (Byte, Bit);
170 NEXT_BIT (Byte, Bit);
178 if (Available < Units) {
188 for (Count = 0; Count < Units; Count++) {
189 ASSERT (!USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit));
191 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] | (UINT8)USB_HC_BIT (Bit));
192 NEXT_BIT (Byte, Bit);
195 return Block->Buf + (StartByte * 8 + StartBit) * USBHC_MEM_UNIT;
221 AllocSize = USBHC_MEM_ROUND (Size);
227 for (Block = Head; Block !=
NULL; Block = Block->Next) {
232 if ((Block->BufHost <= (UINT8 *)Mem) && (((UINT8 *)Mem + AllocSize) <= (Block->BufHost + Block->BufLen))) {
237 ASSERT ((Block !=
NULL));
241 Offset = (UINT8 *)Mem - Block->BufHost;
259 ASSERT ((Head !=
NULL) && (Block !=
NULL));
260 Block->Next = Head->Next;
280 for (Index = 0; Index < Block->BitsLen; Index++) {
281 if (Block->Bits[Index] != 0) {
320 if (EFI_ERROR (Status)) {
324 ZeroMem ((VOID *)(
UINTN)TempPtr, PageNumber*EFI_PAGE_SIZE);
328 Pool->Check4G = Check4G;
329 Pool->Which4G = Which4G;
332 if (Pool->Head ==
NULL) {
357 ASSERT (Pool->Head !=
NULL);
362 for (Block = Pool->Head->Next; Block !=
NULL; Block = Block->Next) {
397 AllocSize = USBHC_MEM_ROUND (Size);
399 ASSERT (Head !=
NULL);
404 for (Block = Head; Block !=
NULL; Block = Block->Next) {
426 Pages = USBHC_MEM_DEFAULT_PAGES;
431 if (NewBlock ==
NULL) {
474 AllocSize = USBHC_MEM_ROUND (Size);
475 ToFree = (UINT8 *)Mem;
477 for (Block = Head; Block !=
NULL; Block = Block->Next) {
482 if ((Block->Buf <= ToFree) && ((ToFree + AllocSize) <= (Block->Buf + Block->BufLen))) {
486 Byte = ((ToFree - Block->Buf) / USBHC_MEM_UNIT) / 8;
487 Bit = ((ToFree - Block->Buf) / USBHC_MEM_UNIT) % 8;
492 for (Count = 0; Count < (AllocSize / USBHC_MEM_UNIT); Count++) {
493 ASSERT (USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit));
495 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] ^ USB_HC_BIT (Bit));
496 NEXT_BIT (Byte, Bit);
508 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_PHYSICAL_ADDRESS UsbHcGetPciAddressForHostMem(IN USBHC_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size)
VOID * UsbHcAllocMemFromBlock(IN USBHC_MEM_BLOCK *Block, IN UINTN Units)
EFI_STATUS UsbHcFreeMemPool(IN USBHC_MEM_POOL *Pool)
VOID UsbHcFreeMemBlock(IN USBHC_MEM_POOL *Pool, IN USBHC_MEM_BLOCK *Block)
BOOLEAN UsbHcIsMemBlockEmpty(IN USBHC_MEM_BLOCK *Block)
VOID UsbHcFreeMem(IN USBHC_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size)
VOID * UsbHcAllocateMem(IN USBHC_MEM_POOL *Pool, IN UINTN Size)
USBHC_MEM_BLOCK * UsbHcAllocMemBlock(IN USBHC_MEM_POOL *Pool, IN UINTN Pages)
VOID UsbHcInsertMemBlockToPool(IN USBHC_MEM_BLOCK *Head, IN USBHC_MEM_BLOCK *Block)
USBHC_MEM_POOL * UsbHcInitMemPool(IN EFI_PCI_IO_PROTOCOL *PciIo, IN BOOLEAN Check4G, IN UINT32 Which4G)
EFI_STATUS EFIAPI PeiServicesAllocatePages(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Pages, OUT EFI_PHYSICAL_ADDRESS *Memory)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)