1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2005-2017 Andes Technology Corporation
4 #include <linux/export.h>
5 #include <linux/highmem.h>
6 #include <linux/sched.h>
8 #include <linux/interrupt.h>
9 #include <linux/memblock.h>
10 #include <asm/fixmap.h>
11 #include <asm/tlbflush.h>
13 void *kmap(struct page
*page
)
17 if (!PageHighMem(page
))
18 return page_address(page
);
19 vaddr
= (unsigned long)kmap_high(page
);
25 void kunmap(struct page
*page
)
27 BUG_ON(in_interrupt());
28 if (!PageHighMem(page
))
33 EXPORT_SYMBOL(kunmap
);
35 void *kmap_atomic(struct page
*page
)
38 unsigned long vaddr
, pte
;
44 if (!PageHighMem(page
))
45 return page_address(page
);
47 type
= kmap_atomic_idx_push();
49 idx
= type
+ KM_TYPE_NR
* smp_processor_id();
50 vaddr
= __fix_to_virt(FIX_KMAP_BEGIN
+ idx
);
51 pte
= (page_to_pfn(page
) << PAGE_SHIFT
) | (PAGE_KERNEL
);
52 ptep
= pte_offset_kernel(pmd_off_k(vaddr
), vaddr
);
55 __nds32__tlbop_inv(vaddr
);
56 __nds32__mtsr_dsb(vaddr
, NDS32_SR_TLB_VPN
);
57 __nds32__tlbop_rwr(pte
);
62 EXPORT_SYMBOL(kmap_atomic
);
64 void __kunmap_atomic(void *kvaddr
)
66 if (kvaddr
>= (void *)FIXADDR_START
) {
67 unsigned long vaddr
= (unsigned long)kvaddr
;
69 kmap_atomic_idx_pop();
70 __nds32__tlbop_inv(vaddr
);
72 ptep
= pte_offset_kernel(pmd_off_k(vaddr
), vaddr
);
79 EXPORT_SYMBOL(__kunmap_atomic
);