blob: 1829fbe59594abd42d1be61e862beb4a5a5db1b6 [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
34struct ethosu_device;
35struct device;
36
37/**
38 * struct ethosu_buffer - Buffer
39 * @dev: Device
40 * @file: File
41 * @kref: Reference counting
Mikael Olsson07545152023-10-17 13:05:38 +020042 * @size: Size of the buffer
Kristofer Jonsson116a6352020-08-20 17:25:23 +020043 * @cpu_addr: Kernel mapped address
44 * @dma_addr: DMA address
Kristofer Jonsson116a6352020-08-20 17:25:23 +020045 */
46struct ethosu_buffer {
Kristofer Jonssonec477042023-01-20 13:38:13 +010047 struct device *dev;
48 struct file *file;
49 struct kref kref;
Kristofer Jonssonec477042023-01-20 13:38:13 +010050 size_t size;
51 void *cpu_addr;
52 dma_addr_t dma_addr;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020053};
54
55/****************************************************************************
56 * Functions
57 ****************************************************************************/
58
59/**
60 * ethosu_buffer_create() - Create buffer
61 *
62 * This function must be called in the context of a user space process.
63 *
64 * Return: fd on success, else error code.
65 */
Kristofer Jonssonec477042023-01-20 13:38:13 +010066int ethosu_buffer_create(struct device *dev,
Mikael Olsson07545152023-10-17 13:05:38 +020067 size_t size);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020068
69/**
70 * ethosu_buffer_get_from_fd() - Get buffer handle from fd
71 *
72 * This function must be called from a user space context.
73 *
74 * Return: Pointer on success, else ERR_PTR.
75 */
76struct ethosu_buffer *ethosu_buffer_get_from_fd(int fd);
77
78/**
79 * ethosu_buffer_get() - Put buffer
80 */
81void ethosu_buffer_get(struct ethosu_buffer *buf);
82
83/**
84 * ethosu_buffer_put() - Put buffer
85 */
86void ethosu_buffer_put(struct ethosu_buffer *buf);
87
Kristofer Jonsson116a6352020-08-20 17:25:23 +020088#endif /* ETHOSU_BUFFER_H */