From nobody Thu Nov 13 13:39:30 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580342773064112.48049761143795; Wed, 29 Jan 2020 16:06:13 -0800 (PST) Received: from localhost ([::1]:53682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwxLX-0001eo-Vc for importer@patchew.org; Wed, 29 Jan 2020 19:06:12 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45141) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwxC5-0003c4-2C for qemu-devel@nongnu.org; Wed, 29 Jan 2020 18:56:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iwxC4-0006vf-1Z for qemu-devel@nongnu.org; Wed, 29 Jan 2020 18:56:24 -0500 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]:41616) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iwxC3-0006tT-SB for qemu-devel@nongnu.org; Wed, 29 Jan 2020 18:56:23 -0500 Received: by mail-pf1-x443.google.com with SMTP id w62so486450pfw.8 for ; Wed, 29 Jan 2020 15:56:23 -0800 (PST) Received: from localhost.localdomain (97-126-123-70.tukw.qwest.net. [97.126.123.70]) by smtp.gmail.com with ESMTPSA id r3sm3953626pfg.145.2020.01.29.15.56.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jan 2020 15:56:21 -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=QOmO6ZsE3LQMtWFwohSrFylZgkA3stKDr6742fL9gX0=; b=e5udKOgHlkctbgDPhLnQcUsKI+9BS9UKqr3s4KI4JXH3qpDyEFarq4lG4Z5Nib+lDQ dNgLfoFYnELPG7mvC011BA77bhikhXim6geTbsrD5R7UzFUtT77YJkdO7Zagx7LiXDu1 Ks2H0fBcLnivhsRvGbcYoD+kbdeBnQxZxmaIdGFkKcS24lW0Bhz2fch5L2zBuSN5MMVo BQSHXFBXTiEEoegBDEbIoPpP7Mu2AIK3K3vPaZ6Zq+ZS/akjPMnPKBsAYW8ajHB5MmxU gInPLV9RTc528HSJkFT6mvrdZXBG11NKi2sj8oJoC/QKxaYlCMn7b5j0wxZ/8W6nOkIm KGZg== 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=QOmO6ZsE3LQMtWFwohSrFylZgkA3stKDr6742fL9gX0=; b=jomlTkPABKetiR1yCCdwXDj8Y66T3xMCDPdGFgWF1WDQGy4IkjF4v0rJl3nDh1tqSs JootysvyG0+xppmvrZPFnKHCQDdVeJv6kZ7GGV8aeKS86SnO6N3wJJFSdfPusHVRmbPF woavVZ5E84H1Y7gnuI0/Cqxp3j0v/B7Dd031VKShyeO6veYUGoSYTP8xeKwZd4LyEN6V 2YkA+8ek9wGOtIk0vAZ7quG99aFDEF5Ol6yQ4AF0GsGOUHyYL6u6Riqp8rQJIw0PmG/O wUdl6waNlU/nc6QRhaScPkJ3YO5aJ89b9G0PO8Omx39zznOFJURYZeGCJo73OqTCv/Lw jfHg== X-Gm-Message-State: APjAAAXj6ft47mG2y+O7pX45KGte7PF/oN0E56WqhDKPO7pUk3kHOe0D WFB7hT+1Odp0hFFkqW8TRIvjJJ0S/g0= X-Google-Smtp-Source: APXvYqw7KvkNaBuUD+0Ig7chtPFZfNIDYEJ2FC0cCP2HBqgosLfNz502iZbloduev2rPg2MJlf+pHQ== X-Received: by 2002:a63:ff20:: with SMTP id k32mr1643343pgi.448.1580342182537; Wed, 29 Jan 2020 15:56:22 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v5 05/41] target/arm: Update CNTVCT_EL0 for VHE Date: Wed, 29 Jan 2020 15:55:38 -0800 Message-Id: <20200129235614.29829-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200129235614.29829-1-richard.henderson@linaro.org> References: <20200129235614.29829-1-richard.henderson@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::443 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) The virtual offset may be 0 depending on EL, E2H and TGE. Reviewed-by: Alex Benn=C3=A9e Signed-off-by: Richard Henderson --- target/arm/helper.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 8b8d2213cf..830f83ae55 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -2515,9 +2515,31 @@ static uint64_t gt_cnt_read(CPUARMState *env, const = ARMCPRegInfo *ri) return gt_get_countervalue(env); } =20 +static uint64_t gt_virt_cnt_offset(CPUARMState *env) +{ + uint64_t hcr; + + switch (arm_current_el(env)) { + case 2: + hcr =3D arm_hcr_el2_eff(env); + if (hcr & HCR_E2H) { + return 0; + } + break; + case 0: + hcr =3D arm_hcr_el2_eff(env); + if ((hcr & (HCR_E2H | HCR_TGE)) =3D=3D (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); } =20 static void gt_cval_write(CPUARMState *env, const ARMCPRegInfo *ri, @@ -2532,7 +2554,13 @@ static void gt_cval_write(CPUARMState *env, const AR= MCPRegInfo *ri, static uint64_t gt_tval_read(CPUARMState *env, const ARMCPRegInfo *ri, int timeridx) { - uint64_t offset =3D timeridx =3D=3D GTIMER_VIRT ? env->cp15.cntvoff_el= 2 : 0; + uint64_t offset =3D 0; + + switch (timeridx) { + case GTIMER_VIRT: + offset =3D gt_virt_cnt_offset(env); + break; + } =20 return (uint32_t)(env->cp15.c14_timer[timeridx].cval - (gt_get_countervalue(env) - offset)); @@ -2542,7 +2570,13 @@ static void gt_tval_write(CPUARMState *env, const AR= MCPRegInfo *ri, int timeridx, uint64_t value) { - uint64_t offset =3D timeridx =3D=3D GTIMER_VIRT ? env->cp15.cntvoff_el= 2 : 0; + uint64_t offset =3D 0; + + switch (timeridx) { + case GTIMER_VIRT: + offset =3D gt_virt_cnt_offset(env); + break; + } =20 trace_arm_gt_tval_write(timeridx, value); env->cp15.c14_timer[timeridx].cval =3D gt_get_countervalue(env) - offs= et + --=20 2.20.1