xref: /openbmc/linux/arch/arc/mm/highmem.c (revision 39cac191)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
245890f6dSVineet Gupta /*
345890f6dSVineet Gupta  * Copyright (C) 2015 Synopsys, Inc. (www.synopsys.com)
445890f6dSVineet Gupta  */
545890f6dSVineet Gupta 
657c8a661SMike Rapoport #include <linux/memblock.h>
745890f6dSVineet Gupta #include <linux/export.h>
845890f6dSVineet Gupta #include <linux/highmem.h>
9ca5999fdSMike Rapoport #include <linux/pgtable.h>
1065fddcfcSMike Rapoport #include <asm/processor.h>
1145890f6dSVineet Gupta #include <asm/pgalloc.h>
1245890f6dSVineet Gupta #include <asm/tlbflush.h>
1345890f6dSVineet Gupta 
1445890f6dSVineet Gupta /*
1545890f6dSVineet Gupta  * HIGHMEM API:
1645890f6dSVineet Gupta  *
177423cc0cSAdam Buchbinder  * kmap() API provides sleep semantics hence referred to as "permanent maps"
1845890f6dSVineet Gupta  * It allows mapping LAST_PKMAP pages, using @last_pkmap_nr as the cursor
1945890f6dSVineet Gupta  * for book-keeping
2045890f6dSVineet Gupta  *
2145890f6dSVineet Gupta  * kmap_atomic() can't sleep (calls pagefault_disable()), thus it provides
2245890f6dSVineet Gupta  * shortlived ala "temporary mappings" which historically were implemented as
2345890f6dSVineet Gupta  * fixmaps (compile time addr etc). Their book-keeping is done per cpu.
2445890f6dSVineet Gupta  *
2545890f6dSVineet Gupta  *	Both these facts combined (preemption disabled and per-cpu allocation)
2645890f6dSVineet Gupta  *	means the total number of concurrent fixmaps will be limited to max
2745890f6dSVineet Gupta  *	such allocations in a single control path. Thus KM_TYPE_NR (another
2845890f6dSVineet Gupta  *	historic relic) is a small'ish number which caps max percpu fixmaps
2945890f6dSVineet Gupta  *
3045890f6dSVineet Gupta  * ARC HIGHMEM Details
3145890f6dSVineet Gupta  *
3245890f6dSVineet Gupta  * - the kernel vaddr space from 0x7z to 0x8z (currently used by vmalloc/module)
3345890f6dSVineet Gupta  *   is now shared between vmalloc and kmap (non overlapping though)
3445890f6dSVineet Gupta  *
3545890f6dSVineet Gupta  * - Both fixmap/pkmap use a dedicated page table each, hooked up to swapper PGD
3645890f6dSVineet Gupta  *   This means each only has 1 PGDIR_SIZE worth of kvaddr mappings, which means
3745890f6dSVineet Gupta  *   2M of kvaddr space for typical config (8K page and 11:8:13 traversal split)
3845890f6dSVineet Gupta  *
39*39cac191SThomas Gleixner  * - The fixed KMAP slots for kmap_local/atomic() require KM_MAX_IDX slots per
40*39cac191SThomas Gleixner  *   CPU. So the number of CPUs sharing a single PTE page is limited.
4145890f6dSVineet Gupta  *
4245890f6dSVineet Gupta  * - pkmap being preemptible, in theory could do with more than 256 concurrent
4345890f6dSVineet Gupta  *   mappings. However, generic pkmap code: map_new_virtual(), doesn't traverse
4445890f6dSVineet Gupta  *   the PGD and only works with a single page table @pkmap_page_table, hence
4545890f6dSVineet Gupta  *   sets the limit
4645890f6dSVineet Gupta  */
4745890f6dSVineet Gupta 
4845890f6dSVineet Gupta extern pte_t * pkmap_page_table;
4945890f6dSVineet Gupta 
alloc_kmap_pgtable(unsigned long kvaddr)50899cfd2bSVineet Gupta static noinline pte_t * __init alloc_kmap_pgtable(unsigned long kvaddr)
5145890f6dSVineet Gupta {
52e05c7b1fSMike Rapoport 	pmd_t *pmd_k = pmd_off_k(kvaddr);
5345890f6dSVineet Gupta 	pte_t *pte_k;
5445890f6dSVineet Gupta 
55e8625dceSMike Rapoport 	pte_k = (pte_t *)memblock_alloc_low(PAGE_SIZE, PAGE_SIZE);
568a7f97b9SMike Rapoport 	if (!pte_k)
578a7f97b9SMike Rapoport 		panic("%s: Failed to allocate %lu bytes align=0x%lx\n",
588a7f97b9SMike Rapoport 		      __func__, PAGE_SIZE, PAGE_SIZE);
598a7f97b9SMike Rapoport 
6045890f6dSVineet Gupta 	pmd_populate_kernel(&init_mm, pmd_k, pte_k);
6145890f6dSVineet Gupta 	return pte_k;
6245890f6dSVineet Gupta }
6345890f6dSVineet Gupta 
kmap_init(void)64899cfd2bSVineet Gupta void __init kmap_init(void)
6545890f6dSVineet Gupta {
6645890f6dSVineet Gupta 	/* Due to recursive include hell, we can't do this in processor.h */
6745890f6dSVineet Gupta 	BUILD_BUG_ON(PAGE_OFFSET < (VMALLOC_END + FIXMAP_SIZE + PKMAP_SIZE));
6845890f6dSVineet Gupta 	BUILD_BUG_ON(LAST_PKMAP > PTRS_PER_PTE);
69*39cac191SThomas Gleixner 	BUILD_BUG_ON(FIX_KMAP_SLOTS > PTRS_PER_PTE);
70*39cac191SThomas Gleixner 
71*39cac191SThomas Gleixner 	pkmap_page_table = alloc_kmap_pgtable(PKMAP_BASE);
72*39cac191SThomas Gleixner 	alloc_kmap_pgtable(FIXMAP_BASE);
7345890f6dSVineet Gupta }
74