rpmsg: char: Introduce the "rpmsg-raw" channel

For the rpmsg virtio backend, the current implementation of the rpmsg char
only allows to instantiate static(i.e. prefixed source and destination
addresses) end points, and only on the Linux user space initiative.

This patch defines the "rpmsg-raw" channel and registers it to the rpmsg bus.
This registration allows:
- To create the channel at the initiative of the remote processor
  relying on the name service announcement mechanism. In other words the
  /dev/rpmsgX interface is instantiate by the remote processor.
- To use the channel object instead of the endpoint, thus preventing the
  user space from having the knowledge of the remote processor's
  endpoint addresses.
- To rely on udev to be inform when a /dev/rpmsgX is created on remote
  processor request, indicating that the remote processor is ready to
  communicate.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
Link: https://lore.kernel.org/r/20220124102524.295783-11-arnaud.pouliquen@foss.st.com
This commit is contained in:
Arnaud Pouliquen 2022-01-24 11:25:23 +01:00 committed by Bjorn Andersson
parent bea9b79c2d
commit bc69d10665
1 changed files with 60 additions and 0 deletions

View File

@ -431,6 +431,54 @@ int rpmsg_chrdev_eptdev_create(struct rpmsg_device *rpdev, struct device *parent
} }
EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create); EXPORT_SYMBOL(rpmsg_chrdev_eptdev_create);
static int rpmsg_chrdev_probe(struct rpmsg_device *rpdev)
{
struct rpmsg_channel_info chinfo;
struct rpmsg_eptdev *eptdev;
struct device *dev = &rpdev->dev;
memcpy(chinfo.name, rpdev->id.name, RPMSG_NAME_SIZE);
chinfo.src = rpdev->src;
chinfo.dst = rpdev->dst;
eptdev = rpmsg_chrdev_eptdev_alloc(rpdev, dev);
if (IS_ERR(eptdev))
return PTR_ERR(eptdev);
/* Set the default_ept to the rpmsg device endpoint */
eptdev->default_ept = rpdev->ept;
/*
* The rpmsg_ept_cb uses *priv parameter to get its rpmsg_eptdev context.
* Storedit in default_ept *priv field.
*/
eptdev->default_ept->priv = eptdev;
return rpmsg_chrdev_eptdev_add(eptdev, chinfo);
}
static void rpmsg_chrdev_remove(struct rpmsg_device *rpdev)
{
int ret;
ret = device_for_each_child(&rpdev->dev, NULL, rpmsg_chrdev_eptdev_destroy);
if (ret)
dev_warn(&rpdev->dev, "failed to destroy endpoints: %d\n", ret);
}
static struct rpmsg_device_id rpmsg_chrdev_id_table[] = {
{ .name = "rpmsg-raw" },
{ },
};
static struct rpmsg_driver rpmsg_chrdev_driver = {
.probe = rpmsg_chrdev_probe,
.remove = rpmsg_chrdev_remove,
.callback = rpmsg_ept_cb,
.id_table = rpmsg_chrdev_id_table,
.drv.name = "rpmsg_chrdev",
};
static int rpmsg_chrdev_init(void) static int rpmsg_chrdev_init(void)
{ {
int ret; int ret;
@ -441,12 +489,24 @@ static int rpmsg_chrdev_init(void)
return ret; return ret;
} }
ret = register_rpmsg_driver(&rpmsg_chrdev_driver);
if (ret < 0) {
pr_err("rpmsg: failed to register rpmsg raw driver\n");
goto free_region;
}
return 0; return 0;
free_region:
unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX);
return ret;
} }
postcore_initcall(rpmsg_chrdev_init); postcore_initcall(rpmsg_chrdev_init);
static void rpmsg_chrdev_exit(void) static void rpmsg_chrdev_exit(void)
{ {
unregister_rpmsg_driver(&rpmsg_chrdev_driver);
unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX); unregister_chrdev_region(rpmsg_major, RPMSG_DEV_MAX);
} }
module_exit(rpmsg_chrdev_exit); module_exit(rpmsg_chrdev_exit);