]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbBotPei/UsbBotPeim.h
MdeModulePkg/IdeBusPei: Add RecoveryBlockIo2 support
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbBotPei / UsbBotPeim.h
CommitLineData
4b1bf81c 1/** @file\r
2Usb BOT Peim definition.\r
3\r
4Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
5 \r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions\r
8of the BSD License which accompanies this distribution. The\r
9full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15**/\r
16\r
17#ifndef _PEI_USB_BOT_PEIM_H_\r
18#define _PEI_USB_BOT_PEIM_H_\r
19\r
20#include <PiPei.h>\r
21\r
22#include <Ppi/UsbIo.h>\r
23#include <Ppi/UsbHostController.h>\r
24#include <Ppi/BlockIo.h>\r
25\r
26#include <Library/DebugLib.h>\r
27\r
28#include <IndustryStandard/Usb.h>\r
29#include <IndustryStandard/Atapi.h>\r
30\r
31#define PEI_FAT_MAX_USB_IO_PPI 127\r
32\r
33/**\r
34 Gets the count of block I/O devices that one specific block driver detects.\r
35\r
36 This function is used for getting the count of block I/O devices that one \r
37 specific block driver detects. To the PEI ATAPI driver, it returns the number\r
38 of all the detected ATAPI devices it detects during the enumeration process. \r
39 To the PEI legacy floppy driver, it returns the number of all the legacy \r
40 devices it finds during its enumeration process. If no device is detected, \r
41 then the function will return zero. \r
42 \r
43 @param[in] PeiServices General-purpose services that are available \r
44 to every PEIM.\r
45 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI \r
46 instance.\r
47 @param[out] NumberBlockDevices The number of block I/O devices discovered.\r
48\r
49 @retval EFI_SUCCESS Operation performed successfully.\r
50\r
51**/\r
52EFI_STATUS\r
53EFIAPI\r
54BotGetNumberOfBlockDevices (\r
55 IN EFI_PEI_SERVICES **PeiServices,\r
56 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
57 OUT UINTN *NumberBlockDevices\r
58 );\r
59\r
60/**\r
61 Gets a block device's media information.\r
62\r
63 This function will provide the caller with the specified block device's media \r
64 information. If the media changes, calling this function will update the media \r
65 information accordingly.\r
66\r
67 @param[in] PeiServices General-purpose services that are available to every\r
68 PEIM\r
69 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
70 @param[in] DeviceIndex Specifies the block device to which the function wants \r
71 to talk. Because the driver that implements Block I/O \r
72 PPIs will manage multiple block devices, the PPIs that \r
73 want to talk to a single device must specify the \r
74 device index that was assigned during the enumeration\r
75 process. This index is a number from one to \r
76 NumberBlockDevices.\r
77 @param[out] MediaInfo The media information of the specified block media. \r
78 The caller is responsible for the ownership of this \r
79 data structure.\r
80\r
81 @retval EFI_SUCCESS Media information about the specified block device \r
82 was obtained successfully.\r
83 @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware \r
84 error.\r
85\r
86**/\r
87EFI_STATUS\r
88EFIAPI\r
89BotGetMediaInfo (\r
90 IN EFI_PEI_SERVICES **PeiServices,\r
91 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
92 IN UINTN DeviceIndex,\r
93 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo\r
94 );\r
95\r
96/**\r
97 Reads the requested number of blocks from the specified block device.\r
98\r
99 The function reads the requested number of blocks from the device. All the \r
100 blocks are read, or an error is returned. If there is no media in the device,\r
101 the function returns EFI_NO_MEDIA.\r
102\r
103 @param[in] PeiServices General-purpose services that are available to \r
104 every PEIM.\r
105 @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r
106 @param[in] DeviceIndex Specifies the block device to which the function wants \r
107 to talk. Because the driver that implements Block I/O \r
108 PPIs will manage multiple block devices, the PPIs that \r
109 want to talk to a single device must specify the device \r
110 index that was assigned during the enumeration process. \r
111 This index is a number from one to NumberBlockDevices.\r
112 @param[in] StartLBA The starting logical block address (LBA) to read from\r
113 on the device\r
114 @param[in] BufferSize The size of the Buffer in bytes. This number must be\r
115 a multiple of the intrinsic block size of the device.\r
116 @param[out] Buffer A pointer to the destination buffer for the data.\r
117 The caller is responsible for the ownership of the \r
118 buffer.\r
119\r
120 @retval EFI_SUCCESS The data was read correctly from the device.\r
121 @retval EFI_DEVICE_ERROR The device reported an error while attempting \r
122 to perform the read operation.\r
123 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not \r
124 valid, or the buffer is not properly aligned.\r
125 @retval EFI_NO_MEDIA There is no media in the device.\r
126 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r
127 the intrinsic block size of the device.\r
128\r
129**/\r
130EFI_STATUS\r
131EFIAPI\r
132BotReadBlocks (\r
133 IN EFI_PEI_SERVICES **PeiServices,\r
134 IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r
135 IN UINTN DeviceIndex,\r
136 IN EFI_PEI_LBA StartLBA,\r
137 IN UINTN BufferSize,\r
138 OUT VOID *Buffer\r
139 );\r
140\r
141/**\r
142 UsbIo installation notification function. \r
143 \r
144 This function finds out all the current USB IO PPIs in the system and add them\r
145 into private data.\r
146\r
147 @param PeiServices Indirect reference to the PEI Services Table.\r
148 @param NotifyDesc Address of the notification descriptor data structure.\r
149 @param InvokePpi Address of the PPI that was invoked.\r
150\r
151 @retval EFI_SUCCESS The function completes successfully.\r
152\r
153**/\r
154EFI_STATUS\r
155EFIAPI\r
156NotifyOnUsbIoPpi (\r
157 IN EFI_PEI_SERVICES **PeiServices,\r
158 IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc,\r
159 IN VOID *InvokePpi\r
160 );\r
161\r
162/**\r
163 Initialize the usb bot device.\r
164\r
165 @param[in] PeiServices General-purpose services that are available to every\r
166 PEIM.\r
167 @param[in] UsbIoPpi Indicates the PEI_USB_IO_PPI instance.\r
168\r
169 @retval EFI_SUCCESS The usb bot device is initialized successfully.\r
170 @retval Other Failed to initialize media.\r
171\r
172**/\r
173EFI_STATUS\r
174InitUsbBot (\r
175 IN EFI_PEI_SERVICES **PeiServices,\r
176 IN PEI_USB_IO_PPI *UsbIoPpi\r
177 );\r
178\r
179#define USBCDROM 1 // let the device type value equal to USBCDROM, which is defined by PI spec.\r
180 // Therefore the CdExpressPei module can do recovery on UsbCdrom.\r
181#define USBFLOPPY 2 // for those that use ReadCapacity(0x25) command to retrieve media capacity\r
182#define USBFLOPPY2 3 // for those that use ReadFormatCapacity(0x23) command to retrieve media capacity\r
183\r
184//\r
185// Bot device structure\r
186//\r
187#define PEI_BOT_DEVICE_SIGNATURE SIGNATURE_32 ('U', 'B', 'O', 'T')\r
188typedef struct {\r
189 UINTN Signature;\r
190 EFI_PEI_RECOVERY_BLOCK_IO_PPI BlkIoPpi;\r
191 EFI_PEI_PPI_DESCRIPTOR BlkIoPpiList;\r
192 EFI_PEI_BLOCK_IO_MEDIA Media;\r
193 PEI_USB_IO_PPI *UsbIoPpi;\r
194 EFI_USB_INTERFACE_DESCRIPTOR *BotInterface;\r
195 EFI_USB_ENDPOINT_DESCRIPTOR *BulkInEndpoint;\r
196 EFI_USB_ENDPOINT_DESCRIPTOR *BulkOutEndpoint;\r
197 UINTN AllocateAddress;\r
198 UINTN DeviceType;\r
199 ATAPI_REQUEST_SENSE_DATA *SensePtr;\r
200} PEI_BOT_DEVICE;\r
201\r
202#define PEI_BOT_DEVICE_FROM_THIS(a) CR (a, PEI_BOT_DEVICE, BlkIoPpi, PEI_BOT_DEVICE_SIGNATURE)\r
203\r
204/**\r
205 Send ATAPI command using BOT protocol.\r
206\r
207 @param PeiServices The pointer of EFI_PEI_SERVICES.\r
208 @param PeiBotDev The instance to PEI_BOT_DEVICE.\r
209 @param Command The command to be sent to ATAPI device.\r
210 @param CommandSize The length of the data to be sent.\r
211 @param DataBuffer The pointer to the data.\r
212 @param BufferLength The length of the data.\r
213 @param Direction The direction of the data.\r
214 @param TimeOutInMilliSeconds Indicates the maximum time, in millisecond, which the\r
215 transfer is allowed to complete.\r
216\r
217 @retval EFI_DEVICE_ERROR Successful to get the status of device.\r
218 @retval EFI_SUCCESS Failed to get the status of device.\r
219\r
220**/\r
221EFI_STATUS\r
222PeiAtapiCommand (\r
223 IN EFI_PEI_SERVICES **PeiServices,\r
224 IN PEI_BOT_DEVICE *PeiBotDev,\r
225 IN VOID *Command,\r
226 IN UINT8 CommandSize,\r
227 IN VOID *DataBuffer,\r
228 IN UINT32 BufferLength,\r
229 IN EFI_USB_DATA_DIRECTION Direction,\r
230 IN UINT16 TimeOutInMilliSeconds\r
231 );\r
232\r
233#endif\r