2 * drivers/s390/sysinfo.c
4 * Copyright (C) 2001 IBM Deutschland Entwicklung GmbH, IBM Corporation
5 * Author(s): Ulrich Weigand (Ulrich.Weigand@de.ibm.com)
8 #include <linux/kernel.h>
10 #include <linux/proc_fs.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
13 #include <asm/ebcdic.h>
15 /* Sigh, math-emu. Don't ask. */
16 #include <asm/sfp-util.h>
17 #include <math-emu/soft-fp.h>
18 #include <math-emu/single.h>
20 struct sysinfo_1_1_1 {
22 char manufacturer[16];
25 char model_capacity[16];
31 struct sysinfo_1_2_1 {
36 unsigned short cpu_address;
39 struct sysinfo_1_2_2 {
42 unsigned short acc_offset;
44 unsigned int secondary_capability;
45 unsigned int capability;
46 unsigned short cpus_total;
47 unsigned short cpus_configured;
48 unsigned short cpus_standby;
49 unsigned short cpus_reserved;
50 unsigned short adjustment[0];
53 struct sysinfo_1_2_2_extension {
54 unsigned int alt_capability;
55 unsigned short alt_adjustment[0];
58 struct sysinfo_2_2_1 {
62 unsigned short cpu_id;
63 unsigned short cpu_address;
66 struct sysinfo_2_2_2 {
68 unsigned short lpar_number;
70 unsigned char characteristics;
71 unsigned short cpus_total;
72 unsigned short cpus_configured;
73 unsigned short cpus_standby;
74 unsigned short cpus_reserved;
78 unsigned short cpus_dedicated;
79 unsigned short cpus_shared;
82 #define LPAR_CHAR_DEDICATED (1 << 7)
83 #define LPAR_CHAR_SHARED (1 << 6)
84 #define LPAR_CHAR_LIMITED (1 << 5)
86 struct sysinfo_3_2_2 {
91 unsigned short cpus_total;
92 unsigned short cpus_configured;
93 unsigned short cpus_standby;
94 unsigned short cpus_reserved;
103 static inline int stsi(void *sysinfo, int fc, int sel1, int sel2)
105 register int r0 asm("0") = (fc << 28) | sel1;
106 register int r1 asm("1") = sel2;
114 : "+d" (r0) : "d" (r1), "a" (sysinfo), "K" (-ENOSYS)
119 static inline int stsi_0(void)
121 int rc = stsi (NULL, 0, 0, 0);
122 return rc == -ENOSYS ? rc : (((unsigned int) rc) >> 28);
125 static int stsi_1_1_1(struct sysinfo_1_1_1 *info, char *page, int len)
127 if (stsi(info, 1, 1, 1) == -ENOSYS)
130 EBCASC(info->manufacturer, sizeof(info->manufacturer));
131 EBCASC(info->type, sizeof(info->type));
132 EBCASC(info->model, sizeof(info->model));
133 EBCASC(info->sequence, sizeof(info->sequence));
134 EBCASC(info->plant, sizeof(info->plant));
135 EBCASC(info->model_capacity, sizeof(info->model_capacity));
136 len += sprintf(page + len, "Manufacturer: %-16.16s\n",
138 len += sprintf(page + len, "Type: %-4.4s\n",
140 if (info->model[0] != '\0')
142 * Sigh: the model field has been renamed with System z9
143 * to model_capacity and a new model field has been added
144 * after the plant field. To avoid confusing older programs
145 * the "Model:" prints "model_capacity model" or just
146 * "model_capacity" if the model string is empty .
148 len += sprintf(page + len,
149 "Model: %-16.16s %-16.16s\n",
150 info->model_capacity, info->model);
152 len += sprintf(page + len, "Model: %-16.16s\n",
153 info->model_capacity);
154 len += sprintf(page + len, "Sequence Code: %-16.16s\n",
156 len += sprintf(page + len, "Plant: %-4.4s\n",
158 len += sprintf(page + len, "Model Capacity: %-16.16s\n",
159 info->model_capacity);
163 #if 0 /* Currently unused */
164 static int stsi_1_2_1(struct sysinfo_1_2_1 *info, char *page, int len)
166 if (stsi(info, 1, 2, 1) == -ENOSYS)
169 len += sprintf(page + len, "\n");
170 EBCASC(info->sequence, sizeof(info->sequence));
171 EBCASC(info->plant, sizeof(info->plant));
172 len += sprintf(page + len, "Sequence Code of CPU: %-16.16s\n",
174 len += sprintf(page + len, "Plant of CPU: %-16.16s\n",
180 static int stsi_1_2_2(struct sysinfo_1_2_2 *info, char *page, int len)
182 struct sysinfo_1_2_2_extension *ext;
185 if (stsi(info, 1, 2, 2) == -ENOSYS)
187 ext = (struct sysinfo_1_2_2_extension *)
188 ((unsigned long) info + info->acc_offset);
190 len += sprintf(page + len, "\n");
191 len += sprintf(page + len, "CPUs Total: %d\n",
193 len += sprintf(page + len, "CPUs Configured: %d\n",
194 info->cpus_configured);
195 len += sprintf(page + len, "CPUs Standby: %d\n",
197 len += sprintf(page + len, "CPUs Reserved: %d\n",
198 info->cpus_reserved);
200 if (info->format == 1) {
202 * Sigh 2. According to the specification the alternate
203 * capability field is a 32 bit floating point number
204 * if the higher order 8 bits are not zero. Printing
205 * a floating point number in the kernel is a no-no,
206 * always print the number as 32 bit unsigned integer.
207 * The user-space needs to know about the strange
208 * encoding of the alternate cpu capability.
210 len += sprintf(page + len, "Capability: %u %u\n",
211 info->capability, ext->alt_capability);
212 for (i = 2; i <= info->cpus_total; i++)
213 len += sprintf(page + len,
214 "Adjustment %02d-way: %u %u\n",
215 i, info->adjustment[i-2],
216 ext->alt_adjustment[i-2]);
219 len += sprintf(page + len, "Capability: %u\n",
221 for (i = 2; i <= info->cpus_total; i++)
222 len += sprintf(page + len,
223 "Adjustment %02d-way: %u\n",
224 i, info->adjustment[i-2]);
227 if (info->secondary_capability != 0)
228 len += sprintf(page + len, "Secondary Capability: %d\n",
229 info->secondary_capability);
234 #if 0 /* Currently unused */
235 static int stsi_2_2_1(struct sysinfo_2_2_1 *info, char *page, int len)
237 if (stsi(info, 2, 2, 1) == -ENOSYS)
240 len += sprintf(page + len, "\n");
241 EBCASC (info->sequence, sizeof(info->sequence));
242 EBCASC (info->plant, sizeof(info->plant));
243 len += sprintf(page + len, "Sequence Code of logical CPU: %-16.16s\n",
245 len += sprintf(page + len, "Plant of logical CPU: %-16.16s\n",
251 static int stsi_2_2_2(struct sysinfo_2_2_2 *info, char *page, int len)
253 if (stsi(info, 2, 2, 2) == -ENOSYS)
256 EBCASC (info->name, sizeof(info->name));
258 len += sprintf(page + len, "\n");
259 len += sprintf(page + len, "LPAR Number: %d\n",
262 len += sprintf(page + len, "LPAR Characteristics: ");
263 if (info->characteristics & LPAR_CHAR_DEDICATED)
264 len += sprintf(page + len, "Dedicated ");
265 if (info->characteristics & LPAR_CHAR_SHARED)
266 len += sprintf(page + len, "Shared ");
267 if (info->characteristics & LPAR_CHAR_LIMITED)
268 len += sprintf(page + len, "Limited ");
269 len += sprintf(page + len, "\n");
271 len += sprintf(page + len, "LPAR Name: %-8.8s\n",
274 len += sprintf(page + len, "LPAR Adjustment: %d\n",
277 len += sprintf(page + len, "LPAR CPUs Total: %d\n",
279 len += sprintf(page + len, "LPAR CPUs Configured: %d\n",
280 info->cpus_configured);
281 len += sprintf(page + len, "LPAR CPUs Standby: %d\n",
283 len += sprintf(page + len, "LPAR CPUs Reserved: %d\n",
284 info->cpus_reserved);
285 len += sprintf(page + len, "LPAR CPUs Dedicated: %d\n",
286 info->cpus_dedicated);
287 len += sprintf(page + len, "LPAR CPUs Shared: %d\n",
292 static int stsi_3_2_2(struct sysinfo_3_2_2 *info, char *page, int len)
296 if (stsi(info, 3, 2, 2) == -ENOSYS)
298 for (i = 0; i < info->count; i++) {
299 EBCASC (info->vm[i].name, sizeof(info->vm[i].name));
300 EBCASC (info->vm[i].cpi, sizeof(info->vm[i].cpi));
301 len += sprintf(page + len, "\n");
302 len += sprintf(page + len, "VM%02d Name: %-8.8s\n",
303 i, info->vm[i].name);
304 len += sprintf(page + len, "VM%02d Control Program: %-16.16s\n",
307 len += sprintf(page + len, "VM%02d Adjustment: %d\n",
310 len += sprintf(page + len, "VM%02d CPUs Total: %d\n",
311 i, info->vm[i].cpus_total);
312 len += sprintf(page + len, "VM%02d CPUs Configured: %d\n",
313 i, info->vm[i].cpus_configured);
314 len += sprintf(page + len, "VM%02d CPUs Standby: %d\n",
315 i, info->vm[i].cpus_standby);
316 len += sprintf(page + len, "VM%02d CPUs Reserved: %d\n",
317 i, info->vm[i].cpus_reserved);
323 static int proc_read_sysinfo(char *page, char **start,
324 off_t off, int count,
325 int *eof, void *data)
327 unsigned long info = get_zeroed_page (GFP_KERNEL);
336 len = stsi_1_1_1((struct sysinfo_1_1_1 *) info, page, len);
339 len = stsi_1_2_2((struct sysinfo_1_2_2 *) info, page, len);
342 len = stsi_2_2_2((struct sysinfo_2_2_2 *) info, page, len);
345 len = stsi_3_2_2((struct sysinfo_3_2_2 *) info, page, len);
351 static __init int create_proc_sysinfo(void)
353 create_proc_read_entry("sysinfo", 0444, NULL,
354 proc_read_sysinfo, NULL);
358 __initcall(create_proc_sysinfo);
360 int get_cpu_capability(unsigned int *capability)
362 struct sysinfo_1_2_2 *info;
365 info = (void *) get_zeroed_page(GFP_KERNEL);
368 rc = stsi(info, 1, 2, 2);
372 *capability = info->capability;
374 free_page((unsigned long) info);
379 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
381 void s390_adjust_jiffies(void)
383 struct sysinfo_1_2_2 *info;
384 const unsigned int fmil = 0x4b189680; /* 1e7 as 32-bit float. */
385 FP_DECL_S(SA); FP_DECL_S(SB); FP_DECL_S(SR);
387 unsigned int capability;
389 info = (void *) get_zeroed_page(GFP_KERNEL);
393 if (stsi(info, 1, 2, 2) != -ENOSYS) {
395 * Major sigh. The cpu capability encoding is "special".
396 * If the first 9 bits of info->capability are 0 then it
397 * is a 32 bit unsigned integer in the range 0 .. 2^23.
398 * If the first 9 bits are != 0 then it is a 32 bit float.
399 * In addition a lower value indicates a proportionally
400 * higher cpu capacity. Bogomips are the other way round.
401 * To get to a halfway suitable number we divide 1e7
402 * by the cpu capability number. Yes, that means a floating
403 * point division .. math-emu here we come :-)
405 FP_UNPACK_SP(SA, &fmil);
406 if ((info->capability >> 23) == 0)
407 FP_FROM_INT_S(SB, info->capability, 32, int);
409 FP_UNPACK_SP(SB, &info->capability);
410 FP_DIV_S(SR, SA, SB);
411 FP_TO_INT_S(capability, SR, 32, 0);
414 * Really old machine without stsi block for basic
415 * cpu information. Report 42.0 bogomips.
418 loops_per_jiffy = capability * (500000/HZ);
419 free_page((unsigned long) info);
423 * calibrate the delay loop
425 void __init calibrate_delay(void)
427 s390_adjust_jiffies();
428 /* Print the good old Bogomips line .. */
429 printk(KERN_DEBUG "Calibrating delay loop (skipped)... "
430 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy/(500000/HZ),
431 (loops_per_jiffy/(5000/HZ)) % 100);