blob: ea4409fb808283ae584d59090c9af82f0788f1ec [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Kristofer Jonssonb42bc0b2023-01-04 17:09:28 +01002 * Copyright 2020-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_MAILBOX_H
22#define ETHOSU_MAILBOX_H
23
24/****************************************************************************
25 * Includes
26 ****************************************************************************/
Kristofer Jonssond779a082023-01-04 17:09:47 +010027#include "ethosu_core_rpmsg.h"
Kristofer Jonsson116a6352020-08-20 17:25:23 +020028
29#include <linux/types.h>
30#include <linux/mailbox_client.h>
31#include <linux/workqueue.h>
Davide Grohmann32660f92022-04-27 16:49:07 +020032#include <linux/idr.h>
Kristofer Jonsson116a6352020-08-20 17:25:23 +020033
34/****************************************************************************
35 * Types
36 ****************************************************************************/
37
38struct device;
39struct ethosu_buffer;
40struct ethosu_device;
41struct ethosu_core_msg;
42struct ethosu_core_queue;
43struct 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;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010051};
52
Mikael Olsson529cfad2023-06-14 17:14:14 +020053/**
54 * struct ethosu_mailbox_msg - Mailbox message
55 * @id: Message id
56 * @type: Message request type
57 * @fail: Message failure callback
58 *
59 * The fail callback will be called with the device mutex locked
60 */
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010061struct ethosu_mailbox_msg {
Mikael Olsson09965b02023-06-13 12:17:04 +020062 int id;
63 uint32_t type;
64 void (*fail)(struct ethosu_mailbox_msg *msg);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020065};
66
67/****************************************************************************
68 * Functions
69 ****************************************************************************/
70
71/**
72 * ethosu_mailbox_init() - Initialize mailbox
73 *
74 * Return: 0 on success, else error code.
75 */
76int ethosu_mailbox_init(struct ethosu_mailbox *mbox,
77 struct device *dev,
Kristofer Jonssond779a082023-01-04 17:09:47 +010078 struct rpmsg_endpoint *ept);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020079
80/**
81 * ethosu_mailbox_deinit() - Deinitialize mailbox
82 */
83void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox);
84
85/**
Davide Grohmann32660f92022-04-27 16:49:07 +020086 * ethosu_mailbox_register() - Register the ethosu_mailbox_msg in ethosu_mailbox
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010087 *
Mikael Olsson529cfad2023-06-14 17:14:14 +020088 * Context: Must be called with the device mutex locked
89 *
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010090 * Return: 0 on success, else error code.
91 */
Davide Grohmann32660f92022-04-27 16:49:07 +020092int ethosu_mailbox_register(struct ethosu_mailbox *mbox,
93 struct ethosu_mailbox_msg *msg);
94
95/**
96 * ethosu_mailbox_free_id() - Free the id of the ethosu_mailbox_msg
Mikael Olsson529cfad2023-06-14 17:14:14 +020097 *
98 * Context: Must be called with the device mutex locked
Davide Grohmann32660f92022-04-27 16:49:07 +020099 */
100void ethosu_mailbox_deregister(struct ethosu_mailbox *mbox,
101 struct ethosu_mailbox_msg *msg);
102
103/**
104 * ethosu_mailbox_find() - Find mailbox message
105 *
Mikael Olsson529cfad2023-06-14 17:14:14 +0200106 * Context: Must be called with the device mutex locked
107 *
Davide Grohmann32660f92022-04-27 16:49:07 +0200108 * Return: a valid pointer on success, otherwise an error ptr.
109 */
110struct ethosu_mailbox_msg *ethosu_mailbox_find(struct ethosu_mailbox *mbox,
Mikael Olsson09965b02023-06-13 12:17:04 +0200111 int msg_id,
112 uint32_t msg_type);
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100113
114/**
115 * ethosu_mailbox_fail() - Fail mailbox messages
116 *
117 * Call fail() callback on all messages in pending list.
Mikael Olsson529cfad2023-06-14 17:14:14 +0200118 *
119 * Context: Must be called with the device mutex locked
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100120 */
121void ethosu_mailbox_fail(struct ethosu_mailbox *mbox);
122
123/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100124 * ethosu_mailbox_reset() - Reset to end of queue
125 */
126void ethosu_mailbox_reset(struct ethosu_mailbox *mbox);
127
128/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200129 * ethosu_mailbox_ping() - Send ping message
130 *
131 * Return: 0 on success, else error code.
132 */
133int ethosu_mailbox_ping(struct ethosu_mailbox *mbox);
134
135/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100136 * ethosu_mailbox_pong() - Send pong response
137 *
138 * Return: 0 on success, else error code.
139 */
140int ethosu_mailbox_pong(struct ethosu_mailbox *mbox);
141
142/**
143 * ethosu_mailbox_version_response - Send version request
144 *
145 * Return: 0 on succes, else error code
146 */
147int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox);
148
149/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200150 * ethosu_mailbox_capabilities_request() - Send capabilities request
151 *
152 * Return: 0 on success, else error code.
153 */
154int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200155 struct ethosu_mailbox_msg *msg);
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200156
157/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200158 * ethosu_mailbox_inference() - Send inference
159 *
160 * Return: 0 on success, else error code.
161 */
162int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200163 struct ethosu_mailbox_msg *msg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200164 uint32_t ifm_count,
165 struct ethosu_buffer **ifm,
166 uint32_t ofm_count,
167 struct ethosu_buffer **ofm,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200168 struct ethosu_buffer *network,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100169 uint32_t network_index,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200170 uint8_t *pmu_event_config,
171 uint8_t pmu_event_config_count,
172 uint8_t pmu_cycle_counter_enable);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200173
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100174/**
175 * ethosu_mailbox_network_info_request() - Send network info request
176 *
177 * Return: 0 on success, else error code.
178 */
179int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200180 struct ethosu_mailbox_msg *msg,
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100181 struct ethosu_buffer *network,
182 uint32_t network_index);
183
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100184/**
185 * ethosu_mailbox_cancel_inference() - Send inference cancellation
186 *
187 * Return: 0 on success, else error code.
188 */
189int ethosu_mailbox_cancel_inference(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200190 struct ethosu_mailbox_msg *msg,
191 int inference_handle);
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100192
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200193#endif /* ETHOSU_MAILBOX_H */