^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * fixmap.h: compile-time virtual memory allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * License. See the file "COPYING" in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Copyright (C) 1998 Ingo Molnar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * x86_32 and x86_64 integration by Gustavo F. Padovan, February 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Break out common bits to asm-generic by Mark Salter, November 2013
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef __ASM_GENERIC_FIXMAP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define __ASM_GENERIC_FIXMAP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/mm_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * 'index to address' translation. If anyone tries to use the idx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * directly without translation, we catch the bug with a NULL-deference
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * kernel oops. Illegal ranges of incoming indices are caught too.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static __always_inline unsigned long fix_to_virt(const unsigned int idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return __fix_to_virt(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static inline unsigned long virt_to_fix(const unsigned long vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) return __virt_to_fix(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * Provide some reasonable defaults for page flags.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * Not all architectures use all of these different types and some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * architectures use different names.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #ifndef FIXMAP_PAGE_NORMAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define FIXMAP_PAGE_NORMAL PAGE_KERNEL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #if !defined(FIXMAP_PAGE_RO) && defined(PAGE_KERNEL_RO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define FIXMAP_PAGE_RO PAGE_KERNEL_RO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #ifndef FIXMAP_PAGE_NOCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #ifndef FIXMAP_PAGE_IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define FIXMAP_PAGE_IO PAGE_KERNEL_IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #ifndef FIXMAP_PAGE_CLEAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define FIXMAP_PAGE_CLEAR __pgprot(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #ifndef set_fixmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define set_fixmap(idx, phys) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) __set_fixmap(idx, phys, FIXMAP_PAGE_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #ifndef clear_fixmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define clear_fixmap(idx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) __set_fixmap(idx, 0, FIXMAP_PAGE_CLEAR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) /* Return a pointer with offset calculated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define __set_fixmap_offset(idx, phys, flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ({ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) unsigned long ________addr; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) __set_fixmap(idx, phys, flags); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ________addr = fix_to_virt(idx) + ((phys) & (PAGE_SIZE - 1)); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ________addr; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define set_fixmap_offset(idx, phys) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NORMAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * Some hardware wants to get fixmapped without caching.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define set_fixmap_nocache(idx, phys) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) __set_fixmap(idx, phys, FIXMAP_PAGE_NOCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define set_fixmap_offset_nocache(idx, phys) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NOCACHE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) * Some fixmaps are for IO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define set_fixmap_io(idx, phys) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) __set_fixmap(idx, phys, FIXMAP_PAGE_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #define set_fixmap_offset_io(idx, phys) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) __set_fixmap_offset(idx, phys, FIXMAP_PAGE_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #endif /* __ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #endif /* __ASM_GENERIC_FIXMAP_H */