|
|
|
/*
|
xlat v2: Split MMU setup and enable
At present, the function provided by the translation library to enable
MMU constructs appropriate values for translation library, and programs
them to the right registers. The construction of initial values,
however, is only required once as both the primary and secondaries
program the same values.
Additionally, the MMU-enabling function is written in C, which means
there's an active stack at the time of enabling MMU. On some systems,
like Arm DynamIQ, having active stack while enabling MMU during warm
boot might lead to coherency problems.
This patch addresses both the above problems by:
- Splitting the MMU-enabling function into two: one that sets up
values to be programmed into the registers, and another one that
takes the pre-computed values and writes to the appropriate
registers. With this, the primary effectively calls both functions
to have the MMU enabled, but secondaries only need to call the
latter.
- Rewriting the function that enables MMU in assembly so that it
doesn't use stack.
This patch fixes a bunch of MISRA issues on the way.
Change-Id: I0faca97263a970ffe765f0e731a1417e43fbfc45
Signed-off-by: Jeenu Viswambharan <jeenu.viswambharan@arm.com>
7 years ago
|
|
|
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This header file contains internal definitions that are not supposed to be
|
|
|
|
* used outside of this library code.
|
|
|
|
*/
|
|
|
|
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
#ifndef XLAT_TABLES_V2_HELPERS_H
|
|
|
|
#define XLAT_TABLES_V2_HELPERS_H
|
|
|
|
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
#ifndef XLAT_TABLES_V2_H
|
|
|
|
#error "Do not include this header file directly. Include xlat_tables_v2.h instead."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __ASSEMBLER__
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
|
|
|
#include <platform_def.h>
|
|
|
|
|
|
|
|
#include <lib/cassert.h>
|
|
|
|
#include <lib/xlat_tables/xlat_tables_arch.h>
|
|
|
|
#include <lib/xlat_tables/xlat_tables_defs.h>
|
|
|
|
|
|
|
|
/* Forward declaration */
|
|
|
|
struct mmap_region;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper macro to define an mmap_region_t. This macro allows to specify all
|
|
|
|
* the fields of the structure but its parameter list is not guaranteed to
|
|
|
|
* remain stable as we add members to mmap_region_t.
|
|
|
|
*/
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
#define MAP_REGION_FULL_SPEC(_pa, _va, _sz, _attr, _gr) \
|
|
|
|
{ \
|
|
|
|
.base_pa = (_pa), \
|
|
|
|
.base_va = (_va), \
|
|
|
|
.size = (_sz), \
|
|
|
|
.attr = (_attr), \
|
|
|
|
.granularity = (_gr), \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Struct that holds all information about the translation tables. */
|
|
|
|
struct xlat_ctx {
|
|
|
|
/*
|
|
|
|
* Max allowed Virtual and Physical Addresses.
|
|
|
|
*/
|
|
|
|
unsigned long long pa_max_address;
|
|
|
|
uintptr_t va_max_address;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Array of all memory regions stored in order of ascending end address
|
|
|
|
* and ascending size to simplify the code that allows overlapping
|
|
|
|
* regions. The list is terminated by the first entry with size == 0.
|
|
|
|
* The max size of the list is stored in `mmap_num`. `mmap` points to an
|
|
|
|
* array of mmap_num + 1 elements, so that there is space for the final
|
|
|
|
* null entry.
|
|
|
|
*/
|
|
|
|
struct mmap_region *mmap;
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
int mmap_num;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Array of finer-grain translation tables.
|
|
|
|
* For example, if the initial lookup level is 1 then this array would
|
|
|
|
* contain both level-2 and level-3 entries.
|
|
|
|
*/
|
|
|
|
uint64_t (*tables)[XLAT_TABLE_ENTRIES];
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
int tables_num;
|
|
|
|
/*
|
|
|
|
* Keep track of how many regions are mapped in each table. The base
|
|
|
|
* table can't be unmapped so it isn't needed to keep track of it.
|
|
|
|
*/
|
|
|
|
#if PLAT_XLAT_TABLES_DYNAMIC
|
|
|
|
int *tables_mapped_regions;
|
|
|
|
#endif /* PLAT_XLAT_TABLES_DYNAMIC */
|
|
|
|
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
int next_table;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Base translation table. It doesn't need to have the same amount of
|
|
|
|
* entries as the ones used for other levels.
|
|
|
|
*/
|
|
|
|
uint64_t *base_table;
|
|
|
|
unsigned int base_table_entries;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Max Physical and Virtual addresses currently in use by the
|
|
|
|
* translation tables. These might get updated as we map/unmap memory
|
|
|
|
* regions but they will never go beyond pa/va_max_address.
|
|
|
|
*/
|
|
|
|
unsigned long long max_pa;
|
|
|
|
uintptr_t max_va;
|
|
|
|
|
|
|
|
/* Level of the base translation table. */
|
|
|
|
unsigned int base_level;
|
|
|
|
|
|
|
|
/* Set to true when the translation tables are initialized. */
|
|
|
|
bool initialized;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Translation regime managed by this xlat_ctx_t. It should be one of
|
|
|
|
* the EL*_REGIME defines.
|
|
|
|
*/
|
|
|
|
int xlat_regime;
|
|
|
|
};
|
|
|
|
|
|
|
|
#if PLAT_XLAT_TABLES_DYNAMIC
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
#define XLAT_ALLOC_DYNMAP_STRUCT(_ctx_name, _xlat_tables_count) \
|
|
|
|
static int _ctx_name##_mapped_regions[_xlat_tables_count];
|
|
|
|
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
#define XLAT_REGISTER_DYNMAP_STRUCT(_ctx_name) \
|
|
|
|
.tables_mapped_regions = _ctx_name##_mapped_regions,
|
|
|
|
#else
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
#define XLAT_ALLOC_DYNMAP_STRUCT(_ctx_name, _xlat_tables_count) \
|
|
|
|
/* do nothing */
|
|
|
|
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
#define XLAT_REGISTER_DYNMAP_STRUCT(_ctx_name) \
|
|
|
|
/* do nothing */
|
|
|
|
#endif /* PLAT_XLAT_TABLES_DYNAMIC */
|
|
|
|
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
#define REGISTER_XLAT_CONTEXT_FULL_SPEC(_ctx_name, _mmap_count, \
|
|
|
|
_xlat_tables_count, _virt_addr_space_size, \
|
|
|
|
_phy_addr_space_size, _xlat_regime, _section_name)\
|
|
|
|
CASSERT(CHECK_PHY_ADDR_SPACE_SIZE(_phy_addr_space_size), \
|
|
|
|
assert_invalid_physical_addr_space_sizefor_##_ctx_name);\
|
|
|
|
\
|
|
|
|
static mmap_region_t _ctx_name##_mmap[_mmap_count + 1]; \
|
|
|
|
\
|
|
|
|
static uint64_t _ctx_name##_xlat_tables[_xlat_tables_count] \
|
|
|
|
[XLAT_TABLE_ENTRIES] \
|
|
|
|
__aligned(XLAT_TABLE_SIZE) __section(_section_name); \
|
|
|
|
\
|
|
|
|
static uint64_t _ctx_name##_base_xlat_table \
|
|
|
|
[GET_NUM_BASE_LEVEL_ENTRIES(_virt_addr_space_size)] \
|
|
|
|
__aligned(GET_NUM_BASE_LEVEL_ENTRIES(_virt_addr_space_size)\
|
|
|
|
* sizeof(uint64_t)); \
|
|
|
|
\
|
|
|
|
XLAT_ALLOC_DYNMAP_STRUCT(_ctx_name, _xlat_tables_count) \
|
|
|
|
\
|
|
|
|
static xlat_ctx_t _ctx_name##_xlat_ctx = { \
|
|
|
|
.va_max_address = (_virt_addr_space_size) - 1UL, \
|
|
|
|
.pa_max_address = (_phy_addr_space_size) - 1ULL, \
|
|
|
|
.mmap = _ctx_name##_mmap, \
|
|
|
|
.mmap_num = (_mmap_count), \
|
|
|
|
.base_level = GET_XLAT_TABLE_LEVEL_BASE(_virt_addr_space_size),\
|
|
|
|
.base_table = _ctx_name##_base_xlat_table, \
|
|
|
|
.base_table_entries = \
|
|
|
|
GET_NUM_BASE_LEVEL_ENTRIES(_virt_addr_space_size),\
|
|
|
|
.tables = _ctx_name##_xlat_tables, \
|
|
|
|
.tables_num = _xlat_tables_count, \
|
|
|
|
XLAT_REGISTER_DYNMAP_STRUCT(_ctx_name) \
|
|
|
|
.xlat_regime = (_xlat_regime), \
|
|
|
|
.max_pa = 0U, \
|
|
|
|
.max_va = 0U, \
|
|
|
|
.next_table = 0, \
|
|
|
|
.initialized = false, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /*__ASSEMBLER__*/
|
xlat v2: Split MMU setup and enable
At present, the function provided by the translation library to enable
MMU constructs appropriate values for translation library, and programs
them to the right registers. The construction of initial values,
however, is only required once as both the primary and secondaries
program the same values.
Additionally, the MMU-enabling function is written in C, which means
there's an active stack at the time of enabling MMU. On some systems,
like Arm DynamIQ, having active stack while enabling MMU during warm
boot might lead to coherency problems.
This patch addresses both the above problems by:
- Splitting the MMU-enabling function into two: one that sets up
values to be programmed into the registers, and another one that
takes the pre-computed values and writes to the appropriate
registers. With this, the primary effectively calls both functions
to have the MMU enabled, but secondaries only need to call the
latter.
- Rewriting the function that enables MMU in assembly so that it
doesn't use stack.
This patch fixes a bunch of MISRA issues on the way.
Change-Id: I0faca97263a970ffe765f0e731a1417e43fbfc45
Signed-off-by: Jeenu Viswambharan <jeenu.viswambharan@arm.com>
7 years ago
|
|
|
|
xlat: Fix MISRA defects
Fix defects of MISRA C-2012 rules 8.13, 10.1, 10.3, 10.4, 10.8, 11.6,
14.4, 15.7, 17.8, 20.10, 20.12, 21.1 and Directive 4.9.
Change-Id: I7ff61e71733908596dbafe2e99d99b4fce9765bd
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
6 years ago
|
|
|
#endif /* XLAT_TABLES_V2_HELPERS_H */
|