1c577b098SGustavo F. Padovan /* 2c577b098SGustavo F. Padovan * fixmap.h: compile-time virtual memory allocation 3c577b098SGustavo F. Padovan * 4c577b098SGustavo F. Padovan * This file is subject to the terms and conditions of the GNU General Public 5c577b098SGustavo F. Padovan * License. See the file "COPYING" in the main directory of this archive 6c577b098SGustavo F. Padovan * for more details. 7c577b098SGustavo F. Padovan * 8c577b098SGustavo F. Padovan * Copyright (C) 1998 Ingo Molnar 9c577b098SGustavo F. Padovan * 10c577b098SGustavo F. Padovan * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 11c577b098SGustavo F. Padovan * x86_32 and x86_64 integration by Gustavo F. Padovan, February 2009 12c577b098SGustavo F. Padovan */ 13c577b098SGustavo F. Padovan 141965aae3SH. Peter Anvin #ifndef _ASM_X86_FIXMAP_H 151965aae3SH. Peter Anvin #define _ASM_X86_FIXMAP_H 16bb898558SAl Viro 17c577b098SGustavo F. Padovan #ifndef __ASSEMBLY__ 18c577b098SGustavo F. Padovan #include <linux/kernel.h> 19c577b098SGustavo F. Padovan #include <asm/acpi.h> 20c577b098SGustavo F. Padovan #include <asm/apicdef.h> 21c577b098SGustavo F. Padovan #include <asm/page.h> 2271056ae2SMarcelo Tosatti #include <asm/pvclock.h> 23bb898558SAl Viro #ifdef CONFIG_X86_32 24c577b098SGustavo F. Padovan #include <linux/threads.h> 25c577b098SGustavo F. Padovan #include <asm/kmap_types.h> 26bb898558SAl Viro #else 27c577b098SGustavo F. Padovan #include <asm/vsyscall.h> 28c577b098SGustavo F. Padovan #endif 29c577b098SGustavo F. Padovan 30c577b098SGustavo F. Padovan /* 31c577b098SGustavo F. Padovan * We can't declare FIXADDR_TOP as variable for x86_64 because vsyscall 32c577b098SGustavo F. Padovan * uses fixmaps that relies on FIXADDR_TOP for proper address calculation. 33c577b098SGustavo F. Padovan * Because of this, FIXADDR_TOP x86 integration was left as later work. 34c577b098SGustavo F. Padovan */ 35c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32 36c577b098SGustavo F. Padovan /* used by vmalloc.c, vsyscall.lds.S. 37c577b098SGustavo F. Padovan * 38c577b098SGustavo F. Padovan * Leave one empty page between vmalloc'ed areas and 39c577b098SGustavo F. Padovan * the start of the fixmap. 40c577b098SGustavo F. Padovan */ 41c577b098SGustavo F. Padovan extern unsigned long __FIXADDR_TOP; 42c577b098SGustavo F. Padovan #define FIXADDR_TOP ((unsigned long)__FIXADDR_TOP) 43c577b098SGustavo F. Padovan 44c577b098SGustavo F. Padovan #define FIXADDR_USER_START __fix_to_virt(FIX_VDSO) 45c577b098SGustavo F. Padovan #define FIXADDR_USER_END __fix_to_virt(FIX_VDSO - 1) 46c577b098SGustavo F. Padovan #else 47c577b098SGustavo F. Padovan #define FIXADDR_TOP (VSYSCALL_END-PAGE_SIZE) 48c577b098SGustavo F. Padovan 49c577b098SGustavo F. Padovan /* Only covers 32bit vsyscalls currently. Need another set for 64bit. */ 50c577b098SGustavo F. Padovan #define FIXADDR_USER_START ((unsigned long)VSYSCALL32_VSYSCALL) 51c577b098SGustavo F. Padovan #define FIXADDR_USER_END (FIXADDR_USER_START + PAGE_SIZE) 52c577b098SGustavo F. Padovan #endif 53c577b098SGustavo F. Padovan 54c577b098SGustavo F. Padovan 55c577b098SGustavo F. Padovan /* 56c577b098SGustavo F. Padovan * Here we define all the compile-time 'special' virtual 57c577b098SGustavo F. Padovan * addresses. The point is to have a constant address at 58c577b098SGustavo F. Padovan * compile time, but to set the physical address only 59c577b098SGustavo F. Padovan * in the boot process. 60c577b098SGustavo F. Padovan * for x86_32: We allocate these special addresses 61c577b098SGustavo F. Padovan * from the end of virtual memory (0xfffff000) backwards. 62c577b098SGustavo F. Padovan * Also this lets us do fail-safe vmalloc(), we 63c577b098SGustavo F. Padovan * can guarantee that these special addresses and 64c577b098SGustavo F. Padovan * vmalloc()-ed addresses never overlap. 65c577b098SGustavo F. Padovan * 66c577b098SGustavo F. Padovan * These 'compile-time allocated' memory buffers are 67c577b098SGustavo F. Padovan * fixed-size 4k pages (or larger if used with an increment 68c577b098SGustavo F. Padovan * higher than 1). Use set_fixmap(idx,phys) to associate 69c577b098SGustavo F. Padovan * physical memory with fixmap indices. 70c577b098SGustavo F. Padovan * 71c577b098SGustavo F. Padovan * TLB entries of such buffers will not be flushed across 72c577b098SGustavo F. Padovan * task switches. 73c577b098SGustavo F. Padovan */ 74c577b098SGustavo F. Padovan enum fixed_addresses { 75c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32 76c577b098SGustavo F. Padovan FIX_HOLE, 77c577b098SGustavo F. Padovan FIX_VDSO, 78c577b098SGustavo F. Padovan #else 79c577b098SGustavo F. Padovan VSYSCALL_LAST_PAGE, 80c577b098SGustavo F. Padovan VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE 81c577b098SGustavo F. Padovan + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1, 829fd67b4eSAndy Lutomirski VVAR_PAGE, 83c577b098SGustavo F. Padovan VSYSCALL_HPET, 84c577b098SGustavo F. Padovan #endif 8571056ae2SMarcelo Tosatti #ifdef CONFIG_PARAVIRT_CLOCK 8671056ae2SMarcelo Tosatti PVCLOCK_FIXMAP_BEGIN, 8771056ae2SMarcelo Tosatti PVCLOCK_FIXMAP_END = PVCLOCK_FIXMAP_BEGIN+PVCLOCK_VSYSCALL_NR_PAGES-1, 8871056ae2SMarcelo Tosatti #endif 89c577b098SGustavo F. Padovan FIX_DBGP_BASE, 90c577b098SGustavo F. Padovan FIX_EARLYCON_MEM_BASE, 91ff30a054SJan Beulich #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 92ff30a054SJan Beulich FIX_OHCI1394_BASE, 93ff30a054SJan Beulich #endif 94c577b098SGustavo F. Padovan #ifdef CONFIG_X86_LOCAL_APIC 95c577b098SGustavo F. Padovan FIX_APIC_BASE, /* local (CPU) APIC) -- required for SMP or not */ 96c577b098SGustavo F. Padovan #endif 97c577b098SGustavo F. Padovan #ifdef CONFIG_X86_IO_APIC 98c577b098SGustavo F. Padovan FIX_IO_APIC_BASE_0, 99c577b098SGustavo F. Padovan FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1, 100c577b098SGustavo F. Padovan #endif 101c577b098SGustavo F. Padovan #ifdef CONFIG_X86_VISWS_APIC 102c577b098SGustavo F. Padovan FIX_CO_CPU, /* Cobalt timer */ 103c577b098SGustavo F. Padovan FIX_CO_APIC, /* Cobalt APIC Redirection Table */ 104c577b098SGustavo F. Padovan FIX_LI_PCIA, /* Lithium PCI Bridge A */ 105c577b098SGustavo F. Padovan FIX_LI_PCIB, /* Lithium PCI Bridge B */ 106c577b098SGustavo F. Padovan #endif 1074eefbe79SKees Cook FIX_RO_IDT, /* Virtual mapping for read-only IDT */ 108c577b098SGustavo F. Padovan #ifdef CONFIG_X86_CYCLONE_TIMER 109c577b098SGustavo F. Padovan FIX_CYCLONE_TIMER, /*cyclone timer register*/ 110c577b098SGustavo F. Padovan #endif 111c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32 112c577b098SGustavo F. Padovan FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */ 113c577b098SGustavo F. Padovan FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1, 114c577b098SGustavo F. Padovan #ifdef CONFIG_PCI_MMCONFIG 115c577b098SGustavo F. Padovan FIX_PCIE_MCFG, 116c577b098SGustavo F. Padovan #endif 117c577b098SGustavo F. Padovan #endif 118c577b098SGustavo F. Padovan #ifdef CONFIG_PARAVIRT 119c577b098SGustavo F. Padovan FIX_PARAVIRT_BOOTMAP, 120c577b098SGustavo F. Padovan #endif 12112b9d7ccSMathieu Desnoyers FIX_TEXT_POKE1, /* reserve 2 pages for text_poke() */ 12212b9d7ccSMathieu Desnoyers FIX_TEXT_POKE0, /* first page is last, because allocation is backward */ 123933b9463SAlan Cox #ifdef CONFIG_X86_INTEL_MID 1247309282cSFeng Tang FIX_LNW_VRTC, 1257309282cSFeng Tang #endif 126fa36e956SArjan van de Ven __end_of_permanent_fixed_addresses, 127fa36e956SArjan van de Ven 128c577b098SGustavo F. Padovan /* 129c577b098SGustavo F. Padovan * 256 temporary boot-time mappings, used by early_ioremap(), 130c577b098SGustavo F. Padovan * before ioremap() is functional. 131c577b098SGustavo F. Padovan * 132499a5f1eSJan Beulich * If necessary we round it up to the next 256 pages boundary so 133499a5f1eSJan Beulich * that we can have a single pgd entry and a single pte table: 134c577b098SGustavo F. Padovan */ 135c577b098SGustavo F. Padovan #define NR_FIX_BTMAPS 64 136c577b098SGustavo F. Padovan #define FIX_BTMAPS_SLOTS 4 137499a5f1eSJan Beulich #define TOTAL_FIX_BTMAPS (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS) 138499a5f1eSJan Beulich FIX_BTMAP_END = 139499a5f1eSJan Beulich (__end_of_permanent_fixed_addresses ^ 140499a5f1eSJan Beulich (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) & 141499a5f1eSJan Beulich -PTRS_PER_PTE 142499a5f1eSJan Beulich ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 143499a5f1eSJan Beulich (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1)) 144499a5f1eSJan Beulich : __end_of_permanent_fixed_addresses, 145499a5f1eSJan Beulich FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1, 146c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32 147c577b098SGustavo F. Padovan FIX_WP_TEST, 148c577b098SGustavo F. Padovan #endif 14931625340SJoseph Cihula #ifdef CONFIG_INTEL_TXT 15031625340SJoseph Cihula FIX_TBOOT_BASE, 15131625340SJoseph Cihula #endif 152c577b098SGustavo F. Padovan __end_of_fixed_addresses 153c577b098SGustavo F. Padovan }; 154c577b098SGustavo F. Padovan 155c577b098SGustavo F. Padovan 156c577b098SGustavo F. Padovan extern void reserve_top_address(unsigned long reserve); 157c577b098SGustavo F. Padovan 158c577b098SGustavo F. Padovan #define FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT) 159c577b098SGustavo F. Padovan #define FIXADDR_BOOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT) 160c577b098SGustavo F. Padovan #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE) 161c577b098SGustavo F. Padovan #define FIXADDR_BOOT_START (FIXADDR_TOP - FIXADDR_BOOT_SIZE) 162bb898558SAl Viro 163bb898558SAl Viro extern int fixmaps_set; 164bb898558SAl Viro 165fd940934SKeith Packard extern pte_t *kmap_pte; 166fd940934SKeith Packard extern pgprot_t kmap_prot; 167fd940934SKeith Packard extern pte_t *pkmap_page_table; 168fd940934SKeith Packard 169bb898558SAl Viro void __native_set_fixmap(enum fixed_addresses idx, pte_t pte); 170bb898558SAl Viro void native_set_fixmap(enum fixed_addresses idx, 1713b3809acSMasami Hiramatsu phys_addr_t phys, pgprot_t flags); 172bb898558SAl Viro 173bb898558SAl Viro #ifndef CONFIG_PARAVIRT 174bb898558SAl Viro static inline void __set_fixmap(enum fixed_addresses idx, 1753b3809acSMasami Hiramatsu phys_addr_t phys, pgprot_t flags) 176bb898558SAl Viro { 177bb898558SAl Viro native_set_fixmap(idx, phys, flags); 178bb898558SAl Viro } 179bb898558SAl Viro #endif 180bb898558SAl Viro 181bb898558SAl Viro #define set_fixmap(idx, phys) \ 182bb898558SAl Viro __set_fixmap(idx, phys, PAGE_KERNEL) 183bb898558SAl Viro 184bb898558SAl Viro /* 185bb898558SAl Viro * Some hardware wants to get fixmapped without caching. 186bb898558SAl Viro */ 187bb898558SAl Viro #define set_fixmap_nocache(idx, phys) \ 188bb898558SAl Viro __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE) 189bb898558SAl Viro 190bb898558SAl Viro #define clear_fixmap(idx) \ 191bb898558SAl Viro __set_fixmap(idx, 0, __pgprot(0)) 192bb898558SAl Viro 193bb898558SAl Viro #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT)) 194bb898558SAl Viro #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT) 195bb898558SAl Viro 196bb898558SAl Viro extern void __this_fixmap_does_not_exist(void); 197bb898558SAl Viro 198bb898558SAl Viro /* 199bb898558SAl Viro * 'index to address' translation. If anyone tries to use the idx 200bb898558SAl Viro * directly without translation, we catch the bug with a NULL-deference 201bb898558SAl Viro * kernel oops. Illegal ranges of incoming indices are caught too. 202bb898558SAl Viro */ 203bb898558SAl Viro static __always_inline unsigned long fix_to_virt(const unsigned int idx) 204bb898558SAl Viro { 205bb898558SAl Viro /* 206bb898558SAl Viro * this branch gets completely eliminated after inlining, 207bb898558SAl Viro * except when someone tries to use fixaddr indices in an 208bb898558SAl Viro * illegal way. (such as mixing up address types or using 209bb898558SAl Viro * out-of-range indices). 210bb898558SAl Viro * 211bb898558SAl Viro * If it doesn't get removed, the linker will complain 212bb898558SAl Viro * loudly with a reasonably clear error message.. 213bb898558SAl Viro */ 214bb898558SAl Viro if (idx >= __end_of_fixed_addresses) 215bb898558SAl Viro __this_fixmap_does_not_exist(); 216bb898558SAl Viro 217bb898558SAl Viro return __fix_to_virt(idx); 218bb898558SAl Viro } 219bb898558SAl Viro 220bb898558SAl Viro static inline unsigned long virt_to_fix(const unsigned long vaddr) 221bb898558SAl Viro { 222bb898558SAl Viro BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START); 223bb898558SAl Viro return __virt_to_fix(vaddr); 224bb898558SAl Viro } 2255a47c7daSFeng Tang 2265a47c7daSFeng Tang /* Return an pointer with offset calculated */ 22791d95fdaSAndrew Morton static __always_inline unsigned long 22891d95fdaSAndrew Morton __set_fixmap_offset(enum fixed_addresses idx, phys_addr_t phys, pgprot_t flags) 2295a47c7daSFeng Tang { 2305a47c7daSFeng Tang __set_fixmap(idx, phys, flags); 2315a47c7daSFeng Tang return fix_to_virt(idx) + (phys & (PAGE_SIZE - 1)); 2325a47c7daSFeng Tang } 2335a47c7daSFeng Tang 2345a47c7daSFeng Tang #define set_fixmap_offset(idx, phys) \ 2355a47c7daSFeng Tang __set_fixmap_offset(idx, phys, PAGE_KERNEL) 2365a47c7daSFeng Tang 2375a47c7daSFeng Tang #define set_fixmap_offset_nocache(idx, phys) \ 2385a47c7daSFeng Tang __set_fixmap_offset(idx, phys, PAGE_KERNEL_NOCACHE) 2395a47c7daSFeng Tang 240c577b098SGustavo F. Padovan #endif /* !__ASSEMBLY__ */ 2411965aae3SH. Peter Anvin #endif /* _ASM_X86_FIXMAP_H */ 242