Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[linux-2.6/mini2440.git] / arch / arm / kernel / crunch.c
blob99995c2b2312551917f19492194f0b2966425425
1 /*
2 * arch/arm/kernel/crunch.c
3 * Cirrus MaverickCrunch context switching and handling
5 * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/signal.h>
16 #include <linux/sched.h>
17 #include <linux/init.h>
18 #include <linux/io.h>
19 #include <mach/ep93xx-regs.h>
20 #include <asm/thread_notify.h>
22 struct crunch_state *crunch_owner;
24 void crunch_task_release(struct thread_info *thread)
26 local_irq_disable();
27 if (crunch_owner == &thread->crunchstate)
28 crunch_owner = NULL;
29 local_irq_enable();
32 static int crunch_enabled(u32 devcfg)
34 return !!(devcfg & EP93XX_SYSCON_DEVICE_CONFIG_CRUNCH_ENABLE);
37 static int crunch_do(struct notifier_block *self, unsigned long cmd, void *t)
39 struct thread_info *thread = (struct thread_info *)t;
40 struct crunch_state *crunch_state;
41 u32 devcfg;
43 crunch_state = &thread->crunchstate;
45 switch (cmd) {
46 case THREAD_NOTIFY_FLUSH:
47 memset(crunch_state, 0, sizeof(*crunch_state));
50 * FALLTHROUGH: Ensure we don't try to overwrite our newly
51 * initialised state information on the first fault.
54 case THREAD_NOTIFY_RELEASE:
55 crunch_task_release(thread);
56 break;
58 case THREAD_NOTIFY_SWITCH:
59 devcfg = __raw_readl(EP93XX_SYSCON_DEVICE_CONFIG);
60 if (crunch_enabled(devcfg) || crunch_owner == crunch_state) {
61 devcfg ^= EP93XX_SYSCON_DEVICE_CONFIG_CRUNCH_ENABLE;
62 __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
63 __raw_writel(devcfg, EP93XX_SYSCON_DEVICE_CONFIG);
65 break;
68 return NOTIFY_DONE;
71 static struct notifier_block crunch_notifier_block = {
72 .notifier_call = crunch_do,
75 static int __init crunch_init(void)
77 thread_register_notifier(&crunch_notifier_block);
78 elf_hwcap |= HWCAP_CRUNCH;
80 return 0;
83 late_initcall(crunch_init);