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>
14 #include <asm/sysinfo.h>
16 /* Sigh, math-emu. Don't ask. */
17 #include <asm/sfp-util.h>
18 #include <math-emu/soft-fp.h>
19 #include <math-emu/single.h>
21 static inline int stsi_0(void)
23 int rc
= stsi (NULL
, 0, 0, 0);
24 return rc
== -ENOSYS
? rc
: (((unsigned int) rc
) >> 28);
27 static int stsi_1_1_1(struct sysinfo_1_1_1
*info
, char *page
, int len
)
29 if (stsi(info
, 1, 1, 1) == -ENOSYS
)
32 EBCASC(info
->manufacturer
, sizeof(info
->manufacturer
));
33 EBCASC(info
->type
, sizeof(info
->type
));
34 EBCASC(info
->model
, sizeof(info
->model
));
35 EBCASC(info
->sequence
, sizeof(info
->sequence
));
36 EBCASC(info
->plant
, sizeof(info
->plant
));
37 EBCASC(info
->model_capacity
, sizeof(info
->model_capacity
));
38 EBCASC(info
->model_perm_cap
, sizeof(info
->model_perm_cap
));
39 EBCASC(info
->model_temp_cap
, sizeof(info
->model_temp_cap
));
40 len
+= sprintf(page
+ len
, "Manufacturer: %-16.16s\n",
42 len
+= sprintf(page
+ len
, "Type: %-4.4s\n",
44 if (info
->model
[0] != '\0')
46 * Sigh: the model field has been renamed with System z9
47 * to model_capacity and a new model field has been added
48 * after the plant field. To avoid confusing older programs
49 * the "Model:" prints "model_capacity model" or just
50 * "model_capacity" if the model string is empty .
52 len
+= sprintf(page
+ len
,
53 "Model: %-16.16s %-16.16s\n",
54 info
->model_capacity
, info
->model
);
56 len
+= sprintf(page
+ len
, "Model: %-16.16s\n",
57 info
->model_capacity
);
58 len
+= sprintf(page
+ len
, "Sequence Code: %-16.16s\n",
60 len
+= sprintf(page
+ len
, "Plant: %-4.4s\n",
62 len
+= sprintf(page
+ len
, "Model Capacity: %-16.16s %08u\n",
63 info
->model_capacity
, *(u32
*) info
->model_cap_rating
);
64 if (info
->model_perm_cap
[0] != '\0')
65 len
+= sprintf(page
+ len
,
66 "Model Perm. Capacity: %-16.16s %08u\n",
68 *(u32
*) info
->model_perm_cap_rating
);
69 if (info
->model_temp_cap
[0] != '\0')
70 len
+= sprintf(page
+ len
,
71 "Model Temp. Capacity: %-16.16s %08u\n",
73 *(u32
*) info
->model_temp_cap_rating
);
77 #if 0 /* Currently unused */
78 static int stsi_1_2_1(struct sysinfo_1_2_1
*info
, char *page
, int len
)
80 if (stsi(info
, 1, 2, 1) == -ENOSYS
)
83 len
+= sprintf(page
+ len
, "\n");
84 EBCASC(info
->sequence
, sizeof(info
->sequence
));
85 EBCASC(info
->plant
, sizeof(info
->plant
));
86 len
+= sprintf(page
+ len
, "Sequence Code of CPU: %-16.16s\n",
88 len
+= sprintf(page
+ len
, "Plant of CPU: %-16.16s\n",
94 static int stsi_1_2_2(struct sysinfo_1_2_2
*info
, char *page
, int len
)
96 struct sysinfo_1_2_2_extension
*ext
;
99 if (stsi(info
, 1, 2, 2) == -ENOSYS
)
101 ext
= (struct sysinfo_1_2_2_extension
*)
102 ((unsigned long) info
+ info
->acc_offset
);
104 len
+= sprintf(page
+ len
, "\n");
105 len
+= sprintf(page
+ len
, "CPUs Total: %d\n",
107 len
+= sprintf(page
+ len
, "CPUs Configured: %d\n",
108 info
->cpus_configured
);
109 len
+= sprintf(page
+ len
, "CPUs Standby: %d\n",
111 len
+= sprintf(page
+ len
, "CPUs Reserved: %d\n",
112 info
->cpus_reserved
);
114 if (info
->format
== 1) {
116 * Sigh 2. According to the specification the alternate
117 * capability field is a 32 bit floating point number
118 * if the higher order 8 bits are not zero. Printing
119 * a floating point number in the kernel is a no-no,
120 * always print the number as 32 bit unsigned integer.
121 * The user-space needs to know about the strange
122 * encoding of the alternate cpu capability.
124 len
+= sprintf(page
+ len
, "Capability: %u %u\n",
125 info
->capability
, ext
->alt_capability
);
126 for (i
= 2; i
<= info
->cpus_total
; i
++)
127 len
+= sprintf(page
+ len
,
128 "Adjustment %02d-way: %u %u\n",
129 i
, info
->adjustment
[i
-2],
130 ext
->alt_adjustment
[i
-2]);
133 len
+= sprintf(page
+ len
, "Capability: %u\n",
135 for (i
= 2; i
<= info
->cpus_total
; i
++)
136 len
+= sprintf(page
+ len
,
137 "Adjustment %02d-way: %u\n",
138 i
, info
->adjustment
[i
-2]);
141 if (info
->secondary_capability
!= 0)
142 len
+= sprintf(page
+ len
, "Secondary Capability: %d\n",
143 info
->secondary_capability
);
148 #if 0 /* Currently unused */
149 static int stsi_2_2_1(struct sysinfo_2_2_1
*info
, char *page
, int len
)
151 if (stsi(info
, 2, 2, 1) == -ENOSYS
)
154 len
+= sprintf(page
+ len
, "\n");
155 EBCASC (info
->sequence
, sizeof(info
->sequence
));
156 EBCASC (info
->plant
, sizeof(info
->plant
));
157 len
+= sprintf(page
+ len
, "Sequence Code of logical CPU: %-16.16s\n",
159 len
+= sprintf(page
+ len
, "Plant of logical CPU: %-16.16s\n",
165 static int stsi_2_2_2(struct sysinfo_2_2_2
*info
, char *page
, int len
)
167 if (stsi(info
, 2, 2, 2) == -ENOSYS
)
170 EBCASC (info
->name
, sizeof(info
->name
));
172 len
+= sprintf(page
+ len
, "\n");
173 len
+= sprintf(page
+ len
, "LPAR Number: %d\n",
176 len
+= sprintf(page
+ len
, "LPAR Characteristics: ");
177 if (info
->characteristics
& LPAR_CHAR_DEDICATED
)
178 len
+= sprintf(page
+ len
, "Dedicated ");
179 if (info
->characteristics
& LPAR_CHAR_SHARED
)
180 len
+= sprintf(page
+ len
, "Shared ");
181 if (info
->characteristics
& LPAR_CHAR_LIMITED
)
182 len
+= sprintf(page
+ len
, "Limited ");
183 len
+= sprintf(page
+ len
, "\n");
185 len
+= sprintf(page
+ len
, "LPAR Name: %-8.8s\n",
188 len
+= sprintf(page
+ len
, "LPAR Adjustment: %d\n",
191 len
+= sprintf(page
+ len
, "LPAR CPUs Total: %d\n",
193 len
+= sprintf(page
+ len
, "LPAR CPUs Configured: %d\n",
194 info
->cpus_configured
);
195 len
+= sprintf(page
+ len
, "LPAR CPUs Standby: %d\n",
197 len
+= sprintf(page
+ len
, "LPAR CPUs Reserved: %d\n",
198 info
->cpus_reserved
);
199 len
+= sprintf(page
+ len
, "LPAR CPUs Dedicated: %d\n",
200 info
->cpus_dedicated
);
201 len
+= sprintf(page
+ len
, "LPAR CPUs Shared: %d\n",
206 static int stsi_3_2_2(struct sysinfo_3_2_2
*info
, char *page
, int len
)
210 if (stsi(info
, 3, 2, 2) == -ENOSYS
)
212 for (i
= 0; i
< info
->count
; i
++) {
213 EBCASC (info
->vm
[i
].name
, sizeof(info
->vm
[i
].name
));
214 EBCASC (info
->vm
[i
].cpi
, sizeof(info
->vm
[i
].cpi
));
215 len
+= sprintf(page
+ len
, "\n");
216 len
+= sprintf(page
+ len
, "VM%02d Name: %-8.8s\n",
217 i
, info
->vm
[i
].name
);
218 len
+= sprintf(page
+ len
, "VM%02d Control Program: %-16.16s\n",
221 len
+= sprintf(page
+ len
, "VM%02d Adjustment: %d\n",
224 len
+= sprintf(page
+ len
, "VM%02d CPUs Total: %d\n",
225 i
, info
->vm
[i
].cpus_total
);
226 len
+= sprintf(page
+ len
, "VM%02d CPUs Configured: %d\n",
227 i
, info
->vm
[i
].cpus_configured
);
228 len
+= sprintf(page
+ len
, "VM%02d CPUs Standby: %d\n",
229 i
, info
->vm
[i
].cpus_standby
);
230 len
+= sprintf(page
+ len
, "VM%02d CPUs Reserved: %d\n",
231 i
, info
->vm
[i
].cpus_reserved
);
237 static int proc_read_sysinfo(char *page
, char **start
,
238 off_t off
, int count
,
239 int *eof
, void *data
)
241 unsigned long info
= get_zeroed_page (GFP_KERNEL
);
250 len
= stsi_1_1_1((struct sysinfo_1_1_1
*) info
, page
, len
);
253 len
= stsi_1_2_2((struct sysinfo_1_2_2
*) info
, page
, len
);
256 len
= stsi_2_2_2((struct sysinfo_2_2_2
*) info
, page
, len
);
259 len
= stsi_3_2_2((struct sysinfo_3_2_2
*) info
, page
, len
);
265 static __init
int create_proc_sysinfo(void)
267 create_proc_read_entry("sysinfo", 0444, NULL
,
268 proc_read_sysinfo
, NULL
);
272 __initcall(create_proc_sysinfo
);
274 int get_cpu_capability(unsigned int *capability
)
276 struct sysinfo_1_2_2
*info
;
279 info
= (void *) get_zeroed_page(GFP_KERNEL
);
282 rc
= stsi(info
, 1, 2, 2);
286 *capability
= info
->capability
;
288 free_page((unsigned long) info
);
293 * CPU capability might have changed. Therefore recalculate loops_per_jiffy.
295 void s390_adjust_jiffies(void)
297 struct sysinfo_1_2_2
*info
;
298 const unsigned int fmil
= 0x4b189680; /* 1e7 as 32-bit float. */
299 FP_DECL_S(SA
); FP_DECL_S(SB
); FP_DECL_S(SR
);
301 unsigned int capability
;
303 info
= (void *) get_zeroed_page(GFP_KERNEL
);
307 if (stsi(info
, 1, 2, 2) != -ENOSYS
) {
309 * Major sigh. The cpu capability encoding is "special".
310 * If the first 9 bits of info->capability are 0 then it
311 * is a 32 bit unsigned integer in the range 0 .. 2^23.
312 * If the first 9 bits are != 0 then it is a 32 bit float.
313 * In addition a lower value indicates a proportionally
314 * higher cpu capacity. Bogomips are the other way round.
315 * To get to a halfway suitable number we divide 1e7
316 * by the cpu capability number. Yes, that means a floating
317 * point division .. math-emu here we come :-)
319 FP_UNPACK_SP(SA
, &fmil
);
320 if ((info
->capability
>> 23) == 0)
321 FP_FROM_INT_S(SB
, info
->capability
, 32, int);
323 FP_UNPACK_SP(SB
, &info
->capability
);
324 FP_DIV_S(SR
, SA
, SB
);
325 FP_TO_INT_S(capability
, SR
, 32, 0);
328 * Really old machine without stsi block for basic
329 * cpu information. Report 42.0 bogomips.
332 loops_per_jiffy
= capability
* (500000/HZ
);
333 free_page((unsigned long) info
);
337 * calibrate the delay loop
339 void __cpuinit
calibrate_delay(void)
341 s390_adjust_jiffies();
342 /* Print the good old Bogomips line .. */
343 printk(KERN_DEBUG
"Calibrating delay loop (skipped)... "
344 "%lu.%02lu BogoMIPS preset\n", loops_per_jiffy
/(500000/HZ
),
345 (loops_per_jiffy
/(5000/HZ
)) % 100);