uint8_t outvalue_buf[4];
};
+#define MAX_DAP_COMMAND_NUM 65536
+
+struct dap_cmd_pool {
+ struct list_head lh;
+ struct dap_cmd cmd;
+} dap_cmd_pool;
+
static void log_dap_cmd(const char *header, struct dap_cmd *el)
{
#ifdef DEBUG_WAIT
#endif
}
-static struct dap_cmd *dap_cmd_new(uint8_t instr,
+static int jtag_limit_queue_size(struct adiv5_dap *dap)
+{
+ if (dap->cmd_pool_size < MAX_DAP_COMMAND_NUM)
+ return ERROR_OK;
+
+ return dap_run(dap);
+}
+
+static struct dap_cmd *dap_cmd_new(struct adiv5_dap *dap, uint8_t instr,
uint8_t reg_addr, uint8_t RnW,
uint8_t *outvalue, uint8_t *invalue,
uint32_t memaccess_tck)
{
- struct dap_cmd *cmd;
- cmd = (struct dap_cmd *)calloc(1, sizeof(struct dap_cmd));
- if (cmd != NULL) {
- INIT_LIST_HEAD(&cmd->lh);
- cmd->instr = instr;
- cmd->reg_addr = reg_addr;
- cmd->RnW = RnW;
- if (outvalue != NULL)
- memcpy(cmd->outvalue_buf, outvalue, 4);
- cmd->invalue = (invalue != NULL) ? invalue : cmd->invalue_buf;
- cmd->memaccess_tck = memaccess_tck;
+ struct dap_cmd_pool *pool = NULL;
+
+ if (list_empty(&dap->cmd_pool)) {
+ pool = calloc(1, sizeof(struct dap_cmd_pool));
+ if (pool == NULL)
+ return NULL;
+ } else {
+ pool = list_first_entry(&dap->cmd_pool, struct dap_cmd_pool, lh);
+ list_del(&pool->lh);
}
+ INIT_LIST_HEAD(&pool->lh);
+ dap->cmd_pool_size++;
+
+ struct dap_cmd *cmd = &pool->cmd;
+ INIT_LIST_HEAD(&cmd->lh);
+ cmd->instr = instr;
+ cmd->reg_addr = reg_addr;
+ cmd->RnW = RnW;
+ if (outvalue != NULL)
+ memcpy(cmd->outvalue_buf, outvalue, 4);
+ cmd->invalue = (invalue != NULL) ? invalue : cmd->invalue_buf;
+ cmd->memaccess_tck = memaccess_tck;
+
return cmd;
}
-static void flush_journal(struct list_head *lh)
+static void dap_cmd_release(struct adiv5_dap *dap, struct dap_cmd *cmd)
+{
+ struct dap_cmd_pool *pool = container_of(cmd, struct dap_cmd_pool, cmd);
+ if (dap->cmd_pool_size > MAX_DAP_COMMAND_NUM)
+ free(pool);
+ else
+ list_add(&pool->lh, &dap->cmd_pool);
+
+ dap->cmd_pool_size--;
+}
+
+static void flush_journal(struct adiv5_dap *dap, struct list_head *lh)
{
struct dap_cmd *el, *tmp;
+ list_for_each_entry_safe(el, tmp, lh, lh) {
+ list_del(&el->lh);
+ dap_cmd_release(dap, el);
+ }
+}
+
+static void jtag_quit(struct adiv5_dap *dap)
+{
+ struct dap_cmd_pool *el, *tmp;
+ struct list_head *lh = &dap->cmd_pool;
+
list_for_each_entry_safe(el, tmp, lh, lh) {
list_del(&el->lh);
free(el);
struct dap_cmd *cmd;
int retval;
- cmd = dap_cmd_new(instr, reg_addr, RnW, outvalue, invalue, memaccess_tck);
+ cmd = dap_cmd_new(dap, instr, reg_addr, RnW, outvalue, invalue, memaccess_tck);
if (cmd != NULL)
cmd->dp_select = dap->select;
else
* To complete the READ, we just keep polling RDBUFF
* until the WAIT condition clears
*/
- tmp = dap_cmd_new(JTAG_DP_DPACC,
+ tmp = dap_cmd_new(dap, JTAG_DP_DPACC,
DP_RDBUFF, DPAP_READ, NULL, NULL, 0);
if (tmp == NULL) {
retval = ERROR_JTAG_DEVICE_ERROR;
}
/* we're done with this command, release it */
- free(tmp);
+ dap_cmd_release(dap, tmp);
if (retval != ERROR_OK)
goto done;
}
/* we're done with the journal, flush it */
- flush_journal(&dap->cmd_journal);
+ flush_journal(dap, &dap->cmd_journal);
/* check for overrun condition in the last batch of transactions */
if (found_wait) {
/* restore SELECT register first */
if (!list_empty(&replay_list)) {
el = list_first_entry(&replay_list, struct dap_cmd, lh);
- tmp = dap_cmd_new(JTAG_DP_DPACC,
+ tmp = dap_cmd_new(dap, JTAG_DP_DPACC,
DP_SELECT, DPAP_WRITE, (uint8_t *)&el->dp_select, NULL, 0);
if (tmp == NULL) {
retval = ERROR_JTAG_DEVICE_ERROR;
}
done:
- flush_journal(&replay_list);
- flush_journal(&dap->cmd_journal);
+ flush_journal(dap, &replay_list);
+ flush_journal(dap, &dap->cmd_journal);
return retval;
}
}
done:
- flush_journal(&dap->cmd_journal);
+ flush_journal(dap, &dap->cmd_journal);
return retval;
}
static int jtag_dp_q_read(struct adiv5_dap *dap, unsigned reg,
uint32_t *data)
{
- int retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC, reg,
+ int retval = jtag_limit_queue_size(dap);
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC, reg,
DPAP_READ, 0, dap->last_read, 0, NULL);
dap->last_read = data;
return retval;
static int jtag_dp_q_write(struct adiv5_dap *dap, unsigned reg,
uint32_t data)
{
- int retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC,
+ int retval = jtag_limit_queue_size(dap);
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC,
reg, DPAP_WRITE, data, dap->last_read, 0, NULL);
dap->last_read = NULL;
return retval;
static int jtag_ap_q_read(struct adiv5_ap *ap, unsigned reg,
uint32_t *data)
{
- int retval = jtag_check_reconnect(ap->dap);
+ int retval = jtag_limit_queue_size(ap->dap);
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = jtag_check_reconnect(ap->dap);
if (retval != ERROR_OK)
return retval;
static int jtag_ap_q_write(struct adiv5_ap *ap, unsigned reg,
uint32_t data)
{
- int retval = jtag_check_reconnect(ap->dap);
+ int retval = jtag_limit_queue_size(ap->dap);
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = jtag_check_reconnect(ap->dap);
if (retval != ERROR_OK)
return retval;
.queue_ap_abort = jtag_ap_q_abort,
.run = jtag_dp_run,
.sync = jtag_dp_sync,
+ .quit = jtag_quit,
};