xref: /rk3399_ARM-atf/plat/ti/k3low/common/drivers/firewall/firewall_config.c (revision e6c3260a923ec2107894bae056cca7c9043d8a67)
1 /*
2  * Copyright (c) 2026, Texas Instruments Inc. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <common/debug.h>
8 #include <ti_sci.h>
9 #include <ti_sci_protocol.h>
10 
11 #include "firewall.h"
12 
13 const struct fwl_data fwls[] = {
14 	{OSPI_FWL_ID, OSPI_FWL_REGION},		/* OSPI */
15 	{ADC_MCASP_FWL_ID, ADC_MCASP_FWL_REGION},/* ADC and MCASP */
16 	{DDR_FWL_ID, DDR_BG_FWL_REGION},	/* DDR */
17 };
18 
19 /*
20  * Take ownership and set the configuration for a given firewall ID and region.
21  * Function arguments are same as those which will be passed to
22  * ti_sci_set_fwl_region()
23  */
add_fwl_configs(const uint16_t fwl_id,const uint16_t region,const uint32_t n_perm_regs,const uint32_t control,const uint32_t permissions[FWL_MAX_PRIVID_SLOTS],const uint64_t start_address,const uint64_t end_address)24 static void add_fwl_configs(const uint16_t fwl_id, const uint16_t region,
25 			    const uint32_t n_perm_regs, const uint32_t control,
26 			    const uint32_t permissions[FWL_MAX_PRIVID_SLOTS],
27 			    const uint64_t start_address, const uint64_t end_address)
28 {
29 	uint8_t owner_index = TFA_HOST_ID;
30 	uint8_t owner_privid = A53_PRIV_ID;
31 	uint16_t owner_permission_bits = 0;
32 	int ret = 0;
33 
34 	ret = ti_sci_change_fwl_owner(fwl_id, region, owner_index,
35 				      &owner_privid, &owner_permission_bits);
36 	if (ret) {
37 		ERROR("Could not change firewall owner (%d)\n", ret);
38 		panic();
39 	}
40 
41 	ret = ti_sci_set_fwl_region(fwl_id, region, n_perm_regs,
42 				    control, permissions,
43 				    start_address, end_address);
44 	if (ret) {
45 		ERROR("Could not set firewall region (%d)\n", ret);
46 		panic();
47 	}
48 }
49 
update_fwl_configs(void)50 void update_fwl_configs(void)
51 {
52 	uint32_t permissions[3] = {FWL_PERM_ALL_RW, FWL_PERM_ALL_RW, FWL_PERM_ALL_RW};
53 
54 	/* Open up firewalls that were configured by ROM for boot phase */
55 	for (int i = 0; i < ARRAY_SIZE(fwls); i++) {
56 		add_fwl_configs(fwls[i].fwl_id, fwls[i].region, FWL_MAX_PRIVID_SLOTS,
57 				FWL_CTRL_EN_BG, permissions, 0x0, 0xFFFFFFFFF);
58 	}
59 }
60