xref: /openbmc/linux/arch/openrisc/include/asm/fixmap.h (revision cd1e565a5b7fa60c349ca8a16db1e61715fe8230)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3  * OpenRISC Linux
4  *
5  * Linux architectural port borrowing liberally from similar works of
6  * others.  All original copyrights apply as per the original source
7  * declaration.
8  *
9  * OpenRISC implementation:
10  * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
11  * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
12  * et al.
13  */
14 
15 #ifndef __ASM_OPENRISC_FIXMAP_H
16 #define __ASM_OPENRISC_FIXMAP_H
17 
18 /* Why exactly do we need 2 empty pages between the top of the fixed
19  * addresses and the top of virtual memory?  Something is using that
20  * memory space but not sure what right now... If you find it, leave
21  * a comment here.
22  */
23 #define FIXADDR_TOP	((unsigned long) (-2*PAGE_SIZE))
24 
25 #include <linux/kernel.h>
26 #include <linux/bug.h>
27 #include <asm/page.h>
28 
29 enum fixed_addresses {
30 	FIX_EARLYCON_MEM_BASE,
31 	__end_of_fixed_addresses
32 };
33 
34 #define FIXADDR_SIZE		(__end_of_fixed_addresses << PAGE_SHIFT)
35 /* FIXADDR_BOTTOM might be a better name here... */
36 #define FIXADDR_START		(FIXADDR_TOP - FIXADDR_SIZE)
37 #define FIXMAP_PAGE_IO		PAGE_KERNEL_NOCACHE
38 
39 extern void __set_fixmap(enum fixed_addresses idx,
40 			 phys_addr_t phys, pgprot_t flags);
41 
42 #define __fix_to_virt(x)	(FIXADDR_TOP - ((x) << PAGE_SHIFT))
43 #define __virt_to_fix(x)	((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
44 
45 /*
46  * 'index to address' translation. If anyone tries to use the idx
47  * directly without tranlation, we catch the bug with a NULL-deference
48  * kernel oops. Illegal ranges of incoming indices are caught too.
49  */
50 static __always_inline unsigned long fix_to_virt(const unsigned int idx)
51 {
52 	/*
53 	 * this branch gets completely eliminated after inlining,
54 	 * except when someone tries to use fixaddr indices in an
55 	 * illegal way. (such as mixing up address types or using
56 	 * out-of-range indices).
57 	 *
58 	 * If it doesn't get removed, the linker will complain
59 	 * loudly with a reasonably clear error message..
60 	 */
61 	if (idx >= __end_of_fixed_addresses)
62 		BUG();
63 
64 	return __fix_to_virt(idx);
65 }
66 
67 static inline unsigned long virt_to_fix(const unsigned long vaddr)
68 {
69 	BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
70 	return __virt_to_fix(vaddr);
71 }
72 
73 #endif
74