1 | /* |
---|
2 | * Machtype: determine machine type & display type |
---|
3 | * |
---|
4 | * RCS Info |
---|
5 | * $Id: machtype_sgi.c,v 1.5 1996-08-20 19:26:07 cfields Exp $ |
---|
6 | * $Locker: $ |
---|
7 | */ |
---|
8 | |
---|
9 | #include <stdio.h> |
---|
10 | #include <string.h> |
---|
11 | #include <strings.h> |
---|
12 | #if defined(_AIX) && defined(_BSD) |
---|
13 | #undef _BSD |
---|
14 | #endif |
---|
15 | #include <nlist.h> |
---|
16 | #include <sys/param.h> |
---|
17 | #include <sys/types.h> |
---|
18 | #include <sys/file.h> |
---|
19 | |
---|
20 | #include <sys/sysinfo.h> |
---|
21 | #include <sys/ioctl.h> |
---|
22 | |
---|
23 | #include <ctype.h> |
---|
24 | #ifdef sgi |
---|
25 | #include <sys/cpu.h> |
---|
26 | #include <invent.h> |
---|
27 | void do_INV_SCSI(inventory_t *); |
---|
28 | void do_INV_DISK(inventory_t *); |
---|
29 | void do_INV_PROCESSOR(inventory_t *,int); |
---|
30 | void do_INV_GRAPHICS(inventory_t *); |
---|
31 | void do_INV_CAM(inventory_t *); |
---|
32 | #endif |
---|
33 | |
---|
34 | |
---|
35 | |
---|
36 | #define NL_NF(nl) ((nl).n_type == 0) |
---|
37 | |
---|
38 | #define KERNEL "/unix" |
---|
39 | #define MEMORY "/dev/kmem" |
---|
40 | |
---|
41 | int verbose = 0; |
---|
42 | |
---|
43 | struct nlist nl[] = { |
---|
44 | #define X_cpu 0 |
---|
45 | { "cputype" }, |
---|
46 | #define X_maxmem 1 |
---|
47 | { "maxmem" }, |
---|
48 | #define X_physmem 2 |
---|
49 | { "physmem" }, |
---|
50 | #define X_nscsi 3 |
---|
51 | { "_nscsi_devices" }, |
---|
52 | { "" }, |
---|
53 | }; |
---|
54 | |
---|
55 | main(argc, argv) |
---|
56 | int argc; |
---|
57 | char **argv; |
---|
58 | { |
---|
59 | int i; |
---|
60 | int cpuflg = 0, dpyflg = 0, raflg = 0, memflg = 0; |
---|
61 | int doathenaV = 0; |
---|
62 | int dosyspV = 0; |
---|
63 | int dolocalV = 0; |
---|
64 | int dobosN = 0; |
---|
65 | int dobosV = 0; |
---|
66 | int dosysnam = 0; |
---|
67 | char *kernel = KERNEL, *memory = MEMORY; |
---|
68 | FILE *f; |
---|
69 | int memfd=0; |
---|
70 | |
---|
71 | for (i = 1; i < argc; i++) { |
---|
72 | if (argv[i][0] != '-') |
---|
73 | usage(argv[0]); |
---|
74 | |
---|
75 | switch (argv[i][1]) { |
---|
76 | case 'c': |
---|
77 | cpuflg++; |
---|
78 | break; |
---|
79 | case 'd': |
---|
80 | dpyflg++; |
---|
81 | break; |
---|
82 | case 'r': |
---|
83 | raflg++; |
---|
84 | break; |
---|
85 | case 'M': |
---|
86 | memflg++; |
---|
87 | break; |
---|
88 | case 'k': |
---|
89 | kernel = argv[i+1]; |
---|
90 | i++; |
---|
91 | break; |
---|
92 | case 'm': |
---|
93 | memory = argv[i+1]; |
---|
94 | i++; |
---|
95 | break; |
---|
96 | case 'A': |
---|
97 | doathenaV = 1; |
---|
98 | break; |
---|
99 | case 'L': |
---|
100 | dolocalV = 1; |
---|
101 | break; |
---|
102 | case 'P': |
---|
103 | dosyspV = 1; |
---|
104 | break; |
---|
105 | case 'N': |
---|
106 | dobosN = 1; |
---|
107 | break; |
---|
108 | case 'E': |
---|
109 | dobosV = 1; |
---|
110 | break; |
---|
111 | case 'S': |
---|
112 | dosysnam = 1; |
---|
113 | break; |
---|
114 | case 'v': |
---|
115 | verbose++; |
---|
116 | break; |
---|
117 | default: |
---|
118 | usage(argv[0]); |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | if ((argc == 1) || ((argc == 2) && verbose)) { |
---|
124 | #if defined(vax) |
---|
125 | puts("vax"); |
---|
126 | #else |
---|
127 | #if defined(ibm032) |
---|
128 | puts("rt"); |
---|
129 | #else |
---|
130 | #if defined(ultrix) && defined(mips) |
---|
131 | puts("decmips"); |
---|
132 | #else |
---|
133 | #if defined(i386) && defined(_AIX) |
---|
134 | puts("ps2"); |
---|
135 | #else /* ! ps2 */ |
---|
136 | #if defined(sgi) |
---|
137 | puts("sgi"); |
---|
138 | #else |
---|
139 | #if defined(sun) && defined(sparc) |
---|
140 | puts("sun4"); |
---|
141 | #else /* ! sun sparc */ |
---|
142 | #if defined(sun) |
---|
143 | puts("sun3"); |
---|
144 | #else |
---|
145 | puts("???"); |
---|
146 | #endif |
---|
147 | #endif |
---|
148 | #endif |
---|
149 | #endif |
---|
150 | #endif |
---|
151 | #endif |
---|
152 | #endif |
---|
153 | exit(0); |
---|
154 | } |
---|
155 | |
---|
156 | /* Print out version of Athena machtype compiled against */ |
---|
157 | if (doathenaV) { |
---|
158 | if (verbose) |
---|
159 | printf("Machtype version: %s.%s\n",ATHMAJV,ATHMINV); |
---|
160 | else |
---|
161 | printf("%s.%s\n",ATHMAJV,ATHMINV); |
---|
162 | } |
---|
163 | |
---|
164 | /* Print out version of attached packs */ |
---|
165 | if (dosyspV) { |
---|
166 | char buf[256],rvd_version[256], *p; |
---|
167 | if ((f = fopen("/srvd/.rvdinfo","r")) == NULL) { |
---|
168 | printf("Syspack information unavailable\n"); |
---|
169 | } else { |
---|
170 | fgets(buf,256,f); |
---|
171 | fclose(f); |
---|
172 | |
---|
173 | /* If it is verbose, give the whole line, else just the vers # */ |
---|
174 | if (verbose) { |
---|
175 | printf(buf); |
---|
176 | } else { |
---|
177 | p = index(buf,' '); /* skip "Athena" */ |
---|
178 | p = index(p+1,' '); /* skip "RVD" */ |
---|
179 | p = index(p+1,' '); /* Skip "RSAIX" */ |
---|
180 | p = index(p+1,' '); /* skip "version" */ |
---|
181 | strncpy(rvd_version,p+1,256); |
---|
182 | p = index(rvd_version,' '); |
---|
183 | *p = '\0'; |
---|
184 | printf("%s\n",rvd_version); |
---|
185 | } |
---|
186 | } |
---|
187 | } |
---|
188 | |
---|
189 | /* Print out local version from /etc/athena/version */ |
---|
190 | if (dolocalV) { |
---|
191 | char buf[256],loc_version[256], *p; |
---|
192 | if ((f = fopen("/etc/athena/version","r")) == NULL) { |
---|
193 | printf("Local version information unavailable\n"); |
---|
194 | } else { |
---|
195 | fseek(f,-100,2); |
---|
196 | while (fgets(buf,256,f) != NULL) |
---|
197 | ; |
---|
198 | fclose(f); |
---|
199 | |
---|
200 | if (verbose) { |
---|
201 | printf(buf); |
---|
202 | } else { |
---|
203 | p = index(buf,' '); /* skip "Athena" */ |
---|
204 | p = index(p+1,' '); /* skip "Workstation/Server" */ |
---|
205 | p = index(p+1,' '); /* Skip "RSAIX" */ |
---|
206 | p = index(p+1,' '); /* skip "version" */ |
---|
207 | strncpy(loc_version,p+1,256); |
---|
208 | p = index(loc_version,' '); |
---|
209 | *p = '\0'; |
---|
210 | printf("%s\n",loc_version); |
---|
211 | } |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | /* Print out vendor OS name */ |
---|
216 | if (dobosN) { |
---|
217 | if (verbose) { |
---|
218 | printf(OSNAME " " OSVERS "\n"); |
---|
219 | } else { |
---|
220 | printf(OSNAME "\n"); |
---|
221 | } |
---|
222 | } |
---|
223 | |
---|
224 | /* Print out vendor OS version */ |
---|
225 | if (dobosV) { |
---|
226 | printf(OSVERS "\n"); |
---|
227 | } |
---|
228 | if (dosysnam) |
---|
229 | printf("%s\n", ATHSYS); |
---|
230 | if (cpuflg) |
---|
231 | do_cpu(kernel, memfd); |
---|
232 | if (dpyflg) |
---|
233 | do_dpy(kernel, memfd); |
---|
234 | if (raflg) |
---|
235 | do_disk(kernel, memfd); |
---|
236 | |
---|
237 | if (memflg) |
---|
238 | { |
---|
239 | |
---|
240 | if (nlist(kernel, nl) < 0) { |
---|
241 | fprintf(stderr,"%s: can't get namelist\n", argv[0]); |
---|
242 | exit(2); |
---|
243 | } |
---|
244 | if ((memfd = open (memory, O_RDONLY)) == -1) { |
---|
245 | perror ("machtype: can't open memory"); |
---|
246 | exit(2); |
---|
247 | } |
---|
248 | if (memflg) |
---|
249 | do_memory(kernel, memfd); |
---|
250 | } |
---|
251 | exit(0); |
---|
252 | } |
---|
253 | |
---|
254 | |
---|
255 | |
---|
256 | usage(name) |
---|
257 | char *name; |
---|
258 | { |
---|
259 | fprintf(stderr, "usage: %s [-v] [-c] [-d] [-r] [-E] [-N] [-M]\n",name); |
---|
260 | fprintf(stderr, " [-k kernel] [-m memory] [-A] [-L] [-P] [-S]\n"); |
---|
261 | exit(1); |
---|
262 | } |
---|
263 | |
---|
264 | |
---|
265 | do_cpu(kernel, mf) |
---|
266 | char *kernel; |
---|
267 | int mf; |
---|
268 | { |
---|
269 | inventory_t *inv; |
---|
270 | int done=0; |
---|
271 | (void)setinvent(); |
---|
272 | inv = getinvent(); |
---|
273 | while ((inv != NULL) && !done) { |
---|
274 | if ( inv->inv_class == 1) { |
---|
275 | do_INV_PROCESSOR(inv,verbose); |
---|
276 | } |
---|
277 | inv = getinvent(); |
---|
278 | } |
---|
279 | } |
---|
280 | |
---|
281 | void do_INV_PROCESSOR(inventory_t *i,int verbose) |
---|
282 | { |
---|
283 | if (i->inv_type == INV_CPUBOARD ) { |
---|
284 | switch (i->inv_state) { |
---|
285 | case INV_R2300BOARD: |
---|
286 | puts(verbose ? "SGI R2300": "R2300"); |
---|
287 | break; |
---|
288 | case INV_IP4BOARD: |
---|
289 | puts(verbose ? "SGI IP4": "IP4"); |
---|
290 | break; |
---|
291 | case INV_IP5BOARD: |
---|
292 | puts(verbose ? "SGI IP5": "IP5"); |
---|
293 | break; |
---|
294 | case INV_IP6BOARD: |
---|
295 | puts(verbose ? "SGI IP6": "IP6"); |
---|
296 | break; |
---|
297 | case INV_IP7BOARD: |
---|
298 | puts(verbose ? "SGI IP7": "IP7"); |
---|
299 | break; |
---|
300 | case INV_IP9BOARD: |
---|
301 | puts(verbose ? "SGI IP9": "IP9"); |
---|
302 | break; |
---|
303 | case INV_IP12BOARD: |
---|
304 | puts(verbose ? "SGI IP12": "IP12"); |
---|
305 | break; |
---|
306 | case INV_IP15BOARD: |
---|
307 | puts(verbose ? "SGI IP15": "IP15"); |
---|
308 | break; |
---|
309 | case INV_IP17BOARD: |
---|
310 | puts(verbose ? "SGI IP17": "IP17"); |
---|
311 | break; |
---|
312 | case INV_IP19BOARD: |
---|
313 | puts(verbose ? "SGI IP19": "IP19"); |
---|
314 | break; |
---|
315 | case INV_IP20BOARD: |
---|
316 | puts(verbose ? "SGI IP20": "IP20"); |
---|
317 | break; |
---|
318 | case INV_IP21BOARD: |
---|
319 | puts(verbose ? "SGI IP21": "IP21"); |
---|
320 | break; |
---|
321 | case INV_IP22BOARD: |
---|
322 | puts(verbose ? "SGI IP22": "IP22"); |
---|
323 | break; |
---|
324 | case INV_IP26BOARD: |
---|
325 | puts(verbose ? "SGI IP26": "IP26"); |
---|
326 | break; |
---|
327 | default: |
---|
328 | if(verbose) |
---|
329 | printf("Unknown SGI type %d\n", i->inv_state); |
---|
330 | else |
---|
331 | puts("SGI???"); |
---|
332 | } |
---|
333 | } else if (verbose) { |
---|
334 | if (i->inv_type == INV_CPUCHIP) { |
---|
335 | fprintf(stdout,"CPU: MIPS R4600\n"); |
---|
336 | } else { |
---|
337 | fprintf(stdout,"FPU:MIPS R4610\n"); |
---|
338 | } |
---|
339 | } |
---|
340 | } |
---|
341 | |
---|
342 | |
---|
343 | #ifdef vax |
---|
344 | int ka420model() |
---|
345 | { |
---|
346 | unsigned long cacr; |
---|
347 | int kUmf; |
---|
348 | if (nl[X_nexus].n_type == 0) |
---|
349 | return -1; |
---|
350 | kUmf = open("/dev/kUmem", O_RDONLY); |
---|
351 | if (kUmf == -1) |
---|
352 | return -1; |
---|
353 | lseek(kUmf, nl[X_nexus].n_value + (int)&((struct nb_regs *)0)->nb_cacr, L_SET); |
---|
354 | if(read(kUmf, &cacr, sizeof(cacr)) != sizeof(cacr)) |
---|
355 | return -1; |
---|
356 | close (kUmf); |
---|
357 | return (cacr >> 6) & 3; |
---|
358 | } |
---|
359 | #endif /* vax */ |
---|
360 | |
---|
361 | do_dpy(kernel, mf) |
---|
362 | char *kernel; |
---|
363 | int mf; |
---|
364 | { |
---|
365 | int status; |
---|
366 | inventory_t *inv; |
---|
367 | int done=0; |
---|
368 | #ifdef sgi |
---|
369 | if (verbose) { |
---|
370 | switch(fork()) { |
---|
371 | case -1: |
---|
372 | fprintf (stderr, |
---|
373 | "Don't know how to determine display type for this machine.\n"); |
---|
374 | return; |
---|
375 | case 0: |
---|
376 | if ((execlp("/usr/gfx/gfxinfo","gfxinfo",NULL) ) == -1 ) { |
---|
377 | fprintf (stderr, |
---|
378 | "Don't know how to determine display type for this machine.\n"); |
---|
379 | return; |
---|
380 | } |
---|
381 | default: |
---|
382 | wait(&status); |
---|
383 | break; |
---|
384 | } /* switch */ |
---|
385 | (void) setinvent(); |
---|
386 | inv = getinvent(); |
---|
387 | while ((inv != NULL) && !done) { |
---|
388 | if ( inv->inv_class == INV_VIDEO) { |
---|
389 | do_INV_CAM(inv); |
---|
390 | } |
---|
391 | inv = getinvent(); |
---|
392 | } |
---|
393 | } else { /* not verbose */ |
---|
394 | (void) setinvent(); |
---|
395 | inv = getinvent(); |
---|
396 | while ((inv != NULL) && !done) { |
---|
397 | if ( inv->inv_class == INV_GRAPHICS) { |
---|
398 | do_INV_GRAPHICS(inv); |
---|
399 | } |
---|
400 | inv = getinvent(); |
---|
401 | } |
---|
402 | } /* verbose */ |
---|
403 | |
---|
404 | #else |
---|
405 | fprintf (stderr, |
---|
406 | "Don't know how to determine display type for this machine.\n"); |
---|
407 | return; |
---|
408 | #endif |
---|
409 | } |
---|
410 | |
---|
411 | void do_INV_GRAPHICS(inventory_t *i) |
---|
412 | { |
---|
413 | if (i->inv_type == INV_NEWPORT ) { |
---|
414 | if (i->inv_state == INV_NEWPORT_24 ) { |
---|
415 | fprintf(stdout,"XL-24\n"); |
---|
416 | } else if (i->inv_state == INV_NEWPORT_XL ) { |
---|
417 | fprintf(stdout,"XL\n"); |
---|
418 | } else { |
---|
419 | fprintf(stdout,"NG1\n"); |
---|
420 | } |
---|
421 | } else if (i->inv_type == INV_GR2 ) { |
---|
422 | if ((i->inv_state & ~INV_GR2_INDY) == INV_GR2_ELAN ) { |
---|
423 | /* an EXPRESS is an EXPRESS of course of course |
---|
424 | except when you are a GR3-XZ */ |
---|
425 | fprintf(stdout,"GR3-XZ\n"); |
---|
426 | } else |
---|
427 | fprintf(stdout,"UNKNOWN video\n"); |
---|
428 | } else { |
---|
429 | fprintf(stdout,"UNKNOWN video\n"); |
---|
430 | } |
---|
431 | } |
---|
432 | |
---|
433 | void do_INV_CAM(inventory_t *i) |
---|
434 | { |
---|
435 | if (i->inv_type == INV_VIDEO_VINO ) { |
---|
436 | if (i->inv_state == INV_VINO_INDY_CAM ) { |
---|
437 | fprintf(stdout,"\tIndy cam connected\n"); |
---|
438 | } |
---|
439 | } |
---|
440 | } |
---|
441 | |
---|
442 | |
---|
443 | |
---|
444 | do_disk(kernel, mf) |
---|
445 | char *kernel; |
---|
446 | int mf; |
---|
447 | { |
---|
448 | inventory_t *inv; |
---|
449 | int t; |
---|
450 | int done=0; |
---|
451 | (void) setinvent(); |
---|
452 | inv = getinvent(); |
---|
453 | t = 0; |
---|
454 | while ((inv != NULL) && !done) { |
---|
455 | if ((inv->inv_class == 2) || (inv->inv_class ==9) ) { |
---|
456 | if ( inv->inv_class == 9) { |
---|
457 | do_INV_SCSI(inv); |
---|
458 | } else { |
---|
459 | do_INV_DISK(inv); |
---|
460 | } |
---|
461 | } |
---|
462 | inv = getinvent(); |
---|
463 | } |
---|
464 | } |
---|
465 | void do_INV_SCSI(inventory_t *i) |
---|
466 | { |
---|
467 | if (i->inv_type == INV_CDROM) { |
---|
468 | fprintf(stdout,"CDROM : unit %i, on SCSI controller %i\n",i->inv_unit,i->inv_controller); |
---|
469 | } else { |
---|
470 | fprintf(stdout,"Unknown type %i:unit %i, on SCSI controller %i\n",i->inv_type,i->inv_unit,i->inv_controller); |
---|
471 | } |
---|
472 | } |
---|
473 | |
---|
474 | void do_INV_DISK(inventory_t *i) |
---|
475 | { |
---|
476 | if (i->inv_type == INV_SCSIDRIVE) { |
---|
477 | fprintf(stdout,"Disk drive: unit %i, on SCSI controller %i\n",i->inv_unit,i->inv_controller); |
---|
478 | } else if (i->inv_type == INV_SCSIFLOPPY) { |
---|
479 | fprintf(stdout,"Floppy drive: unit %i, on SCSI controller %i\n",i->inv_unit,i->inv_controller); |
---|
480 | } else if (i->inv_type == INV_SCSICONTROL) { |
---|
481 | if (i->inv_type == INV_WD93) { |
---|
482 | fprintf(stdout,"SCSI controller %i: Version %s, rev. %c\n",i->inv_controller,"WD 33C93",i->inv_state); |
---|
483 | } else if (i->inv_type == INV_WD93A) { |
---|
484 | fprintf(stdout,"SCSI controller %i: Version %s, rev. %d\n",i->inv_controller,"WD 33C93A",i->inv_state); |
---|
485 | } else if (i->inv_type == INV_WD93B) { |
---|
486 | fprintf(stdout,"SCSI controller %i: Version %s, rev. %d\n",i->inv_controller,"WD 33C93B",i->inv_state); |
---|
487 | } else if (i->inv_type == INV_WD95A) { |
---|
488 | fprintf(stdout,"SCSI controller %i: Version %s, rev. %d\n",i->inv_controller,"WD 33C95A",i->inv_state); |
---|
489 | } else if (i->inv_type == INV_SCIP95) { |
---|
490 | fprintf(stdout,"SCSI controller %i: Version %s, rev. %d\n",i->inv_controller,"SCIP w/WD 33C95A",i->inv_state); |
---|
491 | } else { |
---|
492 | fprintf(stdout,"SCSI controller %i: Version %s, rev. %d\n",i->inv_controller,"Unkown",i->inv_state); |
---|
493 | } |
---|
494 | } else { |
---|
495 | fprintf(stdout,"Unknown type %i:unit %i, on SCSI controller %i\n",i->inv_type,i->inv_unit,i->inv_controller); |
---|
496 | } |
---|
497 | |
---|
498 | } |
---|
499 | |
---|
500 | |
---|
501 | |
---|
502 | #define MEG (1024*1024) |
---|
503 | |
---|
504 | do_memory (kernel, mf) |
---|
505 | char *kernel; |
---|
506 | int mf; |
---|
507 | { |
---|
508 | int pos, mem; |
---|
509 | pos = nl[X_maxmem].n_value; |
---|
510 | if(pos == 0) { |
---|
511 | fprintf(stderr, "can't find maxmem\n"); |
---|
512 | exit(3); |
---|
513 | } |
---|
514 | lseek(mf,pos,L_SET); /* Error checking ? */ |
---|
515 | if(read(mf,&mem,4) == -1) { |
---|
516 | perror("read (kmem)"); |
---|
517 | exit(4); |
---|
518 | } else { |
---|
519 | if(verbose) |
---|
520 | printf("%#06x user, ",mem * getpagesize()); |
---|
521 | } |
---|
522 | pos = nl[X_physmem].n_value; |
---|
523 | if(pos == 0) { |
---|
524 | fprintf(stderr, "can't find physmem\n"); |
---|
525 | exit(3); |
---|
526 | } |
---|
527 | lseek(mf,pos,L_SET); |
---|
528 | if(read(mf,&mem,4) == -1) { |
---|
529 | perror("read (kmem)"); |
---|
530 | exit(4); |
---|
531 | } else { |
---|
532 | if(verbose) |
---|
533 | printf("%#06x (%d M) total\n",mem * getpagesize(),(mem * getpagesize() + MEG/2)/MEG); |
---|
534 | else |
---|
535 | printf("%d\n", mem * getpagesize()); |
---|
536 | } |
---|
537 | return; |
---|
538 | } |
---|
539 | |
---|