1 /*
2  * PROJECT:     ReactOS Storport Driver
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     Storport driver main file
5  * COPYRIGHT:   Copyright 2017 Eric Kohl (eric.kohl@reactos.org)
6  */
7 
8 /* INCLUDES *******************************************************************/
9 
10 #include "precomp.h"
11 
12 #define NDEBUG
13 #include <debug.h>
14 
15 
16 /* GLOBALS ********************************************************************/
17 
18 ULONG PortNumber = 0;
19 
20 
21 /* FUNCTIONS ******************************************************************/
22 
23 static
24 NTSTATUS
PortAddDriverInitData(PDRIVER_OBJECT_EXTENSION DriverExtension,PHW_INITIALIZATION_DATA HwInitializationData)25 PortAddDriverInitData(
26     PDRIVER_OBJECT_EXTENSION DriverExtension,
27     PHW_INITIALIZATION_DATA HwInitializationData)
28 {
29     PDRIVER_INIT_DATA InitData;
30 
31     DPRINT1("PortAddDriverInitData()\n");
32 
33     InitData = ExAllocatePoolWithTag(NonPagedPool,
34                                      sizeof(DRIVER_INIT_DATA),
35                                      TAG_INIT_DATA);
36     if (InitData == NULL)
37         return STATUS_NO_MEMORY;
38 
39     RtlCopyMemory(&InitData->HwInitData,
40                   HwInitializationData,
41                   sizeof(HW_INITIALIZATION_DATA));
42 
43     InsertHeadList(&DriverExtension->InitDataListHead,
44                    &InitData->Entry);
45 
46     return STATUS_SUCCESS;
47 }
48 
49 
50 static
51 VOID
PortDeleteDriverInitData(PDRIVER_OBJECT_EXTENSION DriverExtension)52 PortDeleteDriverInitData(
53     PDRIVER_OBJECT_EXTENSION DriverExtension)
54 {
55     PDRIVER_INIT_DATA InitData;
56     PLIST_ENTRY ListEntry;
57 
58     DPRINT1("PortDeleteDriverInitData()\n");
59 
60     ListEntry = DriverExtension->InitDataListHead.Flink;
61     while (ListEntry != &DriverExtension->InitDataListHead)
62     {
63         InitData = CONTAINING_RECORD(ListEntry,
64                                      DRIVER_INIT_DATA,
65                                      Entry);
66 
67         RemoveEntryList(&InitData->Entry);
68 
69         ExFreePoolWithTag(InitData,
70                           TAG_INIT_DATA);
71 
72         ListEntry = DriverExtension->InitDataListHead.Flink;
73     }
74 }
75 
76 
77 PHW_INITIALIZATION_DATA
PortGetDriverInitData(PDRIVER_OBJECT_EXTENSION DriverExtension,INTERFACE_TYPE InterfaceType)78 PortGetDriverInitData(
79     PDRIVER_OBJECT_EXTENSION DriverExtension,
80     INTERFACE_TYPE InterfaceType)
81 {
82     PDRIVER_INIT_DATA InitData;
83     PLIST_ENTRY ListEntry;
84 
85     DPRINT1("PortGetDriverInitData()\n");
86 
87     ListEntry = DriverExtension->InitDataListHead.Flink;
88     while (ListEntry != &DriverExtension->InitDataListHead)
89     {
90         InitData = CONTAINING_RECORD(ListEntry,
91                                      DRIVER_INIT_DATA,
92                                      Entry);
93         if (InitData->HwInitData.AdapterInterfaceType == InterfaceType)
94             return &InitData->HwInitData;
95 
96         ListEntry = ListEntry->Flink;
97     }
98 
99     return NULL;
100 }
101 
102 
103 static
104 VOID
PortAcquireSpinLock(PFDO_DEVICE_EXTENSION DeviceExtension,STOR_SPINLOCK SpinLock,PVOID LockContext,PSTOR_LOCK_HANDLE LockHandle)105 PortAcquireSpinLock(
106     PFDO_DEVICE_EXTENSION DeviceExtension,
107     STOR_SPINLOCK SpinLock,
108     PVOID LockContext,
109     PSTOR_LOCK_HANDLE LockHandle)
110 {
111     DPRINT1("PortAcquireSpinLock(%p %lu %p %p)\n",
112             DeviceExtension, SpinLock, LockContext, LockHandle);
113 
114     LockHandle->Lock = SpinLock;
115 
116     switch (SpinLock)
117     {
118         case DpcLock: /* 1, */
119             DPRINT1("DpcLock\n");
120             break;
121 
122         case StartIoLock: /* 2 */
123             DPRINT1("StartIoLock\n");
124             break;
125 
126         case InterruptLock: /* 3 */
127             DPRINT1("InterruptLock\n");
128             if (DeviceExtension->Interrupt == NULL)
129                 LockHandle->Context.OldIrql = 0;
130             else
131                 LockHandle->Context.OldIrql = KeAcquireInterruptSpinLock(DeviceExtension->Interrupt);
132             break;
133     }
134 }
135 
136 
137 static
138 VOID
PortReleaseSpinLock(PFDO_DEVICE_EXTENSION DeviceExtension,PSTOR_LOCK_HANDLE LockHandle)139 PortReleaseSpinLock(
140     PFDO_DEVICE_EXTENSION DeviceExtension,
141     PSTOR_LOCK_HANDLE LockHandle)
142 {
143     DPRINT1("PortReleaseSpinLock(%p %p)\n",
144             DeviceExtension, LockHandle);
145 
146     switch (LockHandle->Lock)
147     {
148         case DpcLock: /* 1, */
149             DPRINT1("DpcLock\n");
150             break;
151 
152         case StartIoLock: /* 2 */
153             DPRINT1("StartIoLock\n");
154             break;
155 
156         case InterruptLock: /* 3 */
157             DPRINT1("InterruptLock\n");
158             if (DeviceExtension->Interrupt != NULL)
159                 KeReleaseInterruptSpinLock(DeviceExtension->Interrupt,
160                                            LockHandle->Context.OldIrql);
161             break;
162     }
163 }
164 
165 
166 static
167 NTSTATUS
168 NTAPI
PortAddDevice(_In_ PDRIVER_OBJECT DriverObject,_In_ PDEVICE_OBJECT PhysicalDeviceObject)169 PortAddDevice(
170     _In_ PDRIVER_OBJECT DriverObject,
171     _In_ PDEVICE_OBJECT PhysicalDeviceObject)
172 {
173     PDRIVER_OBJECT_EXTENSION DriverObjectExtension;
174     PFDO_DEVICE_EXTENSION DeviceExtension = NULL;
175     WCHAR NameBuffer[80];
176     UNICODE_STRING DeviceName;
177     PDEVICE_OBJECT Fdo = NULL;
178     KLOCK_QUEUE_HANDLE LockHandle;
179     NTSTATUS Status;
180 
181     DPRINT1("PortAddDevice(%p %p)\n",
182             DriverObject, PhysicalDeviceObject);
183 
184     ASSERT(DriverObject);
185     ASSERT(PhysicalDeviceObject);
186 
187     swprintf(NameBuffer,
188              L"\\Device\\RaidPort%lu",
189              PortNumber);
190     RtlInitUnicodeString(&DeviceName, NameBuffer);
191     PortNumber++;
192 
193     DPRINT1("Creating device: %wZ\n", &DeviceName);
194 
195     /* Create the port device */
196     Status = IoCreateDevice(DriverObject,
197                             sizeof(FDO_DEVICE_EXTENSION),
198                             &DeviceName,
199                             FILE_DEVICE_CONTROLLER,
200                             FILE_DEVICE_SECURE_OPEN,
201                             FALSE,
202                             &Fdo);
203     if (!NT_SUCCESS(Status))
204     {
205         DPRINT1("IoCreateDevice() failed (Status 0x%08lx)\n", Status);
206         return Status;
207     }
208 
209     DPRINT1("Created device: %wZ (%p)\n", &DeviceName, Fdo);
210 
211     /* Initialize the device */
212     Fdo->Flags |= DO_DIRECT_IO;
213     Fdo->Flags |= DO_POWER_PAGABLE;
214 
215     /* Initialize the device extension */
216     DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
217     RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
218 
219     DeviceExtension->ExtensionType = FdoExtension;
220 
221     DeviceExtension->Device = Fdo;
222     DeviceExtension->PhysicalDevice = PhysicalDeviceObject;
223 
224     DeviceExtension->PnpState = dsStopped;
225 
226     KeInitializeSpinLock(&DeviceExtension->PdoListLock);
227     InitializeListHead(&DeviceExtension->PdoListHead);
228 
229     /* Attach the FDO to the device stack */
230     Status = IoAttachDeviceToDeviceStackSafe(Fdo,
231                                              PhysicalDeviceObject,
232                                              &DeviceExtension->LowerDevice);
233     if (!NT_SUCCESS(Status))
234     {
235         DPRINT1("IoAttachDeviceToDeviceStackSafe() failed (Status 0x%08lx)\n", Status);
236         IoDeleteDevice(Fdo);
237         return Status;
238     }
239 
240     /* Insert the FDO to the drivers FDO list */
241     DriverObjectExtension = IoGetDriverObjectExtension(DriverObject,
242                                                        (PVOID)DriverEntry);
243     ASSERT(DriverObjectExtension->ExtensionType == DriverExtension);
244 
245     DeviceExtension->DriverExtension = DriverObjectExtension;
246 
247     KeAcquireInStackQueuedSpinLock(&DriverObjectExtension->AdapterListLock,
248                                    &LockHandle);
249 
250     InsertHeadList(&DriverObjectExtension->AdapterListHead,
251                    &DeviceExtension->AdapterListEntry);
252     DriverObjectExtension->AdapterCount++;
253 
254     KeReleaseInStackQueuedSpinLock(&LockHandle);
255 
256     /* The device has been initialized */
257     Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
258 
259     DPRINT1("PortAddDevice() done (Status 0x%08lx)\n", Status);
260 
261     return Status;
262 }
263 
264 
265 static
266 VOID
267 NTAPI
PortUnload(_In_ PDRIVER_OBJECT DriverObject)268 PortUnload(
269     _In_ PDRIVER_OBJECT DriverObject)
270 {
271     PDRIVER_OBJECT_EXTENSION DriverExtension;
272 
273     DPRINT1("PortUnload(%p)\n",
274             DriverObject);
275 
276     DriverExtension = IoGetDriverObjectExtension(DriverObject,
277                                                  (PVOID)DriverEntry);
278     if (DriverExtension != NULL)
279     {
280         PortDeleteDriverInitData(DriverExtension);
281     }
282 }
283 
284 
285 static
286 NTSTATUS
287 NTAPI
PortDispatchCreate(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)288 PortDispatchCreate(
289     IN PDEVICE_OBJECT DeviceObject,
290     IN PIRP Irp)
291 {
292     DPRINT1("PortDispatchCreate(%p %p)\n",
293             DeviceObject, Irp);
294 
295     Irp->IoStatus.Status = STATUS_SUCCESS;
296     Irp->IoStatus.Information = FILE_OPENED;
297 
298     IoCompleteRequest(Irp, IO_NO_INCREMENT);
299 
300     return STATUS_SUCCESS;
301 }
302 
303 
304 static
305 NTSTATUS
306 NTAPI
PortDispatchClose(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)307 PortDispatchClose(
308     IN PDEVICE_OBJECT DeviceObject,
309     IN PIRP Irp)
310 {
311     DPRINT1("PortDispatchClose(%p %p)\n",
312             DeviceObject, Irp);
313 
314     Irp->IoStatus.Status = STATUS_SUCCESS;
315     Irp->IoStatus.Information = 0;
316 
317     IoCompleteRequest(Irp, IO_NO_INCREMENT);
318 
319     return STATUS_SUCCESS;
320 }
321 
322 
323 static
324 NTSTATUS
325 NTAPI
PortDispatchDeviceControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)326 PortDispatchDeviceControl(
327     IN PDEVICE_OBJECT DeviceObject,
328     IN PIRP Irp)
329 {
330     DPRINT1("PortDispatchDeviceControl(%p %p)\n",
331             DeviceObject, Irp);
332 
333     Irp->IoStatus.Status = STATUS_SUCCESS;
334     Irp->IoStatus.Information = 0;
335 
336     IoCompleteRequest(Irp, IO_NO_INCREMENT);
337 
338     return STATUS_SUCCESS;
339 }
340 
341 
342 static
343 NTSTATUS
344 NTAPI
PortDispatchScsi(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)345 PortDispatchScsi(
346     IN PDEVICE_OBJECT DeviceObject,
347     IN PIRP Irp)
348 {
349     PFDO_DEVICE_EXTENSION DeviceExtension;
350 
351     DPRINT1("PortDispatchScsi(%p %p)\n",
352             DeviceObject, Irp);
353 
354     DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
355     DPRINT1("ExtensionType: %u\n", DeviceExtension->ExtensionType);
356 
357     switch (DeviceExtension->ExtensionType)
358     {
359         case FdoExtension:
360             return PortFdoScsi(DeviceObject,
361                                Irp);
362 
363         case PdoExtension:
364             return PortPdoScsi(DeviceObject,
365                                Irp);
366 
367         default:
368             Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
369             Irp->IoStatus.Information = 0;
370             IoCompleteRequest(Irp, IO_NO_INCREMENT);
371             return STATUS_UNSUCCESSFUL;
372     }
373 
374     return STATUS_SUCCESS;
375 }
376 
377 
378 static
379 NTSTATUS
380 NTAPI
PortDispatchSystemControl(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)381 PortDispatchSystemControl(
382     IN PDEVICE_OBJECT DeviceObject,
383     IN PIRP Irp)
384 {
385     DPRINT1("PortDispatchSystemControl(%p %p)\n",
386             DeviceObject, Irp);
387 
388     Irp->IoStatus.Status = STATUS_SUCCESS;
389     Irp->IoStatus.Information = 0;
390 
391     IoCompleteRequest(Irp, IO_NO_INCREMENT);
392 
393     return STATUS_SUCCESS;
394 }
395 
396 
397 static
398 NTSTATUS
399 NTAPI
PortDispatchPnp(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)400 PortDispatchPnp(
401     IN PDEVICE_OBJECT DeviceObject,
402     IN PIRP Irp)
403 {
404     PFDO_DEVICE_EXTENSION DeviceExtension;
405 
406     DPRINT1("PortDispatchPnp(%p %p)\n",
407             DeviceObject, Irp);
408 
409     DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
410     DPRINT1("ExtensionType: %u\n", DeviceExtension->ExtensionType);
411 
412     switch (DeviceExtension->ExtensionType)
413     {
414         case FdoExtension:
415             return PortFdoPnp(DeviceObject,
416                               Irp);
417 
418         case PdoExtension:
419             return PortPdoPnp(DeviceObject,
420                               Irp);
421 
422         default:
423             Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
424             Irp->IoStatus.Information = 0;
425             IoCompleteRequest(Irp, IO_NO_INCREMENT);
426             return STATUS_UNSUCCESSFUL;
427     }
428 }
429 
430 
431 static
432 NTSTATUS
433 NTAPI
PortDispatchPower(IN PDEVICE_OBJECT DeviceObject,IN PIRP Irp)434 PortDispatchPower(
435     IN PDEVICE_OBJECT DeviceObject,
436     IN PIRP Irp)
437 {
438     DPRINT1("PortDispatchPower(%p %p)\n",
439             DeviceObject, Irp);
440 
441     Irp->IoStatus.Status = STATUS_SUCCESS;
442     Irp->IoStatus.Information = 0;
443 
444     IoCompleteRequest(Irp, IO_NO_INCREMENT);
445 
446     return STATUS_SUCCESS;
447 }
448 
449 
450 /* PUBLIC FUNCTIONS ***********************************************************/
451 
452 /*
453  * @implemented
454  */
455 NTSTATUS
456 NTAPI
DriverEntry(_In_ PDRIVER_OBJECT DriverObject,_In_ PUNICODE_STRING RegistryPath)457 DriverEntry(
458     _In_ PDRIVER_OBJECT DriverObject,
459     _In_ PUNICODE_STRING RegistryPath)
460 {
461     DPRINT1("DriverEntry(%p %p)\n", DriverObject, RegistryPath);
462     return STATUS_SUCCESS;
463 }
464 
465 
466 /*
467  * @unimplemented
468  */
469 STORPORT_API
470 PUCHAR
471 NTAPI
StorPortAllocateRegistryBuffer(_In_ PVOID HwDeviceExtension,_In_ PULONG Length)472 StorPortAllocateRegistryBuffer(
473     _In_ PVOID HwDeviceExtension,
474     _In_ PULONG Length)
475 {
476     DPRINT1("StorPortAllocateRegistryBuffer()\n");
477     UNIMPLEMENTED;
478     return NULL;
479 }
480 
481 
482 /*
483  * @unimplemented
484  */
485 STORPORT_API
486 BOOLEAN
487 NTAPI
StorPortBusy(_In_ PVOID HwDeviceExtension,_In_ ULONG RequestsToComplete)488 StorPortBusy(
489     _In_ PVOID HwDeviceExtension,
490     _In_ ULONG RequestsToComplete)
491 {
492     DPRINT1("StorPortBuzy()\n");
493     UNIMPLEMENTED;
494     return FALSE;
495 }
496 
497 
498 /*
499  * @unimplemented
500  */
501 STORPORT_API
502 VOID
503 NTAPI
StorPortCompleteRequest(_In_ PVOID HwDeviceExtension,_In_ UCHAR PathId,_In_ UCHAR TargetId,_In_ UCHAR Lun,_In_ UCHAR SrbStatus)504 StorPortCompleteRequest(
505     _In_ PVOID HwDeviceExtension,
506     _In_ UCHAR PathId,
507     _In_ UCHAR TargetId,
508     _In_ UCHAR Lun,
509     _In_ UCHAR SrbStatus)
510 {
511     DPRINT1("StorPortCompleteRequest()\n");
512     UNIMPLEMENTED;
513 }
514 
515 
516 /*
517  * @implemented
518  */
519 STORPORT_API
520 ULONG
521 NTAPI
StorPortConvertPhysicalAddressToUlong(_In_ STOR_PHYSICAL_ADDRESS Address)522 StorPortConvertPhysicalAddressToUlong(
523     _In_ STOR_PHYSICAL_ADDRESS Address)
524 {
525     DPRINT1("StorPortConvertPhysicalAddressToUlong()\n");
526 
527     return Address.u.LowPart;
528 }
529 
530 
531 /*
532  * @implemented
533  */
534 STORPORT_API
535 STOR_PHYSICAL_ADDRESS
536 NTAPI
StorPortConvertUlongToPhysicalAddress(_In_ ULONG_PTR UlongAddress)537 StorPortConvertUlongToPhysicalAddress(
538     _In_ ULONG_PTR UlongAddress)
539 {
540     STOR_PHYSICAL_ADDRESS Address;
541 
542     DPRINT1("StorPortConvertUlongToPhysicalAddress()\n");
543 
544     Address.QuadPart = UlongAddress;
545     return Address;
546 }
547 
548 
549 /*
550  * @implemented
551  */
552 STORPORT_API
553 VOID
StorPortDebugPrint(_In_ ULONG DebugPrintLevel,_In_ PCHAR DebugMessage,...)554 StorPortDebugPrint(
555     _In_ ULONG DebugPrintLevel,
556     _In_ PCHAR DebugMessage,
557     ...)
558 {
559     va_list ap;
560 
561     va_start(ap, DebugMessage);
562     vDbgPrintExWithPrefix("STORMINI: ", 0x58, DebugPrintLevel, DebugMessage, ap);
563     va_end(ap);
564 }
565 
566 
567 /*
568  * @unimplemented
569  */
570 STORPORT_API
571 BOOLEAN
572 NTAPI
StorPortDeviceBusy(_In_ PVOID HwDeviceExtension,_In_ UCHAR PathId,_In_ UCHAR TargetId,_In_ UCHAR Lun,_In_ ULONG RequestsToComplete)573 StorPortDeviceBusy(
574     _In_ PVOID HwDeviceExtension,
575     _In_ UCHAR PathId,
576     _In_ UCHAR TargetId,
577     _In_ UCHAR Lun,
578     _In_ ULONG RequestsToComplete)
579 {
580     DPRINT1("StorPortDeviceBusy()\n");
581     UNIMPLEMENTED;
582     return FALSE;
583 }
584 
585 
586 /*
587  * @unimplemented
588  */
589 STORPORT_API
590 BOOLEAN
591 NTAPI
StorPortDeviceReady(_In_ PVOID HwDeviceExtension,_In_ UCHAR PathId,_In_ UCHAR TargetId,_In_ UCHAR Lun)592 StorPortDeviceReady(
593     _In_ PVOID HwDeviceExtension,
594     _In_ UCHAR PathId,
595     _In_ UCHAR TargetId,
596     _In_ UCHAR Lun)
597 {
598     DPRINT1("StorPortDeviceReady()\n");
599     UNIMPLEMENTED;
600     return FALSE;
601 }
602 
603 
604 /*
605  * @unimplemented
606  */
607 STORPORT_API
608 ULONG
StorPortExtendedFunction(_In_ STORPORT_FUNCTION_CODE FunctionCode,_In_ PVOID HwDeviceExtension,...)609 StorPortExtendedFunction(
610     _In_ STORPORT_FUNCTION_CODE FunctionCode,
611     _In_ PVOID HwDeviceExtension,
612     ...)
613 {
614     DPRINT1("StorPortExtendedFunction(%d %p ...)\n",
615             FunctionCode, HwDeviceExtension);
616     UNIMPLEMENTED;
617     return STATUS_NOT_IMPLEMENTED;
618 }
619 
620 
621 /*
622  * @implemented
623  */
624 STORPORT_API
625 VOID
626 NTAPI
StorPortFreeDeviceBase(_In_ PVOID HwDeviceExtension,_In_ PVOID MappedAddress)627 StorPortFreeDeviceBase(
628     _In_ PVOID HwDeviceExtension,
629     _In_ PVOID MappedAddress)
630 {
631     DPRINT1("StorPortFreeDeviceBase(%p %p)\n",
632             HwDeviceExtension, MappedAddress);
633 }
634 
635 
636 /*
637  * @unimplemented
638  */
639 STORPORT_API
640 VOID
641 NTAPI
StorPortFreeRegistryBuffer(_In_ PVOID HwDeviceExtension,_In_ PUCHAR Buffer)642 StorPortFreeRegistryBuffer(
643     _In_ PVOID HwDeviceExtension,
644     _In_ PUCHAR Buffer)
645 {
646     DPRINT1("StorPortFreeRegistryBuffer()\n");
647     UNIMPLEMENTED;
648 }
649 
650 
651 /*
652  * @implemented
653  */
654 STORPORT_API
655 ULONG
656 NTAPI
657 StorPortGetBusData(
658     _In_ PVOID DeviceExtension,
659     _In_ ULONG BusDataType,
660     _In_ ULONG SystemIoBusNumber,
661     _In_ ULONG SlotNumber,
662     _Out_ _When_(Length != 0, _Out_writes_bytes_(Length)) PVOID Buffer,
663     _In_ ULONG Length)
664 {
665     PMINIPORT_DEVICE_EXTENSION MiniportExtension;
666     PBUS_INTERFACE_STANDARD Interface;
667     ULONG ReturnLength;
668 
669     DPRINT1("StorPortGetBusData(%p %lu %lu %lu %p %lu)\n",
670             DeviceExtension, BusDataType, SystemIoBusNumber, SlotNumber, Buffer, Length);
671 
672     /* Get the miniport extension */
673     MiniportExtension = CONTAINING_RECORD(DeviceExtension,
674                                           MINIPORT_DEVICE_EXTENSION,
675                                           HwDeviceExtension);
676     DPRINT1("DeviceExtension %p  MiniportExtension %p\n",
677             DeviceExtension, MiniportExtension);
678 
679     Interface = &MiniportExtension->Miniport->DeviceExtension->BusInterface;
680 
681     if (BusDataType == 4)
682         BusDataType = 0;
683 
684     ReturnLength = Interface->GetBusData(Interface->Context,
685                                          BusDataType,
686                                          Buffer,
687                                          0,
688                                          Length);
689     DPRINT1("ReturnLength: %lu\n", ReturnLength);
690 
691     return ReturnLength;
692 }
693 
694 
695 /*
696  * @implemented
697  */
698 STORPORT_API
699 PVOID
700 NTAPI
StorPortGetDeviceBase(_In_ PVOID HwDeviceExtension,_In_ INTERFACE_TYPE BusType,_In_ ULONG SystemIoBusNumber,_In_ STOR_PHYSICAL_ADDRESS IoAddress,_In_ ULONG NumberOfBytes,_In_ BOOLEAN InIoSpace)701 StorPortGetDeviceBase(
702     _In_ PVOID HwDeviceExtension,
703     _In_ INTERFACE_TYPE BusType,
704     _In_ ULONG SystemIoBusNumber,
705     _In_ STOR_PHYSICAL_ADDRESS IoAddress,
706     _In_ ULONG NumberOfBytes,
707     _In_ BOOLEAN InIoSpace)
708 {
709     PMINIPORT_DEVICE_EXTENSION MiniportExtension;
710     PHYSICAL_ADDRESS TranslatedAddress;
711     PVOID MappedAddress;
712     NTSTATUS Status;
713 
714     DPRINT1("StorPortGetDeviceBase(%p %lu %lu 0x%I64x %lu %u)\n",
715             HwDeviceExtension, BusType, SystemIoBusNumber, IoAddress.QuadPart, NumberOfBytes, InIoSpace);
716 
717     /* Get the miniport extension */
718     MiniportExtension = CONTAINING_RECORD(HwDeviceExtension,
719                                           MINIPORT_DEVICE_EXTENSION,
720                                           HwDeviceExtension);
721     DPRINT1("HwDeviceExtension %p  MiniportExtension %p\n",
722             HwDeviceExtension, MiniportExtension);
723 
724     if (!TranslateResourceListAddress(MiniportExtension->Miniport->DeviceExtension,
725                                       BusType,
726                                       SystemIoBusNumber,
727                                       IoAddress,
728                                       NumberOfBytes,
729                                       InIoSpace,
730                                       &TranslatedAddress))
731     {
732         DPRINT1("Checkpoint!\n");
733         return NULL;
734     }
735 
736     DPRINT1("Translated Address: 0x%I64x\n", TranslatedAddress.QuadPart);
737 
738     /* In I/O space */
739     if (InIoSpace)
740     {
741         DPRINT1("Translated Address: %p\n", (PVOID)(ULONG_PTR)TranslatedAddress.QuadPart);
742         return (PVOID)(ULONG_PTR)TranslatedAddress.QuadPart;
743     }
744 
745     /* In memory space */
746     MappedAddress = MmMapIoSpace(TranslatedAddress,
747                                  NumberOfBytes,
748                                  FALSE);
749     DPRINT1("Mapped Address: %p\n", MappedAddress);
750 
751     Status = AllocateAddressMapping(&MiniportExtension->Miniport->DeviceExtension->MappedAddressList,
752                                     IoAddress,
753                                     MappedAddress,
754                                     NumberOfBytes,
755                                     SystemIoBusNumber);
756     if (!NT_SUCCESS(Status))
757     {
758         DPRINT1("Checkpoint!\n");
759         MappedAddress = NULL;
760     }
761 
762     DPRINT1("Mapped Address: %p\n", MappedAddress);
763     return MappedAddress;
764 }
765 
766 
767 /*
768  * @unimplemented
769  */
770 STORPORT_API
771 PVOID
772 NTAPI
StorPortGetLogicalUnit(_In_ PVOID HwDeviceExtension,_In_ UCHAR PathId,_In_ UCHAR TargetId,_In_ UCHAR Lun)773 StorPortGetLogicalUnit(
774     _In_ PVOID HwDeviceExtension,
775     _In_ UCHAR PathId,
776     _In_ UCHAR TargetId,
777     _In_ UCHAR Lun)
778 {
779     DPRINT1("StorPortGetLogicalUnit()\n");
780     UNIMPLEMENTED;
781     return NULL;
782 }
783 
784 
785 /*
786  * @implemented
787  */
788 STORPORT_API
789 STOR_PHYSICAL_ADDRESS
790 NTAPI
StorPortGetPhysicalAddress(_In_ PVOID HwDeviceExtension,_In_opt_ PSCSI_REQUEST_BLOCK Srb,_In_ PVOID VirtualAddress,_Out_ ULONG * Length)791 StorPortGetPhysicalAddress(
792     _In_ PVOID HwDeviceExtension,
793     _In_opt_ PSCSI_REQUEST_BLOCK Srb,
794     _In_ PVOID VirtualAddress,
795     _Out_ ULONG *Length)
796 {
797     PMINIPORT_DEVICE_EXTENSION MiniportExtension;
798     PFDO_DEVICE_EXTENSION DeviceExtension;
799     STOR_PHYSICAL_ADDRESS PhysicalAddress;
800     ULONG_PTR Offset;
801 
802     DPRINT1("StorPortGetPhysicalAddress(%p %p %p %p)\n",
803             HwDeviceExtension, Srb, VirtualAddress, Length);
804 
805     /* Get the miniport extension */
806     MiniportExtension = CONTAINING_RECORD(HwDeviceExtension,
807                                           MINIPORT_DEVICE_EXTENSION,
808                                           HwDeviceExtension);
809     DPRINT1("HwDeviceExtension %p  MiniportExtension %p\n",
810             HwDeviceExtension, MiniportExtension);
811 
812     DeviceExtension = MiniportExtension->Miniport->DeviceExtension;
813 
814     /* Inside of the uncached extension? */
815     if (((ULONG_PTR)VirtualAddress >= (ULONG_PTR)DeviceExtension->UncachedExtensionVirtualBase) &&
816         ((ULONG_PTR)VirtualAddress <= (ULONG_PTR)DeviceExtension->UncachedExtensionVirtualBase + DeviceExtension->UncachedExtensionSize))
817     {
818         Offset = (ULONG_PTR)VirtualAddress - (ULONG_PTR)DeviceExtension->UncachedExtensionVirtualBase;
819 
820         PhysicalAddress.QuadPart = DeviceExtension->UncachedExtensionPhysicalBase.QuadPart + Offset;
821         *Length = DeviceExtension->UncachedExtensionSize - Offset;
822 
823         return PhysicalAddress;
824     }
825 
826     // FIXME
827 
828 
829     PhysicalAddress = MmGetPhysicalAddress(VirtualAddress);
830     *Length = 1;
831 //    UNIMPLEMENTED;
832 
833 //    *Length = 0;
834 //    PhysicalAddress.QuadPart = (LONGLONG)0;
835 
836     return PhysicalAddress;
837 }
838 
839 
840 /*
841  * @unimplemented
842  */
843 STORPORT_API
844 PSTOR_SCATTER_GATHER_LIST
845 NTAPI
StorPortGetScatterGatherList(_In_ PVOID DeviceExtension,_In_ PSCSI_REQUEST_BLOCK Srb)846 StorPortGetScatterGatherList(
847     _In_ PVOID DeviceExtension,
848     _In_ PSCSI_REQUEST_BLOCK Srb)
849 {
850     DPRINT1("StorPortGetScatterGatherList()\n");
851     UNIMPLEMENTED;
852     return NULL;
853 }
854 
855 
856 /*
857  * @implemented
858  */
859 STORPORT_API
860 PSCSI_REQUEST_BLOCK
861 NTAPI
StorPortGetSrb(_In_ PVOID DeviceExtension,_In_ UCHAR PathId,_In_ UCHAR TargetId,_In_ UCHAR Lun,_In_ LONG QueueTag)862 StorPortGetSrb(
863     _In_ PVOID DeviceExtension,
864     _In_ UCHAR PathId,
865     _In_ UCHAR TargetId,
866     _In_ UCHAR Lun,
867     _In_ LONG QueueTag)
868 {
869     DPRINT("StorPortGetSrb()\n");
870     return NULL;
871 }
872 
873 
874 /*
875  * @implemented
876  */
877 STORPORT_API
878 PVOID
879 NTAPI
StorPortGetUncachedExtension(_In_ PVOID HwDeviceExtension,_In_ PPORT_CONFIGURATION_INFORMATION ConfigInfo,_In_ ULONG NumberOfBytes)880 StorPortGetUncachedExtension(
881     _In_ PVOID HwDeviceExtension,
882     _In_ PPORT_CONFIGURATION_INFORMATION ConfigInfo,
883     _In_ ULONG NumberOfBytes)
884 {
885     PMINIPORT_DEVICE_EXTENSION MiniportExtension;
886     PFDO_DEVICE_EXTENSION DeviceExtension;
887     PHYSICAL_ADDRESS LowestAddress, HighestAddress, Alignment;
888 
889     DPRINT1("StorPortGetUncachedExtension(%p %p %lu)\n",
890             HwDeviceExtension, ConfigInfo, NumberOfBytes);
891 
892     /* Get the miniport extension */
893     MiniportExtension = CONTAINING_RECORD(HwDeviceExtension,
894                                           MINIPORT_DEVICE_EXTENSION,
895                                           HwDeviceExtension);
896     DPRINT1("HwDeviceExtension %p  MiniportExtension %p\n",
897             HwDeviceExtension, MiniportExtension);
898 
899     DeviceExtension = MiniportExtension->Miniport->DeviceExtension;
900 
901     /* Return the uncached extension base address if we already have one */
902     if (DeviceExtension->UncachedExtensionVirtualBase != NULL)
903         return DeviceExtension->UncachedExtensionVirtualBase;
904 
905     // FIXME: Set DMA stuff here?
906 
907     /* Allocate the uncached extension */
908     Alignment.QuadPart = 0;
909     LowestAddress.QuadPart = 0;
910     HighestAddress.QuadPart = 0x00000000FFFFFFFF;
911     DeviceExtension->UncachedExtensionVirtualBase = MmAllocateContiguousMemorySpecifyCache(NumberOfBytes,
912                                                                                            LowestAddress,
913                                                                                            HighestAddress,
914                                                                                            Alignment,
915                                                                                            MmCached);
916     if (DeviceExtension->UncachedExtensionVirtualBase == NULL)
917         return NULL;
918 
919     DeviceExtension->UncachedExtensionPhysicalBase = MmGetPhysicalAddress(DeviceExtension->UncachedExtensionVirtualBase);
920     DeviceExtension->UncachedExtensionSize = NumberOfBytes;
921 
922     return DeviceExtension->UncachedExtensionVirtualBase;
923 }
924 
925 
926 /*
927  * @unimplemented
928  */
929 STORPORT_API
930 PVOID
931 NTAPI
StorPortGetVirtualAddress(_In_ PVOID HwDeviceExtension,_In_ STOR_PHYSICAL_ADDRESS PhysicalAddress)932 StorPortGetVirtualAddress(
933     _In_ PVOID HwDeviceExtension,
934     _In_ STOR_PHYSICAL_ADDRESS PhysicalAddress)
935 {
936     DPRINT1("StorPortGetVirtualAddress(%p %I64x)\n",
937             HwDeviceExtension, PhysicalAddress.QuadPart);
938     UNIMPLEMENTED;
939     return NULL;
940 }
941 
942 
943 /*
944  * @implemented
945  */
946 STORPORT_API
947 ULONG
948 NTAPI
StorPortInitialize(_In_ PVOID Argument1,_In_ PVOID Argument2,_In_ struct _HW_INITIALIZATION_DATA * HwInitializationData,_In_opt_ PVOID HwContext)949 StorPortInitialize(
950     _In_ PVOID Argument1,
951     _In_ PVOID Argument2,
952     _In_ struct _HW_INITIALIZATION_DATA *HwInitializationData,
953     _In_opt_ PVOID HwContext)
954 {
955     PDRIVER_OBJECT DriverObject = (PDRIVER_OBJECT)Argument1;
956     PUNICODE_STRING RegistryPath = (PUNICODE_STRING)Argument2;
957     PDRIVER_OBJECT_EXTENSION DriverObjectExtension;
958     NTSTATUS Status = STATUS_SUCCESS;
959 
960     DPRINT1("StorPortInitialize(%p %p %p %p)\n",
961             Argument1, Argument2, HwInitializationData, HwContext);
962 
963     DPRINT1("HwInitializationDataSize: %lu\n", HwInitializationData->HwInitializationDataSize);
964     DPRINT1("AdapterInterfaceType: %u\n", HwInitializationData->AdapterInterfaceType);
965     DPRINT1("HwInitialize: %p\n", HwInitializationData->HwInitialize);
966     DPRINT1("HwStartIo: %p\n", HwInitializationData->HwStartIo);
967     DPRINT1("HwInterrupt: %p\n", HwInitializationData->HwInterrupt);
968     DPRINT1("HwFindAdapter: %p\n", HwInitializationData->HwFindAdapter);
969     DPRINT1("HwResetBus: %p\n", HwInitializationData->HwResetBus);
970     DPRINT1("HwDmaStarted: %p\n", HwInitializationData->HwDmaStarted);
971     DPRINT1("HwAdapterState: %p\n", HwInitializationData->HwAdapterState);
972     DPRINT1("DeviceExtensionSize: %lu\n", HwInitializationData->DeviceExtensionSize);
973     DPRINT1("SpecificLuExtensionSize: %lu\n", HwInitializationData->SpecificLuExtensionSize);
974     DPRINT1("SrbExtensionSize: %lu\n", HwInitializationData->SrbExtensionSize);
975     DPRINT1("NumberOfAccessRanges: %lu\n", HwInitializationData->NumberOfAccessRanges);
976 
977     /* Check parameters */
978     if ((DriverObject == NULL) ||
979         (RegistryPath == NULL) ||
980         (HwInitializationData == NULL))
981     {
982         DPRINT1("Invalid parameter!\n");
983         return STATUS_INVALID_PARAMETER;
984     }
985 
986     /* Check initialization data */
987     if ((HwInitializationData->HwInitializationDataSize < sizeof(HW_INITIALIZATION_DATA)) ||
988         (HwInitializationData->HwInitialize == NULL) ||
989         (HwInitializationData->HwStartIo == NULL) ||
990         (HwInitializationData->HwFindAdapter == NULL) ||
991         (HwInitializationData->HwResetBus == NULL))
992     {
993         DPRINT1("Revision mismatch!\n");
994         return STATUS_REVISION_MISMATCH;
995     }
996 
997     DriverObjectExtension = IoGetDriverObjectExtension(DriverObject,
998                                                        (PVOID)DriverEntry);
999     if (DriverObjectExtension == NULL)
1000     {
1001         DPRINT1("No driver object extension!\n");
1002 
1003         Status = IoAllocateDriverObjectExtension(DriverObject,
1004                                                  (PVOID)DriverEntry,
1005                                                  sizeof(DRIVER_OBJECT_EXTENSION),
1006                                                  (PVOID *)&DriverObjectExtension);
1007         if (!NT_SUCCESS(Status))
1008         {
1009             DPRINT1("IoAllocateDriverObjectExtension() failed (Status 0x%08lx)\n", Status);
1010             return Status;
1011         }
1012 
1013         DPRINT1("Driver object extension created!\n");
1014 
1015         /* Initialize the driver object extension */
1016         RtlZeroMemory(DriverObjectExtension,
1017                       sizeof(DRIVER_OBJECT_EXTENSION));
1018 
1019         DriverObjectExtension->ExtensionType = DriverExtension;
1020         DriverObjectExtension->DriverObject = DriverObject;
1021 
1022         InitializeListHead(&DriverObjectExtension->AdapterListHead);
1023         KeInitializeSpinLock(&DriverObjectExtension->AdapterListLock);
1024 
1025         InitializeListHead(&DriverObjectExtension->InitDataListHead);
1026 
1027         /* Set handlers */
1028         DriverObject->DriverExtension->AddDevice = PortAddDevice;
1029 //        DriverObject->DriverStartIo = PortStartIo;
1030         DriverObject->DriverUnload = PortUnload;
1031         DriverObject->MajorFunction[IRP_MJ_CREATE] = PortDispatchCreate;
1032         DriverObject->MajorFunction[IRP_MJ_CLOSE] = PortDispatchClose;
1033         DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = PortDispatchDeviceControl;
1034         DriverObject->MajorFunction[IRP_MJ_SCSI] = PortDispatchScsi;
1035         DriverObject->MajorFunction[IRP_MJ_POWER] = PortDispatchPower;
1036         DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = PortDispatchSystemControl;
1037         DriverObject->MajorFunction[IRP_MJ_PNP] = PortDispatchPnp;
1038     }
1039 
1040     /* Add the initialzation data to the driver extension */
1041     Status = PortAddDriverInitData(DriverObjectExtension,
1042                                    HwInitializationData);
1043 
1044     DPRINT1("StorPortInitialize() done (Status 0x%08lx)\n", Status);
1045 
1046     return Status;
1047 }
1048 
1049 
1050 /*
1051  * @unimplemented
1052  */
1053 STORPORT_API
1054 VOID
1055 NTAPI
StorPortLogError(_In_ PVOID HwDeviceExtension,_In_opt_ PSCSI_REQUEST_BLOCK Srb,_In_ UCHAR PathId,_In_ UCHAR TargetId,_In_ UCHAR Lun,_In_ ULONG ErrorCode,_In_ ULONG UniqueId)1056 StorPortLogError(
1057     _In_ PVOID HwDeviceExtension,
1058     _In_opt_ PSCSI_REQUEST_BLOCK Srb,
1059     _In_ UCHAR PathId,
1060     _In_ UCHAR TargetId,
1061     _In_ UCHAR Lun,
1062     _In_ ULONG ErrorCode,
1063     _In_ ULONG UniqueId)
1064 {
1065     DPRINT1("ScsiPortLogError() called\n");
1066     DPRINT1("PathId: 0x%02x  TargetId: 0x%02x  Lun: 0x%02x  ErrorCode: 0x%08lx  UniqueId: 0x%08lx\n",
1067             PathId, TargetId, Lun, ErrorCode, UniqueId);
1068 
1069     DPRINT1("ScsiPortLogError() done\n");
1070 }
1071 
1072 
1073 /*
1074  * @implemented
1075  */
1076 STORPORT_API
1077 VOID
1078 NTAPI
StorPortMoveMemory(_Out_writes_bytes_ (Length)PVOID Destination,_In_reads_bytes_ (Length)PVOID Source,_In_ ULONG Length)1079 StorPortMoveMemory(
1080     _Out_writes_bytes_(Length) PVOID Destination,
1081     _In_reads_bytes_(Length) PVOID Source,
1082     _In_ ULONG Length)
1083 {
1084     RtlMoveMemory(Destination, Source, Length);
1085 }
1086 
1087 
1088 /*
1089  * @unimplemented
1090  */
1091 STORPORT_API
1092 VOID
StorPortNotification(_In_ SCSI_NOTIFICATION_TYPE NotificationType,_In_ PVOID HwDeviceExtension,...)1093 StorPortNotification(
1094     _In_ SCSI_NOTIFICATION_TYPE NotificationType,
1095     _In_ PVOID HwDeviceExtension,
1096     ...)
1097 {
1098     PMINIPORT_DEVICE_EXTENSION MiniportExtension = NULL;
1099     PFDO_DEVICE_EXTENSION DeviceExtension = NULL;
1100     PHW_PASSIVE_INITIALIZE_ROUTINE HwPassiveInitRoutine;
1101     PSTORPORT_EXTENDED_FUNCTIONS *ppExtendedFunctions;
1102     PBOOLEAN Result;
1103     PSTOR_DPC Dpc;
1104     PHW_DPC_ROUTINE HwDpcRoutine;
1105     va_list ap;
1106 
1107     STOR_SPINLOCK SpinLock;
1108     PVOID LockContext;
1109     PSTOR_LOCK_HANDLE LockHandle;
1110     PSCSI_REQUEST_BLOCK Srb;
1111 
1112     DPRINT1("StorPortNotification(%x %p)\n",
1113             NotificationType, HwDeviceExtension);
1114 
1115     /* Get the miniport extension */
1116     if (HwDeviceExtension != NULL)
1117     {
1118         MiniportExtension = CONTAINING_RECORD(HwDeviceExtension,
1119                                               MINIPORT_DEVICE_EXTENSION,
1120                                               HwDeviceExtension);
1121         DPRINT1("HwDeviceExtension %p  MiniportExtension %p\n",
1122                 HwDeviceExtension, MiniportExtension);
1123 
1124         DeviceExtension = MiniportExtension->Miniport->DeviceExtension;
1125     }
1126 
1127     va_start(ap, HwDeviceExtension);
1128 
1129     switch (NotificationType)
1130     {
1131         case RequestComplete:
1132             DPRINT1("RequestComplete\n");
1133             Srb = (PSCSI_REQUEST_BLOCK)va_arg(ap, PSCSI_REQUEST_BLOCK);
1134             DPRINT1("Srb %p\n", Srb);
1135             if (Srb->OriginalRequest != NULL)
1136             {
1137                 DPRINT1("Need to complete the IRP!\n");
1138 
1139             }
1140             break;
1141 
1142         case GetExtendedFunctionTable:
1143             DPRINT1("GetExtendedFunctionTable\n");
1144             ppExtendedFunctions = (PSTORPORT_EXTENDED_FUNCTIONS*)va_arg(ap, PSTORPORT_EXTENDED_FUNCTIONS*);
1145             if (ppExtendedFunctions != NULL)
1146                 *ppExtendedFunctions = NULL; /* FIXME */
1147             break;
1148 
1149         case EnablePassiveInitialization:
1150             DPRINT1("EnablePassiveInitialization\n");
1151             HwPassiveInitRoutine = (PHW_PASSIVE_INITIALIZE_ROUTINE)va_arg(ap, PHW_PASSIVE_INITIALIZE_ROUTINE);
1152             DPRINT1("HwPassiveInitRoutine %p\n", HwPassiveInitRoutine);
1153             Result = (PBOOLEAN)va_arg(ap, PBOOLEAN);
1154 
1155             *Result = FALSE;
1156 
1157             if ((DeviceExtension != NULL) &&
1158                 (DeviceExtension->HwPassiveInitRoutine == NULL))
1159             {
1160                 DeviceExtension->HwPassiveInitRoutine = HwPassiveInitRoutine;
1161                 *Result = TRUE;
1162             }
1163             break;
1164 
1165         case InitializeDpc:
1166             DPRINT1("InitializeDpc\n");
1167             Dpc = (PSTOR_DPC)va_arg(ap, PSTOR_DPC);
1168             DPRINT1("Dpc %p\n", Dpc);
1169             HwDpcRoutine = (PHW_DPC_ROUTINE)va_arg(ap, PHW_DPC_ROUTINE);
1170             DPRINT1("HwDpcRoutine %p\n", HwDpcRoutine);
1171 
1172             KeInitializeDpc((PRKDPC)&Dpc->Dpc,
1173                             (PKDEFERRED_ROUTINE)HwDpcRoutine,
1174                             (PVOID)DeviceExtension);
1175             KeInitializeSpinLock(&Dpc->Lock);
1176             break;
1177 
1178         case AcquireSpinLock:
1179             DPRINT1("AcquireSpinLock\n");
1180             SpinLock = (STOR_SPINLOCK)va_arg(ap, STOR_SPINLOCK);
1181             DPRINT1("SpinLock %lu\n", SpinLock);
1182             LockContext = (PVOID)va_arg(ap, PVOID);
1183             DPRINT1("LockContext %p\n", LockContext);
1184             LockHandle = (PSTOR_LOCK_HANDLE)va_arg(ap, PSTOR_LOCK_HANDLE);
1185             DPRINT1("LockHandle %p\n", LockHandle);
1186             PortAcquireSpinLock(DeviceExtension,
1187                                 SpinLock,
1188                                 LockContext,
1189                                 LockHandle);
1190             break;
1191 
1192         case ReleaseSpinLock:
1193             DPRINT1("ReleaseSpinLock\n");
1194             LockHandle = (PSTOR_LOCK_HANDLE)va_arg(ap, PSTOR_LOCK_HANDLE);
1195             DPRINT1("LockHandle %p\n", LockHandle);
1196             PortReleaseSpinLock(DeviceExtension,
1197                                 LockHandle);
1198             break;
1199 
1200         default:
1201             DPRINT1("Unsupported Notification %lx\n", NotificationType);
1202             break;
1203     }
1204 
1205     va_end(ap);
1206 }
1207 
1208 
1209 /*
1210  * @unimplemented
1211  */
1212 STORPORT_API
1213 BOOLEAN
1214 NTAPI
StorPortPause(_In_ PVOID HwDeviceExtension,_In_ ULONG TimeOut)1215 StorPortPause(
1216     _In_ PVOID HwDeviceExtension,
1217     _In_ ULONG TimeOut)
1218 {
1219     DPRINT1("StorPortPause()\n");
1220     UNIMPLEMENTED;
1221     return FALSE;
1222 }
1223 
1224 
1225 /*
1226  * @unimplemented
1227  */
1228 STORPORT_API
1229 BOOLEAN
1230 NTAPI
StorPortPauseDevice(_In_ PVOID HwDeviceExtension,_In_ UCHAR PathId,_In_ UCHAR TargetId,_In_ UCHAR Lun,_In_ ULONG TimeOut)1231 StorPortPauseDevice(
1232     _In_ PVOID HwDeviceExtension,
1233     _In_ UCHAR PathId,
1234     _In_ UCHAR TargetId,
1235     _In_ UCHAR Lun,
1236     _In_ ULONG TimeOut)
1237 {
1238     DPRINT1("StorPortPauseDevice()\n");
1239     UNIMPLEMENTED;
1240     return FALSE;
1241 }
1242 
1243 
1244 #if defined(_M_AMD64)
1245 /*
1246  * @implemented
1247  */
1248 /* KeQuerySystemTime is an inline function,
1249    so we cannot forward the export to ntoskrnl */
1250 STORPORT_API
1251 VOID
1252 NTAPI
StorPortQuerySystemTime(_Out_ PLARGE_INTEGER CurrentTime)1253 StorPortQuerySystemTime(
1254     _Out_ PLARGE_INTEGER CurrentTime)
1255 {
1256     DPRINT1("StorPortQuerySystemTime(%p)\n", CurrentTime);
1257 
1258     KeQuerySystemTime(CurrentTime);
1259 }
1260 #endif /* defined(_M_AMD64) */
1261 
1262 
1263 /*
1264  * @unimplemented
1265  */
1266 STORPORT_API
1267 BOOLEAN
1268 NTAPI
StorPortReady(_In_ PVOID HwDeviceExtension)1269 StorPortReady(
1270     _In_ PVOID HwDeviceExtension)
1271 {
1272     DPRINT1("StorPortReady()\n");
1273     UNIMPLEMENTED;
1274     return FALSE;
1275 }
1276 
1277 
1278 /*
1279  * @unimplemented
1280  */
1281 STORPORT_API
1282 BOOLEAN
1283 NTAPI
StorPortRegistryRead(_In_ PVOID HwDeviceExtension,_In_ PUCHAR ValueName,_In_ ULONG Global,_In_ ULONG Type,_In_ PUCHAR Buffer,_In_ PULONG BufferLength)1284 StorPortRegistryRead(
1285     _In_ PVOID HwDeviceExtension,
1286     _In_ PUCHAR ValueName,
1287     _In_ ULONG Global,
1288     _In_ ULONG Type,
1289     _In_ PUCHAR Buffer,
1290     _In_ PULONG BufferLength)
1291 {
1292     DPRINT1("StorPortRegistryRead()\n");
1293     UNIMPLEMENTED;
1294     return FALSE;
1295 }
1296 
1297 
1298 /*
1299  * @unimplemented
1300  */
1301 STORPORT_API
1302 BOOLEAN
1303 NTAPI
StorPortRegistryWrite(_In_ PVOID HwDeviceExtension,_In_ PUCHAR ValueName,_In_ ULONG Global,_In_ ULONG Type,_In_ PUCHAR Buffer,_In_ ULONG BufferLength)1304 StorPortRegistryWrite(
1305     _In_ PVOID HwDeviceExtension,
1306     _In_ PUCHAR ValueName,
1307     _In_ ULONG Global,
1308     _In_ ULONG Type,
1309     _In_ PUCHAR Buffer,
1310     _In_ ULONG BufferLength)
1311 {
1312     DPRINT1("StorPortRegistryWrite()\n");
1313     UNIMPLEMENTED;
1314     return FALSE;
1315 }
1316 
1317 
1318 /*
1319  * @unimplemented
1320  */
1321 STORPORT_API
1322 BOOLEAN
1323 NTAPI
StorPortResume(_In_ PVOID HwDeviceExtension)1324 StorPortResume(
1325     _In_ PVOID HwDeviceExtension)
1326 {
1327     DPRINT1("StorPortResume()\n");
1328     UNIMPLEMENTED;
1329     return FALSE;
1330 }
1331 
1332 
1333 /*
1334  * @unimplemented
1335  */
1336 STORPORT_API
1337 BOOLEAN
1338 NTAPI
StorPortResumeDevice(_In_ PVOID HwDeviceExtension,_In_ UCHAR PathId,_In_ UCHAR TargetId,_In_ UCHAR Lun)1339 StorPortResumeDevice(
1340     _In_ PVOID HwDeviceExtension,
1341     _In_ UCHAR PathId,
1342     _In_ UCHAR TargetId,
1343     _In_ UCHAR Lun)
1344 {
1345     DPRINT1("StorPortResumeDevice()\n");
1346     UNIMPLEMENTED;
1347     return FALSE;
1348 }
1349 
1350 
1351 /*
1352  * @implemented
1353  */
1354 STORPORT_API
1355 ULONG
1356 NTAPI
StorPortSetBusDataByOffset(_In_ PVOID DeviceExtension,_In_ ULONG BusDataType,_In_ ULONG SystemIoBusNumber,_In_ ULONG SlotNumber,_In_reads_bytes_ (Length)PVOID Buffer,_In_ ULONG Offset,_In_ ULONG Length)1357 StorPortSetBusDataByOffset(
1358     _In_ PVOID DeviceExtension,
1359     _In_ ULONG BusDataType,
1360     _In_ ULONG SystemIoBusNumber,
1361     _In_ ULONG SlotNumber,
1362     _In_reads_bytes_(Length) PVOID Buffer,
1363     _In_ ULONG Offset,
1364     _In_ ULONG Length)
1365 {
1366     PMINIPORT_DEVICE_EXTENSION MiniportExtension;
1367     PBUS_INTERFACE_STANDARD Interface;
1368     ULONG ReturnLength;
1369 
1370     DPRINT1("StorPortSetBusData(%p %lu %lu %lu %p %lu %lu)\n",
1371             DeviceExtension, BusDataType, SystemIoBusNumber, SlotNumber, Buffer, Offset, Length);
1372 
1373     MiniportExtension = CONTAINING_RECORD(DeviceExtension,
1374                                           MINIPORT_DEVICE_EXTENSION,
1375                                           HwDeviceExtension);
1376     DPRINT1("DeviceExtension %p  MiniportExtension %p\n",
1377             DeviceExtension, MiniportExtension);
1378 
1379     Interface = &MiniportExtension->Miniport->DeviceExtension->BusInterface;
1380 
1381     ReturnLength = Interface->SetBusData(Interface->Context,
1382                                          BusDataType,
1383                                          Buffer,
1384                                          Offset,
1385                                          Length);
1386     DPRINT1("ReturnLength: %lu\n", ReturnLength);
1387 
1388     return ReturnLength;
1389 }
1390 
1391 
1392 /*
1393  * @unimplemented
1394  */
1395 STORPORT_API
1396 BOOLEAN
1397 NTAPI
StorPortSetDeviceQueueDepth(_In_ PVOID HwDeviceExtension,_In_ UCHAR PathId,_In_ UCHAR TargetId,_In_ UCHAR Lun,_In_ ULONG Depth)1398 StorPortSetDeviceQueueDepth(
1399     _In_ PVOID HwDeviceExtension,
1400     _In_ UCHAR PathId,
1401     _In_ UCHAR TargetId,
1402     _In_ UCHAR Lun,
1403     _In_ ULONG Depth)
1404 {
1405     DPRINT1("StorPortSetDeviceQueueDepth()\n");
1406     UNIMPLEMENTED;
1407     return FALSE;
1408 }
1409 
1410 
1411 /*
1412  * @implemented
1413  */
1414 STORPORT_API
1415 VOID
1416 NTAPI
StorPortStallExecution(_In_ ULONG Delay)1417 StorPortStallExecution(
1418     _In_ ULONG Delay)
1419 {
1420     KeStallExecutionProcessor(Delay);
1421 }
1422 
1423 
1424 /*
1425  * @unimplemented
1426  */
1427 STORPORT_API
1428 VOID
1429 NTAPI
StorPortSynchronizeAccess(_In_ PVOID HwDeviceExtension,_In_ PSTOR_SYNCHRONIZED_ACCESS SynchronizedAccessRoutine,_In_opt_ PVOID Context)1430 StorPortSynchronizeAccess(
1431     _In_ PVOID HwDeviceExtension,
1432     _In_ PSTOR_SYNCHRONIZED_ACCESS SynchronizedAccessRoutine,
1433     _In_opt_ PVOID Context)
1434 {
1435     DPRINT1("StorPortSynchronizeAccess()\n");
1436     UNIMPLEMENTED;
1437 }
1438 
1439 
1440 /*
1441  * @implemented
1442  */
1443 STORPORT_API
1444 BOOLEAN
1445 NTAPI
StorPortValidateRange(_In_ PVOID HwDeviceExtension,_In_ INTERFACE_TYPE BusType,_In_ ULONG SystemIoBusNumber,_In_ STOR_PHYSICAL_ADDRESS IoAddress,_In_ ULONG NumberOfBytes,_In_ BOOLEAN InIoSpace)1446 StorPortValidateRange(
1447     _In_ PVOID HwDeviceExtension,
1448     _In_ INTERFACE_TYPE BusType,
1449     _In_ ULONG SystemIoBusNumber,
1450     _In_ STOR_PHYSICAL_ADDRESS IoAddress,
1451     _In_ ULONG NumberOfBytes,
1452     _In_ BOOLEAN InIoSpace)
1453 {
1454     DPRINT1("StorPortValidateRange()\n");
1455     return TRUE;
1456 }
1457 
1458 /* EOF */
1459