summaryrefslogtreecommitdiff
path: root/powerlimit/plpolicy/plpolicy.h
blob: ae767b63ec82f99389690e8f3f2327e25843d07c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*++

Copyright (c) Microsoft Corporation. All rights reserved.

Module Name:

    plpolicy.h

Abstract:

    This is the header file for the simulated power limit policy driver.

--*/

#pragma once

//-------------------------------------------------------------------- Includes

#include <ntddk.h>
#include <wdf.h>
#include <ntstrsafe.h>
#include <initguid.h>
#include <wdmguid.h>
#include <poclass.h>
#include <limits.h>
#include "powerlimitpolicy_drvinterface.h"

//----------------------------------------------------------------------- Types

typedef struct _DEVICE_REGISTRATION {
    LIST_ENTRY Link;
    BOOLEAN Initialized;
    ULONG RequestId;
    PVOID PowerLimitRequest;
    UNICODE_STRING TargetDeviceName;
} DEVICE_REGISTRATION, *PDEVICE_REGISTRATION;

typedef struct _FDO_DATA {
    ULONG RequestCount;
    LIST_ENTRY RequestHeader;
} FDO_DATA, *PFDO_DATA;

WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_DATA, GetDeviceExtension);

//----------------------------------------------------------------------- Debug

#define DebugPrint(l, m, ...) DbgPrintEx(DPFLTR_POWER_ID, l, "[plpolicy]: "m, __VA_ARGS__)
#define DebugEnter() DebugPrint(PLPOLICY_PRINT_TRACE, "Entering " __FUNCTION__ "\n")
#define DebugExit() DebugPrint(PLPOLICY_PRINT_TRACE, "Leaving " __FUNCTION__ "\n")
#define DebugExitStatus(_status_) DebugPrint(PLPOLICY_PRINT_TRACE, "Leaving " __FUNCTION__ ": Status=0x%x\n", _status_)

#define PLPOLICY_PRINT_ERROR        DPFLTR_ERROR_LEVEL
#define PLPOLICY_PRINT_TRACE        DPFLTR_TRACE_LEVEL
#define PLPOLICY_PRINT_INFO         DPFLTR_INFO_LEVEL

#define PLPOLICY_TAG 'PLPO'

#define OffsetToPtr(Base, Offset) ((PVOID)((PUCHAR)(Base) + (Offset)))

//--------------------------------------------------------------------- Globals

extern WDFWAITLOCK GlobalMutex;

//------------------------------------------------------------------ Prototypes

FORCEINLINE
VOID
AcquireGlobalMutex (
    VOID
    )
{

    WdfWaitLockAcquire(GlobalMutex, 0);
    return;
}

FORCEINLINE
VOID
ReleaseGlobalMutex (
    VOID
    )
{

    WdfWaitLockRelease(GlobalMutex);
    return;
}

//
// plpolicy.c
//

NTSTATUS
RegisterRequest (
    _Inout_ PFDO_DATA DevExt,
    _In_ PUNICODE_STRING TargetDeviceName,
    _In_ PDEVICE_OBJECT PolicyDeviceObject,
    _Out_ PULONG RequestId
    );

NTSTATUS
UnregisterRequest (
    _Inout_ PFDO_DATA DevExt,
    _In_ ULONG RequestId
    );

NTSTATUS
QueryAttributes (
    _Out_ PPOWER_LIMIT_ATTRIBUTES Buffer,
    _Inout_ PFDO_DATA DevExt,
    _In_ ULONG RequestId,
    _In_ ULONG BufferCount
    );

NTSTATUS
QueryLimitValues (
    _Out_ PPOWER_LIMIT_VALUE Buffer,
    _Inout_ PFDO_DATA DevExt,
    _In_ ULONG RequestId,
    _In_ ULONG BufferCount
    );

NTSTATUS
SetLimitValues (
    _Inout_ PFDO_DATA DevExt,
    _In_ ULONG RequestId,
    _In_ ULONG BufferCount,
    _In_ PPOWER_LIMIT_VALUE Buffer
    );