[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [PATCH v2 17/47] mini-os: remove the e820 from common code



The e820 is x86 specific. This patch adds a new
function arch_check_mem_block() and rename e820_entris to mem_blocks.

Different archs implements the mem_blocks and arch_check_mem_block.
By this way, we remove the e820 code from the common code.

Signed-off-by: Huang Shijie <shijie.huang@xxxxxxx>
---
 arch/arm/mm.c | 17 +++++++++--------
 arch/x86/mm.c | 22 +++++++++++++++++-----
 include/mm.h  |  3 +++
 mm.c          |  9 ++-------
 4 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/arch/arm/mm.c b/arch/arm/mm.c
index 3d88d3b..4c0b186 100644
--- a/arch/arm/mm.c
+++ b/arch/arm/mm.c
@@ -3,18 +3,19 @@
 #include <arch_mm.h>
 #include <mini-os/errno.h>
 #include <mini-os/hypervisor.h>
+#include <mini-os/posix/limits.h>
 #include <libfdt.h>
 #include <lib.h>
 
 paddr_t physical_address_offset;
-struct e820entry e820_map[1] = {
-    {
-        .addr = 0,
-        .size = ULONG_MAX - 1,
-        .type = E820_RAM
-    }
-};
-unsigned e820_entries = 1;
+unsigned mem_blocks = 1;
+
+int arch_check_mem_block(int index, unsigned long *r_min, unsigned long *r_max)
+{
+    *r_min = 0;
+    *r_max = ULONG_MAX - 1;
+    return 0;
+}
 
 unsigned long allocate_ondemand(unsigned long n, unsigned long alignment)
 {
diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index 05ad029..61ec3f0 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -71,7 +71,7 @@ struct e820entry e820_map[1] = {
         .type = E820_RAM
     }
 };
-unsigned e820_entries = 1;
+unsigned mem_blocks = 1;
 
 void arch_mm_preinit(void *p)
 {
@@ -113,7 +113,7 @@ desc_ptr idt_ptr =
 };
 
 struct e820entry e820_map[E820_MAX];
-unsigned e820_entries;
+unsigned mem_blocks;
 
 static char *e820_types[E820_TYPES] = {
     [E820_RAM]      = "RAM",
@@ -150,9 +150,9 @@ void arch_mm_preinit(void *p)
         xprintk("could not get memory map\n");
         do_exit();
     }
-    e820_entries = memmap.nr_entries;
+    mem_blocks = memmap.nr_entries;
 
-    for ( i = 0; i < e820_entries; i++ )
+    for ( i = 0; i < mem_blocks; i++ )
     {
         if ( e820_map[i].type != E820_RAM )
             continue;
@@ -173,7 +173,7 @@ void arch_print_memmap(void)
     char buf[12];
 
     printk("Memory map:\n");
-    for ( i = 0; i < e820_entries; i++ )
+    for ( i = 0; i < mem_blocks; i++ )
     {
         if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] )
         {
@@ -191,6 +191,18 @@ void arch_print_memmap(void)
 }
 #endif
 
+int arch_check_mem_block(int index, unsigned long *r_min, unsigned long *r_max)
+{
+    if (e820_map[index].type != E820_RAM)
+        return 1;
+    if (e820_map[index].addr + e820_map[index].size >= ULONG_MAX)
+        BUG();
+
+    *r_min = e820_map[index].addr;
+    *r_max = *r_min + e820_map[index].size;
+    return 0;
+}
+
 /*
  * Make pt_pfn a new 'level' page table frame and hook it into the page
  * table at offset in previous level MFN (pref_l_mfn). pt_pfn is a guest
diff --git a/include/mm.h b/include/mm.h
index 4fc364f..08e434d 100644
--- a/include/mm.h
+++ b/include/mm.h
@@ -87,4 +87,7 @@ extern unsigned long heap, brk, heap_mapped, heap_end;
 int free_physical_pages(xen_pfn_t *mfns, int n);
 void fini_mm(void);
 
+extern unsigned int mem_blocks;
+extern int arch_check_mem_block(int index, unsigned long *r_min,
+                                unsigned long *r_max);
 #endif /* _MM_H_ */
diff --git a/mm.c b/mm.c
index 0a6cf5e..5efd846 100644
--- a/mm.c
+++ b/mm.c
@@ -43,7 +43,6 @@
 #include <mini-os/types.h>
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
-#include <mini-os/e820.h>
 
 /*********************
  * ALLOCATION BITMAP
@@ -175,15 +174,11 @@ static void init_page_allocator(unsigned long min, 
unsigned long max)
     /* All allocated by default. */
     memset(mm_alloc_bitmap, ~0, mm_alloc_bitmap_size);
 
-    for ( m = 0; m < e820_entries; m++ )
+    for ( m = 0; m < mem_blocks; m++ )
     {
-        if ( e820_map[m].type != E820_RAM )
+        if (arch_check_mem_block(m, &r_min, &r_max))
             continue;
-        if ( e820_map[m].addr + e820_map[m].size >= ULONG_MAX )
-            BUG();
 
-        r_min = e820_map[m].addr;
-        r_max = r_min + e820_map[m].size;
         if ( r_max <= min || r_min >= max )
             continue;
         if ( r_min < min )
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.