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