gcc flags
This commit is contained in:
2
Makefile
2
Makefile
@@ -1,5 +1,5 @@
|
||||
all:
|
||||
gcc -std=c99 -O3 -Wall -Wextra -o gddr6 gddr6.c -lpci
|
||||
gcc -std=c11 -O3 -Wall -Werror -Wextra -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -Wvla -o gddr6 gddr6.c -lpci
|
||||
clean:
|
||||
rm -f gddr6
|
||||
|
||||
|
||||
32
gddr6.c
32
gddr6.c
@@ -14,6 +14,9 @@
|
||||
__LINE__, __FILE__, errno, strerror(errno)); exit(1); \
|
||||
} while(0)
|
||||
|
||||
// prototypes
|
||||
struct device * pci_detect_dev(void);
|
||||
|
||||
struct device
|
||||
{
|
||||
uint32_t bar0;
|
||||
@@ -32,10 +35,10 @@ static struct device dev_table[] =
|
||||
{ .bar0 = 0xFB000000, .offset = 0x0000EE50, .dev_id = 0x2488, .vram = "GDDR6", .arch = "GA104", .name = "RTX 3070-LHR" },
|
||||
};
|
||||
|
||||
struct device * pci_detect_dev()
|
||||
struct device * pci_detect_dev(void)
|
||||
{
|
||||
struct pci_access *pacc = NULL;
|
||||
struct pci_dev *dev = NULL;
|
||||
struct pci_dev *pci_dev = NULL;
|
||||
struct device *device = NULL;
|
||||
ssize_t dev_table_size = (sizeof(dev_table)/sizeof(struct device));
|
||||
|
||||
@@ -43,19 +46,19 @@ struct device * pci_detect_dev()
|
||||
pci_init(pacc);
|
||||
pci_scan_bus(pacc);
|
||||
|
||||
for (dev = pacc->devices; dev; dev = dev->next)
|
||||
for (pci_dev = pacc->devices; pci_dev; pci_dev = pci_dev->next)
|
||||
{
|
||||
pci_fill_info(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 (dev->device_id == dev_table[i].dev_id)
|
||||
if (pci_dev->device_id == dev_table[i].dev_id)
|
||||
{
|
||||
device = &dev_table[i];
|
||||
|
||||
if (dev->base_addr[0] != device->bar0)
|
||||
if (pci_dev->base_addr[0] != device->bar0)
|
||||
{
|
||||
device->bar0 = dev->base_addr[0];
|
||||
device->bar0 = pci_dev->base_addr[0];
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -71,24 +74,23 @@ int main(int argc, char **argv)
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
int fd;
|
||||
void *map_base;
|
||||
void *virt_addr;
|
||||
uint32_t temp;
|
||||
double temp;
|
||||
uint32_t phys_addr;
|
||||
uint32_t read_result;
|
||||
uint32_t base_offset;
|
||||
uint32_t map_size = 0x1000;
|
||||
uint32_t map_size;
|
||||
|
||||
struct device *device = NULL;
|
||||
char *MEM = "\x2f\x64\x65\x76\x2f\x6d\x65\x6d";
|
||||
|
||||
device = pci_detect_dev();
|
||||
phys_addr = device->bar0 + device->offset;
|
||||
|
||||
if (device == NULL)
|
||||
{
|
||||
printf("No compatible devices device. \n");
|
||||
printf("No compatible GPU found\n.");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
@@ -100,6 +102,8 @@ int main(int argc, char **argv)
|
||||
PRINT_ERROR();
|
||||
}
|
||||
|
||||
map_size = 0x1000;
|
||||
phys_addr = (device->bar0 + device->offset);
|
||||
base_offset = phys_addr & ~(sysconf(_SC_PAGE_SIZE)-1);
|
||||
map_base = mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, base_offset);
|
||||
|
||||
@@ -111,12 +115,12 @@ int main(int argc, char **argv)
|
||||
|
||||
while (1)
|
||||
{
|
||||
virt_addr = (map_base + (phys_addr - base_offset));
|
||||
virt_addr = (uint8_t *) map_base + (phys_addr - base_offset);
|
||||
read_result = *((uint32_t *) virt_addr);
|
||||
|
||||
temp = ((read_result & 0x00000fff) / 0x20);
|
||||
|
||||
printf("\r%s VRAM Temp: %d°c", device->vram, temp);
|
||||
printf("\r%s VRAM Temp: %.1f°c", device->vram, temp);
|
||||
fflush(stdout);
|
||||
|
||||
sleep(1);
|
||||
|
||||
Reference in New Issue
Block a user