1 /* 2 * Copyright 2007, François Revol, revol@free.fr. 3 * Distributed under the terms of the MIT License. 4 * 5 * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de. 6 * Distributed under the terms of the MIT License. 7 * 8 * Copyright 2001, Travis Geiselbrecht. All rights reserved. 9 * Distributed under the terms of the NewOS License. 10 */ 11 12 #include <KernelExport.h> 13 #include <kernel.h> 14 #include <vm.h> 15 #include <vm_address_space.h> 16 #include <vm_priv.h> 17 #include <int.h> 18 #include <boot/kernel_args.h> 19 #include <arch/vm_translation_map.h> 20 #include <arch/cpu.h> 21 #include <arch_mmu.h> 22 #include <stdlib.h> 23 24 #include "generic_vm_physical_page_mapper.h" 25 26 /* 27 * Each mmu of the m68k family has its own tricks, registers and opcodes... 28 * so we use a function array to switch to the one we want. 29 */ 30 31 #warning M68K: 060: must *not* have pgtables in copyback cachable mem!!! 32 33 //extern struct m68k_vm_ops m68851_vm_ops; 34 extern struct m68k_vm_ops m68030_vm_ops; 35 extern struct m68k_vm_ops m68040_vm_ops; 36 // 060 should be identical to 040 except for copyback issue 37 //extern struct m68k_vm_ops m68060_vm_ops; 38 39 #warning M68K: use a static! 40 m68k_vm_ops *get_vm_ops() 41 { 42 int mmu = arch_mmu_type; 43 44 switch (mmu) { 45 case 68551: 46 panic("Unimplemented yet (mmu)"); 47 //return &m68851_vm_ops; 48 return NULL; 49 case 68030: 50 return &m68030_vm_ops; 51 case 68040: 52 return &m68040_vm_ops; 53 case 68060: 54 //return &m68060_vm_ops; 55 panic("Unimplemented yet (mmu)"); 56 return NULL; 57 default: 58 panic("Invalid mmu type!"); 59 return NULL; 60 } 61 } 62 63 void * 64 m68k_translation_map_get_pgdir(vm_translation_map *map) 65 { 66 return get_vm_ops()->m68k_translation_map_get_pgdir(map); 67 } 68 69 // #pragma mark - 70 // VM API 71 72 73 status_t 74 arch_vm_translation_map_init_map(vm_translation_map *map, bool kernel) 75 { 76 return get_vm_ops()->arch_vm_translation_map_init_map(map, kernel); 77 } 78 79 80 status_t 81 arch_vm_translation_map_init_kernel_map_post_sem(vm_translation_map *map) 82 { 83 return get_vm_ops()->arch_vm_translation_map_init_kernel_map_post_sem(map); 84 } 85 86 87 status_t 88 arch_vm_translation_map_init(kernel_args *args) 89 { 90 return get_vm_ops()->arch_vm_translation_map_init(args); 91 } 92 93 94 status_t 95 arch_vm_translation_map_init_post_area(kernel_args *args) 96 { 97 return get_vm_ops()->arch_vm_translation_map_init_post_area(args); 98 } 99 100 101 status_t 102 arch_vm_translation_map_init_post_sem(kernel_args *args) 103 { 104 return get_vm_ops()->arch_vm_translation_map_init_post_sem(args); 105 } 106 107 108 /** Directly maps a page without having knowledge of any kernel structures. 109 * Used only during VM setup. 110 * It currently ignores the "attributes" parameter and sets all pages 111 * read/write. 112 */ 113 114 status_t 115 arch_vm_translation_map_early_map(kernel_args *ka, addr_t virtualAddress, addr_t physicalAddress, 116 uint8 attributes, addr_t (*get_free_page)(kernel_args *)) 117 { 118 return get_vm_ops()->arch_vm_translation_map_early_map(ka, virtualAddress, physicalAddress, 119 attributes, get_free_page); 120 } 121 122 123 // XXX currently assumes this translation map is active 124 125 status_t 126 arch_vm_translation_map_early_query(addr_t va, addr_t *out_physical) 127 { 128 return get_vm_ops()->arch_vm_translation_map_early_query(va, out_physical); 129 } 130 131 132 // #pragma mark - 133 void 134 m68k_set_pgdir(void *rt) 135 { 136 return get_vm_ops()->m68k_set_pgdir(rt); 137 } 138 #if 0 139 140 status_t 141 m68k_map_address_range(addr_t virtualAddress, addr_t physicalAddress, 142 size_t size) 143 { 144 return get_vm_ops()->m68k_map_address_range(virtualAddress, physicalAddress, size); 145 } 146 147 148 void 149 m68k_unmap_address_range(addr_t virtualAddress, size_t size) 150 { 151 get_vm_ops()->m68k_unmap_address_range(virtualAddress, size); 152 } 153 154 155 status_t 156 m68k_remap_address_range(addr_t *_virtualAddress, size_t size, bool unmap) 157 { 158 return get_vm_ops()->m68k_remap_address_range(_virtualAddress, size, unmap); 159 } 160 161 #endif 162 163 bool 164 arch_vm_translation_map_is_kernel_page_accessible(addr_t virtualAddress, 165 uint32 protection) 166 { 167 return get_vm_ops()-arch_vm_translation_map_is_kernel_page_accessible(virtualAddress, 168 protection); 169 } 170 171 172