Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Paul Mackerras | 047ea78 | 2005-11-19 20:17:32 +1100 | [diff] [blame] | 2 | #ifndef __ASM_POWERPC_MMU_CONTEXT_H |
| 3 | #define __ASM_POWERPC_MMU_CONTEXT_H |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 4 | #ifdef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
Benjamin Herrenschmidt | 5e69661 | 2008-12-18 19:13:24 +0000 | [diff] [blame] | 6 | #include <linux/kernel.h> |
| 7 | #include <linux/mm.h> |
| 8 | #include <linux/sched.h> |
| 9 | #include <linux/spinlock.h> |
Kumar Gala | 80a7cc6 | 2007-07-03 03:22:05 -0500 | [diff] [blame] | 10 | #include <asm/mmu.h> |
| 11 | #include <asm/cputable.h> |
Benjamin Herrenschmidt | 5e69661 | 2008-12-18 19:13:24 +0000 | [diff] [blame] | 12 | #include <asm/cputhreads.h> |
Kumar Gala | 80a7cc6 | 2007-07-03 03:22:05 -0500 | [diff] [blame] | 13 | |
| 14 | /* |
Benjamin Herrenschmidt | 5e69661 | 2008-12-18 19:13:24 +0000 | [diff] [blame] | 15 | * Most if the context management is out of line |
Kumar Gala | 80a7cc6 | 2007-07-03 03:22:05 -0500 | [diff] [blame] | 16 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | extern int init_new_context(struct task_struct *tsk, struct mm_struct *mm); |
| 18 | extern void destroy_context(struct mm_struct *mm); |
Alexey Kardashevskiy | 15b244a | 2015-06-05 16:35:24 +1000 | [diff] [blame] | 19 | #ifdef CONFIG_SPAPR_TCE_IOMMU |
| 20 | struct mm_iommu_table_group_mem_t; |
| 21 | |
Balbir Singh | 2e5bbb5 | 2016-09-06 16:27:31 +1000 | [diff] [blame] | 22 | extern int isolate_lru_page(struct page *page); /* from internal.h */ |
Alexey Kardashevskiy | d7baee6 | 2016-11-30 17:52:00 +1100 | [diff] [blame] | 23 | extern bool mm_iommu_preregistered(struct mm_struct *mm); |
| 24 | extern long mm_iommu_get(struct mm_struct *mm, |
| 25 | unsigned long ua, unsigned long entries, |
Alexey Kardashevskiy | 15b244a | 2015-06-05 16:35:24 +1000 | [diff] [blame] | 26 | struct mm_iommu_table_group_mem_t **pmem); |
Alexey Kardashevskiy | d7baee6 | 2016-11-30 17:52:00 +1100 | [diff] [blame] | 27 | extern long mm_iommu_put(struct mm_struct *mm, |
| 28 | struct mm_iommu_table_group_mem_t *mem); |
Alexey Kardashevskiy | 88f54a3 | 2016-11-30 17:51:59 +1100 | [diff] [blame] | 29 | extern void mm_iommu_init(struct mm_struct *mm); |
| 30 | extern void mm_iommu_cleanup(struct mm_struct *mm); |
Alexey Kardashevskiy | d7baee6 | 2016-11-30 17:52:00 +1100 | [diff] [blame] | 31 | extern struct mm_iommu_table_group_mem_t *mm_iommu_lookup(struct mm_struct *mm, |
| 32 | unsigned long ua, unsigned long size); |
Alexey Kardashevskiy | 6b5c19c | 2017-03-22 15:21:47 +1100 | [diff] [blame] | 33 | extern struct mm_iommu_table_group_mem_t *mm_iommu_lookup_rm( |
| 34 | struct mm_struct *mm, unsigned long ua, unsigned long size); |
Alexey Kardashevskiy | d7baee6 | 2016-11-30 17:52:00 +1100 | [diff] [blame] | 35 | extern struct mm_iommu_table_group_mem_t *mm_iommu_find(struct mm_struct *mm, |
| 36 | unsigned long ua, unsigned long entries); |
Alexey Kardashevskiy | 15b244a | 2015-06-05 16:35:24 +1000 | [diff] [blame] | 37 | extern long mm_iommu_ua_to_hpa(struct mm_iommu_table_group_mem_t *mem, |
| 38 | unsigned long ua, unsigned long *hpa); |
Alexey Kardashevskiy | 6b5c19c | 2017-03-22 15:21:47 +1100 | [diff] [blame] | 39 | extern long mm_iommu_ua_to_hpa_rm(struct mm_iommu_table_group_mem_t *mem, |
| 40 | unsigned long ua, unsigned long *hpa); |
Alexey Kardashevskiy | 15b244a | 2015-06-05 16:35:24 +1000 | [diff] [blame] | 41 | extern long mm_iommu_mapped_inc(struct mm_iommu_table_group_mem_t *mem); |
| 42 | extern void mm_iommu_mapped_dec(struct mm_iommu_table_group_mem_t *mem); |
| 43 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | extern void switch_slb(struct task_struct *tsk, struct mm_struct *mm); |
Benjamin Herrenschmidt | 5e69661 | 2008-12-18 19:13:24 +0000 | [diff] [blame] | 45 | extern void set_context(unsigned long id, pgd_t *pgd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Benjamin Herrenschmidt | 6f0ef0f | 2009-07-23 23:15:26 +0000 | [diff] [blame] | 47 | #ifdef CONFIG_PPC_BOOK3S_64 |
Aneesh Kumar K.V | 7e381c0 | 2016-04-29 23:26:02 +1000 | [diff] [blame] | 48 | extern void radix__switch_mmu_context(struct mm_struct *prev, |
Benjamin Herrenschmidt | a25bd72 | 2017-07-24 14:26:06 +1000 | [diff] [blame] | 49 | struct mm_struct *next); |
Aneesh Kumar K.V | d2adba3 | 2016-04-29 23:26:01 +1000 | [diff] [blame] | 50 | static inline void switch_mmu_context(struct mm_struct *prev, |
| 51 | struct mm_struct *next, |
| 52 | struct task_struct *tsk) |
| 53 | { |
Aneesh Kumar K.V | 7e381c0 | 2016-04-29 23:26:02 +1000 | [diff] [blame] | 54 | if (radix_enabled()) |
| 55 | return radix__switch_mmu_context(prev, next); |
Aneesh Kumar K.V | d2adba3 | 2016-04-29 23:26:01 +1000 | [diff] [blame] | 56 | return switch_slb(tsk, next); |
| 57 | } |
| 58 | |
Michael Ellerman | a336f2f | 2017-03-29 22:00:46 +1100 | [diff] [blame] | 59 | extern int hash__alloc_context_id(void); |
Aneesh Kumar K.V | 82228e3 | 2017-03-22 09:07:00 +0530 | [diff] [blame] | 60 | extern void hash__reserve_context_id(int id); |
Alexander Graf | e85a471 | 2009-11-02 12:02:30 +0000 | [diff] [blame] | 61 | extern void __destroy_context(int context_id); |
Benjamin Herrenschmidt | 6f0ef0f | 2009-07-23 23:15:26 +0000 | [diff] [blame] | 62 | static inline void mmu_context_init(void) { } |
| 63 | #else |
Aneesh Kumar K.V | d2adba3 | 2016-04-29 23:26:01 +1000 | [diff] [blame] | 64 | extern void switch_mmu_context(struct mm_struct *prev, struct mm_struct *next, |
| 65 | struct task_struct *tsk); |
Alexander Graf | c83ec26 | 2010-04-16 00:11:36 +0200 | [diff] [blame] | 66 | extern unsigned long __init_new_context(void); |
| 67 | extern void __destroy_context(unsigned long context_id); |
Benjamin Herrenschmidt | 6f0ef0f | 2009-07-23 23:15:26 +0000 | [diff] [blame] | 68 | extern void mmu_context_init(void); |
| 69 | #endif |
| 70 | |
Benjamin Herrenschmidt | a25bd72 | 2017-07-24 14:26:06 +1000 | [diff] [blame] | 71 | #if defined(CONFIG_KVM_BOOK3S_HV_POSSIBLE) && defined(CONFIG_PPC_RADIX_MMU) |
| 72 | extern void radix_kvm_prefetch_workaround(struct mm_struct *mm); |
| 73 | #else |
| 74 | static inline void radix_kvm_prefetch_workaround(struct mm_struct *mm) { } |
| 75 | #endif |
| 76 | |
Tseng-Hui (Frank) Lin | 851d2e2 | 2011-05-02 20:43:04 +0000 | [diff] [blame] | 77 | extern void switch_cop(struct mm_struct *next); |
| 78 | extern int use_cop(unsigned long acop, struct mm_struct *mm); |
| 79 | extern void drop_cop(unsigned long acop, struct mm_struct *mm); |
| 80 | |
Benjamin Herrenschmidt | 3a2df37 | 2017-07-24 14:28:03 +1000 | [diff] [blame] | 81 | extern void switch_mm_irqs_off(struct mm_struct *prev, struct mm_struct *next, |
| 82 | struct task_struct *tsk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
David Gibson | 9765ad1 | 2017-04-19 16:38:26 +1000 | [diff] [blame] | 84 | static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next, |
| 85 | struct task_struct *tsk) |
| 86 | { |
| 87 | unsigned long flags; |
| 88 | |
| 89 | local_irq_save(flags); |
| 90 | switch_mm_irqs_off(prev, next, tsk); |
| 91 | local_irq_restore(flags); |
| 92 | } |
| 93 | #define switch_mm_irqs_off switch_mm_irqs_off |
| 94 | |
| 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | #define deactivate_mm(tsk,mm) do { } while (0) |
| 97 | |
| 98 | /* |
| 99 | * After we have set current->mm to a new value, this activates |
| 100 | * the context for the new mm so we see the new mappings. |
| 101 | */ |
| 102 | static inline void activate_mm(struct mm_struct *prev, struct mm_struct *next) |
| 103 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | switch_mm(prev, next, current); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Benjamin Herrenschmidt | 5e69661 | 2008-12-18 19:13:24 +0000 | [diff] [blame] | 107 | /* We don't currently use enter_lazy_tlb() for anything */ |
| 108 | static inline void enter_lazy_tlb(struct mm_struct *mm, |
| 109 | struct task_struct *tsk) |
| 110 | { |
Benjamin Herrenschmidt | 25d21ad | 2009-07-23 23:15:47 +0000 | [diff] [blame] | 111 | /* 64-bit Book3E keeps track of current PGD in the PACA */ |
| 112 | #ifdef CONFIG_PPC_BOOK3E_64 |
| 113 | get_paca()->pgd = NULL; |
| 114 | #endif |
Benjamin Herrenschmidt | 5e69661 | 2008-12-18 19:13:24 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Thomas Gleixner | c10e83f | 2017-12-14 12:27:29 +0100 | [diff] [blame^] | 117 | static inline int arch_dup_mmap(struct mm_struct *oldmm, |
| 118 | struct mm_struct *mm) |
Laurent Dufour | 83d3f0e | 2015-06-24 16:56:22 -0700 | [diff] [blame] | 119 | { |
Thomas Gleixner | c10e83f | 2017-12-14 12:27:29 +0100 | [diff] [blame^] | 120 | return 0; |
Laurent Dufour | 83d3f0e | 2015-06-24 16:56:22 -0700 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | static inline void arch_exit_mmap(struct mm_struct *mm) |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | static inline void arch_unmap(struct mm_struct *mm, |
| 128 | struct vm_area_struct *vma, |
| 129 | unsigned long start, unsigned long end) |
| 130 | { |
| 131 | if (start <= mm->context.vdso_base && mm->context.vdso_base < end) |
| 132 | mm->context.vdso_base = 0; |
| 133 | } |
| 134 | |
| 135 | static inline void arch_bprm_mm_init(struct mm_struct *mm, |
| 136 | struct vm_area_struct *vma) |
| 137 | { |
| 138 | } |
| 139 | |
Dave Hansen | 1b2ee12 | 2016-02-12 13:02:21 -0800 | [diff] [blame] | 140 | static inline bool arch_vma_access_permitted(struct vm_area_struct *vma, |
Dave Hansen | d61172b | 2016-02-12 13:02:24 -0800 | [diff] [blame] | 141 | bool write, bool execute, bool foreign) |
Dave Hansen | 33a709b | 2016-02-12 13:02:19 -0800 | [diff] [blame] | 142 | { |
| 143 | /* by default, allow everything */ |
| 144 | return true; |
| 145 | } |
Arnd Bergmann | 88ced03 | 2005-12-16 22:43:46 +0100 | [diff] [blame] | 146 | #endif /* __KERNEL__ */ |
Paul Mackerras | 047ea78 | 2005-11-19 20:17:32 +1100 | [diff] [blame] | 147 | #endif /* __ASM_POWERPC_MMU_CONTEXT_H */ |