1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7     FxTelemetryKm.hpp
8 
9 Abstract:
10 
11     This is header file for telemetry methods.
12 
13 Author:
14 
15 
16 
17 Environment:
18 
19     Kernel mode only
20 
21 Revision History:
22 
23 Notes:
24 
25 --*/
26 
27 #pragma once
28 
29 #include "fxldr.h"
30 
31 #if defined(__cplusplus)
32 extern "C" {
33 #endif
34 
35 //
36 // Event name:  KmdfCensusEvtDeviceStart
37 //
38 // Source:      KMDF only
39 //
40 // Description: Written when a FDO completes start successfully.
41 //
42 // Frequency:   If FX_TELEMETRY_ENABLED, once per driver session. This is tracked using the
43 //              DoOnceFlag in the telemetry context. Also not to exceed
44 //              once in 24 hours (last write time stored in registry).
45 //
46 //
47 #define KMDF_CENSUS_EVT_WRITE_DEVICE_START(TraceHandle , Globals, DriverConfig, SetupClass, BusEnum, HwID, Manafacturer)    \
48             TraceLoggingWrite(TraceHandle,                                                                                  \
49                 "KmdfCensusEvtDeviceStart",                                                                                 \
50                 WDF_TELEMETRY_EVT_KEYWORDS,                                                                                 \
51                 WDF_CENSUS_EVT_DATA_COMMON(Globals),                                                                        \
52                 TraceLoggingString((Globals)->Public.DriverName,            "DriverServiceName"),                           \
53                 TraceLoggingKmdfDriverConfigInfo(DriverConfig,              "DriverConfigInfo"),                            \
54                 TraceLoggingWideString(SetupClass.m_UnicodeString.Buffer,   "SetupClass"),                                  \
55                 TraceLoggingWideString(BusEnum.m_UnicodeString.Buffer,      "BusEnumerator"),                               \
56                 TraceLoggingWideString(HwID.m_UnicodeString.Buffer,         "HardwareId"),                                  \
57                 TraceLoggingWideString(Manafacturer.m_UnicodeString.Buffer, "ManufacturerString")                           \
58             );
59 
60 //
61 // This is part of the data for KmdfCensusEvtDeviceStart event.
62 //
63 #define TraceLoggingKmdfDriverConfigInfo(info, fieldName)   \
64     \
65     TraceLoggingStruct(23, fieldName),  \
66     \
67     TraceLoggingUInt8(info.bitmap.IsNonPnpDriver,                           "IsNonPnpDriver"                        ), \
68     TraceLoggingUInt8(info.bitmap.IsNoDispatchOverride,                     "IsNoDispatchOverride"                  ), \
69     TraceLoggingUInt8(info.bitmap.IsVerifierOn,                             "IsVerifierOn"                          ), \
70     TraceLoggingUInt8(info.bitmap.IsEnhancedVerifierOn,                     "IsEnhancedVerifierOn"                  ), \
71     TraceLoggingUInt8(info.bitmap.IsFilter,                                 "IsFilter"                              ), \
72     \
73     TraceLoggingUInt8(info.bitmap.IsUsingRemoveLockOption,                  "IsUsingRemoveLockOption"               ), \
74     TraceLoggingUInt8(info.bitmap.IsUsingNonDefaultHardwareReleaseOrder,    "IsUsingNonDefaultHardwareReleaseOrder" ), \
75     TraceLoggingUInt8(info.bitmap.IsPowerPolicyOwner,                       "IsPowerPolicyOwner"                    ), \
76     TraceLoggingUInt8(info.bitmap.IsS0IdleWakeFromS0Enabled,                "IsS0IdleWakeFromS0Enabled"             ), \
77     TraceLoggingUInt8(info.bitmap.IsS0IdleUsbSSEnabled,                     "IsS0IdleUsbSSEnabled"                  ), \
78     \
79     TraceLoggingUInt8(info.bitmap.IsS0IdleSystemManaged,                    "IsS0IdleSystemManaged"                 ), \
80     TraceLoggingUInt8(info.bitmap.IsSxWakeEnabled,                          "IsSxWakeEnabled"                       ), \
81     TraceLoggingUInt8(info.bitmap.IsUsingLevelTriggeredLineInterrupt,       "IsUsingLevelTriggeredLineInterrupt"    ), \
82     TraceLoggingUInt8(info.bitmap.IsUsingEdgeTriggeredLineInterrupt,        "IsUsingEdgeTriggeredLineInterrupt"     ), \
83     TraceLoggingUInt8(info.bitmap.IsUsingMsiXOrSingleMsi22Interrupt,        "IsUsingMsiXOrSingleMsi22Interrupt"     ), \
84     \
85     TraceLoggingUInt8(info.bitmap.IsUsingMsi22MultiMessageInterrupt,        "IsUsingMsi22MultiMessageInterrupt"     ), \
86     TraceLoggingUInt8(info.bitmap.IsUsingMultipleInterrupt,                 "IsUsingMultipleInterrupt"              ), \
87     TraceLoggingUInt8(info.bitmap.IsUsingPassiveLevelInterrupt,             "IsUsingPassiveLevelInterrupt"          ), \
88     TraceLoggingUInt8(info.bitmap.IsUsingBusMasterDma,                      "IsUsingBusMasterDma"                   ), \
89     TraceLoggingUInt8(info.bitmap.IsUsingSystemDma,                         "IsUsingSystemDma"                      ), \
90     \
91     TraceLoggingUInt8(info.bitmap.IsUsingSystemDmaDuplex,                   "IsUsingSystemDmaDuplex"                ), \
92     TraceLoggingUInt8(info.bitmap.IsUsingStaticBusEnumration,               "IsUsingStaticBusEnumration"            ), \
93     TraceLoggingUInt8(info.bitmap.IsUsingDynamicBusEnumeration,             "IsUsingDynamicBusEnumeration"          )  \
94 
95 //
96 // When changing the structure, do update TraceLoggingKmdfDriverConfigInfo
97 // for fields name and TraceLoggingStruct(count) as well. It is good to keep
98 // fields order the same but it is not required.
99 //
100 union FxTelemetryDriverInfo {
101     struct {
102         DWORD IsNonPnpDriver                        : 1;
103         DWORD IsNoDispatchOverride                  : 1;
104         DWORD IsVerifierOn                          : 1;
105         DWORD IsEnhancedVerifierOn                  : 1;
106         DWORD IsFilter                              : 1;
107         DWORD IsUsingRemoveLockOption               : 1;
108         DWORD IsUsingNonDefaultHardwareReleaseOrder : 1;
109         DWORD IsPowerPolicyOwner                    : 1;
110         DWORD IsS0IdleWakeFromS0Enabled             : 1;
111         DWORD IsS0IdleUsbSSEnabled                  : 1;
112         DWORD IsS0IdleSystemManaged                 : 1;
113         DWORD IsSxWakeEnabled                       : 1;
114         DWORD IsUsingLevelTriggeredLineInterrupt    : 1;
115         DWORD IsUsingEdgeTriggeredLineInterrupt     : 1;
116         DWORD IsUsingMsiXOrSingleMsi22Interrupt     : 1;
117         DWORD IsUsingMsi22MultiMessageInterrupt     : 1;
118         DWORD IsUsingMultipleInterrupt              : 1;
119         DWORD IsUsingPassiveLevelInterrupt          : 1;
120         DWORD IsUsingBusMasterDma                   : 1;
121         DWORD IsUsingSystemDma                      : 1;
122         DWORD IsUsingSystemDmaDuplex                : 1;
123         DWORD IsUsingStaticBusEnumration            : 1;
124         DWORD IsUsingDynamicBusEnumeration          : 1;
125     } bitmap;
126     DWORD Dword;
127 };
128 
129 
130 VOID
131 RegistryWriteCurrentTime(
132     _In_ PFX_DRIVER_GLOBALS DriverGlobals
133     );
134 
135 VOID
136 RegistryReadLastLoggedTime(
137     _In_ PFX_DRIVER_GLOBALS DriverGlobals,
138     _Out_ PLARGE_INTEGER CurrentTime
139     );
140 
141 NTSTATUS
142 GetHardwareIdAndSetupclassFromRegistry(
143     _In_ FxDevice* Fdo,
144     _Out_ PUNICODE_STRING HwIds,
145     _Out_ PUNICODE_STRING SetupClass
146     );
147 
148 BOOLEAN
149 IsLoggingEnabledAndNeeded(
150     _In_ PFX_DRIVER_GLOBALS DriverGlobals
151     );
152 
153 _Must_inspect_result_
154 NTSTATUS
155 FxQueryData(
156     _In_ PFX_DRIVER_GLOBALS DriverGlobals,
157     _In_ HANDLE Key,
158     _In_ PCUNICODE_STRING ValueName,
159     _In_ ULONG Tag,
160     _Out_ PKEY_VALUE_PARTIAL_INFORMATION* Info
161     );
162 
163 VOID
164 GetDriverInfo(
165     _In_ PFX_DRIVER_GLOBALS Globals,
166     _In_opt_ FxDevice* Fdo,
167     _Out_ FxTelemetryDriverInfo* DriverInfo
168     );
169 
170 VOID
171 FxGetDevicePropertyString(
172     _In_ FxDevice* Fdo,
173     _In_ DEVICE_REGISTRY_PROPERTY  DeviceProperty,
174     _Out_ PUNICODE_STRING PropertyString
175     );
176 
177 VOID
178 GetFirstHardwareId(
179     _Inout_ PUNICODE_STRING HardwareIds
180     );
181 
182 _Must_inspect_result_
183 __drv_maxIRQL(PASSIVE_LEVEL)
184 NTSTATUS
185 QueryAndAllocString(
186     _In_  HANDLE Key,
187     _In_  PFX_DRIVER_GLOBALS Globals,
188     _In_  PCUNICODE_STRING ValueName,
189     _Out_ PKEY_VALUE_PARTIAL_INFORMATION* Info
190     );
191 
192 
193 #if defined(__cplusplus)
194 }
195 #endif
196 
197