1 /** @file
2 This file contains the definination for host controller schedule routines.
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 
18 #ifndef _OHCI_SCHED_H
19 #define _OHCI_SCHED_H
20 
21 #include "Descriptor.h"
22 
23 #define HCCA_MEM_SIZE     256
24 #define GRID_SIZE         16
25 #define GRID_SHIFT        4
26 
27 typedef struct _INTERRUPT_CONTEXT_ENTRY INTERRUPT_CONTEXT_ENTRY;
28 
29 struct _INTERRUPT_CONTEXT_ENTRY{
30   UINT8                               DeviceAddress;
31   UINT8                               EndPointAddress;
32   ED_DESCRIPTOR                       *Ed;
33   TD_DESCRIPTOR                       *DataTd;
34   BOOLEAN                             IsSlowDevice;
35   UINT8                               MaxPacketLength;
36   UINTN                               PollingInterval;
37   EFI_ASYNC_USB_TRANSFER_CALLBACK     CallBackFunction;
38   VOID                                *Context;
39   BOOLEAN                             IsPeriodic;
40   VOID                                *Buffer;
41   UINTN                               DataLength;
42   VOID                                *UCBuffer;
43   VOID                                *UCBufferMapping;
44   UINT8                               *Toggle;
45   INTERRUPT_CONTEXT_ENTRY      *NextEntry;
46 };
47 
48 
49 typedef struct {
50   UINT32                  ErrorCode;
51   UINT8                   NextToggle;
52 } OHCI_ED_RESULT;
53 
54 /**
55 
56   Add an item of interrupt context
57 
58   @param  Ohc                   UHC private data
59   @param  NewEntry              New entry to add
60 
61   @retval EFI_SUCCESS           Item successfully added
62 
63 **/
64 EFI_STATUS
65 OhciAddInterruptContextEntry (
66   IN  USB_OHCI_HC_DEV          *Ohc,
67   IN  INTERRUPT_CONTEXT_ENTRY  *NewEntry
68   );
69 
70 /**
71 
72   Free a interrupt context entry
73 
74   @param  Ohc                   UHC private data
75   @param  Entry                 Pointer to an interrupt context entry
76 
77   @retval EFI_SUCCESS           Entry freed
78   @retval EFI_INVALID_PARAMETER Entry is NULL
79 
80 **/
81 EFI_STATUS
82 OhciFreeInterruptContextEntry (
83   IN USB_OHCI_HC_DEV          *Ohc,
84   IN INTERRUPT_CONTEXT_ENTRY  *Entry
85   );
86 
87 /**
88 
89   Free entries match the device address and endpoint address
90 
91   @Param  Ohc                   UHC private date
92   @Param  DeviceAddress         Item to free must match this device address
93   @Param  EndPointAddress       Item to free must match this end point address
94   @Param  DataToggle            DataToggle for output
95 
96   @retval  EFI_SUCCESS          Items match the requirement removed
97 
98 **/
99 EFI_STATUS
100 OhciFreeInterruptContext(
101   IN  USB_OHCI_HC_DEV     *Ohc,
102   IN  UINT8               DeviceAddress,
103   IN  UINT8               EndPointAddress,
104   OUT UINT8               *DataToggle
105   );
106 
107 
108 /**
109 
110   Convert Error code from OHCI format to EFI format
111 
112   @Param  ErrorCode             ErrorCode in OHCI format
113 
114   @retval                       ErrorCode in EFI format
115 
116 **/
117 UINT32
118 ConvertErrorCode (
119   IN  UINT32              ErrorCode
120   );
121 
122 
123 /**
124 
125   Check TDs Results
126 
127   @Param  Ohc                   UHC private data
128   @Param  Td                    TD_DESCRIPTOR
129   @Param  Result                Result to return
130 
131   @retval TRUE                  means OK
132   @retval FLASE                 means Error or Short packet
133 
134 **/
135 BOOLEAN
136 OhciCheckTDsResults (
137   IN  USB_OHCI_HC_DEV     *Ohc,
138   IN  TD_DESCRIPTOR       *Td,
139   OUT UINT32              *Result
140   );
141 /**
142 
143   Check the task status on an ED
144 
145   @Param  Ed                    Pointer to the ED task that TD hooked on
146   @Param  HeadTd                TD header for current transaction
147 
148   @retval                       Task Status Code
149 
150 **/
151 
152 UINT32
153 CheckEDStatus (
154   IN  ED_DESCRIPTOR       *Ed,
155   IN  TD_DESCRIPTOR       *HeadTd,
156   OUT OHCI_ED_RESULT      *EdResult
157   );
158 /**
159 
160   Check the task status
161 
162   @Param  Ohc                   UHC private data
163   @Param  ListType              Pipe type
164   @Param  Ed                    Pointer to the ED task hooked on
165   @Param  HeadTd                Head of TD corresponding to the task
166   @Param  ErrorCode             return the ErrorCode
167 
168   @retval  EFI_SUCCESS          Task done
169   @retval  EFI_NOT_READY        Task on processing
170   @retval  EFI_DEVICE_ERROR     Some error occured
171 
172 **/
173 EFI_STATUS
174 CheckIfDone (
175   IN  USB_OHCI_HC_DEV       *Ohc,
176   IN  DESCRIPTOR_LIST_TYPE  ListType,
177   IN  ED_DESCRIPTOR         *Ed,
178   IN  TD_DESCRIPTOR         *HeadTd,
179   OUT OHCI_ED_RESULT        *EdResult
180   );
181 
182 /**
183 
184   Convert TD condition code to Efi Status
185 
186   @Param  ConditionCode         Condition code to convert
187 
188   @retval  EFI_SUCCESS          No error occured
189   @retval  EFI_NOT_READY        TD still on processing
190   @retval  EFI_DEVICE_ERROR     Error occured in processing TD
191 
192 **/
193 
194 EFI_STATUS
195 OhciTDConditionCodeToStatus (
196   IN  UINT32              ConditionCode
197   );
198 
199 /**
200 
201   Invoke callbacks hooked on done TDs
202 
203   @Param  Entry                 Interrupt transfer transaction information data structure
204   @Param  Context               Ohc private data
205 
206 **/
207 
208 VOID
209 OhciInvokeInterruptCallBack(
210   IN  INTERRUPT_CONTEXT_ENTRY  *Entry,
211   IN  UINT32                   Result
212 );
213 
214 
215 /**
216 
217   Timer to submit periodic interrupt transfer, and invoke callbacks hooked on done TDs
218 
219   @param  Event                 Event handle
220   @param  Context               Device private data
221 
222 **/
223 
224 VOID
225 EFIAPI
226 OhciHouseKeeper (
227   IN  EFI_EVENT           Event,
228   IN  VOID                *Context
229   );
230 
231 #endif
232