|
@@ -128,6 +128,92 @@ static int coresight_find_link_outport(struct coresight_device *csdev,
|
|
|
return -ENODEV;
|
|
|
}
|
|
|
|
|
|
+static inline u32 coresight_read_claim_tags(void __iomem *base)
|
|
|
+{
|
|
|
+ return readl_relaxed(base + CORESIGHT_CLAIMCLR);
|
|
|
+}
|
|
|
+
|
|
|
+static inline bool coresight_is_claimed_self_hosted(void __iomem *base)
|
|
|
+{
|
|
|
+ return coresight_read_claim_tags(base) == CORESIGHT_CLAIM_SELF_HOSTED;
|
|
|
+}
|
|
|
+
|
|
|
+static inline bool coresight_is_claimed_any(void __iomem *base)
|
|
|
+{
|
|
|
+ return coresight_read_claim_tags(base) != 0;
|
|
|
+}
|
|
|
+
|
|
|
+static inline void coresight_set_claim_tags(void __iomem *base)
|
|
|
+{
|
|
|
+ writel_relaxed(CORESIGHT_CLAIM_SELF_HOSTED, base + CORESIGHT_CLAIMSET);
|
|
|
+ isb();
|
|
|
+}
|
|
|
+
|
|
|
+static inline void coresight_clear_claim_tags(void __iomem *base)
|
|
|
+{
|
|
|
+ writel_relaxed(CORESIGHT_CLAIM_SELF_HOSTED, base + CORESIGHT_CLAIMCLR);
|
|
|
+ isb();
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * coresight_claim_device_unlocked : Claim the device for self-hosted usage
|
|
|
+ * to prevent an external tool from touching this device. As per PSCI
|
|
|
+ * standards, section "Preserving the execution context" => "Debug and Trace
|
|
|
+ * save and Restore", DBGCLAIM[1] is reserved for Self-hosted debug/trace and
|
|
|
+ * DBGCLAIM[0] is reserved for external tools.
|
|
|
+ *
|
|
|
+ * Called with CS_UNLOCKed for the component.
|
|
|
+ * Returns : 0 on success
|
|
|
+ */
|
|
|
+int coresight_claim_device_unlocked(void __iomem *base)
|
|
|
+{
|
|
|
+ if (coresight_is_claimed_any(base))
|
|
|
+ return -EBUSY;
|
|
|
+
|
|
|
+ coresight_set_claim_tags(base);
|
|
|
+ if (coresight_is_claimed_self_hosted(base))
|
|
|
+ return 0;
|
|
|
+ /* There was a race setting the tags, clean up and fail */
|
|
|
+ coresight_clear_claim_tags(base);
|
|
|
+ return -EBUSY;
|
|
|
+}
|
|
|
+
|
|
|
+int coresight_claim_device(void __iomem *base)
|
|
|
+{
|
|
|
+ int rc;
|
|
|
+
|
|
|
+ CS_UNLOCK(base);
|
|
|
+ rc = coresight_claim_device_unlocked(base);
|
|
|
+ CS_LOCK(base);
|
|
|
+
|
|
|
+ return rc;
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+ * coresight_disclaim_device_unlocked : Clear the claim tags for the device.
|
|
|
+ * Called with CS_UNLOCKed for the component.
|
|
|
+ */
|
|
|
+void coresight_disclaim_device_unlocked(void __iomem *base)
|
|
|
+{
|
|
|
+
|
|
|
+ if (coresight_is_claimed_self_hosted(base))
|
|
|
+ coresight_clear_claim_tags(base);
|
|
|
+ else
|
|
|
+ /*
|
|
|
+ * The external agent may have not honoured our claim
|
|
|
+ * and has manipulated it. Or something else has seriously
|
|
|
+ * gone wrong in our driver.
|
|
|
+ */
|
|
|
+ WARN_ON_ONCE(1);
|
|
|
+}
|
|
|
+
|
|
|
+void coresight_disclaim_device(void __iomem *base)
|
|
|
+{
|
|
|
+ CS_UNLOCK(base);
|
|
|
+ coresight_disclaim_device_unlocked(base);
|
|
|
+ CS_LOCK(base);
|
|
|
+}
|
|
|
+
|
|
|
static int coresight_enable_sink(struct coresight_device *csdev,
|
|
|
u32 mode, void *data)
|
|
|
{
|