Merge git://git.kernel.org/pub/scm/linux/kernel/git/cmetcalf/linux-tile
[firefly-linux-kernel-4.4.55.git] / arch / tile / include / asm / fixmap.h
1 /*
2  * Copyright (C) 1998 Ingo Molnar
3  * Copyright 2010 Tilera Corporation. All Rights Reserved.
4  *
5  *   This program is free software; you can redistribute it and/or
6  *   modify it under the terms of the GNU General Public License
7  *   as published by the Free Software Foundation, version 2.
8  *
9  *   This program is distributed in the hope that it will be useful, but
10  *   WITHOUT ANY WARRANTY; without even the implied warranty of
11  *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12  *   NON INFRINGEMENT.  See the GNU General Public License for
13  *   more details.
14  */
15
16 #ifndef _ASM_TILE_FIXMAP_H
17 #define _ASM_TILE_FIXMAP_H
18
19 #include <asm/page.h>
20
21 #ifndef __ASSEMBLY__
22 #include <linux/kernel.h>
23 #ifdef CONFIG_HIGHMEM
24 #include <linux/threads.h>
25 #include <asm/kmap_types.h>
26 #endif
27
28 #define __fix_to_virt(x)        (FIXADDR_TOP - ((x) << PAGE_SHIFT))
29 #define __virt_to_fix(x)        ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
30
31 /*
32  * Here we define all the compile-time 'special' virtual
33  * addresses. The point is to have a constant address at
34  * compile time, but to set the physical address only
35  * in the boot process. We allocate these special addresses
36  * from the end of supervisor virtual memory backwards.
37  * Also this lets us do fail-safe vmalloc(), we
38  * can guarantee that these special addresses and
39  * vmalloc()-ed addresses never overlap.
40  *
41  * these 'compile-time allocated' memory buffers are
42  * fixed-size 4k pages. (or larger if used with an increment
43  * higher than 1) use fixmap_set(idx,phys) to associate
44  * physical memory with fixmap indices.
45  *
46  * TLB entries of such buffers will not be flushed across
47  * task switches.
48  */
49 enum fixed_addresses {
50 #ifdef __tilegx__
51         /*
52          * TILEPro has unmapped memory above so the hole isn't needed,
53          * and in any case the hole pushes us over a single 16MB pmd.
54          */
55         FIX_HOLE,
56 #endif
57 #ifdef CONFIG_HIGHMEM
58         FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
59         FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
60 #endif
61 #ifdef __tilegx__  /* see homecache.c */
62         FIX_HOMECACHE_BEGIN,
63         FIX_HOMECACHE_END = FIX_HOMECACHE_BEGIN+(NR_CPUS)-1,
64 #endif
65         __end_of_permanent_fixed_addresses,
66
67         /*
68          * Temporary boot-time mappings, used before ioremap() is functional.
69          * Not currently needed by the Tile architecture.
70          */
71 #define NR_FIX_BTMAPS   0
72 #if NR_FIX_BTMAPS
73         FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
74         FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS - 1,
75         __end_of_fixed_addresses
76 #else
77         __end_of_fixed_addresses = __end_of_permanent_fixed_addresses
78 #endif
79 };
80
81 #define __FIXADDR_SIZE  (__end_of_permanent_fixed_addresses << PAGE_SHIFT)
82 #define __FIXADDR_BOOT_SIZE     (__end_of_fixed_addresses << PAGE_SHIFT)
83 #define FIXADDR_START           (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_SIZE)
84 #define FIXADDR_BOOT_START      (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_BOOT_SIZE)
85
86 extern void __this_fixmap_does_not_exist(void);
87
88 /*
89  * 'index to address' translation. If anyone tries to use the idx
90  * directly without tranlation, we catch the bug with a NULL-deference
91  * kernel oops. Illegal ranges of incoming indices are caught too.
92  */
93 static __always_inline unsigned long fix_to_virt(const unsigned int idx)
94 {
95         /*
96          * this branch gets completely eliminated after inlining,
97          * except when someone tries to use fixaddr indices in an
98          * illegal way. (such as mixing up address types or using
99          * out-of-range indices).
100          *
101          * If it doesn't get removed, the linker will complain
102          * loudly with a reasonably clear error message..
103          */
104         if (idx >= __end_of_fixed_addresses)
105                 __this_fixmap_does_not_exist();
106
107         return __fix_to_virt(idx);
108 }
109
110 static inline unsigned long virt_to_fix(const unsigned long vaddr)
111 {
112         BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
113         return __virt_to_fix(vaddr);
114 }
115
116 #endif /* !__ASSEMBLY__ */
117
118 #endif /* _ASM_TILE_FIXMAP_H */