/*1* Copyright (C) 1998 Ingo Molnar2* Copyright 2010 Tilera Corporation. All Rights Reserved.3*4* This program is free software; you can redistribute it and/or5* modify it under the terms of the GNU General Public License6* as published by the Free Software Foundation, version 2.7*8* This program is distributed in the hope that it will be useful, but9* WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or11* NON INFRINGEMENT. See the GNU General Public License for12* more details.13*/1415#ifndef _ASM_TILE_FIXMAP_H16#define _ASM_TILE_FIXMAP_H1718#include <asm/page.h>1920#ifndef __ASSEMBLY__21#include <linux/kernel.h>22#ifdef CONFIG_HIGHMEM23#include <linux/threads.h>24#include <asm/kmap_types.h>25#endif2627#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))28#define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)2930/*31* Here we define all the compile-time 'special' virtual32* addresses. The point is to have a constant address at33* compile time, but to set the physical address only34* in the boot process. We allocate these special addresses35* from the end of supervisor virtual memory backwards.36* Also this lets us do fail-safe vmalloc(), we37* can guarantee that these special addresses and38* vmalloc()-ed addresses never overlap.39*40* these 'compile-time allocated' memory buffers are41* fixed-size 4k pages. (or larger if used with an increment42* higher than 1) use fixmap_set(idx,phys) to associate43* physical memory with fixmap indices.44*45* TLB entries of such buffers will not be flushed across46* task switches.47*48* We don't bother with a FIX_HOLE since above the fixmaps49* is unmapped memory in any case.50*/51enum fixed_addresses {52#ifdef CONFIG_HIGHMEM53FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */54FIX_KMAP_END = FIX_KMAP_BEGIN+(KM_TYPE_NR*NR_CPUS)-1,55#endif56__end_of_permanent_fixed_addresses,5758/*59* Temporary boot-time mappings, used before ioremap() is functional.60* Not currently needed by the Tile architecture.61*/62#define NR_FIX_BTMAPS 063#if NR_FIX_BTMAPS64FIX_BTMAP_END = __end_of_permanent_fixed_addresses,65FIX_BTMAP_BEGIN = FIX_BTMAP_END + NR_FIX_BTMAPS - 1,66__end_of_fixed_addresses67#else68__end_of_fixed_addresses = __end_of_permanent_fixed_addresses69#endif70};7172extern void __set_fixmap(enum fixed_addresses idx,73unsigned long phys, pgprot_t flags);7475#define set_fixmap(idx, phys) \76__set_fixmap(idx, phys, PAGE_KERNEL)77/*78* Some hardware wants to get fixmapped without caching.79*/80#define set_fixmap_nocache(idx, phys) \81__set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)8283#define clear_fixmap(idx) \84__set_fixmap(idx, 0, __pgprot(0))8586#define __FIXADDR_SIZE (__end_of_permanent_fixed_addresses << PAGE_SHIFT)87#define __FIXADDR_BOOT_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)88#define FIXADDR_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_SIZE)89#define FIXADDR_BOOT_START (FIXADDR_TOP + PAGE_SIZE - __FIXADDR_BOOT_SIZE)9091extern void __this_fixmap_does_not_exist(void);9293/*94* 'index to address' translation. If anyone tries to use the idx95* directly without tranlation, we catch the bug with a NULL-deference96* kernel oops. Illegal ranges of incoming indices are caught too.97*/98static __always_inline unsigned long fix_to_virt(const unsigned int idx)99{100/*101* this branch gets completely eliminated after inlining,102* except when someone tries to use fixaddr indices in an103* illegal way. (such as mixing up address types or using104* out-of-range indices).105*106* If it doesn't get removed, the linker will complain107* loudly with a reasonably clear error message..108*/109if (idx >= __end_of_fixed_addresses)110__this_fixmap_does_not_exist();111112return __fix_to_virt(idx);113}114115static inline unsigned long virt_to_fix(const unsigned long vaddr)116{117BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);118return __virt_to_fix(vaddr);119}120121#endif /* !__ASSEMBLY__ */122123#endif /* _ASM_TILE_FIXMAP_H */124125126