/*1* fixmap.h: compile-time virtual memory allocation2*3* This file is subject to the terms and conditions of the GNU General Public4* License. See the file "COPYING" in the main directory of this archive5* for more details.6*7* Copyright (C) 1998 Ingo Molnar8*9* Support of BIGMEM added by Gerhard Wichert, Siemens AG, July 199910*/1112#ifndef _ASM_FIXMAP_H13#define _ASM_FIXMAP_H1415#include <linux/kernel.h>16#include <linux/threads.h>17#include <asm/page.h>18#ifdef CONFIG_HIGHMEM19#include <asm/kmap_types.h>20#endif2122/*23* Here we define all the compile-time 'special' virtual24* addresses. The point is to have a constant address at25* compile time, but to set the physical address only26* in the boot process. We allocate these special addresses27* from the end of P3 backwards.28* Also this lets us do fail-safe vmalloc(), we29* can guarantee that these special addresses and30* vmalloc()-ed addresses never overlap.31*32* these 'compile-time allocated' memory buffers are33* fixed-size 4k pages. (or larger if used with an increment34* highger than 1) use fixmap_set(idx,phys) to associate35* physical memory with fixmap indices.36*37* TLB entries of such buffers will not be flushed across38* task switches.39*/4041/*42* on UP currently we will have no trace of the fixmap mechanizm,43* no page table allocations, etc. This might change in the44* future, say framebuffers for the console driver(s) could be45* fix-mapped?46*/47enum fixed_addresses {48/*49* The FIX_CMAP entries are used by kmap_coherent() to get virtual50* addresses which are of a known color, and so their values are51* important. __fix_to_virt(FIX_CMAP_END - n) must give an address52* which is the same color as a page (n<<PAGE_SHIFT).53*/54#define FIX_N_COLOURS 855FIX_CMAP_BEGIN,56FIX_CMAP_END = FIX_CMAP_BEGIN + (FIX_N_COLOURS * NR_CPUS) - 1,5758#ifdef CONFIG_HIGHMEM59FIX_KMAP_BEGIN, /* reserved pte's for temporary kernel mappings */60FIX_KMAP_END = FIX_KMAP_BEGIN + (KM_TYPE_NR * NR_CPUS) - 1,61#endif6263#ifdef CONFIG_IOREMAP_FIXED64/*65* FIX_IOREMAP entries are useful for mapping physical address66* space before ioremap() is useable, e.g. really early in boot67* before kmalloc() is working.68*/69#define FIX_N_IOREMAPS 3270FIX_IOREMAP_BEGIN,71FIX_IOREMAP_END = FIX_IOREMAP_BEGIN + FIX_N_IOREMAPS - 1,72#endif7374__end_of_fixed_addresses75};7677extern void __set_fixmap(enum fixed_addresses idx,78unsigned long phys, pgprot_t flags);79extern void __clear_fixmap(enum fixed_addresses idx, pgprot_t flags);8081#define set_fixmap(idx, phys) \82__set_fixmap(idx, phys, PAGE_KERNEL)83/*84* Some hardware wants to get fixmapped without caching.85*/86#define set_fixmap_nocache(idx, phys) \87__set_fixmap(idx, phys, PAGE_KERNEL_NOCACHE)88/*89* used by vmalloc.c.90*91* Leave one empty page between vmalloc'ed areas and92* the start of the fixmap, and leave one page empty93* at the top of mem..94*/95#ifdef CONFIG_SUPERH3296#define FIXADDR_TOP (P4SEG - PAGE_SIZE)97#else98#define FIXADDR_TOP (0xff000000 - PAGE_SIZE)99#endif100#define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)101#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)102103#define __fix_to_virt(x) (FIXADDR_TOP - ((x) << PAGE_SHIFT))104#define __virt_to_fix(x) ((FIXADDR_TOP - ((x)&PAGE_MASK)) >> PAGE_SHIFT)105106extern void __this_fixmap_does_not_exist(void);107108/*109* 'index to address' translation. If anyone tries to use the idx110* directly without tranlation, we catch the bug with a NULL-deference111* kernel oops. Illegal ranges of incoming indices are caught too.112*/113static inline unsigned long fix_to_virt(const unsigned int idx)114{115/*116* this branch gets completely eliminated after inlining,117* except when someone tries to use fixaddr indices in an118* illegal way. (such as mixing up address types or using119* out-of-range indices).120*121* If it doesn't get removed, the linker will complain122* loudly with a reasonably clear error message..123*/124if (idx >= __end_of_fixed_addresses)125__this_fixmap_does_not_exist();126127return __fix_to_virt(idx);128}129130static inline unsigned long virt_to_fix(const unsigned long vaddr)131{132BUG_ON(vaddr >= FIXADDR_TOP || vaddr < FIXADDR_START);133return __virt_to_fix(vaddr);134}135#endif136137138