Subject: Re: wscons on shark
To: None <port-arm@NetBSD.org>
From: Izumi Tsutsui <tsutsui@ceres.dti.ne.jp>
List: port-arm
Date: 01/05/2005 20:44:38
In article <041225035209.M0101462@mirage.ceres.dti.ne.jp>
I wrote:

> It just works on my Funai's DNARD terminal with vga/pckbd, pccons,
> and ofcons.
> 
> diff and dmesg are attached though there are some problems:
> - shark/isa/isa_io_asm.S is mostly identical with
>   arm/arm/bus_space_asm_generic.S, but why bus_space_generic is
>   defined as attribute? 
> - cats uses arm/conf/majors.arm32, but shark uses shark/conf/majors.shark.
>   wsfont is 86 in majors.arm32, but 86 is already occupied by ksyms
>   in majors.shark.
> - Should we still use cninit() for consinit() or not?
> - Xserver is not tested at all, but pccons should be removed anyway?
> 
> Comments?

I've committed cosmetic part, and if there is no objection
I'll commit the attached wscons diff this weekend.
(note pccons/opms support is still available)
---
Izumi Tsutsui
tsutsui@ceres.dti.ne.jp

Index: conf/GENERIC
===================================================================
RCS file: /cvsroot/src/sys/arch/shark/conf/GENERIC,v
retrieving revision 1.37
diff -u -r1.37 GENERIC
--- conf/GENERIC	5 Jan 2005 09:06:33 -0000	1.37
+++ conf/GENERIC	5 Jan 2005 10:47:23 -0000
@@ -167,6 +167,48 @@
 #options 	KERNEL_DEBUG	# compile in kernel debugging capability
 #makeoptions	DEBUG="-g"	# compile full symbol table
 
+#
+# wscons options
+#
+# builtin terminal emulations
+#options 	WSEMUL_SUN		# sun terminal emulation
+options 	WSEMUL_VT100		# VT100 / VT220 emulation
+# customization of console and kernel output - see dev/wscons/wsdisplayvar.h
+#options 	WSDISPLAY_CUSTOM_OUTPUT	# color customization from wsconsctl(8)
+#options 	WS_DEFAULT_FG=WSCOL_WHITE
+#options 	WS_DEFAULT_BG=WSCOL_BLACK
+#options 	WS_DEFAULT_COLATTR="(0)"
+#options 	WS_DEFAULT_MONOATTR="(0)"
+options 	WS_KERNEL_FG=WSCOL_GREEN
+#options 	WS_KERNEL_BG=WSCOL_BLACK
+#options 	WS_KERNEL_COLATTR=""
+#options 	WS_KERNEL_MONOATTR=""
+# customization of console border color
+#options 	WSDISPLAY_CUSTOM_BORDER	# border customization from wsconsctl(8)
+#options 	WSDISPLAY_BORDER_COLOR=WSCOL_BLUE	# default color
+# compatibility to other console drivers
+options 	WSDISPLAY_COMPAT_PCVT		# emulate some ioctls
+options 	WSDISPLAY_COMPAT_SYSCONS	# emulate some ioctls
+options 	WSDISPLAY_COMPAT_USL		# VT handling
+options 	WSDISPLAY_COMPAT_RAWKBD		# can get raw scancodes
+# see dev/pckbc/wskbdmap_mfii.c for implemented layouts
+#options 	PCKBD_LAYOUT="(KB_DE | KB_NODEAD)"
+#options 	PCKBD_LAYOUT="(KB_US | KB_SWAPCTRLCAPS)"
+# allocate a number of virtual screens at autoconfiguration time
+#options 	WSDISPLAY_DEFAULTSCREENS=4
+# use a large software cursor that doesn't blink
+#options 	PCDISPLAY_SOFTCURSOR
+# modify the screen type of the console; defaults to "80x25"
+#options 	VGA_CONSOLE_SCREENTYPE="\"80x24\""
+# the following enables some functions to get mouse console support.
+# if you want a really secure system, it may be better not to enable them,
+# see wsmoused(8), section SECURITY CONSIDERATIONS for more info.
+#options 	WSDISPLAY_CHARFUNCS		# mouse console support
+# console scrolling support.
+#options 	WSDISPLAY_SCROLLSUPPORT
+# enable VGA raster mode capable of displaying multilingual text on console
+#options 	VGA_RASTERCONSOLE
+
 config		netbsd		root on ? type ?
 
 # The main bus device
@@ -197,15 +239,24 @@
 sd*		at atapibus? drive?
 
 # PCCONS@OFW
-ofisapc*	at ofbus?
-pc*		at ofisapc?
+#ofisapc*	at ofbus?
+#pc*		at ofisapc?
 #options 	FRENCH_KBD
 #options 	FINNISH_KBD
 #options 	GERMAN_KBD
 #options 	NORWEGIAN_KBD
 
 # PS/2 Mouse
-opms0		at spckbd? irq 12
+#opms0		at spckbd? irq 12
+
+# wscons
+pckbc*		at ofisa?
+pckbd*		at pckbc?
+pms*		at pckbc?
+vga*		at ofbus?
+wsdisplay*	at vga?
+wskbd*		at pckbd? console ?
+wsmouse*	at pms? mux 0
 
 # CS8900 Ethernet@OFW
 cs*		at ofisa?
@@ -252,6 +303,8 @@
 pseudo-device	openfirm		# /dev/openfirm
 #pseudo-device	vcoda	4		# coda kernel <-> cachemanager
 pseudo-device	clockctl		# user control of clock subsystem
+pseudo-device	wsmux			# mouse & keyboard multiplexor
+pseudo-device	wsfont
 pseudo-device	ksyms			# /dev/ksyms
 #pseudo-device	pf			# PF packet filter
 #pseudo-device	pflog			# PF log if
Index: conf/files.shark
===================================================================
RCS file: /cvsroot/src/sys/arch/shark/conf/files.shark,v
retrieving revision 1.8
diff -u -r1.8 files.shark
--- conf/files.shark	5 Jan 2005 09:13:29 -0000	1.8
+++ conf/files.shark	5 Jan 2005 10:47:23 -0000
@@ -30,6 +30,9 @@
 include "dev/rasops/files.rasops"
 include "dev/wsfont/files.wsfont"
 
+# Include pckbport stuff
+include "dev/pckbport/files.pckbport"
+
 #
 # Machine-independent ATA drivers
 #
@@ -42,9 +45,8 @@
 file	arch/shark/ofw/ofw.c
 file	arch/shark/ofw/oftodclock.c
 
-# OFW console initialization
-file	arch/shark/ofw/consinit.c
-file	dev/cninit.c
+# console initialization
+file	arch/shark/shark/consinit.c
 
 # ISA DMA glue
 file	arch/shark/isa/isadma_machdep.c		isadma
@@ -53,7 +55,6 @@
 include "dev/ofisa/files.ofisa"
 file	arch/shark/ofw/ofisa_machdep.c		ofisa
 file	arch/shark/ofw/com_ofisa_machdep.c	com_ofisa
-file	arch/shark/ofw/com_ofisa_consolehack.c	com_ofisa	# XXX
 file	arch/shark/ofw/if_cs_ofisa_machdep.c	cs_ofisa
 file	arch/shark/ofw/lpt_ofisa_machdep.c	lpt_ofisa | atppc_ofisa
 file	arch/shark/ofw/wdc_ofisa_machdep.c	wdc_ofisa
@@ -95,7 +96,6 @@
 
 # Generic MD files
 file	arch/shark/shark/autoconf.c
-file	arch/shark/shark/conf.c
 
 file	arch/arm/arm/disksubr.c			disk
 file	arch/arm/arm/disksubr_acorn.c		disk
@@ -132,6 +132,10 @@
 attach	pc at ofisapc
 file	arch/shark/shark/pccons.c		pc needs-flag
 
+# ofbus VGA
+attach	vga at ofbus with vga_ofbus
+file	arch/shark/ofw/vga_ofbus.c		vga_ofbus	needs-flag
+
 # Smart Card Reader
 device	scr: tty
 file	arch/shark/shark/scr.c			scr needs-flag
Index: conf/majors.shark
===================================================================
RCS file: /cvsroot/src/sys/arch/shark/conf/majors.shark,v
retrieving revision 1.13
diff -u -r1.13 majors.shark
--- conf/majors.shark	5 Jan 2005 09:15:19 -0000	1.13
+++ conf/majors.shark	5 Jan 2005 10:47:23 -0000
@@ -47,9 +47,14 @@
 device-major	midi		char 57			midi
 device-major	sequencer	char 58			sequencer
 device-major	vcoda		char 59			vcoda
+device-major	wsdisplay	char 60			wsdisplay
+device-major	wskbd		char 61			wskbd
+device-major	wsmouse		char 62			wsmouse
 
 device-major	raid		char 71  block 71	raid
 
+device-major	wsmux		char 73			wsmux
+
 device-major	openfirm	char 77			ofwgencfg
 
 device-major	clockctl	char 84			clockctl
Index: isa/isa_io.c
===================================================================
RCS file: /cvsroot/src/sys/arch/shark/isa/isa_io.c,v
retrieving revision 1.4
diff -u -r1.4 isa_io.c
--- isa/isa_io.c	5 Jan 2005 10:25:43 -0000	1.4
+++ isa/isa_io.c	5 Jan 2005 10:47:24 -0000
@@ -133,7 +133,7 @@
 
 	/* copy */
 	bs_notimpl_bs_c_1,
-	bs_notimpl_bs_c_2,
+	isa_bs_c_2,
 	bs_notimpl_bs_c_4,
 	bs_notimpl_bs_c_8,
 };
@@ -214,7 +214,7 @@
 
 	/* copy */
 	bs_notimpl_bs_c_1,
-	bs_notimpl_bs_c_2,
+	isa_bs_c_2,
 	bs_notimpl_bs_c_4,
 	bs_notimpl_bs_c_8,
 };
Index: isa/isa_io_asm.S
===================================================================
RCS file: /cvsroot/src/sys/arch/shark/isa/isa_io_asm.S,v
retrieving revision 1.1
diff -u -r1.1 isa_io_asm.S
--- isa/isa_io_asm.S	10 Feb 2002 01:57:53 -0000	1.1
+++ isa/isa_io_asm.S	5 Jan 2005 10:47:24 -0000
@@ -339,3 +339,37 @@
 	bne	Lisa_bs_sr_2_loop
 
 	mov	pc, lr
+
+/*
+ * Copy region
+ */
+
+ENTRY(isa_bs_c_2)
+	add	r0, r1, r2
+	ldr	r2, [sp, #0]
+	add	r1, r2, r3
+	ldr	r2, [sp, #4]
+	teq	r2, #0
+	moveq	pc, lr
+
+	cmp	r0, r1
+	blt	2f
+
+1:	ldrh	r3, [r0], #2
+	strh	r3, [r1], #2
+	subs	r2, r2, #1
+	bne	1b
+
+	mov	pc, lr
+
+2:	add	r0, r0, r2, lsl #1
+	add	r1, r1, r2, lsl #1
+	sub	r0, r0, #2
+	sub	r1, r1, #2
+
+3:	ldrh	r3, [r0], #-2
+	strh	r3, [r1], #-2
+	subs	r2, r2, #1
+	bne	3b
+
+	mov	pc, lr
Index: ofw/vga_ofbus.c
===================================================================
RCS file: /cvsroot/src/sys/arch/shark/ofw/vga_ofbus.c,v
retrieving revision 1.5
diff -u -r1.5 vga_ofbus.c
--- ofw/vga_ofbus.c	15 Jul 2003 03:36:02 -0000	1.5
+++ ofw/vga_ofbus.c	5 Jan 2005 10:47:24 -0000
@@ -47,9 +47,8 @@
 #include <dev/wscons/wsdisplayvar.h>
 
 #include <dev/ofw/openfirm.h>
-#if 0
-#include <dnard/ofw/vga_ofisavar.h>
-#endif
+
+#include <shark/ofw/vga_ofbusvar.h>
 
 struct vga_ofbus_softc {
 	struct vga_softc sc_vga;
@@ -91,13 +90,40 @@
 	osc->sc_phandle = oba->oba_phandle;
 
 	vga_common_attach(sc, &isa_io_bs_tag, &isa_mem_bs_tag,
-	    WSDISPLAY_TYPE_ISAVGA, NULL);
+	    WSDISPLAY_TYPE_ISAVGA, 0, NULL);
 }
 
 int
-vga_ofbus_cnattach(int phandle, bus_space_tag_t iot, bus_space_tag_t memt)
+vga_ofbus_cnattach(bus_space_tag_t iot, bus_space_tag_t memt)
 {
-	if (OF_call_method("text-mode3", phandle, 0, 0) != 0) {
+	int chosen_phandle;
+	int stdout_ihandle, stdout_phandle;
+	char buf[128];
+
+	stdout_phandle = 0;
+
+	/*
+	 * Find out whether the firmware's chosen stdout is
+	 * a display.  If so, use the existing ihandle so the firmware
+	 * doesn't become Unhappy.  If not, just open it.
+	 */
+	if ((chosen_phandle = OF_finddevice("/chosen")) == -1 ||
+	    OF_getprop(chosen_phandle, "stdout", &stdout_ihandle, 
+	    sizeof(stdout_ihandle)) != sizeof(stdout_ihandle)) {
+		return 0;
+	}
+	stdout_ihandle = of_decode_int((unsigned char *)&stdout_ihandle);
+	if ((stdout_phandle = OF_instance_to_package(stdout_ihandle)) == -1 ||
+	    OF_getprop(stdout_phandle, "device_type", buf, sizeof(buf)) <= 0) {
+		return 0;
+	}
+
+	if (strcmp(buf, "display") != 0) {
+		/* The display is not stdout device. */
+		return 0;
+	}
+		
+	if (OF_call_method("text-mode3", stdout_ihandle, 0, 0) != 0) {
 		printf("vga_ofbus_match: text-mode3 method invocation on VGA "
 		       "screen device failed\n");
 	}
--- /dev/null	2005-01-05 19:18:55.000000000 +0900
+++ ofw/vga_ofbusvar.h	2004-12-23 17:41:22.000000000 +0900
@@ -0,0 +1,30 @@
+/* $NetBSD$ */
+
+/*
+ * Copyright (c) 1995, 1996 Carnegie-Mellon University.
+ * All rights reserved.
+ *
+ * Author: Chris G. Demetriou
+ * 
+ * Permission to use, copy, modify and distribute this software and
+ * its documentation is hereby granted, provided that both the copyright
+ * notice and this permission notice appear in all copies of the
+ * software, derivative works or modified versions, and any portions
+ * thereof, and that both notices appear in supporting documentation.
+ * 
+ * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 
+ * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 
+ * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
+ * 
+ * Carnegie Mellon requests users of this software to return to
+ *
+ *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
+ *  School of Computer Science
+ *  Carnegie Mellon University
+ *  Pittsburgh PA 15213-3890
+ *
+ * any improvements or extensions that they make and grant Carnegie the
+ * rights to redistribute these changes.
+ */
+
+int vga_ofbus_cnattach(bus_space_tag_t, bus_space_tag_t);
--- /dev/null	2005-01-05 19:18:55.000000000 +0900
+++ shark/consinit.c	2004-12-25 02:00:59.000000000 +0900
@@ -0,0 +1,152 @@
+/*	$NetBSD$	*/
+
+/*
+ * Copyright (c) 1998
+ *	Matthias Drochner.  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.
+ *
+ * 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.
+ *
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <dev/cons.h>
+#include <machine/bus.h>
+#include <dev/isa/isavar.h>
+
+#include "vga.h"
+#if (NVGA > 0)
+#include <dev/ic/mc6845reg.h>
+#include <dev/ic/pcdisplayvar.h>
+#include <dev/ic/vgareg.h>
+#include <dev/ic/vgavar.h>
+#endif
+#include "vga_ofbus.h"
+#if (NVGA_OFBUS > 0)
+#include <shark/ofw/vga_ofbusvar.h>
+#endif
+
+#include "pckbc.h"
+#if (NPCKBC > 0)
+#include <dev/isa/isareg.h>
+#include <dev/ic/i8042reg.h>
+#include <dev/ic/pckbcvar.h>
+#include <dev/pckbport/pckbportvar.h>
+#endif
+#include "pckbd.h" /* for pckbc_machdep_cnattach */
+
+#include "pc.h"
+#if (NPC > 0)
+#include <machine/pccons.h>
+cons_decl(pc)
+static struct consdev pccons = cons_init(pc);
+#endif
+
+#include "com.h"
+#if (NCOM > 0)
+#include <sys/termios.h>
+#include <dev/ic/comreg.h>
+#include <dev/ic/comvar.h>
+#endif
+
+#include "ofcons.h"
+#if (NOFCONS > 0)
+cons_decl(ofcons_)
+static struct consdev ofcons = cons_init(ofcons_);
+#endif
+
+#if (NCOM > 0)
+#ifndef CONADDR
+#define CONADDR 0x3f8
+#endif
+#ifndef CONSPEED
+#define CONSPEED TTYDEF_SPEED
+#endif
+#ifndef CONMODE
+#define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
+#endif
+int comcnmode = CONMODE;
+#endif /* NCOM */
+#ifdef COMCONSOLE
+int comconsole = 1;
+#else
+int comconsole = 0;
+#endif
+
+/*
+ * consinit:
+ * initialize the system console.
+ */
+void
+consinit()
+{
+	struct consdev *cp;
+	static int initted;
+
+	if (initted)
+		return;
+	initted = 1;
+	cp = NULL;
+
+	if (comconsole) {
+#if (NCOM > 0)
+		if (comcnattach(&isa_io_bs_tag, CONADDR, CONSPEED, COM_FREQ,
+		    COM_TYPE_NORMAL, comcnmode))
+			panic("can't init serial console");
+		return;
+#endif
+	} else {
+#if (NPC > 0) || (NVGA > 0)
+#if (NVGA_OFBUS > 0)
+		if (!vga_ofbus_cnattach(&isa_io_bs_tag, &isa_mem_bs_tag)) {
+#if (NPCKBC > 0)
+			pckbc_cnattach(&isa_io_bs_tag, IO_KBD, KBCMDP,
+			    PCKBC_KBD_SLOT);
+#endif /* NPCKBC */
+			return;
+		}
+#endif /* NVGA_OFBUS */
+#if (NPC > 0)
+		cp = &pccons;
+		pccnprobe(cp);
+		if (cp->cn_pri == CN_INTERNAL) {
+			pccninit(cp);
+			cn_tab = cp;
+			return;
+		}
+#endif /* NPC */
+#else /* NPC || NVGA */
+#if (NOFCONS > 0)
+		cp = &ofcons;
+		ofcons_cnprobe(cp);
+		if (cp->cn_pri == CN_INTERNAL) {
+			ofcons_cninit(cp);
+			cn_tab = cp;
+			return;
+		}
+#endif /* NOFCONS */
+#endif /* NPC || NVGA */
+	}
+}