* [PATCH] pci: avoid unnecessary writing of the command register during probe
@ 2013-08-22 22:19 Zoltan Kiss
2013-08-23 16:06 ` Bjorn Helgaas
0 siblings, 1 reply; 2+ messages in thread
From: Zoltan Kiss @ 2013-08-22 22:19 UTC (permalink / raw)
To: Bjorn Helgaas, linux-pci, linux-kernel; +Cc: Zoltan Kiss
While I tracked an another bug, I noticed that the PCI command register is
quite often updated here unnecessarily.
Signed-off-by: Zoltan Kiss <zoltan.kiss@citrix.com>
---
drivers/pci/probe.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 46ada5c..54f6bec 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -178,8 +178,12 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
/* No printks while decoding is disabled! */
if (!dev->mmio_always_on) {
pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
- pci_write_config_word(dev, PCI_COMMAND,
- orig_cmd & ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
+ if (orig_cmd & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)) {
+ pci_write_config_word(dev,
+ PCI_COMMAND,
+ orig_cmd &
+ ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
+ }
}
res->name = pci_name(dev);
@@ -293,7 +297,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
fail:
res->flags = 0;
out:
- if (!dev->mmio_always_on)
+ if (!dev->mmio_always_on &&
+ (orig_cmd & (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)))
pci_write_config_word(dev, PCI_COMMAND, orig_cmd);
if (bar_too_big)
--
1.7.9.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] pci: avoid unnecessary writing of the command register during probe
2013-08-22 22:19 [PATCH] pci: avoid unnecessary writing of the command register during probe Zoltan Kiss
@ 2013-08-23 16:06 ` Bjorn Helgaas
0 siblings, 0 replies; 2+ messages in thread
From: Bjorn Helgaas @ 2013-08-23 16:06 UTC (permalink / raw)
To: Zoltan Kiss; +Cc: linux-pci, linux-kernel
On Thu, Aug 22, 2013 at 11:19:18PM +0100, Zoltan Kiss wrote:
> While I tracked an another bug, I noticed that the PCI command register is
> quite often updated here unnecessarily.
>
> Signed-off-by: Zoltan Kiss <zoltan.kiss@citrix.com>
I applied this to pci/misc with minor tweaks as follows. Let me know
if you see anything wrong.
Bjorn
PCI: Disable decoding for BAR sizing only when it was actually enabled
From: Zoltan Kiss <zoltan.kiss@citrix.com>
We disable BARs while sizing them so we don't cause conflicts with other
devices (see 253d2e5498 and bbffe43524). But if device decoding is already
disabled before we size the BAR, we don't need to disable it again.
[bhelgaas: changelog, add PCI_COMMAND_DECODING_ENABLE for readability]
Signed-off-by: Zoltan Kiss <zoltan.kiss@citrix.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
drivers/pci/probe.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index cf57fe7..2c6f328 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -165,6 +165,8 @@ static inline unsigned long decode_bar(struct pci_dev *dev, u32 bar)
*
* Returns 1 if the BAR is 64-bit, or 0 if 32-bit.
*/
+#define PCI_COMMAND_DECODE_ENABLE (PCI_COMMAND_MEMORY | PCI_COMMAND_IO)
+
int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
struct resource *res, unsigned int pos)
{
@@ -178,8 +180,10 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
/* No printks while decoding is disabled! */
if (!dev->mmio_always_on) {
pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
- pci_write_config_word(dev, PCI_COMMAND,
- orig_cmd & ~(PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
+ if (orig_cmd & PCI_COMMAND_DECODE_ENABLE) {
+ pci_write_config_word(dev, PCI_COMMAND,
+ orig_cmd & ~PCI_COMMAND_DECODE_ENABLE);
+ }
}
res->name = pci_name(dev);
@@ -293,7 +297,8 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
fail:
res->flags = 0;
out:
- if (!dev->mmio_always_on)
+ if (!dev->mmio_always_on &&
+ (orig_cmd & PCI_COMMAND_DECODE_ENABLE))
pci_write_config_word(dev, PCI_COMMAND, orig_cmd);
if (bar_too_big)
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-08-23 16:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-22 22:19 [PATCH] pci: avoid unnecessary writing of the command register during probe Zoltan Kiss
2013-08-23 16:06 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).