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)
71 enum amdgpu_ras_retire_page_reservation {
72 AMDGPU_RAS_RETIRE_PAGE_RESERVED,
73 AMDGPU_RAS_RETIRE_PAGE_PENDING,
74 AMDGPU_RAS_RETIRE_PAGE_FAULT,
77 atomic_t amdgpu_ras_in_intr = ATOMIC_INIT(0);
79 static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
82 static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,
83 size_t size, loff_t *pos)
85 struct ras_manager *obj = (struct ras_manager *)file_inode(f)->i_private;
86 struct ras_query_if info = {
92 if (amdgpu_ras_error_query(obj->adev, &info))
95 s = snprintf(val, sizeof(val), "%s: %lu\n%s: %lu\n",
102 s = min_t(u64, s, size);
105 if (copy_to_user(buf, &val[*pos], s))
113 static const struct file_operations amdgpu_ras_debugfs_ops = {
114 .owner = THIS_MODULE,
115 .read = amdgpu_ras_debugfs_read,
117 .llseek = default_llseek
120 static int amdgpu_ras_find_block_id_by_name(const char *name, int *block_id)
124 for (i = 0; i < ARRAY_SIZE(ras_block_string); i++) {
126 if (strcmp(name, ras_block_str(i)) == 0)
132 static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
133 const char __user *buf, size_t size,
134 loff_t *pos, struct ras_debug_if *data)
136 ssize_t s = min_t(u64, 64, size);
149 memset(str, 0, sizeof(str));
150 memset(data, 0, sizeof(*data));
152 if (copy_from_user(str, buf, s))
155 if (sscanf(str, "disable %32s", block_name) == 1)
157 else if (sscanf(str, "enable %32s %8s", block_name, err) == 2)
159 else if (sscanf(str, "inject %32s %8s", block_name, err) == 2)
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.
226 * - 0: disable RAS on the block. Take ::head as its data.
227 * - 1: enable RAS on the block. Take ::head as its data.
228 * - 2: inject errors on the block. Take ::inject as its data.
230 * How to use the interface?
232 * copy the struct ras_debug_if in your codes and initialize it.
233 * write the struct to the control node.
235 * .. code-block:: bash
237 * echo op block [error [sub_block address value]] > .../ras/ras_ctrl
239 * op: disable, enable, inject
240 * disable: only block is needed
241 * enable: block and error are needed
242 * inject: error, address, value are needed
243 * block: umc, sdma, gfx, .........
244 * see ras_block_string[] for details
246 * ue: multi_uncorrectable
247 * ce: single_correctable
249 * sub block index, pass 0 if there is no sub block
251 * here are some examples for bash commands:
253 * .. code-block:: bash
255 * echo inject umc ue 0x0 0x0 0x0 > /sys/kernel/debug/dri/0/ras/ras_ctrl
256 * echo inject umc ce 0 0 0 > /sys/kernel/debug/dri/0/ras/ras_ctrl
257 * echo disable umc > /sys/kernel/debug/dri/0/ras/ras_ctrl
259 * How to check the result?
261 * For disable/enable, please check ras features at
262 * /sys/class/drm/card[0/1/2...]/device/ras/features
264 * For inject, please check corresponding err count at
265 * /sys/class/drm/card[0/1/2...]/device/ras/[gfx/sdma/...]_err_count
268 * Operation is only allowed on blocks which are supported.
269 * Please check ras mask at /sys/module/amdgpu/parameters/ras_mask
271 static ssize_t amdgpu_ras_debugfs_ctrl_write(struct file *f, const char __user *buf,
272 size_t size, loff_t *pos)
274 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
275 struct ras_debug_if data;
278 ret = amdgpu_ras_debugfs_ctrl_parse_data(f, buf, size, pos, &data);
282 if (!amdgpu_ras_is_supported(adev, data.head.block))
287 ret = amdgpu_ras_feature_enable(adev, &data.head, 0);
290 ret = amdgpu_ras_feature_enable(adev, &data.head, 1);
293 if ((data.inject.address >= adev->gmc.mc_vram_size) ||
294 (data.inject.address >= RAS_UMC_INJECT_ADDR_LIMIT)) {
299 /* umc ce/ue error injection for a bad page is not allowed */
300 if ((data.head.block == AMDGPU_RAS_BLOCK__UMC) &&
301 amdgpu_ras_check_bad_page(adev, data.inject.address)) {
302 DRM_WARN("RAS WARN: 0x%llx has been marked as bad before error injection!\n",
303 data.inject.address);
307 /* data.inject.address is offset instead of absolute gpu address */
308 ret = amdgpu_ras_error_inject(adev, &data.inject);
322 * DOC: AMDGPU RAS debugfs EEPROM table reset interface
324 * Some boards contain an EEPROM which is used to persistently store a list of
325 * bad pages containing ECC errors detected in vram. This interface provides
326 * a way to reset the EEPROM, e.g., after testing error injection.
330 * .. code-block:: bash
332 * echo 1 > ../ras/ras_eeprom_reset
334 * will reset EEPROM table to 0 entries.
337 static ssize_t amdgpu_ras_debugfs_eeprom_write(struct file *f, const char __user *buf,
338 size_t size, loff_t *pos)
340 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
343 ret = amdgpu_ras_eeprom_reset_table(&adev->psp.ras.ras->eeprom_control);
345 return ret == 1 ? size : -EIO;
348 static const struct file_operations amdgpu_ras_debugfs_ctrl_ops = {
349 .owner = THIS_MODULE,
351 .write = amdgpu_ras_debugfs_ctrl_write,
352 .llseek = default_llseek
355 static const struct file_operations amdgpu_ras_debugfs_eeprom_ops = {
356 .owner = THIS_MODULE,
358 .write = amdgpu_ras_debugfs_eeprom_write,
359 .llseek = default_llseek
363 * DOC: AMDGPU RAS sysfs Error Count Interface
365 * It allows user to read the error count for each IP block on the gpu through
366 * /sys/class/drm/card[0/1/2...]/device/ras/[gfx/sdma/...]_err_count
368 * It outputs the multiple lines which report the uncorrected (ue) and corrected
371 * The format of one line is below,
377 * .. code-block:: bash
383 static ssize_t amdgpu_ras_sysfs_read(struct device *dev,
384 struct device_attribute *attr, char *buf)
386 struct ras_manager *obj = container_of(attr, struct ras_manager, sysfs_attr);
387 struct ras_query_if info = {
391 if (amdgpu_ras_error_query(obj->adev, &info))
394 return snprintf(buf, PAGE_SIZE, "%s: %lu\n%s: %lu\n",
396 "ce", info.ce_count);
401 #define get_obj(obj) do { (obj)->use++; } while (0)
402 #define alive_obj(obj) ((obj)->use)
404 static inline void put_obj(struct ras_manager *obj)
406 if (obj && --obj->use == 0)
407 list_del(&obj->node);
408 if (obj && obj->use < 0) {
409 DRM_ERROR("RAS ERROR: Unbalance obj(%s) use\n", obj->head.name);
413 /* make one obj and return it. */
414 static struct ras_manager *amdgpu_ras_create_obj(struct amdgpu_device *adev,
415 struct ras_common_if *head)
417 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
418 struct ras_manager *obj;
423 if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
426 obj = &con->objs[head->block];
427 /* already exist. return obj? */
433 list_add(&obj->node, &con->head);
439 /* return an obj equal to head, or the first when head is NULL */
440 static struct ras_manager *amdgpu_ras_find_obj(struct amdgpu_device *adev,
441 struct ras_common_if *head)
443 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
444 struct ras_manager *obj;
451 if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
454 obj = &con->objs[head->block];
456 if (alive_obj(obj)) {
457 WARN_ON(head->block != obj->head.block);
461 for (i = 0; i < AMDGPU_RAS_BLOCK_COUNT; i++) {
463 if (alive_obj(obj)) {
464 WARN_ON(i != obj->head.block);
474 /* feature ctl begin */
475 static int amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
476 struct ras_common_if *head)
478 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
480 return con->hw_supported & BIT(head->block);
483 static int amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
484 struct ras_common_if *head)
486 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
488 return con->features & BIT(head->block);
492 * if obj is not created, then create one.
493 * set feature enable flag.
495 static int __amdgpu_ras_feature_enable(struct amdgpu_device *adev,
496 struct ras_common_if *head, int enable)
498 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
499 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
501 /* If hardware does not support ras, then do not create obj.
502 * But if hardware support ras, we can create the obj.
503 * Ras framework checks con->hw_supported to see if it need do
504 * corresponding initialization.
505 * IP checks con->support to see if it need disable ras.
507 if (!amdgpu_ras_is_feature_allowed(adev, head))
509 if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
514 obj = amdgpu_ras_create_obj(adev, head);
518 /* In case we create obj somewhere else */
521 con->features |= BIT(head->block);
523 if (obj && amdgpu_ras_is_feature_enabled(adev, head)) {
524 con->features &= ~BIT(head->block);
532 /* wrapper of psp_ras_enable_features */
533 int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
534 struct ras_common_if *head, bool enable)
536 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
537 union ta_ras_cmd_input info;
544 info.disable_features = (struct ta_ras_disable_features_input) {
545 .block_id = amdgpu_ras_block_to_ta(head->block),
546 .error_type = amdgpu_ras_error_to_ta(head->type),
549 info.enable_features = (struct ta_ras_enable_features_input) {
550 .block_id = amdgpu_ras_block_to_ta(head->block),
551 .error_type = amdgpu_ras_error_to_ta(head->type),
555 /* Do not enable if it is not allowed. */
556 WARN_ON(enable && !amdgpu_ras_is_feature_allowed(adev, head));
557 /* Are we alerady in that state we are going to set? */
558 if (!(!!enable ^ !!amdgpu_ras_is_feature_enabled(adev, head)))
561 if (!amdgpu_ras_intr_triggered()) {
562 ret = psp_ras_enable_features(&adev->psp, &info, enable);
564 DRM_ERROR("RAS ERROR: %s %s feature failed ret %d\n",
565 enable ? "enable":"disable",
566 ras_block_str(head->block),
568 if (ret == TA_RAS_STATUS__RESET_NEEDED)
575 __amdgpu_ras_feature_enable(adev, head, enable);
580 /* Only used in device probe stage and called only once. */
581 int amdgpu_ras_feature_enable_on_boot(struct amdgpu_device *adev,
582 struct ras_common_if *head, bool enable)
584 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
590 if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
592 /* There is no harm to issue a ras TA cmd regardless of
593 * the currecnt ras state.
594 * If current state == target state, it will do nothing
595 * But sometimes it requests driver to reset and repost
596 * with error code -EAGAIN.
598 ret = amdgpu_ras_feature_enable(adev, head, 1);
599 /* With old ras TA, we might fail to enable ras.
600 * Log it and just setup the object.
601 * TODO need remove this WA in the future.
603 if (ret == -EINVAL) {
604 ret = __amdgpu_ras_feature_enable(adev, head, 1);
606 DRM_INFO("RAS INFO: %s setup object\n",
607 ras_block_str(head->block));
610 /* setup the object then issue a ras TA disable cmd.*/
611 ret = __amdgpu_ras_feature_enable(adev, head, 1);
615 ret = amdgpu_ras_feature_enable(adev, head, 0);
618 ret = amdgpu_ras_feature_enable(adev, head, enable);
623 static int amdgpu_ras_disable_all_features(struct amdgpu_device *adev,
626 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
627 struct ras_manager *obj, *tmp;
629 list_for_each_entry_safe(obj, tmp, &con->head, node) {
631 * aka just release the obj and corresponding flags
634 if (__amdgpu_ras_feature_enable(adev, &obj->head, 0))
637 if (amdgpu_ras_feature_enable(adev, &obj->head, 0))
642 return con->features;
645 static int amdgpu_ras_enable_all_features(struct amdgpu_device *adev,
648 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
649 int ras_block_count = AMDGPU_RAS_BLOCK_COUNT;
651 const enum amdgpu_ras_error_type default_ras_type =
652 AMDGPU_RAS_ERROR__NONE;
654 for (i = 0; i < ras_block_count; i++) {
655 struct ras_common_if head = {
657 .type = default_ras_type,
658 .sub_block_index = 0,
660 strcpy(head.name, ras_block_str(i));
663 * bypass psp. vbios enable ras for us.
664 * so just create the obj
666 if (__amdgpu_ras_feature_enable(adev, &head, 1))
669 if (amdgpu_ras_feature_enable(adev, &head, 1))
674 return con->features;
676 /* feature ctl end */
678 /* query/inject/cure begin */
679 int amdgpu_ras_error_query(struct amdgpu_device *adev,
680 struct ras_query_if *info)
682 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
683 struct ras_err_data err_data = {0, 0, 0, NULL};
688 switch (info->head.block) {
689 case AMDGPU_RAS_BLOCK__UMC:
690 if (adev->umc.funcs->query_ras_error_count)
691 adev->umc.funcs->query_ras_error_count(adev, &err_data);
692 /* umc query_ras_error_address is also responsible for clearing
695 if (adev->umc.funcs->query_ras_error_address)
696 adev->umc.funcs->query_ras_error_address(adev, &err_data);
698 case AMDGPU_RAS_BLOCK__GFX:
699 if (adev->gfx.funcs->query_ras_error_count)
700 adev->gfx.funcs->query_ras_error_count(adev, &err_data);
702 case AMDGPU_RAS_BLOCK__MMHUB:
703 if (adev->mmhub.funcs->query_ras_error_count)
704 adev->mmhub.funcs->query_ras_error_count(adev, &err_data);
706 case AMDGPU_RAS_BLOCK__PCIE_BIF:
707 if (adev->nbio.funcs->query_ras_error_count)
708 adev->nbio.funcs->query_ras_error_count(adev, &err_data);
714 obj->err_data.ue_count += err_data.ue_count;
715 obj->err_data.ce_count += err_data.ce_count;
717 info->ue_count = obj->err_data.ue_count;
718 info->ce_count = obj->err_data.ce_count;
720 if (err_data.ce_count) {
721 dev_info(adev->dev, "%ld correctable errors detected in %s block\n",
722 obj->err_data.ce_count, ras_block_str(info->head.block));
724 if (err_data.ue_count) {
725 dev_info(adev->dev, "%ld uncorrectable errors detected in %s block\n",
726 obj->err_data.ue_count, ras_block_str(info->head.block));
732 /* wrapper of psp_ras_trigger_error */
733 int amdgpu_ras_error_inject(struct amdgpu_device *adev,
734 struct ras_inject_if *info)
736 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
737 struct ta_ras_trigger_error_input block_info = {
738 .block_id = amdgpu_ras_block_to_ta(info->head.block),
739 .inject_error_type = amdgpu_ras_error_to_ta(info->head.type),
740 .sub_block_index = info->head.sub_block_index,
741 .address = info->address,
742 .value = info->value,
749 switch (info->head.block) {
750 case AMDGPU_RAS_BLOCK__GFX:
751 if (adev->gfx.funcs->ras_error_inject)
752 ret = adev->gfx.funcs->ras_error_inject(adev, info);
756 case AMDGPU_RAS_BLOCK__UMC:
757 case AMDGPU_RAS_BLOCK__MMHUB:
758 case AMDGPU_RAS_BLOCK__XGMI_WAFL:
759 case AMDGPU_RAS_BLOCK__PCIE_BIF:
760 ret = psp_ras_trigger_error(&adev->psp, &block_info);
763 DRM_INFO("%s error injection is not supported yet\n",
764 ras_block_str(info->head.block));
769 DRM_ERROR("RAS ERROR: inject %s error failed ret %d\n",
770 ras_block_str(info->head.block),
776 int amdgpu_ras_error_cure(struct amdgpu_device *adev,
777 struct ras_cure_if *info)
779 /* psp fw has no cure interface for now. */
783 /* get the total error counts on all IPs */
784 unsigned long amdgpu_ras_query_error_count(struct amdgpu_device *adev,
787 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
788 struct ras_manager *obj;
789 struct ras_err_data data = {0, 0};
794 list_for_each_entry(obj, &con->head, node) {
795 struct ras_query_if info = {
799 if (amdgpu_ras_error_query(adev, &info))
802 data.ce_count += info.ce_count;
803 data.ue_count += info.ue_count;
806 return is_ce ? data.ce_count : data.ue_count;
808 /* query/inject/cure end */
813 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
814 struct ras_badpage **bps, unsigned int *count);
816 static char *amdgpu_ras_badpage_flags_str(unsigned int flags)
819 case AMDGPU_RAS_RETIRE_PAGE_RESERVED:
821 case AMDGPU_RAS_RETIRE_PAGE_PENDING:
823 case AMDGPU_RAS_RETIRE_PAGE_FAULT:
830 * DOC: AMDGPU RAS sysfs gpu_vram_bad_pages Interface
832 * It allows user to read the bad pages of vram on the gpu through
833 * /sys/class/drm/card[0/1/2...]/device/ras/gpu_vram_bad_pages
835 * It outputs multiple lines, and each line stands for one gpu page.
837 * The format of one line is below,
838 * gpu pfn : gpu page size : flags
840 * gpu pfn and gpu page size are printed in hex format.
841 * flags can be one of below character,
843 * R: reserved, this gpu page is reserved and not able to use.
845 * P: pending for reserve, this gpu page is marked as bad, will be reserved
846 * in next window of page_reserve.
848 * F: unable to reserve. this gpu page can't be reserved due to some reasons.
852 * .. code-block:: bash
854 * 0x00000001 : 0x00001000 : R
855 * 0x00000002 : 0x00001000 : P
859 static ssize_t amdgpu_ras_sysfs_badpages_read(struct file *f,
860 struct kobject *kobj, struct bin_attribute *attr,
861 char *buf, loff_t ppos, size_t count)
863 struct amdgpu_ras *con =
864 container_of(attr, struct amdgpu_ras, badpages_attr);
865 struct amdgpu_device *adev = con->adev;
866 const unsigned int element_size =
867 sizeof("0xabcdabcd : 0x12345678 : R\n") - 1;
868 unsigned int start = div64_ul(ppos + element_size - 1, element_size);
869 unsigned int end = div64_ul(ppos + count - 1, element_size);
871 struct ras_badpage *bps = NULL;
872 unsigned int bps_count = 0;
874 memset(buf, 0, count);
876 if (amdgpu_ras_badpages_read(adev, &bps, &bps_count))
879 for (; start < end && start < bps_count; start++)
880 s += scnprintf(&buf[s], element_size + 1,
881 "0x%08x : 0x%08x : %1s\n",
884 amdgpu_ras_badpage_flags_str(bps[start].flags));
891 static ssize_t amdgpu_ras_sysfs_features_read(struct device *dev,
892 struct device_attribute *attr, char *buf)
894 struct amdgpu_ras *con =
895 container_of(attr, struct amdgpu_ras, features_attr);
897 return scnprintf(buf, PAGE_SIZE, "feature mask: 0x%x\n", con->features);
900 static int amdgpu_ras_sysfs_create_feature_node(struct amdgpu_device *adev)
902 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
903 struct attribute *attrs[] = {
904 &con->features_attr.attr,
907 struct bin_attribute *bin_attrs[] = {
911 struct attribute_group group = {
914 .bin_attrs = bin_attrs,
917 con->features_attr = (struct device_attribute) {
922 .show = amdgpu_ras_sysfs_features_read,
925 con->badpages_attr = (struct bin_attribute) {
927 .name = "gpu_vram_bad_pages",
932 .read = amdgpu_ras_sysfs_badpages_read,
935 sysfs_attr_init(attrs[0]);
936 sysfs_bin_attr_init(bin_attrs[0]);
938 return sysfs_create_group(&adev->dev->kobj, &group);
941 static int amdgpu_ras_sysfs_remove_feature_node(struct amdgpu_device *adev)
943 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
944 struct attribute *attrs[] = {
945 &con->features_attr.attr,
948 struct bin_attribute *bin_attrs[] = {
952 struct attribute_group group = {
955 .bin_attrs = bin_attrs,
958 sysfs_remove_group(&adev->dev->kobj, &group);
963 int amdgpu_ras_sysfs_create(struct amdgpu_device *adev,
964 struct ras_fs_if *head)
966 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &head->head);
968 if (!obj || obj->attr_inuse)
973 memcpy(obj->fs_data.sysfs_name,
975 sizeof(obj->fs_data.sysfs_name));
977 obj->sysfs_attr = (struct device_attribute){
979 .name = obj->fs_data.sysfs_name,
982 .show = amdgpu_ras_sysfs_read,
984 sysfs_attr_init(&obj->sysfs_attr.attr);
986 if (sysfs_add_file_to_group(&adev->dev->kobj,
987 &obj->sysfs_attr.attr,
998 int amdgpu_ras_sysfs_remove(struct amdgpu_device *adev,
999 struct ras_common_if *head)
1001 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1003 if (!obj || !obj->attr_inuse)
1006 sysfs_remove_file_from_group(&adev->dev->kobj,
1007 &obj->sysfs_attr.attr,
1009 obj->attr_inuse = 0;
1015 static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
1017 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1018 struct ras_manager *obj, *tmp;
1020 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1021 amdgpu_ras_sysfs_remove(adev, &obj->head);
1024 amdgpu_ras_sysfs_remove_feature_node(adev);
1031 static void amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *adev)
1033 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1034 struct drm_minor *minor = adev->ddev->primary;
1036 con->dir = debugfs_create_dir("ras", minor->debugfs_root);
1037 debugfs_create_file("ras_ctrl", S_IWUGO | S_IRUGO, con->dir,
1038 adev, &amdgpu_ras_debugfs_ctrl_ops);
1039 debugfs_create_file("ras_eeprom_reset", S_IWUGO | S_IRUGO, con->dir,
1040 adev, &amdgpu_ras_debugfs_eeprom_ops);
1043 * After one uncorrectable error happens, usually GPU recovery will
1044 * be scheduled. But due to the known problem in GPU recovery failing
1045 * to bring GPU back, below interface provides one direct way to
1046 * user to reboot system automatically in such case within
1047 * ERREVENT_ATHUB_INTERRUPT generated. Normal GPU recovery routine
1048 * will never be called.
1050 debugfs_create_bool("auto_reboot", S_IWUGO | S_IRUGO, con->dir,
1054 void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
1055 struct ras_fs_if *head)
1057 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1058 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &head->head);
1060 if (!obj || obj->ent)
1065 memcpy(obj->fs_data.debugfs_name,
1067 sizeof(obj->fs_data.debugfs_name));
1069 obj->ent = debugfs_create_file(obj->fs_data.debugfs_name,
1070 S_IWUGO | S_IRUGO, con->dir, obj,
1071 &amdgpu_ras_debugfs_ops);
1074 void amdgpu_ras_debugfs_remove(struct amdgpu_device *adev,
1075 struct ras_common_if *head)
1077 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1079 if (!obj || !obj->ent)
1082 debugfs_remove(obj->ent);
1087 static void amdgpu_ras_debugfs_remove_all(struct amdgpu_device *adev)
1089 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1090 struct ras_manager *obj, *tmp;
1092 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1093 amdgpu_ras_debugfs_remove(adev, &obj->head);
1096 debugfs_remove_recursive(con->dir);
1103 static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
1105 amdgpu_ras_sysfs_create_feature_node(adev);
1106 amdgpu_ras_debugfs_create_ctrl_node(adev);
1111 static int amdgpu_ras_fs_fini(struct amdgpu_device *adev)
1113 amdgpu_ras_debugfs_remove_all(adev);
1114 amdgpu_ras_sysfs_remove_all(adev);
1120 static void amdgpu_ras_interrupt_handler(struct ras_manager *obj)
1122 struct ras_ih_data *data = &obj->ih_data;
1123 struct amdgpu_iv_entry entry;
1125 struct ras_err_data err_data = {0, 0, 0, NULL};
1127 while (data->rptr != data->wptr) {
1129 memcpy(&entry, &data->ring[data->rptr],
1130 data->element_size);
1133 data->rptr = (data->aligned_element_size +
1134 data->rptr) % data->ring_size;
1136 /* Let IP handle its data, maybe we need get the output
1137 * from the callback to udpate the error type/count, etc
1140 ret = data->cb(obj->adev, &err_data, &entry);
1141 /* ue will trigger an interrupt, and in that case
1142 * we need do a reset to recovery the whole system.
1143 * But leave IP do that recovery, here we just dispatch
1146 if (ret == AMDGPU_RAS_SUCCESS) {
1147 /* these counts could be left as 0 if
1148 * some blocks do not count error number
1150 obj->err_data.ue_count += err_data.ue_count;
1151 obj->err_data.ce_count += err_data.ce_count;
1157 static void amdgpu_ras_interrupt_process_handler(struct work_struct *work)
1159 struct ras_ih_data *data =
1160 container_of(work, struct ras_ih_data, ih_work);
1161 struct ras_manager *obj =
1162 container_of(data, struct ras_manager, ih_data);
1164 amdgpu_ras_interrupt_handler(obj);
1167 int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev,
1168 struct ras_dispatch_if *info)
1170 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1171 struct ras_ih_data *data = &obj->ih_data;
1176 if (data->inuse == 0)
1179 /* Might be overflow... */
1180 memcpy(&data->ring[data->wptr], info->entry,
1181 data->element_size);
1184 data->wptr = (data->aligned_element_size +
1185 data->wptr) % data->ring_size;
1187 schedule_work(&data->ih_work);
1192 int amdgpu_ras_interrupt_remove_handler(struct amdgpu_device *adev,
1193 struct ras_ih_if *info)
1195 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1196 struct ras_ih_data *data;
1201 data = &obj->ih_data;
1202 if (data->inuse == 0)
1205 cancel_work_sync(&data->ih_work);
1208 memset(data, 0, sizeof(*data));
1214 int amdgpu_ras_interrupt_add_handler(struct amdgpu_device *adev,
1215 struct ras_ih_if *info)
1217 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1218 struct ras_ih_data *data;
1221 /* in case we registe the IH before enable ras feature */
1222 obj = amdgpu_ras_create_obj(adev, &info->head);
1228 data = &obj->ih_data;
1229 /* add the callback.etc */
1230 *data = (struct ras_ih_data) {
1233 .element_size = sizeof(struct amdgpu_iv_entry),
1238 INIT_WORK(&data->ih_work, amdgpu_ras_interrupt_process_handler);
1240 data->aligned_element_size = ALIGN(data->element_size, 8);
1241 /* the ring can store 64 iv entries. */
1242 data->ring_size = 64 * data->aligned_element_size;
1243 data->ring = kmalloc(data->ring_size, GFP_KERNEL);
1255 static int amdgpu_ras_interrupt_remove_all(struct amdgpu_device *adev)
1257 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1258 struct ras_manager *obj, *tmp;
1260 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1261 struct ras_ih_if info = {
1264 amdgpu_ras_interrupt_remove_handler(adev, &info);
1271 /* recovery begin */
1273 /* return 0 on success.
1274 * caller need free bps.
1276 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
1277 struct ras_badpage **bps, unsigned int *count)
1279 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1280 struct ras_err_handler_data *data;
1284 if (!con || !con->eh_data || !bps || !count)
1287 mutex_lock(&con->recovery_lock);
1288 data = con->eh_data;
1289 if (!data || data->count == 0) {
1294 *bps = kmalloc(sizeof(struct ras_badpage) * data->count, GFP_KERNEL);
1300 for (; i < data->count; i++) {
1301 (*bps)[i] = (struct ras_badpage){
1302 .bp = data->bps[i].retired_page,
1303 .size = AMDGPU_GPU_PAGE_SIZE,
1304 .flags = AMDGPU_RAS_RETIRE_PAGE_RESERVED,
1307 if (data->last_reserved <= i)
1308 (*bps)[i].flags = AMDGPU_RAS_RETIRE_PAGE_PENDING;
1309 else if (data->bps_bo[i] == NULL)
1310 (*bps)[i].flags = AMDGPU_RAS_RETIRE_PAGE_FAULT;
1313 *count = data->count;
1315 mutex_unlock(&con->recovery_lock);
1319 static void amdgpu_ras_do_recovery(struct work_struct *work)
1321 struct amdgpu_ras *ras =
1322 container_of(work, struct amdgpu_ras, recovery_work);
1324 amdgpu_device_gpu_recover(ras->adev, 0);
1325 atomic_set(&ras->in_recovery, 0);
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;
1405 if (!con || !con->eh_data)
1408 control = &con->eeprom_control;
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(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);
1458 * check if an address belongs to bad page
1460 * Note: this check is only for umc block
1462 static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
1465 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1466 struct ras_err_handler_data *data;
1470 if (!con || !con->eh_data)
1473 mutex_lock(&con->recovery_lock);
1474 data = con->eh_data;
1478 addr >>= AMDGPU_GPU_PAGE_SHIFT;
1479 for (i = 0; i < data->count; i++)
1480 if (addr == data->bps[i].retired_page) {
1486 mutex_unlock(&con->recovery_lock);
1490 /* called in gpu recovery/init */
1491 int amdgpu_ras_reserve_bad_pages(struct amdgpu_device *adev)
1493 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1494 struct ras_err_handler_data *data;
1496 struct amdgpu_bo *bo = NULL;
1499 if (!con || !con->eh_data)
1502 mutex_lock(&con->recovery_lock);
1503 data = con->eh_data;
1506 /* reserve vram at driver post stage. */
1507 for (i = data->last_reserved; i < data->count; i++) {
1508 bp = data->bps[i].retired_page;
1510 /* There are two cases of reserve error should be ignored:
1511 * 1) a ras bad page has been allocated (used by someone);
1512 * 2) a ras bad page has been reserved (duplicate error injection
1515 if (amdgpu_bo_create_kernel_at(adev, bp << AMDGPU_GPU_PAGE_SHIFT,
1516 AMDGPU_GPU_PAGE_SIZE,
1517 AMDGPU_GEM_DOMAIN_VRAM,
1519 DRM_WARN("RAS WARN: reserve vram for retired page %llx fail\n", bp);
1521 data->bps_bo[i] = bo;
1522 data->last_reserved = i + 1;
1526 /* continue to save bad pages to eeprom even reesrve_vram fails */
1527 ret = amdgpu_ras_save_bad_pages(adev);
1529 mutex_unlock(&con->recovery_lock);
1533 /* called when driver unload */
1534 static int amdgpu_ras_release_bad_pages(struct amdgpu_device *adev)
1536 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1537 struct ras_err_handler_data *data;
1538 struct amdgpu_bo *bo;
1541 if (!con || !con->eh_data)
1544 mutex_lock(&con->recovery_lock);
1545 data = con->eh_data;
1549 for (i = data->last_reserved - 1; i >= 0; i--) {
1550 bo = data->bps_bo[i];
1552 amdgpu_bo_free_kernel(&bo, NULL, NULL);
1554 data->bps_bo[i] = bo;
1555 data->last_reserved = i;
1558 mutex_unlock(&con->recovery_lock);
1562 int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
1564 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1565 struct ras_err_handler_data **data;
1569 data = &con->eh_data;
1573 *data = kmalloc(sizeof(**data), GFP_KERNEL | __GFP_ZERO);
1579 mutex_init(&con->recovery_lock);
1580 INIT_WORK(&con->recovery_work, amdgpu_ras_do_recovery);
1581 atomic_set(&con->in_recovery, 0);
1584 ret = amdgpu_ras_eeprom_init(&con->eeprom_control);
1588 if (con->eeprom_control.num_recs) {
1589 ret = amdgpu_ras_load_bad_pages(adev);
1592 ret = amdgpu_ras_reserve_bad_pages(adev);
1600 amdgpu_ras_release_bad_pages(adev);
1602 kfree((*data)->bps);
1603 kfree((*data)->bps_bo);
1605 con->eh_data = NULL;
1607 DRM_WARN("Failed to initialize ras recovery!\n");
1612 static int amdgpu_ras_recovery_fini(struct amdgpu_device *adev)
1614 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1615 struct ras_err_handler_data *data = con->eh_data;
1617 /* recovery_init failed to init it, fini is useless */
1621 cancel_work_sync(&con->recovery_work);
1622 amdgpu_ras_release_bad_pages(adev);
1624 mutex_lock(&con->recovery_lock);
1625 con->eh_data = NULL;
1627 kfree(data->bps_bo);
1629 mutex_unlock(&con->recovery_lock);
1635 /* return 0 if ras will reset gpu and repost.*/
1636 int amdgpu_ras_request_reset_on_boot(struct amdgpu_device *adev,
1639 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
1644 ras->flags |= AMDGPU_RAS_FLAG_INIT_NEED_RESET;
1649 * check hardware's ras ability which will be saved in hw_supported.
1650 * if hardware does not support ras, we can skip some ras initializtion and
1651 * forbid some ras operations from IP.
1652 * if software itself, say boot parameter, limit the ras ability. We still
1653 * need allow IP do some limited operations, like disable. In such case,
1654 * we have to initialize ras as normal. but need check if operation is
1655 * allowed or not in each function.
1657 static void amdgpu_ras_check_supported(struct amdgpu_device *adev,
1658 uint32_t *hw_supported, uint32_t *supported)
1663 if (amdgpu_sriov_vf(adev) ||
1664 adev->asic_type != CHIP_VEGA20)
1667 if (adev->is_atom_fw &&
1668 (amdgpu_atomfirmware_mem_ecc_supported(adev) ||
1669 amdgpu_atomfirmware_sram_ecc_supported(adev)))
1670 *hw_supported = AMDGPU_RAS_BLOCK_MASK;
1672 *supported = amdgpu_ras_enable == 0 ?
1673 0 : *hw_supported & amdgpu_ras_mask;
1676 int amdgpu_ras_init(struct amdgpu_device *adev)
1678 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1684 con = kmalloc(sizeof(struct amdgpu_ras) +
1685 sizeof(struct ras_manager) * AMDGPU_RAS_BLOCK_COUNT,
1686 GFP_KERNEL|__GFP_ZERO);
1690 con->objs = (struct ras_manager *)(con + 1);
1692 amdgpu_ras_set_context(adev, con);
1694 amdgpu_ras_check_supported(adev, &con->hw_supported,
1696 if (!con->hw_supported) {
1697 amdgpu_ras_set_context(adev, NULL);
1703 INIT_LIST_HEAD(&con->head);
1704 /* Might need get this flag from vbios. */
1705 con->flags = RAS_DEFAULT_FLAGS;
1707 if (adev->nbio.funcs->init_ras_controller_interrupt) {
1708 r = adev->nbio.funcs->init_ras_controller_interrupt(adev);
1713 if (adev->nbio.funcs->init_ras_err_event_athub_interrupt) {
1714 r = adev->nbio.funcs->init_ras_err_event_athub_interrupt(adev);
1719 amdgpu_ras_mask &= AMDGPU_RAS_BLOCK_MASK;
1721 if (amdgpu_ras_fs_init(adev))
1724 DRM_INFO("RAS INFO: ras initialized successfully, "
1725 "hardware ability[%x] ras_mask[%x]\n",
1726 con->hw_supported, con->supported);
1729 amdgpu_ras_set_context(adev, NULL);
1735 /* helper function to handle common stuff in ip late init phase */
1736 int amdgpu_ras_late_init(struct amdgpu_device *adev,
1737 struct ras_common_if *ras_block,
1738 struct ras_fs_if *fs_info,
1739 struct ras_ih_if *ih_info)
1743 /* disable RAS feature per IP block if it is not supported */
1744 if (!amdgpu_ras_is_supported(adev, ras_block->block)) {
1745 amdgpu_ras_feature_enable_on_boot(adev, ras_block, 0);
1749 r = amdgpu_ras_feature_enable_on_boot(adev, ras_block, 1);
1752 /* request gpu reset. will run again */
1753 amdgpu_ras_request_reset_on_boot(adev,
1756 } else if (adev->in_suspend || adev->in_gpu_reset) {
1757 /* in resume phase, if fail to enable ras,
1758 * clean up all ras fs nodes, and disable ras */
1764 /* in resume phase, no need to create ras fs node */
1765 if (adev->in_suspend || adev->in_gpu_reset)
1769 r = amdgpu_ras_interrupt_add_handler(adev, ih_info);
1774 amdgpu_ras_debugfs_create(adev, fs_info);
1776 r = amdgpu_ras_sysfs_create(adev, fs_info);
1782 amdgpu_ras_sysfs_remove(adev, ras_block);
1784 amdgpu_ras_debugfs_remove(adev, ras_block);
1786 amdgpu_ras_interrupt_remove_handler(adev, ih_info);
1788 amdgpu_ras_feature_enable(adev, ras_block, 0);
1792 /* helper function to remove ras fs node and interrupt handler */
1793 void amdgpu_ras_late_fini(struct amdgpu_device *adev,
1794 struct ras_common_if *ras_block,
1795 struct ras_ih_if *ih_info)
1797 if (!ras_block || !ih_info)
1800 amdgpu_ras_sysfs_remove(adev, ras_block);
1801 amdgpu_ras_debugfs_remove(adev, ras_block);
1803 amdgpu_ras_interrupt_remove_handler(adev, ih_info);
1804 amdgpu_ras_feature_enable(adev, ras_block, 0);
1807 /* do some init work after IP late init as dependence.
1808 * and it runs in resume/gpu reset/booting up cases.
1810 void amdgpu_ras_resume(struct amdgpu_device *adev)
1812 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1813 struct ras_manager *obj, *tmp;
1818 if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
1819 /* Set up all other IPs which are not implemented. There is a
1820 * tricky thing that IP's actual ras error type should be
1821 * MULTI_UNCORRECTABLE, but as driver does not handle it, so
1822 * ERROR_NONE make sense anyway.
1824 amdgpu_ras_enable_all_features(adev, 1);
1826 /* We enable ras on all hw_supported block, but as boot
1827 * parameter might disable some of them and one or more IP has
1828 * not implemented yet. So we disable them on behalf.
1830 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1831 if (!amdgpu_ras_is_supported(adev, obj->head.block)) {
1832 amdgpu_ras_feature_enable(adev, &obj->head, 0);
1833 /* there should be no any reference. */
1834 WARN_ON(alive_obj(obj));
1839 if (con->flags & AMDGPU_RAS_FLAG_INIT_NEED_RESET) {
1840 con->flags &= ~AMDGPU_RAS_FLAG_INIT_NEED_RESET;
1841 /* setup ras obj state as disabled.
1842 * for init_by_vbios case.
1843 * if we want to enable ras, just enable it in a normal way.
1844 * If we want do disable it, need setup ras obj as enabled,
1845 * then issue another TA disable cmd.
1846 * See feature_enable_on_boot
1848 amdgpu_ras_disable_all_features(adev, 1);
1849 amdgpu_ras_reset_gpu(adev, 0);
1853 void amdgpu_ras_suspend(struct amdgpu_device *adev)
1855 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1860 amdgpu_ras_disable_all_features(adev, 0);
1861 /* Make sure all ras objects are disabled. */
1863 amdgpu_ras_disable_all_features(adev, 1);
1866 /* do some fini work before IP fini as dependence */
1867 int amdgpu_ras_pre_fini(struct amdgpu_device *adev)
1869 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1874 /* Need disable ras on all IPs here before ip [hw/sw]fini */
1875 amdgpu_ras_disable_all_features(adev, 0);
1876 amdgpu_ras_recovery_fini(adev);
1880 int amdgpu_ras_fini(struct amdgpu_device *adev)
1882 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1887 amdgpu_ras_fs_fini(adev);
1888 amdgpu_ras_interrupt_remove_all(adev);
1890 WARN(con->features, "Feature mask is not cleared");
1893 amdgpu_ras_disable_all_features(adev, 1);
1895 amdgpu_ras_set_context(adev, NULL);
1901 void amdgpu_ras_global_ras_isr(struct amdgpu_device *adev)
1903 uint32_t hw_supported, supported;
1905 amdgpu_ras_check_supported(adev, &hw_supported, &supported);
1909 if (atomic_cmpxchg(&amdgpu_ras_in_intr, 0, 1) == 0) {
1910 DRM_WARN("RAS event of type ERREVENT_ATHUB_INTERRUPT detected!\n");
1912 amdgpu_ras_reset_gpu(adev, false);