Import EhciDxe and UhciDxe into MdeModulePkg.
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UhciDxe / UhciSched.h
1 /** @file
2
3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 UhciSched.h
15
16 Abstract:
17
18 The definition for EHCI register operation routines.
19
20 Revision History
21
22
23 **/
24
25 #ifndef _EFI_UHCI_SCHED_H_
26 #define _EFI_UHCI_SCHED_H_
27
28
29 enum {
30 UHCI_ASYNC_INT_SIGNATURE = EFI_SIGNATURE_32 ('u', 'h', 'c', 'a'),
31
32 //
33 // The failure mask for USB transfer return status. If any of
34 // these bit is set, the transfer failed. EFI_USB_ERR_NOEXECUTE
35 // and EFI_USB_ERR_NAK are not considered as error condition:
36 // the transfer is still going on.
37 //
38 USB_ERR_FAIL_MASK = EFI_USB_ERR_STALL | EFI_USB_ERR_BUFFER |
39 EFI_USB_ERR_BABBLE | EFI_USB_ERR_CRC |
40 EFI_USB_ERR_TIMEOUT | EFI_USB_ERR_BITSTUFF |
41 EFI_USB_ERR_SYSTEM,
42
43 };
44
45 //
46 // Structure to return the result of UHCI QH execution.
47 // Result is the final result of the QH's QTD. NextToggle
48 // is the next data toggle to use. Complete is the actual
49 // length of data transferred.
50 //
51 typedef struct {
52 UINT32 Result;
53 UINT8 NextToggle;
54 UINTN Complete;
55 } UHCI_QH_RESULT;
56
57 typedef struct _UHCI_ASYNC_REQUEST UHCI_ASYNC_REQUEST;
58
59 //
60 // Structure used to manager the asynchronous interrupt transfers.
61 //
62 typedef struct _UHCI_ASYNC_REQUEST{
63 UINTN Signature;
64 LIST_ENTRY Link;
65 UHCI_ASYNC_REQUEST *Recycle;
66
67 //
68 // Endpoint attributes
69 //
70 UINT8 DevAddr;
71 UINT8 EndPoint;
72 BOOLEAN IsLow;
73 UINTN Interval;
74
75 //
76 // Data and UHC structures
77 //
78 UHCI_QH_SW *QhSw;
79 UHCI_TD_SW *FirstTd;
80 UINT8 *Data; // Allocated host memory, not mapped memory
81 UINTN DataLen;
82 VOID *Mapping;
83
84 //
85 // User callback and its context
86 //
87 EFI_ASYNC_USB_TRANSFER_CALLBACK Callback;
88 VOID *Context;
89 } UHCI_ASYNC_REQUEST;
90
91 #define UHCI_ASYNC_INT_FROM_LINK(a) \
92 CR (a, UHCI_ASYNC_REQUEST, Link, UHCI_ASYNC_INT_SIGNATURE)
93
94 EFI_STATUS
95 UhciInitFrameList (
96 IN USB_HC_DEV *Uhc
97 )
98 /*++
99
100 Routine Description:
101
102 Create Frame List Structure
103
104 Arguments:
105
106 Uhc - UHCI device
107
108 Returns:
109
110 EFI_OUT_OF_RESOURCES - Can't allocate memory resources
111 EFI_UNSUPPORTED - Map memory fail
112 EFI_SUCCESS - Success
113
114 --*/
115 ;
116
117
118 /**
119 Destory FrameList buffer
120
121 @param Uhc The UHCI device
122
123 @return VOID
124
125 **/
126 VOID
127 UhciDestoryFrameList (
128 IN USB_HC_DEV *Uhc
129 )
130 ;
131
132
133 /**
134 Convert the poll rate to the maxium 2^n that is smaller
135 than Interval
136
137 @param Interval The poll rate to convert
138
139 @return The converted poll rate
140
141 **/
142 UINTN
143 UhciConvertPollRate (
144 IN UINTN Interval
145 )
146 ;
147
148
149 /**
150 Link a queue head (for asynchronous interrupt transfer) to
151 the frame list.
152
153 @param FrameBase The base of the frame list
154 @param Qh The queue head to link into
155
156 @return None
157
158 **/
159 VOID
160 UhciLinkQhToFrameList (
161 UINT32 *FrameBase,
162 UHCI_QH_SW *Qh
163 )
164 ;
165
166
167 /**
168 Unlink QH from the frame list is easier: find all
169 the precedence node, and pointer there next to QhSw's
170 next.
171
172 @param FrameBase The base address of the frame list
173 @param Qh The queue head to unlink
174
175 @return None
176
177 **/
178 VOID
179 UhciUnlinkQhFromFrameList (
180 UINT32 *FrameBase,
181 UHCI_QH_SW *Qh
182 )
183 ;
184
185
186 /**
187 Check the result of the transfer
188
189 @param Uhc The UHCI device
190 @param Td The first TDs of the transfer
191 @param TimeOut TimeOut value in milliseconds
192 @param IsLow Is Low Speed Device
193 @param QhResult The variable to return result
194
195 @retval EFI_SUCCESS The transfer finished with success
196 @retval EFI_DEVICE_ERROR Transfer failed
197
198 **/
199 EFI_STATUS
200 UhciExecuteTransfer (
201 IN USB_HC_DEV *Uhc,
202 IN UHCI_QH_SW *Qh,
203 IN UHCI_TD_SW *Td,
204 IN UINTN TimeOut,
205 IN BOOLEAN IsLow,
206 OUT UHCI_QH_RESULT *QhResult
207 )
208 ;
209
210
211 /**
212 Create Async Request node, and Link to List
213
214 @param Uhc The UHCI device
215 @param Qh The queue head of the transfer
216 @param FirstTd First TD of the transfer
217 @param DevAddr Device Address
218 @param EndPoint EndPoint Address
219 @param Toggle Data Toggle
220 @param DataLen Data length
221 @param Interval Polling Interval when inserted to frame list
222 @param Mapping Mapping value
223 @param Data Data buffer, unmapped
224 @param Callback Callback after interrupt transfeer
225 @param Context Callback Context passed as function parameter
226 @param IsLow Is Low Speed
227
228 @retval EFI_SUCCESS An asynchronous transfer is created
229 @retval EFI_INVALID_PARAMETER Paremeter is error
230 @retval EFI_OUT_OF_RESOURCES Failed because of resource shortage.
231
232 **/
233 EFI_STATUS
234 UhciCreateAsyncReq (
235 IN USB_HC_DEV *Uhc,
236 IN UHCI_QH_SW *Qh,
237 IN UHCI_TD_SW *FirstTd,
238 IN UINT8 DevAddr,
239 IN UINT8 EndPoint,
240 IN UINTN DataLen,
241 IN UINTN Interval,
242 IN VOID *Mapping,
243 IN UINT8 *Data,
244 IN EFI_ASYNC_USB_TRANSFER_CALLBACK Callback,
245 IN VOID *Context,
246 IN BOOLEAN IsLow
247 )
248 ;
249
250
251 /**
252 Delete Async Interrupt QH and TDs
253
254 @param Uhc The UHCI device
255 @param DevAddr Device Address
256 @param EndPoint EndPoint Address
257 @param Toggle The next data toggle to use
258
259 @retval EFI_SUCCESS The request is deleted
260 @retval EFI_INVALID_PARAMETER Paremeter is error
261 @retval EFI_NOT_FOUND The asynchronous isn't found
262
263 **/
264 EFI_STATUS
265 UhciRemoveAsyncReq (
266 IN USB_HC_DEV *Uhc,
267 IN UINT8 DevAddr,
268 IN UINT8 EndPoint,
269 OUT UINT8 *Toggle
270 )
271 ;
272
273
274 /**
275 Release all the asynchronous transfers on the lsit.
276
277 @param Uhc The UHCI device
278
279 @return VOID
280
281 **/
282 VOID
283 UhciFreeAllAsyncReq (
284 IN USB_HC_DEV *Uhc
285 )
286 ;
287
288
289 /**
290 Interrupt transfer periodic check handler
291
292 @param Event The event of the time
293 @param Context Context of the event, pointer to USB_HC_DEV
294
295 @return VOID
296
297 **/
298 VOID
299 UhciMonitorAsyncReqList (
300 IN EFI_EVENT Event,
301 IN VOID *Context
302 )
303 ;
304
305 #endif