def devices_by_classcode(classcode): """Returns a list of dictionaries containg the bus, device and function for each PCI device with the specified classcode.""" return [dict(bus=bus, dev=dev, fun=fun) for bus in range(int(os.getenv("pcie_startbus", "0"), 0), int(os.getenv("pcie_endbus", "0xff"), 0) + 1) if bits.pci_read(bus, 0, 0, 0, bytes=4) != 0xffffffff for dev in range(2**5) for fun in range(2**3) if classcode == bits.pci_read(bus, dev, fun, 8, bytes=4) >> 8]
def devices_by_classcode(classcode): """Returns a list of dictionaries containg the bus, device and function for each PCI device with the specified classcode.""" return [ dict(bus=bus, dev=dev, fun=fun) for bus in range(int(os.getenv("pcie_startbus", "0"), 0), int(os.getenv("pcie_endbus", "0xff"), 0) + 1) if bits.pci_read(bus, 0, 0, 0, bytes=4) != 0xffffffff for dev in range(2**5) for fun in range(2**3) if classcode == bits.pci_read(bus, dev, fun, 8, bytes=4) >> 8 ]
def ppm_test2(): pciexbase = bits.pci_read(0, 5, 0, 0x84, 4) & 0xfc000000 bits.pcie_set_base(pciexbase) print 'pciexbase = 0x%x' % bits.pcie_get_base() for bus in (0x3f, 0x7f, 0xbf, 0xff): print 'bus 0x%x Interrupt Configuration Reg = 0x%x' % ( bus, bits.pcie_read(bus, 11, 0, 0x48, 4))
def ppm_test1(): pciexbase = bits.pci_read(0, 5, 0, 0x84, 4) & 0xfc000000 bits.pcie_set_base(pciexbase) print 'pciexbase = 0x%x' % bits.pcie_get_base() for bus in (0x3f, 0x7f, 0xbf, 0xff): print 'bus 0x%x devhide_0 = 0x%x' % ( bus, bits.pcie_read(bus, 11, 3, 0xb0, 4))
def do_ehci_handoff(bus, dev, fun, warntime=1, failtime=5, to_os=True): """Tell BIOS to hand off USB HC to or from OS; returns True if successful and all handoffs occurred in the specified timeout, or False otherwise.""" ret = True os_desired = int(to_os) bios_desired = int(not to_os) handoff_desc = "from BIOS to OS" if to_os else "from OS to BIOS" usbbase = bits.pci_read(bus, dev, fun, pci.BAR0, bytes=4) # Need a valid memory resource if (usbbase == 0) or (usbbase & 1): return None hccparams = bits.readl(usbbase + EHCI_HCCPARAMS) eecp = (hccparams >> 8) & 0xff count = MAX_HOST_CONTROLLERS = 64 while eecp and count: extcap = bits.pci_read(bus, dev, fun, eecp, bytes=4) if extcap & EHCI_EXTCAP_HANDOFF: starttime = time.time() bits.pci_write(bus, dev, fun, eecp + 3, os_desired, bytes=1) while True: bios_semaphore = bits.pci_read(bus, dev, fun, eecp + 2, bytes=1) duration = time.time() - starttime if bios_semaphore == bios_desired: break if duration > failtime: ret = False break if duration > failtime: print "FAIL: USB host controller at PCI {bus:#04x}:{dev:#04x}.{fun:#03x} offset {eecp:#x} failed to hand off {handoff_desc} within {failtime}s (took {duration:0.3f}s)".format( **locals()) elif duration > warntime: print "WARNING: USB host controller at PCI {bus:#04x}:{dev:#04x}.{fun:#03x} offset {eecp:#x} failed to hand off {handoff_desc} within {warntime}s (took {duration:0.3f}s)".format( **locals()) eecp = (extcap >> 8) & 0xff count -= 1 if eecp: print "Stopping at {} host controllers".format(MAX_HOST_CONTROLLERS) return ret
def do_ehci_handoff(bus, dev, fun, warntime=1, failtime=5, to_os=True): """Tell BIOS to hand off USB HC to or from OS; returns True if successful and all handoffs occurred in the specified timeout, or False otherwise.""" ret = True os_desired = int(to_os) bios_desired = int(not to_os) handoff_desc = "from BIOS to OS" if to_os else "from OS to BIOS" usbbase = bits.pci_read(bus, dev, fun, pci.BAR0, bytes=4) # Need a valid memory resource if (usbbase == 0) or (usbbase & 1): return None hccparams = bits.readl(usbbase + EHCI_HCCPARAMS); eecp = (hccparams >> 8) & 0xff; count = MAX_HOST_CONTROLLERS = 64 while eecp and count: extcap = bits.pci_read(bus, dev, fun, eecp, bytes=4) if extcap & EHCI_EXTCAP_HANDOFF: starttime = time.time() bits.pci_write(bus, dev, fun, eecp + 3, os_desired, bytes=1) while True: bios_semaphore = bits.pci_read(bus, dev, fun, eecp + 2, bytes=1) duration = time.time() - starttime if bios_semaphore == bios_desired: break if duration > failtime: ret = False break if duration > failtime: print "FAIL: USB host controller at PCI {bus:#04x}:{dev:#04x}.{fun:#03x} offset {eecp:#x} failed to hand off {handoff_desc} within {failtime}s (took {duration:0.3f}s)".format(**locals()) elif duration > warntime: print "WARNING: USB host controller at PCI {bus:#04x}:{dev:#04x}.{fun:#03x} offset {eecp:#x} failed to hand off {handoff_desc} within {warntime}s (took {duration:0.3f}s)".format(**locals()) eecp = (extcap >> 8) & 0xff; count -= 1 if eecp: print "Stopping at {} host controllers".format(MAX_HOST_CONTROLLERS) return ret
def ppm_test2(): pciexbase = bits.pci_read(0, 5, 0, 0x84, 4) & 0xfc000000 bits.pcie_set_base(pciexbase) print 'pciexbase = 0x%x' % bits.pcie_get_base() for bus in (0x3f, 0x7f, 0xbf, 0xff): print 'bus 0x%x Interrupt Configuration Reg = 0x%x' % (bus, bits.pcie_read(bus, 11, 0, 0x48, 4))
def ppm_test1(): pciexbase = bits.pci_read(0, 5, 0, 0x84, 4) & 0xfc000000 bits.pcie_set_base(pciexbase) print 'pciexbase = 0x%x' % bits.pcie_get_base() for bus in (0x3f, 0x7f, 0xbf, 0xff): print 'bus 0x%x devhide_0 = 0x%x' % (bus, bits.pcie_read(bus, 11, 3, 0xb0, 4))