nvml: separated vendor id to string function

for the day nvidia will fix their nvmlDeviceGetPciInfo api..
This commit is contained in:
Tanguy Pruvot 2015-06-23 09:38:53 +02:00
parent e21c75793a
commit 7981e83db7
2 changed files with 49 additions and 30 deletions

View File

@ -232,7 +232,7 @@ nvml_handle * nvml_create()
nvmlh->nvml_pci_domain_id[i] = pciinfo.domain; nvmlh->nvml_pci_domain_id[i] = pciinfo.domain;
nvmlh->nvml_pci_bus_id[i] = pciinfo.bus; nvmlh->nvml_pci_bus_id[i] = pciinfo.bus;
nvmlh->nvml_pci_device_id[i] = pciinfo.device; nvmlh->nvml_pci_device_id[i] = pciinfo.device;
nvmlh->nvml_pci_subsys_id[i] = pciinfo.pci_device_id; nvmlh->nvml_pci_subsys_id[i] = pciinfo.pci_device_id; /* pci_subsystem_id broken (0xccccccccc) */
nvmlh->app_clocks[i] = NVML_FEATURE_UNKNOWN; nvmlh->app_clocks[i] = NVML_FEATURE_UNKNOWN;
if (nvmlh->nvmlDeviceSetAPIRestriction) { if (nvmlh->nvmlDeviceSetAPIRestriction) {
@ -779,7 +779,7 @@ int nvapi_init()
NvAPI_ShortString str; NvAPI_ShortString str;
ret = NvAPI_SYS_GetDriverAndBranchVersion(&udv, str); ret = NvAPI_SYS_GetDriverAndBranchVersion(&udv, str);
if (ret == NVAPI_OK) { if (ret == NVAPI_OK) {
sprintf(driver_version,"%d.%d", udv/100, udv % 100); sprintf(driver_version,"%d.%02d", udv / 100, udv % 100);
} }
return 0; return 0;
@ -888,6 +888,37 @@ unsigned int gpu_power(struct cgpu_info *gpu)
return mw; return mw;
} }
static int translate_vendor_id(uint16_t vid, char *vendorname)
{
bool identified = false;
if (!vendorname)
return -EINVAL;
struct VENDORS {
const uint16_t vid;
const char *name;
} vendors[] = {
{ 0x1043, "ASUS" },
{ 0x10B0, "Gainward" },
// { 0x10DE, "NVIDIA" },
{ 0x1458, "Gigabyte" },
{ 0x1462, "MSI" },
{ 0x3842, "EVGA" },
{ 0, "" }
};
for(int v=0; v < ARRAY_SIZE(vendors); v++) {
if (vid == vendors[v].vid) {
strcpy(vendorname, vendors[v].name);
return vid;
}
}
if (!identified && opt_debug)
applog(LOG_DEBUG, "nvml: Unknown vendor %04x\n", vid);
return 0;
}
#ifdef HAVE_PCIDEV #ifdef HAVE_PCIDEV
extern "C" { extern "C" {
#include <errno.h> #include <errno.h>
@ -900,19 +931,6 @@ static int linux_gpu_vendor(uint8_t pci_bus_id, char* vendorname, uint16_t &pid)
struct pci_dev *dev; struct pci_dev *dev;
uint16_t subdevice; uint16_t subdevice;
struct VENDORS {
const uint16_t vid;
const char *name;
} vendors[] = {
{ 0x1043, "ASUS" },
{ 0x10B0, "Gainward" },
{ 0x10DE, "NVIDIA" },
{ 0x1458, "Gigabyte" },
{ 0x1462, "MSI" },
{ 0x3842, "EVGA" },
{ 0, "" }
};
if (!vendorname) if (!vendorname)
return -EINVAL; return -EINVAL;
@ -925,24 +943,16 @@ static int linux_gpu_vendor(uint8_t pci_bus_id, char* vendorname, uint16_t &pid)
for(dev = pci->devices; dev; dev = dev->next) for(dev = pci->devices; dev; dev = dev->next)
{ {
if (dev->device_class == PCI_CLASS_DISPLAY_VGA && dev->bus == pci_bus_id) if (dev->bus == pci_bus_id && dev->vendor_id == 0x10DE)
{ {
bool identified = false; if (!(dev->known_fields & PCI_FILL_CLASS))
pci_fill_info(dev, PCI_FILL_CLASS);
if (dev->device_class != PCI_CLASS_DISPLAY_VGA)
continue;
subvendor = pci_read_word(dev, PCI_SUBSYSTEM_VENDOR_ID); subvendor = pci_read_word(dev, PCI_SUBSYSTEM_VENDOR_ID);
subdevice = pci_read_word(dev, PCI_SUBSYSTEM_ID); // model subdevice = pci_read_word(dev, PCI_SUBSYSTEM_ID); // model
for(int v=0; v < ARRAY_SIZE(vendors); v++) { translate_vendor_id(subvendor, vendorname);
if (subvendor == vendors[v].vid) {
strcpy(vendorname, vendors[v].name);
identified = true;
pid = subdevice;
break;
}
}
if (!identified && !opt_quiet)
applog(LOG_DEBUG, "%04x:%04x (Unknown vendor)\n",
subvendor, subdevice);
} }
} }
pci_cleanup(pci); pci_cleanup(pci);
@ -956,7 +966,15 @@ int gpu_vendor(uint8_t pci_bus_id, char *vendorname)
uint16_t pid = 0; uint16_t pid = 0;
return linux_gpu_vendor(pci_bus_id, vendorname, pid); return linux_gpu_vendor(pci_bus_id, vendorname, pid);
#else #else
return 0; uint16_t vid = 0, pid = 0;
if (hnvml) { // may not be initialized on start...
for (int id=0; id < hnvml->nvml_gpucount; id++) {
if (hnvml->nvml_pci_bus_id[id] == pci_bus_id) {
nvml_get_info(hnvml, id, vid, pid);
}
}
}
return translate_vendor_id(vid, vendorname);
#endif #endif
} }

View File

@ -231,6 +231,7 @@ extern "C" int scanhash_x11(int thr_id, uint32_t *pdata,
return res; return res;
} else { } else {
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce); applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
pdata[19] = foundNonce + 1;
} }
} }