sysinfo.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. /*
  2. * Copyright IBM Corp. 2001, 2009
  3. * Author(s): Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
  4. * Martin Schwidefsky <schwidefsky@de.ibm.com>,
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/mm.h>
  8. #include <linux/proc_fs.h>
  9. #include <linux/seq_file.h>
  10. #include <linux/init.h>
  11. #include <linux/delay.h>
  12. #include <linux/module.h>
  13. #include <linux/slab.h>
  14. #include <asm/ebcdic.h>
  15. #include <asm/sysinfo.h>
  16. #include <asm/cpcmd.h>
  17. #include <asm/topology.h>
  18. /* Sigh, math-emu. Don't ask. */
  19. #include <asm/sfp-util.h>
  20. #include <math-emu/soft-fp.h>
  21. #include <math-emu/single.h>
  22. int topology_max_mnest;
  23. /*
  24. * stsi - store system information
  25. *
  26. * Returns the current configuration level if function code 0 was specified.
  27. * Otherwise returns 0 on success or a negative value on error.
  28. */
  29. int stsi(void *sysinfo, int fc, int sel1, int sel2)
  30. {
  31. register int r0 asm("0") = (fc << 28) | sel1;
  32. register int r1 asm("1") = sel2;
  33. int rc = 0;
  34. asm volatile(
  35. " stsi 0(%3)\n"
  36. "0: jz 2f\n"
  37. "1: lhi %1,%4\n"
  38. "2:\n"
  39. EX_TABLE(0b, 1b)
  40. : "+d" (r0), "+d" (rc)
  41. : "d" (r1), "a" (sysinfo), "K" (-EOPNOTSUPP)
  42. : "cc", "memory");
  43. if (rc)
  44. return rc;
  45. return fc ? 0 : ((unsigned int) r0) >> 28;
  46. }
  47. EXPORT_SYMBOL(stsi);
  48. static void stsi_1_1_1(struct seq_file *m, struct sysinfo_1_1_1 *info)
  49. {
  50. int i;
  51. if (stsi(info, 1, 1, 1))
  52. return;
  53. EBCASC(info->manufacturer, sizeof(info->manufacturer));
  54. EBCASC(info->type, sizeof(info->type));
  55. EBCASC(info->model, sizeof(info->model));
  56. EBCASC(info->sequence, sizeof(info->sequence));
  57. EBCASC(info->plant, sizeof(info->plant));
  58. EBCASC(info->model_capacity, sizeof(info->model_capacity));
  59. EBCASC(info->model_perm_cap, sizeof(info->model_perm_cap));
  60. EBCASC(info->model_temp_cap, sizeof(info->model_temp_cap));
  61. seq_printf(m, "Manufacturer: %-16.16s\n", info->manufacturer);
  62. seq_printf(m, "Type: %-4.4s\n", info->type);
  63. /*
  64. * Sigh: the model field has been renamed with System z9
  65. * to model_capacity and a new model field has been added
  66. * after the plant field. To avoid confusing older programs
  67. * the "Model:" prints "model_capacity model" or just
  68. * "model_capacity" if the model string is empty .
  69. */
  70. seq_printf(m, "Model: %-16.16s", info->model_capacity);
  71. if (info->model[0] != '\0')
  72. seq_printf(m, " %-16.16s", info->model);
  73. seq_putc(m, '\n');
  74. seq_printf(m, "Sequence Code: %-16.16s\n", info->sequence);
  75. seq_printf(m, "Plant: %-4.4s\n", info->plant);
  76. seq_printf(m, "Model Capacity: %-16.16s %08u\n",
  77. info->model_capacity, info->model_cap_rating);
  78. if (info->model_perm_cap_rating)
  79. seq_printf(m, "Model Perm. Capacity: %-16.16s %08u\n",
  80. info->model_perm_cap,
  81. info->model_perm_cap_rating);
  82. if (info->model_temp_cap_rating)
  83. seq_printf(m, "Model Temp. Capacity: %-16.16s %08u\n",
  84. info->model_temp_cap,
  85. info->model_temp_cap_rating);
  86. if (info->ncr)
  87. seq_printf(m, "Nominal Cap. Rating: %08u\n", info->ncr);
  88. if (info->npr)
  89. seq_printf(m, "Nominal Perm. Rating: %08u\n", info->npr);
  90. if (info->ntr)
  91. seq_printf(m, "Nominal Temp. Rating: %08u\n", info->ntr);
  92. if (info->cai) {
  93. seq_printf(m, "Capacity Adj. Ind.: %d\n", info->cai);
  94. seq_printf(m, "Capacity Ch. Reason: %d\n", info->ccr);
  95. seq_printf(m, "Capacity Transient: %d\n", info->t);
  96. }
  97. if (info->p) {
  98. for (i = 1; i <= ARRAY_SIZE(info->typepct); i++) {
  99. seq_printf(m, "Type %d Percentage: %d\n",
  100. i, info->typepct[i - 1]);
  101. }
  102. }
  103. }
  104. static void stsi_15_1_x(struct seq_file *m, struct sysinfo_15_1_x *info)
  105. {
  106. static int max_mnest;
  107. int i, rc;
  108. seq_putc(m, '\n');
  109. if (!MACHINE_HAS_TOPOLOGY)
  110. return;
  111. if (stsi(info, 15, 1, topology_max_mnest))
  112. return;
  113. seq_printf(m, "CPU Topology HW: ");
  114. for (i = 0; i < TOPOLOGY_NR_MAG; i++)
  115. seq_printf(m, " %d", info->mag[i]);
  116. seq_putc(m, '\n');
  117. #ifdef CONFIG_SCHED_MC
  118. store_topology(info);
  119. seq_printf(m, "CPU Topology SW: ");
  120. for (i = 0; i < TOPOLOGY_NR_MAG; i++)
  121. seq_printf(m, " %d", info->mag[i]);
  122. seq_putc(m, '\n');
  123. #endif
  124. }
  125. static void stsi_1_2_2(struct seq_file *m, struct sysinfo_1_2_2 *info)
  126. {
  127. struct sysinfo_1_2_2_extension *ext;
  128. int i;
  129. if (stsi(info, 1, 2, 2))
  130. return;
  131. ext = (struct sysinfo_1_2_2_extension *)
  132. ((unsigned long) info + info->acc_offset);
  133. seq_printf(m, "CPUs Total: %d\n", info->cpus_total);
  134. seq_printf(m, "CPUs Configured: %d\n", info->cpus_configured);
  135. seq_printf(m, "CPUs Standby: %d\n", info->cpus_standby);
  136. seq_printf(m, "CPUs Reserved: %d\n", info->cpus_reserved);
  137. /*
  138. * Sigh 2. According to the specification the alternate
  139. * capability field is a 32 bit floating point number
  140. * if the higher order 8 bits are not zero. Printing
  141. * a floating point number in the kernel is a no-no,
  142. * always print the number as 32 bit unsigned integer.
  143. * The user-space needs to know about the strange
  144. * encoding of the alternate cpu capability.
  145. */
  146. seq_printf(m, "Capability: %u", info->capability);
  147. if (info->format == 1)
  148. seq_printf(m, " %u", ext->alt_capability);
  149. seq_putc(m, '\n');
  150. if (info->nominal_cap)
  151. seq_printf(m, "Nominal Capability: %d\n", info->nominal_cap);
  152. if (info->secondary_cap)
  153. seq_printf(m, "Secondary Capability: %d\n", info->secondary_cap);
  154. for (i = 2; i <= info->cpus_total; i++) {
  155. seq_printf(m, "Adjustment %02d-way: %u",
  156. i, info->adjustment[i-2]);
  157. if (info->format == 1)
  158. seq_printf(m, " %u", ext->alt_adjustment[i-2]);
  159. seq_putc(m, '\n');
  160. }
  161. }
  162. static void stsi_2_2_2(struct seq_file *m, struct sysinfo_2_2_2 *info)
  163. {
  164. if (stsi(info, 2, 2, 2))
  165. return;
  166. EBCASC(info->name, sizeof(info->name));
  167. seq_putc(m, '\n');
  168. seq_printf(m, "LPAR Number: %d\n", info->lpar_number);
  169. seq_printf(m, "LPAR Characteristics: ");
  170. if (info->characteristics & LPAR_CHAR_DEDICATED)
  171. seq_printf(m, "Dedicated ");
  172. if (info->characteristics & LPAR_CHAR_SHARED)
  173. seq_printf(m, "Shared ");
  174. if (info->characteristics & LPAR_CHAR_LIMITED)
  175. seq_printf(m, "Limited ");
  176. seq_putc(m, '\n');
  177. seq_printf(m, "LPAR Name: %-8.8s\n", info->name);
  178. seq_printf(m, "LPAR Adjustment: %d\n", info->caf);
  179. seq_printf(m, "LPAR CPUs Total: %d\n", info->cpus_total);
  180. seq_printf(m, "LPAR CPUs Configured: %d\n", info->cpus_configured);
  181. seq_printf(m, "LPAR CPUs Standby: %d\n", info->cpus_standby);
  182. seq_printf(m, "LPAR CPUs Reserved: %d\n", info->cpus_reserved);
  183. seq_printf(m, "LPAR CPUs Dedicated: %d\n", info->cpus_dedicated);
  184. seq_printf(m, "LPAR CPUs Shared: %d\n", info->cpus_shared);
  185. if (info->mt_installed & 0x80) {
  186. seq_printf(m, "LPAR CPUs G-MTID: %d\n",
  187. info->mt_general & 0x1f);
  188. seq_printf(m, "LPAR CPUs S-MTID: %d\n",
  189. info->mt_installed & 0x1f);
  190. seq_printf(m, "LPAR CPUs PS-MTID: %d\n",
  191. info->mt_psmtid & 0x1f);
  192. }
  193. }
  194. static void print_ext_name(struct seq_file *m, int lvl,
  195. struct sysinfo_3_2_2 *info)
  196. {
  197. if (info->vm[lvl].ext_name_encoding == 0)
  198. return;
  199. if (info->ext_names[lvl][0] == 0)
  200. return;
  201. switch (info->vm[lvl].ext_name_encoding) {
  202. case 1: /* EBCDIC */
  203. EBCASC(info->ext_names[lvl], sizeof(info->ext_names[lvl]));
  204. break;
  205. case 2: /* UTF-8 */
  206. break;
  207. default:
  208. return;
  209. }
  210. seq_printf(m, "VM%02d Extended Name: %-.256s\n", lvl,
  211. info->ext_names[lvl]);
  212. }
  213. static void print_uuid(struct seq_file *m, int i, struct sysinfo_3_2_2 *info)
  214. {
  215. if (!memcmp(&info->vm[i].uuid, &NULL_UUID_BE, sizeof(uuid_be)))
  216. return;
  217. seq_printf(m, "VM%02d UUID: %pUb\n", i, &info->vm[i].uuid);
  218. }
  219. static void stsi_3_2_2(struct seq_file *m, struct sysinfo_3_2_2 *info)
  220. {
  221. int i;
  222. if (stsi(info, 3, 2, 2))
  223. return;
  224. for (i = 0; i < info->count; i++) {
  225. EBCASC(info->vm[i].name, sizeof(info->vm[i].name));
  226. EBCASC(info->vm[i].cpi, sizeof(info->vm[i].cpi));
  227. seq_putc(m, '\n');
  228. seq_printf(m, "VM%02d Name: %-8.8s\n", i, info->vm[i].name);
  229. seq_printf(m, "VM%02d Control Program: %-16.16s\n", i, info->vm[i].cpi);
  230. seq_printf(m, "VM%02d Adjustment: %d\n", i, info->vm[i].caf);
  231. seq_printf(m, "VM%02d CPUs Total: %d\n", i, info->vm[i].cpus_total);
  232. seq_printf(m, "VM%02d CPUs Configured: %d\n", i, info->vm[i].cpus_configured);
  233. seq_printf(m, "VM%02d CPUs Standby: %d\n", i, info->vm[i].cpus_standby);
  234. seq_printf(m, "VM%02d CPUs Reserved: %d\n", i, info->vm[i].cpus_reserved);
  235. print_ext_name(m, i, info);
  236. print_uuid(m, i, info);
  237. }
  238. }
  239. static int sysinfo_show(struct seq_file *m, void *v)
  240. {
  241. void *info = (void *)get_zeroed_page(GFP_KERNEL);
  242. int level;
  243. if (!info)
  244. return 0;
  245. level = stsi(NULL, 0, 0, 0);
  246. if (level >= 1)
  247. stsi_1_1_1(m, info);
  248. if (level >= 1)
  249. stsi_15_1_x(m, info);
  250. if (level >= 1)
  251. stsi_1_2_2(m, info);
  252. if (level >= 2)
  253. stsi_2_2_2(m, info);
  254. if (level >= 3)
  255. stsi_3_2_2(m, info);
  256. free_page((unsigned long)info);
  257. return 0;
  258. }
  259. static int sysinfo_open(struct inode *inode, struct file *file)
  260. {
  261. return single_open(file, sysinfo_show, NULL);
  262. }
  263. static const struct file_operations sysinfo_fops = {
  264. .open = sysinfo_open,
  265. .read = seq_read,
  266. .llseek = seq_lseek,
  267. .release = single_release,
  268. };
  269. static int __init sysinfo_create_proc(void)
  270. {
  271. proc_create("sysinfo", 0444, NULL, &sysinfo_fops);
  272. return 0;
  273. }
  274. device_initcall(sysinfo_create_proc);
  275. /*
  276. * Service levels interface.
  277. */
  278. static DECLARE_RWSEM(service_level_sem);
  279. static LIST_HEAD(service_level_list);
  280. int register_service_level(struct service_level *slr)
  281. {
  282. struct service_level *ptr;
  283. down_write(&service_level_sem);
  284. list_for_each_entry(ptr, &service_level_list, list)
  285. if (ptr == slr) {
  286. up_write(&service_level_sem);
  287. return -EEXIST;
  288. }
  289. list_add_tail(&slr->list, &service_level_list);
  290. up_write(&service_level_sem);
  291. return 0;
  292. }
  293. EXPORT_SYMBOL(register_service_level);
  294. int unregister_service_level(struct service_level *slr)
  295. {
  296. struct service_level *ptr, *next;
  297. int rc = -ENOENT;
  298. down_write(&service_level_sem);
  299. list_for_each_entry_safe(ptr, next, &service_level_list, list) {
  300. if (ptr != slr)
  301. continue;
  302. list_del(&ptr->list);
  303. rc = 0;
  304. break;
  305. }
  306. up_write(&service_level_sem);
  307. return rc;
  308. }
  309. EXPORT_SYMBOL(unregister_service_level);
  310. static void *service_level_start(struct seq_file *m, loff_t *pos)
  311. {
  312. down_read(&service_level_sem);
  313. return seq_list_start(&service_level_list, *pos);
  314. }
  315. static void *service_level_next(struct seq_file *m, void *p, loff_t *pos)
  316. {
  317. return seq_list_next(p, &service_level_list, pos);
  318. }
  319. static void service_level_stop(struct seq_file *m, void *p)
  320. {
  321. up_read(&service_level_sem);
  322. }
  323. static int service_level_show(struct seq_file *m, void *p)
  324. {
  325. struct service_level *slr;
  326. slr = list_entry(p, struct service_level, list);
  327. slr->seq_print(m, slr);
  328. return 0;
  329. }
  330. static const struct seq_operations service_level_seq_ops = {
  331. .start = service_level_start,
  332. .next = service_level_next,
  333. .stop = service_level_stop,
  334. .show = service_level_show
  335. };
  336. static int service_level_open(struct inode *inode, struct file *file)
  337. {
  338. return seq_open(file, &service_level_seq_ops);
  339. }
  340. static const struct file_operations service_level_ops = {
  341. .open = service_level_open,
  342. .read = seq_read,
  343. .llseek = seq_lseek,
  344. .release = seq_release
  345. };
  346. static void service_level_vm_print(struct seq_file *m,
  347. struct service_level *slr)
  348. {
  349. char *query_buffer, *str;
  350. query_buffer = kmalloc(1024, GFP_KERNEL | GFP_DMA);
  351. if (!query_buffer)
  352. return;
  353. cpcmd("QUERY CPLEVEL", query_buffer, 1024, NULL);
  354. str = strchr(query_buffer, '\n');
  355. if (str)
  356. *str = 0;
  357. seq_printf(m, "VM: %s\n", query_buffer);
  358. kfree(query_buffer);
  359. }
  360. static struct service_level service_level_vm = {
  361. .seq_print = service_level_vm_print
  362. };
  363. static __init int create_proc_service_level(void)
  364. {
  365. proc_create("service_levels", 0, NULL, &service_level_ops);
  366. if (MACHINE_IS_VM)
  367. register_service_level(&service_level_vm);
  368. return 0;
  369. }
  370. subsys_initcall(create_proc_service_level);
  371. /*
  372. * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
  373. */
  374. void s390_adjust_jiffies(void)
  375. {
  376. struct sysinfo_1_2_2 *info;
  377. const unsigned int fmil = 0x4b189680; /* 1e7 as 32-bit float. */
  378. FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR);
  379. FP_DECL_EX;
  380. unsigned int capability;
  381. info = (void *) get_zeroed_page(GFP_KERNEL);
  382. if (!info)
  383. return;
  384. if (stsi(info, 1, 2, 2) == 0) {
  385. /*
  386. * Major sigh. The cpu capability encoding is "special".
  387. * If the first 9 bits of info->capability are 0 then it
  388. * is a 32 bit unsigned integer in the range 0 .. 2^23.
  389. * If the first 9 bits are != 0 then it is a 32 bit float.
  390. * In addition a lower value indicates a proportionally
  391. * higher cpu capacity. Bogomips are the other way round.
  392. * To get to a halfway suitable number we divide 1e7
  393. * by the cpu capability number. Yes, that means a floating
  394. * point division .. math-emu here we come :-)
  395. */
  396. FP_UNPACK_SP(SA, &fmil);
  397. if ((info->capability >> 23) == 0)
  398. FP_FROM_INT_S(SB, (long) info->capability, 64, long);
  399. else
  400. FP_UNPACK_SP(SB, &info->capability);
  401. FP_DIV_S(SR, SA, SB);
  402. FP_TO_INT_S(capability, SR, 32, 0);
  403. } else
  404. /*
  405. * Really old machine without stsi block for basic
  406. * cpu information. Report 42.0 bogomips.
  407. */
  408. capability = 42;
  409. loops_per_jiffy = capability * (500000/HZ);
  410. free_page((unsigned long) info);
  411. }
  412. /*
  413. * calibrate the delay loop
  414. */
  415. void calibrate_delay(void)
  416. {
  417. s390_adjust_jiffies();
  418. /* Print the good old Bogomips line .. */
  419. printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
  420. "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
  421. (loops_per_jiffy/(5000/HZ)) % 100);
  422. }