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