Uses kref for struct page
[akaros.git] / kern / arch / i686 / pmap.c
index 0f711d3..902764c 100644 (file)
@@ -638,28 +638,6 @@ int get_va_perms(pde_t *pgdir, const void *SNT va)
        return the_pte & the_pde & (PTE_U | PTE_W | PTE_P);
 }
 
-void *get_free_va_range(pde_t *pgdir, uintptr_t addr, size_t len)
-{
-       addr = ROUNDUP(MAX(addr,BRK_END),PGSIZE);
-       len = ROUNDUP(len,PGSIZE);
-
-       for(char* a = (char*)addr; a < (char*)USTACKBOT; a += PGSIZE)
-       {
-               for(char* b = a; b < a+len; b += PGSIZE)
-               {
-                       pte_t* pte = pgdir_walk(pgdir,b,0);
-                       if(pte && !PAGE_UNMAPPED(*pte))
-                       {
-                               a = b;
-                               break;
-                       }
-                       if(b+PGSIZE == a+len)
-                               return a;
-               }
-       }
-       return NULL;
-}
-
 /* Flushes a TLB, including global pages.  We should always have the CR4_PGE
  * flag set, but just in case, we'll check.  Toggling this bit flushes the TLB.
  */
@@ -722,13 +700,13 @@ page_check(void)
        }
        assert(PTE_ADDR(boot_pgdir[0]) == page2pa(pp0));
        assert(check_va2pa(boot_pgdir, 0x0) == page2pa(pp1));
-       assert(pp1->page_ref == 1);
-       assert(pp0->page_ref == 1);
+       assert(kref_refcnt(&pp1->pg_kref) == 1);
+       assert(kref_refcnt(&pp0->pg_kref) == 1);
 
        // should be able to map pp2 at PGSIZE because pp0 is already allocated for page table
        assert(page_insert(boot_pgdir, pp2, (void*SNT) PGSIZE, 0) == 0);
        assert(check_va2pa(boot_pgdir, PGSIZE) == page2pa(pp2));
-       assert(pp2->page_ref == 1);
+       assert(kref_refcnt(&pp2->pg_kref) == 1);
 
        // Make sure that pgdir_walk returns a pointer to the pte and
        // not the table or some other garbage
@@ -743,7 +721,7 @@ page_check(void)
        // should be able to map pp2 at PGSIZE because it's already there
        assert(page_insert(boot_pgdir, pp2, (void*SNT) PGSIZE, PTE_U) == 0);
        assert(check_va2pa(boot_pgdir, PGSIZE) == page2pa(pp2));
-       assert(pp2->page_ref == 1);
+       assert(kref_refcnt(&pp2->pg_kref) == 1);
 
        // Make sure that we actually changed the permission on pp2 when we re-mapped it
        {
@@ -765,8 +743,8 @@ page_check(void)
        assert(check_va2pa(boot_pgdir, 0) == page2pa(pp1));
        assert(check_va2pa(boot_pgdir, PGSIZE) == page2pa(pp1));
        // ... and ref counts should reflect this
-       assert(pp1->page_ref == 2);
-       assert(pp2->page_ref == 0);
+       assert(kref_refcnt(&pp1->pg_kref) == 2);
+       assert(kref_refcnt(&pp2->pg_kref) == 0);
 
        // pp2 should be returned by page_alloc
        assert(kpage_alloc(&pp) == 0 && pp == pp2);
@@ -776,15 +754,15 @@ page_check(void)
        page_remove(boot_pgdir, 0x0);
        assert(check_va2pa(boot_pgdir, 0x0) == ~0);
        assert(check_va2pa(boot_pgdir, PGSIZE) == page2pa(pp1));
-       assert(pp1->page_ref == 1);
-       assert(pp2->page_ref == 0);
+       assert(kref_refcnt(&pp1->pg_kref) == 1);
+       assert(kref_refcnt(&pp2->pg_kref) == 0);
 
        // unmapping pp1 at PGSIZE should free it
        page_remove(boot_pgdir, (void*SNT) PGSIZE);
        assert(check_va2pa(boot_pgdir, 0x0) == ~0);
        assert(check_va2pa(boot_pgdir, PGSIZE) == ~0);
-       assert(pp1->page_ref == 0);
-       assert(pp2->page_ref == 0);
+       assert(kref_refcnt(&pp1->pg_kref) == 0);
+       assert(kref_refcnt(&pp2->pg_kref) == 0);
 
        // so it should be returned by page_alloc
        assert(kpage_alloc(&pp) == 0 && pp == pp1);
@@ -796,8 +774,8 @@ page_check(void)
        // forcibly take pp0 back
        assert(PTE_ADDR(boot_pgdir[0]) == page2pa(pp0));
        boot_pgdir[0] = 0;
-       assert(pp0->page_ref == 1);
-       pp0->page_ref = 0;
+       assert(kref_refcnt(&pp0->pg_kref) == 1);
+       page_setref(pp0, 0);
 
        // Catch invalid pointer addition in pgdir_walk - i.e. pgdir + PDX(va)
        {
@@ -811,7 +789,7 @@ page_check(void)
 
          // Clean up again
          boot_pgdir[PDX(va)] = 0;
-         pp0->page_ref = 0;
+         page_setref(pp0, 0);
        }
 
        // give free list back