xref: /freebsd/share/man/man9/pci.9 (revision 55aaf894e8a76fe780757ef6d9d1119c367946cf)
1aac0aafaSHiten Pandya.\"
2bf1639eeSBruce M Simpson.\" Copyright (c) 2005 Bruce M Simpson <bms@FreeBSD.org>
3aac0aafaSHiten Pandya.\" All rights reserved.
4aac0aafaSHiten Pandya.\"
5aac0aafaSHiten Pandya.\" Redistribution and use in source and binary forms, with or without
6aac0aafaSHiten Pandya.\" modification, are permitted provided that the following conditions
7aac0aafaSHiten Pandya.\" are met:
8aac0aafaSHiten Pandya.\" 1. Redistributions of source code must retain the above copyright
9aac0aafaSHiten Pandya.\"    notice, this list of conditions and the following disclaimer.
10aac0aafaSHiten Pandya.\" 2. Redistributions in binary form must reproduce the above copyright
11aac0aafaSHiten Pandya.\"    notice, this list of conditions and the following disclaimer in the
12aac0aafaSHiten Pandya.\"    documentation and/or other materials provided with the distribution.
13aac0aafaSHiten Pandya.\"
14aac0aafaSHiten Pandya.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15aac0aafaSHiten Pandya.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16aac0aafaSHiten Pandya.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17aac0aafaSHiten Pandya.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18aac0aafaSHiten Pandya.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19aac0aafaSHiten Pandya.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20aac0aafaSHiten Pandya.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21aac0aafaSHiten Pandya.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22aac0aafaSHiten Pandya.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23aac0aafaSHiten Pandya.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24aac0aafaSHiten Pandya.\" SUCH DAMAGE.
25aac0aafaSHiten Pandya.\"
26aac0aafaSHiten Pandya.\" $FreeBSD$
27aac0aafaSHiten Pandya.\"
2855aaf894SMarius Strobl.Dd September 30, 2007
29aac0aafaSHiten Pandya.Dt PCI 9
30aac0aafaSHiten Pandya.Os
31aac0aafaSHiten Pandya.Sh NAME
32aac0aafaSHiten Pandya.Nm pci ,
33aac0aafaSHiten Pandya.Nm pci_read_config ,
34aac0aafaSHiten Pandya.Nm pci_write_config ,
35aac0aafaSHiten Pandya.Nm pci_enable_busmaster ,
36aac0aafaSHiten Pandya.Nm pci_disable_busmaster ,
37aac0aafaSHiten Pandya.Nm pci_enable_io ,
38aac0aafaSHiten Pandya.Nm pci_disable_io ,
39aac0aafaSHiten Pandya.Nm pci_set_powerstate ,
40aac0aafaSHiten Pandya.Nm pci_get_powerstate ,
41aac0aafaSHiten Pandya.Nm pci_find_bsf ,
4255aaf894SMarius Strobl.Nm pci_find_dbsf ,
43aac0aafaSHiten Pandya.Nm pci_find_device
44aac0aafaSHiten Pandya.Nd PCI bus interface
45aac0aafaSHiten Pandya.Sh SYNOPSIS
46aac0aafaSHiten Pandya.In sys/bus.h
47aac0aafaSHiten Pandya.In dev/pci/pcivar.h
48aac0aafaSHiten Pandya.In dev/pci/pcireg.h
49aac0aafaSHiten Pandya.In machine/pci_cfgreg.h
50aac0aafaSHiten Pandya.Ft void
5165bb31b8SRuslan Ermilov.Fn pci_write_config "device_t dev" "int reg" "uint32_t val" "int width"
52aac0aafaSHiten Pandya.Ft int
53aac0aafaSHiten Pandya.Fn pci_enable_busmaster "device_t dev"
54aac0aafaSHiten Pandya.Ft int
55aac0aafaSHiten Pandya.Fn pci_disable_busmaster "device_t dev"
56aac0aafaSHiten Pandya.Ft int
57aac0aafaSHiten Pandya.Fn pci_enable_io "device_t dev" "int space"
58aac0aafaSHiten Pandya.Ft int
59aac0aafaSHiten Pandya.Fn pci_disable_io "device_t dev" "int space"
60aac0aafaSHiten Pandya.Ft int
61aac0aafaSHiten Pandya.Fn pci_set_powerstate "device_t dev" "int state"
62aac0aafaSHiten Pandya.Ft int
63aac0aafaSHiten Pandya.Fn pci_get_powerstate "device_t dev"
6465bb31b8SRuslan Ermilov.Ft uint32_t
65aac0aafaSHiten Pandya.Fn pci_read_config "device_t dev" "int reg" "int width"
66aac0aafaSHiten Pandya.Ft device_t
6765bb31b8SRuslan Ermilov.Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func"
68aac0aafaSHiten Pandya.Ft device_t
6955aaf894SMarius Strobl.Fn pci_find_dbsf "uint32_t domain" "uint8_t bus" "uint8_t slot" "uint8_t func"
7055aaf894SMarius Strobl.Ft device_t
7165bb31b8SRuslan Ermilov.Fn pci_find_device "uint16_t vendor" "uint16_t device"
72aac0aafaSHiten Pandya.Sh DESCRIPTION
73aac0aafaSHiten PandyaThe
74aac0aafaSHiten Pandya.Nm
75aac0aafaSHiten Pandyaset of functions are used for managing PCI devices.
76aac0aafaSHiten Pandya.Pp
77aac0aafaSHiten PandyaThe
78aac0aafaSHiten Pandya.Fn pci_read_config
79aac0aafaSHiten Pandyafunction is used to read data from the PCI configuration
80aac0aafaSHiten Pandyaspace of the device
81aac0aafaSHiten Pandya.Fa dev ,
82aac0aafaSHiten Pandyaat offset
83aac0aafaSHiten Pandya.Fa reg ,
84aac0aafaSHiten Pandyawith
85aac0aafaSHiten Pandya.Fa width
86aac0aafaSHiten Pandyaspecifying the size of the access.
87aac0aafaSHiten Pandya.Pp
88aac0aafaSHiten PandyaThe
89aac0aafaSHiten Pandya.Fn pci_write_config
90aac0aafaSHiten Pandyafunction is used to write the value
91aac0aafaSHiten Pandya.Fa val
92aac0aafaSHiten Pandyato the PCI configuration
93aac0aafaSHiten Pandyaspace of the device
94aac0aafaSHiten Pandya.Fa dev ,
95aac0aafaSHiten Pandyaat offset
96aac0aafaSHiten Pandya.Fa reg ,
97aac0aafaSHiten Pandyawith
98aac0aafaSHiten Pandya.Fa width
99aac0aafaSHiten Pandyaspecifying the size of the access.
100aac0aafaSHiten Pandya.Pp
101aac0aafaSHiten PandyaThe
102aac0aafaSHiten Pandya.Fn pci_enable_busmaster
103aac0aafaSHiten Pandyafunction enables PCI bus mastering for the device
104aac0aafaSHiten Pandya.Fa dev ,
105aac0aafaSHiten Pandyaby setting the
106aac0aafaSHiten Pandya.Dv PCIM_CMD_BUSMASTEREN
107aac0aafaSHiten Pandyabit in the
108aac0aafaSHiten Pandya.Dv PCIR_COMMAND
109aac0aafaSHiten Pandyaregister.
110aac0aafaSHiten PandyaThe
111aac0aafaSHiten Pandya.Fn pci_disable_busmaster
112aac0aafaSHiten Pandyafunction clears this bit.
113aac0aafaSHiten Pandya.Pp
114aac0aafaSHiten PandyaThe
115aac0aafaSHiten Pandya.Fn pci_enable_io
116aac0aafaSHiten Pandyafunction enables memory or I/O port address decoding for the device
117aac0aafaSHiten Pandya.Fa dev ,
118aac0aafaSHiten Pandyaby setting the
119aac0aafaSHiten Pandya.Dv PCIM_CMD_MEMEN
120aac0aafaSHiten Pandyaor
121aac0aafaSHiten Pandya.Dv PCIM_CMD_PORTEN
122aac0aafaSHiten Pandyabit in the
123aac0aafaSHiten Pandya.Dv PCIR_COMMAND
1245203edcdSRuslan Ermilovregister appropriately.
1255203edcdSRuslan ErmilovThe
126aac0aafaSHiten Pandya.Fn pci_disable_io
127aac0aafaSHiten Pandyafunction clears the appropriate bit.
128aac0aafaSHiten PandyaThe
12965bb31b8SRuslan Ermilov.Fa space
130aac0aafaSHiten Pandyaargument specifies which resource is affected; this can be either
131aac0aafaSHiten Pandya.Dv SYS_RES_MEMORY
132aac0aafaSHiten Pandyaor
133aac0aafaSHiten Pandya.Dv SYS_RES_IOPORT
134aac0aafaSHiten Pandyaas appropriate.
135aac0aafaSHiten Pandya.Pp
136aac0aafaSHiten Pandya.Em NOTE :
137aac0aafaSHiten PandyaThese functions should be used in preference to manually manipulating
138aac0aafaSHiten Pandyathe configuration space.
139aac0aafaSHiten Pandya.Pp
140aac0aafaSHiten PandyaThe
141aac0aafaSHiten Pandya.Fn pci_get_powerstate
142aac0aafaSHiten Pandyafunction returns the current ACPI power state of the device
143aac0aafaSHiten Pandya.Fa dev .
144aac0aafaSHiten PandyaIf the device does not support power management capabilities, then the default
145aac0aafaSHiten Pandyastate of
146aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D0
147aac0aafaSHiten Pandyais returned.
148aac0aafaSHiten PandyaThe following power states are defined by ACPI:
14965bb31b8SRuslan Ermilov.Bl -hang -width ".Dv PCI_POWERSTATE_UNKNOWN"
150aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D0
151aac0aafaSHiten PandyaState in which device is on and running.
152aac0aafaSHiten PandyaIt is receiving full power from the system and delivering
153aac0aafaSHiten Pandyafull functionality to the user.
154aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D1
155aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
156aac0aafaSHiten Pandyamay not be lot.
15765bb31b8SRuslan ErmilovBusses in this state cannot do anything to the bus, to
1589817b894SBruce M Simpsonforce devices to lose context.
159aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D2
160aac0aafaSHiten PandyaClass-specific low-power state in which device context may or
161aac0aafaSHiten Pandyamay not be lost.
162aac0aafaSHiten PandyaAttains greater power savings than
163aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D1 .
16465bb31b8SRuslan ErmilovBusses in this state can cause devices to lose some context.
165aac0aafaSHiten PandyaDevices
166aac0aafaSHiten Pandya.Em must
167aac0aafaSHiten Pandyabe prepared for the bus to be in this state or higher.
168aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D3
169aac0aafaSHiten PandyaState in which the device is off and not running.
170aac0aafaSHiten PandyaDevice context is lost, and power from the device can
171aac0aafaSHiten Pandyabe removed.
172aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_UNKNOWN
173aac0aafaSHiten PandyaState of the device is unknown.
174aac0aafaSHiten Pandya.El
175aac0aafaSHiten Pandya.Pp
176aac0aafaSHiten PandyaThe
177aac0aafaSHiten Pandya.Fn pci_set_powerstate
178aac0aafaSHiten Pandyafunction is used to transition the device
179aac0aafaSHiten Pandya.Fa dev
180aac0aafaSHiten Pandyato the ACPI power state
181aac0aafaSHiten Pandya.Fa state .
182aac0aafaSHiten PandyaIt checks to see if the device is PCI 2.2 compliant.
183aac0aafaSHiten PandyaIf so, it checks the
184aac0aafaSHiten Pandyacapabilities pointer to determine which power states the device supports.
185aac0aafaSHiten PandyaIf the device does not have power management capabilities, the default state
186aac0aafaSHiten Pandyaof
187aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D0
188aac0aafaSHiten Pandyais set.
189aac0aafaSHiten Pandya.Pp
190aac0aafaSHiten PandyaThe
191aac0aafaSHiten Pandya.Fn pci_find_bsf
192aac0aafaSHiten Pandyafunction looks up the
193aac0aafaSHiten Pandya.Vt device_t
194aac0aafaSHiten Pandyaof a PCI device, given its
195aac0aafaSHiten Pandya.Fa bus ,
196aac0aafaSHiten Pandya.Fa slot ,
197aac0aafaSHiten Pandyaand
19865bb31b8SRuslan Ermilov.Fa func .
199bf1639eeSBruce M SimpsonThe
200bf1639eeSBruce M Simpson.Fa slot
201bf1639eeSBruce M Simpsonnumber actually refers to the number of the device on the bus,
202bf1639eeSBruce M Simpsonwhich does not necessarily indicate its geographic location
203bf1639eeSBruce M Simpsonin terms of a physical slot.
20455aaf894SMarius StroblNote that in case the system has multiple PCI domains,
20555aaf894SMarius Stroblthe
20655aaf894SMarius Strobl.Fn pci_find_bsf
20755aaf894SMarius Stroblfunction only searches the first one.
20855aaf894SMarius StroblActually, it is equivalent to:
20955aaf894SMarius Strobl.Bd -literal -offset indent
21055aaf894SMarius Stroblpci_find_dbsf(0, bus, slot, func);
21155aaf894SMarius Strobl.Ed
21255aaf894SMarius Strobl.Pp
21355aaf894SMarius StroblThe
21455aaf894SMarius Strobl.Fn pci_find_dbsf
21555aaf894SMarius Stroblfunction looks up the
21655aaf894SMarius Strobl.Vt device_t
21755aaf894SMarius Stroblof a PCI device, given its
21855aaf894SMarius Strobl.Fa domain ,
21955aaf894SMarius Strobl.Fa bus ,
22055aaf894SMarius Strobl.Fa slot ,
22155aaf894SMarius Strobland
22255aaf894SMarius Strobl.Fa func .
22355aaf894SMarius StroblThe
22455aaf894SMarius Strobl.Fa slot
22555aaf894SMarius Stroblnumber actually refers to the number of the device on the bus,
22655aaf894SMarius Stroblwhich does not necessarily indicate its geographic location
22755aaf894SMarius Stroblin terms of a physical slot.
228aac0aafaSHiten Pandya.Pp
229aac0aafaSHiten PandyaThe
230aac0aafaSHiten Pandya.Fn pci_find_device
231aac0aafaSHiten Pandyafunction looks up the
232aac0aafaSHiten Pandya.Vt device_t
233aac0aafaSHiten Pandyaof a PCI device, given its
234aac0aafaSHiten Pandya.Fa vendor
235aac0aafaSHiten Pandyaand
236aac0aafaSHiten Pandya.Fa device
2375203edcdSRuslan ErmilovIDs.
2385203edcdSRuslan ErmilovNote that there can be multiple matches for this search; this function
239aac0aafaSHiten Pandyaonly returns the first matching device.
240aac0aafaSHiten Pandya.Sh IMPLEMENTATION NOTES
241aac0aafaSHiten PandyaThe
242aac0aafaSHiten Pandya.Vt pci_addr_t
24365bb31b8SRuslan Ermilovtype varies according to the size of the PCI bus address
244aac0aafaSHiten Pandyaspace on the target architecture.
245aac0aafaSHiten Pandya.Sh SEE ALSO
2467c2c06f2SSheldon Hearn.Xr pci 4 ,
2477c2c06f2SSheldon Hearn.Xr pciconf 8 ,
248aac0aafaSHiten Pandya.Xr bus_alloc_resource 9 ,
249aac0aafaSHiten Pandya.Xr bus_dma 9 ,
250aac0aafaSHiten Pandya.Xr bus_release_resource 9 ,
251aac0aafaSHiten Pandya.Xr bus_setup_intr 9 ,
252aac0aafaSHiten Pandya.Xr bus_teardown_intr 9 ,
253aac0aafaSHiten Pandya.Xr devclass 9 ,
254aac0aafaSHiten Pandya.Xr device 9 ,
255aac0aafaSHiten Pandya.Xr driver 9 ,
256aac0aafaSHiten Pandya.Xr rman 9
257aac0aafaSHiten Pandya.Rs
258aac0aafaSHiten Pandya.%B FreeBSD Developers' Handbook
259aac0aafaSHiten Pandya.%T NewBus
260aac0aafaSHiten Pandya.%O http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/
261aac0aafaSHiten Pandya.Re
262aac0aafaSHiten Pandya.Rs
263aac0aafaSHiten Pandya.%A Shanley
264aac0aafaSHiten Pandya.%A Anderson
265aac0aafaSHiten Pandya.%B PCI System Architecture
266aac0aafaSHiten Pandya.%N 2nd Edition
267aac0aafaSHiten Pandya.%I Addison-Wesley
268aac0aafaSHiten Pandya.%O ISBN 0-201-30974-2
269aac0aafaSHiten Pandya.Re
270aac0aafaSHiten Pandya.Sh AUTHORS
271571dba6eSHiten PandyaThis manual page was written by
272bf1639eeSBruce M Simpson.An Bruce M Simpson Aq bms@FreeBSD.org .
273aac0aafaSHiten Pandya.Sh BUGS
2744d80f750SBruce M SimpsonThe kernel PCI code has a number of references to
2754d80f750SBruce M Simpson.Dq "slot numbers" .
276bf1639eeSBruce M SimpsonThese do not refer to the geographic location of PCI devices,
277bf1639eeSBruce M Simpsonbut to the device number assigned by the combination of the PCI IDSEL
278bf1639eeSBruce M Simpsonmechanism and the platform firmware.
279bf1639eeSBruce M SimpsonThis should be taken note of when working with the kernel PCI code.
280