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

Ian Lindsay iml at formicary.org
Sat Jan 22 04:13:27 CET 2005


On Fri, Jan 21, 2005 at 10:40:26PM +0100, Alex Beregszaszi wrote:
> it's obviously not, any better ideas? at least prefix that mem_fd with
> dha_ or something, less pollution on common names

here's the patch with dha_ prefix for a different flavour of namespace
pollution. the issue is that you can't open /dev/xf86 multiple times
or continue to use mmap'ed region after closing it.
-------------- next part --------------
Index: libdha/libdha.c
===================================================================
RCS file: /cvsroot/mplayer/main/libdha/libdha.c,v
retrieving revision 1.13
diff -u -r1.13 libdha.c
--- libdha/libdha.c	21 Jan 2005 21:36:30 -0000	1.13
+++ libdha/libdha.c	22 Jan 2005 02:51:59 -0000
@@ -10,7 +10,7 @@
 		- dhahelper and some changes by Alex Beregszaszi
     
     supported O/S's:	SVR4, UnixWare, SCO, Solaris,
-			FreeBSD, NetBSD, 386BSD, BSDI BSD/386,
+			FreeBSD, NetBSD, OpenBSD, 386BSD, BSDI BSD/386,
 			Linux, Mach/386, ISC
 			DOS (WATCOM 9.5 compiler), Win9x (with mapdev.vxd)
     Licence: GPL
@@ -69,7 +69,7 @@
 #include <svgalib_helper.h>
 #endif
 
-static int mem_fd = -1;
+int dha_mem_fd = -1;
 
 void *map_phys_mem(unsigned long base, unsigned long size)
 {    
@@ -79,7 +79,7 @@
 #endif
 
 #ifdef CONFIG_SVGAHELPER
-  if ( (mem_fd = open(DEV_SVGA,O_RDWR)) == -1) {
+  if ( (dha_mem_fd = open(DEV_SVGA,O_RDWR)) == -1) {
       perror("libdha: SVGAlib kernelhelper failed");
 #ifdef CONFIG_DHAHELPER
       goto dha_helper_way;
@@ -95,7 +95,7 @@
 #ifdef CONFIG_SVGAHELPER
 dha_helper_way:
 #endif
-  if ( (mem_fd = open("/dev/dhahelper",O_RDWR)) < 0)
+  if ( (dha_mem_fd = open("/dev/dhahelper",O_RDWR)) < 0)
   {
       perror("libdha: DHA kernelhelper failed");
       goto dev_mem_way;
@@ -109,10 +109,10 @@
     mem_req.offset = 0;
     mem_req.size = size;
     
-    if (ioctl(mem_fd, DHAHELPER_MEMORY, &mem_req) < 0)
+    if (ioctl(dha_mem_fd, DHAHELPER_MEMORY, &mem_req) < 0)
     {
 	perror("libdha: DHA kernelhelper failed");
-	close(mem_fd);
+	close(dha_mem_fd);
 	goto dev_mem_way;
     }
     else
@@ -122,27 +122,31 @@
 
 dev_mem_way:
 #ifdef DEV_APERTURE
-  if ((mem_fd = open(DEV_APERTURE, O_RDWR)) == -1)
+  if (dha_mem_fd != -1)
+	goto mmap;	/* only one handle for /dev/xf86 permitted */
+
+  if ((dha_mem_fd = open(DEV_APERTURE, O_RDWR)) == -1)
 	perror("libdha: opening aperture failed");
   else {
-	void *p = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base);
+	void *p = mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,dha_mem_fd,base);
 
 	if (p == MAP_FAILED) {
 	    perror("libdha: mapping aperture failed");
-	    close(mem_fd);
+	    close(dha_mem_fd);
+	    dha_mem_fd = -1;
 	} else
 	    return p;
   }
 #endif
 
-  if ( (mem_fd = open(DEV_MEM,O_RDWR)) == -1)
+  if ( (dha_mem_fd = open(DEV_MEM,O_RDWR)) == -1)
   {
     perror("libdha: opening /dev/mem failed");
     return MAP_FAILED;
   }
 
 mmap:
-  return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,mem_fd,base);
+  return mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,dha_mem_fd,base);
 }
 
 void unmap_phys_mem(void *ptr, unsigned long size)
@@ -155,8 +159,8 @@
       return;
   }
   
-  close(mem_fd);
-  mem_fd = -1;
+  close(dha_mem_fd);
+  dha_mem_fd = -1;
   
   return;
 }
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	22 Jan 2005 02:51:59 -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 dha_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(dha_mem_fd, MEMRANGE_SET, &mro);
 #else
 #warning Please port MTRR stuff!!!
     return ENOSYS;


More information about the MPlayer-dev-eng mailing list