[COMMIT] [vioserial] Add device Id to the port name.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>From d6c22f4cc4fe3ae9e12858aa75f3c943adebe7e2 Mon Sep 17 00:00:00 2001
From: Vadim Rozenfeld <vrozenfe@xxxxxxxxxx>
Date: Mon, 16 May 2011 13:57:51 +0300
Subject: [COMMIT] [vioserial] Add device Id to the port name

---
 vioserial/sys/Device.c |    8 +++++-
 vioserial/sys/Port.c   |   60
++++++++++++++++++++++++-----------------------
 vioserial/sys/vioser.h |    9 ++++---
 3 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/vioserial/sys/Device.c b/vioserial/sys/Device.c
index 544efa9..3b856eb 100644
--- a/vioserial/sys/Device.c
+++ b/vioserial/sys/Device.c
@@ -37,6 +37,8 @@ static NTSTATUS VIOSerialShutDownAllQueues(IN
WDFOBJECT WdfDevice);
 
 #endif
 
+static UINT gDeviceCount = 0;
+
 static
 NTSTATUS
 VIOSerialInitInterruptHandling(
@@ -86,6 +88,7 @@ VIOSerialEvtDeviceAdd(
     WDF_PNPPOWER_EVENT_CALLBACKS PnpPowerCallbacks;
     WDF_CHILD_LIST_CONFIG        ChildListConfig;
     PNP_BUS_INFORMATION          busInfo;
+    PPORTS_DEVICE                pContext = NULL;
 	
     UNREFERENCED_PARAMETER(Driver);
 
@@ -149,9 +152,12 @@ VIOSerialEvtDeviceAdd(
         return status;
     }
 
+    pContext = GetPortsDevice(hDevice);
+    pContext->DeviceId = gDeviceCount++;
+
     busInfo.BusTypeGuid = GUID_DEVCLASS_PORT_DEVICE;
     busInfo.LegacyBusType = PNPBus;
-    busInfo.BusNumber = 0;
+    busInfo.BusNumber = pContext->DeviceId;
 
     WdfDeviceSetBusInformationForChildren(hDevice, &busInfo);
 
diff --git a/vioserial/sys/Port.c b/vioserial/sys/Port.c
index d3c68e4..ec55da1 100644
--- a/vioserial/sys/Port.c
+++ b/vioserial/sys/Port.c
@@ -62,7 +62,7 @@ VIOSerialFindPortById(
         ASSERT(childInfo.Status == WdfChildListRetrieveDeviceSuccess);
         rawPdo = RawPdoSerialPortGetData(hChild);
 
-        if(rawPdo && rawPdo->port->Id == id)
+        if(rawPdo && rawPdo->port->PortId == id)
         {
             WdfChildListEndIteration(list, &iterator);
             TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,"%s  id = %d
port = 0x%p\n", __FUNCTION__, id, rawPdo->port);
@@ -83,14 +83,15 @@ VIOSerialAddPort(
     PPORTS_DEVICE   pContext = GetPortsDevice(Device);
     NTSTATUS        status = STATUS_SUCCESS;
 
-    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,"%s  port = %d\n",
__FUNCTION__, id);
+    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,"%s  DeviceId = %d ::
PortId = %d\n", __FUNCTION__, pContext->DeviceId, id);
 
     WDF_CHILD_IDENTIFICATION_DESCRIPTION_HEADER_INIT(
                                  &port.Header,
                                  sizeof(port)
                                  );
 
-    port.Id = id;
+    port.PortId = id;
+    port.DeviceId = pContext->DeviceId;
     port.NameString.Buffer = NULL;
     port.NameString.Length = 0;
     port.NameString.MaximumLength = 0;
@@ -130,7 +131,7 @@ VIOSerialRemovePort(
     WDFCHILDLIST    list;
     WDF_CHILD_LIST_ITERATOR     iterator;
 
-    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,"%s  port = %d\n",
__FUNCTION__, port->Id);
+    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP,"%s  port = %d\n",
__FUNCTION__, port->PortId);
 
     list = WdfFdoGetDefaultChildList(Device);
     WDF_CHILD_LIST_ITERATOR_INIT(&iterator,
@@ -163,7 +164,8 @@ VIOSerialRemovePort(
         }
         ASSERT(childInfo.Status == WdfChildListRetrieveDeviceSuccess);
 
-        if(vport.Id == port->Id)
+        if ((vport.PortId == port->PortId) &&
+            (vport.DeviceId == port->DeviceId))
         {
            status = WdfChildListUpdateChildDescriptionAsMissing(
                                  list,
@@ -181,7 +183,7 @@ VIOSerialRemovePort(
 
            if(vport.GuestConnected)
            {
-              VIOSerialSendCtrlMsg(vport.BusDevice, vport.Id,
VIRTIO_CONSOLE_PORT_OPEN, 0);
+              VIOSerialSendCtrlMsg(vport.BusDevice, vport.PortId,
VIRTIO_CONSOLE_PORT_OPEN, 0);
            }
            WdfSpinLockAcquire(vport.InBufLock);
            VIOSerialDiscardPortData(&vport);
@@ -263,7 +265,7 @@ VIOSerialRenewAllPorts(
 
         if(vport.GuestConnected)
         {
-           VIOSerialSendCtrlMsg(vport.BusDevice, vport.Id,
VIRTIO_CONSOLE_PORT_OPEN, 1);
+           VIOSerialSendCtrlMsg(vport.BusDevice, vport.PortId,
VIRTIO_CONSOLE_PORT_OPEN, 1);
         }
     }
     WdfChildListEndIteration(list, &iterator);
@@ -326,7 +328,7 @@ VIOSerialShutdownAllPorts(
 
         if(vport.GuestConnected)
         {
-           VIOSerialSendCtrlMsg(vport.BusDevice, vport.Id,
VIRTIO_CONSOLE_PORT_OPEN, 0);
+           VIOSerialSendCtrlMsg(vport.BusDevice, vport.PortId,
VIRTIO_CONSOLE_PORT_OPEN, 0);
         }
 
         WdfSpinLockAcquire(vport.InBufLock);
@@ -356,7 +358,7 @@ VIOSerialInitPortConsole(
     TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "--> %s\n",
__FUNCTION__);
 
     port->GuestConnected = TRUE;
-    VIOSerialSendCtrlMsg(port->BusDevice, port->Id,
VIRTIO_CONSOLE_PORT_OPEN, 1);
+    VIOSerialSendCtrlMsg(port->BusDevice, port->PortId,
VIRTIO_CONSOLE_PORT_OPEN, 1);
 }
 
 VOID
@@ -463,16 +465,16 @@ VIOSerialPortSendPortReady(
     PRAWPDO_VIOSERIAL_PORT  pdoData =
RawPdoSerialPortGetData(WorkItem);
     PVIOSERIAL_PORT         pport = pdoData->port;
 
-    if(!VIOSerialFindPortById(pport->BusDevice, pport->Id))
+    if(!VIOSerialFindPortById(pport->BusDevice, pport->PortId))
     {
         TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "%s re-enqueue
work item for id=%d\n",
-        __FUNCTION__, pport->Id);
+        __FUNCTION__, pport->PortId);
         WdfWorkItemEnqueue(WorkItem);
         return;
     }
     TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "%s sending
PORT_READY for id=%d\n",
-        __FUNCTION__, pport->Id);
-    VIOSerialSendCtrlMsg(pport->BusDevice, pport->Id,
VIRTIO_CONSOLE_PORT_READY, 1);
+        __FUNCTION__, pport->PortId);
+    VIOSerialSendCtrlMsg(pport->BusDevice, pport->PortId,
VIRTIO_CONSOLE_PORT_READY, 1);
 }
 
 NTSTATUS
@@ -524,7 +526,7 @@ VIOSerialDeviceListCreatePdo(
                                  L"%ws%vport%up%u",
                                  L"\\Device\\",
                                  0,
-                                 pport->Id
+                                 pport->PortId
                                  );
 
         if (!NT_SUCCESS(status))
@@ -571,7 +573,7 @@ VIOSerialDeviceListCreatePdo(
         status = RtlUnicodeStringPrintf(
                                  &buffer,
                                  L"%04d", 
-                                 pport->Id
+                                 pport->PortId
                                  );
         if (!NT_SUCCESS(status))
         {
@@ -589,7 +591,7 @@ VIOSerialDeviceListCreatePdo(
         status = RtlUnicodeStringPrintf(
                                  &buffer, 
                                  L"%02d", 
-                                 pport->Id
+                                 pport->PortId
                                  );
         if (!NT_SUCCESS(status))
         {
@@ -607,8 +609,8 @@ VIOSerialDeviceListCreatePdo(
         status = RtlUnicodeStringPrintf(
                                  &buffer,
                                  L"vport%up%u",
-                                 0,
-                                 pport->Id
+                                 pport->DeviceId,
+                                 pport->PortId
                                  );
         if (!NT_SUCCESS(status))
         {
@@ -772,8 +774,8 @@ VIOSerialDeviceListCreatePdo(
         pnpCaps.Removable        =  WdfTrue;
         pnpCaps.EjectSupported   =  WdfTrue;
         pnpCaps.SurpriseRemovalOK=  WdfTrue;
-        pnpCaps.Address          =  pport->Id;
-        pnpCaps.UINumber         =  pport->Id;
+        pnpCaps.Address          =  pport->DeviceId;
+        pnpCaps.UINumber         =  pport->PortId;
 
         WdfDeviceSetPnpCapabilities(hChild, &pnpCaps);
 
@@ -907,7 +909,7 @@ VIOSerialDeviceListCreatePdo(
     if (!NT_SUCCESS(status))
     {
         // We can send this before PDO is PRESENT since the device
won't send any response.
-        VIOSerialSendCtrlMsg(pport->BusDevice, pport->Id,
VIRTIO_CONSOLE_PORT_READY, 0);
+        VIOSerialSendCtrlMsg(pport->BusDevice, pport->PortId,
VIRTIO_CONSOLE_PORT_READY, 0);
     }
 
     TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<--%s status 0x%x
\n", __FUNCTION__, status);
@@ -1156,7 +1158,7 @@ VIOSerialPortDeviceControl(
               break;
            }
            RtlZeroMemory(pport_info, sizeof(VIRTIO_PORT_INFO));
-           pport_info->Id = pdoData->port->Id;
+           pport_info->Id = pdoData->port->PortId;
            pport_info->OutVqFull = pdoData->port->OutVqFull;
            pport_info->HostConnected = pdoData->port->HostConnected;
            pport_info->GuestConnected = pdoData->port->GuestConnected;
@@ -1196,13 +1198,13 @@ VIOSerialPortCreate(
 
     UNREFERENCED_PARAMETER(FileObject);
 
-    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_CREATE_CLOSE,"%s Port id =
%d\n", __FUNCTION__, pdoData->port->Id);
+    TraceEvents(TRACE_LEVEL_INFORMATION, DBG_CREATE_CLOSE,"%s Port id =
%d\n", __FUNCTION__, pdoData->port->PortId);
 
     WdfSpinLockAcquire(pdoData->port->InBufLock);
     if (pdoData->port->GuestConnected == TRUE)
     {
         WdfSpinLockRelease(pdoData->port->InBufLock);
-        TraceEvents(TRACE_LEVEL_INFORMATION, DBG_CREATE_CLOSE,"Guest
already connected Port id = %d\n", pdoData->port->Id);
+        TraceEvents(TRACE_LEVEL_INFORMATION, DBG_CREATE_CLOSE,"Guest
already connected Port id = %d\n", pdoData->port->PortId);
         status = STATUS_OBJECT_NAME_EXISTS;
     }
     else
@@ -1214,7 +1216,7 @@ VIOSerialPortCreate(
         VIOSerialReclaimConsumedBuffers(pdoData->port);
         WdfSpinLockRelease(pdoData->port->OutVqLock);
 
-        VIOSerialSendCtrlMsg(pdoData->port->BusDevice,
pdoData->port->Id, VIRTIO_CONSOLE_PORT_OPEN, 1);
+        VIOSerialSendCtrlMsg(pdoData->port->BusDevice,
pdoData->port->PortId, VIRTIO_CONSOLE_PORT_OPEN, 1);
     }
     WdfRequestComplete(Request, status);
 
@@ -1230,7 +1232,7 @@ VIOSerialPortClose(
 
     TraceEvents(TRACE_LEVEL_INFORMATION, DBG_CREATE_CLOSE, "%s\n",
__FUNCTION__);
 
-    VIOSerialSendCtrlMsg(pdoData->port->BusDevice, pdoData->port->Id,
VIRTIO_CONSOLE_PORT_OPEN, 0);
+    VIOSerialSendCtrlMsg(pdoData->port->BusDevice,
pdoData->port->PortId, VIRTIO_CONSOLE_PORT_OPEN, 0);
 
     WdfSpinLockAcquire(pdoData->port->InBufLock);
     pdoData->port->GuestConnected = FALSE;
@@ -1426,8 +1428,8 @@
VIOSerialEvtChildListIdentificationDescriptionDuplicate(
                                  dst->NameString.MaximumLength
                                  );
     }
-
-    dst->Id = src->Id;
+    dst->DeviceId = src->DeviceId;
+    dst->PortId = src->PortId;
 
     dst->OutVqFull = src->OutVqFull;
     dst->HostConnected = src->HostConnected;
@@ -1469,7 +1471,7 @@
VIOSerialEvtChildListIdentificationDescriptionCompare(
                             VIOSERIAL_PORT,
                             Header);
 
-    return (lhs->Id == rhs->Id);
+    return ((lhs->PortId == rhs->PortId) && (lhs->DeviceId ==
rhs->DeviceId));
 }
 
 VOID
diff --git a/vioserial/sys/vioser.h b/vioserial/sys/vioser.h
index 467367b..5caabc6 100644
--- a/vioserial/sys/vioser.h
+++ b/vioserial/sys/vioser.h
@@ -96,6 +96,7 @@ typedef struct _tagPortDevice
     ULONG               MaximumTransferLength;
 
     BOOLEAN             DeviceOK;
+    UINT                DeviceId;
 } PORTS_DEVICE, *PPORTS_DEVICE;
 
 WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(PORTS_DEVICE, GetPortsDevice)
@@ -136,8 +137,8 @@ typedef struct _tagVioSerialPort
     WDFSPINLOCK         InBufLock;
     WDFSPINLOCK         OutVqLock;
     ANSI_STRING         NameString;
-    UINT                Id;
-
+    UINT                PortId;
+    UINT                DeviceId;
     BOOLEAN             OutVqFull;
     BOOLEAN             HostConnected;
     BOOLEAN             GuestConnected;
@@ -328,7 +329,7 @@ GetInQueue (
     ASSERT (port->BusDevice);
     pContext = GetPortsDevice(port->BusDevice);
     ASSERT (pContext->in_vqs);
-    return pContext->in_vqs[port->Id];
+    return pContext->in_vqs[port->PortId];
 };
 
 __inline
@@ -343,7 +344,7 @@ GetOutQueue (
     ASSERT (port->BusDevice);
     pContext = GetPortsDevice(port->BusDevice);
     ASSERT (pContext->out_vqs);
-    return pContext->out_vqs[port->Id];
+    return pContext->out_vqs[port->PortId];
 };
 
 #endif /* VIOSERIAL_H */
-- 
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


[Index of Archives]     [KVM Development]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Walks]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux