mce_amd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /*
  2. * (c) 2005, 2006 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
  6. *
  7. * Written by Jacob Shin - AMD, Inc.
  8. *
  9. * Support : jacob.shin@amd.com
  10. *
  11. * April 2006
  12. * - added support for AMD Family 0x10 processors
  13. *
  14. * All MC4_MISCi registers are shared between multi-cores
  15. */
  16. #include <linux/interrupt.h>
  17. #include <linux/notifier.h>
  18. #include <linux/kobject.h>
  19. #include <linux/percpu.h>
  20. #include <linux/errno.h>
  21. #include <linux/sched.h>
  22. #include <linux/sysfs.h>
  23. #include <linux/slab.h>
  24. #include <linux/init.h>
  25. #include <linux/cpu.h>
  26. #include <linux/smp.h>
  27. #include <asm/apic.h>
  28. #include <asm/idle.h>
  29. #include <asm/mce.h>
  30. #include <asm/msr.h>
  31. #define NR_BANKS 6
  32. #define NR_BLOCKS 9
  33. #define THRESHOLD_MAX 0xFFF
  34. #define INT_TYPE_APIC 0x00020000
  35. #define MASK_VALID_HI 0x80000000
  36. #define MASK_CNTP_HI 0x40000000
  37. #define MASK_LOCKED_HI 0x20000000
  38. #define MASK_LVTOFF_HI 0x00F00000
  39. #define MASK_COUNT_EN_HI 0x00080000
  40. #define MASK_INT_TYPE_HI 0x00060000
  41. #define MASK_OVERFLOW_HI 0x00010000
  42. #define MASK_ERR_COUNT_HI 0x00000FFF
  43. #define MASK_BLKPTR_LO 0xFF000000
  44. #define MCG_XBLK_ADDR 0xC0000400
  45. struct threshold_block {
  46. unsigned int block;
  47. unsigned int bank;
  48. unsigned int cpu;
  49. u32 address;
  50. u16 interrupt_enable;
  51. u16 threshold_limit;
  52. struct kobject kobj;
  53. struct list_head miscj;
  54. };
  55. struct threshold_bank {
  56. struct kobject *kobj;
  57. struct threshold_block *blocks;
  58. cpumask_var_t cpus;
  59. };
  60. static DEFINE_PER_CPU(struct threshold_bank * [NR_BANKS], threshold_banks);
  61. static unsigned char shared_bank[NR_BANKS] = {
  62. 0, 0, 0, 0, 1
  63. };
  64. static DEFINE_PER_CPU(unsigned char, bank_map); /* see which banks are on */
  65. static void amd_threshold_interrupt(void);
  66. /*
  67. * CPU Initialization
  68. */
  69. struct thresh_restart {
  70. struct threshold_block *b;
  71. int reset;
  72. int set_lvt_off;
  73. int lvt_off;
  74. u16 old_limit;
  75. };
  76. static int lvt_off_valid(struct threshold_block *b, int apic, u32 lo, u32 hi)
  77. {
  78. int msr = (hi & MASK_LVTOFF_HI) >> 20;
  79. if (apic < 0) {
  80. pr_err(FW_BUG "cpu %d, failed to setup threshold interrupt "
  81. "for bank %d, block %d (MSR%08X=0x%x%08x)\n", b->cpu,
  82. b->bank, b->block, b->address, hi, lo);
  83. return 0;
  84. }
  85. if (apic != msr) {
  86. pr_err(FW_BUG "cpu %d, invalid threshold interrupt offset %d "
  87. "for bank %d, block %d (MSR%08X=0x%x%08x)\n",
  88. b->cpu, apic, b->bank, b->block, b->address, hi, lo);
  89. return 0;
  90. }
  91. return 1;
  92. };
  93. /* must be called with correct cpu affinity */
  94. /* Called via smp_call_function_single() */
  95. static void threshold_restart_bank(void *_tr)
  96. {
  97. struct thresh_restart *tr = _tr;
  98. u32 hi, lo;
  99. rdmsr(tr->b->address, lo, hi);
  100. if (tr->b->threshold_limit < (hi & THRESHOLD_MAX))
  101. tr->reset = 1; /* limit cannot be lower than err count */
  102. if (tr->reset) { /* reset err count and overflow bit */
  103. hi =
  104. (hi & ~(MASK_ERR_COUNT_HI | MASK_OVERFLOW_HI)) |
  105. (THRESHOLD_MAX - tr->b->threshold_limit);
  106. } else if (tr->old_limit) { /* change limit w/o reset */
  107. int new_count = (hi & THRESHOLD_MAX) +
  108. (tr->old_limit - tr->b->threshold_limit);
  109. hi = (hi & ~MASK_ERR_COUNT_HI) |
  110. (new_count & THRESHOLD_MAX);
  111. }
  112. if (tr->set_lvt_off) {
  113. if (lvt_off_valid(tr->b, tr->lvt_off, lo, hi)) {
  114. /* set new lvt offset */
  115. hi &= ~MASK_LVTOFF_HI;
  116. hi |= tr->lvt_off << 20;
  117. }
  118. }
  119. tr->b->interrupt_enable ?
  120. (hi = (hi & ~MASK_INT_TYPE_HI) | INT_TYPE_APIC) :
  121. (hi &= ~MASK_INT_TYPE_HI);
  122. hi |= MASK_COUNT_EN_HI;
  123. wrmsr(tr->b->address, lo, hi);
  124. }
  125. static void mce_threshold_block_init(struct threshold_block *b, int offset)
  126. {
  127. struct thresh_restart tr = {
  128. .b = b,
  129. .set_lvt_off = 1,
  130. .lvt_off = offset,
  131. };
  132. b->threshold_limit = THRESHOLD_MAX;
  133. threshold_restart_bank(&tr);
  134. };
  135. static int setup_APIC_mce(int reserved, int new)
  136. {
  137. if (reserved < 0 && !setup_APIC_eilvt(new, THRESHOLD_APIC_VECTOR,
  138. APIC_EILVT_MSG_FIX, 0))
  139. return new;
  140. return reserved;
  141. }
  142. /* cpu init entry point, called from mce.c with preempt off */
  143. void mce_amd_feature_init(struct cpuinfo_x86 *c)
  144. {
  145. struct threshold_block b;
  146. unsigned int cpu = smp_processor_id();
  147. u32 low = 0, high = 0, address = 0;
  148. unsigned int bank, block;
  149. int offset = -1;
  150. for (bank = 0; bank < NR_BANKS; ++bank) {
  151. for (block = 0; block < NR_BLOCKS; ++block) {
  152. if (block == 0)
  153. address = MSR_IA32_MC0_MISC + bank * 4;
  154. else if (block == 1) {
  155. address = (low & MASK_BLKPTR_LO) >> 21;
  156. if (!address)
  157. break;
  158. address += MCG_XBLK_ADDR;
  159. } else
  160. ++address;
  161. if (rdmsr_safe(address, &low, &high))
  162. break;
  163. if (!(high & MASK_VALID_HI))
  164. continue;
  165. if (!(high & MASK_CNTP_HI) ||
  166. (high & MASK_LOCKED_HI))
  167. continue;
  168. if (!block)
  169. per_cpu(bank_map, cpu) |= (1 << bank);
  170. if (shared_bank[bank] && c->cpu_core_id)
  171. break;
  172. offset = setup_APIC_mce(offset,
  173. (high & MASK_LVTOFF_HI) >> 20);
  174. memset(&b, 0, sizeof(b));
  175. b.cpu = cpu;
  176. b.bank = bank;
  177. b.block = block;
  178. b.address = address;
  179. mce_threshold_block_init(&b, offset);
  180. mce_threshold_vector = amd_threshold_interrupt;
  181. }
  182. }
  183. }
  184. /*
  185. * APIC Interrupt Handler
  186. */
  187. /*
  188. * threshold interrupt handler will service THRESHOLD_APIC_VECTOR.
  189. * the interrupt goes off when error_count reaches threshold_limit.
  190. * the handler will simply log mcelog w/ software defined bank number.
  191. */
  192. static void amd_threshold_interrupt(void)
  193. {
  194. u32 low = 0, high = 0, address = 0;
  195. unsigned int bank, block;
  196. struct mce m;
  197. mce_setup(&m);
  198. /* assume first bank caused it */
  199. for (bank = 0; bank < NR_BANKS; ++bank) {
  200. if (!(per_cpu(bank_map, m.cpu) & (1 << bank)))
  201. continue;
  202. for (block = 0; block < NR_BLOCKS; ++block) {
  203. if (block == 0) {
  204. address = MSR_IA32_MC0_MISC + bank * 4;
  205. } else if (block == 1) {
  206. address = (low & MASK_BLKPTR_LO) >> 21;
  207. if (!address)
  208. break;
  209. address += MCG_XBLK_ADDR;
  210. } else {
  211. ++address;
  212. }
  213. if (rdmsr_safe(address, &low, &high))
  214. break;
  215. if (!(high & MASK_VALID_HI)) {
  216. if (block)
  217. continue;
  218. else
  219. break;
  220. }
  221. if (!(high & MASK_CNTP_HI) ||
  222. (high & MASK_LOCKED_HI))
  223. continue;
  224. /*
  225. * Log the machine check that caused the threshold
  226. * event.
  227. */
  228. machine_check_poll(MCP_TIMESTAMP,
  229. &__get_cpu_var(mce_poll_banks));
  230. if (high & MASK_OVERFLOW_HI) {
  231. rdmsrl(address, m.misc);
  232. rdmsrl(MSR_IA32_MC0_STATUS + bank * 4,
  233. m.status);
  234. m.bank = K8_MCE_THRESHOLD_BASE
  235. + bank * NR_BLOCKS
  236. + block;
  237. mce_log(&m);
  238. return;
  239. }
  240. }
  241. }
  242. }
  243. /*
  244. * Sysfs Interface
  245. */
  246. struct threshold_attr {
  247. struct attribute attr;
  248. ssize_t (*show) (struct threshold_block *, char *);
  249. ssize_t (*store) (struct threshold_block *, const char *, size_t count);
  250. };
  251. #define SHOW_FIELDS(name) \
  252. static ssize_t show_ ## name(struct threshold_block *b, char *buf) \
  253. { \
  254. return sprintf(buf, "%lx\n", (unsigned long) b->name); \
  255. }
  256. SHOW_FIELDS(interrupt_enable)
  257. SHOW_FIELDS(threshold_limit)
  258. static ssize_t
  259. store_interrupt_enable(struct threshold_block *b, const char *buf, size_t size)
  260. {
  261. struct thresh_restart tr;
  262. unsigned long new;
  263. if (strict_strtoul(buf, 0, &new) < 0)
  264. return -EINVAL;
  265. b->interrupt_enable = !!new;
  266. memset(&tr, 0, sizeof(tr));
  267. tr.b = b;
  268. smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
  269. return size;
  270. }
  271. static ssize_t
  272. store_threshold_limit(struct threshold_block *b, const char *buf, size_t size)
  273. {
  274. struct thresh_restart tr;
  275. unsigned long new;
  276. if (strict_strtoul(buf, 0, &new) < 0)
  277. return -EINVAL;
  278. if (new > THRESHOLD_MAX)
  279. new = THRESHOLD_MAX;
  280. if (new < 1)
  281. new = 1;
  282. memset(&tr, 0, sizeof(tr));
  283. tr.old_limit = b->threshold_limit;
  284. b->threshold_limit = new;
  285. tr.b = b;
  286. smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
  287. return size;
  288. }
  289. struct threshold_block_cross_cpu {
  290. struct threshold_block *tb;
  291. long retval;
  292. };
  293. static void local_error_count_handler(void *_tbcc)
  294. {
  295. struct threshold_block_cross_cpu *tbcc = _tbcc;
  296. struct threshold_block *b = tbcc->tb;
  297. u32 low, high;
  298. rdmsr(b->address, low, high);
  299. tbcc->retval = (high & 0xFFF) - (THRESHOLD_MAX - b->threshold_limit);
  300. }
  301. static ssize_t show_error_count(struct threshold_block *b, char *buf)
  302. {
  303. struct threshold_block_cross_cpu tbcc = { .tb = b, };
  304. smp_call_function_single(b->cpu, local_error_count_handler, &tbcc, 1);
  305. return sprintf(buf, "%lx\n", tbcc.retval);
  306. }
  307. static ssize_t store_error_count(struct threshold_block *b,
  308. const char *buf, size_t count)
  309. {
  310. struct thresh_restart tr = { .b = b, .reset = 1, .old_limit = 0 };
  311. smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1);
  312. return 1;
  313. }
  314. #define RW_ATTR(val) \
  315. static struct threshold_attr val = { \
  316. .attr = {.name = __stringify(val), .mode = 0644 }, \
  317. .show = show_## val, \
  318. .store = store_## val, \
  319. };
  320. RW_ATTR(interrupt_enable);
  321. RW_ATTR(threshold_limit);
  322. RW_ATTR(error_count);
  323. static struct attribute *default_attrs[] = {
  324. &interrupt_enable.attr,
  325. &threshold_limit.attr,
  326. &error_count.attr,
  327. NULL
  328. };
  329. #define to_block(k) container_of(k, struct threshold_block, kobj)
  330. #define to_attr(a) container_of(a, struct threshold_attr, attr)
  331. static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
  332. {
  333. struct threshold_block *b = to_block(kobj);
  334. struct threshold_attr *a = to_attr(attr);
  335. ssize_t ret;
  336. ret = a->show ? a->show(b, buf) : -EIO;
  337. return ret;
  338. }
  339. static ssize_t store(struct kobject *kobj, struct attribute *attr,
  340. const char *buf, size_t count)
  341. {
  342. struct threshold_block *b = to_block(kobj);
  343. struct threshold_attr *a = to_attr(attr);
  344. ssize_t ret;
  345. ret = a->store ? a->store(b, buf, count) : -EIO;
  346. return ret;
  347. }
  348. static const struct sysfs_ops threshold_ops = {
  349. .show = show,
  350. .store = store,
  351. };
  352. static struct kobj_type threshold_ktype = {
  353. .sysfs_ops = &threshold_ops,
  354. .default_attrs = default_attrs,
  355. };
  356. static __cpuinit int allocate_threshold_blocks(unsigned int cpu,
  357. unsigned int bank,
  358. unsigned int block,
  359. u32 address)
  360. {
  361. struct threshold_block *b = NULL;
  362. u32 low, high;
  363. int err;
  364. if ((bank >= NR_BANKS) || (block >= NR_BLOCKS))
  365. return 0;
  366. if (rdmsr_safe_on_cpu(cpu, address, &low, &high))
  367. return 0;
  368. if (!(high & MASK_VALID_HI)) {
  369. if (block)
  370. goto recurse;
  371. else
  372. return 0;
  373. }
  374. if (!(high & MASK_CNTP_HI) ||
  375. (high & MASK_LOCKED_HI))
  376. goto recurse;
  377. b = kzalloc(sizeof(struct threshold_block), GFP_KERNEL);
  378. if (!b)
  379. return -ENOMEM;
  380. b->block = block;
  381. b->bank = bank;
  382. b->cpu = cpu;
  383. b->address = address;
  384. b->interrupt_enable = 0;
  385. b->threshold_limit = THRESHOLD_MAX;
  386. INIT_LIST_HEAD(&b->miscj);
  387. if (per_cpu(threshold_banks, cpu)[bank]->blocks) {
  388. list_add(&b->miscj,
  389. &per_cpu(threshold_banks, cpu)[bank]->blocks->miscj);
  390. } else {
  391. per_cpu(threshold_banks, cpu)[bank]->blocks = b;
  392. }
  393. err = kobject_init_and_add(&b->kobj, &threshold_ktype,
  394. per_cpu(threshold_banks, cpu)[bank]->kobj,
  395. "misc%i", block);
  396. if (err)
  397. goto out_free;
  398. recurse:
  399. if (!block) {
  400. address = (low & MASK_BLKPTR_LO) >> 21;
  401. if (!address)
  402. return 0;
  403. address += MCG_XBLK_ADDR;
  404. } else {
  405. ++address;
  406. }
  407. err = allocate_threshold_blocks(cpu, bank, ++block, address);
  408. if (err)
  409. goto out_free;
  410. if (b)
  411. kobject_uevent(&b->kobj, KOBJ_ADD);
  412. return err;
  413. out_free:
  414. if (b) {
  415. kobject_put(&b->kobj);
  416. list_del(&b->miscj);
  417. kfree(b);
  418. }
  419. return err;
  420. }
  421. static __cpuinit long
  422. local_allocate_threshold_blocks(int cpu, unsigned int bank)
  423. {
  424. return allocate_threshold_blocks(cpu, bank, 0,
  425. MSR_IA32_MC0_MISC + bank * 4);
  426. }
  427. /* symlinks sibling shared banks to first core. first core owns dir/files. */
  428. static __cpuinit int threshold_create_bank(unsigned int cpu, unsigned int bank)
  429. {
  430. int i, err = 0;
  431. struct threshold_bank *b = NULL;
  432. struct device *dev = per_cpu(mce_device, cpu);
  433. char name[32];
  434. sprintf(name, "threshold_bank%i", bank);
  435. #ifdef CONFIG_SMP
  436. if (cpu_data(cpu).cpu_core_id && shared_bank[bank]) { /* symlink */
  437. i = cpumask_first(cpu_llc_shared_mask(cpu));
  438. /* first core not up yet */
  439. if (cpu_data(i).cpu_core_id)
  440. goto out;
  441. /* already linked */
  442. if (per_cpu(threshold_banks, cpu)[bank])
  443. goto out;
  444. b = per_cpu(threshold_banks, i)[bank];
  445. if (!b)
  446. goto out;
  447. err = sysfs_create_link(&dev->kobj, b->kobj, name);
  448. if (err)
  449. goto out;
  450. cpumask_copy(b->cpus, cpu_llc_shared_mask(cpu));
  451. per_cpu(threshold_banks, cpu)[bank] = b;
  452. goto out;
  453. }
  454. #endif
  455. b = kzalloc(sizeof(struct threshold_bank), GFP_KERNEL);
  456. if (!b) {
  457. err = -ENOMEM;
  458. goto out;
  459. }
  460. if (!zalloc_cpumask_var(&b->cpus, GFP_KERNEL)) {
  461. kfree(b);
  462. err = -ENOMEM;
  463. goto out;
  464. }
  465. b->kobj = kobject_create_and_add(name, &dev->kobj);
  466. if (!b->kobj)
  467. goto out_free;
  468. #ifndef CONFIG_SMP
  469. cpumask_setall(b->cpus);
  470. #else
  471. cpumask_set_cpu(cpu, b->cpus);
  472. #endif
  473. per_cpu(threshold_banks, cpu)[bank] = b;
  474. err = local_allocate_threshold_blocks(cpu, bank);
  475. if (err)
  476. goto out_free;
  477. for_each_cpu(i, b->cpus) {
  478. if (i == cpu)
  479. continue;
  480. dev = per_cpu(mce_device, i);
  481. if (dev)
  482. err = sysfs_create_link(&dev->kobj,b->kobj, name);
  483. if (err)
  484. goto out;
  485. per_cpu(threshold_banks, i)[bank] = b;
  486. }
  487. goto out;
  488. out_free:
  489. per_cpu(threshold_banks, cpu)[bank] = NULL;
  490. free_cpumask_var(b->cpus);
  491. kfree(b);
  492. out:
  493. return err;
  494. }
  495. /* create dir/files for all valid threshold banks */
  496. static __cpuinit int threshold_create_device(unsigned int cpu)
  497. {
  498. unsigned int bank;
  499. int err = 0;
  500. for (bank = 0; bank < NR_BANKS; ++bank) {
  501. if (!(per_cpu(bank_map, cpu) & (1 << bank)))
  502. continue;
  503. err = threshold_create_bank(cpu, bank);
  504. if (err)
  505. return err;
  506. }
  507. return err;
  508. }
  509. /*
  510. * let's be hotplug friendly.
  511. * in case of multiple core processors, the first core always takes ownership
  512. * of shared sysfs dir/files, and rest of the cores will be symlinked to it.
  513. */
  514. static void deallocate_threshold_block(unsigned int cpu,
  515. unsigned int bank)
  516. {
  517. struct threshold_block *pos = NULL;
  518. struct threshold_block *tmp = NULL;
  519. struct threshold_bank *head = per_cpu(threshold_banks, cpu)[bank];
  520. if (!head)
  521. return;
  522. list_for_each_entry_safe(pos, tmp, &head->blocks->miscj, miscj) {
  523. kobject_put(&pos->kobj);
  524. list_del(&pos->miscj);
  525. kfree(pos);
  526. }
  527. kfree(per_cpu(threshold_banks, cpu)[bank]->blocks);
  528. per_cpu(threshold_banks, cpu)[bank]->blocks = NULL;
  529. }
  530. static void threshold_remove_bank(unsigned int cpu, int bank)
  531. {
  532. struct threshold_bank *b;
  533. struct device *dev;
  534. char name[32];
  535. int i = 0;
  536. b = per_cpu(threshold_banks, cpu)[bank];
  537. if (!b)
  538. return;
  539. if (!b->blocks)
  540. goto free_out;
  541. sprintf(name, "threshold_bank%i", bank);
  542. #ifdef CONFIG_SMP
  543. /* sibling symlink */
  544. if (shared_bank[bank] && b->blocks->cpu != cpu) {
  545. dev = per_cpu(mce_device, cpu);
  546. sysfs_remove_link(&dev->kobj, name);
  547. per_cpu(threshold_banks, cpu)[bank] = NULL;
  548. return;
  549. }
  550. #endif
  551. /* remove all sibling symlinks before unregistering */
  552. for_each_cpu(i, b->cpus) {
  553. if (i == cpu)
  554. continue;
  555. dev = per_cpu(mce_device, i);
  556. if (dev)
  557. sysfs_remove_link(&dev->kobj, name);
  558. per_cpu(threshold_banks, i)[bank] = NULL;
  559. }
  560. deallocate_threshold_block(cpu, bank);
  561. free_out:
  562. kobject_del(b->kobj);
  563. kobject_put(b->kobj);
  564. free_cpumask_var(b->cpus);
  565. kfree(b);
  566. per_cpu(threshold_banks, cpu)[bank] = NULL;
  567. }
  568. static void threshold_remove_device(unsigned int cpu)
  569. {
  570. unsigned int bank;
  571. for (bank = 0; bank < NR_BANKS; ++bank) {
  572. if (!(per_cpu(bank_map, cpu) & (1 << bank)))
  573. continue;
  574. threshold_remove_bank(cpu, bank);
  575. }
  576. }
  577. /* get notified when a cpu comes on/off */
  578. static void __cpuinit
  579. amd_64_threshold_cpu_callback(unsigned long action, unsigned int cpu)
  580. {
  581. switch (action) {
  582. case CPU_ONLINE:
  583. case CPU_ONLINE_FROZEN:
  584. threshold_create_device(cpu);
  585. break;
  586. case CPU_DEAD:
  587. case CPU_DEAD_FROZEN:
  588. threshold_remove_device(cpu);
  589. break;
  590. default:
  591. break;
  592. }
  593. }
  594. static __init int threshold_init_device(void)
  595. {
  596. unsigned lcpu = 0;
  597. /* to hit CPUs online before the notifier is up */
  598. for_each_online_cpu(lcpu) {
  599. int err = threshold_create_device(lcpu);
  600. if (err)
  601. return err;
  602. }
  603. threshold_cpu_callback = amd_64_threshold_cpu_callback;
  604. return 0;
  605. }
  606. device_initcall(threshold_init_device);