blob: c192b54c5de2990c2a698868d8ec1ccb94c6ba69 [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
53struct ethosu_mailbox_msg {
Mikael Olsson09965b02023-06-13 12:17:04 +020054 int id;
55 uint32_t type;
56 void (*fail)(struct ethosu_mailbox_msg *msg);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020057};
58
59/****************************************************************************
60 * Functions
61 ****************************************************************************/
62
63/**
64 * ethosu_mailbox_init() - Initialize mailbox
65 *
66 * Return: 0 on success, else error code.
67 */
68int ethosu_mailbox_init(struct ethosu_mailbox *mbox,
69 struct device *dev,
Kristofer Jonssond779a082023-01-04 17:09:47 +010070 struct rpmsg_endpoint *ept);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020071
72/**
73 * ethosu_mailbox_deinit() - Deinitialize mailbox
74 */
75void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox);
76
77/**
Davide Grohmann32660f92022-04-27 16:49:07 +020078 * ethosu_mailbox_register() - Register the ethosu_mailbox_msg in ethosu_mailbox
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010079 *
80 * Return: 0 on success, else error code.
81 */
Davide Grohmann32660f92022-04-27 16:49:07 +020082int ethosu_mailbox_register(struct ethosu_mailbox *mbox,
83 struct ethosu_mailbox_msg *msg);
84
85/**
86 * ethosu_mailbox_free_id() - Free the id of the ethosu_mailbox_msg
87 */
88void ethosu_mailbox_deregister(struct ethosu_mailbox *mbox,
89 struct ethosu_mailbox_msg *msg);
90
91/**
92 * ethosu_mailbox_find() - Find mailbox message
93 *
94 * Return: a valid pointer on success, otherwise an error ptr.
95 */
96struct ethosu_mailbox_msg *ethosu_mailbox_find(struct ethosu_mailbox *mbox,
Mikael Olsson09965b02023-06-13 12:17:04 +020097 int msg_id,
98 uint32_t msg_type);
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010099
100/**
101 * ethosu_mailbox_fail() - Fail mailbox messages
102 *
103 * Call fail() callback on all messages in pending list.
104 */
105void ethosu_mailbox_fail(struct ethosu_mailbox *mbox);
106
107/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100108 * ethosu_mailbox_reset() - Reset to end of queue
109 */
110void ethosu_mailbox_reset(struct ethosu_mailbox *mbox);
111
112/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200113 * ethosu_mailbox_ping() - Send ping message
114 *
115 * Return: 0 on success, else error code.
116 */
117int ethosu_mailbox_ping(struct ethosu_mailbox *mbox);
118
119/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100120 * ethosu_mailbox_pong() - Send pong response
121 *
122 * Return: 0 on success, else error code.
123 */
124int ethosu_mailbox_pong(struct ethosu_mailbox *mbox);
125
126/**
127 * ethosu_mailbox_version_response - Send version request
128 *
129 * Return: 0 on succes, else error code
130 */
131int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox);
132
133/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200134 * ethosu_mailbox_capabilities_request() - Send capabilities request
135 *
136 * Return: 0 on success, else error code.
137 */
138int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200139 struct ethosu_mailbox_msg *msg);
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200140
141/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200142 * ethosu_mailbox_inference() - Send inference
143 *
144 * Return: 0 on success, else error code.
145 */
146int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200147 struct ethosu_mailbox_msg *msg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200148 uint32_t ifm_count,
149 struct ethosu_buffer **ifm,
150 uint32_t ofm_count,
151 struct ethosu_buffer **ofm,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200152 struct ethosu_buffer *network,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100153 uint32_t network_index,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200154 uint8_t *pmu_event_config,
155 uint8_t pmu_event_config_count,
156 uint8_t pmu_cycle_counter_enable);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200157
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100158/**
159 * ethosu_mailbox_network_info_request() - Send network info request
160 *
161 * Return: 0 on success, else error code.
162 */
163int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200164 struct ethosu_mailbox_msg *msg,
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100165 struct ethosu_buffer *network,
166 uint32_t network_index);
167
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100168/**
169 * ethosu_mailbox_cancel_inference() - Send inference cancellation
170 *
171 * Return: 0 on success, else error code.
172 */
173int ethosu_mailbox_cancel_inference(struct ethosu_mailbox *mbox,
Davide Grohmann32660f92022-04-27 16:49:07 +0200174 struct ethosu_mailbox_msg *msg,
175 int inference_handle);
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100176
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200177#endif /* ETHOSU_MAILBOX_H */