Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 1 | /* |
| 2 | * arch/arm/kernel/crunch.c |
| 3 | * Cirrus MaverickCrunch context switching and handling |
| 4 | * |
| 5 | * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org> |
| 6 | * |
| 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. |
| 10 | */ |
| 11 | |
| 12 | #include <linux/module.h> |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 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> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 18 | #include <linux/io.h> |
Ryan Mallon | a6de3df | 2012-01-11 13:14:20 +1100 | [diff] [blame] | 19 | |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 20 | #include <asm/thread_notify.h> |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 21 | |
Ryan Mallon | 9aeec63 | 2012-01-11 12:53:33 +1100 | [diff] [blame] | 22 | #include "soc.h" |
| 23 | |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 24 | struct crunch_state *crunch_owner; |
| 25 | |
| 26 | void crunch_task_release(struct thread_info *thread) |
| 27 | { |
| 28 | local_irq_disable(); |
| 29 | if (crunch_owner == &thread->crunchstate) |
| 30 | crunch_owner = NULL; |
| 31 | local_irq_enable(); |
| 32 | } |
| 33 | |
| 34 | static int crunch_enabled(u32 devcfg) |
| 35 | { |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 36 | return !!(devcfg & EP93XX_SYSCON_DEVCFG_CPENA); |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | static int crunch_do(struct notifier_block *self, unsigned long cmd, void *t) |
| 40 | { |
| 41 | struct thread_info *thread = (struct thread_info *)t; |
| 42 | struct crunch_state *crunch_state; |
| 43 | u32 devcfg; |
| 44 | |
| 45 | crunch_state = &thread->crunchstate; |
| 46 | |
| 47 | switch (cmd) { |
| 48 | case THREAD_NOTIFY_FLUSH: |
| 49 | memset(crunch_state, 0, sizeof(*crunch_state)); |
| 50 | |
| 51 | /* |
| 52 | * FALLTHROUGH: Ensure we don't try to overwrite our newly |
| 53 | * initialised state information on the first fault. |
| 54 | */ |
| 55 | |
Russell King | 797245f | 2009-12-18 14:34:43 +0000 | [diff] [blame] | 56 | case THREAD_NOTIFY_EXIT: |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 57 | crunch_task_release(thread); |
| 58 | break; |
| 59 | |
| 60 | case THREAD_NOTIFY_SWITCH: |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 61 | devcfg = __raw_readl(EP93XX_SYSCON_DEVCFG); |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 62 | if (crunch_enabled(devcfg) || crunch_owner == crunch_state) { |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 63 | /* |
| 64 | * We don't use ep93xx_syscon_swlocked_write() here |
| 65 | * because we are on the context switch path and |
| 66 | * preemption is already disabled. |
| 67 | */ |
| 68 | devcfg ^= EP93XX_SYSCON_DEVCFG_CPENA; |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 69 | __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK); |
Hartley Sweeten | 02239f0 | 2009-07-08 02:00:49 +0100 | [diff] [blame] | 70 | __raw_writel(devcfg, EP93XX_SYSCON_DEVCFG); |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 71 | } |
| 72 | break; |
| 73 | } |
| 74 | |
| 75 | return NOTIFY_DONE; |
| 76 | } |
| 77 | |
| 78 | static struct notifier_block crunch_notifier_block = { |
| 79 | .notifier_call = crunch_do, |
| 80 | }; |
| 81 | |
Shawn Guo | c914283 | 2012-04-26 10:05:15 +0800 | [diff] [blame] | 82 | int __init crunch_init(void) |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 83 | { |
| 84 | thread_register_notifier(&crunch_notifier_block); |
Lennert Buytenhek | fac105d | 2007-02-05 00:35:37 +0100 | [diff] [blame] | 85 | elf_hwcap |= HWCAP_CRUNCH; |
Lennert Buytenhek | c17fad1 | 2006-06-27 23:03:03 +0100 | [diff] [blame] | 86 | |
| 87 | return 0; |
| 88 | } |