1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
3 #include <console/console.h>
4 #include <soc/apusys_devapc.h>
5 #include <soc/devapc.h>
7 static const enum domain_id domain_map
[] = {
8 DOMAIN_0
, DOMAIN_1
, DOMAIN_2
, DOMAIN_3
, DOMAIN_4
, DOMAIN_5
, DOMAIN_6
, DOMAIN_7
,
9 DOMAIN_8
, DOMAIN_9
, DOMAIN_10
, DOMAIN_11
, DOMAIN_12
, DOMAIN_13
, DOMAIN_14
, DOMAIN_15
,
12 #define DAPC_APU_AO_SYS0_ATTR(...) \
15 DAPC_PERM_ATTR_16(__VA_ARGS__) \
18 #define DAPC_APU_NOC_AO_SYS0_ATTR(...) \
21 DAPC_PERM_ATTR_16(__VA_ARGS__) \
26 static const struct apc_apu_dom_16 apusys_noc_dapc
[] = {
28 DAPC_APU_NOC_AO_SYS0_ATTR("slv00-0", NO_PROTECTION
, FORBIDDEN15
),
29 DAPC_APU_NOC_AO_SYS0_ATTR("slv00-1", NO_PROTECTION
, FORBIDDEN15
),
30 DAPC_APU_NOC_AO_SYS0_ATTR("slv00-2", NO_PROTECTION
, FORBIDDEN15
),
31 DAPC_APU_NOC_AO_SYS0_ATTR("slv01-0", NO_PROTECTION
, FORBIDDEN15
),
32 DAPC_APU_NOC_AO_SYS0_ATTR("slv01-1", NO_PROTECTION
, FORBIDDEN15
),
33 DAPC_APU_NOC_AO_SYS0_ATTR("slv01-2", NO_PROTECTION
, FORBIDDEN15
),
34 DAPC_APU_NOC_AO_SYS0_ATTR("slv03-0", NO_PROTECTION
, FORBIDDEN15
),
35 DAPC_APU_NOC_AO_SYS0_ATTR("slv03-1", NO_PROTECTION
, FORBIDDEN15
),
36 DAPC_APU_NOC_AO_SYS0_ATTR("slv03-2", NO_PROTECTION
, FORBIDDEN15
),
37 DAPC_APU_NOC_AO_SYS0_ATTR("slv03-3", NO_PROTECTION
, FORBIDDEN15
),
40 DAPC_APU_NOC_AO_SYS0_ATTR("slv03-4", NO_PROTECTION
, FORBIDDEN15
),
41 DAPC_APU_NOC_AO_SYS0_ATTR("slv04_05_06_07-0", NO_PROTECTION
, FORBIDDEN15
),
42 DAPC_APU_NOC_AO_SYS0_ATTR("slv04_05_06_07-1", NO_PROTECTION
, FORBIDDEN15
),
43 DAPC_APU_NOC_AO_SYS0_ATTR("slv04_05_06_07-2", NO_PROTECTION
, FORBIDDEN15
),
44 DAPC_APU_NOC_AO_SYS0_ATTR("slv04_05_06_07-3", NO_PROTECTION
, FORBIDDEN15
),
46 _Static_assert(ARRAY_SIZE(apusys_noc_dapc
) == APUSYS_NOC_DAPC_AO_SLAVE_NUM
,
47 "Wrong size on apusys_noc_dapc");
50 static const struct apc_apu_dom_16 apusys_ao_apc
[] = {
52 DAPC_APU_AO_SYS0_ATTR("apusys_ao-0", NO_PROTECTION
, FORBIDDEN15
),
53 DAPC_APU_AO_SYS0_ATTR("apusys_ao-1", NO_PROTECTION
, FORBIDDEN15
),
54 DAPC_APU_AO_SYS0_ATTR("apusys_ao-2", SEC_RW_ONLY
, FORBIDDEN15
),
55 DAPC_APU_AO_SYS0_ATTR("apusys_ao-3", NO_PROTECTION
, FORBIDDEN15
),
56 DAPC_APU_AO_SYS0_ATTR("apusys_ao-4", NO_PROTECTION
, FORBIDDEN15
),
57 DAPC_APU_AO_SYS0_ATTR("apusys_ao-5", NO_PROTECTION
, FORBIDDEN15
),
58 DAPC_APU_AO_SYS0_ATTR("apusys_ao-6", NO_PROTECTION
, FORBIDDEN15
),
59 DAPC_APU_AO_SYS0_ATTR("apusys_ao-8", SEC_RW_ONLY
, FORBIDDEN15
),
60 DAPC_APU_AO_SYS0_ATTR("apusys_ao-9", SEC_RW_ONLY
, FORBIDDEN15
),
61 DAPC_APU_AO_SYS0_ATTR("md32_apb_s-0", NO_PROTECTION
, FORBIDDEN15
),
64 DAPC_APU_AO_SYS0_ATTR("md32_apb_s-1", NO_PROTECTION
, FORBIDDEN15
),
65 DAPC_APU_AO_SYS0_ATTR("md32_apb_s-2", NO_PROTECTION
, FORBIDDEN15
),
66 DAPC_APU_AO_SYS0_ATTR("md32_debug_apb", NO_PROTECTION
, FORBIDDEN15
),
67 DAPC_APU_AO_SYS0_ATTR("apu_con2_config", NO_PROTECTION
, FORBIDDEN15
),
68 DAPC_APU_AO_SYS0_ATTR("apu_con1_config", NO_PROTECTION
, FORBIDDEN15
),
69 DAPC_APU_AO_SYS0_ATTR("apu_sctrl_reviscer", SEC_RW_ONLY
, FORBIDDEN15
),
70 DAPC_APU_AO_SYS0_ATTR("apu_sema_stimer", NO_PROTECTION
, FORBIDDEN15
),
71 DAPC_APU_AO_SYS0_ATTR("apu_emi_config", NO_PROTECTION
, FORBIDDEN15
),
72 DAPC_APU_AO_SYS0_ATTR("apu_edma0", NO_PROTECTION
, FORBIDDEN15
),
73 DAPC_APU_AO_SYS0_ATTR("apu_edma1", NO_PROTECTION
, FORBIDDEN15
),
76 DAPC_APU_AO_SYS0_ATTR("apu_cpe_sensor", NO_PROTECTION
, FORBIDDEN15
),
77 DAPC_APU_AO_SYS0_ATTR("apu_cpe_coef", NO_PROTECTION
, FORBIDDEN15
),
78 DAPC_APU_AO_SYS0_ATTR("apu_cpe_ctrl", NO_PROTECTION
, FORBIDDEN15
),
79 DAPC_APU_AO_SYS0_ATTR("apu_sensor_wrp_dla_0", NO_PROTECTION
, FORBIDDEN15
),
80 DAPC_APU_AO_SYS0_ATTR("apu_sensor_wrp_dla_1", NO_PROTECTION
, FORBIDDEN15
),
81 DAPC_APU_AO_SYS0_ATTR("apu_dapc_ao", NO_PROTECTION
, FORBIDDEN15
),
82 DAPC_APU_AO_SYS0_ATTR("apu_dapc", NO_PROTECTION
, FORBIDDEN15
),
83 DAPC_APU_AO_SYS0_ATTR("infra_bcrm", NO_PROTECTION
, FORBIDDEN15
),
84 DAPC_APU_AO_SYS0_ATTR("infra_ao_bcrm", NO_PROTECTION
, FORBIDDEN15
),
85 DAPC_APU_AO_SYS0_ATTR("noc_dapc", NO_PROTECTION
, FORBIDDEN15
),
88 DAPC_APU_AO_SYS0_ATTR("apu_noc_bcrm", NO_PROTECTION
, FORBIDDEN15
),
89 DAPC_APU_AO_SYS0_ATTR("apu_noc_config_0", NO_PROTECTION
, FORBIDDEN
, FORBIDDEN
,
90 NO_PROTECTION
, FORBIDDEN12
),
91 DAPC_APU_AO_SYS0_ATTR("apu_noc_config_1", NO_PROTECTION
, FORBIDDEN
, FORBIDDEN
,
92 NO_PROTECTION
, FORBIDDEN12
),
93 DAPC_APU_AO_SYS0_ATTR("apu_noc_config_2", NO_PROTECTION
, FORBIDDEN
, FORBIDDEN
,
94 NO_PROTECTION
, FORBIDDEN12
),
95 DAPC_APU_AO_SYS0_ATTR("vpu_core0_config-0", NO_PROTECTION
, FORBIDDEN
, FORBIDDEN3
,
96 NO_PROTECTION
, FORBIDDEN3
, FORBIDDEN7
),
97 DAPC_APU_AO_SYS0_ATTR("vpu_core0_config-1", NO_PROTECTION
, FORBIDDEN
, FORBIDDEN3
,
98 NO_PROTECTION
, FORBIDDEN3
, FORBIDDEN7
),
99 DAPC_APU_AO_SYS0_ATTR("vpu_core1_config-0", NO_PROTECTION
, FORBIDDEN
, FORBIDDEN3
,
100 NO_PROTECTION
, FORBIDDEN3
, FORBIDDEN7
),
101 DAPC_APU_AO_SYS0_ATTR("vpu_core1_config-1", NO_PROTECTION
, FORBIDDEN
, FORBIDDEN3
,
102 NO_PROTECTION
, FORBIDDEN3
, FORBIDDEN7
),
103 DAPC_APU_AO_SYS0_ATTR("mdla0_apb-0", NO_PROTECTION
, FORBIDDEN15
),
104 DAPC_APU_AO_SYS0_ATTR("mdla0_apb-1", NO_PROTECTION
, FORBIDDEN15
),
107 DAPC_APU_AO_SYS0_ATTR("mdla0_apb-2", NO_PROTECTION
, FORBIDDEN15
),
108 DAPC_APU_AO_SYS0_ATTR("mdla0_apb-3", NO_PROTECTION
, FORBIDDEN15
),
109 DAPC_APU_AO_SYS0_ATTR("mdla1_apb-0", NO_PROTECTION
, FORBIDDEN15
),
110 DAPC_APU_AO_SYS0_ATTR("mdla1_apb-1", NO_PROTECTION
, FORBIDDEN15
),
111 DAPC_APU_AO_SYS0_ATTR("mdla1_apb-2", NO_PROTECTION
, FORBIDDEN15
),
112 DAPC_APU_AO_SYS0_ATTR("mdla1_apb-3", NO_PROTECTION
, FORBIDDEN15
),
113 DAPC_APU_AO_SYS0_ATTR("apu_iommu0_r0", NO_PROTECTION
, FORBIDDEN15
),
114 DAPC_APU_AO_SYS0_ATTR("apu_iommu0_r1", SEC_RW_ONLY
, FORBIDDEN15
),
115 DAPC_APU_AO_SYS0_ATTR("apu_iommu0_r2", SEC_RW_ONLY
, FORBIDDEN15
),
116 DAPC_APU_AO_SYS0_ATTR("apu_iommu0_r3", SEC_RW_ONLY
, FORBIDDEN15
),
119 DAPC_APU_AO_SYS0_ATTR("apu_iommu0_r4", SEC_RW_ONLY
, FORBIDDEN15
),
120 DAPC_APU_AO_SYS0_ATTR("apu_iommu1_r0", NO_PROTECTION
, FORBIDDEN15
),
121 DAPC_APU_AO_SYS0_ATTR("apu_iommu1_r1", SEC_RW_ONLY
, FORBIDDEN15
),
122 DAPC_APU_AO_SYS0_ATTR("apu_iommu1_r2", SEC_RW_ONLY
, FORBIDDEN15
),
123 DAPC_APU_AO_SYS0_ATTR("apu_iommu1_r3", SEC_RW_ONLY
, FORBIDDEN15
),
124 DAPC_APU_AO_SYS0_ATTR("apu_iommu1_r4", SEC_RW_ONLY
, FORBIDDEN15
),
125 DAPC_APU_AO_SYS0_ATTR("apu_rsi2_config", NO_PROTECTION
, FORBIDDEN15
),
126 DAPC_APU_AO_SYS0_ATTR("apu_s0_ssc_config", NO_PROTECTION
, FORBIDDEN15
),
127 DAPC_APU_AO_SYS0_ATTR("apu_n0_ssc_config", NO_PROTECTION
, FORBIDDEN15
),
128 DAPC_APU_AO_SYS0_ATTR("apu_acp_ssc_config", NO_PROTECTION
, FORBIDDEN15
),
131 DAPC_APU_AO_SYS0_ATTR("apu_s1_ssc_config", NO_PROTECTION
, FORBIDDEN15
),
132 DAPC_APU_AO_SYS0_ATTR("apu_n1_ssc_config", NO_PROTECTION
, FORBIDDEN15
),
133 DAPC_APU_AO_SYS0_ATTR("apu_ao_dbgapb-0", NO_PROTECTION
, FORBIDDEN15
),
134 DAPC_APU_AO_SYS0_ATTR("apu_ao_dbgapb-1", NO_PROTECTION
, FORBIDDEN15
),
135 DAPC_APU_AO_SYS0_ATTR("apu_ao_dbgapb-2", NO_PROTECTION
, FORBIDDEN15
),
136 DAPC_APU_AO_SYS0_ATTR("apu_ao_dbgapb-3", NO_PROTECTION
, FORBIDDEN15
),
137 DAPC_APU_AO_SYS0_ATTR("apu_ao_dbgapb-4", NO_PROTECTION
, FORBIDDEN15
),
138 DAPC_APU_AO_SYS0_ATTR("apu_ao_dbgapb-5", NO_PROTECTION
, FORBIDDEN15
),
139 DAPC_APU_AO_SYS0_ATTR("vpu_core0_debug_apb", NO_PROTECTION
, FORBIDDEN15
),
140 DAPC_APU_AO_SYS0_ATTR("vpu_core1_debug_apb", NO_PROTECTION
, FORBIDDEN15
),
143 DAPC_APU_AO_SYS0_ATTR("apb_infra_dbg_ctl", NO_PROTECTION
, FORBIDDEN15
),
145 _Static_assert(ARRAY_SIZE(apusys_ao_apc
) == APUSYS_APC_SYS0_AO_SLAVE_NUM
,
146 "Wrong size on apusys_ao_apc");
148 static int set_slave_noc_dapc(u32 slave
, enum domain_id domain_id
, enum devapc_perm_type perm
)
150 u32 apc_register_index
;
154 if (perm
>= PERM_NUM
|| perm
< NO_PROTECTION
) {
155 printk(BIOS_ERR
, "[NOC_DAPC] permission type:%#x is not supported!\n", perm
);
156 return APUSYS_APC_ERR_PERMISSION_NOT_SUPPORTED
;
159 if (slave
>= APUSYS_NOC_DAPC_AO_SLAVE_NUM
|| domain_id
>= APUSYS_NOC_DAPC_AO_DOM_NUM
) {
160 printk(BIOS_ERR
, "[NOC_DAPC] %s: %s, %s:%#x, %s:%#x\n", __func__
,
161 "out of boundary", "slave", slave
, "domain_id", domain_id
);
162 return APUSYS_APC_ERR_OUT_OF_BOUNDARY
;
165 apc_register_index
= slave
/ APUSYS_NOC_DAPC_AO_SLAVE_NUM_IN_1_DOM
;
166 apc_set_index
= slave
% APUSYS_NOC_DAPC_AO_SLAVE_NUM_IN_1_DOM
;
167 base
= (void *)((size_t)APUSYS_NOC_DAPC_AO_BASE
+ domain_id
* 0x40 +
168 apc_register_index
* 4);
169 clrsetbits32(base
, 0x3U
<< (apc_set_index
* 2), perm
<< (apc_set_index
* 2));
171 return APUSYS_APC_OK
;
174 static void dump_apusys_noc_dapc(void)
179 reg_num
= DIV_ROUND_UP(ARRAY_SIZE(apusys_noc_dapc
),
180 APUSYS_NOC_DAPC_AO_SLAVE_NUM_IN_1_DOM
);
181 for (d
= 0U; d
< APUSYS_NOC_DAPC_AO_DOM_NUM
; d
++) {
182 for (i
= 0U; i
< reg_num
; i
++)
183 printk(BIOS_DEBUG
, "[NOCDAPC] D%ld_APC_%ld: %#x\n", d
, i
,
184 read32((void *)(APUSYS_NOC_DAPC_AO_BASE
+ d
* 0x40 + i
* 4)));
186 printk(BIOS_DEBUG
, "[NOCDAPC] APC_CON: %#x\n", read32(APUSYS_NOC_DAPC_CON
));
189 static int set_slave_apc(u32 slave
, enum domain_id domain_id
, enum devapc_perm_type perm
)
191 u32 apc_register_index
;
195 if (perm
>= PERM_NUM
|| perm
< NO_PROTECTION
) {
196 printk(BIOS_ERR
, "[APUAPC] perm type:%#x is not supported!\n", perm
);
197 return APUSYS_APC_ERR_PERMISSION_NOT_SUPPORTED
;
200 if (slave
>= APUSYS_APC_SYS0_AO_SLAVE_NUM
|| domain_id
>= APUSYS_APC_SYS0_AO_DOM_NUM
) {
201 printk(BIOS_ERR
, "[APUAPC] %s: %s, %s:%#x, %s:%#x\n", __func__
,
202 "out of boundary", "slave", slave
, "domain_id", domain_id
);
203 return APUSYS_APC_ERR_OUT_OF_BOUNDARY
;
206 apc_register_index
= slave
/ APUSYS_APC_SYS0_AO_SLAVE_NUM_IN_1_DOM
;
207 apc_set_index
= slave
% APUSYS_APC_SYS0_AO_SLAVE_NUM_IN_1_DOM
;
208 base
= (void *)((size_t)APUSYS_APC_AO_BASE
+ domain_id
* 0x40 + apc_register_index
* 4);
210 clrsetbits32(base
, 0x3U
<< (apc_set_index
* 2), perm
<< (apc_set_index
* 2));
212 return APUSYS_APC_OK
;
215 static void dump_apusys_ao_apc(void)
221 DIV_ROUND_UP(ARRAY_SIZE(apusys_ao_apc
), APUSYS_APC_SYS0_AO_SLAVE_NUM_IN_1_DOM
);
222 for (d
= 0U; d
< APUSYS_APC_SYS0_AO_DOM_NUM
; d
++) {
223 for (i
= 0U; i
< reg_num
; i
++)
224 printk(BIOS_DEBUG
, "[APUAPC] D%ld_APC_%ld: %#x\n", d
, i
,
225 read32((void *)(APUSYS_APC_AO_BASE
+ d
* 0x40 + i
* 4)));
227 printk(BIOS_DEBUG
, "[APUAPC] APC_CON: %#x\n", read32(APUSYS_APC_CON
));
230 static int set_apusys_noc_dapc(void)
232 int ret
= APUSYS_APC_OK
;
235 for (i
= 0; i
< ARRAY_SIZE(apusys_noc_dapc
); i
++) {
236 for (j
= 0; j
< ARRAY_SIZE(apusys_noc_dapc
[i
].d_permission
); j
++) {
237 ret
= set_slave_noc_dapc(i
, j
, apusys_noc_dapc
[i
].d_permission
[j
]);
239 printk(BIOS_ERR
, "[APUAPC] fail (%ld, %ld)(%d)!\n", i
, j
, ret
);
246 static int32_t set_apusys_ao_apc(void)
248 int ret
= APUSYS_APC_OK
;
251 for (i
= 0; i
< ARRAY_SIZE(apusys_ao_apc
); i
++) {
252 for (j
= 0; j
< ARRAY_SIZE(apusys_ao_apc
[j
].d_permission
); j
++) {
253 ret
= set_slave_apc(i
, domain_map
[j
], apusys_ao_apc
[i
].d_permission
[j
]);
255 printk(BIOS_ERR
, "[APUAPC] fail (%ld, %ld)(%d)!\n", i
, j
, ret
);
262 void start_apusys_devapc(void)
264 int ret
= APUSYS_APC_OK
;
266 /* Check violation status */
267 printk(BIOS_DEBUG
, "[APUAPC] vio %d\n", read32(APUSYS_APC_CON
) & 0x80000000);
269 /* Initial Permission */
270 ret
= set_apusys_ao_apc();
271 printk(BIOS_DEBUG
, "[APUAPC] %s - %s!\n", "set_apusys_ao_apc",
272 ret
? "FAILED" : "SUCCESS");
275 write32(APUSYS_SYS0_APC_LOCK_0
, APU_SCTRL_REVISER
| DEVAPC_AO_WRAPPER
);
277 /* Initial NoC Permission */
278 ret
= set_apusys_noc_dapc();
279 printk(BIOS_DEBUG
, "[APUAPC] %s - %s!\n", "set_apusys_noc_dapc",
280 ret
? "FAILED" : "SUCCESS");
282 dump_apusys_ao_apc();
283 dump_apusys_noc_dapc();
285 printk(BIOS_DEBUG
, "[APUAPC] %s done\n", __func__
);