Skip to content

Commit 7f40291

Browse files
Devarsh Thakkarmathieupoirier
authored andcommitted
remoteproc: k3-r5: Simplify cluster mode setting usage
Check the validity of mode against SoC supported modes right at the probe to minimize the usage of same check further in the code. Set default value of cluster-mode only if cluster-mode device tree property is empty. In case devicetree provided cluster-mode property is invalid For e.g. using CLUSTER_MODE_SINGLECPU on any SoC other than am64x then return error. If firmware has set the PROC_BOOT_STATUS_FLAG_R5_SINGLECORE_ONLY flag then what it means is that only CLUSTER_MODE_SINGLECPU is possible to use [1] and hence there is no need to check for soc_data->single_cpu_mode first and then checking cluster mode. PROC_BOOT_CFG_FLAG_R5_SINGLE_CORE flag can be set directly for CLUSTER_MODE_SINGLECPU without checking for soc_data->single_cpu_mode since that check has already been done during probe. For IPC-only mode, directly override cluster mode as per config flag set by bootloader without checking for soc specific data. This because config flag would already have been validated by firmware when bootloader was setting it. Link: [1] https://software-dl.ti.com/tisci/esd/latest/2_tisci_msgs/security/PROC_BOOT.html?highlight=singlecore_only#arm-r5 Signed-off-by: Devarsh Thakkar <devarsht@ti.com> Link: https://lore.kernel.org/r/20230327152832.923480-2-devarsht@ti.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
1 parent e199679 commit 7f40291

1 file changed

Lines changed: 40 additions & 36 deletions

File tree

drivers/remoteproc/ti_k3_r5_remoteproc.c

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -852,38 +852,33 @@ static int k3_r5_rproc_configure(struct k3_r5_rproc *kproc)
852852
dev_dbg(dev, "boot_vector = 0x%llx, cfg = 0x%x ctrl = 0x%x stat = 0x%x\n",
853853
boot_vec, cfg, ctrl, stat);
854854

855-
/* check if only Single-CPU mode is supported on applicable SoCs */
856-
if (cluster->soc_data->single_cpu_mode) {
857-
single_cpu =
858-
!!(stat & PROC_BOOT_STATUS_FLAG_R5_SINGLECORE_ONLY);
859-
if (single_cpu && cluster->mode == CLUSTER_MODE_SPLIT) {
860-
dev_err(cluster->dev, "split-mode not permitted, force configuring for single-cpu mode\n");
861-
cluster->mode = CLUSTER_MODE_SINGLECPU;
862-
}
863-
goto config;
855+
single_cpu = !!(stat & PROC_BOOT_STATUS_FLAG_R5_SINGLECORE_ONLY);
856+
lockstep_en = !!(stat & PROC_BOOT_STATUS_FLAG_R5_LOCKSTEP_PERMITTED);
857+
858+
/* Override to single CPU mode if set in status flag */
859+
if (single_cpu && cluster->mode == CLUSTER_MODE_SPLIT) {
860+
dev_err(cluster->dev, "split-mode not permitted, force configuring for single-cpu mode\n");
861+
cluster->mode = CLUSTER_MODE_SINGLECPU;
864862
}
865863

866-
/* check conventional LockStep vs Split mode configuration */
867-
lockstep_en = !!(stat & PROC_BOOT_STATUS_FLAG_R5_LOCKSTEP_PERMITTED);
864+
/* Override to split mode if lockstep enable bit is not set in status flag */
868865
if (!lockstep_en && cluster->mode == CLUSTER_MODE_LOCKSTEP) {
869866
dev_err(cluster->dev, "lockstep mode not permitted, force configuring for split-mode\n");
870867
cluster->mode = CLUSTER_MODE_SPLIT;
871868
}
872869

873-
config:
874870
/* always enable ARM mode and set boot vector to 0 */
875871
boot_vec = 0x0;
876872
if (core == core0) {
877873
clr_cfg = PROC_BOOT_CFG_FLAG_R5_TEINIT;
878-
if (cluster->soc_data->single_cpu_mode) {
879-
/*
880-
* Single-CPU configuration bit can only be configured
881-
* on Core0 and system firmware will NACK any requests
882-
* with the bit configured, so program it only on
883-
* permitted cores
884-
*/
885-
if (cluster->mode == CLUSTER_MODE_SINGLECPU)
886-
set_cfg = PROC_BOOT_CFG_FLAG_R5_SINGLE_CORE;
874+
/*
875+
* Single-CPU configuration bit can only be configured
876+
* on Core0 and system firmware will NACK any requests
877+
* with the bit configured, so program it only on
878+
* permitted cores
879+
*/
880+
if (cluster->mode == CLUSTER_MODE_SINGLECPU) {
881+
set_cfg = PROC_BOOT_CFG_FLAG_R5_SINGLE_CORE;
887882
} else {
888883
/*
889884
* LockStep configuration bit is Read-only on Split-mode
@@ -1108,12 +1103,12 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc)
11081103
struct k3_r5_cluster *cluster = kproc->cluster;
11091104
struct k3_r5_core *core = kproc->core;
11101105
struct device *cdev = core->dev;
1111-
bool r_state = false, c_state = false;
1106+
bool r_state = false, c_state = false, lockstep_en = false, single_cpu = false;
11121107
u32 ctrl = 0, cfg = 0, stat = 0, halted = 0;
11131108
u64 boot_vec = 0;
11141109
u32 atcm_enable, btcm_enable, loczrama;
11151110
struct k3_r5_core *core0;
1116-
enum cluster_mode mode;
1111+
enum cluster_mode mode = cluster->mode;
11171112
int ret;
11181113

11191114
core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem);
@@ -1147,13 +1142,14 @@ static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc)
11471142
atcm_enable = cfg & PROC_BOOT_CFG_FLAG_R5_ATCM_EN ? 1 : 0;
11481143
btcm_enable = cfg & PROC_BOOT_CFG_FLAG_R5_BTCM_EN ? 1 : 0;
11491144
loczrama = cfg & PROC_BOOT_CFG_FLAG_R5_TCM_RSTBASE ? 1 : 0;
1150-
if (cluster->soc_data->single_cpu_mode) {
1151-
mode = cfg & PROC_BOOT_CFG_FLAG_R5_SINGLE_CORE ?
1152-
CLUSTER_MODE_SINGLECPU : CLUSTER_MODE_SPLIT;
1153-
} else {
1154-
mode = cfg & PROC_BOOT_CFG_FLAG_R5_LOCKSTEP ?
1155-
CLUSTER_MODE_LOCKSTEP : CLUSTER_MODE_SPLIT;
1156-
}
1145+
single_cpu = cfg & PROC_BOOT_CFG_FLAG_R5_SINGLE_CORE ? 1 : 0;
1146+
lockstep_en = cfg & PROC_BOOT_CFG_FLAG_R5_LOCKSTEP ? 1 : 0;
1147+
1148+
if (single_cpu)
1149+
mode = CLUSTER_MODE_SINGLECPU;
1150+
if (lockstep_en)
1151+
mode = CLUSTER_MODE_LOCKSTEP;
1152+
11571153
halted = ctrl & PROC_BOOT_CTRL_FLAG_R5_CORE_HALT;
11581154

11591155
/*
@@ -1700,12 +1696,6 @@ static int k3_r5_probe(struct platform_device *pdev)
17001696
return -ENOMEM;
17011697

17021698
cluster->dev = dev;
1703-
/*
1704-
* default to most common efuse configurations - Split-mode on AM64x
1705-
* and LockStep-mode on all others
1706-
*/
1707-
cluster->mode = data->single_cpu_mode ?
1708-
CLUSTER_MODE_SPLIT : CLUSTER_MODE_LOCKSTEP;
17091699
cluster->soc_data = data;
17101700
INIT_LIST_HEAD(&cluster->cores);
17111701

@@ -1716,6 +1706,20 @@ static int k3_r5_probe(struct platform_device *pdev)
17161706
return ret;
17171707
}
17181708

1709+
if (ret == -EINVAL) {
1710+
/*
1711+
* default to most common efuse configurations - Split-mode on AM64x
1712+
* and LockStep-mode on all others
1713+
*/
1714+
cluster->mode = data->single_cpu_mode ?
1715+
CLUSTER_MODE_SPLIT : CLUSTER_MODE_LOCKSTEP;
1716+
}
1717+
1718+
if (cluster->mode == CLUSTER_MODE_SINGLECPU && !data->single_cpu_mode) {
1719+
dev_err(dev, "Cluster mode = %d is not supported on this SoC\n", cluster->mode);
1720+
return -EINVAL;
1721+
}
1722+
17191723
num_cores = of_get_available_child_count(np);
17201724
if (num_cores != 2) {
17211725
dev_err(dev, "MCU cluster requires both R5F cores to be enabled, num_cores = %d\n",

0 commit comments

Comments
 (0)