blob: c4c71a9f492b18e58299b837693b176d26c0a2fd [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>
Mikael Olsson6fb238f2023-08-23 11:02:47 +020031#include <linux/wait.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;
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,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200171 struct ethosu_buffer *network,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100172 uint32_t network_index,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200173 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/**
178 * ethosu_mailbox_network_info_request() - Send network info request
179 *
180 * Return: 0 on success, else error code.
181 */
182int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200183 struct ethosu_mailbox_msg *msg,
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100184 struct ethosu_buffer *network,
185 uint32_t network_index);
186
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100187/**
188 * ethosu_mailbox_cancel_inference() - Send inference cancellation
189 *
190 * Return: 0 on success, else error code.
191 */
192int ethosu_mailbox_cancel_inference(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200193 struct ethosu_mailbox_msg *msg,
194 int inference_handle);
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100195
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200196#endif /* ETHOSU_MAILBOX_H */