Pull out card functions from evga-card

This commit is contained in:
2026-09-29 01:28:05 -07:00
parent 30bf43627d
commit cecc34f0a6
5 changed files with 85 additions and 78 deletions
+3 -54
View File
@@ -81,9 +81,9 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus, int i2c_bus)
/* 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 = pci_addr;
infos[num_gpus].pci_dev_path = strdup(pci_path);
infos[num_gpus].pci_device_id = pci_device;
infos[num_gpus].i2c_dev_path = calloc(strlen(dev_file) + 1, sizeof(char));
strcpy(infos[num_gpus].i2c_dev_path, dev_file);
infos[num_gpus].i2c_dev_path = strdup(dev_file);
num_gpus++;
break;
}
@@ -96,55 +96,4 @@ int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus, int i2c_bus)
}
return num_gpus;
}
/* Read a 16-bit unsigned int from a pci id file */
unsigned short read_pci_id(char *device_path, char *field)
{
char buf[16];
char file_path[PATH_MAX];
strcpy(file_path, device_path);
strcat(file_path, field);
FILE *fp = fopen(file_path, "r");
if (fp == NULL)
return 0;
if (fgets(buf, sizeof(buf), fp) == NULL) {
fclose(fp);
return 0;
}
fclose(fp);
return (unsigned short)strtoul(buf, NULL, 16);
}
char *read_nvidia_pci_address(char *device_path)
{
char file_path[PATH_MAX];
char *ret = calloc(16 + 1, sizeof(char)); /* assuming pci ids could look as large as 00000000:0C:00.0 */
strcpy(file_path, device_path);
strcat(file_path, "/name");
FILE *fp = fopen(file_path, "r");
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;
}
}