8c69b97cc4064f2b8d8371a2fc5055407e7489cb
[openwrt/openwrt.git] / target / linux / ipq806x / patches-4.9 / 0034-ARM-Add-Krait-L2-register-accessor-functions.patch
1 From 1d6b12f73c98ecf252743936a53242356cc50a34 Mon Sep 17 00:00:00 2001
2 From: Stephen Boyd <sboyd@codeaurora.org>
3 Date: Fri, 20 Mar 2015 23:45:20 -0700
4 Subject: [PATCH 34/69] 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 --- a/arch/arm/common/Kconfig
29 +++ b/arch/arm/common/Kconfig
30 @@ -9,6 +9,9 @@ config DMABOUNCE
31 bool
32 select ZONE_DMA
33
34 +config KRAIT_L2_ACCESSORS
35 + bool
36 +
37 config SHARP_LOCOMO
38 bool
39
40 --- a/arch/arm/common/Makefile
41 +++ b/arch/arm/common/Makefile
42 @@ -7,6 +7,7 @@ obj-y += firmware.o
43 obj-$(CONFIG_ICST) += icst.o
44 obj-$(CONFIG_SA1111) += sa1111.o
45 obj-$(CONFIG_DMABOUNCE) += dmabounce.o
46 +obj-$(CONFIG_KRAIT_L2_ACCESSORS) += krait-l2-accessors.o
47 obj-$(CONFIG_SHARP_LOCOMO) += locomo.o
48 obj-$(CONFIG_SHARP_PARAM) += sharpsl_param.o
49 obj-$(CONFIG_SHARP_SCOOP) += scoop.o
50 --- /dev/null
51 +++ b/arch/arm/common/krait-l2-accessors.c
52 @@ -0,0 +1,58 @@
53 +/*
54 + * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
55 + *
56 + * This program is free software; you can redistribute it and/or modify
57 + * it under the terms of the GNU General Public License version 2 and
58 + * only version 2 as published by the Free Software Foundation.
59 + *
60 + * This program is distributed in the hope that it will be useful,
61 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
62 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63 + * GNU General Public License for more details.
64 + */
65 +
66 +#include <linux/spinlock.h>
67 +#include <linux/export.h>
68 +
69 +#include <asm/barrier.h>
70 +#include <asm/krait-l2-accessors.h>
71 +
72 +static DEFINE_RAW_SPINLOCK(krait_l2_lock);
73 +
74 +void krait_set_l2_indirect_reg(u32 addr, u32 val)
75 +{
76 + unsigned long flags;
77 +
78 + raw_spin_lock_irqsave(&krait_l2_lock, flags);
79 + /*
80 + * Select the L2 window by poking l2cpselr, then write to the window
81 + * via l2cpdr.
82 + */
83 + asm volatile ("mcr p15, 3, %0, c15, c0, 6 @ l2cpselr" : : "r" (addr));
84 + isb();
85 + asm volatile ("mcr p15, 3, %0, c15, c0, 7 @ l2cpdr" : : "r" (val));
86 + isb();
87 +
88 + raw_spin_unlock_irqrestore(&krait_l2_lock, flags);
89 +}
90 +EXPORT_SYMBOL(krait_set_l2_indirect_reg);
91 +
92 +u32 krait_get_l2_indirect_reg(u32 addr)
93 +{
94 + u32 val;
95 + unsigned long flags;
96 +
97 + raw_spin_lock_irqsave(&krait_l2_lock, flags);
98 + /*
99 + * Select the L2 window by poking l2cpselr, then read from the window
100 + * via l2cpdr.
101 + */
102 + asm volatile ("mcr p15, 3, %0, c15, c0, 6 @ l2cpselr" : : "r" (addr));
103 + isb();
104 + asm volatile ("mrc p15, 3, %0, c15, c0, 7 @ l2cpdr" : "=r" (val));
105 +
106 + raw_spin_unlock_irqrestore(&krait_l2_lock, flags);
107 +
108 + return val;
109 +}
110 +EXPORT_SYMBOL(krait_get_l2_indirect_reg);
111 --- /dev/null
112 +++ b/arch/arm/include/asm/krait-l2-accessors.h
113 @@ -0,0 +1,20 @@
114 +/*
115 + * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
116 + *
117 + * This program is free software; you can redistribute it and/or modify
118 + * it under the terms of the GNU General Public License version 2 and
119 + * only version 2 as published by the Free Software Foundation.
120 + *
121 + * This program is distributed in the hope that it will be useful,
122 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
123 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124 + * GNU General Public License for more details.
125 + */
126 +
127 +#ifndef __ASMARM_KRAIT_L2_ACCESSORS_H
128 +#define __ASMARM_KRAIT_L2_ACCESSORS_H
129 +
130 +extern void krait_set_l2_indirect_reg(u32 addr, u32 val);
131 +extern u32 krait_get_l2_indirect_reg(u32 addr);
132 +
133 +#endif