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 #else
25 register_phys_mem(MEM_AREA_IO_SEC, TZASC2_BASE, TZASC_SIZE);
26 #endif
27 
28 register_phys_mem(MEM_AREA_IO_SEC, TZASC_BASE, TZASC_SIZE);
29 
imx_configure_tzasc(void)30 static TEE_Result imx_configure_tzasc(void)
31 {
32 	vaddr_t addr[2] = {0};
33 	int end = 1;
34 	int i = 0;
35 
36 	addr[0] = core_mmu_get_va(TZASC_BASE, MEM_AREA_IO_SEC, 1);
37 
38 	if (IS_ENABLED(CFG_MX6Q) || IS_ENABLED(CFG_MX6D) ||
39 	    IS_ENABLED(CFG_MX6DL)) {
40 		assert(TZASC2_BASE != 0);
41 		addr[1] = core_mmu_get_va(TZASC2_BASE, MEM_AREA_IO_SEC, 1);
42 		end = 2;
43 	}
44 
45 	for (i = 0; i < end; i++) {
46 		uint8_t region = 1;
47 
48 		tzc_init(addr[i]);
49 
50 		region = tzc_auto_configure(CFG_DRAM_BASE, CFG_DDR_SIZE,
51 			     TZC_ATTR_SP_NS_RW, region);
52 		region = tzc_auto_configure(CFG_TZDRAM_START, CFG_TZDRAM_SIZE,
53 			     TZC_ATTR_SP_S_RW, region);
54 		region = tzc_auto_configure(CFG_SHMEM_START, CFG_SHMEM_SIZE,
55 			     TZC_ATTR_SP_ALL, region);
56 		tzc_dump_state();
57 
58 		if (tzc_regions_lockdown() != TEE_SUCCESS)
59 			panic("Region lockdown failed!");
60 
61 		tzc_dump_state();
62 	}
63 	return TEE_SUCCESS;
64 }
65 driver_init(imx_configure_tzasc);
66