Skip to content

Commit 17ad016

Browse files
committed
drivers: memc_nxp_s32_qspi: add support for s32ze
Add support QSPI secure flash protection (SFP) Signed-off-by: Cong Nguyen Huu <[email protected]>
1 parent d0e4a04 commit 17ad016

File tree

5 files changed

+199
-1
lines changed

5 files changed

+199
-1
lines changed

drivers/memc/memc_nxp_s32_qspi.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ LOG_MODULE_REGISTER(nxp_s32_qspi_memc, CONFIG_MEMC_LOG_LEVEL);
1111

1212
#include <zephyr/drivers/pinctrl.h>
1313
#include <zephyr/sys/util.h>
14+
#include <zephyr/dt-bindings/qspi/nxp-s32-qspi.h>
1415

1516
#include <soc.h>
1617
#include "memc_nxp_s32_qspi.h"
@@ -154,6 +155,81 @@ uint8_t memc_nxp_s32_qspi_get_instance(const struct device *dev)
154155
QSPI_PORT_SIZE(n, side_upper) \
155156
.readMode##side_upper = QSPI_READ_MODE(n, side, side_upper),
156157

158+
#if FEATURE_QSPI_HAS_SFP
159+
160+
#if QSPI_IP_SFP_ENABLE_MDAD
161+
#define SFP_MDAD_NODE(n) DT_INST_CHILD(n, sfp_mdad)
162+
163+
#define QSPI_SECURE_ATTRIBUTE(node_id) \
164+
(DT_PROP(node_id, secure_attribute) == NXP_S32_QSPI_NON_SECURE ? QSPI_IP_SFP_UNSECURE : \
165+
(DT_PROP(node_id, secure_attribute) == NXP_S32_QSPI_SECURE ? QSPI_IP_SFP_SECURE : \
166+
(DT_PROP(node_id, secure_attribute) == (NXP_S32_QSPI_NON_SECURE | NXP_S32_QSPI_SECURE) ?\
167+
QSPI_IP_SFP_BOTH : \
168+
QSPI_IP_SFP_RESERVED)))
169+
170+
#define _QSPI_SFP_MDAD_CFG(node_id, n) \
171+
{ \
172+
.SecureAttribute = QSPI_SECURE_ATTRIBUTE(node_id), \
173+
.MaskType = DT_ENUM_IDX(node_id, mask_type), \
174+
.Valid = true, \
175+
.Mask = DT_PROP(node_id, mask), \
176+
.DomainId = DT_PROP(node_id, domain_id), \
177+
},
178+
179+
#define QSPI_SFP_MDAD_CFG(n) \
180+
.Tg = { \
181+
DT_FOREACH_CHILD_STATUS_OKAY_VARGS(SFP_MDAD_NODE(n), _QSPI_SFP_MDAD_CFG, n)\
182+
},
183+
#endif /* QSPI_IP_SFP_ENABLE_MDAD */
184+
185+
#if QSPI_IP_SFP_ENABLE_FRAD
186+
#define SFP_FRAD_NODE(n) DT_INST_CHILD(n, sfp_frad)
187+
188+
#define QSPI_ACP_POLICY(node_id) \
189+
(DT_PROP(node_id, master_domain_acp_policy) == NXP_S32_QSPI_SECURE ? \
190+
QSPI_IP_SFP_ACP_SECURE :\
191+
(DT_PROP(node_id, master_domain_acp_policy) == (NXP_S32_QSPI_NON_SECURE | \
192+
NXP_S32_QSPI_PRIVILEGE) ? QSPI_IP_SFP_ACP_PRIVILEGED : \
193+
(DT_PROP(node_id, master_domain_acp_policy) == (NXP_S32_QSPI_SECURE | \
194+
NXP_S32_QSPI_PRIVILEGE) ? QSPI_IP_SFP_ACP_SECURE_PRIVILEGED :\
195+
(DT_PROP(node_id, master_domain_acp_policy) == (NXP_S32_QSPI_NON_SECURE | \
196+
NXP_S32_QSPI_SECURE | NXP_S32_QSPI_PRIVILEGE) ? QSPI_IP_SFP_ACP_ALL : \
197+
QSPI_IP_SFP_ACP_NONE))))
198+
199+
#define QSPI_EXCLUSIVE_ACCESS_LOCK(node_id) \
200+
(DT_ENUM_IDX(node_id, exclusive_access_lock) == 0 ? QSPI_IP_SFP_EAL_DISABLED : \
201+
(DT_ENUM_IDX(node_id, exclusive_access_lock) == 1 ? QSPI_IP_SFP_EAL_OWNER : \
202+
QSPI_IP_SFP_EAL_NONE))
203+
204+
#define _QSPI_SFP_FRAD_CFG(node_id, n) \
205+
{ \
206+
.StartAddress = DT_REG_ADDR(node_id), \
207+
.EndAddress = DT_REG_ADDR(node_id) + DT_REG_SIZE(node_id) - 1, \
208+
.Valid = true, \
209+
.Md0Acp = QSPI_ACP_POLICY(node_id), \
210+
.Md1Acp = QSPI_ACP_POLICY(node_id), \
211+
.ExclusiveAccessLock = QSPI_EXCLUSIVE_ACCESS_LOCK(node_id), \
212+
.ExclusiveAccessOwner = DT_PROP(node_id, exclusive_access_owner), \
213+
},
214+
215+
#define QSPI_SFP_FRAD_CFG(n) \
216+
.Frad = { \
217+
DT_FOREACH_CHILD_STATUS_OKAY_VARGS(SFP_FRAD_NODE(n), _QSPI_SFP_FRAD_CFG, n)\
218+
},
219+
#endif /* QSPI_IP_SFP_ENABLE_FRAD */
220+
221+
#define QSPI_SFP_MASTER_TIMEOUT_CYCLES 0xffff
222+
223+
#define QSPI_SFP_CFG(n) \
224+
IF_ENABLED(QSPI_IP_SFP_ENABLE_GLOBAL, \
225+
(.SfpCfg = { \
226+
.MasterTimeout = QSPI_SFP_MASTER_TIMEOUT_CYCLES, \
227+
IF_ENABLED(QSPI_IP_SFP_ENABLE_MDAD, (QSPI_SFP_MDAD_CFG(n))) \
228+
IF_ENABLED(QSPI_IP_SFP_ENABLE_FRAD, (QSPI_SFP_FRAD_CFG(n))) \
229+
},))
230+
231+
#endif /* FEATURE_QSPI_HAS_SFP */
232+
157233
#define MEMC_NXP_S32_QSPI_CONTROLLER_CONFIG(n) \
158234
BUILD_ASSERT(DT_INST_PROP_LEN(n, ahb_buffers_masters) == QSPI_IP_AHB_BUFFERS, \
159235
"ahb-buffers-masters must be of size QSPI_IP_AHB_BUFFERS"); \
@@ -174,6 +250,7 @@ uint8_t memc_nxp_s32_qspi_get_instance(const struct device *dev)
174250
QSPI_DATA_CFG(n) \
175251
QSPI_ADDR_CFG(n) \
176252
QSPI_BYTES_SWAP_ADDR(n) \
253+
IF_ENABLED(FEATURE_QSPI_HAS_SFP, (QSPI_SFP_CFG(n))) \
177254
}
178255

179256
#define MEMC_NXP_S32_QSPI_INIT_DEVICE(n) \
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: NXP S32 Quad Serial Peripheral Interface (QSPI) Secure Flash Protection SFP FRAD.
5+
6+
The SFP FRAD performs second-level checks on input flash write and erase transactions,
7+
based on the address range of each transaction.
8+
9+
compatible: "nxp,s32-qspi-sfp-frad"
10+
11+
child-binding:
12+
13+
properties:
14+
reg:
15+
type: array
16+
required: true
17+
18+
master-domain-acp-policy:
19+
type: int
20+
required: true
21+
description: |
22+
Selects the master domain access control policy, defined in dt-bindings/qspi/nxp-s32-qspi.h:
23+
- NXP_S32_QSPI_NON_SECURE: Selects the non-secure access control policy.
24+
- NXP_S32_QSPI_SECURE: Selects the secure access control policy.
25+
- NXP_S32_QSPI_PRIVILEGE: Selects the privilege access control policy.
26+
Allowed combinations:
27+
- NXP_S32_QSPI_SECURE
28+
- NXP_S32_QSPI_SECURE | NXP_S32_QSPI_PRIVILEGE
29+
- NXP_S32_QSPI_NON_SECURE | NXP_S32_QSPI_PRIVILEGE
30+
- NXP_S32_QSPI_NON_SECURE | NXP_S32_QSPI_SECURE | NXP_S32_QSPI_PRIVILEGE
31+
32+
exclusive-access-lock:
33+
type: string
34+
enum:
35+
- DISABLED
36+
- OWNER
37+
- NONE
38+
default: DISABLED
39+
description: |
40+
Selects the exclusive access lock:
41+
- DISABLED: The exclusive access lock disabled, granting write permissions for all masters
42+
- ENABLED: The exclusive access lock enabled, granting write permissions only to the
43+
exclusive access owner master and disabling write permissions for other masters.
44+
- NONE: This configuration should not be used
45+
The default corresponds to the reset value of the register field.
46+
47+
exclusive-access-owner:
48+
type: int
49+
default: 0
50+
description: |
51+
The domain master ID that owns the exclusive access lock.
52+
Valid range: 0 - 63. The default corresponds to the reset
53+
value of the register field.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: NXP S32 Quad Serial Peripheral Interface (QSPI) Secure Flash Protection SFP MDAD.
5+
6+
The SFP MDAD performs first-level checks on input transactions, based on the secure attribute
7+
and MGID associated with each transaction.
8+
9+
compatible: "nxp,s32-qspi-sfp-mdad"
10+
11+
child-binding:
12+
13+
properties:
14+
secure-attribute:
15+
type: int
16+
required: true
17+
description: |
18+
Selects the secure attribute, defined in dt-bindings/qspi/nxp-s32-qspi.h:
19+
- NXP_S32_QSPI_NON_SECURE: Allow the bus attribute for this master to non-secure
20+
- NXP_S32_QSPI_SECURE: Allow the bus attribute for this master to secure
21+
Allowed combinations:
22+
- NXP_S32_QSPI_NON_SECURE
23+
- NXP_S32_QSPI_SECURE
24+
- NXP_S32_QSPI_NON_SECURE | NXP_S32_QSPI_SECURE
25+
26+
mask-type:
27+
type: string
28+
enum:
29+
- AND
30+
- OR
31+
default: AND
32+
description: |
33+
Selects the mask type:
34+
- AND: AND-ed mask
35+
- OR: OR-ed mask
36+
The default corresponds to the reset value of the register field.
37+
38+
mask:
39+
type: int
40+
default: 0
41+
description: |
42+
Defines the mask value for the ID-Match comparison.
43+
Valid range: 0 - 63. The default corresponds to the
44+
reset value of the register field.
45+
46+
domain-id:
47+
type: int
48+
required: true
49+
description: |
50+
Domain ID Reference value of the Domain-ID (MID) for MID-comparison.
51+
Valid range: 0 - 63.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_NXP_S32_QSPI_H_
8+
#define ZEPHYR_INCLUDE_DT_BINDINGS_NXP_S32_QSPI_H_
9+
10+
#include <zephyr/dt-bindings/dt-util.h>
11+
12+
/* The QSPI secure attribute and secure policy references */
13+
#define NXP_S32_QSPI_NON_SECURE BIT(0)
14+
#define NXP_S32_QSPI_SECURE BIT(1)
15+
#define NXP_S32_QSPI_PRIVILEGE BIT(2)
16+
17+
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_NXP_S32_QSPI_H_ */

west.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ manifest:
203203
groups:
204204
- hal
205205
- name: hal_nxp
206-
revision: a7dc61f89063c1008f24ee21575c68d0165de91b
206+
revision: 5576d444d203e8973f7e8f5be18263b3d8a7bb1f
207207
path: modules/hal/nxp
208208
groups:
209209
- hal

0 commit comments

Comments
 (0)