Change set_haltgroup() to more general set_group() (#697)

* Change set_haltgroup() to more general set_group()

Change-Id: Ib91a252ac63604e54b756f70c549ccd47241fd10
Signed-off-by: Tim Newsome <tim@sifive.com>

* Properly use enum.

Change-Id: I0edef6053fac388db38a22fe7557623fa93ec705
Co-authored-by: Jan Matyas <50193733+JanMatCodasip@users.noreply.github.com>

* Style changes suggested in review.

Change-Id: I29e83d3dbef09cb971ec0355aff733191a6e4679
Signed-off-by: Tim Newsome <tim@sifive.com>

Co-authored-by: Jan Matyas <50193733+JanMatCodasip@users.noreply.github.com>
This commit is contained in:
Tim Newsome 2022-05-16 10:17:04 -07:00 committed by GitHub
parent a408bdc8db
commit 6047fedc63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 7 deletions

View File

@ -1503,15 +1503,22 @@ static void deinit_target(struct target *target)
info->version_specific = NULL;
}
static int set_haltgroup(struct target *target, bool *supported)
typedef enum {
HALTGROUP,
RESUMEGROUP
} grouptype_t;
static int set_group(struct target *target, bool *supported, unsigned group, grouptype_t grouptype)
{
uint32_t write = set_field(DM_DMCS2_HGWRITE, DM_DMCS2_GROUP, target->smp);
if (dmi_write(target, DM_DMCS2, write) != ERROR_OK)
uint32_t write_val = DM_DMCS2_HGWRITE;
assert(group <= 31);
write_val = set_field(write_val, DM_DMCS2_GROUP, group);
write_val = set_field(write_val, DM_DMCS2_GROUPTYPE, (grouptype == HALTGROUP) ? 1 : 0);
if (dmi_write(target, DM_DMCS2, write_val) != ERROR_OK)
return ERROR_FAIL;
uint32_t read;
if (dmi_read(target, &read, DM_DMCS2) != ERROR_OK)
uint32_t read_val;
if (dmi_read(target, &read_val, DM_DMCS2) != ERROR_OK)
return ERROR_FAIL;
*supported = get_field(read, DM_DMCS2_GROUP) == (unsigned)target->smp;
*supported = get_field(read_val, DM_DMCS2_GROUP) == group;
return ERROR_OK;
}
@ -1754,7 +1761,7 @@ static int examine(struct target *target)
if (target->smp) {
bool haltgroup_supported;
if (set_haltgroup(target, &haltgroup_supported) != ERROR_OK)
if (set_group(target, &haltgroup_supported, target->smp, HALTGROUP) != ERROR_OK)
return ERROR_FAIL;
if (haltgroup_supported)
LOG_INFO("Core %d made part of halt group %d.", target->coreid,