164ae346bSKenneth D. Merry.\" 264ae346bSKenneth D. Merry.\" Copyright (c) 1999 Kenneth D. Merry. 364ae346bSKenneth D. Merry.\" All rights reserved. 464ae346bSKenneth D. Merry.\" 564ae346bSKenneth D. Merry.\" Redistribution and use in source and binary forms, with or without 664ae346bSKenneth D. Merry.\" modification, are permitted provided that the following conditions 764ae346bSKenneth D. Merry.\" are met: 864ae346bSKenneth D. Merry.\" 1. Redistributions of source code must retain the above copyright 964ae346bSKenneth D. Merry.\" notice, this list of conditions and the following disclaimer. 1064ae346bSKenneth D. Merry.\" 2. The name of the author may not be used to endorse or promote products 1164ae346bSKenneth D. Merry.\" derived from this software without specific prior written permission. 1264ae346bSKenneth D. Merry.\" 1364ae346bSKenneth D. Merry.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1464ae346bSKenneth D. Merry.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1564ae346bSKenneth D. Merry.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1664ae346bSKenneth D. Merry.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1764ae346bSKenneth D. Merry.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1864ae346bSKenneth D. Merry.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 1964ae346bSKenneth D. Merry.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2064ae346bSKenneth D. Merry.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2164ae346bSKenneth D. Merry.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2264ae346bSKenneth D. Merry.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2364ae346bSKenneth D. Merry.\" SUCH DAMAGE. 2464ae346bSKenneth D. Merry.\" 2564ae346bSKenneth D. Merry.\" $FreeBSD$ 2664ae346bSKenneth D. Merry.\" 27*85ae35efSKonstantin Belousov.Dd July 27, 2021 2864ae346bSKenneth D. Merry.Dt PCI 4 293d45e180SRuslan Ermilov.Os 3064ae346bSKenneth D. Merry.Sh NAME 3164ae346bSKenneth D. Merry.Nm pci 32*85ae35efSKonstantin Belousov.Nd generic PCI/PCIe bus driver 33251c176fSRuslan Ermilov.Sh SYNOPSIS 34c97a3872SJohn BaldwinTo compile the PCI bus driver into the kernel, 35c97a3872SJohn Baldwinplace the following line in your 36c97a3872SJohn Baldwinkernel configuration file: 37c97a3872SJohn Baldwin.Bd -ragged -offset indent 386b713d58SJeroen Ruigrok van der Werven.Cd device pci 39c97a3872SJohn Baldwin.Ed 40c97a3872SJohn Baldwin.Pp 41c97a3872SJohn BaldwinTo compile in support for Single Root I/O Virtualization 42c97a3872SJohn Baldwin.Pq SR-IOV : 43c97a3872SJohn Baldwin.Bd -ragged -offset indent 44c97a3872SJohn Baldwin.Cd options PCI_IOV 45c97a3872SJohn Baldwin.Ed 46c97a3872SJohn Baldwin.Pp 47c97a3872SJohn BaldwinTo compile in support for native PCI-express HotPlug: 48c97a3872SJohn Baldwin.Bd -ragged -offset indent 49c97a3872SJohn Baldwin.Cd options PCI_HP 50c97a3872SJohn Baldwin.Ed 5164ae346bSKenneth D. Merry.Sh DESCRIPTION 5264ae346bSKenneth D. MerryThe 534b66483fSRuslan Ermilov.Nm 54c97a3872SJohn Baldwindriver provides support for 55c97a3872SJohn Baldwin.Tn PCI 56*85ae35efSKonstantin Belousovand 57*85ae35efSKonstantin Belousov.Tn PCIe 58c97a3872SJohn Baldwindevices in the kernel and limited access to 59c97a3872SJohn Baldwin.Tn PCI 60c97a3872SJohn Baldwindevices for userland. 61c97a3872SJohn Baldwin.Pp 62c97a3872SJohn BaldwinThe 63c97a3872SJohn Baldwin.Nm 64c97a3872SJohn Baldwindriver provides a 65c97a3872SJohn Baldwin.Pa /dev/pci 66c97a3872SJohn Baldwincharacter device that can be used by userland programs to read and write 6764ae346bSKenneth D. Merry.Tn PCI 68b5e7e999SRuslan Ermilovconfiguration registers. 69c97a3872SJohn BaldwinPrograms can also use this device to get a list of all 7064ae346bSKenneth D. Merry.Tn PCI 7164ae346bSKenneth D. Merrydevices, or all 7264ae346bSKenneth D. Merry.Tn PCI 7364ae346bSKenneth D. Merrydevices that match various patterns. 7464ae346bSKenneth D. Merry.Pp 7564ae346bSKenneth D. MerrySince the 764b66483fSRuslan Ermilov.Nm 7764ae346bSKenneth D. Merrydriver provides a write interface for 7864ae346bSKenneth D. Merry.Tn PCI 7964ae346bSKenneth D. Merryconfiguration registers, system administrators should exercise caution when 8064ae346bSKenneth D. Merrygranting access to the 814b66483fSRuslan Ermilov.Nm 82b5e7e999SRuslan Ermilovdevice. 83b5e7e999SRuslan ErmilovIf used improperly, this driver can allow userland applications to 8464ae346bSKenneth D. Merrycrash a machine or cause data loss. 85*85ae35efSKonstantin BelousovIn particular, driver only allows operations on the opened 86*85ae35efSKonstantin Belousov.Pa /dev/pci 87*85ae35efSKonstantin Belousovto modify system state if the file descriptor was opened for writing. 88*85ae35efSKonstantin BelousovFor instance, the 89*85ae35efSKonstantin Belousov.Dv PCIOCREAD 90*85ae35efSKonstantin Belousovand 91*85ae35efSKonstantin Belousov.Dv PCIOCBARMMAP 92*85ae35efSKonstantin Belousovoperations require a writeable descriptor, because reading a config register 93*85ae35efSKonstantin Belousovor a BAR read access could have function-specific side-effects. 940ade47aeSWarner Losh.Pp 950ade47aeSWarner LoshThe 964b66483fSRuslan Ermilov.Nm 97c0c7deaaSChristian Bruefferdriver implements the 98c0c7deaaSChristian Brueffer.Tn PCI 99c0c7deaaSChristian Bruefferbus in the kernel. 100c0c7deaaSChristian BruefferIt enumerates any devices on the 101c0c7deaaSChristian Brueffer.Tn PCI 102c0c7deaaSChristian Bruefferbus and gives 103c0c7deaaSChristian Brueffer.Tn PCI 104c0c7deaaSChristian Bruefferclient drivers the chance to attach to them. 105c0c7deaaSChristian BruefferIt assigns resources to children, when the BIOS does not. 1060ade47aeSWarner LoshIt takes care of routing interrupts when necessary. 107c0c7deaaSChristian BruefferIt reprobes the unattached 108c0c7deaaSChristian Brueffer.Tn PCI 109c0c7deaaSChristian Bruefferchildren when 110c0c7deaaSChristian Brueffer.Tn PCI 111c0c7deaaSChristian Bruefferclient drivers are dynamically 1120ade47aeSWarner Loshloaded at runtime. 1130ade47aeSWarner LoshThe 1140ade47aeSWarner Losh.Nm 115c97a3872SJohn Baldwindriver also includes support for PCI-PCI bridges, 116c97a3872SJohn Baldwinvarious platform-specific Host-PCI bridges, 117c97a3872SJohn Baldwinand basic support for 118c97a3872SJohn Baldwin.Tn PCI 119c97a3872SJohn BaldwinVGA adapters. 12064ae346bSKenneth D. Merry.Sh IOCTLS 12164ae346bSKenneth D. MerryThe following 12264ae346bSKenneth D. Merry.Xr ioctl 2 12364ae346bSKenneth D. Merrycalls are supported by the 1244b66483fSRuslan Ermilov.Nm 125b5e7e999SRuslan Ermilovdriver. 126b5e7e999SRuslan ErmilovThey are defined in the header file 127fe08efe6SRuslan Ermilov.In sys/pciio.h . 12864ae346bSKenneth D. Merry.Bl -tag -width 012345678901234 12964ae346bSKenneth D. Merry.It PCIOCGETCONF 13064ae346bSKenneth D. MerryThis 13164ae346bSKenneth D. Merry.Xr ioctl 2 13264ae346bSKenneth D. Merrytakes a 13364ae346bSKenneth D. Merry.Va pci_conf_io 134b5e7e999SRuslan Ermilovstructure. 135b5e7e999SRuslan ErmilovIt allows the user to retrieve information on all 13664ae346bSKenneth D. Merry.Tn PCI 13764ae346bSKenneth D. Merrydevices in the system, or on 13864ae346bSKenneth D. Merry.Tn PCI 1395203edcdSRuslan Ermilovdevices matching patterns supplied by the user. 1405203edcdSRuslan ErmilovThe call may set 14107e3ed79SJohn-Mark Gurney.Va errno 14207e3ed79SJohn-Mark Gurneyto any value specified in either 14307e3ed79SJohn-Mark Gurney.Xr copyin 9 14407e3ed79SJohn-Mark Gurneyor 14507e3ed79SJohn-Mark Gurney.Xr copyout 9 . 14664ae346bSKenneth D. MerryThe 14764ae346bSKenneth D. Merry.Va pci_conf_io 14864ae346bSKenneth D. Merrystructure consists of a number of fields: 14964ae346bSKenneth D. Merry.Bl -tag -width match_buf_len 15064ae346bSKenneth D. Merry.It pat_buf_len 15164ae346bSKenneth D. MerryThe length, in bytes, of the buffer filled with user-supplied patterns. 15264ae346bSKenneth D. Merry.It num_patterns 15364ae346bSKenneth D. MerryThe number of user-supplied patterns. 15464ae346bSKenneth D. Merry.It patterns 15564ae346bSKenneth D. MerryPointer to a buffer filled with user-supplied patterns. 15664ae346bSKenneth D. Merry.Va patterns 15764ae346bSKenneth D. Merryis a pointer to 15864ae346bSKenneth D. Merry.Va num_patterns 15964ae346bSKenneth D. Merry.Va pci_match_conf 1605203edcdSRuslan Ermilovstructures. 1615203edcdSRuslan ErmilovThe 16264ae346bSKenneth D. Merry.Va pci_match_conf 16364ae346bSKenneth D. Merrystructure consists of the following elements: 16464ae346bSKenneth D. Merry.Bl -tag -width pd_vendor 16564ae346bSKenneth D. Merry.It pc_sel 16664ae346bSKenneth D. Merry.Tn PCI 16755aaf894SMarius Strobldomain, bus, slot and function. 16864ae346bSKenneth D. Merry.It pd_name 16964ae346bSKenneth D. Merry.Tn PCI 17064ae346bSKenneth D. Merrydevice driver name. 17164ae346bSKenneth D. Merry.It pd_unit 17264ae346bSKenneth D. Merry.Tn PCI 17364ae346bSKenneth D. Merrydevice driver unit number. 17464ae346bSKenneth D. Merry.It pc_vendor 17564ae346bSKenneth D. Merry.Tn PCI 17664ae346bSKenneth D. Merryvendor ID. 17764ae346bSKenneth D. Merry.It pc_device 17864ae346bSKenneth D. Merry.Tn PCI 17964ae346bSKenneth D. Merrydevice ID. 18064ae346bSKenneth D. Merry.It pc_class 18164ae346bSKenneth D. Merry.Tn PCI 18264ae346bSKenneth D. Merrydevice class. 18364ae346bSKenneth D. Merry.It flags 18464ae346bSKenneth D. MerryThe flags describe which of the fields the kernel should match against. 185b5e7e999SRuslan ErmilovA device must match all specified fields in order to be returned. 186b5e7e999SRuslan ErmilovThe match flags are enumerated in the 18764ae346bSKenneth D. Merry.Va pci_getconf_flags 18864ae346bSKenneth D. Merrystructure. 1890227791bSRuslan ErmilovHopefully the flag values are obvious enough that they do not need to 19064ae346bSKenneth D. Merrydescribed in detail. 19164ae346bSKenneth D. Merry.El 19264ae346bSKenneth D. Merry.It match_buf_len 19364ae346bSKenneth D. MerryLength of the 19464ae346bSKenneth D. Merry.Va matches 19564ae346bSKenneth D. Merrybuffer allocated by the user to hold the results of the 19664ae346bSKenneth D. Merry.Dv PCIOCGETCONF 19764ae346bSKenneth D. Merryquery. 19864ae346bSKenneth D. Merry.It num_matches 19964ae346bSKenneth D. MerryNumber of matches returned by the kernel. 20064ae346bSKenneth D. Merry.It matches 201b5e7e999SRuslan ErmilovBuffer containing matching devices returned by the kernel. 202b5e7e999SRuslan ErmilovThe items in this buffer are of type 20364ae346bSKenneth D. Merry.Va pci_conf , 20464ae346bSKenneth D. Merrywhich consists of the following items: 20564ae346bSKenneth D. Merry.Bl -tag -width pc_subvendor 20664ae346bSKenneth D. Merry.It pc_sel 20764ae346bSKenneth D. Merry.Tn PCI 20855aaf894SMarius Strobldomain, bus, slot and function. 20964ae346bSKenneth D. Merry.It pc_hdr 21064ae346bSKenneth D. Merry.Tn PCI 21164ae346bSKenneth D. Merryheader type. 21264ae346bSKenneth D. Merry.It pc_subvendor 21364ae346bSKenneth D. Merry.Tn PCI 21464ae346bSKenneth D. Merrysubvendor ID. 21564ae346bSKenneth D. Merry.It pc_subdevice 21664ae346bSKenneth D. Merry.Tn PCI 21764ae346bSKenneth D. Merrysubdevice ID. 21864ae346bSKenneth D. Merry.It pc_vendor 21964ae346bSKenneth D. Merry.Tn PCI 22064ae346bSKenneth D. Merryvendor ID. 22164ae346bSKenneth D. Merry.It pc_device 22264ae346bSKenneth D. Merry.Tn PCI 22364ae346bSKenneth D. Merrydevice ID. 22464ae346bSKenneth D. Merry.It pc_class 22564ae346bSKenneth D. Merry.Tn PCI 22664ae346bSKenneth D. Merrydevice class. 22764ae346bSKenneth D. Merry.It pc_subclass 22864ae346bSKenneth D. Merry.Tn PCI 22964ae346bSKenneth D. Merrydevice subclass. 23064ae346bSKenneth D. Merry.It pc_progif 23164ae346bSKenneth D. Merry.Tn PCI 23264ae346bSKenneth D. Merrydevice programming interface. 23364ae346bSKenneth D. Merry.It pc_revid 23464ae346bSKenneth D. Merry.Tn PCI 23564ae346bSKenneth D. Merryrevision ID. 23664ae346bSKenneth D. Merry.It pd_name 23764ae346bSKenneth D. MerryDriver name. 23864ae346bSKenneth D. Merry.It pd_unit 23964ae346bSKenneth D. MerryDriver unit number. 24064ae346bSKenneth D. Merry.El 24164ae346bSKenneth D. Merry.It offset 24264ae346bSKenneth D. MerryThe offset is passed in by the user to tell the kernel where it should 243b5e7e999SRuslan Ermilovstart traversing the device list. 244b5e7e999SRuslan ErmilovThe value passed out by the kernel 245b5e7e999SRuslan Ermilovpoints to the record immediately after the last one returned. 246b5e7e999SRuslan ErmilovThe user may 24764ae346bSKenneth D. Merrypass the value returned by the kernel in subsequent calls to the 24864ae346bSKenneth D. Merry.Dv PCIOCGETCONF 249b5e7e999SRuslan Ermilovioctl. 250b5e7e999SRuslan ErmilovIf the user does not intend to use the offset, it must be set to zero. 25164ae346bSKenneth D. Merry.It generation 25264ae346bSKenneth D. Merry.Tn PCI 253b5e7e999SRuslan Ermilovconfiguration generation. 254b5e7e999SRuslan ErmilovThis value only needs to be set if the offset is set. 255b5e7e999SRuslan ErmilovThe kernel will compare the current generation number of its internal 25664ae346bSKenneth D. Merrydevice list to the generation passed in by the user to determine whether 25764ae346bSKenneth D. Merryits device list has changed since the user last called the 25864ae346bSKenneth D. Merry.Dv PCIOCGETCONF 259b5e7e999SRuslan Ermilovioctl. 260b5e7e999SRuslan ErmilovIf the device list has changed, a status of 26164ae346bSKenneth D. Merry.Va PCI_GETCONF_LIST_CHANGED 26264ae346bSKenneth D. Merrywill be passed back. 26364ae346bSKenneth D. Merry.It status 26464ae346bSKenneth D. MerryThe status tells the user the disposition of his request for a device list. 26564ae346bSKenneth D. MerryThe possible status values are: 26664ae346bSKenneth D. Merry.Bl -ohang 26764ae346bSKenneth D. Merry.It PCI_GETCONF_LAST_DEVICE 26810012d53SJohn BaldwinThis means that there are no more devices in the PCI device list matching 26910012d53SJohn Baldwinthe specified criteria after the 27064ae346bSKenneth D. Merryones returned in the 27164ae346bSKenneth D. Merry.Va matches 27264ae346bSKenneth D. Merrybuffer. 27364ae346bSKenneth D. Merry.It PCI_GETCONF_LIST_CHANGED 27464ae346bSKenneth D. MerryThis status tells the user that the 27564ae346bSKenneth D. Merry.Tn PCI 27664ae346bSKenneth D. Merrydevice list has changed since his last call to the 27764ae346bSKenneth D. Merry.Dv PCIOCGETCONF 27864ae346bSKenneth D. Merryioctl and he must reset the 27964ae346bSKenneth D. Merry.Va offset 28064ae346bSKenneth D. Merryand 28164ae346bSKenneth D. Merry.Va generation 28264ae346bSKenneth D. Merryto zero to start over at the beginning of the list. 28364ae346bSKenneth D. Merry.It PCI_GETCONF_MORE_DEVS 28464ae346bSKenneth D. MerryThis tells the user that his buffer was not large enough to hold all of the 28510012d53SJohn Baldwinremaining devices in the device list that match his criteria. 28664ae346bSKenneth D. Merry.It PCI_GETCONF_ERROR 287b5e7e999SRuslan ErmilovThis indicates a general error while servicing the user's request. 288b5e7e999SRuslan ErmilovIf the 28907e3ed79SJohn-Mark Gurney.Va pat_buf_len 29007e3ed79SJohn-Mark Gurneyis not equal to 29107e3ed79SJohn-Mark Gurney.Va num_patterns 29207e3ed79SJohn-Mark Gurneytimes 293b5e7e999SRuslan Ermilov.Fn sizeof "struct pci_match_conf" , 294b5e7e999SRuslan Ermilov.Va errno 295b5e7e999SRuslan Ermilovwill be set to 296b5e7e999SRuslan Ermilov.Er EINVAL . 29764ae346bSKenneth D. Merry.El 29864ae346bSKenneth D. Merry.El 29964ae346bSKenneth D. Merry.It PCIOCREAD 30064ae346bSKenneth D. MerryThis 30164ae346bSKenneth D. Merry.Xr ioctl 2 30264ae346bSKenneth D. Merryreads the 30364ae346bSKenneth D. Merry.Tn PCI 304f1bb9412SNiclas Zeisingconfiguration registers specified by the passed-in 30564ae346bSKenneth D. Merry.Va pci_io 3065203edcdSRuslan Ermilovstructure. 3075203edcdSRuslan ErmilovThe 30864ae346bSKenneth D. Merry.Va pci_io 30964ae346bSKenneth D. Merrystructure consists of the following fields: 31064ae346bSKenneth D. Merry.Bl -tag -width pi_width 31164ae346bSKenneth D. Merry.It pi_sel 31264ae346bSKenneth D. MerryA 31364ae346bSKenneth D. Merry.Va pcisel 31455aaf894SMarius Stroblstructure which specifies the domain, bus, slot and function the user would 31555aaf894SMarius Strobllike to query. 31655aaf894SMarius StroblIf the specific bus is not found, errno will be set to ENODEV and -1 returned 31755aaf894SMarius Stroblfrom the ioctl. 31864ae346bSKenneth D. Merry.It pi_reg 31964ae346bSKenneth D. MerryThe 32064ae346bSKenneth D. Merry.Tn PCI 3212d4a74d7SNiclas Zeisingconfiguration registers the user would like to access. 32264ae346bSKenneth D. Merry.It pi_width 323b5e7e999SRuslan ErmilovThe width, in bytes, of the data the user would like to read. 324b5e7e999SRuslan ErmilovThis value 3255203edcdSRuslan Ermilovmay be either 1, 2, or 4. 3265203edcdSRuslan Ermilov3-byte reads and reads larger than 4 bytes are 3275203edcdSRuslan Ermilovnot supported. 3285203edcdSRuslan ErmilovIf an invalid width is passed, errno will be set to EINVAL. 32964ae346bSKenneth D. Merry.It pi_data 33064ae346bSKenneth D. MerryThe data returned by the kernel. 33164ae346bSKenneth D. Merry.El 33264ae346bSKenneth D. Merry.It PCIOCWRITE 33364ae346bSKenneth D. MerryThis 33464ae346bSKenneth D. Merry.Xr ioctl 2 33564ae346bSKenneth D. Merryallows users to write to the 33664ae346bSKenneth D. Merry.Tn PCI 3372d4a74d7SNiclas Zeisingconfiguration registers specified in the passed-in 33864ae346bSKenneth D. Merry.Va pci_io 3395203edcdSRuslan Ermilovstructure. 3405203edcdSRuslan ErmilovThe 34164ae346bSKenneth D. Merry.Va pci_io 342b5e7e999SRuslan Ermilovstructure is described above. 343b5e7e999SRuslan ErmilovThe limitations on data width described for 34464ae346bSKenneth D. Merryreading registers, above, also apply to writing 34564ae346bSKenneth D. Merry.Tn PCI 34664ae346bSKenneth D. Merryconfiguration registers. 34765d328a3SNiclas Zeising.It PCIOCATTACHED 34865d328a3SNiclas ZeisingThis 34965d328a3SNiclas Zeising.Xr ioctl 2 35065d328a3SNiclas Zeisingallows users to query if a driver is attached to the 35165d328a3SNiclas Zeising.Tn PCI 352999546e1SNiclas Zeisingdevice specified in the passed-in 35365d328a3SNiclas Zeising.Va pci_io 35465d328a3SNiclas Zeisingstructure. 35565d328a3SNiclas ZeisingThe 35665d328a3SNiclas Zeising.Va pci_io 35765d328a3SNiclas Zeisingstructure is described above, however, the 35865d328a3SNiclas Zeising.Va pi_reg 35965d328a3SNiclas Zeisingand 36065d328a3SNiclas Zeising.Va pi_width 36165d328a3SNiclas Zeisingfields are not used. 36265d328a3SNiclas ZeisingThe status of the device is stored in the 36365d328a3SNiclas Zeising.Va pi_data 36465d328a3SNiclas Zeisingfield. 36565d328a3SNiclas ZeisingA value of 0 indicates no driver is attached, while a value larger than 0 36665d328a3SNiclas Zeisingindicates that a driver is attached. 36787842989SKonstantin Belousov.It PCIOCBARMMAP 36887842989SKonstantin BelousovThis 36987842989SKonstantin Belousov.Xr ioctl 2 37087842989SKonstantin Belousovcommand allows userspace processes to 37187842989SKonstantin Belousov.Xr mmap 2 37287842989SKonstantin Belousovthe memory-mapped PCI BAR into its address space. 37387842989SKonstantin BelousovThe input parameters and results are passed in the 37487842989SKonstantin Belousov.Va pci_bar_mmap 37587842989SKonstantin Belousovstructure, which has the following fields: 37687842989SKonstantin Belousov.Bl -tag -width Vt struct pcise pbm_sel 37787842989SKonstantin Belousov.It Vt uint64_t pbm_map_base 37887842989SKonstantin BelousovReports the established mapping base to the caller. 37987842989SKonstantin BelousovIf 38087842989SKonstantin Belousov.Va PCIIO_BAR_MMAP_FIXED 38187842989SKonstantin Belousovflag was specified, then this field must be filled before the call 38287842989SKonstantin Belousovwith the desired address for the mapping. 38387842989SKonstantin Belousov.It Vt uint64_t pbm_map_length 38487842989SKonstantin BelousovReports the mapped length of the BAR, in bytes. 38587842989SKonstantin BelousovIts .Vt uint64_t value is always multiple of machine pages. 38687842989SKonstantin Belousov.It Vt int64_t pbm_bar_length 38787842989SKonstantin BelousovReports length of the bar as exposed by the device. 38887842989SKonstantin Belousov.It Vt int pbm_bar_off 38987842989SKonstantin BelousovReports offset from the mapped base to the start of the 39087842989SKonstantin Belousovfirst register in the bar. 39187842989SKonstantin Belousov.It Vt struct pcisel pbm_sel 39287842989SKonstantin BelousovShould be filled before the call. 39387842989SKonstantin BelousovDescribes the device to operate on. 39487842989SKonstantin Belousov.It Vt int pbm_reg 39587842989SKonstantin BelousovThe BAR index to mmap. 39687842989SKonstantin Belousov.It Vt int pbm_flags 39787842989SKonstantin BelousovFlags which augments the operation. 39887842989SKonstantin BelousovSee below. 39987842989SKonstantin Belousov.It Vt int pbm_memattr 40087842989SKonstantin BelousovThe caching attribute for the mapping. 40187842989SKonstantin BelousovTypical values are 40287842989SKonstantin Belousov.Dv VM_MEMATTR_UNCACHEABLE 40387842989SKonstantin Belousovfor control registers BARs, and 40487842989SKonstantin Belousov.Dv VM_MEMATTR_WRITE_COMBINING 40587842989SKonstantin Belousovfor frame buffers. 40687842989SKonstantin BelousovRegular memory-like BAR should be mapped with 40787842989SKonstantin Belousov.Dv VM_MEMATTR_DEFAULT 40887842989SKonstantin Belousovattribute. 40987842989SKonstantin Belousov.El 41087842989SKonstantin Belousov.Pp 41187842989SKonstantin BelousovCurrently defined flags are: 41287842989SKonstantin Belousov.Bl -tag -width PCIIO_BAR_MMAP_ACTIVATE 41387842989SKonstantin Belousov.It PCIIO_BAR_MMAP_FIXED 41487842989SKonstantin BelousovThe resulted mappings should be established at the address 41587842989SKonstantin Belousovspecified by the 41687842989SKonstantin Belousov.Va pbm_map_base 41787842989SKonstantin Belousovmember, otherwise fail. 41887842989SKonstantin Belousov.It PCIIO_BAR_MMAP_EXCL 41987842989SKonstantin BelousovMust be used together with 4201adc28f5SChristian Brueffer.Dv PCIIO_BAR_MMAP_FIXED 42187842989SKonstantin BelousovIf the specified base contains already established mappings, the 42287842989SKonstantin Belousovoperation fails instead of implicitly unmapping them. 42387842989SKonstantin Belousov.It PCIIO_BAR_MMAP_RW 42487842989SKonstantin BelousovThe requested mapping allows both reading and writing. 42587842989SKonstantin BelousovWithout the flag, read-only mapping is established. 42687842989SKonstantin BelousovNote that it is common for the device registers to have side-effects 42787842989SKonstantin Belousoveven on reads. 42887842989SKonstantin Belousov.It PCIIO_BAR_MMAP_ACTIVATE 42987842989SKonstantin Belousov(Unimplemented) If the BAR is not activated, activate it in the course 43087842989SKonstantin Belousovof mapping. 43187842989SKonstantin BelousovCurrently attempt to mmap an inactive BAR results in error. 43287842989SKonstantin Belousov.El 43364ae346bSKenneth D. Merry.El 434c97a3872SJohn Baldwin.Sh LOADER TUNABLES 435c97a3872SJohn BaldwinTunables can be set at the 436c97a3872SJohn Baldwin.Xr loader 8 437c97a3872SJohn Baldwinprompt before booting the kernel, or stored in 438c97a3872SJohn Baldwin.Xr loader.conf 5 . 439c97a3872SJohn BaldwinThe current value of these tunables can be examined at runtime via 440c97a3872SJohn Baldwin.Xr sysctl 8 441c97a3872SJohn Baldwinnodes of the same name. 442c97a3872SJohn BaldwinUnless otherwise specified, 443c97a3872SJohn Baldwineach of these tunables is a boolean that can be enabled by setting the 444c97a3872SJohn Baldwintunable to a non-zero value. 445c97a3872SJohn Baldwin.Bl -tag -width indent 446c97a3872SJohn Baldwin.It Va hw.pci.clear_bars Pq Defaults to 0 447c97a3872SJohn BaldwinIgnore any firmware-assigned memory and I/O port resources. 448c97a3872SJohn BaldwinThis forces the 449c97a3872SJohn Baldwin.Tn PCI 450c97a3872SJohn Baldwinbus driver to allocate resource ranges for memory and I/O port resources 451c97a3872SJohn Baldwinfrom scratch. 452c97a3872SJohn Baldwin.It Va hw.pci.clear_buses Pq Defaults to 0 453c97a3872SJohn BaldwinIgnore any firmware-assigned bus number registers in PCI-PCI bridges. 454c97a3872SJohn BaldwinThis forces the 455c97a3872SJohn Baldwin.Tn PCI 456c97a3872SJohn Baldwinbus driver and PCI-PCI bridge driver to allocate bus numbers for secondary 457c97a3872SJohn Baldwinbuses behind PCI-PCI bridges. 458c97a3872SJohn Baldwin.It Va hw.pci.clear_pcib Pq Defaults to 0 459c97a3872SJohn BaldwinIgnore any firmware-assigned memory and I/O port resource windows in PCI-PCI 460c97a3872SJohn Baldwinbridges. 461c97a3872SJohn BaldwinThis forces the PCI-PCI bridge driver to allocate memory and I/O port resources 462c97a3872SJohn Baldwinfor resource windows from scratch. 463c97a3872SJohn Baldwin.Pp 464c97a3872SJohn BaldwinBy default the PCI-PCI bridge driver will allocate windows that 465c97a3872SJohn Baldwincontain the firmware-assigned resources devices behind the bridge. 466c97a3872SJohn BaldwinIn addition, the PCI-PCI bridge driver will suballocate from existing window 467c97a3872SJohn Baldwinregions when possible to satisfy a resource request. 468c97a3872SJohn BaldwinAs a result, 469c97a3872SJohn Baldwinboth 470c97a3872SJohn Baldwin.Va hw.pci.clear_bars 471c97a3872SJohn Baldwinand 472c97a3872SJohn Baldwin.Va hw.pci.clear_pcib 473c97a3872SJohn Baldwinmust be enabled to fully ignore firmware-supplied resource assignments. 474c97a3872SJohn Baldwin.It Va hw.pci.default_vgapci_unit Pq Defaults to -1 475c97a3872SJohn BaldwinBy default, 476c97a3872SJohn Baldwinthe first 477c97a3872SJohn Baldwin.Tn PCI 478c97a3872SJohn BaldwinVGA adapter encountered by the system is assumed to be the boot display device. 479c97a3872SJohn BaldwinThis tunable can be set to choose a specific VGA adapter by specifying the 480c97a3872SJohn Baldwinunit number of the associated 481c97a3872SJohn Baldwin.Va vgapci Ns Ar X 482c97a3872SJohn Baldwindevice. 483c97a3872SJohn Baldwin.It Va hw.pci.do_power_nodriver Pq Defaults to 0 484c97a3872SJohn BaldwinPlace devices into a low power state 485c97a3872SJohn Baldwin.Pq D3 486c97a3872SJohn Baldwinwhen a suitable device driver is not found. 487c97a3872SJohn BaldwinCan be set to one of the following values: 488c97a3872SJohn Baldwin.Bl -tag -width indent 489c97a3872SJohn Baldwin.It 3 490c97a3872SJohn BaldwinPowers down all 491c97a3872SJohn Baldwin.Tn PCI 492c97a3872SJohn Baldwindevices without a device driver. 493c97a3872SJohn Baldwin.It 2 494c97a3872SJohn BaldwinPowers down most devices without a device driver. 495c97a3872SJohn BaldwinPCI devices with the display, memory, and base peripheral device classes 496c97a3872SJohn Baldwinare not powered down. 497c97a3872SJohn Baldwin.It 1 498c97a3872SJohn BaldwinSimilar to a setting of 2 except that storage controllers are also not 499c97a3872SJohn Baldwinpowered down. 500c97a3872SJohn Baldwin.It 0 501c97a3872SJohn BaldwinAll devices are left fully powered. 502c97a3872SJohn Baldwin.El 503c97a3872SJohn Baldwin.Pp 504c97a3872SJohn BaldwinA 505c97a3872SJohn Baldwin.Tn PCI 506c97a3872SJohn Baldwindevice must support power management to be powered down. 507c97a3872SJohn BaldwinPlacing a device into a low power state may not reduce power consumption. 508c97a3872SJohn Baldwin.It Va hw.pci.do_power_resume Pq Defaults to 1 509c97a3872SJohn BaldwinPlace 510c97a3872SJohn Baldwin.Tn PCI 511c97a3872SJohn Baldwindevices into the fully powered state when resuming either the system or an 512c97a3872SJohn Baldwinindividual device. 513c97a3872SJohn BaldwinSetting this to zero is discouraged as the system will not attempt to power 514c97a3872SJohn Baldwinup non-powered PCI devices after a suspend. 515c97a3872SJohn Baldwin.It Va hw.pci.do_power_suspend Pq Defaults to 1 516c97a3872SJohn BaldwinPlace 517c97a3872SJohn Baldwin.Tn PCI 518c97a3872SJohn Baldwindevices into a low power state when suspending either the system or individual 519c97a3872SJohn Baldwindevices. 520c97a3872SJohn BaldwinNormally the D3 state is used as the low power state, 521c97a3872SJohn Baldwinbut firmware may override the desired power state during a system suspend. 522c97a3872SJohn Baldwin.It Va hw.pci.enable_ari Pq Defaults to 1 523c97a3872SJohn BaldwinEnable support for PCI-express Alternative RID Interpretation. 524c97a3872SJohn BaldwinThis is often used in conjunction with SR-IOV. 525c97a3872SJohn Baldwin.It Va hw.pci.enable_io_modes Pq Defaults to 1 526c97a3872SJohn BaldwinEnable memory or I/O port decoding in a PCI device's command register if it has 527c97a3872SJohn Baldwinfirmware-assigned memory or I/O port resources. 528c97a3872SJohn BaldwinThe firmware 529c97a3872SJohn Baldwin.Pq BIOS 530c97a3872SJohn Baldwinin some systems does not enable memory or I/O port decoding for some devices 531c97a3872SJohn Baldwineven when it has assigned resources to the device. 532c97a3872SJohn BaldwinThis enables decoding for such resources during bus probe. 533c97a3872SJohn Baldwin.It Va hw.pci.enable_msi Pq Defaults to 1 534c97a3872SJohn BaldwinEnable support for Message Signalled Interrupts 535c97a3872SJohn Baldwin.Pq MSI . 536c97a3872SJohn BaldwinMSI interrupts can be disabled by setting this tunable to 0. 537c97a3872SJohn Baldwin.It Va hw.pci.enable_msix Pq Defaults to 1 538c97a3872SJohn BaldwinEnable support for extended Message Signalled Interrupts 539c97a3872SJohn Baldwin.Pq MSI-X . 540c97a3872SJohn BaldwinMSI-X interrupts can be disabled by setting this tunable to 0. 541c97a3872SJohn Baldwin.It Va hw.pci.enable_pcie_hp Pq Defaults to 1 542c97a3872SJohn BaldwinEnable support for native PCI-express HotPlug. 543c97a3872SJohn Baldwin.It Va hw.pci.honor_msi_blacklist Pq Defaults to 1 544c97a3872SJohn BaldwinMSI and MSI-X interrupts are disabled for certain chipsets known to have 545c97a3872SJohn Baldwinbroken MSI and MSI-X implementations when this tunable is set. 546c97a3872SJohn BaldwinIt can be set to zero to permit use of MSI and MSI-X interrupts if the 547c97a3872SJohn Baldwinchipset match is a false positive. 548c97a3872SJohn Baldwin.It Va hw.pci.iov_max_config Pq Defaults to 1MB 549c97a3872SJohn BaldwinThe maximum amount of memory permitted for the configuration parameters 550c97a3872SJohn Baldwinused when creating Virtual Functions via SR-IOV. 551c97a3872SJohn BaldwinThis tunable can also be changed at runtime via 552c97a3872SJohn Baldwin.Xr sysctl 8 . 553c97a3872SJohn Baldwin.It Va hw.pci.realloc_bars Pq Defaults to 0 554c97a3872SJohn BaldwinAttempt to allocate a new resource range during the initial device scan 555c97a3872SJohn Baldwinfor any memory or I/O port resources with firmware-assigned ranges that 556c97a3872SJohn Baldwinconflict with another active resource. 557c97a3872SJohn Baldwin.It Va hw.pci.usb_early_takeover Pq Defaults to 1 on Tn amd64 and Tn i386 558c97a3872SJohn BaldwinDisable legacy device emulation of USB devices during the initial device 559c97a3872SJohn Baldwinscan. 560c97a3872SJohn BaldwinSet this tunable to zero to use USB devices via legacy emulation when 561c97a3872SJohn Baldwinusing a custom kernel without USB controller drivers. 562c97a3872SJohn Baldwin.It Va hw.pci<D>.<B>.<S>.INT<P>.irq 563c97a3872SJohn BaldwinThese tunables can be used to override the interrupt routing for legacy 564c97a3872SJohn BaldwinPCI INTx interrupts. 565c97a3872SJohn BaldwinUnlike other tunables in this list, 566c97a3872SJohn Baldwinthese do not have corresponding sysctl nodes. 567c97a3872SJohn BaldwinThe tunable name includes the address of the PCI device as well as the 568c97a3872SJohn Baldwinpin of the desired INTx IRQ to override: 569c97a3872SJohn Baldwin.Bl -tag -width indent 570c97a3872SJohn Baldwin.It <D> 571c97a3872SJohn BaldwinThe domain 572c97a3872SJohn Baldwin.Pq or segment 573c97a3872SJohn Baldwinof the PCI device in decimal. 574c97a3872SJohn Baldwin.It <B> 575c97a3872SJohn BaldwinThe bus address of the PCI device in decimal. 576c97a3872SJohn Baldwin.It <S> 577c97a3872SJohn BaldwinThe slot of the PCI device in decimal. 578c97a3872SJohn Baldwin.It <P> 579c97a3872SJohn BaldwinThe interrupt pin of the PCI slot to override. 580c97a3872SJohn BaldwinOne of 581c97a3872SJohn Baldwin.Ql A , 582c97a3872SJohn Baldwin.Ql B , 583c97a3872SJohn Baldwin.Ql C , 584c97a3872SJohn Baldwinor 585c97a3872SJohn Baldwin.Ql D . 586c97a3872SJohn Baldwin.El 587c97a3872SJohn Baldwin.Pp 588c97a3872SJohn BaldwinThe value of the tunable is the raw IRQ value to use for the INTx interrupt 589c97a3872SJohn Baldwinpin identified by the tunable name. 590c97a3872SJohn BaldwinMapping of IRQ values to platform interrupt sources is machine dependent. 591c97a3872SJohn Baldwin.El 5929b94cc24SWarner Losh.Sh DEVICE WIRING 5939b94cc24SWarner LoshYou can wire the device unit at a given location with device.hints. 5949b94cc24SWarner LoshEntries of the form 5959b94cc24SWarner Losh.Va hints.<name>.<unit>.at="pci<B>:<S>:<F>" 5969b94cc24SWarner Loshor 5979b94cc24SWarner Losh.Va hints.<name>.<unit>.at="pci<D>:<B>:<S>:<F>" 5989b94cc24SWarner Loshwill force the driver 5999b94cc24SWarner Losh.Va name 6009b94cc24SWarner Loshto probe and attach at unit 6019b94cc24SWarner Losh.Va unit 6029b94cc24SWarner Loshfor any PCI device found to match the specification, where: 6039b94cc24SWarner Losh.Bl -tag -width -indent 6049b94cc24SWarner Losh.It <D> 6059b94cc24SWarner LoshThe domain 6069b94cc24SWarner Losh.Pq or segment 6079b94cc24SWarner Loshof the PCI device in decimal. 6089b94cc24SWarner LoshDefaults to 0 if unspecified 6099b94cc24SWarner Losh.It <B> 6109b94cc24SWarner LoshThe bus address of the PCI device in decimal. 6119b94cc24SWarner Losh.It <S> 6129b94cc24SWarner LoshThe slot of the PCI device in decimal. 6139b94cc24SWarner Losh.It <F> 6149b94cc24SWarner LoshThe function of the PCI device in decimal. 6159b94cc24SWarner Losh.El 6169b94cc24SWarner Losh.Pp 6179b94cc24SWarner LoshThe code to do the matching requires an exact string match. 6189b94cc24SWarner LoshDo not specify the angle brackets 6199b94cc24SWarner Losh.Pq < > 6209b94cc24SWarner Loshin the hints file. 6219b94cc24SWarner LoshWiring multiple devices to the same 6229b94cc24SWarner Losh.Va name 6239b94cc24SWarner Loshand 6249b94cc24SWarner Losh.Va unit 6259b94cc24SWarner Loshproduces undefined results. 6269b94cc24SWarner Losh.Ss Examples 6279b94cc24SWarner LoshGiven the following lines in 6289b94cc24SWarner Losh.Pa /boot/device.hints : 6299b94cc24SWarner Losh.Cd hint.nvme.3.at="pci6:0:0" 6309b94cc24SWarner Losh.Cd hint.igb.8.at="pci14:0:0" 6319b94cc24SWarner LoshIf there is a device that supports 6329b94cc24SWarner Losh.Xr igb 4 6339b94cc24SWarner Loshat PCI bus 14 slot 0 function 0, 6349b94cc24SWarner Loshthen it will be assigned igb8 for probe and attach. 6359b94cc24SWarner LoshLikewise, if there is an 6369b94cc24SWarner Losh.Xr nvme 4 6379b94cc24SWarner Loshcard at PCI bus 6 slot 0 function 0, 6389b94cc24SWarner Loshthen it will be assigned nvme3 for probe and attach. 6399b94cc24SWarner LoshIf another type of card is in either of these locations, the name and 6409b94cc24SWarner Loshunit of that card will be the default names and will be unaffected by 6419b94cc24SWarner Loshthese hints. 6429b94cc24SWarner LoshIf other igb or nvme cards are located elsewhere, they will be 6439b94cc24SWarner Loshassigned their unit numbers sequentially, skipping the unit numbers 6449b94cc24SWarner Loshthat have 'at' hints. 64564ae346bSKenneth D. Merry.Sh FILES 6463136363fSRuslan Ermilov.Bl -tag -width /dev/pci -compact 64764ae346bSKenneth D. Merry.It Pa /dev/pci 64864ae346bSKenneth D. MerryCharacter device for the 6494b66483fSRuslan Ermilov.Nm 65064ae346bSKenneth D. Merrydriver. 65164ae346bSKenneth D. Merry.El 65264ae346bSKenneth D. Merry.Sh SEE ALSO 65364ae346bSKenneth D. Merry.Xr pciconf 8 65464ae346bSKenneth D. Merry.Sh HISTORY 65564ae346bSKenneth D. MerryThe 6564b66483fSRuslan Ermilov.Nm 65764ae346bSKenneth D. Merrydriver (not the kernel's 65864ae346bSKenneth D. Merry.Tn PCI 65964ae346bSKenneth D. Merrysupport code) first appeared in 66064ae346bSKenneth D. Merry.Fx 2.2 , 66164ae346bSKenneth D. Merryand was written by Stefan Esser and Garrett Wollman. 66264ae346bSKenneth D. MerrySupport for device listing and matching was re-implemented by 66364ae346bSKenneth D. MerryKenneth Merry, and first appeared in 66464ae346bSKenneth D. Merry.Fx 3.0 . 66564ae346bSKenneth D. Merry.Sh AUTHORS 6666c899950SBaptiste Daroussin.An Kenneth Merry Aq Mt ken@FreeBSD.org 66764ae346bSKenneth D. Merry.Sh BUGS 6680227791bSRuslan ErmilovIt is not possible for users to specify an accurate offset into the device 66964ae346bSKenneth D. Merrylist without calling the 67064ae346bSKenneth D. Merry.Dv PCIOCGETCONF 67164ae346bSKenneth D. Merryat least once, since they have no way of knowing the current generation 672b5e7e999SRuslan Ermilovnumber otherwise. 6730227791bSRuslan ErmilovThis probably is not a serious problem, though, since 67464ae346bSKenneth D. Merryusers can easily narrow their search by specifying a pattern or patterns 67564ae346bSKenneth D. Merryfor the kernel to match against. 676