process.c 8.2 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11
/*
 *    PARISC Architecture-dependent parts of process handling
 *    based on the work for i386
 *
 *    Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
 *    Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>
 *    Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>
 *    Copyright (C) 2000 David Huggins-Daines <dhd with pobox.org>
 *    Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
 *    Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>
 *    Copyright (C) 2000 David Kennedy <dkennedy with linuxcare.com>
12
 *    Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org>
L
Linus Torvalds 已提交
13 14 15
 *    Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>
 *    Copyright (C) 2001 Alan Modra <amodra at parisc-linux.org>
 *    Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>
16
 *    Copyright (C) 2001-2007 Helge Deller <deller at parisc-linux.org>
L
Linus Torvalds 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
 *    Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>
 *
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with this program; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <stdarg.h>

#include <linux/elf.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/mm.h>
A
Alexey Dobriyan 已提交
41
#include <linux/fs.h>
L
Linus Torvalds 已提交
42 43 44 45
#include <linux/module.h>
#include <linux/personality.h>
#include <linux/ptrace.h>
#include <linux/sched.h>
46
#include <linux/slab.h>
L
Linus Torvalds 已提交
47 48 49
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/kallsyms.h>
50
#include <linux/uaccess.h>
51
#include <linux/rcupdate.h>
L
Linus Torvalds 已提交
52 53

#include <asm/io.h>
54
#include <asm/asm-offsets.h>
55
#include <asm/assembly.h>
L
Linus Torvalds 已提交
56 57 58 59
#include <asm/pdc.h>
#include <asm/pdc_chassis.h>
#include <asm/pgalloc.h>
#include <asm/unwind.h>
60
#include <asm/sections.h>
L
Linus Torvalds 已提交
61 62 63 64 65 66 67 68 69

/*
 * The idle thread. There's no useful work to be
 * done, so just try to conserve power and have a
 * low exit latency (ie sit in a loop waiting for
 * somebody to say that they'd like to reschedule)
 */
void cpu_idle(void)
{
70 71
	set_thread_flag(TIF_POLLING_NRFLAG);

L
Linus Torvalds 已提交
72 73
	/* endless idle loop with no priority at all */
	while (1) {
74
		rcu_idle_enter();
L
Linus Torvalds 已提交
75 76
		while (!need_resched())
			barrier();
77
		rcu_idle_exit();
78
		schedule_preempt_disabled();
L
Linus Torvalds 已提交
79 80 81 82 83
		check_pgt_cache();
	}
}


84
#define COMMAND_GLOBAL  F_EXTEND(0xfffe0030)
L
Linus Torvalds 已提交
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
#define CMD_RESET       5       /* reset any module */

/*
** The Wright Brothers and Gecko systems have a H/W problem
** (Lasi...'nuf said) may cause a broadcast reset to lockup
** the system. An HVERSION dependent PDC call was developed
** to perform a "safe", platform specific broadcast reset instead
** of kludging up all the code.
**
** Older machines which do not implement PDC_BROADCAST_RESET will
** return (with an error) and the regular broadcast reset can be
** issued. Obviously, if the PDC does implement PDC_BROADCAST_RESET
** the PDC call will not return (the system will be reset).
*/
void machine_restart(char *cmd)
{
#ifdef FASTBOOT_SELFTEST_SUPPORT
	/*
	 ** If user has modified the Firmware Selftest Bitmap,
	 ** run the tests specified in the bitmap after the
	 ** system is rebooted w/PDC_DO_RESET.
	 **
	 ** ftc_bitmap = 0x1AUL "Skip destructive memory tests"
	 **
	 ** Using "directed resets" at each processor with the MEM_TOC
	 ** vector cleared will also avoid running destructive
	 ** memory self tests. (Not implemented yet)
	 */
	if (ftc_bitmap) {
		pdc_do_firm_test_reset(ftc_bitmap);
	}
#endif
	/* set up a new led state on systems shipped with a LED State panel */
	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
	
	/* "Normal" system reset */
	pdc_do_reset();

	/* Nope...box should reset with just CMD_RESET now */
	gsc_writel(CMD_RESET, COMMAND_GLOBAL);

	/* Wait for RESET to lay us to rest. */
	while (1) ;

}

void machine_halt(void)
{
	/*
	** The LED/ChassisCodes are updated by the led_halt()
	** function, called by the reboot notifier chain.
	*/
}

139
void (*chassis_power_off)(void);
L
Linus Torvalds 已提交
140 141 142 143 144 145 146 147

/*
 * This routine is called from sys_reboot to actually turn off the
 * machine 
 */
void machine_power_off(void)
{
	/* If there is a registered power off handler, call it. */
148 149
	if (chassis_power_off)
		chassis_power_off();
L
Linus Torvalds 已提交
150 151 152 153 154 155 156 157 158 159 160 161

	/* Put the soft power button back under hardware control.
	 * If the user had already pressed the power button, the
	 * following call will immediately power off. */
	pdc_soft_power_button(0);
	
	pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
		
	/* It seems we have no way to power the system off via
	 * software. The user has to press the button himself. */

	printk(KERN_EMERG "System shut down completed.\n"
162
	       "Please power this system off now.");
L
Linus Torvalds 已提交
163 164
}

165 166
void (*pm_power_off)(void) = machine_power_off;
EXPORT_SYMBOL(pm_power_off);
L
Linus Torvalds 已提交
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205

/*
 * Free current thread data structures etc..
 */
void exit_thread(void)
{
}

void flush_thread(void)
{
	/* Only needs to handle fpu stuff or perf monitors.
	** REVISIT: several arches implement a "lazy fpu state".
	*/
}

void release_thread(struct task_struct *dead_task)
{
}

/*
 * Fill in the FPU structure for a core dump.
 */

int dump_fpu (struct pt_regs * regs, elf_fpregset_t *r)
{
	if (regs == NULL)
		return 0;

	memcpy(r, regs->fr, sizeof *r);
	return 1;
}

int dump_task_fpu (struct task_struct *tsk, elf_fpregset_t *r)
{
	memcpy(r, tsk->thread.regs.fr, sizeof(*r));
	return 1;
}

int
A
Alexey Dobriyan 已提交
206
copy_thread(unsigned long clone_flags, unsigned long usp,
207
	    unsigned long arg,
208
	    struct task_struct *p, struct pt_regs *unused)
L
Linus Torvalds 已提交
209 210
{
	struct pt_regs * cregs = &(p->thread.regs);
211
	void *stack = task_stack_page(p);
L
Linus Torvalds 已提交
212 213 214 215 216 217 218 219 220
	
	/* We have to use void * instead of a function pointer, because
	 * function pointers aren't a pointer to the function on 64-bit.
	 * Make them const so the compiler knows they live in .text */
	extern void * const ret_from_kernel_thread;
	extern void * const child_return;
#ifdef CONFIG_HPUX
	extern void * const hpux_child_return;
#endif
221
	if (unlikely(p->flags & PF_KTHREAD)) {
222
		memset(cregs, 0, sizeof(struct pt_regs));
223 224 225
		if (!usp) /* idle thread */
			return 0;

L
Linus Torvalds 已提交
226 227 228 229
		/* kernel thread */
		/* Must exit via ret_from_kernel_thread in order
		 * to call schedule_tail()
		 */
230
		cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
L
Linus Torvalds 已提交
231 232 233 234 235
		cregs->kpc = (unsigned long) &ret_from_kernel_thread;
		/*
		 * Copy function and argument to be called from
		 * ret_from_kernel_thread.
		 */
236
#ifdef CONFIG_64BIT
237 238 239 240
		cregs->gr[27] = ((unsigned long *)usp)[3];
		cregs->gr[26] = ((unsigned long *)usp)[2];
#else
		cregs->gr[26] = usp;
L
Linus Torvalds 已提交
241
#endif
242
		cregs->gr[25] = arg;
L
Linus Torvalds 已提交
243 244
	} else {
		/* user thread */
245 246 247 248 249 250 251 252
		/* usp must be word aligned.  This also prevents users from
		 * passing in the value 1 (which is the signal for a special
		 * return for a kernel thread) */
		if (usp) {
			usp = ALIGN(usp, 4);
			if (likely(usp))
				cregs->gr[30] = usp;
		}
253
		cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
254
		if (personality(p->personality) == PER_HPUX) {
L
Linus Torvalds 已提交
255 256 257 258 259 260 261 262
#ifdef CONFIG_HPUX
			cregs->kpc = (unsigned long) &hpux_child_return;
#else
			BUG();
#endif
		} else {
			cregs->kpc = (unsigned long) &child_return;
		}
263 264
		/* Setup thread TLS area from the 4th parameter in clone */
		if (clone_flags & CLONE_SETTLS)
265
			cregs->cr27 = cregs->gr[23];
L
Linus Torvalds 已提交
266 267 268 269 270 271 272 273 274 275
	}

	return 0;
}

unsigned long thread_saved_pc(struct task_struct *t)
{
	return t->thread.regs.kpc;
}

276
unsigned long
L
Linus Torvalds 已提交
277 278 279 280 281
get_wchan(struct task_struct *p)
{
	struct unwind_frame_info info;
	unsigned long ip;
	int count = 0;
282 283 284 285

	if (!p || p == current || p->state == TASK_RUNNING)
		return 0;

L
Linus Torvalds 已提交
286 287 288 289 290 291 292 293 294 295 296 297 298 299
	/*
	 * These bracket the sleeping functions..
	 */

	unwind_frame_init_from_blocked_task(&info, p);
	do {
		if (unwind_once(&info) < 0)
			return 0;
		ip = info.ip;
		if (!in_sched_functions(ip))
			return ip;
	} while (count++ < 16);
	return 0;
}
300 301 302 303 304 305 306 307 308 309 310 311

#ifdef CONFIG_64BIT
void *dereference_function_descriptor(void *ptr)
{
	Elf64_Fdesc *desc = ptr;
	void *p;

	if (!probe_kernel_address(&desc->addr, p))
		ptr = p;
	return ptr;
}
#endif