1 /*
2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
3 * Copyright 2016-2020, 2023 NXP
4 * All rights reserved.
5 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9 #ifndef FSL_XRDC_H_
10 #define FSL_XRDC_H_
11
12 #include "fsl_common.h"
13
14 /*!
15 * @addtogroup xrdc
16 * @{
17 */
18
19 /******************************************************************************
20 * Definitions
21 *****************************************************************************/
22 #define FSL_XRDC_DRIVER_VERSION (MAKE_VERSION(2, 0, 5))
23
24 #ifndef FSL_CLOCK_XRDC_GATE_COUNT
25 #define FSL_CLOCK_XRDC_GATE_COUNT 1U
26 #endif
27
28 /*! @brief XRDC status _xrdc_status. */
29 enum
30 {
31 kStatus_XRDC_NoError = MAKE_STATUS(kStatusGroup_XRDC, 0) /*!< No error captured. */
32 };
33
34 /*!
35 * @brief XRDC hardware configuration.
36 */
37 typedef struct _xrdc_hardware_config
38 {
39 uint8_t masterNumber; /*!< Number of bus masters. */
40 uint8_t domainNumber; /*!< Number of domains. */
41 uint8_t pacNumber; /*!< Number of PACs. */
42 uint8_t mrcNumber; /*!< Number of MRCs. */
43 } xrdc_hardware_config_t;
44
45 /*!
46 * @brief XRDC PID enable mode, the register bit XRDC_MDA_Wx[PE], used for domain hit evaluation.
47 */
48 typedef enum _xrdc_pid_enable
49 {
50 kXRDC_PidDisable, /*!< PID is not used in domain hit evalution. */
51 kXRDC_PidDisable1, /*!< PID is not used in domain hit evalution. */
52 kXRDC_PidExp0, /*!< ((XRDC_MDA_W[PID] & ~XRDC_MDA_W[PIDM]) == (XRDC_PID[PID] & ~XRDC_MDA_W[PIDM])). */
53 kXRDC_PidExp1 /*!< ~((XRDC_MDA_W[PID] & ~XRDC_MDA_W[PIDM]) == (XRDC_PID[PID] & ~XRDC_MDA_W[PIDM])). */
54 } xrdc_pid_enable_t;
55
56 /*!
57 * @brief XRDC domain ID select method, the register bit XRDC_MDA_Wx[DIDS], used for
58 * domain hit evaluation.
59 */
60 typedef enum _xrdc_did_sel
61 {
62 kXRDC_DidMda, /*!< Use MDAn[3:0] as DID. */
63 kXRDC_DidInput, /*!< Use the input DID (DID_in) as DID. */
64 kXRDC_DidMdaAndInput, /*!< Use MDAn[3:2] concatenated with DID_in[1:0] as DID. */
65 kXRDC_DidReserved /*!< Reserved. */
66 } xrdc_did_sel_t;
67
68 /*!
69 * @brief XRDC secure attribute, the register bit XRDC_MDA_Wx[SA], used for non-processor
70 * bus master domain assignment.
71 */
72 typedef enum _xrdc_secure_attr
73 {
74 kXRDC_ForceSecure, /*!< Force the bus attribute for this master to secure. */
75 kXRDC_ForceNonSecure, /*!< Force the bus attribute for this master to non-secure. */
76 kXRDC_MasterSecure, /*!< Use the bus master's secure/nonsecure attribute directly. */
77 kXRDC_MasterSecure1, /*!< Use the bus master's secure/nonsecure attribute directly. */
78 } xrdc_secure_attr_t;
79
80 /*!
81 * @brief XRDC privileged attribute, the register bit XRDC_MDA_Wx[PA], used for non-processor
82 * bus master domain assignment.
83 */
84 typedef enum _xrdc_privilege_attr
85 {
86 kXRDC_ForceUser, /*!< Force the bus attribute for this master to user. */
87 kXRDC_ForcePrivilege, /*!< Force the bus attribute for this master to privileged. */
88 kXRDC_MasterPrivilege, /*!< Use the bus master's attribute directly. */
89 kXRDC_MasterPrivilege1, /*!< Use the bus master's attribute directly. */
90 } xrdc_privilege_attr_t;
91
92 /*!
93 * @brief Domain assignment for the processor bus master.
94 */
95 typedef struct _xrdc_processor_domain_assignment
96 {
97 uint32_t domainId : 4U; /*!< Domain ID. */
98 uint32_t domainIdSelect : 2U; /*!< Domain ID select method, see @ref xrdc_did_sel_t. */
99 uint32_t pidEnable : 2U; /*!< PId enable method, see @ref xrdc_pid_enable_t. */
100 uint32_t pidMask : 6U; /*!< PId mask. */
101 uint32_t : 2U; /*!< Reserved. */
102 uint32_t pid : 6U; /*!< PId value. */
103 uint32_t : 2U; /*!< Reserved. */
104 #if !(defined(FSL_FEATURE_XRDC_NO_MDA_LPID) && FSL_FEATURE_XRDC_NO_MDA_LPID)
105 uint32_t logicPartId : 4U; /*!< Logical partition ID. */
106 #else
107 uint32_t : 4U; /*!< Reserved. */
108 #endif
109 #if !(defined(FSL_FEATURE_XRDC_NO_MDA_LPE) && FSL_FEATURE_XRDC_NO_MDA_LPE)
110 uint32_t enableLogicPartId : 1U; /*!< Logical partition ID. */
111 #else
112 uint32_t : 1U; /*!< Reserved. */
113 #endif /* FSL_FEATURE_XRDC_NO_MDA_LPE */
114 uint32_t : 1U; /*!< Reserved. */
115 uint32_t lock : 1U; /*!< Lock the register. */
116 uint32_t : 1U; /*!< Reserved. */
117 } xrdc_processor_domain_assignment_t;
118
119 /*!
120 * @brief Domain assignment for the non-processor bus master.
121 */
122 typedef struct _xrdc_non_processor_domain_assignment
123 {
124 uint32_t domainId : 4U; /*!< Domain ID. */
125 uint32_t privilegeAttr : 2U; /*!< Privileged attribute, see @ref xrdc_privilege_attr_t. */
126 uint32_t secureAttr : 2U; /*!< Secure attribute, see @ref xrdc_secure_attr_t. */
127 uint32_t bypassDomainId : 1U; /*!< Bypass domain ID. */
128 uint32_t : 15U; /*!< Reserved. */
129 #if !(defined(FSL_FEATURE_XRDC_NO_MDA_LPID) && FSL_FEATURE_XRDC_NO_MDA_LPID)
130 uint32_t logicPartId : 4U; /*!< Logical partition ID. */
131 #else
132 uint32_t : 4U; /*!< Reserved. */
133 #endif
134 #if !(defined(FSL_FEATURE_XRDC_NO_MDA_LPE) && FSL_FEATURE_XRDC_NO_MDA_LPE)
135 uint32_t enableLogicPartId : 1U; /*!< Enable logical partition ID. */
136 #else
137 uint32_t : 1U; /*!< Reserved. */
138 #endif
139 uint32_t : 1U; /*!< Reserved. */
140 uint32_t lock : 1U; /*!< Lock the register. */
141 uint32_t : 1U; /*!< Reserved. */
142 } xrdc_non_processor_domain_assignment_t;
143
144 /*!
145 * @brief XRDC PID LK2 definition XRDC_PIDn[LK2]
146 */
147 typedef enum _xrdc_pid_lock
148 {
149 kXRDC_PidLockSecurePrivilegeWritable = 0U, /*!< Writable by any secure privileged write. */
150 kXRDC_PidLockSecurePrivilegeWritable1 = 1U, /*!< Writable by any secure privileged write. */
151 kXRDC_PidLockMasterXOnly = 2U, /*!< PIDx is only writable by master x. */
152 kXRDC_PidLockLocked = 3U /*!< Read-only until the next reset. */
153 } xrdc_pid_lock_t;
154
155 /*!
156 * @brief XRDC process identifier (PID) configuration.
157 */
158 typedef struct _xrdc_pid_config
159 {
160 uint32_t pid : 6U; /*!< PID value, PIDn[PID]. */
161 #if (defined(FSL_FEATURE_XRDC_HAS_PID_SP4SM) && FSL_FEATURE_XRDC_HAS_PID_SP4SM)
162 uint32_t : 21U; /*!< Reserved. */
163 uint32_t sp4smEnable : 1U; /*!< Enable special 4-state model. */
164 #else
165 uint32_t : 22U; /*!< Reserved. */
166 #endif
167 uint32_t tsmEnable : 1U; /*!< Enable three-state model. */
168 uint32_t lockMode : 2U; /*!< PIDn configuration lock mode, see @ref xrdc_pid_lock_t. */
169 uint32_t : 1U; /*!< Reserved. */
170 } xrdc_pid_config_t;
171
172 /*!
173 * @brief XRDC domain access control policy.
174 */
175 typedef enum _xrdc_access_policy
176 {
177 /* policy SecurePriv SecureUser NonSecurePriv NonSecureUsr*/
178 kXRDC_AccessPolicyNone = 0U, /* 000 none none none none */
179 kXRDC_AccessPolicySpuR = 1U, /* 001 r r none none */
180 kXRDC_AccessPolicySpRw = 2U, /* 010 r,w none none none */
181 kXRDC_AccessPolicySpuRw = 3U, /* 011 r,w r,w none none */
182 kXRDC_AccessPolicySpuRwNpR = 4U, /* 100 r,w r,w r none */
183 kXRDC_AccessPolicySpuRwNpuR = 5U, /* 101 r,w r,w r r */
184 kXRDC_AccessPolicySpuRwNpRw = 6U, /* 110 r,w r,w r,w none */
185 kXRDC_AccessPolicyAll = 7U /* 111 r,w r,w r,w r,w */
186 } xrdc_access_policy_t;
187
188 /*!
189 * @brief Access configuration lock mode, the register field PDAC and MRGD LK2.
190 */
191 typedef enum _xrdc_access_config_lock
192 {
193 kXRDC_AccessConfigLockWritable = 0U, /*!< Entire PDACn/MRGDn can be written. */
194 kXRDC_AccessConfigLockWritable1 = 1U, /*!< Entire PDACn/MRGDn can be written. */
195 kXRDC_AccessConfigLockDomainXOnly = 2U, /*!< Domain x only write the DxACP field. */
196 kXRDC_AccessConfigLockLocked = 3U /*!< PDACn is read-only until the next reset. */
197 } xrdc_access_config_lock_t;
198
199 #if (defined(FSL_FEATURE_XRDC_HAS_PDAC_EAL) && FSL_FEATURE_XRDC_HAS_PDAC_EAL) || \
200 (defined(FSL_FEATURE_XRDC_HAS_MRGD_EAL) && FSL_FEATURE_XRDC_HAS_MRGD_EAL)
201 /*!
202 * @brief Exclusive access lock mode configuration, the register field PDAC and MRGD EAL.
203 */
204 typedef enum _xrdc_excl_access_lock_config
205 {
206 kXRDC_ExclAccessLockDisabled = 0U, /*!< Lock disabled. */
207 kXRDC_ExclAccessLockDisabledUntilNextRst = 1U, /*!< Lock disabled until next reset. */
208 kXRDC_ExclAccessLockEnabledStateAvail = 2U, /*!< Lock enabled, lock state = available. */
209 kXRDC_ExclAccessLockEnabledStateNotAvail = 3U /*!< Lock enabled, lock state = not available. */
210 } xrdc_excl_access_lock_config_t;
211 #endif
212
213 /*!
214 * @brief XRDC peripheral domain access control configuration.
215 */
216 typedef struct _xrdc_periph_access_config
217 {
218 xrdc_periph_t periph; /*!< Peripheral name. */
219 xrdc_access_config_lock_t lockMode; /*!< PDACn lock configuration. */
220 #if !(defined(FSL_FEATURE_XRDC_NO_PDAC_SE) && FSL_FEATURE_XRDC_NO_PDAC_SE)
221 bool enableSema; /*!< Enable semaphore or not. */
222 uint32_t semaNum; /*!< Semaphore number. */
223 #endif
224 #if (defined(FSL_FEATURE_XRDC_HAS_PDAC_EAL) && FSL_FEATURE_XRDC_HAS_PDAC_EAL)
225 xrdc_excl_access_lock_config_t exclAccessLockMode; /*!< Exclusive access lock configuration. */
226 #endif
227 xrdc_access_policy_t policy[FSL_FEATURE_XRDC_DOMAIN_COUNT]; /*!< Access policy for each domain. */
228 } xrdc_periph_access_config_t;
229
230 #if !(defined(FSL_FEATURE_XRDC_NO_MRGD_SZ) && FSL_FEATURE_XRDC_NO_MRGD_SZ)
231 /*!
232 * @brief XRDC memory size definition.
233 */
234 typedef enum _xrdc_mem_size
235 {
236 kXRDC_MemSizeNone = 0U, /*!< None size. */
237 kXRDC_MemSize32B = 4U, /*!< 2^(4+1) = 32 */
238 kXRDC_MemSize64B = 5U, /*!< 2^(5+1) = 64 */
239 kXRDC_MemSize128B = 6U, /*!< 2^(6+1) = 128 */
240 kXRDC_MemSize256B = 7U, /*!< 2^(7+1) = 256 */
241 kXRDC_MemSize512B = 8U, /*!< 2^(8+1) = 512 */
242 kXRDC_MemSize1K = 9U, /*!< 2^(9+1) = 1kB */
243 kXRDC_MemSize2K = 10U, /*!< 2^(10+1) = 2kB */
244 kXRDC_MemSize4K = 11U, /*!< 2^(11+1) = 4kB */
245 kXRDC_MemSize8K = 12U, /*!< 2^(12+1) = 8kB */
246 kXRDC_MemSize16K = 13U, /*!< 2^(13+1) = 16kB */
247 kXRDC_MemSize32K = 14U, /*!< 2^(14+1) = 32kB */
248 kXRDC_MemSize64K = 15U, /*!< 2^(15+1) = 64kB */
249 kXRDC_MemSize128K = 16U, /*!< 2^(16+1) = 128kB */
250 kXRDC_MemSize256K = 17U, /*!< 2^(17+1) = 256kB */
251 kXRDC_MemSize512K = 18U, /*!< 2^(18+1) = 512kB */
252 kXRDC_MemSize1M = 19U, /*!< 2^(19+1) = 1MB */
253 kXRDC_MemSize2M = 20U, /*!< 2^(20+1) = 2MB */
254 kXRDC_MemSize4M = 21U, /*!< 2^(21+1) = 4MB */
255 kXRDC_MemSize8M = 22U, /*!< 2^(22+1) = 8MB */
256 kXRDC_MemSize16M = 23U, /*!< 2^(23+1) = 16MB */
257 kXRDC_MemSize32M = 24U, /*!< 2^(24+1) = 32MB */
258 kXRDC_MemSize64M = 25U, /*!< 2^(25+1) = 64MB */
259 kXRDC_MemSize128M = 26U, /*!< 2^(26+1) = 128MB */
260 kXRDC_MemSize256M = 27U, /*!< 2^(27+1) = 256MB */
261 kXRDC_MemSize512M = 28U, /*!< 2^(28+1) = 512MB */
262 kXRDC_MemSize1G = 29U, /*!< 2^(29+1) = 1GB */
263 kXRDC_MemSize2G = 30U, /*!< 2^(30+1) = 2GB */
264 kXRDC_MemSize4G = 31U /*!< 2^(31+1) = 4GB */
265 } xrdc_mem_size_t;
266 #endif /* FSL_FEATURE_XRDC_NO_MRGD_SZ */
267
268 #if (defined(FSL_FEATURE_XRDC_HAS_MRGD_ACCSET) && FSL_FEATURE_XRDC_HAS_MRGD_ACCSET)
269 /*!
270 * @brief XRDC memory ACCSET (SET of programmable access flags).
271 */
272 typedef enum _xrdc_mem_accset
273 {
274 kXRDC_MemAccset1 = 0U, /*!< Memory region SET 1 of programmable access flags. */
275 kXRDC_MemAccset2 = 1U, /*!< Memory region SET 2 of programmable access flags. */
276 } xrdc_mem_accset_t;
277 #endif /* FSL_FEATURE_XRDC_HAS_MRGD_ACCSET */
278
279 #if (defined(FSL_FEATURE_XRDC_HAS_MRGD_CR) && FSL_FEATURE_XRDC_HAS_MRGD_CR)
280 /*!
281 * @brief XRDC memory code region indicator.
282 */
283 typedef enum _xrdc_mem_code_region
284 {
285 kXRDC_MemCodeRegion0 = 0U, /*!< Code region indicator 0=data. */
286 kXRDC_MemCodeRegion1 = 1U, /*!< Code region indicator 1=code. */
287 } xrdc_mem_code_region_t;
288 #endif /* FSL_FEATURE_XRDC_HAS_MRGD_CR */
289
290 #if (defined(FSL_FEATURE_XRDC_HAS_MRGD_DXSEL) && FSL_FEATURE_XRDC_HAS_MRGD_DXSEL)
291 /*!
292 * @brief XRDC domain access flags/policy select.
293 *
294 * Policy:
295 * {R,W,X} Read, write, execute flags.
296 * flag = 0 : inhibits access, flag = 1 : allows access.
297 * policy => SecurePriv_NonSecurePriv_SecureUser_NonSecureUsr
298 * xxx_xxx_xxx_xxx => PS{R,W,X}_PN{R,W,X}_US{R,W,X}_UN{R,W,X}
299 *
300 * PS > PN > US > UN PS > PN > US > UN
301 * DxSEL CodeRegion = 0 CodeRegion = 1
302 * 000 000_000_000_000 = 0x000 000_000_000_000 = 0x000
303 * 001 ACCSET1
304 * 010 ACCSET2
305 * 011 110_000_000_000 = 0xC00 001_001_001_001 = 0x249
306 * 100 110_110_000_000 = 0xD80 111_000_000_000 = 0xE00
307 * 101 110_110_100_100 = 0xDA4 110_111_000_000 = 0xDC0
308 * 110 110_110_110_000 = 0xDB0 110_110_111_000 = 0xDB8
309 * 111 110_110_110_110 = 0xDB6 110_110_111_111 = 0xDBF
310 */
311 typedef enum _xrdc_access_flags_select
312 {
313 kXRDC_AccessFlagsNone = 0U, /* Select predefined constant {r,w,x} flags. See the table above. */
314 kXRDC_AccessFlagsAlt1 = 1U, /* Select ACCSET1 4*{r,w,x} fully‐programmable access flags. */
315 kXRDC_AccessFlagsAlt2 = 2U, /* Select ACCSET2 4*{r,w,x} fully‐programmable access flags. */
316 kXRDC_AccessFlagsAlt3 = 3U, /* Select predefined constant {r,w,x} flags. See the table above. */
317 kXRDC_AccessFlagsAlt4 = 4U, /* Select predefined constant {r,w,x} flags. See the table above. */
318 kXRDC_AccessFlagsAlt5 = 5U, /* Select predefined constant {r,w,x} flags. See the table above. */
319 kXRDC_AccessFlagsAlt6 = 6U, /* Select predefined constant {r,w,x} flags. See the table above. */
320 kXRDC_AccessFlagsAlt7 = 7U /* Select predefined constant {r,w,x} flags. See the table above. */
321 } xrdc_access_flags_select_t;
322 #endif /* FSL_FEATURE_XRDC_HAS_MRGD_DXSEL */
323
324 /*!
325 * @brief XRDC memory region domain access control configuration.
326 */
327 typedef struct _xrdc_mem_access_config
328 {
329 xrdc_mem_t mem; /*!< Memory region descriptor name. */
330 #if !(defined(FSL_FEATURE_XRDC_NO_MRGD_SE) && FSL_FEATURE_XRDC_NO_MRGD_SE)
331 bool enableSema; /*!< Enable semaphore or not. */
332 uint8_t semaNum; /*!< Semaphore number. */
333 #endif
334 #if !(defined(FSL_FEATURE_XRDC_NO_MRGD_SZ) && FSL_FEATURE_XRDC_NO_MRGD_SZ)
335 xrdc_mem_size_t size; /*!< Memory region size. */
336 #endif
337 #if !(defined(FSL_FEATURE_XRDC_NO_MRGD_SRD) && FSL_FEATURE_XRDC_NO_MRGD_SRD)
338 uint8_t subRegionDisableMask; /*!< Sub-region disable mask. */
339 #endif
340
341 #if (defined(FSL_FEATURE_XRDC_HAS_MRGD_ACCSET) && FSL_FEATURE_XRDC_HAS_MRGD_ACCSET)
342 bool enableAccset1Lock; /*!< Enable ACCSET1 access lock or not. */
343 bool enableAccset2Lock; /*!< Enable ACCSET2 access lock or not. */
344 uint16_t accset1; /*!< SET 1 of Programmable access flags.
345 xxx_xxx_xxx_xxx => PS{R,W,X}_PN{R,W,X}_US{R,W,X}_UN{R,W,X}.
346 flag = 0 : inhibits access, flag = 1 : allows access. */
347 uint16_t accset2; /*!< SET 2 of Programmable access flags.
348 xxx_xxx_xxx_xxx => PS{R,W,X}_PN{R,W,X}_US{R,W,X}_UN{R,W,X}.
349 flag = 0 : inhibits access, flag = 1 : allows access. */
350 #endif
351 xrdc_access_config_lock_t lockMode; /*!< MRGDn lock configuration. */
352
353 #if !(defined(FSL_FEATURE_XRDC_NO_MRGD_DXACP) && FSL_FEATURE_XRDC_NO_MRGD_DXACP)
354 xrdc_access_policy_t policy[FSL_FEATURE_XRDC_DOMAIN_COUNT]; /*!< Access policy for each domain. */
355 #elif (defined(FSL_FEATURE_XRDC_HAS_MRGD_DXSEL) && FSL_FEATURE_XRDC_HAS_MRGD_DXSEL)
356 xrdc_access_flags_select_t
357 policy[FSL_FEATURE_XRDC_DOMAIN_COUNT]; /*!< Access policy/flags select for each domain. */
358 #endif
359
360 #if (defined(FSL_FEATURE_XRDC_HAS_MRGD_CR) && FSL_FEATURE_XRDC_HAS_MRGD_CR)
361 xrdc_mem_code_region_t codeRegion; /*!< Code region select. @ref xrdc_mem_code_region_t. */
362 #endif
363
364 uint32_t baseAddress; /*!< Memory region base/start address. */
365 #if (defined(FSL_FEATURE_XRDC_HAS_MRGD_ENDADDR) && FSL_FEATURE_XRDC_HAS_MRGD_ENDADDR)
366 uint32_t endAddress; /*!< Memory region end address. The 5 LSB of end address
367 is ignored and forced to 0x1F by hardware. */
368 #endif
369 #if (defined(FSL_FEATURE_XRDC_HAS_MRGD_EAL) && FSL_FEATURE_XRDC_HAS_MRGD_EAL)
370 xrdc_excl_access_lock_config_t exclAccessLockMode; /*!< Exclusive access lock configuration. */
371 #endif
372 } xrdc_mem_access_config_t;
373
374 /*!
375 * @brief XRDC controller definition for domain error check.
376 */
377 typedef enum _xrdc_controller
378 {
379 kXRDC_MemController0 = 0U, /*!< Memory region controller 0. */
380 kXRDC_MemController1 = 1U, /*!< Memory region controller 1. */
381 kXRDC_MemController2 = 2U, /*!< Memory region controller 2. */
382 kXRDC_MemController3 = 3U, /*!< Memory region controller 3. */
383 kXRDC_MemController4 = 4U, /*!< Memory region controller 4. */
384 kXRDC_MemController5 = 5U, /*!< Memory region controller 5. */
385 kXRDC_MemController6 = 6U, /*!< Memory region controller 6. */
386 kXRDC_MemController7 = 7U, /*!< Memory region controller 7. */
387 kXRDC_MemController8 = 8U, /*!< Memory region controller 8. */
388 kXRDC_MemController9 = 9U, /*!< Memory region controller 9. */
389 kXRDC_MemController10 = 10U, /*!< Memory region controller 10. */
390 kXRDC_MemController11 = 11U, /*!< Memory region controller 11. */
391 kXRDC_MemController12 = 12U, /*!< Memory region controller 12. */
392 kXRDC_MemController13 = 13U, /*!< Memory region controller 13. */
393 kXRDC_MemController14 = 14U, /*!< Memory region controller 14. */
394 kXRDC_MemController15 = 15U, /*!< Memory region controller 15. */
395 kXRDC_PeriphController0 = 16U, /*!< Peripheral access controller 0. */
396 kXRDC_PeriphController1 = 17U, /*!< Peripheral access controller 1. */
397 kXRDC_PeriphController2 = 18U, /*!< Peripheral access controller 2. */
398 kXRDC_PeriphController3 = 19U, /*!< Peripheral access controller 3. */
399 } xrdc_controller_t;
400
401 /*!
402 * @brief XRDC domain error state definition XRDC_DERR_W1_n[EST].
403 */
404 typedef enum _xrdc_error_state
405 {
406 kXRDC_ErrorStateNone = 0x00U, /*!< No access violation detected. */
407 kXRDC_ErrorStateNone1 = 0x01U, /*!< No access violation detected. */
408 kXRDC_ErrorStateSingle = 0x02U, /*!< Single access violation detected. */
409 kXRDC_ErrorStateMulti = 0x03U /*!< Multiple access violation detected. */
410 } xrdc_error_state_t;
411
412 /*!
413 * @brief XRDC domain error attribute definition XRDC_DERR_W1_n[EATR].
414 */
415 typedef enum _xrdc_error_attr
416 {
417 kXRDC_ErrorSecureUserInst = 0x00U, /*!< Secure user mode, instruction fetch access. */
418 kXRDC_ErrorSecureUserData = 0x01U, /*!< Secure user mode, data access. */
419 kXRDC_ErrorSecurePrivilegeInst = 0x02U, /*!< Secure privileged mode, instruction fetch access. */
420 kXRDC_ErrorSecurePrivilegeData = 0x03U, /*!< Secure privileged mode, data access. */
421 kXRDC_ErrorNonSecureUserInst = 0x04U, /*!< NonSecure user mode, instruction fetch access. */
422 kXRDC_ErrorNonSecureUserData = 0x05U, /*!< NonSecure user mode, data access. */
423 kXRDC_ErrorNonSecurePrivilegeInst = 0x06U, /*!< NonSecure privileged mode, instruction fetch access. */
424 kXRDC_ErrorNonSecurePrivilegeData = 0x07U /*!< NonSecure privileged mode, data access. */
425 } xrdc_error_attr_t;
426
427 /*!
428 * @brief XRDC domain error access type definition XRDC_DERR_W1_n[ERW].
429 */
430 typedef enum _xrdc_error_type
431 {
432 kXRDC_ErrorTypeRead = 0x00U, /*!< Error occurs on read reference. */
433 kXRDC_ErrorTypeWrite = 0x01U /*!< Error occurs on write reference. */
434 } xrdc_error_type_t;
435
436 /*!
437 * @brief XRDC domain error definition.
438 */
439 typedef struct _xrdc_error
440 {
441 xrdc_controller_t controller; /*!< Which controller captured access violation. */
442 uint32_t address; /*!< Access address that generated access violation. */
443 xrdc_error_state_t errorState; /*!< Error state. */
444 xrdc_error_attr_t errorAttr; /*!< Error attribute. */
445 xrdc_error_type_t errorType; /*!< Error type. */
446 uint8_t errorPort; /*!< Error port. */
447 uint8_t domainId; /*!< Domain ID. */
448 } xrdc_error_t;
449
450 /*******************************************************************************
451 * API
452 ******************************************************************************/
453
454 #if defined(__cplusplus)
455 extern "C" {
456 #endif
457
458 /*!
459 * @brief Initializes the XRDC module.
460 *
461 * This function enables the XRDC clock.
462 *
463 * @param base XRDC peripheral base address.
464 */
465 void XRDC_Init(XRDC_Type *base);
466
467 /*!
468 * @brief De-initializes the XRDC module.
469 *
470 * This function disables the XRDC clock.
471 *
472 * @param base XRDC peripheral base address.
473 */
474 void XRDC_Deinit(XRDC_Type *base);
475
476 /*!
477 * @name XRDC manager (XRDC_MGR)
478 * @{
479 */
480
481 /*!
482 * @brief Gets the XRDC hardware configuration.
483 *
484 * This function gets the XRDC hardware configurations, including number of bus
485 * masters, number of domains, number of MRCs and number of PACs.
486 *
487 * @param base XRDC peripheral base address.
488 * @param config Pointer to the structure to get the configuration.
489 */
490 void XRDC_GetHardwareConfig(XRDC_Type *base, xrdc_hardware_config_t *config);
491
492 /*!
493 * @brief Locks the XRDC global control register XRDC_CR.
494 *
495 * This function locks the XRDC_CR register. After it is locked, the register is
496 * read-only until the next reset.
497 *
498 * @param base XRDC peripheral base address.
499 */
XRDC_LockGlobalControl(XRDC_Type * base)500 static inline void XRDC_LockGlobalControl(XRDC_Type *base)
501 {
502 base->CR |= XRDC_CR_LK1_MASK;
503 }
504
505 /*!
506 * @brief Sets the XRDC global valid.
507 *
508 * This function sets the XRDC global valid or invalid. When the XRDC is global
509 * invalid, all accesses from all bus masters to all slaves are allowed.
510 *
511 * @param base XRDC peripheral base address.
512 * @param valid True to valid XRDC.
513 */
XRDC_SetGlobalValid(XRDC_Type * base,bool valid)514 static inline void XRDC_SetGlobalValid(XRDC_Type *base, bool valid)
515 {
516 if (valid)
517 {
518 #if (defined(FSL_FEATURE_XRDC_HAS_NO_CR_GVLD) && FSL_FEATURE_XRDC_HAS_NO_CR_GVLD)
519 base->CR |= (XRDC_CR_GVLDM_MASK | XRDC_CR_GVLDC_MASK | XRDC_CR_GVLDP_MASK);
520 #else
521 base->CR |= XRDC_CR_GVLD_MASK;
522 #endif
523 }
524 else
525 {
526 #if (defined(FSL_FEATURE_XRDC_HAS_NO_CR_GVLD) && FSL_FEATURE_XRDC_HAS_NO_CR_GVLD)
527 base->CR &= ~(XRDC_CR_GVLDM_MASK | XRDC_CR_GVLDC_MASK | XRDC_CR_GVLDP_MASK);
528 #else
529 base->CR &= ~XRDC_CR_GVLD_MASK;
530 #endif
531 }
532 }
533
534 /*!
535 * @brief Gets the domain ID of the current bus master.
536 *
537 * This function returns the domain ID of the current bus master.
538 *
539 * @param base XRDC peripheral base address.
540 * @return Domain ID of current bus master.
541 */
XRDC_GetCurrentMasterDomainId(XRDC_Type * base)542 static inline uint8_t XRDC_GetCurrentMasterDomainId(XRDC_Type *base)
543 {
544 return (uint8_t)((base->HWCFG1 & XRDC_HWCFG1_DID_MASK) >> XRDC_HWCFG1_DID_SHIFT);
545 }
546
547 /*!
548 * @brief Gets and clears the first domain error of the current domain.
549 *
550 * This function gets the first access violation information for the current domain
551 * and clears the pending flag. There might be multiple access violations pending
552 * for the current domain. This function only processes the first error.
553 *
554 * @param base XRDC peripheral base address.
555 * @param error Pointer to the error information.
556 * @return If the access violation is captured, this function returns the kStatus_Success.
557 * The error information can be obtained from the parameter error. If no
558 * access violation is captured, this function returns the kStatus_XRDC_NoError.
559 */
560 status_t XRDC_GetAndClearFirstDomainError(XRDC_Type *base, xrdc_error_t *error);
561
562 /*!
563 * @brief Gets and clears the first domain error of the specific domain.
564 *
565 * This function gets the first access violation information for the specific domain
566 * and clears the pending flag. There might be multiple access violations pending
567 * for the current domain. This function only processes the first error.
568 *
569 * @param base XRDC peripheral base address.
570 * @param error Pointer to the error information.
571 * @param domainId The error of which domain to get and clear.
572 * @return If the access violation is captured, this function returns the kStatus_Success.
573 * The error information can be obtained from the parameter error. If no
574 * access violation is captured, this function returns the kStatus_XRDC_NoError.
575 */
576 status_t XRDC_GetAndClearFirstSpecificDomainError(XRDC_Type *base, xrdc_error_t *error, uint8_t domainId);
577
578 /*! @} */
579
580 /*!
581 * @name XRDC Master Domain Assignment Controller (XRDC_MDAC).
582 * @{
583 */
584
585 /*!
586 * @brief Gets the default PID configuration structure.
587 *
588 * This function initializes the configuration structure to default values. The default
589 * values are:
590 *
591 * @code
592 * config->pid = 0U;
593 * config->tsmEnable = 0U;
594 * config->sp4smEnable = 0U;
595 * config->lockMode = kXRDC_PidLockSecurePrivilegeWritable;
596 * @endcode
597 *
598 * @param config Pointer to the configuration structure.
599 */
600 void XRDC_GetPidDefaultConfig(xrdc_pid_config_t *config);
601
602 /*!
603 * @brief Configures the PID for a specific bus master.
604 *
605 * This function configures the PID for a specific bus master. Do not use this
606 * function for non-processor bus masters.
607 *
608 * @param base XRDC peripheral base address.
609 * @param master Which bus master to configure.
610 * @param config Pointer to the configuration structure.
611 */
612 void XRDC_SetPidConfig(XRDC_Type *base, xrdc_master_t master, const xrdc_pid_config_t *config);
613
614 /*!
615 * @brief Sets the PID configuration register lock mode.
616 *
617 * This function sets the PID configuration register lock XRDC_PIDn[LK2].
618 *
619 * @param base XRDC peripheral base address.
620 * @param master Which master's PID to lock.
621 * @param lockMode Lock mode to set.
622 */
XRDC_SetPidLockMode(XRDC_Type * base,xrdc_master_t master,xrdc_pid_lock_t lockMode)623 static inline void XRDC_SetPidLockMode(XRDC_Type *base, xrdc_master_t master, xrdc_pid_lock_t lockMode)
624 {
625 uint32_t reg = base->PID[master];
626
627 reg = ((reg & ~XRDC_PID_LK2_MASK) | XRDC_PID_LK2(lockMode));
628
629 base->PID[master] = reg;
630 }
631
632 /*!
633 * @brief Gets the default master domain assignment for non-processor bus master.
634 *
635 * This function gets the default master domain assignment for non-processor bus master.
636 * It should only be used for the non-processor bus masters, such as DMA. This function
637 * sets the assignment as follows:
638 *
639 * @code
640 * assignment->domainId = 0U;
641 * assignment->privilegeAttr = kXRDC_ForceUser;
642 * assignment->privilegeAttr = kXRDC_ForceSecure;
643 * assignment->bypassDomainId = 0U;
644 * assignment->blogicPartId = 0U;
645 * assignment->benableLogicPartId = 0U;
646 * assignment->lock = 0U;
647 * @endcode
648 *
649 * @param domainAssignment Pointer to the assignment structure.
650 */
651 void XRDC_GetDefaultNonProcessorDomainAssignment(xrdc_non_processor_domain_assignment_t *domainAssignment);
652
653 /*!
654 * @brief Gets the default master domain assignment for the processor bus master.
655 *
656 * This function gets the default master domain assignment for the processor bus master.
657 * It should only be used for the processor bus masters, such as CORE0. This function
658 * sets the assignment as follows:
659 *
660 * @code
661 * assignment->domainId = 0U;
662 * assignment->domainIdSelect = kXRDC_DidMda;
663 * assignment->dpidEnable = kXRDC_PidDisable;
664 * assignment->pidMask = 0U;
665 * assignment->pid = 0U;
666 * assignment->logicPartId = 0U;
667 * assignment->enableLogicPartId = 0U;
668 * assignment->lock = 0U;
669 * @endcode
670 *
671 * @param domainAssignment Pointer to the assignment structure.
672 */
673 void XRDC_GetDefaultProcessorDomainAssignment(xrdc_processor_domain_assignment_t *domainAssignment);
674
675 /*!
676 * @brief Sets the non-processor bus master domain assignment.
677 *
678 * This function sets the non-processor master domain assignment as valid.
679 * One bus master might have multiple domain assignment registers. The parameter
680 * \p assignIndex specifies which assignment register to set.
681 *
682 * Example: Set domain assignment for DMA0.
683 * @code
684 * xrdc_non_processor_domain_assignment_t nonProcessorAssignment;
685 *
686 * XRDC_GetDefaultNonProcessorDomainAssignment(&nonProcessorAssignment);
687 * nonProcessorAssignment.domainId = 1;
688 * nonProcessorAssignment.xxx = xxx;
689 *
690 * XRDC_SetMasterDomainAssignment(XRDC, kXrdcMasterDma0, 0U, &nonProcessorAssignment);
691 * @endcode
692 *
693 * @param base XRDC peripheral base address.
694 * @param master Which master to configure.
695 * @param assignIndex Which assignment register to set.
696 * @param domainAssignment Pointer to the assignment structure.
697 */
698 void XRDC_SetNonProcessorDomainAssignment(XRDC_Type *base,
699 xrdc_master_t master,
700 uint8_t assignIndex,
701 const xrdc_non_processor_domain_assignment_t *domainAssignment);
702
703 /*!
704 * @brief Sets the processor bus master domain assignment.
705 *
706 * This function sets the processor master domain assignment as valid.
707 * One bus master might have multiple domain assignment registers. The parameter
708 * \p assignIndex specifies which assignment register to set.
709 *
710 * Example: Set domain assignment for core 0.
711 * In this example, there are 3 assignment registers for core 0.
712 *
713 * @code
714 * xrdc_processor_domain_assignment_t processorAssignment;
715 *
716 * XRDC_GetDefaultProcessorDomainAssignment(&processorAssignment);
717 *
718 * processorAssignment.domainId = 1;
719 * processorAssignment.xxx = xxx;
720 * XRDC_SetMasterDomainAssignment(XRDC, kXrdcMasterCpu0, 0U, &processorAssignment);
721 *
722 * processorAssignment.domainId = 2;
723 * processorAssignment.xxx = xxx;
724 * XRDC_SetMasterDomainAssignment(XRDC, kXrdcMasterCpu0, 1U, &processorAssignment);
725 *
726 * processorAssignment.domainId = 0;
727 * processorAssignment.xxx = xxx;
728 * XRDC_SetMasterDomainAssignment(XRDC, kXrdcMasterCpu0, 2U, &processorAssignment);
729 * @endcode
730 *
731 * @param base XRDC peripheral base address.
732 * @param master Which master to configure.
733 * @param assignIndex Which assignment register to set.
734 * @param domainAssignment Pointer to the assignment structure.
735 */
736 void XRDC_SetProcessorDomainAssignment(XRDC_Type *base,
737 xrdc_master_t master,
738 uint8_t assignIndex,
739 const xrdc_processor_domain_assignment_t *domainAssignment);
740
741 /*!
742 * @brief Locks the bus master domain assignment register.
743 *
744 * This function locks the master domain assignment. One bus master might have
745 * multiple domain assignment registers. The parameter \p assignIndex specifies
746 * which assignment register to lock. After it is locked, the register can't be changed
747 * until next reset.
748 *
749 * @param base XRDC peripheral base address.
750 * @param master Which master to configure.
751 * @param assignIndex Which assignment register to lock.
752 */
XRDC_LockMasterDomainAssignment(XRDC_Type * base,xrdc_master_t master,uint8_t assignIndex)753 static inline void XRDC_LockMasterDomainAssignment(XRDC_Type *base, xrdc_master_t master, uint8_t assignIndex)
754 {
755 /* Make sure the master has the assignment register. */
756 assert(assignIndex < ((base->MDACFG[master] & XRDC_MDACFG_NMDAR_MASK) >> XRDC_MDACFG_NMDAR_SHIFT));
757
758 base->MDA[master].MDA_W[assignIndex] |= XRDC_MDA_W_LK1_MASK;
759 }
760
761 /*!
762 * @brief Sets the master domain assignment as valid or invalid.
763 *
764 * This function sets the master domain assignment as valid or invalid. One bus master might have
765 * multiple domain assignment registers. The parameter \p assignIndex specifies
766 * which assignment register to configure.
767 *
768 * @param base XRDC peripheral base address.
769 * @param master Which master to configure.
770 * @param assignIndex Index for the domain assignment register.
771 * @param valid True to set valid, false to set invalid.
772 */
XRDC_SetMasterDomainAssignmentValid(XRDC_Type * base,xrdc_master_t master,uint8_t assignIndex,bool valid)773 static inline void XRDC_SetMasterDomainAssignmentValid(XRDC_Type *base,
774 xrdc_master_t master,
775 uint8_t assignIndex,
776 bool valid)
777 {
778 /* Make sure the master has the assignment register. */
779 assert(assignIndex < ((base->MDACFG[master] & XRDC_MDACFG_NMDAR_MASK) >> XRDC_MDACFG_NMDAR_SHIFT));
780
781 if (valid)
782 {
783 base->MDA[master].MDA_W[assignIndex] |= XRDC_MDA_W_VLD_MASK;
784 }
785 else
786 {
787 base->MDA[master].MDA_W[assignIndex] &= ~XRDC_MDA_W_VLD_MASK;
788 }
789 }
790
791 /*! @} */
792
793 /*!
794 * @name XRDC Memory Region Controller (XRDC_MRC)
795 * @{
796 */
797
798 /*!
799 * @brief Gets the default memory region access policy.
800 *
801 * This function gets the default memory region access policy.
802 * It sets the policy as follows:
803 * @code
804 * config->enableSema = false;
805 * config->semaNum = 0U;
806 * config->subRegionDisableMask = 0U;
807 * config->size = kXrdcMemSizeNone;
808 * config->lockMode = kXRDC_AccessConfigLockWritable;
809 * config->baseAddress = 0U;
810 * config->policy[0] = kXRDC_AccessPolicyNone;
811 * config->policy[1] = kXRDC_AccessPolicyNone;
812 * ...
813 * config->policy[15] = kXRDC_AccessPolicyNone;
814 * @endcode
815 *
816 * @param config Pointer to the configuration structure.
817 */
818 void XRDC_GetMemAccessDefaultConfig(xrdc_mem_access_config_t *config);
819
820 /*!
821 * @brief Sets the memory region access policy.
822 *
823 * This function sets the memory region access configuration as valid.
824 * There are two methods to use it:
825 *
826 * Example 1: Set one configuration run time.
827 * Set memory region 0x20000000 ~ 0x20000400 accessible by domain 0, use MRC0_1.
828 * @code
829 * xrdc_mem_access_config_t config =
830 * {
831 * .mem = kXRDC_MemMrc0_1,
832 * .baseAddress = 0x20000000U,
833 * .size = kXRDC_MemSize1K,
834 * .policy[0] = kXRDC_AccessPolicyAll
835 * };
836 * XRDC_SetMemAccessConfig(XRDC, &config);
837 * @endcode
838 *
839 * Example 2: Set multiple configurations during startup.
840 * Set memory region 0x20000000 ~ 0x20000400 accessible by domain 0, use MRC0_1.
841 * Set memory region 0x1FFF0000 ~ 0x1FFF0800 accessible by domain 0, use MRC0_2.
842 * @code
843 * xrdc_mem_access_config_t configs[] =
844 * {
845 * {
846 * .mem = kXRDC_MemMrc0_1,
847 * .baseAddress = 0x20000000U,
848 * .size = kXRDC_MemSize1K,
849 * .policy[0] = kXRDC_AccessPolicyAll
850 * },
851 * {
852 * .mem = kXRDC_MemMrc0_2,
853 * .baseAddress = 0x1FFF0000U,
854 * .size = kXRDC_MemSize2K,
855 * .policy[0] = kXRDC_AccessPolicyAll
856 * }
857 * };
858 *
859 * for (i=0U; i<((sizeof(configs)/sizeof(configs[0]))); i++)
860 * {
861 * XRDC_SetMemAccessConfig(XRDC, &configs[i]);
862 * }
863 * @endcode
864 *
865 * @param base XRDC peripheral base address.
866 * @param config Pointer to the access policy configuration structure.
867 */
868 void XRDC_SetMemAccessConfig(XRDC_Type *base, const xrdc_mem_access_config_t *config);
869
870 /*!
871 * @brief Sets the memory region descriptor register lock mode.
872 *
873 * @param base XRDC peripheral base address.
874 * @param mem Which memory region descriptor to lock.
875 * @param lockMode The lock mode to set.
876 */
XRDC_SetMemAccessLockMode(XRDC_Type * base,xrdc_mem_t mem,xrdc_access_config_lock_t lockMode)877 static inline void XRDC_SetMemAccessLockMode(XRDC_Type *base, xrdc_mem_t mem, xrdc_access_config_lock_t lockMode)
878 {
879 #if !(defined(FSL_FEATURE_XRDC_NO_MRGD_W3_LK2) && FSL_FEATURE_XRDC_NO_MRGD_W3_LK2)
880 uint32_t reg = base->MRGD[mem].MRGD_W[3];
881
882 reg = ((reg & ~XRDC_MRGD_W_LK2_MASK) | XRDC_MRGD_W_LK2(lockMode));
883
884 base->MRGD[mem].MRGD_W[3] = reg;
885 #elif (defined(FSL_FEATURE_XRDC_HAS_MRGD_W4_LK2) && FSL_FEATURE_XRDC_HAS_MRGD_W4_LK2)
886 uint32_t reg = base->MRGD[mem].MRGD_W[4];
887
888 reg = ((reg & ~XRDC_MRGD_W_LK2_MASK) | XRDC_MRGD_W_LK2(lockMode));
889
890 base->MRGD[mem].MRGD_W[4] = reg;
891 #endif
892 }
893
894 /*!
895 * @brief Sets the memory region descriptor as valid or invalid.
896 *
897 * This function sets the memory region access configuration dynamically. For example:
898 *
899 * @code
900 * xrdc_mem_access_config_t config =
901 * {
902 * .mem = kXRDC_MemMrc0_1,
903 * .baseAddress = 0x20000000U,
904 * .size = kXRDC_MemSize1K,
905 * .policy[0] = kXRDC_AccessPolicyAll
906 * };
907 * XRDC_SetMemAccessConfig(XRDC, &config);
908 *
909 * XRDC_SetMemAccessValid(kXRDC_MemMrc0_1, false);
910 *
911 * XRDC_SetMemAccessValid(kXRDC_MemMrc0_1, true);
912 * @endcode
913 *
914 * @param base XRDC peripheral base address.
915 * @param mem Which memory region descriptor to set.
916 * @param valid True to set valid, false to set invalid.
917 */
XRDC_SetMemAccessValid(XRDC_Type * base,xrdc_mem_t mem,bool valid)918 static inline void XRDC_SetMemAccessValid(XRDC_Type *base, xrdc_mem_t mem, bool valid)
919 {
920 #if !(defined(FSL_FEATURE_XRDC_NO_MRGD_W3_VLD) && FSL_FEATURE_XRDC_NO_MRGD_W3_VLD)
921 if (valid)
922 {
923 base->MRGD[mem].MRGD_W[3] |= XRDC_MRGD_W_VLD_MASK;
924 }
925 else
926 {
927 base->MRGD[mem].MRGD_W[3] &= ~XRDC_MRGD_W_VLD_MASK;
928 }
929 #elif (defined(FSL_FEATURE_XRDC_HAS_MRGD_W4_VLD) && FSL_FEATURE_XRDC_HAS_MRGD_W4_VLD)
930 if (valid)
931 {
932 base->MRGD[mem].MRGD_W[4] |= XRDC_MRGD_W_VLD_MASK;
933 }
934 else
935 {
936 base->MRGD[mem].MRGD_W[4] &= ~XRDC_MRGD_W_VLD_MASK;
937 }
938 #endif
939 }
940
941 #if (defined(FSL_FEATURE_XRDC_HAS_MRGD_EAL) && FSL_FEATURE_XRDC_HAS_MRGD_EAL)
942 /*!
943 * @brief Sets the memory region exclusive access lock mode configuration.
944 *
945 * Note: Any write to MRGD_W[0-3]_n clears the MRGD_W4_n[VLD] indicator so a coherent register state can be supported.
946 * It is indispensable to re-assert the valid bit when dynamically changing the EAL in the MRGD, which is done in
947 * this API.
948 *
949 * @param base XRDC peripheral base address.
950 * @param mem Which memory region's exclusive access lock mode to configure.
951 * @param lockMode The exclusive access lock mode to set.
952 */
953 void XRDC_SetMemExclAccessLockMode(XRDC_Type *base, xrdc_mem_t mem, xrdc_excl_access_lock_config_t lockMode);
954
955 /*!
956 * @brief Forces the release of the memory region exclusive access lock.
957 *
958 * A lock can be forced to the available state (EAL=10) by a domain that does not own the
959 * lock through the forced lock release procedure:
960 * The procedure to force a exclusive access lock release is as follows:
961 * 1. Write 0x02000046 to W1 register (PAC/MSC) or W3 register (MRC)
962 * 2. Write 0x02000052 to W1 register (PAC/MSC) or W3 register (MRC)
963 *
964 * Note: The two writes must be consecutive, any intervening write to the register resets the sequence.
965 *
966 * @param base XRDC peripheral base address.
967 * @param mem Which memory region's exclusive access lock to force release.
968 */
969 void XRDC_ForceMemExclAccessLockRelease(XRDC_Type *base, xrdc_mem_t mem);
970
971 /*!
972 * @brief Gets the exclusive access lock domain owner of the memory region.
973 *
974 * This function returns the domain ID of the exclusive access lock owner of the memory region.
975 *
976 * @param base XRDC peripheral base address.
977 * @param mem Which memory region's exclusive access lock domain owner to get.
978 * @return Domain ID of the memory region exclusive access lock owner.
979 */
XRDC_GetMemExclAccessLockDomainOwner(XRDC_Type * base,xrdc_mem_t mem)980 static inline uint8_t XRDC_GetMemExclAccessLockDomainOwner(XRDC_Type *base, xrdc_mem_t mem)
981 {
982 return (uint8_t)((base->MRGD[mem].MRGD_W[2U] & XRDC_MRGD_W_EALO_MASK) >> XRDC_MRGD_W_EALO_SHIFT);
983 }
984 #endif /* FSL_FEATURE_XRDC_HAS_MRGD_EAL */
985
986 #if (defined(FSL_FEATURE_XRDC_HAS_MRGD_ACCSET) && FSL_FEATURE_XRDC_HAS_MRGD_ACCSET)
987 /*!
988 * @brief Sets the memory region ACCSET (programmable access flags) lock.
989 *
990 * @param base XRDC peripheral base address.
991 * @param mem Which memory region descriptor to lock.
992 * @param accset Which set/index of ACCSET to lock.
993 * @param lock True to set lock, false to set unlock.
994 */
995 void XRDC_SetMemAccsetLock(XRDC_Type *base, xrdc_mem_t mem, xrdc_mem_accset_t accset, bool lock);
996 #endif /* FSL_FEATURE_XRDC_HAS_MRGD_ACCSET */
997
998 /*! @} */
999
1000 /*!
1001 * @name XRDC Peripheral Access Controller (XRDC_PAC)
1002 * @{
1003 */
1004
1005 /*!
1006 * @brief Gets the default peripheral access configuration.
1007 *
1008 * The default configuration is set as follows:
1009 * @code
1010 * config->enableSema = false;
1011 * config->semaNum = 0U;
1012 * config->lockMode = kXRDC_AccessConfigLockWritable;
1013 * config->policy[0] = kXRDC_AccessPolicyNone;
1014 * config->policy[1] = kXRDC_AccessPolicyNone;
1015 * ...
1016 * config->policy[15] = kXRDC_AccessPolicyNone;
1017 * @endcode
1018 *
1019 * @param config Pointer to the configuration structure.
1020 */
1021 void XRDC_GetPeriphAccessDefaultConfig(xrdc_periph_access_config_t *config);
1022
1023 /*!
1024 * @brief Sets the peripheral access configuration.
1025 *
1026 * This function sets the peripheral access configuration as valid. Two
1027 * methods to use it:
1028 * Method 1: Set for one peripheral, which is used for runtime settings.
1029 * Example: set LPTMR0 accessible by domain 0
1030 * @code
1031 * xrdc_periph_access_config_t config;
1032 *
1033 * config.periph = kXRDC_PeriphLptmr0;
1034 * config.policy[0] = kXRDC_AccessPolicyAll;
1035 * XRDC_SetPeriphAccessConfig(XRDC, &config);
1036 * @endcode
1037 *
1038 * Method 2: Set for multiple peripherals, which is used for initialization settings.
1039 * @code
1040 * xrdc_periph_access_config_t configs[] =
1041 * {
1042 * {
1043 * .periph = kXRDC_PeriphLptmr0,
1044 * .policy[0] = kXRDC_AccessPolicyAll,
1045 * .policy[1] = kXRDC_AccessPolicyAll
1046 * },
1047 * {
1048 * .periph = kXRDC_PeriphLpuart0,
1049 * .policy[0] = kXRDC_AccessPolicyAll,
1050 * .policy[1] = kXRDC_AccessPolicyAll
1051 * }
1052 * };
1053 *
1054 * for (i=0U; i<(sizeof(configs)/sizeof(configs[0])), i++)
1055 * {
1056 * XRDC_SetPeriphAccessConfig(XRDC, &config[i]);
1057 * }
1058 * @endcode
1059 *
1060 * @param base XRDC peripheral base address.
1061 * @param config Pointer to the configuration structure.
1062 */
1063 void XRDC_SetPeriphAccessConfig(XRDC_Type *base, const xrdc_periph_access_config_t *config);
1064
1065 /*!
1066 * @brief Sets the peripheral access configuration register lock mode.
1067 *
1068 * @param base XRDC peripheral base address.
1069 * @param periph Which peripheral access configuration register to lock.
1070 * @param lockMode The lock mode to set.
1071 */
XRDC_SetPeriphAccessLockMode(XRDC_Type * base,xrdc_periph_t periph,xrdc_access_config_lock_t lockMode)1072 static inline void XRDC_SetPeriphAccessLockMode(XRDC_Type *base,
1073 xrdc_periph_t periph,
1074 xrdc_access_config_lock_t lockMode)
1075 {
1076 uint32_t reg = base->PDAC_W[periph][1];
1077
1078 #if (defined(FSL_FEATURE_XRDC_HAS_PDAC_EAL) && FSL_FEATURE_XRDC_HAS_PDAC_EAL)
1079 /* If there is PDAC_W1[EAL], should not write non-zero value to EAL. */
1080 reg = ((reg & ~(XRDC_PDAC_W_LK2_MASK | XRDC_PDAC_W_EAL_MASK)) | XRDC_PDAC_W_LK2(lockMode));
1081 #else
1082 reg = ((reg & ~XRDC_PDAC_W_LK2_MASK) | XRDC_PDAC_W_LK2(lockMode));
1083 #endif
1084
1085 base->PDAC_W[periph][1] = reg;
1086 }
1087
1088 /*!
1089 * @brief Sets the peripheral access as valid or invalid.
1090 *
1091 * This function sets the peripheral access configuration dynamically. For example:
1092 *
1093 * @code
1094 * xrdc_periph_access_config_t config =
1095 * {
1096 * .periph = kXRDC_PeriphLptmr0;
1097 * .policy[0] = kXRDC_AccessPolicyAll;
1098 * };
1099 * XRDC_SetPeriphAccessConfig(XRDC, &config);
1100 *
1101 * XRDC_SetPeriphAccessValid(kXrdcPeriLptmr0, false);
1102 *
1103 * XRDC_SetPeriphAccessValid(kXrdcPeriLptmr0, true);
1104 * @endcode
1105 *
1106 * @param base XRDC peripheral base address.
1107 * @param periph Which peripheral access configuration to set.
1108 * @param valid True to set valid, false to set invalid.
1109 */
XRDC_SetPeriphAccessValid(XRDC_Type * base,xrdc_periph_t periph,bool valid)1110 static inline void XRDC_SetPeriphAccessValid(XRDC_Type *base, xrdc_periph_t periph, bool valid)
1111 {
1112 #if (defined(FSL_FEATURE_XRDC_HAS_PDAC_EAL) && FSL_FEATURE_XRDC_HAS_PDAC_EAL)
1113 /* If there is PDAC_W1[EAL], should not write non-zero value to EAL. */
1114 uint32_t reg = base->PDAC_W[periph][1] & ~XRDC_PDAC_W_EAL_MASK;
1115
1116 if (valid)
1117 {
1118 base->PDAC_W[periph][1] = reg | XRDC_PDAC_W_VLD_MASK;
1119 }
1120 else
1121 {
1122 base->PDAC_W[periph][1] = reg & ~XRDC_PDAC_W_VLD_MASK;
1123 }
1124 #else
1125 if (valid)
1126 {
1127 base->PDAC_W[periph][1] |= XRDC_PDAC_W_VLD_MASK;
1128 }
1129 else
1130 {
1131 base->PDAC_W[periph][1] &= ~XRDC_PDAC_W_VLD_MASK;
1132 }
1133 #endif
1134 }
1135
1136 #if (defined(FSL_FEATURE_XRDC_HAS_PDAC_EAL) && FSL_FEATURE_XRDC_HAS_PDAC_EAL)
1137 /*!
1138 * @brief Sets the peripheral exclusive access lock mode configuration.
1139 *
1140 * @param base XRDC peripheral base address.
1141 * @param periph Which peripheral's exclusive access lock mode to configure.
1142 * @param lockMode The exclusive access lock mode to set.
1143 */
XRDC_SetPeriphExclAccessLockMode(XRDC_Type * base,xrdc_periph_t periph,xrdc_excl_access_lock_config_t lockMode)1144 static inline void XRDC_SetPeriphExclAccessLockMode(XRDC_Type *base,
1145 xrdc_periph_t periph,
1146 xrdc_excl_access_lock_config_t lockMode)
1147 {
1148 /* Write kXRDC_ExclAccessLockDisabled is not allowed. */
1149 assert(kXRDC_ExclAccessLockDisabled != lockMode);
1150
1151 uint32_t reg = base->PDAC_W[periph][1];
1152
1153 reg = ((reg & ~XRDC_PDAC_W_EAL_MASK) | XRDC_PDAC_W_EAL(lockMode));
1154
1155 base->PDAC_W[periph][1] = reg;
1156 }
1157
1158 /*!
1159 * @brief Forces the release of the peripheral exclusive access lock.
1160 *
1161 * A lock can be forced to the available state (EAL=10) by a domain that does not own the
1162 * lock through the forced lock release procedure:
1163 * The procedure to force a exclusive access lock release is as follows:
1164 * 1. Write 0x02000046 to W1 register (PAC/MSC) or W3 register (MRC)
1165 * 2. Write 0x02000052 to W1 register (PAC/MSC) or W3 register (MRC)
1166 *
1167 * Note: The two writes must be consecutive, any intervening write to the register resets the sequence.
1168 *
1169 * @param base XRDC peripheral base address.
1170 * @param periph Which peripheral's exclusive access lock to force release.
1171 */
1172 void XRDC_ForcePeriphExclAccessLockRelease(XRDC_Type *base, xrdc_periph_t periph);
1173
1174 /*!
1175 * @brief Gets the exclusive access lock domain owner of the peripheral.
1176 *
1177 * This function returns the domain ID of the exclusive access lock owner of the peripheral.
1178 *
1179 * @param base XRDC peripheral base address.
1180 * @param periph Which peripheral's exclusive access lock domain owner to get.
1181 * @return Domain ID of the peripheral exclusive access lock owner.
1182 */
XRDC_GetPeriphExclAccessLockDomainOwner(XRDC_Type * base,xrdc_periph_t periph)1183 static inline uint8_t XRDC_GetPeriphExclAccessLockDomainOwner(XRDC_Type *base, xrdc_periph_t periph)
1184 {
1185 return (uint8_t)((base->PDAC_W[periph][0U] & XRDC_PDAC_W_EALO_MASK) >> XRDC_PDAC_W_EALO_SHIFT);
1186 }
1187 #endif /* FSL_FEATURE_XRDC_HAS_PDAC_EAL */
1188 /*! @} */
1189
1190 #if defined(__cplusplus)
1191 }
1192 #endif
1193
1194 /*!
1195 * @}
1196 */
1197
1198 #endif /* FSL_XRDC_H_ */
1199