2 * The PCI Library -- Reading of Bus Dumps
4 * Copyright (c) 1997--2003 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
17 dump_detect(struct pci_access *a)
19 return !!a->method_params[PCI_ACCESS_DUMP];
23 dump_init(struct pci_access *a)
25 char *name = a->method_params[PCI_ACCESS_DUMP];
28 struct pci_dev *dev = NULL;
29 int len, bn, dn, fn, i, j;
32 a->error("dump: File name not given.");
33 if (!(f = fopen(name, "r")))
34 a->error("dump: Cannot open %s: %s", name, strerror(errno));
35 while (fgets(buf, sizeof(buf)-1, f))
37 char *z = strchr(buf, '\n');
39 a->error("dump: line too long or unterminated");
41 if (z >= buf && *z == '\r')
44 if (len >= 8 && buf[2] == ':' && buf[5] == '.' && buf[7] == ' ' &&
45 sscanf(buf, "%x:%x.%d ", &bn, &dn, &fn) == 3)
47 dev = pci_get_dev(a, bn, dn, fn);
48 dev->aux = pci_malloc(a, 256);
49 memset(dev->aux, 0xff, 256);
54 else if (dev && len >= 51 && buf[2] == ':' && buf[3] == ' ' &&
55 sscanf(buf, "%x: ", &i) == 1)
58 while (isspace(z[0]) && isxdigit(z[1]) && isxdigit(z[2]))
61 if (sscanf(z, "%x", &j) != 1 || i >= 256)
62 a->error("dump: Malformed line");
63 ((byte *) dev->aux)[i++] = j;
71 dump_cleanup(struct pci_access *a UNUSED)
76 dump_scan(struct pci_access *a UNUSED)
81 dump_read(struct pci_dev *d, int pos, byte *buf, int len)
85 struct pci_dev *e = d->access->devices;
86 while (e && (e->bus != d->bus || e->dev != d->dev || e->func != d->func))
93 memcpy(buf, (byte *) d->aux + pos, len);
98 dump_write(struct pci_dev *d UNUSED, int pos UNUSED, byte *buf UNUSED, int len UNUSED)
100 d->access->error("Writing to dump files is not supported.");
105 dump_cleanup_dev(struct pci_dev *d)
114 struct pci_methods pm_dump = {
121 pci_generic_fill_info,