1 /*
2  * OpenRISC Linux
3  *
4  * Linux architectural port borrowing liberally from similar works of
5  * others.  All original copyrights apply as per the original source
6  * declaration.
7  *
8  * OpenRISC implementation:
9  * Copyright (C) 2003 Matjaz Breskvar <phoenix@bsemi.com>
10  * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
11  * et al.
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  */
18 
19 #ifndef _ASM_THREAD_INFO_H
20 #define _ASM_THREAD_INFO_H
21 
22 #ifdef __KERNEL__
23 
24 #ifndef __ASSEMBLY__
25 #include <asm/types.h>
26 #include <asm/processor.h>
27 #endif
28 
29 
30 /* THREAD_SIZE is the size of the task_struct/kernel_stack combo.
31  * normally, the stack is found by doing something like p + THREAD_SIZE
32  * in or32, a page is 8192 bytes, which seems like a sane size
33  */
34 
35 #define THREAD_SIZE_ORDER 0
36 #define THREAD_SIZE       (PAGE_SIZE << THREAD_SIZE_ORDER)
37 
38 /*
39  * low level task data that entry.S needs immediate access to
40  * - this struct should fit entirely inside of one cache line
41  * - this struct shares the supervisor stack pages
42  * - if the contents of this structure are changed, the assembly constants
43  *   must also be changed
44  */
45 #ifndef __ASSEMBLY__
46 
47 typedef unsigned long mm_segment_t;
48 
49 struct thread_info {
50 	struct task_struct	*task;		/* main task structure */
51 	unsigned long		flags;		/* low level flags */
52 	__u32			cpu;		/* current CPU */
53 	__s32			preempt_count; /* 0 => preemptable, <0 => BUG */
54 
55 	mm_segment_t		addr_limit; /* thread address space:
56 					       0-0x7FFFFFFF for user-thead
57 					       0-0xFFFFFFFF for kernel-thread
58 					     */
59 	__u8			supervisor_stack[0];
60 
61 	/* saved context data */
62 	unsigned long           ksp;
63 };
64 #endif
65 
66 /*
67  * macros/functions for gaining access to the thread information structure
68  *
69  * preempt_count needs to be 1 initially, until the scheduler is functional.
70  */
71 #ifndef __ASSEMBLY__
72 #define INIT_THREAD_INFO(tsk)				\
73 {							\
74 	.task		= &tsk,				\
75 	.flags		= 0,				\
76 	.cpu		= 0,				\
77 	.preempt_count	= INIT_PREEMPT_COUNT,		\
78 	.addr_limit	= KERNEL_DS,			\
79 	.ksp            = 0,                            \
80 }
81 
82 /* how to get the thread information struct from C */
83 register struct thread_info *current_thread_info_reg asm("r10");
84 #define current_thread_info()   (current_thread_info_reg)
85 
86 #define get_thread_info(ti) get_task_struct((ti)->task)
87 #define put_thread_info(ti) put_task_struct((ti)->task)
88 
89 #endif /* !__ASSEMBLY__ */
90 
91 /*
92  * thread information flags
93  *   these are process state flags that various assembly files may need to
94  *   access
95  *   - pending work-to-be-done flags are in LSW
96  *   - other flags in MSW
97  */
98 #define TIF_SYSCALL_TRACE	0	/* syscall trace active */
99 #define TIF_NOTIFY_RESUME	1	/* resumption notification requested */
100 #define TIF_SIGPENDING		2	/* signal pending */
101 #define TIF_NEED_RESCHED	3	/* rescheduling necessary */
102 #define TIF_SINGLESTEP		4	/* restore singlestep on return to user
103 					 * mode
104 					 */
105 #define TIF_SYSCALL_TRACEPOINT  8       /* for ftrace syscall instrumentation */
106 #define TIF_RESTORE_SIGMASK     9
107 #define TIF_POLLING_NRFLAG	16	/* true if poll_idle() is polling						 * TIF_NEED_RESCHED
108 					 */
109 #define TIF_MEMDIE              17
110 
111 #define _TIF_SYSCALL_TRACE	(1<<TIF_SYSCALL_TRACE)
112 #define _TIF_NOTIFY_RESUME	(1<<TIF_NOTIFY_RESUME)
113 #define _TIF_SIGPENDING		(1<<TIF_SIGPENDING)
114 #define _TIF_NEED_RESCHED	(1<<TIF_NEED_RESCHED)
115 #define _TIF_SINGLESTEP		(1<<TIF_SINGLESTEP)
116 #define _TIF_POLLING_NRFLAG	(1<<TIF_POLLING_NRFLAG)
117 
118 
119 /* Work to do when returning from interrupt/exception */
120 /* For OpenRISC, this is anything in the LSW other than syscall trace */
121 #define _TIF_WORK_MASK (0xff & ~(_TIF_SYSCALL_TRACE|_TIF_SINGLESTEP))
122 
123 #endif /* __KERNEL__ */
124 
125 #endif /* _ASM_THREAD_INFO_H */
126