]>
Commit | Line | Data |
---|---|---|
ea060cfa | 1 | /** @file\r |
2 | Private Include file for IdeBus PEIM.\r | |
3 | \r | |
d1102dba | 4 | Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>\r |
ea060cfa | 5 | \r |
9d510e61 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
ea060cfa | 7 | \r |
8 | **/\r | |
9 | \r | |
10 | #ifndef _RECOVERY_ATAPI_H_\r | |
11 | #define _RECOVERY_ATAPI_H_\r | |
12 | \r | |
13 | #include <PiPei.h>\r | |
14 | \r | |
15 | #include <Ppi/BlockIo.h>\r | |
25c80c55 | 16 | #include <Ppi/BlockIo2.h>\r |
ea060cfa | 17 | #include <Ppi/AtaController.h>\r |
18 | \r | |
19 | #include <Library/DebugLib.h>\r | |
20 | #include <Library/TimerLib.h>\r | |
21 | #include <Library/PeimEntryPoint.h>\r | |
22 | #include <Library/PeiServicesLib.h>\r | |
23 | #include <Library/BaseMemoryLib.h>\r | |
24 | #include <Library/IoLib.h>\r | |
25 | #include <Library/PeiServicesTablePointerLib.h>\r | |
26 | #include <Library/MemoryAllocationLib.h>\r | |
27 | #include <Library/PcdLib.h>\r | |
28 | \r | |
29 | \r | |
30 | #include <IndustryStandard/Atapi.h>\r | |
31 | \r | |
32 | #define MAX_SENSE_KEY_COUNT 6\r | |
33 | #define MAX_IDE_CHANNELS 4 // Ide and Sata Primary, Secondary Channel.\r | |
34 | #define MAX_IDE_DEVICES 8 // Ide, Sata Primary, Secondary and Master, Slave device.\r | |
35 | \r | |
36 | typedef enum {\r | |
37 | IdePrimary = 0,\r | |
38 | IdeSecondary = 1,\r | |
39 | IdeMaxChannel = 2\r | |
40 | } EFI_IDE_CHANNEL;\r | |
41 | \r | |
42 | typedef enum {\r | |
43 | IdeMaster = 0,\r | |
44 | IdeSlave = 1,\r | |
45 | IdeMaxDevice = 2\r | |
46 | } EFI_IDE_DEVICE;\r | |
47 | \r | |
48 | //\r | |
49 | // IDE Registers\r | |
50 | //\r | |
51 | typedef union {\r | |
52 | UINT16 Command; /* when write */\r | |
53 | UINT16 Status; /* when read */\r | |
54 | } IDE_CMD_OR_STATUS;\r | |
55 | \r | |
56 | typedef union {\r | |
57 | UINT16 Error; /* when read */\r | |
58 | UINT16 Feature; /* when write */\r | |
59 | } IDE_ERROR_OR_FEATURE;\r | |
60 | \r | |
61 | typedef union {\r | |
62 | UINT16 AltStatus; /* when read */\r | |
63 | UINT16 DeviceControl; /* when write */\r | |
64 | } IDE_ALTSTATUS_OR_DEVICECONTROL;\r | |
65 | \r | |
66 | //\r | |
67 | // IDE registers set\r | |
68 | //\r | |
69 | typedef struct {\r | |
70 | UINT16 Data;\r | |
71 | IDE_ERROR_OR_FEATURE Reg1;\r | |
72 | UINT16 SectorCount;\r | |
73 | UINT16 SectorNumber;\r | |
74 | UINT16 CylinderLsb;\r | |
75 | UINT16 CylinderMsb;\r | |
76 | UINT16 Head;\r | |
77 | IDE_CMD_OR_STATUS Reg;\r | |
78 | \r | |
79 | IDE_ALTSTATUS_OR_DEVICECONTROL Alt;\r | |
80 | UINT16 DriveAddress;\r | |
81 | } IDE_BASE_REGISTERS;\r | |
82 | \r | |
83 | typedef struct {\r | |
84 | \r | |
85 | UINTN DevicePosition;\r | |
86 | EFI_PEI_BLOCK_IO_MEDIA MediaInfo;\r | |
25c80c55 | 87 | EFI_PEI_BLOCK_IO2_MEDIA MediaInfo2;\r |
ea060cfa | 88 | \r |
89 | } PEI_ATAPI_DEVICE_INFO;\r | |
90 | \r | |
91 | #define ATAPI_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('a', 'b', 'i', 'o')\r | |
92 | typedef struct {\r | |
93 | UINTN Signature;\r | |
94 | \r | |
95 | EFI_PEI_RECOVERY_BLOCK_IO_PPI AtapiBlkIo;\r | |
25c80c55 | 96 | EFI_PEI_RECOVERY_BLOCK_IO2_PPI AtapiBlkIo2;\r |
ea060cfa | 97 | EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;\r |
25c80c55 | 98 | EFI_PEI_PPI_DESCRIPTOR PpiDescriptor2;\r |
ea060cfa | 99 | PEI_ATA_CONTROLLER_PPI *AtaControllerPpi;\r |
100 | \r | |
101 | UINTN DeviceCount;\r | |
102 | PEI_ATAPI_DEVICE_INFO DeviceInfo[MAX_IDE_DEVICES]; //for max 8 device\r | |
103 | IDE_BASE_REGISTERS IdeIoPortReg[MAX_IDE_CHANNELS]; //for max 4 channel.\r | |
104 | } ATAPI_BLK_IO_DEV;\r | |
105 | \r | |
106 | #define PEI_RECOVERY_ATAPI_FROM_BLKIO_THIS(a) CR (a, ATAPI_BLK_IO_DEV, AtapiBlkIo, ATAPI_BLK_IO_DEV_SIGNATURE)\r | |
25c80c55 | 107 | #define PEI_RECOVERY_ATAPI_FROM_BLKIO2_THIS(a) CR (a, ATAPI_BLK_IO_DEV, AtapiBlkIo2, ATAPI_BLK_IO_DEV_SIGNATURE)\r |
ea060cfa | 108 | \r |
109 | \r | |
110 | #define STALL_1_MILLI_SECOND 1000 // stall 1 ms\r | |
111 | #define STALL_1_SECONDS 1000 * STALL_1_MILLI_SECOND\r | |
112 | \r | |
113 | //\r | |
114 | // Time Out Value For IDE Device Polling\r | |
115 | //\r | |
116 | // ATATIMEOUT is used for waiting time out for ATA device\r | |
117 | //\r | |
118 | #define ATATIMEOUT 1000 // 1 second\r | |
119 | // ATAPITIMEOUT is used for waiting operation\r | |
120 | // except read and write time out for ATAPI device\r | |
121 | //\r | |
122 | #define ATAPITIMEOUT 1000 // 1 second\r | |
123 | // ATAPILONGTIMEOUT is used for waiting read and\r | |
124 | // write operation timeout for ATAPI device\r | |
125 | //\r | |
126 | #define CDROMLONGTIMEOUT 2000 // 2 seconds\r | |
127 | #define ATAPILONGTIMEOUT 5000 // 5 seconds\r | |
128 | \r | |
129 | //\r | |
130 | // PEI Recovery Block I/O PPI\r | |
131 | //\r | |
132 | \r | |
133 | /**\r | |
134 | Gets the count of block I/O devices that one specific block driver detects.\r | |
135 | \r | |
d1102dba | 136 | This function is used for getting the count of block I/O devices that one\r |
ea060cfa | 137 | specific block driver detects. To the PEI ATAPI driver, it returns the number\r |
d1102dba LG |
138 | of all the detected ATAPI devices it detects during the enumeration process.\r |
139 | To the PEI legacy floppy driver, it returns the number of all the legacy\r | |
140 | devices it finds during its enumeration process. If no device is detected,\r | |
141 | then the function will return zero.\r | |
142 | \r | |
143 | @param[in] PeiServices General-purpose services that are available\r | |
ea060cfa | 144 | to every PEIM.\r |
d1102dba | 145 | @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI\r |
ea060cfa | 146 | instance.\r |
147 | @param[out] NumberBlockDevices The number of block I/O devices discovered.\r | |
148 | \r | |
149 | @retval EFI_SUCCESS Operation performed successfully.\r | |
150 | \r | |
151 | **/\r | |
152 | EFI_STATUS\r | |
153 | EFIAPI\r | |
154 | AtapiGetNumberOfBlockDevices (\r | |
155 | IN EFI_PEI_SERVICES **PeiServices,\r | |
156 | IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r | |
157 | OUT UINTN *NumberBlockDevices\r | |
158 | );\r | |
159 | \r | |
160 | /**\r | |
161 | Gets a block device's media information.\r | |
162 | \r | |
d1102dba LG |
163 | This function will provide the caller with the specified block device's media\r |
164 | information. If the media changes, calling this function will update the media\r | |
ea060cfa | 165 | information accordingly.\r |
166 | \r | |
167 | @param[in] PeiServices General-purpose services that are available to every\r | |
168 | PEIM\r | |
169 | @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r | |
d1102dba LG |
170 | @param[in] DeviceIndex Specifies the block device to which the function wants\r |
171 | to talk. Because the driver that implements Block I/O\r | |
172 | PPIs will manage multiple block devices, the PPIs that\r | |
173 | want to talk to a single device must specify the\r | |
ea060cfa | 174 | device index that was assigned during the enumeration\r |
d1102dba | 175 | process. This index is a number from one to\r |
ea060cfa | 176 | NumberBlockDevices.\r |
d1102dba LG |
177 | @param[out] MediaInfo The media information of the specified block media.\r |
178 | The caller is responsible for the ownership of this\r | |
ea060cfa | 179 | data structure.\r |
d1102dba LG |
180 | \r |
181 | @retval EFI_SUCCESS Media information about the specified block device\r | |
ea060cfa | 182 | was obtained successfully.\r |
d1102dba | 183 | @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r |
ea060cfa | 184 | error.\r |
185 | @retval Others Other failure occurs.\r | |
186 | \r | |
187 | **/\r | |
188 | EFI_STATUS\r | |
189 | EFIAPI\r | |
190 | AtapiGetBlockDeviceMediaInfo (\r | |
191 | IN EFI_PEI_SERVICES **PeiServices,\r | |
192 | IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r | |
193 | IN UINTN DeviceIndex,\r | |
194 | OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo\r | |
195 | );\r | |
196 | \r | |
197 | /**\r | |
198 | Reads the requested number of blocks from the specified block device.\r | |
199 | \r | |
d1102dba | 200 | The function reads the requested number of blocks from the device. All the\r |
ea060cfa | 201 | blocks are read, or an error is returned. If there is no media in the device,\r |
202 | the function returns EFI_NO_MEDIA.\r | |
203 | \r | |
d1102dba | 204 | @param[in] PeiServices General-purpose services that are available to\r |
ea060cfa | 205 | every PEIM.\r |
206 | @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.\r | |
d1102dba LG |
207 | @param[in] DeviceIndex Specifies the block device to which the function wants\r |
208 | to talk. Because the driver that implements Block I/O\r | |
209 | PPIs will manage multiple block devices, the PPIs that\r | |
210 | want to talk to a single device must specify the device\r | |
211 | index that was assigned during the enumeration process.\r | |
ea060cfa | 212 | This index is a number from one to NumberBlockDevices.\r |
213 | @param[in] StartLBA The starting logical block address (LBA) to read from\r | |
214 | on the device\r | |
215 | @param[in] BufferSize The size of the Buffer in bytes. This number must be\r | |
216 | a multiple of the intrinsic block size of the device.\r | |
217 | @param[out] Buffer A pointer to the destination buffer for the data.\r | |
d1102dba | 218 | The caller is responsible for the ownership of the\r |
ea060cfa | 219 | buffer.\r |
d1102dba | 220 | \r |
ea060cfa | 221 | @retval EFI_SUCCESS The data was read correctly from the device.\r |
d1102dba | 222 | @retval EFI_DEVICE_ERROR The device reported an error while attempting\r |
ea060cfa | 223 | to perform the read operation.\r |
d1102dba | 224 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r |
ea060cfa | 225 | valid, or the buffer is not properly aligned.\r |
226 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
227 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r | |
228 | the intrinsic block size of the device.\r | |
229 | \r | |
230 | **/\r | |
231 | EFI_STATUS\r | |
232 | EFIAPI\r | |
233 | AtapiReadBlocks (\r | |
234 | IN EFI_PEI_SERVICES **PeiServices,\r | |
235 | IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This,\r | |
236 | IN UINTN DeviceIndex,\r | |
237 | IN EFI_PEI_LBA StartLBA,\r | |
238 | IN UINTN BufferSize,\r | |
239 | OUT VOID *Buffer\r | |
240 | );\r | |
241 | \r | |
25c80c55 FT |
242 | /**\r |
243 | Gets the count of block I/O devices that one specific block driver detects.\r | |
244 | \r | |
245 | This function is used for getting the count of block I/O devices that one\r | |
246 | specific block driver detects. To the PEI ATAPI driver, it returns the number\r | |
247 | of all the detected ATAPI devices it detects during the enumeration process.\r | |
248 | To the PEI legacy floppy driver, it returns the number of all the legacy\r | |
249 | devices it finds during its enumeration process. If no device is detected,\r | |
250 | then the function will return zero.\r | |
251 | \r | |
252 | @param[in] PeiServices General-purpose services that are available\r | |
253 | to every PEIM.\r | |
254 | @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI\r | |
255 | instance.\r | |
256 | @param[out] NumberBlockDevices The number of block I/O devices discovered.\r | |
257 | \r | |
258 | @retval EFI_SUCCESS Operation performed successfully.\r | |
259 | \r | |
260 | **/\r | |
261 | EFI_STATUS\r | |
262 | EFIAPI\r | |
263 | AtapiGetNumberOfBlockDevices2 (\r | |
264 | IN EFI_PEI_SERVICES **PeiServices,\r | |
265 | IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r | |
266 | OUT UINTN *NumberBlockDevices\r | |
267 | );\r | |
268 | \r | |
269 | /**\r | |
270 | Gets a block device's media information.\r | |
271 | \r | |
272 | This function will provide the caller with the specified block device's media\r | |
273 | information. If the media changes, calling this function will update the media\r | |
274 | information accordingly.\r | |
275 | \r | |
276 | @param[in] PeiServices General-purpose services that are available to every\r | |
277 | PEIM\r | |
278 | @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r | |
279 | @param[in] DeviceIndex Specifies the block device to which the function wants\r | |
280 | to talk. Because the driver that implements Block I/O\r | |
281 | PPIs will manage multiple block devices, the PPIs that\r | |
282 | want to talk to a single device must specify the\r | |
283 | device index that was assigned during the enumeration\r | |
284 | process. This index is a number from one to\r | |
285 | NumberBlockDevices.\r | |
286 | @param[out] MediaInfo The media information of the specified block media.\r | |
287 | The caller is responsible for the ownership of this\r | |
288 | data structure.\r | |
289 | \r | |
290 | @retval EFI_SUCCESS Media information about the specified block device\r | |
291 | was obtained successfully.\r | |
292 | @retval EFI_DEVICE_ERROR Cannot get the media information due to a hardware\r | |
293 | error.\r | |
294 | @retval Others Other failure occurs.\r | |
295 | \r | |
296 | **/\r | |
297 | EFI_STATUS\r | |
298 | EFIAPI\r | |
299 | AtapiGetBlockDeviceMediaInfo2 (\r | |
300 | IN EFI_PEI_SERVICES **PeiServices,\r | |
301 | IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r | |
302 | IN UINTN DeviceIndex,\r | |
303 | OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo\r | |
304 | );\r | |
305 | \r | |
306 | /**\r | |
307 | Reads the requested number of blocks from the specified block device.\r | |
308 | \r | |
309 | The function reads the requested number of blocks from the device. All the\r | |
310 | blocks are read, or an error is returned. If there is no media in the device,\r | |
311 | the function returns EFI_NO_MEDIA.\r | |
312 | \r | |
313 | @param[in] PeiServices General-purpose services that are available to\r | |
314 | every PEIM.\r | |
315 | @param[in] This Indicates the EFI_PEI_RECOVERY_BLOCK_IO2_PPI instance.\r | |
316 | @param[in] DeviceIndex Specifies the block device to which the function wants\r | |
317 | to talk. Because the driver that implements Block I/O\r | |
318 | PPIs will manage multiple block devices, the PPIs that\r | |
319 | want to talk to a single device must specify the device\r | |
320 | index that was assigned during the enumeration process.\r | |
321 | This index is a number from one to NumberBlockDevices.\r | |
322 | @param[in] StartLBA The starting logical block address (LBA) to read from\r | |
323 | on the device\r | |
324 | @param[in] BufferSize The size of the Buffer in bytes. This number must be\r | |
325 | a multiple of the intrinsic block size of the device.\r | |
326 | @param[out] Buffer A pointer to the destination buffer for the data.\r | |
327 | The caller is responsible for the ownership of the\r | |
328 | buffer.\r | |
329 | \r | |
330 | @retval EFI_SUCCESS The data was read correctly from the device.\r | |
331 | @retval EFI_DEVICE_ERROR The device reported an error while attempting\r | |
332 | to perform the read operation.\r | |
333 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not\r | |
334 | valid, or the buffer is not properly aligned.\r | |
335 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
336 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of\r | |
337 | the intrinsic block size of the device.\r | |
338 | \r | |
339 | **/\r | |
340 | EFI_STATUS\r | |
341 | EFIAPI\r | |
342 | AtapiReadBlocks2 (\r | |
343 | IN EFI_PEI_SERVICES **PeiServices,\r | |
344 | IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This,\r | |
345 | IN UINTN DeviceIndex,\r | |
346 | IN EFI_PEI_LBA StartLBA,\r | |
347 | IN UINTN BufferSize,\r | |
348 | OUT VOID *Buffer\r | |
349 | );\r | |
350 | \r | |
ea060cfa | 351 | //\r |
352 | // Internal functions\r | |
353 | //\r | |
354 | \r | |
355 | /**\r | |
356 | Enumerate Atapi devices.\r | |
357 | \r | |
358 | This function is used to enumerate Atatpi device in Ide channel.\r | |
359 | \r | |
360 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device\r | |
361 | \r | |
362 | **/\r | |
363 | VOID\r | |
364 | AtapiEnumerateDevices (\r | |
365 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev\r | |
366 | );\r | |
367 | \r | |
368 | /**\r | |
369 | Detect Atapi devices.\r | |
d1102dba | 370 | \r |
ea060cfa | 371 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r |
372 | @param[in] DevicePosition An integer to signify device position.\r | |
373 | @param[out] MediaInfo The media information of the specified block media.\r | |
25c80c55 | 374 | @param[out] MediaInfo2 The media information 2 of the specified block media.\r |
ea060cfa | 375 | \r |
376 | @retval TRUE Atapi device exists in specified position.\r | |
377 | @retval FALSE Atapi device does not exist in specified position.\r | |
378 | \r | |
379 | **/\r | |
380 | BOOLEAN\r | |
381 | DiscoverAtapiDevice (\r | |
382 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
383 | IN UINTN DevicePosition,\r | |
25c80c55 FT |
384 | OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo,\r |
385 | OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2\r | |
ea060cfa | 386 | );\r |
387 | \r | |
388 | /**\r | |
389 | Detect if an IDE controller exists in specified position.\r | |
d1102dba | 390 | \r |
ea060cfa | 391 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r |
392 | @param[in] DevicePosition An integer to signify device position.\r | |
393 | \r | |
394 | @retval TRUE The Atapi device exists.\r | |
395 | @retval FALSE The Atapi device does not present.\r | |
396 | \r | |
397 | **/\r | |
398 | BOOLEAN\r | |
399 | DetectIDEController (\r | |
400 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
401 | IN UINTN DevicePosition\r | |
402 | );\r | |
403 | \r | |
404 | /**\r | |
405 | Wait specified time interval to poll for BSY bit clear in the Status Register.\r | |
d1102dba | 406 | \r |
ea060cfa | 407 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r |
408 | @param[in] IdeIoRegisters A pointer to IDE IO registers.\r | |
409 | @param[in] TimeoutInMilliSeconds Time specified in milliseconds.\r | |
410 | \r | |
411 | @retval EFI_SUCCESS BSY bit is cleared in the specified time interval.\r | |
412 | @retval EFI_TIMEOUT BSY bit is not cleared in the specified time interval.\r | |
413 | \r | |
414 | **/\r | |
415 | EFI_STATUS\r | |
416 | WaitForBSYClear (\r | |
417 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
418 | IN IDE_BASE_REGISTERS *IdeIoRegisters,\r | |
419 | IN UINTN TimeoutInMilliSeconds\r | |
420 | );\r | |
421 | \r | |
422 | /**\r | |
423 | Wait specified time interval to poll for DRDY bit set in the Status register.\r | |
d1102dba | 424 | \r |
ea060cfa | 425 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r |
426 | @param[in] IdeIoRegisters A pointer to IDE IO registers.\r | |
427 | @param[in] TimeoutInMilliSeconds Time specified in milliseconds.\r | |
428 | \r | |
429 | @retval EFI_SUCCESS DRDY bit is set in the specified time interval.\r | |
430 | @retval EFI_TIMEOUT DRDY bit is not set in the specified time interval.\r | |
431 | \r | |
432 | **/\r | |
433 | EFI_STATUS\r | |
434 | DRDYReady (\r | |
435 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
436 | IN IDE_BASE_REGISTERS *IdeIoRegisters,\r | |
437 | IN UINTN TimeoutInMilliSeconds\r | |
438 | );\r | |
439 | \r | |
440 | /**\r | |
441 | Wait specified time interval to poll for DRQ bit clear in the Status Register.\r | |
d1102dba | 442 | \r |
ea060cfa | 443 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r |
444 | @param[in] IdeIoRegisters A pointer to IDE IO registers.\r | |
445 | @param[in] TimeoutInMilliSeconds Time specified in milliseconds.\r | |
446 | \r | |
447 | @retval EFI_SUCCESS DRQ bit is cleared in the specified time interval.\r | |
448 | @retval EFI_TIMEOUT DRQ bit is not cleared in the specified time interval.\r | |
449 | \r | |
450 | **/\r | |
451 | EFI_STATUS\r | |
452 | DRQClear (\r | |
453 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
454 | IN IDE_BASE_REGISTERS *IdeIoRegisters,\r | |
455 | IN UINTN TimeoutInMilliSeconds\r | |
456 | );\r | |
457 | \r | |
458 | /**\r | |
459 | Wait specified time interval to poll for DRQ bit clear in the Alternate Status Register.\r | |
d1102dba | 460 | \r |
ea060cfa | 461 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r |
462 | @param[in] IdeIoRegisters A pointer to IDE IO registers.\r | |
463 | @param[in] TimeoutInMilliSeconds Time specified in milliseconds.\r | |
464 | \r | |
465 | @retval EFI_SUCCESS DRQ bit is cleared in the specified time interval.\r | |
466 | @retval EFI_TIMEOUT DRQ bit is not cleared in the specified time interval.\r | |
467 | \r | |
468 | **/\r | |
469 | EFI_STATUS\r | |
470 | DRQClear2 (\r | |
471 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
472 | IN IDE_BASE_REGISTERS *IdeIoRegisters,\r | |
473 | IN UINTN TimeoutInMilliSeconds\r | |
474 | );\r | |
475 | \r | |
476 | /**\r | |
477 | Wait specified time interval to poll for DRQ bit set in the Status Register.\r | |
478 | \r | |
479 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
480 | @param[in] IdeIoRegisters A pointer to IDE IO registers.\r | |
481 | @param[in] TimeoutInMilliSeconds Time specified in milliseconds.\r | |
482 | \r | |
483 | @retval EFI_SUCCESS DRQ bit is set in the specified time interval.\r | |
484 | @retval EFI_TIMEOUT DRQ bit is not set in the specified time interval.\r | |
485 | @retval EFI_ABORTED Operation Aborted.\r | |
486 | \r | |
487 | **/\r | |
488 | EFI_STATUS\r | |
489 | DRQReady (\r | |
490 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
491 | IN IDE_BASE_REGISTERS *IdeIoRegisters,\r | |
492 | IN UINTN TimeoutInMilliSeconds\r | |
493 | );\r | |
494 | \r | |
495 | /**\r | |
496 | Wait specified time interval to poll for DRQ bit set in the Alternate Status Register.\r | |
497 | \r | |
498 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
499 | @param[in] IdeIoRegisters A pointer to IDE IO registers.\r | |
500 | @param[in] TimeoutInMilliSeconds Time specified in milliseconds.\r | |
501 | \r | |
502 | @retval EFI_SUCCESS DRQ bit is set in the specified time interval.\r | |
503 | @retval EFI_TIMEOUT DRQ bit is not set in the specified time interval.\r | |
504 | @retval EFI_ABORTED Operation Aborted.\r | |
505 | \r | |
506 | **/\r | |
507 | EFI_STATUS\r | |
508 | DRQReady2 (\r | |
509 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
510 | IN IDE_BASE_REGISTERS *IdeIoRegisters,\r | |
511 | IN UINTN TimeoutInMilliSeconds\r | |
512 | );\r | |
513 | \r | |
514 | /**\r | |
515 | Check if there is an error in Status Register.\r | |
516 | \r | |
517 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
518 | @param[in] StatusReg The address to IDE IO registers.\r | |
519 | \r | |
520 | @retval EFI_SUCCESS Operation success.\r | |
521 | @retval EFI_DEVICE_ERROR Device error.\r | |
522 | \r | |
523 | **/\r | |
524 | EFI_STATUS\r | |
525 | CheckErrorStatus (\r | |
526 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
527 | IN UINT16 StatusReg\r | |
528 | );\r | |
529 | \r | |
530 | /**\r | |
531 | Idendify Atapi devices.\r | |
532 | \r | |
533 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
534 | @param[in] DevicePosition An integer to signify device position.\r | |
535 | \r | |
536 | @retval EFI_SUCCESS Identify successfully.\r | |
537 | @retval EFI_DEVICE_ERROR Device cannot be identified successfully.\r | |
538 | \r | |
539 | **/\r | |
540 | EFI_STATUS\r | |
541 | ATAPIIdentify (\r | |
542 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
543 | IN UINTN DevicePosition\r | |
544 | );\r | |
545 | \r | |
546 | /**\r | |
547 | Sends out ATAPI Test Unit Ready Packet Command to the specified device\r | |
548 | to find out whether device is accessible.\r | |
549 | \r | |
550 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
551 | @param[in] DevicePosition An integer to signify device position.\r | |
552 | \r | |
553 | @retval EFI_SUCCESS TestUnit command executed successfully.\r | |
554 | @retval EFI_DEVICE_ERROR Device cannot be executed TestUnit command successfully.\r | |
555 | \r | |
556 | **/\r | |
557 | EFI_STATUS\r | |
558 | TestUnitReady (\r | |
559 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
560 | IN UINTN DevicePosition\r | |
561 | ) ;\r | |
562 | \r | |
563 | /**\r | |
564 | Send out ATAPI commands conforms to the Packet Command with PIO Data In Protocol.\r | |
d1102dba | 565 | \r |
ea060cfa | 566 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r |
567 | @param[in] DevicePosition An integer to signify device position.\r | |
568 | @param[in] Packet A pointer to ATAPI command packet.\r | |
569 | @param[in] Buffer Buffer to contain requested transfer data from device.\r | |
570 | @param[in] ByteCount Requested transfer data length.\r | |
571 | @param[in] TimeoutInMilliSeconds Time out value, in unit of milliseconds.\r | |
572 | \r | |
573 | @retval EFI_SUCCESS Command executed successfully.\r | |
574 | @retval EFI_DEVICE_ERROR Device cannot be executed command successfully.\r | |
575 | \r | |
576 | **/\r | |
577 | EFI_STATUS\r | |
578 | AtapiPacketCommandIn (\r | |
579 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
580 | IN UINTN DevicePosition,\r | |
581 | IN ATAPI_PACKET_COMMAND *Packet,\r | |
582 | IN UINT16 *Buffer,\r | |
583 | IN UINT32 ByteCount,\r | |
584 | IN UINTN TimeoutInMilliSeconds\r | |
585 | );\r | |
586 | \r | |
587 | /**\r | |
588 | Sends out ATAPI Inquiry Packet Command to the specified device.\r | |
589 | This command will return INQUIRY data of the device.\r | |
590 | \r | |
591 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
592 | @param[in] DevicePosition An integer to signify device position.\r | |
593 | @param[out] MediaInfo The media information of the specified block media.\r | |
25c80c55 | 594 | @param[out] MediaInfo2 The media information 2 of the specified block media.\r |
ea060cfa | 595 | \r |
596 | @retval EFI_SUCCESS Command executed successfully.\r | |
597 | @retval EFI_DEVICE_ERROR Device cannot be executed command successfully.\r | |
598 | @retval EFI_UNSUPPORTED Unsupported device type.\r | |
599 | \r | |
600 | **/\r | |
601 | EFI_STATUS\r | |
602 | Inquiry (\r | |
603 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
604 | IN UINTN DevicePosition,\r | |
25c80c55 FT |
605 | OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo,\r |
606 | OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2\r | |
ea060cfa | 607 | );\r |
608 | \r | |
d1102dba LG |
609 | /**\r |
610 | Used before read/write blocks from/to ATAPI device media.\r | |
ea060cfa | 611 | Since ATAPI device media is removable, it is necessary to detect\r |
d1102dba | 612 | whether media is present and get current present media's information.\r |
ea060cfa | 613 | \r |
614 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
615 | @param[in] DevicePosition An integer to signify device position.\r | |
25c80c55 FT |
616 | @param[in, out] MediaInfo The media information of the specified block media.\r |
617 | @param[in, out] MediaInfo2 The media information 2 of the specified block media.\r | |
ea060cfa | 618 | \r |
619 | @retval EFI_SUCCESS Command executed successfully.\r | |
620 | @retval EFI_DEVICE_ERROR Some device errors happen.\r | |
621 | @retval EFI_OUT_OF_RESOURCES Can not allocate required resources.\r | |
622 | \r | |
623 | **/\r | |
624 | EFI_STATUS\r | |
625 | DetectMedia (\r | |
626 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
627 | IN UINTN DevicePosition,\r | |
25c80c55 FT |
628 | IN OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo,\r |
629 | IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2\r | |
ea060cfa | 630 | );\r |
631 | \r | |
d1102dba | 632 | /**\r |
ea060cfa | 633 | Reset specified Atapi device.\r |
634 | \r | |
635 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
636 | @param[in] DevicePosition An integer to signify device position.\r | |
637 | @param[in] Extensive If TRUE, use ATA soft reset, otherwise use Atapi soft reset.\r | |
638 | \r | |
639 | @retval EFI_SUCCESS Command executed successfully.\r | |
640 | @retval EFI_DEVICE_ERROR Some device errors happen.\r | |
641 | \r | |
642 | **/\r | |
643 | EFI_STATUS\r | |
644 | ResetDevice (\r | |
645 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
646 | IN UINTN DevicePosition,\r | |
647 | IN BOOLEAN Extensive\r | |
648 | );\r | |
649 | \r | |
d1102dba | 650 | /**\r |
ea060cfa | 651 | Sends out ATAPI Request Sense Packet Command to the specified device.\r |
652 | \r | |
653 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
654 | @param[in] DevicePosition An integer to signify device position.\r | |
655 | @param[in] SenseBuffers Pointer to sense buffer.\r | |
656 | @param[in, out] SenseCounts Length of sense buffer.\r | |
657 | \r | |
658 | @retval EFI_SUCCESS Command executed successfully.\r | |
659 | @retval EFI_DEVICE_ERROR Some device errors happen.\r | |
660 | \r | |
661 | **/\r | |
662 | EFI_STATUS\r | |
663 | RequestSense (\r | |
25c80c55 FT |
664 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r |
665 | IN UINTN DevicePosition,\r | |
ea060cfa | 666 | IN ATAPI_REQUEST_SENSE_DATA *SenseBuffers,\r |
25c80c55 | 667 | IN OUT UINT8 *SenseCounts\r |
ea060cfa | 668 | );\r |
669 | \r | |
d1102dba | 670 | /**\r |
ea060cfa | 671 | Sends out ATAPI Read Capacity Packet Command to the specified device.\r |
672 | This command will return the information regarding the capacity of the\r | |
673 | media in the device.\r | |
674 | \r | |
675 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
676 | @param[in] DevicePosition An integer to signify device position.\r | |
25c80c55 FT |
677 | @param[in, out] MediaInfo The media information of the specified block media.\r |
678 | @param[in, out] MediaInfo2 The media information 2 of the specified block media.\r | |
ea060cfa | 679 | \r |
680 | @retval EFI_SUCCESS Command executed successfully.\r | |
681 | @retval EFI_DEVICE_ERROR Some device errors happen.\r | |
682 | \r | |
683 | **/\r | |
684 | EFI_STATUS\r | |
685 | ReadCapacity (\r | |
686 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
687 | IN UINTN DevicePosition,\r | |
25c80c55 FT |
688 | IN OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo,\r |
689 | IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2\r | |
ea060cfa | 690 | );\r |
691 | \r | |
d1102dba | 692 | /**\r |
ea060cfa | 693 | Perform read from disk in block unit.\r |
694 | \r | |
695 | @param[in] AtapiBlkIoDev A pointer to atapi block IO device.\r | |
696 | @param[in] DevicePosition An integer to signify device position.\r | |
697 | @param[in] Buffer Buffer to contain read data.\r | |
698 | @param[in] StartLba Starting LBA address.\r | |
699 | @param[in] NumberOfBlocks Number of blocks to read.\r | |
700 | @param[in] BlockSize Size of each block.\r | |
701 | \r | |
702 | @retval EFI_SUCCESS Command executed successfully.\r | |
703 | @retval EFI_DEVICE_ERROR Some device errors happen.\r | |
704 | \r | |
705 | **/\r | |
706 | EFI_STATUS\r | |
707 | ReadSectors (\r | |
708 | IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,\r | |
709 | IN UINTN DevicePosition,\r | |
710 | IN VOID *Buffer,\r | |
711 | IN EFI_PEI_LBA StartLba,\r | |
712 | IN UINTN NumberOfBlocks,\r | |
713 | IN UINTN BlockSize\r | |
714 | );\r | |
715 | \r | |
d1102dba | 716 | /**\r |
ea060cfa | 717 | Check if there is media according to sense data.\r |
718 | \r | |
719 | @param[in] SenseData Pointer to sense data.\r | |
720 | @param[in] SenseCounts Count of sense data.\r | |
721 | \r | |
722 | @retval TRUE No media\r | |
723 | @retval FALSE Media exists\r | |
724 | \r | |
725 | **/\r | |
726 | BOOLEAN\r | |
727 | IsNoMedia (\r | |
728 | IN ATAPI_REQUEST_SENSE_DATA *SenseData,\r | |
729 | IN UINTN SenseCounts\r | |
730 | );\r | |
731 | \r | |
d1102dba | 732 | /**\r |
ea060cfa | 733 | Check if device state is unclear according to sense data.\r |
734 | \r | |
735 | @param[in] SenseData Pointer to sense data.\r | |
736 | @param[in] SenseCounts Count of sense data.\r | |
737 | \r | |
738 | @retval TRUE Device state is unclear\r | |
d1102dba | 739 | @retval FALSE Device state is clear\r |
ea060cfa | 740 | \r |
741 | **/\r | |
742 | BOOLEAN\r | |
743 | IsDeviceStateUnclear (\r | |
744 | IN ATAPI_REQUEST_SENSE_DATA *SenseData,\r | |
745 | IN UINTN SenseCounts\r | |
746 | );\r | |
747 | \r | |
d1102dba | 748 | /**\r |
ea060cfa | 749 | Check if there is media error according to sense data.\r |
750 | \r | |
751 | @param[in] SenseData Pointer to sense data.\r | |
752 | @param[in] SenseCounts Count of sense data.\r | |
753 | \r | |
754 | @retval TRUE Media error\r | |
755 | @retval FALSE No media error\r | |
756 | \r | |
757 | **/\r | |
758 | BOOLEAN\r | |
759 | IsMediaError (\r | |
760 | IN ATAPI_REQUEST_SENSE_DATA *SenseData,\r | |
761 | IN UINTN SenseCounts\r | |
762 | );\r | |
763 | \r | |
d1102dba | 764 | /**\r |
ea060cfa | 765 | Check if drive is ready according to sense data.\r |
766 | \r | |
767 | @param[in] SenseData Pointer to sense data.\r | |
768 | @param[in] SenseCounts Count of sense data.\r | |
769 | @param[out] NeedRetry Indicate if retry is needed.\r | |
770 | \r | |
771 | @retval TRUE Drive ready\r | |
772 | @retval FALSE Drive not ready\r | |
773 | \r | |
774 | **/\r | |
775 | BOOLEAN\r | |
776 | IsDriveReady (\r | |
777 | IN ATAPI_REQUEST_SENSE_DATA *SenseData,\r | |
778 | IN UINTN SenseCounts,\r | |
779 | OUT BOOLEAN *NeedRetry\r | |
780 | );\r | |
781 | \r | |
782 | #endif\r |