blob: f214e5cc094c76ec9f2d5fccc2e101d3378e601f [file] [log] [blame]
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +00001/*
2 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +00005 */
6
7#include <arch.h>
8#include <arch_helpers.h>
9#include <assert.h>
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +000010#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 Bailleux090c8492017-05-19 09:59:37 +010017#include <xlat_tables_arch.h>
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +000018#include <xlat_tables_v2.h>
Sandrine Bailleux090c8492017-05-19 09:59:37 +010019
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +000020#include "xlat_tables_private.h"
21
22/*
Sandrine Bailleux090c8492017-05-19 09:59:37 +010023 * 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 Bailleux090c8492017-05-19 09:59:37 +010040/*
Sandrine Bailleux3120ea22017-07-10 13:37:48 +010041 * Allocate and initialise the default translation context for the BL image
42 * currently executing.
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +000043 */
Sandrine Bailleux3120ea22017-07-10 13:37:48 +010044REGISTER_XLAT_CONTEXT(tf, MAX_MMAP_REGIONS, MAX_XLAT_TABLES,
45 PLAT_VIRT_ADDR_SPACE_SIZE, PLAT_PHY_ADDR_SPACE_SIZE);
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +000046
47void mmap_add_region(unsigned long long base_pa, uintptr_t base_va,
Sandrine Bailleux04980a32017-04-19 14:02:23 +010048 size_t size, mmap_attr_t attr)
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +000049{
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
59void 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 Diazac998032017-02-27 17:23:54 +000067#if PLAT_XLAT_TABLES_DYNAMIC
68
69int mmap_add_dynamic_region(unsigned long long base_pa,
Sandrine Bailleux04980a32017-04-19 14:02:23 +010070 uintptr_t base_va, size_t size, mmap_attr_t attr)
Antonio Nino Diazac998032017-02-27 17:23:54 +000071{
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
81int 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 Diaz233c7c12017-03-08 14:40:23 +000088void 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 Diazefabaa92017-04-27 13:30:22 +010093 tf_xlat_ctx.execute_never_mask =
94 xlat_arch_get_xn_desc(xlat_arch_current_el());
Antonio Nino Diaz233c7c12017-03-08 14:40:23 +000095 init_xlation_table(&tf_xlat_ctx);
96 xlat_tables_print(&tf_xlat_ctx);
97
Sandrine Bailleux3120ea22017-07-10 13:37:48 +010098 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 Diaz233c7c12017-03-08 14:40:23 +0000100
101 init_xlat_tables_arch(tf_xlat_ctx.max_pa);
102}
103
104#ifdef AARCH32
105
106void enable_mmu_secure(unsigned int flags)
107{
108 enable_mmu_arch(flags, tf_xlat_ctx.base_table);
109}
110
111#else
112
113void enable_mmu_el1(unsigned int flags)
114{
115 enable_mmu_arch(flags, tf_xlat_ctx.base_table);
116}
117
118void enable_mmu_el3(unsigned int flags)
119{
120 enable_mmu_arch(flags, tf_xlat_ctx.base_table);
121}
122
123#endif /* AARCH32 */