xref: /freebsd/sys/contrib/openzfs/config/kernel-fpu.m4 (revision 5c4aa6257210502c93ad65882a8a4842d984bae2)
1dnl #
2dnl # Handle differences in kernel FPU code.
3dnl #
4dnl # Kernel
5dnl # 5.16:	XCR code put into asm/fpu/xcr.h
6dnl #		HAVE_KERNEL_FPU_XCR_HEADER
7dnl #
8dnl #		XSTATE_XSAVE and XSTATE_XRESTORE aren't accessible any more
9dnl #		HAVE_KERNEL_FPU_XSAVE_INTERNAL
10dnl #
11dnl # 5.11:	kernel_fpu_begin() is an inlined function now, so don't check
12dnl #		for it inside the kernel symbols.
13dnl #
14dnl # 5.0:	Wrappers have been introduced to save/restore the FPU state.
15dnl #		This change was made to the 4.19.38 and 4.14.120 LTS kernels.
16dnl #		HAVE_KERNEL_FPU_INTERNAL
17dnl #
18dnl # 4.2:	Use __kernel_fpu_{begin,end}()
19dnl #		HAVE_UNDERSCORE_KERNEL_FPU & KERNEL_EXPORTS_X86_FPU
20dnl #
21dnl # Pre-4.2:	Use kernel_fpu_{begin,end}()
22dnl #		HAVE_KERNEL_FPU & KERNEL_EXPORTS_X86_FPU
23dnl #
24dnl # N.B. The header check is performed before all other checks since it
25dnl # depends on HAVE_KERNEL_FPU_API_HEADER being set in confdefs.h.
26dnl #
27AC_DEFUN([ZFS_AC_KERNEL_FPU_HEADER], [
28	AC_MSG_CHECKING([whether fpu headers are available])
29	ZFS_LINUX_TRY_COMPILE([
30		#include <linux/module.h>
31		#include <asm/fpu/api.h>
32	],[
33	],[
34		AC_DEFINE(HAVE_KERNEL_FPU_API_HEADER, 1,
35		    [kernel has asm/fpu/api.h])
36		AC_MSG_RESULT(asm/fpu/api.h)
37		AC_MSG_CHECKING([whether fpu/xcr header is available])
38		ZFS_LINUX_TRY_COMPILE([
39			#include <linux/module.h>
40			#include <asm/fpu/xcr.h>
41		],[
42		],[
43			AC_DEFINE(HAVE_KERNEL_FPU_XCR_HEADER, 1,
44				[kernel has asm/fpu/xcr.h])
45			AC_MSG_RESULT(asm/fpu/xcr.h)
46		],[
47			AC_MSG_RESULT(no asm/fpu/xcr.h)
48		])
49	],[
50		AC_MSG_RESULT(i387.h & xcr.h)
51	])
52])
53
54AC_DEFUN([ZFS_AC_KERNEL_SRC_FPU], [
55	ZFS_LINUX_TEST_SRC([kernel_fpu], [
56		#include <linux/types.h>
57		#ifdef HAVE_KERNEL_FPU_API_HEADER
58		#include <asm/fpu/api.h>
59		#else
60		#include <asm/i387.h>
61		#include <asm/xcr.h>
62		#endif
63	], [
64		kernel_fpu_begin();
65		kernel_fpu_end();
66	], [], [ZFS_META_LICENSE])
67
68	ZFS_LINUX_TEST_SRC([__kernel_fpu], [
69		#include <linux/types.h>
70		#ifdef HAVE_KERNEL_FPU_API_HEADER
71		#include <asm/fpu/api.h>
72		#else
73		#include <asm/i387.h>
74		#include <asm/xcr.h>
75		#endif
76	], [
77		__kernel_fpu_begin();
78		__kernel_fpu_end();
79	], [], [ZFS_META_LICENSE])
80
81	ZFS_LINUX_TEST_SRC([fpu_internal], [
82		#if defined(__x86_64) || defined(__x86_64__) || \
83		    defined(__i386) || defined(__i386__)
84		#if !defined(__x86)
85		#define __x86
86		#endif
87		#endif
88
89		#if !defined(__x86)
90		#error Unsupported architecture
91		#endif
92
93		#include <linux/types.h>
94		#ifdef HAVE_KERNEL_FPU_API_HEADER
95		#include <asm/fpu/api.h>
96		#include <asm/fpu/internal.h>
97		#else
98		#include <asm/i387.h>
99		#include <asm/xcr.h>
100		#endif
101
102		#if !defined(XSTATE_XSAVE)
103		#error XSTATE_XSAVE not defined
104		#endif
105
106		#if !defined(XSTATE_XRESTORE)
107		#error XSTATE_XRESTORE not defined
108		#endif
109	],[
110		struct fpu *fpu = &current->thread.fpu;
111		union fpregs_state *st = &fpu->state;
112		struct fregs_state *fr __attribute__ ((unused)) = &st->fsave;
113		struct fxregs_state *fxr __attribute__ ((unused)) = &st->fxsave;
114		struct xregs_state *xr __attribute__ ((unused)) = &st->xsave;
115	])
116
117	ZFS_LINUX_TEST_SRC([fpu_xsave_internal], [
118		#include <linux/sched.h>
119		#if defined(__x86_64) || defined(__x86_64__) || \
120		    defined(__i386) || defined(__i386__)
121		#if !defined(__x86)
122		#define __x86
123		#endif
124		#endif
125
126		#if !defined(__x86)
127		#error Unsupported architecture
128		#endif
129
130		#include <linux/types.h>
131		#ifdef HAVE_KERNEL_FPU_API_HEADER
132		#include <asm/fpu/api.h>
133		#include <asm/fpu/internal.h>
134		#else
135		#include <asm/i387.h>
136		#include <asm/xcr.h>
137		#endif
138
139	],[
140		struct fpu *fpu = &current->thread.fpu;
141		union fpregs_state *st = &fpu->fpstate->regs;
142		struct fregs_state *fr __attribute__ ((unused)) = &st->fsave;
143		struct fxregs_state *fxr __attribute__ ((unused)) = &st->fxsave;
144		struct xregs_state *xr __attribute__ ((unused)) = &st->xsave;
145	])
146])
147
148AC_DEFUN([ZFS_AC_KERNEL_FPU], [
149	dnl #
150	dnl # Legacy kernel
151	dnl #
152	AC_MSG_CHECKING([whether kernel fpu is available])
153	ZFS_LINUX_TEST_RESULT([kernel_fpu_license], [
154		AC_MSG_RESULT(kernel_fpu_*)
155		AC_DEFINE(HAVE_KERNEL_FPU, 1,
156		    [kernel has kernel_fpu_* functions])
157		AC_DEFINE(KERNEL_EXPORTS_X86_FPU, 1,
158		    [kernel exports FPU functions])
159	],[
160		dnl #
161		dnl # Linux 4.2 kernel
162		dnl #
163		ZFS_LINUX_TEST_RESULT_SYMBOL([__kernel_fpu_license],
164		    [__kernel_fpu_begin],
165		    [arch/x86/kernel/fpu/core.c arch/x86/kernel/i387.c], [
166			AC_MSG_RESULT(__kernel_fpu_*)
167			AC_DEFINE(HAVE_UNDERSCORE_KERNEL_FPU, 1,
168			    [kernel has __kernel_fpu_* functions])
169			AC_DEFINE(KERNEL_EXPORTS_X86_FPU, 1,
170			    [kernel exports FPU functions])
171		],[
172			ZFS_LINUX_TEST_RESULT([fpu_internal], [
173				AC_MSG_RESULT(internal)
174				AC_DEFINE(HAVE_KERNEL_FPU_INTERNAL, 1,
175				    [kernel fpu internal])
176			],[
177				ZFS_LINUX_TEST_RESULT([fpu_xsave_internal], [
178				    AC_MSG_RESULT(internal with internal XSAVE)
179				    AC_DEFINE(HAVE_KERNEL_FPU_XSAVE_INTERNAL, 1,
180					[kernel fpu and XSAVE internal])
181			    ],[
182				AC_MSG_RESULT(unavailable)
183			    ])
184			])
185		])
186	])
187])
188