From patchwork Mon Nov 17 16:47:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Bellows X-Patchwork-Id: 40937 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 30E752450C for ; Mon, 17 Nov 2014 16:49:36 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id 10sf11693789lbg.9 for ; Mon, 17 Nov 2014 08:49:35 -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=e1PFg2Bei1NHEZQcmDTo6y3MOLKj+jL+y9lTAi/nULc=; b=JqBBebWvhbSmxNq2yr6EUVAbEZ5JtZ7/xsVB9Fo2sW6rVWt9/GUpxffKB1KsR1V0OR 65/a7YwzsmTz82U4z3mdOYbInNy64QZf/xEVV+7+gdULzwgPZ4lxWMs+twUjzFPGdwxn 5yN0oCnx63O04OHwR2pf2NZ/fNlblCkFANdjWcWN4MU5G/ZawUfCMuqyz3S79bF6FDkR VhPW+ISguNdg8ZqZl2LgCDmYBHX2OdYyjcDlFArwSTWu716XMa+LXbRjx6UYqEF9RTV0 o5VmF0C+bT9QfBd8a0sC2aPzhu6uEcOnqfNNBAB5oNFxb5gmT1QFTh22+rwIjCg4zQ/f fBRQ== X-Gm-Message-State: ALoCoQmJAGD9u8aFjYE6uTgxRBFIex0j+CFdmVToJxp6tMM4pEwt++mzjMymI+giVJWlG12E4uNX X-Received: by 10.152.26.72 with SMTP id j8mr14177687lag.3.1416242975178; Mon, 17 Nov 2014 08:49:35 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.137 with SMTP id b9ls649090lah.29.gmail; Mon, 17 Nov 2014 08:49:35 -0800 (PST) X-Received: by 10.112.24.130 with SMTP id u2mr3298827lbf.57.1416242975034; Mon, 17 Nov 2014 08:49:35 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id q15si12949752lal.79.2014.11.17.08.49.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Nov 2014 08:49:35 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id l4so16392352lbv.10 for ; Mon, 17 Nov 2014 08:49:34 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr28554166laz.27.1416242974920; Mon, 17 Nov 2014 08:49:34 -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 ew9csp1186892lbc; Mon, 17 Nov 2014 08:49:34 -0800 (PST) X-Received: by 10.229.64.134 with SMTP id e6mr35676819qci.11.1416242973466; Mon, 17 Nov 2014 08:49:33 -0800 (PST) Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id d89si3240404qga.43.2014.11.17.08.49.33 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 17 Nov 2014 08:49:33 -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]:48834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqPUa-0002RJ-Oz for patch@linaro.org; Mon, 17 Nov 2014 11:49:32 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59710) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqPTK-0000xX-Fo for qemu-devel@nongnu.org; Mon, 17 Nov 2014 11:48:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XqPTE-00076T-Bc for qemu-devel@nongnu.org; Mon, 17 Nov 2014 11:48:14 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:33306) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XqPTE-00076F-4D for qemu-devel@nongnu.org; Mon, 17 Nov 2014 11:48:08 -0500 Received: by mail-pa0-f52.google.com with SMTP id eu11so1721298pac.25 for ; Mon, 17 Nov 2014 08:48:07 -0800 (PST) X-Received: by 10.70.43.229 with SMTP id z5mr30642234pdl.25.1416242887548; Mon, 17 Nov 2014 08:48:07 -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 r2sm18499056pdi.60.2014.11.17.08.48.06 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 17 Nov 2014 08:48:06 -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: Mon, 17 Nov 2014 10:47:33 -0600 Message-Id: <1416242878-876-2-git-send-email-greg.bellows@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1416242878-876-1-git-send-email-greg.bellows@linaro.org> References: <1416242878-876-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.52 Cc: greg.bellows@linaro.org Subject: [Qemu-devel] [PATCH v11 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.179 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 Reviewed-by: Peter Maydell --- v10 -> v11 - Fix arm_excp_unmasked el3_is_aa64 logic so it is clearer. 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..810cc0b 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -1247,27 +1247,50 @@ 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; + + /* 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 &= !((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 = (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 +1306,21 @@ 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)) { + if (arm_el_is_aa64(env, 3) || ((scr || hcr) && (!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)