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