[CMBATT]: Implement CmBattGetAcpiInterfaces and CmBattIoCompletion to get the ACPI...
authorSir Richard <sir_richard@svn.reactos.org>
Mon, 22 Mar 2010 01:47:40 +0000 (01:47 +0000)
committerSir Richard <sir_richard@svn.reactos.org>
Mon, 22 Mar 2010 01:47:40 +0000 (01:47 +0000)
[CMBATT]: Implement CmBattWmiRegistration and CmBattWmiDeRegistration to initialize the WMILIB and register with the I/O WMI routines.
[DDK]: Add missing IoWMIRegistrationControl flags.

svn path=/trunk/; revision=46333

reactos/drivers/bus/acpi/cmbatt/cmbatt.h
reactos/drivers/bus/acpi/cmbatt/cmbpnp.c
reactos/drivers/bus/acpi/cmbatt/cmbwmi.c
reactos/include/ddk/wdm.h

index 1eb44ad..1b32953 100644 (file)
@@ -11,6 +11,7 @@
 #include <batclass.h>
 #include <acpiioct.h>
 #include <wmilib.h>
+#include <wdmguid.h>
 #include <debug.h>
 
 #define CMBATT_GENERIC_STATUS   0x01
index 56acf22..323910a 100644 (file)
 
 NTSTATUS
 NTAPI
-CmBattIoCompletion(PDEVICE_OBJECT DeviceObject,
-                   PIRP Irp,
-                   PKEVENT Event)
+CmBattIoCompletion(IN PDEVICE_OBJECT DeviceObject,
+                   IN PIRP Irp,
+                   IN PKEVENT Event)
 {
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
+    if (CmBattDebug & 2) DbgPrint("CmBattIoCompletion: Event (%x)\n", Event);
+
+    /* Set the completion event */
+    KeSetEvent(Event, IO_NO_INCREMENT, FALSE);
+    return STATUS_MORE_PROCESSING_REQUIRED;
 }
 
 NTSTATUS
 NTAPI
-CmBattGetAcpiInterfaces(PDEVICE_OBJECT DeviceObject,
-                        PACPI_INTERFACE_STANDARD AcpiInterface)
+CmBattGetAcpiInterfaces(IN PDEVICE_OBJECT DeviceObject,
+                        IN OUT PACPI_INTERFACE_STANDARD AcpiInterface)
 {
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
+    PIRP Irp;
+    NTSTATUS Status;
+    PIO_STACK_LOCATION IoStackLocation;
+    KEVENT Event;
+
+    /* Allocate the IRP */
+    Irp = IoAllocateIrp(DeviceObject->StackSize, 0);
+    if (!Irp)
+    {
+        /* Fail */
+        if (CmBattDebug & 0xC)
+          DbgPrint("CmBattGetAcpiInterfaces: Failed to allocate Irp\n");
+        return STATUS_INSUFFICIENT_RESOURCES;
+    }
+
+    /* Set default error code */
+    Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
+
+    /* Build the query */
+    IoStackLocation = IoGetNextIrpStackLocation(Irp);
+    IoStackLocation->MinorFunction = IRP_MN_QUERY_INTERFACE;
+    IoStackLocation->Parameters.QueryInterface.InterfaceType = &GUID_ACPI_INTERFACE_STANDARD;
+    IoStackLocation->Parameters.QueryInterface.Size = sizeof(ACPI_INTERFACE_STANDARD);
+    IoStackLocation->Parameters.QueryInterface.Version = 1;
+    IoStackLocation->Parameters.QueryInterface.Interface = (PINTERFACE)AcpiInterface;
+    IoStackLocation->Parameters.QueryInterface.InterfaceSpecificData = NULL;
+
+    /* Set default ACPI interface data */
+    AcpiInterface->Size = sizeof(ACPI_INTERFACE_STANDARD);
+    AcpiInterface->Version = 1;
+
+    /* Initialize our wait event */
+    KeInitializeEvent(&Event, SynchronizationEvent, 0);
+    
+    /* Set the completion routine */
+    IoCopyCurrentIrpStackLocationToNext(Irp);
+    IoSetCompletionRoutine(Irp,
+                           (PVOID)CmBattIoCompletion,
+                           &Event,
+                           TRUE,
+                           TRUE,
+                           TRUE);
+    /* Now call ACPI */
+    Status = IoCallDriver(DeviceObject, Irp);
+    if (Status == STATUS_PENDING)
+    {
+        /* Wait for completion */
+        KeWaitForSingleObject(&Event,
+                              Executive,
+                              KernelMode,
+                              FALSE,
+                              NULL);
+        Status = Irp->IoStatus.Status;
+    }
+    
+    /* Free the IRP */
+    IoFreeIrp(Irp);
+    
+    /* Return status */
+    if (!(NT_SUCCESS(Status)) && (CmBattDebug & 0xC))
+        DbgPrint("CmBattGetAcpiInterfaces: Could not get ACPI driver interfaces, status = %x\n", Status);
+    return Status;
 }
 
 VOID
index 3609e17..8160bdc 100644 (file)
 
 #include "cmbatt.h"
 
+/* GLOBALS ********************************************************************/
+
+WMIGUIDREGINFO CmBattWmiGuidList[1] =
+{
+    {&GUID_POWER_DEVICE_WAKE_ENABLE, 1, 0}
+};
+
 /* FUNCTIONS ******************************************************************/
 
 NTSTATUS
@@ -69,18 +76,37 @@ CmBattSetWmiDataItem(PDEVICE_OBJECT DeviceObject,
 
 NTSTATUS
 NTAPI
-CmBattWmiDeRegistration(PCMBATT_DEVICE_EXTENSION DeviceExtension)
+CmBattWmiDeRegistration(IN PCMBATT_DEVICE_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
+    PAGED_CODE();
+    
+    /* De-register */
+    return IoWMIRegistrationControl(DeviceExtension->FdoDeviceObject,
+                                    WMIREG_ACTION_DEREGISTER); 
 }
 
 NTSTATUS
 NTAPI
-CmBattWmiRegistration(PCMBATT_DEVICE_EXTENSION DeviceExtension)
+CmBattWmiRegistration(IN PCMBATT_DEVICE_EXTENSION DeviceExtension)
 {
-    UNIMPLEMENTED;
-    return STATUS_NOT_IMPLEMENTED;
+    PAGED_CODE();
+    
+    /* GUID information */
+    DeviceExtension->WmiLibInfo.GuidCount = sizeof(CmBattWmiGuidList) /
+                                            sizeof(WMIGUIDREGINFO);
+    DeviceExtension->WmiLibInfo.GuidList = CmBattWmiGuidList;
+    
+    /* Callbacks */
+    DeviceExtension->WmiLibInfo.QueryWmiRegInfo = CmBattQueryWmiRegInfo;
+    DeviceExtension->WmiLibInfo.QueryWmiDataBlock = CmBattQueryWmiDataBlock;
+    DeviceExtension->WmiLibInfo.SetWmiDataBlock = CmBattSetWmiDataBlock;
+    DeviceExtension->WmiLibInfo.SetWmiDataItem = CmBattSetWmiDataItem;
+    DeviceExtension->WmiLibInfo.ExecuteWmiMethod = NULL;
+    DeviceExtension->WmiLibInfo.WmiFunctionControl = NULL;
+    
+    /* Register */
+    return IoWMIRegistrationControl(DeviceExtension->FdoDeviceObject,
+                                    WMIREG_ACTION_REGISTER);
 }
 
 NTSTATUS
index a19e64f..19a1349 100644 (file)
@@ -3158,6 +3158,12 @@ typedef VOID
 (DDKAPI *WMI_NOTIFICATION_CALLBACK)(
   PVOID  Wnode,
   PVOID  Context);
+  
+#define WMIREG_ACTION_REGISTER      1
+#define WMIREG_ACTION_DEREGISTER    2
+#define WMIREG_ACTION_REREGISTER    3
+#define WMIREG_ACTION_UPDATE_GUIDS  4
+#define WMIREG_ACTION_BLOCK_IRPS    5
 
 #define EVENT_INCREMENT                   1
 #define IO_NO_INCREMENT                   0