From cb6ee324dd157dc5dec68eab488e7c829e92e2a2 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 12 Feb 2008 09:54:36 +0100 Subject: [PATCH] Replaced the method_params array by library parameters. This change is backward incompatible, but hopefully nobody used this ill-thought interface. --- common.c | 6 +++--- lib/aix-device.c | 8 +------- lib/dump.c | 15 +++++++++++---- lib/fbsd-device.c | 6 +++--- lib/nbsd-libpci.c | 6 +++--- lib/obsd-device.c | 6 +++--- lib/pci.h | 15 +++++++-------- lib/proc.c | 8 ++++---- lib/sysfs.c | 6 +++--- lspci.c | 7 +++++-- 10 files changed, 43 insertions(+), 40 deletions(-) diff --git a/common.c b/common.c index 7e53157..ed439b4 100644 --- a/common.c +++ b/common.c @@ -1,7 +1,7 @@ /* * The PCI Utilities -- Common Functions * - * Copyright (c) 1997--2006 Martin Mares + * Copyright (c) 1997--2008 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -73,7 +73,7 @@ parse_generic_option(int i, struct pci_access *pacc, char *optarg) { #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 @@ -89,7 +89,7 @@ parse_generic_option(int i, struct pci_access *pacc, char *optarg) #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 diff --git a/lib/aix-device.c b/lib/aix-device.c index e02c98d..2febd79 100644 --- a/lib/aix-device.c +++ b/lib/aix-device.c @@ -122,12 +122,6 @@ aix_bus_number(char *name) /* 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) { @@ -266,7 +260,7 @@ aix_write(struct pci_dev *d, int pos, byte *buf, int len) struct pci_methods pm_aix_device = { "AIX-device", - aix_config, + NULL, aix_detect, aix_init, aix_cleanup, diff --git a/lib/dump.c b/lib/dump.c index 04837e6..9bf50af 100644 --- a/lib/dump.c +++ b/lib/dump.c @@ -1,7 +1,7 @@ /* * The PCI Library -- Reading of Bus Dumps * - * Copyright (c) 1997--2005 Martin Mares + * Copyright (c) 1997--2008 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -18,10 +18,17 @@ struct dump_data { 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 @@ -49,7 +56,7 @@ dump_validate(char *s, char *fmt) 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; @@ -157,7 +164,7 @@ dump_cleanup_dev(struct pci_dev *d) struct pci_methods pm_dump = { "dump", - NULL, /* config */ + dump_config, dump_detect, dump_init, dump_cleanup, diff --git a/lib/fbsd-device.c b/lib/fbsd-device.c index 875480d..3281906 100644 --- a/lib/fbsd-device.c +++ b/lib/fbsd-device.c @@ -33,13 +33,13 @@ 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)) { @@ -53,7 +53,7 @@ fbsd_detect(struct pci_access *a) 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) diff --git a/lib/nbsd-libpci.c b/lib/nbsd-libpci.c index 81600a0..7955570 100644 --- a/lib/nbsd-libpci.c +++ b/lib/nbsd-libpci.c @@ -25,13 +25,13 @@ 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)) { @@ -48,7 +48,7 @@ nbsd_detect(struct pci_access *a) 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); diff --git a/lib/obsd-device.c b/lib/obsd-device.c index 721f2f5..217e787 100644 --- a/lib/obsd-device.c +++ b/lib/obsd-device.c @@ -19,13 +19,13 @@ 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)) { @@ -39,7 +39,7 @@ obsd_detect(struct pci_access *a) 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) diff --git a/lib/pci.h b/lib/pci.h index 4d18385..ce42deb 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -23,23 +23,22 @@ struct pci_methods; 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 */ diff --git a/lib/proc.c b/lib/proc.c index f493e49..20f5790 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -21,13 +21,13 @@ 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)) { @@ -60,7 +60,7 @@ proc_scan(struct pci_access *a) 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) @@ -124,7 +124,7 @@ proc_setup(struct pci_dev *d, int rw) 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"); diff --git a/lib/sysfs.c b/lib/sysfs.c index a6cbd57..581bedb 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -2,7 +2,7 @@ * The PCI Library -- Configuration Access via /sys/bus/pci * * Copyright (c) 2003 Matthew Wilcox - * Copyright (c) 1997--2003 Martin Mares + * Copyright (c) 1997--2008 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -25,13 +25,13 @@ 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 diff --git a/lspci.c b/lspci.c index 5047559..7879f9b 100644 --- a/lspci.c +++ b/lspci.c @@ -1584,13 +1584,16 @@ static char * 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)) -- 2.39.2