svn commit: r355555 - in head/sys: conf powerpc/powernv powerpc/pseries

Leandro Lupori luporl at FreeBSD.org
Mon Dec 9 13:09:33 UTC 2019


Author: luporl
Date: Mon Dec  9 13:09:32 2019
New Revision: 355555
URL: https://svnweb.freebsd.org/changeset/base/355555

Log:
  [PPC64] Enable opal console use as a GDB DBGPORT
  
  This change makes it possible to use OPAL console as a GDB debug port.
  
  Similar to uart and uart_phyp debug ports, it has to be enabled by
  setting the hw.uart.dbgport variable to the serial console node
  of the device tree.
  
  Reviewed by:	jhibbits
  Differential Revision:	https://reviews.freebsd.org/D22649

Added:
  head/sys/powerpc/powernv/opal_dbg.c   (contents, props changed)
Modified:
  head/sys/conf/files.powerpc
  head/sys/powerpc/pseries/phyp_dbg.c

Modified: head/sys/conf/files.powerpc
==============================================================================
--- head/sys/conf/files.powerpc	Mon Dec  9 10:21:24 2019	(r355554)
+++ head/sys/conf/files.powerpc	Mon Dec  9 13:09:32 2019	(r355555)
@@ -185,6 +185,7 @@ powerpc/powermac/vcoregpio.c	optional	powermac 
 powerpc/powernv/opal.c		optional	powernv
 powerpc/powernv/opal_async.c	optional	powernv
 powerpc/powernv/opal_console.c	optional	powernv
+powerpc/powernv/opal_dbg.c	optional	powernv gdb
 powerpc/powernv/opal_dev.c	optional	powernv
 powerpc/powernv/opal_flash.c	optional	powernv opalflash
 powerpc/powernv/opal_hmi.c	optional	powernv

Added: head/sys/powerpc/powernv/opal_dbg.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/powerpc/powernv/opal_dbg.c	Mon Dec  9 13:09:32 2019	(r355555)
@@ -0,0 +1,151 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ *
+ * Copyright (C) 2019 Leandro Lupori
+ *
+ * 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.
+ *
+ * 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 TOOLS GMBH 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/linker_set.h>
+#include <sys/param.h>
+#include <sys/types.h>
+
+struct thread;
+
+#include <vm/vm.h>
+#include <vm/pmap.h>
+
+#include <dev/ofw/openfirm.h>
+#include <gdb/gdb.h>
+
+#include "opal.h"
+
+static gdb_probe_f uart_opal_dbg_probe;
+static gdb_init_f uart_opal_dbg_init;
+static gdb_term_f uart_opal_dbg_term;
+static gdb_getc_f uart_opal_dbg_getc;
+static gdb_putc_f uart_opal_dbg_putc;
+
+GDB_DBGPORT(uart_opal, uart_opal_dbg_probe,
+    uart_opal_dbg_init, uart_opal_dbg_term,
+    uart_opal_dbg_getc, uart_opal_dbg_putc);
+
+static int64_t termnum;
+
+static int
+uart_opal_dbg_probe(void)
+{
+	char buf[64];
+	cell_t reg;
+	phandle_t dev;
+
+	if (!getenv_string("hw.uart.dbgport", buf, sizeof(buf)))
+		return (-1);
+	if ((dev = OF_finddevice(buf)) == -1)
+		return (-1);
+
+	if (OF_getprop(dev, "device_type", buf, sizeof(buf)) == -1)
+		return (-1);
+	if (strcmp(buf, "serial") != 0)
+		return (-1);
+
+	if (OF_getprop(dev, "compatible", buf, sizeof(buf)) == -1)
+		return (-1);
+	if (strcmp(buf, "ibm,opal-console-raw") != 0)
+		return (-1);
+
+	reg = ~0U;
+	OF_getencprop(dev, "reg", &reg, sizeof(reg));
+	if (reg == ~0U)
+		return (-1);
+	termnum = reg;
+
+	return (0);
+}
+
+static void
+uart_opal_dbg_init(void)
+{
+}
+
+static void
+uart_opal_dbg_term(void)
+{
+}
+
+static int
+uart_opal_dbg_getc(void)
+{
+	char c;
+	int err;
+	int64_t len;
+	uint64_t lenp, bufp;
+
+	len = 1;
+	if (pmap_bootstrapped) {
+		lenp = vtophys(&len);
+		bufp = vtophys(&c);
+	} else {
+		lenp = (uint64_t)&len;
+		bufp = (uint64_t)&c;
+	}
+
+	err = opal_call(OPAL_CONSOLE_READ, termnum, lenp, bufp);
+	if (err != OPAL_SUCCESS || len != 1)
+		return (-1);
+
+	opal_call(OPAL_POLL_EVENTS, NULL);
+
+	return (c);
+}
+
+static void
+uart_opal_dbg_putc(int c)
+{
+	char ch;
+	int err;
+	int64_t len;
+	uint64_t lenp, bufp;
+
+	ch = (unsigned char)c;
+	len = 1;
+	if (pmap_bootstrapped) {
+		lenp = vtophys(&len);
+		bufp = vtophys(&ch);
+	} else {
+		lenp = (uint64_t)&len;
+		bufp = (uint64_t)&ch;
+	}
+
+	for (;;) {
+		err = opal_call(OPAL_CONSOLE_WRITE, termnum, lenp, bufp);
+		/* Clear FIFO if needed. */
+		if (err == OPAL_BUSY_EVENT)
+			opal_call(OPAL_POLL_EVENTS, NULL);
+		else
+			/* break on success or unrecoverable errors */
+			break;
+	}
+	DELAY(100);
+}

Modified: head/sys/powerpc/pseries/phyp_dbg.c
==============================================================================
--- head/sys/powerpc/pseries/phyp_dbg.c	Mon Dec  9 10:21:24 2019	(r355554)
+++ head/sys/powerpc/pseries/phyp_dbg.c	Mon Dec  9 13:09:32 2019	(r355555)
@@ -60,7 +60,7 @@ uart_phyp_dbg_probe(void)
 	cell_t reg;
 	phandle_t vty;
 
-	if (!getenv_string("hw.uart_phyp.dbgport", buf, sizeof(buf)))
+	if (!getenv_string("hw.uart.dbgport", buf, sizeof(buf)))
 		return (-1);
 
 	if ((vty = OF_finddevice(buf)) == -1)


More information about the svn-src-all mailing list