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 * Break out common bits to asm-generic by Mark Salter, November 2013 1362306a36Sopenharmony_ci */ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#ifndef __ASM_GENERIC_FIXMAP_H 1662306a36Sopenharmony_ci#define __ASM_GENERIC_FIXMAP_H 1762306a36Sopenharmony_ci 1862306a36Sopenharmony_ci#include <linux/bug.h> 1962306a36Sopenharmony_ci#include <linux/mm_types.h> 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT)) 2262306a36Sopenharmony_ci#define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT) 2362306a36Sopenharmony_ci 2462306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 2562306a36Sopenharmony_ci/* 2662306a36Sopenharmony_ci * 'index to address' translation. If anyone tries to use the idx 2762306a36Sopenharmony_ci * directly without translation, we catch the bug with a NULL-deference 2862306a36Sopenharmony_ci * kernel oops. Illegal ranges of incoming indices are caught too. 2962306a36Sopenharmony_ci */ 3062306a36Sopenharmony_cistatic __always_inline unsigned long fix_to_virt(const unsigned int idx) 3162306a36Sopenharmony_ci{ 3262306a36Sopenharmony_ci BUILD_BUG_ON(idx >= __end_of_fixed_addresses); 3362306a36Sopenharmony_ci return __fix_to_virt(idx); 3462306a36Sopenharmony_ci} 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_cistatic inline unsigned long virt_to_fix(const unsigned long vaddr) 3762306a36Sopenharmony_ci{ 3862306a36Sopenharmony_ci BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START); 3962306a36Sopenharmony_ci return __virt_to_fix(vaddr); 4062306a36Sopenharmony_ci} 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci/* 4362306a36Sopenharmony_ci * Provide some reasonable defaults for page flags. 4462306a36Sopenharmony_ci * Not all architectures use all of these different types and some 4562306a36Sopenharmony_ci * architectures use different names. 4662306a36Sopenharmony_ci */ 4762306a36Sopenharmony_ci#ifndef FIXMAP_PAGE_NORMAL 4862306a36Sopenharmony_ci#define FIXMAP_PAGE_NORMAL PAGE_KERNEL 4962306a36Sopenharmony_ci#endif 5062306a36Sopenharmony_ci#if !defined(FIXMAP_PAGE_RO) && defined(PAGE_KERNEL_RO) 5162306a36Sopenharmony_ci#define FIXMAP_PAGE_RO PAGE_KERNEL_RO 5262306a36Sopenharmony_ci#endif 5362306a36Sopenharmony_ci#ifndef FIXMAP_PAGE_NOCACHE 5462306a36Sopenharmony_ci#define FIXMAP_PAGE_NOCACHE PAGE_KERNEL_NOCACHE 5562306a36Sopenharmony_ci#endif 5662306a36Sopenharmony_ci#ifndef FIXMAP_PAGE_IO 5762306a36Sopenharmony_ci#define FIXMAP_PAGE_IO PAGE_KERNEL_IO 5862306a36Sopenharmony_ci#endif 5962306a36Sopenharmony_ci#ifndef FIXMAP_PAGE_CLEAR 6062306a36Sopenharmony_ci#define FIXMAP_PAGE_CLEAR __pgprot(0) 6162306a36Sopenharmony_ci#endif 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#ifndef set_fixmap 6462306a36Sopenharmony_ci#define set_fixmap(idx, phys) \ 6562306a36Sopenharmony_ci __set_fixmap(idx, phys, FIXMAP_PAGE_NORMAL) 6662306a36Sopenharmony_ci#endif 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci#ifndef clear_fixmap 6962306a36Sopenharmony_ci#define clear_fixmap(idx) \ 7062306a36Sopenharmony_ci __set_fixmap(idx, 0, FIXMAP_PAGE_CLEAR) 7162306a36Sopenharmony_ci#endif 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci/* Return a pointer with offset calculated */ 7462306a36Sopenharmony_ci#define __set_fixmap_offset(idx, phys, flags) \ 7562306a36Sopenharmony_ci({ \ 7662306a36Sopenharmony_ci unsigned long ________addr; \ 7762306a36Sopenharmony_ci __set_fixmap(idx, phys, flags); \ 7862306a36Sopenharmony_ci ________addr = fix_to_virt(idx) + ((phys) & (PAGE_SIZE - 1)); \ 7962306a36Sopenharmony_ci ________addr; \ 8062306a36Sopenharmony_ci}) 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci#define set_fixmap_offset(idx, phys) \ 8362306a36Sopenharmony_ci __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NORMAL) 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci/* 8662306a36Sopenharmony_ci * Some hardware wants to get fixmapped without caching. 8762306a36Sopenharmony_ci */ 8862306a36Sopenharmony_ci#define set_fixmap_nocache(idx, phys) \ 8962306a36Sopenharmony_ci __set_fixmap(idx, phys, FIXMAP_PAGE_NOCACHE) 9062306a36Sopenharmony_ci 9162306a36Sopenharmony_ci#define set_fixmap_offset_nocache(idx, phys) \ 9262306a36Sopenharmony_ci __set_fixmap_offset(idx, phys, FIXMAP_PAGE_NOCACHE) 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/* 9562306a36Sopenharmony_ci * Some fixmaps are for IO 9662306a36Sopenharmony_ci */ 9762306a36Sopenharmony_ci#define set_fixmap_io(idx, phys) \ 9862306a36Sopenharmony_ci __set_fixmap(idx, phys, FIXMAP_PAGE_IO) 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci#define set_fixmap_offset_io(idx, phys) \ 10162306a36Sopenharmony_ci __set_fixmap_offset(idx, phys, FIXMAP_PAGE_IO) 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */ 10462306a36Sopenharmony_ci#endif /* __ASM_GENERIC_FIXMAP_H */ 105