2
* $Id: dump.c,v 1.1 1999/01/22 21:05:20 mj Exp $
4
* The PCI Library -- Reading of Bus Dumps
6
* Copyright (c) 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
8
* Can be freely distributed and used under the terms of the GNU GPL.
19
dump_detect(struct pci_access *a)
21
return !!a->method_params[PCI_ACCESS_DUMP];
25
dump_init(struct pci_access *a)
27
char *name = a->method_params[PCI_ACCESS_DUMP];
30
struct pci_dev *dev = NULL;
31
int len, bn, dn, fn, i, j;
34
a->error("dump: File name not given.");
35
if (!(f = fopen(name, "r")))
36
a->error("dump: Cannot open %s: %s", name, strerror(errno));
37
while (fgets(buf, sizeof(buf)-1, f))
39
char *z = strchr(buf, '\n');
41
a->error("dump: line too long or unterminated");
43
if (z >= buf && *z == '\r')
46
if (len >= 8 && buf[2] == ':' && buf[5] == '.' && buf[7] == ' ' &&
47
sscanf(buf, "%x:%x.%d ", &bn, &dn, &fn) == 3)
49
dev = pci_get_dev(a, bn, dn, fn);
50
dev->aux = pci_malloc(a, 256);
51
memset(dev->aux, 0xff, 256);
56
else if (dev && len >= 51 && buf[2] == ':' && buf[3] == ' ' &&
57
sscanf(buf, "%x: ", &i) == 1)
60
while (isspace(z[0]) && isxdigit(z[1]) && isxdigit(z[2]))
63
if (sscanf(z, "%x", &j) != 1 || i >= 256)
64
a->error("dump: Malformed line");
65
((byte *) dev->aux)[i++] = j;
73
dump_cleanup(struct pci_access * UNUSED a)
78
dump_scan(struct pci_access * UNUSED a)
83
dump_read(struct pci_dev *d, int pos, byte *buf, int len)
87
struct pci_dev *e = d->access->devices;
88
while (e && (e->bus != d->bus || e->dev != d->dev || e->func != d->func))
95
memcpy(buf, (byte *) d->aux + pos, len);
100
dump_write(struct pci_dev * UNUSED d, int UNUSED pos, byte * UNUSED buf, int UNUSED len)
102
d->access->error("Writing to dump files is not supported.");
107
dump_cleanup_dev(struct pci_dev *d)
116
struct pci_methods pm_dump = {
123
pci_generic_fill_info,