[MPlayer-dev-eng] [PATCH] OpenBSD MTRR support

Ian Lindsay iml04 at hampshire.edu
Mon Jan 17 19:45:49 CET 2005


Tested with cvidix nvidia driver on OpenBSD, should work on FreeBSD
too, maybe. I don't know if making mem_fd global is best thing or not..
-------------- next part --------------
Index: libdha/libdha.c
===================================================================
RCS file: /cvsroot/mplayer/main/libdha/libdha.c,v
retrieving revision 1.12
diff -u -r1.12 libdha.c
--- libdha/libdha.c	26 Mar 2004 12:15:54 -0000	1.12
+++ libdha/libdha.c	17 Jan 2005 18:34:49 -0000
@@ -65,7 +65,7 @@
 #include <svgalib_helper.h>
 #endif
 
-static int mem_fd = -1;
+int mem_fd = -1;
 
 void *map_phys_mem(unsigned long base, unsigned long size)
 {    
Index: libdha/mtrr.c
===================================================================
RCS file: /cvsroot/mplayer/main/libdha/mtrr.c,v
retrieving revision 1.6
diff -u -r1.6 mtrr.c
--- libdha/mtrr.c	7 Jun 2002 22:43:25 -0000	1.6
+++ libdha/mtrr.c	17 Jan 2005 18:34:49 -0000
@@ -21,8 +21,13 @@
 #include <machine/mtrr.h>
 #include <machine/sysarch.h>
 #endif
+#elif defined(__OpenBSD__) || defined(__FreeBSD__)
+#include <sys/ioctl.h>
+#include <sys/memrange.h>
 #endif
 
+extern int mem_fd;
+
 #if defined( __i386__ )
 int	mtrr_set_type(unsigned base,unsigned size,int type)
 {
@@ -72,6 +77,32 @@
     /* NetBSD prior to 1.5Y doesn't have MTRR support */
     return ENOSYS;
 #endif
+#elif defined(__OpenBSD__) || defined(__FreeBSD__)
+    struct mem_range_desc mrd;
+    struct mem_range_op mro;
+
+    switch(type) {
+    case MTRR_TYPE_UNCACHABLE:
+	mrd.mr_flags = MDF_UNCACHEABLE; break;
+    case MTRR_TYPE_WRCOMB:
+	mrd.mr_flags = MDF_WRITECOMBINE; break;
+    case MTRR_TYPE_WRTHROUGH:
+	mrd.mr_flags = MDF_WRITETHROUGH; break;
+    case MTRR_TYPE_WRPROT:
+	mrd.mr_flags = MDF_WRITEPROTECT; break;
+    case MTRR_TYPE_WRBACK:
+	mrd.mr_flags = MDF_WRITEBACK; break;
+    default:
+	return EINVAL;
+    }
+    mrd.mr_base = base;
+    mrd.mr_len = size;
+    strcpy(mrd.mr_owner, "libdha");
+
+    mro.mo_desc = &mrd;
+    mro.mo_arg[0] = MEMRANGE_SET_UPDATE;
+
+    return ioctl(mem_fd, MEMRANGE_SET, &mro);
 #else
 #warning Please port MTRR stuff!!!
     return ENOSYS;


More information about the MPlayer-dev-eng mailing list