1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2f15cbe6fSPaul Mundt #ifndef __ASM_SH_THREAD_INFO_H
3f15cbe6fSPaul Mundt #define __ASM_SH_THREAD_INFO_H
4f15cbe6fSPaul Mundt
5f15cbe6fSPaul Mundt /* SuperH version
6f15cbe6fSPaul Mundt * Copyright (C) 2002 Niibe Yutaka
7f15cbe6fSPaul Mundt *
8f15cbe6fSPaul Mundt * The copyright of original i386 version is:
9f15cbe6fSPaul Mundt *
10f15cbe6fSPaul Mundt * Copyright (C) 2002 David Howells (dhowells@redhat.com)
11f15cbe6fSPaul Mundt * - Incorporating suggestions made by Linus Torvalds and Dave Miller
12f15cbe6fSPaul Mundt */
13f15cbe6fSPaul Mundt #include <asm/page.h>
14f15cbe6fSPaul Mundt
155a1dc78aSPaul Mundt /*
165a1dc78aSPaul Mundt * Page fault error code bits
175a1dc78aSPaul Mundt */
185a1dc78aSPaul Mundt #define FAULT_CODE_WRITE (1 << 0) /* write access */
195a1dc78aSPaul Mundt #define FAULT_CODE_INITIAL (1 << 1) /* initial page write */
205a1dc78aSPaul Mundt #define FAULT_CODE_ITLB (1 << 2) /* ITLB miss */
215a1dc78aSPaul Mundt #define FAULT_CODE_PROT (1 << 3) /* protection fault */
225a1dc78aSPaul Mundt #define FAULT_CODE_USER (1 << 4) /* user-mode access */
235a1dc78aSPaul Mundt
24f15cbe6fSPaul Mundt #ifndef __ASSEMBLY__
25f15cbe6fSPaul Mundt #include <asm/processor.h>
26f15cbe6fSPaul Mundt
27f15cbe6fSPaul Mundt struct thread_info {
28f15cbe6fSPaul Mundt struct task_struct *task; /* main task structure */
29f15cbe6fSPaul Mundt unsigned long flags; /* low level flags */
3056bfc42fSPaul Mundt __u32 status; /* thread synchronous flags */
31f15cbe6fSPaul Mundt __u32 cpu;
32f15cbe6fSPaul Mundt int preempt_count; /* 0 => preemptable, <0 => BUG */
33f15cbe6fSPaul Mundt unsigned long previous_sp; /* sp of previous stack in case
34f15cbe6fSPaul Mundt of nested IRQ stacks */
35*5224f790SGustavo A. R. Silva __u8 supervisor_stack[];
36f15cbe6fSPaul Mundt };
37f15cbe6fSPaul Mundt
38f15cbe6fSPaul Mundt #endif
39f15cbe6fSPaul Mundt
40f15cbe6fSPaul Mundt #if defined(CONFIG_4KSTACKS)
41c15c5f8cSPaul Mundt #define THREAD_SHIFT 12
42f15cbe6fSPaul Mundt #else
43c15c5f8cSPaul Mundt #define THREAD_SHIFT 13
44f15cbe6fSPaul Mundt #endif
45f15cbe6fSPaul Mundt
46c15c5f8cSPaul Mundt #define THREAD_SIZE (1 << THREAD_SHIFT)
47f15cbe6fSPaul Mundt #define STACK_WARN (THREAD_SIZE >> 3)
48f15cbe6fSPaul Mundt
49f15cbe6fSPaul Mundt /*
50f15cbe6fSPaul Mundt * macros/functions for gaining access to the thread information structure
51f15cbe6fSPaul Mundt */
52f15cbe6fSPaul Mundt #ifndef __ASSEMBLY__
53f15cbe6fSPaul Mundt #define INIT_THREAD_INFO(tsk) \
54f15cbe6fSPaul Mundt { \
55f15cbe6fSPaul Mundt .task = &tsk, \
56f15cbe6fSPaul Mundt .flags = 0, \
57d3ea9fa0SStuart Menefy .status = 0, \
58f15cbe6fSPaul Mundt .cpu = 0, \
59c99e6efeSPeter Zijlstra .preempt_count = INIT_PREEMPT_COUNT, \
60f15cbe6fSPaul Mundt }
61f15cbe6fSPaul Mundt
62f15cbe6fSPaul Mundt /* how to get the current stack pointer from C */
63f15cbe6fSPaul Mundt register unsigned long current_stack_pointer asm("r15") __used;
64f15cbe6fSPaul Mundt
65f15cbe6fSPaul Mundt /* how to get the thread information struct from C */
current_thread_info(void)66f15cbe6fSPaul Mundt static inline struct thread_info *current_thread_info(void)
67f15cbe6fSPaul Mundt {
68f15cbe6fSPaul Mundt struct thread_info *ti;
6937744feeSArnd Bergmann #if defined(CONFIG_CPU_HAS_SR_RB)
70f15cbe6fSPaul Mundt __asm__ __volatile__ ("stc r7_bank, %0" : "=r" (ti));
71f15cbe6fSPaul Mundt #else
72f15cbe6fSPaul Mundt unsigned long __dummy;
73f15cbe6fSPaul Mundt
74f15cbe6fSPaul Mundt __asm__ __volatile__ (
75f15cbe6fSPaul Mundt "mov r15, %0\n\t"
76f15cbe6fSPaul Mundt "and %1, %0\n\t"
77f15cbe6fSPaul Mundt : "=&r" (ti), "=r" (__dummy)
78f15cbe6fSPaul Mundt : "1" (~(THREAD_SIZE - 1))
79f15cbe6fSPaul Mundt : "memory");
80f15cbe6fSPaul Mundt #endif
81f15cbe6fSPaul Mundt
82f15cbe6fSPaul Mundt return ti;
83f15cbe6fSPaul Mundt }
84f15cbe6fSPaul Mundt
85c15c5f8cSPaul Mundt #define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
86c15c5f8cSPaul Mundt
870ea820cfSPaul Mundt extern void init_thread_xstate(void);
88c15c5f8cSPaul Mundt
89f15cbe6fSPaul Mundt #endif /* __ASSEMBLY__ */
90f15cbe6fSPaul Mundt
91f15cbe6fSPaul Mundt /*
925a1dc78aSPaul Mundt * Thread information flags
935a1dc78aSPaul Mundt *
945a1dc78aSPaul Mundt * - Limited to 24 bits, upper byte used for fault code encoding.
955a1dc78aSPaul Mundt *
965a1dc78aSPaul Mundt * - _TIF_ALLWORK_MASK and _TIF_WORK_MASK need to fit within 2 bytes, or
975a1dc78aSPaul Mundt * we blow the tst immediate size constraints and need to fix up
985a1dc78aSPaul Mundt * arch/sh/kernel/entry-common.S.
99f15cbe6fSPaul Mundt */
100f15cbe6fSPaul Mundt #define TIF_SYSCALL_TRACE 0 /* syscall trace active */
101f15cbe6fSPaul Mundt #define TIF_SIGPENDING 1 /* signal pending */
102f15cbe6fSPaul Mundt #define TIF_NEED_RESCHED 2 /* rescheduling necessary */
1036d3a2733SJens Axboe #define TIF_NOTIFY_SIGNAL 3 /* signal notifications exist */
104f15cbe6fSPaul Mundt #define TIF_SINGLESTEP 4 /* singlestepping active */
105c4637d47SPaul Mundt #define TIF_SYSCALL_AUDIT 5 /* syscall auditing active */
106c4637d47SPaul Mundt #define TIF_SECCOMP 6 /* secure computing */
107ab99c733SPaul Mundt #define TIF_NOTIFY_RESUME 7 /* callback before returning to user */
108a74f7e04SPaul Mundt #define TIF_SYSCALL_TRACEPOINT 8 /* for ftrace syscall instrumentation */
109f15cbe6fSPaul Mundt #define TIF_POLLING_NRFLAG 17 /* true if poll_idle() is polling TIF_NEED_RESCHED */
1100ddc9324SAndreas Dilger #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
111f15cbe6fSPaul Mundt
112f15cbe6fSPaul Mundt #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
113f15cbe6fSPaul Mundt #define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
114f15cbe6fSPaul Mundt #define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
1156d3a2733SJens Axboe #define _TIF_NOTIFY_SIGNAL (1 << TIF_NOTIFY_SIGNAL)
116f15cbe6fSPaul Mundt #define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP)
117f15cbe6fSPaul Mundt #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT)
118c4637d47SPaul Mundt #define _TIF_SECCOMP (1 << TIF_SECCOMP)
119ab99c733SPaul Mundt #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
120a74f7e04SPaul Mundt #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
121f15cbe6fSPaul Mundt #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
122f15cbe6fSPaul Mundt
123cec3fd3eSPaul Mundt /* work to do in syscall trace */
124cec3fd3eSPaul Mundt #define _TIF_WORK_SYSCALL_MASK (_TIF_SYSCALL_TRACE | _TIF_SINGLESTEP | \
125c652d780SMatt Fleming _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
126a74f7e04SPaul Mundt _TIF_SYSCALL_TRACEPOINT)
127cec3fd3eSPaul Mundt
128cec3fd3eSPaul Mundt /* work to do on any return to u-space */
129cec3fd3eSPaul Mundt #define _TIF_ALLWORK_MASK (_TIF_SYSCALL_TRACE | _TIF_SIGPENDING | \
130cec3fd3eSPaul Mundt _TIF_NEED_RESCHED | _TIF_SYSCALL_AUDIT | \
13156bfc42fSPaul Mundt _TIF_SINGLESTEP | _TIF_NOTIFY_RESUME | \
1326d3a2733SJens Axboe _TIF_SYSCALL_TRACEPOINT | _TIF_NOTIFY_SIGNAL)
133cec3fd3eSPaul Mundt
134cec3fd3eSPaul Mundt /* work to do on interrupt/exception return */
135cec3fd3eSPaul Mundt #define _TIF_WORK_MASK (_TIF_ALLWORK_MASK & ~(_TIF_SYSCALL_TRACE | \
136cec3fd3eSPaul Mundt _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP))
137f15cbe6fSPaul Mundt
13856bfc42fSPaul Mundt /*
13956bfc42fSPaul Mundt * Thread-synchronous status.
14056bfc42fSPaul Mundt *
14156bfc42fSPaul Mundt * This is different from the flags in that nobody else
14256bfc42fSPaul Mundt * ever touches our thread-synchronous status, so we don't
14356bfc42fSPaul Mundt * have to worry about atomic accesses.
14456bfc42fSPaul Mundt */
145d3ea9fa0SStuart Menefy #define TS_USEDFPU 0x0002 /* FPU used by this task this quantum */
14656bfc42fSPaul Mundt
14756bfc42fSPaul Mundt #ifndef __ASSEMBLY__
1485a1dc78aSPaul Mundt
1495a1dc78aSPaul Mundt #define TI_FLAG_FAULT_CODE_SHIFT 24
1505a1dc78aSPaul Mundt
1515a1dc78aSPaul Mundt /*
1525a1dc78aSPaul Mundt * Additional thread flag encoding
1535a1dc78aSPaul Mundt */
set_thread_fault_code(unsigned int val)1545a1dc78aSPaul Mundt static inline void set_thread_fault_code(unsigned int val)
1555a1dc78aSPaul Mundt {
1565a1dc78aSPaul Mundt struct thread_info *ti = current_thread_info();
1575a1dc78aSPaul Mundt ti->flags = (ti->flags & (~0 >> (32 - TI_FLAG_FAULT_CODE_SHIFT)))
1585a1dc78aSPaul Mundt | (val << TI_FLAG_FAULT_CODE_SHIFT);
1595a1dc78aSPaul Mundt }
1605a1dc78aSPaul Mundt
get_thread_fault_code(void)1615a1dc78aSPaul Mundt static inline unsigned int get_thread_fault_code(void)
1625a1dc78aSPaul Mundt {
1635a1dc78aSPaul Mundt struct thread_info *ti = current_thread_info();
1645a1dc78aSPaul Mundt return ti->flags >> TI_FLAG_FAULT_CODE_SHIFT;
1655a1dc78aSPaul Mundt }
1664ebefe3eSAl Viro
16756bfc42fSPaul Mundt #endif /* !__ASSEMBLY__ */
168f15cbe6fSPaul Mundt #endif /* __ASM_SH_THREAD_INFO_H */
169