ReactOS 0.4.17-dev-116-ga4b6fe9
atapi.h File Reference
#include <ntddk.h>
#include <ntstrsafe.h>
#include <ntintsafe.h>
#include <wmilib.h>
#include <initguid.h>
#include <wdmguid.h>
#include <wmistr.h>
#include <wmidata.h>
#include <ata.h>
#include <ide.h>
#include <scsi.h>
#include <ntddscsi.h>
#include <ntdddisk.h>
#include <sptilib.h>
#include <section_attribs.h>
#include <debug/driverdbg.h>
#include <reactos/drivers/ata/ata_shared.h>
#include <reactos/drivers/ata/ata_user.h>
#include <reactos/drivers/ata/identify_funcs.h>
#include "debug.h"
#include "scsiex.h"
Include dependency graph for atapi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

union  _ATA_SCSI_ADDRESS
 
struct  _ATAPORT_IO_CONTEXT
 
struct  _ATA_WORKER_CONTEXT
 
struct  _ATA_WORKER_DEVICE_CONTEXT
 
struct  _REQUEST_QUEUE_ENTRY
 
struct  _ATAPORT_PORT_DATA
 
struct  _ATAPORT_COMMON_EXTENSION
 
struct  _ATAPORT_CHANNEL_EXTENSION
 
struct  _ATAPORT_DEVICE_EXTENSION
 

Macros

#define DEVICE_PIO_ONLY   0x00000001
 
#define DEVICE_LBA_MODE   0x00000002
 
#define DEVICE_LBA48   0x00000004
 
#define DEVICE_HAS_FUA   0x00000008
 
#define DEVICE_NCQ   0x00000010
 
#define DEVICE_HAS_MEDIA_STATUS   0x00000020
 
#define DEVICE_SENSE_DATA_REPORTING   0x00000040
 
#define DEVICE_IS_SUPER_FLOPPY   0x00000080
 
#define DEVICE_IS_PDO_REMOVABLE   0x00000100
 
#define DEVICE_UNINITIALIZED   0x00000200
 
#define DEVICE_PNP_STARTED   0x00000400
 
#define DEVICE_DESCRIPTOR_SENSE   0x00000800
 
#define DEVICE_PIO_VIA_DMA   0x00001000
 
#define DEVICE_PIO_FOR_LBA48_XFER   0x00002000
 
#define DEVICE_CACHE_INQUIRY   0x00004000
 
#define QUEUE_FLAG_FROZEN_PORT_BUSY   0x00000001
 
#define QUEUE_FLAG_FROZEN_SLOT   0x00000002
 
#define QUEUE_FLAG_FROZEN_PNP   0x00000004
 
#define QUEUE_FLAG_SIGNAL_STOP   0x00000008
 
#define QUEUE_FLAG_FROZEN_QUEUE_FREEZE   0x00000010
 
#define QUEUE_FLAG_FROZEN_POWER   0x00000020
 
#define QUEUE_FLAG_FROZEN_REMOVED   0x00000040
 
#define QUEUE_FLAG_FROZEN_QUEUE_LOCK   0x00080000
 
#define QUEUE_FLAGS_FROZEN
 
#define QUEUE_FLAGS_FROZEN_NOT_BYPASS    (QUEUE_FLAGS_FROZEN & ~(QUEUE_FLAG_FROZEN_QUEUE_FREEZE | QUEUE_FLAG_FROZEN_QUEUE_LOCK))
 
#define ATAPORT_PAGED_DATA   DATA_SEG("PAGECONS")
 
#define DECLARE_PAGED_UNICODE_STRING(Variable, Str)
 
#define DECLARE_PAGED_STRING(v, n)    static const ATAPORT_PAGED_DATA CHAR (v)[] = (n)
 
#define DECLARE_PAGED_WSTRING(v, n)    static const ATAPORT_PAGED_DATA WCHAR (v)[] = (n)
 
#define ASSUME(cond)
 
#define ATAPORT_TAG   'PedI'
 
#define IS_FDO(p)    ((((PATAPORT_COMMON_EXTENSION)(p))->Flags & DO_IS_FDO) != 0)
 
#define IS_ATAPI(Device)    (((Device)->TransportFlags & DEVICE_IS_ATAPI) != 0)
 
#define NUM_TO_BITMAP(num)   (0xFFFFFFFF >> (RTL_BITS_OF(ULONG) - (num)))
 
#define ATAPORT_FN_FIELD   40
 The maximum length of identifier strings for ATA devices excluding the terminating NULL.
 
#define ATAPORT_SN_FIELD   40
 
#define ATAPORT_RN_FIELD   8
 
#define ATA_RESERVED_PAGES   4
 
#define ATA_MAX_LUN_COUNT   8
 
#define ATA_LOCAL_BUFFER_SIZE   572
 
#define MAX_SLOTS   32
 
#define ATA_MAX_LBA_28   0x0FFFFFFFULL
 
#define ATA_MAX_LBA_48   (1ULL << 48)
 
#define IDE_DRIVE_SELECT_SLAVE   0x10
 
#define IDE_HIGH_ORDER_BYTE   0x80
 
#define IDE_DRIVE_SELECT   0xA0
 
#define IDE_ERROR_WRITE_PROTECT   0x40
 
#define IDE_FEATURE_PIO   0x00
 
#define IDE_FEATURE_DMA   0x01
 
#define IDE_FEATURE_DMADIR   0x04
 
#define IDE_DEVICE_FUA_NCQ   0x80
 
#define IDE_DC_ALWAYS   0x08
 
#define IDE_COMMAND_REQUEST_SENSE_DATA_EXT   0x0B
 
#define SRB_FLAG_RETRY_COUNT_MASK   0x000000FF
 
#define SRB_FLAG_LOW_MEM_RETRY   0x00000100
 
#define SRB_FLAG_PIO_RETRY   0x00000200
 
#define SRB_SET_FLAGS(Srb, Flags)    ((Srb)->SrbExtension = (PVOID)((ULONG_PTR)(Srb)->SrbExtension | (Flags)))
 
#define SRB_CLEAR_FLAGS(Srb, Flags)    ((Srb)->SrbExtension = (PVOID)((ULONG_PTR)(Srb)->SrbExtension & ~(Flags)))
 
#define SRB_GET_FLAGS(Srb)   ((ULONG_PTR)(Srb)->SrbExtension)
 
#define WORKER_FLAG_NEED_RESCAN   0x00000001
 
#define WORKER_FLAG_COMPLETE_PORT_ENUM_EVENT   0x00000002
 
#define DEV_WORKER_FLAG_HOLD_REFERENCE   0x00000001
 
#define DEV_WORKER_FLAG_REMOVED   0x00000002
 
#define QUEUE_ENTRY_FROM_IRP(Irp)    ((PREQUEST_QUEUE_ENTRY)&(((PIRP)(Irp))->Tail.Overlay.DriverContext[0]))
 
#define IRP_FROM_QUEUE_ENTRY(QueueEntry)    (PIRP)CONTAINING_RECORD(QueueEntry, IRP, Tail.Overlay.DriverContext[0])
 
#define ASSERT_REQUEST(Request)    ASSERT((Request) && (Request)->Signature == ATA_DEVICE_REQUEST_SIGNATURE)
 
#define PORT_FLAG_IS_SIMPLEX   0x00000001
 
#define PORT_FLAG_PIO_VIA_DMA   0x00000002
 
#define PORT_FLAG_IS_EXTERNAL   0x00000004
 
#define PORT_FLAG_NCQ   0x00000008
 
#define PORT_FLAG_IS_AHCI   0x00000010
 
#define PORT_FLAG_SYMLINK_CREATED   0x00000020
 
#define PORT_FLAG_IO_TIMER_ACTIVE   0x00000040
 
#define PORT_FLAG_CHANNEL_ATTACHED   0x00000080
 
#define PORT_FLAG_PIO_ONLY   0x00000100
 
#define PORT_FLAG_PIO_FOR_LBA48_XFER   0x00000200
 
#define PORT_FLAG_EXIT_THREAD   0x80000000
 
#define PORT_INT_FLAG_IS_IO_ACTIVE   0x00000001
 
#define PORT_INT_FLAG_IGNORE_LINK_IRQ   0x00000002
 
#define PORT_QUEUE_FLAG_EXCLUSIVE_MODE   0x00000001
 
#define PORT_QUEUE_FLAG_SIGNAL_STOP   0x00000002
 
#define DO_IS_FDO   0x80000000
 

Typedefs

typedef struct _ATAPORT_CHANNEL_EXTENSION ATAPORT_CHANNEL_EXTENSION
 
typedef struct _ATAPORT_CHANNEL_EXTENSIONPATAPORT_CHANNEL_EXTENSION
 
typedef struct _ATAPORT_DEVICE_EXTENSION ATAPORT_DEVICE_EXTENSION
 
typedef struct _ATAPORT_DEVICE_EXTENSIONPATAPORT_DEVICE_EXTENSION
 
typedef struct _ATAPORT_PORT_DATA ATAPORT_PORT_DATA
 
typedef struct _ATAPORT_PORT_DATAPATAPORT_PORT_DATA
 
typedef struct _ATAPORT_IO_CONTEXT ATAPORT_IO_CONTEXT
 
typedef struct _ATAPORT_IO_CONTEXTPATAPORT_IO_CONTEXT
 
typedef union _ATA_SCSI_ADDRESS ATA_SCSI_ADDRESS
 
typedef union _ATA_SCSI_ADDRESSPATA_SCSI_ADDRESS
 
typedef VOID() STOP_IO_CALLBACK(_In_ PATAPORT_IO_CONTEXT Device)
 
typedef STOP_IO_CALLBACKPSTOP_IO_CALLBACK
 
typedef enum _ATA_PORT_ACTION ATA_PORT_ACTION
 
typedef enum _ATA_DEVICE_STATUS ATA_DEVICE_STATUS
 
typedef enum _ATA_ERROR_LOG_VALUE ATA_ERROR_LOG_VALUE
 
typedef struct _ATA_WORKER_CONTEXT ATA_WORKER_CONTEXT
 
typedef struct _ATA_WORKER_CONTEXTPATA_WORKER_CONTEXT
 
typedef struct _ATA_WORKER_DEVICE_CONTEXT ATA_WORKER_DEVICE_CONTEXT
 
typedef struct _ATA_WORKER_DEVICE_CONTEXTPATA_WORKER_DEVICE_CONTEXT
 
typedef struct _REQUEST_QUEUE_ENTRY REQUEST_QUEUE_ENTRY
 
typedef struct _REQUEST_QUEUE_ENTRYPREQUEST_QUEUE_ENTRY
 
typedef struct _ATAPORT_COMMON_EXTENSION ATAPORT_COMMON_EXTENSION
 
typedef struct _ATAPORT_COMMON_EXTENSIONPATAPORT_COMMON_EXTENSION
 

Enumerations

enum  _ATA_PORT_ACTION {
  ACTION_PORT_RESET = (1 << 0) , ACTION_ENUM_PORT = (1 << 1) , ACTION_ENUM_DEVICE_NEW = (1 << 2) , ACTION_ENUM_DEVICE = (1 << 3) ,
  ACTION_PORT_TIMING = (1 << 4) , ACTION_DEVICE_CONFIG = (1 << 5) , ACTION_DEVICE_ERROR = (1 << 6) , ACTION_DEVICE_POWER = (1 << 7)
}
 
enum  _ATA_DEVICE_STATUS { DEV_STATUS_NO_DEVICE , DEV_STATUS_NEW_DEVICE , DEV_STATUS_SAME_DEVICE , DEV_STATUS_FAILED }
 
enum  _ATA_ERROR_LOG_VALUE {
  EVENT_CODE_CRC_ERROR = 100 , EVENT_CODE_BAD_STATE , EVENT_CODE_TIMEOUT , EVENT_CODE_DOWNSHIFT ,
  EVENT_CODE_DMA_DISABLE , EVENT_CODE_NCQ_DISABLE
}
 
enum  DEVICE_TYPE_NAME { GetDeviceType , GetGenericType , GetPeripheralId }
 

Functions

 C_ASSERT (sizeof(REQUEST_QUEUE_ENTRY)<=4 *sizeof(PVOID))
 
 C_ASSERT (REQUEST_FLAG_DATA_IN==SRB_FLAGS_DATA_IN)
 
 C_ASSERT (REQUEST_FLAG_DATA_OUT==SRB_FLAGS_DATA_OUT)
 
 C_ASSERT (REQUEST_FLAG_NO_KEEP_AWAKE==SRB_FLAGS_NO_KEEP_AWAKE)
 
 C_ASSERT (QUEUE_FLAG_FROZEN_QUEUE_FREEZE==SRB_FLAGS_BYPASS_FROZEN_QUEUE)
 
 C_ASSERT (QUEUE_FLAG_FROZEN_QUEUE_LOCK==SRB_FLAGS_BYPASS_LOCKED_QUEUE)
 
FORCEINLINE BOOLEAN AtaPortQueueEmpty (_In_ PATAPORT_PORT_DATA PortData)
 
FORCEINLINE ATA_SCSI_ADDRESS AtaMarshallScsiAddress (_In_ ULONG PathId, _In_ ULONG TargetId, _In_ ULONG Lun)
 
FORCEINLINE BOOLEAN IsPowerOfTwo (_In_ ULONG x)
 
FORCEINLINE BOOLEAN AtaPacketCommandUseDma (_In_ UCHAR OpCode)
 
FORCEINLINE BOOLEAN AtaCommandUseLba48 (_In_ ULONG64 SectorNumber, _In_ ULONG SectorCount)
 
 _Dispatch_type_ (IRP_MJ_CREATE) _Dispatch_type_(IRP_MJ_CLOSE) DRIVER_DISPATCH_PAGED AtaDispatchCreateClose
 
PCSTR AtaTypeCodeToName (_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ DEVICE_TYPE_NAME Type)
 
NTSTATUS AtaOpenRegistryKey (_Out_ PHANDLE KeyHandle, _In_ HANDLE RootKey, _In_ PUNICODE_STRING KeyName, _In_ BOOLEAN Create)
 
VOID AtaGetRegistryKey (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ UCHAR TargetId, _In_ PCWSTR KeyName, _Out_ PULONG KeyValue, _In_ ULONG DefaultValue)
 
VOID AtaSetRegistryKey (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ UCHAR TargetId, _In_ PCWSTR KeyName, _In_ ULONG KeyValue)
 
VOID AtaSetPortRegistryKey (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PCWSTR KeyName, _In_ ULONG KeyValue)
 
NTSTATUS AtaPnpQueryInterface (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ const GUID *Guid, _Out_ PVOID Interface, _In_ ULONG Version, _In_ ULONG Size)
 
NTSTATUS AtaPnpRepeatRequest (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp, _In_opt_ PDEVICE_CAPABILITIES DeviceCapabilities)
 
NTSTATUS AtaPnpQueryDeviceUsageNotification (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp)
 
NTSTATUS AtaPnpQueryPnpDeviceState (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp)
 
VOID AtaPnpInitializeCommonExtension (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PDEVICE_OBJECT SelfDeviceObject, _In_ ULONG Flags)
 
NTSTATUS AtaPortDeviceProcessConfig (_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
NTSTATUS AtaPortDeviceProcessError (_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
NTSTATUS AtaDeviceSendIdentify (_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ UCHAR Command)
 
ATA_DEVICE_STATUS AtaPortIdentifyDevice (_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
 _Dispatch_type_ (IRP_MJ_POWER) DRIVER_DISPATCH_RAISED AtaDispatchPower
 
VOID AtaDeviceFlushPowerIrpQueue (_In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
UCHAR AtaDeviceGetFlushCacheCommand (_In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
NTSTATUS AtaPortDeviceProcessPowerChange (_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
NTSTATUS AtaPortCheckDevicePowerState (_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
VOID AtaPortSelectTimings (_In_ PATAPORT_PORT_DATA PortData, _In_ BOOLEAN ForceCompatibleTimings)
 
PUCHAR AtaCopyIdStringUnsafe (_Out_writes_bytes_all_(Length) PUCHAR Destination, _In_reads_bytes_(Length) PUCHAR Source, _In_ ULONG Length)
 
PCHAR AtaCopyIdStringSafe (_Out_writes_bytes_all_(MaxLength) PCHAR Destination, _In_reads_bytes_(MaxLength) PUCHAR Source, _In_ ULONG MaxLength, _In_ CHAR DefaultCharacter)
 
VOID AtaSwapIdString (_Inout_updates_bytes_(WordCount *sizeof(USHORT)) PVOID Buffer, _In_range_(>, 0) ULONG WordCount)
 
VOID AtaDeviceSetAddressingMode (_In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
NTSTATUS AtaFdoQueryBusRelations (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PIRP Irp)
 
NTSTATUS AtaFdoStartDevice (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PCM_RESOURCE_LIST ResourcesTranslated)
 
NTSTATUS AtaFdoPnp (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _Inout_ PIRP Irp)
 
DECLSPEC_NOINLINE_FROM_PAGED PATAPORT_DEVICE_EXTENSION AtaFdoFindDeviceByPath (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ ATA_SCSI_ADDRESS AtaScsiAddress, _In_ PVOID ReferenceTag)
 
DECLSPEC_NOINLINE_FROM_PAGED PATAPORT_DEVICE_EXTENSION AtaFdoFindNextDeviceByPath (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _Inout_ PATA_SCSI_ADDRESS AtaScsiAddress, _In_ BOOLEAN SearchRemoveDev, _In_ PVOID ReferenceTag)
 
DECLSPEC_NOINLINE_FROM_PAGED VOID AtaFdoDeviceListInsert (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ BOOLEAN DoInsert)
 
 _Dispatch_type_ (IRP_MJ_DEVICE_CONTROL) DRIVER_DISPATCH_RAISED AtaDispatchDeviceControl
 
 _Dispatch_type_ (IRP_MJ_PNP) DRIVER_DISPATCH_PAGED AtaDispatchPnp
 
VOID AtaPdoFreeDevice (_In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
PATAPORT_DEVICE_EXTENSION AtaPdoCreateDevice (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ ATA_SCSI_ADDRESS AtaScsiAddress)
 
NTSTATUS AtaPortSendRequest (_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
VOID AtaPortTimeout (_In_ PATAPORT_PORT_DATA PortData, _In_ ULONG Slot)
 
DECLSPEC_NOINLINE_FROM_PAGED VOID AtaPortSignalWorkerThread (_In_ PATAPORT_PORT_DATA PortData)
 
DECLSPEC_NOINLINE_FROM_PAGED VOID AtaDeviceQueueEvent (_In_ PATAPORT_PORT_DATA PortData, _In_opt_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ ATA_PORT_ACTION Action)
 
BOOLEAN AtaReqDmaTransferToPioTransfer (_In_ PATA_DEVICE_REQUEST Request)
 
VOID AtaCreateStandardInquiryData (_In_ PATAPORT_DEVICE_EXTENSION DevExt)
 
UCHAR AtaReqExecuteScsi (_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ PATA_DEVICE_REQUEST Request, _In_ PSCSI_REQUEST_BLOCK Srb)
 
UCHAR AtaReqSetFixedAtaSenseData (_In_ PATA_DEVICE_REQUEST Request)
 
VOID AtaReqBuildReadLogTaskFile (_In_ PATA_DEVICE_REQUEST Request, _In_ UCHAR LogAddress, _In_ UCHAR PageNumber, _In_ USHORT LogPageCount)
 
 _Dispatch_type_ (IRP_MJ_SCSI) DRIVER_DISPATCH_RAISED AtaDispatchScsi
 
VOID AtaReqCompleteFailedRequest (_In_ PATA_DEVICE_REQUEST Request)
 
UCHAR AtaReqSetFixedSenseData (_In_ PSCSI_REQUEST_BLOCK Srb, _In_ SCSI_SENSE_CODE SenseCode)
 
VOID AtaReqSetLbaInformation (_In_ PSCSI_REQUEST_BLOCK Srb, _In_ ULONG64 Lba)
 
BOOLEAN AtaReqAllocateMdl (_In_ PATA_DEVICE_REQUEST Request)
 
VOID AtaReqSendRequest (_In_ PATA_DEVICE_REQUEST Request)
 
VOID AtaReqStartCompletionDpc (_In_ PATA_DEVICE_REQUEST Request)
 
DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqFreezeQueue (_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ ULONG ReasonFlags)
 
DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqThawQueue (_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ ULONG ReasonFlags)
 
DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqWaitForOutstandingIoToComplete (_In_ PATAPORT_IO_CONTEXT Device, _In_ PSCSI_REQUEST_BLOCK Srb)
 
DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqFlushDeviceQueue (_In_ PATAPORT_IO_CONTEXT Device)
 
UCHAR AtaReqSmartIoControl (_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ PATA_DEVICE_REQUEST Request, _In_ PSCSI_REQUEST_BLOCK Srb)
 
NTSTATUS AtaPdoHandleMiniportSmartVersion (_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ PSCSI_REQUEST_BLOCK Srb)
 
NTSTATUS AtaPdoHandleMiniportIdentify (_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ PSCSI_REQUEST_BLOCK Srb)
 
 _Dispatch_type_ (IRP_MJ_SYSTEM_CONTROL) DRIVER_DISPATCH_PAGED AtaDispatchWmi
 
NTSTATUS AtaPdoWmiRegistration (_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ BOOLEAN Register)
 

Variables

UNICODE_STRING AtapDriverRegistryPath
 
BOOLEAN AtapInPEMode
 
DRIVER_ADD_DEVICE AtaAddChannel
 
DRIVER_UNLOAD AtaUnload
 
DRIVER_INITIALIZE DriverEntry
 
IO_WORKITEM_ROUTINE AtaStorageNotificationWorker
 
KDEFERRED_ROUTINE AtaStorageNotificationlDpc
 
IO_COMPLETION_ROUTINE AtaPdoCompletionRoutine
 
KSTART_ROUTINE AtaPortWorkerThread
 
KDEFERRED_ROUTINE AtaPortWorkerSignalDpc
 
REQUEST_COMPLETION_ROUTINE AtaPortCompleteInternalRequest
 
PORT_NOTIFICATION AtaPortNotification
 
IO_TIMER_ROUTINE AtaPortIoTimer
 
KDEFERRED_ROUTINE AtaReqCompletionDpc
 
SLIST_HEADER AtapCompletionQueueList
 
KDPC AtapCompletionDpc
 

Macro Definition Documentation

◆ ASSERT_REQUEST

#define ASSERT_REQUEST (   Request)     ASSERT((Request) && (Request)->Signature == ATA_DEVICE_REQUEST_SIGNATURE)

Definition at line 326 of file atapi.h.

◆ ASSUME

#define ASSUME (   cond)
Value:
do { \
ASSERT(cond); \
__assume(cond); \
} while (0)

Definition at line 165 of file atapi.h.

◆ ATA_LOCAL_BUFFER_SIZE

#define ATA_LOCAL_BUFFER_SIZE   572

Definition at line 205 of file atapi.h.

◆ ATA_MAX_LBA_28

#define ATA_MAX_LBA_28   0x0FFFFFFFULL

Definition at line 209 of file atapi.h.

◆ ATA_MAX_LBA_48

#define ATA_MAX_LBA_48   (1ULL << 48)

Definition at line 210 of file atapi.h.

◆ ATA_MAX_LUN_COUNT

#define ATA_MAX_LUN_COUNT   8

Definition at line 202 of file atapi.h.

◆ ATA_RESERVED_PAGES

#define ATA_RESERVED_PAGES   4

Definition at line 200 of file atapi.h.

◆ ATAPORT_FN_FIELD

#define ATAPORT_FN_FIELD   40

The maximum length of identifier strings for ATA devices excluding the terminating NULL.

See also
See MSDN note: https://learn.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-ide-devices

and IDENTIFY_DEVICE_DATA.SerialNumber IDENTIFY_DEVICE_DATA.ModelNumber IDENTIFY_DEVICE_DATA.FirmwareRevision

Definition at line 195 of file atapi.h.

◆ ATAPORT_PAGED_DATA

#define ATAPORT_PAGED_DATA   DATA_SEG("PAGECONS")

Pageable read-only data

Definition at line 153 of file atapi.h.

◆ ATAPORT_RN_FIELD

#define ATAPORT_RN_FIELD   8

Definition at line 197 of file atapi.h.

◆ ATAPORT_SN_FIELD

#define ATAPORT_SN_FIELD   40

Definition at line 196 of file atapi.h.

◆ ATAPORT_TAG

#define ATAPORT_TAG   'PedI'

Definition at line 171 of file atapi.h.

◆ DECLARE_PAGED_STRING

#define DECLARE_PAGED_STRING (   v,
  n 
)     static const ATAPORT_PAGED_DATA CHAR (v)[] = (n)

Definition at line 159 of file atapi.h.

◆ DECLARE_PAGED_UNICODE_STRING

#define DECLARE_PAGED_UNICODE_STRING (   Variable,
  Str 
)
Value:
static const ATAPORT_PAGED_DATA WCHAR Variable##_buffer[] = Str; \
UNICODE_STRING Variable = { sizeof(Str) - sizeof(WCHAR), sizeof(Str), (PWCH)Variable##_buffer } \
#define ATAPORT_PAGED_DATA
Definition: atapi.h:153
WCHAR * PWCH
Definition: ntbasedef.h:422
short WCHAR
Definition: pedump.c:58

Definition at line 155 of file atapi.h.

◆ DECLARE_PAGED_WSTRING

#define DECLARE_PAGED_WSTRING (   v,
  n 
)     static const ATAPORT_PAGED_DATA WCHAR (v)[] = (n)

Definition at line 162 of file atapi.h.

◆ DEV_WORKER_FLAG_HOLD_REFERENCE

#define DEV_WORKER_FLAG_HOLD_REFERENCE   0x00000001

Definition at line 304 of file atapi.h.

◆ DEV_WORKER_FLAG_REMOVED

#define DEV_WORKER_FLAG_REMOVED   0x00000002

Definition at line 305 of file atapi.h.

◆ DEVICE_CACHE_INQUIRY

#define DEVICE_CACHE_INQUIRY   0x00004000

Definition at line 96 of file atapi.h.

◆ DEVICE_DESCRIPTOR_SENSE

#define DEVICE_DESCRIPTOR_SENSE   0x00000800

Definition at line 93 of file atapi.h.

◆ DEVICE_HAS_FUA

#define DEVICE_HAS_FUA   0x00000008

Definition at line 85 of file atapi.h.

◆ DEVICE_HAS_MEDIA_STATUS

#define DEVICE_HAS_MEDIA_STATUS   0x00000020

Definition at line 87 of file atapi.h.

◆ DEVICE_IS_PDO_REMOVABLE

#define DEVICE_IS_PDO_REMOVABLE   0x00000100

Definition at line 90 of file atapi.h.

◆ DEVICE_IS_SUPER_FLOPPY

#define DEVICE_IS_SUPER_FLOPPY   0x00000080

Definition at line 89 of file atapi.h.

◆ DEVICE_LBA48

#define DEVICE_LBA48   0x00000004

Definition at line 84 of file atapi.h.

◆ DEVICE_LBA_MODE

#define DEVICE_LBA_MODE   0x00000002

Definition at line 83 of file atapi.h.

◆ DEVICE_NCQ

#define DEVICE_NCQ   0x00000010

Definition at line 86 of file atapi.h.

◆ DEVICE_PIO_FOR_LBA48_XFER

#define DEVICE_PIO_FOR_LBA48_XFER   0x00002000

Definition at line 95 of file atapi.h.

◆ DEVICE_PIO_ONLY

#define DEVICE_PIO_ONLY   0x00000001

Definition at line 82 of file atapi.h.

◆ DEVICE_PIO_VIA_DMA

#define DEVICE_PIO_VIA_DMA   0x00001000

Definition at line 94 of file atapi.h.

◆ DEVICE_PNP_STARTED

#define DEVICE_PNP_STARTED   0x00000400

Definition at line 92 of file atapi.h.

◆ DEVICE_SENSE_DATA_REPORTING

#define DEVICE_SENSE_DATA_REPORTING   0x00000040

Definition at line 88 of file atapi.h.

◆ DEVICE_UNINITIALIZED

#define DEVICE_UNINITIALIZED   0x00000200

Definition at line 91 of file atapi.h.

◆ DO_IS_FDO

#define DO_IS_FDO   0x80000000

Definition at line 430 of file atapi.h.

◆ IDE_COMMAND_REQUEST_SENSE_DATA_EXT

#define IDE_COMMAND_REQUEST_SENSE_DATA_EXT   0x0B

Definition at line 226 of file atapi.h.

◆ IDE_DC_ALWAYS

#define IDE_DC_ALWAYS   0x08

Definition at line 224 of file atapi.h.

◆ IDE_DEVICE_FUA_NCQ

#define IDE_DEVICE_FUA_NCQ   0x80

Definition at line 222 of file atapi.h.

◆ IDE_DRIVE_SELECT

#define IDE_DRIVE_SELECT   0xA0

Definition at line 214 of file atapi.h.

◆ IDE_DRIVE_SELECT_SLAVE

#define IDE_DRIVE_SELECT_SLAVE   0x10

Definition at line 212 of file atapi.h.

◆ IDE_ERROR_WRITE_PROTECT

#define IDE_ERROR_WRITE_PROTECT   0x40

Definition at line 216 of file atapi.h.

◆ IDE_FEATURE_DMA

#define IDE_FEATURE_DMA   0x01

Definition at line 219 of file atapi.h.

◆ IDE_FEATURE_DMADIR

#define IDE_FEATURE_DMADIR   0x04

Definition at line 220 of file atapi.h.

◆ IDE_FEATURE_PIO

#define IDE_FEATURE_PIO   0x00

Definition at line 218 of file atapi.h.

◆ IDE_HIGH_ORDER_BYTE

#define IDE_HIGH_ORDER_BYTE   0x80

Definition at line 213 of file atapi.h.

◆ IRP_FROM_QUEUE_ENTRY

Definition at line 313 of file atapi.h.

◆ IS_ATAPI

#define IS_ATAPI (   Device)     (((Device)->TransportFlags & DEVICE_IS_ATAPI) != 0)

Definition at line 176 of file atapi.h.

◆ IS_FDO

#define IS_FDO (   p)     ((((PATAPORT_COMMON_EXTENSION)(p))->Flags & DO_IS_FDO) != 0)

Definition at line 173 of file atapi.h.

◆ MAX_SLOTS

#define MAX_SLOTS   32

Definition at line 207 of file atapi.h.

◆ NUM_TO_BITMAP

#define NUM_TO_BITMAP (   num)    (0xFFFFFFFF >> (RTL_BITS_OF(ULONG) - (num)))

Definition at line 179 of file atapi.h.

◆ PORT_FLAG_CHANNEL_ATTACHED

#define PORT_FLAG_CHANNEL_ATTACHED   0x00000080

Definition at line 343 of file atapi.h.

◆ PORT_FLAG_EXIT_THREAD

#define PORT_FLAG_EXIT_THREAD   0x80000000

Definition at line 346 of file atapi.h.

◆ PORT_FLAG_IO_TIMER_ACTIVE

#define PORT_FLAG_IO_TIMER_ACTIVE   0x00000040

Definition at line 342 of file atapi.h.

◆ PORT_FLAG_IS_AHCI

#define PORT_FLAG_IS_AHCI   0x00000010

Definition at line 340 of file atapi.h.

◆ PORT_FLAG_IS_EXTERNAL

#define PORT_FLAG_IS_EXTERNAL   0x00000004

Definition at line 338 of file atapi.h.

◆ PORT_FLAG_IS_SIMPLEX

#define PORT_FLAG_IS_SIMPLEX   0x00000001

Definition at line 336 of file atapi.h.

◆ PORT_FLAG_NCQ

#define PORT_FLAG_NCQ   0x00000008

Definition at line 339 of file atapi.h.

◆ PORT_FLAG_PIO_FOR_LBA48_XFER

#define PORT_FLAG_PIO_FOR_LBA48_XFER   0x00000200

Definition at line 345 of file atapi.h.

◆ PORT_FLAG_PIO_ONLY

#define PORT_FLAG_PIO_ONLY   0x00000100

Definition at line 344 of file atapi.h.

◆ PORT_FLAG_PIO_VIA_DMA

#define PORT_FLAG_PIO_VIA_DMA   0x00000002

Definition at line 337 of file atapi.h.

◆ PORT_FLAG_SYMLINK_CREATED

#define PORT_FLAG_SYMLINK_CREATED   0x00000020

Definition at line 341 of file atapi.h.

◆ PORT_INT_FLAG_IGNORE_LINK_IRQ

#define PORT_INT_FLAG_IGNORE_LINK_IRQ   0x00000002

Definition at line 361 of file atapi.h.

◆ PORT_INT_FLAG_IS_IO_ACTIVE

#define PORT_INT_FLAG_IS_IO_ACTIVE   0x00000001

Definition at line 360 of file atapi.h.

◆ PORT_QUEUE_FLAG_EXCLUSIVE_MODE

#define PORT_QUEUE_FLAG_EXCLUSIVE_MODE   0x00000001

Definition at line 369 of file atapi.h.

◆ PORT_QUEUE_FLAG_SIGNAL_STOP

#define PORT_QUEUE_FLAG_SIGNAL_STOP   0x00000002

Definition at line 370 of file atapi.h.

◆ QUEUE_ENTRY_FROM_IRP

#define QUEUE_ENTRY_FROM_IRP (   Irp)     ((PREQUEST_QUEUE_ENTRY)&(((PIRP)(Irp))->Tail.Overlay.DriverContext[0]))

Definition at line 310 of file atapi.h.

◆ QUEUE_FLAG_FROZEN_PNP

#define QUEUE_FLAG_FROZEN_PNP   0x00000004

Definition at line 107 of file atapi.h.

◆ QUEUE_FLAG_FROZEN_PORT_BUSY

#define QUEUE_FLAG_FROZEN_PORT_BUSY   0x00000001

Definition at line 105 of file atapi.h.

◆ QUEUE_FLAG_FROZEN_POWER

#define QUEUE_FLAG_FROZEN_POWER   0x00000020

Definition at line 110 of file atapi.h.

◆ QUEUE_FLAG_FROZEN_QUEUE_FREEZE

#define QUEUE_FLAG_FROZEN_QUEUE_FREEZE   0x00000010

Definition at line 109 of file atapi.h.

◆ QUEUE_FLAG_FROZEN_QUEUE_LOCK

#define QUEUE_FLAG_FROZEN_QUEUE_LOCK   0x00080000

Definition at line 112 of file atapi.h.

◆ QUEUE_FLAG_FROZEN_REMOVED

#define QUEUE_FLAG_FROZEN_REMOVED   0x00000040

Definition at line 111 of file atapi.h.

◆ QUEUE_FLAG_FROZEN_SLOT

#define QUEUE_FLAG_FROZEN_SLOT   0x00000002

Definition at line 106 of file atapi.h.

◆ QUEUE_FLAG_SIGNAL_STOP

#define QUEUE_FLAG_SIGNAL_STOP   0x00000008

Definition at line 108 of file atapi.h.

◆ QUEUE_FLAGS_FROZEN

#define QUEUE_FLAGS_FROZEN
Value:
#define QUEUE_FLAG_FROZEN_SLOT
Definition: atapi.h:106
#define QUEUE_FLAG_FROZEN_POWER
Definition: atapi.h:110
#define QUEUE_FLAG_FROZEN_QUEUE_LOCK
Definition: atapi.h:112
#define QUEUE_FLAG_FROZEN_PORT_BUSY
Definition: atapi.h:105
#define QUEUE_FLAG_FROZEN_PNP
Definition: atapi.h:107
#define QUEUE_FLAG_FROZEN_REMOVED
Definition: atapi.h:111
#define QUEUE_FLAG_FROZEN_QUEUE_FREEZE
Definition: atapi.h:109

Definition at line 114 of file atapi.h.

◆ QUEUE_FLAGS_FROZEN_NOT_BYPASS

Definition at line 123 of file atapi.h.

◆ SRB_CLEAR_FLAGS

#define SRB_CLEAR_FLAGS (   Srb,
  Flags 
)     ((Srb)->SrbExtension = (PVOID)((ULONG_PTR)(Srb)->SrbExtension & ~(Flags)))

Definition at line 235 of file atapi.h.

◆ SRB_FLAG_LOW_MEM_RETRY

#define SRB_FLAG_LOW_MEM_RETRY   0x00000100

Definition at line 229 of file atapi.h.

◆ SRB_FLAG_PIO_RETRY

#define SRB_FLAG_PIO_RETRY   0x00000200

Definition at line 230 of file atapi.h.

◆ SRB_FLAG_RETRY_COUNT_MASK

#define SRB_FLAG_RETRY_COUNT_MASK   0x000000FF

Definition at line 228 of file atapi.h.

◆ SRB_GET_FLAGS

#define SRB_GET_FLAGS (   Srb)    ((ULONG_PTR)(Srb)->SrbExtension)

Definition at line 238 of file atapi.h.

◆ SRB_SET_FLAGS

#define SRB_SET_FLAGS (   Srb,
  Flags 
)     ((Srb)->SrbExtension = (PVOID)((ULONG_PTR)(Srb)->SrbExtension | (Flags)))

Definition at line 232 of file atapi.h.

◆ WORKER_FLAG_COMPLETE_PORT_ENUM_EVENT

#define WORKER_FLAG_COMPLETE_PORT_ENUM_EVENT   0x00000002

Definition at line 280 of file atapi.h.

◆ WORKER_FLAG_NEED_RESCAN

#define WORKER_FLAG_NEED_RESCAN   0x00000001

Definition at line 279 of file atapi.h.

Typedef Documentation

◆ ATA_DEVICE_STATUS

◆ ATA_ERROR_LOG_VALUE

◆ ATA_PORT_ACTION

◆ ATA_SCSI_ADDRESS

◆ ATA_WORKER_CONTEXT

◆ ATA_WORKER_DEVICE_CONTEXT

◆ ATAPORT_CHANNEL_EXTENSION

◆ ATAPORT_COMMON_EXTENSION

◆ ATAPORT_DEVICE_EXTENSION

◆ ATAPORT_IO_CONTEXT

Definition at line 36 of file atapi.h.

◆ ATAPORT_PORT_DATA

Definition at line 35 of file atapi.h.

◆ PATA_SCSI_ADDRESS

◆ PATA_WORKER_CONTEXT

◆ PATA_WORKER_DEVICE_CONTEXT

◆ PATAPORT_CHANNEL_EXTENSION

◆ PATAPORT_COMMON_EXTENSION

◆ PATAPORT_DEVICE_EXTENSION

Definition at line 34 of file atapi.h.

◆ PATAPORT_IO_CONTEXT

Definition at line 36 of file atapi.h.

◆ PATAPORT_PORT_DATA

Definition at line 35 of file atapi.h.

◆ PREQUEST_QUEUE_ENTRY

◆ PSTOP_IO_CALLBACK

Definition at line 75 of file atapi.h.

◆ REQUEST_QUEUE_ENTRY

◆ STOP_IO_CALLBACK

typedef VOID() STOP_IO_CALLBACK(_In_ PATAPORT_IO_CONTEXT Device)

Definition at line 72 of file atapi.h.

Enumeration Type Documentation

◆ _ATA_DEVICE_STATUS

Enumerator
DEV_STATUS_NO_DEVICE 
DEV_STATUS_NEW_DEVICE 
DEV_STATUS_SAME_DEVICE 
DEV_STATUS_FAILED 

Definition at line 253 of file atapi.h.

254{
@ DEV_STATUS_FAILED
Definition: atapi.h:258
@ DEV_STATUS_SAME_DEVICE
Definition: atapi.h:257
@ DEV_STATUS_NO_DEVICE
Definition: atapi.h:255
@ DEV_STATUS_NEW_DEVICE
Definition: atapi.h:256
enum _ATA_DEVICE_STATUS ATA_DEVICE_STATUS

◆ _ATA_ERROR_LOG_VALUE

Enumerator
EVENT_CODE_CRC_ERROR 
EVENT_CODE_BAD_STATE 
EVENT_CODE_TIMEOUT 
EVENT_CODE_DOWNSHIFT 
EVENT_CODE_DMA_DISABLE 
EVENT_CODE_NCQ_DISABLE 

Definition at line 261 of file atapi.h.

262{
@ EVENT_CODE_CRC_ERROR
Definition: atapi.h:263
@ EVENT_CODE_BAD_STATE
Definition: atapi.h:264
@ EVENT_CODE_TIMEOUT
Definition: atapi.h:265
@ EVENT_CODE_NCQ_DISABLE
Definition: atapi.h:268
@ EVENT_CODE_DOWNSHIFT
Definition: atapi.h:266
@ EVENT_CODE_DMA_DISABLE
Definition: atapi.h:267
enum _ATA_ERROR_LOG_VALUE ATA_ERROR_LOG_VALUE

◆ _ATA_PORT_ACTION

Enumerator
ACTION_PORT_RESET 
ACTION_ENUM_PORT 
ACTION_ENUM_DEVICE_NEW 
ACTION_ENUM_DEVICE 
ACTION_PORT_TIMING 
ACTION_DEVICE_CONFIG 
ACTION_DEVICE_ERROR 
ACTION_DEVICE_POWER 

Definition at line 241 of file atapi.h.

242{
243 ACTION_PORT_RESET = (1 << 0), // High priority
244 ACTION_ENUM_PORT = (1 << 1),
245 ACTION_ENUM_DEVICE_NEW = (1 << 2),
246 ACTION_ENUM_DEVICE = (1 << 3),
247 ACTION_PORT_TIMING = (1 << 4), // Set transfer timings after device enumeration only
248 ACTION_DEVICE_CONFIG = (1 << 5), // Also use the timing information for configuration
249 ACTION_DEVICE_ERROR = (1 << 6),
250 ACTION_DEVICE_POWER = (1 << 7),
@ ACTION_DEVICE_CONFIG
Definition: atapi.h:248
@ ACTION_ENUM_PORT
Definition: atapi.h:244
@ ACTION_DEVICE_POWER
Definition: atapi.h:250
@ ACTION_PORT_TIMING
Definition: atapi.h:247
@ ACTION_DEVICE_ERROR
Definition: atapi.h:249
@ ACTION_ENUM_DEVICE_NEW
Definition: atapi.h:245
@ ACTION_ENUM_DEVICE
Definition: atapi.h:246
@ ACTION_PORT_RESET
Definition: atapi.h:243
enum _ATA_PORT_ACTION ATA_PORT_ACTION

◆ DEVICE_TYPE_NAME

Enumerator
GetDeviceType 
GetGenericType 
GetPeripheralId 

Definition at line 564 of file atapi.h.

565{
DEVICE_TYPE_NAME
Definition: atapi.h:565
@ GetGenericType
Definition: atapi.h:567
@ GetPeripheralId
Definition: atapi.h:568
@ GetDeviceType
Definition: atapi.h:566

Function Documentation

◆ _Dispatch_type_() [1/6]

_Dispatch_type_ ( IRP_MJ_CREATE  )

Definition at line 1353 of file isapnp.c.

1364{
1365 PAGED_CODE();
1366
1367 Irp->IoStatus.Status = STATUS_SUCCESS;
1368
1369 DPRINT("%s(%p, %p)\n", __FUNCTION__, DeviceObject, Irp);
1370
1372
1373 return STATUS_SUCCESS;
1374}
#define PAGED_CODE()
_In_ PIRP Irp
Definition: csq.h:116
#define __FUNCTION__
Definition: types.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
#define IO_NO_INCREMENT
Definition: iotypes.h:598

◆ _Dispatch_type_() [2/6]

_Dispatch_type_ ( IRP_MJ_DEVICE_CONTROL  )

Definition at line 1376 of file isapnp.c.

1387{
1388 PISAPNP_COMMON_EXTENSION CommonExt = DeviceObject->DeviceExtension;
1389
1390 PAGED_CODE();
1391
1392 DPRINT("%s(%p, %p) Minor - %X\n", __FUNCTION__, DeviceObject, Irp,
1394
1395 if (CommonExt->Signature == IsaPnpBus)
1396 {
1398 return IoCallDriver(((PISAPNP_FDO_EXTENSION)CommonExt)->Ldo, Irp);
1399 }
1400 else
1401 {
1402 NTSTATUS Status = Irp->IoStatus.Status;
1403
1405 return Status;
1406 }
1407}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: gdiplustypes.h:25
@ IsaPnpBus
Definition: isapnp.h:36
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IoCallDriver
Definition: irp.c:1225
ISAPNP_SIGNATURE Signature
Definition: isapnp.h:43
_In_ UCHAR _In_ UCHAR MinorFunction
Definition: wdfdevice.h:1705

◆ _Dispatch_type_() [3/6]

_Dispatch_type_ ( IRP_MJ_PNP  )

Definition at line 1331 of file isapnp.c.

1341{
1343 PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
1344
1345 PAGED_CODE();
1346
1347 if (DevExt->Signature == IsaPnpBus)
1348 return IsaFdoPnp((PISAPNP_FDO_EXTENSION)DevExt, Irp, IrpSp);
1349 else
1350 return IsaPdoPnp((PISAPNP_PDO_EXTENSION)DevExt, Irp, IrpSp);
1351}
NTSTATUS IsaFdoPnp(_In_ PISAPNP_FDO_EXTENSION FdoExt, _Inout_ PIRP Irp, _In_ PIO_STACK_LOCATION IrpSp)
Definition: fdo.c:123
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4138
NTSTATUS IsaPdoPnp(_In_ PISAPNP_PDO_EXTENSION PdoDeviceExtension, _Inout_ PIRP Irp, _In_ PIO_STACK_LOCATION IrpSp)
Definition: pdo.c:867

◆ _Dispatch_type_() [4/6]

_Dispatch_type_ ( IRP_MJ_POWER  )

Definition at line 1293 of file isapnp.c.

1302{
1303 PISAPNP_COMMON_EXTENSION DevExt = DeviceObject->DeviceExtension;
1305
1306 if (DevExt->Signature != IsaPnpBus)
1307 {
1309 {
1310 case IRP_MN_SET_POWER:
1311 case IRP_MN_QUERY_POWER:
1313 Irp->IoStatus.Status = Status;
1314 break;
1315
1316 default:
1317 Status = Irp->IoStatus.Status;
1318 break;
1319 }
1320
1323 return Status;
1324 }
1325
1328 return PoCallDriver(((PISAPNP_FDO_EXTENSION)DevExt)->Ldo, Irp);
1329}
VOID NTAPI PoStartNextPowerIrp(IN PIRP Irp)
Definition: power.c:758
#define IRP_MN_SET_POWER
#define IRP_MN_QUERY_POWER

◆ _Dispatch_type_() [5/6]

_Dispatch_type_ ( IRP_MJ_SCSI  )

◆ _Dispatch_type_() [6/6]

_Dispatch_type_ ( IRP_MJ_SYSTEM_CONTROL  )

Definition at line 5748 of file btrfs.c.

5750 {
5752 device_extension* Vcb = DeviceObject->DeviceExtension;
5753 bool top_level;
5754
5756
5757 top_level = is_top_level(Irp);
5758
5759 Irp->IoStatus.Information = 0;
5760
5761 if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
5762 volume_device_extension* vde = DeviceObject->DeviceExtension;
5763
5765
5767
5768 goto exit;
5769 } else if (Vcb && Vcb->type == VCB_TYPE_FS) {
5771
5772 Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
5773
5774 goto exit;
5775 } else if (Vcb && Vcb->type == VCB_TYPE_BUS) {
5776 bus_device_extension* bde = DeviceObject->DeviceExtension;
5777
5779
5781
5782 goto exit;
5783 }
5784
5785 Status = Irp->IoStatus.Status;
5787
5788exit:
5789 if (top_level)
5791
5793
5794 return Status;
5795}
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:689
#define VCB_TYPE_FS
Definition: btrfs_drv.h:687
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:691
#define NULL
Definition: types.h:112
InsertTailList & Vcb
Definition: btrfs.c:3044
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:278
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define exit(n)
Definition: config.h:202
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:880
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:849

◆ AtaCommandUseLba48()

FORCEINLINE BOOLEAN AtaCommandUseLba48 ( _In_ ULONG64  SectorNumber,
_In_ ULONG  SectorCount 
)

Definition at line 630 of file atapi.h.

633{
634 /* Use the 48-bit command when reasonable */
635 return (((SectorNumber + SectorCount) >= ATA_MAX_LBA_28) || (SectorCount > 0x100));
636}
#define ATA_MAX_LBA_28
Definition: atapi.h:209
ULONG SectorCount
Definition: part_brfr.c:22

◆ AtaCopyIdStringSafe()

PCHAR AtaCopyIdStringSafe ( _Out_writes_bytes_all_(MaxLength) PCHAR  Destination,
_In_reads_bytes_(MaxLength) PUCHAR  Source,
_In_ ULONG  MaxLength,
_In_ CHAR  DefaultCharacter 
)

Definition at line 35 of file enum.c.

40{
41 PCHAR Dest = Destination;
42
43 PAGED_CODE();
44
45 while (MaxLength != 0)
46 {
47 const UCHAR Char = *Source;
48
49 /* Only characters from space to tilde are allowed in an ID */
50 if (Char > ' ' && Char <= '~' && Char != ',')
51 *Dest = Char;
52 else
53 *Dest = DefaultCharacter;
54
55 ++Source;
56 ++Dest;
57 --MaxLength;
58 }
59
60 return Dest;
61}
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3051
unsigned char UCHAR
Definition: typedefs.h:53
char * PCHAR
Definition: typedefs.h:51

Referenced by AtaCreateAtapiStandardInquiryData(), AtaPdoFillIdentificationStrings(), and AtaPdoQueryId().

◆ AtaCopyIdStringUnsafe()

PUCHAR AtaCopyIdStringUnsafe ( _Out_writes_bytes_all_(Length) PUCHAR  Destination,
_In_reads_bytes_(Length) PUCHAR  Source,
_In_ ULONG  Length 
)

Definition at line 15 of file enum.c.

19{
20 ULONG i;
21
22 ASSUME((Length >= sizeof(USHORT)) && (Length % sizeof(USHORT)) == 0);
23
24 /* Copy the ATA string and swap it */
25 for (i = 0; i < Length; i += sizeof(USHORT))
26 {
27 Destination[i] = Source[i + 1];
28 Destination[i + 1] = Source[i];
29 }
30
31 return &Destination[i - 1];
32}
#define ASSUME(cond)
Definition: atapi.h:165
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
unsigned short USHORT
Definition: pedump.c:61
uint32_t ULONG
Definition: typedefs.h:59

Referenced by AtaCreateStandardInquiryData(), AtaDeviceIsXboxDrive(), AtaReqScsiInquiryDeviceIdentifiers(), and AtaReqScsiInquirySerialNumber().

◆ AtaCreateStandardInquiryData()

VOID AtaCreateStandardInquiryData ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt)

Definition at line 1166 of file satl.c.

1168{
1169 PIDENTIFY_DEVICE_DATA IdentifyData = &DevExt->IdentifyDeviceData;
1170 PINQUIRYDATA InquiryData = &DevExt->InquiryData;
1171 ULONG Offset;
1172 PUCHAR VersionDescriptor;
1173
1174 PAGED_CODE();
1175
1176 InquiryData->DeviceType = DIRECT_ACCESS_DEVICE;
1177 InquiryData->RemovableMedia = AtaDevIsRemovable(IdentifyData);
1178 InquiryData->Versions = 0x07; // SPC-5
1179 InquiryData->ResponseDataFormat = 2; // This means "Complies to this standard"
1180
1181 if (DevExt->Device.DeviceFlags & DEVICE_NCQ)
1182 InquiryData->CommandQueue = 1;
1183
1184 /* T10 vendor ID */
1185 RtlCopyMemory(InquiryData->VendorId, "ATA ", RTL_FIELD_SIZE(INQUIRYDATA, VendorId));
1186
1187 /* Product ID */
1188 AtaCopyIdStringUnsafe(InquiryData->ProductId,
1189 IdentifyData->ModelNumber,
1190 RTL_FIELD_SIZE(INQUIRYDATA, ProductId));
1191
1192 /* Product revision level */
1193 if (IdentifyData->FirmwareRevision[4] == ' ' &&
1194 IdentifyData->FirmwareRevision[5] == ' ' &&
1195 IdentifyData->FirmwareRevision[6] == ' ' &&
1196 IdentifyData->FirmwareRevision[7] == ' ')
1197 {
1198 Offset = 0;
1199 }
1200 else
1201 {
1202 Offset = 4;
1203 }
1205 &IdentifyData->FirmwareRevision[Offset],
1206 RTL_FIELD_SIZE(INQUIRYDATA, ProductRevisionLevel));
1207
1208 VersionDescriptor = &InquiryData->Reserved3[3];
1209
1210 /* SAM-5 (no version claimed) */
1211 *VersionDescriptor++ = 0x00;
1212 *VersionDescriptor++ = 0xA0;
1213
1214 /* SPC-5 (no version claimed) */
1215 *VersionDescriptor++ = 0x05;
1216 *VersionDescriptor++ = 0xC0;
1217
1218 /* SBC-4 (no version claimed) */
1219 *VersionDescriptor++ = 0x06;
1220 *VersionDescriptor++ = 0x00;
1221
1222 if (AtaDevHasIeee1667(IdentifyData))
1223 {
1224 /* IEEE 1667 (no version claimed) */
1225 *VersionDescriptor++ = 0xFF;
1226 *VersionDescriptor++ = 0xC0;
1227 }
1228
1229 if (IdentifyData->MajorRevision != 0xFFFF)
1230 {
1231 if (IdentifyData->MajorRevision & (1 << 8))
1232 {
1233 /* ATA/ATAPI-8 ATA8-ACS ATA/ATAPI Command Set (no version claimed) */
1234 *VersionDescriptor++ = 0x16;
1235 *VersionDescriptor++ = 0x23;
1236 }
1237 else if (IdentifyData->MajorRevision & (1 << 7))
1238 {
1239 if (IdentifyData->MinorRevision == 0x1D)
1240 {
1241 /* ATA/ATAPI-7 INCITS 397-2005 */
1242 *VersionDescriptor++ = 0x16;
1243 *VersionDescriptor++ = 0x1C;
1244 }
1245 else
1246 {
1247 /* ATA/ATAPI-7 (no version claimed) */
1248 *VersionDescriptor++ = 0x16;
1249 *VersionDescriptor++ = 0x00;
1250 }
1251 }
1252 else if (IdentifyData->MajorRevision & (1 << 6))
1253 {
1254 if (IdentifyData->MinorRevision == 0x22)
1255 {
1256 /* ATA/ATAPI-6 INCITS 361-2002 */
1257 *VersionDescriptor++ = 0x15;
1258 *VersionDescriptor++ = 0xFD;
1259 }
1260 else
1261 {
1262 /* ATA/ATAPI-6 (no version claimed) */
1263 *VersionDescriptor++ = 0x15;
1264 *VersionDescriptor++ = 0xE0;
1265 }
1266 }
1267 }
1268
1269 InquiryData->AdditionalLength =
1270 ((ULONG_PTR)VersionDescriptor - (ULONG_PTR)InquiryData) -
1271 RTL_SIZEOF_THROUGH_FIELD(INQUIRYDATA, AdditionalLength);
1272
1273 TRACE("VendorId: '%.*s'\n",
1274 RTL_FIELD_SIZE(INQUIRYDATA, VendorId), InquiryData->VendorId);
1275 TRACE("ProductId: '%.*s'\n",
1276 RTL_FIELD_SIZE(INQUIRYDATA, ProductId), InquiryData->ProductId);
1277 TRACE("ProductRevisionLevel: '%.*s'\n",
1278 RTL_FIELD_SIZE(INQUIRYDATA, ProductRevisionLevel), InquiryData->ProductRevisionLevel);
1279}
#define DEVICE_NCQ
Definition: atapi.h:86
PUCHAR AtaCopyIdStringUnsafe(_Out_writes_bytes_all_(Length) PUCHAR Destination, _In_reads_bytes_(Length) PUCHAR Source, _In_ ULONG Length)
Definition: enum.c:15
#define DIRECT_ACCESS_DEVICE
Definition: cdrw_hw.h:1144
#define ULONG_PTR
Definition: config.h:101
FORCEINLINE BOOLEAN AtaDevHasIeee1667(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
FORCEINLINE BOOLEAN AtaDevIsRemovable(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
#define RTL_FIELD_SIZE(type, field)
Definition: kdb_expr.c:86
#define RTL_SIZEOF_THROUGH_FIELD(type, field)
Definition: ntbasedef.h:684
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define TRACE(s)
Definition: solgame.cpp:4
UCHAR FirmwareRevision[8]
Definition: ata.h:25
USHORT MajorRevision
Definition: ata.h:138
UCHAR ModelNumber[40]
Definition: ata.h:26
USHORT MinorRevision
Definition: ata.h:139
UCHAR Versions
Definition: cdrw_hw.h:1120
UCHAR CommandQueue
Definition: cdrw_hw.h:1125
UCHAR RemovableMedia
Definition: cdrw_hw.h:1119
UCHAR ProductId[16]
Definition: cdrw_hw.h:1133
UCHAR ProductRevisionLevel[4]
Definition: cdrw_hw.h:1134
UCHAR VendorId[8]
Definition: cdrw_hw.h:1132
UCHAR ResponseDataFormat
Definition: cdrw_hw.h:1121
UCHAR DeviceType
Definition: cdrw_hw.h:1116
UCHAR AdditionalLength
Definition: cdrw_hw.h:1122
UCHAR Reserved3[40]
Definition: cdrw_hw.h:1136
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char * PUCHAR
Definition: typedefs.h:53

Referenced by AtaPdoInit().

◆ AtaDeviceFlushPowerIrpQueue()

VOID AtaDeviceFlushPowerIrpQueue ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt)

Definition at line 37 of file dev_power.c.

39{
40 while (TRUE)
41 {
43 PIRP PowerIrp;
44 KIRQL OldLevel;
45
46 KeAcquireSpinLock(&DevExt->Device.QueueLock, &OldLevel);
47 if (IsListEmpty(&DevExt->PowerIrpQueueList))
48 Entry = NULL;
49 else
50 Entry = RemoveHeadList(&DevExt->PowerIrpQueueList);
51 KeReleaseSpinLock(&DevExt->Device.QueueLock, OldLevel);
52
53 if (!Entry)
54 break;
55
56 PowerIrp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
58 AtaPowerCompleteIrp(&DevExt->Common, PowerIrp, STATUS_NO_SUCH_DEVICE);
59 }
60}
static NTSTATUS AtaPowerCompleteIrp(_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp, _In_ NTSTATUS Status)
Definition: dev_power.c:21
#define TRUE
Definition: types.h:120
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
#define ASSERT(a)
Definition: mode.c:44
Entry
Definition: section.c:5216
Definition: typedefs.h:120
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define STATUS_NO_SUCH_DEVICE
Definition: udferr_usr.h:136

Referenced by AtaPortExitStateMachine().

◆ AtaDeviceGetFlushCacheCommand()

UCHAR AtaDeviceGetFlushCacheCommand ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt)

Definition at line 63 of file dev_power.c.

65{
66 UCHAR Command = 0;
67
68 if (!IS_ATAPI(&DevExt->Device))
69 {
70 if ((DevExt->Device.DeviceFlags & DEVICE_LBA48) &&
71 AtaDevHasFlushCacheExt(&DevExt->IdentifyDeviceData))
72 {
74 }
75 else if (AtaDevHasFlushCache(&DevExt->IdentifyDeviceData))
76 {
78 }
79 }
80
81 return Command;
82}
#define IDE_COMMAND_FLUSH_CACHE_EXT
Definition: ata.h:699
#define DEVICE_LBA48
Definition: atapi.h:84
#define IS_ATAPI(Device)
Definition: atapi.h:176
FORCEINLINE BOOLEAN AtaDevHasFlushCache(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
FORCEINLINE BOOLEAN AtaDevHasFlushCacheExt(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
Definition: shell.h:41
#define IDE_COMMAND_FLUSH_CACHE
Definition: atapi.h:401

Referenced by AtaDeviceFlushCache(), and AtaReqScsiSynchronizeCache().

◆ AtaDeviceQueueEvent()

Definition at line 992 of file portstate.c.

996{
998
999 TRACE("New action %lu\n", Action);
1000
1001 OldIrql = KeAcquireInterruptSpinLock(PortData->InterruptObject);
1002 AtaPortQueueEvent(PortData, DevExt, NULL, Action);
1003 KeReleaseInterruptSpinLock(PortData->InterruptObject, OldIrql);
1004}
KIRQL NTAPI KeAcquireInterruptSpinLock(IN PKINTERRUPT Interrupt)
Definition: spinlock.c:154
VOID NTAPI KeReleaseInterruptSpinLock(IN PKINTERRUPT Interrupt, IN KIRQL OldIrql)
Definition: spinlock.c:171
static VOID AtaPortQueueEvent(_In_ PATAPORT_PORT_DATA PortData, _In_opt_ PATAPORT_DEVICE_EXTENSION DevExt, _In_opt_ PATA_DEVICE_REQUEST FailedRequest, _In_ ATA_PORT_ACTION Action)
Definition: portstate.c:16
_In_ WDFIOTARGET _In_ _Strict_type_match_ WDF_IO_TARGET_SENT_IO_ACTION Action
Definition: wdfiotarget.h:510
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778

Referenced by AtaFdoEnumeratePort(), AtaFdoQueryDeviceCount(), AtaFdoQueryDeviceStatus(), AtaPdoQueuePowerIrp(), and AtaPdoStartDevice().

◆ AtaDeviceSendIdentify()

NTSTATUS AtaDeviceSendIdentify ( _In_ PATAPORT_PORT_DATA  PortData,
_In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ UCHAR  Command 
)

Definition at line 45 of file dev_identify.c.

49{
50 PATA_DEVICE_REQUEST Request = &PortData->Worker.InternalRequest;
51
52 TRACE("CH %lu: Send %s identify device %u\n",
53 PortData->PortNumber,
54 Command == IDE_COMMAND_IDENTIFY ? "ATA" : "ATAPI",
55 DevExt->Device.AtaScsiAddress.TargetId);
56
57 /*
58 * For PATA devices, disable interrupts for the identify command and use polling instead.
59 *
60 * On some single device 1 configurations or non-existent IDE channels
61 * the status register stuck permanently at a value of 0,
62 * and we incorrectly assume that the device is present.
63 * This will result in a taskfile timeout
64 * which must be avoided as it would cause hangs at boot time.
65 */
67
69 Request->TimeOut = 10;
70 Request->DataTransferLength = sizeof(DevExt->IdentifyDeviceData);
71
72 RtlZeroMemory(&Request->TaskFile, sizeof(Request->TaskFile));
73 Request->TaskFile.Command = Command;
74
75 return AtaPortSendRequest(PortData, DevExt);
76}
#define REQUEST_FLAG_HAS_LOCAL_BUFFER
Definition: ata_shared.h:327
#define REQUEST_FLAG_DATA_IN
Definition: ata_shared.h:287
#define REQUEST_FLAG_POLL
Definition: ata_shared.h:353
NTSTATUS AtaPortSendRequest(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: portstate.c:831
#define IDE_COMMAND_IDENTIFY
Definition: atapi.h:118
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
_In_ WDFREQUEST Request
Definition: wdfdevice.h:547

Referenced by AtaPortDeviceProcessConfig(), and AtaPortIdentifyDevice().

◆ AtaDeviceSetAddressingMode()

VOID AtaDeviceSetAddressingMode ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt)

Definition at line 182 of file enum.c.

184{
185 PIDENTIFY_DEVICE_DATA IdentifyData = &DevExt->IdentifyDeviceData;
186 ULONG64 TotalSectors;
187
188 DevExt->Device.DeviceFlags &= ~(DEVICE_LBA_MODE | DEVICE_LBA48 | DEVICE_HAS_FUA);
189
190 /* Using LBA addressing mode */
191 if (AtaDevHasLbaTranslation(IdentifyData))
192 {
193 DevExt->Device.DeviceFlags |= DEVICE_LBA_MODE;
194
195 if (AtaDevHas48BitAddressFeature(IdentifyData))
196 {
197 /* Using LBA48 addressing mode */
198 TotalSectors = AtaDevUserAddressableSectors48Bit(IdentifyData);
199 ASSERT(TotalSectors <= ATA_MAX_LBA_48);
200
201 DevExt->Device.DeviceFlags |= DEVICE_LBA48;
202
203 if (AtaDevHasForceUnitAccessCommands(IdentifyData))
204 DevExt->Device.DeviceFlags |= DEVICE_HAS_FUA;
205 }
206 else
207 {
208 /* Using LBA28 addressing mode */
209 TotalSectors = AtaDevUserAddressableSectors28Bit(IdentifyData);
210 ASSERT(TotalSectors <= ATA_MAX_LBA_28);
211 }
212 }
213 else
214 {
215 USHORT Cylinders, Heads, SectorsPerTrack;
216
217 /* Using CHS addressing mode */
218 if (AtaDevIsCurrentGeometryValid(IdentifyData))
219 {
220 AtaDevCurrentChsTranslation(IdentifyData, &Cylinders, &Heads, &SectorsPerTrack);
221 }
222 else
223 {
224 AtaDevDefaultChsTranslation(IdentifyData, &Cylinders, &Heads, &SectorsPerTrack);
225 }
226 DevExt->Device.Cylinders = Cylinders;
227 DevExt->Device.Heads = Heads;
228 DevExt->Device.SectorsPerTrack = SectorsPerTrack;
229
230 TotalSectors = (ULONG64)Cylinders * Heads * SectorsPerTrack;
231 }
232
233 /*
234 * The sector count can be 0 on faulty devices. It's better to keep
235 * them available in the system to allow
236 * the user to send any command to the drive through the pass-through interface.
237 */
238 if (TotalSectors == 0)
239 {
240 ERR("Unknown geometry\n");
241
242 /* Fix up sector count for the READ CAPACITY command */
243 TotalSectors = 1;
244
245 /* Avoid dividing by zero in READ/WRITE commands */
246 DevExt->Device.SectorsPerTrack = 1;
247 DevExt->Device.Heads = 1;
248 }
249
250 DevExt->Device.TotalSectors = TotalSectors;
251
252 DevExt->Device.SectorSize = AtaDevBytesPerLogicalSector(IdentifyData);
253 ASSERT(DevExt->Device.SectorSize >= ATA_MIN_SECTOR_SIZE);
254 DevExt->Device.SectorSize = max(DevExt->Device.SectorSize, ATA_MIN_SECTOR_SIZE);
255
256 INFO("Total sectors %I64u of size %lu, CHS %u:%u:%u\n",
257 DevExt->Device.TotalSectors,
258 DevExt->Device.SectorSize,
259 DevExt->Device.Cylinders,
260 DevExt->Device.Heads,
261 DevExt->Device.SectorsPerTrack);
262}
#define ATA_MIN_SECTOR_SIZE
256 sectors of 512 bytes (128 kB).
Definition: ata_shared.h:24
#define DEVICE_HAS_FUA
Definition: atapi.h:85
#define DEVICE_LBA_MODE
Definition: atapi.h:83
#define ERR(fmt,...)
Definition: precomp.h:57
#define INFO
Definition: debug.h:89
FORCEINLINE VOID AtaDevDefaultChsTranslation(_In_ PIDENTIFY_DEVICE_DATA IdentifyData, _Out_ PUSHORT Cylinders, _Out_ PUSHORT Heads, _Out_ PUSHORT SectorsPerTrack)
Definition: hwidep.h:290
FORCEINLINE ULONG AtaDevBytesPerLogicalSector(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
Definition: hwidep.h:362
#define ATA_MAX_LBA_48
Definition: hwidep.h:50
FORCEINLINE BOOLEAN AtaDevHas48BitAddressFeature(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
Definition: hwidep.h:262
FORCEINLINE ULONG64 AtaDevUserAddressableSectors48Bit(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
Definition: hwidep.h:253
FORCEINLINE BOOLEAN AtaDevHasLbaTranslation(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
Definition: hwidep.h:235
FORCEINLINE ULONG AtaDevUserAddressableSectors28Bit(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
Definition: hwidep.h:244
#define ATA_MAX_LBA_28
Definition: hwidep.h:49
FORCEINLINE BOOLEAN AtaDevIsCurrentGeometryValid(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
Definition: hwidep.h:277
FORCEINLINE VOID AtaDevCurrentChsTranslation(_In_ PIDENTIFY_DEVICE_DATA IdentifyData, _Out_ PUSHORT Cylinders, _Out_ PUSHORT Heads, _Out_ PUSHORT SectorsPerTrack)
Definition: hwidep.h:308
FORCEINLINE BOOLEAN AtaDevHasForceUnitAccessCommands(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
unsigned __int64 ULONG64
Definition: imports.h:198
#define max(a, b)
Definition: svc.c:63
_In_ ULONG _In_ ULONG SectorsPerTrack
Definition: iofuncs.h:2071

Referenced by AtaPdoInit(), and AtaReqCompleteReadCapacity().

◆ AtaFdoDeviceListInsert()

DECLSPEC_NOINLINE_FROM_PAGED VOID AtaFdoDeviceListInsert ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ BOOLEAN  DoInsert 
)

Definition at line 699 of file fdo.c.

703{
704 PSINGLE_LIST_ENTRY Entry, PrevEntry;
705 KIRQL OldLevel;
706 ULONG Address = DevExt->Device.AtaScsiAddress.AsULONG;
707
708 PAGED_CODE();
709
710 KeAcquireSpinLock(&ChanExt->PdoListLock, &OldLevel);
711
712 for (Entry = ChanExt->PdoList.Next, PrevEntry = NULL;
713 Entry != NULL;
714 Entry = Entry->Next)
715 {
716 PATAPORT_DEVICE_EXTENSION CurrentDevExt;
717
718 CurrentDevExt = CONTAINING_RECORD(Entry, ATAPORT_DEVICE_EXTENSION, ListEntry);
719
720 if (DoInsert)
721 {
722 if (CurrentDevExt->Device.AtaScsiAddress.AsULONG > Address)
723 break;
724 }
725 else
726 {
727 if (CurrentDevExt->Device.AtaScsiAddress.AsULONG == Address)
728 break;
729 }
730
731 PrevEntry = Entry;
732 }
733
734 /* The device list is ordered by SCSI address (Path:Target:Lun), smallest first */
735 if (PrevEntry)
736 {
737 /* Before the current entry */
738 if (DoInsert)
739 {
740 DevExt->ListEntry.Next = PrevEntry->Next;
741 PrevEntry->Next = &DevExt->ListEntry;
742 }
743 else
744 {
745 PrevEntry->Next = DevExt->ListEntry.Next;
746 }
747 }
748 else
749 {
750 /* In the beginning */
751 if (DoInsert)
752 PushEntryList(&ChanExt->PdoList, &DevExt->ListEntry);
753 else
754 PopEntryList(&DevExt->ListEntry);
755 }
756
757 KeReleaseSpinLock(&ChanExt->PdoListLock, OldLevel);
758}
HRESULT Next([in] ULONG celt, [out, size_is(celt), length_is(*pceltFetched)] STATPROPSETSTG *rgelt, [out] ULONG *pceltFetched)
static WCHAR Address[46]
Definition: ping.c:68
ATAPORT_IO_CONTEXT Device
Definition: atapi.h:457
ATA_SCSI_ADDRESS AtaScsiAddress
Definition: atapi.h:100
Definition: ntbasedef.h:640
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:641
ULONG AsULONG
Definition: atapi.h:69
FORCEINLINE VOID PushEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead, _Inout_ __drv_aliasesMem PSINGLE_LIST_ENTRY Entry)
Definition: rtlfuncs.h:256
FORCEINLINE PSINGLE_LIST_ENTRY PopEntryList(_Inout_ PSINGLE_LIST_ENTRY ListHead)
Definition: rtlfuncs.h:243

Referenced by AtaFdoEnumeratePort(), and AtaPdoRemoveDevice().

◆ AtaFdoFindDeviceByPath()

DECLSPEC_NOINLINE_FROM_PAGED PATAPORT_DEVICE_EXTENSION AtaFdoFindDeviceByPath ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ ATA_SCSI_ADDRESS  AtaScsiAddress,
_In_ PVOID  ReferenceTag 
)

Definition at line 614 of file fdo.c.

618{
621 KIRQL OldLevel;
623
624 KeAcquireSpinLock(&ChanExt->PdoListLock, &OldLevel);
625
626 for (Entry = ChanExt->PdoList.Next; Entry != NULL; Entry = Entry->Next)
627 {
629
630 if (DevExt->Device.AtaScsiAddress.AsULONG != AtaScsiAddress.AsULONG)
631 continue;
632
633 if (DevExt->ReportedMissing || DevExt->RemovalPending)
634 continue;
635
636 if (ReferenceTag)
637 {
638 Status = IoAcquireRemoveLock(&DevExt->Common.RemoveLock, ReferenceTag);
639 if (!NT_SUCCESS(Status))
640 break;
641 }
642
643 Result = DevExt;
644 break;
645 }
646
647 KeReleaseSpinLock(&ChanExt->PdoListLock, OldLevel);
648
649 return Result;
650}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
IO_REMOVE_LOCK RemoveLock
Definition: atapi.h:434
ATAPORT_COMMON_EXTENSION Common
Definition: atapi.h:455
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:409
#define IoAcquireRemoveLock(RemoveLock, Tag)

Referenced by AtaFdoEnumeratePort(), AtaFdoHandleScsiMiniport(), AtaFdoHandleScsiPassthrough(), AtaPdoHandleMiniportSmartVersion(), AtaPortSelectTimings(), and AtaStorageNotificationlDpc().

◆ AtaFdoFindNextDeviceByPath()

DECLSPEC_NOINLINE_FROM_PAGED PATAPORT_DEVICE_EXTENSION AtaFdoFindNextDeviceByPath ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_Inout_ PATA_SCSI_ADDRESS  AtaScsiAddress,
_In_ BOOLEAN  SearchRemoveDev,
_In_ PVOID  ReferenceTag 
)

Definition at line 654 of file fdo.c.

659{
662 KIRQL OldLevel;
664
665 KeAcquireSpinLock(&ChanExt->PdoListLock, &OldLevel);
666
667 for (Entry = ChanExt->PdoList.Next; Entry != NULL; Entry = Entry->Next)
668 {
670
671 if (DevExt->Device.AtaScsiAddress.AsULONG <= AtaScsiAddress->AsULONG)
672 continue;
673
674 if (DevExt->ReportedMissing)
675 continue;
676
677 if (!SearchRemoveDev && DevExt->RemovalPending)
678 continue;
679
680 *AtaScsiAddress = DevExt->Device.AtaScsiAddress;
681
682 if (ReferenceTag)
683 {
684 Status = IoAcquireRemoveLock(&DevExt->Common.RemoveLock, ReferenceTag);
685 if (!NT_SUCCESS(Status))
686 continue;
687 }
688 Result = DevExt;
689 break;
690 }
691
692 KeReleaseSpinLock(&ChanExt->PdoListLock, OldLevel);
693
694 return Result;
695}

Referenced by AtaFdoHandleGetScsiInquiryData(), AtaFdoInitializeDeviceRelations(), AtaFdoQueryBusRelations(), AtaFdoRemoveDevice(), AtaPortEnterStateMachine(), AtaPortEnumeratePort(), AtaPortExitStateMachine(), and AtaPortOnResetNotification().

◆ AtaFdoPnp()

NTSTATUS AtaFdoPnp ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_Inout_ PIRP  Irp 
)

Definition at line 510 of file fdo.c.

513{
515 PIO_STACK_LOCATION IoStack;
516
517 PAGED_CODE();
518
519 INFO("(%p, %p) Ch.%lu %s\n",
520 ChanExt->Common.Self,
521 Irp,
522 ChanExt->DeviceObjectNumber,
524
525 Status = IoAcquireRemoveLock(&ChanExt->Common.RemoveLock, Irp);
526 if (!NT_SUCCESS(Status))
527 {
528 Irp->IoStatus.Status = Status;
530
531 return Status;
532 }
533
535 switch (IoStack->MinorFunction)
536 {
538 {
539 if (!NT_VERIFY(IoForwardIrpSynchronously(ChanExt->Common.LowerDeviceObject, Irp)))
540 {
542 goto CompleteIrp;
543 }
544 Status = Irp->IoStatus.Status;
545 if (!NT_SUCCESS(Status))
546 goto CompleteIrp;
547
548 Status = AtaFdoStartDevice(ChanExt,
549 IoStack->Parameters.
550 StartDevice.AllocatedResourcesTranslated);
551 goto CompleteIrp;
552 }
553
555 Status = AtaFdoStopDevice(ChanExt, Irp);
556 break;
557
560 return AtaFdoRemoveDevice(ChanExt,
561 Irp,
562 (IoStack->MinorFunction == IRP_MN_REMOVE_DEVICE));
563
565 Status = AtaPnpQueryPnpDeviceState(&ChanExt->Common, Irp);
566 break;
567
569 {
570 if (IoStack->Parameters.QueryDeviceRelations.Type != BusRelations)
571 break;
572
574 if (!NT_SUCCESS(Status))
575 goto CompleteIrp;
576
577 Irp->IoStatus.Status = Status;
578 break;
579 }
580
582 Status = AtaPnpQueryDeviceUsageNotification(&ChanExt->Common, Irp);
583 break;
584
589 Irp->IoStatus.Status = STATUS_SUCCESS;
590 break;
591
592 default:
593 break;
594 }
595
597 Status = IoCallDriver(ChanExt->Common.LowerDeviceObject, Irp);
598
599 IoReleaseRemoveLock(&ChanExt->Common.RemoveLock, Irp);
600
601 return Status;
602
604 Irp->IoStatus.Status = Status;
606
607 IoReleaseRemoveLock(&ChanExt->Common.RemoveLock, Irp);
608
609 return Status;
610}
NTSTATUS AtaPnpQueryPnpDeviceState(_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp)
Definition: atapi.c:555
NTSTATUS AtaPnpQueryDeviceUsageNotification(_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp)
Definition: atapi.c:503
NTSTATUS AtaFdoQueryBusRelations(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PIRP Irp)
Definition: enum.c:566
FORCEINLINE PCHAR GetIRPMinorFunctionString(UCHAR MinorFunction)
Definition: driverdbg.h:13
VOID CompleteIrp(IN PIRP Irp, IN NTSTATUS Status, IN ULONG_PTR Information)
Definition: pnp.c:12
static BOOL StartDevice(IN HDEVINFO DeviceInfoSet, IN PSP_DEVINFO_DATA DevInfoData OPTIONAL, IN BOOL bEnable, IN DWORD HardwareProfile OPTIONAL, OUT BOOL *bNeedReboot OPTIONAL)
Definition: wizard.c:173
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
static NTSTATUS AtaFdoRemoveDevice(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PIRP Irp, _In_ BOOLEAN FinalRemove)
Definition: fdo.c:424
static NTSTATUS AtaFdoStopDevice(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PIRP Irp)
Definition: fdo.c:407
NTSTATUS AtaFdoStartDevice(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PCM_RESOURCE_LIST ResourcesTranslated)
Definition: fdo.c:229
union _IO_STACK_LOCATION::@1696 Parameters
struct _IO_STACK_LOCATION::@4454::@4479 QueryDeviceRelations
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2764
#define IRP_MN_CANCEL_STOP_DEVICE
@ BusRelations
Definition: iotypes.h:2154
#define IRP_MN_QUERY_PNP_DEVICE_STATE
#define IRP_MN_START_DEVICE
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
#define IRP_MN_REMOVE_DEVICE
#define IRP_MN_QUERY_DEVICE_RELATIONS
#define IRP_MN_QUERY_STOP_DEVICE
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define IRP_MN_STOP_DEVICE
#define IRP_MN_QUERY_REMOVE_DEVICE
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3304

Referenced by AtaDispatchPnp().

◆ AtaFdoQueryBusRelations()

NTSTATUS AtaFdoQueryBusRelations ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ PIRP  Irp 
)

Definition at line 566 of file enum.c.

569{
570 PDEVICE_RELATIONS DeviceRelations = NULL;
571 ULONG Size, PdoCount;
572 ATA_SCSI_ADDRESS AtaScsiAddress;
573#if DBG
574 LARGE_INTEGER TimeStart, TimeFinish;
575 ULONG EnumTimeMs;
576#endif
577
578 PAGED_CODE();
579
580#if DBG
581 KeQuerySystemTime(&TimeStart);
582#endif
583
584 AtaScsiAddress.AsULONG = 0;
585 while (TRUE)
586 {
588
589 DevExt = AtaFdoFindNextDeviceByPath(ChanExt, &AtaScsiAddress, TRUE, NULL);
590 if (!DevExt)
591 break;
592
593 DevExt->NotPresent = TRUE;
594
595 if (DevExt->Device.AtaScsiAddress.Lun == 0)
596 {
597 AtaGetRegistryKey(ChanExt,
601 MAXULONG);
602 }
603 }
604
605 AtaFdoEnumeratePort(ChanExt);
606
607 PdoCount = 0;
608 AtaScsiAddress.AsULONG = 0;
609 while (TRUE)
610 {
612
613 DevExt = AtaFdoFindNextDeviceByPath(ChanExt, &AtaScsiAddress, TRUE, NULL);
614 if (!DevExt)
615 break;
616
617 if (!DevExt->NotPresent)
618 ++PdoCount;
619 }
620
621 Size = FIELD_OFFSET(DEVICE_RELATIONS, Objects[PdoCount]);
623 if (!DeviceRelations)
624 {
625 ERR("Failed to allocate device relations\n");
626 goto Cleanup;
627 }
628
629 AtaFdoInitializeDeviceRelations(ChanExt, DeviceRelations);
630
631#if DBG
632 KeQuerySystemTime(&TimeFinish);
633 EnumTimeMs = (TimeFinish.QuadPart - TimeStart.QuadPart) / 10000;
634 if (EnumTimeMs >= 5000)
635 {
636 WARN("%lu: QBR request took %lu ms, %lu devices\n",
637 ChanExt->ScsiPortNumber,
638 EnumTimeMs,
639 DeviceRelations->Count);
640 }
641 else
642 {
643 INFO("%lu: QBR request took %lu ms, %lu devices\n",
644 ChanExt->ScsiPortNumber,
645 EnumTimeMs,
646 DeviceRelations->Count);
647 }
648#endif
649
650 Irp->IoStatus.Information = (ULONG_PTR)DeviceRelations;
651 return STATUS_SUCCESS;
652
653Cleanup:
654 if (DeviceRelations)
655 ExFreePoolWithTag(DeviceRelations, ATAPORT_TAG);
656
658}
#define ExAllocatePoolUninitialized
#define DD_ATA_REG_XFER_MODE_ALLOWED
Definition: ata_user.h:14
VOID AtaGetRegistryKey(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ UCHAR TargetId, _In_ PCWSTR KeyName, _Out_ PULONG KeyValue, _In_ ULONG DefaultValue)
Definition: atapi.c:113
DECLSPEC_NOINLINE_FROM_PAGED PATAPORT_DEVICE_EXTENSION AtaFdoFindNextDeviceByPath(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _Inout_ PATA_SCSI_ADDRESS AtaScsiAddress, _In_ BOOLEAN SearchRemoveDev, _In_ PVOID ReferenceTag)
Definition: fdo.c:654
#define ATAPORT_TAG
Definition: atapi.h:171
#define WARN(fmt,...)
Definition: precomp.h:61
static const WCHAR Cleanup[]
Definition: register.c:80
static VOID AtaFdoEnumeratePort(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt)
Definition: enum.c:416
static VOID AtaFdoInitializeDeviceRelations(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PDEVICE_RELATIONS DeviceRelations)
Definition: enum.c:515
#define KeQuerySystemTime(t)
Definition: env_spec_w32.h:570
#define PagedPool
Definition: env_spec_w32.h:308
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
ULONG TransferModeUserAllowedMask
Definition: atapi.h:503
#define MAXULONG
Definition: typedefs.h:251
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
UCHAR TargetId
Definition: atapi.h:60
LONGLONG QuadPart
Definition: typedefs.h:114
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539

Referenced by AtaFdoPnp().

◆ AtaFdoStartDevice()

NTSTATUS AtaFdoStartDevice ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ PCM_RESOURCE_LIST  ResourcesTranslated 
)

Definition at line 229 of file fdo.c.

232{
233 PATAPORT_PORT_DATA PortData = &ChanExt->PortData;
234 PCIIDEX_CHANNEL_INTERFACE ChannelInterface = { 0 };
236
237 PAGED_CODE();
238
239 INFO("Starting channel %lu\n", ChanExt->DeviceObjectNumber);
240
241 /* Get the interface of ATA channel */
242 Status = AtaPnpQueryInterface(&ChanExt->Common,
243 &GUID_PCIIDE_INTERFACE_ROS,
244 &ChannelInterface,
246 sizeof(ChannelInterface));
247 if (!NT_SUCCESS(Status))
248 {
249 ERR("Failed to query channel interface %lx\n", Status);
250 return Status;
251 }
252 PortData->ChannelContext = ChannelInterface.ChannelContext;
253 PortData->AttachChannel = ChannelInterface.AttachChannel;
254 PortData->SetDeviceData = ChannelInterface.SetDeviceData;
255 PortData->GetInitTaskFile = ChannelInterface.GetInitTaskFile;
256 PortData->DowngradeInterfaceSpeed = ChannelInterface.DowngradeInterfaceSpeed;
257 PortData->InterruptObject = ChannelInterface.InterruptObject;
258 PortData->AbortChannel = ChannelInterface.AbortChannel;
259 PortData->ResetChannel = ChannelInterface.ResetChannel;
260 PortData->EnumerateChannel = ChannelInterface.EnumerateChannel;
261 PortData->IdentifyDevice = ChannelInterface.IdentifyDevice;
262 PortData->SetTransferMode = ChannelInterface.SetTransferMode;
263 PortData->AllocateSlot = ChannelInterface.AllocateSlot;
264 PortData->PreparePrdTable = ChannelInterface.PreparePrdTable;
265 PortData->PrepareIo = ChannelInterface.PrepareIo;
266 PortData->StartIo = ChannelInterface.StartIo;
267 PortData->MaxTargetId = ChannelInterface.MaxTargetId;
268 PortData->MaximumTransferLength = ChannelInterface.MaximumTransferLength;
269 PortData->MaximumPhysicalPages = ChannelInterface.MaximumPhysicalPages;
270 PortData->QueueDepth = ChannelInterface.QueueDepth;
271 PortData->PortNumber = ChannelInterface.Channel;
272 PortData->DmaAdapter = ChannelInterface.DmaAdapter;
273 PortData->ChannelObject = ChannelInterface.ChannelObject;
274
276 PortData->FreeSlotsBitmap =
277 PortData->MaxSlotsBitmap = NUM_TO_BITMAP(PortData->QueueDepth);
278 /* We need the slot numbers to start from zero */
279 PortData->LastUsedSlot = RTL_BITS_OF(ULONG) - 1;
280
281 if (!(ChannelInterface.TransferModeSupported & ~PIO_ALL))
282 PortData->PortFlags |= PORT_FLAG_PIO_ONLY;
283
284 if (ChannelInterface.Flags & ATA_CHANNEL_FLAG_PIO_VIA_DMA)
285 PortData->PortFlags |= PORT_FLAG_PIO_VIA_DMA;
286
287 if (ChannelInterface.Flags & ATA_CHANNEL_FLAG_NCQ)
288 PortData->PortFlags |= PORT_FLAG_NCQ;
289
290 if (ChannelInterface.Flags & ATA_CHANNEL_FLAG_IS_AHCI)
291 PortData->PortFlags |= PORT_FLAG_IS_AHCI;
292
293 if (ChannelInterface.Flags & ATA_CHANNEL_FLAG_IS_EXTERNAL)
294 PortData->PortFlags |= PORT_FLAG_IS_EXTERNAL;
295
296 if (ChannelInterface.Flags & ATA_CHANNEL_FLAG_PIO_FOR_LBA48_XFER)
298
299 if (ChannelInterface.HwSyncObject)
300 {
301 PortData->PortFlags |= PORT_FLAG_IS_SIMPLEX;
302 PortData->HwSyncObject = ChannelInterface.HwSyncObject;
303 }
304
305 /* Reserve PIO memory resources early. Storage drivers should not fail paging I/O operations */
306 if (!(ChannelInterface.Flags & ATA_CHANNEL_FLAG_PIO_VIA_DMA) && !PortData->ReservedVaSpace)
307 {
308 PortData->ReservedVaSpace = MmAllocateMappingAddress(ATA_RESERVED_PAGES * PAGE_SIZE,
310 }
311
313 if (!NT_SUCCESS(Status))
314 {
315 ERR("CH %lu: Failed to allocate local buffer 0x%lx\n", PortData->PortNumber, Status);
316 return Status;
317 }
318
321
322 KeInitializeDpc(&PortData->Worker.Dpc, AtaPortWorkerSignalDpc, PortData);
324 KeInitializeSpinLock(&PortData->Worker.Lock);
326
329#if DBG
330 PortData->Worker.InternalRequest.Signature = ATA_DEVICE_REQUEST_SIGNATURE;
331#endif
332
333 Status = AtaFdoCreatePortThread(PortData);
334 if (!NT_SUCCESS(Status))
335 {
336 ERR("CH %lu: Failed to create port thread 0x%lx\n", PortData->PortNumber, Status);
337 return Status;
338 }
339
340 Status = AtaFdoCreateSymLinks(ChanExt);
341 if (!NT_SUCCESS(Status))
342 {
343 ERR("CH %lu: Failed to create symbolic links 0x%lx\n", PortData->PortNumber, Status);
344 return Status;
345 }
346
348
349 Status = IoRegisterDeviceInterface(ChanExt->Common.Self,
350 &GUID_DEVINTERFACE_STORAGEPORT,
351 NULL,
352 &ChanExt->StorageInterfaceName);
353 if (NT_SUCCESS(Status))
354 {
355 INFO("InterfaceName: '%wZ'\n", &ChanExt->StorageInterfaceName);
356
357 Status = IoSetDeviceInterfaceState(&ChanExt->StorageInterfaceName, TRUE);
358 if (!NT_SUCCESS(Status))
359 {
360 RtlFreeUnicodeString(&ChanExt->StorageInterfaceName);
361 ChanExt->StorageInterfaceName.Buffer = NULL;
362 }
363 }
364
365 *ChannelInterface.PortContext = PortData;
366 *ChannelInterface.PortNotification = AtaPortNotification;
367 *ChannelInterface.Slots = PortData->Slots;
368
369 Status = IoInitializeTimer(ChanExt->Common.Self, AtaPortIoTimer, PortData);
370 if (!NT_SUCCESS(Status))
371 return Status;
372
373 IoStartTimer(ChanExt->Common.Self);
375
376 Status = PortData->AttachChannel(PortData->ChannelContext, TRUE);
377 if (!NT_SUCCESS(Status))
378 {
379 ERR("CH %lu: Failed to attach channel %lx\n", PortData->PortNumber, Status);
380 return Status;
381 }
383
384 return STATUS_SUCCESS;
385}
#define PCIIDEX_INTERFACE_VERSION
Definition: ata_shared.h:12
#define ATA_CHANNEL_FLAG_IS_EXTERNAL
Definition: ata_shared.h:536
#define ATA_CHANNEL_FLAG_PIO_VIA_DMA
Definition: ata_shared.h:535
#define ATA_CHANNEL_FLAG_PIO_FOR_LBA48_XFER
Definition: ata_shared.h:539
#define ATA_CHANNEL_FLAG_NCQ
Definition: ata_shared.h:537
#define ATA_CHANNEL_FLAG_IS_AHCI
Definition: ata_shared.h:538
#define PIO_ALL
Definition: ata_user.h:19
#define DD_ATA_REG_MAX_TARGET_ID
Definition: ata_user.h:13
VOID AtaSetPortRegistryKey(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PCWSTR KeyName, _In_ ULONG KeyValue)
Definition: atapi.c:236
NTSTATUS AtaPnpQueryInterface(_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ const GUID *Guid, _Out_ PVOID Interface, _In_ ULONG Version, _In_ ULONG Size)
Definition: atapi.c:396
IO_TIMER_ROUTINE AtaPortIoTimer
Definition: atapi.h:938
#define PORT_FLAG_PIO_FOR_LBA48_XFER
Definition: atapi.h:345
#define PORT_FLAG_PIO_ONLY
Definition: atapi.h:344
#define PORT_FLAG_NCQ
Definition: atapi.h:339
#define PORT_FLAG_PIO_VIA_DMA
Definition: atapi.h:337
#define PORT_INT_FLAG_IS_IO_ACTIVE
Definition: atapi.h:360
KDEFERRED_ROUTINE AtaPortWorkerSignalDpc
Definition: atapi.h:879
#define PORT_FLAG_IO_TIMER_ACTIVE
Definition: atapi.h:342
#define NUM_TO_BITMAP(num)
Definition: atapi.h:179
#define ATA_RESERVED_PAGES
Definition: atapi.h:200
KDEFERRED_ROUTINE AtaStorageNotificationlDpc
Definition: atapi.h:655
#define PORT_FLAG_IS_SIMPLEX
Definition: atapi.h:336
#define PORT_FLAG_IS_AHCI
Definition: atapi.h:340
#define PORT_FLAG_CHANNEL_ATTACHED
Definition: atapi.h:343
REQUEST_COMPLETION_ROUTINE AtaPortCompleteInternalRequest
Definition: atapi.h:880
PORT_NOTIFICATION AtaPortNotification
Definition: atapi.h:881
#define PORT_FLAG_IS_EXTERNAL
Definition: atapi.h:338
#define FALSE
Definition: types.h:117
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define PAGE_SIZE
Definition: env_spec_w32.h:49
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
NTSTATUS NTAPI IoInitializeTimer(IN PDEVICE_OBJECT DeviceObject, IN PIO_TIMER_ROUTINE TimerRoutine, IN PVOID Context)
Definition: iotimer.c:92
VOID NTAPI IoStartTimer(IN PDEVICE_OBJECT DeviceObject)
Definition: iotimer.c:133
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)
#define RTL_BITS_OF(sizeOfArg)
Definition: ntbasedef.h:680
@ NotificationEvent
NTSTATUS NTAPI IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, IN CONST GUID *InterfaceClassGuid, IN PUNICODE_STRING ReferenceString OPTIONAL, OUT PUNICODE_STRING SymbolicLinkName)
Definition: deviface.c:1437
NTSTATUS NTAPI IoSetDeviceInterfaceState(IN PUNICODE_STRING SymbolicLinkName, IN BOOLEAN Enable)
Definition: deviface.c:1793
static NTSTATUS AtaFdoAllocateLocalBuffer(_In_ PATAPORT_PORT_DATA PortData)
Definition: fdo.c:93
static NTSTATUS AtaFdoCreateSymLinks(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt)
Definition: fdo.c:22
static NTSTATUS AtaFdoCreatePortThread(_In_ PATAPORT_PORT_DATA PortData)
Definition: fdo.c:129
PCHANNEL_SET_MODE SetTransferMode
Definition: atapi.h:386
PVOID ChannelContext
Definition: atapi.h:348
PCHANNEL_ENUMERATE_CHANNEL EnumerateChannel
Definition: atapi.h:384
ULONG MaximumPhysicalPages
Definition: atapi.h:393
ULONG LastUsedSlot
Definition: atapi.h:367
PDMA_ADAPTER DmaAdapter
Definition: atapi.h:353
PDEVICE_OBJECT ChannelObject
Definition: atapi.h:354
ULONG MaximumTransferLength
Definition: atapi.h:392
ULONG FreeSlotsBitmap
Definition: atapi.h:366
PCHANNEL_IDENTIFY_DEVICE IdentifyDevice
Definition: atapi.h:385
PCHANNEL_PREPARE_PRD_TABLE PreparePrdTable
Definition: atapi.h:350
PCHANNEL_SET_DEVICE_DATA SetDeviceData
Definition: atapi.h:387
PATA_DEVICE_REQUEST Slots[MAX_SLOTS]
Definition: atapi.h:355
KEVENT QueueStoppedEvent
Definition: atapi.h:391
PCHANNEL_GET_INIT_TASK_FILE GetInitTaskFile
Definition: atapi.h:388
PCHANNEL_START_IO StartIo
Definition: atapi.h:352
PCHANNEL_ABORT_CHANNEL AbortChannel
Definition: atapi.h:382
PCHANNEL_RESET_CHANNEL ResetChannel
Definition: atapi.h:383
volatile LONG InterruptFlags
Definition: atapi.h:359
PCHANNEL_PREPARE_IO PrepareIo
Definition: atapi.h:351
PCHANNEL_DOWNGRADE_INTERFACE_SPEED DowngradeInterfaceSpeed
Definition: atapi.h:389
ULONG PortNumber
Definition: atapi.h:396
ULONG MaxSlotsBitmap
Definition: atapi.h:397
PKINTERRUPT InterruptObject
Definition: atapi.h:357
ULONG PortFlags
Definition: atapi.h:335
ATA_WORKER_CONTEXT Worker
Definition: atapi.h:400
PCONTROLLER_ATTACH_CHANNEL AttachChannel
Definition: atapi.h:390
PCHANNEL_ALLOCATE_SLOT AllocateSlot
Definition: atapi.h:349
ULONG QueueDepth
Definition: atapi.h:395
LIST_ENTRY PortQueueList
Definition: atapi.h:364
PCONTROLLER_OBJECT HwSyncObject
Definition: atapi.h:381
ULONG MaxTargetId
Definition: atapi.h:394
PVOID ReservedVaSpace
Definition: atapi.h:380
PREQUEST_COMPLETION_ROUTINE Complete
Definition: ata_shared.h:230
ATA_DEVICE_REQUEST InternalRequest
Definition: atapi.h:291
KEVENT EnumerationEvent
Definition: atapi.h:293
KEVENT CompletionEvent
Definition: atapi.h:290
KSPIN_LOCK Lock
Definition: atapi.h:273
KDPC NotificationDpc
Definition: atapi.h:294
Channel interface with the PCIIDEX driver.
Definition: ata_shared.h:502
PPORT_NOTIFICATION * PortNotification
Definition: ata_shared.h:542
PCHANNEL_SET_MODE SetTransferMode
Definition: ata_shared.h:526
PCHANNEL_ALLOCATE_SLOT AllocateSlot
Definition: ata_shared.h:527
PCHANNEL_RESET_CHANNEL ResetChannel
Definition: ata_shared.h:523
PCHANNEL_DOWNGRADE_INTERFACE_SPEED DowngradeInterfaceSpeed
Definition: ata_shared.h:521
PCHANNEL_IDENTIFY_DEVICE IdentifyDevice
Definition: ata_shared.h:525
PCHANNEL_GET_INIT_TASK_FILE GetInitTaskFile
Definition: ata_shared.h:520
PCHANNEL_ABORT_CHANNEL AbortChannel
Definition: ata_shared.h:522
PCHANNEL_SET_DEVICE_DATA SetDeviceData
Definition: ata_shared.h:519
PCHANNEL_START_IO StartIo
Definition: ata_shared.h:530
PCONTROLLER_OBJECT HwSyncObject
Definition: ata_shared.h:531
PCHANNEL_PREPARE_IO PrepareIo
Definition: ata_shared.h:529
PCONTROLLER_ATTACH_CHANNEL AttachChannel
Definition: ata_shared.h:511
PCHANNEL_PREPARE_PRD_TABLE PreparePrdTable
Definition: ata_shared.h:528
PATA_DEVICE_REQUEST ** Slots
Definition: ata_shared.h:543
PDEVICE_OBJECT ChannelObject
Definition: ata_shared.h:533
PCHANNEL_ENUMERATE_CHANNEL EnumerateChannel
Definition: ata_shared.h:524

Referenced by AtaFdoPnp().

◆ AtaGetRegistryKey()

VOID AtaGetRegistryKey ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ UCHAR  TargetId,
_In_ PCWSTR  KeyName,
_Out_ PULONG  KeyValue,
_In_ ULONG  DefaultValue 
)

Definition at line 113 of file atapi.c.

119{
120 UCHAR Buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(*KeyValue)];
121 HANDLE HwKeyHandle, TargetKeyHandle;
122 UNICODE_STRING ValueName, TargetKeyName;
124 WCHAR TargetKeyBuffer[sizeof("Target99")];
127
128 PAGED_CODE();
129
130 Status = IoOpenDeviceRegistryKey(ChanExt->Pdo,
133 &HwKeyHandle);
134 if (!NT_SUCCESS(Status))
135 {
136 TRACE("Failed to open device hardware key, status 0x%lx\n", Status);
137 return;
138 }
139
140 /* Open or create the 'TargetX' key */
141 Status = RtlStringCbPrintfW(TargetKeyBuffer,
142 sizeof(TargetKeyBuffer),
143 L"Target%u",
144 TargetId);
146 RtlInitUnicodeString(&TargetKeyName, TargetKeyBuffer);
147 Status = AtaOpenRegistryKey(&TargetKeyHandle, HwKeyHandle, &TargetKeyName, TRUE);
148 if (!NT_SUCCESS(Status))
149 {
150 TRACE("Failed to create '%wZ' key, status 0x%lx\n", &TargetKeyName, Status);
151 goto Cleanup;
152 }
153
155 Status = ZwQueryValueKey(TargetKeyHandle,
156 &ValueName,
158 PartialInfo,
159 sizeof(Buffer),
160 &ResultLength);
161 ZwClose(TargetKeyHandle);
162 if (!NT_SUCCESS(Status) ||
163 (PartialInfo->Type != REG_DWORD) ||
164 (PartialInfo->DataLength != sizeof(*KeyValue)))
165 {
166 TRACE("Failed to read '%wZ' key, status 0x%lx\n", &ValueName, Status);
167
168 *KeyValue = DefaultValue;
169 goto Cleanup;
170 }
171
172 *KeyValue = *(PULONG)&PartialInfo->Data;
173
174Cleanup:
175 ZwClose(HwKeyHandle);
176}
NTSTATUS AtaOpenRegistryKey(_Out_ PHANDLE KeyHandle, _In_ HANDLE RootKey, _In_ PUNICODE_STRING KeyName, _In_ BOOLEAN Create)
Definition: atapi.c:75
Definition: bufpool.h:45
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR TargetId
Definition: classpnp.h:1314
#define L(x)
Definition: resources.c:13
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
@ KeyValuePartialInformation
Definition: nt_native.h:1185
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:1620
#define REG_DWORD
Definition: sdbapi.c:615
uint32_t * PULONG
Definition: typedefs.h:59
void * PVOID
Definition: typedefs.h:50
UCHAR DefaultValue
Definition: via.c:137
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3782
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786

Referenced by AtaFdoEnumeratePort(), AtaFdoQueryBusRelations(), and AtaPdoInit().

◆ AtaMarshallScsiAddress()

FORCEINLINE ATA_SCSI_ADDRESS AtaMarshallScsiAddress ( _In_ ULONG  PathId,
_In_ ULONG  TargetId,
_In_ ULONG  Lun 
)

Definition at line 585 of file atapi.h.

589{
590 ATA_SCSI_ADDRESS AtaScsiAddress;
591
592 AtaScsiAddress.Lun = Lun;
593 AtaScsiAddress.TargetId = TargetId;
594 AtaScsiAddress.PathId = PathId;
595
596 /* This is used for address comparison. See AtaFdoFindNextDeviceByPath() */
597 AtaScsiAddress.IsValid = 0xAA;
598
599 return AtaScsiAddress;
600}
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR _In_ UCHAR Lun
Definition: classpnp.h:1315
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR PathId
Definition: classpnp.h:1313
UCHAR PathId
Definition: atapi.h:65
UCHAR IsValid
Definition: atapi.h:67

Referenced by AtaFdoEnumeratePort(), AtaFdoHandleScsiMiniport(), AtaFdoHandleScsiPassthrough(), AtaPdoHandleMiniportSmartVersion(), AtaPortSelectTimings(), and AtaStorageNotificationlDpc().

◆ AtaOpenRegistryKey()

NTSTATUS AtaOpenRegistryKey ( _Out_ PHANDLE  KeyHandle,
_In_ HANDLE  RootKey,
_In_ PUNICODE_STRING  KeyName,
_In_ BOOLEAN  Create 
)

Definition at line 75 of file atapi.c.

80{
84
85 PAGED_CODE();
86
88 KeyName,
90 RootKey,
91 NULL);
92
93 if (Create)
94 {
95 Status = ZwCreateKey(KeyHandle,
98 0,
99 NULL,
101 &Disposition);
102 }
103 else
104 {
106 }
107
108 return Status;
109}
@ Create
Definition: registry.c:563
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
static PMEMKEY RootKey
Definition: registry.c:55

Referenced by AtaGetRegistryKey(), and AtaSetRegistryKey().

◆ AtaPacketCommandUseDma()

FORCEINLINE BOOLEAN AtaPacketCommandUseDma ( _In_ UCHAR  OpCode)

Definition at line 613 of file atapi.h.

615{
616 return (OpCode == SCSIOP_READ6 ||
618 OpCode == SCSIOP_READ ||
619 OpCode == SCSIOP_WRITE ||
626}
#define SCSIOP_READ_CD
Definition: cdrw_hw.h:967
#define SCSIOP_WRITE6
Definition: cdrw_hw.h:876
#define SCSIOP_WRITE
Definition: cdrw_hw.h:906
#define SCSIOP_READ6
Definition: cdrw_hw.h:874
#define SCSIOP_READ12
Definition: cdrw_hw.h:956
#define SCSIOP_WRITE12
Definition: cdrw_hw.h:957
#define SCSIOP_READ_CD_MSF
Definition: cdrw_hw.h:964
#define SCSIOP_READ
Definition: cdrw_hw.h:905
OpCode
Definition: dlist.c:229
#define SCSIOP_READ16
Definition: scsi.h:914
#define SCSIOP_WRITE16
Definition: scsi.h:915

Referenced by AtaReqPreparePacketCommand().

◆ AtaPdoCreateDevice()

PATAPORT_DEVICE_EXTENSION AtaPdoCreateDevice ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ ATA_SCSI_ADDRESS  AtaScsiAddress 
)

Definition at line 685 of file pdo.c.

688{
689 PATAPORT_PORT_DATA PortData = &ChanExt->PortData;
694 WCHAR DeviceNameBuffer[sizeof("\\Device\\Ide\\IdeDeviceP99999T9L9-FFF")];
695 ULONG i;
696 DECLARE_PAGED_WSTRING(PdoFormat, L"\\Device\\Ide\\IdeDeviceP%luT%luL%lu-%lx");
697 static ULONG AtapPdoNumber = 0;
698
699 PAGED_CODE();
700
701 Status = RtlStringCbPrintfW(DeviceNameBuffer,
702 sizeof(DeviceNameBuffer),
703 PdoFormat,
704 ChanExt->DeviceObjectNumber,
705 AtaScsiAddress.TargetId,
706 AtaScsiAddress.Lun,
707 AtapPdoNumber++);
709 RtlInitUnicodeString(&DeviceName, DeviceNameBuffer);
710
711 Status = IoCreateDevice(ChanExt->Common.Self->DriverObject,
712 sizeof(*DevExt),
713 &DeviceName,
716 FALSE,
717 &Pdo);
718 if (!NT_SUCCESS(Status))
719 {
720 ERR("Failed to create PDO '%wZ' with status 0x%lx\n", &DeviceName, Status);
721 return NULL;
722 }
723
724 INFO("Created device object %p '%wZ'\n", Pdo, &DeviceName);
725
726 /* DMA buffers alignment */
727 Pdo->AlignmentRequirement = ChanExt->Common.Self->AlignmentRequirement;
728 Pdo->AlignmentRequirement = max(Pdo->AlignmentRequirement, ATA_MIN_BUFFER_ALIGNMENT);
729
730 Pdo->Flags |= DO_DIRECT_IO;
731
732 DevExt = Pdo->DeviceExtension;
733
734 RtlZeroMemory(DevExt, sizeof(*DevExt));
735 AtaPnpInitializeCommonExtension(&DevExt->Common, Pdo, ChanExt->Common.Flags & ~DO_IS_FDO);
736 DevExt->Common.FdoExt = ChanExt;
738 DevExt->Device.SectorSize = ATA_MIN_SECTOR_SIZE;
739 DevExt->Device.PortData = PortData;
740 DevExt->Device.LocalBuffer = PortData->LocalBuffer;
741
742 DevExt->Device.AtaScsiAddress = AtaScsiAddress;
743 DevExt->Device.TransportFlags = AtaScsiAddress.TargetId;
744 DevExt->Device.DeviceSelect = IDE_DRIVE_SELECT | AtaScsiAddress.Lun;
745
746 if (!(PortData->PortFlags & PORT_FLAG_IS_AHCI))
747 {
748 /* Master/Slave select bit */
749 DevExt->Device.DeviceSelect |= ((AtaScsiAddress.TargetId & 1) << 4);
750 }
751
753
754 if (PortData->PortFlags & PORT_FLAG_IS_EXTERNAL)
756
757 if (PortData->PortFlags & PORT_FLAG_PIO_VIA_DMA)
759
762
763 /* Device's capability not explored, yet */
765
766 DevExt->Device.FreeRequestsBitmap =
768
770 sizeof(ATA_DEVICE_REQUEST) * PortData->QueueDepth,
772 if (!DevExt->Device.Requests)
773 goto Failure;
774
775 for (i = 0; i < PortData->QueueDepth; ++i)
776 {
778
780#if DBG
781 Request->Signature = ATA_DEVICE_REQUEST_SIGNATURE;
782#endif
783 }
784
791
792 return DevExt;
793
794Failure:
795 AtaPdoFreeDevice(DevExt);
796
797 return NULL;
798}
struct _ATA_IO_CONTEXT_COMMON * PATA_IO_CONTEXT_COMMON
#define ATA_MIN_BUFFER_ALIGNMENT
Definition: ata_shared.h:30
VOID AtaPnpInitializeCommonExtension(_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PDEVICE_OBJECT SelfDeviceObject, _In_ ULONG Flags)
Definition: atapi.c:572
#define DEVICE_PIO_ONLY
Definition: atapi.h:82
#define DO_IS_FDO
Definition: atapi.h:430
#define DEVICE_IS_PDO_REMOVABLE
Definition: atapi.h:90
#define DECLARE_PAGED_WSTRING(v, n)
Definition: atapi.h:162
#define DEVICE_PIO_FOR_LBA48_XFER
Definition: atapi.h:95
#define DEVICE_UNINITIALIZED
Definition: atapi.h:91
#define DEVICE_PIO_VIA_DMA
Definition: atapi.h:94
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define DO_DIRECT_IO
Definition: env_spec_w32.h:396
#define NonPagedPool
Definition: env_spec_w32.h:307
#define IDE_DRIVE_SELECT
Definition: hwidep.h:56
#define FILE_DEVICE_MASS_STORAGE
Definition: imports.h:60
static PVOID ExAllocatePoolZero(ULONG PoolType, SIZE_T NumberOfBytes, ULONG Tag)
Definition: precomp.h:45
#define DBG(x)
Definition: moztest.c:12
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1032
VOID AtaPdoFreeDevice(_In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: pdo.c:658
ATA_WORKER_DEVICE_CONTEXT Worker
Definition: atapi.h:458
LIST_ENTRY PowerIrpQueueList
Definition: atapi.h:469
ULONG TransferModeAllowedMask
Definition: atapi.h:533
PATAPORT_PORT_DATA PortData
Definition: atapi.h:101
LIST_ENTRY DeviceQueueList
Definition: atapi.h:133
ULONG DeviceFlags
Definition: atapi.h:81
ULONG FreeRequestsBitmap
Definition: atapi.h:131
PATA_DEVICE_REQUEST Requests
Definition: atapi.h:132
KEVENT QueueStoppedEvent
Definition: atapi.h:134
PVOID LocalBuffer
Definition: atapi.h:99
KSPIN_LOCK QueueLock
Definition: atapi.h:102
ULONG MaxRequestsBitmap
Definition: atapi.h:130
PVOID LocalBuffer
Definition: atapi.h:398
PATA_IO_CONTEXT_COMMON Device
Definition: ata_shared.h:223
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281
WDF_EXTERN_C_START typedef _Must_inspect_result_ _In_ WDFDRIVER _In_opt_ PWDF_OBJECT_ATTRIBUTES _In_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT _In_opt_ PDEVICE_OBJECT Pdo
Definition: wdfminiport.h:72

Referenced by AtaFdoEnumeratePort().

◆ AtaPdoFreeDevice()

VOID AtaPdoFreeDevice ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt)

Definition at line 658 of file pdo.c.

660{
661 PAGED_CODE();
662
663 if (DevExt->Device.PowerIdleCounter)
664 {
665 PoRegisterDeviceForIdleDetection(DevExt->Common.Self,
666 0,
667 0,
669 }
670
671 if (DevExt->GtfDataBuffer)
672 {
673 ExFreePoolWithTag(DevExt->GtfDataBuffer, ATAPORT_TAG);
674 DevExt->GtfDataBuffer = NULL;
675 }
676
677 if (DevExt->Device.Requests)
678 ExFreePoolWithTag(DevExt->Device.Requests, ATAPORT_TAG);
679
680 IoDeleteDevice(DevExt->Common.Self);
681}
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1252
PULONG NTAPI PoRegisterDeviceForIdleDetection(IN PDEVICE_OBJECT DeviceObject, IN ULONG ConservationIdleTime, IN ULONG PerformanceIdleTime, IN DEVICE_POWER_STATE State)
Definition: power.c:633
@ PowerDeviceD3
Definition: ntpoapi.h:52

Referenced by AtaFdoEnumeratePort(), AtaFdoRemoveDevice(), AtaPdoCreateDevice(), and AtaPdoRemoveDevice().

◆ AtaPdoHandleMiniportIdentify()

NTSTATUS AtaPdoHandleMiniportIdentify ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ PSCSI_REQUEST_BLOCK  Srb 
)

Definition at line 207 of file smart.c.

210{
211 union _PARAMS
212 {
213 PSENDCMDINPARAMS CmdIn;
214 PSENDCMDOUTPARAMS CmdOut;
215 } Buffer;
216
217 PAGED_CODE();
218
220 (sizeof(SRB_IO_CONTROL) + sizeof(*Buffer.CmdOut) - 1 + IDENTIFY_BUFFER_SIZE))
221 {
224 }
225
227
228 if (IS_ATAPI(&DevExt->Device) || (Buffer.CmdIn->irDriveRegs.bCommandReg != ID_CMD))
229 {
232 }
233
234 Buffer.CmdOut->cBufferSize = IDENTIFY_BUFFER_SIZE;
235 Buffer.CmdOut->DriverStatus.bDriverError = 0;
236 Buffer.CmdOut->DriverStatus.bIDEError = 0;
237
238 RtlCopyMemory(Buffer.CmdOut->bBuffer, &DevExt->IdentifyDeviceData, IDENTIFY_BUFFER_SIZE);
239
241 return STATUS_SUCCESS;
242}
#define ID_CMD
Definition: helper.h:20
struct _SENDCMDINPARAMS * PSENDCMDINPARAMS
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
#define SRB_STATUS_SUCCESS
Definition: srb.h:341
#define SRB_STATUS_INVALID_REQUEST
Definition: srb.h:346
#define IDENTIFY_BUFFER_SIZE
Definition: ntdddisk.h:727
struct _SRB_IO_CONTROL SRB_IO_CONTROL
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
PVOID DataBuffer
Definition: srb.h:263
ULONG DataTransferLength
Definition: srb.h:261
UCHAR SrbStatus
Definition: srb.h:251
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138

Referenced by AtaPdoHandleIoControl().

◆ AtaPdoHandleMiniportSmartVersion()

NTSTATUS AtaPdoHandleMiniportSmartVersion ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ PSCSI_REQUEST_BLOCK  Srb 
)

Definition at line 246 of file smart.c.

249{
250 PATAPORT_CHANNEL_EXTENSION ChanExt = DevExt->Common.FdoExt;
251 PATAPORT_PORT_DATA PortData = &ChanExt->PortData;
252 PGETVERSIONINPARAMS VersionParameters;
253 ULONG i;
254
255 PAGED_CODE();
256
257 if (Srb->DataTransferLength < (sizeof(*VersionParameters) + sizeof(SRB_IO_CONTROL)))
258 {
261 }
262
263 VersionParameters = (PGETVERSIONINPARAMS)(((PUCHAR)Srb->DataBuffer) + sizeof(SRB_IO_CONTROL));
264
265 /* SMART 1.03 */
266 VersionParameters->bVersion = 1;
267 VersionParameters->bRevision = 1;
268 VersionParameters->bReserved = 0;
269
271
272 VersionParameters->bIDEDeviceMap = 0;
273
274 /* Emulate the PATA behavior */
275 for (i = 0; i < MAX_IDE_DEVICE; ++i)
276 {
278 ULONG DeviceFlag;
279
280 DevExt = AtaFdoFindDeviceByPath(ChanExt,
281 AtaMarshallScsiAddress(PortData->PortNumber, i, 0),
282 Srb);
283 if (!DevExt)
284 continue;
285
286 DeviceFlag = 1 << i;
287 if (PortData->PortNumber != 0)
288 DeviceFlag <<= 2;
289 if (IS_ATAPI(&DevExt->Device))
290 DeviceFlag <<= 4;
291 VersionParameters->bIDEDeviceMap |= DeviceFlag;
292
294 }
295
297 return STATUS_SUCCESS;
298}
FORCEINLINE ATA_SCSI_ADDRESS AtaMarshallScsiAddress(_In_ ULONG PathId, _In_ ULONG TargetId, _In_ ULONG Lun)
Definition: atapi.h:585
DECLSPEC_NOINLINE_FROM_PAGED PATAPORT_DEVICE_EXTENSION AtaFdoFindDeviceByPath(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ ATA_SCSI_ADDRESS AtaScsiAddress, _In_ PVOID ReferenceTag)
Definition: fdo.c:614
#define MAX_IDE_DEVICE
Definition: ide.h:32
#define CAP_ATAPI_ID_CMD
Definition: ntdddisk.h:657
struct _GETVERSIONINPARAMS * PGETVERSIONINPARAMS
#define CAP_ATA_ID_CMD
Definition: ntdddisk.h:656
#define CAP_SMART_CMD
Definition: ntdddisk.h:658
ATAPORT_PORT_DATA PortData
Definition: atapi.h:442
ATAPORT_COMMON_EXTENSION Common
Definition: atapi.h:440

Referenced by AtaPdoHandleIoControl().

◆ AtaPdoWmiRegistration()

NTSTATUS AtaPdoWmiRegistration ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ BOOLEAN  Register 
)

Definition at line 189 of file wmi.c.

192{
194
195 PAGED_CODE();
196
197 if (Register)
198 {
199 DevExt->WmiLibInfo.GuidCount = RTL_NUMBER_OF(AtapWmiGuidList);
200 DevExt->WmiLibInfo.GuidList = AtapWmiGuidList;
201
202 DevExt->WmiLibInfo.QueryWmiRegInfo = AtaQueryWmiRegInfo;
203 DevExt->WmiLibInfo.QueryWmiDataBlock = AtaQueryWmiDataBlock;
204
206 }
207 else
208 {
210 }
211
212 return IoWMIRegistrationControl(DevExt->Common.Self, Action);
213}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
static WMIGUIDREGINFO AtapWmiGuidList[]
Definition: wmi.c:14
static NTSTATUS NTAPI AtaQueryWmiRegInfo(_Inout_ PDEVICE_OBJECT DeviceObject, _Inout_ PULONG RegFlags, _Inout_ PUNICODE_STRING InstanceName, _Outptr_result_maybenull_ PUNICODE_STRING *RegistryPath, _Inout_ PUNICODE_STRING MofResourceName, _Outptr_result_maybenull_ PDEVICE_OBJECT *Pdo)
Definition: wmi.c:25
static NTSTATUS NTAPI AtaQueryWmiDataBlock(_Inout_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp, _In_ ULONG GuidIndex, _In_ ULONG InstanceIndex, _In_ ULONG InstanceCount, _Out_writes_opt_(InstanceCount) PULONG InstanceLengthArray, _In_ ULONG BufferAvail, _Out_writes_bytes_opt_(BufferAvail) PUCHAR Buffer)
Definition: wmi.c:51
NTSTATUS NTAPI IoWMIRegistrationControl(IN PDEVICE_OBJECT DeviceObject, IN ULONG Action)
Definition: wmi.c:68
#define WMIREG_ACTION_REGISTER
#define WMIREG_ACTION_DEREGISTER

Referenced by AtaPdoRemoveDevice(), and AtaPdoStartDevice().

◆ AtaPnpInitializeCommonExtension()

VOID AtaPnpInitializeCommonExtension ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ PDEVICE_OBJECT  SelfDeviceObject,
_In_ ULONG  Flags 
)

Definition at line 572 of file atapi.c.

576{
577 PAGED_CODE();
578
579 CommonExt->Flags = Flags;
580 CommonExt->Self = SelfDeviceObject;
581 CommonExt->DevicePowerState = PowerDeviceD0;
582 CommonExt->SystemPowerState = PowerSystemWorking;
583
584 IoInitializeRemoveLock(&CommonExt->RemoveLock, ATAPORT_TAG, 0, 0);
585}
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceD0
Definition: ntpoapi.h:49
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2833

Referenced by AtaAddChannel(), and AtaPdoCreateDevice().

◆ AtaPnpQueryDeviceUsageNotification()

NTSTATUS AtaPnpQueryDeviceUsageNotification ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ PIRP  Irp 
)

Definition at line 503 of file atapi.c.

506{
507 PIO_STACK_LOCATION IoStack;
509 volatile LONG* Counter;
510
511 PAGED_CODE();
512
513 if (!IS_FDO(CommonExt))
514 {
515 Status = AtaPnpRepeatRequest(CommonExt, Irp, NULL);
516 }
517 else
518 {
519 if (!NT_VERIFY(IoForwardIrpSynchronously(CommonExt->LowerDeviceObject, Irp)))
520 return STATUS_UNSUCCESSFUL;
521 Status = Irp->IoStatus.Status;
522 }
523 if (!NT_SUCCESS(Status))
524 return Status;
525
527 switch (IoStack->Parameters.UsageNotification.Type)
528 {
530 Counter = &CommonExt->PageFiles;
531 break;
532
534 Counter = &CommonExt->HibernateFiles;
535 break;
536
538 Counter = &CommonExt->DumpFiles;
539 break;
540
541 default:
542 return Status;
543 }
544
546
547 if (!IS_FDO(CommonExt))
548 IoInvalidateDeviceState(CommonExt->Self);
549
550 return STATUS_SUCCESS;
551}
NTSTATUS AtaPnpRepeatRequest(_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp, _In_opt_ PDEVICE_CAPABILITIES DeviceCapabilities)
Definition: atapi.c:445
#define IS_FDO(p)
Definition: atapi.h:173
long LONG
Definition: pedump.c:60
VOID NTAPI IoInvalidateDeviceState(IN PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:1847
struct _IO_STACK_LOCATION::@4454::@4487 UsageNotification
static LARGE_INTEGER Counter
Definition: clock.c:43
#define IoAdjustPagingPathCount(_Count, _Increment)
@ DeviceUsageTypeHibernation
Definition: iotypes.h:1171
@ DeviceUsageTypeDumpFile
Definition: iotypes.h:1172
@ DeviceUsageTypePaging
Definition: iotypes.h:1170

Referenced by AtaFdoPnp(), and AtaPdoPnp().

◆ AtaPnpQueryInterface()

NTSTATUS AtaPnpQueryInterface ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ const GUID Guid,
_Out_ PVOID  Interface,
_In_ ULONG  Version,
_In_ ULONG  Size 
)

Definition at line 396 of file atapi.c.

402{
404 PIRP Irp;
406 PIO_STACK_LOCATION IoStack;
408
409 PAGED_CODE();
410
412
414 CommonExt->LowerDeviceObject,
415 NULL,
416 0,
417 NULL,
418 &Event,
420 if (!Irp)
422
423 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
424
427 IoStack->Parameters.QueryInterface.InterfaceType = Guid;
428 IoStack->Parameters.QueryInterface.Size = Size;
429 IoStack->Parameters.QueryInterface.Version = Version;
430 IoStack->Parameters.QueryInterface.Interface = Interface;
431 IoStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
432
433 Status = IoCallDriver(CommonExt->LowerDeviceObject, Irp);
434 if (Status == STATUS_PENDING)
435 {
438 }
439
440 return Status;
441}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KernelMode
Definition: asm.h:38
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:100
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
struct _IO_STACK_LOCATION::@4454::@4480 QueryInterface
#define STATUS_PENDING
Definition: telnetd.h:14
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IRP_MN_QUERY_INTERFACE
@ Executive
Definition: ketypes.h:467

Referenced by AtaFdoStartDevice().

◆ AtaPnpQueryPnpDeviceState()

NTSTATUS AtaPnpQueryPnpDeviceState ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ PIRP  Irp 
)

Definition at line 555 of file atapi.c.

558{
559 PAGED_CODE();
560
561 if (CommonExt->PageFiles || CommonExt->HibernateFiles || CommonExt->DumpFiles)
562 Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
563
564 if (IS_FDO(CommonExt))
565 Irp->IoStatus.Status = STATUS_SUCCESS;
566
567 return STATUS_SUCCESS;
568}
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:1006

Referenced by AtaFdoPnp(), and AtaPdoPnp().

◆ AtaPnpRepeatRequest()

NTSTATUS AtaPnpRepeatRequest ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ PIRP  Irp,
_In_opt_ PDEVICE_CAPABILITIES  DeviceCapabilities 
)

Definition at line 445 of file atapi.c.

449{
450 PATAPORT_COMMON_EXTENSION FdoExt = CommonExt->FdoExt;
451 PDEVICE_OBJECT TopDeviceObject;
452 PIO_STACK_LOCATION IoStack, SubStack;
453 PIRP SubIrp;
456
457 PAGED_CODE();
458 ASSERT(!IS_FDO(CommonExt));
459
460 TopDeviceObject = IoGetAttachedDeviceReference(FdoExt->Self);
461
462 SubIrp = IoAllocateIrp(TopDeviceObject->StackSize, FALSE);
463 if (!SubIrp)
464 {
465 ObDereferenceObject(TopDeviceObject);
467 }
468
470
472 SubStack = IoGetNextIrpStackLocation(SubIrp);
473 RtlCopyMemory(SubStack, IoStack, sizeof(*SubStack));
474
476 SubStack->Parameters.DeviceCapabilities.Capabilities = DeviceCapabilities;
477
480 &Event,
481 TRUE,
482 TRUE,
483 TRUE);
484
486
487 Status = IoCallDriver(TopDeviceObject, SubIrp);
488 if (Status == STATUS_PENDING)
489 {
491 }
492
493 ObDereferenceObject(TopDeviceObject);
494
495 Status = SubIrp->IoStatus.Status;
496 IoFreeIrp(SubIrp);
497
498 return Status;
499}
IO_COMPLETION_ROUTINE AtaPdoCompletionRoutine
Definition: atapi.h:859
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
_In_ PIOMMU_DEVICE_PATH _In_ PIOMMU_SVM_CAPABILITIES DeviceCapabilities
Definition: haltypes.h:1824
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1407
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
PDEVICE_OBJECT Self
Definition: atapi.h:432
struct _IO_STACK_LOCATION::@4454::@4481 DeviceCapabilities
IO_STATUS_BLOCK IoStatus
#define DeviceCapabilities
Definition: wingdi.h:4895
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by AtaPdoQueryCapabilities(), and AtaPnpQueryDeviceUsageNotification().

◆ AtaPortCheckDevicePowerState()

NTSTATUS AtaPortCheckDevicePowerState ( _In_ PATAPORT_PORT_DATA  PortData,
_In_ PATAPORT_DEVICE_EXTENSION  DevExt 
)

Definition at line 218 of file dev_power.c.

221{
223
224 if (DevExt->Common.DevicePowerState == PowerDeviceD0)
225 return STATUS_SUCCESS;
226
227 INFO("CH %lu: Powering up idle device '%s'\n", PortData->PortNumber, DevExt->FriendlyName);
228
229 Status = AtaDeviceSetIdleMode(PortData, DevExt);
230 if (!NT_SUCCESS(Status))
231 {
232 /*
233 * If the power on device has failed, the next command can still work.
234 * The media access will result in a transition from the PM1:Idle/PM2:Standby state
235 * to the PM0:Active state by the ATA spec.
236 */
237 ERR("CH %lu: Failed to power up device '%s' %lx\n",
238 PortData->PortNumber, DevExt->FriendlyName, Status);
239 }
240 else
241 {
242 DevExt->Common.DevicePowerState = PowerDeviceD0;
243 }
244
245 return Status;
246}
static NTSTATUS AtaDeviceSetIdleMode(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_power.c:121

Referenced by AtaPortIdentifyDevice().

◆ AtaPortDeviceProcessConfig()

NTSTATUS AtaPortDeviceProcessConfig ( _In_ PATAPORT_PORT_DATA  PortData,
_In_ PATAPORT_DEVICE_EXTENSION  DevExt 
)

Definition at line 341 of file dev_config.c.

344{
346
347 DevExt->Device.DeviceFlags |= DEVICE_PIO_ONLY;
348 DevExt->Device.DeviceFlags &= ~(DEVICE_HAS_MEDIA_STATUS | DEVICE_SENSE_DATA_REPORTING);
349 DevExt->Device.MultiSectorCount = 0;
350
351 Status = AtaDeviceSetGeometry(PortData, DevExt);
353 return Status;
354
355 Status = AtaDeviceSetPioTransferMode(PortData, DevExt);
357 return Status;
358
359 Status = AtaDeviceSetDmaTransferMode(PortData, DevExt);
361 return Status;
362
363 Status = AtaDeviceSetMultipleMode(PortData, DevExt);
365 return Status;
366
367 Status = AtaDeviceExecuteAcpiTaskFile(PortData, DevExt);
369 return Status;
370
373 return Status;
374
375 Status = AtaDeviceLockDeviceParameters(PortData, DevExt);
377 return Status;
378
379 Status = AtaDeviceEnableMsnFeature(PortData, DevExt);
381 return Status;
382
383 /* Identify data might have changed during the configuration, so update it here */
384 Status = AtaDeviceSendIdentify(PortData,
385 DevExt,
386 IS_ATAPI(&DevExt->Device) ?
388 if (NT_SUCCESS(Status))
389 {
390 RtlCopyMemory(&DevExt->IdentifyDeviceData,
391 DevExt->Device.LocalBuffer,
392 sizeof(DevExt->IdentifyDeviceData));
393 }
394
395 return Status;
396}
#define DEVICE_SENSE_DATA_REPORTING
Definition: atapi.h:88
#define DEVICE_HAS_MEDIA_STATUS
Definition: atapi.h:87
NTSTATUS AtaDeviceSendIdentify(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ UCHAR Command)
Definition: dev_identify.c:45
#define IDE_COMMAND_ATAPI_IDENTIFY
Definition: atapi.h:110
static NTSTATUS AtaDeviceLockSecurityModeFeatureCommands(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_config.c:272
static NTSTATUS AtaDeviceSetGeometry(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_config.c:18
static NTSTATUS AtaDeviceSetMultipleMode(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_config.c:133
static NTSTATUS AtaDeviceSetDmaTransferMode(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_config.c:93
static NTSTATUS AtaDeviceSetPioTransferMode(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_config.c:66
static NTSTATUS AtaDeviceEnableMsnFeature(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_config.c:314
static NTSTATUS AtaDeviceLockDeviceParameters(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_config.c:296
static NTSTATUS AtaDeviceExecuteAcpiTaskFile(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_config.c:214
#define STATUS_ADAPTER_HARDWARE_ERROR
Definition: ntstatus.h:524

Referenced by AtaPortConfigureDevice().

◆ AtaPortDeviceProcessError()

NTSTATUS AtaPortDeviceProcessError ( _In_ PATAPORT_PORT_DATA  PortData,
_In_ PATAPORT_DEVICE_EXTENSION  DevExt 
)

Definition at line 642 of file dev_error.c.

645{
646 PATA_DEVICE_REQUEST FailedRequest = PortData->Worker.FailedRequest;
648
649 ASSERT_REQUEST(FailedRequest);
650
651 if (FailedRequest->Flags & REQUEST_FLAG_NCQ)
652 Status = AtaDeviceNcqRecovery(PortData, DevExt);
653 else
654 Status = AtaDeviceGenericRecovery(PortData, DevExt);
655
656 return Status;
657}
#define REQUEST_FLAG_NCQ
Definition: ata_shared.h:284
#define ASSERT_REQUEST(Request)
Definition: atapi.h:326
static NTSTATUS AtaDeviceNcqRecovery(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_error.c:468
static NTSTATUS AtaDeviceGenericRecovery(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_error.c:573

Referenced by AtaPortRecoveryFromError().

◆ AtaPortDeviceProcessPowerChange()

NTSTATUS AtaPortDeviceProcessPowerChange ( _In_ PATAPORT_PORT_DATA  PortData,
_In_ PATAPORT_DEVICE_EXTENSION  DevExt 
)

Definition at line 151 of file dev_power.c.

154{
156 PIRP PowerIrp;
157 PIO_STACK_LOCATION IoStack;
158 DEVICE_POWER_STATE NewState;
159 KIRQL OldLevel;
161
162 KeAcquireSpinLock(&DevExt->Device.QueueLock, &OldLevel);
163 if (IsListEmpty(&DevExt->PowerIrpQueueList))
164 Entry = NULL;
165 else
166 Entry = RemoveHeadList(&DevExt->PowerIrpQueueList);
167 KeReleaseSpinLock(&DevExt->Device.QueueLock, OldLevel);
168 if (!Entry)
169 return STATUS_SUCCESS;
170
171 PowerIrp = CONTAINING_RECORD(Entry, IRP, Tail.Overlay.ListEntry);
172
173 IoStack = IoGetCurrentIrpStackLocation(PowerIrp);
175
176 NewState = IoStack->Parameters.Power.State.DeviceState;
177 if (NewState == DevExt->Common.DevicePowerState)
178 {
179 AtaDeviceCompletePowerIrp(DevExt, PowerIrp);
180 return STATUS_SUCCESS;
181 }
182
183 if (NewState != PowerDeviceD3)
184 {
186
187 /* Power up the device */
188 Status = AtaDeviceSetIdleMode(PortData, DevExt);
190 return Status;
191
192 /* Restore the software settings after power up */
193 _InterlockedOr(&DevExt->Worker.EventsPending, ACTION_DEVICE_CONFIG);
194 _InterlockedOr(&PortData->Worker.EventsPending, ACTION_DEVICE_CONFIG);
195 }
196 else
197 {
199
200 /* Flush device caches */
201 Status = AtaDeviceFlushCache(PortData, DevExt);
203 return Status;
204
205 /* Power down the device */
206 Status = AtaDeviceSetStandbyMode(PortData, DevExt);
208 return Status;
209 }
210
211 AtaDeviceCompletePowerIrp(DevExt, PowerIrp);
212
213 DevExt->Common.DevicePowerState = NewState;
214 return Status;
215}
DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqThawQueue(_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ ULONG ReasonFlags)
Definition: scsi.c:1365
DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqFreezeQueue(_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ ULONG ReasonFlags)
Definition: scsi.c:1351
static NTSTATUS AtaDeviceSetStandbyMode(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_power.c:137
static VOID AtaDeviceCompletePowerIrp(_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ PIRP Irp)
Definition: dev_power.c:86
static NTSTATUS AtaDeviceFlushCache(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_power.c:100
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
long _InterlockedOr(_Interlocked_operand_ long volatile *_Value, long _Mask)
struct _IO_STACK_LOCATION::@4454::@4490 Power

Referenced by AtaPortDeviceChangePower().

◆ AtaPortIdentifyDevice()

ATA_DEVICE_STATUS AtaPortIdentifyDevice ( _In_ PATAPORT_PORT_DATA  PortData,
_In_ PATAPORT_DEVICE_EXTENSION  DevExt 
)

Definition at line 213 of file dev_identify.c.

216{
217 PIDENTIFY_DEVICE_DATA IdentifyData = DevExt->Device.LocalBuffer;
218 ATA_CONNECTION_STATUS ConnectionStatus;
220 BOOLEAN StartFromAtapi, IsSameDevice;
221 ULONG Attempt, RetryCount;
223
224 _InterlockedOr(&PortData->InterruptFlags, PORT_INT_FLAG_IGNORE_LINK_IRQ);
225
226 ConnectionStatus = PortData->IdentifyDevice(PortData->ChannelContext,
227 DevExt->Device.AtaScsiAddress.TargetId);
228
229 _InterlockedAnd(&PortData->InterruptFlags, ~PORT_INT_FLAG_IGNORE_LINK_IRQ);
230
231 if (ConnectionStatus == CONN_STATUS_FAILURE)
232 return DEV_STATUS_FAILED;
233
234 if (ConnectionStatus == CONN_STATUS_NO_DEVICE)
236
237 /* Power up the device if needed */
238 Status = AtaPortCheckDevicePowerState(PortData, DevExt);
240 return DEV_STATUS_FAILED;
241
242 /*
243 * Try the known device type first.
244 * This may speed up device detection by eliminating I/O errors.
245 */
246 if (DevExt->Device.DeviceFlags & DEVICE_UNINITIALIZED)
247 StartFromAtapi = (ConnectionStatus == CONN_STATUS_DEV_ATAPI);
248 else
249 StartFromAtapi = IS_ATAPI(&DevExt->Device);
250
251 /* Look for ATA/ATAPI devices */
252 for (RetryCount = 0; RetryCount < 2; ++RetryCount)
253 {
254 /* Send the identify command */
255 for (Attempt = 0; Attempt < 2; ++Attempt)
256 {
257 if (StartFromAtapi)
259 else
261
262 /* Swap device types */
263 if (Attempt != 0)
265
266 Status = AtaDeviceSendIdentify(PortData,
267 DevExt,
271 return DEV_STATUS_FAILED;
272
273 if (NT_SUCCESS(Status))
274 break;
275 }
276 if (!NT_SUCCESS(Status))
278
279 /*
280 * The drive needs to be spun up
281 * or the device was unable to return complete identity data.
282 */
283 if (AtaDevInPuisState(IdentifyData) || AtaDevIsIdentifyDataIncomplete(IdentifyData))
284 {
285
286 Status = AtaDeviceSpinUp(PortData, DevExt);
288 return DEV_STATUS_FAILED;
289
290 if (!NT_SUCCESS(Status))
291 ERR("Failed to spin-up device\n");
292 continue;
293 }
294 }
295
296 /* Verify the checksum */
297 if (!AtaDevIsIdentifyDataValid(IdentifyData))
298 {
299 ERR("Identify data CRC error\n");
300 return DEV_STATUS_FAILED;
301 }
302
303 if (DevExt->Device.DeviceFlags & DEVICE_UNINITIALIZED)
304 {
305 IsSameDevice = FALSE;
306 }
307 else
308 {
309 IsSameDevice = (DeviceType == DevExt->DeviceType) &&
310 (AtaDeviceIdentifyDataEqual(&DevExt->IdentifyDeviceData,
311 DevExt->Device.LocalBuffer));
312 }
313
314 /* Update identify data */
315 RtlCopyMemory(&DevExt->IdentifyDeviceData,
316 DevExt->Device.LocalBuffer,
317 sizeof(DevExt->IdentifyDeviceData));
318 DevExt->DeviceType = DeviceType;
319
320 if (IsSameDevice)
322
323 DevExt->Device.TransportFlags &= ~(DEVICE_IS_ATAPI |
327
328 if (DeviceType == DEV_ATAPI)
329 {
330 DevExt->Device.TransportFlags |= DEVICE_IS_ATAPI;
331
332 DevExt->Device.CdbSize = AtaDevCdbSizeInWords(&DevExt->IdentifyPacketData);
333 TRACE("Device has CDB size of %u bytes\n", DevExt->Device.CdbSize * 2);
334
335 if (AtaDevHasCdbInterrupt(&DevExt->IdentifyPacketData))
336 {
337 TRACE("Device has CDB interrupt\n");
338 DevExt->Device.TransportFlags |= DEVICE_HAS_CDB_INTERRUPT;
339 }
340
341 if (AtaDevIsDmaDirectionRequired(&DevExt->IdentifyPacketData))
342 {
343 TRACE("Device needs DMA DIR\n");
344 DevExt->Device.TransportFlags |= DEVICE_NEED_DMA_DIRECTION;
345 }
346
347 /* The NEC CDR-260 string is not byteswapped */
348 if (DevExt->IdentifyPacketData.ModelNumber[0] == 'N' &&
349 DevExt->IdentifyPacketData.ModelNumber[1] == 'E' &&
350 DevExt->IdentifyPacketData.ModelNumber[2] == 'C')
351 {
352 TRACE("Device is a NEC CDR-260 drive\n");
353 DevExt->Device.TransportFlags |= DEVICE_IS_NEC_CDR260;
354 }
355
356 Status = AtaDeviceSendInquiry(PortData, DevExt);
358 return DEV_STATUS_FAILED;
359
360 /* Update the inquiry data */
361 RtlCopyMemory(&DevExt->InquiryData,
362 DevExt->Device.LocalBuffer,
363 sizeof(DevExt->InquiryData));
364 }
365
367}
unsigned char BOOLEAN
Definition: actypes.h:127
@ CONN_STATUS_FAILURE
Definition: ata_shared.h:83
@ CONN_STATUS_DEV_ATAPI
Definition: ata_shared.h:87
@ CONN_STATUS_NO_DEVICE
Definition: ata_shared.h:84
#define DEVICE_IS_NEC_CDR260
Definition: ata_shared.h:168
#define DEVICE_HAS_CDB_INTERRUPT
Definition: ata_shared.h:166
enum _ATA_CONNECTION_STATUS ATA_CONNECTION_STATUS
#define DEVICE_NEED_DMA_DIRECTION
Definition: ata_shared.h:167
#define DEVICE_IS_ATAPI
Definition: ata_shared.h:165
enum _ATA_DEVICE_TYPE ATA_DEVICE_TYPE
Private enum between the ATA driver and storprop.dll.
#define PORT_INT_FLAG_IGNORE_LINK_IRQ
Definition: atapi.h:361
NTSTATUS AtaPortCheckDevicePowerState(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_power.c:218
static BOOLEAN AtaDeviceIdentifyDataEqual(_In_ PIDENTIFY_DEVICE_DATA IdentifyData1, _In_ PIDENTIFY_DEVICE_DATA IdentifyData2)
Definition: dev_identify.c:16
static NTSTATUS AtaDeviceSendInquiry(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_identify.c:161
static NTSTATUS AtaDeviceSpinUp(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_identify.c:80
NTSTATUS AtaDeviceSendIdentify(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ UCHAR Command)
Definition: dev_identify.c:45
FORCEINLINE BOOLEAN AtaDevIsIdentifyDataValid(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
Definition: hwidep.h:201
@ DEV_ATA
Definition: hwidep.h:100
@ DEV_ATAPI
Definition: hwidep.h:101
FORCEINLINE UCHAR AtaDevCdbSizeInWords(_In_ PIDENTIFY_PACKET_DATA IdentifyPacketData)
Definition: hwidep.h:226
FORCEINLINE BOOLEAN AtaDevIsIdentifyDataIncomplete(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
FORCEINLINE BOOLEAN AtaDevHasCdbInterrupt(_In_ PIDENTIFY_PACKET_DATA IdentifyPacketData)
FORCEINLINE BOOLEAN AtaDevInPuisState(_In_ PIDENTIFY_DEVICE_DATA IdentifyData)
FORCEINLINE BOOLEAN AtaDevIsDmaDirectionRequired(_In_ PIDENTIFY_PACKET_DATA IdentifyPacketData)
volatile char *const const char modify _InterlockedAnd
Definition: intrin_ppc.h:267
DeviceType
Definition: mmdrv.h:42

Referenced by AtaPortEnumerateDevice().

◆ AtaPortQueueEmpty()

FORCEINLINE BOOLEAN AtaPortQueueEmpty ( _In_ PATAPORT_PORT_DATA  PortData)

Definition at line 573 of file atapi.h.

575{
576 ULONG SlotsBitmap;
577
578 SlotsBitmap = PortData->Worker.PausedSlotsBitmap | PortData->FreeSlotsBitmap;
579
580 return (SlotsBitmap == PortData->MaxSlotsBitmap);
581}

Referenced by AtaPortWaitForIdle(), and AtaReqCompleteRequest().

◆ AtaPortSelectTimings()

VOID AtaPortSelectTimings ( _In_ PATAPORT_PORT_DATA  PortData,
_In_ BOOLEAN  ForceCompatibleTimings 
)

Definition at line 258 of file dev_timings.c.

261{
263 ULONG i;
266
267 if (ForceCompatibleTimings)
268 {
269 for (i = 0; i < ATA_MAX_DEVICE; ++i)
270 {
271 /* Fake device presence */
272 DeviceList[i] = &Config[i];
273
274 /* Disable DMA and select compatible timings */
275 Config[i].SupportedModes = PIO_MODE0;
276 Config[i].CurrentModes = PIO_MODE0;
277 Config[i].MinPioCycleTime = AtapModeToCycleTime[PIO_MODE(0)];
278 Config[i].MinSwDmaCycleTime = AtapModeToCycleTime[SWDMA_MODE(0)];
279 Config[i].MinMwDmaCycleTime = AtapModeToCycleTime[MWDMA_MODE(0)];
280 Config[i].IsFixedDisk = TRUE;
281 Config[i].IoReadySupported = FALSE;
282 Config[i].IsNewDevice = FALSE;
283 Config[i].FriendlyName = "";
284 }
285
286 /* Call the chipset driver */
287 PortData->SetTransferMode(PortData->ChannelContext, DeviceList);
288 return;
289 }
290
291 ChanExt = CONTAINING_RECORD(PortData, ATAPORT_CHANNEL_EXTENSION, PortData);
292
293 for (i = 0; i < ATA_MAX_DEVICE; ++i)
294 {
296 ULONG AllowedModesMask;
297
298 DevExt = AtaFdoFindDeviceByPath(ChanExt,
299 AtaMarshallScsiAddress(PortData->PortNumber, i, 0),
300 NULL);
301 if (!DevExt)
302 continue;
303
304 DevExt->TransferModeCurrentBitmap = 0;
305 DevExt->TransferModeSupportedBitmap = 0;
306
307 AllowedModesMask = DevExt->TransferModeUserAllowedMask;
308 AllowedModesMask &= DevExt->TransferModeAllowedMask;
309 /* Mode cannot be slower than PIO0 */
310 AllowedModesMask |= PIO_MODE0;
311
312 AtaTimQueryPioModeSupport(DevExt, AllowedModesMask);
313 AtaTimQuerySwDmaModeSupport(DevExt, AllowedModesMask);
314 AtaTimQueryMwDmaModeSupport(DevExt, AllowedModesMask);
315 AtaTimQueryUDmaModeSupport(DevExt, AllowedModesMask);
316
317 DeviceList[i] = &Config[i];
318 Config[i].CurrentModes = DevExt->TransferModeCurrentBitmap;
319 Config[i].SupportedModes = DevExt->TransferModeSupportedBitmap;
320 Config[i].MinPioCycleTime = DevExt->MinimumPioCycleTime;
321 Config[i].MinSwDmaCycleTime = DevExt->MinimumSingleWordDmaCycleTime;
322 Config[i].MinMwDmaCycleTime = DevExt->MinimumMultiWordDmaCycleTime;
323 Config[i].IsFixedDisk = !IS_ATAPI(&DevExt->Device);
324 Config[i].IoReadySupported = !!DevExt->IdentifyDeviceData.Capabilities.IordySupported;
325 Config[i].IsNewDevice = !(DevExt->Device.DeviceFlags & DEVICE_PNP_STARTED);
326 Config[i].FriendlyName = DevExt->FriendlyName;
327 }
328
329 /* Call the chipset driver */
330 PortData->SetTransferMode(PortData->ChannelContext, DeviceList);
331
332 /* Save the result */
333 for (i = 0; i < ATA_MAX_DEVICE; ++i)
334 {
335 PCHANNEL_DEVICE_CONFIG DeviceConfig = DeviceList[i];
337
338 if (!DeviceConfig)
339 continue;
340
341 DevExt = AtaFdoFindDeviceByPath(ChanExt,
342 AtaMarshallScsiAddress(PortData->PortNumber, i, 0),
343 NULL);
344 ASSERT(DevExt);
345
346 DevExt->TransferModeSelectedBitmap = 1 << DeviceConfig->PioMode;
347 if (DeviceConfig->DmaMode != PIO_MODE(0))
348 {
349 DevExt->TransferModeSelectedBitmap |= 1 << DeviceConfig->DmaMode;
350 }
351
352 AtaTimDumpTimingInfo(PortData, DevExt);
353 }
354}
#define ATA_MAX_DEVICE
Definition: ata_shared.h:15
#define PIO_MODE(n)
Definition: ata_user.h:36
#define MWDMA_MODE(n)
Definition: ata_user.h:38
#define SWDMA_MODE(n)
Definition: ata_user.h:37
#define DEVICE_PNP_STARTED
Definition: atapi.h:92
static VOID AtaTimQueryPioModeSupport(_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ ULONG AllowedModesMask)
Definition: dev_timings.c:37
static VOID AtaTimDumpTimingInfo(_In_ PATAPORT_PORT_DATA PortData, _In_ PATAPORT_DEVICE_EXTENSION DevExt)
Definition: dev_timings.c:234
static const ULONG AtapModeToCycleTime[]
Definition: dev_timings.c:18
static VOID AtaTimQuerySwDmaModeSupport(_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ ULONG AllowedModesMask)
Definition: dev_timings.c:105
static VOID AtaTimQueryUDmaModeSupport(_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ ULONG AllowedModesMask)
Definition: dev_timings.c:191
static VOID AtaTimQueryMwDmaModeSupport(_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ ULONG AllowedModesMask)
Definition: dev_timings.c:143
PDEVICE_LIST DeviceList
Definition: utils.c:27
#define PIO_MODE0
Definition: ide.h:277
ULONG TransferModeSelectedBitmap
Definition: atapi.h:527
ULONG TransferModeCurrentBitmap
Definition: atapi.h:509
IDENTIFY_DEVICE_DATA IdentifyDeviceData
Definition: atapi.h:474
ULONG TransferModeSupportedBitmap
Definition: atapi.h:518
ULONG MinimumSingleWordDmaCycleTime
Definition: atapi.h:543
ULONG MinimumMultiWordDmaCycleTime
Definition: atapi.h:544
struct _IDENTIFY_DEVICE_DATA::@2049 Capabilities
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG Config
Definition: wdfchildlist.h:476

Referenced by AtaPortResetPort(), and AtaPortSetTransferMode().

◆ AtaPortSendRequest()

NTSTATUS AtaPortSendRequest ( _In_ PATAPORT_PORT_DATA  PortData,
_In_ PATAPORT_DEVICE_EXTENSION  DevExt 
)

Definition at line 831 of file portstate.c.

834{
835 PATA_DEVICE_REQUEST Request = &PortData->Worker.InternalRequest;
837
839 {
840 INFO("CH %lu: Send CDB %u %02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
841 PortData->PortNumber,
842 DevExt->Device.AtaScsiAddress.TargetId,
843 Request->Cdb[0],
844 Request->Cdb[1],
845 Request->Cdb[2],
846 Request->Cdb[3],
847 Request->Cdb[4],
848 Request->Cdb[5],
849 Request->Cdb[6]);
850 }
851 else
852 {
853 INFO("CH %lu: Send TF %u %02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
854 PortData->PortNumber,
855 DevExt->Device.AtaScsiAddress.TargetId,
856 Request->TaskFile.Command,
857 Request->TaskFile.Feature,
858 Request->TaskFile.SectorCount,
859 Request->TaskFile.LowLba,
860 Request->TaskFile.MidLba,
861 Request->TaskFile.HighLba,
862 Request->TaskFile.DriveSelect);
863 }
864
865 KeClearEvent(&PortData->Worker.CompletionEvent);
866
868 Request->Device = (PATA_IO_CONTEXT_COMMON)&DevExt->Device;
869
870 PortData->Worker.OldRequest = PortData->Slots[0];
871 PortData->Slots[0] = Request;
872
874
875 KeAcquireSpinLockAtDpcLevel(&PortData->QueueLock);
876 PortData->ActiveTimersBitmap |= 1 << 0;
877 KeReleaseSpinLockFromDpcLevel(&PortData->QueueLock);
878
880
882
883 KeWaitForSingleObject(&PortData->Worker.CompletionEvent, Executive, KernelMode, FALSE, NULL);
884
885 /* Stop the timer */
886 KeAcquireSpinLock(&PortData->QueueLock, &OldIrql);
887 PortData->ActiveTimersBitmap = 0;
888 KeReleaseSpinLock(&PortData->QueueLock, OldIrql);
889
890 PortData->Slots[0] = PortData->Worker.OldRequest;
891
892 if ((Request->SrbStatus == SRB_STATUS_TIMEOUT) ||
893 (Request->SrbStatus == SRB_STATUS_BUS_RESET))
894 {
896 }
897
898 if (Request->SrbStatus == SRB_STATUS_SUCCESS)
899 return STATUS_SUCCESS;
900
902}
#define REQUEST_FLAG_INTERNAL
Definition: ata_shared.h:345
VOID AtaReqSendRequest(_In_ PATA_DEVICE_REQUEST Request)
Definition: scsi.c:632
#define SRB_STATUS_BUS_RESET
Definition: srb.h:353
#define SRB_STATUS_TIMEOUT
Definition: srb.h:349
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define DISPATCH_LEVEL
Definition: env_spec_w32.h:696
VOID NTAPI KeClearEvent(IN PKEVENT Event)
Definition: eventobj.c:22
#define REQUEST_FLAG_PACKET_COMMAND
Definition: hwidep.h:169
#define KeAcquireSpinLockAtDpcLevel(SpinLock)
Definition: ke.h:125
#define KeReleaseSpinLockFromDpcLevel(SpinLock)
Definition: ke.h:135
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179

Referenced by AtaDeviceEnableMsnFeature(), AtaDeviceExecuteAcpiTaskFile(), AtaDeviceFlushCache(), AtaDeviceLockDeviceParameters(), AtaDeviceLockSecurityModeFeatureCommands(), AtaDeviceSendIdentify(), AtaDeviceSendInquiry(), AtaDeviceSendReadNcqCommandErrorLog(), AtaDeviceSendRequestSense(), AtaDeviceSendRequestSenseExt(), AtaDeviceSetDmaTransferMode(), AtaDeviceSetGeometry(), AtaDeviceSetIdleMode(), AtaDeviceSetMultipleMode(), AtaDeviceSetPioTransferMode(), AtaDeviceSetStandbyMode(), and AtaDeviceSpinUp().

◆ AtaPortSignalWorkerThread()

DECLSPEC_NOINLINE_FROM_PAGED VOID AtaPortSignalWorkerThread ( _In_ PATAPORT_PORT_DATA  PortData)

Definition at line 963 of file portstate.c.

965{
967
968 KeAcquireSpinLock(&PortData->Worker.Lock, &OldIrql);
969 KeSetEvent(&PortData->Worker.ThreadEvent, IO_NO_INCREMENT, FALSE);
970 KeReleaseSpinLock(&PortData->Worker.Lock, OldIrql);
971}
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476

Referenced by AtaFdoDestroyPortThread(), and AtaPortWorkerSignalDpc().

◆ AtaPortTimeout()

VOID AtaPortTimeout ( _In_ PATAPORT_PORT_DATA  PortData,
_In_ ULONG  Slot 
)

Definition at line 905 of file portstate.c.

908{
911
913
914 Request = PortData->Slots[Slot];
916
918
919 ERR("CH %lu: Slot %lu (%08lx) timed out %lx (%lus) %u '%s'\n",
920 PortData->PortNumber,
921 Slot,
922 1 << Slot,
923 Request->Flags,
924 Request->TimeOut,
926 DevExt->FriendlyName);
928 {
929 ERR("CH %lu: CDB %02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
930 PortData->PortNumber,
931 Request->Cdb[0],
932 Request->Cdb[1],
933 Request->Cdb[2],
934 Request->Cdb[3],
935 Request->Cdb[4],
936 Request->Cdb[5],
937 Request->Cdb[6]);
938 }
939 else
940 {
941 ERR("CH %lu: TF %02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
942 PortData->PortNumber,
943 Request->TaskFile.Command,
944 Request->TaskFile.Feature,
945 Request->TaskFile.SectorCount,
946 Request->TaskFile.LowLba,
947 Request->TaskFile.MidLba,
948 Request->TaskFile.HighLba,
949 Request->TaskFile.DriveSelect);
950 }
951
952 Request->SrbStatus = SRB_STATUS_TIMEOUT;
953
954 /* The active command has timed out, set the ATA outputs to something meaningful */
955 Request->Output.Status = IDE_STATUS_ERROR;
956 Request->Output.Error = IDE_ERROR_COMMAND_ABORTED;
957
959}
#define IDE_STATUS_ERROR
Definition: atapi.h:125
#define IDE_ERROR_COMMAND_ABORTED
Definition: atapi.h:158
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
_Must_inspect_result_ _In_ WDFDEVICE Device
Definition: wdfchildlist.h:474

Referenced by AtaPortIoTimer().

◆ AtaReqAllocateMdl()

BOOLEAN AtaReqAllocateMdl ( _In_ PATA_DEVICE_REQUEST  Request)

Definition at line 467 of file scsi.c.

469{
470 PMDL Mdl;
471
472 Mdl = IoAllocateMdl(Request->DataBuffer,
473 Request->DataTransferLength,
474 FALSE,
475 FALSE,
476 NULL);
477 if (!Mdl)
478 return FALSE;
479
481
482 Request->Mdl = Mdl;
484
485 return TRUE;
486}
#define REQUEST_FLAG_HAS_MDL
Definition: ata_shared.h:333
#define IoAllocateMdl
Definition: fxmdl.h:88
VOID NTAPI MmBuildMdlForNonPagedPool(IN PMDL Mdl)
Definition: mdlsup.c:424
_In_ WDFDEVICE _In_ PVOID _In_opt_ PMDL Mdl

Referenced by AtaReqBuildIdentifyCommand().

◆ AtaReqBuildReadLogTaskFile()

VOID AtaReqBuildReadLogTaskFile ( _In_ PATA_DEVICE_REQUEST  Request,
_In_ UCHAR  LogAddress,
_In_ UCHAR  PageNumber,
_In_ USHORT  LogPageCount 
)

Definition at line 399 of file satl.c.

404{
405 PATA_TASKFILE TaskFile = &Request->TaskFile;
406
407 /* PIO Data-In command */
409 Request->DataTransferLength = LogPageCount * IDE_GP_LOG_SECTOR_SIZE;
410
411 TaskFile->Feature = 0;
412 TaskFile->FeatureEx = 0;
413
414 /* LOG PAGE COUNT */
415 TaskFile->SectorCount = (UCHAR)LogPageCount;
416 TaskFile->SectorCountEx = (UCHAR)(LogPageCount >> 8);
417
418 TaskFile->LowLba = LogAddress; // LOG ADDRESS
419 TaskFile->MidLba = PageNumber; // PAGE NUMBER
420 TaskFile->HighLba = 0; // Reserved
421 TaskFile->LowLbaEx = 0; // Reserved
422 TaskFile->MidLbaEx = 0; // PAGE NUMBER EX
423 TaskFile->HighLbaEx = 0; // Reserved
425}
#define IDE_GP_LOG_SECTOR_SIZE
Definition: ata.h:731
#define IDE_COMMAND_READ_LOG_EXT
Definition: ata.h:649
#define REQUEST_FLAG_LBA48
Definition: hwidep.h:167
UCHAR SectorCountEx
Definition: ata_shared.h:200
UCHAR SectorCount
Definition: hwidep.h:151
UCHAR Feature
Definition: hwidep.h:150
UCHAR MidLba
LBA bits 8-15.
Definition: hwidep.h:153
UCHAR LowLbaEx
LBA bits 24-31.
Definition: ata_shared.h:195
UCHAR HighLba
LBA bits 16-23.
Definition: hwidep.h:154
UCHAR FeatureEx
Definition: ata_shared.h:198
UCHAR HighLbaEx
LBA bits 40-47.
Definition: ata_shared.h:197
UCHAR Command
Definition: hwidep.h:147
UCHAR LowLba
LBA bits 0-7.
Definition: hwidep.h:152
UCHAR MidLbaEx
LBA bits 32-39.
Definition: ata_shared.h:196

Referenced by AtaDeviceSendReadNcqCommandErrorLog().

◆ AtaReqCompleteFailedRequest()

VOID AtaReqCompleteFailedRequest ( _In_ PATA_DEVICE_REQUEST  Request)

◆ AtaReqDmaTransferToPioTransfer()

BOOLEAN AtaReqDmaTransferToPioTransfer ( _In_ PATA_DEVICE_REQUEST  Request)

Definition at line 78 of file satl.c.

80{
82
83 ASSERT(!(Device->DeviceFlags & DEVICE_PIO_VIA_DMA));
85
86 /* ATAPI commands */
88 {
89 Request->Flags &= ~REQUEST_DMA_FLAGS;
90 return TRUE;
91 }
92
93 /*
94 * For ATA commands there is no simple way to achieve this,
95 * we have to fix the command opcode.
96 * Determine if it is safe or allowed to change the command.
97 */
99 {
100 Request->Flags &= ~REQUEST_DMA_FLAGS;
101
102 Request->TaskFile.Command = AtaReadWriteCommand(Request, Device);
103 if (Request->TaskFile.Command == 0)
104 {
105 /* PIO is not available */
106 Request->Flags |= REQUEST_DMA_FLAGS;
107 return FALSE;
108 }
109
110 return TRUE;
111 }
112
113 /* PIO is not available */
114 return FALSE;
115}
#define REQUEST_DMA_FLAGS
Definition: ata_shared.h:369
#define REQUEST_FLAG_READ_WRITE
Definition: ata_shared.h:303
struct _ATAPORT_IO_CONTEXT * PATAPORT_IO_CONTEXT
Definition: atapi.h:36
static UCHAR AtaReadWriteCommand(_In_ PATA_DEVICE_REQUEST Request, _In_ PATAPORT_IO_CONTEXT Device)
Definition: satl.c:42

Referenced by AtaReqSendRequest().

◆ AtaReqExecuteScsi()

UCHAR AtaReqExecuteScsi ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ PATA_DEVICE_REQUEST  Request,
_In_ PSCSI_REQUEST_BLOCK  Srb 
)

Definition at line 2054 of file satl.c.

2058{
2059 if (IS_ATAPI(&DevExt->Device))
2060 return AtaReqExecuteScsiAtapi(DevExt, Request, Srb);
2061 else
2062 return AtaReqExecuteScsiAta(DevExt, Request, Srb);
2063}
static UCHAR AtaReqExecuteScsiAta(_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ PATA_DEVICE_REQUEST Request, _In_ PSCSI_REQUEST_BLOCK Srb)
Definition: satl.c:1911
static UCHAR AtaReqExecuteScsiAtapi(_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ PATA_DEVICE_REQUEST Request, _In_ PSCSI_REQUEST_BLOCK Srb)
Definition: satl.c:2020

Referenced by AtaReqTranslateRequest().

◆ AtaReqFlushDeviceQueue()

DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqFlushDeviceQueue ( _In_ PATAPORT_IO_CONTEXT  Device)

Definition at line 1451 of file scsi.c.

1453{
1455 KIRQL OldLevel;
1457
1458 KeAcquireSpinLock(&Device->QueueLock, &OldLevel);
1459
1460 for (Entry = Device->DeviceQueueList.Flink;
1461 Entry != &Device->DeviceQueueList;
1462 Entry = Entry->Flink)
1463 {
1465 PIRP Irp;
1467
1470
1471 AtaReqDeviceQueueRemoveEntry(Device, QueueEntry);
1472
1473 /* Clear our cancel routine */
1476 {
1477 /* We're already canceled, reset the list entry to point to itself */
1479 continue;
1480 }
1481
1482 KeReleaseSpinLock(&Device->QueueLock, OldLevel);
1483
1485 ASSERT(Srb);
1487
1489 Irp->IoStatus.Status = STATUS_CANCELLED;
1490 Irp->IoStatus.Information = Srb->DataTransferLength;
1492
1493 KeAcquireSpinLock(&Device->QueueLock, &OldLevel);
1494 }
1495
1497
1498 KeReleaseSpinLock(&Device->QueueLock, OldLevel);
1499
1500 if (Request)
1501 {
1502 KIRQL OldIrql;
1503
1504 Request->SrbStatus = SRB_STATUS_ABORTED;
1505 Request->InternalState = REQUEST_STATE_NOT_STARTED;
1506
1510 }
1511}
#define REQUEST_STATE_NOT_STARTED
Definition: ata_shared.h:267
#define IRP_FROM_QUEUE_ENTRY(QueueEntry)
Definition: atapi.h:313
#define SRB_STATUS_ABORTED
Definition: srb.h:342
IoSetCancelRoutine(Irp, CancelRoutine)
static VOID AtaReqCompleteRequest(_In_ PATA_DEVICE_REQUEST Request)
Definition: scsi.c:258
_In_ PREQUEST_QUEUE_ENTRY QueueEntry
Definition: scsi.c:1054
static PATA_DEVICE_REQUEST AtaReqRemovePortRequest(_In_ PATAPORT_IO_CONTEXT Device)
Definition: scsi.c:1012
struct _IO_STACK_LOCATION::@4454::@4476 Scsi
Definition: atapi.h:317
PVOID Context
Definition: atapi.h:319
LIST_ENTRY ListEntry
Definition: atapi.h:318
PVOID OriginalRequest
Definition: srb.h:266
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
#define IO_DISK_INCREMENT
Definition: iotypes.h:600

Referenced by AtaFdoRemoveDevice(), AtaPdoDispatchScsi(), AtaPdoRemoveDevice(), and AtaPortExitStateMachine().

◆ AtaReqFreezeQueue()

DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqFreezeQueue ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ ULONG  ReasonFlags 
)

Definition at line 1351 of file scsi.c.

1354{
1355 PATAPORT_IO_CONTEXT Device = &DevExt->Device;
1356 KIRQL OldLevel;
1357
1358 KeAcquireSpinLock(&Device->QueueLock, &OldLevel);
1359 _InterlockedOr(&Device->QueueFlags, ReasonFlags);
1360 KeReleaseSpinLock(&Device->QueueLock, OldLevel);
1361}

Referenced by AtaPdoDispatchScsi(), AtaPdoInit(), AtaPdoRemoveDevice(), AtaPdoStopDevice(), AtaPortDeviceProcessPowerChange(), AtaPortEnterStateMachine(), AtaPortEnumerateDevice(), and AtaPortExitStateMachine().

◆ AtaReqSendRequest()

VOID AtaReqSendRequest ( _In_ PATA_DEVICE_REQUEST  Request)

Definition at line 632 of file scsi.c.

634{
636
639
641
642 /* The channel can only perform DMA I/O and PIO is not supported */
643 if (Device->DeviceFlags & DEVICE_PIO_VIA_DMA)
645
646 if (Request->Flags & REQUEST_FLAG_DMA)
648
649 if (!(Request->Flags & REQUEST_FLAG_NO_KEEP_AWAKE))
650 {
651 PULONG PowerIdleCounter = Device->PowerIdleCounter;
652
653 if (PowerIdleCounter)
654 PoSetDeviceBusy(PowerIdleCounter);
655 }
656
657 /* Local buffer transfer */
659 {
661
663 {
664 /* DMA transfer */
665 Device->PortData->LocalSgList.Elements[0].Length = Request->DataTransferLength;
666 AtaReqPreparePrdTable(NULL, NULL, &Device->PortData->LocalSgList, Request);
667 }
668 else
669 {
670 /* PIO data transfer */
671 Request->DataBuffer = Device->LocalBuffer;
673 }
674 return;
675 }
676
677 /* No data transfer */
679 {
681 return;
682 }
683
684 /* DMA transfer, get the S/G list for the MDL */
686 {
688 return;
689
690 /* This channel can only perform DMA I/O and PIO is not supported */
691 if (Device->DeviceFlags & DEVICE_PIO_VIA_DMA)
692 goto CompleteNoMemory;
693
694 /* S/G list construction failed, attempt to fall back to PIO mode */
696 goto CompleteNoMemory;
697 }
698
699 /* PIO data transfer path */
700 ASSERT(!(Device->DeviceFlags & DEVICE_PIO_VIA_DMA));
701
703 if (!BaseAddress)
704 goto CompleteNoMemory;
705
706 /* Calculate the offset within DataBuffer */
708 (ULONG_PTR)Request->DataBuffer -
710 Request->DataBuffer = (PVOID)Offset;
711
713 return;
714
715CompleteNoMemory:
717 Request->InternalState = REQUEST_STATE_REQUEUE;
718
719 /*
720 * Defer the completion to a DPC.
721 * We cannot complete request with the queue spinlock held.
722 */
724}
#define REQUEST_FLAG_NO_KEEP_AWAKE
Definition: ata_shared.h:339
#define REQUEST_STATE_REQUEUE
Definition: ata_shared.h:270
#define REQUEST_FLAG_DATA_OUT
Definition: ata_shared.h:290
#define REQUEST_FLAG_PROGRAM_DMA
Definition: ata_shared.h:342
#define REQUEST_FLAG_DMA
Definition: ata_shared.h:278
BOOLEAN AtaReqDmaTransferToPioTransfer(_In_ PATA_DEVICE_REQUEST Request)
Definition: satl.c:78
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize _Pre_valid_ PVOID * BaseAddress
Definition: mmfuncs.h:404
#define SRB_STATUS_INSUFFICIENT_RESOURCES
Definition: srb.h:142
static DRIVER_LIST_CONTROL AtaReqPreparePrdTable
Definition: scsi.c:18
static VOID AtaReqStartIo(_In_ PATA_DEVICE_REQUEST Request)
Definition: scsi.c:490
VOID AtaReqStartCompletionDpc(_In_ PATA_DEVICE_REQUEST Request)
Definition: scsi.c:777
static PVOID AtaReqMapBuffer(_In_ PATAPORT_IO_CONTEXT Device, _In_ PATA_DEVICE_REQUEST Request)
Definition: scsi.c:566
static BOOLEAN AtaReqGetScatterGatherList(_In_ PATAPORT_PORT_DATA PortData, _In_ PATA_DEVICE_REQUEST Request)
Definition: scsi.c:606
#define MmGetMdlVirtualAddress(_Mdl)
#define PoSetDeviceBusy(IdlePointer)

Referenced by AtaPortSendRequest(), AtaReqCallSendRequestSerialized(), and AtaReqDispatchRequest().

◆ AtaReqSetFixedAtaSenseData()

UCHAR AtaReqSetFixedAtaSenseData ( _In_ PATA_DEVICE_REQUEST  Request)

Definition at line 248 of file satl.c.

250{
251 SCSI_SENSE_CODE SenseCode;
252 UCHAR SrbStatus, SK, ASK, ASCQ;
253
255
256 if (!AtaReqTranslateFixedError(Request, &SK, &ASK, &ASCQ))
257 return Request->SrbStatus;
258
259 SenseCode.SrbStatus = Request->SrbStatus;
260 SenseCode.SenseKey = SK;
261 SenseCode.AdditionalSenseCode = ASK;
262 SenseCode.AdditionalSenseCodeQualifier = ASCQ;
263
264 SrbStatus = AtaReqSetFixedSenseData(Request->Srb, SenseCode);
266
267 return SrbStatus;
268}
UCHAR AtaReqSetFixedSenseData(_In_ PSCSI_REQUEST_BLOCK Srb, _In_ SCSI_SENSE_CODE SenseCode)
Definition: scsi.c:411
VOID AtaReqSetLbaInformation(_In_ PSCSI_REQUEST_BLOCK Srb, _In_ ULONG64 Lba)
Definition: scsi.c:442
#define SRB_STATUS_AUTOSENSE_VALID
Definition: srb.h:387
static BOOLEAN AtaReqTranslateFixedError(_In_ PATA_DEVICE_REQUEST Request, _Out_ PUCHAR SK, _Out_ PUCHAR ASK, _Out_ PUCHAR ASCQ)
Definition: satl.c:163
static ULONG64 AtaReqLbaFromTaskFile(_In_ PATA_DEVICE_REQUEST Request)
Definition: satl.c:119
UCHAR SenseKey
Definition: scsiex.h:17
UCHAR AdditionalSenseCodeQualifier
Definition: scsiex.h:19
UCHAR SrbStatus
Definition: scsiex.h:16
UCHAR AdditionalSenseCode
Definition: scsiex.h:18

Referenced by AtaDeviceGenericRecovery(), AtaDeviceHandleRequestSense(), and AtaDeviceNcqRecovery().

◆ AtaReqSetFixedSenseData()

UCHAR AtaReqSetFixedSenseData ( _In_ PSCSI_REQUEST_BLOCK  Srb,
_In_ SCSI_SENSE_CODE  SenseCode 
)

Definition at line 411 of file scsi.c.

414{
415 SENSE_DATA SenseData;
416
417 if ((Srb->SenseInfoBuffer == NULL) || (Srb->SenseInfoBufferLength == 0))
418 return SenseCode.SrbStatus;
419
420 ASSERT(!(SenseCode.SrbStatus & SRB_STATUS_AUTOSENSE_VALID));
421
423
424 // TODO: D_SENSE (fixed or descriptor format) is not supported yet
425 RtlZeroMemory(&SenseData, sizeof(SenseData));
426 SenseData.Valid = 1;
428 SenseData.SenseKey = SenseCode.SenseKey;
429 SenseData.AdditionalSenseCode = SenseCode.AdditionalSenseCode;
430 SenseData.AdditionalSenseCodeQualifier = SenseCode.AdditionalSenseCodeQualifier;
431 SenseData.AdditionalSenseLength =
432 sizeof(SenseData) - RTL_SIZEOF_THROUGH_FIELD(SENSE_DATA, AdditionalSenseLength);
433
435 &SenseData,
436 min(Srb->SenseInfoBufferLength, sizeof(SenseData)));
437
438 return SenseCode.SrbStatus | SRB_STATUS_AUTOSENSE_VALID;
439}
#define SCSISTAT_CHECK_CONDITION
Definition: cdrw_hw.h:1079
#define min(a, b)
Definition: monoChain.cc:55
#define SCSI_SENSE_ERRORCODE_FIXED_CURRENT
Definition: scsi.h:623
UCHAR SenseInfoBufferLength
Definition: srb.h:259
PVOID SenseInfoBuffer
Definition: srb.h:264
UCHAR ScsiStatus
Definition: srb.h:252
UCHAR AdditionalSenseLength
Definition: cdrw_hw.h:1173
UCHAR AdditionalSenseCode
Definition: cdrw_hw.h:1175
UCHAR ErrorCode
Definition: cdrw_hw.h:1164
UCHAR AdditionalSenseCodeQualifier
Definition: cdrw_hw.h:1176
UCHAR SenseKey
Definition: cdrw_hw.h:1167
UCHAR Valid
Definition: cdrw_hw.h:1165

Referenced by AtaDeviceHandleRequestSense(), AtaDeviceNcqRecovery(), AtaReqCompleteReadCapacity(), AtaReqScsiRequestSense(), AtaReqSetFixedAtaSenseData(), AtaReqTerminateInvalidField(), AtaReqTerminateInvalidFieldParameter(), AtaReqTerminateInvalidOpCode(), and AtaReqTerminateInvalidRange().

◆ AtaReqSetLbaInformation()

VOID AtaReqSetLbaInformation ( _In_ PSCSI_REQUEST_BLOCK  Srb,
_In_ ULONG64  Lba 
)

Definition at line 442 of file scsi.c.

445{
446 PSENSE_DATA SenseData;
447
448 if ((Srb->SenseInfoBuffer == NULL) || (Srb->SenseInfoBufferLength == 0))
449 return;
450
451 SenseData = Srb->SenseInfoBuffer;
452
454 {
455 ASSERT(SenseData->Valid);
456
457 SenseData->Information[0] = (UCHAR)(Lba >> 24);
458 SenseData->Information[1] = (UCHAR)(Lba >> 16);
459 SenseData->Information[2] = (UCHAR)(Lba >> 8);
460 SenseData->Information[3] = (UCHAR)(Lba >> 0);
461 }
462
463 // TODO: D_SENSE (fixed or descriptor format) is not supported yet
464}
#define RTL_CONTAINS_FIELD(Struct, Size, Field)
Definition: ntbasedef.h:687
UCHAR Information[4]
Definition: cdrw_hw.h:1172
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1049

Referenced by AtaDeviceNcqRecovery(), and AtaReqSetFixedAtaSenseData().

◆ AtaReqSmartIoControl()

UCHAR AtaReqSmartIoControl ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ PATA_DEVICE_REQUEST  Request,
_In_ PSCSI_REQUEST_BLOCK  Srb 
)

Definition at line 92 of file smart.c.

96{
97 union _PARAMS
98 {
99 PSENDCMDINPARAMS CmdIn;
100 PSENDCMDOUTPARAMS CmdOut;
101 } Buffer;
102
103 if (Srb->DataTransferLength < (sizeof(SRB_IO_CONTROL) + sizeof(*Buffer.CmdIn) - 1))
105
107
108 if (Buffer.CmdIn->irDriveRegs.bCommandReg != SMART_CMD)
110
111 switch (Buffer.CmdIn->irDriveRegs.bFeaturesReg)
112 {
113 case READ_ATTRIBUTES:
114 {
115 Request->DataTransferLength = READ_ATTRIBUTE_BUFFER_SIZE;
117 break;
118 }
119
120 case READ_THRESHOLDS:
121 {
122 Request->DataTransferLength = READ_THRESHOLD_BUFFER_SIZE;
124 break;
125 }
126
127 case SMART_READ_LOG:
128 {
129 Request->DataTransferLength =
130 Buffer.CmdIn->irDriveRegs.bSectorCountReg * SMART_LOG_SECTOR_SIZE;
132 break;
133 }
134
135 case SMART_WRITE_LOG:
136 {
137 Request->DataTransferLength =
138 Buffer.CmdIn->irDriveRegs.bSectorCountReg * SMART_LOG_SECTOR_SIZE;
140 break;
141 }
142
144 {
145 Request->DataTransferLength = sizeof(IDEREGS);
147 break;
148 }
149
151 {
152 UCHAR Subcommand = Buffer.CmdIn->irDriveRegs.bSectorNumberReg;
153
154 if (Subcommand == SMART_SHORT_SELFTEST_CAPTIVE ||
156 {
158 }
159
161 }
164 case ENABLE_SMART:
165 case DISABLE_SMART:
167 {
168 Request->DataTransferLength = 0;
169 Request->Flags = 0;
170 break;
171 }
172
173 default:
175 }
176
178 {
180 (sizeof(SRB_IO_CONTROL) + sizeof(*Buffer.CmdOut) - 1 + Request->DataTransferLength))
181 {
183 }
184
185 Request->DataBuffer = Buffer.CmdOut->bBuffer;
186 }
187 else if (Request->Flags & REQUEST_FLAG_DATA_OUT)
188 {
190 (sizeof(SRB_IO_CONTROL) + sizeof(*Buffer.CmdIn) - 1 + Request->DataTransferLength))
191 {
193 }
194
195 Request->DataBuffer = Buffer.CmdIn->bBuffer;
196 }
197
199
200 AtaIdeRegsToTaskFile(DevExt, &Buffer.CmdIn->irDriveRegs, Request);
201
202 return SRB_STATUS_PENDING;
203}
#define REQUEST_FLAG_SAVE_TASK_FILE
Definition: ata_shared.h:309
#define SMART_CMD
Definition: helper.h:21
struct _IDEREGS IDEREGS
#define SRB_STATUS_PENDING
Definition: srb.h:340
#define SMART_WRITE_LOG
Definition: ntdddisk.h:745
#define EXECUTE_OFFLINE_DIAGS
Definition: ntdddisk.h:743
#define READ_ATTRIBUTE_BUFFER_SIZE
Definition: ntdddisk.h:726
#define ENABLE_SMART
Definition: ntdddisk.h:746
#define SMART_SHORT_SELFTEST_CAPTIVE
Definition: ntdddisk.h:716
#define SAVE_ATTRIBUTE_VALUES
Definition: ntdddisk.h:742
#define RETURN_SMART_STATUS
Definition: ntdddisk.h:748
#define READ_THRESHOLDS
Definition: ntdddisk.h:740
#define SMART_READ_LOG
Definition: ntdddisk.h:744
#define SMART_LOG_SECTOR_SIZE
Definition: ntdddisk.h:729
#define DISABLE_SMART
Definition: ntdddisk.h:747
#define SMART_EXTENDED_SELFTEST_CAPTIVE
Definition: ntdddisk.h:717
#define ENABLE_DISABLE_AUTO_OFFLINE
Definition: ntdddisk.h:749
#define READ_ATTRIBUTES
Definition: ntdddisk.h:739
#define READ_THRESHOLD_BUFFER_SIZE
Definition: ntdddisk.h:728
#define ENABLE_DISABLE_AUTOSAVE
Definition: ntdddisk.h:741
#define __fallthrough
Definition: sal_old.h:314
static VOID AtaIdeRegsToTaskFile(_In_ ATAPORT_DEVICE_EXTENSION *__restrict DevExt, _In_ IDEREGS *__restrict IdeRegs, _Out_ ATA_DEVICE_REQUEST *__restrict Request)
Definition: smart.c:16
static ATA_COMPLETION_ACTION AtaReqCompleteSmartIoControl(_In_ PATA_DEVICE_REQUEST Request)
Definition: smart.c:54

Referenced by AtaReqTranslateRequest().

◆ AtaReqStartCompletionDpc()

VOID AtaReqStartCompletionDpc ( _In_ PATA_DEVICE_REQUEST  Request)

Definition at line 777 of file scsi.c.

779{
781
784}
BOOLEAN NTAPI KeInsertQueueDpc(IN PKDPC Dpc, IN PVOID SystemArgument1, IN PVOID SystemArgument2)
Definition: dpc.c:725
SLIST_HEADER AtapCompletionQueueList
Definition: scsi.c:14
KDPC AtapCompletionDpc
Definition: scsi.c:15
#define InterlockedPushEntrySList(SListHead, SListEntry)
Definition: rtlfuncs.h:3406

Referenced by AtaPortGetNextEvent(), AtaPortQueueEvent(), AtaReqSendRequest(), AtaReqStartIo(), and AtaReqStartRequest().

◆ AtaReqThawQueue()

DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqThawQueue ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ ULONG  ReasonFlags 
)

Definition at line 1365 of file scsi.c.

1368{
1369 PATAPORT_IO_CONTEXT Device = &DevExt->Device;
1370 PATAPORT_PORT_DATA PortData;
1371 KIRQL OldIrql;
1372
1375
1376 if (Device->FreeRequestsBitmap != Device->MaxRequestsBitmap)
1378
1379 PortData = Device->PortData;
1381 if (!AtaReqPortQueueListDispatchNextRequest(PortData))
1383
1384 _InterlockedAnd(&Device->QueueFlags, ~ReasonFlags);
1385
1388
1390}
static BOOLEAN AtaReqDeviceQueueDispatchNextRequest(_In_ PATAPORT_IO_CONTEXT Device)
Definition: scsi.c:1218
static VOID AtaDeviceCheckPowerState(_In_ PATAPORT_IO_CONTEXT Device)
Definition: scsi.c:75
KSPIN_LOCK QueueLock
Definition: atapi.h:363

Referenced by AtaPdoDispatchScsi(), AtaPdoStartDevice(), AtaPortDeviceProcessPowerChange(), and AtaPortExitStateMachine().

◆ AtaReqWaitForOutstandingIoToComplete()

DECLSPEC_NOINLINE_FROM_PAGED VOID AtaReqWaitForOutstandingIoToComplete ( _In_ PATAPORT_IO_CONTEXT  Device,
_In_ PSCSI_REQUEST_BLOCK  Srb 
)

Definition at line 1395 of file scsi.c.

1398{
1399 KIRQL OldIrql;
1400 BOOLEAN DoWait;
1402
1405
1406 ASSERT(Device->QueueFlags & QUEUE_FLAGS_FROZEN);
1407
1408 KeClearEvent(&Device->QueueStoppedEvent);
1409
1410 if (Srb)
1411 Device->QuiescenceSrb = Srb;
1412
1413 /* Wait for all the active IRPs to finish executing */
1414 if (Device->FreeRequestsBitmap != Device->MaxRequestsBitmap)
1415 {
1416 Device->QueueFlags |= QUEUE_FLAG_SIGNAL_STOP;
1417 DoWait = !Srb;
1418 }
1419 else
1420 {
1422
1423 KeSetEvent(&Device->QueueStoppedEvent, 0, FALSE);
1424 DoWait = FALSE;
1425 }
1426
1428
1431
1432 /* Requeue the pending request */
1433 if (Request)
1434 {
1435 Request->SrbStatus = SRB_STATUS_BUSY;
1436 Request->InternalState = REQUEST_STATE_NOT_STARTED;
1437
1441 }
1442
1443 if (!DoWait)
1444 return;
1445
1446 KeWaitForSingleObject(&Device->QueueStoppedEvent, Executive, KernelMode, FALSE, NULL);
1447}
#define QUEUE_FLAGS_FROZEN
Definition: atapi.h:114
#define QUEUE_FLAG_SIGNAL_STOP
Definition: atapi.h:108
#define SRB_STATUS_BUSY
Definition: srb.h:345
static VOID AtaDeviceQueueEmptyEvent(_In_ PATAPORT_IO_CONTEXT Device)
Definition: scsi.c:113

Referenced by AtaPdoHandleQuiesceDevice(), and AtaPdoStopDevice().

◆ AtaSetPortRegistryKey()

VOID AtaSetPortRegistryKey ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ PCWSTR  KeyName,
_In_ ULONG  KeyValue 
)

Definition at line 236 of file atapi.c.

240{
241 HANDLE HwKeyHandle;
244
245 PAGED_CODE();
246
247 Status = IoOpenDeviceRegistryKey(ChanExt->Pdo,
250 &HwKeyHandle);
251 if (!NT_SUCCESS(Status))
252 {
253 TRACE("Failed to open device hardware key, status 0x%lx\n", Status);
254 return;
255 }
256
258 Status = ZwSetValueKey(HwKeyHandle,
259 &ValueName,
260 0,
261 REG_DWORD,
262 &KeyValue,
263 sizeof(KeyValue));
264 ZwClose(HwKeyHandle);
265 if (!NT_SUCCESS(Status))
266 {
267 TRACE("Failed to set '%wZ' key, status 0x%lx\n", &ValueName, Status);
268 }
269}

Referenced by AtaFdoStartDevice().

◆ AtaSetRegistryKey()

VOID AtaSetRegistryKey ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ UCHAR  TargetId,
_In_ PCWSTR  KeyName,
_In_ ULONG  KeyValue 
)

Definition at line 180 of file atapi.c.

185{
186 HANDLE HwKeyHandle, TargetKeyHandle;
187 UNICODE_STRING ValueName, TargetKeyName;
189 WCHAR TargetKeyBuffer[sizeof("Target99")];
190
191 PAGED_CODE();
192
193 Status = IoOpenDeviceRegistryKey(ChanExt->Pdo,
196 &HwKeyHandle);
197 if (!NT_SUCCESS(Status))
198 {
199 TRACE("Failed to open device hardware key, status 0x%lx\n", Status);
200 return;
201 }
202
203 /* Open or create the 'TargetX' key */
204 Status = RtlStringCbPrintfW(TargetKeyBuffer,
205 sizeof(TargetKeyBuffer),
206 L"Target%u",
207 TargetId);
209 RtlInitUnicodeString(&TargetKeyName, TargetKeyBuffer);
210 Status = AtaOpenRegistryKey(&TargetKeyHandle, HwKeyHandle, &TargetKeyName, TRUE);
211 if (!NT_SUCCESS(Status))
212 {
213 TRACE("Failed to create '%wZ' key, status 0x%lx\n", &TargetKeyName, Status);
214 goto Cleanup;
215 }
216
218 Status = ZwSetValueKey(TargetKeyHandle,
219 &ValueName,
220 0,
221 REG_DWORD,
222 &KeyValue,
223 sizeof(KeyValue));
224 ZwClose(TargetKeyHandle);
225 if (!NT_SUCCESS(Status))
226 {
227 TRACE("Failed to set '%wZ' key, status 0x%lx\n", &ValueName, Status);
228 }
229
230Cleanup:
231 ZwClose(HwKeyHandle);
232}

Referenced by AtaFdoInitializeDeviceRelations(), and AtaPdoInit().

◆ AtaSwapIdString()

VOID AtaSwapIdString ( _Inout_updates_bytes_(WordCount *sizeof(USHORT)) PVOID  Buffer,
_In_range_(>, 0) ULONG  WordCount 
)

Definition at line 64 of file enum.c.

67{
68 PUSHORT Word = Buffer;
69
70 /* The buffer should be USHORT aligned for ARM compatibility */
71 ASSERT(((ULONG_PTR)Buffer & 1) == 0);
72
73 while (WordCount--)
74 {
75 *Word = RtlUshortByteSwap(*Word);
76 ++Word;
77 }
78}
uint16_t * PUSHORT
Definition: typedefs.h:56
#define RtlUshortByteSwap(_x)
Definition: rtlfuncs.h:3214

Referenced by AtaCreateAtapiStandardInquiryData(), and AtaPdoFillIdentificationStrings().

◆ AtaTypeCodeToName()

PCSTR AtaTypeCodeToName ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ DEVICE_TYPE_NAME  Type 
)

Definition at line 42 of file atapi.c.

45{
47
48 PAGED_CODE();
49
50 DeviceType = DevExt->InquiryData.DeviceType;
52
53 switch (Type)
54 {
55 case GetDeviceType:
56 return AtapGenericDeviceNames[DeviceType].DeviceType;
57
58 case GetPeripheralId:
59 return AtapGenericDeviceNames[DeviceType].PeripheralId;
60
61 case GetGenericType:
62 if (DevExt->Device.DeviceFlags & DEVICE_IS_SUPER_FLOPPY)
63 return "GenSFloppy"; // Install the Super Floppy storage class driver
64 else
65 return AtapGenericDeviceNames[DeviceType].GenericType;
66
67 default:
70 }
71}
Type
Definition: Type.h:7
PCSTR DeviceType
Definition: atapi.c:20
static ATAPORT_PAGED_DATA const struct @1160 AtapGenericDeviceNames[]
#define DEVICE_IS_SUPER_FLOPPY
Definition: atapi.h:89
#define UNREACHABLE

Referenced by AtaPdoQueryId().

◆ C_ASSERT() [1/6]

◆ C_ASSERT() [2/6]

◆ C_ASSERT() [3/6]

◆ C_ASSERT() [4/6]

◆ C_ASSERT() [5/6]

◆ C_ASSERT() [6/6]

C_ASSERT ( sizeof(REQUEST_QUEUE_ENTRY)<=4 *sizeof(PVOID )

◆ IsPowerOfTwo()

FORCEINLINE BOOLEAN IsPowerOfTwo ( _In_ ULONG  x)

Definition at line 604 of file atapi.h.

606{
607 /* Also exclude zero numbers */
608 return (x != 0) && ((x & (x - 1)) == 0);
609}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548

Referenced by AtaAhciHandleFatalError(), and AtaReqAllocateSlot().

Variable Documentation

◆ AtaAddChannel

DRIVER_ADD_DEVICE AtaAddChannel

Definition at line 646 of file atapi.h.

Referenced by DriverEntry().

◆ AtapCompletionDpc

KDPC AtapCompletionDpc
extern

Definition at line 15 of file scsi.c.

Referenced by AtaPortOnRequestComplete(), AtaReqStartCompletionDpc(), and DriverEntry().

◆ AtapCompletionQueueList

SLIST_HEADER AtapCompletionQueueList
extern

◆ AtaPdoCompletionRoutine

IO_COMPLETION_ROUTINE AtaPdoCompletionRoutine

Definition at line 859 of file atapi.h.

Referenced by AtaPnpRepeatRequest().

◆ AtapDriverRegistryPath

UNICODE_STRING AtapDriverRegistryPath
extern

Definition at line 14 of file atapi.c.

Referenced by AtaQueryWmiRegInfo(), AtaUnload(), and DriverEntry().

◆ AtapInPEMode

BOOLEAN AtapInPEMode
extern

Definition at line 15 of file atapi.c.

Referenced by AtaDeviceLockSecurityModeFeatureCommands(), and DriverEntry().

◆ AtaPortCompleteInternalRequest

REQUEST_COMPLETION_ROUTINE AtaPortCompleteInternalRequest

Definition at line 880 of file atapi.h.

Referenced by AtaFdoStartDevice().

◆ AtaPortIoTimer

IO_TIMER_ROUTINE AtaPortIoTimer

Definition at line 938 of file atapi.h.

Referenced by AtaFdoStartDevice().

◆ AtaPortNotification

PORT_NOTIFICATION AtaPortNotification

Definition at line 881 of file atapi.h.

Referenced by AtaFdoStartDevice().

◆ AtaPortWorkerSignalDpc

KDEFERRED_ROUTINE AtaPortWorkerSignalDpc

Definition at line 879 of file atapi.h.

Referenced by AtaFdoStartDevice().

◆ AtaPortWorkerThread

KSTART_ROUTINE AtaPortWorkerThread

◆ AtaReqCompletionDpc

KDEFERRED_ROUTINE AtaReqCompletionDpc

Definition at line 939 of file atapi.h.

Referenced by DriverEntry().

◆ AtaStorageNotificationlDpc

KDEFERRED_ROUTINE AtaStorageNotificationlDpc

Definition at line 655 of file atapi.h.

Referenced by AtaFdoStartDevice(), and AtaStorageNotificationlDpc().

◆ AtaStorageNotificationWorker

IO_WORKITEM_ROUTINE AtaStorageNotificationWorker

Definition at line 654 of file atapi.h.

Referenced by AtaStorageNotificationlDpc().

◆ AtaUnload

DRIVER_UNLOAD AtaUnload

Definition at line 649 of file atapi.h.

Referenced by DriverEntry().

◆ DriverEntry

DRIVER_INITIALIZE DriverEntry

Definition at line 652 of file atapi.h.