switch from bar0 in tables to using probed bar0 pcie values #1
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
## GDDR6(X) GPU Memory Temperature reader for linux
|
## GDDR6(X) GPU Memory Temperature reader for linux
|
||||||
|
|
||||||
|
Reads GDDR6 VRAM memory temperature from an NVIDIA GPU.
|
||||||
|
These findings are based on reverse engineering of the NVIDIA GPU Linux driver.
|
||||||
|
|
||||||
## Needs:
|
## Needs:
|
||||||
- libpciaccess-dev and libpci-dev
|
- libpciaccess-dev and libpci-dev
|
||||||
|
|||||||
154
gddr6.c
154
gddr6.c
@@ -13,106 +13,100 @@
|
|||||||
|
|
||||||
#define PG_SZ sysconf(_SC_PAGE_SIZE)
|
#define PG_SZ sysconf(_SC_PAGE_SIZE)
|
||||||
#define PRINT_ERROR() \
|
#define PRINT_ERROR() \
|
||||||
do { \
|
do { \
|
||||||
fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
|
fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
|
||||||
__LINE__, __FILE__, errno, strerror(errno)); exit(1); \
|
__LINE__, __FILE__, errno, strerror(errno)); exit(1); \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
|
|
||||||
// variables
|
// variables
|
||||||
int fd;
|
int fd;
|
||||||
void *map_base;
|
void *map_base;
|
||||||
|
|
||||||
|
|
||||||
// device struct
|
// device struct
|
||||||
struct device
|
struct device
|
||||||
{
|
{
|
||||||
uint32_t bar0;
|
uint32_t bar0;
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
uint16_t dev_id;
|
uint16_t dev_id;
|
||||||
const char *vram;
|
const char *vram;
|
||||||
const char *arch;
|
const char *arch;
|
||||||
const char *name;
|
const char *name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// device table
|
// device table
|
||||||
static const struct device dev_table[] =
|
struct device dev_table[] =
|
||||||
{
|
{
|
||||||
{ .bar0 = 0xEC000000, .offset = 0x0000E2A8, .dev_id = 0x2684, .vram = "GDDR6X", .arch = "AD102", .name = "RTX 4090" },
|
{ .offset = 0x0000E2A8, .dev_id = 0x2684, .vram = "GDDR6X", .arch = "AD102", .name = "RTX 4090" },
|
||||||
{ .bar0 = 0xFB000000, .offset = 0x0000E2A8, .dev_id = 0x2204, .vram = "GDDR6X", .arch = "GA102", .name = "RTX 3090" },
|
{ .offset = 0x0000E2A8, .dev_id = 0x2204, .vram = "GDDR6X", .arch = "GA102", .name = "RTX 3090" },
|
||||||
{ .bar0 = 0xFA000000, .offset = 0x0000E2A8, .dev_id = 0x2204, .vram = "GDDR6X", .arch = "GA102", .name = "RTX 3090" },
|
{ .offset = 0x0000EE50, .dev_id = 0x2484, .vram = "GDDR6", .arch = "GA104", .name = "RTX 3070" },
|
||||||
{ .bar0 = 0xFB000000, .offset = 0x0000EE50, .dev_id = 0x2484, .vram = "GDDR6", .arch = "GA104", .name = "RTX 3070" },
|
{ .offset = 0x0000EE50, .dev_id = 0x2488, .vram = "GDDR6", .arch = "GA104", .name = "RTX 3070-LHR" },
|
||||||
{ .bar0 = 0xFB000000, .offset = 0x0000EE50, .dev_id = 0x2488, .vram = "GDDR6", .arch = "GA104", .name = "RTX 3070-LHR" },
|
};
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// prototypes
|
// prototypes
|
||||||
void cleanup(int signal);
|
void cleanup(int signal);
|
||||||
void cleanup_sig_handler(void);
|
void cleanup_sig_handler(void);
|
||||||
struct device *pci_detect_dev(void);
|
struct device *pci_detect_dev(void);
|
||||||
|
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
void cleanup(int signal)
|
void cleanup(int signal)
|
||||||
{
|
{
|
||||||
if (signal == SIGHUP || signal == SIGINT || signal == SIGTERM)
|
if (signal == SIGHUP || signal == SIGINT || signal == SIGTERM)
|
||||||
{
|
{
|
||||||
if (map_base != (void *) -1)
|
if (map_base != (void *) -1)
|
||||||
munmap(map_base, PG_SZ);
|
munmap(map_base, PG_SZ);
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// cleanup signal handler
|
// cleanup signal handler
|
||||||
void cleanup_sig_handler(void)
|
void cleanup_sig_handler(void)
|
||||||
{
|
{
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
sa.sa_handler = &cleanup;
|
sa.sa_handler = &cleanup;
|
||||||
sa.sa_flags = 0;
|
sa.sa_flags = 0;
|
||||||
sigfillset(&sa.sa_mask);
|
sigfillset(&sa.sa_mask);
|
||||||
|
|
||||||
if (sigaction(SIGINT, &sa, NULL) < 0)
|
if (sigaction(SIGINT, &sa, NULL) < 0)
|
||||||
perror("Cannot handle SIGINT");
|
perror("Cannot handle SIGINT");
|
||||||
|
|
||||||
if (sigaction(SIGHUP, &sa, NULL) < 0)
|
if (sigaction(SIGHUP, &sa, NULL) < 0)
|
||||||
perror("Cannot handle SIGHUP");
|
perror("Cannot handle SIGHUP");
|
||||||
|
|
||||||
if (sigaction(SIGTERM, &sa, NULL) < 0)
|
if (sigaction(SIGTERM, &sa, NULL) < 0)
|
||||||
perror("Cannot handle SIGTERM");
|
perror("Cannot handle SIGTERM");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// pci device detection
|
// pci device detection
|
||||||
struct device *pci_detect_dev(void)
|
struct device *pci_detect_dev(void)
|
||||||
{
|
{
|
||||||
struct pci_access *pacc = NULL;
|
struct pci_access *pacc = NULL;
|
||||||
struct pci_dev *pci_dev = NULL;
|
struct pci_dev *pci_dev = NULL;
|
||||||
struct device *device = NULL;
|
struct device *device = NULL;
|
||||||
ssize_t dev_table_size = (sizeof(dev_table)/sizeof(struct device));
|
ssize_t dev_table_size = (sizeof(dev_table)/sizeof(struct device));
|
||||||
|
|
||||||
pacc = pci_alloc();
|
pacc = pci_alloc();
|
||||||
pci_init(pacc);
|
pci_init(pacc);
|
||||||
pci_scan_bus(pacc);
|
pci_scan_bus(pacc);
|
||||||
|
|
||||||
for (pci_dev = pacc->devices; pci_dev; pci_dev = pci_dev->next)
|
for (pci_dev = pacc->devices; pci_dev; pci_dev = pci_dev->next)
|
||||||
{
|
{
|
||||||
pci_fill_info(pci_dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);
|
pci_fill_info(pci_dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < dev_table_size; i++)
|
|
||||||
{
|
|
||||||
if (pci_dev->device_id == dev_table[i].dev_id)
|
|
||||||
{
|
|
||||||
device = (struct device *) &dev_table[i];
|
|
||||||
|
|
||||||
if (pci_dev->base_addr[0] != device->bar0)
|
|
||||||
{
|
|
||||||
device->bar0 = pci_dev->base_addr[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < dev_table_size; i++)
|
||||||
|
{
|
||||||
|
if (pci_dev->device_id == dev_table[i].dev_id)
|
||||||
|
{
|
||||||
|
device = (struct device *) &dev_table[i];
|
||||||
|
device->bar0 = (pci_dev->base_addr[0] & 0xFFFFFFFF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user