Skip to contentSkip to conversation

linux-2.6.18-xen: MMCONFIG

PATCH New Simon Horman 1 participant 3 messages Aug 13, 2009

lore
Share & tools
lore
#0 lore raw

cover linux-2.6.18-xen: MMCONFIG

Hi,

the purpose of this small series is two-fold:

1) Allow MMCONFIG to work on 2.6.18 on x86_64 on machines, such as the HP dc7800, where the MMCONFIG aperture is less than the maximum (256Mb).

2) Allow MMCONFIG to work on 2.6.18 i386 on the HP dc7800, and thus allow the kernel to boot with the default config (any config?).

These goals are achieved by back-porting two patches to linux-2.6.18-xen

#1 lore raw

PATCH 1/2 linux-2.6.18-xen: mmconfig: Fix x86_64 ioremap base_address

Current mmconfig has some problems of remapped range.

a) In the case of broken MCFG tables on Asus etc., we need to remap 256M range, but currently only remap 1M.

b) The base address always corresponds to bus number 0, but currently we are assuming it corresponds to start bus number.

This patch fixes the above problems.

(akpm: Arjan suggests that if the MCFG table is broken we just shouldn't use it, rather than try to work around things).

Back-ported to 2.6.18 by Simon Horman

---

Without this change mmconfig fails on x86_64 as it always tries to map the full aperture, which is not allowed by the hypervisor if that isn't the actual aperture of mmconfig.

Also needs "PCI x86: always use conf1 to access config space below 256 bytes", posted separately.

arch/x86_64/pci/mmconfig.c +32 -10
Index: linux-2.6.18-xen.hg/arch/x86_64/pci/mmconfig.c
===================================================================
@@ -30,6 +30,36 @@ struct mmcfg_virt {
 };
 static struct mmcfg_virt *pci_mmcfg_virt;
 
+static inline int mcfg_broken(void)
+{
+       struct acpi_table_mcfg_config *cfg = &pci_mmcfg_config[0];
+
+       /* Handle more broken MCFG tables on Asus etc.
+          They only contain a single entry for bus 0-0. Assume
+          this applies to all busses. */
+       if (pci_mmcfg_config_num == 1 &&
+           cfg->pci_segment_group_number == 0 &&
+           (cfg->start_bus_number | cfg->end_bus_number) == 0)
+               return 1;
+       return 0;
+}
+
+static void __iomem * __init mcfg_ioremap(struct acpi_table_mcfg_config *cfg)
+{
+	void __iomem *addr;
+	u32 size;
+
+	size = (cfg->end_bus_number + 1) << 20;
+	printk(KERN_INFO "%s: end_bus_number=%d\n", __func__,
+	       cfg->end_bus_number);
+	addr = ioremap_nocache(cfg->base_address, size);
+	if (addr) {
+		printk(KERN_INFO "PCI: Using MMCONFIG at %Lx - %Lx\n",
+		       cfg->base_address, cfg->base_address + size - 1);
+	}
+	return addr;
+}
+
 static char __iomem *get_virt(unsigned int seg, unsigned bus)
 {
 	int cfg_num = -1;
@@ -47,13 +77,7 @@ static char __iomem *get_virt(unsigned i
 			return pci_mmcfg_virt[cfg_num].virt;
 	}
 
-	/* Handle more broken MCFG tables on Asus etc.
-	   They only contain a single entry for bus 0-0. Assume
- 	   this applies to all busses. */
-	cfg = &pci_mmcfg_config[0];
-	if (pci_mmcfg_config_num == 1 &&
-		cfg->pci_segment_group_number == 0 &&
-		(cfg->start_bus_number | cfg->end_bus_number) == 0)
+	if (mcfg_broken())
 		return pci_mmcfg_virt[0].virt;
 
 	/* Fall back to type 0 */
@@ -194,14 +218,12 @@ void __init pci_mmcfg_init(void)
 	}
 	for (i = 0; i < pci_mmcfg_config_num; ++i) {
 		pci_mmcfg_virt[i].cfg = &pci_mmcfg_config[i];
-		pci_mmcfg_virt[i].virt = ioremap_nocache(pci_mmcfg_config[i].base_address,
-							 MMCONFIG_APER_MAX);
+		pci_mmcfg_virt[i].virt = mcfg_ioremap(&pci_mmcfg_config[i]);
 		if (!pci_mmcfg_virt[i].virt) {
 			printk("PCI: Cannot map mmconfig aperture for segment %d\n",
 			       pci_mmcfg_config[i].pci_segment_group_number);
 			return;
 		}
-		printk(KERN_INFO "PCI: Using MMCONFIG at %x\n", pci_mmcfg_config[i].base_address);
 	}
 
 	unreachable_devices();
#2 lore raw

PATCH 2/2 linux-2.6.18-xen: PCI x86: always use conf1 to access config space below 256 bytes

In reply to Simon Horman

Back-ported to 2.6.18.8 by Simon Horman

---

Test machine: HP dc7800

x86_64: This patch is needed to allow mcfg_ioremap() to work.
That is, it is needed for the system to boot with the previous patch applied.

i386: This patch is needed for the system to boot.

arch/x86_64/pci/mmconfig.c +9 -43
Index: linux-2.6.18-xen.hg/arch/x86_64/pci/mmconfig.c
===================================================================
@@ -17,12 +17,6 @@
 #define MMCONFIG_APER_MIN	(2 * 1024*1024)
 #define MMCONFIG_APER_MAX	(256 * 1024*1024)
 
-/* Verify the first 16 busses. We assume that systems with more busses
-   get MCFG right. */
-#define MAX_CHECK_BUS 16
-
-static DECLARE_BITMAP(fallback_slots, 32*MAX_CHECK_BUS);
-
 /* Static virtual mapping of the MMCONFIG aperture */
 struct mmcfg_virt {
 	struct acpi_table_mcfg_config *cfg;
@@ -87,9 +81,6 @@ static char __iomem *get_virt(unsigned i
 static char __iomem *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn)
 {
 	char __iomem *addr;
-	if (seg == 0 && bus < MAX_CHECK_BUS &&
-		test_bit(32*bus + PCI_SLOT(devfn), fallback_slots))
-		return NULL;
 	addr = get_virt(seg, bus);
 	if (!addr)
 		return NULL;
@@ -103,13 +94,16 @@ static int pci_mmcfg_read(unsigned int s
 
 	/* Why do we have this when nobody checks it. How about a BUG()!? -AK */
 	if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095))) {
-		*value = -1;
+err:		*value = -1;
 		return -EINVAL;
 	}
 
+	if (reg < 256)
+		return pci_conf1_read(seg,bus,devfn,reg,len,value);
+
 	addr = pci_dev_base(seg, bus, devfn);
 	if (!addr)
-		return pci_conf1_read(seg,bus,devfn,reg,len,value);
+		goto err;
 
 	switch (len) {
 	case 1:
@@ -135,9 +129,12 @@ static int pci_mmcfg_write(unsigned int 
 	if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095)))
 		return -EINVAL;
 
+	if (reg < 256)
+		return pci_conf1_write(seg,bus,devfn,reg,len,value);
+
 	addr = pci_dev_base(seg, bus, devfn);
 	if (!addr)
-		return pci_conf1_write(seg,bus,devfn,reg,len,value);
+		return -EINVAL;
 
 	switch (len) {
 	case 1:
@@ -159,35 +156,6 @@ static struct pci_raw_ops pci_mmcfg = {
 	.write =	pci_mmcfg_write,
 };
 
-/* K8 systems have some devices (typically in the builtin northbridge)
-   that are only accessible using type1
-   Normally this can be expressed in the MCFG by not listing them
-   and assigning suitable _SEGs, but this isn't implemented in some BIOS.
-   Instead try to discover all devices on bus 0 that are unreachable using MM
-   and fallback for them. */
-static __init void unreachable_devices(void)
-{
-	int i, k;
-	/* Use the max bus number from ACPI here? */
-	for (k = 0; k < MAX_CHECK_BUS; k++) {
-		for (i = 0; i < 32; i++) {
-			u32 val1;
-			char __iomem *addr;
-
-			pci_conf1_read(0, k, PCI_DEVFN(i,0), 0, 4, &val1);
-			if (val1 == 0xffffffff)
-				continue;
-			addr = pci_dev_base(0, k, PCI_DEVFN(i, 0));
-			if (addr == NULL|| readl(addr) != val1) {
-				set_bit(i + 32*k, fallback_slots);
-				printk(KERN_NOTICE
-				"PCI: No mmconfig possible on device %x:%x\n",
-					k, i);
-			}
-		}
-	}
-}
-
 void __init pci_mmcfg_init(void)
 {
 	int i;
@@ -226,8 +194,6 @@ void __init pci_mmcfg_init(void)
 		}
 	}
 
-	unreachable_devices();
-
 	raw_pci_ops = &pci_mmcfg;
 	pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
 }
arch/i386/pci/mmconfig.c +9 -50

105 lines not on this page · raw message