adiv6: add dap flags -adiv5 and -adiv6
[openocd.git] / src / target / arm_adi_v5.h
index 1c96dc87ac8c0952d224c5702ef07473a98e0ef6..d7824cedf30950e125811120f9e68c801555e8e9 100644 (file)
 
 #define DLCR_TO_TRN(dlcr) ((uint32_t)(1 + ((3 & (dlcr)) >> 8))) /* 1..4 clocks */
 
+/* Fields of DP_DPIDR register */
+#define DP_DPIDR_VERSION_SHIFT 12
+#define DP_DPIDR_VERSION_MASK  (0xFUL << DP_DPIDR_VERSION_SHIFT)
+
 /* Fields of the DP's AP ABORT register */
 #define DAPABORT        (1UL << 0)
 #define STKCMPCLR       (1UL << 1) /* SWD-only */
@@ -89,6 +93,8 @@
 #define CSYSPWRUPREQ    (1UL << 30)
 #define CSYSPWRUPACK    (1UL << 31)
 
+#define DP_DLPIDR_PROTVSN      1u
+
 #define DP_SELECT_APSEL 0xFF000000
 #define DP_SELECT_APBANK 0x000000F0
 #define DP_SELECT_DPBANK 0x0000000F
@@ -253,6 +259,12 @@ struct adiv5_ap {
 
        /* MEM AP configuration register indicating LPAE support */
        uint32_t cfg_reg;
+
+       /* references counter */
+       unsigned int refcount;
+
+       /* AP referenced during config. Never put it, even when refcount reaches zero */
+       bool config_ap_never_release;
 };
 
 
@@ -336,6 +348,14 @@ struct adiv5_dap {
        bool multidrop_dp_id_valid;
        /** TINSTANCE field of multidrop_targetsel has been configured */
        bool multidrop_instance_id_valid;
+
+       /**
+        * Record if enter in SWD required passing through DORMANT
+        */
+       bool switch_through_dormant;
+
+       /** Indicates ADI version (5, 6 or 0 for unknown) being used */
+       unsigned int adi_version;
 };
 
 /**
@@ -409,6 +429,18 @@ static inline bool is_64bit_ap(struct adiv5_ap *ap)
        return (ap->cfg_reg & MEM_AP_REG_CFG_LA) != 0;
 }
 
+/**
+ * Check if DAP is ADIv6
+ *
+ * @param dap The DAP to test
+ *
+ * @return true for ADIv6, false for either ADIv5 or unknown version
+ */
+static inline bool is_adiv6(const struct adiv5_dap *dap)
+{
+       return dap->adi_version == 6;
+}
+
 /**
  * Send an adi-v5 sequence to the DAP.
  *
@@ -475,6 +507,10 @@ static inline int dap_queue_ap_read(struct adiv5_ap *ap,
                unsigned reg, uint32_t *data)
 {
        assert(ap->dap->ops);
+       if (ap->refcount == 0) {
+               ap->refcount = 1;
+               LOG_ERROR("BUG: refcount AP#%" PRIu8 " used without get", ap->ap_num);
+       }
        return ap->dap->ops->queue_ap_read(ap, reg, data);
 }
 
@@ -491,6 +527,10 @@ static inline int dap_queue_ap_write(struct adiv5_ap *ap,
                unsigned reg, uint32_t data)
 {
        assert(ap->dap->ops);
+       if (ap->refcount == 0) {
+               ap->refcount = 1;
+               LOG_ERROR("BUG: refcount AP#%" PRIu8 " used without get", ap->ap_num);
+       }
        return ap->dap->ops->queue_ap_write(ap, reg, data);
 }
 
@@ -608,19 +648,19 @@ int mem_ap_init(struct adiv5_ap *ap);
 /* Invalidate cached DP select and cached TAR and CSW of all APs */
 void dap_invalidate_cache(struct adiv5_dap *dap);
 
-/* Probe the AP for ROM Table location */
-int dap_get_debugbase(struct adiv5_ap *ap,
-                       target_addr_t *dbgbase, uint32_t *apid);
-
-/* Probe Access Ports to find a particular type */
-int dap_find_ap(struct adiv5_dap *dap,
+/* Probe Access Ports to find a particular type. Increment AP refcount */
+int dap_find_get_ap(struct adiv5_dap *dap,
                        enum ap_type type_to_find,
                        struct adiv5_ap **ap_out);
 
-static inline struct adiv5_ap *dap_ap(struct adiv5_dap *dap, uint8_t ap_num)
-{
-       return &dap->ap[ap_num];
-}
+/* Return AP with specified ap_num. Increment AP refcount */
+struct adiv5_ap *dap_get_ap(struct adiv5_dap *dap, unsigned int ap_num);
+
+/* Return AP with specified ap_num. Increment AP refcount and keep it non-zero */
+struct adiv5_ap *dap_get_config_ap(struct adiv5_dap *dap, unsigned int ap_num);
+
+/* Decrement AP refcount and release the AP when refcount reaches zero */
+int dap_put_ap(struct adiv5_ap *ap);
 
 /** Check if SWD multidrop configuration is valid */
 static inline bool dap_is_multidrop(struct adiv5_dap *dap)
@@ -630,7 +670,7 @@ static inline bool dap_is_multidrop(struct adiv5_dap *dap)
 
 /* Lookup CoreSight component */
 int dap_lookup_cs_component(struct adiv5_ap *ap,
-                       target_addr_t dbgbase, uint8_t type, target_addr_t *addr, int32_t *idx);
+                       uint8_t type, target_addr_t *addr, int32_t idx);
 
 struct target;
 

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)