Skip to content

Commit

Permalink
viogpu: Use callbacks in viogpu_queue
Browse files Browse the repository at this point in the history
Based on #943

Signed-off-by: Max Ramanouski <[email protected]>
Signed-off-by: Kostiantyn Kostiuk <[email protected]>
  • Loading branch information
kostyanf14 committed Oct 24, 2024
1 parent b3554bc commit a97b30d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
13 changes: 11 additions & 2 deletions viogpu/common/viogpu_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ static BOOLEAN BuildSGElement(VirtIOBufferDescriptor* sg, PVOID buf, ULONG size)
return FALSE;
}

static void NotifyEventCompleteCB(void* ctx) {
KeSetEvent((PKEVENT)ctx, IO_NO_INCREMENT, FALSE);
}

VioGpuQueue::VioGpuQueue()
{
m_pBuf = NULL;
Expand Down Expand Up @@ -209,7 +213,9 @@ BOOLEAN CtrlQueue::AskDisplayInfo(PGPU_VBUFFER* buf)
cmd->type = VIRTIO_GPU_CMD_GET_DISPLAY_INFO;

KeInitializeEvent(&event, NotificationEvent, FALSE);
vbuf->event = &event;
vbuf->complete_cb = NotifyEventCompleteCB;
vbuf->complete_ctx = &event;
vbuf->auto_release = false;

LARGE_INTEGER timeout = { 0 };
timeout.QuadPart = Int32x32To64(1000, -10000);
Expand Down Expand Up @@ -259,7 +265,9 @@ BOOLEAN CtrlQueue::AskEdidInfo(PGPU_VBUFFER* buf, UINT id)
cmd->scanout = id;

KeInitializeEvent(&event, NotificationEvent, FALSE);
vbuf->event = &event;
vbuf->complete_cb = NotifyEventCompleteCB;
vbuf->complete_ctx = &event;
vbuf->auto_release = false;

LARGE_INTEGER timeout = { 0 };
timeout.QuadPart = Int32x32To64(1000, -10000);
Expand Down Expand Up @@ -701,6 +709,7 @@ PGPU_VBUFFER VioGpuBuf::GetBuf(

pbuf->buf = (char *)((ULONG_PTR)pbuf + sizeof(*pbuf));
pbuf->size = size;
pbuf->auto_release = true;

pbuf->resp_size = resp_size;
if (resp_size <= MAX_INLINE_RESP_SIZE)
Expand Down
6 changes: 5 additions & 1 deletion viogpu/common/viogpu_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ typedef struct virtio_gpu_vbuffer {

char *resp_buf;
int resp_size;
PKEVENT event;
LIST_ENTRY list_entry;

void (*complete_cb)(void *ctx);
void *complete_ctx;

bool auto_release;
}GPU_VBUFFER, *PGPU_VBUFFER;
//#pragma pack()

Expand Down
24 changes: 8 additions & 16 deletions viogpu/viogpudo/viogpudo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3317,29 +3317,21 @@ VOID VioGpuAdapter::DpcRoutine(_In_ PDXGKRNL_INTERFACE pDxgkInterface)
DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s m_CtrlQueue pvbuf = %p len = %d\n", __FUNCTION__, pvbuf, len));
PGPU_CTRL_HDR pcmd = (PGPU_CTRL_HDR)pvbuf->buf;
PGPU_CTRL_HDR resp = (PGPU_CTRL_HDR)pvbuf->resp_buf;
PKEVENT evnt = pvbuf->event;
if (evnt == NULL)
{

if (resp->type >= VIRTIO_GPU_RESP_ERR_UNSPEC) {
DbgPrint(TRACE_LEVEL_FATAL, ("!!!!! Command failed %d", resp->type));
}
if (resp->type != VIRTIO_GPU_RESP_OK_NODATA)
{
DbgPrint(TRACE_LEVEL_ERROR, ("<--- %s type = %xlu flags = %lu fence_id = %llu ctx_id = %lu cmd_type = %lu\n",
__FUNCTION__, resp->type, resp->flags, resp->fence_id, resp->ctx_id, pcmd->type));
}
m_CtrlQueue.ReleaseBuffer(pvbuf);
continue;
}
switch (pcmd->type)
if (pvbuf->complete_cb != NULL)
{
case VIRTIO_GPU_CMD_GET_DISPLAY_INFO:
case VIRTIO_GPU_CMD_GET_EDID:
{
ASSERT(evnt);
KeSetEvent(evnt, IO_NO_INCREMENT, FALSE);
pvbuf->complete_cb(pvbuf->complete_ctx);
}
break;
default:
DbgPrint(TRACE_LEVEL_ERROR, ("<--- %s Unknown cmd type 0x%x\n", __FUNCTION__, resp->type));
break;
if (pvbuf->auto_release) {
m_CtrlQueue.ReleaseBuffer(pvbuf);
}
};
}
Expand Down

0 comments on commit a97b30d

Please sign in to comment.