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