1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23#include <linux/sched.h>
24#include <linux/mm.h>
25#include <linux/export.h>
26#include <asm/reg.h>
27#include <asm/copro.h>
28#include <asm/spu.h>
29#include <misc/cxl-base.h>
30
31
32
33
34
35
36int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,
37 unsigned long dsisr, vm_fault_t *flt)
38{
39 struct vm_area_struct *vma;
40 unsigned long is_write;
41 int ret;
42
43 if (mm == NULL)
44 return -EFAULT;
45
46 if (mm->pgd == NULL)
47 return -EFAULT;
48
49 down_read(&mm->mmap_sem);
50 ret = -EFAULT;
51 vma = find_vma(mm, ea);
52 if (!vma)
53 goto out_unlock;
54
55 if (ea < vma->vm_start) {
56 if (!(vma->vm_flags & VM_GROWSDOWN))
57 goto out_unlock;
58 if (expand_stack(vma, ea))
59 goto out_unlock;
60 }
61
62 is_write = dsisr & DSISR_ISSTORE;
63 if (is_write) {
64 if (!(vma->vm_flags & VM_WRITE))
65 goto out_unlock;
66 } else {
67 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
68 goto out_unlock;
69
70
71
72
73
74
75 if (!radix_enabled())
76 WARN_ON_ONCE(dsisr & DSISR_PROTFAULT);
77 }
78
79 ret = 0;
80 *flt = handle_mm_fault(vma, ea, is_write ? FAULT_FLAG_WRITE : 0);
81 if (unlikely(*flt & VM_FAULT_ERROR)) {
82 if (*flt & VM_FAULT_OOM) {
83 ret = -ENOMEM;
84 goto out_unlock;
85 } else if (*flt & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) {
86 ret = -EFAULT;
87 goto out_unlock;
88 }
89 BUG();
90 }
91
92 if (*flt & VM_FAULT_MAJOR)
93 current->maj_flt++;
94 else
95 current->min_flt++;
96
97out_unlock:
98 up_read(&mm->mmap_sem);
99 return ret;
100}
101EXPORT_SYMBOL_GPL(copro_handle_mm_fault);
102
103int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)
104{
105 u64 vsid, vsidkey;
106 int psize, ssize;
107
108 switch (REGION_ID(ea)) {
109 case USER_REGION_ID:
110 pr_devel("%s: 0x%llx -- USER_REGION_ID\n", __func__, ea);
111 if (mm == NULL)
112 return 1;
113 psize = get_slice_psize(mm, ea);
114 ssize = user_segment_size(ea);
115 vsid = get_user_vsid(&mm->context, ea, ssize);
116 vsidkey = SLB_VSID_USER;
117 break;
118 case VMALLOC_REGION_ID:
119 pr_devel("%s: 0x%llx -- VMALLOC_REGION_ID\n", __func__, ea);
120 if (ea < VMALLOC_END)
121 psize = mmu_vmalloc_psize;
122 else
123 psize = mmu_io_psize;
124 ssize = mmu_kernel_ssize;
125 vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
126 vsidkey = SLB_VSID_KERNEL;
127 break;
128 case KERNEL_REGION_ID:
129 pr_devel("%s: 0x%llx -- KERNEL_REGION_ID\n", __func__, ea);
130 psize = mmu_linear_psize;
131 ssize = mmu_kernel_ssize;
132 vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
133 vsidkey = SLB_VSID_KERNEL;
134 break;
135 default:
136 pr_debug("%s: invalid region access at %016llx\n", __func__, ea);
137 return 1;
138 }
139
140 if (!vsid)
141 return 1;
142
143 vsid = (vsid << slb_vsid_shift(ssize)) | vsidkey;
144
145 vsid |= mmu_psize_defs[psize].sllp |
146 ((ssize == MMU_SEGSIZE_1T) ? SLB_VSID_B_1T : 0);
147
148 slb->esid = (ea & (ssize == MMU_SEGSIZE_1T ? ESID_MASK_1T : ESID_MASK)) | SLB_ESID_V;
149 slb->vsid = vsid;
150
151 return 0;
152}
153EXPORT_SYMBOL_GPL(copro_calculate_slb);
154
155void copro_flush_all_slbs(struct mm_struct *mm)
156{
157#ifdef CONFIG_SPU_BASE
158 spu_flush_all_slbs(mm);
159#endif
160 cxl_slbia(mm);
161}
162EXPORT_SYMBOL_GPL(copro_flush_all_slbs);
163