18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * fixmap.h: compile-time virtual memory allocation
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
58c2ecf20Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
68c2ecf20Sopenharmony_ci * for more details.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright (C) 1998 Ingo Molnar
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 1999
118c2ecf20Sopenharmony_ci * x86_32 and x86_64 integration by Gustavo F. Padovan, February 2009
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef _ASM_X86_FIXMAP_H
158c2ecf20Sopenharmony_ci#define _ASM_X86_FIXMAP_H
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * Exposed to assembly code for setting up initial page tables. Cannot be
198c2ecf20Sopenharmony_ci * calculated in assembly code (fixmap entries are an enum), but is sanity
208c2ecf20Sopenharmony_ci * checked in the actual fixmap C code to make sure that the fixmap is
218c2ecf20Sopenharmony_ci * covered fully.
228c2ecf20Sopenharmony_ci */
238c2ecf20Sopenharmony_ci#define FIXMAP_PMD_NUM	2
248c2ecf20Sopenharmony_ci/* fixmap starts downwards from the 507th entry in level2_fixmap_pgt */
258c2ecf20Sopenharmony_ci#define FIXMAP_PMD_TOP	507
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
288c2ecf20Sopenharmony_ci#include <linux/kernel.h>
298c2ecf20Sopenharmony_ci#include <asm/apicdef.h>
308c2ecf20Sopenharmony_ci#include <asm/page.h>
318c2ecf20Sopenharmony_ci#include <asm/pgtable_types.h>
328c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_32
338c2ecf20Sopenharmony_ci#include <linux/threads.h>
348c2ecf20Sopenharmony_ci#include <asm/kmap_types.h>
358c2ecf20Sopenharmony_ci#else
368c2ecf20Sopenharmony_ci#include <uapi/asm/vsyscall.h>
378c2ecf20Sopenharmony_ci#endif
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/*
408c2ecf20Sopenharmony_ci * We can't declare FIXADDR_TOP as variable for x86_64 because vsyscall
418c2ecf20Sopenharmony_ci * uses fixmaps that relies on FIXADDR_TOP for proper address calculation.
428c2ecf20Sopenharmony_ci * Because of this, FIXADDR_TOP x86 integration was left as later work.
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_32
458c2ecf20Sopenharmony_ci/*
468c2ecf20Sopenharmony_ci * Leave one empty page between vmalloc'ed areas and
478c2ecf20Sopenharmony_ci * the start of the fixmap.
488c2ecf20Sopenharmony_ci */
498c2ecf20Sopenharmony_ciextern unsigned long __FIXADDR_TOP;
508c2ecf20Sopenharmony_ci#define FIXADDR_TOP	((unsigned long)__FIXADDR_TOP)
518c2ecf20Sopenharmony_ci#else
528c2ecf20Sopenharmony_ci#define FIXADDR_TOP	(round_up(VSYSCALL_ADDR + PAGE_SIZE, 1<<PMD_SHIFT) - \
538c2ecf20Sopenharmony_ci			 PAGE_SIZE)
548c2ecf20Sopenharmony_ci#endif
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci/*
578c2ecf20Sopenharmony_ci * Here we define all the compile-time 'special' virtual
588c2ecf20Sopenharmony_ci * addresses. The point is to have a constant address at
598c2ecf20Sopenharmony_ci * compile time, but to set the physical address only
608c2ecf20Sopenharmony_ci * in the boot process.
618c2ecf20Sopenharmony_ci * for x86_32: We allocate these special addresses
628c2ecf20Sopenharmony_ci * from the end of virtual memory (0xfffff000) backwards.
638c2ecf20Sopenharmony_ci * Also this lets us do fail-safe vmalloc(), we
648c2ecf20Sopenharmony_ci * can guarantee that these special addresses and
658c2ecf20Sopenharmony_ci * vmalloc()-ed addresses never overlap.
668c2ecf20Sopenharmony_ci *
678c2ecf20Sopenharmony_ci * These 'compile-time allocated' memory buffers are
688c2ecf20Sopenharmony_ci * fixed-size 4k pages (or larger if used with an increment
698c2ecf20Sopenharmony_ci * higher than 1). Use set_fixmap(idx,phys) to associate
708c2ecf20Sopenharmony_ci * physical memory with fixmap indices.
718c2ecf20Sopenharmony_ci *
728c2ecf20Sopenharmony_ci * TLB entries of such buffers will not be flushed across
738c2ecf20Sopenharmony_ci * task switches.
748c2ecf20Sopenharmony_ci */
758c2ecf20Sopenharmony_cienum fixed_addresses {
768c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_32
778c2ecf20Sopenharmony_ci	FIX_HOLE,
788c2ecf20Sopenharmony_ci#else
798c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_VSYSCALL_EMULATION
808c2ecf20Sopenharmony_ci	VSYSCALL_PAGE = (FIXADDR_TOP - VSYSCALL_ADDR) >> PAGE_SHIFT,
818c2ecf20Sopenharmony_ci#endif
828c2ecf20Sopenharmony_ci#endif
838c2ecf20Sopenharmony_ci	FIX_DBGP_BASE,
848c2ecf20Sopenharmony_ci	FIX_EARLYCON_MEM_BASE,
858c2ecf20Sopenharmony_ci#ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
868c2ecf20Sopenharmony_ci	FIX_OHCI1394_BASE,
878c2ecf20Sopenharmony_ci#endif
888c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_LOCAL_APIC
898c2ecf20Sopenharmony_ci	FIX_APIC_BASE,	/* local (CPU) APIC) -- required for SMP or not */
908c2ecf20Sopenharmony_ci#endif
918c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_IO_APIC
928c2ecf20Sopenharmony_ci	FIX_IO_APIC_BASE_0,
938c2ecf20Sopenharmony_ci	FIX_IO_APIC_BASE_END = FIX_IO_APIC_BASE_0 + MAX_IO_APICS - 1,
948c2ecf20Sopenharmony_ci#endif
958c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_32
968c2ecf20Sopenharmony_ci	FIX_KMAP_BEGIN,	/* reserved pte's for temporary kernel mappings */
978c2ecf20Sopenharmony_ci	FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
988c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI_MMCONFIG
998c2ecf20Sopenharmony_ci	FIX_PCIE_MCFG,
1008c2ecf20Sopenharmony_ci#endif
1018c2ecf20Sopenharmony_ci#endif
1028c2ecf20Sopenharmony_ci#ifdef CONFIG_PARAVIRT_XXL
1038c2ecf20Sopenharmony_ci	FIX_PARAVIRT_BOOTMAP,
1048c2ecf20Sopenharmony_ci#endif
1058c2ecf20Sopenharmony_ci#ifdef	CONFIG_X86_INTEL_MID
1068c2ecf20Sopenharmony_ci	FIX_LNW_VRTC,
1078c2ecf20Sopenharmony_ci#endif
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#ifdef CONFIG_ACPI_APEI_GHES
1108c2ecf20Sopenharmony_ci	/* Used for GHES mapping from assorted contexts */
1118c2ecf20Sopenharmony_ci	FIX_APEI_GHES_IRQ,
1128c2ecf20Sopenharmony_ci	FIX_APEI_GHES_NMI,
1138c2ecf20Sopenharmony_ci#endif
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci	__end_of_permanent_fixed_addresses,
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci	/*
1188c2ecf20Sopenharmony_ci	 * 512 temporary boot-time mappings, used by early_ioremap(),
1198c2ecf20Sopenharmony_ci	 * before ioremap() is functional.
1208c2ecf20Sopenharmony_ci	 *
1218c2ecf20Sopenharmony_ci	 * If necessary we round it up to the next 512 pages boundary so
1228c2ecf20Sopenharmony_ci	 * that we can have a single pmd entry and a single pte table:
1238c2ecf20Sopenharmony_ci	 */
1248c2ecf20Sopenharmony_ci#define NR_FIX_BTMAPS		64
1258c2ecf20Sopenharmony_ci#define FIX_BTMAPS_SLOTS	8
1268c2ecf20Sopenharmony_ci#define TOTAL_FIX_BTMAPS	(NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
1278c2ecf20Sopenharmony_ci	FIX_BTMAP_END =
1288c2ecf20Sopenharmony_ci	 (__end_of_permanent_fixed_addresses ^
1298c2ecf20Sopenharmony_ci	  (__end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS - 1)) &
1308c2ecf20Sopenharmony_ci	 -PTRS_PER_PTE
1318c2ecf20Sopenharmony_ci	 ? __end_of_permanent_fixed_addresses + TOTAL_FIX_BTMAPS -
1328c2ecf20Sopenharmony_ci	   (__end_of_permanent_fixed_addresses & (TOTAL_FIX_BTMAPS - 1))
1338c2ecf20Sopenharmony_ci	 : __end_of_permanent_fixed_addresses,
1348c2ecf20Sopenharmony_ci	FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,
1358c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_32
1368c2ecf20Sopenharmony_ci	FIX_WP_TEST,
1378c2ecf20Sopenharmony_ci#endif
1388c2ecf20Sopenharmony_ci#ifdef CONFIG_INTEL_TXT
1398c2ecf20Sopenharmony_ci	FIX_TBOOT_BASE,
1408c2ecf20Sopenharmony_ci#endif
1418c2ecf20Sopenharmony_ci	__end_of_fixed_addresses
1428c2ecf20Sopenharmony_ci};
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ciextern void reserve_top_address(unsigned long reserve);
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_ci#define FIXADDR_SIZE		(__end_of_permanent_fixed_addresses << PAGE_SHIFT)
1488c2ecf20Sopenharmony_ci#define FIXADDR_START		(FIXADDR_TOP - FIXADDR_SIZE)
1498c2ecf20Sopenharmony_ci#define FIXADDR_TOT_SIZE	(__end_of_fixed_addresses << PAGE_SHIFT)
1508c2ecf20Sopenharmony_ci#define FIXADDR_TOT_START	(FIXADDR_TOP - FIXADDR_TOT_SIZE)
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ciextern int fixmaps_set;
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ciextern pte_t *kmap_pte;
1558c2ecf20Sopenharmony_ciextern pte_t *pkmap_page_table;
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_civoid __native_set_fixmap(enum fixed_addresses idx, pte_t pte);
1588c2ecf20Sopenharmony_civoid native_set_fixmap(unsigned /* enum fixed_addresses */ idx,
1598c2ecf20Sopenharmony_ci		       phys_addr_t phys, pgprot_t flags);
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#ifndef CONFIG_PARAVIRT_XXL
1628c2ecf20Sopenharmony_cistatic inline void __set_fixmap(enum fixed_addresses idx,
1638c2ecf20Sopenharmony_ci				phys_addr_t phys, pgprot_t flags)
1648c2ecf20Sopenharmony_ci{
1658c2ecf20Sopenharmony_ci	native_set_fixmap(idx, phys, flags);
1668c2ecf20Sopenharmony_ci}
1678c2ecf20Sopenharmony_ci#endif
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci/*
1708c2ecf20Sopenharmony_ci * FIXMAP_PAGE_NOCACHE is used for MMIO. Memory encryption is not
1718c2ecf20Sopenharmony_ci * supported for MMIO addresses, so make sure that the memory encryption
1728c2ecf20Sopenharmony_ci * mask is not part of the page attributes.
1738c2ecf20Sopenharmony_ci */
1748c2ecf20Sopenharmony_ci#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_IO_NOCACHE
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/*
1778c2ecf20Sopenharmony_ci * Early memremap routines used for in-place encryption. The mappings created
1788c2ecf20Sopenharmony_ci * by these routines are intended to be used as temporary mappings.
1798c2ecf20Sopenharmony_ci */
1808c2ecf20Sopenharmony_civoid __init *early_memremap_encrypted(resource_size_t phys_addr,
1818c2ecf20Sopenharmony_ci				      unsigned long size);
1828c2ecf20Sopenharmony_civoid __init *early_memremap_encrypted_wp(resource_size_t phys_addr,
1838c2ecf20Sopenharmony_ci					 unsigned long size);
1848c2ecf20Sopenharmony_civoid __init *early_memremap_decrypted(resource_size_t phys_addr,
1858c2ecf20Sopenharmony_ci				      unsigned long size);
1868c2ecf20Sopenharmony_civoid __init *early_memremap_decrypted_wp(resource_size_t phys_addr,
1878c2ecf20Sopenharmony_ci					 unsigned long size);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci#include <asm-generic/fixmap.h>
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci#define __late_set_fixmap(idx, phys, flags) __set_fixmap(idx, phys, flags)
1928c2ecf20Sopenharmony_ci#define __late_clear_fixmap(idx) __set_fixmap(idx, 0, __pgprot(0))
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_civoid __early_set_fixmap(enum fixed_addresses idx,
1958c2ecf20Sopenharmony_ci			phys_addr_t phys, pgprot_t flags);
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */
1988c2ecf20Sopenharmony_ci#endif /* _ASM_X86_FIXMAP_H */
199