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_clock_t; 57 typedef s32 compat_pid_t; 58 typedef u16 __compat_uid_t; 59 typedef u16 __compat_gid_t; 60 typedef u32 __compat_uid32_t; 61 typedef u32 __compat_gid32_t; 62 typedef u16 compat_mode_t; 63 typedef u32 compat_ino_t; 64 typedef u16 compat_dev_t; 65 typedef s32 compat_off_t; 66 typedef s64 compat_loff_t; 67 typedef u16 compat_nlink_t; 68 typedef u16 compat_ipc_pid_t; 69 typedef s32 compat_daddr_t; 70 typedef u32 compat_caddr_t; 71 typedef __kernel_fsid_t compat_fsid_t; 72 typedef s32 compat_key_t; 73 typedef s32 compat_timer_t; 74 75 typedef s32 compat_int_t; 76 typedef s32 compat_long_t; 77 typedef s64 compat_s64; 78 typedef u32 compat_uint_t; 79 typedef u32 compat_ulong_t; 80 typedef u64 compat_u64; 81 typedef u32 compat_uptr_t; 82 83 typedef struct { 84 u32 mask; 85 u32 addr; 86 } __aligned(8) psw_compat_t; 87 88 typedef struct { 89 psw_compat_t psw; 90 u32 gprs[NUM_GPRS]; 91 u32 acrs[NUM_ACRS]; 92 u32 orig_gpr2; 93 } s390_compat_regs; 94 95 typedef struct { 96 u32 gprs_high[NUM_GPRS]; 97 } s390_compat_regs_high; 98 99 struct compat_stat { 100 compat_dev_t st_dev; 101 u16 __pad1; 102 compat_ino_t st_ino; 103 compat_mode_t st_mode; 104 compat_nlink_t st_nlink; 105 __compat_uid_t st_uid; 106 __compat_gid_t st_gid; 107 compat_dev_t st_rdev; 108 u16 __pad2; 109 u32 st_size; 110 u32 st_blksize; 111 u32 st_blocks; 112 u32 st_atime; 113 u32 st_atime_nsec; 114 u32 st_mtime; 115 u32 st_mtime_nsec; 116 u32 st_ctime; 117 u32 st_ctime_nsec; 118 u32 __unused4; 119 u32 __unused5; 120 }; 121 122 struct compat_flock { 123 short l_type; 124 short l_whence; 125 compat_off_t l_start; 126 compat_off_t l_len; 127 compat_pid_t l_pid; 128 }; 129 130 #define F_GETLK64 12 131 #define F_SETLK64 13 132 #define F_SETLKW64 14 133 134 struct compat_flock64 { 135 short l_type; 136 short l_whence; 137 compat_loff_t l_start; 138 compat_loff_t l_len; 139 compat_pid_t l_pid; 140 }; 141 142 struct compat_statfs { 143 u32 f_type; 144 u32 f_bsize; 145 u32 f_blocks; 146 u32 f_bfree; 147 u32 f_bavail; 148 u32 f_files; 149 u32 f_ffree; 150 compat_fsid_t f_fsid; 151 u32 f_namelen; 152 u32 f_frsize; 153 u32 f_flags; 154 u32 f_spare[4]; 155 }; 156 157 struct compat_statfs64 { 158 u32 f_type; 159 u32 f_bsize; 160 u64 f_blocks; 161 u64 f_bfree; 162 u64 f_bavail; 163 u64 f_files; 164 u64 f_ffree; 165 compat_fsid_t f_fsid; 166 u32 f_namelen; 167 u32 f_frsize; 168 u32 f_flags; 169 u32 f_spare[4]; 170 }; 171 172 #define COMPAT_RLIM_INFINITY 0xffffffff 173 174 typedef u32 compat_old_sigset_t; /* at least 32 bits */ 175 176 #define _COMPAT_NSIG 64 177 #define _COMPAT_NSIG_BPW 32 178 179 typedef u32 compat_sigset_word; 180 181 #define COMPAT_OFF_T_MAX 0x7fffffff 182 183 /* 184 * A pointer passed in from user mode. This should not 185 * be used for syscall parameters, just declare them 186 * as pointers because the syscall entry code will have 187 * appropriately converted them already. 188 */ 189 190 static inline void __user *compat_ptr(compat_uptr_t uptr) 191 { 192 return (void __user *)(unsigned long)(uptr & 0x7fffffffUL); 193 } 194 195 static inline compat_uptr_t ptr_to_compat(void __user *uptr) 196 { 197 return (u32)(unsigned long)uptr; 198 } 199 200 #ifdef CONFIG_COMPAT 201 202 static inline int is_compat_task(void) 203 { 204 return test_thread_flag(TIF_31BIT); 205 } 206 207 static inline void __user *arch_compat_alloc_user_space(long len) 208 { 209 unsigned long stack; 210 211 stack = KSTK_ESP(current); 212 if (is_compat_task()) 213 stack &= 0x7fffffffUL; 214 return (void __user *) (stack - len); 215 } 216 217 #endif 218 219 struct compat_ipc64_perm { 220 compat_key_t key; 221 __compat_uid32_t uid; 222 __compat_gid32_t gid; 223 __compat_uid32_t cuid; 224 __compat_gid32_t cgid; 225 compat_mode_t mode; 226 unsigned short __pad1; 227 unsigned short seq; 228 unsigned short __pad2; 229 unsigned int __unused1; 230 unsigned int __unused2; 231 }; 232 233 struct compat_semid64_ds { 234 struct compat_ipc64_perm sem_perm; 235 compat_ulong_t sem_otime; 236 compat_ulong_t sem_otime_high; 237 compat_ulong_t sem_ctime; 238 compat_ulong_t sem_ctime_high; 239 compat_ulong_t sem_nsems; 240 compat_ulong_t __unused1; 241 compat_ulong_t __unused2; 242 }; 243 244 struct compat_msqid64_ds { 245 struct compat_ipc64_perm msg_perm; 246 compat_ulong_t msg_stime; 247 compat_ulong_t msg_stime_high; 248 compat_ulong_t msg_rtime; 249 compat_ulong_t msg_rtime_high; 250 compat_ulong_t msg_ctime; 251 compat_ulong_t msg_ctime_high; 252 compat_ulong_t msg_cbytes; 253 compat_ulong_t msg_qnum; 254 compat_ulong_t msg_qbytes; 255 compat_pid_t msg_lspid; 256 compat_pid_t msg_lrpid; 257 compat_ulong_t __unused1; 258 compat_ulong_t __unused2; 259 }; 260 261 struct compat_shmid64_ds { 262 struct compat_ipc64_perm shm_perm; 263 compat_size_t shm_segsz; 264 compat_ulong_t shm_atime; 265 compat_ulong_t shm_atime_high; 266 compat_ulong_t shm_dtime; 267 compat_ulong_t shm_dtime_high; 268 compat_ulong_t shm_ctime; 269 compat_ulong_t shm_ctime_high; 270 compat_pid_t shm_cpid; 271 compat_pid_t shm_lpid; 272 compat_ulong_t shm_nattch; 273 compat_ulong_t __unused1; 274 compat_ulong_t __unused2; 275 }; 276 #endif /* _ASM_S390X_COMPAT_H */ 277