21235b56996dde5d56dd679d8d42f194923d7c81
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBusPei / UsbPeim.h
1 /** @file
2 Usb Peim definition.
3
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 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 #ifndef _PEI_USB_PEIM_H_
18 #define _PEI_USB_PEIM_H_
19
20
21 #include <PiPei.h>
22
23 #include <Ppi/UsbHostController.h>
24 #include <Ppi/Usb2HostController.h>
25 #include <Ppi/UsbIo.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/PcdLib.h>
33
34 #include <IndustryStandard/Usb.h>
35
36 #define MAX_ROOT_PORT 2
37 #define MAX_ENDPOINT 16
38
39 #define USB_SLOW_SPEED_DEVICE 0x01
40 #define USB_FULL_SPEED_DEVICE 0x02
41
42 #define PEI_USB_DEVICE_SIGNATURE SIGNATURE_32 ('U', 's', 'b', 'D')
43 typedef struct {
44 UINTN Signature;
45 PEI_USB_IO_PPI UsbIoPpi;
46 EFI_PEI_PPI_DESCRIPTOR UsbIoPpiList;
47 UINT8 DeviceAddress;
48 UINT8 MaxPacketSize0;
49 UINT8 DeviceSpeed;
50 UINT8 IsHub;
51 UINT16 DataToggle;
52 UINT8 DownStreamPortNo;
53 UINT8 Reserved; // Padding for IPF
54 UINTN AllocateAddress;
55 PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi;
56 PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi;
57 UINT8 ConfigurationData[1024];
58 EFI_USB_CONFIG_DESCRIPTOR *ConfigDesc;
59 EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDesc;
60 EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDesc[MAX_ENDPOINT];
61 EFI_USB2_HC_TRANSACTION_TRANSLATOR Translator;
62 } PEI_USB_DEVICE;
63
64 #define PEI_USB_DEVICE_FROM_THIS(a) CR (a, PEI_USB_DEVICE, UsbIoPpi, PEI_USB_DEVICE_SIGNATURE)
65
66
67 /**
68 Submits control transfer to a target USB device.
69
70 @param PeiServices The pointer of EFI_PEI_SERVICES.
71 @param This The pointer of PEI_USB_IO_PPI.
72 @param Request USB device request to send.
73 @param Direction Specifies the data direction for the data stage.
74 @param Timeout Indicates the maximum timeout, in millisecond. If Timeout
75 is 0, then the caller must wait for the function to be
76 completed until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.
77 @param Data Data buffer to be transmitted or received from USB device.
78 @param DataLength The size (in bytes) of the data buffer.
79
80 @retval EFI_SUCCESS Transfer was completed successfully.
81 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resources.
82 @retval EFI_INVALID_PARAMETER Some parameters are invalid.
83 @retval EFI_TIMEOUT Transfer failed due to timeout.
84 @retval EFI_DEVICE_ERROR Transfer failed due to host controller or device error.
85
86 **/
87 EFI_STATUS
88 EFIAPI
89 PeiUsbControlTransfer (
90 IN EFI_PEI_SERVICES **PeiServices,
91 IN PEI_USB_IO_PPI *This,
92 IN EFI_USB_DEVICE_REQUEST *Request,
93 IN EFI_USB_DATA_DIRECTION Direction,
94 IN UINT32 Timeout,
95 IN OUT VOID *Data, OPTIONAL
96 IN UINTN DataLength OPTIONAL
97 );
98
99 /**
100 Submits bulk transfer to a bulk endpoint of a USB device.
101
102 @param PeiServices The pointer of EFI_PEI_SERVICES.
103 @param This The pointer of PEI_USB_IO_PPI.
104 @param DeviceEndpoint Endpoint number and its direction in bit 7.
105 @param Data A pointer to the buffer of data to transmit
106 from or receive into.
107 @param DataLength The lenght of the data buffer.
108 @param Timeout Indicates the maximum time, in millisecond, which the
109 transfer is allowed to complete. If Timeout is 0, then
110 the caller must wait for the function to be completed
111 until EFI_SUCCESS or EFI_DEVICE_ERROR is returned.
112
113 @retval EFI_SUCCESS The transfer was completed successfully.
114 @retval EFI_OUT_OF_RESOURCES The transfer failed due to lack of resource.
115 @retval EFI_INVALID_PARAMETER Parameters are invalid.
116 @retval EFI_TIMEOUT The transfer failed due to timeout.
117 @retval EFI_DEVICE_ERROR The transfer failed due to host controller error.
118
119 **/
120 EFI_STATUS
121 EFIAPI
122 PeiUsbBulkTransfer (
123 IN EFI_PEI_SERVICES **PeiServices,
124 IN PEI_USB_IO_PPI *This,
125 IN UINT8 DeviceEndpoint,
126 IN OUT VOID *Data,
127 IN OUT UINTN *DataLength,
128 IN UINTN Timeout
129 );
130
131 /**
132 Get the usb interface descriptor.
133
134 @param PeiServices General-purpose services that are available to every PEIM.
135 @param This Indicates the PEI_USB_IO_PPI instance.
136 @param InterfaceDescriptor Request interface descriptor.
137
138
139 @retval EFI_SUCCESS Usb interface descriptor is obtained successfully.
140
141 **/
142 EFI_STATUS
143 EFIAPI
144 PeiUsbGetInterfaceDescriptor (
145 IN EFI_PEI_SERVICES **PeiServices,
146 IN PEI_USB_IO_PPI *This,
147 OUT EFI_USB_INTERFACE_DESCRIPTOR **InterfaceDescriptor
148 );
149
150 /**
151 Get the usb endpoint descriptor.
152
153 @param PeiServices General-purpose services that are available to every PEIM.
154 @param This Indicates the PEI_USB_IO_PPI instance.
155 @param EndpointIndex The valid index of the specified endpoint.
156 @param EndpointDescriptor Request endpoint descriptor.
157
158 @retval EFI_SUCCESS Usb endpoint descriptor is obtained successfully.
159 @retval EFI_NOT_FOUND Usb endpoint descriptor is NOT found.
160
161 **/
162 EFI_STATUS
163 EFIAPI
164 PeiUsbGetEndpointDescriptor (
165 IN EFI_PEI_SERVICES **PeiServices,
166 IN PEI_USB_IO_PPI *This,
167 IN UINT8 EndpointIndex,
168 OUT EFI_USB_ENDPOINT_DESCRIPTOR **EndpointDescriptor
169 );
170
171 /**
172 Reset the port and re-configure the usb device.
173
174 @param PeiServices General-purpose services that are available to every PEIM.
175 @param This Indicates the PEI_USB_IO_PPI instance.
176
177 @retval EFI_SUCCESS Usb device is reset and configured successfully.
178 @retval Others Other failure occurs.
179
180 **/
181 EFI_STATUS
182 EFIAPI
183 PeiUsbPortReset (
184 IN EFI_PEI_SERVICES **PeiServices,
185 IN PEI_USB_IO_PPI *This
186 );
187
188 /**
189 Send reset signal over the given root hub port.
190
191 @param PeiServices Describes the list of possible PEI Services.
192 @param UsbHcPpi The pointer of PEI_USB_HOST_CONTROLLER_PPI instance.
193 @param Usb2HcPpi The pointer of PEI_USB2_HOST_CONTROLLER_PPI instance.
194 @param PortNum The port to be reset.
195 @param RetryIndex The retry times.
196
197 **/
198 VOID
199 ResetRootPort (
200 IN EFI_PEI_SERVICES **PeiServices,
201 IN PEI_USB_HOST_CONTROLLER_PPI *UsbHcPpi,
202 IN PEI_USB2_HOST_CONTROLLER_PPI *Usb2HcPpi,
203 IN UINT8 PortNum,
204 IN UINT8 RetryIndex
205 );
206
207 #endif