Skip to content

Commit dd72250

Browse files
authored
Merge pull request #1208 from en-sc/en-sc/pass-tap
target/riscv: pass `jtag_tap` instead of `target`
2 parents 8f59570 + 8309288 commit dd72250

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
@@ -294,7 +294,8 @@ int riscv_batch_run_from(struct riscv_batch *batch, size_t start_idx,
294294
unsigned int delay = 0 /* to silence maybe-uninitialized */;
295295
for (size_t i = start_idx; i < batch->used_scans; ++i) {
296296
if (bscan_tunnel_ir_width != 0)
297-
riscv_add_bscan_tunneled_scan(batch->target, batch->fields + i, batch->bscan_ctxt + i);
297+
riscv_add_bscan_tunneled_scan(batch->target->tap, batch->fields + i,
298+
batch->bscan_ctxt + i);
298299
else
299300
jtag_add_dr_scan(batch->target->tap, 1, batch->fields + i, TAP_IDLE);
300301

src/target/riscv/riscv-011.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ static void increase_dbus_busy_delay(struct target *target)
333333
info->dtmcontrol_idle, info->dbus_busy_delay,
334334
info->interrupt_high_delay);
335335

336-
dtmcontrol_scan(target, DTMCONTROL_DBUS_RESET, NULL /* discard value */);
336+
dtmcs_scan(target->tap, DTMCONTROL_DBUS_RESET, NULL /* discard value */);
337337
}
338338

339339
static void increase_interrupt_high_delay(struct target *target)
@@ -1483,7 +1483,7 @@ static int examine(struct target *target)
14831483
{
14841484
/* Don't need to select dbus, since the first thing we do is read dtmcontrol. */
14851485
uint32_t dtmcontrol;
1486-
if (dtmcontrol_scan(target, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
1486+
if (dtmcs_scan(target->tap, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
14871487
LOG_ERROR("Could not scan dtmcontrol. Check JTAG connectivity/board power.");
14881488
return ERROR_FAIL;
14891489
}

src/target/riscv/riscv-013.c

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

353353
/*** Utility functions. ***/
354354

355-
static void select_dmi(struct target *target)
355+
static void select_dmi(struct jtag_tap *tap)
356356
{
357357
if (bscan_tunnel_ir_width != 0) {
358-
select_dmi_via_bscan(target);
358+
select_dmi_via_bscan(tap);
359359
return;
360360
}
361-
if (!target->tap->enabled)
362-
LOG_TARGET_ERROR(target, "BUG: Target's TAP '%s' is disabled!",
363-
jtag_tap_name(target->tap));
361+
if (!tap->enabled)
362+
LOG_ERROR("BUG: Target's TAP '%s' is disabled!", jtag_tap_name(tap));
364363

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

384383
if (need_ir_scan)
385-
jtag_add_ir_scan(target->tap, &select_dbus, TAP_IDLE);
384+
jtag_add_ir_scan(tap, &select_dbus, TAP_IDLE);
386385
}
387386

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

392-
int res = dtmcontrol_scan(target, DTM_DTMCS_DMIRESET,
391+
int res = dtmcs_scan(target->tap, DTM_DTMCS_DMIRESET,
393392
NULL /* discard result */);
394393
if (res != ERROR_OK)
395394
return res;
@@ -1929,7 +1928,7 @@ static int examine(struct target *target)
19291928
LOG_TARGET_DEBUG(target, "dbgbase=0x%x", target->dbgbase);
19301929

19311930
uint32_t dtmcontrol;
1932-
if (dtmcontrol_scan(target, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
1931+
if (dtmcs_scan(target->tap, 0, &dtmcontrol) != ERROR_OK || dtmcontrol == 0) {
19331932
LOG_TARGET_ERROR(target, "Could not scan dtmcontrol. Check JTAG connectivity/board power.");
19341933
return ERROR_FAIL;
19351934
}
@@ -2437,7 +2436,7 @@ static int batch_run(struct target *target, struct riscv_batch *batch)
24372436
{
24382437
RISCV_INFO(r);
24392438
RISCV013_INFO(info);
2440-
select_dmi(target);
2439+
select_dmi(target->tap);
24412440
riscv_batch_add_nop(batch);
24422441
const int result = riscv_batch_run_from(batch, 0, &info->learned_delays,
24432442
/*resets_delays*/ r->reset_delays_wait >= 0,
@@ -2460,7 +2459,7 @@ static int batch_run(struct target *target, struct riscv_batch *batch)
24602459
static int batch_run_timeout(struct target *target, struct riscv_batch *batch)
24612460
{
24622461
RISCV013_INFO(info);
2463-
select_dmi(target);
2462+
select_dmi(target->tap);
24642463
riscv_batch_add_nop(batch);
24652464

24662465
size_t finished_scans = 0;
@@ -2843,7 +2842,7 @@ static int assert_reset(struct target *target)
28432842
RISCV013_INFO(info);
28442843
int result;
28452844

2846-
select_dmi(target);
2845+
select_dmi(target->tap);
28472846

28482847
if (target_has_event_action(target, TARGET_EVENT_RESET_ASSERT)) {
28492848
/* Run the user-supplied script if there is one. */
@@ -2897,7 +2896,7 @@ static int deassert_reset(struct target *target)
28972896
return ERROR_FAIL;
28982897
int result;
28992898

2900-
select_dmi(target);
2899+
select_dmi(target->tap);
29012900
/* Clear the reset, but make sure haltreq is still set */
29022901
uint32_t control = 0;
29032902
control = set_field(control, DM_DMCONTROL_DMACTIVE, 1);
@@ -4383,7 +4382,7 @@ read_memory_progbuf(struct target *target, const riscv_mem_access_args_t args)
43834382
if (dm013_select_target(target) != ERROR_OK)
43844383
return MEM_ACCESS_SKIPPED_TARGET_SELECT_FAILED;
43854384

4386-
select_dmi(target);
4385+
select_dmi(target->tap);
43874386

43884387
memset(args.read_buffer, 0, args.count * args.size);
43894388

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
@@ -435,14 +435,14 @@ extern struct scan_field select_dtmcontrol;
435435
extern struct scan_field select_dbus;
436436
extern struct scan_field select_idcode;
437437

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

440440
extern struct scan_field *bscan_tunneled_select_dmi;
441441
extern uint32_t bscan_tunneled_select_dmi_num_fields;
442442
typedef enum { BSCAN_TUNNEL_NESTED_TAP, BSCAN_TUNNEL_DATA_REGISTER } bscan_tunnel_type_t;
443443
extern uint8_t bscan_tunnel_ir_width;
444444

445-
void select_dmi_via_bscan(struct target *target);
445+
void select_dmi_via_bscan(struct jtag_tap *tap);
446446

447447
/*** OpenOCD Interface */
448448
int riscv_openocd_poll(struct target *target);
@@ -498,7 +498,7 @@ void riscv_semihosting_init(struct target *target);
498498

499499
enum semihosting_result riscv_semihosting(struct target *target, int *retval);
500500

501-
void riscv_add_bscan_tunneled_scan(struct target *target, const struct scan_field *field,
501+
void riscv_add_bscan_tunneled_scan(struct jtag_tap *tap, const struct scan_field *field,
502502
riscv_bscan_tunneled_scan_context_t *ctxt);
503503

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

0 commit comments

Comments
 (0)