blob: ab19613fe901df2b5d3abc24ec8538a250cb520d [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Mikael Olssonc081e592023-10-30 11:10:56 +01002 * SPDX-FileCopyrightText: Copyright 2020-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_MAILBOX_H
21#define ETHOSU_MAILBOX_H
22
23/****************************************************************************
24 * Includes
25 ****************************************************************************/
Kristofer Jonssond779a082023-01-04 17:09:47 +010026#include "ethosu_core_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;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020039struct ethosu_core_msg;
40struct ethosu_core_queue;
Mikael Olssonc081e592023-10-30 11:10:56 +010041struct ethosu_device;
42struct ethosu_network;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020043struct resource;
44
45typedef void (*ethosu_mailbox_cb)(void *user_arg);
46
47struct ethosu_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/**
56 * struct ethosu_mailbox_msg - Mailbox message
57 * @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 */
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010063struct ethosu_mailbox_msg {
Mikael Olsson09965b02023-06-13 12:17:04 +020064 int id;
65 uint32_t type;
66 void (*fail)(struct ethosu_mailbox_msg *msg);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020067};
68
69/****************************************************************************
70 * Functions
71 ****************************************************************************/
72
73/**
74 * ethosu_mailbox_init() - Initialize mailbox
75 *
76 * Return: 0 on success, else error code.
77 */
78int ethosu_mailbox_init(struct ethosu_mailbox *mbox,
79 struct device *dev,
Kristofer Jonssond779a082023-01-04 17:09:47 +010080 struct rpmsg_endpoint *ept);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020081
82/**
83 * ethosu_mailbox_deinit() - Deinitialize mailbox
84 */
85void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox);
86
87/**
Davide Grohmann32660f92022-04-27 16:49:07 +020088 * ethosu_mailbox_register() - Register the ethosu_mailbox_msg in ethosu_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 */
Davide Grohmann32660f92022-04-27 16:49:07 +020094int ethosu_mailbox_register(struct ethosu_mailbox *mbox,
95 struct ethosu_mailbox_msg *msg);
96
97/**
98 * ethosu_mailbox_free_id() - Free the id of the ethosu_mailbox_msg
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 */
102void ethosu_mailbox_deregister(struct ethosu_mailbox *mbox,
103 struct ethosu_mailbox_msg *msg);
104
105/**
106 * ethosu_mailbox_find() - Find mailbox message
107 *
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 */
112struct ethosu_mailbox_msg *ethosu_mailbox_find(struct ethosu_mailbox *mbox,
Mikael Olsson09965b02023-06-13 12:17:04 +0200113 int msg_id,
114 uint32_t msg_type);
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100115
116/**
117 * ethosu_mailbox_fail() - Fail mailbox messages
118 *
119 * Call fail() callback on all messages in pending list.
Mikael Olsson529cfad2023-06-14 17:14:14 +0200120 *
121 * Context: Must be called with the device mutex locked
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100122 */
123void ethosu_mailbox_fail(struct ethosu_mailbox *mbox);
124
125/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100126 * ethosu_mailbox_reset() - Reset to end of queue
127 */
128void ethosu_mailbox_reset(struct ethosu_mailbox *mbox);
129
130/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200131 * ethosu_mailbox_ping() - Send ping message
132 *
133 * Return: 0 on success, else error code.
134 */
135int ethosu_mailbox_ping(struct ethosu_mailbox *mbox);
136
137/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100138 * ethosu_mailbox_pong() - Send pong response
139 *
140 * Return: 0 on success, else error code.
141 */
142int ethosu_mailbox_pong(struct ethosu_mailbox *mbox);
143
144/**
Mikael Olsson7c843dc2023-08-03 12:41:48 +0200145 * ethosu_mailbox_version_request() - Send protocol version request
Jonny Svärd7c24c772021-01-14 19:53:17 +0100146 *
147 * Return: 0 on succes, else error code
148 */
Mikael Olsson7c843dc2023-08-03 12:41:48 +0200149int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox,
150 struct ethosu_mailbox_msg *msg);
Jonny Svärd7c24c772021-01-14 19:53:17 +0100151
152/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200153 * ethosu_mailbox_capabilities_request() - Send capabilities request
154 *
155 * Return: 0 on success, else error code.
156 */
157int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200158 struct ethosu_mailbox_msg *msg);
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200159
160/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200161 * ethosu_mailbox_inference() - Send inference
162 *
163 * Return: 0 on success, else error code.
164 */
165int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200166 struct ethosu_mailbox_msg *msg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200167 uint32_t ifm_count,
168 struct ethosu_buffer **ifm,
169 uint32_t ofm_count,
170 struct ethosu_buffer **ofm,
Mikael Olssonc081e592023-10-30 11:10:56 +0100171 struct ethosu_network *network,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200172 uint8_t *pmu_event_config,
173 uint8_t pmu_event_config_count,
174 uint8_t pmu_cycle_counter_enable);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200175
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100176/**
177 * ethosu_mailbox_network_info_request() - Send network info request
178 *
179 * Return: 0 on success, else error code.
180 */
181int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200182 struct ethosu_mailbox_msg *msg,
Mikael Olssonc081e592023-10-30 11:10:56 +0100183 struct ethosu_network *network);
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100184
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100185/**
186 * ethosu_mailbox_cancel_inference() - Send inference cancellation
187 *
188 * Return: 0 on success, else error code.
189 */
190int ethosu_mailbox_cancel_inference(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200191 struct ethosu_mailbox_msg *msg,
192 int inference_handle);
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100193
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200194#endif /* ETHOSU_MAILBOX_H */