]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - arch/hexagon/kernel/process.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-bionic-kernel.git] / arch / hexagon / kernel / process.c
CommitLineData
4b30f965
RK
1/*
2 * Process creation support for Hexagon
3 *
e1858b2a 4 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
4b30f965
RK
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 and
8 * only version 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA.
19 */
20
21#include <linux/sched.h>
b17b0153 22#include <linux/sched/debug.h>
29930025 23#include <linux/sched/task.h>
68db0cf1 24#include <linux/sched/task_stack.h>
4b30f965
RK
25#include <linux/types.h>
26#include <linux/module.h>
27#include <linux/tick.h>
28#include <linux/uaccess.h>
29#include <linux/slab.h>
a11e67c2 30#include <linux/tracehook.h>
4b30f965 31
4b30f965
RK
32/*
33 * Program thread launch. Often defined as a macro in processor.h,
34 * but we're shooting for a small footprint and it's not an inner-loop
35 * performance-critical operation.
36 *
37 * The Hexagon ABI specifies that R28 is zero'ed before program launch,
38 * so that gets automatically done here. If we ever stop doing that here,
39 * we'll probably want to define the ELF_PLAT_INIT macro.
40 */
41void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
42{
4b30f965
RK
43 /* We want to zero all data-containing registers. Is this overkill? */
44 memset(regs, 0, sizeof(*regs));
45 /* We might want to also zero all Processor registers here */
46 pt_set_usermode(regs);
47 pt_set_elr(regs, pc);
48 pt_set_rte_sp(regs, sp);
49}
50
51/*
52 * Spin, or better still, do a hardware or VM wait instruction
53 * If hardware or VM offer wait termination even though interrupts
54 * are disabled.
55 */
4e0fcc56 56void arch_cpu_idle(void)
4b30f965
RK
57{
58 __vmwait();
4e0fcc56
TG
59 /* interrupts wake us up, but irqs are still disabled */
60 local_irq_enable();
4b30f965
RK
61}
62
63/*
64 * Return saved PC of a blocked thread
65 */
66unsigned long thread_saved_pc(struct task_struct *tsk)
67{
68 return 0;
69}
70
71/*
72 * Copy architecture-specific thread state
73 */
74int copy_thread(unsigned long clone_flags, unsigned long usp,
afa86fc4 75 unsigned long arg, struct task_struct *p)
4b30f965
RK
76{
77 struct thread_info *ti = task_thread_info(p);
78 struct hexagon_switch_stack *ss;
79 struct pt_regs *childregs;
80 asmlinkage void ret_from_fork(void);
81
82 childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
83 sizeof(*childregs));
84
4b30f965
RK
85 ti->regs = childregs;
86
87 /*
88 * Establish kernel stack pointer and initial PC for new thread
99521855
AV
89 * Note that unlike the usual situation, we do not copy the
90 * parent's callee-saved here; those are in pt_regs and whatever
91 * we leave here will be overridden on return to userland.
4b30f965
RK
92 */
93 ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
94 sizeof(*ss));
95 ss->lr = (unsigned long)ret_from_fork;
96 p->thread.switch_sp = ss;
99521855
AV
97 if (unlikely(p->flags & PF_KTHREAD)) {
98 memset(childregs, 0, sizeof(struct pt_regs));
99 /* r24 <- fn, r25 <- arg */
0d3ab450
RK
100 ss->r24 = usp;
101 ss->r25 = arg;
99521855
AV
102 pt_set_kmode(childregs);
103 return 0;
4b30f965 104 }
f01aceac 105 memcpy(childregs, current_pt_regs(), sizeof(*childregs));
99521855
AV
106 ss->r2524 = 0;
107
f01aceac
AV
108 if (usp)
109 pt_set_rte_sp(childregs, usp);
99521855
AV
110
111 /* Child sees zero return value */
112 childregs->r00 = 0;
113
114 /*
115 * The clone syscall has the C signature:
116 * int [r0] clone(int flags [r0],
117 * void *child_frame [r1],
118 * void *parent_tid [r2],
119 * void *child_tid [r3],
120 * void *thread_control_block [r4]);
121 * ugp is used to provide TLS support.
122 */
123 if (clone_flags & CLONE_SETTLS)
124 childregs->ugp = childregs->r04;
4b30f965
RK
125
126 /*
99521855
AV
127 * Parent sees new pid -- not necessary, not even possible at
128 * this point in the fork process
129 * Might also want to set things like ti->addr_limit
4b30f965 130 */
4b30f965
RK
131
132 return 0;
133}
134
135/*
136 * Release any architecture-specific resources locked by thread
137 */
138void release_thread(struct task_struct *dead_task)
139{
140}
141
4b30f965
RK
142/*
143 * Some archs flush debug and FPU info here
144 */
145void flush_thread(void)
146{
147}
148
149/*
150 * The "wait channel" terminology is archaic, but what we want
151 * is an identification of the point at which the scheduler
152 * was invoked by a blocked thread.
153 */
154unsigned long get_wchan(struct task_struct *p)
155{
156 unsigned long fp, pc;
157 unsigned long stack_page;
158 int count = 0;
159 if (!p || p == current || p->state == TASK_RUNNING)
160 return 0;
161
162 stack_page = (unsigned long)task_stack_page(p);
163 fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
164 do {
165 if (fp < (stack_page + sizeof(struct thread_info)) ||
166 fp >= (THREAD_SIZE - 8 + stack_page))
167 return 0;
168 pc = ((unsigned long *)fp)[1];
169 if (!in_sched_functions(pc))
170 return pc;
171 fp = *(unsigned long *) fp;
172 } while (count++ < 16);
173
174 return 0;
175}
176
4b30f965
RK
177/*
178 * Required placeholder.
179 */
180int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
181{
182 return 0;
183}
a11e67c2
RK
184
185
186/*
187 * Called on the exit path of event entry; see vm_entry.S
188 *
189 * Interrupts will already be disabled.
190 *
191 * Returns 0 if there's no need to re-check for more work.
192 */
193
194int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
195{
f8722a4d 196 if (!(thread_info_flags & _TIF_WORK_MASK)) {
a11e67c2
RK
197 return 0;
198 } /* shortcut -- no work to be done */
199
200 local_irq_enable();
201
202 if (thread_info_flags & _TIF_NEED_RESCHED) {
203 schedule();
204 return 1;
205 }
206
207 if (thread_info_flags & _TIF_SIGPENDING) {
208 do_signal(regs);
209 return 1;
210 }
211
212 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
213 clear_thread_flag(TIF_NOTIFY_RESUME);
214 tracehook_notify_resume(regs);
c710f590 215 return 1;
a11e67c2
RK
216 }
217
218 /* Should not even reach here */
219 panic("%s: bad thread_info flags 0x%08x\n", __func__,
220 thread_info_flags);
221}