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

[Minios-devel] [PATCH v2 31/47] arm: add a new helper ioremap



This patch adds a new helper : ioremap.

This helper is used by the GIC mapping.
The return address is got from the demand area.

Signed-off-by: Huang Shijie <shijie.huang@xxxxxxx>
---
 arch/arm/gic.c        |  6 ++++--
 arch/arm/mm.c         | 39 +++++++++++++++++++++++++++++++++------
 include/arm/arch_mm.h |  2 ++
 3 files changed, 39 insertions(+), 8 deletions(-)

diff --git a/arch/arm/gic.c b/arch/arm/gic.c
index 1855293..1e37cdc 100644
--- a/arch/arm/gic.c
+++ b/arch/arm/gic.c
@@ -207,8 +207,10 @@ void gic_init(void) {
                 continue;
             }
 
-            gic.gicd_base = to_virt((long) fdt64_to_cpu(reg[0]));
-            gic.gicc_base = to_virt((long) fdt64_to_cpu(reg[2]));
+            gic.gicd_base = ioremap((unsigned long) fdt64_to_cpu(reg[0]),
+                                    (unsigned long) fdt64_to_cpu(reg[1]));
+            gic.gicc_base = ioremap((unsigned long) fdt64_to_cpu(reg[2]),
+                                    (unsigned long) fdt64_to_cpu(reg[3]));
             printk("Found GIC: gicd_base = %p, gicc_base = %p\n", 
gic.gicd_base, gic.gicc_base);
             break;
         }
diff --git a/arch/arm/mm.c b/arch/arm/mm.c
index 7d290e2..839356d 100644
--- a/arch/arm/mm.c
+++ b/arch/arm/mm.c
@@ -17,12 +17,6 @@ int arch_check_mem_block(int index, unsigned long *r_min, 
unsigned long *r_max)
     return 0;
 }
 
-unsigned long allocate_ondemand(unsigned long n, unsigned long alignment)
-{
-    // FIXME
-    BUG();
-}
-
 #if defined(__aarch64__)
 
 #include <arm64/pagetable.h>
@@ -237,6 +231,7 @@ void init_pagetable(unsigned long *start_pfn, unsigned long 
base,
 }
 
 static unsigned long virt_kernel_area_end;
+static unsigned long virt_demand_area_end;
 void arch_mm_preinit(void *dtb_pointer)
 {
     paddr_t **dtb_p = dtb_pointer;
@@ -244,6 +239,7 @@ void arch_mm_preinit(void *dtb_pointer)
     uintptr_t end = (uintptr_t) &_end;
 
     virt_kernel_area_end = VIRT_KERNEL_AREA;
+    virt_demand_area_end = VIRT_DEMAND_AREA;
 
     dtb = to_virt(((paddr_t)dtb));
     first_free_pfn = PFN_UP(to_phys(end));
@@ -295,6 +291,37 @@ unsigned long map_frame_virt(unsigned long mfn)
 
     return addr;
 }
+
+unsigned long allocate_ondemand(unsigned long n, unsigned long alignment)
+{
+    unsigned long addr;
+
+    addr = virt_demand_area_end;
+
+    /* Just for simple, make it page aligned. */
+    virt_demand_area_end += (n + PAGE_SIZE - 1) & PAGE_MASK;
+
+    ASSERT(virt_demand_area_end <= VIRT_HEAP_AREA);
+
+    return addr;
+}
+
+void *ioremap(paddr_t paddr, unsigned long size)
+{
+    unsigned long addr;
+    int ret;
+
+    addr = allocate_ondemand(size, 1);
+    if (!addr)
+        return NULL;
+
+    ret = build_pagetable(addr, PHYS_PFN(paddr), PFN_UP(size), MEM_DEV_ATTR,
+                  init_pagetable_ok? alloc_new_page: early_alloc_page, 3);
+    if (ret < 0)
+        return NULL;
+    return (void*)addr;
+}
+
 #else
 void arch_mm_preinit(void *dtb_pointer)
 {
diff --git a/include/arm/arch_mm.h b/include/arm/arch_mm.h
index bee1c69..86d0b3b 100644
--- a/include/arm/arch_mm.h
+++ b/include/arm/arch_mm.h
@@ -13,6 +13,7 @@ typedef uint64_t paddr_t;
 #define MAX_MEM_SIZE            (1UL << 39)
 #define VIRT_KERNEL_AREA        ((unsigned long)to_virt(MAX_MEM_SIZE))
 #define VIRT_DEMAND_AREA        (VIRT_KERNEL_AREA + MAX_MEM_SIZE)
+#define VIRT_HEAP_AREA          (VIRT_DEMAND_AREA + MAX_MEM_SIZE)
 #endif
 
 typedef uint64_t lpae_t;
@@ -47,4 +48,5 @@ void arch_mm_preinit(void *dtb_pointer);
 // FIXME
 #define map_frames(f, n) (NULL)
 
+void *ioremap(paddr_t addr, unsigned long size);
 #endif
-- 
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®.