2 Private Header file for Usb Host Controller PEIM
4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef _EFI_PEI_XHCI_MEM_H_
18 #define _EFI_PEI_XHCI_MEM_H_
22 #define USBHC_MEM_DEFAULT_PAGES 16
24 typedef struct _USBHC_MEM_BLOCK USBHC_MEM_BLOCK
;
26 struct _USBHC_MEM_BLOCK
{
27 UINT8
*Bits
; // Bit array to record which unit is allocated
31 UINTN BufLen
; // Memory size in bytes
32 USBHC_MEM_BLOCK
*Next
;
36 // Memory allocation unit, must be 2^n, n>4
38 #define USBHC_MEM_UNIT 64
40 #define USBHC_MEM_UNIT_MASK (USBHC_MEM_UNIT - 1)
41 #define USBHC_MEM_ROUND(Len) (((Len) + USBHC_MEM_UNIT_MASK) & (~USBHC_MEM_UNIT_MASK))
43 #define USB_HC_BIT(a) ((UINTN)(1 << (a)))
45 #define USB_HC_BIT_IS_SET(Data, Bit) \
46 ((BOOLEAN)(((Data) & USB_HC_BIT(Bit)) == USB_HC_BIT(Bit)))
49 // Advance the byte and bit to the next bit, adjust byte accordingly.
51 #define NEXT_BIT(Byte, Bit) \
61 // USBHC_MEM_POOL is used to manage the memory used by USB
62 // host controller. XHCI requires the control memory and transfer
63 // data to be on the same 4G memory.
65 typedef struct _USBHC_MEM_POOL
{
68 USBHC_MEM_BLOCK
*Head
;
72 Calculate the corresponding pci bus address according to the Mem parameter.
74 @param Pool The memory pool of the host controller.
75 @param Mem The pointer to host memory.
76 @param Size The size of the memory region.
78 @return The pci memory address
82 UsbHcGetPciAddrForHostAddr (
83 IN USBHC_MEM_POOL
*Pool
,
89 Calculate the corresponding host address according to the pci address.
91 @param Pool The memory pool of the host controller.
92 @param Mem The pointer to pci memory.
93 @param Size The size of the memory region.
95 @return The host memory address
99 UsbHcGetHostAddrForPciAddr (
100 IN USBHC_MEM_POOL
*Pool
,
106 Allocates pages at a specified alignment.
108 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
110 @param Pages The number of pages to allocate.
111 @param Alignment The requested alignment of the allocation. Must be a power of two.
112 @param HostAddress The system memory address to map to the PCI controller.
113 @param DeviceAddress The resulting map address for the bus master PCI controller to
114 use to access the hosts HostAddress.
116 @retval EFI_SUCCESS Success to allocate aligned pages.
117 @retval EFI_INVALID_PARAMETER Pages or Alignment is not valid.
118 @retval EFI_OUT_OF_RESOURCES Do not have enough resources to allocate memory.
122 UsbHcAllocateAlignedPages (
125 OUT VOID
**HostAddress
,
126 OUT EFI_PHYSICAL_ADDRESS
*DeviceAddress
130 Frees memory that was allocated with UsbHcAllocateAlignedPages().
132 @param HostAddress The system memory address to map to the PCI controller.
133 @param Pages The number of pages to free.
137 UsbHcFreeAlignedPages (
138 IN VOID
*HostAddress
,