blob: 132dff2f5a29933be3032258619a51c488f83615 [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_DEVICE_H
22#define ETHOSU_DEVICE_H
23
24/****************************************************************************
25 * Includes
26 ****************************************************************************/
27
Davide Grohmann35ce6c82021-06-01 15:03:51 +020028#include "uapi/ethosu.h"
Kristofer Jonsson116a6352020-08-20 17:25:23 +020029#include "ethosu_mailbox.h"
Kristofer Jonssonf5b98c92022-03-14 16:09:12 +010030#include "ethosu_watchdog.h"
Kristofer Jonsson116a6352020-08-20 17:25:23 +020031
32#include <linux/device.h>
33#include <linux/cdev.h>
34#include <linux/io.h>
35#include <linux/mutex.h>
36#include <linux/workqueue.h>
Davide Grohmann35ce6c82021-06-01 15:03:51 +020037#include <linux/completion.h>
Kristofer Jonsson116a6352020-08-20 17:25:23 +020038
39/****************************************************************************
40 * Types
41 ****************************************************************************/
42
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010043struct reset_control;
44
Kristofer Jonsson116a6352020-08-20 17:25:23 +020045/**
46 * struct ethosu_device - Device structure
47 */
48struct ethosu_device {
Kristofer Jonssonf5b98c92022-03-14 16:09:12 +010049 struct device *dev;
50 struct cdev cdev;
51 struct class *class;
52 dev_t devt;
53 struct mutex mutex;
54 struct ethosu_mailbox mailbox;
55 struct ethosu_watchdog watchdog;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010056 struct reset_control *reset;
Kristofer Jonsson116a6352020-08-20 17:25:23 +020057};
58
Davide Grohmann35ce6c82021-06-01 15:03:51 +020059/**
60 * struct ethosu_capabilities - Capabilities internal struct
61 */
62struct ethosu_capabilities {
63 struct ethosu_device *edev;
64 struct completion done;
65 struct kref refcount;
66 struct ethosu_uapi_device_capabilities *capabilities;
Kristofer Jonsson442fefb2022-03-17 17:15:52 +010067 struct ethosu_mailbox_msg msg;
68 int errno;
Davide Grohmann35ce6c82021-06-01 15:03:51 +020069};
70
Kristofer Jonsson116a6352020-08-20 17:25:23 +020071/****************************************************************************
72 * Functions
73 ****************************************************************************/
74
75/**
76 * ethosu_dev_init() - Initialize the device
77 *
78 * Return: 0 on success, else error code.
79 */
80int ethosu_dev_init(struct ethosu_device *edev,
81 struct device *dev,
82 struct class *class,
Kristofer Jonsson4aec3762021-10-13 17:09:27 +020083 dev_t devt,
Kristofer Jonsson116a6352020-08-20 17:25:23 +020084 struct resource *in_queue,
85 struct resource *out_queue);
86
87/**
88 * ethosu_dev_deinit() - Initialize the device
89 */
90void ethosu_dev_deinit(struct ethosu_device *edev);
91
Davide Grohmann8b1fe552022-04-07 16:58:32 +020092/**
93 * ethosu_firmware_reset() - Reset the device running firmware
94 */
95int ethosu_firmware_reset(struct ethosu_device *edev);
96
Kristofer Jonsson116a6352020-08-20 17:25:23 +020097#endif /* ETHOSU_DEVICE_H */