Skip to content

Commit f3f11cf

Browse files
3V3RYONEmathieupoirier
authored andcommitted
remoteproc: k3-r5: Acquire mailbox handle during probe routine
Acquire the mailbox handle during device probe and do not release handle in stop/detach routine or error paths. This removes the redundant requests for mbox handle later during rproc start/attach. This also allows to defer remoteproc driver's probe if mailbox is not probed yet. Signed-off-by: Beleswar Padhi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent c81ef0c commit f3f11cf

File tree

1 file changed

+30
-48
lines changed

1 file changed

+30
-48
lines changed

drivers/remoteproc/ti_k3_r5_remoteproc.c

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ static void k3_r5_rproc_mbox_callback(struct mbox_client *client, void *data)
194194
const char *name = kproc->rproc->name;
195195
u32 msg = omap_mbox_message(data);
196196

197+
/* Do not forward message from a detached core */
198+
if (kproc->rproc->state == RPROC_DETACHED)
199+
return;
200+
197201
dev_dbg(dev, "mbox msg: 0x%x\n", msg);
198202

199203
switch (msg) {
@@ -229,6 +233,10 @@ static void k3_r5_rproc_kick(struct rproc *rproc, int vqid)
229233
mbox_msg_t msg = (mbox_msg_t)vqid;
230234
int ret;
231235

236+
/* Do not forward message to a detached core */
237+
if (kproc->rproc->state == RPROC_DETACHED)
238+
return;
239+
232240
/* send the index of the triggered virtqueue in the mailbox payload */
233241
ret = mbox_send_message(kproc->mbox, (void *)msg);
234242
if (ret < 0)
@@ -399,12 +407,9 @@ static int k3_r5_rproc_request_mbox(struct rproc *rproc)
399407
client->knows_txdone = false;
400408

401409
kproc->mbox = mbox_request_channel(client, 0);
402-
if (IS_ERR(kproc->mbox)) {
403-
ret = -EBUSY;
404-
dev_err(dev, "mbox_request_channel failed: %ld\n",
405-
PTR_ERR(kproc->mbox));
406-
return ret;
407-
}
410+
if (IS_ERR(kproc->mbox))
411+
return dev_err_probe(dev, PTR_ERR(kproc->mbox),
412+
"mbox_request_channel failed\n");
408413

409414
/*
410415
* Ping the remote processor, this is only for sanity-sake for now;
@@ -552,10 +557,6 @@ static int k3_r5_rproc_start(struct rproc *rproc)
552557
u32 boot_addr;
553558
int ret;
554559

555-
ret = k3_r5_rproc_request_mbox(rproc);
556-
if (ret)
557-
return ret;
558-
559560
boot_addr = rproc->bootaddr;
560561
/* TODO: add boot_addr sanity checking */
561562
dev_dbg(dev, "booting R5F core using boot addr = 0x%x\n", boot_addr);
@@ -564,7 +565,7 @@ static int k3_r5_rproc_start(struct rproc *rproc)
564565
core = kproc->core;
565566
ret = ti_sci_proc_set_config(core->tsp, boot_addr, 0, 0);
566567
if (ret)
567-
goto put_mbox;
568+
return ret;
568569

569570
/* unhalt/run all applicable cores */
570571
if (cluster->mode == CLUSTER_MODE_LOCKSTEP) {
@@ -580,13 +581,12 @@ static int k3_r5_rproc_start(struct rproc *rproc)
580581
if (core != core0 && core0->rproc->state == RPROC_OFFLINE) {
581582
dev_err(dev, "%s: can not start core 1 before core 0\n",
582583
__func__);
583-
ret = -EPERM;
584-
goto put_mbox;
584+
return -EPERM;
585585
}
586586

587587
ret = k3_r5_core_run(core);
588588
if (ret)
589-
goto put_mbox;
589+
return ret;
590590
}
591591

592592
return 0;
@@ -596,8 +596,6 @@ static int k3_r5_rproc_start(struct rproc *rproc)
596596
if (k3_r5_core_halt(core))
597597
dev_warn(core->dev, "core halt back failed\n");
598598
}
599-
put_mbox:
600-
mbox_free_channel(kproc->mbox);
601599
return ret;
602600
}
603601

@@ -658,8 +656,6 @@ static int k3_r5_rproc_stop(struct rproc *rproc)
658656
goto out;
659657
}
660658

661-
mbox_free_channel(kproc->mbox);
662-
663659
return 0;
664660

665661
unroll_core_halt:
@@ -674,42 +670,22 @@ static int k3_r5_rproc_stop(struct rproc *rproc)
674670
/*
675671
* Attach to a running R5F remote processor (IPC-only mode)
676672
*
677-
* The R5F attach callback only needs to request the mailbox, the remote
678-
* processor is already booted, so there is no need to issue any TI-SCI
679-
* commands to boot the R5F cores in IPC-only mode. This callback is invoked
680-
* only in IPC-only mode.
673+
* The R5F attach callback is a NOP. The remote processor is already booted, and
674+
* all required resources have been acquired during probe routine, so there is
675+
* no need to issue any TI-SCI commands to boot the R5F cores in IPC-only mode.
676+
* This callback is invoked only in IPC-only mode and exists because
677+
* rproc_validate() checks for its existence.
681678
*/
682-
static int k3_r5_rproc_attach(struct rproc *rproc)
683-
{
684-
struct k3_r5_rproc *kproc = rproc->priv;
685-
struct device *dev = kproc->dev;
686-
int ret;
687-
688-
ret = k3_r5_rproc_request_mbox(rproc);
689-
if (ret)
690-
return ret;
691-
692-
dev_info(dev, "R5F core initialized in IPC-only mode\n");
693-
return 0;
694-
}
679+
static int k3_r5_rproc_attach(struct rproc *rproc) { return 0; }
695680

696681
/*
697682
* Detach from a running R5F remote processor (IPC-only mode)
698683
*
699-
* The R5F detach callback performs the opposite operation to attach callback
700-
* and only needs to release the mailbox, the R5F cores are not stopped and
701-
* will be left in booted state in IPC-only mode. This callback is invoked
702-
* only in IPC-only mode.
684+
* The R5F detach callback is a NOP. The R5F cores are not stopped and will be
685+
* left in booted state in IPC-only mode. This callback is invoked only in
686+
* IPC-only mode and exists for sanity sake.
703687
*/
704-
static int k3_r5_rproc_detach(struct rproc *rproc)
705-
{
706-
struct k3_r5_rproc *kproc = rproc->priv;
707-
struct device *dev = kproc->dev;
708-
709-
mbox_free_channel(kproc->mbox);
710-
dev_info(dev, "R5F core deinitialized in IPC-only mode\n");
711-
return 0;
712-
}
688+
static int k3_r5_rproc_detach(struct rproc *rproc) { return 0; }
713689

714690
/*
715691
* This function implements the .get_loaded_rsc_table() callback and is used
@@ -1278,6 +1254,10 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev)
12781254
kproc->rproc = rproc;
12791255
core->rproc = rproc;
12801256

1257+
ret = k3_r5_rproc_request_mbox(rproc);
1258+
if (ret)
1259+
return ret;
1260+
12811261
ret = k3_r5_rproc_configure_mode(kproc);
12821262
if (ret < 0)
12831263
goto out;
@@ -1392,6 +1372,8 @@ static void k3_r5_cluster_rproc_exit(void *data)
13921372
}
13931373
}
13941374

1375+
mbox_free_channel(kproc->mbox);
1376+
13951377
rproc_del(rproc);
13961378

13971379
k3_r5_reserved_mem_exit(kproc);

0 commit comments

Comments
 (0)