Skip to content

Commit e9fef03

Browse files
committed
target/riscv: Add support for external triggers
Add support for associating a halt group with an external trigger via a newly exposed configuration option "riscv set_external_trigger". Change-Id: If10c67d2e14d8bc7cd6d59011b3215fda4ff4b02 Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
1 parent eb1ecd7 commit e9fef03

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

doc/openocd.texi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11476,6 +11476,11 @@ The second argument configures how OpenOCD should use the selected trigger featu
1147611476
With no parameters, prints current trigger features configuration.
1147711477
@end deffn
1147811478

11479+
@deffn {Command} {riscv set_external_trigger} value
11480+
Associate the supplied external trigger with the SMP halt group for the harts. When the external trigger
11481+
fires the harts in the halt group will be halted.
11482+
@end deffn
11483+
1147911484
@subsection RISC-V Authentication Commands
1148011485

1148111486
The following commands can be used to authenticate to a RISC-V system. Eg. a

src/target/riscv/riscv-013.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,32 @@ static void deinit_target(struct target *target)
17031703
info->version_specific = NULL;
17041704
}
17051705

1706+
static int set_external_trigger(struct target *target, unsigned int group,
1707+
grouptype_t grouptype, unsigned int external_trigger)
1708+
{
1709+
uint32_t write_val = DM_DMCS2_HGWRITE | DM_DMCS2_HGSELECT;
1710+
assert(group <= 31);
1711+
assert(external_trigger < 16);
1712+
write_val = set_field(write_val, DM_DMCS2_GROUP, group);
1713+
write_val = set_field(write_val, DM_DMCS2_GROUPTYPE, (grouptype == HALT_GROUP) ? 0 : 1);
1714+
write_val = set_field(write_val, DM_DMCS2_DMEXTTRIGGER, external_trigger);
1715+
if (dm_write(target, DM_DMCS2, write_val) != ERROR_OK)
1716+
return ERROR_FAIL;
1717+
uint32_t read_val;
1718+
if (dm_read(target, &read_val, DM_DMCS2) != ERROR_OK)
1719+
return ERROR_FAIL;
1720+
if (get_field(read_val, DM_DMCS2_GROUP) == group &&
1721+
get_field(read_val, DM_DMCS2_DMEXTTRIGGER) == external_trigger &&
1722+
get_field(read_val, DM_DMCS2_HGSELECT) == 1) {
1723+
LOG_TARGET_INFO(target, "External trigger %d added to group %d", external_trigger,
1724+
group);
1725+
} else {
1726+
LOG_TARGET_ERROR(target, "External trigger %d not supported", external_trigger);
1727+
}
1728+
1729+
return ERROR_OK;
1730+
}
1731+
17061732
static int set_group(struct target *target, bool *supported, unsigned int group,
17071733
grouptype_t grouptype)
17081734
{
@@ -2051,6 +2077,9 @@ static int examine(struct target *target)
20512077
else
20522078
LOG_TARGET_INFO(target, "Core %d could not be made part of halt group %d.",
20532079
info->index, target->smp);
2080+
if (r->external_trigger)
2081+
if (set_external_trigger(target, target->smp, HALT_GROUP, r->external_trigger) != ERROR_OK)
2082+
return ERROR_FAIL;
20542083
}
20552084

20562085
/* Some regression suites rely on seeing 'Examined RISC-V core' to know

src/target/riscv/riscv.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5262,6 +5262,26 @@ COMMAND_HANDLER(handle_riscv_virt2phys_mode)
52625262
return ERROR_OK;
52635263
}
52645264

5265+
COMMAND_HANDLER(riscv_set_external_trigger)
5266+
{
5267+
struct target *target = get_current_target(CMD_CTX);
5268+
RISCV_INFO(r);
5269+
5270+
if (CMD_ARGC != 1) {
5271+
LOG_ERROR("Command takes exactly 1 parameter.");
5272+
return ERROR_COMMAND_SYNTAX_ERROR;
5273+
}
5274+
int value = atoi(CMD_ARGV[0]);
5275+
if (value <= 0 || value > 16) {
5276+
LOG_ERROR("%s is not a valid integer argument for command.", CMD_ARGV[0]);
5277+
return ERROR_FAIL;
5278+
}
5279+
5280+
r->external_trigger = value;
5281+
5282+
return ERROR_OK;
5283+
}
5284+
52655285
static const struct command_registration riscv_exec_command_handlers[] = {
52665286
{
52675287
.name = "dump_sample_buf",
@@ -5524,6 +5544,13 @@ static const struct command_registration riscv_exec_command_handlers[] = {
55245544
"When off, users need to take care of memory coherency themselves, for example by using "
55255545
"`riscv exec_progbuf` to execute fence or CMO instructions."
55265546
},
5547+
{
5548+
.name = "set_external_trigger",
5549+
.handler = riscv_set_external_trigger,
5550+
.mode = COMMAND_CONFIG,
5551+
.usage = "value",
5552+
.help = "Add the given external trigger to the halt group"
5553+
},
55275554
COMMAND_REGISTRATION_DONE
55285555
};
55295556

src/target/riscv/riscv.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ struct riscv_info {
191191
/* The configured approach to translate virtual addresses to physical */
192192
riscv_virt2phys_mode_t virt2phys_mode;
193193

194+
/* Halt group may be associated with an external trigger */
195+
unsigned int external_trigger;
196+
194197
bool triggers_enumerated;
195198

196199
/* Decremented every scan, and when it reaches 0 we clear the learned

0 commit comments

Comments
 (0)