Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * ARC700 mmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * (started from arm version - for VIPT alias handling)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7)  * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/sched/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <asm/cacheflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define COLOUR_ALIGN(addr, pgoff)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 	((((addr) + SHMLBA - 1) & ~(SHMLBA - 1)) +	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 	 (((pgoff) << PAGE_SHIFT) & (SHMLBA - 1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)  * Ensure that shared mappings are correctly aligned to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)  * avoid aliasing issues with VIPT caches.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  * We need to ensure that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  * a specific page of an object is always mapped at a multiple of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  * SHMLBA bytes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) arch_get_unmapped_area(struct file *filp, unsigned long addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 		unsigned long len, unsigned long pgoff, unsigned long flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 	struct mm_struct *mm = current->mm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	struct vm_area_struct *vma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	int do_align = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 	int aliasing = cache_is_vipt_aliasing();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 	struct vm_unmapped_area_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	 * We only need to do colour alignment if D cache aliases.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	if (aliasing)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 		do_align = filp || (flags & MAP_SHARED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 	 * We enforce the MAP_FIXED case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	if (flags & MAP_FIXED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 		if (aliasing && flags & MAP_SHARED &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 		    (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 		return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 	if (len > TASK_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	if (addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 		if (do_align)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 			addr = COLOUR_ALIGN(addr, pgoff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 			addr = PAGE_ALIGN(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 		vma = find_vma(mm, addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 		if (TASK_SIZE - len >= addr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 		    (!vma || addr + len <= vm_start_gap(vma)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 			return addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	info.flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	info.length = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	info.low_limit = mm->mmap_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	info.high_limit = TASK_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	info.align_offset = pgoff << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	return vm_unmapped_area(&info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }