xref: /haiku/src/system/kernel/arch/arm/arch_vm.cpp (revision 1f46427d16f0f099ae2acf98680f81295d6fa895)
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>
19*1f46427dSDavid 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
2723eafdafSFrançois Revol #	define TRACE(x) dprintf x
2823eafdafSFrançois Revol #else
2923eafdafSFrançois Revol #	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 {
36a17ff827SIthamar R. Adema 	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 {
51a17ff827SIthamar R. Adema 	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*1f46427dSDavid Karoly 	TRACE(("arch_vm_init_end(): %" B_PRIu32 " virtual ranges to keep:\n",
60*1f46427dSDavid Karoly 		args->arch_args.num_virtual_ranges_to_keep));
61*1f46427dSDavid Karoly 
62*1f46427dSDavid Karoly 	for (int i = 0; i < (int)args->arch_args.num_virtual_ranges_to_keep; i++) {
63*1f46427dSDavid Karoly 		addr_range &range = args->arch_args.virtual_ranges_to_keep[i];
64*1f46427dSDavid Karoly 
65*1f46427dSDavid Karoly 		TRACE(("  start: %p, size: %#" B_PRIxSIZE "\n", (void*)range.start, range.size));
66*1f46427dSDavid Karoly 
67*1f46427dSDavid Karoly 		// skip ranges outside the kernel address space
68*1f46427dSDavid Karoly 		if (!IS_KERNEL_ADDRESS(range.start)) {
69*1f46427dSDavid Karoly 			TRACE(("    no kernel address, skipping...\n"));
70*1f46427dSDavid Karoly 			continue;
71*1f46427dSDavid Karoly 		}
72*1f46427dSDavid Karoly 
73*1f46427dSDavid Karoly 		phys_addr_t physicalAddress;
74*1f46427dSDavid Karoly 		void *address = (void*)range.start;
75*1f46427dSDavid Karoly 		if (vm_get_page_mapping(VMAddressSpace::KernelID(), range.start,
76*1f46427dSDavid Karoly 			&physicalAddress) != B_OK)
77*1f46427dSDavid Karoly 			panic("arch_vm_init_end(): No page mapping for %p\n", address);
78*1f46427dSDavid Karoly 
79*1f46427dSDavid Karoly 		area_id area = vm_map_physical_memory(VMAddressSpace::KernelID(),
80*1f46427dSDavid Karoly 			"boot loader reserved area", &address,
81*1f46427dSDavid Karoly 			B_EXACT_ADDRESS, range.size,
82*1f46427dSDavid Karoly 			B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA,
83*1f46427dSDavid Karoly 			physicalAddress, true);
84*1f46427dSDavid Karoly 
85*1f46427dSDavid Karoly 		if (area < 0) {
86*1f46427dSDavid Karoly 			panic("arch_vm_init_end(): Failed to create area for boot loader "
87*1f46427dSDavid Karoly 				"reserved area: %p - %p\n", (void*)range.start,
88*1f46427dSDavid Karoly 				(void*)(range.start + range.size));
89*1f46427dSDavid Karoly 		}
90*1f46427dSDavid Karoly 	}
91*1f46427dSDavid 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 {
131a17ff827SIthamar R. Adema 	// TODO
13223eafdafSFrançois Revol }
13323eafdafSFrançois Revol 
13423eafdafSFrançois Revol 
13523eafdafSFrançois Revol status_t
136147133b7SIngo Weinhold arch_vm_set_memory_type(VMArea *area, phys_addr_t physicalBase, uint32 type)
13723eafdafSFrançois Revol {
138de4f3cf3SIthamar R. Adema 	if (type != 0)
139de4f3cf3SIthamar R. Adema 		dprintf("%s: undefined type %lx!\n", __PRETTY_FUNCTION__, type);
14023eafdafSFrançois Revol 
141de4f3cf3SIthamar R. Adema 	return B_OK;
14223eafdafSFrançois Revol }
143