/*++

    Copyright (c) Microsoft Corporation.  All rights reserved.

Rule Name:

    FDOPowerPolicyOwnerAPI

Domain:

    wdf

Rule ID:

    Not Applicable

Description:

    If an FDO driver relinquishes power policy ownership, the rule warns
    that the methods WdfDeviceInitSetPowerPolicyEventCallbacks, WdfDeviceAssignS0IdleSettings
    and WdfDeviceAssignSxWakeSettings can only be called on the execution paths
    where the driver is a power policy owner.

    For the driver that has the passed the FDODriver rule, if the driver calls the
    WdfDeviceInitSetPowerPolicyOwnership method with the 2nd parameter FALSE, 
    any subsequent calls to WdfDeviceInitSetPowerPolicyEventCallbacks, 
    WdfDeviceAssignS0IdleSettings and WdfDeviceAssignSxWakeSettings
    by that driver will cause a rule violation and a warning message.
    
    Rule diagnostics:
    "Warning: The Driver is not a Power Policy Owner on some execution paths. 
         Check that $fname is called only on those paths where the driver has not 
         relinquished the power policy ownership. For the rule to be applicable, 
         the precondition rule FDODriver should pass."

    Precondition: FDODriver

Help Link:

    https://go.microsoft.com/fwlink/?LinkId=507077

--*/




#include "slic_base.h"

state{
     enum {INIT, NOTOWNER} s = INIT;
} with guard (sdv_main, hdevice_init)
sdv_WdfDeviceInitSetPowerPolicyOwnership.entry[guard $1]
{
   if ($2 == 0) {  
      s = NOTOWNER;       
   }
}
sdv_WdfDeviceInitSetPowerPolicyEventCallbacks.entry[guard $1]
{
   if (s == NOTOWNER) {
   abort "Warning: The Driver is not a Power Policy Owner on some execution paths. Check that $fname is called only on those paths where the driver has not relinquished the power policy ownership. For the rule to be applicable, the precondition rule FDODriver should pass.";
   }
}
[sdv_WdfDeviceAssignS0IdleSettings
,sdv_WdfDeviceAssignSxWakeSettings
].entry
{
   if ((s == NOTOWNER) && ($1 == hdevice)) {
   abort "Warning: The Driver is not a Power Policy Owner on some execution paths. Check that $fname is called only on those paths where the driver has not relinquished the power policy ownership. For the rule to be applicable, the precondition rule FDODriver should pass.";
   }
}
