ReactOS 0.4.16-dev-2293-g4d8327b
sgpc.cpp
Go to the documentation of this file.
1#include "driver.h"
2
6 WDFIOTARGET ioTarget
7) {
8 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
9 "Device Removal Notification\n");
10
11 WdfIoTargetCloseForQueryRemove(ioTarget);
12 return STATUS_SUCCESS;
13}
14
15void
18 WDFIOTARGET ioTarget
19) {
22 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
23 "Device Removal Cancel\n");
24
26
27 status = WdfIoTargetOpen(ioTarget, &openParams);
28
29 if (!NT_SUCCESS(status)) {
30 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
31 "WdfIoTargetOpen failed 0x%x\n", status);
32 WdfObjectDelete(ioTarget);
33 return;
34 }
35}
36
37void
40 WDFIOTARGET ioTarget
41) {
42 PFDO_CONTEXT fdoCtx;
43 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
44 "Device Removal Complete\n");
45
46 PGRAPHICSIOTARGET_CONTEXT ioTargetContext;
47 ioTargetContext = GraphicsIoTarget_GetContext(ioTarget);
48
49 fdoCtx = ioTargetContext->FdoContext;
50
52 WdfCollectionRemove(fdoCtx->GraphicsDevicesCollection, ioTarget);
53 WdfWaitLockRelease(fdoCtx->GraphicsDevicesCollectionWaitLock);
54
55 WdfObjectDelete(ioTarget);
56}
57
58void
60 PVOID GraphicsDeviceHandle,
61 DEVICE_POWER_STATE NewGrfxPowerState,
62 BOOLEAN PreNotification,
63 PVOID PrivateHandle
64) {
65 PFDO_CONTEXT fdoCtx = (PFDO_CONTEXT)PrivateHandle;
66 UNREFERENCED_PARAMETER(GraphicsDeviceHandle);
67 UNREFERENCED_PARAMETER(NewGrfxPowerState);
68 UNREFERENCED_PARAMETER(PreNotification);
70 //No-Op
71}
72
73void
75 PVOID GraphicsDeviceHandle,
76 PVOID PrivateHandle
77) {
78 PFDO_CONTEXT fdoCtx = (PFDO_CONTEXT)PrivateHandle;
79 UNREFERENCED_PARAMETER(GraphicsDeviceHandle);
81 //No-Op
82}
83
84void
87 PFDO_CONTEXT fdoCtx,
89);
90
91void
94 if (!fdoCtx->UseSGPCCodec) {
95 return;
96 }
97
98 if (!fdoCtx->codecs[fdoCtx->GraphicsCodecAddress])
99 return;
100
102
104 // Initialize the description with the information about the detected codec.
105 //
107 &description.Header,
108 sizeof(description)
109 );
110
111 description.FdoContext = fdoCtx;
112 RtlCopyMemory(&description.CodecIds, &fdoCtx->codecs[fdoCtx->GraphicsCodecAddress]->CodecIds, sizeof(description.CodecIds));
113
114 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
115 "Ejecting Gfx Codec\n");
116
117 WdfInterruptAcquireLock(fdoCtx->Interrupt);
118
119 WdfChildListUpdateChildDescriptionAsMissing(WdfFdoGetDefaultChildList(fdoCtx->WdfDevice), &description.Header);
120 //Don't null FdoContext to allow SGPC Audio driver to unregister callbacks / events and cleanup
121
122 WdfInterruptReleaseLock(fdoCtx->Interrupt);
123
124}
125
126void
127NTAPI
129 if (!fdoCtx->UseSGPCCodec) {
130 return;
131 }
132 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
133 "Enumerating Gfx Codec\n");
136}
137
139 PVOID GraphicsDeviceHandle,
140 ULONG ComponentIndex,
141 UINT NewFState,
142 BOOLEAN PreNotification,
143 PVOID PrivateHandle
144) {
145 PFDO_CONTEXT fdoCtx = (PFDO_CONTEXT)PrivateHandle;
146 UNREFERENCED_PARAMETER(GraphicsDeviceHandle);
147 UNREFERENCED_PARAMETER(ComponentIndex);
148 if (NewFState) {
149 if (PreNotification) {
150 EjectGraphicsCodec(fdoCtx);
151 }
152 else {
153
154 }
155 }
156 else {
157 if (PreNotification) {
158
159 }
160 else {
162 }
163 }
164}
165
166void HDAGraphicsPowerInitialComponentStateCallback( //https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/d3dkmthk/nc-d3dkmthk-pdxgk_initial_component_state
167 PVOID GraphicsDeviceHandle,
168 PVOID PrivateHandle,
169 ULONG ComponentIndex,
170 BOOLEAN IsBlockingType,
171 UINT InitialFState,
172 GUID ComponentGuid,
173 UINT PowerComponentMappingFlag
174) {
175 UNREFERENCED_PARAMETER(GraphicsDeviceHandle);
176 UNREFERENCED_PARAMETER(ComponentIndex);
177 UNREFERENCED_PARAMETER(IsBlockingType);
178 UNREFERENCED_PARAMETER(ComponentGuid);
179 PFDO_CONTEXT fdoCtx = (PFDO_CONTEXT)PrivateHandle;
180 if (PowerComponentMappingFlag) {
181 }
182 else {
183 if (InitialFState) {
184 } else {
186 }
187 }
188}
189
190void
191NTAPI
193 PGRAPHICSWORKITEM_CONTEXT workItemContext = GraphicsWorkitem_GetContext(WorkItem);
194 PFDO_CONTEXT fdoCtx = workItemContext->FdoContext;
195 PUNICODE_STRING graphicsDeviceSymlink = &workItemContext->GPUDeviceSymlink;
196
197 WDF_OBJECT_ATTRIBUTES attributes;
199
200 WDFIOTARGET ioTarget;
202 PGRAPHICSIOTARGET_CONTEXT ioTargetContext;
203
204 NTSTATUS status = WdfIoTargetCreate(fdoCtx->WdfDevice, &attributes, &ioTarget);
205 if (!NT_SUCCESS(status)) {
206 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
207 "WdfIoTargetCreate failed 0x%x\n", status);
208 goto exit;
209 }
210
211 ioTargetContext = GraphicsIoTarget_GetContext(ioTarget);
212 ioTargetContext->FdoContext = fdoCtx;
213
215 &openParams,
216 graphicsDeviceSymlink,
222
223 status = WdfIoTargetOpen(ioTarget, &openParams);
224
225 if (!NT_SUCCESS(status)) {
226 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
227 "WdfIoTargetOpen failed with status 0x%x\n", status);
228 WdfObjectDelete(ioTarget);
229 goto exit;
230 }
231
233 WdfCollectionAdd(fdoCtx->GraphicsDevicesCollection, ioTarget);
234 WdfWaitLockRelease(fdoCtx->GraphicsDevicesCollectionWaitLock);
235
236 DXGK_GRAPHICSPOWER_REGISTER_INPUT graphicsPowerRegisterInput;
237 graphicsPowerRegisterInput = { 0 };
238 graphicsPowerRegisterInput.Version = DXGK_GRAPHICSPOWER_VERSION;
239 graphicsPowerRegisterInput.PrivateHandle = fdoCtx;
240 graphicsPowerRegisterInput.PowerNotificationCb = HDAGraphicsPowerNotificationCallback;
241 graphicsPowerRegisterInput.RemovalNotificationCb = HDAGraphicsPowerRemovalNotificationCallback;
242 graphicsPowerRegisterInput.FStateNotificationCb = HDAGraphicsPowerFStateNotificationCallback;
243 graphicsPowerRegisterInput.InitialComponentStateCb = HDAGraphicsPowerInitialComponentStateCallback;
244
245 WDF_MEMORY_DESCRIPTOR inputDescriptor;
246 WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&inputDescriptor, &graphicsPowerRegisterInput, sizeof(graphicsPowerRegisterInput));
247
248 WDF_MEMORY_DESCRIPTOR outputDescriptor;
249 WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&outputDescriptor, &ioTargetContext->graphicsPowerRegisterOutput, sizeof(ioTargetContext->graphicsPowerRegisterOutput));
250
251 status = WdfIoTargetSendInternalIoctlSynchronously(ioTarget,
253 IOCTL_INTERNAL_GRAPHICSPOWER_REGISTER,
254 &inputDescriptor, &outputDescriptor, NULL, NULL);
255 if (!NT_SUCCESS(status)) {
256 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
257 "IOCTL_INTERNAL_GRAPHICSPOWER_REGISTER failed with status 0x%x\n", status);
258 goto exit;
259 }
260
261exit:
262 WdfObjectDelete(WorkItem);
263}
264
266NTAPI
268 PVOID NotificationStruct,
270) {
273 PDEVICE_INTERFACE_CHANGE_NOTIFICATION devNotificationStruct = (PDEVICE_INTERFACE_CHANGE_NOTIFICATION)NotificationStruct;
274
275 if (!IsEqualGUID(devNotificationStruct->InterfaceClassGuid, GUID_DEVINTERFACE_GRAPHICSPOWER)) {
277 }
278
279 if (IsEqualGUID(devNotificationStruct->Event, GUID_DEVICE_INTERFACE_ARRIVAL)) {
280 SklHdAudBusPrint(DEBUG_LEVEL_INFO, DBG_INIT,
281 "Graphics Arrival Notification!\n");
282
283 status = RtlUnicodeStringValidate(devNotificationStruct->SymbolicLinkName);
284 if (!NT_SUCCESS(status)) {
285 return status;
286 }
287
288 WDF_WORKITEM_CONFIG workItemConfig;
290
291 WDF_OBJECT_ATTRIBUTES attributes;
292 WDFWORKITEM workItem;
293
294 WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
296 &attributes,
298 );
299 attributes.ParentObject = fdoCtx->WdfDevice;
300
301 WdfWorkItemCreate(&workItemConfig, &attributes, &workItem);
302
303 PGRAPHICSWORKITEM_CONTEXT workItemContext = GraphicsWorkitem_GetContext(workItem);
304 workItemContext->FdoContext = fdoCtx;
305 workItemContext->GPUDeviceSymlink = *devNotificationStruct->SymbolicLinkName;
306
307 WdfWorkItemEnqueue(workItem);
308 }
309
310 return status;
311}
312
315 WDFKEY driverKey;
316 status = WdfDeviceOpenRegistryKey(fdoCtx->WdfDevice, PLUGPLAY_REGKEY_DRIVER, READ_CONTROL, NULL, &driverKey);
317 if (!NT_SUCCESS(status)) {
318 return;
319 }
320
321 WDFKEY settingsKey;
322 DECLARE_CONST_UNICODE_STRING(DriverSettings, L"Settings");
323 DECLARE_CONST_UNICODE_STRING(GfxSharedCodecAddress, L"GfxSharedCodecAddress");
324 status = WdfRegistryOpenKey(driverKey, &DriverSettings, READ_CONTROL, NULL, &settingsKey);
325 if (!NT_SUCCESS(status)) {
326 goto closeDriverKey;
327 }
328
329 ULONG GfxCodecAddr;
330 status = WdfRegistryQueryULong(settingsKey, &GfxSharedCodecAddress, &GfxCodecAddr);
331 if (NT_SUCCESS(status)) {
332 fdoCtx->UseSGPCCodec = TRUE;
333 fdoCtx->GraphicsCodecAddress = GfxCodecAddr;
334 }
335
336 WdfRegistryClose(settingsKey);
337
338closeDriverKey:
339 WdfRegistryClose(driverKey);
340}
unsigned char BOOLEAN
Definition: actypes.h:127
unsigned char UINT8
Definition: actypes.h:128
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define FILE_SHARE_READ
Definition: compat.h:136
#define L(x)
Definition: resources.c:13
#define SklHdAudBusPrint(dbglevel, fmt,...)
Definition: driver.h:111
const GUID GUID_DEVICE_INTERFACE_ARRIVAL
Definition: deviface.c:14
struct _FDO_CONTEXT * PFDO_CONTEXT
WDF_IO_TARGET_OPEN_PARAMS openParams
GLenum const GLvoid * addr
Definition: glext.h:9621
unsigned int UINT
Definition: ndis.h:50
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define STANDARD_RIGHTS_ALL
Definition: nt_native.h:69
#define READ_CONTROL
Definition: nt_native.h:58
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
enum _DEVICE_POWER_STATE DEVICE_POWER_STATE
NTSTRSAFEAPI RtlUnicodeStringValidate(PCUNICODE_STRING SourceString)
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define exit(n)
Definition: config.h:202
void NTAPI HDAGraphics_EvtIoTargetRemoveComplete(WDFIOTARGET ioTarget)
Definition: sgpc.cpp:39
void HDAGraphicsPowerFStateNotificationCallback(PVOID GraphicsDeviceHandle, ULONG ComponentIndex, UINT NewFState, BOOLEAN PreNotification, PVOID PrivateHandle)
Definition: sgpc.cpp:138
void NTAPI HDAGraphics_EvtIoTargetRemoveCanceled(WDFIOTARGET ioTarget)
Definition: sgpc.cpp:17
void HDAGraphicsPowerRemovalNotificationCallback(PVOID GraphicsDeviceHandle, PVOID PrivateHandle)
Definition: sgpc.cpp:74
void HDAGraphicsPowerInitialComponentStateCallback(PVOID GraphicsDeviceHandle, PVOID PrivateHandle, ULONG ComponentIndex, BOOLEAN IsBlockingType, UINT InitialFState, GUID ComponentGuid, UINT PowerComponentMappingFlag)
Definition: sgpc.cpp:166
void HDAGraphicsPowerNotificationCallback(PVOID GraphicsDeviceHandle, DEVICE_POWER_STATE NewGrfxPowerState, BOOLEAN PreNotification, PVOID PrivateHandle)
Definition: sgpc.cpp:59
void CheckHDAGraphicsRegistryKeys(PFDO_CONTEXT fdoCtx)
Definition: sgpc.cpp:313
void NTAPI EnumerateGraphicsCodec(PFDO_CONTEXT fdoCtx)
Definition: sgpc.cpp:128
void NTAPI EjectGraphicsCodec(PFDO_CONTEXT fdoCtx)
Definition: sgpc.cpp:93
NTSTATUS NTAPI HDAGraphicsPowerInterfaceCallback(PVOID NotificationStruct, PVOID Context)
Definition: sgpc.cpp:267
void NTAPI Fdo_EnumerateCodec(PFDO_CONTEXT fdoCtx, UINT8 addr)
Definition: fdo.cpp:680
void NTAPI HDAGraphicsPowerInterfaceAdd(WDFWORKITEM WorkItem)
Definition: sgpc.cpp:192
NTSTATUS NTAPI HDAGraphics_EvtIoTargetQueryRemove(WDFIOTARGET ioTarget)
Definition: sgpc.cpp:5
#define STATUS_SUCCESS
Definition: shellext.h:65
WDFDEVICE WdfDevice
Definition: fdo.h:115
BOOLEAN GraphicsCodecConnected
Definition: fdo.h:132
struct _PDO_DEVICE_DATA * codecs[HDA_MAX_CODECS]
Definition: fdo.h:150
ULONG GraphicsCodecAddress
Definition: fdo.h:130
WDFWAITLOCK GraphicsDevicesCollectionWaitLock
Definition: fdo.h:128
WDFCOLLECTION GraphicsDevicesCollection
Definition: fdo.h:129
WDFINTERRUPT Interrupt
Definition: fdo.h:124
BOOLEAN UseSGPCCodec
Definition: fdo.h:131
DXGK_GRAPHICSPOWER_REGISTER_OUTPUT graphicsPowerRegisterOutput
Definition: fdo.h:109
struct _FDO_CONTEXT * FdoContext
Definition: fdo.h:108
UNICODE_STRING GPUDeviceSymlink
Definition: fdo.h:102
struct _FDO_CONTEXT * FdoContext
Definition: fdo.h:101
PFN_WDF_IO_TARGET_QUERY_REMOVE EvtIoTargetQueryRemove
Definition: wdfiotarget.h:140
PFN_WDF_IO_TARGET_REMOVE_CANCELED EvtIoTargetRemoveCanceled
Definition: wdfiotarget.h:146
PFN_WDF_IO_TARGET_REMOVE_COMPLETE EvtIoTargetRemoveComplete
Definition: wdfiotarget.h:152
WDFOBJECT ParentObject
Definition: wdfobject.h:130
Definition: ps.c:97
#define NTAPI
Definition: typedefs.h:36
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
#define PLUGPLAY_REGKEY_DRIVER
Definition: usbd.c:42
FORCEINLINE VOID WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT(_Out_ PWDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER Header, _In_ ULONG IdentificationDescriptionSize)
Definition: wdfchildlist.h:83
#define DECLARE_CONST_UNICODE_STRING(_variablename, _string)
Definition: wdfcore.h:161
FORCEINLINE VOID WDF_IO_TARGET_OPEN_PARAMS_INIT_REOPEN(_Out_ PWDF_IO_TARGET_OPEN_PARAMS Params)
Definition: wdfiotarget.h:340
FORCEINLINE VOID WDF_IO_TARGET_OPEN_PARAMS_INIT_OPEN_BY_NAME(_Out_ PWDF_IO_TARGET_OPEN_PARAMS Params, _In_ PCUNICODE_STRING TargetDeviceName, _In_ ACCESS_MASK DesiredAccess)
Definition: wdfiotarget.h:323
FORCEINLINE VOID WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(_Out_ PWDF_MEMORY_DESCRIPTOR Descriptor, _In_ PVOID Buffer, _In_ ULONG BufferLength)
Definition: wdfmemory.h:102
FORCEINLINE VOID WDF_OBJECT_ATTRIBUTES_INIT(_Out_ PWDF_OBJECT_ATTRIBUTES Attributes)
Definition: wdfobject.h:147
#define WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(_attributes, _contexttype)
Definition: wdfobject.h:170
#define WDF_OBJECT_ATTRIBUTES_SET_CONTEXT_TYPE(_attributes, _contexttype)
Definition: wdfobject.h:157
_Must_inspect_result_ FORCEINLINE NTSTATUS WdfWaitLockAcquire(_In_ _Requires_lock_not_held_(_Curr_) WDFWAITLOCK Lock, _In_opt_ PLONGLONG Timeout)
Definition: wdfsync.h:173
#define WDF_NO_HANDLE
Definition: wdftypes.h:107
FORCEINLINE VOID WDF_WORKITEM_CONFIG_INIT(_Out_ PWDF_WORKITEM_CONFIG Config, _In_ PFN_WDF_WORKITEM EvtWorkItemFunc)
Definition: wdfworkitem.h:85
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:115
const char * description
Definition: directx.c:2497
struct _DEVICE_INTERFACE_CHANGE_NOTIFICATION * PDEVICE_INTERFACE_CHANGE_NOTIFICATION