blob: c66f7933beaa0952c31601c17559a7eaa83206c2 [file] [log] [blame]
Chris Metcalf867e3592010-05-28 23:09:12 -04001/*
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 * We don't bother with a FIX_HOLE since above the fixmaps
50 * is unmapped memory in any case.
51 */
52enum fixed_addresses {
53#ifdef CONFIG_HIGHMEM
54 FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
55 FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
56#endif
57 __end_of_permanent_fixed_addresses,
58
59 /*
60 * Temporary boot-time mappings, used before ioremap() is functional.
61 * Not currently needed by the Tile architecture.
62 */
63#define NR_FIX_BTMAPS 0
64#if NR_FIX_BTMAPS
65 FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
66 FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS - 1,
67 __end_of_fixed_addresses
68#else
69 __end_of_fixed_addresses = __end_of_permanent_fixed_addresses
70#endif
71};
72
73extern void __set_fixmap(enum fixed_addresses idx,
74 unsigned long phys, pgprot_t flags);
75
76#define set_fixmap(idx, phys) \
77 __set_fixmap(idx, phys, PAGE_KERNEL)
Chris Metcalf867e3592010-05-28 23:09:12 -040078#define clear_fixmap(idx) \
79 __set_fixmap(idx, 0, __pgprot(0))
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
86extern 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 */
93static __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
110static 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 */