]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - arch/hexagon/kernel/process.c
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
21 #include <linux/sched.h>
22 #include <linux/sched/debug.h>
23 #include <linux/types.h>
24 #include <linux/module.h>
25 #include <linux/tick.h>
26 #include <linux/uaccess.h>
27 #include <linux/slab.h>
28 #include <linux/tracehook.h>
31 * Program thread launch. Often defined as a macro in processor.h,
32 * but we're shooting for a small footprint and it's not an inner-loop
33 * performance-critical operation.
35 * The Hexagon ABI specifies that R28 is zero'ed before program launch,
36 * so that gets automatically done here. If we ever stop doing that here,
37 * we'll probably want to define the ELF_PLAT_INIT macro.
39 void start_thread(struct pt_regs
*regs
, unsigned long pc
, unsigned long sp
)
41 /* We want to zero all data-containing registers. Is this overkill? */
42 memset(regs
, 0, sizeof(*regs
));
43 /* We might want to also zero all Processor registers here */
44 pt_set_usermode(regs
);
46 pt_set_rte_sp(regs
, sp
);
50 * Spin, or better still, do a hardware or VM wait instruction
51 * If hardware or VM offer wait termination even though interrupts
54 void arch_cpu_idle(void)
57 /* interrupts wake us up, but irqs are still disabled */
62 * Return saved PC of a blocked thread
64 unsigned long thread_saved_pc(struct task_struct
*tsk
)
70 * Copy architecture-specific thread state
72 int copy_thread(unsigned long clone_flags
, unsigned long usp
,
73 unsigned long arg
, struct task_struct
*p
)
75 struct thread_info
*ti
= task_thread_info(p
);
76 struct hexagon_switch_stack
*ss
;
77 struct pt_regs
*childregs
;
78 asmlinkage
void ret_from_fork(void);
80 childregs
= (struct pt_regs
*) (((unsigned long) ti
+ THREAD_SIZE
) -
86 * Establish kernel stack pointer and initial PC for new thread
87 * Note that unlike the usual situation, we do not copy the
88 * parent's callee-saved here; those are in pt_regs and whatever
89 * we leave here will be overridden on return to userland.
91 ss
= (struct hexagon_switch_stack
*) ((unsigned long) childregs
-
93 ss
->lr
= (unsigned long)ret_from_fork
;
94 p
->thread
.switch_sp
= ss
;
95 if (unlikely(p
->flags
& PF_KTHREAD
)) {
96 memset(childregs
, 0, sizeof(struct pt_regs
));
97 /* r24 <- fn, r25 <- arg */
100 pt_set_kmode(childregs
);
103 memcpy(childregs
, current_pt_regs(), sizeof(*childregs
));
107 pt_set_rte_sp(childregs
, usp
);
109 /* Child sees zero return value */
113 * The clone syscall has the C signature:
114 * int [r0] clone(int flags [r0],
115 * void *child_frame [r1],
116 * void *parent_tid [r2],
117 * void *child_tid [r3],
118 * void *thread_control_block [r4]);
119 * ugp is used to provide TLS support.
121 if (clone_flags
& CLONE_SETTLS
)
122 childregs
->ugp
= childregs
->r04
;
125 * Parent sees new pid -- not necessary, not even possible at
126 * this point in the fork process
127 * Might also want to set things like ti->addr_limit
134 * Release any architecture-specific resources locked by thread
136 void release_thread(struct task_struct
*dead_task
)
141 * Some archs flush debug and FPU info here
143 void flush_thread(void)
148 * The "wait channel" terminology is archaic, but what we want
149 * is an identification of the point at which the scheduler
150 * was invoked by a blocked thread.
152 unsigned long get_wchan(struct task_struct
*p
)
154 unsigned long fp
, pc
;
155 unsigned long stack_page
;
157 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
160 stack_page
= (unsigned long)task_stack_page(p
);
161 fp
= ((struct hexagon_switch_stack
*)p
->thread
.switch_sp
)->fp
;
163 if (fp
< (stack_page
+ sizeof(struct thread_info
)) ||
164 fp
>= (THREAD_SIZE
- 8 + stack_page
))
166 pc
= ((unsigned long *)fp
)[1];
167 if (!in_sched_functions(pc
))
169 fp
= *(unsigned long *) fp
;
170 } while (count
++ < 16);
176 * Required placeholder.
178 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpu
)
185 * Called on the exit path of event entry; see vm_entry.S
187 * Interrupts will already be disabled.
189 * Returns 0 if there's no need to re-check for more work.
192 int do_work_pending(struct pt_regs
*regs
, u32 thread_info_flags
)
194 if (!(thread_info_flags
& _TIF_WORK_MASK
)) {
196 } /* shortcut -- no work to be done */
200 if (thread_info_flags
& _TIF_NEED_RESCHED
) {
205 if (thread_info_flags
& _TIF_SIGPENDING
) {
210 if (thread_info_flags
& _TIF_NOTIFY_RESUME
) {
211 clear_thread_flag(TIF_NOTIFY_RESUME
);
212 tracehook_notify_resume(regs
);
216 /* Should not even reach here */
217 panic("%s: bad thread_info flags 0x%08x\n", __func__
,