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