]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/amd/display: Add control mechanism for FPU
authorRodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Tue, 27 Jul 2021 00:52:46 +0000 (20:52 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 6 Aug 2021 01:17:59 +0000 (21:17 -0400)
DC invokes DC_FPU_START/END in multiple parts of the code; this can
create a situation where we invoke this FPU operation in a nested way or
exit too early. For avoiding this situation, this commit adds a
mechanism where dc_fpu_begin/end manages the access to
kernel_fpu_begin/end.

Change since V3:
- Christian: Move PPC64 code to dc_fpu_begin/end.

Change since V2:
- Christian: Do not use this_cpu_* between get/put_cpu_ptr().

Change since V1:
- Use a better variable names
- Use get_cpu_ptr and put_cpu_ptr to better balance preemption enable
and disable

Cc: Harry Wentland <harry.wentland@amd.com>
Cc: Anson Jacob <Anson.Jacob@amd.com>
Cc: Christian König <christian.koenig@amd.com>
Cc: Hersen Wu <hersenxs.wu@amd.com>
Cc: Aric Cyr <aric.cyr@amd.com>
Cc: Jun Lei <jun.lei@amd.com>
Cc: Dmytro Laktyushkin <dmytro.laktyushkin@amd.com>
Cc: Qingqing Zhuo <qingqing.zhuo@amd.com>
Signed-off-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/amdgpu_dm/Makefile
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_trace.h
drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.c [new file with mode: 0644]
drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.h [new file with mode: 0644]
drivers/gpu/drm/amd/display/dc/dc_trace.h
drivers/gpu/drm/amd/display/dc/os_types.h

index 91fb72c965455385e24f31b6a27205e398a6801c..718e123a32300a9e79833942764029db0d670f9d 100644 (file)
 
 AMDGPUDM = amdgpu_dm.o amdgpu_dm_irq.o amdgpu_dm_mst_types.o amdgpu_dm_color.o
 
+ifdef CONFIG_DRM_AMD_DC_DCN
+AMDGPUDM += dc_fpu.o
+endif
+
 ifneq ($(CONFIG_DRM_AMD_DC),)
 AMDGPUDM += amdgpu_dm_services.o amdgpu_dm_helpers.o amdgpu_dm_pp_smu.o amdgpu_dm_psr.o
 endif
index 46a33f64cf8ecfe34dcaa5acb0972958c64452fd..230bb12c405ec4774726fa870a33c4fd7e4a4446 100644 (file)
@@ -637,6 +637,27 @@ TRACE_EVENT(amdgpu_refresh_rate_track,
                  __entry->refresh_rate_ns)
 );
 
+TRACE_EVENT(dcn_fpu,
+           TP_PROTO(bool begin, const char *function, const int line),
+           TP_ARGS(begin, function, line),
+
+           TP_STRUCT__entry(
+                            __field(bool, begin)
+                            __field(const char *, function)
+                            __field(int, line)
+           ),
+           TP_fast_assign(
+                          __entry->begin = begin;
+                          __entry->function = function;
+                          __entry->line = line;
+           ),
+           TP_printk("%s()+%d: %s",
+                     __entry->function,
+                     __entry->line,
+                     __entry->begin ? "begin" : "end"
+           )
+);
+
 #endif /* _AMDGPU_DM_TRACE_H_ */
 
 #undef TRACE_INCLUDE_PATH
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.c b/drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.c
new file mode 100644 (file)
index 0000000..d4ab27b
--- /dev/null
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: MIT
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#include "dc_trace.h"
+
+#if defined(CONFIG_X86)
+#include <asm/fpu/api.h>
+#elif defined(CONFIG_PPC64)
+#include <asm/switch_to.h>
+#include <asm/cputable.h>
+#endif
+
+/**
+ * dc_fpu_begin - Enables FPU protection
+ * @function_name: A string containing the function name for debug purposes
+ *   (usually __func__)
+ *
+ * @line: A line number where DC_FP_START was invoked for debug purpose
+ *   (usually __LINE__)
+ *
+ * This function is responsible for managing the use of kernel_fpu_begin() with
+ * the advantage of providing an event trace for debugging.
+ *
+ * Note: Do not call this function directly; always use DC_FP_START().
+ */
+void dc_fpu_begin(const char *function_name, const int line)
+{
+       TRACE_DCN_FPU(true, function_name, line);
+
+#if defined(CONFIG_X86)
+       kernel_fpu_begin();
+#elif defined(CONFIG_PPC64)
+       if (cpu_has_feature(CPU_FTR_VSX_COMP)) {
+               preempt_disable();
+               enable_kernel_vsx();
+       } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) {
+               preempt_disable();
+               enable_kernel_altivec();
+       } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) {
+               preempt_disable();
+               enable_kernel_fp();
+       }
+#endif
+}
+
+/**
+ * dc_fpu_end - Disable FPU protection
+ * @function_name: A string containing the function name for debug purposes
+ * @line: A-line number where DC_FP_END was invoked for debug purpose
+ *
+ * This function is responsible for managing the use of kernel_fpu_end() with
+ * the advantage of providing an event trace for debugging.
+ *
+ * Note: Do not call this function directly; always use DC_FP_END().
+ */
+void dc_fpu_end(const char *function_name, const int line)
+{
+       TRACE_DCN_FPU(false, function_name, line);
+#if defined(CONFIG_X86)
+       kernel_fpu_end();
+#elif defined(CONFIG_PPC64)
+       if (cpu_has_feature(CPU_FTR_VSX_COMP)) {
+               disable_kernel_vsx();
+               preempt_enable();
+       } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) {
+               disable_kernel_altivec();
+               preempt_enable();
+       } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) {
+               disable_kernel_fp();
+               preempt_enable();
+       }
+#endif
+}
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.h b/drivers/gpu/drm/amd/display/amdgpu_dm/dc_fpu.h
new file mode 100644 (file)
index 0000000..fb54983
--- /dev/null
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright 2021 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors: AMD
+ *
+ */
+
+#ifndef __DC_FPU_H__
+#define __DC_FPU_H__
+
+void dc_fpu_begin(const char *function_name, const int line);
+void dc_fpu_end(const char *function_name, const int line);
+
+#endif /* __DC_FPU_H__ */
index d2615357269b096ea3ec7c8856ba031aac694e87..d598ba697e4585f170b4cff819bd85fe21c31061 100644 (file)
@@ -37,3 +37,6 @@
 
 #define TRACE_DCN_CLOCK_STATE(dcn_clocks) \
        trace_amdgpu_dm_dc_clocks_state(dcn_clocks)
+
+#define TRACE_DCN_FPU(begin, function, line) \
+       trace_dcn_fpu(begin, function, line)
index 126c2f3a4dd3b289b4ab871d8af5a8b48c42e70b..f50cae252de41c70ed70d6ce77ce9f4879353fd7 100644 (file)
 #define dm_error(fmt, ...) DRM_ERROR(fmt, ##__VA_ARGS__)
 
 #if defined(CONFIG_DRM_AMD_DC_DCN)
-#if defined(CONFIG_X86)
-#include <asm/fpu/api.h>
-#define DC_FP_START() kernel_fpu_begin()
-#define DC_FP_END() kernel_fpu_end()
-#elif defined(CONFIG_PPC64)
-#include <asm/switch_to.h>
-#include <asm/cputable.h>
-#define DC_FP_START() { \
-       if (cpu_has_feature(CPU_FTR_VSX_COMP)) { \
-               preempt_disable(); \
-               enable_kernel_vsx(); \
-       } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) { \
-               preempt_disable(); \
-               enable_kernel_altivec(); \
-       } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) { \
-               preempt_disable(); \
-               enable_kernel_fp(); \
-       } \
-}
-#define DC_FP_END() { \
-       if (cpu_has_feature(CPU_FTR_VSX_COMP)) { \
-               disable_kernel_vsx(); \
-               preempt_enable(); \
-       } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) { \
-               disable_kernel_altivec(); \
-               preempt_enable(); \
-       } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) { \
-               disable_kernel_fp(); \
-               preempt_enable(); \
-       } \
-}
-#endif
+#include "amdgpu_dm/dc_fpu.h"
+#define DC_FP_START() dc_fpu_begin(__func__, __LINE__)
+#define DC_FP_END() dc_fpu_end(__func__, __LINE__)
 #endif
 
 /*