aboutsummaryrefslogtreecommitdiff
path: root/kernel/include/common
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/include/common')
-rw-r--r--kernel/include/common/ethosu_buffer.h85
-rw-r--r--kernel/include/common/ethosu_device.h71
-rw-r--r--kernel/include/common/ethosu_dma_mem.h58
3 files changed, 214 insertions, 0 deletions
diff --git a/kernel/include/common/ethosu_buffer.h b/kernel/include/common/ethosu_buffer.h
new file mode 100644
index 0000000..868e783
--- /dev/null
+++ b/kernel/include/common/ethosu_buffer.h
@@ -0,0 +1,85 @@
+/*
+ * SPDX-FileCopyrightText: Copyright 2020, 2022-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.
+ */
+
+#ifndef ETHOSU_BUFFER_H
+#define ETHOSU_BUFFER_H
+
+/****************************************************************************
+ * Includes
+ ****************************************************************************/
+
+#include <linux/kref.h>
+#include <linux/types.h>
+
+/****************************************************************************
+ * Types
+ ****************************************************************************/
+
+struct ethosu_dma_mem;
+struct ethosu_device;
+struct device;
+
+/**
+ * struct ethosu_buffer - User data buffer
+ * @dev: Device
+ * @file: File
+ * @kref: Reference counting
+ * @dma_mem: DMA memory allocated for the buffer
+ */
+struct ethosu_buffer {
+ struct device *dev;
+ struct file *file;
+ struct kref kref;
+ struct ethosu_dma_mem *dma_mem;
+};
+
+/****************************************************************************
+ * Functions
+ ****************************************************************************/
+
+/**
+ * ethosu_buffer_create() - Create buffer
+ *
+ * This function must be called in the context of a user space process.
+ *
+ * Return: fd on success, else error code.
+ */
+int ethosu_buffer_create(struct device *dev,
+ size_t size);
+
+/**
+ * ethosu_buffer_get_from_fd() - Get buffer handle from fd
+ *
+ * This function must be called from a user space context.
+ *
+ * Return: Pointer on success, else ERR_PTR.
+ */
+struct ethosu_buffer *ethosu_buffer_get_from_fd(int fd);
+
+/**
+ * ethosu_buffer_get() - Put buffer
+ */
+void ethosu_buffer_get(struct ethosu_buffer *buf);
+
+/**
+ * ethosu_buffer_put() - Put buffer
+ */
+void ethosu_buffer_put(struct ethosu_buffer *buf);
+
+#endif /* ETHOSU_BUFFER_H */
diff --git a/kernel/include/common/ethosu_device.h b/kernel/include/common/ethosu_device.h
new file mode 100644
index 0000000..e96543e
--- /dev/null
+++ b/kernel/include/common/ethosu_device.h
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+#ifndef ETHOSU_DEVICE_H
+#define ETHOSU_DEVICE_H
+
+/****************************************************************************
+ * Includes
+ ****************************************************************************/
+
+#include <uapi/ethosu.h>
+#include <rpmsg/ethosu_rpmsg_mailbox.h>
+
+#include <linux/device.h>
+#include <linux/cdev.h>
+#include <linux/io.h>
+#include <linux/mutex.h>
+#include <linux/rpmsg.h>
+
+/****************************************************************************
+ * Types
+ ****************************************************************************/
+
+/**
+ * struct ethosu_device - Device structure
+ */
+struct ethosu_device {
+ struct device dev;
+ struct rpmsg_device *rpdev;
+ struct rpmsg_endpoint *ept;
+ struct cdev cdev;
+ struct class *class;
+ struct ethosu_mailbox mailbox;
+ struct ethosu_uapi_device_capabilities capabilities;
+};
+
+/****************************************************************************
+ * Functions
+ ****************************************************************************/
+
+/**
+ * ethosu_dev_init() - Initialize the device
+ *
+ * Return: 0 on success, else error code.
+ */
+int ethosu_dev_init(struct rpmsg_device *rpdev,
+ struct class *class,
+ dev_t devt);
+
+/**
+ * ethosu_dev_deinit() - Initialize the device
+ */
+void ethosu_dev_deinit(struct rpmsg_device *rpdev);
+
+#endif /* ETHOSU_DEVICE_H */
diff --git a/kernel/include/common/ethosu_dma_mem.h b/kernel/include/common/ethosu_dma_mem.h
new file mode 100644
index 0000000..eac4b42
--- /dev/null
+++ b/kernel/include/common/ethosu_dma_mem.h
@@ -0,0 +1,58 @@
+/*
+ * SPDX-FileCopyrightText: Copyright 2023-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.
+ */
+
+#ifndef ETHOSU_DMA_MEM_H
+#define ETHOSU_DMA_MEM_H
+
+/****************************************************************************
+ * Includes
+ ****************************************************************************/
+
+#include <linux/types.h>
+
+/****************************************************************************
+ * Types
+ ****************************************************************************/
+
+struct device;
+
+/**
+ * struct ethosu_dma_mem - DMA memory allocation
+ * @dev: Device
+ * @size: Size of the allocation
+ * @cpu_addr: Kernel mapped address
+ * @dma_addr: DMA address
+ */
+struct ethosu_dma_mem {
+ struct device *dev;
+ size_t size;
+ void *cpu_addr;
+ dma_addr_t dma_addr;
+};
+
+/****************************************************************************
+ * Functions
+ ****************************************************************************/
+
+struct ethosu_dma_mem *ethosu_dma_mem_alloc(struct device *dev,
+ size_t size);
+
+void ethosu_dma_mem_free(struct ethosu_dma_mem **dma_mem);
+
+#endif /* ETHOSU_DMA_MEM_H */