Only read Nvidia i2c devices

This commit is contained in:
moosecrap 2025-02-01 00:29:48 -08:00
parent 73f7038eaa
commit afdddabc0c
2 changed files with 16 additions and 4 deletions

View File

@ -13,6 +13,7 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus)
char i2c_devices_path[NAME_MAX];
char device_path[NAME_MAX];
char dev_file[NAME_MAX];
char *pci_addr;
FILE *test_fd;
DIR *dir;
@ -39,6 +40,11 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus)
strcpy(device_path, i2c_devices_path);
strcat(device_path, ent->d_name);
/* Only check Nvidia devices */
pci_addr = read_nvidia_pci_address(device_path);
if (pci_addr == NULL)
continue;
/* Read the PCI info for the underlying device */
pci_vendor = read_pci_id(device_path, "/device/vendor");
pci_device = read_pci_id(device_path, "/device/device");
@ -59,7 +65,7 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus)
if (check_for_icx3(dev_file)) {
/* Write our card info into the provided struct array */
infos[num_gpus].card_name = evga_pci_ids[i].card_name;
infos[num_gpus].pci_id = read_nvidia_pci_address(device_path);
infos[num_gpus].pci_id = pci_addr;
infos[num_gpus].i2c_dev_path = calloc(strlen(dev_file) + 1, sizeof(char));
strcpy(infos[num_gpus].i2c_dev_path, dev_file);
num_gpus++;
@ -111,12 +117,18 @@ char *read_nvidia_pci_address(char *device_path)
FILE *fp = fopen(file_path, "r");
if (fp == NULL)
if (fp == NULL) {
free(ret);
return NULL;
}
fscanf(fp, "NVIDIA i2c adapter %*u at %16s", ret);
fclose(fp);
if (strlen(ret) == 0) {
free(ret);
return NULL;
}
return ret;
}

View File

@ -84,7 +84,7 @@ struct card_info {
char *card_name;
char *pci_id;
char *i2c_dev_path;
int fd;
int i2c_fd;
};
struct gpu_pci_info {