ReactOS  0.4.15-dev-3187-ge372f2b
scsiport.c
Go to the documentation of this file.
1 /*
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>
7  */
8 
9 /* INCLUDES *******************************************************************/
10 
11 #include <freeldr.h>
12 
13 #include <debug.h>
14 DBG_DEFAULT_CHANNEL(SCSIPORT);
15 
16 #define _SCSIPORT_
17 
18 #include <ntddk.h>
19 #include <srb.h>
20 #include <scsi.h>
21 #include <ntddscsi.h>
22 #include <ntddstor.h>
23 #include <ntdddisk.h>
24 #include <stdio.h>
25 #include <stdarg.h>
26 
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
53 
54 #define SCSI_PORT_NEXT_REQUEST_READY 0x0008
55 
56 #define TAG_SCSI_DEVEXT 'DscS'
57 #define TAG_SCSI_ACCESS_RANGES 'AscS'
58 
59 /* GLOBALS ********************************************************************/
60 
61 #ifdef _M_IX86
64 #endif
65 
66 typedef struct
67 {
69 
72 
74 
75  /* SRB extension stuff */
78 
80 
85 
86  /* DMA related stuff */
88 
90 
93 
94 typedef struct tagDISKCONTEXT
95 {
96  /* Device ID */
101 
102  /* Device characteristics */
107 } DISKCONTEXT;
108 
110 
111 /* FUNCTIONS ******************************************************************/
112 
113 ULONG
115  IN ULONG Value)
116 {
117  FOUR_BYTE Dest;
119 
120  Dest.Byte0 = Source->Byte3;
121  Dest.Byte1 = Source->Byte2;
122  Dest.Byte2 = Source->Byte1;
123  Dest.Byte3 = Source->Byte0;
124 
125  return Dest.AsULong;
126 }
127 
128 static
129 BOOLEAN
131  IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
133 {
134  BOOLEAN ret;
135 
137 
138  /* HACK: handle lack of interrupts */
139  while (!(DeviceExtension->InterruptFlags & SCSI_PORT_NEXT_REQUEST_READY))
140  {
141  KeStallExecutionProcessor(100 * 1000);
142  if (!DeviceExtension->HwInterrupt(DeviceExtension->MiniPortDeviceExtension))
143  {
144  ExFreePool(Srb);
145  return FALSE;
146  }
147  }
148 
149  DeviceExtension->InterruptFlags &= ~SCSI_PORT_NEXT_REQUEST_READY;
151 
152  if (!DeviceExtension->HwStartIo(
153  DeviceExtension->MiniPortDeviceExtension,
154  Srb))
155  {
156  ExFreePool(Srb);
157  return FALSE;
158  }
159 
160  /* HACK: handle lack of interrupts */
161  while (Srb->SrbFlags & SRB_FLAGS_IS_ACTIVE)
162  {
163  KeStallExecutionProcessor(100 * 1000);
164  if (!DeviceExtension->HwInterrupt(DeviceExtension->MiniPortDeviceExtension))
165  {
166  ExFreePool(Srb);
167  return FALSE;
168  }
169  }
170 
172  ExFreePool(Srb);
173 
174  return ret;
175 }
176 
177 static ARC_STATUS DiskClose(ULONG FileId)
178 {
181  return ESUCCESS;
182 }
183 
185 {
187 
189 
190  /*
191  * The ARC specification mentions that for partitions, StartingAddress and
192  * EndingAddress are the start and end positions of the partition in terms
193  * of byte offsets from the start of the disk.
194  * CurrentAddress is the current offset into (i.e. relative to) the partition.
195  */
196  Information->StartingAddress.QuadPart = Context->SectorOffset * Context->SectorSize;
197  Information->EndingAddress.QuadPart = (Context->SectorOffset + Context->SectorCount) * Context->SectorSize;
198  Information->CurrentAddress.QuadPart = Context->SectorNumber * Context->SectorSize;
199 
200  return ESUCCESS;
201 }
202 
203 static ARC_STATUS DiskOpen(CHAR* Path, OPENMODE OpenMode, ULONG* FileId)
204 {
206  PCDB Cdb;
208 
210  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
211  ULONG ScsiBus, PathId, TargetId, Lun, Partition, PathSyntax;
215 
216  /* Parse ARC path */
217  if (!DissectArcPath2(Path, &ScsiBus, &TargetId, &Lun, &Partition, &PathSyntax))
218  return EINVAL;
219  if (PathSyntax != 0) /* scsi() format */
220  return EINVAL;
221  DeviceExtension = ScsiDeviceExtensions[ScsiBus];
222  PathId = ScsiBus - DeviceExtension->BusNum;
223 
224  /* Get disk capacity and sector size */
226  if (!Srb)
227  return ENOMEM;
229  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
231  Srb->PathId = (UCHAR)PathId;
233  Srb->Lun = (UCHAR)Lun;
234  Srb->CdbLength = 10;
237  Srb->TimeOutValue = 5; /* in seconds */
239  Cdb = (PCDB)Srb->Cdb;
240  Cdb->CDB10.OperationCode = SCSIOP_READ_CAPACITY;
241  if (!SpiSendSynchronousSrb(DeviceExtension, Srb))
242  {
243  return EIO;
244  }
245 
246  /* Transform result to host endianness */
249 
250  if (Partition != 0)
251  {
252  /* Need to offset start of disk and length */
254  return EIO;
255  }
256 
258  if (!Context)
259  return ENOMEM;
260  Context->DeviceExtension = DeviceExtension;
261  Context->PathId = (UCHAR)PathId;
262  Context->TargetId = (UCHAR)TargetId;
263  Context->Lun = (UCHAR)Lun;
264  Context->SectorSize = SectorSize;
265  Context->SectorOffset = SectorOffset;
266  Context->SectorCount = SectorCount;
267  Context->SectorNumber = 0;
268  FsSetDeviceSpecific(*FileId, Context);
269 
270  return ESUCCESS;
271 }
272 
274 {
277  PCDB Cdb;
278  ULONG FullSectors, NbSectors;
279  ULONG Lba;
280 
281  *Count = 0;
282 
283  if (N == 0)
284  return ESUCCESS;
285 
286  FullSectors = N / Context->SectorSize;
287  NbSectors = (N + Context->SectorSize - 1) / Context->SectorSize;
288  if (Context->SectorNumber + NbSectors >= Context->SectorCount)
289  return EINVAL;
290  if (FullSectors > 0xffff)
291  return EINVAL;
292 
293  /* Read full sectors */
294  ASSERT(Context->SectorNumber < 0xFFFFFFFF);
295  Lba = (ULONG)(Context->SectorOffset + Context->SectorNumber);
296  if (FullSectors > 0)
297  {
299  if (!Srb)
300  return ENOMEM;
301 
303  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
305  Srb->PathId = Context->PathId;
306  Srb->TargetId = Context->TargetId;
307  Srb->Lun = Context->Lun;
308  Srb->CdbLength = 10;
310  Srb->DataTransferLength = FullSectors * Context->SectorSize;
311  Srb->TimeOutValue = 5; /* in seconds */
312  Srb->DataBuffer = Buffer;
313  Cdb = (PCDB)Srb->Cdb;
314  Cdb->CDB10.OperationCode = SCSIOP_READ;
315  Cdb->CDB10.LogicalUnitNumber = Srb->Lun;
316  Cdb->CDB10.LogicalBlockByte0 = (Lba >> 24) & 0xff;
317  Cdb->CDB10.LogicalBlockByte1 = (Lba >> 16) & 0xff;
318  Cdb->CDB10.LogicalBlockByte2 = (Lba >> 8) & 0xff;
319  Cdb->CDB10.LogicalBlockByte3 = Lba & 0xff;
320  Cdb->CDB10.TransferBlocksMsb = (FullSectors >> 8) & 0xff;
321  Cdb->CDB10.TransferBlocksLsb = FullSectors & 0xff;
322  if (!SpiSendSynchronousSrb(Context->DeviceExtension, Srb))
323  {
324  return EIO;
325  }
326  Buffer = (PUCHAR)Buffer + FullSectors * Context->SectorSize;
327  N -= FullSectors * Context->SectorSize;
328  *Count += FullSectors * Context->SectorSize;
329  Context->SectorNumber += FullSectors;
330  Lba += FullSectors;
331  }
332 
333  /* Read incomplete last sector */
334  if (N > 0)
335  {
336  PUCHAR Sector;
337 
338  Sector = ExAllocatePool(PagedPool, Context->SectorSize);
339  if (!Sector)
340  return ENOMEM;
341 
343  if (!Srb)
344  {
345  ExFreePool(Sector);
346  return ENOMEM;
347  }
348 
350  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
352  Srb->PathId = Context->PathId;
353  Srb->TargetId = Context->TargetId;
354  Srb->Lun = Context->Lun;
355  Srb->CdbLength = 10;
357  Srb->DataTransferLength = Context->SectorSize;
358  Srb->TimeOutValue = 5; /* in seconds */
359  Srb->DataBuffer = Sector;
360  Cdb = (PCDB)Srb->Cdb;
361  Cdb->CDB10.OperationCode = SCSIOP_READ;
362  Cdb->CDB10.LogicalUnitNumber = Srb->Lun;
363  Cdb->CDB10.LogicalBlockByte0 = (Lba >> 24) & 0xff;
364  Cdb->CDB10.LogicalBlockByte1 = (Lba >> 16) & 0xff;
365  Cdb->CDB10.LogicalBlockByte2 = (Lba >> 8) & 0xff;
366  Cdb->CDB10.LogicalBlockByte3 = Lba & 0xff;
367  Cdb->CDB10.TransferBlocksMsb = 0;
368  Cdb->CDB10.TransferBlocksLsb = 1;
369  if (!SpiSendSynchronousSrb(Context->DeviceExtension, Srb))
370  {
371  ExFreePool(Sector);
372  return EIO;
373  }
374  RtlCopyMemory(Buffer, Sector, N);
375  *Count += N;
376  /* Context->SectorNumber remains untouched (incomplete sector read) */
377  ExFreePool(Sector);
378  }
379 
380  return ESUCCESS;
381 }
382 
384 {
386  LARGE_INTEGER NewPosition = *Position;
387 
388  switch (SeekMode)
389  {
390  case SeekAbsolute:
391  break;
392  case SeekRelative:
393  NewPosition.QuadPart += (Context->SectorNumber * Context->SectorSize);
394  break;
395  default:
396  ASSERT(FALSE);
397  return EINVAL;
398  }
399 
400  if (NewPosition.QuadPart & (Context->SectorSize - 1))
401  return EINVAL;
402 
403  /* Convert in number of sectors */
404  NewPosition.QuadPart /= Context->SectorSize;
405  if (NewPosition.QuadPart >= Context->SectorCount)
406  return EINVAL;
407 
408  Context->SectorNumber = NewPosition.QuadPart;
409  return ESUCCESS;
410 }
411 
412 static const DEVVTBL DiskVtbl =
413 {
414  DiskClose,
416  DiskOpen,
417  DiskRead,
418  DiskSeek,
419 };
420 
421 static
422 NTSTATUS
424  IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
425  IN PHW_INITIALIZATION_DATA HwInitData,
427  IN BOOLEAN ZeroStruct)
428 {
429  ULONG Bus;
430 
431  /* Zero out the struct if told so */
432  if (ZeroStruct)
433  {
434  /* First zero the portconfig */
435  RtlZeroMemory(ConfigInfo, sizeof(PORT_CONFIGURATION_INFORMATION));
436 
437  /* Initialize the struct */
438  ConfigInfo->Length = sizeof(PORT_CONFIGURATION_INFORMATION);
439  ConfigInfo->AdapterInterfaceType = HwInitData->AdapterInterfaceType;
440  ConfigInfo->InterruptMode = Latched;
441  ConfigInfo->DmaChannel = SP_UNINITIALIZED_VALUE;
442  ConfigInfo->DmaPort = SP_UNINITIALIZED_VALUE;
443  ConfigInfo->MaximumTransferLength = SP_UNINITIALIZED_VALUE;
444  ConfigInfo->MaximumNumberOfTargets = SCSI_MAXIMUM_TARGETS_PER_BUS;
445 
446  /* Store parameters */
447  ConfigInfo->NeedPhysicalAddresses = HwInitData->NeedPhysicalAddresses;
448  ConfigInfo->MapBuffers = HwInitData->MapBuffers;
449  ConfigInfo->AutoRequestSense = HwInitData->AutoRequestSense;
450  ConfigInfo->ReceiveEvent = HwInitData->ReceiveEvent;
451  ConfigInfo->TaggedQueuing = HwInitData->TaggedQueuing;
452  ConfigInfo->MultipleRequestPerLu = HwInitData->MultipleRequestPerLu;
453 
454  /* Get the disk usage */
455  ConfigInfo->AtdiskPrimaryClaimed = FALSE; // FIXME
456  ConfigInfo->AtdiskSecondaryClaimed = FALSE; // FIXME
457 
458  /* Initiator bus id is not set */
459  for (Bus = 0; Bus < 8; Bus++)
460  ConfigInfo->InitiatorBusId[Bus] = (CCHAR)SP_UNINITIALIZED_VALUE;
461  }
462 
463  ConfigInfo->NumberOfPhysicalBreaks = 17;
464 
465  return STATUS_SUCCESS;
466 }
467 
468 VOID
469 __cdecl
471  IN ULONG DebugPrintLevel,
472  IN PCCHAR DebugMessage,
473  IN ...)
474 {
475  va_list ap;
476  CHAR Buffer[512];
477  ULONG Length;
478 
479  if (DebugPrintLevel > 10)
480  return;
481 
482  va_start(ap, DebugMessage);
483 
484  /* Construct a string */
485  Length = _vsnprintf(Buffer, 512, DebugMessage, ap);
486 
487  /* Check if we went past the buffer */
488  if (Length == MAXULONG)
489  {
490  /* Terminate it if we went over-board */
491  Buffer[sizeof(Buffer) - 1] = '\0';
492 
493  /* Put maximum */
494  Length = sizeof(Buffer);
495  }
496 
497  /* Print the message */
498  TRACE("%s", Buffer);
499 
500  /* Cleanup */
501  va_end(ap);
502 }
503 
504 VOID
505 NTAPI
507  IN PVOID HwDeviceExtension,
508  IN UCHAR PathId,
509  IN UCHAR TargetId,
510  IN UCHAR Lun,
511  IN UCHAR SrbStatus)
512 {
513  // FIXME
515 }
516 
517 #undef ScsiPortConvertPhysicalAddressToUlong
518 ULONG
519 NTAPI
522 {
523  return Address.LowPart;
524 }
525 
527 NTAPI
529  IN ULONG_PTR UlongAddress)
530 {
532 
533  Address.QuadPart = UlongAddress;
534  return Address;
535 }
536 
537 VOID
538 NTAPI
540  IN PVOID DeviceExtension)
541 {
542  // FIXME
544 }
545 
546 VOID
547 NTAPI
549  IN PVOID HwDeviceExtension,
550  IN PVOID MappedAddress)
551 {
552  // Nothing to do
553 }
554 
555 ULONG
556 NTAPI
558  IN PVOID DeviceExtension,
559  IN ULONG BusDataType,
560  IN ULONG SystemIoBusNumber,
562  IN PVOID Buffer,
563  IN ULONG Length)
564 {
565  return HalGetBusDataByOffset(BusDataType, SystemIoBusNumber, SlotNumber, Buffer, 0, Length);
566 }
567 
568 PVOID
569 NTAPI
571  IN PVOID HwDeviceExtension,
573  IN ULONG SystemIoBusNumber,
574  IN SCSI_PHYSICAL_ADDRESS IoAddress,
576  IN BOOLEAN InIoSpace)
577 {
580 
581  AddressSpace = (ULONG)InIoSpace;
583  SystemIoBusNumber,
584  IoAddress,
585  &AddressSpace,
587  {
588  return NULL;
589  }
590 
591  /* I/O space */
592  if (AddressSpace != 0)
593  return (PVOID)TranslatedAddress.u.LowPart;
594 
595  // FIXME
597  return (PVOID)IoAddress.LowPart;
598 }
599 
600 PVOID
601 NTAPI
603  IN PVOID HwDeviceExtension,
604  IN UCHAR PathId,
605  IN UCHAR TargetId,
606  IN UCHAR Lun)
607 {
608  // FIXME
610  return NULL;
611 }
612 
614 NTAPI
616  IN PVOID HwDeviceExtension,
619  OUT ULONG *Length)
620 {
621  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
623  ULONG BufferLength = 0;
624  ULONG Offset;
625 
626  TRACE("ScsiPortGetPhysicalAddress(%p %p %p %p)\n",
627  HwDeviceExtension, Srb, VirtualAddress, Length);
628 
629  DeviceExtension = ((PSCSI_PORT_DEVICE_EXTENSION)HwDeviceExtension) - 1;
630 
631  if (Srb == NULL || Srb->SenseInfoBuffer == VirtualAddress)
632  {
633  /* Simply look it up in the allocated common buffer */
634  Offset = (PUCHAR)VirtualAddress - (PUCHAR)DeviceExtension->SrbExtensionBuffer;
635 
636  BufferLength = DeviceExtension->CommonBufferLength - Offset;
638  }
639  else
640  {
641  /* Nothing */
643  }
644 
645  *Length = BufferLength;
646  return PhysicalAddress;
647 }
648 
650 NTAPI
652  IN PVOID DeviceExtension,
653  IN UCHAR PathId,
654  IN UCHAR TargetId,
655  IN UCHAR Lun,
656  IN LONG QueueTag)
657 {
658  // FIXME
660  return NULL;
661 }
662 
663 static
664 NTSTATUS
666  IN OUT PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
667  IN ULONG NonCachedSize)
668 {
670  ULONG CommonBufferLength, BufSize;
671 
672  /* If size is 0, set it to 16 */
673  if (!DeviceExtension->SrbExtensionSize)
674  DeviceExtension->SrbExtensionSize = 16;
675 
676  /* Calculate size */
677  BufSize = DeviceExtension->SrbExtensionSize;
678 
679  /* Round it */
680  BufSize = (BufSize + sizeof(LONGLONG) - 1) & ~(sizeof(LONGLONG) - 1);
681 
682  /* Sum up into the total common buffer length, and round it to page size */
683  CommonBufferLength =
684  ROUND_TO_PAGES(NonCachedSize);
685 
686  /* Allocate it */
687  if (!DeviceExtension->AdapterObject)
688  {
689  /* From nonpaged pool if there is no DMA */
690  CommonBuffer = ExAllocatePool(NonPagedPool, CommonBufferLength);
691  }
692  else
693  {
694  /* Perform a full request since we have a DMA adapter*/
696  CommonBuffer = NULL;
697  }
698 
699  /* Fail in case of error */
700  if (!CommonBuffer)
702 
703  /* Zero it */
704  RtlZeroMemory(CommonBuffer, CommonBufferLength);
705 
706  /* Store its size in Device Extension */
707  DeviceExtension->CommonBufferLength = CommonBufferLength;
708 
709  /* SrbExtension buffer is located at the beginning of the buffer */
710  DeviceExtension->SrbExtensionBuffer = CommonBuffer;
711 
712  /* Non-cached extension buffer is located at the end of
713  the common buffer */
714  if (NonCachedSize)
715  {
716  CommonBufferLength -= NonCachedSize;
717  DeviceExtension->NonCachedExtension = (PUCHAR)CommonBuffer + CommonBufferLength;
718  }
719  else
720  {
721  DeviceExtension->NonCachedExtension = NULL;
722  }
723 
724  return STATUS_SUCCESS;
725 }
726 
727 PVOID
728 NTAPI
730  IN PVOID HwDeviceExtension,
733 {
734  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
736  ULONG MapRegistersCount;
738 
739  TRACE("ScsiPortGetUncachedExtension(%p %p %lu)\n",
740  HwDeviceExtension, ConfigInfo, NumberOfBytes);
741 
742  DeviceExtension = ((PSCSI_PORT_DEVICE_EXTENSION)HwDeviceExtension) - 1;
743 
744  /* Check for allocated common DMA buffer */
745  if (DeviceExtension->SrbExtensionBuffer != NULL)
746  {
747  return NULL;
748  }
749 
750  /* Check for DMA adapter object */
751  if (DeviceExtension->AdapterObject == NULL)
752  {
753  /* Initialize DMA adapter description */
755 
757  DeviceDescription.Master = ConfigInfo->Master;
758  DeviceDescription.ScatterGather = ConfigInfo->ScatterGather;
759  DeviceDescription.DemandMode = ConfigInfo->DemandMode;
760  DeviceDescription.Dma32BitAddresses = ConfigInfo->Dma32BitAddresses;
761  DeviceDescription.BusNumber = ConfigInfo->SystemIoBusNumber;
762  DeviceDescription.DmaChannel = ConfigInfo->DmaChannel;
763  DeviceDescription.InterfaceType = ConfigInfo->AdapterInterfaceType;
764  DeviceDescription.DmaWidth = ConfigInfo->DmaWidth;
765  DeviceDescription.DmaSpeed = ConfigInfo->DmaSpeed;
766  DeviceDescription.MaximumLength = ConfigInfo->MaximumTransferLength;
767  DeviceDescription.DmaPort = ConfigInfo->DmaPort;
768 
769  /* Get a DMA adapter object */
770 #if 0
771  DeviceExtension->AdapterObject =
772  HalGetAdapter(&DeviceDescription, &MapRegistersCount);
773 
774  /* Fail in case of error */
775  if (DeviceExtension->AdapterObject == NULL)
776  {
777  return NULL;
778  }
779 #else
780  MapRegistersCount = 0;
781 #endif
782 
783  /* Set number of physical breaks */
784  if (ConfigInfo->NumberOfPhysicalBreaks != 0 &&
785  MapRegistersCount > ConfigInfo->NumberOfPhysicalBreaks)
786  {
787  DeviceExtension->PortCapabilities.MaximumPhysicalPages =
788  ConfigInfo->NumberOfPhysicalBreaks;
789  }
790  else
791  {
792  DeviceExtension->PortCapabilities.MaximumPhysicalPages = MapRegistersCount;
793  }
794  }
795 
796  /* Update Srb extension size */
797  if (DeviceExtension->SrbExtensionSize != ConfigInfo->SrbExtensionSize)
798  DeviceExtension->SrbExtensionSize = ConfigInfo->SrbExtensionSize;
799 
800  /* Allocate a common DMA buffer */
801  Status = SpiAllocateCommonBuffer(DeviceExtension, NumberOfBytes);
802 
803  if (!NT_SUCCESS(Status))
804  {
805  TRACE("SpiAllocateCommonBuffer() failed with Status = 0x%08X!\n", Status);
806  return NULL;
807  }
808 
809  return DeviceExtension->NonCachedExtension;
810 }
811 
812 PVOID
813 NTAPI
815  IN PVOID HwDeviceExtension,
817 {
818  // FIXME
820  return NULL;
821 }
822 
823 static
824 VOID
826  IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
827  IN PCHAR ArcName,
828  IN ULONG ScsiBus,
829  IN ULONG TargetId,
830  IN ULONG Lun)
831 {
832  ULONG FileId, i;
834  NTSTATUS ret;
836  CHAR PartitionName[64];
837 
838  /* Register device with partition(0) suffix */
839  RtlStringCbPrintfA(PartitionName, sizeof(PartitionName), "%spartition(0)", ArcName);
840  FsRegisterDevice(PartitionName, &DiskVtbl);
841 
842  /* Read device partition table */
843  Status = ArcOpen(PartitionName, OpenReadOnly, &FileId);
844  if (Status == ESUCCESS)
845  {
846  ret = HALDISPATCH->HalIoReadPartitionTable((PDEVICE_OBJECT)FileId, 512, FALSE, &PartitionBuffer);
847  if (NT_SUCCESS(ret))
848  {
849  for (i = 0; i < PartitionBuffer->PartitionCount; i++)
850  {
851  if (PartitionBuffer->PartitionEntry[i].PartitionType != PARTITION_ENTRY_UNUSED)
852  {
853  RtlStringCbPrintfA(PartitionName,
854  sizeof(PartitionName),
855  "%spartition(%lu)",
856  ArcName,
857  PartitionBuffer->PartitionEntry[i].PartitionNumber);
858  FsRegisterDevice(PartitionName, &DiskVtbl);
859  }
860  }
862  }
863  ArcClose(FileId);
864  }
865 }
866 
867 static
868 VOID
870  IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension,
871  IN ULONG ScsiBus,
872  IN UCHAR PathId)
873 {
874  CHAR ArcName[64];
876  PCDB Cdb;
877  INQUIRYDATA InquiryBuffer;
878  UCHAR TargetId;
879  UCHAR Lun;
880 
881  if (!DeviceExtension->HwResetBus(DeviceExtension->MiniPortDeviceExtension, PathId))
882  {
883  return;
884  }
885 
886  /* Remember the extension */
887  ScsiDeviceExtensions[ScsiBus] = DeviceExtension;
888 
889  for (TargetId = 0; TargetId < DeviceExtension->MaxTargedIds; TargetId++)
890  {
891  Lun = 0;
892  do
893  {
894  TRACE("Scanning SCSI device %d.%d.%d\n",
895  ScsiBus, TargetId, Lun);
896 
898  if (!Srb)
899  break;
901  Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
903  Srb->PathId = PathId;
904  Srb->TargetId = TargetId;
905  Srb->Lun = Lun;
906  Srb->CdbLength = 6;
909  Srb->TimeOutValue = 5; /* in seconds */
910  Srb->DataBuffer = &InquiryBuffer;
911  Cdb = (PCDB)Srb->Cdb;
912  Cdb->CDB6INQUIRY.OperationCode = SCSIOP_INQUIRY;
913  Cdb->CDB6INQUIRY.LogicalUnitNumber = Srb->Lun;
914  Cdb->CDB6INQUIRY.AllocationLength = (UCHAR)Srb->DataTransferLength;
915  if (!SpiSendSynchronousSrb(DeviceExtension, Srb))
916  {
917  /* Don't check next LUNs */
918  break;
919  }
920 
921  /* Device exists, create its ARC name */
922  if (InquiryBuffer.RemovableMedia)
923  {
924  sprintf(ArcName, "scsi(%ld)cdrom(%d)fdisk(%d)",
925  ScsiBus, TargetId, Lun);
926  FsRegisterDevice(ArcName, &DiskVtbl);
927  }
928  else
929  {
930  sprintf(ArcName, "scsi(%ld)disk(%d)rdisk(%d)",
931  ScsiBus, TargetId, Lun);
932  /* Now, check if it has partitions */
933  SpiScanDevice(DeviceExtension, ArcName, PathId, TargetId, Lun);
934  }
935 
936  /* Check next LUN */
937  Lun++;
938  } while (Lun < SCSI_MAXIMUM_LOGICAL_UNITS);
939  }
940 }
941 
942 static
943 VOID
946  IN PCM_FULL_RESOURCE_DESCRIPTOR ResourceDescriptor,
948 {
949  PACCESS_RANGE AccessRange;
951  ULONG RangeNumber;
952  ULONG Index;
953 
954  RangeNumber = 0;
955 
956  /* Loop through all entries */
957  for (Index = 0; Index < ResourceDescriptor->PartialResourceList.Count; Index++)
958  {
959  PartialData = &ResourceDescriptor->PartialResourceList.PartialDescriptors[Index];
960 
961  switch (PartialData->Type)
962  {
963  case CmResourceTypePort:
964  /* Copy access ranges */
965  if (RangeNumber < HwInitializationData->NumberOfAccessRanges)
966  {
967  TRACE("Got port at 0x%I64x, len 0x%x\n",
968  PartialData->u.Port.Start.QuadPart, PartialData->u.Port.Length);
969  AccessRange = &((*(PortConfig->AccessRanges))[RangeNumber]);
970 
971  AccessRange->RangeStart = PartialData->u.Port.Start;
972  AccessRange->RangeLength = PartialData->u.Port.Length;
973 
974  AccessRange->RangeInMemory = FALSE;
975  RangeNumber++;
976  }
977  break;
978 
980  /* Copy access ranges */
981  if (RangeNumber < HwInitializationData->NumberOfAccessRanges)
982  {
983  TRACE("Got memory at 0x%I64x, len 0x%x\n",
984  PartialData->u.Memory.Start.QuadPart, PartialData->u.Memory.Length);
985  AccessRange = &((*(PortConfig->AccessRanges))[RangeNumber]);
986 
987  AccessRange->RangeStart = PartialData->u.Memory.Start;
988  AccessRange->RangeLength = PartialData->u.Memory.Length;
989 
990  AccessRange->RangeInMemory = TRUE;
991  RangeNumber++;
992  }
993  break;
994 
996  /* Copy interrupt data */
997  TRACE("Got interrupt level %d, vector %d\n",
998  PartialData->u.Interrupt.Level, PartialData->u.Interrupt.Vector);
999  PortConfig->BusInterruptLevel = PartialData->u.Interrupt.Level;
1000  PortConfig->BusInterruptVector = PartialData->u.Interrupt.Vector;
1001 
1002  /* Set interrupt mode accordingly to the resource */
1003  if (PartialData->Flags == CM_RESOURCE_INTERRUPT_LATCHED)
1004  {
1005  PortConfig->InterruptMode = Latched;
1006  }
1007  else if (PartialData->Flags == CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE)
1008  {
1009  PortConfig->InterruptMode = LevelSensitive;
1010  }
1011  break;
1012 
1013  case CmResourceTypeDma:
1014  TRACE("Got DMA channel %d, port %d\n",
1015  PartialData->u.Dma.Channel, PartialData->u.Dma.Port);
1016  PortConfig->DmaChannel = PartialData->u.Dma.Channel;
1017  PortConfig->DmaPort = PartialData->u.Dma.Port;
1018  break;
1019  }
1020  }
1021 }
1022 
1023 static
1024 BOOLEAN
1028  IN ULONG BusNumber,
1029  IN OUT PPCI_SLOT_NUMBER NextSlotNumber)
1030 {
1031  PCI_COMMON_CONFIG PciConfig;
1033  ULONG DataSize;
1035  ULONG FunctionNumber;
1036  CHAR VendorIdString[8];
1037  CHAR DeviceIdString[8];
1039  NTSTATUS Status;
1040 
1041  SlotNumber.u.AsULONG = 0;
1042 
1043  /* Loop through all devices */
1044  for (DeviceNumber = NextSlotNumber->u.bits.DeviceNumber; DeviceNumber < PCI_MAX_DEVICES; DeviceNumber++)
1045  {
1046  SlotNumber.u.bits.DeviceNumber = DeviceNumber;
1047 
1048  /* Loop through all functions */
1049  for (FunctionNumber = NextSlotNumber->u.bits.FunctionNumber; FunctionNumber < PCI_MAX_FUNCTION; FunctionNumber++)
1050  {
1051  SlotNumber.u.bits.FunctionNumber = FunctionNumber;
1052 
1053  /* Get PCI config bytes */
1056  BusNumber,
1057  SlotNumber.u.AsULONG,
1058  &PciConfig,
1059  0,
1060  sizeof(ULONG));
1061 
1062  /* If result of HalGetBusData is 0, then the bus is wrong */
1063  if (DataSize == 0)
1064  return FALSE;
1065 
1066  /* If result is PCI_INVALID_VENDORID, then this device has no more
1067  "Functions" */
1068  if (PciConfig.VendorID == PCI_INVALID_VENDORID)
1069  break;
1070 
1071  sprintf(VendorIdString, "%04hx", PciConfig.VendorID);
1072  sprintf(DeviceIdString, "%04hx", PciConfig.DeviceID);
1073 
1074  if (_strnicmp(VendorIdString, HwInitializationData->VendorId, HwInitializationData->VendorIdLength) ||
1075  _strnicmp(DeviceIdString, HwInitializationData->DeviceId, HwInitializationData->DeviceIdLength))
1076  {
1077  /* It is not our device */
1078  continue;
1079  }
1080 
1081  TRACE( "Found device 0x%04hx 0x%04hx at %1lu %2lu %1lu\n",
1082  PciConfig.VendorID, PciConfig.DeviceID,
1083  BusNumber,
1084  SlotNumber.u.bits.DeviceNumber, SlotNumber.u.bits.FunctionNumber);
1085 
1087  NULL,
1088  NULL,
1089  NULL,
1090  PCIBus,
1091  BusNumber,
1092  SlotNumber.u.AsULONG,
1093  &ResourceList);
1094 
1095  if (!NT_SUCCESS(Status))
1096  break;
1097 
1098  /* Create configuration information */
1100  ResourceList->List,
1101  PortConfig);
1102 
1103  /* Free the resource list */
1105 
1106  /* Set dev & fn numbers */
1107  NextSlotNumber->u.bits.DeviceNumber = DeviceNumber;
1108  NextSlotNumber->u.bits.FunctionNumber = FunctionNumber + 1;
1109 
1110  /* Save the slot number */
1111  PortConfig->SlotNumber = SlotNumber.u.AsULONG;
1112 
1113  return TRUE;
1114  }
1115  NextSlotNumber->u.bits.FunctionNumber = 0;
1116  }
1117 
1118  NextSlotNumber->u.bits.DeviceNumber = 0;
1119 
1120  return FALSE;
1121 }
1122 
1123 ULONG
1124 NTAPI
1126  IN PVOID Argument1,
1127  IN PVOID Argument2,
1130 {
1131  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
1132  ULONG DeviceExtensionSize;
1133  PORT_CONFIGURATION_INFORMATION PortConfig;
1134  BOOLEAN Again;
1135  BOOLEAN FirstConfigCall = TRUE;
1137  UCHAR ScsiBus;
1138  NTSTATUS Status;
1139 
1140  if (HwInitializationData->HwInitializationDataSize != sizeof(HW_INITIALIZATION_DATA))
1141  {
1142  return STATUS_INVALID_PARAMETER;
1143  }
1144 
1145  /* Check params for validity */
1146  if ((HwInitializationData->HwInitialize == NULL) ||
1147  (HwInitializationData->HwStartIo == NULL) ||
1148  (HwInitializationData->HwInterrupt == NULL) ||
1149  (HwInitializationData->HwFindAdapter == NULL) ||
1150  (HwInitializationData->HwResetBus == NULL))
1151  {
1152  return STATUS_INVALID_PARAMETER;
1153  }
1154 
1155  /* Zero starting slot number */
1156  SlotNumber.u.AsULONG = 0;
1157 
1158  while (TRUE)
1159  {
1160  Again = FALSE;
1161 
1162  DeviceExtensionSize = sizeof(SCSI_PORT_DEVICE_EXTENSION) + HwInitializationData->DeviceExtensionSize;
1163  DeviceExtension = FrLdrTempAlloc(DeviceExtensionSize, TAG_SCSI_DEVEXT);
1164  if (!DeviceExtension)
1165  {
1166  return STATUS_NO_MEMORY;
1167  }
1168  RtlZeroMemory(DeviceExtension, DeviceExtensionSize);
1169  DeviceExtension->InterruptFlags = SCSI_PORT_NEXT_REQUEST_READY;
1170  DeviceExtension->HwInitialize = HwInitializationData->HwInitialize;
1171  DeviceExtension->HwStartIo = HwInitializationData->HwStartIo;
1172  DeviceExtension->HwInterrupt = HwInitializationData->HwInterrupt;
1173  DeviceExtension->HwResetBus = HwInitializationData->HwResetBus;
1174  DeviceExtension->MiniPortDeviceExtension = (PVOID)(DeviceExtension + 1);
1175 
1176  Status = SpiCreatePortConfig(DeviceExtension,
1178  &PortConfig,
1179  FirstConfigCall);
1180  if (Status != STATUS_SUCCESS)
1181  {
1182  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1183  return Status;
1184  }
1185 
1186  PortConfig.NumberOfAccessRanges = HwInitializationData->NumberOfAccessRanges;
1187  PortConfig.AccessRanges = FrLdrTempAlloc(sizeof(ACCESS_RANGE) * HwInitializationData->NumberOfAccessRanges,
1189  if (!PortConfig.AccessRanges)
1190  {
1191  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1192  return STATUS_NO_MEMORY;
1193  }
1194  RtlZeroMemory(PortConfig.AccessRanges, sizeof(ACCESS_RANGE) * HwInitializationData->NumberOfAccessRanges);
1195 
1196  /* Search for matching PCI device */
1197  if ((HwInitializationData->AdapterInterfaceType == PCIBus) &&
1198  (HwInitializationData->VendorIdLength > 0) &&
1199  (HwInitializationData->VendorId != NULL) &&
1200  (HwInitializationData->DeviceIdLength > 0) &&
1201  (HwInitializationData->DeviceId != NULL))
1202  {
1203  PortConfig.BusInterruptLevel = 0;
1204 
1205  /* Get PCI device data */
1206  TRACE("VendorId '%.*s' DeviceId '%.*s'\n",
1207  HwInitializationData->VendorIdLength,
1208  HwInitializationData->VendorId,
1209  HwInitializationData->DeviceIdLength,
1210  HwInitializationData->DeviceId);
1211 
1213  &PortConfig,
1214  0, /* FIXME */
1215  &SlotNumber))
1216  {
1217  /* Continue to the next bus, nothing here */
1218  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1219  return STATUS_INTERNAL_ERROR;
1220  }
1221 
1222  if (!PortConfig.BusInterruptLevel)
1223  {
1224  /* Bypass this slot, because no interrupt was assigned */
1225  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1226  return STATUS_INTERNAL_ERROR;
1227  }
1228  }
1229 
1230  if (HwInitializationData->HwFindAdapter(
1231  DeviceExtension->MiniPortDeviceExtension,
1232  HwContext,
1233  NULL,
1234  NULL,
1235  &PortConfig,
1236  &Again) != SP_RETURN_FOUND)
1237  {
1238  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1239  return STATUS_INTERNAL_ERROR;
1240  }
1241 
1242  /* Copy all stuff which we ever need from PortConfig to the DeviceExtension */
1244  DeviceExtension->MaxTargedIds = SCSI_MAXIMUM_TARGETS_PER_BUS;
1245  else
1246  DeviceExtension->MaxTargedIds = PortConfig.MaximumNumberOfTargets;
1247 
1248  DeviceExtension->BusNum = PortConfig.SystemIoBusNumber;
1249 
1250  TRACE("Adapter found: buses = %d, targets = %d\n",
1251  PortConfig.NumberOfBuses, DeviceExtension->MaxTargedIds);
1252 
1253  /* Initialize adapter */
1254  if (!DeviceExtension->HwInitialize(DeviceExtension->MiniPortDeviceExtension))
1255  {
1256  FrLdrTempFree(DeviceExtension, TAG_SCSI_DEVEXT);
1257  return STATUS_INTERNAL_ERROR;
1258  }
1259 
1260  /* Scan bus */
1261  for (ScsiBus = 0; ScsiBus < PortConfig.NumberOfBuses; ScsiBus++)
1262  {
1263  SpiScanAdapter(DeviceExtension, PortConfig.SystemIoBusNumber, ScsiBus);
1264  PortConfig.SystemIoBusNumber++;
1265  }
1266 
1267  FirstConfigCall = FALSE;
1268  if (!Again)
1269  {
1270  break;
1271  }
1272  }
1273 
1274  return STATUS_SUCCESS;
1275 }
1276 
1277 VOID
1278 NTAPI
1280  IN PVOID HwDeviceExtension,
1282  IN PVOID LogicalAddress,
1283  IN ULONG Length)
1284 {
1285  // FIXME
1286  UNIMPLEMENTED;
1287 }
1288 
1289 VOID
1290 NTAPI
1292  IN PVOID HwDeviceExtension,
1294  IN UCHAR PathId,
1295  IN UCHAR TargetId,
1296  IN UCHAR Lun,
1297  IN ULONG ErrorCode,
1298  IN ULONG UniqueId)
1299 {
1300  // FIXME
1301  UNIMPLEMENTED;
1302 }
1303 
1304 VOID
1305 NTAPI
1309  IN ULONG Length)
1310 {
1312 }
1313 
1314 VOID
1315 __cdecl
1318  IN PVOID HwDeviceExtension,
1319  IN ...)
1320 {
1321  PSCSI_PORT_DEVICE_EXTENSION DeviceExtension;
1323  va_list ap;
1324 
1325  DeviceExtension = ((PSCSI_PORT_DEVICE_EXTENSION)HwDeviceExtension) - 1;
1326 
1327  va_start(ap, HwDeviceExtension);
1328 
1329  switch (NotificationType)
1330  {
1331  case RequestComplete:
1332  /* Mask the SRB as completed */
1335  break;
1336 
1337  case NextRequest:
1338  /* Say that device is ready */
1339  DeviceExtension->InterruptFlags |= SCSI_PORT_NEXT_REQUEST_READY;
1340  break;
1341 
1342  default:
1343  // FIXME
1344  UNIMPLEMENTED;
1345  }
1346 
1347  va_end(ap);
1348 }
1349 
1350 VOID
1351 NTAPI
1353  IN PUCHAR Port,
1354  OUT PUCHAR Buffer,
1355  IN ULONG Count)
1356 {
1358 }
1359 
1360 VOID
1361 NTAPI
1363  IN PULONG Port,
1364  OUT PULONG Buffer,
1365  IN ULONG Count)
1366 {
1368 }
1369 
1370 VOID
1371 NTAPI
1373  IN PUSHORT Port,
1374  OUT PUSHORT Buffer,
1375  IN ULONG Count)
1376 {
1378 }
1379 
1380 UCHAR
1381 NTAPI
1383  IN PUCHAR Port)
1384 {
1385  TRACE("ScsiPortReadPortUchar(%p)\n", Port);
1386 
1387  return READ_PORT_UCHAR(Port);
1388 }
1389 
1390 ULONG
1391 NTAPI
1393  IN PULONG Port)
1394 {
1395  return READ_PORT_ULONG(Port);
1396 }
1397 
1398 USHORT
1399 NTAPI
1401  IN PUSHORT Port)
1402 {
1403  return READ_PORT_USHORT(Port);
1404 }
1405 
1406 VOID
1407 NTAPI
1409  IN PUCHAR Register,
1410  IN PUCHAR Buffer,
1411  IN ULONG Count)
1412 {
1413  // FIXME
1414  UNIMPLEMENTED;
1415 }
1416 
1417 VOID
1418 NTAPI
1420  IN PULONG Register,
1421  IN PULONG Buffer,
1422  IN ULONG Count)
1423 {
1424  // FIXME
1425  UNIMPLEMENTED;
1426 }
1427 
1428 VOID
1429 NTAPI
1431  IN PUSHORT Register,
1432  IN PUSHORT Buffer,
1433  IN ULONG Count)
1434 {
1435  // FIXME
1436  UNIMPLEMENTED;
1437 }
1438 
1439 UCHAR
1440 NTAPI
1442  IN PUCHAR Register)
1443 {
1444  return READ_REGISTER_UCHAR(Register);
1445 }
1446 
1447 ULONG
1448 NTAPI
1450  IN PULONG Register)
1451 {
1452  return READ_REGISTER_ULONG(Register);
1453 }
1454 
1455 USHORT
1456 NTAPI
1458  IN PUSHORT Register)
1459 {
1460  return READ_REGISTER_USHORT(Register);
1461 }
1462 
1463 ULONG
1464 NTAPI
1466  IN PVOID DeviceExtension,
1467  IN ULONG BusDataType,
1468  IN ULONG SystemIoBusNumber,
1470  IN PVOID Buffer,
1471  IN ULONG Offset,
1472  IN ULONG Length)
1473 {
1474  // FIXME
1475  UNIMPLEMENTED;
1476  return 0;
1477 }
1478 
1479 VOID
1480 NTAPI
1482  IN ULONG Delay)
1483 {
1485 }
1486 
1487 BOOLEAN
1488 NTAPI
1490  IN PVOID HwDeviceExtension,
1492  IN ULONG SystemIoBusNumber,
1493  IN SCSI_PHYSICAL_ADDRESS IoAddress,
1495  IN BOOLEAN InIoSpace)
1496 {
1497  // FIXME
1498  UNIMPLEMENTED;
1499  return TRUE;
1500 }
1501 
1502 #if 0
1503 // ScsiPortWmi*
1504 #endif
1505 
1506 
1507 VOID
1508 NTAPI
1510  IN PUCHAR Port,
1511  IN PUCHAR Buffer,
1512  IN ULONG Count)
1513 {
1515 }
1516 
1517 VOID
1518 NTAPI
1520  IN PULONG Port,
1521  IN PULONG Buffer,
1522  IN ULONG Count)
1523 {
1525 }
1526 
1527 VOID
1528 NTAPI
1530  IN PUSHORT Port,
1531  IN PUSHORT Buffer,
1532  IN ULONG Count)
1533 {
1535 }
1536 
1537 VOID
1538 NTAPI
1540  IN PUCHAR Port,
1541  IN UCHAR Value)
1542 {
1544 }
1545 
1546 VOID
1547 NTAPI
1549  IN PULONG Port,
1550  IN ULONG Value)
1551 {
1553 }
1554 
1555 VOID
1556 NTAPI
1558  IN PUSHORT Port,
1559  IN USHORT Value)
1560 {
1562 }
1563 
1564 VOID
1565 NTAPI
1567  IN PUCHAR Register,
1568  IN PUCHAR Buffer,
1569  IN ULONG Count)
1570 {
1571  // FIXME
1572  UNIMPLEMENTED;
1573 }
1574 
1575 VOID
1576 NTAPI
1578  IN PULONG Register,
1579  IN PULONG Buffer,
1580  IN ULONG Count)
1581 {
1582  // FIXME
1583  UNIMPLEMENTED;
1584 }
1585 
1586 VOID
1587 NTAPI
1589  IN PUSHORT Register,
1590  IN PUSHORT Buffer,
1591  IN ULONG Count)
1592 {
1593  // FIXME
1594  UNIMPLEMENTED;
1595 }
1596 
1597 VOID
1598 NTAPI
1600  IN PUCHAR Register,
1601  IN UCHAR Value)
1602 {
1603  WRITE_REGISTER_UCHAR(Register, Value);
1604 }
1605 
1606 VOID
1607 NTAPI
1609  IN PULONG Register,
1610  IN ULONG Value)
1611 {
1612  WRITE_REGISTER_ULONG(Register, Value);
1613 }
1614 
1615 VOID
1616 NTAPI
1618  IN PUSHORT Register,
1619  IN USHORT Value)
1620 {
1621  WRITE_REGISTER_USHORT(Register, Value);
1622 }
1623 
1624 extern char __ImageBase;
1625 
1626 ULONG
1628 {
1629  PIMAGE_NT_HEADERS NtHeaders;
1631  PIMAGE_IMPORT_DESCRIPTOR ImportTable;
1632  ULONG ImportTableSize;
1633  PLDR_DATA_TABLE_ENTRY BootDdDTE, FreeldrDTE;
1634  CHAR NtBootDdPath[MAX_PATH];
1635  PVOID ImageBase = NULL;
1636  ULONG (NTAPI *EntryPoint)(IN PVOID DriverObject, IN PVOID RegistryPath);
1637  BOOLEAN Success;
1638 
1639  // FIXME: Must be done *INSIDE* the HAL!
1640 #ifdef _M_IX86
1643 #endif
1644 
1645  /* Initialize the loaded module list */
1647 
1648  /* Create full ntbootdd.sys path */
1649  strcpy(NtBootDdPath, FrLdrBootPath);
1650  strcat(NtBootDdPath, "\\NTBOOTDD.SYS");
1651 
1652  /* Load file */
1653  Success = PeLdrLoadImage(NtBootDdPath, LoaderBootDriver, &ImageBase);
1654  if (!Success)
1655  {
1656  /* That's OK. File simply doesn't exist */
1657  return ESUCCESS;
1658  }
1659 
1660  /* Allocate a DTE for ntbootdd */
1662  "NTBOOTDD.SYS", ImageBase, &BootDdDTE);
1663  if (!Success)
1664  return EIO;
1665 
1666  /* Add the PE part of freeldr.sys to the list of loaded executables, it
1667  contains ScsiPort* exports, imported by ntbootdd.sys */
1669  "FREELDR.SYS", &__ImageBase, &FreeldrDTE);
1670  if (!Success)
1671  {
1672  RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1673  return EIO;
1674  }
1675 
1676  /* Fix imports */
1678 
1679  /* Now unlinkt the DTEs, they won't be valid later */
1680  RemoveEntryList(&BootDdDTE->InLoadOrderLinks);
1681  RemoveEntryList(&FreeldrDTE->InLoadOrderLinks);
1682 
1683  if (!Success)
1684  return EIO;
1685 
1686  /* Change imports to PA */
1688  TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &ImportTableSize);
1689  for (;(ImportTable->Name != 0) && (ImportTable->FirstThunk != 0);ImportTable++)
1690  {
1691  PIMAGE_THUNK_DATA ThunkData = (PIMAGE_THUNK_DATA)VaToPa(RVA(BootDdDTE->DllBase, ImportTable->FirstThunk));
1692 
1693  while (((PIMAGE_THUNK_DATA)ThunkData)->u1.AddressOfData != 0)
1694  {
1695  ThunkData->u1.Function = (ULONG)VaToPa((PVOID)ThunkData->u1.Function);
1696  ThunkData++;
1697  }
1698  }
1699 
1700  /* Relocate image to PA */
1701  NtHeaders = RtlImageNtHeader(VaToPa(BootDdDTE->DllBase));
1702  if (!NtHeaders)
1703  return EIO;
1705  NtHeaders->OptionalHeader.ImageBase - (ULONG_PTR)BootDdDTE->DllBase,
1706  "FreeLdr",
1707  TRUE,
1708  TRUE, /* in case of conflict still return success */
1709  FALSE);
1710  if (!Success)
1711  return EIO;
1712 
1713  /* Call the entrypoint */
1714  EntryPoint = VaToPa(BootDdDTE->EntryPoint);
1715  (*EntryPoint)(NULL, NULL);
1716 
1717  return ESUCCESS;
1718 }
1719 
1720 /* EOF */
UCHAR Byte0
Definition: tools.h:16
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:65
signed char * PCHAR
Definition: retypes.h:7
BOOLEAN PeLdrScanImportDescriptorTable(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH DirectoryPath, IN PLDR_DATA_TABLE_ENTRY ScanDTE)
Definition: peloader.c:509
struct _FOUR_BYTE * PFOUR_BYTE
PSCSI_PORT_DEVICE_EXTENSION ScsiDeviceExtensions[SCSI_MAXIMUM_BUSES]
Definition: scsiport.c:109
CPPORT Port[4]
Definition: headless.c:35
PVOID NTAPI ScsiPortGetUncachedExtension(IN PVOID HwDeviceExtension, IN PPORT_CONFIGURATION_INFORMATION ConfigInfo, IN ULONG NumberOfBytes)
Definition: scsiport.c:729
VOID NTAPI ScsiPortWritePortBufferUshort(IN PUSHORT Port, IN PUSHORT Buffer, IN ULONG Count)
Definition: scsiport.c:1529
#define IN
Definition: typedefs.h:39
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG BufferLength
Definition: wdfdevice.h:3767
#define SP_UNINITIALIZED_VALUE
Definition: srb.h:224
PPC_QUAL void __inbytestring(unsigned long Port, unsigned char *Buffer, unsigned long Count)
Definition: intrin_ppc.h:584
NTKERNELAPI VOID NTAPI WRITE_REGISTER_ULONG(IN PULONG Register, IN ULONG Value)
ULONG NTAPI ScsiPortReadPortUlong(IN PULONG Port)
Definition: scsiport.c:1392
BOOLEAN PeLdrLoadImage(IN PCHAR FileName, IN TYPE_OF_MEMORY MemoryType, OUT PVOID *ImageBasePA)
Definition: peloader.c:701
static NTSTATUS SpiCreatePortConfig(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PHW_INITIALIZATION_DATA HwInitData, OUT PPORT_CONFIGURATION_INFORMATION ConfigInfo, IN BOOLEAN ZeroStruct)
Definition: scsiport.c:423
VOID NTAPI ScsiPortReadRegisterBufferUshort(IN PUSHORT Register, IN PUSHORT Buffer, IN ULONG Count)
Definition: scsiport.c:1430
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ NDIS_ERROR_CODE ErrorCode
Definition: ndis.h:4436
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
ULONG SrbFlags
Definition: srb.h:252
CCHAR FrLdrBootPath[MAX_PATH]
Definition: freeldr.c:39
enum _INTERFACE_TYPE INTERFACE_TYPE
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR _In_ UCHAR Lun
Definition: classpnp.h:1310
_IRQL_requires_same_ _In_opt_ PVOID Argument1
Definition: cmtypes.h:696
_In_ PSCSI_REQUEST_BLOCK Srb
Definition: cdrom.h:989
UCHAR Cdb[16]
Definition: srb.h:271
VOID NTAPI WRITE_PORT_USHORT(IN PUSHORT Port, IN USHORT Value)
Definition: portio.c:115
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define __cdecl
Definition: accygwin.h:79
enum _SCSI_NOTIFICATION_TYPE SCSI_NOTIFICATION_TYPE
Definition: arc.h:32
#define READ_PORT_UCHAR(p)
Definition: pc98vid.h:22
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:156
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR PathId
Definition: classpnp.h:1310
BOOLEAN(NTAPI * PHW_RESET_BUS)(IN PVOID DeviceExtension, IN ULONG PathId)
Definition: srb.h:471
#define TRUE
Definition: types.h:120
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define SRB_FLAGS_IS_ACTIVE
Definition: srb.h:399
PVOID DataBuffer
Definition: srb.h:255
static VOID SpiResourceToConfig(IN PHW_INITIALIZATION_DATA HwInitializationData, IN PCM_FULL_RESOURCE_DESCRIPTOR ResourceDescriptor, IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig)
Definition: scsiport.c:944
IO_SCSI_CAPABILITIES PortCapabilities
Definition: scsiport.c:79
Definition: arc.h:39
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR TargetId
Definition: classpnp.h:1310
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2272
#define SCSI_MAXIMUM_LOGICAL_UNITS
Definition: srb.h:21
static COORD Position
Definition: mouse.c:34
PPC_QUAL void __outbytestring(unsigned long const Port, const unsigned char *const Buffer, const unsigned long Count)
Definition: intrin_ppc.h:653
unsigned char * PUCHAR
Definition: retypes.h:3
static BOOLEAN SpiGetPciConfigData(IN PHW_INITIALIZATION_DATA HwInitializationData, IN OUT PPORT_CONFIGURATION_INFORMATION PortConfig, IN ULONG BusNumber, IN OUT PPCI_SLOT_NUMBER NextSlotNumber)
Definition: scsiport.c:1025
char CHAR
Definition: xmlstorage.h:175
VOID NTAPI ScsiPortWritePortUshort(IN PUSHORT Port, IN USHORT Value)
Definition: scsiport.c:1557
ULONG DataTransferLength
Definition: srb.h:253
ULONG LoadBootDeviceDriver(VOID)
Definition: scsiport.c:1627
struct SCSI_PORT_DEVICE_EXTENSION * PSCSI_PORT_DEVICE_EXTENSION
PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
Definition: scsiport.c:97
static ARC_STATUS DiskGetFileInformation(ULONG FileId, FILEINFORMATION *Information)
Definition: scsiport.c:184
Definition: cdrw_hw.h:28
LONG NTSTATUS
Definition: precomp.h:26
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:213
#define ReadBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:339
VOID NTAPI ScsiPortWriteRegisterUchar(IN PUCHAR Register, IN UCHAR Value)
Definition: scsiport.c:1599
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@381 Memory
_Must_inspect_result_ _In_ PVOID _In_ struct _HW_INITIALIZATION_DATA _In_ PVOID HwContext
Definition: srb.h:897
Definition: fs.h:24
ULONG NTAPI READ_PORT_ULONG(IN PULONG Port)
Definition: portio.c:70
ULONG NTAPI ScsiPortSetBusDataByOffset(IN PVOID DeviceExtension, IN ULONG BusDataType, IN ULONG SystemIoBusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: scsiport.c:1465
ULONG ntohl(IN ULONG Value)
Definition: scsiport.c:114
struct _IMAGE_IMPORT_DESCRIPTOR * PIMAGE_IMPORT_DESCRIPTOR
UCHAR CdbLength
Definition: srb.h:250
ULONG LogicalBlockAddress
Definition: cdrw_hw.h:1471
VOID NTAPI ScsiPortCompleteRequest(IN PVOID HwDeviceExtension, IN UCHAR PathId, IN UCHAR TargetId, IN UCHAR Lun, IN UCHAR SrbStatus)
Definition: scsiport.c:506
ULONG ARC_STATUS
Definition: arc.h:4
#define H2I(Port)
Definition: portio.c:18
NTKERNELAPI VOID NTAPI WRITE_REGISTER_USHORT(IN PUSHORT Register, IN USHORT Value)
ACCESS_RANGE(* AccessRanges)[]
Definition: srb.h:70
GLdouble u1
Definition: glext.h:8308
struct _CDB::_CDB10 CDB10
NTKERNELAPI ULONG NTAPI READ_REGISTER_ULONG(IN PULONG Register)
if(dx==0 &&dy==0)
Definition: linetemp.h:174
static ARC_STATUS DiskRead(ULONG FileId, VOID *Buffer, ULONG N, ULONG *Count)
Definition: scsiport.c:273
#define SRB_FLAGS_DATA_IN
Definition: srb.h:392
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2272
ULONG TimeOutValue
Definition: srb.h:254
_In_ WDFREQUEST _In_ NTSTATUS _In_ ULONG_PTR Information
Definition: wdfrequest.h:1044
UCHAR SrbStatus
Definition: srb.h:243
#define SRB_STATUS(Status)
Definition: srb.h:381
VOID * FsGetDeviceSpecific(ULONG FileId)
Definition: fs.c:416
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:304
SCSI_PHYSICAL_ADDRESS NTAPI ScsiPortGetPhysicalAddress(IN PVOID HwDeviceExtension, IN PSCSI_REQUEST_BLOCK Srb OPTIONAL, IN PVOID VirtualAddress, OUT ULONG *Length)
Definition: scsiport.c:615
Definition: arc.h:48
VOID NTAPI ScsiPortReadRegisterBufferUchar(IN PUCHAR Register, IN PUCHAR Buffer, IN ULONG Count)
Definition: scsiport.c:1408
#define CmResourceTypePort
Definition: hwresource.cpp:123
PPC_QUAL void __outdwordstring(unsigned long const Port, const unsigned long *const Buffer, const unsigned long Count)
Definition: intrin_ppc.h:671
#define DEVICE_DESCRIPTION_VERSION
Definition: iotypes.h:2063
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:264
VOID NTAPI ScsiPortReadPortBufferUshort(IN PUSHORT Port, OUT PUSHORT Buffer, IN ULONG Count)
Definition: scsiport.c:1372
uint32_t ULONG_PTR
Definition: typedefs.h:65
PVOID NTAPI ScsiPortGetDeviceBase(IN PVOID HwDeviceExtension, IN INTERFACE_TYPE BusType, IN ULONG SystemIoBusNumber, IN SCSI_PHYSICAL_ADDRESS IoAddress, IN ULONG NumberOfBytes, IN BOOLEAN InIoSpace)
Definition: scsiport.c:570
FORCEINLINE BOOLEAN RemoveEntryList(_In_ PLIST_ENTRY Entry)
Definition: rtlfuncs.h:105
#define PARTITION_ENTRY_UNUSED
Definition: disk.h:86
PVOID DllBase
Definition: btrfs_drv.h:1926
UCHAR NTAPI ScsiPortReadRegisterUchar(IN PUCHAR Register)
Definition: scsiport.c:1441
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:465
#define sprintf(buf, format,...)
Definition: sprintf.c:55
_In_ WDF_SPECIAL_FILE_TYPE NotificationType
Definition: wdfdevice.h:1024
VOID NTAPI ScsiPortFreeDeviceBase(IN PVOID HwDeviceExtension, IN PVOID MappedAddress)
Definition: scsiport.c:548
union _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376 u
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@382 Dma
UCHAR Byte3
Definition: tools.h:19
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_ PCUNICODE_STRING DeviceDescription
Definition: wdfpdo.h:430
VOID NTAPI WRITE_PORT_ULONG(IN PULONG Port, IN ULONG Value)
Definition: portio.c:123
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
#define va_end(ap)
Definition: acmsvcex.h:90
#define FALSE
Definition: types.h:117
#define SCSI_MAXIMUM_TARGETS_PER_BUS
Definition: srb.h:22
BOOLEAN(NTAPI * PHW_INITIALIZE)(IN PVOID DeviceExtension)
Definition: srb.h:429
long LONG
Definition: pedump.c:60
DBG_DEFAULT_CHANNEL(SCSIPORT)
#define SCSI_PORT_NEXT_REQUEST_READY
Definition: scsiport.c:54
PVOID EntryPoint
Definition: ntddk_ex.h:203
VOID NTAPI ScsiPortIoMapTransfer(IN PVOID HwDeviceExtension, IN PSCSI_REQUEST_BLOCK Srb, IN PVOID LogicalAddress, IN ULONG Length)
Definition: scsiport.c:1279
VOID NTAPI ScsiPortWriteRegisterBufferUshort(IN PUSHORT Register, IN PUSHORT Buffer, IN ULONG Count)
Definition: scsiport.c:1588
#define SCSIOP_READ
Definition: cdrw_hw.h:905
PHW_INITIALIZE HwInitialize
Definition: scsiport.c:81
_In_ ULONG _In_ BOOLEAN _Out_ struct _DRIVE_LAYOUT_INFORMATION ** PartitionBuffer
Definition: iofuncs.h:2052
VOID __cdecl ScsiDebugPrint(IN ULONG DebugPrintLevel, IN PCCHAR DebugMessage, IN ...)
Definition: scsiport.c:470
ULONG NTAPI ScsiPortInitialize(IN PVOID Argument1, IN PVOID Argument2, IN PHW_INITIALIZATION_DATA HwInitializationData, IN PVOID HwContext OPTIONAL)
Definition: scsiport.c:1125
FORCEINLINE PVOID FrLdrTempAlloc(_In_ SIZE_T Size, _In_ ULONG Tag)
Definition: mm.h:188
UCHAR RemovableMedia
Definition: cdrw_hw.h:1119
#define SectorOffset(L)
Definition: cdprocs.h:1622
unsigned char BOOLEAN
#define INQUIRYDATABUFFERSIZE
Definition: cdrw_hw.h:1113
static WCHAR Address[46]
Definition: ping.c:68
VOID NTAPI ScsiPortWriteRegisterUshort(IN PUSHORT Register, IN USHORT Value)
Definition: scsiport.c:1617
union _CDB * PCDB
char * va_list
Definition: acmsvcex.h:78
enum _SEEKMODE SEEKMODE
Definition: bufpool.h:45
#define BufSize
Definition: FsRtlTunnel.c:28
_Must_inspect_result_ _In_ WDFDMATRANSACTION _In_ PFN_WDF_PROGRAM_DMA _In_ WDF_DMA_DIRECTION _In_ PMDL _In_ PVOID VirtualAddress
VOID NTAPI ScsiPortReadPortBufferUlong(IN PULONG Port, OUT PULONG Buffer, IN ULONG Count)
Definition: scsiport.c:1362
void * PVOID
Definition: retypes.h:9
UCHAR TargetId
Definition: srb.h:246
PSCSI_REQUEST_BLOCK NTAPI ScsiPortGetSrb(IN PVOID DeviceExtension, IN UCHAR PathId, IN UCHAR TargetId, IN UCHAR Lun, IN LONG QueueTag)
Definition: scsiport.c:651
NTHALAPI NTSTATUS NTAPI HalAssignSlotResources(PUNICODE_STRING, PUNICODE_STRING, PDRIVER_OBJECT, PDEVICE_OBJECT, INTERFACE_TYPE, ULONG, ULONG, PCM_RESOURCE_LIST *)
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
_In_ PVOID Argument2
Definition: classpnp.h:721
ULONG SectorSize
Definition: hwdisk.c:34
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
NTSTRSAFEVAPI RtlStringCbPrintfA(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCSTR pszFormat,...)
Definition: ntstrsafe.h:1148
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:406
VOID NTAPI ScsiPortReadPortBufferUchar(IN PUCHAR Port, OUT PUCHAR Buffer, IN ULONG Count)
Definition: scsiport.c:1352
USHORT NTAPI ScsiPortReadRegisterUshort(IN PUSHORT Register)
Definition: scsiport.c:1457
#define SCSIOP_INQUIRY
Definition: cdrw_hw.h:888
Status
Definition: gdiplustypes.h:24
int64_t LONGLONG
Definition: typedefs.h:68
int Count
Definition: noreturn.cpp:7
#define TRACE(s)
Definition: solgame.cpp:4
UCHAR TargetId
Definition: scsiport.c:99
#define PCI_INVALID_VENDORID
Definition: iotypes.h:3601
#define ASSERT(a)
Definition: mode.c:44
struct tagDISKCONTEXT DISKCONTEXT
#define TAG_SCSI_ACCESS_RANGES
Definition: scsiport.c:57
VOID NTAPI HalpInitBusHandler(VOID)
Definition: bushndlr.c:420
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
SCSI_PHYSICAL_ADDRESS NTAPI ScsiPortConvertUlongToPhysicalAddress(IN ULONG_PTR UlongAddress)
Definition: scsiport.c:528
char CCHAR
Definition: typedefs.h:51
_In_ WDFCOLLECTION _In_ ULONG Index
uint64_t ULONGLONG
Definition: typedefs.h:67
PVOID NTAPI ScsiPortGetLogicalUnit(IN PVOID HwDeviceExtension, IN UCHAR PathId, IN UCHAR TargetId, IN UCHAR Lun)
Definition: scsiport.c:602
UCHAR Function
Definition: srb.h:242
BOOLEAN(NTAPI * PHW_STARTIO)(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb)
Definition: srb.h:435
static const DEVVTBL DiskVtbl
Definition: scsiport.c:412
#define MAX_PATH
Definition: compat.h:34
#define PCI_MAX_DEVICES
Definition: iotypes.h:3598
ULONGLONG SectorOffset
Definition: hwdisk.c:35
PPC_QUAL void __outwordstring(unsigned long const Port, const unsigned short *const Buffer, const unsigned long Count)
Definition: intrin_ppc.h:662
VOID FsSetDeviceSpecific(ULONG FileId, VOID *Specific)
Definition: fs.c:409
_In_opt_ WDFREQUEST _In_ ULONG _In_ BOOLEAN _In_ PCDB Cdb
Definition: scratch.h:156
_In_ PREAD_CAPACITY_DATA ReadCapacityBuffer
Definition: cdrom.h:1103
va_start(ap, x)
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
USHORT Length
Definition: srb.h:241
BOOLEAN DissectArcPath2(IN PCSTR ArcPath, OUT PULONG x, OUT PULONG y, OUT PULONG z, OUT PULONG Partition, OUT PULONG PathSyntax)
Definition: arcname.c:121
#define SP_RETURN_FOUND
Definition: srb.h:514
struct _SCSI_REQUEST_BLOCK SCSI_REQUEST_BLOCK
ULONG NTAPI ScsiPortConvertPhysicalAddressToUlong(IN SCSI_PHYSICAL_ADDRESS Address)
Definition: scsiport.c:520
SCSI_PHYSICAL_ADDRESS RangeStart
Definition: srb.h:41
VOID NTAPI ScsiPortWritePortUchar(IN PUCHAR Port, IN UCHAR Value)
Definition: scsiport.c:1539
struct _READ_CAPACITY_DATA READ_CAPACITY_DATA
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _PORT_CONFIGURATION_INFORMATION PORT_CONFIGURATION_INFORMATION
USHORT NTAPI ScsiPortReadPortUshort(IN PUSHORT Port)
Definition: scsiport.c:1400
int ret
BOOLEAN RangeInMemory
Definition: srb.h:43
ULONG NTAPI HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:73
ULONGLONG SectorNumber
Definition: hwdisk.c:37
VOID FsRegisterDevice(CHAR *Prefix, const DEVVTBL *FuncTable)
Definition: fs.c:383
VOID __cdecl ScsiPortNotification(IN SCSI_NOTIFICATION_TYPE NotificationType, IN PVOID HwDeviceExtension, IN ...)
Definition: scsiport.c:1316
VOID NTAPI ScsiPortWritePortUlong(IN PULONG Port, IN ULONG Value)
Definition: scsiport.c:1548
ULONGLONG SectorCount
Definition: hwdisk.c:36
#define RtlImageDirectoryEntryToData
Definition: compat.h:668
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:21
#define ExAllocatePool(type, size)
Definition: fbtusb.h:44
Definition: btrfs_drv.h:1922
PPC_QUAL void __indwordstring(unsigned long Port, unsigned long *Buffer, unsigned long Count)
Definition: intrin_ppc.h:598
Definition: typedefs.h:119
struct _SCSI_PORT_DEVICE_EXTENSION SCSI_PORT_DEVICE_EXTENSION
ULONG SectorCount
Definition: part_xbox.c:31
static VOID SpiScanAdapter(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN ULONG ScsiBus, IN UCHAR PathId)
Definition: scsiport.c:869
IMAGE_OPTIONAL_HEADER32 OptionalHeader
Definition: ntddk_ex.h:184
NTKERNELAPI UCHAR NTAPI READ_REGISTER_UCHAR(IN PUCHAR Register)
BOOLEAN NTAPI HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, IN OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: bus.c:140
#define PCI_MAX_FUNCTION
Definition: iotypes.h:3599
#define MAXULONG
Definition: typedefs.h:251
UCHAR Byte1
Definition: tools.h:17
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:138
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101
#define RVA(m, b)
Definition: freeldr.h:24
ULONG NTAPI ScsiPortGetBusData(IN PVOID DeviceExtension, IN ULONG BusDataType, IN ULONG SystemIoBusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Length)
Definition: scsiport.c:557
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@378 Port
#define va_arg(ap, T)
Definition: acmsvcex.h:89
PHW_RESET_BUS HwResetBus
Definition: scsiport.c:84
PRTL_UNICODE_STRING_BUFFER Path
VOID NTAPI ScsiPortWriteRegisterBufferUlong(IN PULONG Register, IN PULONG Buffer, IN ULONG Count)
Definition: scsiport.c:1577
PADAPTER_OBJECT AdapterObject
Definition: scsiport.c:87
NTSYSAPI ULONG NTAPI LdrRelocateImageWithBias(_In_ PVOID NewAddress, _In_ LONGLONG AdditionalBias, _In_ PCCH LoaderName, _In_ ULONG Success, _In_ ULONG Conflict, _In_ ULONG Invalid)
ULONG NTAPI ScsiPortReadRegisterUlong(IN PULONG Register)
Definition: scsiport.c:1449
UCHAR PathId
Definition: srb.h:245
union _IMAGE_THUNK_DATA32::@2078 u1
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ROUND_TO_PAGES(Size)
unsigned short USHORT
Definition: pedump.c:61
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
ULONG RangeLength
Definition: srb.h:42
_Must_inspect_result_ _In_ WDFDMAENABLER _In_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFCOMMONBUFFER * CommonBuffer
PHW_INTERRUPT HwInterrupt
Definition: scsiport.c:83
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _Inout_ PLARGE_INTEGER NumberOfBytes
Definition: iotypes.h:1035
unsigned int * PULONG
Definition: retypes.h:1
#define NULL
Definition: types.h:112
BOOLEAN(NTAPI * PHW_INTERRUPT)(IN PVOID DeviceExtension)
Definition: srb.h:442
VOID NTAPI ScsiPortReadRegisterBufferUlong(IN PULONG Register, IN PULONG Buffer, IN ULONG Count)
Definition: scsiport.c:1419
#define CM_RESOURCE_INTERRUPT_LEVEL_SENSITIVE
Definition: cmtypes.h:143
Definition: arc.h:40
#define CmResourceTypeInterrupt
Definition: hwresource.cpp:124
static ARC_STATUS DiskOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: scsiport.c:203
#define _vsnprintf
Definition: xmlstorage.h:202
#define SCSIOP_READ_CAPACITY
Definition: cdrw_hw.h:904
ARC_STATUS ArcClose(ULONG FileId)
Definition: fs.c:218
#define RtlImageNtHeader
Definition: compat.h:665
UCHAR NTAPI ScsiPortReadPortUchar(IN PUCHAR Port)
Definition: scsiport.c:1382
#define IMAGE_DIRECTORY_ENTRY_IMPORT
Definition: pedump.c:260
PPC_QUAL void __inwordstring(unsigned long Port, unsigned short *Buffer, unsigned long Count)
Definition: intrin_ppc.h:591
static NTSTATUS SpiAllocateCommonBuffer(IN OUT PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN ULONG NonCachedSize)
Definition: scsiport.c:665
#define SCSI_MAXIMUM_BUSES
Definition: srb.h:24
BOOLEAN NTAPI ScsiPortValidateRange(IN PVOID HwDeviceExtension, IN INTERFACE_TYPE BusType, IN ULONG SystemIoBusNumber, IN SCSI_PHYSICAL_ADDRESS IoAddress, IN ULONG NumberOfBytes, IN BOOLEAN InIoSpace)
Definition: scsiport.c:1489
PVOID SenseInfoBuffer
Definition: srb.h:256
char __ImageBase
Definition: mstscax.cpp:17
struct tagContext Context
Definition: acpixf.h:1034
void int int ULONGLONG int va_list * ap
Definition: winesup.h:32
#define BOOLEAN
Definition: pedump.c:73
#define OUT
Definition: typedefs.h:40
#define CM_RESOURCE_INTERRUPT_LATCHED
Definition: cmtypes.h:144
#define SRB_FUNCTION_EXECUTE_SCSI
Definition: srb.h:307
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
ARC_STATUS ArcOpen(CHAR *Path, OPENMODE OpenMode, ULONG *FileId)
Definition: fs.c:56
unsigned int ULONG
Definition: retypes.h:1
NTKERNELAPI USHORT NTAPI READ_REGISTER_USHORT(IN PUSHORT Register)
#define UNIMPLEMENTED
Definition: debug.h:115
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
static BOOLEAN SpiSendSynchronousSrb(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb)
Definition: scsiport.c:130
#define ULONG_PTR
Definition: config.h:101
#define SRB_STATUS_SUCCESS
Definition: srb.h:333
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167
static ARC_STATUS DiskClose(ULONG FileId)
Definition: scsiport.c:177
FORCEINLINE PVOID VaToPa(PVOID Va)
Definition: conversion.h:15
#define STATUS_SUCCESS
Definition: shellext.h:65
VOID NTAPI ScsiPortLogError(IN PVOID HwDeviceExtension, IN PSCSI_REQUEST_BLOCK Srb OPTIONAL, IN UCHAR PathId, IN UCHAR TargetId, IN UCHAR Lun, IN ULONG ErrorCode, IN ULONG UniqueId)
Definition: scsiport.c:1291
USHORT NTAPI READ_PORT_USHORT(IN PUSHORT Port)
Definition: portio.c:63
struct _CM_PARTIAL_RESOURCE_DESCRIPTOR::@376::@379 Interrupt
PVOID NTAPI ScsiPortGetVirtualAddress(IN PVOID HwDeviceExtension, IN SCSI_PHYSICAL_ADDRESS PhysicalAddress)
Definition: scsiport.c:814
UCHAR Byte2
Definition: tools.h:18
struct _CDB::_CDB6INQUIRY CDB6INQUIRY
_In_ ULONG SectorSize
Definition: halfuncs.h:291
VOID NTAPI HalpInitializePciStubs(VOID)
Definition: pcibus.c:1102
_In_ PCHAR _In_ ULONG DeviceNumber
Definition: classpnp.h:1229
#define CmResourceTypeMemory
Definition: hwresource.cpp:125
static ARC_STATUS DiskSeek(ULONG FileId, LARGE_INTEGER *Position, SEEKMODE SeekMode)
Definition: scsiport.c:383
static VOID SpiScanDevice(IN PSCSI_PORT_DEVICE_EXTENSION DeviceExtension, IN PCHAR ArcName, IN ULONG ScsiBus, IN ULONG TargetId, IN ULONG Lun)
Definition: scsiport.c:825
BOOLEAN PeLdrAllocateDataTableEntry(IN OUT PLIST_ENTRY ModuleListHead, IN PCCH BaseDllName, IN PCCH FullDllName, IN PVOID BasePA, OUT PLDR_DATA_TABLE_ENTRY *NewEntry)
Definition: peloader.c:585
enum _OPENMODE OPENMODE
VOID NTAPI ScsiPortWriteRegisterBufferUchar(IN PUCHAR Register, IN PUCHAR Buffer, IN ULONG Count)
Definition: scsiport.c:1566
NTKERNELAPI VOID NTAPI WRITE_REGISTER_UCHAR(IN PUCHAR Register, IN UCHAR Value)
#define TAG_SCSI_DEVEXT
Definition: scsiport.c:56
VOID NTAPI ScsiPortWritePortBufferUchar(IN PUCHAR Port, IN PUCHAR Buffer, IN ULONG Count)
Definition: scsiport.c:1509
_In_ NDIS_STATUS _In_ ULONG _In_ USHORT _In_opt_ PVOID _In_ ULONG DataSize
Definition: ndis.h:4751
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
unsigned short * PUSHORT
Definition: retypes.h:2
struct _LARGE_INTEGER::@2239 u
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:96
#define HALDISPATCH
Definition: haltypes.h:278
#define WriteBuffer(BaseIoAddress, Buffer, Count)
Definition: atapi.h:344
#define ExFreePool(addr)
Definition: env_spec_w32.h:352
PIMAGE_THUNK_DATA32 PIMAGE_THUNK_DATA
Definition: ntimage.h:566
VOID NTAPI ScsiPortWritePortBufferUlong(IN PULONG Port, IN PULONG Buffer, IN ULONG Count)
Definition: scsiport.c:1519
VOID NTAPI ScsiPortMoveMemory(IN PVOID WriteBuffer, IN PVOID ReadBuffer, IN ULONG Length)
Definition: scsiport.c:1306
ULONG AsULong
Definition: scsi.h:3439
_Must_inspect_result_ _In_ PVOID _In_ struct _HW_INITIALIZATION_DATA * HwInitializationData
Definition: srb.h:897
#define CmResourceTypeDma
Definition: hwresource.cpp:126
LONGLONG QuadPart
Definition: typedefs.h:114
UCHAR PathId
Definition: scsiport.c:98
PADAPTER_OBJECT NTAPI HalGetAdapter(IN PDEVICE_DESCRIPTION DeviceDescription, OUT PULONG NumberOfMapRegisters)
Definition: dma.c:22
VOID NTAPI ScsiPortWriteRegisterUlong(IN PULONG Register, IN ULONG Value)
Definition: scsiport.c:1608
VOID NTAPI ScsiPortFlushDma(IN PVOID DeviceExtension)
Definition: scsiport.c:539
VOID NTAPI ScsiPortStallExecution(IN ULONG Delay)
Definition: scsiport.c:1481
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68
FORCEINLINE VOID FrLdrTempFree(PVOID Allocation, ULONG Tag)
Definition: mm.h:197