Here’s some (excerpts from )WDF-based code that I’ve written to get ACPI
Notify events in a driver. WDM code would be similar, though I strongly
recommend that you use WDF.
- Pick up the ACPI interface function table from either the lower filter
or PDO that’s owned by the ACPI driver. (This can only ever work from
within a driver that’s part of the relevant device stack.
status = WdfFdoQueryForInterface(
Device,
&GUID_ACPI_INTERFACE_STANDARD,
(PINTERFACE) &context->AcpiInterfaces,
sizeof(ACPI_INTERFACE_STANDARD),
1,
NULL);
- Register a notification function.
//
// Register for notification callbacks.
//
callbackStatus =
context->AcpiInterfaces.RegisterForDeviceNotifications(
context->AcpiInterfaces.Context,
AcpiNotifyCallback,
Device
);
- Provide a callback function, or set of functions.
VOID
AcpiNotifyCallback(
PVOID Context,
ULONG NotifyCode
)
/*++
Routine Description:
This routine is called by the ACPI driver whenever
our device is the target of an ASL “Notify” statement.
This would typically happen as a result of a keyboard
hotkey event.
This routine may be called at any IRQL <=
DISPATCH_LEVEL. Because of this, we just queue a work
item to do the actual work.
Arguments:
Context - Handle to a framework driver object created in DriverEntry
NotifyCode - A byte code associated with an ASL “Notify” statement
Return Value:
None. If a failure occurs, just return. This means that
we’ll miss an event. But that’s not fatal in this case.
–*/
{
PACPI_NOTIFICATION_CONTEXT notificationContext;
WDF_WORKITEM_CONFIG workitemConfig;
WDF_OBJECT_ATTRIBUTES attributes;
WDFWORKITEM workItem;
WDFDEVICE device;
NTSTATUS status;
device = (WDFDEVICE)Context;
WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(&attributes,
ACPI_NOTIFICATION_CONTEXT);
WDF_WORKITEM_CONFIG_INIT(&workitemConfig, AcpiNotificationWorker);
workitemConfig.AutomaticSerialization = FALSE;
//
// Allocate the work item to do the actual work
// This is because that to complete the Iotarget
// synchronous evaluation of the bios, we need to
// be at PASSIVE_LEVEL
//
status = WdfWorkItemCreate(&workitemConfig,
&attributes,
&workItem
);
if (!NT_SUCCESS(status)) {
TraceEvents (TRACE_LEVEL_CRITICAL, DBG_INIT, “AcpiNotifyCallback:
WdfWorkItemCreate failed with status 0x%x\n”, status);
return;
}
notificationContext = GetAcpiWorkItemContext(workItem);
notificationContext->Device = device;
notificationContext->NotifyCode = NotifyCode;
WdfWorkItemEnqueue(workItem);
return;
}
VOID
AcpiNotificationWorker(
IN WDFWORKITEM WorkItem
)
/*++
Routine Description:
This routine is called on a worker thread whenever
our device is the target of an ASL “Notify” statement.
Arguments:
WorkItem - The work item associated with this.
Return Value:
None.
–*/
{
PACPI_NOTIFICATION_CONTEXT notificationContext;
PAGED_CODE();
notificationContext = GetAcpiWorkItemContext(WorkItem);
//
// Take action based on the notification code.
//
switch (notificationContext->NotifyCode) {
case 0x80:
// put whatever you like here
break;
case 0x81:
//
// again, whatever you like
//
break;
default:
ASSERT(!“Unknown Notify code sent.”);
}
WdfObjectDelete(WorkItem);
return;
}
–
Jake Oshins
Windows Kernel Group
The Virtual Machine Team at Microsoft is hiring. Contact
xxxxx@microsoft.com for more information.
This posting is provided “AS IS” with no warranties, and confers no rights.
wrote in message news:xxxxx@ntdev…
> I’m sorry, but there is not one sample that demonstrates exactly what you
> want to do.
>
> There are, I assume, samples in the SDK that demonstate how to receive
> ACPI events in user mode. And there are samples in the DDK that should
> how to write a wDM driver that process IOCTLs. But there’s no single
> sample that does both.
>
> P
>