Esempio n. 1
0
    def getIoports(self, devicepath):
        ioports = []

        try:
            resourceData = extractor.extractData(
                os.path.join(devicepath, "resource"))
        except IOError:
            message.addError("Could not obtain ioport information for device: "
                             "%s" % os.path.basename(
                                 devicepath),
                             False)
        else:
            ioportcount = 0
            for line in resourceData.splitlines():
                tokens = line.split(' ')
                if tokens[2][-3] == '1':  # if line represents ioport information

                    ioPort = Element("ioPort", "ioPortType")
                    ioPort["name"] = "ioport%d" % ioportcount
                    ioPort["start"] = util.toWord64(tokens[0])
                    ioPort["end"] = util.toWord64(tokens[1])
                    ioportcount += 1

                    ioports.append(ioPort)
        return ioports
Esempio n. 2
0
    def getDeviceMemoryBlocks(self, devicepath, minsize=PAGE_MIN_SIZE):
        devmemblocks = []
        try:
            resourceData = extractor.extractData(
                os.path.join(devicepath, "resource"))
        except IOError:
            message.addError("Could not obtain memory information for device: "
                             "%s" % os.path.basename(
                                 devicepath),
                             False)
        else:
            memcount = 0
            for line in resourceData.splitlines():
                tokens = line.split(' ')
                if tokens[2][-3] == '2':  # if line represents a memory block

                    memory = Element("memory", "deviceMemoryType")
                    memory["name"] = "mem%d" % memcount
                    memory["physicalAddress"] = util.toWord64(tokens[0])
                    # Rounds memsize up to minsize
                    memsize = util.sizeOf(tokens[1], tokens[0])
                    if int(memsize, 16) < int(minsize, 16):
                        memrounded = util.hexFloor(memsize, minsize)
                        print ("Mem size %s for device %s rounded to: %s" %
                              (memsize,
                               os.path.basename(devicepath),
                               memrounded))
                        memsize = memrounded

                    memory["size"] = util.toWord64(memsize)
                    memory["caching"] = "UC"  # TODO
                    devmemblocks.append(memory)
                    memcount += 1

        return devmemblocks
Esempio n. 3
0
    def createSerialDevices(self, addresses):
        "Creates serial devices that are not COM devices"
        devices = []
        serialcount = 0
        for addr in addresses:
            device = Element("device", "deviceType")
            device["name"] = "serial_%d" % serialcount
            device["shared"] = "true"
            ioport = Element("ioPort", "ioPortType")
            ioport["name"] = "ioport"
            ioport["start"] = util.toWord64(addr.start)
            ioport["end"] = util.toWord64(addr.end)
            device.appendChild(ioport)
            devices.append(device)
            serialcount += 1

        return devices
Esempio n. 4
0
    def createDeviceFromAddr(self,
                             devmem,
                             iommuaddr,
                             iommunamer,
                             iommusize,
                             capoffset,
                             capregbytesize,
                             agaw_bit_start):
        "Generates a device element from a given iommu address"

        device = Element("device", "deviceType")
        device["shared"] = "false"

        # name attr
        device["name"] = iommunamer.getName()

        # memory
        memory = Element("memory", "deviceMemoryType")
        memory["caching"] = "UC"  # TODO
        memory["name"] = "mmio"
        memory["physicalAddress"] = util.toWord64(iommuaddr)
        memory["size"] = util.toWord64(iommusize)
        device.appendChild(memory)

        # capabilities
        capabilities = Element("capabilities", "capabilitiesType")
        # iommu
        iommucap = Element("capability", "capabilityType")
        iommucap["name"] = "iommu"
        capabilities.appendChild(iommucap)
        # agaw
        agawcap = Element("capability", "capabilityType")
        agawcap["name"] = "agaw"
        agawcap.content = self.getIommuAGAW(iommuaddr,
                                            devmem,
                                            capoffset,
                                            capregbytesize,
                                            agaw_bit_start)
        capabilities.appendChild(agawcap)
        device.appendChild(capabilities)

        return device
Esempio n. 5
0
    def createComDevices(self, serialAddresses, comAddresses):
        "Creates COM devices from those in serialAddresses that match the addr"
        "in comAddresses"
        comdevices = []
        comaddr = []
        for addr in serialAddresses:
            if addr in comAddresses:
                comaddr.append(addr)

        for addr in comaddr:
            device = Element("device", "deviceType")
            device["name"] = comAddresses[addr]
            device["shared"] = "true"
            ioport = Element("ioPort", "ioPortType")
            ioport["name"] = "ioport"
            ioport["start"] = util.toWord64(addr.start)
            ioport["end"] = util.toWord64(addr.end)
            device.appendChild(ioport)
            comdevices.append(device)

        return comdevices
Esempio n. 6
0
    def generateMemoryBlock(self, endfile, typefile, startfile):
        memoryBlock = Element("memoryBlock", "memoryBlockType")
        memoryBlock["name"] = extractor.extractData(typefile)
        memaddr = extractor.extractData(startfile)
        memoryBlock["physicalAddress"] = util.toWord64(memaddr)
        memsize = util.sizeOf(extractor.extractData(endfile),
                              extractor.extractData(startfile))
        # Round memsize down to multiple of PAGE_SIZE
        if int(memsize, 16) % int(PAGE_SIZE, 16) != 0:
            memrounded = util.hexRoundToMultiple(
                memsize, PAGE_SIZE, rounddown=True)
            print "Mem size %s for memoryBlock %s rounded down to: %s" % (
                memsize, memaddr, memrounded)
            memsize = memrounded
        memoryBlock["size"] = util.toWord64(memsize)

        if self.isAllocatable(memoryBlock):
            memoryBlock["allocatable"] = "true"
        else:
            memoryBlock["allocatable"] = "false"

        return memoryBlock
Esempio n. 7
0
    def createElem(self):
        print "> Creating element: devices"
        devices = Element("devices", "devicesType")
        devices["pciConfigAddress"] = util.toWord64(
            self.getPciConfigAddress(paths.IOMEM)
        )

        # Add IOMMUs
        print "> Extracting IOMMU device information..."
        devices.appendChild(IommuDevicesCreator().createElems(paths.DMAR,
                                                              paths.TEMP,
                                                              paths.DEVMEM))

        # Add Serial Devices
        print "> Extracting Serial device information..."
        devices.appendChild(SerialDevicesCreator().createElems(paths.IOPORTS))

        # Add Pci Devices
        print "> Extracting PCI device information..."
        devices.appendChild(PciDevicesCreator().createElems(paths.DEVICES))

        print "Element created: devices"

        return devices