Module Name:    src
Committed By:   soren
Date:           Mon Jul 22 13:40:36 UTC 2013

Modified Files:
        src/share/man/man4: options.4
        src/sys/arch/x86/pci: pci_machdep.c
        src/sys/dev/pci: puc.c puccn.c puccn.h

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


To generate a diff of this commit:
cvs rdiff -u -r1.424 -r1.425 src/share/man/man4/options.4
cvs rdiff -u -r1.57 -r1.58 src/sys/arch/x86/pci/pci_machdep.c
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/pci/puc.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/pci/puccn.c
cvs rdiff -u -r1.4 -r1.5 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/share/man/man4/options.4
diff -u src/share/man/man4/options.4:1.424 src/share/man/man4/options.4:1.425
--- src/share/man/man4/options.4:1.424	Thu Jun  6 08:34:05 2013
+++ src/share/man/man4/options.4	Mon Jul 22 13:40:36 2013
@@ -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 @@ set to
 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

Index: src/sys/arch/x86/pci/pci_machdep.c
diff -u src/sys/arch/x86/pci/pci_machdep.c:1.57 src/sys/arch/x86/pci/pci_machdep.c:1.58
--- src/sys/arch/x86/pci/pci_machdep.c:1.57	Fri May  3 15:42:29 2013
+++ src/sys/arch/x86/pci/pci_machdep.c	Mon Jul 22 13:40:36 2013
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: pci_machdep.
 #include "opt_vga.h"
 #include "pci.h"
 #include "wsdisplay.h"
+#include "com.h"
 
 #ifdef DDB
 #include <machine/db_machdep.h>
@@ -137,6 +138,10 @@ __KERNEL_RCSID(0, "$NetBSD: pci_machdep.
 
 #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 @@ device_pci_register(device_t dev, void *
 	}
 	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

Index: src/sys/dev/pci/puc.c
diff -u src/sys/dev/pci/puc.c:1.32 src/sys/dev/pci/puc.c:1.33
--- src/sys/dev/pci/puc.c:1.32	Sat May 28 10:48:50 2011
+++ src/sys/dev/pci/puc.c	Mon Jul 22 13:40:36 2013
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: puc.c,v 1.32
 #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 @@ puc_attach(device_t parent, device_t sel
 	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 @@ puc_attach(device_t parent, device_t sel
 		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 @@ puc_attach(device_t parent, device_t sel
 		    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);
-		}
-#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;
+			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);
 		}
-#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 @@ puc_attach(device_t parent, device_t sel
 		/* 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 @@ puc_attach(device_t parent, device_t sel
 		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,

Index: src/sys/dev/pci/puccn.c
diff -u src/sys/dev/pci/puccn.c:1.10 src/sys/dev/pci/puccn.c:1.11
--- src/sys/dev/pci/puccn.c:1.10	Wed Apr 28 19:17:05 2010
+++ src/sys/dev/pci/puccn.c	Mon Jul 22 13:40:36 2013
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: puccn.c,v 1.
 #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 @@ pucprobe_doit(struct consdev *cn)
 	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);
 

Index: src/sys/dev/pci/puccn.h
diff -u src/sys/dev/pci/puccn.h:1.4 src/sys/dev/pci/puccn.h:1.5
--- src/sys/dev/pci/puccn.h:1.4	Sun Dec 11 12:22:50 2005
+++ src/sys/dev/pci/puccn.h	Mon Jul 22 13:40:36 2013
@@ -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
@@ -34,6 +34,7 @@
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <dev/cons.h>
 
 /*
  * Machine independent support for PCI serial console support.

Reply via email to