>From 55dc00d6c15d4bc34bca41f785c0509fc91275df Mon Sep 17 00:00:00 2001 From: Vadim Rozenfeld <vrozenfe@xxxxxxxxxx> Date: Mon, 16 May 2011 14:41:20 +0300 Subject: [COMMIT] [vioserial] fix send buffer and remove port logic --- vioserial/sys/Buffer.c | 68 ++++++++++++++++++++++++++++++++++++++++++++-- vioserial/sys/Control.c | 18 +++++++----- vioserial/sys/vioser.h | 19 +++++++++--- 3 files changed, 89 insertions(+), 16 deletions(-) diff --git a/vioserial/sys/Buffer.c b/vioserial/sys/Buffer.c index 003a5ee..ded83c7 100644 --- a/vioserial/sys/Buffer.c +++ b/vioserial/sys/Buffer.c @@ -42,13 +42,76 @@ VIOSerialAllocateBuffer( return buf; } +SSIZE_T +VIOSerialSendBuffers( + IN PVIOSERIAL_PORT port, + IN PVOID buf, + IN SIZE_T count, + IN BOOLEAN nonblock +) +{ + UINT dummy; + SSIZE_T ret; + struct VirtIOBufferDescriptor sg; + struct virtqueue *vq = GetOutQueue(port); + PVOID ptr = buf; + SIZE_T len = count; + UINT elements = 0; + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, "--> %s buf = %p, length = %d\n", __FUNCTION__, buf, (int)count); + + WdfSpinLockAcquire(port->OutVqLock); + VIOSerialReclaimConsumedBuffers(port); + + while (len) + { + do + { + sg.physAddr = GetPhysicalAddress(ptr); + sg.ulSize = min(PAGE_SIZE, (unsigned long)len); + + ret = vq->vq_ops->add_buf(vq, &sg, 1, 0, ptr); + if (ret == 0) + { + ptr = (PVOID)((LONG_PTR)ptr + sg.ulSize); + len -= sg.ulSize; + elements++; + } + } while ((ret == 0) && (len > 0)); + + vq->vq_ops->kick(vq); + port->OutVqFull = TRUE; + if (!nonblock) + { + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, "--> %s !nonblock \n", __FUNCTION__); + while(elements) + { + if(vq->vq_ops->get_buf(vq, &dummy)) + { + elements--; + } + else + { + KeStallExecutionProcessor(100); + } + } + } + else + { + //FIXME + } + } + WdfSpinLockRelease(port->OutVqLock); + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, "<-- %s\n", __FUNCTION__); + return count; +} + VOID VIOSerialFreeBuffer( IN PPORT_BUFFER buf ) { ASSERT(buf); - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_QUEUEING, "--> %s buf = % p, buf->va_buf = %p\n", __FUNCTION__, buf, buf->va_buf); + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_QUEUEING, "--> %s buf = %p, buf->va_buf = %p\n", __FUNCTION__, buf, buf->va_buf); if (buf->va_buf) { ExFreePoolWithTag(buf->va_buf, VIOSERIAL_DRIVER_MEMORY_TAG); @@ -84,7 +147,6 @@ VIOSerialFillReadBuf( ) { PPORT_BUFFER buf; - struct virtqueue *vq = GetOutQueue(port); NTSTATUS status = STATUS_SUCCESS; TraceEvents(TRACE_LEVEL_VERBOSE, DBG_QUEUEING, "--> %s\n", __FUNCTION__); @@ -123,7 +185,7 @@ VIOSerialAddInBuf( NTSTATUS status = STATUS_SUCCESS; struct VirtIOBufferDescriptor sg; - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_QUEUEING, "--> %s buf = % p\n", __FUNCTION__, buf); + TraceEvents(TRACE_LEVEL_VERBOSE, DBG_QUEUEING, "--> %s buf = %p \n", __FUNCTION__, buf); if (buf == NULL) { ASSERT(0); diff --git a/vioserial/sys/Control.c b/vioserial/sys/Control.c index 329feb4..7a9be7b 100644 --- a/vioserial/sys/Control.c +++ b/vioserial/sys/Control.c @@ -129,15 +129,13 @@ VIOSerialHandleCtrlMsg( break; case VIRTIO_CONSOLE_PORT_REMOVE: - if (port) - { - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "VIRTIO_CONSOLE_PORT_REMOVE id = %d\n", cpkt->id); - VIOSerialRemovePort(Device, port); - } - else + if (!port) { TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, "VIRTIO_CONSOLE_PORT_REMOVE invalid id = %d\n", cpkt->id); + break; } + TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "VIRTIO_CONSOLE_PORT_REMOVE id = %d\n", cpkt->id); + VIOSerialRemovePort(Device, port); break; case VIRTIO_CONSOLE_CONSOLE_PORT: @@ -156,8 +154,12 @@ VIOSerialHandleCtrlMsg( case VIRTIO_CONSOLE_PORT_OPEN: if (port) { - TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "VIRTIO_CONSOLE_PORT_OPEN id = %d, HostConnected = %d\n", cpkt->id, cpkt->value); - port->HostConnected = (BOOLEAN)cpkt->value; + BOOLEAN Connected = (BOOLEAN)cpkt->value; + TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, "VIRTIO_CONSOLE_PORT_OPEN id = %d, HostConnected = %d\n", cpkt->id, Connected); + if (port->HostConnected != Connected) + { + VIOSerialPortPnpNotify(Device, port, Connected); + } } else { diff --git a/vioserial/sys/vioser.h b/vioserial/sys/vioser.h index 2712a0f..3a47d60 100644 --- a/vioserial/sys/vioser.h +++ b/vioserial/sys/vioser.h @@ -180,6 +180,14 @@ VIOSerialReclaimConsumedBuffers( ); SSIZE_T +VIOSerialSendBuffers( + IN PVIOSERIAL_PORT port, + IN PVOID buf, + IN SIZE_T count, + IN BOOLEAN nonblock +); + +SSIZE_T VIOSerialFillReadBuf( IN PVIOSERIAL_PORT port, IN PVOID outbuf, @@ -286,16 +294,17 @@ EVT_WDF_DEVICE_FILE_CREATE VIOSerialPortCreate; EVT_WDF_FILE_CLOSE VIOSerialPortClose; VOID -VIOSerialPortWriteRequestComplete( - IN WDFDMATRANSACTION DmaTransaction, - IN NTSTATUS Status +VIOSerialPortCreateName ( + IN WDFDEVICE WdfDevice, + IN PVIOSERIAL_PORT port, + IN PPORT_BUFFER buf ); VOID -VIOSerialPortCreateName ( +VIOSerialPortPnpNotify ( IN WDFDEVICE WdfDevice, IN PVIOSERIAL_PORT port, - IN PPORT_BUFFER buf + IN BOOLEAN connected ); VOID -- 1.7.0.2.msysgit.0 -- To unsubscribe from this list: send the line "unsubscribe kvm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html