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