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