AM64x MCU+ SDK  09.02.01
firewall/v0/firewall.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022-23 Texas Instruments Incorporated
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the
14  * distribution.
15  *
16  * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
49 #ifndef FIREWALL_H_
50 #define FIREWALL_H_
51 
52 /* ========================================================================== */
53 /* Include Files */
54 /* ========================================================================== */
55 
56 #include <stdint.h>
57 #include <string.h>
58 #include <drivers/soc.h>
59 #include <kernel/dpl/HwiP.h>
60 #include <kernel/dpl/SemaphoreP.h>
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 /* ========================================================================== */
67 /* Macros & Typedefs */
68 /* ========================================================================== */
69 
73 #define FWL_MAX_PRIVID_SLOTS (3U)
74 
78 #define FWL_MAX_ID (35U)
79 #define FWL_MAX_REGION (16U)
80 
89 #define PRIVID_NONE (0U)
90 #define PRIVID_ALLOW_EVERYONE (195U)
91 #define PRIVID_DMSC (202U)
92 #define PRIVID_BLOCK_EVERYONE (197U)
93 #define PRIVID_SPROXY_PRIVATE (11U)
94 #define PRIVID_A53_NON_SECURE (1U)
95 #define PRIVID_A53_SECURE (1U)
96 #define PRIVID_M4_0_NON_SECURE (100U)
97 #define PRIVID_MAIN_0_R5_0_NONSECURE (212U)
98 #define PRIVID_MAIN_0_R5_0_SECURE (212U)
99 #define PRIVID_MAIN_0_R5_1_NONSECURE (213U)
100 #define PRIVID_MAIN_0_R5_1_SECURE (213U)
101 #define PRIVID_MAIN_1_R5_0_NONSECURE (214U)
102 #define PRIVID_MAIN_1_R5_0_SECURE (214U)
103 #define PRIVID_MAIN_1_R5_1_NONSECURE (215U)
104 #define PRIVID_MAIN_1_R5_1_SECURE (215U)
105 #define PRIVID_MAIN_0_ICSSG_0 (136U)
106 
116 #define FWL_CONTROL_ENABLE_MASK (0xFU)
117 #define FWL_CONTROL_DISABLE (0x0U)
118 #define FWL_CONTROL_ENABLE (0xAU)
119 #define FWL_CONTROL_LOCK (0x10U)
120 #define FWL_CONTROL_BG (0x100U)
121 #define FWL_CONTROL_CACHE_MODE (0x200U)
122 
132 #define FWL_PERM_SEC_MASK (0x00FFU)
133 #define FWL_PERM_NSEC_MASK (0xFF00U)
134 #define FWL_PERM_PRIV_MASK (0x0F0FU)
135 #define FWL_PERM_USER_MASK (0xF0F0U)
136 
137 #define FWL_PERM_WRITE_MASK (0x1111U)
138 #define FWL_PERM_READ_MASK (0x2222U)
139 #define FWL_PERM_CACHE_MASK (0x4444U)
140 #define FWL_PERM_DEBUG_MASK (0x8888U)
141 #define FWL_PERM_DENY_ALL (0x0000U)
142 
152 #define FWL_PERM_RW_ALL (FWL_PERM_WRITE_MASK | \
153  FWL_PERM_READ_MASK | \
154  FWL_PERM_CACHE_MASK | \
155  FWL_PERM_DEBUG_MASK)
156 
157 #define FWL_PERM_RO_ALL (FWL_PERM_READ_MASK | \
158  FWL_PERM_CACHE_MASK | \
159  FWL_PERM_DEBUG_MASK)
160 
161 #define FWL_PERM_WO_ALL (FWL_PERM_WRITE_MASK | \
162  FWL_PERM_CACHE_MASK | \
163  FWL_PERM_DEBUG_MASK)
164 
165 #define FWL_PERM_SEC_RW (FWL_PERM_SEC_MASK & \
166  FWL_PERM_RW_ALL)
167 
168 #define FWL_PERM_NSEC_RW (FWL_PERM_NSEC_MASK & \
169  FWL_PERM_RW_ALL)
170 
171 #define FWL_PERM_PRIV_RW (FWL_PERM_PRIV_MASK & \
172  FWL_PERM_RW_ALL)
173 
174 #define FWL_PERM_USER_RW (FWL_PERM_USER_MASK & \
175  FWL_PERM_RW_ALL)
176 
177 #define FWL_PERM_SEC_RO (FWL_PERM_SEC_MASK & \
178  FWL_PERM_RO_ALL)
179 
180 #define FWL_PERM_NSEC_RO (FWL_PERM_NSEC_MASK & \
181  FWL_PERM_RO_ALL)
182 
183 #define FWL_PERM_PRIV_RO (FWL_PERM_PRIV_MASK & \
184  FWL_PERM_RO_ALL)
185 
186 #define FWL_PERM_USER_RO (FWL_PERM_USER_MASK & \
187  FWL_PERM_RO_ALL)
188 
190 /* ========================================================================== */
191 /* Structure Definitions */
192 /* ========================================================================== */
193 
194 
199 typedef struct
200 {
202  uint16_t regionIndex;
204  uint32_t control;
208  uint64_t startAddr;
210  uint64_t endAddr;
212 
221 typedef struct {
222  /* Id of Firewall to be used */
223  uint32_t firewallId;
224  /* Number of regions in the firewall */
225  uint32_t totalRegions;
226  /* Number of regions initialized */
227  uint32_t initRegions;
228  /* Region configuration */
231 
232 
236 typedef void *Firewall_Handle;
237 
241 typedef struct
242 {
246  uint32_t cfgDone;
248 
253 typedef struct
254 {
259 
261 
262 /* ========================================================================== */
263 /* Function Declarations */
264 /* ========================================================================== */
265 
269 void Firewall_init(void);
270 
274 void Firewall_deinit(void);
275 
286 
295 
305 
314 
315 
316 
317 #ifdef __cplusplus
318 }
319 #endif
320 
321 #endif /* #ifndef FIREWALL_H_ */
322 
Firewall_RegionCfg::endAddr
uint64_t endAddr
Definition: firewall/v0/firewall.h:210
Firewall_Attrs::totalRegions
uint32_t totalRegions
Definition: firewall/v0/firewall.h:225
Firewall_RegionCfg::control
uint32_t control
Definition: firewall/v0/firewall.h:204
Firewall_Attrs
Firewall atributes.
Definition: firewall/v0/firewall.h:221
Firewall_Config
Firewall Instance Configuration. Pointer to this object is returned as handle by driver open.
Definition: firewall/v0/firewall.h:254
FWL_MAX_PRIVID_SLOTS
#define FWL_MAX_PRIVID_SLOTS
Maximun number of privilege ID slots.
Definition: firewall/v0/firewall.h:73
Firewall_init
void Firewall_init(void)
This function initializes the firewall module.
Firewall_RegionCfg
Firewall Region Cfg specifies the MMR configuration for the specified firewall ID.
Definition: firewall/v0/firewall.h:200
SemaphoreP.h
Firewall_RegionCfg::startAddr
uint64_t startAddr
Definition: firewall/v0/firewall.h:208
Firewall_Object
Firewall driver Object.
Definition: firewall/v0/firewall.h:242
Firewall_Attrs::firewallId
uint32_t firewallId
Definition: firewall/v0/firewall.h:223
Firewall_Object::handle
Firewall_Handle handle
Definition: firewall/v0/firewall.h:244
HwiP.h
Firewall_configureSingleRegion
int32_t Firewall_configureSingleRegion(uint32_t firewallId, Firewall_RegionCfg *region)
Configure firewall for a single region.
region
uint16_t region
Definition: tisci_firewall.h:2
Firewall_open
int32_t Firewall_open(Firewall_Handle handle)
This function opens a given Firewall peripheral.
Firewall_Attrs::regionInfo
Firewall_RegionCfg * regionInfo
Definition: firewall/v0/firewall.h:229
Firewall_configureRegion
int32_t Firewall_configureRegion(Firewall_Handle handle)
Intialize a firewall with multiple regions.
Firewall_deinit
void Firewall_deinit(void)
This function de-initializes the firewall module.
Firewall_Attrs::initRegions
uint32_t initRegions
Definition: firewall/v0/firewall.h:227
Firewall_close
void Firewall_close(Firewall_Handle handle)
Function to close Firewall peripheral specified by firewall handle.
Firewall_Config::attrs
Firewall_Attrs * attrs
Definition: firewall/v0/firewall.h:256
permissions
uint32_t permissions[FWL_MAX_PRIVID_SLOTS]
Definition: tisci_firewall.h:5
Firewall_RegionCfg::regionIndex
uint16_t regionIndex
Definition: firewall/v0/firewall.h:202
Firewall_Config::object
Firewall_Object * object
Definition: firewall/v0/firewall.h:258
Firewall_Handle
void * Firewall_Handle
A handle that is initialized in Firewall_open() call.
Definition: firewall/v0/firewall.h:236
Firewall_Object::cfgDone
uint32_t cfgDone
Definition: firewall/v0/firewall.h:246