Merge pull request #1082 from en-sc/en-sc/sbcs-read

target/riscv: simplify `sbcs` read in `write_memory_bus_v1()`
This commit is contained in:
Evgeniy Naydanov 2024-07-04 12:17:08 +03:00 committed by GitHub
commit f5f5f6dd2a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 20 deletions

View File

@ -4802,31 +4802,19 @@ static int write_memory_bus_v1(struct target *target, target_addr_t address,
/* Execute the batch of writes */ /* Execute the batch of writes */
result = batch_run(target, batch); result = batch_run(target, batch);
riscv_batch_free(batch); if (result != ERROR_OK) {
if (result != ERROR_OK) riscv_batch_free(batch);
return result; return result;
}
/* Read sbcs value. bool dmi_busy_encountered = riscv_batch_was_batch_busy(batch);
* At the same time, detect if DMI busy has occurred during the batch write. */ riscv_batch_free(batch);
bool dmi_busy_encountered;
if (dm_op(target, &sbcs, &dmi_busy_encountered, DMI_OP_READ,
DM_SBCS, 0, false, true) != ERROR_OK)
return ERROR_FAIL;
if (dmi_busy_encountered) if (dmi_busy_encountered)
LOG_TARGET_DEBUG(target, "DMI busy encountered during system bus write."); LOG_TARGET_DEBUG(target, "DMI busy encountered during system bus write.");
/* Wait until sbbusy goes low */ result = read_sbcs_nonbusy(target, &sbcs);
time_t start = time(NULL); if (result != ERROR_OK)
while (get_field(sbcs, DM_SBCS_SBBUSY)) { return result;
if (time(NULL) - start > riscv_command_timeout_sec) {
LOG_TARGET_ERROR(target, "Timed out after %ds waiting for sbbusy to go low (sbcs=0x%x). "
"Increase the timeout with riscv set_command_timeout_sec.",
riscv_command_timeout_sec, sbcs);
return ERROR_FAIL;
}
if (dm_read(target, &sbcs, DM_SBCS) != ERROR_OK)
return ERROR_FAIL;
}
if (get_field(sbcs, DM_SBCS_SBBUSYERROR)) { if (get_field(sbcs, DM_SBCS_SBBUSYERROR)) {
/* We wrote while the target was busy. */ /* We wrote while the target was busy. */