2 * linux/arch/arm/kernel/pj4-cp0.c
4 * PJ4 iWMMXt coprocessor context switching and handling
6 * Copyright (c) 2010 Marvell International Inc.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
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>
19 #include <asm/thread_notify.h>
20 #include <asm/cputype.h>
22 static int iwmmxt_do(struct notifier_block
*self
, unsigned long cmd
, void *t
)
24 struct thread_info
*thread
= t
;
27 case THREAD_NOTIFY_FLUSH
:
29 * flush_thread() zeroes thread->fpstate, so no need
30 * to do anything here.
32 * FALLTHROUGH: Ensure we don't try to overwrite our newly
33 * initialised state information on the first fault.
36 case THREAD_NOTIFY_EXIT
:
37 iwmmxt_task_release(thread
);
40 case THREAD_NOTIFY_SWITCH
:
41 iwmmxt_task_switch(thread
);
48 static struct notifier_block __maybe_unused iwmmxt_notifier_block
= {
49 .notifier_call
= iwmmxt_do
,
53 static u32 __init
pj4_cp_access_read(void)
57 __asm__
__volatile__ (
58 "mrc p15, 0, %0, c1, c0, 2\n\t"
63 static void __init
pj4_cp_access_write(u32 value
)
67 __asm__
__volatile__ (
68 "mcr p15, 0, %1, c1, c0, 2\n\t"
69 #ifdef CONFIG_THUMB2_KERNEL
72 "mrc p15, 0, %0, c1, c0, 2\n\t"
76 : "=r" (temp
) : "r" (value
));
79 static int __init
pj4_get_iwmmxt_version(void)
83 cp_access
= pj4_cp_access_read();
84 pj4_cp_access_write(cp_access
| 0xf);
86 /* check if coprocessor 0 and 1 are available */
87 if ((pj4_cp_access_read() & 0xf) != 0xf) {
88 pj4_cp_access_write(cp_access
);
92 /* read iWMMXt coprocessor id register p1, c0 */
93 __asm__
__volatile__ ("mrc p1, 0, %0, c0, c0, 0\n" : "=r" (wcid
));
95 pj4_cp_access_write(cp_access
);
98 if ((wcid
& 0xffffff00) == 0x56051000)
101 if ((wcid
& 0xffffff00) == 0x56052000)
108 * Disable CP0/CP1 on boot, and let call_fpe() and the iWMMXt lazy
109 * switch code handle iWMMXt context switching.
111 static int __init
pj4_cp0_init(void)
113 u32 __maybe_unused cp_access
;
119 vers
= pj4_get_iwmmxt_version();
123 #ifndef CONFIG_IWMMXT
124 pr_info("PJ4 iWMMXt coprocessor detected, but kernel support is missing.\n");
126 cp_access
= pj4_cp_access_read() & ~0xf;
127 pj4_cp_access_write(cp_access
);
129 pr_info("PJ4 iWMMXt v%d coprocessor enabled.\n", vers
);
130 elf_hwcap
|= HWCAP_IWMMXT
;
131 thread_register_notifier(&iwmmxt_notifier_block
);
137 late_initcall(pj4_cp0_init
);