Skip to content

Commit 95dac7e

Browse files
3V3RYONEmathieupoirier
authored andcommitted
remoteproc: k3: Refactor mailbox rx_callback functions into common driver
The mailbox .rx_callback implementations in TI K3 R5, DSP and M4 remoteproc drivers handle inbound mailbox messages in the same way. Introduce a common driver 'ti_k3_common.c' and refactor the implementations into a common function 'k3_rproc_mbox_callback'() in it. 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 fa2399c commit 95dac7e

File tree

6 files changed

+95
-149
lines changed

6 files changed

+95
-149
lines changed

drivers/remoteproc/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o
3636
obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o
3737
obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o
3838
obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o
39-
obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o
40-
obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o
41-
obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o
39+
obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o
40+
obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o ti_k3_common.o
41+
obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o ti_k3_common.o
4242
obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.o

drivers/remoteproc/ti_k3_common.c

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* TI K3 Remote Processor(s) driver common code
4+
*
5+
* Refactored out of ti_k3_r5_remoteproc.c, ti_k3_dsp_remoteproc.c and
6+
* ti_k3_m4_remoteproc.c.
7+
*
8+
* ti_k3_r5_remoteproc.c:
9+
* Copyright (C) 2017-2022 Texas Instruments Incorporated - https://www.ti.com/
10+
* Suman Anna <[email protected]>
11+
*
12+
* ti_k3_dsp_remoteproc.c:
13+
* Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
14+
* Suman Anna <[email protected]>
15+
*
16+
* ti_k3_m4_remoteproc.c:
17+
* Copyright (C) 2021-2024 Texas Instruments Incorporated - https://www.ti.com/
18+
* Hari Nagalla <[email protected]>
19+
*/
20+
21+
#include <linux/io.h>
22+
#include <linux/mailbox_client.h>
23+
#include <linux/module.h>
24+
#include <linux/of_address.h>
25+
#include <linux/of_device.h>
26+
#include <linux/of_reserved_mem.h>
27+
#include <linux/omap-mailbox.h>
28+
#include <linux/platform_device.h>
29+
#include <linux/remoteproc.h>
30+
#include <linux/reset.h>
31+
#include <linux/slab.h>
32+
33+
#include "omap_remoteproc.h"
34+
#include "remoteproc_internal.h"
35+
#include "ti_sci_proc.h"
36+
#include "ti_k3_common.h"
37+
38+
/**
39+
* k3_rproc_mbox_callback() - inbound mailbox message handler
40+
* @client: mailbox client pointer used for requesting the mailbox channel
41+
* @data: mailbox payload
42+
*
43+
* This handler is invoked by the K3 mailbox driver whenever a mailbox
44+
* message is received. Usually, the mailbox payload simply contains
45+
* the index of the virtqueue that is kicked by the remote processor,
46+
* and we let remoteproc core handle it.
47+
*
48+
* In addition to virtqueue indices, we also have some out-of-band values
49+
* that indicate different events. Those values are deliberately very
50+
* large so they don't coincide with virtqueue indices.
51+
*/
52+
void k3_rproc_mbox_callback(struct mbox_client *client, void *data)
53+
{
54+
struct k3_rproc *kproc = container_of(client, struct k3_rproc, client);
55+
struct device *dev = kproc->rproc->dev.parent;
56+
struct rproc *rproc = kproc->rproc;
57+
u32 msg = (u32)(uintptr_t)(data);
58+
59+
dev_dbg(dev, "mbox msg: 0x%x\n", msg);
60+
61+
switch (msg) {
62+
case RP_MBOX_CRASH:
63+
/*
64+
* remoteproc detected an exception, but error recovery is not
65+
* supported. So, just log this for now
66+
*/
67+
dev_err(dev, "K3 rproc %s crashed\n", rproc->name);
68+
break;
69+
case RP_MBOX_ECHO_REPLY:
70+
dev_info(dev, "received echo reply from %s\n", rproc->name);
71+
break;
72+
default:
73+
/* silently handle all other valid messages */
74+
if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
75+
return;
76+
if (msg > rproc->max_notifyid) {
77+
dev_dbg(dev, "dropping unknown message 0x%x", msg);
78+
return;
79+
}
80+
/* msg contains the index of the triggered vring */
81+
if (rproc_vq_interrupt(rproc, msg) == IRQ_NONE)
82+
dev_dbg(dev, "no message was found in vqid %d\n", msg);
83+
}
84+
}
85+
EXPORT_SYMBOL_GPL(k3_rproc_mbox_callback);
86+
87+
MODULE_LICENSE("GPL");
88+
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
@@ -93,4 +93,5 @@ struct k3_rproc {
9393
void *priv;
9494
};
9595

96+
void k3_rproc_mbox_callback(struct mbox_client *client, void *data);
9697
#endif /* REMOTEPROC_TI_K3_COMMON_H */

drivers/remoteproc/ti_k3_dsp_remoteproc.c

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

2525
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
2626

27-
/**
28-
* k3_dsp_rproc_mbox_callback() - inbound mailbox message handler
29-
* @client: mailbox client pointer used for requesting the mailbox channel
30-
* @data: mailbox payload
31-
*
32-
* This handler is invoked by the OMAP mailbox driver whenever a mailbox
33-
* message is received. Usually, the mailbox payload simply contains
34-
* the index of the virtqueue that is kicked by the remote processor,
35-
* and we let remoteproc core handle it.
36-
*
37-
* In addition to virtqueue indices, we also have some out-of-band values
38-
* that indicate different events. Those values are deliberately very
39-
* large so they don't coincide with virtqueue indices.
40-
*/
41-
static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data)
42-
{
43-
struct k3_rproc *kproc = container_of(client, struct k3_rproc, client);
44-
struct device *dev = kproc->rproc->dev.parent;
45-
const char *name = kproc->rproc->name;
46-
u32 msg = omap_mbox_message(data);
47-
48-
dev_dbg(dev, "mbox msg: 0x%x\n", msg);
49-
50-
switch (msg) {
51-
case RP_MBOX_CRASH:
52-
/*
53-
* remoteproc detected an exception, but error recovery is not
54-
* supported. So, just log this for now
55-
*/
56-
dev_err(dev, "K3 DSP rproc %s crashed\n", name);
57-
break;
58-
case RP_MBOX_ECHO_REPLY:
59-
dev_info(dev, "received echo reply from %s\n", name);
60-
break;
61-
default:
62-
/* silently handle all other valid messages */
63-
if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
64-
return;
65-
if (msg > kproc->rproc->max_notifyid) {
66-
dev_dbg(dev, "dropping unknown message 0x%x", msg);
67-
return;
68-
}
69-
/* msg contains the index of the triggered vring */
70-
if (rproc_vq_interrupt(kproc->rproc, msg) == IRQ_NONE)
71-
dev_dbg(dev, "no message was found in vqid %d\n", msg);
72-
}
73-
}
74-
7527
/*
7628
* Kick the remote processor to notify about pending unprocessed messages.
7729
* The vqid usage is not used and is inconsequential, as the kick is performed
@@ -155,7 +107,7 @@ static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
155107

156108
client->dev = dev;
157109
client->tx_done = NULL;
158-
client->rx_callback = k3_dsp_rproc_mbox_callback;
110+
client->rx_callback = k3_rproc_mbox_callback;
159111
client->tx_block = false;
160112
client->knows_txdone = false;
161113

drivers/remoteproc/ti_k3_m4_remoteproc.c

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

24-
/**
25-
* k3_m4_rproc_mbox_callback() - inbound mailbox message handler
26-
* @client: mailbox client pointer used for requesting the mailbox channel
27-
* @data: mailbox payload
28-
*
29-
* This handler is invoked by the K3 mailbox driver whenever a mailbox
30-
* message is received. Usually, the mailbox payload simply contains
31-
* the index of the virtqueue that is kicked by the remote processor,
32-
* and we let remoteproc core handle it.
33-
*
34-
* In addition to virtqueue indices, we also have some out-of-band values
35-
* that indicate different events. Those values are deliberately very
36-
* large so they don't coincide with virtqueue indices.
37-
*/
38-
static void k3_m4_rproc_mbox_callback(struct mbox_client *client, void *data)
39-
{
40-
struct device *dev = client->dev;
41-
struct rproc *rproc = dev_get_drvdata(dev);
42-
u32 msg = (u32)(uintptr_t)(data);
43-
44-
dev_dbg(dev, "mbox msg: 0x%x\n", msg);
45-
46-
switch (msg) {
47-
case RP_MBOX_CRASH:
48-
/*
49-
* remoteproc detected an exception, but error recovery is not
50-
* supported. So, just log this for now
51-
*/
52-
dev_err(dev, "K3 rproc %s crashed\n", rproc->name);
53-
break;
54-
case RP_MBOX_ECHO_REPLY:
55-
dev_info(dev, "received echo reply from %s\n", rproc->name);
56-
break;
57-
default:
58-
/* silently handle all other valid messages */
59-
if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
60-
return;
61-
if (msg > rproc->max_notifyid) {
62-
dev_dbg(dev, "dropping unknown message 0x%x", msg);
63-
return;
64-
}
65-
/* msg contains the index of the triggered vring */
66-
if (rproc_vq_interrupt(rproc, msg) == IRQ_NONE)
67-
dev_dbg(dev, "no message was found in vqid %d\n", msg);
68-
}
69-
}
70-
7124
/*
7225
* Kick the remote processor to notify about pending unprocessed messages.
7326
* The vqid usage is not used and is inconsequential, as the kick is performed
@@ -581,7 +534,7 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
581534

582535
kproc->client.dev = dev;
583536
kproc->client.tx_done = NULL;
584-
kproc->client.rx_callback = k3_m4_rproc_mbox_callback;
537+
kproc->client.rx_callback = k3_rproc_mbox_callback;
585538
kproc->client.tx_block = false;
586539
kproc->client.knows_txdone = false;
587540
kproc->mbox = mbox_request_channel(&kproc->client, 0);

drivers/remoteproc/ti_k3_r5_remoteproc.c

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -129,54 +129,6 @@ struct k3_r5_core {
129129
bool released_from_reset;
130130
};
131131

132-
/**
133-
* k3_r5_rproc_mbox_callback() - inbound mailbox message handler
134-
* @client: mailbox client pointer used for requesting the mailbox channel
135-
* @data: mailbox payload
136-
*
137-
* This handler is invoked by the OMAP mailbox driver whenever a mailbox
138-
* message is received. Usually, the mailbox payload simply contains
139-
* the index of the virtqueue that is kicked by the remote processor,
140-
* and we let remoteproc core handle it.
141-
*
142-
* In addition to virtqueue indices, we also have some out-of-band values
143-
* that indicate different events. Those values are deliberately very
144-
* large so they don't coincide with virtqueue indices.
145-
*/
146-
static void k3_r5_rproc_mbox_callback(struct mbox_client *client, void *data)
147-
{
148-
struct k3_rproc *kproc = container_of(client, struct k3_rproc, client);
149-
struct device *dev = kproc->rproc->dev.parent;
150-
const char *name = kproc->rproc->name;
151-
u32 msg = omap_mbox_message(data);
152-
153-
dev_dbg(dev, "mbox msg: 0x%x\n", msg);
154-
155-
switch (msg) {
156-
case RP_MBOX_CRASH:
157-
/*
158-
* remoteproc detected an exception, but error recovery is not
159-
* supported. So, just log this for now
160-
*/
161-
dev_err(dev, "K3 R5F rproc %s crashed\n", name);
162-
break;
163-
case RP_MBOX_ECHO_REPLY:
164-
dev_info(dev, "received echo reply from %s\n", name);
165-
break;
166-
default:
167-
/* silently handle all other valid messages */
168-
if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
169-
return;
170-
if (msg > kproc->rproc->max_notifyid) {
171-
dev_dbg(dev, "dropping unknown message 0x%x", msg);
172-
return;
173-
}
174-
/* msg contains the index of the triggered vring */
175-
if (rproc_vq_interrupt(kproc->rproc, msg) == IRQ_NONE)
176-
dev_dbg(dev, "no message was found in vqid %d\n", msg);
177-
}
178-
}
179-
180132
/* kick a virtqueue */
181133
static void k3_r5_rproc_kick(struct rproc *rproc, int vqid)
182134
{
@@ -356,7 +308,7 @@ static int k3_r5_rproc_request_mbox(struct rproc *rproc)
356308

357309
client->dev = dev;
358310
client->tx_done = NULL;
359-
client->rx_callback = k3_r5_rproc_mbox_callback;
311+
client->rx_callback = k3_rproc_mbox_callback;
360312
client->tx_block = false;
361313
client->knows_txdone = false;
362314

0 commit comments

Comments
 (0)