1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * PARISC Architecture-dependent parts of process handling
4 * based on the work for i386
6 * Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>
7 * Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>
8 * Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>
9 * Copyright (C) 2000 David Huggins-Daines <dhd with pobox.org>
10 * Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>
11 * Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>
12 * Copyright (C) 2000 David Kennedy <dkennedy with linuxcare.com>
13 * Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org>
14 * Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>
15 * Copyright (C) 2001 Alan Modra <amodra at parisc-linux.org>
16 * Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>
17 * Copyright (C) 2001-2014 Helge Deller <deller@gmx.de>
18 * Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>
20 #include <linux/elf.h>
21 #include <linux/errno.h>
22 #include <linux/kernel.h>
25 #include <linux/cpu.h>
26 #include <linux/module.h>
27 #include <linux/personality.h>
28 #include <linux/ptrace.h>
29 #include <linux/sched.h>
30 #include <linux/sched/debug.h>
31 #include <linux/sched/task.h>
32 #include <linux/sched/task_stack.h>
33 #include <linux/slab.h>
34 #include <linux/stddef.h>
35 #include <linux/unistd.h>
36 #include <linux/kallsyms.h>
37 #include <linux/uaccess.h>
38 #include <linux/rcupdate.h>
39 #include <linux/random.h>
40 #include <linux/nmi.h>
43 #include <asm/asm-offsets.h>
44 #include <asm/assembly.h>
46 #include <asm/pdc_chassis.h>
47 #include <asm/unwind.h>
48 #include <asm/sections.h>
50 #define COMMAND_GLOBAL F_EXTEND(0xfffe0030)
51 #define CMD_RESET 5 /* reset any module */
54 ** The Wright Brothers and Gecko systems have a H/W problem
55 ** (Lasi...'nuf said) may cause a broadcast reset to lockup
56 ** the system. An HVERSION dependent PDC call was developed
57 ** to perform a "safe", platform specific broadcast reset instead
58 ** of kludging up all the code.
60 ** Older machines which do not implement PDC_BROADCAST_RESET will
61 ** return (with an error) and the regular broadcast reset can be
62 ** issued. Obviously, if the PDC does implement PDC_BROADCAST_RESET
63 ** the PDC call will not return (the system will be reset).
65 void machine_restart(char *cmd)
67 #ifdef FASTBOOT_SELFTEST_SUPPORT
69 ** If user has modified the Firmware Selftest Bitmap,
70 ** run the tests specified in the bitmap after the
71 ** system is rebooted w/PDC_DO_RESET.
73 ** ftc_bitmap = 0x1AUL "Skip destructive memory tests"
75 ** Using "directed resets" at each processor with the MEM_TOC
76 ** vector cleared will also avoid running destructive
77 ** memory self tests. (Not implemented yet)
80 pdc_do_firm_test_reset(ftc_bitmap);
83 /* set up a new led state on systems shipped with a LED State panel */
84 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
86 /* "Normal" system reset */
89 /* Nope...box should reset with just CMD_RESET now */
90 gsc_writel(CMD_RESET, COMMAND_GLOBAL);
92 /* Wait for RESET to lay us to rest. */
97 void (*chassis_power_off)(void);
100 * This routine is called from sys_reboot to actually turn off the
103 void machine_power_off(void)
105 /* If there is a registered power off handler, call it. */
106 if (chassis_power_off)
109 /* Put the soft power button back under hardware control.
110 * If the user had already pressed the power button, the
111 * following call will immediately power off. */
112 pdc_soft_power_button(0);
114 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
116 /* ipmi_poweroff may have been installed. */
120 /* It seems we have no way to power the system off via
121 * software. The user has to press the button himself. */
123 printk(KERN_EMERG "System shut down completed.\n"
124 "Please power this system off now.");
126 /* prevent soft lockup/stalled CPU messages for endless loop. */
128 lockup_detector_soft_poweroff();
132 void (*pm_power_off)(void);
133 EXPORT_SYMBOL(pm_power_off);
135 void machine_halt(void)
140 void flush_thread(void)
142 /* Only needs to handle fpu stuff or perf monitors.
143 ** REVISIT: several arches implement a "lazy fpu state".
147 void release_thread(struct task_struct *dead_task)
152 * Idle thread support
154 * Detect when running on QEMU with SeaBIOS PDC Firmware and let
155 * QEMU idle the host too.
158 int running_on_qemu __ro_after_init;
159 EXPORT_SYMBOL(running_on_qemu);
161 void __cpuidle arch_cpu_idle_dead(void)
163 /* nop on real hardware, qemu will offline CPU. */
164 asm volatile("or %%r31,%%r31,%%r31\n":::);
167 void __cpuidle arch_cpu_idle(void)
169 raw_local_irq_enable();
171 /* nop on real hardware, qemu will idle sleep. */
172 asm volatile("or %%r10,%%r10,%%r10\n":::);
175 static int __init parisc_idle_init(void)
177 if (!running_on_qemu)
178 cpu_idle_poll_ctrl(1);
182 arch_initcall(parisc_idle_init);
185 * Copy architecture-specific thread state
188 copy_thread(unsigned long clone_flags, unsigned long usp,
189 unsigned long kthread_arg, struct task_struct *p, unsigned long tls)
191 struct pt_regs *cregs = &(p->thread.regs);
192 void *stack = task_stack_page(p);
194 /* We have to use void * instead of a function pointer, because
195 * function pointers aren't a pointer to the function on 64-bit.
196 * Make them const so the compiler knows they live in .text */
197 extern void * const ret_from_kernel_thread;
198 extern void * const child_return;
200 if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
202 memset(cregs, 0, sizeof(struct pt_regs));
203 if (!usp) /* idle thread */
205 /* Must exit via ret_from_kernel_thread in order
206 * to call schedule_tail()
208 cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
209 cregs->kpc = (unsigned long) &ret_from_kernel_thread;
211 * Copy function and argument to be called from
212 * ret_from_kernel_thread.
215 cregs->gr[27] = ((unsigned long *)usp)[3];
216 cregs->gr[26] = ((unsigned long *)usp)[2];
220 cregs->gr[25] = kthread_arg;
223 /* usp must be word aligned. This also prevents users from
224 * passing in the value 1 (which is the signal for a special
225 * return for a kernel thread) */
231 cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
232 cregs->kpc = (unsigned long) &child_return;
234 /* Setup thread TLS area */
235 if (clone_flags & CLONE_SETTLS)
243 get_wchan(struct task_struct *p)
245 struct unwind_frame_info info;
249 if (!p || p == current || task_is_running(p))
253 * These bracket the sleeping functions..
256 unwind_frame_init_from_blocked_task(&info, p);
258 if (unwind_once(&info) < 0)
260 if (task_is_running(p))
263 if (!in_sched_functions(ip))
265 } while (count++ < MAX_UNWIND_ENTRIES);
270 void *dereference_function_descriptor(void *ptr)
272 Elf64_Fdesc *desc = ptr;
275 if (!get_kernel_nofault(p, (void *)&desc->addr))
280 void *dereference_kernel_function_descriptor(void *ptr)
282 if (ptr < (void *)__start_opd ||
283 ptr >= (void *)__end_opd)
286 return dereference_function_descriptor(ptr);
290 static inline unsigned long brk_rnd(void)
292 return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT;
295 unsigned long arch_randomize_brk(struct mm_struct *mm)
297 unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());