Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Add code to allow the PCI com serial ports to be...



details:   https://anonhg.NetBSD.org/src/rev/ea1034f0a6fe
branches:  trunk
changeset: 495301:ea1034f0a6fe
user:      jeffs <jeffs%NetBSD.org@localhost>
date:      Tue Jul 25 23:18:42 2000 +0000

description:
Add code to allow the PCI com serial ports to be used as the system
console.  This is not enabled by default, and is turned on with
options PUCCN.  Done by castor%netbsd.org@localhost.

diffstat:

 sys/dev/pci/files.pci |    6 +-
 sys/dev/pci/puc.c     |   46 ++++++----
 sys/dev/pci/puccn.c   |  218 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pci/puccn.h   |   46 ++++++++++
 sys/dev/pci/pucvar.h  |    4 +-
 5 files changed, 300 insertions(+), 20 deletions(-)

diffs (truncated from 413 to 300 lines):

diff -r 83703dbcce15 -r ea1034f0a6fe sys/dev/pci/files.pci
--- a/sys/dev/pci/files.pci     Tue Jul 25 22:41:58 2000 +0000
+++ b/sys/dev/pci/files.pci     Tue Jul 25 23:18:42 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.pci,v 1.99 2000/06/25 23:34:27 gmcgarry Exp $
+#      $NetBSD: files.pci,v 1.100 2000/07/25 23:18:44 jeffs Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -256,6 +256,10 @@
 attach com at puc with com_puc
 file   dev/pci/com_puc.c               com_puc
 
+# Console device support for puc drivers
+defopt opt_puccn.h                     PUCCN
+file   dev/pci/puccn.c                 puccn
+
 # XXX THE FOLLOWING BLOCK SHOULD GO INTO dev/pci/files.pci, BUT CANNOT
 # XXX BECAUSE NOT 'lpt' IS DEFINED IN files.isa, RATHER THAN files.
 # XXX (when the conf/files and files.isa bogons are fixed, this can
diff -r 83703dbcce15 -r ea1034f0a6fe sys/dev/pci/puc.c
--- a/sys/dev/pci/puc.c Tue Jul 25 22:41:58 2000 +0000
+++ b/sys/dev/pci/puc.c Tue Jul 25 23:18:42 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puc.c,v 1.4 2000/04/17 16:45:04 cgd Exp $      */
+/*     $NetBSD: puc.c,v 1.5 2000/07/25 23:18:42 jeffs Exp $    */
 
 /*
  * Copyright (c) 1996, 1998, 1999
@@ -59,6 +59,9 @@
 #include <dev/pci/pcireg.h>
 #include <dev/pci/pcivar.h>
 #include <dev/pci/pucvar.h>
+#include <sys/termios.h>
+#include <dev/ic/comreg.h>
+#include <dev/ic/comvar.h>
 
 struct puc_softc {
        struct device           sc_dev;
@@ -95,7 +98,7 @@
        sizeof(struct puc_softc), puc_match, puc_attach
 };
 
-static const struct puc_device_description *
+const struct puc_device_description *
        puc_find_description __P((pcireg_t, pcireg_t, pcireg_t, pcireg_t));
 static const char *
        puc_port_type_name __P((int));
@@ -150,6 +153,9 @@
        pci_intr_handle_t intrhandle;
        pcireg_t subsys;
        int i, barindex;
+       bus_addr_t base;
+       bus_space_tag_t tag;
+       bus_space_handle_t ioh;
 
        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),
@@ -180,19 +186,6 @@
                    puc_port_type_name(sc->sc_desc->ports[i].type));
        printf(")\n");
 
-       /*
-        * XXX This driver assumes that 'com' ports attached to it
-        * XXX can not be console.  That isn't unreasonable, because PCI
-        * XXX devices are supposed to be dynamically mapped, and com
-        * XXX console ports want fixed addresses.  When/if baseboard
-        * XXX 'com' ports are identified as PCI/communications/serial
-        * XXX devices and are known to be mapped at the standard
-        * XXX addresses, if they can be the system console then we have
-        * XXX to cope with doing the mapping right.  Then this will get
-        * XXX really ugly.  Of course, by then we might know the real
-        * XXX definition of PCI/communications/serial, and attach 'com'
-        * XXX directly on PCI.
-        */
        for (i = 0; i < 6; i++) {
                pcireg_t bar, type;
 
@@ -206,6 +199,21 @@
                type = (PCI_MAPREG_TYPE(bar) == PCI_MAPREG_TYPE_IO ?
                    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);
+               } else {
+                       tag = pa->pa_memt;
+                       base =  PCI_MAPREG_MEM_ADDR(bar);
+               }
+               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;
+               }
                sc->sc_bar_mappings[i].mapped = (pci_mapreg_map(pa,
                    PCI_MAPREG_START + 4 * i, type, 0,
                    &sc->sc_bar_mappings[i].t, &sc->sc_bar_mappings[i].h,
@@ -262,12 +270,14 @@
                paa.a = sc->sc_bar_mappings[barindex].a;
                paa.t = sc->sc_bar_mappings[barindex].t;
 
-               if (bus_space_subregion(sc->sc_bar_mappings[barindex].t,
+               if (!com_is_console(sc->sc_bar_mappings[barindex].t,
+                   sc->sc_bar_mappings[barindex].a, &subregion_handle)
+                  && bus_space_subregion(sc->sc_bar_mappings[barindex].t,
                    sc->sc_bar_mappings[barindex].h,
                    sc->sc_desc->ports[i].offset,
                    sc->sc_bar_mappings[barindex].s - 
                      sc->sc_desc->ports[i].offset,
-                   &subregion_handle)) {
+                   &subregion_handle) != 0) {
                        printf("%s: couldn't get subregion for port %d\n",
                            sc->sc_dev.dv_xname, i);
                        continue;
@@ -314,7 +324,7 @@
        return ((*cf->cf_attach->ca_match)(parent, cf, aux));
 }
 
-static const struct puc_device_description *
+const struct puc_device_description *
 puc_find_description(vend, prod, svend, sprod)
        pcireg_t vend, prod, svend, sprod;
 {
diff -r 83703dbcce15 -r ea1034f0a6fe sys/dev/pci/puccn.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/puccn.c       Tue Jul 25 23:18:42 2000 +0000
@@ -0,0 +1,218 @@
+/* $Id: */
+
+/*
+ * Derived from  pci.c
+ * Copyright (c) 2000 Geocast Networks Systems.  All rights reserved.
+ *
+ * Copyright (c) 1995, 1996, 1997, 1998
+ *     Christopher G. Demetriou.  All rights reserved.
+ * Copyright (c) 1994 Charles M. Hannum.  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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by Charles M. Hannum.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * 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.
+ */
+
+
+/*
+ * Machine independent support for PCI serial console support.
+ *
+ * Scan the PCI bus for something which resembles a 16550
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/conf.h>
+#include <sys/device.h>
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include <sys/termios.h>
+#include <dev/ic/comreg.h>
+#include <dev/ic/comvar.h>
+
+#include <dev/cons.h>
+
+#include <dev/pci/pucvar.h>
+#include <dev/pci/puccn.h>
+
+#ifndef CONSPEED
+#define CONSPEED       TTYDEF_SPEED
+#endif
+#ifndef CONMODE
+#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 = I386_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;
+static bus_space_tag_t puctag;
+
+#ifdef KGDB
+static bus_addr_t pucgdbbase;
+#endif
+
+/*
+ * Static dev/func variables allow pucprobe to be called multiple times,
+ * resuming the search where it left off, never retrying the same adaptor.
+ */
+
+static bus_addr_t
+pucprobe_doit(struct consdev *cn)
+{
+       struct pci_attach_args pa;
+       int bus;
+       static int dev = 0, func = 0;
+       int maxdev, nfunctions, i;
+       pcireg_t reg, bhlcr, subsys;
+       int foundport = 0;
+       const struct puc_device_description *desc;
+       pcireg_t base;
+
+       /* Fetch our tags */
+       if (cpu_comcnprobe(cn, &pa) != 0) {
+               return 0;
+       }
+       puctag = pa.pa_iot;
+       pci_decompose_tag(pa.pa_pc, pa.pa_tag, &bus, &maxdev, NULL);
+
+       /* scan through devices */
+
+       for (; dev <= maxdev ; dev++) {
+               pa.pa_tag = pci_make_tag(pa.pa_pc, bus, dev, 0);
+               reg = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_ID_REG);
+               if (PCI_VENDOR(reg) == PCI_VENDOR_INVALID
+                   || PCI_VENDOR(reg) == 0)
+                       continue;
+               bhlcr = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_BHLC_REG);
+               if (PCI_HDRTYPE_MULTIFN(bhlcr)) {
+                       nfunctions = 8;
+               } else {
+                       nfunctions = 1;
+               }
+resume_scan:
+               for (; func < nfunctions; func++)  {
+                       pa.pa_tag = pci_make_tag(pa.pa_pc, bus, dev, func);
+                       reg = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_CLASS_REG);
+                       if (PCI_CLASS(reg)  == PCI_CLASS_COMMUNICATIONS
+                           && PCI_SUBCLASS(reg)
+                              == PCI_SUBCLASS_COMMUNICATIONS_SERIAL) {
+                               pa.pa_id = pci_conf_read(pa.pa_pc, pa.pa_tag, PCI_ID_REG);
+                               subsys = pci_conf_read(pa.pa_pc, pa.pa_tag,
+                                   PCI_SUBSYS_ID_REG);
+                               foundport = 1;
+                               break;
+                       }
+               }
+               if (foundport)
+                       break;
+
+               func = 0;
+       }
+       if (!foundport)
+               return 0;
+       foundport = 0;
+
+       desc = puc_find_description(PCI_VENDOR(pa.pa_id),
+           PCI_PRODUCT(pa.pa_id), PCI_VENDOR(subsys), PCI_PRODUCT(subsys));
+       if (desc == NULL) {
+               func++;
+               goto resume_scan;
+       }
+
+       for (i = 0; PUC_PORT_VALID(desc, i); i++)
+       {
+               if (desc->ports[i].type != PUC_PORT_TYPE_COM)
+                       continue;
+               base = pci_conf_read(pa.pa_pc, pa.pa_tag, desc->ports[i].bar);
+               base += desc->ports[i].offset;
+
+               if (PCI_MAPREG_TYPE(base) != PCI_MAPREG_TYPE_IO)
+                       continue;
+               base = PCI_MAPREG_IO_ADDR(base);
+               if (com_is_console(puctag, base, NULL))
+                       continue;
+               foundport = 1;



Home | Main Index | Thread Index | Old Index