Skip to content

Commit 8309288

Browse files
committed
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 <[email protected]>
1 parent 2210897 commit 8309288

File tree

5 files changed

+47
-45
lines changed

5 files changed

+47
-45
lines changed

src/target/riscv/batch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ int riscv_batch_run_from(struct riscv_batch *batch, size_t start_idx,
288288
unsigned int delay = 0 /* to silence maybe-uninitialized */;
289289
for (size_t i = start_idx; i < batch->used_scans; ++i) {
290290
if (bscan_tunnel_ir_width != 0)
291-
riscv_add_bscan_tunneled_scan(batch->target, batch->fields + i, batch->bscan_ctxt + i);
291+
riscv_add_bscan_tunneled_scan(batch->target->tap, batch->fields + i,
292+
batch->bscan_ctxt + i);
292293
else
293294
jtag_add_dr_scan(batch->target->tap, 1, batch->fields + i, TAP_IDLE);
294295

src/target/riscv/riscv-011.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ static void increase_dbus_busy_delay(struct target *target)
308308
info->dtmcontrol_idle, info->dbus_busy_delay,
309309
info->interrupt_high_delay);
310310

311-
dtmcontrol_scan(target, DTMCONTROL_DBUS_RESET, NULL /* discard value */);
311+
dtmcs_scan(target->tap, DTMCONTROL_DBUS_RESET, NULL /* discard value */);
312312
}
313313

314314
static void increase_interrupt_high_delay(struct target *target)
@@ -1458,7 +1458,7 @@ static int examine(struct target *target)
14581458
{
14591459
/* Don't need to select dbus, since the first thing we do is read dtmcontrol. */
14601460
uint32_t dtmcontrol;
1461-
if (dtmcontrol_scan(target, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
1461+
if (dtmcs_scan(target->tap, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
14621462
LOG_ERROR("Could not scan dtmcontrol. Check JTAG connectivity/board power.");
14631463
return ERROR_FAIL;
14641464
}

src/target/riscv/riscv-013.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -353,44 +353,43 @@ static uint32_t set_dmcontrol_hartsel(uint32_t initial, int hart_index)
353353

354354
/*** Utility functions. ***/
355355

356-
static void select_dmi(struct target *target)
356+
static void select_dmi(struct jtag_tap *tap)
357357
{
358358
if (bscan_tunnel_ir_width != 0) {
359-
select_dmi_via_bscan(target);
359+
select_dmi_via_bscan(tap);
360360
return;
361361
}
362-
if (!target->tap->enabled)
363-
LOG_TARGET_ERROR(target, "BUG: Target's TAP '%s' is disabled!",
364-
jtag_tap_name(target->tap));
362+
if (!tap->enabled)
363+
LOG_ERROR("BUG: Target's TAP '%s' is disabled!", jtag_tap_name(tap));
365364

366365
bool need_ir_scan = false;
367366
/* FIXME: make "tap" a const pointer. */
368-
for (struct jtag_tap *tap = jtag_tap_next_enabled(NULL);
369-
tap; tap = jtag_tap_next_enabled(tap)) {
370-
if (tap != target->tap) {
367+
for (struct jtag_tap *other_tap = jtag_tap_next_enabled(NULL);
368+
other_tap; other_tap = jtag_tap_next_enabled(other_tap)) {
369+
if (other_tap != tap) {
371370
/* Different TAP than ours - check if it is in bypass */
372-
if (!tap->bypass) {
371+
if (!other_tap->bypass) {
373372
need_ir_scan = true;
374373
break;
375374
}
376375
} else {
377376
/* Our TAP - check if the correct instruction is already loaded */
378-
if (!buf_eq(target->tap->cur_instr, select_dbus.out_value, target->tap->ir_length)) {
377+
if (!buf_eq(tap->cur_instr, select_dbus.out_value, tap->ir_length)) {
379378
need_ir_scan = true;
380379
break;
381380
}
382381
}
383382
}
384383

385384
if (need_ir_scan)
386-
jtag_add_ir_scan(target->tap, &select_dbus, TAP_IDLE);
385+
jtag_add_ir_scan(tap, &select_dbus, TAP_IDLE);
387386
}
388387

389388
static int increase_dmi_busy_delay(struct target *target)
390389
{
391390
RISCV013_INFO(info);
392391

393-
int res = dtmcontrol_scan(target, DTM_DTMCS_DMIRESET,
392+
int res = dtmcs_scan(target->tap, DTM_DTMCS_DMIRESET,
394393
NULL /* discard result */);
395394
if (res != ERROR_OK)
396395
return res;
@@ -1921,7 +1920,7 @@ static int examine(struct target *target)
19211920
LOG_TARGET_DEBUG(target, "dbgbase=0x%x", target->dbgbase);
19221921

19231922
uint32_t dtmcontrol;
1924-
if (dtmcontrol_scan(target, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
1923+
if (dtmcs_scan(target->tap, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
19251924
LOG_TARGET_ERROR(target, "Could not scan dtmcontrol. Check JTAG connectivity/board power.");
19261925
return ERROR_FAIL;
19271926
}
@@ -2413,7 +2412,7 @@ static int batch_run(struct target *target, struct riscv_batch *batch)
24132412
{
24142413
RISCV_INFO(r);
24152414
RISCV013_INFO(info);
2416-
select_dmi(target);
2415+
select_dmi(target->tap);
24172416
riscv_batch_add_nop(batch);
24182417
const int result = riscv_batch_run_from(batch, 0, &info->learned_delays,
24192418
/*resets_delays*/ r->reset_delays_wait >= 0,
@@ -2436,7 +2435,7 @@ static int batch_run(struct target *target, struct riscv_batch *batch)
24362435
static int batch_run_timeout(struct target *target, struct riscv_batch *batch)
24372436
{
24382437
RISCV013_INFO(info);
2439-
select_dmi(target);
2438+
select_dmi(target->tap);
24402439
riscv_batch_add_nop(batch);
24412440

24422441
size_t finished_scans = 0;
@@ -2819,7 +2818,7 @@ static int assert_reset(struct target *target)
28192818
RISCV013_INFO(info);
28202819
int result;
28212820

2822-
select_dmi(target);
2821+
select_dmi(target->tap);
28232822

28242823
if (target_has_event_action(target, TARGET_EVENT_RESET_ASSERT)) {
28252824
/* Run the user-supplied script if there is one. */
@@ -2873,7 +2872,7 @@ static int deassert_reset(struct target *target)
28732872
return ERROR_FAIL;
28742873
int result;
28752874

2876-
select_dmi(target);
2875+
select_dmi(target->tap);
28772876
/* Clear the reset, but make sure haltreq is still set */
28782877
uint32_t control = 0;
28792878
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)
43594358
if (dm013_select_target(target) != ERROR_OK)
43604359
return MEM_ACCESS_SKIPPED_TARGET_SELECT_FAILED;
43614360

4362-
select_dmi(target);
4361+
select_dmi(target->tap);
43634362

43644363
memset(args.read_buffer, 0, args.count * args.size);
43654364

src/target/riscv/riscv.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -310,18 +310,18 @@ static void riscv_sample_buf_maybe_add_timestamp(struct target *target, bool bef
310310

311311
static int riscv_resume_go_all_harts(struct target *target);
312312

313-
void select_dmi_via_bscan(struct target *target)
313+
void select_dmi_via_bscan(struct jtag_tap *tap)
314314
{
315-
jtag_add_ir_scan(target->tap, &select_user4, TAP_IDLE);
315+
jtag_add_ir_scan(tap, &select_user4, TAP_IDLE);
316316
if (bscan_tunnel_type == BSCAN_TUNNEL_DATA_REGISTER)
317-
jtag_add_dr_scan(target->tap, bscan_tunnel_data_register_select_dmi_num_fields,
317+
jtag_add_dr_scan(tap, bscan_tunnel_data_register_select_dmi_num_fields,
318318
bscan_tunnel_data_register_select_dmi, TAP_IDLE);
319319
else /* BSCAN_TUNNEL_NESTED_TAP */
320-
jtag_add_dr_scan(target->tap, bscan_tunnel_nested_tap_select_dmi_num_fields,
320+
jtag_add_dr_scan(tap, bscan_tunnel_nested_tap_select_dmi_num_fields,
321321
bscan_tunnel_nested_tap_select_dmi, TAP_IDLE);
322322
}
323323

324-
int dtmcontrol_scan_via_bscan(struct target *target, uint32_t out, uint32_t *in_ptr)
324+
static int dtmcs_scan_via_bscan(struct jtag_tap *tap, uint32_t out, uint32_t *in_ptr)
325325
{
326326
/* On BSCAN TAP: Select IR=USER4, issue tunneled IR scan via BSCAN TAP's DR */
327327
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_
386386
tunneled_dr[0].out_value = bscan_one;
387387
tunneled_dr[0].in_value = NULL;
388388
}
389-
jtag_add_ir_scan(target->tap, &select_user4, TAP_IDLE);
390-
jtag_add_dr_scan(target->tap, ARRAY_SIZE(tunneled_ir), tunneled_ir, TAP_IDLE);
391-
jtag_add_dr_scan(target->tap, ARRAY_SIZE(tunneled_dr), tunneled_dr, TAP_IDLE);
392-
select_dmi_via_bscan(target);
389+
jtag_add_ir_scan(tap, &select_user4, TAP_IDLE);
390+
jtag_add_dr_scan(tap, ARRAY_SIZE(tunneled_ir), tunneled_ir, TAP_IDLE);
391+
jtag_add_dr_scan(tap, ARRAY_SIZE(tunneled_dr), tunneled_dr, TAP_IDLE);
392+
select_dmi_via_bscan(tap);
393393

394394
int retval = jtag_execute_queue();
395395
if (retval != ERROR_OK) {
@@ -407,40 +407,42 @@ int dtmcontrol_scan_via_bscan(struct target *target, uint32_t out, uint32_t *in_
407407
}
408408

409409
/* TODO: rename "dtmcontrol"-> "dtmcs" */
410-
int dtmcontrol_scan(struct target *target, uint32_t out, uint32_t *in_ptr)
410+
int dtmcs_scan(struct jtag_tap *tap, uint32_t out, uint32_t *in_ptr)
411411
{
412412
uint8_t value[4];
413413

414414
if (bscan_tunnel_ir_width != 0)
415-
return dtmcontrol_scan_via_bscan(target, out, in_ptr);
415+
return dtmcs_scan_via_bscan(tap, out, in_ptr);
416416

417417
buf_set_u32(value, 0, 32, out);
418418

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

421421
struct scan_field field = {
422422
.num_bits = 32,
423423
.out_value = value,
424424
.in_value = in_ptr ? value : NULL
425425
};
426-
jtag_add_dr_scan(target->tap, 1, &field, TAP_IDLE);
426+
jtag_add_dr_scan(tap, 1, &field, TAP_IDLE);
427427

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

431431
int retval = jtag_execute_queue();
432432
if (retval != ERROR_OK) {
433-
LOG_TARGET_ERROR(target, "dtmcs scan failed, error code = %d", retval);
433+
LOG_ERROR("'dtmcs' scan failed on TAP %s, error code = %d",
434+
jtag_tap_name(tap), retval);
434435
return retval;
435436
}
436437

437438
if (in_ptr) {
438439
assert(field.in_value);
439440
uint32_t in = buf_get_u32(field.in_value, 0, 32);
440-
LOG_TARGET_DEBUG(target, "DTMCS: 0x%" PRIx32 " -> 0x%" PRIx32, out, in);
441+
LOG_DEBUG("TAP %s: DTMCS: 0x%" PRIx32 " -> 0x%" PRIx32,
442+
jtag_tap_name(tap), out, in);
441443
*in_ptr = in;
442444
} else {
443-
LOG_TARGET_DEBUG(target, "DTMCS: 0x%" PRIx32 " -> ?", out);
445+
LOG_DEBUG("TAP %s: DTMCS: 0x%" PRIx32 " -> ?", jtag_tap_name(tap), out);
444446
}
445447
return ERROR_OK;
446448
}
@@ -2469,7 +2471,7 @@ static int riscv_examine(struct target *target)
24692471

24702472
RISCV_INFO(info);
24712473
uint32_t dtmcontrol;
2472-
if (dtmcontrol_scan(target, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
2474+
if (dtmcs_scan(target->tap, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
24732475
LOG_TARGET_ERROR(target, "Could not read dtmcontrol. Check JTAG connectivity/board power.");
24742476
return ERROR_FAIL;
24752477
}
@@ -6255,10 +6257,10 @@ int riscv_enumerate_triggers(struct target *target)
62556257
return ERROR_OK;
62566258
}
62576259

6258-
void riscv_add_bscan_tunneled_scan(struct target *target, const struct scan_field *field,
6260+
void riscv_add_bscan_tunneled_scan(struct jtag_tap *tap, const struct scan_field *field,
62596261
riscv_bscan_tunneled_scan_context_t *ctxt)
62606262
{
6261-
jtag_add_ir_scan(target->tap, &select_user4, TAP_IDLE);
6263+
jtag_add_ir_scan(tap, &select_user4, TAP_IDLE);
62626264

62636265
memset(ctxt->tunneled_dr, 0, sizeof(ctxt->tunneled_dr));
62646266
if (bscan_tunnel_type == BSCAN_TUNNEL_DATA_REGISTER) {
@@ -6291,5 +6293,5 @@ void riscv_add_bscan_tunneled_scan(struct target *target, const struct scan_fiel
62916293
ctxt->tunneled_dr[3].num_bits = 3;
62926294
ctxt->tunneled_dr[3].out_value = bscan_zero;
62936295
}
6294-
jtag_add_dr_scan(target->tap, ARRAY_SIZE(ctxt->tunneled_dr), ctxt->tunneled_dr, TAP_IDLE);
6296+
jtag_add_dr_scan(tap, ARRAY_SIZE(ctxt->tunneled_dr), ctxt->tunneled_dr, TAP_IDLE);
62956297
}

src/target/riscv/riscv.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,14 @@ extern struct scan_field select_dtmcontrol;
432432
extern struct scan_field select_dbus;
433433
extern struct scan_field select_idcode;
434434

435-
int dtmcontrol_scan(struct target *target, uint32_t out, uint32_t *in_ptr);
435+
int dtmcs_scan(struct jtag_tap *tap, uint32_t out, uint32_t *in_ptr);
436436

437437
extern struct scan_field *bscan_tunneled_select_dmi;
438438
extern uint32_t bscan_tunneled_select_dmi_num_fields;
439439
typedef enum { BSCAN_TUNNEL_NESTED_TAP, BSCAN_TUNNEL_DATA_REGISTER } bscan_tunnel_type_t;
440440
extern uint8_t bscan_tunnel_ir_width;
441441

442-
void select_dmi_via_bscan(struct target *target);
442+
void select_dmi_via_bscan(struct jtag_tap *tap);
443443

444444
/*** OpenOCD Interface */
445445
int riscv_openocd_poll(struct target *target);
@@ -495,7 +495,7 @@ void riscv_semihosting_init(struct target *target);
495495

496496
enum semihosting_result riscv_semihosting(struct target *target, int *retval);
497497

498-
void riscv_add_bscan_tunneled_scan(struct target *target, const struct scan_field *field,
498+
void riscv_add_bscan_tunneled_scan(struct jtag_tap *tap, const struct scan_field *field,
499499
riscv_bscan_tunneled_scan_context_t *ctxt);
500500

501501
int riscv_read_by_any_size(struct target *target, target_addr_t address, uint32_t size, uint8_t *buffer);

0 commit comments

Comments
 (0)