Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2916272rwa; Mon, 22 Aug 2022 16:53:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6HjS5Uar8nWeJCcRaoYWG1puD0xq6zpPwx8QfgWOL7kDQq4WWLxJ+pN8Nr3c+H+yJQ89E4 X-Received: by 2002:a17:902:eb43:b0:172:cd04:a3c9 with SMTP id i3-20020a170902eb4300b00172cd04a3c9mr14204392pli.111.1661212406059; Mon, 22 Aug 2022 16:53:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661212406; cv=none; d=google.com; s=arc-20160816; b=WvpUxRMx7YSSrQvpRnvE68pfyFP177KyDzimzPmo6GANdQATW+Nqr6CAop3HUGubBS JzTJ2+l5PBUiD1qTbS+IAwwhuBdiaeKWxRyRac1ZoUMO1HiIDkSa8bFdAKALSps0wi7r 4y3ZgCB8yf2iXiCqrQKQMKvPB6mk6nCSWk+k0bx5OWABOoQ+zyyxgy9MolTJcvewS9TB /2ElbdvYYV4PW8hVafRaWAprW1TMg0VDg5UKb2yBgBC9N1Zz3pyBZvp3wM+Uels2EgfM cw4OuaLFoWGFVt3Rngi68MW3tpkJDa0s1HnneKHPi7abMGiPwh2S5k0/7Fij27AKVDn2 NbFw== 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 :dkim-signature; bh=DWNJs9NzM9lu6YtxYYBpTGbr6KkssQrv5XP35JaUCFg=; b=xCGU5nnKQCrGabRHHvJMa1Dj/0ZNH1TH3nqYuJZaxXEXMZw9UGwazwV2gvOAcTF6DJ MOnE2X0QPC7Mi734/hbKXx07h5t1ylwfMDXVxtHir1n+KozVjPrlmuppEDpk6d9uwkig xlkvd4zp5H8kFvd9HpNibIdZMSBVY+/VJXQ9awrAXf20opnfM0gX6d8a+C1bIh/pshLD W6p4NG4ugzaEy2EaJhKxwEIih5TBwLRM/1eP2DiGCE5MiNiTnzXT2bcNBhPj0Px17s+I 3DJSjpbiFnEzGdG8HsSOBqBONk5vFsI5RToFsJYf/fCWjuxfkRC9G7NvOt22zqki3nLW 1n3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kb7T2sQG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c196-20020a624ecd000000b00536366cfa93si10121030pfb.197.2022.08.22.16.53.14; Mon, 22 Aug 2022 16:53:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kb7T2sQG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237551AbiHVXPj (ORCPT + 99 others); Mon, 22 Aug 2022 19:15:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238118AbiHVXPc (ORCPT ); Mon, 22 Aug 2022 19:15:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D14222B27B for ; Mon, 22 Aug 2022 16:15:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6E75861360 for ; Mon, 22 Aug 2022 23:15:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75560C433C1; Mon, 22 Aug 2022 23:15:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661210130; bh=N8JZh6pTKTBOA0XZnc33h+Yp6alPmGRwIvBdJCN7Aj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kb7T2sQGPK8dkH8EeeGqffGOH07c0WLL/cUPojmK0PWuWEC/9qff9K5/pcb71ucbX TlSCxNoE0q9kQd/0p0rUX1tf4vl+KwAl0hNpMFfHWIJlCjwWw5uAP51kTkuuaDDcWF HoDILhaI9E4Srjc+WuIQ6N4rw/uf5UjEtx3lOnbt3krsmf/LQgtkqwnVPE3MIJv71w PtJcNzHNFD7gwXJqLvEYSuqx4DWnkJ5mYCVQgBAlE35YpYI2/HNr2zI6uO7ATuiIyN W7Ckomynycpk/iWVBOfsUYFHgfMqznUDQihU7GXwmkthSiyel2iCCVZSw3bJ7ixn89 drvYT/Kic2bpg== Received: by pali.im (Postfix) id 8AF9697B; Tue, 23 Aug 2022 01:15:27 +0200 (CEST) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Nick Child Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] powerpc: Add support for early debugging via Serial 16550 console Date: Tue, 23 Aug 2022 01:15:01 +0200 Message-Id: <20220822231501.16827-1-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20220819211254.22192-1-pali@kernel.org> References: <20220819211254.22192-1-pali@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Currently powerpc early debugging contains lot of platform specific options, but does not support standard UART / serial 16550 console. Later legacy_serial.c code supports registering UART as early debug console from device tree but it is not early during booting, but rather later after machine description code finishes. So for real early debugging via UART is current code unsuitable. Add support for new early debugging option CONFIG_PPC_EARLY_DEBUG_16550 which enable Serial 16550 console on address defined by new option CONFIG_PPC_EARLY_DEBUG_16550_PHYSADDR and by stride by option CONFIG_PPC_EARLY_DEBUG_16550_STRIDE. With this change it is possible to debug powerpc machine descriptor code. For example this early debugging code can print on serial console also "No suitable machine description found" error which is done before legacy_serial.c code. Signed-off-by: Pali Rohár --- Changes in v2: * Move PPC_EARLY_DEBUG_16550 after PPC_EARLY_DEBUG_MEMCONS, so memcons stay default * Add missing dependency on PPC_UDBG_16550 --- Tested on P2020 board. It allowed me do debug and implement this patch series: https://lore.kernel.org/linuxppc-dev/20220819191557.28116-1-pali@kernel.org/ --- arch/powerpc/Kconfig.debug | 15 +++++++++++++++ arch/powerpc/include/asm/udbg.h | 1 + arch/powerpc/kernel/udbg.c | 2 ++ arch/powerpc/kernel/udbg_16550.c | 33 ++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+) diff --git a/arch/powerpc/Kconfig.debug b/arch/powerpc/Kconfig.debug index 9f363c143d86..ad7238d28fa9 100644 --- a/arch/powerpc/Kconfig.debug +++ b/arch/powerpc/Kconfig.debug @@ -283,6 +283,12 @@ config PPC_EARLY_DEBUG_MEMCONS This console provides input and output buffers stored within the kernel BSS and should be safe to select on any system. A debugger can then be used to read kernel output or send input to the console. + +config PPC_EARLY_DEBUG_16550 + bool "Serial 16550" + depends on PPC_UDBG_16550 + help + Select this to enable early debugging via Serial 16550 console endchoice config PPC_MEMCONS_OUTPUT_SIZE @@ -355,6 +361,15 @@ config PPC_EARLY_DEBUG_CPM_ADDR platform probing is done, all platforms selected must share the same address. +config PPC_EARLY_DEBUG_16550_PHYSADDR + hex "Early debug Serial 16550 physical address" + depends on PPC_EARLY_DEBUG_16550 + +config PPC_EARLY_DEBUG_16550_STRIDE + int "Early debug Serial 16550 stride" + depends on PPC_EARLY_DEBUG_16550 + default 1 + config FAIL_IOMMU bool "Fault-injection capability for IOMMU" depends on FAULT_INJECTION diff --git a/arch/powerpc/include/asm/udbg.h b/arch/powerpc/include/asm/udbg.h index b4aa0d88ce2c..20b5a37ab772 100644 --- a/arch/powerpc/include/asm/udbg.h +++ b/arch/powerpc/include/asm/udbg.h @@ -53,6 +53,7 @@ extern void __init udbg_init_ehv_bc(void); extern void __init udbg_init_ps3gelic(void); extern void __init udbg_init_debug_opal_raw(void); extern void __init udbg_init_debug_opal_hvsi(void); +extern void __init udbg_init_debug_16550(void); #endif /* __KERNEL__ */ #endif /* _ASM_POWERPC_UDBG_H */ diff --git a/arch/powerpc/kernel/udbg.c b/arch/powerpc/kernel/udbg.c index b1544b2f6321..92b3fc258d11 100644 --- a/arch/powerpc/kernel/udbg.c +++ b/arch/powerpc/kernel/udbg.c @@ -67,6 +67,8 @@ void __init udbg_early_init(void) udbg_init_debug_opal_raw(); #elif defined(CONFIG_PPC_EARLY_DEBUG_OPAL_HVSI) udbg_init_debug_opal_hvsi(); +#elif defined(CONFIG_PPC_EARLY_DEBUG_16550) + udbg_init_debug_16550(); #endif #ifdef CONFIG_PPC_EARLY_DEBUG diff --git a/arch/powerpc/kernel/udbg_16550.c b/arch/powerpc/kernel/udbg_16550.c index d3942de254c6..46f2d831d7c9 100644 --- a/arch/powerpc/kernel/udbg_16550.c +++ b/arch/powerpc/kernel/udbg_16550.c @@ -8,6 +8,7 @@ #include #include #include +#include extern u8 real_readb(volatile u8 __iomem *addr); extern void real_writeb(u8 data, volatile u8 __iomem *addr); @@ -335,3 +336,35 @@ void __init udbg_init_debug_microwatt(void) } #endif /* CONFIG_PPC_EARLY_DEBUG_MICROWATT */ + +#ifdef CONFIG_PPC_EARLY_DEBUG_16550 + +static void __iomem *udbg_uart_early_addr; + +void __init udbg_init_debug_16550(void) +{ + udbg_uart_early_addr = early_ioremap(CONFIG_PPC_EARLY_DEBUG_16550_PHYSADDR, 0x1000); + udbg_uart_init_mmio(udbg_uart_early_addr, CONFIG_PPC_EARLY_DEBUG_16550_STRIDE); +} + +static int __init udbg_init_debug_16550_ioremap(void) +{ + void __iomem *addr; + + if (!udbg_uart_early_addr) + return 0; + + addr = ioremap(CONFIG_PPC_EARLY_DEBUG_16550_PHYSADDR, 0x1000); + if (WARN_ON(!addr)) + return -ENOMEM; + + udbg_uart_init_mmio(addr, CONFIG_PPC_EARLY_DEBUG_16550_STRIDE); + early_iounmap(udbg_uart_early_addr, 0x1000); + udbg_uart_early_addr = NULL; + + return 0; +} + +early_initcall(udbg_init_debug_16550_ioremap); + +#endif /* CONFIG_PPC_EARLY_DEBUG_16550 */ -- 2.20.1