2 * The PCI Library -- Reading of Bus Dumps
4 * Copyright (c) 1997--2005 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
22 dump_detect(struct pci_access *a)
24 return !!a->method_params[PCI_ACCESS_DUMP];
28 dump_alloc_data(struct pci_dev *dev, int len)
30 struct dump_data *dd = pci_malloc(dev->access, sizeof(struct dump_data) + len - 1);
33 memset(dd->data, 0xff, len);
38 dump_init(struct pci_access *a)
40 char *name = a->method_params[PCI_ACCESS_DUMP];
43 struct pci_dev *dev = NULL;
44 int len, mn, bn, dn, fn, i, j;
47 a->error("dump: File name not given.");
48 if (!(f = fopen(name, "r")))
49 a->error("dump: Cannot open %s: %s", name, strerror(errno));
50 while (fgets(buf, sizeof(buf)-1, f))
52 char *z = strchr(buf, '\n');
54 a->error("dump: line too long or unterminated");
56 if (z >= buf && *z == '\r')
60 if ((len >= 8 && buf[2] == ':' && buf[5] == '.' && buf[7] == ' ' &&
61 sscanf(buf, "%x:%x.%d ", &bn, &dn, &fn) == 3) ||
62 (len >= 13 && buf[4] == ':' && buf[7] == ':' && buf[10] == '.' && buf[12] == ' ' &&
63 sscanf(buf, "%x:%x:%x.%d", &mn, &bn, &dn, &fn) == 4))
65 dev = pci_get_dev(a, mn, bn, dn, fn);
66 dump_alloc_data(dev, 256);
72 (len >= 51 && buf[2] == ':' && buf[3] == ' ' || len >= 52 && buf[3] == ':' && buf[4] == ' ') &&
73 sscanf(buf, "%x: ", &i) == 1)
75 struct dump_data *dd = dev->aux;
77 while (isspace(z[0]) && isxdigit(z[1]) && isxdigit(z[2]))
80 if (sscanf(z, "%x", &j) != 1 || i >= 256)
81 a->error("dump: Malformed line");
84 if (i > dd->allocated) /* Need to re-allocate the buffer */
86 dump_alloc_data(dev, 4096);
87 memcpy(((struct dump_data *) dev->aux)->data, dd->data, 256);
101 dump_cleanup(struct pci_access *a UNUSED)
106 dump_scan(struct pci_access *a UNUSED)
111 dump_read(struct pci_dev *d, int pos, byte *buf, int len)
113 struct dump_data *dd;
116 struct pci_dev *e = d->access->devices;
117 while (e && (e->bus != d->bus || e->dev != d->dev || e->func != d->func))
123 if (pos + len > dd->len)
125 memcpy(buf, dd->data + pos, len);
130 dump_write(struct pci_dev *d UNUSED, int pos UNUSED, byte *buf UNUSED, int len UNUSED)
132 d->access->error("Writing to dump files is not supported.");
137 dump_cleanup_dev(struct pci_dev *d)
146 struct pci_methods pm_dump = {
153 pci_generic_fill_info,