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
));
181 Information
->EndingAddress
.QuadPart
= Context
->SectorCount
* Context
->SectorSize
;
182 Information
->CurrentAddress
.QuadPart
= Context
->SectorNumber
* Context
->SectorSize
;
187 static ARC_STATUS
DiskOpen(CHAR
* Path
, OPENMODE OpenMode
, ULONG
* FileId
)
189 PSCSI_REQUEST_BLOCK Srb
;
191 READ_CAPACITY_DATA ReadCapacityBuffer
;
193 DISKCONTEXT
* Context
;
194 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
195 ULONG ScsiBus
, PathId
, TargetId
, Lun
, Partition
, PathSyntax
;
197 ULONGLONG SectorOffset
= 0;
198 ULONGLONG SectorCount
;
201 if (!DissectArcPath2(Path
, &ScsiBus
, &TargetId
, &Lun
, &Partition
, &PathSyntax
))
203 if (PathSyntax
!= 0) /* scsi() format */
205 DeviceExtension
= ScsiDeviceExtensions
[ScsiBus
];
206 PathId
= ScsiBus
- DeviceExtension
->BusNum
;
208 /* Get disk capacity and sector size */
209 Srb
= ExAllocatePool(PagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
212 RtlZeroMemory(Srb
, sizeof(SCSI_REQUEST_BLOCK
));
213 Srb
->Length
= sizeof(SCSI_REQUEST_BLOCK
);
214 Srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
215 Srb
->PathId
= (UCHAR
)PathId
;
216 Srb
->TargetId
= (UCHAR
)TargetId
;
217 Srb
->Lun
= (UCHAR
)Lun
;
219 Srb
->SrbFlags
= SRB_FLAGS_DATA_IN
;
220 Srb
->DataTransferLength
= sizeof(READ_CAPACITY_DATA
);
221 Srb
->TimeOutValue
= 5; /* in seconds */
222 Srb
->DataBuffer
= &ReadCapacityBuffer
;
223 Cdb
= (PCDB
)Srb
->Cdb
;
224 Cdb
->CDB10
.OperationCode
= SCSIOP_READ_CAPACITY
;
225 if (!SpiSendSynchronousSrb(DeviceExtension
, Srb
))
230 /* Transform result to host endianness */
231 SectorCount
= ntohl(ReadCapacityBuffer
.LogicalBlockAddress
);
232 SectorSize
= ntohl(ReadCapacityBuffer
.BytesPerBlock
);
236 /* Need to offset start of disk and length */
241 Context
= ExAllocatePool(PagedPool
, sizeof(DISKCONTEXT
));
244 Context
->DeviceExtension
= DeviceExtension
;
245 Context
->PathId
= (UCHAR
)PathId
;
246 Context
->TargetId
= (UCHAR
)TargetId
;
247 Context
->Lun
= (UCHAR
)Lun
;
248 Context
->SectorSize
= SectorSize
;
249 Context
->SectorOffset
= SectorOffset
;
250 Context
->SectorCount
= SectorCount
;
251 Context
->SectorNumber
= 0;
252 FsSetDeviceSpecific(*FileId
, Context
);
257 static ARC_STATUS
DiskRead(ULONG FileId
, VOID
* Buffer
, ULONG N
, ULONG
* Count
)
259 DISKCONTEXT
* Context
= FsGetDeviceSpecific(FileId
);
260 PSCSI_REQUEST_BLOCK Srb
;
262 ULONG FullSectors
, NbSectors
;
270 FullSectors
= N
/ Context
->SectorSize
;
271 NbSectors
= (N
+ Context
->SectorSize
- 1) / Context
->SectorSize
;
272 if (Context
->SectorNumber
+ NbSectors
>= Context
->SectorCount
)
274 if (FullSectors
> 0xffff)
277 /* Read full sectors */
278 ASSERT(Context
->SectorNumber
< 0xFFFFFFFF);
279 Lba
= (ULONG
)Context
->SectorNumber
;
282 Srb
= ExAllocatePool(PagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
286 RtlZeroMemory(Srb
, sizeof(SCSI_REQUEST_BLOCK
));
287 Srb
->Length
= sizeof(SCSI_REQUEST_BLOCK
);
288 Srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
289 Srb
->PathId
= Context
->PathId
;
290 Srb
->TargetId
= Context
->TargetId
;
291 Srb
->Lun
= Context
->Lun
;
293 Srb
->SrbFlags
= SRB_FLAGS_DATA_IN
;
294 Srb
->DataTransferLength
= FullSectors
* Context
->SectorSize
;
295 Srb
->TimeOutValue
= 5; /* in seconds */
296 Srb
->DataBuffer
= Buffer
;
297 Cdb
= (PCDB
)Srb
->Cdb
;
298 Cdb
->CDB10
.OperationCode
= SCSIOP_READ
;
299 Cdb
->CDB10
.LogicalUnitNumber
= Srb
->Lun
;
300 Cdb
->CDB10
.LogicalBlockByte0
= (Lba
>> 24) & 0xff;
301 Cdb
->CDB10
.LogicalBlockByte1
= (Lba
>> 16) & 0xff;
302 Cdb
->CDB10
.LogicalBlockByte2
= (Lba
>> 8) & 0xff;
303 Cdb
->CDB10
.LogicalBlockByte3
= Lba
& 0xff;
304 Cdb
->CDB10
.TransferBlocksMsb
= (FullSectors
>> 8) & 0xff;
305 Cdb
->CDB10
.TransferBlocksLsb
= FullSectors
& 0xff;
306 if (!SpiSendSynchronousSrb(Context
->DeviceExtension
, Srb
))
310 Buffer
= (PUCHAR
)Buffer
+ FullSectors
* Context
->SectorSize
;
311 N
-= FullSectors
* Context
->SectorSize
;
312 *Count
+= FullSectors
* Context
->SectorSize
;
316 /* Read incomplete last sector */
321 Sector
= ExAllocatePool(PagedPool
, Context
->SectorSize
);
325 Srb
= ExAllocatePool(PagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
332 RtlZeroMemory(Srb
, sizeof(SCSI_REQUEST_BLOCK
));
333 Srb
->Length
= sizeof(SCSI_REQUEST_BLOCK
);
334 Srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
335 Srb
->PathId
= Context
->PathId
;
336 Srb
->TargetId
= Context
->TargetId
;
337 Srb
->Lun
= Context
->Lun
;
339 Srb
->SrbFlags
= SRB_FLAGS_DATA_IN
;
340 Srb
->DataTransferLength
= Context
->SectorSize
;
341 Srb
->TimeOutValue
= 5; /* in seconds */
342 Srb
->DataBuffer
= Sector
;
343 Cdb
= (PCDB
)Srb
->Cdb
;
344 Cdb
->CDB10
.OperationCode
= SCSIOP_READ
;
345 Cdb
->CDB10
.LogicalUnitNumber
= Srb
->Lun
;
346 Cdb
->CDB10
.LogicalBlockByte0
= (Lba
>> 24) & 0xff;
347 Cdb
->CDB10
.LogicalBlockByte1
= (Lba
>> 16) & 0xff;
348 Cdb
->CDB10
.LogicalBlockByte2
= (Lba
>> 8) & 0xff;
349 Cdb
->CDB10
.LogicalBlockByte3
= Lba
& 0xff;
350 Cdb
->CDB10
.TransferBlocksMsb
= 0;
351 Cdb
->CDB10
.TransferBlocksLsb
= 1;
352 if (!SpiSendSynchronousSrb(Context
->DeviceExtension
, Srb
))
357 RtlCopyMemory(Buffer
, Sector
, N
);
365 static ARC_STATUS
DiskSeek(ULONG FileId
, LARGE_INTEGER
* Position
, SEEKMODE SeekMode
)
367 DISKCONTEXT
* Context
= FsGetDeviceSpecific(FileId
);
369 if (SeekMode
!= SeekAbsolute
)
371 if (Position
->QuadPart
& (Context
->SectorSize
- 1))
374 Context
->SectorNumber
= Position
->QuadPart
/ Context
->SectorSize
;
378 static const DEVVTBL DiskVtbl
= {
380 DiskGetFileInformation
,
389 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
390 IN PHW_INITIALIZATION_DATA HwInitData
,
391 OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo
,
392 IN BOOLEAN ZeroStruct
)
396 /* Zero out the struct if told so */
399 /* First zero the portconfig */
400 RtlZeroMemory(ConfigInfo
, sizeof(PORT_CONFIGURATION_INFORMATION
));
402 /* Initialize the struct */
403 ConfigInfo
->Length
= sizeof(PORT_CONFIGURATION_INFORMATION
);
404 ConfigInfo
->AdapterInterfaceType
= HwInitData
->AdapterInterfaceType
;
405 ConfigInfo
->InterruptMode
= Latched
;
406 ConfigInfo
->DmaChannel
= SP_UNINITIALIZED_VALUE
;
407 ConfigInfo
->DmaPort
= SP_UNINITIALIZED_VALUE
;
408 ConfigInfo
->MaximumTransferLength
= SP_UNINITIALIZED_VALUE
;
409 ConfigInfo
->MaximumNumberOfTargets
= SCSI_MAXIMUM_TARGETS_PER_BUS
;
411 /* Store parameters */
412 ConfigInfo
->NeedPhysicalAddresses
= HwInitData
->NeedPhysicalAddresses
;
413 ConfigInfo
->MapBuffers
= HwInitData
->MapBuffers
;
414 ConfigInfo
->AutoRequestSense
= HwInitData
->AutoRequestSense
;
415 ConfigInfo
->ReceiveEvent
= HwInitData
->ReceiveEvent
;
416 ConfigInfo
->TaggedQueuing
= HwInitData
->TaggedQueuing
;
417 ConfigInfo
->MultipleRequestPerLu
= HwInitData
->MultipleRequestPerLu
;
419 /* Get the disk usage */
420 ConfigInfo
->AtdiskPrimaryClaimed
= FALSE
; // FIXME
421 ConfigInfo
->AtdiskSecondaryClaimed
= FALSE
; // FIXME
423 /* Initiator bus id is not set */
424 for (Bus
= 0; Bus
< 8; Bus
++)
425 ConfigInfo
->InitiatorBusId
[Bus
] = (CCHAR
)SP_UNINITIALIZED_VALUE
;
428 ConfigInfo
->NumberOfPhysicalBreaks
= 17;
430 return STATUS_SUCCESS
;
436 IN ULONG DebugPrintLevel
,
437 IN PCCHAR DebugMessage
,
444 if (DebugPrintLevel
> 10)
447 va_start(ap
, DebugMessage
);
449 /* Construct a string */
450 Length
= _vsnprintf(Buffer
, 512, DebugMessage
, ap
);
452 /* Check if we went past the buffer */
453 if (Length
== MAXULONG
)
455 /* Terminate it if we went over-board */
456 Buffer
[sizeof(Buffer
) - 1] = '\0';
459 Length
= sizeof(Buffer
);
462 /* Print the message */
471 ScsiPortCompleteRequest(
472 IN PVOID HwDeviceExtension
,
482 #undef ScsiPortConvertPhysicalAddressToUlong
485 ScsiPortConvertPhysicalAddressToUlong(
486 IN SCSI_PHYSICAL_ADDRESS Address
)
488 return Address
.LowPart
;
491 SCSI_PHYSICAL_ADDRESS
493 ScsiPortConvertUlongToPhysicalAddress(
494 IN ULONG_PTR UlongAddress
)
496 SCSI_PHYSICAL_ADDRESS Address
;
498 Address
.QuadPart
= UlongAddress
;
505 IN PVOID DeviceExtension
)
513 ScsiPortFreeDeviceBase(
514 IN PVOID HwDeviceExtension
,
515 IN PVOID MappedAddress
)
523 IN PVOID DeviceExtension
,
524 IN ULONG BusDataType
,
525 IN ULONG SystemIoBusNumber
,
530 return HalGetBusDataByOffset(BusDataType
, SystemIoBusNumber
, SlotNumber
, Buffer
, 0, Length
);
535 ScsiPortGetDeviceBase(
536 IN PVOID HwDeviceExtension
,
537 IN INTERFACE_TYPE BusType
,
538 IN ULONG SystemIoBusNumber
,
539 IN SCSI_PHYSICAL_ADDRESS IoAddress
,
540 IN ULONG NumberOfBytes
,
541 IN BOOLEAN InIoSpace
)
543 PHYSICAL_ADDRESS TranslatedAddress
;
546 AddressSpace
= (ULONG
)InIoSpace
;
547 if (HalTranslateBusAddress(BusType
,
551 &TranslatedAddress
) == FALSE
)
557 if (AddressSpace
!= 0)
558 return (PVOID
)TranslatedAddress
.u
.LowPart
;
562 return (PVOID
)IoAddress
.LowPart
;
567 ScsiPortGetLogicalUnit(
568 IN PVOID HwDeviceExtension
,
578 SCSI_PHYSICAL_ADDRESS
580 ScsiPortGetPhysicalAddress(
581 IN PVOID HwDeviceExtension
,
582 IN PSCSI_REQUEST_BLOCK Srb OPTIONAL
,
583 IN PVOID VirtualAddress
,
586 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
587 SCSI_PHYSICAL_ADDRESS PhysicalAddress
;
588 ULONG BufferLength
= 0;
591 TRACE("ScsiPortGetPhysicalAddress(%p %p %p %p)\n",
592 HwDeviceExtension
, Srb
, VirtualAddress
, Length
);
594 DeviceExtension
= ((PSCSI_PORT_DEVICE_EXTENSION
)HwDeviceExtension
) - 1;
596 if (Srb
== NULL
|| Srb
->SenseInfoBuffer
== VirtualAddress
)
598 /* Simply look it up in the allocated common buffer */
599 Offset
= (PUCHAR
)VirtualAddress
- (PUCHAR
)DeviceExtension
->SrbExtensionBuffer
;
601 BufferLength
= DeviceExtension
->CommonBufferLength
- Offset
;
602 PhysicalAddress
.QuadPart
= Offset
;
607 PhysicalAddress
.QuadPart
= (LONGLONG
)(SP_UNINITIALIZED_VALUE
);
610 *Length
= BufferLength
;
611 return PhysicalAddress
;
617 IN PVOID DeviceExtension
,
630 SpiAllocateCommonBuffer(
631 IN OUT PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
632 IN ULONG NonCachedSize
)
635 ULONG CommonBufferLength
, BufSize
;
637 /* If size is 0, set it to 16 */
638 if (!DeviceExtension
->SrbExtensionSize
)
639 DeviceExtension
->SrbExtensionSize
= 16;
642 BufSize
= DeviceExtension
->SrbExtensionSize
;
645 BufSize
= (BufSize
+ sizeof(LONGLONG
) - 1) & ~(sizeof(LONGLONG
) - 1);
647 /* Sum up into the total common buffer length, and round it to page size */
649 ROUND_TO_PAGES(NonCachedSize
);
652 if (!DeviceExtension
->AdapterObject
)
654 /* From nonpaged pool if there is no DMA */
655 CommonBuffer
= ExAllocatePool(NonPagedPool
, CommonBufferLength
);
659 /* Perform a full request since we have a DMA adapter*/
664 /* Fail in case of error */
666 return STATUS_INSUFFICIENT_RESOURCES
;
669 RtlZeroMemory(CommonBuffer
, CommonBufferLength
);
671 /* Store its size in Device Extension */
672 DeviceExtension
->CommonBufferLength
= CommonBufferLength
;
674 /* SrbExtension buffer is located at the beginning of the buffer */
675 DeviceExtension
->SrbExtensionBuffer
= CommonBuffer
;
677 /* Non-cached extension buffer is located at the end of
681 CommonBufferLength
-= NonCachedSize
;
682 DeviceExtension
->NonCachedExtension
= (PUCHAR
)CommonBuffer
+ CommonBufferLength
;
686 DeviceExtension
->NonCachedExtension
= NULL
;
689 return STATUS_SUCCESS
;
694 ScsiPortGetUncachedExtension(
695 IN PVOID HwDeviceExtension
,
696 IN PPORT_CONFIGURATION_INFORMATION ConfigInfo
,
697 IN ULONG NumberOfBytes
)
699 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
700 DEVICE_DESCRIPTION DeviceDescription
;
701 ULONG MapRegistersCount
;
704 TRACE("ScsiPortGetUncachedExtension(%p %p %lu)\n",
705 HwDeviceExtension
, ConfigInfo
, NumberOfBytes
);
707 DeviceExtension
= ((PSCSI_PORT_DEVICE_EXTENSION
)HwDeviceExtension
) - 1;
709 /* Check for allocated common DMA buffer */
710 if (DeviceExtension
->SrbExtensionBuffer
!= NULL
)
715 /* Check for DMA adapter object */
716 if (DeviceExtension
->AdapterObject
== NULL
)
718 /* Initialize DMA adapter description */
719 RtlZeroMemory(&DeviceDescription
, sizeof(DEVICE_DESCRIPTION
));
721 DeviceDescription
.Version
= DEVICE_DESCRIPTION_VERSION
;
722 DeviceDescription
.Master
= ConfigInfo
->Master
;
723 DeviceDescription
.ScatterGather
= ConfigInfo
->ScatterGather
;
724 DeviceDescription
.DemandMode
= ConfigInfo
->DemandMode
;
725 DeviceDescription
.Dma32BitAddresses
= ConfigInfo
->Dma32BitAddresses
;
726 DeviceDescription
.BusNumber
= ConfigInfo
->SystemIoBusNumber
;
727 DeviceDescription
.DmaChannel
= ConfigInfo
->DmaChannel
;
728 DeviceDescription
.InterfaceType
= ConfigInfo
->AdapterInterfaceType
;
729 DeviceDescription
.DmaWidth
= ConfigInfo
->DmaWidth
;
730 DeviceDescription
.DmaSpeed
= ConfigInfo
->DmaSpeed
;
731 DeviceDescription
.MaximumLength
= ConfigInfo
->MaximumTransferLength
;
732 DeviceDescription
.DmaPort
= ConfigInfo
->DmaPort
;
734 /* Get a DMA adapter object */
736 DeviceExtension
->AdapterObject
=
737 HalGetAdapter(&DeviceDescription
, &MapRegistersCount
);
739 /* Fail in case of error */
740 if (DeviceExtension
->AdapterObject
== NULL
)
745 MapRegistersCount
= 0;
748 /* Set number of physical breaks */
749 if (ConfigInfo
->NumberOfPhysicalBreaks
!= 0 &&
750 MapRegistersCount
> ConfigInfo
->NumberOfPhysicalBreaks
)
752 DeviceExtension
->PortCapabilities
.MaximumPhysicalPages
=
753 ConfigInfo
->NumberOfPhysicalBreaks
;
757 DeviceExtension
->PortCapabilities
.MaximumPhysicalPages
= MapRegistersCount
;
761 /* Update Srb extension size */
762 if (DeviceExtension
->SrbExtensionSize
!= ConfigInfo
->SrbExtensionSize
)
763 DeviceExtension
->SrbExtensionSize
= ConfigInfo
->SrbExtensionSize
;
765 /* Allocate a common DMA buffer */
766 Status
= SpiAllocateCommonBuffer(DeviceExtension
, NumberOfBytes
);
768 if (!NT_SUCCESS(Status
))
770 TRACE("SpiAllocateCommonBuffer() failed with Status = 0x%08X!\n", Status
);
774 return DeviceExtension
->NonCachedExtension
;
779 ScsiPortGetVirtualAddress(
780 IN PVOID HwDeviceExtension
,
781 IN SCSI_PHYSICAL_ADDRESS PhysicalAddress
)
791 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
800 struct _DRIVE_LAYOUT_INFORMATION
*PartitionBuffer
;
801 CHAR PartitionName
[64];
803 /* Register device with partition(0) suffix */
804 RtlStringCbPrintfA(PartitionName
, sizeof(PartitionName
), "%spartition(0)", ArcName
);
805 FsRegisterDevice(PartitionName
, &DiskVtbl
);
807 /* Read device partition table */
808 Status
= ArcOpen(PartitionName
, OpenReadOnly
, &FileId
);
809 if (Status
== ESUCCESS
)
811 ret
= HALDISPATCH
->HalIoReadPartitionTable((PDEVICE_OBJECT
)FileId
, 512, FALSE
, &PartitionBuffer
);
814 for (i
= 0; i
< PartitionBuffer
->PartitionCount
; i
++)
816 if (PartitionBuffer
->PartitionEntry
[i
].PartitionType
!= PARTITION_ENTRY_UNUSED
)
818 RtlStringCbPrintfA(PartitionName
,
819 sizeof(PartitionName
),
822 PartitionBuffer
->PartitionEntry
[i
].PartitionNumber
);
823 FsRegisterDevice(PartitionName
, &DiskVtbl
);
826 ExFreePool(PartitionBuffer
);
835 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
840 PSCSI_REQUEST_BLOCK Srb
;
842 INQUIRYDATA InquiryBuffer
;
846 if (!DeviceExtension
->HwResetBus(DeviceExtension
->MiniPortDeviceExtension
, PathId
))
851 /* Remember the extension */
852 ScsiDeviceExtensions
[ScsiBus
] = DeviceExtension
;
854 for (TargetId
= 0; TargetId
< DeviceExtension
->MaxTargedIds
; TargetId
++)
859 TRACE("Scanning SCSI device %d.%d.%d\n",
860 ScsiBus
, TargetId
, Lun
);
862 Srb
= ExAllocatePool(PagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
865 RtlZeroMemory(Srb
, sizeof(SCSI_REQUEST_BLOCK
));
866 Srb
->Length
= sizeof(SCSI_REQUEST_BLOCK
);
867 Srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
868 Srb
->PathId
= PathId
;
869 Srb
->TargetId
= TargetId
;
872 Srb
->SrbFlags
= SRB_FLAGS_DATA_IN
;
873 Srb
->DataTransferLength
= INQUIRYDATABUFFERSIZE
;
874 Srb
->TimeOutValue
= 5; /* in seconds */
875 Srb
->DataBuffer
= &InquiryBuffer
;
876 Cdb
= (PCDB
)Srb
->Cdb
;
877 Cdb
->CDB6INQUIRY
.OperationCode
= SCSIOP_INQUIRY
;
878 Cdb
->CDB6INQUIRY
.LogicalUnitNumber
= Srb
->Lun
;
879 Cdb
->CDB6INQUIRY
.AllocationLength
= (UCHAR
)Srb
->DataTransferLength
;
880 if (!SpiSendSynchronousSrb(DeviceExtension
, Srb
))
882 /* Don't check next LUNs */
886 /* Device exists, create its ARC name */
887 if (InquiryBuffer
.RemovableMedia
)
889 sprintf(ArcName
, "scsi(%ld)cdrom(%d)fdisk(%d)",
890 ScsiBus
, TargetId
, Lun
);
891 FsRegisterDevice(ArcName
, &DiskVtbl
);
895 sprintf(ArcName
, "scsi(%ld)disk(%d)rdisk(%d)",
896 ScsiBus
, TargetId
, Lun
);
897 /* Now, check if it has partitions */
898 SpiScanDevice(DeviceExtension
, ArcName
, PathId
, TargetId
, Lun
);
903 } while (Lun
< SCSI_MAXIMUM_LOGICAL_UNITS
);
910 IN PHW_INITIALIZATION_DATA HwInitializationData
,
911 IN PCM_FULL_RESOURCE_DESCRIPTOR ResourceDescriptor
,
912 IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig
)
914 PACCESS_RANGE AccessRange
;
915 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialData
;
921 /* Loop through all entries */
922 for (Index
= 0; Index
< ResourceDescriptor
->PartialResourceList
.Count
; Index
++)
924 PartialData
= &ResourceDescriptor
->PartialResourceList
.PartialDescriptors
[Index
];
926 switch (PartialData
->Type
)
928 case CmResourceTypePort
:
929 /* Copy access ranges */
930 if (RangeNumber
< HwInitializationData
->NumberOfAccessRanges
)
932 TRACE("Got port at 0x%I64x, len 0x%x\n",
933 PartialData
->u
.Port
.Start
.QuadPart
, PartialData
->u
.Port
.Length
);
934 AccessRange
= &((*(PortConfig
->AccessRanges
))[RangeNumber
]);
936 AccessRange
->RangeStart
= PartialData
->u
.Port
.Start
;
937 AccessRange
->RangeLength
= PartialData
->u
.Port
.Length
;
939 AccessRange
->RangeInMemory
= FALSE
;
944 case CmResourceTypeMemory
:
945 /* Copy access ranges */
946 if (RangeNumber
< HwInitializationData
->NumberOfAccessRanges
)
948 TRACE("Got memory at 0x%I64x, len 0x%x\n",
949 PartialData
->u
.Memory
.Start
.QuadPart
, PartialData
->u
.Memory
.Length
);
950 AccessRange
= &((*(PortConfig
->AccessRanges
))[RangeNumber
]);
952 AccessRange
->RangeStart
= PartialData
->u
.Memory
.Start
;
953 AccessRange
->RangeLength
= PartialData
->u
.Memory
.Length
;
955 AccessRange
->RangeInMemory
= TRUE
;
960 case CmResourceTypeInterrupt
:
961 /* Copy interrupt data */
962 TRACE("Got interrupt level %d, vector %d\n",
963 PartialData
->u
.Interrupt
.Level
, PartialData
->u
.Interrupt
.Vector
);
964 PortConfig
->BusInterruptLevel
= PartialData
->u
.Interrupt
.Level
;
965 PortConfig
->BusInterruptVector
= PartialData
->u
.Interrupt
.Vector
;
967 /* Set interrupt mode accordingly to the resource */
968 if (PartialData
->Flags
== CM_RESOURCE_INTERRUPT_LATCHED
)
970 PortConfig
->InterruptMode
= Latched
;
972 else if (PartialData
->Flags
== CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
)
974 PortConfig
->InterruptMode
= LevelSensitive
;
978 case CmResourceTypeDma
:
979 TRACE("Got DMA channel %d, port %d\n",
980 PartialData
->u
.Dma
.Channel
, PartialData
->u
.Dma
.Port
);
981 PortConfig
->DmaChannel
= PartialData
->u
.Dma
.Channel
;
982 PortConfig
->DmaPort
= PartialData
->u
.Dma
.Port
;
991 IN PHW_INITIALIZATION_DATA HwInitializationData
,
992 IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig
,
994 IN OUT PPCI_SLOT_NUMBER NextSlotNumber
)
996 PCI_COMMON_CONFIG PciConfig
;
997 PCI_SLOT_NUMBER SlotNumber
;
1000 ULONG FunctionNumber
;
1001 CHAR VendorIdString
[8];
1002 CHAR DeviceIdString
[8];
1003 PCM_RESOURCE_LIST ResourceList
= NULL
;
1006 SlotNumber
.u
.AsULONG
= 0;
1008 /* Loop through all devices */
1009 for (DeviceNumber
= NextSlotNumber
->u
.bits
.DeviceNumber
; DeviceNumber
< PCI_MAX_DEVICES
; DeviceNumber
++)
1011 SlotNumber
.u
.bits
.DeviceNumber
= DeviceNumber
;
1013 /* Loop through all functions */
1014 for (FunctionNumber
= NextSlotNumber
->u
.bits
.FunctionNumber
; FunctionNumber
< PCI_MAX_FUNCTION
; FunctionNumber
++)
1016 SlotNumber
.u
.bits
.FunctionNumber
= FunctionNumber
;
1018 /* Get PCI config bytes */
1019 DataSize
= HalGetBusDataByOffset(
1022 SlotNumber
.u
.AsULONG
,
1027 /* If result of HalGetBusData is 0, then the bus is wrong */
1031 /* If result is PCI_INVALID_VENDORID, then this device has no more
1033 if (PciConfig
.VendorID
== PCI_INVALID_VENDORID
)
1036 sprintf(VendorIdString
, "%04hx", PciConfig
.VendorID
);
1037 sprintf(DeviceIdString
, "%04hx", PciConfig
.DeviceID
);
1039 if (_strnicmp(VendorIdString
, HwInitializationData
->VendorId
, HwInitializationData
->VendorIdLength
) ||
1040 _strnicmp(DeviceIdString
, HwInitializationData
->DeviceId
, HwInitializationData
->DeviceIdLength
))
1042 /* It is not our device */
1046 TRACE( "Found device 0x%04hx 0x%04hx at %1lu %2lu %1lu\n",
1047 PciConfig
.VendorID
, PciConfig
.DeviceID
,
1049 SlotNumber
.u
.bits
.DeviceNumber
, SlotNumber
.u
.bits
.FunctionNumber
);
1051 Status
= HalAssignSlotResources(NULL
,
1057 SlotNumber
.u
.AsULONG
,
1060 if (!NT_SUCCESS(Status
))
1063 /* Create configuration information */
1064 SpiResourceToConfig(HwInitializationData
,
1068 /* Free the resource list */
1069 ExFreePool(ResourceList
);
1071 /* Set dev & fn numbers */
1072 NextSlotNumber
->u
.bits
.DeviceNumber
= DeviceNumber
;
1073 NextSlotNumber
->u
.bits
.FunctionNumber
= FunctionNumber
+ 1;
1075 /* Save the slot number */
1076 PortConfig
->SlotNumber
= SlotNumber
.u
.AsULONG
;
1080 NextSlotNumber
->u
.bits
.FunctionNumber
= 0;
1083 NextSlotNumber
->u
.bits
.DeviceNumber
= 0;
1093 IN PHW_INITIALIZATION_DATA HwInitializationData
,
1094 IN PVOID HwContext OPTIONAL
)
1096 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
1097 ULONG DeviceExtensionSize
;
1098 PORT_CONFIGURATION_INFORMATION PortConfig
;
1100 BOOLEAN FirstConfigCall
= TRUE
;
1101 PCI_SLOT_NUMBER SlotNumber
;
1105 if (HwInitializationData
->HwInitializationDataSize
!= sizeof(HW_INITIALIZATION_DATA
))
1107 return STATUS_INVALID_PARAMETER
;
1110 /* Check params for validity */
1111 if ((HwInitializationData
->HwInitialize
== NULL
) ||
1112 (HwInitializationData
->HwStartIo
== NULL
) ||
1113 (HwInitializationData
->HwInterrupt
== NULL
) ||
1114 (HwInitializationData
->HwFindAdapter
== NULL
) ||
1115 (HwInitializationData
->HwResetBus
== NULL
))
1117 return STATUS_INVALID_PARAMETER
;
1120 /* Zero starting slot number */
1121 SlotNumber
.u
.AsULONG
= 0;
1127 DeviceExtensionSize
= sizeof(SCSI_PORT_DEVICE_EXTENSION
) + HwInitializationData
->DeviceExtensionSize
;
1128 DeviceExtension
= FrLdrTempAlloc(DeviceExtensionSize
, TAG_SCSI_DEVEXT
);
1129 if (!DeviceExtension
)
1131 return STATUS_NO_MEMORY
;
1133 RtlZeroMemory(DeviceExtension
, DeviceExtensionSize
);
1134 DeviceExtension
->InterruptFlags
= SCSI_PORT_NEXT_REQUEST_READY
;
1135 DeviceExtension
->HwInitialize
= HwInitializationData
->HwInitialize
;
1136 DeviceExtension
->HwStartIo
= HwInitializationData
->HwStartIo
;
1137 DeviceExtension
->HwInterrupt
= HwInitializationData
->HwInterrupt
;
1138 DeviceExtension
->HwResetBus
= HwInitializationData
->HwResetBus
;
1139 DeviceExtension
->MiniPortDeviceExtension
= (PVOID
)(DeviceExtension
+ 1);
1141 Status
= SpiCreatePortConfig(DeviceExtension
,
1142 HwInitializationData
,
1145 if (Status
!= STATUS_SUCCESS
)
1147 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1151 PortConfig
.NumberOfAccessRanges
= HwInitializationData
->NumberOfAccessRanges
;
1152 PortConfig
.AccessRanges
= FrLdrTempAlloc(sizeof(ACCESS_RANGE
) * HwInitializationData
->NumberOfAccessRanges
,
1153 TAG_SCSI_ACCESS_RANGES
);
1154 if (!PortConfig
.AccessRanges
)
1156 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1157 return STATUS_NO_MEMORY
;
1159 RtlZeroMemory(PortConfig
.AccessRanges
, sizeof(ACCESS_RANGE
) * HwInitializationData
->NumberOfAccessRanges
);
1161 /* Search for matching PCI device */
1162 if ((HwInitializationData
->AdapterInterfaceType
== PCIBus
) &&
1163 (HwInitializationData
->VendorIdLength
> 0) &&
1164 (HwInitializationData
->VendorId
!= NULL
) &&
1165 (HwInitializationData
->DeviceIdLength
> 0) &&
1166 (HwInitializationData
->DeviceId
!= NULL
))
1168 PortConfig
.BusInterruptLevel
= 0;
1170 /* Get PCI device data */
1171 TRACE("VendorId '%.*s' DeviceId '%.*s'\n",
1172 HwInitializationData
->VendorIdLength
,
1173 HwInitializationData
->VendorId
,
1174 HwInitializationData
->DeviceIdLength
,
1175 HwInitializationData
->DeviceId
);
1177 if (!SpiGetPciConfigData(HwInitializationData
,
1182 /* Continue to the next bus, nothing here */
1183 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1184 return STATUS_INTERNAL_ERROR
;
1187 if (!PortConfig
.BusInterruptLevel
)
1189 /* Bypass this slot, because no interrupt was assigned */
1190 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1191 return STATUS_INTERNAL_ERROR
;
1195 if (HwInitializationData
->HwFindAdapter(
1196 DeviceExtension
->MiniPortDeviceExtension
,
1201 &Again
) != SP_RETURN_FOUND
)
1203 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1204 return STATUS_INTERNAL_ERROR
;
1207 /* Copy all stuff which we ever need from PortConfig to the DeviceExtension */
1208 if (PortConfig
.MaximumNumberOfTargets
> SCSI_MAXIMUM_TARGETS_PER_BUS
)
1209 DeviceExtension
->MaxTargedIds
= SCSI_MAXIMUM_TARGETS_PER_BUS
;
1211 DeviceExtension
->MaxTargedIds
= PortConfig
.MaximumNumberOfTargets
;
1213 DeviceExtension
->BusNum
= PortConfig
.SystemIoBusNumber
;
1215 TRACE("Adapter found: buses = %d, targets = %d\n",
1216 PortConfig
.NumberOfBuses
, DeviceExtension
->MaxTargedIds
);
1218 /* Initialize adapter */
1219 if (!DeviceExtension
->HwInitialize(DeviceExtension
->MiniPortDeviceExtension
))
1221 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1222 return STATUS_INTERNAL_ERROR
;
1226 for (ScsiBus
= 0; ScsiBus
< PortConfig
.NumberOfBuses
; ScsiBus
++)
1228 SpiScanAdapter(DeviceExtension
, PortConfig
.SystemIoBusNumber
, ScsiBus
);
1229 PortConfig
.SystemIoBusNumber
++;
1232 FirstConfigCall
= FALSE
;
1239 return STATUS_SUCCESS
;
1244 ScsiPortIoMapTransfer(
1245 IN PVOID HwDeviceExtension
,
1246 IN PSCSI_REQUEST_BLOCK Srb
,
1247 IN PVOID LogicalAddress
,
1257 IN PVOID HwDeviceExtension
,
1258 IN PSCSI_REQUEST_BLOCK Srb OPTIONAL
,
1272 IN PVOID WriteBuffer
,
1273 IN PVOID ReadBuffer
,
1276 RtlMoveMemory(WriteBuffer
, ReadBuffer
, Length
);
1281 ScsiPortNotification(
1282 IN SCSI_NOTIFICATION_TYPE NotificationType
,
1283 IN PVOID HwDeviceExtension
,
1286 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
1287 PSCSI_REQUEST_BLOCK Srb
;
1290 DeviceExtension
= ((PSCSI_PORT_DEVICE_EXTENSION
)HwDeviceExtension
) - 1;
1292 va_start(ap
, HwDeviceExtension
);
1294 switch (NotificationType
)
1296 case RequestComplete
:
1297 /* Mask the SRB as completed */
1298 Srb
= va_arg(ap
, PSCSI_REQUEST_BLOCK
);
1299 Srb
->SrbFlags
&= ~SRB_FLAGS_IS_ACTIVE
;
1303 /* Say that device is ready */
1304 DeviceExtension
->InterruptFlags
|= SCSI_PORT_NEXT_REQUEST_READY
;
1317 ScsiPortReadPortBufferUchar(
1322 __inbytestring(H2I(Port
), Buffer
, Count
);
1327 ScsiPortReadPortBufferUlong(
1332 __indwordstring(H2I(Port
), Buffer
, Count
);
1337 ScsiPortReadPortBufferUshort(
1342 __inwordstring(H2I(Port
), Buffer
, Count
);
1347 ScsiPortReadPortUchar(
1350 TRACE("ScsiPortReadPortUchar(%p)\n", Port
);
1352 return READ_PORT_UCHAR(Port
);
1357 ScsiPortReadPortUlong(
1360 return READ_PORT_ULONG(Port
);
1365 ScsiPortReadPortUshort(
1368 return READ_PORT_USHORT(Port
);
1373 ScsiPortReadRegisterBufferUchar(
1384 ScsiPortReadRegisterBufferUlong(
1395 ScsiPortReadRegisterBufferUshort(
1396 IN PUSHORT Register
,
1406 ScsiPortReadRegisterUchar(
1409 return READ_REGISTER_UCHAR(Register
);
1414 ScsiPortReadRegisterUlong(
1417 return READ_REGISTER_ULONG(Register
);
1422 ScsiPortReadRegisterUshort(
1423 IN PUSHORT Register
)
1425 return READ_REGISTER_USHORT(Register
);
1430 ScsiPortSetBusDataByOffset(
1431 IN PVOID DeviceExtension
,
1432 IN ULONG BusDataType
,
1433 IN ULONG SystemIoBusNumber
,
1434 IN ULONG SlotNumber
,
1446 ScsiPortStallExecution(
1449 KeStallExecutionProcessor(Delay
);
1454 ScsiPortValidateRange(
1455 IN PVOID HwDeviceExtension
,
1456 IN INTERFACE_TYPE BusType
,
1457 IN ULONG SystemIoBusNumber
,
1458 IN SCSI_PHYSICAL_ADDRESS IoAddress
,
1459 IN ULONG NumberOfBytes
,
1460 IN BOOLEAN InIoSpace
)
1474 ScsiPortWritePortBufferUchar(
1479 __outbytestring(H2I(Port
), Buffer
, Count
);
1484 ScsiPortWritePortBufferUlong(
1489 __outdwordstring(H2I(Port
), Buffer
, Count
);
1494 ScsiPortWritePortBufferUshort(
1499 __outwordstring(H2I(Port
), Buffer
, Count
);
1504 ScsiPortWritePortUchar(
1508 WRITE_PORT_UCHAR(Port
, Value
);
1513 ScsiPortWritePortUlong(
1517 WRITE_PORT_ULONG(Port
, Value
);
1522 ScsiPortWritePortUshort(
1526 WRITE_PORT_USHORT(Port
, Value
);
1531 ScsiPortWriteRegisterBufferUchar(
1542 ScsiPortWriteRegisterBufferUlong(
1553 ScsiPortWriteRegisterBufferUshort(
1554 IN PUSHORT Register
,
1564 ScsiPortWriteRegisterUchar(
1568 WRITE_REGISTER_UCHAR(Register
, Value
);
1573 ScsiPortWriteRegisterUlong(
1577 WRITE_REGISTER_ULONG(Register
, Value
);
1582 ScsiPortWriteRegisterUshort(
1583 IN PUSHORT Register
,
1586 WRITE_REGISTER_USHORT(Register
, Value
);
1589 extern char __ImageBase
;
1592 LoadBootDeviceDriver(VOID
)
1594 PIMAGE_NT_HEADERS NtHeaders
;
1595 LIST_ENTRY ModuleListHead
;
1596 PIMAGE_IMPORT_DESCRIPTOR ImportTable
;
1597 ULONG ImportTableSize
;
1598 PLDR_DATA_TABLE_ENTRY BootDdDTE
, FreeldrDTE
;
1599 CHAR NtBootDdPath
[MAX_PATH
];
1600 PVOID ImageBase
= NULL
;
1601 ULONG (NTAPI
*EntryPoint
)(IN PVOID DriverObject
, IN PVOID RegistryPath
);
1604 // FIXME: Must be done *INSIDE* the HAL!
1606 HalpInitializePciStubs();
1607 HalpInitBusHandler();
1610 /* Initialize the loaded module list */
1611 InitializeListHead(&ModuleListHead
);
1613 /* Create full ntbootdd.sys path */
1614 strcpy(NtBootDdPath
, FrLdrBootPath
);
1615 strcat(NtBootDdPath
, "\\NTBOOTDD.SYS");
1618 Success
= WinLdrLoadImage(NtBootDdPath
, LoaderBootDriver
, &ImageBase
);
1621 /* That's OK. File simply doesn't exist */
1625 /* Allocate a DTE for ntbootdd */
1626 Success
= WinLdrAllocateDataTableEntry(&ModuleListHead
, "ntbootdd.sys",
1627 "NTBOOTDD.SYS", ImageBase
, &BootDdDTE
);
1631 /* Add the PE part of freeldr.sys to the list of loaded executables, it
1632 contains ScsiPort* exports, imported by ntbootdd.sys */
1633 Success
= WinLdrAllocateDataTableEntry(&ModuleListHead
, "scsiport.sys",
1634 "FREELDR.SYS", &__ImageBase
, &FreeldrDTE
);
1637 RemoveEntryList(&BootDdDTE
->InLoadOrderLinks
);
1642 Success
= WinLdrScanImportDescriptorTable(&ModuleListHead
, "", BootDdDTE
);
1644 /* Now unlinkt the DTEs, they won't be valid later */
1645 RemoveEntryList(&BootDdDTE
->InLoadOrderLinks
);
1646 RemoveEntryList(&FreeldrDTE
->InLoadOrderLinks
);
1651 /* Change imports to PA */
1652 ImportTable
= (PIMAGE_IMPORT_DESCRIPTOR
)RtlImageDirectoryEntryToData(VaToPa(BootDdDTE
->DllBase
),
1653 TRUE
, IMAGE_DIRECTORY_ENTRY_IMPORT
, &ImportTableSize
);
1654 for (;(ImportTable
->Name
!= 0) && (ImportTable
->FirstThunk
!= 0);ImportTable
++)
1656 PIMAGE_THUNK_DATA ThunkData
= (PIMAGE_THUNK_DATA
)VaToPa(RVA(BootDdDTE
->DllBase
, ImportTable
->FirstThunk
));
1658 while (((PIMAGE_THUNK_DATA
)ThunkData
)->u1
.AddressOfData
!= 0)
1660 ThunkData
->u1
.Function
= (ULONG
)VaToPa((PVOID
)ThunkData
->u1
.Function
);
1665 /* Relocate image to PA */
1666 NtHeaders
= RtlImageNtHeader(VaToPa(BootDdDTE
->DllBase
));
1669 Success
= (BOOLEAN
)LdrRelocateImageWithBias(VaToPa(BootDdDTE
->DllBase
),
1670 NtHeaders
->OptionalHeader
.ImageBase
- (ULONG_PTR
)BootDdDTE
->DllBase
,
1673 TRUE
, /* in case of conflict still return success */
1678 /* Call the entrypoint */
1679 EntryPoint
= VaToPa(BootDdDTE
->EntryPoint
);
1680 (*EntryPoint
)(NULL
, NULL
);