/*
* The PCI Utilities -- Common Functions
*
- * Copyright (c) 1997--2006 Martin Mares <mj@ucw.cz>
+ * Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
{
#ifdef PCI_HAVE_PM_LINUX_PROC
case 'P':
- pacc->method_params[PCI_ACCESS_PROC_BUS_PCI] = optarg;
+ pci_set_param(pacc, "proc.path", optarg);
pacc->method = PCI_ACCESS_PROC_BUS_PCI;
break;
#endif
#endif
#ifdef PCI_HAVE_PM_DUMP
case 'F':
- pacc->method_params[PCI_ACCESS_DUMP] = optarg;
+ pci_set_param(pacc, "dump.name", optarg);
pacc->method = PCI_ACCESS_DUMP;
break;
#endif
/* Method entries */
-static void
-aix_config(struct pci_access *a)
-{
- a->method_params[PCI_ACCESS_AIX_DEVICE] = NULL;
-}
-
static int
aix_detect(struct pci_access *a)
{
struct pci_methods pm_aix_device = {
"AIX-device",
- aix_config,
+ NULL,
aix_detect,
aix_init,
aix_cleanup,
/*
* The PCI Library -- Reading of Bus Dumps
*
- * Copyright (c) 1997--2005 Martin Mares <mj@ucw.cz>
+ * Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
byte data[1];
};
+static void
+dump_config(struct pci_access *a)
+{
+ pci_define_param(a, "dump.name", "", "Name of the bus dump file to read from");
+}
+
static int
dump_detect(struct pci_access *a)
{
- return !!a->method_params[PCI_ACCESS_DUMP];
+ char *name = pci_get_param(a, "dump.name");
+ return name && name[0];
}
static void
static void
dump_init(struct pci_access *a)
{
- char *name = a->method_params[PCI_ACCESS_DUMP];
+ char *name = pci_get_param(a, "dump.name");
FILE *f;
char buf[256];
struct pci_dev *dev = NULL;
struct pci_methods pm_dump = {
"dump",
- NULL, /* config */
+ dump_config,
dump_detect,
dump_init,
dump_cleanup,
static void
fbsd_config(struct pci_access *a)
{
- a->method_params[PCI_ACCESS_FBSD_DEVICE] = PCI_PATH_FBSD_DEVICE;
+ pci_define_param(a, "fbsd.path", PCI_PATH_FBSD_DEVICE, "Path to the FreeBSD PCI device");
}
static int
fbsd_detect(struct pci_access *a)
{
- char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
+ char *name = pci_get_param(a, "fbsd.path");
if (access(name, R_OK))
{
static void
fbsd_init(struct pci_access *a)
{
- char *name = a->method_params[PCI_ACCESS_FBSD_DEVICE];
+ char *name = pci_get_param(a, "fbsd.path");
a->fd = open(name, O_RDWR, 0);
if (a->fd < 0)
static void
nbsd_config(struct pci_access *a)
{
- a->method_params[PCI_ACCESS_NBSD_LIBPCI] = PCI_PATH_NBSD_DEVICE;
+ pci_define_param(a, "nbsd.path", PCI_PATH_NBSD_DEVICE, "Path to the NetBSD PCI device");
}
static int
nbsd_detect(struct pci_access *a)
{
- char *name = a->method_params[PCI_ACCESS_NBSD_LIBPCI];
+ char *name = pci_get_param(a, "nbsd.path");
if (access(name, R_OK))
{
static void
nbsd_init(struct pci_access *a)
{
- char *name = a->method_params[PCI_ACCESS_NBSD_LIBPCI];
+ char *name = pci_get_param(a, "nbsd.path");
int mode = a->writeable ? O_RDWR : O_RDONLY;
a->fd = open(name, mode, 0);
static void
obsd_config(struct pci_access *a)
{
- a->method_params[PCI_ACCESS_OBSD_DEVICE] = PCI_PATH_OBSD_DEVICE;
+ pci_define_param(a, "obsd.path", PCI_PATH_OBSD_DEVICE, "Path to the OpenBSD PCI device");
}
static int
obsd_detect(struct pci_access *a)
{
- char *name = a->method_params[PCI_ACCESS_OBSD_DEVICE];
+ char *name = pci_get_param(a, "obsd.path");
if (access(name, R_OK))
{
static void
obsd_init(struct pci_access *a)
{
- char *name = a->method_params[PCI_ACCESS_OBSD_DEVICE];
+ char *name = pci_get_param(a, "obsd.path");
a->fd = open(name, O_RDWR, 0);
if (a->fd < 0)
enum pci_access_type {
/* Known access methods, remember to update access.c as well */
- PCI_ACCESS_AUTO, /* Autodetection (params: none) */
- PCI_ACCESS_SYS_BUS_PCI, /* Linux /sys/bus/pci (params: path) */
- PCI_ACCESS_PROC_BUS_PCI, /* Linux /proc/bus/pci (params: path) */
- PCI_ACCESS_I386_TYPE1, /* i386 ports, type 1 (params: none) */
- PCI_ACCESS_I386_TYPE2, /* i386 ports, type 2 (params: none) */
- PCI_ACCESS_FBSD_DEVICE, /* FreeBSD /dev/pci (params: path) */
+ PCI_ACCESS_AUTO, /* Autodetection */
+ PCI_ACCESS_SYS_BUS_PCI, /* Linux /sys/bus/pci */
+ PCI_ACCESS_PROC_BUS_PCI, /* Linux /proc/bus/pci */
+ PCI_ACCESS_I386_TYPE1, /* i386 ports, type 1 */
+ PCI_ACCESS_I386_TYPE2, /* i386 ports, type 2 */
+ PCI_ACCESS_FBSD_DEVICE, /* FreeBSD /dev/pci */
PCI_ACCESS_AIX_DEVICE, /* /dev/pci0, /dev/bus0, etc. */
PCI_ACCESS_NBSD_LIBPCI, /* NetBSD libpci */
PCI_ACCESS_OBSD_DEVICE, /* OpenBSD /dev/pci */
- PCI_ACCESS_DUMP, /* Dump file (params: filename) */
+ PCI_ACCESS_DUMP, /* Dump file */
PCI_ACCESS_MAX
};
struct pci_access {
/* Options you can change: */
unsigned int method; /* Access method */
- char *method_params[PCI_ACCESS_MAX]; /* Parameters for the methods */
int writeable; /* Open in read/write mode */
int buscentric; /* Bus-centric view of the world */
static void
proc_config(struct pci_access *a)
{
- a->method_params[PCI_ACCESS_PROC_BUS_PCI] = PCI_PATH_PROC_BUS_PCI;
+ pci_define_param(a, "proc.path", PCI_PATH_PROC_BUS_PCI, "Path to the procfs bus tree");
}
static int
proc_detect(struct pci_access *a)
{
- char *name = a->method_params[PCI_ACCESS_PROC_BUS_PCI];
+ char *name = pci_get_param(a, "proc.path");
if (access(name, R_OK))
{
FILE *f;
char buf[512];
- if (snprintf(buf, sizeof(buf), "%s/devices", a->method_params[PCI_ACCESS_PROC_BUS_PCI]) == sizeof(buf))
+ if (snprintf(buf, sizeof(buf), "%s/devices", pci_get_param(a, "proc.path")) == sizeof(buf))
a->error("File name too long");
f = fopen(buf, "r");
if (!f)
if (a->fd >= 0)
close(a->fd);
e = snprintf(buf, sizeof(buf), "%s/%02x/%02x.%d",
- a->method_params[PCI_ACCESS_PROC_BUS_PCI],
+ pci_get_param(a, "proc.path"),
d->bus, d->dev, d->func);
if (e < 0 || e >= (int) sizeof(buf))
a->error("File name too long");
* The PCI Library -- Configuration Access via /sys/bus/pci
*
* Copyright (c) 2003 Matthew Wilcox <willy@fc.hp.com>
- * Copyright (c) 1997--2003 Martin Mares <mj@ucw.cz>
+ * Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
static void
sysfs_config(struct pci_access *a)
{
- a->method_params[PCI_ACCESS_SYS_BUS_PCI] = PCI_PATH_SYS_BUS_PCI;
+ pci_define_param(a, "sysfs.path", PCI_PATH_SYS_BUS_PCI, "Path to the sysfs device tree");
}
static inline char *
sysfs_name(struct pci_access *a)
{
- return a->method_params[PCI_ACCESS_SYS_BUS_PCI];
+ return pci_get_param(a, "sysfs.path");
}
static int
find_driver(struct device *d, char *buf)
{
struct pci_dev *dev = d->dev;
- char *base = dev->access->method_params[PCI_ACCESS_SYS_BUS_PCI];
- char name[1024], *drv;
+ char name[1024], *drv, *base;
int n;
if (dev->access->method != PCI_ACCESS_SYS_BUS_PCI)
return NULL;
+ base = pci_get_param(dev->access, "sysfs.path");
+ if (!base || !base[0])
+ return NULL;
+
n = snprintf(name, sizeof(name), "%s/devices/%04x:%02x:%02x.%d/driver",
base, dev->domain, dev->bus, dev->dev, dev->func);
if (n < 0 || n >= (int)sizeof(name))