From 464f7005bb1a566f1b10cd422e36cde3aae79179 Mon Sep 17 00:00:00 2001 From: Matthias Welwarsky Date: Thu, 17 Dec 2015 13:43:52 +0100 Subject: [PATCH] arm_debug: optimize DP and AP reads over JTAG On JTAG, all reads are pipelined. If you read a register, the result is not delivered inside the request that issued the read, it is delivered in the following request. The current code therefore issues a scan of the RDBUFF register after each read. This adds a superfluous transaction after each read. This patch follows a strategy similar to what SWD already implements. It also leverages that all JTAG reads are pipelined, i.e. the result will be clocked out in the next JTAG data phase, no matter if it's READ or WRITE. Therefore it's never necessary to explicitly read RDBUFF other than for the very last READ before a dap_run(). Change-Id: Ie40b1fef3203f0cdcb503f40dcbd2a68b0f9776c Signed-off-by: Matthias Welwarsky Reviewed-on: http://openocd.zylin.com/3167 Tested-by: jenkins Reviewed-by: Andreas Fritiofson --- src/target/adi_v5_jtag.c | 45 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/target/adi_v5_jtag.c b/src/target/adi_v5_jtag.c index b71fe382..ad6ef3c7 100644 --- a/src/target/adi_v5_jtag.c +++ b/src/target/adi_v5_jtag.c @@ -153,14 +153,13 @@ static int adi_jtag_dp_scan_u32(struct adiv5_dap *dap, return retval; } -/** - * Utility to write AP registers. - */ -static inline int adi_jtag_ap_write_check(struct adiv5_ap *ap, - uint8_t reg_addr, uint8_t *outvalue) +static void adi_jtag_finish_read(struct adiv5_dap *dap) { - return adi_jtag_dp_scan(ap->dap, JTAG_DP_APACC, reg_addr, DPAP_WRITE, - outvalue, NULL, NULL, ap->memaccess_tck); + if (dap->last_read != NULL) { + adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC, + DP_RDBUFF, DPAP_READ, 0, dap->last_read, &dap->ack, 0); + dap->last_read = NULL; + } } static int adi_jtag_scan_inout_check_u32(struct adiv5_dap *dap, @@ -314,15 +313,19 @@ static int jtagdp_transaction_endcheck(struct adiv5_dap *dap) static int jtag_dp_q_read(struct adiv5_dap *dap, unsigned reg, uint32_t *data) { - return adi_jtag_scan_inout_check_u32(dap, JTAG_DP_DPACC, - reg, DPAP_READ, 0, data, 0); + int retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC, reg, + DPAP_READ, 0, dap->last_read, &dap->ack, 0); + dap->last_read = data; + return retval; } static int jtag_dp_q_write(struct adiv5_dap *dap, unsigned reg, uint32_t data) { - return adi_jtag_scan_inout_check_u32(dap, JTAG_DP_DPACC, - reg, DPAP_WRITE, data, NULL, 0); + int retval = adi_jtag_dp_scan_u32(dap, JTAG_DP_DPACC, + reg, DPAP_WRITE, data, dap->last_read, &dap->ack, 0); + dap->last_read = NULL; + return retval; } /** Select the AP register bank matching bits 7:4 of reg. */ @@ -343,26 +346,29 @@ static int jtag_ap_q_read(struct adiv5_ap *ap, unsigned reg, uint32_t *data) { int retval = jtag_ap_q_bankselect(ap, reg); - if (retval != ERROR_OK) return retval; - return adi_jtag_scan_inout_check_u32(ap->dap, JTAG_DP_APACC, reg, - DPAP_READ, 0, data, ap->memaccess_tck); + retval = adi_jtag_dp_scan_u32(ap->dap, JTAG_DP_APACC, reg, + DPAP_READ, 0, ap->dap->last_read, &ap->dap->ack, + ap->memaccess_tck); + ap->dap->last_read = data; + + return retval; } static int jtag_ap_q_write(struct adiv5_ap *ap, unsigned reg, uint32_t data) { - uint8_t out_value_buf[4]; - int retval = jtag_ap_q_bankselect(ap, reg); if (retval != ERROR_OK) return retval; - buf_set_u32(out_value_buf, 0, 32, data); - - return adi_jtag_ap_write_check(ap, reg, out_value_buf); + retval = adi_jtag_dp_scan_u32(ap->dap, JTAG_DP_APACC, reg, + DPAP_WRITE, data, ap->dap->last_read, &ap->dap->ack, + ap->memaccess_tck); + ap->dap->last_read = NULL; + return retval; } static int jtag_ap_q_abort(struct adiv5_dap *dap, uint8_t *ack) @@ -374,6 +380,7 @@ static int jtag_ap_q_abort(struct adiv5_dap *dap, uint8_t *ack) static int jtag_dp_run(struct adiv5_dap *dap) { + adi_jtag_finish_read(dap); return jtagdp_transaction_endcheck(dap); } -- 2.39.5