Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp65816ybh; Tue, 17 Mar 2020 18:14:38 -0700 (PDT) X-Google-Smtp-Source: ADFU+vv/Vtq4N+fzI4cs+ylIXrG8V5NpvDSL3R1Fk52NhOzzk3TbtyyMvnasg1DLv5MPLl6QpgBb X-Received: by 2002:aca:a882:: with SMTP id r124mr1395199oie.53.1584494078422; Tue, 17 Mar 2020 18:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584494078; cv=none; d=google.com; s=arc-20160816; b=X4pMS73d4/RtdXICVm7luPQ5S557MorI9IQojY12s9GEYvs6wr39clYfGPLO4FmQNI +FNST1tD+cfZzGp3fPEckLMDLrclkLSNSQmQXogTiXG+Y+kMW2BPR7mVY8LiK7Z5RuqS OkNLBUzpqRRJSQVko8fRaLXbz1RScD3NdOJzz4zVsZK7uGJcyaglEaiDr5HvmG8nc0C1 1ckkt8zjgI4sHe28+kxnAOJiC/jgMWVNXOAPORS2s549OzlKPojQ+LirAiUFADgK7Y+4 NLqwEPaN7SX52ukY/19HWv3QORZ6U9xI5hyfEC0HRRBl5907QzWfQICXAClTsjc1s5yc pFJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=nj95covzh6pKBRACc+ZMgUW+nACK5dnkjBXCnasC134=; b=XsfhPlKOKf4bI9nBe5vXrcKF4nirCX2wqkfdqxUMLQ5pDoVARCblIHptU4AHgLBP5c 6wXwoymA1Oh2prswYz8PJtBZZNtz7iBaTrUsHSdAAf5fNnpCam2B+6kle2otGb9WsO5H ZQJSr12NAU/UtlrCvD/uY7zNaU1mIe551oy4tONj3QGObtB176QmI+WIC9eKTDXXXJqv 7027MVK4W5ElwCZjECPNlmv/u0zDeGqgo01lqVcGx7jaOTWlCq16T6qz0PCV/NnNeLDi Db8/HH6WfC0GAtWJQTlItCdCKRiVn2Z3UTPId20cCeQr3HfD9iFHhF3Ydv99HB8rQuZd XWYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=kr7KOnMY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a128si2354650oif.202.2020.03.17.18.14.26; Tue, 17 Mar 2020 18:14:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=kr7KOnMY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727530AbgCRBM1 (ORCPT + 99 others); Tue, 17 Mar 2020 21:12:27 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:45899 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727282AbgCRBL6 (ORCPT ); Tue, 17 Mar 2020 21:11:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584493918; x=1616029918; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vKrUz+xg5193R5R2QD6sHPvXr4GmfWWm9BHn5r97q2U=; b=kr7KOnMYydcu5abvB57Cpb1TY2LS1I0fFxUod98q6at3g/scFIi6QTao eKE9AaVgr1bm8zTdhMCPGwJpricaECziMFtLhPH4xEUJniTblQ+9QlaYN SxbLLpZb0oqNHmVWs2TWR5SSd7MlinwFDq2i+PCyCxAcgz895wXt7uO3S g1Hn21xLR2JMaCNo90Y6Z4v759Rdbj5Yyle8ylnLpmFXA9uNE4QgNoelB dDhRjZm5c/qmLwPkZqWQh/ArOll6iibY5zB3UYMOIHWG4/qikacpyHkG1 XEJaI0nPynuNTtDGIKX3sFG3J/1sEDlIZpFkgkMrXNAjPitzi79+o9BU3 A==; IronPort-SDR: q6E+M2nacpdUb70AJ2Dh/m7EvNJe+mIgRyvqfqFcYghBwVX91Rfa13DjL4l5XHUaqobnZNrUHz GLFgmcWoXs08qBCsnrfQgiLjKsjdk+tSj1tNIwyIapLGNFq3C8dwD7DaesUOxw1lsxiCei4q9o a75a7bkllb+Aq2aUqpucfrWDdz4Y4T1qCG6fylVqOw22Put5/CA5nSvy5521oebUdN8lAWuf01 3/M36goRUj3ip84YMX/db8S/2AoWcWDv0DRsh7HllCLSlB6Hr7kr95iuWVoF0BqZSakEJi5+68 SGo= X-IronPort-AV: E=Sophos;i="5.70,565,1574092800"; d="scan'208";a="133241508" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 18 Mar 2020 09:11:58 +0800 IronPort-SDR: xhQVD81Vmv75k4eeGenx4czPnG48pc/jChSUdsdc0/pifRdgwyPaKCSErTqTD3XCcxuQ9jJt+q ncVf2kTvyh2cx5EWGiFFVlCuoVA4pPZyl2+3vFvapaenbV1Q0RCdCNh4R13VylF6PIB3GBIhK8 xReJPJRgUkJof79JL7S1WrORXxXgLXjnhp7a1Hk4J93tuhAKeyp7pC+EtfzsagHRZXoxWsaEX0 OKR+FF1ZZYDQVnE0qyzoh01M4ffH3Om6nrn+BCe9q5X5dx0eyJW8CEoxAp9+tC7sYGKTRJl5u6 pCLJQMlMAQaKhIs4aLrs6NGF Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2020 18:03:48 -0700 IronPort-SDR: Zzsqh3K4c1R/p9+SJYJMtUAf/6eUSBi6C4L6SjmedTFMfvS8C9LfXtLTZlXfe3QzQjJNsX9pYo tn+JeQzbvcw6rsi2HEd+YDe6xdAeWfIZFqgE3fqqGrnoBLsUfDZy0bEqRPl9lPq2BrM/8axL9m RZSsaJuMoRA7Lr6ajmfgxep3Vh2JJtl25oOQFF4HyWQAz/NsH4LGVEc7cUG8g9q9Dy5oEypxwa hMtYo5pJ83rxXPZJqY7yOJG2WYGnfZGBRboTUoZHwnn93CT1A9Zq0ADUyyxwcTphxEs6ZIujdc gM8= WDCIronportException: Internal Received: from mccorma-lt.ad.shared (HELO yoda.hgst.com) ([10.86.54.125]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Mar 2020 18:11:58 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Albert Ou , Gary Guo , Greentime Hu , linux-riscv@lists.infradead.org, Mao Han , Mike Rapoport , Nick Hu , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Vincent Chen , Zong Li , Bin Meng Subject: [PATCH v11 04/11] RISC-V: Introduce a new config for SBI v0.1 Date: Tue, 17 Mar 2020 18:11:37 -0700 Message-Id: <20200318011144.91532-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200318011144.91532-1-atish.patra@wdc.com> References: <20200318011144.91532-1-atish.patra@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We now have SBI v0.2 which is more scalable and extendable to handle future needs for RISC-V supervisor interfaces. Introduce a new config and move all SBI v0.1 code under that config. This allows to implement the new replacement SBI extensions cleanly and remove v0.1 extensions easily in future. Currently, the config is enabled by default. Once all M-mode software, with v0.1, is no longer in use, this config option and all relevant code can be easily removed. Signed-off-by: Atish Patra Reviewed-by: Anup Patel --- arch/riscv/Kconfig | 7 ++ arch/riscv/include/asm/sbi.h | 2 + arch/riscv/kernel/sbi.c | 132 +++++++++++++++++++++++++++++------ 3 files changed, 118 insertions(+), 23 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 1a3b5a5276be..20c6191399ea 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -308,6 +308,13 @@ config SECCOMP and the task is only allowed to execute a few safe syscalls defined by each seccomp mode. +config RISCV_SBI_V01 + bool "SBI v0.1 support" + default y + depends on RISCV_SBI + help + This config allows kernel to use SBI v0.1 APIs. This will be + deprecated in future once legacy M-mode software are no longer in use. endmenu menu "Boot options" diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h index f68b6ed10a18..d712b61f8dbc 100644 --- a/arch/riscv/include/asm/sbi.h +++ b/arch/riscv/include/asm/sbi.h @@ -11,6 +11,7 @@ #ifdef CONFIG_RISCV_SBI enum sbi_ext_id { +#ifdef CONFIG_RISCV_SBI_V01 SBI_EXT_0_1_SET_TIMER = 0x0, SBI_EXT_0_1_CONSOLE_PUTCHAR = 0x1, SBI_EXT_0_1_CONSOLE_GETCHAR = 0x2, @@ -20,6 +21,7 @@ enum sbi_ext_id { SBI_EXT_0_1_REMOTE_SFENCE_VMA = 0x6, SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID = 0x7, SBI_EXT_0_1_SHUTDOWN = 0x8, +#endif SBI_EXT_BASE = 0x10, SBI_EXT_TIME = 0x54494D45, SBI_EXT_IPI = 0x735049, diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c index 4aee0b49df3c..1368da62ec82 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -13,6 +13,12 @@ unsigned long sbi_spec_version = SBI_SPEC_VERSION_DEFAULT; EXPORT_SYMBOL(sbi_spec_version); +static void (*__sbi_set_timer)(uint64_t stime); +static int (*__sbi_send_ipi)(const unsigned long *hart_mask); +static int (*__sbi_rfence)(int fid, const unsigned long *hart_mask, + unsigned long start, unsigned long size, + unsigned long arg4, unsigned long arg5); + struct sbiret sbi_ecall(int ext, int fid, unsigned long arg0, unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, @@ -57,6 +63,7 @@ static int sbi_err_map_linux_errno(int err) }; } +#ifdef CONFIG_RISCV_SBI_V01 /** * sbi_console_putchar() - Writes given character to the console device. * @ch: The data to be written to the console. @@ -85,12 +92,34 @@ int sbi_console_getchar(void) EXPORT_SYMBOL(sbi_console_getchar); /** - * sbi_set_timer() - Program the timer for next timer event. + * sbi_shutdown() - Remove all the harts from executing supervisor code. + * + * Return: None + */ +void sbi_shutdown(void) +{ + sbi_ecall(SBI_EXT_0_1_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0); +} +EXPORT_SYMBOL(sbi_set_timer); + +/** + * sbi_clear_ipi() - Clear any pending IPIs for the calling hart. + * + * Return: None + */ +void sbi_clear_ipi(void) +{ + sbi_ecall(SBI_EXT_0_1_CLEAR_IPI, 0, 0, 0, 0, 0, 0, 0); +} +EXPORT_SYMBOL(sbi_shutdown); + +/** + * sbi_set_timer_v01() - Program the timer for next timer event. * @stime_value: The value after which next timer event should fire. * * Return: None */ -void sbi_set_timer(uint64_t stime_value) +static void __sbi_set_timer_v01(uint64_t stime_value) { #if __riscv_xlen == 32 sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, @@ -99,27 +128,78 @@ void sbi_set_timer(uint64_t stime_value) sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, 0, 0, 0, 0, 0); #endif } -EXPORT_SYMBOL(sbi_set_timer); -/** - * sbi_shutdown() - Remove all the harts from executing supervisor code. - * - * Return: None - */ -void sbi_shutdown(void) +static int __sbi_send_ipi_v01(const unsigned long *hart_mask) { - sbi_ecall(SBI_EXT_0_1_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0); + sbi_ecall(SBI_EXT_0_1_SEND_IPI, 0, (unsigned long)hart_mask, + 0, 0, 0, 0, 0); + return 0; } -EXPORT_SYMBOL(sbi_shutdown); + +static int __sbi_rfence_v01(int fid, const unsigned long *hart_mask, + unsigned long start, unsigned long size, + unsigned long arg4, unsigned long arg5) +{ + int result = 0; + + /* v0.2 function IDs are equivalent to v0.1 extension IDs */ + switch (fid) { + case SBI_EXT_RFENCE_REMOTE_FENCE_I: + sbi_ecall(SBI_EXT_0_1_REMOTE_FENCE_I, 0, + (unsigned long)hart_mask, 0, 0, 0, 0, 0); + break; + case SBI_EXT_RFENCE_REMOTE_SFENCE_VMA: + sbi_ecall(SBI_EXT_0_1_REMOTE_SFENCE_VMA, 0, + (unsigned long)hart_mask, start, size, + 0, 0, 0); + break; + case SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID: + sbi_ecall(SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, 0, + (unsigned long)hart_mask, start, size, + arg4, 0, 0); + break; + default: + pr_err("SBI call [%d]not supported in SBI v0.1\n", fid); + result = -EINVAL; + } + + return result; +} +#else +static void __sbi_set_timer_v01(uint64_t stime_value) +{ + pr_warn("Timer extension is not available in SBI v%lu.%lu\n", + sbi_major_version(), sbi_minor_version()); +} + +static int __sbi_send_ipi_v01(const unsigned long *hart_mask) +{ + pr_warn("IPI extension is not available in SBI v%lu.%lu\n", + sbi_major_version(), sbi_minor_version()); + + return 0; +} + +static int __sbi_rfence_v01(int fid, const unsigned long *hart_mask, + unsigned long start, unsigned long size, + unsigned long arg4, unsigned long arg5) +{ + pr_warn("remote fence extension is not available in SBI v%lu.%lu\n", + sbi_major_version(), sbi_minor_version()); + + return 0; +} +#endif /* CONFIG_RISCV_SBI_V01 */ /** - * sbi_clear_ipi() - Clear any pending IPIs for the calling hart. + * sbi_set_timer() - Program the timer for next timer event. + * @stime_value: The value after which next timer event should fire. * * Return: None */ -void sbi_clear_ipi(void) +void sbi_set_timer(uint64_t stime_value) { - sbi_ecall(SBI_EXT_0_1_CLEAR_IPI, 0, 0, 0, 0, 0, 0, 0); + __sbi_set_timer(stime_value); } /** @@ -130,8 +210,7 @@ void sbi_clear_ipi(void) */ void sbi_send_ipi(const unsigned long *hart_mask) { - sbi_ecall(SBI_EXT_0_1_SEND_IPI, 0, (unsigned long)hart_mask, - 0, 0, 0, 0, 0); + __sbi_send_ipi(hart_mask); } EXPORT_SYMBOL(sbi_send_ipi); @@ -143,8 +222,8 @@ EXPORT_SYMBOL(sbi_send_ipi); */ void sbi_remote_fence_i(const unsigned long *hart_mask) { - sbi_ecall(SBI_EXT_0_1_REMOTE_FENCE_I, 0, (unsigned long)hart_mask, - 0, 0, 0, 0, 0); + __sbi_rfence(SBI_EXT_RFENCE_REMOTE_FENCE_I, + hart_mask, 0, 0, 0, 0); } EXPORT_SYMBOL(sbi_remote_fence_i); @@ -161,8 +240,8 @@ void sbi_remote_sfence_vma(const unsigned long *hart_mask, unsigned long start, unsigned long size) { - sbi_ecall(SBI_EXT_0_1_REMOTE_SFENCE_VMA, 0, - (unsigned long)hart_mask, start, size, 0, 0, 0); + __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA, + hart_mask, start, size, 0, 0); } EXPORT_SYMBOL(sbi_remote_sfence_vma); @@ -182,8 +261,8 @@ void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, unsigned long size, unsigned long asid) { - sbi_ecall(SBI_EXT_0_1_REMOTE_SFENCE_VMA_ASID, 0, - (unsigned long)hart_mask, start, size, asid, 0, 0); + __sbi_rfence(SBI_EXT_RFENCE_REMOTE_SFENCE_VMA_ASID, + hart_mask, start, size, asid, 0); } EXPORT_SYMBOL(sbi_remote_sfence_vma_asid); @@ -249,8 +328,15 @@ int __init sbi_init(void) pr_info("SBI specification v%lu.%lu detected\n", sbi_major_version(), sbi_minor_version()); - if (!sbi_spec_is_0_1()) + + if (!sbi_spec_is_0_1()) { pr_info("SBI implementation ID=0x%lx Version=0x%lx\n", sbi_get_firmware_id(), sbi_get_firmware_version()); + } + + __sbi_set_timer = __sbi_set_timer_v01; + __sbi_send_ipi = __sbi_send_ipi_v01; + __sbi_rfence = __sbi_rfence_v01; + return 0; } -- 2.25.1