Skip to content

Commit 464027a

Browse files
sraman4malayaku
authored andcommitted
ZC v1574 : EDID management feature, bug fixes in UMD and KMD
Signed-off-by: Raman, Sudharsan <sudharsan.raman@intel.com>
1 parent 621b321 commit 464027a

File tree

16 files changed

+265
-257
lines changed

16 files changed

+265
-257
lines changed

DVInstaller.ps1

9.17 KB
Binary file not shown.

DVServerKMD/DVServerKMD.inf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ WdfCoInstaller$KMDFCOINSTALLERVERSION$.dll=1 ; make sure the number matches with
3636
;*****************************************
3737

3838
[Manufacturer]
39-
%ManufacturerName%=Standard,NT$ARCH$
39+
%ManufacturerName%=Standard,NTamd64.10.0...15063
4040

41-
[Standard.NT$ARCH$]
41+
[Standard.NTamd64.10.0...15063]
4242
%DVServerKMD.DeviceDesc%=DVServerKMD_Device, PCI\VEN_1AF4&DEV_1050&CC_030000
4343

4444
[DVServerKMD_Device.NT]

DVServerKMD/Device.cpp

Lines changed: 50 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,7 @@ NTSTATUS DVServerKMDEvtPrepareHardware(
195195
// The following display info will be passed down from DVServerUMD
196196
// For now, just use hard coded one
197197
//
198-
DXGK_DISPLAY_INFORMATION DisplayInfo = {
199-
1024,
200-
768,
201-
4096,
202-
D3DDDIFMT_X8R8G8B8,
203-
0,
204-
0,
205-
0
206-
};
207-
208-
status = pVioGpuAdapterLite->HWInit(ResourcesTranslated, &DisplayInfo);
198+
status = pVioGpuAdapterLite->HWInit(ResourcesTranslated, &pVioGpuAdapterLite->DisplayInfo);
209199

210200
return status;
211201
}
@@ -257,7 +247,9 @@ NTSTATUS DVServerKMDEvtD0Entry(
257247
restarted, and when it has been powered off.
258248
259249
Note that interrupts will not be enabled at the time that this is called.
260-
They will be enabled after this callback completes.
250+
They will be enabled after this callback completes. Added a new callback
251+
DVServerKMDEvtDeviceD0EntryPostInterruptsEnabled, which will ensure
252+
successful enablement of interrupts for subsequent actions.
261253
262254
This function is not marked pageable because this function is in the
263255
device power up path. When a function is marked pagable and the code
@@ -281,24 +273,10 @@ NTSTATUS DVServerKMDEvtD0Entry(
281273
282274
--*/
283275
{
284-
NTSTATUS status = STATUS_SUCCESS;
285-
PDEVICE_CONTEXT pDeviceContext;
286-
VioGpuAdapterLite* pVioGpuAdapterLite;
287276
TRACING();
277+
NTSTATUS status = STATUS_SUCCESS;
288278
UNREFERENCED_PARAMETER(PreviousState);
289-
290-
pDeviceContext = DeviceGetContext(Device);
291-
292-
//
293-
// Retrieve the DVServerKMD device instance
294-
//
295-
pVioGpuAdapterLite = (VioGpuAdapterLite*)pDeviceContext->pvDeviceExtension;
296-
297-
if (!pVioGpuAdapterLite)
298-
return STATUS_UNSUCCESSFUL;
299-
300-
status = pVioGpuAdapterLite->SetPowerState(PowerDeviceD0);
301-
279+
UNREFERENCED_PARAMETER(Device);
302280
return status;
303281
}
304282

@@ -479,6 +457,50 @@ Return Value:
479457
return STATUS_SUCCESS;
480458
}
481459

460+
NTSTATUS
461+
DVServerKMDEvtDeviceD0EntryPostInterruptsEnabled(
462+
IN WDFDEVICE Device,
463+
IN WDF_POWER_DEVICE_STATE PreviousState
464+
)
465+
/*++
466+
467+
Routine Description:
468+
469+
DVServerKMDEvtDeviceD0EntryPostInterruptsEnabled is called by the framework after the
470+
driver has enabled the device's hardware interrupts.
471+
472+
Arguments:
473+
474+
Device - Handle to a framework device object.
475+
476+
PreviousState - A WDF_POWER_DEVICE_STATE-typed enumerator that identifies the
477+
previous device power state.
478+
479+
Return Value:
480+
481+
NTSTATUS - Failures will be logged, but not acted on.
482+
483+
--*/
484+
{
485+
TRACING();
486+
UNREFERENCED_PARAMETER(PreviousState);
487+
NTSTATUS status = STATUS_SUCCESS;
488+
489+
PDEVICE_CONTEXT pDeviceContext;
490+
VioGpuAdapterLite* pVioGpuAdapterLite;
491+
pDeviceContext = DeviceGetContext(Device);
492+
//
493+
// Retrieve the DVServerKMD device instance
494+
//
495+
pVioGpuAdapterLite = (VioGpuAdapterLite*)pDeviceContext->pvDeviceExtension;
496+
497+
if (!pVioGpuAdapterLite)
498+
return STATUS_UNSUCCESSFUL;
499+
status = pVioGpuAdapterLite->SetPowerState(PowerDeviceD0);
500+
501+
return status;
502+
}
503+
482504
NTSTATUS DVServerKMDEvtInterruptEnable(
483505
IN WDFINTERRUPT Interrupt,
484506
IN WDFDEVICE AssociatedDevice

DVServerKMD/Device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ EVT_WDF_DEVICE_D0_EXIT DVServerKMDEvtD0Exit;
5555
EVT_WDF_INTERRUPT_ISR DVServerKMDEvtInterruptISR;
5656
EVT_WDF_INTERRUPT_DPC DVServerKMDEvtInterruptDPC;
5757
EVT_WDF_DEVICE_D0_EXIT_PRE_INTERRUPTS_DISABLED DVServerKMDEvtDeviceD0ExitPreInterruptsDisabled;
58+
EVT_WDF_DEVICE_D0_ENTRY_POST_INTERRUPTS_ENABLED DVServerKMDEvtDeviceD0EntryPostInterruptsEnabled;
5859
EVT_WDF_INTERRUPT_ENABLE DVServerKMDEvtInterruptEnable;
5960
EVT_WDF_INTERRUPT_DISABLE DVServerKMDEvtInterruptDisable;
6061
EXTERN_C_END

DVServerKMD/Driver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ Return Value:
189189
pnpPowerCallbacks.EvtDeviceD0Exit = DVServerKMDEvtD0Exit;
190190

191191
pnpPowerCallbacks.EvtDeviceD0ExitPreInterruptsDisabled = DVServerKMDEvtDeviceD0ExitPreInterruptsDisabled;
192+
pnpPowerCallbacks.EvtDeviceD0EntryPostInterruptsEnabled = DVServerKMDEvtDeviceD0EntryPostInterruptsEnabled;
192193

193194
//
194195
// Register the PnP Callbacks..

DVServerKMD/viogpulite.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ NTSTATUS VioGpuAdapterLite::SetCurrentModeExt(CURRENT_MODE* pCurrentMode)
160160
return status;
161161
}
162162

163+
// Adding a lock here to prevent potential memory dereferencing issues,
164+
//as m_screen is utilized across multiple threads
165+
KeWaitForMutexObject(&m_screen_mutex, Executive, KernelMode, FALSE, NULL);
163166
DBGPRINT("ScreenNum = %d, Mode = %dx%d\n", pCurrentMode->DispInfo.TargetId, pCurrentMode->DispInfo.Width, pCurrentMode->DispInfo.Height);
164167

165168
for (ULONG idx = 0; idx < m_screen[pCurrentMode->DispInfo.TargetId].GetModeCount(); idx++)
@@ -183,6 +186,7 @@ NTSTATUS VioGpuAdapterLite::SetCurrentModeExt(CURRENT_MODE* pCurrentMode)
183186
break;
184187
}
185188

189+
KeReleaseMutex(&m_screen_mutex, FALSE);
186190
return status;
187191
}
188192

@@ -198,6 +202,9 @@ NTSTATUS VioGpuAdapterLite::VioGpuAdapterLiteInit()
198202
VioGpuDbgBreak();
199203
return status;
200204
}
205+
206+
KeInitializeMutex(&m_screen_mutex, 0);
207+
201208
status = VirtIoDeviceInit();
202209
if (!NT_SUCCESS(status)) {
203210
DBGPRINT("Failed to initialize virtio device, error %x\n", status);
@@ -380,7 +387,20 @@ PBYTE VioGpuAdapterLite::GetEdidData(UINT Id)
380387
{
381388
PAGED_CODE();
382389
TRACING();
383-
return m_bEDID ? m_screen[Id].m_EDIDs : (PBYTE)(&g_gpu_edid);//.data;
390+
PBYTE ret;
391+
392+
if (m_bEDID) {
393+
// Adding a lock here to prevent potential memory dereferencing issues,
394+
//as m_screen is utilized across multiple threads
395+
KeWaitForMutexObject(&m_screen_mutex, Executive, KernelMode, FALSE, NULL);
396+
ret = m_screen[Id].m_EDIDs;
397+
KeReleaseMutex(&m_screen_mutex, FALSE);
398+
}
399+
else {
400+
ret = (PBYTE)(&g_gpu_edid);
401+
}
402+
403+
return ret;
384404
}
385405

386406
NTSTATUS VioGpuAdapterLite::HWInit(WDFCMRESLIST pResList, DXGK_DISPLAY_INFORMATION* pDispInfo)
@@ -787,10 +807,14 @@ BOOLEAN VioGpuAdapterLite::GetEdids(UINT32 screen_num)
787807

788808
PGPU_VBUFFER vbuf = NULL;
789809

810+
// Adding a lock here to prevent potential memory dereferencing issues,
811+
//as m_screen is utilized across multiple threads
812+
KeWaitForMutexObject(&m_screen_mutex, Executive, KernelMode, FALSE, NULL);
790813
if (m_CtrlQueue.AskEdidInfo(&vbuf, screen_num, &m_screen[screen_num].m_EdidEvent) &&
791814
m_CtrlQueue.GetEdidInfo(vbuf, screen_num, m_screen[screen_num].m_EDIDs)) {
792815
m_bEDID = TRUE;
793816
}
817+
KeReleaseMutex(&m_screen_mutex, FALSE);
794818
m_CtrlQueue.ReleaseBuffer(vbuf);
795819

796820
return TRUE;
@@ -881,6 +905,9 @@ NTSTATUS VioGpuAdapterLite::GetModeList(DXGK_DISPLAY_INFORMATION* pDispInfo)
881905

882906
TRACING();
883907

908+
// Adding a lock here to prevent potential memory dereferencing issues,
909+
//as m_screen is utilized across multiple threads
910+
KeWaitForMutexObject(&m_screen_mutex, Executive, KernelMode, FALSE, NULL);
884911
for (UINT32 i = 0; i < m_u32NumScanouts; i++) {
885912

886913
UINT ModeCount = 0;
@@ -971,6 +998,7 @@ NTSTATUS VioGpuAdapterLite::GetModeList(DXGK_DISPLAY_INFORMATION* pDispInfo)
971998
m_screen[i].m_ModeInfo[idx].VisScreenHeight);
972999
}
9731000
}
1001+
KeReleaseMutex(&m_screen_mutex, FALSE);
9741002
return Status;
9751003
}
9761004
PAGED_CODE_SEG_END
@@ -1060,12 +1088,15 @@ void VioGpuAdapterLite::ThreadWorkRoutine(void)
10601088
void VioGpuAdapterLite::ConfigChanged(void)
10611089
{
10621090
TRACING();
1091+
NTSTATUS status = STATUS_SUCCESS;
10631092
UINT32 events_read, events_clear = 0;
10641093
virtio_get_config(&m_VioDev, FIELD_OFFSET(GPU_CONFIG, events_read),
10651094
&events_read, sizeof(m_u32NumScanouts));
10661095
if (events_read & VIRTIO_GPU_EVENT_DISPLAY) {
1067-
for (UINT32 i = 0; i < m_u32NumScanouts; i++) {
1068-
GetDisplayInfo(i);
1096+
status = GetModeList(&DisplayInfo);
1097+
if (!NT_SUCCESS(status)) {
1098+
ERR("GetModeList failed with %x\n", status);
1099+
VioGpuDbgBreak();
10691100
}
10701101
if (hpd_event) {
10711102
DBGPRINT("Sending Hot Plug event to UMD\n");
@@ -1074,10 +1105,6 @@ void VioGpuAdapterLite::ConfigChanged(void)
10741105
events_clear |= VIRTIO_GPU_EVENT_DISPLAY;
10751106
virtio_set_config(&m_VioDev, FIELD_OFFSET(GPU_CONFIG, events_clear),
10761107
&events_clear, sizeof(m_u32NumScanouts));
1077-
// UpdateChildStatus(FALSE);
1078-
// ProcessEdid();
1079-
// TODO: Enable following if needed
1080-
//UpdateChildStatus(TRUE);
10811108
}
10821109
}
10831110

DVServerKMD/viogpulite.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,22 @@ class IVioGpuAdapterLite {
127127
PVOID GetVioGpu(void) { return m_pvDeviceContext; }
128128
virtual PBYTE GetEdidData(UINT Idx) = 0;
129129
virtual PHYSICAL_ADDRESS GetFrameBufferPA(void) = 0;
130+
DXGK_DISPLAY_INFORMATION DisplayInfo = {
131+
1024,
132+
768,
133+
4096,
134+
D3DDDIFMT_X8R8G8B8,
135+
0,
136+
0,
137+
0
138+
};
130139
protected:
131140
virtual NTSTATUS GetModeList(DXGK_DISPLAY_INFORMATION* pDispInfo) = 0;
132141
protected:
133142
ULONG m_Id;
134143
ScreenInfo m_screen[MAX_SCAN_OUT];
135144
BOOLEAN m_bEDID;
145+
KMUTEX m_screen_mutex;
136146
public:
137147
PVOID m_pvDeviceContext;
138148
};
@@ -193,8 +203,6 @@ class VioGpuAdapterLite :
193203
void ProcessEdid(UINT32 screen_num);
194204
BOOLEAN GetEdids(UINT32 screen_num);
195205
void AddEdidModes(UINT32 screen_num);
196-
// Not needed by the DVServerKMD
197-
//NTSTATUS UpdateChildStatus(BOOLEAN connect);
198206
void CreateFrameBufferObj(PVIDEO_MODE_INFORMATION pModeInfo, CURRENT_MODE* pCurrentMode);
199207
void DestroyFrameBufferObj(UINT32 screen_num, BOOLEAN bReset);
200208
BOOLEAN CreateCursor(_In_ CONST DXGKARG_SETPOINTERSHAPE* pSetPointerShape, _In_ CONST CURRENT_MODE* pCurrentMode);

DVServerUMD/DVEnabler/DVEnabler.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include "Trace.h"
1414
#include "DVEnabler.tmh"
1515
#include <Windows.h>
16+
#include <stdio.h>
17+
#include <string.h>
1618

1719

1820
int dvenabler_init()
@@ -67,6 +69,11 @@ int dvenabler_init()
6769

6870
while (1)
6971
{
72+
if (IsSystemLocked()) {
73+
DBGPRINT("System is in locked state, so wait untill system gets unlocked");
74+
continue;
75+
}
76+
7077
//Reset the flags before doing QDC
7178
path_count = NULL, mode_count = NULL;
7279
found_id_path = FALSE, found_non_id_path = FALSE;
@@ -220,4 +227,58 @@ int GetDisplayCount(disp_info* pdinfo) {
220227

221228
return DVENABLER_SUCCESS;
222229

230+
}
231+
232+
233+
/*******************************************************************************
234+
*
235+
* Description
236+
*
237+
* IsSystemLocked - This function is used to check if the system is in locked
238+
* or unlocked state.
239+
*
240+
* Parameters
241+
* Null
242+
*
243+
* Return val
244+
* int - 0 = Unlocked, -1 = ERROR, 1 = Locked
245+
*
246+
******************************************************************************/
247+
248+
int IsSystemLocked() {
249+
FILE* fp;
250+
char buffer[128];
251+
int status = TRUE;
252+
253+
// Run the PowerShell command to get the system lock status
254+
fp = _popen("powershell.exe -WindowStyle Hidden -Command \"(quser 2>$null) -and (get-process logonui -ea 0)\"", "r");
255+
if (fp == NULL) {
256+
ERR("Failed to run PowerShell command.\n");
257+
return DVENABLER_FAILURE;
258+
}
259+
260+
// Read the output of the PowerShell command
261+
while (fgets(buffer, sizeof(buffer), fp) != NULL) {
262+
// Check if the output is "true" (indicating locked) and act accordingly
263+
if (strstr(buffer, "True") != NULL) {
264+
DBGPRINT("System is locked\n");
265+
status = TRUE;
266+
}
267+
else if (strstr(buffer, "False") != NULL) {
268+
DBGPRINT("System is unlocked\n");
269+
status = FALSE;
270+
}
271+
else {
272+
ERR("Unexpected output\n");
273+
status = DVENABLER_FAILURE;
274+
}
275+
}
276+
277+
// Close the pipe and print any errors
278+
if (_pclose(fp) != 0) {
279+
ERR("Error occurred while running PowerShell command.\n");
280+
return DVENABLER_FAILURE;
281+
}
282+
283+
return status;
223284
}

DVServerUMD/DVEnabler/pch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ struct disp_info {
2525
HANDLE mutex;
2626
};
2727
int GetDisplayCount(disp_info* pdinfo);
28+
int IsSystemLocked();
2829
#endif //PCH_H

DVServerUMD/DVServer/DVServer.vcxproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
<ItemGroup>
3838
<ClCompile Include="Driver.cpp" />
3939
<ClCompile Include="DVServeredid.cpp" />
40-
<ClCompile Include="DVServerregistry.cpp" />
4140
<ClCompile Include="Tracing.cpp" />
4241
</ItemGroup>
4342
<ItemGroup>
@@ -361,4 +360,4 @@ certmgr -del -c -n "DVServer" -s PrivateCertStore</Command>
361360
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
362361
<ImportGroup Label="ExtensionTargets">
363362
</ImportGroup>
364-
</Project>
363+
</Project>

0 commit comments

Comments
 (0)