Skip to content

Commit 69265bc

Browse files
arnopoandersson
authored andcommitted
rpmsg: char: Export eptdev create and destroy functions
To prepare the split of the code related to the control (ctrldev) and the endpoint (eptdev) devices in 2 separate files: - Rename and export the functions in rpmsg_char.h. - Suppress the dependency with the rpmsg_ctrldev struct in the rpmsg_eptdev_create function. Suggested-by: Mathieu Poirier <mathieu.poirier@linaro.org> Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org> Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org> Link: https://lore.kernel.org/r/20220124102524.295783-2-arnaud.pouliquen@foss.st.com
1 parent cbf5825 commit 69265bc

File tree

2 files changed

+57
-7
lines changed

2 files changed

+57
-7
lines changed

drivers/rpmsg/rpmsg_char.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/*
3+
* Copyright (C) 2022, STMicroelectronics
34
* Copyright (c) 2016, Linaro Ltd.
45
* Copyright (c) 2012, Michal Simek <monstr@monstr.eu>
56
* Copyright (c) 2012, PetaLogix
@@ -25,6 +26,8 @@
2526
#include <linux/uaccess.h>
2627
#include <uapi/linux/rpmsg.h>
2728

29+
#include "rpmsg_char.h"
30+
2831
#define RPMSG_DEV_MAX (MINORMASK + 1)
2932

3033
static dev_t rpmsg_major;
@@ -79,7 +82,7 @@ struct rpmsg_eptdev {
7982
wait_queue_head_t readq;
8083
};
8184

82-
static int rpmsg_eptdev_destroy(struct device *dev, void *data)
85+
int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data)
8386
{
8487
struct rpmsg_eptdev *eptdev = dev_to_eptdev(dev);
8588

@@ -98,6 +101,7 @@ static int rpmsg_eptdev_destroy(struct device *dev, void *data)
98101

99102
return 0;
100103
}
104+
EXPORT_SYMBOL(rpmsg_chrdev_eptdev_destroy);
101105

102106
static int rpmsg_ept_cb(struct rpmsg_device *rpdev, void *buf, int len,
103107
void *priv, u32 addr)
@@ -284,7 +288,7 @@ static long rpmsg_eptdev_ioctl(struct file *fp, unsigned int cmd,
284288
if (cmd != RPMSG_DESTROY_EPT_IOCTL)
285289
return -EINVAL;
286290

287-
return rpmsg_eptdev_destroy(&eptdev->dev, NULL);
291+
return rpmsg_chrdev_eptdev_destroy(&eptdev->dev, NULL);
288292
}
289293

290294
static const struct file_operations rpmsg_eptdev_fops = {
@@ -342,10 +346,9 @@ static void rpmsg_eptdev_release_device(struct device *dev)
342346
kfree(eptdev);
343347
}
344348

345-
static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev,
349+
int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
346350
struct rpmsg_channel_info chinfo)
347351
{
348-
struct rpmsg_device *rpdev = ctrldev->rpdev;
349352
struct rpmsg_eptdev *eptdev;
350353
struct device *dev;
351354
int ret;
@@ -365,7 +368,7 @@ static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev,
365368

366369
device_initialize(dev);
367370
dev->class = rpmsg_class;
368-
dev->parent = &ctrldev->dev;
371+
dev->parent = parent;
369372
dev->groups = rpmsg_eptdev_groups;
370373
dev_set_drvdata(dev, eptdev);
371374

@@ -402,6 +405,7 @@ static int rpmsg_eptdev_create(struct rpmsg_ctrldev *ctrldev,
402405

403406
return ret;
404407
}
408+
EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create);
405409

406410
static int rpmsg_ctrldev_open(struct inode *inode, struct file *filp)
407411
{
@@ -441,7 +445,7 @@ static long rpmsg_ctrldev_ioctl(struct file *fp, unsigned int cmd,
441445
chinfo.src = eptinfo.src;
442446
chinfo.dst = eptinfo.dst;
443447

444-
return rpmsg_eptdev_create(ctrldev, chinfo);
448+
return rpmsg_chrdev_eptdev_create(ctrldev->rpdev, &ctrldev->dev, chinfo);
445449
};
446450

447451
static const struct file_operations rpmsg_ctrldev_fops = {
@@ -520,7 +524,7 @@ static void rpmsg_chrdev_remove(struct rpmsg_device *rpdev)
520524
int ret;
521525

522526
/* Destroy all endpoints */
523-
ret = device_for_each_child(&ctrldev->dev, NULL, rpmsg_eptdev_destroy);
527+
ret = device_for_each_child(&ctrldev->dev, NULL, rpmsg_chrdev_eptdev_destroy);
524528
if (ret)
525529
dev_warn(&rpdev->dev, "failed to nuke endpoints: %d\n", ret);
526530

drivers/rpmsg/rpmsg_char.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (C) 2022, STMicroelectronics
4+
*/
5+
6+
#ifndef __RPMSG_CHRDEV_H__
7+
#define __RPMSG_CHRDEV_H__
8+
9+
#if IS_ENABLED(CONFIG_RPMSG_CHAR)
10+
/**
11+
* rpmsg_chrdev_eptdev_create() - register char device based on an endpoint
12+
* @rpdev: prepared rpdev to be used for creating endpoints
13+
* @parent: parent device
14+
* @chinfo: associated endpoint channel information.
15+
*
16+
* This function create a new rpmsg char endpoint device to instantiate a new
17+
* endpoint based on chinfo information.
18+
*/
19+
int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
20+
struct rpmsg_channel_info chinfo);
21+
22+
/**
23+
* rpmsg_chrdev_eptdev_destroy() - destroy created char device endpoint.
24+
* @data: private data associated to the endpoint device
25+
*
26+
* This function destroys a rpmsg char endpoint device created by the RPMSG_DESTROY_EPT_IOCTL
27+
* control.
28+
*/
29+
int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data);
30+
31+
#else /*IS_ENABLED(CONFIG_RPMSG_CHAR) */
32+
33+
static inline int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent,
34+
struct rpmsg_channel_info chinfo)
35+
{
36+
return -ENXIO;
37+
}
38+
39+
static inline int rpmsg_chrdev_eptdev_destroy(struct device *dev, void *data)
40+
{
41+
return -ENXIO;
42+
}
43+
44+
#endif /*IS_ENABLED(CONFIG_RPMSG_CHAR) */
45+
46+
#endif /*__RPMSG_CHRDEV_H__ */

0 commit comments

Comments
 (0)