mce_amd.c 16 KB

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