]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/EhciDxe/Ehci.h
fixed DMA not be stopped issue when gBS->ExitBootServices called.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / EhciDxe / Ehci.h
1 /** @file
2
3 Provides some data struct used by EHCI controller driver.
4
5 Copyright (c) 2006 - 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_H_
17 #define _EFI_EHCI_H_
18
19
20 #include <Uefi.h>
21
22 #include <Protocol/Usb2HostController.h>
23 #include <Protocol/PciIo.h>
24
25 #include <Guid/EventGroup.h>
26
27 #include <Library/DebugLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/PcdLib.h>
35
36 #include <IndustryStandard/Pci22.h>
37
38 typedef struct _USB2_HC_DEV USB2_HC_DEV;
39
40 #include "UsbHcMem.h"
41 #include "EhciReg.h"
42 #include "EhciUrb.h"
43 #include "EhciSched.h"
44 #include "EhciDebug.h"
45 #include "ComponentName.h"
46
47 typedef enum {
48 EHC_1_MICROSECOND = 1,
49 EHC_1_MILLISECOND = 1000 * EHC_1_MICROSECOND,
50 EHC_1_SECOND = 1000 * EHC_1_MILLISECOND,
51
52 //
53 // EHCI register operation timeout, set by experience
54 //
55 EHC_RESET_TIMEOUT = 1 * EHC_1_SECOND,
56 EHC_GENERIC_TIMEOUT = 10 * EHC_1_MILLISECOND,
57
58 //
59 // Wait for roothub port power stable, refers to Spec[EHCI1.0-2.3.9]
60 //
61 EHC_ROOT_PORT_RECOVERY_STALL = 20 * EHC_1_MILLISECOND,
62
63 //
64 // Sync and Async transfer polling interval, set by experience,
65 // and the unit of Async is 100us, means 50ms as interval.
66 //
67 EHC_SYNC_POLL_INTERVAL = 20 * EHC_1_MICROSECOND,
68 EHC_ASYNC_POLL_INTERVAL = 50 * 10000U
69 } EHC_TIMEOUT_EXPERIENCE_VALUE;
70
71
72 //
73 // EHC raises TPL to TPL_NOTIFY to serialize all its operations
74 // to protect shared data structures.
75 //
76 #define EHC_TPL TPL_NOTIFY
77
78 //
79 //Iterate through the doule linked list. NOT delete safe
80 //
81 #define EFI_LIST_FOR_EACH(Entry, ListHead) \
82 for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
83
84 //
85 //Iterate through the doule linked list. This is delete-safe.
86 //Don't touch NextEntry
87 //
88 #define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
89 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\
90 Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)
91
92 #define EFI_LIST_CONTAINER(Entry, Type, Field) BASE_CR(Entry, Type, Field)
93
94
95 #define EHC_LOW_32BIT(Addr64) ((UINT32)(((UINTN)(Addr64)) & 0XFFFFFFFF))
96 #define EHC_HIGH_32BIT(Addr64) ((UINT32)(RShiftU64((UINTN)(Addr64), 32) & 0XFFFFFFFF))
97 #define EHC_BIT_IS_SET(Data, Bit) ((BOOLEAN)(((Data) & (Bit)) == (Bit)))
98
99 #define EHC_REG_BIT_IS_SET(Ehc, Offset, Bit) \
100 (EHC_BIT_IS_SET(EhcReadOpReg ((Ehc), (Offset)), (Bit)))
101
102 #define USB2_HC_DEV_SIGNATURE SIGNATURE_32 ('e', 'h', 'c', 'i')
103 #define EHC_FROM_THIS(a) CR(a, USB2_HC_DEV, Usb2Hc, USB2_HC_DEV_SIGNATURE)
104
105 struct _USB2_HC_DEV {
106 UINTN Signature;
107 EFI_USB2_HC_PROTOCOL Usb2Hc;
108
109 EFI_PCI_IO_PROTOCOL *PciIo;
110 UINT64 OriginalPciAttributes;
111 USBHC_MEM_POOL *MemPool;
112
113 //
114 // Schedule data shared between asynchronous and periodic
115 // transfers:
116 // ShortReadStop, as its name indicates, is used to terminate
117 // the short read except the control transfer. EHCI follows
118 // the alternative next QTD point when a short read happens.
119 // For control transfer, even the short read happens, try the
120 // status stage.
121 //
122 EHC_QTD *ShortReadStop;
123 EFI_EVENT PollTimer;
124
125 //
126 // ExitBootServicesEvent is used to stop the EHC DMA operation
127 // after exit boot service.
128 //
129 EFI_EVENT ExitBootServiceEvent;
130
131 //
132 // Asynchronous(bulk and control) transfer schedule data:
133 // ReclaimHead is used as the head of the asynchronous transfer
134 // list. It acts as the reclamation header.
135 //
136 EHC_QH *ReclaimHead;
137
138 //
139 // Peroidic (interrupt) transfer schedule data:
140 //
141 VOID *PeriodFrame; // Mapped as common buffer
142 VOID *PeriodFrameHost;
143 VOID *PeriodFrameMap;
144
145 EHC_QH *PeriodOne;
146 LIST_ENTRY AsyncIntTransfers;
147
148 //
149 // EHCI configuration data
150 //
151 UINT32 HcStructParams; // Cache of HC structure parameter, EHC_HCSPARAMS_OFFSET
152 UINT32 HcCapParams; // Cache of HC capability parameter, HCCPARAMS
153 UINT32 CapLen; // Capability length
154 UINT32 High32bitAddr;
155
156 //
157 // Misc
158 //
159 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
160 };
161
162
163 extern EFI_DRIVER_BINDING_PROTOCOL gEhciDriverBinding;
164 extern EFI_COMPONENT_NAME_PROTOCOL gEhciComponentName;
165 extern EFI_COMPONENT_NAME2_PROTOCOL gEhciComponentName2;
166
167 /**
168 Test to see if this driver supports ControllerHandle. Any
169 ControllerHandle that has Usb2HcProtocol installed will
170 be supported.
171
172 @param This Protocol instance pointer.
173 @param Controller Handle of device to test.
174 @param RemainingDevicePath Not used.
175
176 @return EFI_SUCCESS This driver supports this device.
177 @return EFI_UNSUPPORTED This driver does not support this device.
178
179 **/
180 EFI_STATUS
181 EFIAPI
182 EhcDriverBindingSupported (
183 IN EFI_DRIVER_BINDING_PROTOCOL *This,
184 IN EFI_HANDLE Controller,
185 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
186 );
187
188 /**
189 Starting the Usb EHCI Driver.
190
191 @param This Protocol instance pointer.
192 @param Controller Handle of device to test.
193 @param RemainingDevicePath Not used.
194
195 @return EFI_SUCCESS supports this device.
196 @return EFI_UNSUPPORTED do not support this device.
197 @return EFI_DEVICE_ERROR cannot be started due to device Error.
198 @return EFI_OUT_OF_RESOURCES cannot allocate resources.
199
200 **/
201 EFI_STATUS
202 EFIAPI
203 EhcDriverBindingStart (
204 IN EFI_DRIVER_BINDING_PROTOCOL *This,
205 IN EFI_HANDLE Controller,
206 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
207 );
208
209 /**
210 Stop this driver on ControllerHandle. Support stoping any child handles
211 created by this driver.
212
213 @param This Protocol instance pointer.
214 @param Controller Handle of device to stop driver on.
215 @param NumberOfChildren Number of Children in the ChildHandleBuffer.
216 @param ChildHandleBuffer List of handles for the children we need to stop.
217
218 @return EFI_SUCCESS Success.
219 @return EFI_DEVICE_ERROR Fail.
220
221 **/
222 EFI_STATUS
223 EFIAPI
224 EhcDriverBindingStop (
225 IN EFI_DRIVER_BINDING_PROTOCOL *This,
226 IN EFI_HANDLE Controller,
227 IN UINTN NumberOfChildren,
228 IN EFI_HANDLE *ChildHandleBuffer
229 );
230
231 #endif
232