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