Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 2 | * Copyright (c) 2020-2022 Arm Limited. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 3 | * |
| 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ärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 27 | #include "ethosu_core_interface.h" |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 28 | |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/mailbox_client.h> |
| 31 | #include <linux/workqueue.h> |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 32 | #include <linux/idr.h> |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 33 | |
| 34 | /**************************************************************************** |
| 35 | * Types |
| 36 | ****************************************************************************/ |
| 37 | |
| 38 | struct device; |
| 39 | struct ethosu_buffer; |
| 40 | struct ethosu_device; |
| 41 | struct ethosu_core_msg; |
| 42 | struct ethosu_core_queue; |
Kristofer Jonsson | f5b98c9 | 2022-03-14 16:09:12 +0100 | [diff] [blame] | 43 | struct ethosu_watchdog; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 44 | struct resource; |
| 45 | |
| 46 | typedef void (*ethosu_mailbox_cb)(void *user_arg); |
| 47 | |
| 48 | struct ethosu_mailbox { |
| 49 | struct device *dev; |
| 50 | struct workqueue_struct *wq; |
| 51 | struct work_struct work; |
| 52 | struct ethosu_core_queue __iomem *in_queue; |
| 53 | struct ethosu_core_queue __iomem *out_queue; |
| 54 | struct mbox_client client; |
| 55 | struct mbox_chan *rx; |
| 56 | struct mbox_chan *tx; |
| 57 | ethosu_mailbox_cb callback; |
| 58 | void *user_arg; |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 59 | struct idr msg_idr; |
Kristofer Jonsson | f5b98c9 | 2022-03-14 16:09:12 +0100 | [diff] [blame] | 60 | struct ethosu_watchdog *wdog; |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 61 | unsigned ping_count; |
| 62 | }; |
| 63 | |
| 64 | struct ethosu_mailbox_msg { |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 65 | int id; |
| 66 | void (*fail)(struct ethosu_mailbox_msg *msg); |
| 67 | int (*resend)(struct ethosu_mailbox_msg *msg); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | /**************************************************************************** |
| 71 | * Functions |
| 72 | ****************************************************************************/ |
| 73 | |
| 74 | /** |
| 75 | * ethosu_mailbox_init() - Initialize mailbox |
| 76 | * |
| 77 | * Return: 0 on success, else error code. |
| 78 | */ |
| 79 | int ethosu_mailbox_init(struct ethosu_mailbox *mbox, |
| 80 | struct device *dev, |
| 81 | struct resource *in_queue, |
| 82 | struct resource *out_queue, |
| 83 | ethosu_mailbox_cb callback, |
Kristofer Jonsson | f5b98c9 | 2022-03-14 16:09:12 +0100 | [diff] [blame] | 84 | void *user_arg, |
| 85 | struct ethosu_watchdog *wdog); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * ethosu_mailbox_deinit() - Deinitialize mailbox |
| 89 | */ |
| 90 | void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox); |
| 91 | |
| 92 | /** |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 93 | * ethosu_mailbox_wait_prepare() - Prepare to wait on firmware |
| 94 | * |
| 95 | * This function must only be called when the firmware is in a |
| 96 | * stopped state. It invalidates the firmware queues setting |
| 97 | * size, read and write positions to illegal values. |
| 98 | */ |
| 99 | void ethosu_mailbox_wait_prepare(struct ethosu_mailbox *mbox); |
| 100 | |
| 101 | /** |
| 102 | * ethosu_mailbox_wait_firmware() - Waiting for firmware to initialize |
| 103 | * message queues |
| 104 | * |
| 105 | * Following a call to ethosu_mailbox_wait_prepare() this function waits for |
| 106 | * the firmware to boot up and initialize the firmware queues. |
| 107 | * |
| 108 | * Return: 0 on success, else error code. |
| 109 | */ |
| 110 | int ethosu_mailbox_wait_firmware(struct ethosu_mailbox *mbox); |
| 111 | |
| 112 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 113 | * ethosu_mailbox_read() - Read message from mailbox |
| 114 | * |
| 115 | * Return: 0 message read, else error code. |
| 116 | */ |
| 117 | int ethosu_mailbox_read(struct ethosu_mailbox *mbox, |
| 118 | struct ethosu_core_msg *header, |
| 119 | void *data, |
| 120 | size_t length); |
| 121 | |
| 122 | /** |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 123 | * ethosu_mailbox_register() - Register the ethosu_mailbox_msg in ethosu_mailbox |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 124 | * |
| 125 | * Return: 0 on success, else error code. |
| 126 | */ |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 127 | int ethosu_mailbox_register(struct ethosu_mailbox *mbox, |
| 128 | struct ethosu_mailbox_msg *msg); |
| 129 | |
| 130 | /** |
| 131 | * ethosu_mailbox_free_id() - Free the id of the ethosu_mailbox_msg |
| 132 | */ |
| 133 | void ethosu_mailbox_deregister(struct ethosu_mailbox *mbox, |
| 134 | struct ethosu_mailbox_msg *msg); |
| 135 | |
| 136 | /** |
| 137 | * ethosu_mailbox_find() - Find mailbox message |
| 138 | * |
| 139 | * Return: a valid pointer on success, otherwise an error ptr. |
| 140 | */ |
| 141 | struct ethosu_mailbox_msg *ethosu_mailbox_find(struct ethosu_mailbox *mbox, |
| 142 | int msg_id); |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * ethosu_mailbox_fail() - Fail mailbox messages |
| 146 | * |
| 147 | * Call fail() callback on all messages in pending list. |
| 148 | */ |
| 149 | void ethosu_mailbox_fail(struct ethosu_mailbox *mbox); |
| 150 | |
| 151 | /** |
| 152 | * ethosu_mailbox_resend() - Resend mailbox messages |
| 153 | * |
| 154 | * Call resend() callback on all messages in pending list. |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 155 | */ |
Davide Grohmann | 8b1fe55 | 2022-04-07 16:58:32 +0200 | [diff] [blame] | 156 | void ethosu_mailbox_resend(struct ethosu_mailbox *mbox); |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 157 | |
| 158 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 159 | * ethosu_mailbox_reset() - Reset to end of queue |
| 160 | */ |
| 161 | void ethosu_mailbox_reset(struct ethosu_mailbox *mbox); |
| 162 | |
| 163 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 164 | * ethosu_mailbox_ping() - Send ping message |
| 165 | * |
| 166 | * Return: 0 on success, else error code. |
| 167 | */ |
| 168 | int ethosu_mailbox_ping(struct ethosu_mailbox *mbox); |
| 169 | |
| 170 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 171 | * ethosu_mailbox_pong() - Send pong response |
| 172 | * |
| 173 | * Return: 0 on success, else error code. |
| 174 | */ |
| 175 | int ethosu_mailbox_pong(struct ethosu_mailbox *mbox); |
| 176 | |
| 177 | /** |
| 178 | * ethosu_mailbox_version_response - Send version request |
| 179 | * |
| 180 | * Return: 0 on succes, else error code |
| 181 | */ |
| 182 | int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox); |
| 183 | |
| 184 | /** |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 185 | * ethosu_mailbox_capabilities_request() - Send capabilities request |
| 186 | * |
| 187 | * Return: 0 on success, else error code. |
| 188 | */ |
| 189 | int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox, |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 190 | struct ethosu_mailbox_msg *msg); |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 191 | |
| 192 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 193 | * ethosu_mailbox_inference() - Send inference |
| 194 | * |
| 195 | * Return: 0 on success, else error code. |
| 196 | */ |
| 197 | int ethosu_mailbox_inference(struct ethosu_mailbox *mbox, |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 198 | struct ethosu_mailbox_msg *msg, |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 199 | uint32_t ifm_count, |
| 200 | struct ethosu_buffer **ifm, |
| 201 | uint32_t ofm_count, |
| 202 | struct ethosu_buffer **ofm, |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 203 | struct ethosu_buffer *network, |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 204 | uint32_t network_index, |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 205 | uint8_t *pmu_event_config, |
| 206 | uint8_t pmu_event_config_count, |
| 207 | uint8_t pmu_cycle_counter_enable); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 208 | |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 209 | /** |
| 210 | * ethosu_mailbox_network_info_request() - Send network info request |
| 211 | * |
| 212 | * Return: 0 on success, else error code. |
| 213 | */ |
| 214 | int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox, |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 215 | struct ethosu_mailbox_msg *msg, |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 216 | struct ethosu_buffer *network, |
| 217 | uint32_t network_index); |
| 218 | |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 219 | /** |
| 220 | * ethosu_mailbox_cancel_inference() - Send inference cancellation |
| 221 | * |
| 222 | * Return: 0 on success, else error code. |
| 223 | */ |
| 224 | int ethosu_mailbox_cancel_inference(struct ethosu_mailbox *mbox, |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 225 | struct ethosu_mailbox_msg *msg, |
| 226 | int inference_handle); |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 227 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 228 | #endif /* ETHOSU_MAILBOX_H */ |