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