1 /*
2 * Copyright (c) 2022, MediaTek Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <assert.h>
8 #include <common/bl_common.h>
9 #include <common/debug.h>
10 #include <drivers/console.h>
11 #include <lib/xlat_tables/xlat_tables_compat.h>
12 #include <mtk_mmap_pool.h>
13
14 IMPORT_SYM(uintptr_t, __MTK_MMAP_POINTER_POOL_START__, MTK_MMAP_POINTER_POOL_START);
15 IMPORT_SYM(uintptr_t, __MTK_MMAP_POINTER_POOL_END_UNALIGNED__, MTK_MMAP_POINTER_POOL_END_UNALIGNED);
16 IMPORT_SYM(uintptr_t, __RW_START__, RW_START);
17 IMPORT_SYM(uintptr_t, __DATA_START__, DATA_START);
18
19 #define MAP_MTK_SECTIONS MAP_REGION_FLAT(RW_START, \
20 DATA_START - RW_START, \
21 MT_MEMORY | MT_RO | MT_SECURE)
22
23
print_mmap(const mmap_region_t * regions)24 static void print_mmap(const mmap_region_t *regions)
25 {
26 while (regions->size != 0U) {
27 VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
28 regions->base_va,
29 regions->base_va + regions->size,
30 regions->attr);
31 regions++;
32 }
33 }
34
mtk_xlat_init(const mmap_region_t * bl_regions)35 void mtk_xlat_init(const mmap_region_t *bl_regions)
36 {
37 struct mtk_mmap_descriptor *iter;
38 const mmap_region_t *regions = bl_regions;
39
40 print_mmap(regions);
41 mmap_add(bl_regions);
42 if (MTK_MMAP_POINTER_POOL_START != MTK_MMAP_POINTER_POOL_END_UNALIGNED) {
43 for (iter = (struct mtk_mmap_descriptor *)MTK_MMAP_POINTER_POOL_START;
44 (char *)iter < (char *)MTK_MMAP_POINTER_POOL_END_UNALIGNED;
45 iter++) {
46 regions = iter->mmap_ptr;
47 INFO("mmap_name: %s\n", iter->mmap_name);
48 INFO("mmap_size: 0x%x\n", iter->mmap_size);
49 print_mmap(regions);
50 mmap_add(regions);
51 }
52 }
53 init_xlat_tables();
54 enable_mmu_el3(0);
55 }
56