diff options
Diffstat (limited to 'modules/devices')
32 files changed, 0 insertions, 8417 deletions
diff --git a/modules/devices/alpha/processor.c b/modules/devices/alpha/processor.c deleted file mode 100644 index c7862232..00000000 --- a/modules/devices/alpha/processor.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -GSList * -processor_scan(void) -{ - Processor *processor; - FILE *cpuinfo; - gchar buffer[128]; - long long hz = 0; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - - processor = g_new0(Processor, 1); - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - - get_str("cpu model", processor->model_name); - get_float("BogoMIPS", processor->bogomips); - get_str("platform string", processor->strmodel); - get_str("cycle frequency [Hz]", processor->cycle_frequency_hz_str); - - } - g_strfreev(tmp); - } - - fclose(cpuinfo); - - gchar *tmp = g_strconcat("Alpha ", processor->model_name, NULL); - g_free(processor->model_name); - processor->model_name = tmp; - - if (processor->cycle_frequency_hz_str) { - hz = atoll(processor->cycle_frequency_hz_str); - processor->cpu_mhz = hz; - processor->cpu_mhz /= 1000000; - } else - processor->cpu_mhz = 0.0f; - - return g_slist_append(NULL, processor); -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_info(GSList *processors) -{ - Processor *processor = (Processor *)processors->data; - - return g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%.2f %s\n" /* frequency */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n", /* byte order */ - _("Processor"), - _("Model"), processor->model_name, - _("Platform String"), processor->strmodel, - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str() - ); -} diff --git a/modules/devices/arm/arm_data.c b/modules/devices/arm/arm_data.c deleted file mode 100644 index 60e8ea34..00000000 --- a/modules/devices/arm/arm_data.c +++ /dev/null @@ -1,265 +0,0 @@ -/* - * rpiz - https://github.com/bp0/rpiz - * Copyright (C) 2017 Burt P. <pburt0@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include "arm_data.h" - -#ifndef C_ -#define C_(Ctx, String) String -#endif -#ifndef NC_ -#define NC_(Ctx, String) String -#endif - -/* sources: - * https://unix.stackexchange.com/a/43563 - * git:linux/arch/arm/kernel/setup.c - * git:linux/arch/arm64/kernel/cpuinfo.c - */ -static struct { - char *name, *meaning; -} tab_flag_meaning[] = { - /* arm/hw_cap */ - { "swp", NC_("arm-flag", /*/flag:swp*/ "SWP instruction (atomic read-modify-write)") }, - { "half", NC_("arm-flag", /*/flag:half*/ "Half-word loads and stores") }, - { "thumb", NC_("arm-flag", /*/flag:thumb*/ "Thumb (16-bit instruction set)") }, - { "26bit", NC_("arm-flag", /*/flag:26bit*/ "26-Bit Model (Processor status register folded into program counter)") }, - { "fastmult", NC_("arm-flag", /*/flag:fastmult*/ "32x32->64-bit multiplication") }, - { "fpa", NC_("arm-flag", /*/flag:fpa*/ "Floating point accelerator") }, - { "vfp", NC_("arm-flag", /*/flag:vfp*/ "VFP (early SIMD vector floating point instructions)") }, - { "edsp", NC_("arm-flag", /*/flag:edsp*/ "DSP extensions (the 'e' variant of the ARM9 CPUs, and all others above)") }, - { "java", NC_("arm-flag", /*/flag:java*/ "Jazelle (Java bytecode accelerator)") }, - { "iwmmxt", NC_("arm-flag", /*/flag:iwmmxt*/ "SIMD instructions similar to Intel MMX") }, - { "crunch", NC_("arm-flag", /*/flag:crunch*/ "MaverickCrunch coprocessor (if kernel support enabled)") }, - { "thumbee", NC_("arm-flag", /*/flag:thumbee*/ "ThumbEE") }, - { "neon", NC_("arm-flag", /*/flag:neon*/ "Advanced SIMD/NEON on AArch32") }, - { "evtstrm", NC_("arm-flag", /*/flag:evtstrm*/ "Kernel event stream using generic architected timer") }, - { "vfpv3", NC_("arm-flag", /*/flag:vfpv3*/ "VFP version 3") }, - { "vfpv3d16", NC_("arm-flag", /*/flag:vfpv3d16*/ "VFP version 3 with 16 D-registers") }, - { "vfpv4", NC_("arm-flag", /*/flag:vfpv4*/ "VFP version 4 with fast context switching") }, - { "vfpd32", NC_("arm-flag", /*/flag:vfpd32*/ "VFP with 32 D-registers") }, - { "tls", NC_("arm-flag", /*/flag:tls*/ "TLS register") }, - { "idiva", NC_("arm-flag", /*/flag:idiva*/ "SDIV and UDIV hardware division in ARM mode") }, - { "idivt", NC_("arm-flag", /*/flag:idivt*/ "SDIV and UDIV hardware division in Thumb mode") }, - { "lpae", NC_("arm-flag", /*/flag:lpae*/ "40-bit Large Physical Address Extension") }, - /* arm/hw_cap2 */ - { "pmull", NC_("arm-flag", /*/flag:pmull*/ "64x64->128-bit F2m multiplication (arch>8)") }, - { "aes", NC_("arm-flag", /*/flag:aes*/ "Crypto:AES (arch>8)") }, - { "sha1", NC_("arm-flag", /*/flag:sha1*/ "Crypto:SHA1 (arch>8)") }, - { "sha2", NC_("arm-flag", /*/flag:sha2*/ "Crypto:SHA2 (arch>8)") }, - { "crc32", NC_("arm-flag", /*/flag:crc32*/ "CRC32 checksum instructions (arch>8)") }, - /* arm64/hw_cap */ - { "fp", NULL }, - { "asimd", NC_("arm-flag", /*/flag:asimd*/ "Advanced SIMD/NEON on AArch64 (arch>8)") }, - { "atomics", NULL }, - { "fphp", NULL }, - { "asimdhp", NULL }, - { "cpuid", NULL }, - { "asimdrdm", NULL }, - { "jscvt", NULL }, - { "fcma", NULL }, - { "lrcpc", NULL }, - { NULL, NULL } -}; - -static struct { - int code; char *name; -} tab_arm_implementer[] = { - { 0x41, "ARM" }, - { 0x44, "Intel (formerly DEC) StrongARM" }, - { 0x4e, "nVidia" }, - { 0x54, "Texas Instruments" }, - { 0x56, "Marvell" }, - { 0x69, "Intel XScale" }, - { 0, NULL}, -}; - -static struct { - /* source: t = tested, d = official docs, f = web */ - int code; char *part_desc; -} tab_arm_arm_part[] = { /* only valid for implementer 0x41 ARM */ - /*d */ { 0x920, "ARM920" }, - /*d */ { 0x926, "ARM926" }, - /*d */ { 0x946, "ARM946" }, - /*d */ { 0x966, "ARM966" }, - /*d */ { 0xb02, "ARM11 MPCore" }, - /*d */ { 0xb36, "ARM1136" }, - /*d */ { 0xb56, "ARM1156" }, - /*dt*/ { 0xb76, "ARM1176" }, - /*dt*/ { 0xc05, "Cortex-A5" }, - /*d */ { 0xc07, "Cortex-A7 MPCore" }, - /*dt*/ { 0xc08, "Cortex-A8" }, - /*dt*/ { 0xc09, "Cortex-A9" }, - /*d */ { 0xc0e, "Cortex-A17 MPCore" }, - /*d */ { 0xc0f, "Cortex-A15" }, - /*d */ { 0xd01, "Cortex-A32" }, - /*dt*/ { 0xd03, "Cortex-A53" }, - /*d */ { 0xd04, "Cortex-A35" }, - /*d */ { 0xd05, "Cortex-A55" }, - /*d */ { 0xd07, "Cortex-A57 MPCore" }, - /*d */ { 0xd08, "Cortex-A72" }, - /*d */ { 0xd09, "Cortex-A73" }, - /*d */ { 0xd0a, "Cortex-A75" }, - { 0, NULL}, -}; - -static struct { - char *code; char *name; char *more; -} tab_arm_arch[] = { - { "7", "AArch32", "AArch32 (ARMv7)" }, - { "8", "AArch64", "AArch64 (ARMv8)" }, - { "AArch32", "AArch32", "AArch32 (ARMv7)" }, - { "AArch64", "AArch64", "AArch64 (ARMv8)" }, - { NULL, NULL, NULL }, -}; - -static char all_flags[1024] = ""; - -#define APPEND_FLAG(f) strcat(all_flags, f); strcat(all_flags, " "); -const char *arm_flag_list() { - int i = 0, built = 0; - built = strlen(all_flags); - if (!built) { - while(tab_flag_meaning[i].name != NULL) { - APPEND_FLAG(tab_flag_meaning[i].name); - i++; - } - } - return all_flags; -} - -const char *arm_flag_meaning(const char *flag) { - int i = 0; - if (flag) - while(tab_flag_meaning[i].name != NULL) { - if (strcmp(tab_flag_meaning[i].name, flag) == 0) { - if (tab_flag_meaning[i].meaning != NULL) - return C_("arm-flag", tab_flag_meaning[i].meaning); - else return NULL; - } - i++; - } - return NULL; -} - -static int code_match(int c0, const char* code1) { - int c1; - if (code1 == NULL) return 0; - c1 = strtol(code1, NULL, 0); - return (c0 == c1) ? 1 : 0; -} - -const char *arm_implementer(const char *code) { - int i = 0; - if (code) - while(tab_arm_implementer[i].code) { - if (code_match(tab_arm_implementer[i].code, code)) - return tab_arm_implementer[i].name; - i++; - } - return NULL; -} - -const char *arm_part(const char *imp_code, const char *part_code) { - int i = 0; - if (imp_code && part_code) { - if (code_match(0x41, imp_code)) { - /* 0x41=ARM parts */ - while(tab_arm_arm_part[i].code) { - if (code_match(tab_arm_arm_part[i].code, part_code)) - return tab_arm_arm_part[i].part_desc; - i++; - } - } - } - return NULL; -} - -const char *arm_arch(const char *cpuinfo_arch_str) { - int i = 0; - if (cpuinfo_arch_str) - while(tab_arm_arch[i].code) { - if (strcmp(tab_arm_arch[i].code, cpuinfo_arch_str) == 0) - return tab_arm_arch[i].name; - i++; - } - return cpuinfo_arch_str; -} - -const char *arm_arch_more(const char *cpuinfo_arch_str) { - int i = 0; - if (cpuinfo_arch_str) - while(tab_arm_arch[i].code) { - if (strcmp(tab_arm_arch[i].code, cpuinfo_arch_str) == 0) - return tab_arm_arch[i].more; - i++; - } - return cpuinfo_arch_str; -} - -char *arm_decoded_name(const char *imp, const char *part, const char *var, const char *rev, const char *arch, const char *model_name) { - char *dnbuff; - char *imp_name = NULL, *part_desc = NULL, *arch_name = NULL; - int r = 0, p = 0; - dnbuff = malloc(256); - if (dnbuff) { - memset(dnbuff, 0, 256); - - if (imp && arch && part && rev) { - /* http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0395b/CIHCAGHH.html - * variant and revision can be rendered r{variant}p{revision} */ - r = strtol(var, NULL, 0); - p = strtol(rev, NULL, 0); - imp_name = (char*) arm_implementer(imp); - part_desc = (char*) arm_part(imp, part); - arch_name = (char*) arm_arch(arch); - if (imp_name || part_desc) { - if (arch_name != arch) - sprintf(dnbuff, "%s %s r%dp%d (%s)", - (imp_name) ? imp_name : imp, - (part_desc) ? part_desc : part, - r, p, arch_name); - else - sprintf(dnbuff, "%s %s r%dp%d (arch:%s)", - (imp_name) ? imp_name : imp, - (part_desc) ? part_desc : part, - r, p, arch); - } else { - /* fallback for now */ - sprintf(dnbuff, "%s [imp:%s part:%s r%dp%d arch:%s]", - model_name, - (imp_name) ? imp_name : imp, - (part_desc) ? part_desc : part, - r, p, arch); - } - } else { - /* prolly not ARM arch at all */ - if (model_name) - sprintf(dnbuff, "%s", model_name); - else { - free(dnbuff); - return NULL; - } - } - } - return dnbuff; -} diff --git a/modules/devices/arm/arm_data.h b/modules/devices/arm/arm_data.h deleted file mode 100644 index 63b3c906..00000000 --- a/modules/devices/arm/arm_data.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * rpiz - https://github.com/bp0/rpiz - * Copyright (C) 2017 Burt P. <pburt0@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef _ARMDATA_H_ -#define _ARMDATA_H_ - -/* table lookups */ -const char *arm_implementer(const char *code); -const char *arm_part(const char *imp_code, const char *part_code); -const char *arm_arch(const char *cpuinfo_arch_str); -const char *arm_arch_more(const char *cpuinfo_arch_str); - -/* cpu_implementer, cpu_part, cpu_variant, cpu_revision, cpu_architecture from /proc/cpuinfo - * model_name is returned as a fallback if not enough data is known */ -char *arm_decoded_name( - const char *imp, const char *part, const char *var, const char *rev, - const char *arch, const char *model_name); - -/* cpu flags from /proc/cpuinfo */ -const char *arm_flag_list(void); /* list of all known flags */ -const char *arm_flag_meaning(const char *flag); /* lookup flag meaning */ - -#endif diff --git a/modules/devices/arm/processor.c b/modules/devices/arm/processor.c deleted file mode 100644 index 3bee39f8..00000000 --- a/modules/devices/arm/processor.c +++ /dev/null @@ -1,493 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" -#include "dt_util.h" - -#include "arm_data.h" -#include "arm_data.c" - -enum { - ARM_A32 = 0, - ARM_A64 = 1, - ARM_A32_ON_A64 = 2, -}; - -static const gchar *arm_mode_str[] = { - "A32", - "A64", - "A32 on A64", -}; - -GSList * -processor_scan(void) -{ - GSList *procs = NULL; - Processor *processor = NULL; - FILE *cpuinfo; - gchar buffer[128]; - gchar *rep_pname = NULL; - GSList *pi = NULL; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - -#define CHECK_FOR(k) (g_str_has_prefix(tmp[0], k)) - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - } else { - g_strfreev(tmp); - continue; - } - - get_str("Processor", rep_pname); - - if ( CHECK_FOR("processor") ) { - /* finish previous */ - if (processor) { - procs = g_slist_append(procs, processor); - } - - /* start next */ - processor = g_new0(Processor, 1); - processor->id = atol(tmp[1]); - - if (rep_pname) - processor->linux_name = g_strdup(rep_pname); - - g_strfreev(tmp); - continue; - } - - if (!processor && - ( CHECK_FOR("model name") - || CHECK_FOR("Features") - || CHECK_FOR("BogoMIPS") ) ) { - - /* single proc/core may not have "processor : n" */ - processor = g_new0(Processor, 1); - processor->id = 0; - - if (rep_pname) - processor->linux_name = g_strdup(rep_pname); - } - - if (processor) { - get_str("model name", processor->linux_name); - get_str("Features", processor->flags); - get_float("BogoMIPS", processor->bogomips); - - get_str("CPU implementer", processor->cpu_implementer); - get_str("CPU architecture", processor->cpu_architecture); - get_str("CPU variant", processor->cpu_variant); - get_str("CPU part", processor->cpu_part); - get_str("CPU revision", processor->cpu_revision); - } - g_strfreev(tmp); - } - - if (processor) - procs = g_slist_append(procs, processor); - - g_free(rep_pname); - fclose(cpuinfo); - - /* re-duplicate missing data for /proc/cpuinfo variant that de-duplicated it */ -#define REDUP(f) if (dproc->f && !processor->f) processor->f = g_strdup(dproc->f); - Processor *dproc; - GSList *l; - l = procs = g_slist_reverse(procs); - while (l) { - processor = l->data; - if (processor->flags) { - dproc = processor; - } else if (dproc) { - REDUP(flags); - REDUP(cpu_implementer); - REDUP(cpu_architecture); - REDUP(cpu_variant); - REDUP(cpu_part); - REDUP(cpu_revision); - } - l = g_slist_next(l); - } - procs = g_slist_reverse(procs); - - /* data not from /proc/cpuinfo */ - for (pi = procs; pi; pi = pi->next) { - processor = (Processor *) pi->data; - - /* strings can't be null or segfault later */ - STRIFNULL(processor->linux_name, _("ARM Processor") ); - EMPIFNULL(processor->flags); - UNKIFNULL(processor->cpu_implementer); - UNKIFNULL(processor->cpu_architecture); - UNKIFNULL(processor->cpu_variant); - UNKIFNULL(processor->cpu_part); - UNKIFNULL(processor->cpu_revision); - - processor->model_name = arm_decoded_name( - processor->cpu_implementer, processor->cpu_part, - processor->cpu_variant, processor->cpu_revision, - processor->cpu_architecture, processor->linux_name); - UNKIFNULL(processor->model_name); - - /* topo & freq */ - processor->cpufreq = cpufreq_new(processor->id); - processor->cputopo = cputopo_new(processor->id); - - if (processor->cpufreq->cpukhz_max) - processor->cpu_mhz = processor->cpufreq->cpukhz_max / 1000; - else - processor->cpu_mhz = 0.0f; - - /* mode */ - processor->mode = ARM_A32; - if ( processor_has_flag(processor->flags, "pmull") - || processor_has_flag(processor->flags, "crc32") ) { -#ifdef __aarch64__ - processor->mode = ARM_A64; -#else - processor->mode = ARM_A32_ON_A64; -#endif - } - } - - return procs; -} - -gchar *processor_get_capabilities_from_flags(gchar * strflags) -{ - gchar **flags, **old; - gchar *tmp = NULL; - gint j = 0; - - flags = g_strsplit(strflags, " ", 0); - old = flags; - - while (flags[j]) { - const gchar *meaning = arm_flag_meaning( flags[j] ); - - if (meaning) { - tmp = h_strdup_cprintf("%s=%s\n", tmp, flags[j], meaning); - } else { - tmp = h_strdup_cprintf("%s=\n", tmp, flags[j]); - } - j++; - } - if (tmp == NULL || g_strcmp0(tmp, "") == 0) - tmp = g_strdup_printf("%s=%s\n", "empty", _("Empty List")); - - g_strfreev(old); - return tmp; -} - -#define khzint_to_mhzdouble(k) (((double)k)/1000) -#define cmp_clocks_test(f) if (a->f < b->f) return -1; if (a->f > b->f) return 1; - -static gint cmp_cpufreq_data(cpufreq_data *a, cpufreq_data *b) { - gint i = 0; - i = g_strcmp0(a->shared_list, b->shared_list); if (i!=0) return i; - cmp_clocks_test(cpukhz_max); - cmp_clocks_test(cpukhz_min); - return 0; -} - -static gint cmp_cpufreq_data_ignore_affected(cpufreq_data *a, cpufreq_data *b) { - gint i = 0; - cmp_clocks_test(cpukhz_max); - cmp_clocks_test(cpukhz_min); - return 0; -} - -gchar *clocks_summary(GSList * processors) -{ - gchar *ret = g_strdup_printf("[%s]\n", _("Clocks")); - GSList *all_clocks = NULL, *uniq_clocks = NULL; - GSList *tmp, *l; - Processor *p; - cpufreq_data *c, *cur = NULL; - gint cur_count = 0, i = 0; - - /* create list of all clock references */ - for (l = processors; l; l = l->next) { - p = (Processor*)l->data; - if (p->cpufreq) { - all_clocks = g_slist_prepend(all_clocks, p->cpufreq); - } - } - - if (g_slist_length(all_clocks) == 0) { - ret = h_strdup_cprintf("%s=\n", ret, _("(Not Available)") ); - g_slist_free(all_clocks); - return ret; - } - - /* ignore duplicate references */ - all_clocks = g_slist_sort(all_clocks, (GCompareFunc)cmp_cpufreq_data); - for (l = all_clocks; l; l = l->next) { - c = (cpufreq_data*)l->data; - if (!cur) { - cur = c; - } else { - if (cmp_cpufreq_data(cur, c) != 0) { - uniq_clocks = g_slist_prepend(uniq_clocks, cur); - cur = c; - } - } - } - uniq_clocks = g_slist_prepend(uniq_clocks, cur); - uniq_clocks = g_slist_reverse(uniq_clocks); - cur = 0, cur_count = 0; - - /* count and list clocks */ - for (l = uniq_clocks; l; l = l->next) { - c = (cpufreq_data*)l->data; - if (!cur) { - cur = c; - cur_count = 1; - } else { - if (cmp_cpufreq_data_ignore_affected(cur, c) != 0) { - ret = h_strdup_cprintf(_("%.2f-%.2f %s=%dx\n"), - ret, - khzint_to_mhzdouble(cur->cpukhz_min), - khzint_to_mhzdouble(cur->cpukhz_max), - _("MHz"), - cur_count); - cur = c; - cur_count = 1; - } else { - cur_count++; - } - } - } - ret = h_strdup_cprintf(_("%.2f-%.2f %s=%dx\n"), - ret, - khzint_to_mhzdouble(cur->cpukhz_min), - khzint_to_mhzdouble(cur->cpukhz_max), - _("MHz"), - cur_count); - - g_slist_free(all_clocks); - g_slist_free(uniq_clocks); - return ret; -} - -gchar * -processor_get_detailed_info(Processor *processor) -{ - gchar *tmp_flags, *tmp_imp, *tmp_part, *tmp_arch, *tmp_cpufreq, *tmp_topology, *ret; - tmp_flags = processor_get_capabilities_from_flags(processor->flags); - tmp_imp = (char*)arm_implementer(processor->cpu_implementer); - tmp_part = (char*)arm_part(processor->cpu_implementer, processor->cpu_part); - tmp_arch = (char*)arm_arch_more(processor->cpu_architecture); - - tmp_topology = cputopo_section_str(processor->cputopo); - tmp_cpufreq = cpufreq_section_str(processor->cpufreq); - - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" /* linux name */ - "%s=%s\n" /* decoded name */ - "%s=%s\n" /* mode */ - "%s=%.2f %s\n" /* frequency */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n" /* byte order */ - "%s" /* topology */ - "%s" /* frequency scaling */ - "[%s]\n" /* ARM */ - "%s=[%s] %s\n" /* implementer */ - "%s=[%s] %s\n" /* part */ - "%s=[%s] %s\n" /* architecture */ - "%s=%s\n" /* variant */ - "%s=%s\n" /* revision */ - "[%s]\n" /* flags */ - "%s" - "%s", /* empty */ - _("Processor"), - _("Linux Name"), processor->linux_name, - _("Decoded Name"), processor->model_name, - _("Mode"), arm_mode_str[processor->mode], - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str(), - tmp_topology, - tmp_cpufreq, - _("ARM"), - _("Implementer"), processor->cpu_implementer, (tmp_imp) ? tmp_imp : "", - _("Part"), processor->cpu_part, (tmp_part) ? tmp_part : "", - _("Architecture"), processor->cpu_architecture, (tmp_arch) ? tmp_arch : "", - _("Variant"), processor->cpu_variant, - _("Revision"), processor->cpu_revision, - _("Capabilities"), tmp_flags, - ""); - g_free(tmp_flags); - g_free(tmp_cpufreq); - g_free(tmp_topology); - return ret; -} - -gchar *processor_name(GSList *processors) { - /* compatible contains a list of compatible hardware, so be careful - * with matching order. - * ex: "ti,omap3-beagleboard-xm", "ti,omap3450", "ti,omap3"; - * matches "omap3 family" first. - * ex: "brcm,bcm2837", "brcm,bcm2836"; - * would match 2836 when it is a 2837. - */ -#define UNKSOC "(Unknown)" /* don't translate this */ - const struct { - char *search_str; - char *vendor; - char *soc; - } dt_compat_searches[] = { - { "brcm,bcm2837", "Broadcom", "BCM2837" }, - { "brcm,bcm2836", "Broadcom", "BCM2836" }, - { "brcm,bcm2835", "Broadcom", "BCM2835" }, - { "ti,omap5432", "Texas Instruments", "OMAP5432" }, - { "ti,omap5430", "Texas Instruments", "OMAP5430" }, - { "ti,omap4470", "Texas Instruments", "OMAP4470" }, - { "ti,omap4460", "Texas Instruments", "OMAP4460" }, - { "ti,omap4430", "Texas Instruments", "OMAP4430" }, - { "ti,omap3620", "Texas Instruments", "OMAP3620" }, - { "ti,omap3450", "Texas Instruments", "OMAP3450" }, - { "ti,omap5", "Texas Instruments", "OMAP5-family" }, - { "ti,omap4", "Texas Instruments", "OMAP4-family" }, - { "ti,omap3", "Texas Instruments", "OMAP3-family" }, - { "ti,omap2", "Texas Instruments", "OMAP2-family" }, - { "ti,omap1", "Texas Instruments", "OMAP1-family" }, - { "mediatek,mt6799", "MediaTek", "MT6799 Helio X30" }, - { "mediatek,mt6799", "MediaTek", "MT6799 Helio X30" }, - { "mediatek,mt6797x", "MediaTek", "MT6797X Helio X27" }, - { "mediatek,mt6797t", "MediaTek", "MT6797T Helio X25" }, - { "mediatek,mt6797", "MediaTek", "MT6797 Helio X20" }, - { "mediatek,mt6757T", "MediaTek", "MT6757T Helio P25" }, - { "mediatek,mt6757", "MediaTek", "MT6757 Helio P20" }, - { "mediatek,mt6795", "MediaTek", "MT6795 Helio X10" }, - { "mediatek,mt6755", "MediaTek", "MT6755 Helio P10" }, - { "mediatek,mt6750t", "MediaTek", "MT6750T" }, - { "mediatek,mt6750", "MediaTek", "MT6750" }, - { "mediatek,mt6753", "MediaTek", "MT6753" }, - { "mediatek,mt6752", "MediaTek", "MT6752" }, - { "mediatek,mt6738", "MediaTek", "MT6738" }, - { "mediatek,mt6737t", "MediaTek", "MT6737T" }, - { "mediatek,mt6735", "MediaTek", "MT6735" }, - { "mediatek,mt6732", "MediaTek", "MT6732" }, - { "qcom,msm8939", "Qualcomm", "Snapdragon 615"}, - { "qcom,msm", "Qualcomm", "Snapdragon-family"}, - { "nvidia,tegra" "nVidia", "Tegra-family" }, - { "bcm,", "Broadcom", UNKSOC }, - { "nvidia," "nVidia", UNKSOC }, - { "rockchip," "Rockchip", UNKSOC }, - { "ti,", "Texas Instruments", UNKSOC }, - { "qcom,", "Qualcom", UNKSOC }, - { "mediatek," "MediaTek", UNKSOC }, - { NULL, NULL } - }; - gchar *ret = NULL; - gchar *compat = NULL; - int i; - - compat = dtr_get_string("/compatible", 1); - - if (compat != NULL) { - i = 0; - while(dt_compat_searches[i].search_str != NULL) { - if (strstr(compat, dt_compat_searches[i].search_str) != NULL) { - ret = g_strdup_printf("%s %s", dt_compat_searches[i].vendor, dt_compat_searches[i].soc); - break; - } - i++; - } - } - g_free(compat); - UNKIFNULL(ret); - return ret; -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_by_counting_names(processors); -} - -gchar *processor_meta(GSList * processors) { - gchar *meta_soc = processor_name(processors); - gchar *meta_cpu_desc = processor_describe(processors); - gchar *meta_cpu_topo = processor_describe_default(processors); - gchar *meta_freq_desc = processor_frequency_desc(processors); - gchar *meta_clocks = clocks_summary(processors); - gchar *ret = NULL; - UNKIFNULL(meta_cpu_desc); - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s", - _("SOC/Package"), - _("Name"), meta_soc, - _("Description"), meta_cpu_desc, - _("Topology"), meta_cpu_topo, - _("Logical CPU Config"), meta_freq_desc, - meta_clocks ); - g_free(meta_soc); - g_free(meta_cpu_desc); - g_free(meta_cpu_topo); - g_free(meta_freq_desc); - g_free(meta_clocks); - return ret; -} - -gchar *processor_get_info(GSList * processors) -{ - Processor *processor; - gchar *ret, *tmp, *hashkey; - gchar *meta; /* becomes owned by more_info? no need to free? */ - GSList *l; - - tmp = g_strdup_printf("$CPU_META$%s=\n", _("SOC/Package Information") ); - - meta = processor_meta(processors); - moreinfo_add_with_prefix("DEV", "CPU_META", meta); - - for (l = processors; l; l = l->next) { - processor = (Processor *) l->data; - - tmp = g_strdup_printf("%s$CPU%d$%s=%.2f %s\n", - tmp, processor->id, - processor->model_name, - processor->cpu_mhz, _("MHz")); - - hashkey = g_strdup_printf("CPU%d", processor->id); - moreinfo_add_with_prefix("DEV", hashkey, - processor_get_detailed_info(processor)); - g_free(hashkey); - } - - ret = g_strdup_printf("[$ShellParam$]\n" - "ViewType=1\n" - "[Processors]\n" - "%s", tmp); - g_free(tmp); - - return ret; -} diff --git a/modules/devices/battery.c b/modules/devices/battery.c deleted file mode 100644 index cbcebb12..00000000 --- a/modules/devices/battery.c +++ /dev/null @@ -1,388 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <string.h> -#include <time.h> - -#include "hardinfo.h" -#include "devices.h" - -const struct { - gchar *key, *name; -} ups_fields[] = { - { "UPS Status", NULL }, - { "STATUS", "Status" }, - { "TIMELEFT", "Time Left" }, - { "LINEV", "Line Voltage" }, - { "LOADPCT", "Load Percent" }, - - { "UPS Battery Information", NULL }, - { "BATTV", "Battery Voltage" }, - { "BCHARGE", "Battery Charge" }, - { "BATTDATE", "Battery Date" }, - - { "UPS Information", NULL }, - { "APCMODEL", "Model" }, - { "FIRMWARE", "Firmware Version" }, - { "SERIALNO", "Serial Number" }, - { "UPSMODE", "UPS Mode" }, - { "CABLE", "Cable" }, - { "UPSNAME", "UPS Name" }, - - { "UPS Nominal Values", NULL }, - { "NOMINV", "Voltage" }, - { "NOMBATTV", "Battery Voltage" }, - { "NOMPOWER", "Power" } -}; - - -static void -__scan_battery_apcupsd(void) -{ - GHashTable *ups_data; - FILE *apcaccess; - char buffer[512], *apcaccess_path; - int i; - - apcaccess_path = find_program("apcaccess"); - if (apcaccess_path && (apcaccess = popen(apcaccess_path, "r"))) { - /* first line isn't important */ - if (fgets(buffer, 512, apcaccess)) { - /* allocate the key, value hash table */ - ups_data = g_hash_table_new(g_str_hash, g_str_equal); - - /* read up all the apcaccess' output, saving it in the key, value hash table */ - while (fgets(buffer, 512, apcaccess)) { - buffer[9] = '\0'; - - g_hash_table_insert(ups_data, - g_strdup(g_strstrip(buffer)), - g_strdup(g_strstrip(buffer + 10))); - } - - /* builds the ups info string, respecting the field order as found in ups_fields */ - for (i = 0; i < G_N_ELEMENTS(ups_fields); i++) { - if (!ups_fields[i].name) { - /* there's no name: make a group with the key as its name */ - battery_list = h_strdup_cprintf("[%s]\n", battery_list, ups_fields[i].key); - } else { - /* there's a name: adds a line */ - battery_list = h_strdup_cprintf("%s=%s\n", battery_list, - ups_fields[i].name, - g_hash_table_lookup(ups_data, ups_fields[i].key)); - } - } - - g_hash_table_destroy(ups_data); - } - - pclose(apcaccess); - } - - g_free(apcaccess_path); -} - -static void -__scan_battery_acpi(void) -{ - gchar *acpi_path; - - gchar *present = NULL; - gchar *capacity = NULL; - gchar *technology = NULL; - gchar *voltage = NULL; - gchar *model = NULL, *serial = NULL, *type = NULL; - gchar *state = NULL, *rate = NULL; - gchar *remaining = NULL; - gchar *manufacturer = NULL; - - acpi_path = g_strdup("/proc/acpi/battery"); - if (g_file_test(acpi_path, G_FILE_TEST_EXISTS)) { - GDir *acpi; - - if ((acpi = g_dir_open(acpi_path, 0, NULL))) { - const gchar *entry; - - while ((entry = g_dir_read_name(acpi))) { - gchar *path = g_strdup_printf("%s/%s/info", acpi_path, entry); - FILE *f; - gchar buffer[256]; - gdouble charge_rate = 1.0; - - f = fopen(path, "r"); - g_free(path); - - if (!f) - goto cleanup; - - while (fgets(buffer, 256, f)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - - GET_STR("present", present); - GET_STR("design capacity", capacity); - GET_STR("battery technology", technology); - GET_STR("design voltage", voltage); - GET_STR("model number", model); - GET_STR("serial number", serial); - GET_STR("battery type", type); - GET_STR("OEM info", manufacturer); - - g_strfreev(tmp); - } - fclose(f); - - path = g_strdup_printf("%s/%s/state", acpi_path, entry); - f = fopen(path, "r"); - g_free(path); - - if (!f) - goto cleanup; - - while (fgets(buffer, 256, f)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - - GET_STR("charging state", state); - GET_STR("present rate", rate); - GET_STR("remaining capacity", remaining); - - g_strfreev(tmp); - } - - fclose(f); - - const gchar *url = vendor_get_url(manufacturer); - if (url) { - char *tmp = g_strdup_printf("%s (%s)", vendor_get_name(manufacturer), url); - g_free(manufacturer); - manufacturer = tmp; - } - - if (g_str_equal(present, "yes")) { - if (remaining && capacity) - charge_rate = atof(remaining) / atof(capacity); - else - charge_rate = 0; - - battery_list = h_strdup_cprintf(_("\n[Battery: %s]\n" - "State=%s (load: %s)\n" - "Capacity=%s / %s (%.2f%%)\n" - "Battery Technology=%s (%s)\n" - "Manufacturer=%s\n" - "Model Number=%s\n" - "Serial Number=%s\n"), - battery_list, - entry, - state, rate, - remaining, capacity, charge_rate * 100.0, - technology, type, - manufacturer, - model, - serial); - } - - cleanup: - g_free(present); - g_free(capacity); - g_free(technology); - g_free(type); - g_free(model); - g_free(serial); - g_free(state); - g_free(remaining); - g_free(rate); - g_free(manufacturer); - - present = capacity = technology = type = \ - model = serial = state = remaining = rate = manufacturer = NULL; - } - - g_dir_close(acpi); - } - } - - g_free(acpi_path); -} - -static gchar * -read_contents(const gchar *base, const gchar *key) -{ - gchar *value; - gchar *path; - - path = g_strdup_printf("%s/%s", base, key); - if (!path) - return NULL; - - if (!g_file_get_contents(path, &value, NULL, NULL)) { - free(path); - return NULL; - } - - free(path); - return g_strchomp(value); -} - -static void -__scan_battery_sysfs_add_battery(const gchar *name) -{ - gchar *path = g_strdup_printf("/sys/class/power_supply/%s", name); - gchar *status, *capacity, *capacity_level, *technology, *manufacturer, - *model_name, *serial_number; - - if (!path) - return; - - status = read_contents(path, "status"); - capacity = read_contents(path, "capacity"); - capacity_level = read_contents(path, "capacity_level"); - technology = read_contents(path, "technology"); - manufacturer = read_contents(path, "manufacturer"); - model_name = read_contents(path, "model_name"); - serial_number = read_contents(path, "serial_number"); - - battery_list = h_strdup_cprintf(_("\n[Battery: %s]\n" - "State=%s\n" - "Capacity=%s / %s\n" - "Battery Technology=%s\n" - "Manufacturer=%s\n" - "Model Number=%s\n" - "Serial Number=%s\n"), - battery_list, - name, - status, - capacity, capacity_level, - technology, - manufacturer, - model_name, - serial_number); - - free(status); - free(capacity); - free(capacity_level); - free(technology); - free(manufacturer); - free(model_name); - free(serial_number); -} - -static void -__scan_battery_sysfs(void) -{ - GDir *dir; - const gchar *entry; - - dir = g_dir_open("/sys/class/power_supply", 0, NULL); - if (!dir) - return; - - while ((entry = g_dir_read_name(dir))) { - if (g_str_has_prefix(entry, "BAT")) - __scan_battery_sysfs_add_battery(entry); - } - - g_dir_close(dir); -} - -static void -__scan_battery_apm(void) -{ - FILE *procapm; - static char *sremaining = NULL, *stotal = NULL; - static unsigned int last_time = 0; - static int percentage = 0; - const char *ac_status[] = { "Battery", - "AC Power", - "Charging" }; - int ac_bat; - char apm_bios_ver[16], apm_drv_ver[16]; - char trash[10]; - - if ((procapm = fopen("/proc/apm", "r"))) { - int old_percentage = percentage; - - (void)fscanf(procapm, "%s %s %s 0x%x %s %s %d%%", - apm_drv_ver, apm_bios_ver, trash, - &ac_bat, trash, trash, &percentage); - fclose(procapm); - - if (last_time == 0) { - last_time = time(NULL); - sremaining = stotal = NULL; - } - - if (old_percentage - percentage > 0) { - if (sremaining && stotal) { - g_free(sremaining); - g_free(stotal); - } - - int secs_remaining = (time(NULL) - last_time) * percentage / - (old_percentage - percentage); - sremaining = seconds_to_string(secs_remaining); - stotal = seconds_to_string((secs_remaining * 100) / percentage); - - last_time = time(NULL); - } - } else { - return; - } - - if (stotal && sremaining) { - battery_list = h_strdup_cprintf(_("\n[Battery (APM)]\n" - "Charge=%d%%\n" - "Remaining Charge=%s of %s\n" - "Using=%s\n" - "APM driver version=%s\n" - "APM BIOS version=%s\n"), - battery_list, - percentage, - sremaining, stotal, - ac_status[ac_bat], - apm_drv_ver, apm_bios_ver); - } else { - battery_list = h_strdup_cprintf(_("\n[Battery (APM)]\n" - "Charge=%d%%\n" - "Using=%s\n" - "APM driver version=%s\n" - "APM BIOS version=%s\n"), - battery_list, - percentage, - ac_status[ac_bat], - apm_drv_ver, apm_bios_ver); - - } -} - -void -scan_battery_do(void) -{ - g_free(battery_list); - battery_list = g_strdup(""); - - __scan_battery_sysfs(); - __scan_battery_acpi(); - __scan_battery_apm(); - __scan_battery_apcupsd(); - - if (*battery_list == '\0') { - g_free(battery_list); - - battery_list = g_strdup(_("[No batteries]\n" - "No batteries found on this system=\n")); - } -} diff --git a/modules/devices/devicetree.c b/modules/devices/devicetree.c deleted file mode 100644 index 4f3c85a2..00000000 --- a/modules/devices/devicetree.c +++ /dev/null @@ -1,304 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* - * Device Tree support by Burt P. <pburt0@gmail.com> - * Sources: - * http://elinux.org/Device_Tree_Usage - * http://elinux.org/Device_Tree_Mysteries - */ -#include <unistd.h> -#include <sys/types.h> -#include <stdint.h> -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" -#include "dt_util.h" - -/* These should really go into CMakeLists.txt */ -#if defined(__arm__) -#include "devicetree/rpi_data.c" -#elif defined(__powerpc__) -#include "devicetree/pmac_data.c" -#endif - -gchar *dtree_info = NULL; - -static gchar *get_node(dtr *dt, char *np) { - gchar *nodes = NULL, *props = NULL, *ret = NULL; - gchar *tmp = NULL, *pstr = NULL, *lstr = NULL; - gchar *dir_path; - gchar *node_path; - const gchar *fn; - GDir *dir; - dtr_obj *node, *child; - - props = g_strdup_printf("[%s]\n", _("Properties") ); - nodes = g_strdup_printf("[%s]\n", _("Children") ); - node = dtr_obj_read(dt, np); - dir_path = dtr_obj_full_path(node); - - dir = g_dir_open(dir_path, 0 , NULL); - if (dir) { - while((fn = g_dir_read_name(dir)) != NULL) { - child = dtr_get_prop_obj(dt, node, fn); - pstr = hardinfo_clean_value(dtr_str(child), 1); - lstr = hardinfo_clean_label(fn, 0); - if (dtr_obj_type(child) == DT_NODE) { - tmp = g_strdup_printf("%s%s=%s\n", - nodes, lstr, pstr); - g_free(nodes); - nodes = tmp; - } else { - tmp = g_strdup_printf("%s%s=%s\n", - props, lstr, pstr); - g_free(props); - props = tmp; - } - dtr_obj_free(child); - g_free(pstr); - g_free(lstr); - } - } - g_dir_close(dir); - g_free(dir_path); - - lstr = dtr_obj_alias(node); - pstr = dtr_obj_symbol(node); - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s%s", - _("Node"), - _("Node Path"), dtr_obj_path(node), - _("Alias"), (lstr != NULL) ? lstr : _("(None)"), - _("Symbol"), (pstr != NULL) ? pstr : _("(None)"), - props, nodes); - - dtr_obj_free(node); - g_free(props); - g_free(nodes); - - return ret; -} - -/* different from dtr_get_string() in that it re-uses the existing dt */ -static char *get_dt_string(dtr *dt, char *path, gboolean decode) { - char *ret; - - if (decode) { - dtr_obj *obj = dtr_get_prop_obj(dt, NULL, path); - - ret = dtr_str(obj); - - dtr_obj_free(obj); - } else { - ret = dtr_get_prop_str(dt, NULL, path); - } - - return ret; -} - -static gchar *get_summary(dtr *dt) { - char *model = NULL, *compat = NULL; - char *ret = NULL; - - model = get_dt_string(dt, "/model", 0); - compat = get_dt_string(dt, "/compatible", 1); - UNKIFNULL(model); - EMPIFNULL(compat); - -#if defined(__arm__) - /* Expand on the DT information from known machines, like RPi. - * RPi stores a revision value in /proc/cpuinfo that can be used - * to look up details. This is just a nice place to pull it all - * together for DT machines, with a nice fallback. - * PPC Macs could be handled this way too. They store - * machine identifiers in /proc/cpuinfo. */ - if (strstr(model, "Raspberry Pi") - || strstr(compat, "raspberrypi")) { - gchar *gpu_compat = get_dt_string(dt, "/soc/gpu/compatible", 1); - gchar *rpi_details = rpi_board_details(); - gchar *basic_info; - - basic_info = g_strdup_printf( - "[%s]\n" - "%s=%s\n" - "%s=%s\n", - _("Platform"), - _("Compatible"), compat, - _("GPU-compatible"), gpu_compat); - - if (rpi_details) { - ret = g_strconcat(rpi_details, basic_info, NULL); - - g_free(rpi_details); - } else { - gchar *serial_number = get_dt_string(dt, "/serial-number", 1); - - ret = g_strdup_printf( - "[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s", - _("Raspberry Pi or Compatible"), - _("Model"), model, - _("Serial Number"), serial_number, - _("RCode"), _("No revision code available; unable to lookup model details."), - basic_info); - - g_free(serial_number); - } - - g_free(gpu_compat); - g_free(basic_info); - } -#endif - -#if defined(__powerpc__) - /* Power Macintosh */ - if (strstr(compat, "PowerBook") != NULL - || strstr(compat, "MacRISC") != NULL - || strstr(compat, "Power Macintosh") != NULL) { - gchar *mac_details = ppc_mac_details(); - - if (mac_details) { - gchar *serial_number = get_dt_string(dt, "/serial-number", 1); - - ret = g_strdup_printf( - "%s[%s]\n" - "%s=%s\n", - mac_details, - _("More"), - _("Serial Number"), serial_number); - - free(mac_details); - free(serial_number); - } - } -#endif - - /* fallback */ - if (!ret) { - gchar *serial_number = get_dt_string(dt, "/serial-number", 1); - EMPIFNULL(serial_number); - ret = g_strdup_printf( - "[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n", - _("Board"), - _("Model"), model, - _("Serial Number"), serial_number, - _("Compatible"), compat); - free(serial_number); - } - - free(model); - free(compat); - - return ret; -} - -static void mi_add(const char *key, const char *value) { - gchar *ckey, *rkey; - - ckey = hardinfo_clean_label(key, 0); - rkey = g_strdup_printf("%s:%s", "DTREE", ckey); - - dtree_info = h_strdup_cprintf("$%s$%s=\n", dtree_info, rkey, ckey); - moreinfo_add_with_prefix("DEV", rkey, g_strdup(value)); - - g_free(ckey); - g_free(rkey); -} - -static void add_keys(dtr *dt, char *np) { - gchar *dir_path, *dt_path; - gchar *ftmp, *ntmp; - gchar *n_info; - const gchar *fn; - GDir *dir; - dtr_obj *obj; - - /* add self */ - obj = dtr_obj_read(dt, np); - dt_path = dtr_obj_path(obj); - n_info = get_node(dt, dt_path); - mi_add(dt_path, n_info); - - dir_path = g_strdup_printf("%s/%s", dtr_base_path(dt), np); - dir = g_dir_open(dir_path, 0 , NULL); - if (dir) { - while((fn = g_dir_read_name(dir)) != NULL) { - ftmp = g_strdup_printf("%s/%s", dir_path, fn); - if ( g_file_test(ftmp, G_FILE_TEST_IS_DIR) ) { - if (strcmp(np, "/") == 0) - ntmp = g_strdup_printf("/%s", fn); - else - ntmp = g_strdup_printf("%s/%s", np, fn); - add_keys(dt, ntmp); - g_free(ntmp); - } - g_free(ftmp); - } - } - g_dir_close(dir); -} - -static char *msg_section(dtr *dt, int dump) { - gchar *aslbl = NULL; - gchar *messages = dtr_messages(dt); - gchar *ret = g_strdup_printf("[%s]\n", _("Messages")); - gchar **lines = g_strsplit(messages, "\n", 0); - int i = 0; - while(lines[i] != NULL) { - aslbl = hardinfo_clean_label(lines[i], 0); - ret = appf(ret, "%s=\n", aslbl); - g_free(aslbl); - i++; - } - g_strfreev(lines); - if (dump) - printf("%s", messages); - g_free(messages); - return ret; -} - -void __scan_dtree() -{ - dtr *dt = dtr_new(NULL); - gchar *summary = get_summary(dt); - gchar *maps = dtr_maps_info(dt); - gchar *messages = NULL; - - dtree_info = g_strdup("[Device Tree]\n"); - mi_add("Summary", summary); - mi_add("Maps", maps); - - if(dtr_was_found(dt)) - add_keys(dt, "/"); - messages = msg_section(dt, 0); - mi_add("Messages", messages); - - g_free(summary); - g_free(maps); - g_free(messages); - dtr_free(dt); -} diff --git a/modules/devices/devicetree/pmac_data.c b/modules/devices/devicetree/pmac_data.c deleted file mode 100644 index b236aef1..00000000 --- a/modules/devices/devicetree/pmac_data.c +++ /dev/null @@ -1,98 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "cpu_util.h" /* for PROC_CPUINFO */ - -static gchar *ppc_mac_details(void) { - int i = 0; - gchar *ret = NULL; - gchar *platform = NULL; - gchar *model = NULL; - gchar *machine = NULL; - gchar *motherboard = NULL; - gchar *detected_as = NULL; - gchar *pmac_flags = NULL; - gchar *l2_cache = NULL; - gchar *pmac_gen = NULL; - - FILE *cpuinfo; - gchar buffer[128]; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - if (tmp[1] == NULL) { - g_strfreev(tmp); - continue; - } - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - get_str("platform", platform); - get_str("model", model); - get_str("machine", machine); - get_str("motherboard", motherboard); - get_str("detected as", detected_as); - get_str("pmac flags", pmac_flags); - get_str("L2 cache", l2_cache); - get_str("pmac-generation", pmac_gen); - } - fclose(cpuinfo); - - if (machine == NULL) - goto pmd_exit; - - UNKIFNULL(platform); - UNKIFNULL(model); - UNKIFNULL(motherboard); - UNKIFNULL(detected_as); - UNKIFNULL(pmac_flags); - UNKIFNULL(l2_cache); - UNKIFNULL(pmac_gen); - - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n", - _("Apple Power Macintosh"), - _("Platform"), platform, - _("Model"), model, - _("Machine"), machine, - _("Motherboard"), motherboard, - _("Detected as"), detected_as, - _("PMAC Flags"), pmac_flags, - _("L2 Cache"), l2_cache, - _("PMAC Generation"), pmac_gen ); - -pmd_exit: - g_free(platform); - g_free(model); - g_free(machine); - g_free(motherboard); - g_free(detected_as); - g_free(pmac_flags); - g_free(l2_cache); - g_free(pmac_gen); - return ret; -} diff --git a/modules/devices/devicetree/rpi_data.c b/modules/devices/devicetree/rpi_data.c deleted file mode 100644 index d0132e3a..00000000 --- a/modules/devices/devicetree/rpi_data.c +++ /dev/null @@ -1,166 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> - * This file from: rpiz - https://github.com/bp0/rpiz - * Copyright (C) 2017 Burt P. <pburt0@gmail.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -static char unk[] = "(Unknown)"; - -/* information table from: http://elinux.org/RPi_HardwareHistory */ -static struct { - char *value, *intro, *model, *pcb, *mem, *mfg, *soc; -} rpi_boardinfo[] = { -/* Value Introduction Model Name PCB rev. Memory(spec) Manufacturer SOC(spec) * - * Raspberry Pi %s */ - { unk, unk, unk, unk, unk, unk, NULL }, - { "Beta", "Q1 2012", "B (Beta)", unk, "256MB", "(Beta board)", NULL }, - { "0002", "Q1 2012", "B", "1.0", "256MB", unk, "BCM2835" }, - { "0003", "Q3 2012", "B (ECN0001)", "1.0", "256MB", "(Fuses mod and D14 removed)", NULL }, - { "0004", "Q3 2012", "B", "2.0", "256MB", "Sony", NULL }, - { "0005", "Q4 2012", "B", "2.0", "256MB", "Qisda", NULL }, - { "0006", "Q4 2012", "B", "2.0", "256MB", "Egoman", NULL }, - { "0007", "Q1 2013", "A", "2.0", "256MB", "Egoman", NULL }, - { "0008", "Q1 2013", "A", "2.0", "256MB", "Sony", NULL }, - { "0009", "Q1 2013", "A", "2.0", "256MB", "Qisda", NULL }, - { "000d", "Q4 2012", "B", "2.0", "512MB", "Egoman", NULL }, - { "000e", "Q4 2012", "B", "2.0", "512MB", "Sony", NULL }, - { "000f", "Q4 2012", "B", "2.0", "512MB", "Qisda", NULL }, - { "0010", "Q3 2014", "B+", "1.0", "512MB", "Sony", NULL }, - { "0011", "Q2 2014", "Compute Module 1", "1.0", "512MB", "Sony", NULL }, - { "0012", "Q4 2014", "A+", "1.1", "256MB", "Sony", NULL }, - { "0013", "Q1 2015", "B+", "1.2", "512MB", unk, NULL }, - { "0014", "Q2 2014", "Compute Module 1", "1.0", "512MB", "Embest", NULL }, - { "0015", unk, "A+", "1.1", "256MB/512MB", "Embest", NULL }, - { "a01040", unk, "2 Model B", "1.0", "1GB", "Sony", "BCM2836" }, - { "a01041", "Q1 2015", "2 Model B", "1.1", "1GB", "Sony", "BCM2836" }, - { "a21041", "Q1 2015", "2 Model B", "1.1", "1GB", "Embest", "BCM2836" }, - { "a22042", "Q3 2016", "2 Model B", "1.2", "1GB", "Embest", "BCM2837" }, /* (with BCM2837) */ - { "900021", "Q3 2016", "A+", "1.1", "512MB", "Sony", NULL }, - { "900032", "Q2 2016?", "B+", "1.2", "512MB", "Sony", NULL }, - { "900092", "Q4 2015", "Zero", "1.2", "512MB", "Sony", NULL }, - { "900093", "Q2 2016", "Zero", "1.3", "512MB", "Sony", NULL }, - { "920093", "Q4 2016?", "Zero", "1.3", "512MB", "Embest", NULL }, - { "9000c1", "Q1 2017", "Zero W", "1.1", "512MB", "Sony", NULL }, - { "a02082", "Q1 2016", "3 Model B", "1.2", "1GB", "Sony", "BCM2837" }, - { "a020a0", "Q1 2017", "Compute Module 3 or CM3 Lite", "1.0", "1GB", "Sony", NULL }, - { "a22082", "Q1 2016", "3 Model B", "1.2", "1GB", "Embest", "BCM2837" }, - { "a32082", "Q4 2016", "3 Model B", "1.2", "1GB", "Sony Japan", NULL }, - { NULL, NULL, NULL, NULL, NULL, NULL, NULL } -}; - - -/* return number of chars to skip */ -static int rpi_ov_check(const char *r_code) { - /* sources differ. prefix is either 1000... or just 1... */ - //if (strncmp(r, "1000", 4) == 0) - // return 4; - if (strncmp(r_code, "1", 1) == 0) - return 1; - return 0; -} - -static int rpi_code_match(const char* code0, const char* code1) { - int c0, c1; - if (code0 == NULL || code1 == NULL) return 0; - c0 = strtol(code0, NULL, 16); - c1 = strtol(code1, NULL, 16); - if (c0 && c1) - return (c0 == c1) ? 1 : 0; - else - return (strcmp(code0, code1) == 0) ? 1 : 0; -} - -static int rpi_find_board(const char *r_code) { - int i = 0; - char *r = (char*)r_code; - if (r_code == NULL) - return 0; - /* ignore the overvolt prefix */ - r += rpi_ov_check(r_code); - while (rpi_boardinfo[i].value != NULL) { - if (rpi_code_match(r, rpi_boardinfo[i].value)) - return i; - - i++; - } - return 0; -} - -/* ------------------------- */ - -#include "cpu_util.h" /* for PROC_CPUINFO */ - -static gchar *rpi_board_details(void) { - int i = 0; - gchar *ret = NULL; - gchar *soc = NULL; - gchar *serial = NULL; - gchar *revision = NULL; - int ov = 0; - FILE *cpuinfo; - gchar buffer[128]; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - if (tmp[1] == NULL) { - g_strfreev(tmp); - continue; - } - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - get_str("Revision", revision); - get_str("Hardware", soc); - get_str("Serial", serial); - } - fclose(cpuinfo); - - if (revision == NULL || soc == NULL) { - g_free(soc); - g_free(revision); - return NULL; - } - - ov = rpi_ov_check(revision); - i = rpi_find_board(revision); - ret = g_strdup_printf("[%s]\n" - "%s=%s %s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n", - _("Raspberry Pi"), - _("Board Name"), _("Raspberry Pi"), rpi_boardinfo[i].model, - _("PCB Revision"), rpi_boardinfo[i].pcb, - _("Introduction"), rpi_boardinfo[i].intro, - _("Manufacturer"), rpi_boardinfo[i].mfg, - _("RCode"), rpi_boardinfo[i].value, - _("SOC (spec)"), rpi_boardinfo[i].soc, - _("Memory (spec)"), rpi_boardinfo[i].mem, - _("Serial Number"), serial, - _("Permanent overvolt bit"), (ov) ? C_("rpi-ov-bit", "Set") : C_("rpi-ov-bit", "Not set") ); - - g_free(soc); - g_free(revision); - return ret; -} diff --git a/modules/devices/devmemory.c b/modules/devices/devmemory.c deleted file mode 100644 index 29094dd8..00000000 --- a/modules/devices/devmemory.c +++ /dev/null @@ -1,120 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <string.h> -#include "devices.h" - -GHashTable *memlabels = NULL; - -void scan_memory_do(void) -{ - gchar **keys, *tmp, *tmp_label, *trans_val; - static gint offset = -1; - gint i; - - if (offset == -1) { - /* gah. linux 2.4 adds three lines of data we don't need in - /proc/meminfo */ - gchar *os_kernel = module_call_method("computer::getOSKernel"); - if (os_kernel) { - offset = strstr(os_kernel, "Linux 2.4") ? 3 : 0; - g_free(os_kernel); - } else { - offset = 0; - } - } - - g_file_get_contents("/proc/meminfo", &meminfo, NULL, NULL); - - keys = g_strsplit(meminfo, "\n", 0); - - g_free(meminfo); - g_free(lginterval); - - meminfo = g_strdup(""); - lginterval = g_strdup(""); - - for (i = offset; keys[i]; i++) { - gchar **newkeys = g_strsplit(keys[i], ":", 0); - - if (!newkeys[0]) { - g_strfreev(newkeys); - break; - } - - g_strstrip(newkeys[0]); - g_strstrip(newkeys[1]); - - /* try to find a localizable label */ - tmp = g_hash_table_lookup(memlabels, newkeys[0]); - if (tmp) - tmp_label = _(tmp); - else - tmp_label = ""; /* or newkeys[0] */ - /* although it doesn't matter... */ - - if (strstr(newkeys[1], "kB")) { - trans_val = g_strdup_printf("%d %s", atoi(newkeys[1]), _("KiB") ); - } else { - trans_val = strdup(newkeys[1]); - } - - moreinfo_add_with_prefix("DEV", newkeys[0], g_strdup(trans_val)); - - tmp = g_strconcat(meminfo, newkeys[0], "=", trans_val, "|", tmp_label, "\n", NULL); - g_free(meminfo); - meminfo = tmp; - - g_free(trans_val); - - tmp = g_strconcat(lginterval, - "UpdateInterval$", newkeys[0], "=1000\n", NULL); - g_free(lginterval); - lginterval = tmp; - - g_strfreev(newkeys); - } - g_strfreev(keys); -} - -void init_memory_labels(void) -{ - static const struct { - char *proc_label; - char *real_label; - } proc2real[] = { - { "MemTotal", N_("Total Memory") }, - { "MemFree", N_("Free Memory") }, - { "SwapCached", N_("Cached Swap") }, - { "HighTotal", N_("High Memory") }, - { "HighFree", N_("Free High Memory") }, - { "LowTotal", N_("Low Memory") }, - { "LowFree", N_("Free Low Memory") }, - { "SwapTotal", N_("Virtual Memory") }, - { "SwapFree", N_("Free Virtual Memory") }, - { NULL }, - }; - gint i; - - memlabels = g_hash_table_new(g_str_hash, g_str_equal); - - for (i = 0; proc2real[i].proc_label; i++) { - g_hash_table_insert(memlabels, proc2real[i].proc_label, - _(proc2real[i].real_label)); - } -} diff --git a/modules/devices/dmi.c b/modules/devices/dmi.c deleted file mode 100644 index b25cfe21..00000000 --- a/modules/devices/dmi.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* - * DMI support based on patch by Stewart Adam <s.adam@diffingo.com> - */ -#include <unistd.h> -#include <sys/types.h> - -#include "devices.h" -#include "dmi_util.h" - -typedef struct _DMIInfo DMIInfo; - -struct _DMIInfo { - const gchar *name; - const gchar *id_str; - int group; -}; - -DMIInfo dmi_info_table[] = { - { N_("Product"), NULL, 1 }, - { N_("Name"), "system-product-name", 0 }, - { N_("Family"), "system-product-family", 0 }, - { N_("Vendor"), "system-manufacturer", 0 }, - { N_("Version"), "system-version", 0 }, - { N_("BIOS"), NULL, 1 }, - { N_("Date"), "bios-release-date", 0 }, - { N_("Vendor"), "bios-vendor", 0 }, - { N_("Version"), "bios-version", 0 }, - { N_("Board"), NULL, 1 }, - { N_("Name"), "baseboard-product-name", 0 }, - { N_("Vendor"), "baseboard-manufacturer", 0 }, - { N_("Version"), "baseboard-version", 0 }, - { N_("Serial Number"), "baseboard-serial-number", 0 }, - { N_("Asset Tag"), "baseboard-asset-tag", 0 }, - { N_("Chassis"), NULL, 1 }, - { N_("Vendor"), "chassis-manufacturer", 0 }, - { N_("Type"), "chassis-type", 0 }, - { N_("Version"), "chassis-version", 0 }, - { N_("Serial Number"), "chassis-serial-number", 0 }, - { N_("Asset Tag"), "chassis-asset-tag", 0 }, -}; - -gchar *dmi_info = NULL; - -static void add_to_moreinfo(const char *group, const char *key, char *value) -{ - char *new_key = g_strconcat("DMI:", group, ":", key, NULL); - moreinfo_add_with_prefix("DEV", new_key, g_strdup(g_strstrip(value))); -} - -gboolean dmi_get_info() -{ - const gchar *group = NULL; - DMIInfo *info; - gboolean dmi_succeeded = FALSE; - gint i; - gchar *value; - - if (dmi_info) { - g_free(dmi_info); - dmi_info = NULL; - } - - for (i = 0; i < G_N_ELEMENTS(dmi_info_table); i++) { - info = &dmi_info_table[i]; - - if (info->group) { - group = info->name; - dmi_info = h_strdup_cprintf("[%s]\n", dmi_info, _(info->name) ); - } else if (group && info->id_str) { - if (strcmp(info->id_str, "chassis-type") == 0) - value = dmi_chassis_type_str(-1, 1); - else - value = dmi_get_str(info->id_str); - - if (value != NULL) { - add_to_moreinfo(group, info->name, value); - - const gchar *url = vendor_get_url(value); - if (url) { - const gchar *vendor = vendor_get_name(value); - dmi_info = h_strdup_cprintf("%s=%s (%s, %s)\n", - dmi_info, - _(info->name), - value, - vendor, url); - } else { - dmi_info = h_strdup_cprintf("%s=%s\n", - dmi_info, - _(info->name), - value); - } - dmi_succeeded = TRUE; - } else { - dmi_info = h_strdup_cprintf("%s=%s\n", - dmi_info, - _(info->name), - (getuid() == 0) - ? _("(Not available)") - : _("(Not available; Perhaps try running HardInfo as root.)") ); - } - } - } - - if (!dmi_succeeded) { - g_free(dmi_info); - dmi_info = NULL; - } - - return dmi_succeeded; -} - -void __scan_dmi() -{ - gboolean dmi_ok; - - dmi_ok = dmi_get_info(); - - if (!dmi_ok) { - dmi_info = g_strdup("[No DMI information]\n" - "There was an error retrieving the information.=\n" - "Please try running HardInfo as root.=\n"); - } -} diff --git a/modules/devices/ia64/processor.c b/modules/devices/ia64/processor.c deleted file mode 100644 index c4d06a71..00000000 --- a/modules/devices/ia64/processor.c +++ /dev/null @@ -1,215 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -GSList * -processor_scan(void) -{ - GSList *procs = NULL; - Processor *processor = NULL; - FILE *cpuinfo; - gchar buffer[128]; - gchar *rep_pname = NULL; - GSList *pi = NULL; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - -#define CHECK_FOR(k) (g_str_has_prefix(tmp[0], k)) - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - } else { - g_strfreev(tmp); - continue; - } - - get_str("Processor", rep_pname); - - if ( CHECK_FOR("processor") ) { - /* finish previous */ - if (processor) { - procs = g_slist_append(procs, processor); - } - - /* start next */ - processor = g_new0(Processor, 1); - processor->id = atol(tmp[1]); - - if (rep_pname) - processor->model_name = g_strdup(rep_pname); - - g_strfreev(tmp); - continue; - } - - if (!processor && - ( CHECK_FOR("vendor") - || CHECK_FOR("arch") - || CHECK_FOR("family") ) ) { - - /* single proc/core may not have "processor : n" */ - processor = g_new0(Processor, 1); - processor->id = 0; - - if (rep_pname) - processor->model_name = g_strdup(rep_pname); - } - - if (processor) { - get_str("vendor", processor->vendor_id); - get_str("archrev", processor->archrev); - get_str("arch", processor->arch); - get_str("family", processor->family); - get_str("features", processor->features); - get_int("model", processor->model); - get_int("revision", processor->revision); - get_float("BogoMIPS", processor->bogomips); - get_float("cpu MHz", processor->cpu_mhz); - get_int("cpu regs", processor->cpu_regs); - } - g_strfreev(tmp); - } - - if (processor) - procs = g_slist_append(procs, processor); - - g_free(rep_pname); - fclose(cpuinfo); - - /* TODO: redup */ - - /* data not from /proc/cpuinfo */ - for (pi = procs; pi; pi = pi->next) { - processor = (Processor *) pi->data; - - /* strings can't be null or segfault later */ - STRIFNULL(processor->model_name, _("IA64 Processor") ); - UNKIFNULL(processor->vendor_id); - STRIFNULL(processor->arch, "IA-64"); - STRIFNULL(processor->archrev, "0"); - UNKIFNULL(processor->family); - UNKIFNULL(processor->features); - - /* topo & freq */ - processor->cpufreq = cpufreq_new(processor->id); - processor->cputopo = cputopo_new(processor->id); - - if (processor->cpufreq->cpukhz_max) - processor->cpu_mhz = processor->cpufreq->cpukhz_max / 1000; - - } - - return procs; -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_detailed_info(Processor *processor) -{ - gchar *tmp_cpufreq, *tmp_topology, *ret; - - tmp_topology = cputopo_section_str(processor->cputopo); - tmp_cpufreq = cpufreq_section_str(processor->cpufreq); - - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" /* name */ - "%s=%s\n" /* vendor */ - "%s=%s\n" /* arch */ - "%s=%s\n" /* archrev */ - "%s=%s\n" /* family */ - "%s=%d\n" /* model no. */ - "%s=%d\n" /* revision */ - "%s=%.2f %s\n" /* frequency */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n" /* byte order */ - "%s=%d\n" /* regs */ - "%s=%s\n" /* features */ - "%s" /* topology */ - "%s" /* frequency scaling */ - "%s",/* empty */ - _("Processor"), - _("Name"), processor->model_name, - _("Vendor"), processor->vendor_id, - _("Architecture"), processor->arch, - _("Architecture Revision"), processor->archrev, - _("Family"), processor->family, - _("Model"), processor->model, - _("Revision"), processor->revision, - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str(), - _("CPU regs"), processor->cpu_regs, - _("Features"), processor->features, - tmp_topology, - tmp_cpufreq, - ""); - g_free(tmp_cpufreq); - g_free(tmp_topology); - return ret; -} - -gchar *processor_get_info(GSList * processors) -{ - Processor *processor; - - if (g_slist_length(processors) > 1) { - gchar *ret, *tmp, *hashkey; - GSList *l; - - tmp = g_strdup(""); - - for (l = processors; l; l = l->next) { - processor = (Processor *) l->data; - - tmp = g_strdup_printf("%s$CPU%d$%s=%.2f %s\n", - tmp, processor->id, - processor->model_name, - processor->cpu_mhz, _("MHz")); - - hashkey = g_strdup_printf("CPU%d", processor->id); - moreinfo_add_with_prefix("DEV", hashkey, - processor_get_detailed_info(processor)); - g_free(hashkey); - } - - ret = g_strdup_printf("[$ShellParam$]\n" - "ViewType=1\n" - "[Processors]\n" - "%s", tmp); - g_free(tmp); - - return ret; - } - - processor = (Processor *) processors->data; - return processor_get_detailed_info(processor); -} diff --git a/modules/devices/inputdevices.c b/modules/devices/inputdevices.c deleted file mode 100644 index cf1728a9..00000000 --- a/modules/devices/inputdevices.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <string.h> - -#include "hardinfo.h" -#include "devices.h" - -gchar *input_icons = NULL; - -static struct { - char *name; - char *icon; -} input_devices[] = { - { "Keyboard", "keyboard.png" }, - { "Joystick", "joystick.png" }, - { "Mouse", "mouse.png" }, - { "Speaker", "audio.png" }, - { "Unknown", "module.png" }, -}; - -void -__scan_input_devices(void) -{ - FILE *dev; - gchar buffer[1024]; - gchar *tmp, *name = NULL, *phys = NULL; - gint bus = 0, vendor = 0, product = 0, version = 0; - int d = 0, n = 0; - - dev = fopen("/proc/bus/input/devices", "r"); - if (!dev) - return; - - if (input_list) { - moreinfo_del_with_prefix("DEV:INP"); - g_free(input_list); - g_free(input_icons); - } - input_list = g_strdup(""); - input_icons = g_strdup(""); - - while (fgets(buffer, sizeof(buffer), dev)) { - tmp = buffer; - - switch (*tmp) { - case 'N': - tmp = strreplacechr(tmp + strlen("N: Name="), "=", ':'); - name = g_strdup(tmp); - remove_quotes(name); - break; - case 'P': - phys = g_strdup(tmp + strlen("P: Phys=")); - break; - case 'I': - sscanf(tmp, "I: Bus=%x Vendor=%x Product=%x Version=%x", - &bus, &vendor, &product, &version); - break; - case 'H': - if (strstr(tmp, "kbd")) - d = 0; //INPUT_KEYBOARD; - else if (strstr(tmp, "js")) - d = 1; //INPUT_JOYSTICK; - else if (strstr(tmp, "mouse")) - d = 2; //INPUT_MOUSE; - else - d = 4; //INPUT_UNKNOWN; - break; - case '\n': - if (name && strstr(name, "PC Speaker")) { - d = 3; // INPUT_PCSPKR - } - - tmp = g_strdup_printf("INP%d", ++n); - input_list = h_strdup_cprintf("$%s$%s=\n", - input_list, - tmp, name); - input_icons = h_strdup_cprintf("Icon$%s$%s=%s\n", - input_icons, - tmp, name, - input_devices[d].icon); - - const gchar *v_url = (gchar*)vendor_get_url(name); - const gchar *v_name = (gchar*)vendor_get_name(name); - gchar *v_str = NULL; - if (v_url != NULL) - v_str = g_strdup_printf("[0x%x] %s (%s)", vendor, v_name, v_url); - else - v_str = g_strdup_printf("0x%x", vendor); - v_str = hardinfo_clean_value(v_str, 1); - name = hardinfo_clean_value(name, 1); - - gchar *strhash = g_strdup_printf("[%s]\n" - /* Name */ "%s=%s\n" - /* Type */ "%s=%s\n" - /* Bus */ "%s=0x%x\n" - /* Vendor */ "%s=%s\n" - /* Product */"%s=0x%x\n" - /* Version */"%s=0x%x\n", - _("Device Information"), - _("Name"), name, - _("Type"), input_devices[d].name, - _("Bus"), bus, - _("Vendor"), v_str, - _("Product"), product, - _("Version"), version ); - - if (phys && phys[1] != 0) { - strhash = h_strdup_cprintf("%s=%s\n", strhash, _("Connected to"), phys); - } - - if (phys && strstr(phys, "ir")) { - strhash = h_strdup_cprintf("%s=%s\n", strhash, _("InfraRed port"), _("Yes") ); - } - - moreinfo_add_with_prefix("DEV", tmp, strhash); - g_free(tmp); - g_free(v_str); - g_free(phys); - g_free(name); - } - } - - fclose(dev); -} diff --git a/modules/devices/m68k/processor.c b/modules/devices/m68k/processor.c deleted file mode 100644 index e030732a..00000000 --- a/modules/devices/m68k/processor.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -GSList * -processor_scan(void) -{ - Processor *processor; - FILE *cpuinfo; - gchar buffer[128]; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - - processor = g_new0(Processor, 1); - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - - get_str("CPU", processor->model_name); - get_str("MMU", processor->mmu_name); - get_str("FPU", processor->fpu_name); - get_float("Clocking", processor->cpu_mhz); - get_float("BogoMips", processor->bogomips); - get_str("Calibration", processor->calibration); - } - g_strfreev(tmp); - } - - gchar *tmp; - tmp = g_strconcat("Motorola ", processor->model_name, NULL); - g_free(processor->model_name); - processor->model_name = tmp; - - fclose(cpuinfo); - - return g_slist_append(NULL, processor); -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_info(GSList *processors) -{ - Processor *processor = (Processor *)processors->data; - - return g_strdup_printf("[%s]\n" - "%s=%s\n" /* cpu */ - "%s=%s\n" /* mmu */ - "%s=%s\n" /* fpu */ - "%s=%.2f %s\n" /* frequency */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n" /* byte order */ - "%s=%s\n", /* calibration */ - _("Processor"), - _("Model"), processor->model_name, - _("MMU"), processor->mmu_name, - _("FPU"), processor->fpu_name, - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str(), - _("Calibration"), processor->calibration - ); -} diff --git a/modules/devices/mips/processor.c b/modules/devices/mips/processor.c deleted file mode 100644 index b31af7dd..00000000 --- a/modules/devices/mips/processor.c +++ /dev/null @@ -1,81 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -GSList * -processor_scan(void) -{ - Processor *processor; - FILE *cpuinfo; - gchar buffer[128]; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - - processor = g_new0(Processor, 1); - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - - get_str("system type", processor->vendor_id); - get_str("cpu model", processor->model_name); - get_float("cpu MHz", processor->cpu_mhz); - get_float("BogoMIPS", processor->bogomips); - } - g_strfreev(tmp); - } - - fclose(cpuinfo); - - return g_slist_append(NULL, processor); -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_info(GSList *processors) -{ - Processor *processor = (Processor *)processors->data; - - return g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%.2f %s\n" /* frequency */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n", /* byte order */ - _("Processor"), - _("Model"), processor->model_name, - _("System Type"), processor->vendor_id, - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str() - ); -} diff --git a/modules/devices/parisc/processor.c b/modules/devices/parisc/processor.c deleted file mode 100644 index 9ca38d12..00000000 --- a/modules/devices/parisc/processor.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -GSList * -processor_scan(void) -{ - GSList *procs = NULL; - Processor *processor = NULL; - FILE *cpuinfo; - gchar buffer[128]; - gchar *rep_pname = NULL; - GSList *pi = NULL; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - -#define CHECK_FOR(k) (g_str_has_prefix(tmp[0], k)) - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - } else { - g_strfreev(tmp); - continue; - } - - get_str("Processor", rep_pname); - - if ( CHECK_FOR("processor") ) { - /* finish previous */ - if (processor) { - procs = g_slist_append(procs, processor); - } - - /* start next */ - processor = g_new0(Processor, 1); - processor->id = atol(tmp[1]); - - if (rep_pname) - processor->model_name = g_strdup(rep_pname); - - g_strfreev(tmp); - continue; - } - - if (!processor && - ( CHECK_FOR("cpu family") - || CHECK_FOR("cpu MHz") - || CHECK_FOR("cpu") ) ) { - - /* single proc/core may not have "processor : n" */ - processor = g_new0(Processor, 1); - processor->id = 0; - - if (rep_pname) - processor->model_name = g_strdup(rep_pname); - } - - if (processor) { - get_str("cpu family", processor->cpu_family); - get_float("cpu MHz", processor->cpu_mhz); - get_str("cpu", processor->model_name); - get_float("bogomips", processor->bogomips); - get_str("model name", processor->strmodel); - get_str("I-cache", processor->icache_str); - get_str("D-cache", processor->dcache_str); - get_str("hversion", processor->hversion); - get_str("sversion", processor->sversion); - } - g_strfreev(tmp); - } - - if (processor) - procs = g_slist_append(procs, processor); - - g_free(rep_pname); - fclose(cpuinfo); - - /* TODO: redup */ - - /* data not from /proc/cpuinfo */ - for (pi = procs; pi; pi = pi->next) { - processor = (Processor *) pi->data; - - /* strings can't be null or segfault later */ - STRIFNULL(processor->model_name, _("PA-RISC Processor") ); - STRIFNULL(processor->cpu_family, "PA-RISC"); - UNKIFNULL(processor->strmodel); - - /* topo & freq */ - processor->cpufreq = cpufreq_new(processor->id); - processor->cputopo = cputopo_new(processor->id); - - if (processor->cpufreq->cpukhz_max) - processor->cpu_mhz = processor->cpufreq->cpukhz_max / 1000; - - } - - return procs; -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_detailed_info(Processor *processor) -{ - gchar *tmp_cpufreq, *tmp_topology, *ret; - - tmp_topology = cputopo_section_str(processor->cputopo); - tmp_cpufreq = cpufreq_section_str(processor->cpufreq); - - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" /* model name */ - "%s=%.2f %s\n" /* frequency */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n" /* byte order */ - "%s=%s\n" /* hversion */ - "%s=%s\n" /* sversion */ - "[%s]\n" - "I-Cache=%s\n" - "D-Cache=%s\n" - "%s" /* topology */ - "%s" /* frequency scaling */ - "%s",/* empty */ - _("Processor"), - _("Model"), processor->model_name, - _("Architecture"), processor->cpu_family, - _("System"), processor->strmodel, - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str(), - _("HVersion"), processor->hversion, - _("SVersion"), processor->sversion, - _("Cache"), - processor->icache_str, - processor->dcache_str, - tmp_topology, - tmp_cpufreq, - ""); - - g_free(tmp_cpufreq); - g_free(tmp_topology); - return ret; -} - -gchar *processor_get_info(GSList * processors) -{ - Processor *processor; - - if (g_slist_length(processors) > 1) { - gchar *ret, *tmp, *hashkey; - GSList *l; - - tmp = g_strdup(""); - - for (l = processors; l; l = l->next) { - processor = (Processor *) l->data; - - tmp = g_strdup_printf("%s$CPU%d$%s=%.2f %s\n", - tmp, processor->id, - processor->model_name, - processor->cpu_mhz, _("MHz")); - - hashkey = g_strdup_printf("CPU%d", processor->id); - moreinfo_add_with_prefix("DEV", hashkey, - processor_get_detailed_info(processor)); - g_free(hashkey); - } - - ret = g_strdup_printf("[$ShellParam$]\n" - "ViewType=1\n" - "[Processors]\n" - "%s", tmp); - g_free(tmp); - - return ret; - } - - processor = (Processor *) processors->data; - return processor_get_detailed_info(processor); -} diff --git a/modules/devices/pci.c b/modules/devices/pci.c deleted file mode 100644 index c1965a63..00000000 --- a/modules/devices/pci.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* - * TODO: This thing must be rewritten. We really should have a struct with all the - * PCI stuff we'll present to the user, and hash them by the PCI ID - * (domain:bus:device.function). - * This way we'll have ways to better organize the output, instead of relying - * on the order the information appears on lspci's output. - * Also, the "Resources" thing might be better implemented (and we won't need - * copies of information scattered everywhere like we do today). - */ - -#include <string.h> - -#include "hardinfo.h" -#include "devices.h" - -GHashTable *_pci_devices = NULL; - -void -scan_pci_do(void) -{ - FILE *lspci; - gchar buffer[256], *buf, *strhash = NULL, *strdevice = NULL; - gchar *category = NULL, *name = NULL, *icon, *lspci_path, *command_line = NULL; - gint n = 0, x = 0; - - if ((lspci_path = find_program("lspci")) == NULL) { - goto pci_error; - } else { - command_line = g_strdup_printf("%s -v", lspci_path); - } - - if (!_pci_devices) { - _pci_devices = g_hash_table_new(g_str_hash, g_str_equal); - } - - buf = g_build_filename(g_get_home_dir(), ".hardinfo", "pci.ids", NULL); - if (!g_file_test(buf, G_FILE_TEST_EXISTS)) { - DEBUG("using system-provided PCI IDs"); - g_free(buf); - if (!(lspci = popen(command_line, "r"))) { - goto pci_error; - } - } else { - gchar *tmp; - - tmp = g_strdup_printf("%s -i '%s'", command_line, buf); - g_free(buf); - buf = tmp; - - DEBUG("using updated PCI IDs (from %s)", buf); - if (!(lspci = popen(tmp, "r"))) { - g_free(buf); - goto pci_error; - } else { - g_free(buf); - } - } - - while (fgets(buffer, 256, lspci)) { - buf = g_strstrip(buffer); - - if (!strncmp(buf, "Flags", 5)) { - gint irq = 0, freq = 0, latency = 0, i; - gchar **list; - gboolean bus_master; - - buf += 7; - - bus_master = FALSE; - - list = g_strsplit(buf, ", ", 10); - for (i = 0; i <= 10; i++) { - if (!list[i]) - break; - - if (!strncmp(list[i], "IRQ", 3)) - sscanf(list[i], "IRQ %d", &irq); - else if (strstr(list[i], "Mhz")) - sscanf(list[i], "%dMhz", &freq); - else if (!strncmp(list[i], "bus master", 10)) - bus_master = TRUE; - else if (!strncmp(list[i], "latency", 7)) - sscanf(list[i], "latency %d", &latency); - } - g_strfreev(list); - - if (irq) - strdevice = h_strdup_cprintf("%s=%d\n", strdevice, _("IRQ"), irq); - if (freq) - strdevice = h_strdup_cprintf("%s=%d %s\n", strdevice, _("Frequency"), freq, _("MHz") ); - if (latency) - strdevice = h_strdup_cprintf("%s=%d\n", strdevice, _("Latency"), latency); - - strdevice = h_strdup_cprintf("%s=%s\n", strdevice, _("Bus Master"), bus_master ? _("Yes") : _("No") ); - } else if (!strncmp(buf, "Kernel modules", 14)) { - WALK_UNTIL(' '); - WALK_UNTIL(':'); - buf++; - - strdevice = h_strdup_cprintf("%s=%s\n", strdevice, _("Kernel modules"), buf); - } else if (!strncmp(buf, "Subsystem", 9)) { - WALK_UNTIL(' '); - buf++; - const gchar *oem_vendor_url = vendor_get_url(buf); - if (oem_vendor_url) - strdevice = h_strdup_cprintf(_("%s=%s (%s)\n"), - strdevice, - _("OEM Vendor"), - vendor_get_name(buf), - oem_vendor_url); - } else if (!strncmp(buf, "Capabilities", 12) - && !strstr(buf, "only to root") && - !strstr(buf, "access denied")) { - WALK_UNTIL(' '); - WALK_UNTIL(']'); - buf++; - strdevice = h_strdup_cprintf("Capability#%d=%s\n", strdevice, ++x, buf); - } else if (!strncmp(buf, "Memory at", 9) && strstr(buf, "[size=")) { - gint mem; - gchar unit; - gboolean prefetch; - gboolean _32bit; - - prefetch = strstr(buf, "non-prefetchable") ? FALSE : TRUE; - _32bit = strstr(buf, "32-bit") ? TRUE : FALSE; - - WALK_UNTIL('['); - sscanf(buf, "[size=%d%c", &mem, &unit); - - strdevice = h_strdup_cprintf("%s#%d=%d%cB (%s%s)\n", - strdevice, _("Memory"), ++x, - mem, - (unit == ']') ? ' ' : unit, - _32bit ? "32-bit, " : "", - prefetch ? _("prefetchable") : - _("non-prefetchable") ); - - } else if (!strncmp(buf, "I/O ports at", 12)) { - guint io_addr, io_size; - - sscanf(buf, "I/O ports at %x [size=%d]", &io_addr, &io_size); - - strdevice = - h_strdup_cprintf("%s#%d=0x%x - 0x%x\n", - strdevice, _("I/O ports at"), ++x, io_addr, - io_addr + io_size - 1); - } else if ((buf[0] >= '0' && buf[0] <= '9') && (buf[4] == ':' || buf[2] == ':')) { - gint bus, device, function, domain; - gpointer start, end; - - if (strdevice != NULL && strhash != NULL) { - moreinfo_add_with_prefix("DEV", strhash, strdevice); - g_free(strhash); - g_free(category); - g_free(name); - } - - if (buf[4] == ':') { - sscanf(buf, "%x:%x:%x.%d", &domain, &bus, &device, &function); - } else { - /* lspci without domain field */ - sscanf(buf, "%x:%x.%x", &bus, &device, &function); - domain = 0; - } - - WALK_UNTIL(' '); - - start = buf; - - WALK_UNTIL(':'); - end = buf + 1; - *buf = 0; - - buf = start + 1; - category = g_strdup(buf); - - buf = end; - - if (strstr(category, "RAM memory")) icon = "mem"; - else if (strstr(category, "Multimedia")) icon = "media"; - else if (strstr(category, "USB")) icon = "usb"; - else icon = "pci"; - - name = g_strdup(buf); - g_hash_table_insert(_pci_devices, - g_strdup_printf("0000:%02x:%02x.%x", bus, device, function), - name); - - strhash = g_strdup_printf("PCI%d", n); - strdevice = g_strdup_printf("[%s]\n" - /* Name */ "%s=%s\n" - /* Class */ "%s=%s\n" - /* Domain */ "%s=%d\n" - /* Bus, device, function */ - "%s=%d, %d, %d\n", - _("Device Information"), - _("Name"), name, - _("Class"), category, - _("Domain"), domain, - _("Bus, device, function"), - bus, device, function); - - const gchar *url = vendor_get_url(name); - if (url) { - strdevice = h_strdup_cprintf("%s=%s (%s)\n", - strdevice, - _("Vendor"), - vendor_get_name(name), - url); - } - - g_hash_table_insert(_pci_devices, - g_strdup_printf("0000:%02x:%02x.%x", bus, device, function), - g_strdup(name)); - - pci_list = h_strdup_cprintf("$PCI%d$%s=%s\n", pci_list, n, category, name); - - n++; - } - } - - if (pclose(lspci)) { -pci_error: - /* error (no pci, perhaps?) */ - pci_list = g_strconcat(pci_list, _("No PCI devices found"), "=\n", NULL); - } else if (strhash) { - /* insert the last device */ - moreinfo_add_with_prefix("DEV", strhash, strdevice); - g_free(strhash); - g_free(category); - g_free(name); - } - - g_free(lspci_path); - g_free(command_line); -} diff --git a/modules/devices/ppc/processor.c b/modules/devices/ppc/processor.c deleted file mode 100644 index 3360a136..00000000 --- a/modules/devices/ppc/processor.c +++ /dev/null @@ -1,206 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -GSList * -processor_scan(void) -{ - GSList *procs = NULL; - Processor *processor = NULL; - FILE *cpuinfo; - gchar buffer[128]; - gchar *rep_pname = NULL; - GSList *pi = NULL; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - -#define CHECK_FOR(k) (g_str_has_prefix(tmp[0], k)) - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - } else { - g_strfreev(tmp); - continue; - } - - get_str("Processor", rep_pname); - - if ( CHECK_FOR("processor") ) { - /* finish previous */ - if (processor) { - procs = g_slist_append(procs, processor); - } - - /* start next */ - processor = g_new0(Processor, 1); - processor->id = atol(tmp[1]); - - if (rep_pname) - processor->model_name = g_strdup(rep_pname); - - g_strfreev(tmp); - continue; - } - - if (!processor && - ( CHECK_FOR("cpu") - || CHECK_FOR("clock") - || CHECK_FOR("revision") ) ) { - - /* single proc/core may not have "processor : n" */ - processor = g_new0(Processor, 1); - processor->id = 0; - - if (rep_pname) - processor->model_name = g_strdup(rep_pname); - } - - if (processor) { - get_str("cpu", processor->model_name); - get_str("revision", processor->revision); - get_float("clock", processor->cpu_mhz); - get_float("BogoMIPS", processor->bogomips); - } - g_strfreev(tmp); - } - - if (processor) - procs = g_slist_append(procs, processor); - - g_free(rep_pname); - fclose(cpuinfo); - - /* re-duplicate missing data for /proc/cpuinfo variant that de-duplicated it */ -#define REDUP(f) if (dproc->f && !processor->f) processor->f = g_strdup(dproc->f); - Processor *dproc; - GSList *l; - l = procs = g_slist_reverse(procs); - while (l) { - processor = l->data; - if (processor->model_name) { - dproc = processor; - } else if (dproc) { - REDUP(model_name); - REDUP(revision); - } - l = g_slist_next(l); - } - procs = g_slist_reverse(procs); - - /* data not from /proc/cpuinfo */ - for (pi = procs; pi; pi = pi->next) { - processor = (Processor *) pi->data; - - /* strings can't be null or segfault later */ - STRIFNULL(processor->model_name, _("POWER Processor") ); - UNKIFNULL(processor->revision); - - /* topo & freq */ - processor->cpufreq = cpufreq_new(processor->id); - processor->cputopo = cputopo_new(processor->id); - - if (processor->cpufreq->cpukhz_max) - processor->cpu_mhz = processor->cpufreq->cpukhz_max / 1000; - - } - - return procs; -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_detailed_info(Processor *processor) -{ - gchar *tmp_cpufreq, *tmp_topology, *ret; - - tmp_topology = cputopo_section_str(processor->cputopo); - tmp_cpufreq = cpufreq_section_str(processor->cpufreq); - - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" /* model */ - "%s=%s\n" /* revision */ - "%s=%.2f %s\n" /* frequency */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n" /* byte order */ - "%s" /* topology */ - "%s" /* frequency scaling */ - "%s",/* empty */ - _("Processor"), - _("Model"), processor->model_name, - _("Revision"), processor->revision, - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str(), - tmp_topology, - tmp_cpufreq, - ""); - g_free(tmp_cpufreq); - g_free(tmp_topology); - return ret; -} - -gchar *processor_get_info(GSList * processors) -{ - Processor *processor; - - if (g_slist_length(processors) > 1) { - gchar *ret, *tmp, *hashkey; - GSList *l; - - tmp = g_strdup(""); - - for (l = processors; l; l = l->next) { - processor = (Processor *) l->data; - - tmp = g_strdup_printf("%s$CPU%d$%s=%.2f %s\n", - tmp, processor->id, - processor->model_name, - processor->cpu_mhz, _("MHz")); - - hashkey = g_strdup_printf("CPU%d", processor->id); - moreinfo_add_with_prefix("DEV", hashkey, - processor_get_detailed_info(processor)); - g_free(hashkey); - } - - ret = g_strdup_printf("[$ShellParam$]\n" - "ViewType=1\n" - "[Processors]\n" - "%s", tmp); - g_free(tmp); - - return ret; - } - - processor = (Processor *) processors->data; - return processor_get_detailed_info(processor); -} diff --git a/modules/devices/printers.c b/modules/devices/printers.c deleted file mode 100644 index 77b52a43..00000000 --- a/modules/devices/printers.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2007 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <stdio.h> -#include <stdlib.h> -#include <time.h> - -#include "devices.h" - -typedef struct _CUPSDest CUPSDest; -typedef struct _CUPSOption CUPSOption; - -struct _CUPSOption { - char *name, *value; -}; - -struct _CUPSDest { - char *name, *instance; - int is_default; - int num_options; - CUPSOption *options; -}; - -static int (*cups_dests_get) (CUPSDest **dests) = NULL; -static int (*cups_dests_free) (int num_dests, CUPSDest *dests) = NULL; -static gboolean cups_init = FALSE; - -GModule *cups; - -void -init_cups(void) -{ - const char *libcups[] = { "libcups", "libcups.so", "libcups.so.1", "libcups.so.2", NULL }; - - if (!(cups_dests_get && cups_dests_free)) { - int i; - - for (i = 0; libcups[i] != NULL; i++) { - cups = g_module_open(libcups[i], G_MODULE_BIND_LAZY); - if (cups) - break; - } - - if (!cups) { - cups_init = FALSE; - return; - } - - if (!g_module_symbol(cups, "cupsGetDests", (gpointer) & cups_dests_get) - || !g_module_symbol(cups, "cupsFreeDests", (gpointer) & cups_dests_free)) { - g_module_close(cups); - cups_init = FALSE; - } - } - - cups_init = TRUE; -} - -gchar *__cups_callback_ptype(gchar *strvalue) -{ - if (strvalue) { - unsigned value = atoi(strvalue); - gchar *output = g_strdup("\n"); - - if (value & 0x0004) - output = h_strdup_cprintf(_("\342\232\254 Can do black and white printing=\n"), output); - if (value & 0x0008) - output = h_strdup_cprintf(_("\342\232\254 Can do color printing=\n"), output); - if (value & 0x0010) - output = h_strdup_cprintf(_("\342\232\254 Can do duplexing=\n"), output); - if (value & 0x0020) - output = h_strdup_cprintf(_("\342\232\254 Can do staple output=\n"), output); - if (value & 0x0040) - output = h_strdup_cprintf(_("\342\232\254 Can do copies=\n"), output); - if (value & 0x0080) - output = h_strdup_cprintf(_("\342\232\254 Can collate copies=\n"), output); - if (value & 0x80000) - output = h_strdup_cprintf(_("\342\232\254 Printer is rejecting jobs=\n"), output); - if (value & 0x1000000) - output = h_strdup_cprintf(_("\342\232\254 Printer was automatically discovered and added=\n"), output); - - return output; - } else { - return g_strdup(_("Unknown")); - } -} - -gchar *__cups_callback_state(gchar *value) -{ - if (!value) { - return g_strdup(_("Unknown")); - } - - if (g_str_equal(value, "3")) { - return g_strdup(_("Idle")); - } else if (g_str_equal(value, "4")) { - return g_strdup(_("Printing a Job")); - } else if (g_str_equal(value, "5")) { - return g_strdup(_("Stopped")); - } else { - return g_strdup(_("Unknown")); - } -} - -gchar *__cups_callback_state_change_time(gchar *value) -{ - struct tm tm; - char buf[255]; - - if (value) { - strptime(value, "%s", &tm); - strftime(buf, sizeof(buf), "%c", &tm); - - return g_strdup(buf); - } else { - return g_strdup(_("Unknown")); - } -} - -gchar *__cups_callback_boolean(gchar *value) -{ - if (value) { - return g_strdup(g_str_equal(value, "1") ? _("Yes") : _("No")); - } else { - return g_strdup(_("Unknown")); - } -} - -const struct { - char *key, *name; - gchar *(*callback)(gchar *value); -} cups_fields[] = { - { "Printer Information", NULL, NULL }, - { "printer-info", "Destination Name", NULL }, - { "printer-make-and-model", "Make and Model", NULL }, - - { "Capabilities", NULL, NULL }, - { "printer-type", "#", __cups_callback_ptype }, - - { "Printer State", NULL, NULL }, - { "printer-state", "State", __cups_callback_state }, - { "printer-state-change-time", "Change Time", __cups_callback_state_change_time }, - { "printer-state-reasons", "State Reasons" }, - - { "Sharing Information", NULL, NULL }, - { "printer-is-shared", "Shared?", __cups_callback_boolean }, - { "printer-location", "Physical Location" }, - { "auth-info-required", "Authentication Required", __cups_callback_boolean }, - - { "Jobs", NULL, NULL }, - { "job-hold-until", "Hold Until", NULL }, - { "job-priority", "Priority", NULL }, - { "printer-is-accepting-jobs", "Accepting Jobs", __cups_callback_boolean }, - - { "Media", NULL, NULL }, - { "media", "Media", NULL }, - { "finishings", "Finishings", NULL }, - { "copies", "Copies", NULL }, -}; - -void -scan_printers_do(void) -{ - int num_dests, i, j; - CUPSDest *dests; - gchar *prn_id, *prn_moreinfo; - - g_free(printer_list); - g_free(printer_icons); - - if (!cups_init) { - init_cups(); - - printer_icons = g_strdup(""); - printer_list = g_strdup(_("[Printers]\n" - "No suitable CUPS library found=")); - return; - } - - /* remove old devices from global device table */ - moreinfo_del_with_prefix("DEV:PRN"); - - num_dests = cups_dests_get(&dests); - if (num_dests > 0) { - printer_list = g_strdup_printf(_("[Printers (CUPS)]\n")); - printer_icons = g_strdup(""); - for (i = 0; i < num_dests; i++) { - GHashTable *options; - - options = g_hash_table_new(g_str_hash, g_str_equal); - - for (j = 0; j < dests[i].num_options; j++) { - g_hash_table_insert(options, - g_strdup(dests[i].options[j].name), - g_strdup(dests[i].options[j].value)); - } - - prn_id = g_strdup_printf("PRN%d", i); - - printer_list = h_strdup_cprintf("\n$%s$%s=%s\n", - printer_list, - prn_id, - dests[i].name, - dests[i].is_default ? "<i>Default</i>" : ""); - printer_icons = h_strdup_cprintf("\nIcon$%s$%s=printer.png", - printer_icons, - prn_id, - dests[i].name); - - prn_moreinfo = g_strdup(""); - for (j = 0; j < G_N_ELEMENTS(cups_fields); j++) { - if (!cups_fields[j].name) { - prn_moreinfo = h_strdup_cprintf("[%s]\n", - prn_moreinfo, - cups_fields[j].key); - } else { - gchar *temp; - - temp = g_hash_table_lookup(options, cups_fields[j].key); - - if (cups_fields[j].callback) { - temp = cups_fields[j].callback(temp); - } else { - if (temp) { - /* FIXME Do proper escaping */ - temp = g_strdup(strreplacechr(temp, "&=", ' ')); - } else { - temp = g_strdup(_("Unknown")); - } - } - - prn_moreinfo = h_strdup_cprintf("%s=%s\n", - prn_moreinfo, - cups_fields[j].name, - temp); - - g_free(temp); - } - } - - moreinfo_add_with_prefix("DEV", prn_id, prn_moreinfo); - g_free(prn_id); - g_hash_table_destroy(options); - } - - cups_dests_free(num_dests, dests); - } else { - printer_list = g_strdup(_("[Printers]\n" - "No printers found=\n")); - } -} diff --git a/modules/devices/resources.c b/modules/devices/resources.c deleted file mode 100644 index 15cb8f21..00000000 --- a/modules/devices/resources.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2008 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <string.h> - -#include "devices.h" - -static gchar *_resources = NULL; -static gboolean _require_root = FALSE; - -#if GLIB_CHECK_VERSION(2,14,0) -static GRegex *_regex_pci = NULL, - *_regex_module = NULL; - -static gchar *_resource_obtain_name(gchar *name) -{ - gchar *temp; - - if (!_regex_pci && !_regex_module) { - _regex_pci = g_regex_new("^[0-9a-fA-F]{4}:[0-9a-fA-F]{2}:" - "[0-9a-fA-F]{2}\\.[0-9a-fA-F]{1}$", - 0, 0, NULL); - _regex_module = g_regex_new("^[0-9a-zA-Z\\_\\-]+$", 0, 0, NULL); - } - - name = g_strstrip(name); - - if (g_regex_match(_regex_pci, name, 0, NULL)) { - temp = module_call_method_param("devices::getPCIDeviceDescription", name); - if (temp) { - return g_strdup_printf("<b><small>PCI</small></b> %s", (gchar *)idle_free(temp)); - } - } else if (g_regex_match(_regex_module, name, 0, NULL)) { - temp = module_call_method_param("computer::getKernelModuleDescription", name); - if (temp) { - return g_strdup_printf("<b><small>Module</small></b> %s", (gchar *)idle_free(temp)); - } - } - - return g_strdup(name); -} -#else -static gchar *_resource_obtain_name(gchar *name) -{ - return g_strdup(name); -} -#endif - -void scan_device_resources(gboolean reload) -{ - SCAN_START(); - FILE *io; - gchar buffer[256]; - gint i; - gint zero_to_zero_addr = 0; - - struct { - gchar *file; - gchar *description; - } resources[] = { - { "/proc/ioports", "[I/O Ports]\n" }, - { "/proc/iomem", "[Memory]\n" }, - { "/proc/dma", "[DMA]\n" } - }; - - g_free(_resources); - _resources = g_strdup(""); - - for (i = 0; i < G_N_ELEMENTS(resources); i++) { - if ((io = fopen(resources[i].file, "r"))) { - _resources = h_strconcat(_resources, resources[i].description, NULL); - - while (fgets(buffer, 256, io)) { - gchar **temp = g_strsplit(buffer, ":", 2); - gchar *name = _resource_obtain_name(temp[1]); - - if (strstr(temp[0], "0000-0000")) - zero_to_zero_addr++; - - _resources = h_strdup_cprintf("<tt>%s</tt>=%s\n", _resources, - temp[0], name); - - g_strfreev(temp); - g_free(name); - } - - fclose(io); - } - } - - _require_root = zero_to_zero_addr > 16; - - SCAN_END(); -} - -gchar *callback_device_resources(void) -{ - return g_strdup(_resources); -} - -gboolean root_required_for_resources(void) -{ - return _require_root; -} diff --git a/modules/devices/riscv/processor.c b/modules/devices/riscv/processor.c deleted file mode 100644 index afddf89d..00000000 --- a/modules/devices/riscv/processor.c +++ /dev/null @@ -1,233 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* source: https://github.com/riscv/riscv-linux/blob/riscv-next/arch/riscv/kernel/cpu.c */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -#include "riscv_data.h" -#include "riscv_data.c" - -GSList * -processor_scan(void) -{ - GSList *procs = NULL; - Processor *processor = NULL; - FILE *cpuinfo; - gchar buffer[128]; - gchar *rep_pname = NULL; - gchar *tmpfreq_str = NULL; - GSList *pi = NULL; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - -#define CHECK_FOR(k) (g_str_has_prefix(tmp[0], k)) - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - } else { - g_strfreev(tmp); - continue; - } - - //get_str("Processor", rep_pname); - - if ( CHECK_FOR("hart") ) { - /* finish previous */ - if (processor) { - procs = g_slist_append(procs, processor); - } - - /* start next */ - processor = g_new0(Processor, 1); - processor->id = atol(tmp[1]); - - if (rep_pname) - processor->model_name = g_strdup(rep_pname); - - g_strfreev(tmp); - continue; - } - - if (!processor && - ( CHECK_FOR("mmu") - || CHECK_FOR("isa") - || CHECK_FOR("uarch") ) ) { - - /* single proc/core may not have "hart : n" */ - processor = g_new0(Processor, 1); - processor->id = 0; - - if (rep_pname) - processor->model_name = g_strdup(rep_pname); - } - - if (processor) { - get_str("mmu", processor->mmu); - get_str("isa", processor->isa); - get_str("uarch", processor->uarch); - } - g_strfreev(tmp); - } - - if (processor) - procs = g_slist_append(procs, processor); - - g_free(rep_pname); - fclose(cpuinfo); - - /* TODO: redup */ - - /* data not from /proc/cpuinfo */ - for (pi = procs; pi; pi = pi->next) { - processor = (Processor *) pi->data; - - /* strings can't be null or segfault later */ - STRIFNULL(processor->model_name, _("RISC-V Processor") ); - UNKIFNULL(processor->mmu); - UNKIFNULL(processor->isa); - UNKIFNULL(processor->uarch); - - processor->flags = riscv_isa_to_flags(processor->isa); - - /* topo & freq */ - processor->cpufreq = cpufreq_new(processor->id); - processor->cputopo = cputopo_new(processor->id); - - if (processor->cpufreq->cpukhz_max) - processor->cpu_mhz = processor->cpufreq->cpukhz_max / 1000; - else - processor->cpu_mhz = 0.0f; - } - - return procs; -} - -gchar *processor_get_capabilities_from_flags(gchar * strflags) -{ - gchar **flags, **old; - gchar *tmp = NULL; - gint j = 0; - - flags = g_strsplit(strflags, " ", 0); - old = flags; - - while (flags[j]) { - const gchar *meaning = riscv_ext_meaning( flags[j] ); - - if (meaning) { - tmp = h_strdup_cprintf("%s=%s\n", tmp, flags[j], meaning); - } else { - tmp = h_strdup_cprintf("%s=\n", tmp, flags[j]); - } - j++; - } - if (tmp == NULL || g_strcmp0(tmp, "") == 0) - tmp = g_strdup_printf("%s=%s\n", "empty", _("Empty List")); - - g_strfreev(old); - return tmp; -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_detailed_info(Processor *processor) -{ - gchar *tmp_flags, *tmp_cpufreq, *tmp_topology, *ret; - tmp_flags = processor_get_capabilities_from_flags(processor->flags); - tmp_topology = cputopo_section_str(processor->cputopo); - tmp_cpufreq = cpufreq_section_str(processor->cpufreq); - - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" /* model */ - "%s=%s\n" /* isa */ - "%s=%s\n" /* uarch */ - "%s=%s\n" /* mmu */ - "%s=%.2f %s\n" /* frequency */ - "%s=%s\n" /* byte order */ - "%s" /* topology */ - "%s" /* frequency scaling */ - "[%s]\n" /* extensions */ - "%s" - "%s",/* empty */ - _("Processor"), - _("Model"), processor->model_name, - _("Architecture"), processor->isa, - _("uarch"), processor->uarch, - _("MMU"), processor->mmu, - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("Byte Order"), byte_order_str(), - tmp_topology, - tmp_cpufreq, - _("Capabilities"), tmp_flags, - ""); - g_free(tmp_flags); - g_free(tmp_cpufreq); - g_free(tmp_topology); - return ret; -} - -gchar *processor_get_info(GSList * processors) -{ - Processor *processor; - - if (g_slist_length(processors) > 1) { - gchar *ret, *tmp, *hashkey; - GSList *l; - - tmp = g_strdup(""); - - for (l = processors; l; l = l->next) { - processor = (Processor *) l->data; - - tmp = g_strdup_printf("%s$CPU%d$%s=%.2f %s\n", - tmp, processor->id, - processor->model_name, - processor->cpu_mhz, _("MHz")); - - hashkey = g_strdup_printf("CPU%d", processor->id); - moreinfo_add_with_prefix("DEV", hashkey, - processor_get_detailed_info(processor)); - g_free(hashkey); - } - - ret = g_strdup_printf("[$ShellParam$]\n" - "ViewType=1\n" - "[Processors]\n" - "%s", tmp); - g_free(tmp); - - return ret; - } - - processor = (Processor *) processors->data; - return processor_get_detailed_info(processor); -} diff --git a/modules/devices/riscv/riscv_data.c b/modules/devices/riscv/riscv_data.c deleted file mode 100644 index 4ae68ef4..00000000 --- a/modules/devices/riscv/riscv_data.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * rpiz - https://github.com/bp0/rpiz - * Copyright (C) 2017 Burt P. <pburt0@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include "riscv_data.h" - -#ifndef C_ -#define C_(Ctx, String) String -#endif -#ifndef NC_ -#define NC_(Ctx, String) String -#endif - -static struct { - char *name, *meaning; -} tab_ext_meaning[] = { - { "RV32", NC_("rv-ext", /*/ext:RV32*/ "RISC-V 32-bit") }, - { "RV64", NC_("rv-ext", /*/ext:RV64*/ "RISC-V 64-bit") }, - { "RV128", NC_("rv-ext", /*/ext:RV128*/ "RISC-V 128-bit") }, - { "E", NC_("rv-ext", /*/ext:E*/ "Base embedded integer instructions (15 registers)") }, - { "I", NC_("rv-ext", /*/ext:I*/ "Base integer instructions (31 registers)") }, - { "M", NC_("rv-ext", /*/ext:M*/ "Hardware integer multiply and divide") }, - { "A", NC_("rv-ext", /*/ext:A*/ "Atomic memory operations") }, - { "C", NC_("rv-ext", /*/ext:C*/ "Compressed 16-bit instructions") }, - { "F", NC_("rv-ext", /*/ext:F*/ "Floating-point instructions, single-precision") }, - { "D", NC_("rv-ext", /*/ext:D*/ "Floating-point instructions, double-precision") }, - { "Q", NC_("rv-ext", /*/ext:Q*/ "Floating-point instructions, quad-precision") }, - { "B", NC_("rv-ext", /*/ext:B*/ "Bit manipulation instructions") }, - { "V", NC_("rv-ext", /*/ext:V*/ "Vector operations") }, - { "T", NC_("rv-ext", /*/ext:T*/ "Transactional memory") }, - { "P", NC_("rv-ext", /*/ext:P*/ "Packed SIMD instructions") }, - { "L", NC_("rv-ext", /*/ext:L*/ "Decimal floating-point instructions") }, - { "J", NC_("rv-ext", /*/ext:J*/ "Dynamically translated languages") }, - { "N", NC_("rv-ext", /*/ext:N*/ "User-level interrupts") }, - { NULL, NULL } -}; - -static char all_extensions[1024] = ""; - -#define APPEND_EXT(f) strcat(all_extensions, f); strcat(all_extensions, " "); -const char *riscv_ext_list() { - int i = 0, built = 0; - built = strlen(all_extensions); - if (!built) { - while(tab_ext_meaning[i].name != NULL) { - APPEND_EXT(tab_ext_meaning[i].name); - i++; - } - } - return all_extensions; -} - -const char *riscv_ext_meaning(const char *ext) { - int i = 0, l = 0; - char *c = NULL; - if (ext) { - c = strchr(ext, ':'); /* allow extension:version, ignore version */ - if (c != NULL) - l = c - ext; - else - l = strlen(ext); - while(tab_ext_meaning[i].name != NULL) { - if (strncasecmp(tab_ext_meaning[i].name, ext, l) == 0) { - if (tab_ext_meaning[i].meaning != NULL) - return C_("rv-ext", tab_ext_meaning[i].meaning); - else return NULL; - } - i++; - } - } - return NULL; -} - -/* see RISC-V spec 2.2: Chapter 22: ISA Subset Naming Conventions */ - -/* Spec says case-insensitve, but I prefer single-letter extensions - * capped and version string (like "2p1") with a lowercase p. */ -#define RV_FIX_CASE(fstr,vo) \ - p = fstr; while (*p != 0 && *p != ':') { if (!vo) *p = toupper(*p); p++; } \ - if (*p == ':') while (*p != 0) { if (*p == 'P') *p = 'p'; p++; } - -static int riscv_isa_next(const char *isap, char *flag) { - char *p = NULL, *start = NULL; - char *next_sep = NULL, *next_digit = NULL; - int skip_len = 0, tag_len = 0, ver_len = 0; - char ext_str[32], ver_str[32]; - - if (isap == NULL) - return 0; - - /* find start by skipping any '_' */ - start = (char*)isap; - while (*start != 0 && *start == '_') { start++; skip_len++; }; - if (*start == 0) - return 0; - - /* find next '_' or \0 */ - p = start; while (*p != 0 && *p != '_') { p++; }; next_sep = p; - - /* find next digit that may be a version, find length of version */ - p = start; while (*p != 0 && !isdigit(*p)) { p++; }; - if (isdigit(*p)) next_digit = p; - if (next_digit) { - while (*p != 0 && (isdigit(*p) || *p == 'p' || *p == 'P') ) { - if ((*p == 'p' || *p == 'P') && !isdigit(*(p+1)) ) - break; - ver_len++; - p++; - } - } - - /* is next version nearer than next separator */ - p = start; - if (next_digit && next_digit < next_sep) - tag_len = next_digit - p; - else { - tag_len = next_sep - p; - ver_len = 0; - } - - switch(*p) { - case 'S': case 's': /* supervisor extension */ - case 'X': case 'x': /* custom extension */ - /* custom supervisor extension (SX..) handled by S */ - break; - default: /* single character (standard) extension */ - tag_len = 1; - if (next_digit != p+1) ver_len = 0; - break; - } - - memset(ext_str, 0, 32); - memset(ver_str, 0, 32); - if (ver_len) { - strncpy(ext_str, p, tag_len); - strncpy(ver_str, next_digit, ver_len); - sprintf(flag, "%s:%s", ext_str, ver_str); - if (tag_len == 1) { - RV_FIX_CASE(flag, 0); - } else { - RV_FIX_CASE(flag, 1); - } - return skip_len + tag_len + ver_len; - } else { - strncpy(ext_str, p, tag_len); - sprintf(flag, "%s", ext_str); - if (tag_len == 1) { RV_FIX_CASE(flag, 0); } - return skip_len + tag_len; - } -} - -#define FSTR_SIZE 1024 -#define RV_CHECK_FOR(e) ( strncasecmp(ps, e, 2) == 0 ) -#define ADD_EXT_FLAG(ext) el = strlen(ext); strncpy(pd, ext, el); strncpy(pd + el, " ", 1); pd += el + 1; -char *riscv_isa_to_flags(const char *isa) { - char *flags = NULL, *ps = (char*)isa, *pd = NULL; - char flag_buf[64] = ""; - int isa_len = 0, tl = 0, el = 0; /* el used in macro */ - - if (isa) { - isa_len = strlen(isa); - flags = malloc(FSTR_SIZE); - if (flags) { - memset(flags, 0, FSTR_SIZE); - ps = (char*)isa; - pd = flags; - if ( RV_CHECK_FOR("RV") ) - { ps += 2; } - if ( RV_CHECK_FOR("32") ) - { ADD_EXT_FLAG("RV32"); ps += 2; } - else if ( RV_CHECK_FOR("64") ) - { ADD_EXT_FLAG("RV64"); ps += 2; } - else if ( RV_CHECK_FOR("128") ) - { ADD_EXT_FLAG("RV128"); ps += 3; } - - while( (tl = riscv_isa_next(ps, flag_buf)) ) { - if (flag_buf[0] == 'G') { /* G = IMAFD */ - flag_buf[0] = 'I'; ADD_EXT_FLAG(flag_buf); - flag_buf[0] = 'M'; ADD_EXT_FLAG(flag_buf); - flag_buf[0] = 'A'; ADD_EXT_FLAG(flag_buf); - flag_buf[0] = 'F'; ADD_EXT_FLAG(flag_buf); - flag_buf[0] = 'D'; ADD_EXT_FLAG(flag_buf); - } else { - ADD_EXT_FLAG(flag_buf); - } - ps += tl; - if (ps - isa >= isa_len) break; /* just in case */ - } - } - } - return flags; -} diff --git a/modules/devices/riscv/riscv_data.h b/modules/devices/riscv/riscv_data.h deleted file mode 100644 index 1d3a0a48..00000000 --- a/modules/devices/riscv/riscv_data.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * rpiz - https://github.com/bp0/rpiz - * Copyright (C) 2017 Burt P. <pburt0@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef _RISCVDATA_H_ -#define _RISCVDATA_H_ - -/* convert RISC-V ISA string to flags list */ -char *riscv_isa_to_flags(const char *isa); - -/* all known extensions as flags list */ -const char *riscv_ext_list(void); - -/* get meaning of flag */ -const char *riscv_ext_meaning(const char *ext); - -#endif diff --git a/modules/devices/s390/processor.c b/modules/devices/s390/processor.c deleted file mode 100644 index cf45c33c..00000000 --- a/modules/devices/s390/processor.c +++ /dev/null @@ -1,180 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "string.h" -#include "cpu_util.h" - -GSList * -processor_scan(void) -{ - GSList *procs = NULL; - Processor *processor = NULL; - FILE *cpuinfo; - gchar buffer[128]; - gchar *vendor_id = NULL; - gint num_procs = 0; - gfloat bogomips = 0.0f; - GSList *pi = NULL; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - -#define CHECK_FOR(k) (g_str_has_prefix(tmp[0], k)) - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - } else { - g_strfreev(tmp); - continue; - } - - get_str("vendor_id", vendor_id); - get_int("# processors", num_procs); - get_int("bogomips per cpu", bogomips); - - if ( CHECK_FOR("processor") ) { - /* finish previous */ - if (processor) { - procs = g_slist_append(procs, processor); - } - - /* start next */ - processor = g_new0(Processor, 1); - if (strlen(tmp[0]) >= 10) - processor->id = atol(tmp[0] + 10); /* processor n: ... */ - else - processor->id = 0; /* idk */ - processor->proc_str = g_strdup(tmp[1]); - - if (vendor_id) - processor->model_name = g_strdup(vendor_id); - if (bogomips) - processor->bogomips = bogomips; - - g_strfreev(tmp); - continue; - } - - g_strfreev(tmp); - } - - if (processor) - procs = g_slist_append(procs, processor); - - g_free(vendor_id); - fclose(cpuinfo); - - /* data not from /proc/cpuinfo */ - for (pi = procs; pi; pi = pi->next) { - processor = (Processor *) pi->data; - - /* strings can't be null or segfault later */ - STRIFNULL(processor->model_name, _("S390 Processor") ); - UNKIFNULL(processor->proc_str); - - /* topo & freq */ - processor->cpufreq = cpufreq_new(processor->id); - processor->cputopo = cputopo_new(processor->id); - - if (processor->cpufreq->cpukhz_max) - processor->cpu_mhz = processor->cpufreq->cpukhz_max / 1000; - else - processor->cpu_mhz = 0.0f; - - } - - return procs; -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_detailed_info(Processor *processor) -{ - gchar *tmp_cpufreq, *tmp_topology, *ret; - tmp_topology = cputopo_section_str(processor->cputopo); - tmp_cpufreq = cpufreq_section_str(processor->cpufreq); - - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" /* model */ - "%s=%s\n" /* proc string */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n" /* byte order */ - "%s" /* topology */ - "%s", /* frequency scaling */ - _("Processor"), - _("Model"), processor->model_name, - _("ID String"), processor->proc_str, - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str(), - tmp_topology, - tmp_cpufreq - ); - g_free(tmp_cpufreq); - g_free(tmp_topology); - return ret; -} - -gchar *processor_get_info(GSList * processors) -{ - Processor *processor; - - if (g_slist_length(processors) > 1) { - gchar *ret, *tmp, *hashkey; - GSList *l; - - tmp = g_strdup(""); - - for (l = processors; l; l = l->next) { - processor = (Processor *) l->data; - - tmp = g_strdup_printf("%s$CPU%d$%s=%.2f %s\n", - tmp, processor->id, - processor->model_name, - processor->cpu_mhz, _("MHz")); - - hashkey = g_strdup_printf("CPU%d", processor->id); - moreinfo_add_with_prefix("DEV", hashkey, - processor_get_detailed_info(processor)); - g_free(hashkey); - } - - ret = g_strdup_printf("[$ShellParam$]\n" - "ViewType=1\n" - "[Processors]\n" - "%s", tmp); - g_free(tmp); - - return ret; - } - - processor = (Processor *) processors->data; - return processor_get_detailed_info(processor); -} - diff --git a/modules/devices/sensors.c b/modules/devices/sensors.c deleted file mode 100644 index c9d78ff7..00000000 --- a/modules/devices/sensors.c +++ /dev/null @@ -1,453 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <string.h> - -#include "devices.h" -#include "expr.h" -#include "hardinfo.h" -#include "socket.h" - -gchar *sensors = NULL; -GHashTable *sensor_compute = NULL; -GHashTable *sensor_labels = NULL; - -static void read_sensor_labels(gchar *driver) { - FILE *conf; - gchar buf[256], *line, *p; - gboolean lock = FALSE; - gint i; - - /* Try to open lm-sensors config file sensors3.conf */ - conf = fopen("/etc/sensors3.conf", "r"); - - /* If it fails, try to open sensors.conf */ - if (!conf) - conf = fopen("/etc/sensors.conf", "r"); - - if (!conf) { - /* Cannot open config file. */ - return; - } - - while (fgets(buf, 256, conf)) { - line = buf; - - remove_linefeed(line); - strend(line, '#'); - - if (*line == '\0') { - continue; - } else if (lock && strstr(line, "label")) { /* label lines */ - gchar **names = g_strsplit(strstr(line, "label") + 5, " ", 0); - gchar *name = NULL, *value = NULL; - - for (i = 0; names[i]; i++) { - if (names[i][0] == '\0') - continue; - - if (!name) - name = g_strdup(names[i]); - else if (!value) - value = g_strdup(names[i]); - else - value = g_strconcat(value, " ", names[i], NULL); - } - - remove_quotes(value); - g_hash_table_insert(sensor_labels, name, value); - - g_strfreev(names); - } else if (lock && strstr(line, "ignore")) { /* ignore lines */ - p = strstr(line, "ignore") + 6; - if (!strchr(p, ' ')) - continue; - - while (*p == ' ') - p++; - g_hash_table_insert(sensor_labels, g_strdup(p), "ignore"); - } else if (lock && strstr(line, "compute")) { /* compute lines */ - gchar **formulas = g_strsplit(strstr(line, "compute") + 7, " ", 0); - gchar *name = NULL, *formula = NULL; - - for (i = 0; formulas[i]; i++) { - if (formulas[i][0] == '\0') - continue; - if (formulas[i][0] == ',') - break; - - if (!name) - name = g_strdup(formulas[i]); - else if (!formula) - formula = g_strdup(formulas[i]); - else - formula = g_strconcat(formula, formulas[i], NULL); - } - - g_strfreev(formulas); - g_hash_table_insert(sensor_compute, name, - math_string_to_postfix(formula)); - } else if (g_str_has_prefix(line, - "chip")) { /* chip lines (delimiter) */ - if (lock == FALSE) { - gchar **chips = g_strsplit(line, " ", 0); - - for (i = 1; chips[i]; i++) { - strend(chips[i], '*'); - - if (g_str_has_prefix(chips[i] + 1, driver)) { - lock = TRUE; - break; - } - } - - g_strfreev(chips); - } else { - break; - } - } - } - - fclose(conf); -} - -static void add_sensor(const char *type, - const char *sensor, - const char *driver, - double value, - const char *unit) { - char key[64]; - - sensors = h_strdup_cprintf("%s/%s=%.2f%s|%s\n", sensors, - driver, sensor, value, unit, type); - - snprintf(key, sizeof(key), "%s/%s", driver, sensor); - moreinfo_add_with_prefix("DEV", key, g_strdup_printf("%.2f%s", value, unit)); - - lginterval = h_strdup_cprintf("UpdateInterval$%s=1000\n", lginterval, key); -} - -static gchar *get_sensor_label(gchar *sensor) { - gchar *ret; - - ret = g_hash_table_lookup(sensor_labels, sensor); - if (!ret) - ret = g_strdup(sensor); - else - ret = g_strdup(ret); - - return ret; -} - -static float adjust_sensor(gchar *name, float value) { - GSList *postfix; - - postfix = g_hash_table_lookup(sensor_compute, name); - if (!postfix) - return value; - - return math_postfix_eval(postfix, value); -} - -static char *get_sensor_path(int number, const char *prefix) { - return g_strdup_printf("/sys/class/hwmon/hwmon%d/%s", number, prefix); -} - -static char *determine_driver_for_hwmon_path(char *path) { - char *tmp, *driver; - - tmp = g_strdup_printf("%s/device/driver", path); - driver = g_file_read_link(tmp, NULL); - g_free(tmp); - - if (driver) { - tmp = g_path_get_basename(driver); - g_free(driver); - driver = tmp; - } else { - tmp = g_strdup_printf("%s/device", path); - driver = g_file_read_link(tmp, NULL); - g_free(tmp); - } - - if (!driver) { - tmp = g_strdup_printf("%s/name", path); - if (!g_file_get_contents(tmp, &driver, NULL, NULL)) { - driver = g_strdup("unknown"); - } else { - driver = g_strstrip(driver); - } - g_free(tmp); - } - - return driver; -} - -struct HwmonSensor { - const char *friendly_name; - const char *path_format; - const char *key_format; - const char *unit; - const float adjust_ratio; - const int begin_at; -}; - -static const struct HwmonSensor hwmon_sensors[] = { - { - "Fan", - "%s/fan%d_input", - "fan%d", - "RPM", - 1.0, - 1 - }, - { - "Temperature", - "%s/temp%d_input", - "temp%d", - "\302\260C", - 1000.0, - 1 - }, - { - "Voltage", - "%s/in%d_input", - "in%d", - "V", - 1000.0, - 0 - }, - { } -}; - -static const char *hwmon_prefix[] = {"device", "", NULL}; - -static void read_sensors_hwmon(void) { - int hwmon, count; - gchar *path_hwmon, *path_sensor, *tmp, *driver, *name, *mon; - const char **prefix; - - for (prefix = hwmon_prefix; *prefix; prefix++) { - hwmon = 0; - path_hwmon = get_sensor_path(hwmon, *prefix); - while (path_hwmon && g_file_test(path_hwmon, G_FILE_TEST_EXISTS)) { - const struct HwmonSensor *sensor; - - driver = determine_driver_for_hwmon_path(path_hwmon); - DEBUG("hwmon%d has driver=%s", hwmon, driver); - - if (!sensor_labels) { - read_sensor_labels(driver); - } - - for (sensor = hwmon_sensors; sensor->friendly_name; sensor++) { - DEBUG("current sensor type=%s", sensor->friendly_name); - - for (count = sensor->begin_at;; count++) { - path_sensor = - g_strdup_printf(sensor->path_format, path_hwmon, count); - DEBUG("should be reading from %s", path_sensor); - if (!g_file_get_contents(path_sensor, &tmp, NULL, NULL)) { - g_free(path_sensor); - if (count < 256) - continue; // brute-force find all - else - break; - } - - mon = g_strdup_printf(sensor->key_format, count); - name = get_sensor_label(mon); - if (!g_str_equal(name, "ignore")) { - float adjusted = adjust_sensor(mon, - atof(tmp) / sensor->adjust_ratio); - - add_sensor(sensor->friendly_name, - name, - driver, - adjusted, - sensor->unit); - } - - g_free(tmp); - g_free(mon); - g_free(name); - g_free(path_sensor); - } - } - - g_free(path_hwmon); - g_free(driver); - - path_hwmon = get_sensor_path(++hwmon, *prefix); - } - - g_free(path_hwmon); - } -} - -static void read_sensors_acpi(void) { - const gchar *path_tz = "/proc/acpi/thermal_zone"; - - if (g_file_test(path_tz, G_FILE_TEST_EXISTS)) { - GDir *tz; - - if ((tz = g_dir_open(path_tz, 0, NULL))) { - const gchar *entry; - - while ((entry = g_dir_read_name(tz))) { - gchar *path = - g_strdup_printf("%s/%s/temperature", path_tz, entry); - gchar *contents; - - if (g_file_get_contents(path, &contents, NULL, NULL)) { - int temperature; - - sscanf(contents, "temperature: %d C", &temperature); - - add_sensor("Temperature", - entry, - "ACPI Thermal Zone", - temperature, - "\302\260C"); - } - } - - g_dir_close(tz); - } - } -} - -static void read_sensors_sys_thermal(void) { - const gchar *path_tz = "/sys/class/thermal"; - - if (g_file_test(path_tz, G_FILE_TEST_EXISTS)) { - GDir *tz; - - if ((tz = g_dir_open(path_tz, 0, NULL))) { - const gchar *entry; - gchar *temp = g_strdup(""); - - while ((entry = g_dir_read_name(tz))) { - gchar *path = g_strdup_printf("%s/%s/temp", path_tz, entry); - gchar *contents; - - if (g_file_get_contents(path, &contents, NULL, NULL)) { - int temperature; - - sscanf(contents, "%d", &temperature); - - add_sensor("Temperature", - entry, - "thermal", - temperature / 1000.0, - "\302\260C"); - - g_free(contents); - } - } - - g_dir_close(tz); - } - } -} - -static void read_sensors_omnibook(void) { - const gchar *path_ob = "/proc/omnibook/temperature"; - gchar *contents; - - if (g_file_get_contents(path_ob, &contents, NULL, NULL)) { - int temperature; - - sscanf(contents, "CPU temperature: %d C", &temperature); - - add_sensor("Temperature", - "CPU", - "omnibook", - temperature, - "\302\260C\n"); - - g_free(contents); - } -} - -static void read_sensors_hddtemp(void) { - Socket *s; - gchar buffer[1024]; - gint len = 0; - - if (!(s = sock_connect("127.0.0.1", 7634))) - return; - - while (!len) - len = sock_read(s, buffer, sizeof(buffer)); - sock_close(s); - - if (len > 2 && buffer[0] == '|' && buffer[1] == '/') { - gchar **disks; - int i; - - disks = g_strsplit(buffer, "\n", 0); - for (i = 0; disks[i]; i++) { - gchar **fields = g_strsplit(disks[i] + 1, "|", 5); - - /* - * 0 -> /dev/hda - * 1 -> FUJITSU MHV2080AH - * 2 -> 41 - * 3 -> C - */ - const gchar *unit = strcmp(fields[3], "C") - ? "\302\260C" : "\302\260F"; - add_sensor("Hard Drive", - fields[1], - "hddtemp", - atoi(fields[2]), - unit); - - g_strfreev(fields); - } - - g_strfreev(disks); - } -} - -void scan_sensors_do(void) { - g_free(sensors); - sensors = g_strdup(""); - - g_free(lginterval); - lginterval = g_strdup(""); - - read_sensors_hwmon(); - read_sensors_acpi(); - read_sensors_sys_thermal(); - read_sensors_omnibook(); - read_sensors_hddtemp(); - /* FIXME: Add support for ibm acpi and more sensors */ -} - -void sensors_init(void) { - sensor_labels = - g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - sensor_compute = g_hash_table_new(g_str_hash, g_str_equal); -} - -void sensors_shutdown(void) { - g_hash_table_destroy(sensor_labels); - g_hash_table_destroy(sensor_compute); -} diff --git a/modules/devices/sh/processor.c b/modules/devices/sh/processor.c deleted file mode 100644 index 9da2f9b0..00000000 --- a/modules/devices/sh/processor.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -GSList * -processor_scan(void) -{ - Processor *processor; - FILE *cpuinfo; - gchar buffer[128]; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - - processor = g_new0(Processor, 1); - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - - get_str("machine", processor->vendor_id); - get_str("cpu type", processor->model_name); - get_str("cpu family", processor->family); - get_float("cpu clock", processor->cpu_mhz); - get_float("bus clock", processor->bus_mhz); - get_float("module clock", processor->mod_mhz); - get_float("bogomips", processor->bogomips); - } - g_strfreev(tmp); - } - - fclose(cpuinfo); - - STRIFNULL(processor->model_name, _("SuperH Processor")); - UNKIFNULL(processor->vendor_id); - - return g_slist_append(NULL, processor); -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_info(GSList *processors) -{ - Processor *processor = (Processor *)processors->data; - - return g_strdup_printf("[%s]\n" - "%s=%s\n" /* cpu type */ - "%s=%s\n" /* machine */ - "%s=%s\n" /* family */ - "%s=%.2f %s\n" /* frequency */ - "%s=%.2f %s\n" /* bus frequency */ - "%s=%.2f %s\n" /* module frequency */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n", /* byte order */ - _("Processor"), - _("Name"), processor->model_name, - _("Machine"), processor->vendor_id, - _("Family"), processor->family, - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("Bus Frequency"), processor->bus_mhz, _("MHz"), - _("Module Frequency"), processor->mod_mhz, _("MHz"), - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str() - ); -} diff --git a/modules/devices/sparc/processor.c b/modules/devices/sparc/processor.c deleted file mode 100644 index 32c7aa94..00000000 --- a/modules/devices/sparc/processor.c +++ /dev/null @@ -1,80 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -GSList * -processor_scan(void) -{ - Processor *processor; - FILE *cpuinfo; - gchar buffer[128]; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - - processor = g_new0(Processor, 1); - while (fgets(buffer, 128, cpuinfo)) { - gchar **tmp = g_strsplit(buffer, ":", 2); - - if (tmp[0] && tmp[1]) { - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - - get_str("cpucaps", processor->cpucaps); - get_str("cpu", processor->model_name); - get_str("fpu", processor->has_fpu); - } - g_strfreev(tmp); - } - - fclose(cpuinfo); - - processor->cpu_mhz = 0.0f; - - return g_slist_append(NULL, processor); -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar * -processor_get_info(GSList *processors) -{ - Processor *processor = (Processor *)processors->data; - - return g_strdup_printf("[%s]\n" - "%s=%s\n" /* cpu */ - "%s=%s\n" /* fpu */ - "%s=%s\n" /* byte order */ - "%s=%s\n", /* caps */ - _("Processor"), - _("CPU"), processor->model_name, - _("FPU"), processor->has_fpu, - _("Byte Order"), byte_order_str(), - _("Capabilities"), processor->cpucaps - ); -} diff --git a/modules/devices/spd-decode.c b/modules/devices/spd-decode.c deleted file mode 100644 index 2db4895b..00000000 --- a/modules/devices/spd-decode.c +++ /dev/null @@ -1,1512 +0,0 @@ -/* - * spd-decode.c - * Copyright (c) 2010 Leandro A. F. Pereira - * - * Based on decode-dimms.pl - * Copyright 1998, 1999 Philip Edelbrock <phil@netroedge.com> - * modified by Christian Zuckschwerdt <zany@triq.net> - * modified by Burkart Lingner <burkart@bollchen.de> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <ctype.h> -#include <math.h> -#include <stdio.h> -#include <sys/stat.h> - -#include "hardinfo.h" -#include "devices.h" - -typedef enum { - UNKNOWN, - DIRECT_RAMBUS, - RAMBUS, - FPM_DRAM, - EDO, - PIPELINED_NIBBLE, - SDR_SDRAM, - MULTIPLEXED_ROM, - DDR_SGRAM, - DDR_SDRAM, - DDR2_SDRAM, - DDR3_SDRAM -} RamType; - -char *spd_info = NULL; - -static const char *ram_types[] = { - "Unknown", - "Direct Rambus", - "Rambus", - "FPM DRAM", - "EDO", - "Pipelined Nibble", - "SDR SDRAM", - "Multiplexed ROM", - "DDR SGRAM", - "DDR SDRAM", - "DDR2 SDRAM", - "DDR3 SDRAM" -}; - -static const char *vendors1[] = { "AMD", "AMI", "Fairchild", "Fujitsu", - "GTE", "Harris", "Hitachi", "Inmos", - "Intel", "I.T.T.", "Intersil", - "Monolithic Memories", - "Mostek", - "Freescale (former Motorola)", - "National", "NEC", - "RCA", "Raytheon", - "Conexant (Rockwell)", "Seeq", - "NXP (former Signetics, Philips Semi.)", - "Synertek", - "Texas Instruments", "Toshiba", - "Xicor", "Zilog", "Eurotechnique", - "Mitsubishi", - "Lucent (AT&T)", "Exel", "Atmel", - "SGS/Thomson", - "Lattice Semi.", "NCR", - "Wafer Scale Integration", "IBM", - "Tristar", "Visic", - "Intl. CMOS Technology", "SSSI", - "MicrochipTechnology", "Ricoh Ltd.", - "VLSI", "Micron Technology", - "Hyundai Electronics", - "OKI Semiconductor", "ACTEL", - "Sharp", - "Catalyst", "Panasonic", "IDT", - "Cypress", - "DEC", "LSI Logic", - "Zarlink (former Plessey)", "UTMC", - "Thinking Machine", "Thomson CSF", - "Integrated CMOS (Vertex)", - "Honeywell", - "Tektronix", "Sun Microsystems", - "SST", "ProMos/Mosel Vitelic", - "Infineon (former Siemens)", - "Macronix", "Xerox", "Plus Logic", - "SunDisk", "Elan Circuit Tech.", - "European Silicon Str.", - "Apple Computer", - "Xilinx", "Compaq", - "Protocol Engines", "SCI", - "Seiko Instruments", "Samsung", - "I3 Design System", "Klic", - "Crosspoint Solutions", - "Alliance Semiconductor", "Tandem", - "Hewlett-Packard", - "Intg. Silicon Solutions", - "Brooktree", "New Media", - "MHS Electronic", - "Performance Semi.", - "Winbond Electronic", - "Kawasaki Steel", - "Bright Micro", - "TECMAR", "Exar", "PCMCIA", - "LG Semi (former Goldstar)", - "Northern Telecom", "Sanyo", - "Array Microsystems", - "Crystal Semiconductor", - "Analog Devices", "PMC-Sierra", - "Asparix", "Convex Computer", - "Quality Semiconductor", - "Nimbus Technology", "Transwitch", - "Micronas (ITT Intermetall)", - "Cannon", "Altera", "NEXCOM", - "QUALCOMM", - "Sony", "Cray Research", - "AMS(Austria Micro)", "Vitesse", - "Aster Electronics", - "Bay Networks (Synoptic)", - "Zentrum or ZMD", - "TRW", - "Thesys", "Solbourne Computer", - "Allied-Signal", "Dialog", - "Media Vision", - "Level One Communication" -}; - -static const char *vendors2[] = { "Cirrus Logic", - "National Instruments", - "ILC Data Device", - "Alcatel Mietec", - "Micro Linear", - "Univ. of NC", - "JTAG Technologies", - "BAE Systems", - "Nchip", - "Galileo Tech", - "Bestlink Systems", - "Graychip", - "GENNUM", - "VideoLogic", - "Robert Bosch", - "Chip Express", - "DATARAM", - "United Microelec Corp.", - "TCSI", - "Smart Modular", - "Hughes Aircraft", - "Lanstar Semiconductor", - "Qlogic", "Kingston", - "Music Semi", - "Ericsson Components", - "SpaSE", - "Eon Silicon Devices", - "Programmable Micro Corp", - "DoD", - "Integ. Memories Tech.", - "Corollary Inc.", - "Dallas Semiconductor", - "Omnivision", - "EIV(Switzerland)", - "Novatel Wireless", - "Zarlink (former Mitel)", - "Clearpoint", - "Cabletron", - "STEC (former Silicon Technology)", - "Vanguard", - "Hagiwara Sys-Com", - "Vantis", "Celestica", - "Century", - "Hal Computers", - "Rohm Company Ltd.", - "Juniper Networks", - "Libit Signal Processing", - "Mushkin Enhanced Memory", - "Tundra Semiconductor", - "Adaptec Inc.", - "LightSpeed Semi.", - "ZSP Corp.", - "AMIC Technology", - "Adobe Systems", - "Dynachip", - "PNY Electronics", - "Newport Digital", - "MMC Networks", - "T Square", - "Seiko Epson", - "Broadcom", - "Viking Components", - "V3 Semiconductor", - "Flextronics (former Orbit)", - "Suwa Electronics", - "Transmeta", - "Micron CMS", - "American Computer & Digital Components Inc", - "Enhance 3000 Inc", - "Tower Semiconductor", - "CPU Design", - "Price Point", - "Maxim Integrated Product", - "Tellabs", - "Centaur Technology", - "Unigen Corporation", - "Transcend Information", - "Memory Card Technology", - "CKD Corporation Ltd.", - "Capital Instruments, Inc.", - "Aica Kogyo, Ltd.", - "Linvex Technology", - "MSC Vertriebs GmbH", - "AKM Company, Ltd.", - "Dynamem, Inc.", - "NERA ASA", - "GSI Technology", - "Dane-Elec (C Memory)", - "Acorn Computers", - "Lara Technology", - "Oak Technology, Inc.", - "Itec Memory", - "Tanisys Technology", - "Truevision", - "Wintec Industries", - "Super PC Memory", - "MGV Memory", - "Galvantech", - "Gadzoox Nteworks", - "Multi Dimensional Cons.", - "GateField", - "Integrated Memory System", - "Triscend", "XaQti", - "Goldenram", - "Clear Logic", - "Cimaron Communications", - "Nippon Steel Semi. Corp.", - "Advantage Memory", - "AMCC", - "LeCroy", - "Yamaha Corporation", - "Digital Microwave", - "NetLogic Microsystems", - "MIMOS Semiconductor", - "Advanced Fibre", - "BF Goodrich Data.", - "Epigram", - "Acbel Polytech Inc.", - "Apacer Technology", - "Admor Memory", - "FOXCONN", - "Quadratics Superconductor", - "3COM", -}; - -static const char *vendors3[] = { "Camintonn Corporation", "ISOA Incorporated", - "Agate Semiconductor", "ADMtek Incorporated", - "HYPERTEC", "Adhoc Technologies", "MOSAID Technologies", - "Ardent Technologies", - "Switchcore", "Cisco Systems, Inc.", "Allayer Technologies", - "WorkX AG", - "Oasis Semiconductor", "Novanet Semiconductor", "E-M Solutions", - "Power General", - "Advanced Hardware Arch.", "Inova Semiconductors GmbH", "Telocity", - "Delkin Devices", - "Symagery Microsystems", "C-Port Corporation", - "SiberCore Technologies", "Southland Microsystems", - "Malleable Technologies", "Kendin Communications", - "Great Technology Microcomputer", "Sanmina Corporation", - "HADCO Corporation", "Corsair", "Actrans System Inc.", - "ALPHA Technologies", - "Silicon Laboratories, Inc. (Cygnal)", "Artesyn Technologies", - "Align Manufacturing", "Peregrine Semiconductor", - "Chameleon Systems", "Aplus Flash Technology", "MIPS Technologies", - "Chrysalis ITS", - "ADTEC Corporation", "Kentron Technologies", "Win Technologies", - "Tachyon Semiconductor (former ASIC Designs Inc.)", - "Extreme Packet Devices", "RF Micro Devices", "Siemens AG", - "Sarnoff Corporation", - "Itautec Philco SA", "Radiata Inc.", "Benchmark Elect. (AVEX)", - "Legend", - "SpecTek Incorporated", "Hi/fn", "Enikia Incorporated", - "SwitchOn Networks", - "AANetcom Incorporated", "Micro Memory Bank", "ESS Technology", - "Virata Corporation", - "Excess Bandwidth", "West Bay Semiconductor", "DSP Group", - "Newport Communications", - "Chip2Chip Incorporated", "Phobos Corporation", - "Intellitech Corporation", "Nordic VLSI ASA", - "Ishoni Networks", "Silicon Spice", "Alchemy Semiconductor", - "Agilent Technologies", - "Centillium Communications", "W.L. Gore", "HanBit Electronics", - "GlobeSpan", - "Element 14", "Pycon", "Saifun Semiconductors", "Sibyte, Incorporated", - "MetaLink Technologies", "Feiya Technology", "I & C Technology", - "Shikatronics", - "Elektrobit", "Megic", "Com-Tier", "Malaysia Micro Solutions", - "Hyperchip", "Gemstone Communications", "Anadigm (former Anadyne)", - "3ParData", - "Mellanox Technologies", "Tenx Technologies", "Helix AG", "Domosys", - "Skyup Technology", "HiNT Corporation", "Chiaro", - "MDT Technologies GmbH (former MCI Computer GMBH)", - "Exbit Technology A/S", "Integrated Technology Express", "AVED Memory", - "Legerity", - "Jasmine Networks", "Caspian Networks", "nCUBE", - "Silicon Access Networks", - "FDK Corporation", "High Bandwidth Access", "MultiLink Technology", - "BRECIS", - "World Wide Packets", "APW", "Chicory Systems", "Xstream Logic", - "Fast-Chip", "Zucotto Wireless", "Realchip", "Galaxy Power", - "eSilicon", "Morphics Technology", "Accelerant Networks", - "Silicon Wave", - "SandCraft", "Elpida" -}; - -static const char *vendors4[] = { "Solectron", "Optosys Technologies", - "Buffalo (former Melco)", - "TriMedia Technologies", - "Cyan Technologies", "Global Locate", - "Optillion", - "Terago Communications", - "Ikanos Communications", - "Princeton Technology", - "Nanya Technology", - "Elite Flash Storage", - "Mysticom", "LightSand Communications", - "ATI Technologies", - "Agere Systems", - "NeoMagic", "AuroraNetics", "Golden Empire", - "Mushkin", - "Tioga Technologies", "Netlist", "TeraLogic", - "Cicada Semiconductor", - "Centon Electronics", "Tyco Electronics", - "Magis Works", "Zettacom", - "Cogency Semiconductor", "Chipcon AS", - "Aspex Technology", - "F5 Networks", - "Programmable Silicon Solutions", - "ChipWrights", - "Acorn Networks", - "Quicklogic", - "Kingmax Semiconductor", "BOPS", "Flasys", - "BitBlitz Communications", - "eMemory Technology", "Procket Networks", - "Purple Ray", - "Trebia Networks", - "Delta Electronics", "Onex Communications", - "Ample Communications", - "Memory Experts Intl", - "Astute Networks", "Azanda Network Devices", - "Dibcom", "Tekmos", - "API NetWorks", "Bay Microsystems", - "Firecron Ltd", - "Resonext Communications", - "Tachys Technologies", "Equator Technology", - "Concept Computer", - "SILCOM", - "3Dlabs", "c't Magazine", "Sanera Systems", - "Silicon Packets", - "Viasystems Group", "Simtek", - "Semicon Devices Singapore", - "Satron Handelsges", - "Improv Systems", "INDUSYS GmbH", "Corrent", - "Infrant Technologies", - "Ritek Corp", "empowerTel Networks", - "Hypertec", - "Cavium Networks", - "PLX Technology", "Massana Design", - "Intrinsity", - "Valence Semiconductor", - "Terawave Communications", - "IceFyre Semiconductor", "Primarion", - "Picochip Designs Ltd", - "Silverback Systems", - "Jade Star Technologies", - "Pijnenburg Securealink", - "TakeMS International AG", - "Cambridge Silicon Radio", - "Swissbit", "Nazomi Communications", - "eWave System", - "Rockwell Collins", "Picocel Co., Ltd.", - "Alphamosaic Ltd", - "Sandburst", - "SiCon Video", "NanoAmp Solutions", - "Ericsson Technology", - "PrairieComm", - "Mitac International", "Layer N Networks", - "MtekVision", - "Allegro Networks", - "Marvell Semiconductors", - "Netergy Microelectronic", "NVIDIA", - "Internet Machines", - "Peak Electronics", - "Litchfield Communication", - "Accton Technology", - "Teradiant Networks", - "Europe Technologies", "Cortina Systems", - "RAM Components", - "Raqia Networks", - "ClearSpeed", "Matsushita Battery", - "Xelerated", - "SimpleTech", - "Utron Technology", "Astec International", - "AVM gmbH", - "Redux Communications", - "Dot Hill Systems", "TeraChip" -}; - -static const char *vendors5[] = { "T-RAM Incorporated", - "Innovics Wireless", "Teknovus", "KeyEye Communications", - "Runcom Technologies", "RedSwitch", "Dotcast", - "Silicon Mountain Memory", - "Signia Technologies", "Pixim", "Galazar Networks", - "White Electronic Designs", - "Patriot Scientific", "Neoaxiom Corporation", "3Y Power Technology", - "Europe Technologies", - "Potentia Power Systems", "C-guys Incorporated", - "Digital Communications Technology Incorporated", - "Silicon-Based Technology", - "Fulcrum Microsystems", "Positivo Informatica Ltd", - "XIOtech Corporation", "PortalPlayer", - "Zhiying Software", "Direct2Data", "Phonex Broadband", - "Skyworks Solutions", - "Entropic Communications", "Pacific Force Technology", "Zensys A/S", - "Legend Silicon Corp.", - "sci-worx GmbH", "SMSC (former Oasis Silicon Systems)", - "Renesas Technology", "Raza Microelectronics", - "Phyworks", "MediaTek", "Non-cents Productions", "US Modular", - "Wintegra Ltd", "Mathstar", "StarCore", "Oplus Technologies", - "Mindspeed", "Just Young Computer", "Radia Communications", "OCZ", - "Emuzed", "LOGIC Devices", "Inphi Corporation", "Quake Technologies", - "Vixel", "SolusTek", "Kongsberg Maritime", "Faraday Technology", - "Altium Ltd.", "Insyte", "ARM Ltd.", "DigiVision", - "Vativ Technologies", "Endicott Interconnect Technologies", "Pericom", - "Bandspeed", - "LeWiz Communications", "CPU Technology", "Ramaxel Technology", - "DSP Group", - "Axis Communications", "Legacy Electronics", "Chrontel", - "Powerchip Semiconductor", - "MobilEye Technologies", "Excel Semiconductor", "A-DATA Technology", - "VirtualDigm", - "G Skill Intl", "Quanta Computer", "Yield Microelectronics", - "Afa Technologies", - "KINGBOX Technology Co. Ltd.", "Ceva", "iStor Networks", - "Advance Modules", - "Microsoft", "Open-Silicon", "Goal Semiconductor", - "ARC International", - "Simmtec", "Metanoia", "Key Stream", "Lowrance Electronics", - "Adimos", "SiGe Semiconductor", "Fodus Communications", - "Credence Systems Corp.", - "Genesis Microchip Inc.", "Vihana, Inc.", "WIS Technologies", - "GateChange Technologies", - "High Density Devices AS", "Synopsys", "Gigaram", - "Enigma Semiconductor Inc.", - "Century Micro Inc.", "Icera Semiconductor", - "Mediaworks Integrated Systems", "O'Neil Product Development", - "Supreme Top Technology Ltd.", "MicroDisplay Corporation", - "Team Group Inc.", "Sinett Corporation", - "Toshiba Corporation", "Tensilica", "SiRF Technology", "Bacoc Inc.", - "SMaL Camera Technologies", "Thomson SC", "Airgo Networks", - "Wisair Ltd.", - "SigmaTel", "Arkados", "Compete IT gmbH Co. KG", - "Eudar Technology Inc.", - "Focus Enhancements", "Xyratex" -}; - -static const char *vendors6[] = { "Specular Networks", - "Patriot Memory", - "U-Chip Technology Corp.", - "Silicon Optix", - "Greenfield Networks", - "CompuRAM GmbH", "Stargen, Inc.", - "NetCell Corporation", - "Excalibrus Technologies Ltd", - "SCM Microsystems", - "Xsigo Systems, Inc.", - "CHIPS & Systems Inc", - "Tier 1 Multichip Solutions", - "CWRL Labs", "Teradici", - "Gigaram, Inc.", - "g2 Microsystems", - "PowerFlash Semiconductor", - "P.A. Semi, Inc.", - "NovaTech Solutions, S.A.", - "c2 Microsystems, Inc.", - "Level5 Networks", - "COS Memory AG", - "Innovasic Semiconductor", - "02IC Co. Ltd", "Tabula, Inc.", - "Crucial Technology", - "Chelsio Communications", - "Solarflare Communications", - "Xambala Inc.", "EADS Astrium", - "ATO Semicon Co. Ltd.", - "Imaging Works, Inc.", - "Astute Networks, Inc.", "Tzero", - "Emulex", - "Power-One", "Pulse~LINK Inc.", - "Hon Hai Precision Industry", - "White Rock Networks Inc.", - "Telegent Systems USA, Inc.", - "Atrua Technologies, Inc.", - "Acbel Polytech Inc.", - "eRide Inc.", - "ULi Electronics Inc.", - "Magnum Semiconductor Inc.", - "neoOne Technology, Inc.", - "Connex Technology, Inc.", - "Stream Processors, Inc.", - "Focus Enhancements", - "Telecis Wireless, Inc.", - "uNav Microelectronics", - "Tarari, Inc.", "Ambric, Inc.", - "Newport Media, Inc.", "VMTS", - "Enuclia Semiconductor, Inc.", - "Virtium Technology Inc.", - "Solid State System Co., Ltd.", - "Kian Tech LLC", - "Artimi", - "Power Quotient International", - "Avago Technologies", - "ADTechnology", "Sigma Designs", - "SiCortex, Inc.", - "Ventura Technology Group", - "eASIC", "M.H.S. SAS", - "Micro Star International", - "Rapport Inc.", - "Makway International", - "Broad Reach Engineering Co.", - "Semiconductor Mfg Intl Corp", - "SiConnect", "FCI USA Inc.", - "Validity Sensors", - "Coney Technology Co. Ltd.", - "Spans Logic", "Neterion Inc.", - "Qimonda", - "New Japan Radio Co. Ltd.", - "Velogix", "Montalvo Systems", - "iVivity Inc.", - "Walton Chaintech", - "AENEON", - "Lorom Industrial Co. Ltd.", - "Radiospire Networks", - "Sensio Technologies, Inc.", - "Nethra Imaging", - "Hexon Technology Pte Ltd", - "CompuStocx (CSX)", - "Methode Electronics, Inc.", - "Connect One Ltd.", - "Opulan Technologies", - "Septentrio NV", - "Goldenmars Technology Inc.", - "Kreton Corporation", - "Cochlear Ltd.", - "Altair Semiconductor", - "NetEffect, Inc.", - "Spansion, Inc.", - "Taiwan Semiconductor Mfg", - "Emphany Systems Inc.", - "ApaceWave Technologies", - "Mobilygen Corporation", "Tego", - "Cswitch Corporation", - "Haier (Beijing) IC Design Co.", - "MetaRAM", - "Axel Electronics Co. Ltd.", - "Tilera Corporation", - "Aquantia", - "Vivace Semiconductor", - "Redpine Signals", "Octalica", - "InterDigital Communications", - "Avant Technology", - "Asrock, Inc.", "Availink", - "Quartics, Inc.", - "Element CXI", - "Innovaciones Microelectronicas", - "VeriSilicon Microelectronics", - "W5 Networks" -}; - -static const char *vendors7[] = { "MOVEKING", "Mavrix Technology, Inc.", - "CellGuide Ltd.", "Faraday Technology", - "Diablo Technologies, Inc.", "Jennic", "Octasic", - "Molex Incorporated", - "3Leaf Networks", - "Bright Micron Technology", "Netxen", "NextWave Broadband Inc.", - "DisplayLink", "ZMOS Technology", - "Tec-Hill", "Multigig, Inc.", "Amimon", "Euphonic Technologies, Inc.", - "BRN Phoenix", - "InSilica", "Ember Corporation", "Avexir Technologies Corporation", - "Echelon Corporation", - "Edgewater Computer Systems", "XMOS Semiconductor Ltd.", - "GENUSION, Inc.", "Memory Corp NV", - "SiliconBlue Technologies", "Rambus Inc." -}; - -static const char **vendors[7] = { vendors1, vendors2, vendors3, vendors4, vendors5, vendors6, - vendors7 -}; - -/* - * We consider that no data was written to this area of the SPD EEPROM if - * all bytes read 0x00 or all bytes read 0xff - */ -static int spd_written(unsigned char *bytes, int len) -{ - do { - if (*bytes == 0x00 || *bytes == 0xFF) - return 1; - } while (--len && bytes++); - - return 0; -} - -static int parity(int value) -{ - value ^= value >> 16; - value ^= value >> 8; - value ^= value >> 4; - value &= 0xf; - - return (0x6996 >> value) & 1; -} - -static void decode_sdr_module_size(unsigned char *bytes, int *size) -{ - int i, k = 0; - - i = (bytes[3] & 0x0f) + (bytes[4] & 0x0f) - 17; - if (bytes[5] <= 8 && bytes[17] <= 8) { - k = bytes[5] * bytes[17]; - } - - if (i > 0 && i <= 12 && k > 0) { - if (size) { - *size = (1 << i) * k; - } - } else { - if (size) { - *size = -1; - } - } -} - -static void decode_sdr_module_timings(unsigned char *bytes, float *tcl, float *trcd, float *trp, float *tras) -{ - float cas[3], ctime; - int i, j; - - for (i = 0, j = 0; j < 7; j++) { - if (bytes[18] & 1 << j) { - cas[i++] = j + 1; - } - } - - ctime = (bytes[9] >> 4 + bytes[9] & 0xf) * 0.1; - - if (trcd) { - *trcd = ceil(bytes[29] / ctime); - } - if (trp) { - *trp = ceil(bytes[27] / ctime); - } - if (tras) { - *tras = ceil(bytes[30] / ctime); - } - if (tcl) { - *tcl = cas[i]; - } -} - -static void decode_sdr_module_row_address_bits(unsigned char *bytes, char **bits) -{ - char *temp; - - switch (bytes[3]) { - case 0: - temp = "Undefined"; - break; - case 1: - temp = "1/16"; - break; - case 2: - temp = "2/27"; - break; - case 3: - temp = "3/18"; - break; - default: - /* printf("%d\n", bytes[3]); */ - temp = "Unknown"; - } - - if (bits) { - *bits = temp; - } -} - -static void decode_sdr_module_col_address_bits(unsigned char *bytes, char **bits) -{ - char *temp; - - switch (bytes[4]) { - case 0: - temp = "Undefined"; - break; - case 1: - temp = "1/16"; - break; - case 2: - temp = "2/17"; - break; - case 3: - temp = "3/18"; - break; - default: - /*printf("%d\n", bytes[4]); */ - temp = "Unknown"; - } - - if (bits) { - *bits = temp; - } -} - -static void decode_sdr_module_number_of_rows(unsigned char *bytes, int *rows) -{ - if (rows) { - *rows = bytes[5]; - } -} - -static void decode_sdr_module_data_with(unsigned char *bytes, int *width) -{ - if (width) { - if (bytes[7] > 1) { - *width = 0; - } else { - *width = (bytes[7] * 0xff) + bytes[6]; - } - } -} - -static void decode_sdr_module_interface_signal_levels(unsigned char *bytes, char **signal_levels) -{ - char *temp; - - switch (bytes[8]) { - case 0: - temp = "5.0 Volt/TTL"; - break; - case 1: - temp = "LVTTL"; - break; - case 2: - temp = "HSTL 1.5"; - break; - case 3: - temp = "SSTL 3.3"; - break; - case 4: - temp = "SSTL 2.5"; - break; - case 255: - temp = "New Table"; - break; - default: - temp = "Undefined"; - } - - if (signal_levels) { - *signal_levels = temp; - } -} - -static void decode_sdr_module_configuration_type(unsigned char *bytes, char **module_config_type) -{ - char *temp; - - switch (bytes[11]) { - case 0: - temp = "No parity"; - break; - case 1: - temp = "Parity"; - break; - case 2: - temp = "ECC"; - break; - default: - temp = "Undefined"; - } - - if (module_config_type) { - *module_config_type = temp; - } -} - -static void decode_sdr_module_refresh_type(unsigned char *bytes, char **refresh_type) -{ - char *temp; - - if (bytes[12] & 0x80) { - temp = "Self refreshing"; - } else { - temp = "Not self refreshing"; - } - - if (refresh_type) { - *refresh_type = temp; - } -} - -static void decode_sdr_module_refresh_rate(unsigned char *bytes, char **refresh_rate) -{ - char *temp; - - switch (bytes[12] & 0x7f) { - case 0: - temp = "Normal (15.625us)"; - break; - case 1: - temp = "Reduced (3.9us)"; - break; - case 2: - temp = "Reduced (7.8us)"; - break; - case 3: - temp = "Extended (31.3us)"; - break; - case 4: - temp = "Extended (62.5us)"; - break; - case 5: - temp = "Extended (125us)"; - break; - default: - temp = "Undefined"; - } - - if (refresh_rate) { - *refresh_rate = temp; - } -} - -static gchar *decode_sdr_sdram(unsigned char *bytes, int *size) -{ - int rows, data_width; - float tcl, trcd, trp, tras; - char *row_address_bits, *col_address_bits, *signal_level; - char *module_config_type, *refresh_type, *refresh_rate; - - decode_sdr_module_size(bytes, size); - decode_sdr_module_timings(bytes, &tcl, &trcd, &trp, &tras); - decode_sdr_module_row_address_bits(bytes, &row_address_bits); - decode_sdr_module_col_address_bits(bytes, &col_address_bits); - decode_sdr_module_number_of_rows(bytes, &rows); - decode_sdr_module_data_with(bytes, &data_width); - decode_sdr_module_interface_signal_levels(bytes, &signal_level); - decode_sdr_module_configuration_type(bytes, &module_config_type); - decode_sdr_module_refresh_type(bytes, &refresh_type); - decode_sdr_module_refresh_rate(bytes, &refresh_rate); - - /* TODO: - - RAS to CAS delay - - Supported CAS latencies - - Supported CS latencies - - Supported WE latencies - - Cycle Time / Access time - - SDRAM module attributes - - SDRAM device attributes - - Row densities - - Other misc stuff - */ - - return g_strdup_printf("[Module Information]\n" - "Module type=SDR\n" - "SPD revision=%d\n" - "Row address bits=%s\n" - "Column address bits=%s\n" - "Number of rows=%d\n" - "Data width=%d bits\n" - "Interface signal levels=%s\n" - "Configuration type=%s\n" - "Refresh=%s (%s)\n" - "[Timings]\n" - "tCL=%.2f\n" - "tRCD=%.2f\n" - "tRP=%.2f\n" - "tRAS=%.2f\n", - bytes[62], - row_address_bits, col_address_bits, rows, - data_width, signal_level, module_config_type, - refresh_type, refresh_rate, tcl, trcd, trp, tras); -} - -static void decode_ddr_module_speed(unsigned char *bytes, float *ddrclk, int *pcclk) -{ - float temp, clk; - int tbits, pc; - - temp = (bytes[9] >> 4) + (bytes[9] & 0xf) * 0.1; - clk = 2 * (1000 / temp); - tbits = (bytes[7] * 256) + bytes[6]; - - if (bytes[11] == 2 || bytes[11] == 1) { - tbits -= 8; - } - - pc = clk * tbits / 8; - if (pc % 100 > 50) { - pc += 100; - } - pc -= pc % 100; - - if (ddrclk) - *ddrclk = (int) clk; - - if (pcclk) - *pcclk = pc; -} - -static void decode_ddr_module_size(unsigned char *bytes, int *size) -{ - int i, k; - - i = (bytes[3] & 0x0f) + (bytes[4] & 0x0f) - 17; - k = (bytes[5] <= 8 && bytes[17] <= 8) ? bytes[5] * bytes[17] : 0; - - if (i > 0 && i <= 12 && k > 0) { - if (size) { - *size = (1 << i) * k; - } - } else { - if (size) { - *size = -1; - } - } -} - -static void *decode_ddr_module_timings(unsigned char *bytes, float *tcl, float *trcd, float *trp, float *tras) -{ - float ctime; - float highest_cas = 0; - int i; - - for (i = 0; i < 7; i++) { - if (bytes[18] & (1 << i)) { - highest_cas = 1 + i * 0.5f; - } - } - - ctime = (bytes[9] >> 4) + (bytes[9] & 0xf) * 0.1; - - if (trcd) { - *trcd = (bytes[29] >> 2) + ((bytes[29] & 3) * 0.25); - *trcd = ceil(*trcd / ctime); - } - - if (trp) { - *trp = (bytes[27] >> 2) + ((bytes[27] & 3) * 0.25); - *trp = ceil(*trp / ctime); - } - - if (tras) { - *tras = bytes[30]; - *tras = ceil(*tras / ctime); - } - - if (tcl) { - *tcl = highest_cas; - } -} - -static gchar *decode_ddr_sdram(unsigned char *bytes, int *size) -{ - float ddr_clock; - float tcl, trcd, trp, tras; - int pc_speed; - - decode_ddr_module_speed(bytes, &ddr_clock, &pc_speed); - decode_ddr_module_size(bytes, size); - decode_ddr_module_timings(bytes, &tcl, &trcd, &trp, &tras); - - return g_strdup_printf("[Module Information]\n" - "Module type=DDR %.2fMHz (PC%d)\n" - "SPD revision=%d.%d\n" - "[Timings]\n" - "tCL=%.2f\n" - "tRCD=%.2f\n" - "tRP=%.2f\n" - "tRAS=%.2f\n", ddr_clock, pc_speed, bytes[62] >> 4, bytes[62] & 0xf, tcl, trcd, trp, tras); -} - -static float decode_ddr2_module_ctime(unsigned char byte) -{ - float ctime; - - ctime = (byte >> 4); - byte &= 0xf; - - if (byte <= 9) { - ctime += byte * 0.1; - } else if (byte == 10) { - ctime += 0.25; - } else if (byte == 11) { - ctime += 0.33; - } else if (byte == 12) { - ctime += 0.66; - } else if (byte == 13) { - ctime += 0.75; - } - - return ctime; -} - -static void decode_ddr2_module_speed(unsigned char *bytes, float *ddr_clock, int *pc2_speed) -{ - float ctime; - float ddrclk; - int tbits, pcclk; - - ctime = decode_ddr2_module_ctime(bytes[9]); - ddrclk = 2 * (1000 / ctime); - - tbits = (bytes[7] * 256) + bytes[6]; - if (bytes[11] & 0x03) { - tbits -= 8; - } - - pcclk = ddrclk * tbits / 8; - pcclk -= pcclk % 100; - - if (ddr_clock) { - *ddr_clock = (int) ddrclk; - } - if (pc2_speed) { - *pc2_speed = pcclk; - } -} - -static void decode_ddr2_module_size(unsigned char *bytes, int *size) -{ - int i, k; - - i = (bytes[3] & 0x0f) + (bytes[4] & 0x0f) - 17; - k = ((bytes[5] & 0x7) + 1) * bytes[17]; - - if (i > 0 && i <= 12 && k > 0) { - if (*size) { - *size = ((1 << i) * k); - } - } else { - if (*size) { - *size = 0; - } - } -} - -static void decode_ddr2_module_timings(unsigned char *bytes, float *trcd, float *trp, float *tras, float *tcl) -{ - float ctime; - float highest_cas = 0; - int i; - - for (i = 0; i < 7; i++) { - if (bytes[18] & (1 << i)) { - highest_cas = i; - } - } - - ctime = decode_ddr2_module_ctime(bytes[9]); - - if (trcd) { - *trcd = ceil(((bytes[29] >> 2) + ((bytes[29] & 3) * 0.25)) / ctime); - } - - if (trp) { - *trp = ceil(((bytes[27] >> 2) + ((bytes[27] & 3) * 0.25)) / ctime); - } - - if (tras) { - *tras = ceil(bytes[30] / ctime); - } - - if (tcl) { - *tcl = highest_cas; - } -} - -static gchar *decode_ddr2_sdram(unsigned char *bytes, int *size) -{ - float ddr_clock; - float trcd, trp, tras, tcl; - int pc2_speed; - - decode_ddr2_module_speed(bytes, &ddr_clock, &pc2_speed); - decode_ddr2_module_size(bytes, size); - decode_ddr2_module_timings(bytes, &trcd, &trp, &tras, &tcl); - - return g_strdup_printf("[Module Information]\n" - "Module type=DDR2 %.2f MHz (PC2-%d)\n" - "SPD revision=%d.%d\n" - "[Timings]\n" - "tCL=%.2f\n" - "tRCD=%.2f\n" - "tRP=%.2f\n" - "tRAS=%.2f\n", ddr_clock, pc2_speed, bytes[62] >> 4, bytes[62] & 0xf, tcl, trcd, trp, tras); -} - -static void decode_ddr3_module_speed(unsigned char *bytes, float *ddr_clock, int *pc3_speed) -{ - float ctime; - float ddrclk; - int tbits, pcclk; - float mtb = 0.125; - - if (bytes[10] == 1 && bytes[11] == 8) - mtb = 0.125; - if (bytes[10] == 1 && bytes[11] == 15) - mtb = 0.0625; - ctime = mtb * bytes[12]; - - ddrclk = 2 * (1000 / ctime); - - tbits = 64; - switch (bytes[8]) { - case 1: - tbits = 16; - break; - case 4: - tbits = 32; - break; - case 3: - case 0xb: - tbits = 64; - break; - } - - pcclk = ddrclk * tbits / 8; - pcclk -= pcclk % 100; - - if (ddr_clock) { - *ddr_clock = (int) ddrclk; - } - if (pc3_speed) { - *pc3_speed = pcclk; - } -} - -static void decode_ddr3_module_size(unsigned char *bytes, int *size) -{ - *size = 512 << bytes[4]; -} - -static void decode_ddr3_module_timings(unsigned char *bytes, float *trcd, float *trp, float *tras, float *tcl) -{ - float ctime; - float highest_cas = 0; - int i; - float mtb = 0.125; - - if (bytes[10] == 1 && bytes[11] == 8) - mtb = 0.125; - if (bytes[10] == 1 && bytes[11] == 15) - mtb = 0.0625; - ctime = mtb * bytes[12]; - - switch (bytes[14]) { - case 6: - highest_cas = 5; - break; - case 4: - highest_cas = 6; - break; - case 0xc: - highest_cas = 7; - break; - case 0x1e: - highest_cas = 8; - break; - } - if (trcd) { - *trcd = bytes[18] * mtb; - } - - if (trp) { - *trp = bytes[20] * mtb; - } - - if (tras) { - *tras = (bytes[22] + bytes[21] & 0xf) * mtb; - } - - if (tcl) { - *tcl = highest_cas; - } -} - -static void decode_ddr3_module_type(unsigned char *bytes, const char **type) -{ - switch (bytes[3]) { - case 0x00: - *type = "Undefined"; - break; - case 0x01: - *type = "RDIMM (Registered Long DIMM)"; - break; - case 0x02: - *type = "UDIMM (Unbuffered Long DIMM)"; - break; - case 0x03: - *type = "SODIMM (Small Outline DIMM)"; - break; - default: - *type = "Unknown"; - } -} - -static gchar *decode_ddr3_sdram(unsigned char *bytes, int *size) -{ - float ddr_clock; - float trcd, trp, tras, tcl; - int pc3_speed; - const char *type; - - decode_ddr3_module_speed(bytes, &ddr_clock, &pc3_speed); - decode_ddr3_module_size(bytes, size); - decode_ddr3_module_timings(bytes, &trcd, &trp, &tras, &tcl); - decode_ddr3_module_type(bytes, &type); - - return g_strdup_printf("[Module Information]\n" - "Module type=DDR3 %.2f MHz (PC3-%d)\n" - "SPD revision=%d.%d\n" - "Type=%s\n" - "[Timings]\n" - "tCL=%.2f\n" - "tRCD=%.3fns\n" - "tRP=%.3fns\n" - "tRAS=%.3fns\n", - ddr_clock, pc3_speed, - bytes[1] >> 4, bytes[1] & 0xf, - type, - tcl, - trcd, - trp, - tras); -} - -static void decode_ddr3_part_number(unsigned char *bytes, char *part_number) -{ - int i; - if (part_number) { - for (i = 128; i <= 145; i++) - *part_number++ = bytes[i]; - *part_number = '\0'; - } -} - -static void decode_ddr3_manufacturer(unsigned char *bytes, char **manufacturer) -{ - char *out = "Unknown"; - - end: - if (manufacturer) { - *manufacturer = out; - } -} - -static void decode_module_manufacturer(unsigned char *bytes, char **manufacturer) -{ - char *out = "Unknown"; - unsigned char first; - int ai = 0; - int len = 8; - unsigned char *initial = bytes; - - if (!spd_written(bytes, 8)) { - out = "Undefined"; - goto end; - } - - do { - ai++; - } while ((--len && (*bytes++ == 0x7f))); - first = *--bytes; - - if (ai == 0) { - out = "Invalid"; - goto end; - } - - if (parity(first) != 1) { - out = "Invalid"; - goto end; - } - - out = (char *) vendors[ai - 1][(first & 0x7f) - 1]; - - end: - if (manufacturer) { - *manufacturer = out; - } -} - -static void decode_module_part_number(unsigned char *bytes, char *part_number) -{ - if (part_number) { - bytes += 8 + 64; - - while (*bytes++ && *bytes >= 32 && *bytes < 127) { - *part_number++ = *bytes; - } - *part_number = '\0'; - } -} - -static int decode_ram_type(unsigned char *bytes) -{ - if (bytes[0] < 4) { - switch (bytes[2]) { - case 1: - return DIRECT_RAMBUS; - case 17: - return RAMBUS; - } - } else { - switch (bytes[2]) { - case 1: - return FPM_DRAM; - case 2: - return EDO; - case 3: - return PIPELINED_NIBBLE; - case 4: - return SDR_SDRAM; - case 5: - return MULTIPLEXED_ROM; - case 6: - return DDR_SGRAM; - case 7: - return DDR_SDRAM; - case 8: - return DDR2_SDRAM; - case 11: - return DDR3_SDRAM; - } - } - - return UNKNOWN; -} - -static void read_spd(char *spd_path, int offset, size_t size, int use_sysfs, unsigned char *bytes_out) -{ - if (use_sysfs) { - FILE *spd; - gchar *temp_path; - - temp_path = g_strdup_printf("%s/eeprom", spd_path); - if ((spd = fopen(temp_path, "rb"))) { - fseek(spd, offset, SEEK_SET); - fread(bytes_out, 1, size, spd); - fclose(spd); - } - - g_free(temp_path); - } else { - int i; - - for (i = 0; i <= 3; i++) { - FILE *spd; - char *temp_path; - - temp_path = g_strdup_printf("%s/%02x", spd_path, offset + i * 16); - if ((spd = fopen(temp_path, "rb"))) { - fread(bytes_out + i * 16, 1, 16, spd); - fclose(spd); - } - - g_free(temp_path); - } - } -} - -static gchar *decode_dimms(GSList * dimm_list, gboolean use_sysfs) -{ - GSList *dimm; - GString *output; - gint count = 0; - - output = g_string_new(""); - - for (dimm = dimm_list; dimm; dimm = dimm->next, count++) { - gchar *spd_path = (gchar *) dimm->data; - gchar *manufacturer; - gchar *detailed_info; - gchar *moreinfo_key; - gchar part_number[32]; - unsigned char bytes[256]; - int module_size; - RamType ram_type; - - shell_status_pulse(); - - read_spd(spd_path, 0, 256, use_sysfs, bytes); - ram_type = decode_ram_type(bytes); - - switch (ram_type) { - case DDR2_SDRAM: - detailed_info = decode_ddr2_sdram(bytes, &module_size); - decode_module_part_number(bytes, part_number); - decode_module_manufacturer(bytes + 64, &manufacturer); - break; - case DDR3_SDRAM: - detailed_info = decode_ddr3_sdram(bytes, &module_size); - decode_ddr3_part_number(bytes, part_number); - decode_ddr3_manufacturer(bytes, &manufacturer); - break; - case DDR_SDRAM: - detailed_info = decode_ddr_sdram(bytes, &module_size); - decode_module_part_number(bytes, part_number); - decode_module_manufacturer(bytes + 64, &manufacturer); - break; - case SDR_SDRAM: - detailed_info = decode_sdr_sdram(bytes, &module_size); - decode_module_part_number(bytes, part_number); - decode_module_manufacturer(bytes + 64, &manufacturer); - break; - default: - DEBUG("Unsupported EEPROM type: %s\n", ram_types[ram_type]); - continue; - } - - - - gchar *key = g_strdup_printf("MEM%d", count); - moreinfo_add_with_prefix("DEV", key, g_strdup(detailed_info)); - g_free(key); - g_string_append_printf(output, "$MEM%d$%d=%s|%d MB|%s\n", count, count, part_number, module_size, manufacturer); - - g_free(spd_path); - g_free(detailed_info); - } - - return g_string_free(output, FALSE); -} - -void scan_spd_do(void) -{ - GDir *dir = NULL; - GSList *dimm_list = NULL; - gboolean use_sysfs = FALSE; - gchar *dir_entry; - gchar *list; - - if (g_file_test("/sys/bus/i2c/drivers/eeprom", G_FILE_TEST_EXISTS)) { - dir = g_dir_open("/sys/bus/i2c/drivers/eeprom", 0, NULL); - use_sysfs = TRUE; - } else if (g_file_test("/proc/sys/dev/sensors", G_FILE_TEST_EXISTS)) { - dir = g_dir_open("/proc/sys/dev/sensors", 0, NULL); - } - - if (!dir) { - g_free(spd_info); - if (!g_file_test("/sys/module/eeprom", G_FILE_TEST_EXISTS)) { - spd_info = g_strdup(_("[SPD]\n" - "Please load the eeprom module to obtain information about memory SPD=\n" - "[$ShellParam$]\n" - "ReloadInterval=500\n")); - } else { - spd_info = g_strdup(_("[SPD]\n" "Reading memory SPD not supported on this system=\n")); - } - - return; - } - - while ((dir_entry = (char *) g_dir_read_name(dir))) { - if (use_sysfs && isdigit(dir_entry[0])) { - dimm_list = g_slist_prepend(dimm_list, g_strdup_printf("/sys/bus/i2c/drivers/eeprom/%s", dir_entry)); - } else if (g_str_has_prefix(dir_entry, "eeprom-")) { - dimm_list = g_slist_prepend(dimm_list, g_strdup_printf("/proc/sys/dev/sensors/%s", dir_entry)); - } - } - - g_dir_close(dir); - - list = decode_dimms(dimm_list, use_sysfs); - g_slist_free(dimm_list); - - g_free(spd_info); - spd_info = g_strdup_printf("[%s]\n" - "%s\n" - "[$ShellParam$]\n" - "ViewType=1\n" - "ColumnTitle$TextValue=%s\n" /* Bank */ - "ColumnTitle$Extra1=%s\n" /* Size */ - "ColumnTitle$Extra2=%s\n" /* Manufacturer */ - "ColumnTitle$Value=%s\n" /* Model */ - "ShowColumnHeaders=true\n", - _("SPD"), list, - _("Bank"), _("Size"), _("Manufacturer"), _("Model") ); - g_free(list); -} diff --git a/modules/devices/storage.c b/modules/devices/storage.c deleted file mode 100644 index 0c393682..00000000 --- a/modules/devices/storage.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include <string.h> - -#include "hardinfo.h" -#include "devices.h" - -gchar *storage_icons = NULL; - -/* SCSI support by Pascal F.Martin <pascalmartin@earthlink.net> */ -void -__scan_scsi_devices(void) -{ - FILE *proc_scsi; - gchar buffer[256], *buf; - gint n = 0; - gint scsi_controller = 0; - gint scsi_channel = 0; - gint scsi_id = 0 ; - gint scsi_lun = 0; - gchar *vendor = NULL, *revision = NULL, *model = NULL; - gchar *scsi_storage_list; - - /* remove old devices from global device table */ - moreinfo_del_with_prefix("DEV:SCSI"); - - if (!g_file_test("/proc/scsi/scsi", G_FILE_TEST_EXISTS)) - return; - - scsi_storage_list = g_strdup(_("\n[SCSI Disks]\n")); - - if ((proc_scsi = fopen("/proc/scsi/scsi", "r"))) { - while (fgets(buffer, 256, proc_scsi)) { - buf = g_strstrip(buffer); - if (!strncmp(buf, "Host: scsi", 10)) { - sscanf(buf, - "Host: scsi%d Channel: %d Id: %d Lun: %d", - &scsi_controller, &scsi_channel, &scsi_id, &scsi_lun); - - n++; - } else if (!strncmp(buf, "Vendor: ", 8)) { - buf[17] = '\0'; - buf[41] = '\0'; - buf[53] = '\0'; - - vendor = g_strdup(g_strstrip(buf + 8)); - model = g_strdup_printf("%s %s", vendor, g_strstrip(buf + 24)); - revision = g_strdup(g_strstrip(buf + 46)); - } else if (!strncmp(buf, "Type: ", 8)) { - char *p; - gchar *type = NULL, *icon = NULL; - - if (!(p = strstr(buf, "ANSI SCSI revision"))) { - p = strstr(buf, "ANSI SCSI revision"); - } - - if (p != NULL) { - while (*(--p) == ' '); - *(++p) = 0; - - static struct { - char *type; - char *label; - char *icon; - } type2icon[] = { - { "Direct-Access", "Disk", "hdd"}, - { "Sequential-Access", "Tape", "tape"}, - { "Printer", "Printer", "lpr"}, - { "WORM", "CD-ROM", "cdrom"}, - { "CD-ROM", "CD-ROM", "cdrom"}, - { "Scanner", "Scanner", "scanner"}, - { "Flash Disk", "USB Flash Disk", "usbfldisk" }, - { NULL, "Generic", "scsi"} - }; - int i; - - if (model && strstr(model, "Flash Disk")) { - type = "Flash Disk"; - icon = "usbfldisk"; - } else { - for (i = 0; type2icon[i].type != NULL; i++) - if (g_str_equal(buf + 8, type2icon[i].type)) - break; - - type = type2icon[i].label; - icon = type2icon[i].icon; - } - } - - gchar *devid = g_strdup_printf("SCSI%d", n); - scsi_storage_list = h_strdup_cprintf("$%s$%s=\n", scsi_storage_list, devid, model); - storage_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", storage_icons, devid, model, icon); - - gchar *strhash = g_strdup_printf(_("[Device Information]\n" - "Model=%s\n"), model); - - const gchar *url = vendor_get_url(model); - if (url) { - strhash = h_strdup_cprintf(_("Vendor=%s (%s)\n"), - strhash, - vendor_get_name(model), - url); - } else { - strhash = h_strdup_cprintf(_("Vendor=%s\n"), - strhash, - vendor_get_name(model)); - } - - strhash = h_strdup_cprintf(_("Type=%s\n" - "Revision=%s\n" - "[SCSI Controller]\n" - "Controller=scsi%d\n" - "Channel=%d\n" - "ID=%d\n" "LUN=%d\n"), - strhash, - type, - revision, - scsi_controller, - scsi_channel, - scsi_id, - scsi_lun); - moreinfo_add_with_prefix("DEV", devid, strhash); - g_free(devid); - - g_free(model); - g_free(revision); - g_free(vendor); - - scsi_controller = scsi_channel = scsi_id = scsi_lun = 0; - } - } - fclose(proc_scsi); - } - - if (n) { - storage_list = h_strconcat(storage_list, scsi_storage_list, NULL); - g_free(scsi_storage_list); - } -} - -void __scan_ide_devices(void) -{ - FILE *proc_ide; - gchar *device, iface, *model, *media, *pgeometry = NULL, *lgeometry = NULL; - gint n = 0, i = 0, cache, nn = 0; - gchar *capab = NULL, *speed = NULL, *driver = NULL, *ide_storage_list; - - /* remove old devices from global device table */ - moreinfo_del_with_prefix("DEV:IDE"); - - ide_storage_list = g_strdup(_("\n[IDE Disks]\n")); - - iface = 'a'; - for (i = 0; i <= 16; i++) { - device = g_strdup_printf("/proc/ide/hd%c/model", iface); - if (g_file_test(device, G_FILE_TEST_EXISTS)) { - gchar buf[128]; - - cache = 0; - - proc_ide = fopen(device, "r"); - if (!proc_ide) - continue; - - (void) fgets(buf, 128, proc_ide); - fclose(proc_ide); - - buf[strlen(buf) - 1] = 0; - - model = g_strdup(buf); - - g_free(device); - - device = g_strdup_printf("/proc/ide/hd%c/media", iface); - proc_ide = fopen(device, "r"); - if (!proc_ide) { - free(model); - continue; - } - - (void) fgets(buf, 128, proc_ide); - fclose(proc_ide); - buf[strlen(buf) - 1] = 0; - - media = g_strdup(buf); - if (g_str_equal(media, "cdrom")) { - /* obtain cd-rom drive information from cdrecord */ - GTimer *timer; - gchar *tmp = g_strdup_printf("cdrecord dev=/dev/hd%c -prcap 2>/dev/stdout", iface); - FILE *prcap; - - if ((prcap = popen(tmp, "r"))) { - /* we need a timeout so cdrecord does not try to get information on cd drives - with inserted media, which is not possible currently. half second should be - enough. */ - timer = g_timer_new(); - g_timer_start(timer); - - while (fgets(buf, 128, prcap) - && g_timer_elapsed(timer, NULL) < 0.5) { - if (g_str_has_prefix(buf, " Does")) { - if (g_str_has_suffix(buf, "media\n") - && !strstr(buf, "speed")) { - gchar *media_type = g_strstrip(strstr(buf, "Does ")); - gchar **ttmp = g_strsplit(media_type, " ", 0); - - capab = h_strdup_cprintf("\nCan %s#%d=%s\n", capab, ttmp[1], ++nn, ttmp[2]); - - g_strfreev(ttmp); - } else if (strstr(buf, "Buffer-Underrun-Free")) { - capab = - h_strdup_cprintf - ("\nSupports BurnProof=%s\n", capab, strstr(buf, "Does not") ? "No" : "Yes"); - } else if (strstr(buf, "multi-session")) { - capab = - h_strdup_cprintf - ("\nCan read multi-session CDs=%s\n", - capab, strstr(buf, "Does not") ? "No" : "Yes"); - } else if (strstr(buf, "audio CDs")) { - capab = - h_strdup_cprintf - ("\nCan play audio CDs=%s\n", capab, strstr(buf, "Does not") ? "No" : "Yes"); - } else if (strstr(buf, "PREVENT/ALLOW")) { - capab = - h_strdup_cprintf - ("\nCan lock media=%s\n", capab, strstr(buf, "Does not") ? "No" : "Yes"); - } - } else if ((strstr(buf, "read") - || strstr(buf, "write")) - && strstr(buf, "kB/s")) { - speed = - g_strconcat(speed ? speed : "", strreplacechr(g_strstrip(buf), ":", '='), "\n", NULL); - } else if (strstr(buf, "Device seems to be")) { - driver = g_strdup_printf(_("Driver=%s\n"), strchr(buf, ':') + 1); - } - } - - pclose(prcap); - g_timer_destroy(timer); - } - - g_free(tmp); - } - g_free(device); - - device = g_strdup_printf("/proc/ide/hd%c/cache", iface); - if (g_file_test(device, G_FILE_TEST_EXISTS)) { - proc_ide = fopen(device, "r"); - if (proc_ide) { - (void) fscanf(proc_ide, "%d", &cache); - fclose(proc_ide); - } else { - cache = 0; - } - } - g_free(device); - - device = g_strdup_printf("/proc/ide/hd%c/geometry", iface); - if (g_file_test(device, G_FILE_TEST_EXISTS)) { - gchar *tmp; - - proc_ide = fopen(device, "r"); - if (proc_ide) { - (void) fgets(buf, 64, proc_ide); - for (tmp = buf; *tmp; tmp++) { - if (*tmp >= '0' && *tmp <= '9') - break; - } - - pgeometry = g_strdup(g_strstrip(tmp)); - - (void) fgets(buf, 64, proc_ide); - for (tmp = buf; *tmp; tmp++) { - if (*tmp >= '0' && *tmp <= '9') - break; - } - lgeometry = g_strdup(g_strstrip(tmp)); - - fclose(proc_ide); - } else { - pgeometry = g_strdup("Unknown"); - lgeometry = g_strdup("Unknown"); - } - - } - g_free(device); - - n++; - - gchar *devid = g_strdup_printf("IDE%d", n); - - ide_storage_list = h_strdup_cprintf("$%s$%s=\n", ide_storage_list, devid, model); - storage_icons = - h_strdup_cprintf("Icon$%s$%s=%s.png\n", storage_icons, - devid, model, g_str_equal(media, "cdrom") ? "cdrom" : "hdd"); - - gchar *strhash = g_strdup_printf(_("[Device Information]\n" "Model=%s\n"), - model); - - const gchar *url = vendor_get_url(model); - - if (url) { - strhash = h_strdup_cprintf(_("Vendor=%s (%s)\n"), strhash, vendor_get_name(model), url); - } else { - strhash = h_strdup_cprintf(_("Vendor=%s\n"), strhash, vendor_get_name(model)); - } - - strhash = h_strdup_cprintf(_("Device Name=hd%c\n" - "Media=%s\n" "Cache=%dkb\n"), strhash, iface, media, cache); - if (driver) { - strhash = h_strdup_cprintf("%s\n", strhash, driver); - - g_free(driver); - driver = NULL; - } - - if (pgeometry && lgeometry) { - strhash = h_strdup_cprintf(_("[Geometry]\n" - "Physical=%s\n" "Logical=%s\n"), strhash, pgeometry, lgeometry); - - g_free(pgeometry); - pgeometry = NULL; - g_free(lgeometry); - lgeometry = NULL; - } - - if (capab) { - strhash = h_strdup_cprintf(_("[Capabilities]\n%s"), strhash, capab); - - g_free(capab); - capab = NULL; - } - - if (speed) { - strhash = h_strdup_cprintf(_("[Speeds]\n%s"), strhash, speed); - - g_free(speed); - speed = NULL; - } - - moreinfo_add_with_prefix("DEV", devid, strhash); - g_free(devid); - g_free(model); - } else { - g_free(device); - } - - iface++; - } - - if (n) { - storage_list = h_strconcat(storage_list, ide_storage_list, NULL); - g_free(ide_storage_list); - } -} diff --git a/modules/devices/usb.c b/modules/devices/usb.c deleted file mode 100644 index 9366c7ce..00000000 --- a/modules/devices/usb.c +++ /dev/null @@ -1,436 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2008 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* - * FIXME: - * - listing with sysfs does not generate device hierarchy - */ - -#include <string.h> - -#include "hardinfo.h" -#include "devices.h" - -gchar *usb_list = NULL; - -void __scan_usb_sysfs_add_device(gchar * endpoint, int n) -{ - gchar *manufacturer, *product, *mxpwr, *tmp, *strhash; - gint bus, classid, vendor, prodid; - gfloat version, speed; - - classid = h_sysfs_read_int(endpoint, "bDeviceClass"); - vendor = h_sysfs_read_int(endpoint, "idVendor"); - prodid = h_sysfs_read_int(endpoint, "idProduct"); - bus = h_sysfs_read_int(endpoint, "busnum"); - speed = h_sysfs_read_float(endpoint, "speed"); - version = h_sysfs_read_float(endpoint, "version"); - - if (!(mxpwr = h_sysfs_read_string(endpoint, "bMaxPower"))) { - mxpwr = g_strdup_printf("%d %s", 0 , _("mA") ); - } - - if (!(manufacturer = h_sysfs_read_string(endpoint, "manufacturer"))) { - manufacturer = g_strdup(_("(Unknown)")); - } - - if (!(product = h_sysfs_read_string(endpoint, "product"))) { - if (classid == 9) { - product = g_strdup_printf(_(/*/%.2f is version*/ "USB %.2f Hub"), version); - } else { - product = g_strdup_printf(_("Unknown USB %.2f Device (class %d)"), version, classid); - } - } - - const gchar *v_url = vendor_get_url(manufacturer); - const gchar *v_name = vendor_get_name(manufacturer); - gchar *v_str; - if (v_url != NULL) { - v_str = g_strdup_printf("%s (%s)", v_name, v_url); - } else { - v_str = g_strdup_printf("%s", manufacturer); - } - - tmp = g_strdup_printf("USB%d", n); - usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product); - - strhash = g_strdup_printf("[%s]\n" - /* Product */ "%s=%s\n" - /* Manufacturer */ "%s=%s\n" - /* Speed */ "%s=%.2f %s\n" - /* Max Current */ "%s=%s\n" - "[%s]\n" - /* USB Version */ "%s=%.2f\n" - /* Class */ "%s=0x%x\n" - /* Vendor */ "%s=0x%x\n" - /* Product ID */ "%s=0x%x\n" - /* Bus */ "%s=%d\n", - _("Device Information"), - _("Product"), product, - _("Manufacturer"), v_str, - _("Speed"), speed, _("Mbit/s"), - _("Max Current"), mxpwr, - _("Misc"), - _("USB Version"), version, - _("Class"), classid, - _("Vendor ID"), vendor, - _("Product ID"), prodid, - _("Bus"), bus); - - moreinfo_add_with_prefix("DEV", tmp, strhash); - g_free(tmp); - g_free(v_str); - g_free(manufacturer); - g_free(product); - g_free(mxpwr); -} - -gboolean __scan_usb_sysfs(void) -{ - GDir *sysfs; - gchar *filename; - const gchar *sysfs_path = "/sys/class/usb_endpoint"; - gint usb_device_number = 0; - - if (!(sysfs = g_dir_open(sysfs_path, 0, NULL))) { - return FALSE; - } - - if (usb_list) { - moreinfo_del_with_prefix("DEV:USB"); - g_free(usb_list); - } - usb_list = g_strdup_printf("[%s]\n", _("USB Devices")); - - while ((filename = (gchar *) g_dir_read_name(sysfs))) { - gchar *endpoint = - g_build_filename(sysfs_path, filename, "device", NULL); - gchar *temp; - - temp = g_build_filename(endpoint, "idVendor", NULL); - if (g_file_test(temp, G_FILE_TEST_EXISTS)) { - __scan_usb_sysfs_add_device(endpoint, ++usb_device_number); - } - - g_free(temp); - g_free(endpoint); - } - - g_dir_close(sysfs); - - return usb_device_number > 0; -} - -gboolean __scan_usb_procfs(void) -{ - FILE *dev; - gchar buffer[128]; - gchar *tmp, *manuf = NULL, *product = NULL, *mxpwr = NULL; - gint bus = 0, level = 0, port = 0, classid = 0, trash; - gint vendor = 0, prodid = 0; - gfloat ver = 0.0f, rev = 0.0f, speed = 0.0f; - int n = 0; - - dev = fopen("/proc/bus/usb/devices", "r"); - if (!dev) - return 0; - - if (usb_list) { - moreinfo_del_with_prefix("DEV:USB"); - g_free(usb_list); - } - usb_list = g_strdup_printf("[%s]\n", _("USB Devices")); - - while (fgets(buffer, 128, dev)) { - tmp = buffer; - - switch (*tmp) { - case 'T': - sscanf(tmp, - "T: Bus=%d Lev=%d Prnt=%d Port=%d Cnt=%d Dev#=%d Spd=%f", - &bus, &level, &trash, &port, &trash, &trash, &speed); - break; - case 'D': - sscanf(tmp, "D: Ver=%f Cls=%x", &ver, &classid); - break; - case 'P': - sscanf(tmp, "P: Vendor=%x ProdID=%x Rev=%f", &vendor, &prodid, &rev); - break; - case 'S': - if (strstr(tmp, "Manufacturer=")) { - manuf = g_strdup(strchr(tmp, '=') + 1); - remove_linefeed(manuf); - } else if (strstr(tmp, "Product=")) { - product = g_strdup(strchr(tmp, '=') + 1); - remove_linefeed(product); - } - break; - case 'C': - mxpwr = strstr(buffer, "MxPwr=") + 6; - - tmp = g_strdup_printf("USB%d", ++n); - - if (product && *product == '\0') { - g_free(product); - if (classid == 9) { - product = g_strdup_printf(_("USB %.2f Hub"), ver); - } else { - product = g_strdup_printf(_("Unknown USB %.2f Device (class %d)"), ver, classid); - } - } - - if (classid == 9) { /* hub */ - usb_list = h_strdup_cprintf("[%s#%d]\n", usb_list, product, n); - } else { /* everything else */ - usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, product); - - EMPIFNULL(manuf); - const gchar *v_url = vendor_get_url(manuf); - const gchar *v_name = vendor_get_name(manuf); - gchar *v_str = NULL; - if (strlen(manuf)) { - if (v_url != NULL) - v_str = g_strdup_printf("%s (%s)", v_name, v_url); - else - v_str = g_strdup_printf("%s", manuf); - } - UNKIFNULL(v_str); - UNKIFNULL(product); - - gchar *strhash = g_strdup_printf("[%s]\n" "%s=%s\n" "%s=%s\n", - _("Device Information"), - _("Product"), product, - _("Manufacturer"), v_str); - - strhash = h_strdup_cprintf("[%s #%d]\n" - /* Speed */ "%s=%.2f %s\n" - /* Max Current */ "%s=%s\n" - "[%s]\n" - /* USB Version */ "%s=%.2f\n" - /* Revision */ "%s=%.2f\n" - /* Class */ "%s=0x%x\n" - /* Vendor */ "%s=0x%x\n" - /* Product ID */ "%s=0x%x\n" - /* Bus */ "%s=%d\n" - /* Level */ "%s=%d\n", - strhash, - _("Port"), port, - _("Speed"), speed, _("Mbit/s"), - _("Max Current"), mxpwr, - _("Misc"), - _("USB Version"), ver, - _("Revision"), rev, - _("Class"), classid, - _("Vendor ID"), vendor, - _("Product ID"), prodid, - _("Bus"), bus, - _("Level"), level); - - moreinfo_add_with_prefix("DEV", tmp, strhash); - g_free(v_str); - g_free(tmp); - } - - g_free(manuf); - g_free(product); - manuf = NULL; - product = NULL; - port = classid = 0; - } - } - - fclose(dev); - - return n > 0; -} - - -void __scan_usb_lsusb_add_device(char *buffer, int bufsize, FILE * lsusb, int usb_device_number) -{ - gint bus, device, vendor_id, product_id; - gchar *version = NULL, *product = NULL, *vendor = NULL, *dev_class = NULL, *int_class = NULL; - gchar *max_power = NULL, *name = NULL; - gchar *tmp, *strhash; - long position = 0; - - g_strstrip(buffer); - sscanf(buffer, "Bus %d Device %d: ID %x:%x", &bus, &device, &vendor_id, &product_id); - name = g_strdup(buffer + 33); - - for (fgets(buffer, bufsize, lsusb); position >= 0 && fgets(buffer, bufsize, lsusb); position = ftell(lsusb)) { - g_strstrip(buffer); - - if (g_str_has_prefix(buffer, "idVendor")) { - g_free(vendor); - vendor = g_strdup(buffer + 26); - } else if (g_str_has_prefix(buffer, "idProduct")) { - g_free(product); - product = g_strdup(buffer + 26); - } else if (g_str_has_prefix(buffer, "MaxPower")) { - g_free(max_power); - max_power = g_strdup(buffer + 9); - } else if (g_str_has_prefix(buffer, "bcdUSB")) { - g_free(version); - version = g_strdup(buffer + 7); - } else if (g_str_has_prefix(buffer, "bDeviceClass")) { - g_free(dev_class); - dev_class = g_strdup(buffer + 14); - } else if (g_str_has_prefix(buffer, "bInterfaceClass")) { - g_free(int_class); - int_class = g_strdup(buffer + 16); - } else if (g_str_has_prefix(buffer, "Bus ")) { - /* device separator */ - fseek(lsusb, position, SEEK_SET); - break; - } - } - - if (dev_class && strstr(dev_class, "0 (Defined at Interface level)")) { - g_free(dev_class); - if (int_class) { - dev_class = int_class; - } else { - dev_class = g_strdup(_("(Unknown)")); - } - } else - dev_class = g_strdup(_("(Unknown)")); - - tmp = g_strdup_printf("USB%d", usb_device_number); - usb_list = h_strdup_cprintf("$%s$%s=\n", usb_list, tmp, name); - - const gchar *v_url = vendor_get_url(vendor); - const gchar *v_name = vendor_get_name(vendor); - gchar *v_str; - if (v_url != NULL) { - v_str = g_strdup_printf("%s (%s)", v_name, v_url); - } else { - v_str = g_strdup_printf("%s", g_strstrip(vendor) ); - } - - if (max_power != NULL) { - int mA = atoi(g_strstrip(max_power)); - gchar *trent_steel = g_strdup_printf("%d %s", mA, _("mA")); - g_free(max_power); - max_power = trent_steel; - } - - UNKIFNULL(product); - UNKIFNULL(v_str); - UNKIFNULL(max_power); - UNKIFNULL(version); - UNKIFNULL(dev_class); - - strhash = g_strdup_printf("[%s]\n" - /* Product */ "%s=%s\n" - /* Manufacturer */ "%s=%s\n" - /* Max Current */ "%s=%s\n" - "[%s]\n" - /* USB Version */ "%s=%s\n" - /* Class */ "%s=%s\n" - /* Vendor ID */ "%s=0x%x\n" - /* Product ID */ "%s=0x%x\n" - /* Bus */ "%s=%d\n", - _("Device Information"), - _("Product"), g_strstrip(product), - _("Vendor"), v_str, - _("Max Current"), g_strstrip(max_power), - _("Misc"), - _("USB Version"), g_strstrip(version), - _("Class"), g_strstrip(dev_class), - _("Vendor ID"), vendor_id, - _("Product ID"), product_id, - _("Bus"), bus); - - moreinfo_add_with_prefix("DEV", tmp, strhash); - g_free(v_str); - g_free(vendor); - g_free(product); - g_free(max_power); - g_free(dev_class); - g_free(version); - g_free(tmp); - g_free(name); -} - -gboolean __scan_usb_lsusb(void) -{ - static gchar *lsusb_path = NULL; - int usb_device_number = 0; - FILE *lsusb; - FILE *temp_lsusb; - char buffer[512], *temp; - - if (!lsusb_path) { - if (!(lsusb_path = find_program("lsusb"))) { - DEBUG("lsusb not found"); - - return FALSE; - } - } - - temp = g_strdup_printf("%s -v | tr '[]' '()'", lsusb_path); - if (!(lsusb = popen(temp, "r"))) { - DEBUG("cannot run %s", lsusb_path); - - g_free(temp); - return FALSE; - } - - temp_lsusb = tmpfile(); - if (!temp_lsusb) { - DEBUG("cannot create temporary file for lsusb"); - pclose(lsusb); - g_free(temp); - return FALSE; - } - - while (fgets(buffer, sizeof(buffer), lsusb)) { - fputs(buffer, temp_lsusb); - } - - pclose(lsusb); - - // rewind file so we can read from it - fseek(temp_lsusb, 0, SEEK_SET); - - g_free(temp); - - if (usb_list) { - moreinfo_del_with_prefix("DEV:USB"); - g_free(usb_list); - } - usb_list = g_strdup_printf("[%s]\n", _("USB Devices")); - - while (fgets(buffer, sizeof(buffer), temp_lsusb)) { - if (g_str_has_prefix(buffer, "Bus ")) { - __scan_usb_lsusb_add_device(buffer, sizeof(buffer), temp_lsusb, ++usb_device_number); - } - } - - fclose(temp_lsusb); - - return usb_device_number > 0; -} - -void __scan_usb(void) -{ - if (!__scan_usb_procfs()) { - if (!__scan_usb_sysfs()) { - __scan_usb_lsusb(); - } - } -} diff --git a/modules/devices/x86/processor.c b/modules/devices/x86/processor.c deleted file mode 100644 index f1c2b6e9..00000000 --- a/modules/devices/x86/processor.c +++ /dev/null @@ -1,747 +0,0 @@ -/* - * HardInfo - Displays System Information - * Copyright (C) 2003-2006 Leandro A. F. Pereira <leandro@hardinfo.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "hardinfo.h" -#include "devices.h" -#include "cpu_util.h" - -#include "x86_data.h" -#include "x86_data.c" - -/* - * This function is partly based on x86cpucaps - * by Osamu Kayasono <jacobi@jcom.home.ne.jp> - */ -void get_processor_strfamily(Processor * processor) -{ - gint family = processor->family; - gint model = processor->model; - - if (g_str_equal(processor->vendor_id, "GenuineIntel")) { - if (family == 4) { - processor->strmodel = g_strdup("i486 series"); - } else if (family == 5) { - if (model < 4) { - processor->strmodel = g_strdup("Pentium Classic"); - } else { - processor->strmodel = g_strdup("Pentium MMX"); - } - } else if (family == 6) { - if (model <= 1) { - processor->strmodel = g_strdup("Pentium Pro"); - } else if (model < 7) { - processor->strmodel = g_strdup("Pentium II/Pentium II Xeon/Celeron"); - } else if (model == 9) { - processor->strmodel = g_strdup("Pentium M"); - } else { - processor->strmodel = g_strdup("Pentium III/Pentium III Xeon/Celeron/Core Duo/Core Duo 2"); - } - } else if (family > 6) { - processor->strmodel = g_strdup("Pentium 4"); - } else { - processor->strmodel = g_strdup("i386 class"); - } - } else if (g_str_equal(processor->vendor_id, "AuthenticAMD")) { - if (family == 4) { - if (model <= 9) { - processor->strmodel = g_strdup("AMD i80486 series"); - } else { - processor->strmodel = g_strdup("AMD 5x86"); - } - } else if (family == 5) { - if (model <= 3) { - processor->strmodel = g_strdup("AMD K5"); - } else if (model <= 7) { - processor->strmodel = g_strdup("AMD K6"); - } else if (model == 8) { - processor->strmodel = g_strdup("AMD K6-2"); - } else if (model == 9) { - processor->strmodel = g_strdup("AMD K6-III"); - } else { - processor->strmodel = g_strdup("AMD K6-2+/III+"); - } - } else if (family == 6) { - if (model == 1) { - processor->strmodel = g_strdup("AMD Athlon (K7)"); - } else if (model == 2) { - processor->strmodel = g_strdup("AMD Athlon (K75)"); - } else if (model == 3) { - processor->strmodel = g_strdup("AMD Duron (Spitfire)"); - } else if (model == 4) { - processor->strmodel = g_strdup("AMD Athlon (Thunderbird)"); - } else if (model == 6) { - processor->strmodel = g_strdup("AMD Athlon XP/MP/4 (Palomino)"); - } else if (model == 7) { - processor->strmodel = g_strdup("AMD Duron (Morgan)"); - } else if (model == 8) { - processor->strmodel = g_strdup("AMD Athlon XP/MP (Thoroughbred)"); - } else if (model == 10) { - processor->strmodel = g_strdup("AMD Athlon XP/MP (Barton)"); - } else { - processor->strmodel = g_strdup("AMD Athlon (unknown)"); - } - } else if (family > 6) { - processor->strmodel = g_strdup("AMD Opteron/Athlon64/FX"); - } else { - processor->strmodel = g_strdup("AMD i386 class"); - } - } else if (g_str_equal(processor->vendor_id, "CyrixInstead")) { - if (family == 4) { - processor->strmodel = g_strdup("Cyrix 5x86"); - } else if (family == 5) { - processor->strmodel = g_strdup("Cyrix M1 (6x86)"); - } else if (family == 6) { - if (model == 0) { - processor->strmodel = g_strdup("Cyrix M2 (6x86MX)"); - } else if (model <= 5) { - processor->strmodel = g_strdup("VIA Cyrix III (M2 core)"); - } else if (model == 6) { - processor->strmodel = g_strdup("VIA Cyrix III (WinChip C5A)"); - } else if (model == 7) { - processor->strmodel = g_strdup("VIA Cyrix III (WinChip C5B/C)"); - } else { - processor->strmodel = g_strdup("VIA Cyrix III (WinChip C5C-T)"); - } - } else { - processor->strmodel = g_strdup("Cyrix i386 class"); - } - } else if (g_str_equal(processor->vendor_id, "CentaurHauls")) { - if (family == 5) { - if (model <= 4) { - processor->strmodel = g_strdup("Centaur WinChip C6"); - } else if (model <= 8) { - processor->strmodel = g_strdup("Centaur WinChip 2"); - } else { - processor->strmodel = g_strdup("Centaur WinChip 2A"); - } - } else { - processor->strmodel = g_strdup("Centaur i386 class"); - } - } else if (g_str_equal(processor->vendor_id, "GenuineTMx86")) { - processor->strmodel = g_strdup("Transmeta Crusoe TM3x00/5x00"); - } else { - processor->strmodel = g_strdup("Unknown"); - } -} - -static gchar *__cache_get_info_as_string(Processor *processor) -{ - gchar *result = g_strdup(""); - GSList *cache_list; - ProcessorCache *cache; - - if (!processor->cache) { - return g_strdup(_("Cache information not available=\n")); - } - - for (cache_list = processor->cache; cache_list; cache_list = cache_list->next) { - cache = (ProcessorCache *)cache_list->data; - - result = h_strdup_cprintf(_("Level %d (%s)=%d-way set-associative, %d sets, %dKB size\n"), - result, - cache->level, - C_("cache-type", cache->type), - cache->ways_of_associativity, - cache->number_of_sets, - cache->size); - } - - return result; -} - -/* This is not used directly, but creates translatable strings for - * the type string returned from /sys/.../cache */ -static const char* cache_types[] = { - NC_("cache-type", /*/cache type, as appears in: Level 1 (Data)*/ "Data"), - NC_("cache-type", /*/cache type, as appears in: Level 1 (Instruction)*/ "Instruction"), - NC_("cache-type", /*/cache type, as appears in: Level 2 (Unified)*/ "Unified") -}; - -static void __cache_obtain_info(Processor *processor) -{ - ProcessorCache *cache; - gchar *endpoint, *entry, *index; - gchar *uref = NULL; - gint i; - gint processor_number = processor->id; - - endpoint = g_strdup_printf("/sys/devices/system/cpu/cpu%d/cache", processor_number); - - for (i = 0; ; i++) { - cache = g_new0(ProcessorCache, 1); - - index = g_strdup_printf("index%d/", i); - - entry = g_strconcat(index, "type", NULL); - cache->type = h_sysfs_read_string(endpoint, entry); - g_free(entry); - - if (!cache->type) { - g_free(cache); - g_free(index); - goto fail; - } - - entry = g_strconcat(index, "level", NULL); - cache->level = h_sysfs_read_int(endpoint, entry); - g_free(entry); - - entry = g_strconcat(index, "number_of_sets", NULL); - cache->number_of_sets = h_sysfs_read_int(endpoint, entry); - g_free(entry); - - entry = g_strconcat(index, "physical_line_partition", NULL); - cache->physical_line_partition = h_sysfs_read_int(endpoint, entry); - g_free(entry); - - entry = g_strconcat(index, "size", NULL); - cache->size = h_sysfs_read_int(endpoint, entry); - g_free(entry); - - entry = g_strconcat(index, "ways_of_associativity", NULL); - cache->ways_of_associativity = h_sysfs_read_int(endpoint, entry); - g_free(entry); - - /* unique cache references: id is nice, but share_cpu_list can be - * used if it is not available. */ - entry = g_strconcat(index, "id", NULL); - uref = h_sysfs_read_string(endpoint, entry); - g_free(entry); - if (uref != NULL && *uref != 0 ) - cache->uid = atoi(uref); - else - cache->uid = -1; - g_free(uref); - entry = g_strconcat(index, "shared_cpu_list", NULL); - cache->shared_cpu_list = h_sysfs_read_string(endpoint, entry); - g_free(entry); - - /* reacharound */ - entry = g_strconcat(index, "../../topology/physical_package_id", NULL); - cache->phy_sock = h_sysfs_read_int(endpoint, entry); - g_free(entry); - - g_free(index); - - processor->cache = g_slist_append(processor->cache, cache); - } - -fail: - g_free(endpoint); -} - -#define khzint_to_mhzdouble(k) (((double)k)/1000) -#define cmp_clocks_test(f) if (a->f < b->f) return -1; if (a->f > b->f) return 1; - -static gint cmp_cpufreq_data(cpufreq_data *a, cpufreq_data *b) { - gint i = 0; - i = g_strcmp0(a->shared_list, b->shared_list); if (i!=0) return i; - cmp_clocks_test(cpukhz_max); - cmp_clocks_test(cpukhz_min); - return 0; -} - -static gint cmp_cpufreq_data_ignore_affected(cpufreq_data *a, cpufreq_data *b) { - gint i = 0; - cmp_clocks_test(cpukhz_max); - cmp_clocks_test(cpukhz_min); - return 0; -} - -gchar *clocks_summary(GSList * processors) -{ - gchar *ret = g_strdup_printf("[%s]\n", _("Clocks")); - GSList *all_clocks = NULL, *uniq_clocks = NULL; - GSList *tmp, *l; - Processor *p; - cpufreq_data *c, *cur = NULL; - gint cur_count = 0, i = 0; - - /* create list of all clock references */ - for (l = processors; l; l = l->next) { - p = (Processor*)l->data; - if (p->cpufreq) { - all_clocks = g_slist_prepend(all_clocks, p->cpufreq); - } - } - - if (g_slist_length(all_clocks) == 0) { - ret = h_strdup_cprintf("%s=\n", ret, _("(Not Available)") ); - g_slist_free(all_clocks); - return ret; - } - - /* ignore duplicate references */ - all_clocks = g_slist_sort(all_clocks, (GCompareFunc)cmp_cpufreq_data); - for (l = all_clocks; l; l = l->next) { - c = (cpufreq_data*)l->data; - if (!cur) { - cur = c; - } else { - if (cmp_cpufreq_data(cur, c) != 0) { - uniq_clocks = g_slist_prepend(uniq_clocks, cur); - cur = c; - } - } - } - uniq_clocks = g_slist_prepend(uniq_clocks, cur); - uniq_clocks = g_slist_reverse(uniq_clocks); - cur = 0, cur_count = 0; - - /* count and list clocks */ - for (l = uniq_clocks; l; l = l->next) { - c = (cpufreq_data*)l->data; - if (!cur) { - cur = c; - cur_count = 1; - } else { - if (cmp_cpufreq_data_ignore_affected(cur, c) != 0) { - ret = h_strdup_cprintf(_("%.2f-%.2f %s=%dx\n"), - ret, - khzint_to_mhzdouble(cur->cpukhz_min), - khzint_to_mhzdouble(cur->cpukhz_max), - _("MHz"), - cur_count); - cur = c; - cur_count = 1; - } else { - cur_count++; - } - } - } - ret = h_strdup_cprintf(_("%.2f-%.2f %s=%dx\n"), - ret, - khzint_to_mhzdouble(cur->cpukhz_min), - khzint_to_mhzdouble(cur->cpukhz_max), - _("MHz"), - cur_count); - - g_slist_free(all_clocks); - g_slist_free(uniq_clocks); - return ret; -} - -#define cmp_cache_test(f) if (a->f < b->f) return -1; if (a->f > b->f) return 1; - -static gint cmp_cache(ProcessorCache *a, ProcessorCache *b) { - gint i = 0; - cmp_cache_test(phy_sock); - i = g_strcmp0(a->type, b->type); if (i!=0) return i; - cmp_cache_test(level); - cmp_cache_test(size); - cmp_cache_test(uid); /* uid is unique among caches with the same (type, level) */ - if (a->uid == -1) { - /* if id wasn't available, use shared_cpu_list as a unique ref */ - i = g_strcmp0(a->shared_cpu_list, b->shared_cpu_list); if (i!=0) - return i; - } - return 0; -} - -static gint cmp_cache_ignore_id(ProcessorCache *a, ProcessorCache *b) { - gint i = 0; - cmp_cache_test(phy_sock); - i = g_strcmp0(a->type, b->type); if (i!=0) return i; - cmp_cache_test(level); - cmp_cache_test(size); - return 0; -} - -gchar *caches_summary(GSList * processors) -{ - gchar *ret = g_strdup_printf("[%s]\n", _("Caches")); - GSList *all_cache = NULL, *uniq_cache = NULL; - GSList *tmp, *l; - Processor *p; - ProcessorCache *c, *cur = NULL; - gint cur_count = 0, i = 0; - - /* create list of all cache references */ - for (l = processors; l; l = l->next) { - p = (Processor*)l->data; - if (p->cache) { - tmp = g_slist_copy(p->cache); - if (all_cache) { - all_cache = g_slist_concat(all_cache, tmp); - } else { - all_cache = tmp; - } - } - } - - if (g_slist_length(all_cache) == 0) { - ret = h_strdup_cprintf("%s=\n", ret, _("(Not Available)") ); - g_slist_free(all_cache); - return ret; - } - - /* ignore duplicate references */ - all_cache = g_slist_sort(all_cache, (GCompareFunc)cmp_cache); - for (l = all_cache; l; l = l->next) { - c = (ProcessorCache*)l->data; - if (!cur) { - cur = c; - } else { - if (cmp_cache(cur, c) != 0) { - uniq_cache = g_slist_prepend(uniq_cache, cur); - cur = c; - } - } - } - uniq_cache = g_slist_prepend(uniq_cache, cur); - uniq_cache = g_slist_reverse(uniq_cache); - cur = 0, cur_count = 0; - - /* count and list caches */ - for (l = uniq_cache; l; l = l->next) { - c = (ProcessorCache*)l->data; - if (!cur) { - cur = c; - cur_count = 1; - } else { - if (cmp_cache_ignore_id(cur, c) != 0) { - ret = h_strdup_cprintf(_("Level %d (%s)#%d=%dx %dKB (%dKB), %d-way set-associative, %d sets\n"), - ret, - cur->level, - C_("cache-type", cur->type), - cur->phy_sock, - cur_count, - cur->size, - cur->size * cur_count, - cur->ways_of_associativity, - cur->number_of_sets); - cur = c; - cur_count = 1; - } else { - cur_count++; - } - } - } - ret = h_strdup_cprintf(_("Level %d (%s)#%d=%dx %dKB (%dKB), %d-way set-associative, %d sets\n"), - ret, - cur->level, - C_("cache-type", cur->type), - cur->phy_sock, - cur_count, - cur->size, - cur->size * cur_count, - cur->ways_of_associativity, - cur->number_of_sets); - - g_slist_free(all_cache); - g_slist_free(uniq_cache); - return ret; -} - -#define PROC_SCAN_READ_BUFFER_SIZE 896 -GSList *processor_scan(void) -{ - GSList *procs = NULL, *l = NULL; - Processor *processor = NULL; - FILE *cpuinfo; - gchar buffer[PROC_SCAN_READ_BUFFER_SIZE]; - - cpuinfo = fopen(PROC_CPUINFO, "r"); - if (!cpuinfo) - return NULL; - - while (fgets(buffer, PROC_SCAN_READ_BUFFER_SIZE, cpuinfo)) { - int rlen = strlen(buffer); - if (rlen >= PROC_SCAN_READ_BUFFER_SIZE - 1) { - fprintf(stderr, "Warning: truncated a line (probably flags list) longer than %d bytes while reading %s.\n", PROC_SCAN_READ_BUFFER_SIZE, PROC_CPUINFO); - } - gchar **tmp = g_strsplit(buffer, ":", 2); - if (!tmp[1] || !tmp[0]) { - g_strfreev(tmp); - continue; - } - - tmp[0] = g_strstrip(tmp[0]); - tmp[1] = g_strstrip(tmp[1]); - - if (g_str_has_prefix(tmp[0], "processor")) { - /* finish previous */ - if (processor) - procs = g_slist_append(procs, processor); - - /* start next */ - processor = g_new0(Processor, 1); - processor->id = atol(tmp[1]); - g_strfreev(tmp); - continue; - } - - if (processor) { - get_str("model name", processor->model_name); - get_str("vendor_id", processor->vendor_id); - get_str("flags", processor->flags); - get_str("bugs", processor->bugs); - get_str("power management", processor->pm); - get_str("microcode", processor->microcode); - get_int("cache size", processor->cache_size); - get_float("cpu MHz", processor->cpu_mhz); - get_float("bogomips", processor->bogomips); - - get_str("fpu", processor->has_fpu); - - get_str("fdiv_bug", processor->bug_fdiv); - get_str("hlt_bug", processor->bug_hlt); - get_str("f00f_bug", processor->bug_f00f); - get_str("coma_bug", processor->bug_coma); - /* sep_bug? */ - - get_int("model", processor->model); - get_int("cpu family", processor->family); - get_int("stepping", processor->stepping); - } - g_strfreev(tmp); - } - - fclose(cpuinfo); - - /* finish last */ - if (processor) - procs = g_slist_append(procs, processor); - - for (l = procs; l; l = l->next) { - processor = (Processor *) l->data; - - STRIFNULL(processor->microcode, _("(Not Available)") ); - - get_processor_strfamily(processor); - __cache_obtain_info(processor); - -#define NULLIFNOTYES(f) if (processor->f) if (strcmp(processor->f, "yes") != 0) { g_free(processor->f); processor->f = NULL; } - NULLIFNOTYES(bug_fdiv); - NULLIFNOTYES(bug_hlt); - NULLIFNOTYES(bug_f00f); - NULLIFNOTYES(bug_coma); - - if (processor->bugs == NULL || g_strcmp0(processor->bugs, "") == 0) { - g_free(processor->bugs); - /* make bugs list on old kernels that don't offer one */ - processor->bugs = g_strdup_printf("%s%s%s%s%s%s%s%s%s%s", - /* the oldest bug workarounds indicated in /proc/cpuinfo */ - processor->bug_fdiv ? " fdiv" : "", - processor->bug_hlt ? " _hlt" : "", - processor->bug_f00f ? " f00f" : "", - processor->bug_coma ? " coma" : "", - /* these bug workarounds were reported as "features" in older kernels */ - processor_has_flag(processor->flags, "fxsave_leak") ? " fxsave_leak" : "", - processor_has_flag(processor->flags, "clflush_monitor") ? " clflush_monitor" : "", - processor_has_flag(processor->flags, "11ap") ? " 11ap" : "", - processor_has_flag(processor->flags, "tlb_mmatch") ? " tlb_mmatch" : "", - processor_has_flag(processor->flags, "apic_c1e") ? " apic_c1e" : "", - ""); /* just to make adding lines easier */ - g_strchug(processor->bugs); - } - - if (processor->pm == NULL || g_strcmp0(processor->pm, "") == 0) { - g_free(processor->pm); - /* make power management list on old kernels that don't offer one */ - processor->pm = g_strdup_printf("%s%s", - /* "hw_pstate" -> "hwpstate" */ - processor_has_flag(processor->flags, "hw_pstate") ? " hwpstate" : "", - ""); /* just to make adding lines easier */ - g_strchug(processor->pm); - } - - /* topo & freq */ - processor->cpufreq = cpufreq_new(processor->id); - processor->cputopo = cputopo_new(processor->id); - - if (processor->cpufreq->cpukhz_max) - processor->cpu_mhz = processor->cpufreq->cpukhz_max / 1000; - } - - return procs; -} - -gchar *processor_get_capabilities_from_flags(gchar *strflags, gchar *lookup_prefix) -{ - gchar **flags, **old; - gchar tmp_flag[64] = ""; - const gchar *meaning; - gchar *tmp = NULL; - gint j = 0, i = 0; - - flags = g_strsplit(strflags, " ", 0); - old = flags; - - while (flags[j]) { - if ( sscanf(flags[j], "[%d]", &i) ) { - /* Some flags are indexes, like [13], and that looks like - * a new section to hardinfo shell */ - tmp = h_strdup_cprintf("(%s%d)=\n", tmp, - (lookup_prefix) ? lookup_prefix : "", - i ); - } else { - sprintf(tmp_flag, "%s%s", lookup_prefix, flags[j]); - meaning = x86_flag_meaning(tmp_flag); - - if (meaning) { - tmp = h_strdup_cprintf("%s=%s\n", tmp, flags[j], meaning); - } else { - tmp = h_strdup_cprintf("%s=\n", tmp, flags[j]); - } - } - j++; - } - if (tmp == NULL || g_strcmp0(tmp, "") == 0) - tmp = g_strdup_printf("%s=%s\n", "empty", _("Empty List")); - - g_strfreev(old); - return tmp; -} - -gchar *processor_get_detailed_info(Processor * processor) -{ - gchar *tmp_flags, *tmp_bugs, *tmp_pm, *tmp_cpufreq, *tmp_topology, *ret, *cache_info; - - tmp_flags = processor_get_capabilities_from_flags(processor->flags, ""); - tmp_bugs = processor_get_capabilities_from_flags(processor->bugs, "bug:"); - tmp_pm = processor_get_capabilities_from_flags(processor->pm, "pm:"); - cache_info = __cache_get_info_as_string(processor); - - tmp_topology = cputopo_section_str(processor->cputopo); - tmp_cpufreq = cpufreq_section_str(processor->cpufreq); - - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%d, %d, %d (%s)\n" /* family, model, stepping (decoded name) */ - "%s=%s\n" /* vendor */ - "%s=%s\n" /* microcode */ - "[%s]\n" /* configuration */ - "%s=%d %s\n" /* cache size (from cpuinfo) */ - "%s=%.2f %s\n" /* frequency */ - "%s=%.2f\n" /* bogomips */ - "%s=%s\n" /* byte order */ - "%s" /* topology */ - "%s" /* frequency scaling */ - "[%s]\n" /* cache */ - "%s\n" - "[%s]\n" /* pm */ - "%s" - "[%s]\n" /* bugs */ - "%s" - "[%s]\n" /* flags */ - "%s", - _("Processor"), - _("Model Name"), processor->model_name, - _("Family, model, stepping"), - processor->family, - processor->model, - processor->stepping, - processor->strmodel, - _("Vendor"), vendor_get_name(processor->vendor_id), - _("Microcode Version"), processor->microcode, - _("Configuration"), - _("Cache Size"), processor->cache_size, _("kb"), - _("Frequency"), processor->cpu_mhz, _("MHz"), - _("BogoMips"), processor->bogomips, - _("Byte Order"), byte_order_str(), - tmp_topology, - tmp_cpufreq, - _("Cache"), cache_info, - _("Power Management"), tmp_pm, - _("Bug Workarounds"), tmp_bugs, - _("Capabilities"), tmp_flags ); - g_free(tmp_flags); - g_free(tmp_bugs); - g_free(tmp_pm); - g_free(cache_info); - g_free(tmp_cpufreq); - g_free(tmp_topology); - return ret; -} - -gchar *processor_name(GSList * processors) { - return processor_name_default(processors); -} - -gchar *processor_describe(GSList * processors) { - return processor_describe_default(processors); -} - -gchar *processor_meta(GSList * processors) { - gchar *meta_cpu_name = processor_name(processors); - gchar *meta_cpu_desc = processor_describe(processors); - gchar *meta_freq_desc = processor_frequency_desc(processors); - gchar *meta_clocks = clocks_summary(processors); - gchar *meta_caches = caches_summary(processors); - gchar *ret = NULL; - UNKIFNULL(meta_cpu_desc); - ret = g_strdup_printf("[%s]\n" - "%s=%s\n" - "%s=%s\n" - "%s=%s\n" - "%s" - "%s", - _("Package Information"), - _("Name"), meta_cpu_name, - _("Topology"), meta_cpu_desc, - _("Logical CPU Config"), meta_freq_desc, - meta_clocks, - meta_caches); - g_free(meta_cpu_desc); - g_free(meta_freq_desc); - g_free(meta_clocks); - g_free(meta_caches); - return ret; -} - -gchar *processor_get_info(GSList * processors) -{ - Processor *processor; - gchar *ret, *tmp, *hashkey; - gchar *meta; /* becomes owned by more_info? no need to free? */ - GSList *l; - - tmp = g_strdup_printf("$CPU_META$%s=\n", _("Package Information") ); - - meta = processor_meta(processors); - moreinfo_add_with_prefix("DEV", "CPU_META", meta); - - for (l = processors; l; l = l->next) { - processor = (Processor *) l->data; - - tmp = g_strdup_printf("%s$CPU%d$%s=%.2f %s|%d:%d|%d\n", - tmp, processor->id, - processor->model_name, - processor->cpu_mhz, _("MHz"), - processor->cputopo->socket_id, - processor->cputopo->core_id, - processor->cputopo->id ); - - hashkey = g_strdup_printf("CPU%d", processor->id); - moreinfo_add_with_prefix("DEV", hashkey, - processor_get_detailed_info(processor)); - g_free(hashkey); - } - - ret = g_strdup_printf("[$ShellParam$]\n" - "ViewType=1\n" - "ColumnTitle$Extra1=%s\n" - "ColumnTitle$Extra2=%s\n" - "[Processors]\n" - "%s", _("Socket:Core"), _("Thread" /*TODO: +s*/), tmp); - g_free(tmp); - - return ret; -} - diff --git a/modules/devices/x86/x86_data.c b/modules/devices/x86/x86_data.c deleted file mode 100644 index c052f4e1..00000000 --- a/modules/devices/x86/x86_data.c +++ /dev/null @@ -1,348 +0,0 @@ -/* - * rpiz - https://github.com/bp0/rpiz - * Copyright (C) 2017 Burt P. <pburt0@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include "x86_data.h" - -#ifndef C_ -#define C_(Ctx, String) String -#endif -#ifndef NC_ -#define NC_(Ctx, String) String -#endif - -/* sources: - * https://unix.stackexchange.com/a/43540 - * https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git/tree/arch/x86/include/asm/cpufeatures.h?id=refs/tags/v4.9 - * hardinfo: modules/devices/x86/processor.c - */ -static struct { - char *name, *meaning; -} tab_flag_meaning[] = { -/* Intel-defined CPU features, CPUID level 0x00000001 (edx) - * See also Wikipedia and table 2-27 in Intel Advanced Vector Extensions Programming Reference */ - { "fpu", NC_("x86-flag", /*/flag:fpu*/ "Onboard FPU (floating point support)") }, - { "vme", NC_("x86-flag", /*/flag:vme*/ "Virtual 8086 mode enhancements") }, - { "de", NC_("x86-flag", /*/flag:de*/ "Debugging Extensions (CR4.DE)") }, - { "pse", NC_("x86-flag", /*/flag:pse*/ "Page Size Extensions (4MB memory pages)") }, - { "tsc", NC_("x86-flag", /*/flag:tsc*/ "Time Stamp Counter (RDTSC)") }, - { "msr", NC_("x86-flag", /*/flag:msr*/ "Model-Specific Registers (RDMSR, WRMSR)") }, - { "pae", NC_("x86-flag", /*/flag:pae*/ "Physical Address Extensions (support for more than 4GB of RAM)") }, - { "mce", NC_("x86-flag", /*/flag:mce*/ "Machine Check Exception") }, - { "cx8", NC_("x86-flag", /*/flag:cx8*/ "CMPXCHG8 instruction (64-bit compare-and-swap)") }, - { "apic", NC_("x86-flag", /*/flag:apic*/ "Onboard APIC") }, - { "sep", NC_("x86-flag", /*/flag:sep*/ "SYSENTER/SYSEXIT") }, - { "mtrr", NC_("x86-flag", /*/flag:mtrr*/ "Memory Type Range Registers") }, - { "pge", NC_("x86-flag", /*/flag:pge*/ "Page Global Enable (global bit in PDEs and PTEs)") }, - { "mca", NC_("x86-flag", /*/flag:mca*/ "Machine Check Architecture") }, - { "cmov", NC_("x86-flag", /*/flag:cmov*/ "CMOV instructions (conditional move) (also FCMOV)") }, - { "pat", NC_("x86-flag", /*/flag:pat*/ "Page Attribute Table") }, - { "pse36", NC_("x86-flag", /*/flag:pse36*/ "36-bit PSEs (huge pages)") }, - { "pn", NC_("x86-flag", /*/flag:pn*/ "Processor serial number") }, - { "clflush", NC_("x86-flag", /*/flag:clflush*/ "Cache Line Flush instruction") }, - { "dts", NC_("x86-flag", /*/flag:dts*/ "Debug Store (buffer for debugging and profiling instructions), or alternately: digital thermal sensor") }, - { "acpi", NC_("x86-flag", /*/flag:acpi*/ "ACPI via MSR (temperature monitoring and clock speed modulation)") }, - { "mmx", NC_("x86-flag", /*/flag:mmx*/ "Multimedia Extensions") }, - { "fxsr", NC_("x86-flag", /*/flag:fxsr*/ "FXSAVE/FXRSTOR, CR4.OSFXSR") }, - { "sse", NC_("x86-flag", /*/flag:sse*/ "Intel SSE vector instructions") }, - { "sse2", NC_("x86-flag", /*/flag:sse2*/ "SSE2") }, - { "ss", NC_("x86-flag", /*/flag:ss*/ "CPU self snoop") }, - { "ht", NC_("x86-flag", /*/flag:ht*/ "Hyper-Threading") }, - { "tm", NC_("x86-flag", /*/flag:tm*/ "Automatic clock control (Thermal Monitor)") }, - { "ia64", NC_("x86-flag", /*/flag:ia64*/ "Intel Itanium Architecture 64-bit (not to be confused with Intel's 64-bit x86 architecture with flag x86-64 or \"AMD64\" bit indicated by flag lm)") }, - { "pbe", NC_("x86-flag", /*/flag:pbe*/ "Pending Break Enable (PBE# pin) wakeup support") }, -/* AMD-defined CPU features, CPUID level 0x80000001 - * See also Wikipedia and table 2-23 in Intel Advanced Vector Extensions Programming Reference */ - { "syscall", NC_("x86-flag", /*/flag:syscall*/ "SYSCALL (Fast System Call) and SYSRET (Return From Fast System Call)") }, - { "mp", NC_("x86-flag", /*/flag:mp*/ "Multiprocessing Capable.") }, - { "nx", NC_("x86-flag", /*/flag:nx*/ "Execute Disable") }, - { "mmxext", NC_("x86-flag", /*/flag:mmxext*/ "AMD MMX extensions") }, - { "fxsr_opt", NC_("x86-flag", /*/flag:fxsr_opt*/ "FXSAVE/FXRSTOR optimizations") }, - { "pdpe1gb", NC_("x86-flag", /*/flag:pdpe1gb*/ "One GB pages (allows hugepagesz=1G)") }, - { "rdtscp", NC_("x86-flag", /*/flag:rdtscp*/ "Read Time-Stamp Counter and Processor ID") }, - { "lm", NC_("x86-flag", /*/flag:lm*/ "Long Mode (x86-64: amd64, also known as Intel 64, i.e. 64-bit capable)") }, - { "3dnow", NC_("x86-flag", /*/flag:3dnow*/ "3DNow! (AMD vector instructions, competing with Intel's SSE1)") }, - { "3dnowext", NC_("x86-flag", /*/flag:3dnowext*/ "AMD 3DNow! extensions") }, -/* Transmeta-defined CPU features, CPUID level 0x80860001 */ - { "recovery", NC_("x86-flag", /*/flag:recovery*/ "CPU in recovery mode") }, - { "longrun", NC_("x86-flag", /*/flag:longrun*/ "Longrun power control") }, - { "lrti", NC_("x86-flag", /*/flag:lrti*/ "LongRun table interface") }, -/* Other features, Linux-defined mapping */ - { "cxmmx", NC_("x86-flag", /*/flag:cxmmx*/ "Cyrix MMX extensions") }, - { "k6_mtrr", NC_("x86-flag", /*/flag:k6_mtrr*/ "AMD K6 nonstandard MTRRs") }, - { "cyrix_arr", NC_("x86-flag", /*/flag:cyrix_arr*/ "Cyrix ARRs (= MTRRs)") }, - { "centaur_mcr", NC_("x86-flag", /*/flag:centaur_mcr*/ "Centaur MCRs (= MTRRs)") }, - { "constant_tsc", NC_("x86-flag", /*/flag:constant_tsc*/ "TSC ticks at a constant rate") }, - { "up", NC_("x86-flag", /*/flag:up*/ "SMP kernel running on UP") }, - { "art", NC_("x86-flag", /*/flag:art*/ "Always-Running Timer") }, - { "arch_perfmon", NC_("x86-flag", /*/flag:arch_perfmon*/ "Intel Architectural PerfMon") }, - { "pebs", NC_("x86-flag", /*/flag:pebs*/ "Precise-Event Based Sampling") }, - { "bts", NC_("x86-flag", /*/flag:bts*/ "Branch Trace Store") }, - { "rep_good", NC_("x86-flag", /*/flag:rep_good*/ "rep microcode works well") }, - { "acc_power", NC_("x86-flag", /*/flag:acc_power*/ "AMD accumulated power mechanism") }, - { "nopl", NC_("x86-flag", /*/flag:nopl*/ "The NOPL (0F 1F) instructions") }, - { "xtopology", NC_("x86-flag", /*/flag:xtopology*/ "cpu topology enum extensions") }, - { "tsc_reliable", NC_("x86-flag", /*/flag:tsc_reliable*/ "TSC is known to be reliable") }, - { "nonstop_tsc", NC_("x86-flag", /*/flag:nonstop_tsc*/ "TSC does not stop in C states") }, - { "extd_apicid", NC_("x86-flag", /*/flag:extd_apicid*/ "has extended APICID (8 bits)") }, - { "amd_dcm", NC_("x86-flag", /*/flag:amd_dcm*/ "multi-node processor") }, - { "aperfmperf", NC_("x86-flag", /*/flag:aperfmperf*/ "APERFMPERF") }, - { "eagerfpu", NC_("x86-flag", /*/flag:eagerfpu*/ "Non lazy FPU restore") }, - { "nonstop_tsc_s3", NC_("x86-flag", /*/flag:nonstop_tsc_s3*/ "TSC doesn't stop in S3 state") }, - { "mce_recovery", NC_("x86-flag", /*/flag:mce_recovery*/ "CPU has recoverable machine checks") }, -/* Intel-defined CPU features, CPUID level 0x00000001 (ecx) - * See also Wikipedia and table 2-26 in Intel Advanced Vector Extensions Programming Reference */ - { "pni", NC_("x86-flag", /*/flag:pni*/ "SSE-3 (\"Prescott New Instructions\")") }, - { "pclmulqdq", NC_("x86-flag", /*/flag:pclmulqdq*/ "Perform a Carry-Less Multiplication of Quadword instruction - accelerator for GCM)") }, - { "dtes64", NC_("x86-flag", /*/flag:dtes64*/ "64-bit Debug Store") }, - { "monitor", NC_("x86-flag", /*/flag:monitor*/ "Monitor/Mwait support (Intel SSE3 supplements)") }, - { "ds_cpl", NC_("x86-flag", /*/flag:ds_cpl*/ "CPL Qual. Debug Store") }, - { "vmx", NC_("x86-flag", /*/flag:vmx*/ "Hardware virtualization, Intel VMX") }, - { "smx", NC_("x86-flag", /*/flag:smx*/ "Safer mode TXT (TPM support)") }, - { "est", NC_("x86-flag", /*/flag:est*/ "Enhanced SpeedStep") }, - { "tm2", NC_("x86-flag", /*/flag:tm2*/ "Thermal Monitor 2") }, - { "ssse3", NC_("x86-flag", /*/flag:ssse3*/ "Supplemental SSE-3") }, - { "cid", NC_("x86-flag", /*/flag:cid*/ "Context ID") }, - { "sdbg", NC_("x86-flag", /*/flag:sdbg*/ "silicon debug") }, - { "fma", NC_("x86-flag", /*/flag:fma*/ "Fused multiply-add") }, - { "cx16", NC_("x86-flag", /*/flag:cx16*/ "CMPXCHG16B") }, - { "xtpr", NC_("x86-flag", /*/flag:xtpr*/ "Send Task Priority Messages") }, - { "pdcm", NC_("x86-flag", /*/flag:pdcm*/ "Performance Capabilities") }, - { "pcid", NC_("x86-flag", /*/flag:pcid*/ "Process Context Identifiers") }, - { "dca", NC_("x86-flag", /*/flag:dca*/ "Direct Cache Access") }, - { "sse4_1", NC_("x86-flag", /*/flag:sse4_1*/ "SSE-4.1") }, - { "sse4_2", NC_("x86-flag", /*/flag:sse4_2*/ "SSE-4.2") }, - { "x2apic", NC_("x86-flag", /*/flag:x2apic*/ "x2APIC") }, - { "movbe", NC_("x86-flag", /*/flag:movbe*/ "Move Data After Swapping Bytes instruction") }, - { "popcnt", NC_("x86-flag", /*/flag:popcnt*/ "Return the Count of Number of Bits Set to 1 instruction (Hamming weight, i.e. bit count)") }, - { "tsc_deadline_timer", NC_("x86-flag", /*/flag:tsc_deadline_timer*/ "Tsc deadline timer") }, - { "aes/aes-ni", NC_("x86-flag", /*/flag:aes/aes-ni*/ "Advanced Encryption Standard (New Instructions)") }, - { "xsave", NC_("x86-flag", /*/flag:xsave*/ "Save Processor Extended States: also provides XGETBY,XRSTOR,XSETBY") }, - { "avx", NC_("x86-flag", /*/flag:avx*/ "Advanced Vector Extensions") }, - { "f16c", NC_("x86-flag", /*/flag:f16c*/ "16-bit fp conversions (CVT16)") }, - { "rdrand", NC_("x86-flag", /*/flag:rdrand*/ "Read Random Number from hardware random number generator instruction") }, - { "hypervisor", NC_("x86-flag", /*/flag:hypervisor*/ "Running on a hypervisor") }, -/* VIA/Cyrix/Centaur-defined CPU features, CPUID level 0xC0000001 */ - { "rng", NC_("x86-flag", /*/flag:rng*/ "Random Number Generator present (xstore)") }, - { "rng_en", NC_("x86-flag", /*/flag:rng_en*/ "Random Number Generator enabled") }, - { "ace", NC_("x86-flag", /*/flag:ace*/ "on-CPU crypto (xcrypt)") }, - { "ace_en", NC_("x86-flag", /*/flag:ace_en*/ "on-CPU crypto enabled") }, - { "ace2", NC_("x86-flag", /*/flag:ace2*/ "Advanced Cryptography Engine v2") }, - { "ace2_en", NC_("x86-flag", /*/flag:ace2_en*/ "ACE v2 enabled") }, - { "phe", NC_("x86-flag", /*/flag:phe*/ "PadLock Hash Engine") }, - { "phe_en", NC_("x86-flag", /*/flag:phe_en*/ "PHE enabled") }, - { "pmm", NC_("x86-flag", /*/flag:pmm*/ "PadLock Montgomery Multiplier") }, - { "pmm_en", NC_("x86-flag", /*/flag:pmm_en*/ "PMM enabled") }, -/* More extended AMD flags: CPUID level 0x80000001, ecx */ - { "lahf_lm", NC_("x86-flag", /*/flag:lahf_lm*/ "Load AH from Flags (LAHF) and Store AH into Flags (SAHF) in long mode") }, - { "cmp_legacy", NC_("x86-flag", /*/flag:cmp_legacy*/ "If yes HyperThreading not valid") }, - { "svm", NC_("x86-flag", /*/flag:svm*/ "\"Secure virtual machine\": AMD-V") }, - { "extapic", NC_("x86-flag", /*/flag:extapic*/ "Extended APIC space") }, - { "cr8_legacy", NC_("x86-flag", /*/flag:cr8_legacy*/ "CR8 in 32-bit mode") }, - { "abm", NC_("x86-flag", /*/flag:abm*/ "Advanced Bit Manipulation") }, - { "sse4a", NC_("x86-flag", /*/flag:sse4a*/ "SSE-4A") }, - { "misalignsse", NC_("x86-flag", /*/flag:misalignsse*/ "indicates if a general-protection exception (#GP) is generated when some legacy SSE instructions operate on unaligned data. Also depends on CR0 and Alignment Checking bit") }, - { "3dnowprefetch", NC_("x86-flag", /*/flag:3dnowprefetch*/ "3DNow prefetch instructions") }, - { "osvw", NC_("x86-flag", /*/flag:osvw*/ "indicates OS Visible Workaround, which allows the OS to work around processor errata.") }, - { "ibs", NC_("x86-flag", /*/flag:ibs*/ "Instruction Based Sampling") }, - { "xop", NC_("x86-flag", /*/flag:xop*/ "extended AVX instructions") }, - { "skinit", NC_("x86-flag", /*/flag:skinit*/ "SKINIT/STGI instructions") }, - { "wdt", NC_("x86-flag", /*/flag:wdt*/ "Watchdog timer") }, - { "lwp", NC_("x86-flag", /*/flag:lwp*/ "Light Weight Profiling") }, - { "fma4", NC_("x86-flag", /*/flag:fma4*/ "4 operands MAC instructions") }, - { "tce", NC_("x86-flag", /*/flag:tce*/ "translation cache extension") }, - { "nodeid_msr", NC_("x86-flag", /*/flag:nodeid_msr*/ "NodeId MSR") }, - { "tbm", NC_("x86-flag", /*/flag:tbm*/ "Trailing Bit Manipulation") }, - { "topoext", NC_("x86-flag", /*/flag:topoext*/ "Topology Extensions CPUID leafs") }, - { "perfctr_core", NC_("x86-flag", /*/flag:perfctr_core*/ "Core Performance Counter Extensions") }, - { "perfctr_nb", NC_("x86-flag", /*/flag:perfctr_nb*/ "NB Performance Counter Extensions") }, - { "bpext", NC_("x86-flag", /*/flag:bpext*/ "data breakpoint extension") }, - { "ptsc", NC_("x86-flag", /*/flag:ptsc*/ "performance time-stamp counter") }, - { "perfctr_l2", NC_("x86-flag", /*/flag:perfctr_l2*/ "L2 Performance Counter Extensions") }, - { "mwaitx", NC_("x86-flag", /*/flag:mwaitx*/ "MWAIT extension (MONITORX/MWAITX)") }, -/* Auxiliary flags: Linux defined - For features scattered in various CPUID levels */ - { "cpb", NC_("x86-flag", /*/flag:cpb*/ "AMD Core Performance Boost") }, - { "epb", NC_("x86-flag", /*/flag:epb*/ "IA32_ENERGY_PERF_BIAS support") }, - { "hw_pstate", NC_("x86-flag", /*/flag:hw_pstate*/ "AMD HW-PState") }, - { "proc_feedback", NC_("x86-flag", /*/flag:proc_feedback*/ "AMD ProcFeedbackInterface") }, - { "intel_pt", NC_("x86-flag", /*/flag:intel_pt*/ "Intel Processor Tracing") }, -/* Virtualization flags: Linux defined */ - { "tpr_shadow", NC_("x86-flag", /*/flag:tpr_shadow*/ "Intel TPR Shadow") }, - { "vnmi", NC_("x86-flag", /*/flag:vnmi*/ "Intel Virtual NMI") }, - { "flexpriority", NC_("x86-flag", /*/flag:flexpriority*/ "Intel FlexPriority") }, - { "ept", NC_("x86-flag", /*/flag:ept*/ "Intel Extended Page Table") }, - { "vpid", NC_("x86-flag", /*/flag:vpid*/ "Intel Virtual Processor ID") }, - { "vmmcall", NC_("x86-flag", /*/flag:vmmcall*/ "prefer VMMCALL to VMCALL") }, -/* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx) */ - { "fsgsbase", NC_("x86-flag", /*/flag:fsgsbase*/ "{RD/WR}{FS/GS}BASE instructions") }, - { "tsc_adjust", NC_("x86-flag", /*/flag:tsc_adjust*/ "TSC adjustment MSR") }, - { "bmi1", NC_("x86-flag", /*/flag:bmi1*/ "1st group bit manipulation extensions") }, - { "hle", NC_("x86-flag", /*/flag:hle*/ "Hardware Lock Elision") }, - { "avx2", NC_("x86-flag", /*/flag:avx2*/ "AVX2 instructions") }, - { "smep", NC_("x86-flag", /*/flag:smep*/ "Supervisor Mode Execution Protection") }, - { "bmi2", NC_("x86-flag", /*/flag:bmi2*/ "2nd group bit manipulation extensions") }, - { "erms", NC_("x86-flag", /*/flag:erms*/ "Enhanced REP MOVSB/STOSB") }, - { "invpcid", NC_("x86-flag", /*/flag:invpcid*/ "Invalidate Processor Context ID") }, - { "rtm", NC_("x86-flag", /*/flag:rtm*/ "Restricted Transactional Memory") }, - { "cqm", NC_("x86-flag", /*/flag:cqm*/ "Cache QoS Monitoring") }, - { "mpx", NC_("x86-flag", /*/flag:mpx*/ "Memory Protection Extension") }, - { "avx512f", NC_("x86-flag", /*/flag:avx512f*/ "AVX-512 foundation") }, - { "avx512dq", NC_("x86-flag", /*/flag:avx512dq*/ "AVX-512 Double/Quad instructions") }, - { "rdseed", NC_("x86-flag", /*/flag:rdseed*/ "The RDSEED instruction") }, - { "adx", NC_("x86-flag", /*/flag:adx*/ "The ADCX and ADOX instructions") }, - { "smap", NC_("x86-flag", /*/flag:smap*/ "Supervisor Mode Access Prevention") }, - { "clflushopt", NC_("x86-flag", /*/flag:clflushopt*/ "CLFLUSHOPT instruction") }, - { "clwb", NC_("x86-flag", /*/flag:clwb*/ "CLWB instruction") }, - { "avx512pf", NC_("x86-flag", /*/flag:avx512pf*/ "AVX-512 Prefetch") }, - { "avx512er", NC_("x86-flag", /*/flag:avx512er*/ "AVX-512 Exponential and Reciprocal") }, - { "avx512cd", NC_("x86-flag", /*/flag:avx512cd*/ "AVX-512 Conflict Detection") }, - { "sha_ni", NC_("x86-flag", /*/flag:sha_ni*/ "SHA1/SHA256 Instruction Extensions") }, - { "avx512bw", NC_("x86-flag", /*/flag:avx512bw*/ "AVX-512 Byte/Word instructions") }, - { "avx512vl", NC_("x86-flag", /*/flag:avx512vl*/ "AVX-512 128/256 Vector Length extensions") }, -/* Extended state features, CPUID level 0x0000000d:1 (eax) */ - { "xsaveopt", NC_("x86-flag", /*/flag:xsaveopt*/ "Optimized XSAVE") }, - { "xsavec", NC_("x86-flag", /*/flag:xsavec*/ "XSAVEC") }, - { "xgetbv1", NC_("x86-flag", /*/flag:xgetbv1*/ "XGETBV with ECX = 1") }, - { "xsaves", NC_("x86-flag", /*/flag:xsaves*/ "XSAVES/XRSTORS") }, -/* Intel-defined CPU QoS sub-leaf, CPUID level 0x0000000F:0 (edx) */ - { "cqm_llc", NC_("x86-flag", /*/flag:cqm_llc*/ "LLC QoS") }, -/* Intel-defined CPU QoS sub-leaf, CPUID level 0x0000000F:1 (edx) */ - { "cqm_occup_llc", NC_("x86-flag", /*/flag:cqm_occup_llc*/ "LLC occupancy monitoring") }, - { "cqm_mbm_total", NC_("x86-flag", /*/flag:cqm_mbm_total*/ "LLC total MBM monitoring") }, - { "cqm_mbm_local", NC_("x86-flag", /*/flag:cqm_mbm_local*/ "LLC local MBM monitoring") }, -/* AMD-defined CPU features, CPUID level 0x80000008 (ebx) */ - { "clzero", NC_("x86-flag", /*/flag:clzero*/ "CLZERO instruction") }, - { "irperf", NC_("x86-flag", /*/flag:irperf*/ "instructions retired performance counter") }, -/* Thermal and Power Management leaf, CPUID level 0x00000006 (eax) */ - { "dtherm", NC_("x86-flag", /*/flag:dtherm*/ "digital thermal sensor") }, /* formerly dts */ - { "ida", NC_("x86-flag", /*/flag:ida*/ "Intel Dynamic Acceleration") }, - { "arat", NC_("x86-flag", /*/flag:arat*/ "Always Running APIC Timer") }, - { "pln", NC_("x86-flag", /*/flag:pln*/ "Intel Power Limit Notification") }, - { "pts", NC_("x86-flag", /*/flag:pts*/ "Intel Package Thermal Status") }, - { "hwp", NC_("x86-flag", /*/flag:hwp*/ "Intel Hardware P-states") }, - { "hwp_notify", NC_("x86-flag", /*/flag:hwp_notify*/ "HWP notification") }, - { "hwp_act_window", NC_("x86-flag", /*/flag:hwp_act_window*/ "HWP Activity Window") }, - { "hwp_epp", NC_("x86-flag", /*/flag:hwp_epp*/ "HWP Energy Performance Preference") }, - { "hwp_pkg_req", NC_("x86-flag", /*/flag:hwp_pkg_req*/ "HWP package-level request") }, -/* AMD SVM Feature Identification, CPUID level 0x8000000a (edx) */ - { "npt", NC_("x86-flag", /*/flag:npt*/ "AMD Nested Page Table support") }, - { "lbrv", NC_("x86-flag", /*/flag:lbrv*/ "AMD LBR Virtualization support") }, - { "svm_lock", NC_("x86-flag", /*/flag:svm_lock*/ "AMD SVM locking MSR") }, - { "nrip_save", NC_("x86-flag", /*/flag:nrip_save*/ "AMD SVM next_rip save") }, - { "tsc_scale", NC_("x86-flag", /*/flag:tsc_scale*/ "AMD TSC scaling support") }, - { "vmcb_clean", NC_("x86-flag", /*/flag:vmcb_clean*/ "AMD VMCB clean bits support") }, - { "flushbyasid", NC_("x86-flag", /*/flag:flushbyasid*/ "AMD flush-by-ASID support") }, - { "decodeassists", NC_("x86-flag", /*/flag:decodeassists*/ "AMD Decode Assists support") }, - { "pausefilter", NC_("x86-flag", /*/flag:pausefilter*/ "AMD filtered pause intercept") }, - { "pfthreshold", NC_("x86-flag", /*/flag:pfthreshold*/ "AMD pause filter threshold") }, - { "avic", NC_("x86-flag", /*/flag:avic*/ "Virtual Interrupt Controller") }, -/* Intel-defined CPU features, CPUID level 0x00000007:0 (ecx) */ - { "pku", NC_("x86-flag", /*/flag:pku*/ "Protection Keys for Userspace") }, - { "ospke", NC_("x86-flag", /*/flag:ospke*/ "OS Protection Keys Enable") }, -/* AMD-defined CPU features, CPUID level 0x80000007 (ebx) */ - { "overflow_recov", NC_("x86-flag", /*/flag:overflow_recov*/ "MCA overflow recovery support") }, - { "succor", NC_("x86-flag", /*/flag:succor*/ "uncorrectable error containment and recovery") }, - { "smca", NC_("x86-flag", /*/flag:smca*/ "Scalable MCA") }, - -/* bug workarounds */ - { "bug:f00f", NC_("x86-flag", /*/bug:f00f*/ "Intel F00F bug") }, - { "bug:fdiv", NC_("x86-flag", /*/bug:fdiv*/ "FPU FDIV") }, - { "bug:coma", NC_("x86-flag", /*/bug:coma*/ "Cyrix 6x86 coma") }, - { "bug:tlb_mmatch", NC_("x86-flag", /*/bug:tlb_mmatch*/ "AMD Erratum 383") }, - { "bug:apic_c1e", NC_("x86-flag", /*/bug:apic_c1e*/ "AMD Erratum 400") }, - { "bug:11ap", NC_("x86-flag", /*/bug:11ap*/ "Bad local APIC aka 11AP") }, - { "bug:fxsave_leak", NC_("x86-flag", /*/bug:fxsave_leak*/ "FXSAVE leaks FOP/FIP/FOP") }, - { "bug:clflush_monitor", NC_("x86-flag", /*/bug:clflush_monitor*/ "AAI65, CLFLUSH required before MONITOR") }, - { "bug:sysret_ss_attrs", NC_("x86-flag", /*/bug:sysret_ss_attrs*/ "SYSRET doesn't fix up SS attrs") }, - { "bug:espfix", NC_("x86-flag", /*/bug:espfix*/ "IRET to 16-bit SS corrupts ESP/RSP high bits") }, - { "bug:null_seg", NC_("x86-flag", /*/bug:null_seg*/ "Nulling a selector preserves the base") }, /* see: detect_null_seg_behavior() */ - { "bug:swapgs_fence", NC_("x86-flag", /*/bug:swapgs_fence*/ "SWAPGS without input dep on GS") }, - { "bug:monitor", NC_("x86-flag", /*/bug:monitor*/ "IPI required to wake up remote CPU") }, - { "bug:amd_e400", NC_("x86-flag", /*/bug:amd_e400*/ "AMD Erratum 400") }, - { "bug:cpu_insecure", NC_("x86-flag", /*/bug:cpu_insecure & bug:cpu_meltdown*/ "CPU is affected by meltdown attack and needs kernel page table isolation") }, - { "bug:cpu_meltdown", NC_("x86-flag", /*/bug:cpu_insecure & bug:cpu_meltdown*/ "CPU is affected by meltdown attack and needs kernel page table isolation") }, - { "bug:spectre_v1", NC_("x86-flag", /*/bug:spectre_v1*/ "CPU is affected by Spectre variant 1 attack with conditional branches") }, - { "bug:spectre_v2", NC_("x86-flag", /*/bug:spectre_v2*/ "CPU is affected by Spectre variant 2 attack with indirect branches") }, -/* power management - * ... from arch/x86/kernel/cpu/powerflags.h */ - { "pm:ts", NC_("x86-flag", /*/flag:pm:ts*/ "temperature sensor") }, - { "pm:fid", NC_("x86-flag", /*/flag:pm:fid*/ "frequency id control") }, - { "pm:vid", NC_("x86-flag", /*/flag:pm:vid*/ "voltage id control") }, - { "pm:ttp", NC_("x86-flag", /*/flag:pm:ttp*/ "thermal trip") }, - { "pm:tm", NC_("x86-flag", /*/flag:pm:tm*/ "hardware thermal control") }, - { "pm:stc", NC_("x86-flag", /*/flag:pm:stc*/ "software thermal control") }, - { "pm:100mhzsteps", NC_("x86-flag", /*/flag:pm:100mhzsteps*/ "100 MHz multiplier control") }, - { "pm:hwpstate", NC_("x86-flag", /*/flag:pm:hwpstate*/ "hardware P-state control") }, - { "pm:cpb", NC_("x86-flag", /*/flag:pm:cpb*/ "core performance boost") }, - { "pm:eff_freq_ro", NC_("x86-flag", /*/flag:pm:eff_freq_ro*/ "Readonly aperf/mperf") }, - { "pm:proc_feedback", NC_("x86-flag", /*/flag:pm:proc_feedback*/ "processor feedback interface") }, - { "pm:acc_power", NC_("x86-flag", /*/flag:pm:acc_power*/ "accumulated power mechanism") }, - { NULL, NULL}, -}; - -static char all_flags[4096] = ""; - -#define APPEND_FLAG(f) strcat(all_flags, f); strcat(all_flags, " "); -const char *x86_flag_list() { - int i = 0, built = 0; - built = strlen(all_flags); - if (!built) { - while(tab_flag_meaning[i].name != NULL) { - APPEND_FLAG(tab_flag_meaning[i].name); - i++; - } - } - return all_flags; -} - -const char *x86_flag_meaning(const char *flag) { - int i = 0; - if (flag) - while(tab_flag_meaning[i].name != NULL) { - if (strcmp(tab_flag_meaning[i].name, flag) == 0) { - if (tab_flag_meaning[i].meaning != NULL) - return C_("x86-flag", tab_flag_meaning[i].meaning); - else return NULL; - } - i++; - } - return NULL; -} - -static void x86_flag_find_dups(void) { - int t, i; - - t = 0; - while(tab_flag_meaning[t].name != NULL) { - i = t+1; - while(tab_flag_meaning[i].name != NULL) { - if (strcmp(tab_flag_meaning[t].name, tab_flag_meaning[i].name) == 0) { - printf("x86-flag duplicate definition: %s\n ... %d: %s\n ... %d: %s\n", - tab_flag_meaning[i].name, - t, tab_flag_meaning[t].meaning, - i, tab_flag_meaning[i].meaning); - } - i++; - } - t++; - } -} diff --git a/modules/devices/x86/x86_data.h b/modules/devices/x86/x86_data.h deleted file mode 100644 index 66a4c80f..00000000 --- a/modules/devices/x86/x86_data.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * rpiz - https://github.com/bp0/rpiz - * Copyright (C) 2017 Burt P. <pburt0@gmail.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - */ - -#ifndef _X86DATA_H_ -#define _X86DATA_H_ - -/* cpu flags from /proc/cpuinfo */ -const char *x86_flag_list(void); /* list of all known flags */ -const char *x86_flag_meaning(const char *flag); /* lookup flag meaning */ - -#endif |