From patchwork Thu Nov 6 15:50:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 40326 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 74EC820C4E for ; Thu, 6 Nov 2014 15:52:48 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id b13sf823106wgh.2 for ; Thu, 06 Nov 2014 07:52:47 -0800 (PST) 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=RQGX4RyVUMCA8kVnzmgXQ1MkskwYR49IYIWesf1txwg=; b=ak2X18ReQoikZLiPAW1EubjLi+m133iCgXvloHgbziVzra+aLDl2U6ekAf40604MPt 5V1eesQ5v1nnuAei7i9m3hxQA4bdNF4m36hMsANXKr+A1W0S1nTrA/Itjc1mypWLP0Sd G8H6EoLPbOdDvYjuqoMJ/Qv2l4mi1XVirj+hN9hKWSCqHgUTW1zgDNsTrfdQ/8t626CG zgIlQvi23lpjCf10kyq+MzS/czwMBJFD0jfM+3GD07r0FjN/do6nlXtVisRj9IvcocOf BLgg1cZXRicm4Ca8CLtVw8DCodAwed+WWn757PYAqbigsSjo6kKMwKf+lWl2d7RSKhb9 u6CQ== X-Gm-Message-State: ALoCoQkLpXOKTbR/C1J9NpNjmYVwlozWkAbuUONXUYePhgY68DoxgyYQVXtgw76msZ1pg1ZNVWMq X-Received: by 10.112.159.199 with SMTP id xe7mr115180lbb.21.1415289167394; Thu, 06 Nov 2014 07:52:47 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.227 with SMTP id e3ls104069laa.69.gmail; Thu, 06 Nov 2014 07:52:47 -0800 (PST) X-Received: by 10.152.3.168 with SMTP id d8mr5872976lad.34.1415289167044; Thu, 06 Nov 2014 07:52:47 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id c8si4287095lac.96.2014.11.06.07.52.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 07:52:47 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id u10so1159966lbd.11 for ; Thu, 06 Nov 2014 07:52:47 -0800 (PST) X-Received: by 10.152.6.228 with SMTP id e4mr5692382laa.71.1415289166938; Thu, 06 Nov 2014 07:52:46 -0800 (PST) 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.184.201 with SMTP id ew9csp65286lbc; Thu, 6 Nov 2014 07:52:46 -0800 (PST) X-Received: by 10.140.17.67 with SMTP id 61mr7455312qgc.59.1415289164988; Thu, 06 Nov 2014 07:52:44 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 64si12362011qgy.68.2014.11.06.07.52.44 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 06 Nov 2014 07:52:44 -0800 (PST) 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]:54558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmPMa-0002TT-3q for patch@linaro.org; Thu, 06 Nov 2014 10:52:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36544) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmPLQ-0001S1-83 for qemu-devel@nongnu.org; Thu, 06 Nov 2014 10:51:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XmPLK-0003u7-Av for qemu-devel@nongnu.org; Thu, 06 Nov 2014 10:51:32 -0500 Received: from mail-pd0-f178.google.com ([209.85.192.178]:49330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmPLK-0003tz-0z for qemu-devel@nongnu.org; Thu, 06 Nov 2014 10:51:26 -0500 Received: by mail-pd0-f178.google.com with SMTP id fp1so1347741pdb.37 for ; Thu, 06 Nov 2014 07:51:25 -0800 (PST) X-Received: by 10.68.93.132 with SMTP id cu4mr5394435pbb.36.1415289085302; Thu, 06 Nov 2014 07:51:25 -0800 (PST) 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 z9sm6245585pdp.73.2014.11.06.07.51.23 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 06 Nov 2014 07:51:24 -0800 (PST) From: Greg Bellows To: qemu-devel@nongnu.org, serge.fdrv@gmail.com, edgar.iglesias@gmail.com, aggelerf@ethz.ch, peter.maydell@linaro.org Date: Thu, 6 Nov 2014 09:50:48 -0600 Message-Id: <1415289073-14681-2-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415289073-14681-1-git-send-email-greg.bellows@linaro.org> References: <1415289073-14681-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.192.178 Cc: greg.bellows@linaro.org Subject: [Qemu-devel] [PATCH v10 01/26] target-arm: extend async excp masking 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.180 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 This patch extends arm_excp_unmasked() to use lookup tables for determining whether IRQ and FIQ exceptions are masked. The lookup tables are based on the ARMv8 and ARMv7 specification physical interrupt masking tables. If EL3 is using AArch64 IRQ/FIQ masking is ignored in all exception levels other than EL3 if SCR.{FIQ|IRQ} is set to 1 (routed to EL3). Signed-off-by: Greg Bellows --- v8 -> v9 - Undo the use of tables for exception masking and instead go with simplified logic based on the target EL lookup. - Remove the masking tables v7 -> v8 - Add IRQ and FIQ exeception masking lookup tables. - Rewrite patch to use lookup tables for determining whether an excpetion is masked or not. v5 -> v6 - Globally change Aarch# to AArch# - Fixed comment termination v4 -> v5 - Merge with v4 patch 10 --- target-arm/cpu.h | 66 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 7f80090..cf30b2a 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -1247,27 +1247,51 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx) CPUARMState *env = cs->env_ptr; unsigned int cur_el = arm_current_el(env); unsigned int target_el = arm_excp_target_el(cs, excp_idx); - /* FIXME: Use actual secure state. */ - bool secure = false; - /* If in EL1/0, Physical IRQ routing to EL2 only happens from NS state. */ - bool irq_can_hyp = !secure && cur_el < 2 && target_el == 2; - - /* Don't take exceptions if they target a lower EL. */ + bool secure = arm_is_secure(env); + uint32_t scr; + uint32_t hcr; + bool pstate_unmasked; + int8_t unmasked = 0; + bool is_aa64 = arm_el_is_aa64(env, 3); + + /* Don't take exceptions if they target a lower EL. + * This check should catch any exceptions that would not be taken but left + * pending. + */ if (cur_el > target_el) { return false; } switch (excp_idx) { case EXCP_FIQ: - if (irq_can_hyp && (env->cp15.hcr_el2 & HCR_FMO)) { - return true; - } - return !(env->daif & PSTATE_F); + /* If FIQs are routed to EL3 or EL2 then there are cases where we + * override the CPSR.F in determining if the exception is masked or + * not. If neither of these are set then we fall back to the CPSR.F + * setting otherwise we further assess the state below. + */ + hcr = (env->cp15.hcr_el2 & HCR_FMO); + scr = (env->cp15.scr_el3 & SCR_FIQ); + + /* When EL3 is 32-bit, the SCR.FW bit controls whether the CPSR.F bit + * masks FIQ interrupts when taken in non-secure state. If SCR.FW is + * set then FIQs can be masked by CPSR.F when non-secure but only + * when FIQs are only routed to EL3. + */ + scr &= is_aa64 || !((env->cp15.scr_el3 & SCR_FW) && !hcr); + pstate_unmasked = !(env->daif & PSTATE_F); + break; + case EXCP_IRQ: - if (irq_can_hyp && (env->cp15.hcr_el2 & HCR_IMO)) { - return true; - } - return !(env->daif & PSTATE_I); + /* When EL3 execution state is 32-bit, if HCR.IMO is set then we may + * override the CPSR.I masking when in non-secure state. The SCR.IRQ + * setting has already been taken into consideration when setting the + * target EL, so it does not have a further affect here. + */ + hcr = is_aa64 || (env->cp15.hcr_el2 & HCR_IMO); + scr = false; + pstate_unmasked = !(env->daif & PSTATE_I); + break; + case EXCP_VFIQ: if (secure || !(env->cp15.hcr_el2 & HCR_FMO)) { /* VFIQs are only taken when hypervized and non-secure. */ @@ -1283,6 +1307,20 @@ static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx) default: g_assert_not_reached(); } + + /* Use the target EL, current execution state and SCR/HCR settings to + * determine whether the corresponding CPSR bit is used to mask the + * interrupt. + */ + if ((target_el > cur_el) && (target_el != 1) && (scr || hcr) && + (is_aa64 || !secure)) { + unmasked = 1; + } + + /* The PSTATE bits only mask the interrupt if we have not overriden the + * ability above. + */ + return unmasked || pstate_unmasked; } static inline CPUARMState *cpu_init(const char *cpu_model)