Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) COPYRIGHT 2020 ARM Limited. All rights reserved. |
| 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; |
| 42 | struct resource; |
| 43 | |
| 44 | typedef void (*ethosu_mailbox_cb)(void *user_arg); |
| 45 | |
| 46 | struct ethosu_mailbox { |
| 47 | struct device *dev; |
| 48 | struct workqueue_struct *wq; |
| 49 | struct work_struct work; |
| 50 | struct ethosu_core_queue __iomem *in_queue; |
| 51 | struct ethosu_core_queue __iomem *out_queue; |
| 52 | struct mbox_client client; |
| 53 | struct mbox_chan *rx; |
| 54 | struct mbox_chan *tx; |
| 55 | ethosu_mailbox_cb callback; |
| 56 | void *user_arg; |
| 57 | }; |
| 58 | |
| 59 | /**************************************************************************** |
| 60 | * Functions |
| 61 | ****************************************************************************/ |
| 62 | |
| 63 | /** |
| 64 | * ethosu_mailbox_init() - Initialize mailbox |
| 65 | * |
| 66 | * Return: 0 on success, else error code. |
| 67 | */ |
| 68 | int ethosu_mailbox_init(struct ethosu_mailbox *mbox, |
| 69 | struct device *dev, |
| 70 | struct resource *in_queue, |
| 71 | struct resource *out_queue, |
| 72 | ethosu_mailbox_cb callback, |
| 73 | void *user_arg); |
| 74 | |
| 75 | /** |
| 76 | * ethosu_mailbox_deinit() - Deinitialize mailbox |
| 77 | */ |
| 78 | void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox); |
| 79 | |
| 80 | /** |
| 81 | * ethosu_mailbox_read() - Read message from mailbox |
| 82 | * |
| 83 | * Return: 0 message read, else error code. |
| 84 | */ |
| 85 | int ethosu_mailbox_read(struct ethosu_mailbox *mbox, |
| 86 | struct ethosu_core_msg *header, |
| 87 | void *data, |
| 88 | size_t length); |
| 89 | |
| 90 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 91 | * ethosu_mailbox_reset() - Reset to end of queue |
| 92 | */ |
| 93 | void ethosu_mailbox_reset(struct ethosu_mailbox *mbox); |
| 94 | |
| 95 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 96 | * ethosu_mailbox_ping() - Send ping message |
| 97 | * |
| 98 | * Return: 0 on success, else error code. |
| 99 | */ |
| 100 | int ethosu_mailbox_ping(struct ethosu_mailbox *mbox); |
| 101 | |
| 102 | /** |
Jonny Svärd | 7c24c77 | 2021-01-14 19:53:17 +0100 | [diff] [blame] | 103 | * ethosu_mailbox_pong() - Send pong response |
| 104 | * |
| 105 | * Return: 0 on success, else error code. |
| 106 | */ |
| 107 | int ethosu_mailbox_pong(struct ethosu_mailbox *mbox); |
| 108 | |
| 109 | /** |
| 110 | * ethosu_mailbox_version_response - Send version request |
| 111 | * |
| 112 | * Return: 0 on succes, else error code |
| 113 | */ |
| 114 | int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox); |
| 115 | |
| 116 | /** |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 117 | * ethosu_mailbox_inference() - Send inference |
| 118 | * |
| 119 | * Return: 0 on success, else error code. |
| 120 | */ |
| 121 | int ethosu_mailbox_inference(struct ethosu_mailbox *mbox, |
| 122 | void *user_arg, |
Kristofer Jonsson | b74492c | 2020-09-10 13:26:01 +0200 | [diff] [blame] | 123 | uint32_t ifm_count, |
| 124 | struct ethosu_buffer **ifm, |
| 125 | uint32_t ofm_count, |
| 126 | struct ethosu_buffer **ofm, |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 127 | struct ethosu_buffer *network, |
| 128 | uint8_t *pmu_event_config, |
| 129 | uint8_t pmu_event_config_count, |
| 130 | uint8_t pmu_cycle_counter_enable); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 131 | |
| 132 | #endif /* ETHOSU_MAILBOX_H */ |