linux/drivers/rpmsg/rpmsg_ctrl.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2022, STMicroelectronics
 * Copyright (c) 2016, Linaro Ltd.
 * Copyright (c) 2012, Michal Simek <[email protected]>
 * Copyright (c) 2012, PetaLogix
 * Copyright (c) 2011, Texas Instruments, Inc.
 * Copyright (c) 2011, Google, Inc.
 *
 * Based on rpmsg performance statistics driver by Michal Simek, which in turn
 * was based on TI & Google OMX rpmsg driver.
 */

#define pr_fmt(fmt)

#include <linux/cdev.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/idr.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/rpmsg.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <uapi/linux/rpmsg.h>

#include "rpmsg_char.h"
#include "rpmsg_internal.h"

#define RPMSG_DEV_MAX

static dev_t rpmsg_major;

static DEFINE_IDA(rpmsg_ctrl_ida);
static DEFINE_IDA(rpmsg_minor_ida);

#define dev_to_ctrldev(dev)
#define cdev_to_ctrldev(i_cdev)

/**
 * struct rpmsg_ctrldev - control device for instantiating endpoint devices
 * @rpdev:	underlaying rpmsg device
 * @cdev:	cdev for the ctrl device
 * @dev:	device for the ctrl device
 * @ctrl_lock:	serialize the ioctrls.
 */
struct rpmsg_ctrldev {};

static int rpmsg_ctrldev_open(struct inode *inode, struct file *filp)
{}

static int rpmsg_ctrldev_release(struct inode *inode, struct file *filp)
{}

static long rpmsg_ctrldev_ioctl(struct file *fp, unsigned int cmd,
				unsigned long arg)
{
	struct rpmsg_ctrldev *ctrldev = fp->private_data;
	void __user *argp = (void __user *)arg;
	struct rpmsg_endpoint_info eptinfo;
	struct rpmsg_channel_info chinfo;
	struct rpmsg_device *rpdev;
	int ret = 0;

	if (copy_from_user(&eptinfo, argp, sizeof(eptinfo)))
		return -EFAULT;

	memcpy(chinfo.name, eptinfo.name, RPMSG_NAME_SIZE);
	chinfo.name[RPMSG_NAME_SIZE - 1] = '\0';
	chinfo.src = eptinfo.src;
	chinfo.dst = eptinfo.dst;

	mutex_lock(&ctrldev->ctrl_lock);
	switch (cmd) {
	case RPMSG_CREATE_EPT_IOCTL:
		ret = rpmsg_chrdev_eptdev_create(ctrldev->rpdev, &ctrldev->dev, chinfo);
		break;

	case RPMSG_CREATE_DEV_IOCTL:
		rpdev = rpmsg_create_channel(ctrldev->rpdev, &chinfo);
		if (!rpdev) {
			dev_err(&ctrldev->dev, "failed to create %s channel\n", chinfo.name);
			ret = -ENXIO;
		}
		break;

	case RPMSG_RELEASE_DEV_IOCTL:
		ret = rpmsg_release_channel(ctrldev->rpdev, &chinfo);
		if (ret)
			dev_err(&ctrldev->dev, "failed to release %s channel (%d)\n",
				chinfo.name, ret);
		break;

	default:
		ret = -EINVAL;
	}
	mutex_unlock(&ctrldev->ctrl_lock);

	return ret;
};

static const struct file_operations rpmsg_ctrldev_fops =;

static void rpmsg_ctrldev_release_device(struct device *dev)
{}

static int rpmsg_ctrldev_probe(struct rpmsg_device *rpdev)
{}

static void rpmsg_ctrldev_remove(struct rpmsg_device *rpdev)
{}

static struct rpmsg_driver rpmsg_ctrldev_driver =;

static int rpmsg_ctrldev_init(void)
{}
postcore_initcall(rpmsg_ctrldev_init);

static void rpmsg_ctrldev_exit(void)
{}
module_exit(rpmsg_ctrldev_exit);

MODULE_DESCRIPTION();
MODULE_ALIAS();
MODULE_LICENSE();