summaryrefslogtreecommitdiffstats
path: root/opengl/tests/angeles/gpustate.c
blob: 3c540c9ca5fd16f20c0916a6c4d11cc0baf285a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>

static void *map_memory(const char *fn, unsigned base, unsigned size)
{
    int fd;
    void *ptr;
    
    fd = open(fn, O_RDWR | O_SYNC);
    if(fd < 0) {
        perror("cannot open %s for mapping");
        return MAP_FAILED;
    }

    ptr = mmap(0, size, PROT_READ | PROT_WRITE,
               MAP_SHARED, fd, base);
    close(fd);
    
    if(ptr == MAP_FAILED) {
        fprintf(stderr,"cannot map %s (@%08x,%08x)\n", fn, base, size);
    }
    return ptr;    
}


int main(int argc, char** argv)
{
    void *grp_regs = map_memory("/dev/hw3d", 0, 1024 * 1024);
    printf("GPU base mapped at %p\n", grp_regs);
    int state_offset = 0x10140;
    printf("GPU state = %08lx\n",
            *((long*)((char*)grp_regs + state_offset))  );

    return 0;
}