Module Name:    src
Committed By:   nonaka
Date:           Mon May  1 13:03:02 UTC 2017

Modified Files:
        src/sys/arch/i386/stand/efiboot: boot.c efiboot.h eficons.c

Log Message:
efiboot: implement consdev command.

no support to change console device for efiboot yet.
only pass console parameters to kernel.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/i386/stand/efiboot/boot.c \
    src/sys/arch/i386/stand/efiboot/efiboot.h
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/i386/stand/efiboot/eficons.c

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/i386/stand/efiboot/boot.c
diff -u src/sys/arch/i386/stand/efiboot/boot.c:1.4 src/sys/arch/i386/stand/efiboot/boot.c:1.5
--- src/sys/arch/i386/stand/efiboot/boot.c:1.4	Sun Mar 12 05:33:48 2017
+++ src/sys/arch/i386/stand/efiboot/boot.c	Mon May  1 13:03:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: boot.c,v 1.4 2017/03/12 05:33:48 nonaka Exp $	*/
+/*	$NetBSD: boot.c,v 1.5 2017/05/01 13:03:01 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -30,6 +30,7 @@
 
 #include <sys/bootblock.h>
 #include <sys/boot_flag.h>
+#include <machine/limits.h>
 
 #include "bootcfg.h"
 #include "bootmod.h"
@@ -340,7 +341,7 @@ command_help(char *arg)
 	       "boot [xdNx:][filename] [-12acdqsvxz]\n"
 	       "     (ex. \"hd0a:netbsd.old -s\"\n"
 	       "dev [xd[N[x]]:]\n"
-	       "consdev {pc|com[0123]|com[0123]kbd|auto}\n"
+	       "consdev {pc|com[0123][,{speed}]|com,{ioport}[,{speed}]}\n"
 	       "devpath\n"
 	       "efivar\n"
 	       "gop [{modenum|list}]\n"
@@ -436,12 +437,77 @@ command_dev(char *arg)
 	default_devname = savedevname;
 }
 
-/* ARGSUSED */
+static const struct cons_devs {
+	const char	*name;
+	u_int		tag;
+	int		ioport;
+} cons_devs[] = {
+	{ "pc",		CONSDEV_PC,   0 },
+	{ "com0",	CONSDEV_COM0, 0 },
+	{ "com1",	CONSDEV_COM1, 0 },
+	{ "com2",	CONSDEV_COM2, 0 },
+	{ "com3",	CONSDEV_COM3, 0 },
+	{ "com0kbd",	CONSDEV_COM0KBD, 0 },
+	{ "com1kbd",	CONSDEV_COM1KBD, 0 },
+	{ "com2kbd",	CONSDEV_COM2KBD, 0 },
+	{ "com3kbd",	CONSDEV_COM3KBD, 0 },
+	{ "com",	CONSDEV_COM0, -1 },
+	{ "auto",	CONSDEV_AUTO, 0 },
+	{ NULL,		0 }
+};
+
 void
 command_consdev(char *arg)
 {
-
-	/* XXX not implemented yet */
+	const struct cons_devs *cdp;
+	char *sep, *sep2 = NULL;
+	int ioport, speed = 0;
+
+	sep = strchr(arg, ',');
+	if (sep != NULL) {
+		*sep++ = '\0';
+		sep2 = strchr(sep, ',');
+		if (sep != NULL)
+			*sep2++ = '\0';
+	}
+
+	for (cdp = cons_devs; cdp->name; cdp++) {
+		if (strcmp(arg, cdp->name) == 0) {
+			ioport = cdp->ioport;
+			if (cdp->tag == CONSDEV_PC || cdp->tag == CONSDEV_AUTO) {
+				if (sep != NULL || sep2 != NULL)
+					goto error;
+			} else {
+				/* com? */
+				if (ioport == -1) {
+					if (sep != NULL) {
+						u_long t = strtoul(sep, NULL, 0);
+						if (t > INT_MAX)
+							goto error;
+						ioport = (int)t;
+					}
+					if (sep2 != NULL) {
+						speed = atoi(sep2);
+						if (speed < 0)
+							goto error;
+					}
+				} else {
+					if (sep != NULL) {
+						speed = atoi(sep);
+						if (speed < 0)
+							goto error;
+					}
+					if (sep2 != NULL)
+						goto error;
+				}
+			}
+			consinit(cdp->tag, ioport, speed);
+			print_banner();
+			return;
+		}
+	}
+error:
+	printf("invalid console device.\n");
 }
 
 #ifndef SMALL
Index: src/sys/arch/i386/stand/efiboot/efiboot.h
diff -u src/sys/arch/i386/stand/efiboot/efiboot.h:1.4 src/sys/arch/i386/stand/efiboot/efiboot.h:1.5
--- src/sys/arch/i386/stand/efiboot/efiboot.h:1.4	Sat Feb 11 10:23:39 2017
+++ src/sys/arch/i386/stand/efiboot/efiboot.h	Mon May  1 13:03:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: efiboot.h,v 1.4 2017/02/11 10:23:39 nonaka Exp $	*/
+/*	$NetBSD: efiboot.h,v 1.5 2017/05/01 13:03:01 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -55,6 +55,7 @@ void efi_cleanup(void);
 
 /* eficons.c */
 int cninit(void);
+void consinit(int, int, int);
 void command_text(char *);
 void command_gop(char *);
 

Index: src/sys/arch/i386/stand/efiboot/eficons.c
diff -u src/sys/arch/i386/stand/efiboot/eficons.c:1.3 src/sys/arch/i386/stand/efiboot/eficons.c:1.4
--- src/sys/arch/i386/stand/efiboot/eficons.c:1.3	Fri Mar 24 01:25:36 2017
+++ src/sys/arch/i386/stand/efiboot/eficons.c	Mon May  1 13:03:01 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: eficons.c,v 1.3 2017/03/24 01:25:36 nonaka Exp $	*/
+/*	$NetBSD: eficons.c,v 1.4 2017/05/01 13:03:01 nonaka Exp $	*/
 
 /*-
  * Copyright (c) 2016 Kimihiro Nonaka <non...@netbsd.org>
@@ -34,6 +34,8 @@
 #include "bootinfo.h"
 #include "vbe.h"
 
+extern struct x86_boot_params boot_params;
+
 struct btinfo_console btinfo_console;
 
 static EFI_GRAPHICS_OUTPUT_PROTOCOL *efi_gop;
@@ -46,6 +48,68 @@ static int keybuf_write = 0;
 static void eficons_init_video(void);
 static void efi_switch_video_to_text_mode(void);
 
+static int
+getcomaddr(int idx)
+{
+	static const short comioport[4] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
+
+	if (idx < __arraycount(comioport))
+		return comioport[idx];
+	return 0;
+}
+
+/*
+ * XXX only pass console parameters to kernel.
+ */
+void
+consinit(int dev, int ioport, int speed)
+{
+	int iodev;
+
+#if defined(CONSPEED)
+	btinfo_console.speed = CONSPEED;
+#else
+	btinfo_console.speed = 9600;
+#endif
+
+	switch (dev) {
+	case CONSDEV_AUTO:
+		/* XXX comport */
+		goto nocom;
+
+	case CONSDEV_COM0:
+	case CONSDEV_COM1:
+	case CONSDEV_COM2:
+	case CONSDEV_COM3:
+		iodev = dev;
+comport:
+		btinfo_console.addr = ioport;
+		if (btinfo_console.addr == 0) {
+			btinfo_console.addr = getcomaddr(iodev - CONSDEV_COM0);
+			if (btinfo_console.addr == 0)
+				goto nocom;
+		}
+		if (speed != 0)
+			btinfo_console.speed = speed;
+		break;
+
+	case CONSDEV_COM0KBD:
+	case CONSDEV_COM1KBD:
+	case CONSDEV_COM2KBD:
+	case CONSDEV_COM3KBD:
+		iodev = dev - CONSDEV_COM0KBD + CONSDEV_COM0;
+		goto comport;	/* XXX kbd */
+
+	case CONSDEV_PC:
+	default:
+nocom:
+		iodev = CONSDEV_PC;
+		break;
+	}
+
+	strlcpy(btinfo_console.devname, iodev == CONSDEV_PC ? "pc" : "com", 16);
+}
+
 int
 cninit(void)
 {
@@ -53,10 +117,8 @@ cninit(void)
 	efi_switch_video_to_text_mode();
 	eficons_init_video();
 
-	/* XXX serial console */
-	btinfo_console.devname[0] = 'p';
-	btinfo_console.devname[1] = 'c';
-	btinfo_console.devname[2] = 0;
+	consinit(boot_params.bp_consdev, boot_params.bp_consaddr,
+	    boot_params.bp_conspeed);
 
 	return 0;
 }

Reply via email to