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