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.\" 28dfef6658SSergey Kandaurov.Dd March 5, 2012 29aac0aafaSHiten Pandya.Dt PCI 9 30aac0aafaSHiten Pandya.Os 31aac0aafaSHiten Pandya.Sh NAME 32aac0aafaSHiten Pandya.Nm pci , 33855ed4c5SJohn Baldwin.Nm pci_alloc_msi , 34855ed4c5SJohn Baldwin.Nm pci_alloc_msix , 35aac0aafaSHiten Pandya.Nm pci_disable_busmaster , 36aac0aafaSHiten Pandya.Nm pci_disable_io , 370a9c80e5SJohn Baldwin.Nm pci_enable_busmaster , 380a9c80e5SJohn Baldwin.Nm pci_enable_io , 39aac0aafaSHiten Pandya.Nm pci_find_bsf , 40855ed4c5SJohn Baldwin.Nm pci_find_cap , 4155aaf894SMarius Strobl.Nm pci_find_dbsf , 420a9c80e5SJohn Baldwin.Nm pci_find_device , 4368bf9717SJohn Baldwin.Nm pci_find_extcap , 4468bf9717SJohn Baldwin.Nm pci_find_htcap , 45855ed4c5SJohn Baldwin.Nm pci_get_max_read_req , 460a9c80e5SJohn Baldwin.Nm pci_get_powerstate , 47855ed4c5SJohn Baldwin.Nm pci_get_vpd_ident , 48855ed4c5SJohn Baldwin.Nm pci_get_vpd_readonly , 49855ed4c5SJohn Baldwin.Nm pci_msi_count , 50855ed4c5SJohn Baldwin.Nm pci_msix_count , 51855ed4c5SJohn Baldwin.Nm pci_pending_msix , 520a9c80e5SJohn Baldwin.Nm pci_read_config , 53855ed4c5SJohn Baldwin.Nm pci_release_msi , 54855ed4c5SJohn Baldwin.Nm pci_remap_msix , 550a9c80e5SJohn Baldwin.Nm pci_restore_state , 560a9c80e5SJohn Baldwin.Nm pci_save_state , 57855ed4c5SJohn Baldwin.Nm pci_set_max_read_req , 580a9c80e5SJohn Baldwin.Nm pci_set_powerstate , 590a9c80e5SJohn Baldwin.Nm pci_write_config 60aac0aafaSHiten Pandya.Nd PCI bus interface 61aac0aafaSHiten Pandya.Sh SYNOPSIS 62aac0aafaSHiten Pandya.In sys/bus.h 63aac0aafaSHiten Pandya.In dev/pci/pcireg.h 64855ed4c5SJohn Baldwin.In dev/pci/pcivar.h 65855ed4c5SJohn Baldwin.Ft int 66855ed4c5SJohn Baldwin.Fn pci_alloc_msi "device_t dev" "int *count" 67855ed4c5SJohn Baldwin.Ft int 68855ed4c5SJohn Baldwin.Fn pci_alloc_msix "device_t dev" "int *count" 69aac0aafaSHiten Pandya.Ft int 70aac0aafaSHiten Pandya.Fn pci_disable_busmaster "device_t dev" 71aac0aafaSHiten Pandya.Ft int 72aac0aafaSHiten Pandya.Fn pci_disable_io "device_t dev" "int space" 73aac0aafaSHiten Pandya.Ft int 740a9c80e5SJohn Baldwin.Fn pci_enable_busmaster "device_t dev" 75aac0aafaSHiten Pandya.Ft int 760a9c80e5SJohn Baldwin.Fn pci_enable_io "device_t dev" "int space" 77aac0aafaSHiten Pandya.Ft device_t 7865bb31b8SRuslan Ermilov.Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func" 79855ed4c5SJohn Baldwin.Ft int 80855ed4c5SJohn Baldwin.Fn pci_find_cap "device_t dev" "int capability" "int *capreg" 81aac0aafaSHiten Pandya.Ft device_t 8255aaf894SMarius Strobl.Fn pci_find_dbsf "uint32_t domain" "uint8_t bus" "uint8_t slot" "uint8_t func" 8355aaf894SMarius Strobl.Ft device_t 8465bb31b8SRuslan Ermilov.Fn pci_find_device "uint16_t vendor" "uint16_t device" 850a9c80e5SJohn Baldwin.Ft int 8668bf9717SJohn Baldwin.Fn pci_find_extcap "device_t dev" "int capability" "int *capreg" 8768bf9717SJohn Baldwin.Ft int 8868bf9717SJohn Baldwin.Fn pci_find_htcap "device_t dev" "int capability" "int *capreg" 8968bf9717SJohn Baldwin.Ft int 90855ed4c5SJohn Baldwin.Fn pci_get_max_read_req "device_t dev" 91855ed4c5SJohn Baldwin.Ft int 920a9c80e5SJohn Baldwin.Fn pci_get_powerstate "device_t dev" 93855ed4c5SJohn Baldwin.Ft int 94855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident "device_t dev" "const char **identptr" 95855ed4c5SJohn Baldwin.Ft int 96855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly "device_t dev" "const char *kw" "const char **vptr" 97855ed4c5SJohn Baldwin.Ft int 98855ed4c5SJohn Baldwin.Fn pci_msi_count "device_t dev" 99855ed4c5SJohn Baldwin.Ft int 100855ed4c5SJohn Baldwin.Fn pci_msix_count "device_t dev" 101855ed4c5SJohn Baldwin.Ft int 102855ed4c5SJohn Baldwin.Fn pci_pending_msix "device_t dev" "u_int index" 1030a9c80e5SJohn Baldwin.Ft uint32_t 1040a9c80e5SJohn Baldwin.Fn pci_read_config "device_t dev" "int reg" "int width" 105855ed4c5SJohn Baldwin.Ft int 106855ed4c5SJohn Baldwin.Fn pci_release_msi "device_t dev" 107855ed4c5SJohn Baldwin.Ft int 108855ed4c5SJohn Baldwin.Fn pci_remap_msix "device_t dev" "int count" "const u_int *vectors" 1090a9c80e5SJohn Baldwin.Ft void 1100a9c80e5SJohn Baldwin.Fn pci_restore_state "device_t dev" 1110a9c80e5SJohn Baldwin.Ft void 1120a9c80e5SJohn Baldwin.Fn pci_save_state "device_t dev" 1130a9c80e5SJohn Baldwin.Ft int 114855ed4c5SJohn Baldwin.Fn pci_set_max_read_req "device_t dev" "int size" 115855ed4c5SJohn Baldwin.Ft int 1160a9c80e5SJohn Baldwin.Fn pci_set_powerstate "device_t dev" "int state" 1170a9c80e5SJohn Baldwin.Ft void 1180a9c80e5SJohn Baldwin.Fn pci_write_config "device_t dev" "int reg" "uint32_t val" "int width" 119aac0aafaSHiten Pandya.Sh DESCRIPTION 120aac0aafaSHiten PandyaThe 121aac0aafaSHiten Pandya.Nm 122aac0aafaSHiten Pandyaset of functions are used for managing PCI devices. 123855ed4c5SJohn BaldwinThe functions are split into several groups: 124855ed4c5SJohn Baldwinraw configuration access, 125855ed4c5SJohn Baldwinlocating devices, 126855ed4c5SJohn Baldwindevice information, 127855ed4c5SJohn Baldwindevice configuration, 128855ed4c5SJohn Baldwinand 129855ed4c5SJohn Baldwinmessage signaled interrupts. 130855ed4c5SJohn Baldwin.Ss Raw Configuration Access 131aac0aafaSHiten PandyaThe 132aac0aafaSHiten Pandya.Fn pci_read_config 133aac0aafaSHiten Pandyafunction is used to read data from the PCI configuration 134aac0aafaSHiten Pandyaspace of the device 135aac0aafaSHiten Pandya.Fa dev , 136aac0aafaSHiten Pandyaat offset 137aac0aafaSHiten Pandya.Fa reg , 138aac0aafaSHiten Pandyawith 139aac0aafaSHiten Pandya.Fa width 140aac0aafaSHiten Pandyaspecifying the size of the access. 141aac0aafaSHiten Pandya.Pp 142aac0aafaSHiten PandyaThe 143aac0aafaSHiten Pandya.Fn pci_write_config 144aac0aafaSHiten Pandyafunction is used to write the value 145aac0aafaSHiten Pandya.Fa val 146aac0aafaSHiten Pandyato the PCI configuration 147aac0aafaSHiten Pandyaspace of the device 148aac0aafaSHiten Pandya.Fa dev , 149aac0aafaSHiten Pandyaat offset 150aac0aafaSHiten Pandya.Fa reg , 151aac0aafaSHiten Pandyawith 152aac0aafaSHiten Pandya.Fa width 153aac0aafaSHiten Pandyaspecifying the size of the access. 154aac0aafaSHiten Pandya.Pp 155855ed4c5SJohn Baldwin.Em NOTE : 156855ed4c5SJohn BaldwinDevice drivers should only use these functions for functionality that 157855ed4c5SJohn Baldwinis not available via another 158855ed4c5SJohn Baldwin.Fn pci 159855ed4c5SJohn Baldwinfunction. 160855ed4c5SJohn Baldwin.Ss Locating Devices 161855ed4c5SJohn BaldwinThe 162855ed4c5SJohn Baldwin.Fn pci_find_bsf 163855ed4c5SJohn Baldwinfunction looks up the 164855ed4c5SJohn Baldwin.Vt device_t 165855ed4c5SJohn Baldwinof a PCI device, given its 166855ed4c5SJohn Baldwin.Fa bus , 167855ed4c5SJohn Baldwin.Fa slot , 168855ed4c5SJohn Baldwinand 169855ed4c5SJohn Baldwin.Fa func . 170855ed4c5SJohn BaldwinThe 171855ed4c5SJohn Baldwin.Fa slot 172855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus, 173855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location 174855ed4c5SJohn Baldwinin terms of a physical slot. 175855ed4c5SJohn BaldwinNote that in case the system has multiple PCI domains, 176855ed4c5SJohn Baldwinthe 177855ed4c5SJohn Baldwin.Fn pci_find_bsf 178855ed4c5SJohn Baldwinfunction only searches the first one. 179855ed4c5SJohn BaldwinActually, it is equivalent to: 180855ed4c5SJohn Baldwin.Bd -literal -offset indent 181855ed4c5SJohn Baldwinpci_find_dbsf(0, bus, slot, func); 182855ed4c5SJohn Baldwin.Ed 183855ed4c5SJohn Baldwin.Pp 184855ed4c5SJohn BaldwinThe 185855ed4c5SJohn Baldwin.Fn pci_find_dbsf 186855ed4c5SJohn Baldwinfunction looks up the 187855ed4c5SJohn Baldwin.Vt device_t 188855ed4c5SJohn Baldwinof a PCI device, given its 189855ed4c5SJohn Baldwin.Fa domain , 190855ed4c5SJohn Baldwin.Fa bus , 191855ed4c5SJohn Baldwin.Fa slot , 192855ed4c5SJohn Baldwinand 193855ed4c5SJohn Baldwin.Fa func . 194855ed4c5SJohn BaldwinThe 195855ed4c5SJohn Baldwin.Fa slot 196855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus, 197855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location 198855ed4c5SJohn Baldwinin terms of a physical slot. 199855ed4c5SJohn Baldwin.Pp 200855ed4c5SJohn BaldwinThe 201855ed4c5SJohn Baldwin.Fn pci_find_device 202855ed4c5SJohn Baldwinfunction looks up the 203855ed4c5SJohn Baldwin.Vt device_t 204855ed4c5SJohn Baldwinof a PCI device, given its 205855ed4c5SJohn Baldwin.Fa vendor 206855ed4c5SJohn Baldwinand 207855ed4c5SJohn Baldwin.Fa device 208855ed4c5SJohn BaldwinIDs. 209855ed4c5SJohn BaldwinNote that there can be multiple matches for this search; this function 210855ed4c5SJohn Baldwinonly returns the first matching device. 211855ed4c5SJohn Baldwin.Ss Device Information 212855ed4c5SJohn BaldwinThe 213855ed4c5SJohn Baldwin.Fn pci_find_cap 214855ed4c5SJohn Baldwinfunction is used to locate the first instance of a PCI capability 215855ed4c5SJohn Baldwinregister set for the device 216855ed4c5SJohn Baldwin.Fa dev . 217855ed4c5SJohn BaldwinThe capability to locate is specified by ID via 218855ed4c5SJohn Baldwin.Fa capability . 219855ed4c5SJohn BaldwinConstant macros of the form 220855ed4c5SJohn Baldwin.Dv PCIY_xxx 221855ed4c5SJohn Baldwinfor standard capability IDs are defined in 222855ed4c5SJohn Baldwin.In dev/pci/pcireg.h . 223855ed4c5SJohn BaldwinIf the capability is found, then 224855ed4c5SJohn Baldwin.Fa *capreg 225281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set, 226855ed4c5SJohn Baldwinand 227855ed4c5SJohn Baldwin.Fn pci_find_cap 228855ed4c5SJohn Baldwinreturns zero. 229855ed4c5SJohn BaldwinIf the capability is not found or the device does not support capabilities, 230855ed4c5SJohn Baldwin.Fn pci_find_cap 231855ed4c5SJohn Baldwinreturns an error. 232855ed4c5SJohn Baldwin.Pp 233855ed4c5SJohn BaldwinThe 23468bf9717SJohn Baldwin.Fn pci_find_extcap 23568bf9717SJohn Baldwinfunction is used to locate the first instance of a PCI-express 23668bf9717SJohn Baldwinextended capability register set for the device 23768bf9717SJohn Baldwin.Fa dev . 23868bf9717SJohn BaldwinThe extended capability to locate is specified by ID via 23968bf9717SJohn Baldwin.Fa capability . 24068bf9717SJohn BaldwinConstant macros of the form 24168bf9717SJohn Baldwin.Dv PCIZ_xxx 24268bf9717SJohn Baldwinfor standard extended capability IDs are defined in 24368bf9717SJohn Baldwin.In dev/pci/pcireg.h . 24468bf9717SJohn BaldwinIf the extended capability is found, then 24568bf9717SJohn Baldwin.Fa *capreg 246281a359eSJohn Baldwinis set to the offset in configuration space of the extended capability 24768bf9717SJohn Baldwinregister set, and 24868bf9717SJohn Baldwin.Fn pci_find_extcap 24968bf9717SJohn Baldwinreturns zero. 25068bf9717SJohn BaldwinIf the extended capability is not found or the device is not a 25168bf9717SJohn BaldwinPCI-express device, 25268bf9717SJohn Baldwin.Fn pci_find_extcap 25368bf9717SJohn Baldwinreturns an error. 25468bf9717SJohn Baldwin.Pp 25568bf9717SJohn BaldwinThe 25668bf9717SJohn Baldwin.Fn pci_find_htcap 25768bf9717SJohn Baldwinfunction is used to locate the first instance of a HyperTransport capability 25868bf9717SJohn Baldwinregister set for the device 25968bf9717SJohn Baldwin.Fa dev . 26068bf9717SJohn BaldwinThe capability to locate is specified by type via 26168bf9717SJohn Baldwin.Fa capability . 26268bf9717SJohn BaldwinConstant macros of the form 26368bf9717SJohn Baldwin.Dv PCIM_HTCAP_xxx 26468bf9717SJohn Baldwinfor standard HyperTransport capability types are defined in 26568bf9717SJohn Baldwin.In dev/pci/pcireg.h . 26668bf9717SJohn BaldwinIf the capability is found, then 26768bf9717SJohn Baldwin.Fa *capreg 268281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set, 26968bf9717SJohn Baldwinand 27068bf9717SJohn Baldwin.Fn pci_find_htcap 27168bf9717SJohn Baldwinreturns zero. 27268bf9717SJohn BaldwinIf the capability is not found or the device is not a HyperTransport device, 27368bf9717SJohn Baldwin.Fn pci_find_htcap 27468bf9717SJohn Baldwinreturns an error. 27568bf9717SJohn Baldwin.Pp 27668bf9717SJohn BaldwinThe 277855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident 278855ed4c5SJohn Baldwinfunction is used to fetch a device's Vital Product Data 279855ed4c5SJohn Baldwin.Pq VPD 280855ed4c5SJohn Baldwinidentifier string. 281855ed4c5SJohn BaldwinIf the device 282855ed4c5SJohn Baldwin.Fa dev 283855ed4c5SJohn Baldwinsupports VPD and provides an identifier string, 284855ed4c5SJohn Baldwinthen 285855ed4c5SJohn Baldwin.Fa *identptr 286855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the identifier 287855ed4c5SJohn Baldwinstring, 288855ed4c5SJohn Baldwinand 289855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident 290855ed4c5SJohn Baldwinreturns zero. 291855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide an identifier 292855ed4c5SJohn Baldwinstring, 293855ed4c5SJohn Baldwinthen 294855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident 295855ed4c5SJohn Baldwinreturns an error. 296855ed4c5SJohn Baldwin.Pp 297855ed4c5SJohn BaldwinThe 298855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly 299855ed4c5SJohn Baldwinfunction is used to fetch the value of a single VPD read-only keyword 300855ed4c5SJohn Baldwinfor the device 301855ed4c5SJohn Baldwin.Fa dev . 302855ed4c5SJohn BaldwinThe keyword to fetch is identified by the two character string 303855ed4c5SJohn Baldwin.Fa kw . 304855ed4c5SJohn BaldwinIf the device supports VPD and provides a read-only value for the 305855ed4c5SJohn Baldwinrequested keyword, 306855ed4c5SJohn Baldwinthen 307855ed4c5SJohn Baldwin.Fa *vptr 308855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the value, 309855ed4c5SJohn Baldwinand 310855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly 311855ed4c5SJohn Baldwinreturns zero. 312855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide the requested 313855ed4c5SJohn Baldwinkeyword, 314855ed4c5SJohn Baldwinthen 315855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly 316855ed4c5SJohn Baldwinreturns an error. 317855ed4c5SJohn Baldwin.Ss Device Configuration 318aac0aafaSHiten PandyaThe 319aac0aafaSHiten Pandya.Fn pci_enable_busmaster 320aac0aafaSHiten Pandyafunction enables PCI bus mastering for the device 321aac0aafaSHiten Pandya.Fa dev , 322aac0aafaSHiten Pandyaby setting the 323aac0aafaSHiten Pandya.Dv PCIM_CMD_BUSMASTEREN 324aac0aafaSHiten Pandyabit in the 325aac0aafaSHiten Pandya.Dv PCIR_COMMAND 326aac0aafaSHiten Pandyaregister. 327aac0aafaSHiten PandyaThe 328aac0aafaSHiten Pandya.Fn pci_disable_busmaster 329aac0aafaSHiten Pandyafunction clears this bit. 330aac0aafaSHiten Pandya.Pp 331aac0aafaSHiten PandyaThe 332aac0aafaSHiten Pandya.Fn pci_enable_io 333aac0aafaSHiten Pandyafunction enables memory or I/O port address decoding for the device 334aac0aafaSHiten Pandya.Fa dev , 335aac0aafaSHiten Pandyaby setting the 336aac0aafaSHiten Pandya.Dv PCIM_CMD_MEMEN 337aac0aafaSHiten Pandyaor 338aac0aafaSHiten Pandya.Dv PCIM_CMD_PORTEN 339aac0aafaSHiten Pandyabit in the 340aac0aafaSHiten Pandya.Dv PCIR_COMMAND 3415203edcdSRuslan Ermilovregister appropriately. 3425203edcdSRuslan ErmilovThe 343aac0aafaSHiten Pandya.Fn pci_disable_io 344aac0aafaSHiten Pandyafunction clears the appropriate bit. 345aac0aafaSHiten PandyaThe 34665bb31b8SRuslan Ermilov.Fa space 347aac0aafaSHiten Pandyaargument specifies which resource is affected; this can be either 348aac0aafaSHiten Pandya.Dv SYS_RES_MEMORY 349aac0aafaSHiten Pandyaor 350aac0aafaSHiten Pandya.Dv SYS_RES_IOPORT 351aac0aafaSHiten Pandyaas appropriate. 352855ed4c5SJohn BaldwinDevice drivers should generally not use these routines directly. 353855ed4c5SJohn BaldwinThe PCI bus will enable decoding automatically when a 354855ed4c5SJohn Baldwin.Dv SYS_RES_MEMORY 355855ed4c5SJohn Baldwinor 356855ed4c5SJohn Baldwin.Dv SYS_RES_IOPORT 357855ed4c5SJohn Baldwinresource is activated via 358855ed4c5SJohn Baldwin.Xr bus_alloc_resource 9 359855ed4c5SJohn Baldwinor 360855ed4c5SJohn Baldwin.Xr bus_activate_resource 9 . 361aac0aafaSHiten Pandya.Pp 362855ed4c5SJohn BaldwinThe 363855ed4c5SJohn Baldwin.Fn pci_get_max_read_req 364855ed4c5SJohn Baldwinfunction returns the current maximum read request size in bytes for a 365855ed4c5SJohn BaldwinPCI-express device. 366855ed4c5SJohn BaldwinIf the 367855ed4c5SJohn Baldwin.Fa dev 368855ed4c5SJohn Baldwindevice is not a PCI-express device, 369855ed4c5SJohn Baldwin.Fn pci_get_max_read_req 370855ed4c5SJohn Baldwinreturns zero. 371855ed4c5SJohn Baldwin.Pp 372855ed4c5SJohn BaldwinThe 373855ed4c5SJohn Baldwin.Fn pci_set_max_read_req 374855ed4c5SJohn Baldwinsets the PCI-express maximum read request size for 375855ed4c5SJohn Baldwin.Fa dev . 376855ed4c5SJohn BaldwinThe requested 377855ed4c5SJohn Baldwin.Fa size 378855ed4c5SJohn Baldwinmay be adjusted, 379855ed4c5SJohn Baldwinand 380855ed4c5SJohn Baldwin.Fn pci_set_max_read_req 381855ed4c5SJohn Baldwinreturns the actual size set in bytes. 382855ed4c5SJohn BaldwinIf the 383855ed4c5SJohn Baldwin.Fa dev 384855ed4c5SJohn Baldwindevice is not a PCI-express device, 385855ed4c5SJohn Baldwin.Fn pci_set_max_read_req 386855ed4c5SJohn Baldwinreturns zero. 387aac0aafaSHiten Pandya.Pp 388aac0aafaSHiten PandyaThe 389aac0aafaSHiten Pandya.Fn pci_get_powerstate 390adb63907SJohn Baldwinfunction returns the current power state of the device 391aac0aafaSHiten Pandya.Fa dev . 392aac0aafaSHiten PandyaIf the device does not support power management capabilities, then the default 393aac0aafaSHiten Pandyastate of 394aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D0 395aac0aafaSHiten Pandyais returned. 396adb63907SJohn BaldwinThe following power states are defined by PCI: 39765bb31b8SRuslan Ermilov.Bl -hang -width ".Dv PCI_POWERSTATE_UNKNOWN" 398aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D0 399aac0aafaSHiten PandyaState in which device is on and running. 400aac0aafaSHiten PandyaIt is receiving full power from the system and delivering 401aac0aafaSHiten Pandyafull functionality to the user. 402aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D1 403aac0aafaSHiten PandyaClass-specific low-power state in which device context may or 4045a2e3b61SDaniel Gerzomay not be lost. 40565bb31b8SRuslan ErmilovBusses in this state cannot do anything to the bus, to 4069817b894SBruce M Simpsonforce devices to lose context. 407aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D2 408aac0aafaSHiten PandyaClass-specific low-power state in which device context may or 409aac0aafaSHiten Pandyamay not be lost. 410aac0aafaSHiten PandyaAttains greater power savings than 411aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D1 . 41265bb31b8SRuslan ErmilovBusses in this state can cause devices to lose some context. 413aac0aafaSHiten PandyaDevices 414aac0aafaSHiten Pandya.Em must 415aac0aafaSHiten Pandyabe prepared for the bus to be in this state or higher. 416aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D3 417aac0aafaSHiten PandyaState in which the device is off and not running. 418aac0aafaSHiten PandyaDevice context is lost, and power from the device can 419aac0aafaSHiten Pandyabe removed. 420aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_UNKNOWN 421aac0aafaSHiten PandyaState of the device is unknown. 422aac0aafaSHiten Pandya.El 423aac0aafaSHiten Pandya.Pp 424aac0aafaSHiten PandyaThe 425aac0aafaSHiten Pandya.Fn pci_set_powerstate 426aac0aafaSHiten Pandyafunction is used to transition the device 427aac0aafaSHiten Pandya.Fa dev 428adb63907SJohn Baldwinto the PCI power state 429aac0aafaSHiten Pandya.Fa state . 430adb63907SJohn BaldwinIf the device does not support power management capabilities or 431adb63907SJohn Baldwinit does not support the specific power state 432adb63907SJohn Baldwin.Fa state , 433adb63907SJohn Baldwinthen the function will fail with 434adb63907SJohn Baldwin.Er EOPNOTSUPP . 435aac0aafaSHiten Pandya.Pp 436aac0aafaSHiten PandyaThe 4379415d1e0SJohn Baldwin.Fn pci_save_state 4389415d1e0SJohn Baldwinand 4399415d1e0SJohn Baldwin.Fn pci_restore_state 4409415d1e0SJohn Baldwinfunctions can be used by a device driver to save and restore standard PCI 4419415d1e0SJohn Baldwinconfig registers. 4429415d1e0SJohn BaldwinThe 4439415d1e0SJohn Baldwin.Fn pci_save_state 4449415d1e0SJohn Baldwinfunction must be invoked while the device has valid state before 4459415d1e0SJohn Baldwin.Fn pci_restore_state 4469415d1e0SJohn Baldwincan be used. 4479415d1e0SJohn BaldwinIf the device is not in the fully-powered state 4489415d1e0SJohn Baldwin.Pq Dv PCI_POWERSTATE_D0 4499415d1e0SJohn Baldwinwhen 4509415d1e0SJohn Baldwin.Fn pci_restore_state 4519415d1e0SJohn Baldwinis invoked, 4529415d1e0SJohn Baldwinthen the device will be transitioned to 4539415d1e0SJohn Baldwin.Dv PCI_POWERSTATE_D0 4549415d1e0SJohn Baldwinbefore any config registers are restored. 455855ed4c5SJohn Baldwin.Ss Message Signaled Interrupts 456855ed4c5SJohn BaldwinMessage Signaled Interrupts 457855ed4c5SJohn Baldwin.Pq MSI 458855ed4c5SJohn Baldwinand 459855ed4c5SJohn BaldwinEnhanced Message Signaled Interrupts 460855ed4c5SJohn Baldwin.Pq MSI-X 461855ed4c5SJohn Baldwinare PCI capabilities that provide an alternate method for PCI 462855ed4c5SJohn Baldwindevices to signal interrupts. 463855ed4c5SJohn BaldwinThe legacy INTx interrupt is available to PCI devices as a 464855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 465855ed4c5SJohn Baldwinresource with a resource ID of zero. 466855ed4c5SJohn BaldwinMSI and MSI-X interrupts are available to PCI devices as one or more 467855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 468855ed4c5SJohn Baldwinresources with resource IDs greater than zero. 469855ed4c5SJohn BaldwinA driver must ask the PCI bus to allocate MSI or MSI-X interrupts 470855ed4c5SJohn Baldwinusing 471855ed4c5SJohn Baldwin.Fn pci_alloc_msi 472855ed4c5SJohn Baldwinor 473855ed4c5SJohn Baldwin.Fn pci_alloc_msix 474855ed4c5SJohn Baldwinbefore it can use MSI or MSI-X 475855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 476855ed4c5SJohn Baldwinresources. 477855ed4c5SJohn BaldwinA driver is not allowed to use the legacy INTx 478855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 479855ed4c5SJohn Baldwinresource if MSI or MSI-X interrupts have been allocated, 480855ed4c5SJohn Baldwinand attempts to allocate MSI or MSI-X interrupts will fail if the 481855ed4c5SJohn Baldwindriver is currently using the legacy INTx 482855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 483855ed4c5SJohn Baldwinresource. 484855ed4c5SJohn BaldwinA driver is only allowed to use either MSI or MSI-X, 485855ed4c5SJohn Baldwinbut not both. 4869415d1e0SJohn Baldwin.Pp 4879415d1e0SJohn BaldwinThe 488855ed4c5SJohn Baldwin.Fn pci_count_msi 489855ed4c5SJohn Baldwinfunction returns the maximum number of MSI messages supported by the 490855ed4c5SJohn Baldwindevice 491855ed4c5SJohn Baldwin.Fa dev . 492855ed4c5SJohn BaldwinIf the device does not support MSI, 493855ed4c5SJohn Baldwinthen 494855ed4c5SJohn Baldwin.Fn pci_count_msi 495855ed4c5SJohn Baldwinreturns zero. 49655aaf894SMarius Strobl.Pp 49755aaf894SMarius StroblThe 498855ed4c5SJohn Baldwin.Fn pci_alloc_msi 499855ed4c5SJohn Baldwinfunction attempts to allocate 500855ed4c5SJohn Baldwin.Fa *count 501855ed4c5SJohn BaldwinMSI messages for the device 502855ed4c5SJohn Baldwin.Fa dev . 50355aaf894SMarius StroblThe 504855ed4c5SJohn Baldwin.Fn pci_alloc_msi 505855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various 506855ed4c5SJohn Baldwinreasons including requests for more messages than the device 507855ed4c5SJohn Baldwin.Fa dev 508855ed4c5SJohn Baldwinsupports, 509855ed4c5SJohn Baldwinor if the system has a shortage of available MSI messages. 510855ed4c5SJohn BaldwinOn success, 511855ed4c5SJohn Baldwin.Fa *count 512855ed4c5SJohn Baldwinis set to the number of messages allocated and 513855ed4c5SJohn Baldwin.Fn pci_alloc_msi 514855ed4c5SJohn Baldwinreturns zero. 515855ed4c5SJohn BaldwinThe 516855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 517855ed4c5SJohn Baldwinresources for the allocated messages will be available at consecutive 518855ed4c5SJohn Baldwinresource IDs beginning with one. 519855ed4c5SJohn BaldwinIf 520855ed4c5SJohn Baldwin.Fn pci_alloc_msi 521855ed4c5SJohn Baldwinis not able to allocate any messages, 522855ed4c5SJohn Baldwinit returns an error. 523855ed4c5SJohn BaldwinNote that MSI only supports message counts that are powers of two; 524855ed4c5SJohn Baldwinrequests to allocate a non-power of two count of messages will fail. 525aac0aafaSHiten Pandya.Pp 526aac0aafaSHiten PandyaThe 527855ed4c5SJohn Baldwin.Fn pci_release_msi 528855ed4c5SJohn Baldwinfunction is used to release any allocated MSI or MSI-X messages back 529855ed4c5SJohn Baldwinto the system. 530855ed4c5SJohn BaldwinIf any MSI or MSI-X 531855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 532855ed4c5SJohn Baldwinresources are allocated by the driver or have a configured interrupt 533855ed4c5SJohn Baldwinhandler, 534855ed4c5SJohn Baldwinthis function will fail with 535855ed4c5SJohn Baldwin.Er EBUSY . 536855ed4c5SJohn BaldwinThe 537855ed4c5SJohn Baldwin.Fn pci_release_msi 538855ed4c5SJohn Baldwinfunction returns zero on success and an error on failure. 539855ed4c5SJohn Baldwin.Pp 540642c4993SSergey KandaurovThe 541855ed4c5SJohn Baldwin.Fn pci_count_msix 542855ed4c5SJohn Baldwinfunction returns the maximum number of MSI-X messages supported by the 543855ed4c5SJohn Baldwindevice 544855ed4c5SJohn Baldwin.Fa dev . 545855ed4c5SJohn BaldwinIf the device does not support MSI-X, 546855ed4c5SJohn Baldwinthen 547855ed4c5SJohn Baldwin.Fn pci_count_msix 548855ed4c5SJohn Baldwinreturns zero. 549855ed4c5SJohn Baldwin.Pp 550855ed4c5SJohn BaldwinThe 551855ed4c5SJohn Baldwin.Fn pci_alloc_msix 552855ed4c5SJohn Baldwinfunction attempts to allocate 553855ed4c5SJohn Baldwin.Fa *count 554855ed4c5SJohn BaldwinMSI-X messages for the device 555855ed4c5SJohn Baldwin.Fa dev . 556855ed4c5SJohn BaldwinThe 557855ed4c5SJohn Baldwin.Fn pci_alloc_msix 558855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various 559855ed4c5SJohn Baldwinreasons including requests for more messages than the device 560855ed4c5SJohn Baldwin.Fa dev 561855ed4c5SJohn Baldwinsupports, 562855ed4c5SJohn Baldwinor if the system has a shortage of available MSI-X messages. 563855ed4c5SJohn BaldwinOn success, 564855ed4c5SJohn Baldwin.Fa *count 565855ed4c5SJohn Baldwinis set to the number of messages allocated and 566855ed4c5SJohn Baldwin.Fn pci_alloc_msix 567855ed4c5SJohn Baldwinreturns zero. 568855ed4c5SJohn BaldwinFor MSI-X messages, 569855ed4c5SJohn Baldwinthe resource ID for each 570*73bbeaa5SGlen Barber.Dv SYS_RES_IRQ 571*73bbeaa5SGlen Barberresource identifies the index in the MSI-X table of the 572855ed4c5SJohn Baldwincorresponding message. 573855ed4c5SJohn BaldwinA resource ID of one maps to the first index of the MSI-X table; 574855ed4c5SJohn Baldwina resource ID two identifies the second index in the table, etc. 575855ed4c5SJohn BaldwinThe 576855ed4c5SJohn Baldwin.Fn pci_alloc_msix 577855ed4c5SJohn Baldwinfunction assigns the 578855ed4c5SJohn Baldwin.Fa *count 579855ed4c5SJohn Baldwinmessages allocated to the first 580855ed4c5SJohn Baldwin.Fa *count 581855ed4c5SJohn Baldwintable indicies. 582855ed4c5SJohn BaldwinIf 583855ed4c5SJohn Baldwin.Fn pci_alloc_msix 584855ed4c5SJohn Baldwinis not able to allocate any messages, 585855ed4c5SJohn Baldwinit returns an error. 586855ed4c5SJohn BaldwinUnlike MSI, 587855ed4c5SJohn BaldwinMSI-X does not require message counts that are powers of two. 588855ed4c5SJohn Baldwin.Pp 589855ed4c5SJohn BaldwinThe 590855ed4c5SJohn Baldwin.Fn pci_pending_msix 591855ed4c5SJohn Baldwinfunction examines the 592855ed4c5SJohn Baldwin.Fa dev 593855ed4c5SJohn Baldwindevice's Pending Bit Array 594855ed4c5SJohn Baldwin.Pq PBA 595855ed4c5SJohn Baldwinto determine the pending status of the MSI-X message at table index 596855ed4c5SJohn Baldwin.Fa index . 597855ed4c5SJohn BaldwinIf the indicated message is pending, 598855ed4c5SJohn Baldwinthis function returns a non-zero value; 599855ed4c5SJohn Baldwinotherwise, 600855ed4c5SJohn Baldwinit returns zero. 601855ed4c5SJohn BaldwinPassing an invalid 602855ed4c5SJohn Baldwin.Fa index 603855ed4c5SJohn Baldwinto this function will result in undefined behavior. 604855ed4c5SJohn Baldwin.Pp 605855ed4c5SJohn BaldwinAs mentioned in the description of 606855ed4c5SJohn Baldwin.Fn pci_alloc_msix , 607855ed4c5SJohn BaldwinMSI-X messages are initially assigned to the first N table entries. 608855ed4c5SJohn BaldwinA driver may use a different distribution of available messages to 609855ed4c5SJohn Baldwintable entries via the 610855ed4c5SJohn Baldwin.Fn pci_remap_msix 611855ed4c5SJohn Baldwinfunction. 612*73bbeaa5SGlen BarberNote that this function must be called after a successful call to 613855ed4c5SJohn Baldwin.Fn pci_alloc_msix 614855ed4c5SJohn Baldwinbut before any of the 615855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 616855ed4c5SJohn Baldwinresources are allocated. 617855ed4c5SJohn BaldwinThe 618855ed4c5SJohn Baldwin.Fn pci_remap_msix 619855ed4c5SJohn Baldwinfunction returns zero on success, 620855ed4c5SJohn Baldwinor an error on failure. 621855ed4c5SJohn Baldwin.Pp 622855ed4c5SJohn BaldwinThe 623855ed4c5SJohn Baldwin.Fa vectors 624855ed4c5SJohn Baldwinarray should contain 625855ed4c5SJohn Baldwin.Fa count 626855ed4c5SJohn Baldwinmessage vectors. 627855ed4c5SJohn BaldwinThe array maps directly to the MSI-X table in that the first entry in 628855ed4c5SJohn Baldwinthe array specifies the message used for the first entry in the MSI-X 629855ed4c5SJohn Baldwintable, 630855ed4c5SJohn Baldwinthe second entry in the array corresponds to the second entry in the 631855ed4c5SJohn BaldwinMSI-X table, 632855ed4c5SJohn Baldwinetc. 633855ed4c5SJohn BaldwinThe vector value in each array index can either be zero to indicate 634855ed4c5SJohn Baldwinthat no message should be assigned to the corresponding MSI-X table entry, 635855ed4c5SJohn Baldwinor it can be a number from one to N 636855ed4c5SJohn Baldwin.Po 637855ed4c5SJohn Baldwinwhere N is the count returned from the previous call to 638855ed4c5SJohn Baldwin.Fn pci_alloc_msix 639855ed4c5SJohn Baldwin.Pc 640855ed4c5SJohn Baldwinto indicate which of the allocated messages should be assigned to the 641855ed4c5SJohn Baldwincorresponding MSI-X table entry. 642855ed4c5SJohn Baldwin.Pp 643855ed4c5SJohn BaldwinIf 644855ed4c5SJohn Baldwin.Fn pci_remap_msix 645855ed4c5SJohn Baldwinsucceeds, 646855ed4c5SJohn Baldwineach MSI-X table entry with a non-zero vector will have an associated 647855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 648855ed4c5SJohn Baldwinresource whose resource ID corresponds to the table index as described 649855ed4c5SJohn Baldwinabove for 650855ed4c5SJohn Baldwin.Fn pci_alloc_msix . 651855ed4c5SJohn BaldwinMSI-X table entries that with a vector of zero will not have an 652855ed4c5SJohn Baldwinassociated 653*73bbeaa5SGlen Barber.Dv SYS_RES_IRQ 654*73bbeaa5SGlen Barberresource. 655855ed4c5SJohn BaldwinAdditionally, 656855ed4c5SJohn Baldwinif any of the original messages allocated by 657855ed4c5SJohn Baldwin.Fn pci_alloc_msix 658855ed4c5SJohn Baldwinare not used in the new distribution of messages in the MSI-X table, 659855ed4c5SJohn Baldwinthey will be released automatically. 660855ed4c5SJohn BaldwinNote that if a driver wishes to use fewer messages than were allocated by 661855ed4c5SJohn Baldwin.Fn pci_alloc_msix , 662855ed4c5SJohn Baldwinthe driver must use a single, contiguous range of messages beginning 663855ed4c5SJohn Baldwinwith one in the new distribution. 664855ed4c5SJohn BaldwinThe 665855ed4c5SJohn Baldwin.Fn pci_remap_msix 666855ed4c5SJohn Baldwinfunction will fail if this condition is not met. 667aac0aafaSHiten Pandya.Sh IMPLEMENTATION NOTES 668aac0aafaSHiten PandyaThe 669aac0aafaSHiten Pandya.Vt pci_addr_t 67065bb31b8SRuslan Ermilovtype varies according to the size of the PCI bus address 671aac0aafaSHiten Pandyaspace on the target architecture. 672aac0aafaSHiten Pandya.Sh SEE ALSO 6737c2c06f2SSheldon Hearn.Xr pci 4 , 6747c2c06f2SSheldon Hearn.Xr pciconf 8 , 675aac0aafaSHiten Pandya.Xr bus_alloc_resource 9 , 676aac0aafaSHiten Pandya.Xr bus_dma 9 , 677aac0aafaSHiten Pandya.Xr bus_release_resource 9 , 678aac0aafaSHiten Pandya.Xr bus_setup_intr 9 , 679aac0aafaSHiten Pandya.Xr bus_teardown_intr 9 , 680aac0aafaSHiten Pandya.Xr devclass 9 , 681aac0aafaSHiten Pandya.Xr device 9 , 682aac0aafaSHiten Pandya.Xr driver 9 , 683aac0aafaSHiten Pandya.Xr rman 9 684aac0aafaSHiten Pandya.Rs 685aac0aafaSHiten Pandya.%B FreeBSD Developers' Handbook 686aac0aafaSHiten Pandya.%T NewBus 687aa4a335bSRuslan Ermilov.%U http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/ 688aac0aafaSHiten Pandya.Re 689aac0aafaSHiten Pandya.Rs 690aac0aafaSHiten Pandya.%A Shanley 691aac0aafaSHiten Pandya.%A Anderson 692aac0aafaSHiten Pandya.%B PCI System Architecture 693aac0aafaSHiten Pandya.%N 2nd Edition 694aac0aafaSHiten Pandya.%I Addison-Wesley 695aac0aafaSHiten Pandya.%O ISBN 0-201-30974-2 696aac0aafaSHiten Pandya.Re 697aac0aafaSHiten Pandya.Sh AUTHORS 698571dba6eSHiten PandyaThis manual page was written by 699855ed4c5SJohn Baldwin.An Bruce M Simpson Aq bms@FreeBSD.org 700855ed4c5SJohn Baldwinand 701855ed4c5SJohn Baldwin.An John Baldwin Aq jhb@FreeBSD.org . 702aac0aafaSHiten Pandya.Sh BUGS 7034d80f750SBruce M SimpsonThe kernel PCI code has a number of references to 7044d80f750SBruce M Simpson.Dq "slot numbers" . 705bf1639eeSBruce M SimpsonThese do not refer to the geographic location of PCI devices, 706bf1639eeSBruce M Simpsonbut to the device number assigned by the combination of the PCI IDSEL 707bf1639eeSBruce M Simpsonmechanism and the platform firmware. 708bf1639eeSBruce M SimpsonThis should be taken note of when working with the kernel PCI code. 709