Merge tag 'rproc-v6.14' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc...
[linux.git] / arch / hexagon / kernel / process.c
blob2a77bfd7569450ce4cf30af9376819628feeb559
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Process creation support for Hexagon
5 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
6 */
8 #include <linux/cpu.h>
9 #include <linux/sched.h>
10 #include <linux/sched/debug.h>
11 #include <linux/sched/task.h>
12 #include <linux/sched/task_stack.h>
13 #include <linux/types.h>
14 #include <linux/module.h>
15 #include <linux/tick.h>
16 #include <linux/uaccess.h>
17 #include <linux/slab.h>
18 #include <linux/resume_user_mode.h>
21 * Program thread launch. Often defined as a macro in processor.h,
22 * but we're shooting for a small footprint and it's not an inner-loop
23 * performance-critical operation.
25 * The Hexagon ABI specifies that R28 is zero'ed before program launch,
26 * so that gets automatically done here. If we ever stop doing that here,
27 * we'll probably want to define the ELF_PLAT_INIT macro.
29 void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
31 /* We want to zero all data-containing registers. Is this overkill? */
32 memset(regs, 0, sizeof(*regs));
33 /* We might want to also zero all Processor registers here */
34 pt_set_usermode(regs);
35 pt_set_elr(regs, pc);
36 pt_set_rte_sp(regs, sp);
40 * Spin, or better still, do a hardware or VM wait instruction
41 * If hardware or VM offer wait termination even though interrupts
42 * are disabled.
44 void arch_cpu_idle(void)
46 __vmwait();
47 /* interrupts wake us up, but irqs are still disabled */
51 * Copy architecture-specific thread state
53 int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
55 unsigned long clone_flags = args->flags;
56 unsigned long usp = args->stack;
57 unsigned long tls = args->tls;
58 struct thread_info *ti = task_thread_info(p);
59 struct hexagon_switch_stack *ss;
60 struct pt_regs *childregs;
61 asmlinkage void ret_from_fork(void);
63 childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
64 sizeof(*childregs));
66 ti->regs = childregs;
69 * Establish kernel stack pointer and initial PC for new thread
70 * Note that unlike the usual situation, we do not copy the
71 * parent's callee-saved here; those are in pt_regs and whatever
72 * we leave here will be overridden on return to userland.
74 ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
75 sizeof(*ss));
76 ss->lr = (unsigned long)ret_from_fork;
77 p->thread.switch_sp = ss;
78 if (unlikely(args->fn)) {
79 memset(childregs, 0, sizeof(struct pt_regs));
80 /* r24 <- fn, r25 <- arg */
81 ss->r24 = (unsigned long)args->fn;
82 ss->r25 = (unsigned long)args->fn_arg;
83 pt_set_kmode(childregs);
84 return 0;
86 memcpy(childregs, current_pt_regs(), sizeof(*childregs));
87 ss->r2524 = 0;
89 if (usp)
90 pt_set_rte_sp(childregs, usp);
92 /* Child sees zero return value */
93 childregs->r00 = 0;
96 * The clone syscall has the C signature:
97 * int [r0] clone(int flags [r0],
98 * void *child_frame [r1],
99 * void *parent_tid [r2],
100 * void *child_tid [r3],
101 * void *thread_control_block [r4]);
102 * ugp is used to provide TLS support.
104 if (clone_flags & CLONE_SETTLS)
105 childregs->ugp = tls;
108 * Parent sees new pid -- not necessary, not even possible at
109 * this point in the fork process
112 return 0;
116 * Some archs flush debug and FPU info here
118 void flush_thread(void)
123 * The "wait channel" terminology is archaic, but what we want
124 * is an identification of the point at which the scheduler
125 * was invoked by a blocked thread.
127 unsigned long __get_wchan(struct task_struct *p)
129 unsigned long fp, pc;
130 unsigned long stack_page;
131 int count = 0;
133 stack_page = (unsigned long)task_stack_page(p);
134 fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
135 do {
136 if (fp < (stack_page + sizeof(struct thread_info)) ||
137 fp >= (THREAD_SIZE - 8 + stack_page))
138 return 0;
139 pc = ((unsigned long *)fp)[1];
140 if (!in_sched_functions(pc))
141 return pc;
142 fp = *(unsigned long *) fp;
143 } while (count++ < 16);
145 return 0;
149 * Called on the exit path of event entry; see vm_entry.S
151 * Interrupts will already be disabled.
153 * Returns 0 if there's no need to re-check for more work.
156 int do_work_pending(struct pt_regs *regs, u32 thread_info_flags);
157 int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
159 if (!(thread_info_flags & _TIF_WORK_MASK)) {
160 return 0;
161 } /* shortcut -- no work to be done */
163 local_irq_enable();
165 if (thread_info_flags & _TIF_NEED_RESCHED) {
166 schedule();
167 return 1;
170 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) {
171 do_signal(regs);
172 return 1;
175 if (thread_info_flags & _TIF_NOTIFY_RESUME) {
176 resume_user_mode_work(regs);
177 return 1;
180 /* Should not even reach here */
181 panic("%s: bad thread_info flags 0x%08x\n", __func__,
182 thread_info_flags);