revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / identify / idhardware.c
blobed77bdaca16f917eca78ed051a3fd928e327b796
1 /*
2 * Copyright (c) 2010-2011 Matthias Rustler
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
22 * $Id$
25 #include <resources/processor.h>
27 #include <proto/utility.h>
28 #include <proto/processor.h>
29 #include <clib/alib_protos.h>
31 #include <stdio.h>
32 #include <string.h>
34 #include "identify_intern.h"
35 #include "identify.h"
36 #include "locale.h"
38 #include <aros/debug.h>
40 static CONST_STRPTR handle_version(TEXT *buffer, Tag tag);
41 static CONST_STRPTR handle_size(TEXT *buffer, Tag tag);
42 static CONST_STRPTR handle_freq(TEXT *buffer, Tag tag);
43 static CONST_STRPTR handle_mhz(TEXT *buffer, Tag tag);
44 static CONST_STRPTR handle_number(TEXT *buffer, Tag tag);
45 static CONST_STRPTR handle_address(TEXT *buffer, Tag tag);
46 static CONST_STRPTR handle_hex(TEXT *buffer, Tag tag);
47 static CONST_STRPTR handle_avail(Tag tag, BOOL null4na);
48 static CONST_STRPTR handle_notavail(BOOL null4na);
50 /*****************************************************************************
52 NAME */
53 #include <proto/identify.h>
55 AROS_LH2(CONST_STRPTR, IdHardware,
57 /* SYNOPSIS */
58 AROS_LHA(ULONG , type , D0),
59 AROS_LHA(struct TagItem *, taglist, A0),
61 /* LOCATION */
62 struct IdentifyBaseIntern *, IdentifyBase, 6, Identify)
64 /* FUNCTION
65 Gets information about the current system environment. The result
66 is returned as read only string. This function is fully DraCo
67 compatible!
69 Once a information has been evaluated, it will be cached internally,
70 so changes will be ignored. Use IdHardwareUpdate() to clear the cache
71 contents.
73 INPUTS
74 Type -- (ULONG) Information type. These types are known:
76 IDHW_SYSTEM -- What system is used?
77 (e. g. "Amiga 4000")
79 IDHW_CPU -- What kind of CPU is available?
80 (e. g. "68060")
82 IDHW_FPU -- What kind of FPU is available?
83 (e. g. "68060")
85 IDHW_MMU -- What kind of MMU is available?
86 (e. g. "68060")
88 IDHW_OSVER -- What OS version is used?
89 (e.g. "V39.106")
91 IDHW_EXECVER -- What exec version is used?
92 (e.g. "V39.47")
94 IDHW_WBVER -- What WorkBench version is used?
95 (e.g. "V39.29")
97 IDHW_ROMSIZE -- Size of AmigaOS ROM
98 (e.g. "512KB")
100 IDHW_CHIPSET -- What Chipset is available?
101 (e.g. "AGA")
103 IDHW_GFXSYS -- What Graphic OS is used?
104 (e.g. "CyberGraphX")
106 IDHW_CHIPRAM -- Size of complete Chip RAM
107 (e.g. "~2.0MB")
109 IDHW_FASTRAM -- Size of complete Fast RAM
110 (e.g. "12.0MB")
112 IDHW_RAM -- Size of complete System RAM
113 (e.g. "~14.0MB")
115 IDHW_SETPATCHVER -- [V4] Version of current SetPatch
116 (e.g. "V40.14")
118 IDHW_AUDIOSYS -- [V5] What Audio OS is used?
119 (e.g. "AHI")
121 IDHW_OSNR -- [V5] What AmigaOS is used?
122 (e.g. "3.1")
124 IDHW_VMMCHIPRAM -- [V5] Size of virtual Chip RAM
125 (e.g. "0")
127 IDHW_VMMFASTRAM -- [V5] Size of virtual Fast RAM
128 (e.g. "40.0MB")
130 IDHW_VMMRAM -- [V5] Size of total virtual RAM
131 (e.g. "40.0MB")
133 IDHW_PLNCHIPRAM -- [V5] Size of non-virtual Chip RAM
134 (e.g. "2.0MB")
136 IDHW_PLNFASTRAM -- [V5] Size of non-virtual Fast RAM
137 (e.g. "12.0MB")
139 IDHW_PLNRAM -- [V5] Size of total non-virtual RAM
140 (e.g. "14.0MB")
142 IDHW_VBR -- [V6] Vector Base Register contents
143 (e.g. "0x0806C848")
145 IDHW_LASTALERT -- [V6] Last Alert code
146 (e.g. "80000003")
148 IDHW_VBLANKFREQ -- [V6] VBlank frequency (see execbase.h)
149 (e.g. "50 Hz")
151 IDHW_POWERFREQ -- [V6] Power supply frequency (see execbase.h)
152 (e.g. "50 Hz")
154 IDHW_ECLOCK -- [V6] System E clock frequency
155 (e.g. "709379 Hz")
157 IDHW_SLOWRAM -- [V6] A500/A2000 "Slow" RAM expansion
158 (e.g. "512.0KB")
160 IDHW_GARY -- [V6] GARY revision
161 (e.g. "Normal")
163 IDHW_RAMSEY -- [V6] RAMSEY revision
164 (e.g. "F")
166 IDHW_BATTCLOCK -- [V6] Battery backed up clock present?
167 (e.g. "Found")
169 IDHW_CHUNKYPLANAR -- [V7] Chunky to planar hardware present?
170 (e.g. "Found")
172 IDHW_POWERPC -- [V7] PowerPC CPU present?
173 (e.g. "603e")
175 IDHW_PPCCLOCK -- [V7] PowerPC processor clock
176 (e.g. "200 MHz")
178 IDHW_CPUREV -- [V8] Revision of the main processor, if
179 available (e.g. "Rev 1")
181 IDHW_CPUCLOCK -- [V8] CPU clock
182 (e.g. "50 MHz")
184 IDHW_FPUCLOCK -- [V8] FPU clock, if available
185 (e.g. "50 MHz")
187 IDHW_RAMACCESS -- [V8] Access time of the main board RAM
188 (e.g. "80 ns")
190 IDHW_RAMWIDTH -- [V8] Width of the main board RAM
191 (e.g. "16 bit")
193 IDHW_RAMCAS -- [V8] CAS mode of the main board RAM
194 (e.g. "Double")
196 IDHW_RAMBANDWIDTH -- [V8] Bandwidth of the main board RAM
197 (e.g. "2")
199 IDHW_TCPIP -- [V9] Used TCP/IP stack
200 (e.g. "AmiTCP/IP")
202 IDHW_PPCOS -- [V9] Used PowerPC OS
203 (e.g. "PowerUp")
205 IDHW_AGNUS -- [V9] Agnus chip type and revision
206 (e.g. "Alice 8374 Rev. 3-4")
208 IDHW_AGNUSMODE -- [V9] Agnus chip mode
209 (e.g. "PAL")
211 IDHW_DENISE -- [V10] Denise chip type
212 (e.g. "Lisa 8364")
214 IDHW_DENISEREV -- [V10] Denise chip revision
215 (e.g. "0")
217 TagList -- (struct TagItem *) tags that describe further
218 options. You may provide NULL.
220 TAGS
221 IDTAG_Localize -- [V8] (BOOL) FALSE to get English strings
222 only, TRUE for localized strings. This is useful for applications
223 with English as only language. Defaults to TRUE.
225 IDTAG_NULL4NA -- [V8] (BOOL) TRUE to get NULL pointer instead
226 of a 'not available' string. Defaults to FALSE.
228 RESULT
229 String -- (STRPTR) String containing the desired
230 information, or NULL if not available. Note that
231 all strings are READ ONLY!
233 NOTES
234 Some results are nonsense on AROS.
236 EXAMPLE
238 BUGS
240 SEE ALSO
241 IdHardwareNum(), IdHardwareUpdate()
243 INTERNALS
245 HISTORY
248 *****************************************************************************/
250 AROS_LIBFUNC_INIT
252 struct TagItem *tag;
253 struct TagItem *tags;
255 CONST_STRPTR result = NULL;
256 BOOL null4na = FALSE;
257 BOOL localize = TRUE;
259 for (tags = taglist; (tag = NextTagItem(&tags)); )
261 switch (tag->ti_Tag)
263 case IDTAG_NULL4NA:
264 null4na = tag->ti_Data ? TRUE : FALSE;
265 break;
267 case IDTAG_Localize:
268 localize = tag->ti_Data ? TRUE : FALSE;
269 break;
273 if (localize) {
274 /* FIXME: Do something here? */
277 ObtainSemaphore(&IdentifyBase->sem);
279 switch(type)
281 case IDHW_SYSTEM:
282 result = "AROS";
283 break;
285 case IDHW_CPU:
287 IPTR cpu = 0;
288 APTR ProcessorBase = OpenResource(PROCESSORNAME);
290 if (ProcessorBase)
292 struct TagItem tags [] =
294 { GCIT_Family, (IPTR)&cpu },
295 { TAG_DONE }
297 GetCPUInfo(tags);
298 switch(cpu)
300 case CPUFAMILY_60X: result = "60X"; break;
301 case CPUFAMILY_7X0: result = "7X0"; break;
302 case CPUFAMILY_74XX: result = "74XX"; break;
303 case CPUFAMILY_4XX: result = "4XX"; break;
304 case CPUFAMILY_AMD_K5: result = "AMD_K5"; break;
305 case CPUFAMILY_AMD_K6: result = "AMD_K6"; break;
306 case CPUFAMILY_AMD_K7: result = "AMD_K7"; break;
307 case CPUFAMILY_AMD_K8: result = "AMD_K8"; break;
308 case CPUFAMILY_AMD_K9: result = "ADM_K9"; break;
309 case CPUFAMILY_AMD_K10: result = "AMD_K10"; break;
310 case CPUFAMILY_INTEL_486: result = "INTEL_486"; break;
311 case CPUFAMILY_INTEL_PENTIUM: result = "INTEL_PENTIUM"; break;
312 case CPUFAMILY_INTEL_PENTIUM_PRO: result = "INTEL_PENTIUM_PRO"; break;
313 case CPUFAMILY_INTEL_PENTIUM4: result = "INTEL_PENTIUM4"; break;
314 case CPUFAMILY_MOTOROLA_68000: result = "MOTOROLA_68000"; break;
315 default: result = "unknown"; break;
318 else
320 result = "unknown";
322 break;
324 case IDHW_FPU:
325 result = handle_notavail(null4na);
326 break;
328 case IDHW_MMU:
329 result = handle_notavail(null4na);
330 break;
332 case IDHW_OSVER:
333 result = handle_version(IdentifyBase->hwb.buf_OsVer, IDHW_OSVER);
334 break;
336 case IDHW_EXECVER:
337 result = handle_version(IdentifyBase->hwb.buf_ExecVer, IDHW_EXECVER);
338 break;
340 case IDHW_WBVER:
341 result = handle_version(IdentifyBase->hwb.buf_WbVer, IDHW_WBVER);
342 break;
344 case IDHW_ROMSIZE:
345 result = handle_size(IdentifyBase->hwb.buf_RomSize, IDHW_ROMSIZE);
346 break;
348 case IDHW_CHIPSET:
349 result = _(MSG_HW_OCS);
350 break;
352 case IDHW_GFXSYS:
353 result = _(MSG_HW_CYBERGRAPHX);
354 break;
356 case IDHW_CHIPRAM:
357 result = handle_size(IdentifyBase->hwb.buf_ChipRAM, IDHW_CHIPRAM);
358 break;
360 case IDHW_FASTRAM:
361 result = handle_size(IdentifyBase->hwb.buf_FastRAM, IDHW_FASTRAM);
362 break;
364 case IDHW_RAM:
365 result = handle_size(IdentifyBase->hwb.buf_RAM, IDHW_RAM);
366 break;
368 case IDHW_SETPATCHVER:
369 result = handle_version(IdentifyBase->hwb.buf_SetPatchVer, IDHW_SETPATCHVER);
370 break;
372 case IDHW_AUDIOSYS:
373 result = _(MSG_HW_AHI);
374 break;
376 case IDHW_OSNR:
377 result = _(MSG_HW_OS_40);
378 break;
380 case IDHW_VMMCHIPRAM:
381 result = "0";
382 break;
384 case IDHW_VMMFASTRAM:
385 result = "0";
386 break;
388 case IDHW_VMMRAM:
389 result = "0";
390 break;
392 case IDHW_PLNCHIPRAM:
393 result = handle_size(IdentifyBase->hwb.buf_PlainChipRAM, IDHW_PLNCHIPRAM);
394 break;
396 case IDHW_PLNFASTRAM:
397 result = handle_size(IdentifyBase->hwb.buf_PlainFastRAM, IDHW_PLNFASTRAM);
398 break;
400 case IDHW_PLNRAM:
401 result = handle_size(IdentifyBase->hwb.buf_PlainRAM, IDHW_PLNRAM);
402 break;
404 case IDHW_VBR:
405 IdentifyBase->hwb.buf_VBR[0] = '\0'; // not buffered
406 result = handle_address(IdentifyBase->hwb.buf_VBR, IDHW_VBR);
407 break;
409 case IDHW_LASTALERT:
410 IdentifyBase->hwb.buf_LastAlert[0] = '\0'; // not buffered
411 result = handle_hex(IdentifyBase->hwb.buf_LastAlert, IDHW_LASTALERT);
412 break;
414 case IDHW_VBLANKFREQ:
415 result = handle_freq(IdentifyBase->hwb.buf_VBlankFreq, IDHW_VBLANKFREQ);
416 break;
418 case IDHW_POWERFREQ:
419 result = handle_freq(IdentifyBase->hwb.buf_PowerFreq, IDHW_POWERFREQ);
420 break;
422 case IDHW_ECLOCK:
423 result = handle_freq(IdentifyBase->hwb.buf_EClock, IDHW_ECLOCK);
424 break;
426 case IDHW_SLOWRAM:
427 result = handle_size(IdentifyBase->hwb.buf_SlowRAM, IDHW_SLOWRAM);
428 break;
430 case IDHW_GARY:
431 result = handle_notavail(null4na);
432 break;
434 case IDHW_RAMSEY:
435 result = handle_notavail(null4na);
436 break;
438 case IDHW_BATTCLOCK:
439 result = handle_avail(IDHW_BATTCLOCK, null4na);
440 break;
442 case IDHW_CHUNKYPLANAR:
443 result = handle_avail(IDHW_CHUNKYPLANAR, null4na);
444 break;
446 case IDHW_POWERPC:
447 result = handle_notavail(null4na);
448 break;
450 case IDHW_PPCCLOCK:
451 result = "0 MHz";
452 break;
454 case IDHW_CPUREV:
455 result = handle_notavail(null4na);
456 break;
458 case IDHW_CPUCLOCK:
459 result = handle_mhz(IdentifyBase->hwb.buf_CPUClock, IDHW_CPUCLOCK);
460 break;
462 case IDHW_FPUCLOCK:
463 result = "0 MHz";
464 break;
466 case IDHW_RAMACCESS:
467 result = handle_notavail(null4na);
468 break;
470 case IDHW_RAMWIDTH:
471 result = handle_number(IdentifyBase->hwb.buf_RAMWidth, IDHW_RAMWIDTH);
472 break;
474 case IDHW_RAMCAS:
476 ULONG num = IdHardwareNum(IDHW_RAMCAS, NULL);
477 if (num == 2)
479 result = _(MSG_HW_RAMCAS_DOUBLE);
481 else
483 result = _(MSG_HW_RAMCAS_NORMAL);
485 break;
488 case IDHW_RAMBANDWIDTH:
489 result = handle_notavail(null4na);
490 break;
492 case IDHW_TCPIP:
493 result = _(MSG_HW_TCPIP_AMITCP);
494 break;
496 case IDHW_PPCOS:
497 result = _(MSG_HW_PPCOS_NONE);
498 break;
500 case IDHW_AGNUS:
501 result = _(MSG_HW_AGNUS_NONE);
502 break;
504 case IDHW_AGNUSMODE:
505 result = _(MSG_HW_AMODE_NONE);
506 break;
508 case IDHW_DENISE:
509 result = _(MSG_HW_DENISE_NONE);
510 break;
512 case IDHW_DENISEREV:
513 result = handle_notavail(null4na);
514 break;
516 default:
517 result = handle_notavail(null4na);
518 break;
521 ReleaseSemaphore(&IdentifyBase->sem);
523 return result;
525 AROS_LIBFUNC_EXIT
526 } /* IdHardware */
529 static CONST_STRPTR handle_version(TEXT *buffer, Tag tag)
531 CONST_STRPTR result = buffer;
532 if (*buffer == '\0')
534 ULONG num = IdHardwareNum(tag, NULL);
535 if (num != 0 && num != -1)
537 ULONG version = num & 0xffff;
538 ULONG revision = num >> 16;
539 snprintf(buffer, STRBUFSIZE, _(MSG_HW_VERSION), version, revision);
541 else
543 strlcpy(buffer, _(MSG_HW_NOVERSION), STRBUFSIZE);
546 return result;
549 static CONST_STRPTR handle_size(TEXT *buffer, Tag tag)
551 CONST_STRPTR result = buffer;
552 CONST_STRPTR format;
553 UBYTE fraction = 0;
555 if (*buffer == '\0')
557 UQUAD num = IdHardwareNum(tag, NULL);
558 if (num < 1000)
560 num *= 10;
561 format = _(MSG_BYTE);
563 else if (num < 1000 * 1000)
565 num /= 102;
566 format = _(MSG_KBYTE);
568 else if (num < 1000 * 1000 * 1000)
570 num = num / 1024 / 102;
571 format = _(MSG_MBYTE);
573 else
575 num = num / 1024 / 1024 / 102;
576 format = _(MSG_GBYTE);
578 fraction = num % 10;
579 num /= 10;
581 snprintf(buffer, STRBUFSIZE, format,
582 (long unsigned int)num, '0' + fraction);
584 return result;
587 static CONST_STRPTR handle_freq(TEXT *buffer, Tag tag)
589 CONST_STRPTR result = buffer;
590 if (*buffer == '\0')
592 ULONG num = IdHardwareNum(tag, NULL);
594 snprintf(buffer, STRBUFSIZE, "%u Hz", (unsigned int)num);
597 return result;
600 static CONST_STRPTR handle_mhz(TEXT *buffer, Tag tag)
602 CONST_STRPTR result = buffer;
603 if (*buffer == '\0')
605 ULONG num = IdHardwareNum(tag, NULL);
607 snprintf(buffer, STRBUFSIZE, "%u MHz", (unsigned int)num);
610 return result;
613 static CONST_STRPTR handle_number(TEXT *buffer, Tag tag)
615 CONST_STRPTR result = buffer;
616 if (*buffer == '\0')
618 ULONG num = IdHardwareNum(tag, NULL);
620 snprintf(buffer, STRBUFSIZE, "%u", (unsigned int)num);
623 return result;
626 static CONST_STRPTR handle_address(TEXT *buffer, Tag tag)
628 CONST_STRPTR result = buffer;
629 if (*buffer == '\0')
631 ULONG num = IdHardwareNum(tag, NULL);
633 snprintf(buffer, STRBUFSIZE, "0x%08x", (unsigned int)num);
636 return result;
639 static CONST_STRPTR handle_hex(TEXT *buffer, Tag tag)
641 CONST_STRPTR result = buffer;
642 if (*buffer == '\0')
644 ULONG num = IdHardwareNum(tag, NULL);
646 snprintf(buffer, STRBUFSIZE, "%08x", (unsigned int)num);
649 return result;
652 static CONST_STRPTR handle_avail(Tag tag, BOOL null4na)
654 ULONG num = IdHardwareNum(tag, NULL);
655 if (num)
657 return _(MSG_HW_FOUND);
659 else
661 return handle_notavail(null4na);
665 static CONST_STRPTR handle_notavail(BOOL null4na)
667 if (null4na == FALSE)
668 return _(MSG_HW_NONE);
669 else
670 return NULL;