^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) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #ifndef _ASM_X86_FIXMAP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #define _ASM_X86_FIXMAP_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Exposed to assembly code for setting up initial page tables. Cannot be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * calculated in assembly code (fixmap entries are an enum), but is sanity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * checked in the actual fixmap C code to make sure that the fixmap is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * covered fully.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define FIXMAP_PMD_NUM 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) /* fixmap starts downwards from the 507th entry in level2_fixmap_pgt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define FIXMAP_PMD_TOP 507
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/apicdef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/pgtable_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/threads.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <asm/kmap_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <uapi/asm/vsyscall.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * We can't declare FIXADDR_TOP as variable for x86_64 because vsyscall
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * uses fixmaps that relies on FIXADDR_TOP for proper address calculation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * Because of this, FIXADDR_TOP x86 integration was left as later work.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * Leave one empty page between vmalloc'ed areas and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * the start of the fixmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) extern unsigned long __FIXADDR_TOP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define FIXADDR_TOP ((unsigned long)__FIXADDR_TOP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define FIXADDR_TOP (round_up(VSYSCALL_ADDR + PAGE_SIZE, 1<<PMD_SHIFT) - \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) PAGE_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * Here we define all the compile-time 'special' virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * addresses. The point is to have a constant address at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * compile time, but to set the physical address only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * in the boot process.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * for x86_32: We allocate these special addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * from the end of virtual memory (0xfffff000) backwards.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * Also this lets us do fail-safe vmalloc(), we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * can guarantee that these special addresses and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * vmalloc()-ed addresses never overlap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * These 'compile-time allocated' memory buffers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * fixed-size 4k pages (or larger if used with an increment
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * higher than 1). Use set_fixmap(idx,phys) to associate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * physical memory with fixmap indices.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * TLB entries of such buffers will not be flushed across
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * task switches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) enum fixed_addresses {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) FIX_HOLE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #ifdef CONFIG_X86_VSYSCALL_EMULATION
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) VSYSCALL_PAGE = (FIXADDR_TOP - VSYSCALL_ADDR) >> PAGE_SHIFT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) FIX_DBGP_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) FIX_EARLYCON_MEM_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) FIX_OHCI1394_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #ifdef CONFIG_X86_LOCAL_APIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) FIX_APIC_BASE, /* local (CPU) APIC) -- required for SMP or not */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #ifdef CONFIG_X86_IO_APIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) FIX_IO_APIC_BASE_0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) #ifdef CONFIG_PCI_MMCONFIG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) FIX_PCIE_MCFG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #ifdef CONFIG_PARAVIRT_XXL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) FIX_PARAVIRT_BOOTMAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #ifdef CONFIG_X86_INTEL_MID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) FIX_LNW_VRTC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #ifdef CONFIG_ACPI_APEI_GHES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /* Used for GHES mapping from assorted contexts */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) FIX_APEI_GHES_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) FIX_APEI_GHES_NMI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) __end_of_permanent_fixed_addresses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * 512 temporary boot-time mappings, used by early_ioremap(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * before ioremap() is functional.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * If necessary we round it up to the next 512 pages boundary so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * that we can have a single pmd entry and a single pte table:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) #define NR_FIX_BTMAPS 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) #define FIX_BTMAPS_SLOTS 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) #define TOTAL_FIX_BTMAPS (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) FIX_BTMAP_END =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) (__end_of_permanent_fixed_addresses ^
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) -PTRS_PER_PTE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) : __end_of_permanent_fixed_addresses,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) FIX_WP_TEST,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #ifdef CONFIG_INTEL_TXT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) FIX_TBOOT_BASE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) __end_of_fixed_addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) extern void reserve_top_address(unsigned long reserve);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) #define FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) #define FIXADDR_TOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) #define FIXADDR_TOT_START (FIXADDR_TOP - FIXADDR_TOT_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) extern int fixmaps_set;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) extern pte_t *kmap_pte;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) extern pte_t *pkmap_page_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) void __native_set_fixmap(enum fixed_addresses idx, pte_t pte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) void native_set_fixmap(unsigned /* enum fixed_addresses */ idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) phys_addr_t phys, pgprot_t flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) #ifndef CONFIG_PARAVIRT_XXL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static inline void __set_fixmap(enum fixed_addresses idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) phys_addr_t phys, pgprot_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) native_set_fixmap(idx, phys, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * FIXMAP_PAGE_NOCACHE is used for MMIO. Memory encryption is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * supported for MMIO addresses, so make sure that the memory encryption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * mask is not part of the page attributes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) #define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_IO_NOCACHE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * Early memremap routines used for in-place encryption. The mappings created
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * by these routines are intended to be used as temporary mappings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) void __init *early_memremap_encrypted(resource_size_t phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) void __init *early_memremap_encrypted_wp(resource_size_t phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) void __init *early_memremap_decrypted(resource_size_t phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) void __init *early_memremap_decrypted_wp(resource_size_t phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) unsigned long size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) #include <asm-generic/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) #define __late_set_fixmap(idx, phys, flags) __set_fixmap(idx, phys, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #define __late_clear_fixmap(idx) __set_fixmap(idx, 0, __pgprot(0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) void __early_set_fixmap(enum fixed_addresses idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) phys_addr_t phys, pgprot_t flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) #endif /* !__ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #endif /* _ASM_X86_FIXMAP_H */