blob: 07276f68a7b9114d6f04ea59ed1b175c50dd730b [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Kristofer Jonsson35de9e62022-03-08 13:25:45 +01002 * Copyright (c) 2020-2022 Arm Limited.
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 ****************************************************************************/
Jonny Svärd7c24c772021-01-14 19:53:17 +010027#include "ethosu_core_interface.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>
32
33/****************************************************************************
34 * Types
35 ****************************************************************************/
36
37struct device;
38struct ethosu_buffer;
39struct ethosu_device;
40struct ethosu_core_msg;
41struct ethosu_core_queue;
Kristofer Jonssonf5b98c92022-03-14 16:09:12 +010042struct ethosu_watchdog;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020043struct resource;
44
45typedef void (*ethosu_mailbox_cb)(void *user_arg);
46
47struct ethosu_mailbox {
48 struct device *dev;
49 struct workqueue_struct *wq;
50 struct work_struct work;
51 struct ethosu_core_queue __iomem *in_queue;
52 struct ethosu_core_queue __iomem *out_queue;
53 struct mbox_client client;
54 struct mbox_chan *rx;
55 struct mbox_chan *tx;
56 ethosu_mailbox_cb callback;
57 void *user_arg;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010058 struct list_head pending_list;
Kristofer Jonssonf5b98c92022-03-14 16:09:12 +010059 struct ethosu_watchdog *wdog;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010060 unsigned ping_count;
61};
62
63struct ethosu_mailbox_msg {
64 struct list_head list;
65 void (*fail)(struct ethosu_mailbox_msg *msg);
66 int (*resend)(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,
80 struct resource *in_queue,
81 struct resource *out_queue,
82 ethosu_mailbox_cb callback,
Kristofer Jonssonf5b98c92022-03-14 16:09:12 +010083 void *user_arg,
84 struct ethosu_watchdog *wdog);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020085
86/**
87 * ethosu_mailbox_deinit() - Deinitialize mailbox
88 */
89void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox);
90
91/**
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010092 * ethosu_mailbox_wait_prepare() - Prepare to wait on firmware
93 *
94 * This function must only be called when the firmware is in a
95 * stopped state. It invalidates the firmware queues setting
96 * size, read and write positions to illegal values.
97 */
98void ethosu_mailbox_wait_prepare(struct ethosu_mailbox *mbox);
99
100/**
101 * ethosu_mailbox_wait_firmware() - Waiting for firmware to initialize
102 * message queues
103 *
104 * Following a call to ethosu_mailbox_wait_prepare() this function waits for
105 * the firmware to boot up and initialize the firmware queues.
106 *
107 * Return: 0 on success, else error code.
108 */
109int ethosu_mailbox_wait_firmware(struct ethosu_mailbox *mbox);
110
111/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200112 * ethosu_mailbox_read() - Read message from mailbox
113 *
114 * Return: 0 message read, else error code.
115 */
116int ethosu_mailbox_read(struct ethosu_mailbox *mbox,
117 struct ethosu_core_msg *header,
118 void *data,
119 size_t length);
120
121/**
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100122 * ethosu_mailbox_find() - Find mailbox message
123 *
124 * Return: 0 on success, else error code.
125 */
126int ethosu_mailbox_find(struct ethosu_mailbox *mbox,
127 struct ethosu_mailbox_msg *msg);
128
129/**
130 * ethosu_mailbox_fail() - Fail mailbox messages
131 *
132 * Call fail() callback on all messages in pending list.
133 */
134void ethosu_mailbox_fail(struct ethosu_mailbox *mbox);
135
136/**
137 * ethosu_mailbox_resend() - Resend mailbox messages
138 *
139 * Call resend() callback on all messages in pending list.
140 *
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100141 */
Davide Grohmann8b1fe552022-04-07 16:58:32 +0200142void ethosu_mailbox_resend(struct ethosu_mailbox *mbox);
Kristofer Jonsson442fefb2022-03-17 17:15:52 +0100143
144/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100145 * ethosu_mailbox_reset() - Reset to end of queue
146 */
147void ethosu_mailbox_reset(struct ethosu_mailbox *mbox);
148
149/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200150 * ethosu_mailbox_ping() - Send ping message
151 *
152 * Return: 0 on success, else error code.
153 */
154int ethosu_mailbox_ping(struct ethosu_mailbox *mbox);
155
156/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100157 * ethosu_mailbox_pong() - Send pong response
158 *
159 * Return: 0 on success, else error code.
160 */
161int ethosu_mailbox_pong(struct ethosu_mailbox *mbox);
162
163/**
164 * ethosu_mailbox_version_response - Send version request
165 *
166 * Return: 0 on succes, else error code
167 */
168int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox);
169
170/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200171 * ethosu_mailbox_capabilities_request() - Send capabilities request
172 *
173 * Return: 0 on success, else error code.
174 */
175int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox,
176 void *user_arg);
177
178/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200179 * ethosu_mailbox_inference() - Send inference
180 *
181 * Return: 0 on success, else error code.
182 */
183int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
184 void *user_arg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200185 uint32_t ifm_count,
186 struct ethosu_buffer **ifm,
187 uint32_t ofm_count,
188 struct ethosu_buffer **ofm,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200189 struct ethosu_buffer *network,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100190 uint32_t network_index,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200191 uint8_t *pmu_event_config,
192 uint8_t pmu_event_config_count,
193 uint8_t pmu_cycle_counter_enable);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200194
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100195/**
196 * ethosu_mailbox_network_info_request() - Send network info request
197 *
198 * Return: 0 on success, else error code.
199 */
200int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox,
201 void *user_arg,
202 struct ethosu_buffer *network,
203 uint32_t network_index);
204
Davide Grohmann7e8f5082022-03-23 12:48:45 +0100205/**
206 * ethosu_mailbox_cancel_inference() - Send inference cancellation
207 *
208 * Return: 0 on success, else error code.
209 */
210int ethosu_mailbox_cancel_inference(struct ethosu_mailbox *mbox,
211 void *user_arg,
212 void *inference_handle);
213
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200214#endif /* ETHOSU_MAILBOX_H */