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