[STORPORT] Query the bus interface of the lower (bus) device and implement StorPortGe...
authorEric Kohl <eric.kohl@reactos.org>
Sun, 15 Oct 2017 22:13:21 +0000 (00:13 +0200)
committerEric Kohl <eric.kohl@reactos.org>
Sun, 15 Oct 2017 22:13:21 +0000 (00:13 +0200)
CORE-13866

drivers/storage/port/storport/fdo.c
drivers/storage/port/storport/misc.c
drivers/storage/port/storport/precomp.h
drivers/storage/port/storport/storport.c

index 3f569ac..70b6a30 100644 (file)
@@ -114,6 +114,20 @@ PortFdoStartDevice(
             return STATUS_NO_MEMORY;
     }
 
+    /* Get the bus interface of the lower (bus) device */
+    Status = QueryBusInterface(DeviceExtension->LowerDevice,
+                               (PGUID)&GUID_BUS_INTERFACE_STANDARD,
+                               sizeof(BUS_INTERFACE_STANDARD),
+                               1,
+                               &DeviceExtension->BusInterface,
+                               NULL);
+    DPRINT1("Status: 0x%08lx\n", Status);
+    if (NT_SUCCESS(Status))
+    {
+        DPRINT1("Context: %p\n", DeviceExtension->BusInterface.Context);
+        DeviceExtension->BusInitialized = TRUE;
+    }
+
     /* Start the miniport (FindAdapter & Initialize) */
     Status = PortFdoStartMiniport(DeviceExtension);
     if (!NT_SUCCESS(Status))
index 5f42be2..bcbdb05 100644 (file)
@@ -167,4 +167,54 @@ CopyResourceList(
 }
 
 
+NTSTATUS
+QueryBusInterface(
+    PDEVICE_OBJECT DeviceObject,
+    PGUID Guid,
+    USHORT Size,
+    USHORT Version,
+    PBUS_INTERFACE_STANDARD Interface,
+    PVOID InterfaceSpecificData)
+{
+    KEVENT Event;
+    NTSTATUS Status;
+    PIRP Irp;
+    IO_STATUS_BLOCK IoStatus;
+    PIO_STACK_LOCATION Stack;
+
+    KeInitializeEvent(&Event, NotificationEvent, FALSE);
+
+    Irp = IoBuildSynchronousFsdRequest(IRP_MJ_PNP,
+                                       DeviceObject,
+                                       NULL,
+                                       0,
+                                       NULL,
+                                       &Event,
+                                       &IoStatus);
+    if (Irp == NULL)
+        return STATUS_INSUFFICIENT_RESOURCES;
+
+    Stack = IoGetNextIrpStackLocation(Irp);
+
+    Stack->MajorFunction = IRP_MJ_PNP;
+    Stack->MinorFunction = IRP_MN_QUERY_INTERFACE;
+    Stack->Parameters.QueryInterface.InterfaceType = Guid;
+    Stack->Parameters.QueryInterface.Size = Size;
+    Stack->Parameters.QueryInterface.Version = Version;
+    Stack->Parameters.QueryInterface.Interface = (PINTERFACE)Interface;
+    Stack->Parameters.QueryInterface.InterfaceSpecificData = InterfaceSpecificData;
+
+    Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
+
+    Status = IoCallDriver(DeviceObject, Irp);
+    if (Status == STATUS_PENDING)
+    {
+        KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE, NULL);
+
+        Status=IoStatus.Status;
+    }
+
+    return Status;
+}
+
 /* EOF */
index beacc8e..1bbd70c 100644 (file)
@@ -93,6 +93,8 @@ typedef struct _FDO_DEVICE_EXTENSION
     ULONG SlotNumber;
     PCM_RESOURCE_LIST AllocatedResources;
     PCM_RESOURCE_LIST TranslatedResources;
+    BUS_INTERFACE_STANDARD BusInterface;
+    BOOLEAN BusInitialized;
 } FDO_DEVICE_EXTENSION, *PFDO_DEVICE_EXTENSION;
 
 
@@ -155,6 +157,15 @@ CopyResourceList(
     POOL_TYPE PoolType,
     PCM_RESOURCE_LIST Source);
 
+NTSTATUS
+QueryBusInterface(
+    PDEVICE_OBJECT DeviceObject,
+    PGUID Guid,
+    USHORT Size,
+    USHORT Version,
+    PBUS_INTERFACE_STANDARD Interface,
+    PVOID InterfaceSpecificData);
+
 
 /* pdo.c */
 
index 3520bbf..170c4eb 100644 (file)
@@ -548,7 +548,7 @@ StorPortFreeRegistryBuffer(
 
 
 /*
- * @unimplemented
+ * @implemented
  */
 STORPORT_API
 ULONG
@@ -561,9 +561,32 @@ StorPortGetBusData(
     _Out_ _When_(Length != 0, _Out_writes_bytes_(Length)) PVOID Buffer,
     _In_ ULONG Length)
 {
-    DPRINT1("StorPortGetBusData()\n");
-    UNIMPLEMENTED;
-    return 0;
+    PMINIPORT_DEVICE_EXTENSION MiniportExtension;
+    PBUS_INTERFACE_STANDARD Interface;
+    ULONG ReturnLength;
+
+    DPRINT1("StorPortGetBusData(%p %lu %lu %lu %p %lu)\n",
+            DeviceExtension, BusDataType, SystemIoBusNumber, SlotNumber, Buffer, Length);
+
+    MiniportExtension = CONTAINING_RECORD(DeviceExtension,
+                                          MINIPORT_DEVICE_EXTENSION,
+                                          HwDeviceExtension);
+    DPRINT1("DeviceExtension %p  MiniportExtension %p\n",
+            DeviceExtension, MiniportExtension);
+
+    Interface = &MiniportExtension->Miniport->DeviceExtension->BusInterface;
+
+    if (BusDataType == 4)
+        BusDataType = 0;
+
+    ReturnLength = Interface->GetBusData(Interface->Context,
+                                         BusDataType,
+                                         Buffer,
+                                         0,
+                                         Length);
+    DPRINT1("ReturnLength: %lu\n", ReturnLength);
+
+    return ReturnLength;
 }