sysfs.c 15 KB

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