blob: cc9ea8b102af0204efdb8f7e874eb1d826cd71cd [file] [log] [blame]
Jonny Svärd136810f2021-10-13 16:04:26 +02001/*
2 * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef ETHOSU_DEVICE_H
20#define ETHOSU_DEVICE_H
21
22/******************************************************************************
23 * Includes
24 ******************************************************************************/
25#include "ethosu_types.h"
26
27#include <stdbool.h>
28#include <stdint.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/******************************************************************************
35 * Defines
36 ******************************************************************************/
37
Jonny Svärd20ce37f2021-12-17 17:00:57 +010038// NOTE: Deprecated
Jonny Svärd136810f2021-10-13 16:04:26 +020039#ifndef ETHOSU_PMU_NCOUNTERS
40#define ETHOSU_PMU_NCOUNTERS 4
41#endif
42
43/******************************************************************************
44 * Types
45 ******************************************************************************/
46struct NPU_REG; // Forward declare, to be implemented by each device
47
48struct ethosu_device
49{
50 volatile struct NPU_REG *reg; // Register map
51 uint32_t secure;
52 uint32_t privileged;
53};
54
55/******************************************************************************
56 * Prototypes
57 ******************************************************************************/
58
59/**
60 * Initialize the device.
61 */
62struct ethosu_device *ethosu_dev_init(const void *base_address, uint32_t secure_enable, uint32_t privilege_enable);
63
64/**
65 * Deinitialize the device.
66 */
67void ethosu_dev_deinit(struct ethosu_device *dev);
68
69/**
70 * Initialize AXI settings for device.
71 */
72enum ethosu_error_codes ethosu_dev_axi_init(struct ethosu_device *dev);
73
74/**
75 * Execute a given command stream on NPU.
76 * \param[in] cmd_stream_ptr Pointer to the command stream
77 * \param[in] cms_length Command stream length
78 * \param[in] base_addr Pointer to array of base addresses
79 * - 0: weight tensor
80 * - 1: scratch tensor
81 * - All input tensors
82 * - All output tensors
83 * \param[in] num_base_addr Number of base addresses.
84 * \return \ref ethosu_error_codes
85 */
86enum ethosu_error_codes ethosu_dev_run_command_stream(struct ethosu_device *dev,
87 const uint8_t *cmd_stream_ptr,
88 uint32_t cms_length,
89 const uint64_t *base_addr,
90 int num_base_addr);
91
92/**
93 * Interrupt handler on device layer
94 * \return true if NPU status is OK, otherwise false
95 */
96bool ethosu_dev_handle_interrupt(struct ethosu_device *dev);
97
98/**
99 * Get hardware information from NPU
100 * \param[out] hwinfo Pointer to the hardware info struct to be filled in.
101 */
102void ethosu_dev_get_hw_info(struct ethosu_device *dev, struct ethosu_hw_info *hwinfo);
103
104/**
105 * Verify that requested security state and privilege mode are active
106 * \return 32 bit status value
107 */
108bool ethosu_dev_verify_access_state(struct ethosu_device *dev);
109
110/**
111 * Performs a NPU soft reset and waits for the NPU to become ready
112 * \return \ref ethosu_error_codes
113 */
114enum ethosu_error_codes ethosu_dev_soft_reset(struct ethosu_device *dev);
115
116/**
117 * Enable/disable clock and power using clock/power q interface.
118 * \param[in] clock_q Clock q ENABLE/DISABLE \ref clock_q_request.
119 * \param[in] power_q Power q ENABLE/DISABLE \ref power_q_request.
120 * \return \ref ethosu_error_codes
121 */
122enum ethosu_error_codes ethosu_dev_set_clock_and_power(struct ethosu_device *dev,
123 enum ethosu_clock_q_request clock_q,
124 enum ethosu_power_q_request power_q);
125
126/**
127 * Verifies that optimizer parameters from model are compatible with the hardware
128 * \param[in] cfg Config data from optimizer.
129 * \param[in] id Id data from optimizer.
130 * \return true if parameters match with hardware, false otherwise.
131 */
132bool ethosu_dev_verify_optimizer_config(struct ethosu_device *dev, uint32_t cfg_in, uint32_t id_in);
133
134#ifdef __cplusplus
135}
136#endif
137
138#endif // ETHOSU_DEVICE_H