Lines Matching +full:rpmsg +full:- +full:channel +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0
10 * Based on rpmsg performance statistics driver by Michal Simek, which in turn
11 * was based on TI & Google OMX rpmsg driver.
22 #include <linux/rpmsg.h>
26 #include <uapi/linux/rpmsg.h>
42 * struct rpmsg_ctrldev - control device for instantiating endpoint devices
43 * @rpdev: underlaying rpmsg device
57 struct rpmsg_ctrldev *ctrldev = cdev_to_ctrldev(inode->i_cdev); in rpmsg_ctrldev_open()
59 get_device(&ctrldev->dev); in rpmsg_ctrldev_open()
60 filp->private_data = ctrldev; in rpmsg_ctrldev_open()
67 struct rpmsg_ctrldev *ctrldev = cdev_to_ctrldev(inode->i_cdev); in rpmsg_ctrldev_release()
69 put_device(&ctrldev->dev); in rpmsg_ctrldev_release()
77 struct rpmsg_ctrldev *ctrldev = fp->private_data; in rpmsg_ctrldev_ioctl()
85 return -EFAULT; in rpmsg_ctrldev_ioctl()
87 memcpy(chinfo.name, eptinfo.name, RPMSG_NAME_SIZE); in rpmsg_ctrldev_ioctl()
88 chinfo.name[RPMSG_NAME_SIZE - 1] = '\0'; in rpmsg_ctrldev_ioctl()
92 mutex_lock(&ctrldev->ctrl_lock); in rpmsg_ctrldev_ioctl()
95 ret = rpmsg_chrdev_eptdev_create(ctrldev->rpdev, &ctrldev->dev, chinfo); in rpmsg_ctrldev_ioctl()
99 rpdev = rpmsg_create_channel(ctrldev->rpdev, &chinfo); in rpmsg_ctrldev_ioctl()
101 dev_err(&ctrldev->dev, "failed to create %s channel\n", chinfo.name); in rpmsg_ctrldev_ioctl()
102 ret = -ENXIO; in rpmsg_ctrldev_ioctl()
107 ret = rpmsg_release_channel(ctrldev->rpdev, &chinfo); in rpmsg_ctrldev_ioctl()
109 dev_err(&ctrldev->dev, "failed to release %s channel (%d)\n", in rpmsg_ctrldev_ioctl()
110 chinfo.name, ret); in rpmsg_ctrldev_ioctl()
114 ret = -EINVAL; in rpmsg_ctrldev_ioctl()
116 mutex_unlock(&ctrldev->ctrl_lock); in rpmsg_ctrldev_ioctl()
133 ida_free(&rpmsg_ctrl_ida, dev->id); in rpmsg_ctrldev_release_device()
134 ida_free(&rpmsg_minor_ida, MINOR(dev->devt)); in rpmsg_ctrldev_release_device()
146 return -ENOMEM; in rpmsg_ctrldev_probe()
148 ctrldev->rpdev = rpdev; in rpmsg_ctrldev_probe()
150 dev = &ctrldev->dev; in rpmsg_ctrldev_probe()
152 dev->parent = &rpdev->dev; in rpmsg_ctrldev_probe()
153 dev->class = &rpmsg_class; in rpmsg_ctrldev_probe()
155 mutex_init(&ctrldev->ctrl_lock); in rpmsg_ctrldev_probe()
156 cdev_init(&ctrldev->cdev, &rpmsg_ctrldev_fops); in rpmsg_ctrldev_probe()
157 ctrldev->cdev.owner = THIS_MODULE; in rpmsg_ctrldev_probe()
159 ret = ida_alloc_max(&rpmsg_minor_ida, RPMSG_DEV_MAX - 1, GFP_KERNEL); in rpmsg_ctrldev_probe()
162 dev->devt = MKDEV(MAJOR(rpmsg_major), ret); in rpmsg_ctrldev_probe()
167 dev->id = ret; in rpmsg_ctrldev_probe()
168 dev_set_name(&ctrldev->dev, "rpmsg_ctrl%d", ret); in rpmsg_ctrldev_probe()
170 ret = cdev_device_add(&ctrldev->cdev, &ctrldev->dev); in rpmsg_ctrldev_probe()
175 dev->release = rpmsg_ctrldev_release_device; in rpmsg_ctrldev_probe()
177 dev_set_drvdata(&rpdev->dev, ctrldev); in rpmsg_ctrldev_probe()
182 ida_free(&rpmsg_ctrl_ida, dev->id); in rpmsg_ctrldev_probe()
184 ida_free(&rpmsg_minor_ida, MINOR(dev->devt)); in rpmsg_ctrldev_probe()
194 struct rpmsg_ctrldev *ctrldev = dev_get_drvdata(&rpdev->dev); in rpmsg_ctrldev_remove()
197 mutex_lock(&ctrldev->ctrl_lock); in rpmsg_ctrldev_remove()
199 ret = device_for_each_child(&ctrldev->dev, NULL, rpmsg_chrdev_eptdev_destroy); in rpmsg_ctrldev_remove()
201 dev_warn(&rpdev->dev, "failed to nuke endpoints: %d\n", ret); in rpmsg_ctrldev_remove()
202 mutex_unlock(&ctrldev->ctrl_lock); in rpmsg_ctrldev_remove()
204 cdev_device_del(&ctrldev->cdev, &ctrldev->dev); in rpmsg_ctrldev_remove()
205 put_device(&ctrldev->dev); in rpmsg_ctrldev_remove()
212 .name = "rpmsg_ctrl",
228 pr_err("failed to register rpmsg driver\n"); in rpmsg_ctrldev_init()
243 MODULE_DESCRIPTION("rpmsg control interface");
244 MODULE_ALIAS("rpmsg:" KBUILD_MODNAME);