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