From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bjorn Helgaas Subject: Re: [RFC][PATCH 1/4] PCI PM: Add function for checking PME status of devices Date: Thu, 8 Oct 2009 17:32:02 -0600 Message-ID: <200910081732.03157.bjorn.helgaas@hp.com> References: <200910090051.50932.rjw@sisk.pl> <200910090052.48493.rjw@sisk.pl> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <200910090052.48493.rjw@sisk.pl> Content-Disposition: inline List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org To: "Rafael J. Wysocki" Cc: Linux PCI , LKML , Jesse Barnes , ACPI Devel Maling List , pm list List-Id: linux-acpi@vger.kernel.org On Thursday 08 October 2009 04:52:48 pm Rafael J. Wysocki wrote: > 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(+) > > Index: linux-2.6/drivers/pci/pci.h > =================================================================== > --- linux-2.6.orig/drivers/pci/pci.h > +++ linux-2.6/drivers/pci/pci.h > @@ -49,6 +49,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 > @@ -1167,6 +1167,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. This comment confuses me because it implies that we always clear PME enable, but that's not what the code does. If PME_STATUS is not asserted, the code doesn't write anything. > + */ > +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); I can't tell whether the comment or the code is what was intended, but I think the following would be a clearer way to implement the comment: pci_read_config_word(..., &pmcsr); pci_write_config_word(..., (pmcsr | STATUS) & ~ENABLE); if ((pmcsr & ENABLE) && (pmcsr & STATUS)) return true; return false; Bjorn > + > + 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#. > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760119AbZJHXcp (ORCPT ); Thu, 8 Oct 2009 19:32:45 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758153AbZJHXco (ORCPT ); Thu, 8 Oct 2009 19:32:44 -0400 Received: from g1t0027.austin.hp.com ([15.216.28.34]:43386 "EHLO g1t0027.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755715AbZJHXcm (ORCPT ); Thu, 8 Oct 2009 19:32:42 -0400 From: Bjorn Helgaas To: "Rafael J. Wysocki" Subject: Re: [RFC][PATCH 1/4] PCI PM: Add function for checking PME status of devices Date: Thu, 8 Oct 2009 17:32:02 -0600 User-Agent: KMail/1.9.10 Cc: Linux PCI , pm list , Jesse Barnes , Matthew Garrett , ACPI Devel Maling List , LKML , Alan Stern , Shaohua Li References: <200910090051.50932.rjw@sisk.pl> <200910090052.48493.rjw@sisk.pl> In-Reply-To: <200910090052.48493.rjw@sisk.pl> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200910081732.03157.bjorn.helgaas@hp.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thursday 08 October 2009 04:52:48 pm Rafael J. Wysocki wrote: > 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(+) > > Index: linux-2.6/drivers/pci/pci.h > =================================================================== > --- linux-2.6.orig/drivers/pci/pci.h > +++ linux-2.6/drivers/pci/pci.h > @@ -49,6 +49,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 > @@ -1167,6 +1167,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. This comment confuses me because it implies that we always clear PME enable, but that's not what the code does. If PME_STATUS is not asserted, the code doesn't write anything. > + */ > +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); I can't tell whether the comment or the code is what was intended, but I think the following would be a clearer way to implement the comment: pci_read_config_word(..., &pmcsr); pci_write_config_word(..., (pmcsr | STATUS) & ~ENABLE); if ((pmcsr & ENABLE) && (pmcsr & STATUS)) return true; return false; Bjorn > + > + 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#. >