#ifndef EVGA_CARD_H
#define EVGA_CARD_H

#define NVIDIA_VEN                                      0x10DE

#define NVIDIA_RTX3060_DEV                              0x2503
#define NVIDIA_RTX3060_GA104_DEV                        0x2487
#define NVIDIA_RTX3060_GA106_DEV                        0x2503
#define NVIDIA_RTX3060_LHR_DEV                          0x2504
#define NVIDIA_RTX3060TI_DEV                            0x2486
#define NVIDIA_RTX3060TI_GDDR6X_DEV                     0x24C9
#define NVIDIA_RTX3060TI_LHR_DEV                        0x2489
#define NVIDIA_RTX3060TI_V1_LHR_DEV                     0x2414
#define NVIDIA_RTX3070_DEV                              0x2484
#define NVIDIA_RTX3070_LHR_DEV                          0x2488
#define NVIDIA_RTX3070TI_DEV                            0x2482
#define NVIDIA_RTX3070TI_GA102_DEV                      0x2207
#define NVIDIA_RTX3080_DEV                              0x2206
#define NVIDIA_RTX3080_LHR_DEV                          0x2216
#define NVIDIA_RTX3080_12G_LHR_DEV                      0x220A
#define NVIDIA_RTX3080TI_DEV                            0x2208
#define NVIDIA_RTX3090_DEV                              0x2204
#define NVIDIA_RTX3090TI_DEV                            0x2203

#define EVGA_SUB_VEN                                    0x3842

#define EVGA_RTX3060TI_FTW3_GAMING_SUB_DEV              0x3665
#define EVGA_RTX3060TI_FTW3_ULTRA_SUB_DEV               0x3667
#define EVGA_RTX3060TI_FTW3_ULTRA_KL_SUB_DEV            0x4667
#define EVGA_RTX3070_XC3_BLACK_SUB_DEV                  0x3751
#define EVGA_RTX3070_XC3_GAMING_SUB_DEV                 0x3753
#define EVGA_RTX3070_XC3_ULTRA_SUB_DEV                  0x3755
#define EVGA_RTX3070_XC3_ULTRA_LHR_SUB_DEV              0x4755
#define EVGA_RTX3070_XC3_ULTRA_GAMING_LHR_SUB_DEV       0x4455
#define EVGA_RTX3070_FTW3_ULTRA_SUB_DEV                 0x3767
#define EVGA_RTX3070_FTW3_ULTRA_LHR_SUB_DEV             0x4767
#define EVGA_RTX3070TI_XC3_GAMING_SUB_DEV               0x3783
#define EVGA_RTX3070TI_XC3_ULTRA_SUB_DEV                0x3785
#define EVGA_RTX3070TI_XC3_ULTRA_V2_SUB_DEV             0x3485
#define EVGA_RTX3070TI_FTW3_ULTRA_SUB_DEV               0x3797
#define EVGA_RTX3070TI_FTW3_ULTRA_V2_SUB_DEV            0x3497
#define EVGA_RTX3080_XC3_BLACK_SUB_DEV                  0x3881
#define EVGA_RTX3080_XC3_BLACK_LHR_SUB_DEV              0x4881
#define EVGA_RTX3080_XC3_GAMING_SUB_DEV                 0x3883
#define EVGA_RTX3080_XC3_GAMING_LHR_SUB_DEV             0x4883
#define EVGA_RTX3080_XC3_ULTRA_SUB_DEV                  0x3885
#define EVGA_RTX3080_XC3_ULTRA_LHR_SUB_DEV              0x4885
#define EVGA_RTX3080_XC3_ULTRA_HYBRID_SUB_DEV           0x3888
#define EVGA_RTX3080_XC3_ULTRA_HYBRID_LHR_SUB_DEV       0x4888
#define EVGA_RTX3080_XC3_ULTRA_HC_SUB_DEV               0x3889
#define EVGA_RTX3080_FTW3_GAMING_SUB_DEV                0x3895
#define EVGA_RTX3080_FTW3_ULTRA_SUB_DEV                 0x3897
#define EVGA_RTX3080_FTW3_ULTRA_LHR_SUB_DEV             0x4897
#define EVGA_RTX3080_FTW3_ULTRA_LHR_V2_SUB_DEV          0x4297
#define EVGA_RTX3080_FTW3_ULTRA_HYBRID_SUB_DEV          0x3898
#define EVGA_RTX3080_FTW3_ULTRA_HYBRID_LHR_SUB_DEV      0x4898
#define EVGA_RTX3080_FTW3_ULTRA_HYBRID_GAMING_SUB_DEV   0x4878
#define EVGA_RTX3080_FTW3_ULTRA_HC_SUB_DEV              0x3899
#define EVGA_RTX3080_12G_XC3_ULTRA_SUB_DEV              0x4865
#define EVGA_RTX3080_12G_FTW3_ULTRA_SUB_DEV             0x4877
#define EVGA_RTX3080_12G_FTW3_ULTRA_HC_SUB_DEV          0x4879
#define EVGA_RTX3080TI_XC3_GAMING_SUB_DEV               0x3953
#define EVGA_RTX3080TI_XC3_ULTRA_GAMING_SUB_DEV         0x3955
#define EVGA_RTX3080TI_XC3_GAMING_HYBRID_SUB_DEV        0x3958
#define EVGA_RTX3080TI_XC3_GAMING_HC_SUB_DEV            0x3959
#define EVGA_RTX3080TI_FTW3_ULTRA_SUB_DEV               0x3967
#define EVGA_RTX3080TI_FTW3_ULTRA_HYBRID_SUB_DEV        0x3968
#define EVGA_RTX3080TI_FTW3_ULTRA_HC_SUB_DEV            0x3969
#define EVGA_RTX3090_XC3_BLACK_SUB_DEV                  0x3971
#define EVGA_RTX3090_XC3_GAMING_SUB_DEV                 0x3973
#define EVGA_RTX3090_XC3_ULTRA_SUB_DEV                  0x3975
#define EVGA_RTX3090_XC3_ULTRA_HYBRID_SUB_DEV           0x3978
#define EVGA_RTX3090_XC3_ULTRA_HC_SUB_DEV               0x3979
#define EVGA_RTX3090_FTW3_GAMING_SUB_DEV                0x3985
#define EVGA_RTX3090_FTW3_ULTRA_SUB_DEV                 0x3987
#define EVGA_RTX3090_FTW3_ULTRA_V2_SUB_DEV              0x3982
#define EVGA_RTX3090_FTW3_ULTRA_V3_SUB_DEV              0x3387
#define EVGA_RTX3090_FTW3_ULTRA_HYBRID_SUB_DEV          0x3988
#define EVGA_RTX3090_FTW3_ULTRA_HC_SUB_DEV              0x3989
#define EVGA_RTX3090_KINGPIN_HYBRID_SUB_DEV             0x3998
#define EVGA_RTX3090_KINGPIN_HC_SUB_DEV                 0x3999
#define EVGA_RTX3090TI_FTW3_BLACK_SUB_DEV               0x4981
#define EVGA_RTX3090TI_FTW3_GAMING_SUB_DEV              0x4983
#define EVGA_RTX3090TI_FTW3_ULTRA_GAMING_SUB_DEV        0x4985

struct card_info {
	char *card_name;					/* The 'nice' name of the card */
	char *pci_id;						/* PCI bus address in domain:bus:device.function format. May be shortened (e.g. c:00.0) */
	unsigned short pci_device_id;		/* The device ID of the card, i.e. corresponds to the NVIDIA model number */
	char *i2c_dev_path;					/* Path to the i2c device file */
	int i2c_fd;							/* File descriptor for the i2c device file, for re-use */
	int product_id;						/* EVGA internal product ID, as reported by the iCX3 controller */
	unsigned int bar0;					/* Address of the card's PCI base address register */
	void *nvml_device;					/* Pointer to nvmlDevice_t for use in NVML calls */
	void *vram_addr;					/* Memory mapping for GDDR6 temps */
	void *hotspot_addr;					/* Memory mapping for hotspot temperature */
};

struct gpu_pci_info {
	char *card_name;
	unsigned short vendor_id;
	unsigned short device_id;
	unsigned short subvendor_id;
	unsigned short subdevice_id;
};

static struct gpu_pci_info evga_pci_ids[] =
{
	{"EVGA GeForce RTX 3060 Ti FTW3 Gaming"                , NVIDIA_VEN,   NVIDIA_RTX3060TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3060TI_FTW3_GAMING_SUB_DEV            },
	{"EVGA GeForce RTX 3060 Ti FTW3 Ultra"                 , NVIDIA_VEN,   NVIDIA_RTX3060TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3060TI_FTW3_ULTRA_SUB_DEV             },
	{"EVGA GeForce RTX 3060 Ti FTW3 Ultra LHR"             , NVIDIA_VEN,   NVIDIA_RTX3060TI_LHR_DEV,   EVGA_SUB_VEN,   EVGA_RTX3060TI_FTW3_ULTRA_KL_SUB_DEV          },
	{"EVGA GeForce RTX 3070 Black Gaming"                  , NVIDIA_VEN,   NVIDIA_RTX3070_DEV,         EVGA_SUB_VEN,   EVGA_RTX3070_XC3_BLACK_SUB_DEV                },
	{"EVGA GeForce RTX 3070 XC3 Gaming"                    , NVIDIA_VEN,   NVIDIA_RTX3070_DEV,         EVGA_SUB_VEN,   EVGA_RTX3070_XC3_GAMING_SUB_DEV               },
	{"EVGA GeForce RTX 3070 XC3 Ultra"                     , NVIDIA_VEN,   NVIDIA_RTX3070_DEV,         EVGA_SUB_VEN,   EVGA_RTX3070_XC3_ULTRA_SUB_DEV                },
	{"EVGA GeForce RTX 3070 XC3 Ultra LHR"                 , NVIDIA_VEN,   NVIDIA_RTX3070_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3070_XC3_ULTRA_LHR_SUB_DEV            },
	{"EVGA GeForce RTX 3070 XC3 Ultra Gaming"              , NVIDIA_VEN,   NVIDIA_RTX3070_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3070_XC3_ULTRA_GAMING_LHR_SUB_DEV     },
	{"EVGA GeForce RTX 3070 FTW3 Ultra"                    , NVIDIA_VEN,   NVIDIA_RTX3070_DEV,         EVGA_SUB_VEN,   EVGA_RTX3070_FTW3_ULTRA_SUB_DEV               },
	{"EVGA GeForce RTX 3070 FTW3 Ultra LHR"                , NVIDIA_VEN,   NVIDIA_RTX3070_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3070_FTW3_ULTRA_LHR_SUB_DEV           },
	{"EVGA GeForce RTX 3070 Ti XC3 Gaming"                 , NVIDIA_VEN,   NVIDIA_RTX3070TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3070TI_XC3_GAMING_SUB_DEV             },
	{"EVGA GeForce RTX 3070 Ti XC3 Ultra"                  , NVIDIA_VEN,   NVIDIA_RTX3070TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3070TI_XC3_ULTRA_SUB_DEV              },
	{"EVGA GeForce RTX 3070 Ti XC3 Ultra v2"               , NVIDIA_VEN,   NVIDIA_RTX3070TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3070TI_XC3_ULTRA_V2_SUB_DEV           },
	{"EVGA GeForce RTX 3070 Ti FTW3 Ultra"                 , NVIDIA_VEN,   NVIDIA_RTX3070TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3070TI_FTW3_ULTRA_SUB_DEV             },
	{"EVGA GeForce RTX 3070 Ti FTW3 Ultra v2"              , NVIDIA_VEN,   NVIDIA_RTX3070TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3070TI_FTW3_ULTRA_V2_SUB_DEV          },
	{"EVGA GeForce RTX 3080 XC3 Black"                     , NVIDIA_VEN,   NVIDIA_RTX3080_DEV,         EVGA_SUB_VEN,   EVGA_RTX3080_XC3_BLACK_SUB_DEV                },
	{"EVGA GeForce RTX 3080 XC3 Black LHR"                 , NVIDIA_VEN,   NVIDIA_RTX3080_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3080_XC3_BLACK_LHR_SUB_DEV            },
	{"EVGA GeForce RTX 3080 XC3 Gaming"                    , NVIDIA_VEN,   NVIDIA_RTX3080_DEV,         EVGA_SUB_VEN,   EVGA_RTX3080_XC3_GAMING_SUB_DEV               },
	{"EVGA GeForce RTX 3080 XC3 Gaming LHR"                , NVIDIA_VEN,   NVIDIA_RTX3080_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3080_XC3_GAMING_LHR_SUB_DEV           },
	{"EVGA GeForce RTX 3080 XC3 Ultra"                     , NVIDIA_VEN,   NVIDIA_RTX3080_DEV,         EVGA_SUB_VEN,   EVGA_RTX3080_XC3_ULTRA_SUB_DEV                },
	{"EVGA GeForce RTX 3080 XC3 Ultra LHR"                 , NVIDIA_VEN,   NVIDIA_RTX3080_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3080_XC3_ULTRA_LHR_SUB_DEV            },
	{"EVGA GeForce RTX 3080 XC3 Ultra Hybrid"              , NVIDIA_VEN,   NVIDIA_RTX3080_DEV,         EVGA_SUB_VEN,   EVGA_RTX3080_XC3_ULTRA_HYBRID_SUB_DEV         },
	{"EVGA GeForce RTX 3080 XC3 Ultra Hybrid LHR"          , NVIDIA_VEN,   NVIDIA_RTX3080_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3080_XC3_ULTRA_HYBRID_LHR_SUB_DEV     },
	{"EVGA GeForce RTX 3080 XC3 Ultra Hydro Copper"        , NVIDIA_VEN,   NVIDIA_RTX3080_DEV,         EVGA_SUB_VEN,   EVGA_RTX3080_XC3_ULTRA_HC_SUB_DEV             },
	{"EVGA GeForce RTX 3080 FTW3 Gaming"                   , NVIDIA_VEN,   NVIDIA_RTX3080_DEV,         EVGA_SUB_VEN,   EVGA_RTX3080_FTW3_GAMING_SUB_DEV              },
	{"EVGA GeForce RTX 3080 FTW3 Ultra"                    , NVIDIA_VEN,   NVIDIA_RTX3080_DEV,         EVGA_SUB_VEN,   EVGA_RTX3080_FTW3_ULTRA_SUB_DEV               },
	{"EVGA GeForce RTX 3080 FTW3 Ultra v2 LHR"             , NVIDIA_VEN,   NVIDIA_RTX3080_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3080_FTW3_ULTRA_LHR_V2_SUB_DEV        },
	{"EVGA GeForce RTX 3080 FTW3 Ultra LHR"                , NVIDIA_VEN,   NVIDIA_RTX3080_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3080_FTW3_ULTRA_LHR_SUB_DEV           },
	{"EVGA GeForce RTX 3080 FTW3 Ultra Hybrid"             , NVIDIA_VEN,   NVIDIA_RTX3080_DEV,         EVGA_SUB_VEN,   EVGA_RTX3080_FTW3_ULTRA_HYBRID_SUB_DEV        },
	{"EVGA GeForce RTX 3080 FTW3 Ultra Hybrid LHR"         , NVIDIA_VEN,   NVIDIA_RTX3080_LHR_DEV,     EVGA_SUB_VEN,   EVGA_RTX3080_FTW3_ULTRA_HYBRID_LHR_SUB_DEV    },
	{"EVGA GeForce RTX 3080 FTW3 Ultra Hybrid Gaming LHR"  , NVIDIA_VEN,   NVIDIA_RTX3080_12G_LHR_DEV, EVGA_SUB_VEN,   EVGA_RTX3080_FTW3_ULTRA_HYBRID_GAMING_SUB_DEV },
	{"EVGA GeForce RTX 3080 FTW3 Ultra Hydro Copper"       , NVIDIA_VEN,   NVIDIA_RTX3080_DEV,         EVGA_SUB_VEN,   EVGA_RTX3080_FTW3_ULTRA_HC_SUB_DEV            },
	{"EVGA GeForce RTX 3080 XC3 Ultra 12G"                 , NVIDIA_VEN,   NVIDIA_RTX3080_12G_LHR_DEV, EVGA_SUB_VEN,   EVGA_RTX3080_12G_XC3_ULTRA_SUB_DEV            },
	{"EVGA GeForce RTX 3080 FTW3 Ultra 12GB"               , NVIDIA_VEN,   NVIDIA_RTX3080_12G_LHR_DEV, EVGA_SUB_VEN,   EVGA_RTX3080_12G_FTW3_ULTRA_SUB_DEV           },
	{"EVGA GeForce RTX 3080 FTW3 Ultra Hydro Copper 12G"   , NVIDIA_VEN,   NVIDIA_RTX3080_12G_LHR_DEV, EVGA_SUB_VEN,   EVGA_RTX3080_12G_FTW3_ULTRA_HC_SUB_DEV        },
	{"EVGA GeForce RTX 3080 Ti XC3 Gaming"                 , NVIDIA_VEN,   NVIDIA_RTX3080TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3080TI_XC3_GAMING_SUB_DEV             },
	{"EVGA GeForce RTX 3080 Ti XC3 Ultra Gaming"           , NVIDIA_VEN,   NVIDIA_RTX3080TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3080TI_XC3_ULTRA_GAMING_SUB_DEV       },
	{"EVGA GeForce RTX 3080 Ti XC3 Gaming Hybrid"          , NVIDIA_VEN,   NVIDIA_RTX3080TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3080TI_XC3_GAMING_HYBRID_SUB_DEV      },
	{"EVGA GeForce RTX 3080 Ti XC3 Gaming Hydro Copper"    , NVIDIA_VEN,   NVIDIA_RTX3080TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3080TI_XC3_GAMING_HC_SUB_DEV          },
	{"EVGA GeForce RTX 3080 Ti FTW3 Ultra"                 , NVIDIA_VEN,   NVIDIA_RTX3080TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3080TI_FTW3_ULTRA_SUB_DEV             },
	{"EVGA GeForce RTX 3080 Ti FTW3 Ultra Hybrid"          , NVIDIA_VEN,   NVIDIA_RTX3080TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3080TI_FTW3_ULTRA_HYBRID_SUB_DEV      },
	{"EVGA GeForce RTX 3080 Ti FTW3 Ultra Hydro Copper"    , NVIDIA_VEN,   NVIDIA_RTX3080TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3080TI_FTW3_ULTRA_HC_SUB_DEV          },
	{"EVGA GeForce RTX 3090 XC3 Black"                     , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_XC3_BLACK_SUB_DEV                },
	{"EVGA GeForce RTX 3090 XC3 Gaming"                    , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_XC3_GAMING_SUB_DEV               },
	{"EVGA GeForce RTX 3090 XC3 Ultra"                     , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_XC3_ULTRA_SUB_DEV                },
	{"EVGA GeForce RTX 3090 XC3 Ultra Hybrid"              , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_XC3_ULTRA_HYBRID_SUB_DEV         },
	{"EVGA GeForce RTX 3090 XC3 Ultra Hydro Copper"        , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_XC3_ULTRA_HC_SUB_DEV             },
	{"EVGA GeForce RTX 3090 FTW3 Ultra"                    , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_FTW3_ULTRA_SUB_DEV               },
	{"EVGA GeForce RTX 3090 FTW3 Ultra v2"                 , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_FTW3_ULTRA_V2_SUB_DEV            },
	{"EVGA GeForce RTX 3090 FTW3 Ultra v3"                 , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_FTW3_ULTRA_V3_SUB_DEV            },
	{"EVGA GeForce RTX 3090 FTW3 Ultra Hybrid"             , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_FTW3_ULTRA_HYBRID_SUB_DEV        },
	{"EVGA GeForce RTX 3090 FTW3 Ultra Hydro Copper"       , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_FTW3_ULTRA_HC_SUB_DEV            },
	{"EVGA GeForce RTX 3090 K|NGP|N Hybrid"                , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_KINGPIN_HYBRID_SUB_DEV           },
	{"EVGA GeForce RTX 3090 K|NGP|N Hydro Copper"          , NVIDIA_VEN,   NVIDIA_RTX3090_DEV,         EVGA_SUB_VEN,   EVGA_RTX3090_KINGPIN_HC_SUB_DEV               },
	{"EVGA GeForce RTX 3090 Ti FTW3 Black Gaming"          , NVIDIA_VEN,   NVIDIA_RTX3090TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3090TI_FTW3_BLACK_SUB_DEV             },
	{"EVGA GeForce RTX 3090 Ti FTW3 Gaming"                , NVIDIA_VEN,   NVIDIA_RTX3090TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3090TI_FTW3_GAMING_SUB_DEV            },
	{"EVGA GeForce RTX 3090 Ti FTW3 Ultra Gaming"          , NVIDIA_VEN,   NVIDIA_RTX3090TI_DEV,       EVGA_SUB_VEN,   EVGA_RTX3090TI_FTW3_ULTRA_GAMING_SUB_DEV      }
};

int find_evga_gpu_i2cs(struct card_info *infos, int max_gpus, int i2c_bus);
unsigned short read_pci_id(char *device_path, char *field);
char *read_nvidia_pci_address(char *device_path);

#endif