openocd/src
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
..
flash arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
helper openocd: add post-init and pre-shutdown helpers 2022-05-14 08:58:36 +00:00
jtag drivers/bitbang: silence scan-build warning 2022-06-10 21:54:40 +00:00
pld openocd: use single line for register_commands*() 2021-11-23 11:03:38 +00:00
rtos rtos: zephyr: do not use deprecated symbols name 2022-04-23 09:26:32 +00:00
rtt openocd: include config.h in every file .c 2022-03-26 13:32:57 +00:00
server telnet_server: fix scan-build warning 2022-06-10 21:55:39 +00:00
svf openocd: fix Yoda conditions with checkpatch 2021-07-24 10:38:31 +01:00
target arm_adi_v5: add ap refcount and add get/put around ap use 2022-06-24 21:33:23 +00:00
transport openocd: remove NULL comparisons with checkpatch [1/2] 2021-07-24 10:38:00 +01:00
xsvf openocd: fix simple cases of NULL comparison 2021-07-24 10:37:49 +01:00
Makefile.am build: Fix out-of-tree with --disable-dependency-tracking configure flag 2021-04-05 23:24:14 +01:00
hello.c openocd: fix simple cases of Yoda condition 2021-07-20 14:55:24 +01:00
hello.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00
main.c Cleanup of config/includes. 2021-05-01 14:35:09 +01:00
openocd.c openocd: add post-init and pre-shutdown helpers 2022-05-14 08:58:36 +00:00
openocd.h Make #include guard naming consistent 2016-05-24 22:30:55 +01:00