rewrite the gic implementation, some other fix ups
[lunaix-os.git] / lunaix-os / includes / lunaix / mm / page.h
index 0f9fb0c0aacff04179c5587aaca31ba7f9c3a9c2..772ff75365a397802e8f8365d2c79bafb490cb12 100644 (file)
@@ -145,6 +145,15 @@ pin_leaflet(struct leaflet* leaflet)
     change_page_type(get_ppage(leaflet), PP_FGLOCKED);
 }
 
+static inline int
+to_napot_order(int nr_pages)
+{
+    int order;
+    
+    order = ilog2(nr_pages);
+    return is_pot(nr_pages) ? order : order + 1;
+}
+
 /**
  * @brief Map a leaflet
  * 
@@ -303,4 +312,22 @@ vunmap_range(pfn_t start, size_t npages)
 pte_t 
 alloc_kpage_at(pte_t* ptep, pte_t pte, int order);
 
+static inline void*
+vmalloc_page(int order)
+{
+    struct leaflet* leaf = alloc_leaflet(0);
+    if (!leaf) {
+        return NULL;
+    }
+
+    return (void*)vmap(leaf, KERNEL_DATA);
+}
+
+static inline void
+vmfree(void* ptr)
+{
+    struct leaflet* leaf = ppfn_leaflet(pfn((ptr_t)ptr));
+    leaflet_return(leaf);
+}
+
 #endif /* __LUNAIX_PAGE_H */