1
2
3
4
5
6#include <linux/memblock.h>
7#include <linux/export.h>
8#include <linux/highmem.h>
9#include <linux/pgtable.h>
10#include <asm/processor.h>
11#include <asm/pgalloc.h>
12#include <asm/tlbflush.h>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49extern pte_t * pkmap_page_table;
50static pte_t * fixmap_page_table;
51
52void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
53{
54 int idx, cpu_idx;
55 unsigned long vaddr;
56
57 cpu_idx = kmap_atomic_idx_push();
58 idx = cpu_idx + KM_TYPE_NR * smp_processor_id();
59 vaddr = FIXMAP_ADDR(idx);
60
61 set_pte_at(&init_mm, vaddr, fixmap_page_table + idx,
62 mk_pte(page, prot));
63
64 return (void *)vaddr;
65}
66EXPORT_SYMBOL(kmap_atomic_high_prot);
67
68void kunmap_atomic_high(void *kv)
69{
70 unsigned long kvaddr = (unsigned long)kv;
71
72 if (kvaddr >= FIXMAP_BASE && kvaddr < (FIXMAP_BASE + FIXMAP_SIZE)) {
73
74
75
76
77
78
79
80 int cpu_idx = kmap_atomic_idx();
81 int idx = cpu_idx + KM_TYPE_NR * smp_processor_id();
82
83 WARN_ON(kvaddr != FIXMAP_ADDR(idx));
84
85 pte_clear(&init_mm, kvaddr, fixmap_page_table + idx);
86 local_flush_tlb_kernel_range(kvaddr, kvaddr + PAGE_SIZE);
87
88 kmap_atomic_idx_pop();
89 }
90}
91EXPORT_SYMBOL(kunmap_atomic_high);
92
93static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr)
94{
95 pmd_t *pmd_k = pmd_off_k(kvaddr);
96 pte_t *pte_k;
97
98 pte_k = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
99 if (!pte_k)
100 panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
101 __func__, PAGE_SIZE, PAGE_SIZE);
102
103 pmd_populate_kernel(&init_mm, pmd_k, pte_k);
104 return pte_k;
105}
106
107void __init kmap_init(void)
108{
109
110 BUILD_BUG_ON(PAGE_OFFSET < (VMALLOC_END + FIXMAP_SIZE + PKMAP_SIZE));
111
112 BUILD_BUG_ON(KM_TYPE_NR > PTRS_PER_PTE);
113 pkmap_page_table = alloc_kmap_pgtable(PKMAP_BASE);
114
115 BUILD_BUG_ON(LAST_PKMAP > PTRS_PER_PTE);
116 fixmap_page_table = alloc_kmap_pgtable(FIXMAP_BASE);
117}
118