Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1358729rdh; Fri, 27 Oct 2023 11:42:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEuP9HklN3NYsvGbfyg8FGjol5ChYKtkTCTJ4U0f4HpJWfI8nLLG1nCbB4SnVIA3KuDE29y X-Received: by 2002:a25:d186:0:b0:d9a:3bf1:35e9 with SMTP id i128-20020a25d186000000b00d9a3bf135e9mr3669659ybg.3.1698432167539; Fri, 27 Oct 2023 11:42:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698432167; cv=none; d=google.com; s=arc-20160816; b=U5g+uuBcuvG5SMQYazm+x89V0+mySYJtHqcMVyPx32k4/ppIGTIIztxiwVaHxomDRU vtLnd5pSrSXAl09IEvBdUTZcnDD9mN5ueIsG45uRaTXTgnhUe9g9VdhBrlM1hFyV1NLS 2FA0WjU0yrPH1JysR3P5oFhO87fE1sttetqJPM/SB8MhLbTbX/2Hc/jpRwTn4gH59jzS 9/B7FCkXKy+ml8aNfBHnxqq1GWxC4E9oWed7y081HhIV9r8f0VWx+MKl6SBOFYYJEkAK BmE8U+3gTGvYp9/6k0iERE9WgTJv+R7PEh2Gk+WA48BoopZPeSQTOxqRVMmbBfoHW9sg US5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=yIBHHJoeBZonb5tndpSrM+X2Yc5Shk4jUNpLuZRp3To=; fh=2THP7SIVSTHYjaZ+qoFRou3s/8abGq7E8rX+Q6jzkpQ=; b=OeNjgr86Hgg+ftcKPi2pIK/1RTEAx5kmb5UfMNr7yEH+g4qHsHp1lFX86+eoMxB+w7 D0tq1kEXwEzUmvgDinqjToju9u0MCGtYfWAmbEvkCUSJH4i3fq1+Kiv92kMk43/Sxk0U wG1/5RrIdiA1XMeSJ9QgbJj7taFICt9NhKQRZms4dFa5rXsMucoMZr3HiTgV2L+wyoyL WkeR7JUFsKayeRy/8McFg2hqTMr5msgGKrke04blaLOXdCkRYul4kpI/CbvF43ENUgy4 JCK16yBLBCdafDaCulWb14UMgDFc164NXjK8isUGYifJrG+ibQN585+/Gpx97bZ4LKgP Y8dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@flygoat.com header.s=fm1 header.b=MM3wd7zq; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=l2sWnMmC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id 125-20020a250a83000000b00d9a4a758d53si3223573ybk.83.2023.10.27.11.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 11:42:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@flygoat.com header.s=fm1 header.b=MM3wd7zq; dkim=pass header.i=@messagingengine.com header.s=fm3 header.b=l2sWnMmC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=flygoat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 610AD82CB516; Fri, 27 Oct 2023 11:42:23 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346529AbjJ0SmO (ORCPT + 99 others); Fri, 27 Oct 2023 14:42:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346393AbjJ0Slz (ORCPT ); Fri, 27 Oct 2023 14:41:55 -0400 Received: from wout2-smtp.messagingengine.com (wout2-smtp.messagingengine.com [64.147.123.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE8D555AA; Fri, 27 Oct 2023 11:30:54 -0700 (PDT) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 063313200A1C; Fri, 27 Oct 2023 14:27:18 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 27 Oct 2023 14:27:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1698431238; x= 1698517638; bh=yIBHHJoeBZonb5tndpSrM+X2Yc5Shk4jUNpLuZRp3To=; b=M M3wd7zqrJC5qXl9sTmLvySfmGQgaon1ZtJSJykSv1wYpkQeCN3718Pl4AU4lW1Tb CoGyagVsVe4ralBcTx4pqHDePWZtxT6WollHVWZeieaOsq7/aozUdSdTgiGyg5vF ptRoMVkp+dOSnUtkoCiRqycWuuKlakRxVRtFQbLzmwnPwZQfPjBiUx1h4rZy2a29 GPrgorQE7sl3fJjOtzPifcHYAx01YzY5vV8oSjvZq8MYKDFXYNB95Lrr53cxvChM RueITPoH/FAm1z8aCaWRr94DZyINNSwbwvgli+QN31wjU4LA5k+GRd0UIX27myS6 JYDQbG8fWbsOBf68kc1Gw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1698431238; x= 1698517638; bh=yIBHHJoeBZonb5tndpSrM+X2Yc5Shk4jUNpLuZRp3To=; b=l 2sWnMmC28aBM+5g5OlaoLLhCE03Bvf2w5T/NFjg1thPC5zFMxB8l/cMqIznFlPyZ /7afcKESaqeoCrfGtz2cXA2NpLbY7Rvb50JD6JcDTAAIWIB6Q0LtNkkxbsJ0iMFY mc1SX+AqRtxn8bQJn/IKqmRTBHRbDJTRmD1ngHnNaXOniMYuIdurq5gaNfYmyuNC T416LAGmdkLMP8rxcj4EEybqgFsockgWHp2mZ7Xrh/5OsSukKgZz9j8ww4Tc9gFP GZvx8oWIbomZlXTkpn/ZMAN3VezZCaYLE7AGZumJH/PID5gSPcn+qDiqfG7L8njD VFWOCHHGstPXiMyW/BjVA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrleeggdduvdeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtke ertdertddtnecuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghn ghesfhhlhihgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepfeeludefheegvdeuvd dvgeekgfdvtdettdelieeihfegtedugeekhfdvhfejfedtnecuvehluhhsthgvrhfuihii vgepvdenucfrrghrrghmpehmrghilhhfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhi hgohgrthdrtghomh X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 27 Oct 2023 14:27:17 -0400 (EDT) From: Jiaxun Yang To: linux-mips@vger.kernel.org Cc: linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org, tsbogend@alpha.franken.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, Jiaxun Yang Subject: [PATCH 3/3] serial: Add an earlycon driver for MIPS UHI semihosting Date: Fri, 27 Oct 2023 19:26:50 +0100 Message-Id: <20231027182650.281405-8-jiaxun.yang@flygoat.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027182650.281405-1-jiaxun.yang@flygoat.com> References: <20231027182650.281405-1-jiaxun.yang@flygoat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 27 Oct 2023 11:42:23 -0700 (PDT) UHI is MIPS's implementation of semihosting. Add an earlycon driver to help with debugging on boot. This driver is capable for print log using UHI's "Plog" or interact with KGDB using UHI's stdio function. Signed-off-by: Jiaxun Yang --- drivers/tty/serial/Kconfig | 13 ++++ drivers/tty/serial/Makefile | 1 + drivers/tty/serial/earlycon-mips-uhi.c | 85 ++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 drivers/tty/serial/earlycon-mips-uhi.c diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index bdc568a4ab66..04c62c6b45cd 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig @@ -85,6 +85,19 @@ config SERIAL_EARLYCON_SEMIHOST This is enabled with "earlycon=smh" on the kernel command line. The console is enabled when early_param is processed. +config SERIAL_EARLYCON_UHI + bool "Early console using MIPS UHI semihosting" + depends on MIPS + select SERIAL_CORE + select SERIAL_CORE_CONSOLE + select SERIAL_EARLYCON + help + Support for early debug console using UHI semihosting. + This enables the console before standard serial driver is probed. + This is enabled with "earlycon=uhi" or "earlycon=uhi_stdio" on the + kernel command line. + The console is enabled when early_param is processed. + config SERIAL_EARLYCON_RISCV_SBI bool "Early console using RISC-V SBI" depends on RISCV_SBI_V01 diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile index f6b8c220dcfb..ef5e9c87aea1 100644 --- a/drivers/tty/serial/Makefile +++ b/drivers/tty/serial/Makefile @@ -9,6 +9,7 @@ serial_base-y := serial_core.o serial_base_bus.o serial_ctrl.o serial_port.o obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o obj-$(CONFIG_SERIAL_EARLYCON_SEMIHOST) += earlycon-semihost.o obj-$(CONFIG_SERIAL_EARLYCON_RISCV_SBI) += earlycon-riscv-sbi.o +obj-$(CONFIG_SERIAL_EARLYCON_MIPS_UHI) += earlycon-mips-uhi.o # These Sparc drivers have to appear before others such as 8250 # which share ttySx minor node space. Otherwise console device diff --git a/drivers/tty/serial/earlycon-mips-uhi.c b/drivers/tty/serial/earlycon-mips-uhi.c new file mode 100644 index 000000000000..002bb2c37064 --- /dev/null +++ b/drivers/tty/serial/earlycon-mips-uhi.c @@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * MIPS UHI semihosting based earlycon + * + * Copyright (C) 2023 Jiaxun Yang + */ + +#include +#include +#include +#include +#include + +static int stdin_fd = -1; +static int stdout_fd = -1; + +static void uhi_plog_write(struct console *con, const char *s, unsigned int n) +{ + uhi_plog(s, 0); +} + +static void uhi_stdout_write(struct console *con, const char *s, unsigned int n) +{ + if (stdout_fd < 0) + return; + + uhi_write(stdout_fd, s, n); +} + +#ifdef CONFIG_CONSOLE_POLL +static int uhi_stdin_read(struct console *con, char *s, unsigned int n) +{ + if (stdin_fd < 0) + return 0; + + return uhi_read(stdin_fd, s, n); +} +#endif + +static int uhi_stdio_fd_open(struct console *co, char *options) +{ + /* + * You have to open both stdin and stdout to get console work + * properly on some old CodeScape debugger. + */ + stdin_fd = uhi_open("/dev/stdin", UHI_O_RDONLY, 0); + stdout_fd = uhi_open("/dev/stdout", UHI_O_WRONLY, 0); + + return (stdin_fd < 0 || stdout_fd < 0) ? -ENODEV : 0; +} + +static int uhi_stdio_fd_close(struct console *co) +{ + int ret1 = 0, ret2 = 0; + + if (stdin_fd >= 0) + ret1 = uhi_close(stdin_fd); + if (stdout_fd >= 0) + ret2 = uhi_close(stdout_fd); + + return (ret1 < 0 || ret2 < 0) ? -ENODEV : 0; +} + +static int +__init early_uhi_setup(struct earlycon_device *device, const char *opt) +{ + device->con->write = uhi_plog_write; + return 0; +} + +static int +__init early_uhi_stdio_setup(struct earlycon_device *device, const char *opt) +{ + + device->con->setup = uhi_stdio_fd_open; + device->con->exit = uhi_stdio_fd_close; + device->con->write = uhi_stdout_write; +#ifdef CONFIG_CONSOLE_POLL + device->con->read = uhi_stdin_read; +#endif + return 0; +} + +EARLYCON_DECLARE(uhi, early_uhi_setup); +EARLYCON_DECLARE(uhi_stdio, early_uhi_stdio_setup); -- 2.34.1