1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright (C) 2020 Pengutronix
4  * Rouven Czerwinski <entwicklung@pengutronix.de>
5  */
6 
7 #include <io.h>
8 #include <drivers/imx_snvs.h>
9 #include <mm/core_memprot.h>
10 #include <mm/core_mmu.h>
11 #include <stdint.h>
12 #include <types_ext.h>
13 #include <trace.h>
14 
snvs_get_security_cfg(void)15 enum snvs_security_cfg snvs_get_security_cfg(void)
16 {
17 	vaddr_t snvs = core_mmu_get_va(SNVS_BASE, MEM_AREA_IO_SEC,
18 				       SNVS_HPSR + sizeof(uint32_t));
19 	uint32_t val = 0;
20 
21 	val = io_read32(snvs + SNVS_HPSR);
22 	DMSG("HPSR: 0x%"PRIx32, val);
23 	if (val & SNVS_HPSR_SYS_SECURITY_BAD)
24 		return SNVS_SECURITY_CFG_FIELD_RETURN;
25 	else if (val & SNVS_HPSR_SYS_SECURITY_CLOSED)
26 		return SNVS_SECURITY_CFG_CLOSED;
27 	else if (val & SNVS_HPSR_SYS_SECURITY_OPEN)
28 		return SNVS_SECURITY_CFG_OPEN;
29 	else if (val > 4 && val < 8)
30 		return SNVS_SECURITY_CFG_OPEN;
31 
32 	return SNVS_SECURITY_CFG_FAB;
33 }
34 
snvs_get_ssm_mode(void)35 enum snvs_ssm_mode snvs_get_ssm_mode(void)
36 {
37 	vaddr_t snvs = core_mmu_get_va(SNVS_BASE, MEM_AREA_IO_SEC,
38 				       SNVS_HPSR + sizeof(uint32_t));
39 	uint32_t val = 0;
40 
41 	val = io_read32(snvs + SNVS_HPSR);
42 	val &= HPSR_SSM_ST_MASK;
43 	val = val >> HPSR_SSM_ST_SHIFT;
44 	DMSG("HPSR: SSM ST Mode: 0x%01"PRIx32, val);
45 	return val;
46 }
47