Skip to content

Commit 6fdad99

Browse files
3V3RYONEmathieupoirier
authored andcommitted
remoteproc: k3: Refactor rproc_request_mbox() implementations into common driver
The rproc_request_mbox() implementations in TI K3 R5, DSP and M4 remoteproc drivers acquire the mailbox channel and send the same message through the acquired channel. Refactor the above function into the ti_k3_common.c driver as k3_rproc_request_mbox() and use it throughout R5, DSP and M4 drivers. Signed-off-by: Beleswar Padhi <[email protected]> Tested-by: Judith Mendez <[email protected]> Reviewed-by: Andrew Davis <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mathieu Poirier <[email protected]>
1 parent 67de5d0 commit 6fdad99

File tree

5 files changed

+40
-107
lines changed

5 files changed

+40
-107
lines changed

drivers/remoteproc/ti_k3_common.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,5 +155,41 @@ int k3_rproc_release(struct k3_rproc *kproc)
155155
}
156156
EXPORT_SYMBOL_GPL(k3_rproc_release);
157157

158+
int k3_rproc_request_mbox(struct rproc *rproc)
159+
{
160+
struct k3_rproc *kproc = rproc->priv;
161+
struct mbox_client *client = &kproc->client;
162+
struct device *dev = kproc->dev;
163+
int ret;
164+
165+
client->dev = dev;
166+
client->tx_done = NULL;
167+
client->rx_callback = k3_rproc_mbox_callback;
168+
client->tx_block = false;
169+
client->knows_txdone = false;
170+
171+
kproc->mbox = mbox_request_channel(client, 0);
172+
if (IS_ERR(kproc->mbox))
173+
return dev_err_probe(dev, PTR_ERR(kproc->mbox),
174+
"mbox_request_channel failed\n");
175+
176+
/*
177+
* Ping the remote processor, this is only for sanity-sake for now;
178+
* there is no functional effect whatsoever.
179+
*
180+
* Note that the reply will _not_ arrive immediately: this message
181+
* will wait in the mailbox fifo until the remote processor is booted.
182+
*/
183+
ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
184+
if (ret < 0) {
185+
dev_err(dev, "mbox_send_message failed (%pe)\n", ERR_PTR(ret));
186+
mbox_free_channel(kproc->mbox);
187+
return ret;
188+
}
189+
190+
return 0;
191+
}
192+
EXPORT_SYMBOL_GPL(k3_rproc_request_mbox);
193+
158194
MODULE_LICENSE("GPL");
159195
MODULE_DESCRIPTION("TI K3 common Remoteproc code");

drivers/remoteproc/ti_k3_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,5 @@ void k3_rproc_mbox_callback(struct mbox_client *client, void *data);
9797
void k3_rproc_kick(struct rproc *rproc, int vqid);
9898
int k3_rproc_reset(struct k3_rproc *kproc);
9999
int k3_rproc_release(struct k3_rproc *kproc);
100+
int k3_rproc_request_mbox(struct rproc *rproc);
100101
#endif /* REMOTEPROC_TI_K3_COMMON_H */

drivers/remoteproc/ti_k3_dsp_remoteproc.c

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,6 @@
2424

2525
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
2626

27-
static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
28-
{
29-
struct k3_rproc *kproc = rproc->priv;
30-
struct mbox_client *client = &kproc->client;
31-
struct device *dev = kproc->dev;
32-
int ret;
33-
34-
client->dev = dev;
35-
client->tx_done = NULL;
36-
client->rx_callback = k3_rproc_mbox_callback;
37-
client->tx_block = false;
38-
client->knows_txdone = false;
39-
40-
kproc->mbox = mbox_request_channel(client, 0);
41-
if (IS_ERR(kproc->mbox))
42-
return dev_err_probe(dev, PTR_ERR(kproc->mbox),
43-
"mbox_request_channel failed\n");
44-
45-
/*
46-
* Ping the remote processor, this is only for sanity-sake for now;
47-
* there is no functional effect whatsoever.
48-
*
49-
* Note that the reply will _not_ arrive immediately: this message
50-
* will wait in the mailbox fifo until the remote processor is booted.
51-
*/
52-
ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
53-
if (ret < 0) {
54-
dev_err(dev, "mbox_send_message failed (%pe)\n", ERR_PTR(ret));
55-
mbox_free_channel(kproc->mbox);
56-
return ret;
57-
}
58-
59-
return 0;
60-
}
6127
/*
6228
* The C66x DSP cores have a local reset that affects only the CPU, and a
6329
* generic module reset that powers on the device and allows the DSP internal
@@ -443,7 +409,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
443409
kproc->dev = dev;
444410
kproc->data = data;
445411

446-
ret = k3_dsp_rproc_request_mbox(rproc);
412+
ret = k3_rproc_request_mbox(rproc);
447413
if (ret)
448414
return ret;
449415

drivers/remoteproc/ti_k3_m4_remoteproc.c

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,6 @@
2121
#include "ti_sci_proc.h"
2222
#include "ti_k3_common.h"
2323

24-
static int k3_m4_rproc_request_mbox(struct rproc *rproc)
25-
{
26-
struct k3_rproc *kproc = rproc->priv;
27-
struct mbox_client *client = &kproc->client;
28-
struct device *dev = kproc->dev;
29-
int ret;
30-
31-
client->dev = dev;
32-
client->tx_done = NULL;
33-
client->rx_callback = k3_rproc_mbox_callback;
34-
client->tx_block = false;
35-
client->knows_txdone = false;
36-
37-
kproc->mbox = mbox_request_channel(client, 0);
38-
if (IS_ERR(kproc->mbox))
39-
return dev_err_probe(dev, PTR_ERR(kproc->mbox),
40-
"mbox_request_channel failed\n");
41-
42-
/*
43-
* Ping the remote processor, this is only for sanity-sake for now;
44-
* there is no functional effect whatsoever.
45-
*
46-
* Note that the reply will _not_ arrive immediately: this message
47-
* will wait in the mailbox fifo until the remote processor is booted.
48-
*/
49-
ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
50-
if (ret < 0) {
51-
dev_err(dev, "mbox_send_message failed: %d\n", ret);
52-
mbox_free_channel(kproc->mbox);
53-
return ret;
54-
}
55-
56-
return 0;
57-
}
58-
5924
/*
6025
* The M4 cores have a local reset that affects only the CPU, and a
6126
* generic module reset that powers on the device and allows the internal
@@ -493,7 +458,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
493458
dev_info(dev, "configured M4F for remoteproc mode\n");
494459
}
495460

496-
ret = k3_m4_rproc_request_mbox(rproc);
461+
ret = k3_rproc_request_mbox(rproc);
497462
if (ret)
498463
return ret;
499464

drivers/remoteproc/ti_k3_r5_remoteproc.c

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -284,41 +284,6 @@ static inline int k3_r5_core_run(struct k3_rproc *kproc)
284284
0, PROC_BOOT_CTRL_FLAG_R5_CORE_HALT);
285285
}
286286

287-
static int k3_r5_rproc_request_mbox(struct rproc *rproc)
288-
{
289-
struct k3_rproc *kproc = rproc->priv;
290-
struct mbox_client *client = &kproc->client;
291-
struct device *dev = kproc->dev;
292-
int ret;
293-
294-
client->dev = dev;
295-
client->tx_done = NULL;
296-
client->rx_callback = k3_rproc_mbox_callback;
297-
client->tx_block = false;
298-
client->knows_txdone = false;
299-
300-
kproc->mbox = mbox_request_channel(client, 0);
301-
if (IS_ERR(kproc->mbox))
302-
return dev_err_probe(dev, PTR_ERR(kproc->mbox),
303-
"mbox_request_channel failed\n");
304-
305-
/*
306-
* Ping the remote processor, this is only for sanity-sake for now;
307-
* there is no functional effect whatsoever.
308-
*
309-
* Note that the reply will _not_ arrive immediately: this message
310-
* will wait in the mailbox fifo until the remote processor is booted.
311-
*/
312-
ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
313-
if (ret < 0) {
314-
dev_err(dev, "mbox_send_message failed: %d\n", ret);
315-
mbox_free_channel(kproc->mbox);
316-
return ret;
317-
}
318-
319-
return 0;
320-
}
321-
322287
/*
323288
* The R5F cores have controls for both a reset and a halt/run. The code
324289
* execution from DDR requires the initial boot-strapping code to be run
@@ -1357,7 +1322,7 @@ static int k3_r5_cluster_rproc_init(struct platform_device *pdev)
13571322
kproc = core->kproc;
13581323
rproc = kproc->rproc;
13591324

1360-
ret = k3_r5_rproc_request_mbox(rproc);
1325+
ret = k3_rproc_request_mbox(rproc);
13611326
if (ret)
13621327
return ret;
13631328

0 commit comments

Comments
 (0)