Subject: Re: the 8600 lives!
To: Miles Nordin <carton@Ivy.NET>
From: Michael <macallan18@earthlink.net>
List: port-macppc
Date: 04/02/2005 15:42:02
Hello,


>      m> http://macallam.homeunix.org:6704/stuff/BSD/
> 
> k., I got the X server and kernel to test if it helps with chips 65550
> support.
> 
> I can't boot the kernel because there's a bug with the power
> management driver on my PB2400, so as soon as it attaches, the machine
> powers off, blinks the green Sleep light, and reboots.
> 
> Could I trouble you to post the source patches, either patches to go
> with each new kernel/xserver you release, or else a ``latest patches''
> diff if that's easier?  Optimistically, having the source code
> available might help get your work reviewed and committed, too.  It
> seems like quite a few cards are affected.

The kernel changes are short and simple ( can't post a real patch because my console stuff differs a lot from the official source )
Basically you need to change src/sys/arch/macppc/dev/ofb.c and ofbvar.h like this like this:

add 	
	bus_space_tag_t sc_iot;		/* parent's IO tag - we need to allow mmap()ing this space. */
to struct ofb_softc in ofbvar.h

than add 
	/* store parent's IO tag to allow mmap()ing IO space */
	sc->sc_iot=pa->pa_iot;
to ofbattach() in ofb.h and finally do this to ofb_mmap():
paddr_t
ofb_mmap(v, offset, prot)
	void *v;
	off_t offset;
	int prot;
{
	struct ofb_softc *sc = v;
	struct rasops_info *ri = &sc->sc_ri;
	u_int32_t *ap = sc->sc_addrs;
	paddr_t pa, io;
	int i;

	/* map the framebuffer at offset 0 /*
	if (offset >=0 && offset < (ri->ri_stride * ri->ri_height))
		return sc->sc_paddr + offset;

	/* allow to map our IO space... */
	io=(sc->sc_iot & MACPPC_BUS_ADDR_MASK);	
	if ((offset >= 0xf0000000) && (offset<(0xf0800000)))	/* 23 bit Macintosh IO space */
	{
		return io+(offset-0xf0000000);
	}

#ifdef OFB_FAKE_VGA_FB
	/* somewhat frivolous - fake the VGA framebuffer so vgahw actually does something
	    halfway useful when mapping 0xa0000 */
	if((offset>=0xa0000) && (offset<0xc0000))
		return sc->sc_paddr + offset - 0xa0000;
#endif

	pa = offset;
	for (i = 0; i < 6; i++) {
		switch (ap[0] & OFW_PCI_PHYS_HI_SPACEMASK) {
		case OFW_PCI_PHYS_HI_SPACE_MEM32:
			if (pa >= ap[2] && pa < ap[2] + ap[4])
				return pa;
		/* XXX I/O space? */
		}
		ap += 5;
	}

	return -1;
}

You'll need 
options OFB_FAKE_VGA_FB
in your kernel config so XFree can mmap() what it thinks is the legacy VGA framebuffer ( actually the first 128KB of the real framebuffer here ). This should be fixed in XFree though. The important part is the mapping of PCI IO space, that's what my XFree needs and ultimately what got my Voodoo3 to work.
The XFree86 patch is rather short:
Index: bsd/Imakefile
===================================================================
RCS file: /cvsroot/xsrc/xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/Imakefile,v
retrieving revision 1.19
diff -u -w -r1.19 Imakefile
--- bsd/Imakefile       18 Mar 2005 14:55:15 -0000      1.19
+++ bsd/Imakefile       2 Apr 2005 20:38:36 -0000
@@ -69,6 +69,8 @@
   IOPERMDEFINES = -DUSE_ALPHA_PIO
 # elif defined(i386Architecture)
   IOPERMDEFINES = -DUSE_I386_IOPL
+# elif defined(PpcArchitecture)
+  IOPERMDEFINES = -DUSE_PPC_MMAP
 # elif !defined(ArmArchitecture) && \
        !defined(MipsArchitecture)
   IOPERM_SRC = ioperm_noop.c
Index: bsd/ppc_video.c
===================================================================
RCS file: /cvsroot/xsrc/xfree/xc/programs/Xserver/hw/xfree86/os-support/bsd/ppc_video.c,v
retrieving revision 1.3
diff -u -w -r1.3 ppc_video.c
--- bsd/ppc_video.c     5 Mar 2004 16:33:06 -0000       1.3
+++ bsd/ppc_video.c     2 Apr 2005 20:38:36 -0000
@@ -52,6 +52,8 @@
 
 static pointer ppcMapVidMem(int, unsigned long, unsigned long, int flags);
 static void ppcUnmapVidMem(int, pointer, unsigned long);
+void xf86EnableIO();
+void xf86DisableIO();
 
 void
 xf86OSInitVidMem(VidMemInfoPtr pVidMem)
@@ -114,7 +116,7 @@
 
        lseek(kmem, Base + Offset, 0);
        rv = read(kmem, Buf, Len);
-
+       close(kmem);
        return rv;
 }
 
@@ -135,3 +137,29 @@
 
        return;
 }
+
+#ifdef USE_PPC_MMAP
+
+void xf86EnableIO()
+{
+       int fd=xf86Info.screenFd;
+       xf86MsgVerb(X_WARNING, 3, "xf86EnableIO %d\n",fd);
+       if(ioBase==MAP_FAILED)
+       {
+               ioBase=mmap(NULL,0x10000,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0xf0000000);
+               xf86MsgVerb(X_WARNING, 3, "xf86EnableIO: %08x\n",ioBase);
+               if(ioBase==MAP_FAILED)
+                       xf86MsgVerb(X_WARNING, 3, "Can't map IO space!\n");
+       }
+}
+
+void xf86DisableIO()
+{
+       if(ioBase!=MAP_FAILED)
+       {
+               munmap(ioBase,0x10000);
+               ioBase=MAP_FAILED;
+       }
+}
+
+#endif

This allows XFree to use the mmap()ed IO space for all IO operations. Without it no driver that needs IO access will work properly.

good luck
Michael