]> Git Repo - linux.git/blob - drivers/gpu/drm/amd/amdgpu/amdgpu_ras.h
drm/amdgpu: add support for recording ras error address
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_ras.h
1 /*
2  * Copyright 2018 Advanced Micro Devices, Inc.
3  *
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:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
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.
21  *
22  *
23  */
24 #ifndef _AMDGPU_RAS_H
25 #define _AMDGPU_RAS_H
26
27 #include <linux/debugfs.h>
28 #include <linux/list.h>
29 #include "amdgpu.h"
30 #include "amdgpu_psp.h"
31 #include "ta_ras_if.h"
32
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,
42         AMDGPU_RAS_BLOCK__DF,
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,
48
49         AMDGPU_RAS_BLOCK__LAST
50 };
51
52 #define AMDGPU_RAS_BLOCK_COUNT  AMDGPU_RAS_BLOCK__LAST
53 #define AMDGPU_RAS_BLOCK_MASK   ((1ULL << AMDGPU_RAS_BLOCK_COUNT) - 1)
54
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,
61 };
62
63 enum amdgpu_ras_ret {
64         AMDGPU_RAS_SUCCESS = 0,
65         AMDGPU_RAS_FAIL,
66         AMDGPU_RAS_UE,
67         AMDGPU_RAS_CE,
68         AMDGPU_RAS_PT,
69 };
70
71 struct ras_common_if {
72         enum amdgpu_ras_block block;
73         enum amdgpu_ras_error_type type;
74         uint32_t sub_block_index;
75         /* block name */
76         char name[32];
77 };
78
79 typedef int (*ras_ih_cb)(struct amdgpu_device *adev,
80                 struct amdgpu_iv_entry *entry);
81
82 struct amdgpu_ras {
83         /* ras infrastructure */
84         /* for ras itself. */
85         uint32_t hw_supported;
86         /* for IP to check its ras ability. */
87         uint32_t supported;
88         uint32_t features;
89         struct list_head head;
90         /* debugfs */
91         struct dentry *dir;
92         /* debugfs ctrl */
93         struct dentry *ent;
94         /* sysfs */
95         struct device_attribute features_attr;
96         struct bin_attribute badpages_attr;
97         /* block array */
98         struct ras_manager *objs;
99
100         /* gpu recovery */
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;
107
108         uint32_t flags;
109 };
110
111 struct ras_ih_data {
112         /* interrupt bottom half */
113         struct work_struct ih_work;
114         int inuse;
115         /* IP callback */
116         ras_ih_cb cb;
117         /* full of entries */
118         unsigned char *ring;
119         unsigned int ring_size;
120         unsigned int element_size;
121         unsigned int aligned_element_size;
122         unsigned int rptr;
123         unsigned int wptr;
124 };
125
126 struct ras_fs_data {
127         char sysfs_name[32];
128         char debugfs_name[32];
129 };
130
131 struct ras_err_data {
132         unsigned long ue_count;
133         unsigned long ce_count;
134         unsigned long err_addr_cnt;
135         uint64_t *err_addr;
136 };
137
138 struct ras_err_handler_data {
139         /* point to bad pages array */
140         struct {
141                 unsigned long bp;
142                 struct amdgpu_bo *bo;
143         } *bps;
144         /* the count of entries */
145         int count;
146         /* the space can place new entries */
147         int space_left;
148         /* last reserved entry's index + 1 */
149         int last_reserved;
150 };
151
152 struct ras_manager {
153         struct ras_common_if head;
154         /* reference count */
155         int use;
156         /* ras block link */
157         struct list_head node;
158         /* the device */
159         struct amdgpu_device *adev;
160         /* debugfs */
161         struct dentry *ent;
162         /* sysfs */
163         struct device_attribute sysfs_attr;
164         int attr_inuse;
165
166         /* fs node name */
167         struct ras_fs_data fs_data;
168
169         /* IH data */
170         struct ras_ih_data ih_data;
171
172         struct ras_err_data err_data;
173 };
174
175 struct ras_badpage {
176         unsigned int bp;
177         unsigned int size;
178         unsigned int flags;
179 };
180
181 /* interfaces for IP */
182 struct ras_fs_if {
183         struct ras_common_if head;
184         char sysfs_name[32];
185         char debugfs_name[32];
186 };
187
188 struct ras_query_if {
189         struct ras_common_if head;
190         unsigned long ue_count;
191         unsigned long ce_count;
192 };
193
194 struct ras_inject_if {
195         struct ras_common_if head;
196         uint64_t address;
197         uint64_t value;
198 };
199
200 struct ras_cure_if {
201         struct ras_common_if head;
202         uint64_t address;
203 };
204
205 struct ras_ih_if {
206         struct ras_common_if head;
207         ras_ih_cb cb;
208 };
209
210 struct ras_dispatch_if {
211         struct ras_common_if head;
212         struct amdgpu_iv_entry *entry;
213 };
214
215 struct ras_debug_if {
216         union {
217                 struct ras_common_if head;
218                 struct ras_inject_if inject;
219         };
220         int op;
221 };
222 /* work flow
223  * vbios
224  * 1: ras feature enable (enabled by default)
225  * psp
226  * 2: ras framework init (in ip_init)
227  * IP
228  * 3: IH add
229  * 4: debugfs/sysfs create
230  * 5: query/inject
231  * 6: debugfs/sysfs remove
232  * 7: IH remove
233  * 8: feature disable
234  */
235
236 #define amdgpu_ras_get_context(adev)            ((adev)->psp.ras.ras)
237 #define amdgpu_ras_set_context(adev, ras_con)   ((adev)->psp.ras.ras = (ras_con))
238
239 /* check if ras is supported on block, say, sdma, gfx */
240 static inline int amdgpu_ras_is_supported(struct amdgpu_device *adev,
241                 unsigned int block)
242 {
243         struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
244
245         if (block >= AMDGPU_RAS_BLOCK_COUNT)
246                 return 0;
247         return ras && (ras->supported & (1 << block));
248 }
249
250 int amdgpu_ras_request_reset_on_boot(struct amdgpu_device *adev,
251                 unsigned int block);
252
253 void amdgpu_ras_resume(struct amdgpu_device *adev);
254 void amdgpu_ras_suspend(struct amdgpu_device *adev);
255
256 int amdgpu_ras_query_error_count(struct amdgpu_device *adev,
257                 bool is_ce);
258
259 /* error handling functions */
260 int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
261                 unsigned long *bps, int pages);
262
263 int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev);
264
265 static inline int amdgpu_ras_reset_gpu(struct amdgpu_device *adev,
266                 bool is_baco)
267 {
268         struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
269
270         if (atomic_cmpxchg(&ras->in_recovery, 0, 1) == 0)
271                 schedule_work(&ras->recovery_work);
272         return 0;
273 }
274
275 static inline enum ta_ras_block
276 amdgpu_ras_block_to_ta(enum amdgpu_ras_block block) {
277         switch (block) {
278         case AMDGPU_RAS_BLOCK__UMC:
279                 return TA_RAS_BLOCK__UMC;
280         case AMDGPU_RAS_BLOCK__SDMA:
281                 return TA_RAS_BLOCK__SDMA;
282         case AMDGPU_RAS_BLOCK__GFX:
283                 return TA_RAS_BLOCK__GFX;
284         case AMDGPU_RAS_BLOCK__MMHUB:
285                 return TA_RAS_BLOCK__MMHUB;
286         case AMDGPU_RAS_BLOCK__ATHUB:
287                 return TA_RAS_BLOCK__ATHUB;
288         case AMDGPU_RAS_BLOCK__PCIE_BIF:
289                 return TA_RAS_BLOCK__PCIE_BIF;
290         case AMDGPU_RAS_BLOCK__HDP:
291                 return TA_RAS_BLOCK__HDP;
292         case AMDGPU_RAS_BLOCK__XGMI_WAFL:
293                 return TA_RAS_BLOCK__XGMI_WAFL;
294         case AMDGPU_RAS_BLOCK__DF:
295                 return TA_RAS_BLOCK__DF;
296         case AMDGPU_RAS_BLOCK__SMN:
297                 return TA_RAS_BLOCK__SMN;
298         case AMDGPU_RAS_BLOCK__SEM:
299                 return TA_RAS_BLOCK__SEM;
300         case AMDGPU_RAS_BLOCK__MP0:
301                 return TA_RAS_BLOCK__MP0;
302         case AMDGPU_RAS_BLOCK__MP1:
303                 return TA_RAS_BLOCK__MP1;
304         case AMDGPU_RAS_BLOCK__FUSE:
305                 return TA_RAS_BLOCK__FUSE;
306         default:
307                 WARN_ONCE(1, "RAS ERROR: unexpected block id %d\n", block);
308                 return TA_RAS_BLOCK__UMC;
309         }
310 }
311
312 static inline enum ta_ras_error_type
313 amdgpu_ras_error_to_ta(enum amdgpu_ras_error_type error) {
314         switch (error) {
315         case AMDGPU_RAS_ERROR__NONE:
316                 return TA_RAS_ERROR__NONE;
317         case AMDGPU_RAS_ERROR__PARITY:
318                 return TA_RAS_ERROR__PARITY;
319         case AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE:
320                 return TA_RAS_ERROR__SINGLE_CORRECTABLE;
321         case AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE:
322                 return TA_RAS_ERROR__MULTI_UNCORRECTABLE;
323         case AMDGPU_RAS_ERROR__POISON:
324                 return TA_RAS_ERROR__POISON;
325         default:
326                 WARN_ONCE(1, "RAS ERROR: unexpected error type %d\n", error);
327                 return TA_RAS_ERROR__NONE;
328         }
329 }
330
331 /* called in ip_init and ip_fini */
332 int amdgpu_ras_init(struct amdgpu_device *adev);
333 int amdgpu_ras_fini(struct amdgpu_device *adev);
334 int amdgpu_ras_pre_fini(struct amdgpu_device *adev);
335
336 int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
337                 struct ras_common_if *head, bool enable);
338
339 int amdgpu_ras_feature_enable_on_boot(struct amdgpu_device *adev,
340                 struct ras_common_if *head, bool enable);
341
342 int amdgpu_ras_sysfs_create(struct amdgpu_device *adev,
343                 struct ras_fs_if *head);
344
345 int amdgpu_ras_sysfs_remove(struct amdgpu_device *adev,
346                 struct ras_common_if *head);
347
348 void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
349                 struct ras_fs_if *head);
350
351 void amdgpu_ras_debugfs_remove(struct amdgpu_device *adev,
352                 struct ras_common_if *head);
353
354 int amdgpu_ras_error_query(struct amdgpu_device *adev,
355                 struct ras_query_if *info);
356
357 int amdgpu_ras_error_inject(struct amdgpu_device *adev,
358                 struct ras_inject_if *info);
359
360 int amdgpu_ras_interrupt_add_handler(struct amdgpu_device *adev,
361                 struct ras_ih_if *info);
362
363 int amdgpu_ras_interrupt_remove_handler(struct amdgpu_device *adev,
364                 struct ras_ih_if *info);
365
366 int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev,
367                 struct ras_dispatch_if *info);
368 #endif
This page took 0.050602 seconds and 4 git commands to generate.