1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include <stdarg.h>
22
23#include <linux/elf.h>
24#include <linux/errno.h>
25#include <linux/kernel.h>
26#include <linux/mm.h>
27#include <linux/fs.h>
28#include <linux/cpu.h>
29#include <linux/module.h>
30#include <linux/personality.h>
31#include <linux/ptrace.h>
32#include <linux/sched.h>
33#include <linux/sched/debug.h>
34#include <linux/sched/task.h>
35#include <linux/sched/task_stack.h>
36#include <linux/slab.h>
37#include <linux/stddef.h>
38#include <linux/unistd.h>
39#include <linux/kallsyms.h>
40#include <linux/uaccess.h>
41#include <linux/rcupdate.h>
42#include <linux/random.h>
43#include <linux/nmi.h>
44
45#include <asm/io.h>
46#include <asm/asm-offsets.h>
47#include <asm/assembly.h>
48#include <asm/pdc.h>
49#include <asm/pdc_chassis.h>
50#include <asm/unwind.h>
51#include <asm/sections.h>
52
53#define COMMAND_GLOBAL F_EXTEND(0xfffe0030)
54#define CMD_RESET 5
55
56
57
58
59
60
61
62
63
64
65
66
67
68void machine_restart(char *cmd)
69{
70#ifdef FASTBOOT_SELFTEST_SUPPORT
71
72
73
74
75
76
77
78
79
80
81
82 if (ftc_bitmap) {
83 pdc_do_firm_test_reset(ftc_bitmap);
84 }
85#endif
86
87 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
88
89
90 pdc_do_reset();
91
92
93 gsc_writel(CMD_RESET, COMMAND_GLOBAL);
94
95
96 while (1) ;
97
98}
99
100void (*chassis_power_off)(void);
101
102
103
104
105
106void machine_power_off(void)
107{
108
109 if (chassis_power_off)
110 chassis_power_off();
111
112
113
114
115 pdc_soft_power_button(0);
116
117 pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);
118
119
120 if (pm_power_off)
121 pm_power_off();
122
123
124
125
126 printk(KERN_EMERG "System shut down completed.\n"
127 "Please power this system off now.");
128
129
130 rcu_sysrq_start();
131 lockup_detector_soft_poweroff();
132 for (;;);
133}
134
135void (*pm_power_off)(void);
136EXPORT_SYMBOL(pm_power_off);
137
138void machine_halt(void)
139{
140 machine_power_off();
141}
142
143void flush_thread(void)
144{
145
146
147
148}
149
150void release_thread(struct task_struct *dead_task)
151{
152}
153
154
155
156
157
158
159
160
161int running_on_qemu __ro_after_init;
162EXPORT_SYMBOL(running_on_qemu);
163
164void __cpuidle arch_cpu_idle_dead(void)
165{
166
167 asm volatile("or %%r31,%%r31,%%r31\n":::);
168}
169
170void __cpuidle arch_cpu_idle(void)
171{
172 raw_local_irq_enable();
173
174
175 asm volatile("or %%r10,%%r10,%%r10\n":::);
176}
177
178static int __init parisc_idle_init(void)
179{
180 if (!running_on_qemu)
181 cpu_idle_poll_ctrl(1);
182
183 return 0;
184}
185arch_initcall(parisc_idle_init);
186
187
188
189
190int
191copy_thread(unsigned long clone_flags, unsigned long usp,
192 unsigned long kthread_arg, struct task_struct *p, unsigned long tls)
193{
194 struct pt_regs *cregs = &(p->thread.regs);
195 void *stack = task_stack_page(p);
196
197
198
199
200 extern void * const ret_from_kernel_thread;
201 extern void * const child_return;
202
203 if (unlikely(p->flags & (PF_KTHREAD | PF_IO_WORKER))) {
204
205 memset(cregs, 0, sizeof(struct pt_regs));
206 if (!usp)
207 return 0;
208
209
210
211 cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
212 cregs->kpc = (unsigned long) &ret_from_kernel_thread;
213
214
215
216
217#ifdef CONFIG_64BIT
218 cregs->gr[27] = ((unsigned long *)usp)[3];
219 cregs->gr[26] = ((unsigned long *)usp)[2];
220#else
221 cregs->gr[26] = usp;
222#endif
223 cregs->gr[25] = kthread_arg;
224 } else {
225
226
227
228
229 if (usp) {
230 usp = ALIGN(usp, 4);
231 if (likely(usp))
232 cregs->gr[30] = usp;
233 }
234 cregs->ksp = (unsigned long)stack + THREAD_SZ_ALGN + FRAME_SIZE;
235 cregs->kpc = (unsigned long) &child_return;
236
237
238 if (clone_flags & CLONE_SETTLS)
239 cregs->cr27 = tls;
240 }
241
242 return 0;
243}
244
245unsigned long
246get_wchan(struct task_struct *p)
247{
248 struct unwind_frame_info info;
249 unsigned long ip;
250 int count = 0;
251
252 if (!p || p == current || task_is_running(p))
253 return 0;
254
255
256
257
258
259 unwind_frame_init_from_blocked_task(&info, p);
260 do {
261 if (unwind_once(&info) < 0)
262 return 0;
263 if (task_is_running(p))
264 return 0;
265 ip = info.ip;
266 if (!in_sched_functions(ip))
267 return ip;
268 } while (count++ < MAX_UNWIND_ENTRIES);
269 return 0;
270}
271
272#ifdef CONFIG_64BIT
273void *dereference_function_descriptor(void *ptr)
274{
275 Elf64_Fdesc *desc = ptr;
276 void *p;
277
278 if (!get_kernel_nofault(p, (void *)&desc->addr))
279 ptr = p;
280 return ptr;
281}
282
283void *dereference_kernel_function_descriptor(void *ptr)
284{
285 if (ptr < (void *)__start_opd ||
286 ptr >= (void *)__end_opd)
287 return ptr;
288
289 return dereference_function_descriptor(ptr);
290}
291#endif
292
293static inline unsigned long brk_rnd(void)
294{
295 return (get_random_int() & BRK_RND_MASK) << PAGE_SHIFT;
296}
297
298unsigned long arch_randomize_brk(struct mm_struct *mm)
299{
300 unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
301
302 if (ret < mm->brk)
303 return mm->brk;
304 return ret;
305}
306