From patchwork Fri Oct 24 11:37:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 39454 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7B12824026 for ; Fri, 24 Oct 2014 12:00:30 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id bs8sf571506wib.11 for ; Fri, 24 Oct 2014 05:00:29 -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=HDAqLOK0PlX91XBp2ICNNN0J5prLmbC05v0aEgoos50=; b=HmSU9Wlw0LMfw6+UF7VjtWUqgJ2Qt/X7BnjDOmiZkxevK2znZvOW18TneHHwVcTQHA Wz1UIdLmEnO4Jwk6xmi2eBeAPGWVnYIJ6llW1QFnnrQDVlk5ifxJoNUuPAVQaVmuwEr6 JptM8PDoh+PzPHsp4x916G/hQjCYeELnhzvKjcZFkzUm4lL8Kp80nu11WuEA5spdFgio jMAo3LzseirIk6GOO4MxJhj2PH0c26phuRaMmmFL1POS5QQ+SXrJIJT7GhuXlTeB410D +5eA0xpr+81RqB+YGTIyvj1JNBOlDur0DG2BdNBbed52L6+A1n9FaBQNLhM9MHvRVFNV 0bKg== X-Gm-Message-State: ALoCoQk0nJfa+uh7eVUVsN0KYOrl8Ijm8tVCIJ5ZR0B/7lASsEkCbVbp2fGyhH4hSXhy8SkxgQke X-Received: by 10.112.180.71 with SMTP id dm7mr383202lbc.18.1414152029675; Fri, 24 Oct 2014 05:00:29 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.97 with SMTP id p1ls362573laj.87.gmail; Fri, 24 Oct 2014 05:00:29 -0700 (PDT) X-Received: by 10.112.219.3 with SMTP id pk3mr4084835lbc.18.1414152029520; Fri, 24 Oct 2014 05:00:29 -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 ks12si6728457lac.5.2014.10.24.05.00.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Oct 2014 05:00:29 -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 gq15so2472500lab.26 for ; Fri, 24 Oct 2014 05:00:29 -0700 (PDT) X-Received: by 10.153.8.164 with SMTP id dl4mr3969693lad.29.1414152029427; Fri, 24 Oct 2014 05:00:29 -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 c5csp414147lbz; Fri, 24 Oct 2014 05:00:28 -0700 (PDT) X-Received: by 10.224.124.67 with SMTP id t3mr5150334qar.20.1414152027808; Fri, 24 Oct 2014 05:00:27 -0700 (PDT) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u3si7355423qae.128.2014.10.24.05.00.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 24 Oct 2014 05:00:27 -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]:47068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhdXf-0002Q5-2P for patch@linaro.org; Fri, 24 Oct 2014 08:00:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50374) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhdBb-0006ZA-Qh for qemu-devel@nongnu.org; Fri, 24 Oct 2014 07:37:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XhdBa-0008QO-59 for qemu-devel@nongnu.org; Fri, 24 Oct 2014 07:37:39 -0400 Received: from mnementh.archaic.org.uk ([2001:8b0:1d0::1]:54280) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhdBZ-0008OE-U8 for qemu-devel@nongnu.org; Fri, 24 Oct 2014 07:37:38 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1XhdBS-0007wl-KO for qemu-devel@nongnu.org; Fri, 24 Oct 2014 12:37:30 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 24 Oct 2014 12:37:25 +0100 Message-Id: <1414150649-30428-20-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1414150649-30428-1-git-send-email-peter.maydell@linaro.org> References: <1414150649-30428-1-git-send-email-peter.maydell@linaro.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:8b0:1d0::1 Subject: [Qemu-devel] [PULL 19/23] 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: peter.maydell@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 Reviewed-by: Peter Maydell Message-id: 1413910544-20150-3-git-send-email-greg.bellows@linaro.org Signed-off-by: Peter Maydell --- target-arm/cpu.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index e0e3f9b..44ed6fe 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -753,6 +753,53 @@ static inline int arm_feature(CPUARMState *env, int feature) return (env->features & (1ULL << feature)) != 0; } +#if !defined(CONFIG_USER_ONLY) +/* Return true if exception levels below EL3 are in secure state, + * or would be following an exception return to that level. + * Unlike arm_is_secure() (which is always a question about the + * _current_ state of the CPU) this doesn't care about the current + * EL or mode. + */ +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) {