]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / XhciPei / UsbHcMem.h
1 /** @file
2 Private Header file for Usb Host Controller PEIM
3
4 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _EFI_PEI_XHCI_MEM_H_
11 #define _EFI_PEI_XHCI_MEM_H_
12
13 #include <Uefi.h>
14
15 #define USBHC_MEM_DEFAULT_PAGES 16
16
17 typedef struct _USBHC_MEM_BLOCK USBHC_MEM_BLOCK;
18
19 struct _USBHC_MEM_BLOCK {
20 UINT8 *Bits; // Bit array to record which unit is allocated
21 UINTN BitsLen;
22 UINT8 *Buf;
23 UINT8 *BufHost;
24 UINTN BufLen; // Memory size in bytes
25 VOID *Mapping;
26 USBHC_MEM_BLOCK *Next;
27 };
28
29 //
30 // Memory allocation unit, must be 2^n, n>4
31 //
32 #define USBHC_MEM_UNIT 64
33
34 #define USBHC_MEM_UNIT_MASK (USBHC_MEM_UNIT - 1)
35 #define USBHC_MEM_ROUND(Len) (((Len) + USBHC_MEM_UNIT_MASK) & (~USBHC_MEM_UNIT_MASK))
36
37 #define USB_HC_BIT(a) ((UINTN)(1 << (a)))
38
39 #define USB_HC_BIT_IS_SET(Data, Bit) \
40 ((BOOLEAN)(((Data) & USB_HC_BIT(Bit)) == USB_HC_BIT(Bit)))
41
42 //
43 // Advance the byte and bit to the next bit, adjust byte accordingly.
44 //
45 #define NEXT_BIT(Byte, Bit) \
46 do { \
47 (Bit)++; \
48 if ((Bit) > 7) { \
49 (Byte)++; \
50 (Bit) = 0; \
51 } \
52 } while (0)
53
54 //
55 // USBHC_MEM_POOL is used to manage the memory used by USB
56 // host controller. XHCI requires the control memory and transfer
57 // data to be on the same 4G memory.
58 //
59 typedef struct _USBHC_MEM_POOL {
60 BOOLEAN Check4G;
61 UINT32 Which4G;
62 USBHC_MEM_BLOCK *Head;
63 } USBHC_MEM_POOL;
64
65 /**
66 Calculate the corresponding pci bus address according to the Mem parameter.
67
68 @param Pool The memory pool of the host controller.
69 @param Mem The pointer to host memory.
70 @param Size The size of the memory region.
71
72 @return The pci memory address
73
74 **/
75 EFI_PHYSICAL_ADDRESS
76 UsbHcGetPciAddrForHostAddr (
77 IN USBHC_MEM_POOL *Pool,
78 IN VOID *Mem,
79 IN UINTN Size
80 );
81
82 /**
83 Calculate the corresponding host address according to the pci address.
84
85 @param Pool The memory pool of the host controller.
86 @param Mem The pointer to pci memory.
87 @param Size The size of the memory region.
88
89 @return The host memory address
90
91 **/
92 EFI_PHYSICAL_ADDRESS
93 UsbHcGetHostAddrForPciAddr (
94 IN USBHC_MEM_POOL *Pool,
95 IN VOID *Mem,
96 IN UINTN Size
97 );
98
99 /**
100 Allocates pages at a specified alignment.
101
102 If Alignment is not a power of two and Alignment is not zero, then ASSERT().
103
104 @param Pages The number of pages to allocate.
105 @param Alignment The requested alignment of the allocation. Must be a power of two.
106 @param HostAddress The system memory address to map to the PCI controller.
107 @param DeviceAddress The resulting map address for the bus master PCI controller to
108 use to access the hosts HostAddress.
109 @param Mapping A resulting value to pass to Unmap().
110
111 @retval EFI_SUCCESS Success to allocate aligned pages.
112 @retval EFI_INVALID_PARAMETER Pages or Alignment is not valid.
113 @retval EFI_OUT_OF_RESOURCES Do not have enough resources to allocate memory.
114
115 **/
116 EFI_STATUS
117 UsbHcAllocateAlignedPages (
118 IN UINTN Pages,
119 IN UINTN Alignment,
120 OUT VOID **HostAddress,
121 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
122 OUT VOID **Mapping
123 );
124
125 /**
126 Frees memory that was allocated with UsbHcAllocateAlignedPages().
127
128 @param HostAddress The system memory address to map to the PCI controller.
129 @param Pages The number of pages to free.
130 @param Mapping The mapping value returned from Map().
131
132 **/
133 VOID
134 UsbHcFreeAlignedPages (
135 IN VOID *HostAddress,
136 IN UINTN Pages,
137 IN VOID *Mapping
138 );
139
140 #endif