blob: b6602888e6433aceec83afacb0255f4a3b26b419 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Mikael Olssond4ad9e52024-02-07 11:22:26 +01002 * SPDX-FileCopyrightText: Copyright 2020-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_MAILBOX_H
21#define ETHOSU_RPMSG_MAILBOX_H
Kristofer Jonsson116a6352020-08-20 17:25:23 +020022
23/****************************************************************************
24 * Includes
25 ****************************************************************************/
Mikael Olssond4ad9e52024-02-07 11:22:26 +010026#include <rpmsg/ethosu_rpmsg.h>
Kristofer Jonsson116a6352020-08-20 17:25:23 +020027
28#include <linux/types.h>
29#include <linux/mailbox_client.h>
Mikael Olsson6fb238f2023-08-23 11:02:47 +020030#include <linux/wait.h>
Davide Grohmann32660f92022-04-27 16:49:07 +020031#include <linux/idr.h>
Kristofer Jonsson116a6352020-08-20 17:25:23 +020032
33/****************************************************************************
34 * Types
35 ****************************************************************************/
36
37struct device;
38struct ethosu_buffer;
Mikael Olsson16be2852024-02-12 09:56:56 +010039struct ethosu_rpmsg;
40struct ethosu_rpmsg_core_queue;
Mikael Olssonc081e592023-10-30 11:10:56 +010041struct ethosu_device;
Mikael Olsson16be2852024-02-12 09:56:56 +010042struct ethosu_rpmsg_network;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020043struct resource;
44
Mikael Olsson16be2852024-02-12 09:56:56 +010045typedef void (*ethosu_rpmsg_mailbox_cb)(void *user_arg);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020046
Mikael Olsson16be2852024-02-12 09:56:56 +010047struct ethosu_rpmsg_mailbox {
Kristofer Jonssond779a082023-01-04 17:09:47 +010048 struct device *dev;
49 struct rpmsg_endpoint *ept;
50 struct idr msg_idr;
Mikael Olsson6fb238f2023-08-23 11:02:47 +020051 atomic_t done;
52 wait_queue_head_t send_queue;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010053};
54
Mikael Olsson529cfad2023-06-14 17:14:14 +020055/**
Mikael Olsson16be2852024-02-12 09:56:56 +010056 * struct ethosu_rpmsg_mailbox_msg - Mailbox message
Mikael Olsson529cfad2023-06-14 17:14:14 +020057 * @id: Message id
58 * @type: Message request type
59 * @fail: Message failure callback
60 *
61 * The fail callback will be called with the device mutex locked
62 */
Mikael Olsson16be2852024-02-12 09:56:56 +010063struct ethosu_rpmsg_mailbox_msg {
Mikael Olsson09965b02023-06-13 12:17:04 +020064 int id;
65 uint32_t type;
Mikael Olsson16be2852024-02-12 09:56:56 +010066 void (*fail)(struct ethosu_rpmsg_mailbox_msg *msg);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020067};
68
69/****************************************************************************
70 * Functions
71 ****************************************************************************/
72
73/**
Mikael Olsson16be2852024-02-12 09:56:56 +010074 * ethosu_rpmsg_mailbox_init() - Initialize mailbox
Kristofer Jonsson116a6352020-08-20 17:25:23 +020075 *
76 * Return: 0 on success, else error code.
77 */
Mikael Olsson16be2852024-02-12 09:56:56 +010078int ethosu_rpmsg_mailbox_init(struct ethosu_rpmsg_mailbox *mbox,
79 struct device *dev,
80 struct rpmsg_endpoint *ept);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020081
82/**
Mikael Olsson16be2852024-02-12 09:56:56 +010083 * ethosu_rpmsg_mailbox_deinit() - Deinitialize mailbox
Kristofer Jonsson116a6352020-08-20 17:25:23 +020084 */
Mikael Olsson16be2852024-02-12 09:56:56 +010085void ethosu_rpmsg_mailbox_deinit(struct ethosu_rpmsg_mailbox *mbox);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020086
87/**
Mikael Olsson16be2852024-02-12 09:56:56 +010088 * ethosu_rpmsg_mailbox_register() - Register the message in mailbox
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010089 *
Mikael Olsson529cfad2023-06-14 17:14:14 +020090 * Context: Must be called with the device mutex locked
91 *
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010092 * Return: 0 on success, else error code.
93 */
Mikael Olsson16be2852024-02-12 09:56:56 +010094int ethosu_rpmsg_mailbox_register(struct ethosu_rpmsg_mailbox *mbox,
95 struct ethosu_rpmsg_mailbox_msg *msg);
Davide Grohmann32660f92022-04-27 16:49:07 +020096
97/**
Mikael Olsson16be2852024-02-12 09:56:56 +010098 * ethosu_rpmsg_mailbox_free_id() - Free the id of the message
Mikael Olsson529cfad2023-06-14 17:14:14 +020099 *
100 * Context: Must be called with the device mutex locked
Davide Grohmann32660f92022-04-27 16:49:07 +0200101 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100102void ethosu_rpmsg_mailbox_deregister(struct ethosu_rpmsg_mailbox *mbox,
103 struct ethosu_rpmsg_mailbox_msg *msg);
Davide Grohmann32660f92022-04-27 16:49:07 +0200104
105/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100106 * ethosu_rpmsg_mailbox_find() - Find mailbox message
Davide Grohmann32660f92022-04-27 16:49:07 +0200107 *
Mikael Olsson529cfad2023-06-14 17:14:14 +0200108 * Context: Must be called with the device mutex locked
109 *
Davide Grohmann32660f92022-04-27 16:49:07 +0200110 * Return: a valid pointer on success, otherwise an error ptr.
111 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100112struct ethosu_rpmsg_mailbox_msg *ethosu_rpmsg_mailbox_find(
113 struct ethosu_rpmsg_mailbox *mbox,
114 int msg_id,
115 uint32_t msg_type);
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100116
117/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100118 * ethosu_rpmsg_mailbox_fail() - Fail mailbox messages
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100119 *
120 * Call fail() callback on all messages in pending list.
Mikael Olsson529cfad2023-06-14 17:14:14 +0200121 *
122 * Context: Must be called with the device mutex locked
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100123 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100124void ethosu_rpmsg_mailbox_fail(struct ethosu_rpmsg_mailbox *mbox);
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100125
126/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100127 * ethosu_rpmsg_mailbox_reset() - Reset to end of queue
Jonny Svärd7c24c772021-01-14 19:53:17 +0100128 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100129void ethosu_rpmsg_mailbox_reset(struct ethosu_rpmsg_mailbox *mbox);
Jonny Svärd7c24c772021-01-14 19:53:17 +0100130
131/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100132 * ethosu_rpmsg_mailbox_ping() - Send ping message
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200133 *
134 * Return: 0 on success, else error code.
135 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100136int ethosu_rpmsg_mailbox_ping(struct ethosu_rpmsg_mailbox *mbox);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200137
138/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100139 * ethosu_rpmsg_mailbox_pong() - Send pong response
Jonny Svärd7c24c772021-01-14 19:53:17 +0100140 *
141 * Return: 0 on success, else error code.
142 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100143int ethosu_rpmsg_mailbox_pong(struct ethosu_rpmsg_mailbox *mbox);
Jonny Svärd7c24c772021-01-14 19:53:17 +0100144
145/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100146 * ethosu_rpmsg_mailbox_version_request() - Send protocol version request
Jonny Svärd7c24c772021-01-14 19:53:17 +0100147 *
148 * Return: 0 on succes, else error code
149 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100150int ethosu_rpmsg_mailbox_version_request(struct ethosu_rpmsg_mailbox *mbox,
151 struct ethosu_rpmsg_mailbox_msg *msg);
Jonny Svärd7c24c772021-01-14 19:53:17 +0100152
153/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100154 * ethosu_rpmsg_mailbox_capabilities_request() - Send capabilities request
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200155 *
156 * Return: 0 on success, else error code.
157 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100158int ethosu_rpmsg_mailbox_capabilities_request(struct ethosu_rpmsg_mailbox *mbox,
159 struct ethosu_rpmsg_mailbox_msg *msg);
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200160
161/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100162 * ethosu_rpmsg_mailbox_inference() - Send inference
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200163 *
164 * Return: 0 on success, else error code.
165 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100166int ethosu_rpmsg_mailbox_inference(struct ethosu_rpmsg_mailbox *mbox,
167 struct ethosu_rpmsg_mailbox_msg *msg,
168 uint32_t ifm_count,
169 struct ethosu_buffer **ifm,
170 uint32_t ofm_count,
171 struct ethosu_buffer **ofm,
172 struct ethosu_rpmsg_network *network,
173 uint8_t *pmu_event_config,
174 uint8_t pmu_event_config_count,
175 uint8_t pmu_cycle_counter_enable);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200176
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100177/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100178 * ethosu_rpmsg_mailbox_network_info_request() - Send network info request
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100179 *
180 * Return: 0 on success, else error code.
181 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100182int ethosu_rpmsg_mailbox_network_info_request(struct ethosu_rpmsg_mailbox *mbox,
183 struct ethosu_rpmsg_mailbox_msg *msg,
184 struct ethosu_rpmsg_network *network);
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100185
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100186/**
Mikael Olsson16be2852024-02-12 09:56:56 +0100187 * ethosu_rpmsg_mailbox_cancel_inference() - Send inference cancellation
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100188 *
189 * Return: 0 on success, else error code.
190 */
Mikael Olsson16be2852024-02-12 09:56:56 +0100191int ethosu_rpmsg_mailbox_cancel_inference(struct ethosu_rpmsg_mailbox *mbox,
192 struct ethosu_rpmsg_mailbox_msg *msg,
193 int inference_handle);
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100194
Mikael Olsson16be2852024-02-12 09:56:56 +0100195#endif /* ETHOSU_RPMSG_MAILBOX_H */