public inbox for linux-pm@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Bjorn Helgaas <bjorn.helgaas@hp.com>
Cc: Linux PCI <linux-pci@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Jesse Barnes <jbarnes@virtuousgeek.org>,
	ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	pm list <linux-pm@lists.linux-foundation.org>
Subject: Re: [RFC][PATCH 1/4] PCI PM: Add function for checking PME status of devices
Date: Sat, 10 Oct 2009 00:11:28 +0200	[thread overview]
Message-ID: <200910100011.28268.rjw@sisk.pl> (raw)
In-Reply-To: <200910081732.03157.bjorn.helgaas@hp.com>

On Friday 09 October 2009, Bjorn Helgaas wrote:
> On Thursday 08 October 2009 04:52:48 pm Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rjw@sisk.pl>
> > 
> > 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 <shaohua.li@intel.com>
> > 
> > Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
> > ---
> >  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.

Well, that's a shortcut, perhaps going too far.  It should say "clear PME
status and PME enable, if the PME status was set".  Will fix.

> > + */
> > +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,

The code.  I'll fix the comment.

> 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;

Thanks,
Rafael

  reply	other threads:[~2009-10-09 22:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200910090051.50932.rjw@sisk.pl>
2009-10-08 22:52 ` [RFC][PATCH 1/4] PCI PM: Add function for checking PME status of devices Rafael J. Wysocki
2009-10-08 22:53 ` [RFC][PATCH 2/4] PCI PM: PCIe PME root port service driver (rev. 3) Rafael J. Wysocki
2009-10-08 22:54 ` [RFC][PATCH 3/4] PCI / ACPI PM: Platform support for PCI PME wake-up (rev. 2) Rafael J. Wysocki
2009-10-09 11:23   ` Matthew Garrett
2009-10-09 23:05     ` Rafael J. Wysocki
2009-10-08 22:55 ` [RFC][PATCH 4/4] PCI PM: Run-time callbacks for PCI bus type Rafael J. Wysocki
     [not found] ` <200910090052.48493.rjw@sisk.pl>
2009-10-08 23:32   ` [RFC][PATCH 1/4] PCI PM: Add function for checking PME status of devices Bjorn Helgaas
2009-10-09 22:11     ` Rafael J. Wysocki [this message]
     [not found] ` <1257806529-6535-1-git-send-email-mjg@redhat.com>
2009-11-11 19:58   ` [PATCH] pci: Updates to Rafael's runtime PCI PM patch set Rafael J. Wysocki
     [not found]   ` <200911112058.20331.rjw@sisk.pl>
2009-11-11 20:05     ` Matthew Garrett
     [not found]     ` <20091111200503.GA22328@srcf.ucam.org>
2009-11-11 20:47       ` Rafael J. Wysocki
     [not found] <200909132320.05077.rjw@sisk.pl>
2009-09-13 21:20 ` [RFC][PATCH 1/4] PCI PM: Add function for checking PME status of devices Rafael J. Wysocki
     [not found] ` <200909132320.58093.rjw@sisk.pl>
2009-09-13 22:15   ` Matthew Garrett

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=200910100011.28268.rjw@sisk.pl \
    --to=rjw@sisk.pl \
    --cc=bjorn.helgaas@hp.com \
    --cc=jbarnes@virtuousgeek.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-pm@lists.linux-foundation.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox