blob: 956685bebb95a84d0945b00af3940e9cd053c748 [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;
Kristofer Jonssonf5b98c92022-03-14 16:09:12 +010042struct ethosu_watchdog;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020043struct resource;
44
45typedef void (*ethosu_mailbox_cb)(void *user_arg);
46
47struct ethosu_mailbox {
48 struct device *dev;
49 struct workqueue_struct *wq;
50 struct work_struct work;
51 struct ethosu_core_queue __iomem *in_queue;
52 struct ethosu_core_queue __iomem *out_queue;
53 struct mbox_client client;
54 struct mbox_chan *rx;
55 struct mbox_chan *tx;
56 ethosu_mailbox_cb callback;
57 void *user_arg;
Kristofer Jonssonf5b98c92022-03-14 16:09:12 +010058 struct ethosu_watchdog *wdog;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020059};
60
61/****************************************************************************
62 * Functions
63 ****************************************************************************/
64
65/**
66 * ethosu_mailbox_init() - Initialize mailbox
67 *
68 * Return: 0 on success, else error code.
69 */
70int ethosu_mailbox_init(struct ethosu_mailbox *mbox,
71 struct device *dev,
72 struct resource *in_queue,
73 struct resource *out_queue,
74 ethosu_mailbox_cb callback,
Kristofer Jonssonf5b98c92022-03-14 16:09:12 +010075 void *user_arg,
76 struct ethosu_watchdog *wdog);
Kristofer Jonsson116a6352020-08-20 17:25:23 +020077
78/**
79 * ethosu_mailbox_deinit() - Deinitialize mailbox
80 */
81void ethosu_mailbox_deinit(struct ethosu_mailbox *mbox);
82
83/**
84 * ethosu_mailbox_read() - Read message from mailbox
85 *
86 * Return: 0 message read, else error code.
87 */
88int ethosu_mailbox_read(struct ethosu_mailbox *mbox,
89 struct ethosu_core_msg *header,
90 void *data,
91 size_t length);
92
93/**
Jonny Svärd7c24c772021-01-14 19:53:17 +010094 * ethosu_mailbox_reset() - Reset to end of queue
95 */
96void ethosu_mailbox_reset(struct ethosu_mailbox *mbox);
97
98/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +020099 * ethosu_mailbox_ping() - Send ping message
100 *
101 * Return: 0 on success, else error code.
102 */
103int ethosu_mailbox_ping(struct ethosu_mailbox *mbox);
104
105/**
Jonny Svärd7c24c772021-01-14 19:53:17 +0100106 * ethosu_mailbox_pong() - Send pong response
107 *
108 * Return: 0 on success, else error code.
109 */
110int ethosu_mailbox_pong(struct ethosu_mailbox *mbox);
111
112/**
113 * ethosu_mailbox_version_response - Send version request
114 *
115 * Return: 0 on succes, else error code
116 */
117int ethosu_mailbox_version_request(struct ethosu_mailbox *mbox);
118
119/**
Davide Grohmann35ce6c82021-06-01 15:03:51 +0200120 * ethosu_mailbox_capabilities_request() - Send capabilities request
121 *
122 * Return: 0 on success, else error code.
123 */
124int ethosu_mailbox_capabilities_request(struct ethosu_mailbox *mbox,
125 void *user_arg);
126
127/**
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200128 * ethosu_mailbox_inference() - Send inference
129 *
130 * Return: 0 on success, else error code.
131 */
132int ethosu_mailbox_inference(struct ethosu_mailbox *mbox,
133 void *user_arg,
Kristofer Jonssonb74492c2020-09-10 13:26:01 +0200134 uint32_t ifm_count,
135 struct ethosu_buffer **ifm,
136 uint32_t ofm_count,
137 struct ethosu_buffer **ofm,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200138 struct ethosu_buffer *network,
Kristofer Jonsson35de9e62022-03-08 13:25:45 +0100139 uint32_t network_index,
Per Åstrandf7e407a2020-10-23 21:25:05 +0200140 uint8_t *pmu_event_config,
141 uint8_t pmu_event_config_count,
142 uint8_t pmu_cycle_counter_enable);
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200143
Kristofer Jonsson3c6a2602022-03-10 11:17:29 +0100144/**
145 * ethosu_mailbox_network_info_request() - Send network info request
146 *
147 * Return: 0 on success, else error code.
148 */
149int ethosu_mailbox_network_info_request(struct ethosu_mailbox *mbox,
150 void *user_arg,
151 struct ethosu_buffer *network,
152 uint32_t network_index);
153
Kristofer Jonsson116a6352020-08-20 17:25:23 +0200154#endif /* ETHOSU_MAILBOX_H */