Subject: X on IP22 success
To: None <port-sgimips@netbsd.org>
From: Christopher SEKIYA <wileyc@rezrov.net>
List: port-sgimips
Date: 01/22/2004 20:50:05
All,

With a bit of hackery I've managed to get X working on my Indy.

1280x1024 geometry doesn't work, and the colormaps are really messed up
(24bpp mostly works, 8bpp is pretty broken).  These fail, I think, because of
conflicts between the wscons setup and the X driver, but nevertheless it works.

Patches against sys/arch/sgimips/gio/newport.c and the xfree tree are
appended for the daring.  Feel free to hack at them and make things work
better -- I'll commit what I have once I get the colormap things working right,
but help is _always_ appreciated (the newport X driver is very very far from
optimal, and I'm not proud of what I had to do to the newport driver to make
things work).

-- Chris
	GPG key FEB9DE7F (91AF 4534 4529 4BCC 31A5  938E 023E EEFB FEB9 DE7F)

(diff against -current source tree)

Index: sys/arch/sgimips/gio/newport.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/gio/newport.c,v
retrieving revision 1.1
diff -u -r1.1 newport.c
--- sys/arch/sgimips/gio/newport.c	15 Dec 2003 05:24:51 -0000	1.1
+++ sys/arch/sgimips/gio/newport.c	22 Jan 2004 11:33:05 -0000
@@ -665,7 +665,9 @@
 		    control & ~VC2_CONTROL_CURSOR_ENABLE);
 	} else {
 		/* Work around bug in some board revisions */
-		if (dc->dc_boardrev < 6)
+		if (dc->dc_boardrev == 1)
+			x_offset = 29;
+		else if ( dc->dc_boardrev < 6 )
 			x_offset = 21;
 		else
 			x_offset = 31;
@@ -836,7 +838,7 @@
 static paddr_t
 newport_mmap(void *c, off_t offset, int prot)
 {
-	return -1;
+	return mips_btop(offset);
 }
 
 static int


(diff against xsrc)

diff -urNbB xfree-old/xc/config/cf/Imake.cf xfree/xc/config/cf/Imake.cf
--- xfree-old/xc/config/cf/Imake.cf	2003-03-15 22:27:21.000000000 +0900
+++ xfree/xc/config/cf/Imake.cf	2004-01-22 20:42:27.000000000 +0900
@@ -186,10 +186,10 @@
 #    define Sparc64Architecture
 #  endif
 # endif
-# ifdef mips
+# ifdef __mips__
 #   define MipsArchitecture
 #   define ArcArchitecture
-#   undef mips
+#   undef __mips__
 # endif
 # ifdef __alpha__
 #   define AlphaArchitecture
diff -urNbB xfree-old/xc/config/cf/NetBSD.cf xfree/xc/config/cf/NetBSD.cf
--- xfree-old/xc/config/cf/NetBSD.cf	2003-12-19 22:03:47.000000000 +0900
+++ xfree/xc/config/cf/NetBSD.cf	2004-01-22 20:42:27.000000000 +0900
@@ -307,6 +307,9 @@
 #  ifndef XFree86ConsoleDefines
 #    define XFree86ConsoleDefines -DWSCONS_SUPPORT
 #  endif
+#elif defined(MipsArchitecture)
+#    define XFree86ConsoleDefines -DWSCONS_SUPPORT
+#  define ServerExtraDefines    GccGasOption XFree86ServerDefines
 #else
 #  define ServerExtraDefines GccGasOption
 #endif
@@ -610,7 +613,7 @@
 /* Always build the XInput library, regardless of server support on this plattform */
 #define BuildXInputLib          YES
 
-#if defined(i386Architecture) || defined(Arm32Architecture) || defined(AlphaArchitecture) || defined(PpcArchitecture) || defined(CatsArchitecture) || defined(x86_64Architecture)
+#if defined(i386Architecture) || defined(Arm32Architecture) || defined(AlphaArchitecture) || defined(PpcArchitecture) || defined(CatsArchitecture) || defined(x86_64Architecture) || defined(MipsArchitecture)
 # include <xfree86.cf>
 #endif
 
@@ -686,13 +689,10 @@
 /*
  * Definition for compiling on MIPS machines
  */
-#ifdef MipsArchitecture
-#define PositionIndependentCFlags
-#define SharedLibraryLoadFlags -x -shared --whole-archive -soname `echo $@ |
-sed 's/\.[0-9]*$$//'`
-#define SharedXtReqs $(XLIBONLY) $(SMLIB) $(ICELIB)
-#define SharedXmuReqs $(LDPRELIB) $(XTOOLONLYLIB) $(XONLYLIB) $(EXTENSIONLIB)
-#endif
+
+/* #ifdef MipsArchitecture
+#define XF86OSCardDrivers		newport
+#endif */
 
 /*
  * Definition for compile on macppc machines
diff -urNbB xfree-old/xc/programs/Xserver/hw/xfree86/common/compiler.h xfree/xc/programs/Xserver/hw/xfree86/common/compiler.h
--- xfree-old/xc/programs/Xserver/hw/xfree86/common/compiler.h	2003-05-02 05:07:42.000000000 +0900
+++ xfree/xc/programs/Xserver/hw/xfree86/common/compiler.h	2004-01-22 20:42:27.000000000 +0900
@@ -1002,7 +1002,22 @@
 #      define stw_u(v,p)	(*(unsigned char *)(p)) = (v); \
 				(*(unsigned char *)(p)+1) = ((v) >> 8)
 
+#if defined(__NetBSD__)
+#      define mem_barrier() \
+        __asm__ __volatile__(					\
+		"# prevent instructions being moved around\n\t"	\
+       		".set\tnoreorder\n\t"				\
+		"# 8 nops to fool the R4400 pipeline\n\t"	\
+		"nop;nop;nop;nop;nop;nop;nop;nop\n\t"		\
+		".set\treorder"					\
+		: /* no output */				\
+		: /* no input */				\
+		: "memory")
+#      define write_mem_barrier() mem_barrier()
+#else
 #      define mem_barrier()   /* NOP */
+#endif
+
 #     endif /* !linux */
 #    endif /* __mips__ */
 
diff -urNbB xfree-old/xc/programs/Xserver/hw/xfree86/drivers/newport/newport_driver.c xfree/xc/programs/Xserver/hw/xfree86/drivers/newport/newport_driver.c
--- xfree-old/xc/programs/Xserver/hw/xfree86/drivers/newport/newport_driver.c	2003-02-28 22:20:12.000000000 +0900
+++ xfree/xc/programs/Xserver/hw/xfree86/drivers/newport/newport_driver.c	2004-01-22 20:42:27.000000000 +0900
@@ -32,6 +32,11 @@
  */
 /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/newport/newport_driver.c,v 1.24 2003/02/18 19:10:36 alanh Exp $ */
 
+#if defined(__NetBSD__)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
+
 /* function prototypes, common data structures & generic includes */
 #include "newport.h"
 
@@ -372,15 +377,13 @@
 	NewportProbeCardInfo(pScrn);
 	NewportUnmapRegs(pScrn);
 
-	from=X_PROBED;
-	xf86DrvMsg(pScrn->scrnIndex, from,
+	xf86DrvMsg(pScrn->scrnIndex, X_PROBED,
 		"Newport Graphics Revisions: Board: %d, Rex3: %c, Cmap: %c, Xmap9: %c\n",
 		pNewport->board_rev, pNewport->rex3_rev, 
 		pNewport->cmap_rev, pNewport->xmap9_rev);
 
 	if ( (xf86GetOptValInteger(pNewport->Options, OPTION_BITPLANES, &pNewport->bitplanes)))
-	from = X_CONFIG;
-	xf86DrvMsg(pScrn->scrnIndex, from, "Newport has %d bitplanes\n", pNewport->bitplanes);
+		xf86DrvMsg(pScrn->scrnIndex, X_PROBED, "Newport has %d bitplanes\n", pNewport->bitplanes);
 
 	if ( pScrn->depth > pNewport->bitplanes ) {
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, \
@@ -678,11 +681,13 @@
 
 	width = mode->HDisplay;
 	height = mode->VDisplay;
+/*
 	if (width != 1280 || height != 1024) {
 		xf86DrvMsg(pScrn->scrnIndex, X_ERROR, \
 		"Width = %d and height = %d is not supported by by this driver\n", width, height);
 		return FALSE;
 	}
+*/
 
 	pScrn->vtSema = TRUE;
 	/* first backup the necessary registers... */
@@ -743,7 +748,7 @@
 					NPORT_DMODE1_RGBMD;
 	pNewportRegs->set.colorvram = 0;
 	pNewportRegs->set.xystarti = 0;
-	pNewportRegs->go.xyendi = ( (1279+64) << 16) | 1023;
+	pNewportRegs->go.xyendi = ( ( (width-1)+64) << 16) | (height-1);
 
 	/* default drawmode */
 	NewportWait(pNewportRegs);
@@ -781,9 +786,27 @@
 static unsigned
 NewportHWProbe(unsigned probedIDs[])
 {
+	unsigned hasNewport = 0;
+#if defined(__NetBSD__)
+	int mib[2];
+        size_t len;
+        char *p;
+
+        mib[0] = CTL_HW;
+        mib[1] = HW_MODEL;
+
+        sysctl(mib, 2, NULL, &len, NULL, 0);
+        p = malloc(len);
+        sysctl(mib, 2, p, &len, NULL, 0);
+	if (!strcmp("SGI-IP22", p))
+	{
+		hasNewport = 1;
+		probedIDs[0] = 0;
+	}
+        free(p);
+#else
 	FILE* cpuinfo;
 	char line[80];
-	unsigned hasNewport = 0;
 
 	if ((cpuinfo = fopen("/proc/cpuinfo", "r"))) {
 		while(fgets(line, 80, cpuinfo) != NULL) {
@@ -800,6 +823,7 @@
 		}
 		fclose(cpuinfo);
 	}
+#endif
 	return hasNewport;
 }
 
diff -urNbB xfree-old/xc/programs/Xserver/hw/xfree86/os-support/Imakefile xfree/xc/programs/Xserver/hw/xfree86/os-support/Imakefile
--- xfree-old/xc/programs/Xserver/hw/xfree86/os-support/Imakefile	2003-12-19 22:03:47.000000000 +0900
+++ xfree/xc/programs/Xserver/hw/xfree86/os-support/Imakefile	2004-01-22 20:42:27.000000000 +0900
@@ -17,6 +17,7 @@
 	(defined(NetBSDArchitecture) && defined(PpcArchitecture)) || \
 	(defined(NetBSDArchitecture) && defined(SparcArchitecture)) || \
 	(defined(NetBSDArchitecture) && defined(CatsArchitecture)) || \
+	(defined(NetBSDArchitecture) && defined(MipsArchitecture)) || \
 	(defined(OpenBSDArchitecture) && defined(PpcArchitecture)) || \
 	(defined(LynxOSArchitecture) && defined(PpcArchitecture)) || \
 	defined(x86_64Architecture) || defined(LinuxArchitecture)
diff -urNbB xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile
--- xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile	2003-06-11 02:36:46.000000000 +0900
+++ xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile	2004-01-22 20:42:27.000000000 +0900
@@ -154,6 +154,9 @@
 #elif defined(Sparc64Architecture)
 VIDEO_SRC = sparc64_video.c
 VIDEO_OBJ = sparc64_video.o
+#elif defined(MipsArchitecture)
+VIDEO_SRC = mips_video.c
+VIDEO_OBJ = mips_video.o
 #else
 #error Unknown architecture !
 #endif
diff -urNbB xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsdResource.c xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsdResource.c
--- xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsdResource.c	2003-03-01 06:49:42.000000000 +0900
+++ xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/bsdResource.c	2004-01-22 20:42:27.000000000 +0900
@@ -112,7 +112,7 @@
     return ret;
 }
 
-#elif defined(__powerpc__) || defined(__arm__)
+#elif defined(__powerpc__) || defined(__arm__) || defined(__mips__)
 
 resPtr
 xf86BusAccWindowsFromOS(void)
diff -urNbB xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bsd/mips_video.c xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/mips_video.c
--- xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bsd/mips_video.c	1970-01-01 09:00:00.000000000 +0900
+++ xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/mips_video.c	2004-01-22 20:46:34.000000000 +0900
@@ -0,0 +1,144 @@
+/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bsd/ppc_video.c,v 1.3 2002/11/09 17:28:08 herrb Exp $ */
+/*
+ * Copyright 1992 by Rich Murphey <Rich@Rice.edu>
+ * Copyright 1993 by David Wexelblat <dwex@goblin.org>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the names of Rich Murphey and David Wexelblat 
+ * not be used in advertising or publicity pertaining to distribution of 
+ * the software without specific, written prior permission.  Rich Murphey and
+ * David Wexelblat make no representations about the suitability of this 
+ * software for any purpose.  It is provided "as is" without express or 
+ * implied warranty.
+ *
+ * RICH MURPHEY AND DAVID WEXELBLAT DISCLAIM ALL WARRANTIES WITH REGARD TO 
+ * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND 
+ * FITNESS, IN NO EVENT SHALL RICH MURPHEY OR DAVID WEXELBLAT BE LIABLE FOR 
+ * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER 
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF 
+ * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+
+/* $XConsortium: bsd_video.c /main/10 1996/10/25 11:37:57 kaleb $ */
+
+#include "X.h"
+#include "xf86.h"
+#include "xf86Priv.h"
+
+#include "xf86_OSlib.h"
+#include "xf86OSpriv.h"
+
+#include "bus/Pci.h"
+
+#ifndef MAP_FAILED
+#define MAP_FAILED ((caddr_t)-1)
+#endif
+
+
+/***************************************************************************/
+/* Video Memory Mapping section                                            */
+/***************************************************************************/
+
+#define DEV_MEM "/dev/mem"
+
+static pointer mipsMapVidMem(int, unsigned long, unsigned long, int flags);
+static void mipsUnmapVidMem(int, pointer, unsigned long);
+
+void
+xf86OSInitVidMem(VidMemInfoPtr pVidMem)
+{
+	pVidMem->linearSupported = TRUE;
+	pVidMem->mapMem = mipsMapVidMem;
+	pVidMem->unmapMem = mipsUnmapVidMem;
+	pVidMem->initialised = TRUE;
+}
+
+
+volatile unsigned char *ioBase = MAP_FAILED;
+
+static pointer
+mipsMapVidMem(int ScreenNum, unsigned long Base, unsigned long Size, int flags)
+{
+	int fd = xf86Info.screenFd;
+	pointer base;
+#ifdef DEBUG
+	xf86MsgVerb(X_INFO, 3, "mapVidMem %lx, %lx, fd = %d", 
+		    Base, Size, fd);
+#endif
+
+	base = mmap(0, Size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, Base);
+	if (base == MAP_FAILED)
+		FatalError("%s: could not mmap screen [s=%x,a=%x] (%s)\n",
+			   "xf86MapVidMem", Size, Base, strerror(errno));
+
+	return base;
+}
+
+static void
+mipsUnmapVidMem(int ScreenNum, pointer Base, unsigned long Size)
+{
+	munmap(Base, Size);
+}
+
+int
+xf86ReadBIOS(unsigned long Base, unsigned long Offset, unsigned char *Buf,
+	     int Len)
+{
+	int rv;
+	static int kmem = -1;
+
+	if (kmem == -1) {
+		kmem = open(DEV_MEM, 2);
+		if (kmem == -1) {
+			FatalError("xf86ReadBIOS: open %s\n", DEV_MEM);
+		}
+	}
+
+#ifdef DEBUG
+	xf86MsgVerb(X_INFO, 3, "xf86ReadBIOS() %lx %lx, %x\n", 
+		    Base, Offset, Len);
+#endif
+
+
+	lseek(kmem, Base + Offset, 0);
+	rv = read(kmem, Buf, Len);
+
+	return rv;
+}
+
+void
+xf86EnableIO()
+{
+        printf("xf86EnableIO\n");
+	return;
+}
+
+void
+xf86DisableIO()
+{
+	printf("xf86DisableIO\n");
+	return;
+}
+
+/***************************************************************************/
+/* Interrupt Handling section                                              */
+/***************************************************************************/
+
+Bool
+xf86DisableInterrupts()
+{
+
+	return(TRUE);
+}
+
+void
+xf86EnableInterrupts()
+{
+
+	return;
+}
diff -urNbB xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bus/Imakefile xfree/xc/programs/Xserver/hw/xfree86/os-support/bus/Imakefile
--- xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bus/Imakefile	2003-09-11 07:18:42.000000000 +0900
+++ xfree/xc/programs/Xserver/hw/xfree86/os-support/bus/Imakefile	2004-01-22 20:42:27.000000000 +0900
@@ -65,6 +65,13 @@
 PCIDRVRSRC = netbsdPci.c
 PCIDRVROBJ = netbsdPci.o
 
+#elif defined(NetBSDArchitecture) && defined(MipsArchitecture)
+
+XCOMM NetBSD/mips
+
+PCIDRVRSRC = netbsdPci.c
+PCIDRVROBJ = netbsdPci.o
+
 #elif defined(PpcArchitecture)
 
 XCOMM PowerPC PCI drivers
diff -urNbB xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bus/Pci.h xfree/xc/programs/Xserver/hw/xfree86/os-support/bus/Pci.h
--- xfree-old/xc/programs/Xserver/hw/xfree86/os-support/bus/Pci.h	2003-12-19 22:03:47.000000000 +0900
+++ xfree/xc/programs/Xserver/hw/xfree86/os-support/bus/Pci.h	2004-01-22 20:42:27.000000000 +0900
@@ -249,6 +249,10 @@
 #  define ARCH_PCI_INIT linuxPciInit
 #  define INCLUDE_XF86_MAP_PCI_MEM
 #  define INCLUDE_XF86_NO_DOMAIN
+# elif defined(__NetBSD__)
+#  define ARCH_PCI_INIT netbsdPciInit
+#  define INCLUDE_XF86_MAP_PCI_MEM
+#  define INCLUDE_XF86_NO_DOMAIN
 # endif
 #elif defined(__powerpc__)
 # if defined(linux)