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