17#pragma warning(disable:4214)
18#pragma warning(disable:4201)
21#define MAXIMUM_AHCI_PORT_COUNT 32
22#define MAXIMUM_AHCI_PRDT_ENTRIES 32
23#define MAXIMUM_AHCI_PORT_NCS 30
24#define MAXIMUM_QUEUE_BUFFER_SIZE 255
25#define MAXIMUM_TRANSFER_LENGTH (128*1024)
27#define DEVICE_ATA_BLOCK_SIZE 512
30#define AHCI_DEVICE_TYPE_ATA 1
31#define AHCI_DEVICE_TYPE_ATAPI 2
32#define AHCI_DEVICE_TYPE_NODEVICE 3
35#define AHCI_Global_HBA_CAP_S64A (1 << 31)
38#define FIS_TYPE_REG_H2D 0x27
39#define FIS_TYPE_REG_D2H 0x34
40#define FIS_TYPE_DMA_ACT 0x39
41#define FIS_TYPE_DMA_SETUP 0x41
42#define FIS_TYPE_BIST 0x58
43#define FIS_TYPE_PIO_SETUP 0x5F
44#define FIS_TYPE_DEV_BITS 0xA1
46#define AHCI_ATA_CFIS_FisType 0
47#define AHCI_ATA_CFIS_PMPort_C 1
48#define AHCI_ATA_CFIS_CommandReg 2
49#define AHCI_ATA_CFIS_FeaturesLow 3
50#define AHCI_ATA_CFIS_LBA0 4
51#define AHCI_ATA_CFIS_LBA1 5
52#define AHCI_ATA_CFIS_LBA2 6
53#define AHCI_ATA_CFIS_Device 7
54#define AHCI_ATA_CFIS_LBA3 8
55#define AHCI_ATA_CFIS_LBA4 9
56#define AHCI_ATA_CFIS_LBA5 10
57#define AHCI_ATA_CFIS_FeaturesHigh 11
58#define AHCI_ATA_CFIS_SectorCountLow 12
59#define AHCI_ATA_CFIS_SectorCountHigh 13
62#define ATA_FUNCTION_ATA_COMMAND 0x100
63#define ATA_FUNCTION_ATA_IDENTIFY 0x101
64#define ATA_FUNCTION_ATA_READ 0x102
67#define ATA_FUNCTION_ATAPI_COMMAND 0x200
70#define ATA_FLAGS_DATA_IN (1 << 1)
71#define ATA_FLAGS_DATA_OUT (1 << 2)
72#define ATA_FLAGS_48BIT_COMMAND (1 << 3)
73#define ATA_FLAGS_USE_DMA (1 << 4)
75#define IsAtaCommand(AtaFunction) (AtaFunction & ATA_FUNCTION_ATA_COMMAND)
76#define IsAtapiCommand(AtaFunction) (AtaFunction & ATA_FUNCTION_ATAPI_COMMAND)
77#define IsDataTransferNeeded(SrbExtension) (SrbExtension->Flags & (ATA_FLAGS_DATA_IN | ATA_FLAGS_DATA_OUT))
78#define IsAdapterCAPS64(CAP) (CAP & AHCI_Global_HBA_CAP_S64A)
81#define AHCI_Global_Port_CAP_NCS(x) (((x) & 0xF00) >> 8)
83#define ROUND_UP(N, S) ((((N) + (S) - 1) / (S)) * (S))
85#define AhciDebugPrint(format, ...) DbgPrint("(%s:%d) " format, __RELFILE__, __LINE__, ##__VA_ARGS__)
_In_ PSCSI_REQUEST_BLOCK Srb
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR PathId
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
enum _STOR_DEVICE_POWER_STATE STOR_DEVICE_POWER_STATE
UCHAR DeviceReportLuns(__in PAHCI_ADAPTER_EXTENSION AdapterExtension, __in PSCSI_REQUEST_BLOCK Srb, __in PCDB Cdb)
union _AHCI_INTERRUPT_STATUS AHCI_INTERRUPT_STATUS
BOOLEAN AhciAdapterReset(__in PAHCI_ADAPTER_EXTENSION AdapterExtension)
union _AHCI_COMMAND_HEADER_DESCRIPTION AHCI_COMMAND_HEADER_DESCRIPTION
UCHAR DeviceInquiryRequest(__in PAHCI_ADAPTER_EXTENSION AdapterExtension, __in PSCSI_REQUEST_BLOCK Srb, __in PCDB Cdb)
struct _AHCI_FIS_DMA_SETUP AHCI_FIS_DMA_SETUP
struct _AHCI_COMMAND_TABLE * PAHCI_COMMAND_TABLE
struct _AHCI_PRDT AHCI_PRDT
struct _AHCI_PORT * PAHCI_PORT
#define MAXIMUM_AHCI_PORT_COUNT
union _AHCI_PORT_CMD AHCI_PORT_CMD
struct _AHCI_COMMAND_TABLE AHCI_COMMAND_TABLE
struct _AHCI_PORT_EXTENSION * PAHCI_PORT_EXTENSION
FORCEINLINE BOOLEAN AddQueue(__inout PAHCI_QUEUE Queue, __in PVOID Srb)
struct _AHCI_QUEUE * PAHCI_QUEUE
struct _AHCI_MEMORY_REGISTERS AHCI_MEMORY_REGISTERS
FORCEINLINE ULONG64 AhciGetLba(__in PCDB Cdb, __in ULONG CdbLength)
struct _AHCI_PORT_EXTENSION AHCI_PORT_EXTENSION
union _AHCI_INTERRUPT_ENABLE AHCI_INTERRUPT_ENABLE
UCHAR DeviceRequestSense(__in PAHCI_ADAPTER_EXTENSION AdapterExtension, __in PSCSI_REQUEST_BLOCK Srb, __in PCDB Cdb)
struct _AHCI_D2H_REGISTER_FIS AHCI_D2H_REGISTER_FIS
union _AHCI_TASK_FILE_DATA AHCI_TASK_FILE_DATA
struct _AHCI_PIO_SETUP_FIS AHCI_PIO_SETUP_FIS
FORCEINLINE BOOLEAN IsPortValid(__in PAHCI_ADAPTER_EXTENSION AdapterExtension, __in ULONG pathId)
UCHAR DeviceRequestReadWrite(__in PAHCI_ADAPTER_EXTENSION AdapterExtension, __in PSCSI_REQUEST_BLOCK Srb, __in PCDB Cdb)
struct _AHCI_RECEIVED_FIS AHCI_RECEIVED_FIS
struct _AHCI_COMMAND_HEADER * PAHCI_COMMAND_HEADER
struct _AHCI_PORT AHCI_PORT
struct _LOCAL_SCATTER_GATHER_LIST LOCAL_SCATTER_GATHER_LIST
FORCEINLINE PVOID RemoveQueue(__inout PAHCI_QUEUE Queue)
#define MAXIMUM_AHCI_PORT_NCS
union _AHCI_SERIAL_ATA_STATUS AHCI_SERIAL_ATA_STATUS
union _AHCI_SERIAL_ATA_CONTROL AHCI_SERIAL_ATA_CONTROL
struct _AHCI_RECEIVED_FIS * PAHCI_RECEIVED_FIS
struct _AHCI_SRB_EXTENSION AHCI_SRB_EXTENSION
struct _AHCI_QUEUE AHCI_QUEUE
struct _AHCI_SRB_EXTENSION * PAHCI_SRB_EXTENSION
VOID(* PAHCI_COMPLETION_ROUTINE)(__in PVOID PortExtension, __in PVOID Srb)
FORCEINLINE VOID AhciZeroMemory(__out PCHAR Buffer, __in ULONG BufferSize)
struct _LOCAL_SCATTER_GATHER_LIST * PLOCAL_SCATTER_GATHER_LIST
struct _AHCI_ADAPTER_EXTENSION AHCI_ADAPTER_EXTENSION
struct _AHCI_MEMORY_REGISTERS * PAHCI_MEMORY_REGISTERS
FORCEINLINE PAHCI_SRB_EXTENSION GetSrbExtension(__in PSCSI_REQUEST_BLOCK Srb)
struct _AHCI_ADAPTER_EXTENSION * PAHCI_ADAPTER_EXTENSION
VOID AhciProcessIO(__in PAHCI_ADAPTER_EXTENSION AdapterExtension, __in UCHAR PathId, __in PSCSI_REQUEST_BLOCK Srb)
UCHAR DeviceRequestCapacity(__in PAHCI_ADAPTER_EXTENSION AdapterExtension, __in PSCSI_REQUEST_BLOCK Srb, __in PCDB Cdb)
struct _AHCI_PRDT * PAHCI_PRDT
struct _AHCI_COMMAND_HEADER AHCI_COMMAND_HEADER
struct _AHCI_SET_DEVICE_BITS_FIS AHCI_SET_DEVICE_BITS_FIS
#define MAXIMUM_QUEUE_BUFFER_SIZE
#define MAXIMUM_AHCI_PRDT_ENTRIES
struct _AHCI_ADAPTER_EXTENSION::@1356 StateFlags
PAHCI_MEMORY_REGISTERS ABAR_Address
AHCI_PORT_EXTENSION PortExtension[MAXIMUM_AHCI_PORT_COUNT]
AHCI_COMMAND_HEADER_DESCRIPTION DI
AHCI_PRDT PRDT[MAXIMUM_AHCI_PRDT_ENTRIES]
AHCI_PORT PortList[MAXIMUM_AHCI_PORT_COUNT]
ULONG VendorSpecific[0x18]
ULONG BytesPerPhysicalSector
struct _AHCI_ADAPTER_EXTENSION * AdapterExtension
PIDENTIFY_DEVICE_DATA IdentifyDeviceData
AHCI_QUEUE CompletionQueue
STOR_PHYSICAL_ADDRESS IdentifyDeviceDataPhysicalAddress
struct _AHCI_PORT_EXTENSION::@1355 DeviceParams
STOR_DEVICE_POWER_STATE DevicePowerState
PAHCI_RECEIVED_FIS ReceivedFIS
PSCSI_REQUEST_BLOCK Slot[MAXIMUM_AHCI_PORT_NCS]
PAHCI_COMMAND_HEADER CommandList
ULONG BytesPerLogicalSector
STOR_DPC CommandCompletion
struct _AHCI_PIO_SETUP_FIS PioSetupFIS
struct _AHCI_SET_DEVICE_BITS_FIS SetDeviceFIS
struct _AHCI_FIS_DMA_SETUP DmaSetupFIS
struct _AHCI_D2H_REGISTER_FIS RegisterFIS
PAHCI_COMPLETION_ROUTINE CompletionRoutine
PLOCAL_SCATTER_GATHER_LIST pSgl
AHCI_COMMAND_TABLE CommandTable
LOCAL_SCATTER_GATHER_LIST Sgl
#define FIELD_OFFSET(t, f)
struct _AHCI_TASK_FILE_DATA::@1351::_STS STS
_Must_inspect_result_ _In_ WDFDEVICE _In_ PIRP _In_ WDFQUEUE Queue
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
_Must_inspect_result_ _In_ WDFCMRESLIST List
_Reserved_ PVOID Reserved