1 /* $NetBSD: os_types.h,v 1.4 2022/07/24 20:05:08 riastradh Exp $ */ 2 3 /* 4 * Copyright 2012-16 Advanced Micro Devices, Inc. 5 * Copyright 2019 Raptor Engineering, LLC 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in 15 * all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 * OTHER DEALINGS IN THE SOFTWARE. 24 * 25 * Authors: AMD 26 * 27 */ 28 29 #ifndef _OS_TYPES_H_ 30 #define _OS_TYPES_H_ 31 32 #include <linux/kgdb.h> 33 #include <linux/kref.h> 34 #include <linux/types.h> 35 #include <linux/slab.h> 36 37 #include <asm/byteorder.h> 38 39 #include <drm/drm_print.h> 40 41 #include "cgs_common.h" 42 43 #if defined(__BIG_ENDIAN) && !defined(BIGENDIAN_CPU) 44 #define BIGENDIAN_CPU 45 #elif defined(__LITTLE_ENDIAN) && !defined(LITTLEENDIAN_CPU) 46 #define LITTLEENDIAN_CPU 47 #endif 48 49 #undef FRAME_SIZE 50 51 #define dm_output_to_console(fmt, ...) DRM_DEBUG_KMS(fmt, ##__VA_ARGS__) 52 53 #define dm_error(fmt, ...) DRM_ERROR(fmt, ##__VA_ARGS__) 54 55 #if defined(CONFIG_DRM_AMD_DC_DCN) 56 #ifdef __NetBSD__ 57 #if defined(__i386__) || defined(__x86_64__) 58 #include <x86/fpu.h> 59 #define DC_FP_START() fpu_kern_enter() 60 #define DC_FP_END() fpu_kern_leave() 61 #elif defined(__arm__) || defined(__aarch64__) 62 #include <arm/fpu.h> 63 #define DC_FP_START() fpu_kern_enter() 64 #define DC_FP_END() fpu_kern_leave() 65 #endif 66 #else /* !__NetBSD__ */ 67 #if defined(CONFIG_X86) 68 #include <asm/fpu/api.h> 69 #define DC_FP_START() kernel_fpu_begin() 70 #define DC_FP_END() kernel_fpu_end() 71 #elif defined(CONFIG_PPC64) 72 #include <asm/switch_to.h> 73 #include <asm/cputable.h> 74 #define DC_FP_START() { \ 75 if (cpu_has_feature(CPU_FTR_VSX_COMP)) { \ 76 preempt_disable(); \ 77 enable_kernel_vsx(); \ 78 } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) { \ 79 preempt_disable(); \ 80 enable_kernel_altivec(); \ 81 } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) { \ 82 preempt_disable(); \ 83 enable_kernel_fp(); \ 84 } \ 85 } 86 #define DC_FP_END() { \ 87 if (cpu_has_feature(CPU_FTR_VSX_COMP)) { \ 88 disable_kernel_vsx(); \ 89 preempt_enable(); \ 90 } else if (cpu_has_feature(CPU_FTR_ALTIVEC_COMP)) { \ 91 disable_kernel_altivec(); \ 92 preempt_enable(); \ 93 } else if (!cpu_has_feature(CPU_FTR_FPU_UNAVAILABLE)) { \ 94 disable_kernel_fp(); \ 95 preempt_enable(); \ 96 } \ 97 } 98 #endif 99 #endif 100 #endif 101 102 /* 103 * 104 * general debug capabilities 105 * 106 */ 107 #if defined(CONFIG_HAVE_KGDB) || defined(CONFIG_KGDB) 108 #define ASSERT_CRITICAL(expr) do { \ 109 if (WARN_ON(!(expr))) { \ 110 kgdb_breakpoint(); \ 111 } \ 112 } while (0) 113 #else 114 #define ASSERT_CRITICAL(expr) do { \ 115 if (WARN_ON(!(expr))) { \ 116 ; \ 117 } \ 118 } while (0) 119 #endif 120 121 #if defined(CONFIG_DEBUG_KERNEL_DC) 122 #define ASSERT(expr) ASSERT_CRITICAL(expr) 123 124 #else 125 #define ASSERT(expr) WARN_ON(!(expr)) 126 #endif 127 128 #define BREAK_TO_DEBUGGER() ASSERT(0) 129 130 #define DC_ERR(...) do { \ 131 dm_error(__VA_ARGS__); \ 132 BREAK_TO_DEBUGGER(); \ 133 } while (0) 134 135 #endif /* _OS_TYPES_H_ */ 136