Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
| 8 | #include <arch_helpers.h> |
| 9 | #include <assert.h> |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 10 | #include <common_def.h> |
| 11 | #include <debug.h> |
| 12 | #include <errno.h> |
| 13 | #include <platform_def.h> |
| 14 | #include <string.h> |
| 15 | #include <types.h> |
| 16 | #include <utils.h> |
Sandrine Bailleux | 090c849 | 2017-05-19 09:59:37 +0100 | [diff] [blame] | 17 | #include <xlat_tables_arch.h> |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 18 | #include <xlat_tables_v2.h> |
Sandrine Bailleux | 090c849 | 2017-05-19 09:59:37 +0100 | [diff] [blame] | 19 | |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 20 | #include "xlat_tables_private.h" |
| 21 | |
| 22 | /* |
Sandrine Bailleux | 090c849 | 2017-05-19 09:59:37 +0100 | [diff] [blame] | 23 | * Each platform can define the size of its physical and virtual address spaces. |
| 24 | * If the platform hasn't defined one or both of them, default to |
| 25 | * ADDR_SPACE_SIZE. The latter is deprecated, though. |
| 26 | */ |
| 27 | #if ERROR_DEPRECATED |
| 28 | # ifdef ADDR_SPACE_SIZE |
| 29 | # error "ADDR_SPACE_SIZE is deprecated. Use PLAT_xxx_ADDR_SPACE_SIZE instead." |
| 30 | # endif |
| 31 | #elif defined(ADDR_SPACE_SIZE) |
| 32 | # ifndef PLAT_PHY_ADDR_SPACE_SIZE |
| 33 | # define PLAT_PHY_ADDR_SPACE_SIZE ADDR_SPACE_SIZE |
| 34 | # endif |
| 35 | # ifndef PLAT_VIRT_ADDR_SPACE_SIZE |
| 36 | # define PLAT_VIRT_ADDR_SPACE_SIZE ADDR_SPACE_SIZE |
| 37 | # endif |
| 38 | #endif |
| 39 | |
Sandrine Bailleux | 090c849 | 2017-05-19 09:59:37 +0100 | [diff] [blame] | 40 | /* |
Sandrine Bailleux | 3120ea2 | 2017-07-10 13:37:48 +0100 | [diff] [blame^] | 41 | * Allocate and initialise the default translation context for the BL image |
| 42 | * currently executing. |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 43 | */ |
Sandrine Bailleux | 3120ea2 | 2017-07-10 13:37:48 +0100 | [diff] [blame^] | 44 | REGISTER_XLAT_CONTEXT(tf, MAX_MMAP_REGIONS, MAX_XLAT_TABLES, |
| 45 | PLAT_VIRT_ADDR_SPACE_SIZE, PLAT_PHY_ADDR_SPACE_SIZE); |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 46 | |
| 47 | void mmap_add_region(unsigned long long base_pa, uintptr_t base_va, |
Sandrine Bailleux | 04980a3 | 2017-04-19 14:02:23 +0100 | [diff] [blame] | 48 | size_t size, mmap_attr_t attr) |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 49 | { |
| 50 | mmap_region_t mm = { |
| 51 | .base_va = base_va, |
| 52 | .base_pa = base_pa, |
| 53 | .size = size, |
| 54 | .attr = attr, |
| 55 | }; |
| 56 | mmap_add_region_ctx(&tf_xlat_ctx, (mmap_region_t *)&mm); |
| 57 | } |
| 58 | |
| 59 | void mmap_add(const mmap_region_t *mm) |
| 60 | { |
| 61 | while (mm->size) { |
| 62 | mmap_add_region_ctx(&tf_xlat_ctx, (mmap_region_t *)mm); |
| 63 | mm++; |
| 64 | } |
| 65 | } |
| 66 | |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 67 | #if PLAT_XLAT_TABLES_DYNAMIC |
| 68 | |
| 69 | int mmap_add_dynamic_region(unsigned long long base_pa, |
Sandrine Bailleux | 04980a3 | 2017-04-19 14:02:23 +0100 | [diff] [blame] | 70 | uintptr_t base_va, size_t size, mmap_attr_t attr) |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 71 | { |
| 72 | mmap_region_t mm = { |
| 73 | .base_va = base_va, |
| 74 | .base_pa = base_pa, |
| 75 | .size = size, |
| 76 | .attr = attr, |
| 77 | }; |
| 78 | return mmap_add_dynamic_region_ctx(&tf_xlat_ctx, &mm); |
| 79 | } |
| 80 | |
| 81 | int mmap_remove_dynamic_region(uintptr_t base_va, size_t size) |
| 82 | { |
| 83 | return mmap_remove_dynamic_region_ctx(&tf_xlat_ctx, base_va, size); |
| 84 | } |
| 85 | |
| 86 | #endif /* PLAT_XLAT_TABLES_DYNAMIC */ |
| 87 | |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 88 | void init_xlat_tables(void) |
| 89 | { |
| 90 | assert(!is_mmu_enabled()); |
| 91 | assert(!tf_xlat_ctx.initialized); |
| 92 | print_mmap(tf_xlat_ctx.mmap); |
Antonio Nino Diaz | efabaa9 | 2017-04-27 13:30:22 +0100 | [diff] [blame] | 93 | tf_xlat_ctx.execute_never_mask = |
| 94 | xlat_arch_get_xn_desc(xlat_arch_current_el()); |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 95 | init_xlation_table(&tf_xlat_ctx); |
| 96 | xlat_tables_print(&tf_xlat_ctx); |
| 97 | |
Sandrine Bailleux | 3120ea2 | 2017-07-10 13:37:48 +0100 | [diff] [blame^] | 98 | assert(tf_xlat_ctx.max_va <= tf_xlat_ctx.va_max_address); |
| 99 | assert(tf_xlat_ctx.max_pa <= tf_xlat_ctx.pa_max_address); |
Antonio Nino Diaz | 233c7c1 | 2017-03-08 14:40:23 +0000 | [diff] [blame] | 100 | |
| 101 | init_xlat_tables_arch(tf_xlat_ctx.max_pa); |
| 102 | } |
| 103 | |
| 104 | #ifdef AARCH32 |
| 105 | |
| 106 | void enable_mmu_secure(unsigned int flags) |
| 107 | { |
| 108 | enable_mmu_arch(flags, tf_xlat_ctx.base_table); |
| 109 | } |
| 110 | |
| 111 | #else |
| 112 | |
| 113 | void enable_mmu_el1(unsigned int flags) |
| 114 | { |
| 115 | enable_mmu_arch(flags, tf_xlat_ctx.base_table); |
| 116 | } |
| 117 | |
| 118 | void enable_mmu_el3(unsigned int flags) |
| 119 | { |
| 120 | enable_mmu_arch(flags, tf_xlat_ctx.base_table); |
| 121 | } |
| 122 | |
| 123 | #endif /* AARCH32 */ |