1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright 2019 Pengutronix
4 * All rights reserved.
5 *
6 * Rouven Czerwinski <entwicklung@pengutronix.de>
7 */
8
9 #include <config.h>
10 #include <drivers/tzc380.h>
11 #include <imx-regs.h>
12 #include <initcall.h>
13 #include <kernel/panic.h>
14 #include <mm/core_memprot.h>
15 #include <mm/generic_ram_layout.h>
16
17 /*
18 * TZASC2_BASE is asserted non null when used.
19 * This is needed to compile the code for i.MX6UL/L
20 * and i.MX8MQ.
21 */
22 #ifndef TZASC2_BASE
23 #define TZASC2_BASE 0
24 #endif
25
imx_configure_tzasc(void)26 static TEE_Result imx_configure_tzasc(void)
27 {
28 vaddr_t addr[2] = {0};
29 int end = 1;
30 int i = 0;
31
32 addr[0] = core_mmu_get_va(TZASC_BASE, MEM_AREA_IO_SEC, 1);
33
34 if (IS_ENABLED(CFG_MX6Q) || IS_ENABLED(CFG_MX6D) ||
35 IS_ENABLED(CFG_MX6DL)) {
36 assert(TZASC2_BASE != 0);
37 addr[1] = core_mmu_get_va(TZASC2_BASE, MEM_AREA_IO_SEC, 1);
38 end = 2;
39 }
40
41 for (i = 0; i < end; i++) {
42 uint8_t region = 1;
43
44 tzc_init(addr[i]);
45
46 region = tzc_auto_configure(CFG_DRAM_BASE, CFG_DDR_SIZE,
47 TZC_ATTR_SP_NS_RW, region);
48 region = tzc_auto_configure(CFG_TZDRAM_START, CFG_TZDRAM_SIZE,
49 TZC_ATTR_SP_S_RW, region);
50 region = tzc_auto_configure(CFG_SHMEM_START, CFG_SHMEM_SIZE,
51 TZC_ATTR_SP_ALL, region);
52 tzc_dump_state();
53 if (tzc_regions_lockdown() != TEE_SUCCESS)
54 panic("Region lockdown failed!");
55 }
56 return TEE_SUCCESS;
57 }
58 driver_init(imx_configure_tzasc);
59