2 This file contains the definination for host controller memory
5 Copyright (c) 2013-2015 Intel Corporation.
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #ifndef _USB_HC_MEM_H_
12 #define _USB_HC_MEM_H_
14 #define USB_HC_BIT(a) ((UINTN)(1 << (a)))
16 #define USB_HC_BIT_IS_SET(Data, Bit) \
17 ((BOOLEAN)(((Data) & USB_HC_BIT(Bit)) == USB_HC_BIT(Bit)))
19 #define USB_HC_HIGH_32BIT(Addr64) \
20 ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
22 typedef struct _USBHC_MEM_BLOCK USBHC_MEM_BLOCK
;
23 struct _USBHC_MEM_BLOCK
{
24 UINT8
*Bits
; // Bit array to record which unit is allocated
28 UINTN BufLen
; // Memory size in bytes
30 USBHC_MEM_BLOCK
*Next
;
34 // USBHC_MEM_POOL is used to manage the memory used by USB
35 // host controller. EHCI requires the control memory and transfer
36 // data to be on the same 4G memory.
38 typedef struct _USBHC_MEM_POOL
{
41 USBHC_MEM_BLOCK
*Head
;
45 // Memory allocation unit, must be 2^n, n>4
47 #define USBHC_MEM_UNIT 64
49 #define USBHC_MEM_UNIT_MASK (USBHC_MEM_UNIT - 1)
50 #define USBHC_MEM_DEFAULT_PAGES 16
52 #define USBHC_MEM_ROUND(Len) (((Len) + USBHC_MEM_UNIT_MASK) & (~USBHC_MEM_UNIT_MASK))
55 // Advance the byte and bit to the next bit, adjust byte accordingly.
57 #define NEXT_BIT(Byte, Bit) \
69 Initialize the memory management pool for the host controller.
71 @param PciIo The PciIo that can be used to access the host controller.
72 @param Check4G Whether the host controller requires allocated memory
73 from one 4G address space.
74 @param Which4G The 4G memory area each memory allocated should be from.
76 @retval EFI_SUCCESS The memory pool is initialized.
77 @retval EFI_OUT_OF_RESOURCE Fail to init the memory pool.
88 Release the memory management pool.
90 @param Pool The USB memory pool to free.
92 @retval EFI_SUCCESS The memory pool is freed.
93 @retval EFI_DEVICE_ERROR Failed to free the memory pool.
98 IN USBHC_MEM_POOL
*Pool
103 Allocate some memory from the host controller's memory pool
104 which can be used to communicate with host controller.
106 @param Pool The host controller's memory pool.
107 @param Size Size of the memory to allocate.
109 @return The allocated memory or NULL.
114 IN USBHC_MEM_POOL
*Pool
,
120 Free the allocated memory back to the memory pool.
122 @param Pool The memory pool of the host controller.
123 @param Mem The memory to free.
124 @param Size The size of the memory to free.
129 IN USBHC_MEM_POOL
*Pool
,