openocd/src/target
Antonio Borneo 35a503b08d arm_adi_v5: add ap refcount and add get/put around ap use
While an ADIv5 DAP can only have 256 AP, ADIv6 can provide till
2**40 (1,099,511,627,776) AP per DAP.
The actual trivial code implementation for ADIv5 (that uses an
array of 256 ap in the struct adiv5_dap) cannot be extended as-is
to handle ADIv6.

The simple array of 256 AP can be reused as a dynamic storage for
ADIv6 ap:
- the ADIv5 AP number is replaced by the ADIv6 base address;
- the index of the array (equal to ADIv5 AP number) has no link to
  any ADIv6 property;
- the ADIv6 base_address has to be searched in the array of AP.

The 256 elements in the AP array should be enough for any device
available today. In future it can be easily increased, if needed.

To efficiently use the 256 elements in the AP array, the code
should associate one element of the array to an ADIv6 AP (through
the AP base address), then cancel the association when the AP is
not anymore needed. This is important to avoid saturating the AP
array while exploring the device through 'dap apreg' commands.

Add a reference counter in the struct adiv5_ap to track how many
times the struct has been associated with the same base address.
Introduce the function dap_get_ap() to associate and return the
struct, and dap_put_ap() to release the struct. For the moment the
code covers ADIv5 only, so the association is through the index.
Use the two functions above and dap_find_get_ap() throughout the
code.
Check the return value of dap_get_ap(). It is always not NULL in
the current ADIv5-only implementation, but can be NULL for ADIv6
when there are no more available AP in the array.
Instrument dap_queue_ap_read() and dap_queue_ap_write() to log an
error message if the AP has reference counter zero, meaning that
the AP has not been 'get' yet. This helps identifying AP used
without get/put, e.g. code missed by this patch, or merged later.
Instrument dap_cleanup_all() to log an error message if an AP has
reference counter not zero at openocd exit, meaning that the AP
has not been 'put' yet.

Change-Id: I98316eb42b9f3d9c9bbbb6c73b1091b53f629092
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/6455
Reviewed-by: Daniel Goehring <dgoehrin@os.amperecomputing.com>
Tested-by: jenkins
2022-06-24 21:33:23 +00:00
..
espressif target: add Espressif ESP32-S2 basic support 2022-06-04 08:18:44 +00:00
openrisc target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
riscv target/riscv: drop unused variable registers_initialized 2022-06-04 08:20:09 +00:00
xtensa target: add Espressif ESP32-S2 basic support 2022-06-04 08:18:44 +00:00
Makefile.am target: add Espressif ESP32-S2 basic support 2022-06-04 08:18:44 +00:00
a64_disassembler.c target/disassembler: update capstone include path to <capstone.h> 2022-04-30 17:53:30 +00:00
a64_disassembler.h target/aarch64: a64 disassembler 2020-10-03 11:21:15 +01:00
aarch64.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
aarch64.h target/arm: rename CamelCase symbols 2021-07-20 14:52:25 +01:00
adi_v5_dapdirect.c adi_v5_dapdirect: fix connect under reset 2020-02-24 10:28:46 +00:00
adi_v5_jtag.c adi_v5_jtag: reduce verbosity on persistent WAIT 2022-05-14 08:43:30 +00:00
adi_v5_swd.c adi_v5_swd: add jtag-to-swd through dormant 2021-12-11 17:39:58 +00:00
algorithm.c Remove FSF address from GPL notices 2016-05-24 22:30:01 +01:00
algorithm.h Cleanup of config/includes. 2021-05-01 14:35:09 +01:00
arc.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
arc.h target: fix some minor typo 2021-05-22 10:06:45 +01:00
arc_cmd.c helper/jim-nvp: comply with coding style [2/2] 2021-06-04 17:40:48 +01:00
arc_cmd.h Introduce ARCv2 architecture related code 2020-02-27 06:46:51 +00:00
arc_jtag.c openocd: fix doxygen parameters of functions 2021-01-13 11:33:53 +00:00
arc_jtag.h Introduce ARCv2 architecture related code 2020-02-27 06:46:51 +00:00
arc_mem.c openocd: fix simple cases of Yoda condition 2021-07-20 14:55:24 +01:00
arc_mem.h Introduce ARCv2 architecture related code 2020-02-27 06:46:51 +00:00
arm.h openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
arm7_9_common.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
arm7_9_common.h target/arm926ejs: fix memory leaks 2020-07-08 22:07:38 +01:00
arm7tdmi.c target/arm: optimize architecture flags 2021-06-18 23:12:54 +01:00
arm7tdmi.h target/arm7tdmi: fix memory leak of register cache 2020-07-26 20:12:48 +01:00
arm9tdmi.c target/arm: optimize architecture flags 2021-06-18 23:12:54 +01:00
arm9tdmi.h target: fix memory leaks on targets based on arm9tdmi 2020-07-26 20:12:21 +01:00
arm11.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
arm11.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
arm11_dbgtap.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
arm11_dbgtap.h target/arm: rename CamelCase symbols 2021-07-20 14:52:25 +01:00
arm720t.c target/arm: rename CamelCase symbols 2021-07-20 14:52:25 +01:00
arm720t.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
arm920t.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
arm920t.h target: Add 64-bit target address support 2017-02-10 13:50:17 +01:00
arm926ejs.c target/arm: rename CamelCase symbols 2021-07-20 14:52:25 +01:00
arm926ejs.h target/arm: rename CamelCase symbols 2021-07-20 14:52:25 +01:00
arm946e.c target: declare local symbols as static 2020-11-04 17:39:17 +00:00
arm946e.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
arm966e.c target: use proper format with uint32_t 2020-09-05 17:12:39 +01:00
arm966e.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
arm_adi_v5.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
arm_adi_v5.h arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
arm_coresight.h arm_adi_v5: replace dap_lookup_cs_component() 2022-05-14 08:55:52 +00:00
arm_cti.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
arm_cti.h armv8: valgrind memleak fixes 2018-04-10 09:13:02 +01:00
arm_dap.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
arm_disassembler.c target/disassembler: update capstone include path to <capstone.h> 2022-04-30 17:53:30 +00:00
arm_disassembler.h target/arm: opcodes: rename CamelCase symbols and uppercase variables 2021-07-20 14:52:49 +01:00
arm_dpm.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
arm_dpm.h target/arm: rename CamelCase symbols 2021-07-20 14:52:25 +01:00
arm_jtag.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
arm_jtag.h target/arm_jtag.h: fix wrong comparison in arm_jtag_set_instr 2021-12-11 17:49:30 +00:00
arm_opcodes.h target/arm: opcodes: rename CamelCase symbols and uppercase variables 2021-07-20 14:52:49 +01:00
arm_semihosting.c semihosting: User defined operation, Tcl command exec on host 2022-02-05 21:40:17 +00:00
arm_semihosting.h Rework/update ARM semihosting 2018-06-04 09:16:08 +01:00
arm_simulator.c target/arm: opcodes: rename CamelCase symbols and uppercase variables 2021-07-20 14:52:49 +01:00
arm_simulator.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
arm_tpiu_swo.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
arm_tpiu_swo.h armv7m_trace: get rid of the old tpiu code 2021-03-10 21:34:04 +00:00
armv4_5.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
armv4_5.h target/cortex_a: add hypervisor mode 2020-03-12 10:11:19 +00:00
armv4_5_cache.c helper/command: change prototype of command_print/command_print_sameline 2019-05-14 19:37:11 +01:00
armv4_5_cache.h Cleanup of config/includes. 2021-05-01 14:35:09 +01:00
armv4_5_mmu.c Remove FSF address from GPL notices 2016-05-24 22:30:01 +01:00
armv4_5_mmu.h target: Add 64-bit target address support 2017-02-10 13:50:17 +01:00
armv7a.c cortex_a: get rid of not needed log messages 2022-06-03 23:46:21 +00:00
armv7a.h target/adiv5: Large Physical Address Extension 2021-07-02 17:12:11 +01:00
armv7a_cache.c target/smp: use a struct list_head to hold the smp targets 2022-02-14 15:10:10 +00:00
armv7a_cache.h target: use proper format with uint32_t 2020-09-05 17:12:39 +01:00
armv7a_cache_l2x.c target/smp: use a struct list_head to hold the smp targets 2022-02-14 15:10:10 +00:00
armv7a_cache_l2x.h target: Add 64-bit target address support 2017-02-10 13:50:17 +01:00
armv7a_mmu.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
armv7a_mmu.h armv7a_mmu: Do not restrict virtual addresses to uint32_t 2019-06-12 15:14:44 +01:00
armv7m.c target/cortex_m: faster reading of all CPU registers 2021-11-18 21:09:34 +00:00
armv7m.h target/armv7m,cortex_m: introduce checked arch_info cast routines 2022-02-25 19:56:41 +00:00
armv7m_trace.c armv7m_trace: get rid of the old tpiu code 2021-03-10 21:34:04 +00:00
armv7m_trace.h helper: Remove src/helper from include dirs 2021-10-02 13:18:15 +00:00
armv8.c aarch64: support for aarch32 ARM_MODE_UND 2022-01-29 18:20:48 +00:00
armv8.h target/adiv5: Large Physical Address Extension 2021-07-02 17:12:11 +01:00
armv8_cache.c target/smp: use a struct list_head to hold the smp targets 2022-02-14 15:10:10 +00:00
armv8_cache.h aarch64: add cache handling functions 2017-02-10 14:01:39 +01:00
armv8_dpm.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
armv8_dpm.h target/aarch64: fix watchpoint management 2021-05-22 10:04:20 +01:00
armv8_opcodes.c target/armv8_opcodes: use T32 instructions when the PE is in AArch32 state 2020-03-12 09:47:08 +00:00
armv8_opcodes.h target/arm: opcodes: rename CamelCase symbols and uppercase variables 2021-07-20 14:52:49 +01:00
avr32_ap7k.c target: rename CamelCase symbols 2021-07-24 10:37:25 +01:00
avr32_ap7k.h target: rename CamelCase symbols 2021-07-24 10:37:25 +01:00
avr32_jtag.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
avr32_jtag.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
avr32_mem.c target: fix some minor typo 2021-05-22 10:06:45 +01:00
avr32_mem.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
avr32_regs.c Remove FSF address from GPL notices 2016-05-24 22:30:01 +01:00
avr32_regs.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
avrt.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
avrt.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
breakpoints.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
breakpoints.h breakpoints: fix build on -fno-inline 2022-03-19 11:35:32 +00:00
cortex_a.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
cortex_a.h target/arm: rename CamelCase symbols 2021-07-20 14:52:25 +01:00
cortex_m.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
cortex_m.h target/cortex_m: add Cortex-M part number getter 2022-02-25 20:26:56 +00:00
dsp563xx.c target: rename CamelCase symbols 2021-07-24 10:37:25 +01:00
dsp563xx.h target/dsp563xx: Use bool data type for 'hardware_breakpoints_cleared' 2021-06-26 14:40:34 +01:00
dsp563xx_once.c coding style: wrap lines longer than 120 chars 2020-05-09 14:40:52 +01:00
dsp563xx_once.h coding style: fix space around pointer's asterisk 2020-02-24 10:30:36 +00:00
dsp5680xx.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
dsp5680xx.h target: rename CamelCase symbols 2021-07-24 10:37:25 +01:00
embeddedice.c jtag: remove minidriver code and minidriver-dummy 2021-03-19 21:56:06 +00:00
embeddedice.h target/arm: rename CamelCase symbols 2021-07-20 14:52:25 +01:00
esirisc.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
esirisc.h target: rename CamelCase symbols 2021-07-24 10:37:25 +01:00
esirisc_jtag.c openocd: remove NULL comparisons with checkpatch [1/2] 2021-07-24 10:38:00 +01:00
esirisc_jtag.h esirisc: support eSi-Trace 2018-12-12 08:47:44 +00:00
esirisc_regs.h target: rename CamelCase symbols 2021-07-24 10:37:25 +01:00
esirisc_trace.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
esirisc_trace.h esirisc: support eSi-Trace 2018-12-12 08:47:44 +00:00
etb.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
etb.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
etm.c openocd: use single line for register_commands*() 2021-11-23 11:03:38 +00:00
etm.h target: fix minor typos and duplicated words 2020-07-26 23:09:45 +01:00
etm_dummy.c helper/command: change prototype of command_print/command_print_sameline 2019-05-14 19:37:11 +01:00
etm_dummy.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
fa526.c target: fix memory leaks on targets based on arm9tdmi 2020-07-26 20:12:21 +01:00
feroceon.c target/arm: rename CamelCase symbols 2021-07-20 14:52:25 +01:00
hla_target.c target/hla_target: set cortex_m->common_magic 2021-11-25 09:47:28 +00:00
image.c target/image: fix - p_flags field in ELF64 segment headers is 64 bits wide 2022-04-23 09:26:15 +00:00
image.h target/image: fix - p_flags field in ELF64 segment headers is 64 bits wide 2022-04-23 09:26:15 +00:00
lakemont.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
lakemont.h target: Add 64-bit target address support 2017-02-10 13:50:17 +01:00
ls1_sap.c openocd: remove NULL comparisons with checkpatch [1/2] 2021-07-24 10:38:00 +01:00
mem_ap.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
mips32.c Use boolean argument for register_get_by_name() 2021-06-18 23:14:27 +01:00
mips32.h target/mips: rename CamelCase symbols 2021-07-20 14:53:03 +01:00
mips32_dmaacc.c Remove FSF address from GPL notices 2016-05-24 22:30:01 +01:00
mips32_dmaacc.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
mips32_pracc.c jtag: align adapter speed code to new structure 2021-11-13 10:50:34 +00:00
mips32_pracc.h target/mips: Remove typedef'd struct 2021-03-10 21:30:04 +00:00
mips64.c coding style: fix space separation 2020-07-08 22:08:08 +01:00
mips64.h mips: Add MIPS64 support 2019-11-28 16:59:15 +00:00
mips64_pracc.c jtag: align adapter speed code to new structure 2021-11-13 10:50:34 +00:00
mips64_pracc.h mips: Add MIPS64 support 2019-11-28 16:59:15 +00:00
mips_ejtag.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
mips_ejtag.h target/mips: rename CamelCase symbols 2021-07-20 14:53:03 +01:00
mips_m4k.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
mips_m4k.h mips32: add micromips isa handling 2017-05-08 18:04:56 +01:00
mips_mips64.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
mips_mips64.h mips64: Add generic mips64 target support 2019-11-28 19:49:10 +00:00
nds32.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
nds32.h openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
nds32_aice.c openocd: remove NULL comparisons with checkpatch [1/2] 2021-07-24 10:38:00 +01:00
nds32_aice.h target: Add 64-bit target address support 2017-02-10 13:50:17 +01:00
nds32_cmd.c openocd: fix Yoda conditions with checkpatch 2021-07-24 10:38:31 +01:00
nds32_cmd.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
nds32_disassembler.c openocd: manually fix Yoda conditions 2021-07-20 14:55:43 +01:00
nds32_disassembler.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
nds32_edm.h Cleanup of config/includes. 2021-05-01 14:35:09 +01:00
nds32_insn.h target/nds32: use lowercase for C variables 2021-07-20 14:54:27 +01:00
nds32_reg.c target: use proper format with uint32_t 2020-09-05 17:12:39 +01:00
nds32_reg.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
nds32_tlb.c target/nds32: rename CamelCase symbols 2021-07-20 14:53:12 +01:00
nds32_tlb.h target/nds32: rename CamelCase symbols 2021-07-20 14:53:12 +01:00
nds32_v2.c openocd: fix Yoda conditions with checkpatch 2021-07-24 10:38:31 +01:00
nds32_v2.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
nds32_v3.c openocd: fix simple cases of Yoda condition 2021-07-20 14:55:24 +01:00
nds32_v3.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
nds32_v3_common.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
nds32_v3_common.h target: Add 64-bit target address support 2017-02-10 13:50:17 +01:00
nds32_v3m.c openocd: fix simple cases of Yoda condition 2021-07-20 14:55:24 +01:00
nds32_v3m.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
quark_d20xx.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
quark_x10xx.c target: quark_x10xx: miscellaneous cleanups 2018-01-13 09:25:12 +00:00
register.c target/register: Minor code cleanup 2021-06-18 23:14:09 +01:00
register.h Cleanup of config/includes. 2021-05-01 14:35:09 +01:00
rtt.c openocd: include config.h in every file .c 2022-03-26 13:32:57 +00:00
rtt.h Add initial RTT support 2020-12-02 23:15:52 +00:00
semihosting_common.c semihosting: fix accessing memory outside the bounds of the fn array 2022-06-10 21:56:47 +00:00
semihosting_common.h semihosting: add semihosting_basedir command 2022-05-21 09:01:56 +00:00
smp.c smp: deprecate legacy SMP core switching support 2022-05-07 11:00:00 +00:00
smp.h smp: deprecate legacy SMP core switching support 2022-05-07 11:00:00 +00:00
startup.tcl target: Deprecate 'array2mem' and 'mem2array'' 2022-03-12 09:48:00 +00:00
stm8.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
stm8.h target/stm8: Make 'stm8_command_handlers' static 2021-05-08 09:49:32 +01:00
target.c target: add Espressif ESP32-S2 basic support 2022-06-04 08:18:44 +00:00
target.h Give each SMP group a unique number. 2022-05-27 22:52:35 +00:00
target_request.c openocd: manually remove NULL comparisons 2021-07-24 10:38:19 +01:00
target_request.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
target_type.h target: document possibly unreachable target in deinit_target() 2022-05-07 11:04:45 +00:00
testee.c command_registration: add empty usage field to chained commands 2019-04-07 08:17:36 +01:00
trace.c target: avoid checking for non NULL pointer to free it 2020-09-05 20:47:11 +01:00
trace.h Cleanup of config/includes. 2021-05-01 14:35:09 +01:00
x86_32_common.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
x86_32_common.h target: lakemon: implement assert_reset and deassert_reset 2018-01-13 09:25:34 +00:00
xscale.c target: Rework 'set' variable of break-/watchpoints 2022-03-19 09:14:39 +00:00
xscale.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00