aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjorn Andersson <bjorn.andersson@linaro.org>2016-09-01 18:28:02 -0400
committerBjorn Andersson <bjorn.andersson@linaro.org>2016-09-09 01:15:22 -0400
commit8b881c07cb805e1a126d434359706e45864ea2df (patch)
treeb293450e26a612bbd9a04524e65e7b451b17e915
parentc9bd6f422090b874b5877b4cedcd7757eac33117 (diff)
rpmsg: Move helper for finding rpmsg devices to core
Extract and move the helper function for finding rpmsg child devices to the core. Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
-rw-r--r--drivers/rpmsg/rpmsg_core.c33
-rw-r--r--drivers/rpmsg/rpmsg_internal.h31
-rw-r--r--drivers/rpmsg/virtio_rpmsg_bus.c29
3 files changed, 68 insertions, 25 deletions
diff --git a/drivers/rpmsg/rpmsg_core.c b/drivers/rpmsg/rpmsg_core.c
index 3bee8e03a387..81101775fed0 100644
--- a/drivers/rpmsg/rpmsg_core.c
+++ b/drivers/rpmsg/rpmsg_core.c
@@ -22,6 +22,8 @@
22#include <linux/kernel.h> 22#include <linux/kernel.h>
23#include <linux/rpmsg.h> 23#include <linux/rpmsg.h>
24 24
25#include "rpmsg_internal.h"
26
25/** 27/**
26 * rpmsg_create_ept() - create a new rpmsg_endpoint 28 * rpmsg_create_ept() - create a new rpmsg_endpoint
27 * @rpdev: rpmsg channel device 29 * @rpdev: rpmsg channel device
@@ -229,3 +231,34 @@ int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
229 return ept->ops->trysend_offchannel(ept, src, dst, data, len); 231 return ept->ops->trysend_offchannel(ept, src, dst, data, len);
230} 232}
231EXPORT_SYMBOL(rpmsg_trysend_offchannel); 233EXPORT_SYMBOL(rpmsg_trysend_offchannel);
234
235/*
236 * match an rpmsg channel with a channel info struct.
237 * this is used to make sure we're not creating rpmsg devices for channels
238 * that already exist.
239 */
240static int rpmsg_device_match(struct device *dev, void *data)
241{
242 struct rpmsg_channel_info *chinfo = data;
243 struct rpmsg_device *rpdev = to_rpmsg_device(dev);
244
245 if (chinfo->src != RPMSG_ADDR_ANY && chinfo->src != rpdev->src)
246 return 0;
247
248 if (chinfo->dst != RPMSG_ADDR_ANY && chinfo->dst != rpdev->dst)
249 return 0;
250
251 if (strncmp(chinfo->name, rpdev->id.name, RPMSG_NAME_SIZE))
252 return 0;
253
254 /* found a match ! */
255 return 1;
256}
257
258struct device *rpmsg_find_device(struct device *parent,
259 struct rpmsg_channel_info *chinfo)
260{
261 return device_find_child(parent, chinfo, rpmsg_device_match);
262
263}
264EXPORT_SYMBOL(rpmsg_find_device);
diff --git a/drivers/rpmsg/rpmsg_internal.h b/drivers/rpmsg/rpmsg_internal.h
new file mode 100644
index 000000000000..205debf4ea65
--- /dev/null
+++ b/drivers/rpmsg/rpmsg_internal.h
@@ -0,0 +1,31 @@
1/*
2 * remote processor messaging bus internals
3 *
4 * Copyright (C) 2011 Texas Instruments, Inc.
5 * Copyright (C) 2011 Google, Inc.
6 *
7 * Ohad Ben-Cohen <ohad@wizery.com>
8 * Brian Swetland <swetland@google.com>
9 *
10 * This software is licensed under the terms of the GNU General Public
11 * License version 2, as published by the Free Software Foundation, and
12 * may be copied, distributed, and modified under those terms.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#ifndef __RPMSG_INTERNAL_H__
21#define __RPMSG_INTERNAL_H__
22
23#include <linux/rpmsg.h>
24
25#define to_rpmsg_device(d) container_of(d, struct rpmsg_device, dev)
26#define to_rpmsg_driver(d) container_of(d, struct rpmsg_driver, drv)
27
28struct device *rpmsg_find_device(struct device *parent,
29 struct rpmsg_channel_info *chinfo);
30
31#endif
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index 184663276e51..488fd93a290c 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -35,6 +35,8 @@
35#include <linux/mutex.h> 35#include <linux/mutex.h>
36#include <linux/of_device.h> 36#include <linux/of_device.h>
37 37
38#include "rpmsg_internal.h"
39
38/** 40/**
39 * struct virtproc_info - virtual remote processor state 41 * struct virtproc_info - virtual remote processor state
40 * @vdev: the virtio device 42 * @vdev: the virtio device
@@ -452,29 +454,6 @@ static void rpmsg_release_device(struct device *dev)
452 kfree(rpdev); 454 kfree(rpdev);
453} 455}
454 456
455/*
456 * match an rpmsg channel with a channel info struct.
457 * this is used to make sure we're not creating rpmsg devices for channels
458 * that already exist.
459 */
460static int rpmsg_device_match(struct device *dev, void *data)
461{
462 struct rpmsg_channel_info *chinfo = data;
463 struct rpmsg_device *rpdev = to_rpmsg_device(dev);
464
465 if (chinfo->src != RPMSG_ADDR_ANY && chinfo->src != rpdev->src)
466 return 0;
467
468 if (chinfo->dst != RPMSG_ADDR_ANY && chinfo->dst != rpdev->dst)
469 return 0;
470
471 if (strncmp(chinfo->name, rpdev->id.name, RPMSG_NAME_SIZE))
472 return 0;
473
474 /* found a match ! */
475 return 1;
476}
477
478static const struct rpmsg_device_ops virtio_rpmsg_ops = { 457static const struct rpmsg_device_ops virtio_rpmsg_ops = {
479 .create_ept = virtio_rpmsg_create_ept, 458 .create_ept = virtio_rpmsg_create_ept,
480 .announce_create = virtio_rpmsg_announce_create, 459 .announce_create = virtio_rpmsg_announce_create,
@@ -494,7 +473,7 @@ static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp,
494 int ret; 473 int ret;
495 474
496 /* make sure a similar channel doesn't already exist */ 475 /* make sure a similar channel doesn't already exist */
497 tmp = device_find_child(dev, chinfo, rpmsg_device_match); 476 tmp = rpmsg_find_device(dev, chinfo);
498 if (tmp) { 477 if (tmp) {
499 /* decrement the matched device's refcount back */ 478 /* decrement the matched device's refcount back */
500 put_device(tmp); 479 put_device(tmp);
@@ -547,7 +526,7 @@ static int rpmsg_destroy_channel(struct virtproc_info *vrp,
547 struct virtio_device *vdev = vrp->vdev; 526 struct virtio_device *vdev = vrp->vdev;
548 struct device *dev; 527 struct device *dev;
549 528
550 dev = device_find_child(&vdev->dev, chinfo, rpmsg_device_match); 529 dev = rpmsg_find_device(&vdev->dev, chinfo);
551 if (!dev) 530 if (!dev)
552 return -EINVAL; 531 return -EINVAL;
553 532