mce_amd.c 16 KB

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