.\" $NetBSD: pci_intr.9,v 1.25 2016/09/17 17:38:11 jdolecek Exp $ .\" .\" Copyright (c) 2000 The NetBSD Foundation, Inc. .\" All rights reserved. .\" .\" This code is derived from software contributed to The NetBSD Foundation .\" by Bill Sommerfeld .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd September 17, 2016 .Dt PCI_INTR 9 .Os .Sh NAME .Nm pci_intr , .Nm pci_intr_map , .Nm pci_intr_string , .Nm pci_intr_evcnt , .Nm pci_intr_establish , .Nm pci_intr_establish_xname , .Nm pci_intr_disestablish , .Nm pci_intr_type , .Nm pci_intr_setattr .Nd PCI bus interrupt manipulation functions .Sh SYNOPSIS .In dev/pci/pcivar.h .Ft int .Fn pci_intr_map "const struct pci_attach_args *pa" "pci_intr_handle_t *ih" .Ft const char * .Fn pci_intr_string "pci_chipset_tag_t pc" "pci_intr_handle_t ih" "char *buf" "size_t len" .Ft const struct evcnt * .Fn pci_intr_evcnt "pci_chipset_tag_t pc" "pci_intr_handle_t ih" .Ft void * .Fn pci_intr_establish "pci_chipset_tag_t pc" "pci_intr_handle_t ih" \ "int ipl" "int (*intrhand)(void *)" "void *intrarg" .Ft void * .Fn pci_intr_establish_xname "pci_chipset_tag_t pc" "pci_intr_handle_t ih" \ "int ipl" "int (*intrhand)(void *)" "void *intrarg" "const char *xname" .Ft void .Fn pci_intr_disestablish "pci_chipset_tag_t pc" "void *ih" .Ft int .Fn pci_intr_setattr "pci_chipset_tag_t pc" "pci_intr_handle_t *ih" "int attr" "uint64_t data" .Sh DESCRIPTION The .Nm functions exist to allow device drivers machine-independent access to PCI bus interrupts. The functions described in this page are typically declared in a port's .In machine/pci_machdep.h header file; however, drivers should generally include .In dev/pci/pcivar.h to get other PCI-specific declarations as well. .Pp Each driver has an .Fn attach function which has a bus-specific .Ft attach_args structure. Each driver for a PCI device is passed a pointer to an object of type .Ft struct pci_attach_args which contains, among other things, information about the location of the device in the PCI bus topology sufficient to allow interrupts from the device to be handled. .Pp If a driver wishes to establish an interrupt handler for the device, it should pass the .Ft struct pci_attach_args * to the .Fn pci_intr_map function, which returns zero on success, and nonzero on failure. The function sets the .Ft pci_intr_handle_t pointed at by its second argument to a machine-dependent value which identifies a particular interrupt source. .Pp If the driver wishes to refer to the interrupt source in an attach or error message, it should use the value returned by .Fn pci_intr_string . The buffer passed to .Fn pci_intr_string should be at least .Dv PCI_INTRSTR_LEN bytes. .Pp Subsequently, when the driver is prepared to receive interrupts, it should call .Fn pci_intr_establish to actually establish the handler; when the device interrupts, .Fa intrhand will be called with a single argument .Fa intrarg , and will run at the interrupt priority level .Fa ipl . .Pp The return value of .Fn pci_intr_establish may be saved and passed to .Fn pci_intr_disestablish to disable the interrupt handler when the driver is no longer interested in interrupts from the device. .Pp .Fn pci_intr_establish_xname is almost the same as .Fn pci_intr_establish . The difference is only .Fa xname which is used by .Xr intrctl 8 to show the device name(s) of the interrupt id. .Pp The .Fn pci_intr_setattr function sets an attribute .Fa attr of the interrupt handler to .Fa data . Currenty, only the following attribute is supported: .Bl -tag -width PCI_INTR_MPSAFE .It Dv PCI_INTR_MPSAFE If this attribute is set to .Dv true , it specifies that the interrupt handler is multiprocessor safe and works its own locking; otherwise the kernel lock will be held for the call to the interrupt handler. The default is .Dv false . .El .Pp The .Fn pci_intr_setattr function returns zero on success, and nonzero on failure. .Pp The .Fn pci_intr_evcnt function should return an evcnt structure pointer or .Dv NULL if there is no evcnt associated with this interrupt. See .Xr evcnt 9 for more details. .Ss PORTING A port's implementation of .Fn pci_intr_map may use the following members of .Ft struct pci_attach_args to determine how the device's interrupts are routed. .Bd -literal pci_chipset_tag_t pa_pc; pcitag_t pa_tag; pcitag_t pa_intrtag; /* intr. appears to come from here */ pci_intr_pin_t pa_intrpin; /* intr. appears on this pin */ pci_intr_line_t pa_intrline; /* intr. routing information */ pci_intr_pin_t pa_rawintrpin; /* unswizzled pin */ .Ed .Pp PCI-PCI bridges swizzle (permute) interrupt wiring. Depending on implementation details, it may be more convenient to use either original or the swizzled interrupt parameters. The original device tag and interrupt pin can be found in .Ft pa_tag and .Ft pa_rawintrpin respectively, while the swizzled tag and pin can be found in .Ft pa_intrtag and .Ft pa_intrpin . .Pp When a device is attached to a primary bus, both pairs of fields contain the same values. When a device is found behind one or more pci-pci bridges, .Ft pa_intrpin contains the .Dq swizzled interrupt pin number, while .Ft pa_rawintrpin contains the original interrupt pin; .Ft pa_tag contains the PCI tag of the device itself, and .Ft pa_intrtag contains the PCI tag of the uppermost bridge device. .Sh SEE ALSO .Xr evcnt 9 , .Xr pci 9 , .Xr pci_msi 9 .Sh HISTORY .Fn pci_intr_establish_xname was added in .Nx 8.0 as part of MSI/MSI-X support.