ReactOS  0.4.15-dev-3316-g067ca88
scsiport.c File Reference
#include <freeldr.h>
#include <debug.h>
#include <ntddk.h>
#include <srb.h>
#include <scsi.h>
#include <ntddscsi.h>
#include <ntddstor.h>
#include <ntdddisk.h>
#include <stdio.h>
#include <stdarg.h>
Include dependency graph for scsiport.c:

Go to the source code of this file.

Classes

struct  SCSI_PORT_DEVICE_EXTENSION
 
struct  tagDISKCONTEXT
 

Macros

#define _SCSIPORT_
 
#define SCSI_PORT_NEXT_REQUEST_READY   0x0008
 
#define TAG_SCSI_DEVEXT   'DscS'
 
#define TAG_SCSI_ACCESS_RANGES   'AscS'
 

Typedefs

typedef struct SCSI_PORT_DEVICE_EXTENSIONPSCSI_PORT_DEVICE_EXTENSION
 
typedef struct tagDISKCONTEXT DISKCONTEXT
 

Functions

 DBG_DEFAULT_CHANNEL (SCSIPORT)
 
ULONG ntohl (IN ULONG Value)
 
static BOOLEAN SpiSendSynchronousSrb (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb)
 
static ARC_STATUS DiskClose (ULONG FileId)
 
static ARC_STATUS DiskGetFileInformation (ULONG FileId, FILEINFORMATION *Information)
 
static ARC_STATUS DiskOpen (CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
 
static ARC_STATUS DiskRead (ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
 
static ARC_STATUS DiskSeek (ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
 
static NTSTATUS SpiCreatePortConfig (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PHW_INITIALIZATION_DATA HwInitData, OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo, IN BOOLEAN ZeroStruct)
 
VOID __cdecl ScsiDebugPrint (IN ULONG DebugPrintLevel, IN PCCHAR DebugMessage, IN ...)
 
VOID NTAPI ScsiPortCompleteRequest (IN PVOID HwDeviceExtension, IN UCHAR PathId, IN UCHAR TargetId, IN UCHAR Lun, IN UCHAR SrbStatus)
 
ULONG NTAPI ScsiPortConvertPhysicalAddressToUlong (IN SCSI_PHYSICAL_ADDRESS Address)
 
SCSI_PHYSICAL_ADDRESS NTAPI ScsiPortConvertUlongToPhysicalAddress (IN ULONG_PTR UlongAddress)
 
VOID NTAPI ScsiPortFlushDma (IN PVOID DeviceExtension)
 
VOID NTAPI ScsiPortFreeDeviceBase (IN PVOID HwDeviceExtension, IN PVOID MappedAddress)
 
ULONG NTAPI ScsiPortGetBusData (IN PVOID DeviceExtension, IN ULONG BusDataType, IN ULONG SystemIoBusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
 
PVOID NTAPI ScsiPortGetDeviceBase (IN PVOID HwDeviceExtension, IN INTERFACE_TYPE BusType, IN ULONG SystemIoBusNumber, IN SCSI_PHYSICAL_ADDRESS IoAddress, IN ULONG NumberOfBytes, IN BOOLEAN InIoSpace)
 
PVOID NTAPI ScsiPortGetLogicalUnit (IN PVOID HwDeviceExtension, IN UCHAR PathId, IN UCHAR TargetId, IN UCHAR Lun)
 
SCSI_PHYSICAL_ADDRESS NTAPI ScsiPortGetPhysicalAddress (IN PVOID HwDeviceExtension, IN PSCSI_REQUEST_BLOCK Srb OPTIONAL, IN PVOID VirtualAddress, OUT ULONG *Length)
 
PSCSI_REQUEST_BLOCK NTAPI ScsiPortGetSrb (IN PVOID DeviceExtension, IN UCHAR PathId, IN UCHAR TargetId, IN UCHAR Lun, IN LONG QueueTag)
 
static NTSTATUS SpiAllocateCommonBuffer (IN OUT PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN ULONG NonCachedSize)
 
PVOID NTAPI ScsiPortGetUncachedExtension (IN PVOID HwDeviceExtension, IN PPORT_CONFIGURATION_INFORMATION ConfigInfo, IN ULONG NumberOfBytes)
 
PVOID NTAPI ScsiPortGetVirtualAddress (IN PVOID HwDeviceExtension, IN SCSI_PHYSICAL_ADDRESS PhysicalAddress)
 
static VOID SpiScanDevice (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PCHAR ArcName, IN ULONG ScsiBus, IN ULONG TargetId, IN ULONG Lun)
 
static VOID SpiScanAdapter (IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN ULONG ScsiBus, IN UCHAR PathId)
 
static VOID SpiResourceToConfig (IN PHW_INITIALIZATION_DATA HwInitializationData, IN PCM_FULL_RESOURCE_DESCRIPTOR ResourceDescriptor, IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig)
 
static BOOLEAN SpiGetPciConfigData (IN PHW_INITIALIZATION_DATA HwInitializationData, IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig, IN ULONG BusNumber, IN OUT PPCI_SLOT_NUMBER NextSlotNumber)
 
ULONG NTAPI ScsiPortInitialize (IN PVOID Argument1, IN PVOID Argument2, IN PHW_INITIALIZATION_DATA HwInitializationData, IN PVOID HwContext OPTIONAL)
 
VOID NTAPI ScsiPortIoMapTransfer (IN PVOID HwDeviceExtension, IN PSCSI_REQUEST_BLOCK Srb, IN PVOID LogicalAddress, IN ULONG Length)
 
VOID NTAPI ScsiPortLogError (IN PVOID HwDeviceExtension, IN PSCSI_REQUEST_BLOCK Srb OPTIONAL, IN UCHAR PathId, IN UCHAR TargetId, IN UCHAR Lun, IN ULONG ErrorCode, IN ULONG UniqueId)
 
VOID NTAPI ScsiPortMoveMemory (IN PVOID WriteBuffer, IN PVOID ReadBuffer, IN ULONG Length)
 
VOID __cdecl ScsiPortNotification (IN SCSI_NOTIFICATION_TYPE NotificationType, IN PVOID HwDeviceExtension, IN ...)
 
VOID NTAPI ScsiPortReadPortBufferUchar (IN PUCHAR Port, OUT PUCHAR Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortReadPortBufferUlong (IN PULONG Port, OUT PULONG Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortReadPortBufferUshort (IN PUSHORT Port, OUT PUSHORT Buffer, IN ULONG Count)
 
UCHAR NTAPI ScsiPortReadPortUchar (IN PUCHAR Port)
 
ULONG NTAPI ScsiPortReadPortUlong (IN PULONG Port)
 
USHORT NTAPI ScsiPortReadPortUshort (IN PUSHORT Port)
 
VOID NTAPI ScsiPortReadRegisterBufferUchar (IN PUCHAR Register, IN PUCHAR Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortReadRegisterBufferUlong (IN PULONG Register, IN PULONG Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortReadRegisterBufferUshort (IN PUSHORT Register, IN PUSHORT Buffer, IN ULONG Count)
 
UCHAR NTAPI ScsiPortReadRegisterUchar (IN PUCHAR Register)
 
ULONG NTAPI ScsiPortReadRegisterUlong (IN PULONG Register)
 
USHORT NTAPI ScsiPortReadRegisterUshort (IN PUSHORT Register)
 
ULONG NTAPI ScsiPortSetBusDataByOffset (IN PVOID DeviceExtension, IN ULONG BusDataType, IN ULONG SystemIoBusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
 
VOID NTAPI ScsiPortStallExecution (IN ULONG Delay)
 
BOOLEAN NTAPI ScsiPortValidateRange (IN PVOID HwDeviceExtension, IN INTERFACE_TYPE BusType, IN ULONG SystemIoBusNumber, IN SCSI_PHYSICAL_ADDRESS IoAddress, IN ULONG NumberOfBytes, IN BOOLEAN InIoSpace)
 
VOID NTAPI ScsiPortWritePortBufferUchar (IN PUCHAR Port, IN PUCHAR Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortWritePortBufferUlong (IN PULONG Port, IN PULONG Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortWritePortBufferUshort (IN PUSHORT Port, IN PUSHORT Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortWritePortUchar (IN PUCHAR Port, IN UCHAR Value)
 
VOID NTAPI ScsiPortWritePortUlong (IN PULONG Port, IN ULONG Value)
 
VOID NTAPI ScsiPortWritePortUshort (IN PUSHORT Port, IN USHORT Value)
 
VOID NTAPI ScsiPortWriteRegisterBufferUchar (IN PUCHAR Register, IN PUCHAR Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortWriteRegisterBufferUlong (IN PULONG Register, IN PULONG Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortWriteRegisterBufferUshort (IN PUSHORT Register, IN PUSHORT Buffer, IN ULONG Count)
 
VOID NTAPI ScsiPortWriteRegisterUchar (IN PUCHAR Register, IN UCHAR Value)
 
VOID NTAPI ScsiPortWriteRegisterUlong (IN PULONG Register, IN ULONG Value)
 
VOID NTAPI ScsiPortWriteRegisterUshort (IN PUSHORT Register, IN USHORT Value)
 
ULONG LoadBootDeviceDriver (VOID)
 

Variables

PSCSI_PORT_DEVICE_EXTENSION ScsiDeviceExtensions [SCSI_MAXIMUM_BUSES]
 
static const DEVVTBL DiskVtbl
 
char __ImageBase
 

Macro Definition Documentation

◆ _SCSIPORT_

#define _SCSIPORT_

Definition at line 16 of file scsiport.c.

◆ SCSI_PORT_NEXT_REQUEST_READY

#define SCSI_PORT_NEXT_REQUEST_READY   0x0008

Definition at line 54 of file scsiport.c.

◆ TAG_SCSI_ACCESS_RANGES

#define TAG_SCSI_ACCESS_RANGES   'AscS'

Definition at line 57 of file scsiport.c.

◆ TAG_SCSI_DEVEXT

#define TAG_SCSI_DEVEXT   'DscS'

Definition at line 56 of file scsiport.c.

Typedef Documentation

◆ DISKCONTEXT

◆ PSCSI_PORT_DEVICE_EXTENSION

Function Documentation

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( SCSIPORT  )

◆ DiskClose()

static ARC_STATUS DiskClose ( ULONG  FileId)
static

Definition at line 177 of file scsiport.c.

178 {
181  return ESUCCESS;
182 }
Definition: arc.h:32
VOID * FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:416
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ DiskGetFileInformation()

static ARC_STATUS DiskGetFileInformation ( ULONG  FileId,
FILEINFORMATION Information 
)
static

Definition at line 184 of file scsiport.c.

185 {
187 
189 
190  /*
191  * The ARC specification mentions that for partitions, StartingAddress and
192  * EndingAddress are the start and end positions of the partition in terms
193  * of byte offsets from the start of the disk.
194  * CurrentAddress is the current offset into (i.e. relative to) the partition.
195  */
196  Information->StartingAddress.QuadPart = Context->SectorOffset * Context->SectorSize;
197  Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
198  Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
199 
200  return ESUCCESS;
201 }
Definition: arc.h:32
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1044
VOID * FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:416
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

◆ DiskOpen()

static ARC_STATUS DiskOpen ( CHAR Path,
OPENMODE  OpenMode,
ULONG FileId 
)
static

Definition at line 203 of file scsiport.c.

204 {
206  PCDB Cdb;
208 
210  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
211  ULONG ScsiBus, PathId, TargetId, Lun, Partition, PathSyntax;
215 
216  /* Parse ARC path */
217  if (!DissectArcPath2(Path, &ScsiBus, &TargetId, &Lun, &Partition, &PathSyntax))
218  return EINVAL;
219  if (PathSyntax != 0) /* scsi() format */
220  return EINVAL;
221  DeviceExtension = ScsiDeviceExtensions[ScsiBus];
222  PathId = ScsiBus - DeviceExtension->BusNum;
223 
224  /* Get disk capacity and sector size */
226  if (!Srb)
227  return ENOMEM;
229  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
231  Srb->PathId = (UCHAR)PathId;
233  Srb->Lun = (UCHAR)Lun;
234  Srb->CdbLength = 10;
237  Srb->TimeOutValue = 5; /* in seconds */
239  Cdb = (PCDB)Srb->Cdb;
240  Cdb->CDB10.OperationCode = SCSIOP_READ_CAPACITY;
241  if (!SpiSendSynchronousSrb(DeviceExtension, Srb))
242  {
243  return EIO;
244  }
245 
246  /* Transform result to host endianness */
249 
250  if (Partition != 0)
251  {
252  /* Need to offset start of disk and length */
254  return EIO;
255  }
256 
258  if (!Context)
259  return ENOMEM;
260  Context->DeviceExtension = DeviceExtension;
261  Context->PathId = (UCHAR)PathId;
262  Context->TargetId = (UCHAR)TargetId;
263  Context->Lun = (UCHAR)Lun;
264  Context->SectorSize = SectorSize;
265  Context->SectorOffset = SectorOffset;
266  Context->SectorCount = SectorCount;
267  Context->SectorNumber = 0;
268  FsSetDeviceSpecific(*FileId, Context);
269 
270  return ESUCCESS;
271 }
PSCSI_PORT_DEVICE_EXTENSION ScsiDeviceExtensions[SCSI_MAXIMUM_BUSES]
Definition: scsiport.c:109
ULONG SrbFlags
Definition: srb.h:252
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR _In_ UCHAR Lun
Definition: classpnp.h:1310
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
UCHAR Cdb[16]
Definition: srb.h:271
Definition: arc.h:32
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR PathId
Definition: classpnp.h:1310
PVOID DataBuffer
Definition: srb.h:255
Definition: arc.h:39
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR TargetId
Definition: classpnp.h:1310
ULONG DataTransferLength
Definition: srb.h:253
Definition: cdrw_hw.h:28
ULONG ntohl(IN ULONG Value)
Definition: scsiport.c:114
UCHAR CdbLength
Definition: srb.h:250
ULONG LogicalBlockAddress
Definition: cdrw_hw.h:1471
struct _CDB::_CDB10 CDB10
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define SRB_FLAGS_DATA_IN
Definition: srb.h:392
ULONG TimeOutValue
Definition: srb.h:254
Definition: arc.h:48
#define SectorOffset(L)
Definition: cdprocs.h:1622
union _CDB * PCDB
UCHAR TargetId
Definition: srb.h:246
uint64_t ULONGLONG
Definition: typedefs.h:67
UCHAR Function
Definition: srb.h:242
VOID FsSetDeviceSpecific(ULONG FileId, VOID *Specific)
Definition: fs.c:409
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
Definition: scratch.h:156
_In_ PREAD_CAPACITY_DATA ReadCapacityBuffer
Definition: cdrom.h:1103
USHORT Length
Definition: srb.h:241
BOOLEAN DissectArcPath2(IN PCSTR ArcPath, OUT PULONG x, OUT PULONG y, OUT PULONG z, OUT PULONG Partition, OUT PULONG PathSyntax)
Definition: arcname.c:121
struct _SCSI_REQUEST_BLOCK SCSI_REQUEST_BLOCK
struct _READ_CAPACITY_DATA READ_CAPACITY_DATA
unsigned char UCHAR
Definition: xmlstorage.h:181
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
ULONG SectorCount
Definition: part_xbox.c:31
PRTL_UNICODE_STRING_BUFFER Path
UCHAR PathId
Definition: srb.h:245
Definition: arc.h:40
#define SCSIOP_READ_CAPACITY
Definition: cdrw_hw.h:904
struct tagContext Context
Definition: acpixf.h:1034
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:115
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
static BOOLEAN SpiSendSynchronousSrb(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb)
Definition: scsiport.c:130
_In_ ULONG SectorSize
Definition: halfuncs.h:291

◆ DiskRead()

static ARC_STATUS DiskRead ( ULONG  FileId,
VOID Buffer,
ULONG  N,
ULONG Count 
)
static

Definition at line 273 of file scsiport.c.

274 {
277  PCDB Cdb;
278  ULONG FullSectors, NbSectors;
279  ULONG Lba;
280 
281  *Count = 0;
282 
283  if (N == 0)
284  return ESUCCESS;
285 
286  FullSectors = N / Context->SectorSize;
287  NbSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
288  if (Context->SectorNumber + NbSectors >= Context->SectorCount)
289  return EINVAL;
290  if (FullSectors > 0xffff)
291  return EINVAL;
292 
293  /* Read full sectors */
294  ASSERT(Context->SectorNumber < 0xFFFFFFFF);
295  Lba = (ULONG)(Context->SectorOffset + Context->SectorNumber);
296  if (FullSectors > 0)
297  {
299  if (!Srb)
300  return ENOMEM;
301 
303  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
305  Srb->PathId = Context->PathId;
306  Srb->TargetId = Context->TargetId;
307  Srb->Lun = Context->Lun;
308  Srb->CdbLength = 10;
310  Srb->DataTransferLength = FullSectors * Context->SectorSize;
311  Srb->TimeOutValue = 5; /* in seconds */
312  Srb->DataBuffer = Buffer;
313  Cdb = (PCDB)Srb->Cdb;
314  Cdb->CDB10.OperationCode = SCSIOP_READ;
315  Cdb->CDB10.LogicalUnitNumber = Srb->Lun;
316  Cdb->CDB10.LogicalBlockByte0 = (Lba >> 24) & 0xff;
317  Cdb->CDB10.LogicalBlockByte1 = (Lba >> 16) & 0xff;
318  Cdb->CDB10.LogicalBlockByte2 = (Lba >> 8) & 0xff;
319  Cdb->CDB10.LogicalBlockByte3 = Lba & 0xff;
320  Cdb->CDB10.TransferBlocksMsb = (FullSectors >> 8) & 0xff;
321  Cdb->CDB10.TransferBlocksLsb = FullSectors & 0xff;
322  if (!SpiSendSynchronousSrb(Context->DeviceExtension, Srb))
323  {
324  return EIO;
325  }
326  Buffer = (PUCHAR)Buffer + FullSectors * Context->SectorSize;
327  N -= FullSectors * Context->SectorSize;
328  *Count += FullSectors * Context->SectorSize;
329  Context->SectorNumber += FullSectors;
330  Lba += FullSectors;
331  }
332 
333  /* Read incomplete last sector */
334  if (N > 0)
335  {
336  PUCHAR Sector;
337 
338  Sector = ExAllocatePool(PagedPool, Context->SectorSize);
339  if (!Sector)
340  return ENOMEM;
341 
343  if (!Srb)
344  {
345  ExFreePool(Sector);
346  return ENOMEM;
347  }
348 
350  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
352  Srb->PathId = Context->PathId;
353  Srb->TargetId = Context->TargetId;
354  Srb->Lun = Context->Lun;
355  Srb->CdbLength = 10;
357  Srb->DataTransferLength = Context->SectorSize;
358  Srb->TimeOutValue = 5; /* in seconds */
359  Srb->DataBuffer = Sector;
360  Cdb = (PCDB)Srb->Cdb;
361  Cdb->CDB10.OperationCode = SCSIOP_READ;
362  Cdb->CDB10.LogicalUnitNumber = Srb->Lun;
363  Cdb->CDB10.LogicalBlockByte0 = (Lba >> 24) & 0xff;
364  Cdb->CDB10.LogicalBlockByte1 = (Lba >> 16) & 0xff;
365  Cdb->CDB10.LogicalBlockByte2 = (Lba >> 8) & 0xff;
366  Cdb->CDB10.LogicalBlockByte3 = Lba & 0xff;
367  Cdb->CDB10.TransferBlocksMsb = 0;
368  Cdb->CDB10.TransferBlocksLsb = 1;
369  if (!SpiSendSynchronousSrb(Context->DeviceExtension, Srb))
370  {
371  ExFreePool(Sector);
372  return EIO;
373  }
374  RtlCopyMemory(Buffer, Sector, N);
375  *Count += N;
376  /* Context->SectorNumber remains untouched (incomplete sector read) */
377  ExFreePool(Sector);
378  }
379 
380  return ESUCCESS;
381 }
ULONG SrbFlags
Definition: srb.h:252
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
UCHAR Cdb[16]
Definition: srb.h:271
Definition: arc.h:32
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
PVOID DataBuffer
Definition: srb.h:255
Definition: arc.h:39
unsigned char * PUCHAR
Definition: retypes.h:3
ULONG DataTransferLength
Definition: srb.h:253
Definition: cdrw_hw.h:28
UCHAR CdbLength
Definition: srb.h:250
struct _CDB::_CDB10 CDB10
if(dx==0 &&dy==0)
Definition: linetemp.h:174
#define SRB_FLAGS_DATA_IN
Definition: srb.h:392
ULONG TimeOutValue
Definition: srb.h:254
VOID * FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:416
Definition: arc.h:48
#define SCSIOP_READ
Definition: cdrw_hw.h:905
union _CDB * PCDB
Definition: bufpool.h:45
UCHAR TargetId
Definition: srb.h:246
int Count
Definition: noreturn.cpp:7
#define ASSERT(a)
Definition: mode.c:44
UCHAR Function
Definition: srb.h:242
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
Definition: scratch.h:156
USHORT Length
Definition: srb.h:241
struct _SCSI_REQUEST_BLOCK SCSI_REQUEST_BLOCK
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
UCHAR PathId
Definition: srb.h:245
Definition: arc.h:40
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
static BOOLEAN SpiSendSynchronousSrb(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb)
Definition: scsiport.c:130
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

◆ DiskSeek()

static ARC_STATUS DiskSeek ( ULONG  FileId,
LARGE_INTEGER Position,
SEEKMODE  SeekMode 
)
static

Definition at line 383 of file scsiport.c.

384 {
386  LARGE_INTEGER NewPosition = *Position;
387 
388  switch (SeekMode)
389  {
390  case SeekAbsolute:
391  break;
392  case SeekRelative:
393  NewPosition.QuadPart += (Context->SectorNumber * Context->SectorSize);
394  break;
395  default:
396  ASSERT(FALSE);
397  return EINVAL;
398  }
399 
400  if (NewPosition.QuadPart & (Context->SectorSize - 1))
401  return EINVAL;
402 
403  /* Convert in number of sectors */
404  NewPosition.QuadPart /= Context->SectorSize;
405  if (NewPosition.QuadPart >= Context->SectorCount)
406  return EINVAL;
407 
408  Context->SectorNumber = NewPosition.QuadPart;
409  return ESUCCESS;
410 }
Definition: arc.h:32
Definition: arc.h:39
static COORD Position
Definition: mouse.c:34
VOID * FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:416
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
LONGLONG QuadPart
Definition: typedefs.h:114

◆ LoadBootDeviceDriver()

ULONG LoadBootDeviceDriver ( VOID  )

Definition at line 1627 of file scsiport.c.

1628 {
1629  PIMAGE_NT_HEADERS NtHeaders;
1631  PIMAGE_IMPORT_DESCRIPTOR ImportTable;
1632  ULONG ImportTableSize;
1633  PLDR_DATA_TABLE_ENTRY BootDdDTE, FreeldrDTE;
1634  CHAR NtBootDdPath[MAX_PATH];
1635  PVOID ImageBase = NULL;
1636  ULONG (NTAPI *EntryPoint)(IN PVOID DriverObject, IN PVOID RegistryPath);
1637  BOOLEAN Success;
1638 
1639  // FIXME: Must be done *INSIDE* the HAL!
1640 #ifdef _M_IX86
1643 #endif
1644 
1645  /* Initialize the loaded module list */
1647 
1648  /* Create full ntbootdd.sys path */
1649  strcpy(NtBootDdPath, FrLdrBootPath);
1650  strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
1651 
1652  /* Load file */
1653  Success = PeLdrLoadImage(NtBootDdPath, LoaderBootDriver, &ImageBase);
1654  if (!Success)
1655  {
1656  /* That's OK. File simply doesn't exist */
1657  return ESUCCESS;
1658  }
1659 
1660  /* Allocate a DTE for ntbootdd */
1662  "NTBOOTDD.SYS", ImageBase, &BootDdDTE);
1663  if (!Success)
1664  return EIO;
1665 
1666  /* Add the PE part of freeldr.sys to the list of loaded executables, it
1667  contains ScsiPort* exports, imported by ntbootdd.sys */
1669  "FREELDR.SYS", &__ImageBase, &FreeldrDTE);
1670  if (!Success)
1671  {
1672  RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1673  return EIO;
1674  }
1675 
1676  /* Fix imports */
1678 
1679  /* Now unlinkt the DTEs, they won't be valid later */
1680  RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1681  RemoveEntryList(&FreeldrDTE->InLoadOrderLinks);
1682 
1683  if (!Success)
1684  return EIO;
1685 
1686  /* Change imports to PA */
1688  TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
1689  for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
1690  {
1691  PIMAGE_THUNK_DATA ThunkData = (PIMAGE_THUNK_DATA)VaToPa(RVA(BootDdDTE->DllBase, ImportTable->FirstThunk));
1692 
1693  while (((PIMAGE_THUNK_DATA)ThunkData)->u1.AddressOfData != 0)
1694  {
1695  ThunkData->u1.Function = (ULONG)VaToPa((PVOID)ThunkData->u1.Function);
1696  ThunkData++;
1697  }
1698  }
1699 
1700  /* Relocate image to PA */
1701  NtHeaders = RtlImageNtHeader(VaToPa(BootDdDTE->DllBase));
1702  if (!NtHeaders)
1703  return EIO;
1705  NtHeaders->OptionalHeader.ImageBase - (ULONG_PTR)BootDdDTE->DllBase,
1706  "FreeLdr",
1707  TRUE,
1708  TRUE, /* in case of conflict still return success */
1709  FALSE);
1710  if (!Success)
1711  return EIO;
1712 
1713  /* Call the entrypoint */
1714  EntryPoint = VaToPa(BootDdDTE->EntryPoint);
1715  (*EntryPoint)(NULL, NULL);
1716 
1717  return ESUCCESS;
1718 }
BOOLEAN PeLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE)
Definition: peloader.c:509
#define IN
Definition: typedefs.h:39
BOOLEAN PeLdrLoadImage(IN PCHAR FileName, IN TYPE_OF_MEMORY MemoryType, OUT PVOID *ImageBasePA)
Definition: peloader.c:701
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:39
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
Definition: arc.h:32
#define TRUE
Definition: types.h:120
char CHAR
Definition: xmlstorage.h:175
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
union _IMAGE_THUNK_DATA32::@2079 u1
struct _IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
GLdouble u1
Definition: glext.h:8308
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
PVOID DllBase
Definition: btrfs_drv.h:1926
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define FALSE
Definition: types.h:117
PVOID EntryPoint
Definition: ntddk_ex.h:203
unsigned char BOOLEAN
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
VOID NTAPI HalpInitBusHandler(VOID)
Definition: bushndlr.c:420
#define MAX_PATH
Definition: compat.h:34
#define RtlImageDirectoryEntryToData
Definition: compat.h:668
Definition: btrfs_drv.h:1922
Definition: typedefs.h:119
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:138
#define RVA(m, b)
Definition: freeldr.h:24
NTSYSAPI ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID NewAddress, _In_ LONGLONG AdditionalBias, _In_ PCCH LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define NULL
Definition: types.h:112
Definition: arc.h:40
#define RtlImageNtHeader
Definition: compat.h:665
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
char __ImageBase
Definition: mstscax.cpp:17
#define BOOLEAN
Definition: pedump.c:73
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
VOID NTAPI HalpInitializePciStubs(VOID)
Definition: pcibus.c:1102
BOOLEAN PeLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BasePA, OUT PLDR_DATA_TABLE_ENTRY *NewEntry)
Definition: peloader.c:585
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA
Definition: ntimage.h:566

Referenced by RunLoader().

◆ ntohl()

ULONG ntohl ( IN ULONG  Value)

Definition at line 114 of file scsiport.c.

116 {
117  FOUR_BYTE Dest;
119 
120  Dest.Byte0 = Source->Byte3;
121  Dest.Byte1 = Source->Byte2;
122  Dest.Byte2 = Source->Byte1;
123  Dest.Byte3 = Source->Byte0;
124 
125  return Dest.AsULong;
126 }
UCHAR Byte0
Definition: tools.h:16
struct _FOUR_BYTE * PFOUR_BYTE
UCHAR Byte3
Definition: tools.h:19
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
UCHAR Byte1
Definition: tools.h:17
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
UCHAR Byte2
Definition: tools.h:18
ULONG AsULong
Definition: scsi.h:3439

Referenced by DiskOpen().

◆ ScsiDebugPrint()

VOID __cdecl ScsiDebugPrint ( IN ULONG  DebugPrintLevel,
IN PCCHAR  DebugMessage,
IN ...   
)

Definition at line 470 of file scsiport.c.

474 {
475  va_list ap;
476  CHAR Buffer[512];
477  ULONG Length;
478 
479  if (DebugPrintLevel > 10)
480  return;
481 
482  va_start(ap, DebugMessage);
483 
484  /* Construct a string */
485  Length = _vsnprintf(Buffer, 512, DebugMessage, ap);
486 
487  /* Check if we went past the buffer */
488  if (Length == MAXULONG)
489  {
490  /* Terminate it if we went over-board */
491  Buffer[sizeof(Buffer) - 1] = '\0';
492 
493  /* Put maximum */
494  Length = sizeof(Buffer);
495  }
496 
497  /* Print the message */
498  TRACE("%s", Buffer);
499 
500  /* Cleanup */
501  va_end(ap);
502 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
char CHAR
Definition: xmlstorage.h:175
#define va_end(ap)
Definition: acmsvcex.h:90
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
#define TRACE(s)
Definition: solgame.cpp:4
va_start(ap, x)
#define MAXULONG
Definition: typedefs.h:251
#define _vsnprintf
Definition: xmlstorage.h:202
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
unsigned int ULONG
Definition: retypes.h:1

◆ ScsiPortCompleteRequest()

VOID NTAPI ScsiPortCompleteRequest ( IN PVOID  HwDeviceExtension,
IN UCHAR  PathId,
IN UCHAR  TargetId,
IN UCHAR  Lun,
IN UCHAR  SrbStatus 
)

Definition at line 506 of file scsiport.c.

512 {
513  // FIXME
515 }
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by AtapiResetController(), BT958HwResetBus(), and BusLogic_ProcessCompletedCCBs().

◆ ScsiPortConvertPhysicalAddressToUlong()

ULONG NTAPI ScsiPortConvertPhysicalAddressToUlong ( IN SCSI_PHYSICAL_ADDRESS  Address)

Definition at line 520 of file scsiport.c.

522 {
523  return Address.LowPart;
524 }
static WCHAR Address[46]
Definition: ping.c:68

◆ ScsiPortConvertUlongToPhysicalAddress()

SCSI_PHYSICAL_ADDRESS NTAPI ScsiPortConvertUlongToPhysicalAddress ( IN ULONG_PTR  UlongAddress)

◆ ScsiPortFlushDma()

VOID NTAPI ScsiPortFlushDma ( IN PVOID  DeviceExtension)

Definition at line 539 of file scsiport.c.

541 {
542  // FIXME
544 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortFreeDeviceBase()

VOID NTAPI ScsiPortFreeDeviceBase ( IN PVOID  HwDeviceExtension,
IN PVOID  MappedAddress 
)

Definition at line 548 of file scsiport.c.

551 {
552  // Nothing to do
553 }

Referenced by AtapiFindController(), AtapiFindIsaController(), AtapiFindNativeModeController(), AtapiFindPCIController(), and UniataChipDetect().

◆ ScsiPortGetBusData()

ULONG NTAPI ScsiPortGetBusData ( IN PVOID  DeviceExtension,
IN ULONG  BusDataType,
IN ULONG  SystemIoBusNumber,
IN ULONG  SlotNumber,
IN PVOID  Buffer,
IN ULONG  Length 
)

Definition at line 557 of file scsiport.c.

564 {
565  return HalGetBusDataByOffset(BusDataType, SystemIoBusNumber, SlotNumber, Buffer, 0, Length);
566 }
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:65
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
Definition: bufpool.h:45
ULONG NTAPI HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:73

Referenced by AtapiAliSouthBridgeFixup(), AtapiFindController(), AtapiFindNativeModeController(), AtapiRosbSouthBridgeFixup(), AtapiViaSouthBridgeFixup(), and FindBrokenController().

◆ ScsiPortGetDeviceBase()

PVOID NTAPI ScsiPortGetDeviceBase ( IN PVOID  HwDeviceExtension,
IN INTERFACE_TYPE  BusType,
IN ULONG  SystemIoBusNumber,
IN SCSI_PHYSICAL_ADDRESS  IoAddress,
IN ULONG  NumberOfBytes,
IN BOOLEAN  InIoSpace 
)

Definition at line 570 of file scsiport.c.

577 {
580 
581  AddressSpace = (ULONG)InIoSpace;
583  SystemIoBusNumber,
584  IoAddress,
585  &AddressSpace,
587  {
588  return NULL;
589  }
590 
591  /* I/O space */
592  if (AddressSpace != 0)
593  return (PVOID)TranslatedAddress.u.LowPart;
594 
595  // FIXME
597  return (PVOID)IoAddress.LowPart;
598 }
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:156
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2272
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2272
#define FALSE
Definition: types.h:117
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140
#define NULL
Definition: types.h:112
struct _LARGE_INTEGER::@2240 u
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by AtapiFindController(), AtapiFindIsaController(), AtapiFindNativeModeController(), AtapiFindPCIController(), AtapiGetIoRange(), BT958HwFindAdapter(), and UniataFindBusMasterController().

◆ ScsiPortGetLogicalUnit()

PVOID NTAPI ScsiPortGetLogicalUnit ( IN PVOID  HwDeviceExtension,
IN UCHAR  PathId,
IN UCHAR  TargetId,
IN UCHAR  Lun 
)

Definition at line 602 of file scsiport.c.

607 {
608  // FIXME
610  return NULL;
611 }
#define NULL
Definition: types.h:112
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortGetPhysicalAddress()

SCSI_PHYSICAL_ADDRESS NTAPI ScsiPortGetPhysicalAddress ( IN PVOID  HwDeviceExtension,
IN PSCSI_REQUEST_BLOCK Srb  OPTIONAL,
IN PVOID  VirtualAddress,
OUT ULONG Length 
)

Definition at line 615 of file scsiport.c.

620 {
621  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
623  ULONG BufferLength = 0;
624  ULONG Offset;
625 
626  TRACE("ScsiPortGetPhysicalAddress(%p %p %p %p)\n",
627  HwDeviceExtension, Srb, VirtualAddress, Length);
628 
629  DeviceExtension = ((PSCSI_PORT_DEVICE_EXTENSION)HwDeviceExtension) - 1;
630 
631  if (Srb == NULL || Srb->SenseInfoBuffer == VirtualAddress)
632  {
633  /* Simply look it up in the allocated common buffer */
634  Offset = (PUCHAR)VirtualAddress - (PUCHAR)DeviceExtension->SrbExtensionBuffer;
635 
636  BufferLength = DeviceExtension->CommonBufferLength - Offset;
638  }
639  else
640  {
641  /* Nothing */
643  }
644 
645  *Length = BufferLength;
646  return PhysicalAddress;
647 }
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
#define SP_UNINITIALIZED_VALUE
Definition: srb.h:224
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
unsigned char * PUCHAR
Definition: retypes.h:3
struct SCSI_PORT_DEVICE_EXTENSION * PSCSI_PORT_DEVICE_EXTENSION
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
int64_t LONGLONG
Definition: typedefs.h:68
#define TRACE(s)
Definition: solgame.cpp:4
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define NULL
Definition: types.h:112
PVOID SenseInfoBuffer
Definition: srb.h:256
unsigned int ULONG
Definition: retypes.h:1
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by BusLogic_InitializeHostAdapter(), BusLogic_QueueCommand(), and BusLogic_WriteOutgoingMailbox().

◆ ScsiPortGetSrb()

PSCSI_REQUEST_BLOCK NTAPI ScsiPortGetSrb ( IN PVOID  DeviceExtension,
IN UCHAR  PathId,
IN UCHAR  TargetId,
IN UCHAR  Lun,
IN LONG  QueueTag 
)

Definition at line 651 of file scsiport.c.

657 {
658  // FIXME
660  return NULL;
661 }
#define NULL
Definition: types.h:112
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by AtapiStartIo__(), and BT958HwStartIO().

◆ ScsiPortGetUncachedExtension()

PVOID NTAPI ScsiPortGetUncachedExtension ( IN PVOID  HwDeviceExtension,
IN PPORT_CONFIGURATION_INFORMATION  ConfigInfo,
IN ULONG  NumberOfBytes 
)

Definition at line 729 of file scsiport.c.

733 {
734  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
736  ULONG MapRegistersCount;
738 
739  TRACE("ScsiPortGetUncachedExtension(%p %p %lu)\n",
740  HwDeviceExtension, ConfigInfo, NumberOfBytes);
741 
742  DeviceExtension = ((PSCSI_PORT_DEVICE_EXTENSION)HwDeviceExtension) - 1;
743 
744  /* Check for allocated common DMA buffer */
745  if (DeviceExtension->SrbExtensionBuffer != NULL)
746  {
747  return NULL;
748  }
749 
750  /* Check for DMA adapter object */
751  if (DeviceExtension->AdapterObject == NULL)
752  {
753  /* Initialize DMA adapter description */
755 
757  DeviceDescription.Master = ConfigInfo->Master;
758  DeviceDescription.ScatterGather = ConfigInfo->ScatterGather;
759  DeviceDescription.DemandMode = ConfigInfo->DemandMode;
760  DeviceDescription.Dma32BitAddresses = ConfigInfo->Dma32BitAddresses;
761  DeviceDescription.BusNumber = ConfigInfo->SystemIoBusNumber;
762  DeviceDescription.DmaChannel = ConfigInfo->DmaChannel;
763  DeviceDescription.InterfaceType = ConfigInfo->AdapterInterfaceType;
764  DeviceDescription.DmaWidth = ConfigInfo->DmaWidth;
765  DeviceDescription.DmaSpeed = ConfigInfo->DmaSpeed;
766  DeviceDescription.MaximumLength = ConfigInfo->MaximumTransferLength;
767  DeviceDescription.DmaPort = ConfigInfo->DmaPort;
768 
769  /* Get a DMA adapter object */
770 #if 0
771  DeviceExtension->AdapterObject =
772  HalGetAdapter(&DeviceDescription, &MapRegistersCount);
773 
774  /* Fail in case of error */
775  if (DeviceExtension->AdapterObject == NULL)
776  {
777  return NULL;
778  }
779 #else
780  MapRegistersCount = 0;
781 #endif
782 
783  /* Set number of physical breaks */
784  if (ConfigInfo->NumberOfPhysicalBreaks != 0 &&
785  MapRegistersCount > ConfigInfo->NumberOfPhysicalBreaks)
786  {
787  DeviceExtension->PortCapabilities.MaximumPhysicalPages =
788  ConfigInfo->NumberOfPhysicalBreaks;
789  }
790  else
791  {
792  DeviceExtension->PortCapabilities.MaximumPhysicalPages = MapRegistersCount;
793  }
794  }
795 
796  /* Update Srb extension size */
797  if (DeviceExtension->SrbExtensionSize != ConfigInfo->SrbExtensionSize)
798  DeviceExtension->SrbExtensionSize = ConfigInfo->SrbExtensionSize;
799 
800  /* Allocate a common DMA buffer */
801  Status = SpiAllocateCommonBuffer(DeviceExtension, NumberOfBytes);
802 
803  if (!NT_SUCCESS(Status))
804  {
805  TRACE("SpiAllocateCommonBuffer() failed with Status = 0x%08X!\n", Status);
806  return NULL;
807  }
808 
809  return DeviceExtension->NonCachedExtension;
810 }
IO_SCSI_CAPABILITIES PortCapabilities
Definition: scsiport.c:79
struct SCSI_PORT_DEVICE_EXTENSION * PSCSI_PORT_DEVICE_EXTENSION
LONG NTSTATUS
Definition: precomp.h:26
#define DEVICE_DESCRIPTION_VERSION
Definition: iotypes.h:2063
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceDescription
Definition: wdfpdo.h:430
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
PADAPTER_OBJECT AdapterObject
Definition: scsiport.c:87
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1035
#define NULL
Definition: types.h:112
static NTSTATUS SpiAllocateCommonBuffer(IN OUT PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN ULONG NonCachedSize)
Definition: scsiport.c:665
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
PADAPTER_OBJECT NTAPI HalGetAdapter(IN PDEVICE_DESCRIPTION DeviceDescription, OUT PULONG NumberOfMapRegisters)
Definition: dma.c:22

Referenced by Buslogic_InitBT958().

◆ ScsiPortGetVirtualAddress()

PVOID NTAPI ScsiPortGetVirtualAddress ( IN PVOID  HwDeviceExtension,
IN SCSI_PHYSICAL_ADDRESS  PhysicalAddress 
)

Definition at line 814 of file scsiport.c.

817 {
818  // FIXME
820  return NULL;
821 }
#define NULL
Definition: types.h:112
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by AtapiDmaPioSync(), and BusLogic_ScanIncomingMailboxes().

◆ ScsiPortInitialize()

ULONG NTAPI ScsiPortInitialize ( IN PVOID  Argument1,
IN PVOID  Argument2,
IN PHW_INITIALIZATION_DATA  HwInitializationData,
IN PVOID HwContext  OPTIONAL 
)

Definition at line 1125 of file scsiport.c.

1130 {
1131  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
1132  ULONG DeviceExtensionSize;
1133  PORT_CONFIGURATION_INFORMATION PortConfig;
1134  BOOLEAN Again;
1135  BOOLEAN FirstConfigCall = TRUE;
1137  UCHAR ScsiBus;
1138  NTSTATUS Status;
1139 
1140  if (HwInitializationData->HwInitializationDataSize != sizeof(HW_INITIALIZATION_DATA))
1141  {
1142  return STATUS_INVALID_PARAMETER;
1143  }
1144 
1145  /* Check params for validity */
1146  if ((HwInitializationData->HwInitialize == NULL) ||
1147  (HwInitializationData->HwStartIo == NULL) ||
1148  (HwInitializationData->HwInterrupt == NULL) ||
1149  (HwInitializationData->HwFindAdapter == NULL) ||
1150  (HwInitializationData->HwResetBus == NULL))
1151  {
1152  return STATUS_INVALID_PARAMETER;
1153  }
1154 
1155  /* Zero starting slot number */
1156  SlotNumber.u.AsULONG = 0;
1157 
1158  while (TRUE)
1159  {
1160  Again = FALSE;
1161 
1162  DeviceExtensionSize = sizeof(SCSI_PORT_DEVICE_EXTENSION) + HwInitializationData->DeviceExtensionSize;
1163  DeviceExtension = FrLdrTempAlloc(DeviceExtensionSize, TAG_SCSI_DEVEXT);
1164  if (!DeviceExtension)
1165  {
1166  return STATUS_NO_MEMORY;
1167  }
1168  RtlZeroMemory(DeviceExtension, DeviceExtensionSize);
1169  DeviceExtension->InterruptFlags = SCSI_PORT_NEXT_REQUEST_READY;
1170  DeviceExtension->HwInitialize = HwInitializationData->HwInitialize;
1171  DeviceExtension->HwStartIo = HwInitializationData->HwStartIo;
1172  DeviceExtension->HwInterrupt = HwInitializationData->HwInterrupt;
1173  DeviceExtension->HwResetBus = HwInitializationData->HwResetBus;
1174  DeviceExtension->MiniPortDeviceExtension = (PVOID)(DeviceExtension + 1);
1175 
1176  Status = SpiCreatePortConfig(DeviceExtension,
1178  &PortConfig,
1179  FirstConfigCall);
1180  if (Status != STATUS_SUCCESS)
1181  {
1182  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1183  return Status;
1184  }
1185 
1186  PortConfig.NumberOfAccessRanges = HwInitializationData->NumberOfAccessRanges;
1187  PortConfig.AccessRanges = FrLdrTempAlloc(sizeof(ACCESS_RANGE) * HwInitializationData->NumberOfAccessRanges,
1189  if (!PortConfig.AccessRanges)
1190  {
1191  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1192  return STATUS_NO_MEMORY;
1193  }
1194  RtlZeroMemory(PortConfig.AccessRanges, sizeof(ACCESS_RANGE) * HwInitializationData->NumberOfAccessRanges);
1195 
1196  /* Search for matching PCI device */
1197  if ((HwInitializationData->AdapterInterfaceType == PCIBus) &&
1198  (HwInitializationData->VendorIdLength > 0) &&
1199  (HwInitializationData->VendorId != NULL) &&
1200  (HwInitializationData->DeviceIdLength > 0) &&
1201  (HwInitializationData->DeviceId != NULL))
1202  {
1203  PortConfig.BusInterruptLevel = 0;
1204 
1205  /* Get PCI device data */
1206  TRACE("VendorId '%.*s' DeviceId '%.*s'\n",
1207  HwInitializationData->VendorIdLength,
1208  HwInitializationData->VendorId,
1209  HwInitializationData->DeviceIdLength,
1210  HwInitializationData->DeviceId);
1211 
1213  &PortConfig,
1214  0, /* FIXME */
1215  &SlotNumber))
1216  {
1217  /* Continue to the next bus, nothing here */
1218  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1219  return STATUS_INTERNAL_ERROR;
1220  }
1221 
1222  if (!PortConfig.BusInterruptLevel)
1223  {
1224  /* Bypass this slot, because no interrupt was assigned */
1225  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1226  return STATUS_INTERNAL_ERROR;
1227  }
1228  }
1229 
1230  if (HwInitializationData->HwFindAdapter(
1231  DeviceExtension->MiniPortDeviceExtension,
1232  HwContext,
1233  NULL,
1234  NULL,
1235  &PortConfig,
1236  &Again) != SP_RETURN_FOUND)
1237  {
1238  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1239  return STATUS_INTERNAL_ERROR;
1240  }
1241 
1242  /* Copy all stuff which we ever need from PortConfig to the DeviceExtension */
1244  DeviceExtension->MaxTargedIds = SCSI_MAXIMUM_TARGETS_PER_BUS;
1245  else
1246  DeviceExtension->MaxTargedIds = PortConfig.MaximumNumberOfTargets;
1247 
1248  DeviceExtension->BusNum = PortConfig.SystemIoBusNumber;
1249 
1250  TRACE("Adapter found: buses = %d, targets = %d\n",
1251  PortConfig.NumberOfBuses, DeviceExtension->MaxTargedIds);
1252 
1253  /* Initialize adapter */
1254  if (!DeviceExtension->HwInitialize(DeviceExtension->MiniPortDeviceExtension))
1255  {
1256  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1257  return STATUS_INTERNAL_ERROR;
1258  }
1259 
1260  /* Scan bus */
1261  for (ScsiBus = 0; ScsiBus < PortConfig.NumberOfBuses; ScsiBus++)
1262  {
1263  SpiScanAdapter(DeviceExtension, PortConfig.SystemIoBusNumber, ScsiBus);
1264  PortConfig.SystemIoBusNumber++;
1265  }
1266 
1267  FirstConfigCall = FALSE;
1268  if (!Again)
1269  {
1270  break;
1271  }
1272  }
1273 
1274  return STATUS_SUCCESS;
1275 }
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:65
static NTSTATUS SpiCreatePortConfig(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PHW_INITIALIZATION_DATA HwInitData, OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo, IN BOOLEAN ZeroStruct)
Definition: scsiport.c:423
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
static BOOLEAN SpiGetPciConfigData(IN PHW_INITIALIZATION_DATA HwInitializationData, IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig, IN ULONG BusNumber, IN OUT PPCI_SLOT_NUMBER NextSlotNumber)
Definition: scsiport.c:1025
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PVOID _In_ struct _HW_INITIALIZATION_DATA _In_ PVOID HwContext
Definition: srb.h:897
ACCESS_RANGE(* AccessRanges)[]
Definition: srb.h:70
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
#define FALSE
Definition: types.h:117
#define SCSI_MAXIMUM_TARGETS_PER_BUS
Definition: srb.h:22
#define SCSI_PORT_NEXT_REQUEST_READY
Definition: scsiport.c:54
PHW_INITIALIZE HwInitialize
Definition: scsiport.c:81
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
unsigned char BOOLEAN
void * PVOID
Definition: retypes.h:9
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define TAG_SCSI_ACCESS_RANGES
Definition: scsiport.c:57
#define SP_RETURN_FOUND
Definition: srb.h:514
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _SCSI_PORT_DEVICE_EXTENSION SCSI_PORT_DEVICE_EXTENSION
static VOID SpiScanAdapter(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN ULONG ScsiBus, IN UCHAR PathId)
Definition: scsiport.c:869
PHW_RESET_BUS HwResetBus
Definition: scsiport.c:84
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
PHW_INTERRUPT HwInterrupt
Definition: scsiport.c:83
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TAG_SCSI_DEVEXT
Definition: scsiport.c:56
_Must_inspect_result_ _In_ PVOID _In_ struct _HW_INITIALIZATION_DATA * HwInitializationData
Definition: srb.h:897
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197

Referenced by DriverEntry().

◆ ScsiPortIoMapTransfer()

VOID NTAPI ScsiPortIoMapTransfer ( IN PVOID  HwDeviceExtension,
IN PSCSI_REQUEST_BLOCK  Srb,
IN PVOID  LogicalAddress,
IN ULONG  Length 
)

Definition at line 1279 of file scsiport.c.

1284 {
1285  // FIXME
1286  UNIMPLEMENTED;
1287 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortLogError()

VOID NTAPI ScsiPortLogError ( IN PVOID  HwDeviceExtension,
IN PSCSI_REQUEST_BLOCK Srb  OPTIONAL,
IN UCHAR  PathId,
IN UCHAR  TargetId,
IN UCHAR  Lun,
IN ULONG  ErrorCode,
IN ULONG  UniqueId 
)

Definition at line 1291 of file scsiport.c.

1299 {
1300  // FIXME
1301  UNIMPLEMENTED;
1302 }
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by AtapiStartIo(), AtapiStartIo__(), BT958HwFindAdapter(), Buslogic_InitBT958(), BusLogic_ProcessCompletedCCBs(), and MapError().

◆ ScsiPortMoveMemory()

VOID NTAPI ScsiPortMoveMemory ( IN PVOID  WriteBuffer,
IN PVOID  ReadBuffer,
IN ULONG  Length 
)

Definition at line 1306 of file scsiport.c.

1310 {
1312 }
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define ReadBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:339
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
#define WriteBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:344

Referenced by Atapi2Scsi(), AtapiStartIo(), AtapiStartIo__(), BusLogic_QueueCommand(), and IssueIdentify().

◆ ScsiPortNotification()

VOID __cdecl ScsiPortNotification ( IN SCSI_NOTIFICATION_TYPE  NotificationType,
IN PVOID  HwDeviceExtension,
IN ...   
)

Definition at line 1316 of file scsiport.c.

1320 {
1321  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
1323  va_list ap;
1324 
1325  DeviceExtension = ((PSCSI_PORT_DEVICE_EXTENSION)HwDeviceExtension) - 1;
1326 
1327  va_start(ap, HwDeviceExtension);
1328 
1329  switch (NotificationType)
1330  {
1331  case RequestComplete:
1332  /* Mask the SRB as completed */
1335  break;
1336 
1337  case NextRequest:
1338  /* Say that device is ready */
1339  DeviceExtension->InterruptFlags |= SCSI_PORT_NEXT_REQUEST_READY;
1340  break;
1341 
1342  default:
1343  // FIXME
1344  UNIMPLEMENTED;
1345  }
1346 
1347  va_end(ap);
1348 }
ULONG SrbFlags
Definition: srb.h:252
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
#define SRB_FLAGS_IS_ACTIVE
Definition: srb.h:399
struct SCSI_PORT_DEVICE_EXTENSION * PSCSI_PORT_DEVICE_EXTENSION
_In_ WDF_SPECIAL_FILE_TYPE NotificationType
Definition: wdfdevice.h:1024
#define va_end(ap)
Definition: acmsvcex.h:90
#define SCSI_PORT_NEXT_REQUEST_READY
Definition: scsiport.c:54
char * va_list
Definition: acmsvcex.h:78
va_start(ap, x)
#define va_arg(ap, T)
Definition: acmsvcex.h:89
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by AtapiCallBack(), AtapiCallBack__(), AtapiInterrupt(), AtapiInterrupt__(), AtapiQueueTimerDpc(), AtapiResetController(), AtapiResetController__(), AtapiSendCommand(), AtapiStartIo(), AtapiStartIo__(), AtapiTimerDpc(), BT958HwStartIO(), BT958WmiSrb(), BusLogic_ProcessCompletedCCBs(), ScsiPortCompleteRequest(), ScsiPortStartIo(), ScsiPortStartPacket(), and SpiCompleteRequest().

◆ ScsiPortReadPortBufferUchar()

VOID NTAPI ScsiPortReadPortBufferUchar ( IN PUCHAR  Port,
OUT PUCHAR  Buffer,
IN ULONG  Count 
)

Definition at line 1352 of file scsiport.c.

1356 {
1358 }
CPPORT Port[4]
Definition: headless.c:35
PPC_QUAL void __inbytestring(unsigned long Port, unsigned char *Buffer, unsigned long Count)
Definition: intrin_ppc.h:584
#define H2I(Port)
Definition: portio.c:18
Definition: bufpool.h:45
int Count
Definition: noreturn.cpp:7

◆ ScsiPortReadPortBufferUlong()

VOID NTAPI ScsiPortReadPortBufferUlong ( IN PULONG  Port,
OUT PULONG  Buffer,
IN ULONG  Count 
)

Definition at line 1362 of file scsiport.c.

1366 {
1368 }
CPPORT Port[4]
Definition: headless.c:35
#define H2I(Port)
Definition: portio.c:18
Definition: bufpool.h:45
int Count
Definition: noreturn.cpp:7
PPC_QUAL void __indwordstring(unsigned long Port, unsigned long *Buffer, unsigned long Count)
Definition: intrin_ppc.h:598

◆ ScsiPortReadPortBufferUshort()

VOID NTAPI ScsiPortReadPortBufferUshort ( IN PUSHORT  Port,
OUT PUSHORT  Buffer,
IN ULONG  Count 
)

Definition at line 1372 of file scsiport.c.

1376 {
1378 }
CPPORT Port[4]
Definition: headless.c:35
#define H2I(Port)
Definition: portio.c:18
Definition: bufpool.h:45
int Count
Definition: noreturn.cpp:7
PPC_QUAL void __inwordstring(unsigned long Port, unsigned short *Buffer, unsigned long Count)
Definition: intrin_ppc.h:591

◆ ScsiPortReadPortUchar()

UCHAR NTAPI ScsiPortReadPortUchar ( IN PUCHAR  Port)

Definition at line 1382 of file scsiport.c.

1384 {
1385  TRACE("ScsiPortReadPortUchar(%p)\n", Port);
1386 
1387  return READ_PORT_UCHAR(Port);
1388 }
CPPORT Port[4]
Definition: headless.c:35
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by AtapiFindController(), AtapiFindNativeModeController(), AtapiFindPCIController(), AtapiHwInitialize(), AtapiInterrupt(), FindDevices(), IdeMediaStatus(), IdeSendCommand(), IssueIdentify(), MapError(), ReadBusLogicPort(), and SetDriveParameters().

◆ ScsiPortReadPortUlong()

ULONG NTAPI ScsiPortReadPortUlong ( IN PULONG  Port)

Definition at line 1392 of file scsiport.c.

1394 {
1395  return READ_PORT_ULONG(Port);
1396 }
CPPORT Port[4]
Definition: headless.c:35
ULONG NTAPI READ_PORT_ULONG(IN PULONG Port)
Definition: portio.c:70

◆ ScsiPortReadPortUshort()

USHORT NTAPI ScsiPortReadPortUshort ( IN PUSHORT  Port)

Definition at line 1400 of file scsiport.c.

1402 {
1403  return READ_PORT_USHORT(Port);
1404 }
CPPORT Port[4]
Definition: headless.c:35
USHORT NTAPI READ_PORT_USHORT(IN PUSHORT Port)
Definition: portio.c:63

Referenced by AtapiSendCommand(), and IssueIdentify().

◆ ScsiPortReadRegisterBufferUchar()

VOID NTAPI ScsiPortReadRegisterBufferUchar ( IN PUCHAR  Register,
IN PUCHAR  Buffer,
IN ULONG  Count 
)

Definition at line 1408 of file scsiport.c.

1412 {
1413  // FIXME
1414  UNIMPLEMENTED;
1415 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortReadRegisterBufferUlong()

VOID NTAPI ScsiPortReadRegisterBufferUlong ( IN PULONG  Register,
IN PULONG  Buffer,
IN ULONG  Count 
)

Definition at line 1419 of file scsiport.c.

1423 {
1424  // FIXME
1425  UNIMPLEMENTED;
1426 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortReadRegisterBufferUshort()

VOID NTAPI ScsiPortReadRegisterBufferUshort ( IN PUSHORT  Register,
IN PUSHORT  Buffer,
IN ULONG  Count 
)

Definition at line 1430 of file scsiport.c.

1434 {
1435  // FIXME
1436  UNIMPLEMENTED;
1437 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortReadRegisterUchar()

UCHAR NTAPI ScsiPortReadRegisterUchar ( IN PUCHAR  Register)

Definition at line 1441 of file scsiport.c.

1443 {
1444  return READ_REGISTER_UCHAR(Register);
1445 }
NTKERNELAPI UCHAR NTAPI READ_REGISTER_UCHAR(IN PUCHAR Register)

◆ ScsiPortReadRegisterUlong()

ULONG NTAPI ScsiPortReadRegisterUlong ( IN PULONG  Register)

Definition at line 1449 of file scsiport.c.

1451 {
1452  return READ_REGISTER_ULONG(Register);
1453 }
NTKERNELAPI ULONG NTAPI READ_REGISTER_ULONG(IN PULONG Register)

◆ ScsiPortReadRegisterUshort()

USHORT NTAPI ScsiPortReadRegisterUshort ( IN PUSHORT  Register)

Definition at line 1457 of file scsiport.c.

1459 {
1460  return READ_REGISTER_USHORT(Register);
1461 }
NTKERNELAPI USHORT NTAPI READ_REGISTER_USHORT(IN PUSHORT Register)

◆ ScsiPortSetBusDataByOffset()

ULONG NTAPI ScsiPortSetBusDataByOffset ( IN PVOID  DeviceExtension,
IN ULONG  BusDataType,
IN ULONG  SystemIoBusNumber,
IN ULONG  SlotNumber,
IN PVOID  Buffer,
IN ULONG  Offset,
IN ULONG  Length 
)

Definition at line 1465 of file scsiport.c.

1473 {
1474  // FIXME
1475  UNIMPLEMENTED;
1476  return 0;
1477 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortStallExecution()

◆ ScsiPortValidateRange()

BOOLEAN NTAPI ScsiPortValidateRange ( IN PVOID  HwDeviceExtension,
IN INTERFACE_TYPE  BusType,
IN ULONG  SystemIoBusNumber,
IN SCSI_PHYSICAL_ADDRESS  IoAddress,
IN ULONG  NumberOfBytes,
IN BOOLEAN  InIoSpace 
)

Definition at line 1489 of file scsiport.c.

1496 {
1497  // FIXME
1498  UNIMPLEMENTED;
1499  return TRUE;
1500 }
#define TRUE
Definition: types.h:120
#define UNIMPLEMENTED
Definition: debug.h:115

Referenced by BT958HwFindAdapter(), and UniataFindBusMasterController().

◆ ScsiPortWritePortBufferUchar()

VOID NTAPI ScsiPortWritePortBufferUchar ( IN PUCHAR  Port,
IN PUCHAR  Buffer,
IN ULONG  Count 
)

Definition at line 1509 of file scsiport.c.

1513 {
1515 }
CPPORT Port[4]
Definition: headless.c:35
PPC_QUAL void __outbytestring(unsigned long const Port, const unsigned char *const Buffer, const unsigned long Count)
Definition: intrin_ppc.h:653
#define H2I(Port)
Definition: portio.c:18
Definition: bufpool.h:45
int Count
Definition: noreturn.cpp:7

◆ ScsiPortWritePortBufferUlong()

VOID NTAPI ScsiPortWritePortBufferUlong ( IN PULONG  Port,
IN PULONG  Buffer,
IN ULONG  Count 
)

Definition at line 1519 of file scsiport.c.

1523 {
1525 }
CPPORT Port[4]
Definition: headless.c:35
#define H2I(Port)
Definition: portio.c:18
PPC_QUAL void __outdwordstring(unsigned long const Port, const unsigned long *const Buffer, const unsigned long Count)
Definition: intrin_ppc.h:671
Definition: bufpool.h:45
int Count
Definition: noreturn.cpp:7

◆ ScsiPortWritePortBufferUshort()

VOID NTAPI ScsiPortWritePortBufferUshort ( IN PUSHORT  Port,
IN PUSHORT  Buffer,
IN ULONG  Count 
)

Definition at line 1529 of file scsiport.c.

1533 {
1535 }
CPPORT Port[4]
Definition: headless.c:35
#define H2I(Port)
Definition: portio.c:18
Definition: bufpool.h:45
int Count
Definition: noreturn.cpp:7
PPC_QUAL void __outwordstring(unsigned long const Port, const unsigned short *const Buffer, const unsigned long Count)
Definition: intrin_ppc.h:662

◆ ScsiPortWritePortUchar()

VOID NTAPI ScsiPortWritePortUchar ( IN PUCHAR  Port,
IN UCHAR  Value 
)

Definition at line 1539 of file scsiport.c.

1542 {
1544 }
CPPORT Port[4]
Definition: headless.c:35
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21

Referenced by AtapiFindController(), AtapiFindNativeModeController(), AtapiFindPCIController(), AtapiHwInitialize(), AtapiSendCommand(), FindDevices(), IdeMediaStatus(), IdeReadWrite(), IdeSendCommand(), IdeSendSmartCommand(), IdeVerify(), IssueIdentify(), MapError(), SetDriveParameters(), and WriteBusLogicPort().

◆ ScsiPortWritePortUlong()

VOID NTAPI ScsiPortWritePortUlong ( IN PULONG  Port,
IN ULONG  Value 
)

Definition at line 1548 of file scsiport.c.

1551 {
1553 }
CPPORT Port[4]
Definition: headless.c:35
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406

◆ ScsiPortWritePortUshort()

VOID NTAPI ScsiPortWritePortUshort ( IN PUSHORT  Port,
IN USHORT  Value 
)

Definition at line 1557 of file scsiport.c.

1560 {
1562 }
CPPORT Port[4]
Definition: headless.c:35
VOID NTAPI WRITE_PORT_USHORT(IN PUSHORT Port, IN USHORT Value)
Definition: portio.c:115
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406

◆ ScsiPortWriteRegisterBufferUchar()

VOID NTAPI ScsiPortWriteRegisterBufferUchar ( IN PUCHAR  Register,
IN PUCHAR  Buffer,
IN ULONG  Count 
)

Definition at line 1566 of file scsiport.c.

1570 {
1571  // FIXME
1572  UNIMPLEMENTED;
1573 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortWriteRegisterBufferUlong()

VOID NTAPI ScsiPortWriteRegisterBufferUlong ( IN PULONG  Register,
IN PULONG  Buffer,
IN ULONG  Count 
)

Definition at line 1577 of file scsiport.c.

1581 {
1582  // FIXME
1583  UNIMPLEMENTED;
1584 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortWriteRegisterBufferUshort()

VOID NTAPI ScsiPortWriteRegisterBufferUshort ( IN PUSHORT  Register,
IN PUSHORT  Buffer,
IN ULONG  Count 
)

Definition at line 1588 of file scsiport.c.

1592 {
1593  // FIXME
1594  UNIMPLEMENTED;
1595 }
#define UNIMPLEMENTED
Definition: debug.h:115

◆ ScsiPortWriteRegisterUchar()

VOID NTAPI ScsiPortWriteRegisterUchar ( IN PUCHAR  Register,
IN UCHAR  Value 
)

Definition at line 1599 of file scsiport.c.

1602 {
1603  WRITE_REGISTER_UCHAR(Register, Value);
1604 }
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
NTKERNELAPI VOID NTAPI WRITE_REGISTER_UCHAR(IN PUCHAR Register, IN UCHAR Value)

◆ ScsiPortWriteRegisterUlong()

VOID NTAPI ScsiPortWriteRegisterUlong ( IN PULONG  Register,
IN ULONG  Value 
)

Definition at line 1608 of file scsiport.c.

1611 {
1612  WRITE_REGISTER_ULONG(Register, Value);
1613 }
NTKERNELAPI VOID NTAPI WRITE_REGISTER_ULONG(IN PULONG Register, IN ULONG Value)
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406

◆ ScsiPortWriteRegisterUshort()

VOID NTAPI ScsiPortWriteRegisterUshort ( IN PUSHORT  Register,
IN USHORT  Value 
)

Definition at line 1617 of file scsiport.c.

1620 {
1621  WRITE_REGISTER_USHORT(Register, Value);
1622 }
NTKERNELAPI VOID NTAPI WRITE_REGISTER_USHORT(IN PUSHORT Register, IN USHORT Value)
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406

◆ SpiAllocateCommonBuffer()

static NTSTATUS SpiAllocateCommonBuffer ( IN OUT PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  NonCachedSize 
)
static

Definition at line 665 of file scsiport.c.

668 {
670  ULONG CommonBufferLength, BufSize;
671 
672  /* If size is 0, set it to 16 */
673  if (!DeviceExtension->SrbExtensionSize)
674  DeviceExtension->SrbExtensionSize = 16;
675 
676  /* Calculate size */
677  BufSize = DeviceExtension->SrbExtensionSize;
678 
679  /* Round it */
680  BufSize = (BufSize + sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1);
681 
682  /* Sum up into the total common buffer length, and round it to page size */
683  CommonBufferLength =
684  ROUND_TO_PAGES(NonCachedSize);
685 
686  /* Allocate it */
687  if (!DeviceExtension->AdapterObject)
688  {
689  /* From nonpaged pool if there is no DMA */
690  CommonBuffer = ExAllocatePool(NonPagedPool, CommonBufferLength);
691  }
692  else
693  {
694  /* Perform a full request since we have a DMA adapter*/
696  CommonBuffer = NULL;
697  }
698 
699  /* Fail in case of error */
700  if (!CommonBuffer)
702 
703  /* Zero it */
704  RtlZeroMemory(CommonBuffer, CommonBufferLength);
705 
706  /* Store its size in Device Extension */
707  DeviceExtension->CommonBufferLength = CommonBufferLength;
708 
709  /* SrbExtension buffer is located at the beginning of the buffer */
710  DeviceExtension->SrbExtensionBuffer = CommonBuffer;
711 
712  /* Non-cached extension buffer is located at the end of
713  the common buffer */
714  if (NonCachedSize)
715  {
716  CommonBufferLength -= NonCachedSize;
717  DeviceExtension->NonCachedExtension = (PUCHAR)CommonBuffer + CommonBufferLength;
718  }
719  else
720  {
721  DeviceExtension->NonCachedExtension = NULL;
722  }
723 
724  return STATUS_SUCCESS;
725 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
unsigned char * PUCHAR
Definition: retypes.h:3
#define BufSize
Definition: FsRtlTunnel.c:28
int64_t LONGLONG
Definition: typedefs.h:68
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
#define ROUND_TO_PAGES(Size)
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFCOMMONBUFFER * CommonBuffer
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
#define UNIMPLEMENTED
Definition: debug.h:115
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by ScsiPortGetUncachedExtension().

◆ SpiCreatePortConfig()

static NTSTATUS SpiCreatePortConfig ( IN PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
IN PHW_INITIALIZATION_DATA  HwInitData,
OUT PPORT_CONFIGURATION_INFORMATION  ConfigInfo,
IN BOOLEAN  ZeroStruct 
)
static

Definition at line 423 of file scsiport.c.

428 {
429  ULONG Bus;
430 
431  /* Zero out the struct if told so */
432  if (ZeroStruct)
433  {
434  /* First zero the portconfig */
435  RtlZeroMemory(ConfigInfo, sizeof(PORT_CONFIGURATION_INFORMATION));
436 
437  /* Initialize the struct */
438  ConfigInfo->Length = sizeof(PORT_CONFIGURATION_INFORMATION);
439  ConfigInfo->AdapterInterfaceType = HwInitData->AdapterInterfaceType;
440  ConfigInfo->InterruptMode = Latched;
441  ConfigInfo->DmaChannel = SP_UNINITIALIZED_VALUE;
442  ConfigInfo->DmaPort = SP_UNINITIALIZED_VALUE;
443  ConfigInfo->MaximumTransferLength = SP_UNINITIALIZED_VALUE;
444  ConfigInfo->MaximumNumberOfTargets = SCSI_MAXIMUM_TARGETS_PER_BUS;
445 
446  /* Store parameters */
447  ConfigInfo->NeedPhysicalAddresses = HwInitData->NeedPhysicalAddresses;
448  ConfigInfo->MapBuffers = HwInitData->MapBuffers;
449  ConfigInfo->AutoRequestSense = HwInitData->AutoRequestSense;
450  ConfigInfo->ReceiveEvent = HwInitData->ReceiveEvent;
451  ConfigInfo->TaggedQueuing = HwInitData->TaggedQueuing;
452  ConfigInfo->MultipleRequestPerLu = HwInitData->MultipleRequestPerLu;
453 
454  /* Get the disk usage */
455  ConfigInfo->AtdiskPrimaryClaimed = FALSE; // FIXME
456  ConfigInfo->AtdiskSecondaryClaimed = FALSE; // FIXME
457 
458  /* Initiator bus id is not set */
459  for (Bus = 0; Bus < 8; Bus++)
460  ConfigInfo->InitiatorBusId[Bus] = (CCHAR)SP_UNINITIALIZED_VALUE;
461  }
462 
463  ConfigInfo->NumberOfPhysicalBreaks = 17;
464 
465  return STATUS_SUCCESS;
466 }
#define SP_UNINITIALIZED_VALUE
Definition: srb.h:224
#define FALSE
Definition: types.h:117
#define SCSI_MAXIMUM_TARGETS_PER_BUS
Definition: srb.h:22
char CCHAR
Definition: typedefs.h:51
struct _PORT_CONFIGURATION_INFORMATION PORT_CONFIGURATION_INFORMATION
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define STATUS_SUCCESS
Definition: shellext.h:65

Referenced by ScsiPortInitialize().

◆ SpiGetPciConfigData()

static BOOLEAN SpiGetPciConfigData ( IN PHW_INITIALIZATION_DATA  HwInitializationData,
IN OUT PPORT_CONFIGURATION_INFORMATION  PortConfig,
IN ULONG  BusNumber,
IN OUT PPCI_SLOT_NUMBER  NextSlotNumber 
)
static

Definition at line 1025 of file scsiport.c.

1030 {
1031  PCI_COMMON_CONFIG PciConfig;
1033  ULONG DataSize;
1035  ULONG FunctionNumber;
1036  CHAR VendorIdString[8];
1037  CHAR DeviceIdString[8];
1039  NTSTATUS Status;
1040 
1041  SlotNumber.u.AsULONG = 0;
1042 
1043  /* Loop through all devices */
1044  for (DeviceNumber = NextSlotNumber->u.bits.DeviceNumber; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
1045  {
1046  SlotNumber.u.bits.DeviceNumber = DeviceNumber;
1047 
1048  /* Loop through all functions */
1049  for (FunctionNumber = NextSlotNumber->u.bits.FunctionNumber; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
1050  {
1051  SlotNumber.u.bits.FunctionNumber = FunctionNumber;
1052 
1053  /* Get PCI config bytes */
1056  BusNumber,
1057  SlotNumber.u.AsULONG,
1058  &PciConfig,
1059  0,
1060  sizeof(ULONG));
1061 
1062  /* If result of HalGetBusData is 0, then the bus is wrong */
1063  if (DataSize == 0)
1064  return FALSE;
1065 
1066  /* If result is PCI_INVALID_VENDORID, then this device has no more
1067  "Functions" */
1068  if (PciConfig.VendorID == PCI_INVALID_VENDORID)
1069  break;
1070 
1071  sprintf(VendorIdString, "%04hx", PciConfig.VendorID);
1072  sprintf(DeviceIdString, "%04hx", PciConfig.DeviceID);
1073 
1074  if (_strnicmp(VendorIdString, HwInitializationData->VendorId, HwInitializationData->VendorIdLength) ||
1075  _strnicmp(DeviceIdString, HwInitializationData->DeviceId, HwInitializationData->DeviceIdLength))
1076  {
1077  /* It is not our device */
1078  continue;
1079  }
1080 
1081  TRACE( "Found device 0x%04hx 0x%04hx at %1lu %2lu %1lu\n",
1082  PciConfig.VendorID, PciConfig.DeviceID,
1083  BusNumber,
1084  SlotNumber.u.bits.DeviceNumber, SlotNumber.u.bits.FunctionNumber);
1085 
1087  NULL,
1088  NULL,
1089  NULL,
1090  PCIBus,
1091  BusNumber,
1092  SlotNumber.u.AsULONG,
1093  &ResourceList);
1094 
1095  if (!NT_SUCCESS(Status))
1096  break;
1097 
1098  /* Create configuration information */
1100  ResourceList->List,
1101  PortConfig);
1102 
1103  /* Free the resource list */
1105 
1106  /* Set dev & fn numbers */
1107  NextSlotNumber->u.bits.DeviceNumber = DeviceNumber;
1108  NextSlotNumber->u.bits.FunctionNumber = FunctionNumber + 1;
1109 
1110  /* Save the slot number */
1111  PortConfig->SlotNumber = SlotNumber.u.AsULONG;
1112 
1113  return TRUE;
1114  }
1115  NextSlotNumber->u.bits.FunctionNumber = 0;
1116  }
1117 
1118  NextSlotNumber->u.bits.DeviceNumber = 0;
1119 
1120  return FALSE;
1121 }
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:65
#define TRUE
Definition: types.h:120
static VOID SpiResourceToConfig(IN PHW_INITIALIZATION_DATA HwInitializationData, IN PCM_FULL_RESOURCE_DESCRIPTOR ResourceDescriptor, IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig)
Definition: scsiport.c:944
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:304
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define FALSE
Definition: types.h:117
NTHALAPI NTSTATUS NTAPI HalAssignSlotResources(PUNICODE_STRING, PUNICODE_STRING, PDRIVER_OBJECT, PDEVICE_OBJECT, INTERFACE_TYPE, ULONG, ULONG, PCM_RESOURCE_LIST *)
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
Status
Definition: gdiplustypes.h:24
#define TRACE(s)
Definition: solgame.cpp:4
#define PCI_INVALID_VENDORID
Definition: iotypes.h:3601
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PCI_MAX_DEVICES
Definition: iotypes.h:3598
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
ULONG NTAPI HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:73
#define PCI_MAX_FUNCTION
Definition: iotypes.h:3599
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1229
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
_Must_inspect_result_ _In_ PVOID _In_ struct _HW_INITIALIZATION_DATA * HwInitializationData
Definition: srb.h:897

Referenced by ScsiPortInitialize().

◆ SpiResourceToConfig()

static VOID SpiResourceToConfig ( IN PHW_INITIALIZATION_DATA  HwInitializationData,
IN PCM_FULL_RESOURCE_DESCRIPTOR  ResourceDescriptor,
IN OUT PPORT_CONFIGURATION_INFORMATION  PortConfig 
)
static

Definition at line 944 of file scsiport.c.

948 {
949  PACCESS_RANGE AccessRange;
951  ULONG RangeNumber;
952  ULONG Index;
953 
954  RangeNumber = 0;
955 
956  /* Loop through all entries */
957  for (Index = 0; Index < ResourceDescriptor->PartialResourceList.Count; Index++)
958  {
959  PartialData = &ResourceDescriptor->PartialResourceList.PartialDescriptors[Index];
960 
961  switch (PartialData->Type)
962  {
963  case CmResourceTypePort:
964  /* Copy access ranges */
965  if (RangeNumber < HwInitializationData->NumberOfAccessRanges)
966  {
967  TRACE("Got port at 0x%I64x, len 0x%x\n",
968  PartialData->u.Port.Start.QuadPart, PartialData->u.Port.Length);
969  AccessRange = &((*(PortConfig->AccessRanges))[RangeNumber]);
970 
971  AccessRange->RangeStart = PartialData->u.Port.Start;
972  AccessRange->RangeLength = PartialData->u.Port.Length;
973 
974  AccessRange->RangeInMemory = FALSE;
975  RangeNumber++;
976  }
977  break;
978 
980  /* Copy access ranges */
981  if (RangeNumber < HwInitializationData->NumberOfAccessRanges)
982  {
983  TRACE("Got memory at 0x%I64x, len 0x%x\n",
984  PartialData->u.Memory.Start.QuadPart, PartialData->u.Memory.Length);
985  AccessRange = &((*(PortConfig->AccessRanges))[RangeNumber]);
986 
987  AccessRange->RangeStart = PartialData->u.Memory.Start;
988  AccessRange->RangeLength = PartialData->u.Memory.Length;
989 
990  AccessRange->RangeInMemory = TRUE;
991  RangeNumber++;
992  }
993  break;
994 
996  /* Copy interrupt data */
997  TRACE("Got interrupt level %d, vector %d\n",
998  PartialData->u.Interrupt.Level, PartialData->u.Interrupt.Vector);
999  PortConfig->BusInterruptLevel = PartialData->u.Interrupt.Level;
1000  PortConfig->BusInterruptVector = PartialData->u.Interrupt.Vector;
1001 
1002  /* Set interrupt mode accordingly to the resource */
1003  if (PartialData->Flags == CM_RESOURCE_INTERRUPT_LATCHED)
1004  {
1005  PortConfig->InterruptMode = Latched;
1006  }
1007  else if (PartialData->Flags == CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE)
1008  {
1009  PortConfig->InterruptMode = LevelSensitive;
1010  }
1011  break;
1012 
1013  case CmResourceTypeDma:
1014  TRACE("Got DMA channel %d, port %d\n",
1015  PartialData->u.Dma.Channel, PartialData->u.Dma.Port);
1016  PortConfig->DmaChannel = PartialData->u.Dma.Channel;
1017  PortConfig->DmaPort = PartialData->u.Dma.Port;
1018  break;
1019  }
1020  }
1021 }
#define TRUE
Definition: types.h:120
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@381 Memory
#define CmResourceTypePort
Definition: hwresource.cpp:123
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@382 Dma
#define FALSE
Definition: types.h:117
#define TRACE(s)
Definition: solgame.cpp:4
_In_ WDFCOLLECTION _In_ ULONG Index
SCSI_PHYSICAL_ADDRESS RangeStart
Definition: srb.h:41
BOOLEAN RangeInMemory
Definition: srb.h:43
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@378 Port
ULONG RangeLength
Definition: srb.h:42
#define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
Definition: cmtypes.h:143
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
unsigned int ULONG
Definition: retypes.h:1
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@379 Interrupt
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
#define CmResourceTypeDma
Definition: hwresource.cpp:126

Referenced by SpiGetPciConfigData().

◆ SpiScanAdapter()

static VOID SpiScanAdapter ( IN PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
IN ULONG  ScsiBus,
IN UCHAR  PathId 
)
static

Definition at line 869 of file scsiport.c.

873 {
874  CHAR ArcName[64];
876  PCDB Cdb;
877  INQUIRYDATA InquiryBuffer;
878  UCHAR TargetId;
879  UCHAR Lun;
880 
881  if (!DeviceExtension->HwResetBus(DeviceExtension->MiniPortDeviceExtension, PathId))
882  {
883  return;
884  }
885 
886  /* Remember the extension */
887  ScsiDeviceExtensions[ScsiBus] = DeviceExtension;
888 
889  for (TargetId = 0; TargetId < DeviceExtension->MaxTargedIds; TargetId++)
890  {
891  Lun = 0;
892  do
893  {
894  TRACE("Scanning SCSI device %d.%d.%d\n",
895  ScsiBus, TargetId, Lun);
896 
898  if (!Srb)
899  break;
901  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
903  Srb->PathId = PathId;
904  Srb->TargetId = TargetId;
905  Srb->Lun = Lun;
906  Srb->CdbLength = 6;
909  Srb->TimeOutValue = 5; /* in seconds */
910  Srb->DataBuffer = &InquiryBuffer;
911  Cdb = (PCDB)Srb->Cdb;
912  Cdb->CDB6INQUIRY.OperationCode = SCSIOP_INQUIRY;
913  Cdb->CDB6INQUIRY.LogicalUnitNumber = Srb->Lun;
914  Cdb->CDB6INQUIRY.AllocationLength = (UCHAR)Srb->DataTransferLength;
915  if (!SpiSendSynchronousSrb(DeviceExtension, Srb))
916  {
917  /* Don't check next LUNs */
918  break;
919  }
920 
921  /* Device exists, create its ARC name */
922  if (InquiryBuffer.RemovableMedia)
923  {
924  sprintf(ArcName, "scsi(%ld)cdrom(%d)fdisk(%d)",
925  ScsiBus, TargetId, Lun);
926  FsRegisterDevice(ArcName, &DiskVtbl);
927  }
928  else
929  {
930  sprintf(ArcName, "scsi(%ld)disk(%d)rdisk(%d)",
931  ScsiBus, TargetId, Lun);
932  /* Now, check if it has partitions */
933  SpiScanDevice(DeviceExtension, ArcName, PathId, TargetId, Lun);
934  }
935 
936  /* Check next LUN */
937  Lun++;
938  } while (Lun < SCSI_MAXIMUM_LOGICAL_UNITS);
939  }
940 }
PSCSI_PORT_DEVICE_EXTENSION ScsiDeviceExtensions[SCSI_MAXIMUM_BUSES]
Definition: scsiport.c:109
ULONG SrbFlags
Definition: srb.h:252
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR _In_ UCHAR Lun
Definition: classpnp.h:1310
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
UCHAR Cdb[16]
Definition: srb.h:271
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR PathId
Definition: classpnp.h:1310
PVOID DataBuffer
Definition: srb.h:255
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR TargetId
Definition: classpnp.h:1310
#define SCSI_MAXIMUM_LOGICAL_UNITS
Definition: srb.h:21
char CHAR
Definition: xmlstorage.h:175
ULONG DataTransferLength
Definition: srb.h:253
Definition: cdrw_hw.h:28
UCHAR CdbLength
Definition: srb.h:250
#define SRB_FLAGS_DATA_IN
Definition: srb.h:392
ULONG TimeOutValue
Definition: srb.h:254
#define sprintf(buf, format,...)
Definition: sprintf.c:55
UCHAR RemovableMedia
Definition: cdrw_hw.h:1119
#define INQUIRYDATABUFFERSIZE
Definition: cdrw_hw.h:1113
union _CDB * PCDB
UCHAR TargetId
Definition: srb.h:246
#define SCSIOP_INQUIRY
Definition: cdrw_hw.h:888
#define TRACE(s)
Definition: solgame.cpp:4
UCHAR Function
Definition: srb.h:242
static const DEVVTBL DiskVtbl
Definition: scsiport.c:412
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
Definition: scratch.h:156
USHORT Length
Definition: srb.h:241
struct _SCSI_REQUEST_BLOCK SCSI_REQUEST_BLOCK
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID FsRegisterDevice(CHAR *Prefix, const DEVVTBL *FuncTable)
Definition: fs.c:383
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
UCHAR PathId
Definition: srb.h:245
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
static BOOLEAN SpiSendSynchronousSrb(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb)
Definition: scsiport.c:130
struct _CDB::_CDB6INQUIRY CDB6INQUIRY
static VOID SpiScanDevice(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PCHAR ArcName, IN ULONG ScsiBus, IN ULONG TargetId, IN ULONG Lun)
Definition: scsiport.c:825

Referenced by ScsiPortInitialize().

◆ SpiScanDevice()

static VOID SpiScanDevice ( IN PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
IN PCHAR  ArcName,
IN ULONG  ScsiBus,
IN ULONG  TargetId,
IN ULONG  Lun 
)
static

Definition at line 825 of file scsiport.c.

831 {
832  ULONG FileId, i;
834  NTSTATUS ret;
836  CHAR PartitionName[64];
837 
838  /* Register device with partition(0) suffix */
839  RtlStringCbPrintfA(PartitionName, sizeof(PartitionName), "%spartition(0)", ArcName);
840  FsRegisterDevice(PartitionName, &DiskVtbl);
841 
842  /* Read device partition table */
843  Status = ArcOpen(PartitionName, OpenReadOnly, &FileId);
844  if (Status == ESUCCESS)
845  {
846  ret = HALDISPATCH->HalIoReadPartitionTable((PDEVICE_OBJECT)FileId, 512, FALSE, &PartitionBuffer);
847  if (NT_SUCCESS(ret))
848  {
849  for (i = 0; i < PartitionBuffer->PartitionCount; i++)
850  {
851  if (PartitionBuffer->PartitionEntry[i].PartitionType != PARTITION_ENTRY_UNUSED)
852  {
853  RtlStringCbPrintfA(PartitionName,
854  sizeof(PartitionName),
855  "%spartition(%lu)",
856  ArcName,
857  PartitionBuffer->PartitionEntry[i].PartitionNumber);
858  FsRegisterDevice(PartitionName, &DiskVtbl);
859  }
860  }
862  }
863  ArcClose(FileId);
864  }
865 }
Definition: arc.h:32
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
ULONG ARC_STATUS
Definition: arc.h:4
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
#define FALSE
Definition: types.h:117
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2052
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
Status
Definition: gdiplustypes.h:24
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const DEVVTBL DiskVtbl
Definition: scsiport.c:412
int ret
VOID FsRegisterDevice(CHAR *Prefix, const DEVVTBL *FuncTable)
Definition: fs.c:383
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
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:218
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:56
unsigned int ULONG
Definition: retypes.h:1
#define HALDISPATCH
Definition: haltypes.h:278
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by SpiScanAdapter().

◆ SpiSendSynchronousSrb()

static BOOLEAN SpiSendSynchronousSrb ( IN PSCSI_PORT_DEVICE_EXTENSION  DeviceExtension,
IN PSCSI_REQUEST_BLOCK  Srb 
)
static

Definition at line 130 of file scsiport.c.

133 {
134  BOOLEAN ret;
135 
137 
138  /* HACK: handle lack of interrupts */
139  while (!(DeviceExtension->InterruptFlags & SCSI_PORT_NEXT_REQUEST_READY))
140  {
141  KeStallExecutionProcessor(100 * 1000);
142  if (!DeviceExtension->HwInterrupt(DeviceExtension->MiniPortDeviceExtension))
143  {
144  ExFreePool(Srb);
145  return FALSE;
146  }
147  }
148 
149  DeviceExtension->InterruptFlags &= ~SCSI_PORT_NEXT_REQUEST_READY;
151 
152  if (!DeviceExtension->HwStartIo(
153  DeviceExtension->MiniPortDeviceExtension,
154  Srb))
155  {
156  ExFreePool(Srb);
157  return FALSE;
158  }
159 
160  /* HACK: handle lack of interrupts */
161  while (Srb->SrbFlags & SRB_FLAGS_IS_ACTIVE)
162  {
163  KeStallExecutionProcessor(100 * 1000);
164  if (!DeviceExtension->HwInterrupt(DeviceExtension->MiniPortDeviceExtension))
165  {
166  ExFreePool(Srb);
167  return FALSE;
168  }
169  }
170 
172  ExFreePool(Srb);
173 
174  return ret;
175 }
ULONG SrbFlags
Definition: srb.h:252
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
#define SRB_FLAGS_IS_ACTIVE
Definition: srb.h:399
UCHAR SrbStatus
Definition: srb.h:243
#define SRB_STATUS(Status)
Definition: srb.h:381
#define FALSE
Definition: types.h:117
#define SCSI_PORT_NEXT_REQUEST_READY
Definition: scsiport.c:54
unsigned char BOOLEAN
#define ASSERT(a)
Definition: mode.c:44
int ret
#define SRB_STATUS_SUCCESS
Definition: srb.h:333
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:96
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by DiskOpen(), DiskRead(), and SpiScanAdapter().

Variable Documentation

◆ __ImageBase

char __ImageBase

Definition at line 17 of file mstscax.cpp.

Referenced by LoadBootDeviceDriver().

◆ DiskVtbl

const DEVVTBL DiskVtbl
static
Initial value:
=
{
}
static ARC_STATUS DiskGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: scsiport.c:184
static ARC_STATUS DiskRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: scsiport.c:273
static ARC_STATUS DiskOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: scsiport.c:203
static ARC_STATUS DiskClose(ULONG FileId)
Definition: scsiport.c:177
static ARC_STATUS DiskSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: scsiport.c:383

Definition at line 412 of file scsiport.c.

Referenced by SpiScanAdapter(), and SpiScanDevice().

◆ ScsiDeviceExtensions

Definition at line 109 of file scsiport.c.

Referenced by DiskOpen(), and SpiScanAdapter().