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.
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>
32 #include "amdgpu_ras.h"
33 #include "amdgpu_atomfirmware.h"
34 #include "ivsrcid/nbio/irqsrcs_nbif_7_4.h"
36 const char *ras_error_string[] = {
40 "multi_uncorrectable",
44 const char *ras_block_string[] = {
61 #define ras_err_str(i) (ras_error_string[ffs(i)])
62 #define ras_block_str(i) (ras_block_string[i])
64 #define AMDGPU_RAS_FLAG_INIT_BY_VBIOS 1
65 #define AMDGPU_RAS_FLAG_INIT_NEED_RESET 2
66 #define RAS_DEFAULT_FLAGS (AMDGPU_RAS_FLAG_INIT_BY_VBIOS)
68 /* inject address is 52 bits */
69 #define RAS_UMC_INJECT_ADDR_LIMIT (0x1ULL << 52)
72 atomic_t amdgpu_ras_in_intr = ATOMIC_INIT(0);
74 static int amdgpu_ras_reserve_vram(struct amdgpu_device *adev,
75 uint64_t offset, uint64_t size,
76 struct amdgpu_bo **bo_ptr);
77 static int amdgpu_ras_release_vram(struct amdgpu_device *adev,
78 struct amdgpu_bo **bo_ptr);
80 static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,
81 size_t size, loff_t *pos)
83 struct ras_manager *obj = (struct ras_manager *)file_inode(f)->i_private;
84 struct ras_query_if info = {
90 if (amdgpu_ras_error_query(obj->adev, &info))
93 s = snprintf(val, sizeof(val), "%s: %lu\n%s: %lu\n",
100 s = min_t(u64, s, size);
103 if (copy_to_user(buf, &val[*pos], s))
111 static const struct file_operations amdgpu_ras_debugfs_ops = {
112 .owner = THIS_MODULE,
113 .read = amdgpu_ras_debugfs_read,
115 .llseek = default_llseek
118 static int amdgpu_ras_find_block_id_by_name(const char *name, int *block_id)
122 for (i = 0; i < ARRAY_SIZE(ras_block_string); i++) {
124 if (strcmp(name, ras_block_str(i)) == 0)
130 static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
131 const char __user *buf, size_t size,
132 loff_t *pos, struct ras_debug_if *data)
134 ssize_t s = min_t(u64, 64, size);
147 memset(str, 0, sizeof(str));
148 memset(data, 0, sizeof(*data));
150 if (copy_from_user(str, buf, s))
153 if (sscanf(str, "disable %32s", block_name) == 1)
155 else if (sscanf(str, "enable %32s %8s", block_name, err) == 2)
157 else if (sscanf(str, "inject %32s %8s", block_name, err) == 2)
159 else if (sscanf(str, "reboot %32s", block_name) == 1)
161 else if (str[0] && str[1] && str[2] && str[3])
162 /* ascii string, but commands are not matched. */
166 if (amdgpu_ras_find_block_id_by_name(block_name, &block_id))
169 data->head.block = block_id;
170 /* only ue and ce errors are supported */
171 if (!memcmp("ue", err, 2))
172 data->head.type = AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE;
173 else if (!memcmp("ce", err, 2))
174 data->head.type = AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE;
181 if (sscanf(str, "%*s %*s %*s %u %llu %llu",
182 &sub_block, &address, &value) != 3)
183 if (sscanf(str, "%*s %*s %*s 0x%x 0x%llx 0x%llx",
184 &sub_block, &address, &value) != 3)
186 data->head.sub_block_index = sub_block;
187 data->inject.address = address;
188 data->inject.value = value;
191 if (size < sizeof(*data))
194 if (copy_from_user(data, buf, sizeof(*data)))
201 static struct ras_manager *amdgpu_ras_find_obj(struct amdgpu_device *adev,
202 struct ras_common_if *head);
205 * DOC: AMDGPU RAS debugfs control interface
207 * It accepts struct ras_debug_if who has two members.
209 * First member: ras_debug_if::head or ras_debug_if::inject.
211 * head is used to indicate which IP block will be under control.
213 * head has four members, they are block, type, sub_block_index, name.
214 * block: which IP will be under control.
215 * type: what kind of error will be enabled/disabled/injected.
216 * sub_block_index: some IPs have subcomponets. say, GFX, sDMA.
217 * name: the name of IP.
219 * inject has two more members than head, they are address, value.
220 * As their names indicate, inject operation will write the
221 * value to the address.
223 * Second member: struct ras_debug_if::op.
224 * It has three kinds of operations.
225 * 0: disable RAS on the block. Take ::head as its data.
226 * 1: enable RAS on the block. Take ::head as its data.
227 * 2: inject errors on the block. Take ::inject as its data.
229 * How to use the interface?
231 * copy the struct ras_debug_if in your codes and initialize it.
232 * write the struct to the control node.
235 * echo op block [error [sub_blcok address value]] > .../ras/ras_ctrl
236 * op: disable, enable, inject
237 * disable: only block is needed
238 * enable: block and error are needed
239 * inject: error, address, value are needed
240 * block: umc, smda, gfx, .........
241 * see ras_block_string[] for details
243 * ue: multi_uncorrectable
244 * ce: single_correctable
245 * sub_block: sub block index, pass 0 if there is no sub block
247 * here are some examples for bash commands,
248 * echo inject umc ue 0x0 0x0 0x0 > /sys/kernel/debug/dri/0/ras/ras_ctrl
249 * echo inject umc ce 0 0 0 > /sys/kernel/debug/dri/0/ras/ras_ctrl
250 * echo disable umc > /sys/kernel/debug/dri/0/ras/ras_ctrl
252 * How to check the result?
254 * For disable/enable, please check ras features at
255 * /sys/class/drm/card[0/1/2...]/device/ras/features
257 * For inject, please check corresponding err count at
258 * /sys/class/drm/card[0/1/2...]/device/ras/[gfx/sdma/...]_err_count
260 * NOTE: operation is only allowed on blocks which are supported.
261 * Please check ras mask at /sys/module/amdgpu/parameters/ras_mask
263 static ssize_t amdgpu_ras_debugfs_ctrl_write(struct file *f, const char __user *buf,
264 size_t size, loff_t *pos)
266 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
267 struct ras_debug_if data;
270 ret = amdgpu_ras_debugfs_ctrl_parse_data(f, buf, size, pos, &data);
274 if (!amdgpu_ras_is_supported(adev, data.head.block))
279 ret = amdgpu_ras_feature_enable(adev, &data.head, 0);
282 ret = amdgpu_ras_feature_enable(adev, &data.head, 1);
285 if ((data.inject.address >= adev->gmc.mc_vram_size) ||
286 (data.inject.address >= RAS_UMC_INJECT_ADDR_LIMIT)) {
291 /* data.inject.address is offset instead of absolute gpu address */
292 ret = amdgpu_ras_error_inject(adev, &data.inject);
295 amdgpu_ras_get_context(adev)->reboot = true;
309 * DOC: AMDGPU RAS debugfs EEPROM table reset interface
311 * Usage: echo 1 > ../ras/ras_eeprom_reset will reset EEPROM table to 0 entries.
313 static ssize_t amdgpu_ras_debugfs_eeprom_write(struct file *f, const char __user *buf,
314 size_t size, loff_t *pos)
316 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
319 ret = amdgpu_ras_eeprom_reset_table(&adev->psp.ras.ras->eeprom_control);
321 return ret == 1 ? size : -EIO;
324 static const struct file_operations amdgpu_ras_debugfs_ctrl_ops = {
325 .owner = THIS_MODULE,
327 .write = amdgpu_ras_debugfs_ctrl_write,
328 .llseek = default_llseek
331 static const struct file_operations amdgpu_ras_debugfs_eeprom_ops = {
332 .owner = THIS_MODULE,
334 .write = amdgpu_ras_debugfs_eeprom_write,
335 .llseek = default_llseek
338 static ssize_t amdgpu_ras_sysfs_read(struct device *dev,
339 struct device_attribute *attr, char *buf)
341 struct ras_manager *obj = container_of(attr, struct ras_manager, sysfs_attr);
342 struct ras_query_if info = {
346 if (amdgpu_ras_error_query(obj->adev, &info))
349 return snprintf(buf, PAGE_SIZE, "%s: %lu\n%s: %lu\n",
351 "ce", info.ce_count);
356 #define get_obj(obj) do { (obj)->use++; } while (0)
357 #define alive_obj(obj) ((obj)->use)
359 static inline void put_obj(struct ras_manager *obj)
361 if (obj && --obj->use == 0)
362 list_del(&obj->node);
363 if (obj && obj->use < 0) {
364 DRM_ERROR("RAS ERROR: Unbalance obj(%s) use\n", obj->head.name);
368 /* make one obj and return it. */
369 static struct ras_manager *amdgpu_ras_create_obj(struct amdgpu_device *adev,
370 struct ras_common_if *head)
372 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
373 struct ras_manager *obj;
378 if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
381 obj = &con->objs[head->block];
382 /* already exist. return obj? */
388 list_add(&obj->node, &con->head);
394 /* return an obj equal to head, or the first when head is NULL */
395 static struct ras_manager *amdgpu_ras_find_obj(struct amdgpu_device *adev,
396 struct ras_common_if *head)
398 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
399 struct ras_manager *obj;
406 if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
409 obj = &con->objs[head->block];
411 if (alive_obj(obj)) {
412 WARN_ON(head->block != obj->head.block);
416 for (i = 0; i < AMDGPU_RAS_BLOCK_COUNT; i++) {
418 if (alive_obj(obj)) {
419 WARN_ON(i != obj->head.block);
429 /* feature ctl begin */
430 static int amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
431 struct ras_common_if *head)
433 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
435 return con->hw_supported & BIT(head->block);
438 static int amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
439 struct ras_common_if *head)
441 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
443 return con->features & BIT(head->block);
447 * if obj is not created, then create one.
448 * set feature enable flag.
450 static int __amdgpu_ras_feature_enable(struct amdgpu_device *adev,
451 struct ras_common_if *head, int enable)
453 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
454 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
456 /* If hardware does not support ras, then do not create obj.
457 * But if hardware support ras, we can create the obj.
458 * Ras framework checks con->hw_supported to see if it need do
459 * corresponding initialization.
460 * IP checks con->support to see if it need disable ras.
462 if (!amdgpu_ras_is_feature_allowed(adev, head))
464 if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
469 obj = amdgpu_ras_create_obj(adev, head);
473 /* In case we create obj somewhere else */
476 con->features |= BIT(head->block);
478 if (obj && amdgpu_ras_is_feature_enabled(adev, head)) {
479 con->features &= ~BIT(head->block);
487 /* wrapper of psp_ras_enable_features */
488 int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
489 struct ras_common_if *head, bool enable)
491 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
492 union ta_ras_cmd_input info;
499 info.disable_features = (struct ta_ras_disable_features_input) {
500 .block_id = amdgpu_ras_block_to_ta(head->block),
501 .error_type = amdgpu_ras_error_to_ta(head->type),
504 info.enable_features = (struct ta_ras_enable_features_input) {
505 .block_id = amdgpu_ras_block_to_ta(head->block),
506 .error_type = amdgpu_ras_error_to_ta(head->type),
510 /* Do not enable if it is not allowed. */
511 WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
512 /* Are we alerady in that state we are going to set? */
513 if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
516 ret = psp_ras_enable_features(&adev->psp, &info, enable);
518 DRM_ERROR("RAS ERROR: %s %s feature failed ret %d\n",
519 enable ? "enable":"disable",
520 ras_block_str(head->block),
522 if (ret == TA_RAS_STATUS__RESET_NEEDED)
528 __amdgpu_ras_feature_enable(adev, head, enable);
533 /* Only used in device probe stage and called only once. */
534 int amdgpu_ras_feature_enable_on_boot(struct amdgpu_device *adev,
535 struct ras_common_if *head, bool enable)
537 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
543 if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
545 /* There is no harm to issue a ras TA cmd regardless of
546 * the currecnt ras state.
547 * If current state == target state, it will do nothing
548 * But sometimes it requests driver to reset and repost
549 * with error code -EAGAIN.
551 ret = amdgpu_ras_feature_enable(adev, head, 1);
552 /* With old ras TA, we might fail to enable ras.
553 * Log it and just setup the object.
554 * TODO need remove this WA in the future.
556 if (ret == -EINVAL) {
557 ret = __amdgpu_ras_feature_enable(adev, head, 1);
559 DRM_INFO("RAS INFO: %s setup object\n",
560 ras_block_str(head->block));
563 /* setup the object then issue a ras TA disable cmd.*/
564 ret = __amdgpu_ras_feature_enable(adev, head, 1);
568 ret = amdgpu_ras_feature_enable(adev, head, 0);
571 ret = amdgpu_ras_feature_enable(adev, head, enable);
576 static int amdgpu_ras_disable_all_features(struct amdgpu_device *adev,
579 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
580 struct ras_manager *obj, *tmp;
582 list_for_each_entry_safe(obj, tmp, &con->head, node) {
584 * aka just release the obj and corresponding flags
587 if (__amdgpu_ras_feature_enable(adev, &obj->head, 0))
590 if (amdgpu_ras_feature_enable(adev, &obj->head, 0))
595 return con->features;
598 static int amdgpu_ras_enable_all_features(struct amdgpu_device *adev,
601 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
602 int ras_block_count = AMDGPU_RAS_BLOCK_COUNT;
604 const enum amdgpu_ras_error_type default_ras_type =
605 AMDGPU_RAS_ERROR__NONE;
607 for (i = 0; i < ras_block_count; i++) {
608 struct ras_common_if head = {
610 .type = default_ras_type,
611 .sub_block_index = 0,
613 strcpy(head.name, ras_block_str(i));
616 * bypass psp. vbios enable ras for us.
617 * so just create the obj
619 if (__amdgpu_ras_feature_enable(adev, &head, 1))
622 if (amdgpu_ras_feature_enable(adev, &head, 1))
627 return con->features;
629 /* feature ctl end */
631 /* query/inject/cure begin */
632 int amdgpu_ras_error_query(struct amdgpu_device *adev,
633 struct ras_query_if *info)
635 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
636 struct ras_err_data err_data = {0, 0, 0, NULL};
641 switch (info->head.block) {
642 case AMDGPU_RAS_BLOCK__UMC:
643 if (adev->umc.funcs->query_ras_error_count)
644 adev->umc.funcs->query_ras_error_count(adev, &err_data);
645 /* umc query_ras_error_address is also responsible for clearing
648 if (adev->umc.funcs->query_ras_error_address)
649 adev->umc.funcs->query_ras_error_address(adev, &err_data);
651 case AMDGPU_RAS_BLOCK__GFX:
652 if (adev->gfx.funcs->query_ras_error_count)
653 adev->gfx.funcs->query_ras_error_count(adev, &err_data);
655 case AMDGPU_RAS_BLOCK__MMHUB:
656 if (adev->mmhub_funcs->query_ras_error_count)
657 adev->mmhub_funcs->query_ras_error_count(adev, &err_data);
663 obj->err_data.ue_count += err_data.ue_count;
664 obj->err_data.ce_count += err_data.ce_count;
666 info->ue_count = obj->err_data.ue_count;
667 info->ce_count = obj->err_data.ce_count;
669 if (err_data.ce_count) {
670 dev_info(adev->dev, "%ld correctable errors detected in %s block\n",
671 obj->err_data.ce_count, ras_block_str(info->head.block));
673 if (err_data.ue_count) {
674 dev_info(adev->dev, "%ld uncorrectable errors detected in %s block\n",
675 obj->err_data.ue_count, ras_block_str(info->head.block));
681 /* wrapper of psp_ras_trigger_error */
682 int amdgpu_ras_error_inject(struct amdgpu_device *adev,
683 struct ras_inject_if *info)
685 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
686 struct ta_ras_trigger_error_input block_info = {
687 .block_id = amdgpu_ras_block_to_ta(info->head.block),
688 .inject_error_type = amdgpu_ras_error_to_ta(info->head.type),
689 .sub_block_index = info->head.sub_block_index,
690 .address = info->address,
691 .value = info->value,
698 switch (info->head.block) {
699 case AMDGPU_RAS_BLOCK__GFX:
700 if (adev->gfx.funcs->ras_error_inject)
701 ret = adev->gfx.funcs->ras_error_inject(adev, info);
705 case AMDGPU_RAS_BLOCK__UMC:
706 case AMDGPU_RAS_BLOCK__MMHUB:
707 ret = psp_ras_trigger_error(&adev->psp, &block_info);
710 DRM_INFO("%s error injection is not supported yet\n",
711 ras_block_str(info->head.block));
716 DRM_ERROR("RAS ERROR: inject %s error failed ret %d\n",
717 ras_block_str(info->head.block),
723 int amdgpu_ras_error_cure(struct amdgpu_device *adev,
724 struct ras_cure_if *info)
726 /* psp fw has no cure interface for now. */
730 /* get the total error counts on all IPs */
731 unsigned long amdgpu_ras_query_error_count(struct amdgpu_device *adev,
734 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
735 struct ras_manager *obj;
736 struct ras_err_data data = {0, 0};
741 list_for_each_entry(obj, &con->head, node) {
742 struct ras_query_if info = {
746 if (amdgpu_ras_error_query(adev, &info))
749 data.ce_count += info.ce_count;
750 data.ue_count += info.ue_count;
753 return is_ce ? data.ce_count : data.ue_count;
755 /* query/inject/cure end */
760 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
761 struct ras_badpage **bps, unsigned int *count);
763 static char *amdgpu_ras_badpage_flags_str(unsigned int flags)
777 * DOC: ras sysfs gpu_vram_bad_pages interface
779 * It allows user to read the bad pages of vram on the gpu through
780 * /sys/class/drm/card[0/1/2...]/device/ras/gpu_vram_bad_pages
782 * It outputs multiple lines, and each line stands for one gpu page.
784 * The format of one line is below,
785 * gpu pfn : gpu page size : flags
787 * gpu pfn and gpu page size are printed in hex format.
788 * flags can be one of below character,
789 * R: reserved, this gpu page is reserved and not able to use.
790 * P: pending for reserve, this gpu page is marked as bad, will be reserved
791 * in next window of page_reserve.
792 * F: unable to reserve. this gpu page can't be reserved due to some reasons.
795 * 0x00000001 : 0x00001000 : R
796 * 0x00000002 : 0x00001000 : P
799 static ssize_t amdgpu_ras_sysfs_badpages_read(struct file *f,
800 struct kobject *kobj, struct bin_attribute *attr,
801 char *buf, loff_t ppos, size_t count)
803 struct amdgpu_ras *con =
804 container_of(attr, struct amdgpu_ras, badpages_attr);
805 struct amdgpu_device *adev = con->adev;
806 const unsigned int element_size =
807 sizeof("0xabcdabcd : 0x12345678 : R\n") - 1;
808 unsigned int start = div64_ul(ppos + element_size - 1, element_size);
809 unsigned int end = div64_ul(ppos + count - 1, element_size);
811 struct ras_badpage *bps = NULL;
812 unsigned int bps_count = 0;
814 memset(buf, 0, count);
816 if (amdgpu_ras_badpages_read(adev, &bps, &bps_count))
819 for (; start < end && start < bps_count; start++)
820 s += scnprintf(&buf[s], element_size + 1,
821 "0x%08x : 0x%08x : %1s\n",
824 amdgpu_ras_badpage_flags_str(bps[start].flags));
831 static ssize_t amdgpu_ras_sysfs_features_read(struct device *dev,
832 struct device_attribute *attr, char *buf)
834 struct amdgpu_ras *con =
835 container_of(attr, struct amdgpu_ras, features_attr);
837 return scnprintf(buf, PAGE_SIZE, "feature mask: 0x%x\n", con->features);
840 static int amdgpu_ras_sysfs_create_feature_node(struct amdgpu_device *adev)
842 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
843 struct attribute *attrs[] = {
844 &con->features_attr.attr,
847 struct bin_attribute *bin_attrs[] = {
851 struct attribute_group group = {
854 .bin_attrs = bin_attrs,
857 con->features_attr = (struct device_attribute) {
862 .show = amdgpu_ras_sysfs_features_read,
865 con->badpages_attr = (struct bin_attribute) {
867 .name = "gpu_vram_bad_pages",
872 .read = amdgpu_ras_sysfs_badpages_read,
875 sysfs_attr_init(attrs[0]);
876 sysfs_bin_attr_init(bin_attrs[0]);
878 return sysfs_create_group(&adev->dev->kobj, &group);
881 static int amdgpu_ras_sysfs_remove_feature_node(struct amdgpu_device *adev)
883 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
884 struct attribute *attrs[] = {
885 &con->features_attr.attr,
888 struct bin_attribute *bin_attrs[] = {
892 struct attribute_group group = {
895 .bin_attrs = bin_attrs,
898 sysfs_remove_group(&adev->dev->kobj, &group);
903 int amdgpu_ras_sysfs_create(struct amdgpu_device *adev,
904 struct ras_fs_if *head)
906 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &head->head);
908 if (!obj || obj->attr_inuse)
913 memcpy(obj->fs_data.sysfs_name,
915 sizeof(obj->fs_data.sysfs_name));
917 obj->sysfs_attr = (struct device_attribute){
919 .name = obj->fs_data.sysfs_name,
922 .show = amdgpu_ras_sysfs_read,
924 sysfs_attr_init(&obj->sysfs_attr.attr);
926 if (sysfs_add_file_to_group(&adev->dev->kobj,
927 &obj->sysfs_attr.attr,
938 int amdgpu_ras_sysfs_remove(struct amdgpu_device *adev,
939 struct ras_common_if *head)
941 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
943 if (!obj || !obj->attr_inuse)
946 sysfs_remove_file_from_group(&adev->dev->kobj,
947 &obj->sysfs_attr.attr,
955 static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
957 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
958 struct ras_manager *obj, *tmp;
960 list_for_each_entry_safe(obj, tmp, &con->head, node) {
961 amdgpu_ras_sysfs_remove(adev, &obj->head);
964 amdgpu_ras_sysfs_remove_feature_node(adev);
971 static void amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *adev)
973 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
974 struct drm_minor *minor = adev->ddev->primary;
976 con->dir = debugfs_create_dir("ras", minor->debugfs_root);
977 con->ent = debugfs_create_file("ras_ctrl", S_IWUGO | S_IRUGO, con->dir,
978 adev, &amdgpu_ras_debugfs_ctrl_ops);
979 con->ent = debugfs_create_file("ras_eeprom_reset", S_IWUGO | S_IRUGO, con->dir,
980 adev, &amdgpu_ras_debugfs_eeprom_ops);
983 void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
984 struct ras_fs_if *head)
986 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
987 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &head->head);
989 if (!obj || obj->ent)
994 memcpy(obj->fs_data.debugfs_name,
996 sizeof(obj->fs_data.debugfs_name));
998 obj->ent = debugfs_create_file(obj->fs_data.debugfs_name,
999 S_IWUGO | S_IRUGO, con->dir, obj,
1000 &amdgpu_ras_debugfs_ops);
1003 void amdgpu_ras_debugfs_remove(struct amdgpu_device *adev,
1004 struct ras_common_if *head)
1006 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1008 if (!obj || !obj->ent)
1011 debugfs_remove(obj->ent);
1016 static void amdgpu_ras_debugfs_remove_all(struct amdgpu_device *adev)
1018 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1019 struct ras_manager *obj, *tmp;
1021 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1022 amdgpu_ras_debugfs_remove(adev, &obj->head);
1025 debugfs_remove(con->ent);
1026 debugfs_remove(con->dir);
1034 static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
1036 amdgpu_ras_sysfs_create_feature_node(adev);
1037 amdgpu_ras_debugfs_create_ctrl_node(adev);
1042 static int amdgpu_ras_fs_fini(struct amdgpu_device *adev)
1044 amdgpu_ras_debugfs_remove_all(adev);
1045 amdgpu_ras_sysfs_remove_all(adev);
1051 static void amdgpu_ras_interrupt_handler(struct ras_manager *obj)
1053 struct ras_ih_data *data = &obj->ih_data;
1054 struct amdgpu_iv_entry entry;
1056 struct ras_err_data err_data = {0, 0, 0, NULL};
1058 while (data->rptr != data->wptr) {
1060 memcpy(&entry, &data->ring[data->rptr],
1061 data->element_size);
1064 data->rptr = (data->aligned_element_size +
1065 data->rptr) % data->ring_size;
1067 /* Let IP handle its data, maybe we need get the output
1068 * from the callback to udpate the error type/count, etc
1071 ret = data->cb(obj->adev, &err_data, &entry);
1072 /* ue will trigger an interrupt, and in that case
1073 * we need do a reset to recovery the whole system.
1074 * But leave IP do that recovery, here we just dispatch
1077 if (ret == AMDGPU_RAS_SUCCESS) {
1078 /* these counts could be left as 0 if
1079 * some blocks do not count error number
1081 obj->err_data.ue_count += err_data.ue_count;
1082 obj->err_data.ce_count += err_data.ce_count;
1088 static void amdgpu_ras_interrupt_process_handler(struct work_struct *work)
1090 struct ras_ih_data *data =
1091 container_of(work, struct ras_ih_data, ih_work);
1092 struct ras_manager *obj =
1093 container_of(data, struct ras_manager, ih_data);
1095 amdgpu_ras_interrupt_handler(obj);
1098 int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev,
1099 struct ras_dispatch_if *info)
1101 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1102 struct ras_ih_data *data = &obj->ih_data;
1107 if (data->inuse == 0)
1110 /* Might be overflow... */
1111 memcpy(&data->ring[data->wptr], info->entry,
1112 data->element_size);
1115 data->wptr = (data->aligned_element_size +
1116 data->wptr) % data->ring_size;
1118 schedule_work(&data->ih_work);
1123 int amdgpu_ras_interrupt_remove_handler(struct amdgpu_device *adev,
1124 struct ras_ih_if *info)
1126 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1127 struct ras_ih_data *data;
1132 data = &obj->ih_data;
1133 if (data->inuse == 0)
1136 cancel_work_sync(&data->ih_work);
1139 memset(data, 0, sizeof(*data));
1145 int amdgpu_ras_interrupt_add_handler(struct amdgpu_device *adev,
1146 struct ras_ih_if *info)
1148 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1149 struct ras_ih_data *data;
1152 /* in case we registe the IH before enable ras feature */
1153 obj = amdgpu_ras_create_obj(adev, &info->head);
1159 data = &obj->ih_data;
1160 /* add the callback.etc */
1161 *data = (struct ras_ih_data) {
1164 .element_size = sizeof(struct amdgpu_iv_entry),
1169 INIT_WORK(&data->ih_work, amdgpu_ras_interrupt_process_handler);
1171 data->aligned_element_size = ALIGN(data->element_size, 8);
1172 /* the ring can store 64 iv entries. */
1173 data->ring_size = 64 * data->aligned_element_size;
1174 data->ring = kmalloc(data->ring_size, GFP_KERNEL);
1186 static int amdgpu_ras_interrupt_remove_all(struct amdgpu_device *adev)
1188 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1189 struct ras_manager *obj, *tmp;
1191 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1192 struct ras_ih_if info = {
1195 amdgpu_ras_interrupt_remove_handler(adev, &info);
1202 /* recovery begin */
1204 /* return 0 on success.
1205 * caller need free bps.
1207 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
1208 struct ras_badpage **bps, unsigned int *count)
1210 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1211 struct ras_err_handler_data *data;
1215 if (!con || !con->eh_data || !bps || !count)
1218 mutex_lock(&con->recovery_lock);
1219 data = con->eh_data;
1220 if (!data || data->count == 0) {
1225 *bps = kmalloc(sizeof(struct ras_badpage) * data->count, GFP_KERNEL);
1231 for (; i < data->count; i++) {
1232 (*bps)[i] = (struct ras_badpage){
1233 .bp = data->bps[i].retired_page,
1234 .size = AMDGPU_GPU_PAGE_SIZE,
1238 if (data->last_reserved <= i)
1239 (*bps)[i].flags = 1;
1240 else if (data->bps_bo[i] == NULL)
1241 (*bps)[i].flags = 2;
1244 *count = data->count;
1246 mutex_unlock(&con->recovery_lock);
1250 static void amdgpu_ras_do_recovery(struct work_struct *work)
1252 struct amdgpu_ras *ras =
1253 container_of(work, struct amdgpu_ras, recovery_work);
1255 amdgpu_device_gpu_recover(ras->adev, 0);
1256 atomic_set(&ras->in_recovery, 0);
1259 static int amdgpu_ras_release_vram(struct amdgpu_device *adev,
1260 struct amdgpu_bo **bo_ptr)
1262 /* no need to free it actually. */
1263 amdgpu_bo_free_kernel(bo_ptr, NULL, NULL);
1267 /* reserve vram with size@offset */
1268 static int amdgpu_ras_reserve_vram(struct amdgpu_device *adev,
1269 uint64_t offset, uint64_t size,
1270 struct amdgpu_bo **bo_ptr)
1272 struct ttm_operation_ctx ctx = { false, false };
1273 struct amdgpu_bo_param bp;
1276 struct amdgpu_bo *bo;
1280 memset(&bp, 0, sizeof(bp));
1282 bp.byte_align = PAGE_SIZE;
1283 bp.domain = AMDGPU_GEM_DOMAIN_VRAM;
1284 bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
1285 AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
1286 bp.type = ttm_bo_type_kernel;
1289 r = amdgpu_bo_create(adev, &bp, &bo);
1293 r = amdgpu_bo_reserve(bo, false);
1297 offset = ALIGN(offset, PAGE_SIZE);
1298 for (i = 0; i < bo->placement.num_placement; ++i) {
1299 bo->placements[i].fpfn = offset >> PAGE_SHIFT;
1300 bo->placements[i].lpfn = (offset + size) >> PAGE_SHIFT;
1303 ttm_bo_mem_put(&bo->tbo, &bo->tbo.mem);
1304 r = ttm_bo_mem_space(&bo->tbo, &bo->placement, &bo->tbo.mem, &ctx);
1308 r = amdgpu_bo_pin_restricted(bo,
1309 AMDGPU_GEM_DOMAIN_VRAM,
1318 amdgpu_bo_unreserve(bo);
1322 amdgpu_bo_unreserve(bo);
1324 amdgpu_bo_unref(&bo);
1328 /* alloc/realloc bps array */
1329 static int amdgpu_ras_realloc_eh_data_space(struct amdgpu_device *adev,
1330 struct ras_err_handler_data *data, int pages)
1332 unsigned int old_space = data->count + data->space_left;
1333 unsigned int new_space = old_space + pages;
1334 unsigned int align_space = ALIGN(new_space, 512);
1335 void *bps = kmalloc(align_space * sizeof(*data->bps), GFP_KERNEL);
1336 struct amdgpu_bo **bps_bo =
1337 kmalloc(align_space * sizeof(*data->bps_bo), GFP_KERNEL);
1339 if (!bps || !bps_bo) {
1346 memcpy(bps, data->bps,
1347 data->count * sizeof(*data->bps));
1351 memcpy(bps_bo, data->bps_bo,
1352 data->count * sizeof(*data->bps_bo));
1353 kfree(data->bps_bo);
1357 data->bps_bo = bps_bo;
1358 data->space_left += align_space - old_space;
1362 /* it deal with vram only. */
1363 int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
1364 struct eeprom_table_record *bps, int pages)
1366 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1367 struct ras_err_handler_data *data;
1370 if (!con || !con->eh_data || !bps || pages <= 0)
1373 mutex_lock(&con->recovery_lock);
1374 data = con->eh_data;
1378 if (data->space_left <= pages)
1379 if (amdgpu_ras_realloc_eh_data_space(adev, data, pages)) {
1384 memcpy(&data->bps[data->count], bps, pages * sizeof(*data->bps));
1385 data->count += pages;
1386 data->space_left -= pages;
1389 mutex_unlock(&con->recovery_lock);
1395 * write error record array to eeprom, the function should be
1396 * protected by recovery_lock
1398 static int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev)
1400 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1401 struct ras_err_handler_data *data;
1402 struct amdgpu_ras_eeprom_control *control =
1403 &adev->psp.ras.ras->eeprom_control;
1406 if (!con || !con->eh_data)
1409 data = con->eh_data;
1410 save_count = data->count - control->num_recs;
1411 /* only new entries are saved */
1413 if (amdgpu_ras_eeprom_process_recods(&con->eeprom_control,
1414 &data->bps[control->num_recs],
1417 DRM_ERROR("Failed to save EEPROM table data!");
1425 * read error record array in eeprom and reserve enough space for
1426 * storing new bad pages
1428 static int amdgpu_ras_load_bad_pages(struct amdgpu_device *adev)
1430 struct amdgpu_ras_eeprom_control *control =
1431 &adev->psp.ras.ras->eeprom_control;
1432 struct eeprom_table_record *bps = NULL;
1435 /* no bad page record, skip eeprom access */
1436 if (!control->num_recs)
1439 bps = kcalloc(control->num_recs, sizeof(*bps), GFP_KERNEL);
1443 if (amdgpu_ras_eeprom_process_recods(control, bps, false,
1444 control->num_recs)) {
1445 DRM_ERROR("Failed to load EEPROM table records!");
1450 ret = amdgpu_ras_add_bad_pages(adev, bps, control->num_recs);
1457 /* called in gpu recovery/init */
1458 int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev)
1460 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1461 struct ras_err_handler_data *data;
1463 struct amdgpu_bo *bo;
1466 if (!con || !con->eh_data)
1469 mutex_lock(&con->recovery_lock);
1470 data = con->eh_data;
1473 /* reserve vram at driver post stage. */
1474 for (i = data->last_reserved; i < data->count; i++) {
1475 bp = data->bps[i].retired_page;
1477 if (amdgpu_ras_reserve_vram(adev, bp << PAGE_SHIFT,
1479 DRM_ERROR("RAS ERROR: reserve vram %llx fail\n", bp);
1481 data->bps_bo[i] = bo;
1482 data->last_reserved = i + 1;
1485 /* continue to save bad pages to eeprom even reesrve_vram fails */
1486 ret = amdgpu_ras_save_bad_pages(adev);
1488 mutex_unlock(&con->recovery_lock);
1492 /* called when driver unload */
1493 static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev)
1495 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1496 struct ras_err_handler_data *data;
1497 struct amdgpu_bo *bo;
1500 if (!con || !con->eh_data)
1503 mutex_lock(&con->recovery_lock);
1504 data = con->eh_data;
1508 for (i = data->last_reserved - 1; i >= 0; i--) {
1509 bo = data->bps_bo[i];
1511 amdgpu_ras_release_vram(adev, &bo);
1513 data->bps_bo[i] = bo;
1514 data->last_reserved = i;
1517 mutex_unlock(&con->recovery_lock);
1521 int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
1523 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1524 struct ras_err_handler_data **data;
1528 data = &con->eh_data;
1532 *data = kmalloc(sizeof(**data), GFP_KERNEL | __GFP_ZERO);
1538 mutex_init(&con->recovery_lock);
1539 INIT_WORK(&con->recovery_work, amdgpu_ras_do_recovery);
1540 atomic_set(&con->in_recovery, 0);
1543 ret = amdgpu_ras_eeprom_init(&adev->psp.ras.ras->eeprom_control);
1547 if (adev->psp.ras.ras->eeprom_control.num_recs) {
1548 ret = amdgpu_ras_load_bad_pages(adev);
1551 ret = amdgpu_ras_reserve_bad_pages(adev);
1559 amdgpu_ras_release_bad_pages(adev);
1561 con->eh_data = NULL;
1562 kfree((*data)->bps);
1563 kfree((*data)->bps_bo);
1566 DRM_WARN("Failed to initialize ras recovery!\n");
1571 static int amdgpu_ras_recovery_fini(struct amdgpu_device *adev)
1573 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1574 struct ras_err_handler_data *data = con->eh_data;
1576 /* recovery_init failed to init it, fini is useless */
1580 cancel_work_sync(&con->recovery_work);
1581 amdgpu_ras_release_bad_pages(adev);
1583 mutex_lock(&con->recovery_lock);
1584 con->eh_data = NULL;
1586 kfree(data->bps_bo);
1588 mutex_unlock(&con->recovery_lock);
1594 /* return 0 if ras will reset gpu and repost.*/
1595 int amdgpu_ras_request_reset_on_boot(struct amdgpu_device *adev,
1598 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
1603 ras->flags |= AMDGPU_RAS_FLAG_INIT_NEED_RESET;
1608 * check hardware's ras ability which will be saved in hw_supported.
1609 * if hardware does not support ras, we can skip some ras initializtion and
1610 * forbid some ras operations from IP.
1611 * if software itself, say boot parameter, limit the ras ability. We still
1612 * need allow IP do some limited operations, like disable. In such case,
1613 * we have to initialize ras as normal. but need check if operation is
1614 * allowed or not in each function.
1616 static void amdgpu_ras_check_supported(struct amdgpu_device *adev,
1617 uint32_t *hw_supported, uint32_t *supported)
1622 if (amdgpu_sriov_vf(adev) ||
1623 adev->asic_type != CHIP_VEGA20)
1626 if (adev->is_atom_fw &&
1627 (amdgpu_atomfirmware_mem_ecc_supported(adev) ||
1628 amdgpu_atomfirmware_sram_ecc_supported(adev)))
1629 *hw_supported = AMDGPU_RAS_BLOCK_MASK;
1631 *supported = amdgpu_ras_enable == 0 ?
1632 0 : *hw_supported & amdgpu_ras_mask;
1635 int amdgpu_ras_init(struct amdgpu_device *adev)
1637 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1643 con = kmalloc(sizeof(struct amdgpu_ras) +
1644 sizeof(struct ras_manager) * AMDGPU_RAS_BLOCK_COUNT,
1645 GFP_KERNEL|__GFP_ZERO);
1649 con->objs = (struct ras_manager *)(con + 1);
1651 amdgpu_ras_set_context(adev, con);
1653 amdgpu_ras_check_supported(adev, &con->hw_supported,
1655 if (!con->hw_supported) {
1656 amdgpu_ras_set_context(adev, NULL);
1662 INIT_LIST_HEAD(&con->head);
1663 /* Might need get this flag from vbios. */
1664 con->flags = RAS_DEFAULT_FLAGS;
1666 if (adev->nbio.funcs->init_ras_controller_interrupt) {
1667 r = adev->nbio.funcs->init_ras_controller_interrupt(adev);
1672 if (adev->nbio.funcs->init_ras_err_event_athub_interrupt) {
1673 r = adev->nbio.funcs->init_ras_err_event_athub_interrupt(adev);
1678 amdgpu_ras_mask &= AMDGPU_RAS_BLOCK_MASK;
1680 if (amdgpu_ras_fs_init(adev))
1683 DRM_INFO("RAS INFO: ras initialized successfully, "
1684 "hardware ability[%x] ras_mask[%x]\n",
1685 con->hw_supported, con->supported);
1688 amdgpu_ras_set_context(adev, NULL);
1694 /* helper function to handle common stuff in ip late init phase */
1695 int amdgpu_ras_late_init(struct amdgpu_device *adev,
1696 struct ras_common_if *ras_block,
1697 struct ras_fs_if *fs_info,
1698 struct ras_ih_if *ih_info)
1702 /* disable RAS feature per IP block if it is not supported */
1703 if (!amdgpu_ras_is_supported(adev, ras_block->block)) {
1704 amdgpu_ras_feature_enable_on_boot(adev, ras_block, 0);
1708 r = amdgpu_ras_feature_enable_on_boot(adev, ras_block, 1);
1711 /* request gpu reset. will run again */
1712 amdgpu_ras_request_reset_on_boot(adev,
1715 } else if (adev->in_suspend || adev->in_gpu_reset) {
1716 /* in resume phase, if fail to enable ras,
1717 * clean up all ras fs nodes, and disable ras */
1723 /* in resume phase, no need to create ras fs node */
1724 if (adev->in_suspend || adev->in_gpu_reset)
1728 r = amdgpu_ras_interrupt_add_handler(adev, ih_info);
1733 amdgpu_ras_debugfs_create(adev, fs_info);
1735 r = amdgpu_ras_sysfs_create(adev, fs_info);
1741 amdgpu_ras_sysfs_remove(adev, ras_block);
1743 amdgpu_ras_debugfs_remove(adev, ras_block);
1745 amdgpu_ras_interrupt_remove_handler(adev, ih_info);
1747 amdgpu_ras_feature_enable(adev, ras_block, 0);
1751 /* helper function to remove ras fs node and interrupt handler */
1752 void amdgpu_ras_late_fini(struct amdgpu_device *adev,
1753 struct ras_common_if *ras_block,
1754 struct ras_ih_if *ih_info)
1756 if (!ras_block || !ih_info)
1759 amdgpu_ras_sysfs_remove(adev, ras_block);
1760 amdgpu_ras_debugfs_remove(adev, ras_block);
1762 amdgpu_ras_interrupt_remove_handler(adev, ih_info);
1763 amdgpu_ras_feature_enable(adev, ras_block, 0);
1766 /* do some init work after IP late init as dependence.
1767 * and it runs in resume/gpu reset/booting up cases.
1769 void amdgpu_ras_resume(struct amdgpu_device *adev)
1771 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1772 struct ras_manager *obj, *tmp;
1777 if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
1778 /* Set up all other IPs which are not implemented. There is a
1779 * tricky thing that IP's actual ras error type should be
1780 * MULTI_UNCORRECTABLE, but as driver does not handle it, so
1781 * ERROR_NONE make sense anyway.
1783 amdgpu_ras_enable_all_features(adev, 1);
1785 /* We enable ras on all hw_supported block, but as boot
1786 * parameter might disable some of them and one or more IP has
1787 * not implemented yet. So we disable them on behalf.
1789 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1790 if (!amdgpu_ras_is_supported(adev, obj->head.block)) {
1791 amdgpu_ras_feature_enable(adev, &obj->head, 0);
1792 /* there should be no any reference. */
1793 WARN_ON(alive_obj(obj));
1798 if (con->flags & AMDGPU_RAS_FLAG_INIT_NEED_RESET) {
1799 con->flags &= ~AMDGPU_RAS_FLAG_INIT_NEED_RESET;
1800 /* setup ras obj state as disabled.
1801 * for init_by_vbios case.
1802 * if we want to enable ras, just enable it in a normal way.
1803 * If we want do disable it, need setup ras obj as enabled,
1804 * then issue another TA disable cmd.
1805 * See feature_enable_on_boot
1807 amdgpu_ras_disable_all_features(adev, 1);
1808 amdgpu_ras_reset_gpu(adev, 0);
1812 void amdgpu_ras_suspend(struct amdgpu_device *adev)
1814 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1819 amdgpu_ras_disable_all_features(adev, 0);
1820 /* Make sure all ras objects are disabled. */
1822 amdgpu_ras_disable_all_features(adev, 1);
1825 /* do some fini work before IP fini as dependence */
1826 int amdgpu_ras_pre_fini(struct amdgpu_device *adev)
1828 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1833 /* Need disable ras on all IPs here before ip [hw/sw]fini */
1834 amdgpu_ras_disable_all_features(adev, 0);
1835 amdgpu_ras_recovery_fini(adev);
1839 int amdgpu_ras_fini(struct amdgpu_device *adev)
1841 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1846 amdgpu_ras_fs_fini(adev);
1847 amdgpu_ras_interrupt_remove_all(adev);
1849 WARN(con->features, "Feature mask is not cleared");
1852 amdgpu_ras_disable_all_features(adev, 1);
1854 amdgpu_ras_set_context(adev, NULL);
1860 void amdgpu_ras_global_ras_isr(struct amdgpu_device *adev)
1862 if (atomic_cmpxchg(&amdgpu_ras_in_intr, 0, 1) == 0) {
1863 DRM_WARN("RAS event of type ERREVENT_ATHUB_INTERRUPT detected!\n");
1865 amdgpu_ras_reset_gpu(adev, false);