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