dev: Add a dummy VirtIO device
authorAndreas Sandberg <andreas.sandberg@arm.com>
Mon, 7 Nov 2016 18:16:51 +0000 (18:16 +0000)
committerAndreas Sandberg <andreas.sandberg@arm.com>
Mon, 3 Apr 2017 16:36:15 +0000 (16:36 +0000)
VirtIO transport interfaces always expect a VirtIO device
pointer. However, there are cases (in particular when using VirtIO's
MMIO interface) where we want to instantiate an interface without a
device. Add a dummy device using VirtIO device ID 0 and no queues to
handle this use case.

Change-Id: I6cbe12fd403903ef585be40279c3b1321fde48ff
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Sudhanshu Jha <sudhanshu.jha@arm.com>
Reviewed-by: Rekai Gonzalez Alberquilla <rekai.gonzalezalberquilla@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/2325
Reviewed-by: Weiping Liao <weipingliao@google.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
src/dev/virtio/VirtIO.py
src/dev/virtio/base.cc
src/dev/virtio/base.hh

index 1345c7603dc43051b504d629a018a4d68b6d447e..bf050fd4786913f6ca3d3965af811b64dcd41e6a 100644 (file)
@@ -1,6 +1,6 @@
 # -*- mode:python -*-
 
-# Copyright (c) 2014 ARM Limited
+# Copyright (c) 2014, 2016 ARM Limited
 # All rights reserved.
 #
 # The license below extends only to copyright in the software and shall
@@ -53,11 +53,15 @@ class VirtIODeviceBase(SimObject):
 
     system = Param.System(Parent.any, "system object")
 
+class VirtIODummyDevice(VirtIODeviceBase):
+    type = 'VirtIODummyDevice'
+    cxx_header = 'dev/virtio/base.hh'
+
 class PciVirtIO(PciDevice):
     type = 'PciVirtIO'
     cxx_header = 'dev/virtio/pci.hh'
 
-    vio = Param.VirtIODeviceBase("VirtIO device")
+    vio = Param.VirtIODeviceBase(VirtIODummyDevice(), "VirtIO device")
 
     VendorID = 0x1AF4
     SubsystemVendorID = VendorID;
index f098784d0a4e4e84a07a3bb804456ce24a9ca2e9..61dd3069f45a2f5e37c9f1d6788ee12670464c48 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 ARM Limited
+ * Copyright (c) 2014, 2016 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -41,6 +41,7 @@
 
 #include "debug/VIO.hh"
 #include "params/VirtIODeviceBase.hh"
+#include "params/VirtIODummyDevice.hh"
 
 VirtDescriptor::VirtDescriptor(PortProxy &_memProxy, VirtQueue &_queue,
                                Index descIndex)
@@ -477,3 +478,15 @@ VirtIODeviceBase::registerQueue(VirtQueue &queue)
 {
     _queues.push_back(&queue);
 }
+
+
+VirtIODummyDevice::VirtIODummyDevice(VirtIODummyDeviceParams *params)
+    : VirtIODeviceBase(params, ID_INVALID, 0, 0)
+{
+}
+
+VirtIODummyDevice *
+VirtIODummyDeviceParams::create()
+{
+    return new VirtIODummyDevice(this);
+}
index 4d4c165364173741784a78cd57391bb6f02fb5c8..89c281f215fe4d9383647925a94046d110a5fbba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 ARM Limited
+ * Copyright (c) 2014, 2016 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -48,6 +48,8 @@
 #include "sim/sim_object.hh"
 
 struct VirtIODeviceBaseParams;
+struct VirtIODummyDeviceParams;
+
 class VirtQueue;
 
 /** @{
@@ -875,4 +877,14 @@ class VirtIODeviceBase : public SimObject
     Callback *transKick;
 };
 
+class VirtIODummyDevice : public VirtIODeviceBase
+{
+  public:
+    VirtIODummyDevice(VirtIODummyDeviceParams *params);
+
+  protected:
+    /** VirtIO device ID */
+    static const DeviceId ID_INVALID = 0x00;
+};
+
 #endif // __DEV_VIRTIO_BASE_HH__