1.\" 2.\" Copyright (c) 2003 Bruce M Simpson <bms@spc.org> 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 1. Redistributions of source code must retain the above copyright 9.\" notice, this list of conditions and the following disclaimer. 10.\" 2. Redistributions in binary form must reproduce the above copyright 11.\" notice, this list of conditions and the following disclaimer in the 12.\" documentation and/or other materials provided with the distribution. 13.\" 14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24.\" SUCH DAMAGE. 25.\" 26.\" $FreeBSD$ 27.\" 28.Dd May 21, 2003 29.Dt PCI 9 30.Os 31.Sh NAME 32.Nm pci , 33.Nm pci_read_config , 34.Nm pci_write_config , 35.Nm pci_enable_busmaster , 36.Nm pci_disable_busmaster , 37.Nm pci_enable_io , 38.Nm pci_disable_io , 39.Nm pci_set_powerstate , 40.Nm pci_get_powerstate , 41.Nm pci_find_bsf , 42.Nm pci_find_device 43.Nd PCI bus interface 44.Sh SYNOPSIS 45.In sys/bus.h 46.In dev/pci/pcivar.h 47.In dev/pci/pcireg.h 48.In machine/pci_cfgreg.h 49.Pp 50.Ft void 51.Fn pci_write_config "device_t dev" "int reg" "u_int32_t val" "int width" 52.Ft int 53.Fn pci_enable_busmaster "device_t dev" 54.Ft int 55.Fn pci_disable_busmaster "device_t dev" 56.Ft int 57.Fn pci_enable_io "device_t dev" "int space" 58.Ft int 59.Fn pci_disable_io "device_t dev" "int space" 60.Ft int 61.Fn pci_set_powerstate "device_t dev" "int state" 62.Ft int 63.Fn pci_get_powerstate "device_t dev" 64.Ft u_int32_t 65.Fn pci_read_config "device_t dev" "int reg" "int width" 66.Ft device_t 67.Fn pci_find_bsf "u_int8_t" "u_int8_t" "u_int8_t" 68.Ft device_t 69.Fn pci_find_device "u_int16_t" "u_int16_t" 70.Sh DESCRIPTION 71The 72.Nm 73set of functions are used for managing PCI devices. 74.Pp 75The 76.Fn pci_read_config 77function is used to read data from the PCI configuration 78space of the device 79.Fa dev , 80at offset 81.Fa reg , 82with 83.Fa width 84specifying the size of the access. 85.Pp 86The 87.Fn pci_write_config 88function is used to write the value 89.Fa val 90to the PCI configuration 91space of the device 92.Fa dev , 93at offset 94.Fa reg , 95with 96.Fa width 97specifying the size of the access. 98.Pp 99The 100.Fn pci_enable_busmaster 101function enables PCI bus mastering for the device 102.Fa dev , 103by setting the 104.Dv PCIM_CMD_BUSMASTEREN 105bit in the 106.Dv PCIR_COMMAND 107register. 108The 109.Fn pci_disable_busmaster 110function clears this bit. 111.Pp 112The 113.Fn pci_enable_io 114function enables memory or I/O port address decoding for the device 115.Fa dev , 116by setting the 117.Dv PCIM_CMD_MEMEN 118or 119.Dv PCIM_CMD_PORTEN 120bit in the 121.Dv PCIR_COMMAND 122register appropriately. The 123.Fn pci_disable_io 124function clears the appropriate bit. 125The 126.Fa state 127argument specifies which resource is affected; this can be either 128.Dv SYS_RES_MEMORY 129or 130.Dv SYS_RES_IOPORT 131as appropriate. 132.Pp 133.Em NOTE : 134These functions should be used in preference to manually manipulating 135the configuration space. 136.Pp 137The 138.Fn pci_get_powerstate 139function returns the current ACPI power state of the device 140.Fa dev . 141If the device does not support power management capabilities, then the default 142state of 143.Dv PCI_POWERSTATE_D0 144is returned. 145The following power states are defined by ACPI: 146.Bl -hang -width PCI_POWERSTATE_UNKNOWN 147.It Dv PCI_POWERSTATE_D0 148State in which device is on and running. 149It is receiving full power from the system and delivering 150full functionality to the user. 151.It Dv PCI_POWERSTATE_D1 152Class-specific low-power state in which device context may or 153may not be lot. 154Buses in this state cannot do anything to the bus, to 155force devices to loose context. 156.It Dv PCI_POWERSTATE_D2 157Class-specific low-power state in which device context may or 158may not be lost. 159Attains greater power savings than 160.Dv PCI_POWERSTATE_D1 . 161Buses in this state can cause devices to loose some context. 162Devices 163.Em must 164be prepared for the bus to be in this state or higher. 165.It Dv PCI_POWERSTATE_D3 166State in which the device is off and not running. 167Device context is lost, and power from the device can 168be removed. 169.It Dv PCI_POWERSTATE_UNKNOWN 170State of the device is unknown. 171.El 172.Pp 173The 174.Fn pci_set_powerstate 175function is used to transition the device 176.Fa dev 177to the ACPI power state 178.Fa state . 179It checks to see if the device is PCI 2.2 compliant. 180If so, it checks the 181capabilities pointer to determine which power states the device supports. 182If the device does not have power management capabilities, the default state 183of 184.Dv PCI_POWERSTATE_D0 185is set. 186.Pp 187The 188.Fn pci_find_bsf 189function looks up the 190.Vt device_t 191of a PCI device, given its 192.Fa bus , 193.Fa slot , 194and 195.Fa function . 196.Pp 197The 198.Fn pci_find_device 199function looks up the 200.Vt device_t 201of a PCI device, given its 202.Fa vendor 203and 204.Fa device 205IDs. Note that there can be multiple matches for this search; this function 206only returns the first matching device. 207.Sh IMPLEMENTATION NOTES 208The 209.Vt pci_addr_t 210type is varies according to the size of the PCI bus address 211space on the target architecture. 212.Sh SEE ALSO 213.Xr pci 4 , 214.Xr pciconf 8 , 215.Xr bus_alloc_resource 9 , 216.Xr bus_dma 9 , 217.Xr bus_release_resource 9 , 218.Xr bus_setup_intr 9 , 219.Xr bus_teardown_intr 9 , 220.Xr devclass 9 , 221.Xr device 9 , 222.Xr driver 9 , 223.Xr rman 9 224.Rs 225.%B FreeBSD Developers' Handbook 226.%T NewBus 227.%O http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/ 228.Re 229.Rs 230.%A Shanley 231.%A Anderson 232.%B PCI System Architecture 233.%N 2nd Edition 234.%I Addison-Wesley 235.%O ISBN 0-201-30974-2 236.Re 237.Sh AUTHORS 238This man page was written by 239.An Bruce M Simpson Aq bms@spc.org . 240.Sh BUGS 241This manual page does not yet document PAE and how it affects memory-space 242mapping of PCI devices. 243