42 if (EFI_ERROR (Status)) {
52 ASSERT (USBHC_MEM_UNIT * 8 <= EFI_PAGE_SIZE);
56 Block->BitsLen = Block->BufLen / (USBHC_MEM_UNIT * 8);
65 if (EFI_ERROR (Status)) {
71 Block->Bits = (UINT8 *)(
UINTN)TempPtr;
79 if (EFI_ERROR (Status)) {
85 Block->BufHost = (UINT8 *)(
UINTN)BufHost;
86 Block->Buf = (UINT8 *)(
UINTN)MappedAddr;
87 Block->Mapping = Mapping;
106 ASSERT ((Pool !=
NULL) && (Block !=
NULL));
138 ASSERT ((Block != 0) && (Units != 0));
144 for (Byte = 0, Bit = 0; Byte < Block->BitsLen;) {
150 if (!USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit)) {
153 if (Available >= Units) {
157 NEXT_BIT (Byte, Bit);
159 NEXT_BIT (Byte, Bit);
167 if (Available < Units) {
177 for (Count = 0; Count < Units; Count++) {
178 ASSERT (!USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit));
180 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] | (UINT8)USB_HC_BIT (Bit));
181 NEXT_BIT (Byte, Bit);
184 return Block->BufHost + (StartByte * 8 + StartBit) * USBHC_MEM_UNIT;
214 AllocSize = USBHC_MEM_ROUND (Size);
223 for (Block = Head; Block !=
NULL; Block = Block->Next) {
228 if ((Block->BufHost <= (UINT8 *)Mem) && (((UINT8 *)Mem + AllocSize) <= (Block->BufHost + Block->BufLen))) {
233 ASSERT ((Block !=
NULL));
237 Offset = (UINT8 *)Mem - Block->BufHost;
269 AllocSize = USBHC_MEM_ROUND (Size);
278 for (Block = Head; Block !=
NULL; Block = Block->Next) {
283 if ((Block->Buf <= (UINT8 *)Mem) && (((UINT8 *)Mem + AllocSize) <= (Block->Buf + Block->BufLen))) {
288 ASSERT ((Block !=
NULL));
292 Offset = (UINT8 *)Mem - Block->Buf;
310 ASSERT ((Head !=
NULL) && (Block !=
NULL));
311 Block->Next = Head->Next;
331 for (Index = 0; Index < Block->BitsLen; Index++) {
332 if (Block->Bits[Index] != 0) {
362 if (EFI_ERROR (Status)) {
371 if (Pool->Head ==
NULL) {
396 ASSERT ((Head !=
NULL) && (BlockToUnlink !=
NULL));
398 for (Block = Head; Block !=
NULL; Block = Block->Next) {
399 if (Block->Next == BlockToUnlink) {
400 Block->Next = BlockToUnlink->Next;
401 BlockToUnlink->Next =
NULL;
420 ASSERT (Pool->Head !=
NULL);
427 for (Block = Pool->Head->Next; Block !=
NULL; Block = Pool->Head->Next) {
459 AllocSize = USBHC_MEM_ROUND (Size);
461 ASSERT (Head !=
NULL);
466 for (Block = Head; Block !=
NULL; Block = Block->Next) {
488 Pages = USBHC_MEM_DEFAULT_PAGES;
493 if (NewBlock ==
NULL) {
534 AllocSize = USBHC_MEM_ROUND (Size);
535 ToFree = (UINT8 *)Mem;
537 for (Block = Head; Block !=
NULL; Block = Block->Next) {
542 if ((Block->BufHost <= ToFree) && ((ToFree + AllocSize) <= (Block->BufHost + Block->BufLen))) {
546 Byte = ((ToFree - Block->BufHost) / USBHC_MEM_UNIT) / 8;
547 Bit = ((ToFree - Block->BufHost) / USBHC_MEM_UNIT) % 8;
552 for (Count = 0; Count < (AllocSize / USBHC_MEM_UNIT); Count++) {
553 ASSERT (USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit));
555 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] ^ USB_HC_BIT (Bit));
556 NEXT_BIT (Byte, Bit);
568 ASSERT (Block !=
NULL);
600 OUT VOID **HostAddress,
612 ASSERT ((Alignment & (Alignment - 1)) == 0);
614 if ((Alignment & (Alignment - 1)) != 0) {
615 return EFI_INVALID_PARAMETER;
619 return EFI_INVALID_PARAMETER;
622 if (Alignment > EFI_PAGE_SIZE) {
630 if (EFI_ERROR (Status)) {
631 return EFI_OUT_OF_RESOURCES;
643 if (EFI_ERROR (Status)) {
644 return EFI_OUT_OF_RESOURCES;
648 *HostAddress = Memory;
649 *DeviceAddress = DeviceMemory;
664 IN VOID *HostAddress,
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)
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 UsbHcUnlinkMemBlock(IN USBHC_MEM_BLOCK *Head, IN USBHC_MEM_BLOCK *BlockToUnlink)
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)
EFI_STATUS IoMmuAllocateAlignedBuffer(IN UINTN Pages, IN UINTN Alignment, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
EFI_PHYSICAL_ADDRESS UsbHcGetPciAddrForHostAddr(IN USBHC_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size, IN BOOLEAN Alignment)
EFI_STATUS UsbHcAllocateAlignedPages(IN EFI_PCI_IO_PROTOCOL *PciIo, IN UINTN Pages, IN UINTN Alignment, OUT VOID **HostAddress, OUT EFI_PHYSICAL_ADDRESS *DeviceAddress, OUT VOID **Mapping)
EFI_PHYSICAL_ADDRESS UsbHcGetHostAddrForPciAddr(IN USBHC_MEM_POOL *Pool, IN VOID *Mem, IN UINTN Size, IN BOOLEAN Alignment)
VOID UsbHcFreeAlignedPages(IN EFI_PCI_IO_PROTOCOL *PciIo, IN VOID *HostAddress, IN UINTN Pages, VOID *Mapping)