summaryrefslogtreecommitdiffstats
path: root/drivers/rpmsg
diff options
context:
space:
mode:
authorBjorn Andersson <bjorn.andersson@linaro.org>2016-09-01 18:27:58 -0400
committerBjorn Andersson <bjorn.andersson@linaro.org>2016-09-09 01:15:20 -0400
commit36b72c7dca718717108120cdff7b56258a8862b4 (patch)
treee1a982d2a3e1f9eeb08692f6963d5091600455a3 /drivers/rpmsg
parent92e1de51bf2cb8d49adc8925abe56ce84911a232 (diff)
rpmsg: Introduce indirection table for rpmsg_device operations
To allow for multiple backend implementations add an indireection table for rpmsg_device related operations and move the virtio implementation behind this table. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Diffstat (limited to 'drivers/rpmsg')
-rw-r--r--drivers/rpmsg/virtio_rpmsg_bus.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 1ac9fd871760..088203ed1df8 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -286,10 +286,18 @@ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
286 rpmsg_rx_cb_t cb, void *priv, 286 rpmsg_rx_cb_t cb, void *priv,
287 struct rpmsg_channel_info chinfo) 287 struct rpmsg_channel_info chinfo)
288{ 288{
289 return __rpmsg_create_ept(rpdev->vrp, rpdev, cb, priv, chinfo.src); 289 return rpdev->ops->create_ept(rpdev, cb, priv, chinfo);
290} 290}
291EXPORT_SYMBOL(rpmsg_create_ept); 291EXPORT_SYMBOL(rpmsg_create_ept);
292 292
293static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev,
294 rpmsg_rx_cb_t cb,
295 void *priv,
296 struct rpmsg_channel_info chinfo)
297{
298 return __rpmsg_create_ept(rpdev->vrp, rpdev, cb, priv, chinfo.src);
299}
300
293/** 301/**
294 * __rpmsg_destroy_ept() - destroy an existing rpmsg endpoint 302 * __rpmsg_destroy_ept() - destroy an existing rpmsg endpoint
295 * @vrp: virtproc which owns this ept 303 * @vrp: virtproc which owns this ept
@@ -341,7 +349,6 @@ static int rpmsg_dev_probe(struct device *dev)
341{ 349{
342 struct rpmsg_device *rpdev = to_rpmsg_device(dev); 350 struct rpmsg_device *rpdev = to_rpmsg_device(dev);
343 struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver); 351 struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
344 struct virtproc_info *vrp = rpdev->vrp;
345 struct rpmsg_channel_info chinfo = {}; 352 struct rpmsg_channel_info chinfo = {};
346 struct rpmsg_endpoint *ept; 353 struct rpmsg_endpoint *ept;
347 int err; 354 int err;
@@ -367,6 +374,18 @@ static int rpmsg_dev_probe(struct device *dev)
367 goto out; 374 goto out;
368 } 375 }
369 376
377 if (rpdev->ops->announce_create)
378 err = rpdev->ops->announce_create(rpdev);
379out:
380 return err;
381}
382
383static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev)
384{
385 struct virtproc_info *vrp = rpdev->vrp;
386 struct device *dev = &rpdev->dev;
387 int err = 0;
388
370 /* need to tell remote processor's name service about this channel ? */ 389 /* need to tell remote processor's name service about this channel ? */
371 if (rpdev->announce && 390 if (rpdev->announce &&
372 virtio_has_feature(vrp->vdev, VIRTIO_RPMSG_F_NS)) { 391 virtio_has_feature(vrp->vdev, VIRTIO_RPMSG_F_NS)) {
@@ -381,15 +400,13 @@ static int rpmsg_dev_probe(struct device *dev)
381 dev_err(dev, "failed to announce service %d\n", err); 400 dev_err(dev, "failed to announce service %d\n", err);
382 } 401 }
383 402
384out:
385 return err; 403 return err;
386} 404}
387 405
388static int rpmsg_dev_remove(struct device *dev) 406static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev)
389{ 407{
390 struct rpmsg_device *rpdev = to_rpmsg_device(dev);
391 struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
392 struct virtproc_info *vrp = rpdev->vrp; 408 struct virtproc_info *vrp = rpdev->vrp;
409 struct device *dev = &rpdev->dev;
393 int err = 0; 410 int err = 0;
394 411
395 /* tell remote processor's name service we're removing this channel */ 412 /* tell remote processor's name service we're removing this channel */
@@ -406,6 +423,18 @@ static int rpmsg_dev_remove(struct device *dev)
406 dev_err(dev, "failed to announce service %d\n", err); 423 dev_err(dev, "failed to announce service %d\n", err);
407 } 424 }
408 425
426 return err;
427}
428
429static int rpmsg_dev_remove(struct device *dev)
430{
431 struct rpmsg_device *rpdev = to_rpmsg_device(dev);
432 struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
433 int err = 0;
434
435 if (rpdev->ops->announce_destroy)
436 err = rpdev->ops->announce_destroy(rpdev);
437
409 rpdrv->remove(rpdev); 438 rpdrv->remove(rpdev);
410 439
411 rpmsg_destroy_ept(rpdev->ept); 440 rpmsg_destroy_ept(rpdev->ept);
@@ -479,6 +508,12 @@ static int rpmsg_device_match(struct device *dev, void *data)
479 return 1; 508 return 1;
480} 509}
481 510
511static const struct rpmsg_device_ops virtio_rpmsg_ops = {
512 .create_ept = virtio_rpmsg_create_ept,
513 .announce_create = virtio_rpmsg_announce_create,
514 .announce_destroy = virtio_rpmsg_announce_destroy,
515};
516
482/* 517/*
483 * create an rpmsg channel using its name and address info. 518 * create an rpmsg channel using its name and address info.
484 * this function will be used to create both static and dynamic 519 * this function will be used to create both static and dynamic
@@ -508,6 +543,7 @@ static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp,
508 rpdev->vrp = vrp; 543 rpdev->vrp = vrp;
509 rpdev->src = chinfo->src; 544 rpdev->src = chinfo->src;
510 rpdev->dst = chinfo->dst; 545 rpdev->dst = chinfo->dst;
546 rpdev->ops = &virtio_rpmsg_ops;
511 547
512 /* 548 /*
513 * rpmsg server channels has predefined local address (for now), 549 * rpmsg server channels has predefined local address (for now),