Skip to content

Commit 772742a

Browse files
Suzuki K. Poulosewildea01
authored andcommitted
arm-cci: Get rid of secure transactions for PMU driver
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>
1 parent fc17c83 commit 772742a

5 files changed

Lines changed: 92 additions & 3 deletions

File tree

‎Documentation/devicetree/bindings/arm/cci.txt‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,11 @@ specific to ARM.
9494
- compatible
9595
Usage: required
9696
Value type: <string>
97-
Definition: must be "arm,cci-400-pmu"
98-
97+
Definition: Must contain one of:
98+
"arm,cci-400-pmu,r0"
99+
"arm,cci-400-pmu,r1"
100+
"arm,cci-400-pmu" - DEPRECATED, permitted only where OS has
101+
secure acces to CCI registers
99102
- reg:
100103
Usage: required
101104
Value type: Integer cells. A register entry, expressed

‎arch/arm/include/asm/arm-cci.h‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* arch/arm/include/asm/arm-cci.h
3+
*
4+
* Copyright (C) 2015 ARM Ltd.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef __ASM_ARM_CCI_H
20+
#define __ASM_ARM_CCI_H
21+
22+
#ifdef CONFIG_MCPM
23+
#include <asm/mcpm.h>
24+
25+
/*
26+
* We don't have a reliable way of detecting whether,
27+
* if we have access to secure-only registers, unless
28+
* mcpm is registered.
29+
*/
30+
static inline bool platform_has_secure_cci_access(void)
31+
{
32+
return mcpm_is_available();
33+
}
34+
35+
#else
36+
static inline bool platform_has_secure_cci_access(void)
37+
{
38+
return false;
39+
}
40+
#endif
41+
42+
#endif

‎arch/arm64/include/asm/arm-cci.h‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* arch/arm64/include/asm/arm-cci.h
3+
*
4+
* Copyright (C) 2015 ARM Ltd.
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef __ASM_ARM_CCI_H
20+
#define __ASM_ARM_CCI_H
21+
22+
static inline bool platform_has_secure_cci_access(void)
23+
{
24+
return false;
25+
}
26+
27+
#endif

‎drivers/bus/arm-cci.c‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ static int probe_cci_revision(void)
217217

218218
static const struct cci_pmu_model *probe_cci_model(struct platform_device *pdev)
219219
{
220-
return &cci_pmu_models[probe_cci_revision()];
220+
if (platform_has_secure_cci_access())
221+
return &cci_pmu_models[probe_cci_revision()];
222+
return NULL;
221223
}
222224

223225
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[] = {
882884
static const struct of_device_id arm_cci_pmu_matches[] = {
883885
{
884886
.compatible = "arm,cci-400-pmu",
887+
.data = NULL,
888+
},
889+
{
890+
.compatible = "arm,cci-400-pmu,r0",
891+
.data = &cci_pmu_models[CCI_REV_R0],
892+
},
893+
{
894+
.compatible = "arm,cci-400-pmu,r1",
895+
.data = &cci_pmu_models[CCI_REV_R1],
885896
},
886897
{},
887898
};
@@ -892,7 +903,11 @@ static inline const struct cci_pmu_model *get_cci_model(struct platform_device *
892903
pdev->dev.of_node);
893904
if (!match)
894905
return NULL;
906+
if (match->data)
907+
return match->data;
895908

909+
dev_warn(&pdev->dev, "DEPRECATED compatible property,"
910+
"requires secure access to CCI registers");
896911
return probe_cci_model(pdev);
897912
}
898913

‎include/linux/arm-cci.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#include <linux/errno.h>
2525
#include <linux/types.h>
2626

27+
#include <asm/arm-cci.h>
28+
2729
struct device_node;
2830

2931
#ifdef CONFIG_ARM_CCI

0 commit comments

Comments
 (0)