From patchwork Fri Oct 10 16:03:13 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 38594 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A7027205D8 for ; Fri, 10 Oct 2014 16:05:25 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id p9sf2316796lbv.8 for ; Fri, 10 Oct 2014 09:05:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:date :message-id:in-reply-to:references:subject:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=vhMnR3W1+2qjGSjizTksfCN2HAnhnqpA7mhoLn60koU=; b=XVtjG4Oro3BT/LZUGxZq+0v2gQxqbV1d+v9YjrMRZ9p7yY7EKEghMmLu+gCBjpeP4e OziF1Pv43x6gKHLOq5kezF5+nAAu8IhjHmyGajyFmPos30lhp5z4zAg+ZYHO8M2xN+lZ 2mka5MWplUZmQFeP1qbGwAq94Fsfe9VJJmBfvQFcwvBCTO+lPQbT6BjKNv9w0WIB3LMF imHnCvF9O/cQghiqNkBrveXOU6l/9vZ4qNTgEdTGXEPwbKZ62QLK+MKGwnkcWjLTVIqg /SJwLEw9yA1eCbG6cdYay3OKhB0T1n2LD4/7ORAW0IvoVVCvdidKs5SDKQMsjRB4qba5 OA9Q== X-Gm-Message-State: ALoCoQn3E5Z6SBjlTxlfk52PcuO4DqxhE7HcJXP5eY4nlF2PxuHjJ6PvZo3uFaxx/4JZITgaxP/Y X-Received: by 10.112.158.73 with SMTP id ws9mr11727lbb.22.1412957124134; Fri, 10 Oct 2014 09:05:24 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.2.67 with SMTP id 3ls298655las.63.gmail; Fri, 10 Oct 2014 09:05:24 -0700 (PDT) X-Received: by 10.153.4.11 with SMTP id ca11mr6045451lad.24.1412957123990; Fri, 10 Oct 2014 09:05:23 -0700 (PDT) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com [209.85.217.171]) by mx.google.com with ESMTPS id kk5si10023478lac.34.2014.10.10.09.05.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Oct 2014 09:05:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id z12so3389612lbi.30 for ; Fri, 10 Oct 2014 09:05:22 -0700 (PDT) X-Received: by 10.152.26.226 with SMTP id o2mr5951364lag.44.1412957122535; Fri, 10 Oct 2014 09:05:22 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp455748lbz; Fri, 10 Oct 2014 09:05:21 -0700 (PDT) X-Received: by 10.182.165.138 with SMTP id yy10mr5390291obb.5.1412957121067; Fri, 10 Oct 2014 09:05:21 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id x92si11627921qgx.99.2014.10.10.09.05.19 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 10 Oct 2014 09:05:19 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Received: from localhost ([::1]:49376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xccgw-0007zU-Gc for patch@linaro.org; Fri, 10 Oct 2014 12:05:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34843) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xccfi-0006lb-EP for qemu-devel@nongnu.org; Fri, 10 Oct 2014 12:04:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xccfd-0007wa-Hl for qemu-devel@nongnu.org; Fri, 10 Oct 2014 12:04:02 -0400 Received: from mail-oi0-f48.google.com ([209.85.218.48]:32963) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xccfd-0007wV-Dk for qemu-devel@nongnu.org; Fri, 10 Oct 2014 12:03:57 -0400 Received: by mail-oi0-f48.google.com with SMTP id g201so7088675oib.7 for ; Fri, 10 Oct 2014 09:03:57 -0700 (PDT) X-Received: by 10.202.11.72 with SMTP id 69mr5288546oil.40.1412957036908; Fri, 10 Oct 2014 09:03:56 -0700 (PDT) Received: from gbellows-linaro.bellowshome.net (99-179-1-128.lightspeed.austtx.sbcglobal.net. [99.179.1.128]) by mx.google.com with ESMTPSA id d6sm5382455obt.12.2014.10.10.09.03.55 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Oct 2014 09:03:56 -0700 (PDT) From: Greg Bellows To: qemu-devel@nongnu.org, peter.maydell@linaro.org, serge.fdrv@gmail.com, edgar.iglesias@gmail.com, aggelerf@ethz.ch Date: Fri, 10 Oct 2014 11:03:13 -0500 Message-Id: <1412957023-11105-3-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1412957023-11105-1-git-send-email-greg.bellows@linaro.org> References: <1412957023-11105-1-git-send-email-greg.bellows@linaro.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.218.48 Subject: [Qemu-devel] [PATCH v6 02/32] target-arm: add arm_is_secure() function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: greg.bellows@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Fabian Aggeler arm_is_secure() function allows to determine CPU security state if the CPU implements Security Extensions/EL3. arm_is_secure_below_el3() returns true if CPU is in secure state below EL3. Signed-off-by: Sergey Fedorov Signed-off-by: Fabian Aggeler Signed-off-by: Greg Bellows ========== v5 -> v6 - Broaden CONFIG_USER conditional - Merge resulting false returns with common comment - Globally change Aarch# to AArch# - Replace direct access of env->aarch64 with is_a64() --- target-arm/cpu.h | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 81fffd2..4f6db0f 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -753,6 +753,48 @@ static inline int arm_feature(CPUARMState *env, int feature) return (env->features & (1ULL << feature)) != 0; } +#if !defined(CONFIG_USER_ONLY) +/* Return true if exception level below EL3 is in secure state */ +static inline bool arm_is_secure_below_el3(CPUARMState *env) +{ + if (arm_feature(env, ARM_FEATURE_EL3)) { + return !(env->cp15.scr_el3 & SCR_NS); + } else { + /* If EL2 is not supported then the secure state is implementation + * defined, in which case QEMU defaults to non-secure. + */ + return false; + } +} + +/* Return true if the processor is in secure state */ +static inline bool arm_is_secure(CPUARMState *env) +{ + if (arm_feature(env, ARM_FEATURE_EL3)) { + if (is_a64(env) && extract32(env->pstate, 2, 2) == 3) { + /* CPU currently in AArch64 state and EL3 */ + return true; + } else if (!is_a64(env) && + (env->uncached_cpsr & CPSR_M) == ARM_CPU_MODE_MON) { + /* CPU currently in AArch32 state and monitor mode */ + return true; + } + } + return arm_is_secure_below_el3(env); +} + +#else +static inline bool arm_is_secure_below_el3(CPUARMState *env) +{ + return false; +} + +static inline bool arm_is_secure(CPUARMState *env) +{ + return false; +} +#endif + /* Return true if the specified exception level is running in AArch64 state. */ static inline bool arm_el_is_aa64(CPUARMState *env, int el) {