From patchwork Wed Jun 28 13:14:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Ortiz X-Patchwork-Id: 113869 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8926626vqr; Wed, 28 Jun 2023 06:29:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4bhj1f5DJJllIexCH6zfYUYf7KJGXv4cvqhmvC5C1gcCQcTnGrw18i6eJ8rtptoTpwDRco X-Received: by 2002:a05:6a00:844:b0:668:8c7a:47e2 with SMTP id q4-20020a056a00084400b006688c7a47e2mr32861081pfk.19.1687958956237; Wed, 28 Jun 2023 06:29:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687958956; cv=none; d=google.com; s=arc-20160816; b=gwzIzYT++oondyLWGjm8fRc2cNcDjPhUkjKcR0bId/hC98/Qi2zG3Z0GMQbg2/HKSX dHYMpdbtVhxvzwNEN7JRXb4WMufRuDrz9i3Jk7xTiZzjqAQHs1zuygplLksbSZ6FIV65 ZwtRRh53tlx0sgvutT8InGwZZX2W6ByimnNyTkOoScyg1RaetkEBBYKr1ZaTdO4Ploko pvbfOvWlHcahdPDFocvmMKi/c9fc9nGc4SzILjVRRbHEBXOdX61Q9cq6syXruWZXqJxM YmX96mRgMJMZsd3ILogBciAs098NmYagtLOMqEpDVMVQkyb6X3RTh2B3y5lpO5vZuFXV YYUg== 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=GiOwfD1HiScotDrS0+RvYK350JHm5UF5oC2oX5fkmHM=; fh=K+cpXjSEo8ROzwJvClsygMimouh4VBGKq0pkfxWKSps=; b=H5LNo+DQ3Xs3PEG/lxTyoxfpwoqwfqeSWRZ4+LRVfnyXhZk4L5wNFC3QGi55jQsssm 0ywbmnaIo0/+4FJk59fzC/3pPotcV1qkfvQazCsauA2jNeawtGNszHCOorGjbCleJS78 VkuOT8NxBkVWXPDMU+Kckh+7KHOITTS4Fpx6NykuPMWY0FJHWAYq8DwZ5F+Wor5qzwaM bWLoSsl1YdkPbbOaCA2q2sb6vevGjhoqkWxw8HBF1HwIMIOK/SD4Qo5zED1mHAc4D/CN PxB7hQjX0j+gwM1lyxIvyIvaLNcylVnhXuS5lb2MyWszeorivuxLRu/xN8P426Wg7OV0 y6RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=BDTo0rbe; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y188-20020a6364c5000000b00502ee712648si9593058pgb.578.2023.06.28.06.28.45; Wed, 28 Jun 2023 06:29:16 -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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=BDTo0rbe; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231493AbjF1NPG (ORCPT + 99 others); Wed, 28 Jun 2023 09:15:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbjF1NPE (ORCPT ); Wed, 28 Jun 2023 09:15:04 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E612E1705 for ; Wed, 28 Jun 2023 06:15:02 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-313f59cd193so3095269f8f.2 for ; Wed, 28 Jun 2023 06:15:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1687958101; x=1690550101; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GiOwfD1HiScotDrS0+RvYK350JHm5UF5oC2oX5fkmHM=; b=BDTo0rbe+6rcs0uhompPuUaW/LK5jt5dsFb4IAViNeq3lX26AlV2LVxIfMOUAdPYHd ra73W2Cz4ub2oGGS6jzM5kh+oZAW2WNCMH7yiWCZTTm/IOHKByKDGKcDK6ajqHBaSqnp CcNWFIAl8mL89yI0Fqi60WZD952bP8C7vIB+M5tRgQ6s2+HPnuIa1jGxCo/gMWPqtBG7 0tMT0T/zWX6SNFN11UN8eq/lXB/ZOkvFWxpJEBiaXjV84HpcWhRydve2tc5P0IMEGn9+ KuO6ZcuTp6HX/GLG2h4zRlduXPVdYODbifB+SJr9yu7mGte8T7RWz1R6z6+HVILRP79M bJ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687958101; x=1690550101; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GiOwfD1HiScotDrS0+RvYK350JHm5UF5oC2oX5fkmHM=; b=UWhAlq56pbhUcLPYo/CeCVVaOcghDJUy6xkpC/gq7NKdLD7zF1oqIAnmSw//2bkXL0 szuM2A8J7xEEWREQDFxdOgONyIpQ9VKmRahgQ7Z60UlqRky+KFIBnn3mjXnkx+R28Q/I Earu4/gslD9fznxeca3UiuFut1JN/3dqQ2S1r8x6Dpz34DP8CCY2hf1oULxhA8HyidT/ llsKZqm42BK9SLSLU+49jM8dvyTjh60s4dkc5ubtKdF+IGjfWasfpO9CSltAifDrDUKr nlETZaEPd4FZ3/Do7Ri7AL4v95S+Ty6UceDIYnWjh0VsbxKIthT4CNVzn+3Nzz9IlmZP pd2w== X-Gm-Message-State: ABy/qLa/Z+M2RlTTGovt7rv8sM24rJFtep7mZtVsOfTwPP99JjFE0cnE 5PNM/UVOQHT2SrPy0KEIURCPGw== X-Received: by 2002:adf:f3c4:0:b0:314:1096:ed2f with SMTP id g4-20020adff3c4000000b003141096ed2fmr746609wrp.35.1687958100853; Wed, 28 Jun 2023 06:15:00 -0700 (PDT) Received: from vermeer.tail79c99.ts.net ([2a01:cb1d:81a9:dd00:b570:b34c:ffd4:c805]) by smtp.gmail.com with ESMTPSA id a11-20020a056000050b00b003110dc7f408sm13456946wrf.41.2023.06.28.06.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 06:15:00 -0700 (PDT) From: Samuel Ortiz To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Cc: "Hongren (Zenithal) Zheng" , linux@rivosinc.com, Conor Dooley , Andrew Jones , Heiko Stuebner , Anup Patel , linux-kernel@vger.kernel.org, Guo Ren , Atish Patra , Samuel Ortiz , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Evan Green , Jiatai He Subject: [PATCH v2 1/3] RISC-V: add Bitmanip/Scalar Crypto parsing from DT Date: Wed, 28 Jun 2023 15:14:33 +0200 Message-ID: <20230628131442.3022772-2-sameo@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628131442.3022772-1-sameo@rivosinc.com> References: <20230628131442.3022772-1-sameo@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UPPERCASE_50_75 autolearn=no 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769953250646725095?= X-GMAIL-MSGID: =?utf-8?q?1769953250646725095?= From: "Hongren (Zenithal) Zheng" Parse Zb/Zk related string from DT and output them to cpuinfo. It is worth noting that the Scalar Crypto extension defines "zk" as a shorthand for the Zkn, Zkr and Zkt extensions. Since the Zkn one also implies the Zbkb, Zbkc and Zbkx extensions, simply passing the valid "zk" extension name through a DT will enable all of the Zbkb, Zbkc, Zbkx, Zkn, Zkr and Zkt extensions. Also, since there currently is no mechanism to merge all enabled extensions, the generated cpuinfo output could be relatively large. For example, setting the "riscv,isa" DT property to "rv64imafdc_zk_zks" will generate the following cpuinfo output: "rv64imafdc_zbkb_zbkc_zbkx_zknd_zkne_zknh_zkr_zksed_zksh_zkt". Tested-by: Jiatai He Signed-off-by: Samuel Ortiz Signed-off-by: Hongren (Zenithal) Zheng Reviewed-by: Evan Green Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- arch/riscv/include/asm/hwcap.h | 11 +++++++++++ arch/riscv/kernel/cpu.c | 11 +++++++++++ arch/riscv/kernel/cpufeature.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h index f041bfa7f6a0..b80ca6e77088 100644 --- a/arch/riscv/include/asm/hwcap.h +++ b/arch/riscv/include/asm/hwcap.h @@ -53,6 +53,17 @@ #define RISCV_ISA_EXT_ZICSR 40 #define RISCV_ISA_EXT_ZIFENCEI 41 #define RISCV_ISA_EXT_ZIHPM 42 +#define RISCV_ISA_EXT_ZBC 43 +#define RISCV_ISA_EXT_ZBKB 44 +#define RISCV_ISA_EXT_ZBKC 45 +#define RISCV_ISA_EXT_ZBKX 46 +#define RISCV_ISA_EXT_ZKND 47 +#define RISCV_ISA_EXT_ZKNE 48 +#define RISCV_ISA_EXT_ZKNH 49 +#define RISCV_ISA_EXT_ZKR 50 +#define RISCV_ISA_EXT_ZKSED 51 +#define RISCV_ISA_EXT_ZKSH 52 +#define RISCV_ISA_EXT_ZKT 53 #define RISCV_ISA_EXT_MAX 64 #define RISCV_ISA_EXT_NAME_LEN_MAX 32 diff --git a/arch/riscv/kernel/cpu.c b/arch/riscv/kernel/cpu.c index a2fc952318e9..10524322a4c0 100644 --- a/arch/riscv/kernel/cpu.c +++ b/arch/riscv/kernel/cpu.c @@ -215,7 +215,18 @@ static struct riscv_isa_ext_data isa_ext_arr[] = { __RISCV_ISA_EXT_DATA(zihpm, RISCV_ISA_EXT_ZIHPM), __RISCV_ISA_EXT_DATA(zba, RISCV_ISA_EXT_ZBA), __RISCV_ISA_EXT_DATA(zbb, RISCV_ISA_EXT_ZBB), + __RISCV_ISA_EXT_DATA(zbc, RISCV_ISA_EXT_ZBC), + __RISCV_ISA_EXT_DATA(zbkb, RISCV_ISA_EXT_ZBKB), + __RISCV_ISA_EXT_DATA(zbkc, RISCV_ISA_EXT_ZBKC), + __RISCV_ISA_EXT_DATA(zbkx, RISCV_ISA_EXT_ZBKX), __RISCV_ISA_EXT_DATA(zbs, RISCV_ISA_EXT_ZBS), + __RISCV_ISA_EXT_DATA(zknd, RISCV_ISA_EXT_ZKND), + __RISCV_ISA_EXT_DATA(zkne, RISCV_ISA_EXT_ZKNE), + __RISCV_ISA_EXT_DATA(zknh, RISCV_ISA_EXT_ZKNH), + __RISCV_ISA_EXT_DATA(zkr, RISCV_ISA_EXT_ZKR), + __RISCV_ISA_EXT_DATA(zksed, RISCV_ISA_EXT_ZKSED), + __RISCV_ISA_EXT_DATA(zksh, RISCV_ISA_EXT_ZKSH), + __RISCV_ISA_EXT_DATA(zkt, RISCV_ISA_EXT_ZKT), __RISCV_ISA_EXT_DATA(smaia, RISCV_ISA_EXT_SMAIA), __RISCV_ISA_EXT_DATA(ssaia, RISCV_ISA_EXT_SSAIA), __RISCV_ISA_EXT_DATA(sscofpmf, RISCV_ISA_EXT_SSCOFPMF), diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index bdcf460ea53d..9a872a2007a5 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -309,10 +309,40 @@ void __init riscv_fill_hwcap(void) SET_ISA_EXT_MAP("svpbmt", RISCV_ISA_EXT_SVPBMT); SET_ISA_EXT_MAP("zba", RISCV_ISA_EXT_ZBA); SET_ISA_EXT_MAP("zbb", RISCV_ISA_EXT_ZBB); + SET_ISA_EXT_MAP("zbc", RISCV_ISA_EXT_ZBC); + SET_ISA_EXT_MAP("zbkb", RISCV_ISA_EXT_ZBKB); + SET_ISA_EXT_MAP("zbkc", RISCV_ISA_EXT_ZBKC); + SET_ISA_EXT_MAP("zbkx", RISCV_ISA_EXT_ZBKX); SET_ISA_EXT_MAP("zbs", RISCV_ISA_EXT_ZBS); SET_ISA_EXT_MAP("zicbom", RISCV_ISA_EXT_ZICBOM); SET_ISA_EXT_MAP("zicboz", RISCV_ISA_EXT_ZICBOZ); SET_ISA_EXT_MAP("zihintpause", RISCV_ISA_EXT_ZIHINTPAUSE); + SET_ISA_EXT_MAP("zk", RISCV_ISA_EXT_ZBKB); + SET_ISA_EXT_MAP("zk", RISCV_ISA_EXT_ZBKC); + SET_ISA_EXT_MAP("zk", RISCV_ISA_EXT_ZBKX); + SET_ISA_EXT_MAP("zk", RISCV_ISA_EXT_ZKND); + SET_ISA_EXT_MAP("zk", RISCV_ISA_EXT_ZKNE); + SET_ISA_EXT_MAP("zk", RISCV_ISA_EXT_ZKNH); + SET_ISA_EXT_MAP("zk", RISCV_ISA_EXT_ZKR); + SET_ISA_EXT_MAP("zk", RISCV_ISA_EXT_ZKT); + SET_ISA_EXT_MAP("zkn", RISCV_ISA_EXT_ZBKB); + SET_ISA_EXT_MAP("zkn", RISCV_ISA_EXT_ZBKC); + SET_ISA_EXT_MAP("zkn", RISCV_ISA_EXT_ZBKX); + SET_ISA_EXT_MAP("zkn", RISCV_ISA_EXT_ZKND); + SET_ISA_EXT_MAP("zkn", RISCV_ISA_EXT_ZKNE); + SET_ISA_EXT_MAP("zkn", RISCV_ISA_EXT_ZKNH); + SET_ISA_EXT_MAP("zknd", RISCV_ISA_EXT_ZKND); + SET_ISA_EXT_MAP("zkne", RISCV_ISA_EXT_ZKNE); + SET_ISA_EXT_MAP("zknh", RISCV_ISA_EXT_ZKNH); + SET_ISA_EXT_MAP("zks", RISCV_ISA_EXT_ZBKB); + SET_ISA_EXT_MAP("zks", RISCV_ISA_EXT_ZBKC); + SET_ISA_EXT_MAP("zks", RISCV_ISA_EXT_ZBKX); + SET_ISA_EXT_MAP("zks", RISCV_ISA_EXT_ZKSED); + SET_ISA_EXT_MAP("zks", RISCV_ISA_EXT_ZKSH); + SET_ISA_EXT_MAP("zksed", RISCV_ISA_EXT_ZKSED); + SET_ISA_EXT_MAP("zksh", RISCV_ISA_EXT_ZKSH); + SET_ISA_EXT_MAP("zkr", RISCV_ISA_EXT_ZKR); + SET_ISA_EXT_MAP("zkt", RISCV_ISA_EXT_ZKT); } #undef SET_ISA_EXT_MAP } From patchwork Wed Jun 28 13:14:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Ortiz X-Patchwork-Id: 113868 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8925831vqr; Wed, 28 Jun 2023 06:28:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7wYwnfd9Cufld+e7rfOseV4zLZLP9BeC2Rg6Za3LXGBBcOo4eRQd1ivZ84F1B+3vS9rUlF X-Received: by 2002:a17:907:745:b0:978:928:3b99 with SMTP id xc5-20020a170907074500b0097809283b99mr29759122ejb.46.1687958880471; Wed, 28 Jun 2023 06:28:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687958880; cv=none; d=google.com; s=arc-20160816; b=Qjey5r46aj8yzlMRZpmYFado/Bw4wEgTUYzx7KZY2qNpD9CbHp+EluULfuG7BklUig HcnNJvLXI9fwmF0Q6/YLN/Px+n4wV8XIlRoBEZMDQs6reDC3YIdyVQ+IN8tz4rE+RLRk ekiZlr31Mpm9qsKu90OlN92cJn3VJZbBi10nDBU7qhr6LLa21NrsLV1WXIvpptOKvCvl EPTZEPGrBLvqD1ILv4JcQbEy5IIzYoR8MbNj085+icIGV8Ts3TFpLP4+1Ra0Cu344Qwc mUDaEHLNAbDxcDFlujyh5/0yekiVsrg/U8yKLGLlUKWhLgk4l9cMM4NHKb9v03EL0J9M tgrQ== 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=Y5WQhI98ezKCFPxc8g2DPgXVepDNDhyJRf7FBEyv5Qs=; fh=+KY35iURJH+A+xMI+PExjIVC2hBjVOkkyp1+1Nnq7Zo=; b=JutqzH561CyXQ0tQGABy3ubNIKulAJYGMxFE2tpGHxc643dpchaCnAZMrTNKt5EKna ay71w2E0WsJNUMLOkBmJIZldh3faHpaV7OqdsmJ8nxXpVOrh7IdJwFJGr+otRxNCXZsZ Kn8eqU7EllqVxQQGWquURrvWPTMw6p9/bec9S5LfmQHow7dTKZGZE9+MaNOWtQSOgLdt bHC49DgcIXATYkaXtAmcLPPsmO8wK50qyispMlShkKPxxj6VifT39/xGuFVnRK9V8cCe xm7PiHbLVQ+JUP0fVktCP23psSyBlkrRx3OsGD1JSfYRwELaDWf25HCXLsYA2vVGaZ1o g4KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b="V6/t/L7Q"; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qp7-20020a170907206700b00988588cab8csi5271380ejb.749.2023.06.28.06.27.35; Wed, 28 Jun 2023 06:28:00 -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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b="V6/t/L7Q"; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230186AbjF1NPM (ORCPT + 99 others); Wed, 28 Jun 2023 09:15:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231500AbjF1NPH (ORCPT ); Wed, 28 Jun 2023 09:15:07 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 446D81705 for ; Wed, 28 Jun 2023 06:15:06 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fb10fd9ae9so32150695e9.2 for ; Wed, 28 Jun 2023 06:15:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1687958105; x=1690550105; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y5WQhI98ezKCFPxc8g2DPgXVepDNDhyJRf7FBEyv5Qs=; b=V6/t/L7Qg8TbNvDbaSKMi5CBE0vgOMmNaF8Gh7gEc7wPTWsByhJ2fGmWxJuTe6Tf96 yi+22POylm9GD1ftzzzZotnOy29DAMtbSUnUAdF0k4USA2XG/Y5Eh3A6ns76ENSbIEcS MrCPkwY1jqumU9Vnxmb74/1Mhdzx0MUPsxvex5mUgPQ5FDGvs+MgrK4Cu243ZfHOmGwS +2+9yf4VG6Ol+tql27xVpaNLGeMCdYv9J+X+zRPRMaP3AAMFCWAleaGYs0Vvz0JGH346 SPyryuttUColNeElp4vLd79Wz/qxp+IR58eEFW3Oy6r3CQjlZOzSOrV3k4Jpue+guTZn OQHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687958105; x=1690550105; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y5WQhI98ezKCFPxc8g2DPgXVepDNDhyJRf7FBEyv5Qs=; b=Na7ubvCM3GG5zD/D8DSN2kxQgrqqwCAmzsxIIgP/UAbHL7YEbcfAQlgX+DAEfsHS+A Zo0Ph1Xz3f3WBPcWi8eSFbRZDpXfL9GG4reQSGW/RWwecMlbh4n/Lbpvjjks5n5cGjPl TilGLXx8S/WzrEzKpwBfSPmJ4j10Yp6bWkC6kEaWc6y4HHOeLXU2jeunWxSCztuUm9QU LDDrrxt7HTKw/o7uWG+0/uc7NsY8Pmok6opJHoj1Dp3JEbDJCjNHuMjcDU35DC790V59 85LbwiWcRhd/i9HtNOs+gx3ym+awD49FPcI4LGzTVQFhmHIpO+lrhhla6BxuntuNsHBV nLQA== X-Gm-Message-State: AC+VfDyzC4x5Z/bT0xBXMtfAEHNfGQslDOw2ou3JTUAZXSC76xVAUzoH Pe+aJI83flGSgMPyDLjdXHp2Dw== X-Received: by 2002:a5d:514c:0:b0:311:3fdc:109d with SMTP id u12-20020a5d514c000000b003113fdc109dmr20913067wrt.1.1687958104584; Wed, 28 Jun 2023 06:15:04 -0700 (PDT) Received: from vermeer.tail79c99.ts.net ([2a01:cb1d:81a9:dd00:b570:b34c:ffd4:c805]) by smtp.gmail.com with ESMTPSA id a11-20020a056000050b00b003110dc7f408sm13456946wrf.41.2023.06.28.06.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 06:15:04 -0700 (PDT) From: Samuel Ortiz To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Cc: Samuel Ortiz , linux@rivosinc.com, Conor Dooley , Andrew Jones , Heiko Stuebner , Anup Patel , linux-kernel@vger.kernel.org, "Hongren (Zenithal) Zheng" , Guo Ren , Atish Patra , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Evan Green Subject: [PATCH v2 2/3] RISC-V: hwprobe: Expose Zbc and the scalar crypto extensions Date: Wed, 28 Jun 2023 15:14:34 +0200 Message-ID: <20230628131442.3022772-3-sameo@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628131442.3022772-1-sameo@rivosinc.com> References: <20230628131442.3022772-1-sameo@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769953171042339827?= X-GMAIL-MSGID: =?utf-8?q?1769953171042339827?= Zbc was missing from a previous Bit-Manipulation extension hwprobe patch. Add all scalar crypto extensions bits, and define a macro for setting the hwprobe key/pair in a more readable way. Reviewed-by: Evan Green Signed-off-by: Samuel Ortiz Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- Documentation/riscv/hwprobe.rst | 33 ++++++++++++++++++++++++ arch/riscv/include/uapi/asm/hwprobe.h | 11 ++++++++ arch/riscv/kernel/sys_riscv.c | 36 ++++++++++++++++----------- 3 files changed, 66 insertions(+), 14 deletions(-) diff --git a/Documentation/riscv/hwprobe.rst b/Documentation/riscv/hwprobe.rst index 19165ebd82ba..3177550106e0 100644 --- a/Documentation/riscv/hwprobe.rst +++ b/Documentation/riscv/hwprobe.rst @@ -72,11 +72,44 @@ The following keys are defined: extensions. * :c:macro:`RISCV_HWPROBE_EXT_ZBB`: The Zbb extension is supported, as defined + in version 1.0 of the Bit-Manipulation ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZBC`: The Zbc extension is supported, as defined in version 1.0 of the Bit-Manipulation ISA extensions. * :c:macro:`RISCV_HWPROBE_EXT_ZBS`: The Zbs extension is supported, as defined in version 1.0 of the Bit-Manipulation ISA extensions. + * :c:macro:`RISCV_HWPROBE_EXT_ZBKB`: The Zbkb extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZBKC`: The Zbkc extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZBKX`: The Zbkx extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZKND`: The Zknd extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZKNE`: The Zkne extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZKNH`: The Zknh extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZKR`: The Zkr extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZKSED`: The Zksed extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZKSH`: The Zksh extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + + * :c:macro:`RISCV_HWPROBE_EXT_ZKT`: The Zkt extension is supported, as defined + in version 1.0 of the Scalar Cryptography ISA extensions. + * :c:macro:`RISCV_HWPROBE_KEY_CPUPERF_0`: A bitmask that contains performance information about the selected set of processors. diff --git a/arch/riscv/include/uapi/asm/hwprobe.h b/arch/riscv/include/uapi/asm/hwprobe.h index 006bfb48343d..8357052061b3 100644 --- a/arch/riscv/include/uapi/asm/hwprobe.h +++ b/arch/riscv/include/uapi/asm/hwprobe.h @@ -29,6 +29,17 @@ struct riscv_hwprobe { #define RISCV_HWPROBE_EXT_ZBA (1 << 3) #define RISCV_HWPROBE_EXT_ZBB (1 << 4) #define RISCV_HWPROBE_EXT_ZBS (1 << 5) +#define RISCV_HWPROBE_EXT_ZBC (1 << 6) +#define RISCV_HWPROBE_EXT_ZBKB (1 << 7) +#define RISCV_HWPROBE_EXT_ZBKC (1 << 8) +#define RISCV_HWPROBE_EXT_ZBKX (1 << 9) +#define RISCV_HWPROBE_EXT_ZKND (1 << 10) +#define RISCV_HWPROBE_EXT_ZKNE (1 << 11) +#define RISCV_HWPROBE_EXT_ZKNH (1 << 12) +#define RISCV_HWPROBE_EXT_ZKR (1 << 13) +#define RISCV_HWPROBE_EXT_ZKSED (1 << 14) +#define RISCV_HWPROBE_EXT_ZKSH (1 << 15) +#define RISCV_HWPROBE_EXT_ZKT (1 << 16) #define RISCV_HWPROBE_KEY_CPUPERF_0 5 #define RISCV_HWPROBE_MISALIGNED_UNKNOWN (0 << 0) #define RISCV_HWPROBE_MISALIGNED_EMULATED (1 << 0) diff --git a/arch/riscv/kernel/sys_riscv.c b/arch/riscv/kernel/sys_riscv.c index 26ef5526bfb4..df15926196b6 100644 --- a/arch/riscv/kernel/sys_riscv.c +++ b/arch/riscv/kernel/sys_riscv.c @@ -145,20 +145,28 @@ static void hwprobe_isa_ext0(struct riscv_hwprobe *pair, for_each_cpu(cpu, cpus) { struct riscv_isainfo *isainfo = &hart_isa[cpu]; - if (riscv_isa_extension_available(isainfo->isa, ZBA)) - pair->value |= RISCV_HWPROBE_EXT_ZBA; - else - missing |= RISCV_HWPROBE_EXT_ZBA; - - if (riscv_isa_extension_available(isainfo->isa, ZBB)) - pair->value |= RISCV_HWPROBE_EXT_ZBB; - else - missing |= RISCV_HWPROBE_EXT_ZBB; - - if (riscv_isa_extension_available(isainfo->isa, ZBS)) - pair->value |= RISCV_HWPROBE_EXT_ZBS; - else - missing |= RISCV_HWPROBE_EXT_ZBS; +#define SET_HWPROBE_EXT_PAIR(ext) \ + do { \ + if (riscv_isa_extension_available(isainfo->isa, ext)) \ + pair->value |= RISCV_HWPROBE_EXT_## ext; \ + else \ + missing |= RISCV_HWPROBE_EXT_## ext; \ + } while (false) \ + + SET_HWPROBE_EXT_PAIR(ZBA); + SET_HWPROBE_EXT_PAIR(ZBB); + SET_HWPROBE_EXT_PAIR(ZBC); + SET_HWPROBE_EXT_PAIR(ZBS); + SET_HWPROBE_EXT_PAIR(ZBKB); + SET_HWPROBE_EXT_PAIR(ZBKC); + SET_HWPROBE_EXT_PAIR(ZBKX); + SET_HWPROBE_EXT_PAIR(ZKND); + SET_HWPROBE_EXT_PAIR(ZKNE); + SET_HWPROBE_EXT_PAIR(ZKNH); + SET_HWPROBE_EXT_PAIR(ZKR); + SET_HWPROBE_EXT_PAIR(ZKSED); + SET_HWPROBE_EXT_PAIR(ZKSH); + SET_HWPROBE_EXT_PAIR(ZKT); } /* Now turn off reporting features if any CPU is missing it. */ From patchwork Wed Jun 28 13:14:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Ortiz X-Patchwork-Id: 113867 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp8925693vqr; Wed, 28 Jun 2023 06:27:49 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ52hER6+h0W1+GsHxvVJD7EH49wAq14Z7Jn1jlBkdVC6S3eLgacyPJvhNI78pnNWSm6twqP X-Received: by 2002:a17:907:701:b0:974:6026:a316 with SMTP id xb1-20020a170907070100b009746026a316mr33335347ejb.19.1687958869456; Wed, 28 Jun 2023 06:27:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687958869; cv=none; d=google.com; s=arc-20160816; b=yk0NRZEwM2c7kBde328p0ukpsj2/ttJNw1y8qBI/vfDrwGKkiwyIXLfWduD2Y9ImEQ INXEk3udyIgYDO9b6HsKtqNjrmsa0xExa0HzLKTbDfXmCRtykICcQHUdM/qivEDVEOCi P/cT4+4UdYu21Idb9IrJg0NspW7VOKj1cKFuxqiYWQgp/4bZZ8Om5dYq7eJ2SXHupOkC pJMhpQY5JKUJJV1G1CyY9CKSeIQdH0PhqVMdJo2wpQSaPhlLpUqYWdi7/DDe0g7B246y 6h1WIkZ0RfuoSok6IUCJiX1ZhFxgfXF8UsJvNP3FjP+Sm0MCEbdi7ExD5BsHd7g/+CBy nNtg== 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=UEDUaqobIEXKBJUJL2QuyVEVDAnOAPT+PycLhsHH0e4=; fh=+KY35iURJH+A+xMI+PExjIVC2hBjVOkkyp1+1Nnq7Zo=; b=MeMv9/FBAvhMxdZBV5dzIRWggYPNLWtzQ4MP00fusFfyzU8BhFmvJBPjfqxsjX58db bl7DbIe5k6A0IzCyPZFYHI+WJ+XOhwEH6BVjQYadPq6zhgzaMuEsf14oLHuc7WW5VR5E qnIBByx7dZZMnqyDe0dVpDDJDY6R+JFr6j2jno9pEgxgBnuRzg1YpOIDF+I7RQebijqQ BxYD/nwqPl8UpPk4AxfADvT4hrldgIFDZTi3pjcAtowE099OuFINUTTSgp6zDQ8mFr9U E3cXbQDY+mfLswr7S1i0D9kfDVR/IjDZXhkia9Ksu39BtujwIjTdQeHXtiVYTFLYthP5 ZLgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=PzpxfbdG; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id re21-20020a170906d8d500b00988f4b9113bsi5770904ejb.690.2023.06.28.06.27.25; Wed, 28 Jun 2023 06:27:49 -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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=PzpxfbdG; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231543AbjF1NPO (ORCPT + 99 others); Wed, 28 Jun 2023 09:15:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbjF1NPJ (ORCPT ); Wed, 28 Jun 2023 09:15:09 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8CAD82119 for ; Wed, 28 Jun 2023 06:15:08 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-313e12db357so6180926f8f.0 for ; Wed, 28 Jun 2023 06:15:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1687958107; x=1690550107; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UEDUaqobIEXKBJUJL2QuyVEVDAnOAPT+PycLhsHH0e4=; b=PzpxfbdG1hP8JaT6dGu5MFaJuWjRSgEZs4u66K6iR/KAiam4nJBUjYSvQ8TGXoy+4q v3msqKsXNd1yS7SRhQcy7ZL8ICOg8OxVsNenTnJDmuHHE8o0XnzV17PUmR1OaqTFJUHb l80kTHBXJUsESLmsFFexDiSxsOPxOGvvD/4t7V9fnRf0eAA+AtbX/IyAKiXIbpophLiG 0Lu6napv/3ofoE5nfu0y1S7R6XrhGd53UBqqOr+9cYm+QU9rQa7eNEfhv3Vp08SLGuil o/frg8rQgA65BNf+0YiOOOUxHToVQf0mEehTnG/XL4E8vslfJFMrz5UYOTH2oNXNmBS+ ODIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687958107; x=1690550107; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UEDUaqobIEXKBJUJL2QuyVEVDAnOAPT+PycLhsHH0e4=; b=ejnmrpF/QIVYEFUO0g1qRV61u82mivXJTsMcFAdkSNFv2EHk9kJvMVOmlbgivGvFcg RgXsqnNwpZ7nrmzo5mWuzYk71FWm8kl8xn/HQDsr7ildGd133V1mgJmBoxClv34cTD3a gFfNG3uxGluMz8JN+5VyqxP1rJrunFubv0ehO48rA0sE6V8Azcr61aDjEIRNZ9fYaCtC Ll7qmrgkL1AMgOnMqwxHEmGRfSIq2fJ0myKui4JO03LfbDk0fQdsXrJWCDT6t0GPhOxb WEQq0MErmjHp02kiBNQpwpsv5si97+TpasMSiUyfvNzaZdDn2ra5LZcDgygzTRfh/hWa pwBw== X-Gm-Message-State: ABy/qLabNaqBeJB8HBSLlWteRftMa3hUQjWgb7GeSCJgYOjX6vPW7xdj yzIlaOPxK9tLe7m985Wf3cJAvg== X-Received: by 2002:adf:eb11:0:b0:314:122a:9fe0 with SMTP id s17-20020adfeb11000000b00314122a9fe0mr35636wrn.8.1687958107035; Wed, 28 Jun 2023 06:15:07 -0700 (PDT) Received: from vermeer.tail79c99.ts.net ([2a01:cb1d:81a9:dd00:b570:b34c:ffd4:c805]) by smtp.gmail.com with ESMTPSA id a11-20020a056000050b00b003110dc7f408sm13456946wrf.41.2023.06.28.06.15.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jun 2023 06:15:06 -0700 (PDT) From: Samuel Ortiz To: Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv@lists.infradead.org Cc: Samuel Ortiz , linux@rivosinc.com, Conor Dooley , Andrew Jones , Heiko Stuebner , Anup Patel , linux-kernel@vger.kernel.org, "Hongren (Zenithal) Zheng" , Guo Ren , Atish Patra , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Evan Green Subject: [PATCH v2 3/3] RISC-V: Implement archrandom when Zkr is available Date: Wed, 28 Jun 2023 15:14:35 +0200 Message-ID: <20230628131442.3022772-4-sameo@rivosinc.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230628131442.3022772-1-sameo@rivosinc.com> References: <20230628131442.3022772-1-sameo@rivosinc.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769953159176044810?= X-GMAIL-MSGID: =?utf-8?q?1769953159176044810?= The Zkr extension is ratified and provides 16 bits of entropy seed when reading the SEED CSR. We can implement arch_get_random_seed_longs() by doing multiple csrrw to that CSR and filling an unsigned long with valid entropy bits. Signed-off-by: Samuel Ortiz Acked-by: Conor Dooley Reviewed-by: Guo Ren --- arch/riscv/include/asm/archrandom.h | 70 +++++++++++++++++++++++++++++ arch/riscv/include/asm/csr.h | 9 ++++ 2 files changed, 79 insertions(+) create mode 100644 arch/riscv/include/asm/archrandom.h diff --git a/arch/riscv/include/asm/archrandom.h b/arch/riscv/include/asm/archrandom.h new file mode 100644 index 000000000000..8987cd0b891d --- /dev/null +++ b/arch/riscv/include/asm/archrandom.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Kernel interface for the RISCV arch_random_* functions + * + * Copyright (c) 2023 by Rivos Inc. + * + */ + +#ifndef ASM_RISCV_ARCHRANDOM_H +#define ASM_RISCV_ARCHRANDOM_H + +#include + +#define SEED_RETRY_LOOPS 10 + +static inline bool __must_check csr_seed_long(unsigned long *v) +{ + unsigned int retry = SEED_RETRY_LOOPS, valid_seeds = 0; + const int needed_seeds = sizeof(long) / sizeof(u16); + u16 *entropy = (u16 *)v; + + do { + /* + * The SEED CSR (0x015) must be accessed with a read-write + * instruction. + */ + unsigned long csr_seed = csr_swap(CSR_SEED, 0); + + switch (csr_seed & SEED_OPST_MASK) { + case SEED_OPST_ES16: + entropy[valid_seeds++] = csr_seed & SEED_ENTROPY_MASK; + if (valid_seeds == needed_seeds) + return true; + break; + + case SEED_OPST_DEAD: + pr_err_once("archrandom: Unrecoverable error\n"); + return false; + + case SEED_OPST_BIST: + case SEED_OPST_WAIT: + default: + continue; + } + } while (--retry); + + return false; +} + +static inline size_t __must_check arch_get_random_longs(unsigned long *v, size_t max_longs) +{ + return 0; +} + +static inline size_t __must_check arch_get_random_seed_longs(unsigned long *v, size_t max_longs) +{ + if (!max_longs) + return 0; + + /* + * If Zkr is supported and csr_seed_long succeeds, we return one long + * worth of entropy. + */ + if (riscv_has_extension_likely(RISCV_ISA_EXT_ZKR) && csr_seed_long(v)) + return 1; + + return 0; +} + +#endif /* ASM_RISCV_ARCHRANDOM_H */ diff --git a/arch/riscv/include/asm/csr.h b/arch/riscv/include/asm/csr.h index b98b3b6c9da2..7d0ca9082c66 100644 --- a/arch/riscv/include/asm/csr.h +++ b/arch/riscv/include/asm/csr.h @@ -389,6 +389,15 @@ #define CSR_VTYPE 0xc21 #define CSR_VLENB 0xc22 +/* Scalar Crypto Extension - Entropy */ +#define CSR_SEED 0x015 +#define SEED_OPST_MASK _AC(0xC0000000, UL) +#define SEED_OPST_BIST _AC(0x00000000, UL) +#define SEED_OPST_WAIT _AC(0x40000000, UL) +#define SEED_OPST_ES16 _AC(0x80000000, UL) +#define SEED_OPST_DEAD _AC(0xC0000000, UL) +#define SEED_ENTROPY_MASK _AC(0xFFFF, UL) + #ifdef CONFIG_RISCV_M_MODE # define CSR_STATUS CSR_MSTATUS # define CSR_IE CSR_MIE