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 */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#ifndef _ASM_FIXMAP_H
148c2ecf20Sopenharmony_ci#define _ASM_FIXMAP_H
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#ifdef CONFIG_HIGHMEM
178c2ecf20Sopenharmony_ci#include <linux/threads.h>
188c2ecf20Sopenharmony_ci#include <linux/pgtable.h>
198c2ecf20Sopenharmony_ci#include <asm/kmap_types.h>
208c2ecf20Sopenharmony_ci#endif
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/*
238c2ecf20Sopenharmony_ci * Here we define all the compile-time 'special' virtual
248c2ecf20Sopenharmony_ci * addresses. The point is to have a constant address at
258c2ecf20Sopenharmony_ci * compile time, but to set the physical address only
268c2ecf20Sopenharmony_ci * in the boot process. We allocate these special addresses
278c2ecf20Sopenharmony_ci * from the start of the consistent memory region upwards.
288c2ecf20Sopenharmony_ci * Also this lets us do fail-safe vmalloc(), we
298c2ecf20Sopenharmony_ci * can guarantee that these special addresses and
308c2ecf20Sopenharmony_ci * vmalloc()-ed addresses never overlap.
318c2ecf20Sopenharmony_ci *
328c2ecf20Sopenharmony_ci * these 'compile-time allocated' memory buffers are
338c2ecf20Sopenharmony_ci * fixed-size 4k pages. (or larger if used with an increment
348c2ecf20Sopenharmony_ci * higher than 1) use fixmap_set(idx,phys) to associate
358c2ecf20Sopenharmony_ci * physical memory with fixmap indices.
368c2ecf20Sopenharmony_ci */
378c2ecf20Sopenharmony_cienum fixed_addresses {
388c2ecf20Sopenharmony_ci#ifdef CONFIG_HIGHMEM
398c2ecf20Sopenharmony_ci	/* reserved pte's for temporary kernel mappings */
408c2ecf20Sopenharmony_ci	FIX_KMAP_BEGIN,
418c2ecf20Sopenharmony_ci	FIX_KMAP_END = FIX_KMAP_BEGIN +
428c2ecf20Sopenharmony_ci		(KM_TYPE_NR * NR_CPUS * DCACHE_N_COLORS) - 1,
438c2ecf20Sopenharmony_ci#endif
448c2ecf20Sopenharmony_ci	__end_of_fixed_addresses
458c2ecf20Sopenharmony_ci};
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci#define FIXADDR_TOP     (XCHAL_KSEG_CACHED_VADDR - PAGE_SIZE)
488c2ecf20Sopenharmony_ci#define FIXADDR_SIZE	(__end_of_fixed_addresses << PAGE_SHIFT)
498c2ecf20Sopenharmony_ci#define FIXADDR_START	((FIXADDR_TOP - FIXADDR_SIZE) & PMD_MASK)
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#define __fix_to_virt(x)	(FIXADDR_START + ((x) << PAGE_SHIFT))
528c2ecf20Sopenharmony_ci#define __virt_to_fix(x)	(((x) - FIXADDR_START) >> PAGE_SHIFT)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
558c2ecf20Sopenharmony_ci/*
568c2ecf20Sopenharmony_ci * 'index to address' translation. If anyone tries to use the idx
578c2ecf20Sopenharmony_ci * directly without translation, we catch the bug with a NULL-deference
588c2ecf20Sopenharmony_ci * kernel oops. Illegal ranges of incoming indices are caught too.
598c2ecf20Sopenharmony_ci */
608c2ecf20Sopenharmony_cistatic __always_inline unsigned long fix_to_virt(const unsigned int idx)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	/* Check if this memory layout is broken because fixmap overlaps page
638c2ecf20Sopenharmony_ci	 * table.
648c2ecf20Sopenharmony_ci	 */
658c2ecf20Sopenharmony_ci	BUILD_BUG_ON(FIXADDR_START <
668c2ecf20Sopenharmony_ci		     TLBTEMP_BASE_1 + TLBTEMP_SIZE);
678c2ecf20Sopenharmony_ci	BUILD_BUG_ON(idx >= __end_of_fixed_addresses);
688c2ecf20Sopenharmony_ci	return __fix_to_virt(idx);
698c2ecf20Sopenharmony_ci}
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_cistatic inline unsigned long virt_to_fix(const unsigned long vaddr)
728c2ecf20Sopenharmony_ci{
738c2ecf20Sopenharmony_ci	BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);
748c2ecf20Sopenharmony_ci	return __virt_to_fix(vaddr);
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#endif
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#endif
80