Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libpci Add a library to access PCI devices.
details: https://anonhg.NetBSD.org/src/rev/befd7f2417a4
branches: trunk
changeset: 514919:befd7f2417a4
user: thorpej <thorpej%NetBSD.org@localhost>
date: Thu Sep 13 22:52:19 2001 +0000
description:
Add a library to access PCI devices.
diffstat:
lib/libpci/Makefile | 24 ++++++
lib/libpci/pci.3 | 163 +++++++++++++++++++++++++++++++++++++++++++++++
lib/libpci/pci.h | 60 +++++++++++++++++
lib/libpci/pci_bus.c | 94 +++++++++++++++++++++++++++
lib/libpci/pci_device.c | 86 ++++++++++++++++++++++++
lib/libpci/shlib_version | 5 +
6 files changed, 432 insertions(+), 0 deletions(-)
diffs (truncated from 456 to 300 lines):
diff -r 6a0a61eb5067 -r befd7f2417a4 lib/libpci/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpci/Makefile Thu Sep 13 22:52:19 2001 +0000
@@ -0,0 +1,24 @@
+# $NetBSD: Makefile,v 1.1 2001/09/13 22:52:19 thorpej Exp $
+
+LIB= pci
+
+SRCS= pci_bus.c pci_device.c pci_subr.c
+
+CPPFLAGS+=-DPCIVERBOSE
+
+.PATH.c: ${.CURDIR}/../../sys/dev/pci
+
+MAN= pci.3
+
+MLINKS= pci.3 pcibus_conf_read.3 \
+ pci.3 pcibus_conf_write.3 \
+ pci.3 pcidev_conf_read.3 \
+ pci.3 pcidev_conf_write.3 \
+ pci.3 pci_findvendor.3 \
+ pci.3 pci_devinfo.3 \
+ pci.3 pci_conf_print.3
+
+INCSDIR= /usr/include
+INCS= pci.h
+
+.include <bsd.lib.mk>
diff -r 6a0a61eb5067 -r befd7f2417a4 lib/libpci/pci.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpci/pci.3 Thu Sep 13 22:52:19 2001 +0000
@@ -0,0 +1,163 @@
+.\" $NetBSD: pci.3,v 1.1 2001/09/13 22:52:20 thorpej Exp $
+.\"
+.\" Copyright 2001 Wasabi Systems, Inc.
+.\" All rights reserved.
+.\"
+.\" Written by Jason R. Thorpe for Wasabi Systems, Inc.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed for the NetBSD Project by
+.\" Wasabi Systems, Inc.
+.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse
+.\" or promote products derived from this software without specific prior
+.\" written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd September 12, 2001
+.Os
+.Dt PCI 3
+.Sh NAME
+.Nm pci
+.Nd library interface for PCI bus access
+.Sh LIBRARY
+.Lb libpci
+.Sh SYNOPSIS
+.Fd #include <pci.h>
+.Ft int
+.Fn pcibus_conf_read "int pcifd" "u_int bus" "u_int dev" "u_int func" \
+"u_int reg" "pcireg_t *valp"
+.Ft int
+.Fn pcibus_conf_write "int pcifd" "u_int bus" "u_int dev" "u_int func" \
+"u_int reg" "pcireg_t val"
+.Ft int
+.Fn pcidev_conf_read "int devfd" "u_int reg" "pcireg_t *valp"
+.Ft int
+.Fn pcidev_conf_write "int devfd" "u_int reg" "pcireg_t val"
+.Ft char *
+.Fn pci_findvendor "pcireg_t id_reg"
+.Ft void
+.Fn pci_devinfo "pcireg_t id_reg" "pcireg_t class_reg" "char *devinfo"
+.Ft void
+.Fn pci_conf_print "int pcifd" "u_int bus" "u_int dev" "u_int func"
+.Sh DESCRIPTION
+The
+.Nm
+library provides support for accessing the PCI bus by user programs.
+.Pp
+These functions are available in the
+.Nm libpci
+library.
+Programs should be linked with
+.Fl lpci .
+.Sh CONFIGURATION SPACE FUNCTIONS
+The following functions are used to access PCI configuration space:
+.Bl -tag -width 4n
+.It Fn pcibus_conf_read
+Access the PCI configuration register
+.Fa reg
+on the device located at
+.Fa bus ,
+.Fa dev ,
+.Fa func ,
+and place the result in
+.Fa *valp .
+.Fa pcifd
+must be an open file descriptor to a PCI bus within the target PCI domain.
+.It Fn pcibus_conf_write
+Write the value specified by
+.Fa val
+into the PCI configuration register
+.Fa rag
+on the device located at
+.Fa bus ,
+.Fa dev ,
+.Fa func .
+.Fa pcifd
+must be an open file descriptor to a PCI bus within the target PCI domain.
+.It Fn pcidev_conf_read
+Access the PCI configuration register
+.Fa reg
+on the device associated with the open file descriptor
+.Fa devfd
+and place the result in
+.Fa *valp .
+.It Fn pcidev_conf_write
+Write the value specified by
+.Fa val
+into the PCI configuration register
+.Fa reg
+on the device associated with the open file descriptor
+.Fa devfd .
+.El
+.Sh MISCELLNAEOUS FUNCTIONS
+The following miscellaneous functions are available:
+.Bl -tag -width 4n
+.It Fn pci_findvendor
+Return an ASCII description of the PCI vendor in the
+PCI ID register
+.Fa id_reg .
+.It Fn pci_devinfo
+Return an ASCII description of the PCI vendor, PCI product,
+and PCI class specified by the PCI ID register
+.Fa id_reg
+and PCI class ID register
+.Fa class_reg .
+The description is placed into the buffer pointed to by
+.Fa devinfo .
+The buffer should be at least 256 bytes long.
+.It Fn pci_conf_print
+Print the PCI configuration information for the device located
+at
+.Fa bus ,
+.Fa dev ,
+.Fa func .
+.Fa pcifd
+must be an open file descriptor to a PCI bus within the target PCI domain.
+.El
+.Sh RETURN VALUES
+The
+.Fn pcibus_conf_read ,
+.Fn pcibus_conf_write ,
+.Fn pcidev_conf_read ,
+and
+.Fn pcidev_conf_write
+functions return 0 on success and -1 on failure.
+.Pp
+The
+.Fn pci_findvendor
+function returns NULL if the PCI vendor description cannot be
+found.
+.Sh SEE ALSO
+.Xr pci 4
+.Sh HISTORY
+The
+.Fn pcibus_conf_read ,
+.Fn pcibus_conf_write ,
+.Fn pcidev_conf_read ,
+.Fn pcidev_conf_write ,
+.Fn pci_findvendor ,
+.Fn pci_devinfo ,
+and
+.Fn pci_conf_print
+functions first appeared in
+.Nx 1.6 .
diff -r 6a0a61eb5067 -r befd7f2417a4 lib/libpci/pci.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpci/pci.h Thu Sep 13 22:52:19 2001 +0000
@@ -0,0 +1,60 @@
+/* $NetBSD: pci.h,v 1.1 2001/09/13 22:52:20 thorpej Exp $ */
+
+/*
+ * Copyright 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _PCI_H_
+#define _PCI_H_
+
+/*
+ * Interface to the PCI bus for user programs.
+ */
+
+typedef uint32_t pcireg_t; /* XXX */
+
+/* pci_bus.c */
+int pcibus_conf_read(int, u_int, u_int, u_int, u_int, pcireg_t *);
+int pcibus_conf_write(int, u_int, u_int, u_int, u_int, pcireg_t);
+
+/* pci_device.c */
+int pcidev_conf_read(int, u_int, pcireg_t *);
+int pcidev_conf_write(int, u_int, pcireg_t);
+
+/* pci_subr.c */
+char *pci_findvendor(pcireg_t);
+void pci_devinfo(pcireg_t, pcireg_t, int, char *);
+void pci_conf_print(int, u_int, u_int, u_int);
+
+#endif /* _PCI_H_ */
diff -r 6a0a61eb5067 -r befd7f2417a4 lib/libpci/pci_bus.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libpci/pci_bus.c Thu Sep 13 22:52:19 2001 +0000
@@ -0,0 +1,94 @@
+/* $NetBSD: pci_bus.c,v 1.1 2001/09/13 22:52:20 thorpej Exp $ */
+
+/*
+ * Copyright 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Jason R. Thorpe for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
Home |
Main Index |
Thread Index |
Old Index