jtag: linuxgpiod: drop extra parenthesis
[openocd.git] / src / target / arm_adi_v5.h
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 /***************************************************************************
4 * Copyright (C) 2006 by Magnus Lundin *
5 * lundin@mlu.mine.nu *
6 * *
7 * Copyright (C) 2008 by Spencer Oliver *
8 * spen@spen-soft.co.uk *
9 * *
10 * Copyright (C) 2019-2021, Ampere Computing LLC *
11 ***************************************************************************/
12
13 #ifndef OPENOCD_TARGET_ARM_ADI_V5_H
14 #define OPENOCD_TARGET_ARM_ADI_V5_H
15
16 /**
17 * @file
18 * This defines formats and data structures used to talk to ADIv5 entities.
19 * Those include a DAP, different types of Debug Port (DP), and memory mapped
20 * resources accessed through a MEM-AP.
21 */
22
23 #include <helper/list.h>
24 #include "arm_jtag.h"
25 #include "helper/bits.h"
26
27 /* JEP106 ID for ARM */
28 #define ARM_ID 0x23B
29
30 /* three-bit ACK values for SWD access (sent LSB first) */
31 #define SWD_ACK_OK 0x1
32 #define SWD_ACK_WAIT 0x2
33 #define SWD_ACK_FAULT 0x4
34
35 #define DPAP_WRITE 0
36 #define DPAP_READ 1
37
38 #define BANK_REG(bank, reg) (((bank) << 4) | (reg))
39
40 /* A[3:0] for DP registers; A[1:0] are always zero.
41 * - JTAG accesses all of these via JTAG_DP_DPACC, except for
42 * IDCODE (JTAG_DP_IDCODE) and ABORT (JTAG_DP_ABORT).
43 * - SWD accesses these directly, sometimes needing SELECT.DPBANKSEL
44 */
45 #define DP_DPIDR BANK_REG(0x0, 0x0) /* DPv1+: ro */
46 #define DP_ABORT BANK_REG(0x0, 0x0) /* DPv1+: SWD: wo */
47 #define DP_DPIDR1 BANK_REG(0x1, 0x0) /* DPv3: ro */
48 #define DP_BASEPTR0 BANK_REG(0x2, 0x0) /* DPv3: ro */
49 #define DP_BASEPTR1 BANK_REG(0x3, 0x0) /* DPv3: ro */
50 #define DP_CTRL_STAT BANK_REG(0x0, 0x4) /* DPv0+: rw */
51 #define DP_DLCR BANK_REG(0x1, 0x4) /* DPv1+: SWD: rw */
52 #define DP_TARGETID BANK_REG(0x2, 0x4) /* DPv2: ro */
53 #define DP_DLPIDR BANK_REG(0x3, 0x4) /* DPv2: ro */
54 #define DP_EVENTSTAT BANK_REG(0x4, 0x4) /* DPv2: ro */
55 #define DP_SELECT1 BANK_REG(0x5, 0x4) /* DPv3: ro */
56 #define DP_RESEND BANK_REG(0x0, 0x8) /* DPv1+: SWD: ro */
57 #define DP_SELECT BANK_REG(0x0, 0x8) /* DPv0+: JTAG: rw; SWD: wo */
58 #define DP_RDBUFF BANK_REG(0x0, 0xC) /* DPv0+: ro */
59 #define DP_TARGETSEL BANK_REG(0x0, 0xC) /* DPv2: SWD: wo */
60
61 #define DLCR_TO_TRN(dlcr) ((uint32_t)(1 + ((3 & (dlcr)) >> 8))) /* 1..4 clocks */
62
63 /* Fields of DP_DPIDR register */
64 #define DP_DPIDR_VERSION_SHIFT 12
65 #define DP_DPIDR_VERSION_MASK (0xFUL << DP_DPIDR_VERSION_SHIFT)
66
67 /* Fields of the DP's AP ABORT register */
68 #define DAPABORT (1UL << 0)
69 #define STKCMPCLR (1UL << 1) /* SWD-only */
70 #define STKERRCLR (1UL << 2) /* SWD-only */
71 #define WDERRCLR (1UL << 3) /* SWD-only */
72 #define ORUNERRCLR (1UL << 4) /* SWD-only */
73
74 /* Fields of register DP_DPIDR1 */
75 #define DP_DPIDR1_ASIZE_MASK (0x7F)
76 #define DP_DPIDR1_ERRMODE BIT(7)
77
78 /* Fields of register DP_BASEPTR0 */
79 #define DP_BASEPTR0_VALID BIT(0)
80
81 /* Fields of the DP's CTRL/STAT register */
82 #define CORUNDETECT (1UL << 0)
83 #define SSTICKYORUN (1UL << 1)
84 /* 3:2 - transaction mode (e.g. pushed compare) */
85 #define SSTICKYCMP (1UL << 4)
86 #define SSTICKYERR (1UL << 5)
87 #define READOK (1UL << 6) /* SWD-only */
88 #define WDATAERR (1UL << 7) /* SWD-only */
89 /* 11:8 - mask lanes for pushed compare or verify ops */
90 /* 21:12 - transaction counter */
91 #define CDBGRSTREQ (1UL << 26)
92 #define CDBGRSTACK (1UL << 27)
93 #define CDBGPWRUPREQ (1UL << 28)
94 #define CDBGPWRUPACK (1UL << 29)
95 #define CSYSPWRUPREQ (1UL << 30)
96 #define CSYSPWRUPACK (1UL << 31)
97
98 #define DP_DLPIDR_PROTVSN 1u
99
100 #define ADIV5_DP_SELECT_APSEL 0xFF000000
101 #define ADIV5_DP_SELECT_APBANK 0x000000F0
102 #define DP_SELECT_DPBANK 0x0000000F
103 /*
104 * Mask of AP ADDR in select cache, concatenating DP SELECT and DP_SELECT1.
105 * In case of ADIv5, the mask contains both APSEL and APBANKSEL fields.
106 */
107 #define SELECT_AP_MASK (~(uint64_t)DP_SELECT_DPBANK)
108
109 #define DP_APSEL_MAX (255) /* Strict limit for ADIv5, number of AP buffers for ADIv6 */
110 #define DP_APSEL_INVALID 0xF00 /* more than DP_APSEL_MAX and not ADIv6 aligned 4k */
111
112 #define DP_TARGETSEL_INVALID 0xFFFFFFFFU
113 #define DP_TARGETSEL_DPID_MASK 0x0FFFFFFFU
114 #define DP_TARGETSEL_INSTANCEID_MASK 0xF0000000U
115 #define DP_TARGETSEL_INSTANCEID_SHIFT 28
116
117
118 /* MEM-AP register addresses */
119 #define ADIV5_MEM_AP_REG_CSW (0x00)
120 #define ADIV5_MEM_AP_REG_TAR (0x04)
121 #define ADIV5_MEM_AP_REG_TAR64 (0x08) /* RW: Large Physical Address Extension */
122 #define ADIV5_MEM_AP_REG_DRW (0x0C) /* RW: Data Read/Write register */
123 #define ADIV5_MEM_AP_REG_BD0 (0x10) /* RW: Banked Data register 0-3 */
124 #define ADIV5_MEM_AP_REG_BD1 (0x14)
125 #define ADIV5_MEM_AP_REG_BD2 (0x18)
126 #define ADIV5_MEM_AP_REG_BD3 (0x1C)
127 #define ADIV5_MEM_AP_REG_MBT (0x20) /* --: Memory Barrier Transfer register */
128 #define ADIV5_MEM_AP_REG_BASE64 (0xF0) /* RO: Debug Base Address (LA) register */
129 #define ADIV5_MEM_AP_REG_CFG (0xF4) /* RO: Configuration register */
130 #define ADIV5_MEM_AP_REG_BASE (0xF8) /* RO: Debug Base Address register */
131
132 #define ADIV6_MEM_AP_REG_CSW (0xD00 + ADIV5_MEM_AP_REG_CSW)
133 #define ADIV6_MEM_AP_REG_TAR (0xD00 + ADIV5_MEM_AP_REG_TAR)
134 #define ADIV6_MEM_AP_REG_TAR64 (0xD00 + ADIV5_MEM_AP_REG_TAR64)
135 #define ADIV6_MEM_AP_REG_DRW (0xD00 + ADIV5_MEM_AP_REG_DRW)
136 #define ADIV6_MEM_AP_REG_BD0 (0xD00 + ADIV5_MEM_AP_REG_BD0)
137 #define ADIV6_MEM_AP_REG_BD1 (0xD00 + ADIV5_MEM_AP_REG_BD1)
138 #define ADIV6_MEM_AP_REG_BD2 (0xD00 + ADIV5_MEM_AP_REG_BD2)
139 #define ADIV6_MEM_AP_REG_BD3 (0xD00 + ADIV5_MEM_AP_REG_BD3)
140 #define ADIV6_MEM_AP_REG_MBT (0xD00 + ADIV5_MEM_AP_REG_MBT)
141 #define ADIV6_MEM_AP_REG_BASE64 (0xD00 + ADIV5_MEM_AP_REG_BASE64)
142 #define ADIV6_MEM_AP_REG_CFG (0xD00 + ADIV5_MEM_AP_REG_CFG)
143 #define ADIV6_MEM_AP_REG_BASE (0xD00 + ADIV5_MEM_AP_REG_BASE)
144
145 #define MEM_AP_REG_CSW(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_CSW : ADIV5_MEM_AP_REG_CSW)
146 #define MEM_AP_REG_TAR(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_TAR : ADIV5_MEM_AP_REG_TAR)
147 #define MEM_AP_REG_TAR64(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_TAR64 : ADIV5_MEM_AP_REG_TAR64)
148 #define MEM_AP_REG_DRW(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_DRW : ADIV5_MEM_AP_REG_DRW)
149 #define MEM_AP_REG_BD0(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_BD0 : ADIV5_MEM_AP_REG_BD0)
150 #define MEM_AP_REG_BD1(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_BD1 : ADIV5_MEM_AP_REG_BD1)
151 #define MEM_AP_REG_BD2(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_BD2 : ADIV5_MEM_AP_REG_BD2)
152 #define MEM_AP_REG_BD3(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_BD3 : ADIV5_MEM_AP_REG_BD3)
153 #define MEM_AP_REG_MBT(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_MBT : ADIV5_MEM_AP_REG_MBT)
154 #define MEM_AP_REG_BASE64(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_BASE64 : ADIV5_MEM_AP_REG_BASE64)
155 #define MEM_AP_REG_CFG(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_CFG : ADIV5_MEM_AP_REG_CFG)
156 #define MEM_AP_REG_BASE(dap) (is_adiv6(dap) ? ADIV6_MEM_AP_REG_BASE : ADIV5_MEM_AP_REG_BASE)
157
158 /* Generic AP register address */
159 #define ADIV5_AP_REG_IDR (0xFC) /* RO: Identification Register */
160 #define ADIV6_AP_REG_IDR (0xD00 + ADIV5_AP_REG_IDR)
161 #define AP_REG_IDR(dap) (is_adiv6(dap) ? ADIV6_AP_REG_IDR : ADIV5_AP_REG_IDR)
162
163 /* Fields of the MEM-AP's CSW register */
164 #define CSW_SIZE_MASK 7
165 #define CSW_8BIT 0
166 #define CSW_16BIT 1
167 #define CSW_32BIT 2
168 #define CSW_64BIT 3
169 #define CSW_128BIT 4
170 #define CSW_256BIT 5
171 #define CSW_ADDRINC_MASK (3UL << 4)
172 #define CSW_ADDRINC_OFF 0UL
173 #define CSW_ADDRINC_SINGLE (1UL << 4)
174 #define CSW_ADDRINC_PACKED (2UL << 4)
175 #define CSW_DEVICE_EN (1UL << 6)
176 #define CSW_TRIN_PROG (1UL << 7)
177
178 /* All fields in bits 12 and above are implementation-defined
179 * Defaults for AHB/AXI in "Standard Memory Access Port Definitions" from ADI
180 * Some bits are shared between buses
181 */
182 #define CSW_SPIDEN (1UL << 23)
183 #define CSW_DBGSWENABLE (1UL << 31)
184
185 /* AHB: Privileged */
186 #define CSW_AHB_HPROT1 (1UL << 25)
187 /* AHB: set HMASTER signals to AHB-AP ID */
188 #define CSW_AHB_MASTER_DEBUG (1UL << 29)
189 /* AHB5: non-secure access via HNONSEC
190 * AHB3: SBO, UNPREDICTABLE if zero */
191 #define CSW_AHB_SPROT (1UL << 30)
192 /* AHB: initial value of csw_default */
193 #define CSW_AHB_DEFAULT (CSW_AHB_HPROT1 | CSW_AHB_MASTER_DEBUG | CSW_DBGSWENABLE)
194
195 /* AXI: Privileged */
196 #define CSW_AXI_ARPROT0_PRIV (1UL << 28)
197 /* AXI: Non-secure */
198 #define CSW_AXI_ARPROT1_NONSEC (1UL << 29)
199 /* AXI: initial value of csw_default */
200 #define CSW_AXI_DEFAULT (CSW_AXI_ARPROT0_PRIV | CSW_AXI_ARPROT1_NONSEC | CSW_DBGSWENABLE)
201
202 /* APB: initial value of csw_default */
203 #define CSW_APB_DEFAULT (CSW_DBGSWENABLE)
204
205 /* Fields of the MEM-AP's CFG register */
206 #define MEM_AP_REG_CFG_BE BIT(0)
207 #define MEM_AP_REG_CFG_LA BIT(1)
208 #define MEM_AP_REG_CFG_LD BIT(2)
209 #define MEM_AP_REG_CFG_INVALID 0xFFFFFFF8
210
211 /* Fields of the MEM-AP's IDR register */
212 #define AP_REG_IDR_REVISION_MASK (0xF0000000)
213 #define AP_REG_IDR_REVISION_SHIFT (28)
214 #define AP_REG_IDR_DESIGNER_MASK (0x0FFE0000)
215 #define AP_REG_IDR_DESIGNER_SHIFT (17)
216 #define AP_REG_IDR_CLASS_MASK (0x0001E000)
217 #define AP_REG_IDR_CLASS_SHIFT (13)
218 #define AP_REG_IDR_VARIANT_MASK (0x000000F0)
219 #define AP_REG_IDR_VARIANT_SHIFT (4)
220 #define AP_REG_IDR_TYPE_MASK (0x0000000F)
221 #define AP_REG_IDR_TYPE_SHIFT (0)
222
223 #define AP_REG_IDR_CLASS_NONE (0x0)
224 #define AP_REG_IDR_CLASS_COM (0x1)
225 #define AP_REG_IDR_CLASS_MEM_AP (0x8)
226
227 #define AP_REG_IDR_VALUE(d, c, t) (\
228 (((d) << AP_REG_IDR_DESIGNER_SHIFT) & AP_REG_IDR_DESIGNER_MASK) | \
229 (((c) << AP_REG_IDR_CLASS_SHIFT) & AP_REG_IDR_CLASS_MASK) | \
230 (((t) << AP_REG_IDR_TYPE_SHIFT) & AP_REG_IDR_TYPE_MASK) \
231 )
232
233 #define AP_TYPE_MASK (AP_REG_IDR_DESIGNER_MASK | AP_REG_IDR_CLASS_MASK | AP_REG_IDR_TYPE_MASK)
234
235 /* FIXME: not SWD specific; should be renamed, e.g. adiv5_special_seq */
236 enum swd_special_seq {
237 LINE_RESET,
238 JTAG_TO_SWD,
239 JTAG_TO_DORMANT,
240 SWD_TO_JTAG,
241 SWD_TO_DORMANT,
242 DORMANT_TO_SWD,
243 DORMANT_TO_JTAG,
244 };
245
246 /**
247 * This represents an ARM Debug Interface (v5) Access Port (AP).
248 * Most common is a MEM-AP, for memory access.
249 */
250 struct adiv5_ap {
251 /**
252 * DAP this AP belongs to.
253 */
254 struct adiv5_dap *dap;
255
256 /**
257 * ADIv5: Number of this AP (0~255)
258 * ADIv6: Base address of this AP (4k aligned)
259 * TODO: to be more coherent, it should be renamed apsel
260 */
261 uint64_t ap_num;
262
263 /**
264 * Default value for (MEM-AP) AP_REG_CSW register.
265 */
266 uint32_t csw_default;
267
268 /**
269 * Cache for (MEM-AP) AP_REG_CSW register value. This is written to
270 * configure an access mode, such as autoincrementing AP_REG_TAR during
271 * word access. "-1" indicates no cached value.
272 */
273 uint32_t csw_value;
274
275 /**
276 * Save the supported CSW.Size data types for the MEM-AP.
277 * Each bit corresponds to a data type.
278 * 0b1 = Supported data size. 0b0 = Not supported.
279 * Bit 0 = Byte (8-bits)
280 * Bit 1 = Halfword (16-bits)
281 * Bit 2 = Word (32-bits) - always supported by spec.
282 * Bit 3 = Doubleword (64-bits)
283 * Bit 4 = 128-bits
284 * Bit 5 = 256-bits
285 */
286 uint32_t csw_size_supported_mask;
287 /**
288 * Probed CSW.Size data types for the MEM-AP.
289 * Each bit corresponds to a data type.
290 * 0b1 = Data size has been probed. 0b0 = Not yet probed.
291 * Bits assigned to sizes same way as above.
292 */
293 uint32_t csw_size_probed_mask;
294
295 /**
296 * Cache for (MEM-AP) AP_REG_TAR register value This is written to
297 * configure the address being read or written
298 * "-1" indicates no cached value.
299 */
300 target_addr_t tar_value;
301
302 /**
303 * Configures how many extra tck clocks are added after starting a
304 * MEM-AP access before we try to read its status (and/or result).
305 */
306 uint32_t memaccess_tck;
307
308 /* Size of TAR autoincrement block, ARM ADI Specification requires at least 10 bits */
309 uint32_t tar_autoincr_block;
310
311 /* true if packed transfers are supported by the MEM-AP */
312 bool packed_transfers_supported;
313 bool packed_transfers_probed;
314
315 /* true if unaligned memory access is not supported by the MEM-AP */
316 bool unaligned_access_bad;
317
318 /* true if tar_value is in sync with TAR register */
319 bool tar_valid;
320
321 /* MEM AP configuration register indicating LPAE support */
322 uint32_t cfg_reg;
323
324 /* references counter */
325 unsigned int refcount;
326
327 /* AP referenced during config. Never put it, even when refcount reaches zero */
328 bool config_ap_never_release;
329 };
330
331
332 /**
333 * This represents an ARM Debug Interface (v5) Debug Access Port (DAP).
334 * A DAP has two types of component: one Debug Port (DP), which is a
335 * transport agent; and at least one Access Port (AP), controlling
336 * resource access.
337 *
338 * There are two basic DP transports: JTAG, and ARM's low pin-count SWD.
339 * Accordingly, this interface is responsible for hiding the transport
340 * differences so upper layer code can largely ignore them.
341 *
342 * When the chip is implemented with JTAG-DP or SW-DP, the transport is
343 * fixed as JTAG or SWD, respectively. Chips incorporating SWJ-DP permit
344 * a choice made at board design time (by only using the SWD pins), or
345 * as part of setting up a debug session (if all the dual-role JTAG/SWD
346 * signals are available).
347 */
348 struct adiv5_dap {
349 const struct dap_ops *ops;
350
351 /* dap transaction list for WAIT support */
352 struct list_head cmd_journal;
353
354 /* pool for dap_cmd objects */
355 struct list_head cmd_pool;
356
357 /* number of dap_cmd objects in the pool */
358 size_t cmd_pool_size;
359
360 struct jtag_tap *tap;
361 /* Control config */
362 uint32_t dp_ctrl_stat;
363
364 struct adiv5_ap ap[DP_APSEL_MAX + 1];
365
366 /* The current manually selected AP by the "dap apsel" command */
367 uint64_t apsel;
368
369 /** Cache for DP SELECT and SELECT1 (ADIv6) register. */
370 uint64_t select;
371 /** Validity of DP SELECT cache. false will force register rewrite */
372 bool select_valid;
373 bool select1_valid; /* ADIv6 only */
374 /**
375 * Partial DPBANKSEL validity for SWD only.
376 * ADIv6 line reset sets DP SELECT DPBANKSEL to zero,
377 * ADIv5 does not.
378 * We can rely on it for the banked DP register 0 also on ADIv5
379 * as ADIv5 has no mapping for DP reg 0 - it is always DPIDR.
380 * It is important to avoid setting DP SELECT in connection
381 * reset state before reading DPIDR.
382 */
383 bool select_dpbanksel_valid;
384
385 /* information about current pending SWjDP-AHBAP transaction */
386 uint8_t ack;
387
388 /**
389 * Holds the pointer to the destination word for the last queued read,
390 * for use with posted AP read sequence optimization.
391 */
392 uint32_t *last_read;
393
394 /* The TI TMS470 and TMS570 series processors use a BE-32 memory ordering
395 * despite lack of support in the ARMv7 architecture. Memory access through
396 * the AHB-AP has strange byte ordering these processors, and we need to
397 * swizzle appropriately. */
398 bool ti_be_32_quirks;
399
400 /* The Nuvoton NPCX M4 has an issue with writing to non-4-byte-aligned mmios.
401 * The work around is to repeat the data in all 4 bytes of DRW */
402 bool nu_npcx_quirks;
403
404 /**
405 * STLINK adapter need to know if last AP operation was read or write, and
406 * in case of write has to flush it with a dummy read from DP_RDBUFF
407 */
408 bool stlink_flush_ap_write;
409
410 /**
411 * Signals that an attempt to reestablish communication afresh
412 * should be performed before the next access.
413 */
414 bool do_reconnect;
415
416 /** Flag saying whether to ignore the syspwrupack flag in DAP. Some devices
417 * do not set this bit until later in the bringup sequence */
418 bool ignore_syspwrupack;
419
420 /** Value to select DP in SWD multidrop mode or DP_TARGETSEL_INVALID */
421 uint32_t multidrop_targetsel;
422 /** TPARTNO and TDESIGNER fields of multidrop_targetsel have been configured */
423 bool multidrop_dp_id_valid;
424 /** TINSTANCE field of multidrop_targetsel has been configured */
425 bool multidrop_instance_id_valid;
426
427 /**
428 * Record if enter in SWD required passing through DORMANT
429 */
430 bool switch_through_dormant;
431
432 /** Indicates ADI version (5, 6 or 0 for unknown) being used */
433 unsigned int adi_version;
434
435 /* ADIv6 only field indicating ROM Table address size */
436 unsigned int asize;
437 };
438
439 /**
440 * Transport-neutral representation of queued DAP transactions, supporting
441 * both JTAG and SWD transports. All submitted transactions are logically
442 * queued, until the queue is executed by run(). Some implementations might
443 * execute transactions as soon as they're submitted, but no status is made
444 * available until run().
445 */
446 struct dap_ops {
447 /** Optional; called once on the first enabled dap before connecting */
448 int (*pre_connect_init)(struct adiv5_dap *dap);
449
450 /** connect operation for SWD */
451 int (*connect)(struct adiv5_dap *dap);
452
453 /** send a sequence to the DAP */
454 int (*send_sequence)(struct adiv5_dap *dap, enum swd_special_seq seq);
455
456 /** DP register read. */
457 int (*queue_dp_read)(struct adiv5_dap *dap, unsigned reg,
458 uint32_t *data);
459 /** DP register write. */
460 int (*queue_dp_write)(struct adiv5_dap *dap, unsigned reg,
461 uint32_t data);
462
463 /** AP register read. */
464 int (*queue_ap_read)(struct adiv5_ap *ap, unsigned reg,
465 uint32_t *data);
466 /** AP register write. */
467 int (*queue_ap_write)(struct adiv5_ap *ap, unsigned reg,
468 uint32_t data);
469
470 /** AP operation abort. */
471 int (*queue_ap_abort)(struct adiv5_dap *dap, uint8_t *ack);
472
473 /** Executes all queued DAP operations. */
474 int (*run)(struct adiv5_dap *dap);
475
476 /** Executes all queued DAP operations but doesn't check
477 * sticky error conditions */
478 int (*sync)(struct adiv5_dap *dap);
479
480 /** Optional; called at OpenOCD exit */
481 void (*quit)(struct adiv5_dap *dap);
482 };
483
484 /*
485 * Access Port types
486 */
487 enum ap_type {
488 AP_TYPE_JTAG_AP = AP_REG_IDR_VALUE(ARM_ID, AP_REG_IDR_CLASS_NONE, 0), /* JTAG-AP */
489 AP_TYPE_COM_AP = AP_REG_IDR_VALUE(ARM_ID, AP_REG_IDR_CLASS_COM, 0), /* COM-AP */
490 AP_TYPE_AHB3_AP = AP_REG_IDR_VALUE(ARM_ID, AP_REG_IDR_CLASS_MEM_AP, 1), /* AHB3 Memory-AP */
491 AP_TYPE_APB_AP = AP_REG_IDR_VALUE(ARM_ID, AP_REG_IDR_CLASS_MEM_AP, 2), /* APB2 or APB3 Memory-AP */
492 AP_TYPE_AXI_AP = AP_REG_IDR_VALUE(ARM_ID, AP_REG_IDR_CLASS_MEM_AP, 4), /* AXI3 or AXI4 Memory-AP */
493 AP_TYPE_AHB5_AP = AP_REG_IDR_VALUE(ARM_ID, AP_REG_IDR_CLASS_MEM_AP, 5), /* AHB5 Memory-AP */
494 AP_TYPE_APB4_AP = AP_REG_IDR_VALUE(ARM_ID, AP_REG_IDR_CLASS_MEM_AP, 6), /* APB4 Memory-AP */
495 AP_TYPE_AXI5_AP = AP_REG_IDR_VALUE(ARM_ID, AP_REG_IDR_CLASS_MEM_AP, 7), /* AXI5 Memory-AP */
496 AP_TYPE_AHB5H_AP = AP_REG_IDR_VALUE(ARM_ID, AP_REG_IDR_CLASS_MEM_AP, 8), /* AHB5 with enhanced HPROT Memory-AP */
497 };
498
499 extern const struct dap_ops jtag_dp_ops;
500 extern const struct dap_ops swd_dap_ops;
501
502 /* Check the ap->cfg_reg Long Address field (bit 1)
503 *
504 * 0b0: The AP only supports physical addresses 32 bits or smaller
505 * 0b1: The AP supports physical addresses larger than 32 bits
506 *
507 * @param ap The AP used for reading.
508 *
509 * @return true for 64 bit, false for 32 bit
510 */
511 static inline bool is_64bit_ap(struct adiv5_ap *ap)
512 {
513 return (ap->cfg_reg & MEM_AP_REG_CFG_LA) != 0;
514 }
515
516 /**
517 * Check if DAP is ADIv6
518 *
519 * @param dap The DAP to test
520 *
521 * @return true for ADIv6, false for either ADIv5 or unknown version
522 */
523 static inline bool is_adiv6(const struct adiv5_dap *dap)
524 {
525 return dap->adi_version == 6;
526 }
527
528 /**
529 * Send an adi-v5 sequence to the DAP.
530 *
531 * @param dap The DAP used for reading.
532 * @param seq The sequence to send.
533 *
534 * @return ERROR_OK for success, else a fault code.
535 */
536 static inline int dap_send_sequence(struct adiv5_dap *dap,
537 enum swd_special_seq seq)
538 {
539 assert(dap->ops);
540 return dap->ops->send_sequence(dap, seq);
541 }
542
543 /**
544 * Queue a DP register read.
545 * Note that not all DP registers are readable; also, that JTAG and SWD
546 * have slight differences in DP register support.
547 *
548 * @param dap The DAP used for reading.
549 * @param reg The two-bit number of the DP register being read.
550 * @param data Pointer saying where to store the register's value
551 * (in host endianness).
552 *
553 * @return ERROR_OK for success, else a fault code.
554 */
555 static inline int dap_queue_dp_read(struct adiv5_dap *dap,
556 unsigned reg, uint32_t *data)
557 {
558 assert(dap->ops);
559 return dap->ops->queue_dp_read(dap, reg, data);
560 }
561
562 /**
563 * Queue a DP register write.
564 * Note that not all DP registers are writable; also, that JTAG and SWD
565 * have slight differences in DP register support.
566 *
567 * @param dap The DAP used for writing.
568 * @param reg The two-bit number of the DP register being written.
569 * @param data Value being written (host endianness)
570 *
571 * @return ERROR_OK for success, else a fault code.
572 */
573 static inline int dap_queue_dp_write(struct adiv5_dap *dap,
574 unsigned reg, uint32_t data)
575 {
576 assert(dap->ops);
577 return dap->ops->queue_dp_write(dap, reg, data);
578 }
579
580 /**
581 * Queue an AP register read.
582 *
583 * @param ap The AP used for reading.
584 * @param reg The number of the AP register being read.
585 * @param data Pointer saying where to store the register's value
586 * (in host endianness).
587 *
588 * @return ERROR_OK for success, else a fault code.
589 */
590 static inline int dap_queue_ap_read(struct adiv5_ap *ap,
591 unsigned reg, uint32_t *data)
592 {
593 assert(ap->dap->ops);
594 if (ap->refcount == 0) {
595 ap->refcount = 1;
596 LOG_ERROR("BUG: refcount AP#0x%" PRIx64 " used without get", ap->ap_num);
597 }
598 return ap->dap->ops->queue_ap_read(ap, reg, data);
599 }
600
601 /**
602 * Queue an AP register write.
603 *
604 * @param ap The AP used for writing.
605 * @param reg The number of the AP register being written.
606 * @param data Value being written (host endianness)
607 *
608 * @return ERROR_OK for success, else a fault code.
609 */
610 static inline int dap_queue_ap_write(struct adiv5_ap *ap,
611 unsigned reg, uint32_t data)
612 {
613 assert(ap->dap->ops);
614 if (ap->refcount == 0) {
615 ap->refcount = 1;
616 LOG_ERROR("BUG: refcount AP#0x%" PRIx64 " used without get", ap->ap_num);
617 }
618 return ap->dap->ops->queue_ap_write(ap, reg, data);
619 }
620
621 /**
622 * Queue an AP abort operation. The current AP transaction is aborted,
623 * including any update of the transaction counter. The AP is left in
624 * an unknown state (so it must be re-initialized). For use only after
625 * the AP has reported WAIT status for an extended period.
626 *
627 * @param dap The DAP used for writing.
628 * @param ack Pointer to where transaction status will be stored.
629 *
630 * @return ERROR_OK for success, else a fault code.
631 */
632 static inline int dap_queue_ap_abort(struct adiv5_dap *dap, uint8_t *ack)
633 {
634 assert(dap->ops);
635 return dap->ops->queue_ap_abort(dap, ack);
636 }
637
638 /**
639 * Perform all queued DAP operations, and clear any errors posted in the
640 * CTRL_STAT register when they are done. Note that if more than one AP
641 * operation will be queued, one of the first operations in the queue
642 * should probably enable CORUNDETECT in the CTRL/STAT register.
643 *
644 * @param dap The DAP used.
645 *
646 * @return ERROR_OK for success, else a fault code.
647 */
648 static inline int dap_run(struct adiv5_dap *dap)
649 {
650 assert(dap->ops);
651 return dap->ops->run(dap);
652 }
653
654 static inline int dap_sync(struct adiv5_dap *dap)
655 {
656 assert(dap->ops);
657 if (dap->ops->sync)
658 return dap->ops->sync(dap);
659 return ERROR_OK;
660 }
661
662 static inline int dap_dp_read_atomic(struct adiv5_dap *dap, unsigned reg,
663 uint32_t *value)
664 {
665 int retval;
666
667 retval = dap_queue_dp_read(dap, reg, value);
668 if (retval != ERROR_OK)
669 return retval;
670
671 return dap_run(dap);
672 }
673
674 static inline int dap_dp_poll_register(struct adiv5_dap *dap, unsigned reg,
675 uint32_t mask, uint32_t value, int timeout)
676 {
677 assert(timeout > 0);
678 assert((value & mask) == value);
679
680 int ret;
681 uint32_t regval;
682 LOG_DEBUG("DAP: poll %x, mask 0x%08" PRIx32 ", value 0x%08" PRIx32,
683 reg, mask, value);
684 do {
685 ret = dap_dp_read_atomic(dap, reg, &regval);
686 if (ret != ERROR_OK)
687 return ret;
688
689 if ((regval & mask) == value)
690 break;
691
692 alive_sleep(10);
693 } while (--timeout);
694
695 if (!timeout) {
696 LOG_DEBUG("DAP: poll %x timeout", reg);
697 return ERROR_WAIT;
698 } else {
699 return ERROR_OK;
700 }
701 }
702
703 /* Queued MEM-AP memory mapped single word transfers. */
704 int mem_ap_read_u32(struct adiv5_ap *ap,
705 target_addr_t address, uint32_t *value);
706 int mem_ap_write_u32(struct adiv5_ap *ap,
707 target_addr_t address, uint32_t value);
708
709 /* Synchronous MEM-AP memory mapped single word transfers. */
710 int mem_ap_read_atomic_u32(struct adiv5_ap *ap,
711 target_addr_t address, uint32_t *value);
712 int mem_ap_write_atomic_u32(struct adiv5_ap *ap,
713 target_addr_t address, uint32_t value);
714
715 /* Synchronous MEM-AP memory mapped bus block transfers. */
716 int mem_ap_read_buf(struct adiv5_ap *ap,
717 uint8_t *buffer, uint32_t size, uint32_t count, target_addr_t address);
718 int mem_ap_write_buf(struct adiv5_ap *ap,
719 const uint8_t *buffer, uint32_t size, uint32_t count, target_addr_t address);
720
721 /* Synchronous, non-incrementing buffer functions for accessing fifos. */
722 int mem_ap_read_buf_noincr(struct adiv5_ap *ap,
723 uint8_t *buffer, uint32_t size, uint32_t count, target_addr_t address);
724 int mem_ap_write_buf_noincr(struct adiv5_ap *ap,
725 const uint8_t *buffer, uint32_t size, uint32_t count, target_addr_t address);
726
727 /* Initialisation of the debug system, power domains and registers */
728 int dap_dp_init(struct adiv5_dap *dap);
729 int dap_dp_init_or_reconnect(struct adiv5_dap *dap);
730 int mem_ap_init(struct adiv5_ap *ap);
731
732 /* Invalidate cached DP select and cached TAR and CSW of all APs */
733 void dap_invalidate_cache(struct adiv5_dap *dap);
734
735 /* read ADIv6 baseptr register */
736 int adiv6_dap_read_baseptr(struct command_invocation *cmd, struct adiv5_dap *dap, target_addr_t *baseptr);
737
738 /* test if ap_num is valid, based on current knowledge of dap */
739 bool is_ap_num_valid(struct adiv5_dap *dap, uint64_t ap_num);
740
741 /* Probe Access Ports to find a particular type. Increment AP refcount */
742 int dap_find_get_ap(struct adiv5_dap *dap,
743 enum ap_type type_to_find,
744 struct adiv5_ap **ap_out);
745
746 /* Return AP with specified ap_num. Increment AP refcount */
747 struct adiv5_ap *dap_get_ap(struct adiv5_dap *dap, uint64_t ap_num);
748
749 /* Return AP with specified ap_num. Increment AP refcount and keep it non-zero */
750 struct adiv5_ap *dap_get_config_ap(struct adiv5_dap *dap, uint64_t ap_num);
751
752 /* Decrement AP refcount and release the AP when refcount reaches zero */
753 int dap_put_ap(struct adiv5_ap *ap);
754
755 /** Check if SWD multidrop configuration is valid */
756 static inline bool dap_is_multidrop(struct adiv5_dap *dap)
757 {
758 return dap->multidrop_dp_id_valid && dap->multidrop_instance_id_valid;
759 }
760
761 /* Lookup CoreSight component */
762 int dap_lookup_cs_component(struct adiv5_ap *ap,
763 uint8_t type, target_addr_t *addr, int32_t idx);
764
765 struct target;
766
767 /* Put debug link into SWD mode */
768 int dap_to_swd(struct adiv5_dap *dap);
769
770 /* Put debug link into JTAG mode */
771 int dap_to_jtag(struct adiv5_dap *dap);
772
773 extern const struct command_registration dap_instance_commands[];
774
775 struct arm_dap_object;
776 extern struct adiv5_dap *dap_instance_by_jim_obj(Jim_Interp *interp, Jim_Obj *o);
777 extern struct adiv5_dap *adiv5_get_dap(struct arm_dap_object *obj);
778 extern int dap_info_command(struct command_invocation *cmd,
779 struct adiv5_ap *ap);
780 extern int dap_register_commands(struct command_context *cmd_ctx);
781 extern const char *adiv5_dap_name(struct adiv5_dap *self);
782 extern const struct swd_driver *adiv5_dap_swd_driver(struct adiv5_dap *self);
783 extern int dap_cleanup_all(void);
784
785 struct adiv5_private_config {
786 uint64_t ap_num;
787 struct adiv5_dap *dap;
788 };
789
790 extern int adiv5_verify_config(struct adiv5_private_config *pc);
791
792 enum adiv5_configure_dap_optional {
793 ADI_CONFIGURE_DAP_COMPULSORY = false,
794 ADI_CONFIGURE_DAP_OPTIONAL = true
795 };
796
797 extern int adiv5_jim_configure_ext(struct target *target, struct jim_getopt_info *goi,
798 struct adiv5_private_config *pc,
799 enum adiv5_configure_dap_optional optional);
800 extern int adiv5_jim_configure(struct target *target, struct jim_getopt_info *goi);
801
802 struct adiv5_mem_ap_spot {
803 struct adiv5_dap *dap;
804 uint64_t ap_num;
805 uint32_t base;
806 };
807
808 extern int adiv5_mem_ap_spot_init(struct adiv5_mem_ap_spot *p);
809 extern int adiv5_jim_mem_ap_spot_configure(struct adiv5_mem_ap_spot *cfg,
810 struct jim_getopt_info *goi);
811
812 #endif /* OPENOCD_TARGET_ARM_ADI_V5_H */

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)