17e92e01bSRohan McLure /* SPDX-License-Identifier: GPL-2.0 */
27e92e01bSRohan McLure /*
37e92e01bSRohan McLure  * syscall_wrapper.h - powerpc specific wrappers to syscall definitions
47e92e01bSRohan McLure  *
57e92e01bSRohan McLure  * Based on arch/{x86,arm64}/include/asm/syscall_wrapper.h
67e92e01bSRohan McLure  */
77e92e01bSRohan McLure 
87e92e01bSRohan McLure #ifndef __ASM_POWERPC_SYSCALL_WRAPPER_H
97e92e01bSRohan McLure #define __ASM_POWERPC_SYSCALL_WRAPPER_H
107e92e01bSRohan McLure 
117e92e01bSRohan McLure struct pt_regs;
127e92e01bSRohan McLure 
137e92e01bSRohan McLure #define SC_POWERPC_REGS_TO_ARGS(x, ...)				\
147e92e01bSRohan McLure 	__MAP(x,__SC_ARGS					\
157e92e01bSRohan McLure 	      ,,regs->gpr[3],,regs->gpr[4],,regs->gpr[5]	\
167e92e01bSRohan McLure 	      ,,regs->gpr[6],,regs->gpr[7],,regs->gpr[8])
177e92e01bSRohan McLure 
187e92e01bSRohan McLure #define __SYSCALL_DEFINEx(x, name, ...)						\
19*94746890SMichael Ellerman 	long sys##name(const struct pt_regs *regs);			\
20*94746890SMichael Ellerman 	ALLOW_ERROR_INJECTION(sys##name, ERRNO);			\
217e92e01bSRohan McLure 	static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__));		\
227e92e01bSRohan McLure 	static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__));	\
23*94746890SMichael Ellerman 	long sys##name(const struct pt_regs *regs)			\
247e92e01bSRohan McLure 	{									\
257e92e01bSRohan McLure 		return __se_sys##name(SC_POWERPC_REGS_TO_ARGS(x,__VA_ARGS__));	\
267e92e01bSRohan McLure 	}									\
277e92e01bSRohan McLure 	static long __se_sys##name(__MAP(x,__SC_LONG,__VA_ARGS__))		\
287e92e01bSRohan McLure 	{									\
297e92e01bSRohan McLure 		long ret = __do_sys##name(__MAP(x,__SC_CAST,__VA_ARGS__));	\
307e92e01bSRohan McLure 		__MAP(x,__SC_TEST,__VA_ARGS__);					\
317e92e01bSRohan McLure 		__PROTECT(x, ret,__MAP(x,__SC_ARGS,__VA_ARGS__));		\
327e92e01bSRohan McLure 		return ret;							\
337e92e01bSRohan McLure 	}									\
347e92e01bSRohan McLure 	static inline long __do_sys##name(__MAP(x,__SC_DECL,__VA_ARGS__))
357e92e01bSRohan McLure 
367e92e01bSRohan McLure #define SYSCALL_DEFINE0(sname)							\
377e92e01bSRohan McLure 	SYSCALL_METADATA(_##sname, 0);						\
38*94746890SMichael Ellerman 	long sys_##sname(const struct pt_regs *__unused);		\
39*94746890SMichael Ellerman 	ALLOW_ERROR_INJECTION(sys_##sname, ERRNO);			\
40*94746890SMichael Ellerman 	long sys_##sname(const struct pt_regs *__unused)
417e92e01bSRohan McLure 
427e92e01bSRohan McLure #define COND_SYSCALL(name)							\
43*94746890SMichael Ellerman 	long sys_##name(const struct pt_regs *regs);			\
44*94746890SMichael Ellerman 	long __weak sys_##name(const struct pt_regs *regs)		\
457e92e01bSRohan McLure 	{									\
467e92e01bSRohan McLure 		return sys_ni_syscall();					\
477e92e01bSRohan McLure 	}
487e92e01bSRohan McLure 
497e92e01bSRohan McLure #endif // __ASM_POWERPC_SYSCALL_WRAPPER_H
50