]> git.ipfire.org Git - thirdparty/linux.git/blame - arch/csky/kernel/process.c
Merge tag 'io_uring-5.7-2020-05-22' of git://git.kernel.dk/linux-block
[thirdparty/linux.git] / arch / csky / kernel / process.c
CommitLineData
e9564df7
GR
1// SPDX-License-Identifier: GPL-2.0
2// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
3
4#include <linux/module.h>
5#include <linux/version.h>
6#include <linux/sched.h>
7#include <linux/sched/task_stack.h>
8#include <linux/sched/debug.h>
9#include <linux/delay.h>
10#include <linux/kallsyms.h>
11#include <linux/uaccess.h>
12#include <linux/ptrace.h>
13
14#include <asm/elf.h>
15#include <abi/reg_ops.h>
16
17struct cpuinfo_csky cpu_data[NR_CPUS];
18
2f78c73f
MH
19#ifdef CONFIG_STACKPROTECTOR
20#include <linux/stackprotector.h>
21unsigned long __stack_chk_guard __read_mostly;
22EXPORT_SYMBOL(__stack_chk_guard);
23#endif
24
e9564df7
GR
25asmlinkage void ret_from_fork(void);
26asmlinkage void ret_from_kernel_thread(void);
27
28/*
29 * Some archs flush debug and FPU info here
30 */
31void flush_thread(void){}
32
33/*
34 * Return saved PC from a blocked thread
35 */
36unsigned long thread_saved_pc(struct task_struct *tsk)
37{
67002814 38 struct switch_stack *sw = (struct switch_stack *)tsk->thread.sp;
e9564df7
GR
39
40 return sw->r15;
41}
42
0b9f386c 43int copy_thread_tls(unsigned long clone_flags,
e9564df7
GR
44 unsigned long usp,
45 unsigned long kthread_arg,
0b9f386c
GR
46 struct task_struct *p,
47 unsigned long tls)
e9564df7
GR
48{
49 struct switch_stack *childstack;
50 struct pt_regs *childregs = task_pt_regs(p);
51
52#ifdef CONFIG_CPU_HAS_FPU
53 save_to_user_fp(&p->thread.user_fp);
54#endif
55
56 childstack = ((struct switch_stack *) childregs) - 1;
57 memset(childstack, 0, sizeof(struct switch_stack));
58
67002814
GR
59 /* setup thread.sp for switch_to !!! */
60 p->thread.sp = (unsigned long)childstack;
e9564df7
GR
61
62 if (unlikely(p->flags & PF_KTHREAD)) {
63 memset(childregs, 0, sizeof(struct pt_regs));
64 childstack->r15 = (unsigned long) ret_from_kernel_thread;
48ede51f 65 childstack->r10 = kthread_arg;
e9564df7
GR
66 childstack->r9 = usp;
67 childregs->sr = mfcr("psr");
68 } else {
69 *childregs = *(current_pt_regs());
70 if (usp)
71 childregs->usp = usp;
72 if (clone_flags & CLONE_SETTLS)
73 task_thread_info(p)->tp_value = childregs->tls
0b9f386c 74 = tls;
e9564df7
GR
75
76 childregs->a0 = 0;
77 childstack->r15 = (unsigned long) ret_from_fork;
78 }
79
80 return 0;
81}
82
83/* Fill in the fpu structure for a core dump. */
84int dump_fpu(struct pt_regs *regs, struct user_fp *fpu)
85{
86 memcpy(fpu, &current->thread.user_fp, sizeof(*fpu));
87 return 1;
88}
89EXPORT_SYMBOL(dump_fpu);
90
91int dump_task_regs(struct task_struct *tsk, elf_gregset_t *pr_regs)
92{
93 struct pt_regs *regs = task_pt_regs(tsk);
94
95 /* NOTE: usp is error value. */
96 ELF_CORE_COPY_REGS((*pr_regs), regs)
97
98 return 1;
99}
100
e9564df7
GR
101#ifndef CONFIG_CPU_PM_NONE
102void arch_cpu_idle(void)
103{
104#ifdef CONFIG_CPU_PM_WAIT
105 asm volatile("wait\n");
106#endif
107
108#ifdef CONFIG_CPU_PM_DOZE
109 asm volatile("doze\n");
110#endif
111
112#ifdef CONFIG_CPU_PM_STOP
113 asm volatile("stop\n");
114#endif
115 local_irq_enable();
116}
117#endif