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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * License.  See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * Copyright (C) 2005 Thiemo Seufer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Copyright (C) 2005  MIPS Technologies, Inc.	All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  *	Author: Maciej W. Rozycki <macro@mips.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/addrspace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #ifndef CKSEG2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define CKSEG2 CKSSEG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #ifndef TO_PHYS_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define TO_PHYS_MASK -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  * FUNC is executed in one of the uncached segments, depending on its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  * original address as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  * 1. If the original address is in CKSEG0 or CKSEG1, then the uncached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)  *    segment used is CKSEG1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)  * 2. If the original address is in XKPHYS, then the uncached segment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)  *    used is XKPHYS(2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)  * 3. Otherwise it's a bug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)  * The same remapping is done with the stack pointer.  Stack handling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)  * works because we don't handle stack arguments or more complex return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)  * values, so we can avoid sharing the same stack area between a cached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)  * and the uncached mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) unsigned long run_uncached(void *func)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	register long ret __asm__("$2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	long lfunc = (long)func, ufunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	long usp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	long sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	__asm__("move %0, $sp" : "=r" (sp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	if (sp >= (long)CKSEG0 && sp < (long)CKSEG2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 		usp = CKSEG1ADDR(sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	else if ((long long)sp >= (long long)PHYS_TO_XKPHYS(0, 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 		 (long long)sp < (long long)PHYS_TO_XKPHYS(8, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 		usp = PHYS_TO_XKPHYS(K_CALG_UNCACHED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 				     XKPHYS_TO_PHYS((long long)sp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		usp = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 	if (lfunc >= (long)CKSEG0 && lfunc < (long)CKSEG2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		ufunc = CKSEG1ADDR(lfunc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #ifdef CONFIG_64BIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	else if ((long long)lfunc >= (long long)PHYS_TO_XKPHYS(0, 0) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 		 (long long)lfunc < (long long)PHYS_TO_XKPHYS(8, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		ufunc = PHYS_TO_XKPHYS(K_CALG_UNCACHED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 				       XKPHYS_TO_PHYS((long long)lfunc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 		ufunc = lfunc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	__asm__ __volatile__ (
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 		"	move	$16, $sp\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 		"	move	$sp, %1\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 		"	jalr	%2\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 		"	move	$sp, $16"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 		: "=r" (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 		: "r" (usp), "r" (ufunc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 		: "$16", "$31");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }