Module: xenomai-forge
Branch: master
Commit: 459dc043c7238d2894c9fc3c59bb0f50ceb1d7fa
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=459dc043c7238d2894c9fc3c59bb0f50ceb1d7fa

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Jan  7 17:53:26 2013 +0100

cobalt/blackfin: convert to native linux kthreads

---

 include/asm-blackfin/thread.h        |   62 ++-----------
 kernel/cobalt/arch/blackfin/Kconfig  |    4 -
 kernel/cobalt/arch/blackfin/switch.S |   10 --
 kernel/cobalt/arch/blackfin/thread.c |  175 +++------------------------------
 4 files changed, 23 insertions(+), 228 deletions(-)

diff --git a/include/asm-blackfin/thread.h b/include/asm-blackfin/thread.h
index 9421225..759ee2d 100644
--- a/include/asm-blackfin/thread.h
+++ b/include/asm-blackfin/thread.h
@@ -20,46 +20,18 @@
 #ifndef _XENO_ASM_BLACKFIN_THREAD_H
 #define _XENO_ASM_BLACKFIN_THREAD_H
 
-#include <asm/ptrace.h>
-#include <asm/processor.h>
-
-struct xnthread;
-struct task_struct;
+#include <asm-generic/xenomai/thread.h>
 
 struct xnarchtcb {
-
-    /* Kernel mode side */
-
-       unsigned stacksize;             /* Aligned size of stack (bytes) */
-       unsigned long *stackbase;       /* Stack space */
-
-       struct thread_struct ts;        /* Holds kernel-based thread context. */
-       struct task_struct *user_task; /* Shadowed user-space task */
-#ifdef CONFIG_MPU
-       struct task_struct *active_task;    /* Active user-space task */
-#endif
-       struct thread_struct *tsp;      /* Pointer to the active thread struct 
(&ts or &user->thread). */
+       struct xntcb core;
        struct {
                unsigned long pc;
                unsigned long p0;
                unsigned long r5;
        } mayday;
-
-       struct xnthread *self;
-       int imask;
-       const char *name;
-       void (*entry)(void *cookie);
-       void *cookie;
 };
 
-#define XNARCH_THREAD_STACKSZ   8192
-
-#define xnarch_fpu_ptr(tcb)     NULL /* No FPU handling at all. */
-#define xnarch_stack_size(tcb)  ((tcb)->stacksize)
-#define xnarch_stack_base(tcb) ((tcb)->stackbase)
-#define xnarch_stack_end(tcb)  ((caddr_t)(tcb)->stackbase - (tcb)->stacksize)
-#define xnarch_user_task(tcb)   ((tcb)->user_task)
-#define xnarch_user_pid(tcb)    ((tcb)->user_task->pid)
+#define xnarch_fpu_ptr(tcb)     NULL
 
 #define xnarch_fault_regs(d)   ((d)->regs)
 #define xnarch_fault_trap(d)    ((d)->exception)
@@ -85,37 +57,17 @@ struct xnarchtcb {
 
 void xnarch_switch_to(struct xnarchtcb *out_tcb, struct xnarchtcb *in_tcb);
 
-void xnarch_init_thread(struct xnarchtcb *tcb,
-                       void (*entry)(void *),
-                       void *cookie,
-                       int imask,
-                       struct xnthread *thread, char *name);
-
-void xnarch_leave_root(struct xnarchtcb *rootcb);
-
 int xnarch_escalate(void);
 
-void xnarch_init_root_tcb(struct xnarchtcb *tcb,
-                         struct xnthread *thread,
-                         const char *name);
-
-void xnarch_init_shadow_tcb(struct xnarchtcb *tcb,
-                           struct xnthread *thread,
-                           const char *name);
-
-void xnarch_init_tcb(struct xnarchtcb *tcb);
-
-int xnarch_alloc_stack(struct xnarchtcb *tcb, size_t stacksize);
-
-void xnarch_free_stack(struct xnarchtcb *tcb);
-
+static inline void xnarch_init_root_tcb(struct xnarchtcb *tcb) { }
+static inline void xnarch_init_shadow_tcb(struct xnarchtcb *tcb) { }
 static inline void xnarch_enter_root(struct xnarchtcb *rootcb) { }
+static inline void xnarch_leave_root(struct xnarchtcb *rootcb) { }
 static inline void xnarch_enable_fpu(struct xnarchtcb *current_tcb) { }
-static inline void xnarch_init_fpu(struct xnarchtcb *tcb) { }
 static inline void xnarch_save_fpu(struct xnarchtcb *tcb) { }
 static inline void xnarch_restore_fpu(struct xnarchtcb *tcb) { }
 
-static inline int xnarch_fpu_init_p(struct task_struct *task)
+static inline int xnarch_handle_fpu_fault(struct xnarchtcb *tcb)
 {
        return 0;
 }
diff --git a/kernel/cobalt/arch/blackfin/Kconfig 
b/kernel/cobalt/arch/blackfin/Kconfig
index 7fcaf62..58c85df 100644
--- a/kernel/cobalt/arch/blackfin/Kconfig
+++ b/kernel/cobalt/arch/blackfin/Kconfig
@@ -1,6 +1,2 @@
-config XENO_GENERIC_STACKPOOL
-       bool
-       default y
-
 source "kernel/xenomai/nucleus/Kconfig"
 source "drivers/xenomai/Kconfig"
diff --git a/kernel/cobalt/arch/blackfin/switch.S 
b/kernel/cobalt/arch/blackfin/switch.S
index 40582d4..8e6344e 100644
--- a/kernel/cobalt/arch/blackfin/switch.S
+++ b/kernel/cobalt/arch/blackfin/switch.S
@@ -24,12 +24,6 @@
 
 /*
  * Switch context routine for Xenomai threads.
- * Kernel-based threads are basically seen as co-routines.
- * The context is saved/restored to/from regular thread_structs,
- * so that hybrid scheduling between kernel and user-space Xenomai
- * threads is possible.
- *
- * We protect all caller-saved registers across switches.
  *
  * void __asm_switch_context(struct thread_struct *prev, struct thread_struct 
*next)
  */
@@ -64,10 +58,6 @@ switch_point:
        rets = [sp++];
        rts;
 
-ENTRY(___asm_thread_trampoline)
-       r0 = [sp++];
-       jump switch_point
-
 /*
  * Check for a reason to block context switching for Xenomai. This may
  * be the case, if:
diff --git a/kernel/cobalt/arch/blackfin/thread.c 
b/kernel/cobalt/arch/blackfin/thread.c
index c244fb7..a454e6e 100644
--- a/kernel/cobalt/arch/blackfin/thread.c
+++ b/kernel/cobalt/arch/blackfin/thread.c
@@ -20,57 +20,37 @@
 #include <linux/sched.h>
 #include <linux/ipipe.h>
 #include <linux/mm.h>
-#include <nucleus/pod.h>
-#include <nucleus/heap.h>
+#include <asm/mmu_context.h>
+#include <nucleus/thread.h>
 
-asmlinkage struct task_struct *
+asmlinkage void
 __asm_switch_context(struct thread_struct *prev,
                     struct thread_struct *next);
 
-asmlinkage void __asm_thread_trampoline(void);
-
 asmlinkage int __asm_defer_switch_p(void);
 
 #ifdef CONFIG_MPU
 
 static inline
-struct task_struct *mpu_get_prev(struct xnarchtcb *tcb)
+void mpu_switch(struct xnarchtcb *out_tcb, struct xnarchtcb *in_tcb)
 {
-       return tcb->active_task;
-}
+       struct mm_struct *prev_mm, *next_mm;
+       struct task_struct *next;
 
-static inline
-void mpu_set_next(struct xnarchtcb *tcb, struct task_struct *next)
-{
-       tcb->active_task = next;
-}
-
-static inline
-void mpu_switch(struct task_struct *prev, struct task_struct *next)
-{
-       struct mm_struct *oldmm;
+       next = in_tcb->core.host_task;
+       prev_mm = out_tcb->core.active_mm;
 
-       if (next && next != prev) {
-               oldmm = prev->active_mm;
-               switch_mm(oldmm, next->active_mm, next);
-       }
+       next_mm = in_tcb->core.mm;
+       if (next_mm == NULL)
+               in_tcb->core.active_mm = prev_mm;
+       else
+               ipipe_switch_mm_head(prev_mm, next_mm, next);
 }
 
 #else /* !CONFIG_MPU */
 
 static inline
-struct task_struct *mpu_get_prev(struct xnarchtcb *tcb)
-{
-       return NULL;
-}
-
-static inline
-void mpu_set_next(struct xnarchtcb *tcb, struct task_struct *next)
-{
-}
-
-static inline
-void mpu_switch(struct task_struct *prev, struct task_struct *next)
+void mpu_switch(struct xnarchtcb *out_tcb, struct xnarchtcb *in_tcb)
 {
 }
 
@@ -78,65 +58,8 @@ void mpu_switch(struct task_struct *prev, struct task_struct 
*next)
 
 void xnarch_switch_to(struct xnarchtcb *out_tcb, struct xnarchtcb *in_tcb)
 {
-       struct task_struct *prev = mpu_get_prev(out_tcb);
-       struct task_struct *next = in_tcb->user_task;
-
-       if (likely(next != NULL)) {
-               mpu_set_next(in_tcb, next);
-               ipipe_clear_foreign_stack(&xnarch_machdata.domain);
-       } else {
-               mpu_set_next(in_tcb, prev);
-               ipipe_set_foreign_stack(&xnarch_machdata.domain);
-       }
-
-       mpu_switch(prev, next);
-
-       __asm_switch_context(out_tcb->tsp, in_tcb->tsp);
-}
-
-asmlinkage static void thread_trampoline(struct xnarchtcb *tcb)
-{
-       xnpod_welcome_thread(tcb->self, tcb->imask);
-       tcb->entry(tcb->cookie);
-       xnpod_delete_thread(tcb->self);
-}
-
-void xnarch_init_thread(struct xnarchtcb *tcb,
-                       void (*entry)(void *),
-                       void *cookie,
-                       int imask,
-                       struct xnthread *thread, char *name)
-{
-       unsigned long ksp, *switchregs;
-
-       ksp = (((unsigned long)tcb->stackbase + tcb->stacksize - 40) & ~0xf);
-       switchregs = (unsigned long *)ksp;
-       /*
-        * Stack space is guaranteed to be clear, so R7:4, P5:3, fp
-        * are already zero. We only need to set r0 and rets.
-        */
-       switchregs[0] = (unsigned long)tcb;     /* r0 */
-       switchregs[9] = (unsigned long)thread_trampoline; /* rets */
-
-       tcb->ts.ksp = ksp;
-       tcb->ts.pc = (unsigned long)__asm_thread_trampoline;
-       tcb->ts.usp = 0;
-
-       tcb->entry = entry;
-       tcb->cookie = cookie;
-       tcb->self = thread;
-       tcb->imask = imask;
-       tcb->name = name;
-}
-
-void xnarch_leave_root(struct xnarchtcb *rootcb)
-{
-       /* Remember the preempted Linux task pointer. */
-       rootcb->user_task = current;
-#ifdef CONFIG_MPU
-       rootcb->active_task = current;
-#endif
-       rootcb->tsp = &current->thread;
+       mpu_switch(out_tcb, in_tcb);
+       __asm_switch_context(out_tcb->core.tsp, in_tcb->core.tsp);
 }
 
 int xnarch_escalate(void)
@@ -180,69 +103,3 @@ int xnarch_escalate(void)
 
        return 0;
 }
-
-void xnarch_init_root_tcb(struct xnarchtcb *tcb,
-                         struct xnthread *thread,
-                         const char *name)
-{
-       tcb->user_task = current;
-#ifdef CONFIG_MPU
-       tcb->active_task = NULL;
-#endif
-       tcb->tsp = &tcb->ts;
-       tcb->entry = NULL;
-       tcb->cookie = NULL;
-       tcb->self = thread;
-       tcb->imask = 0;
-       tcb->name = name;
-}
-
-void xnarch_init_shadow_tcb(struct xnarchtcb *tcb,
-                           struct xnthread *thread,
-                           const char *name)
-{
-       struct task_struct *task = current;
-
-       tcb->user_task = task;
-#ifdef CONFIG_MPU
-       tcb->active_task = NULL;
-#endif
-       tcb->tsp = &task->thread;
-       tcb->entry = NULL;
-       tcb->cookie = NULL;
-       tcb->self = thread;
-       tcb->imask = 0;
-       tcb->name = name;
-}
-
-void xnarch_init_tcb(struct xnarchtcb *tcb)
-{
-
-       tcb->user_task = NULL;
-#ifdef CONFIG_MPU
-       tcb->active_task = NULL;
-#endif
-       tcb->tsp = &tcb->ts;
-}
-
-int xnarch_alloc_stack(struct xnarchtcb *tcb, size_t stacksize)
-{
-       int ret = 0;
-
-       tcb->stacksize = stacksize;
-       if (stacksize == 0)
-               tcb->stackbase = NULL;
-       else {
-               tcb->stackbase = xnmalloc(stacksize);
-               if (tcb->stackbase == NULL)
-                       ret = -ENOMEM;
-       }
-
-       return ret;
-}
-
-void xnarch_free_stack(struct xnarchtcb *tcb)
-{
-       if (tcb->stackbase)
-               xnfree(tcb->stackbase);
-}


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to