0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <linux/sched.h>
0011 #include <linux/mm.h>
0012 #include <linux/export.h>
0013 #include <asm/reg.h>
0014 #include <asm/copro.h>
0015 #include <asm/spu.h>
0016 #include <misc/cxl-base.h>
0017
0018
0019
0020
0021
0022
0023 int copro_handle_mm_fault(struct mm_struct *mm, unsigned long ea,
0024 unsigned long dsisr, vm_fault_t *flt)
0025 {
0026 struct vm_area_struct *vma;
0027 unsigned long is_write;
0028 int ret;
0029
0030 if (mm == NULL)
0031 return -EFAULT;
0032
0033 if (mm->pgd == NULL)
0034 return -EFAULT;
0035
0036 mmap_read_lock(mm);
0037 ret = -EFAULT;
0038 vma = find_vma(mm, ea);
0039 if (!vma)
0040 goto out_unlock;
0041
0042 if (ea < vma->vm_start) {
0043 if (!(vma->vm_flags & VM_GROWSDOWN))
0044 goto out_unlock;
0045 if (expand_stack(vma, ea))
0046 goto out_unlock;
0047 }
0048
0049 is_write = dsisr & DSISR_ISSTORE;
0050 if (is_write) {
0051 if (!(vma->vm_flags & VM_WRITE))
0052 goto out_unlock;
0053 } else {
0054 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
0055 goto out_unlock;
0056
0057
0058
0059
0060
0061
0062 if (!radix_enabled())
0063 WARN_ON_ONCE(dsisr & DSISR_PROTFAULT);
0064 }
0065
0066 ret = 0;
0067 *flt = handle_mm_fault(vma, ea, is_write ? FAULT_FLAG_WRITE : 0, NULL);
0068
0069
0070 if (*flt & VM_FAULT_COMPLETED)
0071 return 0;
0072
0073 if (unlikely(*flt & VM_FAULT_ERROR)) {
0074 if (*flt & VM_FAULT_OOM) {
0075 ret = -ENOMEM;
0076 goto out_unlock;
0077 } else if (*flt & (VM_FAULT_SIGBUS | VM_FAULT_SIGSEGV)) {
0078 ret = -EFAULT;
0079 goto out_unlock;
0080 }
0081 BUG();
0082 }
0083
0084 out_unlock:
0085 mmap_read_unlock(mm);
0086 return ret;
0087 }
0088 EXPORT_SYMBOL_GPL(copro_handle_mm_fault);
0089
0090 #ifdef CONFIG_PPC_64S_HASH_MMU
0091 int copro_calculate_slb(struct mm_struct *mm, u64 ea, struct copro_slb *slb)
0092 {
0093 u64 vsid, vsidkey;
0094 int psize, ssize;
0095
0096 switch (get_region_id(ea)) {
0097 case USER_REGION_ID:
0098 pr_devel("%s: 0x%llx -- USER_REGION_ID\n", __func__, ea);
0099 if (mm == NULL)
0100 return 1;
0101 psize = get_slice_psize(mm, ea);
0102 ssize = user_segment_size(ea);
0103 vsid = get_user_vsid(&mm->context, ea, ssize);
0104 vsidkey = SLB_VSID_USER;
0105 break;
0106 case VMALLOC_REGION_ID:
0107 pr_devel("%s: 0x%llx -- VMALLOC_REGION_ID\n", __func__, ea);
0108 psize = mmu_vmalloc_psize;
0109 ssize = mmu_kernel_ssize;
0110 vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
0111 vsidkey = SLB_VSID_KERNEL;
0112 break;
0113 case IO_REGION_ID:
0114 pr_devel("%s: 0x%llx -- IO_REGION_ID\n", __func__, ea);
0115 psize = mmu_io_psize;
0116 ssize = mmu_kernel_ssize;
0117 vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
0118 vsidkey = SLB_VSID_KERNEL;
0119 break;
0120 case LINEAR_MAP_REGION_ID:
0121 pr_devel("%s: 0x%llx -- LINEAR_MAP_REGION_ID\n", __func__, ea);
0122 psize = mmu_linear_psize;
0123 ssize = mmu_kernel_ssize;
0124 vsid = get_kernel_vsid(ea, mmu_kernel_ssize);
0125 vsidkey = SLB_VSID_KERNEL;
0126 break;
0127 default:
0128 pr_debug("%s: invalid region access at %016llx\n", __func__, ea);
0129 return 1;
0130 }
0131
0132 if (!vsid)
0133 return 1;
0134
0135 vsid = (vsid << slb_vsid_shift(ssize)) | vsidkey;
0136
0137 vsid |= mmu_psize_defs[psize].sllp |
0138 ((ssize == MMU_SEGSIZE_1T) ? SLB_VSID_B_1T : 0);
0139
0140 slb->esid = (ea & (ssize == MMU_SEGSIZE_1T ? ESID_MASK_1T : ESID_MASK)) | SLB_ESID_V;
0141 slb->vsid = vsid;
0142
0143 return 0;
0144 }
0145 EXPORT_SYMBOL_GPL(copro_calculate_slb);
0146
0147 void copro_flush_all_slbs(struct mm_struct *mm)
0148 {
0149 #ifdef CONFIG_SPU_BASE
0150 spu_flush_all_slbs(mm);
0151 #endif
0152 cxl_slbia(mm);
0153 }
0154 EXPORT_SYMBOL_GPL(copro_flush_all_slbs);
0155 #endif