2 * File: arch/blackfin/kernel/process.c
7 * Description: Blackfin architecture-dependent process handling.
10 * Copyright 2004-2006 Analog Devices Inc.
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include <linux/module.h>
31 #include <linux/smp_lock.h>
32 #include <linux/unistd.h>
33 #include <linux/user.h>
34 #include <linux/uaccess.h>
35 #include <linux/sched.h>
36 #include <linux/tick.h>
38 #include <linux/err.h>
40 #include <asm/blackfin.h>
41 #include <asm/fixed_code.h>
43 asmlinkage
void ret_from_fork(void);
45 /* Points to the SDRAM backup memory for the stack that is currently in
46 * L1 scratchpad memory.
48 void *current_l1_stack_save
;
50 /* The number of tasks currently using a L1 stack area. The SRAM is
51 * allocated/deallocated whenever this changes from/to zero.
55 /* Start and length of the area in L1 scratchpad memory which we've allocated
59 unsigned long l1_stack_len
;
62 * Powermanagement idle function, if any..
64 void (*pm_idle
)(void) = NULL
;
65 EXPORT_SYMBOL(pm_idle
);
67 void (*pm_power_off
)(void) = NULL
;
68 EXPORT_SYMBOL(pm_power_off
);
71 * The idle loop on BFIN
74 static void default_idle(void)__attribute__((l1_text
));
75 void cpu_idle(void)__attribute__((l1_text
));
79 * This is our default idle handler. We need to disable
80 * interrupts here to ensure we don't miss a wakeup call.
82 static void default_idle(void)
86 idle_with_irq_disabled();
92 * The idle thread. We try to conserve power, while trying to keep
93 * overall latency low. The architecture specific idle is passed
94 * a value to indicate the level of "idleness" of the system.
98 /* endless idle loop with no priority at all */
100 void (*idle
)(void) = pm_idle
;
102 #ifdef CONFIG_HOTPLUG_CPU
103 if (cpu_is_offline(smp_processor_id()))
108 tick_nohz_stop_sched_tick(1);
109 while (!need_resched())
111 tick_nohz_restart_sched_tick();
112 preempt_enable_no_resched();
118 /* Fill in the fpu structure for a core dump. */
120 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
* fpregs
)
126 * This gets run with P1 containing the
127 * function to call, and R1 containing
128 * the "args". Note P0 is clobbered on the way here.
130 void kernel_thread_helper(void);
131 __asm__(".section .text\n"
133 "_kernel_thread_helper:\n\t"
135 "\tr0 = r1;\n\t" "\tcall (p1);\n\t" "\tcall _do_exit;\n" ".previous");
138 * Create a kernel thread.
140 pid_t
kernel_thread(int (*fn
) (void *), void *arg
, unsigned long flags
)
144 memset(®s
, 0, sizeof(regs
));
146 regs
.r1
= (unsigned long)arg
;
147 regs
.p1
= (unsigned long)fn
;
148 regs
.pc
= (unsigned long)kernel_thread_helper
;
150 /* Set bit 2 to tell ret_from_fork we should be returning to kernel
153 __asm__
__volatile__("%0 = syscfg;":"=da"(regs
.syscfg
):);
154 return do_fork(flags
| CLONE_VM
| CLONE_UNTRACED
, 0, ®s
, 0, NULL
,
158 void flush_thread(void)
162 asmlinkage
int bfin_vfork(struct pt_regs
*regs
)
164 return do_fork(CLONE_VFORK
| CLONE_VM
| SIGCHLD
, rdusp(), regs
, 0, NULL
,
168 asmlinkage
int bfin_clone(struct pt_regs
*regs
)
170 unsigned long clone_flags
;
173 /* syscall2 puts clone_flags in r0 and usp in r1 */
174 clone_flags
= regs
->r0
;
180 return do_fork(clone_flags
, newsp
, regs
, 0, NULL
, NULL
);
184 copy_thread(int nr
, unsigned long clone_flags
,
185 unsigned long usp
, unsigned long topstk
,
186 struct task_struct
*p
, struct pt_regs
*regs
)
188 struct pt_regs
*childregs
;
190 childregs
= (struct pt_regs
*) (task_stack_page(p
) + THREAD_SIZE
) - 1;
195 p
->thread
.ksp
= (unsigned long)childregs
;
196 p
->thread
.pc
= (unsigned long)ret_from_fork
;
202 * sys_execve() executes a new program.
205 asmlinkage
int sys_execve(char __user
*name
, char __user
* __user
*argv
, char __user
* __user
*envp
)
209 struct pt_regs
*regs
= (struct pt_regs
*)((&name
) + 6);
212 filename
= getname(name
);
213 error
= PTR_ERR(filename
);
214 if (IS_ERR(filename
))
216 error
= do_execve(filename
, argv
, envp
, regs
);
223 unsigned long get_wchan(struct task_struct
*p
)
225 unsigned long fp
, pc
;
226 unsigned long stack_page
;
228 if (!p
|| p
== current
|| p
->state
== TASK_RUNNING
)
231 stack_page
= (unsigned long)p
;
234 if (fp
< stack_page
+ sizeof(struct thread_info
) ||
235 fp
>= 8184 + stack_page
)
237 pc
= ((unsigned long *)fp
)[1];
238 if (!in_sched_functions(pc
))
240 fp
= *(unsigned long *)fp
;
242 while (count
++ < 16);
246 void finish_atomic_sections (struct pt_regs
*regs
)
248 int __user
*up0
= (int __user
*)regs
->p0
;
250 if (regs
->pc
< ATOMIC_SEQS_START
|| regs
->pc
>= ATOMIC_SEQS_END
)
254 case ATOMIC_XCHG32
+ 2:
255 put_user(regs
->r1
, up0
);
259 case ATOMIC_CAS32
+ 2:
260 case ATOMIC_CAS32
+ 4:
261 if (regs
->r0
== regs
->r1
)
262 put_user(regs
->r2
, up0
);
263 regs
->pc
= ATOMIC_CAS32
+ 8;
265 case ATOMIC_CAS32
+ 6:
266 put_user(regs
->r2
, up0
);
270 case ATOMIC_ADD32
+ 2:
271 regs
->r0
= regs
->r1
+ regs
->r0
;
273 case ATOMIC_ADD32
+ 4:
274 put_user(regs
->r0
, up0
);
275 regs
->pc
= ATOMIC_ADD32
+ 6;
278 case ATOMIC_SUB32
+ 2:
279 regs
->r0
= regs
->r1
- regs
->r0
;
281 case ATOMIC_SUB32
+ 4:
282 put_user(regs
->r0
, up0
);
283 regs
->pc
= ATOMIC_SUB32
+ 6;
286 case ATOMIC_IOR32
+ 2:
287 regs
->r0
= regs
->r1
| regs
->r0
;
289 case ATOMIC_IOR32
+ 4:
290 put_user(regs
->r0
, up0
);
291 regs
->pc
= ATOMIC_IOR32
+ 6;
294 case ATOMIC_AND32
+ 2:
295 regs
->r0
= regs
->r1
& regs
->r0
;
297 case ATOMIC_AND32
+ 4:
298 put_user(regs
->r0
, up0
);
299 regs
->pc
= ATOMIC_AND32
+ 6;
302 case ATOMIC_XOR32
+ 2:
303 regs
->r0
= regs
->r1
^ regs
->r0
;
305 case ATOMIC_XOR32
+ 4:
306 put_user(regs
->r0
, up0
);
307 regs
->pc
= ATOMIC_XOR32
+ 6;
312 #if defined(CONFIG_ACCESS_CHECK)
313 /* Return 1 if access to memory range is OK, 0 otherwise */
314 int _access_ok(unsigned long addr
, unsigned long size
)
318 if (addr
> (addr
+ size
))
320 if (segment_eq(get_fs(), KERNEL_DS
))
322 #ifdef CONFIG_MTD_UCLINUX
323 if (addr
>= memory_start
&& (addr
+ size
) <= memory_end
)
325 if (addr
>= memory_mtd_end
&& (addr
+ size
) <= physical_mem_end
)
328 #ifdef CONFIG_ROMFS_MTD_FS
329 /* For XIP, allow user space to use pointers within the ROMFS. */
330 if (addr
>= memory_mtd_start
&& (addr
+ size
) <= memory_mtd_end
)
334 if (addr
>= memory_start
&& (addr
+ size
) <= physical_mem_end
)
337 if (addr
>= (unsigned long)__init_begin
&&
338 addr
+ size
<= (unsigned long)__init_end
)
340 if (addr
>= L1_SCRATCH_START
341 && addr
+ size
<= L1_SCRATCH_START
+ L1_SCRATCH_LENGTH
)
343 #if L1_CODE_LENGTH != 0
344 if (addr
>= L1_CODE_START
+ (_etext_l1
- _stext_l1
)
345 && addr
+ size
<= L1_CODE_START
+ L1_CODE_LENGTH
)
348 #if L1_DATA_A_LENGTH != 0
349 if (addr
>= L1_DATA_A_START
+ (_ebss_l1
- _sdata_l1
)
350 && addr
+ size
<= L1_DATA_A_START
+ L1_DATA_A_LENGTH
)
353 #if L1_DATA_B_LENGTH != 0
354 if (addr
>= L1_DATA_B_START
355 && addr
+ size
<= L1_DATA_B_START
+ L1_DATA_B_LENGTH
)
360 EXPORT_SYMBOL(_access_ok
);
361 #endif /* CONFIG_ACCESS_CHECK */