1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Page table support for the Hexagon architecture
5 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
11 #include <asm/mem-layout.h>
12 #include <asm/atomic.h>
14 #include <asm-generic/pgalloc.h>
16 extern unsigned long long kmap_generation
;
19 * Page table creation interface
21 static inline pgd_t
*pgd_alloc(struct mm_struct
*mm
)
25 pgd
= (pgd_t
*)__get_free_page(GFP_KERNEL
| __GFP_ZERO
);
28 * There may be better ways to do this, but to ensure
29 * that new address spaces always contain the kernel
30 * base mapping, and to ensure that the user area is
31 * initially marked invalid, initialize the new map
32 * map with a copy of the kernel's persistent map.
35 memcpy(pgd
, swapper_pg_dir
, PTRS_PER_PGD
*sizeof(pgd_t
));
36 mm
->context
.generation
= kmap_generation
;
38 /* Physical version is what is passed to virtual machine on switch */
39 mm
->context
.ptbase
= __pa(pgd
);
44 static inline void pmd_populate(struct mm_struct
*mm
, pmd_t
*pmd
,
48 * Conveniently, zero in 3 LSB means indirect 4K page table.
49 * Not so convenient when you're trying to vary the page size.
51 set_pmd(pmd
, __pmd(((unsigned long)page_to_pfn(pte
) << PAGE_SHIFT
) |
52 HEXAGON_L1_PTE_SIZE
));
56 * Other architectures seem to have ways of making all processes
57 * share the same pmd's for their kernel mappings, but the v0.3
58 * Hexagon VM spec has a "monolithic" L1 table for user and kernel
59 * segments. We track "generations" of the kernel map to minimize
60 * overhead, and update the "slave" copies of the kernel mappings
61 * as part of switch_mm. However, we still need to update the
62 * kernel map of the active thread who's calling pmd_populate_kernel...
64 static inline void pmd_populate_kernel(struct mm_struct
*mm
, pmd_t
*pmd
,
67 extern spinlock_t kmap_gen_lock
;
71 spin_lock(&kmap_gen_lock
);
73 mm
->context
.generation
= kmap_generation
;
74 current
->active_mm
->context
.generation
= kmap_generation
;
75 spin_unlock(&kmap_gen_lock
);
77 set_pmd(pmd
, __pmd(((unsigned long)__pa(pte
)) | HEXAGON_L1_PTE_SIZE
));
80 * Now the "slave" copy of the current thread.
81 * This is pointer arithmetic, not byte addresses!
83 pmdindex
= (pgd_t
*)pmd
- mm
->pgd
;
84 ppmd
= (pmd_t
*)current
->active_mm
->pgd
+ pmdindex
;
85 set_pmd(ppmd
, __pmd(((unsigned long)__pa(pte
)) | HEXAGON_L1_PTE_SIZE
));
86 if (pmdindex
> max_kernel_seg
)
87 max_kernel_seg
= pmdindex
;
90 #define __pte_free_tlb(tlb, pte, addr) \
92 pgtable_pte_page_dtor((pte)); \
93 tlb_remove_page((tlb), (pte)); \