]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbBotPei/UsbBotPeim.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBotPei / UsbBotPeim.h
1 /** @file
2 Usb BOT Peim definition.
3
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _PEI_USB_BOT_PEIM_H_
11 #define _PEI_USB_BOT_PEIM_H_
12
13 #include <PiPei.h>
14
15 #include <Ppi/UsbIo.h>
16 #include <Ppi/UsbHostController.h>
17 #include <Ppi/BlockIo.h>
18 #include <Ppi/BlockIo2.h>
19
20 #include <Library/DebugLib.h>
21
22 #include <IndustryStandard/Usb.h>
23 #include <IndustryStandard/Atapi.h>
24
25 #define PEI_FAT_MAX_USB_IO_PPI 127
26
27 /**
28 Gets the count of block I/O devices that one specific block driver detects.
29
30 This function is used for getting the count of block I/O devices that one
31 specific block driver detects. To the PEI ATAPI driver, it returns the number
32 of all the detected ATAPI devices it detects during the enumeration process.
33 To the PEI legacy floppy driver, it returns the number of all the legacy
34 devices it finds during its enumeration process. If no device is detected,
35 then the function will return zero.
36
37 @param[in] PeiServices General-purpose services that are available
38 to every PEIM.
39 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI
40 instance.
41 @param[out] NumberBlockDevices The number of block I/O devices discovered.
42
43 @retval EFI_SUCCESS Operation performed successfully.
44
45 **/
46 EFI_STATUS
47 EFIAPI
48 BotGetNumberOfBlockDevices (
49 IN EFI_PEI_SERVICES **PeiServices,
50 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,
51 OUT UINTN *NumberBlockDevices
52 );
53
54 /**
55 Gets a block device's media information.
56
57 This function will provide the caller with the specified block device's media
58 information. If the media changes, calling this function will update the media
59 information accordingly.
60
61 @param[in] PeiServices General-purpose services that are available to every
62 PEIM
63 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
64 @param[in] DeviceIndex Specifies the block device to which the function wants
65 to talk. Because the driver that implements Block I/O
66 PPIs will manage multiple block devices, the PPIs that
67 want to talk to a single device must specify the
68 device index that was assigned during the enumeration
69 process. This index is a number from one to
70 NumberBlockDevices.
71 @param[out] MediaInfo The media information of the specified block media.
72 The caller is responsible for the ownership of this
73 data structure.
74
75 @retval EFI_SUCCESS Media information about the specified block device
76 was obtained successfully.
77 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
78 error.
79
80 **/
81 EFI_STATUS
82 EFIAPI
83 BotGetMediaInfo (
84 IN EFI_PEI_SERVICES **PeiServices,
85 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,
86 IN UINTN DeviceIndex,
87 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo
88 );
89
90 /**
91 Reads the requested number of blocks from the specified block device.
92
93 The function reads the requested number of blocks from the device. All the
94 blocks are read, or an error is returned. If there is no media in the device,
95 the function returns EFI_NO_MEDIA.
96
97 @param[in] PeiServices General-purpose services that are available to
98 every PEIM.
99 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
100 @param[in] DeviceIndex Specifies the block device to which the function wants
101 to talk. Because the driver that implements Block I/O
102 PPIs will manage multiple block devices, the PPIs that
103 want to talk to a single device must specify the device
104 index that was assigned during the enumeration process.
105 This index is a number from one to NumberBlockDevices.
106 @param[in] StartLBA The starting logical block address (LBA) to read from
107 on the device
108 @param[in] BufferSize The size of the Buffer in bytes. This number must be
109 a multiple of the intrinsic block size of the device.
110 @param[out] Buffer A pointer to the destination buffer for the data.
111 The caller is responsible for the ownership of the
112 buffer.
113
114 @retval EFI_SUCCESS The data was read correctly from the device.
115 @retval EFI_DEVICE_ERROR The device reported an error while attempting
116 to perform the read operation.
117 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
118 valid, or the buffer is not properly aligned.
119 @retval EFI_NO_MEDIA There is no media in the device.
120 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
121 the intrinsic block size of the device.
122
123 **/
124 EFI_STATUS
125 EFIAPI
126 BotReadBlocks (
127 IN EFI_PEI_SERVICES **PeiServices,
128 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,
129 IN UINTN DeviceIndex,
130 IN EFI_PEI_LBA StartLBA,
131 IN UINTN BufferSize,
132 OUT VOID *Buffer
133 );
134
135 /**
136 Gets the count of block I/O devices that one specific block driver detects.
137
138 This function is used for getting the count of block I/O devices that one
139 specific block driver detects. To the PEI ATAPI driver, it returns the number
140 of all the detected ATAPI devices it detects during the enumeration process.
141 To the PEI legacy floppy driver, it returns the number of all the legacy
142 devices it finds during its enumeration process. If no device is detected,
143 then the function will return zero.
144
145 @param[in] PeiServices General-purpose services that are available
146 to every PEIM.
147 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI
148 instance.
149 @param[out] NumberBlockDevices The number of block I/O devices discovered.
150
151 @retval EFI_SUCCESS Operation performed successfully.
152
153 **/
154 EFI_STATUS
155 EFIAPI
156 BotGetNumberOfBlockDevices2 (
157 IN EFI_PEI_SERVICES **PeiServices,
158 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,
159 OUT UINTN *NumberBlockDevices
160 );
161
162 /**
163 Gets a block device's media information.
164
165 This function will provide the caller with the specified block device's media
166 information. If the media changes, calling this function will update the media
167 information accordingly.
168
169 @param[in] PeiServices General-purpose services that are available to every
170 PEIM
171 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
172 @param[in] DeviceIndex Specifies the block device to which the function wants
173 to talk. Because the driver that implements Block I/O
174 PPIs will manage multiple block devices, the PPIs that
175 want to talk to a single device must specify the
176 device index that was assigned during the enumeration
177 process. This index is a number from one to
178 NumberBlockDevices.
179 @param[out] MediaInfo The media information of the specified block media.
180 The caller is responsible for the ownership of this
181 data structure.
182
183 @retval EFI_SUCCESS Media information about the specified block device
184 was obtained successfully.
185 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
186 error.
187
188 **/
189 EFI_STATUS
190 EFIAPI
191 BotGetMediaInfo2 (
192 IN EFI_PEI_SERVICES **PeiServices,
193 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,
194 IN UINTN DeviceIndex,
195 OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo
196 );
197
198 /**
199 Reads the requested number of blocks from the specified block device.
200
201 The function reads the requested number of blocks from the device. All the
202 blocks are read, or an error is returned. If there is no media in the device,
203 the function returns EFI_NO_MEDIA.
204
205 @param[in] PeiServices General-purpose services that are available to
206 every PEIM.
207 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
208 @param[in] DeviceIndex Specifies the block device to which the function wants
209 to talk. Because the driver that implements Block I/O
210 PPIs will manage multiple block devices, the PPIs that
211 want to talk to a single device must specify the device
212 index that was assigned during the enumeration process.
213 This index is a number from one to NumberBlockDevices.
214 @param[in] StartLBA The starting logical block address (LBA) to read from
215 on the device
216 @param[in] BufferSize The size of the Buffer in bytes. This number must be
217 a multiple of the intrinsic block size of the device.
218 @param[out] Buffer A pointer to the destination buffer for the data.
219 The caller is responsible for the ownership of the
220 buffer.
221
222 @retval EFI_SUCCESS The data was read correctly from the device.
223 @retval EFI_DEVICE_ERROR The device reported an error while attempting
224 to perform the read operation.
225 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
226 valid, or the buffer is not properly aligned.
227 @retval EFI_NO_MEDIA There is no media in the device.
228 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
229 the intrinsic block size of the device.
230
231 **/
232 EFI_STATUS
233 EFIAPI
234 BotReadBlocks2 (
235 IN EFI_PEI_SERVICES **PeiServices,
236 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,
237 IN UINTN DeviceIndex,
238 IN EFI_PEI_LBA StartLBA,
239 IN UINTN BufferSize,
240 OUT VOID *Buffer
241 );
242
243 /**
244 UsbIo installation notification function.
245
246 This function finds out all the current USB IO PPIs in the system and add them
247 into private data.
248
249 @param PeiServices Indirect reference to the PEI Services Table.
250 @param NotifyDesc Address of the notification descriptor data structure.
251 @param InvokePpi Address of the PPI that was invoked.
252
253 @retval EFI_SUCCESS The function completes successfully.
254
255 **/
256 EFI_STATUS
257 EFIAPI
258 NotifyOnUsbIoPpi (
259 IN EFI_PEI_SERVICES **PeiServices,
260 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,
261 IN VOID *InvokePpi
262 );
263
264 /**
265 Initialize the usb bot device.
266
267 @param[in] PeiServices General-purpose services that are available to every
268 PEIM.
269 @param[in] UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
270
271 @retval EFI_SUCCESS The usb bot device is initialized successfully.
272 @retval Other Failed to initialize media.
273
274 **/
275 EFI_STATUS
276 InitUsbBot (
277 IN EFI_PEI_SERVICES **PeiServices,
278 IN PEI_USB_IO_PPI *UsbIoPpi
279 );
280
281 #define USBCDROM 1 // let the device type value equal to USBCDROM, which is defined by PI spec.
282 // Therefore the CdExpressPei module can do recovery on UsbCdrom.
283 #define USBFLOPPY 2 // for those that use ReadCapacity(0x25) command to retrieve media capacity
284 #define USBFLOPPY2 3 // for those that use ReadFormatCapacity(0x23) command to retrieve media capacity
285
286 //
287 // Bot device structure
288 //
289 #define PEI_BOT_DEVICE_SIGNATURE SIGNATURE_32 ('U', 'B', 'O', 'T')
290 typedef struct {
291 UINTN Signature;
292 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi;
293 EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi;
294 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;
295 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList;
296 EFI_PEI_BLOCK_IO_MEDIA Media;
297 EFI_PEI_BLOCK_IO2_MEDIA Media2;
298 PEI_USB_IO_PPI *UsbIoPpi;
299 EFI_USB_INTERFACE_DESCRIPTOR *BotInterface;
300 EFI_USB_ENDPOINT_DESCRIPTOR *BulkInEndpoint;
301 EFI_USB_ENDPOINT_DESCRIPTOR *BulkOutEndpoint;
302 UINTN AllocateAddress;
303 UINTN DeviceType;
304 ATAPI_REQUEST_SENSE_DATA *SensePtr;
305 } PEI_BOT_DEVICE;
306
307 #define PEI_BOT_DEVICE_FROM_THIS(a) CR (a, PEI_BOT_DEVICE, BlkIoPpi, PEI_BOT_DEVICE_SIGNATURE)
308 #define PEI_BOT_DEVICE2_FROM_THIS(a) CR (a, PEI_BOT_DEVICE, BlkIo2Ppi, PEI_BOT_DEVICE_SIGNATURE)
309
310 /**
311 Send ATAPI command using BOT protocol.
312
313 @param PeiServices The pointer of EFI_PEI_SERVICES.
314 @param PeiBotDev The instance to PEI_BOT_DEVICE.
315 @param Command The command to be sent to ATAPI device.
316 @param CommandSize The length of the data to be sent.
317 @param DataBuffer The pointer to the data.
318 @param BufferLength The length of the data.
319 @param Direction The direction of the data.
320 @param TimeOutInMilliSeconds Indicates the maximum time, in millisecond, which the
321 transfer is allowed to complete.
322
323 @retval EFI_DEVICE_ERROR Successful to get the status of device.
324 @retval EFI_SUCCESS Failed to get the status of device.
325
326 **/
327 EFI_STATUS
328 PeiAtapiCommand (
329 IN EFI_PEI_SERVICES **PeiServices,
330 IN PEI_BOT_DEVICE *PeiBotDev,
331 IN VOID *Command,
332 IN UINT8 CommandSize,
333 IN VOID *DataBuffer,
334 IN UINT32 BufferLength,
335 IN EFI_USB_DATA_DIRECTION Direction,
336 IN UINT16 TimeOutInMilliSeconds
337 );
338
339 #endif