123eafdafSFrançois Revol /* 223eafdafSFrançois Revol * Copyright 2007, François Revol, revol@free.fr. 323eafdafSFrançois Revol * Distributed under the terms of the MIT License. 423eafdafSFrançois Revol * 523eafdafSFrançois Revol * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. 623eafdafSFrançois Revol * Distributed under the terms of the MIT License. 723eafdafSFrançois Revol * 823eafdafSFrançois Revol * Copyright 2001, Travis Geiselbrecht. All rights reserved. 923eafdafSFrançois Revol * Distributed under the terms of the NewOS License. 1023eafdafSFrançois Revol */ 1123eafdafSFrançois Revol 12258d4ef9SAlexander von Gluck IV 1323eafdafSFrançois Revol #include <KernelExport.h> 1423eafdafSFrançois Revol 1523eafdafSFrançois Revol #include <kernel.h> 1623eafdafSFrançois Revol #include <boot/kernel_args.h> 1723eafdafSFrançois Revol 18e50cf876SIngo Weinhold #include <vm/vm.h> 191f46427dSDavid Karoly #include <vm/VMAddressSpace.h> 20e50cf876SIngo Weinhold #include <vm/vm_types.h> 2123eafdafSFrançois Revol #include <arch/vm.h> 2223eafdafSFrançois Revol //#include <arch_mmu.h> 2323eafdafSFrançois Revol 2423eafdafSFrançois Revol 2523eafdafSFrançois Revol //#define TRACE_ARCH_VM 2623eafdafSFrançois Revol #ifdef TRACE_ARCH_VM 27*fbe8805dSDavid Karoly # define TRACE(x...) dprintf(x) 2823eafdafSFrançois Revol #else 29*fbe8805dSDavid Karoly # define TRACE(x...) ; 3023eafdafSFrançois Revol #endif 3123eafdafSFrançois Revol 3223eafdafSFrançois Revol 3323eafdafSFrançois Revol status_t 3423eafdafSFrançois Revol arch_vm_init(kernel_args *args) 3523eafdafSFrançois Revol { 36*fbe8805dSDavid Karoly TRACE("arch_vm_init: entry\n"); 3723eafdafSFrançois Revol return B_OK; 3823eafdafSFrançois Revol } 3923eafdafSFrançois Revol 4023eafdafSFrançois Revol 4123eafdafSFrançois Revol status_t 4223eafdafSFrançois Revol arch_vm_init2(kernel_args *args) 4323eafdafSFrançois Revol { 4423eafdafSFrançois Revol return B_OK; 4523eafdafSFrançois Revol } 4623eafdafSFrançois Revol 4723eafdafSFrançois Revol 4823eafdafSFrançois Revol status_t 4923eafdafSFrançois Revol arch_vm_init_post_area(kernel_args *args) 5023eafdafSFrançois Revol { 51*fbe8805dSDavid Karoly TRACE("arch_vm_init_post_area: entry\n"); 5223eafdafSFrançois Revol return B_OK; 5323eafdafSFrançois Revol } 5423eafdafSFrançois Revol 5523eafdafSFrançois Revol 5623eafdafSFrançois Revol status_t 5723eafdafSFrançois Revol arch_vm_init_end(kernel_args *args) 5823eafdafSFrançois Revol { 59*fbe8805dSDavid Karoly TRACE("arch_vm_init_end(): %" B_PRIu32 " virtual ranges to keep:\n", 60*fbe8805dSDavid Karoly args->arch_args.num_virtual_ranges_to_keep); 611f46427dSDavid Karoly 621f46427dSDavid Karoly for (int i = 0; i < (int)args->arch_args.num_virtual_ranges_to_keep; i++) { 631f46427dSDavid Karoly addr_range &range = args->arch_args.virtual_ranges_to_keep[i]; 641f46427dSDavid Karoly 65*fbe8805dSDavid Karoly TRACE(" start: %p, size: %#" B_PRIxSIZE "\n", (void*)range.start, range.size); 661f46427dSDavid Karoly 671f46427dSDavid Karoly // skip ranges outside the kernel address space 681f46427dSDavid Karoly if (!IS_KERNEL_ADDRESS(range.start)) { 69*fbe8805dSDavid Karoly TRACE(" no kernel address, skipping...\n"); 701f46427dSDavid Karoly continue; 711f46427dSDavid Karoly } 721f46427dSDavid Karoly 731f46427dSDavid Karoly phys_addr_t physicalAddress; 741f46427dSDavid Karoly void *address = (void*)range.start; 751f46427dSDavid Karoly if (vm_get_page_mapping(VMAddressSpace::KernelID(), range.start, 761f46427dSDavid Karoly &physicalAddress) != B_OK) 771f46427dSDavid Karoly panic("arch_vm_init_end(): No page mapping for %p\n", address); 781f46427dSDavid Karoly 791f46427dSDavid Karoly area_id area = vm_map_physical_memory(VMAddressSpace::KernelID(), 801f46427dSDavid Karoly "boot loader reserved area", &address, 811f46427dSDavid Karoly B_EXACT_ADDRESS, range.size, 821f46427dSDavid Karoly B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA, 831f46427dSDavid Karoly physicalAddress, true); 841f46427dSDavid Karoly 851f46427dSDavid Karoly if (area < 0) { 861f46427dSDavid Karoly panic("arch_vm_init_end(): Failed to create area for boot loader " 871f46427dSDavid Karoly "reserved area: %p - %p\n", (void*)range.start, 881f46427dSDavid Karoly (void*)(range.start + range.size)); 891f46427dSDavid Karoly } 901f46427dSDavid Karoly } 911f46427dSDavid Karoly 92a17ff827SIthamar R. Adema // Throw away all mappings that are unused by the kernel 93a17ff827SIthamar R. Adema vm_free_unused_boot_loader_range(KERNEL_LOAD_BASE, KERNEL_SIZE); 94a17ff827SIthamar R. Adema 9523eafdafSFrançois Revol return B_OK; 9623eafdafSFrançois Revol } 9723eafdafSFrançois Revol 9823eafdafSFrançois Revol 9923eafdafSFrançois Revol status_t 10023eafdafSFrançois Revol arch_vm_init_post_modules(kernel_args *args) 10123eafdafSFrançois Revol { 10223eafdafSFrançois Revol return B_OK; 10323eafdafSFrançois Revol } 10423eafdafSFrançois Revol 10523eafdafSFrançois Revol 10623eafdafSFrançois Revol void 107b0db552cSIngo Weinhold arch_vm_aspace_swap(struct VMAddressSpace *from, struct VMAddressSpace *to) 10823eafdafSFrançois Revol { 109a17ff827SIthamar R. Adema // This functions is only invoked when a userland thread is in the process 110a17ff827SIthamar R. Adema // of dying. It switches to the kernel team and does whatever cleanup is 111a17ff827SIthamar R. Adema // necessary (in case it is the team's main thread, it will delete the 112a17ff827SIthamar R. Adema // team). 113a17ff827SIthamar R. Adema // It is however not necessary to change the page directory. Userland team's 114a17ff827SIthamar R. Adema // page directories include all kernel mappings as well. Furthermore our 115a17ff827SIthamar R. Adema // arch specific translation map data objects are ref-counted, so they won't 116a17ff827SIthamar R. Adema // go away as long as they are still used on any CPU. 11723eafdafSFrançois Revol } 11823eafdafSFrançois Revol 11923eafdafSFrançois Revol 12023eafdafSFrançois Revol bool 12123eafdafSFrançois Revol arch_vm_supports_protection(uint32 protection) 12223eafdafSFrançois Revol { 123a17ff827SIthamar R. Adema // TODO check ARM protection possibilities 12423eafdafSFrançois Revol return true; 12523eafdafSFrançois Revol } 12623eafdafSFrançois Revol 12723eafdafSFrançois Revol 12823eafdafSFrançois Revol void 129a99eb6b5SIngo Weinhold arch_vm_unset_memory_type(VMArea *area) 13023eafdafSFrançois Revol { 13123eafdafSFrançois Revol } 13223eafdafSFrançois Revol 13323eafdafSFrançois Revol 13423eafdafSFrançois Revol status_t 135147133b7SIngo Weinhold arch_vm_set_memory_type(VMArea *area, phys_addr_t physicalBase, uint32 type) 13623eafdafSFrançois Revol { 137de4f3cf3SIthamar R. Adema return B_OK; 13823eafdafSFrançois Revol } 139