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> |
| 32 | |
| 33 | /**************************************************************************** |
| 34 | * Types |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | struct device; |
| 38 | struct ethosu_buffer; |
| 39 | struct ethosu_device; |
| 40 | struct ethosu_core_msg; |
| 41 | struct ethosu_core_queue; |
Kristofer Jonsson | f5b98c9 | 2022-03-14 16:09:12 +0100 | [diff] [blame] | 42 | struct ethosu_watchdog; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 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; |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 58 | struct list_head pending_list; |
Kristofer Jonsson | f5b98c9 | 2022-03-14 16:09:12 +0100 | [diff] [blame] | 59 | struct ethosu_watchdog *wdog; |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 60 | unsigned ping_count; |
| 61 | }; |
| 62 | |
| 63 | struct 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 Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | /**************************************************************************** |
| 70 | * Functions |
| 71 | ****************************************************************************/ |
| 72 | |
| 73 | /** |
| 74 | * ethosu_mailbox_init() - Initialize mailbox |
| 75 | * |
| 76 | * Return: 0 on success, else error code. |
| 77 | */ |
| 78 | int 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 Jonsson | f5b98c9 | 2022-03-14 16:09:12 +0100 | [diff] [blame] | 83 | void *user_arg, |
| 84 | struct ethosu_watchdog *wdog); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * ethosu_mailbox_deinit() - Deinitialize mailbox |
| 88 | */ |
| 89 | void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox); |
| 90 | |
| 91 | /** |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 92 | * 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 | */ |
| 98 | void 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 | */ |
| 109 | int ethosu_mailbox_wait_firmware(struct ethosu_mailbox *mbox); |
| 110 | |
| 111 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 112 | * ethosu_mailbox_read() - Read message from mailbox |
| 113 | * |
| 114 | * Return: 0 message read, else error code. |
| 115 | */ |
| 116 | int ethosu_mailbox_read(struct ethosu_mailbox *mbox, |
| 117 | struct ethosu_core_msg *header, |
| 118 | void *data, |
| 119 | size_t length); |
| 120 | |
| 121 | /** |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 122 | * ethosu_mailbox_find() - Find mailbox message |
| 123 | * |
| 124 | * Return: 0 on success, else error code. |
| 125 | */ |
| 126 | int 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 | */ |
| 134 | void 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 | */ |
| 143 | int ethosu_mailbox_resend(struct ethosu_mailbox *mbox); |
| 144 | |
| 145 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 146 | * ethosu_mailbox_reset() - Reset to end of queue |
| 147 | */ |
| 148 | void ethosu_mailbox_reset(struct ethosu_mailbox *mbox); |
| 149 | |
| 150 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 151 | * ethosu_mailbox_ping() - Send ping message |
| 152 | * |
| 153 | * Return: 0 on success, else error code. |
| 154 | */ |
| 155 | int ethosu_mailbox_ping(struct ethosu_mailbox *mbox); |
| 156 | |
| 157 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 158 | * ethosu_mailbox_pong() - Send pong response |
| 159 | * |
| 160 | * Return: 0 on success, else error code. |
| 161 | */ |
| 162 | int 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 | */ |
| 169 | int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox); |
| 170 | |
| 171 | /** |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 172 | * ethosu_mailbox_capabilities_request() - Send capabilities request |
| 173 | * |
| 174 | * Return: 0 on success, else error code. |
| 175 | */ |
| 176 | int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox, |
| 177 | void *user_arg); |
| 178 | |
| 179 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 180 | * ethosu_mailbox_inference() - Send inference |
| 181 | * |
| 182 | * Return: 0 on success, else error code. |
| 183 | */ |
| 184 | int ethosu_mailbox_inference(struct ethosu_mailbox *mbox, |
| 185 | void *user_arg, |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 186 | uint32_t ifm_count, |
| 187 | struct ethosu_buffer **ifm, |
| 188 | uint32_t ofm_count, |
| 189 | struct ethosu_buffer **ofm, |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 190 | struct ethosu_buffer *network, |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 191 | uint32_t network_index, |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 192 | uint8_t *pmu_event_config, |
| 193 | uint8_t pmu_event_config_count, |
| 194 | uint8_t pmu_cycle_counter_enable); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 195 | |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 196 | /** |
| 197 | * ethosu_mailbox_network_info_request() - Send network info request |
| 198 | * |
| 199 | * Return: 0 on success, else error code. |
| 200 | */ |
| 201 | int 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 Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 206 | #endif /* ETHOSU_MAILBOX_H */ |