Subject: GIO bus probe, testers wanted
To: None <port-sgimips@NetBSD.org>
From: Ilpo Ruotsalainen <lonewolf@iki.fi>
List: port-sgimips
Date: 12/05/2003 07:56:13
--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Getting sidetracked while hacking seems to be my specialty. This time I
started with newport hacking and ended up writing GIO bus probe.

The attached patch implements a bus probe for the GIO slots (and GFX
slot) and I'm very curious to hear what kind of product/revision codes
it reports for real GIO devices and the graphics boards in Indy/Indigo2
machines. (And of course if it breaks things for you I'd like to hear
about that before I commit this...)

Sadly the linux-mips hackers seem to have come to the conclusion that
the newport graphics boards do not implement the mandatory GIO product
id read properly... If someone has relevant information, please let me
know. (How does the PROM detect what kind of graphics hardware there is?
Any SGI insiders on this list?-)

-- 
Ilpo Ruotsalainen - <lonewolf@iki.fi> - http://www.iki.fi/lonewolf/

--ZPt4rx8FFjLCG7dd
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="gio-bus-probe.patch"

Index: sys/arch/sgimips/gio/gio.c
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/gio/gio.c,v
retrieving revision 1.11
diff --unified -r1.11 gio.c
--- sys/arch/sgimips/gio/gio.c	17 Nov 2003 10:07:58 -0000	1.11
+++ sys/arch/sgimips/gio/gio.c	5 Dec 2003 05:43:51 -0000
@@ -41,6 +41,8 @@
 #include <sys/systm.h>
 #include <sys/device.h>
 
+#include <machine/bus.h>
+
 #include <sgimips/gio/gioreg.h>
 #include <sgimips/gio/giovar.h>
 
@@ -54,10 +56,18 @@
 static void	gio_attach(struct device *, struct device *, void *);
 static int	gio_print(void *, const char *);
 static int	gio_search(struct device *, struct cfdata *, void *);
+static int	gio_submatch(struct device *, struct cfdata *, void *);
 
 CFATTACH_DECL(gio, sizeof(struct gio_softc),
     gio_match, gio_attach, NULL, NULL);
 
+static uint32_t gio_slot_addr[] = {
+	0x1f400000,
+	0x1f600000,
+	0x1f000000,
+	0
+};
+
 static int
 gio_match(parent, match, aux)
 	struct device *parent;
@@ -79,9 +89,31 @@
 	void *aux;
 {
 	struct gio_attach_args ga;
+	int i;
 
 	printf("\n");
 
+	for (i=0; gio_slot_addr[i] != 0; i++) {
+		ga.ga_slot = i;
+		ga.ga_addr = gio_slot_addr[i];
+		ga.ga_iot = 0;
+		ga.ga_ioh = MIPS_PHYS_TO_KSEG1(gio_slot_addr[i]);
+		
+#if 0
+		/* XXX */
+		if (bus_space_peek_4(ga.ga_iot, ga.ga_ioh, 0, &ga.ga_product))
+			continue;
+#else
+
+		if (badaddr((void *)ga.ga_ioh,sizeof(uint32_t)))
+			continue;
+
+		ga.ga_product = bus_space_read_4(ga.ga_iot, ga.ga_ioh, 0);
+#endif
+
+		config_found_sm(self, &ga, gio_print, gio_submatch);
+	}
+
 	config_search(gio_search, self, &ga);
 }
 
@@ -92,8 +124,19 @@
 {
 	struct gio_attach_args *ga = aux;
 
-	if (pnp != 0)
-		return QUIET;
+	if (pnp != NULL) {
+	  	int product, revision;
+
+		product = GIO_PRODUCT_PRODUCTID(ga->ga_product);
+
+		if (GIO_PRODUCT_32BIT_ID(ga->ga_product))
+			revision = GIO_PRODUCT_REVISION(ga->ga_product);
+		else
+			revision = 0;
+
+		aprint_normal("unknown product 0x%02x revision 0x%02x at %s",
+		    product, revision, pnp);
+	}
 
 	if (ga->ga_slot != GIOCF_SLOT_DEFAULT)
 		aprint_normal(" slot %d", ga->ga_slot);
@@ -112,13 +155,34 @@
 	struct gio_attach_args *ga = aux;
 
 	do {
+		/* Handled by direct configuration, so skip here */
+		if (cf->cf_loc[GIOCF_ADDR] == GIOCF_ADDR_DEFAULT)
+			return 0;
+
 		ga->ga_slot = cf->cf_loc[GIOCF_SLOT];
 		ga->ga_addr = cf->cf_loc[GIOCF_ADDR];
 		ga->ga_iot = 0;
 		ga->ga_ioh = MIPS_PHYS_TO_KSEG1(ga->ga_addr);
+
 		if (config_match(parent, cf, ga) > 0)
 			config_attach(parent, cf, ga, gio_print);
 	} while (cf->cf_fstate == FSTATE_STAR);
 
 	return 0;
+}
+
+static int
+gio_submatch(struct device *parent, struct cfdata *cf, void *aux)
+{
+	struct gio_attach_args *ga = aux;
+
+	if (cf->cf_loc[GIOCF_SLOT] != GIOCF_SLOT_DEFAULT &&
+	    cf->cf_loc[GIOCF_SLOT] != ga->ga_slot)
+		return 0;
+
+	if (cf->cf_loc[GIOCF_ADDR] != GIOCF_ADDR_DEFAULT &&
+	    cf->cf_loc[GIOCF_ADDR] != ga->ga_addr)
+		return 0;
+
+	return config_match(parent, cf, aux);
 }
Index: sys/arch/sgimips/gio/gioreg.h
===================================================================
RCS file: /cvsroot/src/sys/arch/sgimips/gio/gioreg.h,v
retrieving revision 1.1
diff --unified -r1.1 gioreg.h
--- sys/arch/sgimips/gio/gioreg.h	14 Jun 2000 16:51:04 -0000	1.1
+++ sys/arch/sgimips/gio/gioreg.h	5 Dec 2003 05:43:51 -0000
@@ -1 +1,39 @@
 /*	$NetBSD: gioreg.h,v 1.1 2000/06/14 16:51:04 soren Exp $	*/
+
+/*
+ * Copyright (c) 2003 Ilpo Ruotsalainen
+ * All rights reserved.
+ * 
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ * 
+ * <<Id: LICENSE_GC,v 1.1 2001/10/01 23:24:05 cgd Exp>>
+ */
+
+#ifndef _ARCH_SGIMIPS_GIO_GIOREG_H_
+#define _ARCH_SGIMIPS_GIO_GIOREG_H_
+
+#define GIO_PRODUCT_32BIT_ID(x)		((x) & 0x80)
+#define GIO_PRODUCT_PRODUCTID(x)	((x) & 0x7f)
+#define GIO_PRODUCT_REVISION(x)		(((x) >> 8) & 0xff)
+
+#endif

--ZPt4rx8FFjLCG7dd--