Module Name:    src
Committed By:   msaitoh
Date:           Sun Jan 26 10:54:24 UTC 2014

Modified Files:
        src/sys/arch/x86/pci: pci_machdep.c
        src/sys/arch/x86/x86: consinit.c
        src/sys/dev/pci: files.pci puccn.c puccn.h

Log Message:
PUCCN improvements:
 - 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).


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/x86/pci/pci_machdep.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/x86/x86/consinit.c
cvs rdiff -u -r1.368 -r1.369 src/sys/dev/pci/files.pci
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/pci/puccn.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/pci/puccn.h

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/x86/pci/pci_machdep.c
diff -u src/sys/arch/x86/pci/pci_machdep.c:1.63 src/sys/arch/x86/pci/pci_machdep.c:1.64
--- src/sys/arch/x86/pci/pci_machdep.c:1.63	Wed Dec 25 17:24:39 2013
+++ src/sys/arch/x86/pci/pci_machdep.c	Sun Jan 26 10:54:24 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: pci_machdep.c,v 1.63 2013/12/25 17:24:39 jakllsch Exp $	*/
+/*	$NetBSD: pci_machdep.c,v 1.64 2014/01/26 10:54:24 msaitoh 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.63 2013/12/25 17:24:39 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.64 2014/01/26 10:54:24 msaitoh Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -110,6 +110,7 @@ __KERNEL_RCSID(0, "$NetBSD: pci_machdep.
 #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 @@ device_pci_register(device_t dev, void *
 	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: src/sys/arch/x86/x86/consinit.c
diff -u src/sys/arch/x86/x86/consinit.c:1.24 src/sys/arch/x86/x86/consinit.c:1.25
--- src/sys/arch/x86/x86/consinit.c:1.24	Sat Oct 13 17:58:55 2012
+++ src/sys/arch/x86/x86/consinit.c	Sun Jan 26 10:54:24 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: consinit.c,v 1.24 2012/10/13 17:58:55 jdc Exp $	*/
+/*	$NetBSD: consinit.c,v 1.25 2014/01/26 10:54:24 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1998
@@ -27,9 +27,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.24 2012/10/13 17:58:55 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.25 2014/01/26 10:54:24 msaitoh Exp $");
 
 #include "opt_kgdb.h"
+#include "opt_puc.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -42,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: consinit.c,v
 #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 @@ __KERNEL_RCSID(0, "$NetBSD: consinit.c,v
 #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 @@ consinit(void)
 	const struct btinfo_console *consinfo;
 	const struct btinfo_framebuffer *fbinfo;
 	static int initted;
+	int rv;
 
 	if (initted)
 		return;
@@ -204,15 +210,22 @@ dokbd:
 		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: src/sys/dev/pci/files.pci
diff -u src/sys/dev/pci/files.pci:1.368 src/sys/dev/pci/files.pci:1.369
--- src/sys/dev/pci/files.pci:1.368	Tue Jan 21 14:52:07 2014
+++ src/sys/dev/pci/files.pci	Sun Jan 26 10:54:24 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: files.pci,v 1.368 2014/01/21 14:52:07 mlelstv Exp $
+#	$NetBSD: files.pci,v 1.369 2014/01/26 10:54:24 msaitoh Exp $
 #
 # Config file and device description for machine-independent PCI code.
 # Included by ports that need it.  Requires that the SCSI files be
@@ -604,9 +604,11 @@ device	puc { port = -1 }
 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: src/sys/dev/pci/puccn.c
diff -u src/sys/dev/pci/puccn.c:1.12 src/sys/dev/pci/puccn.c:1.13
--- src/sys/dev/pci/puccn.c:1.12	Thu Jan 23 17:43:28 2014
+++ src/sys/dev/pci/puccn.c	Sun Jan 26 10:54:24 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: puccn.c,v 1.12 2014/01/23 17:43:28 msaitoh Exp $ */
+/*	$NetBSD: puccn.c,v 1.13 2014/01/26 10:54:24 msaitoh Exp $ */
 
 /*
  * Derived from  pci.c
@@ -42,7 +42,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: puccn.c,v 1.12 2014/01/23 17:43:28 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puccn.c,v 1.13 2014/01/26 10:54:24 msaitoh Exp $");
 
 #include "opt_kgdb.h"
 
@@ -75,6 +75,7 @@ cons_decl(com);
 
 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 @@ pucprobe_doit(struct consdev *cn)
 
 	/* 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 @@ resume_scan:
 	 */
 	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 @@ resume_scan:
 	{
 		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 @@ resume_scan:
 		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 @@ comgdbinit(struct consdev *cn)
 #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: src/sys/dev/pci/puccn.h
diff -u src/sys/dev/pci/puccn.h:1.5 src/sys/dev/pci/puccn.h:1.6
--- src/sys/dev/pci/puccn.h:1.5	Mon Jul 22 13:40:36 2013
+++ src/sys/dev/pci/puccn.h	Sun Jan 26 10:54:24 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: puccn.h,v 1.5 2013/07/22 13:40:36 soren Exp $ */
+/*	$NetBSD: puccn.h,v 1.6 2014/01/26 10:54:24 msaitoh Exp $ */
 
 /*
  * Derived from  pci.c
@@ -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 *);

Reply via email to