// SPDX-License-Identifier: GPL-2.0 /* * PCI IRQ handling code * * Copyright (c) 2008 James Bottomley <[email protected]> * Copyright (C) 2017 Christoph Hellwig. */ #include <linux/device.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/export.h> #include <linux/interrupt.h> #include <linux/pci.h> #include "pci.h" /** * pci_request_irq - allocate an interrupt line for a PCI device * @dev: PCI device to operate on * @nr: device-relative interrupt vector index (0-based). * @handler: Function to be called when the IRQ occurs. * Primary handler for threaded interrupts. * If NULL and thread_fn != NULL the default primary handler is * installed. * @thread_fn: Function called from the IRQ handler thread * If NULL, no IRQ thread is created * @dev_id: Cookie passed back to the handler function * @fmt: Printf-like format string naming the handler * * This call allocates interrupt resources and enables the interrupt line and * IRQ handling. From the point this call is made @handler and @thread_fn may * be invoked. All interrupts requested using this function might be shared. * * @dev_id must not be NULL and must be globally unique. */ int pci_request_irq(struct pci_dev *dev, unsigned int nr, irq_handler_t handler, irq_handler_t thread_fn, void *dev_id, const char *fmt, ...) { … } EXPORT_SYMBOL(…); /** * pci_free_irq - free an interrupt allocated with pci_request_irq * @dev: PCI device to operate on * @nr: device-relative interrupt vector index (0-based). * @dev_id: Device identity to free * * Remove an interrupt handler. The handler is removed and if the interrupt * line is no longer in use by any driver it is disabled. The caller must * ensure the interrupt is disabled on the device before calling this function. * The function does not return until any executing interrupts for this IRQ * have completed. * * This function must not be called from interrupt context. */ void pci_free_irq(struct pci_dev *dev, unsigned int nr, void *dev_id) { … } EXPORT_SYMBOL(…); /** * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge * @dev: the PCI device * @pin: the INTx pin (1=INTA, 2=INTB, 3=INTC, 4=INTD) * * Perform INTx swizzling for a device behind one level of bridge. This is * required by section 9.1 of the PCI-to-PCI bridge specification for devices * behind bridges on add-in cards. For devices with ARI enabled, the slot * number is always 0 (see the Implementation Note in section 2.2.8.1 of * the PCI Express Base Specification, Revision 2.1) */ u8 pci_swizzle_interrupt_pin(const struct pci_dev *dev, u8 pin) { … } int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge) { … } /** * pci_common_swizzle - swizzle INTx all the way to root bridge * @dev: the PCI device * @pinp: pointer to the INTx pin value (1=INTA, 2=INTB, 3=INTD, 4=INTD) * * Perform INTx swizzling for a device. This traverses through all PCI-to-PCI * bridges all the way up to a PCI root bus. */ u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp) { … } EXPORT_SYMBOL_GPL(…); void pci_assign_irq(struct pci_dev *dev) { … } static bool pci_check_and_set_intx_mask(struct pci_dev *dev, bool mask) { … } /** * pci_check_and_mask_intx - mask INTx on pending interrupt * @dev: the PCI device to operate on * * Check if the device dev has its INTx line asserted, mask it and return * true in that case. False is returned if no interrupt was pending. */ bool pci_check_and_mask_intx(struct pci_dev *dev) { … } EXPORT_SYMBOL_GPL(…); /** * pci_check_and_unmask_intx - unmask INTx if no interrupt is pending * @dev: the PCI device to operate on * * Check if the device dev has its INTx line asserted, unmask it if not and * return true. False is returned and the mask remains active if there was * still an interrupt pending. */ bool pci_check_and_unmask_intx(struct pci_dev *dev) { … } EXPORT_SYMBOL_GPL(…); /** * pcibios_penalize_isa_irq - penalize an ISA IRQ * @irq: ISA IRQ to penalize * @active: IRQ active or not * * Permits the platform to provide architecture-specific functionality when * penalizing ISA IRQs. This is the default implementation. Architecture * implementations can override this. */ void __weak pcibios_penalize_isa_irq(int irq, int active) { … } int __weak pcibios_alloc_irq(struct pci_dev *dev) { … } void __weak pcibios_free_irq(struct pci_dev *dev) { … }