[Xorg-driver-geode] building xf86-video-geode on non-Linux platforms?

Matthieu Herrb matthieu.herrb at laas.fr
Mon Feb 20 13:27:40 PST 2012


On Sun, Feb 19, 2012 at 08:58:08PM +0100, Matthieu Herrb wrote:
> On Fri, Feb 17, 2012 at 05:42:50PM +0200, Martin-Éric Racine wrote:
> > 6. helmikuuta 2012 15.14 Martin-Éric Racine
> > <martin-eric.racine at iki.fi> kirjoitti:
> > > 2. tammikuuta 2012 1.04 Martin-Éric Racine <martin-eric.racine at iki.fi>
> > > kirjoitti:
> > >> Starting with release 2.11.13, the autoconf implementation of
> > >> xf86-video-geode allows more flexibility on which platforms it can
> > >> succesfully build for, by skipping the ZTV module on platforms that
> > >> don't support V4L2.
> > >>
> > >> Btw, I'd welcome reports about which new platforms 2.11.13 can
> > >> succesfully build on. So far, we seem to have: Linux (geode & ztv),
> > >> Hurd (geode).
> > >
> > > Arrigo and Marc,
> > >
> > > Could you please confirm on which BSD variants the Geode video module
> > > now builds and whether ZTV get succesfully built as well?
> > 
> > Any news on this? :)
> > 
> 
> Sorry, 
> 
> I've been meaning to test that on OpenBSD for a few weeks already, but
> have always been distracted by other stuff. And it happened again this
> weekend. 
> 
> A quick build test of git HEAD shows that it fails to build in
> geode_msr.c. I'll investigate ASAP and produce either a patch or a
> more detailled bug report.

Wrong alert. I did attempt a build on an amd64 machine, because I
mis-remembered that geode would also build there. Thats' wrong at
least for OpenBSD.

Tried more seriously on a 32 bits machines. No issues there. The git
HEAD builds out of the box (altough I still have local patches from
mbalmer for MSR support on OpenBSD).

diff --git a/src/geode_msr.c b/src/geode_msr.c
index 26fd78f..d3e7a53 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);
+#ifdef X_PRIVSEP
+	msrfd = priv_open_device(_PATH_MSRDEV);
+#else
+	msrfd = open(_PATH_MSRDEV, O_RDWR);
+#endif
 	if (msrfd == -1)
-	    ErrorF("Unable to open /dev/cpu/0/msr: %d\n", errno);
+	    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();
 
@@ -67,6 +110,6 @@ GeodeWriteMSR(unsigned long addr, unsigned long lo, unsigned long hi)
 
     if (write(fd, (void *)data, 8) != 8)
 	return -1;
-
+#endif
     return 0;
 }

-- 
Matthieu Herrb


More information about the Xorg-driver-geode mailing list