Lines Matching +full:rpmsg +full:- +full:in

1 // SPDX-License-Identifier: GPL-2.0
7 #include <linux/rpmsg.h>
10 #include "delta-ipc.h"
11 #include "delta-mem.h"
38 #define msg_to_ctx(msg) ((struct delta_ipc_ctx *)(msg)->header.host_hdl)
39 #define msg_to_copro_hdl(msg) ((msg)->header.copro_hdl)
43 return (ctx->ipc_buf->paddr + (vaddr - ctx->ipc_buf->vaddr)); in to_paddr()
49 return ((data >= ctx->ipc_buf->vaddr) && in is_valid_data()
50 ((data + size) <= (ctx->ipc_buf->vaddr + ctx->ipc_buf->size))); in is_valid_data()
58 * this IPC shared memory, avoiding de-facto recopies inside delta-ipc.
60 * side and are packed (use only of 32 bits size fields in messages
62 * - struct delta_ipc_open_msg
63 * - struct delta_ipc_set_stream_msg
64 * - struct delta_ipc_decode_msg
65 * - struct delta_ipc_close_msg
66 * - struct delta_ipc_cb_msg
104 header->tag = IPC_SANITY_TAG; in build_msg_header()
105 header->host_hdl = to_host_hdl(ctx); in build_msg_header()
106 header->copro_hdl = ctx->copro_hdl; in build_msg_header()
107 header->command = command; in build_msg_header()
114 struct delta_dev *delta = pctx->dev; in delta_ipc_open()
115 struct rpmsg_device *rpmsg_device = delta->rpmsg_device; in delta_ipc_open()
116 struct delta_ipc_ctx *ctx = &pctx->ipc_ctx; in delta_ipc_open()
118 struct delta_buf *buf = &ctx->ipc_buf_struct; in delta_ipc_open()
122 dev_err(delta->dev, in delta_ipc_open()
123 "%s ipc: failed to open, rpmsg is not initialized\n", in delta_ipc_open()
124 pctx->name); in delta_ipc_open()
125 pctx->sys_errors++; in delta_ipc_open()
126 return -EINVAL; in delta_ipc_open()
130 dev_err(delta->dev, in delta_ipc_open()
132 pctx->name); in delta_ipc_open()
133 return -EINVAL; in delta_ipc_open()
136 if (!param || !param->data || !param->size) { in delta_ipc_open()
137 dev_err(delta->dev, in delta_ipc_open()
139 pctx->name); in delta_ipc_open()
140 return -EINVAL; in delta_ipc_open()
144 dev_err(delta->dev, in delta_ipc_open()
146 pctx->name); in delta_ipc_open()
147 return -EINVAL; in delta_ipc_open()
150 if (param->size > ipc_buf_size) { in delta_ipc_open()
151 dev_err(delta->dev, in delta_ipc_open()
153 pctx->name, in delta_ipc_open()
154 param->size, ctx->ipc_buf->size); in delta_ipc_open()
155 return -EINVAL; in delta_ipc_open()
159 init_completion(&ctx->done); in delta_ipc_open()
170 ctx->ipc_buf = buf; in delta_ipc_open()
172 /* build rpmsg message */ in delta_ipc_open()
176 msg.ipc_buf_paddr = ctx->ipc_buf->paddr; in delta_ipc_open()
180 msg.param_size = param->size; in delta_ipc_open()
181 memcpy(ctx->ipc_buf->vaddr, param->data, msg.param_size); in delta_ipc_open()
182 msg.param_paddr = ctx->ipc_buf->paddr; in delta_ipc_open()
185 ret = rpmsg_send(rpmsg_device->ept, &msg, sizeof(msg)); in delta_ipc_open()
187 dev_err(delta->dev, in delta_ipc_open()
189 pctx->name, in delta_ipc_open()
190 ret, name, param->size, param->data); in delta_ipc_open()
196 (&ctx->done, msecs_to_jiffies(IPC_TIMEOUT))) { in delta_ipc_open()
197 dev_err(delta->dev, in delta_ipc_open()
199 pctx->name, in delta_ipc_open()
200 name, param->size, param->data); in delta_ipc_open()
201 ret = -ETIMEDOUT; in delta_ipc_open()
206 if (ctx->cb_err) { in delta_ipc_open()
207 dev_err(delta->dev, in delta_ipc_open()
209 pctx->name, in delta_ipc_open()
210 ctx->cb_err, name, param->size, param->data); in delta_ipc_open()
211 ret = -EIO; in delta_ipc_open()
215 *ipc_buf = ctx->ipc_buf; in delta_ipc_open()
221 pctx->sys_errors++; in delta_ipc_open()
222 hw_free(pctx, ctx->ipc_buf); in delta_ipc_open()
223 ctx->ipc_buf = NULL; in delta_ipc_open()
232 struct delta_dev *delta = pctx->dev; in delta_ipc_set_stream()
233 struct rpmsg_device *rpmsg_device = delta->rpmsg_device; in delta_ipc_set_stream()
238 dev_err(delta->dev, in delta_ipc_set_stream()
240 pctx->name); in delta_ipc_set_stream()
241 return -EINVAL; in delta_ipc_set_stream()
245 dev_err(delta->dev, in delta_ipc_set_stream()
246 "%s ipc: failed to set stream, rpmsg is not initialized\n", in delta_ipc_set_stream()
247 pctx->name); in delta_ipc_set_stream()
248 return -EINVAL; in delta_ipc_set_stream()
251 if (!param || !param->data || !param->size) { in delta_ipc_set_stream()
252 dev_err(delta->dev, in delta_ipc_set_stream()
254 pctx->name); in delta_ipc_set_stream()
255 return -EINVAL; in delta_ipc_set_stream()
258 if (param->size > ctx->ipc_buf->size) { in delta_ipc_set_stream()
259 dev_err(delta->dev, in delta_ipc_set_stream()
261 pctx->name, in delta_ipc_set_stream()
262 param->size, ctx->ipc_buf->size); in delta_ipc_set_stream()
263 return -EINVAL; in delta_ipc_set_stream()
266 if (!is_valid_data(ctx, param->data, param->size)) { in delta_ipc_set_stream()
267 dev_err(delta->dev, in delta_ipc_set_stream()
268 …"%s ipc: failed to set stream, parameter is not in expected address range (size=%d, data=%p not in delta_ipc_set_stream()
269 pctx->name, in delta_ipc_set_stream()
270 param->size, in delta_ipc_set_stream()
271 param->data, in delta_ipc_set_stream()
272 ctx->ipc_buf->vaddr, in delta_ipc_set_stream()
273 ctx->ipc_buf->vaddr + ctx->ipc_buf->size - 1); in delta_ipc_set_stream()
274 return -EINVAL; in delta_ipc_set_stream()
277 /* build rpmsg message */ in delta_ipc_set_stream()
280 msg.param_size = param->size; in delta_ipc_set_stream()
281 msg.param_paddr = to_paddr(ctx, param->data); in delta_ipc_set_stream()
284 ret = rpmsg_send(rpmsg_device->ept, &msg, sizeof(msg)); in delta_ipc_set_stream()
286 dev_err(delta->dev, in delta_ipc_set_stream()
288 pctx->name, in delta_ipc_set_stream()
289 ret, param->size, param->data); in delta_ipc_set_stream()
290 pctx->sys_errors++; in delta_ipc_set_stream()
296 (&ctx->done, msecs_to_jiffies(IPC_TIMEOUT))) { in delta_ipc_set_stream()
297 dev_err(delta->dev, in delta_ipc_set_stream()
299 pctx->name, in delta_ipc_set_stream()
300 param->size, param->data); in delta_ipc_set_stream()
301 pctx->sys_errors++; in delta_ipc_set_stream()
302 return -ETIMEDOUT; in delta_ipc_set_stream()
306 if (ctx->cb_err) { in delta_ipc_set_stream()
307 dev_err(delta->dev, in delta_ipc_set_stream()
309 pctx->name, in delta_ipc_set_stream()
310 ctx->cb_err, param->size, param->data); in delta_ipc_set_stream()
311 pctx->sys_errors++; in delta_ipc_set_stream()
312 return -EIO; in delta_ipc_set_stream()
323 struct delta_dev *delta = pctx->dev; in delta_ipc_decode()
324 struct rpmsg_device *rpmsg_device = delta->rpmsg_device; in delta_ipc_decode()
329 dev_err(delta->dev, in delta_ipc_decode()
331 pctx->name); in delta_ipc_decode()
332 return -EINVAL; in delta_ipc_decode()
336 dev_err(delta->dev, in delta_ipc_decode()
337 "%s ipc: failed to decode, rpmsg is not initialized\n", in delta_ipc_decode()
338 pctx->name); in delta_ipc_decode()
339 return -EINVAL; in delta_ipc_decode()
342 if (!param || !param->data || !param->size) { in delta_ipc_decode()
343 dev_err(delta->dev, in delta_ipc_decode()
345 pctx->name); in delta_ipc_decode()
346 return -EINVAL; in delta_ipc_decode()
349 if (!status || !status->data || !status->size) { in delta_ipc_decode()
350 dev_err(delta->dev, in delta_ipc_decode()
352 pctx->name); in delta_ipc_decode()
353 return -EINVAL; in delta_ipc_decode()
356 if (param->size + status->size > ctx->ipc_buf->size) { in delta_ipc_decode()
357 dev_err(delta->dev, in delta_ipc_decode()
359 pctx->name, in delta_ipc_decode()
360 param->size, in delta_ipc_decode()
361 status->size, in delta_ipc_decode()
362 ctx->ipc_buf->size); in delta_ipc_decode()
363 return -EINVAL; in delta_ipc_decode()
366 if (!is_valid_data(ctx, param->data, param->size)) { in delta_ipc_decode()
367 dev_err(delta->dev, in delta_ipc_decode()
368 …"%s ipc: failed to decode, parameter is not in expected address range (size=%d, data=%p not in %… in delta_ipc_decode()
369 pctx->name, in delta_ipc_decode()
370 param->size, in delta_ipc_decode()
371 param->data, in delta_ipc_decode()
372 ctx->ipc_buf->vaddr, in delta_ipc_decode()
373 ctx->ipc_buf->vaddr + ctx->ipc_buf->size - 1); in delta_ipc_decode()
374 return -EINVAL; in delta_ipc_decode()
377 if (!is_valid_data(ctx, status->data, status->size)) { in delta_ipc_decode()
378 dev_err(delta->dev, in delta_ipc_decode()
379 …"%s ipc: failed to decode, status is not in expected address range (size=%d, data=%p not in %p..… in delta_ipc_decode()
380 pctx->name, in delta_ipc_decode()
381 status->size, in delta_ipc_decode()
382 status->data, in delta_ipc_decode()
383 ctx->ipc_buf->vaddr, in delta_ipc_decode()
384 ctx->ipc_buf->vaddr + ctx->ipc_buf->size - 1); in delta_ipc_decode()
385 return -EINVAL; in delta_ipc_decode()
388 /* build rpmsg message */ in delta_ipc_decode()
391 msg.param_size = param->size; in delta_ipc_decode()
392 msg.param_paddr = to_paddr(ctx, param->data); in delta_ipc_decode()
394 msg.status_size = status->size; in delta_ipc_decode()
395 msg.status_paddr = to_paddr(ctx, status->data); in delta_ipc_decode()
398 ret = rpmsg_send(rpmsg_device->ept, &msg, sizeof(msg)); in delta_ipc_decode()
400 dev_err(delta->dev, in delta_ipc_decode()
402 pctx->name, in delta_ipc_decode()
403 ret, param->size, param->data); in delta_ipc_decode()
404 pctx->sys_errors++; in delta_ipc_decode()
410 (&ctx->done, msecs_to_jiffies(IPC_TIMEOUT))) { in delta_ipc_decode()
411 dev_err(delta->dev, in delta_ipc_decode()
413 pctx->name, in delta_ipc_decode()
414 param->size, param->data); in delta_ipc_decode()
415 pctx->sys_errors++; in delta_ipc_decode()
416 return -ETIMEDOUT; in delta_ipc_decode()
420 if (ctx->cb_err) { in delta_ipc_decode()
421 dev_err(delta->dev, in delta_ipc_decode()
423 pctx->name, in delta_ipc_decode()
424 ctx->cb_err, param->size, param->data); in delta_ipc_decode()
425 pctx->sys_errors++; in delta_ipc_decode()
426 return -EIO; in delta_ipc_decode()
436 struct delta_dev *delta = pctx->dev; in delta_ipc_close()
437 struct rpmsg_device *rpmsg_device = delta->rpmsg_device; in delta_ipc_close()
442 dev_err(delta->dev, in delta_ipc_close()
444 pctx->name); in delta_ipc_close()
448 if (ctx->ipc_buf) { in delta_ipc_close()
449 hw_free(pctx, ctx->ipc_buf); in delta_ipc_close()
450 ctx->ipc_buf = NULL; in delta_ipc_close()
454 dev_err(delta->dev, in delta_ipc_close()
455 "%s ipc: failed to close, rpmsg is not initialized\n", in delta_ipc_close()
456 pctx->name); in delta_ipc_close()
460 /* build rpmsg message */ in delta_ipc_close()
464 ret = rpmsg_send(rpmsg_device->ept, &msg, sizeof(msg)); in delta_ipc_close()
466 dev_err(delta->dev, in delta_ipc_close()
468 pctx->name, ret); in delta_ipc_close()
469 pctx->sys_errors++; in delta_ipc_close()
475 (&ctx->done, msecs_to_jiffies(IPC_TIMEOUT))) { in delta_ipc_close()
476 dev_err(delta->dev, in delta_ipc_close()
478 pctx->name); in delta_ipc_close()
479 pctx->sys_errors++; in delta_ipc_close()
484 if (ctx->cb_err) { in delta_ipc_close()
485 dev_err(delta->dev, in delta_ipc_close()
487 pctx->name, ctx->cb_err); in delta_ipc_close()
488 pctx->sys_errors++; in delta_ipc_close()
501 return -EINVAL; in delta_ipc_cb()
505 dev_err(&rpdev->dev, in delta_ipc_cb()
507 return -EINVAL; in delta_ipc_cb()
511 dev_err(&rpdev->dev, in delta_ipc_cb()
514 return -EINVAL; in delta_ipc_cb()
518 if (msg->header.tag != IPC_SANITY_TAG) { in delta_ipc_cb()
519 dev_err(&rpdev->dev, in delta_ipc_cb()
521 src, msg->header.tag, IPC_SANITY_TAG); in delta_ipc_cb()
522 return -EINVAL; in delta_ipc_cb()
527 dev_err(&rpdev->dev, in delta_ipc_cb()
530 return -EINVAL; in delta_ipc_cb()
535 * to ensure re-entrance on copro side in delta_ipc_cb()
537 if (!ctx->copro_hdl) in delta_ipc_cb()
538 ctx->copro_hdl = msg_to_copro_hdl(msg); in delta_ipc_cb()
544 ctx->cb_err = msg->err; in delta_ipc_cb()
545 complete(&ctx->done); in delta_ipc_cb()
552 struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpmsg_device->dev.driver); in delta_ipc_probe()
555 delta->rpmsg_device = rpmsg_device; in delta_ipc_probe()
562 struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpmsg_device->dev.driver); in delta_ipc_remove()
565 delta->rpmsg_device = NULL; in delta_ipc_remove()
569 {.name = "rpmsg-delta"},
583 delta->rpmsg_driver = delta_rpmsg_driver; in delta_ipc_init()
585 return register_rpmsg_driver(&delta->rpmsg_driver); in delta_ipc_init()
590 unregister_rpmsg_driver(&delta->rpmsg_driver); in delta_ipc_exit()