
From: "Eric W. Biederman" <ebiederm@xmission.com>

This is the x86 implementation of the crashkernel option.  It reserves a
window of memory very early in the bootup process, so we never use it for
anything but the kernel to switch to when the running kernel panics.

In addition to reserving this memory a resource structure is registered so
looking at /proc/iomem it is clear what happened to that memory.

ISSUES:
Is it possible to implement this in a architecture generic way?
What should be done with architectures that always use an iommu and
thus don't report their RAM memory resources in /proc/iomem?

Signed-off-by: Eric Biederman <ebiederm@xmission.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 25-akpm/arch/i386/kernel/efi.c   |    4 ++++
 25-akpm/arch/i386/kernel/setup.c |   32 ++++++++++++++++++++++++++++++++
 25-akpm/arch/i386/mm/discontig.c |    6 ++++++
 3 files changed, 42 insertions(+)

diff -puN arch/i386/kernel/efi.c~x86-crashkernel arch/i386/kernel/efi.c
--- 25/arch/i386/kernel/efi.c~x86-crashkernel	2005-02-28 16:46:35.000000000 -0800
+++ 25-akpm/arch/i386/kernel/efi.c	2005-02-28 16:46:35.000000000 -0800
@@ -30,6 +30,7 @@
 #include <linux/ioport.h>
 #include <linux/module.h>
 #include <linux/efi.h>
+#include <linux/kexec.h>
 
 #include <asm/setup.h>
 #include <asm/io.h>
@@ -596,6 +597,9 @@ efi_initialize_iomem_resources(struct re
 		if (md->type == EFI_CONVENTIONAL_MEMORY) {
 			request_resource(res, code_resource);
 			request_resource(res, data_resource);
+#ifdef CONFIG_KEXEC
+			request_resource(res, &crashk_res);
+#endif
 		}
 	}
 }
diff -puN arch/i386/kernel/setup.c~x86-crashkernel arch/i386/kernel/setup.c
--- 25/arch/i386/kernel/setup.c~x86-crashkernel	2005-02-28 16:46:35.000000000 -0800
+++ 25-akpm/arch/i386/kernel/setup.c	2005-02-28 16:46:59.000000000 -0800
@@ -41,7 +41,10 @@
 #include <linux/init.h>
 #include <linux/edd.h>
 #include <linux/nodemask.h>
+#include <linux/kexec.h>
+
 #include <video/edid.h>
+
 #include <asm/apic.h>
 #include <asm/e820.h>
 #include <asm/mpspec.h>
@@ -828,6 +831,27 @@ static void __init parse_cmdline_early (
 			lapic_disable();
 #endif /* CONFIG_X86_LOCAL_APIC */
 
+#ifdef CONFIG_KEXEC
+		/* crashkernel=size@addr specifies the location to reserve for
+		 * a crash kernel.  By reserving this memory we guarantee
+		 * that linux never set's it up as a DMA target.
+		 * Useful for holding code to do something appropriate
+		 * after a kernel panic.
+		 */
+		else if (!memcmp(from, "crashkernel=", 12)) {
+			unsigned long size, base;
+			size = memparse(from+12, &from);
+			if (*from == '@') {
+				base = memparse(from+1, &from);
+				/* FIXME: Do I want a sanity check
+				 * to validate the memory range?
+				 */
+				crashk_res.start = base;
+				crashk_res.end   = base + size - 1;
+			}
+		}
+#endif
+
 		/*
 		 * highmem=size forces highmem to be exactly 'size' bytes.
 		 * This works even on boxes that have no highmem otherwise.
@@ -960,6 +984,11 @@ unsigned long __init find_max_low_pfn(vo
 			printk(KERN_ERR "ignoring highmem size on non-highmem kernel!\n");
 #endif
 	}
+#ifdef CONFIG_KEXEC
+	if (crashk_res.start != crashk_res.end)
+		reserve_bootmem(crashk_res.start,
+			crashk_res.end - crashk_res.start + 1);
+#endif
 	return max_low_pfn;
 }
 
@@ -1216,6 +1245,9 @@ legacy_init_iomem_resources(struct resou
 			 */
 			request_resource(res, code_resource);
 			request_resource(res, data_resource);
+#ifdef CONFIG_KEXEC
+			request_resource(res, &crashk_res);
+#endif
 		}
 	}
 }
diff -puN arch/i386/mm/discontig.c~x86-crashkernel arch/i386/mm/discontig.c
--- 25/arch/i386/mm/discontig.c~x86-crashkernel	2005-02-28 16:46:35.000000000 -0800
+++ 25-akpm/arch/i386/mm/discontig.c	2005-02-28 16:46:35.000000000 -0800
@@ -29,6 +29,7 @@
 #include <linux/highmem.h>
 #include <linux/initrd.h>
 #include <linux/nodemask.h>
+#include <linux/kexec.h>
 #include <asm/e820.h>
 #include <asm/setup.h>
 #include <asm/mmzone.h>
@@ -279,6 +280,11 @@ unsigned long __init setup_memory(void)
 
 	memset(NODE_DATA(0), 0, sizeof(struct pglist_data));
 	NODE_DATA(0)->bdata = &node0_bdata;
+#ifdef CONFIG_KEXEC
+	if (crashk_res.start != crashk_res.end)
+		reserve_bootmem(crashk_res.start,
+			crashk_res.end - crashk_res.start + 1);
+#endif
 	setup_bootmem_allocator();
 	return max_low_pfn;
 }
_
