Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4182301ybl; Mon, 27 Jan 2020 18:31:36 -0800 (PST) X-Google-Smtp-Source: APXvYqz609sydabbayZD0g0iG1UB5Zew+Ac3kOsFBvz46fQNu4Nh8Iyjpla9aepdvo485ZDy5UTP X-Received: by 2002:a9d:6c06:: with SMTP id f6mr15164765otq.318.1580178696666; Mon, 27 Jan 2020 18:31:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580178696; cv=none; d=google.com; s=arc-20160816; b=PoQoqAJDCqdXJUD/363L0jU7tAiRIhmRfFxx9GYV8U4dnYxAWrSF7t4KWv+9TnmtkU 7sIGlcwdozOZxoi+zTS6IhWm/cE+5fQ1ZXC7WvAP6WheqbVc81pndy0wmgvO+IrecOl0 rGlOKid9jrn1VtaoQ0ce8T+/jV192rQnzQVir+J47rH3J7i2BTVoPvjT6wty9TZIFeDD tzNw5l7Ej4N8MjIevtoSof0rTKN8DchHaWRiXFubobZT5XHpsaoQb9HMchKZAAJYCwlJ Dby5a4tCXRbD3Kwexi7tawrwEn6idFjZ7ymWae3INRuPDTIhpxqibw7gccywO/l+PbIo QMwA== 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=3VYB2H/KqfC+KAeh13yGZPYWmKT7vxlcVbLdm3W8it8=; b=CGPh47iq4MHhpG1A40JLayzlfE2iTWnLXwq1kPLUWR5O6KggVGjKuNlg4fWlE+D5sm JbAkDXcV70kZtbe2hRcS5XBjIQyIf/VKlUN9MPbRQDiB/8pXPKBjvjos0xRZ4Qjgkgxd gWw3VGeAICsCL+tAbW+/rr0OtcBKuWy97yky+vMMW1y+47g0/zMWZLqkwqrII5DqURKv OyfADn/swmP1n2fpMmOrYbAbzTQnFvrfrbiHBCS9E38d5Au9p8nghd1onm8WYEAHJZhq P6zTm97ynSbxEAXVc5i79U8LB/A6ZNAl67ly1IlLIgzg7rHePQi0ZhduZRRHkvYI2XYT rhgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=PSdxb2Xi; 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 b191si1115190oii.266.2020.01.27.18.31.19; Mon, 27 Jan 2020 18:31:36 -0800 (PST) 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=PSdxb2Xi; 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 S1728665AbgA1C2d (ORCPT + 99 others); Mon, 27 Jan 2020 21:28:33 -0500 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:43151 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726101AbgA1C2J (ORCPT ); Mon, 27 Jan 2020 21:28:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1580178489; x=1611714489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lLnSSp5V0S7IlrLQUH6dCPgzF3vGX5c4jvbyzeIJGbU=; b=PSdxb2XiHSYraSCAOxtYAzX3Tf/UPE1cvVST4DqPtTWxTNgJr88dHXL7 lAoABSW+uyqMYzgdauWzWjL54KuDIFekJM0uf8NleahjzUUi9eduEVktO 5qjsH6675+GRejJiLjpTLm6xS8hrKTCImeXaxcRoeBgrJrfxQxZM+FXGM ylov1hudlKh9Wsq9urdRhjflecN+lguZu8oy0DbgXvb5PdzX4gGUrzgQY upujAmbZ7A0eMaPTdAAzCQDirhiDooyOwKLTa8nd1a82ez28M/pOZvAis MyHDcJcvJkClwyuJKXyV31z7qSRgt47Y2I1kB48p506q72Mjmd2IMan7X A==; IronPort-SDR: bP96OfuZwNEPkbqMqVibmtxN5Y1I+lGmAw/Ue0SIZXJbTpmOw7eJkW2PNDYWY15FEAh6qOCOps I4f3Bi0BhYbYc+1H5uBph4z4xYxIht4G+KHfI94TWyDNzSoltJM8eJdJImbIrMZrkn/+LvcIEE a2CEP0nhcFYc+nuqwjBGEoO7r7mY0WQxfgKRueZZWWk2331LpBZZ2OSBxT7sum2kUA9HgWbUTI CC4RjAxpctITMHzQqJRp/L35Wpggw2UiryCcxV1kcRoBs522TC0QU7fyZQU/916Z+IElHZnr8I 36I= X-IronPort-AV: E=Sophos;i="5.70,372,1574092800"; d="scan'208";a="132899397" 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; 28 Jan 2020 10:28:09 +0800 IronPort-SDR: LTO82IiLED1yuSs1qPszm+eSqnkBMm8wj8R/m3vNNykA+MSIfs0Spg5To4HXTI/KeiWl34hepx vaKr78vhhFpkwZLiHxiTPtrq4vA3+JHLAV7thrKc3x7hhHtghpt6M7FPmjMF97j4cjLKpoJRiH THi5wzMbRdlwT4wX+AXqyF7MuYgEKP4M/Gy3qIdKn5g6KytLkFAZKVlRDbt0Zh6kgRBZgZcQDZ qz7K7A/CHVUTmsQKRX1cju+8NMnEXvDxUPLSO2qdZ6hvITXm/Vg9Z2Ty3930NOjJgKrDERkDid 9nd/gv/4BFOeAnaIGB+bouYZ 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; 27 Jan 2020 18:21:24 -0800 IronPort-SDR: SUdIAj1+GzrrXDLC63vGKQJTtKpatY3+LM6ZT5CnM2ESlDFhlaCpPUk2r/eGVVjd4bghrL/QVX fqQ79Gb5tdaKonALni64d/O8wcu+rZqrIWPZs2fKXaVhvtpJBjJshfUeBaGelm56hJOdKJljAK wvKkduPA1PSGgNiXBBYrefU6zShMqG9MIdg+b1xXRB4oplxSSfu0PMw/NIxVqrruIWLNR4CNI9 pmM2yO/vQ0F8/nnHGt/MriFtcJMbucUoBW56mlw5fWO4S04NQ7yAo25fRrvqh3V4owtVqakPcS TLM= WDCIronportException: Internal Received: from jedi-01.sdcorp.global.sandisk.com (HELO jedi-01.int.fusionio.com) ([10.11.143.218]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Jan 2020 18:28:09 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Albert Ou , Borislav Petkov , "Eric W. Biederman" , Geert Uytterhoeven , Greentime Hu , Greg Kroah-Hartman , Heiko Carstens , Kees Cook , linux-riscv@lists.infradead.org, Mao Han , Mike Rapoport , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Vincent Chen , abner.chang@hpe.com, clin@suse.com, nickhu@andestech.com, Palmer Dabbelt Subject: [PATCH v7 04/10] RISC-V: Introduce a new config for SBI v0.1 Date: Mon, 27 Jan 2020 18:27:31 -0800 Message-Id: <20200128022737.15371-5-atish.patra@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200128022737.15371-1-atish.patra@wdc.com> References: <20200128022737.15371-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 | 6 ++ arch/riscv/include/asm/sbi.h | 2 + arch/riscv/kernel/sbi.c | 137 +++++++++++++++++++++++++++++------ 3 files changed, 121 insertions(+), 24 deletions(-) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index fa7dc03459e7..518da42be545 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -307,6 +307,12 @@ 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 + 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 e478368a47f3..4d67bef8f894 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 33632e7f91da..265637cb5eb0 100644 --- a/arch/riscv/kernel/sbi.c +++ b/arch/riscv/kernel/sbi.c @@ -13,6 +13,13 @@ 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 hbase, 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 +64,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,41 +93,115 @@ int sbi_console_getchar(void) EXPORT_SYMBOL(sbi_console_getchar); /** - * sbi_set_timer() - Program the timer for next timer event. - * @stime_value: The value after which next timer event should fire. + * sbi_shutdown() - Remove all the harts from executing supervisor code. * * Return: None */ -void sbi_set_timer(uint64_t stime_value) +void sbi_shutdown(void) { -#if __riscv_xlen == 32 - sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, - stime_value >> 32, 0, 0, 0, 0); -#else - sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, 0, 0, 0, 0, 0); -#endif + sbi_ecall(SBI_EXT_0_1_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0); } EXPORT_SYMBOL(sbi_set_timer); /** - * sbi_shutdown() - Remove all the harts from executing supervisor code. + * sbi_clear_ipi() - Clear any pending IPIs for the calling hart. * * Return: None */ -void sbi_shutdown(void) +void sbi_clear_ipi(void) { - sbi_ecall(SBI_EXT_0_1_SHUTDOWN, 0, 0, 0, 0, 0, 0, 0); + sbi_ecall(SBI_EXT_0_1_CLEAR_IPI, 0, 0, 0, 0, 0, 0, 0); } EXPORT_SYMBOL(sbi_shutdown); /** - * sbi_clear_ipi() - Clear any pending IPIs for the calling hart. + * 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_clear_ipi(void) +static void __sbi_set_timer_v01(uint64_t stime_value) { - sbi_ecall(SBI_EXT_0_1_CLEAR_IPI, 0, 0, 0, 0, 0, 0, 0); +#if __riscv_xlen == 32 + sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, + stime_value >> 32, 0, 0, 0, 0); +#else + sbi_ecall(SBI_EXT_0_1_SET_TIMER, 0, stime_value, 0, 0, 0, 0, 0); +#endif +} + +static int __sbi_send_ipi_v01(const unsigned long *hart_mask) +{ + sbi_ecall(SBI_EXT_0_1_SEND_IPI, 0, (unsigned long)hart_mask, + 0, 0, 0, 0, 0); + return 0; +} + +static int __sbi_rfence_v01(int fid, const unsigned long *hart_mask, + unsigned long hbase, 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 hbase, 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_set_timer() - 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) +{ + __sbi_set_timer(stime_value); } /** @@ -130,11 +212,11 @@ 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); + /** * sbi_remote_fence_i() - Execute FENCE.I instruction on given remote harts. * @hart_mask: A cpu mask containing all the target harts. @@ -143,8 +225,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, 0); } EXPORT_SYMBOL(sbi_remote_fence_i); @@ -161,8 +243,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, 0, start, size, 0, 0); } EXPORT_SYMBOL(sbi_remote_sfence_vma); @@ -182,8 +264,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, 0, start, size, asid, 0); } EXPORT_SYMBOL(sbi_remote_sfence_vma_asid); @@ -249,8 +331,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.24.0