Skip to content

Commit 3a55af3

Browse files
GseoCPatrice Chotard
authored andcommitted
ARM: stm32mp: replace RIFSC check access APIs
Replace RIFSC check access APIs by grant/release access ones that handle the RIF semaphores. Signed-off-by: Gatien Chevallier <gatien.chevallier@foss.st.com> Change-Id: I9446f0d1e900d8e49a2d75fdb24737b6ae9a0b1a Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/u-boot/+/457611 Domain-Review: Patrice CHOTARD <patrice.chotard@foss.st.com> Reviewed-by: Patrice CHOTARD <patrice.chotard@foss.st.com> Tested-by: Gatien CHEVALLIER <gatien.chevallier@st.com> Reviewed-by: Gatien CHEVALLIER <gatien.chevallier@st.com> ACI: CIBUILD <MDG-smet-aci-builds@list.st.com>
1 parent 6ef733a commit 3a55af3

6 files changed

Lines changed: 148 additions & 77 deletions

File tree

arch/arm/mach-stm32mp/include/mach/rif.h

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,53 @@
88

99
#include <linux/types.h>
1010

11+
#if IS_ENABLED(CONFIG_STM32MP21X) || IS_ENABLED(CONFIG_STM32MP23X) || IS_ENABLED(CONFIG_STM32MP25X)
1112
/**
12-
* stm32_rifsc_check_access - Check RIF accesses for given device node
13+
* stm32_rifsc_grant_access_by_id - Grant RIFSC access for a given peripheral using its ID
1314
*
14-
* @device_node Node of the device for which the accesses are checked
15+
* @device_node Node of the peripheral
16+
* @id ID of the peripheral of which access should be granted
1517
*/
16-
int stm32_rifsc_check_access(ofnode device_node);
18+
int stm32_rifsc_grant_access_by_id(ofnode device_node, u32 id);
1719

1820
/**
19-
* stm32_rifsc_check_access - Check RIF accesses for given id
21+
* stm32_rifsc_grant_access_by_id - Grant RIFSC access for a given peripheral using its node
2022
*
21-
* @device_node Node of the device to get a reference on RIFSC
22-
* @id ID of the resource to check
23+
* @id node of the peripheral of which access should be granted
2324
*/
24-
int stm32_rifsc_check_access_by_id(ofnode device_node, u32 id);
25+
int stm32_rifsc_grant_access(ofnode device_node);
2526

27+
/**
28+
* stm32_rifsc_release_access_by_id - Release RIFSC access for a given peripheral using its ID
29+
*
30+
* @device_node Node of the peripheral
31+
* @id ID of the peripheral of which access should be released
32+
*/
33+
void stm32_rifsc_release_access_by_id(ofnode device_node, u32 id);
34+
35+
/**
36+
* stm32_rifsc_release_access_by_id - Release RIFSC access for a given peripheral using its node
37+
*
38+
* @id node of the peripheral of which access should be released
39+
*/
40+
void stm32_rifsc_release_access(ofnode device_node);
41+
#else
42+
static inline int stm32_rifsc_grant_access_by_id(ofnode device_node, u32 id)
43+
{
44+
return -EACCES;
45+
}
46+
47+
static inline int stm32_rifsc_grant_access(ofnode device_node)
48+
{
49+
return -EACCES;
50+
}
51+
52+
static inline void stm32_rifsc_release_access_by_id(ofnode device_node, u32 id)
53+
{
54+
}
55+
56+
static inline void stm32_rifsc_release_access(ofnode device_node)
57+
{
58+
}
59+
#endif
2660
#endif /* MACH_RIF_H*/

arch/arm/mach-stm32mp/stm32mp2/rifsc.c

Lines changed: 74 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -62,43 +62,41 @@ struct stm32_rifsc_child_plat {
6262
u32 domain_id;
6363
};
6464

65-
static bool stm32_rif_is_semaphore_available(void *base, u32 id)
65+
static bool stm32_rif_is_semaphore_available(void *addr)
6666
{
67-
void *addr = base + RIFSC_RISC_PER0_SEMCR(id);
68-
6967
return !(readl(addr) & SEMCR_MUTEX);
7068
}
7169

72-
static int stm32_rif_acquire_semaphore(void *base, u32 id)
70+
static int stm32_rifsc_acquire_semaphore(void *base, u32 id)
7371
{
7472
void *addr = base + RIFSC_RISC_PER0_SEMCR(id);
7573

7674
/* Check that the semaphore is available */
77-
if (!stm32_rif_is_semaphore_available(base, id) &&
75+
if (!stm32_rif_is_semaphore_available(addr) &&
7876
FIELD_GET(RIFSC_RISC_SCID_MASK, (readl(addr)) != RIF_CID1))
7977
return -EACCES;
8078

8179
setbits_le32(addr, SEMCR_MUTEX);
8280

8381
/* Check that CID1 has the semaphore */
84-
if (stm32_rif_is_semaphore_available(base, id) ||
82+
if (stm32_rif_is_semaphore_available(addr) ||
8583
FIELD_GET(RIFSC_RISC_SCID_MASK, (readl(addr)) != RIF_CID1))
8684
return -EACCES;
8785

8886
return 0;
8987
}
9088

91-
static int stm32_rif_release_semaphore(void *base, u32 id)
89+
static int stm32_rifsc_release_semaphore(void *base, u32 id)
9290
{
9391
void *addr = base + RIFSC_RISC_PER0_SEMCR(id);
9492

95-
if (stm32_rif_is_semaphore_available(base, id))
93+
if (stm32_rif_is_semaphore_available(addr))
9694
return 0;
9795

9896
clrbits_le32(addr, SEMCR_MUTEX);
9997

10098
/* Ok if another compartment takes the semaphore before the check */
101-
if (!stm32_rif_is_semaphore_available(base, id) &&
99+
if (!stm32_rif_is_semaphore_available(addr) &&
102100
FIELD_GET(RIFSC_RISC_SCID_MASK, (readl(addr)) == RIF_CID1))
103101
return -EACCES;
104102

@@ -107,11 +105,10 @@ static int stm32_rif_release_semaphore(void *base, u32 id)
107105

108106
static int rifsc_parse_access_controller(ofnode node, struct ofnode_phandle_args *args)
109107
{
110-
int ret;
108+
int ret = ofnode_parse_phandle_with_args(node, "access-controllers",
109+
"#access-controller-cells", 0,
110+
0, args);
111111

112-
ret = ofnode_parse_phandle_with_args(node, "access-controllers",
113-
"#access-controller-cells", 0,
114-
0, args);
115112
if (ret) {
116113
log_debug("failed to parse access-controller (%d)\n", ret);
117114
return ret;
@@ -161,7 +158,7 @@ static int rifsc_check_access(void *base, u32 id)
161158
log_debug("Not in semaphore whitelist for peripheral %d\n", id);
162159
return -EACCES;
163160
}
164-
if (!stm32_rif_is_semaphore_available(base, id) &&
161+
if (!stm32_rif_is_semaphore_available(base + RIFSC_RISC_PER0_SEMCR(id)) &&
165162
!(FIELD_GET(RIFSC_RISC_SCID_MASK, sem_reg_value) & RIF_CID1)) {
166163
log_debug("Semaphore unavailable for peripheral %d\n", id);
167164
return -EACCES;
@@ -175,22 +172,44 @@ static int rifsc_check_access(void *base, u32 id)
175172
return 0;
176173
}
177174

178-
int stm32_rifsc_check_access_by_id(ofnode device_node, u32 id)
175+
int stm32_rifsc_grant_access_by_id(ofnode device_node, u32 id)
179176
{
180177
struct ofnode_phandle_args args;
178+
u32 cid_reg_value;
179+
void *rifsc_base;
181180
int err;
182181

183-
if (id >= STM32MP25_RIFSC_ENTRIES)
184-
return -EINVAL;
185-
186182
err = rifsc_parse_access_controller(device_node, &args);
183+
if (err)
184+
panic("Failed to parse access-controllers property\n");
185+
186+
rifsc_base = (void *)ofnode_get_addr(args.node);
187+
188+
err = rifsc_check_access(rifsc_base, id);
187189
if (err)
188190
return err;
189191

190-
return rifsc_check_access((void *)ofnode_get_addr(args.node), id);
192+
cid_reg_value = readl(rifsc_base + RIFSC_RISC_PER0_CIDCFGR(id));
193+
194+
/*
195+
* If the peripheral is in semaphore mode, take the semaphore so that
196+
* the CID1 has the ownership.
197+
*/
198+
if (cid_reg_value & CIDCFGR_SEMEN &&
199+
(FIELD_GET(RIFSC_RISC_SEMWL_MASK, cid_reg_value) & BIT(RIF_CID1))) {
200+
err = stm32_rifsc_acquire_semaphore(rifsc_base, id);
201+
if (err) {
202+
pr_err("Couldn't acquire RIF semaphore for peripheral %d (%d)\n",
203+
id, err);
204+
return err;
205+
}
206+
pr_debug("Acquiring RIF semaphore for peripheral %d\n", id);
207+
}
208+
209+
return 0;
191210
}
192211

193-
int stm32_rifsc_check_access(ofnode device_node)
212+
int stm32_rifsc_grant_access(ofnode device_node)
194213
{
195214
struct ofnode_phandle_args args;
196215
int err;
@@ -199,58 +218,60 @@ int stm32_rifsc_check_access(ofnode device_node)
199218
if (err)
200219
return err;
201220

202-
return rifsc_check_access((void *)ofnode_get_addr(args.node), args.args[0]);
221+
return stm32_rifsc_grant_access_by_id(device_node, args.args[0]);
222+
203223
}
204224

205-
static int stm32_rifsc_child_pre_probe(struct udevice *dev)
225+
void stm32_rifsc_release_access_by_id(ofnode device_node, u32 id)
206226
{
207-
struct stm32_rifsc_plat *plat = dev_get_plat(dev->parent);
208-
struct stm32_rifsc_child_plat *child_plat = dev_get_parent_plat(dev);
227+
struct ofnode_phandle_args args;
209228
u32 cid_reg_value;
229+
void *rifsc_base;
210230
int err;
211-
u32 id = child_plat->domain_id;
212231

213-
cid_reg_value = readl(plat->base + RIFSC_RISC_PER0_CIDCFGR(id));
232+
err = rifsc_parse_access_controller(device_node, &args);
233+
if (err)
234+
panic("Failed to parse access-controllers property\n");
214235

215-
/*
216-
* If the peripheral is in semaphore mode, take the semaphore so that
217-
* the CID1 has the ownership.
218-
*/
236+
rifsc_base = (void *)ofnode_get_addr(args.node);
237+
238+
cid_reg_value = readl(rifsc_base + RIFSC_RISC_PER0_CIDCFGR(id));
239+
240+
/* If the peripheral is in semaphore mode, release it if we have the ownership */
219241
if (cid_reg_value & CIDCFGR_SEMEN &&
220242
(FIELD_GET(RIFSC_RISC_SEMWL_MASK, cid_reg_value) & BIT(RIF_CID1))) {
221-
err = stm32_rif_acquire_semaphore(plat->base, id);
243+
err = stm32_rifsc_release_semaphore(rifsc_base, id);
222244
if (err) {
223-
dev_err(dev, "Couldn't acquire RIF semaphore for peripheral %d (%d)\n",
224-
id, err);
225-
return err;
245+
panic("Couldn't release RIF semaphore for peripheral %d (%d)\n", id, err);
226246
}
227-
dev_dbg(dev, "Acquiring semaphore for peripheral %d\n", id);
247+
pr_debug("Releasing RIF semaphore for peripheral %d\n", id);
228248
}
249+
}
229250

230-
return 0;
251+
void stm32_rifsc_release_access(ofnode device_node)
252+
{
253+
struct ofnode_phandle_args args;
254+
int err;
255+
256+
err = rifsc_parse_access_controller(device_node, &args);
257+
if (err)
258+
panic("Failed to parse access-controllers property\n");
259+
260+
stm32_rifsc_release_access_by_id(device_node, args.args[0]);
231261
}
232262

233-
static int stm32_rifsc_child_post_remove(struct udevice *dev)
263+
static int stm32_rifsc_child_pre_probe(struct udevice *dev)
234264
{
235-
struct stm32_rifsc_plat *plat = dev_get_plat(dev->parent);
236265
struct stm32_rifsc_child_plat *child_plat = dev_get_parent_plat(dev);
237-
u32 cid_reg_value;
238-
int err;
239-
u32 id = child_plat->domain_id;
240266

241-
cid_reg_value = readl(plat->base + RIFSC_RISC_PER0_CIDCFGR(id));
267+
return stm32_rifsc_grant_access_by_id(dev_ofnode(dev), child_plat->domain_id);
268+
}
242269

243-
/*
244-
* If the peripheral is in semaphore mode, release the semaphore so that
245-
* there's no ownership.
246-
*/
247-
if (cid_reg_value & CIDCFGR_SEMEN &&
248-
(FIELD_GET(RIFSC_RISC_SEMWL_MASK, cid_reg_value) & BIT(RIF_CID1))) {
249-
err = stm32_rif_release_semaphore(plat->base, id);
250-
if (err)
251-
dev_err(dev, "Couldn't release rif semaphore for peripheral %d (%d)\n",
252-
id, err);
253-
}
270+
static int stm32_rifsc_child_post_remove(struct udevice *dev)
271+
{
272+
struct stm32_rifsc_child_plat *child_plat = dev_get_parent_plat(dev);
273+
274+
stm32_rifsc_release_access_by_id(dev_ofnode(dev), child_plat->domain_id);
254275

255276
return 0;
256277
}

drivers/clk/stm32/clk-stm32mp21.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static int stm32mp21_check_security(struct udevice *dev, void __iomem *base,
351351
u32 index = (u32)cfg->sec_id;
352352

353353
if (index & SEC_RIFSC_FLAG)
354-
ret = stm32_rifsc_check_access_by_id(dev_ofnode(dev),
354+
ret = stm32_rifsc_grant_access_by_id(dev_ofnode(dev),
355355
index & ~SEC_RIFSC_FLAG);
356356
else
357357
ret = stm32_rcc_get_access(dev, index);

drivers/clk/stm32/clk-stm32mp25.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static int stm32mp25_check_security(struct udevice *dev, void __iomem *base,
431431
u32 index = (u32)cfg->sec_id;
432432

433433
if (index & SEC_RIFSC_FLAG)
434-
ret = stm32_rifsc_check_access_by_id(dev_ofnode(dev),
434+
ret = stm32_rifsc_grant_access_by_id(dev_ofnode(dev),
435435
index & ~SEC_RIFSC_FLAG);
436436
else
437437
ret = stm32_rcc_get_access(dev, index);

drivers/misc/stm32_omm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ static int stm32_omm_probe(struct udevice *dev) {
198198
if (!ofnode_device_is_compatible(child, "st,stm32mp25-omi"))
199199
return -EINVAL;
200200

201-
ret = stm32_rifsc_check_access(child);
201+
ret = stm32_rifsc_grant_access(child);
202202
if (ret < 0 && ret != -EACCES)
203203
return ret;
204204

@@ -216,7 +216,7 @@ static int stm32_omm_probe(struct udevice *dev) {
216216
return -EINVAL;
217217

218218
/* check if OMM's ressource access is granted */
219-
ret = stm32_rifsc_check_access(dev_ofnode(dev));
219+
ret = stm32_rifsc_grant_access(dev_ofnode(dev));
220220
if (ret < 0 && ret != -EACCES)
221221
goto end;
222222

@@ -405,7 +405,7 @@ static int stm32_omm_bind(struct udevice *dev)
405405
node = ofnode_next_subnode(node)) {
406406
const char *node_name = ofnode_get_name(node);
407407

408-
if (!ofnode_is_enabled(node) || stm32_rifsc_check_access(node)) {
408+
if (!ofnode_is_enabled(node) || stm32_rifsc_grant_access(node)) {
409409
dev_dbg(dev, "%s failed to bind\n", node_name);
410410
continue;
411411
}

0 commit comments

Comments
 (0)