]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/UhciDxe/Uhci.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UhciDxe / Uhci.h
1 /** @file
2
3 The definition for UHCI driver model and HC protocol routines.
4
5 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _EFI_UHCI_H_
11 #define _EFI_UHCI_H_
12
13
14 #include <Uefi.h>
15
16 #include <Protocol/Usb2HostController.h>
17 #include <Protocol/UsbHostController.h>
18 #include <Protocol/PciIo.h>
19
20 #include <Guid/EventGroup.h>
21
22 #include <Library/DebugLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/UefiDriverEntryPoint.h>
25 #include <Library/UefiBootServicesTableLib.h>
26 #include <Library/UefiLib.h>
27 #include <Library/BaseLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/PcdLib.h>
30 #include <Library/ReportStatusCodeLib.h>
31
32 #include <IndustryStandard/Pci.h>
33
34 typedef struct _USB_HC_DEV USB_HC_DEV;
35
36 #include "UsbHcMem.h"
37 #include "UhciQueue.h"
38 #include "UhciReg.h"
39 #include "UhciSched.h"
40 #include "UhciDebug.h"
41 #include "ComponentName.h"
42
43 //
44 // UHC timeout experience values
45 //
46
47 #define UHC_1_MICROSECOND 1
48 #define UHC_1_MILLISECOND (1000 * UHC_1_MICROSECOND)
49 #define UHC_1_SECOND (1000 * UHC_1_MILLISECOND)
50
51 //
52 // UHCI register operation timeout, set by experience
53 //
54 #define UHC_GENERIC_TIMEOUT UHC_1_SECOND
55
56 //
57 // Wait for force global resume(FGR) complete, refers to
58 // specification[UHCI11-2.1.1]
59 //
60 #define UHC_FORCE_GLOBAL_RESUME_STALL (20 * UHC_1_MILLISECOND)
61
62 //
63 // Wait for roothub port reset and recovery, reset stall
64 // is set by experience, and recovery stall refers to
65 // specification[UHCI11-2.1.1]
66 //
67 #define UHC_ROOT_PORT_RESET_STALL (50 * UHC_1_MILLISECOND)
68 #define UHC_ROOT_PORT_RECOVERY_STALL (10 * UHC_1_MILLISECOND)
69
70 //
71 // Sync and Async transfer polling interval, set by experience,
72 // and the unit of Async is 100us.
73 //
74 #define UHC_SYNC_POLL_INTERVAL (1 * UHC_1_MILLISECOND)
75 #define UHC_ASYNC_POLL_INTERVAL EFI_TIMER_PERIOD_MILLISECONDS(1)
76
77 //
78 // UHC raises TPL to TPL_NOTIFY to serialize all its operations
79 // to protect shared data structures.
80 //
81 #define UHCI_TPL TPL_NOTIFY
82
83 #define USB_HC_DEV_SIGNATURE SIGNATURE_32 ('u', 'h', 'c', 'i')
84
85 #pragma pack(1)
86 typedef struct {
87 UINT8 ProgInterface;
88 UINT8 SubClassCode;
89 UINT8 BaseCode;
90 } USB_CLASSC;
91 #pragma pack()
92
93 #define UHC_FROM_USB2_HC_PROTO(This) CR(This, USB_HC_DEV, Usb2Hc, USB_HC_DEV_SIGNATURE)
94
95 //
96 // USB_HC_DEV support the UHCI hardware controller. It schedules
97 // the asynchronous interrupt transfer with the same method as
98 // EHCI: a reversed tree structure. For synchronous interrupt,
99 // control and bulk transfer, it uses three static queue head to
100 // schedule them. SyncIntQh is for interrupt transfer. LsCtrlQh is
101 // for LOW speed control transfer, and FsCtrlBulkQh is for FULL
102 // speed control or bulk transfer. This is because FULL speed contrl
103 // or bulk transfer can reclaim the unused bandwidth. Some USB
104 // device requires this bandwidth reclamation capability.
105 //
106 struct _USB_HC_DEV {
107 UINT32 Signature;
108 EFI_USB2_HC_PROTOCOL Usb2Hc;
109 EFI_PCI_IO_PROTOCOL *PciIo;
110 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
111 UINT64 OriginalPciAttributes;
112
113 //
114 // Schedule data structures
115 //
116 UINT32 *FrameBase; // the buffer pointed by this pointer is used to store pci bus address of the QH descriptor.
117 UINT32 *FrameBaseHostAddr; // the buffer pointed by this pointer is used to store host memory address of the QH descriptor.
118 UHCI_QH_SW *SyncIntQh;
119 UHCI_QH_SW *CtrlQh;
120 UHCI_QH_SW *BulkQh;
121
122 //
123 // Structures to maintain asynchronus interrupt transfers.
124 // When asynchronous interrutp transfer is unlinked from
125 // the frame list, the hardware may still hold a pointer
126 // to it. To synchronize with hardware, its resoureces are
127 // released in two steps using Recycle and RecycleWait.
128 // Check the asynchronous interrupt management routines.
129 //
130 LIST_ENTRY AsyncIntList;
131 EFI_EVENT AsyncIntMonitor;
132 UHCI_ASYNC_REQUEST *Recycle;
133 UHCI_ASYNC_REQUEST *RecycleWait;
134
135
136 UINTN RootPorts;
137 USBHC_MEM_POOL *MemPool;
138 EFI_UNICODE_STRING_TABLE *CtrlNameTable;
139 VOID *FrameMapping;
140
141 //
142 // ExitBootServicesEvent is used to stop the EHC DMA operation
143 // after exit boot service.
144 //
145 EFI_EVENT ExitBootServiceEvent;
146 };
147
148 extern EFI_DRIVER_BINDING_PROTOCOL gUhciDriverBinding;
149 extern EFI_COMPONENT_NAME_PROTOCOL gUhciComponentName;
150 extern EFI_COMPONENT_NAME2_PROTOCOL gUhciComponentName2;
151
152 /**
153 Test to see if this driver supports ControllerHandle. Any
154 ControllerHandle that has UsbHcProtocol installed will be supported.
155
156 @param This Protocol instance pointer.
157 @param Controller Handle of device to test.
158 @param RemainingDevicePath Not used.
159
160 @return EFI_SUCCESS This driver supports this device.
161 @return EFI_UNSUPPORTED This driver does not support this device.
162
163 **/
164 EFI_STATUS
165 EFIAPI
166 UhciDriverBindingSupported (
167 IN EFI_DRIVER_BINDING_PROTOCOL *This,
168 IN EFI_HANDLE Controller,
169 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
170 );
171
172 /**
173 Starting the Usb UHCI Driver.
174
175 @param This Protocol instance pointer.
176 @param Controller Handle of device to test.
177 @param RemainingDevicePath Not used.
178
179 @retval EFI_SUCCESS This driver supports this device.
180 @retval EFI_UNSUPPORTED This driver does not support this device.
181 @retval EFI_DEVICE_ERROR This driver cannot be started due to device Error.
182 EFI_OUT_OF_RESOURCES- Failed due to resource shortage.
183
184 **/
185 EFI_STATUS
186 EFIAPI
187 UhciDriverBindingStart (
188 IN EFI_DRIVER_BINDING_PROTOCOL *This,
189 IN EFI_HANDLE Controller,
190 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
191 );
192
193 /**
194 Stop this driver on ControllerHandle. Support stopping any child handles
195 created by this driver.
196
197 @param This Protocol instance pointer.
198 @param Controller Handle of device to stop driver on.
199 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
200 @param ChildHandleBuffer List of handles for the children we need to stop.
201
202 @return EFI_SUCCESS
203 @return others
204
205 **/
206 EFI_STATUS
207 EFIAPI
208 UhciDriverBindingStop (
209 IN EFI_DRIVER_BINDING_PROTOCOL *This,
210 IN EFI_HANDLE Controller,
211 IN UINTN NumberOfChildren,
212 IN EFI_HANDLE *ChildHandleBuffer
213 );
214
215 #endif