Included Travis' change 1687.

Cleanups, added TRACE() debugging macro instead of commented dprintfs.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2318 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2002-12-30 11:18:57 +00:00
parent 2d4d170f83
commit 7747cd8133
@@ -22,6 +22,12 @@
#include <arch/cpu.h>
#include <arch/vm_translation_map.h>
#define TRACE_VM_TMAP 0
#if TRACE_VM_TMAP
# define TRACE(x) dprintf x
#else
# define TRACE(x) ;
#endif
// 256 MB of iospace
#define IOSPACE_SIZE (256*1024*1024)
@@ -56,6 +62,7 @@ typedef struct vm_translation_map_arch_info_struct {
addr pages_to_invalidate[PAGE_INVALIDATE_CACHE_SIZE];
} vm_translation_map_arch_info;
static ptentry *page_hole = NULL;
static pdentry *page_hole_pgdir = NULL;
static pdentry *kernel_pgdir_phys = NULL;
@@ -73,7 +80,7 @@ static spinlock tmap_list_lock;
#define VADDR_TO_PTENT(va) (((va) / PAGE_SIZE) % 1024)
#define FIRST_USER_PGDIR_ENT (VADDR_TO_PDENT(USER_BASE))
#define NUM_USER_PGDIR_ENTS (VADDR_TO_PDENT(USER_SIZE))
#define NUM_USER_PGDIR_ENTS (VADDR_TO_PDENT(ROUNDUP(USER_SIZE, PAGE_SIZE * 1024)))
#define FIRST_KERNEL_PGDIR_ENT (VADDR_TO_PDENT(KERNEL_BASE))
#define NUM_KERNEL_PGDIR_ENTS (VADDR_TO_PDENT(KERNEL_SIZE))
@@ -81,17 +88,23 @@ static int vm_translation_map_quick_query(addr va, addr *out_physical);
static void flush_tmap(vm_translation_map *map);
static void init_pdentry(pdentry *e)
static void
init_pdentry(pdentry *e)
{
*(int *)e = 0;
}
static void init_ptentry(ptentry *e)
static void
init_ptentry(ptentry *e)
{
*(int *)e = 0;
}
static void _update_all_pgdirs(int index, pdentry e)
static void
_update_all_pgdirs(int index, pdentry e)
{
vm_translation_map *entry;
unsigned int state = disable_interrupts();
@@ -105,21 +118,26 @@ static void _update_all_pgdirs(int index, pdentry e)
restore_interrupts(state);
}
static int lock_tmap(vm_translation_map *map)
static int
lock_tmap(vm_translation_map *map)
{
// dprintf("lock_tmap: map 0x%x\n", map);
TRACE(("lock_tmap: map 0x%x\n", map));
if (recursive_lock_lock(&map->lock) == true) {
// we were the first one to grab the lock
// dprintf("clearing invalidated page count\n");
TRACE(("clearing invalidated page count\n"));
map->arch_data->num_invalidate_pages = 0;
}
return 0;
}
static int unlock_tmap(vm_translation_map *map)
static int
unlock_tmap(vm_translation_map *map)
{
// dprintf("unlock_tmap: map 0x%x\n", map);
TRACE(("unlock_tmap: map 0x%x\n", map));
if (recursive_lock_get_recursion(&map->lock) == 1) {
// we're about to release it for the last time
@@ -129,7 +147,9 @@ static int unlock_tmap(vm_translation_map *map)
return 0;
}
static void destroy_tmap(vm_translation_map *map)
static void
destroy_tmap(vm_translation_map *map)
{
int state;
vm_translation_map *entry;
@@ -146,11 +166,11 @@ static void destroy_tmap(vm_translation_map *map)
entry = tmap_list;
while (entry != NULL) {
if (entry == map) {
if(last != NULL) {
if (last != NULL)
last->next = entry->next;
} else {
else
tmap_list = entry->next;
}
break;
}
last = entry;
@@ -160,7 +180,6 @@ static void destroy_tmap(vm_translation_map *map)
release_spinlock(&tmap_list_lock);
restore_interrupts(state);
if (map->arch_data->pgdir_virt != NULL) {
// cycle through and free all of the user space pgtables
for (i = VADDR_TO_PDENT(USER_BASE); i < VADDR_TO_PDENT(USER_BASE + (USER_SIZE - 1)); i++) {
@@ -182,7 +201,9 @@ static void destroy_tmap(vm_translation_map *map)
recursive_lock_destroy(&map->lock);
}
static void put_pgtable_in_pgdir(pdentry *e, addr pgtable_phys, int attributes)
static void
put_pgtable_in_pgdir(pdentry *e, addr pgtable_phys, int attributes)
{
// put it in the pgdir
init_pdentry(e);
@@ -192,16 +213,17 @@ static void put_pgtable_in_pgdir(pdentry *e, addr pgtable_phys, int attributes)
e->present = 1;
}
static int map_tmap(vm_translation_map *map, addr va, addr pa, unsigned int attributes)
static int
map_tmap(vm_translation_map *map, addr va, addr pa, unsigned int attributes)
{
pdentry *pd;
ptentry *pt;
unsigned int index;
int err;
#if CHATTY_TMAP
dprintf("map_tmap: entry pa 0x%x va 0x%x\n", pa, va);
#endif
TRACE(("map_tmap: entry pa 0x%x va 0x%x\n", pa, va));
/*
dprintf("pgdir at 0x%x\n", pgdir);
dprintf("index is %d\n", va / PAGE_SIZE / 1024);
@@ -221,9 +243,9 @@ static int map_tmap(vm_translation_map *map, addr va, addr pa, unsigned int attr
// we need to allocate a pgtable
page = vm_page_allocate_page(PAGE_STATE_CLEAR);
pgtable = page->ppn * PAGE_SIZE;
#if CHATTY_TMAP
dprintf("map_tmap: asked for free page for pgtable. 0x%x\n", pgtable);
#endif
TRACE(("map_tmap: asked for free page for pgtable. 0x%x\n", pgtable));
// put it in the pgdir
put_pgtable_in_pgdir(&pd[index], pgtable, attributes | LOCK_RW);
@@ -248,9 +270,9 @@ static int map_tmap(vm_translation_map *map, addr va, addr pa, unsigned int attr
vm_put_physical_page((addr)pt);
if(map->arch_data->num_invalidate_pages < PAGE_INVALIDATE_CACHE_SIZE) {
if (map->arch_data->num_invalidate_pages < PAGE_INVALIDATE_CACHE_SIZE)
map->arch_data->pages_to_invalidate[map->arch_data->num_invalidate_pages] = va;
}
map->arch_data->num_invalidate_pages++;
map->map_count++;
@@ -258,7 +280,9 @@ static int map_tmap(vm_translation_map *map, addr va, addr pa, unsigned int attr
return 0;
}
static int unmap_tmap(vm_translation_map *map, addr start, addr end)
static int
unmap_tmap(vm_translation_map *map, addr start, addr end)
{
ptentry *pt;
pdentry *pd = map->arch_data->pgdir_virt;
@@ -268,9 +292,7 @@ static int unmap_tmap(vm_translation_map *map, addr start, addr end)
start = ROUNDOWN(start, PAGE_SIZE);
end = ROUNDUP(end, PAGE_SIZE);
#if CHATTY_TMAP
dprintf("unmap_tmap: asked to free pages 0x%x to 0x%x\n", start, end);
#endif
TRACE(("unmap_tmap: asked to free pages 0x%x to 0x%x\n", start, end));
restart:
if (start >= end)
@@ -292,15 +314,15 @@ restart:
// page mapping not valid
continue;
}
#if CHATTY_TMAP
dprintf("unmap_tmap: removing page 0x%x\n", start);
#endif
TRACE(("unmap_tmap: removing page 0x%x\n", start));
pt[index].present = 0;
map->map_count--;
if(map->arch_data->num_invalidate_pages < PAGE_INVALIDATE_CACHE_SIZE) {
if (map->arch_data->num_invalidate_pages < PAGE_INVALIDATE_CACHE_SIZE)
map->arch_data->pages_to_invalidate[map->arch_data->num_invalidate_pages] = start;
}
map->arch_data->num_invalidate_pages++;
}
@@ -309,7 +331,9 @@ restart:
goto restart;
}
static int query_tmap(vm_translation_map *map, addr va, addr *out_physical, unsigned int *out_flags)
static int
query_tmap(vm_translation_map *map, addr va, addr *out_physical, unsigned int *out_flags)
{
ptentry *pt;
pdentry *pd = map->arch_data->pgdir_virt;
@@ -343,24 +367,30 @@ static int query_tmap(vm_translation_map *map, addr va, addr *out_physical, unsi
vm_put_physical_page((addr)pt);
// dprintf("query_tmap: returning pa 0x%x for va 0x%x\n", *out_physical, va);
TRACE(("query_tmap: returning pa 0x%x for va 0x%x\n", *out_physical, va));
return 0;
}
static addr get_mapped_size_tmap(vm_translation_map *map)
static addr
get_mapped_size_tmap(vm_translation_map *map)
{
return map->map_count;
}
static int protect_tmap(vm_translation_map *map, addr base, addr top, unsigned int attributes)
static int
protect_tmap(vm_translation_map *map, addr base, addr top, unsigned int attributes)
{
// XXX finish
panic("protect_tmap called, not implemented\n");
return ERR_UNIMPLEMENTED;
}
static int clear_flags_tmap(vm_translation_map *map, addr va, unsigned int flags)
static int
clear_flags_tmap(vm_translation_map *map, addr va, unsigned int flags)
{
ptentry *pt;
pdentry *pd = map->arch_data->pgdir_virt;
@@ -392,19 +422,20 @@ static int clear_flags_tmap(vm_translation_map *map, addr va, unsigned int flags
vm_put_physical_page((addr)pt);
if (tlb_flush) {
if(map->arch_data->num_invalidate_pages < PAGE_INVALIDATE_CACHE_SIZE) {
if (map->arch_data->num_invalidate_pages < PAGE_INVALIDATE_CACHE_SIZE)
map->arch_data->pages_to_invalidate[map->arch_data->num_invalidate_pages] = va;
}
map->arch_data->num_invalidate_pages++;
}
// dprintf("query_tmap: returning pa 0x%x for va 0x%x\n", *out_physical, va);
TRACE(("query_tmap: returning pa 0x%x for va 0x%x\n", *out_physical, va));
return 0;
}
static void flush_tmap(vm_translation_map *map)
static void
flush_tmap(vm_translation_map *map)
{
int state;
@@ -414,11 +445,11 @@ static void flush_tmap(vm_translation_map *map)
state = disable_interrupts();
if (map->arch_data->num_invalidate_pages > PAGE_INVALIDATE_CACHE_SIZE) {
// invalidate all pages
// dprintf("flush_tmap: %d pages to invalidate, doing global invalidation\n", map->arch_data->num_invalidate_pages);
TRACE(("flush_tmap: %d pages to invalidate, doing global invalidation\n", map->arch_data->num_invalidate_pages));
arch_cpu_global_TLB_invalidate();
smp_send_broadcast_ici(SMP_MSG_GLOBAL_INVL_PAGE, 0, 0, 0, NULL, SMP_MSG_FLAG_SYNC);
} else {
// dprintf("flush_tmap: %d pages to invalidate, doing local invalidation\n", map->arch_data->num_invalidate_pages);
TRACE(("flush_tmap: %d pages to invalidate, doing local invalidation\n", map->arch_data->num_invalidate_pages));
arch_cpu_invalidate_TLB_list(map->arch_data->pages_to_invalidate, map->arch_data->num_invalidate_pages);
smp_send_broadcast_ici(SMP_MSG_INVL_PAGE_LIST, (unsigned long)map->arch_data->pages_to_invalidate,
map->arch_data->num_invalidate_pages, 0, NULL, SMP_MSG_FLAG_SYNC);
@@ -427,7 +458,9 @@ static void flush_tmap(vm_translation_map *map)
restore_interrupts(state);
}
static int map_iospace_chunk(addr va, addr pa)
static int
map_iospace_chunk(addr va, addr pa)
{
int i;
ptentry *pt;
@@ -458,13 +491,14 @@ static int map_iospace_chunk(addr va, addr pa)
return 0;
}
static int get_physical_page_tmap(addr pa, addr *va, int flags)
static int
get_physical_page_tmap(addr pa, addr *va, int flags)
{
int index;
paddr_chunk_desc *replaced_pchunk;
restart:
mutex_lock(&iospace_mutex);
// see if the page is already mapped
@@ -525,7 +559,9 @@ restart:
return 0;
}
static int put_physical_page_tmap(addr va)
static int
put_physical_page_tmap(addr va)
{
paddr_chunk_desc *desc;
@@ -556,6 +592,7 @@ static int put_physical_page_tmap(addr va)
return 0;
}
static vm_translation_map_ops tmap_ops = {
destroy_tmap,
lock_tmap,
@@ -571,12 +608,15 @@ static vm_translation_map_ops tmap_ops = {
put_physical_page_tmap
};
int vm_translation_map_create(vm_translation_map *new_map, bool kernel)
int
vm_translation_map_create(vm_translation_map *new_map, bool kernel)
{
if (new_map == NULL)
return EINVAL;
dprintf("vm_translation_map_create\n");
TRACE(("vm_translation_map_create\n"));
// initialize the new object
new_map->ops = &tmap_ops;
new_map->map_count = 0;
@@ -632,11 +672,13 @@ dprintf("vm_translation_map_create\n");
return 0;
}
int vm_translation_map_module_init(kernel_args *ka)
int
vm_translation_map_module_init(kernel_args *ka)
{
int i;
dprintf("vm_translation_map_module_init: entry\n");
TRACE(("vm_translation_map_module_init: entry\n"));
// page hole set up in stage2
page_hole = (ptentry *)ka->arch_args.page_hole;
@@ -660,8 +702,8 @@ int vm_translation_map_module_init(kernel_args *ka)
iospace_pgtables = (ptentry *)vm_alloc_from_ka_struct(ka,
PAGE_SIZE * (IOSPACE_SIZE / (PAGE_SIZE * 1024)), LOCK_RW|LOCK_KERNEL);
dprintf("paddr_desc %p, virtual_pmappings %p, iospace_pgtables %p\n",
paddr_desc, virtual_pmappings, iospace_pgtables);
TRACE(("paddr_desc %p, virtual_pmappings %p, iospace_pgtables %p\n",
paddr_desc, virtual_pmappings, iospace_pgtables));
// initialize our data structures
memset(paddr_desc, 0, sizeof(paddr_chunk_desc) * 1024);
@@ -673,7 +715,7 @@ int vm_translation_map_module_init(kernel_args *ka)
iospace_mutex.holder = -1;
iospace_full_sem = -1;
dprintf("mapping iospace_pgtables\n");
TRACE(("mapping iospace_pgtables\n"));
// put the array of pgtables directly into the kernel pagedir
// these will be wired and kept mapped into virtual space to be easy to get to
@@ -690,25 +732,28 @@ int vm_translation_map_module_init(kernel_args *ka)
}
}
dprintf("vm_translation_map_module_init: done\n");
TRACE(("vm_translation_map_module_init: done\n"));
return 0;
}
void vm_translation_map_module_init_post_sem(kernel_args *ka)
void
vm_translation_map_module_init_post_sem(kernel_args *ka)
{
mutex_init(&iospace_mutex, "iospace_mutex");
iospace_full_sem = create_sem(1, "iospace_full_sem");
}
int vm_translation_map_module_init2(kernel_args *ka)
int
vm_translation_map_module_init2(kernel_args *ka)
{
// now that the vm is initialized, create an region that represents
// the page hole
void *temp;
dprintf("vm_translation_map_module_init2: entry\n");
TRACE(("vm_translation_map_module_init2: entry\n"));
// unmap the page hole hack we were using before
kernel_pgdir_virt[1023].present = 0;
@@ -734,29 +779,30 @@ int vm_translation_map_module_init2(kernel_args *ka)
REGION_ADDR_EXACT_ADDRESS, PAGE_SIZE * (IOSPACE_SIZE / (PAGE_SIZE * 1024)),
REGION_WIRING_WIRED_ALREADY, LOCK_RW|LOCK_KERNEL);
dprintf("vm_translation_map_module_init2: creating iospace\n");
TRACE(("vm_translation_map_module_init2: creating iospace\n"));
temp = (void *)IOSPACE_BASE;
vm_create_null_region(vm_get_kernel_aspace_id(), "iospace", &temp,
REGION_ADDR_EXACT_ADDRESS, IOSPACE_SIZE);
dprintf("vm_translation_map_module_init2: done\n");
TRACE(("vm_translation_map_module_init2: done\n"));
return 0;
}
// XXX horrible back door to map a page quickly regardless of translation map object, etc.
// used only during VM setup.
// uses a 'page hole' set up in the stage 2 bootloader. The page hole is created by pointing one of
// the pgdir entries back at itself, effectively mapping the contents of all of the 4MB of pagetables
// into a 4 MB region. It's only used here, and is later unmapped.
int vm_translation_map_quick_map(kernel_args *ka, addr va, addr pa, unsigned int attributes, addr (*get_free_page)(kernel_args *))
int
vm_translation_map_quick_map(kernel_args *ka, addr va, addr pa, unsigned int attributes, addr (*get_free_page)(kernel_args *))
{
ptentry *pentry;
int index;
#if CHATTY_TMAP
dprintf("quick_tmap: entry pa 0x%x va 0x%x\n", pa, va);
#endif
TRACE(("quick_tmap: entry pa 0x%x va 0x%x\n", pa, va));
// check to see if a page table exists for this range
index = VADDR_TO_PDENT(va);
@@ -767,9 +813,8 @@ int vm_translation_map_quick_map(kernel_args *ka, addr va, addr pa, unsigned int
pgtable = get_free_page(ka);
// pgtable is in pages, convert to physical address
pgtable *= PAGE_SIZE;
#if CHATTY_TMAP
dprintf("quick_map: asked for free page for pgtable. 0x%x\n", pgtable);
#endif
TRACE(("quick_map: asked for free page for pgtable. 0x%x\n", pgtable));
// put it in the pgdir
e = &page_hole_pgdir[index];
@@ -792,8 +837,11 @@ int vm_translation_map_quick_map(kernel_args *ka, addr va, addr pa, unsigned int
return 0;
}
// XXX currently assumes this translation map is active
static int vm_translation_map_quick_query(addr va, addr *out_physical)
static int
vm_translation_map_quick_query(addr va, addr *out_physical)
{
ptentry *pentry;
@@ -813,7 +861,10 @@ static int vm_translation_map_quick_query(addr va, addr *out_physical)
return 0;
}
addr vm_translation_map_get_pgdir(vm_translation_map *map)
addr
vm_translation_map_get_pgdir(vm_translation_map *map)
{
return (addr)map->arch_data->pgdir_phys;
}