openocd/src/flash/nor
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
..
Makefile.am flash/nor: add support for Nuvoton NPCX series flash 2021-09-02 06:42:54 +00:00
aduc702x.c flash: rename CamelCase symbols 2021-07-02 17:09:47 +01:00
aducm360.c flash: use proper format with uint32_t 2020-09-05 17:12:32 +01:00
ambiqmicro.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
at91sam3.c openocd: remove NULL comparisons with checkpatch [1/2] 2021-07-24 10:38:00 +01:00
at91sam4.c openocd: remove NULL comparisons with checkpatch [1/2] 2021-07-24 10:38:00 +01:00
at91sam4l.c armv7m.h: relax dependency from 'arm_adi_v5.h' 2021-09-25 12:59:12 +00:00
at91sam7.c openocd: remove NULL comparisons with checkpatch [1/2] 2021-07-24 10:38:00 +01:00
at91samd.c flash/nor/at91samd: remove 'at91samd info' command 2021-12-03 21:53:36 +00:00
ath79.c flash/nor: improved API of flash_driver.info & fixed buffer overruns 2021-06-13 19:58:28 +01:00
atsame5.c flash/nor/atsame5: add LAN9255 devices 2022-01-29 18:18:53 +00:00
atsamv.c flash/nor/atsamv: fixed "maybe uninitialized" compiler warning 2021-08-14 13:28:54 +01:00
avrf.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
bluenrg-x.c bluenrg: add support for bluenrg-lps device and board 2022-05-07 11:03:25 +00:00
bluenrg-x.h bluenrg-x: simplyfied the driver 2020-03-07 15:31:09 +00:00
cc26xx.c target,flash: allow target_free_working_area on NULL area pointer 2021-12-03 21:59:20 +00:00
cc26xx.h flash/nor: Add support for TI CC26xx/CC13xx flash 2018-06-15 20:06:25 +01:00
cc3220sf.c armv7m.h: relax dependency from 'arm_adi_v5.h' 2021-09-25 12:59:12 +00:00
cc3220sf.h flash/nor: Add support for TI CC3220SF internal flash 2018-06-06 15:38:25 +01:00
cfi.c target,flash: allow target_free_working_area on NULL area pointer 2021-12-03 21:59:20 +00:00
cfi.h flash/nor/cfi: fix CamelCase symbols in cfi_spansion_pri_ext 2021-07-02 17:08:40 +01:00
core.c flash/nor/core, target: don't ask for working mem if no target algo 2022-05-29 15:47:21 +00:00
core.h openocd: fix doxygen parameters of functions 2021-01-13 11:33:53 +00:00
driver.h flash/nor: improved API of flash_driver.info & fixed buffer overruns 2021-06-13 19:58:28 +01:00
drivers.c flash/nor: add support for Nuvoton NPCX series flash 2021-09-02 06:42:54 +00:00
dsp5680xx_flash.c flash: fix clang static analyzer build errors 2022-05-21 09:00:51 +00:00
efm32.c flash/nor/efm32: Use Cortex-M 'core_info' field 2022-03-12 09:45:56 +00:00
em357.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
esirisc_flash.c flash/nor: improved API of flash_driver.info & fixed buffer overruns 2021-06-13 19:58:28 +01:00
faux.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
fespi.c target,flash: allow target_free_working_area on NULL area pointer 2021-12-03 21:59:20 +00:00
fm3.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
fm4.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
imp.h Flash, FRAM and EEPROM driver for STM32 QUAD-/OCTOSPI interface 2020-11-08 22:46:00 +00:00
jtagspi.c jtagspi: fix build on MacOS 2021-11-13 22:36:03 +00:00
kinetis.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
kinetis_ke.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
lpc288x.c flash: fix typos and duplicated words 2020-07-26 20:13:22 +01:00
lpc2000.c openocd: fix simple cases of Yoda condition 2021-07-20 14:55:24 +01:00
lpc2900.c openocd: fix simple cases of Yoda condition 2021-07-20 14:55:24 +01:00
lpcspifi.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
max32xxx.c armv7m.h: relax dependency from 'arm_adi_v5.h' 2021-09-25 12:59:12 +00:00
mdr.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
mrvlqspi.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
msp432.c target,flash: allow target_free_working_area on NULL area pointer 2021-12-03 21:59:20 +00:00
msp432.h flash: fix some minor typo 2021-05-22 10:06:32 +01:00
niietcm4.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
non_cfi.c flash/nor/cfi: fix CamelCase symbols in cfi_spansion_pri_ext 2021-07-02 17:08:40 +01:00
non_cfi.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
npcx.c target,flash: allow target_free_working_area on NULL area pointer 2021-12-03 21:59:20 +00:00
nrf5.c armv7m.h: relax dependency from 'arm_adi_v5.h' 2021-09-25 12:59:12 +00:00
numicro.c flash/nor/numicro: remove useless architecture check 2022-06-10 21:50:39 +00:00
ocl.c flash/nor: Use proper data types in driver API 2020-07-07 05:23:54 +01:00
ocl.h flash: fix typos and duplicated words 2020-07-26 20:13:22 +01:00
pic32mx.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
psoc4.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
psoc5lp.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
psoc6.c target,flash: allow target_free_working_area on NULL area pointer 2021-12-03 21:59:20 +00:00
renesas_rpchf.c flash: use proper format with uint32_t 2020-09-05 17:12:32 +01:00
rp2040.c flash/rp2040: don't initialize to NULL fields in struct 2021-11-23 11:04:42 +00:00
sfdp.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
sfdp.h Flash, FRAM and EEPROM driver for STM32 QUAD-/OCTOSPI interface 2020-11-08 22:46:00 +00:00
sh_qspi.c target,flash: allow target_free_working_area on NULL area pointer 2021-12-03 21:59:20 +00:00
sim3x.c arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
spi.c flash/nor/spi: add micron MT25QU01G 2021-12-11 17:49:46 +00:00
spi.h Flash, FRAM and EEPROM driver for STM32 QUAD-/OCTOSPI interface 2020-11-08 22:46:00 +00:00
stellaris.c armv7m.h: relax dependency from 'arm_adi_v5.h' 2021-09-25 12:59:12 +00:00
stm32f1x.c flash/nor/stm32f1x: add can_load_options flag for GD32F1x0, F3x0 and E23x 2022-04-24 08:27:28 +00:00
stm32f2x.c flash/stm32f1x,f2x: fix endianess in slow fallback flash write 2022-03-12 09:32:09 +00:00
stm32h7x.c flash/stm32h7x: fix FLASH_WPSN_PRG mask used for protection 2022-03-12 09:44:31 +00:00
stm32l4x.c flash/stm32l4x: fix scan-build warnings 2022-06-04 08:25:23 +00:00
stm32l4x.h flash/stm32l4x: fix flash programming in 64-bit hosts 2021-09-12 14:26:31 +00:00
stm32lx.c flash/nor/stm32lx: fixed writes at high adapter speeds 2021-11-03 20:32:54 +00:00
stmqspi.c armv7m.h: relax dependency from 'arm_adi_v5.h' 2021-09-25 12:59:12 +00:00
stmqspi.h flash/stmqspi: minor fixes on coding style 2020-11-15 21:04:29 +00:00
stmsmi.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
str7x.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
str9x.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
str9xpec.c openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
swm050.c openocd: fix simple cases of Yoda condition 2021-07-20 14:55:24 +01:00
tcl.c openocd: use single line for register_commands*() 2021-11-23 11:03:38 +00:00
tms470.c openocd: fix Yoda conditions with checkpatch 2021-07-24 10:38:31 +01:00
virtual.c openocd: remove NULL comparisons with checkpatch [1/2] 2021-07-24 10:38:00 +01:00
w600.c flash/nor: improved API of flash_driver.info & fixed buffer overruns 2021-06-13 19:58:28 +01:00
xcf.c openocd: remove NULL comparisons with checkpatch [1/2] 2021-07-24 10:38:00 +01:00
xmc1xxx.c flash/nor: Do not update 'is_erased' 2021-08-14 13:32:07 +01:00
xmc4xxx.c flash/xmc4xxx: use COMMAND_PARSE_NUMBER in command handlers 2021-08-22 13:18:52 +00:00