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 * Copyright 2008 Freescale Semiconductor Inc.
118c2ecf20Sopenharmony_ci *   Port to powerpc added by Kumar Gala
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#ifndef _ASM_FIXMAP_H
158c2ecf20Sopenharmony_ci#define _ASM_FIXMAP_H
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
188c2ecf20Sopenharmony_ci#include <linux/sizes.h>
198c2ecf20Sopenharmony_ci#include <linux/pgtable.h>
208c2ecf20Sopenharmony_ci#include <asm/page.h>
218c2ecf20Sopenharmony_ci#ifdef CONFIG_HIGHMEM
228c2ecf20Sopenharmony_ci#include <linux/threads.h>
238c2ecf20Sopenharmony_ci#include <asm/kmap_types.h>
248c2ecf20Sopenharmony_ci#endif
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC64
278c2ecf20Sopenharmony_ci#define FIXADDR_TOP	(IOREMAP_END + FIXADDR_SIZE)
288c2ecf20Sopenharmony_ci#else
298c2ecf20Sopenharmony_ci#define FIXADDR_SIZE	0
308c2ecf20Sopenharmony_ci#ifdef CONFIG_KASAN
318c2ecf20Sopenharmony_ci#include <asm/kasan.h>
328c2ecf20Sopenharmony_ci#define FIXADDR_TOP	(KASAN_SHADOW_START - PAGE_SIZE)
338c2ecf20Sopenharmony_ci#else
348c2ecf20Sopenharmony_ci#define FIXADDR_TOP	((unsigned long)(-PAGE_SIZE))
358c2ecf20Sopenharmony_ci#endif
368c2ecf20Sopenharmony_ci#endif
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*
398c2ecf20Sopenharmony_ci * Here we define all the compile-time 'special' virtual
408c2ecf20Sopenharmony_ci * addresses. The point is to have a constant address at
418c2ecf20Sopenharmony_ci * compile time, but to set the physical address only
428c2ecf20Sopenharmony_ci * in the boot process. We allocate these special addresses
438c2ecf20Sopenharmony_ci * from the end of virtual memory (0xfffff000) backwards.
448c2ecf20Sopenharmony_ci * Also this lets us do fail-safe vmalloc(), we
458c2ecf20Sopenharmony_ci * can guarantee that these special addresses and
468c2ecf20Sopenharmony_ci * vmalloc()-ed addresses never overlap.
478c2ecf20Sopenharmony_ci *
488c2ecf20Sopenharmony_ci * these 'compile-time allocated' memory buffers are
498c2ecf20Sopenharmony_ci * fixed-size 4k pages. (or larger if used with an increment
508c2ecf20Sopenharmony_ci * highger than 1) use fixmap_set(idx,phys) to associate
518c2ecf20Sopenharmony_ci * physical memory with fixmap indices.
528c2ecf20Sopenharmony_ci *
538c2ecf20Sopenharmony_ci * TLB entries of such buffers will not be flushed across
548c2ecf20Sopenharmony_ci * task switches.
558c2ecf20Sopenharmony_ci */
568c2ecf20Sopenharmony_cienum fixed_addresses {
578c2ecf20Sopenharmony_ci	FIX_HOLE,
588c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC32
598c2ecf20Sopenharmony_ci	/* reserve the top 128K for early debugging purposes */
608c2ecf20Sopenharmony_ci	FIX_EARLY_DEBUG_TOP = FIX_HOLE,
618c2ecf20Sopenharmony_ci	FIX_EARLY_DEBUG_BASE = FIX_EARLY_DEBUG_TOP+(ALIGN(SZ_128K, PAGE_SIZE)/PAGE_SIZE)-1,
628c2ecf20Sopenharmony_ci#ifdef CONFIG_HIGHMEM
638c2ecf20Sopenharmony_ci	FIX_KMAP_BEGIN,	/* reserved pte's for temporary kernel mappings */
648c2ecf20Sopenharmony_ci	FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,
658c2ecf20Sopenharmony_ci#endif
668c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_8xx
678c2ecf20Sopenharmony_ci	/* For IMMR we need an aligned 512K area */
688c2ecf20Sopenharmony_ci#define FIX_IMMR_SIZE	(512 * 1024 / PAGE_SIZE)
698c2ecf20Sopenharmony_ci	FIX_IMMR_START,
708c2ecf20Sopenharmony_ci	FIX_IMMR_BASE = __ALIGN_MASK(FIX_IMMR_START, FIX_IMMR_SIZE - 1) - 1 +
718c2ecf20Sopenharmony_ci		       FIX_IMMR_SIZE,
728c2ecf20Sopenharmony_ci#endif
738c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_83xx
748c2ecf20Sopenharmony_ci	/* For IMMR we need an aligned 2M area */
758c2ecf20Sopenharmony_ci#define FIX_IMMR_SIZE	(SZ_2M / PAGE_SIZE)
768c2ecf20Sopenharmony_ci	FIX_IMMR_START,
778c2ecf20Sopenharmony_ci	FIX_IMMR_BASE = __ALIGN_MASK(FIX_IMMR_START, FIX_IMMR_SIZE - 1) - 1 +
788c2ecf20Sopenharmony_ci		       FIX_IMMR_SIZE,
798c2ecf20Sopenharmony_ci#endif
808c2ecf20Sopenharmony_ci	/* FIX_PCIE_MCFG, */
818c2ecf20Sopenharmony_ci#endif /* CONFIG_PPC32 */
828c2ecf20Sopenharmony_ci	__end_of_permanent_fixed_addresses,
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define NR_FIX_BTMAPS		(SZ_256K / PAGE_SIZE)
858c2ecf20Sopenharmony_ci#define FIX_BTMAPS_SLOTS	16
868c2ecf20Sopenharmony_ci#define TOTAL_FIX_BTMAPS	(NR_FIX_BTMAPS * FIX_BTMAPS_SLOTS)
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	FIX_BTMAP_END = __end_of_permanent_fixed_addresses,
898c2ecf20Sopenharmony_ci	FIX_BTMAP_BEGIN = FIX_BTMAP_END + TOTAL_FIX_BTMAPS - 1,
908c2ecf20Sopenharmony_ci	__end_of_fixed_addresses
918c2ecf20Sopenharmony_ci};
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define __FIXADDR_SIZE	(__end_of_fixed_addresses << PAGE_SHIFT)
948c2ecf20Sopenharmony_ci#define FIXADDR_START		(FIXADDR_TOP - __FIXADDR_SIZE)
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define FIXMAP_ALIGNED_SIZE	(ALIGN(FIXADDR_TOP, PGDIR_SIZE) - \
978c2ecf20Sopenharmony_ci				 ALIGN_DOWN(FIXADDR_START, PGDIR_SIZE))
988c2ecf20Sopenharmony_ci#define FIXMAP_PTE_SIZE	(FIXMAP_ALIGNED_SIZE / PGDIR_SIZE * PTE_TABLE_SIZE)
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NCG
1018c2ecf20Sopenharmony_ci#define FIXMAP_PAGE_IO	PAGE_KERNEL_NCG
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#include <asm-generic/fixmap.h>
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic inline void __set_fixmap(enum fixed_addresses idx,
1068c2ecf20Sopenharmony_ci				phys_addr_t phys, pgprot_t flags)
1078c2ecf20Sopenharmony_ci{
1088c2ecf20Sopenharmony_ci	BUILD_BUG_ON(IS_ENABLED(CONFIG_PPC64) && __FIXADDR_SIZE > FIXADDR_SIZE);
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	if (__builtin_constant_p(idx))
1118c2ecf20Sopenharmony_ci		BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
1128c2ecf20Sopenharmony_ci	else if (WARN_ON(idx >= __end_of_fixed_addresses))
1138c2ecf20Sopenharmony_ci		return;
1148c2ecf20Sopenharmony_ci	if (pgprot_val(flags))
1158c2ecf20Sopenharmony_ci		map_kernel_page(__fix_to_virt(idx), phys, flags);
1168c2ecf20Sopenharmony_ci	else
1178c2ecf20Sopenharmony_ci		unmap_kernel_page(__fix_to_virt(idx));
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#define __early_set_fixmap	__set_fixmap
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#endif /* !__ASSEMBLY__ */
1238c2ecf20Sopenharmony_ci#endif
124