From patchwork Tue Sep 30 21:49:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 38186 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id EB9DF2032C for ; Tue, 30 Sep 2014 21:51:58 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf44473lab.3 for ; Tue, 30 Sep 2014 14:51:57 -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:cc: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=pkgECpv0vmJAEzhWXhRDuj/bcsCh0Pa8nQiy5mhAVHY=; b=aYcOIXnCRF99GZW65p5J5rmpN9kpkZPmzjPmisHHGU1MzdOUOcwgsuadBjgAaF5Zt4 nt58X8oGtG+BdzGFG8FZXvO8MUOmrEfDZV2yH+B47Dc6VU6ZxzDz/4RjVvl/gNqJoQiU pZXkdtDlh/YOoHVTcNk/n/PX8MtUXpLvGIWu6DoiqYGiuQRTdD1XnKTOQTGMxR103OVe DPP+2SgaC7xOqOq3GAa9P8s0HNO7nHDU84sRgu0oSz1L+zmkbhRV/JnlMKiHZYsfMcxq LPnN3uuNuzgbFuoWkq8vyuAOusd68JcK9KbiBXd+3tqu8p/SsjgH6kp/dfmVXqHT2YZU M3mA== X-Gm-Message-State: ALoCoQljyh3npDhSC16fGVsLZtcfaQ/LAEcgaikHhYCZV3GekYOeQ0/KDfaTqiDCnV/1zWw2WOvz X-Received: by 10.194.249.134 with SMTP id yu6mr2577749wjc.1.1412113917697; Tue, 30 Sep 2014 14:51:57 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.136 with SMTP id kq8ls90208lac.94.gmail; Tue, 30 Sep 2014 14:51:57 -0700 (PDT) X-Received: by 10.112.125.132 with SMTP id mq4mr6471896lbb.103.1412113917541; Tue, 30 Sep 2014 14:51:57 -0700 (PDT) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com [209.85.215.53]) by mx.google.com with ESMTPS id f9si24533316lbs.67.2014.09.30.14.51.57 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Sep 2014 14:51:57 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by mail-la0-f53.google.com with SMTP id gq15so3454373lab.12 for ; Tue, 30 Sep 2014 14:51:57 -0700 (PDT) X-Received: by 10.152.204.231 with SMTP id lb7mr49838849lac.44.1412113917479; Tue, 30 Sep 2014 14:51:57 -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.130.169 with SMTP id of9csp429252lbb; Tue, 30 Sep 2014 14:51:56 -0700 (PDT) X-Received: by 10.224.10.198 with SMTP id q6mr68898172qaq.55.1412113916230; Tue, 30 Sep 2014 14:51:56 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id e9si20371574qcr.13.2014.09.30.14.51.55 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 30 Sep 2014 14:51:56 -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]:46543 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ5Kp-0001o6-WA for patch@linaro.org; Tue, 30 Sep 2014 17:51:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42977) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ5JE-0000Mx-Gy for qemu-devel@nongnu.org; Tue, 30 Sep 2014 17:50:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZ5J2-0003Gw-SN for qemu-devel@nongnu.org; Tue, 30 Sep 2014 17:50:12 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:56732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZ5J0-0003Ck-R4 for qemu-devel@nongnu.org; Tue, 30 Sep 2014 17:50:00 -0400 Received: by mail-pa0-f41.google.com with SMTP id eu11so4931335pac.0 for ; Tue, 30 Sep 2014 14:49:57 -0700 (PDT) X-Received: by 10.66.169.73 with SMTP id ac9mr66296367pac.102.1412113797082; Tue, 30 Sep 2014 14:49:57 -0700 (PDT) Received: from gbellows-linaro.qualcomm.com (rrcs-67-52-129-61.west.biz.rr.com. [67.52.129.61]) by mx.google.com with ESMTPSA id qy1sm16027662pbc.27.2014.09.30.14.49.55 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 30 Sep 2014 14:49: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: Tue, 30 Sep 2014 16:49:14 -0500 Message-Id: <1412113785-21525-3-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1412113785-21525-1-git-send-email-greg.bellows@linaro.org> References: <1412113785-21525-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.220.41 Cc: Sergey Fedorov , Greg Bellows Subject: [Qemu-devel] [PATCH v5 02/33] 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.215.53 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 --- target-arm/cpu.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 81fffd2..10afef0 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -753,6 +753,44 @@ static inline int arm_feature(CPUARMState *env, int feature) return (env->features & (1ULL << feature)) != 0; } + +/* Return true if exception level below EL3 is in secure state */ +static inline bool arm_is_secure_below_el3(CPUARMState *env) +{ +#if !defined(CONFIG_USER_ONLY) + if (arm_feature(env, ARM_FEATURE_EL3)) { + return !(env->cp15.scr_el3 & SCR_NS); + } else if (arm_feature(env, ARM_FEATURE_EL2)) { + return false; + } else { + /* IMPDEF: QEMU defaults to non-secure */ + return false; + } +#else + return false; +#endif +} + +/* Return true if the processor is in secure state */ +static inline bool arm_is_secure(CPUARMState *env) +{ +#if !defined(CONFIG_USER_ONLY) + if (arm_feature(env, ARM_FEATURE_EL3)) { + if (env->aarch64 && extract32(env->pstate, 2, 2) == 3) { + /* CPU currently in Aarch64 state and EL3 */ + return true; + } else if (!env->aarch64 && + (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 + 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) {