Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * fixmap.h: compile-time virtual memory allocation
0003  *
0004  * This file is subject to the terms and conditions of the GNU General Public
0005  * License.  See the file "COPYING" in the main directory of this archive
0006  * for more details.
0007  *
0008  * Copyright (C) 1998 Ingo Molnar
0009  *
0010  * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
0011  * x86_32 and x86_64 integration by Gustavo F. Padovan, February 2009
0012  * Break out common bits to asm-generic by Mark Salter, November 2013
0013  */
0014 
0015 #ifndef __ASM_GENERIC_FIXMAP_H
0016 #define __ASM_GENERIC_FIXMAP_H
0017 
0018 #include <linux/bug.h>
0019 #include <linux/mm_types.h>
0020 
0021 #define __fix_to_virt(x)    (FIXADDR_TOP - ((x) << PAGE_SHIFT))
0022 #define __virt_to_fix(x)    ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
0023 
0024 #ifndef __ASSEMBLY__
0025 /*
0026  * 'index to address' translation. If anyone tries to use the idx
0027  * directly without translation, we catch the bug with a NULL-deference
0028  * kernel oops. Illegal ranges of incoming indices are caught too.
0029  */
0030 static __always_inline unsigned long fix_to_virt(const unsigned int idx)
0031 {
0032     BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
0033     return __fix_to_virt(idx);
0034 }
0035 
0036 static inline unsigned long virt_to_fix(const unsigned long vaddr)
0037 {
0038     BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
0039     return __virt_to_fix(vaddr);
0040 }
0041 
0042 /*
0043  * Provide some reasonable defaults for page flags.
0044  * Not all architectures use all of these different types and some
0045  * architectures use different names.
0046  */
0047 #ifndef FIXMAP_PAGE_NORMAL
0048 #define FIXMAP_PAGE_NORMAL PAGE_KERNEL
0049 #endif
0050 #if !defined(FIXMAP_PAGE_RO) && defined(PAGE_KERNEL_RO)
0051 #define FIXMAP_PAGE_RO PAGE_KERNEL_RO
0052 #endif
0053 #ifndef FIXMAP_PAGE_NOCACHE
0054 #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
0055 #endif
0056 #ifndef FIXMAP_PAGE_IO
0057 #define FIXMAP_PAGE_IO PAGE_KERNEL_IO
0058 #endif
0059 #ifndef FIXMAP_PAGE_CLEAR
0060 #define FIXMAP_PAGE_CLEAR __pgprot(0)
0061 #endif
0062 
0063 #ifndef set_fixmap
0064 #define set_fixmap(idx, phys)               \
0065     __set_fixmap(idx, phys, FIXMAP_PAGE_NORMAL)
0066 #endif
0067 
0068 #ifndef clear_fixmap
0069 #define clear_fixmap(idx)           \
0070     __set_fixmap(idx, 0, FIXMAP_PAGE_CLEAR)
0071 #endif
0072 
0073 /* Return a pointer with offset calculated */
0074 #define __set_fixmap_offset(idx, phys, flags)               \
0075 ({                                  \
0076     unsigned long ________addr;                 \
0077     __set_fixmap(idx, phys, flags);                 \
0078     ________addr = fix_to_virt(idx) + ((phys) & (PAGE_SIZE - 1));   \
0079     ________addr;                           \
0080 })
0081 
0082 #define set_fixmap_offset(idx, phys) \
0083     __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NORMAL)
0084 
0085 /*
0086  * Some hardware wants to get fixmapped without caching.
0087  */
0088 #define set_fixmap_nocache(idx, phys) \
0089     __set_fixmap(idx, phys, FIXMAP_PAGE_NOCACHE)
0090 
0091 #define set_fixmap_offset_nocache(idx, phys) \
0092     __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NOCACHE)
0093 
0094 /*
0095  * Some fixmaps are for IO
0096  */
0097 #define set_fixmap_io(idx, phys) \
0098     __set_fixmap(idx, phys, FIXMAP_PAGE_IO)
0099 
0100 #define set_fixmap_offset_io(idx, phys) \
0101     __set_fixmap_offset(idx, phys, FIXMAP_PAGE_IO)
0102 
0103 #endif /* __ASSEMBLY__ */
0104 #endif /* __ASM_GENERIC_FIXMAP_H */