Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * arch/arm/kernel/thumbee.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Copyright (C) 2008 ARM Limited
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/cputype.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/system_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/thread_notify.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)  * Access to the ThumbEE Handler Base register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) static inline unsigned long teehbr_read(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	unsigned long v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) 	asm("mrc	p14, 6, %0, c1, c0, 0\n" : "=r" (v));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	return v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static inline void teehbr_write(unsigned long v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 	asm("mcr	p14, 6, %0, c1, c0, 0\n" : : "r" (v));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int thumbee_notifier(struct notifier_block *self, unsigned long cmd, void *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	struct thread_info *thread = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	case THREAD_NOTIFY_FLUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 		teehbr_write(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	case THREAD_NOTIFY_SWITCH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		current_thread_info()->thumbee_state = teehbr_read();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		teehbr_write(thread->thumbee_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static struct notifier_block thumbee_notifier_block = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	.notifier_call	= thumbee_notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static int __init thumbee_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 	unsigned long pfr0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	unsigned int cpu_arch = cpu_architecture();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 	if (cpu_arch < CPU_ARCH_ARMv7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	pfr0 = read_cpuid_ext(CPUID_EXT_PFR0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	if ((pfr0 & 0x0000f000) != 0x00001000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	pr_info("ThumbEE CPU extension supported.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	elf_hwcap |= HWCAP_THUMBEE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	thread_register_notifier(&thumbee_notifier_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) late_initcall(thumbee_init);