]> Git Repo - linux.git/blob - drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
Merge tag 'drm-intel-next-2020-04-30' of git://anongit.freedesktop.org/drm/drm-intel...
[linux.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_ras.c
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 #include <linux/debugfs.h>
25 #include <linux/list.h>
26 #include <linux/module.h>
27 #include <linux/uaccess.h>
28 #include <linux/reboot.h>
29 #include <linux/syscalls.h>
30
31 #include "amdgpu.h"
32 #include "amdgpu_ras.h"
33 #include "amdgpu_atomfirmware.h"
34 #include "amdgpu_xgmi.h"
35 #include "ivsrcid/nbio/irqsrcs_nbif_7_4.h"
36
37 const char *ras_error_string[] = {
38         "none",
39         "parity",
40         "single_correctable",
41         "multi_uncorrectable",
42         "poison",
43 };
44
45 const char *ras_block_string[] = {
46         "umc",
47         "sdma",
48         "gfx",
49         "mmhub",
50         "athub",
51         "pcie_bif",
52         "hdp",
53         "xgmi_wafl",
54         "df",
55         "smn",
56         "sem",
57         "mp0",
58         "mp1",
59         "fuse",
60 };
61
62 #define ras_err_str(i) (ras_error_string[ffs(i)])
63 #define ras_block_str(i) (ras_block_string[i])
64
65 #define AMDGPU_RAS_FLAG_INIT_BY_VBIOS           1
66 #define AMDGPU_RAS_FLAG_INIT_NEED_RESET         2
67 #define RAS_DEFAULT_FLAGS (AMDGPU_RAS_FLAG_INIT_BY_VBIOS)
68
69 /* inject address is 52 bits */
70 #define RAS_UMC_INJECT_ADDR_LIMIT       (0x1ULL << 52)
71
72 enum amdgpu_ras_retire_page_reservation {
73         AMDGPU_RAS_RETIRE_PAGE_RESERVED,
74         AMDGPU_RAS_RETIRE_PAGE_PENDING,
75         AMDGPU_RAS_RETIRE_PAGE_FAULT,
76 };
77
78 atomic_t amdgpu_ras_in_intr = ATOMIC_INIT(0);
79
80 static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
81                                 uint64_t addr);
82
83 void amdgpu_ras_set_error_query_ready(struct amdgpu_device *adev, bool ready)
84 {
85         if (adev && amdgpu_ras_get_context(adev))
86                 amdgpu_ras_get_context(adev)->error_query_ready = ready;
87 }
88
89 bool amdgpu_ras_get_error_query_ready(struct amdgpu_device *adev)
90 {
91         if (adev && amdgpu_ras_get_context(adev))
92                 return amdgpu_ras_get_context(adev)->error_query_ready;
93
94         return false;
95 }
96
97 static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,
98                                         size_t size, loff_t *pos)
99 {
100         struct ras_manager *obj = (struct ras_manager *)file_inode(f)->i_private;
101         struct ras_query_if info = {
102                 .head = obj->head,
103         };
104         ssize_t s;
105         char val[128];
106
107         if (amdgpu_ras_error_query(obj->adev, &info))
108                 return -EINVAL;
109
110         s = snprintf(val, sizeof(val), "%s: %lu\n%s: %lu\n",
111                         "ue", info.ue_count,
112                         "ce", info.ce_count);
113         if (*pos >= s)
114                 return 0;
115
116         s -= *pos;
117         s = min_t(u64, s, size);
118
119
120         if (copy_to_user(buf, &val[*pos], s))
121                 return -EINVAL;
122
123         *pos += s;
124
125         return s;
126 }
127
128 static const struct file_operations amdgpu_ras_debugfs_ops = {
129         .owner = THIS_MODULE,
130         .read = amdgpu_ras_debugfs_read,
131         .write = NULL,
132         .llseek = default_llseek
133 };
134
135 static int amdgpu_ras_find_block_id_by_name(const char *name, int *block_id)
136 {
137         int i;
138
139         for (i = 0; i < ARRAY_SIZE(ras_block_string); i++) {
140                 *block_id = i;
141                 if (strcmp(name, ras_block_str(i)) == 0)
142                         return 0;
143         }
144         return -EINVAL;
145 }
146
147 static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
148                 const char __user *buf, size_t size,
149                 loff_t *pos, struct ras_debug_if *data)
150 {
151         ssize_t s = min_t(u64, 64, size);
152         char str[65];
153         char block_name[33];
154         char err[9] = "ue";
155         int op = -1;
156         int block_id;
157         uint32_t sub_block;
158         u64 address, value;
159
160         if (*pos)
161                 return -EINVAL;
162         *pos = size;
163
164         memset(str, 0, sizeof(str));
165         memset(data, 0, sizeof(*data));
166
167         if (copy_from_user(str, buf, s))
168                 return -EINVAL;
169
170         if (sscanf(str, "disable %32s", block_name) == 1)
171                 op = 0;
172         else if (sscanf(str, "enable %32s %8s", block_name, err) == 2)
173                 op = 1;
174         else if (sscanf(str, "inject %32s %8s", block_name, err) == 2)
175                 op = 2;
176         else if (str[0] && str[1] && str[2] && str[3])
177                 /* ascii string, but commands are not matched. */
178                 return -EINVAL;
179
180         if (op != -1) {
181                 if (amdgpu_ras_find_block_id_by_name(block_name, &block_id))
182                         return -EINVAL;
183
184                 data->head.block = block_id;
185                 /* only ue and ce errors are supported */
186                 if (!memcmp("ue", err, 2))
187                         data->head.type = AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE;
188                 else if (!memcmp("ce", err, 2))
189                         data->head.type = AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE;
190                 else
191                         return -EINVAL;
192
193                 data->op = op;
194
195                 if (op == 2) {
196                         if (sscanf(str, "%*s %*s %*s %u %llu %llu",
197                                                 &sub_block, &address, &value) != 3)
198                                 if (sscanf(str, "%*s %*s %*s 0x%x 0x%llx 0x%llx",
199                                                         &sub_block, &address, &value) != 3)
200                                         return -EINVAL;
201                         data->head.sub_block_index = sub_block;
202                         data->inject.address = address;
203                         data->inject.value = value;
204                 }
205         } else {
206                 if (size < sizeof(*data))
207                         return -EINVAL;
208
209                 if (copy_from_user(data, buf, sizeof(*data)))
210                         return -EINVAL;
211         }
212
213         return 0;
214 }
215
216 /**
217  * DOC: AMDGPU RAS debugfs control interface
218  *
219  * It accepts struct ras_debug_if who has two members.
220  *
221  * First member: ras_debug_if::head or ras_debug_if::inject.
222  *
223  * head is used to indicate which IP block will be under control.
224  *
225  * head has four members, they are block, type, sub_block_index, name.
226  * block: which IP will be under control.
227  * type: what kind of error will be enabled/disabled/injected.
228  * sub_block_index: some IPs have subcomponets. say, GFX, sDMA.
229  * name: the name of IP.
230  *
231  * inject has two more members than head, they are address, value.
232  * As their names indicate, inject operation will write the
233  * value to the address.
234  *
235  * The second member: struct ras_debug_if::op.
236  * It has three kinds of operations.
237  *
238  * - 0: disable RAS on the block. Take ::head as its data.
239  * - 1: enable RAS on the block. Take ::head as its data.
240  * - 2: inject errors on the block. Take ::inject as its data.
241  *
242  * How to use the interface?
243  *
244  * Programs
245  *
246  * Copy the struct ras_debug_if in your codes and initialize it.
247  * Write the struct to the control node.
248  *
249  * Shells
250  *
251  * .. code-block:: bash
252  *
253  *      echo op block [error [sub_block address value]] > .../ras/ras_ctrl
254  *
255  * Parameters:
256  *
257  * op: disable, enable, inject
258  *      disable: only block is needed
259  *      enable: block and error are needed
260  *      inject: error, address, value are needed
261  * block: umc, sdma, gfx, .........
262  *      see ras_block_string[] for details
263  * error: ue, ce
264  *      ue: multi_uncorrectable
265  *      ce: single_correctable
266  * sub_block:
267  *      sub block index, pass 0 if there is no sub block
268  *
269  * here are some examples for bash commands:
270  *
271  * .. code-block:: bash
272  *
273  *      echo inject umc ue 0x0 0x0 0x0 > /sys/kernel/debug/dri/0/ras/ras_ctrl
274  *      echo inject umc ce 0 0 0 > /sys/kernel/debug/dri/0/ras/ras_ctrl
275  *      echo disable umc > /sys/kernel/debug/dri/0/ras/ras_ctrl
276  *
277  * How to check the result?
278  *
279  * For disable/enable, please check ras features at
280  * /sys/class/drm/card[0/1/2...]/device/ras/features
281  *
282  * For inject, please check corresponding err count at
283  * /sys/class/drm/card[0/1/2...]/device/ras/[gfx/sdma/...]_err_count
284  *
285  * .. note::
286  *      Operations are only allowed on blocks which are supported.
287  *      Please check ras mask at /sys/module/amdgpu/parameters/ras_mask
288  *      to see which blocks support RAS on a particular asic.
289  *
290  */
291 static ssize_t amdgpu_ras_debugfs_ctrl_write(struct file *f, const char __user *buf,
292                 size_t size, loff_t *pos)
293 {
294         struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
295         struct ras_debug_if data;
296         int ret = 0;
297
298         if (!amdgpu_ras_get_error_query_ready(adev)) {
299                 dev_warn(adev->dev, "RAS WARN: error injection "
300                                 "currently inaccessible\n");
301                 return size;
302         }
303
304         ret = amdgpu_ras_debugfs_ctrl_parse_data(f, buf, size, pos, &data);
305         if (ret)
306                 return -EINVAL;
307
308         if (!amdgpu_ras_is_supported(adev, data.head.block))
309                 return -EINVAL;
310
311         switch (data.op) {
312         case 0:
313                 ret = amdgpu_ras_feature_enable(adev, &data.head, 0);
314                 break;
315         case 1:
316                 ret = amdgpu_ras_feature_enable(adev, &data.head, 1);
317                 break;
318         case 2:
319                 if ((data.inject.address >= adev->gmc.mc_vram_size) ||
320                     (data.inject.address >= RAS_UMC_INJECT_ADDR_LIMIT)) {
321                         ret = -EINVAL;
322                         break;
323                 }
324
325                 /* umc ce/ue error injection for a bad page is not allowed */
326                 if ((data.head.block == AMDGPU_RAS_BLOCK__UMC) &&
327                     amdgpu_ras_check_bad_page(adev, data.inject.address)) {
328                         dev_warn(adev->dev, "RAS WARN: 0x%llx has been marked "
329                                         "as bad before error injection!\n",
330                                         data.inject.address);
331                         break;
332                 }
333
334                 /* data.inject.address is offset instead of absolute gpu address */
335                 ret = amdgpu_ras_error_inject(adev, &data.inject);
336                 break;
337         default:
338                 ret = -EINVAL;
339                 break;
340         }
341
342         if (ret)
343                 return -EINVAL;
344
345         return size;
346 }
347
348 /**
349  * DOC: AMDGPU RAS debugfs EEPROM table reset interface
350  *
351  * Some boards contain an EEPROM which is used to persistently store a list of
352  * bad pages which experiences ECC errors in vram.  This interface provides
353  * a way to reset the EEPROM, e.g., after testing error injection.
354  *
355  * Usage:
356  *
357  * .. code-block:: bash
358  *
359  *      echo 1 > ../ras/ras_eeprom_reset
360  *
361  * will reset EEPROM table to 0 entries.
362  *
363  */
364 static ssize_t amdgpu_ras_debugfs_eeprom_write(struct file *f, const char __user *buf,
365                 size_t size, loff_t *pos)
366 {
367         struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
368         int ret;
369
370         ret = amdgpu_ras_eeprom_reset_table(&adev->psp.ras.ras->eeprom_control);
371
372         return ret == 1 ? size : -EIO;
373 }
374
375 static const struct file_operations amdgpu_ras_debugfs_ctrl_ops = {
376         .owner = THIS_MODULE,
377         .read = NULL,
378         .write = amdgpu_ras_debugfs_ctrl_write,
379         .llseek = default_llseek
380 };
381
382 static const struct file_operations amdgpu_ras_debugfs_eeprom_ops = {
383         .owner = THIS_MODULE,
384         .read = NULL,
385         .write = amdgpu_ras_debugfs_eeprom_write,
386         .llseek = default_llseek
387 };
388
389 /**
390  * DOC: AMDGPU RAS sysfs Error Count Interface
391  *
392  * It allows the user to read the error count for each IP block on the gpu through
393  * /sys/class/drm/card[0/1/2...]/device/ras/[gfx/sdma/...]_err_count
394  *
395  * It outputs the multiple lines which report the uncorrected (ue) and corrected
396  * (ce) error counts.
397  *
398  * The format of one line is below,
399  *
400  * [ce|ue]: count
401  *
402  * Example:
403  *
404  * .. code-block:: bash
405  *
406  *      ue: 0
407  *      ce: 1
408  *
409  */
410 static ssize_t amdgpu_ras_sysfs_read(struct device *dev,
411                 struct device_attribute *attr, char *buf)
412 {
413         struct ras_manager *obj = container_of(attr, struct ras_manager, sysfs_attr);
414         struct ras_query_if info = {
415                 .head = obj->head,
416         };
417
418         if (!amdgpu_ras_get_error_query_ready(obj->adev))
419                 return snprintf(buf, PAGE_SIZE,
420                                 "Query currently inaccessible\n");
421
422         if (amdgpu_ras_error_query(obj->adev, &info))
423                 return -EINVAL;
424
425         return snprintf(buf, PAGE_SIZE, "%s: %lu\n%s: %lu\n",
426                         "ue", info.ue_count,
427                         "ce", info.ce_count);
428 }
429
430 /* obj begin */
431
432 #define get_obj(obj) do { (obj)->use++; } while (0)
433 #define alive_obj(obj) ((obj)->use)
434
435 static inline void put_obj(struct ras_manager *obj)
436 {
437         if (obj && --obj->use == 0)
438                 list_del(&obj->node);
439         if (obj && obj->use < 0) {
440                  DRM_ERROR("RAS ERROR: Unbalance obj(%s) use\n", obj->head.name);
441         }
442 }
443
444 /* make one obj and return it. */
445 static struct ras_manager *amdgpu_ras_create_obj(struct amdgpu_device *adev,
446                 struct ras_common_if *head)
447 {
448         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
449         struct ras_manager *obj;
450
451         if (!con)
452                 return NULL;
453
454         if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
455                 return NULL;
456
457         obj = &con->objs[head->block];
458         /* already exist. return obj? */
459         if (alive_obj(obj))
460                 return NULL;
461
462         obj->head = *head;
463         obj->adev = adev;
464         list_add(&obj->node, &con->head);
465         get_obj(obj);
466
467         return obj;
468 }
469
470 /* return an obj equal to head, or the first when head is NULL */
471 struct ras_manager *amdgpu_ras_find_obj(struct amdgpu_device *adev,
472                 struct ras_common_if *head)
473 {
474         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
475         struct ras_manager *obj;
476         int i;
477
478         if (!con)
479                 return NULL;
480
481         if (head) {
482                 if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
483                         return NULL;
484
485                 obj = &con->objs[head->block];
486
487                 if (alive_obj(obj)) {
488                         WARN_ON(head->block != obj->head.block);
489                         return obj;
490                 }
491         } else {
492                 for (i = 0; i < AMDGPU_RAS_BLOCK_COUNT; i++) {
493                         obj = &con->objs[i];
494                         if (alive_obj(obj)) {
495                                 WARN_ON(i != obj->head.block);
496                                 return obj;
497                         }
498                 }
499         }
500
501         return NULL;
502 }
503 /* obj end */
504
505 /* feature ctl begin */
506 static int amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
507                 struct ras_common_if *head)
508 {
509         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
510
511         return con->hw_supported & BIT(head->block);
512 }
513
514 static int amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
515                 struct ras_common_if *head)
516 {
517         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
518
519         return con->features & BIT(head->block);
520 }
521
522 /*
523  * if obj is not created, then create one.
524  * set feature enable flag.
525  */
526 static int __amdgpu_ras_feature_enable(struct amdgpu_device *adev,
527                 struct ras_common_if *head, int enable)
528 {
529         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
530         struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
531
532         /* If hardware does not support ras, then do not create obj.
533          * But if hardware support ras, we can create the obj.
534          * Ras framework checks con->hw_supported to see if it need do
535          * corresponding initialization.
536          * IP checks con->support to see if it need disable ras.
537          */
538         if (!amdgpu_ras_is_feature_allowed(adev, head))
539                 return 0;
540         if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
541                 return 0;
542
543         if (enable) {
544                 if (!obj) {
545                         obj = amdgpu_ras_create_obj(adev, head);
546                         if (!obj)
547                                 return -EINVAL;
548                 } else {
549                         /* In case we create obj somewhere else */
550                         get_obj(obj);
551                 }
552                 con->features |= BIT(head->block);
553         } else {
554                 if (obj && amdgpu_ras_is_feature_enabled(adev, head)) {
555                         con->features &= ~BIT(head->block);
556                         put_obj(obj);
557                 }
558         }
559
560         return 0;
561 }
562
563 /* wrapper of psp_ras_enable_features */
564 int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
565                 struct ras_common_if *head, bool enable)
566 {
567         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
568         union ta_ras_cmd_input info;
569         int ret;
570
571         if (!con)
572                 return -EINVAL;
573
574         if (!enable) {
575                 info.disable_features = (struct ta_ras_disable_features_input) {
576                         .block_id =  amdgpu_ras_block_to_ta(head->block),
577                         .error_type = amdgpu_ras_error_to_ta(head->type),
578                 };
579         } else {
580                 info.enable_features = (struct ta_ras_enable_features_input) {
581                         .block_id =  amdgpu_ras_block_to_ta(head->block),
582                         .error_type = amdgpu_ras_error_to_ta(head->type),
583                 };
584         }
585
586         /* Do not enable if it is not allowed. */
587         WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
588         /* Are we alerady in that state we are going to set? */
589         if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
590                 return 0;
591
592         if (!amdgpu_ras_intr_triggered()) {
593                 ret = psp_ras_enable_features(&adev->psp, &info, enable);
594                 if (ret) {
595                         dev_err(adev->dev, "RAS ERROR: %s %s feature "
596                                         "failed ret %d\n",
597                                         enable ? "enable":"disable",
598                                         ras_block_str(head->block),
599                                         ret);
600                         if (ret == TA_RAS_STATUS__RESET_NEEDED)
601                                 return -EAGAIN;
602                         return -EINVAL;
603                 }
604         }
605
606         /* setup the obj */
607         __amdgpu_ras_feature_enable(adev, head, enable);
608
609         return 0;
610 }
611
612 /* Only used in device probe stage and called only once. */
613 int amdgpu_ras_feature_enable_on_boot(struct amdgpu_device *adev,
614                 struct ras_common_if *head, bool enable)
615 {
616         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
617         int ret;
618
619         if (!con)
620                 return -EINVAL;
621
622         if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
623                 if (enable) {
624                         /* There is no harm to issue a ras TA cmd regardless of
625                          * the currecnt ras state.
626                          * If current state == target state, it will do nothing
627                          * But sometimes it requests driver to reset and repost
628                          * with error code -EAGAIN.
629                          */
630                         ret = amdgpu_ras_feature_enable(adev, head, 1);
631                         /* With old ras TA, we might fail to enable ras.
632                          * Log it and just setup the object.
633                          * TODO need remove this WA in the future.
634                          */
635                         if (ret == -EINVAL) {
636                                 ret = __amdgpu_ras_feature_enable(adev, head, 1);
637                                 if (!ret)
638                                         dev_info(adev->dev,
639                                                 "RAS INFO: %s setup object\n",
640                                                 ras_block_str(head->block));
641                         }
642                 } else {
643                         /* setup the object then issue a ras TA disable cmd.*/
644                         ret = __amdgpu_ras_feature_enable(adev, head, 1);
645                         if (ret)
646                                 return ret;
647
648                         ret = amdgpu_ras_feature_enable(adev, head, 0);
649                 }
650         } else
651                 ret = amdgpu_ras_feature_enable(adev, head, enable);
652
653         return ret;
654 }
655
656 static int amdgpu_ras_disable_all_features(struct amdgpu_device *adev,
657                 bool bypass)
658 {
659         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
660         struct ras_manager *obj, *tmp;
661
662         list_for_each_entry_safe(obj, tmp, &con->head, node) {
663                 /* bypass psp.
664                  * aka just release the obj and corresponding flags
665                  */
666                 if (bypass) {
667                         if (__amdgpu_ras_feature_enable(adev, &obj->head, 0))
668                                 break;
669                 } else {
670                         if (amdgpu_ras_feature_enable(adev, &obj->head, 0))
671                                 break;
672                 }
673         }
674
675         return con->features;
676 }
677
678 static int amdgpu_ras_enable_all_features(struct amdgpu_device *adev,
679                 bool bypass)
680 {
681         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
682         int ras_block_count = AMDGPU_RAS_BLOCK_COUNT;
683         int i;
684         const enum amdgpu_ras_error_type default_ras_type =
685                 AMDGPU_RAS_ERROR__NONE;
686
687         for (i = 0; i < ras_block_count; i++) {
688                 struct ras_common_if head = {
689                         .block = i,
690                         .type = default_ras_type,
691                         .sub_block_index = 0,
692                 };
693                 strcpy(head.name, ras_block_str(i));
694                 if (bypass) {
695                         /*
696                          * bypass psp. vbios enable ras for us.
697                          * so just create the obj
698                          */
699                         if (__amdgpu_ras_feature_enable(adev, &head, 1))
700                                 break;
701                 } else {
702                         if (amdgpu_ras_feature_enable(adev, &head, 1))
703                                 break;
704                 }
705         }
706
707         return con->features;
708 }
709 /* feature ctl end */
710
711 /* query/inject/cure begin */
712 int amdgpu_ras_error_query(struct amdgpu_device *adev,
713                 struct ras_query_if *info)
714 {
715         struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
716         struct ras_err_data err_data = {0, 0, 0, NULL};
717         int i;
718
719         if (!obj)
720                 return -EINVAL;
721
722         switch (info->head.block) {
723         case AMDGPU_RAS_BLOCK__UMC:
724                 if (adev->umc.funcs->query_ras_error_count)
725                         adev->umc.funcs->query_ras_error_count(adev, &err_data);
726                 /* umc query_ras_error_address is also responsible for clearing
727                  * error status
728                  */
729                 if (adev->umc.funcs->query_ras_error_address)
730                         adev->umc.funcs->query_ras_error_address(adev, &err_data);
731                 break;
732         case AMDGPU_RAS_BLOCK__SDMA:
733                 if (adev->sdma.funcs->query_ras_error_count) {
734                         for (i = 0; i < adev->sdma.num_instances; i++)
735                                 adev->sdma.funcs->query_ras_error_count(adev, i,
736                                                                         &err_data);
737                 }
738                 break;
739         case AMDGPU_RAS_BLOCK__GFX:
740                 if (adev->gfx.funcs->query_ras_error_count)
741                         adev->gfx.funcs->query_ras_error_count(adev, &err_data);
742                 break;
743         case AMDGPU_RAS_BLOCK__MMHUB:
744                 if (adev->mmhub.funcs->query_ras_error_count)
745                         adev->mmhub.funcs->query_ras_error_count(adev, &err_data);
746                 break;
747         case AMDGPU_RAS_BLOCK__PCIE_BIF:
748                 if (adev->nbio.funcs->query_ras_error_count)
749                         adev->nbio.funcs->query_ras_error_count(adev, &err_data);
750                 break;
751         case AMDGPU_RAS_BLOCK__XGMI_WAFL:
752                 amdgpu_xgmi_query_ras_error_count(adev, &err_data);
753                 break;
754         default:
755                 break;
756         }
757
758         obj->err_data.ue_count += err_data.ue_count;
759         obj->err_data.ce_count += err_data.ce_count;
760
761         info->ue_count = obj->err_data.ue_count;
762         info->ce_count = obj->err_data.ce_count;
763
764         if (err_data.ce_count) {
765                 dev_info(adev->dev, "%ld correctable hardware errors "
766                                         "detected in %s block, no user "
767                                         "action is needed.\n",
768                                         obj->err_data.ce_count,
769                                         ras_block_str(info->head.block));
770         }
771         if (err_data.ue_count) {
772                 dev_info(adev->dev, "%ld uncorrectable hardware errors "
773                                         "detected in %s block\n",
774                                         obj->err_data.ue_count,
775                                         ras_block_str(info->head.block));
776         }
777
778         return 0;
779 }
780
781 /* wrapper of psp_ras_trigger_error */
782 int amdgpu_ras_error_inject(struct amdgpu_device *adev,
783                 struct ras_inject_if *info)
784 {
785         struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
786         struct ta_ras_trigger_error_input block_info = {
787                 .block_id =  amdgpu_ras_block_to_ta(info->head.block),
788                 .inject_error_type = amdgpu_ras_error_to_ta(info->head.type),
789                 .sub_block_index = info->head.sub_block_index,
790                 .address = info->address,
791                 .value = info->value,
792         };
793         int ret = 0;
794
795         if (!obj)
796                 return -EINVAL;
797
798         /* Calculate XGMI relative offset */
799         if (adev->gmc.xgmi.num_physical_nodes > 1) {
800                 block_info.address =
801                         amdgpu_xgmi_get_relative_phy_addr(adev,
802                                                           block_info.address);
803         }
804
805         switch (info->head.block) {
806         case AMDGPU_RAS_BLOCK__GFX:
807                 if (adev->gfx.funcs->ras_error_inject)
808                         ret = adev->gfx.funcs->ras_error_inject(adev, info);
809                 else
810                         ret = -EINVAL;
811                 break;
812         case AMDGPU_RAS_BLOCK__UMC:
813         case AMDGPU_RAS_BLOCK__MMHUB:
814         case AMDGPU_RAS_BLOCK__XGMI_WAFL:
815         case AMDGPU_RAS_BLOCK__PCIE_BIF:
816                 ret = psp_ras_trigger_error(&adev->psp, &block_info);
817                 break;
818         default:
819                 dev_info(adev->dev, "%s error injection is not supported yet\n",
820                          ras_block_str(info->head.block));
821                 ret = -EINVAL;
822         }
823
824         if (ret)
825                 dev_err(adev->dev, "RAS ERROR: inject %s error failed ret %d\n",
826                                 ras_block_str(info->head.block),
827                                 ret);
828
829         return ret;
830 }
831
832 int amdgpu_ras_error_cure(struct amdgpu_device *adev,
833                 struct ras_cure_if *info)
834 {
835         /* psp fw has no cure interface for now. */
836         return 0;
837 }
838
839 /* get the total error counts on all IPs */
840 unsigned long amdgpu_ras_query_error_count(struct amdgpu_device *adev,
841                 bool is_ce)
842 {
843         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
844         struct ras_manager *obj;
845         struct ras_err_data data = {0, 0};
846
847         if (!con)
848                 return 0;
849
850         list_for_each_entry(obj, &con->head, node) {
851                 struct ras_query_if info = {
852                         .head = obj->head,
853                 };
854
855                 if (amdgpu_ras_error_query(adev, &info))
856                         return 0;
857
858                 data.ce_count += info.ce_count;
859                 data.ue_count += info.ue_count;
860         }
861
862         return is_ce ? data.ce_count : data.ue_count;
863 }
864 /* query/inject/cure end */
865
866
867 /* sysfs begin */
868
869 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
870                 struct ras_badpage **bps, unsigned int *count);
871
872 static char *amdgpu_ras_badpage_flags_str(unsigned int flags)
873 {
874         switch (flags) {
875         case AMDGPU_RAS_RETIRE_PAGE_RESERVED:
876                 return "R";
877         case AMDGPU_RAS_RETIRE_PAGE_PENDING:
878                 return "P";
879         case AMDGPU_RAS_RETIRE_PAGE_FAULT:
880         default:
881                 return "F";
882         };
883 }
884
885 /**
886  * DOC: AMDGPU RAS sysfs gpu_vram_bad_pages Interface
887  *
888  * It allows user to read the bad pages of vram on the gpu through
889  * /sys/class/drm/card[0/1/2...]/device/ras/gpu_vram_bad_pages
890  *
891  * It outputs multiple lines, and each line stands for one gpu page.
892  *
893  * The format of one line is below,
894  * gpu pfn : gpu page size : flags
895  *
896  * gpu pfn and gpu page size are printed in hex format.
897  * flags can be one of below character,
898  *
899  * R: reserved, this gpu page is reserved and not able to use.
900  *
901  * P: pending for reserve, this gpu page is marked as bad, will be reserved
902  * in next window of page_reserve.
903  *
904  * F: unable to reserve. this gpu page can't be reserved due to some reasons.
905  *
906  * Examples:
907  *
908  * .. code-block:: bash
909  *
910  *      0x00000001 : 0x00001000 : R
911  *      0x00000002 : 0x00001000 : P
912  *
913  */
914
915 static ssize_t amdgpu_ras_sysfs_badpages_read(struct file *f,
916                 struct kobject *kobj, struct bin_attribute *attr,
917                 char *buf, loff_t ppos, size_t count)
918 {
919         struct amdgpu_ras *con =
920                 container_of(attr, struct amdgpu_ras, badpages_attr);
921         struct amdgpu_device *adev = con->adev;
922         const unsigned int element_size =
923                 sizeof("0xabcdabcd : 0x12345678 : R\n") - 1;
924         unsigned int start = div64_ul(ppos + element_size - 1, element_size);
925         unsigned int end = div64_ul(ppos + count - 1, element_size);
926         ssize_t s = 0;
927         struct ras_badpage *bps = NULL;
928         unsigned int bps_count = 0;
929
930         memset(buf, 0, count);
931
932         if (amdgpu_ras_badpages_read(adev, &bps, &bps_count))
933                 return 0;
934
935         for (; start < end && start < bps_count; start++)
936                 s += scnprintf(&buf[s], element_size + 1,
937                                 "0x%08x : 0x%08x : %1s\n",
938                                 bps[start].bp,
939                                 bps[start].size,
940                                 amdgpu_ras_badpage_flags_str(bps[start].flags));
941
942         kfree(bps);
943
944         return s;
945 }
946
947 static ssize_t amdgpu_ras_sysfs_features_read(struct device *dev,
948                 struct device_attribute *attr, char *buf)
949 {
950         struct amdgpu_ras *con =
951                 container_of(attr, struct amdgpu_ras, features_attr);
952
953         return scnprintf(buf, PAGE_SIZE, "feature mask: 0x%x\n", con->features);
954 }
955
956 static int amdgpu_ras_sysfs_create_feature_node(struct amdgpu_device *adev)
957 {
958         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
959         struct attribute *attrs[] = {
960                 &con->features_attr.attr,
961                 NULL
962         };
963         struct bin_attribute *bin_attrs[] = {
964                 &con->badpages_attr,
965                 NULL
966         };
967         struct attribute_group group = {
968                 .name = "ras",
969                 .attrs = attrs,
970                 .bin_attrs = bin_attrs,
971         };
972
973         con->features_attr = (struct device_attribute) {
974                 .attr = {
975                         .name = "features",
976                         .mode = S_IRUGO,
977                 },
978                         .show = amdgpu_ras_sysfs_features_read,
979         };
980
981         con->badpages_attr = (struct bin_attribute) {
982                 .attr = {
983                         .name = "gpu_vram_bad_pages",
984                         .mode = S_IRUGO,
985                 },
986                 .size = 0,
987                 .private = NULL,
988                 .read = amdgpu_ras_sysfs_badpages_read,
989         };
990
991         sysfs_attr_init(attrs[0]);
992         sysfs_bin_attr_init(bin_attrs[0]);
993
994         return sysfs_create_group(&adev->dev->kobj, &group);
995 }
996
997 static int amdgpu_ras_sysfs_remove_feature_node(struct amdgpu_device *adev)
998 {
999         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1000         struct attribute *attrs[] = {
1001                 &con->features_attr.attr,
1002                 NULL
1003         };
1004         struct bin_attribute *bin_attrs[] = {
1005                 &con->badpages_attr,
1006                 NULL
1007         };
1008         struct attribute_group group = {
1009                 .name = "ras",
1010                 .attrs = attrs,
1011                 .bin_attrs = bin_attrs,
1012         };
1013
1014         sysfs_remove_group(&adev->dev->kobj, &group);
1015
1016         return 0;
1017 }
1018
1019 int amdgpu_ras_sysfs_create(struct amdgpu_device *adev,
1020                 struct ras_fs_if *head)
1021 {
1022         struct ras_manager *obj = amdgpu_ras_find_obj(adev, &head->head);
1023
1024         if (!obj || obj->attr_inuse)
1025                 return -EINVAL;
1026
1027         get_obj(obj);
1028
1029         memcpy(obj->fs_data.sysfs_name,
1030                         head->sysfs_name,
1031                         sizeof(obj->fs_data.sysfs_name));
1032
1033         obj->sysfs_attr = (struct device_attribute){
1034                 .attr = {
1035                         .name = obj->fs_data.sysfs_name,
1036                         .mode = S_IRUGO,
1037                 },
1038                         .show = amdgpu_ras_sysfs_read,
1039         };
1040         sysfs_attr_init(&obj->sysfs_attr.attr);
1041
1042         if (sysfs_add_file_to_group(&adev->dev->kobj,
1043                                 &obj->sysfs_attr.attr,
1044                                 "ras")) {
1045                 put_obj(obj);
1046                 return -EINVAL;
1047         }
1048
1049         obj->attr_inuse = 1;
1050
1051         return 0;
1052 }
1053
1054 int amdgpu_ras_sysfs_remove(struct amdgpu_device *adev,
1055                 struct ras_common_if *head)
1056 {
1057         struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1058
1059         if (!obj || !obj->attr_inuse)
1060                 return -EINVAL;
1061
1062         sysfs_remove_file_from_group(&adev->dev->kobj,
1063                                 &obj->sysfs_attr.attr,
1064                                 "ras");
1065         obj->attr_inuse = 0;
1066         put_obj(obj);
1067
1068         return 0;
1069 }
1070
1071 static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
1072 {
1073         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1074         struct ras_manager *obj, *tmp;
1075
1076         list_for_each_entry_safe(obj, tmp, &con->head, node) {
1077                 amdgpu_ras_sysfs_remove(adev, &obj->head);
1078         }
1079
1080         amdgpu_ras_sysfs_remove_feature_node(adev);
1081
1082         return 0;
1083 }
1084 /* sysfs end */
1085
1086 /**
1087  * DOC: AMDGPU RAS Reboot Behavior for Unrecoverable Errors
1088  *
1089  * Normally when there is an uncorrectable error, the driver will reset
1090  * the GPU to recover.  However, in the event of an unrecoverable error,
1091  * the driver provides an interface to reboot the system automatically
1092  * in that event.
1093  *
1094  * The following file in debugfs provides that interface:
1095  * /sys/kernel/debug/dri/[0/1/2...]/ras/auto_reboot
1096  *
1097  * Usage:
1098  *
1099  * .. code-block:: bash
1100  *
1101  *      echo true > .../ras/auto_reboot
1102  *
1103  */
1104 /* debugfs begin */
1105 static void amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *adev)
1106 {
1107         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1108         struct drm_minor *minor = adev->ddev->primary;
1109
1110         con->dir = debugfs_create_dir("ras", minor->debugfs_root);
1111         debugfs_create_file("ras_ctrl", S_IWUGO | S_IRUGO, con->dir,
1112                                 adev, &amdgpu_ras_debugfs_ctrl_ops);
1113         debugfs_create_file("ras_eeprom_reset", S_IWUGO | S_IRUGO, con->dir,
1114                                 adev, &amdgpu_ras_debugfs_eeprom_ops);
1115
1116         /*
1117          * After one uncorrectable error happens, usually GPU recovery will
1118          * be scheduled. But due to the known problem in GPU recovery failing
1119          * to bring GPU back, below interface provides one direct way to
1120          * user to reboot system automatically in such case within
1121          * ERREVENT_ATHUB_INTERRUPT generated. Normal GPU recovery routine
1122          * will never be called.
1123          */
1124         debugfs_create_bool("auto_reboot", S_IWUGO | S_IRUGO, con->dir,
1125                                 &con->reboot);
1126 }
1127
1128 void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
1129                 struct ras_fs_if *head)
1130 {
1131         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1132         struct ras_manager *obj = amdgpu_ras_find_obj(adev, &head->head);
1133
1134         if (!obj || obj->ent)
1135                 return;
1136
1137         get_obj(obj);
1138
1139         memcpy(obj->fs_data.debugfs_name,
1140                         head->debugfs_name,
1141                         sizeof(obj->fs_data.debugfs_name));
1142
1143         obj->ent = debugfs_create_file(obj->fs_data.debugfs_name,
1144                                        S_IWUGO | S_IRUGO, con->dir, obj,
1145                                        &amdgpu_ras_debugfs_ops);
1146 }
1147
1148 void amdgpu_ras_debugfs_create_all(struct amdgpu_device *adev)
1149 {
1150         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1151         struct ras_manager *obj;
1152         struct ras_fs_if fs_info;
1153
1154         /*
1155          * it won't be called in resume path, no need to check
1156          * suspend and gpu reset status
1157          */
1158         if (!con)
1159                 return;
1160
1161         amdgpu_ras_debugfs_create_ctrl_node(adev);
1162
1163         list_for_each_entry(obj, &con->head, node) {
1164                 if (amdgpu_ras_is_supported(adev, obj->head.block) &&
1165                         (obj->attr_inuse == 1)) {
1166                         sprintf(fs_info.debugfs_name, "%s_err_inject",
1167                                         ras_block_str(obj->head.block));
1168                         fs_info.head = obj->head;
1169                         amdgpu_ras_debugfs_create(adev, &fs_info);
1170                 }
1171         }
1172 }
1173
1174 void amdgpu_ras_debugfs_remove(struct amdgpu_device *adev,
1175                 struct ras_common_if *head)
1176 {
1177         struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1178
1179         if (!obj || !obj->ent)
1180                 return;
1181
1182         debugfs_remove(obj->ent);
1183         obj->ent = NULL;
1184         put_obj(obj);
1185 }
1186
1187 static void amdgpu_ras_debugfs_remove_all(struct amdgpu_device *adev)
1188 {
1189         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1190         struct ras_manager *obj, *tmp;
1191
1192         list_for_each_entry_safe(obj, tmp, &con->head, node) {
1193                 amdgpu_ras_debugfs_remove(adev, &obj->head);
1194         }
1195
1196         debugfs_remove_recursive(con->dir);
1197         con->dir = NULL;
1198 }
1199 /* debugfs end */
1200
1201 /* ras fs */
1202
1203 static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
1204 {
1205         amdgpu_ras_sysfs_create_feature_node(adev);
1206
1207         return 0;
1208 }
1209
1210 static int amdgpu_ras_fs_fini(struct amdgpu_device *adev)
1211 {
1212         amdgpu_ras_debugfs_remove_all(adev);
1213         amdgpu_ras_sysfs_remove_all(adev);
1214         return 0;
1215 }
1216 /* ras fs end */
1217
1218 /* ih begin */
1219 static void amdgpu_ras_interrupt_handler(struct ras_manager *obj)
1220 {
1221         struct ras_ih_data *data = &obj->ih_data;
1222         struct amdgpu_iv_entry entry;
1223         int ret;
1224         struct ras_err_data err_data = {0, 0, 0, NULL};
1225
1226         while (data->rptr != data->wptr) {
1227                 rmb();
1228                 memcpy(&entry, &data->ring[data->rptr],
1229                                 data->element_size);
1230
1231                 wmb();
1232                 data->rptr = (data->aligned_element_size +
1233                                 data->rptr) % data->ring_size;
1234
1235                 /* Let IP handle its data, maybe we need get the output
1236                  * from the callback to udpate the error type/count, etc
1237                  */
1238                 if (data->cb) {
1239                         ret = data->cb(obj->adev, &err_data, &entry);
1240                         /* ue will trigger an interrupt, and in that case
1241                          * we need do a reset to recovery the whole system.
1242                          * But leave IP do that recovery, here we just dispatch
1243                          * the error.
1244                          */
1245                         if (ret == AMDGPU_RAS_SUCCESS) {
1246                                 /* these counts could be left as 0 if
1247                                  * some blocks do not count error number
1248                                  */
1249                                 obj->err_data.ue_count += err_data.ue_count;
1250                                 obj->err_data.ce_count += err_data.ce_count;
1251                         }
1252                 }
1253         }
1254 }
1255
1256 static void amdgpu_ras_interrupt_process_handler(struct work_struct *work)
1257 {
1258         struct ras_ih_data *data =
1259                 container_of(work, struct ras_ih_data, ih_work);
1260         struct ras_manager *obj =
1261                 container_of(data, struct ras_manager, ih_data);
1262
1263         amdgpu_ras_interrupt_handler(obj);
1264 }
1265
1266 int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev,
1267                 struct ras_dispatch_if *info)
1268 {
1269         struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1270         struct ras_ih_data *data = &obj->ih_data;
1271
1272         if (!obj)
1273                 return -EINVAL;
1274
1275         if (data->inuse == 0)
1276                 return 0;
1277
1278         /* Might be overflow... */
1279         memcpy(&data->ring[data->wptr], info->entry,
1280                         data->element_size);
1281
1282         wmb();
1283         data->wptr = (data->aligned_element_size +
1284                         data->wptr) % data->ring_size;
1285
1286         schedule_work(&data->ih_work);
1287
1288         return 0;
1289 }
1290
1291 int amdgpu_ras_interrupt_remove_handler(struct amdgpu_device *adev,
1292                 struct ras_ih_if *info)
1293 {
1294         struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1295         struct ras_ih_data *data;
1296
1297         if (!obj)
1298                 return -EINVAL;
1299
1300         data = &obj->ih_data;
1301         if (data->inuse == 0)
1302                 return 0;
1303
1304         cancel_work_sync(&data->ih_work);
1305
1306         kfree(data->ring);
1307         memset(data, 0, sizeof(*data));
1308         put_obj(obj);
1309
1310         return 0;
1311 }
1312
1313 int amdgpu_ras_interrupt_add_handler(struct amdgpu_device *adev,
1314                 struct ras_ih_if *info)
1315 {
1316         struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1317         struct ras_ih_data *data;
1318
1319         if (!obj) {
1320                 /* in case we registe the IH before enable ras feature */
1321                 obj = amdgpu_ras_create_obj(adev, &info->head);
1322                 if (!obj)
1323                         return -EINVAL;
1324         } else
1325                 get_obj(obj);
1326
1327         data = &obj->ih_data;
1328         /* add the callback.etc */
1329         *data = (struct ras_ih_data) {
1330                 .inuse = 0,
1331                 .cb = info->cb,
1332                 .element_size = sizeof(struct amdgpu_iv_entry),
1333                 .rptr = 0,
1334                 .wptr = 0,
1335         };
1336
1337         INIT_WORK(&data->ih_work, amdgpu_ras_interrupt_process_handler);
1338
1339         data->aligned_element_size = ALIGN(data->element_size, 8);
1340         /* the ring can store 64 iv entries. */
1341         data->ring_size = 64 * data->aligned_element_size;
1342         data->ring = kmalloc(data->ring_size, GFP_KERNEL);
1343         if (!data->ring) {
1344                 put_obj(obj);
1345                 return -ENOMEM;
1346         }
1347
1348         /* IH is ready */
1349         data->inuse = 1;
1350
1351         return 0;
1352 }
1353
1354 static int amdgpu_ras_interrupt_remove_all(struct amdgpu_device *adev)
1355 {
1356         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1357         struct ras_manager *obj, *tmp;
1358
1359         list_for_each_entry_safe(obj, tmp, &con->head, node) {
1360                 struct ras_ih_if info = {
1361                         .head = obj->head,
1362                 };
1363                 amdgpu_ras_interrupt_remove_handler(adev, &info);
1364         }
1365
1366         return 0;
1367 }
1368 /* ih end */
1369
1370 /* traversal all IPs except NBIO to query error counter */
1371 static void amdgpu_ras_log_on_err_counter(struct amdgpu_device *adev)
1372 {
1373         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1374         struct ras_manager *obj;
1375
1376         if (!con)
1377                 return;
1378
1379         list_for_each_entry(obj, &con->head, node) {
1380                 struct ras_query_if info = {
1381                         .head = obj->head,
1382                 };
1383
1384                 /*
1385                  * PCIE_BIF IP has one different isr by ras controller
1386                  * interrupt, the specific ras counter query will be
1387                  * done in that isr. So skip such block from common
1388                  * sync flood interrupt isr calling.
1389                  */
1390                 if (info.head.block == AMDGPU_RAS_BLOCK__PCIE_BIF)
1391                         continue;
1392
1393                 amdgpu_ras_error_query(adev, &info);
1394         }
1395 }
1396
1397 /* recovery begin */
1398
1399 /* return 0 on success.
1400  * caller need free bps.
1401  */
1402 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
1403                 struct ras_badpage **bps, unsigned int *count)
1404 {
1405         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1406         struct ras_err_handler_data *data;
1407         int i = 0;
1408         int ret = 0;
1409
1410         if (!con || !con->eh_data || !bps || !count)
1411                 return -EINVAL;
1412
1413         mutex_lock(&con->recovery_lock);
1414         data = con->eh_data;
1415         if (!data || data->count == 0) {
1416                 *bps = NULL;
1417                 ret = -EINVAL;
1418                 goto out;
1419         }
1420
1421         *bps = kmalloc(sizeof(struct ras_badpage) * data->count, GFP_KERNEL);
1422         if (!*bps) {
1423                 ret = -ENOMEM;
1424                 goto out;
1425         }
1426
1427         for (; i < data->count; i++) {
1428                 (*bps)[i] = (struct ras_badpage){
1429                         .bp = data->bps[i].retired_page,
1430                         .size = AMDGPU_GPU_PAGE_SIZE,
1431                         .flags = AMDGPU_RAS_RETIRE_PAGE_RESERVED,
1432                 };
1433
1434                 if (data->last_reserved <= i)
1435                         (*bps)[i].flags = AMDGPU_RAS_RETIRE_PAGE_PENDING;
1436                 else if (data->bps_bo[i] == NULL)
1437                         (*bps)[i].flags = AMDGPU_RAS_RETIRE_PAGE_FAULT;
1438         }
1439
1440         *count = data->count;
1441 out:
1442         mutex_unlock(&con->recovery_lock);
1443         return ret;
1444 }
1445
1446 static void amdgpu_ras_do_recovery(struct work_struct *work)
1447 {
1448         struct amdgpu_ras *ras =
1449                 container_of(work, struct amdgpu_ras, recovery_work);
1450         struct amdgpu_device *remote_adev = NULL;
1451         struct amdgpu_device *adev = ras->adev;
1452         struct list_head device_list, *device_list_handle =  NULL;
1453         struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev, false);
1454
1455         /* Build list of devices to query RAS related errors */
1456         if  (hive && adev->gmc.xgmi.num_physical_nodes > 1)
1457                 device_list_handle = &hive->device_list;
1458         else {
1459                 INIT_LIST_HEAD(&device_list);
1460                 list_add_tail(&adev->gmc.xgmi.head, &device_list);
1461                 device_list_handle = &device_list;
1462         }
1463
1464         list_for_each_entry(remote_adev, device_list_handle, gmc.xgmi.head) {
1465                 amdgpu_ras_log_on_err_counter(remote_adev);
1466         }
1467
1468         if (amdgpu_device_should_recover_gpu(ras->adev))
1469                 amdgpu_device_gpu_recover(ras->adev, 0);
1470         atomic_set(&ras->in_recovery, 0);
1471 }
1472
1473 /* alloc/realloc bps array */
1474 static int amdgpu_ras_realloc_eh_data_space(struct amdgpu_device *adev,
1475                 struct ras_err_handler_data *data, int pages)
1476 {
1477         unsigned int old_space = data->count + data->space_left;
1478         unsigned int new_space = old_space + pages;
1479         unsigned int align_space = ALIGN(new_space, 512);
1480         void *bps = kmalloc(align_space * sizeof(*data->bps), GFP_KERNEL);
1481         struct amdgpu_bo **bps_bo =
1482                         kmalloc(align_space * sizeof(*data->bps_bo), GFP_KERNEL);
1483
1484         if (!bps || !bps_bo) {
1485                 kfree(bps);
1486                 kfree(bps_bo);
1487                 return -ENOMEM;
1488         }
1489
1490         if (data->bps) {
1491                 memcpy(bps, data->bps,
1492                                 data->count * sizeof(*data->bps));
1493                 kfree(data->bps);
1494         }
1495         if (data->bps_bo) {
1496                 memcpy(bps_bo, data->bps_bo,
1497                                 data->count * sizeof(*data->bps_bo));
1498                 kfree(data->bps_bo);
1499         }
1500
1501         data->bps = bps;
1502         data->bps_bo = bps_bo;
1503         data->space_left += align_space - old_space;
1504         return 0;
1505 }
1506
1507 /* it deal with vram only. */
1508 int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
1509                 struct eeprom_table_record *bps, int pages)
1510 {
1511         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1512         struct ras_err_handler_data *data;
1513         int ret = 0;
1514
1515         if (!con || !con->eh_data || !bps || pages <= 0)
1516                 return 0;
1517
1518         mutex_lock(&con->recovery_lock);
1519         data = con->eh_data;
1520         if (!data)
1521                 goto out;
1522
1523         if (data->space_left <= pages)
1524                 if (amdgpu_ras_realloc_eh_data_space(adev, data, pages)) {
1525                         ret = -ENOMEM;
1526                         goto out;
1527                 }
1528
1529         memcpy(&data->bps[data->count], bps, pages * sizeof(*data->bps));
1530         data->count += pages;
1531         data->space_left -= pages;
1532
1533 out:
1534         mutex_unlock(&con->recovery_lock);
1535
1536         return ret;
1537 }
1538
1539 /*
1540  * write error record array to eeprom, the function should be
1541  * protected by recovery_lock
1542  */
1543 static int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev)
1544 {
1545         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1546         struct ras_err_handler_data *data;
1547         struct amdgpu_ras_eeprom_control *control;
1548         int save_count;
1549
1550         if (!con || !con->eh_data)
1551                 return 0;
1552
1553         control = &con->eeprom_control;
1554         data = con->eh_data;
1555         save_count = data->count - control->num_recs;
1556         /* only new entries are saved */
1557         if (save_count > 0)
1558                 if (amdgpu_ras_eeprom_process_recods(control,
1559                                                         &data->bps[control->num_recs],
1560                                                         true,
1561                                                         save_count)) {
1562                         dev_err(adev->dev, "Failed to save EEPROM table data!");
1563                         return -EIO;
1564                 }
1565
1566         return 0;
1567 }
1568
1569 /*
1570  * read error record array in eeprom and reserve enough space for
1571  * storing new bad pages
1572  */
1573 static int amdgpu_ras_load_bad_pages(struct amdgpu_device *adev)
1574 {
1575         struct amdgpu_ras_eeprom_control *control =
1576                                         &adev->psp.ras.ras->eeprom_control;
1577         struct eeprom_table_record *bps = NULL;
1578         int ret = 0;
1579
1580         /* no bad page record, skip eeprom access */
1581         if (!control->num_recs)
1582                 return ret;
1583
1584         bps = kcalloc(control->num_recs, sizeof(*bps), GFP_KERNEL);
1585         if (!bps)
1586                 return -ENOMEM;
1587
1588         if (amdgpu_ras_eeprom_process_recods(control, bps, false,
1589                 control->num_recs)) {
1590                 dev_err(adev->dev, "Failed to load EEPROM table records!");
1591                 ret = -EIO;
1592                 goto out;
1593         }
1594
1595         ret = amdgpu_ras_add_bad_pages(adev, bps, control->num_recs);
1596
1597 out:
1598         kfree(bps);
1599         return ret;
1600 }
1601
1602 /*
1603  * check if an address belongs to bad page
1604  *
1605  * Note: this check is only for umc block
1606  */
1607 static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
1608                                 uint64_t addr)
1609 {
1610         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1611         struct ras_err_handler_data *data;
1612         int i;
1613         bool ret = false;
1614
1615         if (!con || !con->eh_data)
1616                 return ret;
1617
1618         mutex_lock(&con->recovery_lock);
1619         data = con->eh_data;
1620         if (!data)
1621                 goto out;
1622
1623         addr >>= AMDGPU_GPU_PAGE_SHIFT;
1624         for (i = 0; i < data->count; i++)
1625                 if (addr == data->bps[i].retired_page) {
1626                         ret = true;
1627                         goto out;
1628                 }
1629
1630 out:
1631         mutex_unlock(&con->recovery_lock);
1632         return ret;
1633 }
1634
1635 /* called in gpu recovery/init */
1636 int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev)
1637 {
1638         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1639         struct ras_err_handler_data *data;
1640         uint64_t bp;
1641         struct amdgpu_bo *bo = NULL;
1642         int i, ret = 0;
1643
1644         if (!con || !con->eh_data)
1645                 return 0;
1646
1647         mutex_lock(&con->recovery_lock);
1648         data = con->eh_data;
1649         if (!data)
1650                 goto out;
1651         /* reserve vram at driver post stage. */
1652         for (i = data->last_reserved; i < data->count; i++) {
1653                 bp = data->bps[i].retired_page;
1654
1655                 /* There are two cases of reserve error should be ignored:
1656                  * 1) a ras bad page has been allocated (used by someone);
1657                  * 2) a ras bad page has been reserved (duplicate error injection
1658                  *    for one page);
1659                  */
1660                 if (amdgpu_bo_create_kernel_at(adev, bp << AMDGPU_GPU_PAGE_SHIFT,
1661                                                AMDGPU_GPU_PAGE_SIZE,
1662                                                AMDGPU_GEM_DOMAIN_VRAM,
1663                                                &bo, NULL))
1664                         dev_warn(adev->dev, "RAS WARN: reserve vram for "
1665                                         "retired page %llx fail\n", bp);
1666
1667                 data->bps_bo[i] = bo;
1668                 data->last_reserved = i + 1;
1669                 bo = NULL;
1670         }
1671
1672         /* continue to save bad pages to eeprom even reesrve_vram fails */
1673         ret = amdgpu_ras_save_bad_pages(adev);
1674 out:
1675         mutex_unlock(&con->recovery_lock);
1676         return ret;
1677 }
1678
1679 /* called when driver unload */
1680 static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev)
1681 {
1682         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1683         struct ras_err_handler_data *data;
1684         struct amdgpu_bo *bo;
1685         int i;
1686
1687         if (!con || !con->eh_data)
1688                 return 0;
1689
1690         mutex_lock(&con->recovery_lock);
1691         data = con->eh_data;
1692         if (!data)
1693                 goto out;
1694
1695         for (i = data->last_reserved - 1; i >= 0; i--) {
1696                 bo = data->bps_bo[i];
1697
1698                 amdgpu_bo_free_kernel(&bo, NULL, NULL);
1699
1700                 data->bps_bo[i] = bo;
1701                 data->last_reserved = i;
1702         }
1703 out:
1704         mutex_unlock(&con->recovery_lock);
1705         return 0;
1706 }
1707
1708 int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
1709 {
1710         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1711         struct ras_err_handler_data **data;
1712         int ret;
1713
1714         if (con)
1715                 data = &con->eh_data;
1716         else
1717                 return 0;
1718
1719         *data = kmalloc(sizeof(**data), GFP_KERNEL | __GFP_ZERO);
1720         if (!*data) {
1721                 ret = -ENOMEM;
1722                 goto out;
1723         }
1724
1725         mutex_init(&con->recovery_lock);
1726         INIT_WORK(&con->recovery_work, amdgpu_ras_do_recovery);
1727         atomic_set(&con->in_recovery, 0);
1728         con->adev = adev;
1729
1730         ret = amdgpu_ras_eeprom_init(&con->eeprom_control);
1731         if (ret)
1732                 goto free;
1733
1734         if (con->eeprom_control.num_recs) {
1735                 ret = amdgpu_ras_load_bad_pages(adev);
1736                 if (ret)
1737                         goto free;
1738                 ret = amdgpu_ras_reserve_bad_pages(adev);
1739                 if (ret)
1740                         goto release;
1741         }
1742
1743         return 0;
1744
1745 release:
1746         amdgpu_ras_release_bad_pages(adev);
1747 free:
1748         kfree((*data)->bps);
1749         kfree((*data)->bps_bo);
1750         kfree(*data);
1751         con->eh_data = NULL;
1752 out:
1753         dev_warn(adev->dev, "Failed to initialize ras recovery!\n");
1754
1755         return ret;
1756 }
1757
1758 static int amdgpu_ras_recovery_fini(struct amdgpu_device *adev)
1759 {
1760         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1761         struct ras_err_handler_data *data = con->eh_data;
1762
1763         /* recovery_init failed to init it, fini is useless */
1764         if (!data)
1765                 return 0;
1766
1767         cancel_work_sync(&con->recovery_work);
1768         amdgpu_ras_release_bad_pages(adev);
1769
1770         mutex_lock(&con->recovery_lock);
1771         con->eh_data = NULL;
1772         kfree(data->bps);
1773         kfree(data->bps_bo);
1774         kfree(data);
1775         mutex_unlock(&con->recovery_lock);
1776
1777         return 0;
1778 }
1779 /* recovery end */
1780
1781 /* return 0 if ras will reset gpu and repost.*/
1782 int amdgpu_ras_request_reset_on_boot(struct amdgpu_device *adev,
1783                 unsigned int block)
1784 {
1785         struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
1786
1787         if (!ras)
1788                 return -EINVAL;
1789
1790         ras->flags |= AMDGPU_RAS_FLAG_INIT_NEED_RESET;
1791         return 0;
1792 }
1793
1794 /*
1795  * check hardware's ras ability which will be saved in hw_supported.
1796  * if hardware does not support ras, we can skip some ras initializtion and
1797  * forbid some ras operations from IP.
1798  * if software itself, say boot parameter, limit the ras ability. We still
1799  * need allow IP do some limited operations, like disable. In such case,
1800  * we have to initialize ras as normal. but need check if operation is
1801  * allowed or not in each function.
1802  */
1803 static void amdgpu_ras_check_supported(struct amdgpu_device *adev,
1804                 uint32_t *hw_supported, uint32_t *supported)
1805 {
1806         *hw_supported = 0;
1807         *supported = 0;
1808
1809         if (amdgpu_sriov_vf(adev) || !adev->is_atom_fw ||
1810             (adev->asic_type != CHIP_VEGA20 &&
1811              adev->asic_type != CHIP_ARCTURUS))
1812                 return;
1813
1814         if (amdgpu_atomfirmware_mem_ecc_supported(adev)) {
1815                 dev_info(adev->dev, "HBM ECC is active.\n");
1816                 *hw_supported |= (1 << AMDGPU_RAS_BLOCK__UMC |
1817                                 1 << AMDGPU_RAS_BLOCK__DF);
1818         } else
1819                 dev_info(adev->dev, "HBM ECC is not presented.\n");
1820
1821         if (amdgpu_atomfirmware_sram_ecc_supported(adev)) {
1822                 dev_info(adev->dev, "SRAM ECC is active.\n");
1823                 *hw_supported |= ~(1 << AMDGPU_RAS_BLOCK__UMC |
1824                                 1 << AMDGPU_RAS_BLOCK__DF);
1825         } else
1826                 dev_info(adev->dev, "SRAM ECC is not presented.\n");
1827
1828         /* hw_supported needs to be aligned with RAS block mask. */
1829         *hw_supported &= AMDGPU_RAS_BLOCK_MASK;
1830
1831         *supported = amdgpu_ras_enable == 0 ?
1832                         0 : *hw_supported & amdgpu_ras_mask;
1833 }
1834
1835 int amdgpu_ras_init(struct amdgpu_device *adev)
1836 {
1837         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1838         int r;
1839
1840         if (con)
1841                 return 0;
1842
1843         con = kmalloc(sizeof(struct amdgpu_ras) +
1844                         sizeof(struct ras_manager) * AMDGPU_RAS_BLOCK_COUNT,
1845                         GFP_KERNEL|__GFP_ZERO);
1846         if (!con)
1847                 return -ENOMEM;
1848
1849         con->objs = (struct ras_manager *)(con + 1);
1850
1851         amdgpu_ras_set_context(adev, con);
1852
1853         amdgpu_ras_check_supported(adev, &con->hw_supported,
1854                         &con->supported);
1855         if (!con->hw_supported) {
1856                 amdgpu_ras_set_context(adev, NULL);
1857                 kfree(con);
1858                 return 0;
1859         }
1860
1861         con->features = 0;
1862         INIT_LIST_HEAD(&con->head);
1863         /* Might need get this flag from vbios. */
1864         con->flags = RAS_DEFAULT_FLAGS;
1865
1866         if (adev->nbio.funcs->init_ras_controller_interrupt) {
1867                 r = adev->nbio.funcs->init_ras_controller_interrupt(adev);
1868                 if (r)
1869                         return r;
1870         }
1871
1872         if (adev->nbio.funcs->init_ras_err_event_athub_interrupt) {
1873                 r = adev->nbio.funcs->init_ras_err_event_athub_interrupt(adev);
1874                 if (r)
1875                         return r;
1876         }
1877
1878         amdgpu_ras_mask &= AMDGPU_RAS_BLOCK_MASK;
1879
1880         if (amdgpu_ras_fs_init(adev))
1881                 goto fs_out;
1882
1883         dev_info(adev->dev, "RAS INFO: ras initialized successfully, "
1884                         "hardware ability[%x] ras_mask[%x]\n",
1885                         con->hw_supported, con->supported);
1886         return 0;
1887 fs_out:
1888         amdgpu_ras_set_context(adev, NULL);
1889         kfree(con);
1890
1891         return -EINVAL;
1892 }
1893
1894 /* helper function to handle common stuff in ip late init phase */
1895 int amdgpu_ras_late_init(struct amdgpu_device *adev,
1896                          struct ras_common_if *ras_block,
1897                          struct ras_fs_if *fs_info,
1898                          struct ras_ih_if *ih_info)
1899 {
1900         int r;
1901
1902         /* disable RAS feature per IP block if it is not supported */
1903         if (!amdgpu_ras_is_supported(adev, ras_block->block)) {
1904                 amdgpu_ras_feature_enable_on_boot(adev, ras_block, 0);
1905                 return 0;
1906         }
1907
1908         r = amdgpu_ras_feature_enable_on_boot(adev, ras_block, 1);
1909         if (r) {
1910                 if (r == -EAGAIN) {
1911                         /* request gpu reset. will run again */
1912                         amdgpu_ras_request_reset_on_boot(adev,
1913                                         ras_block->block);
1914                         return 0;
1915                 } else if (adev->in_suspend || adev->in_gpu_reset) {
1916                         /* in resume phase, if fail to enable ras,
1917                          * clean up all ras fs nodes, and disable ras */
1918                         goto cleanup;
1919                 } else
1920                         return r;
1921         }
1922
1923         /* in resume phase, no need to create ras fs node */
1924         if (adev->in_suspend || adev->in_gpu_reset)
1925                 return 0;
1926
1927         if (ih_info->cb) {
1928                 r = amdgpu_ras_interrupt_add_handler(adev, ih_info);
1929                 if (r)
1930                         goto interrupt;
1931         }
1932
1933         r = amdgpu_ras_sysfs_create(adev, fs_info);
1934         if (r)
1935                 goto sysfs;
1936
1937         return 0;
1938 cleanup:
1939         amdgpu_ras_sysfs_remove(adev, ras_block);
1940 sysfs:
1941         if (ih_info->cb)
1942                 amdgpu_ras_interrupt_remove_handler(adev, ih_info);
1943 interrupt:
1944         amdgpu_ras_feature_enable(adev, ras_block, 0);
1945         return r;
1946 }
1947
1948 /* helper function to remove ras fs node and interrupt handler */
1949 void amdgpu_ras_late_fini(struct amdgpu_device *adev,
1950                           struct ras_common_if *ras_block,
1951                           struct ras_ih_if *ih_info)
1952 {
1953         if (!ras_block || !ih_info)
1954                 return;
1955
1956         amdgpu_ras_sysfs_remove(adev, ras_block);
1957         if (ih_info->cb)
1958                 amdgpu_ras_interrupt_remove_handler(adev, ih_info);
1959         amdgpu_ras_feature_enable(adev, ras_block, 0);
1960 }
1961
1962 /* do some init work after IP late init as dependence.
1963  * and it runs in resume/gpu reset/booting up cases.
1964  */
1965 void amdgpu_ras_resume(struct amdgpu_device *adev)
1966 {
1967         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1968         struct ras_manager *obj, *tmp;
1969
1970         if (!con)
1971                 return;
1972
1973         if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
1974                 /* Set up all other IPs which are not implemented. There is a
1975                  * tricky thing that IP's actual ras error type should be
1976                  * MULTI_UNCORRECTABLE, but as driver does not handle it, so
1977                  * ERROR_NONE make sense anyway.
1978                  */
1979                 amdgpu_ras_enable_all_features(adev, 1);
1980
1981                 /* We enable ras on all hw_supported block, but as boot
1982                  * parameter might disable some of them and one or more IP has
1983                  * not implemented yet. So we disable them on behalf.
1984                  */
1985                 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1986                         if (!amdgpu_ras_is_supported(adev, obj->head.block)) {
1987                                 amdgpu_ras_feature_enable(adev, &obj->head, 0);
1988                                 /* there should be no any reference. */
1989                                 WARN_ON(alive_obj(obj));
1990                         }
1991                 }
1992         }
1993
1994         if (con->flags & AMDGPU_RAS_FLAG_INIT_NEED_RESET) {
1995                 con->flags &= ~AMDGPU_RAS_FLAG_INIT_NEED_RESET;
1996                 /* setup ras obj state as disabled.
1997                  * for init_by_vbios case.
1998                  * if we want to enable ras, just enable it in a normal way.
1999                  * If we want do disable it, need setup ras obj as enabled,
2000                  * then issue another TA disable cmd.
2001                  * See feature_enable_on_boot
2002                  */
2003                 amdgpu_ras_disable_all_features(adev, 1);
2004                 amdgpu_ras_reset_gpu(adev);
2005         }
2006 }
2007
2008 void amdgpu_ras_suspend(struct amdgpu_device *adev)
2009 {
2010         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2011
2012         if (!con)
2013                 return;
2014
2015         amdgpu_ras_disable_all_features(adev, 0);
2016         /* Make sure all ras objects are disabled. */
2017         if (con->features)
2018                 amdgpu_ras_disable_all_features(adev, 1);
2019 }
2020
2021 /* do some fini work before IP fini as dependence */
2022 int amdgpu_ras_pre_fini(struct amdgpu_device *adev)
2023 {
2024         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2025
2026         if (!con)
2027                 return 0;
2028
2029         /* Need disable ras on all IPs here before ip [hw/sw]fini */
2030         amdgpu_ras_disable_all_features(adev, 0);
2031         amdgpu_ras_recovery_fini(adev);
2032         return 0;
2033 }
2034
2035 int amdgpu_ras_fini(struct amdgpu_device *adev)
2036 {
2037         struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2038
2039         if (!con)
2040                 return 0;
2041
2042         amdgpu_ras_fs_fini(adev);
2043         amdgpu_ras_interrupt_remove_all(adev);
2044
2045         WARN(con->features, "Feature mask is not cleared");
2046
2047         if (con->features)
2048                 amdgpu_ras_disable_all_features(adev, 1);
2049
2050         amdgpu_ras_set_context(adev, NULL);
2051         kfree(con);
2052
2053         return 0;
2054 }
2055
2056 void amdgpu_ras_global_ras_isr(struct amdgpu_device *adev)
2057 {
2058         uint32_t hw_supported, supported;
2059
2060         amdgpu_ras_check_supported(adev, &hw_supported, &supported);
2061         if (!hw_supported)
2062                 return;
2063
2064         if (atomic_cmpxchg(&amdgpu_ras_in_intr, 0, 1) == 0) {
2065                 dev_info(adev->dev, "uncorrectable hardware error"
2066                         "(ERREVENT_ATHUB_INTERRUPT) detected!\n");
2067
2068                 amdgpu_ras_reset_gpu(adev);
2069         }
2070 }
This page took 0.15227 seconds and 4 git commands to generate.