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