Fill in PCI information for all i2c interfaces on Linux
This commit is contained in:
parent
1bd3c2ce49
commit
973dce9d80
1 changed files with 57 additions and 71 deletions
|
|
@ -78,73 +78,61 @@ void i2c_smbus_linux_detect(std::vector<i2c_smbus_interface*> &busses)
|
|||
|
||||
close(test_fd);
|
||||
|
||||
// For now, only get PCI information from nVidia GPUs
|
||||
// PCI IDs are not currently obtained from the Nouveau driver
|
||||
// and GPUs using PCI IDs for detection will not work with it.
|
||||
if (sscanf(device_string, "NVIDIA i2c adapter %hu at", &port_id) == 1)
|
||||
// Get PCI Device
|
||||
snprintf(path, sizeof(path), "%s%s%s", driver_path, ent->d_name, "/device/device");
|
||||
test_fd = open(path, O_RDONLY);
|
||||
if (test_fd < 0)
|
||||
{
|
||||
info = true;
|
||||
|
||||
// Get PCI Device
|
||||
snprintf(path, sizeof(path), "%s%s%s", driver_path, ent->d_name, "/device/device");
|
||||
test_fd = open(path, O_RDONLY);
|
||||
if (test_fd < 0)
|
||||
{
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
memset(buff, 0x00, sizeof(buff));
|
||||
read(test_fd, buff, sizeof(buff));
|
||||
buff[strlen(buff) - 1] = 0x00;
|
||||
pci_device = strtoul(buff, NULL, 16);
|
||||
close(test_fd);
|
||||
|
||||
// Get PCI Vendor
|
||||
snprintf(path, sizeof(path), "%s%s%s", driver_path, ent->d_name, "/device/vendor");
|
||||
test_fd = open(path, O_RDONLY);
|
||||
if (test_fd < 0)
|
||||
{
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
memset(buff, 0x00, sizeof(buff));
|
||||
read(test_fd, buff, sizeof(buff));
|
||||
buff[strlen(buff) - 1] = 0x00;
|
||||
pci_vendor = strtoul(buff, NULL, 16);
|
||||
close(test_fd);
|
||||
|
||||
// Get PCI Subsystem Device
|
||||
snprintf(path, sizeof(path), "%s%s%s", driver_path, ent->d_name, "/device/subsystem_device");
|
||||
test_fd = open(path, O_RDONLY);
|
||||
if (test_fd < 0)
|
||||
{
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
memset(buff, 0x00, sizeof(buff));
|
||||
read(test_fd, buff, sizeof(buff));
|
||||
buff[strlen(buff) - 1] = 0x00;
|
||||
pci_subsystem_device = strtoul(buff, NULL, 16);
|
||||
close(test_fd);
|
||||
|
||||
// Get PCI Subsystem Vendor
|
||||
snprintf(path, sizeof(path), "%s%s%s", driver_path, ent->d_name, "/device/subsystem_vendor");
|
||||
test_fd = open(path, O_RDONLY);
|
||||
if (test_fd < 0)
|
||||
{
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
memset(buff, 0x00, sizeof(buff));
|
||||
read(test_fd, buff, sizeof(buff));
|
||||
buff[strlen(buff) - 1] = 0x00;
|
||||
pci_subsystem_vendor = strtoul(buff, NULL, 16);
|
||||
close(test_fd);
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
else
|
||||
memset(buff, 0x00, sizeof(buff));
|
||||
read(test_fd, buff, sizeof(buff));
|
||||
buff[strlen(buff) - 1] = 0x00;
|
||||
pci_device = strtoul(buff, NULL, 16);
|
||||
close(test_fd);
|
||||
|
||||
// Get PCI Vendor
|
||||
snprintf(path, sizeof(path), "%s%s%s", driver_path, ent->d_name, "/device/vendor");
|
||||
test_fd = open(path, O_RDONLY);
|
||||
if (test_fd < 0)
|
||||
{
|
||||
info = false;
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
memset(buff, 0x00, sizeof(buff));
|
||||
read(test_fd, buff, sizeof(buff));
|
||||
buff[strlen(buff) - 1] = 0x00;
|
||||
pci_vendor = strtoul(buff, NULL, 16);
|
||||
close(test_fd);
|
||||
|
||||
// Get PCI Subsystem Device
|
||||
snprintf(path, sizeof(path), "%s%s%s", driver_path, ent->d_name, "/device/subsystem_device");
|
||||
test_fd = open(path, O_RDONLY);
|
||||
if (test_fd < 0)
|
||||
{
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
memset(buff, 0x00, sizeof(buff));
|
||||
read(test_fd, buff, sizeof(buff));
|
||||
buff[strlen(buff) - 1] = 0x00;
|
||||
pci_subsystem_device = strtoul(buff, NULL, 16);
|
||||
close(test_fd);
|
||||
|
||||
// Get PCI Subsystem Vendor
|
||||
snprintf(path, sizeof(path), "%s%s%s", driver_path, ent->d_name, "/device/subsystem_vendor");
|
||||
test_fd = open(path, O_RDONLY);
|
||||
if (test_fd < 0)
|
||||
{
|
||||
ent = readdir(dir);
|
||||
continue;
|
||||
}
|
||||
memset(buff, 0x00, sizeof(buff));
|
||||
read(test_fd, buff, sizeof(buff));
|
||||
buff[strlen(buff) - 1] = 0x00;
|
||||
pci_subsystem_vendor = strtoul(buff, NULL, 16);
|
||||
close(test_fd);
|
||||
|
||||
strcpy(device_string, "/dev/");
|
||||
strcat(device_string, ent->d_name);
|
||||
|
|
@ -158,14 +146,12 @@ void i2c_smbus_linux_detect(std::vector<i2c_smbus_interface*> &busses)
|
|||
|
||||
bus = new i2c_smbus_linux();
|
||||
strcpy(bus->device_name, device_string);
|
||||
bus->handle = test_fd;
|
||||
if (info) {
|
||||
bus->pci_device = pci_device;
|
||||
bus->pci_vendor = pci_vendor;
|
||||
bus->pci_subsystem_device = pci_subsystem_device;
|
||||
bus->pci_subsystem_vendor = pci_subsystem_vendor;
|
||||
bus->port_id = port_id;
|
||||
}
|
||||
bus->handle = test_fd;
|
||||
bus->pci_device = pci_device;
|
||||
bus->pci_vendor = pci_vendor;
|
||||
bus->pci_subsystem_device = pci_subsystem_device;
|
||||
bus->pci_subsystem_vendor = pci_subsystem_vendor;
|
||||
bus->port_id = port_id;
|
||||
busses.push_back(bus);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue