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.\" 28*0aee83ccSJohn Baldwin.Dd August 3, 2016 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 , 4587dd2f95SJohn Baldwin.Nm pci_find_pcie_root_port , 46d7be980dSAndrew Turner.Nm pci_get_id , 472ab0398dSJohn Baldwin.Nm pci_get_max_payload , 48855ed4c5SJohn Baldwin.Nm pci_get_max_read_req , 490a9c80e5SJohn Baldwin.Nm pci_get_powerstate , 50855ed4c5SJohn Baldwin.Nm pci_get_vpd_ident , 51855ed4c5SJohn Baldwin.Nm pci_get_vpd_readonly , 527d971e36SRyan Stone.Nm pci_iov_attach , 53*0aee83ccSJohn Baldwin.Nm pci_iov_attach_name , 547d971e36SRyan Stone.Nm pci_iov_detach , 55855ed4c5SJohn Baldwin.Nm pci_msi_count , 56855ed4c5SJohn Baldwin.Nm pci_msix_count , 57ce204e1bSJohn Baldwin.Nm pci_msix_pba_bar , 58ce204e1bSJohn Baldwin.Nm pci_msix_table_bar , 59855ed4c5SJohn Baldwin.Nm pci_pending_msix , 600a9c80e5SJohn Baldwin.Nm pci_read_config , 61855ed4c5SJohn Baldwin.Nm pci_release_msi , 62855ed4c5SJohn Baldwin.Nm pci_remap_msix , 630a9c80e5SJohn Baldwin.Nm pci_restore_state , 640a9c80e5SJohn Baldwin.Nm pci_save_state , 65855ed4c5SJohn Baldwin.Nm pci_set_max_read_req , 660a9c80e5SJohn Baldwin.Nm pci_set_powerstate , 67ec603c72SJohn Baldwin.Nm pci_write_config , 68ec603c72SJohn Baldwin.Nm pcie_adjust_config , 69ec603c72SJohn Baldwin.Nm pcie_read_config , 70ec603c72SJohn Baldwin.Nm pcie_write_config 71aac0aafaSHiten Pandya.Nd PCI bus interface 72aac0aafaSHiten Pandya.Sh SYNOPSIS 73aac0aafaSHiten Pandya.In sys/bus.h 74aac0aafaSHiten Pandya.In dev/pci/pcireg.h 75855ed4c5SJohn Baldwin.In dev/pci/pcivar.h 76855ed4c5SJohn Baldwin.Ft int 77855ed4c5SJohn Baldwin.Fn pci_alloc_msi "device_t dev" "int *count" 78855ed4c5SJohn Baldwin.Ft int 79855ed4c5SJohn Baldwin.Fn pci_alloc_msix "device_t dev" "int *count" 80aac0aafaSHiten Pandya.Ft int 81aac0aafaSHiten Pandya.Fn pci_disable_busmaster "device_t dev" 82aac0aafaSHiten Pandya.Ft int 83aac0aafaSHiten Pandya.Fn pci_disable_io "device_t dev" "int space" 84aac0aafaSHiten Pandya.Ft int 850a9c80e5SJohn Baldwin.Fn pci_enable_busmaster "device_t dev" 86aac0aafaSHiten Pandya.Ft int 870a9c80e5SJohn Baldwin.Fn pci_enable_io "device_t dev" "int space" 88aac0aafaSHiten Pandya.Ft device_t 8965bb31b8SRuslan Ermilov.Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func" 90855ed4c5SJohn Baldwin.Ft int 91855ed4c5SJohn Baldwin.Fn pci_find_cap "device_t dev" "int capability" "int *capreg" 92aac0aafaSHiten Pandya.Ft device_t 9355aaf894SMarius Strobl.Fn pci_find_dbsf "uint32_t domain" "uint8_t bus" "uint8_t slot" "uint8_t func" 9455aaf894SMarius Strobl.Ft device_t 9565bb31b8SRuslan Ermilov.Fn pci_find_device "uint16_t vendor" "uint16_t device" 960a9c80e5SJohn Baldwin.Ft int 9768bf9717SJohn Baldwin.Fn pci_find_extcap "device_t dev" "int capability" "int *capreg" 9868bf9717SJohn Baldwin.Ft int 9968bf9717SJohn Baldwin.Fn pci_find_htcap "device_t dev" "int capability" "int *capreg" 10087dd2f95SJohn Baldwin.Ft device_t 10187dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port "device_t dev" 10268bf9717SJohn Baldwin.Ft int 103d7be980dSAndrew Turner.Fn pci_get_id "device_t dev" "enum pci_id_type type" "uintptr_t *id" 104d7be980dSAndrew Turner.Ft int 1052ab0398dSJohn Baldwin.Fn pci_get_max_payload "device_t dev" 1062ab0398dSJohn Baldwin.Ft int 107855ed4c5SJohn Baldwin.Fn pci_get_max_read_req "device_t dev" 108855ed4c5SJohn Baldwin.Ft int 1090a9c80e5SJohn Baldwin.Fn pci_get_powerstate "device_t dev" 110855ed4c5SJohn Baldwin.Ft int 111855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident "device_t dev" "const char **identptr" 112855ed4c5SJohn Baldwin.Ft int 113855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly "device_t dev" "const char *kw" "const char **vptr" 114855ed4c5SJohn Baldwin.Ft int 115855ed4c5SJohn Baldwin.Fn pci_msi_count "device_t dev" 116855ed4c5SJohn Baldwin.Ft int 117855ed4c5SJohn Baldwin.Fn pci_msix_count "device_t dev" 118855ed4c5SJohn Baldwin.Ft int 119ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar "device_t dev" 120ce204e1bSJohn Baldwin.Ft int 121ce204e1bSJohn Baldwin.Fn pci_msix_table_bar "device_t dev" 122ce204e1bSJohn Baldwin.Ft int 123855ed4c5SJohn Baldwin.Fn pci_pending_msix "device_t dev" "u_int index" 1240a9c80e5SJohn Baldwin.Ft uint32_t 1250a9c80e5SJohn Baldwin.Fn pci_read_config "device_t dev" "int reg" "int width" 126855ed4c5SJohn Baldwin.Ft int 127855ed4c5SJohn Baldwin.Fn pci_release_msi "device_t dev" 128855ed4c5SJohn Baldwin.Ft int 129855ed4c5SJohn Baldwin.Fn pci_remap_msix "device_t dev" "int count" "const u_int *vectors" 1300a9c80e5SJohn Baldwin.Ft void 1310a9c80e5SJohn Baldwin.Fn pci_restore_state "device_t dev" 1320a9c80e5SJohn Baldwin.Ft void 1330a9c80e5SJohn Baldwin.Fn pci_save_state "device_t dev" 1340a9c80e5SJohn Baldwin.Ft int 135855ed4c5SJohn Baldwin.Fn pci_set_max_read_req "device_t dev" "int size" 136855ed4c5SJohn Baldwin.Ft int 1370a9c80e5SJohn Baldwin.Fn pci_set_powerstate "device_t dev" "int state" 1380a9c80e5SJohn Baldwin.Ft void 1390a9c80e5SJohn Baldwin.Fn pci_write_config "device_t dev" "int reg" "uint32_t val" "int width" 140ec603c72SJohn Baldwin.Ft uint32_t 141ec603c72SJohn Baldwin.Fo pcie_adjust_config 142ec603c72SJohn Baldwin.Fa "device_t dev" 143ec603c72SJohn Baldwin.Fa "int reg" 144ec603c72SJohn Baldwin.Fa "uint32_t mask" 145ec603c72SJohn Baldwin.Fa "uint32_t val" 146ec603c72SJohn Baldwin.Fa "int width" 147ec603c72SJohn Baldwin.Fc 148ec603c72SJohn Baldwin.Ft uint32_t 149ec603c72SJohn Baldwin.Fn pcie_read_config "device_t dev" "int reg" "int width" 150ec603c72SJohn Baldwin.Ft void 151ec603c72SJohn Baldwin.Fn pcie_write_config "device_t dev" "int reg" "uint32_t val" "int width" 152f3bb9251SJohn Baldwin.In dev/pci/pci_iov.h 153f3bb9251SJohn Baldwin.Ft int 154f3bb9251SJohn Baldwin.Fn pci_iov_attach "device_t dev" "nvlist_t *pf_schema" "nvlist_t *vf_schema" 155f3bb9251SJohn Baldwin.Ft int 156*0aee83ccSJohn Baldwin.Fo pci_iov_attach_name 157*0aee83ccSJohn Baldwin.Fa "device_t dev" 158*0aee83ccSJohn Baldwin.Fa "nvlist_t *pf_schema" 159*0aee83ccSJohn Baldwin.Fa "nvlist_t *vf_schema" 160*0aee83ccSJohn Baldwin.Fa "const char *fmt" 161*0aee83ccSJohn Baldwin.Fa "..." 162*0aee83ccSJohn Baldwin.Fc 163*0aee83ccSJohn Baldwin.Ft int 164f3bb9251SJohn Baldwin.Fn pci_iov_detach "device_t dev" 165aac0aafaSHiten Pandya.Sh DESCRIPTION 166aac0aafaSHiten PandyaThe 167aac0aafaSHiten Pandya.Nm 168aac0aafaSHiten Pandyaset of functions are used for managing PCI devices. 169855ed4c5SJohn BaldwinThe functions are split into several groups: 170855ed4c5SJohn Baldwinraw configuration access, 171855ed4c5SJohn Baldwinlocating devices, 172855ed4c5SJohn Baldwindevice information, 173855ed4c5SJohn Baldwindevice configuration, 174855ed4c5SJohn Baldwinand 175855ed4c5SJohn Baldwinmessage signaled interrupts. 176855ed4c5SJohn Baldwin.Ss Raw Configuration Access 177aac0aafaSHiten PandyaThe 178aac0aafaSHiten Pandya.Fn pci_read_config 179aac0aafaSHiten Pandyafunction is used to read data from the PCI configuration 180aac0aafaSHiten Pandyaspace of the device 181aac0aafaSHiten Pandya.Fa dev , 182aac0aafaSHiten Pandyaat offset 183aac0aafaSHiten Pandya.Fa reg , 184aac0aafaSHiten Pandyawith 185aac0aafaSHiten Pandya.Fa width 186aac0aafaSHiten Pandyaspecifying the size of the access. 187aac0aafaSHiten Pandya.Pp 188aac0aafaSHiten PandyaThe 189aac0aafaSHiten Pandya.Fn pci_write_config 190aac0aafaSHiten Pandyafunction is used to write the value 191aac0aafaSHiten Pandya.Fa val 192aac0aafaSHiten Pandyato the PCI configuration 193aac0aafaSHiten Pandyaspace of the device 194aac0aafaSHiten Pandya.Fa dev , 195aac0aafaSHiten Pandyaat offset 196aac0aafaSHiten Pandya.Fa reg , 197aac0aafaSHiten Pandyawith 198aac0aafaSHiten Pandya.Fa width 199aac0aafaSHiten Pandyaspecifying the size of the access. 200aac0aafaSHiten Pandya.Pp 201ec603c72SJohn BaldwinThe 202ec603c72SJohn Baldwin.Fn pcie_adjust_config 203ec603c72SJohn Baldwinfunction is used to modify the value of a register in the PCI-express 204ec603c72SJohn Baldwincapability register set of device 205ec603c72SJohn Baldwin.Fa dev . 206ec603c72SJohn BaldwinThe offset 207ec603c72SJohn Baldwin.Fa reg 208ec603c72SJohn Baldwinspecifies a relative offset in the register set with 209ec603c72SJohn Baldwin.Fa width 210ec603c72SJohn Baldwinspecifying the size of the access. 211ec603c72SJohn BaldwinThe new value of the register is computed by modifying bits set in 212ec603c72SJohn Baldwin.Fa mask 213ec603c72SJohn Baldwinto the value in 214ec603c72SJohn Baldwin.Fa val . 215ec603c72SJohn BaldwinAny bits not specified in 216ec603c72SJohn Baldwin.Fa mask 217ec603c72SJohn Baldwinare preserved. 218ec603c72SJohn BaldwinThe previous value of the register is returned. 219ec603c72SJohn Baldwin.Pp 220ec603c72SJohn BaldwinThe 221ec603c72SJohn Baldwin.Fn pcie_read_config 222ec603c72SJohn Baldwinfunction is used to read the value of a register in the PCI-express 223ec603c72SJohn Baldwincapability register set of device 224ec603c72SJohn Baldwin.Fa dev . 225ec603c72SJohn BaldwinThe offset 226ec603c72SJohn Baldwin.Fa reg 227ec603c72SJohn Baldwinspecifies a relative offset in the register set with 228ec603c72SJohn Baldwin.Fa width 229ec603c72SJohn Baldwinspecifying the size of the access. 230ec603c72SJohn Baldwin.Pp 231ec603c72SJohn BaldwinThe 232ec603c72SJohn Baldwin.Fn pcie_write_config 233ec603c72SJohn Baldwinfunction is used to write the value 234ec603c72SJohn Baldwin.Fa val 235ec603c72SJohn Baldwinto a register in the PCI-express capability register set of device 236ec603c72SJohn Baldwin.Fa dev . 237ec603c72SJohn BaldwinThe offset 238ec603c72SJohn Baldwin.Fa reg 239ec603c72SJohn Baldwinspecifies a relative offset in the register set with 240ec603c72SJohn Baldwin.Fa width 241ec603c72SJohn Baldwinspecifying the size of the access. 242ec603c72SJohn Baldwin.Pp 243855ed4c5SJohn Baldwin.Em NOTE : 244855ed4c5SJohn BaldwinDevice drivers should only use these functions for functionality that 245855ed4c5SJohn Baldwinis not available via another 246855ed4c5SJohn Baldwin.Fn pci 247855ed4c5SJohn Baldwinfunction. 248855ed4c5SJohn Baldwin.Ss Locating Devices 249855ed4c5SJohn BaldwinThe 250855ed4c5SJohn Baldwin.Fn pci_find_bsf 251855ed4c5SJohn Baldwinfunction looks up the 252855ed4c5SJohn Baldwin.Vt device_t 253855ed4c5SJohn Baldwinof a PCI device, given its 254855ed4c5SJohn Baldwin.Fa bus , 255855ed4c5SJohn Baldwin.Fa slot , 256855ed4c5SJohn Baldwinand 257855ed4c5SJohn Baldwin.Fa func . 258855ed4c5SJohn BaldwinThe 259855ed4c5SJohn Baldwin.Fa slot 260855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus, 261855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location 262855ed4c5SJohn Baldwinin terms of a physical slot. 263855ed4c5SJohn BaldwinNote that in case the system has multiple PCI domains, 264855ed4c5SJohn Baldwinthe 265855ed4c5SJohn Baldwin.Fn pci_find_bsf 266855ed4c5SJohn Baldwinfunction only searches the first one. 267855ed4c5SJohn BaldwinActually, it is equivalent to: 268855ed4c5SJohn Baldwin.Bd -literal -offset indent 269855ed4c5SJohn Baldwinpci_find_dbsf(0, bus, slot, func); 270855ed4c5SJohn Baldwin.Ed 271855ed4c5SJohn Baldwin.Pp 272855ed4c5SJohn BaldwinThe 273855ed4c5SJohn Baldwin.Fn pci_find_dbsf 274855ed4c5SJohn Baldwinfunction looks up the 275855ed4c5SJohn Baldwin.Vt device_t 276855ed4c5SJohn Baldwinof a PCI device, given its 277855ed4c5SJohn Baldwin.Fa domain , 278855ed4c5SJohn Baldwin.Fa bus , 279855ed4c5SJohn Baldwin.Fa slot , 280855ed4c5SJohn Baldwinand 281855ed4c5SJohn Baldwin.Fa func . 282855ed4c5SJohn BaldwinThe 283855ed4c5SJohn Baldwin.Fa slot 284855ed4c5SJohn Baldwinnumber actually refers to the number of the device on the bus, 285855ed4c5SJohn Baldwinwhich does not necessarily indicate its geographic location 286855ed4c5SJohn Baldwinin terms of a physical slot. 287855ed4c5SJohn Baldwin.Pp 288855ed4c5SJohn BaldwinThe 289855ed4c5SJohn Baldwin.Fn pci_find_device 290855ed4c5SJohn Baldwinfunction looks up the 291855ed4c5SJohn Baldwin.Vt device_t 292855ed4c5SJohn Baldwinof a PCI device, given its 293855ed4c5SJohn Baldwin.Fa vendor 294855ed4c5SJohn Baldwinand 295855ed4c5SJohn Baldwin.Fa device 296855ed4c5SJohn BaldwinIDs. 297855ed4c5SJohn BaldwinNote that there can be multiple matches for this search; this function 298855ed4c5SJohn Baldwinonly returns the first matching device. 299855ed4c5SJohn Baldwin.Ss Device Information 300855ed4c5SJohn BaldwinThe 301855ed4c5SJohn Baldwin.Fn pci_find_cap 302855ed4c5SJohn Baldwinfunction is used to locate the first instance of a PCI capability 303855ed4c5SJohn Baldwinregister set for the device 304855ed4c5SJohn Baldwin.Fa dev . 305855ed4c5SJohn BaldwinThe capability to locate is specified by ID via 306855ed4c5SJohn Baldwin.Fa capability . 307855ed4c5SJohn BaldwinConstant macros of the form 308855ed4c5SJohn Baldwin.Dv PCIY_xxx 309855ed4c5SJohn Baldwinfor standard capability IDs are defined in 310855ed4c5SJohn Baldwin.In dev/pci/pcireg.h . 311855ed4c5SJohn BaldwinIf the capability is found, then 312855ed4c5SJohn Baldwin.Fa *capreg 313281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set, 314855ed4c5SJohn Baldwinand 315855ed4c5SJohn Baldwin.Fn pci_find_cap 316855ed4c5SJohn Baldwinreturns zero. 317855ed4c5SJohn BaldwinIf the capability is not found or the device does not support capabilities, 318855ed4c5SJohn Baldwin.Fn pci_find_cap 319855ed4c5SJohn Baldwinreturns an error. 320855ed4c5SJohn Baldwin.Pp 321855ed4c5SJohn BaldwinThe 32268bf9717SJohn Baldwin.Fn pci_find_extcap 32368bf9717SJohn Baldwinfunction is used to locate the first instance of a PCI-express 32468bf9717SJohn Baldwinextended capability register set for the device 32568bf9717SJohn Baldwin.Fa dev . 32668bf9717SJohn BaldwinThe extended capability to locate is specified by ID via 32768bf9717SJohn Baldwin.Fa capability . 32868bf9717SJohn BaldwinConstant macros of the form 32968bf9717SJohn Baldwin.Dv PCIZ_xxx 33068bf9717SJohn Baldwinfor standard extended capability IDs are defined in 33168bf9717SJohn Baldwin.In dev/pci/pcireg.h . 33268bf9717SJohn BaldwinIf the extended capability is found, then 33368bf9717SJohn Baldwin.Fa *capreg 334281a359eSJohn Baldwinis set to the offset in configuration space of the extended capability 33568bf9717SJohn Baldwinregister set, and 33668bf9717SJohn Baldwin.Fn pci_find_extcap 33768bf9717SJohn Baldwinreturns zero. 33868bf9717SJohn BaldwinIf the extended capability is not found or the device is not a 33968bf9717SJohn BaldwinPCI-express device, 34068bf9717SJohn Baldwin.Fn pci_find_extcap 34168bf9717SJohn Baldwinreturns an error. 34268bf9717SJohn Baldwin.Pp 34368bf9717SJohn BaldwinThe 34468bf9717SJohn Baldwin.Fn pci_find_htcap 34568bf9717SJohn Baldwinfunction is used to locate the first instance of a HyperTransport capability 34668bf9717SJohn Baldwinregister set for the device 34768bf9717SJohn Baldwin.Fa dev . 34868bf9717SJohn BaldwinThe capability to locate is specified by type via 34968bf9717SJohn Baldwin.Fa capability . 35068bf9717SJohn BaldwinConstant macros of the form 35168bf9717SJohn Baldwin.Dv PCIM_HTCAP_xxx 35268bf9717SJohn Baldwinfor standard HyperTransport capability types are defined in 35368bf9717SJohn Baldwin.In dev/pci/pcireg.h . 35468bf9717SJohn BaldwinIf the capability is found, then 35568bf9717SJohn Baldwin.Fa *capreg 356281a359eSJohn Baldwinis set to the offset in configuration space of the capability register set, 35768bf9717SJohn Baldwinand 35868bf9717SJohn Baldwin.Fn pci_find_htcap 35968bf9717SJohn Baldwinreturns zero. 36068bf9717SJohn BaldwinIf the capability is not found or the device is not a HyperTransport device, 36168bf9717SJohn Baldwin.Fn pci_find_htcap 36268bf9717SJohn Baldwinreturns an error. 36368bf9717SJohn Baldwin.Pp 36468bf9717SJohn BaldwinThe 36587dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port 36687dd2f95SJohn Baldwinfunction walks up the PCI device hierarchy to locate the PCI-express root 36787dd2f95SJohn Baldwinport upstream of 36887dd2f95SJohn Baldwin.Fa dev . 36987dd2f95SJohn BaldwinIf a root port is not found, 37087dd2f95SJohn Baldwin.Fn pci_find_pcie_root_port 37187dd2f95SJohn Baldwinreturns 37287dd2f95SJohn Baldwin.Dv NULL . 37387dd2f95SJohn Baldwin.Pp 37487dd2f95SJohn BaldwinThe 375d7be980dSAndrew Turner.Fn pci_get_id 376d7be980dSAndrew Turnerfunction is used to read an identifier from a device. 377d7be980dSAndrew TurnerThe 378d7be980dSAndrew Turner.Fa type 379d7be980dSAndrew Turnerflag is used to specify which identifier to read. 380d7be980dSAndrew TurnerThe following flags are supported: 381d7be980dSAndrew Turner.Bl -hang -width ".Dv PCI_ID_RID" 382d7be980dSAndrew Turner.It Dv PCI_ID_RID 383d7be980dSAndrew TurnerRead the routing identifier for the device. 3841e43b18cSAndrew Turner.It Dv PCI_ID_MSI 3851e43b18cSAndrew TurnerRead the MSI routing ID. 3861e43b18cSAndrew TurnerThis is needed by some interrupt controllers to route MSI and MSI-X interrupts. 387d7be980dSAndrew Turner.El 388d7be980dSAndrew Turner.Pp 389d7be980dSAndrew TurnerThe 390855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident 391855ed4c5SJohn Baldwinfunction is used to fetch a device's Vital Product Data 392855ed4c5SJohn Baldwin.Pq VPD 393855ed4c5SJohn Baldwinidentifier string. 394855ed4c5SJohn BaldwinIf the device 395855ed4c5SJohn Baldwin.Fa dev 396855ed4c5SJohn Baldwinsupports VPD and provides an identifier string, 397855ed4c5SJohn Baldwinthen 398855ed4c5SJohn Baldwin.Fa *identptr 399855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the identifier 400855ed4c5SJohn Baldwinstring, 401855ed4c5SJohn Baldwinand 402855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident 403855ed4c5SJohn Baldwinreturns zero. 404855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide an identifier 405855ed4c5SJohn Baldwinstring, 406855ed4c5SJohn Baldwinthen 407855ed4c5SJohn Baldwin.Fn pci_get_vpd_ident 408855ed4c5SJohn Baldwinreturns an error. 409855ed4c5SJohn Baldwin.Pp 410855ed4c5SJohn BaldwinThe 411855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly 412855ed4c5SJohn Baldwinfunction is used to fetch the value of a single VPD read-only keyword 413855ed4c5SJohn Baldwinfor the device 414855ed4c5SJohn Baldwin.Fa dev . 415855ed4c5SJohn BaldwinThe keyword to fetch is identified by the two character string 416855ed4c5SJohn Baldwin.Fa kw . 417855ed4c5SJohn BaldwinIf the device supports VPD and provides a read-only value for the 418855ed4c5SJohn Baldwinrequested keyword, 419855ed4c5SJohn Baldwinthen 420855ed4c5SJohn Baldwin.Fa *vptr 421855ed4c5SJohn Baldwinis set to point at a read-only, null-terminated copy of the value, 422855ed4c5SJohn Baldwinand 423855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly 424855ed4c5SJohn Baldwinreturns zero. 425855ed4c5SJohn BaldwinIf the device does not support VPD or does not provide the requested 426855ed4c5SJohn Baldwinkeyword, 427855ed4c5SJohn Baldwinthen 428855ed4c5SJohn Baldwin.Fn pci_get_vpd_readonly 429855ed4c5SJohn Baldwinreturns an error. 430855ed4c5SJohn Baldwin.Ss Device Configuration 431aac0aafaSHiten PandyaThe 432aac0aafaSHiten Pandya.Fn pci_enable_busmaster 433aac0aafaSHiten Pandyafunction enables PCI bus mastering for the device 434aac0aafaSHiten Pandya.Fa dev , 435aac0aafaSHiten Pandyaby setting the 436aac0aafaSHiten Pandya.Dv PCIM_CMD_BUSMASTEREN 437aac0aafaSHiten Pandyabit in the 438aac0aafaSHiten Pandya.Dv PCIR_COMMAND 439aac0aafaSHiten Pandyaregister. 440aac0aafaSHiten PandyaThe 441aac0aafaSHiten Pandya.Fn pci_disable_busmaster 442aac0aafaSHiten Pandyafunction clears this bit. 443aac0aafaSHiten Pandya.Pp 444aac0aafaSHiten PandyaThe 445aac0aafaSHiten Pandya.Fn pci_enable_io 446aac0aafaSHiten Pandyafunction enables memory or I/O port address decoding for the device 447aac0aafaSHiten Pandya.Fa dev , 448aac0aafaSHiten Pandyaby setting the 449aac0aafaSHiten Pandya.Dv PCIM_CMD_MEMEN 450aac0aafaSHiten Pandyaor 451aac0aafaSHiten Pandya.Dv PCIM_CMD_PORTEN 452aac0aafaSHiten Pandyabit in the 453aac0aafaSHiten Pandya.Dv PCIR_COMMAND 4545203edcdSRuslan Ermilovregister appropriately. 4555203edcdSRuslan ErmilovThe 456aac0aafaSHiten Pandya.Fn pci_disable_io 457aac0aafaSHiten Pandyafunction clears the appropriate bit. 458aac0aafaSHiten PandyaThe 45965bb31b8SRuslan Ermilov.Fa space 460aac0aafaSHiten Pandyaargument specifies which resource is affected; this can be either 461aac0aafaSHiten Pandya.Dv SYS_RES_MEMORY 462aac0aafaSHiten Pandyaor 463aac0aafaSHiten Pandya.Dv SYS_RES_IOPORT 464aac0aafaSHiten Pandyaas appropriate. 465855ed4c5SJohn BaldwinDevice drivers should generally not use these routines directly. 466855ed4c5SJohn BaldwinThe PCI bus will enable decoding automatically when a 467855ed4c5SJohn Baldwin.Dv SYS_RES_MEMORY 468855ed4c5SJohn Baldwinor 469855ed4c5SJohn Baldwin.Dv SYS_RES_IOPORT 470855ed4c5SJohn Baldwinresource is activated via 471855ed4c5SJohn Baldwin.Xr bus_alloc_resource 9 472855ed4c5SJohn Baldwinor 473855ed4c5SJohn Baldwin.Xr bus_activate_resource 9 . 474aac0aafaSHiten Pandya.Pp 475855ed4c5SJohn BaldwinThe 4762ab0398dSJohn Baldwin.Fn pci_get_max_payload 4772ab0398dSJohn Baldwinfunction returns the current maximum TLP payload size in bytes for a 4782ab0398dSJohn BaldwinPCI-express device. 4792ab0398dSJohn BaldwinIf the 4802ab0398dSJohn Baldwin.Fa dev 4812ab0398dSJohn Baldwindevice is not a PCI-express device, 4822ab0398dSJohn Baldwin.Fn pci_get_max_payload 4832ab0398dSJohn Baldwinreturns zero. 4842ab0398dSJohn Baldwin.Pp 4852ab0398dSJohn BaldwinThe 486855ed4c5SJohn Baldwin.Fn pci_get_max_read_req 487855ed4c5SJohn Baldwinfunction returns the current maximum read request size in bytes for a 488855ed4c5SJohn BaldwinPCI-express device. 489855ed4c5SJohn BaldwinIf the 490855ed4c5SJohn Baldwin.Fa dev 491855ed4c5SJohn Baldwindevice is not a PCI-express device, 492855ed4c5SJohn Baldwin.Fn pci_get_max_read_req 493855ed4c5SJohn Baldwinreturns zero. 494855ed4c5SJohn Baldwin.Pp 495855ed4c5SJohn BaldwinThe 496855ed4c5SJohn Baldwin.Fn pci_set_max_read_req 497855ed4c5SJohn Baldwinsets the PCI-express maximum read request size for 498855ed4c5SJohn Baldwin.Fa dev . 499855ed4c5SJohn BaldwinThe requested 500855ed4c5SJohn Baldwin.Fa size 501855ed4c5SJohn Baldwinmay be adjusted, 502855ed4c5SJohn Baldwinand 503855ed4c5SJohn Baldwin.Fn pci_set_max_read_req 504855ed4c5SJohn Baldwinreturns the actual size set in bytes. 505855ed4c5SJohn BaldwinIf the 506855ed4c5SJohn Baldwin.Fa dev 507855ed4c5SJohn Baldwindevice is not a PCI-express device, 508855ed4c5SJohn Baldwin.Fn pci_set_max_read_req 509855ed4c5SJohn Baldwinreturns zero. 510aac0aafaSHiten Pandya.Pp 511aac0aafaSHiten PandyaThe 512aac0aafaSHiten Pandya.Fn pci_get_powerstate 513adb63907SJohn Baldwinfunction returns the current power state of the device 514aac0aafaSHiten Pandya.Fa dev . 515aac0aafaSHiten PandyaIf the device does not support power management capabilities, then the default 516aac0aafaSHiten Pandyastate of 517aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D0 518aac0aafaSHiten Pandyais returned. 519adb63907SJohn BaldwinThe following power states are defined by PCI: 52065bb31b8SRuslan Ermilov.Bl -hang -width ".Dv PCI_POWERSTATE_UNKNOWN" 521aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D0 522aac0aafaSHiten PandyaState in which device is on and running. 523aac0aafaSHiten PandyaIt is receiving full power from the system and delivering 524aac0aafaSHiten Pandyafull functionality to the user. 525aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D1 526aac0aafaSHiten PandyaClass-specific low-power state in which device context may or 5275a2e3b61SDaniel Gerzomay not be lost. 52865bb31b8SRuslan ErmilovBusses in this state cannot do anything to the bus, to 5299817b894SBruce M Simpsonforce devices to lose context. 530aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D2 531aac0aafaSHiten PandyaClass-specific low-power state in which device context may or 532aac0aafaSHiten Pandyamay not be lost. 533aac0aafaSHiten PandyaAttains greater power savings than 534aac0aafaSHiten Pandya.Dv PCI_POWERSTATE_D1 . 53565bb31b8SRuslan ErmilovBusses in this state can cause devices to lose some context. 536aac0aafaSHiten PandyaDevices 537aac0aafaSHiten Pandya.Em must 538aac0aafaSHiten Pandyabe prepared for the bus to be in this state or higher. 539aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_D3 540aac0aafaSHiten PandyaState in which the device is off and not running. 541aac0aafaSHiten PandyaDevice context is lost, and power from the device can 542aac0aafaSHiten Pandyabe removed. 543aac0aafaSHiten Pandya.It Dv PCI_POWERSTATE_UNKNOWN 544aac0aafaSHiten PandyaState of the device is unknown. 545aac0aafaSHiten Pandya.El 546aac0aafaSHiten Pandya.Pp 547aac0aafaSHiten PandyaThe 548aac0aafaSHiten Pandya.Fn pci_set_powerstate 549aac0aafaSHiten Pandyafunction is used to transition the device 550aac0aafaSHiten Pandya.Fa dev 551adb63907SJohn Baldwinto the PCI power state 552aac0aafaSHiten Pandya.Fa state . 553adb63907SJohn BaldwinIf the device does not support power management capabilities or 554adb63907SJohn Baldwinit does not support the specific power state 555adb63907SJohn Baldwin.Fa state , 556adb63907SJohn Baldwinthen the function will fail with 557adb63907SJohn Baldwin.Er EOPNOTSUPP . 558aac0aafaSHiten Pandya.Pp 559aac0aafaSHiten PandyaThe 5607d971e36SRyan Stone.Fn pci_iov_attach 5617d971e36SRyan Stonefunction is used to advertise that the given device 5627d971e36SRyan Stone.Pq and associated device driver 5637d971e36SRyan Stonesupports PCI Single-Root I/O Virtualization 564fe3ff217SPatrick Kelsey.Pq SR-IOV . 5657d971e36SRyan StoneA driver that supports SR-IOV must implement the 566f3bb9251SJohn Baldwin.Xr PCI_IOV_INIT 9 , 567f3bb9251SJohn Baldwin.Xr PCI_IOV_ADD_VF 9 5687d971e36SRyan Stoneand 569f3bb9251SJohn Baldwin.Xr PCI_IOV_UNINIT 9 5707d971e36SRyan Stonemethods. 5717d971e36SRyan StoneThis function should be called during the 5727d971e36SRyan Stone.Xr DEVICE_ATTACH 9 5737d971e36SRyan Stonemethod. 5747d971e36SRyan StoneIf this function returns an error, it is recommended that the device driver 5757d971e36SRyan Stonestill successfully attaches, but runs with SR-IOV disabled. 5767d971e36SRyan StoneThe 5777d971e36SRyan Stone.Fa pf_schema 5787d971e36SRyan Stoneand 5797d971e36SRyan Stone.Fa vf_schema 5807d971e36SRyan Stoneparameters are used to define what device-specific configuration parameters the 5817d971e36SRyan Stonedevice driver accepts when SR-IOV is enabled for the Physical Function 5827d971e36SRyan Stone.Pq PF 5837d971e36SRyan Stoneand for individual Virtual Functions 5847d971e36SRyan Stone.Pq VFs 5857d971e36SRyan Stonerespectively. 5867d971e36SRyan StoneSee 5877d971e36SRyan Stone.Xr pci_iov_schema 9 5887d971e36SRyan Stonefor details on how to construct the schema. 5897d971e36SRyan StoneIf either the 5907d971e36SRyan Stone.Pa pf_schema 5917d971e36SRyan Stoneor 5927d971e36SRyan Stone.Pa vf_schema 5937d971e36SRyan Stoneis invalid or specifies parameter names that conflict with parameter names that 5947d971e36SRyan Stoneare already in use, 5957d971e36SRyan Stone.Fn pci_iov_attach 5967d971e36SRyan Stonewill return an error and SR-IOV will not be available on the PF device. 5977d971e36SRyan StoneIf a driver does not accept configuration parameters for either the PF device 5987d971e36SRyan Stoneor the VF devices, the driver must pass an empty schema for that device. 5997d971e36SRyan StoneThe SR-IOV infrastructure takes ownership of the 6007d971e36SRyan Stone.Fa pf_schema 6017d971e36SRyan Stoneand 6027d971e36SRyan Stone.Fa vf_schema 6037d971e36SRyan Stoneand is responsible for freeing them. 6047d971e36SRyan StoneThe driver must never free the schemas itself. 6057d971e36SRyan Stone.Pp 6067d971e36SRyan StoneThe 607*0aee83ccSJohn Baldwin.Fn pci_iov_attach_name 608*0aee83ccSJohn Baldwinfunction is a variant of 609*0aee83ccSJohn Baldwin.Fn pci_iov_attach 610*0aee83ccSJohn Baldwinthat allows the name of the associated character device in 611*0aee83ccSJohn Baldwin.Pa /dev/iov 612*0aee83ccSJohn Baldwinto be specified by 613*0aee83ccSJohn Baldwin.Fa fmt . 614*0aee83ccSJohn BaldwinThe 615*0aee83ccSJohn Baldwin.Fn pci_iov_attach 616*0aee83ccSJohn Baldwinfunction uses the name of 617*0aee83ccSJohn Baldwin.Fa dev 618*0aee83ccSJohn Baldwinas the device name. 619*0aee83ccSJohn Baldwin.Pp 620*0aee83ccSJohn BaldwinThe 6217d971e36SRyan Stone.Fn pci_iov_detach 6227d971e36SRyan Stonefunction is used to advise the SR-IOV infrastructure that the driver for the 6237d971e36SRyan Stonegiven device is attempting to detach and that all SR-IOV resources for the 6247d971e36SRyan Stonedevice must be released. 6257d971e36SRyan StoneThis function must be called during the 6267d971e36SRyan Stone.Xr DEVICE_DETACH 9 6277d971e36SRyan Stonemethod if 6287d971e36SRyan Stone.Fn pci_iov_attach 6297d971e36SRyan Stonewas successfully called on the device and 6307d971e36SRyan Stone.Fn pci_iov_detach 6317d971e36SRyan Stonehas not subsequently been called on the device and returned no error. 6327d971e36SRyan StoneIf this function returns an error, the 6337d971e36SRyan Stone.Xr DEVICE_DETACH 9 6347d971e36SRyan Stonemethod must fail and return an error, as detaching the PF driver while VF 6357d971e36SRyan Stonedevices are active would cause system instability. 6367d971e36SRyan StoneThis function is safe to call and will always succeed if 6377d971e36SRyan Stone.Fn pci_iov_attach 6387d971e36SRyan Stonepreviously failed with an error on the given device, or if 6397d971e36SRyan Stone.Fn pci_iov_attach 6407d971e36SRyan Stonewas never called on the device. 6417d971e36SRyan Stone.Pp 6427d971e36SRyan StoneThe 6439415d1e0SJohn Baldwin.Fn pci_save_state 6449415d1e0SJohn Baldwinand 6459415d1e0SJohn Baldwin.Fn pci_restore_state 6469415d1e0SJohn Baldwinfunctions can be used by a device driver to save and restore standard PCI 6479415d1e0SJohn Baldwinconfig registers. 6489415d1e0SJohn BaldwinThe 6499415d1e0SJohn Baldwin.Fn pci_save_state 6509415d1e0SJohn Baldwinfunction must be invoked while the device has valid state before 6519415d1e0SJohn Baldwin.Fn pci_restore_state 6529415d1e0SJohn Baldwincan be used. 6539415d1e0SJohn BaldwinIf the device is not in the fully-powered state 6549415d1e0SJohn Baldwin.Pq Dv PCI_POWERSTATE_D0 6559415d1e0SJohn Baldwinwhen 6569415d1e0SJohn Baldwin.Fn pci_restore_state 6579415d1e0SJohn Baldwinis invoked, 6589415d1e0SJohn Baldwinthen the device will be transitioned to 6599415d1e0SJohn Baldwin.Dv PCI_POWERSTATE_D0 6609415d1e0SJohn Baldwinbefore any config registers are restored. 661855ed4c5SJohn Baldwin.Ss Message Signaled Interrupts 662855ed4c5SJohn BaldwinMessage Signaled Interrupts 663855ed4c5SJohn Baldwin.Pq MSI 664855ed4c5SJohn Baldwinand 665855ed4c5SJohn BaldwinEnhanced Message Signaled Interrupts 666855ed4c5SJohn Baldwin.Pq MSI-X 667855ed4c5SJohn Baldwinare PCI capabilities that provide an alternate method for PCI 668855ed4c5SJohn Baldwindevices to signal interrupts. 669855ed4c5SJohn BaldwinThe legacy INTx interrupt is available to PCI devices as a 670855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 671855ed4c5SJohn Baldwinresource with a resource ID of zero. 672855ed4c5SJohn BaldwinMSI and MSI-X interrupts are available to PCI devices as one or more 673855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 674855ed4c5SJohn Baldwinresources with resource IDs greater than zero. 675855ed4c5SJohn BaldwinA driver must ask the PCI bus to allocate MSI or MSI-X interrupts 676855ed4c5SJohn Baldwinusing 677855ed4c5SJohn Baldwin.Fn pci_alloc_msi 678855ed4c5SJohn Baldwinor 679855ed4c5SJohn Baldwin.Fn pci_alloc_msix 680855ed4c5SJohn Baldwinbefore it can use MSI or MSI-X 681855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 682855ed4c5SJohn Baldwinresources. 683855ed4c5SJohn BaldwinA driver is not allowed to use the legacy INTx 684855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 685855ed4c5SJohn Baldwinresource if MSI or MSI-X interrupts have been allocated, 686855ed4c5SJohn Baldwinand attempts to allocate MSI or MSI-X interrupts will fail if the 687855ed4c5SJohn Baldwindriver is currently using the legacy INTx 688855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 689855ed4c5SJohn Baldwinresource. 690855ed4c5SJohn BaldwinA driver is only allowed to use either MSI or MSI-X, 691855ed4c5SJohn Baldwinbut not both. 6929415d1e0SJohn Baldwin.Pp 6939415d1e0SJohn BaldwinThe 694563d4639SMark Johnston.Fn pci_msi_count 695855ed4c5SJohn Baldwinfunction returns the maximum number of MSI messages supported by the 696855ed4c5SJohn Baldwindevice 697855ed4c5SJohn Baldwin.Fa dev . 698855ed4c5SJohn BaldwinIf the device does not support MSI, 699855ed4c5SJohn Baldwinthen 700563d4639SMark Johnston.Fn pci_msi_count 701855ed4c5SJohn Baldwinreturns zero. 70255aaf894SMarius Strobl.Pp 70355aaf894SMarius StroblThe 704855ed4c5SJohn Baldwin.Fn pci_alloc_msi 705855ed4c5SJohn Baldwinfunction attempts to allocate 706855ed4c5SJohn Baldwin.Fa *count 707855ed4c5SJohn BaldwinMSI messages for the device 708855ed4c5SJohn Baldwin.Fa dev . 70955aaf894SMarius StroblThe 710855ed4c5SJohn Baldwin.Fn pci_alloc_msi 711855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various 712855ed4c5SJohn Baldwinreasons including requests for more messages than the device 713855ed4c5SJohn Baldwin.Fa dev 714855ed4c5SJohn Baldwinsupports, 715855ed4c5SJohn Baldwinor if the system has a shortage of available MSI messages. 716855ed4c5SJohn BaldwinOn success, 717855ed4c5SJohn Baldwin.Fa *count 718855ed4c5SJohn Baldwinis set to the number of messages allocated and 719855ed4c5SJohn Baldwin.Fn pci_alloc_msi 720855ed4c5SJohn Baldwinreturns zero. 721855ed4c5SJohn BaldwinThe 722855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 723855ed4c5SJohn Baldwinresources for the allocated messages will be available at consecutive 724855ed4c5SJohn Baldwinresource IDs beginning with one. 725855ed4c5SJohn BaldwinIf 726855ed4c5SJohn Baldwin.Fn pci_alloc_msi 727855ed4c5SJohn Baldwinis not able to allocate any messages, 728855ed4c5SJohn Baldwinit returns an error. 729855ed4c5SJohn BaldwinNote that MSI only supports message counts that are powers of two; 730855ed4c5SJohn Baldwinrequests to allocate a non-power of two count of messages will fail. 731aac0aafaSHiten Pandya.Pp 732aac0aafaSHiten PandyaThe 733855ed4c5SJohn Baldwin.Fn pci_release_msi 734855ed4c5SJohn Baldwinfunction is used to release any allocated MSI or MSI-X messages back 735855ed4c5SJohn Baldwinto the system. 736855ed4c5SJohn BaldwinIf any MSI or MSI-X 737855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 738855ed4c5SJohn Baldwinresources are allocated by the driver or have a configured interrupt 739855ed4c5SJohn Baldwinhandler, 740855ed4c5SJohn Baldwinthis function will fail with 741855ed4c5SJohn Baldwin.Er EBUSY . 742855ed4c5SJohn BaldwinThe 743855ed4c5SJohn Baldwin.Fn pci_release_msi 744855ed4c5SJohn Baldwinfunction returns zero on success and an error on failure. 745855ed4c5SJohn Baldwin.Pp 746642c4993SSergey KandaurovThe 747563d4639SMark Johnston.Fn pci_msix_count 748855ed4c5SJohn Baldwinfunction returns the maximum number of MSI-X messages supported by the 749855ed4c5SJohn Baldwindevice 750855ed4c5SJohn Baldwin.Fa dev . 751855ed4c5SJohn BaldwinIf the device does not support MSI-X, 752855ed4c5SJohn Baldwinthen 753563d4639SMark Johnston.Fn pci_msix_count 754855ed4c5SJohn Baldwinreturns zero. 755855ed4c5SJohn Baldwin.Pp 756855ed4c5SJohn BaldwinThe 757ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar 758ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the Base Address Register 759ce204e1bSJohn Baldwin.Pq BAR 760ce204e1bSJohn Baldwincontaining the MSI-X Pending Bit Array (PBA) for device 761ce204e1bSJohn Baldwin.Fa dev . 762ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with 763ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9 764ce204e1bSJohn Baldwinand 765ce204e1bSJohn Baldwin.Xr bus_release_resource 9 766ce204e1bSJohn Baldwinto allocate the BAR. 767ce204e1bSJohn BaldwinIf the device does not support MSI-X, 768ce204e1bSJohn Baldwinthen 769ce204e1bSJohn Baldwin.Fn pci_msix_pba_bar 770ce204e1bSJohn Baldwinreturns -1. 771ce204e1bSJohn Baldwin.Pp 772ce204e1bSJohn BaldwinThe 773ce204e1bSJohn Baldwin.Fn pci_msix_table_bar 774ce204e1bSJohn Baldwinfunction returns the offset in configuration space of the BAR 775ce204e1bSJohn Baldwincontaining the MSI-X vector table for device 776ce204e1bSJohn Baldwin.Fa dev . 777ce204e1bSJohn BaldwinThe returned value can be used as the resource ID with 778ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9 779ce204e1bSJohn Baldwinand 780ce204e1bSJohn Baldwin.Xr bus_release_resource 9 781ce204e1bSJohn Baldwinto allocate the BAR. 782ce204e1bSJohn BaldwinIf the device does not support MSI-X, 783ce204e1bSJohn Baldwinthen 784ce204e1bSJohn Baldwin.Fn pci_msix_table_bar 785ce204e1bSJohn Baldwinreturns -1. 786ce204e1bSJohn Baldwin.Pp 787ce204e1bSJohn BaldwinThe 788855ed4c5SJohn Baldwin.Fn pci_alloc_msix 789855ed4c5SJohn Baldwinfunction attempts to allocate 790855ed4c5SJohn Baldwin.Fa *count 791855ed4c5SJohn BaldwinMSI-X messages for the device 792855ed4c5SJohn Baldwin.Fa dev . 793855ed4c5SJohn BaldwinThe 794855ed4c5SJohn Baldwin.Fn pci_alloc_msix 795855ed4c5SJohn Baldwinfunction may allocate fewer messages than requested for various 796855ed4c5SJohn Baldwinreasons including requests for more messages than the device 797855ed4c5SJohn Baldwin.Fa dev 798855ed4c5SJohn Baldwinsupports, 799855ed4c5SJohn Baldwinor if the system has a shortage of available MSI-X messages. 800855ed4c5SJohn BaldwinOn success, 801855ed4c5SJohn Baldwin.Fa *count 802855ed4c5SJohn Baldwinis set to the number of messages allocated and 803855ed4c5SJohn Baldwin.Fn pci_alloc_msix 804855ed4c5SJohn Baldwinreturns zero. 805855ed4c5SJohn BaldwinFor MSI-X messages, 806855ed4c5SJohn Baldwinthe resource ID for each 80773bbeaa5SGlen Barber.Dv SYS_RES_IRQ 80873bbeaa5SGlen Barberresource identifies the index in the MSI-X table of the 809855ed4c5SJohn Baldwincorresponding message. 810855ed4c5SJohn BaldwinA resource ID of one maps to the first index of the MSI-X table; 811855ed4c5SJohn Baldwina resource ID two identifies the second index in the table, etc. 812855ed4c5SJohn BaldwinThe 813855ed4c5SJohn Baldwin.Fn pci_alloc_msix 814855ed4c5SJohn Baldwinfunction assigns the 815855ed4c5SJohn Baldwin.Fa *count 816855ed4c5SJohn Baldwinmessages allocated to the first 817855ed4c5SJohn Baldwin.Fa *count 8187c64ddd5SWarren Blocktable indices. 819855ed4c5SJohn BaldwinIf 820855ed4c5SJohn Baldwin.Fn pci_alloc_msix 821855ed4c5SJohn Baldwinis not able to allocate any messages, 822855ed4c5SJohn Baldwinit returns an error. 823855ed4c5SJohn BaldwinUnlike MSI, 824855ed4c5SJohn BaldwinMSI-X does not require message counts that are powers of two. 825855ed4c5SJohn Baldwin.Pp 826ce204e1bSJohn BaldwinThe BARs containing the MSI-X vector table and PBA must be 827ce204e1bSJohn Baldwinallocated via 828ce204e1bSJohn Baldwin.Xr bus_alloc_resource 9 829ce204e1bSJohn Baldwinbefore calling 830ce204e1bSJohn Baldwin.Fn pci_alloc_msix 831ce204e1bSJohn Baldwinand must not be released until after calling 832ce204e1bSJohn Baldwin.Fn pci_release_msi . 833ce204e1bSJohn BaldwinNote that the vector table and PBA may be stored in the same BAR or in 834ce204e1bSJohn Baldwindifferent BARs. 835ce204e1bSJohn Baldwin.Pp 836855ed4c5SJohn BaldwinThe 837855ed4c5SJohn Baldwin.Fn pci_pending_msix 838855ed4c5SJohn Baldwinfunction examines the 839855ed4c5SJohn Baldwin.Fa dev 840ce204e1bSJohn Baldwindevice's PBA 841855ed4c5SJohn Baldwinto determine the pending status of the MSI-X message at table index 842855ed4c5SJohn Baldwin.Fa index . 843855ed4c5SJohn BaldwinIf the indicated message is pending, 844855ed4c5SJohn Baldwinthis function returns a non-zero value; 845855ed4c5SJohn Baldwinotherwise, 846855ed4c5SJohn Baldwinit returns zero. 847855ed4c5SJohn BaldwinPassing an invalid 848855ed4c5SJohn Baldwin.Fa index 849855ed4c5SJohn Baldwinto this function will result in undefined behavior. 850855ed4c5SJohn Baldwin.Pp 851855ed4c5SJohn BaldwinAs mentioned in the description of 852855ed4c5SJohn Baldwin.Fn pci_alloc_msix , 853855ed4c5SJohn BaldwinMSI-X messages are initially assigned to the first N table entries. 854855ed4c5SJohn BaldwinA driver may use a different distribution of available messages to 855855ed4c5SJohn Baldwintable entries via the 856855ed4c5SJohn Baldwin.Fn pci_remap_msix 857855ed4c5SJohn Baldwinfunction. 85873bbeaa5SGlen BarberNote that this function must be called after a successful call to 859855ed4c5SJohn Baldwin.Fn pci_alloc_msix 860855ed4c5SJohn Baldwinbut before any of the 861855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 862855ed4c5SJohn Baldwinresources are allocated. 863855ed4c5SJohn BaldwinThe 864855ed4c5SJohn Baldwin.Fn pci_remap_msix 865855ed4c5SJohn Baldwinfunction returns zero on success, 866855ed4c5SJohn Baldwinor an error on failure. 867855ed4c5SJohn Baldwin.Pp 868855ed4c5SJohn BaldwinThe 869855ed4c5SJohn Baldwin.Fa vectors 870855ed4c5SJohn Baldwinarray should contain 871855ed4c5SJohn Baldwin.Fa count 872855ed4c5SJohn Baldwinmessage vectors. 873855ed4c5SJohn BaldwinThe array maps directly to the MSI-X table in that the first entry in 874855ed4c5SJohn Baldwinthe array specifies the message used for the first entry in the MSI-X 875855ed4c5SJohn Baldwintable, 876855ed4c5SJohn Baldwinthe second entry in the array corresponds to the second entry in the 877855ed4c5SJohn BaldwinMSI-X table, 878855ed4c5SJohn Baldwinetc. 879855ed4c5SJohn BaldwinThe vector value in each array index can either be zero to indicate 880855ed4c5SJohn Baldwinthat no message should be assigned to the corresponding MSI-X table entry, 881855ed4c5SJohn Baldwinor it can be a number from one to N 882855ed4c5SJohn Baldwin.Po 883855ed4c5SJohn Baldwinwhere N is the count returned from the previous call to 884855ed4c5SJohn Baldwin.Fn pci_alloc_msix 885855ed4c5SJohn Baldwin.Pc 886855ed4c5SJohn Baldwinto indicate which of the allocated messages should be assigned to the 887855ed4c5SJohn Baldwincorresponding MSI-X table entry. 888855ed4c5SJohn Baldwin.Pp 889855ed4c5SJohn BaldwinIf 890855ed4c5SJohn Baldwin.Fn pci_remap_msix 891855ed4c5SJohn Baldwinsucceeds, 892855ed4c5SJohn Baldwineach MSI-X table entry with a non-zero vector will have an associated 893855ed4c5SJohn Baldwin.Dv SYS_RES_IRQ 894855ed4c5SJohn Baldwinresource whose resource ID corresponds to the table index as described 895855ed4c5SJohn Baldwinabove for 896855ed4c5SJohn Baldwin.Fn pci_alloc_msix . 897855ed4c5SJohn BaldwinMSI-X table entries that with a vector of zero will not have an 898855ed4c5SJohn Baldwinassociated 89973bbeaa5SGlen Barber.Dv SYS_RES_IRQ 90073bbeaa5SGlen Barberresource. 901855ed4c5SJohn BaldwinAdditionally, 902855ed4c5SJohn Baldwinif any of the original messages allocated by 903855ed4c5SJohn Baldwin.Fn pci_alloc_msix 904855ed4c5SJohn Baldwinare not used in the new distribution of messages in the MSI-X table, 905855ed4c5SJohn Baldwinthey will be released automatically. 906855ed4c5SJohn BaldwinNote that if a driver wishes to use fewer messages than were allocated by 907855ed4c5SJohn Baldwin.Fn pci_alloc_msix , 908855ed4c5SJohn Baldwinthe driver must use a single, contiguous range of messages beginning 909855ed4c5SJohn Baldwinwith one in the new distribution. 910855ed4c5SJohn BaldwinThe 911855ed4c5SJohn Baldwin.Fn pci_remap_msix 912855ed4c5SJohn Baldwinfunction will fail if this condition is not met. 913aac0aafaSHiten Pandya.Sh IMPLEMENTATION NOTES 914aac0aafaSHiten PandyaThe 915aac0aafaSHiten Pandya.Vt pci_addr_t 91665bb31b8SRuslan Ermilovtype varies according to the size of the PCI bus address 917aac0aafaSHiten Pandyaspace on the target architecture. 918aac0aafaSHiten Pandya.Sh SEE ALSO 9197c2c06f2SSheldon Hearn.Xr pci 4 , 9207c2c06f2SSheldon Hearn.Xr pciconf 8 , 921aac0aafaSHiten Pandya.Xr bus_alloc_resource 9 , 922aac0aafaSHiten Pandya.Xr bus_dma 9 , 923aac0aafaSHiten Pandya.Xr bus_release_resource 9 , 924aac0aafaSHiten Pandya.Xr bus_setup_intr 9 , 925aac0aafaSHiten Pandya.Xr bus_teardown_intr 9 , 926aac0aafaSHiten Pandya.Xr devclass 9 , 927aac0aafaSHiten Pandya.Xr device 9 , 928aac0aafaSHiten Pandya.Xr driver 9 , 929aac0aafaSHiten Pandya.Xr rman 9 930aac0aafaSHiten Pandya.Rs 931aac0aafaSHiten Pandya.%B FreeBSD Developers' Handbook 932aac0aafaSHiten Pandya.%T NewBus 933aa4a335bSRuslan Ermilov.%U http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/developers-handbook/ 934aac0aafaSHiten Pandya.Re 935aac0aafaSHiten Pandya.Rs 936aac0aafaSHiten Pandya.%A Shanley 937aac0aafaSHiten Pandya.%A Anderson 938aac0aafaSHiten Pandya.%B PCI System Architecture 939aac0aafaSHiten Pandya.%N 2nd Edition 940aac0aafaSHiten Pandya.%I Addison-Wesley 941aac0aafaSHiten Pandya.%O ISBN 0-201-30974-2 942aac0aafaSHiten Pandya.Re 943aac0aafaSHiten Pandya.Sh AUTHORS 9448a7314fcSBaptiste Daroussin.An -nosplit 945571dba6eSHiten PandyaThis manual page was written by 9468a7314fcSBaptiste Daroussin.An Bruce M Simpson Aq Mt bms@FreeBSD.org 947855ed4c5SJohn Baldwinand 9488a7314fcSBaptiste Daroussin.An John Baldwin Aq Mt jhb@FreeBSD.org . 949aac0aafaSHiten Pandya.Sh BUGS 9504d80f750SBruce M SimpsonThe kernel PCI code has a number of references to 9514d80f750SBruce M Simpson.Dq "slot numbers" . 952bf1639eeSBruce M SimpsonThese do not refer to the geographic location of PCI devices, 953bf1639eeSBruce M Simpsonbut to the device number assigned by the combination of the PCI IDSEL 954bf1639eeSBruce M Simpsonmechanism and the platform firmware. 955bf1639eeSBruce M SimpsonThis should be taken note of when working with the kernel PCI code. 956ce204e1bSJohn Baldwin.Pp 957ce204e1bSJohn BaldwinThe PCI bus driver should allocate the MSI-X vector table and PBA internally 958ce204e1bSJohn Baldwinas necessary rather than requiring the caller to do so. 959