Skip to content

Commit

Permalink
target/riscv: remove duplicate dtmcontrol_scan()
Browse files Browse the repository at this point in the history
Also avoid recieving data if the value is discarded on the call-site.

Change-Id: Ied87b551536a00d9fad469b9843cccae1976e6b6
Signed-off-by: Evgeniy Naydanov <[email protected]>
  • Loading branch information
en-sc committed Aug 14, 2024
1 parent 9a23c9e commit 1368e85
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 81 deletions.
32 changes: 0 additions & 32 deletions src/target/riscv/riscv-011.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,38 +273,6 @@ static uint16_t dram_address(unsigned int index)
return 0x40 + index - 0x10;
}

static int dtmcontrol_scan(struct target *target, uint32_t out, uint32_t *in_ptr)
{
struct scan_field field;
uint8_t in_value[4];
uint8_t out_value[4] = { 0 };

buf_set_u32(out_value, 0, 32, out);

jtag_add_ir_scan(target->tap, &select_dtmcontrol, TAP_IDLE);

field.num_bits = 32;
field.out_value = out_value;
field.in_value = in_value;
jtag_add_dr_scan(target->tap, 1, &field, TAP_IDLE);

/* Always return to dbus. */
jtag_add_ir_scan(target->tap, &select_dbus, TAP_IDLE);

int retval = jtag_execute_queue();
if (retval != ERROR_OK) {
LOG_ERROR("failed jtag scan: %d", retval);
return retval;
}

uint32_t in = buf_get_u32(field.in_value, 0, 32);
LOG_DEBUG("DTMCONTROL: 0x%x -> 0x%x", out, in);

if (in_ptr)
*in_ptr = in;
return ERROR_OK;
}

static uint32_t idcode_scan(struct target *target)
{
struct scan_field field;
Expand Down
35 changes: 0 additions & 35 deletions src/target/riscv/riscv-013.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,41 +433,6 @@ static void select_dmi(struct target *target)
jtag_add_ir_scan(target->tap, &select_dbus, TAP_IDLE);
}

static int dtmcontrol_scan(struct target *target, uint32_t out, uint32_t *in_ptr)
{
struct scan_field field;
uint8_t in_value[4];
uint8_t out_value[4] = { 0 };

if (bscan_tunnel_ir_width != 0)
return dtmcontrol_scan_via_bscan(target, out, in_ptr);

buf_set_u32(out_value, 0, 32, out);

jtag_add_ir_scan(target->tap, &select_dtmcontrol, TAP_IDLE);

field.num_bits = 32;
field.out_value = out_value;
field.in_value = in_value;
jtag_add_dr_scan(target->tap, 1, &field, TAP_IDLE);

/* Always return to dmi. */
select_dmi(target);

int retval = jtag_execute_queue();
if (retval != ERROR_OK) {
LOG_ERROR("failed jtag scan: %d", retval);
return retval;
}

uint32_t in = buf_get_u32(field.in_value, 0, 32);
LOG_DEBUG("DTMCS: 0x%x -> 0x%x", out, in);

if (in_ptr)
*in_ptr = in;
return ERROR_OK;
}

static int increase_dmi_busy_delay(struct target *target)
{
RISCV013_INFO(info);
Expand Down
30 changes: 17 additions & 13 deletions src/target/riscv/riscv.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,38 +383,42 @@ int dtmcontrol_scan_via_bscan(struct target *target, uint32_t out, uint32_t *in_
return ERROR_OK;
}

static int dtmcontrol_scan(struct target *target, uint32_t out, uint32_t *in_ptr)
/* TODO: rename "dtmcontrol"-> "dtmcs" */
int dtmcontrol_scan(struct target *target, uint32_t out, uint32_t *in_ptr)
{
struct scan_field field;
uint8_t in_value[4];
uint8_t out_value[4] = { 0 };
uint8_t value[4];

if (bscan_tunnel_ir_width != 0)
return dtmcontrol_scan_via_bscan(target, out, in_ptr);

buf_set_u32(out_value, 0, 32, out);
buf_set_u32(value, 0, 32, out);

jtag_add_ir_scan(target->tap, &select_dtmcontrol, TAP_IDLE);

field.num_bits = 32;
field.out_value = out_value;
field.in_value = in_value;
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);

/* Always return to dbus. */
jtag_add_ir_scan(target->tap, &select_dbus, TAP_IDLE);

int retval = jtag_execute_queue();
if (retval != ERROR_OK) {
LOG_TARGET_ERROR(target, "dtmcontrol scan failed, error code = %d", retval);
LOG_TARGET_ERROR(target, "dtmcs scan failed, error code = %d", retval);
return retval;
}

uint32_t in = buf_get_u32(field.in_value, 0, 32);
LOG_DEBUG("DTMCONTROL: 0x%x -> 0x%x", out, in);

if (in_ptr)
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);
*in_ptr = in;
} else {
LOG_TARGET_DEBUG(target, "DTMCS: 0x%" PRIx32 " -> ?", out);
}
return ERROR_OK;
}

Expand Down
3 changes: 2 additions & 1 deletion src/target/riscv/riscv.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,13 @@ 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);

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 int bscan_tunnel_ir_width;

int dtmcontrol_scan_via_bscan(struct target *target, uint32_t out, uint32_t *in_ptr);
void select_dmi_via_bscan(struct target *target);

/*** OpenOCD Interface */
Expand Down

0 comments on commit 1368e85

Please sign in to comment.