Source-Changes-HG archive

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

[src/trunk]: src Allow console on com_puc without a compile-time option so th...



details:   https://anonhg.NetBSD.org/src/rev/62b204f976a6
branches:  trunk
changeset: 788826:62b204f976a6
user:      soren <soren%NetBSD.org@localhost>
date:      Mon Jul 22 13:40:36 2013 +0000

description:
Allow console on com_puc without a compile-time option so that PC servers
can become headless after the first reboot (sadly, e.g. Intel AMT presents
as a com_puc, but doesn't appear in the BIOS serial port table, so you need
a keyboard and monitor to install and set the installboot parameters first).

Fix com_puc console on devices with offset BAR's.

diffstat:

 share/man/man4/options.4       |   7 +---
 sys/arch/x86/pci/pci_machdep.c |  21 ++++++++++-
 sys/dev/pci/puc.c              |  79 +++++++++++++++++++++--------------------
 sys/dev/pci/puccn.c            |  22 +++--------
 sys/dev/pci/puccn.h            |   3 +-
 5 files changed, 68 insertions(+), 64 deletions(-)

diffs (truncated from 308 to 300 lines):

diff -r 94ad6c8e6f42 -r 62b204f976a6 share/man/man4/options.4
--- a/share/man/man4/options.4  Mon Jul 22 13:27:14 2013 +0000
+++ b/share/man/man4/options.4  Mon Jul 22 13:40:36 2013 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: options.4,v 1.424 2013/06/06 08:34:05 wiz Exp $
+.\"    $NetBSD: options.4,v 1.425 2013/07/22 13:40:36 soren Exp $
 .\"
 .\" Copyright (c) 1996
 .\"    Perry E. Metzger.  All rights reserved.
@@ -1322,11 +1322,6 @@
 What this option allows as far as security is
 concerned, is the ability to safely ensure that the correct script
 is run by the interpreter, as it is passed as an already open file.
-.It Cd options PUCCN
-Enables treating serial ports found on PCI boards
-.Xr puc 4
-as potential console devices.
-The method for choosing such a console device is port dependent.
 .It Cd options RTC_OFFSET=integer
 The kernel (and typically the hardware battery backed-up clock on
 those machines that have one) keeps time in
diff -r 94ad6c8e6f42 -r 62b204f976a6 sys/arch/x86/pci/pci_machdep.c
--- a/sys/arch/x86/pci/pci_machdep.c    Mon Jul 22 13:27:14 2013 +0000
+++ b/sys/arch/x86/pci/pci_machdep.c    Mon Jul 22 13:40:36 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_machdep.c,v 1.57 2013/05/03 15:42:29 jakllsch Exp $        */
+/*     $NetBSD: pci_machdep.c,v 1.58 2013/07/22 13:40:36 soren Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.57 2013/05/03 15:42:29 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.58 2013/07/22 13:40:36 soren Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -113,6 +113,7 @@
 #include "opt_vga.h"
 #include "pci.h"
 #include "wsdisplay.h"
+#include "com.h"
 
 #ifdef DDB
 #include <machine/db_machdep.h>
@@ -137,6 +138,10 @@
 
 #include <machine/mpconfig.h>
 
+#if NCOM > 0
+#include <dev/pci/puccn.h>
+#endif
+
 #include "opt_pci_conf_mode.h"
 
 #ifdef PCI_CONF_MODE
@@ -997,3 +1002,15 @@
        }
        return NULL;
 }
+
+#if NCOM > 0
+int
+cpu_comcnprobe(struct consdev *cn, struct pci_attach_args *pa)
+{
+       pci_mode_detect();
+       pa->pa_iot = x86_bus_space_io;
+       pa->pa_pc = 0;
+       pa->pa_tag = pci_make_tag(0, 0, 31, 0);
+       return 0;
+}
+#endif
diff -r 94ad6c8e6f42 -r 62b204f976a6 sys/dev/pci/puc.c
--- a/sys/dev/pci/puc.c Mon Jul 22 13:27:14 2013 +0000
+++ b/sys/dev/pci/puc.c Mon Jul 22 13:40:36 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puc.c,v 1.32 2011/05/28 10:48:50 ryo Exp $     */
+/*     $NetBSD: puc.c,v 1.33 2013/07/22 13:40:36 soren Exp $   */
 
 /*
  * Copyright (c) 1996, 1998, 1999
@@ -53,7 +53,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: puc.c,v 1.32 2011/05/28 10:48:50 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puc.c,v 1.33 2013/07/22 13:40:36 soren Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -68,7 +68,7 @@
 #include <dev/ic/comvar.h>
 
 #include "locators.h"
-#include "opt_puccn.h"
+#include "com.h"
 
 struct puc_softc {
        /* static configuration data */
@@ -147,13 +147,10 @@
        pci_intr_handle_t intrhandle;
        pcireg_t subsys;
        int i, barindex;
-       bus_addr_t base;
-       bus_space_tag_t tag;
-#ifdef PUCCN
-       bus_space_handle_t ioh;
-#endif
        int locs[PUCCF_NLOCS];
 
+       sc->sc_pc = pa->pa_pc;
+
        subsys = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_SUBSYS_ID_REG);
        sc->sc_desc = puc_find_description(PCI_VENDOR(pa->pa_id),
            PCI_PRODUCT(pa->pa_id), PCI_VENDOR(subsys), PCI_PRODUCT(subsys));
@@ -177,19 +174,19 @@
                return;
        }
 
-       printf(": %s (", sc->sc_desc->name);
+       aprint_naive("\n");
+       aprint_normal(": %s (", sc->sc_desc->name);
        for (i = 0; PUC_PORT_VALID(sc->sc_desc, i); i++)
-               printf("%s%s", i ? ", " : "",
+               aprint_normal("%s%s", i ? ", " : "",
                    puc_port_type_name(sc->sc_desc->ports[i].type));
-       printf(")\n");
+       aprint_normal(")\n");
 
        for (i = 0; i < 6; i++) {
                pcireg_t bar, type;
 
                sc->sc_bar_mappings[i].mapped = 0;
 
-               bar = pci_conf_read(pa->pa_pc, pa->pa_tag,
-                   PCI_MAPREG_START + 4 * i);  /* XXX const */
+               bar = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BAR(i));
                if (bar == 0)                   /* BAR not implemented(?) */
                        continue;
 
@@ -197,31 +194,24 @@
                    PCI_MAPREG_TYPE_IO : PCI_MAPREG_MEM_TYPE(bar));
 
                if (type == PCI_MAPREG_TYPE_IO) {
-                       tag = pa->pa_iot;
-                       base =  PCI_MAPREG_IO_ADDR(bar);
+                       sc->sc_bar_mappings[i].t = pa->pa_iot;
+                       sc->sc_bar_mappings[i].a = PCI_MAPREG_IO_ADDR(bar);
+                       sc->sc_bar_mappings[i].s = PCI_MAPREG_IO_SIZE(bar);
                } else {
-                       tag = pa->pa_memt;
-                       base =  PCI_MAPREG_MEM_ADDR(bar);
+                       sc->sc_bar_mappings[i].t = pa->pa_memt;
+                       sc->sc_bar_mappings[i].a = PCI_MAPREG_MEM_ADDR(bar);
+                       sc->sc_bar_mappings[i].s = PCI_MAPREG_MEM_SIZE(bar);
                }
-#ifdef PUCCN
-               if (com_is_console(tag, base, &ioh)) {
-                       sc->sc_bar_mappings[i].mapped = 1;
-                       sc->sc_bar_mappings[i].a = base;
-                       sc->sc_bar_mappings[i].s = COM_NPORTS;
-                       sc->sc_bar_mappings[i].t = tag;
-                       sc->sc_bar_mappings[i].h = ioh;
-                       continue;
-               }
-#endif
+
                sc->sc_bar_mappings[i].mapped = (pci_mapreg_map(pa,
-                   PCI_MAPREG_START + 4 * i, type, 0,
+                   PCI_BAR(i), type, 0,
                    &sc->sc_bar_mappings[i].t, &sc->sc_bar_mappings[i].h,
                    &sc->sc_bar_mappings[i].a, &sc->sc_bar_mappings[i].s)
                      == 0);
                if (sc->sc_bar_mappings[i].mapped)
                        continue;
 
-               aprint_error_dev(self, "couldn't map BAR at offset 0x%lx\n",
+               aprint_debug_dev(self, "couldn't map BAR at offset 0x%lx\n",
                    (long)(PCI_MAPREG_START + 4 * i));
        }
 
@@ -259,17 +249,32 @@
                /* enable port 0-7 interrupt */
                bus_space_write_1(sc->sc_bar_mappings[1].t,
                    sc->sc_bar_mappings[1].h, SB16C105X_OPT_IMRREG0, 0xff);
+       } else {
+               if (!pmf_device_register(self, NULL, NULL);
+                       aprint_error_dev(self,
+                           "couldn't establish power handler\n");
        }
 
        /* Configure each port. */
        for (i = 0; PUC_PORT_VALID(sc->sc_desc, i); i++) {
+               barindex = PUC_PORT_BAR_INDEX(sc->sc_desc->ports[i].bar);
                bus_space_handle_t subregion_handle;
+               int is_console = 0;
 
                /* make sure the base address register is mapped */
-               barindex = PUC_PORT_BAR_INDEX(sc->sc_desc->ports[i].bar);
+#if NCOM > 0
+               is_console = com_is_console(sc->sc_bar_mappings[barindex].t,
+                   sc->sc_bar_mappings[barindex].a +
+                   sc->sc_desc->ports[i].offset, &subregion_handle);
+               if (is_console) {
+                        sc->sc_bar_mappings[barindex].mapped = 1;
+                               sc->sc_bar_mappings[barindex].h = subregion_handle -
+                           sc->sc_desc->ports[i].offset;       /* XXX hack */
+               }
+#endif
                if (!sc->sc_bar_mappings[barindex].mapped) {
-                       printf("%s: %s port uses unmapped BAR (0x%x)\n",
-                           device_xname(self),
+                       aprint_error_dev(self,
+                           "%s port uses unmapped BAR (0x%x)\n",
                            puc_port_type_name(sc->sc_desc->ports[i].type),
                            sc->sc_desc->ports[i].bar);
                        continue;
@@ -282,17 +287,13 @@
                paa.pc = pa->pa_pc;
                paa.tag = pa->pa_tag;
                paa.intrhandle = intrhandle;
-               paa.a = sc->sc_bar_mappings[barindex].a;
+               paa.a = sc->sc_bar_mappings[barindex].a +
+                   sc->sc_desc->ports[i].offset;
                paa.t = sc->sc_bar_mappings[barindex].t;
                paa.dmat = pa->pa_dmat;
                paa.dmat64 = pa->pa_dmat64;
 
-               if (
-#ifdef PUCCN
-                   !com_is_console(sc->sc_bar_mappings[barindex].t,
-                   sc->sc_bar_mappings[barindex].a, &subregion_handle)
-                  &&
-#endif
+               if (!is_console &&
                    bus_space_subregion(sc->sc_bar_mappings[barindex].t,
                    sc->sc_bar_mappings[barindex].h,
                    sc->sc_desc->ports[i].offset,
diff -r 94ad6c8e6f42 -r 62b204f976a6 sys/dev/pci/puccn.c
--- a/sys/dev/pci/puccn.c       Mon Jul 22 13:27:14 2013 +0000
+++ b/sys/dev/pci/puccn.c       Mon Jul 22 13:40:36 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puccn.c,v 1.10 2010/04/28 19:17:05 dyoung Exp $ */
+/*     $NetBSD: puccn.c,v 1.11 2013/07/22 13:40:36 soren Exp $ */
 
 /*
  * Derived from  pci.c
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: puccn.c,v 1.10 2010/04/28 19:17:05 dyoung Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puccn.c,v 1.11 2013/07/22 13:40:36 soren Exp $");
 
 #include "opt_kgdb.h"
 
@@ -71,18 +71,6 @@
 #define        CONMODE         ((TTYDEF_CFLAG & ~(CSIZE|CSTOPB|PARENB))|CS8) /* 8N1 */
 #endif
 
-#ifdef i386            /* Handle i386 directly */
-int
-cpu_comcnprobe(struct consdev *cn, struct pci_attach_args *pa)
-{
-       pci_mode_detect();
-       pa->pa_iot = x86_bus_space_io;
-       pa->pa_pc = 0;
-       pa->pa_tag = pci_make_tag(0, 0, 31, 0);
-       return 0;
-}
-#endif
-
 cons_decl(com);
 
 static bus_addr_t puccnbase;
@@ -110,9 +98,11 @@
        pcireg_t base;
 
        /* Fetch our tags */
-       if (cpu_comcnprobe(cn, &pa) != 0) {
+#if defined(amd64) || defined(i386)
+       if (cpu_comcnprobe(cn, &pa) != 0)
+#endif
                return 0;
-       }
+
        puctag = pa.pa_iot;
        pci_decompose_tag(pa.pa_pc, pa.pa_tag, &bus, &maxdev, NULL);
 
diff -r 94ad6c8e6f42 -r 62b204f976a6 sys/dev/pci/puccn.h
--- a/sys/dev/pci/puccn.h       Mon Jul 22 13:27:14 2013 +0000
+++ b/sys/dev/pci/puccn.h       Mon Jul 22 13:40:36 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puccn.h,v 1.4 2005/12/11 12:22:50 christos Exp $ */
+/*     $NetBSD: puccn.h,v 1.5 2013/07/22 13:40:36 soren Exp $ */
 
 /*
  * Derived from  pci.c



Home | Main Index | Thread Index | Old Index