// SPDX-License-Identifier: GPL-2.0-or-later1/*2* PARISC Architecture-dependent parts of process handling3* based on the work for i3864*5* Copyright (C) 1999-2003 Matthew Wilcox <willy at parisc-linux.org>6* Copyright (C) 2000 Martin K Petersen <mkp at mkp.net>7* Copyright (C) 2000 John Marvin <jsm at parisc-linux.org>8* Copyright (C) 2000 David Huggins-Daines <dhd with pobox.org>9* Copyright (C) 2000-2003 Paul Bame <bame at parisc-linux.org>10* Copyright (C) 2000 Philipp Rumpf <prumpf with tux.org>11* Copyright (C) 2000 David Kennedy <dkennedy with linuxcare.com>12* Copyright (C) 2000 Richard Hirst <rhirst with parisc-linux.org>13* Copyright (C) 2000 Grant Grundler <grundler with parisc-linux.org>14* Copyright (C) 2001 Alan Modra <amodra at parisc-linux.org>15* Copyright (C) 2001-2002 Ryan Bradetich <rbrad at parisc-linux.org>16* Copyright (C) 2001-2014 Helge Deller <[email protected]>17* Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>18*/19#include <linux/elf.h>20#include <linux/errno.h>21#include <linux/kernel.h>22#include <linux/mm.h>23#include <linux/fs.h>24#include <linux/cpu.h>25#include <linux/module.h>26#include <linux/personality.h>27#include <linux/ptrace.h>28#include <linux/reboot.h>29#include <linux/sched.h>30#include <linux/sched/debug.h>31#include <linux/sched/task.h>32#include <linux/sched/task_stack.h>33#include <linux/slab.h>34#include <linux/stddef.h>35#include <linux/unistd.h>36#include <linux/kallsyms.h>37#include <linux/uaccess.h>38#include <linux/rcupdate.h>39#include <linux/random.h>40#include <linux/nmi.h>41#include <linux/sched/hotplug.h>4243#include <asm/io.h>44#include <asm/asm-offsets.h>45#include <asm/assembly.h>46#include <asm/pdc.h>47#include <asm/pdc_chassis.h>48#include <asm/unwind.h>49#include <asm/sections.h>50#include <asm/cacheflush.h>5152#define COMMAND_GLOBAL F_EXTEND(0xfffe0030)53#define CMD_RESET 5 /* reset any module */5455/*56** The Wright Brothers and Gecko systems have a H/W problem57** (Lasi...'nuf said) may cause a broadcast reset to lockup58** the system. An HVERSION dependent PDC call was developed59** to perform a "safe", platform specific broadcast reset instead60** of kludging up all the code.61**62** Older machines which do not implement PDC_BROADCAST_RESET will63** return (with an error) and the regular broadcast reset can be64** issued. Obviously, if the PDC does implement PDC_BROADCAST_RESET65** the PDC call will not return (the system will be reset).66*/67void machine_restart(char *cmd)68{69#ifdef FASTBOOT_SELFTEST_SUPPORT70/*71** If user has modified the Firmware Selftest Bitmap,72** run the tests specified in the bitmap after the73** system is rebooted w/PDC_DO_RESET.74**75** ftc_bitmap = 0x1AUL "Skip destructive memory tests"76**77** Using "directed resets" at each processor with the MEM_TOC78** vector cleared will also avoid running destructive79** memory self tests. (Not implemented yet)80*/81if (ftc_bitmap) {82pdc_do_firm_test_reset(ftc_bitmap);83}84#endif85/* set up a new led state on systems shipped with a LED State panel */86pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);8788/* "Normal" system reset */89pdc_do_reset();9091/* Nope...box should reset with just CMD_RESET now */92gsc_writel(CMD_RESET, COMMAND_GLOBAL);9394/* Wait for RESET to lay us to rest. */95while (1) ;9697}9899/*100* This routine is called from sys_reboot to actually turn off the101* machine102*/103void machine_power_off(void)104{105/* Put the soft power button back under hardware control.106* If the user had already pressed the power button, the107* following call will immediately power off. */108pdc_soft_power_button(0);109110pdc_chassis_send_status(PDC_CHASSIS_DIRECT_SHUTDOWN);111112/* ipmi_poweroff may have been installed. */113do_kernel_power_off();114115/* It seems we have no way to power the system off via116* software. The user has to press the button himself. */117118printk("Power off or press RETURN to reboot.\n");119120/* prevent soft lockup/stalled CPU messages for endless loop. */121rcu_sysrq_start();122lockup_detector_soft_poweroff();123while (1) {124/* reboot if user presses RETURN key */125if (pdc_iodc_getc() == 13) {126printk("Rebooting...\n");127machine_restart(NULL);128}129}130}131132void (*pm_power_off)(void);133EXPORT_SYMBOL(pm_power_off);134135void machine_halt(void)136{137machine_power_off();138}139140void flush_thread(void)141{142/* Only needs to handle fpu stuff or perf monitors.143** REVISIT: several arches implement a "lazy fpu state".144*/145}146147/*148* Idle thread support149*150* Detect when running on QEMU with SeaBIOS PDC Firmware and let151* QEMU idle the host too.152*/153154int running_on_qemu __ro_after_init;155EXPORT_SYMBOL(running_on_qemu);156157/*158* Called from the idle thread for the CPU which has been shutdown.159*/160void __noreturn arch_cpu_idle_dead(void)161{162#ifdef CONFIG_HOTPLUG_CPU163idle_task_exit();164165local_irq_disable();166167/* Tell the core that this CPU is now safe to dispose of. */168cpuhp_ap_report_dead();169170/* Ensure that the cache lines are written out. */171flush_cache_all_local();172flush_tlb_all_local(NULL);173174/* Let PDC firmware put CPU into firmware idle loop. */175__pdc_cpu_rendezvous();176177pr_warn("PDC does not provide rendezvous function.\n");178#endif179while (1);180}181182void __cpuidle arch_cpu_idle(void)183{184/* nop on real hardware, qemu will idle sleep. */185asm volatile("or %%r10,%%r10,%%r10\n":::);186}187188static int __init parisc_idle_init(void)189{190if (!running_on_qemu)191cpu_idle_poll_ctrl(1);192193return 0;194}195arch_initcall(parisc_idle_init);196197/*198* Copy architecture-specific thread state199*/200int201copy_thread(struct task_struct *p, const struct kernel_clone_args *args)202{203unsigned long clone_flags = args->flags;204unsigned long usp = args->stack;205unsigned long tls = args->tls;206struct pt_regs *cregs = &(p->thread.regs);207void *stack = task_stack_page(p);208209/* We have to use void * instead of a function pointer, because210* function pointers aren't a pointer to the function on 64-bit.211* Make them const so the compiler knows they live in .text */212extern void * const ret_from_kernel_thread;213extern void * const child_return;214215if (unlikely(args->fn)) {216/* kernel thread */217memset(cregs, 0, sizeof(struct pt_regs));218if (args->idle) /* idle thread */219return 0;220/* Must exit via ret_from_kernel_thread in order221* to call schedule_tail()222*/223cregs->ksp = (unsigned long) stack + FRAME_SIZE + PT_SZ_ALGN;224cregs->kpc = (unsigned long) &ret_from_kernel_thread;225/*226* Copy function and argument to be called from227* ret_from_kernel_thread.228*/229#ifdef CONFIG_64BIT230cregs->gr[27] = ((unsigned long *)args->fn)[3];231cregs->gr[26] = ((unsigned long *)args->fn)[2];232#else233cregs->gr[26] = (unsigned long) args->fn;234#endif235cregs->gr[25] = (unsigned long) args->fn_arg;236} else {237/* user thread */238/* usp must be word aligned. This also prevents users from239* passing in the value 1 (which is the signal for a special240* return for a kernel thread) */241if (usp) {242usp = ALIGN(usp, 4);243if (likely(usp))244cregs->gr[30] = usp;245}246cregs->ksp = (unsigned long) stack + FRAME_SIZE;247cregs->kpc = (unsigned long) &child_return;248249/* Setup thread TLS area */250if (clone_flags & CLONE_SETTLS)251cregs->cr27 = tls;252}253254return 0;255}256257unsigned long258__get_wchan(struct task_struct *p)259{260struct unwind_frame_info info;261unsigned long ip;262int count = 0;263264/*265* These bracket the sleeping functions..266*/267268unwind_frame_init_from_blocked_task(&info, p);269do {270if (unwind_once(&info) < 0)271return 0;272if (task_is_running(p))273return 0;274ip = info.ip;275if (!in_sched_functions(ip))276return ip;277} while (count++ < MAX_UNWIND_ENTRIES);278return 0;279}280281282