sysfs.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  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. return count;
  45. }
  46. static ssize_t show_smt_snooze_delay(struct device *dev,
  47. struct device_attribute *attr,
  48. char *buf)
  49. {
  50. struct cpu *cpu = container_of(dev, struct cpu, dev);
  51. return sprintf(buf, "%ld\n", per_cpu(smt_snooze_delay, cpu->dev.id));
  52. }
  53. static DEVICE_ATTR(smt_snooze_delay, 0644, show_smt_snooze_delay,
  54. store_smt_snooze_delay);
  55. static int __init setup_smt_snooze_delay(char *str)
  56. {
  57. unsigned int cpu;
  58. long snooze;
  59. if (!cpu_has_feature(CPU_FTR_SMT))
  60. return 1;
  61. snooze = simple_strtol(str, NULL, 10);
  62. for_each_possible_cpu(cpu)
  63. per_cpu(smt_snooze_delay, cpu) = snooze;
  64. return 1;
  65. }
  66. __setup("smt-snooze-delay=", setup_smt_snooze_delay);
  67. #endif /* CONFIG_PPC64 */
  68. #ifdef CONFIG_PPC_FSL_BOOK3E
  69. #define MAX_BIT 63
  70. static u64 pw20_wt;
  71. static u64 altivec_idle_wt;
  72. static unsigned int get_idle_ticks_bit(u64 ns)
  73. {
  74. u64 cycle;
  75. if (ns >= 10000)
  76. cycle = div_u64(ns + 500, 1000) * tb_ticks_per_usec;
  77. else
  78. cycle = div_u64(ns * tb_ticks_per_usec, 1000);
  79. if (!cycle)
  80. return 0;
  81. return ilog2(cycle);
  82. }
  83. static void do_show_pwrmgtcr0(void *val)
  84. {
  85. u32 *value = val;
  86. *value = mfspr(SPRN_PWRMGTCR0);
  87. }
  88. static ssize_t show_pw20_state(struct device *dev,
  89. struct device_attribute *attr, char *buf)
  90. {
  91. u32 value;
  92. unsigned int cpu = dev->id;
  93. smp_call_function_single(cpu, do_show_pwrmgtcr0, &value, 1);
  94. value &= PWRMGTCR0_PW20_WAIT;
  95. return sprintf(buf, "%u\n", value ? 1 : 0);
  96. }
  97. static void do_store_pw20_state(void *val)
  98. {
  99. u32 *value = val;
  100. u32 pw20_state;
  101. pw20_state = mfspr(SPRN_PWRMGTCR0);
  102. if (*value)
  103. pw20_state |= PWRMGTCR0_PW20_WAIT;
  104. else
  105. pw20_state &= ~PWRMGTCR0_PW20_WAIT;
  106. mtspr(SPRN_PWRMGTCR0, pw20_state);
  107. }
  108. static ssize_t store_pw20_state(struct device *dev,
  109. struct device_attribute *attr,
  110. const char *buf, size_t count)
  111. {
  112. u32 value;
  113. unsigned int cpu = dev->id;
  114. if (kstrtou32(buf, 0, &value))
  115. return -EINVAL;
  116. if (value > 1)
  117. return -EINVAL;
  118. smp_call_function_single(cpu, do_store_pw20_state, &value, 1);
  119. return count;
  120. }
  121. static ssize_t show_pw20_wait_time(struct device *dev,
  122. struct device_attribute *attr, char *buf)
  123. {
  124. u32 value;
  125. u64 tb_cycle = 1;
  126. u64 time;
  127. unsigned int cpu = dev->id;
  128. if (!pw20_wt) {
  129. smp_call_function_single(cpu, do_show_pwrmgtcr0, &value, 1);
  130. value = (value & PWRMGTCR0_PW20_ENT) >>
  131. PWRMGTCR0_PW20_ENT_SHIFT;
  132. tb_cycle = (tb_cycle << (MAX_BIT - value + 1));
  133. /* convert ms to ns */
  134. if (tb_ticks_per_usec > 1000) {
  135. time = div_u64(tb_cycle, tb_ticks_per_usec / 1000);
  136. } else {
  137. u32 rem_us;
  138. time = div_u64_rem(tb_cycle, tb_ticks_per_usec,
  139. &rem_us);
  140. time = time * 1000 + rem_us * 1000 / tb_ticks_per_usec;
  141. }
  142. } else {
  143. time = pw20_wt;
  144. }
  145. return sprintf(buf, "%llu\n", time > 0 ? time : 0);
  146. }
  147. static void set_pw20_wait_entry_bit(void *val)
  148. {
  149. u32 *value = val;
  150. u32 pw20_idle;
  151. pw20_idle = mfspr(SPRN_PWRMGTCR0);
  152. /* Set Automatic PW20 Core Idle Count */
  153. /* clear count */
  154. pw20_idle &= ~PWRMGTCR0_PW20_ENT;
  155. /* set count */
  156. pw20_idle |= ((MAX_BIT - *value) << PWRMGTCR0_PW20_ENT_SHIFT);
  157. mtspr(SPRN_PWRMGTCR0, pw20_idle);
  158. }
  159. static ssize_t store_pw20_wait_time(struct device *dev,
  160. struct device_attribute *attr,
  161. const char *buf, size_t count)
  162. {
  163. u32 entry_bit;
  164. u64 value;
  165. unsigned int cpu = dev->id;
  166. if (kstrtou64(buf, 0, &value))
  167. return -EINVAL;
  168. if (!value)
  169. return -EINVAL;
  170. entry_bit = get_idle_ticks_bit(value);
  171. if (entry_bit > MAX_BIT)
  172. return -EINVAL;
  173. pw20_wt = value;
  174. smp_call_function_single(cpu, set_pw20_wait_entry_bit,
  175. &entry_bit, 1);
  176. return count;
  177. }
  178. static ssize_t show_altivec_idle(struct device *dev,
  179. struct device_attribute *attr, char *buf)
  180. {
  181. u32 value;
  182. unsigned int cpu = dev->id;
  183. smp_call_function_single(cpu, do_show_pwrmgtcr0, &value, 1);
  184. value &= PWRMGTCR0_AV_IDLE_PD_EN;
  185. return sprintf(buf, "%u\n", value ? 1 : 0);
  186. }
  187. static void do_store_altivec_idle(void *val)
  188. {
  189. u32 *value = val;
  190. u32 altivec_idle;
  191. altivec_idle = mfspr(SPRN_PWRMGTCR0);
  192. if (*value)
  193. altivec_idle |= PWRMGTCR0_AV_IDLE_PD_EN;
  194. else
  195. altivec_idle &= ~PWRMGTCR0_AV_IDLE_PD_EN;
  196. mtspr(SPRN_PWRMGTCR0, altivec_idle);
  197. }
  198. static ssize_t store_altivec_idle(struct device *dev,
  199. struct device_attribute *attr,
  200. const char *buf, size_t count)
  201. {
  202. u32 value;
  203. unsigned int cpu = dev->id;
  204. if (kstrtou32(buf, 0, &value))
  205. return -EINVAL;
  206. if (value > 1)
  207. return -EINVAL;
  208. smp_call_function_single(cpu, do_store_altivec_idle, &value, 1);
  209. return count;
  210. }
  211. static ssize_t show_altivec_idle_wait_time(struct device *dev,
  212. struct device_attribute *attr, char *buf)
  213. {
  214. u32 value;
  215. u64 tb_cycle = 1;
  216. u64 time;
  217. unsigned int cpu = dev->id;
  218. if (!altivec_idle_wt) {
  219. smp_call_function_single(cpu, do_show_pwrmgtcr0, &value, 1);
  220. value = (value & PWRMGTCR0_AV_IDLE_CNT) >>
  221. PWRMGTCR0_AV_IDLE_CNT_SHIFT;
  222. tb_cycle = (tb_cycle << (MAX_BIT - value + 1));
  223. /* convert ms to ns */
  224. if (tb_ticks_per_usec > 1000) {
  225. time = div_u64(tb_cycle, tb_ticks_per_usec / 1000);
  226. } else {
  227. u32 rem_us;
  228. time = div_u64_rem(tb_cycle, tb_ticks_per_usec,
  229. &rem_us);
  230. time = time * 1000 + rem_us * 1000 / tb_ticks_per_usec;
  231. }
  232. } else {
  233. time = altivec_idle_wt;
  234. }
  235. return sprintf(buf, "%llu\n", time > 0 ? time : 0);
  236. }
  237. static void set_altivec_idle_wait_entry_bit(void *val)
  238. {
  239. u32 *value = val;
  240. u32 altivec_idle;
  241. altivec_idle = mfspr(SPRN_PWRMGTCR0);
  242. /* Set Automatic AltiVec Idle Count */
  243. /* clear count */
  244. altivec_idle &= ~PWRMGTCR0_AV_IDLE_CNT;
  245. /* set count */
  246. altivec_idle |= ((MAX_BIT - *value) << PWRMGTCR0_AV_IDLE_CNT_SHIFT);
  247. mtspr(SPRN_PWRMGTCR0, altivec_idle);
  248. }
  249. static ssize_t store_altivec_idle_wait_time(struct device *dev,
  250. struct device_attribute *attr,
  251. const char *buf, size_t count)
  252. {
  253. u32 entry_bit;
  254. u64 value;
  255. unsigned int cpu = dev->id;
  256. if (kstrtou64(buf, 0, &value))
  257. return -EINVAL;
  258. if (!value)
  259. return -EINVAL;
  260. entry_bit = get_idle_ticks_bit(value);
  261. if (entry_bit > MAX_BIT)
  262. return -EINVAL;
  263. altivec_idle_wt = value;
  264. smp_call_function_single(cpu, set_altivec_idle_wait_entry_bit,
  265. &entry_bit, 1);
  266. return count;
  267. }
  268. /*
  269. * Enable/Disable interface:
  270. * 0, disable. 1, enable.
  271. */
  272. static DEVICE_ATTR(pw20_state, 0600, show_pw20_state, store_pw20_state);
  273. static DEVICE_ATTR(altivec_idle, 0600, show_altivec_idle, store_altivec_idle);
  274. /*
  275. * Set wait time interface:(Nanosecond)
  276. * Example: Base on TBfreq is 41MHZ.
  277. * 1~48(ns): TB[63]
  278. * 49~97(ns): TB[62]
  279. * 98~195(ns): TB[61]
  280. * 196~390(ns): TB[60]
  281. * 391~780(ns): TB[59]
  282. * 781~1560(ns): TB[58]
  283. * ...
  284. */
  285. static DEVICE_ATTR(pw20_wait_time, 0600,
  286. show_pw20_wait_time,
  287. store_pw20_wait_time);
  288. static DEVICE_ATTR(altivec_idle_wait_time, 0600,
  289. show_altivec_idle_wait_time,
  290. store_altivec_idle_wait_time);
  291. #endif
  292. /*
  293. * Enabling PMCs will slow partition context switch times so we only do
  294. * it the first time we write to the PMCs.
  295. */
  296. static DEFINE_PER_CPU(char, pmcs_enabled);
  297. void ppc_enable_pmcs(void)
  298. {
  299. ppc_set_pmu_inuse(1);
  300. /* Only need to enable them once */
  301. if (__this_cpu_read(pmcs_enabled))
  302. return;
  303. __this_cpu_write(pmcs_enabled, 1);
  304. if (ppc_md.enable_pmcs)
  305. ppc_md.enable_pmcs();
  306. }
  307. EXPORT_SYMBOL(ppc_enable_pmcs);
  308. #define __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, EXTRA) \
  309. static void read_##NAME(void *val) \
  310. { \
  311. *(unsigned long *)val = mfspr(ADDRESS); \
  312. } \
  313. static void write_##NAME(void *val) \
  314. { \
  315. EXTRA; \
  316. mtspr(ADDRESS, *(unsigned long *)val); \
  317. }
  318. #define __SYSFS_SPRSETUP_SHOW_STORE(NAME) \
  319. static ssize_t show_##NAME(struct device *dev, \
  320. struct device_attribute *attr, \
  321. char *buf) \
  322. { \
  323. struct cpu *cpu = container_of(dev, struct cpu, dev); \
  324. unsigned long val; \
  325. smp_call_function_single(cpu->dev.id, read_##NAME, &val, 1); \
  326. return sprintf(buf, "%lx\n", val); \
  327. } \
  328. static ssize_t __used \
  329. store_##NAME(struct device *dev, struct device_attribute *attr, \
  330. const char *buf, size_t count) \
  331. { \
  332. struct cpu *cpu = container_of(dev, struct cpu, dev); \
  333. unsigned long val; \
  334. int ret = sscanf(buf, "%lx", &val); \
  335. if (ret != 1) \
  336. return -EINVAL; \
  337. smp_call_function_single(cpu->dev.id, write_##NAME, &val, 1); \
  338. return count; \
  339. }
  340. #define SYSFS_PMCSETUP(NAME, ADDRESS) \
  341. __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, ppc_enable_pmcs()) \
  342. __SYSFS_SPRSETUP_SHOW_STORE(NAME)
  343. #define SYSFS_SPRSETUP(NAME, ADDRESS) \
  344. __SYSFS_SPRSETUP_READ_WRITE(NAME, ADDRESS, ) \
  345. __SYSFS_SPRSETUP_SHOW_STORE(NAME)
  346. #define SYSFS_SPRSETUP_SHOW_STORE(NAME) \
  347. __SYSFS_SPRSETUP_SHOW_STORE(NAME)
  348. /* Let's define all possible registers, we'll only hook up the ones
  349. * that are implemented on the current processor
  350. */
  351. #if defined(CONFIG_PPC64)
  352. #define HAS_PPC_PMC_CLASSIC 1
  353. #define HAS_PPC_PMC_IBM 1
  354. #define HAS_PPC_PMC_PA6T 1
  355. #elif defined(CONFIG_6xx)
  356. #define HAS_PPC_PMC_CLASSIC 1
  357. #define HAS_PPC_PMC_IBM 1
  358. #define HAS_PPC_PMC_G4 1
  359. #endif
  360. #ifdef HAS_PPC_PMC_CLASSIC
  361. SYSFS_PMCSETUP(mmcr0, SPRN_MMCR0);
  362. SYSFS_PMCSETUP(mmcr1, SPRN_MMCR1);
  363. SYSFS_PMCSETUP(pmc1, SPRN_PMC1);
  364. SYSFS_PMCSETUP(pmc2, SPRN_PMC2);
  365. SYSFS_PMCSETUP(pmc3, SPRN_PMC3);
  366. SYSFS_PMCSETUP(pmc4, SPRN_PMC4);
  367. SYSFS_PMCSETUP(pmc5, SPRN_PMC5);
  368. SYSFS_PMCSETUP(pmc6, SPRN_PMC6);
  369. #ifdef HAS_PPC_PMC_G4
  370. SYSFS_PMCSETUP(mmcr2, SPRN_MMCR2);
  371. #endif
  372. #ifdef CONFIG_PPC64
  373. SYSFS_PMCSETUP(pmc7, SPRN_PMC7);
  374. SYSFS_PMCSETUP(pmc8, SPRN_PMC8);
  375. SYSFS_PMCSETUP(mmcra, SPRN_MMCRA);
  376. SYSFS_SPRSETUP(purr, SPRN_PURR);
  377. SYSFS_SPRSETUP(spurr, SPRN_SPURR);
  378. SYSFS_SPRSETUP(pir, SPRN_PIR);
  379. /*
  380. Lets only enable read for phyp resources and
  381. enable write when needed with a separate function.
  382. Lets be conservative and default to pseries.
  383. */
  384. static DEVICE_ATTR(mmcra, 0600, show_mmcra, store_mmcra);
  385. static DEVICE_ATTR(spurr, 0400, show_spurr, NULL);
  386. static DEVICE_ATTR(purr, 0400, show_purr, store_purr);
  387. static DEVICE_ATTR(pir, 0400, show_pir, NULL);
  388. /*
  389. * This is the system wide DSCR register default value. Any
  390. * change to this default value through the sysfs interface
  391. * will update all per cpu DSCR default values across the
  392. * system stored in their respective PACA structures.
  393. */
  394. static unsigned long dscr_default;
  395. /**
  396. * read_dscr() - Fetch the cpu specific DSCR default
  397. * @val: Returned cpu specific DSCR default value
  398. *
  399. * This function returns the per cpu DSCR default value
  400. * for any cpu which is contained in it's PACA structure.
  401. */
  402. static void read_dscr(void *val)
  403. {
  404. *(unsigned long *)val = get_paca()->dscr_default;
  405. }
  406. /**
  407. * write_dscr() - Update the cpu specific DSCR default
  408. * @val: New cpu specific DSCR default value to update
  409. *
  410. * This function updates the per cpu DSCR default value
  411. * for any cpu which is contained in it's PACA structure.
  412. */
  413. static void write_dscr(void *val)
  414. {
  415. get_paca()->dscr_default = *(unsigned long *)val;
  416. if (!current->thread.dscr_inherit) {
  417. current->thread.dscr = *(unsigned long *)val;
  418. mtspr(SPRN_DSCR, *(unsigned long *)val);
  419. }
  420. }
  421. SYSFS_SPRSETUP_SHOW_STORE(dscr);
  422. static DEVICE_ATTR(dscr, 0600, show_dscr, store_dscr);
  423. static void add_write_permission_dev_attr(struct device_attribute *attr)
  424. {
  425. attr->attr.mode |= 0200;
  426. }
  427. /**
  428. * show_dscr_default() - Fetch the system wide DSCR default
  429. * @dev: Device structure
  430. * @attr: Device attribute structure
  431. * @buf: Interface buffer
  432. *
  433. * This function returns the system wide DSCR default value.
  434. */
  435. static ssize_t show_dscr_default(struct device *dev,
  436. struct device_attribute *attr, char *buf)
  437. {
  438. return sprintf(buf, "%lx\n", dscr_default);
  439. }
  440. /**
  441. * store_dscr_default() - Update the system wide DSCR default
  442. * @dev: Device structure
  443. * @attr: Device attribute structure
  444. * @buf: Interface buffer
  445. * @count: Size of the update
  446. *
  447. * This function updates the system wide DSCR default value.
  448. */
  449. static ssize_t __used store_dscr_default(struct device *dev,
  450. struct device_attribute *attr, const char *buf,
  451. size_t count)
  452. {
  453. unsigned long val;
  454. int ret = 0;
  455. ret = sscanf(buf, "%lx", &val);
  456. if (ret != 1)
  457. return -EINVAL;
  458. dscr_default = val;
  459. on_each_cpu(write_dscr, &val, 1);
  460. return count;
  461. }
  462. static DEVICE_ATTR(dscr_default, 0600,
  463. show_dscr_default, store_dscr_default);
  464. static void sysfs_create_dscr_default(void)
  465. {
  466. int err = 0;
  467. if (cpu_has_feature(CPU_FTR_DSCR))
  468. err = device_create_file(cpu_subsys.dev_root, &dev_attr_dscr_default);
  469. }
  470. #endif /* CONFIG_PPC64 */
  471. #ifdef HAS_PPC_PMC_PA6T
  472. SYSFS_PMCSETUP(pa6t_pmc0, SPRN_PA6T_PMC0);
  473. SYSFS_PMCSETUP(pa6t_pmc1, SPRN_PA6T_PMC1);
  474. SYSFS_PMCSETUP(pa6t_pmc2, SPRN_PA6T_PMC2);
  475. SYSFS_PMCSETUP(pa6t_pmc3, SPRN_PA6T_PMC3);
  476. SYSFS_PMCSETUP(pa6t_pmc4, SPRN_PA6T_PMC4);
  477. SYSFS_PMCSETUP(pa6t_pmc5, SPRN_PA6T_PMC5);
  478. #ifdef CONFIG_DEBUG_KERNEL
  479. SYSFS_SPRSETUP(hid0, SPRN_HID0);
  480. SYSFS_SPRSETUP(hid1, SPRN_HID1);
  481. SYSFS_SPRSETUP(hid4, SPRN_HID4);
  482. SYSFS_SPRSETUP(hid5, SPRN_HID5);
  483. SYSFS_SPRSETUP(ima0, SPRN_PA6T_IMA0);
  484. SYSFS_SPRSETUP(ima1, SPRN_PA6T_IMA1);
  485. SYSFS_SPRSETUP(ima2, SPRN_PA6T_IMA2);
  486. SYSFS_SPRSETUP(ima3, SPRN_PA6T_IMA3);
  487. SYSFS_SPRSETUP(ima4, SPRN_PA6T_IMA4);
  488. SYSFS_SPRSETUP(ima5, SPRN_PA6T_IMA5);
  489. SYSFS_SPRSETUP(ima6, SPRN_PA6T_IMA6);
  490. SYSFS_SPRSETUP(ima7, SPRN_PA6T_IMA7);
  491. SYSFS_SPRSETUP(ima8, SPRN_PA6T_IMA8);
  492. SYSFS_SPRSETUP(ima9, SPRN_PA6T_IMA9);
  493. SYSFS_SPRSETUP(imaat, SPRN_PA6T_IMAAT);
  494. SYSFS_SPRSETUP(btcr, SPRN_PA6T_BTCR);
  495. SYSFS_SPRSETUP(pccr, SPRN_PA6T_PCCR);
  496. SYSFS_SPRSETUP(rpccr, SPRN_PA6T_RPCCR);
  497. SYSFS_SPRSETUP(der, SPRN_PA6T_DER);
  498. SYSFS_SPRSETUP(mer, SPRN_PA6T_MER);
  499. SYSFS_SPRSETUP(ber, SPRN_PA6T_BER);
  500. SYSFS_SPRSETUP(ier, SPRN_PA6T_IER);
  501. SYSFS_SPRSETUP(sier, SPRN_PA6T_SIER);
  502. SYSFS_SPRSETUP(siar, SPRN_PA6T_SIAR);
  503. SYSFS_SPRSETUP(tsr0, SPRN_PA6T_TSR0);
  504. SYSFS_SPRSETUP(tsr1, SPRN_PA6T_TSR1);
  505. SYSFS_SPRSETUP(tsr2, SPRN_PA6T_TSR2);
  506. SYSFS_SPRSETUP(tsr3, SPRN_PA6T_TSR3);
  507. #endif /* CONFIG_DEBUG_KERNEL */
  508. #endif /* HAS_PPC_PMC_PA6T */
  509. #ifdef HAS_PPC_PMC_IBM
  510. static struct device_attribute ibm_common_attrs[] = {
  511. __ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
  512. __ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
  513. };
  514. #endif /* HAS_PPC_PMC_G4 */
  515. #ifdef HAS_PPC_PMC_G4
  516. static struct device_attribute g4_common_attrs[] = {
  517. __ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
  518. __ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
  519. __ATTR(mmcr2, 0600, show_mmcr2, store_mmcr2),
  520. };
  521. #endif /* HAS_PPC_PMC_G4 */
  522. static struct device_attribute classic_pmc_attrs[] = {
  523. __ATTR(pmc1, 0600, show_pmc1, store_pmc1),
  524. __ATTR(pmc2, 0600, show_pmc2, store_pmc2),
  525. __ATTR(pmc3, 0600, show_pmc3, store_pmc3),
  526. __ATTR(pmc4, 0600, show_pmc4, store_pmc4),
  527. __ATTR(pmc5, 0600, show_pmc5, store_pmc5),
  528. __ATTR(pmc6, 0600, show_pmc6, store_pmc6),
  529. #ifdef CONFIG_PPC64
  530. __ATTR(pmc7, 0600, show_pmc7, store_pmc7),
  531. __ATTR(pmc8, 0600, show_pmc8, store_pmc8),
  532. #endif
  533. };
  534. #ifdef HAS_PPC_PMC_PA6T
  535. static struct device_attribute pa6t_attrs[] = {
  536. __ATTR(mmcr0, 0600, show_mmcr0, store_mmcr0),
  537. __ATTR(mmcr1, 0600, show_mmcr1, store_mmcr1),
  538. __ATTR(pmc0, 0600, show_pa6t_pmc0, store_pa6t_pmc0),
  539. __ATTR(pmc1, 0600, show_pa6t_pmc1, store_pa6t_pmc1),
  540. __ATTR(pmc2, 0600, show_pa6t_pmc2, store_pa6t_pmc2),
  541. __ATTR(pmc3, 0600, show_pa6t_pmc3, store_pa6t_pmc3),
  542. __ATTR(pmc4, 0600, show_pa6t_pmc4, store_pa6t_pmc4),
  543. __ATTR(pmc5, 0600, show_pa6t_pmc5, store_pa6t_pmc5),
  544. #ifdef CONFIG_DEBUG_KERNEL
  545. __ATTR(hid0, 0600, show_hid0, store_hid0),
  546. __ATTR(hid1, 0600, show_hid1, store_hid1),
  547. __ATTR(hid4, 0600, show_hid4, store_hid4),
  548. __ATTR(hid5, 0600, show_hid5, store_hid5),
  549. __ATTR(ima0, 0600, show_ima0, store_ima0),
  550. __ATTR(ima1, 0600, show_ima1, store_ima1),
  551. __ATTR(ima2, 0600, show_ima2, store_ima2),
  552. __ATTR(ima3, 0600, show_ima3, store_ima3),
  553. __ATTR(ima4, 0600, show_ima4, store_ima4),
  554. __ATTR(ima5, 0600, show_ima5, store_ima5),
  555. __ATTR(ima6, 0600, show_ima6, store_ima6),
  556. __ATTR(ima7, 0600, show_ima7, store_ima7),
  557. __ATTR(ima8, 0600, show_ima8, store_ima8),
  558. __ATTR(ima9, 0600, show_ima9, store_ima9),
  559. __ATTR(imaat, 0600, show_imaat, store_imaat),
  560. __ATTR(btcr, 0600, show_btcr, store_btcr),
  561. __ATTR(pccr, 0600, show_pccr, store_pccr),
  562. __ATTR(rpccr, 0600, show_rpccr, store_rpccr),
  563. __ATTR(der, 0600, show_der, store_der),
  564. __ATTR(mer, 0600, show_mer, store_mer),
  565. __ATTR(ber, 0600, show_ber, store_ber),
  566. __ATTR(ier, 0600, show_ier, store_ier),
  567. __ATTR(sier, 0600, show_sier, store_sier),
  568. __ATTR(siar, 0600, show_siar, store_siar),
  569. __ATTR(tsr0, 0600, show_tsr0, store_tsr0),
  570. __ATTR(tsr1, 0600, show_tsr1, store_tsr1),
  571. __ATTR(tsr2, 0600, show_tsr2, store_tsr2),
  572. __ATTR(tsr3, 0600, show_tsr3, store_tsr3),
  573. #endif /* CONFIG_DEBUG_KERNEL */
  574. };
  575. #endif /* HAS_PPC_PMC_PA6T */
  576. #endif /* HAS_PPC_PMC_CLASSIC */
  577. static void register_cpu_online(unsigned int cpu)
  578. {
  579. struct cpu *c = &per_cpu(cpu_devices, cpu);
  580. struct device *s = &c->dev;
  581. struct device_attribute *attrs, *pmc_attrs;
  582. int i, nattrs;
  583. #ifdef CONFIG_PPC64
  584. if (cpu_has_feature(CPU_FTR_SMT))
  585. device_create_file(s, &dev_attr_smt_snooze_delay);
  586. #endif
  587. /* PMC stuff */
  588. switch (cur_cpu_spec->pmc_type) {
  589. #ifdef HAS_PPC_PMC_IBM
  590. case PPC_PMC_IBM:
  591. attrs = ibm_common_attrs;
  592. nattrs = sizeof(ibm_common_attrs) / sizeof(struct device_attribute);
  593. pmc_attrs = classic_pmc_attrs;
  594. break;
  595. #endif /* HAS_PPC_PMC_IBM */
  596. #ifdef HAS_PPC_PMC_G4
  597. case PPC_PMC_G4:
  598. attrs = g4_common_attrs;
  599. nattrs = sizeof(g4_common_attrs) / sizeof(struct device_attribute);
  600. pmc_attrs = classic_pmc_attrs;
  601. break;
  602. #endif /* HAS_PPC_PMC_G4 */
  603. #ifdef HAS_PPC_PMC_PA6T
  604. case PPC_PMC_PA6T:
  605. /* PA Semi starts counting at PMC0 */
  606. attrs = pa6t_attrs;
  607. nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute);
  608. pmc_attrs = NULL;
  609. break;
  610. #endif /* HAS_PPC_PMC_PA6T */
  611. default:
  612. attrs = NULL;
  613. nattrs = 0;
  614. pmc_attrs = NULL;
  615. }
  616. for (i = 0; i < nattrs; i++)
  617. device_create_file(s, &attrs[i]);
  618. if (pmc_attrs)
  619. for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
  620. device_create_file(s, &pmc_attrs[i]);
  621. #ifdef CONFIG_PPC64
  622. if (cpu_has_feature(CPU_FTR_MMCRA))
  623. device_create_file(s, &dev_attr_mmcra);
  624. if (cpu_has_feature(CPU_FTR_PURR)) {
  625. if (!firmware_has_feature(FW_FEATURE_LPAR))
  626. add_write_permission_dev_attr(&dev_attr_purr);
  627. device_create_file(s, &dev_attr_purr);
  628. }
  629. if (cpu_has_feature(CPU_FTR_SPURR))
  630. device_create_file(s, &dev_attr_spurr);
  631. if (cpu_has_feature(CPU_FTR_DSCR))
  632. device_create_file(s, &dev_attr_dscr);
  633. if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2))
  634. device_create_file(s, &dev_attr_pir);
  635. #endif /* CONFIG_PPC64 */
  636. #ifdef CONFIG_PPC_FSL_BOOK3E
  637. if (PVR_VER(cur_cpu_spec->pvr_value) == PVR_VER_E6500) {
  638. device_create_file(s, &dev_attr_pw20_state);
  639. device_create_file(s, &dev_attr_pw20_wait_time);
  640. device_create_file(s, &dev_attr_altivec_idle);
  641. device_create_file(s, &dev_attr_altivec_idle_wait_time);
  642. }
  643. #endif
  644. cacheinfo_cpu_online(cpu);
  645. }
  646. #ifdef CONFIG_HOTPLUG_CPU
  647. static void unregister_cpu_online(unsigned int cpu)
  648. {
  649. struct cpu *c = &per_cpu(cpu_devices, cpu);
  650. struct device *s = &c->dev;
  651. struct device_attribute *attrs, *pmc_attrs;
  652. int i, nattrs;
  653. BUG_ON(!c->hotpluggable);
  654. #ifdef CONFIG_PPC64
  655. if (cpu_has_feature(CPU_FTR_SMT))
  656. device_remove_file(s, &dev_attr_smt_snooze_delay);
  657. #endif
  658. /* PMC stuff */
  659. switch (cur_cpu_spec->pmc_type) {
  660. #ifdef HAS_PPC_PMC_IBM
  661. case PPC_PMC_IBM:
  662. attrs = ibm_common_attrs;
  663. nattrs = sizeof(ibm_common_attrs) / sizeof(struct device_attribute);
  664. pmc_attrs = classic_pmc_attrs;
  665. break;
  666. #endif /* HAS_PPC_PMC_IBM */
  667. #ifdef HAS_PPC_PMC_G4
  668. case PPC_PMC_G4:
  669. attrs = g4_common_attrs;
  670. nattrs = sizeof(g4_common_attrs) / sizeof(struct device_attribute);
  671. pmc_attrs = classic_pmc_attrs;
  672. break;
  673. #endif /* HAS_PPC_PMC_G4 */
  674. #ifdef HAS_PPC_PMC_PA6T
  675. case PPC_PMC_PA6T:
  676. /* PA Semi starts counting at PMC0 */
  677. attrs = pa6t_attrs;
  678. nattrs = sizeof(pa6t_attrs) / sizeof(struct device_attribute);
  679. pmc_attrs = NULL;
  680. break;
  681. #endif /* HAS_PPC_PMC_PA6T */
  682. default:
  683. attrs = NULL;
  684. nattrs = 0;
  685. pmc_attrs = NULL;
  686. }
  687. for (i = 0; i < nattrs; i++)
  688. device_remove_file(s, &attrs[i]);
  689. if (pmc_attrs)
  690. for (i = 0; i < cur_cpu_spec->num_pmcs; i++)
  691. device_remove_file(s, &pmc_attrs[i]);
  692. #ifdef CONFIG_PPC64
  693. if (cpu_has_feature(CPU_FTR_MMCRA))
  694. device_remove_file(s, &dev_attr_mmcra);
  695. if (cpu_has_feature(CPU_FTR_PURR))
  696. device_remove_file(s, &dev_attr_purr);
  697. if (cpu_has_feature(CPU_FTR_SPURR))
  698. device_remove_file(s, &dev_attr_spurr);
  699. if (cpu_has_feature(CPU_FTR_DSCR))
  700. device_remove_file(s, &dev_attr_dscr);
  701. if (cpu_has_feature(CPU_FTR_PPCAS_ARCH_V2))
  702. device_remove_file(s, &dev_attr_pir);
  703. #endif /* CONFIG_PPC64 */
  704. #ifdef CONFIG_PPC_FSL_BOOK3E
  705. if (PVR_VER(cur_cpu_spec->pvr_value) == PVR_VER_E6500) {
  706. device_remove_file(s, &dev_attr_pw20_state);
  707. device_remove_file(s, &dev_attr_pw20_wait_time);
  708. device_remove_file(s, &dev_attr_altivec_idle);
  709. device_remove_file(s, &dev_attr_altivec_idle_wait_time);
  710. }
  711. #endif
  712. cacheinfo_cpu_offline(cpu);
  713. }
  714. #ifdef CONFIG_ARCH_CPU_PROBE_RELEASE
  715. ssize_t arch_cpu_probe(const char *buf, size_t count)
  716. {
  717. if (ppc_md.cpu_probe)
  718. return ppc_md.cpu_probe(buf, count);
  719. return -EINVAL;
  720. }
  721. ssize_t arch_cpu_release(const char *buf, size_t count)
  722. {
  723. if (ppc_md.cpu_release)
  724. return ppc_md.cpu_release(buf, count);
  725. return -EINVAL;
  726. }
  727. #endif /* CONFIG_ARCH_CPU_PROBE_RELEASE */
  728. #endif /* CONFIG_HOTPLUG_CPU */
  729. static int sysfs_cpu_notify(struct notifier_block *self,
  730. unsigned long action, void *hcpu)
  731. {
  732. unsigned int cpu = (unsigned int)(long)hcpu;
  733. switch (action) {
  734. case CPU_ONLINE:
  735. case CPU_ONLINE_FROZEN:
  736. register_cpu_online(cpu);
  737. break;
  738. #ifdef CONFIG_HOTPLUG_CPU
  739. case CPU_DEAD:
  740. case CPU_DEAD_FROZEN:
  741. unregister_cpu_online(cpu);
  742. break;
  743. #endif
  744. }
  745. return NOTIFY_OK;
  746. }
  747. static struct notifier_block sysfs_cpu_nb = {
  748. .notifier_call = sysfs_cpu_notify,
  749. };
  750. static DEFINE_MUTEX(cpu_mutex);
  751. int cpu_add_dev_attr(struct device_attribute *attr)
  752. {
  753. int cpu;
  754. mutex_lock(&cpu_mutex);
  755. for_each_possible_cpu(cpu) {
  756. device_create_file(get_cpu_device(cpu), attr);
  757. }
  758. mutex_unlock(&cpu_mutex);
  759. return 0;
  760. }
  761. EXPORT_SYMBOL_GPL(cpu_add_dev_attr);
  762. int cpu_add_dev_attr_group(struct attribute_group *attrs)
  763. {
  764. int cpu;
  765. struct device *dev;
  766. int ret;
  767. mutex_lock(&cpu_mutex);
  768. for_each_possible_cpu(cpu) {
  769. dev = get_cpu_device(cpu);
  770. ret = sysfs_create_group(&dev->kobj, attrs);
  771. WARN_ON(ret != 0);
  772. }
  773. mutex_unlock(&cpu_mutex);
  774. return 0;
  775. }
  776. EXPORT_SYMBOL_GPL(cpu_add_dev_attr_group);
  777. void cpu_remove_dev_attr(struct device_attribute *attr)
  778. {
  779. int cpu;
  780. mutex_lock(&cpu_mutex);
  781. for_each_possible_cpu(cpu) {
  782. device_remove_file(get_cpu_device(cpu), attr);
  783. }
  784. mutex_unlock(&cpu_mutex);
  785. }
  786. EXPORT_SYMBOL_GPL(cpu_remove_dev_attr);
  787. void cpu_remove_dev_attr_group(struct attribute_group *attrs)
  788. {
  789. int cpu;
  790. struct device *dev;
  791. mutex_lock(&cpu_mutex);
  792. for_each_possible_cpu(cpu) {
  793. dev = get_cpu_device(cpu);
  794. sysfs_remove_group(&dev->kobj, attrs);
  795. }
  796. mutex_unlock(&cpu_mutex);
  797. }
  798. EXPORT_SYMBOL_GPL(cpu_remove_dev_attr_group);
  799. /* NUMA stuff */
  800. #ifdef CONFIG_NUMA
  801. static void register_nodes(void)
  802. {
  803. int i;
  804. for (i = 0; i < MAX_NUMNODES; i++)
  805. register_one_node(i);
  806. }
  807. int sysfs_add_device_to_node(struct device *dev, int nid)
  808. {
  809. struct node *node = node_devices[nid];
  810. return sysfs_create_link(&node->dev.kobj, &dev->kobj,
  811. kobject_name(&dev->kobj));
  812. }
  813. EXPORT_SYMBOL_GPL(sysfs_add_device_to_node);
  814. void sysfs_remove_device_from_node(struct device *dev, int nid)
  815. {
  816. struct node *node = node_devices[nid];
  817. sysfs_remove_link(&node->dev.kobj, kobject_name(&dev->kobj));
  818. }
  819. EXPORT_SYMBOL_GPL(sysfs_remove_device_from_node);
  820. #else
  821. static void register_nodes(void)
  822. {
  823. return;
  824. }
  825. #endif
  826. /* Only valid if CPU is present. */
  827. static ssize_t show_physical_id(struct device *dev,
  828. struct device_attribute *attr, char *buf)
  829. {
  830. struct cpu *cpu = container_of(dev, struct cpu, dev);
  831. return sprintf(buf, "%d\n", get_hard_smp_processor_id(cpu->dev.id));
  832. }
  833. static DEVICE_ATTR(physical_id, 0444, show_physical_id, NULL);
  834. static int __init topology_init(void)
  835. {
  836. int cpu;
  837. register_nodes();
  838. cpu_notifier_register_begin();
  839. for_each_possible_cpu(cpu) {
  840. struct cpu *c = &per_cpu(cpu_devices, cpu);
  841. /*
  842. * For now, we just see if the system supports making
  843. * the RTAS calls for CPU hotplug. But, there may be a
  844. * more comprehensive way to do this for an individual
  845. * CPU. For instance, the boot cpu might never be valid
  846. * for hotplugging.
  847. */
  848. if (ppc_md.cpu_die)
  849. c->hotpluggable = 1;
  850. if (cpu_online(cpu) || c->hotpluggable) {
  851. register_cpu(c, cpu);
  852. device_create_file(&c->dev, &dev_attr_physical_id);
  853. }
  854. if (cpu_online(cpu))
  855. register_cpu_online(cpu);
  856. }
  857. __register_cpu_notifier(&sysfs_cpu_nb);
  858. cpu_notifier_register_done();
  859. #ifdef CONFIG_PPC64
  860. sysfs_create_dscr_default();
  861. #endif /* CONFIG_PPC64 */
  862. return 0;
  863. }
  864. subsys_initcall(topology_init);