2 Usb BOT Peim definition.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
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
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.
17 #ifndef _PEI_USB_BOT_PEIM_H_
18 #define _PEI_USB_BOT_PEIM_H_
22 #include <Ppi/UsbIo.h>
23 #include <Ppi/UsbHostController.h>
24 #include <Ppi/BlockIo.h>
25 #include <Ppi/BlockIo2.h>
27 #include <Library/DebugLib.h>
29 #include <IndustryStandard/Usb.h>
30 #include <IndustryStandard/Atapi.h>
32 #define PEI_FAT_MAX_USB_IO_PPI 127
35 Gets the count of block I/O devices that one specific block driver detects.
37 This function is used for getting the count of block I/O devices that one
38 specific block driver detects. To the PEI ATAPI driver, it returns the number
39 of all the detected ATAPI devices it detects during the enumeration process.
40 To the PEI legacy floppy driver, it returns the number of all the legacy
41 devices it finds during its enumeration process. If no device is detected,
42 then the function will return zero.
44 @param[in] PeiServices General-purpose services that are available
46 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI
48 @param[out] NumberBlockDevices The number of block I/O devices discovered.
50 @retval EFI_SUCCESS Operation performed successfully.
55 BotGetNumberOfBlockDevices (
56 IN EFI_PEI_SERVICES
**PeiServices
,
57 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
58 OUT UINTN
*NumberBlockDevices
62 Gets a block device's media information.
64 This function will provide the caller with the specified block device's media
65 information. If the media changes, calling this function will update the media
66 information accordingly.
68 @param[in] PeiServices General-purpose services that are available to every
70 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
71 @param[in] DeviceIndex Specifies the block device to which the function wants
72 to talk. Because the driver that implements Block I/O
73 PPIs will manage multiple block devices, the PPIs that
74 want to talk to a single device must specify the
75 device index that was assigned during the enumeration
76 process. This index is a number from one to
78 @param[out] MediaInfo The media information of the specified block media.
79 The caller is responsible for the ownership of this
82 @retval EFI_SUCCESS Media information about the specified block device
83 was obtained successfully.
84 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
91 IN EFI_PEI_SERVICES
**PeiServices
,
92 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
94 OUT EFI_PEI_BLOCK_IO_MEDIA
*MediaInfo
98 Reads the requested number of blocks from the specified block device.
100 The function reads the requested number of blocks from the device. All the
101 blocks are read, or an error is returned. If there is no media in the device,
102 the function returns EFI_NO_MEDIA.
104 @param[in] PeiServices General-purpose services that are available to
106 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
107 @param[in] DeviceIndex Specifies the block device to which the function wants
108 to talk. Because the driver that implements Block I/O
109 PPIs will manage multiple block devices, the PPIs that
110 want to talk to a single device must specify the device
111 index that was assigned during the enumeration process.
112 This index is a number from one to NumberBlockDevices.
113 @param[in] StartLBA The starting logical block address (LBA) to read from
115 @param[in] BufferSize The size of the Buffer in bytes. This number must be
116 a multiple of the intrinsic block size of the device.
117 @param[out] Buffer A pointer to the destination buffer for the data.
118 The caller is responsible for the ownership of the
121 @retval EFI_SUCCESS The data was read correctly from the device.
122 @retval EFI_DEVICE_ERROR The device reported an error while attempting
123 to perform the read operation.
124 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
125 valid, or the buffer is not properly aligned.
126 @retval EFI_NO_MEDIA There is no media in the device.
127 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
128 the intrinsic block size of the device.
134 IN EFI_PEI_SERVICES
**PeiServices
,
135 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
136 IN UINTN DeviceIndex
,
137 IN EFI_PEI_LBA StartLBA
,
143 Gets the count of block I/O devices that one specific block driver detects.
145 This function is used for getting the count of block I/O devices that one
146 specific block driver detects. To the PEI ATAPI driver, it returns the number
147 of all the detected ATAPI devices it detects during the enumeration process.
148 To the PEI legacy floppy driver, it returns the number of all the legacy
149 devices it finds during its enumeration process. If no device is detected,
150 then the function will return zero.
152 @param[in] PeiServices General-purpose services that are available
154 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI
156 @param[out] NumberBlockDevices The number of block I/O devices discovered.
158 @retval EFI_SUCCESS Operation performed successfully.
163 BotGetNumberOfBlockDevices2 (
164 IN EFI_PEI_SERVICES
**PeiServices
,
165 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
166 OUT UINTN
*NumberBlockDevices
170 Gets a block device's media information.
172 This function will provide the caller with the specified block device's media
173 information. If the media changes, calling this function will update the media
174 information accordingly.
176 @param[in] PeiServices General-purpose services that are available to every
178 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
179 @param[in] DeviceIndex Specifies the block device to which the function wants
180 to talk. Because the driver that implements Block I/O
181 PPIs will manage multiple block devices, the PPIs that
182 want to talk to a single device must specify the
183 device index that was assigned during the enumeration
184 process. This index is a number from one to
186 @param[out] MediaInfo The media information of the specified block media.
187 The caller is responsible for the ownership of this
190 @retval EFI_SUCCESS Media information about the specified block device
191 was obtained successfully.
192 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
199 IN EFI_PEI_SERVICES
**PeiServices
,
200 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
201 IN UINTN DeviceIndex
,
202 OUT EFI_PEI_BLOCK_IO2_MEDIA
*MediaInfo
206 Reads the requested number of blocks from the specified block device.
208 The function reads the requested number of blocks from the device. All the
209 blocks are read, or an error is returned. If there is no media in the device,
210 the function returns EFI_NO_MEDIA.
212 @param[in] PeiServices General-purpose services that are available to
214 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.
215 @param[in] DeviceIndex Specifies the block device to which the function wants
216 to talk. Because the driver that implements Block I/O
217 PPIs will manage multiple block devices, the PPIs that
218 want to talk to a single device must specify the device
219 index that was assigned during the enumeration process.
220 This index is a number from one to NumberBlockDevices.
221 @param[in] StartLBA The starting logical block address (LBA) to read from
223 @param[in] BufferSize The size of the Buffer in bytes. This number must be
224 a multiple of the intrinsic block size of the device.
225 @param[out] Buffer A pointer to the destination buffer for the data.
226 The caller is responsible for the ownership of the
229 @retval EFI_SUCCESS The data was read correctly from the device.
230 @retval EFI_DEVICE_ERROR The device reported an error while attempting
231 to perform the read operation.
232 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
233 valid, or the buffer is not properly aligned.
234 @retval EFI_NO_MEDIA There is no media in the device.
235 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
236 the intrinsic block size of the device.
242 IN EFI_PEI_SERVICES
**PeiServices
,
243 IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI
*This
,
244 IN UINTN DeviceIndex
,
245 IN EFI_PEI_LBA StartLBA
,
251 UsbIo installation notification function.
253 This function finds out all the current USB IO PPIs in the system and add them
256 @param PeiServices Indirect reference to the PEI Services Table.
257 @param NotifyDesc Address of the notification descriptor data structure.
258 @param InvokePpi Address of the PPI that was invoked.
260 @retval EFI_SUCCESS The function completes successfully.
266 IN EFI_PEI_SERVICES
**PeiServices
,
267 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
272 Initialize the usb bot device.
274 @param[in] PeiServices General-purpose services that are available to every
276 @param[in] UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
278 @retval EFI_SUCCESS The usb bot device is initialized successfully.
279 @retval Other Failed to initialize media.
284 IN EFI_PEI_SERVICES
**PeiServices
,
285 IN PEI_USB_IO_PPI
*UsbIoPpi
288 #define USBCDROM 1 // let the device type value equal to USBCDROM, which is defined by PI spec.
289 // Therefore the CdExpressPei module can do recovery on UsbCdrom.
290 #define USBFLOPPY 2 // for those that use ReadCapacity(0x25) command to retrieve media capacity
291 #define USBFLOPPY2 3 // for those that use ReadFormatCapacity(0x23) command to retrieve media capacity
294 // Bot device structure
296 #define PEI_BOT_DEVICE_SIGNATURE SIGNATURE_32 ('U', 'B', 'O', 'T')
299 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi
;
300 EFI_PEI_RECOVERY_BLOCK_IO2_PPI BlkIo2Ppi
;
301 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList
;
302 EFI_PEI_PPI_DESCRIPTOR BlkIo2PpiList
;
303 EFI_PEI_BLOCK_IO_MEDIA Media
;
304 EFI_PEI_BLOCK_IO2_MEDIA Media2
;
305 PEI_USB_IO_PPI
*UsbIoPpi
;
306 EFI_USB_INTERFACE_DESCRIPTOR
*BotInterface
;
307 EFI_USB_ENDPOINT_DESCRIPTOR
*BulkInEndpoint
;
308 EFI_USB_ENDPOINT_DESCRIPTOR
*BulkOutEndpoint
;
309 UINTN AllocateAddress
;
311 ATAPI_REQUEST_SENSE_DATA
*SensePtr
;
314 #define PEI_BOT_DEVICE_FROM_THIS(a) CR (a, PEI_BOT_DEVICE, BlkIoPpi, PEI_BOT_DEVICE_SIGNATURE)
315 #define PEI_BOT_DEVICE2_FROM_THIS(a) CR (a, PEI_BOT_DEVICE, BlkIo2Ppi, PEI_BOT_DEVICE_SIGNATURE)
318 Send ATAPI command using BOT protocol.
320 @param PeiServices The pointer of EFI_PEI_SERVICES.
321 @param PeiBotDev The instance to PEI_BOT_DEVICE.
322 @param Command The command to be sent to ATAPI device.
323 @param CommandSize The length of the data to be sent.
324 @param DataBuffer The pointer to the data.
325 @param BufferLength The length of the data.
326 @param Direction The direction of the data.
327 @param TimeOutInMilliSeconds Indicates the maximum time, in millisecond, which the
328 transfer is allowed to complete.
330 @retval EFI_DEVICE_ERROR Successful to get the status of device.
331 @retval EFI_SUCCESS Failed to get the status of device.
336 IN EFI_PEI_SERVICES
**PeiServices
,
337 IN PEI_BOT_DEVICE
*PeiBotDev
,
339 IN UINT8 CommandSize
,
341 IN UINT32 BufferLength
,
342 IN EFI_USB_DATA_DIRECTION Direction
,
343 IN UINT16 TimeOutInMilliSeconds