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