Merge tag 'dt-3.13-4' of git://git.infradead.org/linux-mvebu into next/dt
[linux-2.6.git] / arch / hexagon / kernel / process.c
blob0a0dd5c05b46af8fda112b2ab9cc606a08d6d5a5
1 /*
2 * Process creation support for Hexagon
4 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
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.
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.
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.
21 #include <linux/sched.h>
22 #include <linux/types.h>
23 #include <linux/module.h>
24 #include <linux/tick.h>
25 #include <linux/uaccess.h>
26 #include <linux/slab.h>
27 #include <linux/tracehook.h>
30 * Program thread launch. Often defined as a macro in processor.h,
31 * but we're shooting for a small footprint and it's not an inner-loop
32 * performance-critical operation.
34 * The Hexagon ABI specifies that R28 is zero'ed before program launch,
35 * so that gets automatically done here. If we ever stop doing that here,
36 * we'll probably want to define the ELF_PLAT_INIT macro.
38 void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
40 /* Set to run with user-mode data segmentation */
41 set_fs(USER_DS);
42 /* We want to zero all data-containing registers. Is this overkill? */
43 memset(regs, 0, sizeof(*regs));
44 /* We might want to also zero all Processor registers here */
45 pt_set_usermode(regs);
46 pt_set_elr(regs, pc);
47 pt_set_rte_sp(regs, sp);
51 * Spin, or better still, do a hardware or VM wait instruction
52 * If hardware or VM offer wait termination even though interrupts
53 * are disabled.
55 void arch_cpu_idle(void)
57 __vmwait();
58 /* interrupts wake us up, but irqs are still disabled */
59 local_irq_enable();
63 * Return saved PC of a blocked thread
65 unsigned long thread_saved_pc(struct task_struct *tsk)
67 return 0;
71 * Copy architecture-specific thread state
73 int copy_thread(unsigned long clone_flags, unsigned long usp,
74 unsigned long arg, struct task_struct *p)
76 struct thread_info *ti = task_thread_info(p);
77 struct hexagon_switch_stack *ss;
78 struct pt_regs *childregs;
79 asmlinkage void ret_from_fork(void);
81 childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
82 sizeof(*childregs));
84 ti->regs = childregs;
87 * Establish kernel stack pointer and initial PC for new thread
88 * Note that unlike the usual situation, we do not copy the
89 * parent's callee-saved here; those are in pt_regs and whatever
90 * we leave here will be overridden on return to userland.
92 ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
93 sizeof(*ss));
94 ss->lr = (unsigned long)ret_from_fork;
95 p->thread.switch_sp = ss;
96 if (unlikely(p->flags & PF_KTHREAD)) {
97 memset(childregs, 0, sizeof(struct pt_regs));
98 /* r24 <- fn, r25 <- arg */
99 ss->r24 = usp;
100 ss->r25 = arg;
101 pt_set_kmode(childregs);
102 return 0;
104 memcpy(childregs, current_pt_regs(), sizeof(*childregs));
105 ss->r2524 = 0;
107 if (usp)
108 pt_set_rte_sp(childregs, usp);
110 /* Child sees zero return value */
111 childregs->r00 = 0;
114 * The clone syscall has the C signature:
115 * int [r0] clone(int flags [r0],
116 * void *child_frame [r1],
117 * void *parent_tid [r2],
118 * void *child_tid [r3],
119 * void *thread_control_block [r4]);
120 * ugp is used to provide TLS support.
122 if (clone_flags & CLONE_SETTLS)
123 childregs->ugp = childregs->r04;
126 * Parent sees new pid -- not necessary, not even possible at
127 * this point in the fork process
128 * Might also want to set things like ti->addr_limit
131 return 0;
135 * Release any architecture-specific resources locked by thread
137 void release_thread(struct task_struct *dead_task)
142 * Free any architecture-specific thread data structures, etc.
144 void exit_thread(void)
149 * Some archs flush debug and FPU info here
151 void flush_thread(void)
156 * The "wait channel" terminology is archaic, but what we want
157 * is an identification of the point at which the scheduler
158 * was invoked by a blocked thread.
160 unsigned long get_wchan(struct task_struct *p)
162 unsigned long fp, pc;
163 unsigned long stack_page;
164 int count = 0;
165 if (!p || p == current || p->state == TASK_RUNNING)
166 return 0;
168 stack_page = (unsigned long)task_stack_page(p);
169 fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
170 do {
171 if (fp < (stack_page + sizeof(struct thread_info)) ||
172 fp >= (THREAD_SIZE - 8 + stack_page))
173 return 0;
174 pc = ((unsigned long *)fp)[1];
175 if (!in_sched_functions(pc))
176 return pc;
177 fp = *(unsigned long *) fp;
178 } while (count++ < 16);
180 return 0;
184 * Required placeholder.
186 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
188 return 0;
193 * Called on the exit path of event entry; see vm_entry.S
195 * Interrupts will already be disabled.
197 * Returns 0 if there's no need to re-check for more work.
200 int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
202 if (!(thread_info_flags & _TIF_WORK_MASK)) {
203 return 0;
204 } /* shortcut -- no work to be done */
206 local_irq_enable();
208 if (thread_info_flags & _TIF_NEED_RESCHED) {
209 schedule();
210 return 1;
213 if (thread_info_flags & _TIF_SIGPENDING) {
214 do_signal(regs);
215 return 1;
218 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
219 clear_thread_flag(TIF_NOTIFY_RESUME);
220 tracehook_notify_resume(regs);
221 return 1;
224 /* Should not even reach here */
225 panic("%s: bad thread_info flags 0x%08x\n", __func__,
226 thread_info_flags);