TianoCore EDK2 master
Loading...
Searching...
No Matches
AtapiPeim.h
Go to the documentation of this file.
1
10#ifndef _RECOVERY_ATAPI_H_
11#define _RECOVERY_ATAPI_H_
12
13#include <PiPei.h>
14
15#include <Ppi/BlockIo.h>
16#include <Ppi/BlockIo2.h>
17#include <Ppi/AtaController.h>
18
19#include <Library/DebugLib.h>
20#include <Library/TimerLib.h>
24#include <Library/IoLib.h>
27#include <Library/PcdLib.h>
28
30
31#define MAX_SENSE_KEY_COUNT 6
32#define MAX_IDE_CHANNELS 4 // Ide and Sata Primary, Secondary Channel.
33#define MAX_IDE_DEVICES 8 // Ide, Sata Primary, Secondary and Master, Slave device.
34
35typedef enum {
36 IdePrimary = 0,
37 IdeSecondary = 1,
38 IdeMaxChannel = 2
39} EFI_IDE_CHANNEL;
40
41typedef enum {
42 IdeMaster = 0,
43 IdeSlave = 1,
44 IdeMaxDevice = 2
45} EFI_IDE_DEVICE;
46
47//
48// IDE Registers
49//
50typedef union {
51 UINT16 Command; /* when write */
52 UINT16 Status; /* when read */
54
55typedef union {
56 UINT16 Error; /* when read */
57 UINT16 Feature; /* when write */
59
60typedef union {
61 UINT16 AltStatus; /* when read */
62 UINT16 DeviceControl; /* when write */
64
65//
66// IDE registers set
67//
68typedef struct {
69 UINT16 Data;
71 UINT16 SectorCount;
72 UINT16 SectorNumber;
73 UINT16 CylinderLsb;
74 UINT16 CylinderMsb;
75 UINT16 Head;
77
79 UINT16 DriveAddress;
81
82typedef struct {
83 UINTN DevicePosition;
84 EFI_PEI_BLOCK_IO_MEDIA MediaInfo;
85 EFI_PEI_BLOCK_IO2_MEDIA MediaInfo2;
87
88#define ATAPI_BLK_IO_DEV_SIGNATURE SIGNATURE_32 ('a', 'b', 'i', 'o')
89typedef struct {
90 UINTN Signature;
91
94 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor;
95 EFI_PEI_PPI_DESCRIPTOR PpiDescriptor2;
96 PEI_ATA_CONTROLLER_PPI *AtaControllerPpi;
97
98 UINTN DeviceCount;
99 PEI_ATAPI_DEVICE_INFO DeviceInfo[MAX_IDE_DEVICES]; // for max 8 device
100 IDE_BASE_REGISTERS IdeIoPortReg[MAX_IDE_CHANNELS]; // for max 4 channel.
102
103#define PEI_RECOVERY_ATAPI_FROM_BLKIO_THIS(a) CR (a, ATAPI_BLK_IO_DEV, AtapiBlkIo, ATAPI_BLK_IO_DEV_SIGNATURE)
104#define PEI_RECOVERY_ATAPI_FROM_BLKIO2_THIS(a) CR (a, ATAPI_BLK_IO_DEV, AtapiBlkIo2, ATAPI_BLK_IO_DEV_SIGNATURE)
105
106#define STALL_1_MILLI_SECOND 1000 // stall 1 ms
107#define STALL_1_SECONDS 1000 * STALL_1_MILLI_SECOND
108
109//
110// Time Out Value For IDE Device Polling
111//
112// ATATIMEOUT is used for waiting time out for ATA device
113//
114#define ATATIMEOUT 1000 // 1 second
115// ATAPITIMEOUT is used for waiting operation
116// except read and write time out for ATAPI device
117//
118#define ATAPITIMEOUT 1000 // 1 second
119// ATAPILONGTIMEOUT is used for waiting read and
120// write operation timeout for ATAPI device
121//
122#define CDROMLONGTIMEOUT 2000 // 2 seconds
123#define ATAPILONGTIMEOUT 5000 // 5 seconds
124
125//
126// PEI Recovery Block I/O PPI
127//
128
149EFIAPI
151 IN EFI_PEI_SERVICES **PeiServices,
153 OUT UINTN *NumberBlockDevices
154 );
155
185EFIAPI
187 IN EFI_PEI_SERVICES **PeiServices,
189 IN UINTN DeviceIndex,
190 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo
191 );
192
228EFIAPI
230 IN EFI_PEI_SERVICES **PeiServices,
232 IN UINTN DeviceIndex,
233 IN EFI_PEI_LBA StartLBA,
234 IN UINTN BufferSize,
235 OUT VOID *Buffer
236 );
237
258EFIAPI
260 IN EFI_PEI_SERVICES **PeiServices,
262 OUT UINTN *NumberBlockDevices
263 );
264
294EFIAPI
296 IN EFI_PEI_SERVICES **PeiServices,
298 IN UINTN DeviceIndex,
300 );
301
337EFIAPI
339 IN EFI_PEI_SERVICES **PeiServices,
341 IN UINTN DeviceIndex,
342 IN EFI_PEI_LBA StartLBA,
343 IN UINTN BufferSize,
344 OUT VOID *Buffer
345 );
346
347//
348// Internal functions
349//
350
359VOID
361 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev
362 );
363
376BOOLEAN
378 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
379 IN UINTN DevicePosition,
380 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo,
381 OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2
382 );
383
394BOOLEAN
396 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
397 IN UINTN DevicePosition
398 );
399
413 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
414 IN IDE_BASE_REGISTERS *IdeIoRegisters,
415 IN UINTN TimeoutInMilliSeconds
416 );
417
430DRDYReady (
431 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
432 IN IDE_BASE_REGISTERS *IdeIoRegisters,
433 IN UINTN TimeoutInMilliSeconds
434 );
435
448DRQClear (
449 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
450 IN IDE_BASE_REGISTERS *IdeIoRegisters,
451 IN UINTN TimeoutInMilliSeconds
452 );
453
466DRQClear2 (
467 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
468 IN IDE_BASE_REGISTERS *IdeIoRegisters,
469 IN UINTN TimeoutInMilliSeconds
470 );
471
485DRQReady (
486 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
487 IN IDE_BASE_REGISTERS *IdeIoRegisters,
488 IN UINTN TimeoutInMilliSeconds
489 );
490
504DRQReady2 (
505 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
506 IN IDE_BASE_REGISTERS *IdeIoRegisters,
507 IN UINTN TimeoutInMilliSeconds
508 );
509
522 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
523 IN UINT16 StatusReg
524 );
525
538 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
539 IN UINTN DevicePosition
540 );
541
555 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
556 IN UINTN DevicePosition
557 );
558
575 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
576 IN UINTN DevicePosition,
577 IN ATAPI_PACKET_COMMAND *Packet,
578 IN UINT16 *Buffer,
579 IN UINT32 ByteCount,
580 IN UINTN TimeoutInMilliSeconds
581 );
582
598Inquiry (
599 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
600 IN UINTN DevicePosition,
601 OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo,
602 OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2
603 );
604
622 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
623 IN UINTN DevicePosition,
624 IN OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo,
625 IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2
626 );
627
641 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
642 IN UINTN DevicePosition,
643 IN BOOLEAN Extensive
644 );
645
660 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
661 IN UINTN DevicePosition,
662 IN ATAPI_REQUEST_SENSE_DATA *SenseBuffers,
663 IN OUT UINT8 *SenseCounts
664 );
665
682 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
683 IN UINTN DevicePosition,
684 IN OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo,
685 IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2
686 );
687
704 IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev,
705 IN UINTN DevicePosition,
706 IN VOID *Buffer,
707 IN EFI_PEI_LBA StartLba,
708 IN UINTN NumberOfBlocks,
709 IN UINTN BlockSize
710 );
711
722BOOLEAN
723IsNoMedia (
724 IN ATAPI_REQUEST_SENSE_DATA *SenseData,
725 IN UINTN SenseCounts
726 );
727
738BOOLEAN
740 IN ATAPI_REQUEST_SENSE_DATA *SenseData,
741 IN UINTN SenseCounts
742 );
743
754BOOLEAN
756 IN ATAPI_REQUEST_SENSE_DATA *SenseData,
757 IN UINTN SenseCounts
758 );
759
771BOOLEAN
773 IN ATAPI_REQUEST_SENSE_DATA *SenseData,
774 IN UINTN SenseCounts,
775 OUT BOOLEAN *NeedRetry
776 );
777
778#endif
UINT64 UINTN
EFI_STATUS EFIAPI AtapiReadBlocks(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
Definition: AtapiPeim.c:258
EFI_STATUS EFIAPI AtapiGetBlockDeviceMediaInfo(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo)
Definition: AtapiPeim.c:158
EFI_STATUS ReadCapacity(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo, IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2)
Definition: AtapiPeim.c:2076
EFI_STATUS DRDYReady(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
Definition: AtapiPeim.c:895
EFI_STATUS DRQReady(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
Definition: AtapiPeim.c:1066
EFI_STATUS TestUnitReady(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition)
Definition: AtapiPeim.c:1379
VOID AtapiEnumerateDevices(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev)
Definition: AtapiPeim.c:515
BOOLEAN DiscoverAtapiDevice(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2)
Definition: AtapiPeim.c:635
EFI_STATUS EFIAPI AtapiGetNumberOfBlockDevices2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, OUT UINTN *NumberBlockDevices)
Definition: AtapiPeim.c:351
EFI_STATUS AtapiPacketCommandIn(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN ATAPI_PACKET_COMMAND *Packet, IN UINT16 *Buffer, IN UINT32 ByteCount, IN UINTN TimeoutInMilliSeconds)
Definition: AtapiPeim.c:1415
EFI_STATUS DRQClear(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
Definition: AtapiPeim.c:951
EFI_STATUS ReadSectors(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN VOID *Buffer, IN EFI_PEI_LBA StartLba, IN UINTN NumberOfBlocks, IN UINTN BlockSize)
Definition: AtapiPeim.c:2182
BOOLEAN DetectIDEController(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition)
Definition: AtapiPeim.c:806
EFI_STATUS ATAPIIdentify(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition)
Definition: AtapiPeim.c:1211
EFI_STATUS RequestSense(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN ATAPI_REQUEST_SENSE_DATA *SenseBuffers, IN OUT UINT8 *SenseCounts)
Definition: AtapiPeim.c:1979
EFI_STATUS WaitForBSYClear(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
Definition: AtapiPeim.c:850
EFI_STATUS CheckErrorStatus(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINT16 StatusReg)
Definition: AtapiPeim.c:1184
EFI_STATUS DetectMedia(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo, IN OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2)
Definition: AtapiPeim.c:1720
BOOLEAN IsNoMedia(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts)
Definition: AtapiPeim.c:2280
BOOLEAN IsDriveReady(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts, OUT BOOLEAN *NeedRetry)
Definition: AtapiPeim.c:2428
EFI_STATUS DRQReady2(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
Definition: AtapiPeim.c:1128
BOOLEAN IsMediaError(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts)
Definition: AtapiPeim.c:2355
BOOLEAN IsDeviceStateUnclear(IN ATAPI_REQUEST_SENSE_DATA *SenseData, IN UINTN SenseCounts)
Definition: AtapiPeim.c:2315
EFI_STATUS EFIAPI AtapiReadBlocks2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, IN EFI_PEI_LBA StartLBA, IN UINTN BufferSize, OUT VOID *Buffer)
Definition: AtapiPeim.c:474
EFI_STATUS EFIAPI AtapiGetBlockDeviceMediaInfo2(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO2_PPI *This, IN UINTN DeviceIndex, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo)
Definition: AtapiPeim.c:401
EFI_STATUS ResetDevice(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, IN BOOLEAN Extensive)
Definition: AtapiPeim.c:1882
EFI_STATUS DRQClear2(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN IDE_BASE_REGISTERS *IdeIoRegisters, IN UINTN TimeoutInMilliSeconds)
Definition: AtapiPeim.c:1008
EFI_STATUS Inquiry(IN ATAPI_BLK_IO_DEV *AtapiBlkIoDev, IN UINTN DevicePosition, OUT EFI_PEI_BLOCK_IO_MEDIA *MediaInfo, OUT EFI_PEI_BLOCK_IO2_MEDIA *MediaInfo2)
Definition: AtapiPeim.c:1623
EFI_STATUS EFIAPI AtapiGetNumberOfBlockDevices(IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_RECOVERY_BLOCK_IO_PPI *This, OUT UINTN *NumberBlockDevices)
Definition: AtapiPeim.c:111
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT64 EFI_PEI_LBA
Definition: BlockIo.h:41
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29