sysinfo.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. /*
  2. * drivers/s390/sysinfo.c
  3. *
  4. * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
  5. * Author(s): Ulrich Weigand (Ulrich.Weigand@de.ibm.com)
  6. */
  7. #include <linux/kernel.h>
  8. #include <linux/mm.h>
  9. #include <linux/proc_fs.h>
  10. #include <linux/init.h>
  11. #include <linux/delay.h>
  12. #include <asm/ebcdic.h>
  13. /* Sigh, math-emu. Don't ask. */
  14. #include <asm/sfp-util.h>
  15. #include <math-emu/soft-fp.h>
  16. #include <math-emu/single.h>
  17. struct sysinfo_1_1_1 {
  18. char reserved_0[32];
  19. char manufacturer[16];
  20. char type[4];
  21. char reserved_1[12];
  22. char model_capacity[16];
  23. char sequence[16];
  24. char plant[4];
  25. char model[16];
  26. };
  27. struct sysinfo_1_2_1 {
  28. char reserved_0[80];
  29. char sequence[16];
  30. char plant[4];
  31. char reserved_1[2];
  32. unsigned short cpu_address;
  33. };
  34. struct sysinfo_1_2_2 {
  35. char format;
  36. char reserved_0[1];
  37. unsigned short acc_offset;
  38. char reserved_1[24];
  39. unsigned int secondary_capability;
  40. unsigned int capability;
  41. unsigned short cpus_total;
  42. unsigned short cpus_configured;
  43. unsigned short cpus_standby;
  44. unsigned short cpus_reserved;
  45. unsigned short adjustment[0];
  46. };
  47. struct sysinfo_1_2_2_extension {
  48. unsigned int alt_capability;
  49. unsigned short alt_adjustment[0];
  50. };
  51. struct sysinfo_2_2_1 {
  52. char reserved_0[80];
  53. char sequence[16];
  54. char plant[4];
  55. unsigned short cpu_id;
  56. unsigned short cpu_address;
  57. };
  58. struct sysinfo_2_2_2 {
  59. char reserved_0[32];
  60. unsigned short lpar_number;
  61. char reserved_1;
  62. unsigned char characteristics;
  63. unsigned short cpus_total;
  64. unsigned short cpus_configured;
  65. unsigned short cpus_standby;
  66. unsigned short cpus_reserved;
  67. char name[8];
  68. unsigned int caf;
  69. char reserved_2[16];
  70. unsigned short cpus_dedicated;
  71. unsigned short cpus_shared;
  72. };
  73. #define LPAR_CHAR_DEDICATED (1 << 7)
  74. #define LPAR_CHAR_SHARED (1 << 6)
  75. #define LPAR_CHAR_LIMITED (1 << 5)
  76. struct sysinfo_3_2_2 {
  77. char reserved_0[31];
  78. unsigned char count;
  79. struct {
  80. char reserved_0[4];
  81. unsigned short cpus_total;
  82. unsigned short cpus_configured;
  83. unsigned short cpus_standby;
  84. unsigned short cpus_reserved;
  85. char name[8];
  86. unsigned int caf;
  87. char cpi[16];
  88. char reserved_1[24];
  89. } vm[8];
  90. };
  91. static inline int stsi(void *sysinfo, int fc, int sel1, int sel2)
  92. {
  93. register int r0 asm("0") = (fc << 28) | sel1;
  94. register int r1 asm("1") = sel2;
  95. asm volatile(
  96. " stsi 0(%2)\n"
  97. "0: jz 2f\n"
  98. "1: lhi %0,%3\n"
  99. "2:\n"
  100. EX_TABLE(0b,1b)
  101. : "+d" (r0) : "d" (r1), "a" (sysinfo), "K" (-ENOSYS)
  102. : "cc", "memory" );
  103. return r0;
  104. }
  105. static inline int stsi_0(void)
  106. {
  107. int rc = stsi (NULL, 0, 0, 0);
  108. return rc == -ENOSYS ? rc : (((unsigned int) rc) >> 28);
  109. }
  110. static int stsi_1_1_1(struct sysinfo_1_1_1 *info, char *page, int len)
  111. {
  112. if (stsi(info, 1, 1, 1) == -ENOSYS)
  113. return len;
  114. EBCASC(info->manufacturer, sizeof(info->manufacturer));
  115. EBCASC(info->type, sizeof(info->type));
  116. EBCASC(info->model, sizeof(info->model));
  117. EBCASC(info->sequence, sizeof(info->sequence));
  118. EBCASC(info->plant, sizeof(info->plant));
  119. EBCASC(info->model_capacity, sizeof(info->model_capacity));
  120. len += sprintf(page + len, "Manufacturer: %-16.16s\n",
  121. info->manufacturer);
  122. len += sprintf(page + len, "Type: %-4.4s\n",
  123. info->type);
  124. if (info->model[0] != '\0')
  125. /*
  126. * Sigh: the model field has been renamed with System z9
  127. * to model_capacity and a new model field has been added
  128. * after the plant field. To avoid confusing older programs
  129. * the "Model:" prints "model_capacity model" or just
  130. * "model_capacity" if the model string is empty .
  131. */
  132. len += sprintf(page + len,
  133. "Model: %-16.16s %-16.16s\n",
  134. info->model_capacity, info->model);
  135. else
  136. len += sprintf(page + len, "Model: %-16.16s\n",
  137. info->model_capacity);
  138. len += sprintf(page + len, "Sequence Code: %-16.16s\n",
  139. info->sequence);
  140. len += sprintf(page + len, "Plant: %-4.4s\n",
  141. info->plant);
  142. len += sprintf(page + len, "Model Capacity: %-16.16s\n",
  143. info->model_capacity);
  144. return len;
  145. }
  146. #if 0 /* Currently unused */
  147. static int stsi_1_2_1(struct sysinfo_1_2_1 *info, char *page, int len)
  148. {
  149. if (stsi(info, 1, 2, 1) == -ENOSYS)
  150. return len;
  151. len += sprintf(page + len, "\n");
  152. EBCASC(info->sequence, sizeof(info->sequence));
  153. EBCASC(info->plant, sizeof(info->plant));
  154. len += sprintf(page + len, "Sequence Code of CPU: %-16.16s\n",
  155. info->sequence);
  156. len += sprintf(page + len, "Plant of CPU: %-16.16s\n",
  157. info->plant);
  158. return len;
  159. }
  160. #endif
  161. static int stsi_1_2_2(struct sysinfo_1_2_2 *info, char *page, int len)
  162. {
  163. struct sysinfo_1_2_2_extension *ext;
  164. int i;
  165. if (stsi(info, 1, 2, 2) == -ENOSYS)
  166. return len;
  167. ext = (struct sysinfo_1_2_2_extension *)
  168. ((unsigned long) info + info->acc_offset);
  169. len += sprintf(page + len, "\n");
  170. len += sprintf(page + len, "CPUs Total: %d\n",
  171. info->cpus_total);
  172. len += sprintf(page + len, "CPUs Configured: %d\n",
  173. info->cpus_configured);
  174. len += sprintf(page + len, "CPUs Standby: %d\n",
  175. info->cpus_standby);
  176. len += sprintf(page + len, "CPUs Reserved: %d\n",
  177. info->cpus_reserved);
  178. if (info->format == 1) {
  179. /*
  180. * Sigh 2. According to the specification the alternate
  181. * capability field is a 32 bit floating point number
  182. * if the higher order 8 bits are not zero. Printing
  183. * a floating point number in the kernel is a no-no,
  184. * always print the number as 32 bit unsigned integer.
  185. * The user-space needs to know about the strange
  186. * encoding of the alternate cpu capability.
  187. */
  188. len += sprintf(page + len, "Capability: %u %u\n",
  189. info->capability, ext->alt_capability);
  190. for (i = 2; i <= info->cpus_total; i++)
  191. len += sprintf(page + len,
  192. "Adjustment %02d-way: %u %u\n",
  193. i, info->adjustment[i-2],
  194. ext->alt_adjustment[i-2]);
  195. } else {
  196. len += sprintf(page + len, "Capability: %u\n",
  197. info->capability);
  198. for (i = 2; i <= info->cpus_total; i++)
  199. len += sprintf(page + len,
  200. "Adjustment %02d-way: %u\n",
  201. i, info->adjustment[i-2]);
  202. }
  203. if (info->secondary_capability != 0)
  204. len += sprintf(page + len, "Secondary Capability: %d\n",
  205. info->secondary_capability);
  206. return len;
  207. }
  208. #if 0 /* Currently unused */
  209. static int stsi_2_2_1(struct sysinfo_2_2_1 *info, char *page, int len)
  210. {
  211. if (stsi(info, 2, 2, 1) == -ENOSYS)
  212. return len;
  213. len += sprintf(page + len, "\n");
  214. EBCASC (info->sequence, sizeof(info->sequence));
  215. EBCASC (info->plant, sizeof(info->plant));
  216. len += sprintf(page + len, "Sequence Code of logical CPU: %-16.16s\n",
  217. info->sequence);
  218. len += sprintf(page + len, "Plant of logical CPU: %-16.16s\n",
  219. info->plant);
  220. return len;
  221. }
  222. #endif
  223. static int stsi_2_2_2(struct sysinfo_2_2_2 *info, char *page, int len)
  224. {
  225. if (stsi(info, 2, 2, 2) == -ENOSYS)
  226. return len;
  227. EBCASC (info->name, sizeof(info->name));
  228. len += sprintf(page + len, "\n");
  229. len += sprintf(page + len, "LPAR Number: %d\n",
  230. info->lpar_number);
  231. len += sprintf(page + len, "LPAR Characteristics: ");
  232. if (info->characteristics & LPAR_CHAR_DEDICATED)
  233. len += sprintf(page + len, "Dedicated ");
  234. if (info->characteristics & LPAR_CHAR_SHARED)
  235. len += sprintf(page + len, "Shared ");
  236. if (info->characteristics & LPAR_CHAR_LIMITED)
  237. len += sprintf(page + len, "Limited ");
  238. len += sprintf(page + len, "\n");
  239. len += sprintf(page + len, "LPAR Name: %-8.8s\n",
  240. info->name);
  241. len += sprintf(page + len, "LPAR Adjustment: %d\n",
  242. info->caf);
  243. len += sprintf(page + len, "LPAR CPUs Total: %d\n",
  244. info->cpus_total);
  245. len += sprintf(page + len, "LPAR CPUs Configured: %d\n",
  246. info->cpus_configured);
  247. len += sprintf(page + len, "LPAR CPUs Standby: %d\n",
  248. info->cpus_standby);
  249. len += sprintf(page + len, "LPAR CPUs Reserved: %d\n",
  250. info->cpus_reserved);
  251. len += sprintf(page + len, "LPAR CPUs Dedicated: %d\n",
  252. info->cpus_dedicated);
  253. len += sprintf(page + len, "LPAR CPUs Shared: %d\n",
  254. info->cpus_shared);
  255. return len;
  256. }
  257. static int stsi_3_2_2(struct sysinfo_3_2_2 *info, char *page, int len)
  258. {
  259. int i;
  260. if (stsi(info, 3, 2, 2) == -ENOSYS)
  261. return len;
  262. for (i = 0; i < info->count; i++) {
  263. EBCASC (info->vm[i].name, sizeof(info->vm[i].name));
  264. EBCASC (info->vm[i].cpi, sizeof(info->vm[i].cpi));
  265. len += sprintf(page + len, "\n");
  266. len += sprintf(page + len, "VM%02d Name: %-8.8s\n",
  267. i, info->vm[i].name);
  268. len += sprintf(page + len, "VM%02d Control Program: %-16.16s\n",
  269. i, info->vm[i].cpi);
  270. len += sprintf(page + len, "VM%02d Adjustment: %d\n",
  271. i, info->vm[i].caf);
  272. len += sprintf(page + len, "VM%02d CPUs Total: %d\n",
  273. i, info->vm[i].cpus_total);
  274. len += sprintf(page + len, "VM%02d CPUs Configured: %d\n",
  275. i, info->vm[i].cpus_configured);
  276. len += sprintf(page + len, "VM%02d CPUs Standby: %d\n",
  277. i, info->vm[i].cpus_standby);
  278. len += sprintf(page + len, "VM%02d CPUs Reserved: %d\n",
  279. i, info->vm[i].cpus_reserved);
  280. }
  281. return len;
  282. }
  283. static int proc_read_sysinfo(char *page, char **start,
  284. off_t off, int count,
  285. int *eof, void *data)
  286. {
  287. unsigned long info = get_zeroed_page (GFP_KERNEL);
  288. int level, len;
  289. if (!info)
  290. return 0;
  291. len = 0;
  292. level = stsi_0();
  293. if (level >= 1)
  294. len = stsi_1_1_1((struct sysinfo_1_1_1 *) info, page, len);
  295. if (level >= 1)
  296. len = stsi_1_2_2((struct sysinfo_1_2_2 *) info, page, len);
  297. if (level >= 2)
  298. len = stsi_2_2_2((struct sysinfo_2_2_2 *) info, page, len);
  299. if (level >= 3)
  300. len = stsi_3_2_2((struct sysinfo_3_2_2 *) info, page, len);
  301. free_page (info);
  302. return len;
  303. }
  304. static __init int create_proc_sysinfo(void)
  305. {
  306. create_proc_read_entry("sysinfo", 0444, NULL,
  307. proc_read_sysinfo, NULL);
  308. return 0;
  309. }
  310. __initcall(create_proc_sysinfo);
  311. int get_cpu_capability(unsigned int *capability)
  312. {
  313. struct sysinfo_1_2_2 *info;
  314. int rc;
  315. info = (void *) get_zeroed_page(GFP_KERNEL);
  316. if (!info)
  317. return -ENOMEM;
  318. rc = stsi(info, 1, 2, 2);
  319. if (rc == -ENOSYS)
  320. goto out;
  321. rc = 0;
  322. *capability = info->capability;
  323. out:
  324. free_page((unsigned long) info);
  325. return rc;
  326. }
  327. /*
  328. * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
  329. */
  330. void s390_adjust_jiffies(void)
  331. {
  332. struct sysinfo_1_2_2 *info;
  333. const unsigned int fmil = 0x4b189680; /* 1e7 as 32-bit float. */
  334. FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR);
  335. FP_DECL_EX;
  336. unsigned int capability;
  337. info = (void *) get_zeroed_page(GFP_KERNEL);
  338. if (!info)
  339. return;
  340. if (stsi(info, 1, 2, 2) != -ENOSYS) {
  341. /*
  342. * Major sigh. The cpu capability encoding is "special".
  343. * If the first 9 bits of info->capability are 0 then it
  344. * is a 32 bit unsigned integer in the range 0 .. 2^23.
  345. * If the first 9 bits are != 0 then it is a 32 bit float.
  346. * In addition a lower value indicates a proportionally
  347. * higher cpu capacity. Bogomips are the other way round.
  348. * To get to a halfway suitable number we divide 1e7
  349. * by the cpu capability number. Yes, that means a floating
  350. * point division .. math-emu here we come :-)
  351. */
  352. FP_UNPACK_SP(SA, &fmil);
  353. if ((info->capability >> 23) == 0)
  354. FP_FROM_INT_S(SB, info->capability, 32, int);
  355. else
  356. FP_UNPACK_SP(SB, &info->capability);
  357. FP_DIV_S(SR, SA, SB);
  358. FP_TO_INT_S(capability, SR, 32, 0);
  359. } else
  360. /*
  361. * Really old machine without stsi block for basic
  362. * cpu information. Report 42.0 bogomips.
  363. */
  364. capability = 42;
  365. loops_per_jiffy = capability * (500000/HZ);
  366. free_page((unsigned long) info);
  367. }
  368. /*
  369. * calibrate the delay loop
  370. */
  371. void __init calibrate_delay(void)
  372. {
  373. s390_adjust_jiffies();
  374. /* Print the good old Bogomips line .. */
  375. printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
  376. "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
  377. (loops_per_jiffy/(5000/HZ)) % 100);
  378. }