3 This file contains the definination for host controller memory management routines
5 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _EFI_EHCI_MEM_H_
17 #define _EFI_EHCI_MEM_H_
19 #define USB_HC_BIT(a) ((UINTN)(1 << (a)))
21 #define USB_HC_BIT_IS_SET(Data, Bit) \
22 ((BOOLEAN)(((Data) & USB_HC_BIT(Bit)) == USB_HC_BIT(Bit)))
24 #define USB_HC_HIGH_32BIT(Addr64) \
25 ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
28 typedef struct _USBHC_MEM_BLOCK USBHC_MEM_BLOCK
;
29 struct _USBHC_MEM_BLOCK
{
30 UINT8
*Bits
; // Bit array to record which unit is allocated
34 UINTN BufLen
; // Memory size in bytes
36 USBHC_MEM_BLOCK
*Next
;
40 // USBHC_MEM_POOL is used to manage the memory used by USB
41 // host controller. EHCI requires the control memory and transfer
42 // data to be on the same 4G memory.
44 typedef struct _USBHC_MEM_POOL
{
45 EFI_PCI_IO_PROTOCOL
*PciIo
;
48 USBHC_MEM_BLOCK
*Head
;
52 // Memory allocation unit, must be 2^n, n>4
54 #define USBHC_MEM_UNIT 64
56 #define USBHC_MEM_UNIT_MASK (USBHC_MEM_UNIT - 1)
57 #define USBHC_MEM_DEFAULT_PAGES 16
59 #define USBHC_MEM_ROUND(Len) (((Len) + USBHC_MEM_UNIT_MASK) & (~USBHC_MEM_UNIT_MASK))
62 // Advance the byte and bit to the next bit, adjust byte accordingly.
64 #define NEXT_BIT(Byte, Bit) \
75 Initialize the memory management pool for the host controller.
77 @param PciIo The PciIo that can be used to access the host controller.
78 @param Check4G Whether the host controller requires allocated memory
79 from one 4G address space.
80 @param Which4G The 4G memory area each memory allocated should be from.
82 @retval EFI_SUCCESS The memory pool is initialized.
83 @retval EFI_OUT_OF_RESOURCE Fail to init the memory pool.
88 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
95 Release the memory management pool.
97 @param Pool The USB memory pool to free.
99 @return EFI_SUCCESS The memory pool is freed.
100 @return EFI_DEVICE_ERROR Failed to free the memory pool.
105 IN USBHC_MEM_POOL
*Pool
111 Allocate some memory from the host controller's memory pool
112 which can be used to communicate with host controller.
114 @param Pool The host controller's memory pool.
115 @param Size Size of the memory to allocate.
117 @return The allocated memory or NULL.
122 IN USBHC_MEM_POOL
*Pool
,
129 Free the allocated memory back to the memory pool.
131 @param Pool The memory pool of the host controller.
132 @param Mem The memory to free.
133 @param Size The size of the memory to free.
140 IN USBHC_MEM_POOL
*Pool
,
146 Calculate the corresponding pci bus address according to the Mem parameter.
148 @param Pool The memory pool of the host controller.
149 @param Mem The pointer to host memory.
150 @param Size The size of the memory region.
152 @return the pci memory address
155 UsbHcGetPciAddressForHostMem (
156 IN USBHC_MEM_POOL
*Pool
,