Blackwell die, system, and VRAM temps.
Code reorganization to better support non-iCX cards.
This commit is contained in:
@@ -1,104 +1,48 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <pci/pci.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define PG_SZ sysconf(_SC_PAGE_SIZE)
|
||||
|
||||
#include "gddr6.h"
|
||||
|
||||
void init_gddr6(struct card_info *card)
|
||||
static struct device_offset device_offset_info[] =
|
||||
{
|
||||
/* Parse the address of the card to get the PCI info */
|
||||
char pci_address[] = "00000000:00:00.0";
|
||||
int len = strlen(card->pci_id);
|
||||
strcpy(&pci_address[sizeof(pci_address) - len - 1], card->pci_id);
|
||||
|
||||
int domain = 0;
|
||||
int bus = 0;
|
||||
int dev = 0;
|
||||
int func = 0;
|
||||
|
||||
sscanf(pci_address, "%x:%x:%x.%x", &domain, &bus, &dev, &func);
|
||||
|
||||
struct pci_access *pacc = NULL;
|
||||
struct pci_dev *pci_dev = NULL;
|
||||
|
||||
pacc = pci_alloc();
|
||||
pci_init(pacc);
|
||||
|
||||
pci_dev = pci_get_dev(pacc, domain, bus, dev, func);
|
||||
|
||||
pci_fill_info(pci_dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);
|
||||
|
||||
card->bar0 = (pci_dev->base_addr[0] & 0xFFFFFFFF);
|
||||
|
||||
pci_cleanup(pacc);
|
||||
|
||||
/* Open our memory mappings */
|
||||
card->vram_addr = NULL;
|
||||
card->hotspot_addr = NULL;
|
||||
|
||||
int fd;
|
||||
if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
|
||||
{
|
||||
printf("Can't read memory for VRAM and Hotspot temperatures. If you are root, enable kernel parameter iomem=relaxed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int phys_addr, base_offset;
|
||||
void *map_base;
|
||||
|
||||
for (int i = 0; i < sizeof(device_offset_info) / sizeof(struct device_offset); i++) {
|
||||
if (card->pci_device_id == device_offset_info[i].device_id){
|
||||
/* Map for VRAM */
|
||||
phys_addr = (card->bar0 + device_offset_info[i].vram_offset);
|
||||
base_offset = phys_addr & ~(PG_SZ-1);
|
||||
map_base = mmap(0, PG_SZ, PROT_READ, MAP_SHARED, fd, base_offset);
|
||||
if(map_base == (void *) -1)
|
||||
printf("Can't map memory for VRAM temperature. If you are root, enable kernel parameter iomem=relaxed\n");
|
||||
else
|
||||
card->vram_addr = (void *) map_base + (phys_addr - base_offset);
|
||||
|
||||
|
||||
/* Map for hotspot */
|
||||
phys_addr = (card->bar0 + device_offset_info[i].hotspot_offset);
|
||||
base_offset = phys_addr & ~(PG_SZ-1);
|
||||
map_base = mmap(0, PG_SZ, PROT_READ, MAP_SHARED, fd, base_offset);
|
||||
if(map_base == (void *) -1)
|
||||
printf("Can't map memory for Hotspot temperature. If you are root, enable kernel parameter iomem=relaxed\n");
|
||||
else
|
||||
card->hotspot_addr = (void *) map_base + (phys_addr - base_offset);
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
}
|
||||
{.device_id = NVIDIA_RTX3090TI_DEV, .vram_offset = 0x0000E2A8, .hotspot_offset = 0x0002046c}, /* RTX 3090 Ti */
|
||||
{.device_id = NVIDIA_RTX3090_DEV, .vram_offset = 0x0000E2A8, .hotspot_offset = 0x0002046c}, /* RTX 3090 */
|
||||
{.device_id = NVIDIA_RTX3080TI_DEV, .vram_offset = 0x0000E2A8, .hotspot_offset = 0x0002046c}, /* RTX 3080 Ti */
|
||||
{.device_id = NVIDIA_RTX3080_12G_LHR_DEV, .vram_offset = 0x0000E2A8, .hotspot_offset = 0x0002046c}, /* RTX 3080 12G LHR */
|
||||
{.device_id = NVIDIA_RTX3080_LHR_DEV, .vram_offset = 0x0000E2A8, .hotspot_offset = 0x0002046c}, /* RTX 3080 LHR */
|
||||
{.device_id = NVIDIA_RTX3080_DEV, .vram_offset = 0x0000E2A8, .hotspot_offset = 0x0002046c}, /* RTX 3080 */
|
||||
{.device_id = NVIDIA_RTX3070TI_GA102_DEV, .vram_offset = 0x0000EE50, .hotspot_offset = 0x0002046c}, /* RTX 3070 Ti GA102 TODO:check */
|
||||
{.device_id = NVIDIA_RTX3070TI_DEV, .vram_offset = 0x0000EE50, .hotspot_offset = 0x0002046c}, /* RTX 3070 Ti TODO:check */
|
||||
{.device_id = NVIDIA_RTX3070_LHR_DEV, .vram_offset = 0x0000EE50, .hotspot_offset = 0x0002046c}, /* RTX 3070 LHR */
|
||||
{.device_id = NVIDIA_RTX3070_DEV, .vram_offset = 0x0000EE50, .hotspot_offset = 0x0002046c}, /* RTX 3070 */
|
||||
};
|
||||
|
||||
float get_vram_temp(struct card_info *card)
|
||||
{
|
||||
float temp = 0.0;
|
||||
|
||||
if(card->vram_addr == NULL)
|
||||
if (card->bar0_mmap == NULL)
|
||||
return 0.0;
|
||||
|
||||
int read_result = *((unsigned int *) card->vram_addr);
|
||||
temp = ((read_result & 0x00000fff) / 0x20);
|
||||
for (int i = 0; i < sizeof(device_offset_info) / sizeof(struct device_offset); i++) {
|
||||
if (card->pci_device_id == device_offset_info[i].device_id) {
|
||||
unsigned int read_result = *((unsigned int *)((char *)card->bar0_mmap + device_offset_info[i].vram_offset));
|
||||
return (float)((read_result & 0x00000fff) / 0x20);
|
||||
}
|
||||
}
|
||||
|
||||
return temp;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
float get_hotspot_temp(struct card_info *card)
|
||||
{
|
||||
float temp = 0.0;
|
||||
|
||||
if(card->hotspot_addr == NULL)
|
||||
if (card->bar0_mmap == NULL)
|
||||
return 0.0;
|
||||
|
||||
int read_result = *((unsigned int *) card->hotspot_addr);
|
||||
temp = (read_result >> 8) & 0xff;
|
||||
for (int i = 0; i < sizeof(device_offset_info) / sizeof(struct device_offset); i++) {
|
||||
if (card->pci_device_id == device_offset_info[i].device_id) {
|
||||
unsigned int read_result = *((unsigned int *)((char *)card->bar0_mmap + device_offset_info[i].hotspot_offset));
|
||||
return (float)((read_result >> 8) & 0xff);
|
||||
}
|
||||
}
|
||||
|
||||
return temp;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user