1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/arch/arm/kernel/pj4-cp0.c
5 * PJ4 iWMMXt coprocessor context switching and handling
7 * Copyright (c) 2010 Marvell International Inc.
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/signal.h>
13 #include <linux/sched.h>
14 #include <linux/init.h>
16 #include <asm/thread_notify.h>
17 #include <asm/cputype.h>
19 static int iwmmxt_do(struct notifier_block
*self
, unsigned long cmd
, void *t
)
21 struct thread_info
*thread
= t
;
24 case THREAD_NOTIFY_FLUSH
:
26 * flush_thread() zeroes thread->fpstate, so no need
27 * to do anything here.
29 * FALLTHROUGH: Ensure we don't try to overwrite our newly
30 * initialised state information on the first fault.
33 case THREAD_NOTIFY_EXIT
:
34 iwmmxt_task_release(thread
);
37 case THREAD_NOTIFY_SWITCH
:
38 iwmmxt_task_switch(thread
);
45 static struct notifier_block __maybe_unused iwmmxt_notifier_block
= {
46 .notifier_call
= iwmmxt_do
,
50 static u32 __init
pj4_cp_access_read(void)
54 __asm__
__volatile__ (
55 "mrc p15, 0, %0, c1, c0, 2\n\t"
60 static void __init
pj4_cp_access_write(u32 value
)
64 __asm__
__volatile__ (
65 "mcr p15, 0, %1, c1, c0, 2\n\t"
66 #ifdef CONFIG_THUMB2_KERNEL
69 "mrc p15, 0, %0, c1, c0, 2\n\t"
73 : "=r" (temp
) : "r" (value
));
76 static int __init
pj4_get_iwmmxt_version(void)
80 cp_access
= pj4_cp_access_read();
81 pj4_cp_access_write(cp_access
| 0xf);
83 /* check if coprocessor 0 and 1 are available */
84 if ((pj4_cp_access_read() & 0xf) != 0xf) {
85 pj4_cp_access_write(cp_access
);
89 /* read iWMMXt coprocessor id register p1, c0 */
90 __asm__
__volatile__ ("mrc p1, 0, %0, c0, c0, 0\n" : "=r" (wcid
));
92 pj4_cp_access_write(cp_access
);
95 if ((wcid
& 0xffffff00) == 0x56051000)
98 if ((wcid
& 0xffffff00) == 0x56052000)
105 * Disable CP0/CP1 on boot, and let call_fpe() and the iWMMXt lazy
106 * switch code handle iWMMXt context switching.
108 static int __init
pj4_cp0_init(void)
110 u32 __maybe_unused cp_access
;
116 vers
= pj4_get_iwmmxt_version();
120 #ifndef CONFIG_IWMMXT
121 pr_info("PJ4 iWMMXt coprocessor detected, but kernel support is missing.\n");
123 cp_access
= pj4_cp_access_read() & ~0xf;
124 pj4_cp_access_write(cp_access
);
126 pr_info("PJ4 iWMMXt v%d coprocessor enabled.\n", vers
);
127 elf_hwcap
|= HWCAP_IWMMXT
;
128 thread_register_notifier(&iwmmxt_notifier_block
);
134 late_initcall(pj4_cp0_init
);