]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/EhciPei/UsbHcMem.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciPei / UsbHcMem.h
1 /** @file
2 Private Header file for Usb Host Controller PEIM
3
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _EFI_EHCI_MEM_H_
11 #define _EFI_EHCI_MEM_H_
12
13 #include <Uefi.h>
14 #include <IndustryStandard/Pci22.h>
15
16 #define USB_HC_BIT(a) ((UINTN)(1 << (a)))
17
18 #define USB_HC_BIT_IS_SET(Data, Bit) \
19 ((BOOLEAN)(((Data) & USB_HC_BIT(Bit)) == USB_HC_BIT(Bit)))
20
21 #define USB_HC_HIGH_32BIT(Addr64) \
22 ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
23
24 typedef struct _USBHC_MEM_BLOCK USBHC_MEM_BLOCK;
25
26 struct _USBHC_MEM_BLOCK {
27 UINT8 *Bits; // Bit array to record which unit is allocated
28 UINTN BitsLen;
29 UINT8 *Buf;
30 UINT8 *BufHost;
31 UINTN BufLen; // Memory size in bytes
32 VOID *Mapping;
33 USBHC_MEM_BLOCK *Next;
34 };
35
36 //
37 // USBHC_MEM_POOL is used to manage the memory used by USB
38 // host controller. EHCI requires the control memory and transfer
39 // data to be on the same 4G memory.
40 //
41 typedef struct _USBHC_MEM_POOL {
42 BOOLEAN Check4G;
43 UINT32 Which4G;
44 USBHC_MEM_BLOCK *Head;
45 } USBHC_MEM_POOL;
46
47 //
48 // Memory allocation unit, must be 2^n, n>4
49 //
50 #define USBHC_MEM_UNIT 64
51
52 #define USBHC_MEM_UNIT_MASK (USBHC_MEM_UNIT - 1)
53 #define USBHC_MEM_DEFAULT_PAGES 16
54
55 #define USBHC_MEM_ROUND(Len) (((Len) + USBHC_MEM_UNIT_MASK) & (~USBHC_MEM_UNIT_MASK))
56
57 //
58 // Advance the byte and bit to the next bit, adjust byte accordingly.
59 //
60 #define NEXT_BIT(Byte, Bit) \
61 do { \
62 (Bit)++; \
63 if ((Bit) > 7) { \
64 (Byte)++; \
65 (Bit) = 0; \
66 } \
67 } while (0)
68
69
70 /**
71 Calculate the corresponding pci bus address according to the Mem parameter.
72
73 @param Pool The memory pool of the host controller.
74 @param Mem The pointer to host memory.
75 @param Size The size of the memory region.
76
77 @return the pci memory address
78 **/
79 EFI_PHYSICAL_ADDRESS
80 UsbHcGetPciAddressForHostMem (
81 IN USBHC_MEM_POOL *Pool,
82 IN VOID *Mem,
83 IN UINTN Size
84 );
85
86 #endif