of: MSI: Simplify irqdomain lookup
[linux/fpc-iii.git] / arch / x86 / kernel / cpu / mcheck / mce_amd.c
blobe99b15077e9464b9c9f337873ae58101285e3215
1 /*
2 * (c) 2005-2015 Advanced Micro Devices, Inc.
3 * Your use of this code is subject to the terms and conditions of the
4 * GNU general public license version 2. See "COPYING" or
5 * http://www.gnu.org/licenses/gpl.html
7 * Written by Jacob Shin - AMD, Inc.
8 * Maintained by: Borislav Petkov <bp@alien8.de>
10 * All MC4_MISCi registers are shared between cores on a node.
12 #include <linux/interrupt.h>
13 #include <linux/notifier.h>
14 #include <linux/kobject.h>
15 #include <linux/percpu.h>
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/sysfs.h>
19 #include <linux/slab.h>
20 #include <linux/init.h>
21 #include <linux/cpu.h>
22 #include <linux/smp.h>
24 #include <asm/amd_nb.h>
25 #include <asm/apic.h>
26 #include <asm/idle.h>
27 #include <asm/mce.h>
28 #include <asm/msr.h>
29 #include <asm/trace/irq_vectors.h>
31 #define NR_BLOCKS 9
32 #define THRESHOLD_MAX 0xFFF
33 #define INT_TYPE_APIC 0x00020000
34 #define MASK_VALID_HI 0x80000000
35 #define MASK_CNTP_HI 0x40000000
36 #define MASK_LOCKED_HI 0x20000000
37 #define MASK_LVTOFF_HI 0x00F00000
38 #define MASK_COUNT_EN_HI 0x00080000
39 #define MASK_INT_TYPE_HI 0x00060000
40 #define MASK_OVERFLOW_HI 0x00010000
41 #define MASK_ERR_COUNT_HI 0x00000FFF
42 #define MASK_BLKPTR_LO 0xFF000000
43 #define MCG_XBLK_ADDR 0xC0000400
45 /* Deferred error settings */
46 #define MSR_CU_DEF_ERR 0xC0000410
47 #define MASK_DEF_LVTOFF 0x000000F0
48 #define MASK_DEF_INT_TYPE 0x00000006
49 #define DEF_LVT_OFF 0x2
50 #define DEF_INT_TYPE_APIC 0x2
52 static const char * const th_names[] = {
53 "load_store",
54 "insn_fetch",
55 "combined_unit",
56 "",
57 "northbridge",
58 "execution_unit",
61 static DEFINE_PER_CPU(struct threshold_bank **, threshold_banks);
62 static DEFINE_PER_CPU(unsigned char, bank_map); /* see which banks are on */
64 static void amd_threshold_interrupt(void);
65 static void amd_deferred_error_interrupt(void);
67 static void default_deferred_error_interrupt(void)
69 pr_err("Unexpected deferred interrupt at vector %x\n", DEFERRED_ERROR_VECTOR);
71 void (*deferred_error_int_vector)(void) = default_deferred_error_interrupt;
74 * CPU Initialization
77 struct thresh_restart {
78 struct threshold_block *b;
79 int reset;
80 int set_lvt_off;
81 int lvt_off;
82 u16 old_limit;
85 static inline bool is_shared_bank(int bank)
87 /* Bank 4 is for northbridge reporting and is thus shared */
88 return (bank == 4);
91 static const char *bank4_names(const struct threshold_block *b)
93 switch (b->address) {
94 /* MSR4_MISC0 */
95 case 0x00000413:
96 return "dram";
98 case 0xc0000408:
99 return "ht_links";
101 case 0xc0000409:
102 return "l3_cache";
104 default:
105 WARN(1, "Funny MSR: 0x%08x\n", b->address);
106 return "";
111 static bool lvt_interrupt_supported(unsigned int bank, u32 msr_high_bits)
114 * bank 4 supports APIC LVT interrupts implicitly since forever.
116 if (bank == 4)
117 return true;
120 * IntP: interrupt present; if this bit is set, the thresholding
121 * bank can generate APIC LVT interrupts
123 return msr_high_bits & BIT(28);
126 static int lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
128 int msr = (hi & MASK_LVTOFF_HI) >> 20;
130 if (apic < 0) {
131 pr_err(FW_BUG "cpu %d, failed to setup threshold interrupt "
132 "for bank %d, block %d (MSR%08X=0x%x%08x)\n", b->cpu,
133 b->bank, b->block, b->address, hi, lo);
134 return 0;
137 if (apic != msr) {
138 pr_err(FW_BUG "cpu %d, invalid threshold interrupt offset %d "
139 "for bank %d, block %d (MSR%08X=0x%x%08x)\n",
140 b->cpu, apic, b->bank, b->block, b->address, hi, lo);
141 return 0;
144 return 1;
148 * Called via smp_call_function_single(), must be called with correct
149 * cpu affinity.
151 static void threshold_restart_bank(void *_tr)
153 struct thresh_restart *tr = _tr;
154 u32 hi, lo;
156 rdmsr(tr->b->address, lo, hi);
158 if (tr->b->threshold_limit < (hi & THRESHOLD_MAX))
159 tr->reset = 1; /* limit cannot be lower than err count */
161 if (tr->reset) { /* reset err count and overflow bit */
162 hi =
163 (hi & ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI)) |
164 (THRESHOLD_MAX - tr->b->threshold_limit);
165 } else if (tr->old_limit) { /* change limit w/o reset */
166 int new_count = (hi & THRESHOLD_MAX) +
167 (tr->old_limit - tr->b->threshold_limit);
169 hi = (hi & ~MASK_ERR_COUNT_HI) |
170 (new_count & THRESHOLD_MAX);
173 /* clear IntType */
174 hi &= ~MASK_INT_TYPE_HI;
176 if (!tr->b->interrupt_capable)
177 goto done;
179 if (tr->set_lvt_off) {
180 if (lvt_off_valid(tr->b, tr->lvt_off, lo, hi)) {
181 /* set new lvt offset */
182 hi &= ~MASK_LVTOFF_HI;
183 hi |= tr->lvt_off << 20;
187 if (tr->b->interrupt_enable)
188 hi |= INT_TYPE_APIC;
190 done:
192 hi |= MASK_COUNT_EN_HI;
193 wrmsr(tr->b->address, lo, hi);
196 static void mce_threshold_block_init(struct threshold_block *b, int offset)
198 struct thresh_restart tr = {
199 .b = b,
200 .set_lvt_off = 1,
201 .lvt_off = offset,
204 b->threshold_limit = THRESHOLD_MAX;
205 threshold_restart_bank(&tr);
208 static int setup_APIC_mce_threshold(int reserved, int new)
210 if (reserved < 0 && !setup_APIC_eilvt(new, THRESHOLD_APIC_VECTOR,
211 APIC_EILVT_MSG_FIX, 0))
212 return new;
214 return reserved;
217 static int setup_APIC_deferred_error(int reserved, int new)
219 if (reserved < 0 && !setup_APIC_eilvt(new, DEFERRED_ERROR_VECTOR,
220 APIC_EILVT_MSG_FIX, 0))
221 return new;
223 return reserved;
226 static void deferred_error_interrupt_enable(struct cpuinfo_x86 *c)
228 u32 low = 0, high = 0;
229 int def_offset = -1, def_new;
231 if (rdmsr_safe(MSR_CU_DEF_ERR, &low, &high))
232 return;
234 def_new = (low & MASK_DEF_LVTOFF) >> 4;
235 if (!(low & MASK_DEF_LVTOFF)) {
236 pr_err(FW_BUG "Your BIOS is not setting up LVT offset 0x2 for deferred error IRQs correctly.\n");
237 def_new = DEF_LVT_OFF;
238 low = (low & ~MASK_DEF_LVTOFF) | (DEF_LVT_OFF << 4);
241 def_offset = setup_APIC_deferred_error(def_offset, def_new);
242 if ((def_offset == def_new) &&
243 (deferred_error_int_vector != amd_deferred_error_interrupt))
244 deferred_error_int_vector = amd_deferred_error_interrupt;
246 low = (low & ~MASK_DEF_INT_TYPE) | DEF_INT_TYPE_APIC;
247 wrmsr(MSR_CU_DEF_ERR, low, high);
250 /* cpu init entry point, called from mce.c with preempt off */
251 void mce_amd_feature_init(struct cpuinfo_x86 *c)
253 struct threshold_block b;
254 unsigned int cpu = smp_processor_id();
255 u32 low = 0, high = 0, address = 0;
256 unsigned int bank, block;
257 int offset = -1, new;
259 for (bank = 0; bank < mca_cfg.banks; ++bank) {
260 for (block = 0; block < NR_BLOCKS; ++block) {
261 if (block == 0)
262 address = MSR_IA32_MCx_MISC(bank);
263 else if (block == 1) {
264 address = (low & MASK_BLKPTR_LO) >> 21;
265 if (!address)
266 break;
268 address += MCG_XBLK_ADDR;
269 } else
270 ++address;
272 if (rdmsr_safe(address, &low, &high))
273 break;
275 if (!(high & MASK_VALID_HI))
276 continue;
278 if (!(high & MASK_CNTP_HI) ||
279 (high & MASK_LOCKED_HI))
280 continue;
282 if (!block)
283 per_cpu(bank_map, cpu) |= (1 << bank);
285 memset(&b, 0, sizeof(b));
286 b.cpu = cpu;
287 b.bank = bank;
288 b.block = block;
289 b.address = address;
290 b.interrupt_capable = lvt_interrupt_supported(bank, high);
292 if (!b.interrupt_capable)
293 goto init;
295 b.interrupt_enable = 1;
296 new = (high & MASK_LVTOFF_HI) >> 20;
297 offset = setup_APIC_mce_threshold(offset, new);
299 if ((offset == new) &&
300 (mce_threshold_vector != amd_threshold_interrupt))
301 mce_threshold_vector = amd_threshold_interrupt;
303 init:
304 mce_threshold_block_init(&b, offset);
308 if (mce_flags.succor)
309 deferred_error_interrupt_enable(c);
312 static void __log_error(unsigned int bank, bool threshold_err, u64 misc)
314 struct mce m;
315 u64 status;
317 rdmsrl(MSR_IA32_MCx_STATUS(bank), status);
318 if (!(status & MCI_STATUS_VAL))
319 return;
321 mce_setup(&m);
323 m.status = status;
324 m.bank = bank;
326 if (threshold_err)
327 m.misc = misc;
329 if (m.status & MCI_STATUS_ADDRV)
330 rdmsrl(MSR_IA32_MCx_ADDR(bank), m.addr);
332 mce_log(&m);
333 wrmsrl(MSR_IA32_MCx_STATUS(bank), 0);
336 static inline void __smp_deferred_error_interrupt(void)
338 inc_irq_stat(irq_deferred_error_count);
339 deferred_error_int_vector();
342 asmlinkage __visible void smp_deferred_error_interrupt(void)
344 entering_irq();
345 __smp_deferred_error_interrupt();
346 exiting_ack_irq();
349 asmlinkage __visible void smp_trace_deferred_error_interrupt(void)
351 entering_irq();
352 trace_deferred_error_apic_entry(DEFERRED_ERROR_VECTOR);
353 __smp_deferred_error_interrupt();
354 trace_deferred_error_apic_exit(DEFERRED_ERROR_VECTOR);
355 exiting_ack_irq();
358 /* APIC interrupt handler for deferred errors */
359 static void amd_deferred_error_interrupt(void)
361 u64 status;
362 unsigned int bank;
364 for (bank = 0; bank < mca_cfg.banks; ++bank) {
365 rdmsrl(MSR_IA32_MCx_STATUS(bank), status);
367 if (!(status & MCI_STATUS_VAL) ||
368 !(status & MCI_STATUS_DEFERRED))
369 continue;
371 __log_error(bank, false, 0);
372 break;
377 * APIC Interrupt Handler
381 * threshold interrupt handler will service THRESHOLD_APIC_VECTOR.
382 * the interrupt goes off when error_count reaches threshold_limit.
383 * the handler will simply log mcelog w/ software defined bank number.
386 static void amd_threshold_interrupt(void)
388 u32 low = 0, high = 0, address = 0;
389 int cpu = smp_processor_id();
390 unsigned int bank, block;
392 /* assume first bank caused it */
393 for (bank = 0; bank < mca_cfg.banks; ++bank) {
394 if (!(per_cpu(bank_map, cpu) & (1 << bank)))
395 continue;
396 for (block = 0; block < NR_BLOCKS; ++block) {
397 if (block == 0) {
398 address = MSR_IA32_MCx_MISC(bank);
399 } else if (block == 1) {
400 address = (low & MASK_BLKPTR_LO) >> 21;
401 if (!address)
402 break;
403 address += MCG_XBLK_ADDR;
404 } else {
405 ++address;
408 if (rdmsr_safe(address, &low, &high))
409 break;
411 if (!(high & MASK_VALID_HI)) {
412 if (block)
413 continue;
414 else
415 break;
418 if (!(high & MASK_CNTP_HI) ||
419 (high & MASK_LOCKED_HI))
420 continue;
423 * Log the machine check that caused the threshold
424 * event.
426 if (high & MASK_OVERFLOW_HI)
427 goto log;
430 return;
432 log:
433 __log_error(bank, true, ((u64)high << 32) | low);
437 * Sysfs Interface
440 struct threshold_attr {
441 struct attribute attr;
442 ssize_t (*show) (struct threshold_block *, char *);
443 ssize_t (*store) (struct threshold_block *, const char *, size_t count);
446 #define SHOW_FIELDS(name) \
447 static ssize_t show_ ## name(struct threshold_block *b, char *buf) \
449 return sprintf(buf, "%lu\n", (unsigned long) b->name); \
451 SHOW_FIELDS(interrupt_enable)
452 SHOW_FIELDS(threshold_limit)
454 static ssize_t
455 store_interrupt_enable(struct threshold_block *b, const char *buf, size_t size)
457 struct thresh_restart tr;
458 unsigned long new;
460 if (!b->interrupt_capable)
461 return -EINVAL;
463 if (kstrtoul(buf, 0, &new) < 0)
464 return -EINVAL;
466 b->interrupt_enable = !!new;
468 memset(&tr, 0, sizeof(tr));
469 tr.b = b;
471 smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
473 return size;
476 static ssize_t
477 store_threshold_limit(struct threshold_block *b, const char *buf, size_t size)
479 struct thresh_restart tr;
480 unsigned long new;
482 if (kstrtoul(buf, 0, &new) < 0)
483 return -EINVAL;
485 if (new > THRESHOLD_MAX)
486 new = THRESHOLD_MAX;
487 if (new < 1)
488 new = 1;
490 memset(&tr, 0, sizeof(tr));
491 tr.old_limit = b->threshold_limit;
492 b->threshold_limit = new;
493 tr.b = b;
495 smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
497 return size;
500 static ssize_t show_error_count(struct threshold_block *b, char *buf)
502 u32 lo, hi;
504 rdmsr_on_cpu(b->cpu, b->address, &lo, &hi);
506 return sprintf(buf, "%u\n", ((hi & THRESHOLD_MAX) -
507 (THRESHOLD_MAX - b->threshold_limit)));
510 static struct threshold_attr error_count = {
511 .attr = {.name = __stringify(error_count), .mode = 0444 },
512 .show = show_error_count,
515 #define RW_ATTR(val) \
516 static struct threshold_attr val = { \
517 .attr = {.name = __stringify(val), .mode = 0644 }, \
518 .show = show_## val, \
519 .store = store_## val, \
522 RW_ATTR(interrupt_enable);
523 RW_ATTR(threshold_limit);
525 static struct attribute *default_attrs[] = {
526 &threshold_limit.attr,
527 &error_count.attr,
528 NULL, /* possibly interrupt_enable if supported, see below */
529 NULL,
532 #define to_block(k) container_of(k, struct threshold_block, kobj)
533 #define to_attr(a) container_of(a, struct threshold_attr, attr)
535 static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
537 struct threshold_block *b = to_block(kobj);
538 struct threshold_attr *a = to_attr(attr);
539 ssize_t ret;
541 ret = a->show ? a->show(b, buf) : -EIO;
543 return ret;
546 static ssize_t store(struct kobject *kobj, struct attribute *attr,
547 const char *buf, size_t count)
549 struct threshold_block *b = to_block(kobj);
550 struct threshold_attr *a = to_attr(attr);
551 ssize_t ret;
553 ret = a->store ? a->store(b, buf, count) : -EIO;
555 return ret;
558 static const struct sysfs_ops threshold_ops = {
559 .show = show,
560 .store = store,
563 static struct kobj_type threshold_ktype = {
564 .sysfs_ops = &threshold_ops,
565 .default_attrs = default_attrs,
568 static int allocate_threshold_blocks(unsigned int cpu, unsigned int bank,
569 unsigned int block, u32 address)
571 struct threshold_block *b = NULL;
572 u32 low, high;
573 int err;
575 if ((bank >= mca_cfg.banks) || (block >= NR_BLOCKS))
576 return 0;
578 if (rdmsr_safe_on_cpu(cpu, address, &low, &high))
579 return 0;
581 if (!(high & MASK_VALID_HI)) {
582 if (block)
583 goto recurse;
584 else
585 return 0;
588 if (!(high & MASK_CNTP_HI) ||
589 (high & MASK_LOCKED_HI))
590 goto recurse;
592 b = kzalloc(sizeof(struct threshold_block), GFP_KERNEL);
593 if (!b)
594 return -ENOMEM;
596 b->block = block;
597 b->bank = bank;
598 b->cpu = cpu;
599 b->address = address;
600 b->interrupt_enable = 0;
601 b->interrupt_capable = lvt_interrupt_supported(bank, high);
602 b->threshold_limit = THRESHOLD_MAX;
604 if (b->interrupt_capable) {
605 threshold_ktype.default_attrs[2] = &interrupt_enable.attr;
606 b->interrupt_enable = 1;
607 } else {
608 threshold_ktype.default_attrs[2] = NULL;
611 INIT_LIST_HEAD(&b->miscj);
613 if (per_cpu(threshold_banks, cpu)[bank]->blocks) {
614 list_add(&b->miscj,
615 &per_cpu(threshold_banks, cpu)[bank]->blocks->miscj);
616 } else {
617 per_cpu(threshold_banks, cpu)[bank]->blocks = b;
620 err = kobject_init_and_add(&b->kobj, &threshold_ktype,
621 per_cpu(threshold_banks, cpu)[bank]->kobj,
622 (bank == 4 ? bank4_names(b) : th_names[bank]));
623 if (err)
624 goto out_free;
625 recurse:
626 if (!block) {
627 address = (low & MASK_BLKPTR_LO) >> 21;
628 if (!address)
629 return 0;
630 address += MCG_XBLK_ADDR;
631 } else {
632 ++address;
635 err = allocate_threshold_blocks(cpu, bank, ++block, address);
636 if (err)
637 goto out_free;
639 if (b)
640 kobject_uevent(&b->kobj, KOBJ_ADD);
642 return err;
644 out_free:
645 if (b) {
646 kobject_put(&b->kobj);
647 list_del(&b->miscj);
648 kfree(b);
650 return err;
653 static int __threshold_add_blocks(struct threshold_bank *b)
655 struct list_head *head = &b->blocks->miscj;
656 struct threshold_block *pos = NULL;
657 struct threshold_block *tmp = NULL;
658 int err = 0;
660 err = kobject_add(&b->blocks->kobj, b->kobj, b->blocks->kobj.name);
661 if (err)
662 return err;
664 list_for_each_entry_safe(pos, tmp, head, miscj) {
666 err = kobject_add(&pos->kobj, b->kobj, pos->kobj.name);
667 if (err) {
668 list_for_each_entry_safe_reverse(pos, tmp, head, miscj)
669 kobject_del(&pos->kobj);
671 return err;
674 return err;
677 static int threshold_create_bank(unsigned int cpu, unsigned int bank)
679 struct device *dev = per_cpu(mce_device, cpu);
680 struct amd_northbridge *nb = NULL;
681 struct threshold_bank *b = NULL;
682 const char *name = th_names[bank];
683 int err = 0;
685 if (is_shared_bank(bank)) {
686 nb = node_to_amd_nb(amd_get_nb_id(cpu));
688 /* threshold descriptor already initialized on this node? */
689 if (nb && nb->bank4) {
690 /* yes, use it */
691 b = nb->bank4;
692 err = kobject_add(b->kobj, &dev->kobj, name);
693 if (err)
694 goto out;
696 per_cpu(threshold_banks, cpu)[bank] = b;
697 atomic_inc(&b->cpus);
699 err = __threshold_add_blocks(b);
701 goto out;
705 b = kzalloc(sizeof(struct threshold_bank), GFP_KERNEL);
706 if (!b) {
707 err = -ENOMEM;
708 goto out;
711 b->kobj = kobject_create_and_add(name, &dev->kobj);
712 if (!b->kobj) {
713 err = -EINVAL;
714 goto out_free;
717 per_cpu(threshold_banks, cpu)[bank] = b;
719 if (is_shared_bank(bank)) {
720 atomic_set(&b->cpus, 1);
722 /* nb is already initialized, see above */
723 if (nb) {
724 WARN_ON(nb->bank4);
725 nb->bank4 = b;
729 err = allocate_threshold_blocks(cpu, bank, 0, MSR_IA32_MCx_MISC(bank));
730 if (!err)
731 goto out;
733 out_free:
734 kfree(b);
736 out:
737 return err;
740 /* create dir/files for all valid threshold banks */
741 static int threshold_create_device(unsigned int cpu)
743 unsigned int bank;
744 struct threshold_bank **bp;
745 int err = 0;
747 bp = kzalloc(sizeof(struct threshold_bank *) * mca_cfg.banks,
748 GFP_KERNEL);
749 if (!bp)
750 return -ENOMEM;
752 per_cpu(threshold_banks, cpu) = bp;
754 for (bank = 0; bank < mca_cfg.banks; ++bank) {
755 if (!(per_cpu(bank_map, cpu) & (1 << bank)))
756 continue;
757 err = threshold_create_bank(cpu, bank);
758 if (err)
759 return err;
762 return err;
765 static void deallocate_threshold_block(unsigned int cpu,
766 unsigned int bank)
768 struct threshold_block *pos = NULL;
769 struct threshold_block *tmp = NULL;
770 struct threshold_bank *head = per_cpu(threshold_banks, cpu)[bank];
772 if (!head)
773 return;
775 list_for_each_entry_safe(pos, tmp, &head->blocks->miscj, miscj) {
776 kobject_put(&pos->kobj);
777 list_del(&pos->miscj);
778 kfree(pos);
781 kfree(per_cpu(threshold_banks, cpu)[bank]->blocks);
782 per_cpu(threshold_banks, cpu)[bank]->blocks = NULL;
785 static void __threshold_remove_blocks(struct threshold_bank *b)
787 struct threshold_block *pos = NULL;
788 struct threshold_block *tmp = NULL;
790 kobject_del(b->kobj);
792 list_for_each_entry_safe(pos, tmp, &b->blocks->miscj, miscj)
793 kobject_del(&pos->kobj);
796 static void threshold_remove_bank(unsigned int cpu, int bank)
798 struct amd_northbridge *nb;
799 struct threshold_bank *b;
801 b = per_cpu(threshold_banks, cpu)[bank];
802 if (!b)
803 return;
805 if (!b->blocks)
806 goto free_out;
808 if (is_shared_bank(bank)) {
809 if (!atomic_dec_and_test(&b->cpus)) {
810 __threshold_remove_blocks(b);
811 per_cpu(threshold_banks, cpu)[bank] = NULL;
812 return;
813 } else {
815 * the last CPU on this node using the shared bank is
816 * going away, remove that bank now.
818 nb = node_to_amd_nb(amd_get_nb_id(cpu));
819 nb->bank4 = NULL;
823 deallocate_threshold_block(cpu, bank);
825 free_out:
826 kobject_del(b->kobj);
827 kobject_put(b->kobj);
828 kfree(b);
829 per_cpu(threshold_banks, cpu)[bank] = NULL;
832 static void threshold_remove_device(unsigned int cpu)
834 unsigned int bank;
836 for (bank = 0; bank < mca_cfg.banks; ++bank) {
837 if (!(per_cpu(bank_map, cpu) & (1 << bank)))
838 continue;
839 threshold_remove_bank(cpu, bank);
841 kfree(per_cpu(threshold_banks, cpu));
844 /* get notified when a cpu comes on/off */
845 static void
846 amd_64_threshold_cpu_callback(unsigned long action, unsigned int cpu)
848 switch (action) {
849 case CPU_ONLINE:
850 case CPU_ONLINE_FROZEN:
851 threshold_create_device(cpu);
852 break;
853 case CPU_DEAD:
854 case CPU_DEAD_FROZEN:
855 threshold_remove_device(cpu);
856 break;
857 default:
858 break;
862 static __init int threshold_init_device(void)
864 unsigned lcpu = 0;
866 /* to hit CPUs online before the notifier is up */
867 for_each_online_cpu(lcpu) {
868 int err = threshold_create_device(lcpu);
870 if (err)
871 return err;
873 threshold_cpu_callback = amd_64_threshold_cpu_callback;
875 return 0;
878 * there are 3 funcs which need to be _initcalled in a logic sequence:
879 * 1. xen_late_init_mcelog
880 * 2. mcheck_init_device
881 * 3. threshold_init_device
883 * xen_late_init_mcelog must register xen_mce_chrdev_device before
884 * native mce_chrdev_device registration if running under xen platform;
886 * mcheck_init_device should be inited before threshold_init_device to
887 * initialize mce_device, otherwise a NULL ptr dereference will cause panic.
889 * so we use following _initcalls
890 * 1. device_initcall(xen_late_init_mcelog);
891 * 2. device_initcall_sync(mcheck_init_device);
892 * 3. late_initcall(threshold_init_device);
894 * when running under xen, the initcall order is 1,2,3;
895 * on baremetal, we skip 1 and we do only 2 and 3.
897 late_initcall(threshold_init_device);