1 // SPDX-License-Identifier: MIT
3 * Copyright 2021 Advanced Micro Devices, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
29 #if defined(CONFIG_X86)
30 #include <asm/fpu/api.h>
31 #elif defined(CONFIG_PPC64)
32 #include <asm/switch_to.h>
33 #include <asm/cputable.h>
34 #elif defined(CONFIG_ARM64)
39 * DOC: DC FPU manipulation overview
41 * DC core uses FPU operations in multiple parts of the code, which requires a
42 * more specialized way to manage these areas' entrance. To fulfill this
43 * requirement, we created some wrapper functions that encapsulate
44 * kernel_fpu_begin/end to better fit our need in the display component. In
45 * summary, in this file, you can find functions related to FPU operation
49 static DEFINE_PER_CPU(int, fpu_recursion_depth);
52 * dc_assert_fp_enabled - Check if FPU protection is enabled
54 * This function tells if the code is already under FPU protection or not. A
55 * function that works as an API for a set of FPU operations can use this
56 * function for checking if the caller invoked it after DC_FP_START(). For
57 * example, take a look at dcn20_fpu.c file.
59 inline void dc_assert_fp_enabled(void)
63 pcpu = get_cpu_ptr(&fpu_recursion_depth);
65 put_cpu_ptr(&fpu_recursion_depth);
71 * dc_fpu_begin - Enables FPU protection
72 * @function_name: A string containing the function name for debug purposes
75 * @line: A line number where DC_FP_START was invoked for debug purpose
78 * This function is responsible for managing the use of kernel_fpu_begin() with
79 * the advantage of providing an event trace for debugging.
81 * Note: Do not call this function directly; always use DC_FP_START().
83 void dc_fpu_begin(const char *function_name, const int line)
87 pcpu = get_cpu_ptr(&fpu_recursion_depth);
91 #if defined(CONFIG_X86)
94 #elif defined(CONFIG_PPC64)
95 if (cpu_has_feature(CPU_FTR_VSX_COMP)) {
98 } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) {
100 enable_kernel_altivec();
101 } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) {
105 #elif defined(CONFIG_ARM64)
110 TRACE_DCN_FPU(true, function_name, line, *pcpu);
111 put_cpu_ptr(&fpu_recursion_depth);
115 * dc_fpu_end - Disable FPU protection
116 * @function_name: A string containing the function name for debug purposes
117 * @line: A-line number where DC_FP_END was invoked for debug purpose
119 * This function is responsible for managing the use of kernel_fpu_end() with
120 * the advantage of providing an event trace for debugging.
122 * Note: Do not call this function directly; always use DC_FP_END().
124 void dc_fpu_end(const char *function_name, const int line)
128 pcpu = get_cpu_ptr(&fpu_recursion_depth);
131 #if defined(CONFIG_X86)
134 #elif defined(CONFIG_PPC64)
135 if (cpu_has_feature(CPU_FTR_VSX_COMP)) {
136 disable_kernel_vsx();
138 } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) {
139 disable_kernel_altivec();
141 } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) {
145 #elif defined(CONFIG_ARM64)
150 TRACE_DCN_FPU(false, function_name, line, *pcpu);
151 put_cpu_ptr(&fpu_recursion_depth);