Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*  linux/arch/sparc/kernel/process.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 1996 Eddie C. Dost   (ecd@skynet.be)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This file handles the architecture-dependent parts of process handling..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/elfcore.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/reboot.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <asm/auxio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <asm/oplib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <asm/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <asm/psr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <asm/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <asm/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include "kernel.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) /* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  * Power management idle function 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49)  * Set in pm platform drivers (apc.c and pmc.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) void (*sparc_idle)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /* 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * Power-off handler instantiation for pm.h compliance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * This is done via auxio, but could be used as a fallback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * handler when auxio is not present-- unused for now...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) void (*pm_power_off)(void) = machine_power_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) EXPORT_SYMBOL(pm_power_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  * sysctl - toggle power-off restriction for serial console 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)  * systems in machine_power_off()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) int scons_pwroff = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) extern void fpsave(unsigned long *, unsigned long *, void *, unsigned long *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) struct task_struct *last_task_used_math = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) struct thread_info *current_set[NR_CPUS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) /* Idle loop support. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) void arch_cpu_idle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (sparc_idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		(*sparc_idle)();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	raw_local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) /* XXX cli/sti -> local_irq_xxx here, check this works once SMP is fixed. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) void machine_halt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	mdelay(8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	prom_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	panic("Halt failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) void machine_restart(char * cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	mdelay(8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	p = strchr (reboot_command, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (p) *p = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	if (cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		prom_reboot(cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	if (*reboot_command)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		prom_reboot(reboot_command);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	prom_feval ("reset");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	panic("Reboot failed!");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void machine_power_off(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	if (auxio_power_register &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	    (!of_node_is_type(of_console_device, "serial") || scons_pwroff)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		u8 power_register = sbus_readb(auxio_power_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		power_register |= AUXIO_POWER_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		sbus_writeb(power_register, auxio_power_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	machine_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) void show_regs(struct pt_regs *r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	struct reg_window32 *rw = (struct reg_window32 *) r->u_regs[14];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	show_regs_print_info(KERN_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)         printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx    %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	       r->psr, r->pc, r->npc, r->y, print_tainted());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	printk("PC: <%pS>\n", (void *) r->pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	printk("%%G: %08lx %08lx  %08lx %08lx  %08lx %08lx  %08lx %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	       r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	       r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	printk("%%O: %08lx %08lx  %08lx %08lx  %08lx %08lx  %08lx %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	       r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	       r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	printk("%%L: %08lx %08lx  %08lx %08lx  %08lx %08lx  %08lx %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	       rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	       rw->locals[4], rw->locals[5], rw->locals[6], rw->locals[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	printk("%%I: %08lx %08lx  %08lx %08lx  %08lx %08lx  %08lx %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	       rw->ins[0], rw->ins[1], rw->ins[2], rw->ins[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	       rw->ins[4], rw->ins[5], rw->ins[6], rw->ins[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)  * The show_stack() is external API which we do not use ourselves.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)  * The oops is printed in die_if_kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) void show_stack(struct task_struct *tsk, unsigned long *_ksp, const char *loglvl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	unsigned long pc, fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	unsigned long task_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct reg_window32 *rw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	if (!tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		tsk = current;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	if (tsk == current && !_ksp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		__asm__ __volatile__("mov	%%fp, %0" : "=r" (_ksp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	task_base = (unsigned long) task_stack_page(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	fp = (unsigned long) _ksp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		/* Bogus frame pointer? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		if (fp < (task_base + sizeof(struct thread_info)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		    fp >= (task_base + (PAGE_SIZE << 1)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		rw = (struct reg_window32 *) fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		pc = rw->ins[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		printk("%s[%08lx : ", loglvl, pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		printk("%s%pS ] ", loglvl, (void *) pc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 		fp = rw->ins[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	} while (++count < 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	printk("%s\n", loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * Free current thread data structures etc..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) void exit_thread(struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	if (last_task_used_math == tsk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (test_ti_thread_flag(task_thread_info(tsk), TIF_USEDFPU)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		/* Keep process from leaving FPU in a bogon state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		put_psr(get_psr() | PSR_EF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		fpsave(&tsk->thread.float_regs[0], &tsk->thread.fsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		       &tsk->thread.fpqueue[0], &tsk->thread.fpqdepth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		last_task_used_math = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		clear_ti_thread_flag(task_thread_info(tsk), TIF_USEDFPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) void flush_thread(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	current_thread_info()->w_saved = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	if(last_task_used_math == current) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (test_thread_flag(TIF_USEDFPU)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		/* Clean the fpu. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		put_psr(get_psr() | PSR_EF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		fpsave(&current->thread.float_regs[0], &current->thread.fsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		       &current->thread.fpqueue[0], &current->thread.fpqdepth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		last_task_used_math = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		clear_thread_flag(TIF_USEDFPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	/* This task is no longer a kernel thread. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (current->thread.flags & SPARC_FLAG_KTHREAD) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		current->thread.flags &= ~SPARC_FLAG_KTHREAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		/* We must fixup kregs as well. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		/* XXX This was not fixed for ti for a while, worked. Unused? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		current->thread.kregs = (struct pt_regs *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		    (task_stack_page(current) + (THREAD_SIZE - TRACEREG_SZ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static inline struct sparc_stackf __user *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) clone_stackframe(struct sparc_stackf __user *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		 struct sparc_stackf __user *src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	unsigned long size, fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct sparc_stackf *tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct sparc_stackf __user *sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	if (get_user(tmp, &src->fp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	fp = (unsigned long) tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	size = (fp - ((unsigned long) src));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	fp = (unsigned long) dst;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	sp = (struct sparc_stackf __user *)(fp - size); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	/* do_fork() grabs the parent semaphore, we must release it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	 * temporarily so we can build the child clone stack frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	 * without deadlocking.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	if (__copy_user(sp, src, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 		sp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	else if (put_user(fp, &sp->fp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		sp = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	return sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) /* Copy a Sparc thread.  The fork() return value conventions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)  * under SunOS are nothing short of bletcherous:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)  * Parent -->  %o0 == childs  pid, %o1 == 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)  * Child  -->  %o0 == parents pid, %o1 == 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)  * NOTE: We have a separate fork kpsr/kwim because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)  *       the parent could change these values between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)  *       sys_fork invocation and when we reach here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)  *       if the parent should sleep while trying to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)  *       allocate the task_struct and kernel stack in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)  *       do_fork().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)  * XXX See comment above sys_vfork in sparc64. todo.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) extern void ret_from_fork(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) extern void ret_from_kernel_thread(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int copy_thread(unsigned long clone_flags, unsigned long sp, unsigned long arg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		struct task_struct *p, unsigned long tls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct thread_info *ti = task_thread_info(p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct pt_regs *childregs, *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	char *new_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) #ifndef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if(last_task_used_math == current) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	if (test_thread_flag(TIF_USEDFPU)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 		put_psr(get_psr() | PSR_EF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		fpsave(&p->thread.float_regs[0], &p->thread.fsr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		       &p->thread.fpqueue[0], &p->thread.fpqdepth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	 *  p->thread_info         new_stack   childregs stack bottom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	 *  !                      !           !             !
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	 *  V                      V (stk.fr.) V  (pt_regs)  V
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	 *  +----- - - - - - ------+===========+=============+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	new_stack = task_stack_page(p) + THREAD_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	new_stack -= STACKFRAME_SZ + TRACEREG_SZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	childregs = (struct pt_regs *) (new_stack + STACKFRAME_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	 * A new process must start with interrupts disabled, see schedule_tail()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	 * and finish_task_switch(). (If we do not do it and if a timer interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	 * hits before we unlock and attempts to take the rq->lock, we deadlock.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	 * Thus, kpsr |= PSR_PIL.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 	ti->ksp = (unsigned long) new_stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	p->thread.kregs = childregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	if (unlikely(p->flags & PF_KTHREAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 		extern int nwindows;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 		unsigned long psr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 		memset(new_stack, 0, STACKFRAME_SZ + TRACEREG_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 		p->thread.flags |= SPARC_FLAG_KTHREAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		p->thread.current_ds = KERNEL_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		ti->kpc = (((unsigned long) ret_from_kernel_thread) - 0x8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 		childregs->u_regs[UREG_G1] = sp; /* function */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 		childregs->u_regs[UREG_G2] = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		psr = childregs->psr = get_psr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 		ti->kpsr = psr | PSR_PIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		ti->kwim = 1 << (((psr & PSR_CWP) + 1) % nwindows);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	memcpy(new_stack, (char *)regs - STACKFRAME_SZ, STACKFRAME_SZ + TRACEREG_SZ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	childregs->u_regs[UREG_FP] = sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	p->thread.flags &= ~SPARC_FLAG_KTHREAD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 	p->thread.current_ds = USER_DS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	ti->kpc = (((unsigned long) ret_from_fork) - 0x8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	ti->kpsr = current->thread.fork_kpsr | PSR_PIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 	ti->kwim = current->thread.fork_kwim;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (sp != regs->u_regs[UREG_FP]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		struct sparc_stackf __user *childstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 		struct sparc_stackf __user *parentstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		 * This is a clone() call with supplied user stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 		 * Set some valid stack frames to give to the child.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		childstack = (struct sparc_stackf __user *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 			(sp & ~0xfUL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 		parentstack = (struct sparc_stackf __user *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 			regs->u_regs[UREG_FP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		printk("clone: parent stack:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 		show_stackframe(parentstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		childstack = clone_stackframe(childstack, parentstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		if (!childstack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 		printk("clone: child stack:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 		show_stackframe(childstack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		childregs->u_regs[UREG_FP] = (unsigned long)childstack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 	/* FPU must be disabled on SMP. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	childregs->psr &= ~PSR_EF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	clear_tsk_thread_flag(p, TIF_USEDFPU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	/* Set the return value for the child. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	childregs->u_regs[UREG_I0] = current->pid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	childregs->u_regs[UREG_I1] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	/* Set the return value for the parent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	regs->u_regs[UREG_I1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	if (clone_flags & CLONE_SETTLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 		childregs->u_regs[UREG_G7] = tls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) unsigned long get_wchan(struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	unsigned long pc, fp, bias = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 	unsigned long task_base = (unsigned long) task;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)         unsigned long ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	struct reg_window32 *rw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	if (!task || task == current ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)             task->state == TASK_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	fp = task_thread_info(task)->ksp + bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 		/* Bogus frame pointer? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		if (fp < (task_base + sizeof(struct thread_info)) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		    fp >= (task_base + (2 * PAGE_SIZE)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		rw = (struct reg_window32 *) fp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 		pc = rw->ins[7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		if (!in_sched_functions(pc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 			ret = pc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 		fp = rw->ins[6] + bias;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	} while (++count < 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)