diff options
| author | Burt P <pburt0@gmail.com> | 2018-03-23 13:17:33 -0500 | 
|---|---|---|
| committer | Leandro A. F. Pereira <leandro@hardinfo.org> | 2018-04-24 07:43:43 -0700 | 
| commit | bcd206e60096f2a7d3c748feaa918cb500074f90 (patch) | |
| tree | cf5f40f3167f623dee54bd6c7e37ff813d41d4e7 /modules | |
| parent | 3fa490a87d4d0b553c1b83f34fe1886af8b3a0e0 (diff) | |
[new] devices/gpu: graphics processors
Signed-off-by: Burt P <pburt0@gmail.com>
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/devices.c | 42 | ||||
| -rw-r--r-- | modules/devices/gpu.c | 203 | 
2 files changed, 229 insertions, 16 deletions
| diff --git a/modules/devices.c b/modules/devices.c index 5e757c15..c30563f6 100644 --- a/modules/devices.c +++ b/modules/devices.c @@ -40,6 +40,7 @@  #include "dt_util.h"  gchar *callback_processors(); +gchar *callback_gpu();  gchar *callback_memory();  gchar *callback_battery();  gchar *callback_pci(); @@ -56,6 +57,7 @@ gchar *callback_dtree();  gchar *callback_device_resources();  void scan_processors(gboolean reload); +void scan_gpu(gboolean reload);  void scan_memory(gboolean reload);  void scan_battery(gboolean reload);  void scan_pci(gboolean reload); @@ -79,6 +81,7 @@ enum {      ENTRY_DTREE,      ENTRY_PROCESSOR,      ENTRY_MEMORY, +    ENTRY_GPU,      ENTRY_PCI,      ENTRY_USB,      ENTRY_PRINTERS, @@ -94,6 +97,7 @@ enum {  static ModuleEntry entries[] = {      [ENTRY_PROCESSOR] = {N_("Processor"), "processor.png", callback_processors, scan_processors, MODULE_FLAG_NONE},      [ENTRY_MEMORY] = {N_("Memory"), "memory.png", callback_memory, scan_memory, MODULE_FLAG_NONE}, +    [ENTRY_GPU] = {N_("Graphics Processors"), "devices.png", callback_gpu, scan_gpu, MODULE_FLAG_NONE},      [ENTRY_PCI] = {N_("PCI Devices"), "devices.png", callback_pci, scan_pci, MODULE_FLAG_NONE},      [ENTRY_USB] = {N_("USB Devices"), "usb.png", callback_usb, scan_usb, MODULE_FLAG_NONE},      [ENTRY_PRINTERS] = {N_("Printers"), "printer.png", callback_printers, scan_printers, MODULE_FLAG_NONE}, @@ -126,6 +130,13 @@ gchar *lginterval = NULL;  #include <vendor.h> +extern gchar *gpu_summary; +const gchar *get_gpu_summary() { +    if (gpu_summary == NULL) +        scan_gpu(FALSE); +    return gpu_summary; +} +  static gint proc_cmp_model_name(Processor *a, Processor *b) {      return g_strcmp0(a->model_name, b->model_name);  } @@ -336,21 +347,6 @@ gchar *get_processor_max_frequency(void)      }  } -gchar *get_pci_device_description(gchar *pci_id) -{ -    gchar *description; - -    if (!_pci_devices) { -        scan_pci(FALSE); -    } - -    if ((description = g_hash_table_lookup(_pci_devices, pci_id))) { -        return g_strdup(description); -    } - -    return NULL; -} -  gchar *get_memory_total(void)  {      scan_memory(FALSE); @@ -413,8 +409,8 @@ ShellModuleMethod *hi_exported_methods(void)  	{"getStorageDevices", get_storage_devices},  	{"getPrinters", get_printers},  	{"getInputDevices", get_input_devices}, -	{"getPCIDeviceDescription", get_pci_device_description},  	{"getMotherboard", get_motherboard}, +	{"getGPUList", get_gpu_summary},  	{NULL}      }; @@ -486,6 +482,13 @@ void scan_battery(gboolean reload)      SCAN_END();  } +void scan_gpu(gboolean reload) +{ +    SCAN_START(); +    scan_gpu_do(); +    SCAN_END(); +} +  void scan_pci(gboolean reload)  {      SCAN_START(); @@ -587,6 +590,13 @@ gchar *callback_pci()  			   "[$ShellParam$]\n" "ViewType=1\n", pci_list);  } +gchar *callback_gpu() +{ +    return g_strdup_printf("[GPUs]\n" +			   "%s" +			   "[$ShellParam$]\n" "ViewType=1\n", gpu_list); +} +  gchar *callback_sensors()  {      return g_strdup_printf("[Sensors]\n" diff --git a/modules/devices/gpu.c b/modules/devices/gpu.c new file mode 100644 index 00000000..d90bf94a --- /dev/null +++ b/modules/devices/gpu.c @@ -0,0 +1,203 @@ +/* + *    HardInfo - Displays System Information + *    Copyright (C) 2003-2017 Leandro A. F. Pereira <leandro@hardinfo.org> + *    This file + *    Copyright (C) 2018 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 + */ + +#include <string.h> + +#include "hardinfo.h" +#include "devices.h" +#include "gpu_util.h" + +void scan_gpu_do(void); + +gchar *gpu_list = NULL; +gchar *gpu_summary = NULL; + +void gpu_summary_add(const char *gpu_name) { +    if (strlen(gpu_summary) == 0) { +        /* first one */ +        gpu_summary = h_strdup_cprintf("%s", gpu_summary, gpu_name); +    } else { +        /* additional */ +        gpu_summary = h_strdup_cprintf(" + %s", gpu_summary, gpu_name); +    } +} + +#define UNKIFNULL_AC(f) (f != NULL) ? f : _("(Unknown)"); + +static void _gpu_pci_dev(gpud* gpu) { +    pcid *p = gpu->pci_dev; +    gchar *str; +    gchar *vendor, *svendor, *v_str, *sv_str, *product, *sproduct; +    gchar *name, *key; +    gchar *drm_path = NULL; + +    vendor = UNKIFNULL_AC(p->vendor_id_str); +    svendor = UNKIFNULL_AC(p->sub_vendor_id_str); +    product = UNKIFNULL_AC(p->device_id_str); +    sproduct = UNKIFNULL_AC(p->sub_device_id_str); +    if (gpu->drm_dev) +        drm_path = g_strdup_printf("/dev/dri/%s", gpu->drm_dev); +    else +        drm_path = g_strdup(_("(Unknown)")); + +#define USE_HARDINFO_VENDOR_THING 0 +    if (USE_HARDINFO_VENDOR_THING) { +        const gchar *v_url = vendor_get_url(vendor); +        const gchar *v_name = vendor_get_name(vendor); +        if (v_url != NULL) { +            v_str = g_strdup_printf("%s (%s)", v_name, v_url); +        } else { +            v_str = g_strdup(vendor); +        } +        v_url = vendor_get_url(svendor); +        v_name = vendor_get_name(svendor); +        if (v_url != NULL) { +            sv_str = g_strdup_printf("%s (%s)", v_name, v_url); +        } else { +            sv_str = g_strdup(svendor); +        } +    } else { +            v_str = g_strdup(vendor); +            sv_str = g_strdup(svendor); +    } + +    name = g_strdup_printf("%s %s", vendor, product); +    key = g_strdup_printf("GPU%s", gpu->id); + +    gpu_summary_add((gpu->nice_name) ? gpu->nice_name : name); +    gpu_list = h_strdup_cprintf("$%s$%s=%s\n", gpu_list, key, gpu->id, name); + +    gchar *vendor_device_str; +    if (p->vendor_id == p->sub_vendor_id && p->device_id == p->sub_device_id) { +        vendor_device_str = g_strdup_printf( +                     /* Vendor */     "%s=[%04x] %s\n" +                     /* Device */     "%s=[%04x] %s\n", +                    _("Vendor"), p->vendor_id, v_str, +                    _("Device"), p->device_id, product); +    } else { +        vendor_device_str = g_strdup_printf( +                     /* Vendor */     "%s=[%04x] %s\n" +                     /* Device */     "%s=[%04x] %s\n" +                     /* Sub-device vendor */     "%s=[%04x] %s\n" +                     /* Sub-device */     "%s=[%04x] %s\n", +                    _("Vendor"), p->vendor_id, v_str, +                    _("Device"), p->device_id, product, +                    _("SVendor"), p->sub_vendor_id, sv_str, +                    _("SDevice"), p->sub_device_id, sproduct); +    } + +    gchar *pcie_str; +    if (p->pcie_width_curr) { +        pcie_str = g_strdup_printf("[%s]\n" +                     /* Width (max) */  "%s=x%u\n" +                     /* Speed (max) */  "%s=%0.1f %s\n", +                    _("PCI Express"), +                    _("Maximum Link Width"), p->pcie_width_max, +                    _("Maximum Link Speed"), p->pcie_speed_max, _("GT/s") ); +    } else +        pcie_str = strdup(""); + +    str = g_strdup_printf("[%s]\n" +             /* Location */  "%s=%s\n" +             /* DRM Dev */   "%s=%s\n" +             /* Class */     "%s=[%04x] %s\n" +                             "%s" +             /* Revision */  "%s=%02x\n" +                             "%s" +                             "[%s]\n" +            /* Driver */     "%s=%s\n" +            /* Modules */    "%s=%s\n", +                _("Device Information"), +                _("Location"), gpu->location, +                _("DRM Device"), drm_path, +                _("Class"), p->class, p->class_str, +                vendor_device_str, +                _("Revision"), p->revision, +                pcie_str, +                _("Driver"), +                _("In Use"), (p->driver) ? p->driver : _("(Unknown)"), +                _("Kernel Modules"), (p->driver_list) ? p->driver_list : _("(Unknown)") +                ); + +    moreinfo_add_with_prefix("DEV", key, str); /* str now owned by morinfo */ + +    g_free(drm_path); +    g_free(vendor_device_str); +    g_free(v_str); +    g_free(sv_str); +    g_free(name); +    g_free(key); +} + +int _dt_soc_gpu(gpud *gpu) { +    static char UNKSOC[] = "(Unknown)"; /* don't translate this */ +    gchar *vendor = gpu->vendor_str; +    gchar *device = gpu->device_str; +    if (vendor == NULL) vendor = UNKSOC; +    if (device == NULL) device = UNKSOC; +    gchar *key = g_strdup(gpu->id); +    gchar *name = (vendor == UNKSOC && device == UNKSOC) +            ? g_strdup(_("Unknown integrated GPU")) +            : g_strdup_printf("%s %s", vendor, device); +    gpu_summary_add((gpu->nice_name) ? gpu->nice_name : name); +    gpu_list = h_strdup_cprintf("$%s$%s=%s\n", gpu_list, key, key, name); +    gchar *str = g_strdup_printf("[%s]\n" +             /* Location */  "%s=%s\n" +             /* dt compat */  "%s=%s\n" +             /* Vendor */  "%s=%s\n" +             /* Device */  "%s=%s\n", +                _("Device Information"), +                _("Location"), gpu->location, +                _("DT Compatibility"), gpu->dt_compat, +                _("Vendor"), vendor, +                _("Device"), device +                ); +    moreinfo_add_with_prefix("DEV", key, str); /* str now owned by morinfo */ +    return 1; +} + +void scan_gpu_do(void) { +    if (gpu_summary) +        g_free(gpu_summary); +    if (gpu_list) { +        moreinfo_del_with_prefix("DEV:GPU"); +        g_free(gpu_list); +    } +    gpu_summary = strdup(""); +    gpu_list = g_strdup_printf("[%s]\n", _("GPUs")); + +    gpud *gpus = gpu_get_device_list(); +    gpud *curr = gpus; + +    int c = gpud_list_count(gpus); + +    if (c > 0) { +        while(curr) { +            if (curr->pci_dev) { +                _gpu_pci_dev(curr); +            } +            if (curr->dt_compat) { +                _dt_soc_gpu(curr); +            } +            curr=curr->next; +        } +    } +    gpud_list_free(gpus); +} | 
