1 | /* |
---|
2 | * Machtype: determine machine type & display type |
---|
3 | * |
---|
4 | * RCS Info |
---|
5 | * $Id: machtype_sgi.c,v 1.14 1999-01-22 23:11:36 ghudson Exp $ |
---|
6 | */ |
---|
7 | |
---|
8 | #include <stdio.h> |
---|
9 | #include <string.h> |
---|
10 | #include <strings.h> |
---|
11 | #include <nlist.h> |
---|
12 | #include <sys/param.h> |
---|
13 | #include <sys/types.h> |
---|
14 | #include <sys/file.h> |
---|
15 | #include <sys/sysinfo.h> |
---|
16 | #include <sys/ioctl.h> |
---|
17 | #include "machtype.h" |
---|
18 | |
---|
19 | #ifdef sgi |
---|
20 | #include <sys/cpu.h> |
---|
21 | #include <invent.h> |
---|
22 | void do_INV_SCSI(inventory_t *, int); |
---|
23 | void do_INV_SCSICONTROL(inventory_t *, int); |
---|
24 | void do_INV_DISK(inventory_t *, int); |
---|
25 | void do_INV_PROCESSOR(inventory_t *,int); |
---|
26 | void do_INV_GRAPHICS(inventory_t *, int); |
---|
27 | void do_INV_CAM(inventory_t *, int); |
---|
28 | #endif |
---|
29 | |
---|
30 | |
---|
31 | |
---|
32 | #define NL_NF(nl) ((nl).n_type == 0) |
---|
33 | |
---|
34 | #define KERNEL "/unix" |
---|
35 | #define MEMORY "/dev/kmem" |
---|
36 | |
---|
37 | struct nlist nl[] = { |
---|
38 | #define X_cpu 0 |
---|
39 | { "cputype" }, |
---|
40 | #define X_maxmem 1 |
---|
41 | { "maxmem" }, |
---|
42 | #define X_physmem 2 |
---|
43 | { "physmem" }, |
---|
44 | #define X_nscsi 3 |
---|
45 | { "_nscsi_devices" }, |
---|
46 | { "" }, |
---|
47 | }; |
---|
48 | |
---|
49 | |
---|
50 | void do_machtype(void) |
---|
51 | { |
---|
52 | puts("sgi"); |
---|
53 | } |
---|
54 | |
---|
55 | void do_cpu(int verbose) |
---|
56 | { |
---|
57 | inventory_t *inv; |
---|
58 | int done=0; |
---|
59 | (void)setinvent(); |
---|
60 | inv = getinvent(); |
---|
61 | while ((inv != NULL) && !done) { |
---|
62 | if ( inv->inv_class == 1) { |
---|
63 | do_INV_PROCESSOR(inv,verbose); |
---|
64 | } |
---|
65 | inv = getinvent(); |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | void do_INV_PROCESSOR(inventory_t *i,int verbose) |
---|
70 | { |
---|
71 | if (i->inv_type == INV_CPUBOARD ) { |
---|
72 | switch (i->inv_state) { |
---|
73 | case INV_IP19BOARD: |
---|
74 | puts(verbose ? "SGI IP19": "IP19"); |
---|
75 | break; |
---|
76 | case INV_IP20BOARD: |
---|
77 | puts(verbose ? "SGI IP20": "IP20"); |
---|
78 | break; |
---|
79 | case INV_IP21BOARD: |
---|
80 | puts(verbose ? "SGI IP21": "IP21"); |
---|
81 | break; |
---|
82 | case INV_IP22BOARD: |
---|
83 | puts(verbose ? "SGI IP22": "IP22"); |
---|
84 | break; |
---|
85 | case INV_IP25BOARD: |
---|
86 | puts(verbose ? "SGI IP25": "IP25"); |
---|
87 | break; |
---|
88 | case INV_IP26BOARD: |
---|
89 | puts(verbose ? "SGI IP26": "IP26"); |
---|
90 | break; |
---|
91 | case INV_IP27BOARD: |
---|
92 | puts(verbose ? "SGI IP27": "IP27"); |
---|
93 | break; |
---|
94 | case INV_IP28BOARD: |
---|
95 | puts(verbose ? "SGI IP28": "IP28"); |
---|
96 | break; |
---|
97 | case INV_IP30BOARD: |
---|
98 | puts(verbose ? "SGI IP30": "IP30"); |
---|
99 | break; |
---|
100 | case INV_IP32BOARD: |
---|
101 | puts(verbose ? "SGI IP32": "IP32"); |
---|
102 | break; |
---|
103 | case INV_IP33BOARD: |
---|
104 | puts(verbose ? "SGI IP33": "IP33"); |
---|
105 | break; |
---|
106 | case INV_IPMHSIMBOARD: |
---|
107 | puts(verbose ? "SGI IPMHSIM": "IPMHSIM"); |
---|
108 | break; |
---|
109 | default: |
---|
110 | if(verbose) |
---|
111 | printf("Unknown SGI type %d\n", i->inv_state); |
---|
112 | else |
---|
113 | puts("SGI???"); |
---|
114 | } |
---|
115 | } else if (verbose) { |
---|
116 | if (i->inv_type == INV_CPUCHIP) { |
---|
117 | fprintf(stdout,"CPU: MIPS R4600\n"); |
---|
118 | } else { |
---|
119 | fprintf(stdout,"FPU:MIPS R4610\n"); |
---|
120 | } |
---|
121 | } |
---|
122 | } |
---|
123 | |
---|
124 | |
---|
125 | void do_dpy(int verbose) |
---|
126 | { |
---|
127 | int status; |
---|
128 | inventory_t *inv; |
---|
129 | int done=0; |
---|
130 | |
---|
131 | if (verbose) { |
---|
132 | switch(fork()) { |
---|
133 | case -1: |
---|
134 | fprintf (stderr, |
---|
135 | "Don't know how to determine display type for this machine.\n"); |
---|
136 | return; |
---|
137 | case 0: |
---|
138 | if ((execlp("/usr/gfx/gfxinfo","gfxinfo",NULL) ) == -1 ) { |
---|
139 | fprintf (stderr, |
---|
140 | "Don't know how to determine display type for this machine.\n"); |
---|
141 | return; |
---|
142 | } |
---|
143 | default: |
---|
144 | wait(&status); |
---|
145 | break; |
---|
146 | } /* switch */ |
---|
147 | (void) setinvent(); |
---|
148 | inv = getinvent(); |
---|
149 | while ((inv != NULL) && !done) { |
---|
150 | if ( inv->inv_class == INV_VIDEO) { |
---|
151 | do_INV_CAM(inv, verbose); |
---|
152 | } |
---|
153 | inv = getinvent(); |
---|
154 | } |
---|
155 | } else { /* not verbose */ |
---|
156 | (void) setinvent(); |
---|
157 | inv = getinvent(); |
---|
158 | while ((inv != NULL) && !done) { |
---|
159 | if ( inv->inv_class == INV_GRAPHICS) { |
---|
160 | do_INV_GRAPHICS(inv, verbose); |
---|
161 | } |
---|
162 | inv = getinvent(); |
---|
163 | } |
---|
164 | } /* verbose */ |
---|
165 | } |
---|
166 | |
---|
167 | void do_INV_GRAPHICS(inventory_t *i, int verbose) |
---|
168 | { |
---|
169 | switch(i->inv_type) |
---|
170 | { |
---|
171 | case INV_NEWPORT: |
---|
172 | switch(i->inv_state) |
---|
173 | { |
---|
174 | case INV_NEWPORT_24: |
---|
175 | fprintf(stdout,"XL-24\n"); |
---|
176 | break; |
---|
177 | case INV_NEWPORT_XL: |
---|
178 | fprintf(stdout,"XL\n"); |
---|
179 | break; |
---|
180 | default: |
---|
181 | fprintf(stdout,"NG1\n"); |
---|
182 | break; |
---|
183 | } |
---|
184 | break; |
---|
185 | case INV_GR2: |
---|
186 | /* an EXPRESS is an EXPRESS of course of course |
---|
187 | except when you are a GR3-XZ */ |
---|
188 | if ((i->inv_state & ~INV_GR2_INDY) == INV_GR2_ELAN ) |
---|
189 | fprintf(stdout,"GR3-XZ\n"); |
---|
190 | else |
---|
191 | fprintf(stdout,"UNKNOWN video\n"); |
---|
192 | break; |
---|
193 | #ifdef INV_CRIME |
---|
194 | case INV_CRIME: |
---|
195 | fprintf(stdout, "CRM\n"); |
---|
196 | break; |
---|
197 | #endif |
---|
198 | default: |
---|
199 | fprintf(stdout,"UNKNOWN video\n"); |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | void do_INV_CAM(inventory_t *i, int verbose) |
---|
204 | { |
---|
205 | if (i->inv_type == INV_VIDEO_VINO ) { |
---|
206 | if (i->inv_state == INV_VINO_INDY_CAM ) { |
---|
207 | fprintf(stdout,"\tIndy cam connected\n"); |
---|
208 | } |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | |
---|
214 | void do_disk(int verbose) |
---|
215 | { |
---|
216 | inventory_t *inv; |
---|
217 | int t; |
---|
218 | int done=0; |
---|
219 | (void) setinvent(); |
---|
220 | inv = getinvent(); |
---|
221 | t = 0; |
---|
222 | while ((inv != NULL) && !done) { |
---|
223 | if (inv->inv_class == INV_DISK) |
---|
224 | do_INV_DISK(inv, verbose); |
---|
225 | else if (inv->inv_class == INV_SCSI) |
---|
226 | do_INV_SCSI(inv, verbose); |
---|
227 | inv = getinvent(); |
---|
228 | } |
---|
229 | } |
---|
230 | void do_INV_SCSI(inventory_t *i, int verbose) |
---|
231 | { |
---|
232 | if (i->inv_type == INV_CDROM) { |
---|
233 | fprintf(stdout,"CDROM: unit %i, on SCSI controller %i\n",i->inv_unit,i->inv_controller); |
---|
234 | } else { |
---|
235 | fprintf(stdout,"Unknown type %i:unit %i, on SCSI controller %i\n",i->inv_type,i->inv_unit,i->inv_controller); |
---|
236 | } |
---|
237 | } |
---|
238 | |
---|
239 | void do_INV_DISK(inventory_t *i, int verbose) |
---|
240 | { |
---|
241 | switch (i->inv_type) |
---|
242 | { |
---|
243 | case INV_SCSIDRIVE: |
---|
244 | printf("Disk drive: unit %u, on SCSI controller %u\n", |
---|
245 | i->inv_unit, i->inv_controller); |
---|
246 | break; |
---|
247 | |
---|
248 | case INV_SCSIFLOPPY: |
---|
249 | printf("Floppy drive: unit %u, on SCSI controller %u\n", |
---|
250 | i->inv_unit, i->inv_controller); |
---|
251 | break; |
---|
252 | |
---|
253 | case INV_SCSICONTROL: |
---|
254 | case INV_GIO_SCSICONTROL: |
---|
255 | #ifdef INV_PCI_SCSICONTROL |
---|
256 | case INV_PCI_SCSICONTROL: |
---|
257 | #endif |
---|
258 | do_INV_SCSICONTROL(i, verbose); |
---|
259 | break; |
---|
260 | |
---|
261 | default: |
---|
262 | printf("Unknown type %u: unit %u, on SCSI controller %u\n", |
---|
263 | i->inv_type, i->inv_unit, i->inv_controller); |
---|
264 | break; |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | void do_INV_SCSICONTROL(inventory_t *i, int verbose) |
---|
269 | { |
---|
270 | /* Only display SCSI controller info when verbose */ |
---|
271 | if (!verbose) |
---|
272 | return; |
---|
273 | |
---|
274 | switch (i->inv_type) |
---|
275 | { |
---|
276 | case INV_SCSICONTROL: |
---|
277 | printf("Integral"); |
---|
278 | break; |
---|
279 | case INV_GIO_SCSICONTROL: |
---|
280 | printf("GIO"); |
---|
281 | break; |
---|
282 | #ifdef INV_PCI_SCSICONTROL |
---|
283 | case INV_PCI_SCSICONTROL: |
---|
284 | printf("PCI"); |
---|
285 | break; |
---|
286 | #endif |
---|
287 | default: |
---|
288 | printf("Unknown"); |
---|
289 | break; |
---|
290 | } |
---|
291 | |
---|
292 | printf(" SCSI controller %u: Version ", i->inv_controller); |
---|
293 | |
---|
294 | switch (i->inv_state) |
---|
295 | { |
---|
296 | case INV_WD93: |
---|
297 | printf("WD 33C93"); |
---|
298 | break; |
---|
299 | |
---|
300 | case INV_WD93A: |
---|
301 | printf("WD 33C93A"); |
---|
302 | break; |
---|
303 | |
---|
304 | case INV_WD93B: |
---|
305 | printf("WD 33C93B"); |
---|
306 | break; |
---|
307 | |
---|
308 | case INV_WD95A: |
---|
309 | printf("WD 33C95A"); |
---|
310 | break; |
---|
311 | |
---|
312 | case INV_SCIP95: |
---|
313 | printf("SCIP w/WD 33C95A"); |
---|
314 | break; |
---|
315 | |
---|
316 | #ifdef INV_ADP7880 |
---|
317 | case INV_ADP7880: |
---|
318 | printf("ADAPTEC 7880"); |
---|
319 | break; |
---|
320 | #endif |
---|
321 | |
---|
322 | default: |
---|
323 | printf("Unknown"); |
---|
324 | break; |
---|
325 | } |
---|
326 | |
---|
327 | if (i->inv_unit) |
---|
328 | printf(", rev. %X", i->inv_unit); |
---|
329 | |
---|
330 | putchar('\n'); |
---|
331 | } |
---|
332 | |
---|
333 | |
---|
334 | #define MEG (1024*1024) |
---|
335 | |
---|
336 | void do_memory(int verbose) |
---|
337 | { |
---|
338 | int mf, pos, mem, nbpp; |
---|
339 | |
---|
340 | if (nlist(KERNEL, nl) < 0) { |
---|
341 | fprintf(stderr,"can't get namelist\n"); |
---|
342 | exit(2); |
---|
343 | } |
---|
344 | if ((mf = open(MEMORY, O_RDONLY)) == -1) { |
---|
345 | perror("can't open memory"); |
---|
346 | exit(2); |
---|
347 | } |
---|
348 | nbpp = getpagesize() / 1024; |
---|
349 | pos = nl[X_maxmem].n_value; |
---|
350 | if(pos == 0) { |
---|
351 | fprintf(stderr, "can't find maxmem\n"); |
---|
352 | exit(3); |
---|
353 | } |
---|
354 | lseek(mf,pos,L_SET); /* Error checking ? */ |
---|
355 | if(read(mf,&mem,4) == -1) { |
---|
356 | perror("read (kmem)"); |
---|
357 | exit(4); |
---|
358 | } else { |
---|
359 | if(verbose) |
---|
360 | printf("%d user, ",mem * nbpp); |
---|
361 | } |
---|
362 | pos = nl[X_physmem].n_value; |
---|
363 | if(pos == 0) { |
---|
364 | fprintf(stderr, "can't find physmem\n"); |
---|
365 | exit(3); |
---|
366 | } |
---|
367 | lseek(mf,pos,L_SET); |
---|
368 | if(read(mf,&mem,4) == -1) { |
---|
369 | perror("read (kmem)"); |
---|
370 | exit(4); |
---|
371 | } else { |
---|
372 | if(verbose) |
---|
373 | printf("%d (%d M) total\n",mem * nbpp,(mem * getpagesize() + MEG/2)/MEG); |
---|
374 | else |
---|
375 | printf("%d\n", mem * nbpp); |
---|
376 | } |
---|
377 | return; |
---|
378 | } |
---|
379 | |
---|