46 ASSERT (USBHC_MEM_UNIT * 8 <= EFI_PAGE_SIZE);
49 Block->BitsLen = Block->BufLen / (USBHC_MEM_UNIT * 8);
52 if (Block->Bits ==
NULL) {
53 gBS->FreePool (Block);
61 Status = PciIo->AllocateBuffer (
70 if (EFI_ERROR (Status)) {
92 if (Pool->Check4G && (Pool->Which4G != USB_HC_HIGH_32BIT (MappedAddr))) {
93 PciIo->Unmap (PciIo, Mapping);
97 Block->BufHost = BufHost;
98 Block->Buf = (UINT8 *)((
UINTN)MappedAddr);
99 Block->Mapping = Mapping;
104 PciIo->FreeBuffer (PciIo, Pages, BufHost);
107 gBS->FreePool (Block->Bits);
108 gBS->FreePool (Block);
127 ASSERT ((Pool !=
NULL) && (Block !=
NULL));
134 PciIo->Unmap (PciIo, Block->Mapping);
137 gBS->FreePool (Block->Bits);
138 gBS->FreePool (Block);
164 ASSERT ((Block != 0) && (Units != 0));
170 for (Byte = 0, Bit = 0; Byte < Block->BitsLen;) {
176 if (!USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit)) {
179 if (Available >= Units) {
183 NEXT_BIT (Byte, Bit);
185 NEXT_BIT (Byte, Bit);
193 if (Available < Units) {
203 for (Count = 0; Count < Units; Count++) {
204 ASSERT (!USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit));
206 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] | (UINT8)USB_HC_BIT (Bit));
207 NEXT_BIT (Byte, Bit);
210 return Block->BufHost + (StartByte * 8 + StartBit) * USBHC_MEM_UNIT;
236 AllocSize = USBHC_MEM_ROUND (Size);
242 for (Block = Head; Block !=
NULL; Block = Block->Next) {
247 if ((Block->BufHost <= (UINT8 *)Mem) && (((UINT8 *)Mem + AllocSize) <= (Block->BufHost + Block->BufLen))) {
252 ASSERT ((Block !=
NULL));
261 Offset = (UINT8 *)Mem - Block->BufHost;
279 ASSERT ((Head !=
NULL) && (Block !=
NULL));
280 Block->Next = Head->Next;
300 for (Index = 0; Index < Block->BitsLen; Index++) {
301 if (Block->Bits[Index] != 0) {
324 ASSERT ((Head !=
NULL) && (BlockToUnlink !=
NULL));
326 for (Block = Head; Block !=
NULL; Block = Block->Next) {
327 if (Block->Next == BlockToUnlink) {
328 Block->Next = BlockToUnlink->Next;
329 BlockToUnlink->Next =
NULL;
363 Pool->Check4G = Check4G;
364 Pool->Which4G = Which4G;
367 if (Pool->Head ==
NULL) {
368 gBS->FreePool (Pool);
391 ASSERT (Pool->Head !=
NULL);
398 for (Block = Pool->Head->Next; Block !=
NULL; Block = Pool->Head->Next) {
404 gBS->FreePool (Pool);
432 AllocSize = USBHC_MEM_ROUND (Size);
434 ASSERT (Head !=
NULL);
439 for (Block = Head; Block !=
NULL; Block = Block->Next) {
461 Pages = USBHC_MEM_DEFAULT_PAGES;
466 if (NewBlock ==
NULL) {
467 DEBUG ((DEBUG_INFO,
"UsbHcAllocateMem: failed to allocate block\n"));
508 AllocSize = USBHC_MEM_ROUND (Size);
509 ToFree = (UINT8 *)Mem;
511 for (Block = Head; Block !=
NULL; Block = Block->Next) {
516 if ((Block->BufHost <= ToFree) && ((ToFree + AllocSize) <= (Block->BufHost + Block->BufLen))) {
520 Byte = ((ToFree - Block->BufHost) / USBHC_MEM_UNIT) / 8;
521 Bit = ((ToFree - Block->BufHost) / USBHC_MEM_UNIT) % 8;
526 for (Count = 0; Count < (AllocSize / USBHC_MEM_UNIT); Count++) {
527 ASSERT (USB_HC_BIT_IS_SET (Block->Bits[Byte], Bit));
529 Block->Bits[Byte] = (UINT8)(Block->Bits[Byte] ^ USB_HC_BIT (Bit));
530 NEXT_BIT (Byte, Bit);
542 ASSERT (Block !=
NULL);
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 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)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define DEBUG(Expression)
@ EfiPciIoOperationBusMasterCommonBuffer
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)