162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * OpenRISC Linux
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Linux architectural port borrowing liberally from similar works of
662306a36Sopenharmony_ci * others.  All original copyrights apply as per the original source
762306a36Sopenharmony_ci * declaration.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * OpenRISC implementation:
1062306a36Sopenharmony_ci * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
1162306a36Sopenharmony_ci * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
1262306a36Sopenharmony_ci * et al.
1362306a36Sopenharmony_ci */
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#ifndef _ASM_THREAD_INFO_H
1662306a36Sopenharmony_ci#define _ASM_THREAD_INFO_H
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci#ifdef __KERNEL__
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#ifndef __ASSEMBLY__
2162306a36Sopenharmony_ci#include <asm/types.h>
2262306a36Sopenharmony_ci#include <asm/processor.h>
2362306a36Sopenharmony_ci#endif
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/* THREAD_SIZE is the size of the task_struct/kernel_stack combo.
2762306a36Sopenharmony_ci * normally, the stack is found by doing something like p + THREAD_SIZE
2862306a36Sopenharmony_ci * in or1k, a page is 8192 bytes, which seems like a sane size
2962306a36Sopenharmony_ci */
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define THREAD_SIZE_ORDER 0
3262306a36Sopenharmony_ci#define THREAD_SIZE       (PAGE_SIZE << THREAD_SIZE_ORDER)
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/*
3562306a36Sopenharmony_ci * low level task data that entry.S needs immediate access to
3662306a36Sopenharmony_ci * - this struct should fit entirely inside of one cache line
3762306a36Sopenharmony_ci * - this struct shares the supervisor stack pages
3862306a36Sopenharmony_ci * - if the contents of this structure are changed, the assembly constants
3962306a36Sopenharmony_ci *   must also be changed
4062306a36Sopenharmony_ci */
4162306a36Sopenharmony_ci#ifndef __ASSEMBLY__
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_cistruct thread_info {
4462306a36Sopenharmony_ci	struct task_struct	*task;		/* main task structure */
4562306a36Sopenharmony_ci	unsigned long		flags;		/* low level flags */
4662306a36Sopenharmony_ci	__u32			cpu;		/* current CPU */
4762306a36Sopenharmony_ci	__s32			preempt_count; /* 0 => preemptable, <0 => BUG */
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci	__u8			supervisor_stack[0];
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci	/* saved context data */
5262306a36Sopenharmony_ci	unsigned long           ksp;
5362306a36Sopenharmony_ci};
5462306a36Sopenharmony_ci#endif
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/*
5762306a36Sopenharmony_ci * macros/functions for gaining access to the thread information structure
5862306a36Sopenharmony_ci *
5962306a36Sopenharmony_ci * preempt_count needs to be 1 initially, until the scheduler is functional.
6062306a36Sopenharmony_ci */
6162306a36Sopenharmony_ci#ifndef __ASSEMBLY__
6262306a36Sopenharmony_ci#define INIT_THREAD_INFO(tsk)				\
6362306a36Sopenharmony_ci{							\
6462306a36Sopenharmony_ci	.task		= &tsk,				\
6562306a36Sopenharmony_ci	.flags		= 0,				\
6662306a36Sopenharmony_ci	.cpu		= 0,				\
6762306a36Sopenharmony_ci	.preempt_count	= INIT_PREEMPT_COUNT,		\
6862306a36Sopenharmony_ci	.ksp            = 0,                            \
6962306a36Sopenharmony_ci}
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci/* how to get the thread information struct from C */
7262306a36Sopenharmony_ciregister struct thread_info *current_thread_info_reg asm("r10");
7362306a36Sopenharmony_ci#define current_thread_info()   (current_thread_info_reg)
7462306a36Sopenharmony_ci
7562306a36Sopenharmony_ci#define get_thread_info(ti) get_task_struct((ti)->task)
7662306a36Sopenharmony_ci#define put_thread_info(ti) put_task_struct((ti)->task)
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#endif /* !__ASSEMBLY__ */
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/*
8162306a36Sopenharmony_ci * thread information flags
8262306a36Sopenharmony_ci *   these are process state flags that various assembly files may need to
8362306a36Sopenharmony_ci *   access
8462306a36Sopenharmony_ci *   - pending work-to-be-done flags are in LSW
8562306a36Sopenharmony_ci *   - other flags in MSW
8662306a36Sopenharmony_ci */
8762306a36Sopenharmony_ci#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
8862306a36Sopenharmony_ci#define TIF_NOTIFY_RESUME	1	/* resumption notification requested */
8962306a36Sopenharmony_ci#define TIF_SIGPENDING		2	/* signal pending */
9062306a36Sopenharmony_ci#define TIF_NEED_RESCHED	3	/* rescheduling necessary */
9162306a36Sopenharmony_ci#define TIF_SINGLESTEP		4	/* restore singlestep on return to user
9262306a36Sopenharmony_ci					 * mode
9362306a36Sopenharmony_ci					 */
9462306a36Sopenharmony_ci#define TIF_NOTIFY_SIGNAL	5	/* signal notifications exist */
9562306a36Sopenharmony_ci#define TIF_SYSCALL_TRACEPOINT  8       /* for ftrace syscall instrumentation */
9662306a36Sopenharmony_ci#define TIF_RESTORE_SIGMASK     9
9762306a36Sopenharmony_ci#define TIF_POLLING_NRFLAG	16	/* true if poll_idle() is polling						 * TIF_NEED_RESCHED
9862306a36Sopenharmony_ci					 */
9962306a36Sopenharmony_ci#define TIF_MEMDIE              17
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
10262306a36Sopenharmony_ci#define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
10362306a36Sopenharmony_ci#define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
10462306a36Sopenharmony_ci#define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
10562306a36Sopenharmony_ci#define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
10662306a36Sopenharmony_ci#define _TIF_NOTIFY_SIGNAL	(1<<TIF_NOTIFY_SIGNAL)
10762306a36Sopenharmony_ci#define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci/* Work to do when returning from interrupt/exception */
11162306a36Sopenharmony_ci/* For OpenRISC, this is anything in the LSW other than syscall trace */
11262306a36Sopenharmony_ci#define _TIF_WORK_MASK (0xff & ~(_TIF_SYSCALL_TRACE|_TIF_SINGLESTEP))
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci#endif /* __KERNEL__ */
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci#endif /* _ASM_THREAD_INFO_H */
117