https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c8c0fc8d643bac8c0caa320c98d18a7160ec0ad4

commit c8c0fc8d643bac8c0caa320c98d18a7160ec0ad4
Author:     Thomas Faber <[email protected]>
AuthorDate: Sun Feb 24 14:33:41 2019 +0100
Commit:     Thomas Faber <[email protected]>
CommitDate: Tue Feb 26 09:51:21 2019 +0100

    [HDAUDBUS] Implement FDO removal. CORE-14617
---
 drivers/wdm/audio/hdaudbus/fdo.cpp      | 55 +++++++++++++++++++++++++++++++++
 drivers/wdm/audio/hdaudbus/hdaudbus.cpp |  6 ++++
 drivers/wdm/audio/hdaudbus/hdaudbus.h   |  9 +++++-
 3 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/drivers/wdm/audio/hdaudbus/fdo.cpp 
b/drivers/wdm/audio/hdaudbus/fdo.cpp
index 3df33c907b..44e41d22c1 100644
--- a/drivers/wdm/audio/hdaudbus/fdo.cpp
+++ b/drivers/wdm/audio/hdaudbus/fdo.cpp
@@ -563,6 +563,7 @@ HDA_FDOStartDevice(
 
         if (Descriptor->Type == CmResourceTypeMemory)
         {
+            DeviceExtension->RegLength = Descriptor->u.Memory.Length;
             DeviceExtension->RegBase = 
(PUCHAR)MmMapIoSpace(Descriptor->u.Memory.Start, Descriptor->u.Memory.Length, 
MmNonCached);
             if (DeviceExtension->RegBase == NULL)
             {
@@ -635,6 +636,60 @@ HDA_FDOStartDevice(
     return Status;
 }
 
+NTSTATUS
+NTAPI
+HDA_FDORemoveDevice(
+    _In_ PDEVICE_OBJECT DeviceObject,
+    _Inout_ PIRP Irp)
+{
+    NTSTATUS Status;
+    PHDA_FDO_DEVICE_EXTENSION DeviceExtension;
+    ULONG CodecIndex, AFGIndex;
+    PHDA_CODEC_ENTRY CodecEntry;
+
+    /* get device extension */
+    DeviceExtension = 
static_cast<PHDA_FDO_DEVICE_EXTENSION>(DeviceObject->DeviceExtension);
+    ASSERT(DeviceExtension->IsFDO == TRUE);
+
+    Irp->IoStatus.Status = STATUS_SUCCESS;
+    IoSkipCurrentIrpStackLocation(Irp);
+    Status = IoCallDriver(DeviceExtension->LowerDevice, Irp);
+
+    IoDetachDevice(DeviceExtension->LowerDevice);
+
+    if (DeviceExtension->RegBase != NULL)
+    {
+        MmUnmapIoSpace(DeviceExtension->RegBase,
+                       DeviceExtension->RegLength);
+    }
+    if (DeviceExtension->Interrupt != NULL)
+    {
+        IoDisconnectInterrupt(DeviceExtension->Interrupt);
+    }
+    if (DeviceExtension->CorbBase != NULL)
+    {
+        MmFreeContiguousMemory(DeviceExtension->CorbBase);
+    }
+    for (CodecIndex = 0; CodecIndex < HDA_MAX_CODECS; CodecIndex++)
+    {
+        CodecEntry = DeviceExtension->Codecs[CodecIndex];
+        if (CodecEntry == NULL)
+        {
+            continue;
+        }
+
+        for (AFGIndex = 0; AFGIndex < CodecEntry->AudioGroupCount; AFGIndex++)
+        {
+            FreeItem(CodecEntry->AudioGroups[AFGIndex]);
+        }
+        FreeItem(CodecEntry);
+    }
+
+    IoDeleteDevice(DeviceObject);
+
+    return Status;
+}
+
 NTSTATUS
 NTAPI
 HDA_FDOQueryBusRelations(
diff --git a/drivers/wdm/audio/hdaudbus/hdaudbus.cpp 
b/drivers/wdm/audio/hdaudbus/hdaudbus.cpp
index 440d75ae58..79b07463b8 100644
--- a/drivers/wdm/audio/hdaudbus/hdaudbus.cpp
+++ b/drivers/wdm/audio/hdaudbus/hdaudbus.cpp
@@ -50,6 +50,12 @@ HDA_FdoPnp(
         Irp->IoStatus.Status = Status;
         IoCompleteRequest(Irp, IO_NO_INCREMENT);
         return Status;
+    case IRP_MN_REMOVE_DEVICE:
+        return HDA_FDORemoveDevice(DeviceObject, Irp);
+    case IRP_MN_QUERY_REMOVE_DEVICE:
+    case IRP_MN_CANCEL_REMOVE_DEVICE:
+        Irp->IoStatus.Status = STATUS_SUCCESS;
+        break;
     case IRP_MN_QUERY_DEVICE_RELATIONS:
         /* handle bus device relations */
         if (IoStack->Parameters.QueryDeviceRelations.Type == BusRelations)
diff --git a/drivers/wdm/audio/hdaudbus/hdaudbus.h 
b/drivers/wdm/audio/hdaudbus/hdaudbus.h
index fa7f04a70a..f29aae5919 100644
--- a/drivers/wdm/audio/hdaudbus/hdaudbus.h
+++ b/drivers/wdm/audio/hdaudbus/hdaudbus.h
@@ -64,8 +64,9 @@ typedef struct
 {
        BOOLEAN IsFDO;
        PDEVICE_OBJECT LowerDevice;
-       
+
        PUCHAR RegBase;
+       SIZE_T RegLength;
        PKINTERRUPT Interrupt;
 
        ULONG CorbLength;
@@ -126,6 +127,12 @@ HDA_FDOStartDevice(
     IN PDEVICE_OBJECT DeviceObject,
     IN PIRP Irp);
 
+NTSTATUS
+NTAPI
+HDA_FDORemoveDevice(
+    _In_ PDEVICE_OBJECT DeviceObject,
+    _Inout_ PIRP Irp);
+
 NTSTATUS
 NTAPI
 HDA_FDOQueryBusRelations(

Reply via email to