01bd7497d11b6745f56d5266296f3e7ed1ba8b76
[openwrt/openwrt.git] / target / linux / ipq806x / patches-4.4 / 133-ARM-Add-Krait-L2-register-accessor-functions.patch
1 Content-Type: text/plain; charset="utf-8"
2 MIME-Version: 1.0
3 Content-Transfer-Encoding: 7bit
4 Subject: [v3,01/13] ARM: Add Krait L2 register accessor functions
5 From: Stephen Boyd <sboyd@codeaurora.org>
6 X-Patchwork-Id: 6063051
7 Message-Id: <1426920332-9340-2-git-send-email-sboyd@codeaurora.org>
8 To: Mike Turquette <mturquette@linaro.org>, Stephen Boyd <sboyd@codeaurora.org>
9 Cc: linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org,
10 linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
11 Viresh Kumar <viresh.kumar@linaro.org>,
12 Mark Rutland <mark.rutland@arm.com>, Russell King <linux@arm.linux.org.uk>,
13 Courtney Cavin <courtney.cavin@sonymobile.com>
14 Date: Fri, 20 Mar 2015 23:45:20 -0700
15
16 Krait CPUs have a handful of L2 cache controller registers that
17 live behind a cp15 based indirection register. First you program
18 the indirection register (l2cpselr) to point the L2 'window'
19 register (l2cpdr) at what you want to read/write. Then you
20 read/write the 'window' register to do what you want. The
21 l2cpselr register is not banked per-cpu so we must lock around
22 accesses to it to prevent other CPUs from re-pointing l2cpdr
23 underneath us.
24
25 Cc: Mark Rutland <mark.rutland@arm.com>
26 Cc: Russell King <linux@arm.linux.org.uk>
27 Cc: Courtney Cavin <courtney.cavin@sonymobile.com>
28 Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
29
30 ---
31 arch/arm/common/Kconfig | 3 ++
32 arch/arm/common/Makefile | 1 +
33 arch/arm/common/krait-l2-accessors.c | 58 +++++++++++++++++++++++++++++++
34 arch/arm/include/asm/krait-l2-accessors.h | 20 +++++++++++
35 4 files changed, 82 insertions(+)
36 create mode 100644 arch/arm/common/krait-l2-accessors.c
37 create mode 100644 arch/arm/include/asm/krait-l2-accessors.h
38
39 --- a/arch/arm/common/Kconfig
40 +++ b/arch/arm/common/Kconfig
41 @@ -9,6 +9,9 @@
42 bool
43 select ZONE_DMA
44
45 +config KRAIT_L2_ACCESSORS
46 + bool
47 +
48 config SHARP_LOCOMO
49 bool
50
51 --- a/arch/arm/common/Makefile
52 +++ b/arch/arm/common/Makefile
53 @@ -7,6 +7,7 @@
54 obj-$(CONFIG_ICST) += icst.o
55 obj-$(CONFIG_SA1111) += sa1111.o
56 obj-$(CONFIG_DMABOUNCE) += dmabounce.o
57 +obj-$(CONFIG_KRAIT_L2_ACCESSORS) += krait-l2-accessors.o
58 obj-$(CONFIG_SHARP_LOCOMO) += locomo.o
59 obj-$(CONFIG_SHARP_PARAM) += sharpsl_param.o
60 obj-$(CONFIG_SHARP_SCOOP) += scoop.o
61 --- /dev/null
62 +++ b/arch/arm/common/krait-l2-accessors.c
63 @@ -0,0 +1,58 @@
64 +/*
65 + * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
66 + *
67 + * This program is free software; you can redistribute it and/or modify
68 + * it under the terms of the GNU General Public License version 2 and
69 + * only version 2 as published by the Free Software Foundation.
70 + *
71 + * This program is distributed in the hope that it will be useful,
72 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
73 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74 + * GNU General Public License for more details.
75 + */
76 +
77 +#include <linux/spinlock.h>
78 +#include <linux/export.h>
79 +
80 +#include <asm/barrier.h>
81 +#include <asm/krait-l2-accessors.h>
82 +
83 +static DEFINE_RAW_SPINLOCK(krait_l2_lock);
84 +
85 +void krait_set_l2_indirect_reg(u32 addr, u32 val)
86 +{
87 + unsigned long flags;
88 +
89 + raw_spin_lock_irqsave(&krait_l2_lock, flags);
90 + /*
91 + * Select the L2 window by poking l2cpselr, then write to the window
92 + * via l2cpdr.
93 + */
94 + asm volatile ("mcr p15, 3, %0, c15, c0, 6 @ l2cpselr" : : "r" (addr));
95 + isb();
96 + asm volatile ("mcr p15, 3, %0, c15, c0, 7 @ l2cpdr" : : "r" (val));
97 + isb();
98 +
99 + raw_spin_unlock_irqrestore(&krait_l2_lock, flags);
100 +}
101 +EXPORT_SYMBOL(krait_set_l2_indirect_reg);
102 +
103 +u32 krait_get_l2_indirect_reg(u32 addr)
104 +{
105 + u32 val;
106 + unsigned long flags;
107 +
108 + raw_spin_lock_irqsave(&krait_l2_lock, flags);
109 + /*
110 + * Select the L2 window by poking l2cpselr, then read from the window
111 + * via l2cpdr.
112 + */
113 + asm volatile ("mcr p15, 3, %0, c15, c0, 6 @ l2cpselr" : : "r" (addr));
114 + isb();
115 + asm volatile ("mrc p15, 3, %0, c15, c0, 7 @ l2cpdr" : "=r" (val));
116 +
117 + raw_spin_unlock_irqrestore(&krait_l2_lock, flags);
118 +
119 + return val;
120 +}
121 +EXPORT_SYMBOL(krait_get_l2_indirect_reg);
122 --- /dev/null
123 +++ b/arch/arm/include/asm/krait-l2-accessors.h
124 @@ -0,0 +1,20 @@
125 +/*
126 + * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
127 + *
128 + * This program is free software; you can redistribute it and/or modify
129 + * it under the terms of the GNU General Public License version 2 and
130 + * only version 2 as published by the Free Software Foundation.
131 + *
132 + * This program is distributed in the hope that it will be useful,
133 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
134 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
135 + * GNU General Public License for more details.
136 + */
137 +
138 +#ifndef __ASMARM_KRAIT_L2_ACCESSORS_H
139 +#define __ASMARM_KRAIT_L2_ACCESSORS_H
140 +
141 +extern void krait_set_l2_indirect_reg(u32 addr, u32 val);
142 +extern u32 krait_get_l2_indirect_reg(u32 addr);
143 +
144 +#endif