forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/arch/mips/include/asm/fpu.h
....@@ -1,11 +1,7 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 /*
23 * Copyright (C) 2002 MontaVista Software Inc.
34 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
4
- *
5
- * This program is free software; you can redistribute it and/or modify it
6
- * under the terms of the GNU General Public License as published by the
7
- * Free Software Foundation; either version 2 of the License, or (at your
8
- * option) any later version.
95 */
106 #ifndef _ASM_FPU_H
117 #define _ASM_FPU_H
....@@ -30,13 +26,6 @@
3026 #include <asm/mips_mt.h>
3127 #endif
3228
33
-struct sigcontext;
34
-struct sigcontext32;
35
-
36
-extern void _init_fpu(unsigned int);
37
-extern void _save_fp(struct task_struct *);
38
-extern void _restore_fp(struct task_struct *);
39
-
4029 /*
4130 * This enum specifies a mode in which we want the FPU to operate, for cores
4231 * which implement the Status.FR bit. Note that the bottom bit of the value
....@@ -50,6 +39,11 @@
5039
5140 #define FPU_FR_MASK 0x1
5241 };
42
+
43
+#ifdef CONFIG_MIPS_FP_SUPPORT
44
+
45
+extern void _save_fp(struct task_struct *);
46
+extern void _restore_fp(struct task_struct *);
5347
5448 #define __disable_fpu() \
5549 do { \
....@@ -77,12 +71,12 @@
7771 goto fr_common;
7872
7973 case FPU_64BIT:
80
-#if !(defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR6) \
81
- || defined(CONFIG_64BIT))
74
+#if !(defined(CONFIG_CPU_MIPSR2) || defined(CONFIG_CPU_MIPSR5) || \
75
+ defined(CONFIG_CPU_MIPSR6) || defined(CONFIG_64BIT))
8276 /* we only have a 32-bit FPU */
8377 return SIGFPE;
8478 #endif
85
- /* fall through */
79
+ fallthrough;
8680 case FPU_32BIT:
8781 if (cpu_has_fre) {
8882 /* clear FRE */
....@@ -198,42 +192,36 @@
198192 preempt_enable();
199193 }
200194
201
-static inline int init_fpu(void)
195
+/**
196
+ * init_fp_ctx() - Initialize task FP context
197
+ * @target: The task whose FP context should be initialized.
198
+ *
199
+ * Initializes the FP context of the target task to sane default values if that
200
+ * target task does not already have valid FP context. Once the context has
201
+ * been initialized, the task will be marked as having used FP & thus having
202
+ * valid FP context.
203
+ *
204
+ * Returns: true if context is initialized, else false.
205
+ */
206
+static inline bool init_fp_ctx(struct task_struct *target)
202207 {
203
- unsigned int fcr31 = current->thread.fpu.fcr31;
204
- int ret = 0;
208
+ /* If FP has been used then the target already has context */
209
+ if (tsk_used_math(target))
210
+ return false;
205211
206
- if (cpu_has_fpu) {
207
- unsigned int config5;
212
+ /* Begin with data registers set to all 1s... */
213
+ memset(&target->thread.fpu.fpr, ~0, sizeof(target->thread.fpu.fpr));
208214
209
- ret = __own_fpu();
210
- if (ret)
211
- return ret;
215
+ /* FCSR has been preset by `mips_set_personality_nan'. */
212216
213
- if (!cpu_has_fre) {
214
- _init_fpu(fcr31);
217
+ /*
218
+ * Record that the target has "used" math, such that the context
219
+ * just initialised, and any modifications made by the caller,
220
+ * aren't discarded.
221
+ */
222
+ set_stopped_child_used_math(target);
215223
216
- return 0;
217
- }
218
-
219
- /*
220
- * Ensure FRE is clear whilst running _init_fpu, since
221
- * single precision FP instructions are used. If FRE
222
- * was set then we'll just end up initialising all 32
223
- * 64b registers.
224
- */
225
- config5 = clear_c0_config5(MIPS_CONF5_FRE);
226
- enable_fpu_hazard();
227
-
228
- _init_fpu(fcr31);
229
-
230
- /* Restore FRE */
231
- write_c0_config5(config5);
232
- enable_fpu_hazard();
233
- } else
234
- fpu_emulator_init_fpu();
235
-
236
- return ret;
224
+ return true;
237225 }
238226
239227 static inline void save_fp(struct task_struct *tsk)
....@@ -260,4 +248,81 @@
260248 return tsk->thread.fpu.fpr;
261249 }
262250
251
+#else /* !CONFIG_MIPS_FP_SUPPORT */
252
+
253
+/*
254
+ * When FP support is disabled we provide only a minimal set of stub functions
255
+ * to avoid callers needing to care too much about CONFIG_MIPS_FP_SUPPORT.
256
+ */
257
+
258
+static inline int __enable_fpu(enum fpu_mode mode)
259
+{
260
+ return SIGILL;
261
+}
262
+
263
+static inline void __disable_fpu(void)
264
+{
265
+ /* no-op */
266
+}
267
+
268
+
269
+static inline int is_fpu_owner(void)
270
+{
271
+ return 0;
272
+}
273
+
274
+static inline void clear_fpu_owner(void)
275
+{
276
+ /* no-op */
277
+}
278
+
279
+static inline int own_fpu_inatomic(int restore)
280
+{
281
+ return SIGILL;
282
+}
283
+
284
+static inline int own_fpu(int restore)
285
+{
286
+ return SIGILL;
287
+}
288
+
289
+static inline void lose_fpu_inatomic(int save, struct task_struct *tsk)
290
+{
291
+ /* no-op */
292
+}
293
+
294
+static inline void lose_fpu(int save)
295
+{
296
+ /* no-op */
297
+}
298
+
299
+static inline bool init_fp_ctx(struct task_struct *target)
300
+{
301
+ return false;
302
+}
303
+
304
+/*
305
+ * The following functions should only be called in paths where we know that FP
306
+ * support is enabled, typically a path where own_fpu() or __enable_fpu() have
307
+ * returned successfully. When CONFIG_MIPS_FP_SUPPORT=n it is known at compile
308
+ * time that this should never happen, so calls to these functions should be
309
+ * optimized away & never actually be emitted.
310
+ */
311
+
312
+extern void save_fp(struct task_struct *tsk)
313
+ __compiletime_error("save_fp() should not be called when CONFIG_MIPS_FP_SUPPORT=n");
314
+
315
+extern void _save_fp(struct task_struct *)
316
+ __compiletime_error("_save_fp() should not be called when CONFIG_MIPS_FP_SUPPORT=n");
317
+
318
+extern void restore_fp(struct task_struct *tsk)
319
+ __compiletime_error("restore_fp() should not be called when CONFIG_MIPS_FP_SUPPORT=n");
320
+
321
+extern void _restore_fp(struct task_struct *)
322
+ __compiletime_error("_restore_fp() should not be called when CONFIG_MIPS_FP_SUPPORT=n");
323
+
324
+extern union fpureg *get_fpu_regs(struct task_struct *tsk)
325
+ __compiletime_error("get_fpu_regs() should not be called when CONFIG_MIPS_FP_SUPPORT=n");
326
+
327
+#endif /* !CONFIG_MIPS_FP_SUPPORT */
263328 #endif /* _ASM_FPU_H */