x86, mce: clean up mce_amd_64.c

Make the coding style match that of the rest of the x86 arch code.

[ Impact: cleanup ]

Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Hidetoshi Seto <seto.hidetoshi@jp.fujitsu.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
Ingo Molnar 2009-04-08 12:31:18 +02:00 committed by H. Peter Anvin
parent cb6f3c155b
commit 1cb2a8e176

View File

@ -13,22 +13,22 @@
* *
* All MC4_MISCi registers are shared between multi-cores * All MC4_MISCi registers are shared between multi-cores
*/ */
#include <linux/cpu.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/kobject.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/sched.h> #include <linux/kobject.h>
#include <linux/smp.h>
#include <linux/sysdev.h> #include <linux/sysdev.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/init.h>
#include <linux/cpu.h>
#include <linux/smp.h>
#include <asm/percpu.h>
#include <asm/apic.h> #include <asm/apic.h>
#include <asm/idle.h>
#include <asm/mce.h> #include <asm/mce.h>
#include <asm/msr.h> #include <asm/msr.h>
#include <asm/percpu.h>
#include <asm/idle.h>
#define PFX "mce_threshold: " #define PFX "mce_threshold: "
#define VERSION "version 1.1.1" #define VERSION "version 1.1.1"
@ -48,26 +48,26 @@
#define MCG_XBLK_ADDR 0xC0000400 #define MCG_XBLK_ADDR 0xC0000400
struct threshold_block { struct threshold_block {
unsigned int block; unsigned int block;
unsigned int bank; unsigned int bank;
unsigned int cpu; unsigned int cpu;
u32 address; u32 address;
u16 interrupt_enable; u16 interrupt_enable;
u16 threshold_limit; u16 threshold_limit;
struct kobject kobj; struct kobject kobj;
struct list_head miscj; struct list_head miscj;
}; };
/* defaults used early on boot */ /* defaults used early on boot */
static struct threshold_block threshold_defaults = { static struct threshold_block threshold_defaults = {
.interrupt_enable = 0, .interrupt_enable = 0,
.threshold_limit = THRESHOLD_MAX, .threshold_limit = THRESHOLD_MAX,
}; };
struct threshold_bank { struct threshold_bank {
struct kobject *kobj; struct kobject *kobj;
struct threshold_block *blocks; struct threshold_block *blocks;
cpumask_var_t cpus; cpumask_var_t cpus;
}; };
static DEFINE_PER_CPU(struct threshold_bank *, threshold_banks[NR_BANKS]); static DEFINE_PER_CPU(struct threshold_bank *, threshold_banks[NR_BANKS]);
@ -86,9 +86,9 @@ static void amd_threshold_interrupt(void);
*/ */
struct thresh_restart { struct thresh_restart {
struct threshold_block *b; struct threshold_block *b;
int reset; int reset;
u16 old_limit; u16 old_limit;
}; };
/* must be called with correct cpu affinity */ /* must be called with correct cpu affinity */
@ -110,6 +110,7 @@ static void threshold_restart_bank(void *_tr)
} else if (tr->old_limit) { /* change limit w/o reset */ } else if (tr->old_limit) { /* change limit w/o reset */
int new_count = (mci_misc_hi & THRESHOLD_MAX) + int new_count = (mci_misc_hi & THRESHOLD_MAX) +
(tr->old_limit - tr->b->threshold_limit); (tr->old_limit - tr->b->threshold_limit);
mci_misc_hi = (mci_misc_hi & ~MASK_ERR_COUNT_HI) | mci_misc_hi = (mci_misc_hi & ~MASK_ERR_COUNT_HI) |
(new_count & THRESHOLD_MAX); (new_count & THRESHOLD_MAX);
} }
@ -125,11 +126,11 @@ static void threshold_restart_bank(void *_tr)
/* cpu init entry point, called from mce.c with preempt off */ /* cpu init entry point, called from mce.c with preempt off */
void mce_amd_feature_init(struct cpuinfo_x86 *c) void mce_amd_feature_init(struct cpuinfo_x86 *c)
{ {
unsigned int bank, block;
unsigned int cpu = smp_processor_id(); unsigned int cpu = smp_processor_id();
u8 lvt_off;
u32 low = 0, high = 0, address = 0; u32 low = 0, high = 0, address = 0;
unsigned int bank, block;
struct thresh_restart tr; struct thresh_restart tr;
u8 lvt_off;
for (bank = 0; bank < NR_BANKS; ++bank) { for (bank = 0; bank < NR_BANKS; ++bank) {
for (block = 0; block < NR_BLOCKS; ++block) { for (block = 0; block < NR_BLOCKS; ++block) {
@ -140,8 +141,7 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
if (!address) if (!address)
break; break;
address += MCG_XBLK_ADDR; address += MCG_XBLK_ADDR;
} } else
else
++address; ++address;
if (rdmsr_safe(address, &low, &high)) if (rdmsr_safe(address, &low, &high))
@ -193,9 +193,9 @@ void mce_amd_feature_init(struct cpuinfo_x86 *c)
*/ */
static void amd_threshold_interrupt(void) static void amd_threshold_interrupt(void)
{ {
u32 low = 0, high = 0, address = 0;
unsigned int bank, block; unsigned int bank, block;
struct mce m; struct mce m;
u32 low = 0, high = 0, address = 0;
mce_setup(&m); mce_setup(&m);
@ -204,16 +204,16 @@ static void amd_threshold_interrupt(void)
if (!(per_cpu(bank_map, m.cpu) & (1 << bank))) if (!(per_cpu(bank_map, m.cpu) & (1 << bank)))
continue; continue;
for (block = 0; block < NR_BLOCKS; ++block) { for (block = 0; block < NR_BLOCKS; ++block) {
if (block == 0) if (block == 0) {
address = MSR_IA32_MC0_MISC + bank * 4; address = MSR_IA32_MC0_MISC + bank * 4;
else if (block == 1) { } else if (block == 1) {
address = (low & MASK_BLKPTR_LO) >> 21; address = (low & MASK_BLKPTR_LO) >> 21;
if (!address) if (!address)
break; break;
address += MCG_XBLK_ADDR; address += MCG_XBLK_ADDR;
} } else {
else
++address; ++address;
}
if (rdmsr_safe(address, &low, &high)) if (rdmsr_safe(address, &low, &high))
break; break;
@ -229,8 +229,10 @@ static void amd_threshold_interrupt(void)
(high & MASK_LOCKED_HI)) (high & MASK_LOCKED_HI))
continue; continue;
/* Log the machine check that caused the threshold /*
event. */ * Log the machine check that caused the threshold
* event.
*/
machine_check_poll(MCP_TIMESTAMP, machine_check_poll(MCP_TIMESTAMP,
&__get_cpu_var(mce_poll_banks)); &__get_cpu_var(mce_poll_banks));
@ -254,48 +256,56 @@ static void amd_threshold_interrupt(void)
struct threshold_attr { struct threshold_attr {
struct attribute attr; struct attribute attr;
ssize_t(*show) (struct threshold_block *, char *); ssize_t (*show) (struct threshold_block *, char *);
ssize_t(*store) (struct threshold_block *, const char *, size_t count); ssize_t (*store) (struct threshold_block *, const char *, size_t count);
}; };
#define SHOW_FIELDS(name) \ #define SHOW_FIELDS(name) \
static ssize_t show_ ## name(struct threshold_block * b, char *buf) \ static ssize_t show_ ## name(struct threshold_block *b, char *buf) \
{ \ { \
return sprintf(buf, "%lx\n", (unsigned long) b->name); \ return sprintf(buf, "%lx\n", (unsigned long) b->name); \
} }
SHOW_FIELDS(interrupt_enable) SHOW_FIELDS(interrupt_enable)
SHOW_FIELDS(threshold_limit) SHOW_FIELDS(threshold_limit)
static ssize_t store_interrupt_enable(struct threshold_block *b, static ssize_t
const char *buf, size_t count) store_interrupt_enable(struct threshold_block *b, const char *buf, size_t count)
{ {
char *end;
struct thresh_restart tr; struct thresh_restart tr;
unsigned long new = simple_strtoul(buf, &end, 0); unsigned long new;
char *end;
new = simple_strtoul(buf, &end, 0);
if (end == buf) if (end == buf)
return -EINVAL; return -EINVAL;
b->interrupt_enable = !!new; b->interrupt_enable = !!new;
tr.b = b; tr.b = b;
tr.reset = 0; tr.reset = 0;
tr.old_limit = 0; tr.old_limit = 0;
smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1); smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
return end - buf; return end - buf;
} }
static ssize_t store_threshold_limit(struct threshold_block *b, static ssize_t
const char *buf, size_t count) store_threshold_limit(struct threshold_block *b, const char *buf, size_t count)
{ {
char *end;
struct thresh_restart tr; struct thresh_restart tr;
unsigned long new = simple_strtoul(buf, &end, 0); unsigned long new;
char *end;
new = simple_strtoul(buf, &end, 0);
if (end == buf) if (end == buf)
return -EINVAL; return -EINVAL;
if (new > THRESHOLD_MAX) if (new > THRESHOLD_MAX)
new = THRESHOLD_MAX; new = THRESHOLD_MAX;
if (new < 1) if (new < 1)
new = 1; new = 1;
tr.old_limit = b->threshold_limit; tr.old_limit = b->threshold_limit;
b->threshold_limit = new; b->threshold_limit = new;
tr.b = b; tr.b = b;
@ -307,8 +317,8 @@ static ssize_t store_threshold_limit(struct threshold_block *b,
} }
struct threshold_block_cross_cpu { struct threshold_block_cross_cpu {
struct threshold_block *tb; struct threshold_block *tb;
long retval; long retval;
}; };
static void local_error_count_handler(void *_tbcc) static void local_error_count_handler(void *_tbcc)
@ -338,15 +348,16 @@ static ssize_t store_error_count(struct threshold_block *b,
return 1; return 1;
} }
#define THRESHOLD_ATTR(_name,_mode,_show,_store) { \ #define THRESHOLD_ATTR(_name, _mode, _show, _store) \
.attr = {.name = __stringify(_name), .mode = _mode }, \ { \
.show = _show, \ .attr = {.name = __stringify(_name), .mode = _mode }, \
.store = _store, \ .show = _show, \
.store = _store, \
}; };
#define RW_ATTR(name) \ #define RW_ATTR(name) \
static struct threshold_attr name = \ static struct threshold_attr name = \
THRESHOLD_ATTR(name, 0644, show_## name, store_## name) THRESHOLD_ATTR(name, 0644, show_## name, store_## name)
RW_ATTR(interrupt_enable); RW_ATTR(interrupt_enable);
RW_ATTR(threshold_limit); RW_ATTR(threshold_limit);
@ -359,15 +370,17 @@ static struct attribute *default_attrs[] = {
NULL NULL
}; };
#define to_block(k) container_of(k, struct threshold_block, kobj) #define to_block(k) container_of(k, struct threshold_block, kobj)
#define to_attr(a) container_of(a, struct threshold_attr, attr) #define to_attr(a) container_of(a, struct threshold_attr, attr)
static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf) static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
{ {
struct threshold_block *b = to_block(kobj); struct threshold_block *b = to_block(kobj);
struct threshold_attr *a = to_attr(attr); struct threshold_attr *a = to_attr(attr);
ssize_t ret; ssize_t ret;
ret = a->show ? a->show(b, buf) : -EIO; ret = a->show ? a->show(b, buf) : -EIO;
return ret; return ret;
} }
@ -377,18 +390,20 @@ static ssize_t store(struct kobject *kobj, struct attribute *attr,
struct threshold_block *b = to_block(kobj); struct threshold_block *b = to_block(kobj);
struct threshold_attr *a = to_attr(attr); struct threshold_attr *a = to_attr(attr);
ssize_t ret; ssize_t ret;
ret = a->store ? a->store(b, buf, count) : -EIO; ret = a->store ? a->store(b, buf, count) : -EIO;
return ret; return ret;
} }
static struct sysfs_ops threshold_ops = { static struct sysfs_ops threshold_ops = {
.show = show, .show = show,
.store = store, .store = store,
}; };
static struct kobj_type threshold_ktype = { static struct kobj_type threshold_ktype = {
.sysfs_ops = &threshold_ops, .sysfs_ops = &threshold_ops,
.default_attrs = default_attrs, .default_attrs = default_attrs,
}; };
static __cpuinit int allocate_threshold_blocks(unsigned int cpu, static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
@ -396,9 +411,9 @@ static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
unsigned int block, unsigned int block,
u32 address) u32 address)
{ {
int err;
u32 low, high;
struct threshold_block *b = NULL; struct threshold_block *b = NULL;
u32 low, high;
int err;
if ((bank >= NR_BANKS) || (block >= NR_BLOCKS)) if ((bank >= NR_BANKS) || (block >= NR_BLOCKS))
return 0; return 0;
@ -421,20 +436,21 @@ static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
if (!b) if (!b)
return -ENOMEM; return -ENOMEM;
b->block = block; b->block = block;
b->bank = bank; b->bank = bank;
b->cpu = cpu; b->cpu = cpu;
b->address = address; b->address = address;
b->interrupt_enable = 0; b->interrupt_enable = 0;
b->threshold_limit = THRESHOLD_MAX; b->threshold_limit = THRESHOLD_MAX;
INIT_LIST_HEAD(&b->miscj); INIT_LIST_HEAD(&b->miscj);
if (per_cpu(threshold_banks, cpu)[bank]->blocks) if (per_cpu(threshold_banks, cpu)[bank]->blocks) {
list_add(&b->miscj, list_add(&b->miscj,
&per_cpu(threshold_banks, cpu)[bank]->blocks->miscj); &per_cpu(threshold_banks, cpu)[bank]->blocks->miscj);
else } else {
per_cpu(threshold_banks, cpu)[bank]->blocks = b; per_cpu(threshold_banks, cpu)[bank]->blocks = b;
}
err = kobject_init_and_add(&b->kobj, &threshold_ktype, err = kobject_init_and_add(&b->kobj, &threshold_ktype,
per_cpu(threshold_banks, cpu)[bank]->kobj, per_cpu(threshold_banks, cpu)[bank]->kobj,
@ -447,8 +463,9 @@ recurse:
if (!address) if (!address)
return 0; return 0;
address += MCG_XBLK_ADDR; address += MCG_XBLK_ADDR;
} else } else {
++address; ++address;
}
err = allocate_threshold_blocks(cpu, bank, ++block, address); err = allocate_threshold_blocks(cpu, bank, ++block, address);
if (err) if (err)
@ -507,6 +524,7 @@ static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
cpumask_copy(b->cpus, cpu_core_mask(cpu)); cpumask_copy(b->cpus, cpu_core_mask(cpu));
per_cpu(threshold_banks, cpu)[bank] = b; per_cpu(threshold_banks, cpu)[bank] = b;
goto out; goto out;
} }
#endif #endif
@ -605,15 +623,13 @@ static void deallocate_threshold_block(unsigned int cpu,
static void threshold_remove_bank(unsigned int cpu, int bank) static void threshold_remove_bank(unsigned int cpu, int bank)
{ {
int i = 0;
struct threshold_bank *b; struct threshold_bank *b;
char name[32]; char name[32];
int i = 0;
b = per_cpu(threshold_banks, cpu)[bank]; b = per_cpu(threshold_banks, cpu)[bank];
if (!b) if (!b)
return; return;
if (!b->blocks) if (!b->blocks)
goto free_out; goto free_out;
@ -624,6 +640,7 @@ static void threshold_remove_bank(unsigned int cpu, int bank)
if (shared_bank[bank] && b->blocks->cpu != cpu) { if (shared_bank[bank] && b->blocks->cpu != cpu) {
sysfs_remove_link(&per_cpu(device_mce, cpu).kobj, name); sysfs_remove_link(&per_cpu(device_mce, cpu).kobj, name);
per_cpu(threshold_banks, cpu)[bank] = NULL; per_cpu(threshold_banks, cpu)[bank] = NULL;
return; return;
} }
#endif #endif
@ -659,8 +676,8 @@ static void threshold_remove_device(unsigned int cpu)
} }
/* get notified when a cpu comes on/off */ /* get notified when a cpu comes on/off */
static void __cpuinit amd_64_threshold_cpu_callback(unsigned long action, static void __cpuinit
unsigned int cpu) amd_64_threshold_cpu_callback(unsigned long action, unsigned int cpu)
{ {
if (cpu >= NR_CPUS) if (cpu >= NR_CPUS)
return; return;
@ -686,11 +703,12 @@ static __init int threshold_init_device(void)
/* to hit CPUs online before the notifier is up */ /* to hit CPUs online before the notifier is up */
for_each_online_cpu(lcpu) { for_each_online_cpu(lcpu) {
int err = threshold_create_device(lcpu); int err = threshold_create_device(lcpu);
if (err) if (err)
return err; return err;
} }
threshold_cpu_callback = amd_64_threshold_cpu_callback; threshold_cpu_callback = amd_64_threshold_cpu_callback;
return 0; return 0;
} }
device_initcall(threshold_init_device); device_initcall(threshold_init_device);