From patchwork Wed Mar 13 06:26:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 160203 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp13955075jad; Tue, 12 Mar 2019 23:32:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwE8r3Qqu27S3QhXrSGMJQZ6/mI1vebFTiN4N3ffVmPqdpQI7WFyP3ylbDFvR0cEoa9Hnxs X-Received: by 2002:a25:750b:: with SMTP id q11mr34070949ybc.195.1552458756712; Tue, 12 Mar 2019 23:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552458756; cv=none; d=google.com; s=arc-20160816; b=OYTimzRIg3JhkzEEyG4wveq59fEl+HmmMNO8KKO7GNdHMO8o294TFA0yOYre6Q3RUM LRlBf01/v/UFWNjeLPuC+emrFAcUy5sF0Jnd4j283nxJzaRwagMB3LgsYvEVV+zzPOwF ikpZL2/NotCI9AkKXxlH+wSSdYXbDQhguJGiS8bCykthVX8baxk8h169ZrH8dEXWMEK4 TzwArbfBlivKzjH6zXxn5VasyHk+KYomRVs70v/qOrh+6m45mPPNTXHQrMv0oiGhn58T 7+zdzGq3Lu7aDktDdEkBuouk5Qk6HaMN+6GWD2KTreZ9A3MioHU0fNgm4Mn2MCgyQeen 4hJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=8ejONeoCzadNPUYlAxbfn+jA7CyP4F1IWrm2q1c5QP0=; b=j4vcGCKZRNxDkM6xQnOnC+M6fW6HAs5ACbSDbcryuJxJuYCyrwHz7fjlfr7JI63INr F3+wMN8sCrIdAvOJcKjorclRqqep8gfJNsU+TfIeM/WkhGdTnfN9IN1cA0XnmIAQNoUL USQIyFZcGK1n0S0cTYERwFlNuYPIMIPVtOre/a0ndBHXUTRc9PKgtFaNqj8LrNvdYkkL mxENMmh4y9EUnGW69gLWyJM9ATXRGtxf2JIn1Ewu3nknsHYSAqn+yudVYUPsbuxJ3c8H HuCLb3VNNDbQhBftWVuW6b8fbZsQ+msuZWiwV8ZqiLHd3Uxp3gPC56IJAJRpC2i+ClGE vyYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oN5wkKZq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id e82si6155319ybe.132.2019.03.12.23.32.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 12 Mar 2019 23:32:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=oN5wkKZq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:39226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xRM-0003sG-92 for patch@linaro.org; Wed, 13 Mar 2019 02:32:36 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53945) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3xLk-0000hT-LI for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3xLi-00021p-4v for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:47 -0400 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]:43162) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3xLg-00020S-TW for qemu-devel@nongnu.org; Wed, 13 Mar 2019 02:26:45 -0400 Received: by mail-pg1-x542.google.com with SMTP id l11so776770pgq.10 for ; Tue, 12 Mar 2019 23:26:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8ejONeoCzadNPUYlAxbfn+jA7CyP4F1IWrm2q1c5QP0=; b=oN5wkKZqD0fvF9x65sX6QPI+B7vDpOFru4ra3fiMqAAehA+8tZmzEwYnh25dAFFBa3 I5UhXUprlSaRE0hfLpNNm+ycev2GgFsBDWObqbZ40CiaIuefqSVq+1p7PJ+/glVi21D5 tWelcGYPLEeUE2PyuxECJYWQ62XmFMcDs0aaAOgP1GxyrnSBriKZeEQnc12qyuwKXSC7 t9Qyl5SWDFE5HnZ3IB1A7My/giE5DmPHVuS2HD/cstKNajmPfXgsx6WDtl/y8sFQbwOl RWyjzJg4WpTGIvCVa7knqA/rQf75VDtidioRKK5rPBR/Rbx1R4RVVXB06Zv7xYSl48c+ AY0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8ejONeoCzadNPUYlAxbfn+jA7CyP4F1IWrm2q1c5QP0=; b=Ns2pRukoGrLXLhEc9/2yeM9fTfzplvDgBnGFU6Qsxmi7l+ciThI7GcFVnc0V2YG4rf ZHMu9eQTEte8OsLop5Cp/OmDykRp3QzfDS1oQwbJNsyjyVcSsDn8RS7tgy6qOz7zFheK HFlX4zAizeVhEfLSAjqW/LoZarhogZCE1xEjq+K+dfs0CqkaY0NJ0WfzBJEj/mqi61EZ onJtg264WFef4c7DDulMGZnEzE2AM7GhRTGTVLuMitEed4Mh84ztKClJsyAIHeE9nnEJ u8wOylaYow0mIHHr+JEq0VSpUcQJ3j8Lqy0nfXAUA0pX7trWqtX2aaxrkWrOM8pFYlbz ITvA== X-Gm-Message-State: APjAAAXBnwtj//2+PlSIdEVaEry3o6F2c7ZQIXlFTdSo9oR1Dx7mLn8Z CfSYWVyBC8c62KVaRJy1iRkSYBp3voY= X-Received: by 2002:aa7:8c13:: with SMTP id c19mr6053062pfd.247.1552458400890; Tue, 12 Mar 2019 23:26:40 -0700 (PDT) Received: from localhost.localdomain (97-113-188-82.tukw.qwest.net. [97.113.188.82]) by smtp.gmail.com with ESMTPSA id m64sm25593889pfi.149.2019.03.12.23.26.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Mar 2019 23:26:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Date: Tue, 12 Mar 2019 23:26:30 -0700 Message-Id: <20190313062630.30568-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190313062630.30568-1-richard.henderson@linaro.org> References: <20190313062630.30568-1-richard.henderson@linaro.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::542 Subject: [Qemu-devel] [PATCH for-4.1 7/7] target/arm: Implement ARMv8.5-RNG X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, david@redhat.com, laurent@vivier.eu, armbru@redhat.com, kraxel@redhat.com, pbonzini@redhat.com, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- target/arm/cpu.h | 5 +++++ target/arm/cpu64.c | 1 + target/arm/helper.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) -- 2.17.1 diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 5f23c62132..aaa9e02e78 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3441,6 +3441,11 @@ static inline bool isar_feature_aa64_condm_5(const ARMISARegisters *id) return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, TS) >= 2; } +static inline bool isar_feature_aa64_rndr(const ARMISARegisters *id) +{ + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RNDR) != 0; +} + static inline bool isar_feature_aa64_jscvt(const ARMISARegisters *id) { return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, JSCVT) != 0; diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 228906f267..835f73cceb 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -310,6 +310,7 @@ static void aarch64_max_initfn(Object *obj) t = FIELD_DP64(t, ID_AA64ISAR0, DP, 1); t = FIELD_DP64(t, ID_AA64ISAR0, FHM, 1); t = FIELD_DP64(t, ID_AA64ISAR0, TS, 2); /* v8.5-CondM */ + t = FIELD_DP64(t, ID_AA64ISAR0, RNDR, 1); cpu->isar.id_aa64isar0 = t; t = cpu->isar.id_aa64isar1; diff --git a/target/arm/helper.c b/target/arm/helper.c index 2607d39ad1..3fe7dc8719 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -20,6 +20,7 @@ #include "fpu/softfloat.h" #include "qemu/range.h" #include "qapi/qapi-commands-target.h" +#include "qemu/random.h" #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ @@ -5717,6 +5718,34 @@ static const ARMCPRegInfo pauth_reginfo[] = { .fieldoffset = offsetof(CPUARMState, apib_key.hi) }, REGINFO_SENTINEL }; + +static uint64_t rndr_readfn(CPUARMState *env, const ARMCPRegInfo *ri) +{ + uint64_t ret; + + /* Success sets NZCV = 0000. */ + env->NF = env->CF = env->VF = 0, env->ZF = 1; + if (likely(qemu_getrandom(&ret, sizeof(ret), true))) { + return ret; + } + + /* Failure sets Z = 1 and returns 0. */ + env->ZF = 0; + return 0; +} + +/* We do not support re-seeding, so the two registers operate the same. */ +static const ARMCPRegInfo rndr_reginfo[] = { + { .name = "RNDR", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END, + .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 0, + .access = PL0_R, .readfn = rndr_readfn }, + { .name = "RNDRRS", .state = ARM_CP_STATE_AA64, + .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END, + .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 1, + .access = PL0_R, .readfn = rndr_readfn }, + REGINFO_SENTINEL +}; #endif static CPAccessResult access_predinv(CPUARMState *env, const ARMCPRegInfo *ri, @@ -6661,6 +6690,9 @@ void register_cp_regs_for_features(ARMCPU *cpu) if (cpu_isar_feature(aa64_pauth, cpu)) { define_arm_cp_regs(cpu, pauth_reginfo); } + if (cpu_isar_feature(aa64_rndr, cpu)) { + define_arm_cp_regs(cpu, rndr_reginfo); + } #endif /*