]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Pci/EhciDxe/UsbHcMem.h
add error handling on usb related modules.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciDxe / UsbHcMem.h
CommitLineData
913cb9dc 1/** @file\r
2\r
78c2ffb5 3 This file contains the definination for host controller memory management routines.\r
4\r
597f4ee2 5Copyright (c) 2007 - 2009, Intel Corporation\r
913cb9dc 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
913cb9dc 14**/\r
15\r
16#ifndef _EFI_EHCI_MEM_H_\r
17#define _EFI_EHCI_MEM_H_\r
18\r
913cb9dc 19#define USB_HC_BIT(a) ((UINTN)(1 << (a)))\r
20\r
21#define USB_HC_BIT_IS_SET(Data, Bit) \\r
22 ((BOOLEAN)(((Data) & USB_HC_BIT(Bit)) == USB_HC_BIT(Bit)))\r
23\r
24#define USB_HC_HIGH_32BIT(Addr64) \\r
25 ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))\r
26\r
fd0d4841 27typedef struct _USBHC_MEM_BLOCK {\r
913cb9dc 28 UINT8 *Bits; // Bit array to record which unit is allocated\r
29 UINTN BitsLen;\r
30 UINT8 *Buf;\r
31 UINT8 *BufHost;\r
32 UINTN BufLen; // Memory size in bytes\r
33 VOID *Mapping;\r
fd0d4841 34 struct _USBHC_MEM_BLOCK *Next;\r
35} USBHC_MEM_BLOCK;\r
913cb9dc 36\r
37//\r
38// USBHC_MEM_POOL is used to manage the memory used by USB\r
39// host controller. EHCI requires the control memory and transfer\r
40// data to be on the same 4G memory.\r
41//\r
42typedef struct _USBHC_MEM_POOL {\r
43 EFI_PCI_IO_PROTOCOL *PciIo;\r
44 BOOLEAN Check4G;\r
45 UINT32 Which4G;\r
46 USBHC_MEM_BLOCK *Head;\r
47} USBHC_MEM_POOL;\r
48\r
78c2ffb5 49typedef enum {\r
913cb9dc 50 USBHC_MEM_UNIT = 64, // Memory allocation unit, must be 2^n, n>4\r
51\r
52 USBHC_MEM_UNIT_MASK = USBHC_MEM_UNIT - 1,\r
c52fa98c 53 USBHC_MEM_DEFAULT_PAGES = 16\r
78c2ffb5 54} USBHC_MEM_UNIT_DATA;\r
913cb9dc 55\r
56#define USBHC_MEM_ROUND(Len) (((Len) + USBHC_MEM_UNIT_MASK) & (~USBHC_MEM_UNIT_MASK))\r
57\r
58//\r
59// Advance the byte and bit to the next bit, adjust byte accordingly.\r
60//\r
61#define NEXT_BIT(Byte, Bit) \\r
62 do { \\r
63 (Bit)++; \\r
64 if ((Bit) > 7) { \\r
65 (Byte)++; \\r
66 (Bit) = 0; \\r
67 } \\r
68 } while (0)\r
69\r
70\r
71\r
78c2ffb5 72/**\r
73 Initialize the memory management pool for the host controller.\r
74\r
75 @param PciIo The PciIo that can be used to access the host controller.\r
76 @param Check4G Whether the host controller requires allocated memory\r
77 from one 4G address space.\r
78 @param Which4G The 4G memory area each memory allocated should be from.\r
79\r
80 @retval EFI_SUCCESS The memory pool is initialized.\r
81 @retval EFI_OUT_OF_RESOURCE Fail to init the memory pool.\r
82\r
83**/\r
913cb9dc 84USBHC_MEM_POOL *\r
85UsbHcInitMemPool (\r
86 IN EFI_PCI_IO_PROTOCOL *PciIo,\r
87 IN BOOLEAN Check4G,\r
88 IN UINT32 Which4G\r
ed66e1bc 89 );\r
913cb9dc 90\r
91\r
913cb9dc 92/**\r
78c2ffb5 93 Release the memory management pool.\r
913cb9dc 94\r
78c2ffb5 95 @param Pool The USB memory pool to free.\r
913cb9dc 96\r
78c2ffb5 97 @retval EFI_SUCCESS The memory pool is freed.\r
98 @retval EFI_DEVICE_ERROR Failed to free the memory pool.\r
913cb9dc 99\r
100**/\r
101EFI_STATUS\r
102UsbHcFreeMemPool (\r
103 IN USBHC_MEM_POOL *Pool\r
ed66e1bc 104 );\r
913cb9dc 105\r
106\r
913cb9dc 107/**\r
108 Allocate some memory from the host controller's memory pool\r
109 which can be used to communicate with host controller.\r
110\r
78c2ffb5 111 @param Pool The host controller's memory pool.\r
112 @param Size Size of the memory to allocate.\r
913cb9dc 113\r
78c2ffb5 114 @return The allocated memory or NULL.\r
913cb9dc 115\r
116**/\r
117VOID *\r
118UsbHcAllocateMem (\r
119 IN USBHC_MEM_POOL *Pool,\r
120 IN UINTN Size\r
ed66e1bc 121 );\r
913cb9dc 122\r
123\r
913cb9dc 124/**\r
78c2ffb5 125 Free the allocated memory back to the memory pool.\r
913cb9dc 126\r
78c2ffb5 127 @param Pool The memory pool of the host controller.\r
128 @param Mem The memory to free.\r
129 @param Size The size of the memory to free.\r
913cb9dc 130\r
913cb9dc 131**/\r
132VOID\r
133UsbHcFreeMem (\r
134 IN USBHC_MEM_POOL *Pool,\r
135 IN VOID *Mem,\r
136 IN UINTN Size\r
ed66e1bc 137 );\r
739802e4 138\r
139/**\r
140 Get the pci memory address according to the allocated host memory address.\r
141\r
142 @param Pool The memory pool of the host controller.\r
143 @param Mem The memory to free.\r
144 @param Size The size of the memory to free.\r
145\r
146 @return the pci memory address\r
147**/\r
148EFI_PHYSICAL_ADDRESS\r
149UsbHcGetPciAddressForHostMem (\r
150 IN USBHC_MEM_POOL *Pool,\r
151 IN VOID *Mem,\r
152 IN UINTN Size\r
153 );\r
154\r
913cb9dc 155#endif\r