PCI 16x50 UART Controller, O2 Enablement (#39)
[lunaix-os.git] / lunaix-os / kernel / mm / mmio.c
index f6d53686eb5836baae85475fee15c04873c65b0a..dbb1870afe9083437f7656d177fe579542184618 100644 (file)
@@ -1,18 +1,26 @@
 #include <lunaix/mm/mmio.h>
 #include <lunaix/mm/mmio.h>
-#include <lunaix/mm/pmm.h>
-#include <lunaix/mm/vmm.h>
+#include <lunaix/mm/page.h>
+#include <lunaix/spike.h>
 
 
-void*
-ioremap(uintptr_t paddr, uint32_t size)
+ptr_t
+ioremap(ptr_t paddr, u32_t size)
 {
 {
-    return vmm_vmap(paddr, size, PG_PREM_RW, PP_FGPERSIST);
+    // FIXME implement a page policy interface allow to decouple the 
+    //       arch-dependent caching behaviour
+
+    pfn_t start = pfn(paddr);
+    size_t npages = leaf_count(size);
+    
+    // Ensure the range is reservable (not already in use)
+    assert(pmm_onhold_range(start, npages));
+
+    ptr_t addr = vmap_range(start, npages, KERNEL_DATA);
+    return addr + va_offset(paddr);
 }
 
 }
 
-void*
-iounmap(uintptr_t vaddr, uint32_t size)
+void
+iounmap(ptr_t vaddr, u32_t size)
 {
 {
-    for (size_t i = 0; i < size; i += PG_SIZE) {
-        uintptr_t paddr = vmm_del_mapping(PD_REFERENCED, vaddr + i);
-        pmm_free_page(KERNEL_PID, paddr);
-    }
+    assert(vaddr >= VMAP && vaddr < VMAP_END);
+    vunmap_range(pfn(vaddr), leaf_count(size));
 }
\ No newline at end of file
 }
\ No newline at end of file