All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Cc: linux-pm@lists.linux-foundation.org,
	Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>,
	linux-pci@vger.kernel.org,
	Jesse Barnes <jbarnes@virtuousgeek.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	Matthew Garrett <mjg@redhat.com>
Subject: [PATCH 9/10] PCI / PCIe: Move PCIe PME code to the pcie directory
Date: Sat, 21 Aug 2010 01:58:22 +0200	[thread overview]
Message-ID: <201008210158.23169.rjw@sisk.pl> (raw)
In-Reply-To: <201008210149.39576.rjw@sisk.pl>

From: Rafael J. Wysocki <rjw@sisk.pl>

The PCIe PME code only consists of one file, so it doesn't need to
occupy its own directory.  Move it to drivers/pci/pcie/pme.c and
remove the contents of drivers/pci/pcie/pme .

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
---
 drivers/pci/pcie/Makefile       |    2 
 drivers/pci/pcie/pme.c          |  462 ++++++++++++++++++++++++++++++++++++++++
 drivers/pci/pcie/pme/Makefile   |    5 
 drivers/pci/pcie/pme/pcie_pme.c |  462 ----------------------------------------
 4 files changed, 463 insertions(+), 468 deletions(-)

Index: linux-2.6/drivers/pci/pcie/pme.c
===================================================================
--- /dev/null
+++ linux-2.6/drivers/pci/pcie/pme.c
@@ -0,0 +1,462 @@
+/*
+ * PCIe Native PME support
+ *
+ * Copyright (C) 2007 - 2009 Intel Corp
+ * Copyright (C) 2007 - 2009 Shaohua Li <shaohua.li@intel.com>
+ * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License V2.  See the file "COPYING" in the main directory of this archive
+ * for more details.
+ */
+
+#include <linux/module.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/pcieport_if.h>
+#include <linux/acpi.h>
+#include <linux/pci-acpi.h>
+#include <linux/pm_runtime.h>
+
+#include "../pci.h"
+#include "portdrv.h"
+
+#define PCI_EXP_RTSTA_PME	0x10000 /* PME status */
+#define PCI_EXP_RTSTA_PENDING	0x20000 /* PME pending */
+
+/*
+ * 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)
+{
+	if (!strncmp(str, "nomsi", 5))
+		pcie_pme_msi_disabled = true;
+
+	return 1;
+}
+__setup("pcie_pme=", pcie_pme_setup);
+
+struct pcie_pme_service_data {
+	spinlock_t lock;
+	struct pcie_device *srv;
+	struct work_struct work;
+	bool noirq; /* Don't enable the PME interrupt used by this service. */
+};
+
+/**
+ * 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)
+{
+	int rtctl_pos;
+	u16 rtctl;
+
+	rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;
+
+	pci_read_config_word(dev, rtctl_pos, &rtctl);
+	if (enable)
+		rtctl |= PCI_EXP_RTCTL_PMEIE;
+	else
+		rtctl &= ~PCI_EXP_RTCTL_PMEIE;
+	pci_write_config_word(dev, rtctl_pos, rtctl);
+}
+
+/**
+ * pcie_pme_clear_status - Clear root port PME interrupt status.
+ * @dev: PCIe root port or event collector.
+ */
+static void pcie_pme_clear_status(struct pci_dev *dev)
+{
+	int rtsta_pos;
+	u32 rtsta;
+
+	rtsta_pos = pci_pcie_cap(dev) + PCI_EXP_RTSTA;
+
+	pci_read_config_dword(dev, rtsta_pos, &rtsta);
+	rtsta |= PCI_EXP_RTSTA_PME;
+	pci_write_config_dword(dev, rtsta_pos, rtsta);
+}
+
+/**
+ * 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)
+{
+	struct pci_dev *dev;
+	bool ret = false;
+
+	list_for_each_entry(dev, &bus->devices, bus_list) {
+		/* Skip PCIe devices in case we started from a root port. */
+		if (!pci_is_pcie(dev) && pci_check_pme_status(dev)) {
+			pm_request_resume(&dev->dev);
+			pci_wakeup_event(dev);
+			ret = true;
+		}
+
+		if (dev->subordinate && pcie_pme_walk_bus(dev->subordinate))
+			ret = true;
+	}
+
+	return ret;
+}
+
+/**
+ * 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)
+{
+	struct pci_dev *dev;
+	bool found = false;
+
+	if (devfn)
+		return false;
+
+	dev = pci_dev_get(bus->self);
+	if (!dev)
+		return false;
+
+	if (pci_is_pcie(dev) && dev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) {
+		down_read(&pci_bus_sem);
+		if (pcie_pme_walk_bus(bus))
+			found = true;
+		up_read(&pci_bus_sem);
+	}
+
+	pci_dev_put(dev);
+	return found;
+}
+
+/**
+ * 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)
+{
+	u8 busnr = req_id >> 8, devfn = req_id & 0xff;
+	struct pci_bus *bus;
+	struct pci_dev *dev;
+	bool found = false;
+
+	/* First, check if the PME is from the root port itself. */
+	if (port->devfn == devfn && port->bus->number == busnr) {
+		if (pci_check_pme_status(port)) {
+			pm_request_resume(&port->dev);
+			found = true;
+		} else {
+			/*
+			 * Apparently, the root port generated the PME on behalf
+			 * of a non-PCIe device downstream.  If this is done by
+			 * a root port, the Requester ID field in its status
+			 * register may contain either the root port's, or the
+			 * source device's information (PCI Express Base
+			 * Specification, Rev. 2.0, Section 6.1.9).
+			 */
+			down_read(&pci_bus_sem);
+			found = pcie_pme_walk_bus(port->subordinate);
+			up_read(&pci_bus_sem);
+		}
+		goto out;
+	}
+
+	/* Second, find the bus the source device is on. */
+	bus = pci_find_bus(pci_domain_nr(port->bus), busnr);
+	if (!bus)
+		goto out;
+
+	/* Next, check if the PME is from a PCIe-PCI bridge. */
+	found = pcie_pme_from_pci_bridge(bus, devfn);
+	if (found)
+		goto out;
+
+	/* Finally, try to find the PME source on the bus. */
+	down_read(&pci_bus_sem);
+	list_for_each_entry(dev, &bus->devices, bus_list) {
+		pci_dev_get(dev);
+		if (dev->devfn == devfn) {
+			found = true;
+			break;
+		}
+		pci_dev_put(dev);
+	}
+	up_read(&pci_bus_sem);
+
+	if (found) {
+		/* The device is there, but we have to check its PME status. */
+		found = pci_check_pme_status(dev);
+		if (found) {
+			pm_request_resume(&dev->dev);
+			pci_wakeup_event(dev);
+		}
+		pci_dev_put(dev);
+	} else if (devfn) {
+		/*
+		 * The device is not there, but we can still try to recover by
+		 * assuming that the PME was reported by a PCIe-PCI bridge that
+		 * used devfn different from zero.
+		 */
+		dev_dbg(&port->dev, "PME interrupt generated for "
+			"non-existent device %02x:%02x.%d\n",
+			busnr, PCI_SLOT(devfn), PCI_FUNC(devfn));
+		found = pcie_pme_from_pci_bridge(bus, 0);
+	}
+
+ out:
+	if (!found)
+		dev_dbg(&port->dev, "Spurious native PME interrupt!\n");
+}
+
+/**
+ * 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)
+{
+	struct pcie_pme_service_data *data =
+			container_of(work, struct pcie_pme_service_data, work);
+	struct pci_dev *port = data->srv->port;
+	int rtsta_pos;
+	u32 rtsta;
+
+	rtsta_pos = pci_pcie_cap(port) + PCI_EXP_RTSTA;
+
+	spin_lock_irq(&data->lock);
+
+	for (;;) {
+		if (data->noirq)
+			break;
+
+		pci_read_config_dword(port, rtsta_pos, &rtsta);
+		if (rtsta & PCI_EXP_RTSTA_PME) {
+			/*
+			 * Clear PME status of the port.  If there are other
+			 * pending PMEs, the status will be set again.
+			 */
+			pcie_pme_clear_status(port);
+
+			spin_unlock_irq(&data->lock);
+			pcie_pme_handle_request(port, rtsta & 0xffff);
+			spin_lock_irq(&data->lock);
+
+			continue;
+		}
+
+		/* No need to loop if there are no more PMEs pending. */
+		if (!(rtsta & PCI_EXP_RTSTA_PENDING))
+			break;
+
+		spin_unlock_irq(&data->lock);
+		cpu_relax();
+		spin_lock_irq(&data->lock);
+	}
+
+	if (!data->noirq)
+		pcie_pme_interrupt_enable(port, true);
+
+	spin_unlock_irq(&data->lock);
+}
+
+/**
+ * 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)
+{
+	struct pci_dev *port;
+	struct pcie_pme_service_data *data;
+	int rtsta_pos;
+	u32 rtsta;
+	unsigned long flags;
+
+	port = ((struct pcie_device *)context)->port;
+	data = get_service_data((struct pcie_device *)context);
+
+	rtsta_pos = pci_pcie_cap(port) + PCI_EXP_RTSTA;
+
+	spin_lock_irqsave(&data->lock, flags);
+	pci_read_config_dword(port, rtsta_pos, &rtsta);
+
+	if (!(rtsta & PCI_EXP_RTSTA_PME)) {
+		spin_unlock_irqrestore(&data->lock, flags);
+		return IRQ_NONE;
+	}
+
+	pcie_pme_interrupt_enable(port, false);
+	spin_unlock_irqrestore(&data->lock, flags);
+
+	/* We don't use pm_wq, because it's freezable. */
+	schedule_work(&data->work);
+
+	return IRQ_HANDLED;
+}
+
+/**
+ * pcie_pme_set_native - Set the PME interrupt flag for given device.
+ * @dev: PCI device to handle.
+ * @ign: Ignored.
+ */
+static int pcie_pme_set_native(struct pci_dev *dev, void *ign)
+{
+	dev_info(&dev->dev, "Signaling PME through PCIe PME interrupt\n");
+
+	device_set_run_wake(&dev->dev, true);
+	dev->pme_interrupt = true;
+	return 0;
+}
+
+/**
+ * pcie_pme_mark_devices - Set the PME interrupt 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 via PCIe
+ * PME interrupts.
+ */
+static void pcie_pme_mark_devices(struct pci_dev *port)
+{
+	pcie_pme_set_native(port, NULL);
+	if (port->subordinate) {
+		pci_walk_bus(port->subordinate, pcie_pme_set_native, NULL);
+	} else {
+		struct pci_bus *bus = port->bus;
+		struct pci_dev *dev;
+
+		/* Check if this is a root port event collector. */
+		if (port->pcie_type != PCI_EXP_TYPE_RC_EC || !bus)
+			return;
+
+		down_read(&pci_bus_sem);
+		list_for_each_entry(dev, &bus->devices, bus_list)
+			if (pci_is_pcie(dev)
+			    && dev->pcie_type == PCI_EXP_TYPE_RC_END)
+				pcie_pme_set_native(dev, NULL);
+		up_read(&pci_bus_sem);
+	}
+}
+
+/**
+ * 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)
+{
+	struct pci_dev *port;
+	struct pcie_pme_service_data *data;
+	int ret;
+
+	data = kzalloc(sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	spin_lock_init(&data->lock);
+	INIT_WORK(&data->work, pcie_pme_work_fn);
+	data->srv = srv;
+	set_service_data(srv, data);
+
+	port = srv->port;
+	pcie_pme_interrupt_enable(port, false);
+	pcie_pme_clear_status(port);
+
+	ret = request_irq(srv->irq, pcie_pme_irq, IRQF_SHARED, "PCIe PME", srv);
+	if (ret) {
+		kfree(data);
+	} else {
+		pcie_pme_mark_devices(port);
+		pcie_pme_interrupt_enable(port, true);
+	}
+
+	return ret;
+}
+
+/**
+ * pcie_pme_suspend - Suspend PCIe PME service device.
+ * @srv: PCIe service device to suspend.
+ */
+static int pcie_pme_suspend(struct pcie_device *srv)
+{
+	struct pcie_pme_service_data *data = get_service_data(srv);
+	struct pci_dev *port = srv->port;
+
+	spin_lock_irq(&data->lock);
+	pcie_pme_interrupt_enable(port, false);
+	pcie_pme_clear_status(port);
+	data->noirq = true;
+	spin_unlock_irq(&data->lock);
+
+	synchronize_irq(srv->irq);
+
+	return 0;
+}
+
+/**
+ * pcie_pme_resume - Resume PCIe PME service device.
+ * @srv - PCIe service device to resume.
+ */
+static int pcie_pme_resume(struct pcie_device *srv)
+{
+	struct pcie_pme_service_data *data = get_service_data(srv);
+	struct pci_dev *port = srv->port;
+
+	spin_lock_irq(&data->lock);
+	data->noirq = false;
+	pcie_pme_clear_status(port);
+	pcie_pme_interrupt_enable(port, true);
+	spin_unlock_irq(&data->lock);
+
+	return 0;
+}
+
+/**
+ * pcie_pme_remove - Prepare PCIe PME service device for removal.
+ * @srv - PCIe service device to resume.
+ */
+static void pcie_pme_remove(struct pcie_device *srv)
+{
+	pcie_pme_suspend(srv);
+	free_irq(srv->irq, srv);
+	kfree(get_service_data(srv));
+}
+
+static struct pcie_port_service_driver pcie_pme_driver = {
+	.name		= "pcie_pme",
+	.port_type 	= PCI_EXP_TYPE_ROOT_PORT,
+	.service 	= PCIE_PORT_SERVICE_PME,
+
+	.probe		= pcie_pme_probe,
+	.suspend	= pcie_pme_suspend,
+	.resume		= pcie_pme_resume,
+	.remove		= pcie_pme_remove,
+};
+
+/**
+ * pcie_pme_service_init - Register the PCIe PME service driver.
+ */
+static int __init pcie_pme_service_init(void)
+{
+	return pcie_port_service_register(&pcie_pme_driver);
+}
+
+module_init(pcie_pme_service_init);
Index: linux-2.6/drivers/pci/pcie/pme/pcie_pme.c
===================================================================
--- linux-2.6.orig/drivers/pci/pcie/pme/pcie_pme.c
+++ /dev/null
@@ -1,462 +0,0 @@
-/*
- * PCIe Native PME support
- *
- * Copyright (C) 2007 - 2009 Intel Corp
- * Copyright (C) 2007 - 2009 Shaohua Li <shaohua.li@intel.com>
- * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc.
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License V2.  See the file "COPYING" in the main directory of this archive
- * for more details.
- */
-
-#include <linux/module.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/pcieport_if.h>
-#include <linux/acpi.h>
-#include <linux/pci-acpi.h>
-#include <linux/pm_runtime.h>
-
-#include "../../pci.h"
-#include "../portdrv.h"
-
-#define PCI_EXP_RTSTA_PME	0x10000 /* PME status */
-#define PCI_EXP_RTSTA_PENDING	0x20000 /* PME pending */
-
-/*
- * 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)
-{
-	if (!strncmp(str, "nomsi", 5))
-		pcie_pme_msi_disabled = true;
-
-	return 1;
-}
-__setup("pcie_pme=", pcie_pme_setup);
-
-struct pcie_pme_service_data {
-	spinlock_t lock;
-	struct pcie_device *srv;
-	struct work_struct work;
-	bool noirq; /* Don't enable the PME interrupt used by this service. */
-};
-
-/**
- * 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)
-{
-	int rtctl_pos;
-	u16 rtctl;
-
-	rtctl_pos = pci_pcie_cap(dev) + PCI_EXP_RTCTL;
-
-	pci_read_config_word(dev, rtctl_pos, &rtctl);
-	if (enable)
-		rtctl |= PCI_EXP_RTCTL_PMEIE;
-	else
-		rtctl &= ~PCI_EXP_RTCTL_PMEIE;
-	pci_write_config_word(dev, rtctl_pos, rtctl);
-}
-
-/**
- * pcie_pme_clear_status - Clear root port PME interrupt status.
- * @dev: PCIe root port or event collector.
- */
-static void pcie_pme_clear_status(struct pci_dev *dev)
-{
-	int rtsta_pos;
-	u32 rtsta;
-
-	rtsta_pos = pci_pcie_cap(dev) + PCI_EXP_RTSTA;
-
-	pci_read_config_dword(dev, rtsta_pos, &rtsta);
-	rtsta |= PCI_EXP_RTSTA_PME;
-	pci_write_config_dword(dev, rtsta_pos, rtsta);
-}
-
-/**
- * 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)
-{
-	struct pci_dev *dev;
-	bool ret = false;
-
-	list_for_each_entry(dev, &bus->devices, bus_list) {
-		/* Skip PCIe devices in case we started from a root port. */
-		if (!pci_is_pcie(dev) && pci_check_pme_status(dev)) {
-			pm_request_resume(&dev->dev);
-			pci_wakeup_event(dev);
-			ret = true;
-		}
-
-		if (dev->subordinate && pcie_pme_walk_bus(dev->subordinate))
-			ret = true;
-	}
-
-	return ret;
-}
-
-/**
- * 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)
-{
-	struct pci_dev *dev;
-	bool found = false;
-
-	if (devfn)
-		return false;
-
-	dev = pci_dev_get(bus->self);
-	if (!dev)
-		return false;
-
-	if (pci_is_pcie(dev) && dev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) {
-		down_read(&pci_bus_sem);
-		if (pcie_pme_walk_bus(bus))
-			found = true;
-		up_read(&pci_bus_sem);
-	}
-
-	pci_dev_put(dev);
-	return found;
-}
-
-/**
- * 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)
-{
-	u8 busnr = req_id >> 8, devfn = req_id & 0xff;
-	struct pci_bus *bus;
-	struct pci_dev *dev;
-	bool found = false;
-
-	/* First, check if the PME is from the root port itself. */
-	if (port->devfn == devfn && port->bus->number == busnr) {
-		if (pci_check_pme_status(port)) {
-			pm_request_resume(&port->dev);
-			found = true;
-		} else {
-			/*
-			 * Apparently, the root port generated the PME on behalf
-			 * of a non-PCIe device downstream.  If this is done by
-			 * a root port, the Requester ID field in its status
-			 * register may contain either the root port's, or the
-			 * source device's information (PCI Express Base
-			 * Specification, Rev. 2.0, Section 6.1.9).
-			 */
-			down_read(&pci_bus_sem);
-			found = pcie_pme_walk_bus(port->subordinate);
-			up_read(&pci_bus_sem);
-		}
-		goto out;
-	}
-
-	/* Second, find the bus the source device is on. */
-	bus = pci_find_bus(pci_domain_nr(port->bus), busnr);
-	if (!bus)
-		goto out;
-
-	/* Next, check if the PME is from a PCIe-PCI bridge. */
-	found = pcie_pme_from_pci_bridge(bus, devfn);
-	if (found)
-		goto out;
-
-	/* Finally, try to find the PME source on the bus. */
-	down_read(&pci_bus_sem);
-	list_for_each_entry(dev, &bus->devices, bus_list) {
-		pci_dev_get(dev);
-		if (dev->devfn == devfn) {
-			found = true;
-			break;
-		}
-		pci_dev_put(dev);
-	}
-	up_read(&pci_bus_sem);
-
-	if (found) {
-		/* The device is there, but we have to check its PME status. */
-		found = pci_check_pme_status(dev);
-		if (found) {
-			pm_request_resume(&dev->dev);
-			pci_wakeup_event(dev);
-		}
-		pci_dev_put(dev);
-	} else if (devfn) {
-		/*
-		 * The device is not there, but we can still try to recover by
-		 * assuming that the PME was reported by a PCIe-PCI bridge that
-		 * used devfn different from zero.
-		 */
-		dev_dbg(&port->dev, "PME interrupt generated for "
-			"non-existent device %02x:%02x.%d\n",
-			busnr, PCI_SLOT(devfn), PCI_FUNC(devfn));
-		found = pcie_pme_from_pci_bridge(bus, 0);
-	}
-
- out:
-	if (!found)
-		dev_dbg(&port->dev, "Spurious native PME interrupt!\n");
-}
-
-/**
- * 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)
-{
-	struct pcie_pme_service_data *data =
-			container_of(work, struct pcie_pme_service_data, work);
-	struct pci_dev *port = data->srv->port;
-	int rtsta_pos;
-	u32 rtsta;
-
-	rtsta_pos = pci_pcie_cap(port) + PCI_EXP_RTSTA;
-
-	spin_lock_irq(&data->lock);
-
-	for (;;) {
-		if (data->noirq)
-			break;
-
-		pci_read_config_dword(port, rtsta_pos, &rtsta);
-		if (rtsta & PCI_EXP_RTSTA_PME) {
-			/*
-			 * Clear PME status of the port.  If there are other
-			 * pending PMEs, the status will be set again.
-			 */
-			pcie_pme_clear_status(port);
-
-			spin_unlock_irq(&data->lock);
-			pcie_pme_handle_request(port, rtsta & 0xffff);
-			spin_lock_irq(&data->lock);
-
-			continue;
-		}
-
-		/* No need to loop if there are no more PMEs pending. */
-		if (!(rtsta & PCI_EXP_RTSTA_PENDING))
-			break;
-
-		spin_unlock_irq(&data->lock);
-		cpu_relax();
-		spin_lock_irq(&data->lock);
-	}
-
-	if (!data->noirq)
-		pcie_pme_interrupt_enable(port, true);
-
-	spin_unlock_irq(&data->lock);
-}
-
-/**
- * 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)
-{
-	struct pci_dev *port;
-	struct pcie_pme_service_data *data;
-	int rtsta_pos;
-	u32 rtsta;
-	unsigned long flags;
-
-	port = ((struct pcie_device *)context)->port;
-	data = get_service_data((struct pcie_device *)context);
-
-	rtsta_pos = pci_pcie_cap(port) + PCI_EXP_RTSTA;
-
-	spin_lock_irqsave(&data->lock, flags);
-	pci_read_config_dword(port, rtsta_pos, &rtsta);
-
-	if (!(rtsta & PCI_EXP_RTSTA_PME)) {
-		spin_unlock_irqrestore(&data->lock, flags);
-		return IRQ_NONE;
-	}
-
-	pcie_pme_interrupt_enable(port, false);
-	spin_unlock_irqrestore(&data->lock, flags);
-
-	/* We don't use pm_wq, because it's freezable. */
-	schedule_work(&data->work);
-
-	return IRQ_HANDLED;
-}
-
-/**
- * pcie_pme_set_native - Set the PME interrupt flag for given device.
- * @dev: PCI device to handle.
- * @ign: Ignored.
- */
-static int pcie_pme_set_native(struct pci_dev *dev, void *ign)
-{
-	dev_info(&dev->dev, "Signaling PME through PCIe PME interrupt\n");
-
-	device_set_run_wake(&dev->dev, true);
-	dev->pme_interrupt = true;
-	return 0;
-}
-
-/**
- * pcie_pme_mark_devices - Set the PME interrupt 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 via PCIe
- * PME interrupts.
- */
-static void pcie_pme_mark_devices(struct pci_dev *port)
-{
-	pcie_pme_set_native(port, NULL);
-	if (port->subordinate) {
-		pci_walk_bus(port->subordinate, pcie_pme_set_native, NULL);
-	} else {
-		struct pci_bus *bus = port->bus;
-		struct pci_dev *dev;
-
-		/* Check if this is a root port event collector. */
-		if (port->pcie_type != PCI_EXP_TYPE_RC_EC || !bus)
-			return;
-
-		down_read(&pci_bus_sem);
-		list_for_each_entry(dev, &bus->devices, bus_list)
-			if (pci_is_pcie(dev)
-			    && dev->pcie_type == PCI_EXP_TYPE_RC_END)
-				pcie_pme_set_native(dev, NULL);
-		up_read(&pci_bus_sem);
-	}
-}
-
-/**
- * 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)
-{
-	struct pci_dev *port;
-	struct pcie_pme_service_data *data;
-	int ret;
-
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
-
-	spin_lock_init(&data->lock);
-	INIT_WORK(&data->work, pcie_pme_work_fn);
-	data->srv = srv;
-	set_service_data(srv, data);
-
-	port = srv->port;
-	pcie_pme_interrupt_enable(port, false);
-	pcie_pme_clear_status(port);
-
-	ret = request_irq(srv->irq, pcie_pme_irq, IRQF_SHARED, "PCIe PME", srv);
-	if (ret) {
-		kfree(data);
-	} else {
-		pcie_pme_mark_devices(port);
-		pcie_pme_interrupt_enable(port, true);
-	}
-
-	return ret;
-}
-
-/**
- * pcie_pme_suspend - Suspend PCIe PME service device.
- * @srv: PCIe service device to suspend.
- */
-static int pcie_pme_suspend(struct pcie_device *srv)
-{
-	struct pcie_pme_service_data *data = get_service_data(srv);
-	struct pci_dev *port = srv->port;
-
-	spin_lock_irq(&data->lock);
-	pcie_pme_interrupt_enable(port, false);
-	pcie_pme_clear_status(port);
-	data->noirq = true;
-	spin_unlock_irq(&data->lock);
-
-	synchronize_irq(srv->irq);
-
-	return 0;
-}
-
-/**
- * pcie_pme_resume - Resume PCIe PME service device.
- * @srv - PCIe service device to resume.
- */
-static int pcie_pme_resume(struct pcie_device *srv)
-{
-	struct pcie_pme_service_data *data = get_service_data(srv);
-	struct pci_dev *port = srv->port;
-
-	spin_lock_irq(&data->lock);
-	data->noirq = false;
-	pcie_pme_clear_status(port);
-	pcie_pme_interrupt_enable(port, true);
-	spin_unlock_irq(&data->lock);
-
-	return 0;
-}
-
-/**
- * pcie_pme_remove - Prepare PCIe PME service device for removal.
- * @srv - PCIe service device to resume.
- */
-static void pcie_pme_remove(struct pcie_device *srv)
-{
-	pcie_pme_suspend(srv);
-	free_irq(srv->irq, srv);
-	kfree(get_service_data(srv));
-}
-
-static struct pcie_port_service_driver pcie_pme_driver = {
-	.name		= "pcie_pme",
-	.port_type 	= PCI_EXP_TYPE_ROOT_PORT,
-	.service 	= PCIE_PORT_SERVICE_PME,
-
-	.probe		= pcie_pme_probe,
-	.suspend	= pcie_pme_suspend,
-	.resume		= pcie_pme_resume,
-	.remove		= pcie_pme_remove,
-};
-
-/**
- * pcie_pme_service_init - Register the PCIe PME service driver.
- */
-static int __init pcie_pme_service_init(void)
-{
-	return pcie_port_service_register(&pcie_pme_driver);
-}
-
-module_init(pcie_pme_service_init);
Index: linux-2.6/drivers/pci/pcie/pme/Makefile
===================================================================
--- linux-2.6.orig/drivers/pci/pcie/pme/Makefile
+++ /dev/null
@@ -1,5 +0,0 @@
-#
-# Makefile for PCI-Express Root Port PME signaling driver
-#
-
-obj-$(CONFIG_PCIE_PME) += pcie_pme.o
Index: linux-2.6/drivers/pci/pcie/Makefile
===================================================================
--- linux-2.6.orig/drivers/pci/pcie/Makefile
+++ linux-2.6/drivers/pci/pcie/Makefile
@@ -13,4 +13,4 @@ obj-$(CONFIG_PCIEPORTBUS)	+= pcieportdrv
 # Build PCI Express AER if needed
 obj-$(CONFIG_PCIEAER)		+= aer/
 
-obj-$(CONFIG_PCIE_PME) += pme/
+obj-$(CONFIG_PCIE_PME) += pme.o

  parent reply	other threads:[~2010-08-20 23:58 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-06  1:03 [PATCH 0/10] ACPI / PCI / PCIe: Rework _OSC handling (v3) Rafael J. Wysocki
2010-08-06  1:05 ` [PATCH 1/10] ACPI / PCI: Introduce function for querying PCI root _OSC Rafael J. Wysocki
2010-08-06  1:05 ` Rafael J. Wysocki
2010-08-06  1:06 ` [PATCH 2/10] PCI / PCIe/ AER: Introduce pci_aer_available() Rafael J. Wysocki
2010-08-06  1:06 ` Rafael J. Wysocki
2010-08-06  1:07 ` [PATCH 3/10] PCI / PCIe: Introduce commad line switch for disabling port services Rafael J. Wysocki
2010-08-06  1:07 ` Rafael J. Wysocki
2010-08-06  1:08 ` [PATCH 4/10] PCI / PCIe: Ask BIOS for control of all native services at once (v6) Rafael J. Wysocki
2010-08-06  1:08 ` Rafael J. Wysocki
2010-08-06  1:09 ` [PATCH 5/10] PCI / PCIe: Disable PCIe port services during port initialization Rafael J. Wysocki
2010-08-06  1:09 ` Rafael J. Wysocki
2010-08-06  1:10 ` [PATCH 6/10] PCI / PCIe: Remove the port driver module exit routine Rafael J. Wysocki
2010-08-06  1:10 ` Rafael J. Wysocki
2010-08-06  1:11 ` [PATCH 7/10] PCI / Hot-plug: Query _OSC before requesting controls Rafael J. Wysocki
2010-08-06  2:20   ` Hidetoshi Seto
2010-08-06  2:20   ` Hidetoshi Seto
2010-08-06 10:34     ` Rafael J. Wysocki
2010-08-09  1:22       ` Kenji Kaneshige
2010-08-09  1:22       ` Kenji Kaneshige
2010-08-06 10:34     ` Rafael J. Wysocki
2010-08-06  1:11 ` Rafael J. Wysocki
2010-08-06  1:12 ` [PATCH 8/10] ACPI / PCI: Do not preserve _OSC control bits returned by a query (v2) Rafael J. Wysocki
2010-08-06  1:12 ` Rafael J. Wysocki
2010-08-06  1:13 ` [PATCH 9/10] ACPI / PCI: Reorder checks in acpi_pci_osc_control_set() Rafael J. Wysocki
2010-08-06  1:13 ` Rafael J. Wysocki
2010-08-06  1:15 ` [PATCH 10/10] ACPI / PCI: Merge acpi_pci_osc_control_{query|set}() Rafael J. Wysocki
2010-08-06  1:15 ` Rafael J. Wysocki
2010-08-06  3:25 ` [PATCH 0/10] ACPI / PCI / PCIe: Rework _OSC handling (v3) Hidetoshi Seto
2010-08-06 10:42   ` Rafael J. Wysocki
2010-08-06 10:42   ` Rafael J. Wysocki
2010-08-06  3:25 ` Hidetoshi Seto
2010-08-20 23:49 ` [PATCH 0/10] ACPI / PCI / PCIe: Rework _OSC handling (v4) Rafael J. Wysocki
2010-08-20 23:50   ` [PATCH 1/10] PCI / PCIe/ AER: Introduce pci_aer_available() Rafael J. Wysocki
2010-08-20 23:50   ` Rafael J. Wysocki
2010-08-24 20:49     ` Jesse Barnes
2010-08-24 20:49     ` Jesse Barnes
2010-08-20 23:51   ` [PATCH 2/10] PCI / PCIe: Introduce commad line switch for disabling port services Rafael J. Wysocki
2010-08-20 23:51   ` Rafael J. Wysocki
2010-08-20 23:52   ` [PATCH 3/10] ACPI / PCI: Reorder checks in acpi_pci_osc_control_set() Rafael J. Wysocki
2010-08-20 23:52   ` Rafael J. Wysocki
2010-08-20 23:53   ` [PATCH 4/10] ACPI / PCI: Make acpi_pci_query_osc() return control bits Rafael J. Wysocki
2010-08-20 23:53   ` Rafael J. Wysocki
2010-08-20 23:54   ` [PATCH 5/10] ACPI / PCI: Do not preserve _OSC control bits returned by a query (v4) Rafael J. Wysocki
2010-08-20 23:54   ` Rafael J. Wysocki
2010-08-23 21:55     ` [Updated changelog][PATCH " Rafael J. Wysocki
2010-08-23 21:55     ` Rafael J. Wysocki
2010-08-20 23:55   ` [PATCH 6/10] ACPI / PCI: Negotiate _OSC control bits before requesting them Rafael J. Wysocki
2010-08-20 23:55   ` Rafael J. Wysocki
2010-08-23 21:53     ` [Update][PATCH 6/10] ACPI / PCI: Negotiate _OSC control bits before requesting them (v2) Rafael J. Wysocki
2010-08-23 21:53     ` Rafael J. Wysocki
2010-08-20 23:56   ` [PATCH 7/10] PCI / PCIe: Ask BIOS for control of all native services at once (v7) Rafael J. Wysocki
2010-08-21 20:02     ` Rafael J. Wysocki
2010-08-21 20:02     ` [linux-pm] " Rafael J. Wysocki
2010-08-20 23:56   ` Rafael J. Wysocki
2010-08-20 23:57   ` [PATCH 8/10] PCI / PCIe: Disable PCIe port services during port initialization Rafael J. Wysocki
2010-08-20 23:57   ` Rafael J. Wysocki
2010-08-20 23:58   ` Rafael J. Wysocki [this message]
2010-08-20 23:58   ` [PATCH 9/10] PCI / PCIe: Move PCIe PME code to the pcie directory Rafael J. Wysocki
2010-08-20 23:59   ` [PATCH 10/10] PCI / PCIe: Remove the port driver module exit routine Rafael J. Wysocki
2010-08-20 23:59   ` Rafael J. Wysocki
2010-08-20 23:49 ` [PATCH 0/10] ACPI / PCI / PCIe: Rework _OSC handling (v4) Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201008210158.23169.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=jbarnes@virtuousgeek.org \
    --cc=kaneshige.kenji@jp.fujitsu.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    --cc=mjg@redhat.com \
    --cc=seto.hidetoshi@jp.fujitsu.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.