Skip to contentSkip to conversation

RFC: PCI: consolidate several pcibios_enable_resources() implementations

PATCH In review Bjorn Helgaas 6 participants 18 messages Feb 19, 2008 – Feb 20, 2008

Subsystems (10)
Arm (32-bit) x86 PowerPC PCI +6 more subsystems
lore
Share & tools
lore
#0 lore raw

cover RFC: PCI: consolidate several pcibios_enable_resources() implementations

There are many implementations of pcibios_enable_resources() that differ in minor ways that look more like bugs than architectural differences. This patch series consolidates most of them to use the x86 version.

This series is for discussion only at this point. I'm interested in feedback about whether any of the differences are "real" and need to be preserved.

ARM and PA-RISC, in particular, have interesting differences:
- ARM always enables bridge devices, which no other arch does
- PA-RISC always turns on SERR and PARITY, which no other arch does

Should other arches do the same thing, or are these somehow related to ARM and PA-RISC architecture?

Bjorn

#1 lore raw

PATCH 1/4 PCI: split pcibios_enable_resources() out of pcibios_enable_device()

On x86, pcibios_enable_device() is factored into pcibios_enable_resources() and pcibios_enable_irq(). On several other architectures, the functional equivalent of pcibios_enable_resources() is expanded directly inside pcibios_enable_device().

This splits these pcibios_enable_device() implementations to make them more similar to the x86 implementation.

There should be no functional change from this patch.

---
 arch/alpha/kernel/pci.c          |    8 +++++++-
 arch/arm/kernel/bios32.c         |    9 +++++++--
 arch/parisc/kernel/pci.c         |    6 +++++-
 arch/powerpc/kernel/pci-common.c |   14 +++++++++-----
 arch/sh/drivers/pci/pci.c        |    7 ++++++-
 arch/sparc64/kernel/pci.c        |    7 ++++++-
 arch/v850/kernel/rte_mb_a_pci.c  |    7 ++++++-
 7 files changed, 46 insertions(+), 12 deletions(-)
arch/alpha/kernel/pci.c +7 -1
Index: work6/arch/alpha/kernel/pci.c
===================================================================
@@ -370,7 +370,7 @@
 #endif
 
 int
-pcibios_enable_device(struct pci_dev *dev, int mask)
+pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, oldcmd;
 	int i;
@@ -396,6 +396,12 @@
 	return 0;
 }
 
+int
+pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 /*
  *  If we set up a device for bus mastering, we need to check the latency
  *  timer as certain firmware forgets to set it properly, as seen
arch/arm/kernel/bios32.c +7 -2
Index: work6/arch/arm/kernel/bios32.c
===================================================================
@@ -655,10 +655,10 @@
 }
 
 /**
- * pcibios_enable_device - Enable I/O and memory.
+ * pcibios_enable_resources - Enable I/O and memory.
  * @dev: PCI device to be enabled
  */
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, old_cmd;
 	int idx;
@@ -697,6 +697,11 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
 			enum pci_mmap_state mmap_state, int write_combine)
 {
arch/parisc/kernel/pci.c +5 -1
Index: work6/arch/parisc/kernel/pci.c
===================================================================
@@ -285,7 +285,7 @@
  * Drivers that do not need parity (eg graphics and possibly networking)
  * can clear these bits if they want.
  */
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd;
 	int idx;
@@ -317,6 +317,10 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
 
 /* PA-RISC specific */
 void pcibios_register_hba(struct pci_hba_data *hba)
arch/powerpc/kernel/pci-common.c +9 -5
Index: work6/arch/powerpc/kernel/pci-common.c
===================================================================
@@ -1153,16 +1153,12 @@
 EXPORT_SYMBOL_GPL(pcibios_claim_one_bus);
 #endif /* CONFIG_HOTPLUG */
 
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, old_cmd;
 	int idx;
 	struct resource *r;
 
-	if (ppc_md.pcibios_enable_device_hook)
-		if (ppc_md.pcibios_enable_device_hook(dev))
-			return -EINVAL;
-
 	pci_read_config_word(dev, PCI_COMMAND, &cmd);
 	old_cmd = cmd;
 	for (idx = 0; idx < PCI_NUM_RESOURCES; idx++) {
@@ -1193,3 +1189,11 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	if (ppc_md.pcibios_enable_device_hook)
+		if (ppc_md.pcibios_enable_device_hook(dev))
+			return -EINVAL;
+
+	return pcibios_enable_resources(dev, mask);
+}
arch/sh/drivers/pci/pci.c +6 -1
Index: work6/arch/sh/drivers/pci/pci.c
===================================================================
@@ -131,7 +131,7 @@
 	}
 }
 
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, old_cmd;
 	int idx;
@@ -163,6 +163,11 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 /*
  *  If we set up a device for bus mastering, we need to check and set
  *  the latency timer as it may not be properly set.
arch/sparc64/kernel/pci.c +6 -1
Index: work6/arch/sparc64/kernel/pci.c
===================================================================
@@ -946,7 +946,7 @@
 {
 }
 
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, oldcmd;
 	int i;
@@ -976,6 +976,11 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 void pcibios_resource_to_bus(struct pci_dev *pdev, struct pci_bus_region *region,
 			     struct resource *res)
 {
arch/v850/kernel/rte_mb_a_pci.c +6 -1
Index: work6/arch/v850/kernel/rte_mb_a_pci.c
===================================================================
@@ -217,7 +217,7 @@
 }
 
 
-int __nomods_init pcibios_enable_device (struct pci_dev *dev, int mask)
+int __nomods_init pcibios_enable_resources (struct pci_dev *dev, int mask)
 {
 	u16 cmd, old_cmd;
 	int idx;
@@ -245,6 +245,11 @@
 	return 0;
 }
 
+int __nomods_init pcibios_enable_device (struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 
 /* Resource allocation.  */
 static void __devinit pcibios_assign_resources (void)
Acked-by on v1 1/4
#2 lore raw

Re: [patch 1/4] PCI: split pcibios_enable_resources() out of pcibios_enable_device()

Quoted 6 lines · Bjorn Helgaas

plain text document attachment (make-pcibios_enable_resources) On x86, pcibios_enable_device() is factored into pcibios_enable_resources() and pcibios_enable_irq(). On several other architectures, the functional equivalent of pcibios_enable_resources() is expanded directly inside pcibios_enable_device().

Quoted 6 lines

This splits these pcibios_enable_device() implementations to make them more similar to the x86 implementation.

There should be no functional change from this patch.

Quoted 200 lines
---
 arch/alpha/kernel/pci.c          |    8 +++++++-
 arch/arm/kernel/bios32.c         |    9 +++++++--
 arch/parisc/kernel/pci.c         |    6 +++++-
 arch/powerpc/kernel/pci-common.c |   14 +++++++++-----
 arch/sh/drivers/pci/pci.c        |    7 ++++++-
 arch/sparc64/kernel/pci.c        |    7 ++++++-
 arch/v850/kernel/rte_mb_a_pci.c  |    7 ++++++-
 7 files changed, 46 insertions(+), 12 deletions(-)

Index: work6/arch/alpha/kernel/pci.c
===================================================================

arch/alpha/kernel/pci.c +7 -1
@@ -370,7 +370,7 @@
 #endif
 
 int
-pcibios_enable_device(struct pci_dev *dev, int mask)
+pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, oldcmd;
 	int i;
@@ -396,6 +396,12 @@
 	return 0;
 }
 
+int
+pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 /*
  *  If we set up a device for bus mastering, we need to check the latency
  *  timer as certain firmware forgets to set it properly, as seen

Index: work6/arch/arm/kernel/bios32.c
===================================================================

arch/arm/kernel/bios32.c +7 -2
@@ -655,10 +655,10 @@
 }
 
 /**
- * pcibios_enable_device - Enable I/O and memory.
+ * pcibios_enable_resources - Enable I/O and memory.
  * @dev: PCI device to be enabled
  */
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, old_cmd;
 	int idx;
@@ -697,6 +697,11 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
 			enum pci_mmap_state mmap_state, int write_combine)
 {

Index: work6/arch/parisc/kernel/pci.c
===================================================================

arch/parisc/kernel/pci.c +5 -1
@@ -285,7 +285,7 @@
  * Drivers that do not need parity (eg graphics and possibly networking)
  * can clear these bits if they want.
  */
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd;
 	int idx;
@@ -317,6 +317,10 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
 
 /* PA-RISC specific */
 void pcibios_register_hba(struct pci_hba_data *hba)

Index: work6/arch/powerpc/kernel/pci-common.c
===================================================================

arch/powerpc/kernel/pci-common.c +9 -5
@@ -1153,16 +1153,12 @@
 EXPORT_SYMBOL_GPL(pcibios_claim_one_bus);
 #endif /* CONFIG_HOTPLUG */
 
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, old_cmd;
 	int idx;
 	struct resource *r;
 
-	if (ppc_md.pcibios_enable_device_hook)
-		if (ppc_md.pcibios_enable_device_hook(dev))
-			return -EINVAL;
-
 	pci_read_config_word(dev, PCI_COMMAND, &cmd);
 	old_cmd = cmd;
 	for (idx = 0; idx < PCI_NUM_RESOURCES; idx++) {
@@ -1193,3 +1189,11 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	if (ppc_md.pcibios_enable_device_hook)
+		if (ppc_md.pcibios_enable_device_hook(dev))
+			return -EINVAL;
+
+	return pcibios_enable_resources(dev, mask);
+}

Index: work6/arch/sh/drivers/pci/pci.c
===================================================================

arch/sh/drivers/pci/pci.c +6 -1
@@ -131,7 +131,7 @@
 	}
 }
 
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, old_cmd;
 	int idx;
@@ -163,6 +163,11 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 /*
  *  If we set up a device for bus mastering, we need to check and set
  *  the latency timer as it may not be properly set.

Index: work6/arch/sparc64/kernel/pci.c
===================================================================

arch/sparc64/kernel/pci.c +6 -1
@@ -946,7 +946,7 @@
 {
 }
 
-int pcibios_enable_device(struct pci_dev *dev, int mask)
+int pcibios_enable_resources(struct pci_dev *dev, int mask)
 {
 	u16 cmd, oldcmd;
 	int i;
@@ -976,6 +976,11 @@
 	return 0;
 }
 
+int pcibios_enable_device(struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 void pcibios_resource_to_bus(struct pci_dev *pdev, struct pci_bus_region *region,
 			     struct resource *res)
 {

Index: work6/arch/v850/kernel/rte_mb_a_pci.c
===================================================================

arch/v850/kernel/rte_mb_a_pci.c +6 -1
@@ -217,7 +217,7 @@
 }
 
 
-int __nomods_init pcibios_enable_device (struct pci_dev *dev, int mask)
+int __nomods_init pcibios_enable_resources (struct pci_dev *dev, int mask)
 {
 	u16 cmd, old_cmd;
 	int idx;
@@ -245,6 +245,11 @@
 	return 0;
 }
 
+int __nomods_init pcibios_enable_device (struct pci_dev *dev, int mask)
+{
+	return pcibios_enable_resources(dev, mask);
+}
+
 
 /* Resource allocation.  */
 static void __devinit pcibios_assign_resources (void)
#3 lore raw

PATCH 2/4 ppc: make pcibios_enable_device() use pcibios_enable_resources()

In reply to Bjorn Helgaas

pcibios_enable_device() has an almost verbatim copy of pcibios_enable_resources(), (the only difference is that pcibios_enable_resources() turns on PCI_COMMAND_MEMORY if there's a ROM resource).

The duplication might be intentional, but I don't see any callers of pcibios_enable_resources() on ppc, so I think it's more likely a historical accident.

This patch removes the duplication, making pcibios_enable_device() simply call pcibios_enable_resources() as x86 does.

arch/ppc/kernel/pci.c +2 -24
Index: work6/arch/ppc/kernel/pci.c
===================================================================
@@ -785,33 +785,11 @@
 
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
 	if (ppc_md.pcibios_enable_device_hook)
 		if (ppc_md.pcibios_enable_device_hook(dev, 0))
 			return -EINVAL;
-		
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for (idx=0; idx<6; idx++) {
-		r = &dev->resource[idx];
-		if (r->flags & IORESOURCE_UNSET) {
-			printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n",
-		       pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
+
+	return pcibios_enable_resources(dev, mask);
 }
 
 struct pci_controller*
#4 lore raw

Re: [patch 2/4] ppc: make pcibios_enable_device() use pcibios_enable_resources()

Quoted 6 lines · Bjorn Helgaas

plain text document attachment (ppc-pcibios_enable_resources) pcibios_enable_device() has an almost verbatim copy of pcibios_enable_resources(), (the only difference is that pcibios_enable_resources() turns on PCI_COMMAND_MEMORY if there's a ROM resource).

Quoted 8 lines

The duplication might be intentional, but I don't see any callers of pcibios_enable_resources() on ppc, so I think it's more likely a historical accident.

This patch removes the duplication, making pcibios_enable_device() simply call pcibios_enable_resources() as x86 does.

Ack. arch/ppc is being phased out soon anyway.

Ben.

Quoted 42 lines

Index: work6/arch/ppc/kernel/pci.c
===================================================================

arch/ppc/kernel/pci.c +2 -24
@@ -785,33 +785,11 @@
 
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
 	if (ppc_md.pcibios_enable_device_hook)
 		if (ppc_md.pcibios_enable_device_hook(dev, 0))
 			return -EINVAL;
-		
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for (idx=0; idx<6; idx++) {
-		r = &dev->resource[idx];
-		if (r->flags & IORESOURCE_UNSET) {
-			printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n",
-		       pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
+
+	return pcibios_enable_resources(dev, mask);
 }
 
 struct pci_controller*
#5 lore raw

PATCH 3/4 xtensa: make pcibios_enable_device() use pcibios_enable_resources()

In reply to Bjorn Helgaas

pcibios_enable_device() has an almost verbatim copy of pcibios_enable_resources(), (the only difference is that pcibios_enable_resources() turns on PCI_COMMAND_MEMORY if there's a ROM resource).

The duplication might be intentional, but I don't see any callers of pcibios_enable_resources() on xtensa, so I think it's more likely a historical accident copied from ppc.

This patch removes the duplication, making pcibios_enable_device() simply call pcibios_enable_resources() as x86 does.

arch/xtensa/kernel/pci.c +1 -25
Index: work6/arch/xtensa/kernel/pci.c
===================================================================
@@ -238,31 +238,7 @@
 
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for (idx=0; idx<6; idx++) {
-		r = &dev->resource[idx];
-		if (!r->start && r->end) {
-			printk(KERN_ERR "PCI: Device %s not available because "
-			       "of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n",
-		       pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-
-	return 0;
+	return pcibios_enable_resources(dev, mask);
 }
 
 #ifdef CONFIG_PROC_FS
#6 lore raw

PATCH 4/4 RFC: PCI: consolidate several pcibios_enable_resources() implementations

In reply to Bjorn Helgaas

There are many implementations of pcibios_enable_resources() that differ in minor ways that look more like bugs than architectural differences. This patch consolidates most of them to use the x86 version.

This patch is for discussion only at this point. I'm interested in feedback about whether any of the differences are "real" and need to be preserved.

ARM and PA-RISC, in particular, have interesting differences:
- ARM always enables bridge devices, which no other arch does
- PA-RISC always turns on SERR and PARITY, which no other arch does

Should other arches do the same thing, or are these somehow related to ARM and PA-RISC architecture?

Here's the x86 version, which seems most complete and up-to-date:

    int pcibios_enable_resources(struct pci_dev *dev, int mask)
    {
	u16 cmd, old_cmd;
	int i;
	struct resource *r;

(0)

	pci_read_config_word(dev, PCI_COMMAND, &cmd);
	old_cmd = cmd;

(1) for (i = 0; i < PCI_NUM_RESOURCES; i++) {
(2) if (!(mask & (1 << i)))

			continue;

		r = &dev->resource[i];

(3) if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))

			continue;

(4) if ((i == PCI_ROM_RESOURCE) &&

				(!(r->flags & IORESOURCE_ROM_ENABLE)))
			continue;
  (5)		if (!r->start && r->end) {
			dev_err(&dev->dev, "device not available because of "
				"resource %d collisions\n", i);
			return -EINVAL;
		}

		if (r->flags & IORESOURCE_IO)
			cmd |= PCI_COMMAND_IO;
		if (r->flags & IORESOURCE_MEM)
			cmd |= PCI_COMMAND_MEMORY;
	}

(6)

  (7)	if (cmd != old_cmd) {
		dev_info(&dev->dev, "enabling device (%04x -> %04x)\n",
			 old_cmd, cmd);
		pci_write_config_word(dev, PCI_COMMAND, cmd);
	}
	return 0;
    }

Compared with the x86 version, other architectures have the following functional differences:

alpha: ignores mask at (2), has no PCI_ROM_RESOURCE check at (4),
has no collision check at (5)

arm: checks only 6 resources at (1), has no PCI_ROM_RESOURCE check at (4),
always fully enables bridges at (6)

cris: checks only 6 resources at (1), has a different ROM
resource check at (4) and (6) that ignores IORESOURCE_ROM_ENABLE

frv: checks only 6 resources at (1), has a different ROM
resource check at (4) and (6) that ignores IORESOURCE_ROM_ENABLE

ia64: checks for NULL dev at (0)

mips: has no IORESOURCE_{IO,MEM} check at (3), has a different
ROM resource check at (4) and (6) that ignores IORESOURCE_ROM_ENABLE

mn10300: checks only 6 resources at (1), has no IORESOURCE_{IO,MEM}
check at (3), has a different ROM resource check at (4) and (6) that ignores IORESOURCE_ROM_ENABLE

parisc: checks DEVICE_COUNT_RESOURCE (12) instead of PCI_NUM_RESOURCES (11)
resources at (1), has no IORESOURCE_{IO,MEM} check at (3), has no PCI_ROM_RESOURCE check at (4), has no collision check at (5) always turns on PCI_COMMAND_SERR | PCI_COMMAND_PARITY at (6), writes cmd even if unchanged at (7)

powerpc: has a different collision check at (5)

ppc: checks only 6 resources at (1), has no IORESOURCE_{IO,MEM} check
at (3), has a different ROM resource check at (4) and (6) that ignores IORESOURCE_ROM_ENABLE, has a different collision check using IORESOURCE_UNSET at (5)

sh: checks only 6 resources at (1), has no IORESOURCE_{IO,MEM} check
at (3), has a different ROM resource check at (4) and (6) that ignores IORESOURCE_ROM_ENABLE

sparc64: has no IORESOURCE_{IO,MEM} check at (3), has no PCI_ROM_RESOURCE
check at (4)

v850: checks only 6 resources at (1), has no IORESOURCE_{IO,MEM} check
at (3), has no PCI_ROM_RESOURCE check at (4)

xtensa: checks only 6 resources at (1), has no IORESOURCE_{IO,MEM} check
at (3), has a different ROM resource check at (4) and (6) that ignores IORESOURCE_ROM_ENABLE

The mips/pmc-sierra implementation of pcibios_enable_resources() is cluttered with a bunch of titan stuff, so I can't immediately consolidate it with the others. So I made the generic version "weak" so pmc-sierra can override it.

---
 arch/alpha/kernel/pci.c                 |   27 -------------
 arch/arm/kernel/bios32.c                |   43 ---------------------
 arch/cris/arch-v32/drivers/pci/bios.c   |   32 ----------------
 arch/frv/mb93090-mb00/pci-frv.c         |   32 ----------------
 arch/ia64/pci/pci.c                     |   42 ---------------------
 arch/mips/pci/pci.c                     |   32 ----------------
 arch/mn10300/unit-asb2305/pci-asb2305.c |   39 -------------------
 arch/parisc/kernel/pci.c                |   41 --------------------
 arch/powerpc/kernel/pci-common.c        |   36 ------------------
 arch/ppc/kernel/pci.c                   |   33 ----------------
 arch/sh/drivers/pci/pci.c               |   32 ----------------
 arch/sparc64/kernel/pci.c               |   30 ---------------
 arch/v850/kernel/rte_mb_a_pci.c         |   28 --------------
 arch/x86/pci/i386.c                     |   38 -------------------
 arch/x86/pci/pci.h                      |    1 
 arch/xtensa/kernel/pci.c                |   31 ---------------
 drivers/pci/Makefile                    |    2 -
 drivers/pci/bios.c                      |   64 ++++++++++++++++++++++++++++++++
 include/linux/pci.h                     |    1 
 19 files changed, 66 insertions(+), 518 deletions(-)
arch/alpha/kernel/pci.c +0 -27
Index: work6/arch/alpha/kernel/pci.c
===================================================================
@@ -370,33 +370,6 @@
 #endif
 
 int
-pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, oldcmd;
-	int i;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	oldcmd = cmd;
-
-	for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-		struct resource *res = &dev->resource[i];
-
-		if (res->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		else if (res->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-
-	if (cmd != oldcmd) {
-		printk(KERN_DEBUG "PCI: Enabling device: (%s), cmd %x\n",
-		       pci_name(dev), cmd);
-		/* Enable the appropriate bits in the PCI command register.  */
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
-int
 pcibios_enable_device(struct pci_dev *dev, int mask)
 {
 	return pcibios_enable_resources(dev, mask);
arch/arm/kernel/bios32.c +0 -43

49 lines not on this page · raw message

arch/cris/arch-v32/drivers/pci/bios.c +0 -32
Index: work6/arch/cris/arch-v32/drivers/pci/bios.c
===================================================================
@@ -55,38 +55,6 @@
 	}
 }
 
-int pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for(idx=0; idx<6; idx++) {
-		/* Only set up the requested stuff */
-		if (!(mask & (1<<idx)))
-			continue;
-
-		r = &dev->resource[idx];
-		if (!r->start && r->end) {
-			printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (dev->resource[PCI_ROM_RESOURCE].start)
-		cmd |= PCI_COMMAND_MEMORY;
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 int pcibios_enable_irq(struct pci_dev *dev)
 {
 	dev->irq = EXT_INTR_VECT;
arch/frv/mb93090-mb00/pci-frv.c +0 -32
Index: work6/arch/frv/mb93090-mb00/pci-frv.c
===================================================================
@@ -231,38 +231,6 @@
 	pcibios_assign_resources();
 }
 
-int pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for(idx=0; idx<6; idx++) {
-		/* Only set up the requested stuff */
-		if (!(mask & (1<<idx)))
-			continue;
-
-		r = &dev->resource[idx];
-		if (!r->start && r->end) {
-			printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (dev->resource[PCI_ROM_RESOURCE].start)
-		cmd |= PCI_COMMAND_MEMORY;
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 /*
  *  If we set up a device for bus mastering, we need to check the latency
  *  timer as certain crappy BIOSes forget to set it properly.
arch/ia64/pci/pci.c +0 -42

48 lines not on this page · raw message

arch/mips/pci/pci.c +0 -32
Index: work6/arch/mips/pci/pci.c
===================================================================
@@ -163,38 +163,6 @@
 
 subsys_initcall(pcibios_init);
 
-static int pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for (idx=0; idx < PCI_NUM_RESOURCES; idx++) {
-		/* Only set up the requested stuff */
-		if (!(mask & (1<<idx)))
-			continue;
-
-		r = &dev->resource[idx];
-		if (!r->start && r->end) {
-			printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (dev->resource[PCI_ROM_RESOURCE].start)
-		cmd |= PCI_COMMAND_MEMORY;
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 /*
  *  If we set up a device for bus mastering, we need to check the latency
  *  timer as certain crappy BIOSes forget to set it properly.
arch/mn10300/unit-asb2305/pci-asb2305.c +0 -39
Index: work6/arch/mn10300/unit-asb2305/pci-asb2305.c
===================================================================
@@ -218,45 +218,6 @@
 	pcibios_allocate_resources(1);
 }
 
-int pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-
-	for (idx = 0; idx < 6; idx++) {
-		/* Only set up the requested stuff */
-		if (!(mask & (1 << idx)))
-			continue;
-
-		r = &dev->resource[idx];
-
-		if (!r->start && r->end) {
-			printk(KERN_ERR
-			       "PCI: Device %s not available because of"
-			       " resource collisions\n",
-			       pci_name(dev));
-			return -EINVAL;
-		}
-
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-
-	if (dev->resource[PCI_ROM_RESOURCE].start)
-		cmd |= PCI_COMMAND_MEMORY;
-
-	if (cmd != old_cmd)
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-
-	return 0;
-}
-
 /*
  *  If we set up a device for bus mastering, we need to check the latency
  *  timer as certain crappy BIOSes forget to set it properly.
arch/parisc/kernel/pci.c +0 -41

47 lines not on this page · raw message

arch/powerpc/kernel/pci-common.c +0 -36
Index: work6/arch/powerpc/kernel/pci-common.c
===================================================================
@@ -1153,42 +1153,6 @@
 EXPORT_SYMBOL_GPL(pcibios_claim_one_bus);
 #endif /* CONFIG_HOTPLUG */
 
-int pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for (idx = 0; idx < PCI_NUM_RESOURCES; idx++) {
-		/* Only set up the requested stuff */
-		if (!(mask & (1 << idx)))
-			continue;
-		r = &dev->resource[idx];
-		if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
-			continue;
-		if ((idx == PCI_ROM_RESOURCE) &&
-				(!(r->flags & IORESOURCE_ROM_ENABLE)))
-			continue;
-		if (r->parent == NULL) {
-			printk(KERN_ERR "PCI: Device %s not available because"
-			       " of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n",
-		       pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
 	if (ppc_md.pcibios_enable_device_hook)
arch/ppc/kernel/pci.c +0 -33
Index: work6/arch/ppc/kernel/pci.c
===================================================================
@@ -578,39 +578,6 @@
 }
 
 
-int
-pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for (idx=0; idx<6; idx++) {
-		/* Only set up the requested stuff */
-		if (!(mask & (1<<idx)))
-			continue;
-	
-		r = &dev->resource[idx];
-		if (r->flags & IORESOURCE_UNSET) {
-			printk(KERN_ERR "PCI: Device %s not available because of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (dev->resource[PCI_ROM_RESOURCE].start)
-		cmd |= PCI_COMMAND_MEMORY;
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n", pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 static int next_controller_index;
 
 struct pci_controller * __init
arch/sh/drivers/pci/pci.c +0 -32
Index: work6/arch/sh/drivers/pci/pci.c
===================================================================
@@ -131,38 +131,6 @@
 	}
 }
 
-int pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for(idx=0; idx<6; idx++) {
-		if (!(mask & (1 << idx)))
-			continue;
-		r = &dev->resource[idx];
-		if (!r->start && r->end) {
-			printk(KERN_ERR "PCI: Device %s not available because "
-			       "of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (dev->resource[PCI_ROM_RESOURCE].start)
-		cmd |= PCI_COMMAND_MEMORY;
-	if (cmd != old_cmd) {
-		printk(KERN_INFO "PCI: Enabling device %s (%04x -> %04x)\n",
-		       pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
 	return pcibios_enable_resources(dev, mask);
arch/sparc64/kernel/pci.c +0 -30
Index: work6/arch/sparc64/kernel/pci.c
===================================================================
@@ -946,36 +946,6 @@
 {
 }
 
-int pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, oldcmd;
-	int i;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	oldcmd = cmd;
-
-	for (i = 0; i < PCI_NUM_RESOURCES; i++) {
-		struct resource *res = &dev->resource[i];
-
-		/* Only set up the requested stuff */
-		if (!(mask & (1<<i)))
-			continue;
-
-		if (res->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (res->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-
-	if (cmd != oldcmd) {
-		printk(KERN_DEBUG "PCI: Enabling device: (%s), cmd %x\n",
-		       pci_name(dev), cmd);
-                /* Enable the appropriate bits in the PCI command register.  */
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 int pcibios_enable_device(struct pci_dev *dev, int mask)
 {
 	return pcibios_enable_resources(dev, mask);
arch/v850/kernel/rte_mb_a_pci.c +0 -28
Index: work6/arch/v850/kernel/rte_mb_a_pci.c
===================================================================
@@ -217,34 +217,6 @@
 }
 
 
-int __nomods_init pcibios_enable_resources (struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for (idx = 0; idx < 6; idx++) {
-		r = &dev->resource[idx];
-		if (!r->start && r->end) {
-			printk(KERN_ERR "PCI: Device %s not available because "
-			       "of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n",
-		       pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 int __nomods_init pcibios_enable_device (struct pci_dev *dev, int mask)
 {
 	return pcibios_enable_resources(dev, mask);
arch/x86/pci/i386.c +0 -38
Index: work6/arch/x86/pci/i386.c
===================================================================
@@ -238,44 +238,6 @@
  */
 fs_initcall(pcibios_assign_resources);
 
-int pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for (idx = 0; idx < PCI_NUM_RESOURCES; idx++) {
-		/* Only set up the requested stuff */
-		if (!(mask & (1 << idx)))
-			continue;
-
-		r = &dev->resource[idx];
-		if (!(r->flags & (IORESOURCE_IO | IORESOURCE_MEM)))
-			continue;
-		if ((idx == PCI_ROM_RESOURCE) &&
-				(!(r->flags & IORESOURCE_ROM_ENABLE)))
-			continue;
-		if (!r->start && r->end) {
-			printk(KERN_ERR "PCI: Device %s not available "
-				"because of resource %d collisions\n",
-				pci_name(dev), idx);
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n",
-			pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 /*
  *  If we set up a device for bus mastering, we need to check the latency
  *  timer as certain crappy BIOSes forget to set it properly.
arch/x86/pci/pci.h +0 -1
Index: work6/arch/x86/pci/pci.h
===================================================================
@@ -44,7 +44,6 @@
 extern unsigned int pcibios_max_latency;
 
 void pcibios_resource_survey(void);
-int pcibios_enable_resources(struct pci_dev *, int);
 
 /* pci-pc.c */
 
arch/xtensa/kernel/pci.c +0 -31
Index: work6/arch/xtensa/kernel/pci.c
===================================================================
@@ -91,37 +91,6 @@
 	}
 }
 
-int
-pcibios_enable_resources(struct pci_dev *dev, int mask)
-{
-	u16 cmd, old_cmd;
-	int idx;
-	struct resource *r;
-
-	pci_read_config_word(dev, PCI_COMMAND, &cmd);
-	old_cmd = cmd;
-	for(idx=0; idx<6; idx++) {
-		r = &dev->resource[idx];
-		if (!r->start && r->end) {
-			printk (KERN_ERR "PCI: Device %s not available because "
-				"of resource collisions\n", pci_name(dev));
-			return -EINVAL;
-		}
-		if (r->flags & IORESOURCE_IO)
-			cmd |= PCI_COMMAND_IO;
-		if (r->flags & IORESOURCE_MEM)
-			cmd |= PCI_COMMAND_MEMORY;
-	}
-	if (dev->resource[PCI_ROM_RESOURCE].start)
-		cmd |= PCI_COMMAND_MEMORY;
-	if (cmd != old_cmd) {
-		printk("PCI: Enabling device %s (%04x -> %04x)\n",
-			pci_name(dev), old_cmd, cmd);
-		pci_write_config_word(dev, PCI_COMMAND, cmd);
-	}
-	return 0;
-}
-
 struct pci_controller * __init pcibios_alloc_controller(void)
 {
 	struct pci_controller *pci_ctrl;
drivers/pci/Makefile +1 -1
Index: work6/drivers/pci/Makefile
===================================================================
@@ -2,7 +2,7 @@
 # Makefile for the PCI bus specific drivers.
 #
 
-obj-y		+= access.o bus.o probe.o remove.o pci.o quirks.o \
+obj-y		+= access.o bios.o bus.o probe.o remove.o pci.o quirks.o \
 			pci-driver.o search.o pci-sysfs.o rom.o setup-res.o
 obj-$(CONFIG_PROC_FS) += proc.o
 
drivers/pci/bios.c new file +64 -0

64 lines not on this page · raw message

include/linux/pci.h +1 -0
Index: work6/include/linux/pci.h
===================================================================
@@ -443,6 +443,7 @@
 extern int no_pci_devices(void);
 
 void pcibios_fixup_bus(struct pci_bus *);
+int pcibios_enable_resources(struct pci_dev *, int mask);
 int __must_check pcibios_enable_device(struct pci_dev *, int mask);
 char *pcibios_setup(char *str);
 
#7 lore raw
Quoted 1 line · Bjorn Helgaas

powerpc: has a different collision check at (5)

I've always found the collision check dodgy. I tend to want to keep the way powerpc does it here.

pci_enable_device() should only enable resources that have successfully been added to the resource tree (that have passed all the collision check etc...). There is a simple & clear indication of that: res->parent is non-NULL. I think that is a better check than the test x86 does on start and end.

That is, whatever the arch code decides to use to decide whether resources are assigned by firmware or by the first pass assignment code or not and collide or not, once that phase is finished (which is the case when calling pcibios_enable_device(), having the resource in the resource-tree or not is, I believe, the proper way to test whether it's a useable resource.

Ben.

#8 lore raw
Quoted 13 lines · Benjamin Herrenschmidt
Quoted 1 line · Bjorn Helgaas

powerpc: has a different collision check at (5)

I've always found the collision check dodgy. I tend to want to keep the way powerpc does it here.

pci_enable_device() should only enable resources that have successfully been added to the resource tree (that have passed all the collision check etc...). There is a simple & clear indication of that: res->parent is non-NULL. I think that is a better check than the test x86 does on start and end.

Quoted 6 lines

That is, whatever the arch code decides to use to decide whether resources are assigned by firmware or by the first pass assignment code or not and collide or not, once that phase is finished (which is the case when calling pcibios_enable_device(), having the resource in the resource-tree or not is, I believe, the proper way to test whether it's a useable resource.

So should x86 adopt that collision check? I don't hear anything about actual architecture differences that are behind this implementation difference.

Bjorn

#9 lore raw
Quoted 8 lines · Bjorn Helgaas
Quoted 6 lines

That is, whatever the arch code decides to use to decide whether resources are assigned by firmware or by the first pass assignment code or not and collide or not, once that phase is finished (which is the case when calling pcibios_enable_device(), having the resource in the resource-tree or not is, I believe, the proper way to test whether it's a useable resource.

So should x86 adopt that collision check?

Yes, and other arches as well, I believe.

Quoted 3 lines

I don't hear anything about
actual architecture differences that are behind this implementation difference.

On ppc64 "0" can be a valid value for resource start, as far as I know.

Ivan.

#10 lore raw
In reply to Bjorn Helgaas
Quoted 11 lines
Quoted 7 lines

That is, whatever the arch code decides to use to decide whether resources are assigned by firmware or by the first pass assignment code or not and collide or not, once that phase is finished (which is the case when calling pcibios_enable_device(), having the resource in the resource-tree or not is, I believe, the proper way to test whether it's a useable resource.

So should x86 adopt that collision check? I don't hear anything about actual architecture differences that are behind this implementation difference.

Well, on powerpc we do allow under some circumstances a 0 start value in BARs, which is why I wanted to use a different check.

Ben.

#11 lore raw
In reply to Bjorn Helgaas

drivers/pci/bios.c

Quoted 19 lines

Index: work6/drivers/pci/Makefile
===================================================================

drivers/pci/Makefile +1 -1
@@ -2,7 +2,7 @@
 # Makefile for the PCI bus specific drivers.
 #
 
-obj-y		+= access.o bus.o probe.o remove.o pci.o quirks.o \
+obj-y		+= access.o bios.o bus.o probe.o remove.o pci.o quirks.o \
 			pci-driver.o search.o pci-sysfs.o rom.o setup-res.o
 obj-$(CONFIG_PROC_FS) += proc.o
 

Index: work6/drivers/pci/bios.c
===================================================================

drivers/pci/bios.c new file +0 -0
                        ^^^^^^

Yuck :-)

Please, don't call this bios ... whatever is in this file really has nothing to do with a "BIOS" in any shape or form :-) I know we used to call those things pcibios_* but that's really historical...

If you want to make clear it's for "utilities" that can be overriden by the arch, maybe call it utils.c, or just stick the function in pci.c, or setup-res.c

Ben.

#12 lore raw
In reply to Bjorn Helgaas
Quoted 3 lines · Bjorn Helgaas

parisc: checks DEVICE_COUNT_RESOURCE (12) instead of PCI_NUM_RESOURCES
(11) resources at (1),

Good catch.

Quoted 1 line

has no IORESOURCE_{IO,MEM} check at (3),

What else can it be?

Quoted 4 lines

has no PCI_ROM_RESOURCE check at (4), has no collision check at (5) always turns on PCI_COMMAND_SERR | PCI_COMMAND_PARITY at (6), writes cmd even if unchanged at (7)

I'll have to check into 4 & 5, there might be a good reason for it. For instance on a four port HP ethernet card (pci-pci bridge + 4 tulips) all 4 of the rom resources are mapped to the same address, which afaict, is allowed but breaks things in mysterious and subtle ways.

That said, the parisc pci code is a rats nest...

cheers, Kyle

#13 lore raw
In reply to Bjorn Helgaas
Quoted 2 lines · Bjorn Helgaas

- PA-RISC always turns on SERR and PARITY, which no other arch does

I suspect this is because we set the host bus adapters to hard fail (HPMC) on detecting an error, since we don't want to
1) return possibly bogus (-1) data
2) write code to use the (undocumented) error detection

More to the point, I suspect it's extra paranoia because firmware has set it up this way. I put in a quick hack to test whether those bits were set, and they came enabled that way by firmware on all the boxes I tested. (Disclaimer, I didn't have any easily accessible boxes with add-on cards installed, so firmware might just set it up for core devices, and we're making sure its set everywhere.)

cheers, Kyle

#14 lore raw
In reply to Bjorn Helgaas
Quoted 10 lines · Bjorn Helgaas

There are many implementations of pcibios_enable_resources() that differ in minor ways that look more like bugs than architectural differences. This patch series consolidates most of them to use the x86 version.

This series is for discussion only at this point. I'm interested in feedback about whether any of the differences are "real" and need to be preserved.

ARM and PA-RISC, in particular, have interesting differences:
- ARM always enables bridge devices, which no other arch does

ARM does this because there is nothing else which would do that - which means devices behind bridges would be completely inaccessible.

Quoted 1 line

- PA-RISC always turns on SERR and PARITY, which no other arch does

ARM also does this, unless pdev_bad_for_parity(dev) is true. See ARMs pcibios_fixup_bus().

Quoted 2 lines

Should other arches do the same thing, or are these somehow related to ARM and PA-RISC architecture?

I suspect they're architecture specific; I wouldn't like to do either on x86, but they're either required or preferred on ARM.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:
#15 lore raw
Quoted 9 lines · Russell King
Quoted 8 lines · Bjorn Helgaas

There are many implementations of pcibios_enable_resources() that differ in minor ways that look more like bugs than architectural differences. This patch series consolidates most of them to use the x86 version.

This series is for discussion only at this point. I'm interested in feedback about whether any of the differences are "real" and need to be preserved.

Quoted 5 lines
Quoted 2 lines

ARM and PA-RISC, in particular, have interesting differences:
- ARM always enables bridge devices, which no other arch does

ARM does this because there is nothing else which would do that - which means devices behind bridges would be completely inaccessible.

That's normally done by pci_enable_bridges() called by pci_assign_unassigned_resources(). (The later has a weird naming, it does more than just assign unassigned resources in fact).

Quoted 4 lines
Quoted 1 line

- PA-RISC always turns on SERR and PARITY, which no other arch does

ARM also does this, unless pdev_bad_for_parity(dev) is true. See ARMs pcibios_fixup_bus().

While that sounds like a good idea to generalize, I think it should remain arch stuff tho, not move to generic code.

On some platforms, weirdo firmwares handle error handling and will be unhappy if the kernel mucks around (such as pSeries).

Quoted 5 lines
Quoted 2 lines

Should other arches do the same thing, or are these somehow related to ARM and PA-RISC architecture?

I suspect they're architecture specific; I wouldn't like to do either on x86, but they're either required or preferred on ARM.

Ben.

#16 lore raw
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 7 lines · Russell King
Quoted 3 lines · Bjorn Helgaas

ARM and PA-RISC, in particular, have interesting differences:
- ARM always enables bridge devices, which no other arch does

ARM does this because there is nothing else which would do that - which means devices behind bridges would be completely inaccessible.

That's normally done by pci_enable_bridges() called by pci_assign_unassigned_resources().

alpha, mips, mn10300, powerpc, and x86 use pci_enable_bridges() via pci_assign_unassigned_resources(). parisc uses pci_enable_bridges() directly from lba_driver_probe(). I guess the other arches (except arm) rely on firmware to enable bridge.

I think pci_assign_unassigned_resources() is a bit of an anachronism -- it's a boot-time thing that does it for all root buses at once. A more hot-plug oriented scheme would do it like parisc, where every time we discover a root bridge, we do any necessary resource assignment and bridge enablement underneath it.

For ARM, maybe that could happen in pcibios_init_hw() or something similar.

Quoted 10 lines
Quoted 4 lines
Quoted 1 line

- PA-RISC always turns on SERR and PARITY, which no other arch does

ARM also does this, unless pdev_bad_for_parity(dev) is true. See ARMs pcibios_fixup_bus().

While that sounds like a good idea to generalize, I think it should remain arch stuff tho, not move to generic code.

On some platforms, weirdo firmwares handle error handling and will be unhappy if the kernel mucks around (such as pSeries).

I agree the SERR and PARITY stuff probably needs to remain arch code. But it would be nice to at least have this and the bridge enable done in similar places across arches.

Bjorn

#17 lore raw
In reply to Bjorn Helgaas
Quoted 8 lines · Bjorn Helgaas

There are many implementations of pcibios_enable_resources() that differ in minor ways that look more like bugs than architectural differences. This patch series consolidates most of them to use the x86 version.

This series is for discussion only at this point. I'm interested in feedback about whether any of the differences are "real" and need to be preserved.

Quoted 6 lines

ARM and PA-RISC, in particular, have interesting differences:
- ARM always enables bridge devices, which no other arch does
- PA-RISC always turns on SERR and PARITY, which no other arch does

Should other arches do the same thing, or are these somehow related to ARM and PA-RISC architecture?

My impression was most x86 BIOS's did NOT turn on SERR/PERR when I added that code to parisc-linux port (2000 or 2001 so) . HPUX was turning on SERR/PERR and so I was comfortable the HW was stable and it not crash under normal use unless something was really broken.

There is certainly nothing architectural specific about SERR/PERR. I felt (at the time) this is more of a case of "if it's not reported to the user, we won't get blamed for it not working well."

hth,
grant