sysfs.c 17 KB

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