// SPDX-License-Identifier: GPL-2.0 /* * PCIe Native PME support * * Copyright (C) 2007 - 2009 Intel Corp * Copyright (C) 2007 - 2009 Shaohua Li <[email protected]> * Copyright (C) 2009 Rafael J. Wysocki <[email protected]>, Novell Inc. */ #define dev_fmt(fmt) … #include <linux/bitfield.h> #include <linux/pci.h> #include <linux/kernel.h> #include <linux/errno.h> #include <linux/slab.h> #include <linux/init.h> #include <linux/interrupt.h> #include <linux/device.h> #include <linux/pm_runtime.h> #include "../pci.h" #include "portdrv.h" /* * If this switch is set, MSI will not be used for PCIe PME signaling. This * causes the PCIe port driver to use INTx interrupts only, but it turns out * that using MSI for PCIe PME signaling doesn't play well with PCIe PME-based * wake-up from system sleep states. */ bool pcie_pme_msi_disabled; static int __init pcie_pme_setup(char *str) { … } __setup(…); struct pcie_pme_service_data { … }; /** * pcie_pme_interrupt_enable - Enable/disable PCIe PME interrupt generation. * @dev: PCIe root port or event collector. * @enable: Enable or disable the interrupt. */ void pcie_pme_interrupt_enable(struct pci_dev *dev, bool enable) { … } /** * pcie_pme_walk_bus - Scan a PCI bus for devices asserting PME#. * @bus: PCI bus to scan. * * Scan given PCI bus and all buses under it for devices asserting PME#. */ static bool pcie_pme_walk_bus(struct pci_bus *bus) { … } /** * pcie_pme_from_pci_bridge - Check if PCIe-PCI bridge generated a PME. * @bus: Secondary bus of the bridge. * @devfn: Device/function number to check. * * PME from PCI devices under a PCIe-PCI bridge may be converted to an in-band * PCIe PME message. In such that case the bridge should use the Requester ID * of device/function number 0 on its secondary bus. */ static bool pcie_pme_from_pci_bridge(struct pci_bus *bus, u8 devfn) { … } /** * pcie_pme_handle_request - Find device that generated PME and handle it. * @port: Root port or event collector that generated the PME interrupt. * @req_id: PCIe Requester ID of the device that generated the PME. */ static void pcie_pme_handle_request(struct pci_dev *port, u16 req_id) { … } /** * pcie_pme_work_fn - Work handler for PCIe PME interrupt. * @work: Work structure giving access to service data. */ static void pcie_pme_work_fn(struct work_struct *work) { … } /** * pcie_pme_irq - Interrupt handler for PCIe root port PME interrupt. * @irq: Interrupt vector. * @context: Interrupt context pointer. */ static irqreturn_t pcie_pme_irq(int irq, void *context) { … } /** * pcie_pme_can_wakeup - Set the wakeup capability flag. * @dev: PCI device to handle. * @ign: Ignored. */ static int pcie_pme_can_wakeup(struct pci_dev *dev, void *ign) { … } /** * pcie_pme_mark_devices - Set the wakeup flag for devices below a port. * @port: PCIe root port or event collector to handle. * * For each device below given root port, including the port itself (or for each * root complex integrated endpoint if @port is a root complex event collector) * set the flag indicating that it can signal run-time wake-up events. */ static void pcie_pme_mark_devices(struct pci_dev *port) { … } /** * pcie_pme_probe - Initialize PCIe PME service for given root port. * @srv: PCIe service to initialize. */ static int pcie_pme_probe(struct pcie_device *srv) { … } static bool pcie_pme_check_wakeup(struct pci_bus *bus) { … } static void pcie_pme_disable_interrupt(struct pci_dev *port, struct pcie_pme_service_data *data) { … } /** * pcie_pme_suspend - Suspend PCIe PME service device. * @srv: PCIe service device to suspend. */ static int pcie_pme_suspend(struct pcie_device *srv) { … } /** * pcie_pme_resume - Resume PCIe PME service device. * @srv: PCIe service device to resume. */ static int pcie_pme_resume(struct pcie_device *srv) { … } /** * pcie_pme_remove - Prepare PCIe PME service device for removal. * @srv: PCIe service device to remove. */ static void pcie_pme_remove(struct pcie_device *srv) { … } static struct pcie_port_service_driver pcie_pme_driver = …; /** * pcie_pme_init - Register the PCIe PME service driver. */ int __init pcie_pme_init(void) { … }