blob: 40819cee5d5ea077bb4933819afe38998ae1e292 [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
Mikael Olsson16be2852024-02-12 09:56:56 +010020#ifndef ETHOSU_RPMSG_NETWORK_H
21#define ETHOSU_RPMSG_NETWORK_H
Kristofer Jonsson116a6352020-08-20 17:25:23 +020022
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
Mikael Olsson16be2852024-02-12 09:56:56 +010039struct ethosu_rpmsg_network {
40 struct device *dev;
41 struct ethosu_rpmsg_mailbox *mailbox;
42 struct file *file;
43 struct kref kref;
44 struct ethosu_dma_mem *dma_mem;
45 uint32_t index;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020046};
47
48/****************************************************************************
49 * Functions
50 ****************************************************************************/
51
52/**
Mikael Olsson16be2852024-02-12 09:56:56 +010053 * ethosu_rpmsg_network_create() - Create network
Kristofer Jonsson116a6352020-08-20 17:25:23 +020054 *
55 * This function must be called in the context of a user space process.
56 *
57 * Return: fd on success, else error code.
58 */
Mikael Olsson16be2852024-02-12 09:56:56 +010059int ethosu_rpmsg_network_create(struct device *dev,
60 struct ethosu_rpmsg_mailbox *mailbox,
61 struct ethosu_uapi_network_create *uapi);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020062
63/**
Mikael Olsson16be2852024-02-12 09:56:56 +010064 * ethosu_rpmsg_network_get_from_fd() - Get network handle from fd
Kristofer Jonsson116a6352020-08-20 17:25:23 +020065 *
66 * This function must be called from a user space context.
67 *
68 * Return: Pointer on success, else ERR_PTR.
69 */
Mikael Olsson16be2852024-02-12 09:56:56 +010070struct ethosu_rpmsg_network *ethosu_rpmsg_network_get_from_fd(int fd);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020071
72/**
Mikael Olsson16be2852024-02-12 09:56:56 +010073 * ethosu_rpmsg_network_get() - Get network
Kristofer Jonsson116a6352020-08-20 17:25:23 +020074 */
Mikael Olsson16be2852024-02-12 09:56:56 +010075void ethosu_rpmsg_network_get(struct ethosu_rpmsg_network *net);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020076
77/**
Mikael Olsson16be2852024-02-12 09:56:56 +010078 * ethosu_rpmsg_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 */
Mikael Olsson16be2852024-02-12 09:56:56 +010082int ethosu_rpmsg_network_put(struct ethosu_rpmsg_network *net);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020083
Mikael Olsson16be2852024-02-12 09:56:56 +010084#endif /* ETHOSU_RPMSG_NETWORK_H */