#!/usr/bin/env python3 # fuses.py: READ-ONLY dump of the memory and PCIe fuse/strap registers of every CMP 170HX (10de:20c2) through BAR0. # Nothing is written. Needs root and iomem=relaxed if a driver is bound. Optional arguments: PCI bus numbers (hex), # e.g. "fuses.py 03 04"; with no arguments all 10de:20c2 cards are listed. import glob, mmap, os, sys R = {"DSOV":0x820084,"FBP_DIS":0x820364,"FBPA_DIS":0x820368,"FBIO_DIS":0x82036C,"ROPL2_DIS":0x8202C4,"FBP_DEF":0x8205CC, "FBP_ST":0x820D38,"LMR":0x100ce0, "GEN3_SPD_DIS":0x820250,"MAGIC_D":0x820520,"BOOT_GEN23_DIS":0x82057C,"BOOT_GEN3_DIS":0x820580} buses = sys.argv[1:] if not buses: for d in sorted(glob.glob("/sys/bus/pci/devices/0000:*:00.0")): try: if open(d + "/vendor").read().strip() == "0x10de" and open(d + "/device").read().strip() == "0x20c2": buses.append(os.path.basename(d)[5:7]) except OSError: pass for b in buses: fd = os.open(f"/sys/bus/pci/devices/0000:{b}:00.0/resource0", os.O_RDONLY | os.O_SYNC) m = mmap.mmap(fd, 0x824000, flags=mmap.MAP_SHARED, prot=mmap.PROT_READ) mv = memoryview(m).cast("I") v = {k: mv[a >> 2] for k, a in R.items()} nact = 12 - bin(v["FBP_DIS"] & 0xfff).count("1") print(b, f"FBP active {nact}/12", " ".join(f"{k}={x:#x}" for k, x in v.items())) mv.release(); m.close(); os.close(fd)