Unifying the Lunaix's Physical Memory Model (#28)
[lunaix-os.git] / lunaix-os / kernel / mm / cake.c
index 9503260ac26dc0522b2d9748e31b205a59647a27..d9ef3810d5c5831aaaa05d81e889df2df38f6698 100644 (file)
@@ -12,8 +12,7 @@
 
 #include <klibc/string.h>
 #include <lunaix/mm/cake.h>
-#include <lunaix/mm/pmm.h>
-#include <lunaix/mm/vmm.h>
+#include <lunaix/mm/page.h>
 #include <lunaix/spike.h>
 #include <lunaix/syslog.h>
 
@@ -28,11 +27,12 @@ struct llist_header piles = { .next = &piles, .prev = &piles };
 void*
 __alloc_cake(unsigned int cake_pg)
 {
-    ptr_t pa = (ptr_t)pmm_alloc_cpage(cake_pg, 0);
-    if (!pa) {
+    struct leaflet* leaflet = alloc_leaflet(count_order(cake_pg));
+    if (!leaflet) {
         return NULL;
     }
-    return vmap(pa, cake_pg * PG_SIZE, PG_PREM_RW, 0);
+    
+    return (void*)vmap(leaflet, KERNEL_DATA);
 }
 
 struct cake_s*
@@ -86,7 +86,7 @@ __init_pile(struct cake_pile* pile,
     *pile = (struct cake_pile){ .piece_size = piece_size,
                                 .cakes_count = 0,
                                 .pieces_per_cake =
-                                  (pg_per_cake * PG_SIZE) /
+                                  (pg_per_cake * PAGE_SIZE) /
                                   (piece_size + sizeof(piece_index_t)),
                                 .pg_per_cake = pg_per_cake };
 
@@ -117,6 +117,9 @@ cake_new_pile(char* name,
 {
     struct cake_pile* pile = (struct cake_pile*)cake_grab(&master_pile);
 
+    // must aligned to napot order!
+    assert(is_pot(pg_per_cake));
+
     __init_pile(pile, name, piece_size, pg_per_cake, options);
 
     return pile;