]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/unicore32/kernel/process.c
sched/headers: Prepare for new header dependencies before moving code to <linux/sched...
[mirror_ubuntu-artful-kernel.git] / arch / unicore32 / kernel / process.c
CommitLineData
f73670e8
G
1/*
2 * linux/arch/unicore32/kernel/process.c
3 *
4 * Code specific to PKUnity SoC and UniCore ISA
5 *
6 * Copyright (C) 2001-2010 GUAN Xue-tao
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <stdarg.h>
13
14#include <linux/module.h>
15#include <linux/sched.h>
b17b0153 16#include <linux/sched/debug.h>
f73670e8
G
17#include <linux/kernel.h>
18#include <linux/mm.h>
19#include <linux/stddef.h>
20#include <linux/unistd.h>
21#include <linux/delay.h>
22#include <linux/reboot.h>
23#include <linux/interrupt.h>
24#include <linux/kallsyms.h>
25#include <linux/init.h>
26#include <linux/cpu.h>
27#include <linux/elfcore.h>
28#include <linux/pm.h>
29#include <linux/tick.h>
30#include <linux/utsname.h>
31#include <linux/uaccess.h>
32#include <linux/random.h>
33#include <linux/gpio.h>
34#include <linux/stacktrace.h>
35
36#include <asm/cacheflush.h>
37#include <asm/processor.h>
f73670e8
G
38#include <asm/stacktrace.h>
39
40#include "setup.h"
41
42static const char * const processor_modes[] = {
43 "UK00", "UK01", "UK02", "UK03", "UK04", "UK05", "UK06", "UK07",
44 "UK08", "UK09", "UK0A", "UK0B", "UK0C", "UK0D", "UK0E", "UK0F",
45 "USER", "REAL", "INTR", "PRIV", "UK14", "UK15", "UK16", "ABRT",
46 "UK18", "UK19", "UK1A", "EXTN", "UK1C", "UK1D", "UK1E", "SUSR"
47};
48
aba92c9e 49void arch_cpu_idle(void)
f73670e8 50{
aba92c9e
TG
51 cpu_do_idle();
52 local_irq_enable();
f73670e8
G
53}
54
f73670e8
G
55void machine_halt(void)
56{
57 gpio_set_value(GPO_SOFT_OFF, 0);
58}
59
60/*
61 * Function pointers to optional machine specific functions
62 */
63void (*pm_power_off)(void) = NULL;
3420d49d 64EXPORT_SYMBOL(pm_power_off);
f73670e8
G
65
66void machine_power_off(void)
67{
68 if (pm_power_off)
69 pm_power_off();
70 machine_halt();
71}
72
73void machine_restart(char *cmd)
74{
75 /* Disable interrupts first */
76 local_irq_disable();
77
78 /*
79 * Tell the mm system that we are going to reboot -
80 * we may need it to insert some 1:1 mappings so that
81 * soft boot works.
82 */
c97a7008 83 setup_mm_for_reboot();
f73670e8
G
84
85 /* Clean and invalidate caches */
86 flush_cache_all();
87
88 /* Turn off caching */
89 cpu_proc_fin();
90
91 /* Push out any further dirty data, and ensure cache is empty */
92 flush_cache_all();
93
94 /*
95 * Now handle reboot code.
96 */
c97a7008 97 if (reboot_mode == REBOOT_SOFT) {
f73670e8
G
98 /* Jump into ROM at address 0xffff0000 */
99 cpu_reset(VECTORS_BASE);
100 } else {
e5abf78b
G
101 writel(0x00002001, PM_PLLSYSCFG); /* cpu clk = 250M */
102 writel(0x00100800, PM_PLLDDRCFG); /* ddr clk = 44M */
103 writel(0x00002001, PM_PLLVGACFG); /* vga clk = 250M */
f73670e8
G
104
105 /* Use on-chip reset capability */
106 /* following instructions must be in one icache line */
107 __asm__ __volatile__(
108 " .align 5\n\t"
109 " stw %1, [%0]\n\t"
110 "201: ldw r0, [%0]\n\t"
111 " cmpsub.a r0, #0\n\t"
112 " bne 201b\n\t"
113 " stw %3, [%2]\n\t"
114 " nop; nop; nop\n\t"
115 /* prefetch 3 instructions at most */
116 :
e5abf78b 117 : "r" (PM_PMCR),
f73670e8
G
118 "r" (PM_PMCR_CFBSYS | PM_PMCR_CFBDDR
119 | PM_PMCR_CFBVGA),
e5abf78b 120 "r" (RESETC_SWRR),
f73670e8
G
121 "r" (RESETC_SWRR_SRB)
122 : "r0", "memory");
123 }
124
125 /*
126 * Whoops - the architecture was unable to reboot.
127 * Tell the user!
128 */
129 mdelay(1000);
130 printk(KERN_EMERG "Reboot failed -- System halted\n");
131 do { } while (1);
132}
133
134void __show_regs(struct pt_regs *regs)
135{
136 unsigned long flags;
137 char buf[64];
138
a43cb95d 139 show_regs_print_info(KERN_DEFAULT);
f73670e8
G
140 print_symbol("PC is at %s\n", instruction_pointer(regs));
141 print_symbol("LR is at %s\n", regs->UCreg_lr);
142 printk(KERN_DEFAULT "pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
143 "sp : %08lx ip : %08lx fp : %08lx\n",
144 regs->UCreg_pc, regs->UCreg_lr, regs->UCreg_asr,
145 regs->UCreg_sp, regs->UCreg_ip, regs->UCreg_fp);
146 printk(KERN_DEFAULT "r26: %08lx r25: %08lx r24: %08lx\n",
147 regs->UCreg_26, regs->UCreg_25,
148 regs->UCreg_24);
149 printk(KERN_DEFAULT "r23: %08lx r22: %08lx r21: %08lx r20: %08lx\n",
150 regs->UCreg_23, regs->UCreg_22,
151 regs->UCreg_21, regs->UCreg_20);
152 printk(KERN_DEFAULT "r19: %08lx r18: %08lx r17: %08lx r16: %08lx\n",
153 regs->UCreg_19, regs->UCreg_18,
154 regs->UCreg_17, regs->UCreg_16);
155 printk(KERN_DEFAULT "r15: %08lx r14: %08lx r13: %08lx r12: %08lx\n",
156 regs->UCreg_15, regs->UCreg_14,
157 regs->UCreg_13, regs->UCreg_12);
158 printk(KERN_DEFAULT "r11: %08lx r10: %08lx r9 : %08lx r8 : %08lx\n",
159 regs->UCreg_11, regs->UCreg_10,
160 regs->UCreg_09, regs->UCreg_08);
161 printk(KERN_DEFAULT "r7 : %08lx r6 : %08lx r5 : %08lx r4 : %08lx\n",
162 regs->UCreg_07, regs->UCreg_06,
163 regs->UCreg_05, regs->UCreg_04);
164 printk(KERN_DEFAULT "r3 : %08lx r2 : %08lx r1 : %08lx r0 : %08lx\n",
165 regs->UCreg_03, regs->UCreg_02,
166 regs->UCreg_01, regs->UCreg_00);
167
168 flags = regs->UCreg_asr;
169 buf[0] = flags & PSR_S_BIT ? 'S' : 's';
170 buf[1] = flags & PSR_Z_BIT ? 'Z' : 'z';
171 buf[2] = flags & PSR_C_BIT ? 'C' : 'c';
172 buf[3] = flags & PSR_V_BIT ? 'V' : 'v';
173 buf[4] = '\0';
174
175 printk(KERN_DEFAULT "Flags: %s INTR o%s REAL o%s Mode %s Segment %s\n",
176 buf, interrupts_enabled(regs) ? "n" : "ff",
177 fast_interrupts_enabled(regs) ? "n" : "ff",
178 processor_modes[processor_mode(regs)],
179 segment_eq(get_fs(), get_ds()) ? "kernel" : "user");
180 {
181 unsigned int ctrl;
182
183 buf[0] = '\0';
184 {
185 unsigned int transbase;
186 asm("movc %0, p0.c2, #0\n"
187 : "=r" (transbase));
188 snprintf(buf, sizeof(buf), " Table: %08x", transbase);
189 }
190 asm("movc %0, p0.c1, #0\n" : "=r" (ctrl));
191
192 printk(KERN_DEFAULT "Control: %08x%s\n", ctrl, buf);
193 }
194}
195
196void show_regs(struct pt_regs *regs)
197{
198 printk(KERN_DEFAULT "\n");
199 printk(KERN_DEFAULT "Pid: %d, comm: %20s\n",
200 task_pid_nr(current), current->comm);
201 __show_regs(regs);
202 __backtrace();
203}
204
f73670e8
G
205void flush_thread(void)
206{
207 struct thread_info *thread = current_thread_info();
208 struct task_struct *tsk = current;
209
210 memset(thread->used_cp, 0, sizeof(thread->used_cp));
211 memset(&tsk->thread.debug, 0, sizeof(struct debug_info));
212#ifdef CONFIG_UNICORE_FPU_F64
213 memset(&thread->fpstate, 0, sizeof(struct fp_state));
214#endif
215}
216
217void release_thread(struct task_struct *dead_task)
218{
219}
220
221asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
38e99353 222asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
f73670e8
G
223
224int
225copy_thread(unsigned long clone_flags, unsigned long stack_start,
afa86fc4 226 unsigned long stk_sz, struct task_struct *p)
f73670e8
G
227{
228 struct thread_info *thread = task_thread_info(p);
229 struct pt_regs *childregs = task_pt_regs(p);
230
f73670e8
G
231 memset(&thread->cpu_context, 0, sizeof(struct cpu_context_save));
232 thread->cpu_context.sp = (unsigned long)childregs;
cb562173 233 if (unlikely(p->flags & PF_KTHREAD)) {
38e99353
AV
234 thread->cpu_context.pc = (unsigned long)ret_from_kernel_thread;
235 thread->cpu_context.r4 = stack_start;
236 thread->cpu_context.r5 = stk_sz;
237 memset(childregs, 0, sizeof(struct pt_regs));
238 } else {
239 thread->cpu_context.pc = (unsigned long)ret_from_fork;
cb562173 240 *childregs = *current_pt_regs();
38e99353 241 childregs->UCreg_00 = 0;
cb562173
AV
242 if (stack_start)
243 childregs->UCreg_sp = stack_start;
f73670e8 244
38e99353 245 if (clone_flags & CLONE_SETTLS)
cb562173 246 childregs->UCreg_16 = childregs->UCreg_03;
38e99353 247 }
f73670e8
G
248 return 0;
249}
250
251/*
252 * Fill in the task's elfregs structure for a core dump.
253 */
254int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs)
255{
256 elf_core_copy_regs(elfregs, task_pt_regs(t));
257 return 1;
258}
259
260/*
261 * fill in the fpe structure for a core dump...
262 */
263int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fp)
264{
265 struct thread_info *thread = current_thread_info();
266 int used_math = thread->used_cp[1] | thread->used_cp[2];
267
268#ifdef CONFIG_UNICORE_FPU_F64
269 if (used_math)
270 memcpy(fp, &thread->fpstate, sizeof(*fp));
271#endif
272 return used_math != 0;
273}
274EXPORT_SYMBOL(dump_fpu);
275
f73670e8
G
276unsigned long get_wchan(struct task_struct *p)
277{
278 struct stackframe frame;
279 int count = 0;
280 if (!p || p == current || p->state == TASK_RUNNING)
281 return 0;
282
283 frame.fp = thread_saved_fp(p);
284 frame.sp = thread_saved_sp(p);
285 frame.lr = 0; /* recovered from the stack */
286 frame.pc = thread_saved_pc(p);
287 do {
288 int ret = unwind_frame(&frame);
289 if (ret < 0)
290 return 0;
291 if (!in_sched_functions(frame.pc))
292 return frame.pc;
293 } while ((count++) < 16);
294 return 0;
295}
296
297unsigned long arch_randomize_brk(struct mm_struct *mm)
298{
05c2679e 299 return randomize_page(mm->brk, 0x02000000);
f73670e8
G
300}
301
302/*
303 * The vectors page is always readable from user space for the
304 * atomic helpers and the signal restart code. Let's declare a mapping
305 * for it so it is visible through ptrace and /proc/<pid>/mem.
306 */
307
308int vectors_user_mapping(void)
309{
310 struct mm_struct *mm = current->mm;
311 return install_special_mapping(mm, 0xffff0000, PAGE_SIZE,
312 VM_READ | VM_EXEC |
313 VM_MAYREAD | VM_MAYEXEC |
314e51b9 314 VM_DONTEXPAND | VM_DONTDUMP,
f73670e8
G
315 NULL);
316}
317
318const char *arch_vma_name(struct vm_area_struct *vma)
319{
320 return (vma->vm_start == 0xffff0000) ? "[vectors]" : NULL;
321}