]>
Commit | Line | Data |
---|---|---|
1a59d1b8 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
1da177e4 LT |
2 | /* |
3 | * PARISC Architecture-dependent parts of process handling | |
4 | * based on the work for i386 | |
5 | * | |
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> | |
b2450cc1 | 13 | * Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org> |
1da177e4 LT |
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> | |
9dabf60d | 17 | * Copyright (C) 2001-2014 Helge Deller <deller@gmx.de> |
1da177e4 | 18 | * Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org> |
1da177e4 | 19 | */ |
1da177e4 LT |
20 | #include <linux/elf.h> |
21 | #include <linux/errno.h> | |
22 | #include <linux/kernel.h> | |
23 | #include <linux/mm.h> | |
4e950f6f | 24 | #include <linux/fs.h> |
310d8278 | 25 | #include <linux/cpu.h> |
1da177e4 LT |
26 | #include <linux/module.h> |
27 | #include <linux/personality.h> | |
28 | #include <linux/ptrace.h> | |
29 | #include <linux/sched.h> | |
b17b0153 | 30 | #include <linux/sched/debug.h> |
29930025 | 31 | #include <linux/sched/task.h> |
68db0cf1 | 32 | #include <linux/sched/task_stack.h> |
5a0e3ad6 | 33 | #include <linux/slab.h> |
1da177e4 LT |
34 | #include <linux/stddef.h> |
35 | #include <linux/unistd.h> | |
36 | #include <linux/kallsyms.h> | |
b609308e | 37 | #include <linux/uaccess.h> |
fbe75218 | 38 | #include <linux/rcupdate.h> |
9dabf60d | 39 | #include <linux/random.h> |
56188832 | 40 | #include <linux/nmi.h> |
1da177e4 LT |
41 | |
42 | #include <asm/io.h> | |
0013a854 | 43 | #include <asm/asm-offsets.h> |
ff0ab8af | 44 | #include <asm/assembly.h> |
1da177e4 LT |
45 | #include <asm/pdc.h> |
46 | #include <asm/pdc_chassis.h> | |
1da177e4 | 47 | #include <asm/unwind.h> |
b609308e | 48 | #include <asm/sections.h> |
1da177e4 | 49 | |
10992092 | 50 | #define COMMAND_GLOBAL F_EXTEND(0xfffe0030) |
1da177e4 LT |
51 | #define CMD_RESET 5 /* reset any module */ |
52 | ||
53 | /* | |
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. | |
59 | ** | |
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). | |
64 | */ | |
65 | void machine_restart(char *cmd) | |
66 | { | |
67 | #ifdef FASTBOOT_SELFTEST_SUPPORT | |
68 | /* | |
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. | |
72 | ** | |
73 | ** ftc_bitmap = 0x1AUL "Skip destructive memory tests" | |
74 | ** | |
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) | |
78 | */ | |
79 | if (ftc_bitmap) { | |
80 | pdc_do_firm_test_reset(ftc_bitmap); | |
81 | } | |
82 | #endif | |
83 | /* set up a new led state on systems shipped with a LED State panel */ | |
84 | pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN); | |
85 | ||
86 | /* "Normal" system reset */ | |
87 | pdc_do_reset(); | |
88 | ||
89 | /* Nope...box should reset with just CMD_RESET now */ | |
90 | gsc_writel(CMD_RESET, COMMAND_GLOBAL); | |
91 | ||
92 | /* Wait for RESET to lay us to rest. */ | |
93 | while (1) ; | |
94 | ||
95 | } | |
96 | ||
85509c00 | 97 | void (*chassis_power_off)(void); |
1da177e4 LT |
98 | |
99 | /* | |
100 | * This routine is called from sys_reboot to actually turn off the | |
101 | * machine | |
102 | */ | |
103 | void machine_power_off(void) | |
104 | { | |
105 | /* If there is a registered power off handler, call it. */ | |
85509c00 KM |
106 | if (chassis_power_off) |
107 | chassis_power_off(); | |
1da177e4 LT |
108 | |
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); | |
113 | ||
114 | pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN); | |
24002d59 HD |
115 | |
116 | /* ipmi_poweroff may have been installed. */ | |
117 | if (pm_power_off) | |
118 | pm_power_off(); | |
1da177e4 LT |
119 | |
120 | /* It seems we have no way to power the system off via | |
121 | * software. The user has to press the button himself. */ | |
122 | ||
123 | printk(KERN_EMERG "System shut down completed.\n" | |
ad361c98 | 124 | "Please power this system off now."); |
73580dac | 125 | |
476e75a4 HD |
126 | /* prevent soft lockup/stalled CPU messages for endless loop. */ |
127 | rcu_sysrq_start(); | |
47bb4baf | 128 | lockup_detector_soft_poweroff(); |
73580dac | 129 | for (;;); |
1da177e4 LT |
130 | } |
131 | ||
24002d59 | 132 | void (*pm_power_off)(void); |
85509c00 | 133 | EXPORT_SYMBOL(pm_power_off); |
1da177e4 | 134 | |
67698287 HD |
135 | void machine_halt(void) |
136 | { | |
137 | machine_power_off(); | |
138 | } | |
139 | ||
1da177e4 LT |
140 | void flush_thread(void) |
141 | { | |
142 | /* Only needs to handle fpu stuff or perf monitors. | |
143 | ** REVISIT: several arches implement a "lazy fpu state". | |
144 | */ | |
1da177e4 LT |
145 | } |
146 | ||
147 | void release_thread(struct task_struct *dead_task) | |
148 | { | |
149 | } | |
150 | ||
310d8278 HD |
151 | /* |
152 | * Idle thread support | |
153 | * | |
154 | * Detect when running on QEMU with SeaBIOS PDC Firmware and let | |
155 | * QEMU idle the host too. | |
156 | */ | |
157 | ||
7e4c65bf | 158 | int running_on_qemu __ro_after_init; |
3e1120f4 | 159 | EXPORT_SYMBOL(running_on_qemu); |
310d8278 HD |
160 | |
161 | void __cpuidle arch_cpu_idle_dead(void) | |
162 | { | |
163 | /* nop on real hardware, qemu will offline CPU. */ | |
164 | asm volatile("or %%r31,%%r31,%%r31\n":::); | |
165 | } | |
166 | ||
167 | void __cpuidle arch_cpu_idle(void) | |
168 | { | |
58c644ba | 169 | raw_local_irq_enable(); |
310d8278 HD |
170 | |
171 | /* nop on real hardware, qemu will idle sleep. */ | |
172 | asm volatile("or %%r10,%%r10,%%r10\n":::); | |
173 | } | |
174 | ||
175 | static int __init parisc_idle_init(void) | |
176 | { | |
310d8278 HD |
177 | if (!running_on_qemu) |
178 | cpu_idle_poll_ctrl(1); | |
179 | ||
180 | return 0; | |
181 | } | |
182 | arch_initcall(parisc_idle_init); | |
183 | ||
5fec97d0 AD |
184 | /* |
185 | * Copy architecture-specific thread state | |
186 | */ | |
1da177e4 | 187 | int |
714acdbd | 188 | copy_thread(unsigned long clone_flags, unsigned long usp, |
d2f36c78 | 189 | unsigned long kthread_arg, struct task_struct *p, unsigned long tls) |
1da177e4 | 190 | { |
afa86fc4 | 191 | struct pt_regs *cregs = &(p->thread.regs); |
40f1f0de | 192 | void *stack = task_stack_page(p); |
1da177e4 LT |
193 | |
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; | |
c78c2b7e | 199 | |
0100e6bb | 200 | if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) { |
5fec97d0 | 201 | /* kernel thread */ |
a44e060f | 202 | memset(cregs, 0, sizeof(struct pt_regs)); |
ff0ab8af AV |
203 | if (!usp) /* idle thread */ |
204 | return 0; | |
1da177e4 LT |
205 | /* Must exit via ret_from_kernel_thread in order |
206 | * to call schedule_tail() | |
207 | */ | |
ff0ab8af | 208 | cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE; |
1da177e4 LT |
209 | cregs->kpc = (unsigned long) &ret_from_kernel_thread; |
210 | /* | |
211 | * Copy function and argument to be called from | |
212 | * ret_from_kernel_thread. | |
213 | */ | |
a8f44e38 | 214 | #ifdef CONFIG_64BIT |
a44e060f AV |
215 | cregs->gr[27] = ((unsigned long *)usp)[3]; |
216 | cregs->gr[26] = ((unsigned long *)usp)[2]; | |
217 | #else | |
218 | cregs->gr[26] = usp; | |
1da177e4 | 219 | #endif |
5fec97d0 | 220 | cregs->gr[25] = kthread_arg; |
1da177e4 LT |
221 | } else { |
222 | /* user thread */ | |
415bfae9 AV |
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) */ | |
226 | if (usp) { | |
227 | usp = ALIGN(usp, 4); | |
228 | if (likely(usp)) | |
229 | cregs->gr[30] = usp; | |
230 | } | |
ff0ab8af | 231 | cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE; |
c78c2b7e HD |
232 | cregs->kpc = (unsigned long) &child_return; |
233 | ||
d2f36c78 | 234 | /* Setup thread TLS area */ |
b2450cc1 | 235 | if (clone_flags & CLONE_SETTLS) |
d2f36c78 | 236 | cregs->cr27 = tls; |
1da177e4 LT |
237 | } |
238 | ||
239 | return 0; | |
240 | } | |
241 | ||
3db03b4a | 242 | unsigned long |
1da177e4 LT |
243 | get_wchan(struct task_struct *p) |
244 | { | |
245 | struct unwind_frame_info info; | |
246 | unsigned long ip; | |
247 | int count = 0; | |
cc650a7a | 248 | |
b03fbd4f | 249 | if (!p || p == current || task_is_running(p)) |
cc650a7a KM |
250 | return 0; |
251 | ||
1da177e4 LT |
252 | /* |
253 | * These bracket the sleeping functions.. | |
254 | */ | |
255 | ||
256 | unwind_frame_init_from_blocked_task(&info, p); | |
257 | do { | |
258 | if (unwind_once(&info) < 0) | |
259 | return 0; | |
b03fbd4f | 260 | if (task_is_running(p)) |
f2863032 | 261 | return 0; |
1da177e4 LT |
262 | ip = info.ip; |
263 | if (!in_sched_functions(ip)) | |
264 | return ip; | |
c8921d72 | 265 | } while (count++ < MAX_UNWIND_ENTRIES); |
1da177e4 LT |
266 | return 0; |
267 | } | |
b609308e KM |
268 | |
269 | #ifdef CONFIG_64BIT | |
270 | void *dereference_function_descriptor(void *ptr) | |
271 | { | |
272 | Elf64_Fdesc *desc = ptr; | |
273 | void *p; | |
274 | ||
0c389d89 | 275 | if (!get_kernel_nofault(p, (void *)&desc->addr)) |
b609308e KM |
276 | ptr = p; |
277 | return ptr; | |
278 | } | |
1705bd6a SS |
279 | |
280 | void *dereference_kernel_function_descriptor(void *ptr) | |
281 | { | |
282 | if (ptr < (void *)__start_opd || | |
283 | ptr >= (void *)__end_opd) | |
284 | return ptr; | |
285 | ||
286 | return dereference_function_descriptor(ptr); | |
287 | } | |
b609308e | 288 | #endif |
9dabf60d HD |
289 | |
290 | static inline unsigned long brk_rnd(void) | |
291 | { | |
18d98a79 | 292 | return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT; |
9dabf60d HD |
293 | } |
294 | ||
295 | unsigned long arch_randomize_brk(struct mm_struct *mm) | |
296 | { | |
297 | unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd()); | |
298 | ||
299 | if (ret < mm->brk) | |
300 | return mm->brk; | |
301 | return ret; | |
302 | } |