#include <linux/interrupt.h>
#include <linux/notifier.h>
#include <linux/kobject.h>
#include <linux/percpu.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/sysfs.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/cpu.h>
#include <linux/smp.h>
#include <linux/string.h>
#include <asm/amd_nb.h>
#include <asm/traps.h>
#include <asm/apic.h>
#include <asm/mce.h>
#include <asm/msr.h>
#include <asm/trace/irq_vectors.h>
#include "internal.h"
#define NR_BLOCKS …
#define THRESHOLD_MAX …
#define INT_TYPE_APIC …
#define MASK_VALID_HI …
#define MASK_CNTP_HI …
#define MASK_LOCKED_HI …
#define MASK_LVTOFF_HI …
#define MASK_COUNT_EN_HI …
#define MASK_INT_TYPE_HI …
#define MASK_OVERFLOW_HI …
#define MASK_ERR_COUNT_HI …
#define MASK_BLKPTR_LO …
#define MCG_XBLK_ADDR …
#define MSR_CU_DEF_ERR …
#define MASK_DEF_LVTOFF …
#define MASK_DEF_INT_TYPE …
#define DEF_LVT_OFF …
#define DEF_INT_TYPE_APIC …
#define SMCA_THR_LVT_OFF …
static bool thresholding_irq_en;
static const char * const th_names[] = …;
static const char * const smca_umc_block_names[] = …;
#define HWID_MCATYPE(hwid, mcatype) …
struct smca_hwid { … };
struct smca_bank { … };
static DEFINE_PER_CPU_READ_MOSTLY(struct smca_bank[MAX_NR_BANKS], smca_banks);
static DEFINE_PER_CPU_READ_MOSTLY(u8[N_SMCA_BANK_TYPES], smca_bank_counts);
static const char * const smca_names[] = …;
static const char *smca_get_name(enum smca_bank_types t)
{ … }
enum smca_bank_types smca_get_bank_type(unsigned int cpu, unsigned int bank)
{ … }
EXPORT_SYMBOL_GPL(…);
static const struct smca_hwid smca_hwid_mcatypes[] = …;
#define MAX_MCATYPE_NAME_LEN …
static char buf_mcatype[MAX_MCATYPE_NAME_LEN];
static DEFINE_PER_CPU(struct threshold_bank **, threshold_banks);
static DEFINE_PER_CPU(u64, bank_map);
static DEFINE_PER_CPU(u64, smca_misc_banks_map);
static void amd_threshold_interrupt(void);
static void amd_deferred_error_interrupt(void);
static void default_deferred_error_interrupt(void)
{ … }
void (*deferred_error_int_vector)(void) = …;
static void smca_set_misc_banks_map(unsigned int bank, unsigned int cpu)
{ … }
static void smca_configure(unsigned int bank, unsigned int cpu)
{ … }
struct thresh_restart { … };
static inline bool is_shared_bank(int bank)
{ … }
static const char *bank4_names(const struct threshold_block *b)
{
switch (b->address) {
case 0x00000413:
return "dram";
case 0xc0000408:
return "ht_links";
case 0xc0000409:
return "l3_cache";
default:
WARN(1, "Funny MSR: 0x%08x\n", b->address);
return "";
}
};
static bool lvt_interrupt_supported(unsigned int bank, u32 msr_high_bits)
{ … }
static int lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
{
int msr = (hi & MASK_LVTOFF_HI) >> 20;
if (apic < 0) {
pr_err(FW_BUG "cpu %d, failed to setup threshold interrupt "
"for bank %d, block %d (MSR%08X=0x%x%08x)\n", b->cpu,
b->bank, b->block, b->address, hi, lo);
return 0;
}
if (apic != msr) {
if (mce_flags.smca)
return 0;
pr_err(FW_BUG "cpu %d, invalid threshold interrupt offset %d "
"for bank %d, block %d (MSR%08X=0x%x%08x)\n",
b->cpu, apic, b->bank, b->block, b->address, hi, lo);
return 0;
}
return 1;
};
static void threshold_restart_bank(void *_tr)
{ … }
static void mce_threshold_block_init(struct threshold_block *b, int offset)
{
struct thresh_restart tr = {
.b = b,
.set_lvt_off = 1,
.lvt_off = offset,
};
b->threshold_limit = THRESHOLD_MAX;
threshold_restart_bank(&tr);
};
static int setup_APIC_mce_threshold(int reserved, int new)
{ … }
static int setup_APIC_deferred_error(int reserved, int new)
{ … }
static void deferred_error_interrupt_enable(struct cpuinfo_x86 *c)
{ … }
static u32 smca_get_block_address(unsigned int bank, unsigned int block,
unsigned int cpu)
{ … }
static u32 get_block_address(u32 current_addr, u32 low, u32 high,
unsigned int bank, unsigned int block,
unsigned int cpu)
{ … }
static int
prepare_threshold_block(unsigned int bank, unsigned int block, u32 addr,
int offset, u32 misc_high)
{ … }
bool amd_filter_mce(struct mce *m)
{ … }
static void disable_err_thresholding(struct cpuinfo_x86 *c, unsigned int bank)
{ … }
void mce_amd_feature_init(struct cpuinfo_x86 *c)
{ … }
static bool legacy_mce_is_memory_error(struct mce *m)
{ … }
static bool smca_mce_is_memory_error(struct mce *m)
{ … }
bool amd_mce_is_memory_error(struct mce *m)
{ … }
bool amd_mce_usable_address(struct mce *m)
{ … }
static void __log_error(unsigned int bank, u64 status, u64 addr, u64 misc)
{ … }
DEFINE_IDTENTRY_SYSVEC(sysvec_deferred_error)
{ … }
static inline bool
_log_error_bank(unsigned int bank, u32 msr_stat, u32 msr_addr, u64 misc)
{ … }
static bool _log_error_deferred(unsigned int bank, u32 misc)
{ … }
static void log_error_deferred(unsigned int bank)
{ … }
static void amd_deferred_error_interrupt(void)
{ … }
static void log_error_thresholding(unsigned int bank, u64 misc)
{ … }
static void log_and_reset_block(struct threshold_block *block)
{ … }
static void amd_threshold_interrupt(void)
{ … }
struct threshold_attr { … };
#define SHOW_FIELDS(name) …
SHOW_FIELDS(…) …
SHOW_FIELDS(…) …
static ssize_t
store_interrupt_enable(struct threshold_block *b, const char *buf, size_t size)
{ … }
static ssize_t
store_threshold_limit(struct threshold_block *b, const char *buf, size_t size)
{ … }
static ssize_t show_error_count(struct threshold_block *b, char *buf)
{ … }
static struct threshold_attr error_count = …;
#define RW_ATTR(val) …
RW_ATTR(interrupt_enable);
RW_ATTR(threshold_limit);
static struct attribute *default_attrs[] = …;
ATTRIBUTE_GROUPS(…);
#define to_block(k) …
#define to_attr(a) …
static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
{ … }
static ssize_t store(struct kobject *kobj, struct attribute *attr,
const char *buf, size_t count)
{ … }
static const struct sysfs_ops threshold_ops = …;
static void threshold_block_release(struct kobject *kobj);
static const struct kobj_type threshold_ktype = …;
static const char *get_name(unsigned int cpu, unsigned int bank, struct threshold_block *b)
{ … }
static int allocate_threshold_blocks(unsigned int cpu, struct threshold_bank *tb,
unsigned int bank, unsigned int block,
u32 address)
{ … }
static int __threshold_add_blocks(struct threshold_bank *b)
{ … }
static int threshold_create_bank(struct threshold_bank **bp, unsigned int cpu,
unsigned int bank)
{ … }
static void threshold_block_release(struct kobject *kobj)
{ … }
static void deallocate_threshold_blocks(struct threshold_bank *bank)
{ … }
static void __threshold_remove_blocks(struct threshold_bank *b)
{ … }
static void threshold_remove_bank(struct threshold_bank *bank)
{ … }
static void __threshold_remove_device(struct threshold_bank **bp)
{ … }
int mce_threshold_remove_device(unsigned int cpu)
{ … }
int mce_threshold_create_device(unsigned int cpu)
{ … }