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 | ****************************************************************************/ |
Kristofer Jonsson | d779a08 | 2023-01-04 17:09:47 +0100 | [diff] [blame] | 27 | #include "ethosu_core_rpmsg.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> |
Mikael Olsson | 6fb238f | 2023-08-23 11:02:47 +0200 | [diff] [blame^] | 31 | #include <linux/wait.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 { |
Kristofer Jonsson | d779a08 | 2023-01-04 17:09:47 +0100 | [diff] [blame] | 48 | struct device *dev; |
| 49 | struct rpmsg_endpoint *ept; |
| 50 | struct idr msg_idr; |
Mikael Olsson | 6fb238f | 2023-08-23 11:02:47 +0200 | [diff] [blame^] | 51 | atomic_t done; |
| 52 | wait_queue_head_t send_queue; |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 53 | }; |
| 54 | |
Mikael Olsson | 529cfad | 2023-06-14 17:14:14 +0200 | [diff] [blame] | 55 | /** |
| 56 | * struct ethosu_mailbox_msg - Mailbox message |
| 57 | * @id: Message id |
| 58 | * @type: Message request type |
| 59 | * @fail: Message failure callback |
| 60 | * |
| 61 | * The fail callback will be called with the device mutex locked |
| 62 | */ |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 63 | struct ethosu_mailbox_msg { |
Mikael Olsson | 09965b0 | 2023-06-13 12:17:04 +0200 | [diff] [blame] | 64 | int id; |
| 65 | uint32_t type; |
| 66 | void (*fail)(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, |
Kristofer Jonsson | d779a08 | 2023-01-04 17:09:47 +0100 | [diff] [blame] | 80 | struct rpmsg_endpoint *ept); |
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 | /** |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 88 | * ethosu_mailbox_register() - Register the ethosu_mailbox_msg in ethosu_mailbox |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 89 | * |
Mikael Olsson | 529cfad | 2023-06-14 17:14:14 +0200 | [diff] [blame] | 90 | * Context: Must be called with the device mutex locked |
| 91 | * |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 92 | * Return: 0 on success, else error code. |
| 93 | */ |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 94 | int ethosu_mailbox_register(struct ethosu_mailbox *mbox, |
| 95 | struct ethosu_mailbox_msg *msg); |
| 96 | |
| 97 | /** |
| 98 | * ethosu_mailbox_free_id() - Free the id of the ethosu_mailbox_msg |
Mikael Olsson | 529cfad | 2023-06-14 17:14:14 +0200 | [diff] [blame] | 99 | * |
| 100 | * Context: Must be called with the device mutex locked |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 101 | */ |
| 102 | void ethosu_mailbox_deregister(struct ethosu_mailbox *mbox, |
| 103 | struct ethosu_mailbox_msg *msg); |
| 104 | |
| 105 | /** |
| 106 | * ethosu_mailbox_find() - Find mailbox message |
| 107 | * |
Mikael Olsson | 529cfad | 2023-06-14 17:14:14 +0200 | [diff] [blame] | 108 | * Context: Must be called with the device mutex locked |
| 109 | * |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 110 | * Return: a valid pointer on success, otherwise an error ptr. |
| 111 | */ |
| 112 | struct ethosu_mailbox_msg *ethosu_mailbox_find(struct ethosu_mailbox *mbox, |
Mikael Olsson | 09965b0 | 2023-06-13 12:17:04 +0200 | [diff] [blame] | 113 | int msg_id, |
| 114 | uint32_t msg_type); |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * ethosu_mailbox_fail() - Fail mailbox messages |
| 118 | * |
| 119 | * Call fail() callback on all messages in pending list. |
Mikael Olsson | 529cfad | 2023-06-14 17:14:14 +0200 | [diff] [blame] | 120 | * |
| 121 | * Context: Must be called with the device mutex locked |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 122 | */ |
| 123 | void ethosu_mailbox_fail(struct ethosu_mailbox *mbox); |
| 124 | |
| 125 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 126 | * ethosu_mailbox_reset() - Reset to end of queue |
| 127 | */ |
| 128 | void ethosu_mailbox_reset(struct ethosu_mailbox *mbox); |
| 129 | |
| 130 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 131 | * ethosu_mailbox_ping() - Send ping message |
| 132 | * |
| 133 | * Return: 0 on success, else error code. |
| 134 | */ |
| 135 | int ethosu_mailbox_ping(struct ethosu_mailbox *mbox); |
| 136 | |
| 137 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 138 | * ethosu_mailbox_pong() - Send pong response |
| 139 | * |
| 140 | * Return: 0 on success, else error code. |
| 141 | */ |
| 142 | int ethosu_mailbox_pong(struct ethosu_mailbox *mbox); |
| 143 | |
| 144 | /** |
Mikael Olsson | 7c843dc | 2023-08-03 12:41:48 +0200 | [diff] [blame] | 145 | * ethosu_mailbox_version_request() - Send protocol version request |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 146 | * |
| 147 | * Return: 0 on succes, else error code |
| 148 | */ |
Mikael Olsson | 7c843dc | 2023-08-03 12:41:48 +0200 | [diff] [blame] | 149 | int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox, |
| 150 | struct ethosu_mailbox_msg *msg); |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 151 | |
| 152 | /** |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 153 | * ethosu_mailbox_capabilities_request() - Send capabilities request |
| 154 | * |
| 155 | * Return: 0 on success, else error code. |
| 156 | */ |
| 157 | int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox, |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 158 | struct ethosu_mailbox_msg *msg); |
Davide Grohmann | 35ce6c8 | 2021-06-01 15:03:51 +0200 | [diff] [blame] | 159 | |
| 160 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 161 | * ethosu_mailbox_inference() - Send inference |
| 162 | * |
| 163 | * Return: 0 on success, else error code. |
| 164 | */ |
| 165 | int ethosu_mailbox_inference(struct ethosu_mailbox *mbox, |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 166 | struct ethosu_mailbox_msg *msg, |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 167 | uint32_t ifm_count, |
| 168 | struct ethosu_buffer **ifm, |
| 169 | uint32_t ofm_count, |
| 170 | struct ethosu_buffer **ofm, |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 171 | struct ethosu_buffer *network, |
Kristofer Jonsson | 35de9e6 | 2022-03-08 13:25:45 +0100 | [diff] [blame] | 172 | uint32_t network_index, |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 173 | uint8_t *pmu_event_config, |
| 174 | uint8_t pmu_event_config_count, |
| 175 | uint8_t pmu_cycle_counter_enable); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 176 | |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 177 | /** |
| 178 | * ethosu_mailbox_network_info_request() - Send network info request |
| 179 | * |
| 180 | * Return: 0 on success, else error code. |
| 181 | */ |
| 182 | int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox, |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 183 | struct ethosu_mailbox_msg *msg, |
Kristofer Jonsson | 3c6a260 | 2022-03-10 11:17:29 +0100 | [diff] [blame] | 184 | struct ethosu_buffer *network, |
| 185 | uint32_t network_index); |
| 186 | |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 187 | /** |
| 188 | * ethosu_mailbox_cancel_inference() - Send inference cancellation |
| 189 | * |
| 190 | * Return: 0 on success, else error code. |
| 191 | */ |
| 192 | int ethosu_mailbox_cancel_inference(struct ethosu_mailbox *mbox, |
Davide Grohmann | 32660f9 | 2022-04-27 16:49:07 +0200 | [diff] [blame] | 193 | struct ethosu_mailbox_msg *msg, |
| 194 | int inference_handle); |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 195 | |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 196 | #endif /* ETHOSU_MAILBOX_H */ |