Subject: xsrc/35918: add support to xsrc/xfree/xc for the OpenBSD aperture driver
To: None <xsrc-manager@netbsd.org, gnats-admin@netbsd.org,>
From: Greg A. Woods <woods@planix.com>
List: netbsd-bugs
Date: 03/05/2007 03:35:00
>Number:         35918
>Category:       xsrc
>Synopsis:       add support to xsrc/xfree/xc for the OpenBSD aperture driver
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    xsrc-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Mon Mar 05 03:35:00 +0000 2007
>Originator:     Greg A. Woods
>Release:        NetBSD xsrc
>Organization:
Planix, Inc.; Toronto, Ontario; Canada
>Environment:
System: NetBSD
>Description:

	some time ago I imported OpenBSD's VGA aperture driver into my
	netbsd-1-6 tree and added support to xsrc-current so that I
	could use it.

>How-To-Repeat:


>Fix:

Index: xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/xsrc/xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c,v
retrieving revision 1.4
diff -u -r1.4 i386_video.c
--- xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c	18 Mar 2005 14:55:15 -0000	1.4
+++ xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c	5 Mar 2007 01:37:36 -0000
@@ -73,19 +73,33 @@
 		"\tin /etc/sysctl.conf and reboot your machine\n" \
 		"\trefer to xf86(4) for details"
 #endif
+#ifdef __NetBSD__
+#define SYSCTL_MSG "\tCheck that you have set 'machdep.allow_vga_aperture=1'\n"\
+		   "\tin /etc/sysctl.conf and run '/etc/rc.d/sysctl start'\n" \
+		   "\tRefer to vga_aperture(4) for details.\n"
+#define SYSCTL_MSG2 \
+		"Check that you have set 'machdep.allow_vga_aperture=2'\n" \
+		"\tin /etc/sysctl.conf and run '/etc/rc.d/sysctl start'\n" \
+		"\tRefer to vga_aperture(4) for details.\n"
+#endif
 
 /***************************************************************************/
 /* Video Memory Mapping section                                            */
 /***************************************************************************/
 
-static Bool useDevMem = FALSE;
-static int  devMemFd = -1;
-
 #ifdef HAS_APERTURE_DRV
-#define DEV_APERTURE "/dev/xf86"
+# ifdef __OpenBSD__
+#  define DEV_APERTURE "/dev/xf86"
+# else
+#  define DEV_APERTURE "/dev/vga_aperture"
+# endif
 #endif
 #define DEV_MEM "/dev/mem"
 
+static Bool useDevMem = FALSE;
+static int  devMemFd = -1;
+static char *devMemName = "dev_mem";
+
 static pointer mapVidMem(int, unsigned long, unsigned long, int);
 static void unmapVidMem(int, pointer, unsigned long);
 
@@ -126,6 +140,7 @@
 	    {
 		munmap((caddr_t)base, 4096);
 		devMemFd = fd;
+		devMemName = DEV_MEM;
 		useDevMem = TRUE;
 		return;
 	    } else {
@@ -143,7 +158,7 @@
 	if (warn)
 	{ 
 	    xf86Msg(X_WARNING, "checkDevMem: failed to open %s (%s)\n",
-		    DEV_MEM, strerror(errno));
+		    devMemName, strerror(errno));
 	} 
 	useDevMem = FALSE;
 	return;
@@ -159,6 +174,7 @@
 	    {
 		munmap((caddr_t)base, 4096);
 		devMemFd = fd;
+		devMemName = DEV_APERTURE;
 		useDevMem = TRUE;
 		xf86Msg(X_INFO, "checkDevMem: using aperture driver %s\n",
 		        DEV_APERTURE);
@@ -174,14 +190,14 @@
 	} else {
 	    if (warn)
 	    {
-#ifndef __OpenBSD__
-		xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
-			"\t(%s)\n", DEV_MEM, DEV_APERTURE, strerror(errno));
-#else /* __OpenBSD__ */
+#if defined(SYSCTL_MSG)
 		xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
 			"\t(%s)\n%s", DEV_MEM, DEV_APERTURE, strerror(errno),
 			SYSCTL_MSG);
-#endif /* __OpenBSD__ */
+#else
+		xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
+			"\t(%s)\n", DEV_MEM, DEV_APERTURE, strerror(errno));
+#endif
 	    }
 	}
 	
@@ -226,7 +242,7 @@
 	    if (devMemFd < 0) 
 	    {
 		FatalError("xf86MapVidMem: failed to open %s (%s)",
-			   DEV_MEM, strerror(errno));
+			   devMemName, strerror(errno));
 	    }
 	    base = mmap((caddr_t)0, Size,
 			(flags & VIDMEM_READONLY) ?
@@ -235,7 +251,7 @@
 	    if (base == MAP_FAILED)
 	    {
 		FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)",
-			   "xf86MapVidMem", DEV_MEM, Size, Base, 
+			   "xf86MapVidMem", devMemName, Size, Base, 
 			   strerror(errno));
 	    }
 	    return(base);
@@ -255,8 +271,8 @@
 	    );
 	if (base == MAP_FAILED)
 	{
-	    FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)",
-		       strerror(errno));
+	    FatalError("xf86MapVidMem: Could not mmap screen file %s (%s)",
+		       xf86Info.screenName, strerror(errno));
 	}
 	return(base);
 }
@@ -293,9 +309,9 @@
 	if ((long)ptr == -1)
 	{
 		xf86Msg(X_WARNING, 
-			"xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n",
-			DEV_MEM, Len, Base, Offset, strerror(errno));
-#ifdef __OpenBSD__
+			"xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)",
+			devMemName, Len, Base, Offset, strerror(errno));
+#if defined(SYSCTL_MSG2)
 		if (Base < 0xa0000) {
 		    xf86Msg(X_WARNING, SYSCTL_MSG2);
 		} 
@@ -332,12 +348,12 @@
 
 	if (i386_iopl(TRUE) < 0)
 	{
-#ifndef __OpenBSD__
-		FatalError("%s: Failed to set IOPL for extended I/O",
-			   "xf86EnableIO");
-#else
+#if defined(SYSCTL_MSG)
 		FatalError("%s: Failed to set IOPL for extended I/O\n%s",
 			   "xf86EnableIO", SYSCTL_MSG);
+#else
+		FatalError("%s: Failed to set IOPL for extended I/O",
+			   "xf86EnableIO");
 #endif
 	}
 	ExtendedEnabled = TRUE;
@@ -370,7 +386,7 @@
 
        if (amd64_iopl(TRUE) < 0)
        {
-#ifndef __OpenBSD__
+#ifndef SYSCTL_MSG
                FatalError("%s: Failed to set IOPL for extended I/O",
                           "xf86EnableIO");
 #else
Index: xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/xsrc/xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c,v
retrieving revision 1.2
diff -u -r1.2 alpha_video.c
--- xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c	8 Apr 2005 20:56:22 -0000	1.2
+++ xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/alpha_video.c	12 Jul 2006 00:26:30 -0000
@@ -184,15 +184,25 @@
                   "\tin /etc/sysctl.conf and reboot your machine\n" \
                   "\trefer to xf86(4) for details"
 #endif
-
-static Bool useDevMem = FALSE;
-static int  devMemFd = -1;
+#ifdef __NetBSD__
+# define SYSCTL_MSG "\tCheck that you have set 'machdep.allow_vga_aperture=1'\n"\
+		    "\tin /etc/sysctl.conf and run '/etc/rc.d/sysctl start'\n" \
+		    "\tRefer to vga_aperture(4) for details.\n"
+#endif
 
 #ifdef HAS_APERTURE_DRV
-#define DEV_APERTURE "/dev/xf86"
+# ifdef __OpenBSD__
+#  define DEV_APERTURE "/dev/xf86"
+# else
+#  define DEV_APERTURE "/dev/vga_aperture"
+# endif
 #endif
 #define DEV_MEM "/dev/mem"
 
+static Bool useDevMem = FALSE;
+static int  devMemFd = -1;
+static char *devMemName = "dev_mem";
+
 static pointer mapVidMem(int, unsigned long, unsigned long, int);
 static void unmapVidMem(int, pointer, unsigned long);
 static pointer mapVidMemSparse(int, unsigned long, unsigned long, int);
@@ -243,6 +253,7 @@
 	    if (base != MAP_FAILED) {
 		munmap((caddr_t)base, 4096);
 		devMemFd = fd;
+		devMemName = DEV_MEM;
 		useDevMem = TRUE;
 		return;
 	    } else {
@@ -257,14 +268,15 @@
            xf86Msg(X_WARNING, "checkDevMem: failed to open/mmap %s (%s)\n",
                    DEV_MEM, strerror(errno));
 #else
-#ifndef __OpenBSD__
-           xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
-               "\t(%s)\n", DEV_APERTURE, DEV_MEM, strerror(errno));
-#else /* __OpenBSD__ */
+# if defined(SYSCTL_MSG)
            xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
                    "\t(%s)\n%s", DEV_APERTURE, DEV_MEM, strerror(errno),
                    SYSCTL_MSG);
-#endif /* __OpenBSD__ */
+# else
+           xf86Msg(X_WARNING, "checkDevMem: failed to open %s and %s\n"
+               "\t(%s)\n", DEV_APERTURE, DEV_MEM, strerror(errno));
+# endif
+	   
 #endif
            xf86ErrorF("\tlinear framebuffer access unavailable\n");
 	}
@@ -310,7 +322,7 @@
 	    if (devMemFd < 0) 
 	    {
 		FatalError("xf86MapVidMem: failed to open %s (%s)\n",
-			   DEV_MEM, strerror(errno));
+			   devMemName, strerror(errno));
 	    }
 	    base = mmap((caddr_t)0, Size,
 			(flags & VIDMEM_READONLY) ?
@@ -318,14 +330,14 @@
 			 MAP_FLAGS, devMemFd, (off_t)Base + BUS_BASE_BWX);
 	    if (base == MAP_FAILED)
 	    {
-		FatalError("%s: could not mmap %s [s=%lx,a=%lx] (%s)\n",
-			   "xf86MapVidMem", DEV_MEM, Size, Base, 
+		FatalError("%s: could not mmap %s [s=%x,a=%lx] (%s)\n",
+			   "xf86MapVidMem", devMemName, Size, Base, 
 			   strerror(errno));
 	    }
 	    return(base);
 	}
 		
-	/* else, mmap /dev/vga */
+	/* else, mmap the screenFd */
 	if ((unsigned long)Base < 0xA0000 || (unsigned long)Base >= 0xC0000)
 	{
 		FatalError("%s: Address 0x%lx outside allowable range\n",
@@ -338,8 +350,8 @@
 		    (unsigned long)Base + BUS_BASE);
 	if (base == MAP_FAILED)
 	{
-	    FatalError("xf86MapVidMem: Could not mmap /dev/vga (%s)\n",
-		       strerror(errno));
+	    FatalError("xf86MapVidMem: Could not mmap screen file %s (%s)\n",
+		       xf86Info.screenName, strerror(errno));
 	}
 	return(base);
 }
@@ -377,7 +389,7 @@
 	{
 		xf86Msg(X_WARNING, 
 			"xf86ReadBIOS: %s mmap[s=%x,a=%lx,o=%lx] failed (%s)\n",
-			DEV_MEM, Len, Base, Offset, strerror(errno));
+			devMemName, Len, Base, Offset, strerror(errno));
 		return(-1);
 	}
 #ifdef DEBUG
Index: xfree/xc/programs/Xserver/hw/xfree86/common/xf86Privstr.h
===================================================================
RCS file: /cvs/master/m-NetBSD/main/xsrc/xfree/xc/programs/Xserver/hw/xfree86/common/xf86Privstr.h,v
retrieving revision 1.1.1.7
diff -u -r1.1.1.7 xf86Privstr.h
--- xfree/xc/programs/Xserver/hw/xfree86/common/xf86Privstr.h	18 Mar 2005 13:11:23 -0000	1.1.1.7
+++ xfree/xc/programs/Xserver/hw/xfree86/common/xf86Privstr.h	12 Jul 2006 00:25:31 -0000
@@ -187,6 +187,7 @@
 #ifdef CSRG_BASED
     int			screenFd;	/* fd for memory mapped access to
 					 * vga card */
+    char *              screenName;	/* name opened for screenFd */
     int			consType;	/* Which console driver? */
 #endif
 
Index: xfree/xc/programs/Xserver/hw/xfree86/common/xf86Globals.c
===================================================================
RCS file: /cvs/master/m-NetBSD/main/xsrc/xfree/xc/programs/Xserver/hw/xfree86/common/xf86Globals.c,v
retrieving revision 1.1.1.7
diff -u -r1.1.1.7 xf86Globals.c
--- xfree/xc/programs/Xserver/hw/xfree86/common/xf86Globals.c	18 Mar 2005 13:11:22 -0000	1.1.1.7
+++ xfree/xc/programs/Xserver/hw/xfree86/common/xf86Globals.c	5 Mar 2007 01:39:02 -0000
@@ -201,6 +201,7 @@
 	NULL,		/* currentScreen */
 #ifdef CSRG_BASED
 	-1,		/* screenFd */
+	NULL,		/* screenName */
 	-1,		/* consType */
 #endif
 #ifdef XKB