aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMikael Olsson <mikael.olsson@arm.com>2023-10-17 13:05:38 +0200
committerMikael Olsson <mikael.olsson@arm.com>2023-11-06 09:36:00 +0100
commit075451507cda3e8f543caecacfadf226a69e5a05 (patch)
treed12ec47fa73c61a7bec3543a29c5dd2ae6b66c93 /kernel
parent45d47991f745094e328f32e769c22d811d397b1d (diff)
downloadethos-u-linux-driver-stack-075451507cda3e8f543caecacfadf226a69e5a05.tar.gz
Remove buffer capacity, offset and resize in UAPI
The UAPI no longer supports the buffer capacity, offset and resize functionality. Instead, the UAPI now only accepts a fixed size given at the creation of the buffer. This change was made because the features were not used and made the buffer handling more complicated. The user knows how big buffers they need for their networks so they don't need resize support or partial buffer usage support by having separate size and capacity with an offset. Without these features, the buffer instance no longer needs any IOCTL call support so it has been removed. However, to still be able to check the size of a buffer from its file descriptor, seek support has been implemented so lseek and similar functions can be used to get the size. The driver library's clear function that previously only reset the size and offset values of the buffer will now clear the buffer content instead. These are breaking changes so the Linux kernel NPU driver version and the driver library version have been given major version bumps. All the tests and other applications affected by these changes have been updated accordingly. Change-Id: Ifc34cf04724a95853ad23fd7398dd286f73bcdab Signed-off-by: Mikael Olsson <mikael.olsson@arm.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/ethosu_buffer.c126
-rw-r--r--kernel/ethosu_buffer.h25
-rw-r--r--kernel/ethosu_device.c6
-rw-r--r--kernel/ethosu_inference.c23
-rw-r--r--kernel/ethosu_mailbox.c16
-rw-r--r--kernel/uapi/ethosu.h20
6 files changed, 54 insertions, 162 deletions
diff --git a/kernel/ethosu_buffer.c b/kernel/ethosu_buffer.c
index 07c8033..bf7d745 100644
--- a/kernel/ethosu_buffer.c
+++ b/kernel/ethosu_buffer.c
@@ -15,7 +15,6 @@
* 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.
- *
*/
/****************************************************************************
@@ -45,17 +44,14 @@ static int ethosu_buffer_release(struct inode *inode,
static int ethosu_buffer_mmap(struct file *file,
struct vm_area_struct *vma);
-static long ethosu_buffer_ioctl(struct file *file,
- unsigned int cmd,
- unsigned long arg);
+static loff_t ethosu_buffer_llseek(struct file *file,
+ loff_t offset,
+ int whence);
static const struct file_operations ethosu_buffer_fops = {
- .release = &ethosu_buffer_release,
- .mmap = &ethosu_buffer_mmap,
- .unlocked_ioctl = &ethosu_buffer_ioctl,
-#ifdef CONFIG_COMPAT
- .compat_ioctl = &ethosu_buffer_ioctl,
-#endif
+ .release = &ethosu_buffer_release,
+ .mmap = &ethosu_buffer_mmap,
+ .llseek = &ethosu_buffer_llseek,
};
/****************************************************************************
@@ -75,8 +71,8 @@ static void ethosu_buffer_destroy(struct kref *kref)
dev_dbg(dev, "Buffer destroy. buf=0x%pK", buf);
- memset(buf->cpu_addr, 0, buf->capacity);
- dma_free_coherent(dev, buf->capacity, buf->cpu_addr,
+ memset(buf->cpu_addr, 0, buf->size);
+ dma_free_coherent(dev, buf->size, buf->cpu_addr,
buf->dma_addr);
memset(buf, 0, sizeof(*buf));
@@ -108,78 +104,43 @@ static int ethosu_buffer_mmap(struct file *file,
file, buf);
ret = dma_mmap_coherent(dev, vma, buf->cpu_addr,
- buf->dma_addr, buf->capacity);
+ buf->dma_addr, buf->size);
return ret;
}
-static long ethosu_buffer_ioctl(struct file *file,
- unsigned int cmd,
- unsigned long arg)
+static loff_t ethosu_buffer_llseek(struct file *file,
+ loff_t offset,
+ int whence)
{
struct ethosu_buffer *buf = file->private_data;
- struct device *dev = buf->dev;
- void __user *udata = (void __user *)arg;
- int ret;
-
- ret = device_lock_interruptible(dev);
- if (ret)
- return ret;
-
- switch (cmd) {
- case ETHOSU_IOCTL_BUFFER_SET: {
- struct ethosu_uapi_buffer uapi;
-
- if (copy_from_user(&uapi, udata, sizeof(uapi))) {
- ret = -EFAULT;
- break;
- }
-
- dev_dbg(dev,
- "Buffer ioctl: Buffer set. size=%u, offset=%u\n",
- uapi.size, uapi.offset);
- ret = ethosu_buffer_resize(buf, uapi.size, uapi.offset);
- break;
- }
- case ETHOSU_IOCTL_BUFFER_GET: {
- struct ethosu_uapi_buffer uapi = { 0 };
-
- uapi.size = buf->size;
- uapi.offset = buf->offset;
-
- dev_dbg(dev,
- "Buffer ioctl: Buffer get. size=%u, offset=%u\n",
- uapi.size, uapi.offset);
-
- if (copy_to_user(udata, &uapi, sizeof(uapi))) {
- ret = -EFAULT;
- break;
- }
+ if (offset != 0)
+ return -EINVAL;
- ret = 0;
- break;
- }
- default: {
- dev_err(dev, "Invalid ioctl. cmd=%u, arg=%lu",
- cmd, arg);
- ret = -ENOIOCTLCMD;
- break;
- }
+ /*
+ * SEEK_END and SEEK_SET is supported with a zero offset to allow buffer
+ * size discovery using seek functions e.g.
+ * size = lseek(buf_fd, 0, SEEK_END);
+ * lseek(buf_fd, 0, SEEK_SET);
+ */
+ switch (whence) {
+ case SEEK_END:
+ return buf->size;
+ case SEEK_SET:
+ return 0;
+ default:
+ return -EINVAL;
}
-
- device_unlock(dev);
-
- return ret;
}
int ethosu_buffer_create(struct device *dev,
- size_t capacity)
+ size_t size)
{
struct ethosu_buffer *buf;
int ret = -ENOMEM;
- if (!capacity)
+ if (!size)
return -EINVAL;
buf = devm_kzalloc(dev, sizeof(*buf), GFP_KERNEL);
@@ -187,13 +148,11 @@ int ethosu_buffer_create(struct device *dev,
return -ENOMEM;
buf->dev = dev;
- buf->capacity = capacity;
- buf->offset = 0;
- buf->size = 0;
+ buf->size = size;
kref_init(&buf->kref);
- buf->cpu_addr = dma_alloc_coherent(dev, capacity,
- &buf->dma_addr, GFP_KERNEL);
+ buf->cpu_addr = dma_alloc_coherent(dev, size, &buf->dma_addr,
+ GFP_KERNEL);
if (!buf->cpu_addr)
goto free_buf;
@@ -203,17 +162,19 @@ int ethosu_buffer_create(struct device *dev,
goto free_dma;
buf->file = fget(ret);
+ buf->file->f_mode |= FMODE_LSEEK;
+
fput(buf->file);
dev_dbg(dev,
- "Buffer create. file=0x%pK, fd=%d, buf=0x%pK, capacity=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, phys_addr=0x%llx\n",
- buf->file, ret, buf, capacity, buf->cpu_addr, buf->dma_addr,
+ "Buffer create. file=0x%pK, fd=%d, buf=0x%pK, size=%zu, cpu_addr=0x%pK, dma_addr=0x%llx, phys_addr=0x%llx\n",
+ buf->file, ret, buf, size, buf->cpu_addr, buf->dma_addr,
virt_to_phys(buf->cpu_addr));
return ret;
free_dma:
- dma_free_coherent(dev, buf->capacity, buf->cpu_addr,
+ dma_free_coherent(dev, buf->size, buf->cpu_addr,
buf->dma_addr);
free_buf:
@@ -254,16 +215,3 @@ void ethosu_buffer_put(struct ethosu_buffer *buf)
{
kref_put(&buf->kref, ethosu_buffer_destroy);
}
-
-int ethosu_buffer_resize(struct ethosu_buffer *buf,
- size_t size,
- size_t offset)
-{
- if ((size + offset) > buf->capacity)
- return -EINVAL;
-
- buf->size = size;
- buf->offset = offset;
-
- return 0;
-}
diff --git a/kernel/ethosu_buffer.h b/kernel/ethosu_buffer.h
index bc5958c..1829fbe 100644
--- a/kernel/ethosu_buffer.h
+++ b/kernel/ethosu_buffer.h
@@ -1,5 +1,6 @@
/*
- * Copyright 2020,2022-2023 Arm Limited and/or its affiliates
+ * SPDX-FileCopyrightText: Copyright 2020,2022-2023 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
@@ -14,8 +15,6 @@
* 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.
- *
- * SPDX-License-Identifier: GPL-2.0-only
*/
#ifndef ETHOSU_BUFFER_H
@@ -40,21 +39,14 @@ struct device;
* @dev: Device
* @file: File
* @kref: Reference counting
- * @capacity: Maximum capacity of the buffer
- * @offset: Offset to first byte of buffer
- * @size: Size of the data in the buffer
+ * @size: Size of the buffer
* @cpu_addr: Kernel mapped address
* @dma_addr: DMA address
- * @dma_addr_orig: Original DMA address before range mapping
- *
- * 'offset + size' must not be larger than 'capacity'.
*/
struct ethosu_buffer {
struct device *dev;
struct file *file;
struct kref kref;
- size_t capacity;
- size_t offset;
size_t size;
void *cpu_addr;
dma_addr_t dma_addr;
@@ -72,7 +64,7 @@ struct ethosu_buffer {
* Return: fd on success, else error code.
*/
int ethosu_buffer_create(struct device *dev,
- size_t capacity);
+ size_t size);
/**
* ethosu_buffer_get_from_fd() - Get buffer handle from fd
@@ -93,13 +85,4 @@ void ethosu_buffer_get(struct ethosu_buffer *buf);
*/
void ethosu_buffer_put(struct ethosu_buffer *buf);
-/**
- * ethosu_buffer_resize() - Resize and validate buffer
- *
- * Return: 0 on success, else error code.
- */
-int ethosu_buffer_resize(struct ethosu_buffer *buf,
- size_t size,
- size_t offset);
-
#endif /* ETHOSU_BUFFER_H */
diff --git a/kernel/ethosu_device.c b/kernel/ethosu_device.c
index 8e21512..73ddb2e 100644
--- a/kernel/ethosu_device.c
+++ b/kernel/ethosu_device.c
@@ -290,10 +290,10 @@ static long ethosu_ioctl(struct file *file,
return ret;
dev_dbg(dev,
- "Device ioctl: Buffer create. capacity=%u",
- uapi.capacity);
+ "Device ioctl: Buffer create. size=%u",
+ uapi.size);
- ret = ethosu_buffer_create(dev, uapi.capacity);
+ ret = ethosu_buffer_create(dev, uapi.size);
device_unlock(dev);
diff --git a/kernel/ethosu_inference.c b/kernel/ethosu_inference.c
index 5c57074..b985e75 100644
--- a/kernel/ethosu_inference.c
+++ b/kernel/ethosu_inference.c
@@ -15,7 +15,6 @@
* 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.
- *
*/
/****************************************************************************
@@ -426,7 +425,6 @@ void ethosu_inference_rsp(struct ethosu_mailbox *mailbox,
struct device *dev = mailbox->dev;
struct ethosu_mailbox_msg *msg;
struct ethosu_inference *inf;
- int ret;
int i;
msg = ethosu_mailbox_find(mailbox, msg_id,
@@ -442,27 +440,14 @@ void ethosu_inference_rsp(struct ethosu_mailbox *mailbox,
inf = container_of(msg, typeof(*inf), msg);
if (rsp->status == ETHOSU_CORE_STATUS_OK &&
- inf->ofm_count <= ETHOSU_CORE_BUFFER_MAX) {
- uint32_t i;
-
+ inf->ofm_count <= ETHOSU_CORE_BUFFER_MAX)
inf->status = ETHOSU_UAPI_STATUS_OK;
-
- for (i = 0; i < inf->ofm_count; i++) {
- struct ethosu_buffer *ofm = inf->ofm[i];
-
- ret = ethosu_buffer_resize(
- ofm, ofm->size + rsp->ofm_size[i],
- ofm->offset);
- if (ret)
- inf->status = ETHOSU_UAPI_STATUS_ERROR;
- }
- } else if (rsp->status == ETHOSU_CORE_STATUS_REJECTED) {
+ else if (rsp->status == ETHOSU_CORE_STATUS_REJECTED)
inf->status = ETHOSU_UAPI_STATUS_REJECTED;
- } else if (rsp->status == ETHOSU_CORE_STATUS_ABORTED) {
+ else if (rsp->status == ETHOSU_CORE_STATUS_ABORTED)
inf->status = ETHOSU_UAPI_STATUS_ABORTED;
- } else {
+ else
inf->status = ETHOSU_UAPI_STATUS_ERROR;
- }
if (inf->status == ETHOSU_UAPI_STATUS_OK) {
for (i = 0; i < ETHOSU_CORE_PMU_MAX; i++) {
diff --git a/kernel/ethosu_mailbox.c b/kernel/ethosu_mailbox.c
index 5cc2465..e499860 100644
--- a/kernel/ethosu_mailbox.c
+++ b/kernel/ethosu_mailbox.c
@@ -1,5 +1,6 @@
/*
- * Copyright 2020-2023 Arm Limited and/or its affiliates
+ * SPDX-FileCopyrightText: Copyright 2020-2023 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
@@ -14,8 +15,6 @@
* 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.
- *
- * SPDX-License-Identifier: GPL-2.0-only
*/
/****************************************************************************
@@ -125,17 +124,10 @@ static int ethosu_send_locked(struct ethosu_mailbox *mbox,
static void ethosu_core_set_size(struct ethosu_buffer *buf,
struct ethosu_core_buffer *cbuf)
{
- cbuf->ptr = (uint32_t)buf->dma_addr + buf->offset;
+ cbuf->ptr = (uint32_t)buf->dma_addr;
cbuf->size = (uint32_t)buf->size;
}
-static void ethosu_core_set_capacity(struct ethosu_buffer *buf,
- struct ethosu_core_buffer *cbuf)
-{
- cbuf->ptr = (uint32_t)buf->dma_addr + buf->offset + buf->size;
- cbuf->size = (uint32_t)buf->capacity - buf->offset - buf->size;
-}
-
int ethosu_mailbox_register(struct ethosu_mailbox *mbox,
struct ethosu_mailbox_msg *msg)
{
@@ -278,7 +270,7 @@ int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
ethosu_core_set_size(ifm[i], &inf_req->ifm[i]);
for (i = 0; i < ofm_count; i++)
- ethosu_core_set_capacity(ofm[i], &inf_req->ofm[i]);
+ ethosu_core_set_size(ofm[i], &inf_req->ofm[i]);
for (i = 0; i < ETHOSU_CORE_PMU_MAX; i++)
inf_req->pmu_event_config[i] = pmu_event_config[i];
diff --git a/kernel/uapi/ethosu.h b/kernel/uapi/ethosu.h
index 69f8d3a..4e4d180 100644
--- a/kernel/uapi/ethosu.h
+++ b/kernel/uapi/ethosu.h
@@ -49,10 +49,6 @@ namespace EthosU {
struct ethosu_uapi_kernel_driver_version)
#define ETHOSU_IOCTL_BUFFER_CREATE ETHOSU_IOR(0x10, \
struct ethosu_uapi_buffer_create)
-#define ETHOSU_IOCTL_BUFFER_SET ETHOSU_IOR(0x11, \
- struct ethosu_uapi_buffer)
-#define ETHOSU_IOCTL_BUFFER_GET ETHOSU_IOW(0x12, \
- struct ethosu_uapi_buffer)
#define ETHOSU_IOCTL_NETWORK_CREATE ETHOSU_IOR(0x20, \
struct ethosu_uapi_network_create)
#define ETHOSU_IOCTL_NETWORK_INFO ETHOSU_IOR(0x21, \
@@ -71,7 +67,7 @@ namespace EthosU {
#define ETHOSU_PMU_EVENT_MAX 8
/* Kernel driver version */
-#define ETHOSU_KERNEL_DRIVER_VERSION_MAJOR 1
+#define ETHOSU_KERNEL_DRIVER_VERSION_MAJOR 2
#define ETHOSU_KERNEL_DRIVER_VERSION_MINOR 0
#define ETHOSU_KERNEL_DRIVER_VERSION_PATCH 0
@@ -105,21 +101,9 @@ struct ethosu_uapi_kernel_driver_version {
/**
* struct ethosu_uapi_buffer_create - Create buffer request
- * @capacity: Maximum capacity of the buffer
+ * @size: Size of the requested buffer
*/
struct ethosu_uapi_buffer_create {
- __u32 capacity;
-};
-
-/**
- * struct ethosu_uapi_buffer - Buffer descriptor
- * @offset: Offset to where the data starts
- * @size: Size of the data
- *
- * 'offset + size' must not exceed the capacity of the buffer.
- */
-struct ethosu_uapi_buffer {
- __u32 offset;
__u32 size;
};