blob: 269018a066edf1993679e010144b3261a903fefe [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Mikael Olssond4ad9e52024-02-07 11:22:26 +01002 * SPDX-FileCopyrightText: Copyright 2020, 2022-2024 Arm Limited and/or its affiliates <open-source-office@arm.com>
Mikael Olssonc081e592023-10-30 11:10:56 +01003 * 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_NETWORK_H
21#define ETHOSU_NETWORK_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_buffer;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020035struct ethosu_uapi_network_create;
36struct device;
37struct file;
38
39struct ethosu_network {
Kristofer Jonssonec477042023-01-20 13:38:13 +010040 struct device *dev;
41 struct ethosu_mailbox *mailbox;
42 struct file *file;
43 struct kref kref;
Mikael Olssonc081e592023-10-30 11:10:56 +010044 struct ethosu_dma_mem *dma_mem;
Kristofer Jonssonec477042023-01-20 13:38:13 +010045 uint32_t index;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020046};
47
48/****************************************************************************
49 * Functions
50 ****************************************************************************/
51
52/**
53 * ethosu_network_create() - Create network
54 *
55 * This function must be called in the context of a user space process.
56 *
57 * Return: fd on success, else error code.
58 */
Kristofer Jonssonec477042023-01-20 13:38:13 +010059int ethosu_network_create(struct device *dev,
60 struct ethosu_mailbox *mailbox,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020061 struct ethosu_uapi_network_create *uapi);
62
63/**
64 * ethosu_network_get_from_fd() - Get network handle from fd
65 *
66 * This function must be called from a user space context.
67 *
68 * Return: Pointer on success, else ERR_PTR.
69 */
70struct ethosu_network *ethosu_network_get_from_fd(int fd);
71
72/**
73 * ethosu_network_get() - Get network
74 */
75void ethosu_network_get(struct ethosu_network *net);
76
77/**
78 * ethosu_network_put() - Put network
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010079 *
80 * Return: 1 if object was removed, else 0.
Kristofer Jonsson116a6352020-08-20 17:25:23 +020081 */
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010082int ethosu_network_put(struct ethosu_network *net);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020083
84#endif /* ETHOSU_NETWORK_H */