1 /*
2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 /***********************************************************************************************************************
8 * Includes <System Includes> , "Project Includes"
9 **********************************************************************************************************************/
10 #include "bsp_api.h"
11 #if (1 == BSP_FEATURE_TZC400_SUPPORTED)
12 #include "bsp_tzc400.h"
13 #endif
14
15 /***********************************************************************************************************************
16 * Macro definitions
17 **********************************************************************************************************************/
18 #if BSP_FEATURE_TZC400_SUPPORTED
19 #if (1 == _RZN_ORDINAL)
20 #define BSP_TZC_400_BASEADRESS (0x81100000)
21 #define BSP_TZC_400_MODULE_OFFSET (uint32_t) (0x1000)
22 #define BSP_TZC_400_REGION_ACTION_OFFSET (uint32_t) (0x004)
23 #define BSP_TZC_400_REGION_SPEC_DISABLEULATION_CTL_OFFSET (uint32_t) (0x00C)
24 #define BSP_TZC_400_REGION_GATEKEEPER_OFFSET (uint32_t) (0x008)
25 #define BSP_TZC_400_REGION_ATTR_N_OFFSET(n) (uint32_t) (0x110 + (0x20 * n))
26 #define BSP_TZC_400_REGION_ID_ACCESS_N_OFFSET(n) (uint32_t) (0x114 + (0x20 * n))
27 #define BSP_TZC_400_NUMBER_SHIFT_NSAID_WR_EN 16U
28 #define BSP_TZC_400_NUMBER_SHIFT_NSAID_RD_EN 0U
29 #define BSP_TZC_400_MAX_MODULE 9U
30 #define BSP_TZC_400_MAX_REGION_SUPPORT 1U
31 #define BSP_TZC_400_MAX_FILTER 4U
32
33 #define BSP_TZC400_REGION(module, region) \
34 { \
35 BSP_CFG_TZC400_ ## module ## _REGION_ID_ACCESS_NSAID_RD_EN_ ## region, \
36 BSP_CFG_TZC400_ ## module ## _REGION_ID_ACCESS_NSAID_WR_EN_ ## region, \
37 BSP_CFG_TZC400_ ## module ## _REGION_ATTR_S_RD_EN_ ## region, \
38 BSP_CFG_TZC400_ ## module ## _REGION_ATTR_S_WR_EN_ ## region, \
39 BSP_CFG_TZC400_ ## module ## _REGION_ATTR_FILTER_UNIT_ ## region, \
40 }
41 #define BSP_TZC400_MODULE(module) \
42 { \
43 BSP_CFG_TZC400_ ## module ## _GATEKEEPER, \
44 BSP_CFG_TZC400_ ## module ## _WRITE_SPEC_DISABLE, \
45 BSP_CFG_TZC400_ ## module ## _READ_SPEC_DISABLE, \
46 { \
47 BSP_TZC400_REGION(module, 0), \
48 } \
49 }
50 #endif
51 #endif
52
53 /***********************************************************************************************************************
54 * Typedef definitions
55 **********************************************************************************************************************/
56 #if BSP_FEATURE_TZC400_SUPPORTED
57 #if (1 == _RZN_ORDINAL)
58 typedef struct st_bsp_tzc400_region_cfg_data
59 {
60 uint16_t id_access_rd_en;
61 uint16_t id_access_wr_en;
62 uint8_t attr_rd_en;
63 uint8_t attr_wr_en;
64 uint8_t attr_filter;
65 } bsp_tzc400_region_cfg_data_t;
66
67 typedef struct st_bsp_tzc400_cfg_data
68 {
69 uint32_t gatekeeper;
70 uint8_t write_spec_disable;
71 uint8_t read_spec_disable;
72
73 bsp_tzc400_region_cfg_data_t region[BSP_TZC_400_MAX_REGION_SUPPORT];
74 } bsp_tzc400_cfg_data_t;
75 #endif
76 #endif
77
78 /***********************************************************************************************************************
79 * Exported global variables (to be accessed by other files)
80 **********************************************************************************************************************/
81
82 /***********************************************************************************************************************
83 * Private global variables and functions
84 **********************************************************************************************************************/
85 #if BSP_FEATURE_TZC400_SUPPORTED
86 #if (1 == _RZN_ORDINAL)
87 static const bsp_tzc400_cfg_data_t g_bsp_tzc_module_cfg_data[] =
88 {
89 BSP_TZC400_MODULE(0),
90 BSP_TZC400_MODULE(1),
91 BSP_TZC400_MODULE(2),
92 BSP_TZC400_MODULE(3),
93 BSP_TZC400_MODULE(4),
94 BSP_TZC400_MODULE(5),
95 BSP_TZC400_MODULE(6),
96 BSP_TZC400_MODULE(7),
97 BSP_TZC400_MODULE(8),
98 };
99
100 /*******************************************************************************************************************//**
101 * Configure TrustedZone 400.
102 * @param[in] None
103 * @param[out] None
104 * @note This function supports configurable the registers of TZC-400.
105 * @retval None
106 **********************************************************************************************************************/
bsp_tzc_400_cfg(void)107 void bsp_tzc_400_cfg (void)
108 {
109 /* Initialize local variable */
110 uint8_t tzc400module;
111 uintptr_t basetzc400;
112 volatile uint32_t * p_reg;
113
114 /* Loop all modules of TZC400 */
115 for (tzc400module = 0; tzc400module < BSP_TZC_400_MAX_MODULE; tzc400module++)
116 {
117 /* Get base address of each module */
118 basetzc400 = (uintptr_t) (BSP_TZC_400_BASEADRESS + (BSP_TZC_400_MODULE_OFFSET * tzc400module));
119
120 /* Setting for GATE_KEEPER */
121 p_reg = (uint32_t *) (basetzc400 + BSP_TZC_400_REGION_GATEKEEPER_OFFSET);
122 *p_reg = g_bsp_tzc_module_cfg_data[tzc400module].gatekeeper;
123
124 /* Setting for SPECULATION_CTRL */
125 p_reg = (uint32_t *) (basetzc400 + BSP_TZC_400_REGION_SPEC_DISABLEULATION_CTL_OFFSET);
126 *p_reg = (uint32_t) ((g_bsp_tzc_module_cfg_data[tzc400module].write_spec_disable << 1) |
127 (g_bsp_tzc_module_cfg_data[tzc400module].read_spec_disable << 0));
128
129 /* Setting attribute for region 0 only as BSP_TZC_400_MAX_REGION_SUPPORT */
130 p_reg = (uint32_t *) (basetzc400 + BSP_TZC_400_REGION_ATTR_N_OFFSET(0));
131 *p_reg = (uint32_t) ((g_bsp_tzc_module_cfg_data[tzc400module].region[0].attr_rd_en << 30) |
132 (g_bsp_tzc_module_cfg_data[tzc400module].region[0].attr_wr_en << 31) |
133 (g_bsp_tzc_module_cfg_data[tzc400module].region[0].attr_filter));
134
135 /* Setting id access for region 0 only as BSP_TZC_400_MAX_REGION_SUPPORT */
136 p_reg = (uint32_t *) (basetzc400 + BSP_TZC_400_REGION_ID_ACCESS_N_OFFSET(0));
137 *p_reg =
138 (uint32_t) ((g_bsp_tzc_module_cfg_data[tzc400module].region[0].id_access_rd_en <<
139 BSP_TZC_400_NUMBER_SHIFT_NSAID_RD_EN) |
140 (g_bsp_tzc_module_cfg_data[tzc400module].region[0].id_access_wr_en <<
141 BSP_TZC_400_NUMBER_SHIFT_NSAID_WR_EN));
142 }
143 }
144
145 #endif
146 #endif
147