sysfs.c 17 KB

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