Module Name:    src
Committed By:   rkujawa
Date:           Tue Jan 10 20:29:50 UTC 2012

Modified Files:
        src/sys/arch/amiga/amiga: amiga_init.c
        src/sys/arch/amiga/conf: DRACO GENERIC GENERIC.in INSTALL files.amiga
        src/sys/arch/amiga/dev: bppcsc.c cbiiisc.c
        src/sys/arch/amiga/pci: p5pb.c p5pbreg.h p5pbvar.h
Added Files:
        src/sys/arch/amiga/dev: p5bus.c p5busvar.h
        src/sys/arch/amiga/pci: p5membar.c p5membarvar.h

Log Message:
Changes to Phase5 hardware support:
- Rework p5pb driver - simplify, cleanup, make more flexible.
- Add p5membar driver, which handles PCI resources autoconfigured by the 
firmware.
- Introduce intermediate p5bus layer, between zbus and CSPPC/BPPC on-board 
devices (p5pb, cbiiisc, bppcsc).
- Add experimental G-REX support to p5pb (first slot support only).
- Split CV64/3D PCI bridge support into separate cv3dpb driver (to be committed 
later).

Approved by phx.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/sys/arch/amiga/amiga/amiga_init.c
cvs rdiff -u -r1.148 -r1.149 src/sys/arch/amiga/conf/DRACO
cvs rdiff -u -r1.278 -r1.279 src/sys/arch/amiga/conf/GENERIC
cvs rdiff -u -r1.90 -r1.91 src/sys/arch/amiga/conf/GENERIC.in
cvs rdiff -u -r1.100 -r1.101 src/sys/arch/amiga/conf/INSTALL
cvs rdiff -u -r1.150 -r1.151 src/sys/arch/amiga/conf/files.amiga
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/amiga/dev/bppcsc.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/amiga/dev/cbiiisc.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/amiga/dev/p5bus.c \
    src/sys/arch/amiga/dev/p5busvar.h
cvs rdiff -u -r0 -r1.1 src/sys/arch/amiga/pci/p5membar.c \
    src/sys/arch/amiga/pci/p5membarvar.h
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/amiga/pci/p5pb.c
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/amiga/pci/p5pbreg.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/amiga/pci/p5pbvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amiga/amiga/amiga_init.c
diff -u src/sys/arch/amiga/amiga/amiga_init.c:1.124 src/sys/arch/amiga/amiga/amiga_init.c:1.125
--- src/sys/arch/amiga/amiga/amiga_init.c:1.124	Sun Jul 10 21:02:37 2011
+++ src/sys/arch/amiga/amiga/amiga_init.c	Tue Jan 10 20:29:49 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: amiga_init.c,v 1.124 2011/07/10 21:02:37 mhitch Exp $	*/
+/*	$NetBSD: amiga_init.c,v 1.125 2012/01/10 20:29:49 rkujawa Exp $	*/
 
 /*
  * Copyright (c) 1994 Michael L. Hitch
@@ -38,7 +38,7 @@
 #include "ser.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: amiga_init.c,v 1.124 2011/07/10 21:02:37 mhitch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amiga_init.c,v 1.125 2012/01/10 20:29:49 rkujawa Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -331,6 +331,16 @@ start_c(id, fphystart, fphysize, cphysiz
 	    ncd = RELOC(ncfdev, int); ncd > 0; ncd--, cd++) {
 		int bd_type = cd->rom.type & (ERT_TYPEMASK | ERTF_MEMLIST);
 
+		/*
+		 * Hack to support p5bus and p5pb on CyberStorm Mk-III / PPC
+		 * and Blizzard PPC. XXX: this hack should only be active if
+		 * non-autoconfiguring CyberVision PPC or BlizzardVision PPC
+		 * was found. 
+		 */
+		if (cd->rom.manid == 8512 && 
+		    (cd->rom.prodid == 100 || cd->rom.prodid == 110)) 
+			RELOC(ZBUSAVAIL, u_int) += m68k_round_page(0x1400000);
+
 		if (bd_type != ERT_ZORROIII &&
 		    (bd_type != ERT_ZORROII || isztwopa(cd->addr)))
 			continue;	/* It's not Z2 or Z3 I/O board */
@@ -345,6 +355,7 @@ start_c(id, fphystart, fphysize, cphysiz
 		    (cd->rom.flags & ERT_Z3_SSMASK) == 0)
 			cd->size = 0x10000 <<
 			    ((cd->rom.type - 1) & ERT_MEMMASK);
+
 		RELOC(ZBUSAVAIL, u_int) += m68k_round_page(cd->size);
 	}
 

Index: src/sys/arch/amiga/conf/DRACO
diff -u src/sys/arch/amiga/conf/DRACO:1.148 src/sys/arch/amiga/conf/DRACO:1.149
--- src/sys/arch/amiga/conf/DRACO:1.148	Mon Dec 26 13:09:03 2011
+++ src/sys/arch/amiga/conf/DRACO	Tue Jan 10 20:29:49 2012
@@ -1,4 +1,4 @@
-# $NetBSD: DRACO,v 1.148 2011/12/26 13:09:03 mlelstv Exp $
+# $NetBSD: DRACO,v 1.149 2012/01/10 20:29:49 rkujawa Exp $
 #
 # This file was automatically created.
 # Changes will be lost when make is run in this directory.
@@ -29,7 +29,7 @@ include "arch/amiga/conf/std.amiga"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.148 $"
+#ident 		"GENERIC-$Revision: 1.149 $"
 
 
 maxusers	8

Index: src/sys/arch/amiga/conf/GENERIC
diff -u src/sys/arch/amiga/conf/GENERIC:1.278 src/sys/arch/amiga/conf/GENERIC:1.279
--- src/sys/arch/amiga/conf/GENERIC:1.278	Mon Dec 26 13:09:03 2011
+++ src/sys/arch/amiga/conf/GENERIC	Tue Jan 10 20:29:49 2012
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.278 2011/12/26 13:09:03 mlelstv Exp $
+# $NetBSD: GENERIC,v 1.279 2012/01/10 20:29:49 rkujawa Exp $
 #
 # This file was automatically created.
 # Changes will be lost when make is run in this directory.
@@ -29,7 +29,7 @@ include "arch/amiga/conf/std.amiga"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.278 $"
+#ident 		"GENERIC-$Revision: 1.279 $"
 
 
 maxusers	8
@@ -271,6 +271,8 @@ options        KFONT_CONS_ISO8859_1
 #options 	FONT_VT220L8x10
 #options	FONT_VT220ISO8x16
 
+p5bus0		at zbus0		# Phase5 CSPPC/BPPC internal bus
+
 grfcc0		at mainbus0		# custom chips
 grfrt0		at zbus0		# retina II
 grfrh0		at zbus0		# retina III
@@ -402,7 +404,7 @@ mgnsc0		at zbus0		# Magnum scsi
 scsibus*	at mgnsc0
 wesc0		at zbus0		# Warp Engine scsi
 scsibus*	at wesc0
-bppcsc0		at zbus0		# BlizzardPPC 603e+ scsi
+bppcsc0		at p5bus0		# BlizzardPPC 603e+ scsi
 scsibus*	at bppcsc0
 afsc0		at zbus0		# A4091 scsi
 scsibus*	at afsc0
@@ -420,7 +422,7 @@ cbsc0		at zbus0		# CyberSCSI I
 scsibus*	at cbsc0
 cbiisc0 	at zbus0		# CyberSCSI II
 scsibus*	at cbiisc0
-cbiiisc0 	at zbus0		# Cyberstorm mk.III/Cyberstorm PPC SCSI
+cbiiisc0 	at p5bus0		# Cyberstorm mk.III/Cyberstorm PPC SCSI
 scsibus*	at cbiiisc0
 empsc0		at zbus0		# Emplant scsi
 scsibus*	at empsc0
@@ -468,14 +470,20 @@ uk*	at scsibus? target ? lun ?	# scsi un
 # PCI bus support
 options		PCIVERBOSE              # verbose PCI device autoconfig messages
 #options	PCI_CONFIG_DUMP
-options		PCI_NETBSD_CONFIGURE
+options		PCI_NETBSD_CONFIGURE	# used only by mppb(4)
 
-p5pb0		at zbus0                # Phase5 PCI bridge (CVPPC/BVPPC)
+p5pb0		at p5bus0		# Phase5 PCI bridge (CVPPC/BVPPC/G-REX)
+p5membar*	at zbus0		# Phase5 PCI bridge autoconfiguring BARs
+#options	P5PB_OLD_FIRMWARE	# enable support for p5pb with old fw
+#options	P5PB_GENFB		# enable genfb support for CVPPC/BVPPC
+#options	P5PB_DEBUG		# enable excessive debug for p5pb
 pci*		at p5pb0
-mppb*           at zbus0                # Matay Prometheus Zorro-PCI bridge
+
+mppb*           at zbus0		# Matay Prometheus Zorro-PCI bridge
 pci*            at mppb?
 
-ne*             at pci?                 # NE2000 Ethernet
+#genfb*		at pci?			# generic fb, CVPPC/BVPPC only
+ne*             at pci?			# NE2000 Ethernet
 
 # Bluetooth Controller and Device support
 # tested only with btuart on an A1200

Index: src/sys/arch/amiga/conf/GENERIC.in
diff -u src/sys/arch/amiga/conf/GENERIC.in:1.90 src/sys/arch/amiga/conf/GENERIC.in:1.91
--- src/sys/arch/amiga/conf/GENERIC.in:1.90	Mon Dec 26 13:07:24 2011
+++ src/sys/arch/amiga/conf/GENERIC.in	Tue Jan 10 20:29:50 2012
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC.in,v 1.90 2011/12/26 13:07:24 mlelstv Exp $
+# $NetBSD: GENERIC.in,v 1.91 2012/01/10 20:29:50 rkujawa Exp $
 #
 ##
 # GENERIC machine description file
@@ -52,7 +52,7 @@ include "arch/amiga/conf/std.amiga"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.90 $"
+#ident 		"GENERIC-$Revision: 1.91 $"
 
 m4_ifdef(`INSTALL_CONFIGURATION', `m4_dnl
 makeoptions	COPTS="-Os"
@@ -329,6 +329,8 @@ m4_ifdef(`AMIGA_CONFIGURATION', `m4_dnl
 ')m4_dnl
 
 m4_ifdef(`AMIGA_CONFIGURATION', `m4_dnl
+p5bus0		at zbus0		# Phase5 CSPPC/BPPC internal bus
+
 grfcc0		at mainbus0		# custom chips
 grfrt0		at zbus0		# retina II
 ')m4_dnl
@@ -483,7 +485,7 @@ mgnsc0		at zbus0		# Magnum scsi
 scsibus*	at mgnsc0
 wesc0		at zbus0		# Warp Engine scsi
 scsibus*	at wesc0
-bppcsc0		at zbus0		# BlizzardPPC 603e+ scsi
+bppcsc0		at p5bus0		# BlizzardPPC 603e+ scsi
 scsibus*	at bppcsc0
 afsc0		at zbus0		# A4091 scsi
 scsibus*	at afsc0
@@ -501,7 +503,7 @@ cbsc0		at zbus0		# CyberSCSI I
 scsibus*	at cbsc0
 cbiisc0 	at zbus0		# CyberSCSI II
 scsibus*	at cbiisc0
-cbiiisc0 	at zbus0		# Cyberstorm mk.III/Cyberstorm PPC SCSI
+cbiiisc0 	at p5bus0		# Cyberstorm mk.III/Cyberstorm PPC SCSI
 scsibus*	at cbiiisc0
 empsc0		at zbus0		# Emplant scsi
 scsibus*	at empsc0
@@ -555,14 +557,20 @@ m4_ifdef(`AMIGA_CONFIGURATION', `m4_dnl
 # PCI bus support
 options		PCIVERBOSE              # verbose PCI device autoconfig messages
 #options	PCI_CONFIG_DUMP
-options		PCI_NETBSD_CONFIGURE
+options		PCI_NETBSD_CONFIGURE	# used only by mppb(4)
 
-p5pb0		at zbus0                # Phase5 PCI bridge (CVPPC/BVPPC)
+p5pb0		at p5bus0		# Phase5 PCI bridge (CVPPC/BVPPC/G-REX)
+p5membar*	at zbus0		# Phase5 PCI bridge autoconfiguring BARs
+#options	P5PB_OLD_FIRMWARE	# enable support for p5pb with old fw
+#options	P5PB_GENFB		# enable genfb support for CVPPC/BVPPC
+#options	P5PB_DEBUG		# enable excessive debug for p5pb
 pci*		at p5pb0
-mppb*           at zbus0                # Matay Prometheus Zorro-PCI bridge
+
+mppb*           at zbus0		# Matay Prometheus Zorro-PCI bridge
 pci*            at mppb?
 
-ne*             at pci?                 # NE2000 Ethernet
+#genfb*		at pci?			# generic fb, CVPPC/BVPPC only
+ne*             at pci?			# NE2000 Ethernet
 
 # Bluetooth Controller and Device support
 # tested only with btuart on an A1200

Index: src/sys/arch/amiga/conf/INSTALL
diff -u src/sys/arch/amiga/conf/INSTALL:1.100 src/sys/arch/amiga/conf/INSTALL:1.101
--- src/sys/arch/amiga/conf/INSTALL:1.100	Mon Dec 26 13:09:03 2011
+++ src/sys/arch/amiga/conf/INSTALL	Tue Jan 10 20:29:50 2012
@@ -1,4 +1,4 @@
-# $NetBSD: INSTALL,v 1.100 2011/12/26 13:09:03 mlelstv Exp $
+# $NetBSD: INSTALL,v 1.101 2012/01/10 20:29:50 rkujawa Exp $
 #
 # This file was automatically created.
 # Changes will be lost when make is run in this directory.
@@ -29,7 +29,7 @@ include "arch/amiga/conf/std.amiga"
 
 options 	INCLUDE_CONFIG_FILE	# embed config file in kernel binary
 
-#ident 		"GENERIC-$Revision: 1.100 $"
+#ident 		"GENERIC-$Revision: 1.101 $"
 
 makeoptions	COPTS="-Os"
 
@@ -225,6 +225,8 @@ options        KFONT_CONS_ISO8859_1
 #options 	FONT_VT220L8x10
 #options	FONT_VT220ISO8x16
 
+p5bus0		at zbus0		# Phase5 CSPPC/BPPC internal bus
+
 grfcc0		at mainbus0		# custom chips
 grfrt0		at zbus0		# retina II
 grfrh0		at zbus0		# retina III
@@ -348,7 +350,7 @@ mgnsc0		at zbus0		# Magnum scsi
 scsibus*	at mgnsc0
 wesc0		at zbus0		# Warp Engine scsi
 scsibus*	at wesc0
-bppcsc0		at zbus0		# BlizzardPPC 603e+ scsi
+bppcsc0		at p5bus0		# BlizzardPPC 603e+ scsi
 scsibus*	at bppcsc0
 afsc0		at zbus0		# A4091 scsi
 scsibus*	at afsc0
@@ -366,7 +368,7 @@ cbsc0		at zbus0		# CyberSCSI I
 scsibus*	at cbsc0
 cbiisc0 	at zbus0		# CyberSCSI II
 scsibus*	at cbiisc0
-cbiiisc0 	at zbus0		# Cyberstorm mk.III/Cyberstorm PPC SCSI
+cbiiisc0 	at p5bus0		# Cyberstorm mk.III/Cyberstorm PPC SCSI
 scsibus*	at cbiiisc0
 empsc0		at zbus0		# Emplant scsi
 scsibus*	at empsc0
@@ -412,14 +414,20 @@ ch*	at scsibus? target ? lun ?	# scsi au
 # PCI bus support
 options		PCIVERBOSE              # verbose PCI device autoconfig messages
 #options	PCI_CONFIG_DUMP
-options		PCI_NETBSD_CONFIGURE
+options		PCI_NETBSD_CONFIGURE	# used only by mppb(4)
 
-p5pb0		at zbus0                # Phase5 PCI bridge (CVPPC/BVPPC)
+p5pb0		at p5bus0		# Phase5 PCI bridge (CVPPC/BVPPC/G-REX)
+p5membar*	at zbus0		# Phase5 PCI bridge autoconfiguring BARs
+#options	P5PB_OLD_FIRMWARE	# enable support for p5pb with old fw
+#options	P5PB_GENFB		# enable genfb support for CVPPC/BVPPC
+#options	P5PB_DEBUG		# enable excessive debug for p5pb
 pci*		at p5pb0
-mppb*           at zbus0                # Matay Prometheus Zorro-PCI bridge
+
+mppb*           at zbus0		# Matay Prometheus Zorro-PCI bridge
 pci*            at mppb?
 
-ne*             at pci?                 # NE2000 Ethernet
+#genfb*		at pci?			# generic fb, CVPPC/BVPPC only
+ne*             at pci?			# NE2000 Ethernet
 
 # Bluetooth Controller and Device support
 # tested only with btuart on an A1200

Index: src/sys/arch/amiga/conf/files.amiga
diff -u src/sys/arch/amiga/conf/files.amiga:1.150 src/sys/arch/amiga/conf/files.amiga:1.151
--- src/sys/arch/amiga/conf/files.amiga:1.150	Thu Dec 15 14:25:12 2011
+++ src/sys/arch/amiga/conf/files.amiga	Tue Jan 10 20:29:50 2012
@@ -1,4 +1,4 @@
-#	$NetBSD: files.amiga,v 1.150 2011/12/15 14:25:12 phx Exp $
+#	$NetBSD: files.amiga,v 1.151 2012/01/10 20:29:50 rkujawa Exp $
 
 # maxpartitions must be first item in files.${ARCH}.newconf
 maxpartitions 16			# NOTE THAT AMIGA IS SPECIAL!
@@ -33,6 +33,10 @@ defflag				P5PPC68KBOARD
 defflag				LEV6_DEFER
 defflag				DEVRELOAD
 
+defflag opt_p5pb.h		P5PB_GENFB
+defflag opt_p5pb.h		P5PB_OLD_FIRMWARE
+defflag opt_p5pb.h		P5PB_DEBUG
+
 defparam			IOBZCLOCK
 
 device	mainbus {}
@@ -355,11 +359,6 @@ device	wesc: scsi, asiop
 attach	wesc at zbus
 file	arch/amiga/dev/wesc.c		wesc needs-flag
 
-# Phase5 Blizzard 603e+ SCSI
-device	bppcsc: scsi, asiop
-attach	bppcsc at zbus
-file	arch/amiga/dev/bppcsc.c		bppcsc needs-flag
-
 # C= A4091 & A4000T
 device	afsc: scsi, asiop
 attach	afsc at zbus
@@ -371,11 +370,6 @@ file	arch/amiga/dev/afsc.c		afsc | aftsc
 define	siopng
 file	arch/amiga/dev/siop2.c		siopng
 
-# CyberStorm MKIII scsi
-device	cbiiisc: scsi, siopng
-attach	cbiiisc at zbus
-file	arch/amiga/dev/cbiiisc.c	cbiiisc needs-flag
-
 # Emulex ESP216 & FAS216 controllers
 
 # FastlaneZ3
@@ -498,13 +492,32 @@ include "compat/ossaudio/files.ossaudio"
 # Bluetooth stack
 include "dev/bluetooth/files.bluetooth"
 
+# Phase5 BPPC/CSPPC internal bus
+device	p5bus {}
+attach	p5bus at zbus
+file	arch/amiga/dev/p5bus.c		p5bus
+
+device	p5membar {}
+attach	p5membar at zbus
+file	arch/amiga/pci/p5membar.c	p5membar
+
+# CyberStorm MKIII scsi
+device	cbiiisc: scsi, siopng
+attach	cbiiisc at p5bus 
+file	arch/amiga/dev/cbiiisc.c	cbiiisc needs-flag
+
+# Phase5 Blizzard 603e+ SCSI
+device	bppcsc: scsi, asiop
+attach	bppcsc at p5bus 
+file	arch/amiga/dev/bppcsc.c		bppcsc needs-flag
+
 # PCI bus
 file	arch/amiga/pci/p5pb.c		pci
 file	arch/amiga/pci/mppb.c		pci
 file	arch/amiga/pci/pci_machdep.c	pci
 
 device	p5pb: pcibus
-attach	p5pb at zbus
+attach	p5pb at p5bus 
 
 device	mppb: pcibus
 attach	mppb at zbus

Index: src/sys/arch/amiga/dev/bppcsc.c
diff -u src/sys/arch/amiga/dev/bppcsc.c:1.1 src/sys/arch/amiga/dev/bppcsc.c:1.2
--- src/sys/arch/amiga/dev/bppcsc.c:1.1	Fri Jan 14 10:01:12 2011
+++ src/sys/arch/amiga/dev/bppcsc.c	Tue Jan 10 20:29:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: bppcsc.c,v 1.1 2011/01/14 10:01:12 phx Exp $ */
+/*	$NetBSD: bppcsc.c,v 1.2 2012/01/10 20:29:50 rkujawa Exp $ */
 
 /*
  * Copyright (c) 1982, 1990 The Regents of the University of California.
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bppcsc.c,v 1.1 2011/01/14 10:01:12 phx Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bppcsc.c,v 1.2 2012/01/10 20:29:50 rkujawa Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -79,6 +79,7 @@ __KERNEL_RCSID(0, "$NetBSD: bppcsc.c,v 1
 #include <amiga/dev/siopreg.h>
 #include <amiga/dev/siopvar.h>
 #include <amiga/dev/zbusvar.h>
+#include <amiga/dev/p5busvar.h>
 
 #define BPPC_SCSI_OFF	0xf40000
 #define BPPC_PUPROM_OFF	0xf00010
@@ -99,15 +100,13 @@ CFATTACH_DECL(bppcsc, sizeof(struct siop
 int
 bppcscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
 {
-	struct zbus_args *zap;
-	char *p5type; 
+	struct p5bus_attach_args *p5baa;
+
+	p5baa = (struct p5bus_attach_args *) auxp;
+
+	if (strcmp(p5baa->p5baa_name, "bppcsc") == 0)
+		return 1;
 
-	zap = auxp;
-	if (zap->manid == 8512 && zap->prodid == 110) {
-		p5type = (char *)__UNVOLATILE(ztwomap(BPPC_PUPROM_OFF));
-		if (p5type[0] == 'I')		/* only "+" model has SCSI */
-			return 1;
-	}
 	return 0 ;
 }
 

Index: src/sys/arch/amiga/dev/cbiiisc.c
diff -u src/sys/arch/amiga/dev/cbiiisc.c:1.19 src/sys/arch/amiga/dev/cbiiisc.c:1.20
--- src/sys/arch/amiga/dev/cbiiisc.c:1.19	Mon Dec 20 00:25:25 2010
+++ src/sys/arch/amiga/dev/cbiiisc.c	Tue Jan 10 20:29:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cbiiisc.c,v 1.19 2010/12/20 00:25:25 matt Exp $ */
+/*	$NetBSD: cbiiisc.c,v 1.20 2012/01/10 20:29:50 rkujawa Exp $ */
 
 /*
  * Copyright (c) 1982, 1990 The Regents of the University of California.
@@ -58,7 +58,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cbiiisc.c,v 1.19 2010/12/20 00:25:25 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cbiiisc.c,v 1.20 2012/01/10 20:29:50 rkujawa Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -79,6 +79,7 @@ __KERNEL_RCSID(0, "$NetBSD: cbiiisc.c,v 
 #include <amiga/dev/siopreg.h>
 #include <amiga/dev/siopvar.h>
 #include <amiga/dev/zbusvar.h>
+#include <amiga/dev/p5busvar.h>
 
 void cbiiiscattach(struct device *, struct device *, void *);
 int  cbiiiscmatch(struct device *, struct cfdata *, void *);
@@ -99,26 +100,25 @@ CFATTACH_DECL(cbiiisc, sizeof(struct sio
 int
 cbiiiscmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
 {
-	struct zbus_args *zap;
+	struct p5bus_attach_args *p5baa;
 
-	zap = auxp;
-	if (zap->manid == 8512 && zap->prodid == 100)
-		return(1);
-	return(0);
+	p5baa = (struct p5bus_attach_args *) auxp;
+
+	if (strcmp(p5baa->p5baa_name, "cbiiisc") == 0)
+		return 1;
+
+	return 0;
 }
 
 void
 cbiiiscattach(struct device *pdp, struct device *dp, void *auxp)
 {
 	struct siop_softc *sc = (struct siop_softc *)dp;
-	struct zbus_args *zap;
 	siop_regmap_p rp;
         struct scsipi_adapter *adapt = &sc->sc_adapter;
         struct scsipi_channel *chan = &sc->sc_channel;
 
-	printf("\n");
-
-	zap = auxp;
+	aprint_normal(": CyberStorm PPC/Mk-III SCSI host adapter\n");
 
 	sc->sc_siopp = rp = ztwomap(0xf40000);
 	/* siopng_dump_registers(sc); */

Index: src/sys/arch/amiga/pci/p5pb.c
diff -u src/sys/arch/amiga/pci/p5pb.c:1.4 src/sys/arch/amiga/pci/p5pb.c:1.5
--- src/sys/arch/amiga/pci/p5pb.c:1.4	Fri Oct  7 23:08:33 2011
+++ src/sys/arch/amiga/pci/p5pb.c	Tue Jan 10 20:29:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: p5pb.c,v 1.4 2011/10/07 23:08:33 rkujawa Exp $ */
+/*	$NetBSD: p5pb.c,v 1.5 2012/01/10 20:29:50 rkujawa Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -37,6 +37,7 @@
 #include <sys/device.h>
 #include <sys/malloc.h>
 #include <sys/extent.h>
+#include <sys/kmem.h>
 
 #include <uvm/uvm_extern.h>
 
@@ -45,52 +46,22 @@
 
 #include <m68k/bus_dma.h>
 #include <amiga/dev/zbusvar.h>
+#include <amiga/dev/p5busvar.h>
 #include <amiga/pci/p5pbreg.h>
 #include <amiga/pci/p5pbvar.h>
+#include <amiga/pci/p5membarvar.h>
 
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcidevs.h>
 #include <dev/pci/pciconf.h>
 
-/* Zorro IDs */
-#define ZORRO_MANID_P5		8512
-#define ZORRO_PRODID_BPPC	110		/* BlizzardPPC */
-#define ZORRO_PRODID_CSPPC	100		/* CyberStormPPC */
-#define ZORRO_PRODID_P5PB	101		/* CVPPC/BVPPC/G-REX */
-#define ZORRO_PRODID_CV643D_Z3	67		/* CV64/3D */
-
 /* Initial CVPPC/BVPPC resolution as configured by the firmware */
 #define P5GFX_WIDTH		640
 #define P5GFX_HEIGHT		480
 #define P5GFX_DEPTH		8
 #define P5GFX_LINEBYTES		640
 
-/* #define P5PB_MATCH_CV643D	1 */
-/* #define P5PB_DEBUG		1 */
-
-static struct p5pb_bridge_type p5pb_bridge_cvppc = {
-	"Phase5 CVPPC/BVPPC PCI bridge",
-	false,
-	true,
-	1,
-};
-
-static struct p5pb_bridge_type p5pb_bridge_cv643d = {
-	"Phase5 CyberVision 64/3D PCI bridge",
-	false,
-	false,
-	1,
-};
-
-/* const struct p5pb_bridge_type p5pb_bridge_grex {
-	"DCE Computer G-REX PCI bridge",
-	true,
-	false,
-	5
-}
-*/
-
 static int	p5pb_match(struct device *, struct cfdata *, void *);
 static void	p5pb_attach(struct device *, struct device *, void *);
 void		p5pb_set_props(struct p5pb_softc *sc);
@@ -107,63 +78,25 @@ void		p5pb_pci_decompose_tag(pci_chipset
 		    int *bp, int *dp, int *fp);
 int		p5pb_pci_intr_map(const struct pci_attach_args *pa, 
 		    pci_intr_handle_t *ihp);
-bool	p5pb_bus_map_cv643d(struct p5pb_softc *sc);
-static bool	p5pb_bus_map_cvppc(struct p5pb_softc *sc);
+bool		p5pb_bus_map_cvppc(struct p5pb_softc *sc);
+bool		p5pb_bus_map_grex(struct p5pb_softc *sc);
+bool		p5pb_bus_map_common(struct p5pb_softc *sc);
+uint8_t		p5pb_find_resources(struct p5pb_softc *sc);
 
 CFATTACH_DECL_NEW(p5pb, sizeof(struct p5pb_softc),
     p5pb_match, p5pb_attach, NULL, NULL);
 
-static int p5pb_present = 0;
-
 static int
 p5pb_match(device_t parent, cfdata_t cf, void *aux)
 {
-	struct zbus_args *zap;
-
-	zap = aux;
-
-	if (zap->manid != ZORRO_MANID_P5)
-		return 0;
-
-#ifdef I_HAVE_P5PB_REALLY
-	/* 
-	 * At least some firmware versions do not create AutoConfig entries for 
-	 * CyberVisionPPC/BlizzardVisionPPC (product ID 0101). There's no "nice"
-	 * way to detect the PCI bus in this case. At least check for CSPPC/BPPC.
-         */
-	if ((zap->prodid != ZORRO_PRODID_BPPC) && 
-	    (zap->prodid != ZORRO_PRODID_CSPPC)) {
-		if (!p5pb_present) {
-			p5pb_present = 1;
-			return 100; /* XXX: This will break SCSI! */
-		}
-	}
-#endif 
+	struct p5bus_attach_args *p5baa;
 
-	if ((zap->prodid != ZORRO_PRODID_P5PB)
-#ifdef P5PB_MATCH_CV643D
-	/*
-	 * This should not be used now, because CV64/3D grf driver does
-	 * attach directly to Zorro bus. Might get useful if we ever get
-	 * virgefb..
-	 */
-		&& (zap->prodid != ZORRO_PRODID_CV643D_Z3)
-
-#endif
-	    )
-		return 0;
-		
-#ifdef P5PB_DEBUG
-	aprint_normal("p5pb matched by Zorro ID %d, %d\n", zap->manid,
-	    zap->prodid); 
-#endif
+	p5baa = (struct p5bus_attach_args *) aux;
 
-	if (p5pb_present)
-		return 0; /* Allow only one. */
+	if (strcmp(p5baa->p5baa_name, "p5pb") == 0)
+		return 1;
 
-
-	p5pb_present = 1;
-	return 10;
+	return 0;
 }
 
 
@@ -172,35 +105,40 @@ p5pb_attach(device_t parent, device_t se
 {
 	struct p5pb_softc *sc; 
 	struct pcibus_attach_args pba;  
-	struct p5pb_bridge_type *bt;
-	struct zbus_args *zap;
 
 	sc = device_private(self);
 	pci_chipset_tag_t pc = &sc->apc;
 	sc->sc_dev = self;
-	zap = aux;
-	
-	if(zap->prodid == ZORRO_PRODID_CV643D_Z3) {
-		bt = &p5pb_bridge_cv643d;
-		sc->p5pb_bus_map = &p5pb_bus_map_cv643d;
-		sc->ba = zap->va;
+
+	if (p5pb_find_resources(sc) > 0) {
+		sc->p5pb_bus_map = &p5pb_bus_map_grex;
 	} else {
-		bt = &p5pb_bridge_cvppc;
-		sc->p5pb_bus_map = p5pb_bus_map_cvppc;
+#ifdef P5PB_OLD_FIRMWARE
+		sc->p5pb_bus_map = &p5pb_bus_map_cvppc;
+#else
+		aprint_normal(": no PCI bridges detected\n");
+		return;
+#endif /* P5PB_OLD_FIRMWARE */
 	}
 
-	if(!(sc->p5pb_bus_map(sc))) {
+	aprint_normal(": Phase5 CVPPC/BVPPC/G-REX PCI bridge\n");
+
+	if(!p5pb_bus_map_common(sc)) {
 		aprint_error_dev(self,
-		    "couldn't map PCI configuration registers\n");
+		    "couldn't map PCI configuration and I/O spaces\n");
 		return;
 	}
 
-	aprint_normal(": %s\n", bt->name); 
+	if(!(sc->p5pb_bus_map(sc))) {
+		aprint_error_dev(self,
+		    "couldn't map PCI memory space\n");
+		return;
+	}
 
 #ifdef P5PB_DEBUG
 	aprint_normal("p5pb: mapped %x -> %x, %x -> %x\n, %x -> %x\n",
 	    P5BUS_PCI_CONF_BASE, sc->pci_conf_area.base,
-	    P5BUS_PCI_IO_BASE, sc->pci_conf_area.base,
+	    P5BUS_PCI_IO_BASE, sc->pci_io_area.base,
 	    P5BUS_PCI_MEM_BASE, sc->pci_mem_area.base ); 
 #endif 
 
@@ -227,11 +165,54 @@ p5pb_attach(device_t parent, device_t se
 	pba.pba_bus = 0;
 	pba.pba_bridgetag = NULL;
 
+#ifdef P5PB_GENFB
 	p5pb_set_props(sc);
+#endif /* P5PB_GENFB */
 
 	config_found_ia(self, "pcibus", &pba, pcibusprint);
 }
 
+/* 
+ * Find autoconfigured resuorces (for boards running G-REX firmware). Return the
+ * total number of found resources.
+ */
+uint8_t
+p5pb_find_resources(struct p5pb_softc *sc) 
+{
+	uint8_t i, rv;
+	struct p5pb_autoconf_entry *auto_entry;
+	struct p5membar_softc *membar_sc;
+	device_t p5membar_dev;
+	
+	rv = 0;
+
+	TAILQ_INIT(&sc->auto_bars);
+
+	/* 255 should be enough for everybody */
+	for(i = 0; i < 255; i++) {
+
+		if ((p5membar_dev = 
+		    device_find_by_driver_unit("p5membar", i)) != NULL) {
+
+			rv++;
+
+			membar_sc = device_private(p5membar_dev);
+			if (membar_sc->sc_type == P5MEMBAR_TYPE_INTERNAL)
+				continue;
+
+			auto_entry = 
+			    kmem_alloc(sizeof(struct p5pb_autoconf_entry), 
+			    KM_SLEEP);
+
+			auto_entry->base = membar_sc->sc_base;
+			auto_entry->size = membar_sc->sc_size;
+
+			TAILQ_INSERT_TAIL(&sc->auto_bars, auto_entry, entries);
+		}
+	}	
+	return rv;	
+}
+
 /*
  * Set properties needed to support fb driver. These are read later during
  * autoconfg in device_register().
@@ -298,7 +279,7 @@ p5pb_pci_conf_write(pci_chipset_tag_t pc
 int
 p5pb_pci_bus_maxdevs(pci_chipset_tag_t pc, int busno) 
 {
-	/* G-Rex has max 5 slots. CVPPC/BVPPC has only 1. */
+	/* G-REX has max 5 slots. CVPPC/BVPPC has only 1. */
 	return 1;
 }
 
@@ -317,13 +298,48 @@ p5pb_pci_intr_map(const struct pci_attac
 	return 0;
 }
 
-static bool
-p5pb_bus_map_cvppc(struct p5pb_softc *sc) 
+/* PCI memory mapping done G-REX-style. */
+bool
+p5pb_bus_map_grex(struct p5pb_softc *sc)
 {
+	struct p5pb_autoconf_entry *membar_entry;
+	bus_addr_t bar_address;
+	bus_addr_t pci_mem_highest;
+
+	pci_mem_highest = P5BUS_PCI_MEM_BASE;
+
 #ifdef P5PB_DEBUG
-	aprint_normal("p5pb: p5pb_bus_map_cvppc called\n");
+	aprint_normal("p5pb: p5pb_bus_map_grex called\n");
+#endif /* P5PB_DEBUG */
+
+	/* Determine the highest address used by any PCI card. */
+	TAILQ_FOREACH(membar_entry, &sc->auto_bars, entries) {
+
+		bar_address = (bus_addr_t) membar_entry->base;
+		if ((bar_address + membar_entry->size) > pci_mem_highest)
+			pci_mem_highest = bar_address + membar_entry->size;
+
+#ifdef P5PB_DEBUG
+		aprint_normal("p5pb: memory BAR at %p, highest address %x\n", 
+		    membar_entry->base, pci_mem_highest);
+#endif /* P5PB_DEBUG */
+	}
+
+	sc->pci_mem_area.base = (bus_addr_t) zbusmap(
+	    (void *) P5BUS_PCI_MEM_BASE, pci_mem_highest - P5BUS_PCI_MEM_BASE);
+	sc->pci_mem_area.absm = &amiga_bus_stride_1swap_abs;
+
+	return true;
+}
+
+/* Map things common for all supported bridges. */
+bool
+p5pb_bus_map_common(struct p5pb_softc *sc)
+{
+#ifdef P5PB_DEBUG
+	aprint_normal("p5pb: p5pb_bus_map_common called\n");
 #endif /* P5PB_DEBUG */
-	/* Setup bus space mappings. */
+
 	sc->pci_conf_area.base = (bus_addr_t) zbusmap(
 	    (void *) P5BUS_PCI_CONF_BASE, P5BUS_PCI_CONF_SIZE);
 	sc->pci_conf_area.absm = &amiga_bus_stride_1;
@@ -332,47 +348,32 @@ p5pb_bus_map_cvppc(struct p5pb_softc *sc
 	    (void *) P5BUS_PCI_IO_BASE, P5BUS_PCI_IO_SIZE);
 	sc->pci_io_area.absm = &amiga_bus_stride_1swap_abs;
 
-	sc->pci_mem_area.base = (bus_addr_t) zbusmap(
-	    (void *) P5BUS_PCI_MEM_BASE, P5BUS_PCI_MEM_SIZE);
-	sc->pci_mem_area.absm = &amiga_bus_stride_1swap_abs;
-	
 	sc->apc.pci_conf_datat = &(sc->pci_conf_area);
 	sc->apc.pci_conf_addresst = &(sc->pci_conf_area);
 
-	if (bus_space_map(sc->apc.pci_conf_addresst, OFF_PCI_CONF_ADDR, 
-	    256, 0, &sc->apc.pci_conf_addressh)) 
-		return false;
-
 	if (bus_space_map(sc->apc.pci_conf_datat, OFF_PCI_CONF_DATA, 
 	    256, 0, &sc->apc.pci_conf_datah)) 
 		return false;
 
+	/* XXX */
+	/* if (bus_space_map(sc->apc.pci_conf_addresst, OFF_PCI_CONF_ADDR, 
+	    256, 0, &sc->apc.pci_conf_addressh)) 
+		return false; */
+
 	return true;
 }
 
+/* Hard-coded memory mapping for CVPPC/BVPPC (without G-REX firmware). */
 bool
-p5pb_bus_map_cv643d(struct p5pb_softc *sc) {
+p5pb_bus_map_cvppc(struct p5pb_softc *sc) 
+{
 #ifdef P5PB_DEBUG
-	aprint_normal("p5pb: p5pb_bus_map_cv643d called, ba = %x\n", 
-	    (bus_addr_t) sc->ba);
+	aprint_normal("p5pb: p5pb_bus_map_cvppc called\n");
 #endif /* P5PB_DEBUG */
+	sc->pci_mem_area.base = (bus_addr_t) zbusmap(
+	    (void *) P5BUS_PCI_MEM_BASE, P5BUS_PCI_MEM_SIZE);
+	sc->pci_mem_area.absm = &amiga_bus_stride_1swap_abs;
 
-	sc->pci_conf_area.base = (bus_addr_t) sc->ba + CV643D_PCI_CONF_BASE;
-	sc->pci_conf_area.absm = &amiga_bus_stride_1;
-
-	sc->pci_mem_area.base = (bus_addr_t) sc->ba + CV643D_PCI_MEM_BASE; 
-	sc->pci_mem_area.absm = &amiga_bus_stride_1;
-
-	sc->pci_io_area.base = (bus_addr_t) sc->ba + CV643D_PCI_IO_BASE;
-	sc->pci_io_area.absm = &amiga_bus_stride_1;
-
-	sc->apc.pci_conf_datat = &(sc->pci_conf_area);
-
-	if (bus_space_map(sc->apc.pci_conf_datat, 0, 
-	    CV643D_PCI_CONF_SIZE, 0, &sc->apc.pci_conf_datah)) 
-		return false;
-
-		
 	return true;
 }
 

Index: src/sys/arch/amiga/pci/p5pbreg.h
diff -u src/sys/arch/amiga/pci/p5pbreg.h:1.3 src/sys/arch/amiga/pci/p5pbreg.h:1.4
--- src/sys/arch/amiga/pci/p5pbreg.h:1.3	Fri Oct  7 08:44:21 2011
+++ src/sys/arch/amiga/pci/p5pbreg.h	Tue Jan 10 20:29:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: p5pbreg.h,v 1.3 2011/10/07 08:44:21 rkujawa Exp $ */
+/*	$NetBSD: p5pbreg.h,v 1.4 2012/01/10 20:29:50 rkujawa Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -58,10 +58,13 @@
 #define P5BUS_PCI_IO_BASE	0xFFFA0000
 #define P5BUS_PCI_IO_SIZE	0x0000FFFF
 
+#define P5BUS_PCI_BRIDGE_BASE	0xFFFE0000
+#define P5BUS_PCI_BRIDGE_SIZE	0x0000FFFF	/* 4kB on some fw revs */
+
 #define OFF_PCI_CONF_DATA	0x00000000 
 #define OFF_PCI_CONF_ADDR	0x00020000
 
-#define P5BUS_CONF_ENDIAN	0x0000          /* PCI_CONF_ADDR + offset */
+#define P5BUS_CONF_ENDIAN	0x0000          /* PCI_BRIDGE_BASE + offset */
 #define P5BUS_CONF_ENDIAN_BIG	0x02            /* to switch into BE mode */
 #define P5BUS_CONF_INTR		0x0010          /* ? XXX interrupt enable? */
 #define P5BUS_CONF_INTR_INT2	0x01            /* ? XXX INT2? */

Index: src/sys/arch/amiga/pci/p5pbvar.h
diff -u src/sys/arch/amiga/pci/p5pbvar.h:1.1 src/sys/arch/amiga/pci/p5pbvar.h:1.2
--- src/sys/arch/amiga/pci/p5pbvar.h:1.1	Fri Oct  7 08:44:21 2011
+++ src/sys/arch/amiga/pci/p5pbvar.h	Tue Jan 10 20:29:50 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: p5pbvar.h,v 1.1 2011/10/07 08:44:21 rkujawa Exp $ */
+/*	$NetBSD: p5pbvar.h,v 1.2 2012/01/10 20:29:50 rkujawa Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -36,23 +36,26 @@
 #include <dev/pci/pciconf.h>
 #include <machine/pci_machdep.h>
 
-struct p5pb_bridge_type {
-	const char	*name;		/* descriptive name */
-	bool		configure_bus;	/* should we configure the bus? */
-	bool		set_genfb_props;/* should we set props for genfb(4)? */
-	int		maxdevs;	/* max number of devices on the bus */
+struct p5pb_autoconf_entry {
+	volatile char	*base;
+	uint32_t	size;
+	TAILQ_ENTRY(p5pb_autoconf_entry) entries;
 };
 
 struct p5pb_softc {
-	device_t sc_dev;
-	volatile char *ba;
-	struct bus_space_tag pci_conf_area;
-	struct bus_space_tag pci_mem_area;
-	struct bus_space_tag pci_io_area;
-	struct amiga_pci_chipset apc;
-	struct p5pb_bridge_type bridge_type;
-	bool	(*p5pb_bus_map)(struct p5pb_softc *);
-};
+	device_t				sc_dev;
+
+	volatile char				*ba;
+	struct bus_space_tag			pci_conf_area;
+	struct bus_space_tag			pci_mem_area;
+	struct bus_space_tag			pci_io_area;
+	struct amiga_pci_chipset		apc;
+
+	/* list of preconfigured BARs */
+	TAILQ_HEAD(, p5pb_autoconf_entry)	auto_bars;
 
+	bool(*p5pb_bus_map)(struct p5pb_softc *);
+
+};
 
 #endif /* _AMIGA_P5PBVAR_H_ */

Added files:

Index: src/sys/arch/amiga/dev/p5bus.c
diff -u /dev/null src/sys/arch/amiga/dev/p5bus.c:1.1
--- /dev/null	Tue Jan 10 20:29:50 2012
+++ src/sys/arch/amiga/dev/p5bus.c	Tue Jan 10 20:29:50 2012
@@ -0,0 +1,209 @@
+/*      $NetBSD: p5bus.c,v 1.1 2012/01/10 20:29:50 rkujawa Exp $ */
+
+/*-
+ * Copyright (c) 2011, 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Radoslaw Kujawa.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/* Driver for internal BlizzardPPC, CyberStorm Mk-III/PPC bus. */
+
+#include <sys/cdefs.h>
+
+#include <sys/systm.h>
+#include <sys/types.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+
+#include <amiga/dev/zbusvar.h>
+#include <amiga/dev/p5busvar.h>
+
+#define ZORRO_MANID_P5		8512
+#define ZORRO_PRODID_CSPPC	100 
+#define ZORRO_PRODID_BPPC	110
+
+#define P5_ROM_OFF		0xF00010
+#define P5_SN_LEN		7
+
+static int	p5bus_match(struct device *pdp, struct cfdata *cfp, void *auxp);
+static void	p5bus_attach(device_t parent, device_t self, void *aux);
+static char*	p5bus_cardsn(void);
+static int	p5bus_print(void *aux, const char *str);
+static void	p5bus_callback(device_t self);
+
+struct p5bus_softc {
+	device_t	sc_dev;
+	uint8_t		sc_cardtype;
+	uint8_t		sc_has_scsi;
+#define P5BUS_SCSI_NONE	0
+#define P5BUS_SCSI_710		1	/* NCR 53C710 */
+#define P5BUS_SCSI_770		2	/* NCR 53C770 */
+	uint8_t		sc_has_ppc;
+#define P5BUS_PPC_NONE		0	/* CS Mk-III only */
+#define P5BUS_PPC_OK		1	/* has working PPC CPU */
+	uint8_t		sc_has_pci;
+#define P5BUS_PCI_NONE		0
+#define P5BUS_PCI_CVPPC	1	/* CyberVisionPPC / BlizzardVisionPPC */
+#define P5BUS_PCI_GREX		2	/* G-REX (not yet) */
+};
+
+CFATTACH_DECL_NEW(p5bus, sizeof(struct p5bus_softc),
+    p5bus_match, p5bus_attach, NULL, NULL);
+
+static int
+p5bus_match(struct device *pdp, struct cfdata *cfp, void *auxp)
+{
+	struct zbus_args *zap;
+
+	zap = auxp;
+
+	if (zap->manid != ZORRO_MANID_P5) 
+		return 0;
+
+
+	if ((zap->prodid != ZORRO_PRODID_BPPC) && 
+	    (zap->prodid != ZORRO_PRODID_CSPPC)) 
+		return 0;
+
+	return 1;
+}
+
+static void
+p5bus_attach(device_t parent, device_t self, void *aux)
+{
+	struct p5bus_softc *sc;
+	struct zbus_args *zap;
+	struct p5bus_attach_args p5baa;
+	char *sn;
+
+	zap = aux;
+	sc = device_private(self);
+	sc->sc_dev = self;
+
+	sn = p5bus_cardsn();
+
+	aprint_normal(": Phase5 PowerUP on-board bus\n");
+
+	/* "Detect" what devices are present and attach the right drivers. */
+
+	if (zap->prodid == ZORRO_PRODID_CSPPC) {
+
+		if (sn[0] == 'F') {
+			aprint_normal_dev(sc->sc_dev, 
+			    "CyberStorm Mk-III (sn %s)\n", sn);
+			sc->sc_has_ppc = P5BUS_PPC_NONE;
+		} else {
+			aprint_normal_dev(sc->sc_dev, 
+			    "CyberStorm PPC 604e (sn %s)\n", sn);
+			sc->sc_has_ppc = P5BUS_PPC_OK;
+		}
+
+		sc->sc_cardtype = P5_CARDTYPE_CS;
+		sc->sc_has_scsi = P5BUS_SCSI_770;
+	
+	} else if (zap->prodid == ZORRO_PRODID_BPPC) {
+
+		if (sn[0] == 'I') {	/* only "+" model has SCSI */
+			aprint_normal_dev(sc->sc_dev, 
+			    "BlizzardPPC 603e (sn %s)\n", sn);
+			sc->sc_has_scsi = P5BUS_SCSI_NONE;
+		} else {
+			aprint_normal_dev(sc->sc_dev, 
+			    "BlizzardPPC 603e+ (sn %s)\n", sn);
+			sc->sc_has_scsi = P5BUS_SCSI_710;
+		}
+	
+		sc->sc_cardtype = P5_CARDTYPE_BPPC;	
+		sc->sc_has_ppc = P5BUS_PPC_OK;
+
+	}
+
+	sc->sc_has_pci = P5BUS_PCI_CVPPC; /* XXX: insert probe here? */
+
+	p5baa.p5baa_cardtype = sc->sc_cardtype;
+
+	/* Attach the SCSI host adapters. */
+	switch (sc->sc_has_scsi) {
+	case P5BUS_SCSI_710:
+		strcpy(p5baa.p5baa_name, "bppcsc");
+		config_found_ia(sc->sc_dev, "p5bus", &p5baa, p5bus_print);
+		break;
+	case P5BUS_SCSI_770:
+		strcpy(p5baa.p5baa_name, "cbiiisc");
+		config_found_ia(sc->sc_dev, "p5bus", &p5baa, p5bus_print);
+		break;
+	default:
+		break;
+	}
+
+	/*
+	 * We need to wait for possible p5membar attachments. Defer the rest 
+	 * until parent (zbus) is completely configured. 
+	 */
+	config_defer(self, p5bus_callback);
+
+}
+
+/* Continue the attachment. */
+static void
+p5bus_callback(device_t self) {
+
+	struct p5bus_attach_args p5baa;
+	struct p5bus_softc *sc;
+
+	sc = device_private(self);
+	p5baa.p5baa_cardtype = sc->sc_cardtype;
+
+	if (sc->sc_has_pci) {
+		strcpy(p5baa.p5baa_name, "p5pb");
+		config_found_ia(sc->sc_dev, "p5bus", &p5baa, p5bus_print);
+	}
+}
+
+/* Get serial number of the card. */
+static char * 
+p5bus_cardsn()
+{
+	char *snr, *sn;
+
+	sn = kmem_zalloc(P5_SN_LEN + 1, KM_SLEEP);
+	snr = (char *)__UNVOLATILE(ztwomap(P5_ROM_OFF));
+
+	memcpy(sn, snr, P5_SN_LEN);
+	return sn;
+}
+
+static int
+p5bus_print(void *aux, const char *str)
+{
+	if (str == NULL)
+		return 0;
+
+	printf("%s ", str);
+
+	return 0;
+}
+
Index: src/sys/arch/amiga/dev/p5busvar.h
diff -u /dev/null src/sys/arch/amiga/dev/p5busvar.h:1.1
--- /dev/null	Tue Jan 10 20:29:50 2012
+++ src/sys/arch/amiga/dev/p5busvar.h	Tue Jan 10 20:29:50 2012
@@ -0,0 +1,41 @@
+/*      $NetBSD: p5busvar.h,v 1.1 2012/01/10 20:29:50 rkujawa Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Radoslaw Kujawa.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+
+#define P5_CARDTYPE_CS		1	/* CyberStorm PPC/Mk-III */
+#define P5_CARDTYPE_BPPC	2	/* BlizzardPPC */
+
+struct p5bus_attach_args {
+	char	p5baa_name[32];
+	uint8_t	p5baa_cardtype; 
+};
+

Index: src/sys/arch/amiga/pci/p5membar.c
diff -u /dev/null src/sys/arch/amiga/pci/p5membar.c:1.1
--- /dev/null	Tue Jan 10 20:29:50 2012
+++ src/sys/arch/amiga/pci/p5membar.c	Tue Jan 10 20:29:50 2012
@@ -0,0 +1,120 @@
+/*	$NetBSD: p5membar.c,v 1.1 2012/01/10 20:29:50 rkujawa Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Radoslaw Kujawa.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Handle autoconfigured PCI resources on some revisions of CyberVision PPC,
+ * BlizzardVision PPC graphics cards and all G-REX PCI busboards. 
+ */
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/time.h>
+#include <sys/systm.h>
+#include <sys/errno.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/extent.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/bus.h>
+#include <machine/cpu.h>
+
+#include <m68k/bus_dma.h>
+#include <amiga/dev/zbusvar.h>
+#include <amiga/pci/p5pbreg.h>
+#include <amiga/pci/p5pbvar.h>
+#include <amiga/pci/p5membarvar.h>
+
+/* Zorro IDs */
+#define ZORRO_MANID_P5		8512
+#define ZORRO_PRODID_P5PB	101		/* CVPPC/BVPPC/G-REX */
+
+static int	p5membar_match(struct device *, struct cfdata *, void *);
+static void	p5membar_attach(struct device *, struct device *, void *);
+
+CFATTACH_DECL_NEW(p5membar, sizeof(struct p5membar_softc),
+    p5membar_match, p5membar_attach, NULL, NULL);
+
+static int
+p5membar_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct zbus_args *zap;
+
+	zap = aux;
+
+	if (zap->manid != ZORRO_MANID_P5)
+		return 0;
+
+	if (zap->prodid != ZORRO_PRODID_P5PB)
+		return 0;
+
+	return 1;
+}
+
+static void
+p5membar_attach(device_t parent, device_t self, void *aux)
+{
+	struct zbus_args *zap;
+	struct p5membar_softc *sc;
+
+	sc = device_private(self); 
+	zap = aux;
+
+	sc->sc_dev = self;
+	sc->sc_base = zap->pa;
+	sc->sc_size = zap->size;
+
+	if ((bus_addr_t) zap->pa == P5BUS_PCI_CONF_BASE) {
+		aprint_normal(": PCI config area, %d kB\n",
+		    zap->size / 1024);
+		sc->sc_type = P5MEMBAR_TYPE_INTERNAL;
+	} else if ((bus_addr_t) zap->pa == P5BUS_PCI_IO_BASE) {
+		aprint_normal(": PCI I/O area, %d kB\n",
+		    zap->size / 1024);
+		sc->sc_type = P5MEMBAR_TYPE_INTERNAL;
+	} else if ((bus_addr_t) zap->pa == P5BUS_PCI_BRIDGE_BASE) {
+		aprint_normal(": PCI bridge, %d kB\n",
+		    zap->size / 1024);
+		sc->sc_type = P5MEMBAR_TYPE_INTERNAL;
+	} else {
+		aprint_normal(": PCI memory BAR, %d kB\n",
+		    zap->size / 1024);
+		sc->sc_type = P5MEMBAR_TYPE_MEMORY;
+	}
+
+	/*
+	 * Do nothing here, p5pb should find the p5membar devices
+	 * and do the right(tm) thing. 
+	 */
+
+}
+
Index: src/sys/arch/amiga/pci/p5membarvar.h
diff -u /dev/null src/sys/arch/amiga/pci/p5membarvar.h:1.1
--- /dev/null	Tue Jan 10 20:29:50 2012
+++ src/sys/arch/amiga/pci/p5membarvar.h	Tue Jan 10 20:29:50 2012
@@ -0,0 +1,45 @@
+/*	$NetBSD: p5membarvar.h,v 1.1 2012/01/10 20:29:50 rkujawa Exp $ */
+
+/*-
+ * Copyright (c) 2012 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Radoslaw Kujawa.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/device.h>
+
+struct p5membar_softc {
+	device_t	sc_dev;
+
+	uint8_t		sc_type;
+#define P5MEMBAR_TYPE_INTERNAL	1	/* internal stuff, don't touch */
+#define P5MEMBAR_TYPE_MEMORY	2	/* PCI memory BAR */	
+
+	volatile char	*sc_base;	/* base PA */
+	uint32_t	sc_size;
+};
+

Reply via email to