Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 1 | /* |
Kristofer Jonsson | d779a08 | 2023-01-04 17:09:47 +0100 | [diff] [blame] | 2 | * Copyright 2020,2022-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_INFERENCE_H |
| 22 | #define ETHOSU_INFERENCE_H |
| 23 | |
| 24 | /**************************************************************************** |
| 25 | * Includes |
| 26 | ****************************************************************************/ |
| 27 | |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 28 | #include "ethosu_mailbox.h" |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 29 | #include "uapi/ethosu.h" |
| 30 | |
| 31 | #include <linux/kref.h> |
| 32 | #include <linux/types.h> |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 33 | |
| 34 | /**************************************************************************** |
| 35 | * Types |
| 36 | ****************************************************************************/ |
| 37 | |
| 38 | struct ethosu_buffer; |
Kristofer Jonsson | d779a08 | 2023-01-04 17:09:47 +0100 | [diff] [blame] | 39 | struct ethosu_core_msg_inference_rsp; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 40 | struct ethosu_network; |
| 41 | struct ethosu_uapi_inference_create; |
| 42 | struct file; |
| 43 | |
| 44 | /** |
| 45 | * struct ethosu_inference - Inference struct |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 46 | * @edev: Arm Ethos-U device |
| 47 | * @file: File handle |
| 48 | * @kref: Reference counter |
| 49 | * @waitq: Wait queue |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 50 | * @done: Wait condition is done |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 51 | * @ifm: Pointer to IFM buffer |
| 52 | * @ofm: Pointer to OFM buffer |
| 53 | * @net: Pointer to network |
Per Åstrand | f7e407a | 2020-10-23 21:25:05 +0200 | [diff] [blame] | 54 | * @status: Inference status |
| 55 | * @pmu_event_config: PMU event configuration |
| 56 | * @pmu_event_count: PMU event count after inference |
| 57 | * @pmu_cycle_counter_enable: PMU cycle counter config |
| 58 | * @pmu_cycle_counter_count: PMU cycle counter count after inference |
Davide Grohmann | 7e8f508 | 2022-03-23 12:48:45 +0100 | [diff] [blame] | 59 | * @msg: Mailbox message |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 60 | */ |
| 61 | struct ethosu_inference { |
Kristofer Jonsson | ec47704 | 2023-01-20 13:38:13 +0100 | [diff] [blame] | 62 | struct device *dev; |
| 63 | struct ethosu_mailbox *mailbox; |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 64 | struct file *file; |
| 65 | struct kref kref; |
| 66 | wait_queue_head_t waitq; |
| 67 | bool done; |
| 68 | uint32_t ifm_count; |
| 69 | struct ethosu_buffer *ifm[ETHOSU_FD_MAX]; |
| 70 | uint32_t ofm_count; |
| 71 | struct ethosu_buffer *ofm[ETHOSU_FD_MAX]; |
| 72 | struct ethosu_network *net; |
| 73 | enum ethosu_uapi_status status; |
| 74 | uint8_t pmu_event_config[ETHOSU_PMU_EVENT_MAX]; |
| 75 | uint32_t pmu_event_count[ETHOSU_PMU_EVENT_MAX]; |
| 76 | uint32_t pmu_cycle_counter_enable; |
| 77 | uint64_t pmu_cycle_counter_count; |
| 78 | struct ethosu_mailbox_msg msg; |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | /**************************************************************************** |
| 82 | * Functions |
| 83 | ****************************************************************************/ |
| 84 | |
| 85 | /** |
| 86 | * ethosu_inference_create() - Create inference |
| 87 | * |
| 88 | * This function must be called in the context of a user space process. |
| 89 | * |
| 90 | * Return: fd on success, else error code. |
| 91 | */ |
Kristofer Jonsson | ec47704 | 2023-01-20 13:38:13 +0100 | [diff] [blame] | 92 | int ethosu_inference_create(struct device *dev, |
| 93 | struct ethosu_mailbox *mailbox, |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 94 | struct ethosu_network *net, |
| 95 | struct ethosu_uapi_inference_create *uapi); |
| 96 | |
| 97 | /** |
| 98 | * ethosu_inference_get_from_fd() - Get inference handle from fd |
| 99 | * |
| 100 | * This function must be called from a user space context. |
| 101 | * |
| 102 | * Return: Pointer on success, else ERR_PTR. |
| 103 | */ |
| 104 | struct ethosu_inference *ethosu_inference_get_from_fd(int fd); |
| 105 | |
| 106 | /** |
| 107 | * ethosu_inference_get() - Get inference |
| 108 | */ |
| 109 | void ethosu_inference_get(struct ethosu_inference *inf); |
| 110 | |
| 111 | /** |
| 112 | * ethosu_inference_put() - Put inference |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 113 | * |
| 114 | * Return: 1 if object was removed, else 0. |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 115 | */ |
Kristofer Jonsson | 442fefb | 2022-03-17 17:15:52 +0100 | [diff] [blame] | 116 | int ethosu_inference_put(struct ethosu_inference *inf); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 117 | |
| 118 | /** |
| 119 | * ethosu_inference_rsp() - Handle inference response |
| 120 | */ |
Kristofer Jonsson | ec47704 | 2023-01-20 13:38:13 +0100 | [diff] [blame] | 121 | void ethosu_inference_rsp(struct ethosu_mailbox *mailbox, |
Kristofer Jonsson | d779a08 | 2023-01-04 17:09:47 +0100 | [diff] [blame] | 122 | int msg_id, |
| 123 | struct ethosu_core_msg_inference_rsp *rsp); |
Kristofer Jonsson | 116a635 | 2020-08-20 17:25:23 +0200 | [diff] [blame] | 124 | |
| 125 | #endif /* ETHOSU_INFERENCE_H */ |