Skip to content

Instantly share code, notes, and snippets.

@jemk
Created January 26, 2015 14:58
Show Gist options
  • Save jemk/9c5895dc8bf9a23c289a to your computer and use it in GitHub Desktop.
Save jemk/9c5895dc8bf9a23c289a to your computer and use it in GitHub Desktop.
Get sunxi VE version
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#define IOCTL_GET_ENV_INFO 0x101
#define IOCTL_ENGINE_REQ 0x206
#define IOCTL_ENGINE_REL 0x207
#define REG_VE_VERSION 0x0f0
struct ve_info
{
uint32_t reserved_mem;
int reserved_mem_size;
uint32_t registers;
};
static inline uint32_t readl(void *addr)
{
return *((volatile uint32_t *) addr);
}
int main(void)
{
int fd;
struct ve_info info;
void *regs;
fd = open("/dev/cedar_dev", O_RDWR);
if (fd == -1)
{
fprintf(stderr, "Could not open /dev/cedar_dev: %s\n", strerror(errno));
return 1;
}
if (ioctl(fd, IOCTL_GET_ENV_INFO, (void *)(&info)) == -1)
{
fprintf(stderr, "Could not get env_info: %s\n", strerror(errno));
close(fd);
return 1;
}
regs = mmap(NULL, 0x800, PROT_READ | PROT_WRITE, MAP_SHARED, fd, info.registers);
if (regs == MAP_FAILED)
{
fprintf(stderr, "Could not mmap register space: %s\n", strerror(errno));
close(fd);
return 1;
}
ioctl(fd, IOCTL_ENGINE_REQ, 0);
printf("VE Version: 0x%08x\n", readl(regs + REG_VE_VERSION));
ioctl(fd, IOCTL_ENGINE_REL, 0);
munmap(regs, 0x800);
close(fd);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment