162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * NiosII low-level thread information
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2011 Tobias Klauser <tklauser@distanz.ch>
562306a36Sopenharmony_ci * Copyright (C) 2004 Microtronix Datacom Ltd.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Based on asm/thread_info_no.h from m68k which is:
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Copyright (C) 2002 David Howells <dhowells@redhat.com>
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * This file is subject to the terms and conditions of the GNU General Public
1262306a36Sopenharmony_ci * License.  See the file "COPYING" in the main directory of this archive
1362306a36Sopenharmony_ci * for more details.
1462306a36Sopenharmony_ci */
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci#ifndef _ASM_NIOS2_THREAD_INFO_H
1762306a36Sopenharmony_ci#define _ASM_NIOS2_THREAD_INFO_H
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci#ifdef __KERNEL__
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci/*
2262306a36Sopenharmony_ci * Size of the kernel stack for each process.
2362306a36Sopenharmony_ci */
2462306a36Sopenharmony_ci#define THREAD_SIZE_ORDER	1
2562306a36Sopenharmony_ci#define THREAD_SIZE		8192 /* 2 * PAGE_SIZE */
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ci#ifndef __ASSEMBLY__
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci/*
3062306a36Sopenharmony_ci * low level task data that entry.S needs immediate access to
3162306a36Sopenharmony_ci * - this struct should fit entirely inside of one cache line
3262306a36Sopenharmony_ci * - this struct shares the supervisor stack pages
3362306a36Sopenharmony_ci * - if the contents of this structure are changed, the assembly constants
3462306a36Sopenharmony_ci *   must also be changed
3562306a36Sopenharmony_ci */
3662306a36Sopenharmony_cistruct thread_info {
3762306a36Sopenharmony_ci	struct task_struct	*task;		/* main task structure */
3862306a36Sopenharmony_ci	unsigned long		flags;		/* low level flags */
3962306a36Sopenharmony_ci	__u32			cpu;		/* current CPU */
4062306a36Sopenharmony_ci	int			preempt_count;	/* 0 => preemptable,<0 => BUG */
4162306a36Sopenharmony_ci	struct pt_regs		*regs;
4262306a36Sopenharmony_ci};
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci/*
4562306a36Sopenharmony_ci * macros/functions for gaining access to the thread information structure
4662306a36Sopenharmony_ci *
4762306a36Sopenharmony_ci * preempt_count needs to be 1 initially, until the scheduler is functional.
4862306a36Sopenharmony_ci */
4962306a36Sopenharmony_ci#define INIT_THREAD_INFO(tsk)			\
5062306a36Sopenharmony_ci{						\
5162306a36Sopenharmony_ci	.task		= &tsk,			\
5262306a36Sopenharmony_ci	.flags		= 0,			\
5362306a36Sopenharmony_ci	.cpu		= 0,			\
5462306a36Sopenharmony_ci	.preempt_count	= INIT_PREEMPT_COUNT,	\
5562306a36Sopenharmony_ci}
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci/* how to get the thread information struct from C */
5862306a36Sopenharmony_cistatic inline struct thread_info *current_thread_info(void)
5962306a36Sopenharmony_ci{
6062306a36Sopenharmony_ci	register unsigned long sp asm("sp");
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci	return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
6362306a36Sopenharmony_ci}
6462306a36Sopenharmony_ci#endif /* !__ASSEMBLY__ */
6562306a36Sopenharmony_ci
6662306a36Sopenharmony_ci/*
6762306a36Sopenharmony_ci * thread information flags
6862306a36Sopenharmony_ci * - these are process state flags that various assembly files may need to
6962306a36Sopenharmony_ci *   access
7062306a36Sopenharmony_ci * - pending work-to-be-done flags are in LSW
7162306a36Sopenharmony_ci * - other flags in MSW
7262306a36Sopenharmony_ci */
7362306a36Sopenharmony_ci#define TIF_SYSCALL_TRACE	0	/* syscall trace active */
7462306a36Sopenharmony_ci#define TIF_NOTIFY_RESUME	1	/* resumption notification requested */
7562306a36Sopenharmony_ci#define TIF_SIGPENDING		2	/* signal pending */
7662306a36Sopenharmony_ci#define TIF_NEED_RESCHED	3	/* rescheduling necessary */
7762306a36Sopenharmony_ci#define TIF_MEMDIE		4	/* is terminating due to OOM killer */
7862306a36Sopenharmony_ci#define TIF_SECCOMP		5	/* secure computing */
7962306a36Sopenharmony_ci#define TIF_SYSCALL_AUDIT	6	/* syscall auditing active */
8062306a36Sopenharmony_ci#define TIF_NOTIFY_SIGNAL	7	/* signal notifications exist */
8162306a36Sopenharmony_ci#define TIF_RESTORE_SIGMASK	9	/* restore signal mask in do_signal() */
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define TIF_POLLING_NRFLAG	16	/* true if poll_idle() is polling
8462306a36Sopenharmony_ci					   TIF_NEED_RESCHED */
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
8762306a36Sopenharmony_ci#define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
8862306a36Sopenharmony_ci#define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
8962306a36Sopenharmony_ci#define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
9062306a36Sopenharmony_ci#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
9162306a36Sopenharmony_ci#define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
9262306a36Sopenharmony_ci#define _TIF_NOTIFY_SIGNAL	(1 << TIF_NOTIFY_SIGNAL)
9362306a36Sopenharmony_ci#define _TIF_RESTORE_SIGMASK	(1 << TIF_RESTORE_SIGMASK)
9462306a36Sopenharmony_ci#define _TIF_POLLING_NRFLAG	(1 << TIF_POLLING_NRFLAG)
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci/* work to do on interrupt/exception return */
9762306a36Sopenharmony_ci#define _TIF_WORK_MASK		0x0000FFFE
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci#endif /* __KERNEL__ */
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci#endif /* _ASM_NIOS2_THREAD_INFO_H */
102