blob: c5865d0b8c33f7fa2b156a1f03fd659a112f0fff [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 ****************************************************************************/
27
28#include <linux/types.h>
29#include <linux/mailbox_client.h>
30#include <linux/workqueue.h>
31
32/****************************************************************************
33 * Types
34 ****************************************************************************/
35
36struct device;
37struct ethosu_buffer;
38struct ethosu_device;
39struct ethosu_core_msg;
40struct ethosu_core_queue;
41struct resource;
42
43typedef void (*ethosu_mailbox_cb)(void *user_arg);
44
45struct ethosu_mailbox {
46 struct device *dev;
47 struct workqueue_struct *wq;
48 struct work_struct work;
49 struct ethosu_core_queue __iomem *in_queue;
50 struct ethosu_core_queue __iomem *out_queue;
51 struct mbox_client client;
52 struct mbox_chan *rx;
53 struct mbox_chan *tx;
54 ethosu_mailbox_cb callback;
55 void *user_arg;
56};
57
58/****************************************************************************
59 * Functions
60 ****************************************************************************/
61
62/**
63 * ethosu_mailbox_init() - Initialize mailbox
64 *
65 * Return: 0 on success, else error code.
66 */
67int ethosu_mailbox_init(struct ethosu_mailbox *mbox,
68 struct device *dev,
69 struct resource *in_queue,
70 struct resource *out_queue,
71 ethosu_mailbox_cb callback,
72 void *user_arg);
73
74/**
75 * ethosu_mailbox_deinit() - Deinitialize mailbox
76 */
77void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox);
78
79/**
80 * ethosu_mailbox_read() - Read message from mailbox
81 *
82 * Return: 0 message read, else error code.
83 */
84int ethosu_mailbox_read(struct ethosu_mailbox *mbox,
85 struct ethosu_core_msg *header,
86 void *data,
87 size_t length);
88
89/**
90 * ethosu_mailbox_ping() - Send ping message
91 *
92 * Return: 0 on success, else error code.
93 */
94int ethosu_mailbox_ping(struct ethosu_mailbox *mbox);
95
96/**
97 * ethosu_mailbox_inference() - Send inference
98 *
99 * Return: 0 on success, else error code.
100 */
101int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
102 void *user_arg,
103 struct ethosu_buffer *ifm,
104 struct ethosu_buffer *ofm,
105 struct ethosu_buffer *network);
106
107#endif /* ETHOSU_MAILBOX_H */