]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/metag/kernel/process.c
2 * Copyright (C) 2005,2006,2007,2008,2009,2010,2011 Imagination Technologies
4 * This file contains the architecture-dependent parts of process handling.
8 #include <linux/errno.h>
9 #include <linux/export.h>
10 #include <linux/sched.h>
11 #include <linux/sched/debug.h>
12 #include <linux/sched/task.h>
13 #include <linux/sched/task_stack.h>
14 #include <linux/kernel.h>
16 #include <linux/unistd.h>
17 #include <linux/ptrace.h>
18 #include <linux/user.h>
19 #include <linux/reboot.h>
20 #include <linux/elfcore.h>
22 #include <linux/tick.h>
23 #include <linux/slab.h>
24 #include <linux/mman.h>
26 #include <linux/syscalls.h>
27 #include <linux/uaccess.h>
28 #include <linux/smp.h>
29 #include <asm/core_reg.h>
30 #include <asm/user_gateway.h>
32 #include <asm/traps.h>
33 #include <asm/switch_to.h>
36 * Wait for the next interrupt and enable local interrupts
38 void arch_cpu_idle(void)
43 * Quickly jump straight into the interrupt entry point without actually
44 * triggering an interrupt. When TXSTATI gets read the processor will
45 * block until an interrupt is triggered.
47 asm volatile (/* Switch into ISTAT mode */
49 /* Enable local interrupts */
52 * We can't directly "SWAP PC, PCX", so we swap via a
53 * temporary. Essentially we do:
54 * PCX_new = 1f (the place to continue execution)
57 "ADD %0, CPC0, #(1f-.)\n\t"
60 /* Continue execution here with interrupts enabled */
63 : "r" (get_trigger_mask()));
66 #ifdef CONFIG_HOTPLUG_CPU
67 void arch_cpu_idle_dead(void)
73 void (*pm_power_off
)(void);
74 EXPORT_SYMBOL(pm_power_off
);
76 void (*soc_restart
)(char *cmd
);
77 void (*soc_halt
)(void);
79 void machine_restart(char *cmd
)
83 hard_processor_halt(HALT_OK
);
86 void machine_halt(void)
91 hard_processor_halt(HALT_OK
);
94 void machine_power_off(void)
99 hard_processor_halt(HALT_OK
);
107 void show_regs(struct pt_regs
*regs
)
110 const char *AX0_names
[] = {"A0StP", "A0FrP"};
111 const char *AX1_names
[] = {"A1GbP", "A1LbP"};
113 const char *DX0_names
[] = {
124 const char *DX1_names
[] = {
135 show_regs_print_info(KERN_INFO
);
137 pr_info(" pt_regs @ %p\n", regs
);
138 pr_info(" SaveMask = 0x%04hx\n", regs
->ctx
.SaveMask
);
139 pr_info(" Flags = 0x%04hx (%c%c%c%c)\n", regs
->ctx
.Flags
,
140 regs
->ctx
.Flags
& FLAG_Z
? 'Z' : 'z',
141 regs
->ctx
.Flags
& FLAG_N
? 'N' : 'n',
142 regs
->ctx
.Flags
& FLAG_O
? 'O' : 'o',
143 regs
->ctx
.Flags
& FLAG_C
? 'C' : 'c');
144 pr_info(" TXRPT = 0x%08x\n", regs
->ctx
.CurrRPT
);
145 pr_info(" PC = 0x%08x\n", regs
->ctx
.CurrPC
);
148 for (i
= 0; i
< 2; i
++) {
149 pr_info(" %s = 0x%08x ",
152 printk(" %s = 0x%08x\n",
157 if (regs
->ctx
.SaveMask
& TBICTX_XEXT_BIT
)
158 pr_warn(" Extended state present - AX2.[01] will be WRONG\n");
160 /* Special place with AXx.2 */
161 pr_info(" A0.2 = 0x%08x ",
162 regs
->ctx
.Ext
.AX2
.U0
);
163 printk(" A1.2 = 0x%08x\n",
164 regs
->ctx
.Ext
.AX2
.U1
);
166 /* 'extended' AX regs (nominally, just AXx.3) */
167 for (i
= 0; i
< (TBICTX_AX_REGS
- 3); i
++) {
168 pr_info(" A0.%d = 0x%08x ", i
+ 3, regs
->ctx
.AX3
[i
].U0
);
169 printk(" A1.%d = 0x%08x\n", i
+ 3, regs
->ctx
.AX3
[i
].U1
);
172 for (i
= 0; i
< 8; i
++) {
173 pr_info(" %s = 0x%08x ", DX0_names
[i
], regs
->ctx
.DX
[i
].U0
);
174 printk(" %s = 0x%08x\n", DX1_names
[i
], regs
->ctx
.DX
[i
].U1
);
177 show_trace(NULL
, (unsigned long *)regs
->ctx
.AX
[0].U0
, regs
);
181 * Copy architecture-specific thread state
183 int copy_thread(unsigned long clone_flags
, unsigned long usp
,
184 unsigned long kthread_arg
, struct task_struct
*tsk
)
186 struct pt_regs
*childregs
= task_pt_regs(tsk
);
187 void *kernel_context
= ((void *) childregs
+
188 sizeof(struct pt_regs
));
189 unsigned long global_base
;
191 BUG_ON(((unsigned long)childregs
) & 0x7);
192 BUG_ON(((unsigned long)kernel_context
) & 0x7);
194 memset(&tsk
->thread
.kernel_context
, 0,
195 sizeof(tsk
->thread
.kernel_context
));
197 tsk
->thread
.kernel_context
= __TBISwitchInit(kernel_context
,
201 if (unlikely(tsk
->flags
& PF_KTHREAD
)) {
203 * Make sure we don't leak any kernel data to child's regs
204 * if kernel thread becomes a userspace thread in the future
206 memset(childregs
, 0 , sizeof(struct pt_regs
));
208 global_base
= __core_reg_get(A1GbP
);
209 childregs
->ctx
.AX
[0].U1
= (unsigned long) global_base
;
210 childregs
->ctx
.AX
[0].U0
= (unsigned long) kernel_context
;
211 /* Set D1Ar1=kthread_arg and D1RtP=usp (fn) */
212 childregs
->ctx
.DX
[4].U1
= usp
;
213 childregs
->ctx
.DX
[3].U1
= kthread_arg
;
214 tsk
->thread
.int_depth
= 2;
219 * Get a pointer to where the new child's register block should have
221 * The Meta's stack grows upwards, and the context is the the first
222 * thing to be pushed by TBX (phew)
224 *childregs
= *current_pt_regs();
225 /* Set the correct stack for the clone mode */
227 childregs
->ctx
.AX
[0].U0
= ALIGN(usp
, 8);
228 tsk
->thread
.int_depth
= 1;
230 /* set return value for child process */
231 childregs
->ctx
.DX
[0].U0
= 0;
233 /* The TLS pointer is passed as an argument to sys_clone. */
234 if (clone_flags
& CLONE_SETTLS
)
235 tsk
->thread
.tls_ptr
=
236 (__force
void __user
*)childregs
->ctx
.DX
[1].U1
;
238 #ifdef CONFIG_METAG_FPU
239 if (tsk
->thread
.fpu_context
) {
240 struct meta_fpu_context
*ctx
;
242 ctx
= kmemdup(tsk
->thread
.fpu_context
,
243 sizeof(struct meta_fpu_context
), GFP_ATOMIC
);
244 tsk
->thread
.fpu_context
= ctx
;
248 #ifdef CONFIG_METAG_DSP
249 if (tsk
->thread
.dsp_context
) {
250 struct meta_ext_context
*ctx
;
253 ctx
= kmemdup(tsk
->thread
.dsp_context
,
254 sizeof(struct meta_ext_context
), GFP_ATOMIC
);
255 for (i
= 0; i
< 2; i
++)
256 ctx
->ram
[i
] = kmemdup(ctx
->ram
[i
], ctx
->ram_sz
[i
],
258 tsk
->thread
.dsp_context
= ctx
;
265 #ifdef CONFIG_METAG_FPU
266 static void alloc_fpu_context(struct thread_struct
*thread
)
268 thread
->fpu_context
= kzalloc(sizeof(struct meta_fpu_context
),
272 static void clear_fpu(struct thread_struct
*thread
)
274 thread
->user_flags
&= ~TBICTX_FPAC_BIT
;
275 kfree(thread
->fpu_context
);
276 thread
->fpu_context
= NULL
;
279 static void clear_fpu(struct thread_struct
*thread
)
284 #ifdef CONFIG_METAG_DSP
285 static void clear_dsp(struct thread_struct
*thread
)
287 if (thread
->dsp_context
) {
288 kfree(thread
->dsp_context
->ram
[0]);
289 kfree(thread
->dsp_context
->ram
[1]);
291 kfree(thread
->dsp_context
);
293 thread
->dsp_context
= NULL
;
296 __core_reg_set(D0
.8
, 0);
299 static void clear_dsp(struct thread_struct
*thread
)
304 struct task_struct
*__sched
__switch_to(struct task_struct
*prev
,
305 struct task_struct
*next
)
309 to
.Switch
.pCtx
= next
->thread
.kernel_context
;
310 to
.Switch
.pPara
= prev
;
312 #ifdef CONFIG_METAG_FPU
313 if (prev
->thread
.user_flags
& TBICTX_FPAC_BIT
) {
314 struct pt_regs
*regs
= task_pt_regs(prev
);
317 state
.Sig
.SaveMask
= prev
->thread
.user_flags
;
318 state
.Sig
.pCtx
= ®s
->ctx
;
320 if (!prev
->thread
.fpu_context
)
321 alloc_fpu_context(&prev
->thread
);
322 if (prev
->thread
.fpu_context
)
323 __TBICtxFPUSave(state
, prev
->thread
.fpu_context
);
326 * Force a restore of the FPU context next time this process is
329 if (prev
->thread
.fpu_context
)
330 prev
->thread
.fpu_context
->needs_restore
= true;
334 from
= __TBISwitch(to
, &prev
->thread
.kernel_context
);
336 /* Restore TLS pointer for this process. */
337 set_gateway_tls(current
->thread
.tls_ptr
);
339 return (struct task_struct
*) from
.Switch
.pPara
;
342 void flush_thread(void)
344 clear_fpu(¤t
->thread
);
345 clear_dsp(¤t
->thread
);
349 * Free current thread data structures etc.
351 void exit_thread(struct task_struct
*tsk
)
353 clear_fpu(&tsk
->thread
);
354 clear_dsp(&tsk
->thread
);
357 /* TODO: figure out how to unwind the kernel stack here to figure out
358 * where we went to sleep. */
359 unsigned long get_wchan(struct task_struct
*p
)
364 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpu
)
366 /* Returning 0 indicates that the FPU state was not stored (as it was
371 #ifdef CONFIG_METAG_USER_TCM
373 #define ELF_MIN_ALIGN PAGE_SIZE
375 #define ELF_PAGESTART(_v) ((_v) & ~(unsigned long)(ELF_MIN_ALIGN-1))
376 #define ELF_PAGEOFFSET(_v) ((_v) & (ELF_MIN_ALIGN-1))
377 #define ELF_PAGEALIGN(_v) (((_v) + ELF_MIN_ALIGN - 1) & ~(ELF_MIN_ALIGN - 1))
379 #define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE)
381 unsigned long __metag_elf_map(struct file
*filep
, unsigned long addr
,
382 struct elf_phdr
*eppnt
, int prot
, int type
,
383 unsigned long total_size
)
385 unsigned long map_addr
, size
;
386 unsigned long page_off
= ELF_PAGEOFFSET(eppnt
->p_vaddr
);
387 unsigned long raw_size
= eppnt
->p_filesz
+ page_off
;
388 unsigned long off
= eppnt
->p_offset
- page_off
;
389 unsigned int tcm_tag
;
390 addr
= ELF_PAGESTART(addr
);
391 size
= ELF_PAGEALIGN(raw_size
);
393 /* mmap() will return -EINVAL if given a zero size, but a
394 * segment with zero filesize is perfectly valid */
398 tcm_tag
= tcm_lookup_tag(addr
);
400 if (tcm_tag
!= TCM_INVALID_TAG
)
404 * total_size is the size of the ELF (interpreter) image.
405 * The _first_ mmap needs to know the full size, otherwise
406 * randomization might put this image into an overlapping
407 * position with the ELF binary image. (since size < total_size)
408 * So we first map the 'big' image - and unmap the remainder at
409 * the end. (which unmap is needed for ELF images with holes.)
412 total_size
= ELF_PAGEALIGN(total_size
);
413 map_addr
= vm_mmap(filep
, addr
, total_size
, prot
, type
, off
);
414 if (!BAD_ADDR(map_addr
))
415 vm_munmap(map_addr
+size
, total_size
-size
);
417 map_addr
= vm_mmap(filep
, addr
, size
, prot
, type
, off
);
419 if (!BAD_ADDR(map_addr
) && tcm_tag
!= TCM_INVALID_TAG
) {
420 struct tcm_allocation
*tcm
;
421 unsigned long tcm_addr
;
423 tcm
= kmalloc(sizeof(*tcm
), GFP_KERNEL
);
427 tcm_addr
= tcm_alloc(tcm_tag
, raw_size
);
428 if (tcm_addr
!= addr
) {
434 tcm
->addr
= tcm_addr
;
435 tcm
->size
= raw_size
;
437 list_add(&tcm
->list
, ¤t
->mm
->context
.tcm
);
439 eppnt
->p_vaddr
= map_addr
;
440 if (copy_from_user((void *) addr
, (void __user
*) map_addr
,