]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - arch/powerpc/include/asm/mmu_context.h
Merge remote-tracking branches 'asoc/topic/cs35l32', 'asoc/topic/cs35l34', 'asoc...
[mirror_ubuntu-jammy-kernel.git] / arch / powerpc / include / asm / mmu_context.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
047ea784
PM
2#ifndef __ASM_POWERPC_MMU_CONTEXT_H
3#define __ASM_POWERPC_MMU_CONTEXT_H
88ced031 4#ifdef __KERNEL__
047ea784 5
5e696617
BH
6#include <linux/kernel.h>
7#include <linux/mm.h>
8#include <linux/sched.h>
9#include <linux/spinlock.h>
80a7cc6c
KG
10#include <asm/mmu.h>
11#include <asm/cputable.h>
5e696617 12#include <asm/cputhreads.h>
80a7cc6c
KG
13
14/*
5e696617 15 * Most if the context management is out of line
80a7cc6c 16 */
1da177e4
LT
17extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm);
18extern void destroy_context(struct mm_struct *mm);
15b244a8
AK
19#ifdef CONFIG_SPAPR_TCE_IOMMU
20struct mm_iommu_table_group_mem_t;
21
2e5bbb54 22extern int isolate_lru_page(struct page *page); /* from internal.h */
d7baee69
AK
23extern bool mm_iommu_preregistered(struct mm_struct *mm);
24extern long mm_iommu_get(struct mm_struct *mm,
25 unsigned long ua, unsigned long entries,
15b244a8 26 struct mm_iommu_table_group_mem_t **pmem);
d7baee69
AK
27extern long mm_iommu_put(struct mm_struct *mm,
28 struct mm_iommu_table_group_mem_t *mem);
88f54a35
AK
29extern void mm_iommu_init(struct mm_struct *mm);
30extern void mm_iommu_cleanup(struct mm_struct *mm);
d7baee69
AK
31extern struct mm_iommu_table_group_mem_t *mm_iommu_lookup(struct mm_struct *mm,
32 unsigned long ua, unsigned long size);
6b5c19c5
AK
33extern struct mm_iommu_table_group_mem_t *mm_iommu_lookup_rm(
34 struct mm_struct *mm, unsigned long ua, unsigned long size);
d7baee69
AK
35extern struct mm_iommu_table_group_mem_t *mm_iommu_find(struct mm_struct *mm,
36 unsigned long ua, unsigned long entries);
15b244a8
AK
37extern long mm_iommu_ua_to_hpa(struct mm_iommu_table_group_mem_t *mem,
38 unsigned long ua, unsigned long *hpa);
6b5c19c5
AK
39extern long mm_iommu_ua_to_hpa_rm(struct mm_iommu_table_group_mem_t *mem,
40 unsigned long ua, unsigned long *hpa);
15b244a8
AK
41extern long mm_iommu_mapped_inc(struct mm_iommu_table_group_mem_t *mem);
42extern void mm_iommu_mapped_dec(struct mm_iommu_table_group_mem_t *mem);
43#endif
1da177e4 44extern void switch_slb(struct task_struct *tsk, struct mm_struct *mm);
5e696617 45extern void set_context(unsigned long id, pgd_t *pgd);
1da177e4 46
6f0ef0f5 47#ifdef CONFIG_PPC_BOOK3S_64
7e381c0f 48extern void radix__switch_mmu_context(struct mm_struct *prev,
a25bd72b 49 struct mm_struct *next);
d2adba3f
AK
50static inline void switch_mmu_context(struct mm_struct *prev,
51 struct mm_struct *next,
52 struct task_struct *tsk)
53{
7e381c0f
AK
54 if (radix_enabled())
55 return radix__switch_mmu_context(prev, next);
d2adba3f
AK
56 return switch_slb(tsk, next);
57}
58
a336f2f5 59extern int hash__alloc_context_id(void);
82228e36 60extern void hash__reserve_context_id(int id);
e85a4710 61extern void __destroy_context(int context_id);
6f0ef0f5
BH
62static inline void mmu_context_init(void) { }
63#else
d2adba3f
AK
64extern void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next,
65 struct task_struct *tsk);
c83ec269
AG
66extern unsigned long __init_new_context(void);
67extern void __destroy_context(unsigned long context_id);
6f0ef0f5
BH
68extern void mmu_context_init(void);
69#endif
70
a25bd72b
BH
71#if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE) && defined(CONFIG_PPC_RADIX_MMU)
72extern void radix_kvm_prefetch_workaround(struct mm_struct *mm);
73#else
74static inline void radix_kvm_prefetch_workaround(struct mm_struct *mm) { }
75#endif
76
851d2e2f
THFL
77extern void switch_cop(struct mm_struct *next);
78extern int use_cop(unsigned long acop, struct mm_struct *mm);
79extern void drop_cop(unsigned long acop, struct mm_struct *mm);
80
03b8abed
FB
81#ifdef CONFIG_PPC_BOOK3S_64
82static inline void inc_mm_active_cpus(struct mm_struct *mm)
83{
84 atomic_inc(&mm->context.active_cpus);
85}
86
87static inline void dec_mm_active_cpus(struct mm_struct *mm)
88{
89 atomic_dec(&mm->context.active_cpus);
90}
91
92static inline void mm_context_add_copro(struct mm_struct *mm)
93{
94 /*
95 * On hash, should only be called once over the lifetime of
96 * the context, as we can't decrement the active cpus count
97 * and flush properly for the time being.
98 */
99 inc_mm_active_cpus(mm);
100}
101
102static inline void mm_context_remove_copro(struct mm_struct *mm)
103{
104 /*
105 * Need to broadcast a global flush of the full mm before
106 * decrementing active_cpus count, as the next TLBI may be
107 * local and the nMMU and/or PSL need to be cleaned up.
108 * Should be rare enough so that it's acceptable.
109 *
110 * Skip on hash, as we don't know how to do the proper flush
111 * for the time being. Invalidations will remain global if
112 * used on hash.
113 */
114 if (radix_enabled()) {
115 flush_all_mm(mm);
116 dec_mm_active_cpus(mm);
117 }
118}
119#else
120static inline void inc_mm_active_cpus(struct mm_struct *mm) { }
121static inline void dec_mm_active_cpus(struct mm_struct *mm) { }
122static inline void mm_context_add_copro(struct mm_struct *mm) { }
123static inline void mm_context_remove_copro(struct mm_struct *mm) { }
124#endif
125
126
3a2df379
BH
127extern void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next,
128 struct task_struct *tsk);
1da177e4 129
9765ad13
DG
130static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
131 struct task_struct *tsk)
132{
133 unsigned long flags;
134
135 local_irq_save(flags);
136 switch_mm_irqs_off(prev, next, tsk);
137 local_irq_restore(flags);
138}
139#define switch_mm_irqs_off switch_mm_irqs_off
140
141
1da177e4
LT
142#define deactivate_mm(tsk,mm) do { } while (0)
143
144/*
145 * After we have set current->mm to a new value, this activates
146 * the context for the new mm so we see the new mappings.
147 */
148static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next)
149{
1da177e4 150 switch_mm(prev, next, current);
1da177e4
LT
151}
152
5e696617
BH
153/* We don't currently use enter_lazy_tlb() for anything */
154static inline void enter_lazy_tlb(struct mm_struct *mm,
155 struct task_struct *tsk)
156{
25d21ad6
BH
157 /* 64-bit Book3E keeps track of current PGD in the PACA */
158#ifdef CONFIG_PPC_BOOK3E_64
159 get_paca()->pgd = NULL;
160#endif
5e696617
BH
161}
162
c10e83f5
TG
163static inline int arch_dup_mmap(struct mm_struct *oldmm,
164 struct mm_struct *mm)
83d3f0e9 165{
c10e83f5 166 return 0;
83d3f0e9
LD
167}
168
30b49ec7 169#ifndef CONFIG_PPC_BOOK3S_64
83d3f0e9
LD
170static inline void arch_exit_mmap(struct mm_struct *mm)
171{
172}
30b49ec7
NP
173#else
174extern void arch_exit_mmap(struct mm_struct *mm);
175#endif
83d3f0e9
LD
176
177static inline void arch_unmap(struct mm_struct *mm,
178 struct vm_area_struct *vma,
179 unsigned long start, unsigned long end)
180{
181 if (start <= mm->context.vdso_base && mm->context.vdso_base < end)
182 mm->context.vdso_base = 0;
183}
184
185static inline void arch_bprm_mm_init(struct mm_struct *mm,
186 struct vm_area_struct *vma)
187{
188}
189
1b2ee126 190static inline bool arch_vma_access_permitted(struct vm_area_struct *vma,
d61172b4 191 bool write, bool execute, bool foreign)
33a709b2
DH
192{
193 /* by default, allow everything */
194 return true;
195}
88ced031 196#endif /* __KERNEL__ */
047ea784 197#endif /* __ASM_POWERPC_MMU_CONTEXT_H */