Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * highmem.c: virtual kernel memory mappings for high memory |
| 3 | * |
| 4 | * PowerPC version, stolen from the i386 version. |
| 5 | * |
| 6 | * Used in CONFIG_HIGHMEM systems for memory pages which |
| 7 | * are not addressable by direct kernel virtual addresses. |
| 8 | * |
| 9 | * Copyright (C) 1999 Gerhard Wichert, Siemens AG |
| 10 | * Gerhard.Wichert@pdb.siemens.de |
| 11 | * |
| 12 | * |
| 13 | * Redesigned the x86 32-bit VM architecture to deal with |
| 14 | * up to 16 Terrabyte physical memory. With current x86 CPUs |
| 15 | * we now support up to 64 Gigabytes physical RAM. |
| 16 | * |
| 17 | * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com> |
| 18 | * |
| 19 | * Reworked for PowerPC by various contributors. Moved from |
| 20 | * highmem.h by Benjamin Herrenschmidt (c) 2009 IBM Corp. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/highmem.h> |
| 24 | #include <linux/module.h> |
| 25 | |
| 26 | /* |
| 27 | * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap |
| 28 | * gives a more generic (and caching) interface. But kmap_atomic can |
| 29 | * be used in IRQ contexts, so in some (very limited) cases we need |
| 30 | * it. |
| 31 | */ |
Peter Zijlstra | 3e4d3af | 2010-10-26 14:21:51 -0700 | [diff] [blame] | 32 | void *kmap_atomic_prot(struct page *page, pgprot_t prot) |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 33 | { |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 34 | unsigned long vaddr; |
Peter Zijlstra | 3e4d3af | 2010-10-26 14:21:51 -0700 | [diff] [blame] | 35 | int idx, type; |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 36 | |
David Hildenbrand | 2cb7c9c | 2015-05-11 17:52:09 +0200 | [diff] [blame] | 37 | preempt_disable(); |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 38 | pagefault_disable(); |
| 39 | if (!PageHighMem(page)) |
| 40 | return page_address(page); |
| 41 | |
Peter Zijlstra | 3e4d3af | 2010-10-26 14:21:51 -0700 | [diff] [blame] | 42 | type = kmap_atomic_idx_push(); |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 43 | idx = type + KM_TYPE_NR*smp_processor_id(); |
| 44 | vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); |
| 45 | #ifdef CONFIG_DEBUG_HIGHMEM |
| 46 | BUG_ON(!pte_none(*(kmap_pte-idx))); |
| 47 | #endif |
| 48 | __set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot), 1); |
| 49 | local_flush_tlb_page(NULL, vaddr); |
| 50 | |
| 51 | return (void*) vaddr; |
| 52 | } |
| 53 | EXPORT_SYMBOL(kmap_atomic_prot); |
| 54 | |
Peter Zijlstra | 3e4d3af | 2010-10-26 14:21:51 -0700 | [diff] [blame] | 55 | void __kunmap_atomic(void *kvaddr) |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 56 | { |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 57 | unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK; |
Peter Zijlstra | 3e4d3af | 2010-10-26 14:21:51 -0700 | [diff] [blame] | 58 | int type; |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 59 | |
| 60 | if (vaddr < __fix_to_virt(FIX_KMAP_END)) { |
| 61 | pagefault_enable(); |
David Hildenbrand | 2cb7c9c | 2015-05-11 17:52:09 +0200 | [diff] [blame] | 62 | preempt_enable(); |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 63 | return; |
| 64 | } |
| 65 | |
Peter Zijlstra | 2027394 | 2010-10-27 15:32:58 -0700 | [diff] [blame] | 66 | type = kmap_atomic_idx(); |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 67 | |
Peter Zijlstra | 3e4d3af | 2010-10-26 14:21:51 -0700 | [diff] [blame] | 68 | #ifdef CONFIG_DEBUG_HIGHMEM |
| 69 | { |
| 70 | unsigned int idx; |
| 71 | |
| 72 | idx = type + KM_TYPE_NR * smp_processor_id(); |
| 73 | BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx)); |
| 74 | |
| 75 | /* |
| 76 | * force other mappings to Oops if they'll try to access |
| 77 | * this pte without first remap it |
| 78 | */ |
| 79 | pte_clear(&init_mm, vaddr, kmap_pte-idx); |
| 80 | local_flush_tlb_page(NULL, vaddr); |
| 81 | } |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 82 | #endif |
Peter Zijlstra | 2027394 | 2010-10-27 15:32:58 -0700 | [diff] [blame] | 83 | |
| 84 | kmap_atomic_idx_pop(); |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 85 | pagefault_enable(); |
David Hildenbrand | 2cb7c9c | 2015-05-11 17:52:09 +0200 | [diff] [blame] | 86 | preempt_enable(); |
Benjamin Herrenschmidt | 850f6ac | 2009-06-18 19:25:00 +0000 | [diff] [blame] | 87 | } |
Peter Zijlstra | 3e4d3af | 2010-10-26 14:21:51 -0700 | [diff] [blame] | 88 | EXPORT_SYMBOL(__kunmap_atomic); |