TianoCore EDK2 master
Loading...
Searching...
No Matches
AtaBus.h
Go to the documentation of this file.
1
12#ifndef _ATA_BUS_H_
13#define _ATA_BUS_H_
14
15#include <Uefi.h>
16
18#include <Protocol/BlockIo.h>
19#include <Protocol/BlockIo2.h>
20#include <Protocol/DiskInfo.h>
21#include <Protocol/DevicePath.h>
23
24#include <Library/DebugLib.h>
26#include <Library/BaseLib.h>
27#include <Library/UefiLib.h>
33#include <Library/TimerLib.h>
35
37
38//
39// Time out value for ATA pass through protocol
40//
41#define ATA_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)
42
43//
44// Maximum number of times to retry ATA command
45//
46#define MAX_RETRY_TIMES 3
47
48//
49// The maximum total sectors count in 28 bit addressing mode
50//
51#define MAX_28BIT_ADDRESSING_CAPACITY 0xfffffff
52
53//
54// The maximum ATA transaction sector count in 28 bit addressing mode.
55//
56#define MAX_28BIT_TRANSFER_BLOCK_NUM 0x100
57
58//
59// The maximum ATA transaction sector count in 48 bit addressing mode.
60//
61// #define MAX_48BIT_TRANSFER_BLOCK_NUM 0x10000
62
63//
64// BugBug: if the TransferLength is equal with 0x10000 (the 48bit max length),
65// there is a bug that even the register interrupt bit has been sit, the buffer
66// seems not ready. Change the Maximum Sector Numbers to 0xFFFF to work round
67// this issue.
68//
69#define MAX_48BIT_TRANSFER_BLOCK_NUM 0xFFFF
70
71//
72// The maximum model name in ATA identify data
73//
74#define MAX_MODEL_NAME_LEN 40
75
76#define ATA_TASK_SIGNATURE SIGNATURE_32 ('A', 'T', 'S', 'K')
77#define ATA_DEVICE_SIGNATURE SIGNATURE_32 ('A', 'B', 'I', 'D')
78#define ATA_SUB_TASK_SIGNATURE SIGNATURE_32 ('A', 'S', 'T', 'S')
79
80//
81// ATA bus data structure for ATA controller
82//
83typedef struct {
84 EFI_ATA_PASS_THRU_PROTOCOL *AtaPassThru;
85 EFI_HANDLE Controller;
86 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
87 EFI_HANDLE DriverBindingHandle;
89
90//
91// ATA device data structure for each child device
92//
93typedef struct {
94 UINT32 Signature;
95
96 EFI_HANDLE Handle;
99 EFI_BLOCK_IO_MEDIA BlockMedia;
100 EFI_DISK_INFO_PROTOCOL DiskInfo;
101 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
103
104 ATA_BUS_DRIVER_DATA *AtaBusDriverData;
105 UINT16 Port;
106 UINT16 PortMultiplierPort;
107
108 //
109 // Buffer for the execution of ATA pass through protocol
110 //
114
115 BOOLEAN UdmaValid;
116 BOOLEAN Lba48Bit;
117
118 //
119 // Cached data for ATA identify data
120 //
121 ATA_IDENTIFY_DATA *IdentifyData;
122
123 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
124 CHAR16 ModelName[MAX_MODEL_NAME_LEN + 1];
125
126 LIST_ENTRY AtaTaskList;
127 LIST_ENTRY AtaSubTaskList;
128 BOOLEAN Abort;
129} ATA_DEVICE;
130
131//
132// Sub-Task for the non blocking I/O
133//
134typedef struct {
135 UINT32 Signature;
136 ATA_DEVICE *AtaDevice;
137 EFI_BLOCK_IO2_TOKEN *Token;
138 UINTN *UnsignalledEventCount;
140 BOOLEAN *IsError;// Indicate whether meeting error during source allocation for new task.
141 LIST_ENTRY TaskEntry;
143
144//
145// Task for the non blocking I/O
146//
147typedef struct {
148 UINT32 Signature;
149 EFI_BLOCK_IO2_TOKEN *Token;
150 ATA_DEVICE *AtaDevice;
151 UINT8 *Buffer;
152 EFI_LBA StartLba;
153 UINTN NumberOfBlocks;
154 BOOLEAN IsWrite;
155 LIST_ENTRY TaskEntry;
157
158#define ATA_DEVICE_FROM_BLOCK_IO(a) CR (a, ATA_DEVICE, BlockIo, ATA_DEVICE_SIGNATURE)
159#define ATA_DEVICE_FROM_BLOCK_IO2(a) CR (a, ATA_DEVICE, BlockIo2, ATA_DEVICE_SIGNATURE)
160#define ATA_DEVICE_FROM_DISK_INFO(a) CR (a, ATA_DEVICE, DiskInfo, ATA_DEVICE_SIGNATURE)
161#define ATA_DEVICE_FROM_STORAGE_SECURITY(a) CR (a, ATA_DEVICE, StorageSecurity, ATA_DEVICE_SIGNATURE)
162#define ATA_ASYN_SUB_TASK_FROM_ENTRY(a) CR (a, ATA_BUS_ASYN_SUB_TASK, TaskEntry, ATA_SUB_TASK_SIGNATURE)
163#define ATA_ASYN_TASK_FROM_ENTRY(a) CR (a, ATA_BUS_ASYN_TASK, TaskEntry, ATA_TASK_SIGNATURE)
164
165//
166// Global Variables
167//
168extern EFI_DRIVER_BINDING_PROTOCOL gAtaBusDriverBinding;
169extern EFI_COMPONENT_NAME_PROTOCOL gAtaBusComponentName;
170extern EFI_COMPONENT_NAME2_PROTOCOL gAtaBusComponentName2;
171
185VOID *
187 IN ATA_DEVICE *AtaDevice,
188 IN UINTN BufferSize
189 );
190
201VOID
203 IN VOID *Buffer,
204 IN UINTN BufferSize
205 );
206
213VOID
214EFIAPI
217 );
218
232 IN ATA_DEVICE *AtaDevice
233 );
234
251 IN OUT ATA_DEVICE *AtaDevice
252 );
253
274 IN OUT ATA_DEVICE *AtaDevice,
275 IN OUT UINT8 *Buffer,
276 IN EFI_LBA StartLba,
277 IN UINTN NumberOfBlocks,
278 IN BOOLEAN IsWrite,
280 );
281
312EFIAPI
314 IN OUT ATA_DEVICE *AtaDevice,
315 IN OUT VOID *Buffer,
316 IN UINT8 SecurityProtocolId,
317 IN UINT16 SecurityProtocolSpecificData,
318 IN UINTN TransferLength,
319 IN BOOLEAN IsTrustSend,
320 IN UINT64 Timeout,
321 OUT UINTN *TransferLengthOut
322 );
323
324//
325// Protocol interface prototypes
326//
327
371EFIAPI
374 IN EFI_HANDLE Controller,
375 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
376 );
377
414EFIAPI
417 IN EFI_HANDLE Controller,
418 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
419 );
420
448EFIAPI
451 IN EFI_HANDLE Controller,
452 IN UINTN NumberOfChildren,
453 IN EFI_HANDLE *ChildHandleBuffer
454 );
455
496EFIAPI
499 IN CHAR8 *Language,
500 OUT CHAR16 **DriverName
501 );
502
572EFIAPI
575 IN EFI_HANDLE ControllerHandle,
576 IN EFI_HANDLE ChildHandle OPTIONAL,
577 IN CHAR8 *Language,
578 OUT CHAR16 **ControllerName
579 );
580
593EFIAPI
596 IN BOOLEAN ExtendedVerification
597 );
598
619EFIAPI
622 IN UINT32 MediaId,
623 IN EFI_LBA Lba,
624 IN UINTN BufferSize,
625 OUT VOID *Buffer
626 );
627
649EFIAPI
652 IN UINT32 MediaId,
653 IN EFI_LBA Lba,
654 IN UINTN BufferSize,
655 IN VOID *Buffer
656 );
657
669EFIAPI
672 );
673
686EFIAPI
689 IN BOOLEAN ExtendedVerification
690 );
691
719EFIAPI
722 IN UINT32 MediaId,
723 IN EFI_LBA Lba,
725 IN UINTN BufferSize,
726 OUT VOID *Buffer
727 );
728
752EFIAPI
755 IN UINT32 MediaId,
756 IN EFI_LBA Lba,
758 IN UINTN BufferSize,
759 IN VOID *Buffer
760 );
761
774EFIAPI
778 );
779
790VOID
791EFIAPI
793 IN ATA_DEVICE *AtaDevice
794 );
795
813EFIAPI
816 IN OUT VOID *InquiryData,
817 IN OUT UINT32 *InquiryDataSize
818 );
819
839EFIAPI
842 IN OUT VOID *IdentifyData,
843 IN OUT UINT32 *IdentifyDataSize
844 );
845
864EFIAPI
867 IN OUT VOID *SenseData,
868 IN OUT UINT32 *SenseDataSize,
869 OUT UINT8 *SenseDataNumber
870 );
871
884EFIAPI
887 OUT UINT32 *IdeChannel,
888 OUT UINT32 *IdeDevice
889 );
890
966EFIAPI
969 IN UINT32 MediaId,
970 IN UINT64 Timeout,
971 IN UINT8 SecurityProtocolId,
972 IN UINT16 SecurityProtocolSpecificData,
973 IN UINTN PayloadBufferSize,
974 OUT VOID *PayloadBuffer,
975 OUT UINTN *PayloadTransferSize
976 );
977
1042EFIAPI
1045 IN UINT32 MediaId,
1046 IN UINT64 Timeout,
1047 IN UINT8 SecurityProtocolId,
1048 IN UINT16 SecurityProtocolSpecificData,
1049 IN UINTN PayloadBufferSize,
1050 IN VOID *PayloadBuffer
1051 );
1052
1064VOID
1066 IN ATA_DEVICE *AtaDevice
1067 );
1068
1069#endif
UINT64 UINTN
EFI_STATUS ResetAtaDevice(IN ATA_DEVICE *AtaDevice)
EFI_STATUS EFIAPI AtaBlockIoResetEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: AtaBus.c:1191
EFI_STATUS EFIAPI AtaDiskInfoSenseData(IN EFI_DISK_INFO_PROTOCOL *This, IN OUT VOID *SenseData, IN OUT UINT32 *SenseDataSize, OUT UINT8 *SenseDataNumber)
Definition: AtaBus.c:1409
EFI_STATUS DiscoverAtaDevice(IN OUT ATA_DEVICE *AtaDevice)
EFI_STATUS EFIAPI AtaStorageSecurityReceiveData(IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, OUT VOID *PayloadBuffer, OUT UINTN *PayloadTransferSize)
Definition: AtaBus.c:1523
VOID EFIAPI FreeAtaSubTask(IN OUT ATA_BUS_ASYN_SUB_TASK *Task)
VOID EFIAPI AtaTerminateNonBlockingTask(IN ATA_DEVICE *AtaDevice)
VOID FreeAlignedBuffer(IN VOID *Buffer, IN UINTN BufferSize)
Definition: AtaBus.c:124
EFI_STATUS EFIAPI AtaBusComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName)
Definition: ComponentName.c:86
EFI_STATUS EFIAPI AtaBusDriverBindingStart(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: AtaBus.c:715
EFI_STATUS EFIAPI AtaBlockIoWriteBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, IN VOID *Buffer)
Definition: AtaBus.c:1280
EFI_STATUS EFIAPI AtaBlockIoFlushBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
Definition: AtaBus.c:1305
EFI_STATUS EFIAPI AtaBlockIoWriteBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, IN VOID *Buffer)
Definition: AtaBus.c:1145
EFI_STATUS EFIAPI AtaBlockIoReset(IN EFI_BLOCK_IO_PROTOCOL *This, IN BOOLEAN ExtendedVerification)
Definition: AtaBus.c:967
EFI_STATUS EFIAPI AtaDiskInfoInquiry(IN EFI_DISK_INFO_PROTOCOL *This, IN OUT VOID *InquiryData, IN OUT UINT32 *InquiryDataSize)
Definition: AtaBus.c:1339
EFI_STATUS EFIAPI AtaBusDriverBindingStop(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer)
Definition: AtaBus.c:897
EFI_STATUS EFIAPI AtaBusDriverBindingSupported(IN EFI_DRIVER_BINDING_PROTOCOL *This, IN EFI_HANDLE Controller, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath)
Definition: AtaBus.c:587
EFI_STATUS EFIAPI AtaBusComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName)
EFI_STATUS EFIAPI TrustTransferAtaDevice(IN OUT ATA_DEVICE *AtaDevice, IN OUT VOID *Buffer, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN TransferLength, IN BOOLEAN IsTrustSend, IN UINT64 Timeout, OUT UINTN *TransferLengthOut)
EFI_STATUS EFIAPI AtaBlockIoReadBlocksEx(IN EFI_BLOCK_IO2_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN OUT EFI_BLOCK_IO2_TOKEN *Token, IN UINTN BufferSize, OUT VOID *Buffer)
Definition: AtaBus.c:1244
EFI_STATUS EFIAPI AtaDiskInfoWhichIde(IN EFI_DISK_INFO_PROTOCOL *This, OUT UINT32 *IdeChannel, OUT UINT32 *IdeDevice)
Definition: AtaBus.c:1432
VOID * AllocateAlignedBuffer(IN ATA_DEVICE *AtaDevice, IN UINTN BufferSize)
Definition: AtaBus.c:105
EFI_STATUS EFIAPI AtaStorageSecuritySendData(IN EFI_STORAGE_SECURITY_COMMAND_PROTOCOL *This, IN UINT32 MediaId, IN UINT64 Timeout, IN UINT8 SecurityProtocolId, IN UINT16 SecurityProtocolSpecificData, IN UINTN PayloadBufferSize, IN VOID *PayloadBuffer)
Definition: AtaBus.c:1636
EFI_STATUS AccessAtaDevice(IN OUT ATA_DEVICE *AtaDevice, IN OUT UINT8 *Buffer, IN EFI_LBA StartLba, IN UINTN NumberOfBlocks, IN BOOLEAN IsWrite, IN OUT EFI_BLOCK_IO2_TOKEN *Token)
EFI_STATUS EFIAPI AtaBlockIoReadBlocks(IN EFI_BLOCK_IO_PROTOCOL *This, IN UINT32 MediaId, IN EFI_LBA Lba, IN UINTN BufferSize, OUT VOID *Buffer)
Definition: AtaBus.c:1112
VOID InitiateTPerReset(IN ATA_DEVICE *AtaDevice)
EFI_STATUS EFIAPI AtaDiskInfoIdentify(IN EFI_DISK_INFO_PROTOCOL *This, IN OUT VOID *IdentifyData, IN OUT UINT32 *IdentifyDataSize)
Definition: AtaBus.c:1368
EFI_STATUS EFIAPI AtaBlockIoFlushBlocks(IN EFI_BLOCK_IO_PROTOCOL *This)
Definition: AtaBus.c:1168
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT64 EFI_LBA
Definition: UefiBaseType.h:45
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33