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