Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src introduce a better pci_drvname() and PCI_IOC_DRVNAME as pcii...
details: https://anonhg.NetBSD.org/src/rev/68b869472381
branches: trunk
changeset: 347950:68b869472381
user: mrg <mrg%NetBSD.org@localhost>
date: Sat Sep 24 23:12:54 2016 +0000
description:
introduce a better pci_drvname() and PCI_IOC_DRVNAME as pciio_drvnameonbus()
and PCI_IOC_DRVNAMEONBUS. the new ones also take a (autoconf) PCI bus
number, which allows lookups for any device on any pci bus node. use this
in pcictl which current reports the wrong values sometimes.
up next: use these in libpciaccess.
diffstat:
distrib/sets/lists/base/shl.mi | 4 ++--
distrib/sets/lists/debug/shl.mi | 4 ++--
lib/libpci/pci.3 | 10 ++++++++--
lib/libpci/pci.h | 4 +++-
lib/libpci/pci_drvname.c | 28 ++++++++++++++++++++++++++--
lib/libpci/shlib_version | 4 ++--
sys/dev/pci/pci_usrreq.c | 28 ++++++++++++++++++++++++++--
sys/dev/pci/pciio.h | 13 ++++++++++---
usr.sbin/pcictl/pcictl.c | 5 +++--
9 files changed, 82 insertions(+), 18 deletions(-)
diffs (260 lines):
diff -r 280f4275099b -r 68b869472381 distrib/sets/lists/base/shl.mi
--- a/distrib/sets/lists/base/shl.mi Sat Sep 24 21:57:38 2016 +0000
+++ b/distrib/sets/lists/base/shl.mi Sat Sep 24 23:12:54 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.786 2016/09/24 20:13:48 christos Exp $
+# $NetBSD: shl.mi,v 1.787 2016/09/24 23:12:54 mrg Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@@ -432,7 +432,7 @@
./usr/lib/libpcap.so.5.1 base-net-shlib compatfile
./usr/lib/libpci.so base-sys-shlib compatfile
./usr/lib/libpci.so.2 base-sys-shlib compatfile
-./usr/lib/libpci.so.2.1 base-sys-shlib compatfile
+./usr/lib/libpci.so.2.2 base-sys-shlib compatfile
./usr/lib/libperfuse.so base-perfuse-shlib compatfile
./usr/lib/libperfuse.so.0 base-perfuse-shlib compatfile
./usr/lib/libperfuse.so.0.0 base-perfuse-shlib compatfile
diff -r 280f4275099b -r 68b869472381 distrib/sets/lists/debug/shl.mi
--- a/distrib/sets/lists/debug/shl.mi Sat Sep 24 21:57:38 2016 +0000
+++ b/distrib/sets/lists/debug/shl.mi Sat Sep 24 23:12:54 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.146 2016/09/24 20:13:48 christos Exp $
+# $NetBSD: shl.mi,v 1.147 2016/09/24 23:12:54 mrg Exp $
./usr/libdata/debug/lib base-sys-usr debug,dynamicroot,compatdir
./usr/libdata/debug/lib/libblacklist.so.0.0.debug comp-sys-debug debug,dynamicroot
./usr/libdata/debug/lib/libc.so.12.205.debug comp-sys-debug debug,dynamicroot
@@ -152,7 +152,7 @@
./usr/libdata/debug/usr/lib/libpam.so.4.0.debug comp-sys-debug debug,compatfile,pam
./usr/libdata/debug/usr/lib/libpanel.so.1.0.debug comp-sys-debug debug,compatfile
./usr/libdata/debug/usr/lib/libpcap.so.5.1.debug comp-net-debug debug,compatfile
-./usr/libdata/debug/usr/lib/libpci.so.2.1.debug comp-sys-debug debug,compatfile
+./usr/libdata/debug/usr/lib/libpci.so.2.2.debug comp-sys-debug debug,compatfile
./usr/libdata/debug/usr/lib/libperfuse.so.0.0.debug comp-perfuse-debug debug,compatfile
./usr/libdata/debug/usr/lib/libposix.so.0.1.debug comp-sys-debug debug,compatfile
./usr/libdata/debug/usr/lib/libppath.so.0.0.debug comp-sys-debug debug,compatfile
diff -r 280f4275099b -r 68b869472381 lib/libpci/pci.3
--- a/lib/libpci/pci.3 Sat Sep 24 21:57:38 2016 +0000
+++ b/lib/libpci/pci.3 Sat Sep 24 23:12:54 2016 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pci.3,v 1.12 2016/01/23 07:21:18 wiz Exp $
+.\" $NetBSD: pci.3,v 1.13 2016/09/24 23:12:54 mrg Exp $
.\"
.\" Copyright 2001 Wasabi Systems, Inc.
.\" All rights reserved.
@@ -33,7 +33,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd December 16, 2014
+.Dd September 23, 2016
.Dt PCI 3
.Os
.Sh NAME
@@ -61,6 +61,8 @@
.Fn pci_conf_print "int pcifd" "unsigned int bus" "unsigned int dev" "unsigned int func"
.Ft int
.Fn pci_drvname "int pcifd" "unsigned int dev" "unsigned int func" "char *drvname" "size_t len"
+.Ft int
+.Fn pci_drvnameonbus "int pcifd" "u_int bus" "u_int dev" "u_int func" "char *drvname" "size_t len"
.Sh DESCRIPTION
The
.Nm
@@ -151,6 +153,10 @@
using
.Fa len
as the buffer length.
+.It Fn pci_drvnameonbus
+Just like
+.Fn pci_drvname
+but also allows looking up via PCI bus number.
.El
.Sh RETURN VALUES
The
diff -r 280f4275099b -r 68b869472381 lib/libpci/pci.h
--- a/lib/libpci/pci.h Sat Sep 24 21:57:38 2016 +0000
+++ b/lib/libpci/pci.h Sat Sep 24 23:12:54 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci.h,v 1.8 2016/01/23 01:26:14 dholland Exp $ */
+/* $NetBSD: pci.h,v 1.9 2016/09/24 23:12:54 mrg Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -59,6 +59,8 @@
/* pci_drvname.c */
int pci_drvname(int, unsigned int, unsigned int, char *, size_t);
+int pci_drvnameonbus(int, unsigned int, unsigned int, unsigned int, char *,
+ size_t);
/* pci_subr.c */
void pci_devinfo(pcireg_t, pcireg_t, int, char *, size_t);
diff -r 280f4275099b -r 68b869472381 lib/libpci/pci_drvname.c
--- a/lib/libpci/pci_drvname.c Sat Sep 24 21:57:38 2016 +0000
+++ b/lib/libpci/pci_drvname.c Sat Sep 24 23:12:54 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_drvname.c,v 1.1 2014/07/25 01:38:26 mrg Exp $ */
+/* $NetBSD: pci_drvname.c,v 1.2 2016/09/24 23:12:54 mrg Exp $ */
/*
* Copyright (c) 2014 Matthew R. Green
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: pci_drvname.c,v 1.1 2014/07/25 01:38:26 mrg Exp $");
+__RCSID("$NetBSD: pci_drvname.c,v 1.2 2016/09/24 23:12:54 mrg Exp $");
#include <sys/types.h>
#include <sys/ioctl.h>
@@ -60,3 +60,27 @@
strlcpy(name, drvname.name, len);
return 0;
}
+
+/*
+ * pci_drvnameonbus:
+ *
+ * What's the driver name for a PCI device on any PCI bus?
+ */
+int
+pci_drvnameonbus(int fd, u_int bus, u_int device, u_int func, char *name,
+ size_t len)
+{
+ struct pciio_drvnameonbus drvname;
+ int rv;
+
+ drvname.bus = bus;
+ drvname.device = device;
+ drvname.function = func;
+
+ rv = ioctl(fd, PCI_IOC_DRVNAMEONBUS, &drvname);
+ if (rv == -1)
+ return -1;
+
+ strlcpy(name, drvname.name, len);
+ return 0;
+}
diff -r 280f4275099b -r 68b869472381 lib/libpci/shlib_version
--- a/lib/libpci/shlib_version Sat Sep 24 21:57:38 2016 +0000
+++ b/lib/libpci/shlib_version Sat Sep 24 23:12:54 2016 +0000
@@ -1,5 +1,5 @@
-# $NetBSD: shlib_version,v 1.4 2014/07/25 01:38:26 mrg Exp $
+# $NetBSD: shlib_version,v 1.5 2016/09/24 23:12:54 mrg Exp $
# Remember to update distrib/sets/lists/base/shl.* when changing
#
major=2
-minor=1
+minor=2
diff -r 280f4275099b -r 68b869472381 sys/dev/pci/pci_usrreq.c
--- a/sys/dev/pci/pci_usrreq.c Sat Sep 24 21:57:38 2016 +0000
+++ b/sys/dev/pci/pci_usrreq.c Sat Sep 24 23:12:54 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pci_usrreq.c,v 1.29 2015/08/24 23:55:04 pooka Exp $ */
+/* $NetBSD: pci_usrreq.c,v 1.30 2016/09/24 23:12:54 mrg Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_usrreq.c,v 1.29 2015/08/24 23:55:04 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_usrreq.c,v 1.30 2016/09/24 23:12:54 mrg Exp $");
#ifdef _KERNEL_OPT
#include "opt_pci.h"
@@ -80,6 +80,7 @@
struct pciio_bdf_cfgreg *bdfr;
struct pciio_businfo *binfo;
struct pciio_drvname *dname;
+ struct pciio_drvnameonbus *dnameonbus;
pcitag_t tag;
switch (cmd) {
@@ -120,6 +121,29 @@
sizeof dname->name);
return 0;
+ case PCI_IOC_DRVNAMEONBUS:
+ dnameonbus = data;
+ int i;
+
+ for (i = 0; i < pci_cd.cd_ndevs; i++) {
+ sc = device_lookup_private(&pci_cd, i);
+ if (sc->sc_bus == dnameonbus->bus)
+ break; /* found the right bus */
+ }
+ if (i == pci_cd.cd_ndevs || sc == NULL)
+ return ENXIO;
+ if (dnameonbus->device >= sc->sc_maxndevs ||
+ dnameonbus->function > 7)
+ return EINVAL;
+
+ child = &sc->PCI_SC_DEVICESC(dnameonbus->device,
+ dnameonbus->function);
+ if (!child->c_dev)
+ return ENXIO;
+ strlcpy(dnameonbus->name, device_xname(child->c_dev),
+ sizeof dnameonbus->name);
+ return 0;
+
default:
return ENOTTY;
}
diff -r 280f4275099b -r 68b869472381 sys/dev/pci/pciio.h
--- a/sys/dev/pci/pciio.h Sat Sep 24 21:57:38 2016 +0000
+++ b/sys/dev/pci/pciio.h Sat Sep 24 23:12:54 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pciio.h,v 1.4 2014/07/25 01:38:26 mrg Exp $ */
+/* $NetBSD: pciio.h,v 1.5 2016/09/24 23:12:54 mrg Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -97,17 +97,24 @@
* pciio_drvname:
*
* Driver info for a PCI device (autoconfiguration node) instance.
- * Must be run on the correct bus.
*/
+/* The old drvname must be run on the correct bus. */
#define PCI_IO_DRVNAME_LEN 16
struct pciio_drvname {
u_int device; /* in: device number */
u_int function; /* in: function number */
char name[PCI_IO_DRVNAME_LEN];
};
+#define PCI_IOC_DRVNAME _IOWR('P', 5, struct pciio_drvname)
-#define PCI_IOC_DRVNAME _IOWR('P', 5, struct pciio_drvname)
+struct pciio_drvnameonbus {
+ u_int bus; /* in: (autoconf) bus number */
+ u_int device; /* in: device number */
+ u_int function; /* in: function number */
+ char name[PCI_IO_DRVNAME_LEN];
+};
+#define PCI_IOC_DRVNAMEONBUS _IOWR('P', 5, struct pciio_drvnameonbus)
#endif /* _DEV_PCI_PCIIO_H_ */
diff -r 280f4275099b -r 68b869472381 usr.sbin/pcictl/pcictl.c
--- a/usr.sbin/pcictl/pcictl.c Sat Sep 24 21:57:38 2016 +0000
+++ b/usr.sbin/pcictl/pcictl.c Sat Sep 24 23:12:54 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pcictl.c,v 1.21 2014/09/01 07:11:19 manu Exp $ */
+/* $NetBSD: pcictl.c,v 1.22 2016/09/24 23:12:54 mrg Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -446,7 +446,8 @@
}
if (print_names) {
char drvname[16];
- if (pci_drvname(pcifd, dev, func, drvname, sizeof drvname) == 0)
+ if (pci_drvnameonbus(pcifd, bus, dev, func, drvname,
+ sizeof drvname) == 0)
printf(" [%s]", drvname);
}
printf("\n");
Home |
Main Index |
Thread Index |
Old Index