blob: 55d4436096e4ca031b612c120a2ba6798a3182a8 [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 *
141 * Return: 0 on success, else error code.
142 */
143int ethosu_mailbox_resend(struct ethosu_mailbox *mbox);
144
145/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100146 * ethosu_mailbox_reset() - Reset to end of queue
147 */
148void ethosu_mailbox_reset(struct ethosu_mailbox *mbox);
149
150/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200151 * ethosu_mailbox_ping() - Send ping message
152 *
153 * Return: 0 on success, else error code.
154 */
155int ethosu_mailbox_ping(struct ethosu_mailbox *mbox);
156
157/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100158 * ethosu_mailbox_pong() - Send pong response
159 *
160 * Return: 0 on success, else error code.
161 */
162int ethosu_mailbox_pong(struct ethosu_mailbox *mbox);
163
164/**
165 * ethosu_mailbox_version_response - Send version request
166 *
167 * Return: 0 on succes, else error code
168 */
169int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox);
170
171/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200172 * ethosu_mailbox_capabilities_request() - Send capabilities request
173 *
174 * Return: 0 on success, else error code.
175 */
176int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox,
177 void *user_arg);
178
179/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200180 * ethosu_mailbox_inference() - Send inference
181 *
182 * Return: 0 on success, else error code.
183 */
184int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
185 void *user_arg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200186 uint32_t ifm_count,
187 struct ethosu_buffer **ifm,
188 uint32_t ofm_count,
189 struct ethosu_buffer **ofm,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200190 struct ethosu_buffer *network,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100191 uint32_t network_index,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200192 uint8_t *pmu_event_config,
193 uint8_t pmu_event_config_count,
194 uint8_t pmu_cycle_counter_enable);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200195
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100196/**
197 * ethosu_mailbox_network_info_request() - Send network info request
198 *
199 * Return: 0 on success, else error code.
200 */
201int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox,
202 void *user_arg,
203 struct ethosu_buffer *network,
204 uint32_t network_index);
205
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200206#endif /* ETHOSU_MAILBOX_H */