aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-10-06 10:59:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-10-06 10:59:37 -0400
commit82fa407da081d05323171577d86f62d77df17465 (patch)
tree4fd548ec817dc41a69170bb64761ace9abc071f3
parentc7f5d36a3cc26e5068f4444aa22c4579e5eac85f (diff)
parent81a63001862f92d47c8c40a7fad870d5fbd8680b (diff)
Merge branch 'for-linus' of git://git.armlinux.org.uk/~rmk/linux-arm
Pull ARM updates from Russell King: - Correct ARMs dma-mapping to use the correct printk format strings. - Avoid defining OBJCOPYFLAGS globally which upsets lkdtm rodata testing. - Cleanups to ARMs asm/memory.h include. - L2 cache cleanups. - Allow flat nommu binaries to be executed on ARM MMU systems. - Kernel hardening - add more read-only after init annotations, including making some kernel vdso variables const. - Ensure AMBA primecell clocks are appropriately defaulted. - ARM breakpoint cleanup. - Various StrongARM 11x0 and companion chip (SA1111) updates to bring this legacy platform to use more modern APIs for (eg) GPIOs and interrupts, which will allow us in the future to reduce some of the board-level driver clutter and elimate function callbacks into board code via platform data. There still appears to be interest in these platforms! - Remove the now redundant secure_flush_area() API. - Module PLT relocation optimisations. Ard says: This series of 4 patches optimizes the ARM PLT generation code that is invoked at module load time, to get rid of the O(n^2) algorithm that results in pathological load times of 10 seconds or more for large modules on certain STB platforms. - ARMv7M cache maintanence support. - L2 cache PMU support * 'for-linus' of git://git.armlinux.org.uk/~rmk/linux-arm: (35 commits) ARM: sa1111: provide to_sa1111_device() macro ARM: sa1111: add sa1111_get_irq() ARM: sa1111: clean up duplication in IRQ chip implementation ARM: sa1111: implement a gpio_chip for SA1111 GPIOs ARM: sa1111: move irq cleanup to separate function ARM: sa1111: use devm_clk_get() ARM: sa1111: use devm_kzalloc() ARM: sa1111: ensure we only touch RAB bus type devices when removing ARM: 8611/1: l2x0: add PMU support ARM: 8610/1: V7M: Add dsb before jumping in handler mode ARM: 8609/1: V7M: Add support for the Cortex-M7 processor ARM: 8608/1: V7M: Indirect proc_info construction for V7M CPUs ARM: 8607/1: V7M: Wire up caches for V7M processors with cache support. ARM: 8606/1: V7M: introduce cache operations ARM: 8605/1: V7M: fix notrace variant of save_and_disable_irqs ARM: 8604/1: V7M: Add support for reading the CTR with read_cpuid_cachetype() ARM: 8603/1: V7M: Add addresses for mem-mapped V7M cache operations ARM: 8602/1: factor out CSSELR/CCSIDR operations that use cp15 directly ARM: kernel: avoid brute force search on PLT generation ARM: kernel: sort relocation sections before allocating PLTs ...
-rw-r--r--arch/arm/Makefile1
-rw-r--r--arch/arm/boot/Makefile2
-rw-r--r--arch/arm/common/sa1111.c434
-rw-r--r--arch/arm/include/asm/assembler.h4
-rw-r--r--arch/arm/include/asm/cacheflush.h17
-rw-r--r--arch/arm/include/asm/cachetype.h39
-rw-r--r--arch/arm/include/asm/cputype.h36
-rw-r--r--arch/arm/include/asm/flat.h5
-rw-r--r--arch/arm/include/asm/glue-cache.h4
-rw-r--r--arch/arm/include/asm/hardware/cache-l2x0.h19
-rw-r--r--arch/arm/include/asm/hardware/sa1111.h4
-rw-r--r--arch/arm/include/asm/hw_breakpoint.h1
-rw-r--r--arch/arm/include/asm/memory.h15
-rw-r--r--arch/arm/include/asm/module.h6
-rw-r--r--arch/arm/include/asm/v7m.h22
-rw-r--r--arch/arm/kernel/cpuidle.c2
-rw-r--r--arch/arm/kernel/head-nommu.S16
-rw-r--r--arch/arm/kernel/module-plts.c243
-rw-r--r--arch/arm/kernel/module.lds3
-rw-r--r--arch/arm/kernel/setup.c26
-rw-r--r--arch/arm/kernel/smp.c2
-rw-r--r--arch/arm/kernel/vdso.c11
-rw-r--r--arch/arm/lib/delay.c2
-rw-r--r--arch/arm/mach-footbridge/include/mach/hardware.h2
-rw-r--r--arch/arm/mach-rpc/include/mach/hardware.h2
-rw-r--r--arch/arm/mach-sa1100/include/mach/hardware.h20
-rw-r--r--arch/arm/mm/Kconfig17
-rw-r--r--arch/arm/mm/Makefile3
-rw-r--r--arch/arm/mm/cache-l2x0-pmu.c584
-rw-r--r--arch/arm/mm/cache-l2x0.c11
-rw-r--r--arch/arm/mm/cache-v7m.S453
-rw-r--r--arch/arm/mm/dma-mapping.c4
-rw-r--r--arch/arm/mm/mmu.c2
-rw-r--r--arch/arm/mm/proc-macros.S16
-rw-r--r--arch/arm/mm/proc-v7m.S108
-rw-r--r--drivers/amba/bus.c5
-rw-r--r--drivers/cpufreq/sa1110-cpufreq.c2
-rw-r--r--fs/Kconfig.binfmt2
-rw-r--r--include/linux/cpuhotplug.h1
39 files changed, 1752 insertions, 394 deletions
diff --git a/arch/arm/Makefile b/arch/arm/Makefile
index 61f6ccc19cfa..6be9ee148b78 100644
--- a/arch/arm/Makefile
+++ b/arch/arm/Makefile
@@ -23,7 +23,6 @@ ifeq ($(CONFIG_ARM_MODULE_PLTS),y)
23LDFLAGS_MODULE += -T $(srctree)/arch/arm/kernel/module.lds 23LDFLAGS_MODULE += -T $(srctree)/arch/arm/kernel/module.lds
24endif 24endif
25 25
26OBJCOPYFLAGS :=-O binary -R .comment -S
27GZFLAGS :=-9 26GZFLAGS :=-9
28#KBUILD_CFLAGS +=-pipe 27#KBUILD_CFLAGS +=-pipe
29 28
diff --git a/arch/arm/boot/Makefile b/arch/arm/boot/Makefile
index bdc1d5af03d2..50f8d1be7fcb 100644
--- a/arch/arm/boot/Makefile
+++ b/arch/arm/boot/Makefile
@@ -11,6 +11,8 @@
11# Copyright (C) 1995-2002 Russell King 11# Copyright (C) 1995-2002 Russell King
12# 12#
13 13
14OBJCOPYFLAGS :=-O binary -R .comment -S
15
14ifneq ($(MACHINE),) 16ifneq ($(MACHINE),)
15include $(MACHINE)/Makefile.boot 17include $(MACHINE)/Makefile.boot
16endif 18endif
diff --git a/arch/arm/common/sa1111.c b/arch/arm/common/sa1111.c
index 2e076c492005..4ecd5120fce7 100644
--- a/arch/arm/common/sa1111.c
+++ b/arch/arm/common/sa1111.c
@@ -15,6 +15,7 @@
15 * from machine specific code with proper arguments when required. 15 * from machine specific code with proper arguments when required.
16 */ 16 */
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/gpio/driver.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/irq.h> 20#include <linux/irq.h>
20#include <linux/kernel.h> 21#include <linux/kernel.h>
@@ -107,6 +108,7 @@ struct sa1111 {
107 spinlock_t lock; 108 spinlock_t lock;
108 void __iomem *base; 109 void __iomem *base;
109 struct sa1111_platform_data *pdata; 110 struct sa1111_platform_data *pdata;
111 struct gpio_chip gc;
110#ifdef CONFIG_PM 112#ifdef CONFIG_PM
111 void *saved_state; 113 void *saved_state;
112#endif 114#endif
@@ -231,132 +233,44 @@ static void sa1111_irq_handler(struct irq_desc *desc)
231#define SA1111_IRQMASK_LO(x) (1 << (x - sachip->irq_base)) 233#define SA1111_IRQMASK_LO(x) (1 << (x - sachip->irq_base))
232#define SA1111_IRQMASK_HI(x) (1 << (x - sachip->irq_base - 32)) 234#define SA1111_IRQMASK_HI(x) (1 << (x - sachip->irq_base - 32))
233 235
234static void sa1111_ack_irq(struct irq_data *d) 236static u32 sa1111_irqmask(struct irq_data *d)
235{
236}
237
238static void sa1111_mask_lowirq(struct irq_data *d)
239{ 237{
240 struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 238 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
241 void __iomem *mapbase = sachip->base + SA1111_INTC;
242 unsigned long ie0;
243 239
244 ie0 = sa1111_readl(mapbase + SA1111_INTEN0); 240 return BIT((d->irq - sachip->irq_base) & 31);
245 ie0 &= ~SA1111_IRQMASK_LO(d->irq);
246 writel(ie0, mapbase + SA1111_INTEN0);
247} 241}
248 242
249static void sa1111_unmask_lowirq(struct irq_data *d) 243static int sa1111_irqbank(struct irq_data *d)
250{ 244{
251 struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 245 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
252 void __iomem *mapbase = sachip->base + SA1111_INTC;
253 unsigned long ie0;
254
255 ie0 = sa1111_readl(mapbase + SA1111_INTEN0);
256 ie0 |= SA1111_IRQMASK_LO(d->irq);
257 sa1111_writel(ie0, mapbase + SA1111_INTEN0);
258}
259
260/*
261 * Attempt to re-trigger the interrupt. The SA1111 contains a register
262 * (INTSET) which claims to do this. However, in practice no amount of
263 * manipulation of INTEN and INTSET guarantees that the interrupt will
264 * be triggered. In fact, its very difficult, if not impossible to get
265 * INTSET to re-trigger the interrupt.
266 */
267static int sa1111_retrigger_lowirq(struct irq_data *d)
268{
269 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
270 void __iomem *mapbase = sachip->base + SA1111_INTC;
271 unsigned int mask = SA1111_IRQMASK_LO(d->irq);
272 unsigned long ip0;
273 int i;
274
275 ip0 = sa1111_readl(mapbase + SA1111_INTPOL0);
276 for (i = 0; i < 8; i++) {
277 sa1111_writel(ip0 ^ mask, mapbase + SA1111_INTPOL0);
278 sa1111_writel(ip0, mapbase + SA1111_INTPOL0);
279 if (sa1111_readl(mapbase + SA1111_INTSTATCLR0) & mask)
280 break;
281 }
282 246
283 if (i == 8) 247 return ((d->irq - sachip->irq_base) / 32) * 4;
284 pr_err("Danger Will Robinson: failed to re-trigger IRQ%d\n",
285 d->irq);
286 return i == 8 ? -1 : 0;
287} 248}
288 249
289static int sa1111_type_lowirq(struct irq_data *d, unsigned int flags) 250static void sa1111_ack_irq(struct irq_data *d)
290{
291 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
292 void __iomem *mapbase = sachip->base + SA1111_INTC;
293 unsigned int mask = SA1111_IRQMASK_LO(d->irq);
294 unsigned long ip0;
295
296 if (flags == IRQ_TYPE_PROBE)
297 return 0;
298
299 if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0)
300 return -EINVAL;
301
302 ip0 = sa1111_readl(mapbase + SA1111_INTPOL0);
303 if (flags & IRQ_TYPE_EDGE_RISING)
304 ip0 &= ~mask;
305 else
306 ip0 |= mask;
307 sa1111_writel(ip0, mapbase + SA1111_INTPOL0);
308 sa1111_writel(ip0, mapbase + SA1111_WAKEPOL0);
309
310 return 0;
311}
312
313static int sa1111_wake_lowirq(struct irq_data *d, unsigned int on)
314{ 251{
315 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
316 void __iomem *mapbase = sachip->base + SA1111_INTC;
317 unsigned int mask = SA1111_IRQMASK_LO(d->irq);
318 unsigned long we0;
319
320 we0 = sa1111_readl(mapbase + SA1111_WAKEEN0);
321 if (on)
322 we0 |= mask;
323 else
324 we0 &= ~mask;
325 sa1111_writel(we0, mapbase + SA1111_WAKEEN0);
326
327 return 0;
328} 252}
329 253
330static struct irq_chip sa1111_low_chip = { 254static void sa1111_mask_irq(struct irq_data *d)
331 .name = "SA1111-l",
332 .irq_ack = sa1111_ack_irq,
333 .irq_mask = sa1111_mask_lowirq,
334 .irq_unmask = sa1111_unmask_lowirq,
335 .irq_retrigger = sa1111_retrigger_lowirq,
336 .irq_set_type = sa1111_type_lowirq,
337 .irq_set_wake = sa1111_wake_lowirq,
338};
339
340static void sa1111_mask_highirq(struct irq_data *d)
341{ 255{
342 struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 256 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
343 void __iomem *mapbase = sachip->base + SA1111_INTC; 257 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d);
344 unsigned long ie1; 258 u32 ie;
345 259
346 ie1 = sa1111_readl(mapbase + SA1111_INTEN1); 260 ie = sa1111_readl(mapbase + SA1111_INTEN0);
347 ie1 &= ~SA1111_IRQMASK_HI(d->irq); 261 ie &= ~sa1111_irqmask(d);
348 sa1111_writel(ie1, mapbase + SA1111_INTEN1); 262 sa1111_writel(ie, mapbase + SA1111_INTEN0);
349} 263}
350 264
351static void sa1111_unmask_highirq(struct irq_data *d) 265static void sa1111_unmask_irq(struct irq_data *d)
352{ 266{
353 struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 267 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
354 void __iomem *mapbase = sachip->base + SA1111_INTC; 268 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d);
355 unsigned long ie1; 269 u32 ie;
356 270
357 ie1 = sa1111_readl(mapbase + SA1111_INTEN1); 271 ie = sa1111_readl(mapbase + SA1111_INTEN0);
358 ie1 |= SA1111_IRQMASK_HI(d->irq); 272 ie |= sa1111_irqmask(d);
359 sa1111_writel(ie1, mapbase + SA1111_INTEN1); 273 sa1111_writel(ie, mapbase + SA1111_INTEN0);
360} 274}
361 275
362/* 276/*
@@ -366,19 +280,18 @@ static void sa1111_unmask_highirq(struct irq_data *d)
366 * be triggered. In fact, its very difficult, if not impossible to get 280 * be triggered. In fact, its very difficult, if not impossible to get
367 * INTSET to re-trigger the interrupt. 281 * INTSET to re-trigger the interrupt.
368 */ 282 */
369static int sa1111_retrigger_highirq(struct irq_data *d) 283static int sa1111_retrigger_irq(struct irq_data *d)
370{ 284{
371 struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 285 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
372 void __iomem *mapbase = sachip->base + SA1111_INTC; 286 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d);
373 unsigned int mask = SA1111_IRQMASK_HI(d->irq); 287 u32 ip, mask = sa1111_irqmask(d);
374 unsigned long ip1;
375 int i; 288 int i;
376 289
377 ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); 290 ip = sa1111_readl(mapbase + SA1111_INTPOL0);
378 for (i = 0; i < 8; i++) { 291 for (i = 0; i < 8; i++) {
379 sa1111_writel(ip1 ^ mask, mapbase + SA1111_INTPOL1); 292 sa1111_writel(ip ^ mask, mapbase + SA1111_INTPOL0);
380 sa1111_writel(ip1, mapbase + SA1111_INTPOL1); 293 sa1111_writel(ip, mapbase + SA1111_INTPOL0);
381 if (sa1111_readl(mapbase + SA1111_INTSTATCLR1) & mask) 294 if (sa1111_readl(mapbase + SA1111_INTSTATCLR0) & mask)
382 break; 295 break;
383 } 296 }
384 297
@@ -388,12 +301,11 @@ static int sa1111_retrigger_highirq(struct irq_data *d)
388 return i == 8 ? -1 : 0; 301 return i == 8 ? -1 : 0;
389} 302}
390 303
391static int sa1111_type_highirq(struct irq_data *d, unsigned int flags) 304static int sa1111_type_irq(struct irq_data *d, unsigned int flags)
392{ 305{
393 struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 306 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
394 void __iomem *mapbase = sachip->base + SA1111_INTC; 307 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d);
395 unsigned int mask = SA1111_IRQMASK_HI(d->irq); 308 u32 ip, mask = sa1111_irqmask(d);
396 unsigned long ip1;
397 309
398 if (flags == IRQ_TYPE_PROBE) 310 if (flags == IRQ_TYPE_PROBE)
399 return 0; 311 return 0;
@@ -401,42 +313,41 @@ static int sa1111_type_highirq(struct irq_data *d, unsigned int flags)
401 if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0) 313 if ((!(flags & IRQ_TYPE_EDGE_RISING) ^ !(flags & IRQ_TYPE_EDGE_FALLING)) == 0)
402 return -EINVAL; 314 return -EINVAL;
403 315
404 ip1 = sa1111_readl(mapbase + SA1111_INTPOL1); 316 ip = sa1111_readl(mapbase + SA1111_INTPOL0);
405 if (flags & IRQ_TYPE_EDGE_RISING) 317 if (flags & IRQ_TYPE_EDGE_RISING)
406 ip1 &= ~mask; 318 ip &= ~mask;
407 else 319 else
408 ip1 |= mask; 320 ip |= mask;
409 sa1111_writel(ip1, mapbase + SA1111_INTPOL1); 321 sa1111_writel(ip, mapbase + SA1111_INTPOL0);
410 sa1111_writel(ip1, mapbase + SA1111_WAKEPOL1); 322 sa1111_writel(ip, mapbase + SA1111_WAKEPOL0);
411 323
412 return 0; 324 return 0;
413} 325}
414 326
415static int sa1111_wake_highirq(struct irq_data *d, unsigned int on) 327static int sa1111_wake_irq(struct irq_data *d, unsigned int on)
416{ 328{
417 struct sa1111 *sachip = irq_data_get_irq_chip_data(d); 329 struct sa1111 *sachip = irq_data_get_irq_chip_data(d);
418 void __iomem *mapbase = sachip->base + SA1111_INTC; 330 void __iomem *mapbase = sachip->base + SA1111_INTC + sa1111_irqbank(d);
419 unsigned int mask = SA1111_IRQMASK_HI(d->irq); 331 u32 we, mask = sa1111_irqmask(d);
420 unsigned long we1;
421 332
422 we1 = sa1111_readl(mapbase + SA1111_WAKEEN1); 333 we = sa1111_readl(mapbase + SA1111_WAKEEN0);
423 if (on) 334 if (on)
424 we1 |= mask; 335 we |= mask;
425 else 336 else
426 we1 &= ~mask; 337 we &= ~mask;
427 sa1111_writel(we1, mapbase + SA1111_WAKEEN1); 338 sa1111_writel(we, mapbase + SA1111_WAKEEN0);
428 339
429 return 0; 340 return 0;
430} 341}
431 342
432static struct irq_chip sa1111_high_chip = { 343static struct irq_chip sa1111_irq_chip = {
433 .name = "SA1111-h", 344 .name = "SA1111",
434 .irq_ack = sa1111_ack_irq, 345 .irq_ack = sa1111_ack_irq,
435 .irq_mask = sa1111_mask_highirq, 346 .irq_mask = sa1111_mask_irq,
436 .irq_unmask = sa1111_unmask_highirq, 347 .irq_unmask = sa1111_unmask_irq,
437 .irq_retrigger = sa1111_retrigger_highirq, 348 .irq_retrigger = sa1111_retrigger_irq,
438 .irq_set_type = sa1111_type_highirq, 349 .irq_set_type = sa1111_type_irq,
439 .irq_set_wake = sa1111_wake_highirq, 350 .irq_set_wake = sa1111_wake_irq,
440}; 351};
441 352
442static int sa1111_setup_irq(struct sa1111 *sachip, unsigned irq_base) 353static int sa1111_setup_irq(struct sa1111 *sachip, unsigned irq_base)
@@ -482,16 +393,14 @@ static int sa1111_setup_irq(struct sa1111 *sachip, unsigned irq_base)
482 393
483 for (i = IRQ_GPAIN0; i <= SSPROR; i++) { 394 for (i = IRQ_GPAIN0; i <= SSPROR; i++) {
484 irq = sachip->irq_base + i; 395 irq = sachip->irq_base + i;
485 irq_set_chip_and_handler(irq, &sa1111_low_chip, 396 irq_set_chip_and_handler(irq, &sa1111_irq_chip, handle_edge_irq);
486 handle_edge_irq);
487 irq_set_chip_data(irq, sachip); 397 irq_set_chip_data(irq, sachip);
488 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE); 398 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
489 } 399 }
490 400
491 for (i = AUDXMTDMADONEA; i <= IRQ_S1_BVD1_STSCHG; i++) { 401 for (i = AUDXMTDMADONEA; i <= IRQ_S1_BVD1_STSCHG; i++) {
492 irq = sachip->irq_base + i; 402 irq = sachip->irq_base + i;
493 irq_set_chip_and_handler(irq, &sa1111_high_chip, 403 irq_set_chip_and_handler(irq, &sa1111_irq_chip, handle_edge_irq);
494 handle_edge_irq);
495 irq_set_chip_data(irq, sachip); 404 irq_set_chip_data(irq, sachip);
496 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE); 405 irq_clear_status_flags(irq, IRQ_NOREQUEST | IRQ_NOPROBE);
497 } 406 }
@@ -509,6 +418,181 @@ static int sa1111_setup_irq(struct sa1111 *sachip, unsigned irq_base)
509 return 0; 418 return 0;
510} 419}
511 420
421static void sa1111_remove_irq(struct sa1111 *sachip)
422{
423 void __iomem *irqbase = sachip->base + SA1111_INTC;
424
425 /* disable all IRQs */
426 sa1111_writel(0, irqbase + SA1111_INTEN0);
427 sa1111_writel(0, irqbase + SA1111_INTEN1);
428 sa1111_writel(0, irqbase + SA1111_WAKEEN0);
429 sa1111_writel(0, irqbase + SA1111_WAKEEN1);
430
431 if (sachip->irq != NO_IRQ) {
432 irq_set_chained_handler_and_data(sachip->irq, NULL, NULL);
433 irq_free_descs(sachip->irq_base, SA1111_IRQ_NR);
434
435 release_mem_region(sachip->phys + SA1111_INTC, 512);
436 }
437}
438
439enum {
440 SA1111_GPIO_PXDDR = (SA1111_GPIO_PADDR - SA1111_GPIO_PADDR),
441 SA1111_GPIO_PXDRR = (SA1111_GPIO_PADRR - SA1111_GPIO_PADDR),
442 SA1111_GPIO_PXDWR = (SA1111_GPIO_PADWR - SA1111_GPIO_PADDR),
443 SA1111_GPIO_PXSDR = (SA1111_GPIO_PASDR - SA1111_GPIO_PADDR),
444 SA1111_GPIO_PXSSR = (SA1111_GPIO_PASSR - SA1111_GPIO_PADDR),
445};
446
447static struct sa1111 *gc_to_sa1111(struct gpio_chip *gc)
448{
449 return container_of(gc, struct sa1111, gc);
450}
451
452static void __iomem *sa1111_gpio_map_reg(struct sa1111 *sachip, unsigned offset)
453{
454 void __iomem *reg = sachip->base + SA1111_GPIO;
455
456 if (offset < 4)
457 return reg + SA1111_GPIO_PADDR;
458 if (offset < 10)
459 return reg + SA1111_GPIO_PBDDR;
460 if (offset < 18)
461 return reg + SA1111_GPIO_PCDDR;
462 return NULL;
463}
464
465static u32 sa1111_gpio_map_bit(unsigned offset)
466{
467 if (offset < 4)
468 return BIT(offset);
469 if (offset < 10)
470 return BIT(offset - 4);
471 if (offset < 18)
472 return BIT(offset - 10);
473 return 0;
474}
475
476static void sa1111_gpio_modify(void __iomem *reg, u32 mask, u32 set)
477{
478 u32 val;
479
480 val = readl_relaxed(reg);
481 val &= ~mask;
482 val |= mask & set;
483 writel_relaxed(val, reg);
484}
485
486static int sa1111_gpio_get_direction(struct gpio_chip *gc, unsigned offset)
487{
488 struct sa1111 *sachip = gc_to_sa1111(gc);
489 void __iomem *reg = sa1111_gpio_map_reg(sachip, offset);
490 u32 mask = sa1111_gpio_map_bit(offset);
491
492 return !!(readl_relaxed(reg + SA1111_GPIO_PXDDR) & mask);
493}
494
495static int sa1111_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
496{
497 struct sa1111 *sachip = gc_to_sa1111(gc);
498 unsigned long flags;
499 void __iomem *reg = sa1111_gpio_map_reg(sachip, offset);
500 u32 mask = sa1111_gpio_map_bit(offset);
501
502 spin_lock_irqsave(&sachip->lock, flags);
503 sa1111_gpio_modify(reg + SA1111_GPIO_PXDDR, mask, mask);
504 sa1111_gpio_modify(reg + SA1111_GPIO_PXSDR, mask, mask);
505 spin_unlock_irqrestore(&sachip->lock, flags);
506
507 return 0;
508}
509
510static int sa1111_gpio_direction_output(struct gpio_chip *gc, unsigned offset,
511 int value)
512{
513 struct sa1111 *sachip = gc_to_sa1111(gc);
514 unsigned long flags;
515 void __iomem *reg = sa1111_gpio_map_reg(sachip, offset);
516 u32 mask = sa1111_gpio_map_bit(offset);
517
518 spin_lock_irqsave(&sachip->lock, flags);
519 sa1111_gpio_modify(reg + SA1111_GPIO_PXDWR, mask, value ? mask : 0);
520 sa1111_gpio_modify(reg + SA1111_GPIO_PXSSR, mask, value ? mask : 0);
521 sa1111_gpio_modify(reg + SA1111_GPIO_PXDDR, mask, 0);
522 sa1111_gpio_modify(reg + SA1111_GPIO_PXSDR, mask, 0);
523 spin_unlock_irqrestore(&sachip->lock, flags);
524
525 return 0;
526}
527
528static int sa1111_gpio_get(struct gpio_chip *gc, unsigned offset)
529{
530 struct sa1111 *sachip = gc_to_sa1111(gc);
531 void __iomem *reg = sa1111_gpio_map_reg(sachip, offset);
532 u32 mask = sa1111_gpio_map_bit(offset);
533
534 return !!(readl_relaxed(reg + SA1111_GPIO_PXDRR) & mask);
535}
536
537static void sa1111_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
538{
539 struct sa1111 *sachip = gc_to_sa1111(gc);
540 unsigned long flags;
541 void __iomem *reg = sa1111_gpio_map_reg(sachip, offset);
542 u32 mask = sa1111_gpio_map_bit(offset);
543
544 spin_lock_irqsave(&sachip->lock, flags);
545 sa1111_gpio_modify(reg + SA1111_GPIO_PXDWR, mask, value ? mask : 0);
546 sa1111_gpio_modify(reg + SA1111_GPIO_PXSSR, mask, value ? mask : 0);
547 spin_unlock_irqrestore(&sachip->lock, flags);
548}
549
550static void sa1111_gpio_set_multiple(struct gpio_chip *gc, unsigned long *mask,
551 unsigned long *bits)
552{
553 struct sa1111 *sachip = gc_to_sa1111(gc);
554 unsigned long flags;
555 void __iomem *reg = sachip->base + SA1111_GPIO;
556 u32 msk, val;
557
558 msk = *mask;
559 val = *bits;
560
561 spin_lock_irqsave(&sachip->lock, flags);
562 sa1111_gpio_modify(reg + SA1111_GPIO_PADWR, msk & 15, val);
563 sa1111_gpio_modify(reg + SA1111_GPIO_PASSR, msk & 15, val);
564 sa1111_gpio_modify(reg + SA1111_GPIO_PBDWR, (msk >> 4) & 255, val >> 4);
565 sa1111_gpio_modify(reg + SA1111_GPIO_PBSSR, (msk >> 4) & 255, val >> 4);
566 sa1111_gpio_modify(reg + SA1111_GPIO_PCDWR, (msk >> 12) & 255, val >> 12);
567 sa1111_gpio_modify(reg + SA1111_GPIO_PCSSR, (msk >> 12) & 255, val >> 12);
568 spin_unlock_irqrestore(&sachip->lock, flags);
569}
570
571static int sa1111_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
572{
573 struct sa1111 *sachip = gc_to_sa1111(gc);
574
575 return sachip->irq_base + offset;
576}
577
578static int sa1111_setup_gpios(struct sa1111 *sachip)
579{
580 sachip->gc.label = "sa1111";
581 sachip->gc.parent = sachip->dev;
582 sachip->gc.owner = THIS_MODULE;
583 sachip->gc.get_direction = sa1111_gpio_get_direction;
584 sachip->gc.direction_input = sa1111_gpio_direction_input;
585 sachip->gc.direction_output = sa1111_gpio_direction_output;
586 sachip->gc.get = sa1111_gpio_get;
587 sachip->gc.set = sa1111_gpio_set;
588 sachip->gc.set_multiple = sa1111_gpio_set_multiple;
589 sachip->gc.to_irq = sa1111_gpio_to_irq;
590 sachip->gc.base = -1;
591 sachip->gc.ngpio = 18;
592
593 return devm_gpiochip_add_data(sachip->dev, &sachip->gc, sachip);
594}
595
512/* 596/*
513 * Bring the SA1111 out of reset. This requires a set procedure: 597 * Bring the SA1111 out of reset. This requires a set procedure:
514 * 1. nRESET asserted (by hardware) 598 * 1. nRESET asserted (by hardware)
@@ -607,7 +691,7 @@ sa1111_configure_smc(struct sa1111 *sachip, int sdram, unsigned int drac,
607 691
608static void sa1111_dev_release(struct device *_dev) 692static void sa1111_dev_release(struct device *_dev)
609{ 693{
610 struct sa1111_dev *dev = SA1111_DEV(_dev); 694 struct sa1111_dev *dev = to_sa1111_device(_dev);
611 695
612 kfree(dev); 696 kfree(dev);
613} 697}
@@ -696,19 +780,17 @@ static int __sa1111_probe(struct device *me, struct resource *mem, int irq)
696 if (!pd) 780 if (!pd)
697 return -EINVAL; 781 return -EINVAL;
698 782
699 sachip = kzalloc(sizeof(struct sa1111), GFP_KERNEL); 783 sachip = devm_kzalloc(me, sizeof(struct sa1111), GFP_KERNEL);
700 if (!sachip) 784 if (!sachip)
701 return -ENOMEM; 785 return -ENOMEM;
702 786
703 sachip->clk = clk_get(me, "SA1111_CLK"); 787 sachip->clk = devm_clk_get(me, "SA1111_CLK");
704 if (IS_ERR(sachip->clk)) { 788 if (IS_ERR(sachip->clk))
705 ret = PTR_ERR(sachip->clk); 789 return PTR_ERR(sachip->clk);
706 goto err_free;
707 }
708 790
709 ret = clk_prepare(sachip->clk); 791 ret = clk_prepare(sachip->clk);
710 if (ret) 792 if (ret)
711 goto err_clkput; 793 return ret;
712 794
713 spin_lock_init(&sachip->lock); 795 spin_lock_init(&sachip->lock);
714 796
@@ -757,6 +839,11 @@ static int __sa1111_probe(struct device *me, struct resource *mem, int irq)
757 goto err_clk; 839 goto err_clk;
758 } 840 }
759 841
842 /* Setup the GPIOs - should really be done after the IRQ setup */
843 ret = sa1111_setup_gpios(sachip);
844 if (ret)
845 goto err_irq;
846
760#ifdef CONFIG_ARCH_SA1100 847#ifdef CONFIG_ARCH_SA1100
761 { 848 {
762 unsigned int val; 849 unsigned int val;
@@ -799,22 +886,22 @@ static int __sa1111_probe(struct device *me, struct resource *mem, int irq)
799 886
800 return 0; 887 return 0;
801 888
889 err_irq:
890 sa1111_remove_irq(sachip);
802 err_clk: 891 err_clk:
803 clk_disable(sachip->clk); 892 clk_disable(sachip->clk);
804 err_unmap: 893 err_unmap:
805 iounmap(sachip->base); 894 iounmap(sachip->base);
806 err_clk_unprep: 895 err_clk_unprep:
807 clk_unprepare(sachip->clk); 896 clk_unprepare(sachip->clk);
808 err_clkput:
809 clk_put(sachip->clk);
810 err_free:
811 kfree(sachip);
812 return ret; 897 return ret;
813} 898}
814 899
815static int sa1111_remove_one(struct device *dev, void *data) 900static int sa1111_remove_one(struct device *dev, void *data)
816{ 901{
817 struct sa1111_dev *sadev = SA1111_DEV(dev); 902 struct sa1111_dev *sadev = to_sa1111_device(dev);
903 if (dev->bus != &sa1111_bus_type)
904 return 0;
818 device_del(&sadev->dev); 905 device_del(&sadev->dev);
819 release_resource(&sadev->res); 906 release_resource(&sadev->res);
820 put_device(&sadev->dev); 907 put_device(&sadev->dev);
@@ -823,29 +910,14 @@ static int sa1111_remove_one(struct device *dev, void *data)
823 910
824static void __sa1111_remove(struct sa1111 *sachip) 911static void __sa1111_remove(struct sa1111 *sachip)
825{ 912{
826 void __iomem *irqbase = sachip->base + SA1111_INTC;
827
828 device_for_each_child(sachip->dev, NULL, sa1111_remove_one); 913 device_for_each_child(sachip->dev, NULL, sa1111_remove_one);
829 914
830 /* disable all IRQs */ 915 sa1111_remove_irq(sachip);
831 sa1111_writel(0, irqbase + SA1111_INTEN0);
832 sa1111_writel(0, irqbase + SA1111_INTEN1);
833 sa1111_writel(0, irqbase + SA1111_WAKEEN0);
834 sa1111_writel(0, irqbase + SA1111_WAKEEN1);
835 916
836 clk_disable(sachip->clk); 917 clk_disable(sachip->clk);
837 clk_unprepare(sachip->clk); 918 clk_unprepare(sachip->clk);
838 919
839 if (sachip->irq != NO_IRQ) {
840 irq_set_chained_handler_and_data(sachip->irq, NULL, NULL);
841 irq_free_descs(sachip->irq_base, SA1111_IRQ_NR);
842
843 release_mem_region(sachip->phys + SA1111_INTC, 512);
844 }
845
846 iounmap(sachip->base); 920 iounmap(sachip->base);
847 clk_put(sachip->clk);
848 kfree(sachip);
849} 921}
850 922
851struct sa1111_save_data { 923struct sa1111_save_data {
@@ -1285,6 +1357,14 @@ void sa1111_disable_device(struct sa1111_dev *sadev)
1285} 1357}
1286EXPORT_SYMBOL(sa1111_disable_device); 1358EXPORT_SYMBOL(sa1111_disable_device);
1287 1359
1360int sa1111_get_irq(struct sa1111_dev *sadev, unsigned num)
1361{
1362 if (num >= ARRAY_SIZE(sadev->irq))
1363 return -EINVAL;
1364 return sadev->irq[num];
1365}
1366EXPORT_SYMBOL_GPL(sa1111_get_irq);
1367
1288/* 1368/*
1289 * SA1111 "Register Access Bus." 1369 * SA1111 "Register Access Bus."
1290 * 1370 *
@@ -1293,7 +1373,7 @@ EXPORT_SYMBOL(sa1111_disable_device);
1293 */ 1373 */
1294static int sa1111_match(struct device *_dev, struct device_driver *_drv) 1374static int sa1111_match(struct device *_dev, struct device_driver *_drv)
1295{ 1375{
1296 struct sa1111_dev *dev = SA1111_DEV(_dev); 1376 struct sa1111_dev *dev = to_sa1111_device(_dev);
1297 struct sa1111_driver *drv = SA1111_DRV(_drv); 1377 struct sa1111_driver *drv = SA1111_DRV(_drv);
1298 1378
1299 return !!(dev->devid & drv->devid); 1379 return !!(dev->devid & drv->devid);
@@ -1301,7 +1381,7 @@ static int sa1111_match(struct device *_dev, struct device_driver *_drv)
1301 1381
1302static int sa1111_bus_suspend(struct device *dev, pm_message_t state) 1382static int sa1111_bus_suspend(struct device *dev, pm_message_t state)
1303{ 1383{
1304 struct sa1111_dev *sadev = SA1111_DEV(dev); 1384 struct sa1111_dev *sadev = to_sa1111_device(dev);
1305 struct sa1111_driver *drv = SA1111_DRV(dev->driver); 1385 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1306 int ret = 0; 1386 int ret = 0;
1307 1387
@@ -1312,7 +1392,7 @@ static int sa1111_bus_suspend(struct device *dev, pm_message_t state)
1312 1392
1313static int sa1111_bus_resume(struct device *dev) 1393static int sa1111_bus_resume(struct device *dev)
1314{ 1394{
1315 struct sa1111_dev *sadev = SA1111_DEV(dev); 1395 struct sa1111_dev *sadev = to_sa1111_device(dev);
1316 struct sa1111_driver *drv = SA1111_DRV(dev->driver); 1396 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1317 int ret = 0; 1397 int ret = 0;
1318 1398
@@ -1326,12 +1406,12 @@ static void sa1111_bus_shutdown(struct device *dev)
1326 struct sa1111_driver *drv = SA1111_DRV(dev->driver); 1406 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1327 1407
1328 if (drv && drv->shutdown) 1408 if (drv && drv->shutdown)
1329 drv->shutdown(SA1111_DEV(dev)); 1409 drv->shutdown(to_sa1111_device(dev));
1330} 1410}
1331 1411
1332static int sa1111_bus_probe(struct device *dev) 1412static int sa1111_bus_probe(struct device *dev)
1333{ 1413{
1334 struct sa1111_dev *sadev = SA1111_DEV(dev); 1414 struct sa1111_dev *sadev = to_sa1111_device(dev);
1335 struct sa1111_driver *drv = SA1111_DRV(dev->driver); 1415 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1336 int ret = -ENODEV; 1416 int ret = -ENODEV;
1337 1417
@@ -1342,7 +1422,7 @@ static int sa1111_bus_probe(struct device *dev)
1342 1422
1343static int sa1111_bus_remove(struct device *dev) 1423static int sa1111_bus_remove(struct device *dev)
1344{ 1424{
1345 struct sa1111_dev *sadev = SA1111_DEV(dev); 1425 struct sa1111_dev *sadev = to_sa1111_device(dev);
1346 struct sa1111_driver *drv = SA1111_DRV(dev->driver); 1426 struct sa1111_driver *drv = SA1111_DRV(dev->driver);
1347 int ret = 0; 1427 int ret = 0;
1348 1428
@@ -1407,7 +1487,7 @@ static int sa1111_needs_bounce(struct device *dev, dma_addr_t addr, size_t size)
1407static int sa1111_notifier_call(struct notifier_block *n, unsigned long action, 1487static int sa1111_notifier_call(struct notifier_block *n, unsigned long action,
1408 void *data) 1488 void *data)
1409{ 1489{
1410 struct sa1111_dev *dev = SA1111_DEV(data); 1490 struct sa1111_dev *dev = to_sa1111_device(data);
1411 1491
1412 switch (action) { 1492 switch (action) {
1413 case BUS_NOTIFY_ADD_DEVICE: 1493 case BUS_NOTIFY_ADD_DEVICE:
diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h
index 4eaea2173bf8..68b06f9c65de 100644
--- a/arch/arm/include/asm/assembler.h
+++ b/arch/arm/include/asm/assembler.h
@@ -159,7 +159,11 @@
159 .endm 159 .endm
160 160
161 .macro save_and_disable_irqs_notrace, oldcpsr 161 .macro save_and_disable_irqs_notrace, oldcpsr
162#ifdef CONFIG_CPU_V7M
163 mrs \oldcpsr, primask
164#else
162 mrs \oldcpsr, cpsr 165 mrs \oldcpsr, cpsr
166#endif
163 disable_irq_notrace 167 disable_irq_notrace
164 .endm 168 .endm
165 169
diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
index 9156fc303afd..bdd283bc5842 100644
--- a/arch/arm/include/asm/cacheflush.h
+++ b/arch/arm/include/asm/cacheflush.h
@@ -501,21 +501,4 @@ static inline void set_kernel_text_ro(void) { }
501void flush_uprobe_xol_access(struct page *page, unsigned long uaddr, 501void flush_uprobe_xol_access(struct page *page, unsigned long uaddr,
502 void *kaddr, unsigned long len); 502 void *kaddr, unsigned long len);
503 503
504/**
505 * secure_flush_area - ensure coherency across the secure boundary
506 * @addr: virtual address
507 * @size: size of region
508 *
509 * Ensure that the specified area of memory is coherent across the secure
510 * boundary from the non-secure side. This is used when calling secure
511 * firmware where the secure firmware does not ensure coherency.
512 */
513static inline void secure_flush_area(const void *addr, size_t size)
514{
515 phys_addr_t phys = __pa(addr);
516
517 __cpuc_flush_dcache_area((void *)addr, size);
518 outer_flush_range(phys, phys + size);
519}
520
521#endif 504#endif
diff --git a/arch/arm/include/asm/cachetype.h b/arch/arm/include/asm/cachetype.h
index 7ea78144ae22..01509ae0bbec 100644
--- a/arch/arm/include/asm/cachetype.h
+++ b/arch/arm/include/asm/cachetype.h
@@ -56,4 +56,43 @@ static inline unsigned int __attribute__((pure)) cacheid_is(unsigned int mask)
56 (~__CACHEID_NEVER & __CACHEID_ARCH_MIN & mask & cacheid); 56 (~__CACHEID_NEVER & __CACHEID_ARCH_MIN & mask & cacheid);
57} 57}
58 58
59#define CSSELR_ICACHE 1
60#define CSSELR_DCACHE 0
61
62#define CSSELR_L1 (0 << 1)
63#define CSSELR_L2 (1 << 1)
64#define CSSELR_L3 (2 << 1)
65#define CSSELR_L4 (3 << 1)
66#define CSSELR_L5 (4 << 1)
67#define CSSELR_L6 (5 << 1)
68#define CSSELR_L7 (6 << 1)
69
70#ifndef CONFIG_CPU_V7M
71static inline void set_csselr(unsigned int cache_selector)
72{
73 asm volatile("mcr p15, 2, %0, c0, c0, 0" : : "r" (cache_selector));
74}
75
76static inline unsigned int read_ccsidr(void)
77{
78 unsigned int val;
79
80 asm volatile("mrc p15, 1, %0, c0, c0, 0" : "=r" (val));
81 return val;
82}
83#else /* CONFIG_CPU_V7M */
84#include <linux/io.h>
85#include "asm/v7m.h"
86
87static inline void set_csselr(unsigned int cache_selector)
88{
89 writel(cache_selector, BASEADDR_V7M_SCB + V7M_SCB_CTR);
90}
91
92static inline unsigned int read_ccsidr(void)
93{
94 return readl(BASEADDR_V7M_SCB + V7M_SCB_CCSIDR);
95}
96#endif
97
59#endif 98#endif
diff --git a/arch/arm/include/asm/cputype.h b/arch/arm/include/asm/cputype.h
index 1ee94c716a7f..754f86f667d4 100644
--- a/arch/arm/include/asm/cputype.h
+++ b/arch/arm/include/asm/cputype.h
@@ -60,6 +60,7 @@
60 ((mpidr >> (MPIDR_LEVEL_BITS * level)) & MPIDR_LEVEL_MASK) 60 ((mpidr >> (MPIDR_LEVEL_BITS * level)) & MPIDR_LEVEL_MASK)
61 61
62#define ARM_CPU_IMP_ARM 0x41 62#define ARM_CPU_IMP_ARM 0x41
63#define ARM_CPU_IMP_DEC 0x44
63#define ARM_CPU_IMP_INTEL 0x69 64#define ARM_CPU_IMP_INTEL 0x69
64 65
65/* ARM implemented processors */ 66/* ARM implemented processors */
@@ -76,6 +77,17 @@
76#define ARM_CPU_PART_CORTEX_A15 0x4100c0f0 77#define ARM_CPU_PART_CORTEX_A15 0x4100c0f0
77#define ARM_CPU_PART_MASK 0xff00fff0 78#define ARM_CPU_PART_MASK 0xff00fff0
78 79
80/* DEC implemented cores */
81#define ARM_CPU_PART_SA1100 0x4400a110
82
83/* Intel implemented cores */
84#define ARM_CPU_PART_SA1110 0x6900b110
85#define ARM_CPU_REV_SA1110_A0 0
86#define ARM_CPU_REV_SA1110_B0 4
87#define ARM_CPU_REV_SA1110_B1 5
88#define ARM_CPU_REV_SA1110_B2 6
89#define ARM_CPU_REV_SA1110_B4 8
90
79#define ARM_CPU_XSCALE_ARCH_MASK 0xe000 91#define ARM_CPU_XSCALE_ARCH_MASK 0xe000
80#define ARM_CPU_XSCALE_ARCH_V1 0x2000 92#define ARM_CPU_XSCALE_ARCH_V1 0x2000
81#define ARM_CPU_XSCALE_ARCH_V2 0x4000 93#define ARM_CPU_XSCALE_ARCH_V2 0x4000
@@ -152,6 +164,11 @@ static inline unsigned int __attribute_const__ read_cpuid_id(void)
152 return read_cpuid(CPUID_ID); 164 return read_cpuid(CPUID_ID);
153} 165}
154 166
167static inline unsigned int __attribute_const__ read_cpuid_cachetype(void)
168{
169 return read_cpuid(CPUID_CACHETYPE);
170}
171
155#elif defined(CONFIG_CPU_V7M) 172#elif defined(CONFIG_CPU_V7M)
156 173
157static inline unsigned int __attribute_const__ read_cpuid_id(void) 174static inline unsigned int __attribute_const__ read_cpuid_id(void)
@@ -159,6 +176,11 @@ static inline unsigned int __attribute_const__ read_cpuid_id(void)
159 return readl(BASEADDR_V7M_SCB + V7M_SCB_CPUID); 176 return readl(BASEADDR_V7M_SCB + V7M_SCB_CPUID);
160} 177}
161 178
179static inline unsigned int __attribute_const__ read_cpuid_cachetype(void)
180{
181 return readl(BASEADDR_V7M_SCB + V7M_SCB_CTR);
182}
183
162#else /* ifdef CONFIG_CPU_CP15 / elif defined(CONFIG_CPU_V7M) */ 184#else /* ifdef CONFIG_CPU_CP15 / elif defined(CONFIG_CPU_V7M) */
163 185
164static inline unsigned int __attribute_const__ read_cpuid_id(void) 186static inline unsigned int __attribute_const__ read_cpuid_id(void)
@@ -173,6 +195,11 @@ static inline unsigned int __attribute_const__ read_cpuid_implementor(void)
173 return (read_cpuid_id() & 0xFF000000) >> 24; 195 return (read_cpuid_id() & 0xFF000000) >> 24;
174} 196}
175 197
198static inline unsigned int __attribute_const__ read_cpuid_revision(void)
199{
200 return read_cpuid_id() & 0x0000000f;
201}
202
176/* 203/*
177 * The CPU part number is meaningless without referring to the CPU 204 * The CPU part number is meaningless without referring to the CPU
178 * implementer: implementers are free to define their own part numbers 205 * implementer: implementers are free to define their own part numbers
@@ -193,11 +220,6 @@ static inline unsigned int __attribute_const__ xscale_cpu_arch_version(void)
193 return read_cpuid_id() & ARM_CPU_XSCALE_ARCH_MASK; 220 return read_cpuid_id() & ARM_CPU_XSCALE_ARCH_MASK;
194} 221}
195 222
196static inline unsigned int __attribute_const__ read_cpuid_cachetype(void)
197{
198 return read_cpuid(CPUID_CACHETYPE);
199}
200
201static inline unsigned int __attribute_const__ read_cpuid_tcmstatus(void) 223static inline unsigned int __attribute_const__ read_cpuid_tcmstatus(void)
202{ 224{
203 return read_cpuid(CPUID_TCM); 225 return read_cpuid(CPUID_TCM);
@@ -208,6 +230,10 @@ static inline unsigned int __attribute_const__ read_cpuid_mpidr(void)
208 return read_cpuid(CPUID_MPIDR); 230 return read_cpuid(CPUID_MPIDR);
209} 231}
210 232
233/* StrongARM-11x0 CPUs */
234#define cpu_is_sa1100() (read_cpuid_part() == ARM_CPU_PART_SA1100)
235#define cpu_is_sa1110() (read_cpuid_part() == ARM_CPU_PART_SA1110)
236
211/* 237/*
212 * Intel's XScale3 core supports some v6 features (supersections, L2) 238 * Intel's XScale3 core supports some v6 features (supersections, L2)
213 * but advertises itself as v5 as it does not support the v6 ISA. For 239 * but advertises itself as v5 as it does not support the v6 ISA. For
diff --git a/arch/arm/include/asm/flat.h b/arch/arm/include/asm/flat.h
index e847d23351ed..acf1d14b89a6 100644
--- a/arch/arm/include/asm/flat.h
+++ b/arch/arm/include/asm/flat.h
@@ -8,8 +8,9 @@
8#define flat_argvp_envp_on_stack() 1 8#define flat_argvp_envp_on_stack() 1
9#define flat_old_ram_flag(flags) (flags) 9#define flat_old_ram_flag(flags) (flags)
10#define flat_reloc_valid(reloc, size) ((reloc) <= (size)) 10#define flat_reloc_valid(reloc, size) ((reloc) <= (size))
11#define flat_get_addr_from_rp(rp, relval, flags, persistent) ((void)persistent,get_unaligned(rp)) 11#define flat_get_addr_from_rp(rp, relval, flags, persistent) \
12#define flat_put_addr_at_rp(rp, val, relval) put_unaligned(val,rp) 12 ({ unsigned long __val; __get_user_unaligned(__val, rp); __val; })
13#define flat_put_addr_at_rp(rp, val, relval) __put_user_unaligned(val, rp)
13#define flat_get_relocate_addr(rel) (rel) 14#define flat_get_relocate_addr(rel) (rel)
14#define flat_set_persistent(relval, p) 0 15#define flat_set_persistent(relval, p) 0
15 16
diff --git a/arch/arm/include/asm/glue-cache.h b/arch/arm/include/asm/glue-cache.h
index cab07f69382d..01c3d92624e5 100644
--- a/arch/arm/include/asm/glue-cache.h
+++ b/arch/arm/include/asm/glue-cache.h
@@ -118,11 +118,7 @@
118#endif 118#endif
119 119
120#if defined(CONFIG_CPU_V7M) 120#if defined(CONFIG_CPU_V7M)
121# ifdef _CACHE
122# define MULTI_CACHE 1 121# define MULTI_CACHE 1
123# else
124# define _CACHE nop
125# endif
126#endif 122#endif
127 123
128#if !defined(_CACHE) && !defined(MULTI_CACHE) 124#if !defined(_CACHE) && !defined(MULTI_CACHE)
diff --git a/arch/arm/include/asm/hardware/cache-l2x0.h b/arch/arm/include/asm/hardware/cache-l2x0.h
index 3a5ec1c25659..736292b42fca 100644
--- a/arch/arm/include/asm/hardware/cache-l2x0.h
+++ b/arch/arm/include/asm/hardware/cache-l2x0.h
@@ -87,6 +87,15 @@
87#define L310_CACHE_ID_RTL_R3P2 0x08 87#define L310_CACHE_ID_RTL_R3P2 0x08
88#define L310_CACHE_ID_RTL_R3P3 0x09 88#define L310_CACHE_ID_RTL_R3P3 0x09
89 89
90#define L2X0_EVENT_CNT_CTRL_ENABLE BIT(0)
91
92#define L2X0_EVENT_CNT_CFG_SRC_SHIFT 2
93#define L2X0_EVENT_CNT_CFG_SRC_MASK 0xf
94#define L2X0_EVENT_CNT_CFG_SRC_DISABLED 0
95#define L2X0_EVENT_CNT_CFG_INT_DISABLED 0
96#define L2X0_EVENT_CNT_CFG_INT_INCR 1
97#define L2X0_EVENT_CNT_CFG_INT_OVERFLOW 2
98
90/* L2C auxiliary control register - bits common to L2C-210/220/310 */ 99/* L2C auxiliary control register - bits common to L2C-210/220/310 */
91#define L2C_AUX_CTRL_WAY_SIZE_SHIFT 17 100#define L2C_AUX_CTRL_WAY_SIZE_SHIFT 17
92#define L2C_AUX_CTRL_WAY_SIZE_MASK (7 << 17) 101#define L2C_AUX_CTRL_WAY_SIZE_MASK (7 << 17)
@@ -157,6 +166,16 @@ static inline int l2x0_of_init(u32 aux_val, u32 aux_mask)
157} 166}
158#endif 167#endif
159 168
169#ifdef CONFIG_CACHE_L2X0_PMU
170void l2x0_pmu_register(void __iomem *base, u32 part);
171void l2x0_pmu_suspend(void);
172void l2x0_pmu_resume(void);
173#else
174static inline void l2x0_pmu_register(void __iomem *base, u32 part) {}
175static inline void l2x0_pmu_suspend(void) {}
176static inline void l2x0_pmu_resume(void) {}
177#endif
178
160struct l2x0_regs { 179struct l2x0_regs {
161 unsigned long phy_base; 180 unsigned long phy_base;
162 unsigned long aux_ctrl; 181 unsigned long aux_ctrl;
diff --git a/arch/arm/include/asm/hardware/sa1111.h b/arch/arm/include/asm/hardware/sa1111.h
index 7c2bbc7f0be1..8979fa3bbf2d 100644
--- a/arch/arm/include/asm/hardware/sa1111.h
+++ b/arch/arm/include/asm/hardware/sa1111.h
@@ -420,7 +420,7 @@ struct sa1111_dev {
420 u64 dma_mask; 420 u64 dma_mask;
421}; 421};
422 422
423#define SA1111_DEV(_d) container_of((_d), struct sa1111_dev, dev) 423#define to_sa1111_device(x) container_of(x, struct sa1111_dev, dev)
424 424
425#define sa1111_get_drvdata(d) dev_get_drvdata(&(d)->dev) 425#define sa1111_get_drvdata(d) dev_get_drvdata(&(d)->dev)
426#define sa1111_set_drvdata(d,p) dev_set_drvdata(&(d)->dev, p) 426#define sa1111_set_drvdata(d,p) dev_set_drvdata(&(d)->dev, p)
@@ -446,6 +446,8 @@ struct sa1111_driver {
446int sa1111_enable_device(struct sa1111_dev *); 446int sa1111_enable_device(struct sa1111_dev *);
447void sa1111_disable_device(struct sa1111_dev *); 447void sa1111_disable_device(struct sa1111_dev *);
448 448
449int sa1111_get_irq(struct sa1111_dev *, unsigned num);
450
449unsigned int sa1111_pll_clock(struct sa1111_dev *); 451unsigned int sa1111_pll_clock(struct sa1111_dev *);
450 452
451#define SA1111_AUDIO_ACLINK 0 453#define SA1111_AUDIO_ACLINK 0
diff --git a/arch/arm/include/asm/hw_breakpoint.h b/arch/arm/include/asm/hw_breakpoint.h
index 8e427c7b4425..afcaf8bf971b 100644
--- a/arch/arm/include/asm/hw_breakpoint.h
+++ b/arch/arm/include/asm/hw_breakpoint.h
@@ -114,7 +114,6 @@ struct notifier_block;
114struct perf_event; 114struct perf_event;
115struct pmu; 115struct pmu;
116 116
117extern struct pmu perf_ops_bp;
118extern int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl, 117extern int arch_bp_generic_fields(struct arch_hw_breakpoint_ctrl ctrl,
119 int *gen_len, int *gen_type); 118 int *gen_len, int *gen_type);
120extern int arch_check_bp_in_kernelspace(struct perf_event *bp); 119extern int arch_check_bp_in_kernelspace(struct perf_event *bp);
diff --git a/arch/arm/include/asm/memory.h b/arch/arm/include/asm/memory.h
index 31c07a2cc100..76cbd9c674df 100644
--- a/arch/arm/include/asm/memory.h
+++ b/arch/arm/include/asm/memory.h
@@ -159,13 +159,8 @@
159 * PFNs are used to describe any physical page; this means 159 * PFNs are used to describe any physical page; this means
160 * PFN 0 == physical address 0. 160 * PFN 0 == physical address 0.
161 */ 161 */
162#if defined(__virt_to_phys)
163#define PHYS_OFFSET PLAT_PHYS_OFFSET
164#define PHYS_PFN_OFFSET ((unsigned long)(PHYS_OFFSET >> PAGE_SHIFT))
165
166#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT)
167 162
168#elif defined(CONFIG_ARM_PATCH_PHYS_VIRT) 163#if defined(CONFIG_ARM_PATCH_PHYS_VIRT)
169 164
170/* 165/*
171 * Constants used to force the right instruction encodings and shifts 166 * Constants used to force the right instruction encodings and shifts
@@ -182,10 +177,6 @@ extern const void *__pv_table_begin, *__pv_table_end;
182#define PHYS_OFFSET ((phys_addr_t)__pv_phys_pfn_offset << PAGE_SHIFT) 177#define PHYS_OFFSET ((phys_addr_t)__pv_phys_pfn_offset << PAGE_SHIFT)
183#define PHYS_PFN_OFFSET (__pv_phys_pfn_offset) 178#define PHYS_PFN_OFFSET (__pv_phys_pfn_offset)
184 179
185#define virt_to_pfn(kaddr) \
186 ((((unsigned long)(kaddr) - PAGE_OFFSET) >> PAGE_SHIFT) + \
187 PHYS_PFN_OFFSET)
188
189#define __pv_stub(from,to,instr,type) \ 180#define __pv_stub(from,to,instr,type) \
190 __asm__("@ __pv_stub\n" \ 181 __asm__("@ __pv_stub\n" \
191 "1: " instr " %0, %1, %2\n" \ 182 "1: " instr " %0, %1, %2\n" \
@@ -257,12 +248,12 @@ static inline unsigned long __phys_to_virt(phys_addr_t x)
257 return x - PHYS_OFFSET + PAGE_OFFSET; 248 return x - PHYS_OFFSET + PAGE_OFFSET;
258} 249}
259 250
251#endif
252
260#define virt_to_pfn(kaddr) \ 253#define virt_to_pfn(kaddr) \
261 ((((unsigned long)(kaddr) - PAGE_OFFSET) >> PAGE_SHIFT) + \ 254 ((((unsigned long)(kaddr) - PAGE_OFFSET) >> PAGE_SHIFT) + \
262 PHYS_PFN_OFFSET) 255 PHYS_PFN_OFFSET)
263 256
264#endif
265
266/* 257/*
267 * These are *only* valid on the kernel direct mapped RAM memory. 258 * These are *only* valid on the kernel direct mapped RAM memory.
268 * Note: Drivers should NOT use these. They are the wrong 259 * Note: Drivers should NOT use these. They are the wrong
diff --git a/arch/arm/include/asm/module.h b/arch/arm/include/asm/module.h
index e358b7966c06..464748b9fd7d 100644
--- a/arch/arm/include/asm/module.h
+++ b/arch/arm/include/asm/module.h
@@ -23,10 +23,8 @@ struct mod_arch_specific {
23 struct unwind_table *unwind[ARM_SEC_MAX]; 23 struct unwind_table *unwind[ARM_SEC_MAX];
24#endif 24#endif
25#ifdef CONFIG_ARM_MODULE_PLTS 25#ifdef CONFIG_ARM_MODULE_PLTS
26 struct elf32_shdr *core_plt; 26 struct elf32_shdr *plt;
27 struct elf32_shdr *init_plt; 27 int plt_count;
28 int core_plt_count;
29 int init_plt_count;
30#endif 28#endif
31}; 29};
32 30
diff --git a/arch/arm/include/asm/v7m.h b/arch/arm/include/asm/v7m.h
index 615781c61627..1fd775c1bc5d 100644
--- a/arch/arm/include/asm/v7m.h
+++ b/arch/arm/include/asm/v7m.h
@@ -24,6 +24,9 @@
24 24
25#define V7M_SCB_CCR 0x14 25#define V7M_SCB_CCR 0x14
26#define V7M_SCB_CCR_STKALIGN (1 << 9) 26#define V7M_SCB_CCR_STKALIGN (1 << 9)
27#define V7M_SCB_CCR_DC (1 << 16)
28#define V7M_SCB_CCR_IC (1 << 17)
29#define V7M_SCB_CCR_BP (1 << 18)
27 30
28#define V7M_SCB_SHPR2 0x1c 31#define V7M_SCB_SHPR2 0x1c
29#define V7M_SCB_SHPR3 0x20 32#define V7M_SCB_SHPR3 0x20
@@ -47,6 +50,25 @@
47#define EXC_RET_STACK_MASK 0x00000004 50#define EXC_RET_STACK_MASK 0x00000004
48#define EXC_RET_THREADMODE_PROCESSSTACK 0xfffffffd 51#define EXC_RET_THREADMODE_PROCESSSTACK 0xfffffffd
49 52
53/* Cache related definitions */
54
55#define V7M_SCB_CLIDR 0x78 /* Cache Level ID register */
56#define V7M_SCB_CTR 0x7c /* Cache Type register */
57#define V7M_SCB_CCSIDR 0x80 /* Cache size ID register */
58#define V7M_SCB_CSSELR 0x84 /* Cache size selection register */
59
60/* Cache opeartions */
61#define V7M_SCB_ICIALLU 0x250 /* I-cache invalidate all to PoU */
62#define V7M_SCB_ICIMVAU 0x258 /* I-cache invalidate by MVA to PoU */
63#define V7M_SCB_DCIMVAC 0x25c /* D-cache invalidate by MVA to PoC */
64#define V7M_SCB_DCISW 0x260 /* D-cache invalidate by set-way */
65#define V7M_SCB_DCCMVAU 0x264 /* D-cache clean by MVA to PoU */
66#define V7M_SCB_DCCMVAC 0x268 /* D-cache clean by MVA to PoC */
67#define V7M_SCB_DCCSW 0x26c /* D-cache clean by set-way */
68#define V7M_SCB_DCCIMVAC 0x270 /* D-cache clean and invalidate by MVA to PoC */
69#define V7M_SCB_DCCISW 0x274 /* D-cache clean and invalidate by set-way */
70#define V7M_SCB_BPIALL 0x278 /* D-cache clean and invalidate by set-way */
71
50#ifndef __ASSEMBLY__ 72#ifndef __ASSEMBLY__
51 73
52enum reboot_mode; 74enum reboot_mode;
diff --git a/arch/arm/kernel/cpuidle.c b/arch/arm/kernel/cpuidle.c
index 7dccc964d75f..a3308ad1a024 100644
--- a/arch/arm/kernel/cpuidle.c
+++ b/arch/arm/kernel/cpuidle.c
@@ -19,7 +19,7 @@ extern struct of_cpuidle_method __cpuidle_method_of_table[];
19static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel 19static const struct of_cpuidle_method __cpuidle_method_of_table_sentinel
20 __used __section(__cpuidle_method_of_table_end); 20 __used __section(__cpuidle_method_of_table_end);
21 21
22static struct cpuidle_ops cpuidle_ops[NR_CPUS]; 22static struct cpuidle_ops cpuidle_ops[NR_CPUS] __ro_after_init;
23 23
24/** 24/**
25 * arm_cpuidle_simple_enter() - a wrapper to cpu_do_idle() 25 * arm_cpuidle_simple_enter() - a wrapper to cpu_do_idle()
diff --git a/arch/arm/kernel/head-nommu.S b/arch/arm/kernel/head-nommu.S
index fb1a69eb49c1..6b4eb27b8758 100644
--- a/arch/arm/kernel/head-nommu.S
+++ b/arch/arm/kernel/head-nommu.S
@@ -158,7 +158,21 @@ __after_proc_init:
158 bic r0, r0, #CR_V 158 bic r0, r0, #CR_V
159#endif 159#endif
160 mcr p15, 0, r0, c1, c0, 0 @ write control reg 160 mcr p15, 0, r0, c1, c0, 0 @ write control reg
161#endif /* CONFIG_CPU_CP15 */ 161#elif defined (CONFIG_CPU_V7M)
162 /* For V7M systems we want to modify the CCR similarly to the SCTLR */
163#ifdef CONFIG_CPU_DCACHE_DISABLE
164 bic r0, r0, #V7M_SCB_CCR_DC
165#endif
166#ifdef CONFIG_CPU_BPREDICT_DISABLE
167 bic r0, r0, #V7M_SCB_CCR_BP
168#endif
169#ifdef CONFIG_CPU_ICACHE_DISABLE
170 bic r0, r0, #V7M_SCB_CCR_IC
171#endif
172 movw r3, #:lower16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
173 movt r3, #:upper16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
174 str r0, [r3]
175#endif /* CONFIG_CPU_CP15 elif CONFIG_CPU_V7M */
162 ret lr 176 ret lr
163ENDPROC(__after_proc_init) 177ENDPROC(__after_proc_init)
164 .ltorg 178 .ltorg
diff --git a/arch/arm/kernel/module-plts.c b/arch/arm/kernel/module-plts.c
index 0c7efc3446c0..3a5cba90c971 100644
--- a/arch/arm/kernel/module-plts.c
+++ b/arch/arm/kernel/module-plts.c
@@ -9,6 +9,7 @@
9#include <linux/elf.h> 9#include <linux/elf.h>
10#include <linux/kernel.h> 10#include <linux/kernel.h>
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/sort.h>
12 13
13#include <asm/cache.h> 14#include <asm/cache.h>
14#include <asm/opcodes.h> 15#include <asm/opcodes.h>
@@ -30,154 +31,198 @@ struct plt_entries {
30 u32 lit[PLT_ENT_COUNT]; 31 u32 lit[PLT_ENT_COUNT];
31}; 32};
32 33
33static bool in_init(const struct module *mod, u32 addr) 34u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val)
34{ 35{
35 return addr - (u32)mod->init_layout.base < mod->init_layout.size; 36 struct plt_entries *plt = (struct plt_entries *)mod->arch.plt->sh_addr;
37 int idx = 0;
38
39 /*
40 * Look for an existing entry pointing to 'val'. Given that the
41 * relocations are sorted, this will be the last entry we allocated.
42 * (if one exists).
43 */
44 if (mod->arch.plt_count > 0) {
45 plt += (mod->arch.plt_count - 1) / PLT_ENT_COUNT;
46 idx = (mod->arch.plt_count - 1) % PLT_ENT_COUNT;
47
48 if (plt->lit[idx] == val)
49 return (u32)&plt->ldr[idx];
50
51 idx = (idx + 1) % PLT_ENT_COUNT;
52 if (!idx)
53 plt++;
54 }
55
56 mod->arch.plt_count++;
57 BUG_ON(mod->arch.plt_count * PLT_ENT_SIZE > mod->arch.plt->sh_size);
58
59 if (!idx)
60 /* Populate a new set of entries */
61 *plt = (struct plt_entries){
62 { [0 ... PLT_ENT_COUNT - 1] = PLT_ENT_LDR, },
63 { val, }
64 };
65 else
66 plt->lit[idx] = val;
67
68 return (u32)&plt->ldr[idx];
36} 69}
37 70
38u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val) 71#define cmp_3way(a,b) ((a) < (b) ? -1 : (a) > (b))
72
73static int cmp_rel(const void *a, const void *b)
39{ 74{
40 struct plt_entries *plt, *plt_end; 75 const Elf32_Rel *x = a, *y = b;
41 int c, *count; 76 int i;
42
43 if (in_init(mod, loc)) {
44 plt = (void *)mod->arch.init_plt->sh_addr;
45 plt_end = (void *)plt + mod->arch.init_plt->sh_size;
46 count = &mod->arch.init_plt_count;
47 } else {
48 plt = (void *)mod->arch.core_plt->sh_addr;
49 plt_end = (void *)plt + mod->arch.core_plt->sh_size;
50 count = &mod->arch.core_plt_count;
51 }
52 77
53 /* Look for an existing entry pointing to 'val' */ 78 /* sort by type and symbol index */
54 for (c = *count; plt < plt_end; c -= PLT_ENT_COUNT, plt++) { 79 i = cmp_3way(ELF32_R_TYPE(x->r_info), ELF32_R_TYPE(y->r_info));
55 int i; 80 if (i == 0)
56 81 i = cmp_3way(ELF32_R_SYM(x->r_info), ELF32_R_SYM(y->r_info));
57 if (!c) { 82 return i;
58 /* Populate a new set of entries */ 83}
59 *plt = (struct plt_entries){ 84
60 { [0 ... PLT_ENT_COUNT - 1] = PLT_ENT_LDR, }, 85static bool is_zero_addend_relocation(Elf32_Addr base, const Elf32_Rel *rel)
61 { val, } 86{
62 }; 87 u32 *tval = (u32 *)(base + rel->r_offset);
63 ++*count; 88
64 return (u32)plt->ldr; 89 /*
65 } 90 * Do a bitwise compare on the raw addend rather than fully decoding
66 for (i = 0; i < PLT_ENT_COUNT; i++) { 91 * the offset and doing an arithmetic comparison.
67 if (!plt->lit[i]) { 92 * Note that a zero-addend jump/call relocation is encoded taking the
68 plt->lit[i] = val; 93 * PC bias into account, i.e., -8 for ARM and -4 for Thumb2.
69 ++*count; 94 */
70 } 95 switch (ELF32_R_TYPE(rel->r_info)) {
71 if (plt->lit[i] == val) 96 u16 upper, lower;
72 return (u32)&plt->ldr[i]; 97
73 } 98 case R_ARM_THM_CALL:
99 case R_ARM_THM_JUMP24:
100 upper = __mem_to_opcode_thumb16(((u16 *)tval)[0]);
101 lower = __mem_to_opcode_thumb16(((u16 *)tval)[1]);
102
103 return (upper & 0x7ff) == 0x7ff && (lower & 0x2fff) == 0x2ffe;
104
105 case R_ARM_CALL:
106 case R_ARM_PC24:
107 case R_ARM_JUMP24:
108 return (__mem_to_opcode_arm(*tval) & 0xffffff) == 0xfffffe;
74 } 109 }
75 BUG(); 110 BUG();
76} 111}
77 112
78static int duplicate_rel(Elf32_Addr base, const Elf32_Rel *rel, int num, 113static bool duplicate_rel(Elf32_Addr base, const Elf32_Rel *rel, int num)
79 u32 mask)
80{ 114{
81 u32 *loc1, *loc2; 115 const Elf32_Rel *prev;
82 int i;
83 116
84 for (i = 0; i < num; i++) { 117 /*
85 if (rel[i].r_info != rel[num].r_info) 118 * Entries are sorted by type and symbol index. That means that,
86 continue; 119 * if a duplicate entry exists, it must be in the preceding
120 * slot.
121 */
122 if (!num)
123 return false;
87 124
88 /* 125 prev = rel + num - 1;
89 * Identical relocation types against identical symbols can 126 return cmp_rel(rel + num, prev) == 0 &&
90 * still result in different PLT entries if the addend in the 127 is_zero_addend_relocation(base, prev);
91 * place is different. So resolve the target of the relocation
92 * to compare the values.
93 */
94 loc1 = (u32 *)(base + rel[i].r_offset);
95 loc2 = (u32 *)(base + rel[num].r_offset);
96 if (((*loc1 ^ *loc2) & mask) == 0)
97 return 1;
98 }
99 return 0;
100} 128}
101 129
102/* Count how many PLT entries we may need */ 130/* Count how many PLT entries we may need */
103static unsigned int count_plts(Elf32_Addr base, const Elf32_Rel *rel, int num) 131static unsigned int count_plts(const Elf32_Sym *syms, Elf32_Addr base,
132 const Elf32_Rel *rel, int num)
104{ 133{
105 unsigned int ret = 0; 134 unsigned int ret = 0;
135 const Elf32_Sym *s;
106 int i; 136 int i;
107 137
108 /* 138 for (i = 0; i < num; i++) {
109 * Sure, this is order(n^2), but it's usually short, and not
110 * time critical
111 */
112 for (i = 0; i < num; i++)
113 switch (ELF32_R_TYPE(rel[i].r_info)) { 139 switch (ELF32_R_TYPE(rel[i].r_info)) {
114 case R_ARM_CALL: 140 case R_ARM_CALL:
115 case R_ARM_PC24: 141 case R_ARM_PC24:
116 case R_ARM_JUMP24: 142 case R_ARM_JUMP24:
117 if (!duplicate_rel(base, rel, i,
118 __opcode_to_mem_arm(0x00ffffff)))
119 ret++;
120 break;
121#ifdef CONFIG_THUMB2_KERNEL
122 case R_ARM_THM_CALL: 143 case R_ARM_THM_CALL:
123 case R_ARM_THM_JUMP24: 144 case R_ARM_THM_JUMP24:
124 if (!duplicate_rel(base, rel, i, 145 /*
125 __opcode_to_mem_thumb32(0x07ff2fff))) 146 * We only have to consider branch targets that resolve
147 * to undefined symbols. This is not simply a heuristic,
148 * it is a fundamental limitation, since the PLT itself
149 * is part of the module, and needs to be within range
150 * as well, so modules can never grow beyond that limit.
151 */
152 s = syms + ELF32_R_SYM(rel[i].r_info);
153 if (s->st_shndx != SHN_UNDEF)
154 break;
155
156 /*
157 * Jump relocations with non-zero addends against
158 * undefined symbols are supported by the ELF spec, but
159 * do not occur in practice (e.g., 'jump n bytes past
160 * the entry point of undefined function symbol f').
161 * So we need to support them, but there is no need to
162 * take them into consideration when trying to optimize
163 * this code. So let's only check for duplicates when
164 * the addend is zero.
165 */
166 if (!is_zero_addend_relocation(base, rel + i) ||
167 !duplicate_rel(base, rel, i))
126 ret++; 168 ret++;
127#endif
128 } 169 }
170 }
129 return ret; 171 return ret;
130} 172}
131 173
132int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, 174int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs,
133 char *secstrings, struct module *mod) 175 char *secstrings, struct module *mod)
134{ 176{
135 unsigned long core_plts = 0, init_plts = 0; 177 unsigned long plts = 0;
136 Elf32_Shdr *s, *sechdrs_end = sechdrs + ehdr->e_shnum; 178 Elf32_Shdr *s, *sechdrs_end = sechdrs + ehdr->e_shnum;
179 Elf32_Sym *syms = NULL;
137 180
138 /* 181 /*
139 * To store the PLTs, we expand the .text section for core module code 182 * To store the PLTs, we expand the .text section for core module code
140 * and the .init.text section for initialization code. 183 * and for initialization code.
141 */ 184 */
142 for (s = sechdrs; s < sechdrs_end; ++s) 185 for (s = sechdrs; s < sechdrs_end; ++s) {
143 if (strcmp(".core.plt", secstrings + s->sh_name) == 0) 186 if (strcmp(".plt", secstrings + s->sh_name) == 0)
144 mod->arch.core_plt = s; 187 mod->arch.plt = s;
145 else if (strcmp(".init.plt", secstrings + s->sh_name) == 0) 188 else if (s->sh_type == SHT_SYMTAB)
146 mod->arch.init_plt = s; 189 syms = (Elf32_Sym *)s->sh_addr;
147 190 }
148 if (!mod->arch.core_plt || !mod->arch.init_plt) { 191
149 pr_err("%s: sections missing\n", mod->name); 192 if (!mod->arch.plt) {
193 pr_err("%s: module PLT section missing\n", mod->name);
194 return -ENOEXEC;
195 }
196 if (!syms) {
197 pr_err("%s: module symtab section missing\n", mod->name);
150 return -ENOEXEC; 198 return -ENOEXEC;
151 } 199 }
152 200
153 for (s = sechdrs + 1; s < sechdrs_end; ++s) { 201 for (s = sechdrs + 1; s < sechdrs_end; ++s) {
154 const Elf32_Rel *rels = (void *)ehdr + s->sh_offset; 202 Elf32_Rel *rels = (void *)ehdr + s->sh_offset;
155 int numrels = s->sh_size / sizeof(Elf32_Rel); 203 int numrels = s->sh_size / sizeof(Elf32_Rel);
156 Elf32_Shdr *dstsec = sechdrs + s->sh_info; 204 Elf32_Shdr *dstsec = sechdrs + s->sh_info;
157 205
158 if (s->sh_type != SHT_REL) 206 if (s->sh_type != SHT_REL)
159 continue; 207 continue;
160 208
161 if (strstr(secstrings + s->sh_name, ".init")) 209 /* ignore relocations that operate on non-exec sections */
162 init_plts += count_plts(dstsec->sh_addr, rels, numrels); 210 if (!(dstsec->sh_flags & SHF_EXECINSTR))
163 else 211 continue;
164 core_plts += count_plts(dstsec->sh_addr, rels, numrels); 212
213 /* sort by type and symbol index */
214 sort(rels, numrels, sizeof(Elf32_Rel), cmp_rel, NULL);
215
216 plts += count_plts(syms, dstsec->sh_addr, rels, numrels);
165 } 217 }
166 218
167 mod->arch.core_plt->sh_type = SHT_NOBITS; 219 mod->arch.plt->sh_type = SHT_NOBITS;
168 mod->arch.core_plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; 220 mod->arch.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC;
169 mod->arch.core_plt->sh_addralign = L1_CACHE_BYTES; 221 mod->arch.plt->sh_addralign = L1_CACHE_BYTES;
170 mod->arch.core_plt->sh_size = round_up(core_plts * PLT_ENT_SIZE, 222 mod->arch.plt->sh_size = round_up(plts * PLT_ENT_SIZE,
171 sizeof(struct plt_entries)); 223 sizeof(struct plt_entries));
172 mod->arch.core_plt_count = 0; 224 mod->arch.plt_count = 0;
173 225
174 mod->arch.init_plt->sh_type = SHT_NOBITS; 226 pr_debug("%s: plt=%x\n", __func__, mod->arch.plt->sh_size);
175 mod->arch.init_plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC;
176 mod->arch.init_plt->sh_addralign = L1_CACHE_BYTES;
177 mod->arch.init_plt->sh_size = round_up(init_plts * PLT_ENT_SIZE,
178 sizeof(struct plt_entries));
179 mod->arch.init_plt_count = 0;
180 pr_debug("%s: core.plt=%x, init.plt=%x\n", __func__,
181 mod->arch.core_plt->sh_size, mod->arch.init_plt->sh_size);
182 return 0; 227 return 0;
183} 228}
diff --git a/arch/arm/kernel/module.lds b/arch/arm/kernel/module.lds
index 3682fa107918..05881e2b414c 100644
--- a/arch/arm/kernel/module.lds
+++ b/arch/arm/kernel/module.lds
@@ -1,4 +1,3 @@
1SECTIONS { 1SECTIONS {
2 .core.plt : { BYTE(0) } 2 .plt : { BYTE(0) }
3 .init.plt : { BYTE(0) }
4} 3}
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index df7f2a75e769..34e3f3c45634 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -114,19 +114,19 @@ EXPORT_SYMBOL(elf_hwcap2);
114 114
115 115
116#ifdef MULTI_CPU 116#ifdef MULTI_CPU
117struct processor processor __read_mostly; 117struct processor processor __ro_after_init;
118#endif 118#endif
119#ifdef MULTI_TLB 119#ifdef MULTI_TLB
120struct cpu_tlb_fns cpu_tlb __read_mostly; 120struct cpu_tlb_fns cpu_tlb __ro_after_init;
121#endif 121#endif
122#ifdef MULTI_USER 122#ifdef MULTI_USER
123struct cpu_user_fns cpu_user __read_mostly; 123struct cpu_user_fns cpu_user __ro_after_init;
124#endif 124#endif
125#ifdef MULTI_CACHE 125#ifdef MULTI_CACHE
126struct cpu_cache_fns cpu_cache __read_mostly; 126struct cpu_cache_fns cpu_cache __ro_after_init;
127#endif 127#endif
128#ifdef CONFIG_OUTER_CACHE 128#ifdef CONFIG_OUTER_CACHE
129struct outer_cache_fns outer_cache __read_mostly; 129struct outer_cache_fns outer_cache __ro_after_init;
130EXPORT_SYMBOL(outer_cache); 130EXPORT_SYMBOL(outer_cache);
131#endif 131#endif
132 132
@@ -290,12 +290,9 @@ static int cpu_has_aliasing_icache(unsigned int arch)
290 /* arch specifies the register format */ 290 /* arch specifies the register format */
291 switch (arch) { 291 switch (arch) {
292 case CPU_ARCH_ARMv7: 292 case CPU_ARCH_ARMv7:
293 asm("mcr p15, 2, %0, c0, c0, 0 @ set CSSELR" 293 set_csselr(CSSELR_ICACHE | CSSELR_L1);
294 : /* No output operands */
295 : "r" (1));
296 isb(); 294 isb();
297 asm("mrc p15, 1, %0, c0, c0, 0 @ read CCSIDR" 295 id_reg = read_ccsidr();
298 : "=r" (id_reg));
299 line_size = 4 << ((id_reg & 0x7) + 2); 296 line_size = 4 << ((id_reg & 0x7) + 2);
300 num_sets = ((id_reg >> 13) & 0x7fff) + 1; 297 num_sets = ((id_reg >> 13) & 0x7fff) + 1;
301 aliasing_icache = (line_size * num_sets) > PAGE_SIZE; 298 aliasing_icache = (line_size * num_sets) > PAGE_SIZE;
@@ -315,11 +312,12 @@ static void __init cacheid_init(void)
315{ 312{
316 unsigned int arch = cpu_architecture(); 313 unsigned int arch = cpu_architecture();
317 314
318 if (arch == CPU_ARCH_ARMv7M) { 315 if (arch >= CPU_ARCH_ARMv6) {
319 cacheid = 0;
320 } else if (arch >= CPU_ARCH_ARMv6) {
321 unsigned int cachetype = read_cpuid_cachetype(); 316 unsigned int cachetype = read_cpuid_cachetype();
322 if ((cachetype & (7 << 29)) == 4 << 29) { 317
318 if ((arch == CPU_ARCH_ARMv7M) && !cachetype) {
319 cacheid = 0;
320 } else if ((cachetype & (7 << 29)) == 4 << 29) {
323 /* ARMv7 register format */ 321 /* ARMv7 register format */
324 arch = CPU_ARCH_ARMv7; 322 arch = CPU_ARCH_ARMv7;
325 cacheid = CACHEID_VIPT_NONALIASING; 323 cacheid = CACHEID_VIPT_NONALIASING;
diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
index 861521606c6d..937c8920d741 100644
--- a/arch/arm/kernel/smp.c
+++ b/arch/arm/kernel/smp.c
@@ -82,7 +82,7 @@ enum ipi_msg_type {
82 82
83static DECLARE_COMPLETION(cpu_running); 83static DECLARE_COMPLETION(cpu_running);
84 84
85static struct smp_operations smp_ops; 85static struct smp_operations smp_ops __ro_after_init;
86 86
87void __init smp_set_ops(const struct smp_operations *ops) 87void __init smp_set_ops(const struct smp_operations *ops)
88{ 88{
diff --git a/arch/arm/kernel/vdso.c b/arch/arm/kernel/vdso.c
index a0affd14086a..53cf86cf2d1a 100644
--- a/arch/arm/kernel/vdso.c
+++ b/arch/arm/kernel/vdso.c
@@ -17,6 +17,7 @@
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */ 18 */
19 19
20#include <linux/cache.h>
20#include <linux/elf.h> 21#include <linux/elf.h>
21#include <linux/err.h> 22#include <linux/err.h>
22#include <linux/kernel.h> 23#include <linux/kernel.h>
@@ -39,7 +40,7 @@
39static struct page **vdso_text_pagelist; 40static struct page **vdso_text_pagelist;
40 41
41/* Total number of pages needed for the data and text portions of the VDSO. */ 42/* Total number of pages needed for the data and text portions of the VDSO. */
42unsigned int vdso_total_pages __read_mostly; 43unsigned int vdso_total_pages __ro_after_init;
43 44
44/* 45/*
45 * The VDSO data page. 46 * The VDSO data page.
@@ -47,13 +48,13 @@ unsigned int vdso_total_pages __read_mostly;
47static union vdso_data_store vdso_data_store __page_aligned_data; 48static union vdso_data_store vdso_data_store __page_aligned_data;
48static struct vdso_data *vdso_data = &vdso_data_store.data; 49static struct vdso_data *vdso_data = &vdso_data_store.data;
49 50
50static struct page *vdso_data_page; 51static struct page *vdso_data_page __ro_after_init;
51static struct vm_special_mapping vdso_data_mapping = { 52static const struct vm_special_mapping vdso_data_mapping = {
52 .name = "[vvar]", 53 .name = "[vvar]",
53 .pages = &vdso_data_page, 54 .pages = &vdso_data_page,
54}; 55};
55 56
56static struct vm_special_mapping vdso_text_mapping = { 57static struct vm_special_mapping vdso_text_mapping __ro_after_init = {
57 .name = "[vdso]", 58 .name = "[vdso]",
58}; 59};
59 60
@@ -67,7 +68,7 @@ struct elfinfo {
67/* Cached result of boot-time check for whether the arch timer exists, 68/* Cached result of boot-time check for whether the arch timer exists,
68 * and if so, whether the virtual counter is useable. 69 * and if so, whether the virtual counter is useable.
69 */ 70 */
70static bool cntvct_ok __read_mostly; 71static bool cntvct_ok __ro_after_init;
71 72
72static bool __init cntvct_functional(void) 73static bool __init cntvct_functional(void)
73{ 74{
diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
index 8044591dca72..2cef11884857 100644
--- a/arch/arm/lib/delay.c
+++ b/arch/arm/lib/delay.c
@@ -29,7 +29,7 @@
29/* 29/*
30 * Default to the loop-based delay implementation. 30 * Default to the loop-based delay implementation.
31 */ 31 */
32struct arm_delay_ops arm_delay_ops = { 32struct arm_delay_ops arm_delay_ops __ro_after_init = {
33 .delay = __loop_delay, 33 .delay = __loop_delay,
34 .const_udelay = __loop_const_udelay, 34 .const_udelay = __loop_const_udelay,
35 .udelay = __loop_udelay, 35 .udelay = __loop_udelay,
diff --git a/arch/arm/mach-footbridge/include/mach/hardware.h b/arch/arm/mach-footbridge/include/mach/hardware.h
index 02f6d7a706b1..20d5ad781fe2 100644
--- a/arch/arm/mach-footbridge/include/mach/hardware.h
+++ b/arch/arm/mach-footbridge/include/mach/hardware.h
@@ -59,7 +59,7 @@
59#define XBUS_SWITCH_J17_11 ((*XBUS_SWITCH) & (1 << 5)) 59#define XBUS_SWITCH_J17_11 ((*XBUS_SWITCH) & (1 << 5))
60#define XBUS_SWITCH_J17_9 ((*XBUS_SWITCH) & (1 << 6)) 60#define XBUS_SWITCH_J17_9 ((*XBUS_SWITCH) & (1 << 6))
61 61
62#define UNCACHEABLE_ADDR (ARMCSR_BASE + 0x108) 62#define UNCACHEABLE_ADDR (ARMCSR_BASE + 0x108) /* CSR_ROMBASEMASK */
63 63
64 64
65/* PIC irq control */ 65/* PIC irq control */
diff --git a/arch/arm/mach-rpc/include/mach/hardware.h b/arch/arm/mach-rpc/include/mach/hardware.h
index 257166b21f3d..aa79fa47373a 100644
--- a/arch/arm/mach-rpc/include/mach/hardware.h
+++ b/arch/arm/mach-rpc/include/mach/hardware.h
@@ -40,7 +40,7 @@
40#define SCREEN_END 0xdfc00000 40#define SCREEN_END 0xdfc00000
41#define SCREEN_BASE 0xdf800000 41#define SCREEN_BASE 0xdf800000
42 42
43#define UNCACHEABLE_ADDR 0xdf010000 43#define UNCACHEABLE_ADDR (FLUSH_BASE + 0x10000)
44 44
45/* 45/*
46 * IO Addresses 46 * IO Addresses
diff --git a/arch/arm/mach-sa1100/include/mach/hardware.h b/arch/arm/mach-sa1100/include/mach/hardware.h
index cbedd75a9d65..d944fd7e464f 100644
--- a/arch/arm/mach-sa1100/include/mach/hardware.h
+++ b/arch/arm/mach-sa1100/include/mach/hardware.h
@@ -13,7 +13,7 @@
13#define __ASM_ARCH_HARDWARE_H 13#define __ASM_ARCH_HARDWARE_H
14 14
15 15
16#define UNCACHEABLE_ADDR 0xfa050000 16#define UNCACHEABLE_ADDR 0xfa050000 /* ICIP */
17 17
18 18
19/* 19/*
@@ -36,28 +36,10 @@
36#define io_v2p( x ) \ 36#define io_v2p( x ) \
37 ( (((x)&0x00ffffff) | (((x)&(0x30000000>>VIO_SHIFT))<<VIO_SHIFT)) + PIO_START ) 37 ( (((x)&0x00ffffff) | (((x)&(0x30000000>>VIO_SHIFT))<<VIO_SHIFT)) + PIO_START )
38 38
39#define CPU_SA1110_A0 (0)
40#define CPU_SA1110_B0 (4)
41#define CPU_SA1110_B1 (5)
42#define CPU_SA1110_B2 (6)
43#define CPU_SA1110_B4 (8)
44
45#define CPU_SA1100_ID (0x4401a110)
46#define CPU_SA1100_MASK (0xfffffff0)
47#define CPU_SA1110_ID (0x6901b110)
48#define CPU_SA1110_MASK (0xfffffff0)
49
50#define __MREG(x) IOMEM(io_p2v(x)) 39#define __MREG(x) IOMEM(io_p2v(x))
51 40
52#ifndef __ASSEMBLY__ 41#ifndef __ASSEMBLY__
53 42
54#include <asm/cputype.h>
55
56#define CPU_REVISION (read_cpuid_id() & 15)
57
58#define cpu_is_sa1100() ((read_cpuid_id() & CPU_SA1100_MASK) == CPU_SA1100_ID)
59#define cpu_is_sa1110() ((read_cpuid_id() & CPU_SA1110_MASK) == CPU_SA1110_ID)
60
61# define __REG(x) (*((volatile unsigned long __iomem *)io_p2v(x))) 43# define __REG(x) (*((volatile unsigned long __iomem *)io_p2v(x)))
62# define __PREG(x) (io_v2p((unsigned long)&(x))) 44# define __PREG(x) (io_v2p((unsigned long)&(x)))
63 45
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index d15a7fe51618..c1799dd1d0d9 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -403,6 +403,7 @@ config CPU_V7M
403 bool 403 bool
404 select CPU_32v7M 404 select CPU_32v7M
405 select CPU_ABRT_NOMMU 405 select CPU_ABRT_NOMMU
406 select CPU_CACHE_V7M
406 select CPU_CACHE_NOP 407 select CPU_CACHE_NOP
407 select CPU_PABRT_LEGACY 408 select CPU_PABRT_LEGACY
408 select CPU_THUMBONLY 409 select CPU_THUMBONLY
@@ -518,6 +519,9 @@ config CPU_CACHE_VIPT
518config CPU_CACHE_FA 519config CPU_CACHE_FA
519 bool 520 bool
520 521
522config CPU_CACHE_V7M
523 bool
524
521if MMU 525if MMU
522# The copy-page model 526# The copy-page model
523config CPU_COPY_V4WT 527config CPU_COPY_V4WT
@@ -750,14 +754,14 @@ config CPU_HIGH_VECTOR
750 754
751config CPU_ICACHE_DISABLE 755config CPU_ICACHE_DISABLE
752 bool "Disable I-Cache (I-bit)" 756 bool "Disable I-Cache (I-bit)"
753 depends on CPU_CP15 && !(CPU_ARM720T || CPU_ARM740T || CPU_XSCALE || CPU_XSC3) 757 depends on (CPU_CP15 && !(CPU_ARM720T || CPU_ARM740T || CPU_XSCALE || CPU_XSC3)) || CPU_V7M
754 help 758 help
755 Say Y here to disable the processor instruction cache. Unless 759 Say Y here to disable the processor instruction cache. Unless
756 you have a reason not to or are unsure, say N. 760 you have a reason not to or are unsure, say N.
757 761
758config CPU_DCACHE_DISABLE 762config CPU_DCACHE_DISABLE
759 bool "Disable D-Cache (C-bit)" 763 bool "Disable D-Cache (C-bit)"
760 depends on CPU_CP15 && !SMP 764 depends on (CPU_CP15 && !SMP) || CPU_V7M
761 help 765 help
762 Say Y here to disable the processor data cache. Unless 766 Say Y here to disable the processor data cache. Unless
763 you have a reason not to or are unsure, say N. 767 you have a reason not to or are unsure, say N.
@@ -792,7 +796,7 @@ config CPU_CACHE_ROUND_ROBIN
792 796
793config CPU_BPREDICT_DISABLE 797config CPU_BPREDICT_DISABLE
794 bool "Disable branch prediction" 798 bool "Disable branch prediction"
795 depends on CPU_ARM1020 || CPU_V6 || CPU_V6K || CPU_MOHAWK || CPU_XSC3 || CPU_V7 || CPU_FA526 799 depends on CPU_ARM1020 || CPU_V6 || CPU_V6K || CPU_MOHAWK || CPU_XSC3 || CPU_V7 || CPU_FA526 || CPU_V7M
796 help 800 help
797 Say Y here to disable branch prediction. If unsure, say N. 801 Say Y here to disable branch prediction. If unsure, say N.
798 802
@@ -916,6 +920,13 @@ config CACHE_L2X0
916 help 920 help
917 This option enables the L2x0 PrimeCell. 921 This option enables the L2x0 PrimeCell.
918 922
923config CACHE_L2X0_PMU
924 bool "L2x0 performance monitor support" if CACHE_L2X0
925 depends on PERF_EVENTS
926 help
927 This option enables support for the performance monitoring features
928 of the L220 and PL310 outer cache controllers.
929
919if CACHE_L2X0 930if CACHE_L2X0
920 931
921config PL310_ERRATA_588369 932config PL310_ERRATA_588369
diff --git a/arch/arm/mm/Makefile b/arch/arm/mm/Makefile
index 7f76d96ce546..e8698241ece9 100644
--- a/arch/arm/mm/Makefile
+++ b/arch/arm/mm/Makefile
@@ -43,9 +43,11 @@ obj-$(CONFIG_CPU_CACHE_V6) += cache-v6.o
43obj-$(CONFIG_CPU_CACHE_V7) += cache-v7.o 43obj-$(CONFIG_CPU_CACHE_V7) += cache-v7.o
44obj-$(CONFIG_CPU_CACHE_FA) += cache-fa.o 44obj-$(CONFIG_CPU_CACHE_FA) += cache-fa.o
45obj-$(CONFIG_CPU_CACHE_NOP) += cache-nop.o 45obj-$(CONFIG_CPU_CACHE_NOP) += cache-nop.o
46obj-$(CONFIG_CPU_CACHE_V7M) += cache-v7m.o
46 47
47AFLAGS_cache-v6.o :=-Wa,-march=armv6 48AFLAGS_cache-v6.o :=-Wa,-march=armv6
48AFLAGS_cache-v7.o :=-Wa,-march=armv7-a 49AFLAGS_cache-v7.o :=-Wa,-march=armv7-a
50AFLAGS_cache-v7m.o :=-Wa,-march=armv7-m
49 51
50obj-$(CONFIG_CPU_COPY_V4WT) += copypage-v4wt.o 52obj-$(CONFIG_CPU_COPY_V4WT) += copypage-v4wt.o
51obj-$(CONFIG_CPU_COPY_V4WB) += copypage-v4wb.o 53obj-$(CONFIG_CPU_COPY_V4WB) += copypage-v4wb.o
@@ -101,6 +103,7 @@ AFLAGS_proc-v7.o :=-Wa,-march=armv7-a
101obj-$(CONFIG_OUTER_CACHE) += l2c-common.o 103obj-$(CONFIG_OUTER_CACHE) += l2c-common.o
102obj-$(CONFIG_CACHE_FEROCEON_L2) += cache-feroceon-l2.o 104obj-$(CONFIG_CACHE_FEROCEON_L2) += cache-feroceon-l2.o
103obj-$(CONFIG_CACHE_L2X0) += cache-l2x0.o l2c-l2x0-resume.o 105obj-$(CONFIG_CACHE_L2X0) += cache-l2x0.o l2c-l2x0-resume.o
106obj-$(CONFIG_CACHE_L2X0_PMU) += cache-l2x0-pmu.o
104obj-$(CONFIG_CACHE_XSC3L2) += cache-xsc3l2.o 107obj-$(CONFIG_CACHE_XSC3L2) += cache-xsc3l2.o
105obj-$(CONFIG_CACHE_TAUROS2) += cache-tauros2.o 108obj-$(CONFIG_CACHE_TAUROS2) += cache-tauros2.o
106obj-$(CONFIG_CACHE_UNIPHIER) += cache-uniphier.o 109obj-$(CONFIG_CACHE_UNIPHIER) += cache-uniphier.o
diff --git a/arch/arm/mm/cache-l2x0-pmu.c b/arch/arm/mm/cache-l2x0-pmu.c
new file mode 100644
index 000000000000..976d3057272e
--- /dev/null
+++ b/arch/arm/mm/cache-l2x0-pmu.c
@@ -0,0 +1,584 @@
1/*
2 * L220/L310 cache controller support
3 *
4 * Copyright (C) 2016 ARM Limited
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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include <linux/errno.h>
20#include <linux/hrtimer.h>
21#include <linux/io.h>
22#include <linux/list.h>
23#include <linux/perf_event.h>
24#include <linux/printk.h>
25#include <linux/slab.h>
26#include <linux/types.h>
27
28#include <asm/hardware/cache-l2x0.h>
29
30#define PMU_NR_COUNTERS 2
31
32static void __iomem *l2x0_base;
33static struct pmu *l2x0_pmu;
34static cpumask_t pmu_cpu;
35
36static const char *l2x0_name;
37
38static ktime_t l2x0_pmu_poll_period;
39static struct hrtimer l2x0_pmu_hrtimer;
40
41/*
42 * The L220/PL310 PMU has two equivalent counters, Counter1 and Counter0.
43 * Registers controlling these are laid out in pairs, in descending order, i.e.
44 * the register for Counter1 comes first, followed by the register for
45 * Counter0.
46 * We ensure that idx 0 -> Counter0, and idx1 -> Counter1.
47 */
48static struct perf_event *events[PMU_NR_COUNTERS];
49
50/* Find an unused counter */
51static int l2x0_pmu_find_idx(void)
52{
53 int i;
54
55 for (i = 0; i < PMU_NR_COUNTERS; i++) {
56 if (!events[i])
57 return i;
58 }
59
60 return -1;
61}
62
63/* How many counters are allocated? */
64static int l2x0_pmu_num_active_counters(void)
65{
66 int i, cnt = 0;
67
68 for (i = 0; i < PMU_NR_COUNTERS; i++) {
69 if (events[i])
70 cnt++;
71 }
72
73 return cnt;
74}
75
76static void l2x0_pmu_counter_config_write(int idx, u32 val)
77{
78 writel_relaxed(val, l2x0_base + L2X0_EVENT_CNT0_CFG - 4 * idx);
79}
80
81static u32 l2x0_pmu_counter_read(int idx)
82{
83 return readl_relaxed(l2x0_base + L2X0_EVENT_CNT0_VAL - 4 * idx);
84}
85
86static void l2x0_pmu_counter_write(int idx, u32 val)
87{
88 writel_relaxed(val, l2x0_base + L2X0_EVENT_CNT0_VAL - 4 * idx);
89}
90
91static void __l2x0_pmu_enable(void)
92{
93 u32 val = readl_relaxed(l2x0_base + L2X0_EVENT_CNT_CTRL);
94 val |= L2X0_EVENT_CNT_CTRL_ENABLE;
95 writel_relaxed(val, l2x0_base + L2X0_EVENT_CNT_CTRL);
96}
97
98static void __l2x0_pmu_disable(void)
99{
100 u32 val = readl_relaxed(l2x0_base + L2X0_EVENT_CNT_CTRL);
101 val &= ~L2X0_EVENT_CNT_CTRL_ENABLE;
102 writel_relaxed(val, l2x0_base + L2X0_EVENT_CNT_CTRL);
103}
104
105static void l2x0_pmu_enable(struct pmu *pmu)
106{
107 if (l2x0_pmu_num_active_counters() == 0)
108 return;
109
110 __l2x0_pmu_enable();
111}
112
113static void l2x0_pmu_disable(struct pmu *pmu)
114{
115 if (l2x0_pmu_num_active_counters() == 0)
116 return;
117
118 __l2x0_pmu_disable();
119}
120
121static void warn_if_saturated(u32 count)
122{
123 if (count != 0xffffffff)
124 return;
125
126 pr_warn_ratelimited("L2X0 counter saturated. Poll period too long\n");
127}
128
129static void l2x0_pmu_event_read(struct perf_event *event)
130{
131 struct hw_perf_event *hw = &event->hw;
132 u64 prev_count, new_count, mask;
133
134 do {
135 prev_count = local64_read(&hw->prev_count);
136 new_count = l2x0_pmu_counter_read(hw->idx);
137 } while (local64_xchg(&hw->prev_count, new_count) != prev_count);
138
139 mask = GENMASK_ULL(31, 0);
140 local64_add((new_count - prev_count) & mask, &event->count);
141
142 warn_if_saturated(new_count);
143}
144
145static void l2x0_pmu_event_configure(struct perf_event *event)
146{
147 struct hw_perf_event *hw = &event->hw;
148
149 /*
150 * The L2X0 counters saturate at 0xffffffff rather than wrapping, so we
151 * will *always* lose some number of events when a counter saturates,
152 * and have no way of detecting how many were lost.
153 *
154 * To minimize the impact of this, we try to maximize the period by
155 * always starting counters at zero. To ensure that group ratios are
156 * representative, we poll periodically to avoid counters saturating.
157 * See l2x0_pmu_poll().
158 */
159 local64_set(&hw->prev_count, 0);
160 l2x0_pmu_counter_write(hw->idx, 0);
161}
162
163static enum hrtimer_restart l2x0_pmu_poll(struct hrtimer *hrtimer)
164{
165 unsigned long flags;
166 int i;
167
168 local_irq_save(flags);
169 __l2x0_pmu_disable();
170
171 for (i = 0; i < PMU_NR_COUNTERS; i++) {
172 struct perf_event *event = events[i];
173
174 if (!event)
175 continue;
176
177 l2x0_pmu_event_read(event);
178 l2x0_pmu_event_configure(event);
179 }
180
181 __l2x0_pmu_enable();
182 local_irq_restore(flags);
183
184 hrtimer_forward_now(hrtimer, l2x0_pmu_poll_period);
185 return HRTIMER_RESTART;
186}
187
188
189static void __l2x0_pmu_event_enable(int idx, u32 event)
190{
191 u32 val;
192
193 val = event << L2X0_EVENT_CNT_CFG_SRC_SHIFT;
194 val |= L2X0_EVENT_CNT_CFG_INT_DISABLED;
195 l2x0_pmu_counter_config_write(idx, val);
196}
197
198static void l2x0_pmu_event_start(struct perf_event *event, int flags)
199{
200 struct hw_perf_event *hw = &event->hw;
201
202 if (WARN_ON_ONCE(!(event->hw.state & PERF_HES_STOPPED)))
203 return;
204
205 if (flags & PERF_EF_RELOAD) {
206 WARN_ON_ONCE(!(hw->state & PERF_HES_UPTODATE));
207 l2x0_pmu_event_configure(event);
208 }
209
210 hw->state = 0;
211
212 __l2x0_pmu_event_enable(hw->idx, hw->config_base);
213}
214
215static void __l2x0_pmu_event_disable(int idx)
216{
217 u32 val;
218
219 val = L2X0_EVENT_CNT_CFG_SRC_DISABLED << L2X0_EVENT_CNT_CFG_SRC_SHIFT;
220 val |= L2X0_EVENT_CNT_CFG_INT_DISABLED;
221 l2x0_pmu_counter_config_write(idx, val);
222}
223
224static void l2x0_pmu_event_stop(struct perf_event *event, int flags)
225{
226 struct hw_perf_event *hw = &event->hw;
227
228 if (WARN_ON_ONCE(event->hw.state & PERF_HES_STOPPED))
229 return;
230
231 __l2x0_pmu_event_disable(hw->idx);
232
233 hw->state |= PERF_HES_STOPPED;
234
235 if (flags & PERF_EF_UPDATE) {
236 l2x0_pmu_event_read(event);
237 hw->state |= PERF_HES_UPTODATE;
238 }
239}
240
241static int l2x0_pmu_event_add(struct perf_event *event, int flags)
242{
243 struct hw_perf_event *hw = &event->hw;
244 int idx = l2x0_pmu_find_idx();
245
246 if (idx == -1)
247 return -EAGAIN;
248
249 /*
250 * Pin the timer, so that the overflows are handled by the chosen
251 * event->cpu (this is the same one as presented in "cpumask"
252 * attribute).
253 */
254 if (l2x0_pmu_num_active_counters() == 0)
255 hrtimer_start(&l2x0_pmu_hrtimer, l2x0_pmu_poll_period,
256 HRTIMER_MODE_REL_PINNED);
257
258 events[idx] = event;
259 hw->idx = idx;
260
261 l2x0_pmu_event_configure(event);
262
263 hw->state = PERF_HES_STOPPED | PERF_HES_UPTODATE;
264
265 if (flags & PERF_EF_START)
266 l2x0_pmu_event_start(event, 0);
267
268 return 0;
269}
270
271static void l2x0_pmu_event_del(struct perf_event *event, int flags)
272{
273 struct hw_perf_event *hw = &event->hw;
274
275 l2x0_pmu_event_stop(event, PERF_EF_UPDATE);
276
277 events[hw->idx] = NULL;
278 hw->idx = -1;
279
280 if (l2x0_pmu_num_active_counters() == 0)
281 hrtimer_cancel(&l2x0_pmu_hrtimer);
282}
283
284static bool l2x0_pmu_group_is_valid(struct perf_event *event)
285{
286 struct pmu *pmu = event->pmu;
287 struct perf_event *leader = event->group_leader;
288 struct perf_event *sibling;
289 int num_hw = 0;
290
291 if (leader->pmu == pmu)
292 num_hw++;
293 else if (!is_software_event(leader))
294 return false;
295
296 list_for_each_entry(sibling, &leader->sibling_list, group_entry) {
297 if (sibling->pmu == pmu)
298 num_hw++;
299 else if (!is_software_event(sibling))
300 return false;
301 }
302
303 return num_hw <= PMU_NR_COUNTERS;
304}
305
306static int l2x0_pmu_event_init(struct perf_event *event)
307{
308 struct hw_perf_event *hw = &event->hw;
309
310 if (event->attr.type != l2x0_pmu->type)
311 return -ENOENT;
312
313 if (is_sampling_event(event) ||
314 event->attach_state & PERF_ATTACH_TASK)
315 return -EINVAL;
316
317 if (event->attr.exclude_user ||
318 event->attr.exclude_kernel ||
319 event->attr.exclude_hv ||
320 event->attr.exclude_idle ||
321 event->attr.exclude_host ||
322 event->attr.exclude_guest)
323 return -EINVAL;
324
325 if (event->cpu < 0)
326 return -EINVAL;
327
328 if (event->attr.config & ~L2X0_EVENT_CNT_CFG_SRC_MASK)
329 return -EINVAL;
330
331 hw->config_base = event->attr.config;
332
333 if (!l2x0_pmu_group_is_valid(event))
334 return -EINVAL;
335
336 event->cpu = cpumask_first(&pmu_cpu);
337
338 return 0;
339}
340
341struct l2x0_event_attribute {
342 struct device_attribute attr;
343 unsigned int config;
344 bool pl310_only;
345};
346
347#define L2X0_EVENT_ATTR(_name, _config, _pl310_only) \
348 (&((struct l2x0_event_attribute[]) {{ \
349 .attr = __ATTR(_name, S_IRUGO, l2x0_pmu_event_show, NULL), \
350 .config = _config, \
351 .pl310_only = _pl310_only, \
352 }})[0].attr.attr)
353
354#define L220_PLUS_EVENT_ATTR(_name, _config) \
355 L2X0_EVENT_ATTR(_name, _config, false)
356
357#define PL310_EVENT_ATTR(_name, _config) \
358 L2X0_EVENT_ATTR(_name, _config, true)
359
360static ssize_t l2x0_pmu_event_show(struct device *dev,
361 struct device_attribute *attr, char *buf)
362{
363 struct l2x0_event_attribute *lattr;
364
365 lattr = container_of(attr, typeof(*lattr), attr);
366 return snprintf(buf, PAGE_SIZE, "config=0x%x\n", lattr->config);
367}
368
369static umode_t l2x0_pmu_event_attr_is_visible(struct kobject *kobj,
370 struct attribute *attr,
371 int unused)
372{
373 struct device *dev = kobj_to_dev(kobj);
374 struct pmu *pmu = dev_get_drvdata(dev);
375 struct l2x0_event_attribute *lattr;
376
377 lattr = container_of(attr, typeof(*lattr), attr.attr);
378
379 if (!lattr->pl310_only || strcmp("l2c_310", pmu->name) == 0)
380 return attr->mode;
381
382 return 0;
383}
384
385static struct attribute *l2x0_pmu_event_attrs[] = {
386 L220_PLUS_EVENT_ATTR(co, 0x1),
387 L220_PLUS_EVENT_ATTR(drhit, 0x2),
388 L220_PLUS_EVENT_ATTR(drreq, 0x3),
389 L220_PLUS_EVENT_ATTR(dwhit, 0x4),
390 L220_PLUS_EVENT_ATTR(dwreq, 0x5),
391 L220_PLUS_EVENT_ATTR(dwtreq, 0x6),
392 L220_PLUS_EVENT_ATTR(irhit, 0x7),
393 L220_PLUS_EVENT_ATTR(irreq, 0x8),
394 L220_PLUS_EVENT_ATTR(wa, 0x9),
395 PL310_EVENT_ATTR(ipfalloc, 0xa),
396 PL310_EVENT_ATTR(epfhit, 0xb),
397 PL310_EVENT_ATTR(epfalloc, 0xc),
398 PL310_EVENT_ATTR(srrcvd, 0xd),
399 PL310_EVENT_ATTR(srconf, 0xe),
400 PL310_EVENT_ATTR(epfrcvd, 0xf),
401 NULL
402};
403
404static struct attribute_group l2x0_pmu_event_attrs_group = {
405 .name = "events",
406 .attrs = l2x0_pmu_event_attrs,
407 .is_visible = l2x0_pmu_event_attr_is_visible,
408};
409
410static ssize_t l2x0_pmu_cpumask_show(struct device *dev,
411 struct device_attribute *attr, char *buf)
412{
413 return cpumap_print_to_pagebuf(true, buf, &pmu_cpu);
414}
415
416static struct device_attribute l2x0_pmu_cpumask_attr =
417 __ATTR(cpumask, S_IRUGO, l2x0_pmu_cpumask_show, NULL);
418
419static struct attribute *l2x0_pmu_cpumask_attrs[] = {
420 &l2x0_pmu_cpumask_attr.attr,
421 NULL,
422};
423
424static struct attribute_group l2x0_pmu_cpumask_attr_group = {
425 .attrs = l2x0_pmu_cpumask_attrs,
426};
427
428static const struct attribute_group *l2x0_pmu_attr_groups[] = {
429 &l2x0_pmu_event_attrs_group,
430 &l2x0_pmu_cpumask_attr_group,
431 NULL,
432};
433
434static void l2x0_pmu_reset(void)
435{
436 int i;
437
438 __l2x0_pmu_disable();
439
440 for (i = 0; i < PMU_NR_COUNTERS; i++)
441 __l2x0_pmu_event_disable(i);
442}
443
444static int l2x0_pmu_offline_cpu(unsigned int cpu)
445{
446 unsigned int target;
447
448 if (!cpumask_test_and_clear_cpu(cpu, &pmu_cpu))
449 return 0;
450
451 target = cpumask_any_but(cpu_online_mask, cpu);
452 if (target >= nr_cpu_ids)
453 return 0;
454
455 perf_pmu_migrate_context(l2x0_pmu, cpu, target);
456 cpumask_set_cpu(target, &pmu_cpu);
457
458 return 0;
459}
460
461void l2x0_pmu_suspend(void)
462{
463 int i;
464
465 if (!l2x0_pmu)
466 return;
467
468 l2x0_pmu_disable(l2x0_pmu);
469
470 for (i = 0; i < PMU_NR_COUNTERS; i++) {
471 if (events[i])
472 l2x0_pmu_event_stop(events[i], PERF_EF_UPDATE);
473 }
474
475}
476
477void l2x0_pmu_resume(void)
478{
479 int i;
480
481 if (!l2x0_pmu)
482 return;
483
484 l2x0_pmu_reset();
485
486 for (i = 0; i < PMU_NR_COUNTERS; i++) {
487 if (events[i])
488 l2x0_pmu_event_start(events[i], PERF_EF_RELOAD);
489 }
490
491 l2x0_pmu_enable(l2x0_pmu);
492}
493
494void __init l2x0_pmu_register(void __iomem *base, u32 part)
495{
496 /*
497 * Determine whether we support the PMU, and choose the name for sysfs.
498 * This is also used by l2x0_pmu_event_attr_is_visible to determine
499 * which events to display, as the PL310 PMU supports a superset of
500 * L220 events.
501 *
502 * The L210 PMU has a different programmer's interface, and is not
503 * supported by this driver.
504 *
505 * We must defer registering the PMU until the perf subsystem is up and
506 * running, so just stash the name and base, and leave that to another
507 * initcall.
508 */
509 switch (part & L2X0_CACHE_ID_PART_MASK) {
510 case L2X0_CACHE_ID_PART_L220:
511 l2x0_name = "l2c_220";
512 break;
513 case L2X0_CACHE_ID_PART_L310:
514 l2x0_name = "l2c_310";
515 break;
516 default:
517 return;
518 }
519
520 l2x0_base = base;
521}
522
523static __init int l2x0_pmu_init(void)
524{
525 int ret;
526
527 if (!l2x0_base)
528 return 0;
529
530 l2x0_pmu = kzalloc(sizeof(*l2x0_pmu), GFP_KERNEL);
531 if (!l2x0_pmu) {
532 pr_warn("Unable to allocate L2x0 PMU\n");
533 return -ENOMEM;
534 }
535
536 *l2x0_pmu = (struct pmu) {
537 .task_ctx_nr = perf_invalid_context,
538 .pmu_enable = l2x0_pmu_enable,
539 .pmu_disable = l2x0_pmu_disable,
540 .read = l2x0_pmu_event_read,
541 .start = l2x0_pmu_event_start,
542 .stop = l2x0_pmu_event_stop,
543 .add = l2x0_pmu_event_add,
544 .del = l2x0_pmu_event_del,
545 .event_init = l2x0_pmu_event_init,
546 .attr_groups = l2x0_pmu_attr_groups,
547 };
548
549 l2x0_pmu_reset();
550
551 /*
552 * We always use a hrtimer rather than an interrupt.
553 * See comments in l2x0_pmu_event_configure and l2x0_pmu_poll.
554 *
555 * Polling once a second allows the counters to fill up to 1/128th on a
556 * quad-core test chip with cores clocked at 400MHz. Hopefully this
557 * leaves sufficient headroom to avoid overflow on production silicon
558 * at higher frequencies.
559 */
560 l2x0_pmu_poll_period = ms_to_ktime(1000);
561 hrtimer_init(&l2x0_pmu_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
562 l2x0_pmu_hrtimer.function = l2x0_pmu_poll;
563
564 cpumask_set_cpu(0, &pmu_cpu);
565 ret = cpuhp_setup_state_nocalls(CPUHP_AP_PERF_ARM_L2X0_ONLINE,
566 "AP_PERF_ARM_L2X0_ONLINE", NULL,
567 l2x0_pmu_offline_cpu);
568 if (ret)
569 goto out_pmu;
570
571 ret = perf_pmu_register(l2x0_pmu, l2x0_name, -1);
572 if (ret)
573 goto out_cpuhp;
574
575 return 0;
576
577out_cpuhp:
578 cpuhp_remove_state_nocalls(CPUHP_AP_PERF_ARM_L2X0_ONLINE);
579out_pmu:
580 kfree(l2x0_pmu);
581 l2x0_pmu = NULL;
582 return ret;
583}
584device_initcall(l2x0_pmu_init);
diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
index cc12905ae6f8..d1870c777c6e 100644
--- a/arch/arm/mm/cache-l2x0.c
+++ b/arch/arm/mm/cache-l2x0.c
@@ -142,6 +142,8 @@ static void l2c_disable(void)
142{ 142{
143 void __iomem *base = l2x0_base; 143 void __iomem *base = l2x0_base;
144 144
145 l2x0_pmu_suspend();
146
145 outer_cache.flush_all(); 147 outer_cache.flush_all();
146 l2c_write_sec(0, base, L2X0_CTRL); 148 l2c_write_sec(0, base, L2X0_CTRL);
147 dsb(st); 149 dsb(st);
@@ -159,6 +161,8 @@ static void l2c_resume(void)
159 /* Do not touch the controller if already enabled. */ 161 /* Do not touch the controller if already enabled. */
160 if (!(readl_relaxed(base + L2X0_CTRL) & L2X0_CTRL_EN)) 162 if (!(readl_relaxed(base + L2X0_CTRL) & L2X0_CTRL_EN))
161 l2c_enable(base, l2x0_data->num_lock); 163 l2c_enable(base, l2x0_data->num_lock);
164
165 l2x0_pmu_resume();
162} 166}
163 167
164/* 168/*
@@ -709,9 +713,8 @@ static void __init l2c310_fixup(void __iomem *base, u32 cache_id,
709 if (revision >= L310_CACHE_ID_RTL_R3P0 && 713 if (revision >= L310_CACHE_ID_RTL_R3P0 &&
710 revision < L310_CACHE_ID_RTL_R3P2) { 714 revision < L310_CACHE_ID_RTL_R3P2) {
711 u32 val = l2x0_saved_regs.prefetch_ctrl; 715 u32 val = l2x0_saved_regs.prefetch_ctrl;
712 /* I don't think bit23 is required here... but iMX6 does so */ 716 if (val & L310_PREFETCH_CTRL_DBL_LINEFILL) {
713 if (val & (BIT(30) | BIT(23))) { 717 val &= ~L310_PREFETCH_CTRL_DBL_LINEFILL;
714 val &= ~(BIT(30) | BIT(23));
715 l2x0_saved_regs.prefetch_ctrl = val; 718 l2x0_saved_regs.prefetch_ctrl = val;
716 errata[n++] = "752271"; 719 errata[n++] = "752271";
717 } 720 }
@@ -892,6 +895,8 @@ static int __init __l2c_init(const struct l2c_init_data *data,
892 pr_info("%s: CACHE_ID 0x%08x, AUX_CTRL 0x%08x\n", 895 pr_info("%s: CACHE_ID 0x%08x, AUX_CTRL 0x%08x\n",
893 data->type, cache_id, aux); 896 data->type, cache_id, aux);
894 897
898 l2x0_pmu_register(l2x0_base, cache_id);
899
895 return 0; 900 return 0;
896} 901}
897 902
diff --git a/arch/arm/mm/cache-v7m.S b/arch/arm/mm/cache-v7m.S
new file mode 100644
index 000000000000..816a7e44e6f1
--- /dev/null
+++ b/arch/arm/mm/cache-v7m.S
@@ -0,0 +1,453 @@
1/*
2 * linux/arch/arm/mm/cache-v7m.S
3 *
4 * Based on linux/arch/arm/mm/cache-v7.S
5 *
6 * Copyright (C) 2001 Deep Blue Solutions Ltd.
7 * Copyright (C) 2005 ARM Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This is the "shell" of the ARMv7M processor support.
14 */
15#include <linux/linkage.h>
16#include <linux/init.h>
17#include <asm/assembler.h>
18#include <asm/errno.h>
19#include <asm/unwind.h>
20#include <asm/v7m.h>
21
22#include "proc-macros.S"
23
24/* Generic V7M read/write macros for memory mapped cache operations */
25.macro v7m_cache_read, rt, reg
26 movw \rt, #:lower16:BASEADDR_V7M_SCB + \reg
27 movt \rt, #:upper16:BASEADDR_V7M_SCB + \reg
28 ldr \rt, [\rt]
29.endm
30
31.macro v7m_cacheop, rt, tmp, op, c = al
32 movw\c \tmp, #:lower16:BASEADDR_V7M_SCB + \op
33 movt\c \tmp, #:upper16:BASEADDR_V7M_SCB + \op
34 str\c \rt, [\tmp]
35.endm
36
37
38.macro read_ccsidr, rt
39 v7m_cache_read \rt, V7M_SCB_CCSIDR
40.endm
41
42.macro read_clidr, rt
43 v7m_cache_read \rt, V7M_SCB_CLIDR
44.endm
45
46.macro write_csselr, rt, tmp
47 v7m_cacheop \rt, \tmp, V7M_SCB_CSSELR
48.endm
49
50/*
51 * dcisw: Invalidate data cache by set/way
52 */
53.macro dcisw, rt, tmp
54 v7m_cacheop \rt, \tmp, V7M_SCB_DCISW
55.endm
56
57/*
58 * dccisw: Clean and invalidate data cache by set/way
59 */
60.macro dccisw, rt, tmp
61 v7m_cacheop \rt, \tmp, V7M_SCB_DCCISW
62.endm
63
64/*
65 * dccimvac: Clean and invalidate data cache line by MVA to PoC.
66 */
67.irp c,,eq,ne,cs,cc,mi,pl,vs,vc,hi,ls,ge,lt,gt,le,hs,lo
68.macro dccimvac\c, rt, tmp
69 v7m_cacheop \rt, \tmp, V7M_SCB_DCCIMVAC, \c
70.endm
71.endr
72
73/*
74 * dcimvac: Invalidate data cache line by MVA to PoC
75 */
76.macro dcimvac, rt, tmp
77 v7m_cacheop \rt, \tmp, V7M_SCB_DCIMVAC
78.endm
79
80/*
81 * dccmvau: Clean data cache line by MVA to PoU
82 */
83.macro dccmvau, rt, tmp
84 v7m_cacheop \rt, \tmp, V7M_SCB_DCCMVAU
85.endm
86
87/*
88 * dccmvac: Clean data cache line by MVA to PoC
89 */
90.macro dccmvac, rt, tmp
91 v7m_cacheop \rt, \tmp, V7M_SCB_DCCMVAC
92.endm
93
94/*
95 * icimvau: Invalidate instruction caches by MVA to PoU
96 */
97.macro icimvau, rt, tmp
98 v7m_cacheop \rt, \tmp, V7M_SCB_ICIMVAU
99.endm
100
101/*
102 * Invalidate the icache, inner shareable if SMP, invalidate BTB for UP.
103 * rt data ignored by ICIALLU(IS), so can be used for the address
104 */
105.macro invalidate_icache, rt
106 v7m_cacheop \rt, \rt, V7M_SCB_ICIALLU
107 mov \rt, #0
108.endm
109
110/*
111 * Invalidate the BTB, inner shareable if SMP.
112 * rt data ignored by BPIALL, so it can be used for the address
113 */
114.macro invalidate_bp, rt
115 v7m_cacheop \rt, \rt, V7M_SCB_BPIALL
116 mov \rt, #0
117.endm
118
119ENTRY(v7m_invalidate_l1)
120 mov r0, #0
121
122 write_csselr r0, r1
123 read_ccsidr r0
124
125 movw r1, #0x7fff
126 and r2, r1, r0, lsr #13
127
128 movw r1, #0x3ff
129
130 and r3, r1, r0, lsr #3 @ NumWays - 1
131 add r2, r2, #1 @ NumSets
132
133 and r0, r0, #0x7
134 add r0, r0, #4 @ SetShift
135
136 clz r1, r3 @ WayShift
137 add r4, r3, #1 @ NumWays
1381: sub r2, r2, #1 @ NumSets--
139 mov r3, r4 @ Temp = NumWays
1402: subs r3, r3, #1 @ Temp--
141 mov r5, r3, lsl r1
142 mov r6, r2, lsl r0
143 orr r5, r5, r6 @ Reg = (Temp<<WayShift)|(NumSets<<SetShift)
144 dcisw r5, r6
145 bgt 2b
146 cmp r2, #0
147 bgt 1b
148 dsb st
149 isb
150 ret lr
151ENDPROC(v7m_invalidate_l1)
152
153/*
154 * v7m_flush_icache_all()
155 *
156 * Flush the whole I-cache.
157 *
158 * Registers:
159 * r0 - set to 0
160 */
161ENTRY(v7m_flush_icache_all)
162 invalidate_icache r0
163 ret lr
164ENDPROC(v7m_flush_icache_all)
165
166/*
167 * v7m_flush_dcache_all()
168 *
169 * Flush the whole D-cache.
170 *
171 * Corrupted registers: r0-r7, r9-r11
172 */
173ENTRY(v7m_flush_dcache_all)
174 dmb @ ensure ordering with previous memory accesses
175 read_clidr r0
176 mov r3, r0, lsr #23 @ move LoC into position
177 ands r3, r3, #7 << 1 @ extract LoC*2 from clidr
178 beq finished @ if loc is 0, then no need to clean
179start_flush_levels:
180 mov r10, #0 @ start clean at cache level 0
181flush_levels:
182 add r2, r10, r10, lsr #1 @ work out 3x current cache level
183 mov r1, r0, lsr r2 @ extract cache type bits from clidr
184 and r1, r1, #7 @ mask of the bits for current cache only
185 cmp r1, #2 @ see what cache we have at this level
186 blt skip @ skip if no cache, or just i-cache
187#ifdef CONFIG_PREEMPT
188 save_and_disable_irqs_notrace r9 @ make cssr&csidr read atomic
189#endif
190 write_csselr r10, r1 @ set current cache level
191 isb @ isb to sych the new cssr&csidr
192 read_ccsidr r1 @ read the new csidr
193#ifdef CONFIG_PREEMPT
194 restore_irqs_notrace r9
195#endif
196 and r2, r1, #7 @ extract the length of the cache lines
197 add r2, r2, #4 @ add 4 (line length offset)
198 movw r4, #0x3ff
199 ands r4, r4, r1, lsr #3 @ find maximum number on the way size
200 clz r5, r4 @ find bit position of way size increment
201 movw r7, #0x7fff
202 ands r7, r7, r1, lsr #13 @ extract max number of the index size
203loop1:
204 mov r9, r7 @ create working copy of max index
205loop2:
206 lsl r6, r4, r5
207 orr r11, r10, r6 @ factor way and cache number into r11
208 lsl r6, r9, r2
209 orr r11, r11, r6 @ factor index number into r11
210 dccisw r11, r6 @ clean/invalidate by set/way
211 subs r9, r9, #1 @ decrement the index
212 bge loop2
213 subs r4, r4, #1 @ decrement the way
214 bge loop1
215skip:
216 add r10, r10, #2 @ increment cache number
217 cmp r3, r10
218 bgt flush_levels
219finished:
220 mov r10, #0 @ swith back to cache level 0
221 write_csselr r10, r3 @ select current cache level in cssr
222 dsb st
223 isb
224 ret lr
225ENDPROC(v7m_flush_dcache_all)
226
227/*
228 * v7m_flush_cache_all()
229 *
230 * Flush the entire cache system.
231 * The data cache flush is now achieved using atomic clean / invalidates
232 * working outwards from L1 cache. This is done using Set/Way based cache
233 * maintenance instructions.
234 * The instruction cache can still be invalidated back to the point of
235 * unification in a single instruction.
236 *
237 */
238ENTRY(v7m_flush_kern_cache_all)
239 stmfd sp!, {r4-r7, r9-r11, lr}
240 bl v7m_flush_dcache_all
241 invalidate_icache r0
242 ldmfd sp!, {r4-r7, r9-r11, lr}
243 ret lr
244ENDPROC(v7m_flush_kern_cache_all)
245
246/*
247 * v7m_flush_cache_all()
248 *
249 * Flush all TLB entries in a particular address space
250 *
251 * - mm - mm_struct describing address space
252 */
253ENTRY(v7m_flush_user_cache_all)
254 /*FALLTHROUGH*/
255
256/*
257 * v7m_flush_cache_range(start, end, flags)
258 *
259 * Flush a range of TLB entries in the specified address space.
260 *
261 * - start - start address (may not be aligned)
262 * - end - end address (exclusive, may not be aligned)
263 * - flags - vm_area_struct flags describing address space
264 *
265 * It is assumed that:
266 * - we have a VIPT cache.
267 */
268ENTRY(v7m_flush_user_cache_range)
269 ret lr
270ENDPROC(v7m_flush_user_cache_all)
271ENDPROC(v7m_flush_user_cache_range)
272
273/*
274 * v7m_coherent_kern_range(start,end)
275 *
276 * Ensure that the I and D caches are coherent within specified
277 * region. This is typically used when code has been written to
278 * a memory region, and will be executed.
279 *
280 * - start - virtual start address of region
281 * - end - virtual end address of region
282 *
283 * It is assumed that:
284 * - the Icache does not read data from the write buffer
285 */
286ENTRY(v7m_coherent_kern_range)
287 /* FALLTHROUGH */
288
289/*
290 * v7m_coherent_user_range(start,end)
291 *
292 * Ensure that the I and D caches are coherent within specified
293 * region. This is typically used when code has been written to
294 * a memory region, and will be executed.
295 *
296 * - start - virtual start address of region
297 * - end - virtual end address of region
298 *
299 * It is assumed that:
300 * - the Icache does not read data from the write buffer
301 */
302ENTRY(v7m_coherent_user_range)
303 UNWIND(.fnstart )
304 dcache_line_size r2, r3
305 sub r3, r2, #1
306 bic r12, r0, r3
3071:
308/*
309 * We use open coded version of dccmvau otherwise USER() would
310 * point at movw instruction.
311 */
312 dccmvau r12, r3
313 add r12, r12, r2
314 cmp r12, r1
315 blo 1b
316 dsb ishst
317 icache_line_size r2, r3
318 sub r3, r2, #1
319 bic r12, r0, r3
3202:
321 icimvau r12, r3
322 add r12, r12, r2
323 cmp r12, r1
324 blo 2b
325 invalidate_bp r0
326 dsb ishst
327 isb
328 ret lr
329 UNWIND(.fnend )
330ENDPROC(v7m_coherent_kern_range)
331ENDPROC(v7m_coherent_user_range)
332
333/*
334 * v7m_flush_kern_dcache_area(void *addr, size_t size)
335 *
336 * Ensure that the data held in the page kaddr is written back
337 * to the page in question.
338 *
339 * - addr - kernel address
340 * - size - region size
341 */
342ENTRY(v7m_flush_kern_dcache_area)
343 dcache_line_size r2, r3
344 add r1, r0, r1
345 sub r3, r2, #1
346 bic r0, r0, r3
3471:
348 dccimvac r0, r3 @ clean & invalidate D line / unified line
349 add r0, r0, r2
350 cmp r0, r1
351 blo 1b
352 dsb st
353 ret lr
354ENDPROC(v7m_flush_kern_dcache_area)
355
356/*
357 * v7m_dma_inv_range(start,end)
358 *
359 * Invalidate the data cache within the specified region; we will
360 * be performing a DMA operation in this region and we want to
361 * purge old data in the cache.
362 *
363 * - start - virtual start address of region
364 * - end - virtual end address of region
365 */
366v7m_dma_inv_range:
367 dcache_line_size r2, r3
368 sub r3, r2, #1
369 tst r0, r3
370 bic r0, r0, r3
371 dccimvacne r0, r3
372 subne r3, r2, #1 @ restore r3, corrupted by v7m's dccimvac
373 tst r1, r3
374 bic r1, r1, r3
375 dccimvacne r1, r3
3761:
377 dcimvac r0, r3
378 add r0, r0, r2
379 cmp r0, r1
380 blo 1b
381 dsb st
382 ret lr
383ENDPROC(v7m_dma_inv_range)
384
385/*
386 * v7m_dma_clean_range(start,end)
387 * - start - virtual start address of region
388 * - end - virtual end address of region
389 */
390v7m_dma_clean_range:
391 dcache_line_size r2, r3
392 sub r3, r2, #1
393 bic r0, r0, r3
3941:
395 dccmvac r0, r3 @ clean D / U line
396 add r0, r0, r2
397 cmp r0, r1
398 blo 1b
399 dsb st
400 ret lr
401ENDPROC(v7m_dma_clean_range)
402
403/*
404 * v7m_dma_flush_range(start,end)
405 * - start - virtual start address of region
406 * - end - virtual end address of region
407 */
408ENTRY(v7m_dma_flush_range)
409 dcache_line_size r2, r3
410 sub r3, r2, #1
411 bic r0, r0, r3
4121:
413 dccimvac r0, r3 @ clean & invalidate D / U line
414 add r0, r0, r2
415 cmp r0, r1
416 blo 1b
417 dsb st
418 ret lr
419ENDPROC(v7m_dma_flush_range)
420
421/*
422 * dma_map_area(start, size, dir)
423 * - start - kernel virtual start address
424 * - size - size of region
425 * - dir - DMA direction
426 */
427ENTRY(v7m_dma_map_area)
428 add r1, r1, r0
429 teq r2, #DMA_FROM_DEVICE
430 beq v7m_dma_inv_range
431 b v7m_dma_clean_range
432ENDPROC(v7m_dma_map_area)
433
434/*
435 * dma_unmap_area(start, size, dir)
436 * - start - kernel virtual start address
437 * - size - size of region
438 * - dir - DMA direction
439 */
440ENTRY(v7m_dma_unmap_area)
441 add r1, r1, r0
442 teq r2, #DMA_TO_DEVICE
443 bne v7m_dma_inv_range
444 ret lr
445ENDPROC(v7m_dma_unmap_area)
446
447 .globl v7m_flush_kern_cache_louis
448 .equ v7m_flush_kern_cache_louis, v7m_flush_kern_cache_all
449
450 __INITDATA
451
452 @ define struct cpu_cache_fns (see <asm/cacheflush.h> and proc-macros.S)
453 define_cache_functions v7m
diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c
index c6834c0cfd1c..a2302aba5df2 100644
--- a/arch/arm/mm/dma-mapping.c
+++ b/arch/arm/mm/dma-mapping.c
@@ -436,7 +436,7 @@ static int __init atomic_pool_init(void)
436 gen_pool_set_algo(atomic_pool, 436 gen_pool_set_algo(atomic_pool,
437 gen_pool_first_fit_order_align, 437 gen_pool_first_fit_order_align,
438 (void *)PAGE_SHIFT); 438 (void *)PAGE_SHIFT);
439 pr_info("DMA: preallocated %zd KiB pool for atomic coherent allocations\n", 439 pr_info("DMA: preallocated %zu KiB pool for atomic coherent allocations\n",
440 atomic_pool_size / 1024); 440 atomic_pool_size / 1024);
441 return 0; 441 return 0;
442 } 442 }
@@ -445,7 +445,7 @@ destroy_genpool:
445 gen_pool_destroy(atomic_pool); 445 gen_pool_destroy(atomic_pool);
446 atomic_pool = NULL; 446 atomic_pool = NULL;
447out: 447out:
448 pr_err("DMA: failed to allocate %zx KiB pool for atomic coherent allocation\n", 448 pr_err("DMA: failed to allocate %zu KiB pool for atomic coherent allocation\n",
449 atomic_pool_size / 1024); 449 atomic_pool_size / 1024);
450 return -ENOMEM; 450 return -ENOMEM;
451} 451}
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index 30fe03f95c85..4001dd15818d 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -243,7 +243,7 @@ __setup("noalign", noalign_setup);
243#define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE 243#define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
244#define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE 244#define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
245 245
246static struct mem_type mem_types[] = { 246static struct mem_type mem_types[] __ro_after_init = {
247 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */ 247 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
248 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED | 248 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
249 L_PTE_SHARED, 249 L_PTE_SHARED,
diff --git a/arch/arm/mm/proc-macros.S b/arch/arm/mm/proc-macros.S
index c671f345266a..0d40c285bd86 100644
--- a/arch/arm/mm/proc-macros.S
+++ b/arch/arm/mm/proc-macros.S
@@ -7,6 +7,10 @@
7#include <asm/asm-offsets.h> 7#include <asm/asm-offsets.h>
8#include <asm/thread_info.h> 8#include <asm/thread_info.h>
9 9
10#ifdef CONFIG_CPU_V7M
11#include <asm/v7m.h>
12#endif
13
10/* 14/*
11 * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm) 15 * vma_vm_mm - get mm pointer from vma pointer (vma->vm_mm)
12 */ 16 */
@@ -70,7 +74,13 @@
70 * on ARMv7. 74 * on ARMv7.
71 */ 75 */
72 .macro dcache_line_size, reg, tmp 76 .macro dcache_line_size, reg, tmp
77#ifdef CONFIG_CPU_V7M
78 movw \tmp, #:lower16:BASEADDR_V7M_SCB + V7M_SCB_CTR
79 movt \tmp, #:upper16:BASEADDR_V7M_SCB + V7M_SCB_CTR
80 ldr \tmp, [\tmp]
81#else
73 mrc p15, 0, \tmp, c0, c0, 1 @ read ctr 82 mrc p15, 0, \tmp, c0, c0, 1 @ read ctr
83#endif
74 lsr \tmp, \tmp, #16 84 lsr \tmp, \tmp, #16
75 and \tmp, \tmp, #0xf @ cache line size encoding 85 and \tmp, \tmp, #0xf @ cache line size encoding
76 mov \reg, #4 @ bytes per word 86 mov \reg, #4 @ bytes per word
@@ -82,7 +92,13 @@
82 * on ARMv7. 92 * on ARMv7.
83 */ 93 */
84 .macro icache_line_size, reg, tmp 94 .macro icache_line_size, reg, tmp
95#ifdef CONFIG_CPU_V7M
96 movw \tmp, #:lower16:BASEADDR_V7M_SCB + V7M_SCB_CTR
97 movt \tmp, #:upper16:BASEADDR_V7M_SCB + V7M_SCB_CTR
98 ldr \tmp, [\tmp]
99#else
85 mrc p15, 0, \tmp, c0, c0, 1 @ read ctr 100 mrc p15, 0, \tmp, c0, c0, 1 @ read ctr
101#endif
86 and \tmp, \tmp, #0xf @ cache line size encoding 102 and \tmp, \tmp, #0xf @ cache line size encoding
87 mov \reg, #4 @ bytes per word 103 mov \reg, #4 @ bytes per word
88 mov \reg, \reg, lsl \tmp @ actual cache line size 104 mov \reg, \reg, lsl \tmp @ actual cache line size
diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S
index 7229d8d0be1a..f6d333f09bfe 100644
--- a/arch/arm/mm/proc-v7m.S
+++ b/arch/arm/mm/proc-v7m.S
@@ -74,14 +74,42 @@ ENTRY(cpu_v7m_do_resume)
74ENDPROC(cpu_v7m_do_resume) 74ENDPROC(cpu_v7m_do_resume)
75#endif 75#endif
76 76
77ENTRY(cpu_cm7_dcache_clean_area)
78 dcache_line_size r2, r3
79 movw r3, #:lower16:BASEADDR_V7M_SCB + V7M_SCB_DCCMVAC
80 movt r3, #:upper16:BASEADDR_V7M_SCB + V7M_SCB_DCCMVAC
81
821: str r0, [r3] @ clean D entry
83 add r0, r0, r2
84 subs r1, r1, r2
85 bhi 1b
86 dsb
87 ret lr
88ENDPROC(cpu_cm7_dcache_clean_area)
89
90ENTRY(cpu_cm7_proc_fin)
91 movw r2, #:lower16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
92 movt r2, #:upper16:(BASEADDR_V7M_SCB + V7M_SCB_CCR)
93 ldr r0, [r2]
94 bic r0, r0, #(V7M_SCB_CCR_DC | V7M_SCB_CCR_IC)
95 str r0, [r2]
96 ret lr
97ENDPROC(cpu_cm7_proc_fin)
98
77 .section ".text.init", #alloc, #execinstr 99 .section ".text.init", #alloc, #execinstr
78 100
101__v7m_cm7_setup:
102 mov r8, #(V7M_SCB_CCR_DC | V7M_SCB_CCR_IC| V7M_SCB_CCR_BP)
103 b __v7m_setup_cont
79/* 104/*
80 * __v7m_setup 105 * __v7m_setup
81 * 106 *
82 * This should be able to cover all ARMv7-M cores. 107 * This should be able to cover all ARMv7-M cores.
83 */ 108 */
84__v7m_setup: 109__v7m_setup:
110 mov r8, 0
111
112__v7m_setup_cont:
85 @ Configure the vector table base address 113 @ Configure the vector table base address
86 ldr r0, =BASEADDR_V7M_SCB 114 ldr r0, =BASEADDR_V7M_SCB
87 ldr r12, =vector_table 115 ldr r12, =vector_table
@@ -104,6 +132,7 @@ __v7m_setup:
104 badr r1, 1f 132 badr r1, 1f
105 ldr r5, [r12, #11 * 4] @ read the SVC vector entry 133 ldr r5, [r12, #11 * 4] @ read the SVC vector entry
106 str r1, [r12, #11 * 4] @ write the temporary SVC vector entry 134 str r1, [r12, #11 * 4] @ write the temporary SVC vector entry
135 dsb
107 mov r6, lr @ save LR 136 mov r6, lr @ save LR
108 ldr sp, =init_thread_union + THREAD_START_SP 137 ldr sp, =init_thread_union + THREAD_START_SP
109 cpsie i 138 cpsie i
@@ -116,15 +145,32 @@ __v7m_setup:
116 mov r1, #1 145 mov r1, #1
117 msr control, r1 @ Thread mode has unpriviledged access 146 msr control, r1 @ Thread mode has unpriviledged access
118 147
148 @ Configure caches (if implemented)
149 teq r8, #0
150 stmneia r12, {r0-r6, lr} @ v7m_invalidate_l1 touches r0-r6
151 blne v7m_invalidate_l1
152 teq r8, #0 @ re-evalutae condition
153 ldmneia r12, {r0-r6, lr}
154
119 @ Configure the System Control Register to ensure 8-byte stack alignment 155 @ Configure the System Control Register to ensure 8-byte stack alignment
120 @ Note the STKALIGN bit is either RW or RAO. 156 @ Note the STKALIGN bit is either RW or RAO.
121 ldr r12, [r0, V7M_SCB_CCR] @ system control register 157 ldr r0, [r0, V7M_SCB_CCR] @ system control register
122 orr r12, #V7M_SCB_CCR_STKALIGN 158 orr r0, #V7M_SCB_CCR_STKALIGN
123 str r12, [r0, V7M_SCB_CCR] 159 orr r0, r0, r8
160
124 ret lr 161 ret lr
125ENDPROC(__v7m_setup) 162ENDPROC(__v7m_setup)
126 163
164/*
165 * Cortex-M7 processor functions
166 */
167 globl_equ cpu_cm7_proc_init, cpu_v7m_proc_init
168 globl_equ cpu_cm7_reset, cpu_v7m_reset
169 globl_equ cpu_cm7_do_idle, cpu_v7m_do_idle
170 globl_equ cpu_cm7_switch_mm, cpu_v7m_switch_mm
171
127 define_processor_functions v7m, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1 172 define_processor_functions v7m, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
173 define_processor_functions cm7, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1
128 174
129 .section ".rodata" 175 .section ".rodata"
130 string cpu_arch_name, "armv7m" 176 string cpu_arch_name, "armv7m"
@@ -133,6 +179,50 @@ ENDPROC(__v7m_setup)
133 179
134 .section ".proc.info.init", #alloc 180 .section ".proc.info.init", #alloc
135 181
182.macro __v7m_proc name, initfunc, cache_fns = nop_cache_fns, hwcaps = 0, proc_fns = v7m_processor_functions
183 .long 0 /* proc_info_list.__cpu_mm_mmu_flags */
184 .long 0 /* proc_info_list.__cpu_io_mmu_flags */
185 initfn \initfunc, \name
186 .long cpu_arch_name
187 .long cpu_elf_name
188 .long HWCAP_HALF | HWCAP_THUMB | HWCAP_FAST_MULT | \hwcaps
189 .long cpu_v7m_name
190 .long \proc_fns
191 .long 0 /* proc_info_list.tlb */
192 .long 0 /* proc_info_list.user */
193 .long \cache_fns
194.endm
195
196 /*
197 * Match ARM Cortex-M7 processor.
198 */
199 .type __v7m_cm7_proc_info, #object
200__v7m_cm7_proc_info:
201 .long 0x410fc270 /* ARM Cortex-M7 0xC27 */
202 .long 0xff0ffff0 /* Mask off revision, patch release */
203 __v7m_proc __v7m_cm7_proc_info, __v7m_cm7_setup, hwcaps = HWCAP_EDSP, cache_fns = v7m_cache_fns, proc_fns = cm7_processor_functions
204 .size __v7m_cm7_proc_info, . - __v7m_cm7_proc_info
205
206 /*
207 * Match ARM Cortex-M4 processor.
208 */
209 .type __v7m_cm4_proc_info, #object
210__v7m_cm4_proc_info:
211 .long 0x410fc240 /* ARM Cortex-M4 0xC24 */
212 .long 0xff0ffff0 /* Mask off revision, patch release */
213 __v7m_proc __v7m_cm4_proc_info, __v7m_setup, hwcaps = HWCAP_EDSP
214 .size __v7m_cm4_proc_info, . - __v7m_cm4_proc_info
215
216 /*
217 * Match ARM Cortex-M3 processor.
218 */
219 .type __v7m_cm3_proc_info, #object
220__v7m_cm3_proc_info:
221 .long 0x410fc230 /* ARM Cortex-M3 0xC23 */
222 .long 0xff0ffff0 /* Mask off revision, patch release */
223 __v7m_proc __v7m_cm3_proc_info, __v7m_setup
224 .size __v7m_cm3_proc_info, . - __v7m_cm3_proc_info
225
136 /* 226 /*
137 * Match any ARMv7-M processor core. 227 * Match any ARMv7-M processor core.
138 */ 228 */
@@ -140,16 +230,6 @@ ENDPROC(__v7m_setup)
140__v7m_proc_info: 230__v7m_proc_info:
141 .long 0x000f0000 @ Required ID value 231 .long 0x000f0000 @ Required ID value
142 .long 0x000f0000 @ Mask for ID 232 .long 0x000f0000 @ Mask for ID
143 .long 0 @ proc_info_list.__cpu_mm_mmu_flags 233 __v7m_proc __v7m_proc_info, __v7m_setup
144 .long 0 @ proc_info_list.__cpu_io_mmu_flags
145 initfn __v7m_setup, __v7m_proc_info @ proc_info_list.__cpu_flush
146 .long cpu_arch_name
147 .long cpu_elf_name
148 .long HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT
149 .long cpu_v7m_name
150 .long v7m_processor_functions @ proc_info_list.proc
151 .long 0 @ proc_info_list.tlb
152 .long 0 @ proc_info_list.user
153 .long nop_cache_fns @ proc_info_list.cache
154 .size __v7m_proc_info, . - __v7m_proc_info 234 .size __v7m_proc_info, . - __v7m_proc_info
155 235
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index a5b5c87e2114..a56fa2a1e9aa 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -19,6 +19,7 @@
19#include <linux/amba/bus.h> 19#include <linux/amba/bus.h>
20#include <linux/sizes.h> 20#include <linux/sizes.h>
21#include <linux/limits.h> 21#include <linux/limits.h>
22#include <linux/clk/clk-conf.h>
22 23
23#include <asm/irq.h> 24#include <asm/irq.h>
24 25
@@ -237,6 +238,10 @@ static int amba_probe(struct device *dev)
237 int ret; 238 int ret;
238 239
239 do { 240 do {
241 ret = of_clk_set_defaults(dev->of_node, false);
242 if (ret < 0)
243 break;
244
240 ret = dev_pm_domain_attach(dev, true); 245 ret = dev_pm_domain_attach(dev, true);
241 if (ret == -EPROBE_DEFER) 246 if (ret == -EPROBE_DEFER)
242 break; 247 break;
diff --git a/drivers/cpufreq/sa1110-cpufreq.c b/drivers/cpufreq/sa1110-cpufreq.c
index b5befc211172..2bac9b6cfeea 100644
--- a/drivers/cpufreq/sa1110-cpufreq.c
+++ b/drivers/cpufreq/sa1110-cpufreq.c
@@ -159,7 +159,7 @@ sdram_calculate_timing(struct sdram_info *sd, u_int cpu_khz,
159 * half speed or use delayed read latching (errata 13). 159 * half speed or use delayed read latching (errata 13).
160 */ 160 */
161 if ((ns_to_cycles(sdram->tck, sd_khz) > 1) || 161 if ((ns_to_cycles(sdram->tck, sd_khz) > 1) ||
162 (CPU_REVISION < CPU_SA1110_B2 && sd_khz < 62000)) 162 (read_cpuid_revision() < ARM_CPU_REV_SA1110_B2 && sd_khz < 62000))
163 sd_khz /= 2; 163 sd_khz /= 2;
164 164
165 sd->mdcnfg = MDCNFG & 0x007f007f; 165 sd->mdcnfg = MDCNFG & 0x007f007f;
diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
index c7efddf6e038..4c09d93d9569 100644
--- a/fs/Kconfig.binfmt
+++ b/fs/Kconfig.binfmt
@@ -89,7 +89,7 @@ config BINFMT_SCRIPT
89 89
90config BINFMT_FLAT 90config BINFMT_FLAT
91 bool "Kernel support for flat binaries" 91 bool "Kernel support for flat binaries"
92 depends on !MMU || M68K 92 depends on !MMU || ARM || M68K
93 depends on !FRV || BROKEN 93 depends on !FRV || BROKEN
94 help 94 help
95 Support uClinux FLAT format binaries. 95 Support uClinux FLAT format binaries.
diff --git a/include/linux/cpuhotplug.h b/include/linux/cpuhotplug.h
index 7b6c446ee17f..a8ffc405f915 100644
--- a/include/linux/cpuhotplug.h
+++ b/include/linux/cpuhotplug.h
@@ -114,6 +114,7 @@ enum cpuhp_state {
114 CPUHP_AP_PERF_S390_SF_ONLINE, 114 CPUHP_AP_PERF_S390_SF_ONLINE,
115 CPUHP_AP_PERF_ARM_CCI_ONLINE, 115 CPUHP_AP_PERF_ARM_CCI_ONLINE,
116 CPUHP_AP_PERF_ARM_CCN_ONLINE, 116 CPUHP_AP_PERF_ARM_CCN_ONLINE,
117 CPUHP_AP_PERF_ARM_L2X0_ONLINE,
117 CPUHP_AP_WORKQUEUE_ONLINE, 118 CPUHP_AP_WORKQUEUE_ONLINE,
118 CPUHP_AP_RCUTREE_ONLINE, 119 CPUHP_AP_RCUTREE_ONLINE,
119 CPUHP_AP_NOTIFY_ONLINE, 120 CPUHP_AP_NOTIFY_ONLINE,