Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
Mikael Olsson | d4ad9e5 | 2024-02-07 11:22:26 +0100 | [diff] [blame^] | 2 | * SPDX-FileCopyrightText: Copyright 2020, 2022-2024 Arm Limited and/or its affiliates <open-source-office@arm.com> |
| 3 | * SPDX-License-Identifier: GPL-2.0-only |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 4 | * |
| 5 | * This program is free software and is provided to you under the terms of the |
| 6 | * GNU General Public License version 2 as published by the Free Software |
| 7 | * Foundation, and any use by you of this program is subject to the terms |
| 8 | * of such GNU licence. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, you can access it online at |
| 17 | * http://www.gnu.org/licenses/gpl-2.0.html. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #ifndef ETHOSU_INFERENCE_H |
| 21 | #define ETHOSU_INFERENCE_H |
| 22 | |
| 23 | /**************************************************************************** |
| 24 | * Includes |
| 25 | ****************************************************************************/ |
| 26 | |
Mikael Olsson | d4ad9e5 | 2024-02-07 11:22:26 +0100 | [diff] [blame^] | 27 | #include <rpmsg/ethosu_rpmsg_mailbox.h> |
| 28 | #include <uapi/ethosu.h> |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 29 | |
| 30 | #include <linux/kref.h> |
| 31 | #include <linux/types.h> |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 32 | |
| 33 | /**************************************************************************** |
| 34 | * Types |
| 35 | ****************************************************************************/ |
| 36 | |
| 37 | struct ethosu_buffer; |
Kristofer Jonsson | d779a08 | 2023-01-04 17:09:47 +0100 | [diff] [blame] | 38 | struct ethosu_core_msg_inference_rsp; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 39 | struct ethosu_network; |
| 40 | struct ethosu_uapi_inference_create; |
| 41 | struct file; |
| 42 | |
| 43 | /** |
| 44 | * struct ethosu_inference - Inference struct |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 45 | * @edev: Arm Ethos-U device |
| 46 | * @file: File handle |
| 47 | * @kref: Reference counter |
| 48 | * @waitq: Wait queue |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 49 | * @done: Wait condition is done |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 50 | * @ifm: Pointer to IFM buffer |
| 51 | * @ofm: Pointer to OFM buffer |
| 52 | * @net: Pointer to network |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 53 | * @status: Inference status |
| 54 | * @pmu_event_config: PMU event configuration |
| 55 | * @pmu_event_count: PMU event count after inference |
| 56 | * @pmu_cycle_counter_enable: PMU cycle counter config |
| 57 | * @pmu_cycle_counter_count: PMU cycle counter count after inference |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 58 | * @msg: Mailbox message |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 59 | */ |
| 60 | struct ethosu_inference { |
Kristofer Jonsson | ec47704 | 2023-01-20 13:38:13 +0100 | [diff] [blame] | 61 | struct device *dev; |
| 62 | struct ethosu_mailbox *mailbox; |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 63 | struct file *file; |
| 64 | struct kref kref; |
| 65 | wait_queue_head_t waitq; |
| 66 | bool done; |
| 67 | uint32_t ifm_count; |
| 68 | struct ethosu_buffer *ifm[ETHOSU_FD_MAX]; |
| 69 | uint32_t ofm_count; |
| 70 | struct ethosu_buffer *ofm[ETHOSU_FD_MAX]; |
| 71 | struct ethosu_network *net; |
| 72 | enum ethosu_uapi_status status; |
| 73 | uint8_t pmu_event_config[ETHOSU_PMU_EVENT_MAX]; |
Mikael Olsson | e87446c | 2023-12-15 17:17:06 +0100 | [diff] [blame] | 74 | uint64_t pmu_event_count[ETHOSU_PMU_EVENT_MAX]; |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 75 | uint32_t pmu_cycle_counter_enable; |
| 76 | uint64_t pmu_cycle_counter_count; |
| 77 | struct ethosu_mailbox_msg msg; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | /**************************************************************************** |
| 81 | * Functions |
| 82 | ****************************************************************************/ |
| 83 | |
| 84 | /** |
| 85 | * ethosu_inference_create() - Create inference |
| 86 | * |
| 87 | * This function must be called in the context of a user space process. |
| 88 | * |
| 89 | * Return: fd on success, else error code. |
| 90 | */ |
Kristofer Jonsson | ec47704 | 2023-01-20 13:38:13 +0100 | [diff] [blame] | 91 | int ethosu_inference_create(struct device *dev, |
| 92 | struct ethosu_mailbox *mailbox, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 93 | struct ethosu_network *net, |
| 94 | struct ethosu_uapi_inference_create *uapi); |
| 95 | |
| 96 | /** |
| 97 | * ethosu_inference_get_from_fd() - Get inference handle from fd |
| 98 | * |
| 99 | * This function must be called from a user space context. |
| 100 | * |
| 101 | * Return: Pointer on success, else ERR_PTR. |
| 102 | */ |
| 103 | struct ethosu_inference *ethosu_inference_get_from_fd(int fd); |
| 104 | |
| 105 | /** |
| 106 | * ethosu_inference_get() - Get inference |
| 107 | */ |
| 108 | void ethosu_inference_get(struct ethosu_inference *inf); |
| 109 | |
| 110 | /** |
| 111 | * ethosu_inference_put() - Put inference |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 112 | * |
| 113 | * Return: 1 if object was removed, else 0. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 114 | */ |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 115 | int ethosu_inference_put(struct ethosu_inference *inf); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * ethosu_inference_rsp() - Handle inference response |
| 119 | */ |
Kristofer Jonsson | ec47704 | 2023-01-20 13:38:13 +0100 | [diff] [blame] | 120 | void ethosu_inference_rsp(struct ethosu_mailbox *mailbox, |
Kristofer Jonsson | d779a08 | 2023-01-04 17:09:47 +0100 | [diff] [blame] | 121 | int msg_id, |
| 122 | struct ethosu_core_msg_inference_rsp *rsp); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 123 | |
| 124 | #endif /* ETHOSU_INFERENCE_H */ |