Merge tag 'x86-urgent-2020-08-15' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / arch / x86 / mm / highmem_32.c
blob075fe51317b0fe3e3692c9bd70095d236f357e1f
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/highmem.h>
3 #include <linux/export.h>
4 #include <linux/swap.h> /* for totalram_pages */
5 #include <linux/memblock.h>
7 void *kmap_atomic_high_prot(struct page *page, pgprot_t prot)
9 unsigned long vaddr;
10 int idx, type;
12 type = kmap_atomic_idx_push();
13 idx = type + KM_TYPE_NR*smp_processor_id();
14 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
15 BUG_ON(!pte_none(*(kmap_pte-idx)));
16 set_pte(kmap_pte-idx, mk_pte(page, prot));
17 arch_flush_lazy_mmu_mode();
19 return (void *)vaddr;
21 EXPORT_SYMBOL(kmap_atomic_high_prot);
24 * This is the same as kmap_atomic() but can map memory that doesn't
25 * have a struct page associated with it.
27 void *kmap_atomic_pfn(unsigned long pfn)
29 return kmap_atomic_prot_pfn(pfn, kmap_prot);
31 EXPORT_SYMBOL_GPL(kmap_atomic_pfn);
33 void kunmap_atomic_high(void *kvaddr)
35 unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
37 if (vaddr >= __fix_to_virt(FIX_KMAP_END) &&
38 vaddr <= __fix_to_virt(FIX_KMAP_BEGIN)) {
39 int idx, type;
41 type = kmap_atomic_idx();
42 idx = type + KM_TYPE_NR * smp_processor_id();
44 #ifdef CONFIG_DEBUG_HIGHMEM
45 WARN_ON_ONCE(vaddr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
46 #endif
48 * Force other mappings to Oops if they'll try to access this
49 * pte without first remap it. Keeping stale mappings around
50 * is a bad idea also, in case the page changes cacheability
51 * attributes or becomes a protected page in a hypervisor.
53 kpte_clear_flush(kmap_pte-idx, vaddr);
54 kmap_atomic_idx_pop();
55 arch_flush_lazy_mmu_mode();
57 #ifdef CONFIG_DEBUG_HIGHMEM
58 else {
59 BUG_ON(vaddr < PAGE_OFFSET);
60 BUG_ON(vaddr >= (unsigned long)high_memory);
62 #endif
64 EXPORT_SYMBOL(kunmap_atomic_high);
66 void __init set_highmem_pages_init(void)
68 struct zone *zone;
69 int nid;
72 * Explicitly reset zone->managed_pages because set_highmem_pages_init()
73 * is invoked before memblock_free_all()
75 reset_all_zones_managed_pages();
76 for_each_zone(zone) {
77 unsigned long zone_start_pfn, zone_end_pfn;
79 if (!is_highmem(zone))
80 continue;
82 zone_start_pfn = zone->zone_start_pfn;
83 zone_end_pfn = zone_start_pfn + zone->spanned_pages;
85 nid = zone_to_nid(zone);
86 printk(KERN_INFO "Initializing %s for node %d (%08lx:%08lx)\n",
87 zone->name, nid, zone_start_pfn, zone_end_pfn);
89 add_highpages_with_active_regions(nid, zone_start_pfn,
90 zone_end_pfn);