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
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
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>
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
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
36 +config KRAIT_L2_ACCESSORS
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
56 index 0000000..5d514bb
58 +++ b/arch/arm/common/krait-l2-accessors.c
61 + * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
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.
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.
73 +#include <linux/spinlock.h>
74 +#include <linux/export.h>
76 +#include <asm/barrier.h>
77 +#include <asm/krait-l2-accessors.h>
79 +static DEFINE_RAW_SPINLOCK(krait_l2_lock);
81 +void krait_set_l2_indirect_reg(u32 addr, u32 val)
83 + unsigned long flags;
85 + raw_spin_lock_irqsave(&krait_l2_lock, flags);
87 + * Select the L2 window by poking l2cpselr, then write to the window
90 + asm volatile ("mcr p15, 3, %0, c15, c0, 6 @ l2cpselr" : : "r" (addr));
92 + asm volatile ("mcr p15, 3, %0, c15, c0, 7 @ l2cpdr" : : "r" (val));
95 + raw_spin_unlock_irqrestore(&krait_l2_lock, flags);
97 +EXPORT_SYMBOL(krait_set_l2_indirect_reg);
99 +u32 krait_get_l2_indirect_reg(u32 addr)
102 + unsigned long flags;
104 + raw_spin_lock_irqsave(&krait_l2_lock, flags);
106 + * Select the L2 window by poking l2cpselr, then read from the window
109 + asm volatile ("mcr p15, 3, %0, c15, c0, 6 @ l2cpselr" : : "r" (addr));
111 + asm volatile ("mrc p15, 3, %0, c15, c0, 7 @ l2cpdr" : "=r" (val));
113 + raw_spin_unlock_irqrestore(&krait_l2_lock, flags);
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
120 index 0000000..48fe552
122 +++ b/arch/arm/include/asm/krait-l2-accessors.h
125 + * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
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.
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.
137 +#ifndef __ASMARM_KRAIT_L2_ACCESSORS_H
138 +#define __ASMARM_KRAIT_L2_ACCESSORS_H
140 +extern void krait_set_l2_indirect_reg(u32 addr, u32 val);
141 +extern u32 krait_get_l2_indirect_reg(u32 addr);