TT Zephyr Platforms 19.5.0-rc1
Tenstorrent Firmware
Loading...
Searching...
No Matches
jtag.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Tenstorrent AI ULC
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef INCLUDE_ZEPHYR_DRIVERS_JTAG_H_
8#define INCLUDE_ZEPHYR_DRIVERS_JTAG_H_
9
10#include <errno.h>
11#include <stdbool.h>
12#include <stdint.h>
13
14#include <zephyr/device.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20#ifdef CONFIG_JTAG_EMUL
21int jtag_emul_setup(const struct device *dev, uint32_t *buf, size_t buf_len);
22int jtag_emul_axi_read32(const struct device *dev, uint32_t addr, uint32_t *value);
23#endif
24
25typedef int (*jtag_setup_api_t)(const struct device *dev);
26typedef int (*jtag_teardown_api_t)(const struct device *dev);
27
28typedef int (*jtag_tick_api_t)(const struct device *dev, uint32_t count);
29typedef int (*jtag_reset_api_t)(const struct device *dev);
30typedef int (*jtag_read_id_api_t)(const struct device *dev, uint32_t *id);
31
32typedef int (*jtag_update_ir_api_t)(const struct device *dev, uint32_t count, const uint8_t *data);
33typedef int (*jtag_update_dr_api_t)(const struct device *dev, bool idle, uint32_t count,
34 const uint8_t *data_in, uint8_t *data_out);
35
36typedef int (*jtag_axi_read32_api_t)(const struct device *dev, uint32_t addr, uint32_t *value);
37typedef int (*jtag_axi_write32_api_t)(const struct device *dev, uint32_t addr, uint32_t value);
38typedef int (*jtag_axi_block_write_api_t)(const struct device *dev, uint32_t addr,
39 const uint32_t *value, uint32_t len);
40
56
57static inline int jtag_tick(const struct device *dev, uint32_t count)
58{
59 const struct jtag_api *api = dev->api;
60
61 if (dev == NULL) {
62 return -EINVAL;
63 }
64
65 return api->tick(dev, count);
66}
67
68static inline int jtag_read_id(const struct device *dev, uint32_t *id)
69{
70 const struct jtag_api *api = dev->api;
71
72 if (dev == NULL || id == NULL) {
73 return -EINVAL;
74 }
75
76 return api->read_id(dev, id);
77}
78
79static inline int jtag_reset(const struct device *dev)
80{
81 const struct jtag_api *api = dev->api;
82
83 if (dev == NULL) {
84 return -EINVAL;
85 }
86
87 return api->reset(dev);
88}
89
90static ALWAYS_INLINE int jtag_update_ir(const struct device *dev, uint32_t count,
91 const uint8_t *data)
92{
93 const struct jtag_api *api = dev->api;
94
95 if (dev == NULL || (data == NULL && count > 0)) {
96 return -EINVAL;
97 }
98
99 if (count == 0) {
100 return 0;
101 }
102
103 return api->update_ir(dev, count, data);
104}
105
106static ALWAYS_INLINE int jtag_update_dr(const struct device *dev, bool idle, uint32_t count,
107 const uint8_t *data_in, uint8_t *data_out)
108{
109 const struct jtag_api *api = dev->api;
110
111 if (dev == NULL || (data_in == NULL && count > 0)) {
112 return -EINVAL;
113 }
114
115 if (count == 0) {
116 return 0;
117 }
118
119 return api->update_dr(dev, idle, count, data_in, data_out);
120}
121
122static inline int jtag_setup(const struct device *dev)
123{
124 const struct jtag_api *api = dev->api;
125
126 if (dev == NULL) {
127 return -EINVAL;
128 }
129
130 return api->setup(dev);
131}
132
133static inline int jtag_teardown(const struct device *dev)
134{
135 const struct jtag_api *api = dev->api;
136
137 if (dev == NULL) {
138 return -EINVAL;
139 }
140
141 return api->teardown(dev);
142}
143
144static inline int jtag_axi_read32(const struct device *dev, uint32_t addr, uint32_t *value)
145{
146 const struct jtag_api *api = dev->api;
147
148 if (dev == NULL) {
149 return -EINVAL;
150 }
151
152 return api->axi_read32(dev, addr, value);
153}
154
155static inline int jtag_axi_write32(const struct device *dev, uint32_t addr, uint32_t value)
156{
157 const struct jtag_api *api = dev->api;
158
159 if (dev == NULL) {
160 return -EINVAL;
161 }
162
163 return api->axi_write32(dev, addr, value);
164}
165
166static inline int jtag_axi_block_write(const struct device *dev, uint32_t addr,
167 const uint32_t *value, uint32_t len)
168{
169 const struct jtag_api *api = dev->api;
170
171 if (dev == NULL) {
172 return -EINVAL;
173 }
174
175 return api->axi_block_write(dev, addr, value, len);
176}
177
178#ifdef __cplusplus
179}
180#endif
181
182#endif /* INCLUDE_ZEPHYR_DRIVERS_JTAG_H_ */
#define NULL
Definition avs.c:45
#define EINVAL
#define ALWAYS_INLINE
int(* jtag_read_id_api_t)(const struct device *dev, uint32_t *id)
Definition jtag.h:30
static int jtag_tick(const struct device *dev, uint32_t count)
Definition jtag.h:57
static int jtag_axi_block_write(const struct device *dev, uint32_t addr, const uint32_t *value, uint32_t len)
Definition jtag.h:166
int(* jtag_teardown_api_t)(const struct device *dev)
Definition jtag.h:26
int(* jtag_reset_api_t)(const struct device *dev)
Definition jtag.h:29
static int jtag_reset(const struct device *dev)
Definition jtag.h:79
static int jtag_axi_write32(const struct device *dev, uint32_t addr, uint32_t value)
Definition jtag.h:155
static int jtag_setup(const struct device *dev)
Definition jtag.h:122
static int jtag_read_id(const struct device *dev, uint32_t *id)
Definition jtag.h:68
static int jtag_axi_read32(const struct device *dev, uint32_t addr, uint32_t *value)
Definition jtag.h:144
int(* jtag_axi_read32_api_t)(const struct device *dev, uint32_t addr, uint32_t *value)
Definition jtag.h:36
int(* jtag_axi_write32_api_t)(const struct device *dev, uint32_t addr, uint32_t value)
Definition jtag.h:37
int(* jtag_update_ir_api_t)(const struct device *dev, uint32_t count, const uint8_t *data)
Definition jtag.h:32
int(* jtag_axi_block_write_api_t)(const struct device *dev, uint32_t addr, const uint32_t *value, uint32_t len)
Definition jtag.h:38
static ALWAYS_INLINE int jtag_update_ir(const struct device *dev, uint32_t count, const uint8_t *data)
Definition jtag.h:90
int(* jtag_setup_api_t)(const struct device *dev)
Definition jtag.h:25
static ALWAYS_INLINE int jtag_update_dr(const struct device *dev, bool idle, uint32_t count, const uint8_t *data_in, uint8_t *data_out)
Definition jtag.h:106
int(* jtag_tick_api_t)(const struct device *dev, uint32_t count)
Definition jtag.h:28
static int jtag_teardown(const struct device *dev)
Definition jtag.h:133
int(* jtag_update_dr_api_t)(const struct device *dev, bool idle, uint32_t count, const uint8_t *data_in, uint8_t *data_out)
Definition jtag.h:33
static uint8_t buf[1]
Definition log_backend_ringbuf.c:24
__UINT32_TYPE__ uint32_t
__UINT8_TYPE__ uint8_t
void * data
const void * api
Definition jtag.h:41
jtag_axi_read32_api_t axi_read32
Definition jtag.h:52
jtag_teardown_api_t teardown
Definition jtag.h:43
jtag_tick_api_t tick
Definition jtag.h:45
jtag_setup_api_t setup
Definition jtag.h:42
jtag_reset_api_t reset
Definition jtag.h:46
jtag_axi_block_write_api_t axi_block_write
Definition jtag.h:54
jtag_update_dr_api_t update_dr
Definition jtag.h:50
jtag_update_ir_api_t update_ir
Definition jtag.h:49
jtag_read_id_api_t read_id
Definition jtag.h:47
jtag_axi_write32_api_t axi_write32
Definition jtag.h:53