arm_debug: optimize DP and AP reads over JTAG 67/3167/9
authorMatthias Welwarsky <matthias@welwarsky.de>
Thu, 17 Dec 2015 12:43:52 +0000 (13:43 +0100)
committerAndreas Fritiofson <andreas.fritiofson@gmail.com>
Tue, 29 Dec 2015 20:33:58 +0000 (20:33 +0000)
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 <matthias@welwarsky.de>
Reviewed-on: http://openocd.zylin.com/3167
Tested-by: jenkins
Reviewed-by: Andreas Fritiofson <andreas.fritiofson@gmail.com>
src/target/adi_v5_jtag.c

index b71fe3820ea53e20d02041a98164b61b1c448612..ad6ef3c7a55243a351848f1ac38b1278e0f35e50 100644 (file)
@@ -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);
 }
 

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)