Module: xenomai-3
Branch: next
Commit: 7dea971f53421d8b260258b431fc568ac5c8e1bd
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7dea971f53421d8b260258b431fc568ac5c8e1bd

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Jul  7 10:52:41 2016 +0200

cobalt/powerpc: cleanup fpu support

In order to support the Book3E architecture, we now rely on the
regular kernel accessors for manipulating the MSR, instead of assuming
Book3S.

In the same move, some obsolete compat code for kernel releases prior
to v3.10 (i.e. not supported by Cobalt) was dropped.

---

 kernel/cobalt/arch/powerpc/fpu.S    |   58 +++++++++++++----------------------
 kernel/cobalt/arch/powerpc/thread.c |   51 ++++++------------------------
 2 files changed, 31 insertions(+), 78 deletions(-)

diff --git a/kernel/cobalt/arch/powerpc/fpu.S b/kernel/cobalt/arch/powerpc/fpu.S
index bd9bcc1..186e922 100644
--- a/kernel/cobalt/arch/powerpc/fpu.S
+++ b/kernel/cobalt/arch/powerpc/fpu.S
@@ -23,46 +23,15 @@
 #include <asm/ppc_asm.h>
 #include <asm/asm-offsets.h>
 
-#ifdef CONFIG_PPC601_SYNC_FIX
-#define SYNC                           \
-BEGIN_FTR_SECTION                      \
-       sync;                           \
-       isync;                          \
-END_FTR_SECTION_IFSET(CPU_FTR_601)
-#else /* !CONFIG_PPC601_SYNC_FIX */
-#define        SYNC
-#endif /* CONFIG_PPC601_SYNC_FIX */
-
-#ifdef CONFIG_PPC64
-#ifndef MTMSRD
-#define MTMSRD(r)      mtmsrd  r
-#endif
-#ifndef MTFSF_L
-#define MTFSF_L(REG) \
-       .long (0xfc00058e | ((0xff) << 17) | ((REG) << 11) | (1 << 25))
-#endif
-#else /* !CONFIG_PPC64 */
-#ifndef MTMSRD
-#define MTMSRD(r)      mtmsr   r
-#endif
-#ifndef MTFSF_L
-#define MTFSF_L(REG)   mtfsf   0xff, (REG)
-#endif
-#endif /* !CONFIG_PPC64 */
-
 #ifdef THREAD_FPSTATE
-#define FIXUP_REG_FPSTATE(__reg) addi  __reg,__reg,THREAD_FPSTATE
+#define FIXUP_REG_FPSTATE(__reg)       addi    __reg, __reg, THREAD_FPSTATE
 #else
-#define FIXUP_REG_FPSTATE(__reg)
-#ifndef THREAD_FPSCR
 /*
- * The following accessor has to work with ancient kernel versions,
- * for which THREAD_FPSCR is not usable for 64bit save/restore.
+ * v3.10 -> v3.13 do not have THREAD_FPSTATE yet, but still
+ * define THREAD_FPSCR.
  */
-#define FPSTATE_FPSCR(base)    THREAD_FPR0+32*8(base)
-#else
-#define        FPSTATE_FPSCR(base)     THREAD_FPSCR(base)
-#endif
+#define FIXUP_REG_FPSTATE(__reg)
+#define        FPSTATE_FPSCR(__base)           THREAD_FPSCR(__base)
 #endif
 
 /* r3 = &thread_struct (tcb->fpup) */
@@ -99,3 +68,20 @@ _GLOBAL(__asm_restore_fpu)
        MTFSF_L(fr0)
        REST_32FPRS(0,r3)
        blr
+
+_GLOBAL(__asm_disable_fpu)
+       mfmsr   r5
+       li      r3,MSR_FP
+       andc    r5,r5,r3
+       SYNC
+       MTMSRD(r5)
+       isync
+       blr
+
+_GLOBAL(__asm_enable_fpu)
+       mfmsr   r5
+       ori     r5,r5,MSR_FP
+       SYNC
+       MTMSRD(r5)
+       isync
+       blr
diff --git a/kernel/cobalt/arch/powerpc/thread.c 
b/kernel/cobalt/arch/powerpc/thread.c
index 7f6ff87..2a61d50 100644
--- a/kernel/cobalt/arch/powerpc/thread.c
+++ b/kernel/cobalt/arch/powerpc/thread.c
@@ -67,6 +67,10 @@ asmlinkage void __asm_save_fpu(struct thread_struct *ts);
 
 asmlinkage void __asm_restore_fpu(struct thread_struct *ts);
 
+asmlinkage void __asm_disable_fpu(void);
+
+asmlinkage void __asm_enable_fpu(void);
+
 #ifndef CONFIG_SMP
 #define get_fpu_owner(cur) last_task_used_math
 #else /* CONFIG_SMP */
@@ -77,53 +81,15 @@ asmlinkage void __asm_restore_fpu(struct thread_struct *ts);
 })
 #endif /* CONFIG_SMP */
 
-#ifdef CONFIG_PPC64
-#define do_disable_fpu() ({                            \
-    register unsigned long _msr;                        \
-    __asm__ __volatile__ ( "mfmsr %0" : "=r"(_msr) );   \
-    __asm__ __volatile__ ( "mtmsrd %0"                  \
-                          : /* no output */            \
-                          : "r"(_msr & ~(MSR_FP))      \
-                          : "memory" );                \
-})
-
-#define do_enable_fpu() ({                             \
-    register unsigned long _msr;                        \
-    __asm__ __volatile__ ( "mfmsr %0" : "=r"(_msr) );   \
-    __asm__ __volatile__ ( "mtmsrd %0"                  \
-                          : /* no output */            \
-                          : "r"(_msr | MSR_FP)         \
-                          : "memory" );                \
-})
-#else /* !CONFIG_PPC64 */
-#define do_disable_fpu() ({                            \
-    register unsigned long _msr;                        \
-    __asm__ __volatile__ ( "mfmsr %0" : "=r"(_msr) );   \
-    __asm__ __volatile__ ( "mtmsr %0"                   \
-                          : /* no output */            \
-                          : "r"(_msr & ~(MSR_FP))      \
-                          : "memory" );                \
-})
-
-#define do_enable_fpu() ({                             \
-    register unsigned long _msr;                        \
-    __asm__ __volatile__ ( "mfmsr %0" : "=r"(_msr) );   \
-    __asm__ __volatile__ ( "mtmsr %0"                   \
-                          : /* no output */            \
-                          : "r"(_msr | MSR_FP)         \
-                          : "memory" );                \
-})
-#endif /* CONFIG_PPC64 */
-
 static void xnarch_enable_fpu(struct xnthread *thread)
 {
        struct xnarchtcb *tcb = xnthread_archtcb(thread);
        struct task_struct *task = tcb->core.host_task;
 
        if (task && task != tcb->core.user_fpu_owner)
-               do_disable_fpu();
+               __asm_disable_fpu();
        else
-               do_enable_fpu();
+               __asm_enable_fpu();
 }
 
 void xnarch_save_fpu(struct xnthread *thread)
@@ -164,8 +130,9 @@ static void xnarch_restore_fpu(struct xnthread *thread)
         * FIXME: We restore FPU "as it was" when Xenomai preempted Linux,
         * whereas we could be much lazier.
         */
-       if (tcb->core.host_task && tcb->core.host_task != 
tcb->core.user_fpu_owner)
-               do_disable_fpu();
+       if (tcb->core.host_task &&
+           tcb->core.host_task != tcb->core.user_fpu_owner)
+               __asm_disable_fpu();
 }
 
 void xnarch_switch_fpu(struct xnthread *from, struct xnthread *to)


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

Reply via email to