From patchwork Mon Jun 30 23:09:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 32805 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f197.google.com (mail-ve0-f197.google.com [209.85.128.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E9F86203F4 for ; Mon, 30 Jun 2014 23:13:33 +0000 (UTC) Received: by mail-ve0-f197.google.com with SMTP id jz11sf21186018veb.0 for ; Mon, 30 Jun 2014 16:13:33 -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=WbTs+b8wiBQAJccct8s6cKFmrOXWiVC6nBm9l9O7Acs=; b=CwdEJ9tcSvtX9xsfENhV/XcEnH3lRGxDNOLPj613iO1iAZ/tLsUBdpd7Kob9qdbgk6 1vBQeow+LnjOdsJV65cZMdbZ2FmO6OFgR4EvQOJ8QGrzQwnMpwhc8OO2bj1ygkl/k49L DROXHksm4SoKL9CbQ302ul6fZo4Fg0yo8F3f2UjuIrMMK5qswRQlB9b0vpLv8D+N8o2A 6SttxnKn5z4864Io1WeghW3A++MCMw9sQtv9jrnxEWmqvRsREkAbZFf2ifpmCnZdXy/B 2hT4Ya0yyTNM1m0sEkW+XRvxcxYadPr2E0CnxJ70qkaddtL5+Oxi1y3Dx9pDVLD6BM/P cDvg== X-Gm-Message-State: ALoCoQl96HkO/EkqDnH/RHKg58psxMTRBhIu6+61ZGDYbFXNKGtq20EXIOxNjRrGzi9xDilqOVwZ X-Received: by 10.236.144.136 with SMTP id n8mr1818683yhj.22.1404170013692; Mon, 30 Jun 2014 16:13:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.81.240 with SMTP id f103ls1664226qgd.95.gmail; Mon, 30 Jun 2014 16:13:33 -0700 (PDT) X-Received: by 10.58.29.16 with SMTP id f16mr41859156veh.23.1404170013561; Mon, 30 Jun 2014 16:13:33 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id cz8si10694957vcb.88.2014.06.30.16.13.33 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 16:13:33 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id il7so8163945vcb.41 for ; Mon, 30 Jun 2014 16:13:33 -0700 (PDT) X-Received: by 10.52.117.209 with SMTP id kg17mr33130842vdb.28.1404170013472; Mon, 30 Jun 2014 16:13:33 -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.221.37.5 with SMTP id tc5csp174899vcb; Mon, 30 Jun 2014 16:13:33 -0700 (PDT) X-Received: by 10.224.160.209 with SMTP id o17mr66435045qax.103.1404170012974; Mon, 30 Jun 2014 16:13:32 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id o19si27039135qae.2.2014.06.30.16.13.32 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 30 Jun 2014 16:13:32 -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]:37029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1klQ-0008LG-Be for patch@linaro.org; Mon, 30 Jun 2014 19:13:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1kic-0005Y6-JR for qemu-devel@nongnu.org; Mon, 30 Jun 2014 19:10:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X1kiU-00037Y-1I for qemu-devel@nongnu.org; Mon, 30 Jun 2014 19:10:38 -0400 Received: from mail-ob0-f180.google.com ([209.85.214.180]:48309) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X1kiT-00037M-ST for qemu-devel@nongnu.org; Mon, 30 Jun 2014 19:10:29 -0400 Received: by mail-ob0-f180.google.com with SMTP id vb8so9558514obc.39 for ; Mon, 30 Jun 2014 16:10:29 -0700 (PDT) X-Received: by 10.182.241.130 with SMTP id wi2mr40491422obc.27.1404169829528; Mon, 30 Jun 2014 16:10:29 -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 cu7sm76370192oec.12.2014.06.30.16.10.27 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 30 Jun 2014 16:10:28 -0700 (PDT) From: greg.bellows@linaro.org To: qemu-devel@nongnu.org Date: Mon, 30 Jun 2014 18:09:04 -0500 Message-Id: <1404169773-20264-5-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1404169773-20264-1-git-send-email-greg.bellows@linaro.org> References: <1404169773-20264-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.214.180 Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, Sergey Fedorov , Fabian Aggeler , Greg Bellows , serge.fdrv@gmail.com, edgar.iglesias@gmail.com, christoffer.dall@linaro.org Subject: [Qemu-devel] [PATCH v4 04/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.220.182 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 ffc51f2..aba077b 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -726,6 +726,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) {