aboutsummaryrefslogtreecommitdiff
path: root/kernel/ethosu_mailbox.h
blob: 26367f62b478ff8b1dcb084fda57c9c112a95a16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
 * Copyright (c) 2020-2022 Arm Limited.
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU licence.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you can access it online at
 * http://www.gnu.org/licenses/gpl-2.0.html.
 *
 * SPDX-License-Identifier: GPL-2.0-only
 */

#ifndef ETHOSU_MAILBOX_H
#define ETHOSU_MAILBOX_H

/****************************************************************************
 * Includes
 ****************************************************************************/
#include "ethosu_core_interface.h"

#include <linux/types.h>
#include <linux/mailbox_client.h>
#include <linux/workqueue.h>
#include <linux/idr.h>

/****************************************************************************
 * Types
 ****************************************************************************/

struct device;
struct ethosu_buffer;
struct ethosu_device;
struct ethosu_core_msg;
struct ethosu_core_queue;
struct ethosu_watchdog;
struct resource;

typedef void (*ethosu_mailbox_cb)(void *user_arg);

struct ethosu_mailbox {
	struct device            *dev;
	struct workqueue_struct  *wq;
	struct work_struct       work;
	struct ethosu_core_queue __iomem *in_queue;
	struct ethosu_core_queue __iomem *out_queue;
	struct mbox_client       client;
	struct mbox_chan         *rx;
	struct mbox_chan         *tx;
	ethosu_mailbox_cb        callback;
	void                     *user_arg;
	struct idr               msg_idr;
	struct ethosu_watchdog   *wdog;
	unsigned                 ping_count;
};

struct ethosu_mailbox_msg {
	int  id;
	void (*fail)(struct ethosu_mailbox_msg *msg);
	int  (*resend)(struct ethosu_mailbox_msg *msg);
};

/****************************************************************************
 * Functions
 ****************************************************************************/

/**
 * ethosu_mailbox_init() - Initialize mailbox
 *
 * Return: 0 on success, else error code.
 */
int ethosu_mailbox_init(struct ethosu_mailbox *mbox,
			struct device *dev,
			struct resource *in_queue,
			struct resource *out_queue,
			ethosu_mailbox_cb callback,
			void *user_arg,
			struct ethosu_watchdog *wdog);

/**
 * ethosu_mailbox_deinit() - Deinitialize mailbox
 */
void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox);

/**
 * ethosu_mailbox_wait_prepare() - Prepare to wait on firmware
 *
 * This function must only be called when the firmware is in a
 * stopped state. It invalidates the firmware queues setting
 * size, read and write positions to illegal values.
 */
void ethosu_mailbox_wait_prepare(struct ethosu_mailbox *mbox);

/**
 * ethosu_mailbox_wait_firmware() - Waiting for firmware to initialize
 *                                  message queues
 *
 * Following a call to ethosu_mailbox_wait_prepare() this function waits for
 * the firmware to boot up and initialize the firmware queues.
 *
 * Return: 0 on success, else error code.
 */
int ethosu_mailbox_wait_firmware(struct ethosu_mailbox *mbox);

/**
 * ethosu_mailbox_read() - Read message from mailbox
 *
 * Return: 0 message read, else error code.
 */
int ethosu_mailbox_read(struct ethosu_mailbox *mbox,
			struct ethosu_core_msg *header,
			void *data,
			size_t length);

/**
 * ethosu_mailbox_register() - Register the ethosu_mailbox_msg in ethosu_mailbox
 *
 * Return: 0 on success, else error code.
 */
int ethosu_mailbox_register(struct ethosu_mailbox *mbox,
			    struct ethosu_mailbox_msg *msg);

/**
 * ethosu_mailbox_free_id() - Free the id of the ethosu_mailbox_msg
 */
void ethosu_mailbox_deregister(struct ethosu_mailbox *mbox,
			       struct ethosu_mailbox_msg *msg);

/**
 * ethosu_mailbox_find() - Find mailbox message
 *
 * Return: a valid pointer on success, otherwise an error ptr.
 */
struct ethosu_mailbox_msg *ethosu_mailbox_find(struct ethosu_mailbox *mbox,
					       int msg_id);

/**
 * ethosu_mailbox_fail() - Fail mailbox messages
 *
 * Call fail() callback on all messages in pending list.
 */
void ethosu_mailbox_fail(struct ethosu_mailbox *mbox);

/**
 * ethosu_mailbox_resend() - Resend mailbox messages
 *
 * Call resend() callback on all messages in pending list.
 */
void ethosu_mailbox_resend(struct ethosu_mailbox *mbox);

/**
 * ethosu_mailbox_reset() - Reset to end of queue
 */
void ethosu_mailbox_reset(struct ethosu_mailbox *mbox);

/**
 * ethosu_mailbox_ping() - Send ping message
 *
 * Return: 0 on success, else error code.
 */
int ethosu_mailbox_ping(struct ethosu_mailbox *mbox);

/**
 * ethosu_mailbox_pong() - Send pong response
 *
 * Return: 0 on success, else error code.
 */
int ethosu_mailbox_pong(struct ethosu_mailbox *mbox);

/**
 * ethosu_mailbox_version_response - Send version request
 *
 * Return: 0 on succes, else error code
 */
int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox);

/**
 * ethosu_mailbox_capabilities_request() - Send capabilities request
 *
 * Return: 0 on success, else error code.
 */
int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox,
					struct ethosu_mailbox_msg *msg);

/**
 * ethosu_mailbox_inference() - Send inference
 *
 * Return: 0 on success, else error code.
 */
int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
			     struct ethosu_mailbox_msg *msg,
			     uint32_t ifm_count,
			     struct ethosu_buffer **ifm,
			     uint32_t ofm_count,
			     struct ethosu_buffer **ofm,
			     struct ethosu_buffer *network,
			     uint32_t network_index,
			     uint8_t *pmu_event_config,
			     uint8_t pmu_event_config_count,
			     uint8_t pmu_cycle_counter_enable);

/**
 * ethosu_mailbox_network_info_request() - Send network info request
 *
 * Return: 0 on success, else error code.
 */
int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox,
					struct ethosu_mailbox_msg *msg,
					struct ethosu_buffer *network,
					uint32_t network_index);

/**
 * ethosu_mailbox_cancel_inference() - Send inference cancellation
 *
 * Return: 0 on success, else error code.
 */
int ethosu_mailbox_cancel_inference(struct ethosu_mailbox *mbox,
				    struct ethosu_mailbox_msg *msg,
				    int inference_handle);

#endif /* ETHOSU_MAILBOX_H */