tech-kern archive

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

puccn improvement



 Hi, all.

 I made a patch to make sys/dev/pci/puccn.c usable than before.
This is NOT perfect, but it's better than before. I think this
patch is useful for further work, for example, to support MMIO
com device and support such devicees that the registers are
4 byte aligned without compile time option.

 http://www.netbsd.org/~msaitoh/puccn_20140124.dif

--------------------------------------
 - Fix a bug that the puc cn mechanism doesn't use the UART's frequency
   in pucdata.c's table.

 - Add a new option PUC_CNAUTO. If this option is set, consinit() in
   x86/x86/consinit.c checks puc com device to use it as console.
   Without this option, the behavior is the same as before.

 - Add a new config parameter PUC_CNBUS. The old code scans bus #0 only.
   If PUC_CNBUS is set, the specified number's bus will be scanned.

 - Rename comcnprobe() to puc_cnprobe() to make it clear.

 - Rename comcninit() to puc_cninit() to make it clear.

 - Add code for a device that a device's com register is MMIO (#if0 ed).
--------------------------------------


Index: sys/arch/x86/pci/pci_machdep.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/pci/pci_machdep.c,v
retrieving revision 1.63
diff -u -r1.63 pci_machdep.c
--- sys/arch/x86/pci/pci_machdep.c      25 Dec 2013 17:24:39 -0000      1.63
+++ sys/arch/x86/pci/pci_machdep.c      23 Jan 2014 18:56:22 -0000
@@ -110,6 +110,7 @@
 #include "opt_acpi.h"
 #include "opt_ddb.h"
 #include "opt_mpbios.h"
+#include "opt_puc.h"
 #include "opt_vga.h"
 #include "pci.h"
 #include "wsdisplay.h"
@@ -963,14 +964,21 @@
        return NULL;
 }

+#ifndef PUC_CNBUS
+#define PUC_CNBUS 0
+#endif
+
 #if NCOM > 0
 int
-cpu_comcnprobe(struct consdev *cn, struct pci_attach_args *pa)
+cpu_puc_cnprobe(struct consdev *cn, struct pci_attach_args *pa)
 {
        pci_mode_detect();
        pa->pa_iot = x86_bus_space_io;
+       pa->pa_memt = x86_bus_space_mem;
        pa->pa_pc = 0;
-       pa->pa_tag = pci_make_tag(0, 0, pci_bus_maxdevs(NULL, 0) - 1, 0);
+       pa->pa_tag = pci_make_tag(0, PUC_CNBUS, pci_bus_maxdevs(NULL, 0) - 1,
+                                 0);
+
        return 0;
 }
 #endif
Index: sys/arch/x86/x86/consinit.c
===================================================================
RCS file: /cvsroot/src/sys/arch/x86/x86/consinit.c,v
retrieving revision 1.24
diff -u -r1.24 consinit.c
--- sys/arch/x86/x86/consinit.c 13 Oct 2012 17:58:55 -0000      1.24
+++ sys/arch/x86/x86/consinit.c 23 Jan 2014 18:56:22 -0000
@@ -30,6 +30,7 @@
 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.24 2012/10/13 17:58:55 jdc Exp $");

 #include "opt_kgdb.h"
+#include "opt_puc.h"

 #include <sys/param.h>
 #include <sys/systm.h>
@@ -42,6 +43,7 @@
 #include "vga.h"
 #include "ega.h"
 #include "pcdisplay.h"
+#include "com_puc.h"
 #if (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
 #include <dev/ic/mc6845reg.h>
 #include <dev/ic/pcdisplayvar.h>
@@ -76,6 +78,9 @@
 #include <dev/ic/comreg.h>
 #include <dev/ic/comvar.h>
 #endif
+#if (NCOM_PUC > 0)
+#include <dev/pci/puccn.h>
+#endif

 #include "ukbd.h"
 #if (NUKBD > 0)
@@ -144,6 +149,7 @@
        const struct btinfo_console *consinfo;
        const struct btinfo_framebuffer *fbinfo;
        static int initted;
+       int rv;

        if (initted)
                return;
@@ -204,15 +210,22 @@
                int addr = consinfo->addr;
                int speed = consinfo->speed;

+#if (NCOM_PUC > 0) && defined(PUC_CNAUTO)
+               puc_cnprobe(NULL);
+               rv = puc_cninit(NULL);
+               if (rv == 0)
+                       return;
+#endif
+
                if (addr == 0)
                        addr = CONADDR;
                if (speed == 0)
                        speed = CONSPEED;

-               if (comcnattach(x86_bus_space_io, addr, speed,
-                               COM_FREQ, COM_TYPE_NORMAL, comcnmode))
+               rv = comcnattach(x86_bus_space_io, addr, speed,
+                                COM_FREQ, COM_TYPE_NORMAL, comcnmode);
+               if (rv != 0)
                        panic("can't init serial console @%x", consinfo->addr);
-
                return;
        }
 #endif
Index: sys/dev/pci/files.pci
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/files.pci,v
retrieving revision 1.368
diff -u -r1.368 files.pci
--- sys/dev/pci/files.pci       21 Jan 2014 14:52:07 -0000      1.368
+++ sys/dev/pci/files.pci       23 Jan 2014 18:56:23 -0000
@@ -604,9 +604,11 @@
 attach puc at pci
 file   dev/pci/puc.c                   puc
 file   dev/pci/pucdata.c               puc
+defflag opt_puc.h      PUC_CNAUTO
+defparam opt_puc.h     PUC_CNBUS

 attach com at puc with com_puc
-file   dev/pci/com_puc.c               com_puc
+file   dev/pci/com_puc.c               com_puc needs-flag
 file   dev/pci/cyber.c                 com_puc
 file   dev/pci/puccn.c                 com_puc

Index: sys/dev/pci/puccn.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/puccn.c,v
retrieving revision 1.12
diff -u -r1.12 puccn.c
--- sys/dev/pci/puccn.c 23 Jan 2014 17:43:28 -0000      1.12
+++ sys/dev/pci/puccn.c 23 Jan 2014 18:56:23 -0000
@@ -75,6 +75,7 @@

 static bus_addr_t puccnbase;
 static bus_space_tag_t puctag;
+static int puccnflags;

 #ifdef KGDB
 static bus_addr_t pucgdbbase;
@@ -99,11 +100,10 @@

        /* Fetch our tags */
 #if defined(amd64) || defined(i386)
-       if (cpu_comcnprobe(cn, &pa) != 0)
+       if (cpu_puc_cnprobe(cn, &pa) != 0)
 #endif
                return 0;

-       puctag = pa.pa_iot;
        pci_decompose_tag(pa.pa_pc, pa.pa_tag, &bus, &maxdev, NULL);

        /* Scan through devices and find a communication class device. */
@@ -145,6 +145,8 @@
         */
        if (!foundport)
                return 0;
+
+       /* Clear foundport flag */
        foundport = 0;

        /* Check whether the device is in the puc device table or not */
@@ -166,12 +168,21 @@
        {
                if (desc->ports[i].type != PUC_PORT_TYPE_COM)
                        continue;
+               puccnflags = desc->ports[i].flags;
                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 (PCI_MAPREG_TYPE(base) == PCI_MAPREG_TYPE_IO) {
+                       puctag = pa.pa_iot;
+                       base = PCI_MAPREG_IO_ADDR(base);
+               }
+#if 0 /* For MMIO device */
+               else {
+                       puctag = pa.pa_memt;
+                       base = PCI_MAPREG_MEM_ADDR(base);
+               }
+#endif
+
                if (com_is_console(puctag, base, NULL))
                        continue;
                foundport = 1;
@@ -183,8 +194,13 @@
                goto resume_scan;
        }

+#if 0
        cn->cn_pri = CN_REMOTE;
-       return PCI_MAPREG_IO_ADDR(base);
+#else
+       if (cn)
+               cn->cn_pri = CN_REMOTE;
+#endif
+       return base;
 }

 #ifdef KGDB
@@ -211,19 +227,21 @@
 #endif

 void
-comcnprobe(struct consdev *cn)
+puc_cnprobe(struct consdev *cn)
 {

        puccnbase = pucprobe_doit(cn);
 }

-void
-comcninit(struct consdev *cn)
+int
+puc_cninit(struct consdev *cn)
 {
+
        if (puccnbase == 0)
-               return;
+               return -1;

-       comcnattach(puctag, puccnbase, CONSPEED, COM_FREQ, COM_TYPE_NORMAL,
+       return comcnattach(puctag, puccnbase, CONSPEED,
+           puccnflags & PUC_COM_CLOCKMASK, COM_TYPE_NORMAL,
            CONMODE);
 }

Index: sys/dev/pci/puccn.h
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/puccn.h,v
retrieving revision 1.5
diff -u -r1.5 puccn.h
--- sys/dev/pci/puccn.h 22 Jul 2013 13:40:36 -0000      1.5
+++ sys/dev/pci/puccn.h 23 Jan 2014 18:56:23 -0000
@@ -35,6 +35,7 @@
  */

 #include <dev/cons.h>
+#include <dev/pci/pcivar.h>

 /*
  * Machine independent support for PCI serial console support.
@@ -44,4 +45,6 @@
  * used before the normal PCI bus initialization.
  */

-int cpu_comcnprobe(struct consdev *, struct pci_attach_args *);
+void puc_cnprobe(struct consdev *);
+int puc_cninit(struct consdev *);
+int cpu_puc_cnprobe(struct consdev *, struct pci_attach_args *);

-- 
-----------------------------------------------
                SAITOH Masanobu (msaitoh%execsw.org@localhost
                                 msaitoh%netbsd.org@localhost)


Home | Main Index | Thread Index | Old Index