]> git.karo-electronics.de Git - linux-beck.git/commitdiff
arm-cci: Get rid of secure transactions for PMU driver
authorSuzuki K. Poulose <suzuki.poulose@arm.com>
Wed, 18 Mar 2015 12:24:40 +0000 (12:24 +0000)
committerWill Deacon <will.deacon@arm.com>
Fri, 27 Mar 2015 13:44:35 +0000 (13:44 +0000)
Avoid secure transactions while probing the CCI PMU. The
existing code makes use of the Peripheral ID2 (PID2) register
to determine the revision of the CCI400, which requires a
secure transaction. This puts a limitation on the usage of the
driver on systems running non-secure Linux(e.g, ARM64).

Updated the device-tree binding for cci pmu node to add the explicit
revision number for the compatible field.

The supported strings are :
arm,cci-400-pmu,r0
arm,cci-400-pmu,r1
arm,cci-400-pmu - DEPRECATED. See NOTE below

NOTE: If the revision is not mentioned, we need to probe the cci revision,
which could be fatal on a platform running non-secure. We need a reliable way
to know if we can poke the CCI registers at runtime on ARM32. We depend on
'mcpm_is_available()' when it is available. mcpm_is_available() returns true
only when there is a registered driver for mcpm. Otherwise, we assume that we
don't have secure access, and skips probing the revision number(ARM64 case).

The MCPM should figure out if it is safe to access the CCI. Unfortunately
there isn't a reliable way to indicate the same via dtb. This patch doesn't
address/change the current situation. It only deals with the CCI-PMU, leaving
the assumptions about the secure access as it has been, prior to this patch.

Cc: devicetree@vger.kernel.org
Cc: Punit Agrawal <punit.agrawal@arm.com>
Tested-by: Sudeep Holla <sudeep.holla@arm.com>
Acked-by: Nicolas Pitre <nicolas.pitre@linaro.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Suzuki K. Poulose <suzuki.poulose@arm.com>
Signed-off-by: Will Deacon <will.deacon@arm.com>
Documentation/devicetree/bindings/arm/cci.txt
arch/arm/include/asm/arm-cci.h [new file with mode: 0644]
arch/arm64/include/asm/arm-cci.h [new file with mode: 0644]
drivers/bus/arm-cci.c
include/linux/arm-cci.h

index f28d82bbbc56b3f3dff7716ede2f200f315d8e70..3c5c631328d3b6cbb4d7c9edefddf936347a545e 100644 (file)
@@ -94,8 +94,11 @@ specific to ARM.
                - compatible
                        Usage: required
                        Value type: <string>
-                       Definition: must be "arm,cci-400-pmu"
-
+                       Definition: Must contain one of:
+                                "arm,cci-400-pmu,r0"
+                                "arm,cci-400-pmu,r1"
+                                "arm,cci-400-pmu"  - DEPRECATED, permitted only where OS has
+                                                     secure acces to CCI registers
                - reg:
                        Usage: required
                        Value type: Integer cells. A register entry, expressed
diff --git a/arch/arm/include/asm/arm-cci.h b/arch/arm/include/asm/arm-cci.h
new file mode 100644 (file)
index 0000000..fe77f7a
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * arch/arm/include/asm/arm-cci.h
+ *
+ * Copyright (C) 2015 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_ARM_CCI_H
+#define __ASM_ARM_CCI_H
+
+#ifdef CONFIG_MCPM
+#include <asm/mcpm.h>
+
+/*
+ * We don't have a reliable way of detecting whether,
+ * if we have access to secure-only registers, unless
+ * mcpm is registered.
+ */
+static inline bool platform_has_secure_cci_access(void)
+{
+       return mcpm_is_available();
+}
+
+#else
+static inline bool platform_has_secure_cci_access(void)
+{
+       return false;
+}
+#endif
+
+#endif
diff --git a/arch/arm64/include/asm/arm-cci.h b/arch/arm64/include/asm/arm-cci.h
new file mode 100644 (file)
index 0000000..f0b6371
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * arch/arm64/include/asm/arm-cci.h
+ *
+ * Copyright (C) 2015 ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ASM_ARM_CCI_H
+#define __ASM_ARM_CCI_H
+
+static inline bool platform_has_secure_cci_access(void)
+{
+       return false;
+}
+
+#endif
index ae3864d95e6c8501ac6dbe4c8991ea69467729dc..a23663c7a306422b7373202be27fec17dae13b6e 100644 (file)
@@ -217,7 +217,9 @@ static int probe_cci_revision(void)
 
 static const struct cci_pmu_model *probe_cci_model(struct platform_device *pdev)
 {
-       return &cci_pmu_models[probe_cci_revision()];
+       if (platform_has_secure_cci_access())
+               return &cci_pmu_models[probe_cci_revision()];
+       return NULL;
 }
 
 static int pmu_is_valid_counter(struct cci_pmu *cci_pmu, int idx)
@@ -882,6 +884,15 @@ static struct cci_pmu_model cci_pmu_models[] = {
 static const struct of_device_id arm_cci_pmu_matches[] = {
        {
                .compatible = "arm,cci-400-pmu",
+               .data   = NULL,
+       },
+       {
+               .compatible = "arm,cci-400-pmu,r0",
+               .data   = &cci_pmu_models[CCI_REV_R0],
+       },
+       {
+               .compatible = "arm,cci-400-pmu,r1",
+               .data   = &cci_pmu_models[CCI_REV_R1],
        },
        {},
 };
@@ -892,7 +903,11 @@ static inline const struct cci_pmu_model *get_cci_model(struct platform_device *
                                                        pdev->dev.of_node);
        if (!match)
                return NULL;
+       if (match->data)
+               return match->data;
 
+       dev_warn(&pdev->dev, "DEPRECATED compatible property,"
+                        "requires secure access to CCI registers");
        return probe_cci_model(pdev);
 }
 
index 79d6edf446d513d22702ad093b7382ca8ab57b7d..aede5c765eec2b71bcc396b0583189a7cbd6eff5 100644 (file)
@@ -24,6 +24,8 @@
 #include <linux/errno.h>
 #include <linux/types.h>
 
+#include <asm/arm-cci.h>
+
 struct device_node;
 
 #ifdef CONFIG_ARM_CCI