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>
30 #include <linux/pm_runtime.h>
31 #include <linux/list_sort.h>
34 #include "amdgpu_ras.h"
35 #include "amdgpu_atomfirmware.h"
36 #include "amdgpu_xgmi.h"
37 #include "ivsrcid/nbio/irqsrcs_nbif_7_4.h"
38 #include "nbio_v4_3.h"
39 #include "nbio_v7_9.h"
41 #include "amdgpu_reset.h"
42 #include "amdgpu_psp.h"
44 #ifdef CONFIG_X86_MCE_AMD
47 static bool notifier_registered;
49 static const char *RAS_FS_NAME = "ras";
51 const char *ras_error_string[] = {
55 "multi_uncorrectable",
59 const char *ras_block_string[] = {
81 const char *ras_mca_block_string[] = {
88 struct amdgpu_ras_block_list {
90 struct list_head node;
92 struct amdgpu_ras_block_object *ras_obj;
95 const char *get_ras_block_str(struct ras_common_if *ras_block)
100 if (ras_block->block >= AMDGPU_RAS_BLOCK_COUNT ||
101 ras_block->block >= ARRAY_SIZE(ras_block_string))
102 return "OUT OF RANGE";
104 if (ras_block->block == AMDGPU_RAS_BLOCK__MCA)
105 return ras_mca_block_string[ras_block->sub_block_index];
107 return ras_block_string[ras_block->block];
110 #define ras_block_str(_BLOCK_) \
111 (((_BLOCK_) < ARRAY_SIZE(ras_block_string)) ? ras_block_string[_BLOCK_] : "Out Of Range")
113 #define ras_err_str(i) (ras_error_string[ffs(i)])
115 #define RAS_DEFAULT_FLAGS (AMDGPU_RAS_FLAG_INIT_BY_VBIOS)
117 /* inject address is 52 bits */
118 #define RAS_UMC_INJECT_ADDR_LIMIT (0x1ULL << 52)
120 /* typical ECC bad page rate is 1 bad page per 100MB VRAM */
121 #define RAS_BAD_PAGE_COVER (100 * 1024 * 1024ULL)
123 #define MAX_UMC_POISON_POLLING_TIME_ASYNC 300 //ms
125 #define AMDGPU_RAS_RETIRE_PAGE_INTERVAL 100 //ms
127 enum amdgpu_ras_retire_page_reservation {
128 AMDGPU_RAS_RETIRE_PAGE_RESERVED,
129 AMDGPU_RAS_RETIRE_PAGE_PENDING,
130 AMDGPU_RAS_RETIRE_PAGE_FAULT,
133 atomic_t amdgpu_ras_in_intr = ATOMIC_INIT(0);
135 static bool amdgpu_ras_check_bad_page_unlock(struct amdgpu_ras *con,
137 static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
139 #ifdef CONFIG_X86_MCE_AMD
140 static void amdgpu_register_bad_pages_mca_notifier(struct amdgpu_device *adev);
141 struct mce_notifier_adev_list {
142 struct amdgpu_device *devs[MAX_GPU_INSTANCE];
145 static struct mce_notifier_adev_list mce_adev_list;
148 void amdgpu_ras_set_error_query_ready(struct amdgpu_device *adev, bool ready)
150 if (adev && amdgpu_ras_get_context(adev))
151 amdgpu_ras_get_context(adev)->error_query_ready = ready;
154 static bool amdgpu_ras_get_error_query_ready(struct amdgpu_device *adev)
156 if (adev && amdgpu_ras_get_context(adev))
157 return amdgpu_ras_get_context(adev)->error_query_ready;
162 static int amdgpu_reserve_page_direct(struct amdgpu_device *adev, uint64_t address)
164 struct ras_err_data err_data;
165 struct eeprom_table_record err_rec;
168 if ((address >= adev->gmc.mc_vram_size) ||
169 (address >= RAS_UMC_INJECT_ADDR_LIMIT)) {
171 "RAS WARN: input address 0x%llx is invalid.\n",
176 if (amdgpu_ras_check_bad_page(adev, address)) {
178 "RAS WARN: 0x%llx has already been marked as bad page!\n",
183 ret = amdgpu_ras_error_data_init(&err_data);
187 memset(&err_rec, 0x0, sizeof(struct eeprom_table_record));
188 err_data.err_addr = &err_rec;
189 amdgpu_umc_fill_error_record(&err_data, address, address, 0, 0);
191 if (amdgpu_bad_page_threshold != 0) {
192 amdgpu_ras_add_bad_pages(adev, err_data.err_addr,
193 err_data.err_addr_cnt);
194 amdgpu_ras_save_bad_pages(adev, NULL);
197 amdgpu_ras_error_data_fini(&err_data);
199 dev_warn(adev->dev, "WARNING: THIS IS ONLY FOR TEST PURPOSES AND WILL CORRUPT RAS EEPROM\n");
200 dev_warn(adev->dev, "Clear EEPROM:\n");
201 dev_warn(adev->dev, " echo 1 > /sys/kernel/debug/dri/0/ras/ras_eeprom_reset\n");
206 static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,
207 size_t size, loff_t *pos)
209 struct ras_manager *obj = (struct ras_manager *)file_inode(f)->i_private;
210 struct ras_query_if info = {
216 if (amdgpu_ras_query_error_status(obj->adev, &info))
219 /* Hardware counter will be reset automatically after the query on Vega20 and Arcturus */
220 if (amdgpu_ip_version(obj->adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 2) &&
221 amdgpu_ip_version(obj->adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 4)) {
222 if (amdgpu_ras_reset_error_status(obj->adev, info.head.block))
223 dev_warn(obj->adev->dev, "Failed to reset error counter and error status");
226 s = snprintf(val, sizeof(val), "%s: %lu\n%s: %lu\n",
228 "ce", info.ce_count);
233 s = min_t(u64, s, size);
236 if (copy_to_user(buf, &val[*pos], s))
244 static const struct file_operations amdgpu_ras_debugfs_ops = {
245 .owner = THIS_MODULE,
246 .read = amdgpu_ras_debugfs_read,
248 .llseek = default_llseek
251 static int amdgpu_ras_find_block_id_by_name(const char *name, int *block_id)
255 for (i = 0; i < ARRAY_SIZE(ras_block_string); i++) {
257 if (strcmp(name, ras_block_string[i]) == 0)
263 static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
264 const char __user *buf, size_t size,
265 loff_t *pos, struct ras_debug_if *data)
267 ssize_t s = min_t(u64, 64, size);
275 /* default value is 0 if the mask is not set by user */
276 u32 instance_mask = 0;
282 memset(str, 0, sizeof(str));
283 memset(data, 0, sizeof(*data));
285 if (copy_from_user(str, buf, s))
288 if (sscanf(str, "disable %32s", block_name) == 1)
290 else if (sscanf(str, "enable %32s %8s", block_name, err) == 2)
292 else if (sscanf(str, "inject %32s %8s", block_name, err) == 2)
294 else if (strstr(str, "retire_page") != NULL)
296 else if (str[0] && str[1] && str[2] && str[3])
297 /* ascii string, but commands are not matched. */
302 if (sscanf(str, "%*s 0x%llx", &address) != 1 &&
303 sscanf(str, "%*s %llu", &address) != 1)
307 data->inject.address = address;
312 if (amdgpu_ras_find_block_id_by_name(block_name, &block_id))
315 data->head.block = block_id;
316 /* only ue, ce and poison errors are supported */
317 if (!memcmp("ue", err, 2))
318 data->head.type = AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE;
319 else if (!memcmp("ce", err, 2))
320 data->head.type = AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE;
321 else if (!memcmp("poison", err, 6))
322 data->head.type = AMDGPU_RAS_ERROR__POISON;
329 if (sscanf(str, "%*s %*s %*s 0x%x 0x%llx 0x%llx 0x%x",
330 &sub_block, &address, &value, &instance_mask) != 4 &&
331 sscanf(str, "%*s %*s %*s %u %llu %llu %u",
332 &sub_block, &address, &value, &instance_mask) != 4 &&
333 sscanf(str, "%*s %*s %*s 0x%x 0x%llx 0x%llx",
334 &sub_block, &address, &value) != 3 &&
335 sscanf(str, "%*s %*s %*s %u %llu %llu",
336 &sub_block, &address, &value) != 3)
338 data->head.sub_block_index = sub_block;
339 data->inject.address = address;
340 data->inject.value = value;
341 data->inject.instance_mask = instance_mask;
344 if (size < sizeof(*data))
347 if (copy_from_user(data, buf, sizeof(*data)))
354 static void amdgpu_ras_instance_mask_check(struct amdgpu_device *adev,
355 struct ras_debug_if *data)
357 int num_xcc = adev->gfx.xcc_mask ? NUM_XCC(adev->gfx.xcc_mask) : 1;
358 uint32_t mask, inst_mask = data->inject.instance_mask;
360 /* no need to set instance mask if there is only one instance */
361 if (num_xcc <= 1 && inst_mask) {
362 data->inject.instance_mask = 0;
364 "RAS inject mask(0x%x) isn't supported and force it to 0.\n",
370 switch (data->head.block) {
371 case AMDGPU_RAS_BLOCK__GFX:
372 mask = GENMASK(num_xcc - 1, 0);
374 case AMDGPU_RAS_BLOCK__SDMA:
375 mask = GENMASK(adev->sdma.num_instances - 1, 0);
377 case AMDGPU_RAS_BLOCK__VCN:
378 case AMDGPU_RAS_BLOCK__JPEG:
379 mask = GENMASK(adev->vcn.num_vcn_inst - 1, 0);
386 /* remove invalid bits in instance mask */
387 data->inject.instance_mask &= mask;
388 if (inst_mask != data->inject.instance_mask)
390 "Adjust RAS inject mask 0x%x to 0x%x\n",
391 inst_mask, data->inject.instance_mask);
395 * DOC: AMDGPU RAS debugfs control interface
397 * The control interface accepts struct ras_debug_if which has two members.
399 * First member: ras_debug_if::head or ras_debug_if::inject.
401 * head is used to indicate which IP block will be under control.
403 * head has four members, they are block, type, sub_block_index, name.
404 * block: which IP will be under control.
405 * type: what kind of error will be enabled/disabled/injected.
406 * sub_block_index: some IPs have subcomponets. say, GFX, sDMA.
407 * name: the name of IP.
409 * inject has three more members than head, they are address, value and mask.
410 * As their names indicate, inject operation will write the
411 * value to the address.
413 * The second member: struct ras_debug_if::op.
414 * It has three kinds of operations.
416 * - 0: disable RAS on the block. Take ::head as its data.
417 * - 1: enable RAS on the block. Take ::head as its data.
418 * - 2: inject errors on the block. Take ::inject as its data.
420 * How to use the interface?
424 * Copy the struct ras_debug_if in your code and initialize it.
425 * Write the struct to the control interface.
429 * .. code-block:: bash
431 * echo "disable <block>" > /sys/kernel/debug/dri/<N>/ras/ras_ctrl
432 * echo "enable <block> <error>" > /sys/kernel/debug/dri/<N>/ras/ras_ctrl
433 * echo "inject <block> <error> <sub-block> <address> <value> <mask>" > /sys/kernel/debug/dri/<N>/ras/ras_ctrl
435 * Where N, is the card which you want to affect.
437 * "disable" requires only the block.
438 * "enable" requires the block and error type.
439 * "inject" requires the block, error type, address, and value.
441 * The block is one of: umc, sdma, gfx, etc.
442 * see ras_block_string[] for details
444 * The error type is one of: ue, ce and poison where,
445 * ue is multi-uncorrectable
446 * ce is single-correctable
449 * The sub-block is a the sub-block index, pass 0 if there is no sub-block.
450 * The address and value are hexadecimal numbers, leading 0x is optional.
451 * The mask means instance mask, is optional, default value is 0x1.
455 * .. code-block:: bash
457 * echo inject umc ue 0x0 0x0 0x0 > /sys/kernel/debug/dri/0/ras/ras_ctrl
458 * echo inject umc ce 0 0 0 3 > /sys/kernel/debug/dri/0/ras/ras_ctrl
459 * echo disable umc > /sys/kernel/debug/dri/0/ras/ras_ctrl
461 * How to check the result of the operation?
463 * To check disable/enable, see "ras" features at,
464 * /sys/class/drm/card[0/1/2...]/device/ras/features
466 * To check inject, see the corresponding error count at,
467 * /sys/class/drm/card[0/1/2...]/device/ras/[gfx|sdma|umc|...]_err_count
470 * Operations are only allowed on blocks which are supported.
471 * Check the "ras" mask at /sys/module/amdgpu/parameters/ras_mask
472 * to see which blocks support RAS on a particular asic.
475 static ssize_t amdgpu_ras_debugfs_ctrl_write(struct file *f,
476 const char __user *buf,
477 size_t size, loff_t *pos)
479 struct amdgpu_device *adev = (struct amdgpu_device *)file_inode(f)->i_private;
480 struct ras_debug_if data;
483 if (!amdgpu_ras_get_error_query_ready(adev)) {
484 dev_warn(adev->dev, "RAS WARN: error injection "
485 "currently inaccessible\n");
489 ret = amdgpu_ras_debugfs_ctrl_parse_data(f, buf, size, pos, &data);
494 ret = amdgpu_reserve_page_direct(adev, data.inject.address);
501 if (!amdgpu_ras_is_supported(adev, data.head.block))
506 ret = amdgpu_ras_feature_enable(adev, &data.head, 0);
509 ret = amdgpu_ras_feature_enable(adev, &data.head, 1);
512 if ((data.inject.address >= adev->gmc.mc_vram_size &&
513 adev->gmc.mc_vram_size) ||
514 (data.inject.address >= RAS_UMC_INJECT_ADDR_LIMIT)) {
515 dev_warn(adev->dev, "RAS WARN: input address "
516 "0x%llx is invalid.",
517 data.inject.address);
522 /* umc ce/ue error injection for a bad page is not allowed */
523 if ((data.head.block == AMDGPU_RAS_BLOCK__UMC) &&
524 amdgpu_ras_check_bad_page(adev, data.inject.address)) {
525 dev_warn(adev->dev, "RAS WARN: inject: 0x%llx has "
526 "already been marked as bad!\n",
527 data.inject.address);
531 amdgpu_ras_instance_mask_check(adev, &data);
533 /* data.inject.address is offset instead of absolute gpu address */
534 ret = amdgpu_ras_error_inject(adev, &data.inject);
548 * DOC: AMDGPU RAS debugfs EEPROM table reset interface
550 * Some boards contain an EEPROM which is used to persistently store a list of
551 * bad pages which experiences ECC errors in vram. This interface provides
552 * a way to reset the EEPROM, e.g., after testing error injection.
556 * .. code-block:: bash
558 * echo 1 > ../ras/ras_eeprom_reset
560 * will reset EEPROM table to 0 entries.
563 static ssize_t amdgpu_ras_debugfs_eeprom_write(struct file *f,
564 const char __user *buf,
565 size_t size, loff_t *pos)
567 struct amdgpu_device *adev =
568 (struct amdgpu_device *)file_inode(f)->i_private;
571 ret = amdgpu_ras_eeprom_reset_table(
572 &(amdgpu_ras_get_context(adev)->eeprom_control));
575 /* Something was written to EEPROM.
577 amdgpu_ras_get_context(adev)->flags = RAS_DEFAULT_FLAGS;
584 static const struct file_operations amdgpu_ras_debugfs_ctrl_ops = {
585 .owner = THIS_MODULE,
587 .write = amdgpu_ras_debugfs_ctrl_write,
588 .llseek = default_llseek
591 static const struct file_operations amdgpu_ras_debugfs_eeprom_ops = {
592 .owner = THIS_MODULE,
594 .write = amdgpu_ras_debugfs_eeprom_write,
595 .llseek = default_llseek
599 * DOC: AMDGPU RAS sysfs Error Count Interface
601 * It allows the user to read the error count for each IP block on the gpu through
602 * /sys/class/drm/card[0/1/2...]/device/ras/[gfx/sdma/...]_err_count
604 * It outputs the multiple lines which report the uncorrected (ue) and corrected
607 * The format of one line is below,
613 * .. code-block:: bash
619 static ssize_t amdgpu_ras_sysfs_read(struct device *dev,
620 struct device_attribute *attr, char *buf)
622 struct ras_manager *obj = container_of(attr, struct ras_manager, sysfs_attr);
623 struct ras_query_if info = {
627 if (!amdgpu_ras_get_error_query_ready(obj->adev))
628 return sysfs_emit(buf, "Query currently inaccessible\n");
630 if (amdgpu_ras_query_error_status(obj->adev, &info))
633 if (amdgpu_ip_version(obj->adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 2) &&
634 amdgpu_ip_version(obj->adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 4)) {
635 if (amdgpu_ras_reset_error_status(obj->adev, info.head.block))
636 dev_warn(obj->adev->dev, "Failed to reset error counter and error status");
639 if (info.head.block == AMDGPU_RAS_BLOCK__UMC)
640 return sysfs_emit(buf, "%s: %lu\n%s: %lu\n%s: %lu\n", "ue", info.ue_count,
641 "ce", info.ce_count, "de", info.de_count);
643 return sysfs_emit(buf, "%s: %lu\n%s: %lu\n", "ue", info.ue_count,
644 "ce", info.ce_count);
649 #define get_obj(obj) do { (obj)->use++; } while (0)
650 #define alive_obj(obj) ((obj)->use)
652 static inline void put_obj(struct ras_manager *obj)
654 if (obj && (--obj->use == 0)) {
655 list_del(&obj->node);
656 amdgpu_ras_error_data_fini(&obj->err_data);
659 if (obj && (obj->use < 0))
660 DRM_ERROR("RAS ERROR: Unbalance obj(%s) use\n", get_ras_block_str(&obj->head));
663 /* make one obj and return it. */
664 static struct ras_manager *amdgpu_ras_create_obj(struct amdgpu_device *adev,
665 struct ras_common_if *head)
667 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
668 struct ras_manager *obj;
670 if (!adev->ras_enabled || !con)
673 if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
676 if (head->block == AMDGPU_RAS_BLOCK__MCA) {
677 if (head->sub_block_index >= AMDGPU_RAS_MCA_BLOCK__LAST)
680 obj = &con->objs[AMDGPU_RAS_BLOCK__LAST + head->sub_block_index];
682 obj = &con->objs[head->block];
684 /* already exist. return obj? */
688 if (amdgpu_ras_error_data_init(&obj->err_data))
693 list_add(&obj->node, &con->head);
699 /* return an obj equal to head, or the first when head is NULL */
700 struct ras_manager *amdgpu_ras_find_obj(struct amdgpu_device *adev,
701 struct ras_common_if *head)
703 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
704 struct ras_manager *obj;
707 if (!adev->ras_enabled || !con)
711 if (head->block >= AMDGPU_RAS_BLOCK_COUNT)
714 if (head->block == AMDGPU_RAS_BLOCK__MCA) {
715 if (head->sub_block_index >= AMDGPU_RAS_MCA_BLOCK__LAST)
718 obj = &con->objs[AMDGPU_RAS_BLOCK__LAST + head->sub_block_index];
720 obj = &con->objs[head->block];
725 for (i = 0; i < AMDGPU_RAS_BLOCK_COUNT + AMDGPU_RAS_MCA_BLOCK_COUNT; i++) {
736 /* feature ctl begin */
737 static int amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
738 struct ras_common_if *head)
740 return adev->ras_hw_enabled & BIT(head->block);
743 static int amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
744 struct ras_common_if *head)
746 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
748 return con->features & BIT(head->block);
752 * if obj is not created, then create one.
753 * set feature enable flag.
755 static int __amdgpu_ras_feature_enable(struct amdgpu_device *adev,
756 struct ras_common_if *head, int enable)
758 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
759 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
761 /* If hardware does not support ras, then do not create obj.
762 * But if hardware support ras, we can create the obj.
763 * Ras framework checks con->hw_supported to see if it need do
764 * corresponding initialization.
765 * IP checks con->support to see if it need disable ras.
767 if (!amdgpu_ras_is_feature_allowed(adev, head))
772 obj = amdgpu_ras_create_obj(adev, head);
776 /* In case we create obj somewhere else */
779 con->features |= BIT(head->block);
781 if (obj && amdgpu_ras_is_feature_enabled(adev, head)) {
782 con->features &= ~BIT(head->block);
790 /* wrapper of psp_ras_enable_features */
791 int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
792 struct ras_common_if *head, bool enable)
794 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
795 union ta_ras_cmd_input *info;
801 /* For non-gfx ip, do not enable ras feature if it is not allowed */
802 /* For gfx ip, regardless of feature support status, */
803 /* Force issue enable or disable ras feature commands */
804 if (head->block != AMDGPU_RAS_BLOCK__GFX &&
805 !amdgpu_ras_is_feature_allowed(adev, head))
808 /* Only enable gfx ras feature from host side */
809 if (head->block == AMDGPU_RAS_BLOCK__GFX &&
810 !amdgpu_sriov_vf(adev) &&
811 !amdgpu_ras_intr_triggered()) {
812 info = kzalloc(sizeof(union ta_ras_cmd_input), GFP_KERNEL);
817 info->disable_features = (struct ta_ras_disable_features_input) {
818 .block_id = amdgpu_ras_block_to_ta(head->block),
819 .error_type = amdgpu_ras_error_to_ta(head->type),
822 info->enable_features = (struct ta_ras_enable_features_input) {
823 .block_id = amdgpu_ras_block_to_ta(head->block),
824 .error_type = amdgpu_ras_error_to_ta(head->type),
828 ret = psp_ras_enable_features(&adev->psp, info, enable);
830 dev_err(adev->dev, "ras %s %s failed poison:%d ret:%d\n",
831 enable ? "enable":"disable",
832 get_ras_block_str(head),
833 amdgpu_ras_is_poison_mode_supported(adev), ret);
842 __amdgpu_ras_feature_enable(adev, head, enable);
847 /* Only used in device probe stage and called only once. */
848 int amdgpu_ras_feature_enable_on_boot(struct amdgpu_device *adev,
849 struct ras_common_if *head, bool enable)
851 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
857 if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
859 /* There is no harm to issue a ras TA cmd regardless of
860 * the currecnt ras state.
861 * If current state == target state, it will do nothing
862 * But sometimes it requests driver to reset and repost
863 * with error code -EAGAIN.
865 ret = amdgpu_ras_feature_enable(adev, head, 1);
866 /* With old ras TA, we might fail to enable ras.
867 * Log it and just setup the object.
868 * TODO need remove this WA in the future.
870 if (ret == -EINVAL) {
871 ret = __amdgpu_ras_feature_enable(adev, head, 1);
874 "RAS INFO: %s setup object\n",
875 get_ras_block_str(head));
878 /* setup the object then issue a ras TA disable cmd.*/
879 ret = __amdgpu_ras_feature_enable(adev, head, 1);
883 /* gfx block ras dsiable cmd must send to ras-ta */
884 if (head->block == AMDGPU_RAS_BLOCK__GFX)
885 con->features |= BIT(head->block);
887 ret = amdgpu_ras_feature_enable(adev, head, 0);
889 /* clean gfx block ras features flag */
890 if (adev->ras_enabled && head->block == AMDGPU_RAS_BLOCK__GFX)
891 con->features &= ~BIT(head->block);
894 ret = amdgpu_ras_feature_enable(adev, head, enable);
899 static int amdgpu_ras_disable_all_features(struct amdgpu_device *adev,
902 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
903 struct ras_manager *obj, *tmp;
905 list_for_each_entry_safe(obj, tmp, &con->head, node) {
907 * aka just release the obj and corresponding flags
910 if (__amdgpu_ras_feature_enable(adev, &obj->head, 0))
913 if (amdgpu_ras_feature_enable(adev, &obj->head, 0))
918 return con->features;
921 static int amdgpu_ras_enable_all_features(struct amdgpu_device *adev,
924 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
926 const enum amdgpu_ras_error_type default_ras_type = AMDGPU_RAS_ERROR__NONE;
928 for (i = 0; i < AMDGPU_RAS_BLOCK_COUNT; i++) {
929 struct ras_common_if head = {
931 .type = default_ras_type,
932 .sub_block_index = 0,
935 if (i == AMDGPU_RAS_BLOCK__MCA)
940 * bypass psp. vbios enable ras for us.
941 * so just create the obj
943 if (__amdgpu_ras_feature_enable(adev, &head, 1))
946 if (amdgpu_ras_feature_enable(adev, &head, 1))
951 for (i = 0; i < AMDGPU_RAS_MCA_BLOCK_COUNT; i++) {
952 struct ras_common_if head = {
953 .block = AMDGPU_RAS_BLOCK__MCA,
954 .type = default_ras_type,
955 .sub_block_index = i,
960 * bypass psp. vbios enable ras for us.
961 * so just create the obj
963 if (__amdgpu_ras_feature_enable(adev, &head, 1))
966 if (amdgpu_ras_feature_enable(adev, &head, 1))
971 return con->features;
973 /* feature ctl end */
975 static int amdgpu_ras_block_match_default(struct amdgpu_ras_block_object *block_obj,
976 enum amdgpu_ras_block block)
981 if (block_obj->ras_comm.block == block)
987 static struct amdgpu_ras_block_object *amdgpu_ras_get_ras_block(struct amdgpu_device *adev,
988 enum amdgpu_ras_block block, uint32_t sub_block_index)
990 struct amdgpu_ras_block_list *node, *tmp;
991 struct amdgpu_ras_block_object *obj;
993 if (block >= AMDGPU_RAS_BLOCK__LAST)
996 list_for_each_entry_safe(node, tmp, &adev->ras_list, node) {
997 if (!node->ras_obj) {
998 dev_warn(adev->dev, "Warning: abnormal ras list node.\n");
1002 obj = node->ras_obj;
1003 if (obj->ras_block_match) {
1004 if (obj->ras_block_match(obj, block, sub_block_index) == 0)
1007 if (amdgpu_ras_block_match_default(obj, block) == 0)
1015 static void amdgpu_ras_get_ecc_info(struct amdgpu_device *adev, struct ras_err_data *err_data)
1017 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
1021 * choosing right query method according to
1022 * whether smu support query error information
1024 ret = amdgpu_dpm_get_ecc_info(adev, (void *)&(ras->umc_ecc));
1025 if (ret == -EOPNOTSUPP) {
1026 if (adev->umc.ras && adev->umc.ras->ras_block.hw_ops &&
1027 adev->umc.ras->ras_block.hw_ops->query_ras_error_count)
1028 adev->umc.ras->ras_block.hw_ops->query_ras_error_count(adev, err_data);
1030 /* umc query_ras_error_address is also responsible for clearing
1033 if (adev->umc.ras && adev->umc.ras->ras_block.hw_ops &&
1034 adev->umc.ras->ras_block.hw_ops->query_ras_error_address)
1035 adev->umc.ras->ras_block.hw_ops->query_ras_error_address(adev, err_data);
1037 if (adev->umc.ras &&
1038 adev->umc.ras->ecc_info_query_ras_error_count)
1039 adev->umc.ras->ecc_info_query_ras_error_count(adev, err_data);
1041 if (adev->umc.ras &&
1042 adev->umc.ras->ecc_info_query_ras_error_address)
1043 adev->umc.ras->ecc_info_query_ras_error_address(adev, err_data);
1047 static void amdgpu_ras_error_print_error_data(struct amdgpu_device *adev,
1048 struct ras_manager *ras_mgr,
1049 struct ras_err_data *err_data,
1050 struct ras_query_context *qctx,
1051 const char *blk_name,
1055 struct amdgpu_smuio_mcm_config_info *mcm_info;
1056 struct ras_err_node *err_node;
1057 struct ras_err_info *err_info;
1058 u64 event_id = qctx->event_id;
1061 for_each_ras_error(err_node, err_data) {
1062 err_info = &err_node->err_info;
1063 mcm_info = &err_info->mcm_info;
1064 if (err_info->ue_count) {
1065 RAS_EVENT_LOG(adev, event_id, "socket: %d, die: %d, "
1066 "%lld new uncorrectable hardware errors detected in %s block\n",
1067 mcm_info->socket_id,
1074 for_each_ras_error(err_node, &ras_mgr->err_data) {
1075 err_info = &err_node->err_info;
1076 mcm_info = &err_info->mcm_info;
1077 RAS_EVENT_LOG(adev, event_id, "socket: %d, die: %d, "
1078 "%lld uncorrectable hardware errors detected in total in %s block\n",
1079 mcm_info->socket_id, mcm_info->die_id, err_info->ue_count, blk_name);
1084 for_each_ras_error(err_node, err_data) {
1085 err_info = &err_node->err_info;
1086 mcm_info = &err_info->mcm_info;
1087 if (err_info->de_count) {
1088 RAS_EVENT_LOG(adev, event_id, "socket: %d, die: %d, "
1089 "%lld new deferred hardware errors detected in %s block\n",
1090 mcm_info->socket_id,
1097 for_each_ras_error(err_node, &ras_mgr->err_data) {
1098 err_info = &err_node->err_info;
1099 mcm_info = &err_info->mcm_info;
1100 RAS_EVENT_LOG(adev, event_id, "socket: %d, die: %d, "
1101 "%lld deferred hardware errors detected in total in %s block\n",
1102 mcm_info->socket_id, mcm_info->die_id,
1103 err_info->de_count, blk_name);
1106 for_each_ras_error(err_node, err_data) {
1107 err_info = &err_node->err_info;
1108 mcm_info = &err_info->mcm_info;
1109 if (err_info->ce_count) {
1110 RAS_EVENT_LOG(adev, event_id, "socket: %d, die: %d, "
1111 "%lld new correctable hardware errors detected in %s block\n",
1112 mcm_info->socket_id,
1119 for_each_ras_error(err_node, &ras_mgr->err_data) {
1120 err_info = &err_node->err_info;
1121 mcm_info = &err_info->mcm_info;
1122 RAS_EVENT_LOG(adev, event_id, "socket: %d, die: %d, "
1123 "%lld correctable hardware errors detected in total in %s block\n",
1124 mcm_info->socket_id, mcm_info->die_id,
1125 err_info->ce_count, blk_name);
1131 static inline bool err_data_has_source_info(struct ras_err_data *data)
1133 return !list_empty(&data->err_node_list);
1136 static void amdgpu_ras_error_generate_report(struct amdgpu_device *adev,
1137 struct ras_query_if *query_if,
1138 struct ras_err_data *err_data,
1139 struct ras_query_context *qctx)
1141 struct ras_manager *ras_mgr = amdgpu_ras_find_obj(adev, &query_if->head);
1142 const char *blk_name = get_ras_block_str(&query_if->head);
1143 u64 event_id = qctx->event_id;
1145 if (err_data->ce_count) {
1146 if (err_data_has_source_info(err_data)) {
1147 amdgpu_ras_error_print_error_data(adev, ras_mgr, err_data, qctx,
1148 blk_name, false, false);
1149 } else if (!adev->aid_mask &&
1150 adev->smuio.funcs &&
1151 adev->smuio.funcs->get_socket_id &&
1152 adev->smuio.funcs->get_die_id) {
1153 RAS_EVENT_LOG(adev, event_id, "socket: %d, die: %d "
1154 "%ld correctable hardware errors "
1155 "detected in %s block\n",
1156 adev->smuio.funcs->get_socket_id(adev),
1157 adev->smuio.funcs->get_die_id(adev),
1158 ras_mgr->err_data.ce_count,
1161 RAS_EVENT_LOG(adev, event_id, "%ld correctable hardware errors "
1162 "detected in %s block\n",
1163 ras_mgr->err_data.ce_count,
1168 if (err_data->ue_count) {
1169 if (err_data_has_source_info(err_data)) {
1170 amdgpu_ras_error_print_error_data(adev, ras_mgr, err_data, qctx,
1171 blk_name, true, false);
1172 } else if (!adev->aid_mask &&
1173 adev->smuio.funcs &&
1174 adev->smuio.funcs->get_socket_id &&
1175 adev->smuio.funcs->get_die_id) {
1176 RAS_EVENT_LOG(adev, event_id, "socket: %d, die: %d "
1177 "%ld uncorrectable hardware errors "
1178 "detected in %s block\n",
1179 adev->smuio.funcs->get_socket_id(adev),
1180 adev->smuio.funcs->get_die_id(adev),
1181 ras_mgr->err_data.ue_count,
1184 RAS_EVENT_LOG(adev, event_id, "%ld uncorrectable hardware errors "
1185 "detected in %s block\n",
1186 ras_mgr->err_data.ue_count,
1191 if (err_data->de_count) {
1192 if (err_data_has_source_info(err_data)) {
1193 amdgpu_ras_error_print_error_data(adev, ras_mgr, err_data, qctx,
1194 blk_name, false, true);
1195 } else if (!adev->aid_mask &&
1196 adev->smuio.funcs &&
1197 adev->smuio.funcs->get_socket_id &&
1198 adev->smuio.funcs->get_die_id) {
1199 RAS_EVENT_LOG(adev, event_id, "socket: %d, die: %d "
1200 "%ld deferred hardware errors "
1201 "detected in %s block\n",
1202 adev->smuio.funcs->get_socket_id(adev),
1203 adev->smuio.funcs->get_die_id(adev),
1204 ras_mgr->err_data.de_count,
1207 RAS_EVENT_LOG(adev, event_id, "%ld deferred hardware errors "
1208 "detected in %s block\n",
1209 ras_mgr->err_data.de_count,
1215 static void amdgpu_rasmgr_error_data_statistic_update(struct ras_manager *obj, struct ras_err_data *err_data)
1217 struct ras_err_node *err_node;
1218 struct ras_err_info *err_info;
1220 if (err_data_has_source_info(err_data)) {
1221 for_each_ras_error(err_node, err_data) {
1222 err_info = &err_node->err_info;
1223 amdgpu_ras_error_statistic_de_count(&obj->err_data,
1224 &err_info->mcm_info, NULL, err_info->de_count);
1225 amdgpu_ras_error_statistic_ce_count(&obj->err_data,
1226 &err_info->mcm_info, NULL, err_info->ce_count);
1227 amdgpu_ras_error_statistic_ue_count(&obj->err_data,
1228 &err_info->mcm_info, NULL, err_info->ue_count);
1231 /* for legacy asic path which doesn't has error source info */
1232 obj->err_data.ue_count += err_data->ue_count;
1233 obj->err_data.ce_count += err_data->ce_count;
1234 obj->err_data.de_count += err_data->de_count;
1238 static struct ras_manager *get_ras_manager(struct amdgpu_device *adev, enum amdgpu_ras_block blk)
1240 struct ras_common_if head;
1242 memset(&head, 0, sizeof(head));
1245 return amdgpu_ras_find_obj(adev, &head);
1248 int amdgpu_ras_bind_aca(struct amdgpu_device *adev, enum amdgpu_ras_block blk,
1249 const struct aca_info *aca_info, void *data)
1251 struct ras_manager *obj;
1253 /* in resume phase, no need to create aca fs node */
1254 if (adev->in_suspend || amdgpu_in_reset(adev))
1257 obj = get_ras_manager(adev, blk);
1261 return amdgpu_aca_add_handle(adev, &obj->aca_handle, ras_block_str(blk), aca_info, data);
1264 int amdgpu_ras_unbind_aca(struct amdgpu_device *adev, enum amdgpu_ras_block blk)
1266 struct ras_manager *obj;
1268 obj = get_ras_manager(adev, blk);
1272 amdgpu_aca_remove_handle(&obj->aca_handle);
1277 static int amdgpu_aca_log_ras_error_data(struct amdgpu_device *adev, enum amdgpu_ras_block blk,
1278 enum aca_error_type type, struct ras_err_data *err_data,
1279 struct ras_query_context *qctx)
1281 struct ras_manager *obj;
1283 obj = get_ras_manager(adev, blk);
1287 return amdgpu_aca_get_error_data(adev, &obj->aca_handle, type, err_data, qctx);
1290 ssize_t amdgpu_ras_aca_sysfs_read(struct device *dev, struct device_attribute *attr,
1291 struct aca_handle *handle, char *buf, void *data)
1293 struct ras_manager *obj = container_of(handle, struct ras_manager, aca_handle);
1294 struct ras_query_if info = {
1298 if (amdgpu_ras_query_error_status(obj->adev, &info))
1301 return sysfs_emit(buf, "%s: %lu\n%s: %lu\n%s: %lu\n", "ue", info.ue_count,
1302 "ce", info.ce_count, "de", info.de_count);
1305 static int amdgpu_ras_query_error_status_helper(struct amdgpu_device *adev,
1306 struct ras_query_if *info,
1307 struct ras_err_data *err_data,
1308 struct ras_query_context *qctx,
1309 unsigned int error_query_mode)
1311 enum amdgpu_ras_block blk = info ? info->head.block : AMDGPU_RAS_BLOCK_COUNT;
1312 struct amdgpu_ras_block_object *block_obj = NULL;
1315 if (blk == AMDGPU_RAS_BLOCK_COUNT)
1318 if (error_query_mode == AMDGPU_RAS_INVALID_ERROR_QUERY)
1321 if (error_query_mode == AMDGPU_RAS_DIRECT_ERROR_QUERY) {
1322 if (info->head.block == AMDGPU_RAS_BLOCK__UMC) {
1323 amdgpu_ras_get_ecc_info(adev, err_data);
1325 block_obj = amdgpu_ras_get_ras_block(adev, info->head.block, 0);
1326 if (!block_obj || !block_obj->hw_ops) {
1327 dev_dbg_once(adev->dev, "%s doesn't config RAS function\n",
1328 get_ras_block_str(&info->head));
1332 if (block_obj->hw_ops->query_ras_error_count)
1333 block_obj->hw_ops->query_ras_error_count(adev, err_data);
1335 if ((info->head.block == AMDGPU_RAS_BLOCK__SDMA) ||
1336 (info->head.block == AMDGPU_RAS_BLOCK__GFX) ||
1337 (info->head.block == AMDGPU_RAS_BLOCK__MMHUB)) {
1338 if (block_obj->hw_ops->query_ras_error_status)
1339 block_obj->hw_ops->query_ras_error_status(adev);
1343 if (amdgpu_aca_is_enabled(adev)) {
1344 ret = amdgpu_aca_log_ras_error_data(adev, blk, ACA_ERROR_TYPE_UE, err_data, qctx);
1348 ret = amdgpu_aca_log_ras_error_data(adev, blk, ACA_ERROR_TYPE_CE, err_data, qctx);
1352 ret = amdgpu_aca_log_ras_error_data(adev, blk, ACA_ERROR_TYPE_DEFERRED, err_data, qctx);
1356 /* FIXME: add code to check return value later */
1357 amdgpu_mca_smu_log_ras_error(adev, blk, AMDGPU_MCA_ERROR_TYPE_UE, err_data, qctx);
1358 amdgpu_mca_smu_log_ras_error(adev, blk, AMDGPU_MCA_ERROR_TYPE_CE, err_data, qctx);
1365 /* query/inject/cure begin */
1366 int amdgpu_ras_query_error_status(struct amdgpu_device *adev, struct ras_query_if *info)
1368 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1369 struct ras_err_data err_data;
1370 struct ras_query_context qctx;
1371 unsigned int error_query_mode;
1377 ret = amdgpu_ras_error_data_init(&err_data);
1381 if (!amdgpu_ras_get_error_query_mode(adev, &error_query_mode))
1384 memset(&qctx, 0, sizeof(qctx));
1385 qctx.event_id = amdgpu_ras_acquire_event_id(adev, amdgpu_ras_intr_triggered() ?
1386 RAS_EVENT_TYPE_ISR : RAS_EVENT_TYPE_INVALID);
1388 if (!down_read_trylock(&adev->reset_domain->sem)) {
1390 goto out_fini_err_data;
1393 ret = amdgpu_ras_query_error_status_helper(adev, info,
1397 up_read(&adev->reset_domain->sem);
1399 goto out_fini_err_data;
1401 amdgpu_rasmgr_error_data_statistic_update(obj, &err_data);
1403 info->ue_count = obj->err_data.ue_count;
1404 info->ce_count = obj->err_data.ce_count;
1405 info->de_count = obj->err_data.de_count;
1407 amdgpu_ras_error_generate_report(adev, info, &err_data, &qctx);
1410 amdgpu_ras_error_data_fini(&err_data);
1415 int amdgpu_ras_reset_error_count(struct amdgpu_device *adev,
1416 enum amdgpu_ras_block block)
1418 struct amdgpu_ras_block_object *block_obj = amdgpu_ras_get_ras_block(adev, block, 0);
1419 const struct amdgpu_mca_smu_funcs *mca_funcs = adev->mca.mca_funcs;
1420 const struct aca_smu_funcs *smu_funcs = adev->aca.smu_funcs;
1422 if (!block_obj || !block_obj->hw_ops) {
1423 dev_dbg_once(adev->dev, "%s doesn't config RAS function\n",
1424 ras_block_str(block));
1428 if (!amdgpu_ras_is_supported(adev, block) ||
1429 !amdgpu_ras_get_aca_debug_mode(adev))
1432 /* skip ras error reset in gpu reset */
1433 if ((amdgpu_in_reset(adev) || amdgpu_ras_in_recovery(adev)) &&
1434 ((smu_funcs && smu_funcs->set_debug_mode) ||
1435 (mca_funcs && mca_funcs->mca_set_debug_mode)))
1438 if (block_obj->hw_ops->reset_ras_error_count)
1439 block_obj->hw_ops->reset_ras_error_count(adev);
1444 int amdgpu_ras_reset_error_status(struct amdgpu_device *adev,
1445 enum amdgpu_ras_block block)
1447 struct amdgpu_ras_block_object *block_obj = amdgpu_ras_get_ras_block(adev, block, 0);
1449 if (amdgpu_ras_reset_error_count(adev, block) == -EOPNOTSUPP)
1452 if ((block == AMDGPU_RAS_BLOCK__GFX) ||
1453 (block == AMDGPU_RAS_BLOCK__MMHUB)) {
1454 if (block_obj->hw_ops->reset_ras_error_status)
1455 block_obj->hw_ops->reset_ras_error_status(adev);
1461 /* wrapper of psp_ras_trigger_error */
1462 int amdgpu_ras_error_inject(struct amdgpu_device *adev,
1463 struct ras_inject_if *info)
1465 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &info->head);
1466 struct ta_ras_trigger_error_input block_info = {
1467 .block_id = amdgpu_ras_block_to_ta(info->head.block),
1468 .inject_error_type = amdgpu_ras_error_to_ta(info->head.type),
1469 .sub_block_index = info->head.sub_block_index,
1470 .address = info->address,
1471 .value = info->value,
1474 struct amdgpu_ras_block_object *block_obj = amdgpu_ras_get_ras_block(adev,
1476 info->head.sub_block_index);
1478 /* inject on guest isn't allowed, return success directly */
1479 if (amdgpu_sriov_vf(adev))
1485 if (!block_obj || !block_obj->hw_ops) {
1486 dev_dbg_once(adev->dev, "%s doesn't config RAS function\n",
1487 get_ras_block_str(&info->head));
1491 /* Calculate XGMI relative offset */
1492 if (adev->gmc.xgmi.num_physical_nodes > 1 &&
1493 info->head.block != AMDGPU_RAS_BLOCK__GFX) {
1494 block_info.address =
1495 amdgpu_xgmi_get_relative_phy_addr(adev,
1496 block_info.address);
1499 if (block_obj->hw_ops->ras_error_inject) {
1500 if (info->head.block == AMDGPU_RAS_BLOCK__GFX)
1501 ret = block_obj->hw_ops->ras_error_inject(adev, info, info->instance_mask);
1502 else /* Special ras_error_inject is defined (e.g: xgmi) */
1503 ret = block_obj->hw_ops->ras_error_inject(adev, &block_info,
1504 info->instance_mask);
1507 ret = psp_ras_trigger_error(&adev->psp, &block_info, info->instance_mask);
1511 dev_err(adev->dev, "ras inject %s failed %d\n",
1512 get_ras_block_str(&info->head), ret);
1518 * amdgpu_ras_query_error_count_helper -- Get error counter for specific IP
1519 * @adev: pointer to AMD GPU device
1520 * @ce_count: pointer to an integer to be set to the count of correctible errors.
1521 * @ue_count: pointer to an integer to be set to the count of uncorrectible errors.
1522 * @query_info: pointer to ras_query_if
1524 * Return 0 for query success or do nothing, otherwise return an error
1527 static int amdgpu_ras_query_error_count_helper(struct amdgpu_device *adev,
1528 unsigned long *ce_count,
1529 unsigned long *ue_count,
1530 struct ras_query_if *query_info)
1535 /* do nothing if query_info is not specified */
1538 ret = amdgpu_ras_query_error_status(adev, query_info);
1542 *ce_count += query_info->ce_count;
1543 *ue_count += query_info->ue_count;
1545 /* some hardware/IP supports read to clear
1546 * no need to explictly reset the err status after the query call */
1547 if (amdgpu_ip_version(adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 2) &&
1548 amdgpu_ip_version(adev, MP0_HWIP, 0) != IP_VERSION(11, 0, 4)) {
1549 if (amdgpu_ras_reset_error_status(adev, query_info->head.block))
1551 "Failed to reset error counter and error status\n");
1558 * amdgpu_ras_query_error_count -- Get error counts of all IPs or specific IP
1559 * @adev: pointer to AMD GPU device
1560 * @ce_count: pointer to an integer to be set to the count of correctible errors.
1561 * @ue_count: pointer to an integer to be set to the count of uncorrectible
1563 * @query_info: pointer to ras_query_if if the query request is only for
1564 * specific ip block; if info is NULL, then the qurey request is for
1565 * all the ip blocks that support query ras error counters/status
1567 * If set, @ce_count or @ue_count, count and return the corresponding
1568 * error counts in those integer pointers. Return 0 if the device
1569 * supports RAS. Return -EOPNOTSUPP if the device doesn't support RAS.
1571 int amdgpu_ras_query_error_count(struct amdgpu_device *adev,
1572 unsigned long *ce_count,
1573 unsigned long *ue_count,
1574 struct ras_query_if *query_info)
1576 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1577 struct ras_manager *obj;
1578 unsigned long ce, ue;
1581 if (!adev->ras_enabled || !con)
1584 /* Don't count since no reporting.
1586 if (!ce_count && !ue_count)
1592 /* query all the ip blocks that support ras query interface */
1593 list_for_each_entry(obj, &con->head, node) {
1594 struct ras_query_if info = {
1598 ret = amdgpu_ras_query_error_count_helper(adev, &ce, &ue, &info);
1601 /* query specific ip block */
1602 ret = amdgpu_ras_query_error_count_helper(adev, &ce, &ue, query_info);
1616 /* query/inject/cure end */
1621 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
1622 struct ras_badpage **bps, unsigned int *count);
1624 static char *amdgpu_ras_badpage_flags_str(unsigned int flags)
1627 case AMDGPU_RAS_RETIRE_PAGE_RESERVED:
1629 case AMDGPU_RAS_RETIRE_PAGE_PENDING:
1631 case AMDGPU_RAS_RETIRE_PAGE_FAULT:
1638 * DOC: AMDGPU RAS sysfs gpu_vram_bad_pages Interface
1640 * It allows user to read the bad pages of vram on the gpu through
1641 * /sys/class/drm/card[0/1/2...]/device/ras/gpu_vram_bad_pages
1643 * It outputs multiple lines, and each line stands for one gpu page.
1645 * The format of one line is below,
1646 * gpu pfn : gpu page size : flags
1648 * gpu pfn and gpu page size are printed in hex format.
1649 * flags can be one of below character,
1651 * R: reserved, this gpu page is reserved and not able to use.
1653 * P: pending for reserve, this gpu page is marked as bad, will be reserved
1654 * in next window of page_reserve.
1656 * F: unable to reserve. this gpu page can't be reserved due to some reasons.
1660 * .. code-block:: bash
1662 * 0x00000001 : 0x00001000 : R
1663 * 0x00000002 : 0x00001000 : P
1667 static ssize_t amdgpu_ras_sysfs_badpages_read(struct file *f,
1668 struct kobject *kobj, struct bin_attribute *attr,
1669 char *buf, loff_t ppos, size_t count)
1671 struct amdgpu_ras *con =
1672 container_of(attr, struct amdgpu_ras, badpages_attr);
1673 struct amdgpu_device *adev = con->adev;
1674 const unsigned int element_size =
1675 sizeof("0xabcdabcd : 0x12345678 : R\n") - 1;
1676 unsigned int start = div64_ul(ppos + element_size - 1, element_size);
1677 unsigned int end = div64_ul(ppos + count - 1, element_size);
1679 struct ras_badpage *bps = NULL;
1680 unsigned int bps_count = 0;
1682 memset(buf, 0, count);
1684 if (amdgpu_ras_badpages_read(adev, &bps, &bps_count))
1687 for (; start < end && start < bps_count; start++)
1688 s += scnprintf(&buf[s], element_size + 1,
1689 "0x%08x : 0x%08x : %1s\n",
1692 amdgpu_ras_badpage_flags_str(bps[start].flags));
1699 static ssize_t amdgpu_ras_sysfs_features_read(struct device *dev,
1700 struct device_attribute *attr, char *buf)
1702 struct amdgpu_ras *con =
1703 container_of(attr, struct amdgpu_ras, features_attr);
1705 return sysfs_emit(buf, "feature mask: 0x%x\n", con->features);
1708 static ssize_t amdgpu_ras_sysfs_version_show(struct device *dev,
1709 struct device_attribute *attr, char *buf)
1711 struct amdgpu_ras *con =
1712 container_of(attr, struct amdgpu_ras, version_attr);
1713 return sysfs_emit(buf, "table version: 0x%x\n", con->eeprom_control.tbl_hdr.version);
1716 static ssize_t amdgpu_ras_sysfs_schema_show(struct device *dev,
1717 struct device_attribute *attr, char *buf)
1719 struct amdgpu_ras *con =
1720 container_of(attr, struct amdgpu_ras, schema_attr);
1721 return sysfs_emit(buf, "schema: 0x%x\n", con->schema);
1724 static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
1726 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1728 if (adev->dev->kobj.sd)
1729 sysfs_remove_file_from_group(&adev->dev->kobj,
1730 &con->badpages_attr.attr,
1734 static int amdgpu_ras_sysfs_remove_dev_attr_node(struct amdgpu_device *adev)
1736 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1737 struct attribute *attrs[] = {
1738 &con->features_attr.attr,
1739 &con->version_attr.attr,
1740 &con->schema_attr.attr,
1743 struct attribute_group group = {
1744 .name = RAS_FS_NAME,
1748 if (adev->dev->kobj.sd)
1749 sysfs_remove_group(&adev->dev->kobj, &group);
1754 int amdgpu_ras_sysfs_create(struct amdgpu_device *adev,
1755 struct ras_common_if *head)
1757 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1759 if (amdgpu_aca_is_enabled(adev))
1762 if (!obj || obj->attr_inuse)
1767 snprintf(obj->fs_data.sysfs_name, sizeof(obj->fs_data.sysfs_name),
1768 "%s_err_count", head->name);
1770 obj->sysfs_attr = (struct device_attribute){
1772 .name = obj->fs_data.sysfs_name,
1775 .show = amdgpu_ras_sysfs_read,
1777 sysfs_attr_init(&obj->sysfs_attr.attr);
1779 if (sysfs_add_file_to_group(&adev->dev->kobj,
1780 &obj->sysfs_attr.attr,
1786 obj->attr_inuse = 1;
1791 int amdgpu_ras_sysfs_remove(struct amdgpu_device *adev,
1792 struct ras_common_if *head)
1794 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
1796 if (amdgpu_aca_is_enabled(adev))
1799 if (!obj || !obj->attr_inuse)
1802 if (adev->dev->kobj.sd)
1803 sysfs_remove_file_from_group(&adev->dev->kobj,
1804 &obj->sysfs_attr.attr,
1806 obj->attr_inuse = 0;
1812 static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
1814 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1815 struct ras_manager *obj, *tmp;
1817 list_for_each_entry_safe(obj, tmp, &con->head, node) {
1818 amdgpu_ras_sysfs_remove(adev, &obj->head);
1821 if (amdgpu_bad_page_threshold != 0)
1822 amdgpu_ras_sysfs_remove_bad_page_node(adev);
1824 amdgpu_ras_sysfs_remove_dev_attr_node(adev);
1831 * DOC: AMDGPU RAS Reboot Behavior for Unrecoverable Errors
1833 * Normally when there is an uncorrectable error, the driver will reset
1834 * the GPU to recover. However, in the event of an unrecoverable error,
1835 * the driver provides an interface to reboot the system automatically
1838 * The following file in debugfs provides that interface:
1839 * /sys/kernel/debug/dri/[0/1/2...]/ras/auto_reboot
1843 * .. code-block:: bash
1845 * echo true > .../ras/auto_reboot
1849 static struct dentry *amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *adev)
1851 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1852 struct amdgpu_ras_eeprom_control *eeprom = &con->eeprom_control;
1853 struct drm_minor *minor = adev_to_drm(adev)->primary;
1856 dir = debugfs_create_dir(RAS_FS_NAME, minor->debugfs_root);
1857 debugfs_create_file("ras_ctrl", S_IWUGO | S_IRUGO, dir, adev,
1858 &amdgpu_ras_debugfs_ctrl_ops);
1859 debugfs_create_file("ras_eeprom_reset", S_IWUGO | S_IRUGO, dir, adev,
1860 &amdgpu_ras_debugfs_eeprom_ops);
1861 debugfs_create_u32("bad_page_cnt_threshold", 0444, dir,
1862 &con->bad_page_cnt_threshold);
1863 debugfs_create_u32("ras_num_recs", 0444, dir, &eeprom->ras_num_recs);
1864 debugfs_create_x32("ras_hw_enabled", 0444, dir, &adev->ras_hw_enabled);
1865 debugfs_create_x32("ras_enabled", 0444, dir, &adev->ras_enabled);
1866 debugfs_create_file("ras_eeprom_size", S_IRUGO, dir, adev,
1867 &amdgpu_ras_debugfs_eeprom_size_ops);
1868 con->de_ras_eeprom_table = debugfs_create_file("ras_eeprom_table",
1870 &amdgpu_ras_debugfs_eeprom_table_ops);
1871 amdgpu_ras_debugfs_set_ret_size(&con->eeprom_control);
1874 * After one uncorrectable error happens, usually GPU recovery will
1875 * be scheduled. But due to the known problem in GPU recovery failing
1876 * to bring GPU back, below interface provides one direct way to
1877 * user to reboot system automatically in such case within
1878 * ERREVENT_ATHUB_INTERRUPT generated. Normal GPU recovery routine
1879 * will never be called.
1881 debugfs_create_bool("auto_reboot", S_IWUGO | S_IRUGO, dir, &con->reboot);
1884 * User could set this not to clean up hardware's error count register
1885 * of RAS IPs during ras recovery.
1887 debugfs_create_bool("disable_ras_err_cnt_harvest", 0644, dir,
1888 &con->disable_ras_err_cnt_harvest);
1892 static void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
1893 struct ras_fs_if *head,
1896 struct ras_manager *obj = amdgpu_ras_find_obj(adev, &head->head);
1903 memcpy(obj->fs_data.debugfs_name,
1905 sizeof(obj->fs_data.debugfs_name));
1907 debugfs_create_file(obj->fs_data.debugfs_name, S_IWUGO | S_IRUGO, dir,
1908 obj, &amdgpu_ras_debugfs_ops);
1911 static bool amdgpu_ras_aca_is_supported(struct amdgpu_device *adev)
1915 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) {
1916 case IP_VERSION(13, 0, 6):
1917 case IP_VERSION(13, 0, 14):
1928 void amdgpu_ras_debugfs_create_all(struct amdgpu_device *adev)
1930 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1932 struct ras_manager *obj;
1933 struct ras_fs_if fs_info;
1936 * it won't be called in resume path, no need to check
1937 * suspend and gpu reset status
1939 if (!IS_ENABLED(CONFIG_DEBUG_FS) || !con)
1942 dir = amdgpu_ras_debugfs_create_ctrl_node(adev);
1944 list_for_each_entry(obj, &con->head, node) {
1945 if (amdgpu_ras_is_supported(adev, obj->head.block) &&
1946 (obj->attr_inuse == 1)) {
1947 sprintf(fs_info.debugfs_name, "%s_err_inject",
1948 get_ras_block_str(&obj->head));
1949 fs_info.head = obj->head;
1950 amdgpu_ras_debugfs_create(adev, &fs_info, dir);
1954 if (amdgpu_ras_aca_is_supported(adev)) {
1955 if (amdgpu_aca_is_enabled(adev))
1956 amdgpu_aca_smu_debugfs_init(adev, dir);
1958 amdgpu_mca_smu_debugfs_init(adev, dir);
1965 static BIN_ATTR(gpu_vram_bad_pages, S_IRUGO,
1966 amdgpu_ras_sysfs_badpages_read, NULL, 0);
1967 static DEVICE_ATTR(features, S_IRUGO,
1968 amdgpu_ras_sysfs_features_read, NULL);
1969 static DEVICE_ATTR(version, 0444,
1970 amdgpu_ras_sysfs_version_show, NULL);
1971 static DEVICE_ATTR(schema, 0444,
1972 amdgpu_ras_sysfs_schema_show, NULL);
1973 static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
1975 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
1976 struct attribute_group group = {
1977 .name = RAS_FS_NAME,
1979 struct attribute *attrs[] = {
1980 &con->features_attr.attr,
1981 &con->version_attr.attr,
1982 &con->schema_attr.attr,
1985 struct bin_attribute *bin_attrs[] = {
1991 group.attrs = attrs;
1993 /* add features entry */
1994 con->features_attr = dev_attr_features;
1995 sysfs_attr_init(attrs[0]);
1997 /* add version entry */
1998 con->version_attr = dev_attr_version;
1999 sysfs_attr_init(attrs[1]);
2001 /* add schema entry */
2002 con->schema_attr = dev_attr_schema;
2003 sysfs_attr_init(attrs[2]);
2005 if (amdgpu_bad_page_threshold != 0) {
2006 /* add bad_page_features entry */
2007 bin_attr_gpu_vram_bad_pages.private = NULL;
2008 con->badpages_attr = bin_attr_gpu_vram_bad_pages;
2009 bin_attrs[0] = &con->badpages_attr;
2010 group.bin_attrs = bin_attrs;
2011 sysfs_bin_attr_init(bin_attrs[0]);
2014 r = sysfs_create_group(&adev->dev->kobj, &group);
2016 dev_err(adev->dev, "Failed to create RAS sysfs group!");
2021 static int amdgpu_ras_fs_fini(struct amdgpu_device *adev)
2023 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2024 struct ras_manager *con_obj, *ip_obj, *tmp;
2026 if (IS_ENABLED(CONFIG_DEBUG_FS)) {
2027 list_for_each_entry_safe(con_obj, tmp, &con->head, node) {
2028 ip_obj = amdgpu_ras_find_obj(adev, &con_obj->head);
2034 amdgpu_ras_sysfs_remove_all(adev);
2041 /* For the hardware that cannot enable bif ring for both ras_controller_irq
2042 * and ras_err_evnet_athub_irq ih cookies, the driver has to poll status
2043 * register to check whether the interrupt is triggered or not, and properly
2044 * ack the interrupt if it is there
2046 void amdgpu_ras_interrupt_fatal_error_handler(struct amdgpu_device *adev)
2048 /* Fatal error events are handled on host side */
2049 if (amdgpu_sriov_vf(adev))
2052 if (adev->nbio.ras &&
2053 adev->nbio.ras->handle_ras_controller_intr_no_bifring)
2054 adev->nbio.ras->handle_ras_controller_intr_no_bifring(adev);
2056 if (adev->nbio.ras &&
2057 adev->nbio.ras->handle_ras_err_event_athub_intr_no_bifring)
2058 adev->nbio.ras->handle_ras_err_event_athub_intr_no_bifring(adev);
2061 static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *obj,
2062 struct amdgpu_iv_entry *entry)
2064 bool poison_stat = false;
2065 struct amdgpu_device *adev = obj->adev;
2066 struct amdgpu_ras_block_object *block_obj =
2067 amdgpu_ras_get_ras_block(adev, obj->head.block, 0);
2068 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2070 if (!block_obj || !con)
2073 /* both query_poison_status and handle_poison_consumption are optional,
2074 * but at least one of them should be implemented if we need poison
2075 * consumption handler
2077 if (block_obj->hw_ops && block_obj->hw_ops->query_poison_status) {
2078 poison_stat = block_obj->hw_ops->query_poison_status(adev);
2080 /* Not poison consumption interrupt, no need to handle it */
2081 dev_info(adev->dev, "No RAS poison status in %s poison IH.\n",
2082 block_obj->ras_comm.name);
2088 amdgpu_umc_poison_handler(adev, obj->head.block, 0);
2090 if (block_obj->hw_ops && block_obj->hw_ops->handle_poison_consumption)
2091 poison_stat = block_obj->hw_ops->handle_poison_consumption(adev);
2093 /* gpu reset is fallback for failed and default cases.
2094 * For RMA case, amdgpu_umc_poison_handler will handle gpu reset.
2096 if (poison_stat && !con->is_rma) {
2097 dev_info(adev->dev, "GPU reset for %s RAS poison consumption is issued!\n",
2098 block_obj->ras_comm.name);
2099 amdgpu_ras_reset_gpu(adev);
2103 amdgpu_gfx_poison_consumption_handler(adev, entry);
2106 static void amdgpu_ras_interrupt_poison_creation_handler(struct ras_manager *obj,
2107 struct amdgpu_iv_entry *entry)
2109 dev_info(obj->adev->dev,
2110 "Poison is created\n");
2112 if (amdgpu_ip_version(obj->adev, UMC_HWIP, 0) >= IP_VERSION(12, 0, 0)) {
2113 struct amdgpu_ras *con = amdgpu_ras_get_context(obj->adev);
2115 atomic_inc(&con->page_retirement_req_cnt);
2116 atomic_inc(&con->poison_creation_count);
2118 wake_up(&con->page_retirement_wq);
2122 static void amdgpu_ras_interrupt_umc_handler(struct ras_manager *obj,
2123 struct amdgpu_iv_entry *entry)
2125 struct ras_ih_data *data = &obj->ih_data;
2126 struct ras_err_data err_data;
2132 ret = amdgpu_ras_error_data_init(&err_data);
2136 /* Let IP handle its data, maybe we need get the output
2137 * from the callback to update the error type/count, etc
2139 amdgpu_ras_set_fed(obj->adev, true);
2140 ret = data->cb(obj->adev, &err_data, entry);
2141 /* ue will trigger an interrupt, and in that case
2142 * we need do a reset to recovery the whole system.
2143 * But leave IP do that recovery, here we just dispatch
2146 if (ret == AMDGPU_RAS_SUCCESS) {
2147 /* these counts could be left as 0 if
2148 * some blocks do not count error number
2150 obj->err_data.ue_count += err_data.ue_count;
2151 obj->err_data.ce_count += err_data.ce_count;
2152 obj->err_data.de_count += err_data.de_count;
2155 amdgpu_ras_error_data_fini(&err_data);
2158 static void amdgpu_ras_interrupt_handler(struct ras_manager *obj)
2160 struct ras_ih_data *data = &obj->ih_data;
2161 struct amdgpu_iv_entry entry;
2163 while (data->rptr != data->wptr) {
2165 memcpy(&entry, &data->ring[data->rptr],
2166 data->element_size);
2169 data->rptr = (data->aligned_element_size +
2170 data->rptr) % data->ring_size;
2172 if (amdgpu_ras_is_poison_mode_supported(obj->adev)) {
2173 if (obj->head.block == AMDGPU_RAS_BLOCK__UMC)
2174 amdgpu_ras_interrupt_poison_creation_handler(obj, &entry);
2176 amdgpu_ras_interrupt_poison_consumption_handler(obj, &entry);
2178 if (obj->head.block == AMDGPU_RAS_BLOCK__UMC)
2179 amdgpu_ras_interrupt_umc_handler(obj, &entry);
2181 dev_warn(obj->adev->dev,
2182 "No RAS interrupt handler for non-UMC block with poison disabled.\n");
2187 static void amdgpu_ras_interrupt_process_handler(struct work_struct *work)
2189 struct ras_ih_data *data =
2190 container_of(work, struct ras_ih_data, ih_work);
2191 struct ras_manager *obj =
2192 container_of(data, struct ras_manager, ih_data);
2194 amdgpu_ras_interrupt_handler(obj);
2197 int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev,
2198 struct ras_dispatch_if *info)
2200 struct ras_manager *obj;
2201 struct ras_ih_data *data;
2203 obj = amdgpu_ras_find_obj(adev, &info->head);
2207 data = &obj->ih_data;
2209 if (data->inuse == 0)
2212 /* Might be overflow... */
2213 memcpy(&data->ring[data->wptr], info->entry,
2214 data->element_size);
2217 data->wptr = (data->aligned_element_size +
2218 data->wptr) % data->ring_size;
2220 schedule_work(&data->ih_work);
2225 int amdgpu_ras_interrupt_remove_handler(struct amdgpu_device *adev,
2226 struct ras_common_if *head)
2228 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
2229 struct ras_ih_data *data;
2234 data = &obj->ih_data;
2235 if (data->inuse == 0)
2238 cancel_work_sync(&data->ih_work);
2241 memset(data, 0, sizeof(*data));
2247 int amdgpu_ras_interrupt_add_handler(struct amdgpu_device *adev,
2248 struct ras_common_if *head)
2250 struct ras_manager *obj = amdgpu_ras_find_obj(adev, head);
2251 struct ras_ih_data *data;
2252 struct amdgpu_ras_block_object *ras_obj;
2255 /* in case we registe the IH before enable ras feature */
2256 obj = amdgpu_ras_create_obj(adev, head);
2262 ras_obj = container_of(head, struct amdgpu_ras_block_object, ras_comm);
2264 data = &obj->ih_data;
2265 /* add the callback.etc */
2266 *data = (struct ras_ih_data) {
2268 .cb = ras_obj->ras_cb,
2269 .element_size = sizeof(struct amdgpu_iv_entry),
2274 INIT_WORK(&data->ih_work, amdgpu_ras_interrupt_process_handler);
2276 data->aligned_element_size = ALIGN(data->element_size, 8);
2277 /* the ring can store 64 iv entries. */
2278 data->ring_size = 64 * data->aligned_element_size;
2279 data->ring = kmalloc(data->ring_size, GFP_KERNEL);
2291 static int amdgpu_ras_interrupt_remove_all(struct amdgpu_device *adev)
2293 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2294 struct ras_manager *obj, *tmp;
2296 list_for_each_entry_safe(obj, tmp, &con->head, node) {
2297 amdgpu_ras_interrupt_remove_handler(adev, &obj->head);
2304 /* traversal all IPs except NBIO to query error counter */
2305 static void amdgpu_ras_log_on_err_counter(struct amdgpu_device *adev)
2307 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2308 struct ras_manager *obj;
2310 if (!adev->ras_enabled || !con)
2313 list_for_each_entry(obj, &con->head, node) {
2314 struct ras_query_if info = {
2319 * PCIE_BIF IP has one different isr by ras controller
2320 * interrupt, the specific ras counter query will be
2321 * done in that isr. So skip such block from common
2322 * sync flood interrupt isr calling.
2324 if (info.head.block == AMDGPU_RAS_BLOCK__PCIE_BIF)
2328 * this is a workaround for aldebaran, skip send msg to
2329 * smu to get ecc_info table due to smu handle get ecc
2330 * info table failed temporarily.
2331 * should be removed until smu fix handle ecc_info table.
2333 if ((info.head.block == AMDGPU_RAS_BLOCK__UMC) &&
2334 (amdgpu_ip_version(adev, MP1_HWIP, 0) ==
2335 IP_VERSION(13, 0, 2)))
2338 amdgpu_ras_query_error_status(adev, &info);
2340 if (amdgpu_ip_version(adev, MP0_HWIP, 0) !=
2341 IP_VERSION(11, 0, 2) &&
2342 amdgpu_ip_version(adev, MP0_HWIP, 0) !=
2343 IP_VERSION(11, 0, 4) &&
2344 amdgpu_ip_version(adev, MP0_HWIP, 0) !=
2345 IP_VERSION(13, 0, 0)) {
2346 if (amdgpu_ras_reset_error_status(adev, info.head.block))
2347 dev_warn(adev->dev, "Failed to reset error counter and error status");
2352 /* Parse RdRspStatus and WrRspStatus */
2353 static void amdgpu_ras_error_status_query(struct amdgpu_device *adev,
2354 struct ras_query_if *info)
2356 struct amdgpu_ras_block_object *block_obj;
2358 * Only two block need to query read/write
2359 * RspStatus at current state
2361 if ((info->head.block != AMDGPU_RAS_BLOCK__GFX) &&
2362 (info->head.block != AMDGPU_RAS_BLOCK__MMHUB))
2365 block_obj = amdgpu_ras_get_ras_block(adev,
2367 info->head.sub_block_index);
2369 if (!block_obj || !block_obj->hw_ops) {
2370 dev_dbg_once(adev->dev, "%s doesn't config RAS function\n",
2371 get_ras_block_str(&info->head));
2375 if (block_obj->hw_ops->query_ras_error_status)
2376 block_obj->hw_ops->query_ras_error_status(adev);
2380 static void amdgpu_ras_query_err_status(struct amdgpu_device *adev)
2382 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2383 struct ras_manager *obj;
2385 if (!adev->ras_enabled || !con)
2388 list_for_each_entry(obj, &con->head, node) {
2389 struct ras_query_if info = {
2393 amdgpu_ras_error_status_query(adev, &info);
2397 /* recovery begin */
2399 /* return 0 on success.
2400 * caller need free bps.
2402 static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
2403 struct ras_badpage **bps, unsigned int *count)
2405 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2406 struct ras_err_handler_data *data;
2408 int ret = 0, status;
2410 if (!con || !con->eh_data || !bps || !count)
2413 mutex_lock(&con->recovery_lock);
2414 data = con->eh_data;
2415 if (!data || data->count == 0) {
2421 *bps = kmalloc(sizeof(struct ras_badpage) * data->count, GFP_KERNEL);
2427 for (; i < data->count; i++) {
2428 (*bps)[i] = (struct ras_badpage){
2429 .bp = data->bps[i].retired_page,
2430 .size = AMDGPU_GPU_PAGE_SIZE,
2431 .flags = AMDGPU_RAS_RETIRE_PAGE_RESERVED,
2433 status = amdgpu_vram_mgr_query_page_status(&adev->mman.vram_mgr,
2434 data->bps[i].retired_page << AMDGPU_GPU_PAGE_SHIFT);
2435 if (status == -EBUSY)
2436 (*bps)[i].flags = AMDGPU_RAS_RETIRE_PAGE_PENDING;
2437 else if (status == -ENOENT)
2438 (*bps)[i].flags = AMDGPU_RAS_RETIRE_PAGE_FAULT;
2441 *count = data->count;
2443 mutex_unlock(&con->recovery_lock);
2447 static void amdgpu_ras_set_fed_all(struct amdgpu_device *adev,
2448 struct amdgpu_hive_info *hive, bool status)
2450 struct amdgpu_device *tmp_adev;
2453 list_for_each_entry(tmp_adev, &hive->device_list, gmc.xgmi.head)
2454 amdgpu_ras_set_fed(tmp_adev, status);
2456 amdgpu_ras_set_fed(adev, status);
2460 bool amdgpu_ras_in_recovery(struct amdgpu_device *adev)
2462 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
2463 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
2464 int hive_ras_recovery = 0;
2467 hive_ras_recovery = atomic_read(&hive->ras_recovery);
2468 amdgpu_put_xgmi_hive(hive);
2471 if (ras && (atomic_read(&ras->in_recovery) || hive_ras_recovery))
2477 static void amdgpu_ras_do_recovery(struct work_struct *work)
2479 struct amdgpu_ras *ras =
2480 container_of(work, struct amdgpu_ras, recovery_work);
2481 struct amdgpu_device *remote_adev = NULL;
2482 struct amdgpu_device *adev = ras->adev;
2483 struct list_head device_list, *device_list_handle = NULL;
2484 struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
2487 atomic_set(&hive->ras_recovery, 1);
2489 /* If any device which is part of the hive received RAS fatal
2490 * error interrupt, set fatal error status on all. This
2491 * condition will need a recovery, and flag will be cleared
2492 * as part of recovery.
2494 list_for_each_entry(remote_adev, &hive->device_list,
2496 if (amdgpu_ras_get_fed_status(remote_adev)) {
2497 amdgpu_ras_set_fed_all(adev, hive, true);
2501 if (!ras->disable_ras_err_cnt_harvest) {
2503 /* Build list of devices to query RAS related errors */
2504 if (hive && adev->gmc.xgmi.num_physical_nodes > 1) {
2505 device_list_handle = &hive->device_list;
2507 INIT_LIST_HEAD(&device_list);
2508 list_add_tail(&adev->gmc.xgmi.head, &device_list);
2509 device_list_handle = &device_list;
2512 list_for_each_entry(remote_adev,
2513 device_list_handle, gmc.xgmi.head) {
2514 amdgpu_ras_query_err_status(remote_adev);
2515 amdgpu_ras_log_on_err_counter(remote_adev);
2520 if (amdgpu_device_should_recover_gpu(ras->adev)) {
2521 struct amdgpu_reset_context reset_context;
2522 memset(&reset_context, 0, sizeof(reset_context));
2524 reset_context.method = AMD_RESET_METHOD_NONE;
2525 reset_context.reset_req_dev = adev;
2526 reset_context.src = AMDGPU_RESET_SRC_RAS;
2528 /* Perform full reset in fatal error mode */
2529 if (!amdgpu_ras_is_poison_mode_supported(ras->adev))
2530 set_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);
2532 clear_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);
2534 if (ras->gpu_reset_flags & AMDGPU_RAS_GPU_RESET_MODE2_RESET) {
2535 ras->gpu_reset_flags &= ~AMDGPU_RAS_GPU_RESET_MODE2_RESET;
2536 reset_context.method = AMD_RESET_METHOD_MODE2;
2539 /* Fatal error occurs in poison mode, mode1 reset is used to
2542 if (ras->gpu_reset_flags & AMDGPU_RAS_GPU_RESET_MODE1_RESET) {
2543 ras->gpu_reset_flags &= ~AMDGPU_RAS_GPU_RESET_MODE1_RESET;
2544 set_bit(AMDGPU_NEED_FULL_RESET, &reset_context.flags);
2546 psp_fatal_error_recovery_quirk(&adev->psp);
2550 amdgpu_device_gpu_recover(ras->adev, NULL, &reset_context);
2552 atomic_set(&ras->in_recovery, 0);
2554 atomic_set(&hive->ras_recovery, 0);
2555 amdgpu_put_xgmi_hive(hive);
2559 /* alloc/realloc bps array */
2560 static int amdgpu_ras_realloc_eh_data_space(struct amdgpu_device *adev,
2561 struct ras_err_handler_data *data, int pages)
2563 unsigned int old_space = data->count + data->space_left;
2564 unsigned int new_space = old_space + pages;
2565 unsigned int align_space = ALIGN(new_space, 512);
2566 void *bps = kmalloc(align_space * sizeof(*data->bps), GFP_KERNEL);
2573 memcpy(bps, data->bps,
2574 data->count * sizeof(*data->bps));
2579 data->space_left += align_space - old_space;
2583 /* it deal with vram only. */
2584 int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
2585 struct eeprom_table_record *bps, int pages)
2587 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2588 struct ras_err_handler_data *data;
2592 if (!con || !con->eh_data || !bps || pages <= 0)
2595 mutex_lock(&con->recovery_lock);
2596 data = con->eh_data;
2600 for (i = 0; i < pages; i++) {
2601 if (amdgpu_ras_check_bad_page_unlock(con,
2602 bps[i].retired_page << AMDGPU_GPU_PAGE_SHIFT))
2605 if (!data->space_left &&
2606 amdgpu_ras_realloc_eh_data_space(adev, data, 256)) {
2611 amdgpu_ras_reserve_page(adev, bps[i].retired_page);
2613 memcpy(&data->bps[data->count], &bps[i], sizeof(*data->bps));
2618 mutex_unlock(&con->recovery_lock);
2624 * write error record array to eeprom, the function should be
2625 * protected by recovery_lock
2626 * new_cnt: new added UE count, excluding reserved bad pages, can be NULL
2628 int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev,
2629 unsigned long *new_cnt)
2631 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2632 struct ras_err_handler_data *data;
2633 struct amdgpu_ras_eeprom_control *control;
2636 if (!con || !con->eh_data) {
2643 mutex_lock(&con->recovery_lock);
2644 control = &con->eeprom_control;
2645 data = con->eh_data;
2646 save_count = data->count - control->ras_num_recs;
2647 mutex_unlock(&con->recovery_lock);
2650 *new_cnt = save_count / adev->umc.retire_unit;
2652 /* only new entries are saved */
2653 if (save_count > 0) {
2654 if (amdgpu_ras_eeprom_append(control,
2655 &data->bps[control->ras_num_recs],
2657 dev_err(adev->dev, "Failed to save EEPROM table data!");
2661 dev_info(adev->dev, "Saved %d pages to EEPROM table.\n", save_count);
2668 * read error record array in eeprom and reserve enough space for
2669 * storing new bad pages
2671 static int amdgpu_ras_load_bad_pages(struct amdgpu_device *adev)
2673 struct amdgpu_ras_eeprom_control *control =
2674 &adev->psp.ras_context.ras->eeprom_control;
2675 struct eeprom_table_record *bps;
2678 /* no bad page record, skip eeprom access */
2679 if (control->ras_num_recs == 0 || amdgpu_bad_page_threshold == 0)
2682 bps = kcalloc(control->ras_num_recs, sizeof(*bps), GFP_KERNEL);
2686 ret = amdgpu_ras_eeprom_read(control, bps, control->ras_num_recs);
2688 dev_err(adev->dev, "Failed to load EEPROM table records!");
2690 ret = amdgpu_ras_add_bad_pages(adev, bps, control->ras_num_recs);
2696 static bool amdgpu_ras_check_bad_page_unlock(struct amdgpu_ras *con,
2699 struct ras_err_handler_data *data = con->eh_data;
2702 addr >>= AMDGPU_GPU_PAGE_SHIFT;
2703 for (i = 0; i < data->count; i++)
2704 if (addr == data->bps[i].retired_page)
2711 * check if an address belongs to bad page
2713 * Note: this check is only for umc block
2715 static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
2718 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2721 if (!con || !con->eh_data)
2724 mutex_lock(&con->recovery_lock);
2725 ret = amdgpu_ras_check_bad_page_unlock(con, addr);
2726 mutex_unlock(&con->recovery_lock);
2730 static void amdgpu_ras_validate_threshold(struct amdgpu_device *adev,
2733 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2736 * Justification of value bad_page_cnt_threshold in ras structure
2738 * Generally, 0 <= amdgpu_bad_page_threshold <= max record length
2739 * in eeprom or amdgpu_bad_page_threshold == -2, introduce two
2740 * scenarios accordingly.
2742 * Bad page retirement enablement:
2743 * - If amdgpu_bad_page_threshold = -2,
2744 * bad_page_cnt_threshold = typical value by formula.
2746 * - When the value from user is 0 < amdgpu_bad_page_threshold <
2747 * max record length in eeprom, use it directly.
2749 * Bad page retirement disablement:
2750 * - If amdgpu_bad_page_threshold = 0, bad page retirement
2751 * functionality is disabled, and bad_page_cnt_threshold will
2755 if (amdgpu_bad_page_threshold < 0) {
2756 u64 val = adev->gmc.mc_vram_size;
2758 do_div(val, RAS_BAD_PAGE_COVER);
2759 con->bad_page_cnt_threshold = min(lower_32_bits(val),
2762 con->bad_page_cnt_threshold = min_t(int, max_count,
2763 amdgpu_bad_page_threshold);
2767 int amdgpu_ras_put_poison_req(struct amdgpu_device *adev,
2768 enum amdgpu_ras_block block, uint16_t pasid,
2769 pasid_notify pasid_fn, void *data, uint32_t reset)
2772 struct ras_poison_msg poison_msg;
2773 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2775 memset(&poison_msg, 0, sizeof(poison_msg));
2776 poison_msg.block = block;
2777 poison_msg.pasid = pasid;
2778 poison_msg.reset = reset;
2779 poison_msg.pasid_fn = pasid_fn;
2780 poison_msg.data = data;
2782 ret = kfifo_put(&con->poison_fifo, poison_msg);
2784 dev_err(adev->dev, "Poison message fifo is full!\n");
2791 static int amdgpu_ras_get_poison_req(struct amdgpu_device *adev,
2792 struct ras_poison_msg *poison_msg)
2794 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2796 return kfifo_get(&con->poison_fifo, poison_msg);
2799 static void amdgpu_ras_ecc_log_init(struct ras_ecc_log_info *ecc_log)
2801 mutex_init(&ecc_log->lock);
2803 /* Set any value as siphash key */
2804 memset(&ecc_log->ecc_key, 0xad, sizeof(ecc_log->ecc_key));
2806 INIT_RADIX_TREE(&ecc_log->de_page_tree, GFP_KERNEL);
2807 ecc_log->de_queried_count = 0;
2808 ecc_log->prev_de_queried_count = 0;
2811 static void amdgpu_ras_ecc_log_fini(struct ras_ecc_log_info *ecc_log)
2813 struct radix_tree_iter iter;
2815 struct ras_ecc_err *ecc_err;
2817 mutex_lock(&ecc_log->lock);
2818 radix_tree_for_each_slot(slot, &ecc_log->de_page_tree, &iter, 0) {
2819 ecc_err = radix_tree_deref_slot(slot);
2820 kfree(ecc_err->err_pages.pfn);
2822 radix_tree_iter_delete(&ecc_log->de_page_tree, &iter, slot);
2824 mutex_unlock(&ecc_log->lock);
2826 mutex_destroy(&ecc_log->lock);
2827 ecc_log->de_queried_count = 0;
2828 ecc_log->prev_de_queried_count = 0;
2831 static void amdgpu_ras_do_page_retirement(struct work_struct *work)
2833 struct amdgpu_ras *con = container_of(work, struct amdgpu_ras,
2834 page_retirement_dwork.work);
2835 struct amdgpu_device *adev = con->adev;
2836 struct ras_err_data err_data;
2837 unsigned long err_cnt;
2839 if (amdgpu_in_reset(adev) || amdgpu_ras_in_recovery(adev))
2842 amdgpu_ras_error_data_init(&err_data);
2844 amdgpu_umc_handle_bad_pages(adev, &err_data);
2845 err_cnt = err_data.err_addr_cnt;
2847 amdgpu_ras_error_data_fini(&err_data);
2849 if (err_cnt && con->is_rma)
2850 amdgpu_ras_reset_gpu(adev);
2852 mutex_lock(&con->umc_ecc_log.lock);
2853 if (radix_tree_tagged(&con->umc_ecc_log.de_page_tree,
2854 UMC_ECC_NEW_DETECTED_TAG))
2855 schedule_delayed_work(&con->page_retirement_dwork,
2856 msecs_to_jiffies(AMDGPU_RAS_RETIRE_PAGE_INTERVAL));
2857 mutex_unlock(&con->umc_ecc_log.lock);
2860 static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
2861 uint32_t poison_creation_count)
2864 struct ras_ecc_log_info *ecc_log;
2865 struct ras_query_if info;
2866 uint32_t timeout = 0;
2867 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
2868 uint64_t de_queried_count;
2869 uint32_t new_detect_count, total_detect_count;
2870 uint32_t need_query_count = poison_creation_count;
2871 bool query_data_timeout = false;
2873 memset(&info, 0, sizeof(info));
2874 info.head.block = AMDGPU_RAS_BLOCK__UMC;
2876 ecc_log = &ras->umc_ecc_log;
2877 total_detect_count = 0;
2879 ret = amdgpu_ras_query_error_status(adev, &info);
2883 de_queried_count = ecc_log->de_queried_count;
2884 if (de_queried_count > ecc_log->prev_de_queried_count) {
2885 new_detect_count = de_queried_count - ecc_log->prev_de_queried_count;
2886 ecc_log->prev_de_queried_count = de_queried_count;
2889 new_detect_count = 0;
2892 if (new_detect_count) {
2893 total_detect_count += new_detect_count;
2895 if (!timeout && need_query_count)
2896 timeout = MAX_UMC_POISON_POLLING_TIME_ASYNC;
2900 query_data_timeout = true;
2906 } while (total_detect_count < need_query_count);
2908 if (query_data_timeout) {
2909 dev_warn(adev->dev, "Can't find deferred error! count: %u\n",
2910 (need_query_count - total_detect_count));
2914 if (total_detect_count)
2915 schedule_delayed_work(&ras->page_retirement_dwork, 0);
2920 static void amdgpu_ras_clear_poison_fifo(struct amdgpu_device *adev)
2922 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2923 struct ras_poison_msg msg;
2927 ret = kfifo_get(&con->poison_fifo, &msg);
2931 static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
2932 uint32_t msg_count, uint32_t *gpu_reset)
2934 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2935 uint32_t reset_flags = 0, reset = 0;
2936 struct ras_poison_msg msg;
2939 kgd2kfd_set_sram_ecc_flag(adev->kfd.dev);
2941 for (i = 0; i < msg_count; i++) {
2942 ret = amdgpu_ras_get_poison_req(adev, &msg);
2947 msg.pasid_fn(adev, msg.pasid, msg.data);
2949 reset_flags |= msg.reset;
2952 /* for RMA, amdgpu_ras_poison_creation_handler will trigger gpu reset */
2953 if (reset_flags && !con->is_rma) {
2954 if (reset_flags & AMDGPU_RAS_GPU_RESET_MODE1_RESET)
2955 reset = AMDGPU_RAS_GPU_RESET_MODE1_RESET;
2956 else if (reset_flags & AMDGPU_RAS_GPU_RESET_MODE2_RESET)
2957 reset = AMDGPU_RAS_GPU_RESET_MODE2_RESET;
2959 reset = reset_flags;
2961 flush_delayed_work(&con->page_retirement_dwork);
2963 con->gpu_reset_flags |= reset;
2964 amdgpu_ras_reset_gpu(adev);
2968 /* Wait for gpu recovery to complete */
2969 flush_work(&con->recovery_work);
2975 static int amdgpu_ras_page_retirement_thread(void *param)
2977 struct amdgpu_device *adev = (struct amdgpu_device *)param;
2978 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
2979 uint32_t poison_creation_count, msg_count;
2983 while (!kthread_should_stop()) {
2985 wait_event_interruptible(con->page_retirement_wq,
2986 kthread_should_stop() ||
2987 atomic_read(&con->page_retirement_req_cnt));
2989 if (kthread_should_stop())
2995 poison_creation_count = atomic_read(&con->poison_creation_count);
2996 ret = amdgpu_ras_poison_creation_handler(adev, poison_creation_count);
3000 if (poison_creation_count) {
3001 atomic_sub(poison_creation_count, &con->poison_creation_count);
3002 atomic_sub(poison_creation_count, &con->page_retirement_req_cnt);
3004 } while (atomic_read(&con->poison_creation_count));
3007 msg_count = kfifo_len(&con->poison_fifo);
3009 ret = amdgpu_ras_poison_consumption_handler(adev,
3010 msg_count, &gpu_reset);
3011 if ((ret != -EIO) &&
3012 (gpu_reset != AMDGPU_RAS_GPU_RESET_MODE1_RESET))
3013 atomic_sub(msg_count, &con->page_retirement_req_cnt);
3017 if ((ret == -EIO) || (gpu_reset == AMDGPU_RAS_GPU_RESET_MODE1_RESET)) {
3018 /* gpu mode-1 reset is ongoing or just completed ras mode-1 reset */
3019 /* Clear poison creation request */
3020 atomic_set(&con->poison_creation_count, 0);
3022 /* Clear poison fifo */
3023 amdgpu_ras_clear_poison_fifo(adev);
3025 /* Clear all poison requests */
3026 atomic_set(&con->page_retirement_req_cnt, 0);
3029 /* Wait for mode-1 reset to complete */
3030 down_read(&adev->reset_domain->sem);
3031 up_read(&adev->reset_domain->sem);
3034 /* Wake up work to save bad pages to eeprom */
3035 schedule_delayed_work(&con->page_retirement_dwork, 0);
3036 } else if (gpu_reset) {
3037 /* gpu just completed mode-2 reset or other reset */
3038 /* Clear poison consumption messages cached in fifo */
3039 msg_count = kfifo_len(&con->poison_fifo);
3041 amdgpu_ras_clear_poison_fifo(adev);
3042 atomic_sub(msg_count, &con->page_retirement_req_cnt);
3045 /* Wake up work to save bad pages to eeprom */
3046 schedule_delayed_work(&con->page_retirement_dwork, 0);
3053 int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
3055 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3056 struct ras_err_handler_data **data;
3057 u32 max_eeprom_records_count = 0;
3060 if (!con || amdgpu_sriov_vf(adev))
3063 /* Allow access to RAS EEPROM via debugfs, when the ASIC
3064 * supports RAS and debugfs is enabled, but when
3065 * adev->ras_enabled is unset, i.e. when "ras_enable"
3066 * module parameter is set to 0.
3070 if (!adev->ras_enabled)
3073 data = &con->eh_data;
3074 *data = kzalloc(sizeof(**data), GFP_KERNEL);
3080 mutex_init(&con->recovery_lock);
3081 INIT_WORK(&con->recovery_work, amdgpu_ras_do_recovery);
3082 atomic_set(&con->in_recovery, 0);
3083 con->eeprom_control.bad_channel_bitmap = 0;
3085 max_eeprom_records_count = amdgpu_ras_eeprom_max_record_count(&con->eeprom_control);
3086 amdgpu_ras_validate_threshold(adev, max_eeprom_records_count);
3088 /* Todo: During test the SMU might fail to read the eeprom through I2C
3089 * when the GPU is pending on XGMI reset during probe time
3090 * (Mostly after second bus reset), skip it now
3092 if (adev->gmc.xgmi.pending_reset)
3094 ret = amdgpu_ras_eeprom_init(&con->eeprom_control);
3096 * This calling fails when is_rma is true or
3099 if (con->is_rma || ret)
3102 if (con->eeprom_control.ras_num_recs) {
3103 ret = amdgpu_ras_load_bad_pages(adev);
3107 amdgpu_dpm_send_hbm_bad_pages_num(adev, con->eeprom_control.ras_num_recs);
3109 if (con->update_channel_flag == true) {
3110 amdgpu_dpm_send_hbm_bad_channel_flag(adev, con->eeprom_control.bad_channel_bitmap);
3111 con->update_channel_flag = false;
3115 mutex_init(&con->page_rsv_lock);
3116 INIT_KFIFO(con->poison_fifo);
3117 mutex_init(&con->page_retirement_lock);
3118 init_waitqueue_head(&con->page_retirement_wq);
3119 atomic_set(&con->page_retirement_req_cnt, 0);
3120 atomic_set(&con->poison_creation_count, 0);
3121 con->page_retirement_thread =
3122 kthread_run(amdgpu_ras_page_retirement_thread, adev, "umc_page_retirement");
3123 if (IS_ERR(con->page_retirement_thread)) {
3124 con->page_retirement_thread = NULL;
3125 dev_warn(adev->dev, "Failed to create umc_page_retirement thread!!!\n");
3128 INIT_DELAYED_WORK(&con->page_retirement_dwork, amdgpu_ras_do_page_retirement);
3129 amdgpu_ras_ecc_log_init(&con->umc_ecc_log);
3130 #ifdef CONFIG_X86_MCE_AMD
3131 if ((adev->asic_type == CHIP_ALDEBARAN) &&
3132 (adev->gmc.xgmi.connected_to_cpu))
3133 amdgpu_register_bad_pages_mca_notifier(adev);
3138 kfree((*data)->bps);
3140 con->eh_data = NULL;
3142 dev_warn(adev->dev, "Failed to initialize ras recovery! (%d)\n", ret);
3145 * Except error threshold exceeding case, other failure cases in this
3146 * function would not fail amdgpu driver init.
3156 static int amdgpu_ras_recovery_fini(struct amdgpu_device *adev)
3158 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3159 struct ras_err_handler_data *data = con->eh_data;
3161 /* recovery_init failed to init it, fini is useless */
3165 if (con->page_retirement_thread)
3166 kthread_stop(con->page_retirement_thread);
3168 atomic_set(&con->page_retirement_req_cnt, 0);
3169 atomic_set(&con->poison_creation_count, 0);
3171 mutex_destroy(&con->page_rsv_lock);
3173 cancel_work_sync(&con->recovery_work);
3175 cancel_delayed_work_sync(&con->page_retirement_dwork);
3177 amdgpu_ras_ecc_log_fini(&con->umc_ecc_log);
3179 mutex_lock(&con->recovery_lock);
3180 con->eh_data = NULL;
3183 mutex_unlock(&con->recovery_lock);
3189 static bool amdgpu_ras_asic_supported(struct amdgpu_device *adev)
3191 if (amdgpu_sriov_vf(adev)) {
3192 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) {
3193 case IP_VERSION(13, 0, 2):
3194 case IP_VERSION(13, 0, 6):
3195 case IP_VERSION(13, 0, 14):
3202 if (adev->asic_type == CHIP_IP_DISCOVERY) {
3203 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) {
3204 case IP_VERSION(13, 0, 0):
3205 case IP_VERSION(13, 0, 6):
3206 case IP_VERSION(13, 0, 10):
3207 case IP_VERSION(13, 0, 14):
3214 return adev->asic_type == CHIP_VEGA10 ||
3215 adev->asic_type == CHIP_VEGA20 ||
3216 adev->asic_type == CHIP_ARCTURUS ||
3217 adev->asic_type == CHIP_ALDEBARAN ||
3218 adev->asic_type == CHIP_SIENNA_CICHLID;
3222 * this is workaround for vega20 workstation sku,
3223 * force enable gfx ras, ignore vbios gfx ras flag
3224 * due to GC EDC can not write
3226 static void amdgpu_ras_get_quirks(struct amdgpu_device *adev)
3228 struct atom_context *ctx = adev->mode_info.atom_context;
3233 if (strnstr(ctx->vbios_pn, "D16406",
3234 sizeof(ctx->vbios_pn)) ||
3235 strnstr(ctx->vbios_pn, "D36002",
3236 sizeof(ctx->vbios_pn)))
3237 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__GFX);
3240 /* Query ras capablity via atomfirmware interface */
3241 static void amdgpu_ras_query_ras_capablity_from_vbios(struct amdgpu_device *adev)
3244 if (amdgpu_atomfirmware_mem_ecc_supported(adev)) {
3245 dev_info(adev->dev, "MEM ECC is active.\n");
3246 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__UMC |
3247 1 << AMDGPU_RAS_BLOCK__DF);
3249 dev_info(adev->dev, "MEM ECC is not presented.\n");
3253 if (amdgpu_atomfirmware_sram_ecc_supported(adev)) {
3254 dev_info(adev->dev, "SRAM ECC is active.\n");
3255 if (!amdgpu_sriov_vf(adev))
3256 adev->ras_hw_enabled |= ~(1 << AMDGPU_RAS_BLOCK__UMC |
3257 1 << AMDGPU_RAS_BLOCK__DF);
3259 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__PCIE_BIF |
3260 1 << AMDGPU_RAS_BLOCK__SDMA |
3261 1 << AMDGPU_RAS_BLOCK__GFX);
3264 * VCN/JPEG RAS can be supported on both bare metal and
3267 if (amdgpu_ip_version(adev, VCN_HWIP, 0) == IP_VERSION(2, 6, 0) ||
3268 amdgpu_ip_version(adev, VCN_HWIP, 0) == IP_VERSION(4, 0, 0) ||
3269 amdgpu_ip_version(adev, VCN_HWIP, 0) == IP_VERSION(4, 0, 3))
3270 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__VCN |
3271 1 << AMDGPU_RAS_BLOCK__JPEG);
3273 adev->ras_hw_enabled &= ~(1 << AMDGPU_RAS_BLOCK__VCN |
3274 1 << AMDGPU_RAS_BLOCK__JPEG);
3277 * XGMI RAS is not supported if xgmi num physical nodes
3280 if (!adev->gmc.xgmi.num_physical_nodes)
3281 adev->ras_hw_enabled &= ~(1 << AMDGPU_RAS_BLOCK__XGMI_WAFL);
3283 dev_info(adev->dev, "SRAM ECC is not presented.\n");
3287 /* Query poison mode from umc/df IP callbacks */
3288 static void amdgpu_ras_query_poison_mode(struct amdgpu_device *adev)
3290 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3291 bool df_poison, umc_poison;
3293 /* poison setting is useless on SRIOV guest */
3294 if (amdgpu_sriov_vf(adev) || !con)
3297 /* Init poison supported flag, the default value is false */
3298 if (adev->gmc.xgmi.connected_to_cpu ||
3299 adev->gmc.is_app_apu) {
3300 /* enabled by default when GPU is connected to CPU */
3301 con->poison_supported = true;
3302 } else if (adev->df.funcs &&
3303 adev->df.funcs->query_ras_poison_mode &&
3305 adev->umc.ras->query_ras_poison_mode) {
3307 adev->df.funcs->query_ras_poison_mode(adev);
3309 adev->umc.ras->query_ras_poison_mode(adev);
3311 /* Only poison is set in both DF and UMC, we can support it */
3312 if (df_poison && umc_poison)
3313 con->poison_supported = true;
3314 else if (df_poison != umc_poison)
3316 "Poison setting is inconsistent in DF/UMC(%d:%d)!\n",
3317 df_poison, umc_poison);
3322 * check hardware's ras ability which will be saved in hw_supported.
3323 * if hardware does not support ras, we can skip some ras initializtion and
3324 * forbid some ras operations from IP.
3325 * if software itself, say boot parameter, limit the ras ability. We still
3326 * need allow IP do some limited operations, like disable. In such case,
3327 * we have to initialize ras as normal. but need check if operation is
3328 * allowed or not in each function.
3330 static void amdgpu_ras_check_supported(struct amdgpu_device *adev)
3332 adev->ras_hw_enabled = adev->ras_enabled = 0;
3334 if (!amdgpu_ras_asic_supported(adev))
3337 /* query ras capability from psp */
3338 if (amdgpu_psp_get_ras_capability(&adev->psp))
3339 goto init_ras_enabled_flag;
3341 /* query ras capablity from bios */
3342 if (!adev->gmc.xgmi.connected_to_cpu && !adev->gmc.is_app_apu) {
3343 amdgpu_ras_query_ras_capablity_from_vbios(adev);
3345 /* driver only manages a few IP blocks RAS feature
3346 * when GPU is connected cpu through XGMI */
3347 adev->ras_hw_enabled |= (1 << AMDGPU_RAS_BLOCK__GFX |
3348 1 << AMDGPU_RAS_BLOCK__SDMA |
3349 1 << AMDGPU_RAS_BLOCK__MMHUB);
3352 /* apply asic specific settings (vega20 only for now) */
3353 amdgpu_ras_get_quirks(adev);
3355 /* query poison mode from umc/df ip callback */
3356 amdgpu_ras_query_poison_mode(adev);
3358 init_ras_enabled_flag:
3359 /* hw_supported needs to be aligned with RAS block mask. */
3360 adev->ras_hw_enabled &= AMDGPU_RAS_BLOCK_MASK;
3362 adev->ras_enabled = amdgpu_ras_enable == 0 ? 0 :
3363 adev->ras_hw_enabled & amdgpu_ras_mask;
3365 /* aca is disabled by default */
3366 adev->aca.is_enabled = false;
3369 static void amdgpu_ras_counte_dw(struct work_struct *work)
3371 struct amdgpu_ras *con = container_of(work, struct amdgpu_ras,
3372 ras_counte_delay_work.work);
3373 struct amdgpu_device *adev = con->adev;
3374 struct drm_device *dev = adev_to_drm(adev);
3375 unsigned long ce_count, ue_count;
3378 res = pm_runtime_get_sync(dev->dev);
3382 /* Cache new values.
3384 if (amdgpu_ras_query_error_count(adev, &ce_count, &ue_count, NULL) == 0) {
3385 atomic_set(&con->ras_ce_count, ce_count);
3386 atomic_set(&con->ras_ue_count, ue_count);
3389 pm_runtime_mark_last_busy(dev->dev);
3391 pm_runtime_put_autosuspend(dev->dev);
3394 static int amdgpu_get_ras_schema(struct amdgpu_device *adev)
3396 return amdgpu_ras_is_poison_mode_supported(adev) ? AMDGPU_RAS_ERROR__POISON : 0 |
3397 AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE |
3398 AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE |
3399 AMDGPU_RAS_ERROR__PARITY;
3402 static void ras_event_mgr_init(struct ras_event_manager *mgr)
3406 for (i = 0; i < ARRAY_SIZE(mgr->seqnos); i++)
3407 atomic64_set(&mgr->seqnos[i], 0);
3410 static void amdgpu_ras_event_mgr_init(struct amdgpu_device *adev)
3412 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
3413 struct amdgpu_hive_info *hive;
3418 hive = amdgpu_get_xgmi_hive(adev);
3419 ras->event_mgr = hive ? &hive->event_mgr : &ras->__event_mgr;
3421 /* init event manager with node 0 on xgmi system */
3422 if (!amdgpu_in_reset(adev)) {
3423 if (!hive || adev->gmc.xgmi.node_id == 0)
3424 ras_event_mgr_init(ras->event_mgr);
3428 amdgpu_put_xgmi_hive(hive);
3431 static void amdgpu_ras_init_reserved_vram_size(struct amdgpu_device *adev)
3433 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3435 if (!con || (adev->flags & AMD_IS_APU))
3438 switch (amdgpu_ip_version(adev, MP0_HWIP, 0)) {
3439 case IP_VERSION(13, 0, 2):
3440 case IP_VERSION(13, 0, 6):
3441 case IP_VERSION(13, 0, 14):
3442 con->reserved_pages_in_bytes = AMDGPU_RAS_RESERVED_VRAM_SIZE;
3449 int amdgpu_ras_init(struct amdgpu_device *adev)
3451 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3457 con = kzalloc(sizeof(*con) +
3458 sizeof(struct ras_manager) * AMDGPU_RAS_BLOCK_COUNT +
3459 sizeof(struct ras_manager) * AMDGPU_RAS_MCA_BLOCK_COUNT,
3465 INIT_DELAYED_WORK(&con->ras_counte_delay_work, amdgpu_ras_counte_dw);
3466 atomic_set(&con->ras_ce_count, 0);
3467 atomic_set(&con->ras_ue_count, 0);
3469 con->objs = (struct ras_manager *)(con + 1);
3471 amdgpu_ras_set_context(adev, con);
3473 amdgpu_ras_check_supported(adev);
3475 if (!adev->ras_enabled || adev->asic_type == CHIP_VEGA10) {
3476 /* set gfx block ras context feature for VEGA20 Gaming
3477 * send ras disable cmd to ras ta during ras late init.
3479 if (!adev->ras_enabled && adev->asic_type == CHIP_VEGA20) {
3480 con->features |= BIT(AMDGPU_RAS_BLOCK__GFX);
3489 con->update_channel_flag = false;
3492 INIT_LIST_HEAD(&con->head);
3493 /* Might need get this flag from vbios. */
3494 con->flags = RAS_DEFAULT_FLAGS;
3496 /* initialize nbio ras function ahead of any other
3497 * ras functions so hardware fatal error interrupt
3498 * can be enabled as early as possible */
3499 switch (amdgpu_ip_version(adev, NBIO_HWIP, 0)) {
3500 case IP_VERSION(7, 4, 0):
3501 case IP_VERSION(7, 4, 1):
3502 case IP_VERSION(7, 4, 4):
3503 if (!adev->gmc.xgmi.connected_to_cpu)
3504 adev->nbio.ras = &nbio_v7_4_ras;
3506 case IP_VERSION(4, 3, 0):
3507 if (adev->ras_hw_enabled & (1 << AMDGPU_RAS_BLOCK__DF))
3508 /* unlike other generation of nbio ras,
3509 * nbio v4_3 only support fatal error interrupt
3510 * to inform software that DF is freezed due to
3511 * system fatal error event. driver should not
3512 * enable nbio ras in such case. Instead,
3514 adev->nbio.ras = &nbio_v4_3_ras;
3516 case IP_VERSION(7, 9, 0):
3517 if (!adev->gmc.is_app_apu)
3518 adev->nbio.ras = &nbio_v7_9_ras;
3521 /* nbio ras is not available */
3525 /* nbio ras block needs to be enabled ahead of other ras blocks
3526 * to handle fatal error */
3527 r = amdgpu_nbio_ras_sw_init(adev);
3531 if (adev->nbio.ras &&
3532 adev->nbio.ras->init_ras_controller_interrupt) {
3533 r = adev->nbio.ras->init_ras_controller_interrupt(adev);
3538 if (adev->nbio.ras &&
3539 adev->nbio.ras->init_ras_err_event_athub_interrupt) {
3540 r = adev->nbio.ras->init_ras_err_event_athub_interrupt(adev);
3545 /* Packed socket_id to ras feature mask bits[31:29] */
3546 if (adev->smuio.funcs &&
3547 adev->smuio.funcs->get_socket_id)
3548 con->features |= ((adev->smuio.funcs->get_socket_id(adev)) <<
3549 AMDGPU_RAS_FEATURES_SOCKETID_SHIFT);
3551 /* Get RAS schema for particular SOC */
3552 con->schema = amdgpu_get_ras_schema(adev);
3554 amdgpu_ras_init_reserved_vram_size(adev);
3556 if (amdgpu_ras_fs_init(adev)) {
3561 if (amdgpu_ras_aca_is_supported(adev)) {
3562 if (amdgpu_aca_is_enabled(adev))
3563 r = amdgpu_aca_init(adev);
3565 r = amdgpu_mca_init(adev);
3570 dev_info(adev->dev, "RAS INFO: ras initialized successfully, "
3571 "hardware ability[%x] ras_mask[%x]\n",
3572 adev->ras_hw_enabled, adev->ras_enabled);
3576 amdgpu_ras_set_context(adev, NULL);
3582 int amdgpu_persistent_edc_harvesting_supported(struct amdgpu_device *adev)
3584 if (adev->gmc.xgmi.connected_to_cpu ||
3585 adev->gmc.is_app_apu)
3590 static int amdgpu_persistent_edc_harvesting(struct amdgpu_device *adev,
3591 struct ras_common_if *ras_block)
3593 struct ras_query_if info = {
3597 if (!amdgpu_persistent_edc_harvesting_supported(adev))
3600 if (amdgpu_ras_query_error_status(adev, &info) != 0)
3601 DRM_WARN("RAS init harvest failure");
3603 if (amdgpu_ras_reset_error_status(adev, ras_block->block) != 0)
3604 DRM_WARN("RAS init harvest reset failure");
3609 bool amdgpu_ras_is_poison_mode_supported(struct amdgpu_device *adev)
3611 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3616 return con->poison_supported;
3619 /* helper function to handle common stuff in ip late init phase */
3620 int amdgpu_ras_block_late_init(struct amdgpu_device *adev,
3621 struct ras_common_if *ras_block)
3623 struct amdgpu_ras_block_object *ras_obj = NULL;
3624 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3625 struct ras_query_if *query_info;
3626 unsigned long ue_count, ce_count;
3629 /* disable RAS feature per IP block if it is not supported */
3630 if (!amdgpu_ras_is_supported(adev, ras_block->block)) {
3631 amdgpu_ras_feature_enable_on_boot(adev, ras_block, 0);
3635 r = amdgpu_ras_feature_enable_on_boot(adev, ras_block, 1);
3637 if (adev->in_suspend || amdgpu_in_reset(adev)) {
3638 /* in resume phase, if fail to enable ras,
3639 * clean up all ras fs nodes, and disable ras */
3645 /* check for errors on warm reset edc persisant supported ASIC */
3646 amdgpu_persistent_edc_harvesting(adev, ras_block);
3648 /* in resume phase, no need to create ras fs node */
3649 if (adev->in_suspend || amdgpu_in_reset(adev))
3652 ras_obj = container_of(ras_block, struct amdgpu_ras_block_object, ras_comm);
3653 if (ras_obj->ras_cb || (ras_obj->hw_ops &&
3654 (ras_obj->hw_ops->query_poison_status ||
3655 ras_obj->hw_ops->handle_poison_consumption))) {
3656 r = amdgpu_ras_interrupt_add_handler(adev, ras_block);
3661 if (ras_obj->hw_ops &&
3662 (ras_obj->hw_ops->query_ras_error_count ||
3663 ras_obj->hw_ops->query_ras_error_status)) {
3664 r = amdgpu_ras_sysfs_create(adev, ras_block);
3668 /* Those are the cached values at init.
3670 query_info = kzalloc(sizeof(*query_info), GFP_KERNEL);
3673 memcpy(&query_info->head, ras_block, sizeof(struct ras_common_if));
3675 if (amdgpu_ras_query_error_count(adev, &ce_count, &ue_count, query_info) == 0) {
3676 atomic_set(&con->ras_ce_count, ce_count);
3677 atomic_set(&con->ras_ue_count, ue_count);
3686 if (ras_obj->ras_cb)
3687 amdgpu_ras_interrupt_remove_handler(adev, ras_block);
3689 amdgpu_ras_feature_enable(adev, ras_block, 0);
3693 static int amdgpu_ras_block_late_init_default(struct amdgpu_device *adev,
3694 struct ras_common_if *ras_block)
3696 return amdgpu_ras_block_late_init(adev, ras_block);
3699 /* helper function to remove ras fs node and interrupt handler */
3700 void amdgpu_ras_block_late_fini(struct amdgpu_device *adev,
3701 struct ras_common_if *ras_block)
3703 struct amdgpu_ras_block_object *ras_obj;
3707 amdgpu_ras_sysfs_remove(adev, ras_block);
3709 ras_obj = container_of(ras_block, struct amdgpu_ras_block_object, ras_comm);
3710 if (ras_obj->ras_cb)
3711 amdgpu_ras_interrupt_remove_handler(adev, ras_block);
3714 static void amdgpu_ras_block_late_fini_default(struct amdgpu_device *adev,
3715 struct ras_common_if *ras_block)
3717 return amdgpu_ras_block_late_fini(adev, ras_block);
3720 /* do some init work after IP late init as dependence.
3721 * and it runs in resume/gpu reset/booting up cases.
3723 void amdgpu_ras_resume(struct amdgpu_device *adev)
3725 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3726 struct ras_manager *obj, *tmp;
3728 if (!adev->ras_enabled || !con) {
3729 /* clean ras context for VEGA20 Gaming after send ras disable cmd */
3730 amdgpu_release_ras_context(adev);
3735 if (con->flags & AMDGPU_RAS_FLAG_INIT_BY_VBIOS) {
3736 /* Set up all other IPs which are not implemented. There is a
3737 * tricky thing that IP's actual ras error type should be
3738 * MULTI_UNCORRECTABLE, but as driver does not handle it, so
3739 * ERROR_NONE make sense anyway.
3741 amdgpu_ras_enable_all_features(adev, 1);
3743 /* We enable ras on all hw_supported block, but as boot
3744 * parameter might disable some of them and one or more IP has
3745 * not implemented yet. So we disable them on behalf.
3747 list_for_each_entry_safe(obj, tmp, &con->head, node) {
3748 if (!amdgpu_ras_is_supported(adev, obj->head.block)) {
3749 amdgpu_ras_feature_enable(adev, &obj->head, 0);
3750 /* there should be no any reference. */
3751 WARN_ON(alive_obj(obj));
3757 void amdgpu_ras_suspend(struct amdgpu_device *adev)
3759 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3761 if (!adev->ras_enabled || !con)
3764 amdgpu_ras_disable_all_features(adev, 0);
3765 /* Make sure all ras objects are disabled. */
3766 if (AMDGPU_RAS_GET_FEATURES(con->features))
3767 amdgpu_ras_disable_all_features(adev, 1);
3770 int amdgpu_ras_late_init(struct amdgpu_device *adev)
3772 struct amdgpu_ras_block_list *node, *tmp;
3773 struct amdgpu_ras_block_object *obj;
3776 amdgpu_ras_event_mgr_init(adev);
3778 if (amdgpu_ras_aca_is_supported(adev)) {
3779 if (amdgpu_in_reset(adev)) {
3780 if (amdgpu_aca_is_enabled(adev))
3781 r = amdgpu_aca_reset(adev);
3783 r = amdgpu_mca_reset(adev);
3788 if (!amdgpu_sriov_vf(adev)) {
3789 if (amdgpu_aca_is_enabled(adev))
3790 amdgpu_ras_set_aca_debug_mode(adev, false);
3792 amdgpu_ras_set_mca_debug_mode(adev, false);
3796 /* Guest side doesn't need init ras feature */
3797 if (amdgpu_sriov_vf(adev))
3800 list_for_each_entry_safe(node, tmp, &adev->ras_list, node) {
3801 obj = node->ras_obj;
3803 dev_warn(adev->dev, "Warning: abnormal ras list node.\n");
3807 if (!amdgpu_ras_is_supported(adev, obj->ras_comm.block))
3810 if (obj->ras_late_init) {
3811 r = obj->ras_late_init(adev, &obj->ras_comm);
3813 dev_err(adev->dev, "%s failed to execute ras_late_init! ret:%d\n",
3814 obj->ras_comm.name, r);
3818 amdgpu_ras_block_late_init_default(adev, &obj->ras_comm);
3824 /* do some fini work before IP fini as dependence */
3825 int amdgpu_ras_pre_fini(struct amdgpu_device *adev)
3827 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3829 if (!adev->ras_enabled || !con)
3833 /* Need disable ras on all IPs here before ip [hw/sw]fini */
3834 if (AMDGPU_RAS_GET_FEATURES(con->features))
3835 amdgpu_ras_disable_all_features(adev, 0);
3836 amdgpu_ras_recovery_fini(adev);
3840 int amdgpu_ras_fini(struct amdgpu_device *adev)
3842 struct amdgpu_ras_block_list *ras_node, *tmp;
3843 struct amdgpu_ras_block_object *obj = NULL;
3844 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3846 if (!adev->ras_enabled || !con)
3849 list_for_each_entry_safe(ras_node, tmp, &adev->ras_list, node) {
3850 if (ras_node->ras_obj) {
3851 obj = ras_node->ras_obj;
3852 if (amdgpu_ras_is_supported(adev, obj->ras_comm.block) &&
3854 obj->ras_fini(adev, &obj->ras_comm);
3856 amdgpu_ras_block_late_fini_default(adev, &obj->ras_comm);
3859 /* Clear ras blocks from ras_list and free ras block list node */
3860 list_del(&ras_node->node);
3864 amdgpu_ras_fs_fini(adev);
3865 amdgpu_ras_interrupt_remove_all(adev);
3867 if (amdgpu_ras_aca_is_supported(adev)) {
3868 if (amdgpu_aca_is_enabled(adev))
3869 amdgpu_aca_fini(adev);
3871 amdgpu_mca_fini(adev);
3874 WARN(AMDGPU_RAS_GET_FEATURES(con->features), "Feature mask is not cleared");
3876 if (AMDGPU_RAS_GET_FEATURES(con->features))
3877 amdgpu_ras_disable_all_features(adev, 0);
3879 cancel_delayed_work_sync(&con->ras_counte_delay_work);
3881 amdgpu_ras_set_context(adev, NULL);
3887 bool amdgpu_ras_get_fed_status(struct amdgpu_device *adev)
3889 struct amdgpu_ras *ras;
3891 ras = amdgpu_ras_get_context(adev);
3895 return atomic_read(&ras->fed);
3898 void amdgpu_ras_set_fed(struct amdgpu_device *adev, bool status)
3900 struct amdgpu_ras *ras;
3902 ras = amdgpu_ras_get_context(adev);
3904 atomic_set(&ras->fed, !!status);
3907 bool amdgpu_ras_event_id_is_valid(struct amdgpu_device *adev, u64 id)
3909 return !(id & BIT_ULL(63));
3912 u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type type)
3914 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
3918 case RAS_EVENT_TYPE_ISR:
3919 id = (u64)atomic64_read(&ras->event_mgr->seqnos[type]);
3921 case RAS_EVENT_TYPE_INVALID:
3923 id = BIT_ULL(63) | 0ULL;
3930 void amdgpu_ras_global_ras_isr(struct amdgpu_device *adev)
3932 if (atomic_cmpxchg(&amdgpu_ras_in_intr, 0, 1) == 0) {
3933 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
3934 u64 event_id = (u64)atomic64_inc_return(&ras->event_mgr->seqnos[RAS_EVENT_TYPE_ISR]);
3936 RAS_EVENT_LOG(adev, event_id, "uncorrectable hardware error"
3937 "(ERREVENT_ATHUB_INTERRUPT) detected!\n");
3939 amdgpu_ras_set_fed(adev, true);
3940 ras->gpu_reset_flags |= AMDGPU_RAS_GPU_RESET_MODE1_RESET;
3941 amdgpu_ras_reset_gpu(adev);
3945 bool amdgpu_ras_need_emergency_restart(struct amdgpu_device *adev)
3947 if (adev->asic_type == CHIP_VEGA20 &&
3948 adev->pm.fw_version <= 0x283400) {
3949 return !(amdgpu_asic_reset_method(adev) == AMD_RESET_METHOD_BACO) &&
3950 amdgpu_ras_intr_triggered();
3956 void amdgpu_release_ras_context(struct amdgpu_device *adev)
3958 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
3963 if (!adev->ras_enabled && con->features & BIT(AMDGPU_RAS_BLOCK__GFX)) {
3964 con->features &= ~BIT(AMDGPU_RAS_BLOCK__GFX);
3965 amdgpu_ras_set_context(adev, NULL);
3970 #ifdef CONFIG_X86_MCE_AMD
3971 static struct amdgpu_device *find_adev(uint32_t node_id)
3974 struct amdgpu_device *adev = NULL;
3976 for (i = 0; i < mce_adev_list.num_gpu; i++) {
3977 adev = mce_adev_list.devs[i];
3979 if (adev && adev->gmc.xgmi.connected_to_cpu &&
3980 adev->gmc.xgmi.physical_node_id == node_id)
3988 #define GET_MCA_IPID_GPUID(m) (((m) >> 44) & 0xF)
3989 #define GET_UMC_INST(m) (((m) >> 21) & 0x7)
3990 #define GET_CHAN_INDEX(m) ((((m) >> 12) & 0x3) | (((m) >> 18) & 0x4))
3991 #define GPU_ID_OFFSET 8
3993 static int amdgpu_bad_page_notifier(struct notifier_block *nb,
3994 unsigned long val, void *data)
3996 struct mce *m = (struct mce *)data;
3997 struct amdgpu_device *adev = NULL;
3998 uint32_t gpu_id = 0;
3999 uint32_t umc_inst = 0, ch_inst = 0;
4002 * If the error was generated in UMC_V2, which belongs to GPU UMCs,
4003 * and error occurred in DramECC (Extended error code = 0) then only
4004 * process the error, else bail out.
4006 if (!m || !((smca_get_bank_type(m->extcpu, m->bank) == SMCA_UMC_V2) &&
4007 (XEC(m->status, 0x3f) == 0x0)))
4011 * If it is correctable error, return.
4013 if (mce_is_correctable(m))
4017 * GPU Id is offset by GPU_ID_OFFSET in MCA_IPID_UMC register.
4019 gpu_id = GET_MCA_IPID_GPUID(m->ipid) - GPU_ID_OFFSET;
4021 adev = find_adev(gpu_id);
4023 DRM_WARN("%s: Unable to find adev for gpu_id: %d\n", __func__,
4029 * If it is uncorrectable error, then find out UMC instance and
4032 umc_inst = GET_UMC_INST(m->ipid);
4033 ch_inst = GET_CHAN_INDEX(m->ipid);
4035 dev_info(adev->dev, "Uncorrectable error detected in UMC inst: %d, chan_idx: %d",
4038 if (!amdgpu_umc_page_retirement_mca(adev, m->addr, ch_inst, umc_inst))
4044 static struct notifier_block amdgpu_bad_page_nb = {
4045 .notifier_call = amdgpu_bad_page_notifier,
4046 .priority = MCE_PRIO_UC,
4049 static void amdgpu_register_bad_pages_mca_notifier(struct amdgpu_device *adev)
4052 * Add the adev to the mce_adev_list.
4053 * During mode2 reset, amdgpu device is temporarily
4054 * removed from the mgpu_info list which can cause
4055 * page retirement to fail.
4056 * Use this list instead of mgpu_info to find the amdgpu
4057 * device on which the UMC error was reported.
4059 mce_adev_list.devs[mce_adev_list.num_gpu++] = adev;
4062 * Register the x86 notifier only once
4063 * with MCE subsystem.
4065 if (notifier_registered == false) {
4066 mce_register_decode_chain(&amdgpu_bad_page_nb);
4067 notifier_registered = true;
4072 struct amdgpu_ras *amdgpu_ras_get_context(struct amdgpu_device *adev)
4077 return adev->psp.ras_context.ras;
4080 int amdgpu_ras_set_context(struct amdgpu_device *adev, struct amdgpu_ras *ras_con)
4085 adev->psp.ras_context.ras = ras_con;
4089 /* check if ras is supported on block, say, sdma, gfx */
4090 int amdgpu_ras_is_supported(struct amdgpu_device *adev,
4094 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
4096 if (block >= AMDGPU_RAS_BLOCK_COUNT)
4099 ret = ras && (adev->ras_enabled & (1 << block));
4101 /* For the special asic with mem ecc enabled but sram ecc
4102 * not enabled, even if the ras block is not supported on
4103 * .ras_enabled, if the asic supports poison mode and the
4104 * ras block has ras configuration, it can be considered
4105 * that the ras block supports ras function.
4108 (block == AMDGPU_RAS_BLOCK__GFX ||
4109 block == AMDGPU_RAS_BLOCK__SDMA ||
4110 block == AMDGPU_RAS_BLOCK__VCN ||
4111 block == AMDGPU_RAS_BLOCK__JPEG) &&
4112 (amdgpu_ras_mask & (1 << block)) &&
4113 amdgpu_ras_is_poison_mode_supported(adev) &&
4114 amdgpu_ras_get_ras_block(adev, block, 0))
4120 int amdgpu_ras_reset_gpu(struct amdgpu_device *adev)
4122 struct amdgpu_ras *ras = amdgpu_ras_get_context(adev);
4124 /* mode1 is the only selection for RMA status */
4126 ras->gpu_reset_flags = 0;
4127 ras->gpu_reset_flags |= AMDGPU_RAS_GPU_RESET_MODE1_RESET;
4130 if (atomic_cmpxchg(&ras->in_recovery, 0, 1) == 0)
4131 amdgpu_reset_domain_schedule(ras->adev->reset_domain, &ras->recovery_work);
4135 int amdgpu_ras_set_mca_debug_mode(struct amdgpu_device *adev, bool enable)
4137 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
4141 ret = amdgpu_mca_smu_set_debug_mode(adev, enable);
4143 con->is_aca_debug_mode = enable;
4149 int amdgpu_ras_set_aca_debug_mode(struct amdgpu_device *adev, bool enable)
4151 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
4155 if (amdgpu_aca_is_enabled(adev))
4156 ret = amdgpu_aca_smu_set_debug_mode(adev, enable);
4158 ret = amdgpu_mca_smu_set_debug_mode(adev, enable);
4160 con->is_aca_debug_mode = enable;
4166 bool amdgpu_ras_get_aca_debug_mode(struct amdgpu_device *adev)
4168 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
4169 const struct aca_smu_funcs *smu_funcs = adev->aca.smu_funcs;
4170 const struct amdgpu_mca_smu_funcs *mca_funcs = adev->mca.mca_funcs;
4175 if ((amdgpu_aca_is_enabled(adev) && smu_funcs && smu_funcs->set_debug_mode) ||
4176 (!amdgpu_aca_is_enabled(adev) && mca_funcs && mca_funcs->mca_set_debug_mode))
4177 return con->is_aca_debug_mode;
4182 bool amdgpu_ras_get_error_query_mode(struct amdgpu_device *adev,
4183 unsigned int *error_query_mode)
4185 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
4186 const struct amdgpu_mca_smu_funcs *mca_funcs = adev->mca.mca_funcs;
4187 const struct aca_smu_funcs *smu_funcs = adev->aca.smu_funcs;
4190 *error_query_mode = AMDGPU_RAS_INVALID_ERROR_QUERY;
4194 if ((smu_funcs && smu_funcs->set_debug_mode) || (mca_funcs && mca_funcs->mca_set_debug_mode))
4196 (con->is_aca_debug_mode) ? AMDGPU_RAS_DIRECT_ERROR_QUERY : AMDGPU_RAS_FIRMWARE_ERROR_QUERY;
4198 *error_query_mode = AMDGPU_RAS_DIRECT_ERROR_QUERY;
4203 /* Register each ip ras block into amdgpu ras */
4204 int amdgpu_ras_register_ras_block(struct amdgpu_device *adev,
4205 struct amdgpu_ras_block_object *ras_block_obj)
4207 struct amdgpu_ras_block_list *ras_node;
4208 if (!adev || !ras_block_obj)
4211 ras_node = kzalloc(sizeof(*ras_node), GFP_KERNEL);
4215 INIT_LIST_HEAD(&ras_node->node);
4216 ras_node->ras_obj = ras_block_obj;
4217 list_add_tail(&ras_node->node, &adev->ras_list);
4222 void amdgpu_ras_get_error_type_name(uint32_t err_type, char *err_type_name)
4228 case AMDGPU_RAS_ERROR__SINGLE_CORRECTABLE:
4229 sprintf(err_type_name, "correctable");
4231 case AMDGPU_RAS_ERROR__MULTI_UNCORRECTABLE:
4232 sprintf(err_type_name, "uncorrectable");
4235 sprintf(err_type_name, "unknown");
4240 bool amdgpu_ras_inst_get_memory_id_field(struct amdgpu_device *adev,
4241 const struct amdgpu_ras_err_status_reg_entry *reg_entry,
4243 uint32_t *memory_id)
4245 uint32_t err_status_lo_data, err_status_lo_offset;
4250 err_status_lo_offset =
4251 AMDGPU_RAS_REG_ENTRY_OFFSET(reg_entry->hwip, instance,
4252 reg_entry->seg_lo, reg_entry->reg_lo);
4253 err_status_lo_data = RREG32(err_status_lo_offset);
4255 if ((reg_entry->flags & AMDGPU_RAS_ERR_STATUS_VALID) &&
4256 !REG_GET_FIELD(err_status_lo_data, ERR_STATUS_LO, ERR_STATUS_VALID_FLAG))
4259 *memory_id = REG_GET_FIELD(err_status_lo_data, ERR_STATUS_LO, MEMORY_ID);
4264 bool amdgpu_ras_inst_get_err_cnt_field(struct amdgpu_device *adev,
4265 const struct amdgpu_ras_err_status_reg_entry *reg_entry,
4267 unsigned long *err_cnt)
4269 uint32_t err_status_hi_data, err_status_hi_offset;
4274 err_status_hi_offset =
4275 AMDGPU_RAS_REG_ENTRY_OFFSET(reg_entry->hwip, instance,
4276 reg_entry->seg_hi, reg_entry->reg_hi);
4277 err_status_hi_data = RREG32(err_status_hi_offset);
4279 if ((reg_entry->flags & AMDGPU_RAS_ERR_INFO_VALID) &&
4280 !REG_GET_FIELD(err_status_hi_data, ERR_STATUS_HI, ERR_INFO_VALID_FLAG))
4281 /* keep the check here in case we need to refer to the result later */
4282 dev_dbg(adev->dev, "Invalid err_info field\n");
4284 /* read err count */
4285 *err_cnt = REG_GET_FIELD(err_status_hi_data, ERR_STATUS, ERR_CNT);
4290 void amdgpu_ras_inst_query_ras_error_count(struct amdgpu_device *adev,
4291 const struct amdgpu_ras_err_status_reg_entry *reg_list,
4292 uint32_t reg_list_size,
4293 const struct amdgpu_ras_memory_id_entry *mem_list,
4294 uint32_t mem_list_size,
4297 unsigned long *err_count)
4300 unsigned long err_cnt;
4301 char err_type_name[16];
4304 for (i = 0; i < reg_list_size; i++) {
4305 /* query memory_id from err_status_lo */
4306 if (!amdgpu_ras_inst_get_memory_id_field(adev, ®_list[i],
4307 instance, &memory_id))
4310 /* query err_cnt from err_status_hi */
4311 if (!amdgpu_ras_inst_get_err_cnt_field(adev, ®_list[i],
4312 instance, &err_cnt) ||
4316 *err_count += err_cnt;
4318 /* log the errors */
4319 amdgpu_ras_get_error_type_name(err_type, err_type_name);
4321 /* memory_list is not supported */
4323 "%ld %s hardware errors detected in %s, instance: %d, memory_id: %d\n",
4324 err_cnt, err_type_name,
4325 reg_list[i].block_name,
4326 instance, memory_id);
4328 for (j = 0; j < mem_list_size; j++) {
4329 if (memory_id == mem_list[j].memory_id) {
4331 "%ld %s hardware errors detected in %s, instance: %d, memory block: %s\n",
4332 err_cnt, err_type_name,
4333 reg_list[i].block_name,
4334 instance, mem_list[j].name);
4342 void amdgpu_ras_inst_reset_ras_error_count(struct amdgpu_device *adev,
4343 const struct amdgpu_ras_err_status_reg_entry *reg_list,
4344 uint32_t reg_list_size,
4347 uint32_t err_status_lo_offset, err_status_hi_offset;
4350 for (i = 0; i < reg_list_size; i++) {
4351 err_status_lo_offset =
4352 AMDGPU_RAS_REG_ENTRY_OFFSET(reg_list[i].hwip, instance,
4353 reg_list[i].seg_lo, reg_list[i].reg_lo);
4354 err_status_hi_offset =
4355 AMDGPU_RAS_REG_ENTRY_OFFSET(reg_list[i].hwip, instance,
4356 reg_list[i].seg_hi, reg_list[i].reg_hi);
4357 WREG32(err_status_lo_offset, 0);
4358 WREG32(err_status_hi_offset, 0);
4362 int amdgpu_ras_error_data_init(struct ras_err_data *err_data)
4364 memset(err_data, 0, sizeof(*err_data));
4366 INIT_LIST_HEAD(&err_data->err_node_list);
4371 static void amdgpu_ras_error_node_release(struct ras_err_node *err_node)
4376 list_del(&err_node->node);
4380 void amdgpu_ras_error_data_fini(struct ras_err_data *err_data)
4382 struct ras_err_node *err_node, *tmp;
4384 list_for_each_entry_safe(err_node, tmp, &err_data->err_node_list, node)
4385 amdgpu_ras_error_node_release(err_node);
4388 static struct ras_err_node *amdgpu_ras_error_find_node_by_id(struct ras_err_data *err_data,
4389 struct amdgpu_smuio_mcm_config_info *mcm_info)
4391 struct ras_err_node *err_node;
4392 struct amdgpu_smuio_mcm_config_info *ref_id;
4394 if (!err_data || !mcm_info)
4397 for_each_ras_error(err_node, err_data) {
4398 ref_id = &err_node->err_info.mcm_info;
4400 if (mcm_info->socket_id == ref_id->socket_id &&
4401 mcm_info->die_id == ref_id->die_id)
4408 static struct ras_err_node *amdgpu_ras_error_node_new(void)
4410 struct ras_err_node *err_node;
4412 err_node = kvzalloc(sizeof(*err_node), GFP_KERNEL);
4416 INIT_LIST_HEAD(&err_node->node);
4421 static int ras_err_info_cmp(void *priv, const struct list_head *a, const struct list_head *b)
4423 struct ras_err_node *nodea = container_of(a, struct ras_err_node, node);
4424 struct ras_err_node *nodeb = container_of(b, struct ras_err_node, node);
4425 struct amdgpu_smuio_mcm_config_info *infoa = &nodea->err_info.mcm_info;
4426 struct amdgpu_smuio_mcm_config_info *infob = &nodeb->err_info.mcm_info;
4428 if (unlikely(infoa->socket_id != infob->socket_id))
4429 return infoa->socket_id - infob->socket_id;
4431 return infoa->die_id - infob->die_id;
4436 static struct ras_err_info *amdgpu_ras_error_get_info(struct ras_err_data *err_data,
4437 struct amdgpu_smuio_mcm_config_info *mcm_info)
4439 struct ras_err_node *err_node;
4441 err_node = amdgpu_ras_error_find_node_by_id(err_data, mcm_info);
4443 return &err_node->err_info;
4445 err_node = amdgpu_ras_error_node_new();
4449 INIT_LIST_HEAD(&err_node->err_info.err_addr_list);
4451 memcpy(&err_node->err_info.mcm_info, mcm_info, sizeof(*mcm_info));
4453 err_data->err_list_count++;
4454 list_add_tail(&err_node->node, &err_data->err_node_list);
4455 list_sort(NULL, &err_data->err_node_list, ras_err_info_cmp);
4457 return &err_node->err_info;
4460 void amdgpu_ras_add_mca_err_addr(struct ras_err_info *err_info, struct ras_err_addr *err_addr)
4462 /* This function will be retired. */
4466 void amdgpu_ras_del_mca_err_addr(struct ras_err_info *err_info, struct ras_err_addr *mca_err_addr)
4468 list_del(&mca_err_addr->node);
4469 kfree(mca_err_addr);
4472 int amdgpu_ras_error_statistic_ue_count(struct ras_err_data *err_data,
4473 struct amdgpu_smuio_mcm_config_info *mcm_info,
4474 struct ras_err_addr *err_addr, u64 count)
4476 struct ras_err_info *err_info;
4478 if (!err_data || !mcm_info)
4484 err_info = amdgpu_ras_error_get_info(err_data, mcm_info);
4488 if (err_addr && err_addr->err_status)
4489 amdgpu_ras_add_mca_err_addr(err_info, err_addr);
4491 err_info->ue_count += count;
4492 err_data->ue_count += count;
4497 int amdgpu_ras_error_statistic_ce_count(struct ras_err_data *err_data,
4498 struct amdgpu_smuio_mcm_config_info *mcm_info,
4499 struct ras_err_addr *err_addr, u64 count)
4501 struct ras_err_info *err_info;
4503 if (!err_data || !mcm_info)
4509 err_info = amdgpu_ras_error_get_info(err_data, mcm_info);
4513 err_info->ce_count += count;
4514 err_data->ce_count += count;
4519 int amdgpu_ras_error_statistic_de_count(struct ras_err_data *err_data,
4520 struct amdgpu_smuio_mcm_config_info *mcm_info,
4521 struct ras_err_addr *err_addr, u64 count)
4523 struct ras_err_info *err_info;
4525 if (!err_data || !mcm_info)
4531 err_info = amdgpu_ras_error_get_info(err_data, mcm_info);
4535 if (err_addr && err_addr->err_status)
4536 amdgpu_ras_add_mca_err_addr(err_info, err_addr);
4538 err_info->de_count += count;
4539 err_data->de_count += count;
4544 #define mmMP0_SMN_C2PMSG_92 0x1609C
4545 #define mmMP0_SMN_C2PMSG_126 0x160BE
4546 static void amdgpu_ras_boot_time_error_reporting(struct amdgpu_device *adev,
4549 u32 socket_id, aid_id, hbm_id;
4554 /* The pattern for smn addressing in other SOC could be different from
4555 * the one for aqua_vanjaram. We should revisit the code if the pattern
4556 * is changed. In such case, replace the aqua_vanjaram implementation
4557 * with more common helper */
4558 reg_addr = (mmMP0_SMN_C2PMSG_92 << 2) +
4559 aqua_vanjaram_encode_ext_smn_addressing(instance);
4560 fw_status = amdgpu_device_indirect_rreg_ext(adev, reg_addr);
4562 reg_addr = (mmMP0_SMN_C2PMSG_126 << 2) +
4563 aqua_vanjaram_encode_ext_smn_addressing(instance);
4564 boot_error = amdgpu_device_indirect_rreg_ext(adev, reg_addr);
4566 socket_id = AMDGPU_RAS_GPU_ERR_SOCKET_ID(boot_error);
4567 aid_id = AMDGPU_RAS_GPU_ERR_AID_ID(boot_error);
4568 hbm_id = ((1 == AMDGPU_RAS_GPU_ERR_HBM_ID(boot_error)) ? 0 : 1);
4570 if (AMDGPU_RAS_GPU_ERR_MEM_TRAINING(boot_error))
4572 "socket: %d, aid: %d, hbm: %d, fw_status: 0x%x, memory training failed\n",
4573 socket_id, aid_id, hbm_id, fw_status);
4575 if (AMDGPU_RAS_GPU_ERR_FW_LOAD(boot_error))
4577 "socket: %d, aid: %d, fw_status: 0x%x, firmware load failed at boot time\n",
4578 socket_id, aid_id, fw_status);
4580 if (AMDGPU_RAS_GPU_ERR_WAFL_LINK_TRAINING(boot_error))
4582 "socket: %d, aid: %d, fw_status: 0x%x, wafl link training failed\n",
4583 socket_id, aid_id, fw_status);
4585 if (AMDGPU_RAS_GPU_ERR_XGMI_LINK_TRAINING(boot_error))
4587 "socket: %d, aid: %d, fw_status: 0x%x, xgmi link training failed\n",
4588 socket_id, aid_id, fw_status);
4590 if (AMDGPU_RAS_GPU_ERR_USR_CP_LINK_TRAINING(boot_error))
4592 "socket: %d, aid: %d, fw_status: 0x%x, usr cp link training failed\n",
4593 socket_id, aid_id, fw_status);
4595 if (AMDGPU_RAS_GPU_ERR_USR_DP_LINK_TRAINING(boot_error))
4597 "socket: %d, aid: %d, fw_status: 0x%x, usr dp link training failed\n",
4598 socket_id, aid_id, fw_status);
4600 if (AMDGPU_RAS_GPU_ERR_HBM_MEM_TEST(boot_error))
4602 "socket: %d, aid: %d, hbm: %d, fw_status: 0x%x, hbm memory test failed\n",
4603 socket_id, aid_id, hbm_id, fw_status);
4605 if (AMDGPU_RAS_GPU_ERR_HBM_BIST_TEST(boot_error))
4607 "socket: %d, aid: %d, hbm: %d, fw_status: 0x%x, hbm bist test failed\n",
4608 socket_id, aid_id, hbm_id, fw_status);
4611 static bool amdgpu_ras_boot_error_detected(struct amdgpu_device *adev,
4618 reg_addr = (mmMP0_SMN_C2PMSG_92 << 2) +
4619 aqua_vanjaram_encode_ext_smn_addressing(instance);
4621 for (retry_loop = 0; retry_loop < AMDGPU_RAS_BOOT_STATUS_POLLING_LIMIT; retry_loop++) {
4622 reg_data = amdgpu_device_indirect_rreg_ext(adev, reg_addr);
4623 if ((reg_data & AMDGPU_RAS_BOOT_STATUS_MASK) == AMDGPU_RAS_BOOT_STEADY_STATUS)
4632 void amdgpu_ras_query_boot_status(struct amdgpu_device *adev, u32 num_instances)
4636 for (i = 0; i < num_instances; i++) {
4637 if (amdgpu_ras_boot_error_detected(adev, i))
4638 amdgpu_ras_boot_time_error_reporting(adev, i);
4642 int amdgpu_ras_reserve_page(struct amdgpu_device *adev, uint64_t pfn)
4644 struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
4645 struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
4646 uint64_t start = pfn << AMDGPU_GPU_PAGE_SHIFT;
4649 mutex_lock(&con->page_rsv_lock);
4650 ret = amdgpu_vram_mgr_query_page_status(mgr, start);
4652 ret = amdgpu_vram_mgr_reserve_range(mgr, start, AMDGPU_GPU_PAGE_SIZE);
4653 mutex_unlock(&con->page_rsv_lock);
4658 void amdgpu_ras_event_log_print(struct amdgpu_device *adev, u64 event_id,
4659 const char *fmt, ...)
4661 struct va_format vaf;
4664 va_start(args, fmt);
4668 if (amdgpu_ras_event_id_is_valid(adev, event_id))
4669 dev_printk(KERN_INFO, adev->dev, "{%llu}%pV", event_id, &vaf);
4671 dev_printk(KERN_INFO, adev->dev, "%pV", &vaf);