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*87842989SKonstantin Belousov.Dd June 14, 2018 2864ae346bSKenneth D. Merry.Dt PCI 4 293d45e180SRuslan Ermilov.Os 3064ae346bSKenneth D. Merry.Sh NAME 3164ae346bSKenneth D. Merry.Nm pci 32c97a3872SJohn Baldwin.Nd generic PCI 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 56c97a3872SJohn Baldwindevices in the kernel and limited access to 57c97a3872SJohn Baldwin.Tn PCI 58c97a3872SJohn Baldwindevices for userland. 59c97a3872SJohn Baldwin.Pp 60c97a3872SJohn BaldwinThe 61c97a3872SJohn Baldwin.Nm 62c97a3872SJohn Baldwindriver provides a 63c97a3872SJohn Baldwin.Pa /dev/pci 64c97a3872SJohn Baldwincharacter device that can be used by userland programs to read and write 6564ae346bSKenneth D. Merry.Tn PCI 66b5e7e999SRuslan Ermilovconfiguration registers. 67c97a3872SJohn BaldwinPrograms can also use this device to get a list of all 6864ae346bSKenneth D. Merry.Tn PCI 6964ae346bSKenneth D. Merrydevices, or all 7064ae346bSKenneth D. Merry.Tn PCI 7164ae346bSKenneth D. Merrydevices that match various patterns. 7264ae346bSKenneth D. Merry.Pp 7364ae346bSKenneth D. MerrySince the 744b66483fSRuslan Ermilov.Nm 7564ae346bSKenneth D. Merrydriver provides a write interface for 7664ae346bSKenneth D. Merry.Tn PCI 7764ae346bSKenneth D. Merryconfiguration registers, system administrators should exercise caution when 7864ae346bSKenneth D. Merrygranting access to the 794b66483fSRuslan Ermilov.Nm 80b5e7e999SRuslan Ermilovdevice. 81b5e7e999SRuslan ErmilovIf used improperly, this driver can allow userland applications to 8264ae346bSKenneth D. Merrycrash a machine or cause data loss. 830ade47aeSWarner Losh.Pp 840ade47aeSWarner LoshThe 854b66483fSRuslan Ermilov.Nm 86c0c7deaaSChristian Bruefferdriver implements the 87c0c7deaaSChristian Brueffer.Tn PCI 88c0c7deaaSChristian Bruefferbus in the kernel. 89c0c7deaaSChristian BruefferIt enumerates any devices on the 90c0c7deaaSChristian Brueffer.Tn PCI 91c0c7deaaSChristian Bruefferbus and gives 92c0c7deaaSChristian Brueffer.Tn PCI 93c0c7deaaSChristian Bruefferclient drivers the chance to attach to them. 94c0c7deaaSChristian BruefferIt assigns resources to children, when the BIOS does not. 950ade47aeSWarner LoshIt takes care of routing interrupts when necessary. 96c0c7deaaSChristian BruefferIt reprobes the unattached 97c0c7deaaSChristian Brueffer.Tn PCI 98c0c7deaaSChristian Bruefferchildren when 99c0c7deaaSChristian Brueffer.Tn PCI 100c0c7deaaSChristian Bruefferclient drivers are dynamically 1010ade47aeSWarner Loshloaded at runtime. 1020ade47aeSWarner LoshThe 1030ade47aeSWarner Losh.Nm 104c97a3872SJohn Baldwindriver also includes support for PCI-PCI bridges, 105c97a3872SJohn Baldwinvarious platform-specific Host-PCI bridges, 106c97a3872SJohn Baldwinand basic support for 107c97a3872SJohn Baldwin.Tn PCI 108c97a3872SJohn BaldwinVGA adapters. 10964ae346bSKenneth D. Merry.Sh IOCTLS 11064ae346bSKenneth D. MerryThe following 11164ae346bSKenneth D. Merry.Xr ioctl 2 11264ae346bSKenneth D. Merrycalls are supported by the 1134b66483fSRuslan Ermilov.Nm 114b5e7e999SRuslan Ermilovdriver. 115b5e7e999SRuslan ErmilovThey are defined in the header file 116fe08efe6SRuslan Ermilov.In sys/pciio.h . 11764ae346bSKenneth D. Merry.Bl -tag -width 012345678901234 11864ae346bSKenneth D. Merry.It PCIOCGETCONF 11964ae346bSKenneth D. MerryThis 12064ae346bSKenneth D. Merry.Xr ioctl 2 12164ae346bSKenneth D. Merrytakes a 12264ae346bSKenneth D. Merry.Va pci_conf_io 123b5e7e999SRuslan Ermilovstructure. 124b5e7e999SRuslan ErmilovIt allows the user to retrieve information on all 12564ae346bSKenneth D. Merry.Tn PCI 12664ae346bSKenneth D. Merrydevices in the system, or on 12764ae346bSKenneth D. Merry.Tn PCI 1285203edcdSRuslan Ermilovdevices matching patterns supplied by the user. 1295203edcdSRuslan ErmilovThe call may set 13007e3ed79SJohn-Mark Gurney.Va errno 13107e3ed79SJohn-Mark Gurneyto any value specified in either 13207e3ed79SJohn-Mark Gurney.Xr copyin 9 13307e3ed79SJohn-Mark Gurneyor 13407e3ed79SJohn-Mark Gurney.Xr copyout 9 . 13564ae346bSKenneth D. MerryThe 13664ae346bSKenneth D. Merry.Va pci_conf_io 13764ae346bSKenneth D. Merrystructure consists of a number of fields: 13864ae346bSKenneth D. Merry.Bl -tag -width match_buf_len 13964ae346bSKenneth D. Merry.It pat_buf_len 14064ae346bSKenneth D. MerryThe length, in bytes, of the buffer filled with user-supplied patterns. 14164ae346bSKenneth D. Merry.It num_patterns 14264ae346bSKenneth D. MerryThe number of user-supplied patterns. 14364ae346bSKenneth D. Merry.It patterns 14464ae346bSKenneth D. MerryPointer to a buffer filled with user-supplied patterns. 14564ae346bSKenneth D. Merry.Va patterns 14664ae346bSKenneth D. Merryis a pointer to 14764ae346bSKenneth D. Merry.Va num_patterns 14864ae346bSKenneth D. Merry.Va pci_match_conf 1495203edcdSRuslan Ermilovstructures. 1505203edcdSRuslan ErmilovThe 15164ae346bSKenneth D. Merry.Va pci_match_conf 15264ae346bSKenneth D. Merrystructure consists of the following elements: 15364ae346bSKenneth D. Merry.Bl -tag -width pd_vendor 15464ae346bSKenneth D. Merry.It pc_sel 15564ae346bSKenneth D. Merry.Tn PCI 15655aaf894SMarius Strobldomain, bus, slot and function. 15764ae346bSKenneth D. Merry.It pd_name 15864ae346bSKenneth D. Merry.Tn PCI 15964ae346bSKenneth D. Merrydevice driver name. 16064ae346bSKenneth D. Merry.It pd_unit 16164ae346bSKenneth D. Merry.Tn PCI 16264ae346bSKenneth D. Merrydevice driver unit number. 16364ae346bSKenneth D. Merry.It pc_vendor 16464ae346bSKenneth D. Merry.Tn PCI 16564ae346bSKenneth D. Merryvendor ID. 16664ae346bSKenneth D. Merry.It pc_device 16764ae346bSKenneth D. Merry.Tn PCI 16864ae346bSKenneth D. Merrydevice ID. 16964ae346bSKenneth D. Merry.It pc_class 17064ae346bSKenneth D. Merry.Tn PCI 17164ae346bSKenneth D. Merrydevice class. 17264ae346bSKenneth D. Merry.It flags 17364ae346bSKenneth D. MerryThe flags describe which of the fields the kernel should match against. 174b5e7e999SRuslan ErmilovA device must match all specified fields in order to be returned. 175b5e7e999SRuslan ErmilovThe match flags are enumerated in the 17664ae346bSKenneth D. Merry.Va pci_getconf_flags 17764ae346bSKenneth D. Merrystructure. 1780227791bSRuslan ErmilovHopefully the flag values are obvious enough that they do not need to 17964ae346bSKenneth D. Merrydescribed in detail. 18064ae346bSKenneth D. Merry.El 18164ae346bSKenneth D. Merry.It match_buf_len 18264ae346bSKenneth D. MerryLength of the 18364ae346bSKenneth D. Merry.Va matches 18464ae346bSKenneth D. Merrybuffer allocated by the user to hold the results of the 18564ae346bSKenneth D. Merry.Dv PCIOCGETCONF 18664ae346bSKenneth D. Merryquery. 18764ae346bSKenneth D. Merry.It num_matches 18864ae346bSKenneth D. MerryNumber of matches returned by the kernel. 18964ae346bSKenneth D. Merry.It matches 190b5e7e999SRuslan ErmilovBuffer containing matching devices returned by the kernel. 191b5e7e999SRuslan ErmilovThe items in this buffer are of type 19264ae346bSKenneth D. Merry.Va pci_conf , 19364ae346bSKenneth D. Merrywhich consists of the following items: 19464ae346bSKenneth D. Merry.Bl -tag -width pc_subvendor 19564ae346bSKenneth D. Merry.It pc_sel 19664ae346bSKenneth D. Merry.Tn PCI 19755aaf894SMarius Strobldomain, bus, slot and function. 19864ae346bSKenneth D. Merry.It pc_hdr 19964ae346bSKenneth D. Merry.Tn PCI 20064ae346bSKenneth D. Merryheader type. 20164ae346bSKenneth D. Merry.It pc_subvendor 20264ae346bSKenneth D. Merry.Tn PCI 20364ae346bSKenneth D. Merrysubvendor ID. 20464ae346bSKenneth D. Merry.It pc_subdevice 20564ae346bSKenneth D. Merry.Tn PCI 20664ae346bSKenneth D. Merrysubdevice ID. 20764ae346bSKenneth D. Merry.It pc_vendor 20864ae346bSKenneth D. Merry.Tn PCI 20964ae346bSKenneth D. Merryvendor ID. 21064ae346bSKenneth D. Merry.It pc_device 21164ae346bSKenneth D. Merry.Tn PCI 21264ae346bSKenneth D. Merrydevice ID. 21364ae346bSKenneth D. Merry.It pc_class 21464ae346bSKenneth D. Merry.Tn PCI 21564ae346bSKenneth D. Merrydevice class. 21664ae346bSKenneth D. Merry.It pc_subclass 21764ae346bSKenneth D. Merry.Tn PCI 21864ae346bSKenneth D. Merrydevice subclass. 21964ae346bSKenneth D. Merry.It pc_progif 22064ae346bSKenneth D. Merry.Tn PCI 22164ae346bSKenneth D. Merrydevice programming interface. 22264ae346bSKenneth D. Merry.It pc_revid 22364ae346bSKenneth D. Merry.Tn PCI 22464ae346bSKenneth D. Merryrevision ID. 22564ae346bSKenneth D. Merry.It pd_name 22664ae346bSKenneth D. MerryDriver name. 22764ae346bSKenneth D. Merry.It pd_unit 22864ae346bSKenneth D. MerryDriver unit number. 22964ae346bSKenneth D. Merry.El 23064ae346bSKenneth D. Merry.It offset 23164ae346bSKenneth D. MerryThe offset is passed in by the user to tell the kernel where it should 232b5e7e999SRuslan Ermilovstart traversing the device list. 233b5e7e999SRuslan ErmilovThe value passed out by the kernel 234b5e7e999SRuslan Ermilovpoints to the record immediately after the last one returned. 235b5e7e999SRuslan ErmilovThe user may 23664ae346bSKenneth D. Merrypass the value returned by the kernel in subsequent calls to the 23764ae346bSKenneth D. Merry.Dv PCIOCGETCONF 238b5e7e999SRuslan Ermilovioctl. 239b5e7e999SRuslan ErmilovIf the user does not intend to use the offset, it must be set to zero. 24064ae346bSKenneth D. Merry.It generation 24164ae346bSKenneth D. Merry.Tn PCI 242b5e7e999SRuslan Ermilovconfiguration generation. 243b5e7e999SRuslan ErmilovThis value only needs to be set if the offset is set. 244b5e7e999SRuslan ErmilovThe kernel will compare the current generation number of its internal 24564ae346bSKenneth D. Merrydevice list to the generation passed in by the user to determine whether 24664ae346bSKenneth D. Merryits device list has changed since the user last called the 24764ae346bSKenneth D. Merry.Dv PCIOCGETCONF 248b5e7e999SRuslan Ermilovioctl. 249b5e7e999SRuslan ErmilovIf the device list has changed, a status of 25064ae346bSKenneth D. Merry.Va PCI_GETCONF_LIST_CHANGED 25164ae346bSKenneth D. Merrywill be passed back. 25264ae346bSKenneth D. Merry.It status 25364ae346bSKenneth D. MerryThe status tells the user the disposition of his request for a device list. 25464ae346bSKenneth D. MerryThe possible status values are: 25564ae346bSKenneth D. Merry.Bl -ohang 25664ae346bSKenneth D. Merry.It PCI_GETCONF_LAST_DEVICE 25710012d53SJohn BaldwinThis means that there are no more devices in the PCI device list matching 25810012d53SJohn Baldwinthe specified criteria after the 25964ae346bSKenneth D. Merryones returned in the 26064ae346bSKenneth D. Merry.Va matches 26164ae346bSKenneth D. Merrybuffer. 26264ae346bSKenneth D. Merry.It PCI_GETCONF_LIST_CHANGED 26364ae346bSKenneth D. MerryThis status tells the user that the 26464ae346bSKenneth D. Merry.Tn PCI 26564ae346bSKenneth D. Merrydevice list has changed since his last call to the 26664ae346bSKenneth D. Merry.Dv PCIOCGETCONF 26764ae346bSKenneth D. Merryioctl and he must reset the 26864ae346bSKenneth D. Merry.Va offset 26964ae346bSKenneth D. Merryand 27064ae346bSKenneth D. Merry.Va generation 27164ae346bSKenneth D. Merryto zero to start over at the beginning of the list. 27264ae346bSKenneth D. Merry.It PCI_GETCONF_MORE_DEVS 27364ae346bSKenneth D. MerryThis tells the user that his buffer was not large enough to hold all of the 27410012d53SJohn Baldwinremaining devices in the device list that match his criteria. 27564ae346bSKenneth D. Merry.It PCI_GETCONF_ERROR 276b5e7e999SRuslan ErmilovThis indicates a general error while servicing the user's request. 277b5e7e999SRuslan ErmilovIf the 27807e3ed79SJohn-Mark Gurney.Va pat_buf_len 27907e3ed79SJohn-Mark Gurneyis not equal to 28007e3ed79SJohn-Mark Gurney.Va num_patterns 28107e3ed79SJohn-Mark Gurneytimes 282b5e7e999SRuslan Ermilov.Fn sizeof "struct pci_match_conf" , 283b5e7e999SRuslan Ermilov.Va errno 284b5e7e999SRuslan Ermilovwill be set to 285b5e7e999SRuslan Ermilov.Er EINVAL . 28664ae346bSKenneth D. Merry.El 28764ae346bSKenneth D. Merry.El 28864ae346bSKenneth D. Merry.It PCIOCREAD 28964ae346bSKenneth D. MerryThis 29064ae346bSKenneth D. Merry.Xr ioctl 2 29164ae346bSKenneth D. Merryreads the 29264ae346bSKenneth D. Merry.Tn PCI 29364ae346bSKenneth D. Merryconfiguration registers specified by the passed-in 29464ae346bSKenneth D. Merry.Va pci_io 2955203edcdSRuslan Ermilovstructure. 2965203edcdSRuslan ErmilovThe 29764ae346bSKenneth D. Merry.Va pci_io 29864ae346bSKenneth D. Merrystructure consists of the following fields: 29964ae346bSKenneth D. Merry.Bl -tag -width pi_width 30064ae346bSKenneth D. Merry.It pi_sel 30164ae346bSKenneth D. MerryA 30264ae346bSKenneth D. Merry.Va pcisel 30355aaf894SMarius Stroblstructure which specifies the domain, bus, slot and function the user would 30455aaf894SMarius Strobllike to query. 30555aaf894SMarius StroblIf the specific bus is not found, errno will be set to ENODEV and -1 returned 30655aaf894SMarius Stroblfrom the ioctl. 30764ae346bSKenneth D. Merry.It pi_reg 30864ae346bSKenneth D. MerryThe 30964ae346bSKenneth D. Merry.Tn PCI 31064ae346bSKenneth D. Merryconfiguration register the user would like to access. 31164ae346bSKenneth D. Merry.It pi_width 312b5e7e999SRuslan ErmilovThe width, in bytes, of the data the user would like to read. 313b5e7e999SRuslan ErmilovThis value 3145203edcdSRuslan Ermilovmay be either 1, 2, or 4. 3155203edcdSRuslan Ermilov3-byte reads and reads larger than 4 bytes are 3165203edcdSRuslan Ermilovnot supported. 3175203edcdSRuslan ErmilovIf an invalid width is passed, errno will be set to EINVAL. 31864ae346bSKenneth D. Merry.It pi_data 31964ae346bSKenneth D. MerryThe data returned by the kernel. 32064ae346bSKenneth D. Merry.El 32164ae346bSKenneth D. Merry.It PCIOCWRITE 32264ae346bSKenneth D. MerryThis 32364ae346bSKenneth D. Merry.Xr ioctl 2 32464ae346bSKenneth D. Merryallows users to write to the 32564ae346bSKenneth D. Merry.Tn PCI 32664ae346bSKenneth D. Merryspecified in the passed-in 32764ae346bSKenneth D. Merry.Va pci_io 3285203edcdSRuslan Ermilovstructure. 3295203edcdSRuslan ErmilovThe 33064ae346bSKenneth D. Merry.Va pci_io 331b5e7e999SRuslan Ermilovstructure is described above. 332b5e7e999SRuslan ErmilovThe limitations on data width described for 33364ae346bSKenneth D. Merryreading registers, above, also apply to writing 33464ae346bSKenneth D. Merry.Tn PCI 33564ae346bSKenneth D. Merryconfiguration registers. 336*87842989SKonstantin Belousov.It PCIOCBARMMAP 337*87842989SKonstantin BelousovThis 338*87842989SKonstantin Belousov.Xr ioctl 2 339*87842989SKonstantin Belousovcommand allows userspace processes to 340*87842989SKonstantin Belousov.Xr mmap 2 341*87842989SKonstantin Belousovthe memory-mapped PCI BAR into its address space. 342*87842989SKonstantin BelousovThe input parameters and results are passed in the 343*87842989SKonstantin Belousov.Va pci_bar_mmap 344*87842989SKonstantin Belousovstructure, which has the following fields: 345*87842989SKonstantin Belousov.Bl -tag -width Vt struct pcise pbm_sel 346*87842989SKonstantin Belousov.It Vt uint64_t pbm_map_base 347*87842989SKonstantin BelousovReports the established mapping base to the caller. 348*87842989SKonstantin BelousovIf 349*87842989SKonstantin Belousov.Va PCIIO_BAR_MMAP_FIXED 350*87842989SKonstantin Belousovflag was specified, then this field must be filled before the call 351*87842989SKonstantin Belousovwith the desired address for the mapping. 352*87842989SKonstantin Belousov.It Vt uint64_t pbm_map_length 353*87842989SKonstantin BelousovReports the mapped length of the BAR, in bytes. 354*87842989SKonstantin BelousovIts .Vt uint64_t value is always multiple of machine pages. 355*87842989SKonstantin Belousov.It Vt int64_t pbm_bar_length 356*87842989SKonstantin BelousovReports length of the bar as exposed by the device. 357*87842989SKonstantin Belousov.It Vt int pbm_bar_off 358*87842989SKonstantin BelousovReports offset from the mapped base to the start of the 359*87842989SKonstantin Belousovfirst register in the bar. 360*87842989SKonstantin Belousov.It Vt struct pcisel pbm_sel 361*87842989SKonstantin BelousovShould be filled before the call. 362*87842989SKonstantin BelousovDescribes the device to operate on. 363*87842989SKonstantin Belousov.It Vt int pbm_reg 364*87842989SKonstantin BelousovThe BAR index to mmap. 365*87842989SKonstantin Belousov.It Vt int pbm_flags 366*87842989SKonstantin BelousovFlags which augments the operation. 367*87842989SKonstantin BelousovSee below. 368*87842989SKonstantin Belousov.It Vt int pbm_memattr 369*87842989SKonstantin BelousovThe caching attribute for the mapping. 370*87842989SKonstantin BelousovTypical values are 371*87842989SKonstantin Belousov.Dv VM_MEMATTR_UNCACHEABLE 372*87842989SKonstantin Belousovfor control registers BARs, and 373*87842989SKonstantin Belousov.Dv VM_MEMATTR_WRITE_COMBINING 374*87842989SKonstantin Belousovfor frame buffers. 375*87842989SKonstantin BelousovRegular memory-like BAR should be mapped with 376*87842989SKonstantin Belousov.Dv VM_MEMATTR_DEFAULT 377*87842989SKonstantin Belousovattribute. 378*87842989SKonstantin Belousov.El 379*87842989SKonstantin Belousov.Pp 380*87842989SKonstantin BelousovCurrently defined flags are: 381*87842989SKonstantin Belousov.Bl -tag -width PCIIO_BAR_MMAP_ACTIVATE 382*87842989SKonstantin Belousov.It PCIIO_BAR_MMAP_FIXED 383*87842989SKonstantin BelousovThe resulted mappings should be established at the address 384*87842989SKonstantin Belousovspecified by the 385*87842989SKonstantin Belousov.Va pbm_map_base 386*87842989SKonstantin Belousovmember, otherwise fail. 387*87842989SKonstantin Belousov.It PCIIO_BAR_MMAP_EXCL 388*87842989SKonstantin BelousovMust be used together with 389*87842989SKonstantin Belousov.Vd PCIIO_BAR_MMAP_FIXED 390*87842989SKonstantin BelousovIf the specified base contains already established mappings, the 391*87842989SKonstantin Belousovoperation fails instead of implicitly unmapping them. 392*87842989SKonstantin Belousov.It PCIIO_BAR_MMAP_RW 393*87842989SKonstantin BelousovThe requested mapping allows both reading and writing. 394*87842989SKonstantin BelousovWithout the flag, read-only mapping is established. 395*87842989SKonstantin BelousovNote that it is common for the device registers to have side-effects 396*87842989SKonstantin Belousoveven on reads. 397*87842989SKonstantin Belousov.It PCIIO_BAR_MMAP_ACTIVATE 398*87842989SKonstantin Belousov(Unimplemented) If the BAR is not activated, activate it in the course 399*87842989SKonstantin Belousovof mapping. 400*87842989SKonstantin BelousovCurrently attempt to mmap an inactive BAR results in error. 401*87842989SKonstantin Belousov.El 40264ae346bSKenneth D. Merry.El 403c97a3872SJohn Baldwin.Sh LOADER TUNABLES 404c97a3872SJohn BaldwinTunables can be set at the 405c97a3872SJohn Baldwin.Xr loader 8 406c97a3872SJohn Baldwinprompt before booting the kernel, or stored in 407c97a3872SJohn Baldwin.Xr loader.conf 5 . 408c97a3872SJohn BaldwinThe current value of these tunables can be examined at runtime via 409c97a3872SJohn Baldwin.Xr sysctl 8 410c97a3872SJohn Baldwinnodes of the same name. 411c97a3872SJohn BaldwinUnless otherwise specified, 412c97a3872SJohn Baldwineach of these tunables is a boolean that can be enabled by setting the 413c97a3872SJohn Baldwintunable to a non-zero value. 414c97a3872SJohn Baldwin.Bl -tag -width indent 415c97a3872SJohn Baldwin.It Va hw.pci.clear_bars Pq Defaults to 0 416c97a3872SJohn BaldwinIgnore any firmware-assigned memory and I/O port resources. 417c97a3872SJohn BaldwinThis forces the 418c97a3872SJohn Baldwin.Tn PCI 419c97a3872SJohn Baldwinbus driver to allocate resource ranges for memory and I/O port resources 420c97a3872SJohn Baldwinfrom scratch. 421c97a3872SJohn Baldwin.It Va hw.pci.clear_buses Pq Defaults to 0 422c97a3872SJohn BaldwinIgnore any firmware-assigned bus number registers in PCI-PCI bridges. 423c97a3872SJohn BaldwinThis forces the 424c97a3872SJohn Baldwin.Tn PCI 425c97a3872SJohn Baldwinbus driver and PCI-PCI bridge driver to allocate bus numbers for secondary 426c97a3872SJohn Baldwinbuses behind PCI-PCI bridges. 427c97a3872SJohn Baldwin.It Va hw.pci.clear_pcib Pq Defaults to 0 428c97a3872SJohn BaldwinIgnore any firmware-assigned memory and I/O port resource windows in PCI-PCI 429c97a3872SJohn Baldwinbridges. 430c97a3872SJohn BaldwinThis forces the PCI-PCI bridge driver to allocate memory and I/O port resources 431c97a3872SJohn Baldwinfor resource windows from scratch. 432c97a3872SJohn Baldwin.Pp 433c97a3872SJohn BaldwinBy default the PCI-PCI bridge driver will allocate windows that 434c97a3872SJohn Baldwincontain the firmware-assigned resources devices behind the bridge. 435c97a3872SJohn BaldwinIn addition, the PCI-PCI bridge driver will suballocate from existing window 436c97a3872SJohn Baldwinregions when possible to satisfy a resource request. 437c97a3872SJohn BaldwinAs a result, 438c97a3872SJohn Baldwinboth 439c97a3872SJohn Baldwin.Va hw.pci.clear_bars 440c97a3872SJohn Baldwinand 441c97a3872SJohn Baldwin.Va hw.pci.clear_pcib 442c97a3872SJohn Baldwinmust be enabled to fully ignore firmware-supplied resource assignments. 443c97a3872SJohn Baldwin.It Va hw.pci.default_vgapci_unit Pq Defaults to -1 444c97a3872SJohn BaldwinBy default, 445c97a3872SJohn Baldwinthe first 446c97a3872SJohn Baldwin.Tn PCI 447c97a3872SJohn BaldwinVGA adapter encountered by the system is assumed to be the boot display device. 448c97a3872SJohn BaldwinThis tunable can be set to choose a specific VGA adapter by specifying the 449c97a3872SJohn Baldwinunit number of the associated 450c97a3872SJohn Baldwin.Va vgapci Ns Ar X 451c97a3872SJohn Baldwindevice. 452c97a3872SJohn Baldwin.It Va hw.pci.do_power_nodriver Pq Defaults to 0 453c97a3872SJohn BaldwinPlace devices into a low power state 454c97a3872SJohn Baldwin.Pq D3 455c97a3872SJohn Baldwinwhen a suitable device driver is not found. 456c97a3872SJohn BaldwinCan be set to one of the following values: 457c97a3872SJohn Baldwin.Bl -tag -width indent 458c97a3872SJohn Baldwin.It 3 459c97a3872SJohn BaldwinPowers down all 460c97a3872SJohn Baldwin.Tn PCI 461c97a3872SJohn Baldwindevices without a device driver. 462c97a3872SJohn Baldwin.It 2 463c97a3872SJohn BaldwinPowers down most devices without a device driver. 464c97a3872SJohn BaldwinPCI devices with the display, memory, and base peripheral device classes 465c97a3872SJohn Baldwinare not powered down. 466c97a3872SJohn Baldwin.It 1 467c97a3872SJohn BaldwinSimilar to a setting of 2 except that storage controllers are also not 468c97a3872SJohn Baldwinpowered down. 469c97a3872SJohn Baldwin.It 0 470c97a3872SJohn BaldwinAll devices are left fully powered. 471c97a3872SJohn Baldwin.El 472c97a3872SJohn Baldwin.Pp 473c97a3872SJohn BaldwinA 474c97a3872SJohn Baldwin.Tn PCI 475c97a3872SJohn Baldwindevice must support power management to be powered down. 476c97a3872SJohn BaldwinPlacing a device into a low power state may not reduce power consumption. 477c97a3872SJohn Baldwin.It Va hw.pci.do_power_resume Pq Defaults to 1 478c97a3872SJohn BaldwinPlace 479c97a3872SJohn Baldwin.Tn PCI 480c97a3872SJohn Baldwindevices into the fully powered state when resuming either the system or an 481c97a3872SJohn Baldwinindividual device. 482c97a3872SJohn BaldwinSetting this to zero is discouraged as the system will not attempt to power 483c97a3872SJohn Baldwinup non-powered PCI devices after a suspend. 484c97a3872SJohn Baldwin.It Va hw.pci.do_power_suspend Pq Defaults to 1 485c97a3872SJohn BaldwinPlace 486c97a3872SJohn Baldwin.Tn PCI 487c97a3872SJohn Baldwindevices into a low power state when suspending either the system or individual 488c97a3872SJohn Baldwindevices. 489c97a3872SJohn BaldwinNormally the D3 state is used as the low power state, 490c97a3872SJohn Baldwinbut firmware may override the desired power state during a system suspend. 491c97a3872SJohn Baldwin.It Va hw.pci.enable_ari Pq Defaults to 1 492c97a3872SJohn BaldwinEnable support for PCI-express Alternative RID Interpretation. 493c97a3872SJohn BaldwinThis is often used in conjunction with SR-IOV. 494c97a3872SJohn Baldwin.It Va hw.pci.enable_io_modes Pq Defaults to 1 495c97a3872SJohn BaldwinEnable memory or I/O port decoding in a PCI device's command register if it has 496c97a3872SJohn Baldwinfirmware-assigned memory or I/O port resources. 497c97a3872SJohn BaldwinThe firmware 498c97a3872SJohn Baldwin.Pq BIOS 499c97a3872SJohn Baldwinin some systems does not enable memory or I/O port decoding for some devices 500c97a3872SJohn Baldwineven when it has assigned resources to the device. 501c97a3872SJohn BaldwinThis enables decoding for such resources during bus probe. 502c97a3872SJohn Baldwin.It Va hw.pci.enable_msi Pq Defaults to 1 503c97a3872SJohn BaldwinEnable support for Message Signalled Interrupts 504c97a3872SJohn Baldwin.Pq MSI . 505c97a3872SJohn BaldwinMSI interrupts can be disabled by setting this tunable to 0. 506c97a3872SJohn Baldwin.It Va hw.pci.enable_msix Pq Defaults to 1 507c97a3872SJohn BaldwinEnable support for extended Message Signalled Interrupts 508c97a3872SJohn Baldwin.Pq MSI-X . 509c97a3872SJohn BaldwinMSI-X interrupts can be disabled by setting this tunable to 0. 510c97a3872SJohn Baldwin.It Va hw.pci.enable_pcie_hp Pq Defaults to 1 511c97a3872SJohn BaldwinEnable support for native PCI-express HotPlug. 512c97a3872SJohn Baldwin.It Va hw.pci.honor_msi_blacklist Pq Defaults to 1 513c97a3872SJohn BaldwinMSI and MSI-X interrupts are disabled for certain chipsets known to have 514c97a3872SJohn Baldwinbroken MSI and MSI-X implementations when this tunable is set. 515c97a3872SJohn BaldwinIt can be set to zero to permit use of MSI and MSI-X interrupts if the 516c97a3872SJohn Baldwinchipset match is a false positive. 517c97a3872SJohn Baldwin.It Va hw.pci.iov_max_config Pq Defaults to 1MB 518c97a3872SJohn BaldwinThe maximum amount of memory permitted for the configuration parameters 519c97a3872SJohn Baldwinused when creating Virtual Functions via SR-IOV. 520c97a3872SJohn BaldwinThis tunable can also be changed at runtime via 521c97a3872SJohn Baldwin.Xr sysctl 8 . 522c97a3872SJohn Baldwin.It Va hw.pci.realloc_bars Pq Defaults to 0 523c97a3872SJohn BaldwinAttempt to allocate a new resource range during the initial device scan 524c97a3872SJohn Baldwinfor any memory or I/O port resources with firmware-assigned ranges that 525c97a3872SJohn Baldwinconflict with another active resource. 526c97a3872SJohn Baldwin.It Va hw.pci.usb_early_takeover Pq Defaults to 1 on Tn amd64 and Tn i386 527c97a3872SJohn BaldwinDisable legacy device emulation of USB devices during the initial device 528c97a3872SJohn Baldwinscan. 529c97a3872SJohn BaldwinSet this tunable to zero to use USB devices via legacy emulation when 530c97a3872SJohn Baldwinusing a custom kernel without USB controller drivers. 531c97a3872SJohn Baldwin.It Va hw.pci<D>.<B>.<S>.INT<P>.irq 532c97a3872SJohn BaldwinThese tunables can be used to override the interrupt routing for legacy 533c97a3872SJohn BaldwinPCI INTx interrupts. 534c97a3872SJohn BaldwinUnlike other tunables in this list, 535c97a3872SJohn Baldwinthese do not have corresponding sysctl nodes. 536c97a3872SJohn BaldwinThe tunable name includes the address of the PCI device as well as the 537c97a3872SJohn Baldwinpin of the desired INTx IRQ to override: 538c97a3872SJohn Baldwin.Bl -tag -width indent 539c97a3872SJohn Baldwin.It <D> 540c97a3872SJohn BaldwinThe domain 541c97a3872SJohn Baldwin.Pq or segment 542c97a3872SJohn Baldwinof the PCI device in decimal. 543c97a3872SJohn Baldwin.It <B> 544c97a3872SJohn BaldwinThe bus address of the PCI device in decimal. 545c97a3872SJohn Baldwin.It <S> 546c97a3872SJohn BaldwinThe slot of the PCI device in decimal. 547c97a3872SJohn Baldwin.It <P> 548c97a3872SJohn BaldwinThe interrupt pin of the PCI slot to override. 549c97a3872SJohn BaldwinOne of 550c97a3872SJohn Baldwin.Ql A , 551c97a3872SJohn Baldwin.Ql B , 552c97a3872SJohn Baldwin.Ql C , 553c97a3872SJohn Baldwinor 554c97a3872SJohn Baldwin.Ql D . 555c97a3872SJohn Baldwin.El 556c97a3872SJohn Baldwin.Pp 557c97a3872SJohn BaldwinThe value of the tunable is the raw IRQ value to use for the INTx interrupt 558c97a3872SJohn Baldwinpin identified by the tunable name. 559c97a3872SJohn BaldwinMapping of IRQ values to platform interrupt sources is machine dependent. 560c97a3872SJohn Baldwin.El 5619b94cc24SWarner Losh.Sh DEVICE WIRING 5629b94cc24SWarner LoshYou can wire the device unit at a given location with device.hints. 5639b94cc24SWarner LoshEntries of the form 5649b94cc24SWarner Losh.Va hints.<name>.<unit>.at="pci<B>:<S>:<F>" 5659b94cc24SWarner Loshor 5669b94cc24SWarner Losh.Va hints.<name>.<unit>.at="pci<D>:<B>:<S>:<F>" 5679b94cc24SWarner Loshwill force the driver 5689b94cc24SWarner Losh.Va name 5699b94cc24SWarner Loshto probe and attach at unit 5709b94cc24SWarner Losh.Va unit 5719b94cc24SWarner Loshfor any PCI device found to match the specification, where: 5729b94cc24SWarner Losh.Bl -tag -width -indent 5739b94cc24SWarner Losh.It <D> 5749b94cc24SWarner LoshThe domain 5759b94cc24SWarner Losh.Pq or segment 5769b94cc24SWarner Loshof the PCI device in decimal. 5779b94cc24SWarner LoshDefaults to 0 if unspecified 5789b94cc24SWarner Losh.It <B> 5799b94cc24SWarner LoshThe bus address of the PCI device in decimal. 5809b94cc24SWarner Losh.It <S> 5819b94cc24SWarner LoshThe slot of the PCI device in decimal. 5829b94cc24SWarner Losh.It <F> 5839b94cc24SWarner LoshThe function of the PCI device in decimal. 5849b94cc24SWarner Losh.El 5859b94cc24SWarner Losh.Pp 5869b94cc24SWarner LoshThe code to do the matching requires an exact string match. 5879b94cc24SWarner LoshDo not specify the angle brackets 5889b94cc24SWarner Losh.Pq < > 5899b94cc24SWarner Loshin the hints file. 5909b94cc24SWarner LoshWiring multiple devices to the same 5919b94cc24SWarner Losh.Va name 5929b94cc24SWarner Loshand 5939b94cc24SWarner Losh.Va unit 5949b94cc24SWarner Loshproduces undefined results. 5959b94cc24SWarner Losh.Ss Examples 5969b94cc24SWarner LoshGiven the following lines in 5979b94cc24SWarner Losh.Pa /boot/device.hints : 5989b94cc24SWarner Losh.Cd hint.nvme.3.at="pci6:0:0" 5999b94cc24SWarner Losh.Cd hint.igb.8.at="pci14:0:0" 6009b94cc24SWarner LoshIf there is a device that supports 6019b94cc24SWarner Losh.Xr igb 4 6029b94cc24SWarner Loshat PCI bus 14 slot 0 function 0, 6039b94cc24SWarner Loshthen it will be assigned igb8 for probe and attach. 6049b94cc24SWarner LoshLikewise, if there is an 6059b94cc24SWarner Losh.Xr nvme 4 6069b94cc24SWarner Loshcard at PCI bus 6 slot 0 function 0, 6079b94cc24SWarner Loshthen it will be assigned nvme3 for probe and attach. 6089b94cc24SWarner LoshIf another type of card is in either of these locations, the name and 6099b94cc24SWarner Loshunit of that card will be the default names and will be unaffected by 6109b94cc24SWarner Loshthese hints. 6119b94cc24SWarner LoshIf other igb or nvme cards are located elsewhere, they will be 6129b94cc24SWarner Loshassigned their unit numbers sequentially, skipping the unit numbers 6139b94cc24SWarner Loshthat have 'at' hints. 61464ae346bSKenneth D. Merry.Sh FILES 6153136363fSRuslan Ermilov.Bl -tag -width /dev/pci -compact 61664ae346bSKenneth D. Merry.It Pa /dev/pci 61764ae346bSKenneth D. MerryCharacter device for the 6184b66483fSRuslan Ermilov.Nm 61964ae346bSKenneth D. Merrydriver. 62064ae346bSKenneth D. Merry.El 62164ae346bSKenneth D. Merry.Sh SEE ALSO 62264ae346bSKenneth D. Merry.Xr pciconf 8 62364ae346bSKenneth D. Merry.Sh HISTORY 62464ae346bSKenneth D. MerryThe 6254b66483fSRuslan Ermilov.Nm 62664ae346bSKenneth D. Merrydriver (not the kernel's 62764ae346bSKenneth D. Merry.Tn PCI 62864ae346bSKenneth D. Merrysupport code) first appeared in 62964ae346bSKenneth D. Merry.Fx 2.2 , 63064ae346bSKenneth D. Merryand was written by Stefan Esser and Garrett Wollman. 63164ae346bSKenneth D. MerrySupport for device listing and matching was re-implemented by 63264ae346bSKenneth D. MerryKenneth Merry, and first appeared in 63364ae346bSKenneth D. Merry.Fx 3.0 . 63464ae346bSKenneth D. Merry.Sh AUTHORS 6356c899950SBaptiste Daroussin.An Kenneth Merry Aq Mt ken@FreeBSD.org 63664ae346bSKenneth D. Merry.Sh BUGS 6370227791bSRuslan ErmilovIt is not possible for users to specify an accurate offset into the device 63864ae346bSKenneth D. Merrylist without calling the 63964ae346bSKenneth D. Merry.Dv PCIOCGETCONF 64064ae346bSKenneth D. Merryat least once, since they have no way of knowing the current generation 641b5e7e999SRuslan Ermilovnumber otherwise. 6420227791bSRuslan ErmilovThis probably is not a serious problem, though, since 64364ae346bSKenneth D. Merryusers can easily narrow their search by specifying a pattern or patterns 64464ae346bSKenneth D. Merryfor the kernel to match against. 645