Adding upstream version 4.00~pre54+dfsg.
[syslinux-debian/hramrach.git] / com32 / sysdump / pci.c
blob1d6872799631102c58a36a7848c0bf03707bb4dc
1 /*
2 * Dump PCI device headers
3 */
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8 #include <sys/pci.h>
9 #include "sysdump.h"
10 #include "backend.h"
12 static void dump_pci_device(struct backend *be, pciaddr_t a, uint8_t hdrtype)
14 unsigned int bus = pci_bus(a);
15 unsigned int dev = pci_dev(a);
16 unsigned int func = pci_func(a);
17 uint8_t data[256];
18 unsigned int i;
19 char filename[32];
21 hdrtype &= 0x7f;
23 printf("Scanning PCI bus... %02x:%02x.%x\r", bus, dev, func);
25 /* Assume doing a full device dump is actually safe... */
26 for (i = 0; i < sizeof data; i += 4)
27 *(uint32_t *)(data+i) = pci_readl(a + i);
29 snprintf(filename, sizeof filename, "pci/%02x:%02x.%x",
30 bus, dev, func);
31 cpio_writefile(be, filename, data, sizeof data);
34 void dump_pci(struct backend *be)
36 int cfgtype;
37 unsigned int nbus, ndev, nfunc, maxfunc;
38 pciaddr_t a;
39 uint32_t did;
40 uint8_t hdrtype;
42 cfgtype = pci_set_config_type(PCI_CFG_AUTO);
43 if (cfgtype == PCI_CFG_NONE)
44 return;
46 cpio_mkdir(be, "pci");
48 for (nbus = 0; nbus < MAX_PCI_BUSES; nbus++) {
49 for (ndev = 0; ndev < MAX_PCI_DEVICES; ndev++) {
50 maxfunc = 1; /* Assume a single-function device */
52 for (nfunc = 0; nfunc < maxfunc; nfunc++) {
53 a = pci_mkaddr(nbus, ndev, nfunc, 0);
54 did = pci_readl(a);
56 if (did == 0xffffffff || did == 0xffff0000 ||
57 did == 0x0000ffff || did == 0x00000000)
58 continue;
60 hdrtype = pci_readb(a + 0x0e);
61 if (hdrtype & 0x80)
62 maxfunc = MAX_PCI_FUNC; /* Multifunction device */
64 dump_pci_device(be, a, hdrtype);
69 printf("Scanning PCI bus... done. \n");