Reuse memory mappings
This commit is contained in:
parent
b7d22ed9ac
commit
20e2683110
@ -92,6 +92,8 @@ struct card_info {
|
|||||||
int product_id; /* EVGA internal product ID, as reported by the iCX3 controller */
|
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 */
|
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 *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 {
|
struct gpu_pci_info {
|
||||||
|
91
gddr6.c
91
gddr6.c
@ -36,70 +36,69 @@ void init_gddr6(struct card_info *card)
|
|||||||
card->bar0 = (pci_dev->base_addr[0] & 0xFFFFFFFF);
|
card->bar0 = (pci_dev->base_addr[0] & 0xFFFFFFFF);
|
||||||
|
|
||||||
pci_cleanup(pacc);
|
pci_cleanup(pacc);
|
||||||
}
|
|
||||||
|
|
||||||
float get_vram_temp(struct card_info *card)
|
|
||||||
{
|
|
||||||
int fd;
|
|
||||||
float temp = 0.0;
|
|
||||||
|
|
||||||
|
/* Open our memory mappings */
|
||||||
|
card->vram_addr = NULL;
|
||||||
|
card->hotspot_addr = NULL;
|
||||||
|
|
||||||
|
int fd;
|
||||||
if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
|
if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
|
||||||
{
|
{
|
||||||
printf("Can't read memory. If you are root, enable kernel parameter iomem=relaxed\n");
|
printf("Can't read memory for VRAM and Hotspot temperatures. If you are root, enable kernel parameter iomem=relaxed\n");
|
||||||
return 0;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int phys_addr, base_offset;
|
||||||
|
void *map_base;
|
||||||
|
|
||||||
for (int i = 0; i < sizeof(device_offset_info) / sizeof(struct device_offset); i++) {
|
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){
|
if (card->pci_device_id == device_offset_info[i].device_id){
|
||||||
unsigned int phys_addr = (card->bar0 + device_offset_info[i].vram_offset);
|
/* Map for VRAM */
|
||||||
unsigned int base_offset = phys_addr & ~(PG_SZ-1);
|
phys_addr = (card->bar0 + device_offset_info[i].vram_offset);
|
||||||
void *map_base = mmap(0, PG_SZ, PROT_READ, MAP_SHARED, fd, base_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)
|
if(map_base == (void *) -1)
|
||||||
{
|
printf("Can't map memory for VRAM temperature. If you are root, enable kernel parameter iomem=relaxed\n");
|
||||||
if (fd != -1)
|
else
|
||||||
close(fd);
|
card->vram_addr = (void *) map_base + (phys_addr - base_offset);
|
||||||
printf("Can't read memory for VRAM temperature. If you are root, enable kernel parameter iomem=relaxed\n");
|
|
||||||
}
|
|
||||||
void *virt_addr = (char *) map_base + (phys_addr - base_offset);
|
/* Map for hotspot */
|
||||||
int read_result = *((unsigned int *) virt_addr);
|
phys_addr = (card->bar0 + device_offset_info[i].hotspot_offset);
|
||||||
temp = ((read_result & 0x00000fff) / 0x20);
|
base_offset = phys_addr & ~(PG_SZ-1);
|
||||||
munmap(map_base, PG_SZ);
|
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);
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
float get_vram_temp(struct card_info *card)
|
||||||
|
{
|
||||||
|
float temp = 0.0;
|
||||||
|
|
||||||
|
if(card->vram_addr == NULL)
|
||||||
|
return 0.0;
|
||||||
|
|
||||||
|
int read_result = *((unsigned int *) card->vram_addr);
|
||||||
|
temp = ((read_result & 0x00000fff) / 0x20);
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
float get_hotspot_temp(struct card_info *card)
|
float get_hotspot_temp(struct card_info *card)
|
||||||
{
|
{
|
||||||
int fd;
|
|
||||||
float temp = 0.0;
|
float temp = 0.0;
|
||||||
|
|
||||||
if ((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
|
if(card->hotspot_addr == NULL)
|
||||||
{
|
return 0.0;
|
||||||
printf("Can't read memory. If you are root, enable kernel parameter iomem=relaxed\n");
|
|
||||||
return 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 phys_addr = (card->bar0 + device_offset_info[i].hotspot_offset);
|
|
||||||
unsigned int base_offset = phys_addr & ~(PG_SZ-1);
|
|
||||||
void *map_base = mmap(0, PG_SZ, PROT_READ, MAP_SHARED, fd, base_offset);
|
|
||||||
if(map_base == (void *) -1)
|
|
||||||
{
|
|
||||||
if (fd != -1)
|
|
||||||
close(fd);
|
|
||||||
printf("Can't read memory for hotspot. If you are root, enable kernel parameter iomem=relaxed\n");
|
|
||||||
}
|
|
||||||
void *virt_addr = (char *) map_base + (phys_addr - base_offset);
|
|
||||||
int read_result = *((unsigned int *) virt_addr);
|
|
||||||
temp = (read_result >> 8) & 0xff;
|
|
||||||
munmap(map_base, PG_SZ);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fd);
|
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user