]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/XhciPei/UsbHcMem.h
MdeModulePkg XhciPei: Fix build failure "conversion from 'UINT32' to 'UINT8', possibl...
[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
32 USBHC_MEM_BLOCK *Next;\r
33};\r
34\r
35//\r
36// Memory allocation unit, must be 2^n, n>4\r
37//\r
38#define USBHC_MEM_UNIT 64\r
39\r
40#define USBHC_MEM_UNIT_MASK (USBHC_MEM_UNIT - 1)\r
41#define USBHC_MEM_ROUND(Len) (((Len) + USBHC_MEM_UNIT_MASK) & (~USBHC_MEM_UNIT_MASK))\r
42\r
43#define USB_HC_BIT(a) ((UINTN)(1 << (a)))\r
44\r
45#define USB_HC_BIT_IS_SET(Data, Bit) \\r
46 ((BOOLEAN)(((Data) & USB_HC_BIT(Bit)) == USB_HC_BIT(Bit)))\r
47\r
48//\r
49// Advance the byte and bit to the next bit, adjust byte accordingly.\r
50//\r
51#define NEXT_BIT(Byte, Bit) \\r
52 do { \\r
53 (Bit)++; \\r
54 if ((Bit) > 7) { \\r
55 (Byte)++; \\r
56 (Bit) = 0; \\r
57 } \\r
58 } while (0)\r
59\r
60//\r
61// USBHC_MEM_POOL is used to manage the memory used by USB\r
62// host controller. XHCI requires the control memory and transfer\r
63// data to be on the same 4G memory.\r
64//\r
65typedef struct _USBHC_MEM_POOL {\r
66 BOOLEAN Check4G;\r
67 UINT32 Which4G;\r
68 USBHC_MEM_BLOCK *Head;\r
69} USBHC_MEM_POOL;\r
70\r
71/**\r
72 Calculate the corresponding pci bus address according to the Mem parameter.\r
73\r
74 @param Pool The memory pool of the host controller.\r
75 @param Mem The pointer to host memory.\r
76 @param Size The size of the memory region.\r
77\r
78 @return The pci memory address\r
79\r
80**/\r
81EFI_PHYSICAL_ADDRESS\r
82UsbHcGetPciAddrForHostAddr (\r
83 IN USBHC_MEM_POOL *Pool,\r
84 IN VOID *Mem,\r
85 IN UINTN Size\r
86 );\r
87\r
88/**\r
89 Calculate the corresponding host address according to the pci address.\r
90\r
91 @param Pool The memory pool of the host controller.\r
92 @param Mem The pointer to pci memory.\r
93 @param Size The size of the memory region.\r
94\r
95 @return The host memory address\r
96\r
97**/\r
98EFI_PHYSICAL_ADDRESS\r
99UsbHcGetHostAddrForPciAddr (\r
100 IN USBHC_MEM_POOL *Pool,\r
101 IN VOID *Mem,\r
102 IN UINTN Size\r
103 );\r
104\r
105/**\r
106 Allocates pages at a specified alignment.\r
107\r
108 If Alignment is not a power of two and Alignment is not zero, then ASSERT().\r
109\r
110 @param Pages The number of pages to allocate.\r
111 @param Alignment The requested alignment of the allocation. Must be a power of two.\r
112 @param HostAddress The system memory address to map to the PCI controller.\r
113 @param DeviceAddress The resulting map address for the bus master PCI controller to\r
114 use to access the hosts HostAddress.\r
115\r
116 @retval EFI_SUCCESS Success to allocate aligned pages.\r
117 @retval EFI_INVALID_PARAMETER Pages or Alignment is not valid.\r
118 @retval EFI_OUT_OF_RESOURCES Do not have enough resources to allocate memory.\r
119\r
120**/\r
121EFI_STATUS\r
122UsbHcAllocateAlignedPages (\r
123 IN UINTN Pages,\r
124 IN UINTN Alignment,\r
125 OUT VOID **HostAddress,\r
126 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress\r
127 );\r
128\r
129/**\r
130 Frees memory that was allocated with UsbHcAllocateAlignedPages().\r
131\r
132 @param HostAddress The system memory address to map to the PCI controller.\r
133 @param Pages The number of pages to free.\r
134\r
135**/\r
136VOID\r
137UsbHcFreeAlignedPages (\r
138 IN VOID *HostAddress,\r
139 IN UINTN Pages\r
140 );\r
141\r
142#endif\r