2 * Copyright 2018 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
27 #include <linux/debugfs.h>
28 #include <linux/list.h>
30 #include "amdgpu_psp.h"
31 #include "ta_ras_if.h"
33 enum amdgpu_ras_block {
34 AMDGPU_RAS_BLOCK__UMC = 0,
35 AMDGPU_RAS_BLOCK__SDMA,
36 AMDGPU_RAS_BLOCK__GFX,
37 AMDGPU_RAS_BLOCK__MMHUB,
38 AMDGPU_RAS_BLOCK__ATHUB,
39 AMDGPU_RAS_BLOCK__PCIE_BIF,
40 AMDGPU_RAS_BLOCK__HDP,
41 AMDGPU_RAS_BLOCK__XGMI_WAFL,
43 AMDGPU_RAS_BLOCK__SMN,
44 AMDGPU_RAS_BLOCK__SEM,
45 AMDGPU_RAS_BLOCK__MP0,
46 AMDGPU_RAS_BLOCK__MP1,
47 AMDGPU_RAS_BLOCK__FUSE,
49 AMDGPU_RAS_BLOCK__LAST
52 #define AMDGPU_RAS_BLOCK_COUNT AMDGPU_RAS_BLOCK__LAST
53 #define AMDGPU_RAS_BLOCK_MASK ((1ULL << AMDGPU_RAS_BLOCK_COUNT) - 1)
55 enum amdgpu_ras_error_type {
56 AMDGPU_RAS_ERROR__NONE = 0,
57 AMDGPU_RAS_ERROR__PARITY = 1,
58 AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE = 2,
59 AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE = 4,
60 AMDGPU_RAS_ERROR__POISON = 8,
64 AMDGPU_RAS_SUCCESS = 0,
71 struct ras_common_if {
72 enum amdgpu_ras_block block;
73 enum amdgpu_ras_error_type type;
74 uint32_t sub_block_index;
79 typedef int (*ras_ih_cb)(struct amdgpu_device *adev,
80 struct amdgpu_iv_entry *entry);
83 /* ras infrastructure */
85 uint32_t hw_supported;
86 /* for IP to check its ras ability. */
89 struct list_head head;
95 struct device_attribute features_attr;
96 struct bin_attribute badpages_attr;
98 struct ras_manager *objs;
101 struct work_struct recovery_work;
102 atomic_t in_recovery;
103 struct amdgpu_device *adev;
104 /* error handler data */
105 struct ras_err_handler_data *eh_data;
106 struct mutex recovery_lock;
111 /* interfaces for IP */
114 struct ras_common_if head;
116 char debugfs_name[32];
119 struct ras_query_if {
120 struct ras_common_if head;
121 unsigned long ue_count;
122 unsigned long ce_count;
125 struct ras_inject_if {
126 struct ras_common_if head;
132 struct ras_common_if head;
137 struct ras_common_if head;
141 struct ras_dispatch_if {
142 struct ras_common_if head;
143 struct amdgpu_iv_entry *entry;
146 struct ras_debug_if {
148 struct ras_common_if head;
149 struct ras_inject_if inject;
155 * 1: ras feature enable (enabled by default)
157 * 2: ras framework init (in ip_init)
160 * 4: debugfs/sysfs create
162 * 6: debugfs/sysfs remove
167 #define amdgpu_ras_get_context(adev) ((adev)->psp.ras.ras)
168 #define amdgpu_ras_set_context(adev, ras_con) ((adev)->psp.ras.ras = (ras_con))
170 /* check if ras is supported on block, say, sdma, gfx */
171 static inline int amdgpu_ras_is_supported(struct amdgpu_device *adev,
174 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
176 if (block >= AMDGPU_RAS_BLOCK_COUNT)
178 return ras && (ras->supported & (1 << block));
181 int amdgpu_ras_request_reset_on_boot(struct amdgpu_device *adev,
184 void amdgpu_ras_resume(struct amdgpu_device *adev);
185 void amdgpu_ras_suspend(struct amdgpu_device *adev);
187 int amdgpu_ras_query_error_count(struct amdgpu_device *adev,
190 /* error handling functions */
191 int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
192 unsigned long *bps, int pages);
194 int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev);
196 static inline int amdgpu_ras_reset_gpu(struct amdgpu_device *adev,
199 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
201 if (atomic_cmpxchg(&ras->in_recovery, 0, 1) == 0)
202 schedule_work(&ras->recovery_work);
206 static inline enum ta_ras_block
207 amdgpu_ras_block_to_ta(enum amdgpu_ras_block block) {
209 case AMDGPU_RAS_BLOCK__UMC:
210 return TA_RAS_BLOCK__UMC;
211 case AMDGPU_RAS_BLOCK__SDMA:
212 return TA_RAS_BLOCK__SDMA;
213 case AMDGPU_RAS_BLOCK__GFX:
214 return TA_RAS_BLOCK__GFX;
215 case AMDGPU_RAS_BLOCK__MMHUB:
216 return TA_RAS_BLOCK__MMHUB;
217 case AMDGPU_RAS_BLOCK__ATHUB:
218 return TA_RAS_BLOCK__ATHUB;
219 case AMDGPU_RAS_BLOCK__PCIE_BIF:
220 return TA_RAS_BLOCK__PCIE_BIF;
221 case AMDGPU_RAS_BLOCK__HDP:
222 return TA_RAS_BLOCK__HDP;
223 case AMDGPU_RAS_BLOCK__XGMI_WAFL:
224 return TA_RAS_BLOCK__XGMI_WAFL;
225 case AMDGPU_RAS_BLOCK__DF:
226 return TA_RAS_BLOCK__DF;
227 case AMDGPU_RAS_BLOCK__SMN:
228 return TA_RAS_BLOCK__SMN;
229 case AMDGPU_RAS_BLOCK__SEM:
230 return TA_RAS_BLOCK__SEM;
231 case AMDGPU_RAS_BLOCK__MP0:
232 return TA_RAS_BLOCK__MP0;
233 case AMDGPU_RAS_BLOCK__MP1:
234 return TA_RAS_BLOCK__MP1;
235 case AMDGPU_RAS_BLOCK__FUSE:
236 return TA_RAS_BLOCK__FUSE;
238 WARN_ONCE(1, "RAS ERROR: unexpected block id %d\n", block);
239 return TA_RAS_BLOCK__UMC;
243 static inline enum ta_ras_error_type
244 amdgpu_ras_error_to_ta(enum amdgpu_ras_error_type error) {
246 case AMDGPU_RAS_ERROR__NONE:
247 return TA_RAS_ERROR__NONE;
248 case AMDGPU_RAS_ERROR__PARITY:
249 return TA_RAS_ERROR__PARITY;
250 case AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE:
251 return TA_RAS_ERROR__SINGLE_CORRECTABLE;
252 case AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE:
253 return TA_RAS_ERROR__MULTI_UNCORRECTABLE;
254 case AMDGPU_RAS_ERROR__POISON:
255 return TA_RAS_ERROR__POISON;
257 WARN_ONCE(1, "RAS ERROR: unexpected error type %d\n", error);
258 return TA_RAS_ERROR__NONE;
262 /* called in ip_init and ip_fini */
263 int amdgpu_ras_init(struct amdgpu_device *adev);
264 int amdgpu_ras_fini(struct amdgpu_device *adev);
265 int amdgpu_ras_pre_fini(struct amdgpu_device *adev);
267 int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
268 struct ras_common_if *head, bool enable);
270 int amdgpu_ras_feature_enable_on_boot(struct amdgpu_device *adev,
271 struct ras_common_if *head, bool enable);
273 int amdgpu_ras_sysfs_create(struct amdgpu_device *adev,
274 struct ras_fs_if *head);
276 int amdgpu_ras_sysfs_remove(struct amdgpu_device *adev,
277 struct ras_common_if *head);
279 void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
280 struct ras_fs_if *head);
282 void amdgpu_ras_debugfs_remove(struct amdgpu_device *adev,
283 struct ras_common_if *head);
285 int amdgpu_ras_error_query(struct amdgpu_device *adev,
286 struct ras_query_if *info);
288 int amdgpu_ras_error_inject(struct amdgpu_device *adev,
289 struct ras_inject_if *info);
291 int amdgpu_ras_interrupt_add_handler(struct amdgpu_device *adev,
292 struct ras_ih_if *info);
294 int amdgpu_ras_interrupt_remove_handler(struct amdgpu_device *adev,
295 struct ras_ih_if *info);
297 int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev,
298 struct ras_dispatch_if *info);