Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
Mikael Olsson | 0754515 | 2023-10-17 13:05:38 +0200 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright 2020,2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 3 | * SPDX-License-Identifier: GPL-2.0-only |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software and is provided to you under the terms of the |
| 6 | * GNU General Public License version 2 as published by the Free Software |
| 7 | * Foundation, and any use by you of this program is subject to the terms |
| 8 | * of such GNU licence. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, you can access it online at |
| 17 | * http://www.gnu.org/licenses/gpl-2.0.html. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #ifndef ETHOSU_BUFFER_H |
| 21 | #define ETHOSU_BUFFER_H |
| 22 | |
| 23 | /**************************************************************************** |
| 24 | * Includes |
| 25 | ****************************************************************************/ |
| 26 | |
| 27 | #include <linux/kref.h> |
| 28 | #include <linux/types.h> |
| 29 | |
| 30 | /**************************************************************************** |
| 31 | * Types |
| 32 | ****************************************************************************/ |
| 33 | |
Mikael Olsson | 9c999fd | 2023-10-30 11:05:39 +0100 | [diff] [blame] | 34 | struct ethosu_dma_mem; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 35 | struct ethosu_device; |
| 36 | struct device; |
| 37 | |
| 38 | /** |
Mikael Olsson | 9c999fd | 2023-10-30 11:05:39 +0100 | [diff] [blame] | 39 | * struct ethosu_buffer - User data buffer |
| 40 | * @dev: Device |
| 41 | * @file: File |
| 42 | * @kref: Reference counting |
| 43 | * @dma_mem: DMA memory allocated for the buffer |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 44 | */ |
| 45 | struct ethosu_buffer { |
Mikael Olsson | 9c999fd | 2023-10-30 11:05:39 +0100 | [diff] [blame] | 46 | struct device *dev; |
| 47 | struct file *file; |
| 48 | struct kref kref; |
| 49 | struct ethosu_dma_mem *dma_mem; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /**************************************************************************** |
| 53 | * Functions |
| 54 | ****************************************************************************/ |
| 55 | |
| 56 | /** |
| 57 | * ethosu_buffer_create() - Create buffer |
| 58 | * |
| 59 | * This function must be called in the context of a user space process. |
| 60 | * |
| 61 | * Return: fd on success, else error code. |
| 62 | */ |
Kristofer Jonsson | ec47704 | 2023-01-20 13:38:13 +0100 | [diff] [blame] | 63 | int ethosu_buffer_create(struct device *dev, |
Mikael Olsson | 0754515 | 2023-10-17 13:05:38 +0200 | [diff] [blame] | 64 | size_t size); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 65 | |
| 66 | /** |
| 67 | * ethosu_buffer_get_from_fd() - Get buffer handle from fd |
| 68 | * |
| 69 | * This function must be called from a user space context. |
| 70 | * |
| 71 | * Return: Pointer on success, else ERR_PTR. |
| 72 | */ |
| 73 | struct ethosu_buffer *ethosu_buffer_get_from_fd(int fd); |
| 74 | |
| 75 | /** |
| 76 | * ethosu_buffer_get() - Put buffer |
| 77 | */ |
| 78 | void ethosu_buffer_get(struct ethosu_buffer *buf); |
| 79 | |
| 80 | /** |
| 81 | * ethosu_buffer_put() - Put buffer |
| 82 | */ |
| 83 | void ethosu_buffer_put(struct ethosu_buffer *buf); |
| 84 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 85 | #endif /* ETHOSU_BUFFER_H */ |