Subject: identify cobalt models
To: None <port-cobalt@NetBSD.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-cobalt
Date: 04/09/2006 17:00:52
Hi,

I'd also like to commit the attached diff which enable
to identify cobalt models (Qube2700/Cube2/RaQ/RaQ2), and
I've also put GENERIC kernel (which also includes the previous
todclock device changes) at:
http://www.ceres.dti.ne.jp/~tsutsui/netbsd/netbsd-cobalt-GENERIC-20060409.gz

The device info is taken from Linux sources and it works
fine on my RaQ2:
---
Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
    The NetBSD Foundation, Inc.  All rights reserved.
Copyright (c) 1982, 1986, 1989, 1991, 1993
    The Regents of the University of California.  All rights reserved.

NetBSD 3.99.17 (COLT) #193: Sun Apr  9 10:10:05 JST 2006
        tsutsui@mirage:/usr/src/sys/arch/cobalt/compile/COLT
Cobalt RaQ 2
total memory = 256 MB
avail memory = 247 MB
mainbus0 (root)
com0 at mainbus0 addr 0x1c800000 level 3: st16650a, working fifo
com0: console
cpu0 at mainbus0: QED RM5200 CPU (0x28a0) Rev. 10.0 with built-in FPU Rev. 10.0
cpu0: 32KB/32B 2-way set-associative L1 Instruction cache, 48 TLB entries
cpu0: 32KB/32B 2-way set-associative write-back L1 Data cache
mcclock0 at mainbus0 addr 0x10000070: mc146818 compatible time-of-day clock
panel0 at mainbus0 addr 0x1f000000
 :
---
but any reports on other medels would be appreciated.

---
Izumi Tsutsui


Index: cobalt/machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/cobalt/cobalt/machdep.c,v
retrieving revision 1.59
diff -u -r1.59 machdep.c
--- cobalt/machdep.c	9 Apr 2006 01:29:38 -0000	1.59
+++ cobalt/machdep.c	9 Apr 2006 06:48:32 -0000
@@ -104,6 +104,18 @@
 int	bootunit = -1;
 int	bootpart = -1;
 
+u_int cobalt_id;
+static const char * const cobalt_model[] =
+{
+	NULL,
+	NULL,
+	NULL,
+	"Cobalt Qube 2700",
+	"Cobalt RaQ",
+	"Cobalt Qube 2",
+	"Cobalt RaQ 2"
+};
+#define COBALT_MODELS	(sizeof(cobalt_model) / sizeof(cobalt_model[0]))
 
 phys_ram_seg_t mem_clusters[VM_PHYSSEG_MAX];
 int mem_cluster_cnt;
@@ -111,6 +123,7 @@
 void	mach_init(unsigned int, u_int, char*);
 void	decode_bootstring(void);
 static char *	strtok_light(char *, const char);
+static u_int read_board_id(void);
 
 /*
  * safepri is a safe priority for sleep to set for a spin-wait during
@@ -181,6 +194,13 @@
 	}
 #endif
 
+	cobalt_id = read_board_id();
+	if (cobalt_id >= COBALT_MODELS || cobalt_model[cobalt_id] == NULL)
+		sprintf(cpu_model, "Cobalt unknown model (board ID %u)",
+		    cobalt_id);
+	else
+		strcpy(cpu_model, cobalt_model[cobalt_id]);
+
 	physmem = btoc(memsize - MIPS_KSEG0_START);
 
 	consinit();
@@ -227,8 +247,6 @@
 		kgdb_connect(0);
 #endif
 
-	strcpy(cpu_model, "Cobalt Microserver");
-
 	/*
 	 * Load the rest of the available pages into the VM system.
 	 */
@@ -267,6 +285,7 @@
 	 * Good {morning,afternoon,evening,night}.
 	 */
 	printf("%s%s", copyright, version);
+	printf("%s\n", cpu_model);
 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
 	printf("total memory = %s\n", pbuf);
 
@@ -561,3 +580,34 @@
 
 	return NULL;
 }
+
+/*
+ * Get board ID of cobalt models.
+ * 
+ * The board ID info is stored at the PCI config register
+ * on the PCI-ISA bridge part of the VIA VT82C586 chipset.
+ * We can't use pci_conf_read(9) yet here, so read it directly.
+ */
+static u_int
+read_board_id(void)
+{
+	volatile uint32_t *pcicfg_addr, *pcicfg_data;
+	uint32_t reg;
+
+#define PCIB_PCI_BUS		0
+#define PCIB_PCI_DEV		9
+#define PCIB_PCI_FUNC		0
+#define PCIB_BOARD_ID_REG	0x94
+#define COBALT_BOARD_ID(reg)	((reg & 0x000000f0) >> 4)
+
+	pcicfg_addr = (uint32_t *)MIPS_PHYS_TO_KSEG1(GT_BASE + GT_PCICFG_ADDR);
+	pcicfg_data = (uint32_t *)MIPS_PHYS_TO_KSEG1(GT_BASE + GT_PCICFG_DATA);
+
+	*pcicfg_addr = PCICFG_ENABLE |
+	    (PCIB_PCI_BUS << 16) | (PCIB_PCI_DEV << 11) | (PCIB_PCI_FUNC << 8) |
+	    PCIB_BOARD_ID_REG;
+	reg = *pcicfg_data;
+	*pcicfg_addr = 0;
+
+	return COBALT_BOARD_ID(reg); 
+}
Index: include/cpu.h
===================================================================
RCS file: /cvsroot/src/sys/arch/cobalt/include/cpu.h,v
retrieving revision 1.10
diff -u -r1.10 cpu.h
--- include/cpu.h	4 Sep 2001 06:23:16 -0000	1.10
+++ include/cpu.h	9 Apr 2006 06:48:32 -0000
@@ -1,3 +1,20 @@
 /*	$NetBSD: cpu.h,v 1.10 2001/09/04 06:23:16 simonb Exp $	*/
 
+#ifndef _COBALT_CPU_H_
+#define _COBALT_CPU_H_
+
 #include <mips/cpu.h>
+
+#ifdef _KERNEL
+#ifndef _LOCORE
+extern u_int cobalt_id;
+
+#define COBALT_ID_QUBE2700	3
+#define COBALT_ID_RAQ		4
+#define COBALT_ID_QUBE2		5
+#define COBALT_ID_RAQ2		6 
+
+#endif /* !_LOCORE */
+#endif /* _KERNEL */
+
+#endif /* !_COBALT_CPU_H_ */