^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Architecture-specific setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 1998-2003 Hewlett-Packard Co
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * David Mosberger-Tang <davidm@hpl.hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * 04/11/17 Ashok Raj <ashok.raj@intel.com> Added CPU Hotplug Support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * 2005-10-07 Keith Owens <kaos@sgi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Add notify_die() hooks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/personality.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/sched/debug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/sched/hotplug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/sched/task.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/sched/task_stack.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/thread_info.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/efi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/kdebug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/utsname.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/tracehook.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <asm/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <asm/elf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <asm/sal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <asm/unwind.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <asm/user.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <asm/xtp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include "entry.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include "sigframe.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) void (*ia64_mark_idle)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) EXPORT_SYMBOL(boot_option_idle_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void (*pm_power_off) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) EXPORT_SYMBOL(pm_power_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) ia64_do_show_stack (struct unw_frame_info *info, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) unsigned long ip, sp, bsp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) const char *loglvl = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) printk("%s\nCall Trace:\n", loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) unw_get_ip(info, &ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (ip == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) unw_get_sp(info, &sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) unw_get_bsp(info, &bsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) printk("%s [<%016lx>] %pS\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) " sp=%016lx bsp=%016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) loglvl, ip, (void *)ip, sp, bsp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) } while (unw_unwind(info) >= 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) show_stack (struct task_struct *task, unsigned long *sp, const char *loglvl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (!task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) unw_init_running(ia64_do_show_stack, (void *)loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct unw_frame_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) unw_init_from_blocked_task(&info, task);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ia64_do_show_stack(&info, (void *)loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) show_regs (struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) unsigned long ip = regs->cr_iip + ia64_psr(regs)->ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) print_modules();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) show_regs_print_info(KERN_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) printk("psr : %016lx ifs : %016lx ip : [<%016lx>] %s (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) regs->cr_ipsr, regs->cr_ifs, ip, print_tainted(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) init_utsname()->release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) printk("ip is at %pS\n", (void *)ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) printk("unat: %016lx pfs : %016lx rsc : %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) regs->ar_unat, regs->ar_pfs, regs->ar_rsc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) printk("rnat: %016lx bsps: %016lx pr : %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) regs->ar_rnat, regs->ar_bspstore, regs->pr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) printk("ldrs: %016lx ccv : %016lx fpsr: %016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) regs->loadrs, regs->ar_ccv, regs->ar_fpsr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) printk("csd : %016lx ssd : %016lx\n", regs->ar_csd, regs->ar_ssd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) printk("b0 : %016lx b6 : %016lx b7 : %016lx\n", regs->b0, regs->b6, regs->b7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) printk("f6 : %05lx%016lx f7 : %05lx%016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) regs->f6.u.bits[1], regs->f6.u.bits[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) regs->f7.u.bits[1], regs->f7.u.bits[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) printk("f8 : %05lx%016lx f9 : %05lx%016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) regs->f8.u.bits[1], regs->f8.u.bits[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) regs->f9.u.bits[1], regs->f9.u.bits[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) printk("f10 : %05lx%016lx f11 : %05lx%016lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) regs->f10.u.bits[1], regs->f10.u.bits[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) regs->f11.u.bits[1], regs->f11.u.bits[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) printk("r1 : %016lx r2 : %016lx r3 : %016lx\n", regs->r1, regs->r2, regs->r3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) printk("r8 : %016lx r9 : %016lx r10 : %016lx\n", regs->r8, regs->r9, regs->r10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) printk("r11 : %016lx r12 : %016lx r13 : %016lx\n", regs->r11, regs->r12, regs->r13);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) printk("r14 : %016lx r15 : %016lx r16 : %016lx\n", regs->r14, regs->r15, regs->r16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) printk("r17 : %016lx r18 : %016lx r19 : %016lx\n", regs->r17, regs->r18, regs->r19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) printk("r20 : %016lx r21 : %016lx r22 : %016lx\n", regs->r20, regs->r21, regs->r22);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) printk("r23 : %016lx r24 : %016lx r25 : %016lx\n", regs->r23, regs->r24, regs->r25);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) printk("r26 : %016lx r27 : %016lx r28 : %016lx\n", regs->r26, regs->r27, regs->r28);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) printk("r29 : %016lx r30 : %016lx r31 : %016lx\n", regs->r29, regs->r30, regs->r31);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (user_mode(regs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) /* print the stacked registers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) unsigned long val, *bsp, ndirty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int i, sof, is_nat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) sof = regs->cr_ifs & 0x7f; /* size of frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) ndirty = (regs->loadrs >> 19);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) bsp = ia64_rse_skip_regs((unsigned long *) regs->ar_bspstore, ndirty);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) for (i = 0; i < sof; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) get_user(val, (unsigned long __user *) ia64_rse_skip_regs(bsp, i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) printk("r%-3u:%c%016lx%s", 32 + i, is_nat ? '*' : ' ', val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ((i == sof - 1) || (i % 3) == 2) ? "\n" : " ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) show_stack(NULL, NULL, KERN_DEFAULT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) /* local support for deprecated console_print */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) console_print(const char *s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) printk(KERN_EMERG "%s", s);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) do_notify_resume_user(sigset_t *unused, struct sigscratch *scr, long in_syscall)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (fsys_mode(current, &scr->pt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * defer signal-handling etc. until we return to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * privilege-level 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (!ia64_psr(&scr->pt)->lp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) ia64_psr(&scr->pt)->lp = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /* deal with pending signal delivery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (test_thread_flag(TIF_SIGPENDING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) local_irq_enable(); /* force interrupt enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) ia64_do_signal(scr, in_syscall);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (test_thread_flag(TIF_NOTIFY_RESUME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) local_irq_enable(); /* force interrupt enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) tracehook_notify_resume(&scr->pt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* copy user rbs to kernel rbs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) if (unlikely(test_thread_flag(TIF_RESTORE_RSE))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) local_irq_enable(); /* force interrupt enable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) ia64_sync_krbs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) local_irq_disable(); /* force interrupt disable */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static int __init nohalt_setup(char * str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) cpu_idle_poll_ctrl(true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) __setup("nohalt", nohalt_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) #ifdef CONFIG_HOTPLUG_CPU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* We don't actually take CPU down, just spin without interrupts. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static inline void play_dead(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned int this_cpu = smp_processor_id();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Ack it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) __this_cpu_write(cpu_state, CPU_DEAD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) max_xtp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) idle_task_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ia64_jump_to_sal(&sal_boot_rendez_state[this_cpu]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * The above is a point of no-return, the processor is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * expected to be in SAL loop now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static inline void play_dead(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) #endif /* CONFIG_HOTPLUG_CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) void arch_cpu_idle_dead(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) play_dead();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) void arch_cpu_idle(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) void (*mark_idle)(int) = ia64_mark_idle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) min_xtp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) rmb();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (mark_idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) (*mark_idle)(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) raw_safe_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (mark_idle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) (*mark_idle)(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) normal_xtp();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) ia64_save_extra (struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ia64_save_debug_regs(&task->thread.dbr[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) ia64_load_extra (struct task_struct *task)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) if ((task->thread.flags & IA64_THREAD_DBG_VALID) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ia64_load_debug_regs(&task->thread.dbr[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * Copy the state of an ia-64 thread.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * We get here through the following call chain:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * from user-level: from kernel:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * <clone syscall> <some kernel call frames>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * sys_clone :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * kernel_clone kernel_clone
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * copy_thread copy_thread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * This means that the stack layout is as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * +---------------------+ (highest addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * | struct pt_regs |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * +---------------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) * | struct switch_stack |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) * +---------------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) * | |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) * | memory stack |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) * | | <-- sp (lowest addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) * +---------------------+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) * Observe that we copy the unat values that are in pt_regs and switch_stack. Spilling an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * integer to address X causes bit N in ar.unat to be set to the NaT bit of the register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) * with N=(X & 0x1ff)/8. Thus, copying the unat value preserves the NaT bits ONLY if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) * pt_regs structure in the parent is congruent to that of the child, modulo 512. Since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * the stack is page aligned and the page size is at least 4KB, this is always the case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * so there is nothing to worry about.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) copy_thread(unsigned long clone_flags, unsigned long user_stack_base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) unsigned long user_stack_size, struct task_struct *p, unsigned long tls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) extern char ia64_ret_from_clone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) struct switch_stack *child_stack, *stack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) unsigned long rbs, child_rbs, rbs_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) struct pt_regs *child_ptregs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct pt_regs *regs = current_pt_regs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) child_ptregs = (struct pt_regs *) ((unsigned long) p + IA64_STK_OFFSET) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) child_stack = (struct switch_stack *) child_ptregs - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) rbs = (unsigned long) current + IA64_RBS_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) child_rbs = (unsigned long) p + IA64_RBS_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) /* copy parts of thread_struct: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) p->thread.ksp = (unsigned long) child_stack - 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) * NOTE: The calling convention considers all floating point
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) * registers in the high partition (fph) to be scratch. Since
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) * the only way to get to this point is through a system call,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * we know that the values in fph are all dead. Hence, there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * is no need to inherit the fph state from the parent to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * child and all we have to do is to make sure that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * IA64_THREAD_FPH_VALID is cleared in the child.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * XXX We could push this optimization a bit further by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * clearing IA64_THREAD_FPH_VALID on ANY system call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * However, it's not clear this is worth doing. Also, it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * would be a slight deviation from the normal Linux system
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * call behavior where scratch registers are preserved across
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * system calls (unless used by the system call itself).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) # define THREAD_FLAGS_TO_CLEAR (IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) | IA64_THREAD_PM_VALID)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) # define THREAD_FLAGS_TO_SET 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) p->thread.flags = ((current->thread.flags & ~THREAD_FLAGS_TO_CLEAR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) | THREAD_FLAGS_TO_SET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) ia64_drop_fpu(p); /* don't pick up stale state from a CPU's fph */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (unlikely(p->flags & PF_KTHREAD)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) if (unlikely(!user_stack_base)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* fork_idle() called us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) memset(child_stack, 0, sizeof(*child_ptregs) + sizeof(*child_stack));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) child_stack->r4 = user_stack_base; /* payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) child_stack->r5 = user_stack_size; /* argument */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) * Preserve PSR bits, except for bits 32-34 and 37-45,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * which we can't read.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) child_ptregs->cr_ipsr = ia64_getreg(_IA64_REG_PSR) | IA64_PSR_BN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /* mark as valid, empty frame */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) child_ptregs->cr_ifs = 1UL << 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) child_stack->ar_fpsr = child_ptregs->ar_fpsr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) = ia64_getreg(_IA64_REG_AR_FPSR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) child_stack->pr = (1 << PRED_KERNEL_STACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) child_stack->ar_bspstore = child_rbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) child_stack->b0 = (unsigned long) &ia64_ret_from_clone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) /* stop some PSR bits from being inherited.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * the psr.up/psr.pp bits must be cleared on fork but inherited on execve()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * therefore we must specify them explicitly here and not include them in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * IA64_PSR_BITS_TO_CLEAR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) child_ptregs->cr_ipsr = ((child_ptregs->cr_ipsr | IA64_PSR_BITS_TO_SET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_PP | IA64_PSR_UP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) stack = ((struct switch_stack *) regs) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) /* copy parent's switch_stack & pt_regs to child: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) memcpy(child_stack, stack, sizeof(*child_ptregs) + sizeof(*child_stack));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) /* copy the parent's register backing store to the child: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) rbs_size = stack->ar_bspstore - rbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) memcpy((void *) child_rbs, (void *) rbs, rbs_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) if (clone_flags & CLONE_SETTLS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) child_ptregs->r13 = tls;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (user_stack_base) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) child_ptregs->r12 = user_stack_base + user_stack_size - 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) child_ptregs->ar_bspstore = user_stack_base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) child_ptregs->ar_rnat = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) child_ptregs->loadrs = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) child_stack->ar_bspstore = child_rbs + rbs_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) child_stack->b0 = (unsigned long) &ia64_ret_from_clone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /* stop some PSR bits from being inherited.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * the psr.up/psr.pp bits must be cleared on fork but inherited on execve()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) * therefore we must specify them explicitly here and not include them in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * IA64_PSR_BITS_TO_CLEAR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) child_ptregs->cr_ipsr = ((child_ptregs->cr_ipsr | IA64_PSR_BITS_TO_SET)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) & ~(IA64_PSR_BITS_TO_CLEAR | IA64_PSR_PP | IA64_PSR_UP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) asmlinkage long ia64_clone(unsigned long clone_flags, unsigned long stack_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) unsigned long stack_size, unsigned long parent_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) unsigned long child_tidptr, unsigned long tls)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) struct kernel_clone_args args = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) .flags = (lower_32_bits(clone_flags) & ~CSIGNAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) .pidfd = (int __user *)parent_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) .child_tid = (int __user *)child_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) .parent_tid = (int __user *)parent_tidptr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) .exit_signal = (lower_32_bits(clone_flags) & CSIGNAL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) .stack = stack_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) .stack_size = stack_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) .tls = tls,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return kernel_clone(&args);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) do_copy_task_regs (struct task_struct *task, struct unw_frame_info *info, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) unsigned long mask, sp, nat_bits = 0, ar_rnat, urbs_end, cfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) unsigned long ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) elf_greg_t *dst = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) struct pt_regs *pt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) char nat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) memset(dst, 0, sizeof(elf_gregset_t)); /* don't leak any kernel bits to user-level */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (unw_unwind_to_user(info) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) unw_get_sp(info, &sp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) pt = (struct pt_regs *) (sp + 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) urbs_end = ia64_get_user_rbs_end(task, pt, &cfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) if (ia64_sync_user_rbs(task, info->sw, pt->ar_bspstore, urbs_end) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) ia64_peek(task, info->sw, urbs_end, (long) ia64_rse_rnat_addr((long *) urbs_end),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) &ar_rnat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) * coredump format:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * r0-r31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * NaT bits (for r0-r31; bit N == 1 iff rN is a NaT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * predicate registers (p0-p63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * b0-b7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * ip cfm user-mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * ar.rsc ar.bsp ar.bspstore ar.rnat
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * ar.ccv ar.unat ar.fpsr ar.pfs ar.lc ar.ec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /* r0 is zero */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) for (i = 1, mask = (1UL << i); i < 32; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) unw_get_gr(info, i, &dst[i], &nat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (nat)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) nat_bits |= mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) mask <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) dst[32] = nat_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) unw_get_pr(info, &dst[33]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) for (i = 0; i < 8; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) unw_get_br(info, i, &dst[34 + i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) unw_get_rp(info, &ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) dst[42] = ip + ia64_psr(pt)->ri;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) dst[43] = cfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) dst[44] = pt->cr_ipsr & IA64_PSR_UM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) unw_get_ar(info, UNW_AR_RSC, &dst[45]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * For bsp and bspstore, unw_get_ar() would return the kernel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * addresses, but we need the user-level addresses instead:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) dst[46] = urbs_end; /* note: by convention PT_AR_BSP points to the end of the urbs! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) dst[47] = pt->ar_bspstore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) dst[48] = ar_rnat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) unw_get_ar(info, UNW_AR_CCV, &dst[49]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) unw_get_ar(info, UNW_AR_UNAT, &dst[50]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) unw_get_ar(info, UNW_AR_FPSR, &dst[51]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) dst[52] = pt->ar_pfs; /* UNW_AR_PFS is == to pt->cr_ifs for interrupt frames */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) unw_get_ar(info, UNW_AR_LC, &dst[53]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) unw_get_ar(info, UNW_AR_EC, &dst[54]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) unw_get_ar(info, UNW_AR_CSD, &dst[55]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) unw_get_ar(info, UNW_AR_SSD, &dst[56]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) do_copy_regs (struct unw_frame_info *info, void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) do_copy_task_regs(current, info, arg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) ia64_elf_core_copy_regs (struct pt_regs *pt, elf_gregset_t dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) unw_init_running(do_copy_regs, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * Flush thread state. This is called when a thread does an execve().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) flush_thread (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) /* drop floating-point and debug-register state if it exists: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) current->thread.flags &= ~(IA64_THREAD_FPH_VALID | IA64_THREAD_DBG_VALID);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) ia64_drop_fpu(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) * Clean up state associated with a thread. This is called when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * the thread calls exit().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) exit_thread (struct task_struct *tsk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) ia64_drop_fpu(tsk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) get_wchan (struct task_struct *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) struct unw_frame_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) unsigned long ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (!p || p == current || p->state == TASK_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) * Note: p may not be a blocked task (it could be current or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * another process running on some other CPU. Rather than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) * trying to determine if p is really blocked, we just assume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) * it's blocked and rely on the unwind routines to fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) * gracefully if the process wasn't really blocked after all.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * --davidm 99/12/15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) unw_init_from_blocked_task(&info, p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (p->state == TASK_RUNNING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) if (unw_unwind(&info) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) unw_get_ip(&info, &ip);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) if (!in_sched_functions(ip))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) return ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) } while (count++ < 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) cpu_halt (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) pal_power_mgmt_info_u_t power_info[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) unsigned long min_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) int i, min_power_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (ia64_pal_halt_info(power_info) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) min_power_state = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) min_power = power_info[0].pal_power_mgmt_info_s.power_consumption;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) for (i = 1; i < 8; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (power_info[i].pal_power_mgmt_info_s.im
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) && power_info[i].pal_power_mgmt_info_s.power_consumption < min_power) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) min_power = power_info[i].pal_power_mgmt_info_s.power_consumption;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) min_power_state = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) while (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) ia64_pal_halt(min_power_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) void machine_shutdown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) smp_shutdown_nonboot_cpus(reboot_cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) #ifdef CONFIG_KEXEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) kexec_disable_iosapic();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) machine_restart (char *restart_cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) (void) notify_die(DIE_MACHINE_RESTART, restart_cmd, NULL, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) efi_reboot(REBOOT_WARM, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) machine_halt (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) (void) notify_die(DIE_MACHINE_HALT, "", NULL, 0, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) cpu_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) machine_power_off (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) if (pm_power_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) pm_power_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) machine_halt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) EXPORT_SYMBOL(ia64_delay_loop);