sysfs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. #include <linux/sysdev.h>
  2. #include <linux/cpu.h>
  3. #include <linux/smp.h>
  4. #include <linux/percpu.h>
  5. #include <linux/init.h>
  6. #include <linux/sched.h>
  7. #include <linux/module.h>
  8. #include <linux/nodemask.h>
  9. #include <linux/cpumask.h>
  10. #include <linux/notifier.h>
  11. #include <asm/current.h>
  12. #include <asm/processor.h>
  13. #include <asm/cputable.h>
  14. #include <asm/firmware.h>
  15. #include <asm/hvcall.h>
  16. #include <asm/prom.h>
  17. #include <asm/machdep.h>
  18. #include <asm/smp.h>
  19. #include "cacheinfo.h"
  20. #ifdef CONFIG_PPC64
  21. #include <asm/paca.h>
  22. #include <asm/lppaca.h>
  23. #endif
  24. static DEFINE_PER_CPU(struct cpu, cpu_devices);
  25. /*
  26. * SMT snooze delay stuff, 64-bit only for now
  27. */
  28. #ifdef CONFIG_PPC64
  29. /* Time in microseconds we delay before sleeping in the idle loop */
  30. DEFINE_PER_CPU(unsigned long, smt_snooze_delay) = { 100 };
  31. static ssize_t store_smt_snooze_delay(struct sys_device *dev,
  32. struct sysdev_attribute *attr,
  33. const char *buf,
  34. size_t count)
  35. {
  36. struct cpu *cpu = container_of(dev, struct cpu, sysdev);
  37. ssize_t ret;
  38. unsigned long snooze;
  39. ret = sscanf(buf, "%lu", &snooze);
  40. if (ret != 1)
  41. return -EINVAL;
  42. per_cpu(smt_snooze_delay, cpu->sysdev.id) = snooze;
  43. return count;
  44. }
  45. static ssize_t show_smt_snooze_delay(struct sys_device *dev,
  46. struct sysdev_attribute *attr,
  47. char *buf)
  48. {
  49. struct cpu *cpu = container_of(dev, struct cpu, sysdev);
  50. return sprintf(buf, "%lu\n", per_cpu(smt_snooze_delay, cpu->sysdev.id));
  51. }
  52. static SYSDEV_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay,
  53. store_smt_snooze_delay);
  54. /* Only parse OF options if the matching cmdline option was not specified */
  55. static int smt_snooze_cmdline;
  56. static int __init smt_setup(void)
  57. {
  58. struct device_node *options;
  59. const unsigned int *val;
  60. unsigned int cpu;
  61. if (!cpu_has_feature(CPU_FTR_SMT))
  62. return -ENODEV;
  63. options = of_find_node_by_path("/options");
  64. if (!options)
  65. return -ENODEV;
  66. val = of_get_property(options, "ibm,smt-snooze-delay", NULL);
  67. if (!smt_snooze_cmdline && val) {
  68. for_each_possible_cpu(cpu)
  69. per_cpu(smt_snooze_delay, cpu) = *val;
  70. }
  71. of_node_put(options);
  72. return 0;
  73. }
  74. __initcall(smt_setup);
  75. static int __init setup_smt_snooze_delay(char *str)
  76. {
  77. unsigned int cpu;
  78. int snooze;
  79. if (!cpu_has_feature(CPU_FTR_SMT))
  80. return 1;
  81. smt_snooze_cmdline = 1;
  82. if (get_option(&str, &snooze)) {
  83. for_each_possible_cpu(cpu)
  84. per_cpu(smt_snooze_delay, cpu) = snooze;
  85. }
  86. return 1;
  87. }
  88. __setup("smt-snooze-delay=", setup_smt_snooze_delay);
  89. #endif /* CONFIG_PPC64 */
  90. /*
  91. * Enabling PMCs will slow partition context switch times so we only do
  92. * it the first time we write to the PMCs.
  93. */
  94. static DEFINE_PER_CPU(char, pmcs_enabled);
  95. void ppc_enable_pmcs(void)
  96. {
  97. /* Only need to enable them once */
  98. if (__get_cpu_var(pmcs_enabled))
  99. return;
  100. __get_cpu_var(pmcs_enabled) = 1;
  101. if (ppc_md.enable_pmcs)
  102. ppc_md.enable_pmcs();
  103. }
  104. EXPORT_SYMBOL(ppc_enable_pmcs);
  105. #define SYSFS_PMCSETUP(NAME, ADDRESS) \
  106. static void read_##NAME(void *val) \
  107. { \
  108. mtspr(ADDRESS, *(unsigned long *)val); \
  109. } \
  110. static unsigned long write_##NAME(unsigned long val) \
  111. { \
  112. ppc_enable_pmcs(); \
  113. mtspr(ADDRESS, *(unsigned long *)val); \
  114. return 0; \
  115. } \
  116. static ssize_t show_##NAME(struct sys_device *dev, \
  117. struct sysdev_attribute *attr, \
  118. char *buf) \
  119. { \
  120. struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
  121. unsigned long val; \
  122. smp_call_function_single(cpu->sysdev.id, read_##NAME, &val, 1); \
  123. return sprintf(buf, "%lx\n", val); \
  124. } \
  125. static ssize_t __used \
  126. store_##NAME(struct sys_device *dev, struct sysdev_attribute *attr, \
  127. const char *buf, size_t count) \
  128. { \
  129. struct cpu *cpu = container_of(dev, struct cpu, sysdev); \
  130. unsigned long val; \
  131. int ret = sscanf(buf, "%lx", &val); \
  132. if (ret != 1) \
  133. return -EINVAL; \
  134. smp_call_function_single(cpu->sysdev.id, write_##NAME, &val, 1); \
  135. return count; \
  136. }
  137. /* Let's define all possible registers, we'll only hook up the ones
  138. * that are implemented on the current processor
  139. */
  140. #if defined(CONFIG_PPC64)
  141. #define HAS_PPC_PMC_CLASSIC 1
  142. #define HAS_PPC_PMC_IBM 1
  143. #define HAS_PPC_PMC_PA6T 1
  144. #elif defined(CONFIG_6xx)
  145. #define HAS_PPC_PMC_CLASSIC 1
  146. #define HAS_PPC_PMC_IBM 1
  147. #define HAS_PPC_PMC_G4 1
  148. #endif
  149. #ifdef HAS_PPC_PMC_CLASSIC
  150. SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0);
  151. SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1);
  152. SYSFS_PMCSETUP(pmc1, SPRN_PMC1);
  153. SYSFS_PMCSETUP(pmc2, SPRN_PMC2);
  154. SYSFS_PMCSETUP(pmc3, SPRN_PMC3);
  155. SYSFS_PMCSETUP(pmc4, SPRN_PMC4);
  156. SYSFS_PMCSETUP(pmc5, SPRN_PMC5);
  157. SYSFS_PMCSETUP(pmc6, SPRN_PMC6);
  158. #ifdef HAS_PPC_PMC_G4
  159. SYSFS_PMCSETUP(mmcr2, SPRN_MMCR2);
  160. #endif
  161. #ifdef CONFIG_PPC64
  162. SYSFS_PMCSETUP(pmc7, SPRN_PMC7);
  163. SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
  164. SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
  165. SYSFS_PMCSETUP(purr, SPRN_PURR);
  166. SYSFS_PMCSETUP(spurr, SPRN_SPURR);
  167. SYSFS_PMCSETUP(dscr, SPRN_DSCR);
  168. static SYSDEV_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
  169. static SYSDEV_ATTR(spurr, 0600, show_spurr, NULL);
  170. static SYSDEV_ATTR(dscr, 0600, show_dscr, store_dscr);
  171. static SYSDEV_ATTR(purr, 0600, show_purr, store_purr);
  172. #endif /* CONFIG_PPC64 */
  173. #ifdef HAS_PPC_PMC_PA6T
  174. SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0);
  175. SYSFS_PMCSETUP(pa6t_pmc1, SPRN_PA6T_PMC1);
  176. SYSFS_PMCSETUP(pa6t_pmc2, SPRN_PA6T_PMC2);
  177. SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3);
  178. SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4);
  179. SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5);
  180. #ifdef CONFIG_DEBUG_KERNEL
  181. SYSFS_PMCSETUP(hid0, SPRN_HID0);
  182. SYSFS_PMCSETUP(hid1, SPRN_HID1);
  183. SYSFS_PMCSETUP(hid4, SPRN_HID4);
  184. SYSFS_PMCSETUP(hid5, SPRN_HID5);
  185. SYSFS_PMCSETUP(ima0, SPRN_PA6T_IMA0);
  186. SYSFS_PMCSETUP(ima1, SPRN_PA6T_IMA1);
  187. SYSFS_PMCSETUP(ima2, SPRN_PA6T_IMA2);
  188. SYSFS_PMCSETUP(ima3, SPRN_PA6T_IMA3);
  189. SYSFS_PMCSETUP(ima4, SPRN_PA6T_IMA4);
  190. SYSFS_PMCSETUP(ima5, SPRN_PA6T_IMA5);
  191. SYSFS_PMCSETUP(ima6, SPRN_PA6T_IMA6);
  192. SYSFS_PMCSETUP(ima7, SPRN_PA6T_IMA7);
  193. SYSFS_PMCSETUP(ima8, SPRN_PA6T_IMA8);
  194. SYSFS_PMCSETUP(ima9, SPRN_PA6T_IMA9);
  195. SYSFS_PMCSETUP(imaat, SPRN_PA6T_IMAAT);
  196. SYSFS_PMCSETUP(btcr, SPRN_PA6T_BTCR);
  197. SYSFS_PMCSETUP(pccr, SPRN_PA6T_PCCR);
  198. SYSFS_PMCSETUP(rpccr, SPRN_PA6T_RPCCR);
  199. SYSFS_PMCSETUP(der, SPRN_PA6T_DER);
  200. SYSFS_PMCSETUP(mer, SPRN_PA6T_MER);
  201. SYSFS_PMCSETUP(ber, SPRN_PA6T_BER);
  202. SYSFS_PMCSETUP(ier, SPRN_PA6T_IER);
  203. SYSFS_PMCSETUP(sier, SPRN_PA6T_SIER);
  204. SYSFS_PMCSETUP(siar, SPRN_PA6T_SIAR);
  205. SYSFS_PMCSETUP(tsr0, SPRN_PA6T_TSR0);
  206. SYSFS_PMCSETUP(tsr1, SPRN_PA6T_TSR1);
  207. SYSFS_PMCSETUP(tsr2, SPRN_PA6T_TSR2);
  208. SYSFS_PMCSETUP(tsr3, SPRN_PA6T_TSR3);
  209. #endif /* CONFIG_DEBUG_KERNEL */
  210. #endif /* HAS_PPC_PMC_PA6T */
  211. #ifdef HAS_PPC_PMC_IBM
  212. static struct sysdev_attribute ibm_common_attrs[] = {
  213. _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
  214. _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
  215. };
  216. #endif /* HAS_PPC_PMC_G4 */
  217. #ifdef HAS_PPC_PMC_G4
  218. static struct sysdev_attribute g4_common_attrs[] = {
  219. _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
  220. _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
  221. _SYSDEV_ATTR(mmcr2, 0600, show_mmcr2, store_mmcr2),
  222. };
  223. #endif /* HAS_PPC_PMC_G4 */
  224. static struct sysdev_attribute classic_pmc_attrs[] = {
  225. _SYSDEV_ATTR(pmc1, 0600, show_pmc1, store_pmc1),
  226. _SYSDEV_ATTR(pmc2, 0600, show_pmc2, store_pmc2),
  227. _SYSDEV_ATTR(pmc3, 0600, show_pmc3, store_pmc3),
  228. _SYSDEV_ATTR(pmc4, 0600, show_pmc4, store_pmc4),
  229. _SYSDEV_ATTR(pmc5, 0600, show_pmc5, store_pmc5),
  230. _SYSDEV_ATTR(pmc6, 0600, show_pmc6, store_pmc6),
  231. #ifdef CONFIG_PPC64
  232. _SYSDEV_ATTR(pmc7, 0600, show_pmc7, store_pmc7),
  233. _SYSDEV_ATTR(pmc8, 0600, show_pmc8, store_pmc8),
  234. #endif
  235. };
  236. #ifdef HAS_PPC_PMC_PA6T
  237. static struct sysdev_attribute pa6t_attrs[] = {
  238. _SYSDEV_ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
  239. _SYSDEV_ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
  240. _SYSDEV_ATTR(pmc0, 0600, show_pa6t_pmc0, store_pa6t_pmc0),
  241. _SYSDEV_ATTR(pmc1, 0600, show_pa6t_pmc1, store_pa6t_pmc1),
  242. _SYSDEV_ATTR(pmc2, 0600, show_pa6t_pmc2, store_pa6t_pmc2),
  243. _SYSDEV_ATTR(pmc3, 0600, show_pa6t_pmc3, store_pa6t_pmc3),
  244. _SYSDEV_ATTR(pmc4, 0600, show_pa6t_pmc4, store_pa6t_pmc4),
  245. _SYSDEV_ATTR(pmc5, 0600, show_pa6t_pmc5, store_pa6t_pmc5),
  246. #ifdef CONFIG_DEBUG_KERNEL
  247. _SYSDEV_ATTR(hid0, 0600, show_hid0, store_hid0),
  248. _SYSDEV_ATTR(hid1, 0600, show_hid1, store_hid1),
  249. _SYSDEV_ATTR(hid4, 0600, show_hid4, store_hid4),
  250. _SYSDEV_ATTR(hid5, 0600, show_hid5, store_hid5),
  251. _SYSDEV_ATTR(ima0, 0600, show_ima0, store_ima0),
  252. _SYSDEV_ATTR(ima1, 0600, show_ima1, store_ima1),
  253. _SYSDEV_ATTR(ima2, 0600, show_ima2, store_ima2),
  254. _SYSDEV_ATTR(ima3, 0600, show_ima3, store_ima3),
  255. _SYSDEV_ATTR(ima4, 0600, show_ima4, store_ima4),
  256. _SYSDEV_ATTR(ima5, 0600, show_ima5, store_ima5),
  257. _SYSDEV_ATTR(ima6, 0600, show_ima6, store_ima6),
  258. _SYSDEV_ATTR(ima7, 0600, show_ima7, store_ima7),
  259. _SYSDEV_ATTR(ima8, 0600, show_ima8, store_ima8),
  260. _SYSDEV_ATTR(ima9, 0600, show_ima9, store_ima9),
  261. _SYSDEV_ATTR(imaat, 0600, show_imaat, store_imaat),
  262. _SYSDEV_ATTR(btcr, 0600, show_btcr, store_btcr),
  263. _SYSDEV_ATTR(pccr, 0600, show_pccr, store_pccr),
  264. _SYSDEV_ATTR(rpccr, 0600, show_rpccr, store_rpccr),
  265. _SYSDEV_ATTR(der, 0600, show_der, store_der),
  266. _SYSDEV_ATTR(mer, 0600, show_mer, store_mer),
  267. _SYSDEV_ATTR(ber, 0600, show_ber, store_ber),
  268. _SYSDEV_ATTR(ier, 0600, show_ier, store_ier),
  269. _SYSDEV_ATTR(sier, 0600, show_sier, store_sier),
  270. _SYSDEV_ATTR(siar, 0600, show_siar, store_siar),
  271. _SYSDEV_ATTR(tsr0, 0600, show_tsr0, store_tsr0),
  272. _SYSDEV_ATTR(tsr1, 0600, show_tsr1, store_tsr1),
  273. _SYSDEV_ATTR(tsr2, 0600, show_tsr2, store_tsr2),
  274. _SYSDEV_ATTR(tsr3, 0600, show_tsr3, store_tsr3),
  275. #endif /* CONFIG_DEBUG_KERNEL */
  276. };
  277. #endif /* HAS_PPC_PMC_PA6T */
  278. #endif /* HAS_PPC_PMC_CLASSIC */
  279. static void __cpuinit register_cpu_online(unsigned int cpu)
  280. {
  281. struct cpu *c = &per_cpu(cpu_devices, cpu);
  282. struct sys_device *s = &c->sysdev;
  283. struct sysdev_attribute *attrs, *pmc_attrs;
  284. int i, nattrs;
  285. #ifdef CONFIG_PPC64
  286. if (!firmware_has_feature(FW_FEATURE_ISERIES) &&
  287. cpu_has_feature(CPU_FTR_SMT))
  288. sysdev_create_file(s, &attr_smt_snooze_delay);
  289. #endif
  290. /* PMC stuff */
  291. switch (cur_cpu_spec->pmc_type) {
  292. #ifdef HAS_PPC_PMC_IBM
  293. case PPC_PMC_IBM:
  294. attrs = ibm_common_attrs;
  295. nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute);
  296. pmc_attrs = classic_pmc_attrs;
  297. break;
  298. #endif /* HAS_PPC_PMC_IBM */
  299. #ifdef HAS_PPC_PMC_G4
  300. case PPC_PMC_G4:
  301. attrs = g4_common_attrs;
  302. nattrs = sizeof(g4_common_attrs) / sizeof(struct sysdev_attribute);
  303. pmc_attrs = classic_pmc_attrs;
  304. break;
  305. #endif /* HAS_PPC_PMC_G4 */
  306. #ifdef HAS_PPC_PMC_PA6T
  307. case PPC_PMC_PA6T:
  308. /* PA Semi starts counting at PMC0 */
  309. attrs = pa6t_attrs;
  310. nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute);
  311. pmc_attrs = NULL;
  312. break;
  313. #endif /* HAS_PPC_PMC_PA6T */
  314. default:
  315. attrs = NULL;
  316. nattrs = 0;
  317. pmc_attrs = NULL;
  318. }
  319. for (i = 0; i < nattrs; i++)
  320. sysdev_create_file(s, &attrs[i]);
  321. if (pmc_attrs)
  322. for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
  323. sysdev_create_file(s, &pmc_attrs[i]);
  324. #ifdef CONFIG_PPC64
  325. if (cpu_has_feature(CPU_FTR_MMCRA))
  326. sysdev_create_file(s, &attr_mmcra);
  327. if (cpu_has_feature(CPU_FTR_PURR))
  328. sysdev_create_file(s, &attr_purr);
  329. if (cpu_has_feature(CPU_FTR_SPURR))
  330. sysdev_create_file(s, &attr_spurr);
  331. if (cpu_has_feature(CPU_FTR_DSCR))
  332. sysdev_create_file(s, &attr_dscr);
  333. #endif /* CONFIG_PPC64 */
  334. cacheinfo_cpu_online(cpu);
  335. }
  336. #ifdef CONFIG_HOTPLUG_CPU
  337. static void unregister_cpu_online(unsigned int cpu)
  338. {
  339. struct cpu *c = &per_cpu(cpu_devices, cpu);
  340. struct sys_device *s = &c->sysdev;
  341. struct sysdev_attribute *attrs, *pmc_attrs;
  342. int i, nattrs;
  343. BUG_ON(!c->hotpluggable);
  344. #ifdef CONFIG_PPC64
  345. if (!firmware_has_feature(FW_FEATURE_ISERIES) &&
  346. cpu_has_feature(CPU_FTR_SMT))
  347. sysdev_remove_file(s, &attr_smt_snooze_delay);
  348. #endif
  349. /* PMC stuff */
  350. switch (cur_cpu_spec->pmc_type) {
  351. #ifdef HAS_PPC_PMC_IBM
  352. case PPC_PMC_IBM:
  353. attrs = ibm_common_attrs;
  354. nattrs = sizeof(ibm_common_attrs) / sizeof(struct sysdev_attribute);
  355. pmc_attrs = classic_pmc_attrs;
  356. break;
  357. #endif /* HAS_PPC_PMC_IBM */
  358. #ifdef HAS_PPC_PMC_G4
  359. case PPC_PMC_G4:
  360. attrs = g4_common_attrs;
  361. nattrs = sizeof(g4_common_attrs) / sizeof(struct sysdev_attribute);
  362. pmc_attrs = classic_pmc_attrs;
  363. break;
  364. #endif /* HAS_PPC_PMC_G4 */
  365. #ifdef HAS_PPC_PMC_PA6T
  366. case PPC_PMC_PA6T:
  367. /* PA Semi starts counting at PMC0 */
  368. attrs = pa6t_attrs;
  369. nattrs = sizeof(pa6t_attrs) / sizeof(struct sysdev_attribute);
  370. pmc_attrs = NULL;
  371. break;
  372. #endif /* HAS_PPC_PMC_PA6T */
  373. default:
  374. attrs = NULL;
  375. nattrs = 0;
  376. pmc_attrs = NULL;
  377. }
  378. for (i = 0; i < nattrs; i++)
  379. sysdev_remove_file(s, &attrs[i]);
  380. if (pmc_attrs)
  381. for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
  382. sysdev_remove_file(s, &pmc_attrs[i]);
  383. #ifdef CONFIG_PPC64
  384. if (cpu_has_feature(CPU_FTR_MMCRA))
  385. sysdev_remove_file(s, &attr_mmcra);
  386. if (cpu_has_feature(CPU_FTR_PURR))
  387. sysdev_remove_file(s, &attr_purr);
  388. if (cpu_has_feature(CPU_FTR_SPURR))
  389. sysdev_remove_file(s, &attr_spurr);
  390. if (cpu_has_feature(CPU_FTR_DSCR))
  391. sysdev_remove_file(s, &attr_dscr);
  392. #endif /* CONFIG_PPC64 */
  393. cacheinfo_cpu_offline(cpu);
  394. }
  395. #endif /* CONFIG_HOTPLUG_CPU */
  396. static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
  397. unsigned long action, void *hcpu)
  398. {
  399. unsigned int cpu = (unsigned int)(long)hcpu;
  400. switch (action) {
  401. case CPU_ONLINE:
  402. case CPU_ONLINE_FROZEN:
  403. register_cpu_online(cpu);
  404. break;
  405. #ifdef CONFIG_HOTPLUG_CPU
  406. case CPU_DEAD:
  407. case CPU_DEAD_FROZEN:
  408. unregister_cpu_online(cpu);
  409. break;
  410. #endif
  411. }
  412. return NOTIFY_OK;
  413. }
  414. static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
  415. .notifier_call = sysfs_cpu_notify,
  416. };
  417. static DEFINE_MUTEX(cpu_mutex);
  418. int cpu_add_sysdev_attr(struct sysdev_attribute *attr)
  419. {
  420. int cpu;
  421. mutex_lock(&cpu_mutex);
  422. for_each_possible_cpu(cpu) {
  423. sysdev_create_file(get_cpu_sysdev(cpu), attr);
  424. }
  425. mutex_unlock(&cpu_mutex);
  426. return 0;
  427. }
  428. EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr);
  429. int cpu_add_sysdev_attr_group(struct attribute_group *attrs)
  430. {
  431. int cpu;
  432. struct sys_device *sysdev;
  433. int ret;
  434. mutex_lock(&cpu_mutex);
  435. for_each_possible_cpu(cpu) {
  436. sysdev = get_cpu_sysdev(cpu);
  437. ret = sysfs_create_group(&sysdev->kobj, attrs);
  438. WARN_ON(ret != 0);
  439. }
  440. mutex_unlock(&cpu_mutex);
  441. return 0;
  442. }
  443. EXPORT_SYMBOL_GPL(cpu_add_sysdev_attr_group);
  444. void cpu_remove_sysdev_attr(struct sysdev_attribute *attr)
  445. {
  446. int cpu;
  447. mutex_lock(&cpu_mutex);
  448. for_each_possible_cpu(cpu) {
  449. sysdev_remove_file(get_cpu_sysdev(cpu), attr);
  450. }
  451. mutex_unlock(&cpu_mutex);
  452. }
  453. EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr);
  454. void cpu_remove_sysdev_attr_group(struct attribute_group *attrs)
  455. {
  456. int cpu;
  457. struct sys_device *sysdev;
  458. mutex_lock(&cpu_mutex);
  459. for_each_possible_cpu(cpu) {
  460. sysdev = get_cpu_sysdev(cpu);
  461. sysfs_remove_group(&sysdev->kobj, attrs);
  462. }
  463. mutex_unlock(&cpu_mutex);
  464. }
  465. EXPORT_SYMBOL_GPL(cpu_remove_sysdev_attr_group);
  466. /* NUMA stuff */
  467. #ifdef CONFIG_NUMA
  468. static void register_nodes(void)
  469. {
  470. int i;
  471. for (i = 0; i < MAX_NUMNODES; i++)
  472. register_one_node(i);
  473. }
  474. int sysfs_add_device_to_node(struct sys_device *dev, int nid)
  475. {
  476. struct node *node = &node_devices[nid];
  477. return sysfs_create_link(&node->sysdev.kobj, &dev->kobj,
  478. kobject_name(&dev->kobj));
  479. }
  480. EXPORT_SYMBOL_GPL(sysfs_add_device_to_node);
  481. void sysfs_remove_device_from_node(struct sys_device *dev, int nid)
  482. {
  483. struct node *node = &node_devices[nid];
  484. sysfs_remove_link(&node->sysdev.kobj, kobject_name(&dev->kobj));
  485. }
  486. EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node);
  487. #else
  488. static void register_nodes(void)
  489. {
  490. return;
  491. }
  492. #endif
  493. /* Only valid if CPU is present. */
  494. static ssize_t show_physical_id(struct sys_device *dev,
  495. struct sysdev_attribute *attr, char *buf)
  496. {
  497. struct cpu *cpu = container_of(dev, struct cpu, sysdev);
  498. return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->sysdev.id));
  499. }
  500. static SYSDEV_ATTR(physical_id, 0444, show_physical_id, NULL);
  501. static int __init topology_init(void)
  502. {
  503. int cpu;
  504. register_nodes();
  505. register_cpu_notifier(&sysfs_cpu_nb);
  506. for_each_possible_cpu(cpu) {
  507. struct cpu *c = &per_cpu(cpu_devices, cpu);
  508. /*
  509. * For now, we just see if the system supports making
  510. * the RTAS calls for CPU hotplug. But, there may be a
  511. * more comprehensive way to do this for an individual
  512. * CPU. For instance, the boot cpu might never be valid
  513. * for hotplugging.
  514. */
  515. if (ppc_md.cpu_die)
  516. c->hotpluggable = 1;
  517. if (cpu_online(cpu) || c->hotpluggable) {
  518. register_cpu(c, cpu);
  519. sysdev_create_file(&c->sysdev, &attr_physical_id);
  520. }
  521. if (cpu_online(cpu))
  522. register_cpu_online(cpu);
  523. }
  524. return 0;
  525. }
  526. subsys_initcall(topology_init);