mce_amd.c 16 KB

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