]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - drivers/remoteproc/omap_remoteproc.c
UBUNTU: Ubuntu-5.4.0-117.132
[mirror_ubuntu-focal-kernel.git] / drivers / remoteproc / omap_remoteproc.c
CommitLineData
1802d0be 1// SPDX-License-Identifier: GPL-2.0-only
34ed5a33
OBC
2/*
3 * OMAP Remote Processor driver
4 *
5 * Copyright (C) 2011 Texas Instruments, Inc.
6 * Copyright (C) 2011 Google, Inc.
7 *
8 * Ohad Ben-Cohen <ohad@wizery.com>
9 * Brian Swetland <swetland@google.com>
10 * Fernando Guzman Lugo <fernando.lugo@ti.com>
11 * Mark Grosen <mgrosen@ti.com>
12 * Suman Anna <s-anna@ti.com>
13 * Hari Kanigeri <h-kanigeri2@ti.com>
34ed5a33
OBC
14 */
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/err.h>
19#include <linux/platform_device.h>
20#include <linux/dma-mapping.h>
21#include <linux/remoteproc.h>
8841a66a 22#include <linux/mailbox_client.h>
c869c75c 23#include <linux/omap-mailbox.h>
34ed5a33 24
2203747c 25#include <linux/platform_data/remoteproc-omap.h>
34ed5a33
OBC
26
27#include "omap_remoteproc.h"
28#include "remoteproc_internal.h"
29
30/**
31 * struct omap_rproc - omap remote processor state
8841a66a
SA
32 * @mbox: mailbox channel handle
33 * @client: mailbox client to request the mailbox channel
34ed5a33
OBC
34 * @rproc: rproc handle
35 */
36struct omap_rproc {
8841a66a
SA
37 struct mbox_chan *mbox;
38 struct mbox_client client;
34ed5a33
OBC
39 struct rproc *rproc;
40};
41
42/**
43 * omap_rproc_mbox_callback() - inbound mailbox message handler
8841a66a 44 * @client: mailbox client pointer used for requesting the mailbox channel
34ed5a33
OBC
45 * @data: mailbox payload
46 *
47 * This handler is invoked by omap's mailbox driver whenever a mailbox
48 * message is received. Usually, the mailbox payload simply contains
49 * the index of the virtqueue that is kicked by the remote processor,
50 * and we let remoteproc core handle it.
51 *
52 * In addition to virtqueue indices, we also have some out-of-band values
53 * that indicates different events. Those values are deliberately very
54 * big so they don't coincide with virtqueue indices.
55 */
8841a66a 56static void omap_rproc_mbox_callback(struct mbox_client *client, void *data)
34ed5a33 57{
8841a66a
SA
58 struct omap_rproc *oproc = container_of(client, struct omap_rproc,
59 client);
b5ab5e24 60 struct device *dev = oproc->rproc->dev.parent;
34ed5a33 61 const char *name = oproc->rproc->name;
8841a66a 62 u32 msg = (u32)data;
34ed5a33
OBC
63
64 dev_dbg(dev, "mbox msg: 0x%x\n", msg);
65
66 switch (msg) {
67 case RP_MBOX_CRASH:
68 /* just log this for now. later, we'll also do recovery */
69 dev_err(dev, "omap rproc %s crashed\n", name);
70 break;
71 case RP_MBOX_ECHO_REPLY:
72 dev_info(dev, "received echo reply from %s\n", name);
73 break;
74 default:
55f34080 75 /* msg contains the index of the triggered vring */
34ed5a33
OBC
76 if (rproc_vq_interrupt(oproc->rproc, msg) == IRQ_NONE)
77 dev_dbg(dev, "no message was found in vqid %d\n", msg);
78 }
34ed5a33
OBC
79}
80
81/* kick a virtqueue */
82static void omap_rproc_kick(struct rproc *rproc, int vqid)
83{
84 struct omap_rproc *oproc = rproc->priv;
b5ab5e24 85 struct device *dev = rproc->dev.parent;
34ed5a33
OBC
86 int ret;
87
88 /* send the index of the triggered virtqueue in the mailbox payload */
8841a66a
SA
89 ret = mbox_send_message(oproc->mbox, (void *)vqid);
90 if (ret < 0)
14096c13
AS
91 dev_err(dev, "failed to send mailbox message, status = %d\n",
92 ret);
34ed5a33
OBC
93}
94
95/*
96 * Power up the remote processor.
97 *
98 * This function will be invoked only after the firmware for this rproc
99 * was loaded, parsed successfully, and all of its resource requirements
100 * were met.
101 */
102static int omap_rproc_start(struct rproc *rproc)
103{
104 struct omap_rproc *oproc = rproc->priv;
b5ab5e24
OBC
105 struct device *dev = rproc->dev.parent;
106 struct platform_device *pdev = to_platform_device(dev);
34ed5a33
OBC
107 struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
108 int ret;
8841a66a 109 struct mbox_client *client = &oproc->client;
34ed5a33 110
4980f465
JG
111 if (pdata->set_bootaddr)
112 pdata->set_bootaddr(rproc->bootaddr);
113
8841a66a
SA
114 client->dev = dev;
115 client->tx_done = NULL;
116 client->rx_callback = omap_rproc_mbox_callback;
117 client->tx_block = false;
118 client->knows_txdone = false;
34ed5a33 119
8841a66a 120 oproc->mbox = omap_mbox_request_channel(client, pdata->mbox_name);
34ed5a33 121 if (IS_ERR(oproc->mbox)) {
8841a66a
SA
122 ret = -EBUSY;
123 dev_err(dev, "mbox_request_channel failed: %ld\n",
124 PTR_ERR(oproc->mbox));
34ed5a33
OBC
125 return ret;
126 }
127
128 /*
129 * Ping the remote processor. this is only for sanity-sake;
130 * there is no functional effect whatsoever.
131 *
132 * Note that the reply will _not_ arrive immediately: this message
133 * will wait in the mailbox fifo until the remote processor is booted.
134 */
8841a66a
SA
135 ret = mbox_send_message(oproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
136 if (ret < 0) {
137 dev_err(dev, "mbox_send_message failed: %d\n", ret);
34ed5a33
OBC
138 goto put_mbox;
139 }
140
141 ret = pdata->device_enable(pdev);
142 if (ret) {
b5ab5e24 143 dev_err(dev, "omap_device_enable failed: %d\n", ret);
34ed5a33
OBC
144 goto put_mbox;
145 }
146
147 return 0;
148
149put_mbox:
8841a66a 150 mbox_free_channel(oproc->mbox);
34ed5a33
OBC
151 return ret;
152}
153
154/* power off the remote processor */
155static int omap_rproc_stop(struct rproc *rproc)
156{
b5ab5e24
OBC
157 struct device *dev = rproc->dev.parent;
158 struct platform_device *pdev = to_platform_device(dev);
34ed5a33
OBC
159 struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
160 struct omap_rproc *oproc = rproc->priv;
161 int ret;
162
163 ret = pdata->device_shutdown(pdev);
164 if (ret)
165 return ret;
166
8841a66a 167 mbox_free_channel(oproc->mbox);
34ed5a33
OBC
168
169 return 0;
170}
171
c008fad2 172static const struct rproc_ops omap_rproc_ops = {
34ed5a33
OBC
173 .start = omap_rproc_start,
174 .stop = omap_rproc_stop,
175 .kick = omap_rproc_kick,
176};
177
0fe763c5 178static int omap_rproc_probe(struct platform_device *pdev)
34ed5a33
OBC
179{
180 struct omap_rproc_pdata *pdata = pdev->dev.platform_data;
181 struct omap_rproc *oproc;
182 struct rproc *rproc;
183 int ret;
184
185 ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
186 if (ret) {
6b039762 187 dev_err(&pdev->dev, "dma_set_coherent_mask: %d\n", ret);
34ed5a33
OBC
188 return ret;
189 }
190
191 rproc = rproc_alloc(&pdev->dev, pdata->name, &omap_rproc_ops,
334765f4 192 pdata->firmware, sizeof(*oproc));
34ed5a33
OBC
193 if (!rproc)
194 return -ENOMEM;
195
196 oproc = rproc->priv;
197 oproc->rproc = rproc;
315491e5
SA
198 /* All existing OMAP IPU and DSP processors have an MMU */
199 rproc->has_iommu = true;
34ed5a33
OBC
200
201 platform_set_drvdata(pdev, rproc);
202
160e7c84 203 ret = rproc_add(rproc);
34ed5a33
OBC
204 if (ret)
205 goto free_rproc;
206
207 return 0;
208
209free_rproc:
433c0e04 210 rproc_free(rproc);
34ed5a33
OBC
211 return ret;
212}
213
0fe763c5 214static int omap_rproc_remove(struct platform_device *pdev)
34ed5a33
OBC
215{
216 struct rproc *rproc = platform_get_drvdata(pdev);
217
160e7c84 218 rproc_del(rproc);
433c0e04 219 rproc_free(rproc);
c6b5a276
OBC
220
221 return 0;
34ed5a33
OBC
222}
223
224static struct platform_driver omap_rproc_driver = {
225 .probe = omap_rproc_probe,
0fe763c5 226 .remove = omap_rproc_remove,
34ed5a33
OBC
227 .driver = {
228 .name = "omap-rproc",
34ed5a33
OBC
229 },
230};
231
63d667bf 232module_platform_driver(omap_rproc_driver);
34ed5a33
OBC
233
234MODULE_LICENSE("GPL v2");
235MODULE_DESCRIPTION("OMAP Remote Processor control driver");