2 * The PCI Utilities -- Bus Mapping Mode
4 * Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
16 struct bus_bridge *next;
17 byte this, dev, func, first, last, bug;
23 struct bus_bridge *bridges, *via;
26 static struct bus_info *bus_info;
29 map_bridge(struct bus_info *bi, struct device *d, int np, int ns, int nl)
31 struct bus_bridge *b = xmalloc(sizeof(struct bus_bridge));
32 struct pci_dev *p = d->dev;
34 b->next = bi->bridges;
36 b->this = get_conf_byte(d, np);
39 b->first = get_conf_byte(d, ns);
40 b->last = get_conf_byte(d, nl);
41 printf("## %02x:%02x.%d is a bridge from %02x to %02x-%02x\n",
42 p->bus, p->dev, p->func, b->this, b->first, b->last);
43 if (b->this != p->bus)
44 printf("!!! Bridge points to invalid primary bus.\n");
45 if (b->first > b->last)
47 printf("!!! Bridge points to invalid bus range.\n");
55 int domain = (filter.domain >= 0 ? filter.domain : 0);
57 int verbose = pacc->debugging;
58 struct bus_info *bi = bus_info + bus;
62 printf("Mapping bus %04x:%02x\n", domain, bus);
63 for (dev = 0; dev < 32; dev++)
64 if (filter.slot < 0 || filter.slot == dev)
67 for (func = 0; func < func_limit; func++)
68 if (filter.func < 0 || filter.func == func)
70 struct pci_dev *p = pci_get_dev(pacc, domain, bus, dev, func);
71 u16 vendor = pci_read_word(p, PCI_VENDOR_ID);
72 if (vendor && vendor != 0xffff)
74 if (!func && (pci_read_byte(p, PCI_HEADER_TYPE) & 0x80))
77 printf("Discovered device %04x:%02x:%02x.%d\n", domain, bus, dev, func);
79 if (d = scan_device(p))
82 switch (get_conf_byte(d, PCI_HEADER_TYPE) & 0x7f)
84 case PCI_HEADER_TYPE_BRIDGE:
85 map_bridge(bi, d, PCI_PRIMARY_BUS, PCI_SECONDARY_BUS, PCI_SUBORDINATE_BUS);
87 case PCI_HEADER_TYPE_CARDBUS:
88 map_bridge(bi, d, PCI_CB_PRIMARY_BUS, PCI_CB_CARD_BUS, PCI_CB_SUBORDINATE_BUS);
94 printf("But it was filtered out.\n");
102 do_map_bridges(int bus, int min, int max)
104 struct bus_info *bi = bus_info + bus;
105 struct bus_bridge *b;
108 for (b=bi->bridges; b; b=b->next)
110 if (bus_info[b->first].guestbook)
112 else if (b->first < min || b->last > max)
116 bus_info[b->first].via = b;
117 do_map_bridges(b->first, b->first, b->last);
127 printf("\nSummary of buses:\n\n");
128 for (i=0; i<256; i++)
129 if (bus_info[i].exists && !bus_info[i].guestbook)
130 do_map_bridges(i, 0, 255);
131 for (i=0; i<256; i++)
133 struct bus_info *bi = bus_info + i;
134 struct bus_bridge *b = bi->via;
140 printf("Entered via %02x:%02x.%d\n", b->this, b->dev, b->func);
142 printf("Primary host bus\n");
144 printf("Secondary host bus (?)\n");
146 for (b=bi->bridges; b; b=b->next)
148 printf("\t%02x.%d Bridge to %02x-%02x", b->dev, b->func, b->first, b->last);
152 printf(" <overlap bug>");
155 printf(" <crossing bug>");
166 if (pacc->method == PCI_ACCESS_PROC_BUS_PCI ||
167 pacc->method == PCI_ACCESS_SYS_BUS_PCI ||
168 pacc->method == PCI_ACCESS_WIN32_CFGMGR32 ||
169 pacc->method == PCI_ACCESS_DUMP)
170 printf("WARNING: Bus mapping can be reliable only with direct hardware access enabled.\n\n");
171 bus_info = xmalloc(sizeof(struct bus_info) * 256);
172 memset(bus_info, 0, sizeof(struct bus_info) * 256);
174 do_map_bus(filter.bus);
178 for (bus=0; bus<256; bus++)