blob: 8bef2d2764ac3f4ce9d76d81487807934bc46b90 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Mikael Olsson07545152023-10-17 13:05:38 +02002 * 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 Jonsson116a6352020-08-20 17:25:23 +02004 *
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 Jonsson116a6352020-08-20 17:25:23 +020018 */
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 Olsson9c999fd2023-10-30 11:05:39 +010034struct ethosu_dma_mem;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020035struct ethosu_device;
36struct device;
37
38/**
Mikael Olsson9c999fd2023-10-30 11:05:39 +010039 * 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 Jonsson116a6352020-08-20 17:25:23 +020044 */
45struct ethosu_buffer {
Mikael Olsson9c999fd2023-10-30 11:05:39 +010046 struct device *dev;
47 struct file *file;
48 struct kref kref;
49 struct ethosu_dma_mem *dma_mem;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020050};
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 Jonssonec477042023-01-20 13:38:13 +010063int ethosu_buffer_create(struct device *dev,
Mikael Olsson07545152023-10-17 13:05:38 +020064 size_t size);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020065
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 */
73struct ethosu_buffer *ethosu_buffer_get_from_fd(int fd);
74
75/**
76 * ethosu_buffer_get() - Put buffer
77 */
78void ethosu_buffer_get(struct ethosu_buffer *buf);
79
80/**
81 * ethosu_buffer_put() - Put buffer
82 */
83void ethosu_buffer_put(struct ethosu_buffer *buf);
84
Kristofer Jonsson116a6352020-08-20 17:25:23 +020085#endif /* ETHOSU_BUFFER_H */