[PATCH 2/3] riscv: SBI as the interface for the early console

Jinglin Wen posted 3 patches 1 year, 10 months ago
[PATCH 2/3] riscv: SBI as the interface for the early console
Posted by Jinglin Wen 1 year, 10 months ago
Use the SBI interface as the early console output interface
for the RISC-V platform.

Signed-off-by: Jinglin Wen <jinglin.wen@shingroup.cn>
---
 drivers/tty/hvc/Kconfig         | 12 ++++++++++++
 drivers/tty/hvc/hvc_riscv_sbi.c | 29 +++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/drivers/tty/hvc/Kconfig b/drivers/tty/hvc/Kconfig
index c2a4e88b328f..48658d2b700c 100644
--- a/drivers/tty/hvc/Kconfig
+++ b/drivers/tty/hvc/Kconfig
@@ -118,6 +118,18 @@ config HVC_RISCV_SBI
 
 	  If you don't know what do to here, say N.
 
+config RISCV_EARLY_CONSOLE_SBI
+	bool "Use SBI as the interface for RISC-V early console"
+	depends on RISCV
+	help
+	  Choose 'Y' to use the SBI interface as the early console
+	  output interface for the RISC-V platform.
+
+	  This configuration is a temporary setup for debugging
+	  purposes during the boot process to address issues as
+	  early as possible. It should not be enabled in production
+	  kernel.
+
 config HVCS
 	tristate "IBM Hypervisor Virtual Console Server support"
 	depends on PPC_PSERIES && HVC_CONSOLE
diff --git a/drivers/tty/hvc/hvc_riscv_sbi.c b/drivers/tty/hvc/hvc_riscv_sbi.c
index cede8a572594..6686dcf62853 100644
--- a/drivers/tty/hvc/hvc_riscv_sbi.c
+++ b/drivers/tty/hvc/hvc_riscv_sbi.c
@@ -12,6 +12,7 @@
 #include <linux/types.h>
 
 #include <asm/sbi.h>
+#include <asm/early_console.h>
 
 #include "hvc_console.h"
 
@@ -81,3 +82,31 @@ static int __init hvc_sbi_init(void)
 	return 0;
 }
 device_initcall(hvc_sbi_init);
+
+#ifdef CONFIG_RISCV_EARLY_CONSOLE_SBI
+static ssize_t (*sbi_early_putc_common)(uint32_t vtermno, const u8 *buf, size_t count);
+
+static void sbi_early_putc(char c)
+{
+	unsigned int termno = 0;
+	int count = -1;
+
+	if (c == '\n')
+		sbi_early_putc('\r');
+
+	do {
+		count = sbi_early_putc_common(termno, &c, 1);
+	} while (count == 0 || count == -EAGAIN);
+}
+
+void __init hvc_sbi_early_init(void (**putc)(char c))
+{
+	if (sbi_debug_console_available)
+		sbi_early_putc_common = hvc_sbi_dbcn_tty_put;
+	else if (IS_ENABLED(CONFIG_RISCV_SBI_V01))
+		sbi_early_putc_common = hvc_sbi_tty_put;
+
+	if (sbi_early_putc_common)
+		*putc = sbi_early_putc;
+}
+#endif
-- 
2.25.1
Re: [PATCH 2/3] riscv: SBI as the interface for the early console
Posted by kernel test robot 1 year, 9 months ago
Hi Jinglin,

kernel test robot noticed the following build errors:

[auto build test ERROR on tty/tty-testing]
[also build test ERROR on tty/tty-next tty/tty-linus linus/master v6.9-rc4 next-20240416]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jinglin-Wen/riscv-Support-for-early-console/20240410-143840
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
patch link:    https://lore.kernel.org/r/20240410063432.23058-3-jinglin.wen%40shingroup.cn
patch subject: [PATCH 2/3] riscv: SBI as the interface for the early console
config: riscv-randconfig-r071-20240417 (https://download.01.org/0day-ci/archive/20240417/202404171502.Yz861Nvd-lkp@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240417/202404171502.Yz861Nvd-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202404171502.Yz861Nvd-lkp@intel.com/

All errors (new ones prefixed by >>):

   riscv64-linux-ld: arch/riscv/kernel/early_console.o: in function `early_console_init':
>> arch/riscv/kernel/early_console.c:100:(.init.text+0x18): undefined reference to `hvc_sbi_early_init'


vim +100 arch/riscv/kernel/early_console.c

f4e6608ec4adae Jinglin Wen 2024-04-10   87  
f4e6608ec4adae Jinglin Wen 2024-04-10   88  /*
f4e6608ec4adae Jinglin Wen 2024-04-10   89   * This is called after sbi_init.
f4e6608ec4adae Jinglin Wen 2024-04-10   90   */
f4e6608ec4adae Jinglin Wen 2024-04-10   91  void __init early_console_init(void)
f4e6608ec4adae Jinglin Wen 2024-04-10   92  {
f4e6608ec4adae Jinglin Wen 2024-04-10   93  	/*
f4e6608ec4adae Jinglin Wen 2024-04-10   94  	 * Set riscv_early_console_putc.
f4e6608ec4adae Jinglin Wen 2024-04-10   95  	 * If there are other output interfaces, you can add corresponding code
f4e6608ec4adae Jinglin Wen 2024-04-10   96  	 * to initialize riscv_early_console_putc.
f4e6608ec4adae Jinglin Wen 2024-04-10   97  	 */
f4e6608ec4adae Jinglin Wen 2024-04-10   98  #if defined(CONFIG_RISCV_EARLY_CONSOLE_SBI)
f4e6608ec4adae Jinglin Wen 2024-04-10   99  	/* using the sbi */
f4e6608ec4adae Jinglin Wen 2024-04-10 @100  	hvc_sbi_early_init(&riscv_early_console_putc);
f4e6608ec4adae Jinglin Wen 2024-04-10  101  #else
f4e6608ec4adae Jinglin Wen 2024-04-10  102  	/* using other */
f4e6608ec4adae Jinglin Wen 2024-04-10  103  #endif
f4e6608ec4adae Jinglin Wen 2024-04-10  104  
f4e6608ec4adae Jinglin Wen 2024-04-10  105  	console_loglevel = CONSOLE_LOGLEVEL_MOTORMOUTH;
f4e6608ec4adae Jinglin Wen 2024-04-10  106  	register_early_console();
f4e6608ec4adae Jinglin Wen 2024-04-10  107  }
f4e6608ec4adae Jinglin Wen 2024-04-10  108  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki