2022-06-26 23:24:07 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
|
2018-03-23 20:17:29 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2016 by Matthias Welwarsky *
|
|
|
|
* *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "target/arm_adi_v5.h"
|
|
|
|
#include "target/arm.h"
|
|
|
|
#include "helper/list.h"
|
|
|
|
#include "helper/command.h"
|
|
|
|
#include "transport/transport.h"
|
|
|
|
#include "jtag/interface.h"
|
|
|
|
|
|
|
|
static LIST_HEAD(all_dap);
|
|
|
|
|
|
|
|
extern const struct dap_ops swd_dap_ops;
|
|
|
|
extern const struct dap_ops jtag_dp_ops;
|
2019-01-22 15:31:18 +00:00
|
|
|
extern struct adapter_driver *adapter_driver;
|
2018-03-23 20:17:29 +00:00
|
|
|
|
|
|
|
/* DAP command support */
|
|
|
|
struct arm_dap_object {
|
|
|
|
struct list_head lh;
|
|
|
|
struct adiv5_dap dap;
|
|
|
|
char *name;
|
|
|
|
const struct swd_driver *swd;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void dap_instance_init(struct adiv5_dap *dap)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
/* Set up with safe defaults */
|
2018-09-05 13:37:15 +00:00
|
|
|
for (i = 0; i <= DP_APSEL_MAX; i++) {
|
2018-03-23 20:17:29 +00:00
|
|
|
dap->ap[i].dap = dap;
|
2021-08-14 21:56:12 +00:00
|
|
|
dap->ap[i].ap_num = DP_APSEL_INVALID;
|
2018-03-23 20:17:29 +00:00
|
|
|
/* memaccess_tck max is 255 */
|
|
|
|
dap->ap[i].memaccess_tck = 255;
|
|
|
|
/* Number of bits for tar autoincrement, impl. dep. at least 10 */
|
|
|
|
dap->ap[i].tar_autoincr_block = (1<<10);
|
2018-02-22 23:03:20 +00:00
|
|
|
/* default CSW value */
|
2019-04-16 19:12:18 +00:00
|
|
|
dap->ap[i].csw_default = CSW_AHB_DEFAULT;
|
2021-08-05 15:08:11 +00:00
|
|
|
dap->ap[i].cfg_reg = MEM_AP_REG_CFG_INVALID; /* mem_ap configuration reg (large physical addr, etc.) */
|
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
2021-08-04 21:07:57 +00:00
|
|
|
dap->ap[i].refcount = 0;
|
|
|
|
dap->ap[i].config_ap_never_release = false;
|
2018-03-23 20:17:29 +00:00
|
|
|
}
|
|
|
|
INIT_LIST_HEAD(&dap->cmd_journal);
|
2019-02-26 09:45:40 +00:00
|
|
|
INIT_LIST_HEAD(&dap->cmd_pool);
|
2018-03-23 20:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *adiv5_dap_name(struct adiv5_dap *self)
|
|
|
|
{
|
|
|
|
struct arm_dap_object *obj = container_of(self, struct arm_dap_object, dap);
|
|
|
|
return obj->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct swd_driver *adiv5_dap_swd_driver(struct adiv5_dap *self)
|
|
|
|
{
|
|
|
|
struct arm_dap_object *obj = container_of(self, struct arm_dap_object, dap);
|
|
|
|
return obj->swd;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct adiv5_dap *adiv5_get_dap(struct arm_dap_object *obj)
|
|
|
|
{
|
|
|
|
return &obj->dap;
|
|
|
|
}
|
|
|
|
struct adiv5_dap *dap_instance_by_jim_obj(Jim_Interp *interp, Jim_Obj *o)
|
|
|
|
{
|
|
|
|
struct arm_dap_object *obj = NULL;
|
|
|
|
const char *name;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
name = Jim_GetString(o, NULL);
|
|
|
|
|
|
|
|
list_for_each_entry(obj, &all_dap, lh) {
|
|
|
|
if (!strcmp(name, obj->name)) {
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (found)
|
|
|
|
return &obj->dap;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dap_init_all(void)
|
|
|
|
{
|
|
|
|
struct arm_dap_object *obj;
|
|
|
|
int retval;
|
|
|
|
|
|
|
|
LOG_DEBUG("Initializing all DAPs ...");
|
|
|
|
|
|
|
|
list_for_each_entry(obj, &all_dap, lh) {
|
|
|
|
struct adiv5_dap *dap = &obj->dap;
|
|
|
|
|
|
|
|
/* with hla, dap is just a dummy */
|
|
|
|
if (transport_is_hla())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* skip taps that are disabled */
|
|
|
|
if (!dap->tap->enabled)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (transport_is_swd()) {
|
|
|
|
dap->ops = &swd_dap_ops;
|
2019-01-22 15:31:18 +00:00
|
|
|
obj->swd = adapter_driver->swd_ops;
|
2019-01-23 09:52:28 +00:00
|
|
|
} else if (transport_is_dapdirect_swd()) {
|
|
|
|
dap->ops = adapter_driver->dap_swd_ops;
|
|
|
|
} else if (transport_is_dapdirect_jtag()) {
|
|
|
|
dap->ops = adapter_driver->dap_jtag_ops;
|
2018-03-23 20:17:29 +00:00
|
|
|
} else
|
|
|
|
dap->ops = &jtag_dp_ops;
|
|
|
|
|
2021-08-06 13:01:34 +00:00
|
|
|
if (dap->adi_version == 0) {
|
|
|
|
LOG_DEBUG("DAP %s configured by default to use ADIv5 protocol", jtag_tap_name(dap->tap));
|
|
|
|
dap->adi_version = 5;
|
|
|
|
} else {
|
|
|
|
LOG_DEBUG("DAP %s configured to use %s protocol by user cfg file", jtag_tap_name(dap->tap),
|
|
|
|
is_adiv6(dap) ? "ADIv6" : "ADIv5");
|
|
|
|
}
|
|
|
|
|
2018-03-23 20:17:29 +00:00
|
|
|
retval = dap->ops->connect(dap);
|
|
|
|
if (retval != ERROR_OK)
|
|
|
|
return retval;
|
2021-08-21 21:59:38 +00:00
|
|
|
|
|
|
|
/* see if address size of ROM Table is greater than 32-bits */
|
|
|
|
if (is_adiv6(dap)) {
|
|
|
|
uint32_t dpidr1;
|
|
|
|
|
|
|
|
retval = dap->ops->queue_dp_read(dap, DP_DPIDR1, &dpidr1);
|
|
|
|
if (retval != ERROR_OK) {
|
|
|
|
LOG_ERROR("DAP read of DPIDR1 failed...");
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
retval = dap_run(dap);
|
|
|
|
if (retval != ERROR_OK) {
|
|
|
|
LOG_ERROR("DAP read of DPIDR1 failed...");
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
dap->asize = dpidr1 & DP_DPIDR1_ASIZE_MASK;
|
|
|
|
}
|
2018-03-23 20:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dap_cleanup_all(void)
|
|
|
|
{
|
|
|
|
struct arm_dap_object *obj, *tmp;
|
2018-06-10 12:39:26 +00:00
|
|
|
struct adiv5_dap *dap;
|
2018-03-23 20:17:29 +00:00
|
|
|
|
|
|
|
list_for_each_entry_safe(obj, tmp, &all_dap, lh) {
|
2018-06-10 12:39:26 +00:00
|
|
|
dap = &obj->dap;
|
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
2021-08-04 21:07:57 +00:00
|
|
|
for (unsigned int i = 0; i <= DP_APSEL_MAX; i++) {
|
|
|
|
if (dap->ap[i].refcount != 0)
|
|
|
|
LOG_ERROR("BUG: refcount AP#%u still %u at exit", i, dap->ap[i].refcount);
|
|
|
|
}
|
2018-06-10 12:39:26 +00:00
|
|
|
if (dap->ops && dap->ops->quit)
|
|
|
|
dap->ops->quit(dap);
|
|
|
|
|
2018-03-23 20:17:29 +00:00
|
|
|
free(obj->name);
|
|
|
|
free(obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum dap_cfg_param {
|
|
|
|
CFG_CHAIN_POSITION,
|
2018-04-03 17:13:40 +00:00
|
|
|
CFG_IGNORE_SYSPWRUPACK,
|
2021-04-06 11:59:14 +00:00
|
|
|
CFG_DP_ID,
|
|
|
|
CFG_INSTANCE_ID,
|
2021-08-06 13:01:34 +00:00
|
|
|
CFG_ADIV6,
|
|
|
|
CFG_ADIV5,
|
2018-03-23 20:17:29 +00:00
|
|
|
};
|
|
|
|
|
2021-04-24 22:48:14 +00:00
|
|
|
static const struct jim_nvp nvp_config_opts[] = {
|
2021-04-06 11:59:14 +00:00
|
|
|
{ .name = "-chain-position", .value = CFG_CHAIN_POSITION },
|
2018-04-03 17:13:40 +00:00
|
|
|
{ .name = "-ignore-syspwrupack", .value = CFG_IGNORE_SYSPWRUPACK },
|
2021-04-06 11:59:14 +00:00
|
|
|
{ .name = "-dp-id", .value = CFG_DP_ID },
|
|
|
|
{ .name = "-instance-id", .value = CFG_INSTANCE_ID },
|
2021-08-06 13:01:34 +00:00
|
|
|
{ .name = "-adiv6", .value = CFG_ADIV6 },
|
|
|
|
{ .name = "-adiv5", .value = CFG_ADIV5 },
|
2018-03-23 20:17:29 +00:00
|
|
|
{ .name = NULL, .value = -1 }
|
|
|
|
};
|
|
|
|
|
2021-04-24 22:48:14 +00:00
|
|
|
static int dap_configure(struct jim_getopt_info *goi, struct arm_dap_object *dap)
|
2018-03-23 20:17:29 +00:00
|
|
|
{
|
2021-04-24 22:48:14 +00:00
|
|
|
struct jim_nvp *n;
|
2018-03-23 20:17:29 +00:00
|
|
|
int e;
|
|
|
|
|
2021-11-15 14:32:39 +00:00
|
|
|
/* parse config ... */
|
2018-03-23 20:17:29 +00:00
|
|
|
while (goi->argc > 0) {
|
|
|
|
Jim_SetEmptyResult(goi->interp);
|
|
|
|
|
2021-04-24 22:48:14 +00:00
|
|
|
e = jim_getopt_nvp(goi, nvp_config_opts, &n);
|
2018-03-23 20:17:29 +00:00
|
|
|
if (e != JIM_OK) {
|
2021-04-24 22:48:14 +00:00
|
|
|
jim_getopt_nvp_unknown(goi, nvp_config_opts, 0);
|
2018-03-23 20:17:29 +00:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
switch (n->value) {
|
|
|
|
case CFG_CHAIN_POSITION: {
|
|
|
|
Jim_Obj *o_t;
|
2021-04-24 22:48:14 +00:00
|
|
|
e = jim_getopt_obj(goi, &o_t);
|
2018-03-23 20:17:29 +00:00
|
|
|
if (e != JIM_OK)
|
|
|
|
return e;
|
2021-11-15 14:32:39 +00:00
|
|
|
|
|
|
|
struct jtag_tap *tap;
|
2018-03-23 20:17:29 +00:00
|
|
|
tap = jtag_tap_by_jim_obj(goi->interp, o_t);
|
2021-07-03 16:51:20 +00:00
|
|
|
if (!tap) {
|
2018-03-23 20:17:29 +00:00
|
|
|
Jim_SetResultString(goi->interp, "-chain-position is invalid", -1);
|
|
|
|
return JIM_ERR;
|
|
|
|
}
|
2021-11-15 14:32:39 +00:00
|
|
|
dap->dap.tap = tap;
|
2018-03-23 20:17:29 +00:00
|
|
|
/* loop for more */
|
|
|
|
break;
|
|
|
|
}
|
2018-04-03 17:13:40 +00:00
|
|
|
case CFG_IGNORE_SYSPWRUPACK:
|
|
|
|
dap->dap.ignore_syspwrupack = true;
|
|
|
|
break;
|
2021-04-06 11:59:14 +00:00
|
|
|
case CFG_DP_ID: {
|
|
|
|
jim_wide w;
|
|
|
|
e = jim_getopt_wide(goi, &w);
|
|
|
|
if (e != JIM_OK) {
|
|
|
|
Jim_SetResultFormatted(goi->interp,
|
|
|
|
"create %s: bad parameter %s",
|
|
|
|
dap->name, n->name);
|
|
|
|
return JIM_ERR;
|
|
|
|
}
|
|
|
|
if (w < 0 || w > DP_TARGETSEL_DPID_MASK) {
|
|
|
|
Jim_SetResultFormatted(goi->interp,
|
|
|
|
"create %s: %s out of range",
|
|
|
|
dap->name, n->name);
|
|
|
|
return JIM_ERR;
|
|
|
|
}
|
|
|
|
dap->dap.multidrop_targetsel =
|
|
|
|
(dap->dap.multidrop_targetsel & DP_TARGETSEL_INSTANCEID_MASK)
|
|
|
|
| (w & DP_TARGETSEL_DPID_MASK);
|
|
|
|
dap->dap.multidrop_dp_id_valid = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case CFG_INSTANCE_ID: {
|
|
|
|
jim_wide w;
|
|
|
|
e = jim_getopt_wide(goi, &w);
|
|
|
|
if (e != JIM_OK) {
|
|
|
|
Jim_SetResultFormatted(goi->interp,
|
|
|
|
"create %s: bad parameter %s",
|
|
|
|
dap->name, n->name);
|
|
|
|
return JIM_ERR;
|
|
|
|
}
|
|
|
|
if (w < 0 || w > 15) {
|
|
|
|
Jim_SetResultFormatted(goi->interp,
|
|
|
|
"create %s: %s out of range",
|
|
|
|
dap->name, n->name);
|
|
|
|
return JIM_ERR;
|
|
|
|
}
|
|
|
|
dap->dap.multidrop_targetsel =
|
|
|
|
(dap->dap.multidrop_targetsel & DP_TARGETSEL_DPID_MASK)
|
|
|
|
| ((w << DP_TARGETSEL_INSTANCEID_SHIFT) & DP_TARGETSEL_INSTANCEID_MASK);
|
|
|
|
dap->dap.multidrop_instance_id_valid = true;
|
|
|
|
break;
|
|
|
|
}
|
2021-08-06 13:01:34 +00:00
|
|
|
case CFG_ADIV6:
|
|
|
|
dap->dap.adi_version = 6;
|
|
|
|
break;
|
|
|
|
case CFG_ADIV5:
|
|
|
|
dap->dap.adi_version = 5;
|
|
|
|
break;
|
2018-03-23 20:17:29 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return JIM_OK;
|
|
|
|
}
|
|
|
|
|
2021-04-06 20:30:52 +00:00
|
|
|
static int dap_check_config(struct adiv5_dap *dap)
|
|
|
|
{
|
|
|
|
if (transport_is_jtag() || transport_is_dapdirect_jtag() || transport_is_hla())
|
|
|
|
return ERROR_OK;
|
|
|
|
|
|
|
|
struct arm_dap_object *obj;
|
|
|
|
bool new_multidrop = dap_is_multidrop(dap);
|
|
|
|
bool had_multidrop = new_multidrop;
|
|
|
|
uint32_t targetsel = dap->multidrop_targetsel;
|
|
|
|
unsigned int non_multidrop_count = had_multidrop ? 0 : 1;
|
|
|
|
|
|
|
|
list_for_each_entry(obj, &all_dap, lh) {
|
|
|
|
struct adiv5_dap *dap_it = &obj->dap;
|
|
|
|
|
|
|
|
if (transport_is_swd()) {
|
|
|
|
if (dap_is_multidrop(dap_it)) {
|
|
|
|
had_multidrop = true;
|
|
|
|
if (new_multidrop && dap_it->multidrop_targetsel == targetsel) {
|
|
|
|
uint32_t dp_id = targetsel & DP_TARGETSEL_DPID_MASK;
|
|
|
|
uint32_t instance_id = targetsel >> DP_TARGETSEL_INSTANCEID_SHIFT;
|
|
|
|
LOG_ERROR("%s and %s have the same multidrop selectors -dp-id 0x%08"
|
|
|
|
PRIx32 " and -instance-id 0x%" PRIx32,
|
|
|
|
obj->name, adiv5_dap_name(dap),
|
|
|
|
dp_id, instance_id);
|
|
|
|
return ERROR_FAIL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
non_multidrop_count++;
|
|
|
|
}
|
|
|
|
} else if (transport_is_dapdirect_swd()) {
|
|
|
|
non_multidrop_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (non_multidrop_count > 1) {
|
|
|
|
LOG_ERROR("Two or more SWD non multidrop DAPs are not supported");
|
|
|
|
return ERROR_FAIL;
|
|
|
|
}
|
|
|
|
if (had_multidrop && non_multidrop_count) {
|
|
|
|
LOG_ERROR("Mixing of SWD multidrop DAPs and non multidrop DAPs is not supported");
|
|
|
|
return ERROR_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2021-04-24 22:48:14 +00:00
|
|
|
static int dap_create(struct jim_getopt_info *goi)
|
2018-03-23 20:17:29 +00:00
|
|
|
{
|
|
|
|
struct command_context *cmd_ctx;
|
|
|
|
static struct arm_dap_object *dap;
|
|
|
|
Jim_Obj *new_cmd;
|
|
|
|
Jim_Cmd *cmd;
|
|
|
|
const char *cp;
|
|
|
|
int e;
|
|
|
|
|
|
|
|
cmd_ctx = current_command_context(goi->interp);
|
2021-07-03 16:51:20 +00:00
|
|
|
assert(cmd_ctx);
|
2018-03-23 20:17:29 +00:00
|
|
|
|
|
|
|
if (goi->argc < 3) {
|
|
|
|
Jim_WrongNumArgs(goi->interp, 1, goi->argv, "?name? ..options...");
|
|
|
|
return JIM_ERR;
|
|
|
|
}
|
|
|
|
/* COMMAND */
|
2021-04-24 22:48:14 +00:00
|
|
|
jim_getopt_obj(goi, &new_cmd);
|
2018-03-23 20:17:29 +00:00
|
|
|
/* does this command exist? */
|
2021-09-17 16:37:41 +00:00
|
|
|
cmd = Jim_GetCommand(goi->interp, new_cmd, JIM_NONE);
|
2018-03-23 20:17:29 +00:00
|
|
|
if (cmd) {
|
|
|
|
cp = Jim_GetString(new_cmd, NULL);
|
|
|
|
Jim_SetResultFormatted(goi->interp, "Command: %s Exists", cp);
|
|
|
|
return JIM_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create it */
|
|
|
|
dap = calloc(1, sizeof(struct arm_dap_object));
|
2021-07-03 16:51:20 +00:00
|
|
|
if (!dap)
|
2018-03-23 20:17:29 +00:00
|
|
|
return JIM_ERR;
|
|
|
|
|
2021-11-15 14:32:39 +00:00
|
|
|
dap_instance_init(&dap->dap);
|
2018-03-23 20:17:29 +00:00
|
|
|
|
|
|
|
cp = Jim_GetString(new_cmd, NULL);
|
|
|
|
dap->name = strdup(cp);
|
|
|
|
|
2021-11-15 14:32:39 +00:00
|
|
|
e = dap_configure(goi, dap);
|
|
|
|
if (e != JIM_OK)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
if (!dap->dap.tap) {
|
|
|
|
Jim_SetResultString(goi->interp, "-chain-position required when creating DAP", -1);
|
|
|
|
e = JIM_ERR;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2021-04-06 20:30:52 +00:00
|
|
|
e = dap_check_config(&dap->dap);
|
|
|
|
if (e != ERROR_OK) {
|
|
|
|
e = JIM_ERR;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2021-11-17 21:15:20 +00:00
|
|
|
struct command_registration dap_create_commands[] = {
|
2018-03-23 20:17:29 +00:00
|
|
|
{
|
|
|
|
.name = cp,
|
|
|
|
.mode = COMMAND_ANY,
|
|
|
|
.help = "dap instance command group",
|
|
|
|
.usage = "",
|
|
|
|
.chain = dap_instance_commands,
|
|
|
|
},
|
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
/* don't expose the instance commands when using hla */
|
|
|
|
if (transport_is_hla())
|
2021-11-17 21:15:20 +00:00
|
|
|
dap_create_commands[0].chain = NULL;
|
2018-03-23 20:17:29 +00:00
|
|
|
|
2021-11-17 21:15:20 +00:00
|
|
|
e = register_commands_with_data(cmd_ctx, NULL, dap_create_commands, dap);
|
2021-11-10 11:46:42 +00:00
|
|
|
if (e != ERROR_OK) {
|
2021-11-15 14:32:39 +00:00
|
|
|
e = JIM_ERR;
|
|
|
|
goto err;
|
2021-11-10 11:46:42 +00:00
|
|
|
}
|
2018-03-23 20:17:29 +00:00
|
|
|
|
|
|
|
list_add_tail(&dap->lh, &all_dap);
|
|
|
|
|
2020-05-12 09:52:56 +00:00
|
|
|
return JIM_OK;
|
2021-11-15 14:32:39 +00:00
|
|
|
|
|
|
|
err:
|
|
|
|
free(dap->name);
|
|
|
|
free(dap);
|
|
|
|
return e;
|
2018-03-23 20:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int jim_dap_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
|
|
|
{
|
2021-04-24 22:48:14 +00:00
|
|
|
struct jim_getopt_info goi;
|
|
|
|
jim_getopt_setup(&goi, interp, argc - 1, argv + 1);
|
2018-03-23 20:17:29 +00:00
|
|
|
if (goi.argc < 2) {
|
|
|
|
Jim_WrongNumArgs(goi.interp, goi.argc, goi.argv,
|
|
|
|
"<name> [<dap_options> ...]");
|
|
|
|
return JIM_ERR;
|
|
|
|
}
|
|
|
|
return dap_create(&goi);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int jim_dap_names(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
|
|
|
|
{
|
|
|
|
struct arm_dap_object *obj;
|
|
|
|
|
|
|
|
if (argc != 1) {
|
|
|
|
Jim_WrongNumArgs(interp, 1, argv, "Too many parameters");
|
|
|
|
return JIM_ERR;
|
|
|
|
}
|
|
|
|
Jim_SetResult(interp, Jim_NewListObj(interp, NULL, 0));
|
|
|
|
list_for_each_entry(obj, &all_dap, lh) {
|
|
|
|
Jim_ListAppendElement(interp, Jim_GetResult(interp),
|
|
|
|
Jim_NewStringObj(interp, obj->name, -1));
|
|
|
|
}
|
|
|
|
return JIM_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
COMMAND_HANDLER(handle_dap_init)
|
|
|
|
{
|
|
|
|
return dap_init_all();
|
|
|
|
}
|
|
|
|
|
|
|
|
COMMAND_HANDLER(handle_dap_info_command)
|
|
|
|
{
|
|
|
|
struct target *target = get_current_target(CMD_CTX);
|
|
|
|
struct arm *arm = target_to_arm(target);
|
|
|
|
struct adiv5_dap *dap = arm->dap;
|
2021-08-14 21:56:12 +00:00
|
|
|
uint64_t apsel;
|
2018-03-23 20:17:29 +00:00
|
|
|
|
2021-07-03 16:51:20 +00:00
|
|
|
if (!dap) {
|
2019-01-19 14:58:49 +00:00
|
|
|
LOG_ERROR("DAP instance not available. Probably a HLA target...");
|
|
|
|
return ERROR_TARGET_RESOURCE_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2018-03-23 20:17:29 +00:00
|
|
|
switch (CMD_ARGC) {
|
|
|
|
case 0:
|
|
|
|
apsel = dap->apsel;
|
|
|
|
break;
|
|
|
|
case 1:
|
2021-08-09 13:31:10 +00:00
|
|
|
if (!strcmp(CMD_ARGV[0], "root")) {
|
|
|
|
if (!is_adiv6(dap)) {
|
|
|
|
command_print(CMD, "Option \"root\" not allowed with ADIv5 DAP");
|
|
|
|
return ERROR_COMMAND_ARGUMENT_INVALID;
|
|
|
|
}
|
|
|
|
int retval = adiv6_dap_read_baseptr(CMD, dap, &apsel);
|
|
|
|
if (retval != ERROR_OK) {
|
|
|
|
command_print(CMD, "Failed reading DAP baseptr");
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2021-08-14 21:56:12 +00:00
|
|
|
COMMAND_PARSE_NUMBER(u64, CMD_ARGV[0], apsel);
|
|
|
|
if (!is_ap_num_valid(dap, apsel))
|
2018-03-23 20:17:29 +00:00
|
|
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
|
|
|
}
|
|
|
|
|
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
2021-08-04 21:07:57 +00:00
|
|
|
struct adiv5_ap *ap = dap_get_ap(dap, apsel);
|
|
|
|
if (!ap) {
|
|
|
|
command_print(CMD, "Cannot get AP");
|
|
|
|
return ERROR_FAIL;
|
|
|
|
}
|
|
|
|
int retval = dap_info_command(CMD, ap);
|
|
|
|
dap_put_ap(ap);
|
|
|
|
return retval;
|
2018-03-23 20:17:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct command_registration dap_subcommand_handlers[] = {
|
|
|
|
{
|
|
|
|
.name = "create",
|
|
|
|
.mode = COMMAND_ANY,
|
|
|
|
.jim_handler = jim_dap_create,
|
|
|
|
.usage = "name '-chain-position' name",
|
|
|
|
.help = "Creates a new DAP instance",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "names",
|
|
|
|
.mode = COMMAND_ANY,
|
|
|
|
.jim_handler = jim_dap_names,
|
|
|
|
.usage = "",
|
|
|
|
.help = "Lists all registered DAP instances by name",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "init",
|
|
|
|
.mode = COMMAND_ANY,
|
|
|
|
.handler = handle_dap_init,
|
|
|
|
.usage = "",
|
|
|
|
.help = "Initialize all registered DAP instances"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "info",
|
|
|
|
.handler = handle_dap_info_command,
|
|
|
|
.mode = COMMAND_EXEC,
|
2021-08-09 13:31:10 +00:00
|
|
|
.help = "display ROM table for specified MEM-AP (default MEM-AP of current target) "
|
|
|
|
"or the ADIv6 root ROM table of current target's DAP",
|
|
|
|
.usage = "[ap_num | 'root']",
|
2018-03-23 20:17:29 +00:00
|
|
|
},
|
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct command_registration dap_commands[] = {
|
|
|
|
{
|
|
|
|
.name = "dap",
|
|
|
|
.mode = COMMAND_CONFIG,
|
|
|
|
.help = "DAP commands",
|
|
|
|
.chain = dap_subcommand_handlers,
|
2019-01-04 14:13:53 +00:00
|
|
|
.usage = "",
|
2018-03-23 20:17:29 +00:00
|
|
|
},
|
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
|
|
|
|
|
|
|
int dap_register_commands(struct command_context *cmd_ctx)
|
|
|
|
{
|
|
|
|
return register_commands(cmd_ctx, NULL, dap_commands);
|
|
|
|
}
|