Linux Audio

Check our new training course

Loading...
v4.17
 
  1/*
  2 * Process creation support for Hexagon
  3 *
  4 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
  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>
 22#include <linux/sched/debug.h>
 23#include <linux/sched/task.h>
 24#include <linux/sched/task_stack.h>
 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>
 30#include <linux/tracehook.h>
 31
 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{
 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 */
 56void arch_cpu_idle(void)
 57{
 58	__vmwait();
 59	/*  interrupts wake us up, but irqs are still disabled */
 60	local_irq_enable();
 61}
 62
 63/*
 64 * Copy architecture-specific thread state
 65 */
 66int copy_thread(unsigned long clone_flags, unsigned long usp,
 67		unsigned long arg, struct task_struct *p)
 68{
 
 
 
 69	struct thread_info *ti = task_thread_info(p);
 70	struct hexagon_switch_stack *ss;
 71	struct pt_regs *childregs;
 72	asmlinkage void ret_from_fork(void);
 73
 74	childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
 75					sizeof(*childregs));
 76
 77	ti->regs = childregs;
 78
 79	/*
 80	 * Establish kernel stack pointer and initial PC for new thread
 81	 * Note that unlike the usual situation, we do not copy the
 82	 * parent's callee-saved here; those are in pt_regs and whatever
 83	 * we leave here will be overridden on return to userland.
 84	 */
 85	ss = (struct hexagon_switch_stack *) ((unsigned long) childregs -
 86						    sizeof(*ss));
 87	ss->lr = (unsigned long)ret_from_fork;
 88	p->thread.switch_sp = ss;
 89	if (unlikely(p->flags & PF_KTHREAD)) {
 90		memset(childregs, 0, sizeof(struct pt_regs));
 91		/* r24 <- fn, r25 <- arg */
 92		ss->r24 = usp;
 93		ss->r25 = arg;
 94		pt_set_kmode(childregs);
 95		return 0;
 96	}
 97	memcpy(childregs, current_pt_regs(), sizeof(*childregs));
 98	ss->r2524 = 0;
 99
100	if (usp)
101		pt_set_rte_sp(childregs, usp);
102
103	/* Child sees zero return value */
104	childregs->r00 = 0;
105
106	/*
107	 * The clone syscall has the C signature:
108	 * int [r0] clone(int flags [r0],
109	 *           void *child_frame [r1],
110	 *           void *parent_tid [r2],
111	 *           void *child_tid [r3],
112	 *           void *thread_control_block [r4]);
113	 * ugp is used to provide TLS support.
114	 */
115	if (clone_flags & CLONE_SETTLS)
116		childregs->ugp = childregs->r04;
117
118	/*
119	 * Parent sees new pid -- not necessary, not even possible at
120	 * this point in the fork process
121	 * Might also want to set things like ti->addr_limit
122	 */
123
124	return 0;
125}
126
127/*
128 * Release any architecture-specific resources locked by thread
129 */
130void release_thread(struct task_struct *dead_task)
131{
132}
133
134/*
135 * Some archs flush debug and FPU info here
136 */
137void flush_thread(void)
138{
139}
140
141/*
142 * The "wait channel" terminology is archaic, but what we want
143 * is an identification of the point at which the scheduler
144 * was invoked by a blocked thread.
145 */
146unsigned long get_wchan(struct task_struct *p)
147{
148	unsigned long fp, pc;
149	unsigned long stack_page;
150	int count = 0;
151	if (!p || p == current || p->state == TASK_RUNNING)
152		return 0;
153
154	stack_page = (unsigned long)task_stack_page(p);
155	fp = ((struct hexagon_switch_stack *)p->thread.switch_sp)->fp;
156	do {
157		if (fp < (stack_page + sizeof(struct thread_info)) ||
158			fp >= (THREAD_SIZE - 8 + stack_page))
159			return 0;
160		pc = ((unsigned long *)fp)[1];
161		if (!in_sched_functions(pc))
162			return pc;
163		fp = *(unsigned long *) fp;
164	} while (count++ < 16);
165
166	return 0;
167}
168
169/*
170 * Required placeholder.
171 */
172int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
173{
174	return 0;
175}
176
177
178/*
179 * Called on the exit path of event entry; see vm_entry.S
180 *
181 * Interrupts will already be disabled.
182 *
183 * Returns 0 if there's no need to re-check for more work.
184 */
185
 
186int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
187{
188	if (!(thread_info_flags & _TIF_WORK_MASK)) {
189		return 0;
190	}  /* shortcut -- no work to be done */
191
192	local_irq_enable();
193
194	if (thread_info_flags & _TIF_NEED_RESCHED) {
195		schedule();
196		return 1;
197	}
198
199	if (thread_info_flags & _TIF_SIGPENDING) {
200		do_signal(regs);
201		return 1;
202	}
203
204	if (thread_info_flags & _TIF_NOTIFY_RESUME) {
205		clear_thread_flag(TIF_NOTIFY_RESUME);
206		tracehook_notify_resume(regs);
207		return 1;
208	}
209
210	/* Should not even reach here */
211	panic("%s: bad thread_info flags 0x%08x\n", __func__,
212		thread_info_flags);
213}
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * Process creation support for Hexagon
  4 *
  5 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  6 */
  7
  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>
 19
 20/*
 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.
 24 *
 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.
 28 */
 29void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
 30{
 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);
 37}
 38
 39/*
 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.
 43 */
 44void arch_cpu_idle(void)
 45{
 46	__vmwait();
 47	/*  interrupts wake us up, but irqs are still disabled */
 
 48}
 49
 50/*
 51 * Copy architecture-specific thread state
 52 */
 53int copy_thread(struct task_struct *p, const struct kernel_clone_args *args)
 
 54{
 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);
 62
 63	childregs = (struct pt_regs *) (((unsigned long) ti + THREAD_SIZE) -
 64					sizeof(*childregs));
 65
 66	ti->regs = childregs;
 67
 68	/*
 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.
 73	 */
 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;
 85	}
 86	memcpy(childregs, current_pt_regs(), sizeof(*childregs));
 87	ss->r2524 = 0;
 88
 89	if (usp)
 90		pt_set_rte_sp(childregs, usp);
 91
 92	/* Child sees zero return value */
 93	childregs->r00 = 0;
 94
 95	/*
 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.
103	 */
104	if (clone_flags & CLONE_SETTLS)
105		childregs->ugp = tls;
106
107	/*
108	 * Parent sees new pid -- not necessary, not even possible at
109	 * this point in the fork process
 
110	 */
111
112	return 0;
113}
114
115/*
 
 
 
 
 
 
 
116 * Some archs flush debug and FPU info here
117 */
118void flush_thread(void)
119{
120}
121
122/*
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.
126 */
127unsigned long __get_wchan(struct task_struct *p)
128{
129	unsigned long fp, pc;
130	unsigned long stack_page;
131	int count = 0;
 
 
132
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);
144
145	return 0;
146}
147
148/*
 
 
 
 
 
 
 
 
 
149 * Called on the exit path of event entry; see vm_entry.S
150 *
151 * Interrupts will already be disabled.
152 *
153 * Returns 0 if there's no need to re-check for more work.
154 */
155
156int do_work_pending(struct pt_regs *regs, u32 thread_info_flags);
157int do_work_pending(struct pt_regs *regs, u32 thread_info_flags)
158{
159	if (!(thread_info_flags & _TIF_WORK_MASK)) {
160		return 0;
161	}  /* shortcut -- no work to be done */
162
163	local_irq_enable();
164
165	if (thread_info_flags & _TIF_NEED_RESCHED) {
166		schedule();
167		return 1;
168	}
169
170	if (thread_info_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) {
171		do_signal(regs);
172		return 1;
173	}
174
175	if (thread_info_flags & _TIF_NOTIFY_RESUME) {
176		resume_user_mode_work(regs);
 
177		return 1;
178	}
179
180	/* Should not even reach here */
181	panic("%s: bad thread_info flags 0x%08x\n", __func__,
182		thread_info_flags);
183}