Skip to content

Commit

Permalink
nvml: separated vendor id to string function
Browse files Browse the repository at this point in the history
for the day nvidia will fix their nvmlDeviceGetPciInfo api..
  • Loading branch information
tpruvot committed Jun 23, 2015
1 parent e21c757 commit 7981e83
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
74 changes: 46 additions & 28 deletions nvml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ nvml_handle * nvml_create()
nvmlh->nvml_pci_domain_id[i] = pciinfo.domain;
nvmlh->nvml_pci_bus_id[i] = pciinfo.bus;
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;
if (nvmlh->nvmlDeviceSetAPIRestriction) {
Expand Down Expand Up @@ -779,7 +779,7 @@ int nvapi_init()
NvAPI_ShortString str;
ret = NvAPI_SYS_GetDriverAndBranchVersion(&udv, str);
if (ret == NVAPI_OK) {
sprintf(driver_version,"%d.%d", udv/100, udv % 100);
sprintf(driver_version,"%d.%02d", udv / 100, udv % 100);
}

return 0;
Expand Down Expand Up @@ -888,31 +888,49 @@ unsigned int gpu_power(struct cgpu_info *gpu)
return mw;
}

#ifdef HAVE_PCIDEV
extern "C" {
#include <errno.h>
#include <pci/pci.h>
}
static int linux_gpu_vendor(uint8_t pci_bus_id, char* vendorname, uint16_t &pid)
static int translate_vendor_id(uint16_t vid, char *vendorname)
{
uint16_t subvendor = 0;
struct pci_access *pci;
struct pci_dev *dev;
uint16_t subdevice;
bool identified = false;

if (!vendorname)
return -EINVAL;

struct VENDORS {
const uint16_t vid;
const char *name;
} vendors[] = {
{ 0x1043, "ASUS" },
{ 0x10B0, "Gainward" },
{ 0x10DE, "NVIDIA" },
// { 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
extern "C" {
#include <errno.h>
#include <pci/pci.h>
}
static int linux_gpu_vendor(uint8_t pci_bus_id, char* vendorname, uint16_t &pid)
{
uint16_t subvendor = 0;
struct pci_access *pci;
struct pci_dev *dev;
uint16_t subdevice;

if (!vendorname)
return -EINVAL;

Expand All @@ -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)
{
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);
subdevice = pci_read_word(dev, PCI_SUBSYSTEM_ID); // model

for(int v=0; v < ARRAY_SIZE(vendors); v++) {
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);
translate_vendor_id(subvendor, vendorname);
}
}
pci_cleanup(pci);
Expand All @@ -956,7 +966,15 @@ int gpu_vendor(uint8_t pci_bus_id, char *vendorname)
uint16_t pid = 0;
return linux_gpu_vendor(pci_bus_id, vendorname, pid);
#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
}

Expand Down
1 change: 1 addition & 0 deletions x11/x11.cu
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ extern "C" int scanhash_x11(int thr_id, uint32_t *pdata,
return res;
} else {
applog(LOG_WARNING, "GPU #%d: result for %08x does not validate on CPU!", device_map[thr_id], foundNonce);
pdata[19] = foundNonce + 1;
}
}

Expand Down

0 comments on commit 7981e83

Please sign in to comment.