]> git.proxmox.com Git - mirror_ubuntu-kernels.git/blame - arch/openrisc/include/asm/fixmap.h
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-kernels.git] / arch / openrisc / include / asm / fixmap.h
CommitLineData
2874c5fd 1/* SPDX-License-Identifier: GPL-2.0-or-later */
61e85e36
JB
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.
61e85e36
JB
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>
e687448c 26#include <linux/bug.h>
61e85e36
JB
27#include <asm/page.h>
28
29/*
30 * On OpenRISC we use these special fixed_addresses for doing ioremap
31 * early in the boot process before memory initialization is complete.
32 * This is used, in particular, by the early serial console code.
33 *
34 * It's not really 'fixmap', per se, but fits loosely into the same
35 * paradigm.
36 */
37enum fixed_addresses {
38 /*
39 * FIX_IOREMAP entries are useful for mapping physical address
40 * space before ioremap() is useable, e.g. really early in boot
41 * before kmalloc() is working.
42 */
43#define FIX_N_IOREMAPS 32
44 FIX_IOREMAP_BEGIN,
45 FIX_IOREMAP_END = FIX_IOREMAP_BEGIN + FIX_N_IOREMAPS - 1,
46 __end_of_fixed_addresses
47};
48
49#define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
50/* FIXADDR_BOTTOM might be a better name here... */
51#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
52
53#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
54#define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
55
56/*
57 * 'index to address' translation. If anyone tries to use the idx
58 * directly without tranlation, we catch the bug with a NULL-deference
59 * kernel oops. Illegal ranges of incoming indices are caught too.
60 */
61static __always_inline unsigned long fix_to_virt(const unsigned int idx)
62{
63 /*
64 * this branch gets completely eliminated after inlining,
65 * except when someone tries to use fixaddr indices in an
66 * illegal way. (such as mixing up address types or using
67 * out-of-range indices).
68 *
69 * If it doesn't get removed, the linker will complain
70 * loudly with a reasonably clear error message..
71 */
72 if (idx >= __end_of_fixed_addresses)
73 BUG();
74
75 return __fix_to_virt(idx);
76}
77
78static inline unsigned long virt_to_fix(const unsigned long vaddr)
79{
80 BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
81 return __virt_to_fix(vaddr);
82}
83
84#endif