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 ULONGLONG SectorNumber
;
378 if (SeekMode
!= SeekAbsolute
)
380 if (Position
->QuadPart
& (Context
->SectorSize
- 1))
383 SectorNumber
= Position
->QuadPart
/ Context
->SectorSize
;
384 if (SectorNumber
>= Context
->SectorCount
)
387 Context
->SectorNumber
= SectorNumber
;
391 static const DEVVTBL DiskVtbl
= {
393 DiskGetFileInformation
,
402 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
403 IN PHW_INITIALIZATION_DATA HwInitData
,
404 OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo
,
405 IN BOOLEAN ZeroStruct
)
409 /* Zero out the struct if told so */
412 /* First zero the portconfig */
413 RtlZeroMemory(ConfigInfo
, sizeof(PORT_CONFIGURATION_INFORMATION
));
415 /* Initialize the struct */
416 ConfigInfo
->Length
= sizeof(PORT_CONFIGURATION_INFORMATION
);
417 ConfigInfo
->AdapterInterfaceType
= HwInitData
->AdapterInterfaceType
;
418 ConfigInfo
->InterruptMode
= Latched
;
419 ConfigInfo
->DmaChannel
= SP_UNINITIALIZED_VALUE
;
420 ConfigInfo
->DmaPort
= SP_UNINITIALIZED_VALUE
;
421 ConfigInfo
->MaximumTransferLength
= SP_UNINITIALIZED_VALUE
;
422 ConfigInfo
->MaximumNumberOfTargets
= SCSI_MAXIMUM_TARGETS_PER_BUS
;
424 /* Store parameters */
425 ConfigInfo
->NeedPhysicalAddresses
= HwInitData
->NeedPhysicalAddresses
;
426 ConfigInfo
->MapBuffers
= HwInitData
->MapBuffers
;
427 ConfigInfo
->AutoRequestSense
= HwInitData
->AutoRequestSense
;
428 ConfigInfo
->ReceiveEvent
= HwInitData
->ReceiveEvent
;
429 ConfigInfo
->TaggedQueuing
= HwInitData
->TaggedQueuing
;
430 ConfigInfo
->MultipleRequestPerLu
= HwInitData
->MultipleRequestPerLu
;
432 /* Get the disk usage */
433 ConfigInfo
->AtdiskPrimaryClaimed
= FALSE
; // FIXME
434 ConfigInfo
->AtdiskSecondaryClaimed
= FALSE
; // FIXME
436 /* Initiator bus id is not set */
437 for (Bus
= 0; Bus
< 8; Bus
++)
438 ConfigInfo
->InitiatorBusId
[Bus
] = (CCHAR
)SP_UNINITIALIZED_VALUE
;
441 ConfigInfo
->NumberOfPhysicalBreaks
= 17;
443 return STATUS_SUCCESS
;
449 IN ULONG DebugPrintLevel
,
450 IN PCCHAR DebugMessage
,
457 if (DebugPrintLevel
> 10)
460 va_start(ap
, DebugMessage
);
462 /* Construct a string */
463 Length
= _vsnprintf(Buffer
, 512, DebugMessage
, ap
);
465 /* Check if we went past the buffer */
466 if (Length
== MAXULONG
)
468 /* Terminate it if we went over-board */
469 Buffer
[sizeof(Buffer
) - 1] = '\0';
472 Length
= sizeof(Buffer
);
475 /* Print the message */
484 ScsiPortCompleteRequest(
485 IN PVOID HwDeviceExtension
,
495 #undef ScsiPortConvertPhysicalAddressToUlong
498 ScsiPortConvertPhysicalAddressToUlong(
499 IN SCSI_PHYSICAL_ADDRESS Address
)
501 return Address
.LowPart
;
504 SCSI_PHYSICAL_ADDRESS
506 ScsiPortConvertUlongToPhysicalAddress(
507 IN ULONG_PTR UlongAddress
)
509 SCSI_PHYSICAL_ADDRESS Address
;
511 Address
.QuadPart
= UlongAddress
;
518 IN PVOID DeviceExtension
)
526 ScsiPortFreeDeviceBase(
527 IN PVOID HwDeviceExtension
,
528 IN PVOID MappedAddress
)
536 IN PVOID DeviceExtension
,
537 IN ULONG BusDataType
,
538 IN ULONG SystemIoBusNumber
,
543 return HalGetBusDataByOffset(BusDataType
, SystemIoBusNumber
, SlotNumber
, Buffer
, 0, Length
);
548 ScsiPortGetDeviceBase(
549 IN PVOID HwDeviceExtension
,
550 IN INTERFACE_TYPE BusType
,
551 IN ULONG SystemIoBusNumber
,
552 IN SCSI_PHYSICAL_ADDRESS IoAddress
,
553 IN ULONG NumberOfBytes
,
554 IN BOOLEAN InIoSpace
)
556 PHYSICAL_ADDRESS TranslatedAddress
;
559 AddressSpace
= (ULONG
)InIoSpace
;
560 if (HalTranslateBusAddress(BusType
,
564 &TranslatedAddress
) == FALSE
)
570 if (AddressSpace
!= 0)
571 return (PVOID
)TranslatedAddress
.u
.LowPart
;
575 return (PVOID
)IoAddress
.LowPart
;
580 ScsiPortGetLogicalUnit(
581 IN PVOID HwDeviceExtension
,
591 SCSI_PHYSICAL_ADDRESS
593 ScsiPortGetPhysicalAddress(
594 IN PVOID HwDeviceExtension
,
595 IN PSCSI_REQUEST_BLOCK Srb OPTIONAL
,
596 IN PVOID VirtualAddress
,
599 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
600 SCSI_PHYSICAL_ADDRESS PhysicalAddress
;
601 ULONG BufferLength
= 0;
604 TRACE("ScsiPortGetPhysicalAddress(%p %p %p %p)\n",
605 HwDeviceExtension
, Srb
, VirtualAddress
, Length
);
607 DeviceExtension
= ((PSCSI_PORT_DEVICE_EXTENSION
)HwDeviceExtension
) - 1;
609 if (Srb
== NULL
|| Srb
->SenseInfoBuffer
== VirtualAddress
)
611 /* Simply look it up in the allocated common buffer */
612 Offset
= (PUCHAR
)VirtualAddress
- (PUCHAR
)DeviceExtension
->SrbExtensionBuffer
;
614 BufferLength
= DeviceExtension
->CommonBufferLength
- Offset
;
615 PhysicalAddress
.QuadPart
= Offset
;
620 PhysicalAddress
.QuadPart
= (LONGLONG
)(SP_UNINITIALIZED_VALUE
);
623 *Length
= BufferLength
;
624 return PhysicalAddress
;
630 IN PVOID DeviceExtension
,
643 SpiAllocateCommonBuffer(
644 IN OUT PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
645 IN ULONG NonCachedSize
)
648 ULONG CommonBufferLength
, BufSize
;
650 /* If size is 0, set it to 16 */
651 if (!DeviceExtension
->SrbExtensionSize
)
652 DeviceExtension
->SrbExtensionSize
= 16;
655 BufSize
= DeviceExtension
->SrbExtensionSize
;
658 BufSize
= (BufSize
+ sizeof(LONGLONG
) - 1) & ~(sizeof(LONGLONG
) - 1);
660 /* Sum up into the total common buffer length, and round it to page size */
662 ROUND_TO_PAGES(NonCachedSize
);
665 if (!DeviceExtension
->AdapterObject
)
667 /* From nonpaged pool if there is no DMA */
668 CommonBuffer
= ExAllocatePool(NonPagedPool
, CommonBufferLength
);
672 /* Perform a full request since we have a DMA adapter*/
677 /* Fail in case of error */
679 return STATUS_INSUFFICIENT_RESOURCES
;
682 RtlZeroMemory(CommonBuffer
, CommonBufferLength
);
684 /* Store its size in Device Extension */
685 DeviceExtension
->CommonBufferLength
= CommonBufferLength
;
687 /* SrbExtension buffer is located at the beginning of the buffer */
688 DeviceExtension
->SrbExtensionBuffer
= CommonBuffer
;
690 /* Non-cached extension buffer is located at the end of
694 CommonBufferLength
-= NonCachedSize
;
695 DeviceExtension
->NonCachedExtension
= (PUCHAR
)CommonBuffer
+ CommonBufferLength
;
699 DeviceExtension
->NonCachedExtension
= NULL
;
702 return STATUS_SUCCESS
;
707 ScsiPortGetUncachedExtension(
708 IN PVOID HwDeviceExtension
,
709 IN PPORT_CONFIGURATION_INFORMATION ConfigInfo
,
710 IN ULONG NumberOfBytes
)
712 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
713 DEVICE_DESCRIPTION DeviceDescription
;
714 ULONG MapRegistersCount
;
717 TRACE("ScsiPortGetUncachedExtension(%p %p %lu)\n",
718 HwDeviceExtension
, ConfigInfo
, NumberOfBytes
);
720 DeviceExtension
= ((PSCSI_PORT_DEVICE_EXTENSION
)HwDeviceExtension
) - 1;
722 /* Check for allocated common DMA buffer */
723 if (DeviceExtension
->SrbExtensionBuffer
!= NULL
)
728 /* Check for DMA adapter object */
729 if (DeviceExtension
->AdapterObject
== NULL
)
731 /* Initialize DMA adapter description */
732 RtlZeroMemory(&DeviceDescription
, sizeof(DEVICE_DESCRIPTION
));
734 DeviceDescription
.Version
= DEVICE_DESCRIPTION_VERSION
;
735 DeviceDescription
.Master
= ConfigInfo
->Master
;
736 DeviceDescription
.ScatterGather
= ConfigInfo
->ScatterGather
;
737 DeviceDescription
.DemandMode
= ConfigInfo
->DemandMode
;
738 DeviceDescription
.Dma32BitAddresses
= ConfigInfo
->Dma32BitAddresses
;
739 DeviceDescription
.BusNumber
= ConfigInfo
->SystemIoBusNumber
;
740 DeviceDescription
.DmaChannel
= ConfigInfo
->DmaChannel
;
741 DeviceDescription
.InterfaceType
= ConfigInfo
->AdapterInterfaceType
;
742 DeviceDescription
.DmaWidth
= ConfigInfo
->DmaWidth
;
743 DeviceDescription
.DmaSpeed
= ConfigInfo
->DmaSpeed
;
744 DeviceDescription
.MaximumLength
= ConfigInfo
->MaximumTransferLength
;
745 DeviceDescription
.DmaPort
= ConfigInfo
->DmaPort
;
747 /* Get a DMA adapter object */
749 DeviceExtension
->AdapterObject
=
750 HalGetAdapter(&DeviceDescription
, &MapRegistersCount
);
752 /* Fail in case of error */
753 if (DeviceExtension
->AdapterObject
== NULL
)
758 MapRegistersCount
= 0;
761 /* Set number of physical breaks */
762 if (ConfigInfo
->NumberOfPhysicalBreaks
!= 0 &&
763 MapRegistersCount
> ConfigInfo
->NumberOfPhysicalBreaks
)
765 DeviceExtension
->PortCapabilities
.MaximumPhysicalPages
=
766 ConfigInfo
->NumberOfPhysicalBreaks
;
770 DeviceExtension
->PortCapabilities
.MaximumPhysicalPages
= MapRegistersCount
;
774 /* Update Srb extension size */
775 if (DeviceExtension
->SrbExtensionSize
!= ConfigInfo
->SrbExtensionSize
)
776 DeviceExtension
->SrbExtensionSize
= ConfigInfo
->SrbExtensionSize
;
778 /* Allocate a common DMA buffer */
779 Status
= SpiAllocateCommonBuffer(DeviceExtension
, NumberOfBytes
);
781 if (!NT_SUCCESS(Status
))
783 TRACE("SpiAllocateCommonBuffer() failed with Status = 0x%08X!\n", Status
);
787 return DeviceExtension
->NonCachedExtension
;
792 ScsiPortGetVirtualAddress(
793 IN PVOID HwDeviceExtension
,
794 IN SCSI_PHYSICAL_ADDRESS PhysicalAddress
)
804 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
813 struct _DRIVE_LAYOUT_INFORMATION
*PartitionBuffer
;
814 CHAR PartitionName
[64];
816 /* Register device with partition(0) suffix */
817 RtlStringCbPrintfA(PartitionName
, sizeof(PartitionName
), "%spartition(0)", ArcName
);
818 FsRegisterDevice(PartitionName
, &DiskVtbl
);
820 /* Read device partition table */
821 Status
= ArcOpen(PartitionName
, OpenReadOnly
, &FileId
);
822 if (Status
== ESUCCESS
)
824 ret
= HALDISPATCH
->HalIoReadPartitionTable((PDEVICE_OBJECT
)FileId
, 512, FALSE
, &PartitionBuffer
);
827 for (i
= 0; i
< PartitionBuffer
->PartitionCount
; i
++)
829 if (PartitionBuffer
->PartitionEntry
[i
].PartitionType
!= PARTITION_ENTRY_UNUSED
)
831 RtlStringCbPrintfA(PartitionName
,
832 sizeof(PartitionName
),
835 PartitionBuffer
->PartitionEntry
[i
].PartitionNumber
);
836 FsRegisterDevice(PartitionName
, &DiskVtbl
);
839 ExFreePool(PartitionBuffer
);
848 IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
853 PSCSI_REQUEST_BLOCK Srb
;
855 INQUIRYDATA InquiryBuffer
;
859 if (!DeviceExtension
->HwResetBus(DeviceExtension
->MiniPortDeviceExtension
, PathId
))
864 /* Remember the extension */
865 ScsiDeviceExtensions
[ScsiBus
] = DeviceExtension
;
867 for (TargetId
= 0; TargetId
< DeviceExtension
->MaxTargedIds
; TargetId
++)
872 TRACE("Scanning SCSI device %d.%d.%d\n",
873 ScsiBus
, TargetId
, Lun
);
875 Srb
= ExAllocatePool(PagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
878 RtlZeroMemory(Srb
, sizeof(SCSI_REQUEST_BLOCK
));
879 Srb
->Length
= sizeof(SCSI_REQUEST_BLOCK
);
880 Srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
881 Srb
->PathId
= PathId
;
882 Srb
->TargetId
= TargetId
;
885 Srb
->SrbFlags
= SRB_FLAGS_DATA_IN
;
886 Srb
->DataTransferLength
= INQUIRYDATABUFFERSIZE
;
887 Srb
->TimeOutValue
= 5; /* in seconds */
888 Srb
->DataBuffer
= &InquiryBuffer
;
889 Cdb
= (PCDB
)Srb
->Cdb
;
890 Cdb
->CDB6INQUIRY
.OperationCode
= SCSIOP_INQUIRY
;
891 Cdb
->CDB6INQUIRY
.LogicalUnitNumber
= Srb
->Lun
;
892 Cdb
->CDB6INQUIRY
.AllocationLength
= (UCHAR
)Srb
->DataTransferLength
;
893 if (!SpiSendSynchronousSrb(DeviceExtension
, Srb
))
895 /* Don't check next LUNs */
899 /* Device exists, create its ARC name */
900 if (InquiryBuffer
.RemovableMedia
)
902 sprintf(ArcName
, "scsi(%ld)cdrom(%d)fdisk(%d)",
903 ScsiBus
, TargetId
, Lun
);
904 FsRegisterDevice(ArcName
, &DiskVtbl
);
908 sprintf(ArcName
, "scsi(%ld)disk(%d)rdisk(%d)",
909 ScsiBus
, TargetId
, Lun
);
910 /* Now, check if it has partitions */
911 SpiScanDevice(DeviceExtension
, ArcName
, PathId
, TargetId
, Lun
);
916 } while (Lun
< SCSI_MAXIMUM_LOGICAL_UNITS
);
923 IN PHW_INITIALIZATION_DATA HwInitializationData
,
924 IN PCM_FULL_RESOURCE_DESCRIPTOR ResourceDescriptor
,
925 IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig
)
927 PACCESS_RANGE AccessRange
;
928 PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialData
;
934 /* Loop through all entries */
935 for (Index
= 0; Index
< ResourceDescriptor
->PartialResourceList
.Count
; Index
++)
937 PartialData
= &ResourceDescriptor
->PartialResourceList
.PartialDescriptors
[Index
];
939 switch (PartialData
->Type
)
941 case CmResourceTypePort
:
942 /* Copy access ranges */
943 if (RangeNumber
< HwInitializationData
->NumberOfAccessRanges
)
945 TRACE("Got port at 0x%I64x, len 0x%x\n",
946 PartialData
->u
.Port
.Start
.QuadPart
, PartialData
->u
.Port
.Length
);
947 AccessRange
= &((*(PortConfig
->AccessRanges
))[RangeNumber
]);
949 AccessRange
->RangeStart
= PartialData
->u
.Port
.Start
;
950 AccessRange
->RangeLength
= PartialData
->u
.Port
.Length
;
952 AccessRange
->RangeInMemory
= FALSE
;
957 case CmResourceTypeMemory
:
958 /* Copy access ranges */
959 if (RangeNumber
< HwInitializationData
->NumberOfAccessRanges
)
961 TRACE("Got memory at 0x%I64x, len 0x%x\n",
962 PartialData
->u
.Memory
.Start
.QuadPart
, PartialData
->u
.Memory
.Length
);
963 AccessRange
= &((*(PortConfig
->AccessRanges
))[RangeNumber
]);
965 AccessRange
->RangeStart
= PartialData
->u
.Memory
.Start
;
966 AccessRange
->RangeLength
= PartialData
->u
.Memory
.Length
;
968 AccessRange
->RangeInMemory
= TRUE
;
973 case CmResourceTypeInterrupt
:
974 /* Copy interrupt data */
975 TRACE("Got interrupt level %d, vector %d\n",
976 PartialData
->u
.Interrupt
.Level
, PartialData
->u
.Interrupt
.Vector
);
977 PortConfig
->BusInterruptLevel
= PartialData
->u
.Interrupt
.Level
;
978 PortConfig
->BusInterruptVector
= PartialData
->u
.Interrupt
.Vector
;
980 /* Set interrupt mode accordingly to the resource */
981 if (PartialData
->Flags
== CM_RESOURCE_INTERRUPT_LATCHED
)
983 PortConfig
->InterruptMode
= Latched
;
985 else if (PartialData
->Flags
== CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
)
987 PortConfig
->InterruptMode
= LevelSensitive
;
991 case CmResourceTypeDma
:
992 TRACE("Got DMA channel %d, port %d\n",
993 PartialData
->u
.Dma
.Channel
, PartialData
->u
.Dma
.Port
);
994 PortConfig
->DmaChannel
= PartialData
->u
.Dma
.Channel
;
995 PortConfig
->DmaPort
= PartialData
->u
.Dma
.Port
;
1003 SpiGetPciConfigData(
1004 IN PHW_INITIALIZATION_DATA HwInitializationData
,
1005 IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig
,
1007 IN OUT PPCI_SLOT_NUMBER NextSlotNumber
)
1009 PCI_COMMON_CONFIG PciConfig
;
1010 PCI_SLOT_NUMBER SlotNumber
;
1013 ULONG FunctionNumber
;
1014 CHAR VendorIdString
[8];
1015 CHAR DeviceIdString
[8];
1016 PCM_RESOURCE_LIST ResourceList
= NULL
;
1019 SlotNumber
.u
.AsULONG
= 0;
1021 /* Loop through all devices */
1022 for (DeviceNumber
= NextSlotNumber
->u
.bits
.DeviceNumber
; DeviceNumber
< PCI_MAX_DEVICES
; DeviceNumber
++)
1024 SlotNumber
.u
.bits
.DeviceNumber
= DeviceNumber
;
1026 /* Loop through all functions */
1027 for (FunctionNumber
= NextSlotNumber
->u
.bits
.FunctionNumber
; FunctionNumber
< PCI_MAX_FUNCTION
; FunctionNumber
++)
1029 SlotNumber
.u
.bits
.FunctionNumber
= FunctionNumber
;
1031 /* Get PCI config bytes */
1032 DataSize
= HalGetBusDataByOffset(
1035 SlotNumber
.u
.AsULONG
,
1040 /* If result of HalGetBusData is 0, then the bus is wrong */
1044 /* If result is PCI_INVALID_VENDORID, then this device has no more
1046 if (PciConfig
.VendorID
== PCI_INVALID_VENDORID
)
1049 sprintf(VendorIdString
, "%04hx", PciConfig
.VendorID
);
1050 sprintf(DeviceIdString
, "%04hx", PciConfig
.DeviceID
);
1052 if (_strnicmp(VendorIdString
, HwInitializationData
->VendorId
, HwInitializationData
->VendorIdLength
) ||
1053 _strnicmp(DeviceIdString
, HwInitializationData
->DeviceId
, HwInitializationData
->DeviceIdLength
))
1055 /* It is not our device */
1059 TRACE( "Found device 0x%04hx 0x%04hx at %1lu %2lu %1lu\n",
1060 PciConfig
.VendorID
, PciConfig
.DeviceID
,
1062 SlotNumber
.u
.bits
.DeviceNumber
, SlotNumber
.u
.bits
.FunctionNumber
);
1064 Status
= HalAssignSlotResources(NULL
,
1070 SlotNumber
.u
.AsULONG
,
1073 if (!NT_SUCCESS(Status
))
1076 /* Create configuration information */
1077 SpiResourceToConfig(HwInitializationData
,
1081 /* Free the resource list */
1082 ExFreePool(ResourceList
);
1084 /* Set dev & fn numbers */
1085 NextSlotNumber
->u
.bits
.DeviceNumber
= DeviceNumber
;
1086 NextSlotNumber
->u
.bits
.FunctionNumber
= FunctionNumber
+ 1;
1088 /* Save the slot number */
1089 PortConfig
->SlotNumber
= SlotNumber
.u
.AsULONG
;
1093 NextSlotNumber
->u
.bits
.FunctionNumber
= 0;
1096 NextSlotNumber
->u
.bits
.DeviceNumber
= 0;
1106 IN PHW_INITIALIZATION_DATA HwInitializationData
,
1107 IN PVOID HwContext OPTIONAL
)
1109 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
1110 ULONG DeviceExtensionSize
;
1111 PORT_CONFIGURATION_INFORMATION PortConfig
;
1113 BOOLEAN FirstConfigCall
= TRUE
;
1114 PCI_SLOT_NUMBER SlotNumber
;
1118 if (HwInitializationData
->HwInitializationDataSize
!= sizeof(HW_INITIALIZATION_DATA
))
1120 return STATUS_INVALID_PARAMETER
;
1123 /* Check params for validity */
1124 if ((HwInitializationData
->HwInitialize
== NULL
) ||
1125 (HwInitializationData
->HwStartIo
== NULL
) ||
1126 (HwInitializationData
->HwInterrupt
== NULL
) ||
1127 (HwInitializationData
->HwFindAdapter
== NULL
) ||
1128 (HwInitializationData
->HwResetBus
== NULL
))
1130 return STATUS_INVALID_PARAMETER
;
1133 /* Zero starting slot number */
1134 SlotNumber
.u
.AsULONG
= 0;
1140 DeviceExtensionSize
= sizeof(SCSI_PORT_DEVICE_EXTENSION
) + HwInitializationData
->DeviceExtensionSize
;
1141 DeviceExtension
= FrLdrTempAlloc(DeviceExtensionSize
, TAG_SCSI_DEVEXT
);
1142 if (!DeviceExtension
)
1144 return STATUS_NO_MEMORY
;
1146 RtlZeroMemory(DeviceExtension
, DeviceExtensionSize
);
1147 DeviceExtension
->InterruptFlags
= SCSI_PORT_NEXT_REQUEST_READY
;
1148 DeviceExtension
->HwInitialize
= HwInitializationData
->HwInitialize
;
1149 DeviceExtension
->HwStartIo
= HwInitializationData
->HwStartIo
;
1150 DeviceExtension
->HwInterrupt
= HwInitializationData
->HwInterrupt
;
1151 DeviceExtension
->HwResetBus
= HwInitializationData
->HwResetBus
;
1152 DeviceExtension
->MiniPortDeviceExtension
= (PVOID
)(DeviceExtension
+ 1);
1154 Status
= SpiCreatePortConfig(DeviceExtension
,
1155 HwInitializationData
,
1158 if (Status
!= STATUS_SUCCESS
)
1160 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1164 PortConfig
.NumberOfAccessRanges
= HwInitializationData
->NumberOfAccessRanges
;
1165 PortConfig
.AccessRanges
= FrLdrTempAlloc(sizeof(ACCESS_RANGE
) * HwInitializationData
->NumberOfAccessRanges
,
1166 TAG_SCSI_ACCESS_RANGES
);
1167 if (!PortConfig
.AccessRanges
)
1169 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1170 return STATUS_NO_MEMORY
;
1172 RtlZeroMemory(PortConfig
.AccessRanges
, sizeof(ACCESS_RANGE
) * HwInitializationData
->NumberOfAccessRanges
);
1174 /* Search for matching PCI device */
1175 if ((HwInitializationData
->AdapterInterfaceType
== PCIBus
) &&
1176 (HwInitializationData
->VendorIdLength
> 0) &&
1177 (HwInitializationData
->VendorId
!= NULL
) &&
1178 (HwInitializationData
->DeviceIdLength
> 0) &&
1179 (HwInitializationData
->DeviceId
!= NULL
))
1181 PortConfig
.BusInterruptLevel
= 0;
1183 /* Get PCI device data */
1184 TRACE("VendorId '%.*s' DeviceId '%.*s'\n",
1185 HwInitializationData
->VendorIdLength
,
1186 HwInitializationData
->VendorId
,
1187 HwInitializationData
->DeviceIdLength
,
1188 HwInitializationData
->DeviceId
);
1190 if (!SpiGetPciConfigData(HwInitializationData
,
1195 /* Continue to the next bus, nothing here */
1196 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1197 return STATUS_INTERNAL_ERROR
;
1200 if (!PortConfig
.BusInterruptLevel
)
1202 /* Bypass this slot, because no interrupt was assigned */
1203 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1204 return STATUS_INTERNAL_ERROR
;
1208 if (HwInitializationData
->HwFindAdapter(
1209 DeviceExtension
->MiniPortDeviceExtension
,
1214 &Again
) != SP_RETURN_FOUND
)
1216 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1217 return STATUS_INTERNAL_ERROR
;
1220 /* Copy all stuff which we ever need from PortConfig to the DeviceExtension */
1221 if (PortConfig
.MaximumNumberOfTargets
> SCSI_MAXIMUM_TARGETS_PER_BUS
)
1222 DeviceExtension
->MaxTargedIds
= SCSI_MAXIMUM_TARGETS_PER_BUS
;
1224 DeviceExtension
->MaxTargedIds
= PortConfig
.MaximumNumberOfTargets
;
1226 DeviceExtension
->BusNum
= PortConfig
.SystemIoBusNumber
;
1228 TRACE("Adapter found: buses = %d, targets = %d\n",
1229 PortConfig
.NumberOfBuses
, DeviceExtension
->MaxTargedIds
);
1231 /* Initialize adapter */
1232 if (!DeviceExtension
->HwInitialize(DeviceExtension
->MiniPortDeviceExtension
))
1234 FrLdrTempFree(DeviceExtension
, TAG_SCSI_DEVEXT
);
1235 return STATUS_INTERNAL_ERROR
;
1239 for (ScsiBus
= 0; ScsiBus
< PortConfig
.NumberOfBuses
; ScsiBus
++)
1241 SpiScanAdapter(DeviceExtension
, PortConfig
.SystemIoBusNumber
, ScsiBus
);
1242 PortConfig
.SystemIoBusNumber
++;
1245 FirstConfigCall
= FALSE
;
1252 return STATUS_SUCCESS
;
1257 ScsiPortIoMapTransfer(
1258 IN PVOID HwDeviceExtension
,
1259 IN PSCSI_REQUEST_BLOCK Srb
,
1260 IN PVOID LogicalAddress
,
1270 IN PVOID HwDeviceExtension
,
1271 IN PSCSI_REQUEST_BLOCK Srb OPTIONAL
,
1285 IN PVOID WriteBuffer
,
1286 IN PVOID ReadBuffer
,
1289 RtlMoveMemory(WriteBuffer
, ReadBuffer
, Length
);
1294 ScsiPortNotification(
1295 IN SCSI_NOTIFICATION_TYPE NotificationType
,
1296 IN PVOID HwDeviceExtension
,
1299 PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
;
1300 PSCSI_REQUEST_BLOCK Srb
;
1303 DeviceExtension
= ((PSCSI_PORT_DEVICE_EXTENSION
)HwDeviceExtension
) - 1;
1305 va_start(ap
, HwDeviceExtension
);
1307 switch (NotificationType
)
1309 case RequestComplete
:
1310 /* Mask the SRB as completed */
1311 Srb
= va_arg(ap
, PSCSI_REQUEST_BLOCK
);
1312 Srb
->SrbFlags
&= ~SRB_FLAGS_IS_ACTIVE
;
1316 /* Say that device is ready */
1317 DeviceExtension
->InterruptFlags
|= SCSI_PORT_NEXT_REQUEST_READY
;
1330 ScsiPortReadPortBufferUchar(
1335 __inbytestring(H2I(Port
), Buffer
, Count
);
1340 ScsiPortReadPortBufferUlong(
1345 __indwordstring(H2I(Port
), Buffer
, Count
);
1350 ScsiPortReadPortBufferUshort(
1355 __inwordstring(H2I(Port
), Buffer
, Count
);
1360 ScsiPortReadPortUchar(
1363 TRACE("ScsiPortReadPortUchar(%p)\n", Port
);
1365 return READ_PORT_UCHAR(Port
);
1370 ScsiPortReadPortUlong(
1373 return READ_PORT_ULONG(Port
);
1378 ScsiPortReadPortUshort(
1381 return READ_PORT_USHORT(Port
);
1386 ScsiPortReadRegisterBufferUchar(
1397 ScsiPortReadRegisterBufferUlong(
1408 ScsiPortReadRegisterBufferUshort(
1409 IN PUSHORT Register
,
1419 ScsiPortReadRegisterUchar(
1422 return READ_REGISTER_UCHAR(Register
);
1427 ScsiPortReadRegisterUlong(
1430 return READ_REGISTER_ULONG(Register
);
1435 ScsiPortReadRegisterUshort(
1436 IN PUSHORT Register
)
1438 return READ_REGISTER_USHORT(Register
);
1443 ScsiPortSetBusDataByOffset(
1444 IN PVOID DeviceExtension
,
1445 IN ULONG BusDataType
,
1446 IN ULONG SystemIoBusNumber
,
1447 IN ULONG SlotNumber
,
1459 ScsiPortStallExecution(
1462 KeStallExecutionProcessor(Delay
);
1467 ScsiPortValidateRange(
1468 IN PVOID HwDeviceExtension
,
1469 IN INTERFACE_TYPE BusType
,
1470 IN ULONG SystemIoBusNumber
,
1471 IN SCSI_PHYSICAL_ADDRESS IoAddress
,
1472 IN ULONG NumberOfBytes
,
1473 IN BOOLEAN InIoSpace
)
1487 ScsiPortWritePortBufferUchar(
1492 __outbytestring(H2I(Port
), Buffer
, Count
);
1497 ScsiPortWritePortBufferUlong(
1502 __outdwordstring(H2I(Port
), Buffer
, Count
);
1507 ScsiPortWritePortBufferUshort(
1512 __outwordstring(H2I(Port
), Buffer
, Count
);
1517 ScsiPortWritePortUchar(
1521 WRITE_PORT_UCHAR(Port
, Value
);
1526 ScsiPortWritePortUlong(
1530 WRITE_PORT_ULONG(Port
, Value
);
1535 ScsiPortWritePortUshort(
1539 WRITE_PORT_USHORT(Port
, Value
);
1544 ScsiPortWriteRegisterBufferUchar(
1555 ScsiPortWriteRegisterBufferUlong(
1566 ScsiPortWriteRegisterBufferUshort(
1567 IN PUSHORT Register
,
1577 ScsiPortWriteRegisterUchar(
1581 WRITE_REGISTER_UCHAR(Register
, Value
);
1586 ScsiPortWriteRegisterUlong(
1590 WRITE_REGISTER_ULONG(Register
, Value
);
1595 ScsiPortWriteRegisterUshort(
1596 IN PUSHORT Register
,
1599 WRITE_REGISTER_USHORT(Register
, Value
);
1602 extern char __ImageBase
;
1605 LoadBootDeviceDriver(VOID
)
1607 PIMAGE_NT_HEADERS NtHeaders
;
1608 LIST_ENTRY ModuleListHead
;
1609 PIMAGE_IMPORT_DESCRIPTOR ImportTable
;
1610 ULONG ImportTableSize
;
1611 PLDR_DATA_TABLE_ENTRY BootDdDTE
, FreeldrDTE
;
1612 CHAR NtBootDdPath
[MAX_PATH
];
1613 PVOID ImageBase
= NULL
;
1614 ULONG (NTAPI
*EntryPoint
)(IN PVOID DriverObject
, IN PVOID RegistryPath
);
1617 // FIXME: Must be done *INSIDE* the HAL!
1619 HalpInitializePciStubs();
1620 HalpInitBusHandler();
1623 /* Initialize the loaded module list */
1624 InitializeListHead(&ModuleListHead
);
1626 /* Create full ntbootdd.sys path */
1627 strcpy(NtBootDdPath
, FrLdrBootPath
);
1628 strcat(NtBootDdPath
, "\\NTBOOTDD.SYS");
1631 Success
= WinLdrLoadImage(NtBootDdPath
, LoaderBootDriver
, &ImageBase
);
1634 /* That's OK. File simply doesn't exist */
1638 /* Allocate a DTE for ntbootdd */
1639 Success
= WinLdrAllocateDataTableEntry(&ModuleListHead
, "ntbootdd.sys",
1640 "NTBOOTDD.SYS", ImageBase
, &BootDdDTE
);
1644 /* Add the PE part of freeldr.sys to the list of loaded executables, it
1645 contains ScsiPort* exports, imported by ntbootdd.sys */
1646 Success
= WinLdrAllocateDataTableEntry(&ModuleListHead
, "scsiport.sys",
1647 "FREELDR.SYS", &__ImageBase
, &FreeldrDTE
);
1650 RemoveEntryList(&BootDdDTE
->InLoadOrderLinks
);
1655 Success
= WinLdrScanImportDescriptorTable(&ModuleListHead
, "", BootDdDTE
);
1657 /* Now unlinkt the DTEs, they won't be valid later */
1658 RemoveEntryList(&BootDdDTE
->InLoadOrderLinks
);
1659 RemoveEntryList(&FreeldrDTE
->InLoadOrderLinks
);
1664 /* Change imports to PA */
1665 ImportTable
= (PIMAGE_IMPORT_DESCRIPTOR
)RtlImageDirectoryEntryToData(VaToPa(BootDdDTE
->DllBase
),
1666 TRUE
, IMAGE_DIRECTORY_ENTRY_IMPORT
, &ImportTableSize
);
1667 for (;(ImportTable
->Name
!= 0) && (ImportTable
->FirstThunk
!= 0);ImportTable
++)
1669 PIMAGE_THUNK_DATA ThunkData
= (PIMAGE_THUNK_DATA
)VaToPa(RVA(BootDdDTE
->DllBase
, ImportTable
->FirstThunk
));
1671 while (((PIMAGE_THUNK_DATA
)ThunkData
)->u1
.AddressOfData
!= 0)
1673 ThunkData
->u1
.Function
= (ULONG
)VaToPa((PVOID
)ThunkData
->u1
.Function
);
1678 /* Relocate image to PA */
1679 NtHeaders
= RtlImageNtHeader(VaToPa(BootDdDTE
->DllBase
));
1682 Success
= (BOOLEAN
)LdrRelocateImageWithBias(VaToPa(BootDdDTE
->DllBase
),
1683 NtHeaders
->OptionalHeader
.ImageBase
- (ULONG_PTR
)BootDdDTE
->DllBase
,
1686 TRUE
, /* in case of conflict still return success */
1691 /* Call the entrypoint */
1692 EntryPoint
= VaToPa(BootDdDTE
->EntryPoint
);
1693 (*EntryPoint
)(NULL
, NULL
);