2 * PROJECT: ReactOS Boot Loader (FreeLDR)
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: boot/freeldr/freeldr/disk/scsiport.c
5 * PURPOSE: Interface for SCSI Emulation
6 * PROGRAMMERS: Hervé Poussineau <hpoussin@reactos.org>
9 /* INCLUDES *******************************************************************/
14 DBG_DEFAULT_CHANNEL(SCSIPORT
);
27 #undef ScsiPortLogError
28 #undef ScsiPortMoveMemory
29 #undef ScsiPortWritePortBufferUchar
30 #undef ScsiPortWritePortBufferUlong
31 #undef ScsiPortWritePortBufferUshort
32 #undef ScsiPortWritePortUchar
33 #undef ScsiPortWritePortUlong
34 #undef ScsiPortWritePortUshort
35 #undef ScsiPortWriteRegisterBufferUchar
36 #undef ScsiPortWriteRegisterBufferUlong
37 #undef ScsiPortWriteRegisterBufferUshort
38 #undef ScsiPortWriteRegisterUchar
39 #undef ScsiPortWriteRegisterUlong
40 #undef ScsiPortWriteRegisterUshort
41 #undef ScsiPortReadPortBufferUchar
42 #undef ScsiPortReadPortBufferUlong
43 #undef ScsiPortReadPortBufferUshort
44 #undef ScsiPortReadPortUchar
45 #undef ScsiPortReadPortUlong
46 #undef ScsiPortReadPortUshort
47 #undef ScsiPortReadRegisterBufferUchar
48 #undef ScsiPortReadRegisterBufferUlong
49 #undef ScsiPortReadRegisterBufferUshort
50 #undef ScsiPortReadRegisterUchar
51 #undef ScsiPortReadRegisterUlong
52 #undef ScsiPortReadRegisterUshort
54 #define SCSI_PORT_NEXT_REQUEST_READY 0x0008
56 #define TAG_SCSI_DEVEXT 'DscS'
57 #define TAG_SCSI_ACCESS_RANGES 'AscS'
59 /* GLOBALS ********************************************************************/
62 VOID NTAPI
HalpInitializePciStubs(VOID
);
63 VOID NTAPI
HalpInitBusHandler(VOID
);
68 PVOID NonCachedExtension
;
75 /* SRB extension stuff */
76 ULONG SrbExtensionSize
;
77 PVOID SrbExtensionBuffer
;
79 IO_SCSI_CAPABILITIES PortCapabilities
;
81 PHW_INITIALIZE HwInitialize
;
82 PHW_STARTIO HwStartIo
;
83 PHW_INTERRUPT HwInterrupt
;
84 PHW_RESET_BUS HwResetBus
;
86 /* DMA related stuff */
87 PADAPTER_OBJECT AdapterObject
;
89 ULONG CommonBufferLength
;
91 PVOID MiniPortDeviceExtension
;
92 } SCSI_PORT_DEVICE_EXTENSION
, *PSCSI_PORT_DEVICE_EXTENSION
;
94 typedef struct tagDISKCONTEXT
97 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
102 /* Device characteristics */
104 ULONGLONG SectorOffset
;
105 ULONGLONG SectorCount
;
106 ULONGLONG SectorNumber
;
109 PSCSI_PORT_DEVICE_EXTENSION ScsiDeviceExtensions
[SCSI_MAXIMUM_BUSES
];
111 /* FUNCTIONS ******************************************************************/
118 PFOUR_BYTE Source
= (PFOUR_BYTE
)&Value
;
120 Dest
.Byte0
= Source
->Byte3
;
121 Dest
.Byte1
= Source
->Byte2
;
122 Dest
.Byte2
= Source
->Byte1
;
123 Dest
.Byte3
= Source
->Byte0
;
130 SpiSendSynchronousSrb(
131 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
132 IN PSCSI_REQUEST_BLOCK Srb
)
136 ASSERT(!(Srb
->SrbFlags
& SRB_FLAGS_IS_ACTIVE
));
138 /* HACK: handle lack of interrupts */
139 while (!(DeviceExtension
->InterruptFlags
& SCSI_PORT_NEXT_REQUEST_READY
))
141 KeStallExecutionProcessor(100 * 1000);
142 DeviceExtension
->HwInterrupt(DeviceExtension
->MiniPortDeviceExtension
);
145 DeviceExtension
->InterruptFlags
&= ~SCSI_PORT_NEXT_REQUEST_READY
;
146 Srb
->SrbFlags
|= SRB_FLAGS_IS_ACTIVE
;
148 if (!DeviceExtension
->HwStartIo(
149 DeviceExtension
->MiniPortDeviceExtension
,
156 /* HACK: handle lack of interrupts */
157 while (Srb
->SrbFlags
& SRB_FLAGS_IS_ACTIVE
)
159 KeStallExecutionProcessor(100 * 1000);
160 DeviceExtension
->HwInterrupt(DeviceExtension
->MiniPortDeviceExtension
);
163 ret
= SRB_STATUS(Srb
->SrbStatus
) == SRB_STATUS_SUCCESS
;
169 static ARC_STATUS
DiskClose(ULONG FileId
)
171 DISKCONTEXT
* Context
= FsGetDeviceSpecific(FileId
);
176 static ARC_STATUS
DiskGetFileInformation(ULONG FileId
, FILEINFORMATION
* Information
)
178 DISKCONTEXT
* Context
= FsGetDeviceSpecific(FileId
);
180 RtlZeroMemory(Information
, sizeof(*Information
));
183 * The ARC specification mentions that for partitions, StartingAddress and
184 * EndingAddress are the start and end positions of the partition in terms
185 * of byte offsets from the start of the disk.
186 * CurrentAddress is the current offset into (i.e. relative to) the partition.
188 Information
->StartingAddress
.QuadPart
= Context
->SectorOffset
* Context
->SectorSize
;
189 Information
->EndingAddress
.QuadPart
= (Context
->SectorOffset
+ Context
->SectorCount
) * Context
->SectorSize
;
190 Information
->CurrentAddress
.QuadPart
= Context
->SectorNumber
* Context
->SectorSize
;
195 static ARC_STATUS
DiskOpen(CHAR
* Path
, OPENMODE OpenMode
, ULONG
* FileId
)
197 PSCSI_REQUEST_BLOCK Srb
;
199 READ_CAPACITY_DATA ReadCapacityBuffer
;
201 DISKCONTEXT
* Context
;
202 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
203 ULONG ScsiBus
, PathId
, TargetId
, Lun
, Partition
, PathSyntax
;
205 ULONGLONG SectorOffset
= 0;
206 ULONGLONG SectorCount
;
209 if (!DissectArcPath2(Path
, &ScsiBus
, &TargetId
, &Lun
, &Partition
, &PathSyntax
))
211 if (PathSyntax
!= 0) /* scsi() format */
213 DeviceExtension
= ScsiDeviceExtensions
[ScsiBus
];
214 PathId
= ScsiBus
- DeviceExtension
->BusNum
;
216 /* Get disk capacity and sector size */
217 Srb
= ExAllocatePool(PagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
220 RtlZeroMemory(Srb
, sizeof(SCSI_REQUEST_BLOCK
));
221 Srb
->Length
= sizeof(SCSI_REQUEST_BLOCK
);
222 Srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
223 Srb
->PathId
= (UCHAR
)PathId
;
224 Srb
->TargetId
= (UCHAR
)TargetId
;
225 Srb
->Lun
= (UCHAR
)Lun
;
227 Srb
->SrbFlags
= SRB_FLAGS_DATA_IN
;
228 Srb
->DataTransferLength
= sizeof(READ_CAPACITY_DATA
);
229 Srb
->TimeOutValue
= 5; /* in seconds */
230 Srb
->DataBuffer
= &ReadCapacityBuffer
;
231 Cdb
= (PCDB
)Srb
->Cdb
;
232 Cdb
->CDB10
.OperationCode
= SCSIOP_READ_CAPACITY
;
233 if (!SpiSendSynchronousSrb(DeviceExtension
, Srb
))
238 /* Transform result to host endianness */
239 SectorCount
= ntohl(ReadCapacityBuffer
.LogicalBlockAddress
);
240 SectorSize
= ntohl(ReadCapacityBuffer
.BytesPerBlock
);
244 /* Need to offset start of disk and length */
249 Context
= ExAllocatePool(PagedPool
, sizeof(DISKCONTEXT
));
252 Context
->DeviceExtension
= DeviceExtension
;
253 Context
->PathId
= (UCHAR
)PathId
;
254 Context
->TargetId
= (UCHAR
)TargetId
;
255 Context
->Lun
= (UCHAR
)Lun
;
256 Context
->SectorSize
= SectorSize
;
257 Context
->SectorOffset
= SectorOffset
;
258 Context
->SectorCount
= SectorCount
;
259 Context
->SectorNumber
= 0;
260 FsSetDeviceSpecific(*FileId
, Context
);
265 static ARC_STATUS
DiskRead(ULONG FileId
, VOID
* Buffer
, ULONG N
, ULONG
* Count
)
267 DISKCONTEXT
* Context
= FsGetDeviceSpecific(FileId
);
268 PSCSI_REQUEST_BLOCK Srb
;
270 ULONG FullSectors
, NbSectors
;
278 FullSectors
= N
/ Context
->SectorSize
;
279 NbSectors
= (N
+ Context
->SectorSize
- 1) / Context
->SectorSize
;
280 if (Context
->SectorNumber
+ NbSectors
>= Context
->SectorCount
)
282 if (FullSectors
> 0xffff)
285 /* Read full sectors */
286 ASSERT(Context
->SectorNumber
< 0xFFFFFFFF);
287 Lba
= (ULONG
)(Context
->SectorOffset
+ Context
->SectorNumber
);
290 Srb
= ExAllocatePool(PagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
294 RtlZeroMemory(Srb
, sizeof(SCSI_REQUEST_BLOCK
));
295 Srb
->Length
= sizeof(SCSI_REQUEST_BLOCK
);
296 Srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
297 Srb
->PathId
= Context
->PathId
;
298 Srb
->TargetId
= Context
->TargetId
;
299 Srb
->Lun
= Context
->Lun
;
301 Srb
->SrbFlags
= SRB_FLAGS_DATA_IN
;
302 Srb
->DataTransferLength
= FullSectors
* Context
->SectorSize
;
303 Srb
->TimeOutValue
= 5; /* in seconds */
304 Srb
->DataBuffer
= Buffer
;
305 Cdb
= (PCDB
)Srb
->Cdb
;
306 Cdb
->CDB10
.OperationCode
= SCSIOP_READ
;
307 Cdb
->CDB10
.LogicalUnitNumber
= Srb
->Lun
;
308 Cdb
->CDB10
.LogicalBlockByte0
= (Lba
>> 24) & 0xff;
309 Cdb
->CDB10
.LogicalBlockByte1
= (Lba
>> 16) & 0xff;
310 Cdb
->CDB10
.LogicalBlockByte2
= (Lba
>> 8) & 0xff;
311 Cdb
->CDB10
.LogicalBlockByte3
= Lba
& 0xff;
312 Cdb
->CDB10
.TransferBlocksMsb
= (FullSectors
>> 8) & 0xff;
313 Cdb
->CDB10
.TransferBlocksLsb
= FullSectors
& 0xff;
314 if (!SpiSendSynchronousSrb(Context
->DeviceExtension
, Srb
))
318 Buffer
= (PUCHAR
)Buffer
+ FullSectors
* Context
->SectorSize
;
319 N
-= FullSectors
* Context
->SectorSize
;
320 *Count
+= FullSectors
* Context
->SectorSize
;
324 /* Read incomplete last sector */
329 Sector
= ExAllocatePool(PagedPool
, Context
->SectorSize
);
333 Srb
= ExAllocatePool(PagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
340 RtlZeroMemory(Srb
, sizeof(SCSI_REQUEST_BLOCK
));
341 Srb
->Length
= sizeof(SCSI_REQUEST_BLOCK
);
342 Srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
343 Srb
->PathId
= Context
->PathId
;
344 Srb
->TargetId
= Context
->TargetId
;
345 Srb
->Lun
= Context
->Lun
;
347 Srb
->SrbFlags
= SRB_FLAGS_DATA_IN
;
348 Srb
->DataTransferLength
= Context
->SectorSize
;
349 Srb
->TimeOutValue
= 5; /* in seconds */
350 Srb
->DataBuffer
= Sector
;
351 Cdb
= (PCDB
)Srb
->Cdb
;
352 Cdb
->CDB10
.OperationCode
= SCSIOP_READ
;
353 Cdb
->CDB10
.LogicalUnitNumber
= Srb
->Lun
;
354 Cdb
->CDB10
.LogicalBlockByte0
= (Lba
>> 24) & 0xff;
355 Cdb
->CDB10
.LogicalBlockByte1
= (Lba
>> 16) & 0xff;
356 Cdb
->CDB10
.LogicalBlockByte2
= (Lba
>> 8) & 0xff;
357 Cdb
->CDB10
.LogicalBlockByte3
= Lba
& 0xff;
358 Cdb
->CDB10
.TransferBlocksMsb
= 0;
359 Cdb
->CDB10
.TransferBlocksLsb
= 1;
360 if (!SpiSendSynchronousSrb(Context
->DeviceExtension
, Srb
))
365 RtlCopyMemory(Buffer
, Sector
, N
);
373 static ARC_STATUS
DiskSeek(ULONG FileId
, LARGE_INTEGER
* Position
, SEEKMODE SeekMode
)
375 DISKCONTEXT
* Context
= FsGetDeviceSpecific(FileId
);
376 LARGE_INTEGER NewPosition
= *Position
;
383 NewPosition
.QuadPart
+= (Context
->SectorNumber
* Context
->SectorSize
);
390 if (NewPosition
.QuadPart
& (Context
->SectorSize
- 1))
393 /* Convert in number of sectors */
394 NewPosition
.QuadPart
/= Context
->SectorSize
;
395 if (NewPosition
.QuadPart
>= Context
->SectorCount
)
398 Context
->SectorNumber
= NewPosition
.QuadPart
;
402 static const DEVVTBL DiskVtbl
= {
404 DiskGetFileInformation
,
413 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
414 IN PHW_INITIALIZATION_DATA HwInitData
,
415 OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo
,
416 IN BOOLEAN ZeroStruct
)
420 /* Zero out the struct if told so */
423 /* First zero the portconfig */
424 RtlZeroMemory(ConfigInfo
, sizeof(PORT_CONFIGURATION_INFORMATION
));
426 /* Initialize the struct */
427 ConfigInfo
->Length
= sizeof(PORT_CONFIGURATION_INFORMATION
);
428 ConfigInfo
->AdapterInterfaceType
= HwInitData
->AdapterInterfaceType
;
429 ConfigInfo
->InterruptMode
= Latched
;
430 ConfigInfo
->DmaChannel
= SP_UNINITIALIZED_VALUE
;
431 ConfigInfo
->DmaPort
= SP_UNINITIALIZED_VALUE
;
432 ConfigInfo
->MaximumTransferLength
= SP_UNINITIALIZED_VALUE
;
433 ConfigInfo
->MaximumNumberOfTargets
= SCSI_MAXIMUM_TARGETS_PER_BUS
;
435 /* Store parameters */
436 ConfigInfo
->NeedPhysicalAddresses
= HwInitData
->NeedPhysicalAddresses
;
437 ConfigInfo
->MapBuffers
= HwInitData
->MapBuffers
;
438 ConfigInfo
->AutoRequestSense
= HwInitData
->AutoRequestSense
;
439 ConfigInfo
->ReceiveEvent
= HwInitData
->ReceiveEvent
;
440 ConfigInfo
->TaggedQueuing
= HwInitData
->TaggedQueuing
;
441 ConfigInfo
->MultipleRequestPerLu
= HwInitData
->MultipleRequestPerLu
;
443 /* Get the disk usage */
444 ConfigInfo
->AtdiskPrimaryClaimed
= FALSE
; // FIXME
445 ConfigInfo
->AtdiskSecondaryClaimed
= FALSE
; // FIXME
447 /* Initiator bus id is not set */
448 for (Bus
= 0; Bus
< 8; Bus
++)
449 ConfigInfo
->InitiatorBusId
[Bus
] = (CCHAR
)SP_UNINITIALIZED_VALUE
;
452 ConfigInfo
->NumberOfPhysicalBreaks
= 17;
454 return STATUS_SUCCESS
;
460 IN ULONG DebugPrintLevel
,
461 IN PCCHAR DebugMessage
,
468 if (DebugPrintLevel
> 10)
471 va_start(ap
, DebugMessage
);
473 /* Construct a string */
474 Length
= _vsnprintf(Buffer
, 512, DebugMessage
, ap
);
476 /* Check if we went past the buffer */
477 if (Length
== MAXULONG
)
479 /* Terminate it if we went over-board */
480 Buffer
[sizeof(Buffer
) - 1] = '\0';
483 Length
= sizeof(Buffer
);
486 /* Print the message */
495 ScsiPortCompleteRequest(
496 IN PVOID HwDeviceExtension
,
506 #undef ScsiPortConvertPhysicalAddressToUlong
509 ScsiPortConvertPhysicalAddressToUlong(
510 IN SCSI_PHYSICAL_ADDRESS Address
)
512 return Address
.LowPart
;
515 SCSI_PHYSICAL_ADDRESS
517 ScsiPortConvertUlongToPhysicalAddress(
518 IN ULONG_PTR UlongAddress
)
520 SCSI_PHYSICAL_ADDRESS Address
;
522 Address
.QuadPart
= UlongAddress
;
529 IN PVOID DeviceExtension
)
537 ScsiPortFreeDeviceBase(
538 IN PVOID HwDeviceExtension
,
539 IN PVOID MappedAddress
)
547 IN PVOID DeviceExtension
,
548 IN ULONG BusDataType
,
549 IN ULONG SystemIoBusNumber
,
554 return HalGetBusDataByOffset(BusDataType
, SystemIoBusNumber
, SlotNumber
, Buffer
, 0, Length
);
559 ScsiPortGetDeviceBase(
560 IN PVOID HwDeviceExtension
,
561 IN INTERFACE_TYPE BusType
,
562 IN ULONG SystemIoBusNumber
,
563 IN SCSI_PHYSICAL_ADDRESS IoAddress
,
564 IN ULONG NumberOfBytes
,
565 IN BOOLEAN InIoSpace
)
567 PHYSICAL_ADDRESS TranslatedAddress
;
570 AddressSpace
= (ULONG
)InIoSpace
;
571 if (HalTranslateBusAddress(BusType
,
575 &TranslatedAddress
) == FALSE
)
581 if (AddressSpace
!= 0)
582 return (PVOID
)TranslatedAddress
.u
.LowPart
;
586 return (PVOID
)IoAddress
.LowPart
;
591 ScsiPortGetLogicalUnit(
592 IN PVOID HwDeviceExtension
,
602 SCSI_PHYSICAL_ADDRESS
604 ScsiPortGetPhysicalAddress(
605 IN PVOID HwDeviceExtension
,
606 IN PSCSI_REQUEST_BLOCK Srb OPTIONAL
,
607 IN PVOID VirtualAddress
,
610 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
611 SCSI_PHYSICAL_ADDRESS PhysicalAddress
;
612 ULONG BufferLength
= 0;
615 TRACE("ScsiPortGetPhysicalAddress(%p %p %p %p)\n",
616 HwDeviceExtension
, Srb
, VirtualAddress
, Length
);
618 DeviceExtension
= ((PSCSI_PORT_DEVICE_EXTENSION
)HwDeviceExtension
) - 1;
620 if (Srb
== NULL
|| Srb
->SenseInfoBuffer
== VirtualAddress
)
622 /* Simply look it up in the allocated common buffer */
623 Offset
= (PUCHAR
)VirtualAddress
- (PUCHAR
)DeviceExtension
->SrbExtensionBuffer
;
625 BufferLength
= DeviceExtension
->CommonBufferLength
- Offset
;
626 PhysicalAddress
.QuadPart
= Offset
;
631 PhysicalAddress
.QuadPart
= (LONGLONG
)(SP_UNINITIALIZED_VALUE
);
634 *Length
= BufferLength
;
635 return PhysicalAddress
;
641 IN PVOID DeviceExtension
,
654 SpiAllocateCommonBuffer(
655 IN OUT PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
656 IN ULONG NonCachedSize
)
659 ULONG CommonBufferLength
, BufSize
;
661 /* If size is 0, set it to 16 */
662 if (!DeviceExtension
->SrbExtensionSize
)
663 DeviceExtension
->SrbExtensionSize
= 16;
666 BufSize
= DeviceExtension
->SrbExtensionSize
;
669 BufSize
= (BufSize
+ sizeof(LONGLONG
) - 1) & ~(sizeof(LONGLONG
) - 1);
671 /* Sum up into the total common buffer length, and round it to page size */
673 ROUND_TO_PAGES(NonCachedSize
);
676 if (!DeviceExtension
->AdapterObject
)
678 /* From nonpaged pool if there is no DMA */
679 CommonBuffer
= ExAllocatePool(NonPagedPool
, CommonBufferLength
);
683 /* Perform a full request since we have a DMA adapter*/
688 /* Fail in case of error */
690 return STATUS_INSUFFICIENT_RESOURCES
;
693 RtlZeroMemory(CommonBuffer
, CommonBufferLength
);
695 /* Store its size in Device Extension */
696 DeviceExtension
->CommonBufferLength
= CommonBufferLength
;
698 /* SrbExtension buffer is located at the beginning of the buffer */
699 DeviceExtension
->SrbExtensionBuffer
= CommonBuffer
;
701 /* Non-cached extension buffer is located at the end of
705 CommonBufferLength
-= NonCachedSize
;
706 DeviceExtension
->NonCachedExtension
= (PUCHAR
)CommonBuffer
+ CommonBufferLength
;
710 DeviceExtension
->NonCachedExtension
= NULL
;
713 return STATUS_SUCCESS
;
718 ScsiPortGetUncachedExtension(
719 IN PVOID HwDeviceExtension
,
720 IN PPORT_CONFIGURATION_INFORMATION ConfigInfo
,
721 IN ULONG NumberOfBytes
)
723 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
724 DEVICE_DESCRIPTION DeviceDescription
;
725 ULONG MapRegistersCount
;
728 TRACE("ScsiPortGetUncachedExtension(%p %p %lu)\n",
729 HwDeviceExtension
, ConfigInfo
, NumberOfBytes
);
731 DeviceExtension
= ((PSCSI_PORT_DEVICE_EXTENSION
)HwDeviceExtension
) - 1;
733 /* Check for allocated common DMA buffer */
734 if (DeviceExtension
->SrbExtensionBuffer
!= NULL
)
739 /* Check for DMA adapter object */
740 if (DeviceExtension
->AdapterObject
== NULL
)
742 /* Initialize DMA adapter description */
743 RtlZeroMemory(&DeviceDescription
, sizeof(DEVICE_DESCRIPTION
));
745 DeviceDescription
.Version
= DEVICE_DESCRIPTION_VERSION
;
746 DeviceDescription
.Master
= ConfigInfo
->Master
;
747 DeviceDescription
.ScatterGather
= ConfigInfo
->ScatterGather
;
748 DeviceDescription
.DemandMode
= ConfigInfo
->DemandMode
;
749 DeviceDescription
.Dma32BitAddresses
= ConfigInfo
->Dma32BitAddresses
;
750 DeviceDescription
.BusNumber
= ConfigInfo
->SystemIoBusNumber
;
751 DeviceDescription
.DmaChannel
= ConfigInfo
->DmaChannel
;
752 DeviceDescription
.InterfaceType
= ConfigInfo
->AdapterInterfaceType
;
753 DeviceDescription
.DmaWidth
= ConfigInfo
->DmaWidth
;
754 DeviceDescription
.DmaSpeed
= ConfigInfo
->DmaSpeed
;
755 DeviceDescription
.MaximumLength
= ConfigInfo
->MaximumTransferLength
;
756 DeviceDescription
.DmaPort
= ConfigInfo
->DmaPort
;
758 /* Get a DMA adapter object */
760 DeviceExtension
->AdapterObject
=
761 HalGetAdapter(&DeviceDescription
, &MapRegistersCount
);
763 /* Fail in case of error */
764 if (DeviceExtension
->AdapterObject
== NULL
)
769 MapRegistersCount
= 0;
772 /* Set number of physical breaks */
773 if (ConfigInfo
->NumberOfPhysicalBreaks
!= 0 &&
774 MapRegistersCount
> ConfigInfo
->NumberOfPhysicalBreaks
)
776 DeviceExtension
->PortCapabilities
.MaximumPhysicalPages
=
777 ConfigInfo
->NumberOfPhysicalBreaks
;
781 DeviceExtension
->PortCapabilities
.MaximumPhysicalPages
= MapRegistersCount
;
785 /* Update Srb extension size */
786 if (DeviceExtension
->SrbExtensionSize
!= ConfigInfo
->SrbExtensionSize
)
787 DeviceExtension
->SrbExtensionSize
= ConfigInfo
->SrbExtensionSize
;
789 /* Allocate a common DMA buffer */
790 Status
= SpiAllocateCommonBuffer(DeviceExtension
, NumberOfBytes
);
792 if (!NT_SUCCESS(Status
))
794 TRACE("SpiAllocateCommonBuffer() failed with Status = 0x%08X!\n", Status
);
798 return DeviceExtension
->NonCachedExtension
;
803 ScsiPortGetVirtualAddress(
804 IN PVOID HwDeviceExtension
,
805 IN SCSI_PHYSICAL_ADDRESS PhysicalAddress
)
815 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
824 struct _DRIVE_LAYOUT_INFORMATION
*PartitionBuffer
;
825 CHAR PartitionName
[64];
827 /* Register device with partition(0) suffix */
828 RtlStringCbPrintfA(PartitionName
, sizeof(PartitionName
), "%spartition(0)", ArcName
);
829 FsRegisterDevice(PartitionName
, &DiskVtbl
);
831 /* Read device partition table */
832 Status
= ArcOpen(PartitionName
, OpenReadOnly
, &FileId
);
833 if (Status
== ESUCCESS
)
835 ret
= HALDISPATCH
->HalIoReadPartitionTable((PDEVICE_OBJECT
)FileId
, 512, FALSE
, &PartitionBuffer
);
838 for (i
= 0; i
< PartitionBuffer
->PartitionCount
; i
++)
840 if (PartitionBuffer
->PartitionEntry
[i
].PartitionType
!= PARTITION_ENTRY_UNUSED
)
842 RtlStringCbPrintfA(PartitionName
,
843 sizeof(PartitionName
),
846 PartitionBuffer
->PartitionEntry
[i
].PartitionNumber
);
847 FsRegisterDevice(PartitionName
, &DiskVtbl
);
850 ExFreePool(PartitionBuffer
);
859 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
864 PSCSI_REQUEST_BLOCK Srb
;
866 INQUIRYDATA InquiryBuffer
;
870 if (!DeviceExtension
->HwResetBus(DeviceExtension
->MiniPortDeviceExtension
, PathId
))
875 /* Remember the extension */
876 ScsiDeviceExtensions
[ScsiBus
] = DeviceExtension
;
878 for (TargetId
= 0; TargetId
< DeviceExtension
->MaxTargedIds
; TargetId
++)
883 TRACE("Scanning SCSI device %d.%d.%d\n",
884 ScsiBus
, TargetId
, Lun
);
886 Srb
= ExAllocatePool(PagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
889 RtlZeroMemory(Srb
, sizeof(SCSI_REQUEST_BLOCK
));
890 Srb
->Length
= sizeof(SCSI_REQUEST_BLOCK
);
891 Srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
892 Srb
->PathId
= PathId
;
893 Srb
->TargetId
= TargetId
;
896 Srb
->SrbFlags
= SRB_FLAGS_DATA_IN
;
897 Srb
->DataTransferLength
= INQUIRYDATABUFFERSIZE
;
898 Srb
->TimeOutValue
= 5; /* in seconds */
899 Srb
->DataBuffer
= &InquiryBuffer
;
900 Cdb
= (PCDB
)Srb
->Cdb
;
901 Cdb
->CDB6INQUIRY
.OperationCode
= SCSIOP_INQUIRY
;
902 Cdb
->CDB6INQUIRY
.LogicalUnitNumber
= Srb
->Lun
;
903 Cdb
->CDB6INQUIRY
.AllocationLength
= (UCHAR
)Srb
->DataTransferLength
;
904 if (!SpiSendSynchronousSrb(DeviceExtension
, Srb
))
906 /* Don't check next LUNs */
910 /* Device exists, create its ARC name */
911 if (InquiryBuffer
.RemovableMedia
)
913 sprintf(ArcName
, "scsi(%ld)cdrom(%d)fdisk(%d)",
914 ScsiBus
, TargetId
, Lun
);
915 FsRegisterDevice(ArcName
, &DiskVtbl
);
919 sprintf(ArcName
, "scsi(%ld)disk(%d)rdisk(%d)",
920 ScsiBus
, TargetId
, Lun
);
921 /* Now, check if it has partitions */
922 SpiScanDevice(DeviceExtension
, ArcName
, PathId
, TargetId
, Lun
);
927 } while (Lun
< SCSI_MAXIMUM_LOGICAL_UNITS
);
934 IN PHW_INITIALIZATION_DATA HwInitializationData
,
935 IN PCM_FULL_RESOURCE_DESCRIPTOR ResourceDescriptor
,
936 IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig
)
938 PACCESS_RANGE AccessRange
;
939 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialData
;
945 /* Loop through all entries */
946 for (Index
= 0; Index
< ResourceDescriptor
->PartialResourceList
.Count
; Index
++)
948 PartialData
= &ResourceDescriptor
->PartialResourceList
.PartialDescriptors
[Index
];
950 switch (PartialData
->Type
)
952 case CmResourceTypePort
:
953 /* Copy access ranges */
954 if (RangeNumber
< HwInitializationData
->NumberOfAccessRanges
)
956 TRACE("Got port at 0x%I64x, len 0x%x\n",
957 PartialData
->u
.Port
.Start
.QuadPart
, PartialData
->u
.Port
.Length
);
958 AccessRange
= &((*(PortConfig
->AccessRanges
))[RangeNumber
]);
960 AccessRange
->RangeStart
= PartialData
->u
.Port
.Start
;
961 AccessRange
->RangeLength
= PartialData
->u
.Port
.Length
;
963 AccessRange
->RangeInMemory
= FALSE
;
968 case CmResourceTypeMemory
:
969 /* Copy access ranges */
970 if (RangeNumber
< HwInitializationData
->NumberOfAccessRanges
)
972 TRACE("Got memory at 0x%I64x, len 0x%x\n",
973 PartialData
->u
.Memory
.Start
.QuadPart
, PartialData
->u
.Memory
.Length
);
974 AccessRange
= &((*(PortConfig
->AccessRanges
))[RangeNumber
]);
976 AccessRange
->RangeStart
= PartialData
->u
.Memory
.Start
;
977 AccessRange
->RangeLength
= PartialData
->u
.Memory
.Length
;
979 AccessRange
->RangeInMemory
= TRUE
;
984 case CmResourceTypeInterrupt
:
985 /* Copy interrupt data */
986 TRACE("Got interrupt level %d, vector %d\n",
987 PartialData
->u
.Interrupt
.Level
, PartialData
->u
.Interrupt
.Vector
);
988 PortConfig
->BusInterruptLevel
= PartialData
->u
.Interrupt
.Level
;
989 PortConfig
->BusInterruptVector
= PartialData
->u
.Interrupt
.Vector
;
991 /* Set interrupt mode accordingly to the resource */
992 if (PartialData
->Flags
== CM_RESOURCE_INTERRUPT_LATCHED
)
994 PortConfig
->InterruptMode
= Latched
;
996 else if (PartialData
->Flags
== CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
)
998 PortConfig
->InterruptMode
= LevelSensitive
;
1002 case CmResourceTypeDma
:
1003 TRACE("Got DMA channel %d, port %d\n",
1004 PartialData
->u
.Dma
.Channel
, PartialData
->u
.Dma
.Port
);
1005 PortConfig
->DmaChannel
= PartialData
->u
.Dma
.Channel
;
1006 PortConfig
->DmaPort
= PartialData
->u
.Dma
.Port
;
1014 SpiGetPciConfigData(
1015 IN PHW_INITIALIZATION_DATA HwInitializationData
,
1016 IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig
,
1018 IN OUT PPCI_SLOT_NUMBER NextSlotNumber
)
1020 PCI_COMMON_CONFIG PciConfig
;
1021 PCI_SLOT_NUMBER SlotNumber
;
1024 ULONG FunctionNumber
;
1025 CHAR VendorIdString
[8];
1026 CHAR DeviceIdString
[8];
1027 PCM_RESOURCE_LIST ResourceList
= NULL
;
1030 SlotNumber
.u
.AsULONG
= 0;
1032 /* Loop through all devices */
1033 for (DeviceNumber
= NextSlotNumber
->u
.bits
.DeviceNumber
; DeviceNumber
< PCI_MAX_DEVICES
; DeviceNumber
++)
1035 SlotNumber
.u
.bits
.DeviceNumber
= DeviceNumber
;
1037 /* Loop through all functions */
1038 for (FunctionNumber
= NextSlotNumber
->u
.bits
.FunctionNumber
; FunctionNumber
< PCI_MAX_FUNCTION
; FunctionNumber
++)
1040 SlotNumber
.u
.bits
.FunctionNumber
= FunctionNumber
;
1042 /* Get PCI config bytes */
1043 DataSize
= HalGetBusDataByOffset(
1046 SlotNumber
.u
.AsULONG
,
1051 /* If result of HalGetBusData is 0, then the bus is wrong */
1055 /* If result is PCI_INVALID_VENDORID, then this device has no more
1057 if (PciConfig
.VendorID
== PCI_INVALID_VENDORID
)
1060 sprintf(VendorIdString
, "%04hx", PciConfig
.VendorID
);
1061 sprintf(DeviceIdString
, "%04hx", PciConfig
.DeviceID
);
1063 if (_strnicmp(VendorIdString
, HwInitializationData
->VendorId
, HwInitializationData
->VendorIdLength
) ||
1064 _strnicmp(DeviceIdString
, HwInitializationData
->DeviceId
, HwInitializationData
->DeviceIdLength
))
1066 /* It is not our device */
1070 TRACE( "Found device 0x%04hx 0x%04hx at %1lu %2lu %1lu\n",
1071 PciConfig
.VendorID
, PciConfig
.DeviceID
,
1073 SlotNumber
.u
.bits
.DeviceNumber
, SlotNumber
.u
.bits
.FunctionNumber
);
1075 Status
= HalAssignSlotResources(NULL
,
1081 SlotNumber
.u
.AsULONG
,
1084 if (!NT_SUCCESS(Status
))
1087 /* Create configuration information */
1088 SpiResourceToConfig(HwInitializationData
,
1092 /* Free the resource list */
1093 ExFreePool(ResourceList
);
1095 /* Set dev & fn numbers */
1096 NextSlotNumber
->u
.bits
.DeviceNumber
= DeviceNumber
;
1097 NextSlotNumber
->u
.bits
.FunctionNumber
= FunctionNumber
+ 1;
1099 /* Save the slot number */
1100 PortConfig
->SlotNumber
= SlotNumber
.u
.AsULONG
;
1104 NextSlotNumber
->u
.bits
.FunctionNumber
= 0;
1107 NextSlotNumber
->u
.bits
.DeviceNumber
= 0;
1117 IN PHW_INITIALIZATION_DATA HwInitializationData
,
1118 IN PVOID HwContext OPTIONAL
)
1120 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
1121 ULONG DeviceExtensionSize
;
1122 PORT_CONFIGURATION_INFORMATION PortConfig
;
1124 BOOLEAN FirstConfigCall
= TRUE
;
1125 PCI_SLOT_NUMBER SlotNumber
;
1129 if (HwInitializationData
->HwInitializationDataSize
!= sizeof(HW_INITIALIZATION_DATA
))
1131 return STATUS_INVALID_PARAMETER
;
1134 /* Check params for validity */
1135 if ((HwInitializationData
->HwInitialize
== NULL
) ||
1136 (HwInitializationData
->HwStartIo
== NULL
) ||
1137 (HwInitializationData
->HwInterrupt
== NULL
) ||
1138 (HwInitializationData
->HwFindAdapter
== NULL
) ||
1139 (HwInitializationData
->HwResetBus
== NULL
))
1141 return STATUS_INVALID_PARAMETER
;
1144 /* Zero starting slot number */
1145 SlotNumber
.u
.AsULONG
= 0;
1151 DeviceExtensionSize
= sizeof(SCSI_PORT_DEVICE_EXTENSION
) + HwInitializationData
->DeviceExtensionSize
;
1152 DeviceExtension
= FrLdrTempAlloc(DeviceExtensionSize
, TAG_SCSI_DEVEXT
);
1153 if (!DeviceExtension
)
1155 return STATUS_NO_MEMORY
;
1157 RtlZeroMemory(DeviceExtension
, DeviceExtensionSize
);
1158 DeviceExtension
->InterruptFlags
= SCSI_PORT_NEXT_REQUEST_READY
;
1159 DeviceExtension
->HwInitialize
= HwInitializationData
->HwInitialize
;
1160 DeviceExtension
->HwStartIo
= HwInitializationData
->HwStartIo
;
1161 DeviceExtension
->HwInterrupt
= HwInitializationData
->HwInterrupt
;
1162 DeviceExtension
->HwResetBus
= HwInitializationData
->HwResetBus
;
1163 DeviceExtension
->MiniPortDeviceExtension
= (PVOID
)(DeviceExtension
+ 1);
1165 Status
= SpiCreatePortConfig(DeviceExtension
,
1166 HwInitializationData
,
1169 if (Status
!= STATUS_SUCCESS
)
1171 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1175 PortConfig
.NumberOfAccessRanges
= HwInitializationData
->NumberOfAccessRanges
;
1176 PortConfig
.AccessRanges
= FrLdrTempAlloc(sizeof(ACCESS_RANGE
) * HwInitializationData
->NumberOfAccessRanges
,
1177 TAG_SCSI_ACCESS_RANGES
);
1178 if (!PortConfig
.AccessRanges
)
1180 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1181 return STATUS_NO_MEMORY
;
1183 RtlZeroMemory(PortConfig
.AccessRanges
, sizeof(ACCESS_RANGE
) * HwInitializationData
->NumberOfAccessRanges
);
1185 /* Search for matching PCI device */
1186 if ((HwInitializationData
->AdapterInterfaceType
== PCIBus
) &&
1187 (HwInitializationData
->VendorIdLength
> 0) &&
1188 (HwInitializationData
->VendorId
!= NULL
) &&
1189 (HwInitializationData
->DeviceIdLength
> 0) &&
1190 (HwInitializationData
->DeviceId
!= NULL
))
1192 PortConfig
.BusInterruptLevel
= 0;
1194 /* Get PCI device data */
1195 TRACE("VendorId '%.*s' DeviceId '%.*s'\n",
1196 HwInitializationData
->VendorIdLength
,
1197 HwInitializationData
->VendorId
,
1198 HwInitializationData
->DeviceIdLength
,
1199 HwInitializationData
->DeviceId
);
1201 if (!SpiGetPciConfigData(HwInitializationData
,
1206 /* Continue to the next bus, nothing here */
1207 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1208 return STATUS_INTERNAL_ERROR
;
1211 if (!PortConfig
.BusInterruptLevel
)
1213 /* Bypass this slot, because no interrupt was assigned */
1214 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1215 return STATUS_INTERNAL_ERROR
;
1219 if (HwInitializationData
->HwFindAdapter(
1220 DeviceExtension
->MiniPortDeviceExtension
,
1225 &Again
) != SP_RETURN_FOUND
)
1227 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1228 return STATUS_INTERNAL_ERROR
;
1231 /* Copy all stuff which we ever need from PortConfig to the DeviceExtension */
1232 if (PortConfig
.MaximumNumberOfTargets
> SCSI_MAXIMUM_TARGETS_PER_BUS
)
1233 DeviceExtension
->MaxTargedIds
= SCSI_MAXIMUM_TARGETS_PER_BUS
;
1235 DeviceExtension
->MaxTargedIds
= PortConfig
.MaximumNumberOfTargets
;
1237 DeviceExtension
->BusNum
= PortConfig
.SystemIoBusNumber
;
1239 TRACE("Adapter found: buses = %d, targets = %d\n",
1240 PortConfig
.NumberOfBuses
, DeviceExtension
->MaxTargedIds
);
1242 /* Initialize adapter */
1243 if (!DeviceExtension
->HwInitialize(DeviceExtension
->MiniPortDeviceExtension
))
1245 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1246 return STATUS_INTERNAL_ERROR
;
1250 for (ScsiBus
= 0; ScsiBus
< PortConfig
.NumberOfBuses
; ScsiBus
++)
1252 SpiScanAdapter(DeviceExtension
, PortConfig
.SystemIoBusNumber
, ScsiBus
);
1253 PortConfig
.SystemIoBusNumber
++;
1256 FirstConfigCall
= FALSE
;
1263 return STATUS_SUCCESS
;
1268 ScsiPortIoMapTransfer(
1269 IN PVOID HwDeviceExtension
,
1270 IN PSCSI_REQUEST_BLOCK Srb
,
1271 IN PVOID LogicalAddress
,
1281 IN PVOID HwDeviceExtension
,
1282 IN PSCSI_REQUEST_BLOCK Srb OPTIONAL
,
1296 IN PVOID WriteBuffer
,
1297 IN PVOID ReadBuffer
,
1300 RtlMoveMemory(WriteBuffer
, ReadBuffer
, Length
);
1305 ScsiPortNotification(
1306 IN SCSI_NOTIFICATION_TYPE NotificationType
,
1307 IN PVOID HwDeviceExtension
,
1310 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
1311 PSCSI_REQUEST_BLOCK Srb
;
1314 DeviceExtension
= ((PSCSI_PORT_DEVICE_EXTENSION
)HwDeviceExtension
) - 1;
1316 va_start(ap
, HwDeviceExtension
);
1318 switch (NotificationType
)
1320 case RequestComplete
:
1321 /* Mask the SRB as completed */
1322 Srb
= va_arg(ap
, PSCSI_REQUEST_BLOCK
);
1323 Srb
->SrbFlags
&= ~SRB_FLAGS_IS_ACTIVE
;
1327 /* Say that device is ready */
1328 DeviceExtension
->InterruptFlags
|= SCSI_PORT_NEXT_REQUEST_READY
;
1341 ScsiPortReadPortBufferUchar(
1346 __inbytestring(H2I(Port
), Buffer
, Count
);
1351 ScsiPortReadPortBufferUlong(
1356 __indwordstring(H2I(Port
), Buffer
, Count
);
1361 ScsiPortReadPortBufferUshort(
1366 __inwordstring(H2I(Port
), Buffer
, Count
);
1371 ScsiPortReadPortUchar(
1374 TRACE("ScsiPortReadPortUchar(%p)\n", Port
);
1376 return READ_PORT_UCHAR(Port
);
1381 ScsiPortReadPortUlong(
1384 return READ_PORT_ULONG(Port
);
1389 ScsiPortReadPortUshort(
1392 return READ_PORT_USHORT(Port
);
1397 ScsiPortReadRegisterBufferUchar(
1408 ScsiPortReadRegisterBufferUlong(
1419 ScsiPortReadRegisterBufferUshort(
1420 IN PUSHORT Register
,
1430 ScsiPortReadRegisterUchar(
1433 return READ_REGISTER_UCHAR(Register
);
1438 ScsiPortReadRegisterUlong(
1441 return READ_REGISTER_ULONG(Register
);
1446 ScsiPortReadRegisterUshort(
1447 IN PUSHORT Register
)
1449 return READ_REGISTER_USHORT(Register
);
1454 ScsiPortSetBusDataByOffset(
1455 IN PVOID DeviceExtension
,
1456 IN ULONG BusDataType
,
1457 IN ULONG SystemIoBusNumber
,
1458 IN ULONG SlotNumber
,
1470 ScsiPortStallExecution(
1473 KeStallExecutionProcessor(Delay
);
1478 ScsiPortValidateRange(
1479 IN PVOID HwDeviceExtension
,
1480 IN INTERFACE_TYPE BusType
,
1481 IN ULONG SystemIoBusNumber
,
1482 IN SCSI_PHYSICAL_ADDRESS IoAddress
,
1483 IN ULONG NumberOfBytes
,
1484 IN BOOLEAN InIoSpace
)
1498 ScsiPortWritePortBufferUchar(
1503 __outbytestring(H2I(Port
), Buffer
, Count
);
1508 ScsiPortWritePortBufferUlong(
1513 __outdwordstring(H2I(Port
), Buffer
, Count
);
1518 ScsiPortWritePortBufferUshort(
1523 __outwordstring(H2I(Port
), Buffer
, Count
);
1528 ScsiPortWritePortUchar(
1532 WRITE_PORT_UCHAR(Port
, Value
);
1537 ScsiPortWritePortUlong(
1541 WRITE_PORT_ULONG(Port
, Value
);
1546 ScsiPortWritePortUshort(
1550 WRITE_PORT_USHORT(Port
, Value
);
1555 ScsiPortWriteRegisterBufferUchar(
1566 ScsiPortWriteRegisterBufferUlong(
1577 ScsiPortWriteRegisterBufferUshort(
1578 IN PUSHORT Register
,
1588 ScsiPortWriteRegisterUchar(
1592 WRITE_REGISTER_UCHAR(Register
, Value
);
1597 ScsiPortWriteRegisterUlong(
1601 WRITE_REGISTER_ULONG(Register
, Value
);
1606 ScsiPortWriteRegisterUshort(
1607 IN PUSHORT Register
,
1610 WRITE_REGISTER_USHORT(Register
, Value
);
1613 extern char __ImageBase
;
1616 LoadBootDeviceDriver(VOID
)
1618 PIMAGE_NT_HEADERS NtHeaders
;
1619 LIST_ENTRY ModuleListHead
;
1620 PIMAGE_IMPORT_DESCRIPTOR ImportTable
;
1621 ULONG ImportTableSize
;
1622 PLDR_DATA_TABLE_ENTRY BootDdDTE
, FreeldrDTE
;
1623 CHAR NtBootDdPath
[MAX_PATH
];
1624 PVOID ImageBase
= NULL
;
1625 ULONG (NTAPI
*EntryPoint
)(IN PVOID DriverObject
, IN PVOID RegistryPath
);
1628 // FIXME: Must be done *INSIDE* the HAL!
1630 HalpInitializePciStubs();
1631 HalpInitBusHandler();
1634 /* Initialize the loaded module list */
1635 InitializeListHead(&ModuleListHead
);
1637 /* Create full ntbootdd.sys path */
1638 strcpy(NtBootDdPath
, FrLdrBootPath
);
1639 strcat(NtBootDdPath
, "\\NTBOOTDD.SYS");
1642 Success
= WinLdrLoadImage(NtBootDdPath
, LoaderBootDriver
, &ImageBase
);
1645 /* That's OK. File simply doesn't exist */
1649 /* Allocate a DTE for ntbootdd */
1650 Success
= WinLdrAllocateDataTableEntry(&ModuleListHead
, "ntbootdd.sys",
1651 "NTBOOTDD.SYS", ImageBase
, &BootDdDTE
);
1655 /* Add the PE part of freeldr.sys to the list of loaded executables, it
1656 contains ScsiPort* exports, imported by ntbootdd.sys */
1657 Success
= WinLdrAllocateDataTableEntry(&ModuleListHead
, "scsiport.sys",
1658 "FREELDR.SYS", &__ImageBase
, &FreeldrDTE
);
1661 RemoveEntryList(&BootDdDTE
->InLoadOrderLinks
);
1666 Success
= WinLdrScanImportDescriptorTable(&ModuleListHead
, "", BootDdDTE
);
1668 /* Now unlinkt the DTEs, they won't be valid later */
1669 RemoveEntryList(&BootDdDTE
->InLoadOrderLinks
);
1670 RemoveEntryList(&FreeldrDTE
->InLoadOrderLinks
);
1675 /* Change imports to PA */
1676 ImportTable
= (PIMAGE_IMPORT_DESCRIPTOR
)RtlImageDirectoryEntryToData(VaToPa(BootDdDTE
->DllBase
),
1677 TRUE
, IMAGE_DIRECTORY_ENTRY_IMPORT
, &ImportTableSize
);
1678 for (;(ImportTable
->Name
!= 0) && (ImportTable
->FirstThunk
!= 0);ImportTable
++)
1680 PIMAGE_THUNK_DATA ThunkData
= (PIMAGE_THUNK_DATA
)VaToPa(RVA(BootDdDTE
->DllBase
, ImportTable
->FirstThunk
));
1682 while (((PIMAGE_THUNK_DATA
)ThunkData
)->u1
.AddressOfData
!= 0)
1684 ThunkData
->u1
.Function
= (ULONG
)VaToPa((PVOID
)ThunkData
->u1
.Function
);
1689 /* Relocate image to PA */
1690 NtHeaders
= RtlImageNtHeader(VaToPa(BootDdDTE
->DllBase
));
1693 Success
= (BOOLEAN
)LdrRelocateImageWithBias(VaToPa(BootDdDTE
->DllBase
),
1694 NtHeaders
->OptionalHeader
.ImageBase
- (ULONG_PTR
)BootDdDTE
->DllBase
,
1697 TRUE
, /* in case of conflict still return success */
1702 /* Call the entrypoint */
1703 EntryPoint
= VaToPa(BootDdDTE
->EntryPoint
);
1704 (*EntryPoint
)(NULL
, NULL
);