2 Usb BOT Peim definition.
4 Copyright (c) 2006, 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>
26 #include <Library/DebugLib.h>
28 #include <IndustryStandard/Usb.h>
29 #include <IndustryStandard/Atapi.h>
31 #define PEI_FAT_MAX_USB_IO_PPI 127
34 Gets the count of block I/O devices that one specific block driver detects.
36 This function is used for getting the count of block I/O devices that one
37 specific block driver detects. To the PEI ATAPI driver, it returns the number
38 of all the detected ATAPI devices it detects during the enumeration process.
39 To the PEI legacy floppy driver, it returns the number of all the legacy
40 devices it finds during its enumeration process. If no device is detected,
41 then the function will return zero.
43 @param[in] PeiServices General-purpose services that are available
45 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI
47 @param[out] NumberBlockDevices The number of block I/O devices discovered.
49 @retval EFI_SUCCESS Operation performed successfully.
54 BotGetNumberOfBlockDevices (
55 IN EFI_PEI_SERVICES
**PeiServices
,
56 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
57 OUT UINTN
*NumberBlockDevices
61 Gets a block device's media information.
63 This function will provide the caller with the specified block device's media
64 information. If the media changes, calling this function will update the media
65 information accordingly.
67 @param[in] PeiServices General-purpose services that are available to every
69 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
70 @param[in] DeviceIndex Specifies the block device to which the function wants
71 to talk. Because the driver that implements Block I/O
72 PPIs will manage multiple block devices, the PPIs that
73 want to talk to a single device must specify the
74 device index that was assigned during the enumeration
75 process. This index is a number from one to
77 @param[out] MediaInfo The media information of the specified block media.
78 The caller is responsible for the ownership of this
81 @retval EFI_SUCCESS Media information about the specified block device
82 was obtained successfully.
83 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware
90 IN EFI_PEI_SERVICES
**PeiServices
,
91 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
93 OUT EFI_PEI_BLOCK_IO_MEDIA
*MediaInfo
97 Reads the requested number of blocks from the specified block device.
99 The function reads the requested number of blocks from the device. All the
100 blocks are read, or an error is returned. If there is no media in the device,
101 the function returns EFI_NO_MEDIA.
103 @param[in] PeiServices General-purpose services that are available to
105 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
106 @param[in] DeviceIndex Specifies the block device to which the function wants
107 to talk. Because the driver that implements Block I/O
108 PPIs will manage multiple block devices, the PPIs that
109 want to talk to a single device must specify the device
110 index that was assigned during the enumeration process.
111 This index is a number from one to NumberBlockDevices.
112 @param[in] StartLBA The starting logical block address (LBA) to read from
114 @param[in] BufferSize The size of the Buffer in bytes. This number must be
115 a multiple of the intrinsic block size of the device.
116 @param[out] Buffer A pointer to the destination buffer for the data.
117 The caller is responsible for the ownership of the
120 @retval EFI_SUCCESS The data was read correctly from the device.
121 @retval EFI_DEVICE_ERROR The device reported an error while attempting
122 to perform the read operation.
123 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not
124 valid, or the buffer is not properly aligned.
125 @retval EFI_NO_MEDIA There is no media in the device.
126 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of
127 the intrinsic block size of the device.
133 IN EFI_PEI_SERVICES
**PeiServices
,
134 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI
*This
,
135 IN UINTN DeviceIndex
,
136 IN EFI_PEI_LBA StartLBA
,
142 UsbIo installation notification function.
144 This function finds out all the current USB IO PPIs in the system and add them
147 @param PeiServices Indirect reference to the PEI Services Table.
148 @param NotifyDesc Address of the notification descriptor data structure.
149 @param InvokePpi Address of the PPI that was invoked.
151 @retval EFI_SUCCESS The function completes successfully.
157 IN EFI_PEI_SERVICES
**PeiServices
,
158 IN EFI_PEI_NOTIFY_DESCRIPTOR
*NotifyDesc
,
163 Initialize the usb bot device.
165 @param[in] PeiServices General-purpose services that are available to every
167 @param[in] UsbIoPpi Indicates the PEI_USB_IO_PPI instance.
169 @retval EFI_SUCCESS The usb bot device is initialized successfully.
170 @retval Other Failed to initialize media.
175 IN EFI_PEI_SERVICES
**PeiServices
,
176 IN PEI_USB_IO_PPI
*UsbIoPpi
179 #define USBCDROM 1 // let the device type value equal to USBCDROM, which is defined by PI spec.
180 // Therefore the CdExpressPei module can do recovery on UsbCdrom.
181 #define USBFLOPPY 2 // for those that use ReadCapacity(0x25) command to retrieve media capacity
182 #define USBFLOPPY2 3 // for those that use ReadFormatCapacity(0x23) command to retrieve media capacity
185 // Bot device structure
187 #define PEI_BOT_DEVICE_SIGNATURE SIGNATURE_32 ('U', 'B', 'O', 'T')
190 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi
;
191 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList
;
192 EFI_PEI_BLOCK_IO_MEDIA Media
;
193 PEI_USB_IO_PPI
*UsbIoPpi
;
194 EFI_USB_INTERFACE_DESCRIPTOR
*BotInterface
;
195 EFI_USB_ENDPOINT_DESCRIPTOR
*BulkInEndpoint
;
196 EFI_USB_ENDPOINT_DESCRIPTOR
*BulkOutEndpoint
;
197 UINTN AllocateAddress
;
199 ATAPI_REQUEST_SENSE_DATA
*SensePtr
;
202 #define PEI_BOT_DEVICE_FROM_THIS(a) CR (a, PEI_BOT_DEVICE, BlkIoPpi, PEI_BOT_DEVICE_SIGNATURE)
205 Send ATAPI command using BOT protocol.
207 @param PeiServices The pointer of EFI_PEI_SERVICES.
208 @param PeiBotDev The instance to PEI_BOT_DEVICE.
209 @param Command The command to be sent to ATAPI device.
210 @param CommandSize The length of the data to be sent.
211 @param DataBuffer The pointer to the data.
212 @param BufferLength The length of the data.
213 @param Direction The direction of the data.
214 @param TimeOutInMilliSeconds Indicates the maximum time, in millisecond, which the
215 transfer is allowed to complete.
217 @retval EFI_DEVICE_ERROR Successful to get the status of device.
218 @retval EFI_SUCCESS Failed to get the status of device.
223 IN EFI_PEI_SERVICES
**PeiServices
,
224 IN PEI_BOT_DEVICE
*PeiBotDev
,
226 IN UINT8 CommandSize
,
228 IN UINT32 BufferLength
,
229 IN EFI_USB_DATA_DIRECTION Direction
,
230 IN UINT16 TimeOutInMilliSeconds