1 /* 2 * Copyright (c) 2014-2016 Travis Geiselbrecht 3 * 4 * Use of this source code is governed by a MIT-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/MIT 7 */ 8 #pragma once 9 10 #if ARCH_HAS_MMU 11 12 #include <arch.h> 13 #include <sys/types.h> 14 #include <lk/compiler.h> 15 16 /* to bring in definition of arch_aspace */ 17 #include <arch/aspace.h> 18 19 __BEGIN_CDECLS 20 21 #define ARCH_MMU_FLAG_CACHED (0<<0) 22 #define ARCH_MMU_FLAG_UNCACHED (1<<0) 23 #define ARCH_MMU_FLAG_UNCACHED_DEVICE (2<<0) /* only exists on some arches, otherwise UNCACHED */ 24 #define ARCH_MMU_FLAG_CACHE_MASK (3<<0) 25 26 #define ARCH_MMU_FLAG_PERM_USER (1<<2) 27 #define ARCH_MMU_FLAG_PERM_RO (1<<3) 28 #define ARCH_MMU_FLAG_PERM_NO_EXECUTE (1<<4) 29 #define ARCH_MMU_FLAG_NS (1<<5) /* NON-SECURE */ 30 #define ARCH_MMU_FLAG_INVALID (1<<7) /* indicates that flags are not specified */ 31 32 /* forward declare the per-address space arch-specific context object */ 33 typedef struct arch_aspace arch_aspace_t; 34 35 #define ARCH_ASPACE_FLAG_KERNEL (1<<0) 36 37 /* initialize per address space */ 38 status_t arch_mmu_init_aspace(arch_aspace_t *aspace, vaddr_t base, size_t size, uint flags) __NONNULL((1)); 39 status_t arch_mmu_destroy_aspace(arch_aspace_t *aspace) __NONNULL((1)); 40 41 /* routines to map/unmap/query mappings per address space */ 42 int arch_mmu_map(arch_aspace_t *aspace, vaddr_t vaddr, paddr_t paddr, uint count, uint flags) __NONNULL((1)); 43 int arch_mmu_unmap(arch_aspace_t *aspace, vaddr_t vaddr, uint count) __NONNULL((1)); 44 status_t arch_mmu_query(arch_aspace_t *aspace, vaddr_t vaddr, paddr_t *paddr, uint *flags) __NONNULL((1)); 45 46 vaddr_t arch_mmu_pick_spot(arch_aspace_t *aspace, 47 vaddr_t base, uint prev_region_arch_mmu_flags, 48 vaddr_t end, uint next_region_arch_mmu_flags, 49 vaddr_t align, size_t size, uint arch_mmu_flags) __NONNULL((1)); 50 51 /* load a new user address space context. 52 * aspace argument NULL should unload user space. 53 */ 54 void arch_mmu_context_switch(arch_aspace_t *aspace); 55 56 void arch_disable_mmu(void); 57 58 __END_CDECLS 59 60 #endif 61 62