Thomas Gleixner | 4505153 | 2019-05-29 16:57:47 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Catalin Marinas | d7f864b | 2008-04-18 22:43:06 +0100 | [diff] [blame] | 2 | /* |
| 3 | * arch/arm/kernel/thumbee.c |
| 4 | * |
| 5 | * Copyright (C) 2008 ARM Limited |
Catalin Marinas | d7f864b | 2008-04-18 22:43:06 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/init.h> |
| 10 | |
Jonathan Austin | 58834ee | 2012-04-12 17:52:10 +0100 | [diff] [blame] | 11 | #include <asm/cputype.h> |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 12 | #include <asm/system_info.h> |
Catalin Marinas | d7f864b | 2008-04-18 22:43:06 +0100 | [diff] [blame] | 13 | #include <asm/thread_notify.h> |
| 14 | |
| 15 | /* |
| 16 | * Access to the ThumbEE Handler Base register |
| 17 | */ |
Catalin Marinas | 7f1fd31 | 2008-11-10 14:14:11 +0000 | [diff] [blame] | 18 | static inline unsigned long teehbr_read(void) |
Catalin Marinas | d7f864b | 2008-04-18 22:43:06 +0100 | [diff] [blame] | 19 | { |
| 20 | unsigned long v; |
| 21 | asm("mrc p14, 6, %0, c1, c0, 0\n" : "=r" (v)); |
| 22 | return v; |
| 23 | } |
| 24 | |
| 25 | static inline void teehbr_write(unsigned long v) |
| 26 | { |
| 27 | asm("mcr p14, 6, %0, c1, c0, 0\n" : : "r" (v)); |
| 28 | } |
| 29 | |
| 30 | static int thumbee_notifier(struct notifier_block *self, unsigned long cmd, void *t) |
| 31 | { |
| 32 | struct thread_info *thread = t; |
| 33 | |
| 34 | switch (cmd) { |
| 35 | case THREAD_NOTIFY_FLUSH: |
Nathan Lynch | fbfb872 | 2014-09-11 02:49:08 +0100 | [diff] [blame] | 36 | teehbr_write(0); |
Catalin Marinas | d7f864b | 2008-04-18 22:43:06 +0100 | [diff] [blame] | 37 | break; |
| 38 | case THREAD_NOTIFY_SWITCH: |
| 39 | current_thread_info()->thumbee_state = teehbr_read(); |
| 40 | teehbr_write(thread->thumbee_state); |
| 41 | break; |
| 42 | } |
| 43 | |
| 44 | return NOTIFY_DONE; |
| 45 | } |
| 46 | |
| 47 | static struct notifier_block thumbee_notifier_block = { |
| 48 | .notifier_call = thumbee_notifier, |
| 49 | }; |
| 50 | |
| 51 | static int __init thumbee_init(void) |
| 52 | { |
| 53 | unsigned long pfr0; |
| 54 | unsigned int cpu_arch = cpu_architecture(); |
| 55 | |
| 56 | if (cpu_arch < CPU_ARCH_ARMv7) |
| 57 | return 0; |
| 58 | |
Jonathan Austin | 58834ee | 2012-04-12 17:52:10 +0100 | [diff] [blame] | 59 | pfr0 = read_cpuid_ext(CPUID_EXT_PFR0); |
Catalin Marinas | d7f864b | 2008-04-18 22:43:06 +0100 | [diff] [blame] | 60 | if ((pfr0 & 0x0000f000) != 0x00001000) |
| 61 | return 0; |
| 62 | |
Russell King | 4ed89f2 | 2014-10-28 11:26:42 +0000 | [diff] [blame] | 63 | pr_info("ThumbEE CPU extension supported.\n"); |
Catalin Marinas | d7f864b | 2008-04-18 22:43:06 +0100 | [diff] [blame] | 64 | elf_hwcap |= HWCAP_THUMBEE; |
| 65 | thread_register_notifier(&thumbee_notifier_block); |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | late_initcall(thumbee_init); |