xref: /openbmc/linux/arch/xtensa/kernel/syscall.c (revision 49c40fb4)
1fc4fb2adSChris Zankel /*
2fc4fb2adSChris Zankel  * arch/xtensa/kernel/syscall.c
3fc4fb2adSChris Zankel  *
4fc4fb2adSChris Zankel  * This file is subject to the terms and conditions of the GNU General Public
5fc4fb2adSChris Zankel  * License.  See the file "COPYING" in the main directory of this archive
6fc4fb2adSChris Zankel  * for more details.
7fc4fb2adSChris Zankel  *
8fc4fb2adSChris Zankel  * Copyright (C) 2001 - 2005 Tensilica Inc.
9fc4fb2adSChris Zankel  * Copyright (C) 2000 Silicon Graphics, Inc.
10fc4fb2adSChris Zankel  * Copyright (C) 1995 - 2000 by Ralf Baechle
11fc4fb2adSChris Zankel  *
12fc4fb2adSChris Zankel  * Joe Taylor <joe@tensilica.com, joetylr@yahoo.com>
13fc4fb2adSChris Zankel  * Marc Gauthier <marc@tensilica.com, marc@alumni.uwaterloo.ca>
14fc4fb2adSChris Zankel  * Chris Zankel <chris@zankel.net>
15fc4fb2adSChris Zankel  * Kevin Chea
16fc4fb2adSChris Zankel  *
17fc4fb2adSChris Zankel  */
187c0f6ba6SLinus Torvalds #include <linux/uaccess.h>
191c0350bdSChris Zankel #include <asm/syscall.h>
20fc4fb2adSChris Zankel #include <linux/linkage.h>
21fc4fb2adSChris Zankel #include <linux/stringify.h>
22fc4fb2adSChris Zankel #include <linux/errno.h>
23fc4fb2adSChris Zankel #include <linux/syscalls.h>
24fc4fb2adSChris Zankel #include <linux/file.h>
25fc4fb2adSChris Zankel #include <linux/fs.h>
26fc4fb2adSChris Zankel #include <linux/mman.h>
2701042607SIngo Molnar #include <linux/sched/mm.h>
28fc4fb2adSChris Zankel #include <linux/shm.h>
29fc4fb2adSChris Zankel 
308d949ae2SMasahiro Yamada syscall_t sys_call_table[] /* FIXME __cacheline_aligned */= {
31daf26180SMasahiro Yamada #define __SYSCALL(nr, entry)	(syscall_t)entry,
325eacadb5SFiroz Khan #include <asm/syscall_table.h>
33fc4fb2adSChris Zankel };
34fc4fb2adSChris Zankel 
35de73b6b1SMax Filippov #define COLOUR_ALIGN(addr, pgoff) \
36de73b6b1SMax Filippov 	((((addr) + SHMLBA - 1) & ~(SHMLBA - 1)) + \
37de73b6b1SMax Filippov 	 (((pgoff) << PAGE_SHIFT) & (SHMLBA - 1)))
38de73b6b1SMax Filippov 
xtensa_shmat(int shmid,char __user * shmaddr,int shmflg)39fc4fb2adSChris Zankel asmlinkage long xtensa_shmat(int shmid, char __user *shmaddr, int shmflg)
40fc4fb2adSChris Zankel {
41fc4fb2adSChris Zankel 	unsigned long ret;
42fc4fb2adSChris Zankel 	long err;
43fc4fb2adSChris Zankel 
44079a96aeSWill Deacon 	err = do_shmat(shmid, shmaddr, shmflg, &ret, SHMLBA);
45fc4fb2adSChris Zankel 	if (err)
46fc4fb2adSChris Zankel 		return err;
47fc4fb2adSChris Zankel 	return (long)ret;
48fc4fb2adSChris Zankel }
49fc4fb2adSChris Zankel 
xtensa_fadvise64_64(int fd,int advice,unsigned long long offset,unsigned long long len)502f72d4f6SChris Zankel asmlinkage long xtensa_fadvise64_64(int fd, int advice,
512f72d4f6SChris Zankel 		unsigned long long offset, unsigned long long len)
52bc671aa9SChris Zankel {
539d5b7c95SDominik Brodowski 	return ksys_fadvise64_64(fd, offset, len, advice);
54bc671aa9SChris Zankel }
55de73b6b1SMax Filippov 
56d10fa7cfSMax Filippov #ifdef CONFIG_MMU
arch_get_unmapped_area(struct file * filp,unsigned long addr,unsigned long len,unsigned long pgoff,unsigned long flags)57de73b6b1SMax Filippov unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
58de73b6b1SMax Filippov 		unsigned long len, unsigned long pgoff, unsigned long flags)
59de73b6b1SMax Filippov {
60de73b6b1SMax Filippov 	struct vm_area_struct *vmm;
61*49c40fb4SMatthew Wilcox (Oracle) 	struct vma_iterator vmi;
62de73b6b1SMax Filippov 
63de73b6b1SMax Filippov 	if (flags & MAP_FIXED) {
64de73b6b1SMax Filippov 		/* We do not accept a shared mapping if it would violate
65de73b6b1SMax Filippov 		 * cache aliasing constraints.
66de73b6b1SMax Filippov 		 */
67de73b6b1SMax Filippov 		if ((flags & MAP_SHARED) &&
68de73b6b1SMax Filippov 				((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
69de73b6b1SMax Filippov 			return -EINVAL;
70de73b6b1SMax Filippov 		return addr;
71de73b6b1SMax Filippov 	}
72de73b6b1SMax Filippov 
73de73b6b1SMax Filippov 	if (len > TASK_SIZE)
74de73b6b1SMax Filippov 		return -ENOMEM;
75de73b6b1SMax Filippov 	if (!addr)
76de73b6b1SMax Filippov 		addr = TASK_UNMAPPED_BASE;
77de73b6b1SMax Filippov 
78de73b6b1SMax Filippov 	if (flags & MAP_SHARED)
79de73b6b1SMax Filippov 		addr = COLOUR_ALIGN(addr, pgoff);
80de73b6b1SMax Filippov 	else
81de73b6b1SMax Filippov 		addr = PAGE_ALIGN(addr);
82de73b6b1SMax Filippov 
83*49c40fb4SMatthew Wilcox (Oracle) 	vma_iter_init(&vmi, current->mm, addr);
84*49c40fb4SMatthew Wilcox (Oracle) 	for_each_vma(vmi, vmm) {
85*49c40fb4SMatthew Wilcox (Oracle) 		/* At this point:  (addr < vmm->vm_end). */
86*49c40fb4SMatthew Wilcox (Oracle) 		if (addr + len <= vm_start_gap(vmm))
87*49c40fb4SMatthew Wilcox (Oracle) 			break;
88*49c40fb4SMatthew Wilcox (Oracle) 
89de73b6b1SMax Filippov 		addr = vmm->vm_end;
90de73b6b1SMax Filippov 		if (flags & MAP_SHARED)
91de73b6b1SMax Filippov 			addr = COLOUR_ALIGN(addr, pgoff);
92de73b6b1SMax Filippov 	}
93*49c40fb4SMatthew Wilcox (Oracle) 
94*49c40fb4SMatthew Wilcox (Oracle) 	if (TASK_SIZE - len < addr)
95*49c40fb4SMatthew Wilcox (Oracle) 		return -ENOMEM;
96*49c40fb4SMatthew Wilcox (Oracle) 
97*49c40fb4SMatthew Wilcox (Oracle) 	return addr;
98de73b6b1SMax Filippov }
99d10fa7cfSMax Filippov #endif
100