Antonio Nino Diaz | f1b84f6 | 2018-07-03 11:58:49 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <debug.h> |
| 8 | #include <platform_def.h> |
| 9 | #include <xlat_tables_defs.h> |
| 10 | #include <xlat_tables_v2.h> |
| 11 | |
| 12 | #include "xlat_tables_private.h" |
| 13 | |
| 14 | /* |
| 15 | * Each platform can define the size of its physical and virtual address spaces. |
| 16 | * If the platform hasn't defined one or both of them, default to |
| 17 | * ADDR_SPACE_SIZE. The latter is deprecated, though. |
| 18 | */ |
| 19 | #if ERROR_DEPRECATED |
| 20 | # ifdef ADDR_SPACE_SIZE |
| 21 | # error "ADDR_SPACE_SIZE is deprecated. Use PLAT_xxx_ADDR_SPACE_SIZE instead." |
| 22 | # endif |
| 23 | #elif defined(ADDR_SPACE_SIZE) |
| 24 | # ifndef PLAT_PHY_ADDR_SPACE_SIZE |
| 25 | # define PLAT_PHY_ADDR_SPACE_SIZE ADDR_SPACE_SIZE |
| 26 | # endif |
| 27 | # ifndef PLAT_VIRT_ADDR_SPACE_SIZE |
| 28 | # define PLAT_VIRT_ADDR_SPACE_SIZE ADDR_SPACE_SIZE |
| 29 | # endif |
| 30 | #endif |
| 31 | |
| 32 | /* |
| 33 | * Allocate and initialise the default translation context for the BL image |
| 34 | * currently executing. |
| 35 | */ |
| 36 | REGISTER_XLAT_CONTEXT(tf, MAX_MMAP_REGIONS, MAX_XLAT_TABLES, |
| 37 | PLAT_VIRT_ADDR_SPACE_SIZE, PLAT_PHY_ADDR_SPACE_SIZE); |
| 38 | |
| 39 | void mmap_add_region(unsigned long long base_pa, uintptr_t base_va, size_t size, |
| 40 | unsigned int attr) |
| 41 | { |
| 42 | mmap_region_t mm = MAP_REGION(base_pa, base_va, size, attr); |
| 43 | |
| 44 | mmap_add_region_ctx(&tf_xlat_ctx, &mm); |
| 45 | } |
| 46 | |
| 47 | void mmap_add(const mmap_region_t *mm) |
| 48 | { |
| 49 | mmap_add_ctx(&tf_xlat_ctx, mm); |
| 50 | } |
| 51 | |
| 52 | #if PLAT_XLAT_TABLES_DYNAMIC |
| 53 | |
| 54 | int mmap_add_dynamic_region(unsigned long long base_pa, uintptr_t base_va, |
| 55 | size_t size, unsigned int attr) |
| 56 | { |
| 57 | mmap_region_t mm = MAP_REGION(base_pa, base_va, size, attr); |
| 58 | |
| 59 | return mmap_add_dynamic_region_ctx(&tf_xlat_ctx, &mm); |
| 60 | } |
| 61 | |
| 62 | int mmap_remove_dynamic_region(uintptr_t base_va, size_t size) |
| 63 | { |
| 64 | return mmap_remove_dynamic_region_ctx(&tf_xlat_ctx, |
| 65 | base_va, size); |
| 66 | } |
| 67 | |
| 68 | #endif /* PLAT_XLAT_TABLES_DYNAMIC */ |
| 69 | |
| 70 | void init_xlat_tables(void) |
| 71 | { |
| 72 | init_xlat_tables_ctx(&tf_xlat_ctx); |
| 73 | } |
| 74 | |
| 75 | /* |
| 76 | * If dynamic allocation of new regions is disabled then by the time we call the |
| 77 | * function enabling the MMU, we'll have registered all the memory regions to |
| 78 | * map for the system's lifetime. Therefore, at this point we know the maximum |
| 79 | * physical address that will ever be mapped. |
| 80 | * |
| 81 | * If dynamic allocation is enabled then we can't make any such assumption |
| 82 | * because the maximum physical address could get pushed while adding a new |
| 83 | * region. Therefore, in this case we have to assume that the whole address |
| 84 | * space size might be mapped. |
| 85 | */ |
| 86 | #ifdef PLAT_XLAT_TABLES_DYNAMIC |
| 87 | #define MAX_PHYS_ADDR tf_xlat_ctx.pa_max_address |
| 88 | #else |
| 89 | #define MAX_PHYS_ADDR tf_xlat_ctx.max_pa |
| 90 | #endif |
| 91 | |
| 92 | #ifdef AARCH32 |
| 93 | |
| 94 | void enable_mmu_secure(unsigned int flags) |
| 95 | { |
| 96 | setup_mmu_cfg(flags, tf_xlat_ctx.base_table, MAX_PHYS_ADDR, |
| 97 | tf_xlat_ctx.va_max_address); |
| 98 | enable_mmu_direct(flags); |
| 99 | } |
| 100 | |
| 101 | #else |
| 102 | |
| 103 | void enable_mmu_el1(unsigned int flags) |
| 104 | { |
| 105 | setup_mmu_cfg(flags, tf_xlat_ctx.base_table, MAX_PHYS_ADDR, |
| 106 | tf_xlat_ctx.va_max_address); |
| 107 | enable_mmu_direct_el1(flags); |
| 108 | } |
| 109 | |
| 110 | void enable_mmu_el3(unsigned int flags) |
| 111 | { |
| 112 | setup_mmu_cfg(flags, tf_xlat_ctx.base_table, MAX_PHYS_ADDR, |
| 113 | tf_xlat_ctx.va_max_address); |
| 114 | enable_mmu_direct_el3(flags); |
| 115 | } |
| 116 | |
| 117 | #endif /* AARCH32 */ |