1 /*
2 * Architecture-specific setup.
3 *
4 * Copyright (C) 1998-2003 Hewlett-Packard Co
5 * David Mosberger-Tang <davidm@hpl.hp.com>
6 */
7 #define __KERNEL_SYSCALLS__ /* see <asm/unistd.h> */
8 #include <linux/config.h>
9
10 #include <linux/pm.h>
11 #include <linux/elf.h>
12 #include <linux/errno.h>
13 #include <linux/kernel.h>
14 #include <linux/mm.h>
15 #include <linux/personality.h>
16 #include <linux/sched.h>
17 #include <linux/slab.h>
18 #include <linux/smp_lock.h>
19 #include <linux/stddef.h>
20 #include <linux/unistd.h>
21 #include <linux/efi.h>
22
23 #include <asm/delay.h>
24 #include <asm/perfmon.h>
25 #include <asm/pgtable.h>
26 #include <asm/processor.h>
27 #include <asm/sal.h>
28 #include <asm/uaccess.h>
29 #include <asm/unwind.h>
30 #include <asm/user.h>
31
32 #ifdef CONFIG_IA64_SGI_SN
33 #include <asm/sn/idle.h>
34 #endif
35
36 #define print_symbol(fmt, addr) printk(fmt, "(no symbol)");
37
38 void
ia64_do_show_stack(struct unw_frame_info * info,void * arg)39 ia64_do_show_stack (struct unw_frame_info *info, void *arg)
40 {
41 unsigned long ip, sp, bsp;
42 char buf[128]; /* don't make it so big that it overflows the stack! */
43
44 printk("\nCall Trace:\n");
45 do {
46 unw_get_ip(info, &ip);
47 if (ip == 0)
48 break;
49
50 unw_get_sp(info, &sp);
51 unw_get_bsp(info, &bsp);
52 snprintf(buf, sizeof(buf),
53 " [<%016lx>] %%s\n"
54 " sp=%016lx bsp=%016lx\n",
55 ip, sp, bsp);
56 print_symbol(buf, ip);
57 } while (unw_unwind(info) >= 0);
58 }
59
60 void
show_stack(struct task_struct * task)61 show_stack (struct task_struct *task)
62 {
63 if (!task)
64 unw_init_running(ia64_do_show_stack, 0);
65 else {
66 struct unw_frame_info info;
67
68 unw_init_from_blocked_task(&info, task);
69 ia64_do_show_stack(&info, 0);
70 }
71 }
72
73 void
show_trace_task(struct task_struct * task)74 show_trace_task (struct task_struct *task)
75 {
76 show_stack(task);
77 }
78
79 void
show_regs(struct pt_regs * regs)80 show_regs (struct pt_regs *regs)
81 {
82 unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
83
84 printk("\nPid: %d, CPU %d, comm: %20s\n", current->pid, smp_processor_id(), current->comm);
85 printk("psr : %016lx ifs : %016lx ip : [<%016lx>] %s\n",
86 regs->cr_ipsr, regs->cr_ifs, ip, print_tainted());
87 print_symbol("ip is at %s\n", ip);
88 printk("unat: %016lx pfs : %016lx rsc : %016lx\n",
89 regs->ar_unat, regs->ar_pfs, regs->ar_rsc);
90 printk("rnat: %016lx bsps: %016lx pr : %016lx\n",
91 regs->ar_rnat, regs->ar_bspstore, regs->pr);
92 printk("ldrs: %016lx ccv : %016lx fpsr: %016lx\n",
93 regs->loadrs, regs->ar_ccv, regs->ar_fpsr);
94 printk("csd : %016lx ssd : %016lx\n", regs->ar_csd, regs->ar_ssd);
95 printk("b0 : %016lx b6 : %016lx b7 : %016lx\n", regs->b0, regs->b6, regs->b7);
96 printk("f6 : %05lx%016lx f7 : %05lx%016lx\n",
97 regs->f6.u.bits[1], regs->f6.u.bits[0],
98 regs->f7.u.bits[1], regs->f7.u.bits[0]);
99 printk("f8 : %05lx%016lx f9 : %05lx%016lx\n",
100 regs->f8.u.bits[1], regs->f8.u.bits[0],
101 regs->f9.u.bits[1], regs->f9.u.bits[0]);
102 printk("f10 : %05lx%016lx f11 : %05lx%016lx\n",
103 regs->f10.u.bits[1], regs->f10.u.bits[0],
104 regs->f11.u.bits[1], regs->f11.u.bits[0]);
105
106 printk("r1 : %016lx r2 : %016lx r3 : %016lx\n", regs->r1, regs->r2, regs->r3);
107 printk("r8 : %016lx r9 : %016lx r10 : %016lx\n", regs->r8, regs->r9, regs->r10);
108 printk("r11 : %016lx r12 : %016lx r13 : %016lx\n", regs->r11, regs->r12, regs->r13);
109 printk("r14 : %016lx r15 : %016lx r16 : %016lx\n", regs->r14, regs->r15, regs->r16);
110 printk("r17 : %016lx r18 : %016lx r19 : %016lx\n", regs->r17, regs->r18, regs->r19);
111 printk("r20 : %016lx r21 : %016lx r22 : %016lx\n", regs->r20, regs->r21, regs->r22);
112 printk("r23 : %016lx r24 : %016lx r25 : %016lx\n", regs->r23, regs->r24, regs->r25);
113 printk("r26 : %016lx r27 : %016lx r28 : %016lx\n", regs->r26, regs->r27, regs->r28);
114 printk("r29 : %016lx r30 : %016lx r31 : %016lx\n", regs->r29, regs->r30, regs->r31);
115
116 if (user_mode(regs)) {
117 /* print the stacked registers */
118 unsigned long val, sof, *bsp, ndirty;
119 int i, is_nat = 0;
120
121 sof = regs->cr_ifs & 0x7f; /* size of frame */
122 ndirty = (regs->loadrs >> 19);
123 bsp = ia64_rse_skip_regs((unsigned long *) regs->ar_bspstore, ndirty);
124 for (i = 0; i < sof; ++i) {
125 get_user(val, ia64_rse_skip_regs(bsp, i));
126 printk("r%-3u:%c%016lx%s", 32 + i, is_nat ? '*' : ' ', val,
127 ((i == sof - 1) || (i % 3) == 2) ? "\n" : " ");
128 }
129 }
130 if (!user_mode(regs))
131 show_stack(NULL);
132 }
133
134 /*
135 * We use this if we don't have any better idle routine..
136 */
137 void
default_idle(void)138 default_idle (void)
139 {
140 #ifdef CONFIG_IA64_PAL_IDLE
141 if (!current->need_resched)
142 safe_halt();
143 #endif
144 }
145
146 void __attribute__((noreturn))
cpu_idle(void * unused)147 cpu_idle (void *unused)
148 {
149 init_idle();
150 current->nice = 20;
151 current->counter = -100;
152
153
154 /* endless idle loop with no priority at all */
155 while (1) {
156 void (*idle)(void) = pm_idle;
157 if (!idle)
158 idle = default_idle;
159
160 #ifdef CONFIG_SMP
161 if (!current->need_resched)
162 min_xtp();
163 #endif
164
165 while (!current->need_resched) {
166 #ifdef CONFIG_IA64_SGI_SN
167 snidle();
168 #endif
169 (*idle)();
170 }
171
172 #ifdef CONFIG_IA64_SGI_SN
173 snidleoff();
174 #endif
175
176 #ifdef CONFIG_SMP
177 normal_xtp();
178 #endif
179 schedule();
180 check_pgt_cache();
181 }
182 }
183
184 void
ia64_save_extra(struct task_struct * task)185 ia64_save_extra (struct task_struct *task)
186 {
187 #ifdef CONFIG_PERFMON
188 unsigned long info;
189 #endif
190
191 if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0)
192 ia64_save_debug_regs(&task->thread.dbr[0]);
193
194 #ifdef CONFIG_PERFMON
195 if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0)
196 pfm_save_regs(task);
197
198 info = local_cpu_data->pfm_syst_info;
199 if (info & PFM_CPUINFO_SYST_WIDE)
200 pfm_syst_wide_update_task(task, info, 0);
201 #endif
202
203 #ifdef CONFIG_IA32_SUPPORT
204 if (IS_IA32_PROCESS(ia64_task_regs(task)))
205 ia32_save_state(task);
206 #endif
207 }
208
209 void
ia64_load_extra(struct task_struct * task)210 ia64_load_extra (struct task_struct *task)
211 {
212 #ifdef CONFIG_PERFMON
213 unsigned long info;
214 #endif
215
216 if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0)
217 ia64_load_debug_regs(&task->thread.dbr[0]);
218
219 #ifdef CONFIG_PERFMON
220 if ((task->thread.flags & IA64_THREAD_PM_VALID) != 0)
221 pfm_load_regs(task);
222
223 info = local_cpu_data->pfm_syst_info;
224 if (info & PFM_CPUINFO_SYST_WIDE)
225 pfm_syst_wide_update_task(task, info, 1);
226 #endif
227
228 #ifdef CONFIG_IA32_SUPPORT
229 if (IS_IA32_PROCESS(ia64_task_regs(task)))
230 ia32_load_state(task);
231 #endif
232 }
233
234 /*
235 * Copy the state of an ia-64 thread.
236 *
237 * We get here through the following call chain:
238 *
239 * <clone syscall>
240 * sys_clone
241 * do_fork
242 * copy_thread
243 *
244 * This means that the stack layout is as follows:
245 *
246 * +---------------------+ (highest addr)
247 * | struct pt_regs |
248 * +---------------------+
249 * | struct switch_stack |
250 * +---------------------+
251 * | |
252 * | memory stack |
253 * | | <-- sp (lowest addr)
254 * +---------------------+
255 *
256 * Note: if we get called through arch_kernel_thread() then the memory
257 * above "(highest addr)" is valid kernel stack memory that needs to
258 * be copied as well.
259 *
260 * Observe that we copy the unat values that are in pt_regs and
261 * switch_stack. Spilling an integer to address X causes bit N in
262 * ar.unat to be set to the NaT bit of the register, with N=(X &
263 * 0x1ff)/8. Thus, copying the unat value preserves the NaT bits ONLY
264 * if the pt_regs structure in the parent is congruent to that of the
265 * child, modulo 512. Since the stack is page aligned and the page
266 * size is at least 4KB, this is always the case, so there is nothing
267 * to worry about.
268 */
269 int
copy_thread(int nr,unsigned long clone_flags,unsigned long user_stack_base,unsigned long user_stack_size,struct task_struct * p,struct pt_regs * regs)270 copy_thread (int nr, unsigned long clone_flags,
271 unsigned long user_stack_base, unsigned long user_stack_size,
272 struct task_struct *p, struct pt_regs *regs)
273 {
274 unsigned long rbs, child_rbs, rbs_size, stack_offset, stack_top, stack_used;
275 struct switch_stack *child_stack, *stack;
276 extern char ia64_ret_from_clone, ia32_ret_from_clone;
277 struct pt_regs *child_ptregs;
278 int retval = 0;
279
280 #ifdef CONFIG_SMP
281 /*
282 * For SMP idle threads, fork_by_hand() calls do_fork with
283 * NULL regs.
284 */
285 if (!regs)
286 return 0;
287 #endif
288
289 stack_top = (unsigned long) current + IA64_STK_OFFSET;
290 stack = ((struct switch_stack *) regs) - 1;
291 stack_used = stack_top - (unsigned long) stack;
292 stack_offset = IA64_STK_OFFSET - stack_used;
293
294 child_stack = (struct switch_stack *) ((unsigned long) p + stack_offset);
295 child_ptregs = (struct pt_regs *) (child_stack + 1);
296
297 /* copy parent's switch_stack & pt_regs to child: */
298 memcpy(child_stack, stack, stack_used);
299
300 rbs = (unsigned long) current + IA64_RBS_OFFSET;
301 child_rbs = (unsigned long) p + IA64_RBS_OFFSET;
302 rbs_size = stack->ar_bspstore - rbs;
303
304 /* copy the parent's register backing store to the child: */
305 memcpy((void *) child_rbs, (void *) rbs, rbs_size);
306
307 if (user_mode(child_ptregs)) {
308 if (user_stack_base) {
309 child_ptregs->r12 = user_stack_base + user_stack_size - 16;
310 child_ptregs->ar_bspstore = user_stack_base;
311 child_ptregs->ar_rnat = 0;
312 child_ptregs->loadrs = 0;
313 }
314 } else {
315 /*
316 * Note: we simply preserve the relative position of
317 * the stack pointer here. There is no need to
318 * allocate a scratch area here, since that will have
319 * been taken care of by the caller of sys_clone()
320 * already.
321 */
322 child_ptregs->r12 = (unsigned long) (child_ptregs + 1); /* kernel sp */
323 child_ptregs->r13 = (unsigned long) p; /* set `current' pointer */
324 }
325 if (IS_IA32_PROCESS(regs))
326 child_stack->b0 = (unsigned long) &ia32_ret_from_clone;
327 else
328 child_stack->b0 = (unsigned long) &ia64_ret_from_clone;
329 child_stack->ar_bspstore = child_rbs + rbs_size;
330
331 /* copy parts of thread_struct: */
332 p->thread.ksp = (unsigned long) child_stack - 16;
333
334 /* stop some PSR bits from being inherited: */
335 child_ptregs->cr_ipsr = ((child_ptregs->cr_ipsr | IA64_PSR_BITS_TO_SET)
336 & ~IA64_PSR_BITS_TO_CLEAR);
337
338 /*
339 * NOTE: The calling convention considers all floating point registers in the high
340 * partition (fph) to be scratch. Since the only way to get to this point is
341 * through a system call, we know that the values in fph are all dead. Hence,
342 * there is no need to inherit the fph state from the parent to the child and all
343 * we have to do is to make sure that IA64_THREAD_FPH_VALID is cleared in the
344 * child.
345 *
346 * XXX We could push this optimization a bit further by clearing
347 * IA64_THREAD_FPH_VALID on ANY system call. However, it's not clear this is
348 * worth doing. Also, it would be a slight deviation from the normal Linux system
349 * call behavior where scratch registers are preserved across system calls (unless
350 * used by the system call itself).
351 */
352 # define THREAD_FLAGS_TO_CLEAR (IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID \
353 | IA64_THREAD_PM_VALID)
354 # define THREAD_FLAGS_TO_SET 0
355 p->thread.flags = ((current->thread.flags & ~THREAD_FLAGS_TO_CLEAR)
356 | THREAD_FLAGS_TO_SET);
357 ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */
358 #ifdef CONFIG_IA32_SUPPORT
359 /*
360 * If we're cloning an IA32 task then save the IA32 extra
361 * state from the current task to the new task
362 */
363 if (IS_IA32_PROCESS(ia64_task_regs(current)))
364 ia32_save_state(p);
365 #endif
366
367 #ifdef CONFIG_PERFMON
368 /*
369 * reset notifiers and owner check (may not have a perfmon context)
370 */
371 atomic_set(&p->thread.pfm_notifiers_check, 0);
372 atomic_set(&p->thread.pfm_owners_check, 0);
373 /* clear list of sampling buffer to free for new task */
374 p->thread.pfm_smpl_buf_list = NULL;
375
376 if (current->thread.pfm_context)
377 retval = pfm_inherit(p, child_ptregs);
378 #endif
379 return retval;
380 }
381
382 void
do_copy_regs(struct unw_frame_info * info,void * arg)383 do_copy_regs (struct unw_frame_info *info, void *arg)
384 {
385 unsigned long mask, sp, nat_bits = 0, ip, ar_rnat, urbs_end, cfm;
386 elf_greg_t *dst = arg;
387 struct pt_regs *pt;
388 char nat;
389 int i;
390
391 memset(dst, 0, sizeof(elf_gregset_t)); /* don't leak any kernel bits to user-level */
392
393 if (unw_unwind_to_user(info) < 0)
394 return;
395
396 unw_get_sp(info, &sp);
397 pt = (struct pt_regs *) (sp + 16);
398
399 urbs_end = ia64_get_user_rbs_end(current, pt, &cfm);
400
401 if (ia64_sync_user_rbs(current, info->sw, pt->ar_bspstore, urbs_end) < 0)
402 return;
403
404 ia64_peek(current, info->sw, urbs_end, (long) ia64_rse_rnat_addr((long *) urbs_end),
405 &ar_rnat);
406
407 /*
408 * coredump format:
409 * r0-r31
410 * NaT bits (for r0-r31; bit N == 1 iff rN is a NaT)
411 * predicate registers (p0-p63)
412 * b0-b7
413 * ip cfm user-mask
414 * ar.rsc ar.bsp ar.bspstore ar.rnat
415 * ar.ccv ar.unat ar.fpsr ar.pfs ar.lc ar.ec
416 */
417
418 /* r0 is zero */
419 for (i = 1, mask = (1UL << i); i < 32; ++i) {
420 unw_get_gr(info, i, &dst[i], &nat);
421 if (nat)
422 nat_bits |= mask;
423 mask <<= 1;
424 }
425 dst[32] = nat_bits;
426 unw_get_pr(info, &dst[33]);
427
428 for (i = 0; i < 8; ++i)
429 unw_get_br(info, i, &dst[34 + i]);
430
431 unw_get_rp(info, &ip);
432 dst[42] = ip + ia64_psr(pt)->ri;
433 dst[43] = cfm;
434 dst[44] = pt->cr_ipsr & IA64_PSR_UM;
435
436 unw_get_ar(info, UNW_AR_RSC, &dst[45]);
437 /*
438 * For bsp and bspstore, unw_get_ar() would return the kernel
439 * addresses, but we need the user-level addresses instead:
440 */
441 dst[46] = urbs_end; /* note: by convention PT_AR_BSP points to the end of the urbs! */
442 dst[47] = pt->ar_bspstore;
443 dst[48] = ar_rnat;
444 unw_get_ar(info, UNW_AR_CCV, &dst[49]);
445 unw_get_ar(info, UNW_AR_UNAT, &dst[50]);
446 unw_get_ar(info, UNW_AR_FPSR, &dst[51]);
447 dst[52] = pt->ar_pfs; /* UNW_AR_PFS is == to pt->cr_ifs for interrupt frames */
448 unw_get_ar(info, UNW_AR_LC, &dst[53]);
449 unw_get_ar(info, UNW_AR_EC, &dst[54]);
450 unw_get_ar(info, UNW_AR_CSD, &dst[55]);
451 unw_get_ar(info, UNW_AR_SSD, &dst[56]);
452 }
453
454 void
do_dump_fpu(struct unw_frame_info * info,void * arg)455 do_dump_fpu (struct unw_frame_info *info, void *arg)
456 {
457 elf_fpreg_t *dst = arg;
458 int i;
459
460 memset(dst, 0, sizeof(elf_fpregset_t)); /* don't leak any "random" bits */
461
462 if (unw_unwind_to_user(info) < 0)
463 return;
464
465 /* f0 is 0.0, f1 is 1.0 */
466
467 for (i = 2; i < 32; ++i)
468 unw_get_fr(info, i, dst + i);
469
470 ia64_flush_fph(current);
471 if ((current->thread.flags & IA64_THREAD_FPH_VALID) != 0)
472 memcpy(dst + 32, current->thread.fph, 96*16);
473 }
474
475 void
ia64_elf_core_copy_regs(struct pt_regs * pt,elf_gregset_t dst)476 ia64_elf_core_copy_regs (struct pt_regs *pt, elf_gregset_t dst)
477 {
478 unw_init_running(do_copy_regs, dst);
479 }
480
481 int
dump_fpu(struct pt_regs * pt,elf_fpregset_t dst)482 dump_fpu (struct pt_regs *pt, elf_fpregset_t dst)
483 {
484 unw_init_running(do_dump_fpu, dst);
485 return 1; /* f0-f31 are always valid so we always return 1 */
486 }
487
488 long
sys_execve(char * filename,char ** argv,char ** envp,struct pt_regs * regs)489 sys_execve (char *filename, char **argv, char **envp, struct pt_regs *regs)
490 {
491 int error;
492
493 filename = getname(filename);
494 error = PTR_ERR(filename);
495 if (IS_ERR(filename))
496 goto out;
497 error = do_execve(filename, argv, envp, regs);
498 putname(filename);
499 out:
500 return error;
501 }
502
503 void
ia64_set_personality(struct elf64_hdr * elf_ex,int ibcs2_interpreter)504 ia64_set_personality (struct elf64_hdr *elf_ex, int ibcs2_interpreter)
505 {
506 set_personality(PER_LINUX);
507 if (elf_ex->e_flags & EF_IA_64_LINUX_EXECUTABLE_STACK)
508 current->thread.flags |= IA64_THREAD_XSTACK;
509 else
510 current->thread.flags &= ~IA64_THREAD_XSTACK;
511 }
512
513 pid_t
arch_kernel_thread(int (* fn)(void *),void * arg,unsigned long flags)514 arch_kernel_thread (int (*fn)(void *), void *arg, unsigned long flags)
515 {
516 struct task_struct *parent = current;
517 int result, tid;
518
519 tid = clone(flags | CLONE_VM, 0);
520 if (parent != current) {
521 #ifdef CONFIG_IA32_SUPPORT
522 if (IS_IA32_PROCESS(ia64_task_regs(current))) {
523 /* A kernel thread is always a 64-bit process. */
524 current->thread.map_base = DEFAULT_MAP_BASE;
525 current->thread.task_size = DEFAULT_TASK_SIZE;
526 ia64_set_kr(IA64_KR_IO_BASE, current->thread.old_iob);
527 ia64_set_kr(IA64_KR_TSSD, current->thread.old_k1);
528 }
529 #endif
530 result = (*fn)(arg);
531 _exit(result);
532 }
533 return tid;
534 }
535
536 /*
537 * Flush thread state. This is called when a thread does an execve().
538 */
539 void
flush_thread(void)540 flush_thread (void)
541 {
542 /* drop floating-point and debug-register state if it exists: */
543 current->thread.flags &= ~(IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID);
544 ia64_drop_fpu(current);
545 }
546
547 #ifdef CONFIG_PERFMON
548 /*
549 * by the time we get here, the task is detached from the tasklist. This is important
550 * because it means that no other tasks can ever find it as a notified task, therfore there
551 * is no race condition between this code and let's say a pfm_context_create().
552 * Conversely, the pfm_cleanup_notifiers() cannot try to access a task's pfm context if this
553 * other task is in the middle of its own pfm_context_exit() because it would already be out of
554 * the task list. Note that this case is very unlikely between a direct child and its parents
555 * (if it is the notified process) because of the way the exit is notified via SIGCHLD.
556 */
557
558 void
release_thread(struct task_struct * task)559 release_thread (struct task_struct *task)
560 {
561 if (task->thread.pfm_context)
562 pfm_context_exit(task);
563
564 if (atomic_read(&task->thread.pfm_notifiers_check) > 0)
565 pfm_cleanup_notifiers(task);
566
567 if (atomic_read(&task->thread.pfm_owners_check) > 0)
568 pfm_cleanup_owners(task);
569
570 if (task->thread.pfm_smpl_buf_list)
571 pfm_cleanup_smpl_buf(task);
572 }
573 #endif
574
575 /*
576 * Clean up state associated with current thread. This is called when
577 * the thread calls exit().
578 */
579 void
exit_thread(void)580 exit_thread (void)
581 {
582 ia64_drop_fpu(current);
583 #ifdef CONFIG_PERFMON
584 /* stop monitoring */
585 if (current->thread.pfm_context)
586 pfm_flush_regs(current);
587
588 /* free debug register resources */
589 if (current->thread.flags & IA64_THREAD_DBG_VALID)
590 pfm_release_debug_registers(current);
591 #endif
592 }
593
594 unsigned long
get_wchan(struct task_struct * p)595 get_wchan (struct task_struct *p)
596 {
597 struct unw_frame_info info;
598 unsigned long ip;
599 int count = 0;
600 /*
601 * These bracket the sleeping functions..
602 */
603 extern void scheduling_functions_start_here(void);
604 extern void scheduling_functions_end_here(void);
605 # define first_sched ((unsigned long) scheduling_functions_start_here)
606 # define last_sched ((unsigned long) scheduling_functions_end_here)
607
608 /*
609 * Note: p may not be a blocked task (it could be current or
610 * another process running on some other CPU. Rather than
611 * trying to determine if p is really blocked, we just assume
612 * it's blocked and rely on the unwind routines to fail
613 * gracefully if the process wasn't really blocked after all.
614 * --davidm 99/12/15
615 */
616 unw_init_from_blocked_task(&info, p);
617 do {
618 if (unw_unwind(&info) < 0)
619 return 0;
620 unw_get_ip(&info, &ip);
621 if (ip < first_sched || ip >= last_sched)
622 return ip;
623 } while (count++ < 16);
624 return 0;
625 # undef first_sched
626 # undef last_sched
627 }
628
629 void
cpu_halt(void)630 cpu_halt (void)
631 {
632 pal_power_mgmt_info_u_t power_info[8];
633 unsigned long min_power;
634 int i, min_power_state;
635
636 if (ia64_pal_halt_info(power_info) != 0)
637 return;
638
639 min_power_state = 0;
640 min_power = power_info[0].pal_power_mgmt_info_s.power_consumption;
641 for (i = 1; i < 8; ++i)
642 if (power_info[i].pal_power_mgmt_info_s.im
643 && power_info[i].pal_power_mgmt_info_s.power_consumption < min_power) {
644 min_power = power_info[i].pal_power_mgmt_info_s.power_consumption;
645 min_power_state = i;
646 }
647
648 while (1)
649 ia64_pal_halt(min_power_state);
650 }
651
652 void
machine_restart(char * restart_cmd)653 machine_restart (char *restart_cmd)
654 {
655 (*efi.reset_system)(EFI_RESET_WARM, 0, 0, 0);
656 }
657
658 void
machine_halt(void)659 machine_halt (void)
660 {
661 cpu_halt();
662 }
663
664 void
machine_power_off(void)665 machine_power_off (void)
666 {
667 if (pm_power_off)
668 pm_power_off();
669 machine_halt();
670 }
671