#include <linux/debugfs.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/uaccess.h>
#include <linux/reboot.h>
#include <linux/syscalls.h>
#include <linux/pm_runtime.h>
#include <linux/list_sort.h>
#include "amdgpu.h"
#include "amdgpu_ras.h"
#include "amdgpu_atomfirmware.h"
#include "amdgpu_xgmi.h"
#include "ivsrcid/nbio/irqsrcs_nbif_7_4.h"
#include "nbio_v4_3.h"
#include "nbio_v7_9.h"
#include "atom.h"
#include "amdgpu_reset.h"
#include "amdgpu_psp.h"
#ifdef CONFIG_X86_MCE_AMD
#include <asm/mce.h>
static bool notifier_registered;
#endif
static const char *RAS_FS_NAME = …;
const char *ras_error_string[] = …;
const char *ras_block_string[] = …;
const char *ras_mca_block_string[] = …;
struct amdgpu_ras_block_list { … };
const char *get_ras_block_str(struct ras_common_if *ras_block)
{ … }
#define ras_block_str(_BLOCK_) …
#define ras_err_str(i) …
#define RAS_DEFAULT_FLAGS …
#define RAS_UMC_INJECT_ADDR_LIMIT …
#define RAS_BAD_PAGE_COVER …
#define MAX_UMC_POISON_POLLING_TIME_ASYNC …
#define AMDGPU_RAS_RETIRE_PAGE_INTERVAL …
#define MAX_FLUSH_RETIRE_DWORK_TIMES …
enum amdgpu_ras_retire_page_reservation { … };
atomic_t amdgpu_ras_in_intr = …;
static bool amdgpu_ras_check_bad_page_unlock(struct amdgpu_ras *con,
uint64_t addr);
static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
uint64_t addr);
#ifdef CONFIG_X86_MCE_AMD
static void amdgpu_register_bad_pages_mca_notifier(struct amdgpu_device *adev);
struct mce_notifier_adev_list { … };
static struct mce_notifier_adev_list mce_adev_list;
#endif
void amdgpu_ras_set_error_query_ready(struct amdgpu_device *adev, bool ready)
{ … }
static bool amdgpu_ras_get_error_query_ready(struct amdgpu_device *adev)
{ … }
static int amdgpu_reserve_page_direct(struct amdgpu_device *adev, uint64_t address)
{ … }
static ssize_t amdgpu_ras_debugfs_read(struct file *f, char __user *buf,
size_t size, loff_t *pos)
{ … }
static const struct file_operations amdgpu_ras_debugfs_ops = …;
static int amdgpu_ras_find_block_id_by_name(const char *name, int *block_id)
{ … }
static int amdgpu_ras_debugfs_ctrl_parse_data(struct file *f,
const char __user *buf, size_t size,
loff_t *pos, struct ras_debug_if *data)
{ … }
static void amdgpu_ras_instance_mask_check(struct amdgpu_device *adev,
struct ras_debug_if *data)
{ … }
static ssize_t amdgpu_ras_debugfs_ctrl_write(struct file *f,
const char __user *buf,
size_t size, loff_t *pos)
{ … }
static ssize_t amdgpu_ras_debugfs_eeprom_write(struct file *f,
const char __user *buf,
size_t size, loff_t *pos)
{ … }
static const struct file_operations amdgpu_ras_debugfs_ctrl_ops = …;
static const struct file_operations amdgpu_ras_debugfs_eeprom_ops = …;
static ssize_t amdgpu_ras_sysfs_read(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
#define get_obj(obj) …
#define alive_obj(obj) …
static inline void put_obj(struct ras_manager *obj)
{ … }
static struct ras_manager *amdgpu_ras_create_obj(struct amdgpu_device *adev,
struct ras_common_if *head)
{ … }
struct ras_manager *amdgpu_ras_find_obj(struct amdgpu_device *adev,
struct ras_common_if *head)
{ … }
static int amdgpu_ras_is_feature_allowed(struct amdgpu_device *adev,
struct ras_common_if *head)
{ … }
static int amdgpu_ras_is_feature_enabled(struct amdgpu_device *adev,
struct ras_common_if *head)
{ … }
static int __amdgpu_ras_feature_enable(struct amdgpu_device *adev,
struct ras_common_if *head, int enable)
{ … }
int amdgpu_ras_feature_enable(struct amdgpu_device *adev,
struct ras_common_if *head, bool enable)
{ … }
int amdgpu_ras_feature_enable_on_boot(struct amdgpu_device *adev,
struct ras_common_if *head, bool enable)
{ … }
static int amdgpu_ras_disable_all_features(struct amdgpu_device *adev,
bool bypass)
{ … }
static int amdgpu_ras_enable_all_features(struct amdgpu_device *adev,
bool bypass)
{ … }
static int amdgpu_ras_block_match_default(struct amdgpu_ras_block_object *block_obj,
enum amdgpu_ras_block block)
{ … }
static struct amdgpu_ras_block_object *amdgpu_ras_get_ras_block(struct amdgpu_device *adev,
enum amdgpu_ras_block block, uint32_t sub_block_index)
{ … }
static void amdgpu_ras_get_ecc_info(struct amdgpu_device *adev, struct ras_err_data *err_data)
{ … }
static void amdgpu_ras_error_print_error_data(struct amdgpu_device *adev,
struct ras_manager *ras_mgr,
struct ras_err_data *err_data,
struct ras_query_context *qctx,
const char *blk_name,
bool is_ue,
bool is_de)
{ … }
static inline bool err_data_has_source_info(struct ras_err_data *data)
{ … }
static void amdgpu_ras_error_generate_report(struct amdgpu_device *adev,
struct ras_query_if *query_if,
struct ras_err_data *err_data,
struct ras_query_context *qctx)
{ … }
static void amdgpu_rasmgr_error_data_statistic_update(struct ras_manager *obj, struct ras_err_data *err_data)
{ … }
static struct ras_manager *get_ras_manager(struct amdgpu_device *adev, enum amdgpu_ras_block blk)
{ … }
int amdgpu_ras_bind_aca(struct amdgpu_device *adev, enum amdgpu_ras_block blk,
const struct aca_info *aca_info, void *data)
{ … }
int amdgpu_ras_unbind_aca(struct amdgpu_device *adev, enum amdgpu_ras_block blk)
{ … }
static int amdgpu_aca_log_ras_error_data(struct amdgpu_device *adev, enum amdgpu_ras_block blk,
enum aca_error_type type, struct ras_err_data *err_data,
struct ras_query_context *qctx)
{ … }
ssize_t amdgpu_ras_aca_sysfs_read(struct device *dev, struct device_attribute *attr,
struct aca_handle *handle, char *buf, void *data)
{ … }
static int amdgpu_ras_query_error_status_helper(struct amdgpu_device *adev,
struct ras_query_if *info,
struct ras_err_data *err_data,
struct ras_query_context *qctx,
unsigned int error_query_mode)
{ … }
static int amdgpu_ras_query_error_status_with_event(struct amdgpu_device *adev,
struct ras_query_if *info,
enum ras_event_type type)
{ … }
int amdgpu_ras_query_error_status(struct amdgpu_device *adev, struct ras_query_if *info)
{ … }
int amdgpu_ras_reset_error_count(struct amdgpu_device *adev,
enum amdgpu_ras_block block)
{ … }
int amdgpu_ras_reset_error_status(struct amdgpu_device *adev,
enum amdgpu_ras_block block)
{ … }
int amdgpu_ras_error_inject(struct amdgpu_device *adev,
struct ras_inject_if *info)
{ … }
static int amdgpu_ras_query_error_count_helper(struct amdgpu_device *adev,
unsigned long *ce_count,
unsigned long *ue_count,
struct ras_query_if *query_info)
{ … }
int amdgpu_ras_query_error_count(struct amdgpu_device *adev,
unsigned long *ce_count,
unsigned long *ue_count,
struct ras_query_if *query_info)
{ … }
static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
struct ras_badpage **bps, unsigned int *count);
static char *amdgpu_ras_badpage_flags_str(unsigned int flags)
{ … }
static ssize_t amdgpu_ras_sysfs_badpages_read(struct file *f,
struct kobject *kobj, struct bin_attribute *attr,
char *buf, loff_t ppos, size_t count)
{ … }
static ssize_t amdgpu_ras_sysfs_features_read(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static ssize_t amdgpu_ras_sysfs_version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static ssize_t amdgpu_ras_sysfs_schema_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static struct { … } dump_event[] = …;
static ssize_t amdgpu_ras_sysfs_event_state_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ … }
static void amdgpu_ras_sysfs_remove_bad_page_node(struct amdgpu_device *adev)
{ … }
static int amdgpu_ras_sysfs_remove_dev_attr_node(struct amdgpu_device *adev)
{ … }
int amdgpu_ras_sysfs_create(struct amdgpu_device *adev,
struct ras_common_if *head)
{ … }
int amdgpu_ras_sysfs_remove(struct amdgpu_device *adev,
struct ras_common_if *head)
{ … }
static int amdgpu_ras_sysfs_remove_all(struct amdgpu_device *adev)
{ … }
static struct dentry *amdgpu_ras_debugfs_create_ctrl_node(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_debugfs_create(struct amdgpu_device *adev,
struct ras_fs_if *head,
struct dentry *dir)
{ … }
static bool amdgpu_ras_aca_is_supported(struct amdgpu_device *adev)
{ … }
void amdgpu_ras_debugfs_create_all(struct amdgpu_device *adev)
{ … }
static BIN_ATTR(gpu_vram_bad_pages, S_IRUGO,
amdgpu_ras_sysfs_badpages_read, NULL, 0);
static DEVICE_ATTR(features, S_IRUGO,
amdgpu_ras_sysfs_features_read, NULL);
static DEVICE_ATTR(version, 0444,
amdgpu_ras_sysfs_version_show, NULL);
static DEVICE_ATTR(schema, 0444,
amdgpu_ras_sysfs_schema_show, NULL);
static DEVICE_ATTR(event_state, 0444,
amdgpu_ras_sysfs_event_state_show, NULL);
static int amdgpu_ras_fs_init(struct amdgpu_device *adev)
{ … }
static int amdgpu_ras_fs_fini(struct amdgpu_device *adev)
{ … }
void amdgpu_ras_interrupt_fatal_error_handler(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_interrupt_poison_consumption_handler(struct ras_manager *obj,
struct amdgpu_iv_entry *entry)
{ … }
static void amdgpu_ras_interrupt_poison_creation_handler(struct ras_manager *obj,
struct amdgpu_iv_entry *entry)
{ … }
static void amdgpu_ras_interrupt_umc_handler(struct ras_manager *obj,
struct amdgpu_iv_entry *entry)
{ … }
static void amdgpu_ras_interrupt_handler(struct ras_manager *obj)
{ … }
static void amdgpu_ras_interrupt_process_handler(struct work_struct *work)
{ … }
int amdgpu_ras_interrupt_dispatch(struct amdgpu_device *adev,
struct ras_dispatch_if *info)
{ … }
int amdgpu_ras_interrupt_remove_handler(struct amdgpu_device *adev,
struct ras_common_if *head)
{ … }
int amdgpu_ras_interrupt_add_handler(struct amdgpu_device *adev,
struct ras_common_if *head)
{ … }
static int amdgpu_ras_interrupt_remove_all(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_log_on_err_counter(struct amdgpu_device *adev, enum ras_event_type type)
{ … }
static void amdgpu_ras_error_status_query(struct amdgpu_device *adev,
struct ras_query_if *info)
{ … }
static void amdgpu_ras_query_err_status(struct amdgpu_device *adev)
{ … }
static int amdgpu_ras_badpages_read(struct amdgpu_device *adev,
struct ras_badpage **bps, unsigned int *count)
{ … }
static void amdgpu_ras_set_fed_all(struct amdgpu_device *adev,
struct amdgpu_hive_info *hive, bool status)
{ … }
bool amdgpu_ras_in_recovery(struct amdgpu_device *adev)
{ … }
static enum ras_event_type amdgpu_ras_get_fatal_error_event(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_do_recovery(struct work_struct *work)
{ … }
static int amdgpu_ras_realloc_eh_data_space(struct amdgpu_device *adev,
struct ras_err_handler_data *data, int pages)
{ … }
int amdgpu_ras_add_bad_pages(struct amdgpu_device *adev,
struct eeprom_table_record *bps, int pages)
{ … }
int amdgpu_ras_save_bad_pages(struct amdgpu_device *adev,
unsigned long *new_cnt)
{ … }
static int amdgpu_ras_load_bad_pages(struct amdgpu_device *adev)
{ … }
static bool amdgpu_ras_check_bad_page_unlock(struct amdgpu_ras *con,
uint64_t addr)
{ … }
static bool amdgpu_ras_check_bad_page(struct amdgpu_device *adev,
uint64_t addr)
{ … }
static void amdgpu_ras_validate_threshold(struct amdgpu_device *adev,
uint32_t max_count)
{ … }
int amdgpu_ras_put_poison_req(struct amdgpu_device *adev,
enum amdgpu_ras_block block, uint16_t pasid,
pasid_notify pasid_fn, void *data, uint32_t reset)
{ … }
static int amdgpu_ras_get_poison_req(struct amdgpu_device *adev,
struct ras_poison_msg *poison_msg)
{ … }
static void amdgpu_ras_ecc_log_init(struct ras_ecc_log_info *ecc_log)
{ … }
static void amdgpu_ras_ecc_log_fini(struct ras_ecc_log_info *ecc_log)
{ … }
static bool amdgpu_ras_schedule_retirement_dwork(struct amdgpu_ras *con,
uint32_t delayed_ms)
{ … }
static void amdgpu_ras_do_page_retirement(struct work_struct *work)
{ … }
static int amdgpu_ras_poison_creation_handler(struct amdgpu_device *adev,
uint32_t poison_creation_count)
{ … }
static void amdgpu_ras_clear_poison_fifo(struct amdgpu_device *adev)
{ … }
static int amdgpu_ras_poison_consumption_handler(struct amdgpu_device *adev,
uint32_t msg_count, uint32_t *gpu_reset)
{ … }
static int amdgpu_ras_page_retirement_thread(void *param)
{ … }
int amdgpu_ras_recovery_init(struct amdgpu_device *adev)
{ … }
static int amdgpu_ras_recovery_fini(struct amdgpu_device *adev)
{ … }
static bool amdgpu_ras_asic_supported(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_get_quirks(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_query_ras_capablity_from_vbios(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_query_poison_mode(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_check_supported(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_counte_dw(struct work_struct *work)
{ … }
static int amdgpu_get_ras_schema(struct amdgpu_device *adev)
{ … }
static void ras_event_mgr_init(struct ras_event_manager *mgr)
{ … }
static void amdgpu_ras_event_mgr_init(struct amdgpu_device *adev)
{ … }
static void amdgpu_ras_init_reserved_vram_size(struct amdgpu_device *adev)
{ … }
int amdgpu_ras_init(struct amdgpu_device *adev)
{ … }
int amdgpu_persistent_edc_harvesting_supported(struct amdgpu_device *adev)
{ … }
static int amdgpu_persistent_edc_harvesting(struct amdgpu_device *adev,
struct ras_common_if *ras_block)
{ … }
bool amdgpu_ras_is_poison_mode_supported(struct amdgpu_device *adev)
{ … }
int amdgpu_ras_block_late_init(struct amdgpu_device *adev,
struct ras_common_if *ras_block)
{ … }
static int amdgpu_ras_block_late_init_default(struct amdgpu_device *adev,
struct ras_common_if *ras_block)
{ … }
void amdgpu_ras_block_late_fini(struct amdgpu_device *adev,
struct ras_common_if *ras_block)
{ … }
static void amdgpu_ras_block_late_fini_default(struct amdgpu_device *adev,
struct ras_common_if *ras_block)
{ … }
void amdgpu_ras_resume(struct amdgpu_device *adev)
{ … }
void amdgpu_ras_suspend(struct amdgpu_device *adev)
{ … }
int amdgpu_ras_late_init(struct amdgpu_device *adev)
{ … }
int amdgpu_ras_pre_fini(struct amdgpu_device *adev)
{ … }
int amdgpu_ras_fini(struct amdgpu_device *adev)
{ … }
bool amdgpu_ras_get_fed_status(struct amdgpu_device *adev)
{ … }
void amdgpu_ras_set_fed(struct amdgpu_device *adev, bool status)
{ … }
static struct ras_event_manager *__get_ras_event_mgr(struct amdgpu_device *adev)
{ … }
int amdgpu_ras_mark_ras_event_caller(struct amdgpu_device *adev, enum ras_event_type type,
const void *caller)
{ … }
u64 amdgpu_ras_acquire_event_id(struct amdgpu_device *adev, enum ras_event_type type)
{ … }
void amdgpu_ras_global_ras_isr(struct amdgpu_device *adev)
{ … }
bool amdgpu_ras_need_emergency_restart(struct amdgpu_device *adev)
{ … }
void amdgpu_release_ras_context(struct amdgpu_device *adev)
{ … }
#ifdef CONFIG_X86_MCE_AMD
static struct amdgpu_device *find_adev(uint32_t node_id)
{ … }
#define GET_MCA_IPID_GPUID(m) …
#define GET_UMC_INST(m) …
#define GET_CHAN_INDEX(m) …
#define GPU_ID_OFFSET …
static int amdgpu_bad_page_notifier(struct notifier_block *nb,
unsigned long val, void *data)
{ … }
static struct notifier_block amdgpu_bad_page_nb = …;
static void amdgpu_register_bad_pages_mca_notifier(struct amdgpu_device *adev)
{ … }
#endif
struct amdgpu_ras *amdgpu_ras_get_context(struct amdgpu_device *adev)
{ … }
int amdgpu_ras_set_context(struct amdgpu_device *adev, struct amdgpu_ras *ras_con)
{ … }
int amdgpu_ras_is_supported(struct amdgpu_device *adev,
unsigned int block)
{ … }
int amdgpu_ras_reset_gpu(struct amdgpu_device *adev)
{ … }
int amdgpu_ras_set_mca_debug_mode(struct amdgpu_device *adev, bool enable)
{ … }
int amdgpu_ras_set_aca_debug_mode(struct amdgpu_device *adev, bool enable)
{ … }
bool amdgpu_ras_get_aca_debug_mode(struct amdgpu_device *adev)
{ … }
bool amdgpu_ras_get_error_query_mode(struct amdgpu_device *adev,
unsigned int *error_query_mode)
{ … }
int amdgpu_ras_register_ras_block(struct amdgpu_device *adev,
struct amdgpu_ras_block_object *ras_block_obj)
{ … }
void amdgpu_ras_get_error_type_name(uint32_t err_type, char *err_type_name)
{ … }
bool amdgpu_ras_inst_get_memory_id_field(struct amdgpu_device *adev,
const struct amdgpu_ras_err_status_reg_entry *reg_entry,
uint32_t instance,
uint32_t *memory_id)
{ … }
bool amdgpu_ras_inst_get_err_cnt_field(struct amdgpu_device *adev,
const struct amdgpu_ras_err_status_reg_entry *reg_entry,
uint32_t instance,
unsigned long *err_cnt)
{ … }
void amdgpu_ras_inst_query_ras_error_count(struct amdgpu_device *adev,
const struct amdgpu_ras_err_status_reg_entry *reg_list,
uint32_t reg_list_size,
const struct amdgpu_ras_memory_id_entry *mem_list,
uint32_t mem_list_size,
uint32_t instance,
uint32_t err_type,
unsigned long *err_count)
{ … }
void amdgpu_ras_inst_reset_ras_error_count(struct amdgpu_device *adev,
const struct amdgpu_ras_err_status_reg_entry *reg_list,
uint32_t reg_list_size,
uint32_t instance)
{ … }
int amdgpu_ras_error_data_init(struct ras_err_data *err_data)
{ … }
static void amdgpu_ras_error_node_release(struct ras_err_node *err_node)
{ … }
void amdgpu_ras_error_data_fini(struct ras_err_data *err_data)
{ … }
static struct ras_err_node *amdgpu_ras_error_find_node_by_id(struct ras_err_data *err_data,
struct amdgpu_smuio_mcm_config_info *mcm_info)
{ … }
static struct ras_err_node *amdgpu_ras_error_node_new(void)
{ … }
static int ras_err_info_cmp(void *priv, const struct list_head *a, const struct list_head *b)
{ … }
static struct ras_err_info *amdgpu_ras_error_get_info(struct ras_err_data *err_data,
struct amdgpu_smuio_mcm_config_info *mcm_info)
{ … }
void amdgpu_ras_add_mca_err_addr(struct ras_err_info *err_info, struct ras_err_addr *err_addr)
{ … }
void amdgpu_ras_del_mca_err_addr(struct ras_err_info *err_info, struct ras_err_addr *mca_err_addr)
{ … }
int amdgpu_ras_error_statistic_ue_count(struct ras_err_data *err_data,
struct amdgpu_smuio_mcm_config_info *mcm_info,
struct ras_err_addr *err_addr, u64 count)
{ … }
int amdgpu_ras_error_statistic_ce_count(struct ras_err_data *err_data,
struct amdgpu_smuio_mcm_config_info *mcm_info,
struct ras_err_addr *err_addr, u64 count)
{ … }
int amdgpu_ras_error_statistic_de_count(struct ras_err_data *err_data,
struct amdgpu_smuio_mcm_config_info *mcm_info,
struct ras_err_addr *err_addr, u64 count)
{ … }
#define mmMP0_SMN_C2PMSG_92 …
#define mmMP0_SMN_C2PMSG_126 …
static void amdgpu_ras_boot_time_error_reporting(struct amdgpu_device *adev,
u32 instance)
{ … }
static bool amdgpu_ras_boot_error_detected(struct amdgpu_device *adev,
u32 instance)
{ … }
void amdgpu_ras_query_boot_status(struct amdgpu_device *adev, u32 num_instances)
{ … }
int amdgpu_ras_reserve_page(struct amdgpu_device *adev, uint64_t pfn)
{ … }
void amdgpu_ras_event_log_print(struct amdgpu_device *adev, u64 event_id,
const char *fmt, ...)
{ … }