Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/i386/stand/efiboot efiboot: implement consdev command.



details:   https://anonhg.NetBSD.org/src/rev/99a5ec21202f
branches:  trunk
changeset: 823662:99a5ec21202f
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Mon May 01 13:03:01 2017 +0000

description:
efiboot: implement consdev command.

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

diffstat:

 sys/arch/i386/stand/efiboot/boot.c    |  74 +++++++++++++++++++++++++++++++++-
 sys/arch/i386/stand/efiboot/efiboot.h |   3 +-
 sys/arch/i386/stand/efiboot/eficons.c |  72 +++++++++++++++++++++++++++++++--
 3 files changed, 139 insertions(+), 10 deletions(-)

diffs (223 lines):

diff -r 5494f8c4b7ea -r 99a5ec21202f sys/arch/i386/stand/efiboot/boot.c
--- a/sys/arch/i386/stand/efiboot/boot.c        Mon May 01 12:29:40 2017 +0000
+++ b/sys/arch/i386/stand/efiboot/boot.c        Mon May 01 13:03:01 2017 +0000
@@ -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 <nonaka%netbsd.org@localhost>
@@ -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 @@
               "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 @@
        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)
 {
+       const struct cons_devs *cdp;
+       char *sep, *sep2 = NULL;
+       int ioport, speed = 0;
 
-       /* XXX not implemented yet */
+       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
diff -r 5494f8c4b7ea -r 99a5ec21202f sys/arch/i386/stand/efiboot/efiboot.h
--- a/sys/arch/i386/stand/efiboot/efiboot.h     Mon May 01 12:29:40 2017 +0000
+++ b/sys/arch/i386/stand/efiboot/efiboot.h     Mon May 01 13:03:01 2017 +0000
@@ -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 <nonaka%netbsd.org@localhost>
@@ -55,6 +55,7 @@
 
 /* eficons.c */
 int cninit(void);
+void consinit(int, int, int);
 void command_text(char *);
 void command_gop(char *);
 
diff -r 5494f8c4b7ea -r 99a5ec21202f sys/arch/i386/stand/efiboot/eficons.c
--- a/sys/arch/i386/stand/efiboot/eficons.c     Mon May 01 12:29:40 2017 +0000
+++ b/sys/arch/i386/stand/efiboot/eficons.c     Mon May 01 13:03:01 2017 +0000
@@ -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 <nonaka%netbsd.org@localhost>
@@ -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 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 @@
        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;
 }



Home | Main Index | Thread Index | Old Index