[ACPI]
[reactos.git] / reactos / drivers / bus / acpi / main.c
index d8d8b3e..46667b9 100644 (file)
@@ -6,7 +6,9 @@
 #include <acpi_bus.h>
 #include <acpi_drivers.h>
 
-//#define NDEBUG
+#include <acpiioct.h>
+
+#define NDEBUG
 #include <debug.h>
 
 #ifdef ALLOC_PRAGMA
@@ -29,13 +31,15 @@ Bus_AddDevice(
     PDEVICE_OBJECT      deviceObject = NULL;
     PFDO_DEVICE_DATA    deviceData = NULL;
     PWCHAR              deviceName = NULL;
+#ifndef NDEBUG
     ULONG               nameLength;
+#endif
 
     PAGED_CODE ();
 
     DPRINT("Add Device: 0x%p\n",  PhysicalDeviceObject);
 
-    DPRINT1("#################### Bus_CreateClose Creating FDO Device ####################\n");
+    DPRINT("#################### Bus_CreateClose Creating FDO Device ####################\n");
     status = IoCreateDevice(DriverObject,
                       sizeof(FDO_DEVICE_DATA),
                       NULL,
@@ -134,7 +138,7 @@ Bus_AddDevice(
         goto End;
     }
 
-    DPRINT1("AddDevice: %p to %p->%p (%ws) \n",
+    DPRINT("AddDevice: %p to %p->%p (%ws) \n",
                    deviceObject,
                    deviceData->NextLowerDriver,
                    PhysicalDeviceObject,
@@ -164,36 +168,63 @@ End:
 
 NTSTATUS
 NTAPI
-ACPIDispatchDeviceControl(
+ACPIDispatchCreateClose(
    IN PDEVICE_OBJECT DeviceObject,
    IN PIRP Irp)
 {
-    PIO_STACK_LOCATION IrpSp;
-    NTSTATUS Status;
+   Irp->IoStatus.Status = STATUS_SUCCESS;
+   Irp->IoStatus.Information = 0;
 
-    DPRINT("Called. IRP is at (0x%X)\n", Irp);
+   IoCompleteRequest(Irp, IO_NO_INCREMENT);
 
-    Irp->IoStatus.Information = 0;
+   return STATUS_SUCCESS;
+}
 
-    IrpSp  = IoGetCurrentIrpStackLocation(Irp);
-    switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) {
-        default:
-            DPRINT("Unknown IOCTL 0x%X\n", IrpSp->Parameters.DeviceIoControl.IoControlCode);
-            Status = STATUS_NOT_IMPLEMENTED;
-            break;
-  }
+NTSTATUS
+NTAPI
+ACPIDispatchDeviceControl(
+   IN PDEVICE_OBJECT DeviceObject,
+   IN PIRP Irp)
+{
+    PIO_STACK_LOCATION      irpStack;
+    NTSTATUS                status = STATUS_NOT_SUPPORTED;
+    PCOMMON_DEVICE_DATA     commonData;
+
+    PAGED_CODE ();
 
-    if (Status != STATUS_PENDING) {
-        Irp->IoStatus.Status = Status;
+    irpStack = IoGetCurrentIrpStackLocation (Irp);
+    ASSERT (IRP_MJ_DEVICE_CONTROL == irpStack->MajorFunction);
 
-        DPRINT("Completing IRP at 0x%X\n", Irp);
+    commonData = (PCOMMON_DEVICE_DATA) DeviceObject->DeviceExtension;
+
+    Irp->IoStatus.Information = 0;
 
-        IoCompleteRequest(Irp, IO_NO_INCREMENT);
-  }
+    if (!commonData->IsFDO)
+    {
+       switch (irpStack->Parameters.DeviceIoControl.IoControlCode)
+       {
+           case IOCTL_ACPI_EVAL_METHOD:
+              status = Bus_PDO_EvalMethod((PPDO_DEVICE_DATA)commonData,
+                                          Irp);
+              break;
+
+           /* TODO: Implement other IOCTLs */
+
+           default:
+              DPRINT1("Unsupported IOCTL: %x\n", irpStack->Parameters.DeviceIoControl.IoControlCode);
+              break;
+       }
+    }
+    else
+       DPRINT1("IOCTL sent to the ACPI FDO! Kill the caller!\n");
 
-    DPRINT("Leaving. Status 0x%X\n", Status);
+    if (status != STATUS_PENDING)
+    {
+       Irp->IoStatus.Status = status;
+       IoCompleteRequest(Irp, IO_NO_INCREMENT);
+    }
 
-    return Status;
+    return status;
 }
 
 NTSTATUS
@@ -211,6 +242,8 @@ DriverEntry (
     DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ACPIDispatchDeviceControl;
     DriverObject->MajorFunction [IRP_MJ_PNP] = Bus_PnP;
     DriverObject->MajorFunction [IRP_MJ_POWER] = Bus_Power;
+    DriverObject->MajorFunction [IRP_MJ_CREATE] = ACPIDispatchCreateClose;
+    DriverObject->MajorFunction [IRP_MJ_CLOSE] = ACPIDispatchCreateClose;
 
     DriverObject->DriverExtension->AddDevice = Bus_AddDevice;