xref: /openbmc/linux/arch/hexagon/include/asm/fixmap.h (revision 12eb4683)
1 /*
2  * Fixmap support for Hexagon - enough to support highmem features
3  *
4  * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 and
8  * only version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18  * 02110-1301, USA.
19  */
20 
21 #ifndef _ASM_FIXMAP_H
22 #define _ASM_FIXMAP_H
23 
24 /*
25  * A lot of the fixmap info is already in mem-layout.h
26  */
27 #include <asm/mem-layout.h>
28 
29 /*
30  * Full fixmap support involves set_fixmap() functions, but
31  * these may not be needed if all we're after is an area for
32  * highmem kernel mappings.
33  */
34 #define	__fix_to_virt(x)	(FIXADDR_TOP - ((x) << PAGE_SHIFT))
35 #define	__virt_to_fix(x)	((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
36 
37 extern void __this_fixmap_does_not_exist(void);
38 
39 /**
40  * fix_to_virt -- "index to address" translation.
41  *
42  * If anyone tries to use the idx directly without translation,
43  * we catch the bug with a NULL-deference kernel oops. Illegal
44  * ranges of incoming indices are caught too.
45  */
46 static inline unsigned long fix_to_virt(const unsigned int idx)
47 {
48 	/*
49 	 * This branch gets completely eliminated after inlining,
50 	 * except when someone tries to use fixaddr indices in an
51 	 * illegal way. (such as mixing up address types or using
52 	 * out-of-range indices).
53 	 *
54 	 * If it doesn't get removed, the linker will complain
55 	 * loudly with a reasonably clear error message..
56 	 */
57 	if (idx >= __end_of_fixed_addresses)
58 		__this_fixmap_does_not_exist();
59 
60 	return __fix_to_virt(idx);
61 }
62 
63 static inline unsigned long virt_to_fix(const unsigned long vaddr)
64 {
65 	BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
66 	return __virt_to_fix(vaddr);
67 }
68 
69 #define kmap_get_fixmap_pte(vaddr) \
70 	pte_offset_kernel(pmd_offset(pud_offset(pgd_offset_k(vaddr), \
71 				(vaddr)), (vaddr)), (vaddr))
72 
73 #endif
74