Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 1 | /* |
| 2 | * highmem.h: 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 | |
| 20 | #ifndef _ASM_HIGHMEM_H |
| 21 | #define _ASM_HIGHMEM_H |
| 22 | |
| 23 | #ifdef __KERNEL__ |
| 24 | |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/interrupt.h> |
| 27 | #include <asm/kmap_types.h> |
| 28 | #include <asm/tlbflush.h> |
| 29 | #include <asm/page.h> |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 30 | #include <asm/fixmap.h> |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 31 | |
| 32 | extern pte_t *kmap_pte; |
| 33 | extern pgprot_t kmap_prot; |
| 34 | extern pte_t *pkmap_page_table; |
| 35 | |
| 36 | /* |
| 37 | * Right now we initialize only a single pte table. It can be extended |
| 38 | * easily, subsequent pte tables have to be allocated in one physical |
| 39 | * chunk of RAM. |
| 40 | */ |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 41 | /* |
| 42 | * We use one full pte table with 4K pages. And with 16K/64K pages pte |
| 43 | * table covers enough memory (32MB and 512MB resp.) that both FIXMAP |
| 44 | * and PKMAP can be placed in single pte table. We use 1024 pages for |
| 45 | * PKMAP in case of 16K/64K pages. |
| 46 | */ |
| 47 | #ifdef CONFIG_PPC_4K_PAGES |
| 48 | #define PKMAP_ORDER PTE_SHIFT |
| 49 | #else |
| 50 | #define PKMAP_ORDER 10 |
| 51 | #endif |
| 52 | #define LAST_PKMAP (1 << PKMAP_ORDER) |
| 53 | #ifndef CONFIG_PPC_4K_PAGES |
| 54 | #define PKMAP_BASE (FIXADDR_START - PAGE_SIZE*(LAST_PKMAP + 1)) |
| 55 | #else |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 56 | #define PKMAP_BASE ((FIXADDR_START - PAGE_SIZE*(LAST_PKMAP + 1)) & PMD_MASK) |
Ilya Yanok | ca9153a | 2008-12-11 04:55:41 +0300 | [diff] [blame] | 57 | #endif |
| 58 | #define LAST_PKMAP_MASK (LAST_PKMAP-1) |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 59 | #define PKMAP_NR(virt) ((virt-PKMAP_BASE) >> PAGE_SHIFT) |
| 60 | #define PKMAP_ADDR(nr) (PKMAP_BASE + ((nr) << PAGE_SHIFT)) |
| 61 | |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 62 | extern void *kmap_high(struct page *page); |
| 63 | extern void kunmap_high(struct page *page); |
| 64 | |
| 65 | static inline void *kmap(struct page *page) |
| 66 | { |
| 67 | might_sleep(); |
| 68 | if (!PageHighMem(page)) |
| 69 | return page_address(page); |
| 70 | return kmap_high(page); |
| 71 | } |
| 72 | |
| 73 | static inline void kunmap(struct page *page) |
| 74 | { |
| 75 | BUG_ON(in_interrupt()); |
| 76 | if (!PageHighMem(page)) |
| 77 | return; |
| 78 | kunmap_high(page); |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap |
| 83 | * gives a more generic (and caching) interface. But kmap_atomic can |
| 84 | * be used in IRQ contexts, so in some (very limited) cases we need |
| 85 | * it. |
| 86 | */ |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 87 | static inline void *kmap_atomic_prot(struct page *page, enum km_type type, pgprot_t prot) |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 88 | { |
| 89 | unsigned int idx; |
| 90 | unsigned long vaddr; |
| 91 | |
| 92 | /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */ |
| 93 | pagefault_disable(); |
| 94 | if (!PageHighMem(page)) |
| 95 | return page_address(page); |
| 96 | |
| 97 | idx = type + KM_TYPE_NR*smp_processor_id(); |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 98 | vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx); |
| 99 | #ifdef CONFIG_DEBUG_HIGHMEM |
| 100 | BUG_ON(!pte_none(*(kmap_pte-idx))); |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 101 | #endif |
Kumar Gala | 9bf2b5c | 2008-07-16 15:54:21 -0500 | [diff] [blame] | 102 | __set_pte_at(&init_mm, vaddr, kmap_pte-idx, mk_pte(page, prot)); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 103 | local_flush_tlb_page(NULL, vaddr); |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 104 | |
| 105 | return (void*) vaddr; |
| 106 | } |
| 107 | |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 108 | static inline void *kmap_atomic(struct page *page, enum km_type type) |
| 109 | { |
| 110 | return kmap_atomic_prot(page, type, kmap_prot); |
| 111 | } |
| 112 | |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 113 | static inline void kunmap_atomic(void *kvaddr, enum km_type type) |
| 114 | { |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 115 | #ifdef CONFIG_DEBUG_HIGHMEM |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 116 | unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK; |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 117 | enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id(); |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 118 | |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 119 | if (vaddr < __fix_to_virt(FIX_KMAP_END)) { |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 120 | pagefault_enable(); |
| 121 | return; |
| 122 | } |
| 123 | |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 124 | BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx)); |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 125 | |
| 126 | /* |
| 127 | * force other mappings to Oops if they'll try to access |
| 128 | * this pte without first remap it |
| 129 | */ |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 130 | pte_clear(&init_mm, vaddr, kmap_pte-idx); |
Benjamin Herrenschmidt | f048aac | 2008-12-18 19:13:38 +0000 | [diff] [blame] | 131 | local_flush_tlb_page(NULL, vaddr); |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 132 | #endif |
| 133 | pagefault_enable(); |
| 134 | } |
| 135 | |
| 136 | static inline struct page *kmap_atomic_to_page(void *ptr) |
| 137 | { |
| 138 | unsigned long idx, vaddr = (unsigned long) ptr; |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 139 | pte_t *pte; |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 140 | |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 141 | if (vaddr < FIXADDR_START) |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 142 | return virt_to_page(ptr); |
| 143 | |
Kumar Gala | 2c419bd | 2008-04-23 23:05:20 +1000 | [diff] [blame] | 144 | idx = virt_to_fix(vaddr); |
| 145 | pte = kmap_pte - (idx - FIX_KMAP_BEGIN); |
| 146 | return pte_page(*pte); |
Kumar Gala | 33d71d2 | 2007-08-20 08:50:28 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | #define flush_cache_kmaps() flush_cache_all() |
| 150 | |
| 151 | #endif /* __KERNEL__ */ |
| 152 | |
| 153 | #endif /* _ASM_HIGHMEM_H */ |