From patchwork Tue Dec 3 02:29:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 180667 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp942525ile; Mon, 2 Dec 2019 18:40:31 -0800 (PST) X-Google-Smtp-Source: APXvYqyNb/AV52iE0DI5/YESiZrVN8yJ3VwGIi0xZmaoH4Oohvi1v2QpA9A9Im99lq3m8hHzafv5 X-Received: by 2002:a17:906:33d2:: with SMTP id w18mr3406686eja.193.1575340831170; Mon, 02 Dec 2019 18:40:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575340831; cv=none; d=google.com; s=arc-20160816; b=J1rulpwmnjRWjnxFkAFsZGnho19bZRDQrzp9l8f/L5h7SQsJpUN64MyLQgmW/tqKwL taPx+jrjNFZuvFNdZoIyOZjMna8zAAidocTWdmhX8G8HYOyKSUo8zvm7y2lSz0cmWR26 704a84w9J70ee/nfz4yDvWcur4AZfZLQBDQHndlFpOfAlvm42mX8fmVcLqTDs8e2PHoF fYONGUQTNQrIxALDD6PsuV0qKGZIlZvY6OgY6wFf8u2+uf16sCSbNyT4Z1rRKSE7UWxJ vlYtnz9nV026Yuas7ymvvBJGpb1BaN6i7r9y3buNxPo62s1GQ3CTQ40kLh8j6QUb2gMH QBpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=B4OK5efhSNwYjg2uPjOpVrsLC64wOt5gZm1Hay36cdk=; b=tnExhRA/ZmHcebcraGBUZ8QQiRe5gKW+x+2SCmBHwWbPfyBbEbNBqrMwwmnfVbzptW n0SqBvtV2mtBM8FB9+4W66ZJCBQdsV4GaYK36gZM40+ZsQl9IaOGl1rEwXRfyHrUNNQ1 XLBI6JvUs0XDDhSNbEWP+Wtgb2H27c/GlL9rHMZdsXGqw8roD3zO/a12cMcH5jzjv9jm jG9UPGFx9bPkyYgl0p7pG2sSkRWQ1eMpSYRRqZ7V4kX33r7/nnsYsPJBbkcqIXaqUuZ/ pWUs6rObHvJf6dF6hJlyTMVm3lwwGE8GkmgiBF9NFLRDlaX4tNR1k+EpXuaLDq6JYm8s 2CcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=clOw8n7w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c20si1150944edt.157.2019.12.02.18.40.30 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 02 Dec 2019 18:40:31 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=clOw8n7w; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iby73-00063t-Ap for patch@linaro.org; Mon, 02 Dec 2019 21:40:29 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:59568) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ibxwi-000329-5w for qemu-devel@nongnu.org; Mon, 02 Dec 2019 21:29:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ibxwg-00082i-RA for qemu-devel@nongnu.org; Mon, 02 Dec 2019 21:29:47 -0500 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:35153) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ibxwg-00081I-LK for qemu-devel@nongnu.org; Mon, 02 Dec 2019 21:29:46 -0500 Received: by mail-pf1-x444.google.com with SMTP id b19so991719pfo.2 for ; Mon, 02 Dec 2019 18:29:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B4OK5efhSNwYjg2uPjOpVrsLC64wOt5gZm1Hay36cdk=; b=clOw8n7wldm1zRwqprAH0AohlYp0Z82dbX+3fEU1Q3IGgXz6GVClQNHF1CSaIj68/6 8BA/KuvYj4WnZzWSuMJVU7z9v+GbDzq3mbiYpV5jbfHQNHdhH8BzQS2E2F2akJqPcigw eVTRar3ZaWAL40y3xcRMpxhWXE4+hiPyYRF6d+vHWBklyPydLP98o63d4/T/yi4LltRC jNOJmeMD3PV/EGT+ez6X+hsb9Uk2MeDVM9y+qS2exz7tfAzqPafomdtQMzb1uKGN/h4x tbfFDYORuqjfxax7+kw30tE3SKNtBPo5xTtb5m1E4j9DL+ZSNlkvusRLqI0nf5C8UZoj HJgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B4OK5efhSNwYjg2uPjOpVrsLC64wOt5gZm1Hay36cdk=; b=DIRSpbWiNoSuCEXtVCeh2Wvlx/qME/wIp0Eo2Q83WRmiXDCDdKNNa4sT2IQzJyPyIx +UxXSYDk8kJ76MNVpXJPWOxF7ZP6biL/N47Q7S+Cjz7ma7S2vuGWEXbLcxpeLQN/EQ8H +wGqVxE3M5NrhPNP9lncnwdZBA9mPLCwi3UzmHYyOC20xFqFtGmtTVCU157aKDxl42r9 RmP6DvbHVKlZ51yQJooERHnNkmYzpo22+iEemq0UFNVsG3MWewFaTXhahlU3OjL9A8rx VA9476OSIwE5oL6EO6DlKB3WEAXwktCzLJxMtz0nsJoDlPu5WfFEBL76tsqHqZimfDnz eDLw== X-Gm-Message-State: APjAAAXpOQcldsdJXZe+VjQkM44aOfBVpD9b3IrS9y2rolYsbzuc1Xnh IZ8pbS5GHjMOWJ69w9nkC+xeBibhBxI= X-Received: by 2002:a63:5346:: with SMTP id t6mr2545902pgl.302.1575340185457; Mon, 02 Dec 2019 18:29:45 -0800 (PST) Received: from localhost.localdomain (97-113-7-119.tukw.qwest.net. [97.113.7.119]) by smtp.gmail.com with ESMTPSA id q22sm873695pfg.170.2019.12.02.18.29.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 18:29:44 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 05/40] target/arm: Update CNTVCT_EL0 for VHE Date: Mon, 2 Dec 2019 18:29:02 -0800 Message-Id: <20191203022937.1474-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191203022937.1474-1-richard.henderson@linaro.org> References: <20191203022937.1474-1-richard.henderson@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::444 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The virtual offset may be 0 depending on EL, E2H and TGE. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- target/arm/helper.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/target/arm/helper.c b/target/arm/helper.c index 06ec4641f3..731507a82f 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2475,9 +2475,31 @@ static uint64_t gt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri) return gt_get_countervalue(env); } +static uint64_t gt_virt_cnt_offset(CPUARMState *env) +{ + uint64_t hcr; + + switch (arm_current_el(env)) { + case 2: + hcr = arm_hcr_el2_eff(env); + if (hcr & HCR_E2H) { + return 0; + } + break; + case 0: + hcr = arm_hcr_el2_eff(env); + if ((hcr & (HCR_E2H | HCR_TGE)) == (HCR_E2H | HCR_TGE)) { + return 0; + } + break; + } + + return env->cp15.cntvoff_el2; +} + static uint64_t gt_virt_cnt_read(CPUARMState *env, const ARMCPRegInfo *ri) { - return gt_get_countervalue(env) - env->cp15.cntvoff_el2; + return gt_get_countervalue(env) - gt_virt_cnt_offset(env); } static void gt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -2492,7 +2514,13 @@ static void gt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri, static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri, int timeridx) { - uint64_t offset = timeridx == GTIMER_VIRT ? env->cp15.cntvoff_el2 : 0; + uint64_t offset = 0; + + switch (timeridx) { + case GTIMER_VIRT: + offset = gt_virt_cnt_offset(env); + break; + } return (uint32_t)(env->cp15.c14_timer[timeridx].cval - (gt_get_countervalue(env) - offset)); @@ -2502,7 +2530,13 @@ static void gt_tval_write(CPUARMState *env, const ARMCPRegInfo *ri, int timeridx, uint64_t value) { - uint64_t offset = timeridx == GTIMER_VIRT ? env->cp15.cntvoff_el2 : 0; + uint64_t offset = 0; + + switch (timeridx) { + case GTIMER_VIRT: + offset = gt_virt_cnt_offset(env); + break; + } trace_arm_gt_tval_write(timeridx, value); env->cp15.c14_timer[timeridx].cval = gt_get_countervalue(env) - offset +