Append mmconf region in createDeviceFromPath
authorReto Buerki <reet@codelabs.ch>
Mon, 11 Sep 2017 10:03:29 +0000 (12:03 +0200)
committerReto Buerki <reet@codelabs.ch>
Tue, 26 Sep 2017 13:00:15 +0000 (15:00 +0200)
src/creator.py
src/dmar.py
test/test_creator.py

index d26d356..d33add9 100644 (file)
@@ -649,6 +649,12 @@ class PciDevicesCreator():
     def createDeviceFromPath(self, devicepath, devicecapmgr, devicespec,
                              iommugrp):
         device = schemadata.schema.deviceType(name=devicespec.name)
+        pcistr = os.path.basename(devicepath)
+
+        bus = int(self.getDeviceBus(pcistr), 16)
+        devno = int(self.getDeviceNo(pcistr), 16)
+        fn = int(self.getDeviceFunction(pcistr), 16)
+
         if devicespec.descr:
             device.description = devicespec.descr
 
@@ -663,15 +669,18 @@ class PciDevicesCreator():
         for devmemblock in self.getDeviceMemory(devicepath):
             device.append(devmemblock)
 
+        # mmconf
+        device.append(
+            self.get_mmconf(int(getPciConfigAddress(paths.IOMEM), 16),
+                            bus, devno, fn))
+
         # ioports
         for ioport in self.getIoports(devicepath):
             device.append(ioport)
 
         # reserved memory region if present
-        pcistr = os.path.basename(devicepath)
-        rmrr = dmar.get_referenced_rmrr(self.getDeviceBus(pcistr),
-                                        self.getDeviceNo(pcistr),
-                                        self.getDeviceFunction(pcistr))
+        rmrr = dmar.get_referenced_rmrr(bus, devno, fn)
+
         if rmrr:
             device.append(schemadata.schema.namedRefType(ref=rmrr))
 
index 64d3594..d669599 100644 (file)
@@ -120,11 +120,8 @@ def get_referenced_rmrr(bus, device, fn):
     PCI device. If the given device does not reference an RMRR 'none' is
     returned.
     """
-    b = int(bus, 16)
-    d = int(device, 16)
-    f = int(fn, 16)
     for dev in _devices:
-        if dev.bus == b and dev.device == d and dev.function == f:
+        if dev.bus == bus and dev.device == device and dev.function == fn:
             return dev.rmrr_name
 
     return None
index baea7f0..fc40dd5 100644 (file)
@@ -664,7 +664,15 @@ class TestPciDevicesCreator:
 
         device.append(pci)
         device.append(irq)
-        device.append(memory)
+        device.append(src.schemadata.schema.deviceMemoryType(
+            caching="UC", name="mem1", physicalAddress="16#fb22_4000#",
+            size="16#1000#"))
+        # PCI config base not readable as non-root, set to known value
+        mmconfaddr = "16#f800_2000#"
+        resultdev.memory[1].physicalAddress = mmconfaddr
+        device.append(src.schemadata.schema.deviceMemoryType(
+            caching="UC", name="mmconf", physicalAddress=mmconfaddr,
+            size="16#1000#"))
         device.append(ioport)
         device.append(rmrr)