Xenomai  3.0.5
fptest.h
1 /*
2  * Copyright (C) 2006 Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>.
3  *
4  * Xenomai is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * Xenomai is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Xenomai; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 #ifndef _COBALT_X86_ASM_FPTEST_H
20 #define _COBALT_X86_ASM_FPTEST_H
21 
22 #include <linux/errno.h>
23 #include <asm/processor.h>
24 #include <asm/xenomai/wrappers.h>
25 #include <asm/xenomai/uapi/fptest.h>
26 
27 static inline int fp_kernel_supported(void)
28 {
29  return 1;
30 }
31 
32 static inline int fp_linux_begin(void)
33 {
34 #if defined(CONFIG_X86_USE_3DNOW) \
35  || defined(CONFIG_MD_RAID456) || defined(CONFIG_MD_RAID456_MODULE)
36  /* Ther kernel uses x86 FPU, we can not also use it in our tests. */
37  static int once = 0;
38  if (!once) {
39  once = 1;
40  printk("%s:%d: Warning: Linux is compiled to use FPU in "
41  "kernel-space.\nFor this reason, switchtest can not "
42  "test using FPU in Linux kernel-space.\n",
43  __FILE__, __LINE__);
44  }
45  return -EBUSY;
46 #endif /* 3DNow or RAID 456 */
47  kernel_fpu_begin();
48  /* kernel_fpu_begin() does no re-initialize the fpu context, but
49  fp_regs_set() implicitely expects an initialized fpu context, so
50  initialize it here. */
51  __asm__ __volatile__("fninit");
52  return 0;
53 }
54 
55 static inline void fp_linux_end(void)
56 {
57  kernel_fpu_end();
58 }
59 
60 static inline int fp_detect(void)
61 {
62  int features = 0;
63 
64 #ifndef cpu_has_xmm2
65 #ifdef cpu_has_sse2
66 #define cpu_has_xmm2 cpu_has_sse2
67 #else
68 #define cpu_has_xmm2 0
69 #endif
70 #endif
71  if (cpu_has_xmm2)
72  features |= __COBALT_HAVE_SSE2;
73 
74 #ifndef cpu_has_avx
75 #define cpu_has_avx 0
76 #endif
77  if (cpu_has_avx)
78  features |= __COBALT_HAVE_AVX;
79 
80  return features;
81 }
82 
83 #endif /* _COBALT_X86_ASM_FPTEST_H */