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