From patchwork Thu Sep 20 19:18:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 147153 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp2376783ljw; Thu, 20 Sep 2018 12:19:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYXoh9JlMqv32BiFRzrAi1nfpgDQKMY0vflFWOxLNdjljn8nnl0oLoSEiEB1pCr18T6UFjI X-Received: by 2002:a62:3545:: with SMTP id c66-v6mr42357665pfa.63.1537471160825; Thu, 20 Sep 2018 12:19:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537471160; cv=none; d=google.com; s=arc-20160816; b=zn4PWOnDQNbMTnrHsE2foIiKU/pUBX58qNS220ukzdmRHIGQ1eYHnm6B7dmo5XQJe1 EyaM4MKLBdhTT5gYUvJji8/FPNfbl8rypBfgInP1lSvJa4kgdsiia4Fb4ztQf9MGztrP U5SPSeG78dHNL/aP1TxAMOb+0OdcuvbYiW110zk895XSqID/paOb4zEpBo5LRYNnIcol 9eOGO7yZ+zGz1IYQDPhPJONdze/91FBk1fSCujT+ZpdH1ck4R79Sfnt+kfyaZtpKkD9v Rp+kXLMXVU1WW4SAO2vsZ8iyoFYmzIDpt90y9KTBTzGZzGYdYRR+ctTNCsr+R8VV+Q12 cExQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=XYoLsNZfR03NjVkAKkp/jGU/bTSOzZPT2U9//grQAEE=; b=aXOYXB6TMz8yjJKeYhxLK7U63Px+lV+v8AOBM/PeDC1ItIqGc9cjLTGhSK+0sEdR8Y YhiZDGLYNpy4A0PhX2aVONvgLVNKYSlLDVluovh4gaQsDGgIW7fDJXDQZy95ACNRC2t7 zeDZxUEXM0kXbvAJqYzBKN3s4BySo8KULIaC//UMVOi6ie6BJnyIEvAf4O03L99ChKJo 1rrrVAUU1NxzCQEh267eJ+tHbcZHaTpIsOGuLgTCoRPDNIE0K7tlnFQcdQIm8gISoXGu GXs+AXOy4JUzzclB0oBZwzh7NS0lJrvbg3f8A3ywAeqPQ53SBsczvcPOuLczoI8m5TqL zk/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kzF8OFIE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8-v6si24491134pgl.101.2018.09.20.12.19.20; Thu, 20 Sep 2018 12:19:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kzF8OFIE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389073AbeIUBER (ORCPT + 32 others); Thu, 20 Sep 2018 21:04:17 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37462 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388518AbeIUBEP (ORCPT ); Thu, 20 Sep 2018 21:04:15 -0400 Received: by mail-pl1-f194.google.com with SMTP id q5-v6so1323495pli.4 for ; Thu, 20 Sep 2018 12:19:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XYoLsNZfR03NjVkAKkp/jGU/bTSOzZPT2U9//grQAEE=; b=kzF8OFIE3qtMuejYaqTvZvL95QYKOlQZrKK0uIFM9dhVnqAohTiniPi63WKR/L4rXZ 8ftWAmzB7wE8tzhg88XaTWaEzQG01u1WpXMQvsfWwBOJ6rf7pYv1Tq/SJrowH0y87S/2 i942xsdc98ln3Gw7RtqOwvNja2yIw3cSbug9A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XYoLsNZfR03NjVkAKkp/jGU/bTSOzZPT2U9//grQAEE=; b=klKjpeI70OwiX3glbq8mSxUCBqdZGEW9Q/2Qa6trO3qWs488fO/ppMX89U2Kr3a9ke DbLqrAmG+rSMntP0WB7SHLBU7uDIkrjXT8fqa+HAaAyN2DaRkrS3JstXvTtxrUxIfRTL RzOsAvHY2j0UnKsIKXeA6jak08bIqgUGVgYizjOWAfwjIUp8JW0RbXgmEGDQ43OTIhEV F9CgOQ3SRXsbf2bT3KW6xQ2JvAB5BxlzFic7uRtj/6id1T/wPUqAu29Ww0U+Jh2YvU3O qRwV944srOb8167mbf+iWmpFHQX+KaVpRFnosjBHd1Q0U+3cnZfOClbYiQiioPMHmEFu celg== X-Gm-Message-State: APzg51AdZpf+u8LzOGpaeaf0YLjQ+yVSW37+qpSZxQ4t8iaYPxoZJqiP dk7T+9zMNG/X/srGIqS0nAUo0Y1Ku5o= X-Received: by 2002:a17:902:a715:: with SMTP id w21-v6mr40817654plq.61.1537471156580; Thu, 20 Sep 2018 12:19:16 -0700 (PDT) Received: from localhost.localdomain ([209.121.128.187]) by smtp.gmail.com with ESMTPSA id k13-v6sm4424443pgf.37.2018.09.20.12.19.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Sep 2018 12:19:15 -0700 (PDT) From: Mathieu Poirier To: gregkh@linuxfoundation.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH 36/44] coresight: Add support for CLAIM tag protocol Date: Thu, 20 Sep 2018 13:18:11 -0600 Message-Id: <1537471099-19781-37-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1537471099-19781-1-git-send-email-mathieu.poirier@linaro.org> References: <1537471099-19781-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Suzuki K Poulose Coresight architecture defines CLAIM tags for a device to negotiate control of the components (external agent vs self-hosted). Each device has a pair of registers (CLAIMSET & CLAIMCLR) for managing the CLAIM tags. However, the protocol for the CLAIM tags is IMPLEMENTATION DEFINED. PSCI has recommendations for the use of the CLAIM tags to negotiate controls for external agent vs self-hosted use. This patch implements the recommended protocol by PSCI. The claim/disclaim operations are performed from the device specific drivers. The disadvantage is that the calls are sprinkled in each driver, but this makes the operation much simpler. Cc: Mathieu Poirier Signed-off-by: Suzuki K Poulose Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-priv.h | 7 +++ drivers/hwtracing/coresight/coresight.c | 86 ++++++++++++++++++++++++++++ include/linux/coresight.h | 20 +++++++ 3 files changed, 113 insertions(+) -- 2.7.4 diff --git a/drivers/hwtracing/coresight/coresight-priv.h b/drivers/hwtracing/coresight/coresight-priv.h index c11da5564a67..579f34943bf1 100644 --- a/drivers/hwtracing/coresight/coresight-priv.h +++ b/drivers/hwtracing/coresight/coresight-priv.h @@ -25,6 +25,13 @@ #define CORESIGHT_DEVID 0xfc8 #define CORESIGHT_DEVTYPE 0xfcc + +/* + * Coresight device CLAIM protocol. + * See PSCI - ARM DEN 0022D, Section: 6.8.1 Debug and Trace save and restore. + */ +#define CORESIGHT_CLAIM_SELF_HOSTED BIT(1) + #define TIMEOUT_US 100 #define BMVAL(val, lsb, msb) ((val & GENMASK(msb, lsb)) >> lsb) diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index f4f50753cf75..2b0df1a0a8df 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -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) { diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 53535821dc25..46c67a764877 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -257,6 +257,13 @@ extern int coresight_enable(struct coresight_device *csdev); extern void coresight_disable(struct coresight_device *csdev); extern int coresight_timeout(void __iomem *addr, u32 offset, int position, int value); + +extern int coresight_claim_device(void __iomem *base); +extern int coresight_claim_device_unlocked(void __iomem *base); + +extern void coresight_disclaim_device(void __iomem *base); +extern void coresight_disclaim_device_unlocked(void __iomem *base); + #else static inline struct coresight_device * coresight_register(struct coresight_desc *desc) { return NULL; } @@ -266,6 +273,19 @@ coresight_enable(struct coresight_device *csdev) { return -ENOSYS; } static inline void coresight_disable(struct coresight_device *csdev) {} static inline int coresight_timeout(void __iomem *addr, u32 offset, int position, int value) { return 1; } +static inline int coresight_claim_device_unlocked(void __iomem *base) +{ + return -EINVAL; +} + +static inline int coresight_claim_device(void __iomem *base) +{ + return -EINVAL; +} + +static inline void coresight_disclaim_device(void __iomem *base) {} +static inline void coresight_disclaim_device_unlocked(void __iomem *base) {} + #endif #ifdef CONFIG_OF