[PATCH -mm] x86 boot : Use E820 memory map on EFI 32 platform

2007-12-11 Thread Huang, Ying
Because the EFI memory map are converted to e820 memory map in
bootloader, the EFI memory map handling code is removed to clean up.

This patch is based on 2.6.24-rc4-mm1 and has been tested on Intel
32-bit platform with EFI 32 and UEFI 32 firmware.
 
Signed-off-by: Huang Ying <[EMAIL PROTECTED]>

---
 arch/x86/kernel/e820_32.c  |  117 +++
 arch/x86/kernel/efi_32.c   |  150 -
 arch/x86/kernel/setup_32.c |   16 +---
 arch/x86/mm/init_32.c  |   18 -
 include/asm-x86/e820_32.h  |2 
 5 files changed, 16 insertions(+), 287 deletions(-)

--- a/arch/x86/kernel/e820_32.c
+++ b/arch/x86/kernel/e820_32.c
@@ -7,7 +7,6 @@
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -181,7 +180,7 @@ static void __init probe_roms(void)
  * Request address space for all standard RAM and ROM resources
  * and also for regions reported as reserved by the e820.
  */
-void __init legacy_init_iomem_resources(struct resource *code_resource,
+void __init init_iomem_resources(struct resource *code_resource,
struct resource *data_resource,
struct resource *bss_resource)
 {
@@ -261,19 +260,17 @@ void __init add_memory_region(unsigned l
 {
int x;
 
-   if (!efi_enabled) {
-   x = e820.nr_map;
+   x = e820.nr_map;
 
-   if (x == E820MAX) {
-   printk(KERN_ERR "Ooops! Too many entries in the memory 
map!\n");
-   return;
-   }
-
-   e820.map[x].addr = start;
-   e820.map[x].size = size;
-   e820.map[x].type = type;
-   e820.nr_map++;
+   if (x == E820MAX) {
+   printk(KERN_ERR "Ooops! Too many entries in the memory map!\n");
+   return;
}
+
+   e820.map[x].addr = start;
+   e820.map[x].size = size;
+   e820.map[x].type = type;
+   e820.nr_map++;
 } /* add_memory_region */
 
 /*
@@ -489,29 +486,6 @@ int __init copy_e820_map(struct e820entr
 }
 
 /*
- * Callback for efi_memory_walk.
- */
-static int __init
-efi_find_max_pfn(unsigned long start, unsigned long end, void *arg)
-{
-   unsigned long *max_pfn = arg, pfn;
-
-   if (start < end) {
-   pfn = PFN_UP(end -1);
-   if (pfn > *max_pfn)
-   *max_pfn = pfn;
-   }
-   return 0;
-}
-
-static int __init
-efi_memory_present_wrapper(unsigned long start, unsigned long end, void *arg)
-{
-   memory_present(0, PFN_UP(start), PFN_DOWN(end));
-   return 0;
-}
-
-/*
  * Find the highest page frame number we have available
  */
 void __init find_max_pfn(void)
@@ -519,11 +493,6 @@ void __init find_max_pfn(void)
int i;
 
max_pfn = 0;
-   if (efi_enabled) {
-   efi_memmap_walk(efi_find_max_pfn, _pfn);
-   efi_memmap_walk(efi_memory_present_wrapper, NULL);
-   return;
-   }
 
for (i = 0; i < e820.nr_map; i++) {
unsigned long start, end;
@@ -541,34 +510,12 @@ void __init find_max_pfn(void)
 }
 
 /*
- * Free all available memory for boot time allocation.  Used
- * as a callback function by efi_memory_walk()
- */
-
-static int __init
-free_available_memory(unsigned long start, unsigned long end, void *arg)
-{
-   /* check max_low_pfn */
-   if (start >= (max_low_pfn << PAGE_SHIFT))
-   return 0;
-   if (end >= (max_low_pfn << PAGE_SHIFT))
-   end = max_low_pfn << PAGE_SHIFT;
-   if (start < end)
-   free_bootmem(start, end - start);
-
-   return 0;
-}
-/*
  * Register fully available low RAM pages with the bootmem allocator.
  */
 void __init register_bootmem_low_pages(unsigned long max_low_pfn)
 {
int i;
 
-   if (efi_enabled) {
-   efi_memmap_walk(free_available_memory, NULL);
-   return;
-   }
for (i = 0; i < e820.nr_map; i++) {
unsigned long curr_pfn, last_pfn, size;
/*
@@ -676,56 +623,12 @@ void __init print_memory_map(char *who)
}
 }
 
-static __init __always_inline void efi_limit_regions(unsigned long long size)
-{
-   unsigned long long current_addr = 0;
-   efi_memory_desc_t *md, *next_md;
-   void *p, *p1;
-   int i, j;
-
-   j = 0;
-   p1 = memmap.map;
-   for (p = p1, i = 0; p < memmap.map_end; p += memmap.desc_size, i++) {
-   md = p;
-   next_md = p1;
-   current_addr = md->phys_addr +
-   PFN_PHYS(md->num_pages);
-   if (is_available_memory(md)) {
-   if (md->phys_addr >= size) continue;
-   memcpy(next_md, md, memmap.desc_size);
-   if (current_addr >= size) {
-   next_md->num_pages -=
-   PFN_UP(current_addr-size);
-   }
-  

[PATCH -mm] x86 boot : Use E820 memory map on EFI 32 platform

2007-12-11 Thread Huang, Ying
Because the EFI memory map are converted to e820 memory map in
bootloader, the EFI memory map handling code is removed to clean up.

This patch is based on 2.6.24-rc4-mm1 and has been tested on Intel
32-bit platform with EFI 32 and UEFI 32 firmware.
 
Signed-off-by: Huang Ying [EMAIL PROTECTED]

---
 arch/x86/kernel/e820_32.c  |  117 +++
 arch/x86/kernel/efi_32.c   |  150 -
 arch/x86/kernel/setup_32.c |   16 +---
 arch/x86/mm/init_32.c  |   18 -
 include/asm-x86/e820_32.h  |2 
 5 files changed, 16 insertions(+), 287 deletions(-)

--- a/arch/x86/kernel/e820_32.c
+++ b/arch/x86/kernel/e820_32.c
@@ -7,7 +7,6 @@
 #include linux/kexec.h
 #include linux/module.h
 #include linux/mm.h
-#include linux/efi.h
 #include linux/pfn.h
 #include linux/uaccess.h
 #include linux/suspend.h
@@ -181,7 +180,7 @@ static void __init probe_roms(void)
  * Request address space for all standard RAM and ROM resources
  * and also for regions reported as reserved by the e820.
  */
-void __init legacy_init_iomem_resources(struct resource *code_resource,
+void __init init_iomem_resources(struct resource *code_resource,
struct resource *data_resource,
struct resource *bss_resource)
 {
@@ -261,19 +260,17 @@ void __init add_memory_region(unsigned l
 {
int x;
 
-   if (!efi_enabled) {
-   x = e820.nr_map;
+   x = e820.nr_map;
 
-   if (x == E820MAX) {
-   printk(KERN_ERR Ooops! Too many entries in the memory 
map!\n);
-   return;
-   }
-
-   e820.map[x].addr = start;
-   e820.map[x].size = size;
-   e820.map[x].type = type;
-   e820.nr_map++;
+   if (x == E820MAX) {
+   printk(KERN_ERR Ooops! Too many entries in the memory map!\n);
+   return;
}
+
+   e820.map[x].addr = start;
+   e820.map[x].size = size;
+   e820.map[x].type = type;
+   e820.nr_map++;
 } /* add_memory_region */
 
 /*
@@ -489,29 +486,6 @@ int __init copy_e820_map(struct e820entr
 }
 
 /*
- * Callback for efi_memory_walk.
- */
-static int __init
-efi_find_max_pfn(unsigned long start, unsigned long end, void *arg)
-{
-   unsigned long *max_pfn = arg, pfn;
-
-   if (start  end) {
-   pfn = PFN_UP(end -1);
-   if (pfn  *max_pfn)
-   *max_pfn = pfn;
-   }
-   return 0;
-}
-
-static int __init
-efi_memory_present_wrapper(unsigned long start, unsigned long end, void *arg)
-{
-   memory_present(0, PFN_UP(start), PFN_DOWN(end));
-   return 0;
-}
-
-/*
  * Find the highest page frame number we have available
  */
 void __init find_max_pfn(void)
@@ -519,11 +493,6 @@ void __init find_max_pfn(void)
int i;
 
max_pfn = 0;
-   if (efi_enabled) {
-   efi_memmap_walk(efi_find_max_pfn, max_pfn);
-   efi_memmap_walk(efi_memory_present_wrapper, NULL);
-   return;
-   }
 
for (i = 0; i  e820.nr_map; i++) {
unsigned long start, end;
@@ -541,34 +510,12 @@ void __init find_max_pfn(void)
 }
 
 /*
- * Free all available memory for boot time allocation.  Used
- * as a callback function by efi_memory_walk()
- */
-
-static int __init
-free_available_memory(unsigned long start, unsigned long end, void *arg)
-{
-   /* check max_low_pfn */
-   if (start = (max_low_pfn  PAGE_SHIFT))
-   return 0;
-   if (end = (max_low_pfn  PAGE_SHIFT))
-   end = max_low_pfn  PAGE_SHIFT;
-   if (start  end)
-   free_bootmem(start, end - start);
-
-   return 0;
-}
-/*
  * Register fully available low RAM pages with the bootmem allocator.
  */
 void __init register_bootmem_low_pages(unsigned long max_low_pfn)
 {
int i;
 
-   if (efi_enabled) {
-   efi_memmap_walk(free_available_memory, NULL);
-   return;
-   }
for (i = 0; i  e820.nr_map; i++) {
unsigned long curr_pfn, last_pfn, size;
/*
@@ -676,56 +623,12 @@ void __init print_memory_map(char *who)
}
 }
 
-static __init __always_inline void efi_limit_regions(unsigned long long size)
-{
-   unsigned long long current_addr = 0;
-   efi_memory_desc_t *md, *next_md;
-   void *p, *p1;
-   int i, j;
-
-   j = 0;
-   p1 = memmap.map;
-   for (p = p1, i = 0; p  memmap.map_end; p += memmap.desc_size, i++) {
-   md = p;
-   next_md = p1;
-   current_addr = md-phys_addr +
-   PFN_PHYS(md-num_pages);
-   if (is_available_memory(md)) {
-   if (md-phys_addr = size) continue;
-   memcpy(next_md, md, memmap.desc_size);
-   if (current_addr = size) {
-   next_md-num_pages -=
-