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