1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * System call callback functions for SPUs
4 */
5
6#undef DEBUG
7
8#include <linux/kallsyms.h>
9#include <linux/export.h>
10#include <linux/syscalls.h>
11
12#include <asm/spu.h>
13#include <asm/syscalls.h>
14#include <asm/unistd.h>
15
16/*
17 * This table defines the system calls that an SPU can call.
18 * It is currently a subset of the 64 bit powerpc system calls,
19 * with the exact semantics.
20 *
21 * The reasons for disabling some of the system calls are:
22 * 1. They interact with the way SPU syscalls are handled
23 *    and we can't let them execute ever:
24 *	restart_syscall, exit, for, execve, ptrace, ...
25 * 2. They are deprecated and replaced by other means:
26 *	uselib, pciconfig_*, sysfs, ...
27 * 3. They are somewhat interacting with the system in a way
28 *    we don't want an SPU to:
29 *	reboot, init_module, mount, kexec_load
30 * 4. They are optional and we can't rely on them being
31 *    linked into the kernel. Unfortunately, the cond_syscall
32 *    helper does not work here as it does not add the necessary
33 *    opd symbols:
34 *	mbind, mq_open, ipc, ...
35 */
36
37static const syscall_fn spu_syscall_table[] = {
38#define __SYSCALL_WITH_COMPAT(nr, entry, compat) __SYSCALL(nr, entry)
39#define __SYSCALL(nr, entry) [nr] = (void *) entry,
40#include <asm/syscall_table_spu.h>
41};
42
43long spu_sys_callback(struct spu_syscall_block *s)
44{
45	syscall_fn syscall;
46
47	if (s->nr_ret >= ARRAY_SIZE(spu_syscall_table)) {
48		pr_debug("%s: invalid syscall #%lld", __func__, s->nr_ret);
49		return -ENOSYS;
50	}
51
52	syscall = spu_syscall_table[s->nr_ret];
53
54	pr_debug("SPU-syscall "
55		 "%pSR:syscall%lld(%llx, %llx, %llx, %llx, %llx, %llx)\n",
56		 syscall,
57		 s->nr_ret,
58		 s->parm[0], s->parm[1], s->parm[2],
59		 s->parm[3], s->parm[4], s->parm[5]);
60
61	return syscall(s->parm[0], s->parm[1], s->parm[2],
62		       s->parm[3], s->parm[4], s->parm[5]);
63}
64EXPORT_SYMBOL_GPL(spu_sys_callback);
65