From patchwork Sun Sep 13 21:20:58 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rafael Wysocki X-Patchwork-Id: 47199 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8DLQIne022578 for ; Sun, 13 Sep 2009 21:26:18 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754953AbZIMVYr (ORCPT ); Sun, 13 Sep 2009 17:24:47 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755182AbZIMVYq (ORCPT ); Sun, 13 Sep 2009 17:24:46 -0400 Received: from ogre.sisk.pl ([217.79.144.158]:50575 "EHLO ogre.sisk.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755090AbZIMVYl (ORCPT ); Sun, 13 Sep 2009 17:24:41 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by ogre.sisk.pl (Postfix) with ESMTP id C314B14FF98; Sun, 13 Sep 2009 20:19:43 +0200 (CEST) Received: from ogre.sisk.pl ([127.0.0.1]) by localhost (ogre.sisk.pl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 12446-09; Sun, 13 Sep 2009 20:19:12 +0200 (CEST) Received: from tosh.localnet (220-bem-13.acn.waw.pl [82.210.184.220]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ogre.sisk.pl (Postfix) with ESMTP id C7CD7157D19; Sun, 13 Sep 2009 20:19:12 +0200 (CEST) From: "Rafael J. Wysocki" To: pm list Subject: [RFC][PATCH 1/4] PCI PM: Add function for checking PME status of devices Date: Sun, 13 Sep 2009 23:20:58 +0200 User-Agent: KMail/1.12.1 (Linux/2.6.31-rjw; KDE/4.3.1; x86_64; ; ) Cc: Linux PCI , Len Brown , LKML , Jesse Barnes , Matthew Garrett , Shaohua Li , ACPI Devel Maling List References: <200909132320.05077.rjw@sisk.pl> In-Reply-To: <200909132320.05077.rjw@sisk.pl> MIME-Version: 1.0 Message-Id: <200909132320.58093.rjw@sisk.pl> X-Virus-Scanned: amavisd-new at ogre.sisk.pl using MkS_Vir for Linux Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Rafael J. Wysocki Add function pci_check_pme_status() that will check the PME status bit of given device and clear it along with the PME enable bit. It will be necessary for PCI run-time power management. Based on a patch from Shaohua Li Signed-off-by: Rafael J. Wysocki --- drivers/pci/pci.c | 35 +++++++++++++++++++++++++++++++++++ drivers/pci/pci.h | 1 + 2 files changed, 36 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-2.6/drivers/pci/pci.h =================================================================== --- linux-2.6.orig/drivers/pci/pci.h +++ linux-2.6/drivers/pci/pci.h @@ -48,6 +48,7 @@ struct pci_platform_pm_ops { extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops); extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state); extern void pci_disable_enabled_device(struct pci_dev *dev); +extern bool pci_check_pme_status(struct pci_dev *dev); extern void pci_pm_init(struct pci_dev *dev); extern void platform_pci_wakeup_init(struct pci_dev *dev); extern void pci_allocate_cap_save_buffers(struct pci_dev *dev); Index: linux-2.6/drivers/pci/pci.c =================================================================== --- linux-2.6.orig/drivers/pci/pci.c +++ linux-2.6/drivers/pci/pci.c @@ -1161,6 +1161,41 @@ int pci_set_pcie_reset_state(struct pci_ } /** + * pci_check_pme_status - Check if given device has generated PME. + * @dev: Device to check. + * + * Check the PME status of the device, clear PME status and PME enable. Return + * 'true' if PME has been generated by the device (and hasn't been spurious) or + * 'false' otherwise. + */ +bool pci_check_pme_status(struct pci_dev *dev) +{ + int pmcsr_pos; + u16 pmcsr; + bool ret = false; + + if (!dev->pm_cap) + return false; + + pmcsr_pos = dev->pm_cap + PCI_PM_CTRL; + /* clear PME status and disable PME to avoid interrupt flood */ + pci_read_config_word(dev, pmcsr_pos, &pmcsr); + if (!(pmcsr & PCI_PM_CTRL_PME_STATUS)) + return false; + + pmcsr |= PCI_PM_CTRL_PME_STATUS; + /* Ignore spurious PME or clear PME enable if it's not spurious. */ + if (pmcsr & PCI_PM_CTRL_PME_ENABLE) { + pmcsr &= ~PCI_PM_CTRL_PME_ENABLE; + ret = true; + } + + pci_write_config_word(dev, pmcsr_pos, pmcsr); + + return ret; +} + +/** * pci_pme_capable - check the capability of PCI device to generate PME# * @dev: PCI device to handle. * @state: PCI state from which device will issue PME#.