diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 10 | ||||
-rw-r--r-- | src/geode_msr.c | 53 |
2 files changed, 48 insertions, 15 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 6c02386..42b0ce7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -143,13 +143,3 @@ EXTRA_DIST = \ \ gx_vga.c \ lx_vga.c - -if BUILD_ZTV - -ztv_drv_la_LTLIBRARIES = ztv_drv.la -ztv_drv_la_LDFLAGS = -module -avoid-version -ztv_drv_ladir = $(moduledir)/drivers - -ztv_drv_la_SOURCES = z4l.c - -endif BUILD_ZTV diff --git a/src/geode_msr.c b/src/geode_msr.c index d3a72c4..582b4c9 100644 --- a/src/geode_msr.c +++ b/src/geode_msr.c @@ -2,23 +2,40 @@ #include "config.h" #endif +#include <sys/types.h> +#include <sys/ioctl.h> +#ifdef __OpenBSD__ +#include <machine/amdmsr.h> +#endif + #include <stdio.h> #include <unistd.h> #include <fcntl.h> -#include <sys/types.h> #include <errno.h> + #include "os.h" #include "geode.h" +#ifdef __OpenBSD__ +#define _PATH_MSRDEV "/dev/amdmsr" +#define X_PRIVSEP +#else +#define _PATH_MSRDEV "/dev/cpu/0/msr" +#endif + static int _msr_open(void) { static int msrfd = 0; if (msrfd == 0) { - msrfd = open("/dev/cpu/0/msr", O_RDWR); - if (msrfd == -1) - ErrorF("Unable to open /dev/cpu/0/msr: %d\n", errno); +#ifdef X_PRIVSEP + msrfd = priv_open_device(_PATH_MSRDEV); +#else + msrfd = open(_PATH_MSRDEV, O_RDWR); +#endif + if (msrfd == -1) + ErrorF("Unable to open %s: %s\n", _PATH_MSRDEV, strerror(errno)); } return msrfd; @@ -27,6 +44,20 @@ _msr_open(void) int GeodeReadMSR(unsigned long addr, unsigned long *lo, unsigned long *hi) { +#ifdef __OpenBSD__ + struct amdmsr_req req; +#endif + int fd = _msr_open(); + +#ifdef __OpenBSD__ + req.addr = addr; + + if (ioctl(fd, RDMSR, &req) == -1) + ErrorF("Unable to RDMSR %d\n", errno); + + *hi = req.val >> 32; + *lo = req.val & 0xffffffff; +#else unsigned int data[2]; int fd = _msr_open(); int ret; @@ -46,13 +77,25 @@ GeodeReadMSR(unsigned long addr, unsigned long *lo, unsigned long *hi) *hi = data[1]; *lo = data[0]; - +#endif return 0; } int GeodeWriteMSR(unsigned long addr, unsigned long lo, unsigned long hi) { +#ifdef __OpenBSD__ + struct amdmsr_req req; +#endif + int fd = _msr_open(); + +#ifdef __OpenBSD__ + req.addr = addr; + req.val = (u_int64_t)hi << 32 | (u_int64_t)lo; + + if (ioctl(fd, WRMSR, &req) == -1) + ErrorF("Unable to WRMSR %d\n", errno); +#else unsigned int data[2]; int fd = _msr_open(); |