aboutsummaryrefslogtreecommitdiff
path: root/kernel/common/ethosu_driver.c
diff options
context:
space:
mode:
authorMikael Olsson <mikael.olsson@arm.com>2024-02-07 11:22:26 +0100
committerMikael Olsson <mikael.olsson@arm.com>2024-02-12 13:04:41 +0100
commitd4ad9e55cb8e17a4a42b3a94c64e6bc48529b26e (patch)
tree9084d770574bc2a278ddfa121985ac030f711daa /kernel/common/ethosu_driver.c
parent09cdc30b3b3a52176cd02518c07d5f44c1ce8dd1 (diff)
downloadethos-u-linux-driver-stack-d4ad9e55cb8e17a4a42b3a94c64e6bc48529b26e.tar.gz
Restructure kernel driver source tree
As a first step to have a clearer separation of the different parts of the kernel driver, the source files have been placed into separate directories according to their purpose and the different parts are only allowed to use headers from another part in the include folder. Files have been renamed accordingly to namespace them by their purpose. Change-Id: I75e09ebf0002c99a22b6d4b09d34504d186c32b3 Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
Diffstat (limited to 'kernel/common/ethosu_driver.c')
-rw-r--r--kernel/common/ethosu_driver.c161
1 files changed, 161 insertions, 0 deletions
diff --git a/kernel/common/ethosu_driver.c b/kernel/common/ethosu_driver.c
new file mode 100644
index 0000000..15f13b5
--- /dev/null
+++ b/kernel/common/ethosu_driver.c
@@ -0,0 +1,161 @@
+/*
+ * SPDX-FileCopyrightText: Copyright 2020-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
+ * SPDX-License-Identifier: GPL-2.0-only
+ *
+ * This program is free software and is provided to you under the terms of the
+ * GNU General Public License version 2 as published by the Free Software
+ * Foundation, and any use by you of this program is subject to the terms
+ * of such GNU licence.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, you can access it online at
+ * http://www.gnu.org/licenses/gpl-2.0.html.
+ */
+
+#include <common/ethosu_device.h>
+#include <uapi/ethosu.h>
+
+#include <linux/bitmap.h>
+#include <linux/fs.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/rpmsg.h>
+
+/****************************************************************************
+ * Defines
+ ****************************************************************************/
+
+#define ETHOSU_DRIVER_STR(s) #s
+#define ETHOSU_DRIVER_VERSION_STR(major, minor, patch) \
+ ETHOSU_DRIVER_STR(major) "." \
+ ETHOSU_DRIVER_STR(minor) "." \
+ ETHOSU_DRIVER_STR(patch)
+#define ETHOSU_DRIVER_VERSION ETHOSU_DRIVER_VERSION_STR( \
+ ETHOSU_KERNEL_DRIVER_VERSION_MAJOR, \
+ ETHOSU_KERNEL_DRIVER_VERSION_MINOR, \
+ ETHOSU_KERNEL_DRIVER_VERSION_PATCH)
+
+#define ETHOSU_DRIVER_NAME "ethosu"
+
+#define MINOR_BASE 0 /* Minor version starts at 0 */
+#define MINOR_COUNT 64 /* Allocate minor versions */
+
+/****************************************************************************
+ * Variables
+ ****************************************************************************/
+
+static struct class *ethosu_class;
+
+static dev_t devt;
+
+/****************************************************************************
+ * Rpmsg driver
+ ****************************************************************************/
+
+static int ethosu_rpmsg_probe(struct rpmsg_device *rpdev)
+{
+ int ret;
+
+ /* Initialize device */
+ ret = ethosu_dev_init(rpdev, ethosu_class, devt);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static void ethosu_rpmsg_remove(struct rpmsg_device *rpdev)
+{
+ ethosu_dev_deinit(rpdev);
+}
+
+static int ethosu_rpmsg_cb(struct rpmsg_device *rpdev,
+ void *data,
+ int len,
+ void *priv,
+ u32 src)
+{
+ dev_err(&rpdev->dev, "%s", __FUNCTION__);
+
+ return -EINVAL;
+}
+
+static struct rpmsg_device_id ethosu_rpmsg_driver_id_table[] = {
+ { .name = "ethos-u-0.0" },
+ {},
+};
+
+MODULE_DEVICE_TABLE(rpmsg, ethosu_rpmsg_driver_id_table);
+
+static struct rpmsg_driver ethosu_rpmsg_driver = {
+ .drv = {
+ .name = ETHOSU_DRIVER_NAME,
+ .owner = THIS_MODULE,
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
+ },
+ .id_table = ethosu_rpmsg_driver_id_table,
+ .probe = ethosu_rpmsg_probe,
+ .callback = ethosu_rpmsg_cb,
+ .remove = ethosu_rpmsg_remove,
+};
+
+/****************************************************************************
+ * Module init and exit
+ ****************************************************************************/
+
+static void __exit ethosu_exit(void)
+{
+ unregister_rpmsg_driver(&ethosu_rpmsg_driver);
+ unregister_chrdev_region(devt, MINOR_COUNT);
+ class_destroy(ethosu_class);
+}
+
+static int __init ethosu_init(void)
+{
+ int ret;
+
+ ethosu_class = class_create(THIS_MODULE, ETHOSU_DRIVER_NAME);
+ if (IS_ERR(ethosu_class)) {
+ pr_err("Failed to create class '%s'.\n", ETHOSU_DRIVER_NAME);
+
+ return PTR_ERR(ethosu_class);
+ }
+
+ ret = alloc_chrdev_region(&devt, MINOR_BASE, MINOR_COUNT,
+ ETHOSU_DRIVER_NAME);
+ if (ret) {
+ pr_err("Failed to allocate chrdev region.\n");
+ goto destroy_class;
+ }
+
+ ret = register_rpmsg_driver(&ethosu_rpmsg_driver);
+ if (ret) {
+ pr_err("Failed to register Arm Ethos-U rpmsg driver.\n");
+ goto region_unregister;
+ }
+
+ return 0;
+
+region_unregister:
+ unregister_chrdev_region(devt, MINOR_COUNT);
+
+destroy_class:
+ class_destroy(ethosu_class);
+
+ return ret;
+}
+
+module_init(ethosu_init)
+module_exit(ethosu_exit)
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Arm Ltd");
+MODULE_DESCRIPTION("Arm Ethos-U NPU Driver");
+MODULE_VERSION(ETHOSU_DRIVER_VERSION);