1*73531600Sabhinav.\" $NetBSD: pci.3,v 1.14 2017/10/22 15:28:48 abhinav Exp $ 216487fdfSthorpej.\" 316487fdfSthorpej.\" Copyright 2001 Wasabi Systems, Inc. 416487fdfSthorpej.\" All rights reserved. 516487fdfSthorpej.\" 616487fdfSthorpej.\" Written by Jason R. Thorpe for Wasabi Systems, Inc. 716487fdfSthorpej.\" 816487fdfSthorpej.\" Redistribution and use in source and binary forms, with or without 916487fdfSthorpej.\" modification, are permitted provided that the following conditions 1016487fdfSthorpej.\" are met: 1116487fdfSthorpej.\" 1. Redistributions of source code must retain the above copyright 1216487fdfSthorpej.\" notice, this list of conditions and the following disclaimer. 1316487fdfSthorpej.\" 2. Redistributions in binary form must reproduce the above copyright 1416487fdfSthorpej.\" notice, this list of conditions and the following disclaimer in the 1516487fdfSthorpej.\" documentation and/or other materials provided with the distribution. 1616487fdfSthorpej.\" 3. All advertising materials mentioning features or use of this software 1716487fdfSthorpej.\" must display the following acknowledgement: 1816487fdfSthorpej.\" This product includes software developed for the NetBSD Project by 1916487fdfSthorpej.\" Wasabi Systems, Inc. 2016487fdfSthorpej.\" 4. The name of Wasabi Systems, Inc. may not be used to endorse 2116487fdfSthorpej.\" or promote products derived from this software without specific prior 2216487fdfSthorpej.\" written permission. 2316487fdfSthorpej.\" 2416487fdfSthorpej.\" THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND 2516487fdfSthorpej.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2616487fdfSthorpej.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2716487fdfSthorpej.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC 2816487fdfSthorpej.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2916487fdfSthorpej.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 3016487fdfSthorpej.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 3116487fdfSthorpej.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 3216487fdfSthorpej.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3316487fdfSthorpej.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3416487fdfSthorpej.\" POSSIBILITY OF SUCH DAMAGE. 3516487fdfSthorpej.\" 3662ee7dc2Smrg.Dd September 23, 2016 3716487fdfSthorpej.Dt PCI 3 38997634feSjoerg.Os 3916487fdfSthorpej.Sh NAME 40*73531600Sabhinav.Nm pci , 41*73531600Sabhinav.Nm pcibus_conf_read , 42*73531600Sabhinav.Nm pcibus_conf_write , 43*73531600Sabhinav.Nm pcidev_conf_read , 44*73531600Sabhinav.Nm pcidev_conf_write , 45*73531600Sabhinav.Nm pci_findvendor , 46*73531600Sabhinav.Nm pci_devinfo , 47*73531600Sabhinav.Nm pci_conf_print , 48*73531600Sabhinav.Nm pci_drvname , 49*73531600Sabhinav.Nm pci_drvnameonbus 5016487fdfSthorpej.Nd library interface for PCI bus access 5116487fdfSthorpej.Sh LIBRARY 5216487fdfSthorpej.Lb libpci 5316487fdfSthorpej.Sh SYNOPSIS 54472351e1Swiz.In pci.h 5516487fdfSthorpej.Ft int 5648a57620Swiz.Fn pcibus_conf_read "int pcifd" "unsigned int bus" "unsigned int dev" "unsigned int func" \ 5748a57620Swiz"unsigned int reg" "pcireg_t *valp" 5816487fdfSthorpej.Ft int 5948a57620Swiz.Fn pcibus_conf_write "int pcifd" "unsigned int bus" "unsigned int dev" "unsigned int func" \ 6048a57620Swiz"unsigned int reg" "pcireg_t val" 6116487fdfSthorpej.Ft int 6248a57620Swiz.Fn pcidev_conf_read "int devfd" "unsigned int reg" "pcireg_t *valp" 6316487fdfSthorpej.Ft int 6448a57620Swiz.Fn pcidev_conf_write "int devfd" "unsigned int reg" "pcireg_t val" 6516487fdfSthorpej.Ft char * 6616487fdfSthorpej.Fn pci_findvendor "pcireg_t id_reg" 6716487fdfSthorpej.Ft void 685a1f437dSmsaitoh.Fn pci_devinfo "pcireg_t id_reg" "pcireg_t class_reg" "int showclass" "char *devinfo" "size_t len" 6916487fdfSthorpej.Ft void 7048a57620Swiz.Fn pci_conf_print "int pcifd" "unsigned int bus" "unsigned int dev" "unsigned int func" 711e4a2ee3Smrg.Ft int 7248a57620Swiz.Fn pci_drvname "int pcifd" "unsigned int dev" "unsigned int func" "char *drvname" "size_t len" 7362ee7dc2Smrg.Ft int 7462ee7dc2Smrg.Fn pci_drvnameonbus "int pcifd" "u_int bus" "u_int dev" "u_int func" "char *drvname" "size_t len" 7516487fdfSthorpej.Sh DESCRIPTION 7616487fdfSthorpejThe 7716487fdfSthorpej.Nm 7816487fdfSthorpejlibrary provides support for accessing the PCI bus by user programs. 7916487fdfSthorpej.Pp 8016487fdfSthorpejThese functions are available in the 8116487fdfSthorpej.Nm libpci 8216487fdfSthorpejlibrary. 8316487fdfSthorpejPrograms should be linked with 8416487fdfSthorpej.Fl lpci . 8516487fdfSthorpej.Sh CONFIGURATION SPACE FUNCTIONS 8616487fdfSthorpejThe following functions are used to access PCI configuration space: 8716487fdfSthorpej.Bl -tag -width 4n 8816487fdfSthorpej.It Fn pcibus_conf_read 8916487fdfSthorpejAccess the PCI configuration register 9016487fdfSthorpej.Fa reg 9116487fdfSthorpejon the device located at 9216487fdfSthorpej.Fa bus , 9316487fdfSthorpej.Fa dev , 9416487fdfSthorpej.Fa func , 9516487fdfSthorpejand place the result in 9616487fdfSthorpej.Fa *valp . 9716487fdfSthorpej.Fa pcifd 9816487fdfSthorpejmust be an open file descriptor to a PCI bus within the target PCI domain. 9916487fdfSthorpej.It Fn pcibus_conf_write 10016487fdfSthorpejWrite the value specified by 10116487fdfSthorpej.Fa val 10216487fdfSthorpejinto the PCI configuration register 1036e975d41Scegger.Fa reg 10416487fdfSthorpejon the device located at 10516487fdfSthorpej.Fa bus , 10616487fdfSthorpej.Fa dev , 10716487fdfSthorpej.Fa func . 10816487fdfSthorpej.Fa pcifd 10916487fdfSthorpejmust be an open file descriptor to a PCI bus within the target PCI domain. 11016487fdfSthorpej.It Fn pcidev_conf_read 11116487fdfSthorpejAccess the PCI configuration register 11216487fdfSthorpej.Fa reg 11316487fdfSthorpejon the device associated with the open file descriptor 11416487fdfSthorpej.Fa devfd 11516487fdfSthorpejand place the result in 11616487fdfSthorpej.Fa *valp . 11716487fdfSthorpej.It Fn pcidev_conf_write 11816487fdfSthorpejWrite the value specified by 11916487fdfSthorpej.Fa val 12016487fdfSthorpejinto the PCI configuration register 12116487fdfSthorpej.Fa reg 12216487fdfSthorpejon the device associated with the open file descriptor 12316487fdfSthorpej.Fa devfd . 12416487fdfSthorpej.El 125feb03dd1Swiz.Sh MISCELLANEOUS FUNCTIONS 12616487fdfSthorpejThe following miscellaneous functions are available: 12716487fdfSthorpej.Bl -tag -width 4n 12816487fdfSthorpej.It Fn pci_findvendor 12916487fdfSthorpejReturn an ASCII description of the PCI vendor in the 13016487fdfSthorpejPCI ID register 13116487fdfSthorpej.Fa id_reg . 13216487fdfSthorpej.It Fn pci_devinfo 13316487fdfSthorpejReturn an ASCII description of the PCI vendor, PCI product, 13416487fdfSthorpejand PCI class specified by the PCI ID register 13516487fdfSthorpej.Fa id_reg 13616487fdfSthorpejand PCI class ID register 13716487fdfSthorpej.Fa class_reg . 13816487fdfSthorpejThe description is placed into the buffer pointed to by 1397407d114Skleink.Fa devinfo ; 1407407d114Skleinkthe size of that buffer is specified in 1417407d114Skleink.Fa len . 1425a1f437dSmsaitohIf 1435a1f437dSmsaitoh.Fa showclass 1445a1f437dSmsaitohis not 0, the class, subclass and interface are added into the buffer. 14516487fdfSthorpej.It Fn pci_conf_print 14616487fdfSthorpejPrint the PCI configuration information for the device located 14716487fdfSthorpejat 14816487fdfSthorpej.Fa bus , 14916487fdfSthorpej.Fa dev , 15016487fdfSthorpej.Fa func . 15116487fdfSthorpej.Fa pcifd 15216487fdfSthorpejmust be an open file descriptor to a PCI bus within the target PCI domain. 1531e4a2ee3Smrg.It Fn pci_drvname 1541e4a2ee3SmrgFor the PCI bus opened on 1551e4a2ee3Smrg.Fa pcifd , 1561e4a2ee3Smrgreturn the driver name for 1571e4a2ee3Smrg.Fa dev 1581e4a2ee3Smrgand 1591e4a2ee3Smrg.Fa func 1601e4a2ee3Smrginto 1611e4a2ee3Smrg.Fa drvname 1621e4a2ee3Smrgusing 1631e4a2ee3Smrg.Fa len 1641e4a2ee3Smrgas the buffer length. 16562ee7dc2Smrg.It Fn pci_drvnameonbus 16662ee7dc2SmrgJust like 16762ee7dc2Smrg.Fn pci_drvname 16862ee7dc2Smrgbut also allows looking up via PCI bus number. 16916487fdfSthorpej.El 17016487fdfSthorpej.Sh RETURN VALUES 17116487fdfSthorpejThe 17216487fdfSthorpej.Fn pcibus_conf_read , 17316487fdfSthorpej.Fn pcibus_conf_write , 17416487fdfSthorpej.Fn pcidev_conf_read , 1751e4a2ee3Smrg.Fn pcidev_conf_write , 176ce9ef299Swiz.Fn pci_devinfo , 17716487fdfSthorpejand 1781e4a2ee3Smrg.Fn pci_drvname 179ce9ef299Swizfunctions return 0 on success and \-1 on failure. 18016487fdfSthorpej.Pp 18116487fdfSthorpejThe 18216487fdfSthorpej.Fn pci_findvendor 183ce9ef299Swizfunction returns 184ce9ef299Swiz.Dv NULL 185ce9ef299Swizif the PCI vendor description cannot be found. 18616487fdfSthorpej.Sh SEE ALSO 18716487fdfSthorpej.Xr pci 4 18816487fdfSthorpej.Sh HISTORY 18916487fdfSthorpejThe 19016487fdfSthorpej.Fn pcibus_conf_read , 19116487fdfSthorpej.Fn pcibus_conf_write , 19216487fdfSthorpej.Fn pcidev_conf_read , 19316487fdfSthorpej.Fn pcidev_conf_write , 19416487fdfSthorpej.Fn pci_findvendor , 19516487fdfSthorpej.Fn pci_devinfo , 19616487fdfSthorpejand 19716487fdfSthorpej.Fn pci_conf_print 19816487fdfSthorpejfunctions first appeared in 19916487fdfSthorpej.Nx 1.6 . 2001e4a2ee3SmrgThe 2011e4a2ee3Smrg.Fn pci_drvname 2021e4a2ee3Smrgfunction first appeared in 2031e4a2ee3Smrg.Nx 7.0 . 204