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_INFERENCE_H |
| 22 | #define ETHOSU_INFERENCE_H |
| 23 | |
| 24 | /**************************************************************************** |
| 25 | * Includes |
| 26 | ****************************************************************************/ |
| 27 | |
| 28 | #include "uapi/ethosu.h" |
| 29 | |
| 30 | #include <linux/kref.h> |
| 31 | #include <linux/types.h> |
| 32 | #include <linux/wait.h> |
| 33 | |
| 34 | /**************************************************************************** |
| 35 | * Types |
| 36 | ****************************************************************************/ |
| 37 | |
| 38 | struct ethosu_buffer; |
| 39 | struct ethosu_core_inference_rsp; |
| 40 | struct ethosu_device; |
| 41 | struct ethosu_network; |
| 42 | struct ethosu_uapi_inference_create; |
| 43 | struct file; |
| 44 | |
| 45 | /** |
| 46 | * struct ethosu_inference - Inference struct |
| 47 | * @edev: Arm Ethos-U device |
| 48 | * @file: File handle |
| 49 | * @kref: Reference counter |
| 50 | * @waitq: Wait queue |
| 51 | * @ifm: Pointer to IFM buffer |
| 52 | * @ofm: Pointer to OFM buffer |
| 53 | * @net: Pointer to network |
| 54 | * @pending: Pending response from the firmware |
| 55 | * @status: Inference status |
| 56 | */ |
| 57 | struct ethosu_inference { |
| 58 | struct ethosu_device *edev; |
| 59 | struct file *file; |
| 60 | struct kref kref; |
| 61 | wait_queue_head_t waitq; |
| 62 | struct ethosu_buffer *ifm; |
| 63 | struct ethosu_buffer *ofm; |
| 64 | struct ethosu_network *net; |
| 65 | bool pending; |
| 66 | enum ethosu_uapi_status status; |
| 67 | struct list_head list; |
| 68 | }; |
| 69 | |
| 70 | /**************************************************************************** |
| 71 | * Functions |
| 72 | ****************************************************************************/ |
| 73 | |
| 74 | /** |
| 75 | * ethosu_inference_create() - Create inference |
| 76 | * |
| 77 | * This function must be called in the context of a user space process. |
| 78 | * |
| 79 | * Return: fd on success, else error code. |
| 80 | */ |
| 81 | int ethosu_inference_create(struct ethosu_device *edev, |
| 82 | struct ethosu_network *net, |
| 83 | struct ethosu_uapi_inference_create *uapi); |
| 84 | |
| 85 | /** |
| 86 | * ethosu_inference_get_from_fd() - Get inference handle from fd |
| 87 | * |
| 88 | * This function must be called from a user space context. |
| 89 | * |
| 90 | * Return: Pointer on success, else ERR_PTR. |
| 91 | */ |
| 92 | struct ethosu_inference *ethosu_inference_get_from_fd(int fd); |
| 93 | |
| 94 | /** |
| 95 | * ethosu_inference_get() - Get inference |
| 96 | */ |
| 97 | void ethosu_inference_get(struct ethosu_inference *inf); |
| 98 | |
| 99 | /** |
| 100 | * ethosu_inference_put() - Put inference |
| 101 | */ |
| 102 | void ethosu_inference_put(struct ethosu_inference *inf); |
| 103 | |
| 104 | /** |
| 105 | * ethosu_inference_rsp() - Handle inference response |
| 106 | */ |
| 107 | void ethosu_inference_rsp(struct ethosu_device *edev, |
| 108 | struct ethosu_core_inference_rsp *rsp); |
| 109 | |
| 110 | #endif /* ETHOSU_INFERENCE_H */ |