1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_S390X_COMPAT_H 3 #define _ASM_S390X_COMPAT_H 4 /* 5 * Architecture specific compatibility types 6 */ 7 #include <linux/types.h> 8 #include <linux/sched.h> 9 #include <linux/sched/task_stack.h> 10 #include <linux/thread_info.h> 11 12 #define __TYPE_IS_PTR(t) (!__builtin_types_compatible_p( \ 13 typeof(0?(__force t)0:0ULL), u64)) 14 15 #define __SC_DELOUSE(t,v) ({ \ 16 BUILD_BUG_ON(sizeof(t) > 4 && !__TYPE_IS_PTR(t)); \ 17 (__force t)(__TYPE_IS_PTR(t) ? ((v) & 0x7fffffff) : (v)); \ 18 }) 19 20 #define PSW32_MASK_PER 0x40000000UL 21 #define PSW32_MASK_DAT 0x04000000UL 22 #define PSW32_MASK_IO 0x02000000UL 23 #define PSW32_MASK_EXT 0x01000000UL 24 #define PSW32_MASK_KEY 0x00F00000UL 25 #define PSW32_MASK_BASE 0x00080000UL /* Always one */ 26 #define PSW32_MASK_MCHECK 0x00040000UL 27 #define PSW32_MASK_WAIT 0x00020000UL 28 #define PSW32_MASK_PSTATE 0x00010000UL 29 #define PSW32_MASK_ASC 0x0000C000UL 30 #define PSW32_MASK_CC 0x00003000UL 31 #define PSW32_MASK_PM 0x00000f00UL 32 #define PSW32_MASK_RI 0x00000080UL 33 34 #define PSW32_MASK_USER 0x0000FF00UL 35 36 #define PSW32_ADDR_AMODE 0x80000000UL 37 #define PSW32_ADDR_INSN 0x7FFFFFFFUL 38 39 #define PSW32_DEFAULT_KEY (((u32) PAGE_DEFAULT_ACC) << 20) 40 41 #define PSW32_ASC_PRIMARY 0x00000000UL 42 #define PSW32_ASC_ACCREG 0x00004000UL 43 #define PSW32_ASC_SECONDARY 0x00008000UL 44 #define PSW32_ASC_HOME 0x0000C000UL 45 46 #define PSW32_USER_BITS (PSW32_MASK_DAT | PSW32_MASK_IO | PSW32_MASK_EXT | \ 47 PSW32_DEFAULT_KEY | PSW32_MASK_BASE | \ 48 PSW32_MASK_MCHECK | PSW32_MASK_PSTATE | \ 49 PSW32_ASC_PRIMARY) 50 51 #define COMPAT_USER_HZ 100 52 #define COMPAT_UTS_MACHINE "s390\0\0\0\0" 53 54 typedef u32 compat_size_t; 55 typedef s32 compat_ssize_t; 56 typedef s32 compat_time_t; 57 typedef s32 compat_clock_t; 58 typedef s32 compat_pid_t; 59 typedef u16 __compat_uid_t; 60 typedef u16 __compat_gid_t; 61 typedef u32 __compat_uid32_t; 62 typedef u32 __compat_gid32_t; 63 typedef u16 compat_mode_t; 64 typedef u32 compat_ino_t; 65 typedef u16 compat_dev_t; 66 typedef s32 compat_off_t; 67 typedef s64 compat_loff_t; 68 typedef u16 compat_nlink_t; 69 typedef u16 compat_ipc_pid_t; 70 typedef s32 compat_daddr_t; 71 typedef u32 compat_caddr_t; 72 typedef __kernel_fsid_t compat_fsid_t; 73 typedef s32 compat_key_t; 74 typedef s32 compat_timer_t; 75 76 typedef s32 compat_int_t; 77 typedef s32 compat_long_t; 78 typedef s64 compat_s64; 79 typedef u32 compat_uint_t; 80 typedef u32 compat_ulong_t; 81 typedef u64 compat_u64; 82 typedef u32 compat_uptr_t; 83 84 typedef struct { 85 u32 mask; 86 u32 addr; 87 } __aligned(8) psw_compat_t; 88 89 typedef struct { 90 psw_compat_t psw; 91 u32 gprs[NUM_GPRS]; 92 u32 acrs[NUM_ACRS]; 93 u32 orig_gpr2; 94 } s390_compat_regs; 95 96 typedef struct { 97 u32 gprs_high[NUM_GPRS]; 98 } s390_compat_regs_high; 99 100 struct compat_timespec { 101 compat_time_t tv_sec; 102 s32 tv_nsec; 103 }; 104 105 struct compat_timeval { 106 compat_time_t tv_sec; 107 s32 tv_usec; 108 }; 109 110 struct compat_stat { 111 compat_dev_t st_dev; 112 u16 __pad1; 113 compat_ino_t st_ino; 114 compat_mode_t st_mode; 115 compat_nlink_t st_nlink; 116 __compat_uid_t st_uid; 117 __compat_gid_t st_gid; 118 compat_dev_t st_rdev; 119 u16 __pad2; 120 u32 st_size; 121 u32 st_blksize; 122 u32 st_blocks; 123 u32 st_atime; 124 u32 st_atime_nsec; 125 u32 st_mtime; 126 u32 st_mtime_nsec; 127 u32 st_ctime; 128 u32 st_ctime_nsec; 129 u32 __unused4; 130 u32 __unused5; 131 }; 132 133 struct compat_flock { 134 short l_type; 135 short l_whence; 136 compat_off_t l_start; 137 compat_off_t l_len; 138 compat_pid_t l_pid; 139 }; 140 141 #define F_GETLK64 12 142 #define F_SETLK64 13 143 #define F_SETLKW64 14 144 145 struct compat_flock64 { 146 short l_type; 147 short l_whence; 148 compat_loff_t l_start; 149 compat_loff_t l_len; 150 compat_pid_t l_pid; 151 }; 152 153 struct compat_statfs { 154 u32 f_type; 155 u32 f_bsize; 156 u32 f_blocks; 157 u32 f_bfree; 158 u32 f_bavail; 159 u32 f_files; 160 u32 f_ffree; 161 compat_fsid_t f_fsid; 162 u32 f_namelen; 163 u32 f_frsize; 164 u32 f_flags; 165 u32 f_spare[4]; 166 }; 167 168 struct compat_statfs64 { 169 u32 f_type; 170 u32 f_bsize; 171 u64 f_blocks; 172 u64 f_bfree; 173 u64 f_bavail; 174 u64 f_files; 175 u64 f_ffree; 176 compat_fsid_t f_fsid; 177 u32 f_namelen; 178 u32 f_frsize; 179 u32 f_flags; 180 u32 f_spare[4]; 181 }; 182 183 #define COMPAT_RLIM_INFINITY 0xffffffff 184 185 typedef u32 compat_old_sigset_t; /* at least 32 bits */ 186 187 #define _COMPAT_NSIG 64 188 #define _COMPAT_NSIG_BPW 32 189 190 typedef u32 compat_sigset_word; 191 192 #define COMPAT_OFF_T_MAX 0x7fffffff 193 194 /* 195 * A pointer passed in from user mode. This should not 196 * be used for syscall parameters, just declare them 197 * as pointers because the syscall entry code will have 198 * appropriately converted them already. 199 */ 200 201 static inline void __user *compat_ptr(compat_uptr_t uptr) 202 { 203 return (void __user *)(unsigned long)(uptr & 0x7fffffffUL); 204 } 205 206 static inline compat_uptr_t ptr_to_compat(void __user *uptr) 207 { 208 return (u32)(unsigned long)uptr; 209 } 210 211 #ifdef CONFIG_COMPAT 212 213 static inline int is_compat_task(void) 214 { 215 return test_thread_flag(TIF_31BIT); 216 } 217 218 static inline void __user *arch_compat_alloc_user_space(long len) 219 { 220 unsigned long stack; 221 222 stack = KSTK_ESP(current); 223 if (is_compat_task()) 224 stack &= 0x7fffffffUL; 225 return (void __user *) (stack - len); 226 } 227 228 #endif 229 230 struct compat_ipc64_perm { 231 compat_key_t key; 232 __compat_uid32_t uid; 233 __compat_gid32_t gid; 234 __compat_uid32_t cuid; 235 __compat_gid32_t cgid; 236 compat_mode_t mode; 237 unsigned short __pad1; 238 unsigned short seq; 239 unsigned short __pad2; 240 unsigned int __unused1; 241 unsigned int __unused2; 242 }; 243 244 struct compat_semid64_ds { 245 struct compat_ipc64_perm sem_perm; 246 compat_time_t sem_otime; 247 compat_ulong_t __pad1; 248 compat_time_t sem_ctime; 249 compat_ulong_t __pad2; 250 compat_ulong_t sem_nsems; 251 compat_ulong_t __unused1; 252 compat_ulong_t __unused2; 253 }; 254 255 struct compat_msqid64_ds { 256 struct compat_ipc64_perm msg_perm; 257 compat_time_t msg_stime; 258 compat_ulong_t __pad1; 259 compat_time_t msg_rtime; 260 compat_ulong_t __pad2; 261 compat_time_t msg_ctime; 262 compat_ulong_t __pad3; 263 compat_ulong_t msg_cbytes; 264 compat_ulong_t msg_qnum; 265 compat_ulong_t msg_qbytes; 266 compat_pid_t msg_lspid; 267 compat_pid_t msg_lrpid; 268 compat_ulong_t __unused1; 269 compat_ulong_t __unused2; 270 }; 271 272 struct compat_shmid64_ds { 273 struct compat_ipc64_perm shm_perm; 274 compat_size_t shm_segsz; 275 compat_time_t shm_atime; 276 compat_ulong_t __pad1; 277 compat_time_t shm_dtime; 278 compat_ulong_t __pad2; 279 compat_time_t shm_ctime; 280 compat_ulong_t __pad3; 281 compat_pid_t shm_cpid; 282 compat_pid_t shm_lpid; 283 compat_ulong_t shm_nattch; 284 compat_ulong_t __unused1; 285 compat_ulong_t __unused2; 286 }; 287 #endif /* _ASM_S390X_COMPAT_H */ 288