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