#include #include #include #include #include #include #include #include #define IO_REGS_LENGTH 0x80000 // GMU No longer needed //#define IO_BASE_ADDR 0xe0080000 off_t get_offset(char *argv1) { char *c = strchr(argv1, 'x'); off_t io_base = 0x0; if (c != NULL) { sscanf(argv1, "%lx", &io_base); } else // no 'x' in the string, must be an integer instead of a hex value { // Is this valid? io_base = atol(argv1); } return io_base; } int main(int argc, char *argv[]) { unsigned long *MMIOBase; unsigned long swf1; int fd; off_t io_base_addr; if (argc != 2) { fprintf(stderr, "Usage:\n\t%s \n\n\tWhere is base address of Display Controller 32-bit, non-prefetchable memory.\n\tHint: use /sbin/lspci -v to obtain this value.\n", argv[0]); return -1; } io_base_addr = get_offset(argv[1]); if ((fd = open("/dev/mem", O_RDWR)) < 0) { fprintf(stderr, "Cannot open /dev/mem\n"); return -1; } // MMIOBase = (unsigned long *)mmap(NULL, IO_REGS_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t)IO_BASE_ADDR); MMIOBase = (unsigned long *)mmap(NULL, IO_REGS_LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, fd, io_base_addr); if (MMIOBase == (unsigned long *)-1) { close(fd); perror("IOBase "); fprintf(stderr, "Can't map MMIOBase\n"); return -1; } swf1 = MMIOBase[0x71414/4]; printf("SWF1 before = 0x%8.8X\n", swf1); swf1 &= ~0xf; swf1 |= 8; printf("SWF1 after = 0x%8.8X\n", swf1); MMIOBase[0x71414/4] = swf1; munmap(MMIOBase, IO_REGS_LENGTH); close(fd); return 0; }