public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better
@ 2006-03-25 16:23 Arjan van de Ven
  2006-03-25 16:24 ` [patch 2 of 4] Introduce e820_all_mapped Arjan van de Ven
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Arjan van de Ven @ 2006-03-25 16:23 UTC (permalink / raw)
  To: ak, linux-kernel

Rename e820_mapped to e820_any_mapped since it tests if any part
of the range is mapped according to the type. Later steps will introduce
e820_all_mapped which will check if the entire range is mapped with the type.
Both have their merit.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>

---
 arch/x86_64/kernel/aperture.c |    2 +-
 arch/x86_64/kernel/e820.c     |    2 +-
 arch/x86_64/mm/init.c         |    2 +-
 include/asm-x86_64/e820.h     |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

Index: linux-2.6.16-mmconfig/arch/x86_64/kernel/aperture.c
===================================================================
--- linux-2.6.16-mmconfig.orig/arch/x86_64/kernel/aperture.c
+++ linux-2.6.16-mmconfig/arch/x86_64/kernel/aperture.c
@@ -80,7 +80,7 @@ static int __init aperture_valid(char *n
 		printk("Aperture from %s beyond 4GB. Ignoring.\n",name);
 		return 0; 
 	}
-	if (e820_mapped(aper_base, aper_base + aper_size, E820_RAM)) {  
+	if (e820_any_mapped(aper_base, aper_base + aper_size, E820_RAM)) {
 		printk("Aperture from %s pointing to e820 RAM. Ignoring.\n",name);
 		return 0; 
 	} 
Index: linux-2.6.16-mmconfig/arch/x86_64/kernel/e820.c
===================================================================
--- linux-2.6.16-mmconfig.orig/arch/x86_64/kernel/e820.c
+++ linux-2.6.16-mmconfig/arch/x86_64/kernel/e820.c
@@ -80,7 +80,7 @@ static inline int bad_addr(unsigned long
 	return 0;
 } 
 
-int __init e820_mapped(unsigned long start, unsigned long end, unsigned type) 
+int __init e820_any_mapped(unsigned long start, unsigned long end, unsigned type)
 { 
 	int i;
 	for (i = 0; i < e820.nr_map; i++) { 
Index: linux-2.6.16-mmconfig/arch/x86_64/mm/init.c
===================================================================
--- linux-2.6.16-mmconfig.orig/arch/x86_64/mm/init.c
+++ linux-2.6.16-mmconfig/arch/x86_64/mm/init.c
@@ -277,7 +277,7 @@ static void __meminit phys_pud_init(pud_
 		if (paddr >= end)
 			break;
 
-		if (!after_bootmem && !e820_mapped(paddr, paddr+PUD_SIZE, 0)) {
+		if (!after_bootmem && !e820_any_mapped(paddr, paddr+PUD_SIZE, 0)) {
 			set_pud(pud, __pud(0)); 
 			continue;
 		} 
Index: linux-2.6.16-mmconfig/include/asm-x86_64/e820.h
===================================================================
--- linux-2.6.16-mmconfig.orig/include/asm-x86_64/e820.h
+++ linux-2.6.16-mmconfig/include/asm-x86_64/e820.h
@@ -47,7 +47,7 @@ extern void contig_e820_setup(void); 
 extern unsigned long e820_end_of_ram(void);
 extern void e820_reserve_resources(void);
 extern void e820_print_map(char *who);
-extern int e820_mapped(unsigned long start, unsigned long end, unsigned type);
+extern int e820_any_mapped(unsigned long start, unsigned long end, unsigned type);
 
 extern void e820_bootmem_free(pg_data_t *pgdat, unsigned long start,unsigned long end);
 extern void e820_setup_gap(void);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [patch 2 of 4] Introduce e820_all_mapped
  2006-03-25 16:23 [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better Arjan van de Ven
@ 2006-03-25 16:24 ` Arjan van de Ven
  2006-03-25 16:24 ` [patch 3 of 4] MCFG sanity check Arjan van de Ven
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Arjan van de Ven @ 2006-03-25 16:24 UTC (permalink / raw)
  To: linux-kernel, ak

Introduce a e820_all_mapped() function which checks if the entire
range <start,end> is mapped with type. This is done by moving the local
start variable to the end of each known-good region; if at the end
of the function the start address is still before end, there must be
a part that's not of the correct type; otherwise it's a good region.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>

---
 arch/x86_64/kernel/e820.c |   32 ++++++++++++++++++++++++++++++++
 include/asm-x86_64/e820.h |    1 +
 2 files changed, 33 insertions(+)

Index: linux-2.6.16-mmconfig/arch/x86_64/kernel/e820.c
===================================================================
--- linux-2.6.16-mmconfig.orig/arch/x86_64/kernel/e820.c
+++ linux-2.6.16-mmconfig/arch/x86_64/kernel/e820.c
@@ -80,6 +80,9 @@ static inline int bad_addr(unsigned long
 	return 0;
 } 
 
+/*
+ * This function checks if any part of the range <start,end> is mapped with type.
+ */
 int __init e820_any_mapped(unsigned long start, unsigned long end, unsigned type)
 { 
 	int i;
@@ -94,6 +97,35 @@ int __init e820_any_mapped(unsigned long
 	return 0;
 }
 
+/*
+ * This function checks if the entire range <start,end> is mapped with type.
+ *
+ * Note: this function only works correct if the e820 table is sorted and
+ * not-overlapping, which is the case
+ */
+int __init e820_all_mapped(unsigned long start, unsigned long end, unsigned type)
+{
+	int i;
+	for (i = 0; i < e820.nr_map; i++) {
+		struct e820entry *ei = &e820.map[i];
+		if (type && ei->type != type)
+			continue;
+		/* is the region (part) in overlap with the current region ?*/
+		if (ei->addr >= end || ei->addr + ei->size <= start)
+			continue;
+
+		/* if the region is at the beginning of <start,end> we move
+		 * start to the end of the region since it's ok until there
+		 */
+		if (ei->addr <= start)
+			start = ei->addr + ei->size;
+		/* if start is now at or beyond end, we're done, full coverage */
+		if (start >= end)
+			return 1; /* we're done */
+	}
+	return 0;
+}
+
 /* 
  * Find a free area in a specific range. 
  */ 
Index: linux-2.6.16-mmconfig/include/asm-x86_64/e820.h
===================================================================
--- linux-2.6.16-mmconfig.orig/include/asm-x86_64/e820.h
+++ linux-2.6.16-mmconfig/include/asm-x86_64/e820.h
@@ -48,6 +48,7 @@ extern unsigned long e820_end_of_ram(voi
 extern void e820_reserve_resources(void);
 extern void e820_print_map(char *who);
 extern int e820_any_mapped(unsigned long start, unsigned long end, unsigned type);
+extern int e820_all_mapped(unsigned long start, unsigned long end, unsigned type);
 
 extern void e820_bootmem_free(pg_data_t *pgdat, unsigned long start,unsigned long end);
 extern void e820_setup_gap(void);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [patch 3 of 4] MCFG sanity check
  2006-03-25 16:23 [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better Arjan van de Ven
  2006-03-25 16:24 ` [patch 2 of 4] Introduce e820_all_mapped Arjan van de Ven
@ 2006-03-25 16:24 ` Arjan van de Ven
  2006-03-25 16:25 ` [patch 4 of 4] i386 version of the changes Arjan van de Ven
  2006-03-25 16:50 ` [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better Andi Kleen
  3 siblings, 0 replies; 5+ messages in thread
From: Arjan van de Ven @ 2006-03-25 16:24 UTC (permalink / raw)
  To: linux-kernel, ak

This patch introduces a user for the e820_all_mapped function:

There have been several machines that don't have a working MMCONFIG, often
because of a buggy MCFG table in the ACPI bios. This patch adds a simple
sanity check that detects a whole bunch of these cases, and when it detects
it, linux now boots rather than crash-and-burns. The accuracy of this
detection can in principle be improved if there was a "is this entire range
in e820 with THIS attribute", but no such function exist and the complexity
needed for this is not really worth it; this simple check already catches
most cases anyway.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>
---
 arch/x86_64/pci/mmconfig.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

Index: linux-2.6.16-mmconfig/arch/x86_64/pci/mmconfig.c
===================================================================
--- linux-2.6.16-mmconfig.orig/arch/x86_64/pci/mmconfig.c
+++ linux-2.6.16-mmconfig/arch/x86_64/pci/mmconfig.c
@@ -9,6 +9,8 @@
 #include <linux/init.h>
 #include <linux/acpi.h>
 #include <linux/bitmap.h>
+#include <asm/e820.h>
+
 #include "pci.h"
 
 #define MMCONFIG_APER_SIZE (256*1024*1024)
@@ -161,6 +163,14 @@ void __init pci_mmcfg_init(void)
 	    (pci_mmcfg_config[0].base_address == 0))
 		return;
 
+	if (!e820_all_mapped(pci_mmcfg_config[0].base_address,
+			pci_mmcfg_config[0].base_address + MMCONFIG_APER_SIZE,
+			E820_RESERVED)) {
+		printk(KERN_INFO "PCI: BIOS Bug: MCFG area is not E820-reserved\n");
+		printk(KERN_INFO "PCI: Not using MMCONFIG.\n");
+		return;
+	}
+
 	/* RED-PEN i386 doesn't do _nocache right now */
 	pci_mmcfg_virt = kmalloc(sizeof(*pci_mmcfg_virt) * pci_mmcfg_config_num, GFP_KERNEL);
 	if (pci_mmcfg_virt == NULL) {


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [patch 4 of 4] i386 version of the changes
  2006-03-25 16:23 [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better Arjan van de Ven
  2006-03-25 16:24 ` [patch 2 of 4] Introduce e820_all_mapped Arjan van de Ven
  2006-03-25 16:24 ` [patch 3 of 4] MCFG sanity check Arjan van de Ven
@ 2006-03-25 16:25 ` Arjan van de Ven
  2006-03-25 16:50 ` [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better Andi Kleen
  3 siblings, 0 replies; 5+ messages in thread
From: Arjan van de Ven @ 2006-03-25 16:25 UTC (permalink / raw)
  To: linux-kernel, ak

---
 arch/i386/kernel/setup.c |   30 ++++++++++++++++++++++++++++++
 arch/i386/pci/mmconfig.c |   12 ++++++++++++
 include/asm-i386/e820.h  |    3 +++
 3 files changed, 45 insertions(+)

Index: linux-2.6.16-mmconfig/arch/i386/kernel/setup.c
===================================================================
--- linux-2.6.16-mmconfig.orig/arch/i386/kernel/setup.c
+++ linux-2.6.16-mmconfig/arch/i386/kernel/setup.c
@@ -991,6 +991,36 @@ void __init find_max_pfn(void)
 }
 
 /*
+ * This function checks if the entire range <start,end> is mapped with type.
+ *
+ * Note: this function only works correct if the e820 table is sorted and
+ * not-overlapping, which is the case
+ */
+int __init e820_all_mapped(unsigned long start, unsigned long end, unsigned type)
+{
+	int i;
+	for (i = 0; i < e820.nr_map; i++) {
+		struct e820entry *ei = &e820.map[i];
+		if (type && ei->type != type)
+			continue;
+		/* is the region (part) in overlap with the current region ?*/
+		if (ei->addr >= end || ei->addr + ei->size <= start)
+			continue;
+
+		/* if the region is at the beginning of <start,end> we move
+		 * start to the end of the region since it's ok until there
+		 */
+		if (ei->addr <= start)
+			start = ei->addr + ei->size;
+		/* if start is now at or beyond end, we're done, full coverage */
+		if (start >= end)
+			return 1; /* we're done */
+	}
+	return 0;
+}
+
+
+/*
  * Determine low and high memory ranges:
  */
 unsigned long __init find_max_low_pfn(void)
Index: linux-2.6.16-mmconfig/arch/i386/pci/mmconfig.c
===================================================================
--- linux-2.6.16-mmconfig.orig/arch/i386/pci/mmconfig.c
+++ linux-2.6.16-mmconfig/arch/i386/pci/mmconfig.c
@@ -12,6 +12,7 @@
 #include <linux/pci.h>
 #include <linux/init.h>
 #include <linux/acpi.h>
+#include <asm/e820.h>
 #include "pci.h"
 
 #define mmcfg_virt_addr ((void __iomem *) fix_to_virt(FIX_PCIE_MCFG))
@@ -19,6 +20,9 @@
 /* The base address of the last MMCONFIG device accessed */
 static u32 mmcfg_last_accessed_device;
 
+#define MMCONFIG_APER_SIZE (256*1024*1024)
+
+
 static DECLARE_BITMAP(fallback_slots, 32);
 
 /*
@@ -183,6 +187,14 @@ void __init pci_mmcfg_init(void)
 	    (pci_mmcfg_config[0].base_address == 0))
 		return;
 
+	if (!e820_all_mapped(pci_mmcfg_config[0].base_address,
+			pci_mmcfg_config[0].base_address + MMCONFIG_APER_SIZE,
+			E820_RESERVED)) {
+		printk(KERN_INFO "PCI: BIOS Bug: MCFG area is not E820-reserved\n");
+		printk(KERN_INFO "PCI: Not using MMCONFIG.\n");
+		return;
+	}
+
 	printk(KERN_INFO "PCI: Using MMCONFIG\n");
 	raw_pci_ops = &pci_mmcfg;
 	pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
Index: linux-2.6.16-mmconfig/include/asm-i386/e820.h
===================================================================
--- linux-2.6.16-mmconfig.orig/include/asm-i386/e820.h
+++ linux-2.6.16-mmconfig/include/asm-i386/e820.h
@@ -35,6 +35,9 @@ struct e820map {
 };
 
 extern struct e820map e820;
+
+extern int e820_all_mapped(unsigned long start, unsigned long end, unsigned type);
+
 #endif/*!__ASSEMBLY__*/
 
 #endif/*__E820_HEADER*/



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better
  2006-03-25 16:23 [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better Arjan van de Ven
                   ` (2 preceding siblings ...)
  2006-03-25 16:25 ` [patch 4 of 4] i386 version of the changes Arjan van de Ven
@ 2006-03-25 16:50 ` Andi Kleen
  3 siblings, 0 replies; 5+ messages in thread
From: Andi Kleen @ 2006-03-25 16:50 UTC (permalink / raw)
  To: Arjan van de Ven; +Cc: linux-kernel

On Saturday 25 March 2006 17:23, Arjan van de Ven wrote:
> Rename e820_mapped to e820_any_mapped since it tests if any part
> of the range is mapped according to the type. Later steps will introduce
> e820_all_mapped which will check if the entire range is mapped with the type.
> Both have their merit.

I merged it after fixing it all up. There were rejects. Merged the i386
changes with the x86-64 changes. And removed the bogus hunk in the MCFG
patch. Also some cosmetic changes to make the lines < 80 chars 

Thanks,

-Andi

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-03-25 16:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-25 16:23 [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better Arjan van de Ven
2006-03-25 16:24 ` [patch 2 of 4] Introduce e820_all_mapped Arjan van de Ven
2006-03-25 16:24 ` [patch 3 of 4] MCFG sanity check Arjan van de Ven
2006-03-25 16:25 ` [patch 4 of 4] i386 version of the changes Arjan van de Ven
2006-03-25 16:50 ` [patch 1 of 4] Rename e820_map to e820_any_map to reflect its behavior better Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox