Skip to contentSkip to conversation

pci: fix nit in ROM BAR size probing

PATCH In review Michael S. Tsirkin 2 participants 4 messages Oct 29, 2009 – Nov 4, 2009 PCI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pci: fix nit in ROM BAR size probing

When probing for ROM BAR size, we should not change bits 1:10 in this BAR, because these
bits are marked as "reserved for future use" in PCI spec, so changing them might have side effects.

No such issue for I/O or memory, as there is
an implementation note in PCI spec which explicitly allows writing 0xfffffffff there.

---
 drivers/pci/probe.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/pci/probe.c +2 -2
index 8105e32..d65aae4 100644
@@ -163,12 +163,12 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 {
 	u32 l, sz, mask;
 
-	mask = type ? ~PCI_ROM_ADDRESS_ENABLE : ~0;
+	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
 
 	res->name = pci_name(dev);
 
 	pci_read_config_dword(dev, pos, &l);
-	pci_write_config_dword(dev, pos, mask);
+	pci_write_config_dword(dev, pos, l | mask);
 	pci_read_config_dword(dev, pos, &sz);
 	pci_write_config_dword(dev, pos, l);
 
Signature · 1 line
1.6.5.rc2
#1 lore raw
Quoted 22 lines · On Thu, 29 Oct 2009 17:24:59 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

When probing for ROM BAR size, we should not change bits 1:10 in this BAR, because these
bits are marked as "reserved for future use" in PCI spec, so changing them might have side effects.

No such issue for I/O or memory, as there is
an implementation note in PCI spec which explicitly allows writing 0xfffffffff there.

---
 drivers/pci/probe.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/pci/probe.c +0 -0
index 8105e32..d65aae4 100644
@@ -163,12 +163,12 @@ int __pci_read_base(struct pci_dev *dev, enum
 pci_bar_type type, {
 	u32 l, sz, mask;
 

drivers/pci/probe.c int __pci_read_base(struct pci_dev *dev, enum · line 173

Quoted 10 lines
drivers/pci/probe.c +2 -2
-	mask = type ? ~PCI_ROM_ADDRESS_ENABLE : ~0;
+	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
 
 	res->name = pci_name(dev);
 
 	pci_read_config_dword(dev, pos, &l);
-	pci_write_config_dword(dev, pos, mask);
+	pci_write_config_dword(dev, pos, l | mask);
 	pci_read_config_dword(dev, pos, &sz);
 	pci_write_config_dword(dev, pos, l);

Applied to linux-next, thanks. Another possible enhancement here would be to make the mask into a switch based on the type, since mem32 and mem64 "BARs" (added by willy for doing BAR-like stuff) could probably use ~0 as well.

Jesse

#2 lore raw
Quoted 41 lines · Jesse Barnes
Quoted 22 lines · On Thu, 29 Oct 2009 17:24:59 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

When probing for ROM BAR size, we should not change bits 1:10 in this BAR, because these
bits are marked as "reserved for future use" in PCI spec, so changing them might have side effects.

No such issue for I/O or memory, as there is
an implementation note in PCI spec which explicitly allows writing 0xfffffffff there.

---
 drivers/pci/probe.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/pci/probe.c +0 -0
index 8105e32..d65aae4 100644
@@ -163,12 +163,12 @@ int __pci_read_base(struct pci_dev *dev, enum
 pci_bar_type type, {
 	u32 l, sz, mask;
 

drivers/pci/probe.c int __pci_read_base(struct pci_dev *dev, enum · line 173

Quoted 10 lines
drivers/pci/probe.c +2 -2
-	mask = type ? ~PCI_ROM_ADDRESS_ENABLE : ~0;
+	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
 
 	res->name = pci_name(dev);
 
 	pci_read_config_dword(dev, pos, &l);
-	pci_write_config_dword(dev, pos, mask);
+	pci_write_config_dword(dev, pos, l | mask);
 	pci_read_config_dword(dev, pos, &sz);
 	pci_write_config_dword(dev, pos, l);

Applied to linux-next, thanks. Another possible enhancement here would be to make the mask into a switch based on the type, since mem32 and mem64 "BARs" (added by willy for doing BAR-like stuff) could probably use ~0 as well.

Quoted 1 line

Jesse

Where can I find the patch by willy that adds these?

Signature · 1 line
MST
#3 lore raw
Quoted 42 lines · On Wed, 4 Nov 2009 19:06:19 +0200 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 41 lines · Jesse Barnes
Quoted 22 lines · On Thu, 29 Oct 2009 17:24:59 +0200 "Michael S. Tsirkin" <[email protected]> wrote:

When probing for ROM BAR size, we should not change bits 1:10 in this BAR, because these
bits are marked as "reserved for future use" in PCI spec, so changing them might have side effects.

No such issue for I/O or memory, as there is
an implementation note in PCI spec which explicitly allows writing 0xfffffffff there.

---
 drivers/pci/probe.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/pci/probe.c +0 -0
index 8105e32..d65aae4 100644
@@ -163,12 +163,12 @@ int __pci_read_base(struct pci_dev *dev,
 enum pci_bar_type type, {
 	u32 l, sz, mask;
 

drivers/pci/probe.c int __pci_read_base(struct pci_dev *dev, · line 173

Quoted 10 lines
drivers/pci/probe.c +2 -2
-	mask = type ? ~PCI_ROM_ADDRESS_ENABLE : ~0;
+	mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
 
 	res->name = pci_name(dev);
 
 	pci_read_config_dword(dev, pos, &l);
-	pci_write_config_dword(dev, pos, mask);
+	pci_write_config_dword(dev, pos, l | mask);
 	pci_read_config_dword(dev, pos, &sz);
 	pci_write_config_dword(dev, pos, l);

Applied to linux-next, thanks. Another possible enhancement here would be to make the mask into a switch based on the type, since mem32 and mem64 "BARs" (added by willy for doing BAR-like stuff) could probably use ~0 as well.

Quoted 3 lines
Quoted 1 line

Jesse

Where can I find the patch by willy that adds these?

commit 6ac665c63dcac8fcec534a1d224ecbb8b867ad59

Author: Matthew Wilcox <[email protected]>
Date:   Mon Jul 28 13:38:59 2008 -0400

PCI: rewrite PCI BAR reading code

Signature · 1 line
Jesse Barnes, Intel Open Source Technology Center