/*1* highmem.c: virtual kernel memory mappings for high memory2*3* PowerPC version, stolen from the i386 version.4*5* Used in CONFIG_HIGHMEM systems for memory pages which6* are not addressable by direct kernel virtual addresses.7*8* Copyright (C) 1999 Gerhard Wichert, Siemens AG9* [email protected]10*11*12* Redesigned the x86 32-bit VM architecture to deal with13* up to 16 Terrabyte physical memory. With current x86 CPUs14* we now support up to 64 Gigabytes physical RAM.15*16* Copyright (C) 1999 Ingo Molnar <[email protected]>17*18* Reworked for PowerPC by various contributors. Moved from19* highmem.h by Benjamin Herrenschmidt (c) 2009 IBM Corp.20*/2122#include <linux/highmem.h>23#include <linux/module.h>2425/*26* The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap27* gives a more generic (and caching) interface. But kmap_atomic can28* be used in IRQ contexts, so in some (very limited) cases we need29* it.30*/31void *kmap_atomic_prot(struct page *page, pgprot_t prot)32{33unsigned long vaddr;34int idx, type;3536/* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */37pagefault_disable();38if (!PageHighMem(page))39return page_address(page);4041type = kmap_atomic_idx_push();42idx = type + KM_TYPE_NR*smp_processor_id();43vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);44#ifdef CONFIG_DEBUG_HIGHMEM45BUG_ON(!pte_none(*(kmap_pte-idx)));46#endif47__set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot), 1);48local_flush_tlb_page(NULL, vaddr);4950return (void*) vaddr;51}52EXPORT_SYMBOL(kmap_atomic_prot);5354void __kunmap_atomic(void *kvaddr)55{56unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;57int type;5859if (vaddr < __fix_to_virt(FIX_KMAP_END)) {60pagefault_enable();61return;62}6364type = kmap_atomic_idx();6566#ifdef CONFIG_DEBUG_HIGHMEM67{68unsigned int idx;6970idx = type + KM_TYPE_NR * smp_processor_id();71BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx));7273/*74* force other mappings to Oops if they'll try to access75* this pte without first remap it76*/77pte_clear(&init_mm, vaddr, kmap_pte-idx);78local_flush_tlb_page(NULL, vaddr);79}80#endif8182kmap_atomic_idx_pop();83pagefault_enable();84}85EXPORT_SYMBOL(__kunmap_atomic);868788