From owner-svn-src-all@freebsd.org Mon Dec 9 13:09:33 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C3B4D1D6780; Mon, 9 Dec 2019 13:09:33 +0000 (UTC) (envelope-from luporl@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 47Wk714b6Kz4bRl; Mon, 9 Dec 2019 13:09:33 +0000 (UTC) (envelope-from luporl@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7A81D1AFFA; Mon, 9 Dec 2019 13:09:33 +0000 (UTC) (envelope-from luporl@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id xB9D9Xnh001683; Mon, 9 Dec 2019 13:09:33 GMT (envelope-from luporl@FreeBSD.org) Received: (from luporl@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id xB9D9W7S001680; Mon, 9 Dec 2019 13:09:32 GMT (envelope-from luporl@FreeBSD.org) Message-Id: <201912091309.xB9D9W7S001680@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: luporl set sender to luporl@FreeBSD.org using -f From: Leandro Lupori Date: Mon, 9 Dec 2019 13:09:32 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r355555 - in head/sys: conf powerpc/powernv powerpc/pseries X-SVN-Group: head X-SVN-Commit-Author: luporl X-SVN-Commit-Paths: in head/sys: conf powerpc/powernv powerpc/pseries X-SVN-Commit-Revision: 355555 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 09 Dec 2019 13:09:33 -0000 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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +struct thread; + +#include +#include + +#include +#include + +#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", ®, 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)