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-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * OpenRISC Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Linux architectural port borrowing liberally from similar works of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  * others.  All original copyrights apply as per the original source
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * declaration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9)  * OpenRISC implementation:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)  * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)  * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)  * et al.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef __ASM_OPENRISC_FIXMAP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define __ASM_OPENRISC_FIXMAP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) /* Why exactly do we need 2 empty pages between the top of the fixed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)  * addresses and the top of virtual memory?  Something is using that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)  * memory space but not sure what right now... If you find it, leave
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)  * a comment here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define FIXADDR_TOP	((unsigned long) (-2*PAGE_SIZE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/page.h>
^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)  * On OpenRISC we use these special fixed_addresses for doing ioremap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)  * early in the boot process before memory initialization is complete.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)  * This is used, in particular, by the early serial console code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)  * It's not really 'fixmap', per se, but fits loosely into the same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)  * paradigm.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) enum fixed_addresses {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	 * FIX_IOREMAP entries are useful for mapping physical address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	 * space before ioremap() is useable, e.g. really early in boot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	 * before kmalloc() is working.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define FIX_N_IOREMAPS  32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	FIX_IOREMAP_BEGIN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	FIX_IOREMAP_END = FIX_IOREMAP_BEGIN + FIX_N_IOREMAPS - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	__end_of_fixed_addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define FIXADDR_SIZE		(__end_of_fixed_addresses << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /* FIXADDR_BOTTOM might be a better name here... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define FIXADDR_START		(FIXADDR_TOP - FIXADDR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define __fix_to_virt(x)	(FIXADDR_TOP - ((x) << PAGE_SHIFT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define __virt_to_fix(x)	((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)  * 'index to address' translation. If anyone tries to use the idx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)  * directly without tranlation, we catch the bug with a NULL-deference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)  * kernel oops. Illegal ranges of incoming indices are caught too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) static __always_inline unsigned long fix_to_virt(const unsigned int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 	 * this branch gets completely eliminated after inlining,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 	 * except when someone tries to use fixaddr indices in an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 	 * illegal way. (such as mixing up address types or using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	 * out-of-range indices).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	 * If it doesn't get removed, the linker will complain
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	 * loudly with a reasonably clear error message..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	if (idx >= __end_of_fixed_addresses)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 		BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	return __fix_to_virt(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static inline unsigned long virt_to_fix(const unsigned long vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	return __virt_to_fix(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #endif