blob: f004f92f24d5f00ab42bf273d2b04cf3fdf5ad81 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
Kristofer Jonsson35de9e62022-03-08 13:25:45 +01002 * Copyright (c) 2020-2022 Arm Limited.
Kristofer Jonsson116a6352020-08-20 17:25:23 +02003 *
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ärd7c24c772021-01-14 19:53:17 +010027#include "ethosu_core_interface.h"
Kristofer Jonsson116a6352020-08-20 17:25:23 +020028
29#include <linux/types.h>
30#include <linux/mailbox_client.h>
31#include <linux/workqueue.h>
32
33/****************************************************************************
34 * Types
35 ****************************************************************************/
36
37struct device;
38struct ethosu_buffer;
39struct ethosu_device;
40struct ethosu_core_msg;
41struct ethosu_core_queue;
42struct resource;
43
44typedef void (*ethosu_mailbox_cb)(void *user_arg);
45
46struct 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 */
68int 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 */
78void 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 */
85int ethosu_mailbox_read(struct ethosu_mailbox *mbox,
86 struct ethosu_core_msg *header,
87 void *data,
88 size_t length);
89
90/**
Jonny Svärd7c24c772021-01-14 19:53:17 +010091 * ethosu_mailbox_reset() - Reset to end of queue
92 */
93void ethosu_mailbox_reset(struct ethosu_mailbox *mbox);
94
95/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +020096 * ethosu_mailbox_ping() - Send ping message
97 *
98 * Return: 0 on success, else error code.
99 */
100int ethosu_mailbox_ping(struct ethosu_mailbox *mbox);
101
102/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100103 * ethosu_mailbox_pong() - Send pong response
104 *
105 * Return: 0 on success, else error code.
106 */
107int 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 */
114int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox);
115
116/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200117 * ethosu_mailbox_capabilities_request() - Send capabilities request
118 *
119 * Return: 0 on success, else error code.
120 */
121int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox,
122 void *user_arg);
123
124/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200125 * ethosu_mailbox_inference() - Send inference
126 *
127 * Return: 0 on success, else error code.
128 */
129int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
130 void *user_arg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200131 uint32_t ifm_count,
132 struct ethosu_buffer **ifm,
133 uint32_t ofm_count,
134 struct ethosu_buffer **ofm,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200135 struct ethosu_buffer *network,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100136 uint32_t network_index,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200137 uint8_t *pmu_event_config,
138 uint8_t pmu_event_config_count,
139 uint8_t pmu_cycle_counter_enable);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200140
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100141/**
142 * ethosu_mailbox_network_info_request() - Send network info request
143 *
144 * Return: 0 on success, else error code.
145 */
146int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox,
147 void *user_arg,
148 struct ethosu_buffer *network,
149 uint32_t network_index);
150
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200151#endif /* ETHOSU_MAILBOX_H */