[syslinux:master] sysdump: add PCI config space dumping

syslinux-bot for H. Peter Anvin hpa at zytor.com
Sat Feb 6 23:12:02 PST 2010


Commit-ID:  eb87986dff065af4acbede5abbbcde5ee39eae19
Gitweb:     http://syslinux.zytor.com/commit/eb87986dff065af4acbede5abbbcde5ee39eae19
Author:     H. Peter Anvin <hpa at zytor.com>
AuthorDate: Sat, 6 Feb 2010 22:54:06 -0800
Committer:  H. Peter Anvin <hpa at zytor.com>
CommitDate: Sat, 6 Feb 2010 23:09:51 -0800

sysdump: add PCI config space dumping

Dump PCI configuration space.

Signed-off-by: H. Peter Anvin <hpa at zytor.com>


---
 com32/sysdump/dmi.c     |    1 -
 com32/sysdump/main.c    |    1 +
 com32/sysdump/pci.c     |   70 +++++++++++++++++++++++++++++++++++++++++++++++
 com32/sysdump/sysdump.h |    1 +
 4 files changed, 72 insertions(+), 1 deletions(-)

diff --git a/com32/sysdump/dmi.c b/com32/sysdump/dmi.c
index ad7c452..a64e5c1 100644
--- a/com32/sysdump/dmi.c
+++ b/com32/sysdump/dmi.c
@@ -5,7 +5,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <sys/cpu.h>
 #include "sysdump.h"
 #include "backend.h"
 
diff --git a/com32/sysdump/main.c b/com32/sysdump/main.c
index ffe3430..f6aea9c 100644
--- a/com32/sysdump/main.c
+++ b/com32/sysdump/main.c
@@ -37,6 +37,7 @@ static void dump_all(struct backend *be, const char *argv[], size_t len)
 
     dump_memory(be);
     dump_dmi(be);
+    dump_pci(be);
     dump_vesa_tables(be);
 
     cpio_close(be);
diff --git a/com32/sysdump/pci.c b/com32/sysdump/pci.c
new file mode 100644
index 0000000..debbbaf
--- /dev/null
+++ b/com32/sysdump/pci.c
@@ -0,0 +1,70 @@
+/*
+ * Dump PCI device headers
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/pci.h>
+#include "sysdump.h"
+#include "backend.h"
+
+static void dump_pci_device(struct backend *be, pciaddr_t a, uint8_t hdrtype)
+{
+    unsigned int bus  = pci_bus(a);
+    unsigned int dev  = pci_dev(a);
+    unsigned int func = pci_func(a);
+    uint8_t data[256];
+    unsigned int i;
+    char filename[32];
+
+    hdrtype &= 0x7f;
+
+    printf("Scanning PCI bus... %02x:%02x.%x\r", bus, dev, func);
+
+    /* Assume doing a full device dump is actually safe... */
+    for (i = 0; i < sizeof data; i += 4)
+	*(uint32_t *)(data+i) = pci_readl(a + i);
+
+    snprintf(filename, sizeof filename, "pci/%02x:%02x.%x",
+	     bus, dev, func);
+    cpio_writefile(be, filename, data, sizeof data);
+}
+
+void dump_pci(struct backend *be)
+{
+    int cfgtype;
+    unsigned int nbus, ndev, nfunc, maxfunc;
+    pciaddr_t a;
+    uint32_t did;
+    uint8_t hdrtype;
+
+    cfgtype = pci_set_config_type(PCI_CFG_AUTO);
+    if (cfgtype == PCI_CFG_NONE)
+	return;
+
+    cpio_mkdir(be, "pci");
+
+    for (nbus = 0; nbus < MAX_PCI_BUSES; nbus++) {
+	for (ndev = 0; ndev < MAX_PCI_DEVICES; ndev++) {
+	    maxfunc = 1;	/* Assume a single-function device */
+
+	    for (nfunc = 0; nfunc < maxfunc; nfunc++) {
+		a = pci_mkaddr(nbus, ndev, nfunc, 0);
+		did = pci_readl(a);
+
+		if (did == 0xffffffff || did == 0xffff0000 ||
+		    did == 0x0000ffff || did == 0x00000000)
+		    continue;
+
+		hdrtype = pci_readb(a + 0x0e);
+		if (hdrtype & 0x80)
+		    maxfunc = MAX_PCI_FUNC;	/* Multifunction device */
+
+		dump_pci_device(be, a, hdrtype);
+	    }
+	}
+    }
+
+    printf("Scanning PCI bus... done   \n");
+}
diff --git a/com32/sysdump/sysdump.h b/com32/sysdump/sysdump.h
index df9da31..4b58cf3 100644
--- a/com32/sysdump/sysdump.h
+++ b/com32/sysdump/sysdump.h
@@ -5,6 +5,7 @@ struct backend;
 
 void dump_memory(struct backend *);
 void dump_dmi(struct backend *);
+void dump_pci(struct backend *);
 void dump_vesa_tables(struct backend *);
 
 #endif /* SYSDUMP_H */



More information about the Syslinux-commits mailing list