blob: e0d41b15c792f093d03ec9d8c6e03cd857b1b881 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Kristofer Jonssonec477042023-01-20 13:38:13 +01002 * Copyright 2020,2022-2023 Arm Limited and/or its affiliates
Kristofer Jonsson116a6352020-08-20 17:25:23 +02003 *
4 * This program is free software and is provided to you under the terms of the
5 * GNU General Public License version 2 as published by the Free Software
6 * Foundation, and any use by you of this program is subject to the terms
7 * of such GNU licence.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, you can access it online at
16 * http://www.gnu.org/licenses/gpl-2.0.html.
17 *
18 * SPDX-License-Identifier: GPL-2.0-only
19 */
20
21#ifndef ETHOSU_NETWORK_H
22#define ETHOSU_NETWORK_H
23
24/****************************************************************************
25 * Includes
26 ****************************************************************************/
27
28#include <linux/kref.h>
29#include <linux/types.h>
30
31/****************************************************************************
32 * Types
33 ****************************************************************************/
34
35struct ethosu_buffer;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020036struct ethosu_uapi_network_create;
37struct device;
38struct file;
39
40struct ethosu_network {
Kristofer Jonssonec477042023-01-20 13:38:13 +010041 struct device *dev;
42 struct ethosu_mailbox *mailbox;
43 struct file *file;
44 struct kref kref;
45 struct ethosu_buffer *buf;
46 uint32_t index;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020047};
48
49/****************************************************************************
50 * Functions
51 ****************************************************************************/
52
53/**
54 * ethosu_network_create() - Create network
55 *
56 * This function must be called in the context of a user space process.
57 *
58 * Return: fd on success, else error code.
59 */
Kristofer Jonssonec477042023-01-20 13:38:13 +010060int ethosu_network_create(struct device *dev,
61 struct ethosu_mailbox *mailbox,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020062 struct ethosu_uapi_network_create *uapi);
63
64/**
65 * ethosu_network_get_from_fd() - Get network handle from fd
66 *
67 * This function must be called from a user space context.
68 *
69 * Return: Pointer on success, else ERR_PTR.
70 */
71struct ethosu_network *ethosu_network_get_from_fd(int fd);
72
73/**
74 * ethosu_network_get() - Get network
75 */
76void ethosu_network_get(struct ethosu_network *net);
77
78/**
79 * ethosu_network_put() - Put network
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010080 *
81 * Return: 1 if object was removed, else 0.
Kristofer Jonsson116a6352020-08-20 17:25:23 +020082 */
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010083int ethosu_network_put(struct ethosu_network *net);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020084
85#endif /* ETHOSU_NETWORK_H */