]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/score/kernel/process.c
Merge branch 'sh/dynamic-irq-cleanup' into sh-latest
[karo-tx-linux.git] / arch / score / kernel / process.c
1 /*
2  * arch/score/kernel/process.c
3  *
4  * Score Processor version.
5  *
6  * Copyright (C) 2009 Sunplus Core Technology Co., Ltd.
7  *  Chen Liqin <liqin.chen@sunplusct.com>
8  *  Lennox Wu <lennox.wu@sunplusct.com>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, see the file COPYING, or write
22  * to the Free Software Foundation, Inc.,
23  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24  */
25
26 #include <linux/module.h>
27 #include <linux/reboot.h>
28 #include <linux/elfcore.h>
29 #include <linux/pm.h>
30
31 void (*pm_power_off)(void);
32 EXPORT_SYMBOL(pm_power_off);
33
34 /* If or when software machine-restart is implemented, add code here. */
35 void machine_restart(char *command) {}
36
37 /* If or when software machine-halt is implemented, add code here. */
38 void machine_halt(void) {}
39
40 /* If or when software machine-power-off is implemented, add code here. */
41 void machine_power_off(void) {}
42
43 /*
44  * The idle thread. There's no useful work to be
45  * done, so just try to conserve power and have a
46  * low exit latency (ie sit in a loop waiting for
47  * somebody to say that they'd like to reschedule)
48  */
49 void __noreturn cpu_idle(void)
50 {
51         /* endless idle loop with no priority at all */
52         while (1) {
53                 while (!need_resched())
54                         barrier();
55
56                 schedule_preempt_disabled();
57         }
58 }
59
60 void ret_from_fork(void);
61
62 void start_thread(struct pt_regs *regs, unsigned long pc, unsigned long sp)
63 {
64         unsigned long status;
65
66         /* New thread loses kernel privileges. */
67         status = regs->cp0_psr & ~(KU_MASK);
68         status |= KU_USER;
69         regs->cp0_psr = status;
70         regs->cp0_epc = pc;
71         regs->regs[0] = sp;
72 }
73
74 void exit_thread(void) {}
75
76 /*
77  * When a process does an "exec", machine state like FPU and debug
78  * registers need to be reset.  This is a hook function for that.
79  * Currently we don't have any such state to reset, so this is empty.
80  */
81 void flush_thread(void) {}
82
83 /*
84  * set up the kernel stack and exception frames for a new process
85  */
86 int copy_thread(unsigned long clone_flags, unsigned long usp,
87                 unsigned long unused,
88                 struct task_struct *p, struct pt_regs *regs)
89 {
90         struct thread_info *ti = task_thread_info(p);
91         struct pt_regs *childregs = task_pt_regs(p);
92
93         p->set_child_tid = NULL;
94         p->clear_child_tid = NULL;
95
96         *childregs = *regs;
97         childregs->regs[7] = 0;         /* Clear error flag */
98         childregs->regs[4] = 0;         /* Child gets zero as return value */
99         regs->regs[4] = p->pid;
100
101         if (childregs->cp0_psr & 0x8) { /* test kernel fork or user fork */
102                 childregs->regs[0] = usp;               /* user fork */
103         } else {
104                 childregs->regs[28] = (unsigned long) ti; /* kernel fork */
105                 childregs->regs[0] = (unsigned long) childregs;
106         }
107
108         p->thread.reg0 = (unsigned long) childregs;
109         p->thread.reg3 = (unsigned long) ret_from_fork;
110         p->thread.cp0_psr = 0;
111
112         return 0;
113 }
114
115 /* Fill in the fpu structure for a core dump. */
116 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *r)
117 {
118         return 1;
119 }
120
121 static void __noreturn
122 kernel_thread_helper(void *unused0, int (*fn)(void *),
123                  void *arg, void *unused1)
124 {
125         do_exit(fn(arg));
126 }
127
128 /*
129  * Create a kernel thread.
130  */
131 long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
132 {
133         struct pt_regs regs;
134
135         memset(&regs, 0, sizeof(regs));
136
137         regs.regs[6] = (unsigned long) arg;
138         regs.regs[5] = (unsigned long) fn;
139         regs.cp0_epc = (unsigned long) kernel_thread_helper;
140         regs.cp0_psr = (regs.cp0_psr & ~(0x1|0x4|0x8)) | \
141                         ((regs.cp0_psr & 0x3) << 2);
142
143         return do_fork(flags | CLONE_VM | CLONE_UNTRACED, \
144                         0, &regs, 0, NULL, NULL);
145 }
146
147 unsigned long thread_saved_pc(struct task_struct *tsk)
148 {
149         return task_pt_regs(tsk)->cp0_epc;
150 }
151
152 unsigned long get_wchan(struct task_struct *task)
153 {
154         if (!task || task == current || task->state == TASK_RUNNING)
155                 return 0;
156
157         if (!task_stack_page(task))
158                 return 0;
159
160         return task_pt_regs(task)->cp0_epc;
161 }
162
163 unsigned long arch_align_stack(unsigned long sp)
164 {
165         return sp;
166 }