| 
									
										
										
										
											2008-04-18 22:43:06 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * arch/arm/kernel/thumbee.c | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2008 ARM Limited | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License version 2 as | 
					
						
							|  |  |  |  * published by the Free Software Foundation. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <linux/kernel.h>
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 17:52:10 +01:00
										 |  |  | #include <asm/cputype.h>
 | 
					
						
							| 
									
										
										
										
											2012-03-28 18:30:01 +01:00
										 |  |  | #include <asm/system_info.h>
 | 
					
						
							| 
									
										
										
										
											2008-04-18 22:43:06 +01:00
										 |  |  | #include <asm/thread_notify.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * Access to the ThumbEE Handler Base register | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2008-11-10 14:14:11 +00:00
										 |  |  | static inline unsigned long teehbr_read(void) | 
					
						
							| 
									
										
										
										
											2008-04-18 22:43:06 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned long v; | 
					
						
							|  |  |  | 	asm("mrc	p14, 6, %0, c1, c0, 0\n" : "=r" (v)); | 
					
						
							|  |  |  | 	return v; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void teehbr_write(unsigned long v) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	asm("mcr	p14, 6, %0, c1, c0, 0\n" : : "r" (v)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int thumbee_notifier(struct notifier_block *self, unsigned long cmd, void *t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct thread_info *thread = t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (cmd) { | 
					
						
							|  |  |  | 	case THREAD_NOTIFY_FLUSH: | 
					
						
							| 
									
										
										
										
											2014-09-11 02:49:08 +01:00
										 |  |  | 		teehbr_write(0); | 
					
						
							| 
									
										
										
										
											2008-04-18 22:43:06 +01:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case THREAD_NOTIFY_SWITCH: | 
					
						
							|  |  |  | 		current_thread_info()->thumbee_state = teehbr_read(); | 
					
						
							|  |  |  | 		teehbr_write(thread->thumbee_state); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return NOTIFY_DONE; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct notifier_block thumbee_notifier_block = { | 
					
						
							|  |  |  | 	.notifier_call	= thumbee_notifier, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int __init thumbee_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long pfr0; | 
					
						
							|  |  |  | 	unsigned int cpu_arch = cpu_architecture(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (cpu_arch < CPU_ARCH_ARMv7) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-12 17:52:10 +01:00
										 |  |  | 	pfr0 = read_cpuid_ext(CPUID_EXT_PFR0); | 
					
						
							| 
									
										
										
										
											2008-04-18 22:43:06 +01:00
										 |  |  | 	if ((pfr0 & 0x0000f000) != 0x00001000) | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	printk(KERN_INFO "ThumbEE CPU extension supported.\n"); | 
					
						
							|  |  |  | 	elf_hwcap |= HWCAP_THUMBEE; | 
					
						
							|  |  |  | 	thread_register_notifier(&thumbee_notifier_block); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | late_initcall(thumbee_init); |