xref: /haiku/src/system/kernel/arch/arm64/arch_vm.cpp (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
1 /*
2  * Copyright 2019-2022 Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #include <KernelExport.h>
6 
7 #include <boot/kernel_args.h>
8 #include <kernel.h>
9 
10 #include <arch/vm.h>
11 #include <vm/vm.h>
12 #include <vm/VMAddressSpace.h>
13 #include <vm/vm_types.h>
14 
15 
16 //#define TRACE_ARCH_VM
17 #ifdef TRACE_ARCH_VM
18 #	define TRACE(x...) dprintf(x)
19 #else
20 #	define TRACE(x...) ;
21 #endif
22 
23 
24 status_t
25 arch_vm_init(kernel_args* args)
26 {
27 	TRACE("arch_vm_init\n");
28 	return B_OK;
29 }
30 
31 
32 status_t
33 arch_vm_init2(kernel_args* args)
34 {
35 	TRACE("arch_vm_init2\n");
36 	return B_OK;
37 }
38 
39 
40 status_t
41 arch_vm_init_post_area(kernel_args* args)
42 {
43 	TRACE("arch_vm_init_post_area\n");
44 	return B_OK;
45 }
46 
47 
48 status_t
49 arch_vm_init_end(kernel_args* args)
50 {
51 	TRACE("arch_vm_init_end(): %" B_PRIu32 " virtual ranges to keep:\n",
52 		args->arch_args.num_virtual_ranges_to_keep);
53 
54 	for (int i = 0; i < (int)args->arch_args.num_virtual_ranges_to_keep; i++) {
55 		addr_range &range = args->arch_args.virtual_ranges_to_keep[i];
56 
57 		TRACE("  start: %p, size: %#" B_PRIxSIZE "\n", (void*)range.start, range.size);
58 
59 		// skip ranges outside the kernel address space
60 		if (!IS_KERNEL_ADDRESS(range.start)) {
61 			TRACE("    no kernel address, skipping...\n");
62 			continue;
63 		}
64 
65 		phys_addr_t physicalAddress;
66 		void *address = (void*)range.start;
67 		if (vm_get_page_mapping(VMAddressSpace::KernelID(), range.start,
68 			&physicalAddress) != B_OK)
69 			panic("arch_vm_init_end(): No page mapping for %p\n", address);
70 
71 		area_id area = vm_map_physical_memory(VMAddressSpace::KernelID(),
72 			"boot loader reserved area", &address,
73 			B_EXACT_ADDRESS, range.size,
74 			B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA,
75 			physicalAddress, true);
76 
77 		if (area < 0) {
78 			panic("arch_vm_init_end(): Failed to create area for boot loader "
79 				"reserved area: %p - %p\n", (void*)range.start,
80 				(void*)(range.start + range.size));
81 		}
82 	}
83 
84 	return B_OK;
85 }
86 
87 
88 status_t
89 arch_vm_init_post_modules(kernel_args* args)
90 {
91 	TRACE("arch_vm_init_post_modules\n");
92 	return B_OK;
93 }
94 
95 
96 void
97 arch_vm_aspace_swap(struct VMAddressSpace* from, struct VMAddressSpace* to)
98 {
99 	TRACE("arch_vm_aspace_swap\n");
100 }
101 
102 
103 bool
104 arch_vm_supports_protection(uint32 protection)
105 {
106 	// User-RO/Kernel-RW is not possible
107 	if ((protection & B_READ_AREA) != 0 && (protection & B_WRITE_AREA) == 0
108 		&& (protection & B_KERNEL_WRITE_AREA) != 0) {
109 		return false;
110 	}
111 
112 	return true;
113 }
114 
115 
116 void
117 arch_vm_unset_memory_type(VMArea* area)
118 {
119 }
120 
121 
122 status_t
123 arch_vm_set_memory_type(VMArea* area, phys_addr_t physicalBase, uint32 type)
124 {
125 	return B_OK;
126 }
127