Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5255621ybl; Tue, 27 Aug 2019 01:40:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHJ0kLNcW7iVCnm2PdGT89RDcFskZo2sJIELuIasIS4CPmpa9elPEC+KeyyA8EkLnPBrYj X-Received: by 2002:a65:6401:: with SMTP id a1mr20215757pgv.42.1566895237445; Tue, 27 Aug 2019 01:40:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566895237; cv=none; d=google.com; s=arc-20160816; b=mMwQ0lOV2qk9czZsomTbr34FkzzhKkHbCE416cmT1uZZB1KhF6X+7YRsngbY8XzDO4 6Gn0CmSVBiSyo0ZELw2I8oVKEBBDn3/qV4k4XxmpwZ0BsKSIPsJcYDGXqvLVORHgMSp4 Ga4g9mRSplAR83Zf8V6Y/87QapLlPrl9hbLlhLAM9yUhKpCxq8/8Wf4ftIbD6PnQq3qj VOt8Q67mjf5e6i6YN25GT/6sGQv+8EUhQYoZoGEBEV17V5+hvz2GpSzwJHV6rNdRaMMO pF9XqM2kWlwga1T2ST2QOi3sFvv23ciq2Jks2JZ7QSKm0NrSUtzbh26QJs7OYBbsdsvT RXZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date; bh=SPDMdpvm9KGxRdLyyg40kUw4p+pZsHIiycLSM9Fjbpc=; b=CVESA5fBXOIjEm8utCjKTGcQaiMykUEizfyK4HbmyZBxlLUTUxGnt787PfLIoD8rrs 5a4+dk1ErIC4SYxTHYAlJJ8lKwU6pHpTE3O7iywK5KF212hQC9Zd8osRTAK2KqzKua/1 9UnktLZU5f6nKMCRqmu6HekJatSEUkcf5xoGkTXPkeZiU7wIOjaebjw2eY+zh6awk0yA FDdfwgCEVm2MO03eGvfdPkGopD4rh1LxEXTwkRZaMGERZOhiFDPf3u/JyrdFxRyu82Ym fZVpG0cAjPnzgxmjt3+OZ9xkMsy3oCq0UokOysXSDx5sLkpC6Z4arop6VuF8IEfCIec5 2azw== ARC-Authentication-Results: i=1; mx.google.com; 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 38si12138246pla.216.2019.08.27.01.40.21; Tue, 27 Aug 2019 01:40:37 -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; 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729197AbfH0Ij0 (ORCPT + 99 others); Tue, 27 Aug 2019 04:39:26 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37154 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726735AbfH0Ij0 (ORCPT ); Tue, 27 Aug 2019 04:39:26 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7R8YFvC082657 for ; Tue, 27 Aug 2019 04:39:24 -0400 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2umxgv63a8-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 27 Aug 2019 04:39:24 -0400 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 27 Aug 2019 09:39:22 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 27 Aug 2019 09:39:17 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x7R8dGV555312578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 27 Aug 2019 08:39:16 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 860D04C040; Tue, 27 Aug 2019 08:39:16 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 868B64C04E; Tue, 27 Aug 2019 08:39:15 +0000 (GMT) Received: from rapoport-lnx (unknown [9.148.8.59]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 27 Aug 2019 08:39:15 +0000 (GMT) Date: Tue, 27 Aug 2019 11:39:13 +0300 From: Mike Rapoport To: Anup Patel Cc: Atish Patra , "linux-kernel@vger.kernel.org List" , Albert Ou , Alan Kao , Alexios Zavras , Palmer Dabbelt , Paul Walmsley , Gary Guo , Greg Kroah-Hartman , linux-riscv , Thomas Gleixner Subject: Re: [RFC PATCH 2/2] RISC-V: Add basic support for SBI v0.2 References: <20190826233256.32383-1-atish.patra@wdc.com> <20190826233256.32383-3-atish.patra@wdc.com> <20190827075831.GD682@rapoport-lnx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 19082708-0008-0000-0000-0000030DC4B6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19082708-0009-0000-0000-00004A2BFFE1 Message-Id: <20190827083913.GG682@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-27_01:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908270096 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 27, 2019 at 01:53:23PM +0530, Anup Patel wrote: > On Tue, Aug 27, 2019 at 1:28 PM Mike Rapoport wrote: > > > > On Mon, Aug 26, 2019 at 04:32:56PM -0700, Atish Patra wrote: > > > The SBI v0.2 introduces a base extension which is backward compatible > > > with v0.1. Implement all helper functions and minimum required SBI > > > calls from v0.2 for now. All other base extension function will be > > > added later as per need. > > > > > > Signed-off-by: Atish Patra > > > --- > > > arch/riscv/include/asm/sbi.h | 68 +++++++++++++++++++++++++++++------- > > > arch/riscv/kernel/Makefile | 1 + > > > arch/riscv/kernel/sbi.c | 50 ++++++++++++++++++++++++++ > > > arch/riscv/kernel/setup.c | 2 ++ > > > 4 files changed, 108 insertions(+), 13 deletions(-) > > > create mode 100644 arch/riscv/kernel/sbi.c > > > > > > diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h > > > index 7f5ecaaaa0d7..4a4476956693 100644 > > > --- a/arch/riscv/include/asm/sbi.h > > > +++ b/arch/riscv/include/asm/sbi.h > > > @@ -8,7 +8,6 @@ > > > > > > #include > > > > > > - > > > #define SBI_EXT_LEGACY_SET_TIMER 0x0 > > > #define SBI_EXT_LEGACY_CONSOLE_PUTCHAR 0x1 > > > #define SBI_EXT_LEGACY_CONSOLE_GETCHAR 0x2 > > > @@ -19,28 +18,61 @@ > > > #define SBI_EXT_LEGACY_REMOTE_SFENCE_VMA_ASID 0x7 > > > #define SBI_EXT_LEGACY_SHUTDOWN 0x8 > > > > > > -#define SBI_CALL_LEGACY(which, arg0, arg1, arg2, arg3) ({ \ > > > +#define SBI_EXT_BASE 0x10 > > > + > > > +enum sbi_ext_base_fid { > > > + SBI_EXT_BASE_GET_SPEC_VERSION = 0, > > > + SBI_EXT_BASE_GET_IMP_ID, > > > + SBI_EXT_BASE_GET_IMP_VERSION, > > > + SBI_EXT_BASE_PROBE_EXT, > > > + SBI_EXT_BASE_GET_MVENDORID, > > > + SBI_EXT_BASE_GET_MARCHID, > > > + SBI_EXT_BASE_GET_MIMPID, > > > +}; > > > + > > > +#define SBI_CALL_LEGACY(ext, fid, arg0, arg1, arg2, arg3) ({ \ > > > register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); \ > > > register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); \ > > > register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); \ > > > register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); \ > > > - register uintptr_t a7 asm ("a7") = (uintptr_t)(which); \ > > > + register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); \ > > > + register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); \ > > > asm volatile ("ecall" \ > > > - : "+r" (a0) \ > > > - : "r" (a1), "r" (a2), "r" (a3), "r" (a7) \ > > > + : "+r" (a0), "+r" (a1) \ > > > + : "r" (a2), "r" (a3), "r" (a6), "r" (a7) \ > > > > Maybe I'm missing something, but how is this supposed to work on systems > > with SBI v0.1? Wouldn't this cause a mismatch in the registers? > > The SBI v0.2 has two major changes: > 1. New improved calling convention which is backward compatible > with SBI v0.1 so older kernels with SBI v0.1 will continue to work as-is. > 2. Base set of mandatory SBI v0.2 calls which can be used to detect > SBI version, check supported SBI calls and extentions. > > Old calling convention in SBI v0.1 was: > Parameters: > a0 -> arg0 > a1 -> arg1 > a2 -> arg2 > a3 -> arg3 > a7 -> function_id > Return: > a0 -> return value or error code > > In SBI v0.2, we have extension and function. Each SBI extension > is a set of function. The new calling convention in SBI v0.2 is: > Parameters: > a0 -> arg0 > a1 -> arg1 > a2 -> arg2 > a3 -> arg3 > a6 -> function_id > a7 -> extension_id > Return: > a0 -> error code > a1 -> return value (optional) So with this patch SBI_CALL_LEGACY() uses SBI v0.2 convention, right? Doesn't it mean that you cannot run a new kernel on a system with SBI v0.1? > All legacy SBI v0.1 functions can be thought of as separate > extensions. That's how SBI v0.2 will be backward compatible. > > Regards, > Anup > > > > > > : "memory"); \ > > > a0; \ > > > }) > > > > > > /* Lazy implementations until SBI is finalized */ > > > -#define SBI_CALL_LEGACY_0(which) SBI_CALL_LEGACY(which, 0, 0, 0, 0) > > > -#define SBI_CALL_LEGACY_1(which, arg0) SBI_CALL_LEGACY(which, arg0, 0, 0, 0) > > > -#define SBI_CALL_LEGACY_2(which, arg0, arg1) \ > > > - SBI_CALL_LEGACY(which, arg0, arg1, 0, 0) > > > -#define SBI_CALL_LEGACY_3(which, arg0, arg1, arg2) \ > > > - SBI_CALL_LEGACY(which, arg0, arg1, arg2, 0) > > > -#define SBI_CALL_LEGACY_4(which, arg0, arg1, arg2, arg3) \ > > > - SBI_CALL_LEGACY(which, arg0, arg1, arg2, arg3) > > > +#define SBI_CALL_LEGACY_0(ext) SBI_CALL_LEGACY(ext, 0, 0, 0, 0, 0) > > > +#define SBI_CALL_LEGACY_1(ext, arg0) SBI_CALL_LEGACY(ext, 0, arg0, 0, 0, 0) > > > +#define SBI_CALL_LEGACY_2(ext, arg0, arg1) \ > > > + SBI_CALL_LEGACY(ext, 0, arg0, arg1, 0, 0) > > > +#define SBI_CALL_LEGACY_3(ext, arg0, arg1, arg2) \ > > > + SBI_CALL_LEGACY(ext, 0, arg0, arg1, arg2, 0) > > > +#define SBI_CALL_LEGACY_4(ext, arg0, arg1, arg2, arg3) \ > > > + SBI_CALL_LEGACY(ext, 0, arg0, arg1, arg2, arg3) > > > + > > > +extern unsigned long sbi_firmware_version; > > > +struct sbiret { > > > + long error; > > > + long value; > > > +}; > > > + > > > +void riscv_sbi_init(void); > > > +struct sbiret riscv_sbi_ecall(int ext, int fid, int arg0, int arg1, > > > + int arg2, int arg3); > > > + > > > +#define SBI_CALL_0(ext, fid) riscv_sbi_ecall(ext, fid, 0, 0, 0, 0) > > > +#define SBI_CALL_1(ext, fid, arg0) riscv_sbi_ecall(ext, fid, arg0, 0, 0, 0) > > > +#define SBI_CALL_2(ext, fid, arg0, arg1) \ > > > + riscv_sbi_ecall(ext, fid, arg0, arg1, 0, 0) > > > +#define SBI_CALL_3(ext, fid, arg0, arg1, arg2) \ > > > + riscv_sbi_ecall(ext, fid, arg0, arg1, arg2, 0) > > > +#define SBI_CALL_4(ext, fid, arg0, arg1, arg2, arg3) \ > > > + riscv_sbi_ecall(ext, fid, arg0, arg1, arg2, arg3) > > > + > > > > > > static inline void sbi_console_putchar(int ch) > > > { > > > @@ -99,4 +131,14 @@ static inline void sbi_remote_sfence_vma_asid(const unsigned long *hart_mask, > > > start, size, asid); > > > } > > > > > > +static inline unsigned long riscv_sbi_major_version(void) > > > +{ > > > + return (sbi_firmware_version >> 24) & 0x7f; > > > +} > > > + > > > +static inline unsigned long riscv_sbi_minor_version(void) > > > +{ > > > + return sbi_firmware_version & 0xffffff; > > > +} > > > + > > > #endif > > > diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile > > > index 2420d37d96de..faf862d26924 100644 > > > --- a/arch/riscv/kernel/Makefile > > > +++ b/arch/riscv/kernel/Makefile > > > @@ -17,6 +17,7 @@ obj-y += irq.o > > > obj-y += process.o > > > obj-y += ptrace.o > > > obj-y += reset.o > > > +obj-y += sbi.o > > > obj-y += setup.o > > > obj-y += signal.o > > > obj-y += syscall_table.o > > > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c > > > new file mode 100644 > > > index 000000000000..457b8cc0e9d9 > > > --- /dev/null > > > +++ b/arch/riscv/kernel/sbi.c > > > @@ -0,0 +1,50 @@ > > > +// SPDX-License-Identifier: GPL-2.0-only > > > +/* > > > + * SBI initialilization and base extension implementation. > > > + * > > > + * Copyright (c) 2019 Western Digital Corporation or its affiliates. > > > + */ > > > + > > > +#include > > > +#include > > > + > > > +unsigned long sbi_firmware_version; > > > + > > > +struct sbiret riscv_sbi_ecall(int ext, int fid, int arg0, int arg1, > > > + int arg2, int arg3) > > > +{ > > > + struct sbiret ret; > > > + > > > + register uintptr_t a0 asm ("a0") = (uintptr_t)(arg0); > > > + register uintptr_t a1 asm ("a1") = (uintptr_t)(arg1); > > > + register uintptr_t a2 asm ("a2") = (uintptr_t)(arg2); > > > + register uintptr_t a3 asm ("a3") = (uintptr_t)(arg3); > > > + register uintptr_t a6 asm ("a6") = (uintptr_t)(fid); > > > + register uintptr_t a7 asm ("a7") = (uintptr_t)(ext); > > > + asm volatile ("ecall" > > > + : "+r" (a0), "+r" (a1) > > > + : "r" (a2), "r" (a3), "r" (a6), "r" (a7) > > > + : "memory"); > > > + ret.error = a0; > > > + ret.value = a1; > > > + > > > + return ret; > > > +} > > > + > > > +static struct sbiret sbi_get_spec_version(void) > > > +{ > > > + return SBI_CALL_0(SBI_EXT_BASE, SBI_EXT_BASE_GET_SPEC_VERSION); > > > +} > > > + > > > +void riscv_sbi_init(void) > > > +{ > > > + struct sbiret ret; > > > + > > > + /* legacy SBI version*/ > > > + sbi_firmware_version = 0x1; > > > + ret = sbi_get_spec_version(); > > > + if (!ret.error) > > > + sbi_firmware_version = ret.value; > > > + pr_info("SBI version implemented in firmware [%lu:%lu]\n", > > > + riscv_sbi_major_version(), riscv_sbi_minor_version()); > > > +} > > > diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c > > > index a990a6cb184f..4c324fd398c8 100644 > > > --- a/arch/riscv/kernel/setup.c > > > +++ b/arch/riscv/kernel/setup.c > > > @@ -21,6 +21,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > #include > > > #include > > > > > > @@ -70,6 +71,7 @@ void __init setup_arch(char **cmdline_p) > > > swiotlb_init(1); > > > #endif > > > > > > + riscv_sbi_init(); > > > #ifdef CONFIG_SMP > > > setup_smp(); > > > #endif > > > -- > > > 2.21.0 > > > > > > > > > _______________________________________________ > > > linux-riscv mailing list > > > linux-riscv@lists.infradead.org > > > http://lists.infradead.org/mailman/listinfo/linux-riscv > > > > -- > > Sincerely yours, > > Mike. > > -- Sincerely yours, Mike.