162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * fixmap.h: compile-time virtual memory allocation 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public 562306a36Sopenharmony_ci * License. See the file "COPYING" in the main directory of this archive 662306a36Sopenharmony_ci * for more details. 762306a36Sopenharmony_ci * 862306a36Sopenharmony_ci * Copyright (C) 1998 Ingo Molnar 962306a36Sopenharmony_ci * 1062306a36Sopenharmony_ci * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999 1162306a36Sopenharmony_ci * x86_32 and x86_64 integration by Gustavo F. Padovan, February 2009 1262306a36Sopenharmony_ci */ 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci#ifndef _ASM_X86_FIXMAP_H 1562306a36Sopenharmony_ci#define _ASM_X86_FIXMAP_H 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#include <asm/kmap_size.h> 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci/* 2062306a36Sopenharmony_ci * Exposed to assembly code for setting up initial page tables. Cannot be 2162306a36Sopenharmony_ci * calculated in assembly code (fixmap entries are an enum), but is sanity 2262306a36Sopenharmony_ci * checked in the actual fixmap C code to make sure that the fixmap is 2362306a36Sopenharmony_ci * covered fully. 2462306a36Sopenharmony_ci */ 2562306a36Sopenharmony_ci#ifndef CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP 2662306a36Sopenharmony_ci# define FIXMAP_PMD_NUM 2 2762306a36Sopenharmony_ci#else 2862306a36Sopenharmony_ci# define KM_PMDS (KM_MAX_IDX * ((CONFIG_NR_CPUS + 511) / 512)) 2962306a36Sopenharmony_ci# define FIXMAP_PMD_NUM (KM_PMDS + 2) 3062306a36Sopenharmony_ci#endif 3162306a36Sopenharmony_ci/* fixmap starts downwards from the 507th entry in level2_fixmap_pgt */ 3262306a36Sopenharmony_ci#define FIXMAP_PMD_TOP 507 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 3562306a36Sopenharmony_ci#include <linux/kernel.h> 3662306a36Sopenharmony_ci#include <asm/apicdef.h> 3762306a36Sopenharmony_ci#include <asm/page.h> 3862306a36Sopenharmony_ci#include <asm/pgtable_types.h> 3962306a36Sopenharmony_ci#ifdef CONFIG_X86_32 4062306a36Sopenharmony_ci#include <linux/threads.h> 4162306a36Sopenharmony_ci#else 4262306a36Sopenharmony_ci#include <uapi/asm/vsyscall.h> 4362306a36Sopenharmony_ci#endif 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci/* 4662306a36Sopenharmony_ci * We can't declare FIXADDR_TOP as variable for x86_64 because vsyscall 4762306a36Sopenharmony_ci * uses fixmaps that relies on FIXADDR_TOP for proper address calculation. 4862306a36Sopenharmony_ci * Because of this, FIXADDR_TOP x86 integration was left as later work. 4962306a36Sopenharmony_ci */ 5062306a36Sopenharmony_ci#ifdef CONFIG_X86_32 5162306a36Sopenharmony_ci/* 5262306a36Sopenharmony_ci * Leave one empty page between vmalloc'ed areas and 5362306a36Sopenharmony_ci * the start of the fixmap. 5462306a36Sopenharmony_ci */ 5562306a36Sopenharmony_ciextern unsigned long __FIXADDR_TOP; 5662306a36Sopenharmony_ci#define FIXADDR_TOP ((unsigned long)__FIXADDR_TOP) 5762306a36Sopenharmony_ci#else 5862306a36Sopenharmony_ci#define FIXADDR_TOP (round_up(VSYSCALL_ADDR + PAGE_SIZE, 1<<PMD_SHIFT) - \ 5962306a36Sopenharmony_ci PAGE_SIZE) 6062306a36Sopenharmony_ci#endif 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* 6362306a36Sopenharmony_ci * Here we define all the compile-time 'special' virtual 6462306a36Sopenharmony_ci * addresses. The point is to have a constant address at 6562306a36Sopenharmony_ci * compile time, but to set the physical address only 6662306a36Sopenharmony_ci * in the boot process. 6762306a36Sopenharmony_ci * for x86_32: We allocate these special addresses 6862306a36Sopenharmony_ci * from the end of virtual memory (0xfffff000) backwards. 6962306a36Sopenharmony_ci * Also this lets us do fail-safe vmalloc(), we 7062306a36Sopenharmony_ci * can guarantee that these special addresses and 7162306a36Sopenharmony_ci * vmalloc()-ed addresses never overlap. 7262306a36Sopenharmony_ci * 7362306a36Sopenharmony_ci * These 'compile-time allocated' memory buffers are 7462306a36Sopenharmony_ci * fixed-size 4k pages (or larger if used with an increment 7562306a36Sopenharmony_ci * higher than 1). Use set_fixmap(idx,phys) to associate 7662306a36Sopenharmony_ci * physical memory with fixmap indices. 7762306a36Sopenharmony_ci * 7862306a36Sopenharmony_ci * TLB entries of such buffers will not be flushed across 7962306a36Sopenharmony_ci * task switches. 8062306a36Sopenharmony_ci */ 8162306a36Sopenharmony_cienum fixed_addresses { 8262306a36Sopenharmony_ci#ifdef CONFIG_X86_32 8362306a36Sopenharmony_ci FIX_HOLE, 8462306a36Sopenharmony_ci#else 8562306a36Sopenharmony_ci#ifdef CONFIG_X86_VSYSCALL_EMULATION 8662306a36Sopenharmony_ci VSYSCALL_PAGE = (FIXADDR_TOP - VSYSCALL_ADDR) >> PAGE_SHIFT, 8762306a36Sopenharmony_ci#endif 8862306a36Sopenharmony_ci#endif 8962306a36Sopenharmony_ci FIX_DBGP_BASE, 9062306a36Sopenharmony_ci FIX_EARLYCON_MEM_BASE, 9162306a36Sopenharmony_ci#ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT 9262306a36Sopenharmony_ci FIX_OHCI1394_BASE, 9362306a36Sopenharmony_ci#endif 9462306a36Sopenharmony_ci#ifdef CONFIG_X86_LOCAL_APIC 9562306a36Sopenharmony_ci FIX_APIC_BASE, /* local (CPU) APIC) -- required for SMP or not */ 9662306a36Sopenharmony_ci#endif 9762306a36Sopenharmony_ci#ifdef CONFIG_X86_IO_APIC 9862306a36Sopenharmony_ci FIX_IO_APIC_BASE_0, 9962306a36Sopenharmony_ci FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1, 10062306a36Sopenharmony_ci#endif 10162306a36Sopenharmony_ci#ifdef CONFIG_KMAP_LOCAL 10262306a36Sopenharmony_ci FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */ 10362306a36Sopenharmony_ci FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_MAX_IDX * NR_CPUS) - 1, 10462306a36Sopenharmony_ci#ifdef CONFIG_PCI_MMCONFIG 10562306a36Sopenharmony_ci FIX_PCIE_MCFG, 10662306a36Sopenharmony_ci#endif 10762306a36Sopenharmony_ci#endif 10862306a36Sopenharmony_ci#ifdef CONFIG_PARAVIRT_XXL 10962306a36Sopenharmony_ci FIX_PARAVIRT_BOOTMAP, 11062306a36Sopenharmony_ci#endif 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci#ifdef CONFIG_ACPI_APEI_GHES 11362306a36Sopenharmony_ci /* Used for GHES mapping from assorted contexts */ 11462306a36Sopenharmony_ci FIX_APEI_GHES_IRQ, 11562306a36Sopenharmony_ci FIX_APEI_GHES_NMI, 11662306a36Sopenharmony_ci#endif 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci __end_of_permanent_fixed_addresses, 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci /* 12162306a36Sopenharmony_ci * 512 temporary boot-time mappings, used by early_ioremap(), 12262306a36Sopenharmony_ci * before ioremap() is functional. 12362306a36Sopenharmony_ci * 12462306a36Sopenharmony_ci * If necessary we round it up to the next 512 pages boundary so 12562306a36Sopenharmony_ci * that we can have a single pmd entry and a single pte table: 12662306a36Sopenharmony_ci */ 12762306a36Sopenharmony_ci#define NR_FIX_BTMAPS 64 12862306a36Sopenharmony_ci#define FIX_BTMAPS_SLOTS 8 12962306a36Sopenharmony_ci#define TOTAL_FIX_BTMAPS (NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS) 13062306a36Sopenharmony_ci FIX_BTMAP_END = 13162306a36Sopenharmony_ci (__end_of_permanent_fixed_addresses ^ 13262306a36Sopenharmony_ci (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) & 13362306a36Sopenharmony_ci -PTRS_PER_PTE 13462306a36Sopenharmony_ci ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 13562306a36Sopenharmony_ci (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1)) 13662306a36Sopenharmony_ci : __end_of_permanent_fixed_addresses, 13762306a36Sopenharmony_ci FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1, 13862306a36Sopenharmony_ci#ifdef CONFIG_X86_32 13962306a36Sopenharmony_ci FIX_WP_TEST, 14062306a36Sopenharmony_ci#endif 14162306a36Sopenharmony_ci#ifdef CONFIG_INTEL_TXT 14262306a36Sopenharmony_ci FIX_TBOOT_BASE, 14362306a36Sopenharmony_ci#endif 14462306a36Sopenharmony_ci __end_of_fixed_addresses 14562306a36Sopenharmony_ci}; 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci 14862306a36Sopenharmony_ciextern void reserve_top_address(unsigned long reserve); 14962306a36Sopenharmony_ci 15062306a36Sopenharmony_ci#define FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT) 15162306a36Sopenharmony_ci#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE) 15262306a36Sopenharmony_ci#define FIXADDR_TOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT) 15362306a36Sopenharmony_ci#define FIXADDR_TOT_START (FIXADDR_TOP - FIXADDR_TOT_SIZE) 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ciextern int fixmaps_set; 15662306a36Sopenharmony_ci 15762306a36Sopenharmony_ciextern pte_t *pkmap_page_table; 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_civoid __native_set_fixmap(enum fixed_addresses idx, pte_t pte); 16062306a36Sopenharmony_civoid native_set_fixmap(unsigned /* enum fixed_addresses */ idx, 16162306a36Sopenharmony_ci phys_addr_t phys, pgprot_t flags); 16262306a36Sopenharmony_ci 16362306a36Sopenharmony_ci#ifndef CONFIG_PARAVIRT_XXL 16462306a36Sopenharmony_cistatic inline void __set_fixmap(enum fixed_addresses idx, 16562306a36Sopenharmony_ci phys_addr_t phys, pgprot_t flags) 16662306a36Sopenharmony_ci{ 16762306a36Sopenharmony_ci native_set_fixmap(idx, phys, flags); 16862306a36Sopenharmony_ci} 16962306a36Sopenharmony_ci#endif 17062306a36Sopenharmony_ci 17162306a36Sopenharmony_ci/* 17262306a36Sopenharmony_ci * FIXMAP_PAGE_NOCACHE is used for MMIO. Memory encryption is not 17362306a36Sopenharmony_ci * supported for MMIO addresses, so make sure that the memory encryption 17462306a36Sopenharmony_ci * mask is not part of the page attributes. 17562306a36Sopenharmony_ci */ 17662306a36Sopenharmony_ci#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_IO_NOCACHE 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci/* 17962306a36Sopenharmony_ci * Early memremap routines used for in-place encryption. The mappings created 18062306a36Sopenharmony_ci * by these routines are intended to be used as temporary mappings. 18162306a36Sopenharmony_ci */ 18262306a36Sopenharmony_civoid __init *early_memremap_encrypted(resource_size_t phys_addr, 18362306a36Sopenharmony_ci unsigned long size); 18462306a36Sopenharmony_civoid __init *early_memremap_encrypted_wp(resource_size_t phys_addr, 18562306a36Sopenharmony_ci unsigned long size); 18662306a36Sopenharmony_civoid __init *early_memremap_decrypted(resource_size_t phys_addr, 18762306a36Sopenharmony_ci unsigned long size); 18862306a36Sopenharmony_civoid __init *early_memremap_decrypted_wp(resource_size_t phys_addr, 18962306a36Sopenharmony_ci unsigned long size); 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci#include <asm-generic/fixmap.h> 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci#define __late_set_fixmap(idx, phys, flags) __set_fixmap(idx, phys, flags) 19462306a36Sopenharmony_ci#define __late_clear_fixmap(idx) __set_fixmap(idx, 0, __pgprot(0)) 19562306a36Sopenharmony_ci 19662306a36Sopenharmony_civoid __early_set_fixmap(enum fixed_addresses idx, 19762306a36Sopenharmony_ci phys_addr_t phys, pgprot_t flags); 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci#endif /* !__ASSEMBLY__ */ 20062306a36Sopenharmony_ci#endif /* _ASM_X86_FIXMAP_H */ 201