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> 22bb898558SAl Viro #ifdef CONFIG_X86_32 23c577b098SGustavo F. Padovan #include <linux/threads.h> 24c577b098SGustavo F. Padovan #include <asm/kmap_types.h> 25bb898558SAl Viro #else 26c577b098SGustavo F. Padovan #include <asm/vsyscall.h> 27c577b098SGustavo F. Padovan #endif 28c577b098SGustavo F. Padovan 29c577b098SGustavo F. Padovan /* 30c577b098SGustavo F. Padovan * We can't declare FIXADDR_TOP as variable for x86_64 because vsyscall 31c577b098SGustavo F. Padovan * uses fixmaps that relies on FIXADDR_TOP for proper address calculation. 32c577b098SGustavo F. Padovan * Because of this, FIXADDR_TOP x86 integration was left as later work. 33c577b098SGustavo F. Padovan */ 34c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32 35c577b098SGustavo F. Padovan /* used by vmalloc.c, vsyscall.lds.S. 36c577b098SGustavo F. Padovan * 37c577b098SGustavo F. Padovan * Leave one empty page between vmalloc'ed areas and 38c577b098SGustavo F. Padovan * the start of the fixmap. 39c577b098SGustavo F. Padovan */ 40c577b098SGustavo F. Padovan extern unsigned long __FIXADDR_TOP; 41c577b098SGustavo F. Padovan #define FIXADDR_TOP ((unsigned long)__FIXADDR_TOP) 42c577b098SGustavo F. Padovan 43c577b098SGustavo F. Padovan #define FIXADDR_USER_START __fix_to_virt(FIX_VDSO) 44c577b098SGustavo F. Padovan #define FIXADDR_USER_END __fix_to_virt(FIX_VDSO - 1) 45c577b098SGustavo F. Padovan #else 46c577b098SGustavo F. Padovan #define FIXADDR_TOP (VSYSCALL_END-PAGE_SIZE) 47c577b098SGustavo F. Padovan 48c577b098SGustavo F. Padovan /* Only covers 32bit vsyscalls currently. Need another set for 64bit. */ 49c577b098SGustavo F. Padovan #define FIXADDR_USER_START ((unsigned long)VSYSCALL32_VSYSCALL) 50c577b098SGustavo F. Padovan #define FIXADDR_USER_END (FIXADDR_USER_START + PAGE_SIZE) 51c577b098SGustavo F. Padovan #endif 52c577b098SGustavo F. Padovan 53c577b098SGustavo F. Padovan 54c577b098SGustavo F. Padovan /* 55c577b098SGustavo F. Padovan * Here we define all the compile-time 'special' virtual 56c577b098SGustavo F. Padovan * addresses. The point is to have a constant address at 57c577b098SGustavo F. Padovan * compile time, but to set the physical address only 58c577b098SGustavo F. Padovan * in the boot process. 59c577b098SGustavo F. Padovan * for x86_32: We allocate these special addresses 60c577b098SGustavo F. Padovan * from the end of virtual memory (0xfffff000) backwards. 61c577b098SGustavo F. Padovan * Also this lets us do fail-safe vmalloc(), we 62c577b098SGustavo F. Padovan * can guarantee that these special addresses and 63c577b098SGustavo F. Padovan * vmalloc()-ed addresses never overlap. 64c577b098SGustavo F. Padovan * 65c577b098SGustavo F. Padovan * These 'compile-time allocated' memory buffers are 66c577b098SGustavo F. Padovan * fixed-size 4k pages (or larger if used with an increment 67c577b098SGustavo F. Padovan * higher than 1). Use set_fixmap(idx,phys) to associate 68c577b098SGustavo F. Padovan * physical memory with fixmap indices. 69c577b098SGustavo F. Padovan * 70c577b098SGustavo F. Padovan * TLB entries of such buffers will not be flushed across 71c577b098SGustavo F. Padovan * task switches. 72c577b098SGustavo F. Padovan */ 73c577b098SGustavo F. Padovan enum fixed_addresses { 74c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32 75c577b098SGustavo F. Padovan FIX_HOLE, 76c577b098SGustavo F. Padovan FIX_VDSO, 77c577b098SGustavo F. Padovan #else 78c577b098SGustavo F. Padovan VSYSCALL_LAST_PAGE, 79c577b098SGustavo F. Padovan VSYSCALL_FIRST_PAGE = VSYSCALL_LAST_PAGE 80c577b098SGustavo F. Padovan + ((VSYSCALL_END-VSYSCALL_START) >> PAGE_SHIFT) - 1, 81c577b098SGustavo F. Padovan VSYSCALL_HPET, 82c577b098SGustavo F. Padovan #endif 83c577b098SGustavo F. Padovan FIX_DBGP_BASE, 84c577b098SGustavo F. Padovan FIX_EARLYCON_MEM_BASE, 85ff30a054SJan Beulich #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 86ff30a054SJan Beulich FIX_OHCI1394_BASE, 87ff30a054SJan Beulich #endif 88c577b098SGustavo F. Padovan #ifdef CONFIG_X86_LOCAL_APIC 89c577b098SGustavo F. Padovan FIX_APIC_BASE, /* local (CPU) APIC) -- required for SMP or not */ 90c577b098SGustavo F. Padovan #endif 91c577b098SGustavo F. Padovan #ifdef CONFIG_X86_IO_APIC 92c577b098SGustavo F. Padovan FIX_IO_APIC_BASE_0, 93c577b098SGustavo F. Padovan FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1, 94c577b098SGustavo F. Padovan #endif 95c577b098SGustavo F. Padovan #ifdef CONFIG_X86_VISWS_APIC 96c577b098SGustavo F. Padovan FIX_CO_CPU, /* Cobalt timer */ 97c577b098SGustavo F. Padovan FIX_CO_APIC, /* Cobalt APIC Redirection Table */ 98c577b098SGustavo F. Padovan FIX_LI_PCIA, /* Lithium PCI Bridge A */ 99c577b098SGustavo F. Padovan FIX_LI_PCIB, /* Lithium PCI Bridge B */ 100c577b098SGustavo F. Padovan #endif 101c577b098SGustavo F. Padovan #ifdef CONFIG_X86_F00F_BUG 102c577b098SGustavo F. Padovan FIX_F00F_IDT, /* Virtual mapping for IDT */ 103c577b098SGustavo F. Padovan #endif 104c577b098SGustavo F. Padovan #ifdef CONFIG_X86_CYCLONE_TIMER 105c577b098SGustavo F. Padovan FIX_CYCLONE_TIMER, /*cyclone timer register*/ 106c577b098SGustavo F. Padovan #endif 107c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32 108c577b098SGustavo F. Padovan FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */ 109c577b098SGustavo F. Padovan FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1, 110c577b098SGustavo F. Padovan #ifdef CONFIG_PCI_MMCONFIG 111c577b098SGustavo F. Padovan FIX_PCIE_MCFG, 112c577b098SGustavo F. Padovan #endif 113c577b098SGustavo F. Padovan #endif 114c577b098SGustavo F. Padovan #ifdef CONFIG_PARAVIRT 115c577b098SGustavo F. Padovan FIX_PARAVIRT_BOOTMAP, 116c577b098SGustavo F. Padovan #endif 11712b9d7ccSMathieu Desnoyers FIX_TEXT_POKE1, /* reserve 2 pages for text_poke() */ 11812b9d7ccSMathieu Desnoyers FIX_TEXT_POKE0, /* first page is last, because allocation is backward */ 119c577b098SGustavo F. Padovan __end_of_permanent_fixed_addresses, 120c577b098SGustavo F. Padovan /* 121c577b098SGustavo F. Padovan * 256 temporary boot-time mappings, used by early_ioremap(), 122c577b098SGustavo F. Padovan * before ioremap() is functional. 123c577b098SGustavo F. Padovan * 124499a5f1eSJan Beulich * If necessary we round it up to the next 256 pages boundary so 125499a5f1eSJan Beulich * that we can have a single pgd entry and a single pte table: 126c577b098SGustavo F. Padovan */ 127c577b098SGustavo F. Padovan #define NR_FIX_BTMAPS 64 128c577b098SGustavo F. Padovan #define FIX_BTMAPS_SLOTS 4 129499a5f1eSJan Beulich #define TOTAL_FIX_BTMAPS (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS) 130499a5f1eSJan Beulich FIX_BTMAP_END = 131499a5f1eSJan Beulich (__end_of_permanent_fixed_addresses ^ 132499a5f1eSJan Beulich (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) & 133499a5f1eSJan Beulich -PTRS_PER_PTE 134499a5f1eSJan Beulich ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 135499a5f1eSJan Beulich (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1)) 136499a5f1eSJan Beulich : __end_of_permanent_fixed_addresses, 137499a5f1eSJan Beulich FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1, 138c577b098SGustavo F. Padovan #ifdef CONFIG_X86_32 139c577b098SGustavo F. Padovan FIX_WP_TEST, 140c577b098SGustavo F. Padovan #endif 14131625340SJoseph Cihula #ifdef CONFIG_INTEL_TXT 14231625340SJoseph Cihula FIX_TBOOT_BASE, 14331625340SJoseph Cihula #endif 144c577b098SGustavo F. Padovan __end_of_fixed_addresses 145c577b098SGustavo F. Padovan }; 146c577b098SGustavo F. Padovan 147c577b098SGustavo F. Padovan 148c577b098SGustavo F. Padovan extern void reserve_top_address(unsigned long reserve); 149c577b098SGustavo F. Padovan 150c577b098SGustavo F. Padovan #define FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT) 151c577b098SGustavo F. Padovan #define FIXADDR_BOOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT) 152c577b098SGustavo F. Padovan #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE) 153c577b098SGustavo F. Padovan #define FIXADDR_BOOT_START (FIXADDR_TOP - FIXADDR_BOOT_SIZE) 154bb898558SAl Viro 155bb898558SAl Viro extern int fixmaps_set; 156bb898558SAl Viro 157fd940934SKeith Packard extern pte_t *kmap_pte; 158fd940934SKeith Packard extern pgprot_t kmap_prot; 159fd940934SKeith Packard extern pte_t *pkmap_page_table; 160fd940934SKeith Packard 161bb898558SAl Viro void __native_set_fixmap(enum fixed_addresses idx, pte_t pte); 162bb898558SAl Viro void native_set_fixmap(enum fixed_addresses idx, 1633b3809acSMasami Hiramatsu phys_addr_t phys, pgprot_t flags); 164bb898558SAl Viro 165bb898558SAl Viro #ifndef CONFIG_PARAVIRT 166bb898558SAl Viro static inline void __set_fixmap(enum fixed_addresses idx, 1673b3809acSMasami Hiramatsu phys_addr_t phys, pgprot_t flags) 168bb898558SAl Viro { 169bb898558SAl Viro native_set_fixmap(idx, phys, flags); 170bb898558SAl Viro } 171bb898558SAl Viro #endif 172bb898558SAl Viro 173bb898558SAl Viro #define set_fixmap(idx, phys) \ 174bb898558SAl Viro __set_fixmap(idx, phys, PAGE_KERNEL) 175bb898558SAl Viro 176bb898558SAl Viro /* 177bb898558SAl Viro * Some hardware wants to get fixmapped without caching. 178bb898558SAl Viro */ 179bb898558SAl Viro #define set_fixmap_nocache(idx, phys) \ 180bb898558SAl Viro __set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE) 181bb898558SAl Viro 182bb898558SAl Viro #define clear_fixmap(idx) \ 183bb898558SAl Viro __set_fixmap(idx, 0, __pgprot(0)) 184bb898558SAl Viro 185bb898558SAl Viro #define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT)) 186bb898558SAl Viro #define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT) 187bb898558SAl Viro 188bb898558SAl Viro extern void __this_fixmap_does_not_exist(void); 189bb898558SAl Viro 190bb898558SAl Viro /* 191bb898558SAl Viro * 'index to address' translation. If anyone tries to use the idx 192bb898558SAl Viro * directly without translation, we catch the bug with a NULL-deference 193bb898558SAl Viro * kernel oops. Illegal ranges of incoming indices are caught too. 194bb898558SAl Viro */ 195bb898558SAl Viro static __always_inline unsigned long fix_to_virt(const unsigned int idx) 196bb898558SAl Viro { 197bb898558SAl Viro /* 198bb898558SAl Viro * this branch gets completely eliminated after inlining, 199bb898558SAl Viro * except when someone tries to use fixaddr indices in an 200bb898558SAl Viro * illegal way. (such as mixing up address types or using 201bb898558SAl Viro * out-of-range indices). 202bb898558SAl Viro * 203bb898558SAl Viro * If it doesn't get removed, the linker will complain 204bb898558SAl Viro * loudly with a reasonably clear error message.. 205bb898558SAl Viro */ 206bb898558SAl Viro if (idx >= __end_of_fixed_addresses) 207bb898558SAl Viro __this_fixmap_does_not_exist(); 208bb898558SAl Viro 209bb898558SAl Viro return __fix_to_virt(idx); 210bb898558SAl Viro } 211bb898558SAl Viro 212bb898558SAl Viro static inline unsigned long virt_to_fix(const unsigned long vaddr) 213bb898558SAl Viro { 214bb898558SAl Viro BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START); 215bb898558SAl Viro return __virt_to_fix(vaddr); 216bb898558SAl Viro } 2175a47c7daSFeng Tang 2185a47c7daSFeng Tang /* Return an pointer with offset calculated */ 2195a47c7daSFeng Tang static inline unsigned long __set_fixmap_offset(enum fixed_addresses idx, 2205a47c7daSFeng Tang phys_addr_t phys, pgprot_t flags) 2215a47c7daSFeng Tang { 2225a47c7daSFeng Tang __set_fixmap(idx, phys, flags); 2235a47c7daSFeng Tang return fix_to_virt(idx) + (phys & (PAGE_SIZE - 1)); 2245a47c7daSFeng Tang } 2255a47c7daSFeng Tang 2265a47c7daSFeng Tang #define set_fixmap_offset(idx, phys) \ 2275a47c7daSFeng Tang __set_fixmap_offset(idx, phys, PAGE_KERNEL) 2285a47c7daSFeng Tang 2295a47c7daSFeng Tang #define set_fixmap_offset_nocache(idx, phys) \ 2305a47c7daSFeng Tang __set_fixmap_offset(idx, phys, PAGE_KERNEL_NOCACHE) 2315a47c7daSFeng Tang 232c577b098SGustavo F. Padovan #endif /* !__ASSEMBLY__ */ 2331965aae3SH. Peter Anvin #endif /* _ASM_X86_FIXMAP_H */ 234