1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright 2025 Advanced Micro Devices, Inc. 4 * 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: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 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. 22 * 23 */ 24 25 #ifndef __RAS_SYS_H__ 26 #define __RAS_SYS_H__ 27 #include <linux/stdarg.h> 28 #include <linux/printk.h> 29 #include <linux/dev_printk.h> 30 #include <linux/mempool.h> 31 #include <linux/math64.h> 32 #include <linux/time.h> 33 #include "amdgpu.h" 34 #include "amdgpu_ip.h" 35 36 /* inject address is 52 bits */ 37 #define RAS_UMC_INJECT_ADDR_LIMIT (0x1ULL << 52) 38 39 #define RAS_DEV_ERR(device, fmt, ...) \ 40 do { \ 41 if (device) \ 42 dev_err(((struct amdgpu_device *)device)->dev, fmt, ##__VA_ARGS__); \ 43 else \ 44 printk(KERN_ERR fmt, ##__VA_ARGS__); \ 45 } while (0) 46 47 #define RAS_DEV_WARN(device, fmt, ...) \ 48 do { \ 49 if (device) \ 50 dev_warn(((struct amdgpu_device *)device)->dev, fmt, ##__VA_ARGS__); \ 51 else \ 52 printk(KERN_WARNING fmt, ##__VA_ARGS__); \ 53 } while (0) 54 55 #define RAS_DEV_WARN_RATELIMITED(device, fmt, ...) \ 56 do { \ 57 if (device) \ 58 dev_warn_ratelimited(((struct amdgpu_device *)device)->dev, \ 59 fmt, ##__VA_ARGS__); \ 60 else \ 61 printk_ratelimited(KERN_WARNING fmt, ##__VA_ARGS__); \ 62 } while (0) 63 64 #define RAS_DEV_INFO(device, fmt, ...) \ 65 do { \ 66 if (device) \ 67 dev_info(((struct amdgpu_device *)device)->dev, fmt, ##__VA_ARGS__); \ 68 else \ 69 printk(KERN_INFO fmt, ##__VA_ARGS__); \ 70 } while (0) 71 72 #define RAS_DEV_DBG(device, fmt, ...) \ 73 do { \ 74 if (device) \ 75 dev_dbg(((struct amdgpu_device *)device)->dev, fmt, ##__VA_ARGS__); \ 76 else \ 77 printk(KERN_DEBUG fmt, ##__VA_ARGS__); \ 78 } while (0) 79 80 #define RAS_INFO(fmt, ...) printk(KERN_INFO fmt, ##__VA_ARGS__) 81 82 #define RAS_DEV_RREG32_SOC15(dev, ip, inst, reg) \ 83 ({ \ 84 struct amdgpu_device *adev = (struct amdgpu_device *)dev; \ 85 __RREG32_SOC15_RLC__(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg, \ 86 0, ip##_HWIP, inst); \ 87 }) 88 89 #define RAS_DEV_WREG32_SOC15(dev, ip, inst, reg, value) \ 90 ({ \ 91 struct amdgpu_device *adev = (struct amdgpu_device *)dev; \ 92 __WREG32_SOC15_RLC__((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), \ 93 value, 0, ip##_HWIP, inst); \ 94 }) 95 96 /* GET_INST returns the physical instance corresponding to a logical instance */ 97 #define RAS_GET_INST(dev, ip, inst) \ 98 ({ \ 99 struct amdgpu_device *adev = (struct amdgpu_device *)dev; \ 100 amdgpu_ip_map_logical_to_dev_inst(&adev->ip_map, ip##_HWIP, inst); \ 101 }) 102 103 #define RAS_GET_MASK(dev, ip, mask) \ 104 ({ \ 105 struct amdgpu_device *adev = (struct amdgpu_device *)dev; \ 106 amdgpu_ip_map_logical_to_dev_mask(&adev->ip_map, ip##_HWIP, mask); \ 107 }) 108 109 static inline void *ras_radix_tree_delete_iter(struct radix_tree_root *root, void *iter) 110 { 111 return radix_tree_delete(root, ((struct radix_tree_iter *)iter)->index); 112 } 113 114 static inline long ras_wait_event_interruptible_timeout(void *wq_head, 115 int (*condition)(void *param), void *param, unsigned int timeout) 116 { 117 return wait_event_interruptible_timeout(*(wait_queue_head_t *)wq_head, 118 condition(param), timeout); 119 } 120 121 extern const struct ras_sys_func amdgpu_ras_sys_fn; 122 123 #endif 124