1 /** @file
2 Provides some data struct used by OHCI controller driver.
3 
4 Copyright (c) 2013-2015 Intel Corporation.
5 
6 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 
17 #ifndef _OHCI_URB_H
18 #define _OHCI_URB_H
19 
20 #include "Descriptor.h"
21 
22 
23 //
24 // Func List
25 //
26 
27 
28 /**
29 
30   Create a TD
31 
32   @Param  Ohc                   UHC private data
33 
34   @retval                       TD structure pointer
35 
36 **/
37 TD_DESCRIPTOR *
38 OhciCreateTD (
39   IN USB_OHCI_HC_DEV      *Ohc
40   );
41 
42 /**
43 
44   Free a TD
45 
46   @Param  Ohc                   UHC private data
47   @Param  Td                    Pointer to a TD to free
48 
49   @retval  EFI_SUCCESS          TD freed
50 
51 **/
52 EFI_STATUS
53 OhciFreeTD (
54   IN USB_OHCI_HC_DEV      *Ohc,
55   IN TD_DESCRIPTOR        *Td
56   );
57 
58 /**
59 
60   Create a ED
61 
62   @Param   Ohc                  Device private data
63 
64   @retval  ED                   descriptor pointer
65 
66 **/
67 ED_DESCRIPTOR *
68 OhciCreateED (
69   USB_OHCI_HC_DEV          *Ohc
70   );
71 
72 
73 /**
74 
75   Free a ED
76 
77   @Param  Ohc                   UHC private data
78   @Param  Ed                    Pointer to a ED to free
79 
80   @retval  EFI_SUCCESS          ED freed
81 
82 **/
83 
84 EFI_STATUS
85 OhciFreeED (
86   IN USB_OHCI_HC_DEV      *Ohc,
87   IN ED_DESCRIPTOR        *Ed
88   );
89 
90 /**
91 
92   Free  ED
93 
94   @Param  Ohc                    Device private data
95   @Param  Ed                     Pointer to a ED to free
96 
97   @retval  EFI_SUCCESS           ED freed
98 
99 **/
100 EFI_STATUS
101 OhciFreeAllTDFromED (
102   IN USB_OHCI_HC_DEV      *Ohc,
103   IN ED_DESCRIPTOR        *Ed
104   );
105 
106 /**
107 
108   Find a working ED match the requirement
109 
110   @Param  EdHead                Head of the ED list
111   @Param  DeviceAddress         Device address to search
112   @Param  EndPointNum           End point num to search
113   @Param  EdDir                 ED Direction to search
114 
115   @retval   ED descriptor searched
116 
117 **/
118 
119 ED_DESCRIPTOR *
120 OhciFindWorkingEd (
121   IN ED_DESCRIPTOR       *EdHead,
122   IN UINT8               DeviceAddress,
123   IN UINT8               EndPointNum,
124   IN UINT8               EdDir
125   );
126 
127 
128 /**
129 
130   Initialize interrupt list.
131 
132   @Param Ohc                    Device private data
133 
134   @retval  EFI_SUCCESS          Initialization done
135 
136 **/
137 EFI_STATUS
138 OhciInitializeInterruptList (
139   USB_OHCI_HC_DEV          *Ohc
140   );
141 
142 /**
143 
144   Attach an ED
145 
146   @Param  Ed                    Ed to be attached
147   @Param  NewEd                 Ed to attach
148 
149   @retval EFI_SUCCESS           NewEd attached to Ed
150   @retval EFI_INVALID_PARAMETER Ed is NULL
151 
152 **/
153 EFI_STATUS
154 OhciAttachED (
155   IN ED_DESCRIPTOR        *Ed,
156   IN ED_DESCRIPTOR        *NewEd
157   );
158 
159 /**
160 
161   Count ED number on a ED chain
162 
163   @Param  Ed                    Head of the ED chain
164 
165   @retval                       ED number on the chain
166 
167 **/
168 
169 UINTN
170 CountEdNum (
171   IN ED_DESCRIPTOR      *Ed
172   );
173 
174 /**
175 
176   Find the minimal burn ED list on a specific depth level
177 
178   @Param  Ohc                   Device private data
179   @Param  Depth                 Depth level
180 
181   @retval                       ED list found
182 
183 **/
184 
185 ED_DESCRIPTOR *
186 OhciFindMinInterruptEDList (
187   IN USB_OHCI_HC_DEV      *Ohc,
188   IN UINT32               Depth
189   );
190 
191 /**
192 
193   Attach an ED to an ED list
194 
195   @Param  OHC                   UHC private data
196   @Param  ListType              Type of the ED list
197   @Param  Ed                    ED to attach
198   @Param  EdList                ED list to be attached
199 
200   @retval  EFI_SUCCESS          ED attached to ED list
201 
202 **/
203 ED_DESCRIPTOR *
204 OhciAttachEDToList (
205   IN USB_OHCI_HC_DEV       *Ohc,
206   IN DESCRIPTOR_LIST_TYPE  ListType,
207   IN ED_DESCRIPTOR         *Ed,
208   IN ED_DESCRIPTOR         *EdList
209   );
210 
211 /**
212 
213   Remove interrupt EDs that match requirement
214 
215   @Param  Ohc                   UHC private data
216   @Param  IntEd                 The address of Interrupt endpoint
217 
218   @retval  EFI_SUCCESS          EDs match requirement removed
219 
220 **/
221 
222 EFI_STATUS
223 OhciFreeInterruptEdByEd (
224   IN USB_OHCI_HC_DEV      *Ohc,
225   IN ED_DESCRIPTOR        *IntEd
226   );
227 
228 /**
229 
230   Remove interrupt EDs that match requirement
231 
232   @Param  Ohc                   UHC private data
233   @Param  FunctionAddress       Requirement on function address
234   @Param  EndPointNum           Requirement on end point number
235 
236   @retval  EFI_SUCCESS          EDs match requirement removed
237 
238 **/
239 EFI_STATUS
240 OhciFreeInterruptEdByAddr (
241   IN USB_OHCI_HC_DEV      *Ohc,
242   IN UINT8                FunctionAddress,
243   IN UINT8                EndPointNum
244   );
245 
246 
247 /**
248 
249   Link Td2 to the end of Td1
250 
251   @Param Td1                    TD to be linked
252   @Param Td2                    TD to link
253 
254   @retval EFI_SUCCESS           TD successfully linked
255   @retval EFI_INVALID_PARAMETER Td1 is NULL
256 
257 **/
258 EFI_STATUS
259 OhciLinkTD (
260   IN TD_DESCRIPTOR        *Td1,
261   IN TD_DESCRIPTOR        *Td2
262   );
263 
264 
265 /**
266 
267   Attach TD list to ED
268 
269   @Param  Ed                    ED which TD list attach on
270   @Param  HeadTd                Head of the TD list to attach
271 
272   @retval  EFI_SUCCESS          TD list attached on the ED
273 
274 **/
275 EFI_STATUS
276 OhciAttachTDListToED (
277   IN ED_DESCRIPTOR        *Ed,
278   IN TD_DESCRIPTOR        *HeadTd
279   );
280 
281 
282 /**
283 
284   Set value to ED specific field
285 
286   @Param  Ed                    ED to be set
287   @Param  Field                 Field to be set
288   @Param  Value                 Value to set
289 
290   @retval  EFI_SUCCESS          Value set
291 
292 **/
293 EFI_STATUS
294 OhciSetEDField (
295   IN ED_DESCRIPTOR        *Ed,
296   IN UINT32               Field,
297   IN UINT32               Value
298   );
299 
300 
301 /**
302 
303   Get value from an ED's specific field
304 
305   @Param  Ed                    ED pointer
306   @Param  Field                 Field to get value from
307 
308   @retval                       Value of the field
309 
310 **/
311 UINT32
312 OhciGetEDField (
313   IN ED_DESCRIPTOR        *Ed,
314   IN UINT32               Field
315   );
316 
317 
318 /**
319 
320   Set value to TD specific field
321 
322   @Param  Td                    TD to be set
323   @Param  Field                 Field to be set
324   @Param  Value                 Value to set
325 
326   @retval  EFI_SUCCESS          Value set
327 
328 **/
329 EFI_STATUS
330 OhciSetTDField (
331   IN TD_DESCRIPTOR        *Td,
332   IN UINT32               Field,
333   IN UINT32               Value
334   );
335 
336 
337 /**
338 
339   Get value from ED specific field
340 
341   @Param  Td                    TD pointer
342   @Param  Field                 Field to get value from
343 
344   @retval                       Value of the field
345 
346 **/
347 
348 UINT32
349 OhciGetTDField (
350   IN TD_DESCRIPTOR      *Td,
351   IN UINT32             Field
352   );
353 /**
354 
355   Free the Ed,Td,buffer that were created during transferring
356 
357   @Param  Ohc                   Device private data
358 **/
359 
360 VOID
361 OhciFreeDynamicIntMemory(
362   IN USB_OHCI_HC_DEV      *Ohc
363   );
364 
365 /**
366 
367   Free the Ed that were initilized during driver was starting,
368   those memory were used as interrupt ED head
369 
370   @Param  Ohc                   Device private data
371 
372 
373 **/
374 VOID
375 OhciFreeFixedIntMemory (
376   IN USB_OHCI_HC_DEV      *Ohc
377   );
378 /**
379 
380   Release all OHCI used memory when OHCI going to quit
381 
382   @Param  Ohc                   Device private data
383 
384   @retval EFI_SUCCESS          Memory released
385 
386 **/
387 
388 EFI_STATUS
389 OhciFreeIntTransferMemory (
390   IN USB_OHCI_HC_DEV           *Ohc
391   );
392 
393 #endif
394