target/riscv: pass `jtag_tap` instead of `target`
For some functions, passing `target` is excessive. The corresponding `tap` provides all the necessary data. Change-Id: Ie5836024a15222bda7c2b727f5dbaac38f459b3c Signed-off-by: Evgeniy Naydanov <evgeniy.naydanov@syntacore.com>
This commit is contained in:
parent
22108977c0
commit
8cbd420c94
|
@ -308,7 +308,7 @@ static void increase_dbus_busy_delay(struct target *target)
|
|||
info->dtmcontrol_idle, info->dbus_busy_delay,
|
||||
info->interrupt_high_delay);
|
||||
|
||||
dtmcontrol_scan(target, DTMCONTROL_DBUS_RESET, NULL /* discard value */);
|
||||
dtmcs_scan(target->tap, DTMCONTROL_DBUS_RESET, NULL /* discard value */);
|
||||
}
|
||||
|
||||
static void increase_interrupt_high_delay(struct target *target)
|
||||
|
@ -1458,7 +1458,7 @@ static int examine(struct target *target)
|
|||
{
|
||||
/* Don't need to select dbus, since the first thing we do is read dtmcontrol. */
|
||||
uint32_t dtmcontrol;
|
||||
if (dtmcontrol_scan(target, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
|
||||
if (dtmcs_scan(target->tap, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
|
||||
LOG_ERROR("Could not scan dtmcontrol. Check JTAG connectivity/board power.");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
|
|
@ -353,29 +353,28 @@ static uint32_t set_dmcontrol_hartsel(uint32_t initial, int hart_index)
|
|||
|
||||
/*** Utility functions. ***/
|
||||
|
||||
static void select_dmi(struct target *target)
|
||||
static void select_dmi(struct jtag_tap *tap)
|
||||
{
|
||||
if (bscan_tunnel_ir_width != 0) {
|
||||
select_dmi_via_bscan(target);
|
||||
select_dmi_via_bscan(tap);
|
||||
return;
|
||||
}
|
||||
if (!target->tap->enabled)
|
||||
LOG_TARGET_ERROR(target, "BUG: Target's TAP '%s' is disabled!",
|
||||
jtag_tap_name(target->tap));
|
||||
if (!tap->enabled)
|
||||
LOG_ERROR("BUG: Target's TAP '%s' is disabled!", jtag_tap_name(tap));
|
||||
|
||||
bool need_ir_scan = false;
|
||||
/* FIXME: make "tap" a const pointer. */
|
||||
for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL);
|
||||
tap; tap = jtag_tap_next_enabled(tap)) {
|
||||
if (tap != target->tap) {
|
||||
for (struct jtag_tap *other_tap = jtag_tap_next_enabled(NULL);
|
||||
other_tap; other_tap = jtag_tap_next_enabled(other_tap)) {
|
||||
if (other_tap != tap) {
|
||||
/* Different TAP than ours - check if it is in bypass */
|
||||
if (!tap->bypass) {
|
||||
if (!other_tap->bypass) {
|
||||
need_ir_scan = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Our TAP - check if the correct instruction is already loaded */
|
||||
if (!buf_eq(target->tap->cur_instr, select_dbus.out_value, target->tap->ir_length)) {
|
||||
if (!buf_eq(tap->cur_instr, select_dbus.out_value, tap->ir_length)) {
|
||||
need_ir_scan = true;
|
||||
break;
|
||||
}
|
||||
|
@ -383,14 +382,14 @@ static void select_dmi(struct target *target)
|
|||
}
|
||||
|
||||
if (need_ir_scan)
|
||||
jtag_add_ir_scan(target->tap, &select_dbus, TAP_IDLE);
|
||||
jtag_add_ir_scan(tap, &select_dbus, TAP_IDLE);
|
||||
}
|
||||
|
||||
static int increase_dmi_busy_delay(struct target *target)
|
||||
{
|
||||
RISCV013_INFO(info);
|
||||
|
||||
int res = dtmcontrol_scan(target, DTM_DTMCS_DMIRESET,
|
||||
int res = dtmcs_scan(target->tap, DTM_DTMCS_DMIRESET,
|
||||
NULL /* discard result */);
|
||||
if (res != ERROR_OK)
|
||||
return res;
|
||||
|
@ -1921,7 +1920,7 @@ static int examine(struct target *target)
|
|||
LOG_TARGET_DEBUG(target, "dbgbase=0x%x", target->dbgbase);
|
||||
|
||||
uint32_t dtmcontrol;
|
||||
if (dtmcontrol_scan(target, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
|
||||
if (dtmcs_scan(target->tap, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
|
||||
LOG_TARGET_ERROR(target, "Could not scan dtmcontrol. Check JTAG connectivity/board power.");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
@ -2413,7 +2412,7 @@ static int batch_run(struct target *target, struct riscv_batch *batch)
|
|||
{
|
||||
RISCV_INFO(r);
|
||||
RISCV013_INFO(info);
|
||||
select_dmi(target);
|
||||
select_dmi(target->tap);
|
||||
riscv_batch_add_nop(batch);
|
||||
const int result = riscv_batch_run_from(batch, 0, &info->learned_delays,
|
||||
/*resets_delays*/ r->reset_delays_wait >= 0,
|
||||
|
@ -2436,7 +2435,7 @@ static int batch_run(struct target *target, struct riscv_batch *batch)
|
|||
static int batch_run_timeout(struct target *target, struct riscv_batch *batch)
|
||||
{
|
||||
RISCV013_INFO(info);
|
||||
select_dmi(target);
|
||||
select_dmi(target->tap);
|
||||
riscv_batch_add_nop(batch);
|
||||
|
||||
size_t finished_scans = 0;
|
||||
|
@ -2819,7 +2818,7 @@ static int assert_reset(struct target *target)
|
|||
RISCV013_INFO(info);
|
||||
int result;
|
||||
|
||||
select_dmi(target);
|
||||
select_dmi(target->tap);
|
||||
|
||||
if (target_has_event_action(target, TARGET_EVENT_RESET_ASSERT)) {
|
||||
/* Run the user-supplied script if there is one. */
|
||||
|
@ -2873,7 +2872,7 @@ static int deassert_reset(struct target *target)
|
|||
return ERROR_FAIL;
|
||||
int result;
|
||||
|
||||
select_dmi(target);
|
||||
select_dmi(target->tap);
|
||||
/* Clear the reset, but make sure haltreq is still set */
|
||||
uint32_t control = 0;
|
||||
control = set_field(control, DM_DMCONTROL_DMACTIVE, 1);
|
||||
|
@ -4359,7 +4358,7 @@ read_memory_progbuf(struct target *target, const riscv_mem_access_args_t args)
|
|||
if (dm013_select_target(target) != ERROR_OK)
|
||||
return MEM_ACCESS_SKIPPED_TARGET_SELECT_FAILED;
|
||||
|
||||
select_dmi(target);
|
||||
select_dmi(target->tap);
|
||||
|
||||
memset(args.read_buffer, 0, args.count * args.size);
|
||||
|
||||
|
|
|
@ -310,18 +310,18 @@ static void riscv_sample_buf_maybe_add_timestamp(struct target *target, bool bef
|
|||
|
||||
static int riscv_resume_go_all_harts(struct target *target);
|
||||
|
||||
void select_dmi_via_bscan(struct target *target)
|
||||
void select_dmi_via_bscan(struct jtag_tap *tap)
|
||||
{
|
||||
jtag_add_ir_scan(target->tap, &select_user4, TAP_IDLE);
|
||||
jtag_add_ir_scan(tap, &select_user4, TAP_IDLE);
|
||||
if (bscan_tunnel_type == BSCAN_TUNNEL_DATA_REGISTER)
|
||||
jtag_add_dr_scan(target->tap, bscan_tunnel_data_register_select_dmi_num_fields,
|
||||
jtag_add_dr_scan(tap, bscan_tunnel_data_register_select_dmi_num_fields,
|
||||
bscan_tunnel_data_register_select_dmi, TAP_IDLE);
|
||||
else /* BSCAN_TUNNEL_NESTED_TAP */
|
||||
jtag_add_dr_scan(target->tap, bscan_tunnel_nested_tap_select_dmi_num_fields,
|
||||
jtag_add_dr_scan(tap, bscan_tunnel_nested_tap_select_dmi_num_fields,
|
||||
bscan_tunnel_nested_tap_select_dmi, TAP_IDLE);
|
||||
}
|
||||
|
||||
int dtmcontrol_scan_via_bscan(struct target *target, uint32_t out, uint32_t *in_ptr)
|
||||
static int dtmcs_scan_via_bscan(struct jtag_tap *tap, uint32_t out, uint32_t *in_ptr)
|
||||
{
|
||||
/* On BSCAN TAP: Select IR=USER4, issue tunneled IR scan via BSCAN TAP's DR */
|
||||
uint8_t tunneled_dr_width[4] = {32};
|
||||
|
@ -386,10 +386,10 @@ int dtmcontrol_scan_via_bscan(struct target *target, uint32_t out, uint32_t *in_
|
|||
tunneled_dr[0].out_value = bscan_one;
|
||||
tunneled_dr[0].in_value = NULL;
|
||||
}
|
||||
jtag_add_ir_scan(target->tap, &select_user4, TAP_IDLE);
|
||||
jtag_add_dr_scan(target->tap, ARRAY_SIZE(tunneled_ir), tunneled_ir, TAP_IDLE);
|
||||
jtag_add_dr_scan(target->tap, ARRAY_SIZE(tunneled_dr), tunneled_dr, TAP_IDLE);
|
||||
select_dmi_via_bscan(target);
|
||||
jtag_add_ir_scan(tap, &select_user4, TAP_IDLE);
|
||||
jtag_add_dr_scan(tap, ARRAY_SIZE(tunneled_ir), tunneled_ir, TAP_IDLE);
|
||||
jtag_add_dr_scan(tap, ARRAY_SIZE(tunneled_dr), tunneled_dr, TAP_IDLE);
|
||||
select_dmi_via_bscan(tap);
|
||||
|
||||
int retval = jtag_execute_queue();
|
||||
if (retval != ERROR_OK) {
|
||||
|
@ -407,40 +407,42 @@ int dtmcontrol_scan_via_bscan(struct target *target, uint32_t out, uint32_t *in_
|
|||
}
|
||||
|
||||
/* TODO: rename "dtmcontrol"-> "dtmcs" */
|
||||
int dtmcontrol_scan(struct target *target, uint32_t out, uint32_t *in_ptr)
|
||||
int dtmcs_scan(struct jtag_tap *tap, uint32_t out, uint32_t *in_ptr)
|
||||
{
|
||||
uint8_t value[4];
|
||||
|
||||
if (bscan_tunnel_ir_width != 0)
|
||||
return dtmcontrol_scan_via_bscan(target, out, in_ptr);
|
||||
return dtmcs_scan_via_bscan(tap, out, in_ptr);
|
||||
|
||||
buf_set_u32(value, 0, 32, out);
|
||||
|
||||
jtag_add_ir_scan(target->tap, &select_dtmcontrol, TAP_IDLE);
|
||||
jtag_add_ir_scan(tap, &select_dtmcontrol, TAP_IDLE);
|
||||
|
||||
struct scan_field field = {
|
||||
.num_bits = 32,
|
||||
.out_value = value,
|
||||
.in_value = in_ptr ? value : NULL
|
||||
};
|
||||
jtag_add_dr_scan(target->tap, 1, &field, TAP_IDLE);
|
||||
jtag_add_dr_scan(tap, 1, &field, TAP_IDLE);
|
||||
|
||||
/* Always return to dbus. */
|
||||
jtag_add_ir_scan(target->tap, &select_dbus, TAP_IDLE);
|
||||
jtag_add_ir_scan(tap, &select_dbus, TAP_IDLE);
|
||||
|
||||
int retval = jtag_execute_queue();
|
||||
if (retval != ERROR_OK) {
|
||||
LOG_TARGET_ERROR(target, "dtmcs scan failed, error code = %d", retval);
|
||||
LOG_ERROR("'dtmcs' scan failed on TAP %s, error code = %d",
|
||||
jtag_tap_name(tap), retval);
|
||||
return retval;
|
||||
}
|
||||
|
||||
if (in_ptr) {
|
||||
assert(field.in_value);
|
||||
uint32_t in = buf_get_u32(field.in_value, 0, 32);
|
||||
LOG_TARGET_DEBUG(target, "DTMCS: 0x%" PRIx32 " -> 0x%" PRIx32, out, in);
|
||||
LOG_DEBUG("TAP %s: DTMCS: 0x%" PRIx32 " -> 0x%" PRIx32,
|
||||
jtag_tap_name(tap), out, in);
|
||||
*in_ptr = in;
|
||||
} else {
|
||||
LOG_TARGET_DEBUG(target, "DTMCS: 0x%" PRIx32 " -> ?", out);
|
||||
LOG_DEBUG("TAP %s: DTMCS: 0x%" PRIx32 " -> ?", jtag_tap_name(tap), out);
|
||||
}
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
@ -2469,7 +2471,7 @@ static int riscv_examine(struct target *target)
|
|||
|
||||
RISCV_INFO(info);
|
||||
uint32_t dtmcontrol;
|
||||
if (dtmcontrol_scan(target, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
|
||||
if (dtmcs_scan(target->tap, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
|
||||
LOG_TARGET_ERROR(target, "Could not read dtmcontrol. Check JTAG connectivity/board power.");
|
||||
return ERROR_FAIL;
|
||||
}
|
||||
|
|
|
@ -432,14 +432,14 @@ extern struct scan_field select_dtmcontrol;
|
|||
extern struct scan_field select_dbus;
|
||||
extern struct scan_field select_idcode;
|
||||
|
||||
int dtmcontrol_scan(struct target *target, uint32_t out, uint32_t *in_ptr);
|
||||
int dtmcs_scan(struct jtag_tap *tap, uint32_t out, uint32_t *in_ptr);
|
||||
|
||||
extern struct scan_field *bscan_tunneled_select_dmi;
|
||||
extern uint32_t bscan_tunneled_select_dmi_num_fields;
|
||||
typedef enum { BSCAN_TUNNEL_NESTED_TAP, BSCAN_TUNNEL_DATA_REGISTER } bscan_tunnel_type_t;
|
||||
extern uint8_t bscan_tunnel_ir_width;
|
||||
|
||||
void select_dmi_via_bscan(struct target *target);
|
||||
void select_dmi_via_bscan(struct jtag_tap *tap);
|
||||
|
||||
/*** OpenOCD Interface */
|
||||
int riscv_openocd_poll(struct target *target);
|
||||
|
|
Loading…
Reference in New Issue