]>
Commit | Line | Data |
---|---|---|
9b6bbcdb MK |
1 | /** @file\r |
2 | This file contains the definination for host controller memory\r | |
3 | management routines.\r | |
4 | \r | |
5 | Copyright (c) 2013-2015 Intel Corporation.\r | |
6 | \r | |
7 | This program and the accompanying materials\r | |
8 | are licensed and made available under the terms and conditions of the BSD License\r | |
9 | which accompanies this distribution. The full text of the license may be found at\r | |
10 | http://opensource.org/licenses/bsd-license.php\r | |
11 | \r | |
12 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
13 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
14 | \r | |
15 | **/\r | |
16 | \r | |
17 | #ifndef _USB_HC_MEM_H_\r | |
18 | #define _USB_HC_MEM_H_\r | |
19 | \r | |
20 | #define USB_HC_BIT(a) ((UINTN)(1 << (a)))\r | |
21 | \r | |
22 | #define USB_HC_BIT_IS_SET(Data, Bit) \\r | |
23 | ((BOOLEAN)(((Data) & USB_HC_BIT(Bit)) == USB_HC_BIT(Bit)))\r | |
24 | \r | |
25 | #define USB_HC_HIGH_32BIT(Addr64) \\r | |
26 | ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))\r | |
27 | \r | |
28 | typedef struct _USBHC_MEM_BLOCK USBHC_MEM_BLOCK;\r | |
29 | struct _USBHC_MEM_BLOCK {\r | |
30 | UINT8 *Bits; // Bit array to record which unit is allocated\r | |
31 | UINTN BitsLen;\r | |
32 | UINT8 *Buf;\r | |
33 | UINT8 *BufHost;\r | |
34 | UINTN BufLen; // Memory size in bytes\r | |
35 | VOID *Mapping;\r | |
36 | USBHC_MEM_BLOCK *Next;\r | |
37 | };\r | |
38 | \r | |
39 | //\r | |
40 | // USBHC_MEM_POOL is used to manage the memory used by USB\r | |
41 | // host controller. EHCI requires the control memory and transfer\r | |
42 | // data to be on the same 4G memory.\r | |
43 | //\r | |
44 | typedef struct _USBHC_MEM_POOL {\r | |
45 | EFI_PCI_IO_PROTOCOL *PciIo;\r | |
46 | BOOLEAN Check4G;\r | |
47 | UINT32 Which4G;\r | |
48 | USBHC_MEM_BLOCK *Head;\r | |
49 | } USBHC_MEM_POOL;\r | |
50 | \r | |
51 | //\r | |
52 | // Memory allocation unit, must be 2^n, n>4\r | |
53 | //\r | |
54 | #define USBHC_MEM_UNIT 64\r | |
55 | \r | |
56 | #define USBHC_MEM_UNIT_MASK (USBHC_MEM_UNIT - 1)\r | |
57 | #define USBHC_MEM_DEFAULT_PAGES 16\r | |
58 | \r | |
59 | #define USBHC_MEM_ROUND(Len) (((Len) + USBHC_MEM_UNIT_MASK) & (~USBHC_MEM_UNIT_MASK))\r | |
60 | \r | |
61 | //\r | |
62 | // Advance the byte and bit to the next bit, adjust byte accordingly.\r | |
63 | //\r | |
64 | #define NEXT_BIT(Byte, Bit) \\r | |
65 | do { \\r | |
66 | (Bit)++; \\r | |
67 | if ((Bit) > 7) { \\r | |
68 | (Byte)++; \\r | |
69 | (Bit) = 0; \\r | |
70 | } \\r | |
71 | } while (0)\r | |
72 | \r | |
73 | \r | |
74 | \r | |
75 | /**\r | |
76 | Initialize the memory management pool for the host controller.\r | |
77 | \r | |
78 | @param PciIo The PciIo that can be used to access the host controller.\r | |
79 | @param Check4G Whether the host controller requires allocated memory\r | |
80 | from one 4G address space.\r | |
81 | @param Which4G The 4G memory area each memory allocated should be from.\r | |
82 | \r | |
83 | @retval EFI_SUCCESS The memory pool is initialized.\r | |
84 | @retval EFI_OUT_OF_RESOURCE Fail to init the memory pool.\r | |
85 | \r | |
86 | **/\r | |
87 | USBHC_MEM_POOL *\r | |
88 | UsbHcInitMemPool (\r | |
89 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
90 | IN BOOLEAN Check4G,\r | |
91 | IN UINT32 Which4G\r | |
92 | );\r | |
93 | \r | |
94 | \r | |
95 | /**\r | |
96 | Release the memory management pool.\r | |
97 | \r | |
98 | @param Pool The USB memory pool to free.\r | |
99 | \r | |
100 | @retval EFI_SUCCESS The memory pool is freed.\r | |
101 | @retval EFI_DEVICE_ERROR Failed to free the memory pool.\r | |
102 | \r | |
103 | **/\r | |
104 | EFI_STATUS\r | |
105 | UsbHcFreeMemPool (\r | |
106 | IN USBHC_MEM_POOL *Pool\r | |
107 | );\r | |
108 | \r | |
109 | \r | |
110 | /**\r | |
111 | Allocate some memory from the host controller's memory pool\r | |
112 | which can be used to communicate with host controller.\r | |
113 | \r | |
114 | @param Pool The host controller's memory pool.\r | |
115 | @param Size Size of the memory to allocate.\r | |
116 | \r | |
117 | @return The allocated memory or NULL.\r | |
118 | \r | |
119 | **/\r | |
120 | VOID *\r | |
121 | UsbHcAllocateMem (\r | |
122 | IN USBHC_MEM_POOL *Pool,\r | |
123 | IN UINTN Size\r | |
124 | );\r | |
125 | \r | |
126 | \r | |
127 | /**\r | |
128 | Free the allocated memory back to the memory pool.\r | |
129 | \r | |
130 | @param Pool The memory pool of the host controller.\r | |
131 | @param Mem The memory to free.\r | |
132 | @param Size The size of the memory to free.\r | |
133 | \r | |
134 | **/\r | |
135 | VOID\r | |
136 | UsbHcFreeMem (\r | |
137 | IN USBHC_MEM_POOL *Pool,\r | |
138 | IN VOID *Mem,\r | |
139 | IN UINTN Size\r | |
140 | );\r | |
141 | \r | |
142 | /**\r | |
143 | Calculate the corresponding pci bus address according to the Mem parameter.\r | |
144 | \r | |
145 | @param Pool The memory pool of the host controller.\r | |
146 | @param Mem The pointer to host memory.\r | |
147 | @param Size The size of the memory region.\r | |
148 | \r | |
149 | @return the pci memory address\r | |
150 | **/\r | |
151 | EFI_PHYSICAL_ADDRESS\r | |
152 | UsbHcGetPciAddressForHostMem (\r | |
153 | IN USBHC_MEM_POOL *Pool,\r | |
154 | IN VOID *Mem,\r | |
155 | IN UINTN Size\r | |
156 | );\r | |
157 | \r | |
158 | #endif\r |