xref: /netbsd-src/lib/libpci/pci.3 (revision f14316bcbc544b96a93e884bc5c2b15fd60e22ae)
1.\"	$NetBSD: pci.3,v 1.9 2014/07/25 10:21:34 wiz Exp $
2.\"
3.\" Copyright 2001 Wasabi Systems, Inc.
4.\" All rights reserved.
5.\"
6.\" Written by Jason R. Thorpe for Wasabi Systems, Inc.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\"    must display the following acknowledgement:
18.\"	This product includes software developed for the NetBSD Project by
19.\"	Wasabi Systems, Inc.
20.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse
21.\"    or promote products derived from this software without specific prior
22.\"    written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
28.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34.\" POSSIBILITY OF SUCH DAMAGE.
35.\"
36.Dd July 24, 2014
37.Dt PCI 3
38.Os
39.Sh NAME
40.Nm pci
41.Nd library interface for PCI bus access
42.Sh LIBRARY
43.Lb libpci
44.Sh SYNOPSIS
45.In pci.h
46.Ft int
47.Fn pcibus_conf_read "int pcifd" "u_int bus" "u_int dev" "u_int func" \
48"u_int reg" "pcireg_t *valp"
49.Ft int
50.Fn pcibus_conf_write "int pcifd" "u_int bus" "u_int dev" "u_int func" \
51"u_int reg" "pcireg_t val"
52.Ft int
53.Fn pcidev_conf_read "int devfd" "u_int reg" "pcireg_t *valp"
54.Ft int
55.Fn pcidev_conf_write "int devfd" "u_int reg" "pcireg_t val"
56.Ft char *
57.Fn pci_findvendor "pcireg_t id_reg"
58.Ft void
59.Fn pci_devinfo "pcireg_t id_reg" "pcireg_t class_reg" "char *devinfo" "size_t len"
60.Ft void
61.Fn pci_conf_print "int pcifd" "u_int bus" "u_int dev" "u_int func"
62.Ft int
63.Fn pci_drvname "int pcifd" "u_int dev" "u_int func" "char *drvname" "size_t len"
64.Sh DESCRIPTION
65The
66.Nm
67library provides support for accessing the PCI bus by user programs.
68.Pp
69These functions are available in the
70.Nm libpci
71library.
72Programs should be linked with
73.Fl lpci .
74.Sh CONFIGURATION SPACE FUNCTIONS
75The following functions are used to access PCI configuration space:
76.Bl -tag -width 4n
77.It Fn pcibus_conf_read
78Access the PCI configuration register
79.Fa reg
80on the device located at
81.Fa bus ,
82.Fa dev ,
83.Fa func ,
84and place the result in
85.Fa *valp .
86.Fa pcifd
87must be an open file descriptor to a PCI bus within the target PCI domain.
88.It Fn pcibus_conf_write
89Write the value specified by
90.Fa val
91into the PCI configuration register
92.Fa reg
93on the device located at
94.Fa bus ,
95.Fa dev ,
96.Fa func .
97.Fa pcifd
98must be an open file descriptor to a PCI bus within the target PCI domain.
99.It Fn pcidev_conf_read
100Access the PCI configuration register
101.Fa reg
102on the device associated with the open file descriptor
103.Fa devfd
104and place the result in
105.Fa *valp .
106.It Fn pcidev_conf_write
107Write the value specified by
108.Fa val
109into the PCI configuration register
110.Fa reg
111on the device associated with the open file descriptor
112.Fa devfd .
113.El
114.Sh MISCELLANEOUS FUNCTIONS
115The following miscellaneous functions are available:
116.Bl -tag -width 4n
117.It Fn pci_findvendor
118Return an ASCII description of the PCI vendor in the
119PCI ID register
120.Fa id_reg .
121.It Fn pci_devinfo
122Return an ASCII description of the PCI vendor, PCI product,
123and PCI class specified by the PCI ID register
124.Fa id_reg
125and PCI class ID register
126.Fa class_reg .
127The description is placed into the buffer pointed to by
128.Fa devinfo ;
129the size of that buffer is specified in
130.Fa len .
131.It Fn pci_conf_print
132Print the PCI configuration information for the device located
133at
134.Fa bus ,
135.Fa dev ,
136.Fa func .
137.Fa pcifd
138must be an open file descriptor to a PCI bus within the target PCI domain.
139.It Fn pci_drvname
140For the PCI bus opened on
141.Fa pcifd ,
142return the driver name for
143.Fa dev
144and
145.Fa func
146into
147.Fa drvname
148using
149.Fa len
150as the buffer length.
151.El
152.Sh RETURN VALUES
153The
154.Fn pcibus_conf_read ,
155.Fn pcibus_conf_write ,
156.Fn pcidev_conf_read ,
157.Fn pcidev_conf_write ,
158.Fn pci_devinfo ,
159and
160.Fn pci_drvname
161functions return 0 on success and \-1 on failure.
162.Pp
163The
164.Fn pci_findvendor
165function returns
166.Dv NULL
167if the PCI vendor description cannot be found.
168.Sh SEE ALSO
169.Xr pci 4
170.Sh HISTORY
171The
172.Fn pcibus_conf_read ,
173.Fn pcibus_conf_write ,
174.Fn pcidev_conf_read ,
175.Fn pcidev_conf_write ,
176.Fn pci_findvendor ,
177.Fn pci_devinfo ,
178and
179.Fn pci_conf_print
180functions first appeared in
181.Nx 1.6 .
182The
183.Fn pci_drvname
184function first appeared in
185.Nx 7.0 .
186