ReactOS 0.4.16-dev-197-g92996da
scsiport.c File Reference
#include <freeldr.h>
#include <debug.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 53 of file scsiport.c.

◆ TAG_SCSI_ACCESS_RANGES

#define TAG_SCSI_ACCESS_RANGES   'AscS'

Definition at line 56 of file scsiport.c.

◆ TAG_SCSI_DEVEXT

#define TAG_SCSI_DEVEXT   'DscS'

Definition at line 55 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 176 of file scsiport.c.

177{
180 return ESUCCESS;
181}
PVOID FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:632
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
@ ESUCCESS
Definition: arc.h:32

◆ DiskGetFileInformation()

static ARC_STATUS DiskGetFileInformation ( ULONG  FileId,
FILEINFORMATION Information 
)
static

Definition at line 183 of file scsiport.c.

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

◆ DiskOpen()

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

Definition at line 202 of file scsiport.c.

203{
205 PCDB Cdb;
207
209 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
210 ULONG ScsiBus, PathId, TargetId, Lun, Partition, PathSyntax;
214
215 /* Parse ARC path */
216 if (!DissectArcPath2(Path, &ScsiBus, &TargetId, &Lun, &Partition, &PathSyntax))
217 return EINVAL;
218 if (PathSyntax != 0) /* scsi() format */
219 return EINVAL;
220 DeviceExtension = ScsiDeviceExtensions[ScsiBus];
221 PathId = ScsiBus - DeviceExtension->BusNum;
222
223 /* Get disk capacity and sector size */
225 if (!Srb)
226 return ENOMEM;
228 Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
232 Srb->Lun = (UCHAR)Lun;
233 Srb->CdbLength = 10;
236 Srb->TimeOutValue = 5; /* in seconds */
238 Cdb = (PCDB)Srb->Cdb;
239 Cdb->CDB10.OperationCode = SCSIOP_READ_CAPACITY;
240 if (!SpiSendSynchronousSrb(DeviceExtension, Srb))
241 {
242 return EIO;
243 }
244
245 /* Transform result to host endianness */
248
249 if (Partition != 0)
250 {
251 /* Need to offset start of disk and length */
253 return EIO;
254 }
255
257 if (!Context)
258 return ENOMEM;
259 Context->DeviceExtension = DeviceExtension;
260 Context->PathId = (UCHAR)PathId;
261 Context->TargetId = (UCHAR)TargetId;
262 Context->Lun = (UCHAR)Lun;
263 Context->SectorSize = SectorSize;
264 Context->SectorOffset = SectorOffset;
265 Context->SectorCount = SectorCount;
266 Context->SectorNumber = 0;
268
269 return ESUCCESS;
270}
PRTL_UNICODE_STRING_BUFFER Path
#define EINVAL
Definition: acclib.h:90
#define ENOMEM
Definition: acclib.h:84
#define EIO
Definition: acclib.h:81
BOOLEAN DissectArcPath2(IN PCSTR ArcPath, OUT PULONG x, OUT PULONG y, OUT PULONG z, OUT PULONG Partition, OUT PULONG PathSyntax)
Definition: arcname.c:121
static BOOLEAN SpiSendSynchronousSrb(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb)
Definition: scsiport.c:129
PSCSI_PORT_DEVICE_EXTENSION ScsiDeviceExtensions[SCSI_MAXIMUM_BUSES]
Definition: scsiport.c:108
#define UNIMPLEMENTED
Definition: debug.h:118
VOID FsSetDeviceSpecific(ULONG FileId, PVOID Specific)
Definition: fs.c:625
#define SectorOffset(L)
Definition: cdprocs.h:1622
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
_In_ PREAD_CAPACITY_DATA ReadCapacityBuffer
Definition: cdrom.h:1103
struct _READ_CAPACITY_DATA READ_CAPACITY_DATA
#define SCSIOP_READ_CAPACITY
Definition: cdrw_hw.h:904
union _CDB * PCDB
_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
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR TargetId
Definition: classpnp.h:1314
struct _SCSI_REQUEST_BLOCK SCSI_REQUEST_BLOCK
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:315
#define SRB_FLAGS_DATA_IN
Definition: srb.h:400
#define PagedPool
Definition: env_spec_w32.h:308
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
if(dx< 0)
Definition: linetemp.h:194
#define ntohl(x)
Definition: module.h:205
ULONG SectorCount
Definition: part_xbox.c:31
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
Definition: scratch.h:159
ULONG LogicalBlockAddress
Definition: cdrw_hw.h:1471
ULONG TimeOutValue
Definition: srb.h:262
UCHAR TargetId
Definition: srb.h:254
PVOID DataBuffer
Definition: srb.h:263
UCHAR PathId
Definition: srb.h:253
UCHAR CdbLength
Definition: srb.h:258
UCHAR Cdb[16]
Definition: srb.h:279
UCHAR Function
Definition: srb.h:250
ULONG DataTransferLength
Definition: srb.h:261
ULONG SrbFlags
Definition: srb.h:260
USHORT Length
Definition: srb.h:249
uint32_t ULONG
Definition: typedefs.h:59
uint64_t ULONGLONG
Definition: typedefs.h:67
Definition: cdrw_hw.h:28
struct _CDB::_CDB10 CDB10
_In_ ULONG SectorSize
Definition: halfuncs.h:291
unsigned char UCHAR
Definition: xmlstorage.h:181

◆ DiskRead()

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

Definition at line 272 of file scsiport.c.

273{
276 PCDB Cdb;
277 ULONG FullSectors, NbSectors;
278 ULONG Lba;
279
280 *Count = 0;
281
282 if (N == 0)
283 return ESUCCESS;
284
285 FullSectors = N / Context->SectorSize;
286 NbSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
287 if (Context->SectorNumber + NbSectors >= Context->SectorCount)
288 return EINVAL;
289 if (FullSectors > 0xffff)
290 return EINVAL;
291
292 /* Read full sectors */
293 ASSERT(Context->SectorNumber < 0xFFFFFFFF);
294 Lba = (ULONG)(Context->SectorOffset + Context->SectorNumber);
295 if (FullSectors > 0)
296 {
298 if (!Srb)
299 return ENOMEM;
300
302 Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
304 Srb->PathId = Context->PathId;
305 Srb->TargetId = Context->TargetId;
306 Srb->Lun = Context->Lun;
307 Srb->CdbLength = 10;
309 Srb->DataTransferLength = FullSectors * Context->SectorSize;
310 Srb->TimeOutValue = 5; /* in seconds */
312 Cdb = (PCDB)Srb->Cdb;
313 Cdb->CDB10.OperationCode = SCSIOP_READ;
314 Cdb->CDB10.LogicalUnitNumber = Srb->Lun;
315 Cdb->CDB10.LogicalBlockByte0 = (Lba >> 24) & 0xff;
316 Cdb->CDB10.LogicalBlockByte1 = (Lba >> 16) & 0xff;
317 Cdb->CDB10.LogicalBlockByte2 = (Lba >> 8) & 0xff;
318 Cdb->CDB10.LogicalBlockByte3 = Lba & 0xff;
319 Cdb->CDB10.TransferBlocksMsb = (FullSectors >> 8) & 0xff;
320 Cdb->CDB10.TransferBlocksLsb = FullSectors & 0xff;
321 if (!SpiSendSynchronousSrb(Context->DeviceExtension, Srb))
322 {
323 return EIO;
324 }
325 Buffer = (PUCHAR)Buffer + FullSectors * Context->SectorSize;
326 N -= FullSectors * Context->SectorSize;
327 *Count += FullSectors * Context->SectorSize;
328 Context->SectorNumber += FullSectors;
329 Lba += FullSectors;
330 }
331
332 /* Read incomplete last sector */
333 if (N > 0)
334 {
335 PUCHAR Sector;
336
337 Sector = ExAllocatePool(PagedPool, Context->SectorSize);
338 if (!Sector)
339 return ENOMEM;
340
342 if (!Srb)
343 {
344 ExFreePool(Sector);
345 return ENOMEM;
346 }
347
349 Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
351 Srb->PathId = Context->PathId;
352 Srb->TargetId = Context->TargetId;
353 Srb->Lun = Context->Lun;
354 Srb->CdbLength = 10;
356 Srb->DataTransferLength = Context->SectorSize;
357 Srb->TimeOutValue = 5; /* in seconds */
358 Srb->DataBuffer = Sector;
359 Cdb = (PCDB)Srb->Cdb;
360 Cdb->CDB10.OperationCode = SCSIOP_READ;
361 Cdb->CDB10.LogicalUnitNumber = Srb->Lun;
362 Cdb->CDB10.LogicalBlockByte0 = (Lba >> 24) & 0xff;
363 Cdb->CDB10.LogicalBlockByte1 = (Lba >> 16) & 0xff;
364 Cdb->CDB10.LogicalBlockByte2 = (Lba >> 8) & 0xff;
365 Cdb->CDB10.LogicalBlockByte3 = Lba & 0xff;
366 Cdb->CDB10.TransferBlocksMsb = 0;
367 Cdb->CDB10.TransferBlocksLsb = 1;
368 if (!SpiSendSynchronousSrb(Context->DeviceExtension, Srb))
369 {
370 ExFreePool(Sector);
371 return EIO;
372 }
373 RtlCopyMemory(Buffer, Sector, N);
374 *Count += N;
375 /* Context->SectorNumber remains untouched (incomplete sector read) */
376 ExFreePool(Sector);
377 }
378
379 return ESUCCESS;
380}
#define N
Definition: crc32.c:57
#define SCSIOP_READ
Definition: cdrw_hw.h:905
Definition: bufpool.h:45
#define ASSERT(a)
Definition: mode.c:44
int Count
Definition: noreturn.cpp:7
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
unsigned char * PUCHAR
Definition: typedefs.h:53

◆ DiskSeek()

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

Definition at line 382 of file scsiport.c.

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

◆ LoadBootDeviceDriver()

ULONG LoadBootDeviceDriver ( VOID  )

Definition at line 1635 of file scsiport.c.

1636{
1637 PIMAGE_NT_HEADERS NtHeaders;
1639 PIMAGE_IMPORT_DESCRIPTOR ImportTable;
1640 ULONG ImportTableSize;
1641 PLDR_DATA_TABLE_ENTRY BootDdDTE, FreeldrDTE;
1642 CHAR NtBootDdPath[MAX_PATH];
1643 PVOID ImageBase = NULL;
1646
1647 // FIXME: Must be done *INSIDE* the HAL!
1648#ifdef _M_IX86
1651#endif
1652
1653 /* Initialize the loaded module list */
1655
1656 /* Create full ntbootdd.sys path */
1657 strcpy(NtBootDdPath, FrLdrBootPath);
1658 strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
1659
1660 /* Load file */
1661 Success = PeLdrLoadImage(NtBootDdPath, LoaderBootDriver, &ImageBase);
1662 if (!Success)
1663 {
1664 /* That's OK, file simply doesn't exist */
1665 return ESUCCESS;
1666 }
1667
1668 /* Allocate a DTE for ntbootdd */
1670 "NTBOOTDD.SYS", ImageBase, &BootDdDTE);
1671 if (!Success)
1672 {
1673 /* Cleanup and bail out */
1674 MmFreeMemory(ImageBase);
1675 return EIO;
1676 }
1677
1678 /* Add the PE part of freeldr.sys to the list of loaded executables, it
1679 contains ScsiPort* exports, imported by ntbootdd.sys */
1681 "FREELDR.SYS", &__ImageBase, &FreeldrDTE);
1682 if (!Success)
1683 {
1684 /* Cleanup and bail out */
1685 PeLdrFreeDataTableEntry(BootDdDTE);
1686 MmFreeMemory(ImageBase);
1687 return EIO;
1688 }
1689
1690 /* Fix imports */
1692 if (!Success)
1693 {
1694 /* Cleanup and bail out */
1695 PeLdrFreeDataTableEntry(FreeldrDTE);
1696 PeLdrFreeDataTableEntry(BootDdDTE);
1697 MmFreeMemory(ImageBase);
1698 return EIO;
1699 }
1700
1701 /* Now unlink the DTEs, they won't be valid later */
1702 RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1703 RemoveEntryList(&FreeldrDTE->InLoadOrderLinks);
1704
1705 /* Change imports to PA */
1707 TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
1708 for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
1709 {
1710 PIMAGE_THUNK_DATA ThunkData = (PIMAGE_THUNK_DATA)VaToPa(RVA(BootDdDTE->DllBase, ImportTable->FirstThunk));
1711
1712 while (((PIMAGE_THUNK_DATA)ThunkData)->u1.AddressOfData != 0)
1713 {
1714 ThunkData->u1.Function = (ULONG_PTR)VaToPa((PVOID)ThunkData->u1.Function);
1715 ThunkData++;
1716 }
1717 }
1718
1719 /* Relocate image to PA */
1720 NtHeaders = RtlImageNtHeader(VaToPa(BootDdDTE->DllBase));
1721 if (!NtHeaders)
1722 return EIO;
1724 NtHeaders->OptionalHeader.ImageBase - (ULONG_PTR)BootDdDTE->DllBase,
1725 "FreeLdr",
1726 TRUE,
1727 TRUE, /* In case of conflict still return success */
1728 FALSE);
1729 if (!Success)
1730 return EIO;
1731
1732 /* Call the entrypoint */
1733 EntryPoint = VaToPa(BootDdDTE->EntryPoint);
1734 (*EntryPoint)(NULL, NULL);
1735
1736 return ESUCCESS;
1737}
unsigned char BOOLEAN
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
char __ImageBase
VOID MmFreeMemory(PVOID MemoryPointer)
Definition: mm.c:215
VOID NTAPI HalpInitBusHandler(VOID)
Definition: bushndlr.c:444
VOID NTAPI HalpInitializePciStubs(VOID)
Definition: pcibus.c:1190
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define RtlImageDirectoryEntryToData
Definition: compat.h:809
#define RtlImageNtHeader
Definition: compat.h:806
#define MAX_PATH
Definition: compat.h:34
#define ULONG_PTR
Definition: config.h:101
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
@ Success
Definition: eventcreate.c:712
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:29
#define RVA(m, b)
Definition: freeldr.h:28
GLdouble u1
Definition: glext.h:8308
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID BaseAddress, _In_ LONGLONG AdditionalBias, _In_opt_ PCSTR LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
Definition: image.c:474
struct _IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA
Definition: ntimage.h:566
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
#define BOOLEAN
Definition: pedump.c:73
BOOLEAN PeLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE)
Definition: peloader.c:605
VOID PeLdrFreeDataTableEntry(_In_ PLDR_DATA_TABLE_ENTRY Entry)
Definition: peloader.c:798
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:681
BOOLEAN PeLdrLoadImage(_In_ PCSTR FilePath, _In_ TYPE_OF_MEMORY MemoryType, _Out_ PVOID *ImageBasePA)
Loads the specified image from the file.
Definition: peloader.c:823
@ LoaderBootDriver
Definition: arc.h:185
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
union _IMAGE_THUNK_DATA32::@2138 u1
Definition: btrfs_drv.h:1876
PVOID EntryPoint
Definition: ntddk_ex.h:203
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:138
PVOID DllBase
Definition: btrfs_drv.h:1880
Definition: typedefs.h:120
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
char CHAR
Definition: xmlstorage.h:175

Referenced by RunLoader().

◆ ntohl()

ULONG ntohl ( IN ULONG  Value)

Definition at line 113 of file scsiport.c.

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

◆ ScsiDebugPrint()

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

Definition at line 471 of file scsiport.c.

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

◆ ScsiPortCompleteRequest()

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

Definition at line 507 of file scsiport.c.

513{
514 // FIXME
516}

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

◆ ScsiPortConvertPhysicalAddressToUlong()

ULONG NTAPI ScsiPortConvertPhysicalAddressToUlong ( IN SCSI_PHYSICAL_ADDRESS  Address)

Definition at line 521 of file scsiport.c.

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

◆ ScsiPortConvertUlongToPhysicalAddress()

◆ ScsiPortFlushDma()

VOID NTAPI ScsiPortFlushDma ( IN PVOID  DeviceExtension)

Definition at line 540 of file scsiport.c.

542{
543 // FIXME
545}

◆ ScsiPortFreeDeviceBase()

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

Definition at line 549 of file scsiport.c.

552{
553 // Nothing to do
554}

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 558 of file scsiport.c.

565{
566 return HalGetBusDataByOffset(BusDataType, SystemIoBusNumber, SlotNumber, Buffer, 0, Length);
567}
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
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:68

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 571 of file scsiport.c.

578{
581
582 AddressSpace = (ULONG)InIoSpace;
584 SystemIoBusNumber,
585 IoAddress,
588 {
589 return NULL;
590 }
591
592 /* I/O space */
593 if (AddressSpace != 0)
594 return (PVOID)(ULONG_PTR)TranslatedAddress.u.LowPart;
595
596 // FIXME
597#if 0
600 FALSE);
601#else
603 return (PVOID)(ULONG_PTR)IoAddress.LowPart;
604#endif
605}
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
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
struct _LARGE_INTEGER::@2299 u
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:159
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2275
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1036

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 609 of file scsiport.c.

614{
615 // FIXME
617 return NULL;
618}

◆ ScsiPortGetPhysicalAddress()

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

Definition at line 622 of file scsiport.c.

627{
628 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
632
633 TRACE("ScsiPortGetPhysicalAddress(%p %p %p %p)\n",
634 HwDeviceExtension, Srb, VirtualAddress, Length);
635
636 DeviceExtension = ((PSCSI_PORT_DEVICE_EXTENSION)HwDeviceExtension) - 1;
637
639 {
640 /* Simply look it up in the allocated common buffer */
642
643 BufferLength = DeviceExtension->CommonBufferLength - Offset;
645 }
646 else
647 {
648 /* Nothing */
650 }
651
653 return PhysicalAddress;
654}
struct SCSI_PORT_DEVICE_EXTENSION * PSCSI_PORT_DEVICE_EXTENSION
#define SP_UNINITIALIZED_VALUE
Definition: srb.h:232
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
PVOID SenseInfoBuffer
Definition: srb.h:264
int64_t LONGLONG
Definition: typedefs.h:68
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3771
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098

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 658 of file scsiport.c.

664{
665 // FIXME
667 return NULL;
668}

Referenced by AtapiStartIo__(), and BT958HwStartIO().

◆ ScsiPortGetUncachedExtension()

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

Definition at line 736 of file scsiport.c.

740{
741 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
743 ULONG MapRegistersCount;
745
746 TRACE("ScsiPortGetUncachedExtension(%p %p %lu)\n",
747 HwDeviceExtension, ConfigInfo, NumberOfBytes);
748
749 DeviceExtension = ((PSCSI_PORT_DEVICE_EXTENSION)HwDeviceExtension) - 1;
750
751 /* Check for allocated common DMA buffer */
752 if (DeviceExtension->SrbExtensionBuffer != NULL)
753 {
754 return NULL;
755 }
756
757 /* Check for DMA adapter object */
758 if (DeviceExtension->AdapterObject == NULL)
759 {
760 /* Initialize DMA adapter description */
762
764 DeviceDescription.Master = ConfigInfo->Master;
765 DeviceDescription.ScatterGather = ConfigInfo->ScatterGather;
766 DeviceDescription.DemandMode = ConfigInfo->DemandMode;
767 DeviceDescription.Dma32BitAddresses = ConfigInfo->Dma32BitAddresses;
768 DeviceDescription.BusNumber = ConfigInfo->SystemIoBusNumber;
769 DeviceDescription.DmaChannel = ConfigInfo->DmaChannel;
770 DeviceDescription.InterfaceType = ConfigInfo->AdapterInterfaceType;
771 DeviceDescription.DmaWidth = ConfigInfo->DmaWidth;
772 DeviceDescription.DmaSpeed = ConfigInfo->DmaSpeed;
773 DeviceDescription.MaximumLength = ConfigInfo->MaximumTransferLength;
774 DeviceDescription.DmaPort = ConfigInfo->DmaPort;
775
776 /* Get a DMA adapter object */
777#if 0
778 DeviceExtension->AdapterObject =
779 HalGetAdapter(&DeviceDescription, &MapRegistersCount);
780
781 /* Fail in case of error */
782 if (DeviceExtension->AdapterObject == NULL)
783 {
784 return NULL;
785 }
786#else
787 MapRegistersCount = 0;
788#endif
789
790 /* Set number of physical breaks */
791 if (ConfigInfo->NumberOfPhysicalBreaks != 0 &&
792 MapRegistersCount > ConfigInfo->NumberOfPhysicalBreaks)
793 {
794 DeviceExtension->PortCapabilities.MaximumPhysicalPages =
795 ConfigInfo->NumberOfPhysicalBreaks;
796 }
797 else
798 {
799 DeviceExtension->PortCapabilities.MaximumPhysicalPages = MapRegistersCount;
800 }
801 }
802
803 /* Update Srb extension size */
804 if (DeviceExtension->SrbExtensionSize != ConfigInfo->SrbExtensionSize)
805 DeviceExtension->SrbExtensionSize = ConfigInfo->SrbExtensionSize;
806
807 /* Allocate a common DMA buffer */
808 Status = SpiAllocateCommonBuffer(DeviceExtension, NumberOfBytes);
809
810 if (!NT_SUCCESS(Status))
811 {
812 TRACE("SpiAllocateCommonBuffer() failed with Status = 0x%08X!\n", Status);
813 return NULL;
814 }
815
816 return DeviceExtension->NonCachedExtension;
817}
LONG NTSTATUS
Definition: precomp.h:26
static NTSTATUS SpiAllocateCommonBuffer(IN OUT PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN ULONG NonCachedSize)
Definition: scsiport.c:672
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
Status
Definition: gdiplustypes.h:25
PADAPTER_OBJECT NTAPI HalGetAdapter(IN PDEVICE_DESCRIPTION DeviceDescription, OUT PULONG NumberOfMapRegisters)
Definition: dma.c:22
PADAPTER_OBJECT AdapterObject
Definition: scsiport.c:86
IO_SCSI_CAPABILITIES PortCapabilities
Definition: scsiport.c:78
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceDescription
Definition: wdfpdo.h:432
#define DEVICE_DESCRIPTION_VERSION
Definition: iotypes.h:2063

Referenced by Buslogic_InitBT958().

◆ ScsiPortGetVirtualAddress()

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

Definition at line 821 of file scsiport.c.

824{
825 // FIXME
827 return NULL;
828}

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 1133 of file scsiport.c.

1138{
1139 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
1140 ULONG DeviceExtensionSize;
1142 BOOLEAN Again;
1143 BOOLEAN FirstConfigCall = TRUE;
1145 UCHAR ScsiBus;
1147
1148 if (HwInitializationData->HwInitializationDataSize != sizeof(HW_INITIALIZATION_DATA))
1149 {
1151 }
1152
1153 /* Check params for validity */
1154 if ((HwInitializationData->HwInitialize == NULL) ||
1155 (HwInitializationData->HwStartIo == NULL) ||
1156 (HwInitializationData->HwInterrupt == NULL) ||
1157 (HwInitializationData->HwFindAdapter == NULL) ||
1158 (HwInitializationData->HwResetBus == NULL))
1159 {
1161 }
1162
1163 /* Zero starting slot number */
1164 SlotNumber.u.AsULONG = 0;
1165
1166 while (TRUE)
1167 {
1168 Again = FALSE;
1169
1170 DeviceExtensionSize = sizeof(SCSI_PORT_DEVICE_EXTENSION) + HwInitializationData->DeviceExtensionSize;
1171 DeviceExtension = FrLdrTempAlloc(DeviceExtensionSize, TAG_SCSI_DEVEXT);
1172 if (!DeviceExtension)
1173 {
1174 return STATUS_NO_MEMORY;
1175 }
1176 RtlZeroMemory(DeviceExtension, DeviceExtensionSize);
1178 DeviceExtension->HwInitialize = HwInitializationData->HwInitialize;
1179 DeviceExtension->HwStartIo = HwInitializationData->HwStartIo;
1180 DeviceExtension->HwInterrupt = HwInitializationData->HwInterrupt;
1181 DeviceExtension->HwResetBus = HwInitializationData->HwResetBus;
1182 DeviceExtension->MiniPortDeviceExtension = (PVOID)(DeviceExtension + 1);
1183
1184 Status = SpiCreatePortConfig(DeviceExtension,
1186 &PortConfig,
1187 FirstConfigCall);
1188 if (Status != STATUS_SUCCESS)
1189 {
1190 FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1191 return Status;
1192 }
1193
1194 PortConfig.NumberOfAccessRanges = HwInitializationData->NumberOfAccessRanges;
1195 PortConfig.AccessRanges = FrLdrTempAlloc(sizeof(ACCESS_RANGE) * HwInitializationData->NumberOfAccessRanges,
1197 if (!PortConfig.AccessRanges)
1198 {
1199 FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1200 return STATUS_NO_MEMORY;
1201 }
1202 RtlZeroMemory(PortConfig.AccessRanges, sizeof(ACCESS_RANGE) * HwInitializationData->NumberOfAccessRanges);
1203
1204 /* Search for matching PCI device */
1205 if ((HwInitializationData->AdapterInterfaceType == PCIBus) &&
1206 (HwInitializationData->VendorIdLength > 0) &&
1207 (HwInitializationData->VendorId != NULL) &&
1208 (HwInitializationData->DeviceIdLength > 0) &&
1209 (HwInitializationData->DeviceId != NULL))
1210 {
1211 PortConfig.BusInterruptLevel = 0;
1212
1213 /* Get PCI device data */
1214 TRACE("VendorId '%.*s' DeviceId '%.*s'\n",
1215 HwInitializationData->VendorIdLength,
1216 HwInitializationData->VendorId,
1217 HwInitializationData->DeviceIdLength,
1218 HwInitializationData->DeviceId);
1219
1221 &PortConfig,
1222 0, /* FIXME */
1223 &SlotNumber))
1224 {
1225 /* Continue to the next bus, nothing here */
1226 FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1227 return STATUS_INTERNAL_ERROR;
1228 }
1229
1230 if (!PortConfig.BusInterruptLevel)
1231 {
1232 /* Bypass this slot, because no interrupt was assigned */
1233 FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1234 return STATUS_INTERNAL_ERROR;
1235 }
1236 }
1237
1238 if (HwInitializationData->HwFindAdapter(
1239 DeviceExtension->MiniPortDeviceExtension,
1240 HwContext,
1241 NULL,
1242 NULL,
1243 &PortConfig,
1244 &Again) != SP_RETURN_FOUND)
1245 {
1246 FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1247 return STATUS_INTERNAL_ERROR;
1248 }
1249
1250 /* Copy all stuff which we ever need from PortConfig to the DeviceExtension */
1252 DeviceExtension->MaxTargedIds = SCSI_MAXIMUM_TARGETS_PER_BUS;
1253 else
1254 DeviceExtension->MaxTargedIds = PortConfig.MaximumNumberOfTargets;
1255
1256 DeviceExtension->BusNum = PortConfig.SystemIoBusNumber;
1257
1258 TRACE("Adapter found: buses = %d, targets = %d\n",
1259 PortConfig.NumberOfBuses, DeviceExtension->MaxTargedIds);
1260
1261 /* Initialize adapter */
1262 if (!DeviceExtension->HwInitialize(DeviceExtension->MiniPortDeviceExtension))
1263 {
1264 FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1265 return STATUS_INTERNAL_ERROR;
1266 }
1267
1268 /* Scan bus */
1269 for (ScsiBus = 0; ScsiBus < PortConfig.NumberOfBuses; ScsiBus++)
1270 {
1271 SpiScanAdapter(DeviceExtension, PortConfig.SystemIoBusNumber, ScsiBus);
1272 PortConfig.SystemIoBusNumber++;
1273 }
1274
1275 FirstConfigCall = FALSE;
1276 if (!Again)
1277 {
1278 break;
1279 }
1280 }
1281
1282 return STATUS_SUCCESS;
1283}
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:1033
static VOID SpiScanAdapter(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN ULONG ScsiBus, IN UCHAR PathId)
Definition: scsiport.c:877
#define TAG_SCSI_ACCESS_RANGES
Definition: scsiport.c:56
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:422
#define SCSI_PORT_NEXT_REQUEST_READY
Definition: scsiport.c:53
#define TAG_SCSI_DEVEXT
Definition: scsiport.c:55
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197
#define STATUS_NO_MEMORY
Definition: d3dkmdt.h:51
#define SCSI_MAXIMUM_TARGETS_PER_BUS
Definition: srb.h:22
#define SP_RETURN_FOUND
Definition: srb.h:522
@ PCIBus
Definition: hwresource.cpp:142
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
_Must_inspect_result_ _In_ PVOID _In_ struct _HW_INITIALIZATION_DATA _In_ PVOID HwContext
Definition: srb.h:907
_Must_inspect_result_ _In_ PVOID _In_ struct _HW_INITIALIZATION_DATA * HwInitializationData
Definition: srb.h:906
#define STATUS_SUCCESS
Definition: shellext.h:65
PHW_INITIALIZE HwInitialize
Definition: scsiport.c:80
PHW_RESET_BUS HwResetBus
Definition: scsiport.c:83
PHW_INTERRUPT HwInterrupt
Definition: scsiport.c:82
ACCESS_RANGE(* AccessRanges)[]
Definition: srb.h:74
void * PVOID
Definition: typedefs.h:50
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135

Referenced by DriverEntry().

◆ ScsiPortIoMapTransfer()

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

Definition at line 1287 of file scsiport.c.

1292{
1293 // FIXME
1295}

◆ 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 1299 of file scsiport.c.

1307{
1308 // FIXME
1310}

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 1314 of file scsiport.c.

1318{
1320}
#define WriteBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:344
#define ReadBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:339
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264

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 1324 of file scsiport.c.

1328{
1329 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
1331 va_list ap;
1332
1333 DeviceExtension = ((PSCSI_PORT_DEVICE_EXTENSION)HwDeviceExtension) - 1;
1334
1335 va_start(ap, HwDeviceExtension);
1336
1337 switch (NotificationType)
1338 {
1339 case RequestComplete:
1340 /* Mask the SRB as completed */
1342 Srb->SrbFlags &= ~SRB_FLAGS_IS_ACTIVE;
1343 break;
1344
1345 case NextRequest:
1346 /* Say that device is ready */
1347 DeviceExtension->InterruptFlags |= SCSI_PORT_NEXT_REQUEST_READY;
1348 break;
1349
1350 default:
1351 // FIXME
1353 }
1354
1355 va_end(ap);
1356}
#define va_arg(ap, T)
Definition: acmsvcex.h:89
@ RequestComplete
Definition: srb.h:531
@ NextRequest
Definition: srb.h:532
_In_ WDF_SPECIAL_FILE_TYPE NotificationType
Definition: wdfdevice.h:1024

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 1360 of file scsiport.c.

1364{
1366}
#define H2I(Port)
Definition: portio.c:18
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

◆ ScsiPortReadPortBufferUlong()

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

Definition at line 1370 of file scsiport.c.

1374{
1376}
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 1380 of file scsiport.c.

1384{
1386}
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)

◆ ScsiPortReadPortUlong()

ULONG NTAPI ScsiPortReadPortUlong ( IN PULONG  Port)

Definition at line 1400 of file scsiport.c.

1402{
1403 return READ_PORT_ULONG(Port);
1404}
ULONG NTAPI READ_PORT_ULONG(IN PULONG Port)
Definition: portio.c:70

◆ ScsiPortReadPortUshort()

USHORT NTAPI ScsiPortReadPortUshort ( IN PUSHORT  Port)

Definition at line 1408 of file scsiport.c.

1410{
1411 return READ_PORT_USHORT(Port);
1412}
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 1416 of file scsiport.c.

1420{
1421 // FIXME
1423}

◆ ScsiPortReadRegisterBufferUlong()

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

Definition at line 1427 of file scsiport.c.

1431{
1432 // FIXME
1434}

◆ ScsiPortReadRegisterBufferUshort()

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

Definition at line 1438 of file scsiport.c.

1442{
1443 // FIXME
1445}

◆ ScsiPortReadRegisterUchar()

UCHAR NTAPI ScsiPortReadRegisterUchar ( IN PUCHAR  Register)

Definition at line 1449 of file scsiport.c.

1451{
1453}
NTKERNELAPI UCHAR NTAPI READ_REGISTER_UCHAR(IN PUCHAR Register)

◆ ScsiPortReadRegisterUlong()

ULONG NTAPI ScsiPortReadRegisterUlong ( IN PULONG  Register)

Definition at line 1457 of file scsiport.c.

1459{
1461}
#define READ_REGISTER_ULONG(r)
Definition: arm.h:26

◆ ScsiPortReadRegisterUshort()

USHORT NTAPI ScsiPortReadRegisterUshort ( IN PUSHORT  Register)

Definition at line 1465 of file scsiport.c.

1467{
1469}
#define READ_REGISTER_USHORT(r)
Definition: arm.h:29

◆ 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 1473 of file scsiport.c.

1481{
1482 // FIXME
1484 return 0;
1485}

◆ 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 1497 of file scsiport.c.

1504{
1505 // FIXME
1507 return TRUE;
1508}

Referenced by BT958HwFindAdapter(), and UniataFindBusMasterController().

◆ ScsiPortWritePortBufferUchar()

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

Definition at line 1517 of file scsiport.c.

1521{
1523}
PPC_QUAL void __outbytestring(unsigned long const Port, const unsigned char *const Buffer, const unsigned long Count)
Definition: intrin_ppc.h:653

◆ ScsiPortWritePortBufferUlong()

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

Definition at line 1527 of file scsiport.c.

1531{
1533}
PPC_QUAL void __outdwordstring(unsigned long const Port, const unsigned long *const Buffer, const unsigned long Count)
Definition: intrin_ppc.h:671

◆ ScsiPortWritePortBufferUshort()

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

Definition at line 1537 of file scsiport.c.

1541{
1543}
PPC_QUAL void __outwordstring(unsigned long const Port, const unsigned short *const Buffer, const unsigned long Count)
Definition: intrin_ppc.h:662

◆ ScsiPortWritePortUchar()

◆ ScsiPortWritePortUlong()

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

Definition at line 1556 of file scsiport.c.

1559{
1561}
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123

◆ ScsiPortWritePortUshort()

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

Definition at line 1565 of file scsiport.c.

1568{
1570}
VOID NTAPI WRITE_PORT_USHORT(IN PUSHORT Port, IN USHORT Value)
Definition: portio.c:115

◆ ScsiPortWriteRegisterBufferUchar()

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

Definition at line 1574 of file scsiport.c.

1578{
1579 // FIXME
1581}

◆ ScsiPortWriteRegisterBufferUlong()

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

Definition at line 1585 of file scsiport.c.

1589{
1590 // FIXME
1592}

◆ ScsiPortWriteRegisterBufferUshort()

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

Definition at line 1596 of file scsiport.c.

1600{
1601 // FIXME
1603}

◆ ScsiPortWriteRegisterUchar()

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

Definition at line 1607 of file scsiport.c.

1610{
1612}
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 1616 of file scsiport.c.

1619{
1621}
#define WRITE_REGISTER_ULONG(r, v)
Definition: arm.h:27

◆ ScsiPortWriteRegisterUshort()

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

Definition at line 1625 of file scsiport.c.

1628{
1630}
#define WRITE_REGISTER_USHORT(r, v)
Definition: arm.h:30

◆ SpiAllocateCommonBuffer()

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

Definition at line 672 of file scsiport.c.

675{
677 ULONG CommonBufferLength, BufSize;
678
679 /* If size is 0, set it to 16 */
680 if (!DeviceExtension->SrbExtensionSize)
681 DeviceExtension->SrbExtensionSize = 16;
682
683 /* Calculate size */
684 BufSize = DeviceExtension->SrbExtensionSize;
685
686 /* Round it */
687 BufSize = (BufSize + sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1);
688
689 /* Sum up into the total common buffer length, and round it to page size */
690 CommonBufferLength =
691 ROUND_TO_PAGES(NonCachedSize);
692
693 /* Allocate it */
694 if (!DeviceExtension->AdapterObject)
695 {
696 /* From nonpaged pool if there is no DMA */
697 CommonBuffer = ExAllocatePool(NonPagedPool, CommonBufferLength);
698 }
699 else
700 {
701 /* Perform a full request since we have a DMA adapter*/
704 }
705
706 /* Fail in case of error */
707 if (!CommonBuffer)
709
710 /* Zero it */
711 RtlZeroMemory(CommonBuffer, CommonBufferLength);
712
713 /* Store its size in Device Extension */
714 DeviceExtension->CommonBufferLength = CommonBufferLength;
715
716 /* SrbExtension buffer is located at the beginning of the buffer */
717 DeviceExtension->SrbExtensionBuffer = CommonBuffer;
718
719 /* Non-cached extension buffer is located at the end of
720 the common buffer */
721 if (NonCachedSize)
722 {
723 CommonBufferLength -= NonCachedSize;
724 DeviceExtension->NonCachedExtension = (PUCHAR)CommonBuffer + CommonBufferLength;
725 }
726 else
727 {
728 DeviceExtension->NonCachedExtension = NULL;
729 }
730
731 return STATUS_SUCCESS;
732}
#define BufSize
Definition: FsRtlTunnel.c:28
#define NonPagedPool
Definition: env_spec_w32.h:307
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFCOMMONBUFFER * CommonBuffer
#define ROUND_TO_PAGES(Size)

Referenced by ScsiPortGetUncachedExtension(), and ScsiPortInitialize().

◆ 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 422 of file scsiport.c.

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

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 1033 of file scsiport.c.

1038{
1039 PCI_COMMON_CONFIG PciConfig;
1043 ULONG FunctionNumber;
1044 CHAR VendorIdString[8];
1045 CHAR DeviceIdString[8];
1048
1049 SlotNumber.u.AsULONG = 0;
1050
1051 /* Loop through all devices */
1052 for (DeviceNumber = NextSlotNumber->u.bits.DeviceNumber; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
1053 {
1054 SlotNumber.u.bits.DeviceNumber = DeviceNumber;
1055
1056 /* Loop through all functions */
1057 for (FunctionNumber = NextSlotNumber->u.bits.FunctionNumber; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
1058 {
1059 SlotNumber.u.bits.FunctionNumber = FunctionNumber;
1060
1061 /* Get PCI config bytes */
1064 BusNumber,
1065 SlotNumber.u.AsULONG,
1066 &PciConfig,
1067 0,
1068 sizeof(ULONG));
1069
1070 /* If result of HalGetBusData is 0, then the bus is wrong */
1071 if (DataSize == 0)
1072 return FALSE;
1073
1074 /* If result is PCI_INVALID_VENDORID, then this device has no more
1075 "Functions" */
1076 if (PciConfig.VendorID == PCI_INVALID_VENDORID)
1077 break;
1078
1079 sprintf(VendorIdString, "%04hx", PciConfig.VendorID);
1080 sprintf(DeviceIdString, "%04hx", PciConfig.DeviceID);
1081
1082 if (_strnicmp(VendorIdString, HwInitializationData->VendorId, HwInitializationData->VendorIdLength) ||
1083 _strnicmp(DeviceIdString, HwInitializationData->DeviceId, HwInitializationData->DeviceIdLength))
1084 {
1085 /* It is not our device */
1086 continue;
1087 }
1088
1089 TRACE( "Found device 0x%04hx 0x%04hx at %1lu %2lu %1lu\n",
1090 PciConfig.VendorID, PciConfig.DeviceID,
1091 BusNumber,
1092 SlotNumber.u.bits.DeviceNumber, SlotNumber.u.bits.FunctionNumber);
1093
1095 NULL,
1096 NULL,
1097 NULL,
1098 PCIBus,
1099 BusNumber,
1100 SlotNumber.u.AsULONG,
1101 &ResourceList);
1102
1103 if (!NT_SUCCESS(Status))
1104 break;
1105
1106 /* Create configuration information */
1108 ResourceList->List,
1109 PortConfig);
1110
1111 /* Free the resource list */
1113
1114 /* Set dev & fn numbers */
1115 NextSlotNumber->u.bits.DeviceNumber = DeviceNumber;
1116 NextSlotNumber->u.bits.FunctionNumber = FunctionNumber + 1;
1117
1118 /* Save the slot number */
1119 PortConfig->SlotNumber = SlotNumber.u.AsULONG;
1120
1121 return TRUE;
1122 }
1123 NextSlotNumber->u.bits.FunctionNumber = 0;
1124 }
1125
1126 NextSlotNumber->u.bits.DeviceNumber = 0;
1127
1128 return FALSE;
1129}
static VOID SpiResourceToConfig(IN PHW_INITIALIZATION_DATA HwInitializationData, IN PCM_FULL_RESOURCE_DESCRIPTOR ResourceDescriptor, IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig)
Definition: scsiport.c:952
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1230
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
NTHALAPI NTSTATUS NTAPI HalAssignSlotResources(PUNICODE_STRING, PUNICODE_STRING, PDRIVER_OBJECT, PDEVICE_OBJECT, INTERFACE_TYPE, ULONG, ULONG, PCM_RESOURCE_LIST *)
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4755
@ PCIConfiguration
Definition: miniport.h:93
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:160
#define PCI_INVALID_VENDORID
Definition: iotypes.h:3601
#define PCI_MAX_FUNCTION
Definition: iotypes.h:3599
#define PCI_MAX_DEVICES
Definition: iotypes.h:3598

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 952 of file scsiport.c.

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

Referenced by SpiGetPciConfigData().

◆ SpiScanAdapter()

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

Definition at line 877 of file scsiport.c.

881{
882 CHAR ArcName[64];
884 PCDB Cdb;
885 INQUIRYDATA InquiryBuffer;
887 UCHAR Lun;
888
889 if (!DeviceExtension->HwResetBus(DeviceExtension->MiniPortDeviceExtension, PathId))
890 {
891 return;
892 }
893
894 /* Remember the extension */
895 ScsiDeviceExtensions[ScsiBus] = DeviceExtension;
896
897 for (TargetId = 0; TargetId < DeviceExtension->MaxTargedIds; TargetId++)
898 {
899 Lun = 0;
900 do
901 {
902 TRACE("Scanning SCSI device %d.%d.%d\n",
903 ScsiBus, TargetId, Lun);
904
906 if (!Srb)
907 break;
909 Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
911 Srb->PathId = PathId;
913 Srb->Lun = Lun;
914 Srb->CdbLength = 6;
917 Srb->TimeOutValue = 5; /* in seconds */
918 Srb->DataBuffer = &InquiryBuffer;
919 Cdb = (PCDB)Srb->Cdb;
920 Cdb->CDB6INQUIRY.OperationCode = SCSIOP_INQUIRY;
921 Cdb->CDB6INQUIRY.LogicalUnitNumber = Srb->Lun;
922 Cdb->CDB6INQUIRY.AllocationLength = (UCHAR)Srb->DataTransferLength;
923 if (!SpiSendSynchronousSrb(DeviceExtension, Srb))
924 {
925 /* Don't check next LUNs */
926 break;
927 }
928
929 /* Device exists, create its ARC name */
930 if (InquiryBuffer.RemovableMedia)
931 {
932 sprintf(ArcName, "scsi(%ld)cdrom(%d)fdisk(%d)",
933 ScsiBus, TargetId, Lun);
934 FsRegisterDevice(ArcName, &DiskVtbl);
935 }
936 else
937 {
938 sprintf(ArcName, "scsi(%ld)disk(%d)rdisk(%d)",
939 ScsiBus, TargetId, Lun);
940 /* Now, check if it has partitions */
941 SpiScanDevice(DeviceExtension, ArcName, PathId, TargetId, Lun);
942 }
943
944 /* Check next LUN */
945 Lun++;
947 }
948}
static const DEVVTBL DiskVtbl
Definition: scsiport.c:411
static VOID SpiScanDevice(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PCHAR ArcName, IN ULONG ScsiBus, IN ULONG TargetId, IN ULONG Lun)
Definition: scsiport.c:832
VOID FsRegisterDevice(_In_ PCSTR DeviceName, _In_ const DEVVTBL *FuncTable)
Definition: fs.c:596
#define SCSIOP_INQUIRY
Definition: cdrw_hw.h:888
#define INQUIRYDATABUFFERSIZE
Definition: cdrw_hw.h:1113
#define SCSI_MAXIMUM_LOGICAL_UNITS
Definition: srb.h:21
UCHAR RemovableMedia
Definition: cdrw_hw.h:1119
struct _CDB::_CDB6INQUIRY CDB6INQUIRY

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 832 of file scsiport.c.

838{
839 ULONG FileId, i;
843 CHAR PartitionName[64];
844
845 /* Register device with partition(0) suffix */
846 RtlStringCbPrintfA(PartitionName, sizeof(PartitionName), "%spartition(0)", ArcName);
847 FsRegisterDevice(PartitionName, &DiskVtbl);
848
849 /* Read device partition table */
850 Status = ArcOpen(PartitionName, OpenReadOnly, &FileId);
851 if (Status == ESUCCESS)
852 {
853 ret = HALDISPATCH->HalIoReadPartitionTable((PDEVICE_OBJECT)(ULONG_PTR)FileId,
854 512, FALSE, &PartitionBuffer);
855 if (NT_SUCCESS(ret))
856 {
857 for (i = 0; i < PartitionBuffer->PartitionCount; i++)
858 {
859 if (PartitionBuffer->PartitionEntry[i].PartitionType != PARTITION_ENTRY_UNUSED)
860 {
861 RtlStringCbPrintfA(PartitionName,
862 sizeof(PartitionName),
863 "%spartition(%lu)",
864 ArcName,
865 PartitionBuffer->PartitionEntry[i].PartitionNumber);
866 FsRegisterDevice(PartitionName, &DiskVtbl);
867 }
868 }
870 }
871 ArcClose(FileId);
872 }
873}
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:87
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:219
ARC_STATUS ArcClose(_In_ ULONG FileId)
Definition: fs.c:409
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
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
ULONG ARC_STATUS
Definition: arc.h:4
@ OpenReadOnly
Definition: arc.h:65
uint32_t ULONG_PTR
Definition: typedefs.h:65
int ret
#define HALDISPATCH
Definition: haltypes.h:278
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2052

Referenced by SpiScanAdapter().

◆ SpiSendSynchronousSrb()

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

Definition at line 129 of file scsiport.c.

132{
133 BOOLEAN ret;
134
136
137 /* HACK: handle lack of interrupts */
138 while (!(DeviceExtension->InterruptFlags & SCSI_PORT_NEXT_REQUEST_READY))
139 {
140 KeStallExecutionProcessor(100 * 1000);
141 if (!DeviceExtension->HwInterrupt(DeviceExtension->MiniPortDeviceExtension))
142 {
144 return FALSE;
145 }
146 }
147
148 DeviceExtension->InterruptFlags &= ~SCSI_PORT_NEXT_REQUEST_READY;
150
151 if (!DeviceExtension->HwStartIo(
152 DeviceExtension->MiniPortDeviceExtension,
153 Srb))
154 {
156 return FALSE;
157 }
158
159 /* HACK: handle lack of interrupts */
161 {
162 KeStallExecutionProcessor(100 * 1000);
163 if (!DeviceExtension->HwInterrupt(DeviceExtension->MiniPortDeviceExtension))
164 {
166 return FALSE;
167 }
168 }
169
172
173 return ret;
174}
#define SRB_FLAGS_IS_ACTIVE
Definition: srb.h:407
#define SRB_STATUS(Status)
Definition: srb.h:389
#define SRB_STATUS_SUCCESS
Definition: srb.h:341
UCHAR SrbStatus
Definition: srb.h:251

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

Variable Documentation

◆ __ImageBase

char __ImageBase
extern

Referenced by LoadBootDeviceDriver().

◆ DiskVtbl

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

Definition at line 411 of file scsiport.c.

Referenced by SpiScanAdapter(), and SpiScanDevice().

◆ ScsiDeviceExtensions

Definition at line 108 of file scsiport.c.

Referenced by DiskOpen(), and SpiScanAdapter().