1 | /* |
---|
2 | * Architecture-specific setup. |
---|
3 | * |
---|
4 | * Copyright (C) 1998-2003 Hewlett-Packard Co |
---|
5 | * David Mosberger-Tang <davidm@hpl.hp.com> |
---|
6 | * 04/11/17 Ashok Raj <ashok.raj@intel.com> Added CPU Hotplug Support |
---|
7 | */ |
---|
8 | #ifdef XEN |
---|
9 | #include <xen/types.h> |
---|
10 | #include <xen/lib.h> |
---|
11 | #include <xen/symbols.h> |
---|
12 | #include <xen/smp.h> |
---|
13 | #include <xen/sched.h> |
---|
14 | #include <asm/uaccess.h> |
---|
15 | #include <asm/processor.h> |
---|
16 | #include <asm/ptrace.h> |
---|
17 | #include <asm/unwind.h> |
---|
18 | #else |
---|
19 | #define __KERNEL_SYSCALLS__ /* see <asm/unistd.h> */ |
---|
20 | #include <linux/config.h> |
---|
21 | |
---|
22 | #include <linux/cpu.h> |
---|
23 | #include <linux/pm.h> |
---|
24 | #include <linux/elf.h> |
---|
25 | #include <linux/errno.h> |
---|
26 | #include <linux/kallsyms.h> |
---|
27 | #include <linux/kernel.h> |
---|
28 | #include <linux/mm.h> |
---|
29 | #include <linux/module.h> |
---|
30 | #include <linux/notifier.h> |
---|
31 | #include <linux/personality.h> |
---|
32 | #include <linux/sched.h> |
---|
33 | #include <linux/slab.h> |
---|
34 | #include <linux/smp_lock.h> |
---|
35 | #include <linux/stddef.h> |
---|
36 | #include <linux/thread_info.h> |
---|
37 | #include <linux/unistd.h> |
---|
38 | #include <linux/efi.h> |
---|
39 | #include <linux/interrupt.h> |
---|
40 | #include <linux/delay.h> |
---|
41 | #include <linux/kprobes.h> |
---|
42 | |
---|
43 | #include <asm/cpu.h> |
---|
44 | #include <asm/delay.h> |
---|
45 | #include <asm/elf.h> |
---|
46 | #include <asm/ia32.h> |
---|
47 | #include <asm/irq.h> |
---|
48 | #include <asm/pgalloc.h> |
---|
49 | #include <asm/processor.h> |
---|
50 | #include <asm/sal.h> |
---|
51 | #include <asm/tlbflush.h> |
---|
52 | #include <asm/uaccess.h> |
---|
53 | #include <asm/unwind.h> |
---|
54 | #include <asm/user.h> |
---|
55 | |
---|
56 | #include "entry.h" |
---|
57 | |
---|
58 | #ifdef CONFIG_PERFMON |
---|
59 | # include <asm/perfmon.h> |
---|
60 | #endif |
---|
61 | |
---|
62 | #include "sigframe.h" |
---|
63 | |
---|
64 | void (*ia64_mark_idle)(int); |
---|
65 | static DEFINE_PER_CPU(unsigned int, cpu_idle_state); |
---|
66 | |
---|
67 | unsigned long boot_option_idle_override = 0; |
---|
68 | EXPORT_SYMBOL(boot_option_idle_override); |
---|
69 | #endif |
---|
70 | |
---|
71 | void |
---|
72 | ia64_do_show_stack (struct unw_frame_info *info, void *arg) |
---|
73 | { |
---|
74 | unsigned long ip, sp, bsp; |
---|
75 | char buf[128]; /* don't make it so big that it overflows the stack! */ |
---|
76 | |
---|
77 | printk("\nCall Trace:\n"); |
---|
78 | do { |
---|
79 | unw_get_ip(info, &ip); |
---|
80 | if (ip == 0) |
---|
81 | break; |
---|
82 | |
---|
83 | unw_get_sp(info, &sp); |
---|
84 | unw_get_bsp(info, &bsp); |
---|
85 | snprintf(buf, sizeof(buf), |
---|
86 | " [<%016lx>] %%s\n" |
---|
87 | " sp=%016lx bsp=%016lx\n", |
---|
88 | ip, sp, bsp); |
---|
89 | print_symbol(buf, ip); |
---|
90 | } while (unw_unwind(info) >= 0); |
---|
91 | } |
---|
92 | |
---|
93 | void |
---|
94 | show_stack (struct task_struct *task, unsigned long *sp) |
---|
95 | { |
---|
96 | if (!task) |
---|
97 | unw_init_running(ia64_do_show_stack, NULL); |
---|
98 | else { |
---|
99 | struct unw_frame_info info; |
---|
100 | |
---|
101 | unw_init_from_blocked_task(&info, task); |
---|
102 | ia64_do_show_stack(&info, NULL); |
---|
103 | } |
---|
104 | } |
---|
105 | |
---|
106 | void |
---|
107 | dump_stack (void) |
---|
108 | { |
---|
109 | show_stack(NULL, NULL); |
---|
110 | } |
---|
111 | |
---|
112 | EXPORT_SYMBOL(dump_stack); |
---|
113 | |
---|
114 | #ifdef XEN |
---|
115 | void |
---|
116 | show_registers(struct pt_regs *regs) |
---|
117 | #else |
---|
118 | void |
---|
119 | show_regs (struct pt_regs *regs) |
---|
120 | #endif |
---|
121 | { |
---|
122 | unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri; |
---|
123 | |
---|
124 | #ifndef XEN |
---|
125 | print_modules(); |
---|
126 | printk("\nPid: %d, CPU %d, comm: %20s\n", current->pid, smp_processor_id(), current->comm); |
---|
127 | printk("psr : %016lx ifs : %016lx ip : [<%016lx>] %s\n", |
---|
128 | regs->cr_ipsr, regs->cr_ifs, ip, print_tainted()); |
---|
129 | #else |
---|
130 | struct vcpu* vcpu = current; |
---|
131 | if (vcpu != NULL) { |
---|
132 | struct domain* d = vcpu->domain; |
---|
133 | printk("d 0x%p domid %d\n", d, d->domain_id); |
---|
134 | printk("vcpu 0x%p vcpu %d\n", |
---|
135 | vcpu, vcpu->vcpu_id); |
---|
136 | } |
---|
137 | printk("\nCPU %d\n", smp_processor_id()); |
---|
138 | printk("psr : %016lx ifs : %016lx ip : [<%016lx>]\n", |
---|
139 | regs->cr_ipsr, regs->cr_ifs, ip); |
---|
140 | #endif |
---|
141 | print_symbol("ip is at %s\n", ip); |
---|
142 | printk("unat: %016lx pfs : %016lx rsc : %016lx\n", |
---|
143 | regs->ar_unat, regs->ar_pfs, regs->ar_rsc); |
---|
144 | printk("rnat: %016lx bsps: %016lx pr : %016lx\n", |
---|
145 | regs->ar_rnat, regs->ar_bspstore, regs->pr); |
---|
146 | printk("ldrs: %016lx ccv : %016lx fpsr: %016lx\n", |
---|
147 | regs->loadrs, regs->ar_ccv, regs->ar_fpsr); |
---|
148 | printk("csd : %016lx ssd : %016lx\n", regs->ar_csd, regs->ar_ssd); |
---|
149 | printk("b0 : %016lx b6 : %016lx b7 : %016lx\n", regs->b0, regs->b6, regs->b7); |
---|
150 | printk("f6 : %05lx%016lx f7 : %05lx%016lx\n", |
---|
151 | regs->f6.u.bits[1], regs->f6.u.bits[0], |
---|
152 | regs->f7.u.bits[1], regs->f7.u.bits[0]); |
---|
153 | printk("f8 : %05lx%016lx f9 : %05lx%016lx\n", |
---|
154 | regs->f8.u.bits[1], regs->f8.u.bits[0], |
---|
155 | regs->f9.u.bits[1], regs->f9.u.bits[0]); |
---|
156 | printk("f10 : %05lx%016lx f11 : %05lx%016lx\n", |
---|
157 | regs->f10.u.bits[1], regs->f10.u.bits[0], |
---|
158 | regs->f11.u.bits[1], regs->f11.u.bits[0]); |
---|
159 | |
---|
160 | printk("r1 : %016lx r2 : %016lx r3 : %016lx\n", regs->r1, regs->r2, regs->r3); |
---|
161 | printk("r8 : %016lx r9 : %016lx r10 : %016lx\n", regs->r8, regs->r9, regs->r10); |
---|
162 | printk("r11 : %016lx r12 : %016lx r13 : %016lx\n", regs->r11, regs->r12, regs->r13); |
---|
163 | printk("r14 : %016lx r15 : %016lx r16 : %016lx\n", regs->r14, regs->r15, regs->r16); |
---|
164 | printk("r17 : %016lx r18 : %016lx r19 : %016lx\n", regs->r17, regs->r18, regs->r19); |
---|
165 | printk("r20 : %016lx r21 : %016lx r22 : %016lx\n", regs->r20, regs->r21, regs->r22); |
---|
166 | printk("r23 : %016lx r24 : %016lx r25 : %016lx\n", regs->r23, regs->r24, regs->r25); |
---|
167 | printk("r26 : %016lx r27 : %016lx r28 : %016lx\n", regs->r26, regs->r27, regs->r28); |
---|
168 | printk("r29 : %016lx r30 : %016lx r31 : %016lx\n", regs->r29, regs->r30, regs->r31); |
---|
169 | |
---|
170 | #ifndef XEN |
---|
171 | if (user_mode(regs)) { |
---|
172 | /* print the stacked registers */ |
---|
173 | unsigned long val, *bsp, ndirty; |
---|
174 | int i, sof, is_nat = 0; |
---|
175 | |
---|
176 | sof = regs->cr_ifs & 0x7f; /* size of frame */ |
---|
177 | ndirty = (regs->loadrs >> 19); |
---|
178 | bsp = ia64_rse_skip_regs((unsigned long *) regs->ar_bspstore, ndirty); |
---|
179 | for (i = 0; i < sof; ++i) { |
---|
180 | get_user(val, (unsigned long __user *) ia64_rse_skip_regs(bsp, i)); |
---|
181 | printk("r%-3u:%c%016lx%s", 32 + i, is_nat ? '*' : ' ', val, |
---|
182 | ((i == sof - 1) || (i % 3) == 2) ? "\n" : " "); |
---|
183 | } |
---|
184 | } else |
---|
185 | #endif |
---|
186 | show_stack(NULL, NULL); |
---|
187 | } |
---|
188 | |
---|
189 | #ifndef XEN |
---|
190 | void |
---|
191 | do_notify_resume_user (sigset_t *oldset, struct sigscratch *scr, long in_syscall) |
---|
192 | { |
---|
193 | if (fsys_mode(current, &scr->pt)) { |
---|
194 | /* defer signal-handling etc. until we return to privilege-level 0. */ |
---|
195 | if (!ia64_psr(&scr->pt)->lp) |
---|
196 | ia64_psr(&scr->pt)->lp = 1; |
---|
197 | return; |
---|
198 | } |
---|
199 | |
---|
200 | #ifdef CONFIG_PERFMON |
---|
201 | if (current->thread.pfm_needs_checking) |
---|
202 | pfm_handle_work(); |
---|
203 | #endif |
---|
204 | |
---|
205 | /* deal with pending signal delivery */ |
---|
206 | if (test_thread_flag(TIF_SIGPENDING)) |
---|
207 | ia64_do_signal(oldset, scr, in_syscall); |
---|
208 | } |
---|
209 | |
---|
210 | static int pal_halt = 1; |
---|
211 | static int can_do_pal_halt = 1; |
---|
212 | |
---|
213 | static int __init nohalt_setup(char * str) |
---|
214 | { |
---|
215 | pal_halt = can_do_pal_halt = 0; |
---|
216 | return 1; |
---|
217 | } |
---|
218 | __setup("nohalt", nohalt_setup); |
---|
219 | |
---|
220 | void |
---|
221 | update_pal_halt_status(int status) |
---|
222 | { |
---|
223 | can_do_pal_halt = pal_halt && status; |
---|
224 | } |
---|
225 | |
---|
226 | /* |
---|
227 | * We use this if we don't have any better idle routine.. |
---|
228 | */ |
---|
229 | void |
---|
230 | default_idle (void) |
---|
231 | { |
---|
232 | local_irq_enable(); |
---|
233 | while (!need_resched()) |
---|
234 | if (can_do_pal_halt) |
---|
235 | safe_halt(); |
---|
236 | else |
---|
237 | cpu_relax(); |
---|
238 | } |
---|
239 | |
---|
240 | #ifdef CONFIG_HOTPLUG_CPU |
---|
241 | /* We don't actually take CPU down, just spin without interrupts. */ |
---|
242 | static inline void play_dead(void) |
---|
243 | { |
---|
244 | extern void ia64_cpu_local_tick (void); |
---|
245 | unsigned int this_cpu = smp_processor_id(); |
---|
246 | |
---|
247 | /* Ack it */ |
---|
248 | __get_cpu_var(cpu_state) = CPU_DEAD; |
---|
249 | |
---|
250 | max_xtp(); |
---|
251 | local_irq_disable(); |
---|
252 | idle_domain_exit(); |
---|
253 | ia64_jump_to_sal(&sal_boot_rendez_state[this_cpu]); |
---|
254 | /* |
---|
255 | * The above is a point of no-return, the processor is |
---|
256 | * expected to be in SAL loop now. |
---|
257 | */ |
---|
258 | BUG(); |
---|
259 | } |
---|
260 | #else |
---|
261 | static inline void play_dead(void) |
---|
262 | { |
---|
263 | BUG(); |
---|
264 | } |
---|
265 | #endif /* CONFIG_HOTPLUG_CPU */ |
---|
266 | |
---|
267 | void cpu_idle_wait(void) |
---|
268 | { |
---|
269 | unsigned int cpu, this_cpu = get_cpu(); |
---|
270 | cpumask_t map; |
---|
271 | |
---|
272 | set_cpus_allowed(current, cpumask_of_cpu(this_cpu)); |
---|
273 | put_cpu(); |
---|
274 | |
---|
275 | cpus_clear(map); |
---|
276 | for_each_online_cpu(cpu) { |
---|
277 | per_cpu(cpu_idle_state, cpu) = 1; |
---|
278 | cpu_set(cpu, map); |
---|
279 | } |
---|
280 | |
---|
281 | __get_cpu_var(cpu_idle_state) = 0; |
---|
282 | |
---|
283 | wmb(); |
---|
284 | do { |
---|
285 | ssleep(1); |
---|
286 | for_each_online_cpu(cpu) { |
---|
287 | if (cpu_isset(cpu, map) && !per_cpu(cpu_idle_state, cpu)) |
---|
288 | cpu_clear(cpu, map); |
---|
289 | } |
---|
290 | cpus_and(map, map, cpu_online_map); |
---|
291 | } while (!cpus_empty(map)); |
---|
292 | } |
---|
293 | EXPORT_SYMBOL_GPL(cpu_idle_wait); |
---|
294 | |
---|
295 | void __attribute__((noreturn)) |
---|
296 | cpu_idle (void) |
---|
297 | { |
---|
298 | void (*mark_idle)(int) = ia64_mark_idle; |
---|
299 | |
---|
300 | /* endless idle loop with no priority at all */ |
---|
301 | while (1) { |
---|
302 | #ifdef CONFIG_SMP |
---|
303 | if (!need_resched()) |
---|
304 | min_xtp(); |
---|
305 | #endif |
---|
306 | while (!need_resched()) { |
---|
307 | void (*idle)(void); |
---|
308 | |
---|
309 | if (__get_cpu_var(cpu_idle_state)) |
---|
310 | __get_cpu_var(cpu_idle_state) = 0; |
---|
311 | |
---|
312 | rmb(); |
---|
313 | if (mark_idle) |
---|
314 | (*mark_idle)(1); |
---|
315 | |
---|
316 | idle = pm_idle; |
---|
317 | if (!idle) |
---|
318 | idle = default_idle; |
---|
319 | (*idle)(); |
---|
320 | } |
---|
321 | |
---|
322 | if (mark_idle) |
---|
323 | (*mark_idle)(0); |
---|
324 | |
---|
325 | #ifdef CONFIG_SMP |
---|
326 | normal_xtp(); |
---|
327 | #endif |
---|
328 | schedule(); |
---|
329 | check_pgt_cache(); |
---|
330 | if (cpu_is_offline(smp_processor_id())) |
---|
331 | play_dead(); |
---|
332 | } |
---|
333 | } |
---|
334 | |
---|
335 | void |
---|
336 | ia64_save_extra (struct task_struct *task) |
---|
337 | { |
---|
338 | #ifdef CONFIG_PERFMON |
---|
339 | unsigned long info; |
---|
340 | #endif |
---|
341 | |
---|
342 | if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0) |
---|
343 | ia64_save_debug_regs(&task->thread.dbr[0]); |
---|
344 | |
---|
345 | #ifdef CONFIG_PERFMON |
---|
346 | if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0) |
---|
347 | pfm_save_regs(task); |
---|
348 | |
---|
349 | info = __get_cpu_var(pfm_syst_info); |
---|
350 | if (info & PFM_CPUINFO_SYST_WIDE) |
---|
351 | pfm_syst_wide_update_task(task, info, 0); |
---|
352 | #endif |
---|
353 | |
---|
354 | #ifdef CONFIG_IA32_SUPPORT |
---|
355 | if (IS_IA32_PROCESS(ia64_task_regs(task))) |
---|
356 | ia32_save_state(task); |
---|
357 | #endif |
---|
358 | } |
---|
359 | |
---|
360 | void |
---|
361 | ia64_load_extra (struct task_struct *task) |
---|
362 | { |
---|
363 | #ifdef CONFIG_PERFMON |
---|
364 | unsigned long info; |
---|
365 | #endif |
---|
366 | |
---|
367 | if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0) |
---|
368 | ia64_load_debug_regs(&task->thread.dbr[0]); |
---|
369 | |
---|
370 | #ifdef CONFIG_PERFMON |
---|
371 | if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0) |
---|
372 | pfm_load_regs(task); |
---|
373 | |
---|
374 | info = __get_cpu_var(pfm_syst_info); |
---|
375 | if (info & PFM_CPUINFO_SYST_WIDE) |
---|
376 | pfm_syst_wide_update_task(task, info, 1); |
---|
377 | #endif |
---|
378 | |
---|
379 | #ifdef CONFIG_IA32_SUPPORT |
---|
380 | if (IS_IA32_PROCESS(ia64_task_regs(task))) |
---|
381 | ia32_load_state(task); |
---|
382 | #endif |
---|
383 | } |
---|
384 | |
---|
385 | /* |
---|
386 | * Copy the state of an ia-64 thread. |
---|
387 | * |
---|
388 | * We get here through the following call chain: |
---|
389 | * |
---|
390 | * from user-level: from kernel: |
---|
391 | * |
---|
392 | * <clone syscall> <some kernel call frames> |
---|
393 | * sys_clone : |
---|
394 | * do_fork do_fork |
---|
395 | * copy_thread copy_thread |
---|
396 | * |
---|
397 | * This means that the stack layout is as follows: |
---|
398 | * |
---|
399 | * +---------------------+ (highest addr) |
---|
400 | * | struct pt_regs | |
---|
401 | * +---------------------+ |
---|
402 | * | struct switch_stack | |
---|
403 | * +---------------------+ |
---|
404 | * | | |
---|
405 | * | memory stack | |
---|
406 | * | | <-- sp (lowest addr) |
---|
407 | * +---------------------+ |
---|
408 | * |
---|
409 | * Observe that we copy the unat values that are in pt_regs and switch_stack. Spilling an |
---|
410 | * integer to address X causes bit N in ar.unat to be set to the NaT bit of the register, |
---|
411 | * with N=(X & 0x1ff)/8. Thus, copying the unat value preserves the NaT bits ONLY if the |
---|
412 | * pt_regs structure in the parent is congruent to that of the child, modulo 512. Since |
---|
413 | * the stack is page aligned and the page size is at least 4KB, this is always the case, |
---|
414 | * so there is nothing to worry about. |
---|
415 | */ |
---|
416 | int |
---|
417 | copy_thread (int nr, unsigned long clone_flags, |
---|
418 | unsigned long user_stack_base, unsigned long user_stack_size, |
---|
419 | struct task_struct *p, struct pt_regs *regs) |
---|
420 | { |
---|
421 | extern char ia64_ret_from_clone, ia32_ret_from_clone; |
---|
422 | struct switch_stack *child_stack, *stack; |
---|
423 | unsigned long rbs, child_rbs, rbs_size; |
---|
424 | struct pt_regs *child_ptregs; |
---|
425 | int retval = 0; |
---|
426 | |
---|
427 | #ifdef CONFIG_SMP |
---|
428 | /* |
---|
429 | * For SMP idle threads, fork_by_hand() calls do_fork with |
---|
430 | * NULL regs. |
---|
431 | */ |
---|
432 | if (!regs) |
---|
433 | return 0; |
---|
434 | #endif |
---|
435 | |
---|
436 | stack = ((struct switch_stack *) regs) - 1; |
---|
437 | |
---|
438 | child_ptregs = (struct pt_regs *) ((unsigned long) p + IA64_STK_OFFSET) - 1; |
---|
439 | child_stack = (struct switch_stack *) child_ptregs - 1; |
---|
440 | |
---|
441 | /* copy parent's switch_stack & pt_regs to child: */ |
---|
442 | memcpy(child_stack, stack, sizeof(*child_ptregs) + sizeof(*child_stack)); |
---|
443 | |
---|
444 | rbs = (unsigned long) current + IA64_RBS_OFFSET; |
---|
445 | child_rbs = (unsigned long) p + IA64_RBS_OFFSET; |
---|
446 | rbs_size = stack->ar_bspstore - rbs; |
---|
447 | |
---|
448 | /* copy the parent's register backing store to the child: */ |
---|
449 | memcpy((void *) child_rbs, (void *) rbs, rbs_size); |
---|
450 | |
---|
451 | if (likely(user_mode(child_ptregs))) { |
---|
452 | if ((clone_flags & CLONE_SETTLS) && !IS_IA32_PROCESS(regs)) |
---|
453 | child_ptregs->r13 = regs->r16; /* see sys_clone2() in entry.S */ |
---|
454 | if (user_stack_base) { |
---|
455 | child_ptregs->r12 = user_stack_base + user_stack_size - 16; |
---|
456 | child_ptregs->ar_bspstore = user_stack_base; |
---|
457 | child_ptregs->ar_rnat = 0; |
---|
458 | child_ptregs->loadrs = 0; |
---|
459 | } |
---|
460 | } else { |
---|
461 | /* |
---|
462 | * Note: we simply preserve the relative position of |
---|
463 | * the stack pointer here. There is no need to |
---|
464 | * allocate a scratch area here, since that will have |
---|
465 | * been taken care of by the caller of sys_clone() |
---|
466 | * already. |
---|
467 | */ |
---|
468 | child_ptregs->r12 = (unsigned long) child_ptregs - 16; /* kernel sp */ |
---|
469 | child_ptregs->r13 = (unsigned long) p; /* set `current' pointer */ |
---|
470 | } |
---|
471 | child_stack->ar_bspstore = child_rbs + rbs_size; |
---|
472 | if (IS_IA32_PROCESS(regs)) |
---|
473 | child_stack->b0 = (unsigned long) &ia32_ret_from_clone; |
---|
474 | else |
---|
475 | child_stack->b0 = (unsigned long) &ia64_ret_from_clone; |
---|
476 | |
---|
477 | /* copy parts of thread_struct: */ |
---|
478 | p->thread.ksp = (unsigned long) child_stack - 16; |
---|
479 | |
---|
480 | /* stop some PSR bits from being inherited. |
---|
481 | * the psr.up/psr.pp bits must be cleared on fork but inherited on execve() |
---|
482 | * therefore we must specify them explicitly here and not include them in |
---|
483 | * IA64_PSR_BITS_TO_CLEAR. |
---|
484 | */ |
---|
485 | child_ptregs->cr_ipsr = ((child_ptregs->cr_ipsr | IA64_PSR_BITS_TO_SET) |
---|
486 | & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_PP | IA64_PSR_UP)); |
---|
487 | |
---|
488 | /* |
---|
489 | * NOTE: The calling convention considers all floating point |
---|
490 | * registers in the high partition (fph) to be scratch. Since |
---|
491 | * the only way to get to this point is through a system call, |
---|
492 | * we know that the values in fph are all dead. Hence, there |
---|
493 | * is no need to inherit the fph state from the parent to the |
---|
494 | * child and all we have to do is to make sure that |
---|
495 | * IA64_THREAD_FPH_VALID is cleared in the child. |
---|
496 | * |
---|
497 | * XXX We could push this optimization a bit further by |
---|
498 | * clearing IA64_THREAD_FPH_VALID on ANY system call. |
---|
499 | * However, it's not clear this is worth doing. Also, it |
---|
500 | * would be a slight deviation from the normal Linux system |
---|
501 | * call behavior where scratch registers are preserved across |
---|
502 | * system calls (unless used by the system call itself). |
---|
503 | */ |
---|
504 | # define THREAD_FLAGS_TO_CLEAR (IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID \ |
---|
505 | | IA64_THREAD_PM_VALID) |
---|
506 | # define THREAD_FLAGS_TO_SET 0 |
---|
507 | p->thread.flags = ((current->thread.flags & ~THREAD_FLAGS_TO_CLEAR) |
---|
508 | | THREAD_FLAGS_TO_SET); |
---|
509 | ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */ |
---|
510 | #ifdef CONFIG_IA32_SUPPORT |
---|
511 | /* |
---|
512 | * If we're cloning an IA32 task then save the IA32 extra |
---|
513 | * state from the current task to the new task |
---|
514 | */ |
---|
515 | if (IS_IA32_PROCESS(ia64_task_regs(current))) { |
---|
516 | ia32_save_state(p); |
---|
517 | if (clone_flags & CLONE_SETTLS) |
---|
518 | retval = ia32_clone_tls(p, child_ptregs); |
---|
519 | |
---|
520 | /* Copy partially mapped page list */ |
---|
521 | if (!retval) |
---|
522 | retval = ia32_copy_partial_page_list(p, clone_flags); |
---|
523 | } |
---|
524 | #endif |
---|
525 | |
---|
526 | #ifdef CONFIG_PERFMON |
---|
527 | if (current->thread.pfm_context) |
---|
528 | pfm_inherit(p, child_ptregs); |
---|
529 | #endif |
---|
530 | return retval; |
---|
531 | } |
---|
532 | |
---|
533 | static void |
---|
534 | do_copy_task_regs (struct task_struct *task, struct unw_frame_info *info, void *arg) |
---|
535 | { |
---|
536 | unsigned long mask, sp, nat_bits = 0, ip, ar_rnat, urbs_end, cfm; |
---|
537 | elf_greg_t *dst = arg; |
---|
538 | struct pt_regs *pt; |
---|
539 | char nat; |
---|
540 | int i; |
---|
541 | |
---|
542 | memset(dst, 0, sizeof(elf_gregset_t)); /* don't leak any kernel bits to user-level */ |
---|
543 | |
---|
544 | if (unw_unwind_to_user(info) < 0) |
---|
545 | return; |
---|
546 | |
---|
547 | unw_get_sp(info, &sp); |
---|
548 | pt = (struct pt_regs *) (sp + 16); |
---|
549 | |
---|
550 | urbs_end = ia64_get_user_rbs_end(task, pt, &cfm); |
---|
551 | |
---|
552 | if (ia64_sync_user_rbs(task, info->sw, pt->ar_bspstore, urbs_end) < 0) |
---|
553 | return; |
---|
554 | |
---|
555 | ia64_peek(task, info->sw, urbs_end, (long) ia64_rse_rnat_addr((long *) urbs_end), |
---|
556 | &ar_rnat); |
---|
557 | |
---|
558 | /* |
---|
559 | * coredump format: |
---|
560 | * r0-r31 |
---|
561 | * NaT bits (for r0-r31; bit N == 1 iff rN is a NaT) |
---|
562 | * predicate registers (p0-p63) |
---|
563 | * b0-b7 |
---|
564 | * ip cfm user-mask |
---|
565 | * ar.rsc ar.bsp ar.bspstore ar.rnat |
---|
566 | * ar.ccv ar.unat ar.fpsr ar.pfs ar.lc ar.ec |
---|
567 | */ |
---|
568 | |
---|
569 | /* r0 is zero */ |
---|
570 | for (i = 1, mask = (1UL << i); i < 32; ++i) { |
---|
571 | unw_get_gr(info, i, &dst[i], &nat); |
---|
572 | if (nat) |
---|
573 | nat_bits |= mask; |
---|
574 | mask <<= 1; |
---|
575 | } |
---|
576 | dst[32] = nat_bits; |
---|
577 | unw_get_pr(info, &dst[33]); |
---|
578 | |
---|
579 | for (i = 0; i < 8; ++i) |
---|
580 | unw_get_br(info, i, &dst[34 + i]); |
---|
581 | |
---|
582 | unw_get_rp(info, &ip); |
---|
583 | dst[42] = ip + ia64_psr(pt)->ri; |
---|
584 | dst[43] = cfm; |
---|
585 | dst[44] = pt->cr_ipsr & IA64_PSR_UM; |
---|
586 | |
---|
587 | unw_get_ar(info, UNW_AR_RSC, &dst[45]); |
---|
588 | /* |
---|
589 | * For bsp and bspstore, unw_get_ar() would return the kernel |
---|
590 | * addresses, but we need the user-level addresses instead: |
---|
591 | */ |
---|
592 | dst[46] = urbs_end; /* note: by convention PT_AR_BSP points to the end of the urbs! */ |
---|
593 | dst[47] = pt->ar_bspstore; |
---|
594 | dst[48] = ar_rnat; |
---|
595 | unw_get_ar(info, UNW_AR_CCV, &dst[49]); |
---|
596 | unw_get_ar(info, UNW_AR_UNAT, &dst[50]); |
---|
597 | unw_get_ar(info, UNW_AR_FPSR, &dst[51]); |
---|
598 | dst[52] = pt->ar_pfs; /* UNW_AR_PFS is == to pt->cr_ifs for interrupt frames */ |
---|
599 | unw_get_ar(info, UNW_AR_LC, &dst[53]); |
---|
600 | unw_get_ar(info, UNW_AR_EC, &dst[54]); |
---|
601 | unw_get_ar(info, UNW_AR_CSD, &dst[55]); |
---|
602 | unw_get_ar(info, UNW_AR_SSD, &dst[56]); |
---|
603 | } |
---|
604 | |
---|
605 | void |
---|
606 | do_dump_task_fpu (struct task_struct *task, struct unw_frame_info *info, void *arg) |
---|
607 | { |
---|
608 | elf_fpreg_t *dst = arg; |
---|
609 | int i; |
---|
610 | |
---|
611 | memset(dst, 0, sizeof(elf_fpregset_t)); /* don't leak any "random" bits */ |
---|
612 | |
---|
613 | if (unw_unwind_to_user(info) < 0) |
---|
614 | return; |
---|
615 | |
---|
616 | /* f0 is 0.0, f1 is 1.0 */ |
---|
617 | |
---|
618 | for (i = 2; i < 32; ++i) |
---|
619 | unw_get_fr(info, i, dst + i); |
---|
620 | |
---|
621 | ia64_flush_fph(task); |
---|
622 | if ((task->thread.flags & IA64_THREAD_FPH_VALID) != 0) |
---|
623 | memcpy(dst + 32, task->thread.fph, 96*16); |
---|
624 | } |
---|
625 | |
---|
626 | void |
---|
627 | do_copy_regs (struct unw_frame_info *info, void *arg) |
---|
628 | { |
---|
629 | do_copy_task_regs(current, info, arg); |
---|
630 | } |
---|
631 | |
---|
632 | void |
---|
633 | do_dump_fpu (struct unw_frame_info *info, void *arg) |
---|
634 | { |
---|
635 | do_dump_task_fpu(current, info, arg); |
---|
636 | } |
---|
637 | |
---|
638 | int |
---|
639 | dump_task_regs(struct task_struct *task, elf_gregset_t *regs) |
---|
640 | { |
---|
641 | struct unw_frame_info tcore_info; |
---|
642 | |
---|
643 | if (current == task) { |
---|
644 | unw_init_running(do_copy_regs, regs); |
---|
645 | } else { |
---|
646 | memset(&tcore_info, 0, sizeof(tcore_info)); |
---|
647 | unw_init_from_blocked_task(&tcore_info, task); |
---|
648 | do_copy_task_regs(task, &tcore_info, regs); |
---|
649 | } |
---|
650 | return 1; |
---|
651 | } |
---|
652 | |
---|
653 | void |
---|
654 | ia64_elf_core_copy_regs (struct pt_regs *pt, elf_gregset_t dst) |
---|
655 | { |
---|
656 | unw_init_running(do_copy_regs, dst); |
---|
657 | } |
---|
658 | |
---|
659 | int |
---|
660 | dump_task_fpu (struct task_struct *task, elf_fpregset_t *dst) |
---|
661 | { |
---|
662 | struct unw_frame_info tcore_info; |
---|
663 | |
---|
664 | if (current == task) { |
---|
665 | unw_init_running(do_dump_fpu, dst); |
---|
666 | } else { |
---|
667 | memset(&tcore_info, 0, sizeof(tcore_info)); |
---|
668 | unw_init_from_blocked_task(&tcore_info, task); |
---|
669 | do_dump_task_fpu(task, &tcore_info, dst); |
---|
670 | } |
---|
671 | return 1; |
---|
672 | } |
---|
673 | |
---|
674 | int |
---|
675 | dump_fpu (struct pt_regs *pt, elf_fpregset_t dst) |
---|
676 | { |
---|
677 | unw_init_running(do_dump_fpu, dst); |
---|
678 | return 1; /* f0-f31 are always valid so we always return 1 */ |
---|
679 | } |
---|
680 | |
---|
681 | long |
---|
682 | sys_execve (char __user *filename, char __user * __user *argv, char __user * __user *envp, |
---|
683 | struct pt_regs *regs) |
---|
684 | { |
---|
685 | char *fname; |
---|
686 | int error; |
---|
687 | |
---|
688 | fname = getname(filename); |
---|
689 | error = PTR_ERR(fname); |
---|
690 | if (IS_ERR(fname)) |
---|
691 | goto out; |
---|
692 | error = do_execve(fname, argv, envp, regs); |
---|
693 | putname(fname); |
---|
694 | out: |
---|
695 | return error; |
---|
696 | } |
---|
697 | |
---|
698 | pid_t |
---|
699 | kernel_thread (int (*fn)(void *), void *arg, unsigned long flags) |
---|
700 | { |
---|
701 | extern void start_kernel_thread (void); |
---|
702 | unsigned long *helper_fptr = (unsigned long *) &start_kernel_thread; |
---|
703 | struct { |
---|
704 | struct switch_stack sw; |
---|
705 | struct pt_regs pt; |
---|
706 | } regs; |
---|
707 | |
---|
708 | memset(®s, 0, sizeof(regs)); |
---|
709 | regs.pt.cr_iip = helper_fptr[0]; /* set entry point (IP) */ |
---|
710 | regs.pt.r1 = helper_fptr[1]; /* set GP */ |
---|
711 | regs.pt.r9 = (unsigned long) fn; /* 1st argument */ |
---|
712 | regs.pt.r11 = (unsigned long) arg; /* 2nd argument */ |
---|
713 | /* Preserve PSR bits, except for bits 32-34 and 37-45, which we can't read. */ |
---|
714 | regs.pt.cr_ipsr = ia64_getreg(_IA64_REG_PSR) | IA64_PSR_BN; |
---|
715 | regs.pt.cr_ifs = 1UL << 63; /* mark as valid, empty frame */ |
---|
716 | regs.sw.ar_fpsr = regs.pt.ar_fpsr = ia64_getreg(_IA64_REG_AR_FPSR); |
---|
717 | regs.sw.ar_bspstore = (unsigned long) current + IA64_RBS_OFFSET; |
---|
718 | regs.sw.pr = (1 << PRED_KERNEL_STACK); |
---|
719 | return do_fork(flags | CLONE_VM | CLONE_UNTRACED, 0, ®s.pt, 0, NULL, NULL); |
---|
720 | } |
---|
721 | EXPORT_SYMBOL(kernel_thread); |
---|
722 | |
---|
723 | /* This gets called from kernel_thread() via ia64_invoke_thread_helper(). */ |
---|
724 | int |
---|
725 | kernel_thread_helper (int (*fn)(void *), void *arg) |
---|
726 | { |
---|
727 | #ifdef CONFIG_IA32_SUPPORT |
---|
728 | if (IS_IA32_PROCESS(ia64_task_regs(current))) { |
---|
729 | /* A kernel thread is always a 64-bit process. */ |
---|
730 | current->thread.map_base = DEFAULT_MAP_BASE; |
---|
731 | current->thread.task_size = DEFAULT_TASK_SIZE; |
---|
732 | ia64_set_kr(IA64_KR_IO_BASE, current->thread.old_iob); |
---|
733 | ia64_set_kr(IA64_KR_TSSD, current->thread.old_k1); |
---|
734 | } |
---|
735 | #endif |
---|
736 | return (*fn)(arg); |
---|
737 | } |
---|
738 | |
---|
739 | /* |
---|
740 | * Flush thread state. This is called when a thread does an execve(). |
---|
741 | */ |
---|
742 | void |
---|
743 | flush_thread (void) |
---|
744 | { |
---|
745 | /* |
---|
746 | * Remove function-return probe instances associated with this task |
---|
747 | * and put them back on the free list. Do not insert an exit probe for |
---|
748 | * this function, it will be disabled by kprobe_flush_task if you do. |
---|
749 | */ |
---|
750 | kprobe_flush_task(current); |
---|
751 | |
---|
752 | /* drop floating-point and debug-register state if it exists: */ |
---|
753 | current->thread.flags &= ~(IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID); |
---|
754 | ia64_drop_fpu(current); |
---|
755 | if (IS_IA32_PROCESS(ia64_task_regs(current))) |
---|
756 | ia32_drop_partial_page_list(current); |
---|
757 | } |
---|
758 | |
---|
759 | /* |
---|
760 | * Clean up state associated with current thread. This is called when |
---|
761 | * the thread calls exit(). |
---|
762 | */ |
---|
763 | void |
---|
764 | exit_thread (void) |
---|
765 | { |
---|
766 | |
---|
767 | /* |
---|
768 | * Remove function-return probe instances associated with this task |
---|
769 | * and put them back on the free list. Do not insert an exit probe for |
---|
770 | * this function, it will be disabled by kprobe_flush_task if you do. |
---|
771 | */ |
---|
772 | kprobe_flush_task(current); |
---|
773 | |
---|
774 | ia64_drop_fpu(current); |
---|
775 | #ifdef CONFIG_PERFMON |
---|
776 | /* if needed, stop monitoring and flush state to perfmon context */ |
---|
777 | if (current->thread.pfm_context) |
---|
778 | pfm_exit_thread(current); |
---|
779 | |
---|
780 | /* free debug register resources */ |
---|
781 | if (current->thread.flags & IA64_THREAD_DBG_VALID) |
---|
782 | pfm_release_debug_registers(current); |
---|
783 | #endif |
---|
784 | if (IS_IA32_PROCESS(ia64_task_regs(current))) |
---|
785 | ia32_drop_partial_page_list(current); |
---|
786 | } |
---|
787 | |
---|
788 | unsigned long |
---|
789 | get_wchan (struct task_struct *p) |
---|
790 | { |
---|
791 | struct unw_frame_info info; |
---|
792 | unsigned long ip; |
---|
793 | int count = 0; |
---|
794 | |
---|
795 | /* |
---|
796 | * Note: p may not be a blocked task (it could be current or |
---|
797 | * another process running on some other CPU. Rather than |
---|
798 | * trying to determine if p is really blocked, we just assume |
---|
799 | * it's blocked and rely on the unwind routines to fail |
---|
800 | * gracefully if the process wasn't really blocked after all. |
---|
801 | * --davidm 99/12/15 |
---|
802 | */ |
---|
803 | unw_init_from_blocked_task(&info, p); |
---|
804 | do { |
---|
805 | if (unw_unwind(&info) < 0) |
---|
806 | return 0; |
---|
807 | unw_get_ip(&info, &ip); |
---|
808 | if (!in_sched_functions(ip)) |
---|
809 | return ip; |
---|
810 | } while (count++ < 16); |
---|
811 | return 0; |
---|
812 | } |
---|
813 | #endif // !XEN |
---|
814 | |
---|
815 | void |
---|
816 | cpu_halt (void) |
---|
817 | { |
---|
818 | pal_power_mgmt_info_u_t power_info[8]; |
---|
819 | unsigned long min_power; |
---|
820 | int i, min_power_state; |
---|
821 | |
---|
822 | if (ia64_pal_halt_info(power_info) != 0) |
---|
823 | return; |
---|
824 | |
---|
825 | min_power_state = 0; |
---|
826 | min_power = power_info[0].pal_power_mgmt_info_s.power_consumption; |
---|
827 | for (i = 1; i < 8; ++i) |
---|
828 | if (power_info[i].pal_power_mgmt_info_s.im |
---|
829 | && power_info[i].pal_power_mgmt_info_s.power_consumption < min_power) { |
---|
830 | min_power = power_info[i].pal_power_mgmt_info_s.power_consumption; |
---|
831 | min_power_state = i; |
---|
832 | } |
---|
833 | |
---|
834 | while (1) |
---|
835 | ia64_pal_halt(min_power_state); |
---|
836 | } |
---|
837 | |
---|
838 | #ifndef XEN |
---|
839 | void |
---|
840 | machine_restart (char *restart_cmd) |
---|
841 | { |
---|
842 | (*efi.reset_system)(EFI_RESET_WARM, 0, 0, NULL); |
---|
843 | } |
---|
844 | |
---|
845 | void |
---|
846 | machine_halt (void) |
---|
847 | { |
---|
848 | cpu_halt(); |
---|
849 | } |
---|
850 | |
---|
851 | void |
---|
852 | machine_power_off (void) |
---|
853 | { |
---|
854 | if (pm_power_off) |
---|
855 | pm_power_off(); |
---|
856 | machine_halt(); |
---|
857 | } |
---|
858 | #endif // !XEN |
---|