File Index
Files and directories
Sign in
FILE

pgtable.h

File preview with syntax highlighting.

linux-6.19.14/arch/powerpc/include/asm/pgtable.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2#ifndef _ASM_POWERPC_PGTABLE_H
  3#define _ASM_POWERPC_PGTABLE_H
  4
  5#ifndef __ASSEMBLER__
  6#include <linux/mmdebug.h>
  7#include <linux/mmzone.h>
  8#include <asm/processor.h>		/* For TASK_SIZE */
  9#include <asm/mmu.h>
 10#include <asm/page.h>
 11#include <asm/tlbflush.h>
 12
 13struct mm_struct;
 14
 15#endif /* !__ASSEMBLER__ */
 16
 17#ifdef CONFIG_PPC_BOOK3S
 18#include <asm/book3s/pgtable.h>
 19#else
 20#include <asm/nohash/pgtable.h>
 21#endif /* !CONFIG_PPC_BOOK3S */
 22
 23/* Make modules code happy. We don't set RO yet */
 24#define PAGE_KERNEL_EXEC	PAGE_KERNEL_X
 25
 26/* Advertise special mapping type for AGP */
 27#define PAGE_AGP		(PAGE_KERNEL_NC)
 28#define HAVE_PAGE_AGP
 29
 30#ifndef __ASSEMBLER__
 31
 32#define PFN_PTE_SHIFT		PTE_RPN_SHIFT
 33
 34void set_ptes(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
 35		pte_t pte, unsigned int nr);
 36#define set_ptes set_ptes
 37#define update_mmu_cache(vma, addr, ptep) \
 38	update_mmu_cache_range(NULL, vma, addr, ptep, 1)
 39
 40#ifndef MAX_PTRS_PER_PGD
 41#define MAX_PTRS_PER_PGD PTRS_PER_PGD
 42#endif
 43
 44/* Keep this as a macro to avoid include dependency mess */
 45#define pte_page(x)		pfn_to_page(pte_pfn(x))
 46
 47static inline unsigned long pte_pfn(pte_t pte)
 48{
 49	return (pte_val(pte) & PTE_RPN_MASK) >> PTE_RPN_SHIFT;
 50}
 51
 52/*
 53 * Select all bits except the pfn
 54 */
 55#define pte_pgprot pte_pgprot
 56static inline pgprot_t pte_pgprot(pte_t pte)
 57{
 58	unsigned long pte_flags;
 59
 60	pte_flags = pte_val(pte) & ~PTE_RPN_MASK;
 61	return __pgprot(pte_flags);
 62}
 63
 64static inline pgprot_t pgprot_nx(pgprot_t prot)
 65{
 66	return pte_pgprot(pte_exprotect(__pte(pgprot_val(prot))));
 67}
 68#define pgprot_nx pgprot_nx
 69
 70#ifndef pmd_page_vaddr
 71static inline const void *pmd_page_vaddr(pmd_t pmd)
 72{
 73	return __va(pmd_val(pmd) & ~PMD_MASKED_BITS);
 74}
 75#define pmd_page_vaddr pmd_page_vaddr
 76#endif
 77/*
 78 * ZERO_PAGE is a global shared page that is always zero: used
 79 * for zero-mapped memory areas etc..
 80 */
 81extern unsigned long empty_zero_page[];
 82#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
 83
 84extern pgd_t swapper_pg_dir[];
 85
 86extern void paging_init(void);
 87void poking_init(void);
 88
 89extern unsigned long ioremap_bot;
 90extern const pgprot_t protection_map[16];
 91
 92/* can we use this in kvm */
 93unsigned long vmalloc_to_phys(void *vmalloc_addr);
 94
 95void pgtable_cache_add(unsigned int shift);
 96
 97#ifdef CONFIG_PPC32
 98void __init *early_alloc_pgtable(unsigned long size);
 99#endif
100pte_t *early_pte_alloc_kernel(pmd_t *pmdp, unsigned long va);
101
102#if defined(CONFIG_STRICT_KERNEL_RWX) || defined(CONFIG_PPC32)
103void mark_initmem_nx(void);
104#else
105static inline void mark_initmem_nx(void) { }
106#endif
107
108#define __HAVE_ARCH_PTEP_SET_ACCESS_FLAGS
109int ptep_set_access_flags(struct vm_area_struct *vma, unsigned long address,
110			  pte_t *ptep, pte_t entry, int dirty);
111
112pgprot_t __phys_mem_access_prot(unsigned long pfn, unsigned long size,
113				pgprot_t vma_prot);
114
115struct file;
116static inline pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
117					    unsigned long size, pgprot_t vma_prot)
118{
119	return __phys_mem_access_prot(pfn, size, vma_prot);
120}
121#define __HAVE_PHYS_MEM_ACCESS_PROT
122
123void __update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep);
124
125/*
126 * This gets called at the end of handling a page fault, when
127 * the kernel has put a new PTE into the page table for the process.
128 * We use it to ensure coherency between the i-cache and d-cache
129 * for the page which has just been mapped in.
130 * On machines which use an MMU hash table, we use this to put a
131 * corresponding HPTE into the hash table ahead of time, instead of
132 * waiting for the inevitable extra hash-table miss exception.
133 */
134static inline void update_mmu_cache_range(struct vm_fault *vmf,
135		struct vm_area_struct *vma, unsigned long address,
136		pte_t *ptep, unsigned int nr)
137{
138	if ((mmu_has_feature(MMU_FTR_HPTE_TABLE) && !radix_enabled()) ||
139	    (IS_ENABLED(CONFIG_PPC_E500) && IS_ENABLED(CONFIG_HUGETLB_PAGE)))
140		__update_mmu_cache(vma, address, ptep);
141}
142
143/*
144 * When used, PTE_FRAG_NR is defined in subarch pgtable.h
145 * so we are sure it is included when arriving here.
146 */
147#ifdef PTE_FRAG_NR
148static inline void *pte_frag_get(mm_context_t *ctx)
149{
150	return ctx->pte_frag;
151}
152
153static inline void pte_frag_set(mm_context_t *ctx, void *p)
154{
155	ctx->pte_frag = p;
156}
157#else
158#define PTE_FRAG_NR		1
159#define PTE_FRAG_SIZE_SHIFT	PAGE_SHIFT
160#define PTE_FRAG_SIZE		(1UL << PTE_FRAG_SIZE_SHIFT)
161
162static inline void *pte_frag_get(mm_context_t *ctx)
163{
164	return NULL;
165}
166
167static inline void pte_frag_set(mm_context_t *ctx, void *p)
168{
169}
170#endif
171
172#define pmd_pgtable pmd_pgtable
173static inline pgtable_t pmd_pgtable(pmd_t pmd)
174{
175	return (pgtable_t)pmd_page_vaddr(pmd);
176}
177
178#ifdef CONFIG_PPC64
179int __meminit vmemmap_populated(unsigned long vmemmap_addr, int vmemmap_map_size);
180bool altmap_cross_boundary(struct vmem_altmap *altmap, unsigned long start,
181			   unsigned long page_size);
182/*
183 * mm/memory_hotplug.c:mhp_supports_memmap_on_memory goes into details
184 * some of the restrictions. We don't check for PMD_SIZE because our
185 * vmemmap allocation code can fallback correctly. The pageblock
186 * alignment requirement is met using altmap->reserve blocks.
187 */
188#define arch_supports_memmap_on_memory arch_supports_memmap_on_memory
189static inline bool arch_supports_memmap_on_memory(unsigned long vmemmap_size)
190{
191	if (!radix_enabled())
192		return false;
193	/*
194	 * With 4K page size and 2M PMD_SIZE, we can align
195	 * things better with memory block size value
196	 * starting from 128MB. Hence align things with PMD_SIZE.
197	 */
198	if (IS_ENABLED(CONFIG_PPC_4K_PAGES))
199		return IS_ALIGNED(vmemmap_size, PMD_SIZE);
200	return true;
201}
202
203#endif /* CONFIG_PPC64 */
204
205#endif /* __ASSEMBLER__ */
206
207#endif /* _ASM_POWERPC_PGTABLE_H */
~/ Read-only file preview.