aboutsummaryrefslogtreecommitdiffstats
path: root/arch/c6x
diff options
context:
space:
mode:
authorAurelien Jacquiot <a-jacquiot@ti.com>2011-10-04 11:03:44 -0400
committerMark Salter <msalter@redhat.com>2011-10-06 19:47:40 -0400
commit687b12baecae2aa3af9df05c12b90d8e9ef21fa7 (patch)
tree0d73b753a7dd541d987a06fd7b69d7958170a5dd /arch/c6x
parent14aa7e8bf6d84c9a42c48e7f93472d830f694b1e (diff)
C6X: process management
Original port to early 2.6 kernel using TI COFF toolchain. Brought up to date by Mark Salter <msalter@redhat.com> Signed-off-by: Aurelien Jacquiot <a-jacquiot@ti.com> Signed-off-by: Mark Salter <msalter@redhat.com> Acked-by: Arnd Bergmann <arnd@arndb.de>
Diffstat (limited to 'arch/c6x')
-rw-r--r--arch/c6x/include/asm/processor.h132
-rw-r--r--arch/c6x/include/asm/thread_info.h121
-rw-r--r--arch/c6x/kernel/process.c263
-rw-r--r--arch/c6x/kernel/switch_to.S74
4 files changed, 590 insertions, 0 deletions
diff --git a/arch/c6x/include/asm/processor.h b/arch/c6x/include/asm/processor.h
new file mode 100644
index 000000000000..8154c4ee8c9c
--- /dev/null
+++ b/arch/c6x/include/asm/processor.h
@@ -0,0 +1,132 @@
1/*
2 * Port on Texas Instruments TMS320C6x architecture
3 *
4 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
6 *
7 * Updated for 2.6.34: Mark Salter <msalter@redhat.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef _ASM_C6X_PROCESSOR_H
14#define _ASM_C6X_PROCESSOR_H
15
16#include <asm/ptrace.h>
17#include <asm/page.h>
18#include <asm/current.h>
19
20/*
21 * Default implementation of macro that returns current
22 * instruction pointer ("program counter").
23 */
24#define current_text_addr() \
25({ \
26 void *__pc; \
27 asm("mvc .S2 pce1,%0\n" : "=b"(__pc)); \
28 __pc; \
29})
30
31/*
32 * User space process size. This is mostly meaningless for NOMMU
33 * but some C6X processors may have RAM addresses up to 0xFFFFFFFF.
34 * Since calls like mmap() can return an address or an error, we
35 * have to allow room for error returns when code does something
36 * like:
37 *
38 * addr = do_mmap(...)
39 * if ((unsigned long)addr >= TASK_SIZE)
40 * ... its an error code, not an address ...
41 *
42 * Here, we allow for 4096 error codes which means we really can't
43 * use the last 4K page on systems with RAM extending all the way
44 * to the end of the 32-bit address space.
45 */
46#define TASK_SIZE 0xFFFFF000
47
48/*
49 * This decides where the kernel will search for a free chunk of vm
50 * space during mmap's. We won't be using it
51 */
52#define TASK_UNMAPPED_BASE 0
53
54struct thread_struct {
55 unsigned long long b15_14;
56 unsigned long long a15_14;
57 unsigned long long b13_12;
58 unsigned long long a13_12;
59 unsigned long long b11_10;
60 unsigned long long a11_10;
61 unsigned long long ricl_icl;
62 unsigned long usp; /* user stack pointer */
63 unsigned long pc; /* kernel pc */
64 unsigned long wchan;
65};
66
67#define INIT_THREAD \
68{ \
69 .usp = 0, \
70 .wchan = 0, \
71}
72
73#define INIT_MMAP { \
74 &init_mm, 0, 0, NULL, PAGE_SHARED, VM_READ | VM_WRITE | VM_EXEC, 1, \
75 NULL, NULL }
76
77#define task_pt_regs(task) \
78 ((struct pt_regs *)(THREAD_START_SP + task_stack_page(task)) - 1)
79
80#define alloc_kernel_stack() __get_free_page(GFP_KERNEL)
81#define free_kernel_stack(page) free_page((page))
82
83
84/* Forward declaration, a strange C thing */
85struct task_struct;
86
87extern void start_thread(struct pt_regs *regs, unsigned int pc,
88 unsigned long usp);
89
90/* Free all resources held by a thread. */
91static inline void release_thread(struct task_struct *dead_task)
92{
93}
94
95/* Prepare to copy thread state - unlazy all lazy status */
96#define prepare_to_copy(tsk) do { } while (0)
97
98extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
99
100#define copy_segments(tsk, mm) do { } while (0)
101#define release_segments(mm) do { } while (0)
102
103/*
104 * saved PC of a blocked thread.
105 */
106#define thread_saved_pc(tsk) (task_pt_regs(tsk)->pc)
107
108/*
109 * saved kernel SP and DP of a blocked thread.
110 */
111#ifdef _BIG_ENDIAN
112#define thread_saved_ksp(tsk) \
113 (*(unsigned long *)&(tsk)->thread.b15_14)
114#define thread_saved_dp(tsk) \
115 (*(((unsigned long *)&(tsk)->thread.b15_14) + 1))
116#else
117#define thread_saved_ksp(tsk) \
118 (*(((unsigned long *)&(tsk)->thread.b15_14) + 1))
119#define thread_saved_dp(tsk) \
120 (*(unsigned long *)&(tsk)->thread.b15_14)
121#endif
122
123extern unsigned long get_wchan(struct task_struct *p);
124
125#define KSTK_EIP(tsk) (task_pt_regs(task)->pc)
126#define KSTK_ESP(tsk) (task_pt_regs(task)->sp)
127
128#define cpu_relax() do { } while (0)
129
130extern const struct seq_operations cpuinfo_op;
131
132#endif /* ASM_C6X_PROCESSOR_H */
diff --git a/arch/c6x/include/asm/thread_info.h b/arch/c6x/include/asm/thread_info.h
new file mode 100644
index 000000000000..fd99148cda9d
--- /dev/null
+++ b/arch/c6x/include/asm/thread_info.h
@@ -0,0 +1,121 @@
1/*
2 * Port on Texas Instruments TMS320C6x architecture
3 *
4 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
6 *
7 * Updated for 2.6.3x: Mark Salter <msalter@redhat.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13#ifndef _ASM_C6X_THREAD_INFO_H
14#define _ASM_C6X_THREAD_INFO_H
15
16#ifdef __KERNEL__
17
18#include <asm/page.h>
19
20#ifdef CONFIG_4KSTACKS
21#define THREAD_SIZE 4096
22#define THREAD_SHIFT 12
23#define THREAD_ORDER 0
24#else
25#define THREAD_SIZE 8192
26#define THREAD_SHIFT 13
27#define THREAD_ORDER 1
28#endif
29
30#define THREAD_START_SP (THREAD_SIZE - 8)
31
32#ifndef __ASSEMBLY__
33
34typedef struct {
35 unsigned long seg;
36} mm_segment_t;
37
38/*
39 * low level task data.
40 */
41struct thread_info {
42 struct task_struct *task; /* main task structure */
43 struct exec_domain *exec_domain; /* execution domain */
44 unsigned long flags; /* low level flags */
45 int cpu; /* cpu we're on */
46 int preempt_count; /* 0 = preemptable, <0 = BUG */
47 mm_segment_t addr_limit; /* thread address space */
48 struct restart_block restart_block;
49};
50
51/*
52 * macros/functions for gaining access to the thread information structure
53 *
54 * preempt_count needs to be 1 initially, until the scheduler is functional.
55 */
56#define INIT_THREAD_INFO(tsk) \
57{ \
58 .task = &tsk, \
59 .exec_domain = &default_exec_domain, \
60 .flags = 0, \
61 .cpu = 0, \
62 .preempt_count = INIT_PREEMPT_COUNT, \
63 .addr_limit = KERNEL_DS, \
64 .restart_block = { \
65 .fn = do_no_restart_syscall, \
66 }, \
67}
68
69#define init_thread_info (init_thread_union.thread_info)
70#define init_stack (init_thread_union.stack)
71
72/* get the thread information struct of current task */
73static inline __attribute__((const))
74struct thread_info *current_thread_info(void)
75{
76 struct thread_info *ti;
77 asm volatile (" clr .s2 B15,0,%1,%0\n"
78 : "=b" (ti)
79 : "Iu5" (THREAD_SHIFT - 1));
80 return ti;
81}
82
83#define __HAVE_ARCH_THREAD_INFO_ALLOCATOR
84
85/* thread information allocation */
86#ifdef CONFIG_DEBUG_STACK_USAGE
87#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK | __GFP_ZERO)
88#else
89#define THREAD_FLAGS (GFP_KERNEL | __GFP_NOTRACK)
90#endif
91
92#define alloc_thread_info_node(tsk, node) \
93 ((struct thread_info *)__get_free_pages(THREAD_FLAGS, THREAD_ORDER))
94
95#define free_thread_info(ti) free_pages((unsigned long) (ti), THREAD_ORDER)
96#define get_thread_info(ti) get_task_struct((ti)->task)
97#define put_thread_info(ti) put_task_struct((ti)->task)
98#endif /* __ASSEMBLY__ */
99
100#define PREEMPT_ACTIVE 0x10000000
101
102/*
103 * thread information flag bit numbers
104 * - pending work-to-be-done flags are in LSW
105 * - other flags in MSW
106 */
107#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
108#define TIF_NOTIFY_RESUME 1 /* resumption notification requested */
109#define TIF_SIGPENDING 2 /* signal pending */
110#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
111#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
112
113#define TIF_POLLING_NRFLAG 16 /* true if polling TIF_NEED_RESCHED */
114#define TIF_MEMDIE 17 /* OOM killer killed process */
115
116#define TIF_WORK_MASK 0x00007FFE /* work on irq/exception return */
117#define TIF_ALLWORK_MASK 0x00007FFF /* work on any return to u-space */
118
119#endif /* __KERNEL__ */
120
121#endif /* _ASM_C6X_THREAD_INFO_H */
diff --git a/arch/c6x/kernel/process.c b/arch/c6x/kernel/process.c
new file mode 100644
index 000000000000..aa65c879323b
--- /dev/null
+++ b/arch/c6x/kernel/process.c
@@ -0,0 +1,263 @@
1/*
2 * Port on Texas Instruments TMS320C6x architecture
3 *
4 * Copyright (C) 2004, 2006, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
12#include <linux/module.h>
13#include <linux/unistd.h>
14#include <linux/ptrace.h>
15#include <linux/init_task.h>
16#include <linux/tick.h>
17#include <linux/mqueue.h>
18#include <linux/syscalls.h>
19#include <linux/reboot.h>
20
21#include <asm/syscalls.h>
22
23/* hooks for board specific support */
24void (*c6x_restart)(void);
25void (*c6x_halt)(void);
26
27extern asmlinkage void ret_from_fork(void);
28
29static struct signal_struct init_signals = INIT_SIGNALS(init_signals);
30static struct sighand_struct init_sighand = INIT_SIGHAND(init_sighand);
31
32/*
33 * Initial thread structure.
34 */
35union thread_union init_thread_union __init_task_data = {
36 INIT_THREAD_INFO(init_task)
37};
38
39/*
40 * Initial task structure.
41 */
42struct task_struct init_task = INIT_TASK(init_task);
43EXPORT_SYMBOL(init_task);
44
45/*
46 * power off function, if any
47 */
48void (*pm_power_off)(void);
49EXPORT_SYMBOL(pm_power_off);
50
51static void c6x_idle(void)
52{
53 unsigned long tmp;
54
55 /*
56 * Put local_irq_enable and idle in same execute packet
57 * to make them atomic and avoid race to idle with
58 * interrupts enabled.
59 */
60 asm volatile (" mvc .s2 CSR,%0\n"
61 " or .d2 1,%0,%0\n"
62 " mvc .s2 %0,CSR\n"
63 "|| idle\n"
64 : "=b"(tmp));
65}
66
67/*
68 * The idle loop for C64x
69 */
70void cpu_idle(void)
71{
72 /* endless idle loop with no priority at all */
73 while (1) {
74 tick_nohz_stop_sched_tick(1);
75 while (1) {
76 local_irq_disable();
77 if (need_resched()) {
78 local_irq_enable();
79 break;
80 }
81 c6x_idle(); /* enables local irqs */
82 }
83 tick_nohz_restart_sched_tick();
84
85 preempt_enable_no_resched();
86 schedule();
87 preempt_disable();
88 }
89}
90
91static void halt_loop(void)
92{
93 printk(KERN_EMERG "System Halted, OK to turn off power\n");
94 local_irq_disable();
95 while (1)
96 asm volatile("idle\n");
97}
98
99void machine_restart(char *__unused)
100{
101 if (c6x_restart)
102 c6x_restart();
103 halt_loop();
104}
105
106void machine_halt(void)
107{
108 if (c6x_halt)
109 c6x_halt();
110 halt_loop();
111}
112
113void machine_power_off(void)
114{
115 if (pm_power_off)
116 pm_power_off();
117 halt_loop();
118}
119
120static void kernel_thread_helper(int dummy, void *arg, int (*fn)(void *))
121{
122 do_exit(fn(arg));
123}
124
125/*
126 * Create a kernel thread
127 */
128int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags)
129{
130 struct pt_regs regs;
131
132 /*
133 * copy_thread sets a4 to zero (child return from fork)
134 * so we can't just set things up to directly return to
135 * fn.
136 */
137 memset(&regs, 0, sizeof(regs));
138 regs.b4 = (unsigned long) arg;
139 regs.a6 = (unsigned long) fn;
140 regs.pc = (unsigned long) kernel_thread_helper;
141 local_save_flags(regs.csr);
142 regs.csr |= 1;
143 regs.tsr = 5; /* Set GEE and GIE in TSR */
144
145 /* Ok, create the new process.. */
146 return do_fork(flags | CLONE_VM | CLONE_UNTRACED, -1, &regs,
147 0, NULL, NULL);
148}
149EXPORT_SYMBOL(kernel_thread);
150
151void flush_thread(void)
152{
153}
154
155void exit_thread(void)
156{
157}
158
159SYSCALL_DEFINE1(c6x_clone, struct pt_regs *, regs)
160{
161 unsigned long clone_flags;
162 unsigned long newsp;
163
164 /* syscall puts clone_flags in A4 and usp in B4 */
165 clone_flags = regs->orig_a4;
166 if (regs->b4)
167 newsp = regs->b4;
168 else
169 newsp = regs->sp;
170
171 return do_fork(clone_flags, newsp, regs, 0, (int __user *)regs->a6,
172 (int __user *)regs->b6);
173}
174
175/*
176 * Do necessary setup to start up a newly executed thread.
177 */
178void start_thread(struct pt_regs *regs, unsigned int pc, unsigned long usp)
179{
180 /*
181 * The binfmt loader will setup a "full" stack, but the C6X
182 * operates an "empty" stack. So we adjust the usp so that
183 * argc doesn't get destroyed if an interrupt is taken before
184 * it is read from the stack.
185 *
186 * NB: Library startup code needs to match this.
187 */
188 usp -= 8;
189
190 set_fs(USER_DS);
191 regs->pc = pc;
192 regs->sp = usp;
193 regs->tsr |= 0x40; /* set user mode */
194 current->thread.usp = usp;
195}
196
197/*
198 * Copy a new thread context in its stack.
199 */
200int copy_thread(unsigned long clone_flags, unsigned long usp,
201 unsigned long ustk_size,
202 struct task_struct *p, struct pt_regs *regs)
203{
204 struct pt_regs *childregs;
205
206 childregs = task_pt_regs(p);
207
208 *childregs = *regs;
209 childregs->a4 = 0;
210
211 if (usp == -1)
212 /* case of __kernel_thread: we return to supervisor space */
213 childregs->sp = (unsigned long)(childregs + 1);
214 else
215 /* Otherwise use the given stack */
216 childregs->sp = usp;
217
218 /* Set usp/ksp */
219 p->thread.usp = childregs->sp;
220 /* switch_to uses stack to save/restore 14 callee-saved regs */
221 thread_saved_ksp(p) = (unsigned long)childregs - 8;
222 p->thread.pc = (unsigned int) ret_from_fork;
223 p->thread.wchan = (unsigned long) ret_from_fork;
224#ifdef __DSBT__
225 {
226 unsigned long dp;
227
228 asm volatile ("mv .S2 b14,%0\n" : "=b"(dp));
229
230 thread_saved_dp(p) = dp;
231 if (usp == -1)
232 childregs->dp = dp;
233 }
234#endif
235 return 0;
236}
237
238/*
239 * c6x_execve() executes a new program.
240 */
241SYSCALL_DEFINE4(c6x_execve, const char __user *, name,
242 const char __user *const __user *, argv,
243 const char __user *const __user *, envp,
244 struct pt_regs *, regs)
245{
246 int error;
247 char *filename;
248
249 filename = getname(name);
250 error = PTR_ERR(filename);
251 if (IS_ERR(filename))
252 goto out;
253
254 error = do_execve(filename, argv, envp, regs);
255 putname(filename);
256out:
257 return error;
258}
259
260unsigned long get_wchan(struct task_struct *p)
261{
262 return p->thread.wchan;
263}
diff --git a/arch/c6x/kernel/switch_to.S b/arch/c6x/kernel/switch_to.S
new file mode 100644
index 000000000000..09177ed0fa5c
--- /dev/null
+++ b/arch/c6x/kernel/switch_to.S
@@ -0,0 +1,74 @@
1/*
2 * Copyright (C) 2011 Texas Instruments Incorporated
3 * Author: Mark Salter (msalter@redhat.com)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/linkage.h>
11#include <asm/asm-offsets.h>
12
13#define SP B15
14
15 /*
16 * void __switch_to(struct thread_info *prev,
17 * struct thread_info *next,
18 * struct task_struct *tsk) ;
19 */
20ENTRY(__switch_to)
21 LDDW .D2T2 *+B4(THREAD_B15_14),B7:B6
22 || MV .L2X A4,B5 ; prev
23 || MV .L1X B4,A5 ; next
24 || MVC .S2 RILC,B1
25
26 STW .D2T2 B3,*+B5(THREAD_PC)
27 || STDW .D1T1 A13:A12,*+A4(THREAD_A13_12)
28 || MVC .S2 ILC,B0
29
30 LDW .D2T2 *+B4(THREAD_PC),B3
31 || LDDW .D1T1 *+A5(THREAD_A13_12),A13:A12
32
33 STDW .D1T1 A11:A10,*+A4(THREAD_A11_10)
34 || STDW .D2T2 B1:B0,*+B5(THREAD_RICL_ICL)
35#ifndef __DSBT__
36 || MVKL .S2 current_ksp,B1
37#endif
38
39 STDW .D2T2 B15:B14,*+B5(THREAD_B15_14)
40 || STDW .D1T1 A15:A14,*+A4(THREAD_A15_14)
41#ifndef __DSBT__
42 || MVKH .S2 current_ksp,B1
43#endif
44
45 ;; Switch to next SP
46 MV .S2 B7,SP
47#ifdef __DSBT__
48 || STW .D2T2 B7,*+B14(current_ksp)
49#else
50 || STW .D2T2 B7,*B1
51 || MV .L2 B6,B14
52#endif
53 || LDDW .D1T1 *+A5(THREAD_RICL_ICL),A1:A0
54
55 STDW .D2T2 B11:B10,*+B5(THREAD_B11_10)
56 || LDDW .D1T1 *+A5(THREAD_A15_14),A15:A14
57
58 STDW .D2T2 B13:B12,*+B5(THREAD_B13_12)
59 || LDDW .D1T1 *+A5(THREAD_A11_10),A11:A10
60
61 B .S2 B3 ; return in next E1
62 || LDDW .D2T2 *+B4(THREAD_B13_12),B13:B12
63
64 LDDW .D2T2 *+B4(THREAD_B11_10),B11:B10
65 NOP
66
67 MV .L2X A0,B0
68 || MV .S1 A6,A4
69
70 MVC .S2 B0,ILC
71 || MV .L2X A1,B1
72
73 MVC .S2 B1,RILC
74ENDPROC(__switch_to)