[PATCH] x86: introduce reserve_initrd

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Yinghai Lu
Date: Sunday, June 22, 2008 - 2:46 am

Signed-off-by: Yinghai Lu <yhlu.kernel@gmail.com>

---
 arch/x86/kernel/setup_32.c |   16 ++++++++-----
 arch/x86/kernel/setup_64.c |   53 ++++++++++++++++++++++++---------------------
 arch/x86/mm/init_32.c      |    6 +----
 include/asm-x86/setup.h    |    2 +
 4 files changed, 43 insertions(+), 34 deletions(-)

Index: linux-2.6/arch/x86/kernel/setup_32.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup_32.c
+++ linux-2.6/arch/x86/kernel/setup_32.c
@@ -337,7 +337,7 @@ void __init reserve_initrd(void)
 		 * in i386_start_kernel
 		 */
 		initrd_start = ramdisk_image + PAGE_OFFSET;
-		initrd_end = initrd_start+ramdisk_size;
+		initrd_end = initrd_start + ramdisk_size;
 		return;
 	}
 
@@ -364,7 +364,7 @@ void __init reserve_initrd(void)
 
 #define MAX_MAP_CHUNK	(NR_FIX_BTMAPS << PAGE_SHIFT)
 
-static void __init relocate_initrd(void)
+static void __init post_reserve_initrd(void)
 {
 	u64 ramdisk_image = boot_params.hdr.ramdisk_image;
 	u64 ramdisk_size  = boot_params.hdr.ramdisk_size;
@@ -418,7 +418,13 @@ static void __init relocate_initrd(void)
 	/* need to free that, otherwise init highmem will reserve it again */
 	free_early(ramdisk_image, ramdisk_image+ramdisk_size);
 }
-
+#else
+void __init reserve_initrd(void)
+{
+}
+static void __init post_reserve_initrd(void)
+{
+}
 #endif /* CONFIG_BLK_DEV_INITRD */
 
 /*
@@ -638,9 +644,7 @@ void __init setup_arch(char **cmdline_p)
 	 * NOTE: at this point the bootmem allocator is fully available.
 	 */
 
-#ifdef CONFIG_BLK_DEV_INITRD
-	relocate_initrd();
-#endif
+	post_reserve_initrd();
 
 	remapped_pgdat_init();
 	sparse_init();
Index: linux-2.6/arch/x86/kernel/setup_64.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/setup_64.c
+++ linux-2.6/arch/x86/kernel/setup_64.c
@@ -154,6 +154,33 @@ static inline void copy_edd(void)
 }
 #endif
 
+void __init reserve_initrd(void)
+{
+#ifdef CONFIG_BLK_DEV_INITRD
+	if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
+		unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
+		unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
+		unsigned long ramdisk_end   = ramdisk_image + ramdisk_size;
+		unsigned long end_of_mem    = end_pfn << PAGE_SHIFT;
+
+		if (ramdisk_end <= end_of_mem) {
+			/*
+			 * don't need to reserve again, already reserved early
+			 * in x86_64_start_kernel, and early_res_to_bootmem
+			 * will convert that to reserved in bootmem
+			 */
+			initrd_start = ramdisk_image + PAGE_OFFSET;
+			initrd_end = initrd_start+ramdisk_size;
+		} else {
+			free_early(ramdisk_image, ramdisk_end);
+			printk(KERN_ERR "initrd extends beyond end of memory "
+			       "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
+			       ramdisk_end, end_of_mem);
+			initrd_start = 0;
+		}
+	}
+#endif
+}
 /*
  * setup_arch - architecture-specific boot-time initializations
  *
@@ -251,6 +278,8 @@ void __init setup_arch(char **cmdline_p)
 		end_pfn = e820_end_of_ram();
 	}
 
+	reserve_initrd();
+
 	num_physpages = end_pfn;
 
 	check_efer();
@@ -307,30 +336,6 @@ void __init setup_arch(char **cmdline_p)
 	*/
 	find_smp_config();
 #endif
-#ifdef CONFIG_BLK_DEV_INITRD
-	if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
-		unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
-		unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
-		unsigned long ramdisk_end   = ramdisk_image + ramdisk_size;
-		unsigned long end_of_mem    = end_pfn << PAGE_SHIFT;
-
-		if (ramdisk_end <= end_of_mem) {
-			/*
-			 * don't need to reserve again, already reserved early
-			 * in x86_64_start_kernel, and early_res_to_bootmem
-			 * convert that to reserved in bootmem
-			 */
-			initrd_start = ramdisk_image + PAGE_OFFSET;
-			initrd_end = initrd_start+ramdisk_size;
-		} else {
-			free_bootmem(ramdisk_image, ramdisk_size);
-			printk(KERN_ERR "initrd extends beyond end of memory "
-			       "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
-			       ramdisk_end, end_of_mem);
-			initrd_start = 0;
-		}
-	}
-#endif
 	reserve_crashkernel();
 
 	reserve_ibft_region();
Index: linux-2.6/arch/x86/mm/init_32.c
===================================================================
--- linux-2.6.orig/arch/x86/mm/init_32.c
+++ linux-2.6/arch/x86/mm/init_32.c
@@ -597,8 +597,6 @@ void __init zone_sizes_init(void)
 }
 #endif /* !CONFIG_NEED_MULTIPLE_NODES */
 
-extern void reserve_initrd(void);
-
 void __init setup_bootmem_allocator(void)
 {
 	int i;
@@ -613,9 +611,9 @@ void __init setup_bootmem_allocator(void
 	if (bootmap == -1L)
 		panic("Cannot find bootmem map of size %ld\n", bootmap_size);
 	reserve_early(bootmap, bootmap + bootmap_size, "BOOTMAP");
-#ifdef CONFIG_BLK_DEV_INITRD
+
 	reserve_initrd();
-#endif
+
 	bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, max_low_pfn);
 	printk(KERN_INFO "  mapped low ram: 0 - %08lx\n",
 		 max_pfn_mapped<<PAGE_SHIFT);
Index: linux-2.6/include/asm-x86/setup.h
===================================================================
--- linux-2.6.orig/include/asm-x86/setup.h
+++ linux-2.6/include/asm-x86/setup.h
@@ -39,6 +39,8 @@ void reserve_crashkernel(void);
 #include <asm/bootparam.h>
 
 void reserve_standard_io_resources(void);
+void reserve_initrd(void);
+
 
 #ifndef _SETUP
 
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] x86: make 64bit identify_cpu use cpu_dev, Yinghai Lu, (Wed Jun 18, 2:15 am)
Re: [PATCH] x86: make 64bit identify_cpu use cpu_dev, Ingo Molnar, (Wed Jun 18, 7:17 am)
Re: [PATCH] x86: make 64bit identify_cpu use cpu_dev, Ingo Molnar, (Thu Jun 19, 2:03 am)
Re: [PATCH] x86: make 64bit identify_cpu use cpu_dev, Yinghai Lu, (Thu Jun 19, 1:00 pm)
[PATCH] x86: make 64bit identify_cpu use cpu_dev v2, Yinghai Lu, (Thu Jun 19, 3:30 pm)
Re: [PATCH] x86: make 64bit identify_cpu use cpu_dev v2, Ingo Molnar, (Thu Jun 19, 11:29 pm)
[PATCH] x86: merge setup64.c into common_64.c, Yinghai Lu, (Sat Jun 21, 4:25 pm)
[PATCH] x86: move elfcorehdr parsing to setup.c, Yinghai Lu, (Sat Jun 21, 9:02 pm)
[PATCH] x86: introduce initmem_init for 64 bit, Yinghai Lu, (Sun Jun 22, 2:44 am)
[PATCH] x86: introduce initmem_init for 32 bit, Yinghai Lu, (Sun Jun 22, 2:45 am)
[PATCH] x86: introduce reserve_initrd, Yinghai Lu, (Sun Jun 22, 2:46 am)
[PATCH] x86: move boot_params declaring to setup.c, Yinghai Lu, (Sun Jun 22, 5:37 pm)
[PATCH] x86: introduce reserve_initrd, Yinghai Lu, (Sun Jun 22, 5:40 pm)
[PATCH] x86: cleanup using max_low_pfn for 32 bit, Yinghai Lu, (Mon Jun 23, 3:05 am)
[PATCH] x86: cleanup min_low_pfn, Yinghai Lu, (Mon Jun 23, 3:06 am)
Re: [PATCH] x86: cleanup using max_low_pfn for 32 bit, Ingo Molnar, (Mon Jun 23, 12:56 pm)
Re: [PATCH] x86: cleanup using max_low_pfn for 32 bit, H. Peter Anvin, (Mon Jun 23, 12:57 pm)
Re: [PATCH] x86: cleanup using max_low_pfn for 32 bit, Ingo Molnar, (Mon Jun 23, 1:22 pm)