Книга: Writing Windows WDM Device Drivers

Dispatch Routine Power Handling

Dispatch Routine Power Handling

Each Wdm2 I/O request dispatch routine must check that the Wdm2 device is powered up. Listing 10.8 shows how Wdm2Write calls PowerUpDevice to power the device up if necessary by calling SendDeviceSetPower. Finally, PowerUpDevice resets the idle counter using PoSetDeviceBusy.

Listing 10.8 Dispatch routine power handling

NTSTATUS Wdm2Write(IN PDEVICE_OBJECT fdo, IN PIRP Irp) {
 // …
 NTSTATUS status = PowerUpDevice(fdo);
 if (!NT_SUCCESS(status)) return CompleteIrp(Irp, status, 0);
 // …
}
NTSTATUS PowerUpDevice(IN PDEVICE_OBJECT fdo) {
 PWDM2_DEVICE_EXTENSION dx = (PWDH2_DEVICE_EXTENSION)fdo->DeviceExtension;
 // If need be, increase power
 if (dx->PowerState>PowerDeviceD0) {
  NTSTATUS status = SendDeviceSetPower(dx, PowerDeviceD0);
  if (!NT_SUCCESS(status)) return status;
 }
 // Zero our idle counter
 if (dx->PowerIdleCounter) PoSetDeviceBusy(dx->PowerIdleCounter);
 return STATUS_SUCCESS;
}

Оглавление книги


Генерация: 1.725. Запросов К БД/Cache: 3 / 0
поделиться
Вверх Вниз