]> Git Repo - linux.git/blob - arch/sparc/mm/highmem.c
Merge tag 'for-linus-5.5-ofs1' of git://git.kernel.org/pub/scm/linux/kernel/git/hubca...
[linux.git] / arch / sparc / mm / highmem.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *  highmem.c: virtual kernel memory mappings for high memory
4  *
5  *  Provides kernel-static versions of atomic kmap functions originally
6  *  found as inlines in include/asm-sparc/highmem.h.  These became
7  *  needed as kmap_atomic() and kunmap_atomic() started getting
8  *  called from within modules.
9  *  -- Tomas Szepe <[email protected]>, September 2002
10  *
11  *  But kmap_atomic() and kunmap_atomic() cannot be inlined in
12  *  modules because they are loaded with btfixup-ped functions.
13  */
14
15 /*
16  * The use of kmap_atomic/kunmap_atomic is discouraged - kmap/kunmap
17  * gives a more generic (and caching) interface. But kmap_atomic can
18  * be used in IRQ contexts, so in some (very limited) cases we need it.
19  *
20  * XXX This is an old text. Actually, it's good to use atomic kmaps,
21  * provided you remember that they are atomic and not try to sleep
22  * with a kmap taken, much like a spinlock. Non-atomic kmaps are
23  * shared by CPUs, and so precious, and establishing them requires IPI.
24  * Atomic kmaps are lightweight and we may have NCPUS more of them.
25  */
26 #include <linux/highmem.h>
27 #include <linux/export.h>
28 #include <linux/mm.h>
29
30 #include <asm/cacheflush.h>
31 #include <asm/tlbflush.h>
32 #include <asm/pgalloc.h>
33 #include <asm/vaddrs.h>
34
35 pgprot_t kmap_prot;
36
37 static pte_t *kmap_pte;
38
39 void __init kmap_init(void)
40 {
41         unsigned long address;
42         p4d_t *p4d;
43         pud_t *pud;
44         pmd_t *dir;
45
46         address = __fix_to_virt(FIX_KMAP_BEGIN);
47         p4d = p4d_offset(pgd_offset_k(address), address);
48         pud = pud_offset(p4d, address);
49         dir = pmd_offset(pud, address);
50
51         /* cache the first kmap pte */
52         kmap_pte = pte_offset_kernel(dir, address);
53         kmap_prot = __pgprot(SRMMU_ET_PTE | SRMMU_PRIV | SRMMU_CACHE);
54 }
55
56 void *kmap_atomic(struct page *page)
57 {
58         unsigned long vaddr;
59         long idx, type;
60
61         preempt_disable();
62         pagefault_disable();
63         if (!PageHighMem(page))
64                 return page_address(page);
65
66         type = kmap_atomic_idx_push();
67         idx = type + KM_TYPE_NR*smp_processor_id();
68         vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
69
70 /* XXX Fix - Anton */
71 #if 0
72         __flush_cache_one(vaddr);
73 #else
74         flush_cache_all();
75 #endif
76
77 #ifdef CONFIG_DEBUG_HIGHMEM
78         BUG_ON(!pte_none(*(kmap_pte-idx)));
79 #endif
80         set_pte(kmap_pte-idx, mk_pte(page, kmap_prot));
81 /* XXX Fix - Anton */
82 #if 0
83         __flush_tlb_one(vaddr);
84 #else
85         flush_tlb_all();
86 #endif
87
88         return (void*) vaddr;
89 }
90 EXPORT_SYMBOL(kmap_atomic);
91
92 void __kunmap_atomic(void *kvaddr)
93 {
94         unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
95         int type;
96
97         if (vaddr < FIXADDR_START) { // FIXME
98                 pagefault_enable();
99                 preempt_enable();
100                 return;
101         }
102
103         type = kmap_atomic_idx();
104
105 #ifdef CONFIG_DEBUG_HIGHMEM
106         {
107                 unsigned long idx;
108
109                 idx = type + KM_TYPE_NR * smp_processor_id();
110                 BUG_ON(vaddr != __fix_to_virt(FIX_KMAP_BEGIN+idx));
111
112                 /* XXX Fix - Anton */
113 #if 0
114                 __flush_cache_one(vaddr);
115 #else
116                 flush_cache_all();
117 #endif
118
119                 /*
120                  * force other mappings to Oops if they'll try to access
121                  * this pte without first remap it
122                  */
123                 pte_clear(&init_mm, vaddr, kmap_pte-idx);
124                 /* XXX Fix - Anton */
125 #if 0
126                 __flush_tlb_one(vaddr);
127 #else
128                 flush_tlb_all();
129 #endif
130         }
131 #endif
132
133         kmap_atomic_idx_pop();
134         pagefault_enable();
135         preempt_enable();
136 }
137 EXPORT_SYMBOL(__kunmap_atomic);
This page took 0.041192 seconds and 4 git commands to generate.