1 /** @file
2 Provides the definition of Usb Hc Protocol and OHCI controller
3 private data structure.
4 
5 Copyright (c) 2013-2015 Intel Corporation.
6 
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution.  The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11 
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 
17 
18 
19 #ifndef _OHCI_PEIM_H
20 #define _OHCI_PEIM_H
21 
22 #include <PiPei.h>
23 
24 #include <Ppi/UsbController.h>
25 #include <Ppi/UsbHostController.h>
26 
27 #include <Library/DebugLib.h>
28 #include <Library/PeimEntryPoint.h>
29 #include <Library/PeiServicesLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/TimerLib.h>
32 #include <Library/IoLib.h>
33 
34 typedef struct _USB_OHCI_HC_DEV USB_OHCI_HC_DEV;
35 
36 #include "UsbHcMem.h"
37 #include "OhciReg.h"
38 #include "OhciSched.h"
39 #include "OhciUrb.h"
40 #include "Descriptor.h"
41 
42 #define EFI_USB_SPEED_FULL 0x0000
43 #define EFI_USB_SPEED_LOW  0x0001
44 #define EFI_USB_SPEED_HIGH 0x0002
45 
46 #define PAGESIZE                    4096
47 
48 #define HC_1_MICROSECOND            1
49 #define HC_1_MILLISECOND            (1000 * HC_1_MICROSECOND)
50 #define HC_1_SECOND                 (1000 * HC_1_MILLISECOND)
51 
52 
53 #define USB_OHCI_HC_DEV_SIGNATURE   SIGNATURE_32('o','h','c','i')
54 
55 struct _USB_OHCI_HC_DEV {
56   UINTN                        Signature;
57   PEI_USB_HOST_CONTROLLER_PPI  UsbHostControllerPpi;
58   EFI_PEI_PPI_DESCRIPTOR       PpiDescriptor;
59   UINT32                       UsbHostControllerBaseAddress;
60   VOID                         *MemPool;
61 };
62 
63 #define PEI_RECOVERY_USB_OHC_DEV_FROM_EHCI_THIS(a)  CR (a, USB_OHCI_HC_DEV, UsbHostControllerPpi, USB_OHCI_HC_DEV_SIGNATURE)
64 
65 //
66 // Func List
67 //
68 
69 /**
70   Provides software reset for the USB host controller.
71 
72   @param  PeiServices           The pointer of EFI_PEI_SERVICES.
73   @param  This                  The pointer of PEI_USB_HOST_CONTROLLER_PPI.
74   @param  Attributes            A bit mask of the reset operation to perform.
75 
76   @retval EFI_SUCCESS           The reset operation succeeded.
77   @retval EFI_INVALID_PARAMETER Attributes is not valid.
78   @retval EFI_UNSUPPOURTED      The type of reset specified by Attributes is
79                                 not currently supported by the host controller.
80   @retval EFI_DEVICE_ERROR      Host controller isn't halted to reset.
81 
82 **/
83 EFI_STATUS
84 InitializeUsbHC (
85   IN EFI_PEI_SERVICES   **PeiServices,
86   IN USB_OHCI_HC_DEV    *Ohc,
87   IN UINT16             Attributes
88   );
89 
90 /**
91   Submits control transfer to a target USB device.
92 
93   @param  PeiServices            The pointer of EFI_PEI_SERVICES.
94   @param  This                   The pointer of PEI_USB_HOST_CONTROLLER_PPI.
95   @param  DeviceAddress          The target device address.
96   @param  DeviceSpeed            Target device speed.
97   @param  MaximumPacketLength    Maximum packet size the default control transfer
98                                  endpoint is capable of sending or receiving.
99   @param  Request                USB device request to send.
100   @param  TransferDirection      Specifies the data direction for the data stage.
101   @param  Data                   Data buffer to be transmitted or received from USB device.
102   @param  DataLength             The size (in bytes) of the data buffer.
103   @param  TimeOut                Indicates the maximum timeout, in millisecond.
104   @param  TransferResult         Return the result of this control transfer.
105 
106   @retval EFI_SUCCESS            Transfer was completed successfully.
107   @retval EFI_OUT_OF_RESOURCES   The transfer failed due to lack of resources.
108   @retval EFI_INVALID_PARAMETER  Some parameters are invalid.
109   @retval EFI_TIMEOUT            Transfer failed due to timeout.
110   @retval EFI_DEVICE_ERROR       Transfer failed due to host controller or device error.
111 
112 **/
113 EFI_STATUS
114 EFIAPI
115 OhciControlTransfer (
116   IN  EFI_PEI_SERVICES                    **PeiServices,
117   IN  PEI_USB_HOST_CONTROLLER_PPI         *This,
118   IN  UINT8                               DeviceAddress,
119   IN  UINT8                               DeviceSpeed,
120   IN  UINT8                               MaxPacketLength,
121   IN  EFI_USB_DEVICE_REQUEST              *Request,
122   IN  EFI_USB_DATA_DIRECTION              TransferDirection,
123   IN  OUT VOID                            *Data,
124   IN  OUT UINTN                           *DataLength,
125   IN  UINTN                               TimeOut,
126   OUT UINT32                              *TransferResult
127   );
128 /**
129   Submits bulk transfer to a bulk endpoint of a USB device.
130 
131   @param  PeiServices           The pointer of EFI_PEI_SERVICES.
132   @param  This                  The pointer of PEI_USB_HOST_CONTROLLER_PPI.
133   @param  DeviceAddress         Target device address.
134   @param  EndPointAddress       Endpoint number and its direction in bit 7.
135   @param  MaxiPacketLength      Maximum packet size the endpoint is capable of
136                                 sending or receiving.
137   @param  Data                  A pointers to the buffers of data to transmit
138                                 from or receive into.
139   @param  DataLength            The lenght of the data buffer.
140   @param  DataToggle            On input, the initial data toggle for the transfer;
141                                 On output, it is updated to to next data toggle to use of
142                                 the subsequent bulk transfer.
143   @param  TimeOut               Indicates the maximum time, in millisecond, which the
144                                 transfer is allowed to complete.
145   @param  TransferResult        A pointer to the detailed result information of the
146                                 bulk transfer.
147 
148   @retval EFI_SUCCESS           The transfer was completed successfully.
149   @retval EFI_OUT_OF_RESOURCES  The transfer failed due to lack of resource.
150   @retval EFI_INVALID_PARAMETER Parameters are invalid.
151   @retval EFI_TIMEOUT           The transfer failed due to timeout.
152   @retval EFI_DEVICE_ERROR      The transfer failed due to host controller error.
153 
154 **/
155 EFI_STATUS
156 EFIAPI
157 OhciBulkTransfer (
158   IN EFI_PEI_SERVICES                     **PeiServices,
159   IN PEI_USB_HOST_CONTROLLER_PPI          *This,
160   IN  UINT8                               DeviceAddress,
161   IN  UINT8                               EndPointAddress,
162   IN  UINT8                               MaxPacketLength,
163   IN  OUT VOID                            *Data,
164   IN  OUT UINTN                           *DataLength,
165   IN  OUT UINT8                           *DataToggle,
166   IN  UINTN                               TimeOut,
167   OUT UINT32                              *TransferResult
168   );
169 /**
170   Retrieves the number of root hub ports.
171 
172   @param[in]  PeiServices       The pointer to the PEI Services Table.
173   @param[in]  This              The pointer to this instance of the
174                                 PEI_USB_HOST_CONTROLLER_PPI.
175   @param[out] NumOfPorts        The pointer to the number of the root hub ports.
176 
177   @retval EFI_SUCCESS           The port number was retrieved successfully.
178   @retval EFI_INVALID_PARAMETER PortNumber is NULL.
179 
180 **/
181 
182 EFI_STATUS
183 EFIAPI
184 OhciGetRootHubNumOfPorts (
185   IN EFI_PEI_SERVICES                       **PeiServices,
186   IN PEI_USB_HOST_CONTROLLER_PPI           *This,
187   OUT UINT8                *NumOfPorts
188   );
189 /**
190   Retrieves the current status of a USB root hub port.
191 
192   @param  PeiServices            The pointer of EFI_PEI_SERVICES.
193   @param  This                   The pointer of PEI_USB_HOST_CONTROLLER_PPI.
194   @param  PortNumber             The root hub port to retrieve the state from.
195   @param  PortStatus             Variable to receive the port state.
196 
197   @retval EFI_SUCCESS            The status of the USB root hub port specified.
198                                  by PortNumber was returned in PortStatus.
199   @retval EFI_INVALID_PARAMETER  PortNumber is invalid.
200 
201 **/
202 
203 EFI_STATUS
204 EFIAPI
205 OhciGetRootHubPortStatus (
206   IN  EFI_PEI_SERVICES             **PeiServices,
207   IN  PEI_USB_HOST_CONTROLLER_PPI  *This,
208   IN  UINT8                        PortNumber,
209   OUT EFI_USB_PORT_STATUS          *PortStatus
210   );
211 /**
212 
213   Sets a feature for the specified root hub port.
214 
215   @param  This                  A pointer to the EFI_USB_HC_PROTOCOL.
216   @param  PortNumber            Specifies the root hub port whose feature
217                                 is requested to be set.
218   @param  PortFeature           Indicates the feature selector associated
219                                 with the feature set request.
220 
221   @retval EFI_SUCCESS           The feature specified by PortFeature was set for the
222                                 USB root hub port specified by PortNumber.
223   @retval EFI_DEVICE_ERROR      Set feature failed because of hardware issue
224   @retval EFI_INVALID_PARAMETER PortNumber is invalid or PortFeature is invalid.
225 **/
226 EFI_STATUS
227 EFIAPI
228 OhciSetRootHubPortFeature (
229   IN EFI_PEI_SERVICES             **PeiServices,
230   IN PEI_USB_HOST_CONTROLLER_PPI  *This,
231   IN UINT8                        PortNumber,
232   IN EFI_USB_PORT_FEATURE         PortFeature
233   );
234 /**
235   Clears a feature for the specified root hub port.
236 
237   @param  PeiServices           The pointer of EFI_PEI_SERVICES.
238   @param  This                  The pointer of PEI_USB_HOST_CONTROLLER_PPI.
239   @param  PortNumber            Specifies the root hub port whose feature
240                                 is requested to be cleared.
241   @param  PortFeature           Indicates the feature selector associated with the
242                                 feature clear request.
243 
244   @retval EFI_SUCCESS            The feature specified by PortFeature was cleared
245                                  for the USB root hub port specified by PortNumber.
246   @retval EFI_INVALID_PARAMETER  PortNumber is invalid or PortFeature is invalid.
247 
248 **/
249 
250 EFI_STATUS
251 EFIAPI
252 OhciClearRootHubPortFeature (
253   IN EFI_PEI_SERVICES             **PeiServices,
254   IN PEI_USB_HOST_CONTROLLER_PPI  *This,
255   IN UINT8                        PortNumber,
256   IN EFI_USB_PORT_FEATURE         PortFeature
257   );
258 #endif
259