blob: 0bc5ffbdb25c1774f3427446f14d2f324e11c935 [file] [log] [blame]
Kristofer Jonsson116a6352020-08-20 17:25:23 +02001/*
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ä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/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200117 * ethosu_mailbox_inference() - Send inference
118 *
119 * Return: 0 on success, else error code.
120 */
121int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
122 void *user_arg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200123 uint32_t ifm_count,
124 struct ethosu_buffer **ifm,
125 uint32_t ofm_count,
126 struct ethosu_buffer **ofm,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200127 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 Jonsson116a6352020-08-20 17:25:23 +0200131
132#endif /* ETHOSU_MAILBOX_H */