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