[STORPORT] Implement StorPortSetBusDataByOffset.
[reactos.git] / drivers / storage / port / storport / storport.c
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
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
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
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 NTSTATUS
105 NTAPI
106 PortAddDevice(
107 _In_ PDRIVER_OBJECT DriverObject,
108 _In_ PDEVICE_OBJECT PhysicalDeviceObject)
109 {
110 PDRIVER_OBJECT_EXTENSION DriverObjectExtension;
111 PFDO_DEVICE_EXTENSION DeviceExtension = NULL;
112 WCHAR NameBuffer[80];
113 UNICODE_STRING DeviceName;
114 PDEVICE_OBJECT Fdo = NULL;
115 KLOCK_QUEUE_HANDLE LockHandle;
116 NTSTATUS Status;
117
118 DPRINT1("PortAddDevice(%p %p)\n",
119 DriverObject, PhysicalDeviceObject);
120
121 ASSERT(DriverObject);
122 ASSERT(PhysicalDeviceObject);
123
124 swprintf(NameBuffer,
125 L"\\Device\\RaidPort%lu",
126 PortNumber);
127 RtlInitUnicodeString(&DeviceName, NameBuffer);
128 PortNumber++;
129
130 DPRINT1("Creating device: %wZ\n", &DeviceName);
131
132 /* Create the port device */
133 Status = IoCreateDevice(DriverObject,
134 sizeof(FDO_DEVICE_EXTENSION),
135 &DeviceName,
136 FILE_DEVICE_CONTROLLER,
137 FILE_DEVICE_SECURE_OPEN,
138 FALSE,
139 &Fdo);
140 if (!NT_SUCCESS(Status))
141 {
142 DPRINT1("IoCreateDevice() failed (Status 0x%08lx)\n", Status);
143 return Status;
144 }
145
146 DPRINT1("Created device: %wZ (%p)\n", &DeviceName, Fdo);
147
148 /* Initialize the device */
149 Fdo->Flags |= DO_DIRECT_IO;
150 Fdo->Flags |= DO_POWER_PAGABLE;
151
152 /* Initialize the device extension */
153 DeviceExtension = (PFDO_DEVICE_EXTENSION)Fdo->DeviceExtension;
154 RtlZeroMemory(DeviceExtension, sizeof(FDO_DEVICE_EXTENSION));
155
156 DeviceExtension->ExtensionType = FdoExtension;
157
158 DeviceExtension->Device = Fdo;
159 DeviceExtension->PhysicalDevice = PhysicalDeviceObject;
160
161 DeviceExtension->PnpState = dsStopped;
162
163 /* Attach the FDO to the device stack */
164 Status = IoAttachDeviceToDeviceStackSafe(Fdo,
165 PhysicalDeviceObject,
166 &DeviceExtension->LowerDevice);
167 if (!NT_SUCCESS(Status))
168 {
169 DPRINT1("IoAttachDeviceToDeviceStackSafe() failed (Status 0x%08lx)\n", Status);
170 IoDeleteDevice(Fdo);
171 return Status;
172 }
173
174 /* Insert the FDO to the drivers FDO list */
175 DriverObjectExtension = IoGetDriverObjectExtension(DriverObject,
176 (PVOID)DriverEntry);
177 ASSERT(DriverObjectExtension->ExtensionType == DriverExtension);
178
179 DeviceExtension->DriverExtension = DriverObjectExtension;
180
181 KeAcquireInStackQueuedSpinLock(&DriverObjectExtension->AdapterListLock,
182 &LockHandle);
183
184 InsertHeadList(&DriverObjectExtension->AdapterListHead,
185 &DeviceExtension->AdapterListEntry);
186 DriverObjectExtension->AdapterCount++;
187
188 KeReleaseInStackQueuedSpinLock(&LockHandle);
189
190 /* The device has been initialized */
191 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
192
193 DPRINT1("PortAddDevice() done (Status 0x%08lx)\n", Status);
194
195 return Status;
196 }
197
198
199 static
200 VOID
201 NTAPI
202 PortUnload(
203 _In_ PDRIVER_OBJECT DriverObject)
204 {
205 PDRIVER_OBJECT_EXTENSION DriverExtension;
206
207 DPRINT1("PortUnload(%p)\n",
208 DriverObject);
209
210 DriverExtension = IoGetDriverObjectExtension(DriverObject,
211 (PVOID)DriverEntry);
212 if (DriverExtension != NULL)
213 {
214 PortDeleteDriverInitData(DriverExtension);
215 }
216 }
217
218
219 static
220 NTSTATUS
221 NTAPI
222 PortDispatchCreate(
223 IN PDEVICE_OBJECT DeviceObject,
224 IN PIRP Irp)
225 {
226 DPRINT1("PortDispatchCreate(%p %p)\n",
227 DeviceObject, Irp);
228
229 Irp->IoStatus.Status = STATUS_SUCCESS;
230 Irp->IoStatus.Information = FILE_OPENED;
231
232 IoCompleteRequest(Irp, IO_NO_INCREMENT);
233
234 return STATUS_SUCCESS;
235 }
236
237
238 static
239 NTSTATUS
240 NTAPI
241 PortDispatchClose(
242 IN PDEVICE_OBJECT DeviceObject,
243 IN PIRP Irp)
244 {
245 DPRINT1("PortDispatchClose(%p %p)\n",
246 DeviceObject, Irp);
247
248 Irp->IoStatus.Status = STATUS_SUCCESS;
249 Irp->IoStatus.Information = 0;
250
251 IoCompleteRequest(Irp, IO_NO_INCREMENT);
252
253 return STATUS_SUCCESS;
254 }
255
256
257 static
258 NTSTATUS
259 NTAPI
260 PortDispatchDeviceControl(
261 IN PDEVICE_OBJECT DeviceObject,
262 IN PIRP Irp)
263 {
264 DPRINT1("PortDispatchDeviceControl(%p %p)\n",
265 DeviceObject, Irp);
266
267 Irp->IoStatus.Status = STATUS_SUCCESS;
268 Irp->IoStatus.Information = 0;
269
270 IoCompleteRequest(Irp, IO_NO_INCREMENT);
271
272 return STATUS_SUCCESS;
273 }
274
275
276 static
277 NTSTATUS
278 NTAPI
279 PortDispatchScsi(
280 IN PDEVICE_OBJECT DeviceObject,
281 IN PIRP Irp)
282 {
283 DPRINT1("PortDispatchScsi(%p %p)\n",
284 DeviceObject, Irp);
285
286 Irp->IoStatus.Status = STATUS_SUCCESS;
287 Irp->IoStatus.Information = 0;
288
289 IoCompleteRequest(Irp, IO_NO_INCREMENT);
290
291 return STATUS_SUCCESS;
292 }
293
294
295 static
296 NTSTATUS
297 NTAPI
298 PortDispatchSystemControl(
299 IN PDEVICE_OBJECT DeviceObject,
300 IN PIRP Irp)
301 {
302 DPRINT1("PortDispatchSystemControl(%p %p)\n",
303 DeviceObject, Irp);
304
305 Irp->IoStatus.Status = STATUS_SUCCESS;
306 Irp->IoStatus.Information = 0;
307
308 IoCompleteRequest(Irp, IO_NO_INCREMENT);
309
310 return STATUS_SUCCESS;
311 }
312
313
314 static
315 NTSTATUS
316 NTAPI
317 PortDispatchPnp(
318 IN PDEVICE_OBJECT DeviceObject,
319 IN PIRP Irp)
320 {
321 PFDO_DEVICE_EXTENSION DeviceExtension;
322
323 DPRINT1("PortDispatchPnp(%p %p)\n",
324 DeviceObject, Irp);
325
326 DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
327 DPRINT1("ExtensionType: %u\n", DeviceExtension->ExtensionType);
328
329 switch (DeviceExtension->ExtensionType)
330 {
331 case FdoExtension:
332 return PortFdoPnp(DeviceObject,
333 Irp);
334
335 case PdoExtension:
336 return PortPdoPnp(DeviceObject,
337 Irp);
338
339 default:
340 Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
341 Irp->IoStatus.Information = 0;
342 IoCompleteRequest(Irp, IO_NO_INCREMENT);
343 return STATUS_UNSUCCESSFUL;
344 }
345 }
346
347
348 static
349 NTSTATUS
350 NTAPI
351 PortDispatchPower(
352 IN PDEVICE_OBJECT DeviceObject,
353 IN PIRP Irp)
354 {
355 DPRINT1("PortDispatchPower(%p %p)\n",
356 DeviceObject, Irp);
357
358 Irp->IoStatus.Status = STATUS_SUCCESS;
359 Irp->IoStatus.Information = 0;
360
361 IoCompleteRequest(Irp, IO_NO_INCREMENT);
362
363 return STATUS_SUCCESS;
364 }
365
366
367 /* PUBLIC FUNCTIONS ***********************************************************/
368
369 /*
370 * @implemented
371 */
372 NTSTATUS
373 NTAPI
374 DriverEntry(
375 _In_ PDRIVER_OBJECT DriverObject,
376 _In_ PUNICODE_STRING RegistryPath)
377 {
378 DPRINT1("DriverEntry(%p %p)\n", DriverObject, RegistryPath);
379 return STATUS_SUCCESS;
380 }
381
382
383 /*
384 * @unimplemented
385 */
386 STORPORT_API
387 PUCHAR
388 NTAPI
389 StorPortAllocateRegistryBuffer(
390 _In_ PVOID HwDeviceExtension,
391 _In_ PULONG Length)
392 {
393 DPRINT1("StorPortAllocateRegistryBuffer()\n");
394 UNIMPLEMENTED;
395 return NULL;
396 }
397
398
399 /*
400 * @unimplemented
401 */
402 STORPORT_API
403 BOOLEAN
404 NTAPI
405 StorPortBusy(
406 _In_ PVOID HwDeviceExtension,
407 _In_ ULONG RequestsToComplete)
408 {
409 DPRINT1("StorPortBuzy()\n");
410 UNIMPLEMENTED;
411 return FALSE;
412 }
413
414
415 /*
416 * @unimplemented
417 */
418 STORPORT_API
419 VOID
420 NTAPI
421 StorPortCompleteRequest(
422 _In_ PVOID HwDeviceExtension,
423 _In_ UCHAR PathId,
424 _In_ UCHAR TargetId,
425 _In_ UCHAR Lun,
426 _In_ UCHAR SrbStatus)
427 {
428 DPRINT1("StorPortCompleteRequest()\n");
429 UNIMPLEMENTED;
430 }
431
432
433 /*
434 * @implemented
435 */
436 STORPORT_API
437 ULONG
438 NTAPI
439 StorPortConvertPhysicalAddressToUlong(
440 _In_ STOR_PHYSICAL_ADDRESS Address)
441 {
442 DPRINT1("StorPortConvertPhysicalAddressToUlong()\n");
443
444 return Address.u.LowPart;
445 }
446
447
448 /*
449 * @implemented
450 */
451 STORPORT_API
452 STOR_PHYSICAL_ADDRESS
453 NTAPI
454 StorPortConvertUlongToPhysicalAddress(
455 _In_ ULONG_PTR UlongAddress)
456 {
457 STOR_PHYSICAL_ADDRESS Address;
458
459 DPRINT1("StorPortConvertUlongToPhysicalAddress()\n");
460
461 Address.QuadPart = UlongAddress;
462 return Address;
463 }
464
465
466 /*
467 * @implemented
468 */
469 STORPORT_API
470 VOID
471 StorPortDebugPrint(
472 _In_ ULONG DebugPrintLevel,
473 _In_ PCHAR DebugMessage,
474 ...)
475 {
476 va_list ap;
477
478 va_start(ap, DebugMessage);
479 vDbgPrintExWithPrefix("STORMINI: ", 0x58, DebugPrintLevel, DebugMessage, ap);
480 va_end(ap);
481 }
482
483
484 /*
485 * @unimplemented
486 */
487 STORPORT_API
488 BOOLEAN
489 NTAPI
490 StorPortDeviceBusy(
491 _In_ PVOID HwDeviceExtension,
492 _In_ UCHAR PathId,
493 _In_ UCHAR TargetId,
494 _In_ UCHAR Lun,
495 _In_ ULONG RequestsToComplete)
496 {
497 DPRINT1("StorPortDeviceBusy()\n");
498 UNIMPLEMENTED;
499 return FALSE;
500 }
501
502
503 /*
504 * @unimplemented
505 */
506 STORPORT_API
507 BOOLEAN
508 NTAPI
509 StorPortDeviceReady(
510 _In_ PVOID HwDeviceExtension,
511 _In_ UCHAR PathId,
512 _In_ UCHAR TargetId,
513 _In_ UCHAR Lun)
514 {
515 DPRINT1("StorPortDeviceReady()\n");
516 UNIMPLEMENTED;
517 return FALSE;
518 }
519
520
521 /*
522 * @implemented
523 */
524 STORPORT_API
525 VOID
526 NTAPI
527 StorPortFreeDeviceBase(
528 _In_ PVOID HwDeviceExtension,
529 _In_ PVOID MappedAddress)
530 {
531 DPRINT1("StorPortFreeDeviceBase()\n");
532 }
533
534
535 /*
536 * @unimplemented
537 */
538 STORPORT_API
539 VOID
540 NTAPI
541 StorPortFreeRegistryBuffer(
542 _In_ PVOID HwDeviceExtension,
543 _In_ PUCHAR Buffer)
544 {
545 DPRINT1("StorPortFreeRegistryBuffer()\n");
546 UNIMPLEMENTED;
547 }
548
549
550 /*
551 * @implemented
552 */
553 STORPORT_API
554 ULONG
555 NTAPI
556 StorPortGetBusData(
557 _In_ PVOID DeviceExtension,
558 _In_ ULONG BusDataType,
559 _In_ ULONG SystemIoBusNumber,
560 _In_ ULONG SlotNumber,
561 _Out_ _When_(Length != 0, _Out_writes_bytes_(Length)) PVOID Buffer,
562 _In_ ULONG Length)
563 {
564 PMINIPORT_DEVICE_EXTENSION MiniportExtension;
565 PBUS_INTERFACE_STANDARD Interface;
566 ULONG ReturnLength;
567
568 DPRINT1("StorPortGetBusData(%p %lu %lu %lu %p %lu)\n",
569 DeviceExtension, BusDataType, SystemIoBusNumber, SlotNumber, Buffer, Length);
570
571 MiniportExtension = CONTAINING_RECORD(DeviceExtension,
572 MINIPORT_DEVICE_EXTENSION,
573 HwDeviceExtension);
574 DPRINT1("DeviceExtension %p MiniportExtension %p\n",
575 DeviceExtension, MiniportExtension);
576
577 Interface = &MiniportExtension->Miniport->DeviceExtension->BusInterface;
578
579 if (BusDataType == 4)
580 BusDataType = 0;
581
582 ReturnLength = Interface->GetBusData(Interface->Context,
583 BusDataType,
584 Buffer,
585 0,
586 Length);
587 DPRINT1("ReturnLength: %lu\n", ReturnLength);
588
589 return ReturnLength;
590 }
591
592
593 /*
594 * @unimplemented
595 */
596 STORPORT_API
597 PVOID
598 NTAPI
599 StorPortGetDeviceBase(
600 _In_ PVOID HwDeviceExtension,
601 _In_ INTERFACE_TYPE BusType,
602 _In_ ULONG SystemIoBusNumber,
603 _In_ STOR_PHYSICAL_ADDRESS IoAddress,
604 _In_ ULONG NumberOfBytes,
605 _In_ BOOLEAN InIoSpace)
606 {
607 DPRINT1("StorPortGetDeviceBase()\n");
608 UNIMPLEMENTED;
609 return NULL;
610 }
611
612
613 /*
614 * @unimplemented
615 */
616 STORPORT_API
617 PVOID
618 NTAPI
619 StorPortGetLogicalUnit(
620 _In_ PVOID HwDeviceExtension,
621 _In_ UCHAR PathId,
622 _In_ UCHAR TargetId,
623 _In_ UCHAR Lun)
624 {
625 DPRINT1("StorPortGetLogicalUnit()\n");
626 UNIMPLEMENTED;
627 return NULL;
628 }
629
630
631 /*
632 * @unimplemented
633 */
634 STORPORT_API
635 STOR_PHYSICAL_ADDRESS
636 NTAPI
637 StorPortGetPhysicalAddress(
638 _In_ PVOID HwDeviceExtension,
639 _In_opt_ PSCSI_REQUEST_BLOCK Srb,
640 _In_ PVOID VirtualAddress,
641 _Out_ ULONG *Length)
642 {
643 STOR_PHYSICAL_ADDRESS PhysicalAddress;
644
645 DPRINT1("StorPortGetPhysicalAddress(%p %p %p %p)\n",
646 HwDeviceExtension, Srb, VirtualAddress, Length);
647 UNIMPLEMENTED;
648
649 *Length = 0;
650 PhysicalAddress.QuadPart = (LONGLONG)0;
651
652 return PhysicalAddress;
653 }
654
655
656 /*
657 * @unimplemented
658 */
659 STORPORT_API
660 PSTOR_SCATTER_GATHER_LIST
661 NTAPI
662 StorPortGetScatterGatherList(
663 _In_ PVOID DeviceExtension,
664 _In_ PSCSI_REQUEST_BLOCK Srb)
665 {
666 DPRINT1("StorPortGetScatterGatherList()\n");
667 UNIMPLEMENTED;
668 return NULL;
669 }
670
671
672 /*
673 * @implemented
674 */
675 STORPORT_API
676 PSCSI_REQUEST_BLOCK
677 NTAPI
678 StorPortGetSrb(
679 _In_ PVOID DeviceExtension,
680 _In_ UCHAR PathId,
681 _In_ UCHAR TargetId,
682 _In_ UCHAR Lun,
683 _In_ LONG QueueTag)
684 {
685 DPRINT("StorPortGetSrb()\n");
686 return NULL;
687 }
688
689
690 /*
691 * @unimplemented
692 */
693 STORPORT_API
694 PVOID
695 NTAPI
696 StorPortGetUncachedExtension(
697 _In_ PVOID HwDeviceExtension,
698 _In_ PPORT_CONFIGURATION_INFORMATION ConfigInfo,
699 _In_ ULONG NumberOfBytes)
700 {
701 DPRINT1("StorPortGetUncachedExtension(%p %p %lu)\n",
702 HwDeviceExtension, ConfigInfo, NumberOfBytes);
703 UNIMPLEMENTED;
704 return NULL;
705 }
706
707
708 /*
709 * @unimplemented
710 */
711 STORPORT_API
712 PVOID
713 NTAPI
714 StorPortGetVirtualAddress(
715 _In_ PVOID HwDeviceExtension,
716 _In_ STOR_PHYSICAL_ADDRESS PhysicalAddress)
717 {
718 DPRINT1("StorPortGetVirtualAddress(%p %I64x)\n",
719 HwDeviceExtension, PhysicalAddress.QuadPart);
720 UNIMPLEMENTED;
721 return NULL;
722 }
723
724
725 /*
726 * @implemented
727 */
728 STORPORT_API
729 ULONG
730 NTAPI
731 StorPortInitialize(
732 _In_ PVOID Argument1,
733 _In_ PVOID Argument2,
734 _In_ struct _HW_INITIALIZATION_DATA *HwInitializationData,
735 _In_opt_ PVOID HwContext)
736 {
737 PDRIVER_OBJECT DriverObject = (PDRIVER_OBJECT)Argument1;
738 PUNICODE_STRING RegistryPath = (PUNICODE_STRING)Argument2;
739 PDRIVER_OBJECT_EXTENSION DriverObjectExtension;
740 NTSTATUS Status = STATUS_SUCCESS;
741
742 DPRINT1("StorPortInitialize(%p %p %p %p)\n",
743 Argument1, Argument2, HwInitializationData, HwContext);
744
745 DPRINT1("HwInitializationDataSize: %lu\n", HwInitializationData->HwInitializationDataSize);
746 DPRINT1("AdapterInterfaceType: %u\n", HwInitializationData->AdapterInterfaceType);
747 DPRINT1("HwInitialize: %p\n", HwInitializationData->HwInitialize);
748 DPRINT1("HwStartIo: %p\n", HwInitializationData->HwStartIo);
749 DPRINT1("HwInterrupt: %p\n", HwInitializationData->HwInterrupt);
750 DPRINT1("HwFindAdapter: %p\n", HwInitializationData->HwFindAdapter);
751 DPRINT1("HwResetBus: %p\n", HwInitializationData->HwResetBus);
752 DPRINT1("HwDmaStarted: %p\n", HwInitializationData->HwDmaStarted);
753 DPRINT1("HwAdapterState: %p\n", HwInitializationData->HwAdapterState);
754 DPRINT1("DeviceExtensionSize: %lu\n", HwInitializationData->DeviceExtensionSize);
755 DPRINT1("SpecificLuExtensionSize: %lu\n", HwInitializationData->SpecificLuExtensionSize);
756 DPRINT1("SrbExtensionSize: %lu\n", HwInitializationData->SrbExtensionSize);
757 DPRINT1("NumberOfAccessRanges: %lu\n", HwInitializationData->NumberOfAccessRanges);
758
759 /* Check parameters */
760 if ((DriverObject == NULL) ||
761 (RegistryPath == NULL) ||
762 (HwInitializationData == NULL))
763 {
764 DPRINT1("Invalid parameter!\n");
765 return STATUS_INVALID_PARAMETER;
766 }
767
768 /* Check initialization data */
769 if ((HwInitializationData->HwInitializationDataSize < sizeof(HW_INITIALIZATION_DATA)) ||
770 (HwInitializationData->HwInitialize == NULL) ||
771 (HwInitializationData->HwStartIo == NULL) ||
772 (HwInitializationData->HwFindAdapter == NULL) ||
773 (HwInitializationData->HwResetBus == NULL))
774 {
775 DPRINT1("Revision mismatch!\n");
776 return STATUS_REVISION_MISMATCH;
777 }
778
779 DriverObjectExtension = IoGetDriverObjectExtension(DriverObject,
780 (PVOID)DriverEntry);
781 if (DriverObjectExtension == NULL)
782 {
783 DPRINT1("No driver object extension!\n");
784
785 Status = IoAllocateDriverObjectExtension(DriverObject,
786 (PVOID)DriverEntry,
787 sizeof(DRIVER_OBJECT_EXTENSION),
788 (PVOID *)&DriverObjectExtension);
789 if (!NT_SUCCESS(Status))
790 {
791 DPRINT1("IoAllocateDriverObjectExtension() failed (Status 0x%08lx)\n", Status);
792 return Status;
793 }
794
795 DPRINT1("Driver object extension created!\n");
796
797 /* Initialize the driver object extension */
798 RtlZeroMemory(DriverObjectExtension,
799 sizeof(DRIVER_OBJECT_EXTENSION));
800
801 DriverObjectExtension->ExtensionType = DriverExtension;
802 DriverObjectExtension->DriverObject = DriverObject;
803
804 InitializeListHead(&DriverObjectExtension->AdapterListHead);
805 KeInitializeSpinLock(&DriverObjectExtension->AdapterListLock);
806
807 InitializeListHead(&DriverObjectExtension->InitDataListHead);
808
809 /* Set handlers */
810 DriverObject->DriverExtension->AddDevice = PortAddDevice;
811 // DriverObject->DriverStartIo = PortStartIo;
812 DriverObject->DriverUnload = PortUnload;
813 DriverObject->MajorFunction[IRP_MJ_CREATE] = PortDispatchCreate;
814 DriverObject->MajorFunction[IRP_MJ_CLOSE] = PortDispatchClose;
815 DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = PortDispatchDeviceControl;
816 DriverObject->MajorFunction[IRP_MJ_SCSI] = PortDispatchScsi;
817 DriverObject->MajorFunction[IRP_MJ_POWER] = PortDispatchPower;
818 DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = PortDispatchSystemControl;
819 DriverObject->MajorFunction[IRP_MJ_PNP] = PortDispatchPnp;
820 }
821
822 /* Add the initialzation data to the driver extension */
823 Status = PortAddDriverInitData(DriverObjectExtension,
824 HwInitializationData);
825
826 DPRINT1("StorPortInitialize() done (Status 0x%08lx)\n", Status);
827
828 return Status;
829 }
830
831
832 /*
833 * @unimplemented
834 */
835 STORPORT_API
836 VOID
837 NTAPI
838 StorPortLogError(
839 _In_ PVOID HwDeviceExtension,
840 _In_opt_ PSCSI_REQUEST_BLOCK Srb,
841 _In_ UCHAR PathId,
842 _In_ UCHAR TargetId,
843 _In_ UCHAR Lun,
844 _In_ ULONG ErrorCode,
845 _In_ ULONG UniqueId)
846 {
847 DPRINT1("ScsiPortLogError() called\n");
848 DPRINT1("PathId: 0x%02x TargetId: 0x%02x Lun: 0x%02x ErrorCode: 0x%08lx UniqueId: 0x%08lx\n",
849 PathId, TargetId, Lun, ErrorCode, UniqueId);
850
851 DPRINT1("ScsiPortLogError() done\n");
852 }
853
854
855 /*
856 * @implemented
857 */
858 STORPORT_API
859 VOID
860 NTAPI
861 StorPortMoveMemory(
862 _Out_writes_bytes_(Length) PVOID Destination,
863 _In_reads_bytes_(Length) PVOID Source,
864 _In_ ULONG Length)
865 {
866 RtlMoveMemory(Destination, Source, Length);
867 }
868
869
870 /*
871 * @unimplemented
872 */
873 STORPORT_API
874 VOID
875 StorPortNotification(
876 _In_ SCSI_NOTIFICATION_TYPE NotificationType,
877 _In_ PVOID HwDeviceExtension,
878 ...)
879 {
880 DPRINT1("StorPortNotification()\n");
881 }
882
883
884 /*
885 * @unimplemented
886 */
887 STORPORT_API
888 BOOLEAN
889 NTAPI
890 StorPortPause(
891 _In_ PVOID HwDeviceExtension,
892 _In_ ULONG TimeOut)
893 {
894 DPRINT1("StorPortPause()\n");
895 UNIMPLEMENTED;
896 return FALSE;
897 }
898
899
900 /*
901 * @unimplemented
902 */
903 STORPORT_API
904 BOOLEAN
905 NTAPI
906 StorPortPauseDevice(
907 _In_ PVOID HwDeviceExtension,
908 _In_ UCHAR PathId,
909 _In_ UCHAR TargetId,
910 _In_ UCHAR Lun,
911 _In_ ULONG TimeOut)
912 {
913 DPRINT1("StorPortPauseDevice()\n");
914 UNIMPLEMENTED;
915 return FALSE;
916 }
917
918
919 /*
920 * @unimplemented
921 */
922 STORPORT_API
923 BOOLEAN
924 NTAPI
925 StorPortReady(
926 _In_ PVOID HwDeviceExtension)
927 {
928 DPRINT1("StorPortReady()\n");
929 UNIMPLEMENTED;
930 return FALSE;
931 }
932
933
934 /*
935 * @unimplemented
936 */
937 STORPORT_API
938 BOOLEAN
939 NTAPI
940 StorPortRegistryRead(
941 _In_ PVOID HwDeviceExtension,
942 _In_ PUCHAR ValueName,
943 _In_ ULONG Global,
944 _In_ ULONG Type,
945 _In_ PUCHAR Buffer,
946 _In_ PULONG BufferLength)
947 {
948 DPRINT1("StorPortRegistryRead()\n");
949 UNIMPLEMENTED;
950 return FALSE;
951 }
952
953
954 /*
955 * @unimplemented
956 */
957 STORPORT_API
958 BOOLEAN
959 NTAPI
960 StorPortRegistryWrite(
961 _In_ PVOID HwDeviceExtension,
962 _In_ PUCHAR ValueName,
963 _In_ ULONG Global,
964 _In_ ULONG Type,
965 _In_ PUCHAR Buffer,
966 _In_ ULONG BufferLength)
967 {
968 DPRINT1("StorPortRegistryWrite()\n");
969 UNIMPLEMENTED;
970 return FALSE;
971 }
972
973
974 /*
975 * @unimplemented
976 */
977 STORPORT_API
978 BOOLEAN
979 NTAPI
980 StorPortResume(
981 _In_ PVOID HwDeviceExtension)
982 {
983 DPRINT1("StorPortResume()\n");
984 UNIMPLEMENTED;
985 return FALSE;
986 }
987
988
989 /*
990 * @unimplemented
991 */
992 STORPORT_API
993 BOOLEAN
994 NTAPI
995 StorPortResumeDevice(
996 _In_ PVOID HwDeviceExtension,
997 _In_ UCHAR PathId,
998 _In_ UCHAR TargetId,
999 _In_ UCHAR Lun)
1000 {
1001 DPRINT1("StorPortResumeDevice()\n");
1002 UNIMPLEMENTED;
1003 return FALSE;
1004 }
1005
1006
1007 /*
1008 * @implemented
1009 */
1010 STORPORT_API
1011 ULONG
1012 NTAPI
1013 StorPortSetBusDataByOffset(
1014 _In_ PVOID DeviceExtension,
1015 _In_ ULONG BusDataType,
1016 _In_ ULONG SystemIoBusNumber,
1017 _In_ ULONG SlotNumber,
1018 _In_reads_bytes_(Length) PVOID Buffer,
1019 _In_ ULONG Offset,
1020 _In_ ULONG Length)
1021 {
1022 PMINIPORT_DEVICE_EXTENSION MiniportExtension;
1023 PBUS_INTERFACE_STANDARD Interface;
1024 ULONG ReturnLength;
1025
1026 DPRINT1("StorPortSetBusData(%p %lu %lu %lu %p %lu %lu)\n",
1027 DeviceExtension, BusDataType, SystemIoBusNumber, SlotNumber, Buffer, Offset, Length);
1028
1029 MiniportExtension = CONTAINING_RECORD(DeviceExtension,
1030 MINIPORT_DEVICE_EXTENSION,
1031 HwDeviceExtension);
1032 DPRINT1("DeviceExtension %p MiniportExtension %p\n",
1033 DeviceExtension, MiniportExtension);
1034
1035 Interface = &MiniportExtension->Miniport->DeviceExtension->BusInterface;
1036
1037 ReturnLength = Interface->SetBusData(Interface->Context,
1038 BusDataType,
1039 Buffer,
1040 Offset,
1041 Length);
1042 DPRINT1("ReturnLength: %lu\n", ReturnLength);
1043
1044 return ReturnLength;
1045 }
1046
1047
1048 /*
1049 * @unimplemented
1050 */
1051 STORPORT_API
1052 BOOLEAN
1053 NTAPI
1054 StorPortSetDeviceQueueDepth(
1055 _In_ PVOID HwDeviceExtension,
1056 _In_ UCHAR PathId,
1057 _In_ UCHAR TargetId,
1058 _In_ UCHAR Lun,
1059 _In_ ULONG Depth)
1060 {
1061 DPRINT1("StorPortSetDeviceQueueDepth()\n");
1062 UNIMPLEMENTED;
1063 return FALSE;
1064 }
1065
1066
1067 /*
1068 * @implemented
1069 */
1070 STORPORT_API
1071 VOID
1072 NTAPI
1073 StorPortStallExecution(
1074 _In_ ULONG Delay)
1075 {
1076 KeStallExecutionProcessor(Delay);
1077 }
1078
1079
1080 /*
1081 * @unimplemented
1082 */
1083 STORPORT_API
1084 VOID
1085 NTAPI
1086 StorPortSynchronizeAccess(
1087 _In_ PVOID HwDeviceExtension,
1088 _In_ PSTOR_SYNCHRONIZED_ACCESS SynchronizedAccessRoutine,
1089 _In_opt_ PVOID Context)
1090 {
1091 DPRINT1("StorPortSynchronizeAccess()\n");
1092 UNIMPLEMENTED;
1093 }
1094
1095
1096 /*
1097 * @implemented
1098 */
1099 STORPORT_API
1100 BOOLEAN
1101 NTAPI
1102 StorPortValidateRange(
1103 _In_ PVOID HwDeviceExtension,
1104 _In_ INTERFACE_TYPE BusType,
1105 _In_ ULONG SystemIoBusNumber,
1106 _In_ STOR_PHYSICAL_ADDRESS IoAddress,
1107 _In_ ULONG NumberOfBytes,
1108 _In_ BOOLEAN InIoSpace)
1109 {
1110 DPRINT1("StorPortValidateRange()\n");
1111 return TRUE;
1112 }
1113
1114 /* EOF */