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

[Minios-devel] [PATCH v3 30/43] arm64: 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         | 38 ++++++++++++++++++++++++++++++++------
 include/arm/arch_mm.h |  2 ++
 3 files changed, 38 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 e83ac70..b1c192a 100644
--- a/arch/arm/mm.c
+++ b/arch/arm/mm.c
@@ -18,12 +18,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();
-}
-
 extern lpae_t boot_l0_pgtable[512];
 
 static inline void set_pgt_entry(lpae_t *ptr, lpae_t val)
@@ -234,6 +228,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;
@@ -241,6 +236,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));
@@ -293,6 +289,36 @@ 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;
+}
+
 void arch_init_mm(unsigned long *start_pfn_p, unsigned long *max_pfn_p)
 {
     int memory;
diff --git a/include/arm/arch_mm.h b/include/arm/arch_mm.h
index 4f3fd8f..ad122e7 100644
--- a/include/arm/arch_mm.h
+++ b/include/arm/arch_mm.h
@@ -7,6 +7,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)
 
 typedef uint64_t lpae_t;
 
@@ -40,4 +41,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®.