From patchwork Tue Feb 8 11:39:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540781 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp495206imo; Tue, 8 Feb 2022 05:36:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJxl3mNynHtf5uNoeK9eTx5SmPeih8RHjNUpqC3ioIteFBgVEitVzdntcH735BaAnfdbeOVW X-Received: by 2002:a25:3401:: with SMTP id b1mr3487452yba.713.1644327393665; Tue, 08 Feb 2022 05:36:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644327393; cv=none; d=google.com; s=arc-20160816; b=lclcqCXZ2z1BBhT9b6YaljPaTRI6RRnLzptpYYW7c5Rbuni7/nnrNIcLFuMGHV0546 dNrKCZqnwpzZjS9kfrJH79sc1OYov/djHscFU10QPWw6e3sJczdlR8ZwymNjOjRmbdyl ccBh7A2WBRc8A3Xgm31giA0OFqHzGnaKyRYud4+0qf1TWNOkdlW7OrdQZdDcYHkqAGJ6 Lhbuk2ZVeAuSF1bdUiKsMQ1XseAPZhO+ujXGbsnCAC5bd6HGPCh+w+vJeTVFr/Lq6ruK WwG1+zwv+UkLQ5fIyNvIcxqpjrW+FlIMNxZmNRrr69oX/FdGa0xTTYRGLY6vMjmZaSG0 WWCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=/mqhqQhQLs9hWhzKkqqLGUYC8DmGhSXzHDhfqr5RRB8=; b=wrYGiHmYZdWDxGdOSwx+3JsyKTcEdDuPuj73xRddsHMTthC6nYZ5pPHVWSHTsMk2WA O0txRHFidmroij+P0HObYFptMAlkm/e6q+mA9iBOFrhpHBDki1wfENFu/tr7/YhyjQjJ FQ/pw/9PApM5FQ8jJkQyu7XlSouzqSu2VqQSX4tDGT0SD32U9JH123Z+djifC+QAFcdQ r+mJldIGzuNYJ64zKms11/jVTXY6jE9jXXU2h7JFCrzXFqzTFPPq+llwX7BYP8uAHvHN Y0VrpU2/Zio72kX5foibN2Mpxf0L8p1HcYCqmFXBvF4weT43x5RRBScgG8EGBndFhkEb 3JhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a0vPkIme; 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=pass (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 f66si9379265ybc.513.2022.02.08.05.36.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:36:33 -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=pass header.i=@linaro.org header.s=google header.b=a0vPkIme; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQfZ-0006Cv-6H for patch@linaro.org; Tue, 08 Feb 2022 08:36:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34600) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqm-0000ia-RL for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:02 -0500 Received: from [2a00:1450:4864:20::42f] (port=36465 helo=mail-wr1-x42f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqh-00023U-17 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:39:58 -0500 Received: by mail-wr1-x42f.google.com with SMTP id i15so7777448wrb.3 for ; Tue, 08 Feb 2022 03:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=/mqhqQhQLs9hWhzKkqqLGUYC8DmGhSXzHDhfqr5RRB8=; b=a0vPkImern1yWjt4RQVIzKl39vWu1Hdyhh3lWxzgISMhTak2vJOOqN2ODQtZBpFKMs weW96TugfROeSPZUW53/DT/a602upcR90OYow8WQQ8ft6KhuDCwm1XxgL6oAAmt9z7uE 2cCiVdaxmVOOxMky7ov9BV1HOP0vYp9Qg1OeHL8IZvcS172Xa6MkN5SmkDEP1LZKdUYZ 2Vfxy+HzEMT8m9Rj6emwBglbr29cM9MVCa1II822sQBWSj8G92f1QtY0lDN3tM+MAhDd 9Rs4V2XAGOYGVByW8IHr9xE4WRCdK0ku4utup+OY2LQFg3yvfHCX38L+Wwi+yvF0mR3e 0tMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/mqhqQhQLs9hWhzKkqqLGUYC8DmGhSXzHDhfqr5RRB8=; b=mXDEvDb9ERmeAKG0jcy0A9GootHlxYhqqq0QU/mKwFsccU/btxwton3VUqZWTyJ57/ bBDEmJB08xyOZT0wnPGKKKhAIOPSIGiQXIjC8JgAJLaBuS1E6ew/a4UBA3zxOHhS/BFo vVyW328LdQmvP2cDlW8E0oK6gHXDTY/JAxj+PeqUNQz8oPfxrmI62X/hbTP2nC49iRZ+ flVIUauEr2qT6D++X5dSSGpeb9/ntquKCjKzXIYEIWPVUdjK1cUNR10eMQpNavyvv3nv rpQWGCAfZLCy6HnNXuRSXWt9nL+l58o1V+7gdJcMs2c2Kinh+CyJiGwMnT0fzja8jnDp gNNw== X-Gm-Message-State: AOAM530oam9QPypY1RKOAcdgsuddF2KcdkhkK9PYNrqXwrFH00DPodk5 CvEUHpIaIpSYMLABADQVI9/N0r9R9T9/eQ== X-Received: by 2002:adf:d849:: with SMTP id k9mr3156209wrl.366.1644320391242; Tue, 08 Feb 2022 03:39:51 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:50 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 01/39] target/arm: Fix sve_zcr_len_for_el for VHE mode running Date: Tue, 8 Feb 2022 11:39:10 +0000 Message-Id: <20220208113948.3217356-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42f (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Richard Henderson When HCR_EL2.{E2H,TGE} == '11', ZCR_EL1 is unused. Reported-by: Zenghui Yu Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Reviewed-by: Zenghui Yu Message-id: 20220127063428.30212-2-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/helper.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 6dd241fbef3..649958a727d 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6225,7 +6225,8 @@ uint32_t sve_zcr_len_for_el(CPUARMState *env, int el) ARMCPU *cpu = env_archcpu(env); uint32_t zcr_len = cpu->sve_max_vq - 1; - if (el <= 1) { + if (el <= 1 && + (arm_hcr_el2_eff(env) & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE)) { zcr_len = MIN(zcr_len, 0xf & (uint32_t)env->vfp.zcr_el[1]); } if (el <= 2 && arm_feature(env, ARM_FEATURE_EL2)) { From patchwork Tue Feb 8 11:39:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540760 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp443611imo; Tue, 8 Feb 2022 04:21:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJx7IhVx8Gsk66DVG0swlKsAoeDmj+vSLAohbbOFzTmslTnOw3QQBYWaZgngVa8XM54St6x0 X-Received: by 2002:a81:1d86:: with SMTP id d128mr4459888ywd.76.1644322877307; Tue, 08 Feb 2022 04:21:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644322877; cv=none; d=google.com; s=arc-20160816; b=XhOys/Jq6gntVEnqNhH4SR1YWt29CUMKfE24oY8g73YnO5LUbqb9iz8gROjgKTiIbc ka3ZQhq3teEZfH0sjzFBCU+73k8J/N6I8D2S/ljT9dxCpZG7bjBPhe56s7oCz+7Uo79X wsr0+A90CByFcUlzCd4bDnbJpSwLKzlkA6Gt4yssyiwVWsboufm//0GATh/DUpUuLyOu D9FsqEuQNs0h5+SXSNPc79m4tfnQrH+NCOzOEruWgYUeTYtoFjFZkmdv58+HhbO6lZvc BDhh48eKgN+llGjKEO5PrELNqSD32FurmKLTFCD7xWFiL0A46QHbdBcKBPaPxLUqX9IV qFBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=07gBIxwOWE1tZbNF3mc8srn+QlzhsQp+V7aHyDnjcfs=; b=wonoTwOokP9i17/s1xQUm+JMUQ8HG1mE3ZBD2+3NCdAWouYMhsh+wK39WIKK63Kr+5 awlHy4zXUFrlZ91AGK5InEmTYi9tTp64BOdcFwZCGr1/WfUE3zerC/srVjf4L8Dun1wB kbHhhU5XSGiRXH4vCTiF9FfhSzYorcRwCtzWIMB15rcN3mbAi7kdA2BK449HM+OzKGZt QCJ3acb5DffH+8q3e2YnnHu9+rZe0sv0R5qdOCnEmzCVW64/w0SJ8jFBeXSGxP4EW7Ls 1KHAmRXjnOBAY7yBfD0+rx8idM6lXbFuEHu0aoVbh2wB6BWC2Vjbh/WoK9eF77IysmOf Dv4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vRdsyj3B; 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=pass (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 188si5273063ybb.170.2022.02.08.04.21.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:21:17 -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=pass header.i=@linaro.org header.s=google header.b=vRdsyj3B; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPUi-00052J-Nv for patch@linaro.org; Tue, 08 Feb 2022 07:21:16 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqm-0000id-RK for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:02 -0500 Received: from [2a00:1450:4864:20::331] (port=42537 helo=mail-wm1-x331.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqi-00023a-4s for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:39:59 -0500 Received: by mail-wm1-x331.google.com with SMTP id k3-20020a1ca103000000b0037bdea84f9cso1403968wme.1 for ; Tue, 08 Feb 2022 03:39:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=07gBIxwOWE1tZbNF3mc8srn+QlzhsQp+V7aHyDnjcfs=; b=vRdsyj3BbBUTuoEvqcUNU9brIM4cweGwjG44IDZPYFKzbLxv4PguQ7o854FTDDyfq2 /dT52o8Pr/yHuDLzGvuRdV36CgBnM/mCj9iBhWGoF/C8VSVLSuo0sfqWPigz70/UuKeR b/1okm2CgoxarRKVpwwDeDa9Juu2KCgj0R6Buu182/P6043kq3UABO4MOwAw79qbfvHC teUvQngZ5UPkvyw7FANcsCR86x//ZeDdenVX0mazvt91dPUYihD87M4r/lAqU7BGaClS /8zkzCuGSOSoAkzpYLLixublQQTi+zQe6CqV/1OTDFdZFYmdqWGcxZTSU0rtdU2+3S6y /slQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=07gBIxwOWE1tZbNF3mc8srn+QlzhsQp+V7aHyDnjcfs=; b=e6iNVviAMX6gLRkvgufPZamd8xB/H64jiXWHkFX1zqIAQJSNUXxCYWtw2hIVtMCk5t tzqP/mNRSu55teFPL+2g73FN1RQS1Ie0d0I2u7Rn8QLkDxqNW06JcPfi5Q2Cu10LTqkQ O52eeAod6MAvrkYAw5v7hOVSZ2phSt9BC0e7XDHfF6Mz8rX7PJ2LNHP1/TNrJoQJaJZQ YyvBJooyCl6gpNSIZNMg6VEswaw37GT6ABfA7uDeGBSeN9hk1JoaX2Ohqwr/X84cnxUv DK5kPAaSMXrDIc5u2HgvP5/BnYJ46Yi6IbKBvQurJI00MCyO6oslvalZzA20zAUyg4uE b0Fw== X-Gm-Message-State: AOAM53377RZ4386hqiE6M1idjPwkfqgeJb9qM6JS7j5U16Xho7O21j1+ gM+kNnoQ7aaZrHegiSiGIREhNRmU5B2y3A== X-Received: by 2002:a1c:a552:: with SMTP id o79mr794000wme.40.1644320391919; Tue, 08 Feb 2022 03:39:51 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:51 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 02/39] target/arm: Tidy sve_exception_el for CPACR_EL1 access Date: Tue, 8 Feb 2022 11:39:11 +0000 Message-Id: <20220208113948.3217356-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::331 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Richard Henderson Extract entire fields for ZEN and FPEN, rather than testing specific bits. This makes it easier to follow the code versus the ARM spec. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Reviewed-by: Zenghui Yu Message-id: 20220127063428.30212-3-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/helper.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 649958a727d..e474ab2e1de 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6154,30 +6154,28 @@ int sve_exception_el(CPUARMState *env, int el) uint64_t hcr_el2 = arm_hcr_el2_eff(env); if (el <= 1 && (hcr_el2 & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE)) { - bool disabled = false; - - /* The CPACR.ZEN controls traps to EL1: - * 0, 2 : trap EL0 and EL1 accesses - * 1 : trap only EL0 accesses - * 3 : trap no accesses - */ - if (!extract32(env->cp15.cpacr_el1, 16, 1)) { - disabled = true; - } else if (!extract32(env->cp15.cpacr_el1, 17, 1)) { - disabled = el == 0; - } - if (disabled) { + /* Check CPACR.ZEN. */ + switch (extract32(env->cp15.cpacr_el1, 16, 2)) { + case 1: + if (el != 0) { + break; + } + /* fall through */ + case 0: + case 2: /* route_to_el2 */ return hcr_el2 & HCR_TGE ? 2 : 1; } /* Check CPACR.FPEN. */ - if (!extract32(env->cp15.cpacr_el1, 20, 1)) { - disabled = true; - } else if (!extract32(env->cp15.cpacr_el1, 21, 1)) { - disabled = el == 0; - } - if (disabled) { + switch (extract32(env->cp15.cpacr_el1, 20, 2)) { + case 1: + if (el != 0) { + break; + } + /* fall through */ + case 0: + case 2: return 0; } } From patchwork Tue Feb 8 11:39:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540768 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp454135imo; Tue, 8 Feb 2022 04:37:36 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4DkFSgvuqLr22N5rpHX+w7logDkKkz1ZmcQoyIJDh9C0HeZX0CmtF1viSNTh3D1YpSQu+ X-Received: by 2002:a05:6902:2c2:: with SMTP id w2mr4343141ybh.467.1644323856538; Tue, 08 Feb 2022 04:37:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644323856; cv=none; d=google.com; s=arc-20160816; b=ZaCKGdVhu8Yvo3psQGSdW1O3HmgDvAFrAS2nEtYjzFzNrx0T40e5luibS7U+CSkdwA 3Aw3dhV8srikCXxtJ0u18XYBLf24vryX5xlHAUIHbyKTdG//XHicaHxLy2utGeVbhmxx 5BKgwN4KekfgKlJVhFzyuUbS+pHjv9Th1sLBe0IQSm7BeGPUlb9Ys+Lhx2YF/wrgXKDN Od7SkLUTTJGAc3IjVZGXxZ5WS291v160rto1by1skObU4PTniZ9o/k4JST/E7rmy2rhT f0/3qjI7XjzKSxDfV03dF5VJorgXHzQW1FqXznl5fIGL78PB/0mSZXMndy2gmv2b33Hk 9lmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=WhWGZQdZPDMluOYmzcS+hSOKutm5iVyF+6AU+8IWoss=; b=aC6D4fO3YWgKw8dfrbj/Y4eDeU9T027I05+IUaccFlEeronXV6V1tAamrWGU5ZlM1a zrf7vauTyPuBKiJqokGcUMXvy0FFcdFlx2IZNbXJMEbigxQyPXeFsJPJtqvIklzZAJvZ WeTV9pzC2P69qJSg33lq4VeERdqRHcZlnYaCG6hsY5tWPPPdEbA7p+SEe+eBL+1hOZem E6LQUAKyQct73deJPE0b/sxQlu3qMQH5KC5SoxEYmHgCVacawIUQhNkVgzD6uOJZzxr4 T0E9xISTU3h15dOPLb1qR/LBddisY7K+oLLNwwVcglZk6g7u7BF9rt9G0Z2HlhAeXwX4 5itQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jkH0Se3c; 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=pass (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 bh7si15523498ywb.117.2022.02.08.04.37.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:37:36 -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=pass header.i=@linaro.org header.s=google header.b=jkH0Se3c; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPkV-0005Ib-N6 for patch@linaro.org; Tue, 08 Feb 2022 07:37:35 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqm-0000ic-RF for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:02 -0500 Received: from [2a00:1450:4864:20::42c] (port=45946 helo=mail-wr1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqi-00023d-5z for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:39:59 -0500 Received: by mail-wr1-x42c.google.com with SMTP id m14so30119872wrg.12 for ; Tue, 08 Feb 2022 03:39:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=WhWGZQdZPDMluOYmzcS+hSOKutm5iVyF+6AU+8IWoss=; b=jkH0Se3ci6nwLKmWnVntHkoyDnz82ywTrnyMBngT0jXHSXFdOjwScg2Ze7kA29jkfS roA0cD2kmNDim4qzLvbnT7QDmwWUYmZ6lsbdAm5a2UcOg1kMtOTbx6wRhjUx8ei9X9ds xUBvWxpFgP4WxOzwv3EXiU7RFSHS6mqyu6P+w+HoPjc3FtJIXdOkXb693Q75d9DGYcZC xnzxarxjIeSgtwZERBraAph8xSbm9h+tEnOWeM75EnQeEOQEpTl6U992w0vw6SqSNFcN v0CxAjnM3wXrUouiGSXKEUYnOUz/y007xY7DTir5ZTy6wRC5+ek3lKNDW7tv8/8gJvSG 5JlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WhWGZQdZPDMluOYmzcS+hSOKutm5iVyF+6AU+8IWoss=; b=xFnS6inQhPJy4f5bBFjdpPkJwCYKqkdaLxtiMzHTkG2N9w/LHhdEcHcB8wSSHeCJnh D+H+6WS2ByBqV+K0hypCMYyRyn86/gIcNLC2sv2JeNtf/mAiEK/agFH7ArvYKGAdivP2 or4Jxr75yCs4VZXWy/INkVGvTlAeMZDc1U/oco9/1EcQUmgcX7QuOrCc5LJ0pPVtzQS7 LFzyqD/pIoCYfF/cOK1pDsDEUSuEox9jRWVv8qz4ad4JVNzO00ErrACuRqAbM8J2Havl D+r8S5SC/5CqHz4gHYyGQDc0Wt1lvHaxRLDIDh61Z/FVDSgMfr90ADn85KXbGoYz3tAX f1hw== X-Gm-Message-State: AOAM53045RPCaj5MLJ+/4EpSr20cZ1/YTyaeGBV25YS7VwksOsii54sw tDPZvWNf8uc8zPHH2rFzJYxILkYvHCuoAQ== X-Received: by 2002:a5d:59af:: with SMTP id p15mr3310067wrr.488.1644320392558; Tue, 08 Feb 2022 03:39:52 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:52 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 03/39] target/arm: Fix {fp, sve}_exception_el for VHE mode running Date: Tue, 8 Feb 2022 11:39:12 +0000 Message-Id: <20220208113948.3217356-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42c (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Richard Henderson When HCR_EL2.E2H is set, the format of CPTR_EL2 changes to look more like CPACR_EL1, with ZEN and FPEN fields instead of TZ and TFP fields. Reported-by: Zenghui Yu Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Message-id: 20220127063428.30212-4-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/helper.c | 77 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index e474ab2e1de..83bbb446e70 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -6180,15 +6180,41 @@ int sve_exception_el(CPUARMState *env, int el) } } - /* CPTR_EL2. Since TZ and TFP are positive, - * they will be zero when EL2 is not present. + /* + * CPTR_EL2 changes format with HCR_EL2.E2H (regardless of TGE). */ - if (el <= 2 && arm_is_el2_enabled(env)) { - if (env->cp15.cptr_el[2] & CPTR_TZ) { - return 2; - } - if (env->cp15.cptr_el[2] & CPTR_TFP) { - return 0; + if (el <= 2) { + if (hcr_el2 & HCR_E2H) { + /* Check CPTR_EL2.ZEN. */ + switch (extract32(env->cp15.cptr_el[2], 16, 2)) { + case 1: + if (el != 0 || !(hcr_el2 & HCR_TGE)) { + break; + } + /* fall through */ + case 0: + case 2: + return 2; + } + + /* Check CPTR_EL2.FPEN. */ + switch (extract32(env->cp15.cptr_el[2], 20, 2)) { + case 1: + if (el == 2 || !(hcr_el2 & HCR_TGE)) { + break; + } + /* fall through */ + case 0: + case 2: + return 0; + } + } else if (arm_is_el2_enabled(env)) { + if (env->cp15.cptr_el[2] & CPTR_TZ) { + return 2; + } + if (env->cp15.cptr_el[2] & CPTR_TFP) { + return 0; + } } } @@ -12912,6 +12938,8 @@ uint32_t HELPER(crc32c)(uint32_t acc, uint32_t val, uint32_t bytes) int fp_exception_el(CPUARMState *env, int cur_el) { #ifndef CONFIG_USER_ONLY + uint64_t hcr_el2; + /* CPACR and the CPTR registers don't exist before v6, so FP is * always accessible */ @@ -12935,13 +12963,15 @@ int fp_exception_el(CPUARMState *env, int cur_el) return 0; } + hcr_el2 = arm_hcr_el2_eff(env); + /* The CPACR controls traps to EL1, or PL1 if we're 32 bit: * 0, 2 : trap EL0 and EL1/PL1 accesses * 1 : trap only EL0 accesses * 3 : trap no accesses * This register is ignored if E2H+TGE are both set. */ - if ((arm_hcr_el2_eff(env) & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE)) { + if ((hcr_el2 & (HCR_E2H | HCR_TGE)) != (HCR_E2H | HCR_TGE)) { int fpen = extract32(env->cp15.cpacr_el1, 20, 2); switch (fpen) { @@ -12982,15 +13012,28 @@ int fp_exception_el(CPUARMState *env, int cur_el) } } - /* For the CPTR registers we don't need to guard with an ARM_FEATURE - * check because zero bits in the registers mean "don't trap". + /* + * CPTR_EL2 is present in v7VE or v8, and changes format + * with HCR_EL2.E2H (regardless of TGE). */ - - /* CPTR_EL2 : present in v7VE or v8 */ - if (cur_el <= 2 && extract32(env->cp15.cptr_el[2], 10, 1) - && arm_is_el2_enabled(env)) { - /* Trap FP ops at EL2, NS-EL1 or NS-EL0 to EL2 */ - return 2; + if (cur_el <= 2) { + if (hcr_el2 & HCR_E2H) { + /* Check CPTR_EL2.FPEN. */ + switch (extract32(env->cp15.cptr_el[2], 20, 2)) { + case 1: + if (cur_el != 0 || !(hcr_el2 & HCR_TGE)) { + break; + } + /* fall through */ + case 0: + case 2: + return 2; + } + } else if (arm_is_el2_enabled(env)) { + if (env->cp15.cptr_el[2] & CPTR_TFP) { + return 2; + } + } } /* CPTR_EL3 : present in v8 */ From patchwork Tue Feb 8 11:39:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540785 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp506523imo; Tue, 8 Feb 2022 05:55:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJwHA0QhcU4OtE1Uo/hyw1Mdgj8QBoehRmFV8Bfm++t4gCd6xhohQxMuY3p9Y4kYoD6kgoAo X-Received: by 2002:a81:cf0b:: with SMTP id u11mr4941354ywi.182.1644328507018; Tue, 08 Feb 2022 05:55:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644328507; cv=none; d=google.com; s=arc-20160816; b=Q6e/npg5JfLI9SbBU6+Ik1xAjNoOdtDQj4wiZJHi9mOpm8bX27FMky/4B5Mj+WMRlq OEEjN1FJbPWy6gdryVCaBsGSmWllNR6FXNGOwjtybUUNb0u7LEQNu84YqM2XmM9uwx0u F6jiin4W1i7G4Jr/z5N/+7omEAfTyecrQmdyE7TMLJz2fPY2bX1+P1bIf9XnhHDJI8ty J/2sFMqL/hIPjGAcpFNx9YbTvLHyoAzHgOGcW+/k1O0vRpSYtDimjvWryuYHkGg+fyeu M7ZmxqNfYZ4O3nwDdcM0jZMf+Euwlc72aCwfIbLr2fMcsXoR/wqjalEGxTMktOfmiKSy 2j5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=MLlizRXZn+AMzN5F3UlrBZo/pdTn0HGKf6NjWxwcDQI=; b=xD4wwVYJZu3Wvs2p//0JSOgjmmsNTWSmPxlgHYhyHCUk/JdGuuCCnykBecVw6fM2Kp NkKo9xLZouVIVZeFjVesVtHqSRU5srJE18YHIcdu3yPALU6+rARaaCOoyqjraCzNLJFi uUDE+AErFwwuerYFWONcYhDgWrAa45R7ZMMCeTJo5vE8Ywl0y2MaerQDjRPvlcePH2t5 R+UgV/OzOFNjKbx/Kd4UUSDIU6gEwcUU3na2ecQNidmeO3Qj5f7blrHqtz5sY6gVKBb/ 55J9HuB1+pyplhC9O6wxfVnH9kW4o8fsibqoWjbhvvIwI1WPPiFWTnXhqokF6D6wgc/d czcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="jhbzK6v/"; 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=pass (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 y3si588547ybk.634.2022.02.08.05.55.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:55:07 -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=pass header.i=@linaro.org header.s=google header.b="jhbzK6v/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQxW-0003Rz-GU for patch@linaro.org; Tue, 08 Feb 2022 08:55:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34762) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqt-0000lB-Qs for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:08 -0500 Received: from [2a00:1450:4864:20::32b] (port=35358 helo=mail-wm1-x32b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqi-00023h-68 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:03 -0500 Received: by mail-wm1-x32b.google.com with SMTP id l123-20020a1c2581000000b0037b9d960079so1168429wml.0 for ; Tue, 08 Feb 2022 03:39:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=MLlizRXZn+AMzN5F3UlrBZo/pdTn0HGKf6NjWxwcDQI=; b=jhbzK6v/Lt4fpgFmTTr0Z6bbjv4z8NyTRdqofCZWYGKnGimIjNOMzNw3XLcjkgKthz vBI+SR8LRPx2CbH49WXnmNcuUWFjPpUU0Hy04yh5TwMLcihw7pZyQrMV74DwGsE660LI QoR0kKODhDWebG8lcmCALXs/S6FIFDQ9nj7xlvkMAFGeZCPp8047A7L2IdK+43chPLit zTVKg9Qkgxo2G8HawaWic2Txto3+efcbav/OhhAeofXmmhEkVvlYnjNFAVE7gybhqDDv AksthJ1m8mFucivIASIbCXe+NBr2h2eaIu7RN9wAuaU7eyGXHNWiG1CauBzVtjLPetCP lwRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MLlizRXZn+AMzN5F3UlrBZo/pdTn0HGKf6NjWxwcDQI=; b=cf30LHPu0cBbkLnbJLZh8GIBgRf4w1376d7XDpQAv+yXmCRb1YjczFIGjmjWAe7LtT USPoCn72a6rA5spGyIKoTRAmg2vwVNMomGYQFioDmbNzCQYnvlyaHazmc020cFFXneQJ pddym0FLXOHwz5m3mdRTT50vLngKAZISfKvHkPrm4VD+C5EF1f7w566p+xwK3SHXYjaG 0svPFdCi0IBCnOFL7XjJsBxLDLuyoFqZdsbP8rWR26DAD4OiiCA0D7bRKsIXJ/4PPmFU 0coqQFOVDHrO9MpUYxQ/R+ikUoBnSw98QWqi8WzrKq8e2FWaw2j+WZEefpIr2ORVmGOm sQng== X-Gm-Message-State: AOAM530cc6SMq+s3ZRgVTy0etQDKkKca3ieIu309n+sLUzkmWQriJVnD nugVMC2FAgG8RHwBZspDcUCU4+566sLZqw== X-Received: by 2002:a05:600c:1c23:: with SMTP id j35mr784317wms.138.1644320393071; Tue, 08 Feb 2022 03:39:53 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:52 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 04/39] target/arm: Use CPTR_TFP with CPTR_EL3 in fp_exception_el Date: Tue, 8 Feb 2022 11:39:13 +0000 Message-Id: <20220208113948.3217356-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32b (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Richard Henderson Use the named bit rather than a bare extract32. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell Reviewed-by: Zenghui Yu Message-id: 20220127063428.30212-5-richard.henderson@linaro.org Signed-off-by: Peter Maydell --- target/arm/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index 83bbb446e70..b5f80988c90 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -13037,7 +13037,7 @@ int fp_exception_el(CPUARMState *env, int cur_el) } /* CPTR_EL3 : present in v8 */ - if (extract32(env->cp15.cptr_el[3], 10, 1)) { + if (env->cp15.cptr_el[3] & CPTR_TFP) { /* Trap all FP ops to EL3 */ return 3; } From patchwork Tue Feb 8 11:39:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540758 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp441548imo; Tue, 8 Feb 2022 04:18:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJpi0Yq7aSlWZ0hJNP5IuC26vT+SqBNpP3FWaBRTZjsRAL9PTGJoXZjYPbuTz3nPRE9fKV X-Received: by 2002:a81:7603:: with SMTP id r3mr4471265ywc.176.1644322682445; Tue, 08 Feb 2022 04:18:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644322682; cv=none; d=google.com; s=arc-20160816; b=qzNRrGwMhMH48gjHrc1+7lSayx1L9d3sxJgEWTdZgUihGKxxZwrQtlTTlJ+6vHm5+T ZCS8ISNIXn1tjGhghChu5ibngx/x2Hzoa/TtAdz7TjnlbVVv9hXvcUriF+xjRNCPVUNq /atNL83ptl7AjHWySvHDSH42Q1YPQEx10MMIQzMjIwxMchLqmelKdxhdMwRhAgk68fS+ GCm2T6DzHTiVXrxYWu9386DFiJvTec3zwMZWbEOnLwFKQWbmbHVfjeFArHuwHG1i+CbZ SRxXQPTz70yzaCjcbRlRDfQnl3/GO0fCHdTcIDn4oIPJG8NBPB98TCLa4WLALJMA3IxC wCLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=8DE+kSBE9JeorBInTufvqzj6URnlu+Op8R/h5V0Mkw4=; b=ZWzysIw5eD04Y0PJSl7b1s+Fj+E3GZE+0Ob9HEUZE6aCyIEXjSMkCP6QcGJ4YKKZdJ dPwCul94Y76cDBjw8fXCB+fqH8fyAAiNEf09xSqVKCAMJL6ZyGLbW3Q8PbHRDRM0YRuY ZvJipdyJO2+/LbPr2+Q9AXUREkYG66XmU0Z1V6xPbdw3q/wK7hDnTxvSDJY136KDULpQ gurqgvMi8OGHQO0w9XOiSTEmXPbVc1Bgd+iwo/HrXcnRBN8ykO4lkPVwjtp9ZfpOXRnn 7KX+SblxIhpQXP6MDmYGRW9ui9M2lwLs47Im+YXZn7gxVnH7tbh46wgsc0E4fyuNUCjY vLMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tGTESSnt; 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=pass (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 j1si9348208ywe.262.2022.02.08.04.18.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:18:02 -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=pass header.i=@linaro.org header.s=google header.b=tGTESSnt; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34870 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPRZ-0006WW-Aj for patch@linaro.org; Tue, 08 Feb 2022 07:18:01 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOql-0000iE-2i for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:00 -0500 Received: from [2a00:1450:4864:20::335] (port=53047 helo=mail-wm1-x335.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqi-00023l-4P for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:39:57 -0500 Received: by mail-wm1-x335.google.com with SMTP id v129so8397707wme.2 for ; Tue, 08 Feb 2022 03:39:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=8DE+kSBE9JeorBInTufvqzj6URnlu+Op8R/h5V0Mkw4=; b=tGTESSntjeaiD+lm8vrkdssGA2zXmTVQJyYBWA26RWH/Qzquvej+Vm2igAejduSUKX s154fiukX2POawrSzxYc+QBRyL/snB/+QSqd6D9Cx+PW4OQ63BqyXFRaFzlsiBgk36Z6 JQqJGZ0TAmX96pC/crHwnpZBZtJFNTf4bwCWW4eCibFCuUyWM/LF0LlFyjGAHomXmxSA SEVvSK8UsEMh+Zh8y+ZAdF+x28UQ5PikngNn/8qZBdK0YYwMR2PX67xZcZIFhzKkbKWG d03nUYIAXYBwmCP1kvINlnnuYCgpD0y2TZyIEr6vr2RlTInVcw+sPdCgjBO/K8bkYI2L pSSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8DE+kSBE9JeorBInTufvqzj6URnlu+Op8R/h5V0Mkw4=; b=fo/hAw+RfsQrgWwvyjYCBF4LBfAtfJ+eZNiia9/J2WJKNeVp2e4XYDtWVmFQ7Jr7nP aGS9IIHHykTPt4dJUeN7j2GSDR+v89mPlZWFDvTyYOIDon19HT+bVSaC1L+vr6cz7sEO UQx5KfjkMSlGXLKojirh9JKF173aYiPGseaJcWXxkdHvX1MDHWBmB8y48+JEMxLIlT9x BcJwiGUckToca75r6aT3BcGZ+d0AGCbqK7FwkebNhRhHiefcIQv0YF+tKl0vjbcDfGqr Bee+UvQtNi7WB1Wh7rNVsXxviV8pRW/6xcKvAKUaCnAqK5rEtR5DUZI9ooQHxud5l+bF LN1w== X-Gm-Message-State: AOAM533BW5Sy2E4roPFI7/9oaeYGEfpOQlHlyP8DJ/kOOBhZ/7/xW5DU jWtyxdUS6KPlEfEU82Uq59Xu06QX2SZdUQ== X-Received: by 2002:a1c:f210:: with SMTP id s16mr767960wmc.121.1644320393673; Tue, 08 Feb 2022 03:39:53 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:53 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 05/39] hw/arm/xlnx-zynqmp: 'Or' the QSPI / QSPI DMA IRQs Date: Tue, 8 Feb 2022 11:39:14 +0000 Message-Id: <20220208113948.3217356-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::335 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::335; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Francisco Iglesias 'Or' the IRQs coming from the QSPI and QSPI DMA models. This is done for avoiding the situation where one of the models incorrectly deasserts an interrupt asserted from the other model (which will result in that the IRQ is lost and will not reach guest SW). Signed-off-by: Francisco Iglesias Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Luc Michel Message-id: 20220203151742.1457-1-francisco.iglesias@xilinx.com Signed-off-by: Peter Maydell --- include/hw/arm/xlnx-zynqmp.h | 2 ++ hw/arm/xlnx-zynqmp.c | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/hw/arm/xlnx-zynqmp.h b/include/hw/arm/xlnx-zynqmp.h index 062e637fe49..9424f81c377 100644 --- a/include/hw/arm/xlnx-zynqmp.h +++ b/include/hw/arm/xlnx-zynqmp.h @@ -38,6 +38,7 @@ #include "hw/dma/xlnx_csu_dma.h" #include "hw/nvram/xlnx-bbram.h" #include "hw/nvram/xlnx-zynqmp-efuse.h" +#include "hw/or-irq.h" #define TYPE_XLNX_ZYNQMP "xlnx-zynqmp" OBJECT_DECLARE_SIMPLE_TYPE(XlnxZynqMPState, XLNX_ZYNQMP) @@ -122,6 +123,7 @@ struct XlnxZynqMPState { XlnxZDMA gdma[XLNX_ZYNQMP_NUM_GDMA_CH]; XlnxZDMA adma[XLNX_ZYNQMP_NUM_ADMA_CH]; XlnxCSUDMA qspi_dma; + qemu_or_irq qspi_irq_orgate; char *boot_cpu; ARMCPU *boot_cpu_ptr; diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c index 1c52a575aad..5fbf38c4660 100644 --- a/hw/arm/xlnx-zynqmp.c +++ b/hw/arm/xlnx-zynqmp.c @@ -50,6 +50,7 @@ #define LQSPI_ADDR 0xc0000000 #define QSPI_IRQ 15 #define QSPI_DMA_ADDR 0xff0f0800 +#define NUM_QSPI_IRQ_LINES 2 #define DP_ADDR 0xfd4a0000 #define DP_IRQ 113 @@ -362,6 +363,8 @@ static void xlnx_zynqmp_init(Object *obj) } object_initialize_child(obj, "qspi-dma", &s->qspi_dma, TYPE_XLNX_CSU_DMA); + object_initialize_child(obj, "qspi-irq-orgate", + &s->qspi_irq_orgate, TYPE_OR_IRQ); } static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) @@ -709,6 +712,11 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) gic_spi[adma_ch_intr[i]]); } + object_property_set_int(OBJECT(&s->qspi_irq_orgate), + "num-lines", NUM_QSPI_IRQ_LINES, &error_fatal); + qdev_realize(DEVICE(&s->qspi_irq_orgate), NULL, &error_fatal); + qdev_connect_gpio_out(DEVICE(&s->qspi_irq_orgate), 0, gic_spi[QSPI_IRQ]); + if (!object_property_set_link(OBJECT(&s->qspi_dma), "dma", OBJECT(system_memory), errp)) { return; @@ -718,7 +726,8 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) } sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi_dma), 0, QSPI_DMA_ADDR); - sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi_dma), 0, gic_spi[QSPI_IRQ]); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi_dma), 0, + qdev_get_gpio_in(DEVICE(&s->qspi_irq_orgate), 0)); if (!object_property_set_link(OBJECT(&s->qspi), "stream-connected-dma", OBJECT(&s->qspi_dma), errp)) { @@ -729,7 +738,8 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) } sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 0, QSPI_ADDR); sysbus_mmio_map(SYS_BUS_DEVICE(&s->qspi), 1, LQSPI_ADDR); - sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi), 0, gic_spi[QSPI_IRQ]); + sysbus_connect_irq(SYS_BUS_DEVICE(&s->qspi), 0, + qdev_get_gpio_in(DEVICE(&s->qspi_irq_orgate), 1)); for (i = 0; i < XLNX_ZYNQMP_NUM_QSPI_BUS; i++) { g_autofree gchar *bus_name = g_strdup_printf("qspi%d", i); From patchwork Tue Feb 8 11:39:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540759 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp441900imo; Tue, 8 Feb 2022 04:18:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHhuuk+wMlB/Jptle8MTifwk1hP5KykkRGX7f9xVXo5dtwEl44AMs+Tpp1ppEPpWuvtk6m X-Received: by 2002:a25:df14:: with SMTP id w20mr4300998ybg.226.1644322710248; Tue, 08 Feb 2022 04:18:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644322710; cv=none; d=google.com; s=arc-20160816; b=uNrQjfiNlhebLTyQqJCrQG4WRjde2Iji0/yeIlWvpkj360Pm1vq/32uJKh3TJIHHkB 1KOrBni2JOX0MfaRAybucd+tEY2DA65CtpncFHRYK25qWMj9PE5pVfazlTbvD2Al5rnw qItYodWJBHAlMCx71scA1njkEHUCka4IejhdbKQL8rdVUOOuD4u018rqBPFYyZBjUHbI 32sWlSlWM+JjKH+RLh0afmJcu/kTKfHM0+iS1A+tepH0sonjnfpHzvJuGcAJ3cSv2rc1 3EyKqfs7HWjr0KnDTcSEoPihE1HOSSAt6ZoIlnND4mT/96SEmsdvJyBigUkfvhwGNMY3 9MWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=vq/df6xgkKKAE6qKHg9aukmBZl7u0CV6QFgmU7R9Q6U=; b=DzSU8uTVF9cFllWYjBp0zQg9+Et7+IsTXkvRvQTKYlWQDK44lo3/gjUk2vFRlLQAha t33uu89Z8Tz/aSF1ZaRFUzNshe1Yx0kaAsEyd+/qCJXaol9N1UgXjyu0tF8KOp+ymnrA 6IjZbt67QmNQFwIzg2xYSXbusYXt1T2tUVgMsw8hI5cvrkE/pfnkMOTIbZ7nAt1UquxC Q/6Z3Ap++7p/t9Hb681QD2iwSEfJ5GtZfENOcF7rCZPT6NCmwfSeJ9Pl+8eo9ifkMSae gGsm1f9MPkVBurFXgGf1B0dsat3qFeQMl0k6HjgqTIn6F/C2jX6gdqrAgyq1PZuUULUT ++pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cb1+xAdA; 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=pass (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 g3si9849913ywg.74.2022.02.08.04.18.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:18:30 -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=pass header.i=@linaro.org header.s=google header.b=cb1+xAdA; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36934 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPS1-00082y-Nt for patch@linaro.org; Tue, 08 Feb 2022 07:18:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqm-0000iZ-Qj for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:02 -0500 Received: from [2a00:1450:4864:20::332] (port=45982 helo=mail-wm1-x332.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqi-00023p-59 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:39:59 -0500 Received: by mail-wm1-x332.google.com with SMTP id j5-20020a05600c1c0500b0034d2e956aadso1393813wms.4 for ; Tue, 08 Feb 2022 03:39:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=vq/df6xgkKKAE6qKHg9aukmBZl7u0CV6QFgmU7R9Q6U=; b=cb1+xAdAmyaRkS57gasjBDqUic+MQX1mBJcpzMBaTISJB11aK2X5RFG1WP0hEV9AE4 zI8g/byaNpXfStch0TfbQpbLg2yOi1sC9Vc/JvS0EYaLbZKunqnUq/zXeNynCFpJiJJR wDQNEihqIR17tMG03gJFCbzKDxXzcdKW6ttzcxzrv/r8Jph/KfgJJsOzPw4jf7MB4o06 A0YpGZVS2e4Cy9mUJp6LHLwb1NussMpBjsf+1aTyXM1lPrmkw5UD/doYAQ2islB/XuKX IwayqdGChWjfPVbUaeOz5S+tLdJKRAvYMtMQm0I484kUOhQdgYKmyg/72aVkzEtqz32S MttA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vq/df6xgkKKAE6qKHg9aukmBZl7u0CV6QFgmU7R9Q6U=; b=vxPebksiFV3Os/1z3eg2UIXQv9iexOEZZRZi8iWFYqxdVAZjaE5n2Z3w+OmLPoIEaM zeu3KN1ywOItVVtABwA1+P6Q86ObwkInfTtCRu+8X5ylcsTEShd6DrKoBFVpqg3Wh0rl Qg99sI9z8CCxIUjXHRv7yr92JoBLJub1nzELgUJVPFXCQ8LH4acthnDchwps2cecGk+J 7dKlbp1sqrNbV0NIbr7eZbrZaUatsLR8vMFCvehsXwkyPkMvWxTvq5AjShDRMzZwBYB7 rEX5uXRCDx8iLRvWseKIgyAeUMXwz02O8ETIAcKOTsUVqymNLuE7Ieb92t6JHieMlY1Q 1WRQ== X-Gm-Message-State: AOAM531b5nHyzSVg/QRy+RREWjVeobrXhy3xd1TtRjP7t5of3DgTGZ0Q p95sdOCn+RInY42jtXPlF4IkAJjoJhWmnA== X-Received: by 2002:a7b:c7c3:: with SMTP id z3mr786123wmk.68.1644320394224; Tue, 08 Feb 2022 03:39:54 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:53 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 06/39] target/arm: make psci-conduit settable after realize Date: Tue, 8 Feb 2022 11:39:15 +0000 Message-Id: <20220208113948.3217356-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::332 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We want to allow the psci-conduit property to be set after realize, because the parts of the code which are best placed to decide if it's OK to enable QEMU's builtin PSCI emulation (the board code and the arm_load_kernel() function are distant from the code which creates and realizes CPUs (typically inside an SoC object's init and realize method) and run afterwards. Since the DEFINE_PROP_* macros don't have support for creating properties which can be changed after realize, change the property to be created with object_property_add_uint32_ptr(), which is what we already use in this function for creating settable-after-realize properties like init-svtor and init-nsvtor. Note that it doesn't conceptually make sense to change the setting of the property after the machine has been completely initialized, beacuse this would mean that the behaviour of the machine when first started would differ from its behaviour when the system is subsequently reset. (It would also require the underlying state to be migrated, which we don't do.) Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Tested-by: Edgar E. Iglesias Tested-by: Cédric Le Goater Message-id: 20220127154639.2090164-2-peter.maydell@linaro.org --- target/arm/cpu.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index cdbc4cdd012..5a9c02a2561 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1317,6 +1317,11 @@ void arm_cpu_post_init(Object *obj) OBJ_PROP_FLAG_READWRITE); } + /* Not DEFINE_PROP_UINT32: we want this to be settable after realize */ + object_property_add_uint32_ptr(obj, "psci-conduit", + &cpu->psci_conduit, + OBJ_PROP_FLAG_READWRITE); + qdev_property_add_static(DEVICE(obj), &arm_cpu_cfgend_property); if (arm_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER)) { @@ -1987,7 +1992,6 @@ static ObjectClass *arm_cpu_class_by_name(const char *cpu_model) } static Property arm_cpu_properties[] = { - DEFINE_PROP_UINT32("psci-conduit", ARMCPU, psci_conduit, 0), DEFINE_PROP_UINT64("midr", ARMCPU, midr, 0), DEFINE_PROP_UINT64("mp-affinity", ARMCPU, mp_affinity, ARM64_AFFINITY_INVALID), From patchwork Tue Feb 8 11:39:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540771 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp470294imo; Tue, 8 Feb 2022 05:02:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJy+Y4L/NlZa+ozbKJDv0xIRvfVDydls44t80aL3SxAzYhUOWY1HIb1uivNbdQOm7ZUZMUk6 X-Received: by 2002:a25:6a55:: with SMTP id f82mr4162384ybc.1.1644325370711; Tue, 08 Feb 2022 05:02:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644325370; cv=none; d=google.com; s=arc-20160816; b=pR/36/KCd8VqJAsbzVSjtWVF5qRxLV4YxpufQmVxKGcdLZpVTn9XOOTGwkUrDqHEmY Oz2mC/Wwq+OOXpHGrys3sl7eKk/nEU4beZbJakr/K1G3hYFywBkx2EceFzy60KZh4GoF pU9sysoyFzB6vmVQleqeAkkIg/jMlMbyL4UnXJLN3FPJhcGWKHztA8iq6l1/KgsTbj76 BYFSCtoLwA5hY/UMxNWA8Ay7SBAQs6M/PJI8ZpLLPS2vpjPd/HqperhgF911iHuqqk2R j2cnFGOvZHp4tFMlnVUpr1UpFzeZzFsKMnlCf3uex3JCdcDDE4yhXlZbSP6xpt3pF79F i5QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=le1kGG0BoHfz96RIYHeCxoomGYMoeJRnTLdNe+CpqI4=; b=QnvAmBa+R7WaL5A9Zpoyz3Fd4Fu7PzhvzP2zXaHfdg82o4D5xLfmhIK30vq8cFb0MJ eFvy3MfrhSQKsz2eiGmeXeg7QkZcE2zyZr9aErgsyQKkLwPGDaMg46F39snTOl5yfnxn g9oCvgZSE5C+KHGfrQ9mlWhTMj2IqBAsVTSHxSwuIuwOGS43tiLTxSZqzPACdqXQUj6s nvNhVL7mFnbh1NWODA7ltCKa2HxCez7si2qtkAjhp6fb5/pK2Lauw30NH7qFKUvUbbFv OysWaW1bDpF2EsamqPLkzTz/NSggkBKnMkb2LomMu8OHnHcsO71UlxLs0pQ5lNwirzxd plNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ih+uk4lB; 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=pass (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 143si9135124ywx.323.2022.02.08.05.02.50 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:02:50 -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=pass header.i=@linaro.org header.s=google header.b=Ih+uk4lB; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48280 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQ8w-0004aU-2Y for patch@linaro.org; Tue, 08 Feb 2022 08:02:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqm-0000ib-RJ for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:02 -0500 Received: from [2a00:1450:4864:20::336] (port=53048 helo=mail-wm1-x336.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqi-00023t-5q for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:39:59 -0500 Received: by mail-wm1-x336.google.com with SMTP id v129so8397744wme.2 for ; Tue, 08 Feb 2022 03:39:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=le1kGG0BoHfz96RIYHeCxoomGYMoeJRnTLdNe+CpqI4=; b=Ih+uk4lB9A5JfkfRvg4eV8DDhFX1rsc9iThyGNmRfxYVddgfIIcD7o3G6ROf2ynpRR l+MbA7pq83nt7IKUx50FV0RVFt9wNCWkMD4C0qxOtjVj0dUHjhT8UkfmbsmGEIpkzPnO 91vIRYRQHvLyaYmiesfQnBkqsqJ9D5mA2IEpA2PDPC2xDYMyU0bjoJAUTBN7IKp2hQJe VP3Q94d07SMvnXnsivlKIBSv0yJvxm7yDP9yr5UFzeDwEx6YOLrMAd3u7Gmp2t1YA3he V5Z/rJw83SPmrFlOH2YlRt0cyyGExHnkTgMFd7ykon6iQjAEwFHgnoj2k8QWcbX8UV+r LI2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=le1kGG0BoHfz96RIYHeCxoomGYMoeJRnTLdNe+CpqI4=; b=Kfo3cfxsMY2hNUTQlDwptllinycxzUhXy9SrnRUB2oWBXkr9HygTcVe2DI4qEi0Hou RzP7p0huvcDV4wszByZcuwmeUEZimCApNN2Wq6HNn9VfN3PCNm7zq4/j0wE7TLNPKxmc mJFAKuY3tJc7mNClD7iNIJAAJgWDtgq2gncn7KJzqmtclE7mDprkpdGF4e0JN4c8z9ZS UaiQX9WyVhLz5dTdKThliFAQO88hlHOu5ml6XcqN5cVEVvDN+SfeEH5Z1m/KTvyfkg+b 5fkGILxAodpKCGCd35Gs7fTrTLEsA3djZfNqi1H3+nhK2kxVaocCE5aXwqj9LlmNgkrm 2kCw== X-Gm-Message-State: AOAM5332p1/utt7Y5M/FDmFMH7xUOrFud4mSV5k3XpVLCFQaLtK2/cXo Is5X2xt9Hde+t2/n7nN3rD75P7QIAT5KDQ== X-Received: by 2002:a7b:c74c:: with SMTP id w12mr776476wmk.140.1644320394794; Tue, 08 Feb 2022 03:39:54 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:54 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 07/39] cpu.c: Make start-powered-off settable after realize Date: Tue, 8 Feb 2022 11:39:16 +0000 Message-Id: <20220208113948.3217356-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::336 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" The CPU object's start-powered-off property is currently only settable before the CPU object is realized. For arm machines this is awkward, because we would like to decide whether the CPU should be powered-off based on how we are booting the guest code, which is something done in the machine model code and in common code called by the machine model, which runs much later and in completely different parts of the codebase from the SoC object code that is responsible for creating and realizing the CPU objects. Allow start-powered-off to be set after realize. Since this isn't something that's supported by the DEFINE_PROP_* macros, we have to switch the property definition to use the object_class_property_add_bool() function. Note that it doesn't conceptually make sense to change the setting of the property after the machine has been completely initialized, beacuse this would mean that the behaviour of the machine when first started would differ from its behaviour when the system is subsequently reset. (It would also require the underlying state to be migrated, which we don't do.) Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Tested-by: Edgar E. Iglesias Tested-by: Cédric Le Goater Message-id: 20220127154639.2090164-3-peter.maydell@linaro.org --- cpu.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cpu.c b/cpu.c index 016bf06a1ae..3ea38aea707 100644 --- a/cpu.c +++ b/cpu.c @@ -196,13 +196,33 @@ static Property cpu_common_props[] = { DEFINE_PROP_LINK("memory", CPUState, memory, TYPE_MEMORY_REGION, MemoryRegion *), #endif - DEFINE_PROP_BOOL("start-powered-off", CPUState, start_powered_off, false), DEFINE_PROP_END_OF_LIST(), }; +static bool cpu_get_start_powered_off(Object *obj, Error **errp) +{ + CPUState *cpu = CPU(obj); + return cpu->start_powered_off; +} + +static void cpu_set_start_powered_off(Object *obj, bool value, Error **errp) +{ + CPUState *cpu = CPU(obj); + cpu->start_powered_off = value; +} + void cpu_class_init_props(DeviceClass *dc) { + ObjectClass *oc = OBJECT_CLASS(dc); + device_class_set_props(dc, cpu_common_props); + /* + * We can't use DEFINE_PROP_BOOL in the Property array for this + * property, because we want this to be settable after realize. + */ + object_class_property_add_bool(oc, "start-powered-off", + cpu_get_start_powered_off, + cpu_set_start_powered_off); } void cpu_exec_initfn(CPUState *cpu) From patchwork Tue Feb 8 11:39:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540762 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp446896imo; Tue, 8 Feb 2022 04:26:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxcYns4FG4O8Uu61HHbXsIduMT5zN80gaUaLJsXJlGgnVpWjTmwzFcYoRUZPkqOQFzV41wk X-Received: by 2002:a25:f07:: with SMTP id 7mr4308459ybp.470.1644323190457; Tue, 08 Feb 2022 04:26:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644323190; cv=none; d=google.com; s=arc-20160816; b=C+gngu7WS1hrmY1qK981DuzhsSvFLreM8eAx8nVo0NoKQTZObp0g2vdNAyM4g7xgFv k6ZRFloFvuI9CEHEU98TjlyJOjTInltxVB20GNZiF4afH+meDaE3pLvx+eQJDjyYHrTT ZlOd5YwYPSdK7YygzAt+HCxedkUcg7Af4XoVV1Wq5cU3IdxbTtRDW2jeHanYbogLD6fQ RQsoxxSj0qkZPL+3wKMS2uho0hWv9jdYIwSXdT9KafJrxLZmzd6xGLv5AtvptOR1LzmI Mw8/8jkffffwj7Ahwu1w1utG/06jRtxjpnpstuXLqgeJnStelIEPB5vpU9NDC6B1erJb pmDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=2KC0E86q/MPblk/ysJ6HWl+znRCYNySN3t/36zawKEM=; b=NepPAW/qt4D0D0hngzcnIg4lwI23HZezbulIr2yRKBUlGCwCfTbgttQTNWqEmUxY71 p3hb9/bYLlRCxWUVar30c1W1olgVYs0dorFF4oLPaSIgoO4qWXSbipo2gHV7A3ZJKRLn AOz2BZDoUq5pwdI/wn1pYBNZiUUA+4lUy5Owvt54OjXmqvp72fJ5OUEe3vlI1tXk6xLq faFP2N8NyOgDMptq1zHtpyZYUplZGvsiKDtQDNV56+PFqVNGkj+ZUP6JiN5LPNcNLOrT C/iGGdoun2KiB3aL0Qozcxz0E1JF5a/znGYS829+CZ7hEmgnwJ8WScXs9iVUw+747HJt iRnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RuzrLyyF; 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=pass (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 t47si5936867ybi.63.2022.02.08.04.26.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:26:30 -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=pass header.i=@linaro.org header.s=google header.b=RuzrLyyF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPZl-0001UM-S6 for patch@linaro.org; Tue, 08 Feb 2022 07:26:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34634) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqn-0000il-TV for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:02 -0500 Received: from [2a00:1450:4864:20::331] (port=50943 helo=mail-wm1-x331.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqk-000240-NX for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:01 -0500 Received: by mail-wm1-x331.google.com with SMTP id m26so11985260wms.0 for ; Tue, 08 Feb 2022 03:39:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=2KC0E86q/MPblk/ysJ6HWl+znRCYNySN3t/36zawKEM=; b=RuzrLyyFW/DzLc6Oa4M6603z7/Sa4KIa3om7VtIPszcpWjeM5o8TuvACdD2Vz0r62k PeA+45/7fnMIIeWbCRUuChw9nqhMJC1m62FvzdfwGXsw+7KWxVRJXT0S7q5o1R0lLQea tivAqJuarNWF2H9Dk0Q8h31HccPhA7H5VjDgwJFytrc2oGbyKKR4ZhWi+mi9HPxMF8Tw C/tcsMyhESTZmLQOZ20Vxo5+tvd5Uet7aKfs5hX6B1sr9WLQdwgGbVn94jIRTtzoaEV1 NqmxV8I78YI+kLJvjDLSW1CUEPXE5YYO//LEwLaJ20ZSYa+U7Hve163cy9RXeyEoQlsx Tzgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2KC0E86q/MPblk/ysJ6HWl+znRCYNySN3t/36zawKEM=; b=1lzefTA27o96+/PgEyuFsRi23MuPG+jWsgUHVp9wsDj5H4r7FBRjyNfLIeeu2Z6zn5 Higehy/CeyKeLHMa5LFXKkxFFBJGdhVghQ9aeA9cvJXT3ODHqk0/kUhQNqdVYVd6r22u X3NJy2N+zVM6GXAFAg3YRH4hCC7g90Yjmq+CVD3jdlgdVS/TAnlJp/lkV9pg9f50dkMd pHNM0mHJhe76fjupm4KsnnFcRBgiEpdnxaunQlwUykBIBF2VDu+5bX71VioLgmnpWxyO IOzzd9ue/2mVHUbZG3nbbO4bmnjvr9LkFVml7/cy/IR8CR1d9lclndNgkzi9dO4RqvmB y0zA== X-Gm-Message-State: AOAM530qP3hE7hKFu5mt86MRwfrqNPzpdjmA2PVRs5dh0/8DwhdYKn6l ON1qAG1+qly0pDfY9pCZyZc2ZqV62632OA== X-Received: by 2002:a05:600c:a4c:: with SMTP id c12mr773125wmq.48.1644320395431; Tue, 08 Feb 2022 03:39:55 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:55 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 08/39] hw/arm/boot: Support setting psci-conduit based on guest EL Date: Tue, 8 Feb 2022 11:39:17 +0000 Message-Id: <20220208113948.3217356-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::331 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x331.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Currently we expect board code to set the psci-conduit property on CPUs and ensure that secondary CPUs are created with the start-powered-off property set to false, if the board wishes to use QEMU's builtin PSCI emulation. This worked OK for the virt board where we first wanted to use it, because the virt board directly creates its CPUs and is in a reasonable position to set those properties. For other boards which model real hardware and use a separate SoC object, however, it is more awkward. Most PSCI-using boards just set the psci-conduit board unconditionally. This was never strictly speaking correct (because you would not be able to run EL3 guest firmware that itself provided the PSCI interface, as the QEMU implementation would overrule it), but mostly worked in practice because for non-PSCI SMC calls QEMU would emulate the SMC instruction as normal (by trapping to guest EL3). However, we would like to make our PSCI emulation follow the part of the SMCC specification that mandates that SMC calls with unknown function identifiers return a failure code, which means that all SMC calls will be handled by the PSCI code and the "emulate as normal" path will no longer be taken. We tried to implement that in commit 9fcd15b9193e81 ("arm: tcg: Adhere to SMCCC 1.3 section 5.2"), but this regressed attempts to run EL3 guest code on the affected boards: * mcimx6ul-evk, mcimx7d-sabre, orangepi, xlnx-zcu102 * for the case only of EL3 code loaded via -kernel (and not via -bios or -pflash), virt and xlnx-versal-virt so for the 7.0 release we reverted it (in commit 4825eaae4fdd56f). This commit provides a mechanism that boards can use to arrange that psci-conduit is set if running guest code at a low enough EL but not if it would be running at the same EL that the conduit implies that the QEMU PSCI implementation is using. (Later commits will convert individual board models to use this mechanism.) We do this by moving the setting of the psci-conduit and start-powered-off properties to arm_load_kernel(). Boards which want to potentially use emulated PSCI must set a psci_conduit field in the arm_boot_info struct to the type of conduit they want to use (SMC or HVC); arm_load_kernel() will then set the CPUs up accordingly if it is not going to start the guest code at the same or higher EL as the fake QEMU firmware would be at. Board/SoC code which uses this mechanism should no longer set the CPU psci-conduit property directly. It should only set the start-powered-off property for secondaries if EL3 guest firmware running bare metal expects that rather than the alternative "all CPUs start executing the firmware at once". Note that when calculating whether we are going to run guest code at EL3, we ignore the setting of arm_boot_info::secure_board_setup, which might cause us to run a stub bit of guest code at EL3 which does some board-specific setup before dropping to EL2 or EL1 to run the guest kernel. This is OK because only one board that enables PSCI sets secure_board_setup (the highbank board), and the stub code it writes will behave the same way whether the one SMC call it makes is handled by "emulate the SMC" or by "PSCI default returns an error code". So we can leave that stub code in place until after we've changed the PSCI default behaviour; at that point we will remove it. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Tested-by: Edgar E. Iglesias Tested-by: Cédric Le Goater Message-id: 20220127154639.2090164-4-peter.maydell@linaro.org --- include/hw/arm/boot.h | 10 +++++++++ hw/arm/boot.c | 50 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/include/hw/arm/boot.h b/include/hw/arm/boot.h index ce2b48b88bc..0bcb58babba 100644 --- a/include/hw/arm/boot.h +++ b/include/hw/arm/boot.h @@ -86,6 +86,16 @@ struct arm_boot_info { * the user it should implement this hook. */ void (*modify_dtb)(const struct arm_boot_info *info, void *fdt); + /* + * If a board wants to use the QEMU emulated-firmware PSCI support, + * it should set this to QEMU_PSCI_CONDUIT_HVC or QEMU_PSCI_CONDUIT_SMC + * as appropriate. arm_load_kernel() will set the psci-conduit and + * start-powered-off properties on the CPUs accordingly. + * Note that if the guest image is started at the same exception level + * as the conduit specifies calls should go to (eg guest firmware booted + * to EL3) then PSCI will not be enabled. + */ + int psci_conduit; /* Used internally by arm_boot.c */ int is_linux; hwaddr initrd_start; diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 399f8e837ce..327e449f831 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -1299,6 +1299,8 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) { CPUState *cs; AddressSpace *as = arm_boot_address_space(cpu, info); + int boot_el; + CPUARMState *env = &cpu->env; /* * CPU objects (unlike devices) are not automatically reset on system @@ -1329,6 +1331,54 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) arm_setup_direct_kernel_boot(cpu, info); } + /* + * Disable the PSCI conduit if it is set up to target the same + * or a lower EL than the one we're going to start the guest code in. + * This logic needs to agree with the code in do_cpu_reset() which + * decides whether we're going to boot the guest in the highest + * supported exception level or in a lower one. + */ + + /* Boot into highest supported EL ... */ + if (arm_feature(env, ARM_FEATURE_EL3)) { + boot_el = 3; + } else if (arm_feature(env, ARM_FEATURE_EL2)) { + boot_el = 2; + } else { + boot_el = 1; + } + /* ...except that if we're booting Linux we adjust the EL we boot into */ + if (info->is_linux && !info->secure_boot) { + boot_el = arm_feature(env, ARM_FEATURE_EL2) ? 2 : 1; + } + + if ((info->psci_conduit == QEMU_PSCI_CONDUIT_HVC && boot_el >= 2) || + (info->psci_conduit == QEMU_PSCI_CONDUIT_SMC && boot_el == 3)) { + info->psci_conduit = QEMU_PSCI_CONDUIT_DISABLED; + } + + if (info->psci_conduit != QEMU_PSCI_CONDUIT_DISABLED) { + for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) { + Object *cpuobj = OBJECT(cs); + + object_property_set_int(cpuobj, "psci-conduit", info->psci_conduit, + &error_abort); + /* + * Secondary CPUs start in PSCI powered-down state. Like the + * code in do_cpu_reset(), we assume first_cpu is the primary + * CPU. + */ + if (cs != first_cpu) { + object_property_set_bool(cpuobj, "start-powered-off", true, + &error_abort); + } + } + } + + /* + * arm_load_dtb() may add a PSCI node so it must be called after we have + * decided whether to enable PSCI and set the psci-conduit CPU properties. + */ if (!info->skip_dtb_autoload && have_dtb(info)) { if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as, ms) < 0) { exit(1); From patchwork Tue Feb 8 11:39:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540763 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp447708imo; Tue, 8 Feb 2022 04:27:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzw2bVfrImgX+mYUH5MDmr/Z8pJXfHGnNIR36QzrvZDjI+/uPk2HTTdrXY3fpD1JTV35rk+ X-Received: by 2002:a81:3406:: with SMTP id b6mr4629193ywa.387.1644323262514; Tue, 08 Feb 2022 04:27:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644323262; cv=none; d=google.com; s=arc-20160816; b=chCUfsclaSXyK6FqAK6Tb7xbINn/9oAalYwD7YgsWPla/165jc+FtoS2RAdO5TO9UV 7/O5jAnzsJgodo4At2MBwwneZcNyIQxBV0XYvR5a2TtlroE5S3BDQNYBNoZ9Br3p72BF v1rALBk9eypAeYOADb4fwQdCnh/Usoj1eh7/qK4+AU33nTXekccOt2F8DKZu4d5umM/7 NqkLdkaGy42u2uY+aABxmkUHGpcJlG1VlraWBSDYGsKN+XLPufcHiiXc+O0+x9OOgHl5 7Lo6Pyd1g5VWyZD40sDpxHQwA5rOeLGh5FJIlD03rfeIseS9t6QfgRK7Vi6opBshY76f Y01A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=VYqx5i90QNVSg4oDJ8Ire4MWcmLtpzgJo5wY1iMRSRA=; b=Xb1aMYAAC0WydwkM1o5gcNvvQj+gqP+mxnzEYgHoEGFa3VwRjTl8oWo3u82gTY3KRl pBzOUJaOtgzU4AQM7w4gEVIYm+rnz+OLKCElNcdycoX8lWdQH+hDu8TxrTxbDAVYAmkN QQISUAU6OC97W3lELUcDhI9fToyUS/A7e5o/F021itOk7UgLPOrWWviZJ7NLaeaU1vHb Dx0NCrV7Q5kfipgsIIhTUk9voU6keD0lD4Nqh689Vl50OUxYeXQTfj8PY6ECHg9jzqtS oZTcIHuJ3izofiZ3vV5ZiR0yqtL0x5w7nRRx6TRFwjiIP+eTyPTIvs/XqFEopGSAAQ01 JvFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ylIY/srV"; 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=pass (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 w1si11092491ybu.225.2022.02.08.04.27.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:27:42 -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=pass header.i=@linaro.org header.s=google header.b="ylIY/srV"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52094 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPav-0002YL-Vt for patch@linaro.org; Tue, 08 Feb 2022 07:27:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqt-0000lA-Pp for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:08 -0500 Received: from [2a00:1450:4864:20::42f] (port=38565 helo=mail-wr1-x42f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqj-000246-Ap for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:04 -0500 Received: by mail-wr1-x42f.google.com with SMTP id s10so27592158wra.5 for ; Tue, 08 Feb 2022 03:39:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=VYqx5i90QNVSg4oDJ8Ire4MWcmLtpzgJo5wY1iMRSRA=; b=ylIY/srV63tVkAWoowPooIjoAsEan1u8QaA/O/lJW6YSKP8HyFez/lzsk+EC9u9hrV 8Im6Ftf5x9uJTfAJrvXcjhBladPGpT3ZgVOy8ceUROzgLHIxFZPlbs9W9+iPRtE9RLsB cMbUE2ABLTcm81DZMWw1FUE44k+RsTwRqVItE/txy7fYmKVAKVo30sFmEKtMSO3Me9br u1AqNLoElHVlwEAssVIzds5LixTaHwV27upN/U5cuHeZi5VlY3Y+Ci8zxJLcDXwk87Yx YCAKyAx7AdYKNUR0nKLFT6mxe0ntYAAMfZE8Bvs6VkY00AFzePa6hmb4fGCloiczU2DQ ZLTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VYqx5i90QNVSg4oDJ8Ire4MWcmLtpzgJo5wY1iMRSRA=; b=M7xfDywEoFs9AEusBVcEpr79FOXipe8fSoIBtiRlRhjCZxlwyB5NnGGlLMNYBorbm/ fzyncpZf3ctGpzNWZJXXAESugrAnElNWWJm4VuDjEnViiXY4sdtcunwZuw8ReFoJcQPF r+n38NvMGhB+69DBtpvkUiU7qGcZbhvmk6R/rP+coSMX/rzBIDt8dhdvUfZwiZrGfcnT xz+/XYCsR2jYLxTgMxxTN2HmM/bGw7BgaC2RopcaRX9WbXMXtKzmBIe9+MDf5uqQHTvA E8dDy0F+sgWg77Yefm9Ma/q7eW5/DE5xQgfH2fIb76WeB12e3T8zCHlezekzHnf//x6e PniA== X-Gm-Message-State: AOAM5330gfJUmJZX53fsSBCYlTdoVE3dZ7tUKf/77PpHWffKfeygPu/d OBOv9tvk59kolgk8Zhf0PnE1TO0KaYMaWg== X-Received: by 2002:a5d:6452:: with SMTP id d18mr3124630wrw.493.1644320396024; Tue, 08 Feb 2022 03:39:56 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:55 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 09/39] hw/arm: imx: Don't enable PSCI conduit when booting guest in EL3 Date: Tue, 8 Feb 2022 11:39:18 +0000 Message-Id: <20220208113948.3217356-10-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42f (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42f; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42f.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Change the iMX-SoC based boards to use the new boot.c functionality to allow us to enable psci-conduit only if the guest is being booted in EL1 or EL2, so that if the user runs guest EL3 firmware code our PSCI emulation doesn't get in its way. To do this we stop setting the psci-conduit property on the CPU objects in the SoC code, and instead set the psci_conduit field in the arm_boot_info struct to tell the common boot loader code that we'd like PSCI if the guest is starting at an EL that it makes sense with. This affects the mcimx6ul-evk and mcimx7d-sabre boards. Note that for the mcimx7d board, this means that when running guest code at EL3 there is currently no way to power on the secondary CPUs, because we do not currently have a model of the system reset controller module which should be used to do that for the imx7 SoC, only for the imx6 SoC. (Previously EL3 code which knew it was running on QEMU could use a PSCI call to do this.) This doesn't affect the imx6ul-evk board because it is uniprocessor. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Tested-by: Edgar E. Iglesias Tested-by: Cédric Le Goater Acked-by: Richard Henderson Message-id: 20220127154639.2090164-5-peter.maydell@linaro.org --- hw/arm/fsl-imx6ul.c | 2 -- hw/arm/fsl-imx7.c | 8 ++++---- hw/arm/mcimx6ul-evk.c | 1 + hw/arm/mcimx7d-sabre.c | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/hw/arm/fsl-imx6ul.c b/hw/arm/fsl-imx6ul.c index 1d1a708dd97..f1897123294 100644 --- a/hw/arm/fsl-imx6ul.c +++ b/hw/arm/fsl-imx6ul.c @@ -166,8 +166,6 @@ static void fsl_imx6ul_realize(DeviceState *dev, Error **errp) return; } - object_property_set_int(OBJECT(&s->cpu), "psci-conduit", - QEMU_PSCI_CONDUIT_SMC, &error_abort); qdev_realize(DEVICE(&s->cpu), NULL, &error_abort); /* diff --git a/hw/arm/fsl-imx7.c b/hw/arm/fsl-imx7.c index 149885f2b80..cc6fdb9373f 100644 --- a/hw/arm/fsl-imx7.c +++ b/hw/arm/fsl-imx7.c @@ -159,9 +159,6 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) for (i = 0; i < smp_cpus; i++) { o = OBJECT(&s->cpu[i]); - object_property_set_int(o, "psci-conduit", QEMU_PSCI_CONDUIT_SMC, - &error_abort); - /* On uniprocessor, the CBAR is set to 0 */ if (smp_cpus > 1) { object_property_set_int(o, "reset-cbar", FSL_IMX7_A7MPCORE_ADDR, @@ -169,7 +166,10 @@ static void fsl_imx7_realize(DeviceState *dev, Error **errp) } if (i) { - /* Secondary CPUs start in PSCI powered-down state */ + /* + * Secondary CPUs start in powered-down state (and can be + * powered up via the SRC system reset controller) + */ object_property_set_bool(o, "start-powered-off", true, &error_abort); } diff --git a/hw/arm/mcimx6ul-evk.c b/hw/arm/mcimx6ul-evk.c index 28b4886f48b..8131518426a 100644 --- a/hw/arm/mcimx6ul-evk.c +++ b/hw/arm/mcimx6ul-evk.c @@ -35,6 +35,7 @@ static void mcimx6ul_evk_init(MachineState *machine) .board_id = -1, .ram_size = machine->ram_size, .nb_cpus = machine->smp.cpus, + .psci_conduit = QEMU_PSCI_CONDUIT_SMC, }; s = FSL_IMX6UL(object_new(TYPE_FSL_IMX6UL)); diff --git a/hw/arm/mcimx7d-sabre.c b/hw/arm/mcimx7d-sabre.c index 50a5ecde31a..ba84fc21920 100644 --- a/hw/arm/mcimx7d-sabre.c +++ b/hw/arm/mcimx7d-sabre.c @@ -37,6 +37,7 @@ static void mcimx7d_sabre_init(MachineState *machine) .board_id = -1, .ram_size = machine->ram_size, .nb_cpus = machine->smp.cpus, + .psci_conduit = QEMU_PSCI_CONDUIT_SMC, }; s = FSL_IMX7(object_new(TYPE_FSL_IMX7)); From patchwork Tue Feb 8 11:39:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540765 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp450200imo; Tue, 8 Feb 2022 04:31:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxRWfrzh0faaADBduzeCdoD+c2ySUTked7iR1sAdPUrzGD2TMJS3D/t98O8gM3Bt9W5tGZY X-Received: by 2002:a25:4805:: with SMTP id v5mr4073545yba.258.1644323503480; Tue, 08 Feb 2022 04:31:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644323503; cv=none; d=google.com; s=arc-20160816; b=sc+uVWVk3hc/hdbJlVuZvwgaKZfURwft/kXR873axXFPavnv71FqLh4mdnqIMvWdhW JF3+dIMra1FWQVs2THx1Sy89/AlmBaPqn506sqrYKUJA3t5eADBIAzJ2y+Th2edUzXoO ROhXs8JkDL8VyI5D18VE43NEedWh6vGDfGPbboQXYnFBlV9vuR/h4wtnFipo21K7ppcI Si/yBhPaLvgz2c25/q4r1gzmaLhJNPHtLGuoU5IejupNM8gPS2TDXz6PPi0F0lV1p4nn U03VU19XRPr6KhAtFKn5I1+n2TvlA9ungaskbqsEesZ7IJt2ePz9FqDeMxzHhsWGSiSA 39RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=PVQGUaLUYR0ZoTmSZ6QO0Yr2xljBTBn4GGoM7Uq+BeA=; b=abw2MbH2sEPESQl/BJIaFSbezO9NkjTVrDS9wy+mh1LB26DKNf2Hzcv2VScWKaYpIC vJGv10aDXTMEMyKhrvY5TbJifLaYbA4JTYLbCtaQmOyffuYFRTM83IoWgNpl3t+yBxQf /jgCr5btFbM7C+Ask680ws3+hyNAwXItDcrKS8qlIetYlihPO/vMZ87xGQM9vjHjlptf 5PGGBMY5T+FNSoDfssIhSh7RLZ1lHI3bcdmhYGbml5pSqCly5hLvxLCz49abhaM86ig4 nRFhDbbnSkcTpruu8UQfazMoMrDcgyCmvPn04q+zBuUOYEMHs/OVsnRyQzaT09OJsygt DmnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=K8oBm1Q9; 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=pass (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 p14si6184492ybg.776.2022.02.08.04.31.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:31:43 -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=pass header.i=@linaro.org header.s=google header.b=K8oBm1Q9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPen-0007ou-9P for patch@linaro.org; Tue, 08 Feb 2022 07:31:42 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqn-0000ii-Hu for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:02 -0500 Received: from [2a00:1450:4864:20::429] (port=39795 helo=mail-wr1-x429.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqk-00024B-OI for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:01 -0500 Received: by mail-wr1-x429.google.com with SMTP id d27so1898604wrc.6 for ; Tue, 08 Feb 2022 03:39:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=PVQGUaLUYR0ZoTmSZ6QO0Yr2xljBTBn4GGoM7Uq+BeA=; b=K8oBm1Q930r/T5dq+sVt7665hLlm4M/LVl6Ol5GcdYYg+MEP5uve4olVvQEat/F0td X1Kuw1YASyXuVdEy/B425/uc8iCEwQWTVSVZFhKRx2XlVVeah1BXACp5Rpbp1ErL6lUL 947JZ4gAhHGf3fOjrsflXewMGNDjI2yWGle+RGypGZq19D7ZDkek+AkSTNH1SGgofwzs wLtLsIATP6eDDZk+zwT+c2ntjnmwiK77G81FyyHbFradPlZA28WGgQ9Hnzj358QvgoDj xK4zZYi6yoKyCZDDUT1XS00nkXv0XEjc+gssQauxIl+1WKrk/7iSJE7kY7B2QiMEMhCs qcsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PVQGUaLUYR0ZoTmSZ6QO0Yr2xljBTBn4GGoM7Uq+BeA=; b=ZugRvxTmfxo2hoWN7oWQ8CqwUGMcSdw4W53i7PpfLYVThJRFZIhB5tw5iFl/2Kh+bF A9uol2vHrxdmfa0vc704pAvuPgqNQ5jvHjKqwUzm0eT7Ny4Eix1LieWVv6cOk4zN7hdQ 5ymWiz7jA3vEu1EGRRehp/MU60Q3eRG4lSjsF++iXIW4NLdlsJJ0uu37i+R6yksPEAA1 FvvaszZ5pYIPn83HmrWWMR3tljHradxKP/S5OPP7/LH3gSoZyHCt4EB8W4AGLTjm/xuD crzK+7XWqrFgWsKlo770Xi7Q5TRm5GYxAGCUiDHJKllXzZhoBkSwk7o/sGFf2Yl7/XAf f+WA== X-Gm-Message-State: AOAM530/Gdu5mEnmdptWMzMEPkqm+nWt0KJ+dMGklzL7lHjYTXXkKRjY rMSL16cYs2r6hkMdP7s8jpvfaI0QeqTc/g== X-Received: by 2002:a5d:49c1:: with SMTP id t1mr3232732wrs.359.1644320396642; Tue, 08 Feb 2022 03:39:56 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:56 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 10/39] hw/arm: allwinner: Don't enable PSCI conduit when booting guest in EL3 Date: Tue, 8 Feb 2022 11:39:19 +0000 Message-Id: <20220208113948.3217356-11-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::429 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x429.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Change the allwinner-h3 based board to use the new boot.c functionality to allow us to enable psci-conduit only if the guest is being booted in EL1 or EL2, so that if the user runs guest EL3 firmware code our PSCI emulation doesn't get in its way. To do this we stop setting the psci-conduit property on the CPU objects in the SoC code, and instead set the psci_conduit field in the arm_boot_info struct to tell the common boot loader code that we'd like PSCI if the guest is starting at an EL that it makes sense with. This affects the orangepi-pc board. This commit leaves the secondary CPUs in the powered-down state if the guest is booting at EL3, which is the same behaviour as before this commit. The secondaries can no longer be started by that EL3 code making a PSCI call but can still be started via the CPU Configuration Module registers (which we model in hw/misc/allwinner-cpucfg.c). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-6-peter.maydell@linaro.org --- hw/arm/allwinner-h3.c | 9 ++++----- hw/arm/orangepi.c | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c index f9b7ed18711..318ed4348c7 100644 --- a/hw/arm/allwinner-h3.c +++ b/hw/arm/allwinner-h3.c @@ -235,11 +235,10 @@ static void allwinner_h3_realize(DeviceState *dev, Error **errp) /* CPUs */ for (i = 0; i < AW_H3_NUM_CPUS; i++) { - /* Provide Power State Coordination Interface */ - qdev_prop_set_int32(DEVICE(&s->cpus[i]), "psci-conduit", - QEMU_PSCI_CONDUIT_SMC); - - /* Disable secondary CPUs */ + /* + * Disable secondary CPUs. Guest EL3 firmware will start + * them via CPU reset control registers. + */ qdev_prop_set_bit(DEVICE(&s->cpus[i]), "start-powered-off", i > 0); diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c index e7963822367..68fe9182414 100644 --- a/hw/arm/orangepi.c +++ b/hw/arm/orangepi.c @@ -105,6 +105,7 @@ static void orangepi_init(MachineState *machine) } orangepi_binfo.loader_start = h3->memmap[AW_H3_DEV_SDRAM]; orangepi_binfo.ram_size = machine->ram_size; + orangepi_binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC; arm_load_kernel(ARM_CPU(first_cpu), machine, &orangepi_binfo); } From patchwork Tue Feb 8 11:39:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540757 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp437642imo; Tue, 8 Feb 2022 04:12:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJya27QsJuvWU+T0eSwq4xsSfPfaLXb6Slvby5iTxtQZsaWJ5+qIT+dKO+891JSNNC35F/hS X-Received: by 2002:a25:1944:: with SMTP id 65mr4012832ybz.487.1644322326633; Tue, 08 Feb 2022 04:12:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644322326; cv=none; d=google.com; s=arc-20160816; b=K+bKayKs/nI9KDGPyB/2Rmba2llBhAJB4EOyB7YFVot+ldjQKRE2o1qn7K688LN9QR B6RKcgMv2t90oD71w16SwCsBfZhNehGcmK7hojR6bxjTP7uFcaJOv8XVgC0yS1I6ZBKL 6g/X7ZVe1FZFC8CTupYLnFt+ZyUskiPbM7B5cyQg0GYWGsvq13lgyti/+4qO3lYTbx0H Av9o6XgV3E7d1lqJ3XsTrd7j/PxK42UlRh6VLgXRUTiTUWv8PIN2VvvGKIzDEUlw7joW ZuaQsWIkJBv8suABxmBe1g591ION2bDF8VxiOa67G4lKadyMxOmxP3TG0PDDduQpkPX2 w+7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=JIBuxLdewgryzVDpiDHfhlGi/hrvUx98UZy6rt0YW+g=; b=qsXmzQ9qBgNUTMmKx2FXYE2aGz0PE76lwDT7gbDUtGl7vnkrVLS1Cqu9tzOtwacBlN 5301QREN+785TCVoDefcIXQLLY9ofcL5pzp8JPBuarGhrflDhP2ixuV0GfGKLpbFnS6Y WUVnhQjpPYUXSjx+kVeQCDq646GoEn8Jv5xAKTNXjj6b86+iTHT/4cO+J+/+qYMZnkbY ERAeAG3WsED3yPP+UVwkYku56HogYtgN7zbtbql+4kbL+ttEGYgW2odqTLzl0hRf86IX 4Owcmt2gh52BwMvR4UAvd5piRPcfV/ro74g9Y+ZsETDR9yo0lu6WcxX3VQ+CnzhhTqoK tceQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fcotyDpT; 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=pass (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 r19si5113270ybc.300.2022.02.08.04.12.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:12:06 -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=pass header.i=@linaro.org header.s=google header.b=fcotyDpT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPLq-0008Ll-3S for patch@linaro.org; Tue, 08 Feb 2022 07:12:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqn-0000ij-Hy for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:02 -0500 Received: from [2a00:1450:4864:20::42c] (port=42886 helo=mail-wr1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqk-00024M-Oi for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:01 -0500 Received: by mail-wr1-x42c.google.com with SMTP id h6so11460649wrb.9 for ; Tue, 08 Feb 2022 03:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=JIBuxLdewgryzVDpiDHfhlGi/hrvUx98UZy6rt0YW+g=; b=fcotyDpTK13gBGSabP8zBhKBjiKVWIepKY4/66JcavEPiHawUrgmOGH29rVeqnTQJV K3NmoN8g7ivHY6nWsSFpuqUZCA1mHfBqeccrq93LkwPYwjX3cVVe3/6dAsJDBklhtIdq 7hZIrM8l4jm4tAXtCsIzI8wxa2Hl+SVsoSECYaoc5dqAFAIQFiTgt8dUYirCCZIyXxEh wkVApwcrkHn+HgCryo3WQ1I+H+2QNONCCIIMGqO3AJa2+qOvzdlX+7CxPGFjIuFagF9O k1WQJIqnAC1tYytvvLC9SAqhtTUQsTB9muiO2luXLnOGDg7VwcDDNplUcbJjHCo5WloW 2N3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JIBuxLdewgryzVDpiDHfhlGi/hrvUx98UZy6rt0YW+g=; b=jlYXUdOTeNdMj1ItJPL/u/7S+Fml7q4ZdBDg+SD3OkVgqO0fH+/Rt5XYoh6Uz2WVgc R7okgPN6Q5o+hzZ8IjX6mGMj7x0vWI9EC8aaWYqxigcW9O+dX0ApnlLFCWmvjTgT2MfJ BeUMIEXCklnDTG+qIGV6GuR1B4uLbUvLG+L79buW7+F5gmIdEMOEl5QEJd1Toaf4BUj9 nSQzqsi5ee/xdMv3BWFcvGP9j6y73NxMS/LmnCEJfPldvfXdKvQJJfuAixkjUbsqBYmx cPj1B/4Yw5oTdUHqYBMbIwnkvPuPz72+mJTh62hDmLUMzjeLVqOmhibnBef/20Mw2bbX qsNA== X-Gm-Message-State: AOAM53167Gretw7JUQIYDJpxMFe/NKbJQGpHyEmsSFPBhHLsVKSmshI9 Ecbntw/3TSric8MvdvRYYKb7AZvxTvbo1A== X-Received: by 2002:adf:d843:: with SMTP id k3mr1183525wrl.633.1644320397313; Tue, 08 Feb 2022 03:39:57 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:57 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 11/39] hw/arm/xlnx-zcu102: Don't enable PSCI conduit when booting guest in EL3 Date: Tue, 8 Feb 2022 11:39:20 +0000 Message-Id: <20220208113948.3217356-12-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42c (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Change the Xilinx ZynqMP-based board xlnx-zcu102 to use the new boot.c functionality to allow us to enable psci-conduit only if the guest is being booted in EL1 or EL2, so that if the user runs guest EL3 firmware code our PSCI emulation doesn't get in its way. To do this we stop setting the psci-conduit property on the CPU objects in the SoC code, and instead set the psci_conduit field in the arm_boot_info struct to tell the common boot loader code that we'd like PSCI if the guest is starting at an EL that it makes sense with. Note that this means that EL3 guest code will have no way to power on secondary cores, because we don't model any kind of power controller that does that on this SoC. Signed-off-by: Peter Maydell Reviewed-by: Edgar E. Iglesias Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Edgar E. Iglesias Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Acked-by: Richard Henderson Message-id: 20220127154639.2090164-7-peter.maydell@linaro.org --- hw/arm/xlnx-zcu102.c | 1 + hw/arm/xlnx-zynqmp.c | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c index 45eb19ab3b7..4c84bb932aa 100644 --- a/hw/arm/xlnx-zcu102.c +++ b/hw/arm/xlnx-zcu102.c @@ -236,6 +236,7 @@ static void xlnx_zcu102_init(MachineState *machine) s->binfo.ram_size = ram_size; s->binfo.loader_start = 0; s->binfo.modify_dtb = zcu102_modify_dtb; + s->binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC; arm_load_kernel(s->soc.boot_cpu_ptr, machine, &s->binfo); } diff --git a/hw/arm/xlnx-zynqmp.c b/hw/arm/xlnx-zynqmp.c index 5fbf38c4660..6d0e4116db7 100644 --- a/hw/arm/xlnx-zynqmp.c +++ b/hw/arm/xlnx-zynqmp.c @@ -216,7 +216,9 @@ static void xlnx_zynqmp_create_rpu(MachineState *ms, XlnxZynqMPState *s, name = object_get_canonical_path_component(OBJECT(&s->rpu_cpu[i])); if (strcmp(name, boot_cpu)) { - /* Secondary CPUs start in PSCI powered-down state */ + /* + * Secondary CPUs start in powered-down state. + */ object_property_set_bool(OBJECT(&s->rpu_cpu[i]), "start-powered-off", true, &error_abort); } else { @@ -438,12 +440,11 @@ static void xlnx_zynqmp_realize(DeviceState *dev, Error **errp) for (i = 0; i < num_apus; i++) { const char *name; - object_property_set_int(OBJECT(&s->apu_cpu[i]), "psci-conduit", - QEMU_PSCI_CONDUIT_SMC, &error_abort); - name = object_get_canonical_path_component(OBJECT(&s->apu_cpu[i])); if (strcmp(name, boot_cpu)) { - /* Secondary CPUs start in PSCI powered-down state */ + /* + * Secondary CPUs start in powered-down state. + */ object_property_set_bool(OBJECT(&s->apu_cpu[i]), "start-powered-off", true, &error_abort); } else { From patchwork Tue Feb 8 11:39:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540764 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp448349imo; Tue, 8 Feb 2022 04:28:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJxCKwQ3lTLy+jXSFFMo84meMnF6GMmgVoBtFupaa9beYO9OBMxZdaV+h4nQB19HUWHYEw/U X-Received: by 2002:a81:3e19:: with SMTP id l25mr4249110ywa.417.1644323319998; Tue, 08 Feb 2022 04:28:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644323319; cv=none; d=google.com; s=arc-20160816; b=ZX3d5FI8kxnR1uMY9ntgqc6uS+cx5hR3ggIdj49i8c7q5OV5Yr46c9qcrSIsWEQtVM mRuGCFQUXKQUIL0usENyZCCdS3wFP9yvd9V3Pn714oxgVvrq1AHTYnkKvTvcvf7P8HC5 n0YOp9mPM/2bAB9JJEFiDOFsKu+258CSL01P7BvwczRO1a+lgj80Vuv4FYMegVPHsGEz dG8ehplHXDfoaTpebGnGvYvublYX+C7Qc64w3Xpr+xtAPk/GcGN/yT+gQCOuz+ikIOIZ n4/pCeFquHGAxvvFChlWJUaE3zLXX2dZj7D/wpAW7Y7xOlGAZRsp2p8WVY++YywdTeYn 8ctA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=GqHfUpEsKMZLaI4jcU1cq1CuH1+qtJTC3nWZv1Haqzk=; b=q1Z98yWESdDOVnTRrdF7P+OdZuHKfEbWCceJXb1lmh8xpF52NROyziV7RfoKWRbsKx 9IV1a5+MnzgXyVzxHKXKImTukIOyorNYYMDr4wud9kHR7+CvRyaMhLk+3sXaBtl61hgR OkXjr45xr2kTp92ve/7jjbLKw58+FJcMFu+fX0nbtfnhpvIoaTcOjn0ca57itYyPLWqh KZXdY511zYfnJwDuOZq/m9UYjR+YKEKfB8yhctrkTW9AqDeLh3cmglENOlYKGULXlXJC mT/Ar5bJ3bHUteqZ/Nw9FGqYS4psKUotE12EgcPimG3JPyWuYXo6ER5eLJEcRKlWvSYC H3ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="K0wN+YP/"; 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=pass (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 k135si8602793ywa.490.2022.02.08.04.28.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:28:39 -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=pass header.i=@linaro.org header.s=google header.b="K0wN+YP/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPbq-0004EJ-Bl for patch@linaro.org; Tue, 08 Feb 2022 07:28:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34754) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqt-0000l8-OB for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:08 -0500 Received: from [2a00:1450:4864:20::436] (port=41983 helo=mail-wr1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqm-00024S-IW for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:03 -0500 Received: by mail-wr1-x436.google.com with SMTP id k1so13650572wrd.8 for ; Tue, 08 Feb 2022 03:39:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=GqHfUpEsKMZLaI4jcU1cq1CuH1+qtJTC3nWZv1Haqzk=; b=K0wN+YP/zZgz/7LiEHTm3gMPirwjIq0cY8InoRkSQGOSUyJne4VJNTID4TOMr16ufl Ik7vdv4zu2qLYATwaEyOb7qRjUD+aniAhNeb1fnrJMZbcOBTb1Z536gwiqnLiQ5LjGkm eh7qUWyI/OymGNiA5a8hvmQvfMT9KRkv+1S30jLKVsC/sKQVHso4dUjEF3HCVZUdTgIv cuLPR+1dYDPFvsxpaOuEoqQIe84GPDLo7cr8LVBjywRBNvyKpSsWvDwsE2UJudo9IxpU QD3AXxbpj6PuYjkku8PUGBObEAXGZCBSh7rfAOEGkUgrHqOOZM82fzYCwPlY0cFB6VRi Squw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GqHfUpEsKMZLaI4jcU1cq1CuH1+qtJTC3nWZv1Haqzk=; b=GSN0ofih/E148lf/vayTjex5JmdjSosma6IB9ajPcCslNBbvaSlm2VOyxS5m3qqybO 3ZOle0HX+Of5IDQFYRt4JKqjmSUthHJkSDsKaeZaWaTdOCY5+dvE+UXmgixCq8UnJLv/ ap0c3Pi6VAyPZ/Qk+boKX7Zt7PlOvIMJBEAGsf2xOW+adnF5d721iVQkJzeRuo3nm+Y5 UzqOzFaf0CgyoWJDmQMGsnzE/hQu40UmLHrczvrb19ge9F2799gxKOSFxPqGreUj90E+ MFls5GhGm4ZqHDlq9qk8GtCgh/TCtiroPj1id+ll1d/eIBDdwiQwZIsynAfiXLrc89tt uZig== X-Gm-Message-State: AOAM530JRvkRIVHdbMSGmYhHTX0ZrV0oi3jq01AfD3/LoU9K/zHgjFx+ h0YJ7En5/kMjIzT4OllUWFi9g7XQsppFtg== X-Received: by 2002:adf:f981:: with SMTP id f1mr3182951wrr.651.1644320398014; Tue, 08 Feb 2022 03:39:58 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:57 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 12/39] hw/arm/versal: Let boot.c handle PSCI enablement Date: Tue, 8 Feb 2022 11:39:21 +0000 Message-Id: <20220208113948.3217356-13-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::436 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Instead of setting the CPU psci-conduit and start-powered-off properties in the xlnx-versal-virt board code, set the arm_boot_info psci_conduit field so that the boot.c code can do it. This will fix a corner case where we were incorrectly enabling PSCI emulation when booting guest code into EL3 because it was an ELF file passed to -kernel. (EL3 guest code started via -bios, -pflash, or the generic loader was already being run with PSCI emulation disabled.) Note that EL3 guest code has no way to turn on the secondary CPUs because there's no emulated power controller, but this was already true for EL3 guest code run via -bios, -pflash, or the generic loader. Signed-off-by: Peter Maydell Reviewed-by: Edgar E. Iglesias Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Edgar E. Iglesias Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-8-peter.maydell@linaro.org --- include/hw/arm/xlnx-versal.h | 1 - hw/arm/xlnx-versal-virt.c | 6 ++++-- hw/arm/xlnx-versal.c | 5 +---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/hw/arm/xlnx-versal.h b/include/hw/arm/xlnx-versal.h index 1b5ad4de802..0728316ec77 100644 --- a/include/hw/arm/xlnx-versal.h +++ b/include/hw/arm/xlnx-versal.h @@ -103,7 +103,6 @@ struct Versal { struct { MemoryRegion *mr_ddr; - uint32_t psci_conduit; } cfg; }; diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c index 3f56ae28eea..ef3231cdbb3 100644 --- a/hw/arm/xlnx-versal-virt.c +++ b/hw/arm/xlnx-versal-virt.c @@ -628,6 +628,9 @@ static void versal_virt_init(MachineState *machine) * When loading an OS, we turn on QEMU's PSCI implementation with SMC * as the PSCI conduit. When there's no -kernel, we assume the user * provides EL3 firmware to handle PSCI. + * + * Even if the user provides a kernel filename, arm_load_kernel() + * may suppress PSCI if it's going to boot that guest code at EL3. */ if (machine->kernel_filename) { psci_conduit = QEMU_PSCI_CONDUIT_SMC; @@ -637,8 +640,6 @@ static void versal_virt_init(MachineState *machine) TYPE_XLNX_VERSAL); object_property_set_link(OBJECT(&s->soc), "ddr", OBJECT(machine->ram), &error_abort); - object_property_set_int(OBJECT(&s->soc), "psci-conduit", psci_conduit, - &error_abort); sysbus_realize(SYS_BUS_DEVICE(&s->soc), &error_fatal); fdt_create(s); @@ -679,6 +680,7 @@ static void versal_virt_init(MachineState *machine) s->binfo.loader_start = 0x0; s->binfo.get_dtb = versal_virt_get_dtb; s->binfo.modify_dtb = versal_virt_modify_dtb; + s->binfo.psci_conduit = psci_conduit; if (machine->kernel_filename) { arm_load_kernel(&s->soc.fpd.apu.cpu[0], machine, &s->binfo); } else { diff --git a/hw/arm/xlnx-versal.c b/hw/arm/xlnx-versal.c index ab58bebfd2e..2551dfc22d6 100644 --- a/hw/arm/xlnx-versal.c +++ b/hw/arm/xlnx-versal.c @@ -40,10 +40,8 @@ static void versal_create_apu_cpus(Versal *s) object_initialize_child(OBJECT(s), "apu-cpu[*]", &s->fpd.apu.cpu[i], XLNX_VERSAL_ACPU_TYPE); obj = OBJECT(&s->fpd.apu.cpu[i]); - object_property_set_int(obj, "psci-conduit", s->cfg.psci_conduit, - &error_abort); if (i) { - /* Secondary CPUs start in PSCI powered-down state */ + /* Secondary CPUs start in powered-down state */ object_property_set_bool(obj, "start-powered-off", true, &error_abort); } @@ -667,7 +665,6 @@ static void versal_init(Object *obj) static Property versal_properties[] = { DEFINE_PROP_LINK("ddr", Versal, cfg.mr_ddr, TYPE_MEMORY_REGION, MemoryRegion *), - DEFINE_PROP_UINT32("psci-conduit", Versal, cfg.psci_conduit, 0), DEFINE_PROP_END_OF_LIST() }; From patchwork Tue Feb 8 11:39:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540789 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp518882imo; Tue, 8 Feb 2022 06:09:45 -0800 (PST) X-Google-Smtp-Source: ABdhPJxsju3UKfBlGbrdNDPzZnv/woJIFdNDXHf2ZvPlQb9WYsDOAhazAdEWOJcizUZLnh2UqqkD X-Received: by 2002:a5b:98f:: with SMTP id c15mr4733385ybq.214.1644329385746; Tue, 08 Feb 2022 06:09:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644329385; cv=none; d=google.com; s=arc-20160816; b=SETBBR53RCVHiY7hOC7KZ8q2rngZ3yiYCwKJpi1FEad6nf0ZxY1cBPlEJtJbASgfee 6fDjDGLRDGa1vKD7BPIBGHbGr40PL08HLHl6cuYL2W+ZfRRClu+8sOq+4JpqgKKeUfKJ l+h51387osqcJgddCysDMaozd03lsgC4ODqltLKLfpsyi5v14++FGKAQ/Q5I4bqVwtii ciumNGIwuN0mYV+j6/IGWT0OGCs17OrnG6M2PT2QWjEVrYuSrgytzHi1s0KzXS0IeCFc SpdHqcpHmB+RsmhgZh9DybBBmHw7XameLCvNYe6/TdAvJJTDuP9POBpn9pXMcDQMg6Ac wn7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=fwoBiexU45XLKaINWWKJ9pyjhIoo7bPekJWNYGgC67I=; b=GKRIX8rrg0vdm/YQmvSXz1ZLtB1g2Fg+KrHOSaQDQaFwA6C+E8FamaqZljoArVX0jA sHyyCvGlLVTHrUqobPH3CRHBnpBhw/W1fOFv7Fb8gJRrskG99Pw8juYORPr0zHOD6tX9 VgYKwKEuNlvaIG8AHLyirQcx5mStUiAVQvGGprma01mMCiBxRlS1N4kLA+oqCrIZp/yg V7JJn7VvvE5wS8O4gFBV/fdcVBdM9cT5IcxGSPt7bC3XdH7UuBTvZeuBjSSYWu0E9yNy oP0QAAM5Y00gYAXirMrgG7Vm5mQG4+F4eDrN2EFQEMGA/F41WqHyh0gY9M7Ho9Sz5283 6IXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GtygNhjH; 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=pass (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 g6si11395589ywi.108.2022.02.08.06.09.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:09:45 -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=pass header.i=@linaro.org header.s=google header.b=GtygNhjH; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHRBh-0007ei-8V for patch@linaro.org; Tue, 08 Feb 2022 09:09:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34678) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqp-0000kw-Dx for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:08 -0500 Received: from [2a00:1450:4864:20::429] (port=41971 helo=mail-wr1-x429.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqm-00024d-IT for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:02 -0500 Received: by mail-wr1-x429.google.com with SMTP id k1so13650596wrd.8 for ; Tue, 08 Feb 2022 03:39:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=fwoBiexU45XLKaINWWKJ9pyjhIoo7bPekJWNYGgC67I=; b=GtygNhjHA/S+GLJxsVoDOq29eGHHG0+do2eX2nP8GDdmWrFqOkXot3/BpX4Rfacyiz egV1j7ZnmxAIEtqNSCKFiqEaCxD13AKBZzjhVldylGrVe8IzTUcPmwlo6uAFE8S9iOf4 Df/jPRswFQIEdWd0LHxVHgTv2oNkE2ljBg6OfvGfAfPijAVQWWELE+DBwhbBDjncZ4BD 1gn2K58lGaS6SOOu5YF4zs25BlVT5aLEDgu+hrHQue8iav/iWxcc1+QP3ArUlHWKqP3h /cAOghpC/YfM/WsN9N4QN4iHNa0Z9YtV49f7EXHAYIwtTmMhbPOaOkxSLkFuWIhun3FW p9dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fwoBiexU45XLKaINWWKJ9pyjhIoo7bPekJWNYGgC67I=; b=5e5cgNDjff2jEsis3LwQ5KL3NY6GEV4t2za/fNqonsMRutOJnF9gVWbaLY6W0mNvfP /3n2EnamdzbFdqyyMl9XGPGLBB1/JJGoDlyXR1ushcNq7GCKH2+A9jdgY01Tc3dRbf+k 8VvVoPzaPQ7y3eR/6pwKiPinLEDUxViXcSlfKID/UJktgR6FO8kIcdl35HMC8YtQI+ij D2Zu15NtkPCUSZmC0AxFDmV3qjGeTKq0JUTFSbKzkNtDjPRE578YYAV+BEVYMSZMkmZs imn34Fbn0Htd3bW9Y1zr/n+QGU5+ISDjVqhUCw+Dh1ka29rDvd8aF3pDVyn0TU8xhymS kMJg== X-Gm-Message-State: AOAM530/AtDy/cdqvTwLH9/cuXycQwOaTH0ZiI9hZQY6e5uhqjcWZYxU sH0D323P0nFhRPesHiCztvnwRsYBvu6vMg== X-Received: by 2002:adf:d183:: with SMTP id v3mr3238782wrc.538.1644320398635; Tue, 08 Feb 2022 03:39:58 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:58 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 13/39] hw/arm/virt: Let boot.c handle PSCI enablement Date: Tue, 8 Feb 2022 11:39:22 +0000 Message-Id: <20220208113948.3217356-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::429 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x429.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Instead of setting the CPU psci-conduit and start-powered-off properties in the virt board code, set the arm_boot_info psci_conduit field so that the boot.c code can do it. This will fix a corner case where we were incorrectly enabling PSCI emulation when booting guest code into EL3 because it was an ELF file passed to -kernel or to the generic loader. (EL3 guest code started via -bios or -pflash was already being run with PSCI emulation disabled.) Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-9-peter.maydell@linaro.org --- hw/arm/virt.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 141350bf215..398145a7180 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2088,17 +2088,6 @@ static void machvirt_init(MachineState *machine) object_property_set_bool(cpuobj, "has_el2", false, NULL); } - if (vms->psci_conduit != QEMU_PSCI_CONDUIT_DISABLED) { - object_property_set_int(cpuobj, "psci-conduit", vms->psci_conduit, - NULL); - - /* Secondary CPUs start in PSCI powered-down state */ - if (n > 0) { - object_property_set_bool(cpuobj, "start-powered-off", true, - NULL); - } - } - if (vmc->kvm_no_adjvtime && object_property_find(cpuobj, "kvm-no-adjvtime")) { object_property_set_bool(cpuobj, "kvm-no-adjvtime", true, NULL); @@ -2246,6 +2235,7 @@ static void machvirt_init(MachineState *machine) vms->bootinfo.get_dtb = machvirt_dtb; vms->bootinfo.skip_dtb_autoload = true; vms->bootinfo.firmware_loaded = firmware_loaded; + vms->bootinfo.psci_conduit = vms->psci_conduit; arm_load_kernel(ARM_CPU(first_cpu), machine, &vms->bootinfo); vms->machine_done.notify = virt_machine_done; From patchwork Tue Feb 8 11:39:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540787 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp514437imo; Tue, 8 Feb 2022 06:05:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhc8hnhrk1csB7BXZtTDey1jnRcfBarEuWA65Qp5pnzMx5KZLAZU36r+6kKs9NOZwlAY/R X-Received: by 2002:a5b:28f:: with SMTP id x15mr5072223ybl.521.1644329108163; Tue, 08 Feb 2022 06:05:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644329108; cv=none; d=google.com; s=arc-20160816; b=JVISX8b29K/4iVWTeZNU3XpFcRXi5uacyyM8vAfAtR0T74imBi6JA8KfUzgwNBSkb1 tqbsPBNJQYXQeteLVzMO5CGhpXZMHljfjfgk42Xnsf+OsM2vyk/qJvO7S6KGbtqt35G3 eCRhECvsUr9ZI6994gIwIbxMNwnBhJ1QVc7xjImeb5XjBSyw6dnhzEhqc5So3taDR1fZ sjtWqIg9/Jtbvvzh2S75ryBZgOcVRQkYDc/eO3NK0U7tLgw67eSF5qd3UJ7+IKp7GGmu vMp2Rskl+Jrz+gu5zHXvhbGfpm+HyVGqcXGnMbyybrlcvbbPeo/TK3CXCKJ6nF3x0Ohz wFTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=pWyIdAyiNvL5aeMyV/2dz6HORKREdSQ7gC9teOnHGYE=; b=IpBZ4AGtefXx/8bYpmNMWyEhiZX7Oh0O5YGcyjowDI3KmvCYnbg0bacj5aj0o1Xm/a 1WB8VEiCL+ZhzDs9Caq1bMzhgC/zC/AAK1YThiiblO0sZh61dvvNeI8Oj8/G2nGMzHFD W0eeQj4cl/bVM+Wjl33+wvZezYehPyWoyN59Ug6b1sJ3+24NoZAHtIiNzwnNtE7vwIc2 SkFv6AEuur6wJyG9bfOfxgshoEf3q5zxu9J5o0Q0tt9TgullOTM0h+ZXnrk8Hb4XoNtd /8XdorwcDECrQf7/B1KzGP/NQitshxkVRyy1cubgYaXK5GZ7XxloPmOVaN6pfNKfhKN8 M0Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qADBOkj9; 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=pass (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 b67si2865910ywh.551.2022.02.08.06.05.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:05:08 -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=pass header.i=@linaro.org header.s=google header.b=qADBOkj9; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHR7D-00012D-JZ for patch@linaro.org; Tue, 08 Feb 2022 09:05:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34752) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqt-0000l7-No for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:08 -0500 Received: from [2a00:1450:4864:20::436] (port=38572 helo=mail-wr1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqm-00025w-KT for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:04 -0500 Received: by mail-wr1-x436.google.com with SMTP id s10so27592396wra.5 for ; Tue, 08 Feb 2022 03:40:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=pWyIdAyiNvL5aeMyV/2dz6HORKREdSQ7gC9teOnHGYE=; b=qADBOkj9jv4Fee3l4jFHPE+B0o+ZM3dEI5l82FzN27PIcBmmD5fDS8zkI3IVeXY41M o/hJTrzTg76pcPthPntcuSJHznkChjrqzxRBr3azqlXqn+h4IR40T1RzvI7Ektz/q5pc FaKvSTaYKLf1/IxSvNaNEKEGcFCDwtFcF9JzyCSScm75LHi5KHfIk+yKuivzq66Y/JKj d9LiXv++7UI2w1rOuH0185vNiWBJY1s/w2bHKoMqjdhlg9i7NB+xC/GY70fKkNwWr44D 5+MJbVjtywsNz4ZEjZoshgEGUdMAbNzXT/hL9//TLYH1XjFbbHf74JYG2K9ELSG403+Z UULg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pWyIdAyiNvL5aeMyV/2dz6HORKREdSQ7gC9teOnHGYE=; b=WE9GKpEptWgcnrH1v9P7NjriApeKQ3yjh0JGY13d7ucW7hOkeWs3KocBldzKWgDo0B UL38e+0AP6zDcmOi/bJ3bKBiOb87rFz5+TlPqirv5VVLG0Db1fV5FNWOhUoDNLimQoGN 6//QYRIUbNsTQJlkeUz/JGM3meD7ayrtBGDOPhpsuAueg0YIgUKVdhBq6vhM8jETBwbm eg9A9Wt+msoZT7f4gtFMMFUZwWhGJcJuwAtEe9SjzRMZststKORfsXR8ffD2FGcwKAqL GGmR5VmuK7R2JZZwKazoNnDmEFg4CHQ9r8WsMhKXItPCzLbv6pf98blcsEkfPQJ6WO5w drWQ== X-Gm-Message-State: AOAM531E+xJ3RrpnnRvSK7ddOLn2Or1F4mIpeFqBsOpGgfks4pmJe0sE PKAFCR5vJHebizq9NYg+LMmTR2m58RCShw== X-Received: by 2002:a5d:64e9:: with SMTP id g9mr3209948wri.341.1644320399335; Tue, 08 Feb 2022 03:39:59 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:58 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 14/39] hw/arm: highbank: For EL3 guests, don't enable PSCI, start all cores Date: Tue, 8 Feb 2022 11:39:23 +0000 Message-Id: <20220208113948.3217356-15-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::436 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Change the highbank/midway boards to use the new boot.c functionality to allow us to enable psci-conduit only if the guest is being booted in EL1 or EL2, so that if the user runs guest EL3 firmware code our PSCI emulation doesn't get in its way. To do this we stop setting the psci-conduit and start-powered-off properties on the CPU objects in the board code, and instead set the psci_conduit field in the arm_boot_info struct to tell the common boot loader code that we'd like PSCI if the guest is starting at an EL that it makes sense with (in which case it will set these properties). This means that when running guest code at EL3, all the cores will start execution at once on poweron. This matches the real hardware behaviour. (A brief description of the hardware boot process is in the u-boot documentation for these boards: https://u-boot.readthedocs.io/en/latest/board/highbank/highbank.html#boot-process -- in theory one might run the 'a9boot'/'a15boot' secure monitor code in QEMU, though we probably don't emulate enough for that.) This affects the highbank and midway boards. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-10-peter.maydell@linaro.org --- hw/arm/highbank.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c index 4210894d814..048f8550cb9 100644 --- a/hw/arm/highbank.c +++ b/hw/arm/highbank.c @@ -271,12 +271,6 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id) object_property_set_int(cpuobj, "psci-conduit", QEMU_PSCI_CONDUIT_SMC, &error_abort); - if (n) { - /* Secondary CPUs start in PSCI powered-down state */ - object_property_set_bool(cpuobj, "start-powered-off", true, - &error_abort); - } - if (object_property_find(cpuobj, "reset-cbar")) { object_property_set_int(cpuobj, "reset-cbar", MPCORE_PERIPHBASE, &error_abort); @@ -397,6 +391,7 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id) highbank_binfo.board_setup_addr = BOARD_SETUP_ADDR; highbank_binfo.write_board_setup = hb_write_board_setup; highbank_binfo.secure_board_setup = true; + highbank_binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC; arm_load_kernel(ARM_CPU(first_cpu), machine, &highbank_binfo); } From patchwork Tue Feb 8 11:39:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540761 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp443986imo; Tue, 8 Feb 2022 04:21:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJwmst3rHQnYtKkN8UUIQf7uD+0HptKrtEtulBohEolOPwSggP/tpusKn5mnu01H9AcaSAeR X-Received: by 2002:a25:4842:: with SMTP id v63mr4493991yba.21.1644322915916; Tue, 08 Feb 2022 04:21:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644322915; cv=none; d=google.com; s=arc-20160816; b=mlVJy6bszog3QyfazMv9lIrvBYywZrLGmGON4hvYMYIINanck1AQOcf45xOzwxlgpe f5R4ShozUhiXfWJvDRlxb6e9w2lEEig5rL5XbX7nV2Q80ZpC0DEoKw7grLk1RicWWr3n TMmQTHqT9q8U1op6UA9uWFWIn+MkzyoNufaC0CklYZ4fhqcsJVq12HXAc7AwOA5whsKp C/nhM7nZOzCJzFKYmh5DSANRJwfqEku5X/Dt71SKc3D+lIv1VtleWC57cQwxxd53iyVx +3K4DCFT1Zd48SfVTs2yhteE6ZloZ+QuH2wW85Dj/ZG9dMix9q4dWKyvnW0wd4oWwPZa 5VnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=0p89JlNK/gdgxgU6z1QE83PIekJHSLOFEA28AM6yAyk=; b=nw14oOLDyaDflnBMFHCgD6QX4FK5W7Ltd9z6znPH5UKHtdD/u3Cg3kf0T/+0RcpZAV W4Y60w4xjUowuxeaaWrIK8uWzV9j3v9BZEsfGZNQT6PKO/IDrc51riN1zGYdaJiyvrvj 3z11pyPcPPNYQm2aROi99dL/nI673Hqgw+juEH7Lq7lVXZR7D6mMDb/s+v4LfMCFuS0q 9WCV3RqIc4DpYlwrLLIxzbeqJnXfIXBIMaoOBWd54y+CC8xngP3PYgi8ZgE/pZOV/jsf 2sucHI0F7H8vVjnjMBmKPb6EWWFbh4c1tBjsr5Xp71YJSrvBywPlLqQ5R6Z7CQ7AosMK Xkdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RtrCaCwg; 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=pass (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 b20si9897740ywb.313.2022.02.08.04.21.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:21:55 -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=pass header.i=@linaro.org header.s=google header.b=RtrCaCwg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45624 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPVL-0006X6-3e for patch@linaro.org; Tue, 08 Feb 2022 07:21:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqt-0000l6-KX for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:08 -0500 Received: from [2a00:1450:4864:20::42c] (port=45049 helo=mail-wr1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqn-000260-8L for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:04 -0500 Received: by mail-wr1-x42c.google.com with SMTP id k18so30169536wrg.11 for ; Tue, 08 Feb 2022 03:40:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0p89JlNK/gdgxgU6z1QE83PIekJHSLOFEA28AM6yAyk=; b=RtrCaCwgRKDDgmRcI3b785kbzlleCu0ZpTievGNAnIkU8UkGMevLodBC0t+n40+ujT c7xT8Eg4ivDpAo1rcxy1b3OiIZPaHe2q8k9/y7BzILMLXU8e+0h8gLs1NNvutrXYEam9 NkLm0Dp+riw8GkOcgZNfyYVhRZxK3U5YF9PO94u3FpVjLLHGxEBxxOUu7KvDK+3IG+Nt h7pExs1ZwhC9FX/Fni3t9pz0ZPSbwth/aNOVu+f4EGSMWxK4hes1DrzijsKH4gu21JhE LO/dWq6cwS+Ku4Wm0A/rtefi+3g+m/QEt1WfYcbvHt1WRhSP6iKuPvTTc6FZGwFSkyKn 7i1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0p89JlNK/gdgxgU6z1QE83PIekJHSLOFEA28AM6yAyk=; b=TjlrrLsSKpZcu7Fs33HBbnrG1P9KikeI0XCwmMd7KBst+1eUJ4IPW4fGF2rVX0NI/Q Hr+RZYjSUNjAtXJ/iuDeX5V/imibvcnrA+2gTj7YFqXs4vfnA38zuI28xU9ghhEBx5kO ZjO3YPiitVs8Hn5/v/ij3W/5lXByCen1pqvr8QCpdcxaAZY8u0BOiHgWdwbIP5DiVztG fZjVsy5YxqOewPh5wXw0O5eN+5VWUGqhh187Z9Dh/jZXzNg7160DyvRcP7+4BvGYIGtU 4J//kvuJrdgdrs515YCFdbQS9cej2sJUny2eFERVEvYXt6gcivIIIFdfkdtMXiY4JmA6 Exkg== X-Gm-Message-State: AOAM533W4Et8XVgwvRRWdNkvTQa4LvePXsCwr+KDdEyMXEjfvMq1105P 8s8ZH8DuAfKndeJ+QF1vPxGqXYArX0GgVA== X-Received: by 2002:a5d:59af:: with SMTP id p15mr3310499wrr.488.1644320399960; Tue, 08 Feb 2022 03:39:59 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.39.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:39:59 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 15/39] arm: tcg: Adhere to SMCCC 1.3 section 5.2 Date: Tue, 8 Feb 2022 11:39:24 +0000 Message-Id: <20220208113948.3217356-16-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42c (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" The SMCCC 1.3 spec section 5.2 says The Unknown SMC Function Identifier is a sign-extended value of (-1) that is returned in the R0, W0 or X0 registers. An implementation must return this error code when it receives: * An SMC or HVC call with an unknown Function Identifier * An SMC or HVC call for a removed Function Identifier * An SMC64/HVC64 call from AArch32 state To comply with these statements, let's always return -1 when we encounter an unknown HVC or SMC call. [PMM: This is a reinstatement of commit 9fcd15b9193e819b, previously reverted in commit 4825eaae4fdd56fba0f; we can do this now that we have arranged for all the affected board models to not enable the PSCI emulation if they are running guest code at EL3. This avoids the regressions that caused us to revert the change for 7.0.] Signed-off-by: Alexander Graf Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Edgar E. Iglesias Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- target/arm/psci.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/target/arm/psci.c b/target/arm/psci.c index 6709e280133..b279c0b9a45 100644 --- a/target/arm/psci.c +++ b/target/arm/psci.c @@ -27,15 +27,13 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type) { - /* Return true if the r0/x0 value indicates a PSCI call and - * the exception type matches the configured PSCI conduit. This is - * called before the SMC/HVC instruction is executed, to decide whether - * we should treat it as a PSCI call or with the architecturally + /* + * Return true if the exception type matches the configured PSCI conduit. + * This is called before the SMC/HVC instruction is executed, to decide + * whether we should treat it as a PSCI call or with the architecturally * defined behaviour for an SMC or HVC (which might be UNDEF or trap * to EL2 or to EL3). */ - CPUARMState *env = &cpu->env; - uint64_t param = is_a64(env) ? env->xregs[0] : env->regs[0]; switch (excp_type) { case EXCP_HVC: @@ -52,27 +50,7 @@ bool arm_is_psci_call(ARMCPU *cpu, int excp_type) return false; } - switch (param) { - case QEMU_PSCI_0_2_FN_PSCI_VERSION: - case QEMU_PSCI_0_2_FN_MIGRATE_INFO_TYPE: - case QEMU_PSCI_0_2_FN_AFFINITY_INFO: - case QEMU_PSCI_0_2_FN64_AFFINITY_INFO: - case QEMU_PSCI_0_2_FN_SYSTEM_RESET: - case QEMU_PSCI_0_2_FN_SYSTEM_OFF: - case QEMU_PSCI_0_1_FN_CPU_ON: - case QEMU_PSCI_0_2_FN_CPU_ON: - case QEMU_PSCI_0_2_FN64_CPU_ON: - case QEMU_PSCI_0_1_FN_CPU_OFF: - case QEMU_PSCI_0_2_FN_CPU_OFF: - case QEMU_PSCI_0_1_FN_CPU_SUSPEND: - case QEMU_PSCI_0_2_FN_CPU_SUSPEND: - case QEMU_PSCI_0_2_FN64_CPU_SUSPEND: - case QEMU_PSCI_0_1_FN_MIGRATE: - case QEMU_PSCI_0_2_FN_MIGRATE: - return true; - default: - return false; - } + return true; } void arm_handle_psci_call(ARMCPU *cpu) @@ -194,10 +172,9 @@ void arm_handle_psci_call(ARMCPU *cpu) break; case QEMU_PSCI_0_1_FN_MIGRATE: case QEMU_PSCI_0_2_FN_MIGRATE: + default: ret = QEMU_PSCI_RET_NOT_SUPPORTED; break; - default: - g_assert_not_reached(); } err: From patchwork Tue Feb 8 11:39:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540774 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp476335imo; Tue, 8 Feb 2022 05:09:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGCazxF+jG7z4ifbbLHGiBOvFaWPp4u5pZPvB0xx1yz13dXv+4H/EJtjC4ekUlIEVfFwtf X-Received: by 2002:a05:6e02:160b:: with SMTP id t11mr2265822ilu.75.1644325787142; Tue, 08 Feb 2022 05:09:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644325787; cv=none; d=google.com; s=arc-20160816; b=Ob7imPNjk6my/jDklhqpvl938pRbWxvIaBIOHJ69mkrrGLabXdlzAXRCNUW45LpNY1 /NjLiLVDQgoSshIa7DVyu+L/q4ghXUf8V+k2za+MaDSFMP1lq/UaUsz10obIbS3XKkPZ L+xcQr6fwOopl43a3TAlqQw2pfO0aIaFYyMWG14yu28SgZIOJVjFLEWzXBgUXhvHfNXq zlvcIFohlbUF7dgafF3nT2LXxBxUji3x0X6hRh1klblg4fExHOvdFQc/irlM51G46NsT IeWuL2X+mre+L38u7gZuCaO1b99ShXVj2f3o8h07QdafvTb5QmS50Ki7MMAZPN2VQ4YV qyKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=QtabcHuqRoobl9uCmQRJITCYrON5FJXP9MgJHRnT3j0=; b=LN8wFX3ChixsqirT965N6ET7RcBJe59KawD19zhnk3vjKgPalLA6dNdstS7kA0jfYz 3RZdmmlDn4XeSeQ/iHCBIBGZacL+KtNJa9Iq3hzaVQpK37IpsMyCPYF1WNLvLSagzxJE RN922laKZzT+6biQ+l5g2FCAiuC7Rz5wIzUsh14vkrNs4Mau6OcNXvSu/BktGoOQ15S6 ABoDfaw/qrYdMbBIkIHzQtduqhR9P63vROz4ZpgYP7QoZaegGjjXDjZdqeg4jIgzeAhA cP8lcpQV7siVKwW0T9iE6Apqcg3DeObOaRihtYNZAw0PZDzhOo2gqQ5/Ql5d1TVOGyIl /JpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="qe/HDIvj"; 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=pass (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 q4si5998385iow.53.2022.02.08.05.09.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:09:47 -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=pass header.i=@linaro.org header.s=google header.b="qe/HDIvj"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQFe-0003Hi-Jm for patch@linaro.org; Tue, 08 Feb 2022 08:09:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqt-0000lC-Q9 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:08 -0500 Received: from [2a00:1450:4864:20::42d] (port=38564 helo=mail-wr1-x42d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqn-00026Q-Sv for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:05 -0500 Received: by mail-wr1-x42d.google.com with SMTP id s10so27592484wra.5 for ; Tue, 08 Feb 2022 03:40:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=QtabcHuqRoobl9uCmQRJITCYrON5FJXP9MgJHRnT3j0=; b=qe/HDIvjGrCeMw6hL0Wq3CiTjiyzPTO103Y2m4txq/9ZH5P6kQ1v/Av6sM9veSutx9 hRb/uQeooj44SuPdGz4h2xCuZrFuuhSM0IOE3pBmqo2OcUBzO184VKhxBfP9xjVbz8Hv WWTUNPJhknt4xr4T2DnBjDnJdGprDk/eOoCLmWoi+IrypbHAUMnCzGwoxLWfalHlul4w BpiMwy284RhtAizRyAtdPNFTq9QvDJMmkByOdpV3DooGeg6xBVQl8tJ4+qRyQqq9D/4D pSxmIT7ru8sQHRZ+H2/9bj91upwmecDZuhUiOXQNrc/sRQpHT9ehFcmX36+L8gv1aS76 3TFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QtabcHuqRoobl9uCmQRJITCYrON5FJXP9MgJHRnT3j0=; b=M2PVJGBSDi1AG7a4kVq9mFRXxuJ4wH7+OUeCGlX2u+LnBLPsAZ/BQskUz9SLhhUSFw qdBoiZqBV9AyOWj3VgAKxr2idZ8cL0+L4yMwAQXHxUSEYHxN1si57UufZYOo+W7Dhnz5 4B68Biek7J5EpPU+eCPU/zsYEvvjhhNMu5Fqa5ymHHLTOqFxIpKhkm8wAakIHZjuiwxA WOfIfsyI9WqCk8Rm2ChkILEzENA+tLNIUQNogZtw3WEVPmpugQnCQxf7DCB3CrMCM7Ch ld6H9OyQBdCHmU++J5GWegbWcnW22xM3zMd3UQCYpJUNgixvNHlDqkOt1b9Pn9z6qz/y uAIA== X-Gm-Message-State: AOAM533AxFGTExUcr7qEU0SdD4r2Oy+ars6Pw07f7H4nCMioSmNYV66L zF0h1WPHT0i0b1kQV5X+V1/mr5x1qAjftQ== X-Received: by 2002:adf:fb05:: with SMTP id c5mr3245150wrr.220.1644320400540; Tue, 08 Feb 2022 03:40:00 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:00 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 16/39] hw/arm/highbank: Drop use of secure_board_setup Date: Tue, 8 Feb 2022 11:39:25 +0000 Message-Id: <20220208113948.3217356-17-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42d (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Guest code on highbank may make non-PSCI SMC calls in order to enable/disable the L2x0 cache controller (see the Linux kernel's arch/arm/mach-highbank/highbank.c highbank_l2c310_write_sec() function). The ABI for this is documented in kernel commit 8e56130dcb as being borrowed from the OMAP44xx ROM. The OMAP44xx TRM documents this function ID as having no return value and potentially trashing all guest registers except SP and PC. For QEMU's purposes (where our L2x0 model is a stub and enabling or disabling it doesn't affect the guest behaviour) a simple "do nothing" SMC is fine. We currently implement this NOP behaviour using a little bit of Secure code we run before jumping to the guest kernel, which is written by arm_write_secure_board_setup_dummy_smc(). The code sets up a set of Secure vectors where the SMC entry point returns without doing anything. Now that the PSCI SMC emulation handles all SMC calls (setting r0 to an error code if the input r0 function identifier is not recognized), we can use that default behaviour as sufficient for the highbank cache controller call. (Because the guest code assumes r0 has no interesting value on exit it doesn't matter that we set it to the error code). We can therefore delete the highbank board code that sets secure_board_setup to true and writes the secure-code bootstub. (Note that because the OMAP44xx ABI puts function-identifiers in r12 and PSCI uses r0, we only avoid a clash because Linux's code happens to put the function-identifier in both registers. But this is true also when the kernel is running on real firmware that implements both ABIs as far as I can see.) This change fixes in passing booting on the 'midway' board model, which has been completely broken since we added support for Hyp mode to the Cortex-A15 CPU. When we did that boot.c was made to start running the guest code in Hyp mode; this includes the board_setup hook, which instantly UNDEFs because the NSACR is not accessible from Hyp. (Put another way, we never made the secure_board_setup hook support cope with Hyp mode.) Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-12-peter.maydell@linaro.org --- hw/arm/highbank.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c index 048f8550cb9..a21afd178d1 100644 --- a/hw/arm/highbank.c +++ b/hw/arm/highbank.c @@ -48,12 +48,6 @@ /* Board init. */ -static void hb_write_board_setup(ARMCPU *cpu, - const struct arm_boot_info *info) -{ - arm_write_secure_board_setup_dummy_smc(cpu, info, MVBAR_ADDR); -} - static void hb_write_secondary(ARMCPU *cpu, const struct arm_boot_info *info) { int n; @@ -389,8 +383,6 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id) highbank_binfo.write_secondary_boot = hb_write_secondary; highbank_binfo.secondary_cpu_reset_hook = hb_reset_secondary; highbank_binfo.board_setup_addr = BOARD_SETUP_ADDR; - highbank_binfo.write_board_setup = hb_write_board_setup; - highbank_binfo.secure_board_setup = true; highbank_binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC; arm_load_kernel(ARM_CPU(first_cpu), machine, &highbank_binfo); From patchwork Tue Feb 8 11:39:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540783 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp501706imo; Tue, 8 Feb 2022 05:46:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwo2hIGAUdu0WV3lYIHmJ7EV+0lZSWApabduHOb6sJrL2x8P3afWXhL6fDz93JzUzyYPBbC X-Received: by 2002:a25:c483:: with SMTP id u125mr4772987ybf.302.1644328014146; Tue, 08 Feb 2022 05:46:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644328014; cv=none; d=google.com; s=arc-20160816; b=HuvWkN+mTycVoyE0aChUGuJddQdWPU4Cps9XRT7xRkNNykl2O8OZtPRBwK0aiUu2qu fFAgaX+soI5F0+P07hBJSmqTtSfF2Izwn4ZJQSyEX7M47PPodDkL7f4DScJm7WF8dK5d 653+iGRyR/zbPcb4u32XlzBrhB4XhD/GggvuMPmI/FszKROfZwIe+rV3S4BHRPHD91Xl 789MCtpY4MmoKYRpgQcELRYMkpTTmhlfwvRJQ5VQv71aZr9vSbyFIgB/qdM1CQOxNVda 9422Jtx+WAWlXNShCTYz89lVvb6Q3WWniO88qRaQEmXLDSLY0eT+BfSNjnJ1QG+aP45Y 4bnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=17laaPJRMH9FCMUGpQ5IzmJ4dX79Qam+3Hyao1VjYHY=; b=r8AENewf+oAyfuqUmGxelAy6Umq6RRIQePlouVeCmY/4bIBs+KOFZh++iB2qcAeLYj bHIvZV63bPNNLKGtGcRiJYp2hAe7h7/vqGJIhaARuTc3BacIqaex0kDMOlx8/ihI1jz1 teg4uH//PECi23qpO5YgdPep7Zz8+gDDBDO+2j26/AxuU66qXuJ2ttUesD7Ve2FasccC tDAS+yi4WhgRRETt9FpPeFUViSwDWJyyzLAocqpTz0IkMOOZTJUCfGJ411NCEVV16npx XkNXThl/7Z7vvnF7fHlqXqPU5GUkC4FiBaFRycrV/nQHaM9OgCpPtxC8C1ii+oq4PyMp 4ftA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="H/ycfy3+"; 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=pass (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 e68si3834782ywa.382.2022.02.08.05.46.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:46:54 -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=pass header.i=@linaro.org header.s=google header.b="H/ycfy3+"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQpZ-0002zz-JK for patch@linaro.org; Tue, 08 Feb 2022 08:46:53 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqt-0000l9-PF for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:08 -0500 Received: from [2a00:1450:4864:20::432] (port=45055 helo=mail-wr1-x432.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqo-00026n-Ht for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:04 -0500 Received: by mail-wr1-x432.google.com with SMTP id k18so30169617wrg.11 for ; Tue, 08 Feb 2022 03:40:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=17laaPJRMH9FCMUGpQ5IzmJ4dX79Qam+3Hyao1VjYHY=; b=H/ycfy3+lPaqcbWJlZrKN0UBsqjewpjA6CZ00aaYncOawnU9ZAvLFi//B3DfMEBExR u1n+vHB1ET8c3+ewnh79tGEdnSNCso7wUGB8DaVv3bwKPyKxHbP5xVo9rczExbp4gkGG w5MZLR5kH4KLy1yS1G/G7Se1ulqD7ZxDKj+tbtvuPWj6jgV8MWN8d4ZrtnCY24EUvLPm 2ozpiKw/gch4oz+i1G5WziUj4hTdehPMwB8GLH7OWv6YjBIDugBJqg6fvLqNpT+pYLgr Cvo5KpWuvxGh8r5hqqKqw4vstJ6HErkCN8Ly16OuxxqXJttbDWeT1KgFIMMEGAKv0CSb rbbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=17laaPJRMH9FCMUGpQ5IzmJ4dX79Qam+3Hyao1VjYHY=; b=cVdqEWFDjdXFy1YSJlAT3nxOuf93fPZ+CcJXB9PcdAiZ1XjWmsxCdukFlqAF94naFR M8zl/xQgLrXFFh4u69/OjCJNESsLUjFfUX1+VbWraUAs4QV0TBY3Mi6MN7IlCQkS3kgG jEmZ2Vl+52Za86ms0peFyodKsEcP3o5Lvjh8rVg2zo3R0HHFpGy3PC19DfAtUzdiwpMg VecanlQf0hCvnzeUBeHSyj02c9KkakK6lhCUqvx2QtNuwNbWZfm7LnAZSuNCJLGpOhoO 6sJvLXYqnT0STvmfimSEF/2yGPceg/xy74axq4+ZdJtZh8MnMFASwTLpfKeLdCZkgz26 J4Pw== X-Gm-Message-State: AOAM533GF9wABBqpDA02hQCOhjF2TCi0WzlZCushYN7GCiwWdoUHtMte UFGb2aHx5f7N4kFzIGlWl78fxruYJra5kQ== X-Received: by 2002:a5d:4706:: with SMTP id y6mr3246539wrq.331.1644320401126; Tue, 08 Feb 2022 03:40:01 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:00 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 17/39] hw/arm/boot: Prevent setting both psci_conduit and secure_board_setup Date: Tue, 8 Feb 2022 11:39:26 +0000 Message-Id: <20220208113948.3217356-18-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::432 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Now that we have dealt with the one special case (highbank) that needed to set both psci_conduit and secure_board_setup, we don't need to allow that combination any more. It doesn't make sense in general, so use an assertion to ensure we don't add new boards that do it by accident without thinking through the consequences. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-13-peter.maydell@linaro.org --- hw/arm/boot.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 327e449f831..0424c178305 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -1339,6 +1339,16 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) * supported exception level or in a lower one. */ + /* + * If PSCI is enabled, then SMC calls all go to the PSCI handler and + * are never emulated to trap into guest code. It therefore does not + * make sense for the board to have a setup code fragment that runs + * in Secure, because this will probably need to itself issue an SMC of some + * kind as part of its operation. + */ + assert(info->psci_conduit == QEMU_PSCI_CONDUIT_DISABLED || + !info->secure_board_setup); + /* Boot into highest supported EL ... */ if (arm_feature(env, ARM_FEATURE_EL3)) { boot_el = 3; From patchwork Tue Feb 8 11:39:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540777 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp483431imo; Tue, 8 Feb 2022 05:19:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwztCw+Yp6dwzDRjmiTV80A4Z4U+FjVWUfWhpogNoPzFbvIT3mVyBrzYU6fUPHGP2un47w+ X-Received: by 2002:a25:8c8e:: with SMTP id m14mr4584870ybl.159.1644326371396; Tue, 08 Feb 2022 05:19:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644326371; cv=none; d=google.com; s=arc-20160816; b=KZa3sw9uW0qZ6BFvi/59wiSgw3hNKpvMpooAWNdVvJDFL6Cdv+Bqz3cKR7rSfAU+zZ R7AlbLDE0ua3hQgojsU4iB903l+Idh89mQkYm52yg18I2OBGjc5kT/Nd4RNR/+W/I2gt XhtMZYuVfl58eHfDI9+yUHL8CGh2u5QZ9xo26qFM9ZSCuvLebOzakEr4mYuW6hhZChgd IJIMdfv7xDKbAghYOSaT6rRxhdK0T5p6HlFBdiOFk21iHEbmuVrG6hLFkHGjbRKMUQws 0+NkoB6c4uMPYwim4xg9Po0/kVeI9NH1Zgm5iCWduRQX+yCdLF0McJxGNWq9rmHVvzB3 I37A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=cC5mdKRuC+fKKjkTJ4bWT+06ilMknwtgKl7IQRoNk9g=; b=yhm1babCBHJbP2fN/qUapFseCyWjEJTlPY5OaT8DVkTM7wdBhD/TB2BgEDWJzXTwV9 itUo7chtzDtgysW5B0avzTWVN6VfDpgr6EJblfio4mjqR0Ij15aJMIYhJlhlz4Ma/YKw lgmWC2cEZaLoZfS0mOVXBH17szvaRk/tLcr0U7E7E9GFFJhiRVhUnZou3GcoCkrTxZoW LOHddmSFtR3dP8g7ubxdsUUJj9TV+B6+di7RZY2pvKqW0F2DY1B8Oa0HmEiA7pMxoYEN R/EznqFfFXkwtDqKbv4py0KXPCXE0a8Vy1dToB0OUCXxoV9SEOPKv1vrZusXEg+ilZFG If/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XEXEeCvh; 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=pass (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 b3si8006288ybg.388.2022.02.08.05.19.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:19: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=pass header.i=@linaro.org header.s=google header.b=XEXEeCvh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37810 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQP4-0001pG-TD for patch@linaro.org; Tue, 08 Feb 2022 08:19:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34860) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqw-0000pB-Ns for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:10 -0500 Received: from [2a00:1450:4864:20::32e] (port=43812 helo=mail-wm1-x32e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqt-00027O-00 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:09 -0500 Received: by mail-wm1-x32e.google.com with SMTP id k6-20020a05600c1c8600b003524656034cso1401518wms.2 for ; Tue, 08 Feb 2022 03:40:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=cC5mdKRuC+fKKjkTJ4bWT+06ilMknwtgKl7IQRoNk9g=; b=XEXEeCvhaaVM9HAPV764rxCW2t2bkkOpD73/Xya6JGlo3FTyRyxkxXhXTck5/RBqIA 3zU0fAuCnk7rnxArnoLS89LDvq4t9x3qWfQEoTbstT65Meh9l2Kp3xFzh9KLWnpAiVhq aHNE/u3AKpxPuSqx0RylrmQfMu/twQrfd2ZNqb7HaadYTWBf+OwUU+J39lqxNV34MrMB bUNIHtANopOBhsjFBp8qPhYpzRyQxOuFMf/B3fYYdzZNU2ibHfvG+gtep7lKcsjiX3rl OVwfRpTszZ/2bVDt31FmBYpw18u/nuGPqViABW9oLeGAzncdyKA/8alc7m+jHuynAjai 64gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cC5mdKRuC+fKKjkTJ4bWT+06ilMknwtgKl7IQRoNk9g=; b=FPP7nmqSnXeNvhhx81pjXYhOyOIKLyxABOQ17fFXhHoZFeWYq6Z4yPRI1JTK6+6MKf rW2J4SvoD7kcruh4JDJ1ERBhXBA3Y/At812ahaPQY48XH3LfWKrXz0Tt7bCBZJNh7a0s zR2YVkGlDwp5HY0m8hLLBTyG9C0ggiUExJ61rWo/8fKBBMUMGZvgpiZsLEAIWif7dLQl DezJWRGzRyAvv/eWnf7xFG+Zo1UtVeeyVDkCvY8707SzIVySirUyMyLlrRyxyD4p+cdJ VOlBXyt3bFhcqV2WLK9LG0/qWoIZBdjrUHLlJilBv2PFOt6ASTs+Xlsma6qQjELAeWoa l1jQ== X-Gm-Message-State: AOAM531rckwfavaDnwM30KKB0UTCAPSXj4xIR+53iJz98w6Z1fYf/IqZ 1gbBQBgTf/DqbUEILp7wN6ZJNtU4+JbknA== X-Received: by 2002:a05:600c:1ca8:: with SMTP id k40mr796897wms.62.1644320401775; Tue, 08 Feb 2022 03:40:01 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:01 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 18/39] hw/arm/boot: Don't write secondary boot stub if using PSCI Date: Tue, 8 Feb 2022 11:39:27 +0000 Message-Id: <20220208113948.3217356-19-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32e (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32e; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" If we're using PSCI emulation to start secondary CPUs, there is no point in writing the "secondary boot" stub code, because it will never be used -- secondary CPUs start powered-off, and when powered on are set to begin execution at the address specified by the guest's power-on PSCI call, not at the stub. Move the call to the hook that writes the secondary boot stub code so that we can do it only if we're starting a Linux kernel and not using PSCI. (None of the users of the hook care about the ordering of its call relative to anything else: they only use it to write a rom blob to guest memory.) Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-14-peter.maydell@linaro.org --- include/hw/arm/boot.h | 3 +++ hw/arm/boot.c | 35 ++++++++++++++++++++++++----------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/include/hw/arm/boot.h b/include/hw/arm/boot.h index 0bcb58babba..0cfc1c95c4e 100644 --- a/include/hw/arm/boot.h +++ b/include/hw/arm/boot.h @@ -70,6 +70,9 @@ struct arm_boot_info { * boot loader/boot ROM code, and secondary_cpu_reset_hook() should * perform any necessary CPU reset handling and set the PC for the * secondary CPUs to point at this boot blob. + * + * These hooks won't be called if secondary CPUs are booting via + * emulated PSCI (see psci_conduit below). */ void (*write_secondary_boot)(ARMCPU *cpu, const struct arm_boot_info *info); diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 0424c178305..184628ce564 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -804,7 +804,7 @@ static void do_cpu_reset(void *opaque) set_kernel_args(info, as); } } - } else { + } else if (info->secondary_cpu_reset_hook) { info->secondary_cpu_reset_hook(cpu, info); } } @@ -1030,13 +1030,6 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, elf_machine = EM_ARM; } - if (!info->secondary_cpu_reset_hook) { - info->secondary_cpu_reset_hook = default_reset_secondary; - } - if (!info->write_secondary_boot) { - info->write_secondary_boot = default_write_secondary; - } - if (info->nb_cpus == 0) info->nb_cpus = 1; @@ -1216,9 +1209,6 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, write_bootloader("bootloader", info->loader_start, primary_loader, fixupcontext, as); - if (info->nb_cpus > 1) { - info->write_secondary_boot(cpu, info); - } if (info->write_board_setup) { info->write_board_setup(cpu, info); } @@ -1385,6 +1375,29 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) } } + if (info->psci_conduit == QEMU_PSCI_CONDUIT_DISABLED && + info->is_linux && info->nb_cpus > 1) { + /* + * We're booting Linux but not using PSCI, so for SMP we need + * to write a custom secondary CPU boot loader stub, and arrange + * for the secondary CPU reset to make the accompanying initialization. + */ + if (!info->secondary_cpu_reset_hook) { + info->secondary_cpu_reset_hook = default_reset_secondary; + } + if (!info->write_secondary_boot) { + info->write_secondary_boot = default_write_secondary; + } + info->write_secondary_boot(cpu, info); + } else { + /* + * No secondary boot stub; don't use the reset hook that would + * have set the CPU up to call it + */ + info->write_secondary_boot = NULL; + info->secondary_cpu_reset_hook = NULL; + } + /* * arm_load_dtb() may add a PSCI node so it must be called after we have * decided whether to enable PSCI and set the psci-conduit CPU properties. From patchwork Tue Feb 8 11:39:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540797 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp554177imo; Tue, 8 Feb 2022 06:56:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyuE6GtMYJsWtau4z5NuXvez+hXHCyLiOQWnVSaWvc4d5WHS4M6OVTqa7SavrI5wTgdB454 X-Received: by 2002:a0d:e0c2:: with SMTP id j185mr5074128ywe.86.1644332161249; Tue, 08 Feb 2022 06:56:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644332161; cv=none; d=google.com; s=arc-20160816; b=g2DQNy/vQgFFx/ST13j4UrWOttEY8rH8RAjFKqaUsWJ5QpxXH9is4u5Nv+rXGDU3tb kcIPHbO77w2vTfbvY+s90PjQLGq8eNqPELC/w4VG27fs5/pJZe8L4DFnYp6ovsDnZHcA +1zsDEX9zSqDDHOiu7OP9fbEpVjUNiR1BR/FGWz6w2kjjAwCJg7ihlNMQ0HoowmoSkhz hSk9CF1mbRS8Red/ENBjKKJA7LEYF4Xh94aZX6iPhWx04unrf33rRTco0JsS5DZtsIGM +c747zrQmEPYW3pqeta/SEVFcMX+j6IFKBOXMLdhv/apbwDi+2ogYlcbhf40jPgobHEa 28Lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=7U9MMxjs5aOmUbpGxUkDHRsFOCc8L4YhvKF6hVVJTbc=; b=W4DtTS21/lVIpsiWDDMktJvabOGsVvlPxbTTaZxxdIaUnVFwek6fjGoxL7cgT2Tfh8 RdtfJVVD8GMWBOEVvKbseRyg38i8n4fUFfm1ldtNn7sdzwL8BkmBLRKn47WVtePcF0GD gS/noQJt6O2DLoDCd1cU3w6GJGyP4Lx5GFvpku1hQj/kYTU9BsvqEkmY9n4HMzFXTHeh ozxIcJYoqmguvJcNIX6xcFMOMxIdBbidINhLG5jnTFPIpn8IqF2mU/es+77hWqSCEQ4g j9I4Sr1kJHzAEAeaYd4Ik4GfzeITsZSueHPnxajIBaNU/PDGzlDEpiTdmiL5TRWe+DQ6 zZyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xyrDHvAT; 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=pass (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 p12si15701136ybu.805.2022.02.08.06.56.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:56:01 -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=pass header.i=@linaro.org header.s=google header.b=xyrDHvAT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37804 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHRuS-0004SR-Ns for patch@linaro.org; Tue, 08 Feb 2022 09:56:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-000166-4g for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:45 -0500 Received: from [2a00:1450:4864:20::431] (port=42892 helo=mail-wr1-x431.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqt-00028W-7L for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:23 -0500 Received: by mail-wr1-x431.google.com with SMTP id h6so11460998wrb.9 for ; Tue, 08 Feb 2022 03:40:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7U9MMxjs5aOmUbpGxUkDHRsFOCc8L4YhvKF6hVVJTbc=; b=xyrDHvATWOFIDFmyTHcMrGrVhqBc4piJqMb8pT/NJgOT5fKM/WkMTatkgqT6egn9uQ nMOv0HR5Qb8lfO5DmkfAUhkqiHLBunzGC78ZwctK+zMvDGWI+LVoQET2SZWbH/Pr02/h Ua0pv2r3E/BssqbjL6GSnSv8W/++kgW5bhLM+j1toYwImdTUJOt2h7p2vjrZCvBkiPp+ O/zakHETsy6SagyPuE+vC2rhZSBtZh5xKSafOtXQVrGuTNqs3N8G7OjKN5O6OWhge4qE pdX+S0x5Gjl/n8+UXdpMwYIr2Z6BoBO1yGsK2t3g4CAxXOFIZrK6HNJg7zCJVntfueWs a5Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7U9MMxjs5aOmUbpGxUkDHRsFOCc8L4YhvKF6hVVJTbc=; b=mXvxdhNzNjUl0n6fd2OLLFdsaA9vHAqRjjpaEE/GfBz6uehCn9myhgqJfal/rEf/au Ged5Qu3dJiuxh2wiSbgKlkj9p63IRe6EXiaosJv/lkGKZLxDdvjoYyvvWr/DfBSCIuah oYJDiTKBGWQACKg20qsSLp9gSyRW7XbOk7BtMJN7YbUvjUMba+SywrDHpvFjblLbBIkc 62Ap4gNPaiZ6cTaJ6yKzuAPjbc2JDhrqQpttFD7OqB8ucKR0yZ1TgBITsi30zu81O1qc SW31f2czS+9OJuRGmYQ9VCktmleyBHv9dGjlzrf4YGOeUTakm3Em+uYacFx0YgNtYaDN F8lA== X-Gm-Message-State: AOAM530hw4IuxfPa/jPeluUxSXS/26qvyubDCyaunMwK0V7yzCFPKQJq p1JiR88yUMlKmUPANaB6IzrtTrqEatN29Q== X-Received: by 2002:adf:fac8:: with SMTP id a8mr1525810wrs.330.1644320402451; Tue, 08 Feb 2022 03:40:02 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:02 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 19/39] hw/arm/highbank: Drop unused secondary boot stub code Date: Tue, 8 Feb 2022 11:39:28 +0000 Message-Id: <20220208113948.3217356-20-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::431 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" The highbank and midway board code includes boot-stub code for handling secondary CPU boot which keeps the secondaries in a pen until the primary writes to a known location with the address they should jump to. This code is never used, because the boards enable QEMU's PSCI emulation, so secondary CPUs are kept powered off until the PSCI call which turns them on, and then start execution from the address given by the guest in that PSCI call. Delete the unreachable code. (The code was wrong for midway in any case -- on the Cortex-A15 the GIC CPU interface registers are at a different offset from PERIPHBASE compared to the Cortex-A9, and the code baked-in the offsets for highbank's A9.) Note that this commit implicitly depends on the preceding "Don't write secondary boot stub if using PSCI" commit -- the default secondary-boot stub code overlaps with one of the highbank-specific bootcode rom blobs, so we must suppress the secondary-boot stub code entirely, not merely replace the highbank-specific version with the default. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-15-peter.maydell@linaro.org --- hw/arm/highbank.c | 56 ----------------------------------------------- 1 file changed, 56 deletions(-) diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c index a21afd178d1..da681b15708 100644 --- a/hw/arm/highbank.c +++ b/hw/arm/highbank.c @@ -48,60 +48,6 @@ /* Board init. */ -static void hb_write_secondary(ARMCPU *cpu, const struct arm_boot_info *info) -{ - int n; - uint32_t smpboot[] = { - 0xee100fb0, /* mrc p15, 0, r0, c0, c0, 5 - read current core id */ - 0xe210000f, /* ands r0, r0, #0x0f */ - 0xe3a03040, /* mov r3, #0x40 - jump address is 0x40 + 0x10 * core id */ - 0xe0830200, /* add r0, r3, r0, lsl #4 */ - 0xe59f2024, /* ldr r2, privbase */ - 0xe3a01001, /* mov r1, #1 */ - 0xe5821100, /* str r1, [r2, #256] - set GICC_CTLR.Enable */ - 0xe3a010ff, /* mov r1, #0xff */ - 0xe5821104, /* str r1, [r2, #260] - set GICC_PMR.Priority to 0xff */ - 0xf57ff04f, /* dsb */ - 0xe320f003, /* wfi */ - 0xe5901000, /* ldr r1, [r0] */ - 0xe1110001, /* tst r1, r1 */ - 0x0afffffb, /* beq */ - 0xe12fff11, /* bx r1 */ - MPCORE_PERIPHBASE /* privbase: MPCore peripheral base address. */ - }; - for (n = 0; n < ARRAY_SIZE(smpboot); n++) { - smpboot[n] = tswap32(smpboot[n]); - } - rom_add_blob_fixed_as("smpboot", smpboot, sizeof(smpboot), SMP_BOOT_ADDR, - arm_boot_address_space(cpu, info)); -} - -static void hb_reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info) -{ - CPUARMState *env = &cpu->env; - - switch (info->nb_cpus) { - case 4: - address_space_stl_notdirty(&address_space_memory, - SMP_BOOT_REG + 0x30, 0, - MEMTXATTRS_UNSPECIFIED, NULL); - /* fallthrough */ - case 3: - address_space_stl_notdirty(&address_space_memory, - SMP_BOOT_REG + 0x20, 0, - MEMTXATTRS_UNSPECIFIED, NULL); - /* fallthrough */ - case 2: - address_space_stl_notdirty(&address_space_memory, - SMP_BOOT_REG + 0x10, 0, - MEMTXATTRS_UNSPECIFIED, NULL); - env->regs[15] = SMP_BOOT_ADDR; - break; - default: - break; - } -} - #define NUM_REGS 0x200 static void hb_regs_write(void *opaque, hwaddr offset, uint64_t value, unsigned size) @@ -380,8 +326,6 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id) highbank_binfo.board_id = -1; highbank_binfo.nb_cpus = smp_cpus; highbank_binfo.loader_start = 0; - highbank_binfo.write_secondary_boot = hb_write_secondary; - highbank_binfo.secondary_cpu_reset_hook = hb_reset_secondary; highbank_binfo.board_setup_addr = BOARD_SETUP_ADDR; highbank_binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC; From patchwork Tue Feb 8 11:39:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540791 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp524144imo; Tue, 8 Feb 2022 06:15:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJw8Oyu1M35OVZTIKMiUxckucrsWFlsXNV0D83oY8aGvag8hfTOq9pDzVjPJRa1exUiR6wRQ X-Received: by 2002:a81:60d:: with SMTP id 13mr4703094ywg.71.1644329743938; Tue, 08 Feb 2022 06:15:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644329743; cv=none; d=google.com; s=arc-20160816; b=KGoIHWK834XPxpD05yZiQ00GVMG+dmI6Gvb3t6XFi0gLbv4ZwVWjoM2kY4MPg8Mb0Q SsANZbZCluYUuAJk38rE8a/SnG03J6OYce78vZYb1Oem+ANLXUt9YmS9bwqre6QqRZE9 rB9NRfmlvABe+aJBnotrF3dKtOfb6tl3O7T5K2hsuMT8Bt4j8/ie5j5IU42eYorAFKZQ GbzG/2gTcGbPeFqfXzrIM6V4SsaecNsWZmu+KqPPUQnott+mM5KpNRjIDr2W/iAXejOE VCllcf/Sq2WBz9tA0mWS1Fyz5spJ8/Qo4nq7nq/o6vgBP88jlcx65jVAXakzRwI5SIve mqrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=ZXF8obUqyYR5kOFy49wzmo9l3CSXJa/zlm1Q7Oqye/E=; b=YHYtRfsW+N7Qg+oFz1IE6DT8crSNQmX2OZ+lcToMPMm+oE/ss+KNuqxwkInLNfwZq0 1NCQjr5E34HBjEnZQEJTE3GfyPPECvsluOFLd0+Qc6EQVQiO/1GrnP2OzZsT3sKnH8aH yOkn2zJRGt5cBxu/sdeLl8clpnbQyvZkcUFR5ROLYu8LpVl79C26IU178S2gn24Fh2Ed Rb/2KeLu94eL6pM2/5XeHaF4RI4AUdskZvo5kqzLZWOAggCBcxFg/8kcSzmPBH9pmxKG S+d1BMcpyWXEjG8Cu9WUdmjKFqhd0Nm9wAP7byrJ18b3qoZSq9C83ZPXGg5qD7LJ3ev6 7ZJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="tdM6rMg/"; 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=pass (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 t2si10315843ywt.104.2022.02.08.06.15.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:15:43 -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=pass header.i=@linaro.org header.s=google header.b="tdM6rMg/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38860 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHRHT-0005PT-E4 for patch@linaro.org; Tue, 08 Feb 2022 09:15:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34872) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqx-0000rQ-E7 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:11 -0500 Received: from [2a00:1450:4864:20::333] (port=37680 helo=mail-wm1-x333.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqt-00029A-9Q for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:11 -0500 Received: by mail-wm1-x333.google.com with SMTP id l12-20020a7bc34c000000b003467c58cbdfso1120590wmj.2 for ; Tue, 08 Feb 2022 03:40:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZXF8obUqyYR5kOFy49wzmo9l3CSXJa/zlm1Q7Oqye/E=; b=tdM6rMg/RZAZKhEH+hh4BMZQgn0dNdMidj6jwN3bb5ip0r3iZi4d9NCTAUSOBEKVI4 sCfmTnZnRg1Q8j+FDN9b6oo/BWnbZegVTOv68Q0ulxBeGsC2BaTd7KaBIQhwRYaMtFzM jPy3H7h/+qZLsw4GZ38oALNusy8Fa+mmcF1mMcJNeymsj8CCFG37qzWYlIAzWa0b9gDI kA3QzPwJCRdXIci9sn6UZ5ENMYuQGfOcggya9ZlYdjVoyE5dL3UdGQG9xi5MDrJyF2or YCCgHOXWVayOeDfQnWEWGVJ2B0XGc876bU+JVHvlFXFC0XFEECgnoR1rruHKbO5EG5vT jdSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZXF8obUqyYR5kOFy49wzmo9l3CSXJa/zlm1Q7Oqye/E=; b=oWg6trlP54pnudo7rNskXcuMGGixV93Je+KH5X/9+VdXbpuVGlrms7bMZbnQ92oOOn lH/ZFX+zKgE3NsVe6STXXe3KqU3PERooghUziZAHfR+8potLMVMKP4EQQ0e8QqPMiFZI Uk2WAfRbmfrU4mRiuEKn96YtW7LiHgdk1WDploM3ohzRAfkkbm4C6E4LOjvgFkK5zwJG eKajzhNiUxboyuST0tYEjztTIO5SvEU5vcHBnfU5ZJZ+nSqNgc54pQ2gds+HlBIc1lOz G/IiIJePqRGy1q38jT94UmFfYB0ns2s11scn8ZWwwTyeX/9qK2GngZvGzzIgTH93bl14 9vHg== X-Gm-Message-State: AOAM531+UkerO4dsb9NGvfdnFM6BdX/kmmjJ3s1cRlxocAON0BproOIc SB35r7Taq8VvfZYw12KZ9X3ZduZPrqn7Sw== X-Received: by 2002:a05:600c:3b21:: with SMTP id m33mr763987wms.7.1644320403175; Tue, 08 Feb 2022 03:40:03 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:02 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 20/39] hw/arm/boot: Drop nb_cpus field from arm_boot_info Date: Tue, 8 Feb 2022 11:39:29 +0000 Message-Id: <20220208113948.3217356-21-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::333 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We use the arm_boot_info::nb_cpus field in only one place, and that place can easily get the number of CPUs locally rather than relying on the board code to have set the field correctly. (At least one board, xlnx-versal-virt, does not set the field despite having more than one CPU.) Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-16-peter.maydell@linaro.org --- include/hw/arm/boot.h | 1 - hw/arm/aspeed.c | 1 - hw/arm/boot.c | 7 +++---- hw/arm/exynos4_boards.c | 1 - hw/arm/highbank.c | 1 - hw/arm/imx25_pdk.c | 3 +-- hw/arm/kzm.c | 1 - hw/arm/mcimx6ul-evk.c | 1 - hw/arm/mcimx7d-sabre.c | 1 - hw/arm/npcm7xx.c | 3 --- hw/arm/orangepi.c | 4 +--- hw/arm/raspi.c | 1 - hw/arm/realview.c | 1 - hw/arm/sabrelite.c | 1 - hw/arm/sbsa-ref.c | 1 - hw/arm/vexpress.c | 1 - hw/arm/virt.c | 1 - hw/arm/xilinx_zynq.c | 1 - 18 files changed, 5 insertions(+), 26 deletions(-) diff --git a/include/hw/arm/boot.h b/include/hw/arm/boot.h index 0cfc1c95c4e..c7ebae156ec 100644 --- a/include/hw/arm/boot.h +++ b/include/hw/arm/boot.h @@ -56,7 +56,6 @@ struct arm_boot_info { hwaddr smp_loader_start; hwaddr smp_bootreg_addr; hwaddr gic_cpu_if_addr; - int nb_cpus; int board_id; /* ARM machines that support the ARM Security Extensions use this field to * control whether Linux is booted as secure(true) or non-secure(false). diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index cf20ae0db5e..d911dc904fb 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -431,7 +431,6 @@ static void aspeed_machine_init(MachineState *machine) aspeed_board_binfo.ram_size = machine->ram_size; aspeed_board_binfo.loader_start = sc->memmap[ASPEED_DEV_SDRAM]; - aspeed_board_binfo.nb_cpus = sc->num_cpus; if (amc->i2c_init) { amc->i2c_init(bmc); diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 184628ce564..b46f1fe889e 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -1030,9 +1030,6 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, elf_machine = EM_ARM; } - if (info->nb_cpus == 0) - info->nb_cpus = 1; - /* Assume that raw images are linux kernels, and ELF images are not. */ kernel_size = arm_load_elf(info, &elf_entry, &image_low_addr, &image_high_addr, elf_machine, as); @@ -1291,6 +1288,7 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) AddressSpace *as = arm_boot_address_space(cpu, info); int boot_el; CPUARMState *env = &cpu->env; + int nb_cpus = 0; /* * CPU objects (unlike devices) are not automatically reset on system @@ -1300,6 +1298,7 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) */ for (cs = first_cpu; cs; cs = CPU_NEXT(cs)) { qemu_register_reset(do_cpu_reset, ARM_CPU(cs)); + nb_cpus++; } /* @@ -1376,7 +1375,7 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) } if (info->psci_conduit == QEMU_PSCI_CONDUIT_DISABLED && - info->is_linux && info->nb_cpus > 1) { + info->is_linux && nb_cpus > 1) { /* * We're booting Linux but not using PSCI, so for SMP we need * to write a custom secondary CPU boot loader stub, and arrange diff --git a/hw/arm/exynos4_boards.c b/hw/arm/exynos4_boards.c index 35dd9875da1..ef5bcbc212c 100644 --- a/hw/arm/exynos4_boards.c +++ b/hw/arm/exynos4_boards.c @@ -67,7 +67,6 @@ static unsigned long exynos4_board_ram_size[EXYNOS4_NUM_OF_BOARDS] = { static struct arm_boot_info exynos4_board_binfo = { .loader_start = EXYNOS4210_BASE_BOOT_ADDR, .smp_loader_start = EXYNOS4210_SMP_BOOT_ADDR, - .nb_cpus = EXYNOS4210_NCPUS, .write_secondary_boot = exynos4210_write_secondary, }; diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c index da681b15708..f12aacea6b8 100644 --- a/hw/arm/highbank.c +++ b/hw/arm/highbank.c @@ -324,7 +324,6 @@ static void calxeda_init(MachineState *machine, enum cxmachines machine_id) * clear that the value is meaningless. */ highbank_binfo.board_id = -1; - highbank_binfo.nb_cpus = smp_cpus; highbank_binfo.loader_start = 0; highbank_binfo.board_setup_addr = BOARD_SETUP_ADDR; highbank_binfo.psci_conduit = QEMU_PSCI_CONDUIT_SMC; diff --git a/hw/arm/imx25_pdk.c b/hw/arm/imx25_pdk.c index 6dff0001633..b4f7f4e8a7f 100644 --- a/hw/arm/imx25_pdk.c +++ b/hw/arm/imx25_pdk.c @@ -114,8 +114,7 @@ static void imx25_pdk_init(MachineState *machine) imx25_pdk_binfo.ram_size = machine->ram_size; imx25_pdk_binfo.loader_start = FSL_IMX25_SDRAM0_ADDR; - imx25_pdk_binfo.board_id = 1771, - imx25_pdk_binfo.nb_cpus = 1; + imx25_pdk_binfo.board_id = 1771; for (i = 0; i < FSL_IMX25_NUM_ESDHCS; i++) { BusState *bus; diff --git a/hw/arm/kzm.c b/hw/arm/kzm.c index 39559c44c29..b1b281c9acb 100644 --- a/hw/arm/kzm.c +++ b/hw/arm/kzm.c @@ -124,7 +124,6 @@ static void kzm_init(MachineState *machine) } kzm_binfo.ram_size = machine->ram_size; - kzm_binfo.nb_cpus = 1; if (!qtest_enabled()) { arm_load_kernel(&s->soc.cpu, machine, &kzm_binfo); diff --git a/hw/arm/mcimx6ul-evk.c b/hw/arm/mcimx6ul-evk.c index 8131518426a..d83c3c380e8 100644 --- a/hw/arm/mcimx6ul-evk.c +++ b/hw/arm/mcimx6ul-evk.c @@ -34,7 +34,6 @@ static void mcimx6ul_evk_init(MachineState *machine) .loader_start = FSL_IMX6UL_MMDC_ADDR, .board_id = -1, .ram_size = machine->ram_size, - .nb_cpus = machine->smp.cpus, .psci_conduit = QEMU_PSCI_CONDUIT_SMC, }; diff --git a/hw/arm/mcimx7d-sabre.c b/hw/arm/mcimx7d-sabre.c index ba84fc21920..6182b15f190 100644 --- a/hw/arm/mcimx7d-sabre.c +++ b/hw/arm/mcimx7d-sabre.c @@ -36,7 +36,6 @@ static void mcimx7d_sabre_init(MachineState *machine) .loader_start = FSL_IMX7_MMDC_ADDR, .board_id = -1, .ram_size = machine->ram_size, - .nb_cpus = machine->smp.cpus, .psci_conduit = QEMU_PSCI_CONDUIT_SMC, }; diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c index 878c2208e07..d85cc027651 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -355,10 +355,7 @@ static struct arm_boot_info npcm7xx_binfo = { void npcm7xx_load_kernel(MachineState *machine, NPCM7xxState *soc) { - NPCM7xxClass *sc = NPCM7XX_GET_CLASS(soc); - npcm7xx_binfo.ram_size = machine->ram_size; - npcm7xx_binfo.nb_cpus = sc->num_cpus; arm_load_kernel(&soc->cpu[0], machine, &npcm7xx_binfo); } diff --git a/hw/arm/orangepi.c b/hw/arm/orangepi.c index 68fe9182414..3ace4748704 100644 --- a/hw/arm/orangepi.c +++ b/hw/arm/orangepi.c @@ -25,9 +25,7 @@ #include "hw/qdev-properties.h" #include "hw/arm/allwinner-h3.h" -static struct arm_boot_info orangepi_binfo = { - .nb_cpus = AW_H3_NUM_CPUS, -}; +static struct arm_boot_info orangepi_binfo; static void orangepi_init(MachineState *machine) { diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index b4dd6c1e99a..92d068d1f9d 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -204,7 +204,6 @@ static void setup_boot(MachineState *machine, RaspiProcessorId processor_id, s->binfo.board_id = MACH_TYPE_BCM2708; s->binfo.ram_size = ram_size; - s->binfo.nb_cpus = machine->smp.cpus; if (processor_id <= PROCESSOR_ID_BCM2836) { /* diff --git a/hw/arm/realview.c b/hw/arm/realview.c index ddc70b54a56..7b424e94a5f 100644 --- a/hw/arm/realview.c +++ b/hw/arm/realview.c @@ -363,7 +363,6 @@ static void realview_init(MachineState *machine, memory_region_add_subregion(sysmem, SMP_BOOT_ADDR, ram_hack); realview_binfo.ram_size = ram_size; - realview_binfo.nb_cpus = smp_cpus; realview_binfo.board_id = realview_board_id[board_type]; realview_binfo.loader_start = (board_type == BOARD_PB_A8 ? 0x70000000 : 0); arm_load_kernel(ARM_CPU(first_cpu), machine, &realview_binfo); diff --git a/hw/arm/sabrelite.c b/hw/arm/sabrelite.c index cce49aa25cf..41191245b81 100644 --- a/hw/arm/sabrelite.c +++ b/hw/arm/sabrelite.c @@ -93,7 +93,6 @@ static void sabrelite_init(MachineState *machine) } sabrelite_binfo.ram_size = machine->ram_size; - sabrelite_binfo.nb_cpus = machine->smp.cpus; sabrelite_binfo.secure_boot = true; sabrelite_binfo.write_secondary_boot = sabrelite_write_secondary; sabrelite_binfo.secondary_cpu_reset_hook = sabrelite_reset_secondary; diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c index dd944553f78..23874019639 100644 --- a/hw/arm/sbsa-ref.c +++ b/hw/arm/sbsa-ref.c @@ -776,7 +776,6 @@ static void sbsa_ref_init(MachineState *machine) create_secure_ec(secure_sysmem); sms->bootinfo.ram_size = machine->ram_size; - sms->bootinfo.nb_cpus = smp_cpus; sms->bootinfo.board_id = -1; sms->bootinfo.loader_start = sbsa_ref_memmap[SBSA_MEM].base; sms->bootinfo.get_dtb = sbsa_ref_dtb; diff --git a/hw/arm/vexpress.c b/hw/arm/vexpress.c index 3e99b7918ab..e1d1983ae65 100644 --- a/hw/arm/vexpress.c +++ b/hw/arm/vexpress.c @@ -708,7 +708,6 @@ static void vexpress_common_init(MachineState *machine) } daughterboard->bootinfo.ram_size = machine->ram_size; - daughterboard->bootinfo.nb_cpus = machine->smp.cpus; daughterboard->bootinfo.board_id = VEXPRESS_BOARD_ID; daughterboard->bootinfo.loader_start = daughterboard->loader_start; daughterboard->bootinfo.smp_loader_start = map[VE_SRAM]; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 398145a7180..46bf7ceddf3 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2229,7 +2229,6 @@ static void machvirt_init(MachineState *machine) } vms->bootinfo.ram_size = machine->ram_size; - vms->bootinfo.nb_cpus = smp_cpus; vms->bootinfo.board_id = -1; vms->bootinfo.loader_start = vms->memmap[VIRT_MEM].base; vms->bootinfo.get_dtb = machvirt_dtb; diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c index 50e7268396c..3190cc0b8db 100644 --- a/hw/arm/xilinx_zynq.c +++ b/hw/arm/xilinx_zynq.c @@ -343,7 +343,6 @@ static void zynq_init(MachineState *machine) sysbus_mmio_map(busdev, 0, 0xF8007000); zynq_binfo.ram_size = machine->ram_size; - zynq_binfo.nb_cpus = 1; zynq_binfo.board_id = 0xd32; zynq_binfo.loader_start = 0; zynq_binfo.board_setup_addr = BOARD_SETUP_ADDR; From patchwork Tue Feb 8 11:39:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540766 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp450505imo; Tue, 8 Feb 2022 04:32:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNQzx52m/iL1zrg3CUAS6B04whpocQxejzX7EZXdQL04riA5OmRPj7Pc6yGaOVp2dD01cs X-Received: by 2002:a81:3744:: with SMTP id e65mr4546182ywa.191.1644323528849; Tue, 08 Feb 2022 04:32:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644323528; cv=none; d=google.com; s=arc-20160816; b=tlCnrZyCN4XiEhy1jttx1Koyr4CNwIcujX8jAnF7+uPI7AoaT9OwpGhWJT4bZJZ6XK 3ek8FNPLaOr2PeA1SiUit7XHvhXRPP+vhB/uc5vSGGOQ+q86HXFPWp/4gKju3EDLjPfN LE5MI+qlnsCncwCFl017W9tHB/nZ0KSy1Mvj9ocsB90PZBNIqrmYmb5Q9x+aA4egSRiy YDmrpsfkPCWIU/FBPrNivU4lKdBsxrvXA6tNaNZGjxjCp0iCL46G66E38iAw0/pP1elt CJRQ+ybIqrJxwhTifRmxDeLfFW1HnpmRPCWX6tDzNoDvdURomyauY38bBJLn3ATy4MS/ gLTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=ihHWYxdE5z0CuYDIY4LqywVkWHM3vo8ypMEKSXKgPrs=; b=QmR0grCbPSSPePmF3Cxho//mL48O8+HICnLgEn3NnC1UxKm1PgKN1W5HURSiYSN2BG D6OdT8IoGK9S1Eik+uPYkQpDJHLQW35zu+iCHPLBsMOBZKqd+xOygRs97N0gAow+lzLA XMBaeI3OxLXXhGxBS/nCvIYwSzrFB4lXpwIZa6w20BMVIC5C4t7Z9wIIukjXbCuLfg97 tANF4smLg5SNwzWxfIS01h8mg0DvcNew7AKDo7Gc/cE/EpsTu/UG8qJH/gn+0y+P6dN1 g5U/gj/n7jZMKmuyx+QwpVuBTvvyfW7QgdlkVNF2mnXgB0caEPXzsT9SHgOs+ex9lfjS ptOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eQdoidTj; 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=pass (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 g27si3001766ybe.204.2022.02.08.04.32.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:32:08 -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=pass header.i=@linaro.org header.s=google header.b=eQdoidTj; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPfE-0000TF-AW for patch@linaro.org; Tue, 08 Feb 2022 07:32:08 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34960) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOr1-0000xS-PS for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:15 -0500 Received: from [2a00:1450:4864:20::42e] (port=45052 helo=mail-wr1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqt-00029D-9U for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:15 -0500 Received: by mail-wr1-x42e.google.com with SMTP id k18so30169848wrg.11 for ; Tue, 08 Feb 2022 03:40:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ihHWYxdE5z0CuYDIY4LqywVkWHM3vo8ypMEKSXKgPrs=; b=eQdoidTjv0eMbtL8olYadlxkO/2CEqarNGfWzrLtj7wicklk2cwhb/JcF4kfuj09fQ dKCi2E7QYz/jmmBeCx+1CItdBIHQ2UUEWYAVEl9X6YVdYRKAPhtBv9QoUOldh3zWfbe8 shLEeNu+zP35aR3WUOccsMX5lBZ8/p6u+BOBsNmfswYYXohxkrKwB1Zs/gmck2jPwW7I QMMohmhpnntI6HspAn/eq/KiNWP3zIuW5iUB9IiHYTyjxluzhO7R1Yp3uDK6l8rtvQuc FXqMBOnLm6LVcyq5sTcmjHrYKY8DGVe1/YJ+j/OKEyBd4WK+nMLB/Mnrkv8+BJHu67Zw Id6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ihHWYxdE5z0CuYDIY4LqywVkWHM3vo8ypMEKSXKgPrs=; b=MU6rsK5LDUdzBrDThXO99FIE30wNfpszP9bACsyxETC3qj3/3us0BOVZ7cN0TTp8D5 O58Nq4j+fPmhLgaabriVF1lCZOQezQaWLl/S1Wsx8Fr4svug7FqsRf+zR18pm2XmrWyY Fzx761wYPHo1e34wjDx//jEfndP6T+JgdiYlj6c3P+Tj4gbo6iVUVjS5QCyCX3cwKPAp 8FZzPNYyGOU4Y9OrqtaMK9roQFFgeNvRib2e9u1TwvKcNobYF2MrzI4EqxLHPs8X+GT7 UKhQqPyfvndGMBHwdvZKqWjfWCD6N3IeklKuCLnwSjAYMIrvNcz9/jp6ytVJs8HIUKSf SY8Q== X-Gm-Message-State: AOAM533XvdzAzmSm+VyICDeXs8XfEF5k3DLdbhW8CYF5NTbiXcGceNL9 RoK2kf9a1leLjjtna6V4y9cWPan1w+Diwg== X-Received: by 2002:adf:d1ed:: with SMTP id g13mr3198917wrd.477.1644320403727; Tue, 08 Feb 2022 03:40:03 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:03 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 21/39] hw/arm/boot: Drop existing dtb /psci node rather than retaining it Date: Tue, 8 Feb 2022 11:39:30 +0000 Message-Id: <20220208113948.3217356-22-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42e (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" If we're using PSCI emulation, we add a /psci node to the device tree we pass to the guest. At the moment, if the dtb already has a /psci node in it, we retain it, rather than replacing it. (This behaviour was added in commit c39770cd637765 in 2018.) This is a problem if the existing node doesn't match our PSCI emulation. In particular, it might specify the wrong method (HVC vs SMC), or wrong function IDs for cpu_suspend/cpu_off/etc, in which case the guest will not get the behaviour it wants when it makes PSCI calls. An example of this is trying to boot the highbank or midway board models using the device tree supplied in the kernel sources: this device tree includes a /psci node that specifies function IDs that don't match the (PSCI 0.2 compliant) IDs that QEMU uses. The dtb cpu_suspend function ID happens to match the PSCI 0.2 cpu_off ID, so the guest hangs after booting when the kernel tries to idle the CPU and instead it gets turned off. Instead of retaining an existing /psci node, delete it entirely and replace it with a node whose properties match QEMU's PSCI emulation behaviour. This matches the way we handle /memory nodes, where we also delete any existing nodes and write in ones that match the way QEMU is going to behave. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Niek Linnenbank Tested-by: Edgar E. Iglesias Tested-by: Cédric Le Goater Tested-by: Niek Linnenbank Message-id: 20220127154639.2090164-17-peter.maydell@linaro.org --- hw/arm/boot.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index b46f1fe889e..b1e95978f26 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -478,12 +478,13 @@ static void fdt_add_psci_node(void *fdt) } /* - * If /psci node is present in provided DTB, assume that no fixup - * is necessary and all PSCI configuration should be taken as-is + * A pre-existing /psci node might specify function ID values + * that don't match QEMU's PSCI implementation. Delete the whole + * node and put our own in instead. */ rc = fdt_path_offset(fdt, "/psci"); if (rc >= 0) { - return; + qemu_fdt_nop_node(fdt, "/psci"); } qemu_fdt_add_subnode(fdt, "/psci"); From patchwork Tue Feb 8 11:39:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540780 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp490500imo; Tue, 8 Feb 2022 05:29:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJzK0efH0YeNEYmBGeh3iRehi7zcby8jzGAQYInOtcmlokCry7YrO9wBWJ371S92GdN5OgTt X-Received: by 2002:a25:4805:: with SMTP id v5mr4302175yba.258.1644326986458; Tue, 08 Feb 2022 05:29:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644326986; cv=none; d=google.com; s=arc-20160816; b=WRHERJTVTwg2On5okiLolPboyrEjmygqYGJGQnrvKT+9aqcADc1AoR5pmx9eZYa8yl XIWIdQtNzUpmmROPv5M9Es+ogWPVqQqOx/LkLv4lTo1U3Yz5iFOHXYQqJtxDJEogMheA jVT0Jikzs1BuEl0V9EBNUV1vLh91etG75tdYOh+lsIBrpjCPUhIbyd7fos+zUFJE13U+ O3e/kEeC8bhOkWCZylJLgxbRLKwUF409laC/VNxP0VXjwMsy8kkhjXm4Fm0BuzBw2Avf pRJS/VAM4K5FkPL/LBwWxWwbDmrhuVQYnvBIm38FejB2WGuI65PJMRKL75Z+Cy9VnSQq hrRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=R+U0WlmEp4qPr7iVHCi2HAdqUU7KtQ2aWLdMsCHpUvE=; b=ZCWZU7nNcWdHu7uSQMRVIk+ws7CJT9My6zl0tUisA2Zn8Qn90gF2EmNGsfEE9+BmUE +l/PG63nhZKZ3otVcSANEMXdbTY5VZ8Zh6E5WQNydsQK1dJYHc3z2fDXrMUTNdFhGvC0 1MtLndPECXVF6Gf/GD1h8I6SbCGjHrfcM9PiXSXcgt3W4BcjbeK1PvX1C1rDBbTizaca YESlRLhztXF2uPVA91Wt198INaPEv4Cx6yjOG5E8+gvg1IXJFa10iHkkq1mtQZuXdReT kasOVEl3ifXu8ocN4rd+X8mLkXFh5FcsnzGNpU52KwHY0IYnF+4hEr5aqZpupf6a7XjT EKzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YuLWtESZ; 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=pass (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 p71si6872213ybc.520.2022.02.08.05.29.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:29:46 -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=pass header.i=@linaro.org header.s=google header.b=YuLWtESZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQYx-000075-HE for patch@linaro.org; Tue, 08 Feb 2022 08:29:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34862) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqw-0000pT-R7 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:10 -0500 Received: from [2a00:1450:4864:20::42a] (port=37433 helo=mail-wr1-x42a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqt-00029I-8I for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:10 -0500 Received: by mail-wr1-x42a.google.com with SMTP id w11so30204436wra.4 for ; Tue, 08 Feb 2022 03:40:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=R+U0WlmEp4qPr7iVHCi2HAdqUU7KtQ2aWLdMsCHpUvE=; b=YuLWtESZ3JZAa3w0PmWcI0nb6zPuxQTusxeCnFRFKmhn7VJOO4LV9X5vKqvD4g3WhZ SWGFPTvBLhIzCeqXyRRy22ymcmb6w02F+ZhwuTqxrysHFVnRgsd1myXjopWP6WaxJFS3 6P5oAYf77uQPYIXIexmAjU2cikALOhRVBD9tElT9+t/9oGICxAbYhaz5dNmhRcVF5pXb yXWn3FAPr62ILFd1yPv3sg95+UYc7myZS9iBvesfY1WQa8UskRyFPjIskUStluTNSmcg eadIIqVqnZQytZLkkPdYQLXKS5a+2fqRSiPJWeIGFGLDXLWIZLKZvIzdPpHINQZxti+w iW2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R+U0WlmEp4qPr7iVHCi2HAdqUU7KtQ2aWLdMsCHpUvE=; b=SA+9irU141FbV3RvFBGsrXCenyGCNqGj7NQz+HI3UEWCvjXD764vu34ROhFAYmA+im A7568OGXrFweu3KrfcS6qLHiHn0Iho2wfMxEF7/KHp969K1P2WQCtVWFPrd8FJkgFfMC 3OpIEguB4a42JxdkYzcQG7/ZinlGCIcOkHfOsHFi65yI7H0iwFtHcVtlVWegsQgLJeL8 SBgf2C/HycT9Ytz6DktdaCuSogZo7bd1NoEqy12J3mfvIwuy6lbB+6BvvOJJk4yXiiro k6J8yXsptldGTWCvaaylUtdvlhLTVXHuq98YqJ3ZGYB2eOHyxBSAjVOyLYgtbunpQYm1 2Ybw== X-Gm-Message-State: AOAM533LzbbsYJyrde+7LV0JXqaWEaSA1gLzSITG1+clo7N+QP/Qbr0M En1JyIgLRt0XjmuAO9yHDq0DnEDyxpvLzQ== X-Received: by 2002:a5d:6452:: with SMTP id d18mr3125089wrw.493.1644320404324; Tue, 08 Feb 2022 03:40:04 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:04 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 22/39] hw/arm: versal-virt: Always call arm_load_kernel() Date: Tue, 8 Feb 2022 11:39:31 +0000 Message-Id: <20220208113948.3217356-23-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42a (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: "Edgar E. Iglesias" Always call arm_load_kernel() regardless of kernel_filename being set. This is needed because arm_load_kernel() sets up reset for the CPUs. Fixes: 6f16da53ff (hw/arm: versal: Add a virtual Xilinx Versal board) Reported-by: Peter Maydell Signed-off-by: Edgar E. Iglesias Message-id: 20220130110313.4045351-2-edgar.iglesias@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/arm/xlnx-versal-virt.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c index ef3231cdbb3..7c7baff8b7f 100644 --- a/hw/arm/xlnx-versal-virt.c +++ b/hw/arm/xlnx-versal-virt.c @@ -681,20 +681,13 @@ static void versal_virt_init(MachineState *machine) s->binfo.get_dtb = versal_virt_get_dtb; s->binfo.modify_dtb = versal_virt_modify_dtb; s->binfo.psci_conduit = psci_conduit; - if (machine->kernel_filename) { - arm_load_kernel(&s->soc.fpd.apu.cpu[0], machine, &s->binfo); - } else { - AddressSpace *as = arm_boot_address_space(&s->soc.fpd.apu.cpu[0], - &s->binfo); + if (!machine->kernel_filename) { /* Some boot-loaders (e.g u-boot) don't like blobs at address 0 (NULL). * Offset things by 4K. */ s->binfo.loader_start = 0x1000; s->binfo.dtb_limit = 0x1000000; - if (arm_load_dtb(s->binfo.loader_start, - &s->binfo, s->binfo.dtb_limit, as, machine) < 0) { - exit(EXIT_FAILURE); - } } + arm_load_kernel(&s->soc.fpd.apu.cpu[0], machine, &s->binfo); for (i = 0; i < XLNX_VERSAL_NUM_OSPI_FLASH; i++) { BusState *spi_bus; From patchwork Tue Feb 8 11:39:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540767 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp451714imo; Tue, 8 Feb 2022 04:33:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyiHl5oXm3Jh/P80cb8tYih0c/m89tIr6j6gE6tixBixS1CSxYj2VqQ32xAHPxXt1pqYENL X-Received: by 2002:a25:b09f:: with SMTP id f31mr4191122ybj.406.1644323636577; Tue, 08 Feb 2022 04:33:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644323636; cv=none; d=google.com; s=arc-20160816; b=M8mRObomQnrAyAqFA/PnApUMLqREyzDiQhbeG8bx6rX42A67JdntsMYsjxplavQMTg iOPOMOVgmIx1cX7Wl4uKUFRjiR0qqCuhLSJpSD1o0v/KK+I7rKp/pgEH6SXzm7x4FZV2 KPh4vcEfY6klX1UhNmhZ9m0qcanp+ueidENVBbj6YF17Ol3O+2h6yyHPYt2FibXy1rDW hJNWLO3uEz9tJdU0QxvrzEgCOgKMGcpdXP1Xsdyo7ABPyu5Cr/BhIJuMKr0CFlj6t6zE GOugRV8xxXwKtgAK9y1x1w/CK+/4jHvMv+cSpsz3ChyHdKCnX/KyUoIy4SnBKhY7kN2P bG0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=BBV95CWsxDrWvVC9C6IsOCCdTEjqLMSargWjpZxMzYw=; b=TZ1FjED/F7OesyA6Nh0ScPmN7iWA27PEJwiCMCZupsVb+CS4v6+fY8uL0Ac69iaq5m I3pe3wAslGIaHDw5HzVWxjvKsxXOkIQHNtscm4ZlMP4tnjvIVOo7do+ctzbwn0obHvMa 6gYZOcNBjXT0wOOmbhYMdiSb8bulxRJq8PVEu6UNrtmLBke1ua7msoD3vPOsVAph+qJG +5XAdtYV6XT92uy5LwEggaQPv/kO1mX2AjE/3ffafHarW++/kLuGZ/dNNYtmbwSMjOEp ozgv3aBOtS0wbGtPA34ASkidwxfxUDuAj4C89druEx6JxBqZN/YDMY+6wccowmxqriTf 2O3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="X7/9h0bR"; 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=pass (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 w1si11511926ybu.271.2022.02.08.04.33.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:33:56 -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=pass header.i=@linaro.org header.s=google header.b="X7/9h0bR"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPgy-0001zi-3K for patch@linaro.org; Tue, 08 Feb 2022 07:33:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34858) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOqw-0000p7-Nj for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:10 -0500 Received: from [2a00:1450:4864:20::42e] (port=37437 helo=mail-wr1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqt-00029Q-80 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:08 -0500 Received: by mail-wr1-x42e.google.com with SMTP id w11so30204489wra.4 for ; Tue, 08 Feb 2022 03:40:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=BBV95CWsxDrWvVC9C6IsOCCdTEjqLMSargWjpZxMzYw=; b=X7/9h0bRBaQ+1muTp/W2It/S2Uspmx0PWoodWrnPntpDFCH/e/5iRhFjbTOwPxlcoj pq7WnadD1mbQuq1SLnDhBNhUcZoYm3bwAi1aouSDyurrUimuv+tSBBBm5KjZGW4d2Z21 LHZjFvETbVvNCZ3dwghjv02H2A3HiAXXHQiqocg+piiIiWtzvixW8dorGT+6/tLr0T/L QwVrsig5JL9DBNoHpytzUBkwwnM/PDA7j6W2nhQk+s4WPigXXzhIgkzh0eoFN2oEB03m pxBpMO6tq5Id3klbO4wBy+imN47TbmRfUB/9+AyOKL6lYSzGlYl70nCGBosbtsKDxAta xGLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BBV95CWsxDrWvVC9C6IsOCCdTEjqLMSargWjpZxMzYw=; b=TIdH362/RrQhwI7E4NWFUJ6xx8EH9TFVCLOcSR1vrjdM19949RRI5Nx+bvVtUAFTmz AC4OM05CJt3cETIXGaD7fK9q9KAyUSs25ELZQV/nv0LgYatC/Lz5yBAyKDwQZGSc8Mdd sWm33macBT70JlK48UcbjkBvMqVmH9S+wvfkJpF+H4bYTU5rolnY/Tn8yoAD8VQ4uktD rMoGL8P3K0qdVq1143HzMpTnrj2gMVcWhbZT4Yt0gBj0HOxw9mMAgqoxYJDa2m2Mdcpg MmsJBtikmrNMkno88Al8F55FYFWhHabM828E9FSGlZ7iI0rHMk6AaCWHcxgRKpnv/PN8 iVmg== X-Gm-Message-State: AOAM532ol0kmKF6or0TCcP10F10xVJvE+fzeaT4eBHrstU7B+xwAN8zl 1UbqozqpVaaShpkfkv21hMSfwqBYhoe/lg== X-Received: by 2002:a05:6000:170c:: with SMTP id n12mr3304385wrc.380.1644320405087; Tue, 08 Feb 2022 03:40:05 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:04 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 23/39] arm: force flag recalculation when messing with DAIF Date: Tue, 8 Feb 2022 11:39:32 +0000 Message-Id: <20220208113948.3217356-24-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42e (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42e; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Alex Bennée The recently introduced debug tests in kvm-unit-tests exposed an error in our handling of singlestep cause by stale hflags. This is caught by --enable-debug-tcg when running the tests. Signed-off-by: Alex Bennée Reported-by: Andrew Jones Tested-by: Andrew Jones Reviewed-by: Richard Henderson Message-id: 20220202122353.457084-1-alex.bennee@linaro.org Signed-off-by: Peter Maydell --- target/arm/helper-a64.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c index d6a6fd73d96..7cf953b1e64 100644 --- a/target/arm/helper-a64.c +++ b/target/arm/helper-a64.c @@ -83,12 +83,14 @@ void HELPER(msr_i_daifset)(CPUARMState *env, uint32_t imm) { daif_check(env, 0x1e, imm, GETPC()); env->daif |= (imm << 6) & PSTATE_DAIF; + arm_rebuild_hflags(env); } void HELPER(msr_i_daifclear)(CPUARMState *env, uint32_t imm) { daif_check(env, 0x1f, imm, GETPC()); env->daif &= ~((imm << 6) & PSTATE_DAIF); + arm_rebuild_hflags(env); } /* Convert a softfloat float_relation_ (as returned by From patchwork Tue Feb 8 11:39:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540770 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp463737imo; Tue, 8 Feb 2022 04:52:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzVKsYTjtRLw6hNR6CVGbSa5o6n+T4GDU5Ho3QMsqvyW6ekgerTpKHujlE+mCUCFxQP/4KR X-Received: by 2002:a81:2f01:: with SMTP id v1mr4571041ywv.98.1644324776370; Tue, 08 Feb 2022 04:52:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644324776; cv=none; d=google.com; s=arc-20160816; b=TpuNXeiS5eJiRnkTyOv1eO2bshNzjUE65zSmrAp0IY3mTd/7Yjn3BHfo+cKn5ed2+U HIXGWdSheIGM9qS9bsDtIO/acsPyuXnpp2cHf05KI8y1eRpvJ9Pxkr9C9oU65VbUDVEd xuF5j0o/uKZta3m6HAvGvcbrLplPiVv20i/Xu8LYQSVEwDVrtm9/HJ2NGkgxSaVek0rQ dTT8sB18jsivFWrKYXYlZ0kRFNqOsuzKxXRdOG1/NlVvAMkJOo5gkLLAj1XvqDoQyGZJ ELNn3preBI0BS5DUT0MCfS+uDrv9yMQ8eNrY63MXlJ1ne9fPBD+YgimYBygu/tz3MxeO G8CQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=Jz4riheGOmiMeuNbjKDE7wXP/MlDdFoZj/oQ3PvSVLE=; b=z0gNTWHxIlhfMc7R2TO+WJS2OP+SVkETNLl5zM5g/X4W7iNOfjP7B3Mp6uljdeAzuj 0oGqdu76YrR+/9QO6zLi7daYzCcPlipkWijbw6BfWla+JKdwMN5KRZIeQPSHEU3EYman 8JcpZV42qd+4s9atm4lDwHinEKqKjh/GCDAg3xjqqtD4rl4xYJRzly5Ut4dr+WJdNnYD Dvis8J9LCdTZQ8Kk5KPt4j3nDN6+4FMvaMVoDV28mBONgxapSBoyLZJrnUsukdnSwFfM vMh5seARn4p8VMhA4I/sCKa6ToQ7jMfP7pxG4/bHLtk9SfH2x714KfcN4N2Kemo/6DHX U6ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xVzZ8UxQ; 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=pass (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 e82si5144699yba.53.2022.02.08.04.52.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:52:56 -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=pass header.i=@linaro.org header.s=google header.b=xVzZ8UxQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPzL-00086m-Qq for patch@linaro.org; Tue, 08 Feb 2022 07:52:55 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-000165-3v for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:45 -0500 Received: from [2a00:1450:4864:20::32d] (port=46706 helo=mail-wm1-x32d.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqt-00029U-9I for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:22 -0500 Received: by mail-wm1-x32d.google.com with SMTP id l67-20020a1c2546000000b00353951c3f62so1398076wml.5 for ; Tue, 08 Feb 2022 03:40:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Jz4riheGOmiMeuNbjKDE7wXP/MlDdFoZj/oQ3PvSVLE=; b=xVzZ8UxQDHTvE5e8M1Bl4tV9Za0lWk7Qu7aP4wFxlGRDLtWYct5BNkK9C+9zfdgyVF pEKuLLXo9iV+uZ8t7A/ZjFqvDVh7Oqkkrd4PCS4DR5JvG1D075IzPtE0PskOceKIJ+zE 7CNUuZEFfr/8yEfVUtVWC9dT/zcfyODq1o07xPzfjopRthOAI6DU5Z0W+jrOTp928Xvj r/Psuo1hObbdNolXPxDotZX4QRymmgtV9TOd0uYxa2D4HDYwGkxrYEiA5tlQ8zmdJQes XDl9KTSB618foenmEoj6FkUzKR7DHaQIhegMaUeoBpHBvHqhHyg3kVAw11HXi/nVXv5q V8hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Jz4riheGOmiMeuNbjKDE7wXP/MlDdFoZj/oQ3PvSVLE=; b=k88UabCXoPfhYGaAEO47l1i6djrubD1ZV27n6/mFNfON0FZaBar4aOBCx0zAszUdNl BtzraKf4Zinha4NYBS6dfIUUNIVqqxdjoIH83sO7omO8rCnzgbzPYN74hXuncsasS9Iq t3/QEIcuT7HUiLVVtjH0iOEl/erQ0DQ+aCFXxeLusV8VVD6y4Vn/cJ6N0w1j1CAQDQHi u/amjLwhEx2F74nzcZrls9OgoYeWo7NoF3tzUNkxnXDfbSrcFMEkyAARccZQ9nwo/OQD VUkEhFdU0rnaom1SLE744PdqlQ89WdqzFT89TC1/nB6BXQlEJnfzrUPpdFwZlLUKfcLT 3sSg== X-Gm-Message-State: AOAM533jTb/jBp7XDNh1yTO/0gLzrRZyroodH+XrsalsQLLUf5CdJ9Gi VtxA/gsNiMC6v8fnmZVMPxZoQhac42qfKA== X-Received: by 2002:a05:600c:210c:: with SMTP id u12mr806188wml.56.1644320405639; Tue, 08 Feb 2022 03:40:05 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:05 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 24/39] hw/timer/armv7m_systick: Update clock source before enabling timer Date: Tue, 8 Feb 2022 11:39:33 +0000 Message-Id: <20220208113948.3217356-25-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32d (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32d; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32d.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Richard Petri Starting the SysTick timer and changing the clock source a the same time will result in an error, if the previous clock period was zero. For exmaple, on the mps2-tz platforms, no refclk is present. Right after reset, the configured ptimer period is zero, and trying to enabling it will turn it off right away. E.g., code running on the platform setting SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | SysTick_CTRL_ENABLE_Msk; should change the clock source and enable the timer on real hardware, but resulted in an error in qemu. Signed-off-by: Richard Petri Reviewed-by: Peter Maydell Message-id: 20220201192650.289584-1-git@rpls.de Signed-off-by: Peter Maydell --- hw/timer/armv7m_systick.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c index 3bd951dd044..5dfe39afe36 100644 --- a/hw/timer/armv7m_systick.c +++ b/hw/timer/armv7m_systick.c @@ -149,6 +149,10 @@ static MemTxResult systick_write(void *opaque, hwaddr addr, s->control &= 0xfffffff8; s->control |= value & 7; + if ((oldval ^ value) & SYSTICK_CLKSOURCE) { + systick_set_period_from_clock(s); + } + if ((oldval ^ value) & SYSTICK_ENABLE) { if (value & SYSTICK_ENABLE) { ptimer_run(s->ptimer, 0); @@ -156,10 +160,6 @@ static MemTxResult systick_write(void *opaque, hwaddr addr, ptimer_stop(s->ptimer); } } - - if ((oldval ^ value) & SYSTICK_CLKSOURCE) { - systick_set_period_from_clock(s); - } ptimer_transaction_commit(s->ptimer); break; } From patchwork Tue Feb 8 11:39:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540782 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp495293imo; Tue, 8 Feb 2022 05:36:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyLaS9tIWBUFNm8sp6gapdTwPQ9MB/XvcaCSZmN87cGixS9C59qdQYOaQX7qNoT9PE5AAdZ X-Received: by 2002:a25:1106:: with SMTP id 6mr4404527ybr.459.1644327399775; Tue, 08 Feb 2022 05:36:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644327399; cv=none; d=google.com; s=arc-20160816; b=sb7BQJavRRjA/HSWSKs/NNMyVVKBg13giH/23kc1h/RB9LaANXmbcqvAfZieu1NOw+ vT4SKjXufMm4XmtyWROPVNKyPKEWPcpentv4nLZGB+DAtHFMNM3rKp0p/eQxuqIJS1Dp K7qepGXI1Fu7Ds+0LOxNQFeN5KnGc7wMIu9OkYnvtadCGpYCJI+fGLSoZOd2e33KfsFb u+WZbso6wRFmbVOcIo0q9XjhJouZ8/l4LcLkZ8EYNQx8Bv9b+WYXHdAipdDnME1OrWTt V7aJzyy8rphySGfvNtYATMyOdZJqGFOYsmPMDiRRHPx+Yx+bgcDchW0185p4cc3eC5Zj 3Wcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=ZU4Qt8dF8HrU5xx9gXHm/kYMTxx7ioejy8a/MXphI7c=; b=x8TSsz8MURzWXd1hgKxxkw9KjGVbqdek9FJqPm2cCpfidQCsNzA0gjTySbSy7q7i+5 YEcprrVaek0PJDX5jtcoy1pgpByxWkIEOaB/MDiGNiLiyfmxzZve1w2PbUuJMTWrMqa+ JVQsGM+nNKCnwyfFhtneqOTsn1Q86pOKSkIH7yROy1kuBtyrWImd87nWsyw9gpoK7GLJ Tob3eXvY2Z2auOPbA04d6602TwRPZp1vVnZ69x86J1HYiTZ3q9eLYjTzxGAw3Qq18mCM Shjz62Lrc3W849cUTnVpN2oRdub3Px09oyHvFCfUo8Ixkp8OflFuN1q1gezpeI5oMRr3 Tl7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Tb574Vxn; 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=pass (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 a132si4139635ywh.20.2022.02.08.05.36.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:36:39 -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=pass header.i=@linaro.org header.s=google header.b=Tb574Vxn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQff-0006Qe-8h for patch@linaro.org; Tue, 08 Feb 2022 08:36:39 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34930) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOr0-0000v1-11 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:14 -0500 Received: from [2a00:1450:4864:20::332] (port=53773 helo=mail-wm1-x332.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqt-00029b-MH for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:13 -0500 Received: by mail-wm1-x332.google.com with SMTP id n8so11948210wmk.3 for ; Tue, 08 Feb 2022 03:40:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ZU4Qt8dF8HrU5xx9gXHm/kYMTxx7ioejy8a/MXphI7c=; b=Tb574VxnftOb0xkQQZQm899rPqCTXBLASZM5wfFl/6AA8+zRXQMsZy5y0EELiKDPtV GkaW+Z5Cc/SVAO0v9/l4hbV6xnFESZUFi3hT9PZpxCiaCiU7gQA3rk0Kltx27Lt5irJw cRNxwC4+K5iRRtUBgIGn7vI3Gbx0np1jZQ9S5JjYMpBBet6m0CpELe52P8bZ6n19sRZz N2SiLDg/EAewtxHDfKFGlSLor7DcKWm6OJkIW0wLqRprdOp+Jsmr4AkmB6FulQ/KhBoC jghtlDmDJ4n7xANUIizMe4uD60XK2Z9ppwvg4UjReYNSdvccknuz8Y1DNsiSOLD4N8DI wmdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZU4Qt8dF8HrU5xx9gXHm/kYMTxx7ioejy8a/MXphI7c=; b=dNvW5duCdSgohxa89FXdT2iMpfdS1mqjO0IXZm0K2naHYdrjrj3pkRA9REQWmdHf+b 7oG9FdaD//LRQ192BFpu38/Qb5KpubZG0SHu1Q3sFwUuiit4DOgIcbeR/u/jxzS7BfL6 AGbVA7DiJB4IXLZ+DxTWGjxZnrvaOQR9QGWcYhISXcgBO5n7iVY+bAlxLUus21COP2Qn RUUfdaxGlTdXR/zVtXd3MTCSvb63ETpii/a6OZnxfvEGMFF6qXGXiviRGJ/pQKwLQ4od zahWEMzSgQs1iK1zQ7bDUtyYDm4F8Wep/36jPEjGOeLrisxHWXeVvP/eUKsK96puNtXw Mcfg== X-Gm-Message-State: AOAM530s8UDyJ6994Px6P3NaJeXbW+3uLkbS0pXkv2iNNuTbstUP+oWV 2QFDxEAJGePEXoUyhabJaNvF+2Lyjf/QYA== X-Received: by 2002:a1c:1946:: with SMTP id 67mr811785wmz.12.1644320406202; Tue, 08 Feb 2022 03:40:06 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:05 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 25/39] hw/arm/smmuv3: Fix device reset Date: Tue, 8 Feb 2022 11:39:34 +0000 Message-Id: <20220208113948.3217356-26-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::332 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x332.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Eric Auger We currently miss a bunch of register resets in the device reset function. This sometimes prevents the guest from rebooting after a system_reset (with virtio-blk-pci). For instance, we may get the following errors: invalid STE smmuv3-iommu-memory-region-0-0 translation failed for iova=0x13a9d2000(SMMU_EVT_C_BAD_STE) Invalid read at addr 0x13A9D2000, size 2, region '(null)', reason: rejected invalid STE smmuv3-iommu-memory-region-0-0 translation failed for iova=0x13a9d2000(SMMU_EVT_C_BAD_STE) Invalid write at addr 0x13A9D2000, size 2, region '(null)', reason: rejected invalid STE Signed-off-by: Eric Auger Message-id: 20220202111602.627429-1-eric.auger@redhat.com Fixes: 10a83cb988 ("hw/arm/smmuv3: Skeleton") Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/arm/smmuv3.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c index 3b43368be0f..674623aabea 100644 --- a/hw/arm/smmuv3.c +++ b/hw/arm/smmuv3.c @@ -278,6 +278,12 @@ static void smmuv3_init_regs(SMMUv3State *s) s->features = 0; s->sid_split = 0; s->aidr = 0x1; + s->cr[0] = 0; + s->cr0ack = 0; + s->irq_ctrl = 0; + s->gerror = 0; + s->gerrorn = 0; + s->statusr = 0; } static int smmu_get_ste(SMMUv3State *s, dma_addr_t addr, STE *buf, From patchwork Tue Feb 8 11:39:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540792 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp532045imo; Tue, 8 Feb 2022 06:24:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJybXrlXlLpzGHmYz50Y7rFfuFoXa9p/L2pcXXmxElFsoeLwr/PIVt8TKqR+93eGfT9wN2Lc X-Received: by 2002:a0d:fb06:: with SMTP id l6mr4958925ywf.44.1644330299046; Tue, 08 Feb 2022 06:24:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644330299; cv=none; d=google.com; s=arc-20160816; b=QoOFQsDkc+6K7iKZ+UIvC9p7igXgfqYsIICqS3FP4ZZ343dbg8O8hZLUg1RJChqXfH T3d2Gjx0pRz6Sip556eJtt7LmldtcTPVgl1U0tranwFsOItko7SyNGU20YpmJQoPAN1g Rzv+GA1QSaZ9lGEx/aS4QVH15MJ2zezNE+ZuCdifLBCDes/HnUwo0SFJrZyHN9E48W+h j/8tnM4ppXt3838QmZKOFl+cIpo5kKDVinXCA0GfpUIXZu5pviX1vQRbNEAx60lQqXFx Ty4FzuVrwGjLT5iDNRQ7QGgo7vdI5eBuUPn+OeqmNjp0HdGGoT5xw1sQ8MoN7qDxe+2K 12tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=I6ofd2+RFe7Q0zIenoAENpu2K6I00G1x9Fk14iiIxg0=; b=hEIJApOYYvI66h5VESHw5rzE8c3JJJHGrzkffDzuL0MvNucBUbITcfE9P+fCh1sG89 z/+xJV2iOwn1+cUadZzJkIwH9NKxgUIgxAhsJpjrhrh2ztKg+v9T009bshNOy1GQZ647 eIAy8J9HxBT5fAVlDxJ7mLknI8MO9mQTOApleafMBLEQqQsXFYrS2V/6bN+O7f+9nU+9 akn8Hwi/cAk5ygerDvRnVdND1h/NT89OXFJ5bWbMPmh6UbyE3vSv+GBZWfl5S4+WGQQU nUQDuwDSf7HUSzfOg08YzJCpkGk8ec83RKyRqwQrQHE0S2xRqKw8gSlULh33K/dUSJiC n0pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ID6sJXt+; 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=pass (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 e144si5978408ywa.36.2022.02.08.06.24.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:24:59 -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=pass header.i=@linaro.org header.s=google header.b=ID6sJXt+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHRQQ-0005p6-BW for patch@linaro.org; Tue, 08 Feb 2022 09:24:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34966) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOr1-0000y7-Uq for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:16 -0500 Received: from [2a00:1450:4864:20::42c] (port=39800 helo=mail-wr1-x42c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqu-0002A8-FA for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:15 -0500 Received: by mail-wr1-x42c.google.com with SMTP id d27so1899422wrc.6 for ; Tue, 08 Feb 2022 03:40:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=I6ofd2+RFe7Q0zIenoAENpu2K6I00G1x9Fk14iiIxg0=; b=ID6sJXt+adJpITWPJjcZXLg3PagQTwDfw2optpPuTfR77eXog//kXncLFIg9JHnIA/ BijTEPXssedr2nkMyD5y6zYVwlSYwzcWAExxPuEqldMI72uqx3J7uIvTKtMDiVb/f3a2 HgGEk0a1vRSjq2EoY7d775X8mETPLUeu0Tz30tRLGms66K8nsruzK8lZsgxMj1p+hkvA l3v/3zr7pmVOzCrBKeBjHgQyE4wTBzd3+4WFjLalHJ8ftV/CVaXMkEP5A89U5HkgyYof 9s2ovKRGmvTPsmkPczqtIWtegQrfLA09DdJemTTZ3chnFlSw3v5dRuD6HjddEisaQ6h3 hRnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I6ofd2+RFe7Q0zIenoAENpu2K6I00G1x9Fk14iiIxg0=; b=ZBG87mmh29PL7INpcrlrRQLuxatzIyZRXb+eG9xE/BosfxGp2ss9zTwcBcA0eg6eGu /JlNHaWD2pCCGjGZhJWmfKmb6Cq3kJNJjrrxEyTQ0fmQlZuIyKfI6DxMjOdVv6bosV6k +aZxJN+Ih4wv1epbH+z37yrT9F3reYbjGEI4mxt+eBwNewtbRhTWPsnQZCzGSibQDk/y m8/uCj9g4ic7q5rqaEMjCLxiSvyNGw4j+YvyLnp15AZzv+1sgq2rSSp1WQ+vjZMHI7oa vY75DQJWgC2yPiS3UOIDYDdwdMUM7chqizVCz2MfhgTYjv2u3Yu1MZK+l/GS4MjVfI9u FaMw== X-Gm-Message-State: AOAM532PMH2GNVjVwdpvERPdUz4vmu66h2EJw5N2BwoK+EiJYHQWYEIH /oIiCE4pF3zbaw+tvLs6XqQlEOAc0DQhmQ== X-Received: by 2002:a5d:49c1:: with SMTP id t1mr3233368wrs.359.1644320407004; Tue, 08 Feb 2022 03:40:07 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:06 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 26/39] hw/intc/arm_gicv3_its: Use address_space_map() to access command queue packets Date: Tue, 8 Feb 2022 11:39:35 +0000 Message-Id: <20220208113948.3217356-27-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42c (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42c; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42c.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Currently the ITS accesses each 8-byte doubleword in a 4-doubleword command packet with a separate address_space_ldq_le() call. This is awkward because the individual command processing functions have ended up with code to handle "load more doublewords out of the packet", which is both unwieldy and also a potential source of bugs because it's not obvious when looking at a line that pulls a field out of the 'value' variable which of the 4 doublewords that variable currently holds. Switch to using address_space_map() to map the whole command packet at once and fish the four doublewords out of it. Then each process_* function can start with a few lines of code that extract the fields it cares about. This requires us to split out the guts of process_its_cmd() into a new do_process_its_cmd(), because we were previously overloading the value and offset arguments as a backdoor way to directly pass the devid and eventid from a write to GITS_TRANSLATER. The new do_process_its_cmd() takes those arguments directly, and process_its_cmd() is just a wrapper that does the "read fields from command packet" part. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-2-peter.maydell@linaro.org --- hw/intc/gicv3_internal.h | 4 +- hw/intc/arm_gicv3_its.c | 208 +++++++++++---------------------------- 2 files changed, 62 insertions(+), 150 deletions(-) diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h index b1af26df9f4..60c8617e4e4 100644 --- a/hw/intc/gicv3_internal.h +++ b/hw/intc/gicv3_internal.h @@ -309,8 +309,8 @@ FIELD(GITS_TYPER, CIL, 36, 1) #define LPI_CTE_ENABLED TABLE_ENTRY_VALID_MASK #define LPI_PRIORITY_MASK 0xfc -#define GITS_CMDQ_ENTRY_SIZE 32 -#define NUM_BYTES_IN_DW 8 +#define GITS_CMDQ_ENTRY_WORDS 4 +#define GITS_CMDQ_ENTRY_SIZE (GITS_CMDQ_ENTRY_WORDS * sizeof(uint64_t)) #define CMD_MASK 0xff diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 51d9be4ae6f..b74753fb8fe 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -224,11 +224,9 @@ static uint64_t get_dte(GICv3ITSState *s, uint32_t devid, MemTxResult *res) * 3. handling of ITS CLEAR command * 4. handling of ITS DISCARD command */ -static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, - uint32_t offset, ItsCmdType cmd) +static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, + uint32_t eventid, ItsCmdType cmd) { - AddressSpace *as = &s->gicv3->dma_as; - uint32_t devid, eventid; MemTxResult res = MEMTX_OK; bool dte_valid; uint64_t dte = 0; @@ -240,22 +238,6 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, bool cte_valid = false; uint64_t rdbase; - if (cmd == NONE) { - devid = offset; - } else { - devid = ((value & DEVID_MASK) >> DEVID_SHIFT); - - offset += NUM_BYTES_IN_DW; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - } - - if (res != MEMTX_OK) { - return CMD_STALL; - } - - eventid = (value & EVENTID_MASK); - if (devid >= s->dt.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: devid %d>=%d", @@ -342,11 +324,19 @@ static ItsCmdResult process_its_cmd(GICv3ITSState *s, uint64_t value, } return CMD_CONTINUE; } - -static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, - uint32_t offset, bool ignore_pInt) +static ItsCmdResult process_its_cmd(GICv3ITSState *s, const uint64_t *cmdpkt, + ItsCmdType cmd) +{ + uint32_t devid, eventid; + + devid = (cmdpkt[0] & DEVID_MASK) >> DEVID_SHIFT; + eventid = cmdpkt[1] & EVENTID_MASK; + return do_process_its_cmd(s, devid, eventid, cmd); +} + +static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, + bool ignore_pInt) { - AddressSpace *as = &s->gicv3->dma_as; uint32_t devid, eventid; uint32_t pIntid = 0; uint64_t num_eventids; @@ -357,32 +347,16 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, uint64_t value, uint64_t dte = 0; IteEntry ite = {}; - devid = ((value & DEVID_MASK) >> DEVID_SHIFT); - offset += NUM_BYTES_IN_DW; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - - if (res != MEMTX_OK) { - return CMD_STALL; - } - - eventid = (value & EVENTID_MASK); + devid = (cmdpkt[0] & DEVID_MASK) >> DEVID_SHIFT; + eventid = cmdpkt[1] & EVENTID_MASK; if (ignore_pInt) { pIntid = eventid; } else { - pIntid = ((value & pINTID_MASK) >> pINTID_SHIFT); + pIntid = (cmdpkt[1] & pINTID_MASK) >> pINTID_SHIFT; } - offset += NUM_BYTES_IN_DW; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - - if (res != MEMTX_OK) { - return CMD_STALL; - } - - icid = value & ICID_MASK; + icid = cmdpkt[2] & ICID_MASK; if (devid >= s->dt.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, @@ -459,31 +433,18 @@ static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid, return res == MEMTX_OK; } -static ItsCmdResult process_mapc(GICv3ITSState *s, uint32_t offset) +static ItsCmdResult process_mapc(GICv3ITSState *s, const uint64_t *cmdpkt) { - AddressSpace *as = &s->gicv3->dma_as; uint16_t icid; uint64_t rdbase; bool valid; - MemTxResult res = MEMTX_OK; - uint64_t value; - offset += NUM_BYTES_IN_DW; - offset += NUM_BYTES_IN_DW; + icid = cmdpkt[2] & ICID_MASK; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - - if (res != MEMTX_OK) { - return CMD_STALL; - } - - icid = value & ICID_MASK; - - rdbase = (value & R_MAPC_RDBASE_MASK) >> R_MAPC_RDBASE_SHIFT; + rdbase = (cmdpkt[2] & R_MAPC_RDBASE_MASK) >> R_MAPC_RDBASE_SHIFT; rdbase &= RDBASE_PROCNUM_MASK; - valid = (value & CMD_FIELD_VALID_MASK); + valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; if ((icid >= s->ct.num_entries) || (rdbase >= s->gicv3->num_cpu)) { qemu_log_mask(LOG_GUEST_ERROR, @@ -532,39 +493,17 @@ static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid, return res == MEMTX_OK; } -static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value, - uint32_t offset) +static ItsCmdResult process_mapd(GICv3ITSState *s, const uint64_t *cmdpkt) { - AddressSpace *as = &s->gicv3->dma_as; uint32_t devid; uint8_t size; uint64_t itt_addr; bool valid; - MemTxResult res = MEMTX_OK; - devid = ((value & DEVID_MASK) >> DEVID_SHIFT); - - offset += NUM_BYTES_IN_DW; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - - if (res != MEMTX_OK) { - return CMD_STALL; - } - - size = (value & SIZE_MASK); - - offset += NUM_BYTES_IN_DW; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - - if (res != MEMTX_OK) { - return CMD_STALL; - } - - itt_addr = (value & ITTADDR_MASK) >> ITTADDR_SHIFT; - - valid = (value & CMD_FIELD_VALID_MASK); + devid = (cmdpkt[0] & DEVID_MASK) >> DEVID_SHIFT; + size = cmdpkt[1] & SIZE_MASK; + itt_addr = (cmdpkt[2] & ITTADDR_MASK) >> ITTADDR_SHIFT; + valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; if ((devid >= s->dt.num_entries) || (size > FIELD_EX64(s->typer, GITS_TYPER, IDBITS))) { @@ -582,23 +521,13 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, uint64_t value, return update_dte(s, devid, valid, size, itt_addr) ? CMD_CONTINUE : CMD_STALL; } -static ItsCmdResult process_movall(GICv3ITSState *s, uint64_t value, - uint32_t offset) +static ItsCmdResult process_movall(GICv3ITSState *s, const uint64_t *cmdpkt) { - AddressSpace *as = &s->gicv3->dma_as; - MemTxResult res = MEMTX_OK; uint64_t rd1, rd2; - /* No fields in dwords 0 or 1 */ - offset += NUM_BYTES_IN_DW; - offset += NUM_BYTES_IN_DW; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - if (res != MEMTX_OK) { - return CMD_STALL; - } + rd1 = FIELD_EX64(cmdpkt[2], MOVALL_2, RDBASE1); + rd2 = FIELD_EX64(cmdpkt[3], MOVALL_3, RDBASE2); - rd1 = FIELD_EX64(value, MOVALL_2, RDBASE1); if (rd1 >= s->gicv3->num_cpu) { qemu_log_mask(LOG_GUEST_ERROR, "%s: RDBASE1 %" PRId64 @@ -606,15 +535,6 @@ static ItsCmdResult process_movall(GICv3ITSState *s, uint64_t value, __func__, rd1, s->gicv3->num_cpu); return CMD_CONTINUE; } - - offset += NUM_BYTES_IN_DW; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - if (res != MEMTX_OK) { - return CMD_STALL; - } - - rd2 = FIELD_EX64(value, MOVALL_3, RDBASE2); if (rd2 >= s->gicv3->num_cpu) { qemu_log_mask(LOG_GUEST_ERROR, "%s: RDBASE2 %" PRId64 @@ -634,10 +554,8 @@ static ItsCmdResult process_movall(GICv3ITSState *s, uint64_t value, return CMD_CONTINUE; } -static ItsCmdResult process_movi(GICv3ITSState *s, uint64_t value, - uint32_t offset) +static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) { - AddressSpace *as = &s->gicv3->dma_as; MemTxResult res = MEMTX_OK; uint32_t devid, eventid, intid; uint16_t old_icid, new_icid; @@ -648,23 +566,9 @@ static ItsCmdResult process_movi(GICv3ITSState *s, uint64_t value, uint64_t num_eventids; IteEntry ite = {}; - devid = FIELD_EX64(value, MOVI_0, DEVICEID); - - offset += NUM_BYTES_IN_DW; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - if (res != MEMTX_OK) { - return CMD_STALL; - } - eventid = FIELD_EX64(value, MOVI_1, EVENTID); - - offset += NUM_BYTES_IN_DW; - value = address_space_ldq_le(as, s->cq.base_addr + offset, - MEMTXATTRS_UNSPECIFIED, &res); - if (res != MEMTX_OK) { - return CMD_STALL; - } - new_icid = FIELD_EX64(value, MOVI_2, ICID); + devid = FIELD_EX64(cmdpkt[0], MOVI_0, DEVICEID); + eventid = FIELD_EX64(cmdpkt[1], MOVI_1, EVENTID); + new_icid = FIELD_EX64(cmdpkt[2], MOVI_2, ICID); if (devid >= s->dt.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, @@ -786,9 +690,7 @@ static void process_cmdq(GICv3ITSState *s) uint32_t wr_offset = 0; uint32_t rd_offset = 0; uint32_t cq_offset = 0; - uint64_t data; AddressSpace *as = &s->gicv3->dma_as; - MemTxResult res = MEMTX_OK; uint8_t cmd; int i; @@ -816,28 +718,40 @@ static void process_cmdq(GICv3ITSState *s) while (wr_offset != rd_offset) { ItsCmdResult result = CMD_CONTINUE; + void *hostmem; + hwaddr buflen; + uint64_t cmdpkt[GITS_CMDQ_ENTRY_WORDS]; cq_offset = (rd_offset * GITS_CMDQ_ENTRY_SIZE); - data = address_space_ldq_le(as, s->cq.base_addr + cq_offset, - MEMTXATTRS_UNSPECIFIED, &res); - if (res != MEMTX_OK) { + + buflen = GITS_CMDQ_ENTRY_SIZE; + hostmem = address_space_map(as, s->cq.base_addr + cq_offset, + &buflen, false, MEMTXATTRS_UNSPECIFIED); + if (!hostmem || buflen != GITS_CMDQ_ENTRY_SIZE) { + if (hostmem) { + address_space_unmap(as, hostmem, buflen, false, 0); + } s->creadr = FIELD_DP64(s->creadr, GITS_CREADR, STALLED, 1); qemu_log_mask(LOG_GUEST_ERROR, "%s: could not read command at 0x%" PRIx64 "\n", __func__, s->cq.base_addr + cq_offset); break; } + for (i = 0; i < ARRAY_SIZE(cmdpkt); i++) { + cmdpkt[i] = ldq_le_p(hostmem + i * sizeof(uint64_t)); + } + address_space_unmap(as, hostmem, buflen, false, 0); - cmd = (data & CMD_MASK); + cmd = cmdpkt[0] & CMD_MASK; trace_gicv3_its_process_command(rd_offset, cmd); switch (cmd) { case GITS_CMD_INT: - result = process_its_cmd(s, data, cq_offset, INTERRUPT); + result = process_its_cmd(s, cmdpkt, INTERRUPT); break; case GITS_CMD_CLEAR: - result = process_its_cmd(s, data, cq_offset, CLEAR); + result = process_its_cmd(s, cmdpkt, CLEAR); break; case GITS_CMD_SYNC: /* @@ -848,19 +762,19 @@ static void process_cmdq(GICv3ITSState *s) */ break; case GITS_CMD_MAPD: - result = process_mapd(s, data, cq_offset); + result = process_mapd(s, cmdpkt); break; case GITS_CMD_MAPC: - result = process_mapc(s, cq_offset); + result = process_mapc(s, cmdpkt); break; case GITS_CMD_MAPTI: - result = process_mapti(s, data, cq_offset, false); + result = process_mapti(s, cmdpkt, false); break; case GITS_CMD_MAPI: - result = process_mapti(s, data, cq_offset, true); + result = process_mapti(s, cmdpkt, true); break; case GITS_CMD_DISCARD: - result = process_its_cmd(s, data, cq_offset, DISCARD); + result = process_its_cmd(s, cmdpkt, DISCARD); break; case GITS_CMD_INV: case GITS_CMD_INVALL: @@ -875,10 +789,10 @@ static void process_cmdq(GICv3ITSState *s) } break; case GITS_CMD_MOVI: - result = process_movi(s, data, cq_offset); + result = process_movi(s, cmdpkt); break; case GITS_CMD_MOVALL: - result = process_movall(s, data, cq_offset); + result = process_movall(s, cmdpkt); break; default: break; @@ -1032,15 +946,13 @@ static MemTxResult gicv3_its_translation_write(void *opaque, hwaddr offset, { GICv3ITSState *s = (GICv3ITSState *)opaque; bool result = true; - uint32_t devid = 0; trace_gicv3_its_translation_write(offset, data, size, attrs.requester_id); switch (offset) { case GITS_TRANSLATER: if (s->ctlr & R_GITS_CTLR_ENABLED_MASK) { - devid = attrs.requester_id; - result = process_its_cmd(s, data, devid, NONE); + result = do_process_its_cmd(s, attrs.requester_id, data, NONE); } break; default: From patchwork Tue Feb 8 11:39:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540793 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp534906imo; Tue, 8 Feb 2022 06:28:58 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7+AUN0jm2OZPO7Dyw4poPX5hMVVcxvRur8T4ghdW1y1cwarztx/6fdgPEXWh5L9sgSIgB X-Received: by 2002:a05:6902:1082:: with SMTP id v2mr4864641ybu.333.1644330538212; Tue, 08 Feb 2022 06:28:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644330538; cv=none; d=google.com; s=arc-20160816; b=mAQuzVBcBZU9ynvnscIBEYaMhivuRhxKhC8kwaCBRMYFaqXROGU1UclKxR/bCIQAJ4 SiF03Zp3MJ2rTDF/VUDWQ77W/H7w/lwcKEHkmVm8jtZTlOGxXLFGWFecvTLTiZQC4sB1 fLE/ZTkYXDkXHAOGUCk9zduOGX/VuOI2I0U+hPC16Mv7nXL4ZhHWi+fJ1RaAX8bteO2P 8XS8NXaCPRpq6368JvrWNpkbIPec3DUVpz9bla6xyqKPkj+7odm2/L4JDsndMEbHgNMQ MLnMkZtR3tkK2KgrVmIVw/pZCTmvsn4IgSriWZgZk8jaoTb1m56lyL7l6L9vw6RgiknG B9DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=c5mg1sNC/wyzllW1lIoDZ1cl9qJaOMFNomNf1hGBhD4=; b=V3NrsJO/OHDMQZnam7b/bWVWXvb9EkCUyeQwN7B74HUJheY6VMkowwtq5a8EBTelgq uMRTDnWGWRErHMb3xYbJkyCCiuStjXJehtiyUQLv+g9RaFaqR46Gyvu7QZ7sL780mhF7 uEmNSd/A+Ofapxf7MrUGrecFuearPXFaub1OE7oS3LkyBKGJx9KkR/0H1ZBYDl+f9ouR 5MmLRxU6tluboRJhJh4ux+qjzcUTwDzdLmKB2YjJDTU7x23YyDP1CHMvO0dzpgRmcKc+ hVuzWVFubGtPS1LiHY7a1M8MuToas7x+4x7+6QEAeNkY2ptdSxXyQJqgQyTICyEM+Jah fORw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x54jSh9U; 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=pass (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 v8si4147439ybl.66.2022.02.08.06.28.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:28:58 -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=pass header.i=@linaro.org header.s=google header.b=x54jSh9U; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHRUH-0003a7-Jk for patch@linaro.org; Tue, 08 Feb 2022 09:28:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrS-000161-VS for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:44 -0500 Received: from [2a00:1450:4864:20::42b] (port=43870 helo=mail-wr1-x42b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqw-0002GC-DA for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:16 -0500 Received: by mail-wr1-x42b.google.com with SMTP id i14so539190wrc.10 for ; Tue, 08 Feb 2022 03:40:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=c5mg1sNC/wyzllW1lIoDZ1cl9qJaOMFNomNf1hGBhD4=; b=x54jSh9U4xwDFck+rAPimKknPhbgnufPpGvYvNdUahSwRAuWokmDzUVGl5LabxMPvt okgbCSlk2YrYT0u63ULLBip1+N6ruNak9OBUT2nkjeGtnuunGRwcCfVZ9FK6yNGI2+xq 8Ms7fRx1Nuu5T+mV7vwQ4UIfZVZ3QS8lzhtRZKXzmeOv3qJAUj63j9Q6F2JYq9c5djp7 tZYrv4NIrYk73aiXrrYhHzscliAqCXg/JAHPMUe5M1Twfh/I+9cjWp6mqjmCHg+rFyjL OPzanGDyCDNeSCaRSoBkCmMPCfkzSxkj3ifDfevOA5JNLs2vEM0dkuQOQs4InCmq52yx eJpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=c5mg1sNC/wyzllW1lIoDZ1cl9qJaOMFNomNf1hGBhD4=; b=8LqZToOYzLZvHWepm9dqESCH1Jj1YL5uY8qswC7lCQncSjvzxat8a9c0Nz12ymL2Nz ZpETHdeEyWfn3Lek/rFexdAFgUANxy95fWLVSYDyc8QG8xR5tzK22svj90G3OOSRUDGi 6PWSCSy3Qe3kL+Zm3MXpgPL5F1+11x7rkeAjwGdqOFRWITXMSITZxbgpSDQ1Bpov/clC x0xWIGs3XEG+/bxSbE9wuJ+00WEuStEVp+XbVdy8+k3MgispoOoLTv9ABVBwLYHOcGzQ kHwo7UJCU4VcYgDr66PHshvnQk9nV4sYu7VlTJF4r5BoRK5c+4Kz0XWu9JLUGGZ/7CVw YQIQ== X-Gm-Message-State: AOAM533jT+dcebRL32bkgwr/AH64Zs6WuhNh9zCSgRafaBLybEZFArNh EGwn/vKT0mxx+X9lt09XkNwQNyWU7wRIvw== X-Received: by 2002:a5d:500c:: with SMTP id e12mr3144354wrt.193.1644320407842; Tue, 08 Feb 2022 03:40:07 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:07 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 27/39] hw/intc/arm_gicv3_its: Keep DTEs as a struct, not a raw uint64_t Date: Tue, 8 Feb 2022 11:39:36 +0000 Message-Id: <20220208113948.3217356-28-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42b (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42b; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42b.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" In the ITS, a DTE is an entry in the device table, which contains multiple fields. Currently the function get_dte() which reads one entry from the device table returns it as a raw 64-bit integer, which we then pass around in that form, only extracting fields from it as we need them. Create a real C struct with the same fields as the DTE, and populate it in get_dte(), so that that function and update_dte() are the only ones that need to care about the in-guest-memory format of the DTE. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-3-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 111 ++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 55 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index b74753fb8fe..6d70d7d59e2 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -46,6 +46,12 @@ typedef struct { uint64_t itel; } IteEntry; +typedef struct DTEntry { + bool valid; + unsigned size; + uint64_t ittaddr; +} DTEntry; + /* * The ITS spec permits a range of CONSTRAINED UNPREDICTABLE options * if a command parameter is not correct. These include both "stall @@ -143,22 +149,18 @@ static bool get_cte(GICv3ITSState *s, uint16_t icid, uint64_t *cte, return FIELD_EX64(*cte, CTE, VALID); } -static bool update_ite(GICv3ITSState *s, uint32_t eventid, uint64_t dte, +static bool update_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, IteEntry ite) { AddressSpace *as = &s->gicv3->dma_as; - uint64_t itt_addr; MemTxResult res = MEMTX_OK; - itt_addr = FIELD_EX64(dte, DTE, ITTADDR); - itt_addr <<= ITTADDR_SHIFT; /* 256 byte aligned */ - - address_space_stq_le(as, itt_addr + (eventid * (sizeof(uint64_t) + + address_space_stq_le(as, dte->ittaddr + (eventid * (sizeof(uint64_t) + sizeof(uint32_t))), ite.itel, MEMTXATTRS_UNSPECIFIED, &res); if (res == MEMTX_OK) { - address_space_stl_le(as, itt_addr + (eventid * (sizeof(uint64_t) + + address_space_stl_le(as, dte->ittaddr + (eventid * (sizeof(uint64_t) + sizeof(uint32_t))) + sizeof(uint32_t), ite.iteh, MEMTXATTRS_UNSPECIFIED, &res); } @@ -169,24 +171,20 @@ static bool update_ite(GICv3ITSState *s, uint32_t eventid, uint64_t dte, } } -static bool get_ite(GICv3ITSState *s, uint32_t eventid, uint64_t dte, +static bool get_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, uint16_t *icid, uint32_t *pIntid, MemTxResult *res) { AddressSpace *as = &s->gicv3->dma_as; - uint64_t itt_addr; bool status = false; IteEntry ite = {}; - itt_addr = FIELD_EX64(dte, DTE, ITTADDR); - itt_addr <<= ITTADDR_SHIFT; /* 256 byte aligned */ - - ite.itel = address_space_ldq_le(as, itt_addr + + ite.itel = address_space_ldq_le(as, dte->ittaddr + (eventid * (sizeof(uint64_t) + sizeof(uint32_t))), MEMTXATTRS_UNSPECIFIED, res); if (*res == MEMTX_OK) { - ite.iteh = address_space_ldl_le(as, itt_addr + + ite.iteh = address_space_ldl_le(as, dte->ittaddr + (eventid * (sizeof(uint64_t) + sizeof(uint32_t))) + sizeof(uint32_t), MEMTXATTRS_UNSPECIFIED, res); @@ -205,15 +203,33 @@ static bool get_ite(GICv3ITSState *s, uint32_t eventid, uint64_t dte, return status; } -static uint64_t get_dte(GICv3ITSState *s, uint32_t devid, MemTxResult *res) +/* + * Read the Device Table entry at index @devid. On success (including + * successfully determining that there is no valid DTE for this index), + * we return MEMTX_OK and populate the DTEntry struct accordingly. + * If there is an error reading memory then we return the error code. + */ +static MemTxResult get_dte(GICv3ITSState *s, uint32_t devid, DTEntry *dte) { + MemTxResult res = MEMTX_OK; AddressSpace *as = &s->gicv3->dma_as; - uint64_t entry_addr = table_entry_addr(s, &s->dt, devid, res); + uint64_t entry_addr = table_entry_addr(s, &s->dt, devid, &res); + uint64_t dteval; if (entry_addr == -1) { - return 0; /* a DTE entry with the Valid bit clear */ + /* No L2 table entry, i.e. no valid DTE, or a memory error */ + dte->valid = false; + return res; } - return address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, res); + dteval = address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, &res); + if (res != MEMTX_OK) { + return res; + } + dte->valid = FIELD_EX64(dteval, DTE, VALID); + dte->size = FIELD_EX64(dteval, DTE, SIZE); + /* DTE word field stores bits [51:8] of the ITT address */ + dte->ittaddr = FIELD_EX64(dteval, DTE, ITTADDR) << ITTADDR_SHIFT; + return MEMTX_OK; } /* @@ -228,8 +244,6 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, uint32_t eventid, ItsCmdType cmd) { MemTxResult res = MEMTX_OK; - bool dte_valid; - uint64_t dte = 0; uint64_t num_eventids; uint16_t icid = 0; uint32_t pIntid = 0; @@ -237,6 +251,7 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, uint64_t cte = 0; bool cte_valid = false; uint64_t rdbase; + DTEntry dte; if (devid >= s->dt.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, @@ -245,23 +260,17 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, return CMD_CONTINUE; } - dte = get_dte(s, devid, &res); - - if (res != MEMTX_OK) { + if (get_dte(s, devid, &dte) != MEMTX_OK) { return CMD_STALL; } - dte_valid = FIELD_EX64(dte, DTE, VALID); - - if (!dte_valid) { + if (!dte.valid) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: " - "invalid dte: %"PRIx64" for %d\n", - __func__, dte, devid); + "invalid dte for %d\n", __func__, devid); return CMD_CONTINUE; } - num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); - + num_eventids = 1ULL << (dte.size + 1); if (eventid >= num_eventids) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: eventid %d >= %" @@ -270,7 +279,7 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, return CMD_CONTINUE; } - ite_valid = get_ite(s, eventid, dte, &icid, &pIntid, &res); + ite_valid = get_ite(s, eventid, &dte, &icid, &pIntid, &res); if (res != MEMTX_OK) { return CMD_STALL; } @@ -320,7 +329,7 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, if (cmd == DISCARD) { IteEntry ite = {}; /* remove mapping from interrupt translation table */ - return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL; + return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; } return CMD_CONTINUE; } @@ -341,11 +350,9 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, uint32_t pIntid = 0; uint64_t num_eventids; uint32_t num_intids; - bool dte_valid; - MemTxResult res = MEMTX_OK; uint16_t icid = 0; - uint64_t dte = 0; IteEntry ite = {}; + DTEntry dte; devid = (cmdpkt[0] & DEVID_MASK) >> DEVID_SHIFT; eventid = cmdpkt[1] & EVENTID_MASK; @@ -365,24 +372,21 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, return CMD_CONTINUE; } - dte = get_dte(s, devid, &res); - - if (res != MEMTX_OK) { + if (get_dte(s, devid, &dte) != MEMTX_OK) { return CMD_STALL; } - dte_valid = FIELD_EX64(dte, DTE, VALID); - num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); + num_eventids = 1ULL << (dte.size + 1); num_intids = 1ULL << (GICD_TYPER_IDBITS + 1); if ((icid >= s->ct.num_entries) - || !dte_valid || (eventid >= num_eventids) || + || !dte.valid || (eventid >= num_eventids) || (((pIntid < GICV3_LPI_INTID_START) || (pIntid >= num_intids)) && (pIntid != INTID_SPURIOUS))) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes " "icid %d or eventid %d or pIntid %d or" "unmapped dte %d\n", __func__, icid, eventid, - pIntid, dte_valid); + pIntid, dte.valid); /* * in this implementation, in case of error * we ignore this command and move onto the next @@ -392,13 +396,13 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, } /* add ite entry to interrupt translation table */ - ite.itel = FIELD_DP64(ite.itel, ITE_L, VALID, dte_valid); + ite.itel = FIELD_DP64(ite.itel, ITE_L, VALID, true); ite.itel = FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYSICAL); ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, pIntid); ite.itel = FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS); ite.iteh = FIELD_DP32(ite.iteh, ITE_H, ICID, icid); - return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL; + return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; } static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid, @@ -561,10 +565,10 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) uint16_t old_icid, new_icid; uint64_t old_cte, new_cte; uint64_t old_rdbase, new_rdbase; - uint64_t dte; - bool dte_valid, ite_valid, cte_valid; + bool ite_valid, cte_valid; uint64_t num_eventids; IteEntry ite = {}; + DTEntry dte; devid = FIELD_EX64(cmdpkt[0], MOVI_0, DEVICEID); eventid = FIELD_EX64(cmdpkt[1], MOVI_1, EVENTID); @@ -576,21 +580,18 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) __func__, devid, s->dt.num_entries); return CMD_CONTINUE; } - dte = get_dte(s, devid, &res); - if (res != MEMTX_OK) { + if (get_dte(s, devid, &dte) != MEMTX_OK) { return CMD_STALL; } - dte_valid = FIELD_EX64(dte, DTE, VALID); - if (!dte_valid) { + if (!dte.valid) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: " - "invalid dte: %"PRIx64" for %d\n", - __func__, dte, devid); + "invalid dte for %d\n", __func__, devid); return CMD_CONTINUE; } - num_eventids = 1ULL << (FIELD_EX64(dte, DTE, SIZE) + 1); + num_eventids = 1ULL << (dte.size + 1); if (eventid >= num_eventids) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: eventid %d >= %" @@ -599,7 +600,7 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) return CMD_CONTINUE; } - ite_valid = get_ite(s, eventid, dte, &old_icid, &intid, &res); + ite_valid = get_ite(s, eventid, &dte, &old_icid, &intid, &res); if (res != MEMTX_OK) { return CMD_STALL; } @@ -678,7 +679,7 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, intid); ite.itel = FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS); ite.iteh = FIELD_DP32(ite.iteh, ITE_H, ICID, new_icid); - return update_ite(s, eventid, dte, ite) ? CMD_CONTINUE : CMD_STALL; + return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; } /* From patchwork Tue Feb 8 11:39:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540788 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp514735imo; Tue, 8 Feb 2022 06:05:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJy/pqmeTtq9ELMEJkceSUZKNATSJfAx24AHz4NeKjnph+TNAzH1utV5naPiSq6Wrq2/0Ef6 X-Received: by 2002:a25:2107:: with SMTP id h7mr4614595ybh.513.1644329123935; Tue, 08 Feb 2022 06:05:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644329123; cv=none; d=google.com; s=arc-20160816; b=gUPz9HvD1SBdEcRXYcj1ARa2FICibX+vafCiqEZus7KERY2NRVYA07cGAOrg72dLhc 4OdC20XtrwbhxAJ9uXOgMnHmGNo4gKzDzdpRfEQTgL3xc2JfghAu4SgjwqxFhwrTPm8u Zl7MDGs8+wyfaRrXgrfsvIIwGw/gFUgY1dh4yTR0UVPDYoQpxZ/7EcAI/CG8r87A+Zpv buR0tDkbGBvAWb8wCtrYgBSXDcG1hT5Oky+q7siauYAFYYiwyBgumkemW344v5oh6Vvw vrnBraMa0GoVlX/rW19KXX0DLdj1k/fDmN4hLDyDik5hGvAB7zMWAW8MW8zIeeaZ4N5i W9wA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=HSePLC3CQFBtM40/pCnr2cnwRaT/DzoxkqceSrf8Vpc=; b=vf7A6vQdWIMFgt68YQF1gpfDR1wylbxVQt+F6GoiDCMJno1RFHAFYI4kHHP4h8ZmMn QDfr7b3yROE+Ivtn+gdj0RcfmgQD8Led7RNd1yXpXbWU0EPHecAqcOUB43E+pilG+h50 IXb97N3ERrKhBWVG5ctthFZHUJSVjqGz+tlA0Cwg2yBdh8MIvnky2i9KQuB+50T91ocB xSJ6D19npTxVWFMt0+/3W78wn2jlnCYgN0mmH2w5xQwmN0G7QyjU3zTdHxx6+5QVHRKh 5GgZW59X+SQcUqBlJf0ncCmV9kJ0NniFz8l65uIg/OKtRHe5O4Re1xFxIFauwvyOYwZO 7O4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aCscCFKQ; 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=pass (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 v1si2500352ybu.607.2022.02.08.06.05.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:05:23 -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=pass header.i=@linaro.org header.s=google header.b=aCscCFKQ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHR7T-0001kB-8c for patch@linaro.org; Tue, 08 Feb 2022 09:05:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrS-000162-Va for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:45 -0500 Received: from [2a00:1450:4864:20::42a] (port=37434 helo=mail-wr1-x42a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqw-0002KW-DY for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:17 -0500 Received: by mail-wr1-x42a.google.com with SMTP id w11so30204855wra.4 for ; Tue, 08 Feb 2022 03:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=HSePLC3CQFBtM40/pCnr2cnwRaT/DzoxkqceSrf8Vpc=; b=aCscCFKQSmDyCzcPky81DcQWZQjBeD5JevWxSCR+rphNYh0lKaLu68fC9ARi2vjYqQ gGl1uUZ25OHBad5seaTsram+kp+xu4Y7j4mTPOOgIdhWhvmkarZcAqv33lLKwV/M0W8b 2WJA7b8A6vO0TKMixtqWojDHlzkZLB7xgJ2ZH/G1gCeHJQSitcqInBnyD8K4/N0WuWAb ijhNUf7F9DrWT4tIdc5FlXL/+lpHkLUQQmyOXiD1rv+lIyO8rrv7LXXt2ANSwdtL1GBP TZlcBxHCIuMqOCs0UTviwutHldaN23/efRkxgj46BI96uffhkYyEvYe5E6K0bRYvWTik x9Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HSePLC3CQFBtM40/pCnr2cnwRaT/DzoxkqceSrf8Vpc=; b=DiT5aZpin23nXj+f+0T2mMT3w4rdf6WUUeOdxUppaSGNgclo+ZqAiqLgIwrs9acsH7 xuLyN4hqan2YF1m7UDWR3XarF8TvWS2rKFX+Rvehos46+BeQMiZxALVI/i9BTQdWzvVE AVBs8VzMvL1RQoeP/N1DfFAqu1o/In998mfdBuTeyItxHqRRvDRBq/m+5hRncskPN9G6 OEr7loccKMxLbGxQ9ogP1PMilFT1h2HF69ISbrT4lAm9g7se9hidwguTeK78Wn0HSvvQ nSYFqFRUdEfJICh+QTx/LoJUvw1MwkF8Lwv8J9eoahVCOPENkm4JBwIBlYpr+rcQS1f0 MDWQ== X-Gm-Message-State: AOAM533kTLpBZksqAhY9/rpk9FrSCr5m8FntULrZV2cWvaMUClot1bIi NkMvI68POucB9dXz+BNOstZ0JivIB82Daw== X-Received: by 2002:adf:f981:: with SMTP id f1mr3183563wrr.651.1644320408482; Tue, 08 Feb 2022 03:40:08 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:08 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 28/39] hw/intc/arm_gicv3_its: Pass DTEntry to update_dte() Date: Tue, 8 Feb 2022 11:39:37 +0000 Message-Id: <20220208113948.3217356-29-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::42a (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x42a.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Make update_dte() take a DTEntry struct rather than all the fields of the new DTE as separate arguments. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-4-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 6d70d7d59e2..1856210e79a 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -465,20 +465,23 @@ static ItsCmdResult process_mapc(GICv3ITSState *s, const uint64_t *cmdpkt) return update_cte(s, icid, valid, rdbase) ? CMD_CONTINUE : CMD_STALL; } -static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid, - uint8_t size, uint64_t itt_addr) +/* + * Update the Device Table entry for @devid to @dte. Returns true + * on success, false if there was a memory access error. + */ +static bool update_dte(GICv3ITSState *s, uint32_t devid, const DTEntry *dte) { AddressSpace *as = &s->gicv3->dma_as; uint64_t entry_addr; - uint64_t dte = 0; + uint64_t dteval = 0; MemTxResult res = MEMTX_OK; if (s->dt.valid) { - if (valid) { + if (dte->valid) { /* add mapping entry to device table */ - dte = FIELD_DP64(dte, DTE, VALID, 1); - dte = FIELD_DP64(dte, DTE, SIZE, size); - dte = FIELD_DP64(dte, DTE, ITTADDR, itt_addr); + dteval = FIELD_DP64(dteval, DTE, VALID, 1); + dteval = FIELD_DP64(dteval, DTE, SIZE, dte->size); + dteval = FIELD_DP64(dteval, DTE, ITTADDR, dte->ittaddr); } } else { return true; @@ -493,27 +496,25 @@ static bool update_dte(GICv3ITSState *s, uint32_t devid, bool valid, /* No L2 table for this index: discard write and continue */ return true; } - address_space_stq_le(as, entry_addr, dte, MEMTXATTRS_UNSPECIFIED, &res); + address_space_stq_le(as, entry_addr, dteval, MEMTXATTRS_UNSPECIFIED, &res); return res == MEMTX_OK; } static ItsCmdResult process_mapd(GICv3ITSState *s, const uint64_t *cmdpkt) { uint32_t devid; - uint8_t size; - uint64_t itt_addr; - bool valid; + DTEntry dte; devid = (cmdpkt[0] & DEVID_MASK) >> DEVID_SHIFT; - size = cmdpkt[1] & SIZE_MASK; - itt_addr = (cmdpkt[2] & ITTADDR_MASK) >> ITTADDR_SHIFT; - valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; + dte.size = cmdpkt[1] & SIZE_MASK; + dte.ittaddr = (cmdpkt[2] & ITTADDR_MASK) >> ITTADDR_SHIFT; + dte.valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; if ((devid >= s->dt.num_entries) || - (size > FIELD_EX64(s->typer, GITS_TYPER, IDBITS))) { + (dte.size > FIELD_EX64(s->typer, GITS_TYPER, IDBITS))) { qemu_log_mask(LOG_GUEST_ERROR, "ITS MAPD: invalid device table attributes " - "devid %d or size %d\n", devid, size); + "devid %d or size %d\n", devid, dte.size); /* * in this implementation, in case of error * we ignore this command and move onto the next @@ -522,7 +523,7 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, const uint64_t *cmdpkt) return CMD_CONTINUE; } - return update_dte(s, devid, valid, size, itt_addr) ? CMD_CONTINUE : CMD_STALL; + return update_dte(s, devid, &dte) ? CMD_CONTINUE : CMD_STALL; } static ItsCmdResult process_movall(GICv3ITSState *s, const uint64_t *cmdpkt) From patchwork Tue Feb 8 11:39:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540786 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp507640imo; Tue, 8 Feb 2022 05:56:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJxHdkaUABTCiqHh+qrzUeVJrdg3xAiKHC4PoynYRjBYuLUCIDX+NqVAynINK0FZJZIzGGNc X-Received: by 2002:a0d:e346:: with SMTP id m67mr4634219ywe.484.1644328608279; Tue, 08 Feb 2022 05:56:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644328608; cv=none; d=google.com; s=arc-20160816; b=N/RMedLw5CiREiMZKYcIS1flam7RpCOh5oyzo9O4LqtWPg5EOXTf6GqjSG3N3s0XlW VuNlAOsoobKvgK7z6cXb/rHGL7jLRZovFKeWj0x7X0glU30++0Bg6isw2qraXKhx3K72 WrQ2FwLDOeFaghjE1LX4054ngAYTog66csrKAYR/M0mC/UINvp/l9UoDNLgzHSXUDcgB sesX9ATWdmln7+3YglAVRYufuLo3GBPAMgbc4QRL8Y3EmzppbHxEZJiBDOxeDZu4/M84 7zTDURiEkvRXXYHNtHQGuHb0hZr+rTV4nGlyfdprCn0ANw8WabDIb+FbT1ByKBn3cRsZ +PTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=pp3mTpA7sXqcSdEShjFPNL03srw1TL9PNunr5ys0FH4=; b=zca7hwN2lsMZoMgEQ7dirInVRUMBfdlqWmlwEL6a71p+eiTIliF+c7rX6ju+/lEJYL PYF/wwTlgDd7VO7sKCxJXrOnYXbLuv5l32ll8LCt33UaC5E9JGlgu5XytSKN05IoD2JD 5G/c86AFg9VgGtUimz6k8st0Fnc2CPwxpFneVUbLlFOJY3MqWd2nv6RUNcWh6y4WC/cW JNggWtmh30bCWmq/+0Q+nCvpvaElpFCBgMpGNc3heqjpOxQp52OnGel8eTfZ4A32XI1S JOHAfZmIWoVtmEAH77kySGnCKT+297DDnfR9D54DHq797cq8ohnr0v+4mE9mEtj+O3/h LvSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MSDAs6eG; 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=pass (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 u4si717034ybd.311.2022.02.08.05.56.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:56:48 -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=pass header.i=@linaro.org header.s=google header.b=MSDAs6eG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQz9-0003qI-Ed for patch@linaro.org; Tue, 08 Feb 2022 08:56:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35112) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrS-000160-V1 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:44 -0500 Received: from [2a00:1450:4864:20::433] (port=46723 helo=mail-wr1-x433.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqw-0002Kd-HQ for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:17 -0500 Received: by mail-wr1-x433.google.com with SMTP id q7so2005619wrc.13 for ; Tue, 08 Feb 2022 03:40:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=pp3mTpA7sXqcSdEShjFPNL03srw1TL9PNunr5ys0FH4=; b=MSDAs6eGfdW7CXcqOWmCwB+DWXGL3PeRnM4a3ozP3UVJuxuXiqoNfNTQV9sp+r7SP3 DQVjwXpeTbN2WUyhECV1uAITYtLQAg6SZPlsnQq98WU5F1QDulXak1D+ec8X/td+yJJy 1tTnJROtcf7QQBBURtkBuv+OtODkebC/c7M2tZslK5Sf0OyNG7Nc59mnmBhK/0r55ZS0 hagFT88eqs0MW5yMnNofOMrdtnFJyx4tmU8vx8mpInGgUvFziXbnHtoK5CnUtxDDl/L7 YaoTY5md1QlyyDYrIZUa7A3Hlz9Q32J2WkJhGymsqdPfZIJwMC16nrs09AYLsk3nJo4J UpzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pp3mTpA7sXqcSdEShjFPNL03srw1TL9PNunr5ys0FH4=; b=f5c8OVUQ/48fQYtVF738VRjfmDZCEqJ7kLELpTIrbc+ktxbD1nl8VOhjQT+/wMxP1h wupfNrkrj8Tfgc0qjyJyAG6YE+cVRT2uErB0HvR1EwOlH1OvuwV/OhKhdbNt7B6I60u2 2sFo4LDH1HFlG5L/YN4gVGXLFDFc8EJu3nDxqI1BUO3hLwsclxFU7jjTynuziRGA3NKp 2TaibpYboHgPzLam7WxVotuhZFvcdVYSWF7Cf4Abc5A+2lpcHzjMreJDEi3UF8fc40Sl Q6ixCrC5gKPOeSxUQ19NpwPz3owDd8SarFY5RQ4gOqSc8IIhjMLkBe7SSBCm/c98zwSl wO5Q== X-Gm-Message-State: AOAM530yM4YVMMZNmvcpWH/Adh56LA3QmEdgCAnoBDK5mc8GiJLp9M26 lTimEwfsa3XPBX+YRrdU8YTxXN4SAmtLdQ== X-Received: by 2002:a05:6000:1846:: with SMTP id c6mr3187345wri.683.1644320409145; Tue, 08 Feb 2022 03:40:09 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:08 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 29/39] hw/intc/arm_gicv3_its: Keep CTEs as a struct, not a raw uint64_t Date: Tue, 8 Feb 2022 11:39:38 +0000 Message-Id: <20220208113948.3217356-30-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::433 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::433; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x433.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" In the ITS, a CTE is an entry in the collection table, which contains multiple fields. Currently the function get_cte() which reads one entry from the device table returns a success/failure boolean and passes back the raw 64-bit integer CTE value via a pointer argument. We then extract fields from the CTE as we need them. Create a real C struct with the same fields as the CTE, and populate it in get_cte(), so that that function and update_cte() are the only ones which need to care about the in-guest-memory format of the CTE. This brings get_cte()'s API into line with get_dte(). Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-5-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 96 ++++++++++++++++++++++------------------- 1 file changed, 52 insertions(+), 44 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 1856210e79a..482a71ba73c 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -52,6 +52,11 @@ typedef struct DTEntry { uint64_t ittaddr; } DTEntry; +typedef struct CTEntry { + bool valid; + uint32_t rdbase; +} CTEntry; + /* * The ITS spec permits a range of CONSTRAINED UNPREDICTABLE options * if a command parameter is not correct. These include both "stall @@ -135,18 +140,32 @@ static uint64_t table_entry_addr(GICv3ITSState *s, TableDesc *td, return (l2 & ((1ULL << 51) - 1)) + (idx % num_l2_entries) * td->entry_sz; } -static bool get_cte(GICv3ITSState *s, uint16_t icid, uint64_t *cte, - MemTxResult *res) +/* + * Read the Collection Table entry at index @icid. On success (including + * successfully determining that there is no valid CTE for this index), + * we return MEMTX_OK and populate the CTEntry struct @cte accordingly. + * If there is an error reading memory then we return the error code. + */ +static MemTxResult get_cte(GICv3ITSState *s, uint16_t icid, CTEntry *cte) { AddressSpace *as = &s->gicv3->dma_as; - uint64_t entry_addr = table_entry_addr(s, &s->ct, icid, res); + MemTxResult res = MEMTX_OK; + uint64_t entry_addr = table_entry_addr(s, &s->ct, icid, &res); + uint64_t cteval; if (entry_addr == -1) { - return false; /* not valid */ + /* No L2 table entry, i.e. no valid CTE, or a memory error */ + cte->valid = false; + return res; } - *cte = address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, res); - return FIELD_EX64(*cte, CTE, VALID); + cteval = address_space_ldq_le(as, entry_addr, MEMTXATTRS_UNSPECIFIED, &res); + if (res != MEMTX_OK) { + return res; + } + cte->valid = FIELD_EX64(cteval, CTE, VALID); + cte->rdbase = FIELD_EX64(cteval, CTE, RDBASE); + return MEMTX_OK; } static bool update_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, @@ -248,10 +267,8 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, uint16_t icid = 0; uint32_t pIntid = 0; bool ite_valid = false; - uint64_t cte = 0; - bool cte_valid = false; - uint64_t rdbase; DTEntry dte; + CTEntry cte; if (devid >= s->dt.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, @@ -298,15 +315,13 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, return CMD_CONTINUE; } - cte_valid = get_cte(s, icid, &cte, &res); - if (res != MEMTX_OK) { + if (get_cte(s, icid, &cte) != MEMTX_OK) { return CMD_STALL; } - if (!cte_valid) { + if (!cte.valid) { qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes: " - "invalid cte: %"PRIx64"\n", - __func__, cte); + "%s: invalid command attributes: invalid CTE\n", + __func__); return CMD_CONTINUE; } @@ -314,16 +329,14 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, * Current implementation only supports rdbase == procnum * Hence rdbase physical address is ignored */ - rdbase = FIELD_EX64(cte, CTE, RDBASE); - - if (rdbase >= s->gicv3->num_cpu) { + if (cte.rdbase >= s->gicv3->num_cpu) { return CMD_CONTINUE; } if ((cmd == CLEAR) || (cmd == DISCARD)) { - gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 0); + gicv3_redist_process_lpi(&s->gicv3->cpu[cte.rdbase], pIntid, 0); } else { - gicv3_redist_process_lpi(&s->gicv3->cpu[rdbase], pIntid, 1); + gicv3_redist_process_lpi(&s->gicv3->cpu[cte.rdbase], pIntid, 1); } if (cmd == DISCARD) { @@ -564,12 +577,11 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) MemTxResult res = MEMTX_OK; uint32_t devid, eventid, intid; uint16_t old_icid, new_icid; - uint64_t old_cte, new_cte; - uint64_t old_rdbase, new_rdbase; - bool ite_valid, cte_valid; + bool ite_valid; uint64_t num_eventids; IteEntry ite = {}; DTEntry dte; + CTEntry old_cte, new_cte; devid = FIELD_EX64(cmdpkt[0], MOVI_0, DEVICEID); eventid = FIELD_EX64(cmdpkt[1], MOVI_1, EVENTID); @@ -627,50 +639,46 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) return CMD_CONTINUE; } - cte_valid = get_cte(s, old_icid, &old_cte, &res); - if (res != MEMTX_OK) { + if (get_cte(s, old_icid, &old_cte) != MEMTX_OK) { return CMD_STALL; } - if (!cte_valid) { + if (!old_cte.valid) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: " - "invalid cte: %"PRIx64"\n", - __func__, old_cte); + "invalid CTE for old ICID 0x%x\n", + __func__, old_icid); return CMD_CONTINUE; } - cte_valid = get_cte(s, new_icid, &new_cte, &res); - if (res != MEMTX_OK) { + if (get_cte(s, new_icid, &new_cte) != MEMTX_OK) { return CMD_STALL; } - if (!cte_valid) { + if (!new_cte.valid) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: " - "invalid cte: %"PRIx64"\n", - __func__, new_cte); + "invalid CTE for new ICID 0x%x\n", + __func__, new_icid); return CMD_CONTINUE; } - old_rdbase = FIELD_EX64(old_cte, CTE, RDBASE); - if (old_rdbase >= s->gicv3->num_cpu) { + if (old_cte.rdbase >= s->gicv3->num_cpu) { qemu_log_mask(LOG_GUEST_ERROR, - "%s: CTE has invalid rdbase 0x%"PRIx64"\n", - __func__, old_rdbase); + "%s: CTE has invalid rdbase 0x%x\n", + __func__, old_cte.rdbase); return CMD_CONTINUE; } - new_rdbase = FIELD_EX64(new_cte, CTE, RDBASE); - if (new_rdbase >= s->gicv3->num_cpu) { + if (new_cte.rdbase >= s->gicv3->num_cpu) { qemu_log_mask(LOG_GUEST_ERROR, - "%s: CTE has invalid rdbase 0x%"PRIx64"\n", - __func__, new_rdbase); + "%s: CTE has invalid rdbase 0x%x\n", + __func__, new_cte.rdbase); return CMD_CONTINUE; } - if (old_rdbase != new_rdbase) { + if (old_cte.rdbase != new_cte.rdbase) { /* Move the LPI from the old redistributor to the new one */ - gicv3_redist_mov_lpi(&s->gicv3->cpu[old_rdbase], - &s->gicv3->cpu[new_rdbase], + gicv3_redist_mov_lpi(&s->gicv3->cpu[old_cte.rdbase], + &s->gicv3->cpu[new_cte.rdbase], intid); } From patchwork Tue Feb 8 11:39:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540796 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp548970imo; Tue, 8 Feb 2022 06:48:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3jdgCi6YP/yVxSTwsk9DwKJFpKVUcvEvKPyRQ8whSvml2ozYaAAlsx1BTeqSF9qpEXBBv X-Received: by 2002:a81:ac4f:: with SMTP id z15mr5213544ywj.7.1644331693837; Tue, 08 Feb 2022 06:48:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644331693; cv=none; d=google.com; s=arc-20160816; b=qdmaEeFr4QzEpTjB/YlRR4vukf4F0S24Y7nOjUGBJ/SAhUJE1NiBbhI/CVVwhiQxfo SDGYJJkNjoZ8HIf/JEPFUF7YeECKa7vTefMIFkHH0GEhIvCcI4S6YoWXQ96K2ZgAepLL ZgpnMMuHluFpbJEej64mlRp9U4D8tTC1fPXrYr5TfTHfmP3zFCf1TKoKalJEP3vcTcHi 9tqiYWRc10wO+vJaYPuaJZq2IxXE0Qckxe1TxKFrcEprtlT38xUhiq+3RDZyDSk1+8G5 aFC+CNlt9NuZs5E+k/0KmomjSpaljxiFAV9JjtM3iT13oA7kzAHmyYv9i2rlfNURp0Cy su3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=keqKBjLZSfQavofr1KknVuxPyJINzN8sPoLRoq5UyvA=; b=KgR4qL3WhwExA4cHLsve2DyALnmZAhVrY05S8yFNLJjB62hcDxo0AjutRxEVhDkUU/ 3c0XCvnZQ4svpSn+kFzGZ/OV9SzuQZjFQOpiU7734mtQuKTugBxkncWljzMNchRsz6NL d/zkbmFy1CUWV30q92Xww7SPJ+buQY7jCbArHpxXM9flAIfjk3CFsLt4rI/kkLtMzo2q nZG8JoySm7ivK8CWAebbQMUuWay462EuWHQzXDLV+QYVZkICtSAnp0THsiVnxfqxav47 VQAKA4ofCid609kXUrAkrV+sO8SrZ2aKHHDMxy07kAsJxZaHCcX89orQC/ePVin6L/5f 04xA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kcAFY7Xf; 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=pass (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 j144si7219359ybj.353.2022.02.08.06.48.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:48:13 -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=pass header.i=@linaro.org header.s=google header.b=kcAFY7Xf; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57348 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHRmv-0006l4-7m for patch@linaro.org; Tue, 08 Feb 2022 09:48:13 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrS-00015z-V0 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:45 -0500 Received: from [2a00:1450:4864:20::434] (port=34311 helo=mail-wr1-x434.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqx-0002Ki-6K for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:18 -0500 Received: by mail-wr1-x434.google.com with SMTP id f17so30223584wrx.1 for ; Tue, 08 Feb 2022 03:40:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=keqKBjLZSfQavofr1KknVuxPyJINzN8sPoLRoq5UyvA=; b=kcAFY7XfPoqIpwJ7AFrdsf2bJ7ikzNuX2y88fHQPtxHTB69kQdE2PQoJT/erqF4e+6 rZrFFyfYgjEytPoOFpPpi1QJouDAwTKuGkqJWQTGclinD6X+NOhUgNYbd0BAoauH3qs5 XrTNlTal/N2cN+A+qnpRJCPyrGwbxYXgys8+PitmbnCUVQk9+hB4God9Koadx599ChAc sA1mbsrVbJmEtlUtUDSRiP7rRkkaytSmo6Li66AJTCFrwziTrwZC616ymzfckyY0C0/j reCOrLyDGzSxBIoVB5AHc2wqwONEogA0CRpbR6fdX76xrCu5d5W+3o8jjLqZKLqvDiP+ ZlGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=keqKBjLZSfQavofr1KknVuxPyJINzN8sPoLRoq5UyvA=; b=Re8/ANCAbRoFfiEQp98QVoEVqVfV+cc7R59n6SxPI6O8f3yTGto0CblHjDv/jwlkoA Ra2RcfWgrQfzU4bsFrvSNtaz+G62+ouEY5GFUzUceTbpFPKUyLFfT2V8hWxDDJQLY7bZ bGJXcvOSj3JQSVamV2pUkSPQNK0+KSiSZL2iy+KS1T5oWRd9QP179VSEMCgk/QpIqVIp y3ZC7bbVYJonsQri82WQvCe5rhErBlkK6y/ZiznCFBtGPLKuzCGINEXU/bas4yEqm6/p veGMc+xP2dFIZANdC18KcQxdvizcVe2VRAU6WN8nVxNABBPnzl+rx0CqQ45rsrUAJMs5 r6OQ== X-Gm-Message-State: AOAM532HjiwHXghTMFbWjwWaag6mcJ/2o/BuDOKUcFMEfddYL17PRONQ UUOIDG2MB2g2zEfbgU1CMlomv6J0BHY7ug== X-Received: by 2002:a05:6000:1564:: with SMTP id 4mr3273789wrz.56.1644320409819; Tue, 08 Feb 2022 03:40:09 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:09 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 30/39] hw/intc/arm_gicv3_its: Pass CTEntry to update_cte() Date: Tue, 8 Feb 2022 11:39:39 +0000 Message-Id: <20220208113948.3217356-31-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::434 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::434; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x434.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Make update_cte() take a CTEntry struct rather than all the fields of the new CTE as separate arguments. This brings it into line with the update_dte() API. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-6-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 482a71ba73c..b94775fd379 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -418,22 +418,25 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; } -static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid, - uint64_t rdbase) +/* + * Update the Collection Table entry for @icid to @cte. Returns true + * on success, false if there was a memory access error. + */ +static bool update_cte(GICv3ITSState *s, uint16_t icid, const CTEntry *cte) { AddressSpace *as = &s->gicv3->dma_as; uint64_t entry_addr; - uint64_t cte = 0; + uint64_t cteval = 0; MemTxResult res = MEMTX_OK; if (!s->ct.valid) { return true; } - if (valid) { + if (cte->valid) { /* add mapping entry to collection table */ - cte = FIELD_DP64(cte, CTE, VALID, 1); - cte = FIELD_DP64(cte, CTE, RDBASE, rdbase); + cteval = FIELD_DP64(cteval, CTE, VALID, 1); + cteval = FIELD_DP64(cteval, CTE, RDBASE, cte->rdbase); } entry_addr = table_entry_addr(s, &s->ct, icid, &res); @@ -446,27 +449,26 @@ static bool update_cte(GICv3ITSState *s, uint16_t icid, bool valid, return true; } - address_space_stq_le(as, entry_addr, cte, MEMTXATTRS_UNSPECIFIED, &res); + address_space_stq_le(as, entry_addr, cteval, MEMTXATTRS_UNSPECIFIED, &res); return res == MEMTX_OK; } static ItsCmdResult process_mapc(GICv3ITSState *s, const uint64_t *cmdpkt) { uint16_t icid; - uint64_t rdbase; - bool valid; + CTEntry cte; icid = cmdpkt[2] & ICID_MASK; - rdbase = (cmdpkt[2] & R_MAPC_RDBASE_MASK) >> R_MAPC_RDBASE_SHIFT; - rdbase &= RDBASE_PROCNUM_MASK; + cte.rdbase = (cmdpkt[2] & R_MAPC_RDBASE_MASK) >> R_MAPC_RDBASE_SHIFT; + cte.rdbase &= RDBASE_PROCNUM_MASK; - valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; + cte.valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; - if ((icid >= s->ct.num_entries) || (rdbase >= s->gicv3->num_cpu)) { + if ((icid >= s->ct.num_entries) || (cte.rdbase >= s->gicv3->num_cpu)) { qemu_log_mask(LOG_GUEST_ERROR, "ITS MAPC: invalid collection table attributes " - "icid %d rdbase %" PRIu64 "\n", icid, rdbase); + "icid %d rdbase %u\n", icid, cte.rdbase); /* * in this implementation, in case of error * we ignore this command and move onto the next @@ -475,7 +477,7 @@ static ItsCmdResult process_mapc(GICv3ITSState *s, const uint64_t *cmdpkt) return CMD_CONTINUE; } - return update_cte(s, icid, valid, rdbase) ? CMD_CONTINUE : CMD_STALL; + return update_cte(s, icid, &cte) ? CMD_CONTINUE : CMD_STALL; } /* From patchwork Tue Feb 8 11:39:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540775 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp478182imo; Tue, 8 Feb 2022 05:12:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJzagbLAgw8cYMry5cmZn/E8hIBnz6oWh4KxbHa16cNgcpR7B8q+nMM5+XztrmB0k9F0n3ip X-Received: by 2002:a25:328a:: with SMTP id y132mr3993774yby.575.1644325928120; Tue, 08 Feb 2022 05:12:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644325928; cv=none; d=google.com; s=arc-20160816; b=yFrN9HZ5PqIF4j+lzTB1joyfwciP6H79RUyA8JHpqiQwt6JIp4aRWPilHH8niAxP8G wqw59vWb/U8r71ed50xelKsQUqYBV9R3HzSv11YV9Gl3Q1Q+b0Ery216Za1dMcGoPmht rRuhv7UTDZG91IZwL/OsoppimyhocM/SxwyqlDBD2ZKtUUg9JSxjDjM+kALFc3uQLiJS +h+x9WSyZ6zlUZ+QhbwfCcXPgyPyDqjJwaF3+nzV43Zp+jwWhvajZbeIsHosaS+bRPw2 K/Vls2V4KbuEVA3yHIHEbma/OM1L9ZZ89liTCYEA5s/WyWZ7EQOJV+uLciPwhs6WEQkS eXzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=xfspF6EAoKjns9Lx2RLE19pfQhU8M3s3hFNN5x9GJpc=; b=Z9LJ75t1jGR2QbOEgi3nFCDQrXs36u10ZOYb7n0vFfmUkB4tuLd/SUZGRCHiquSXyX wxB4vesBQWHqvOa80S8PrAigk4JCq7V3nuCQb/8mJtDhHk63lRAvzRt3OIGU3dFj/co6 6rg685+/ZcCyDEWgNapcBDstC2Px8FzD5qhYJSNGrf9Z7XCz904uXeHkD7rstn+JDVnt uQdh2CEMd1uQGGUGZY7Z4NQKTL09OBFeSXvmwLRsgA9j0vM9WVFjLb/SDhCnIf8d/EUv 57QN+T3PUXd3A2hBvTljJQL2TkrNo54Y1E0+N/Zm1bGHfM7xlpxDKtuwVuLfhwWe/D86 TBbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=is0L+Ko+; 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=pass (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 124si8797450ybv.759.2022.02.08.05.12.07 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:12:08 -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=pass header.i=@linaro.org header.s=google header.b=is0L+Ko+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58798 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQHu-0004Lb-Tp for patch@linaro.org; Tue, 08 Feb 2022 08:12:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35118) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-000163-05 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:44 -0500 Received: from [2a00:1450:4864:20::436] (port=40815 helo=mail-wr1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqx-0002LD-Sg for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:19 -0500 Received: by mail-wr1-x436.google.com with SMTP id s18so30187247wrv.7 for ; Tue, 08 Feb 2022 03:40:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=xfspF6EAoKjns9Lx2RLE19pfQhU8M3s3hFNN5x9GJpc=; b=is0L+Ko+xtPghWNztjUtbpDpYWWYEIoCvHw8aOv6pkBOV5q9O1srLl1InLPPMUInFM XWw6umYnlf84edcQmrctgrMwAoLdkEba3Wqcn/DpfeasKd0ohs1LsTujSQcxVjJp70Hn b7fyV7EBjl0WcIkaqAM2yGjG7cBsUK6U9gdWXbIcvf2L7rgrzgaZNI7pnYWWWr/S0A+u Mh/yNyqLxO38IZP9TqeJeCU2Ir5uq08FbHcy9SMQ//jcK3XBM7/rhJVUZnbI+HwkYFPj N4gCEFO719/UAQ0mIA3173q/3qaWV6BEh8nIkj8B4QjVINQ4/HoTFDYX9e03FviJ/Dc+ OyGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xfspF6EAoKjns9Lx2RLE19pfQhU8M3s3hFNN5x9GJpc=; b=WP81f8wTVWTOqyR9spoTf7LaA3WjciFsP2wUjRWookYBU/U4LLFtfXeK/YJmaGvxZg CVSeELpVv/CZB/g4MF01rLKR5J1iQj1ZEbUhFoD+7SPo3NCtRtHBnWoISm8bgWxtaf73 AgeRtWeTmW/fY9FybIV9CSWtRsPG4QZEeNAa81B+DZuept+zBT1xF9EsxhaZAx6V3Asz h4NUJWVuJqgaKtE+wjSW8pzSGTa9tLzmb7M0Ck/eJI199RcqMKtMuuTcJClgkPfWMHUT 60US4Kg2pFaDtHzSmP9I2jmDgASzVP8OrafyfD0U9SgKoW7by2YNUTZSJySqApRmQqj5 IjBw== X-Gm-Message-State: AOAM532hzGnRwHuXf/+EsngjNgkxI0FH/0CjHkXLmY9T8C3bsA7H0aT3 7FmdgYjDbGbD/6BsJefJtkKBhEcEUx74QA== X-Received: by 2002:a5d:64e9:: with SMTP id g9mr3210636wri.341.1644320410689; Tue, 08 Feb 2022 03:40:10 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:10 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 31/39] hw/intc/arm_gicv3_its: Fix address calculation in get_ite() and update_ite() Date: Tue, 8 Feb 2022 11:39:40 +0000 Message-Id: <20220208113948.3217356-32-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::436 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" In get_ite() and update_ite() we work with a 12-byte in-guest-memory table entry, which we intend to handle as an 8-byte value followed by a 4-byte value. Unfortunately the calculation of the address of the 4-byte value is wrong, because we write it as: table_base_address + (index * entrysize) + 4 (obfuscated by the way the expression has been written) when it should be + 8. This bug meant that we overwrote the top bytes of the 8-byte value with the 4-byte value. There are no guest-visible effects because the top half of the 8-byte value contains only the doorbell interrupt field, which is used only in GICv4, and the two bugs in the "write ITE" and "read ITE" codepaths cancel each other out. We can't simply change the calculation, because this would break migration of a (TCG) guest from the old version of QEMU which had in-guest-memory interrupt tables written using the buggy version of update_ite(). We must also at the same time change the layout of the fields within the ITE_L and ITE_H values so that the in-memory locations of the fields we care about (VALID, INTTYPE, INTID and ICID) stay the same. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-7-peter.maydell@linaro.org --- hw/intc/gicv3_internal.h | 19 ++++++++++--------- hw/intc/arm_gicv3_its.c | 28 +++++++++++----------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/hw/intc/gicv3_internal.h b/hw/intc/gicv3_internal.h index 60c8617e4e4..2bf1baef047 100644 --- a/hw/intc/gicv3_internal.h +++ b/hw/intc/gicv3_internal.h @@ -370,22 +370,23 @@ FIELD(MOVI_2, ICID, 0, 16) * 12 bytes Interrupt translation Table Entry size * as per Table 5.3 in GICv3 spec * ITE Lower 8 Bytes - * Bits: | 49 ... 26 | 25 ... 2 | 1 | 0 | - * Values: | Doorbell | IntNum | IntType | Valid | + * Bits: | 63 ... 48 | 47 ... 32 | 31 ... 26 | 25 ... 2 | 1 | 0 | + * Values: | vPEID | ICID | unused | IntNum | IntType | Valid | * ITE Higher 4 Bytes - * Bits: | 31 ... 16 | 15 ...0 | - * Values: | vPEID | ICID | - * (When Doorbell is unused, as it always is in GICv3, it is 1023) + * Bits: | 31 ... 25 | 24 ... 0 | + * Values: | unused | Doorbell | + * (When Doorbell is unused, as it always is for INTYPE_PHYSICAL, + * the value of that field in memory cannot be relied upon -- older + * versions of QEMU did not correctly write to that memory.) */ #define ITS_ITT_ENTRY_SIZE 0xC FIELD(ITE_L, VALID, 0, 1) FIELD(ITE_L, INTTYPE, 1, 1) FIELD(ITE_L, INTID, 2, 24) -FIELD(ITE_L, DOORBELL, 26, 24) - -FIELD(ITE_H, ICID, 0, 16) -FIELD(ITE_H, VPEID, 16, 16) +FIELD(ITE_L, ICID, 32, 16) +FIELD(ITE_L, VPEID, 48, 16) +FIELD(ITE_H, DOORBELL, 0, 24) /* Possible values for ITE_L INTTYPE */ #define ITE_INTTYPE_VIRTUAL 0 diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index b94775fd379..48eaf20a6c9 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -173,14 +173,12 @@ static bool update_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, { AddressSpace *as = &s->gicv3->dma_as; MemTxResult res = MEMTX_OK; + hwaddr iteaddr = dte->ittaddr + eventid * ITS_ITT_ENTRY_SIZE; - address_space_stq_le(as, dte->ittaddr + (eventid * (sizeof(uint64_t) + - sizeof(uint32_t))), ite.itel, MEMTXATTRS_UNSPECIFIED, - &res); + address_space_stq_le(as, iteaddr, ite.itel, MEMTXATTRS_UNSPECIFIED, &res); if (res == MEMTX_OK) { - address_space_stl_le(as, dte->ittaddr + (eventid * (sizeof(uint64_t) + - sizeof(uint32_t))) + sizeof(uint32_t), ite.iteh, + address_space_stl_le(as, iteaddr + 8, ite.iteh, MEMTXATTRS_UNSPECIFIED, &res); } if (res != MEMTX_OK) { @@ -196,16 +194,12 @@ static bool get_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, AddressSpace *as = &s->gicv3->dma_as; bool status = false; IteEntry ite = {}; + hwaddr iteaddr = dte->ittaddr + eventid * ITS_ITT_ENTRY_SIZE; - ite.itel = address_space_ldq_le(as, dte->ittaddr + - (eventid * (sizeof(uint64_t) + - sizeof(uint32_t))), MEMTXATTRS_UNSPECIFIED, - res); + ite.itel = address_space_ldq_le(as, iteaddr, MEMTXATTRS_UNSPECIFIED, res); if (*res == MEMTX_OK) { - ite.iteh = address_space_ldl_le(as, dte->ittaddr + - (eventid * (sizeof(uint64_t) + - sizeof(uint32_t))) + sizeof(uint32_t), + ite.iteh = address_space_ldl_le(as, iteaddr + 8, MEMTXATTRS_UNSPECIFIED, res); if (*res == MEMTX_OK) { @@ -213,7 +207,7 @@ static bool get_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, int inttype = FIELD_EX64(ite.itel, ITE_L, INTTYPE); if (inttype == ITE_INTTYPE_PHYSICAL) { *pIntid = FIELD_EX64(ite.itel, ITE_L, INTID); - *icid = FIELD_EX32(ite.iteh, ITE_H, ICID); + *icid = FIELD_EX64(ite.itel, ITE_L, ICID); status = true; } } @@ -412,8 +406,8 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, ite.itel = FIELD_DP64(ite.itel, ITE_L, VALID, true); ite.itel = FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYSICAL); ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, pIntid); - ite.itel = FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS); - ite.iteh = FIELD_DP32(ite.iteh, ITE_H, ICID, icid); + ite.itel = FIELD_DP64(ite.itel, ITE_L, ICID, icid); + ite.iteh = FIELD_DP32(ite.iteh, ITE_H, DOORBELL, INTID_SPURIOUS); return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; } @@ -688,8 +682,8 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) ite.itel = FIELD_DP64(ite.itel, ITE_L, VALID, 1); ite.itel = FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYSICAL); ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, intid); - ite.itel = FIELD_DP64(ite.itel, ITE_L, DOORBELL, INTID_SPURIOUS); - ite.iteh = FIELD_DP32(ite.iteh, ITE_H, ICID, new_icid); + ite.itel = FIELD_DP64(ite.itel, ITE_L, ICID, new_icid); + ite.iteh = FIELD_DP32(ite.iteh, ITE_H, DOORBELL, INTID_SPURIOUS); return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; } From patchwork Tue Feb 8 11:39:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540794 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp542091imo; Tue, 8 Feb 2022 06:38:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwAnbHvl/RYaZe4QqcQWmExqBwXRnE2k+FFws3PwV51zE4Mlieam1qfAPlExsAXeQWrT9y/ X-Received: by 2002:a81:ad4e:: with SMTP id l14mr4731461ywk.364.1644331097988; Tue, 08 Feb 2022 06:38:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644331097; cv=none; d=google.com; s=arc-20160816; b=GspPqhWc4YGAQlhWMx8PwiwfbLdvpcIIDBPik9b6mFrwQP5n8rU6OGgiQdVvSdfjrf 6gcvEjZLdzpTm0sVLbR4q1Tto7LbBSslge3kSgWO0cwd7iPfFcbUxtXRrO6mXAZYsutE sv1F+S9Fl1Owu77I03te3NTOVDbcktRyfHTlQCbh1fWvtEQBpFFdAnojaulSDy310N9B 5/t9ezXqpx9V8L6xfT88nb0TX3BFogv6Sl+lDg7Cs5VdeqqCGxHgXkp+iOkDvqNLJINp 9vDHg7xO+1e8LzSuFcQpLRY9KJFBMKlLYJRXLB5/2R1k21ugrzx3xeFpbDOJLBNl1/MK Lt7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=0nAIsli8o+pZmkYitfIfjW6xhVr7iIIvjz1VT24XEHc=; b=mB0nJHC2xkn/d3t0hiSUlao6diOq+LX92jMy1O+tL7WgcSda9eoV/GvGDKjTqgY0NS WLlYSiKSvYpUknA/JTudw3HaVi1KAiDkTJ1fbPnaEw95BMyC4ro9LQqRht9VvfNAWOZf LpIrP8E85qUxZWZkelTii6ny+4yqh52rar01kYxSNKFrWEKz22aCO40V4SfhV6HBpQh9 zWP/ygepSA//fSlI3WH2fP7cP/7wyVWmKUzeiafJN/7EfyFef+WDl+J1Z9LTzX0cwsGV algzxorXzD/LG+XnGpazYjfSJRKj7QC2GTuZNzJy15QpW27a5zzrdEhsm253UOs7MRMP uh5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Si1WSiXz; 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=pass (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 o5si9260746ybp.630.2022.02.08.06.38.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:38:17 -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=pass header.i=@linaro.org header.s=google header.b=Si1WSiXz; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39670 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHRdJ-0001St-FE for patch@linaro.org; Tue, 08 Feb 2022 09:38:17 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-000169-4K for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:45 -0500 Received: from [2a00:1450:4864:20::431] (port=33400 helo=mail-wr1-x431.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqy-0002LP-GG for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:22 -0500 Received: by mail-wr1-x431.google.com with SMTP id e3so16229294wra.0 for ; Tue, 08 Feb 2022 03:40:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0nAIsli8o+pZmkYitfIfjW6xhVr7iIIvjz1VT24XEHc=; b=Si1WSiXzccJdh9jC6OBjWDRKzZVOLnln9gs0SODMd1wNQXd+oAO7SNtEeu2APDgkJV +xMng2bRD2tUaWS8J2Gu+goj/sFVo5CCUiDP2T/R3lD+KhVb3RwbfWa9L14s8zQ4Ri3i S4YbxKVA79ravMX3o/Dba8Zqe2OSdyDrY6yLMJBgQYknaZ3y9ItOIcoNG/qLnXQfTh8o bKSKbqBPTSLfHGpO8NvVs1SgTP7Uc++HpNHX0g7OHukOPCYyg57iGL7NcutGRQZ+toKX l6Nk466CYK410JiRm5iteAK1NXkpk4Nc7qgFmIu14bFowfJg22tTOgJzHF7KGSmKcGbk tz9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0nAIsli8o+pZmkYitfIfjW6xhVr7iIIvjz1VT24XEHc=; b=vbhcCQmT9UOy+BhsETwhqxYcF1VOf8IJ75OR1kpYlHBZgNTuw1l+XqHS4ayb322UQN 4H86wDCzrKQaDo71Yptvsl2Ilr+ljzzKr93iXXT5NFk1XowAmfYqSnFksPvAgN5MqBv4 94CKZsffirmgs+g4PFs0295Bp/WmnfDxHMC4Rii/20BhrO0yMjGWFyeY0twZve/fKiiL oAaMxD7I+mu3+HML+vmIYPPhbl6RYWJCNYfVHKs/hO6HHGKd5opTWTJdCtZ4YaroXfom Bk5TXw1Curea433cmz3uA0xFYT1opy2uA8r951GHFoHOQqOut0YHpIVrfl6jX7dhYMaj stjA== X-Gm-Message-State: AOAM530o69rgpiE0W2DVOL+OeCNjzMhbdmk3EdajpI5rzFDrWhURMb82 Xvageukg6ePvB1Pib6+1wAs8q0paZLhkiA== X-Received: by 2002:a5d:560c:: with SMTP id l12mr3270359wrv.647.1644320411298; Tue, 08 Feb 2022 03:40:11 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:10 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 32/39] hw/intc/arm_gicv3_its: Avoid nested ifs in get_ite() Date: Tue, 8 Feb 2022 11:39:41 +0000 Message-Id: <20220208113948.3217356-33-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::431 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::431; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x431.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01, T_SPF_TEMPERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" The get_ite() code has some awkward nested if statements; clean them up by returning early if the memory accesses fail. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-8-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 48eaf20a6c9..6975a349f62 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -197,20 +197,22 @@ static bool get_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, hwaddr iteaddr = dte->ittaddr + eventid * ITS_ITT_ENTRY_SIZE; ite.itel = address_space_ldq_le(as, iteaddr, MEMTXATTRS_UNSPECIFIED, res); + if (*res != MEMTX_OK) { + return false; + } - if (*res == MEMTX_OK) { - ite.iteh = address_space_ldl_le(as, iteaddr + 8, - MEMTXATTRS_UNSPECIFIED, res); + ite.iteh = address_space_ldl_le(as, iteaddr + 8, + MEMTXATTRS_UNSPECIFIED, res); + if (*res != MEMTX_OK) { + return false; + } - if (*res == MEMTX_OK) { - if (FIELD_EX64(ite.itel, ITE_L, VALID)) { - int inttype = FIELD_EX64(ite.itel, ITE_L, INTTYPE); - if (inttype == ITE_INTTYPE_PHYSICAL) { - *pIntid = FIELD_EX64(ite.itel, ITE_L, INTID); - *icid = FIELD_EX64(ite.itel, ITE_L, ICID); - status = true; - } - } + if (FIELD_EX64(ite.itel, ITE_L, VALID)) { + int inttype = FIELD_EX64(ite.itel, ITE_L, INTTYPE); + if (inttype == ITE_INTTYPE_PHYSICAL) { + *pIntid = FIELD_EX64(ite.itel, ITE_L, INTID); + *icid = FIELD_EX64(ite.itel, ITE_L, ICID); + status = true; } } return status; From patchwork Tue Feb 8 11:39:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540773 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp474732imo; Tue, 8 Feb 2022 05:07:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyTE87NV4v4ur1cpZKSvaTN9e79y6zyM0a69aStUwcxMJ7PGOUKQ3/HRQvol3tLwclLh4w+ X-Received: by 2002:a81:e202:: with SMTP id p2mr2287716ywl.22.1644325667104; Tue, 08 Feb 2022 05:07:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644325667; cv=none; d=google.com; s=arc-20160816; b=C2t4WADSatmy8tfZSiJXmX/CWokGatBpypDPBiBCsp2dtBvMI0QlkxivEOk7h9sLuY xRreCHqwDU1Oyjq3ablNs1upy/kaeEQXQ/yEa+M6AuUstZpdrl75Z22tgs3dJhHcXhFy srhn5aeEJlZNtOX7c/eOQH0R+IHyirClf8SPLS9FOq7C1TbsVPt6UKNMIyvz/4mdanEI Q/A9bWfQ57eopP4MDOVWQ4a3izSSAeQl7MZQHS7hmErscbmF4DiLrDt96WX9/6k712UF jf3Wb4Jtlht/Ztlm78lWwA8RJzvvh8nwXfebq0WFrDjbelgqoCdbONZglrJzDxKjNbjc BsIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=7NPk/GFLa2bDZPmnC/VZgNCWvHi+FsQr21PrNbAwHpY=; b=kg7117Q64j8L9v7ebR5gK+Ax6pdt2YdRbtCWtI0G7Xpy5u3kTB+O8Fa+7g6xc9oUr2 UV8xgPgQNLqC0uiTTGAwGWZFVhYfKsO0hKVP6HzKsv2gKA+4jg1zIIlwbIhstLhNpCxu miY4FZAWA3uqTbMV/VFgtFIINhMajvTF4HKJ1O4gRft+Uy+eMIrkEIVjejxPzGiIB3Oh Up9iT/Z8fU3rdlPSe2Giqxvd14eBTSBrq8nV20IoNl2BPBSpHjx5hXE4s/+S1YIzO2hL 6YjPnXMnOX08kWMCP+N1MARIyCmFHejPZOZEDr31SV3w7dd2i2bXa1PGmYb9fyc1nlRQ xpAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KPQXthcN; 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=pass (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 k186si9033955ywb.59.2022.02.08.05.07.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:07:47 -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=pass header.i=@linaro.org header.s=google header.b=KPQXthcN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52208 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQDi-00080U-Ik for patch@linaro.org; Tue, 08 Feb 2022 08:07:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-000164-2N for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:44 -0500 Received: from [2a00:1450:4864:20::436] (port=39811 helo=mail-wr1-x436.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqz-0002Ld-7D for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:20 -0500 Received: by mail-wr1-x436.google.com with SMTP id d27so1899805wrc.6 for ; Tue, 08 Feb 2022 03:40:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7NPk/GFLa2bDZPmnC/VZgNCWvHi+FsQr21PrNbAwHpY=; b=KPQXthcNeJhfk9sbacfaiaOCqDuteBRzg+IYuNL/4bz7Ti8tUDlPmbS4VaR8I8keuE VNMjFXKXfJuvpf60NTzV04oB907Q8dsqPsSDW6FKsPuTYHvUkMia4NBGBgaojeYR3bXp yFoMPiAD6bJ3pYisfQ4bA/TI9ZLY2v8tq52wIB7wV7dTyzk4NdyUuzTtEyvjqA9MftsY uVPHM+1xtDMF9mriEH0wkRPtYrIFFvpPRlOQIFGh+WpRnDiUuzvoM3iRsiHOsDicbnMZ 0YW10X+9hQb9BwMKbRYUFPWqKWLaWzHlJXinSQUFWjxDXcpoIHUc6mIvih8x7UmD8OyM zsDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7NPk/GFLa2bDZPmnC/VZgNCWvHi+FsQr21PrNbAwHpY=; b=kJCz8cVdPinxjOLNZM6GcDSydGnxtQ1TvMZ9bljUrfZtjvXUueErM9qvOwhKwU4F+3 D7MXnq/eMI5nJt6ZszCqhAHPc17sNI0Fe4tma30V4C//nuv+hPHgDGUjzFPbbb/vo1lz 8EI5qWlvIN/FGixLjoXsKRIG0d9QyUvEqmMC6RM/MR+PAaFPfdYT1/KuYqj8BcTCmxiv 8VtIkGa50+1YPBPOGezGifsw3JPI/dQtt7uk6/0/zEVsk1iZSS8fAfeRJXVic0ichozt rnXi6vlzJV48I2UNDvKNnkbJxsnNMBKRWhz2dbmPy/uXMWW662MLSR+ZChsfFR0tUsyb 7cTA== X-Gm-Message-State: AOAM531bj6K4cKzXPEsUJXZ0UzJ7Uvg9S7plJxpVq8zISNml8rVH4dDm hXGQtX3NrfP3mhP0fJKh75Pi8hqnVYfSig== X-Received: by 2002:a5d:59af:: with SMTP id p15mr3311260wrr.488.1644320411987; Tue, 08 Feb 2022 03:40:11 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:11 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 33/39] hw/intc/arm_gicv3_its: Pass ITE values back from get_ite() via a struct Date: Tue, 8 Feb 2022 11:39:42 +0000 Message-Id: <20220208113948.3217356-34-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::436 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x436.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" In get_ite() we currently return the caller some of the fields of an Interrupt Table Entry via a set of pointer arguments, and validate some of them internally (interrupt type and valid bit) to return a simple true/false 'valid' indication. Define a new ITEntry struct which has all the fields that the in-memory ITE has, and bring the get_ite() function in to line with get_dte() and get_cte(). This paves the way for handling virtual interrupts, which will want a different subset of the fields in the ITE. Handling them under the old "lots of pointer arguments" scheme would have meant a confusingly large set of arguments for this function. The new struct ITEntry is obviously confusably similar to the existing IteEntry struct, whose fields are the raw 12 bytes of the in-memory ITE. In the next commit we will make update_ite() use ITEntry instead of IteEntry, which will allow us to delete the IteEntry struct and remove the confusion. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-9-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 102 ++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 6975a349f62..bd741085022 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -57,6 +57,16 @@ typedef struct CTEntry { uint32_t rdbase; } CTEntry; +typedef struct ITEntry { + bool valid; + int inttype; + uint32_t intid; + uint32_t doorbell; + uint32_t icid; + uint32_t vpeid; +} ITEntry; + + /* * The ITS spec permits a range of CONSTRAINED UNPREDICTABLE options * if a command parameter is not correct. These include both "stall @@ -188,34 +198,38 @@ static bool update_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, } } -static bool get_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, - uint16_t *icid, uint32_t *pIntid, MemTxResult *res) +/* + * Read the Interrupt Table entry at index @eventid from the table specified + * by the DTE @dte. On success, we return MEMTX_OK and populate the ITEntry + * struct @ite accordingly. If there is an error reading memory then we return + * the error code. + */ +static MemTxResult get_ite(GICv3ITSState *s, uint32_t eventid, + const DTEntry *dte, ITEntry *ite) { AddressSpace *as = &s->gicv3->dma_as; - bool status = false; - IteEntry ite = {}; + MemTxResult res = MEMTX_OK; + uint64_t itel; + uint32_t iteh; hwaddr iteaddr = dte->ittaddr + eventid * ITS_ITT_ENTRY_SIZE; - ite.itel = address_space_ldq_le(as, iteaddr, MEMTXATTRS_UNSPECIFIED, res); - if (*res != MEMTX_OK) { - return false; + itel = address_space_ldq_le(as, iteaddr, MEMTXATTRS_UNSPECIFIED, &res); + if (res != MEMTX_OK) { + return res; } - ite.iteh = address_space_ldl_le(as, iteaddr + 8, - MEMTXATTRS_UNSPECIFIED, res); - if (*res != MEMTX_OK) { - return false; + iteh = address_space_ldl_le(as, iteaddr + 8, MEMTXATTRS_UNSPECIFIED, &res); + if (res != MEMTX_OK) { + return res; } - if (FIELD_EX64(ite.itel, ITE_L, VALID)) { - int inttype = FIELD_EX64(ite.itel, ITE_L, INTTYPE); - if (inttype == ITE_INTTYPE_PHYSICAL) { - *pIntid = FIELD_EX64(ite.itel, ITE_L, INTID); - *icid = FIELD_EX64(ite.itel, ITE_L, ICID); - status = true; - } - } - return status; + ite->valid = FIELD_EX64(itel, ITE_L, VALID); + ite->inttype = FIELD_EX64(itel, ITE_L, INTTYPE); + ite->intid = FIELD_EX64(itel, ITE_L, INTID); + ite->icid = FIELD_EX64(itel, ITE_L, ICID); + ite->vpeid = FIELD_EX64(itel, ITE_L, VPEID); + ite->doorbell = FIELD_EX64(iteh, ITE_H, DOORBELL); + return MEMTX_OK; } /* @@ -258,13 +272,10 @@ static MemTxResult get_dte(GICv3ITSState *s, uint32_t devid, DTEntry *dte) static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, uint32_t eventid, ItsCmdType cmd) { - MemTxResult res = MEMTX_OK; uint64_t num_eventids; - uint16_t icid = 0; - uint32_t pIntid = 0; - bool ite_valid = false; DTEntry dte; CTEntry cte; + ITEntry ite; if (devid >= s->dt.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, @@ -292,26 +303,25 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, return CMD_CONTINUE; } - ite_valid = get_ite(s, eventid, &dte, &icid, &pIntid, &res); - if (res != MEMTX_OK) { + if (get_ite(s, eventid, &dte, &ite) != MEMTX_OK) { return CMD_STALL; } - if (!ite_valid) { + if (!ite.valid || ite.inttype != ITE_INTTYPE_PHYSICAL) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: invalid ITE\n", __func__); return CMD_CONTINUE; } - if (icid >= s->ct.num_entries) { + if (ite.icid >= s->ct.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid ICID 0x%x in ITE (table corrupted?)\n", - __func__, icid); + __func__, ite.icid); return CMD_CONTINUE; } - if (get_cte(s, icid, &cte) != MEMTX_OK) { + if (get_cte(s, ite.icid, &cte) != MEMTX_OK) { return CMD_STALL; } if (!cte.valid) { @@ -330,15 +340,15 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, } if ((cmd == CLEAR) || (cmd == DISCARD)) { - gicv3_redist_process_lpi(&s->gicv3->cpu[cte.rdbase], pIntid, 0); + gicv3_redist_process_lpi(&s->gicv3->cpu[cte.rdbase], ite.intid, 0); } else { - gicv3_redist_process_lpi(&s->gicv3->cpu[cte.rdbase], pIntid, 1); + gicv3_redist_process_lpi(&s->gicv3->cpu[cte.rdbase], ite.intid, 1); } if (cmd == DISCARD) { - IteEntry ite = {}; + IteEntry itee = {}; /* remove mapping from interrupt translation table */ - return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; + return update_ite(s, eventid, &dte, itee) ? CMD_CONTINUE : CMD_STALL; } return CMD_CONTINUE; } @@ -572,14 +582,13 @@ static ItsCmdResult process_movall(GICv3ITSState *s, const uint64_t *cmdpkt) static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) { - MemTxResult res = MEMTX_OK; - uint32_t devid, eventid, intid; - uint16_t old_icid, new_icid; - bool ite_valid; + uint32_t devid, eventid; + uint16_t new_icid; uint64_t num_eventids; IteEntry ite = {}; DTEntry dte; CTEntry old_cte, new_cte; + ITEntry old_ite; devid = FIELD_EX64(cmdpkt[0], MOVI_0, DEVICEID); eventid = FIELD_EX64(cmdpkt[1], MOVI_1, EVENTID); @@ -611,22 +620,21 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) return CMD_CONTINUE; } - ite_valid = get_ite(s, eventid, &dte, &old_icid, &intid, &res); - if (res != MEMTX_OK) { + if (get_ite(s, eventid, &dte, &old_ite) != MEMTX_OK) { return CMD_STALL; } - if (!ite_valid) { + if (!old_ite.valid || old_ite.inttype != ITE_INTTYPE_PHYSICAL) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: invalid ITE\n", __func__); return CMD_CONTINUE; } - if (old_icid >= s->ct.num_entries) { + if (old_ite.icid >= s->ct.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid ICID 0x%x in ITE (table corrupted?)\n", - __func__, old_icid); + __func__, old_ite.icid); return CMD_CONTINUE; } @@ -637,14 +645,14 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) return CMD_CONTINUE; } - if (get_cte(s, old_icid, &old_cte) != MEMTX_OK) { + if (get_cte(s, old_ite.icid, &old_cte) != MEMTX_OK) { return CMD_STALL; } if (!old_cte.valid) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes: " "invalid CTE for old ICID 0x%x\n", - __func__, old_icid); + __func__, old_ite.icid); return CMD_CONTINUE; } @@ -677,13 +685,13 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) /* Move the LPI from the old redistributor to the new one */ gicv3_redist_mov_lpi(&s->gicv3->cpu[old_cte.rdbase], &s->gicv3->cpu[new_cte.rdbase], - intid); + old_ite.intid); } /* Update the ICID field in the interrupt translation table entry */ ite.itel = FIELD_DP64(ite.itel, ITE_L, VALID, 1); ite.itel = FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYSICAL); - ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, intid); + ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, old_ite.intid); ite.itel = FIELD_DP64(ite.itel, ITE_L, ICID, new_icid); ite.iteh = FIELD_DP32(ite.iteh, ITE_H, DOORBELL, INTID_SPURIOUS); return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; From patchwork Tue Feb 8 11:39:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540795 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp546543imo; Tue, 8 Feb 2022 06:44:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxj4MYPmMQxA/6OTDFjgiuDHTisLGP3vfZmwClFHIIhYzGmuVSeDUV6DVoNfd0Zr8ARj4t2 X-Received: by 2002:a81:8b46:: with SMTP id e6mr5021830ywk.75.1644331484580; Tue, 08 Feb 2022 06:44:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644331484; cv=none; d=google.com; s=arc-20160816; b=HfOQOcZc9Ht7oUw0vpO6Mdj0Wv6fgrSB0rKaBEOQfza0eC5Oc1o2XP5m2V6iNg34VJ nczn2uU4YwOcdjYUV7Nzppfex1SmFV53msUpwlyAdTodYVrbN8c+PKLa8IAGCyZUo09y HdVhiayA5R9fr3Hw8GoYLVnMAa8Eb5kPh3u33SLf+Wd0NArfeQhiaGnf5c5Mw0gjobeR lKzU9OZOo7EqWEW3q6VTXNZPC2Om6T5t3c+6uJ9pcaSnWkslNs88Q8Ux5JXO8EPY3lj7 iJA+5rR5vynIjctQIrIPp1Vb/mQnm5/ezDjhwrbG7xRL+wjE270O5qccphpNLrVJtuTM I7MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=pDKWDRaOnUkRnKvjdAk2YeqA1RSpMi3f12OGrjJ3J00=; b=ozeoPw1xlfYtfhuTB2t65gzwjKpJYzULTBnq4hL9LFptlmhO9LReU2me1wUbqwYhmG hP+zVRsjWwgpAln28OZarrwul6IoYPIeGkkHqNTQKdwYT9D3m+CGzrnxhdSwfoKFjs1D KaoxUhNjr+IqQ4ASzNNK89DZIZvm3z2K2udfYQ+0pm+4O7KJegKGLeFbYuvU+xPdPFrr OnqPD9i70K1RP1TvHqHnHq9iMPfdtpM3Z3V9ska3EVvpocQRC8X5UIbWucMT12oU4vja tV/NW/pmi2WrhGVZlnwH4BjwSMRO2iVgdoVrIGRNXcWC7IfCbL3C22eg+92DPHPOuV/y Aa/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MvUcPyWn; 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=pass (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 e6si4061327ywa.232.2022.02.08.06.44.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 06:44:44 -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=pass header.i=@linaro.org header.s=google header.b=MvUcPyWn; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48742 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHRjY-0000SC-0b for patch@linaro.org; Tue, 08 Feb 2022 09:44:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-00016C-4I for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:44 -0500 Received: from [2a00:1450:4864:20::32b] (port=44559 helo=mail-wm1-x32b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOqz-0002Ln-T0 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:21 -0500 Received: by mail-wm1-x32b.google.com with SMTP id l35-20020a05600c1d2300b0034d477271c1so1399883wms.3 for ; Tue, 08 Feb 2022 03:40:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=pDKWDRaOnUkRnKvjdAk2YeqA1RSpMi3f12OGrjJ3J00=; b=MvUcPyWnRsJQ+JoDMD6sw9mQGhX9dqGa9Vb9qiCO/g7bS/PfIJmy/qti9njmfFeO3y uNCNzN923bx5Urq1wMhgLhc76PVm/0vqXB6gcxFMNjhc0jl/nYmV8J9S2uq271UDiojl /OA8vKbERY47SdYsMj9HIF0r3GsJQ+wSJ6UDD4k5EjHbAVtDmdTKz+309KrLijhYehcN 2NZ1ohW7RL0a5e7tIXp6yj30F4weqWTsurW4YO4mVl4Wh+GeLfzy8cYKfqVS05ACk/3J 0yYzOC5yxkC5ZyXWxdEkDCWxVkNYJHKuYgbJDCn+McYPLT1Yw3Cs84ecwuotJe/qfOMr crqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pDKWDRaOnUkRnKvjdAk2YeqA1RSpMi3f12OGrjJ3J00=; b=dBY9Alcr2083wDyWeFUEqhdNiAhLCuePBWWDvBDdnXsn4pB1rDL+kY7BsHNjBXHK9i 2EcdwREYb5XdvnrPxCRTXIvMENuwtlb2KccNT40vXtb9BzjyQfSTk/AGZ+LOtCVAN5Nl yvebTCy9AhVrz3xD061fwGDPD8Uww/O4vv2VCmnYwwsrYA2P6LSgHtAqaG1dsxWlnlOv Di6sk/1ZxRRTqak5Tpy5NdIw7PSsPVgL9Fcf2R4fV3ppOnnLzfwcQvxDDDJ2H+phRuwu QJQck10R7qfwijbJmMHkjNQk5tRkZ1OrjxMKYiLoVZQ17QZNWOXO2jXXtTXzind1iF9Z bHbw== X-Gm-Message-State: AOAM532ZcszzuF0ebHbgfBta37NMw6a46f0LSGgYMYmmLq3oFQLjhyrI WinhCuxF3N3fw0fu6k6lJIoXuV6N4KH56Q== X-Received: by 2002:a1c:f219:: with SMTP id s25mr767134wmc.119.1644320412610; Tue, 08 Feb 2022 03:40:12 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:12 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 34/39] hw/intc/arm_gicv3_its: Make update_ite() use ITEntry Date: Tue, 8 Feb 2022 11:39:43 +0000 Message-Id: <20220208113948.3217356-35-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32b (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32b.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Make the update_ite() struct use the new ITEntry struct, so that callers don't need to assemble the in-memory ITE data themselves, and only get_ite() and update_ite() need to care about that in-memory layout. We can then drop the no-longer-used IteEntry struct definition. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-10-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 62 +++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index bd741085022..e3b63efddcc 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -41,11 +41,6 @@ typedef enum ItsCmdType { INTERRUPT = 3, } ItsCmdType; -typedef struct { - uint32_t iteh; - uint64_t itel; -} IteEntry; - typedef struct DTEntry { bool valid; unsigned size; @@ -178,24 +173,35 @@ static MemTxResult get_cte(GICv3ITSState *s, uint16_t icid, CTEntry *cte) return MEMTX_OK; } +/* + * Update the Interrupt Table entry at index @evinted in the table specified + * by the dte @dte. Returns true on success, false if there was a memory + * access error. + */ static bool update_ite(GICv3ITSState *s, uint32_t eventid, const DTEntry *dte, - IteEntry ite) + const ITEntry *ite) { AddressSpace *as = &s->gicv3->dma_as; MemTxResult res = MEMTX_OK; hwaddr iteaddr = dte->ittaddr + eventid * ITS_ITT_ENTRY_SIZE; + uint64_t itel = 0; + uint32_t iteh = 0; - address_space_stq_le(as, iteaddr, ite.itel, MEMTXATTRS_UNSPECIFIED, &res); - - if (res == MEMTX_OK) { - address_space_stl_le(as, iteaddr + 8, ite.iteh, - MEMTXATTRS_UNSPECIFIED, &res); + if (ite->valid) { + itel = FIELD_DP64(itel, ITE_L, VALID, 1); + itel = FIELD_DP64(itel, ITE_L, INTTYPE, ite->inttype); + itel = FIELD_DP64(itel, ITE_L, INTID, ite->intid); + itel = FIELD_DP64(itel, ITE_L, ICID, ite->icid); + itel = FIELD_DP64(itel, ITE_L, VPEID, ite->vpeid); + iteh = FIELD_DP32(iteh, ITE_H, DOORBELL, ite->doorbell); } + + address_space_stq_le(as, iteaddr, itel, MEMTXATTRS_UNSPECIFIED, &res); if (res != MEMTX_OK) { return false; - } else { - return true; } + address_space_stl_le(as, iteaddr + 8, iteh, MEMTXATTRS_UNSPECIFIED, &res); + return res == MEMTX_OK; } /* @@ -346,9 +352,10 @@ static ItsCmdResult do_process_its_cmd(GICv3ITSState *s, uint32_t devid, } if (cmd == DISCARD) { - IteEntry itee = {}; + ITEntry ite = {}; /* remove mapping from interrupt translation table */ - return update_ite(s, eventid, &dte, itee) ? CMD_CONTINUE : CMD_STALL; + ite.valid = false; + return update_ite(s, eventid, &dte, &ite) ? CMD_CONTINUE : CMD_STALL; } return CMD_CONTINUE; } @@ -370,8 +377,8 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, uint64_t num_eventids; uint32_t num_intids; uint16_t icid = 0; - IteEntry ite = {}; DTEntry dte; + ITEntry ite; devid = (cmdpkt[0] & DEVID_MASK) >> DEVID_SHIFT; eventid = cmdpkt[1] & EVENTID_MASK; @@ -415,13 +422,13 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, } /* add ite entry to interrupt translation table */ - ite.itel = FIELD_DP64(ite.itel, ITE_L, VALID, true); - ite.itel = FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYSICAL); - ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, pIntid); - ite.itel = FIELD_DP64(ite.itel, ITE_L, ICID, icid); - ite.iteh = FIELD_DP32(ite.iteh, ITE_H, DOORBELL, INTID_SPURIOUS); - - return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; + ite.valid = true; + ite.inttype = ITE_INTTYPE_PHYSICAL; + ite.intid = pIntid; + ite.icid = icid; + ite.doorbell = INTID_SPURIOUS; + ite.vpeid = 0; + return update_ite(s, eventid, &dte, &ite) ? CMD_CONTINUE : CMD_STALL; } /* @@ -585,7 +592,6 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) uint32_t devid, eventid; uint16_t new_icid; uint64_t num_eventids; - IteEntry ite = {}; DTEntry dte; CTEntry old_cte, new_cte; ITEntry old_ite; @@ -689,12 +695,8 @@ static ItsCmdResult process_movi(GICv3ITSState *s, const uint64_t *cmdpkt) } /* Update the ICID field in the interrupt translation table entry */ - ite.itel = FIELD_DP64(ite.itel, ITE_L, VALID, 1); - ite.itel = FIELD_DP64(ite.itel, ITE_L, INTTYPE, ITE_INTTYPE_PHYSICAL); - ite.itel = FIELD_DP64(ite.itel, ITE_L, INTID, old_ite.intid); - ite.itel = FIELD_DP64(ite.itel, ITE_L, ICID, new_icid); - ite.iteh = FIELD_DP32(ite.iteh, ITE_H, DOORBELL, INTID_SPURIOUS); - return update_ite(s, eventid, &dte, ite) ? CMD_CONTINUE : CMD_STALL; + old_ite.icid = new_icid; + return update_ite(s, eventid, &dte, &old_ite) ? CMD_CONTINUE : CMD_STALL; } /* From patchwork Tue Feb 8 11:39:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540776 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp479756imo; Tue, 8 Feb 2022 05:14:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzo7qpILZ+uxm9KfiLAhV/OmXYNyi28wQsTYOuSz0EwpYo2BOVF5Cdfp24WcGXX9R6BRl5w X-Received: by 2002:a25:df48:: with SMTP id w69mr4425293ybg.13.1644326054845; Tue, 08 Feb 2022 05:14:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644326054; cv=none; d=google.com; s=arc-20160816; b=QswQ929NmS1c+7PB3i/Ncsk52UuuRpUp3DuxTTqeSbYpx+MXWJ8YlURk3nN74GjGxJ 3mjd+5uYRYpD9DQDQcfGJi33NhyfjHasb3xgBWZqPTyOeloT5i8Awms95igVK5Qg6b9s vE6AojCZwJOi6toRnb9yee8zY3b0ee+0qofd4Zp0pTNqAFAIjYPBy91SVyCsrtNpYpih YYyKnZ/X2gl67KrtNU2P+NDIaOYqyb3aIc3Clc1D3LSpPdGTNDCLpPvYPNBr2Jzqpt3e U+a+sox7lJOsr25KznmWtk0VFRnva6C406T5WwxVVZGOjlPaRWCMz4J+ateKrXh9QSbc 2v7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=zb3L1l1HvD2mZcRDMDBTPVZ3tas7ENOoWbQTgGqAIa8=; b=dNcodFiZgp9XAWAjPlF5y+rNqhDL1tRAAVl/9glJlDKKZFiDSSLb0jr/HjoVHQv2WH s+H7Q4G1hTf57MTVoDLq80HJFPZKaB84xlRARWda7U0R8cLL1QhlhQbEXt2rynWUnzOI /7BdkfuCwvohYZCEMKEU/3u2b6Eb/P9sKxQ8oVOCacpeRWs0XPIF96iMDzIKbHO9J43U /YKySAywGJ9eknsu4USYh7hIPEl8+Yi3/RxtNRiBK8i0NhKzqhkZp/p6tbKuNBjHuIVN H9+5buuDrLFN5qIWFMeEux9u7IdfhbWT/VIGwD+/wacTKDMgJH0f2m7bnmcYGQgGgdo5 n80Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WoOiYqQO; 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=pass (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 b129si8016051ywa.18.2022.02.08.05.14.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:14:14 -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=pass header.i=@linaro.org header.s=google header.b=WoOiYqQO; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:32790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQJy-0005tY-9r for patch@linaro.org; Tue, 08 Feb 2022 08:14:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-000168-4G for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:44 -0500 Received: from [2a00:1450:4864:20::329] (port=46703 helo=mail-wm1-x329.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOr1-0002M6-CU for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:23 -0500 Received: by mail-wm1-x329.google.com with SMTP id l67-20020a1c2546000000b00353951c3f62so1398299wml.5 for ; Tue, 08 Feb 2022 03:40:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zb3L1l1HvD2mZcRDMDBTPVZ3tas7ENOoWbQTgGqAIa8=; b=WoOiYqQOO+pnMGiVE91IdCDujMPI3vzW53E2HE7vR4HYxOCehBPRia6L+Aedxddhd1 s8/p5LEon5BYOrChl5dgNDnHt44LOz/GTfI+Yo7PCQ0zOLfwM8DItbGI9Iz2k8718Rgd FjRLvNuUJCZKie/qojIY8T6DXhiXfDrUXBX1yDVVJCNz2gqoVEQkqmJ122jsbsBZKU/X LYMeGFVEeWqsC0G/qHukc2KWDjIRDRPBk2iHzD0BNp4OUQegYysbWIdLdj5xRp5TkLf/ iR1b2c8SbMXdyUgLvqX+b2mQOSEuNwMS1OmO7ckHWP6rWlV4SAfcSPNMdXIovWRY8MT/ W6yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zb3L1l1HvD2mZcRDMDBTPVZ3tas7ENOoWbQTgGqAIa8=; b=u7VCT3+OnQPaEvft4N10bpJi5BkNOt8WRpRThSXdd9HhGTNAcyvoUImj3sE4Wy+pgy bvbOE+vcUG2xusfbKlgedSckvlfftDVuMflfwUV+OgANUYibzYRkO0IchXu3G/MTmeIC SeXZb+C+LHj+660ZnPPcvZOKav6Z9ueitf5x0OOcTHLOXn5SrKJGwE3Cjhc3oCfoJBwp /Pdwosyit47QUG1Tx3K1vxeXc66+D1FRtBW23+XvPtIDuS8tuF26LPocQGKqYCGT22At eQapCtr0bq30oASw4Nzd+aG49we7LKRCRaotd2T8YdPvmSbwrbGbnttGzLOGAMNGbhlU m7FQ== X-Gm-Message-State: AOAM533nx3jQ5b5zMNSBa0p4UtugLKGD01lYtO16eJg9GOR+wEl3dyrp /jrPcPiYefk6OrXARiO1vFs2p5aHBEECyg== X-Received: by 2002:a05:600c:1c23:: with SMTP id j35mr785520wms.138.1644320413520; Tue, 08 Feb 2022 03:40:13 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:12 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 35/39] hw/intc/arm_gicv3_its: Drop TableDesc and CmdQDesc valid fields Date: Tue, 8 Feb 2022 11:39:44 +0000 Message-Id: <20220208113948.3217356-36-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::329 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Currently we track in the TableDesc and CmdQDesc structs the state of the GITS_BASER and GITS_CBASER Valid bits. However we aren't very consistent abut checking the valid field: we test it in update_cte() and update_dte(), but not anywhere else we look things up in tables. The GIC specification says that it is UNPREDICTABLE if a guest fails to set any of these Valid bits before enabling the ITS via GITS_CTLR.Enabled. So we can choose to handle Valid == 0 as equivalent to a zero-length table. This is in fact how we're already catching this case in most of the table-access paths: when Valid is 0 we leave the num_entries fields in TableDesc or CmdQDesc set to zero, and then the out-of-bounds check "index >= num_entries" that we have to do anyway before doing any of these table lookups will always be true, catching the no-valid-table case without any extra code. So we can remove the checks on the valid field from update_cte() and update_dte(): since these happen after the bounds check there was never any case when the test could fail. That means the valid fields would be entirely unused, so just remove them. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-11-peter.maydell@linaro.org --- include/hw/intc/arm_gicv3_its_common.h | 2 -- hw/intc/arm_gicv3_its.c | 31 ++++++++++++-------------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/include/hw/intc/arm_gicv3_its_common.h b/include/hw/intc/arm_gicv3_its_common.h index 3e2ad2dff60..0f130494dd3 100644 --- a/include/hw/intc/arm_gicv3_its_common.h +++ b/include/hw/intc/arm_gicv3_its_common.h @@ -42,7 +42,6 @@ #define GITS_TRANSLATER 0x0040 typedef struct { - bool valid; bool indirect; uint16_t entry_sz; uint32_t page_sz; @@ -51,7 +50,6 @@ typedef struct { } TableDesc; typedef struct { - bool valid; uint32_t num_entries; uint64_t base_addr; } CmdQDesc; diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index e3b63efddcc..9735d609df2 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -442,10 +442,6 @@ static bool update_cte(GICv3ITSState *s, uint16_t icid, const CTEntry *cte) uint64_t cteval = 0; MemTxResult res = MEMTX_OK; - if (!s->ct.valid) { - return true; - } - if (cte->valid) { /* add mapping entry to collection table */ cteval = FIELD_DP64(cteval, CTE, VALID, 1); @@ -504,15 +500,11 @@ static bool update_dte(GICv3ITSState *s, uint32_t devid, const DTEntry *dte) uint64_t dteval = 0; MemTxResult res = MEMTX_OK; - if (s->dt.valid) { - if (dte->valid) { - /* add mapping entry to device table */ - dteval = FIELD_DP64(dteval, DTE, VALID, 1); - dteval = FIELD_DP64(dteval, DTE, SIZE, dte->size); - dteval = FIELD_DP64(dteval, DTE, ITTADDR, dte->ittaddr); - } - } else { - return true; + if (dte->valid) { + /* add mapping entry to device table */ + dteval = FIELD_DP64(dteval, DTE, VALID, 1); + dteval = FIELD_DP64(dteval, DTE, SIZE, dte->size); + dteval = FIELD_DP64(dteval, DTE, ITTADDR, dte->ittaddr); } entry_addr = table_entry_addr(s, &s->dt, devid, &res); @@ -901,7 +893,6 @@ static void extract_table_params(GICv3ITSState *s) } memset(td, 0, sizeof(*td)); - td->valid = FIELD_EX64(value, GITS_BASER, VALID); /* * If GITS_BASER.Valid is 0 for any then we will not process * interrupts. (GITS_TYPER.HCC is 0 for this implementation, so we @@ -909,8 +900,15 @@ static void extract_table_params(GICv3ITSState *s) * for the register corresponding to the Collection table but we * still have to process interrupts using non-memory-backed * Collection table entries.) + * The specification makes it UNPREDICTABLE to enable the ITS without + * marking each BASER as valid. We choose to handle these as if + * the table was zero-sized, so commands using the table will fail + * and interrupts requested via GITS_TRANSLATER writes will be ignored. + * This happens automatically by leaving the num_entries field at + * zero, which will be caught by the bounds checks we have before + * every table lookup anyway. */ - if (!td->valid) { + if (!FIELD_EX64(value, GITS_BASER, VALID)) { continue; } td->page_sz = page_sz; @@ -936,9 +934,8 @@ static void extract_cmdq_params(GICv3ITSState *s) num_pages = FIELD_EX64(value, GITS_CBASER, SIZE) + 1; memset(&s->cq, 0 , sizeof(s->cq)); - s->cq.valid = FIELD_EX64(value, GITS_CBASER, VALID); - if (s->cq.valid) { + if (FIELD_EX64(value, GITS_CBASER, VALID)) { s->cq.num_entries = (num_pages * GITS_PAGE_SIZE_4K) / GITS_CMDQ_ENTRY_SIZE; s->cq.base_addr = FIELD_EX64(value, GITS_CBASER, PHYADDR); From patchwork Tue Feb 8 11:39:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540769 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp460979imo; Tue, 8 Feb 2022 04:48:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuq8B8WYa0gW5Jx336knyaAUmENn4/V4EH30OJkRGa8/WY375ECVIRpd6wXC1zM5/kU9db X-Received: by 2002:a81:f10b:: with SMTP id h11mr4610267ywm.396.1644324515307; Tue, 08 Feb 2022 04:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644324515; cv=none; d=google.com; s=arc-20160816; b=AFudZ8mBx/LtsoRZkzppQBtNjtNDDht1g+ezDLr9sRIo88mYtEGLnfacO+9emJahio JbSQGqASCv5/1jbseZQ1z4+FRFzjzWTeNEtWvf8/o4dKSYJYHq2kfEgMqA/wz6IzM/Yl 1bksdp5Mh0IrfeDFbwWhwPTNRnXyqi/dSD0eJBVFFXuWV2TBN7yynhMAI9V7z6MhUI51 EJ059qUkPef8/4jK8L1Qq8JNDz2OO8JCGlDEolCWJ7AQUWZOfWtnvzU6v1Ef1oizQGFh SAWhprYWc0ud951gC+GZzLfc0U9Pb6f16DfXGc1pBJWTsgPk+NJi+9r6XAEy0dDGebZX 7dCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=uJSi79pD20H9mn2ISVJzcWT+Ek0/1qEnDg0RX82vzg4=; b=Fnr3D9VNTH5+vO0JmfjQ/zNN/mHceez7r8g5ZV5095rXMK4e3Ybi/gLnMJw+JFnNqw 2HpAvHRY0mAs+YbHdn45tu3Is0jBclF5Ph5s2v+RNoqrO+47UxGS/m8Eb5Uf54dqQEZE vmjkNbOYaTjTEoaOvt5lH9swvNdWRF9kHkxrbPbv2Z4wC3iGsPYkxmtMjc0eod+HNNhh XapCHp2kOM87h2xic9UvNmunPhrullxnXVF9esQ3RKDCC+ci4fa8xLd4ACCkJl+c83w/ enXYd3YTEVCz8UDpeHw9VUThXamz9veOrq/soTjN2X4RUx/U2XnJnZk3IB3locUYNG8k WlQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uvPUH5cg; 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=pass (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 u5si9791061yba.619.2022.02.08.04.48.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 04:48:35 -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=pass header.i=@linaro.org header.s=google header.b=uvPUH5cg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHPv7-0006Sd-7N for patch@linaro.org; Tue, 08 Feb 2022 07:48:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35134) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-00016A-4c for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:45 -0500 Received: from [2a00:1450:4864:20::330] (port=33396 helo=mail-wm1-x330.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOr1-0002Md-E7 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:22 -0500 Received: by mail-wm1-x330.google.com with SMTP id y6-20020a7bc186000000b0037bdc5a531eso737687wmi.0 for ; Tue, 08 Feb 2022 03:40:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=uJSi79pD20H9mn2ISVJzcWT+Ek0/1qEnDg0RX82vzg4=; b=uvPUH5cgksrJgQnxcGUSVFr/PIYVyy8o8aFbfc0eY8NJMu0Z9jcS1ud7ds6G6K2j5a zyh/7GrMHK2d2D8krtJedCK8zd80aVqsQ9dNTG2sdUi7Y6wOhGALsIRwIkoctlct0N63 aMN73whJkh64lYLPI4OaperCB2NS1Z0eYP9HKOl1ylK8QEPkYU0FHYzPGoYD7fHRPC0m ot4hmW2sVZgzN6zrJLvTp58Yxwr0rgvo4QaLKAtEJwn8B3pqjFq4ycZJdfFOFz0HaK1g xdql0jU2Ana25H4lrqnfg2gzVCFYV8DuOaXVKlVy06mgwbLzS3i+E4WGYXCr8y1jAR8C I7GA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uJSi79pD20H9mn2ISVJzcWT+Ek0/1qEnDg0RX82vzg4=; b=EsvjkfBqNqmriZj6ZydTc6CA0iqfDM4DSLVCONr1Y8eDvbaJ7ogkJf0pcie/Vtx1xK dpDkOBSTNAEq2NEUA/nGrVnPb3zsw5KoSDubBnibvrXNmvmxJ09QRC2uQC1HF0mcxC53 AImhSYqV+xw36mNYeHLYS76u6DJwVwnLlFuDyrR0Uf+Th/UpPNkEIMWwwfaHMNCKyHvl Hy0Xl9TL8kFw/IMNmB6zVfJlqDw/BJE4K6SJ8a5mVvxgSBqV1d7zEDsttftiBrxmQMfm nhdqWXMIqK4fQSuvc0K7IMGKOBhYMAsoXygq4JD9cM9BfCo+//qhnKEsmVBZp3DLsw87 8UHw== X-Gm-Message-State: AOAM532NHwX6qRHFDwQHUIOivRlR1TlcZtrkBjoovv4Co53UW8V8ZK+G GTIJh/6CsZkKip8GZUVXHm+ODooI4DMm4w== X-Received: by 2002:a1c:f210:: with SMTP id s16mr769201wmc.121.1644320414084; Tue, 08 Feb 2022 03:40:14 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:13 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 36/39] hw/intc/arm_gicv3_its: In MAPC with V=0, don't check rdbase field Date: Tue, 8 Feb 2022 11:39:45 +0000 Message-Id: <20220208113948.3217356-37-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::330 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::330; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x330.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" In the MAPC command, if V=0 this is a request to delete a collection table entry and the rdbase field of the command packet will not be used. In particular, the specification says that the "UNPREDICTABLE if rdbase is not valid" only applies for V=1. We were doing a check-and-log-guest-error on rdbase regardless of whether the V bit was set, and also (harmlessly but confusingly) storing the contents of the rdbase field into the updated collection table entry. Update the code so that if V=0 we don't check or use the rdbase field value. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-12-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 9735d609df2..069991f7f36 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -468,21 +468,21 @@ static ItsCmdResult process_mapc(GICv3ITSState *s, const uint64_t *cmdpkt) CTEntry cte; icid = cmdpkt[2] & ICID_MASK; - - cte.rdbase = (cmdpkt[2] & R_MAPC_RDBASE_MASK) >> R_MAPC_RDBASE_SHIFT; - cte.rdbase &= RDBASE_PROCNUM_MASK; - cte.valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; + if (cte.valid) { + cte.rdbase = (cmdpkt[2] & R_MAPC_RDBASE_MASK) >> R_MAPC_RDBASE_SHIFT; + cte.rdbase &= RDBASE_PROCNUM_MASK; + } else { + cte.rdbase = 0; + } - if ((icid >= s->ct.num_entries) || (cte.rdbase >= s->gicv3->num_cpu)) { + if (icid >= s->ct.num_entries) { + qemu_log_mask(LOG_GUEST_ERROR, "ITS MAPC: invalid ICID 0x%d", icid); + return CMD_CONTINUE; + } + if (cte.valid && cte.rdbase >= s->gicv3->num_cpu) { qemu_log_mask(LOG_GUEST_ERROR, - "ITS MAPC: invalid collection table attributes " - "icid %d rdbase %u\n", icid, cte.rdbase); - /* - * in this implementation, in case of error - * we ignore this command and move onto the next - * command in the queue - */ + "ITS MAPC: invalid RDBASE %u ", cte.rdbase); return CMD_CONTINUE; } From patchwork Tue Feb 8 11:39:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540778 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp483802imo; Tue, 8 Feb 2022 05:20:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJyk83baiZ8Jf6wRFiWUoushwHZ/pIhEP/CoBBIOtGAjel6ZRoyClW1rOSg93NfXvshzpR8Q X-Received: by 2002:a25:2943:: with SMTP id p64mr4472005ybp.37.1644326405236; Tue, 08 Feb 2022 05:20:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644326405; cv=none; d=google.com; s=arc-20160816; b=FapPtqb87qTSf6NOG2KssAIDAD6EHAeg7KLVVNQjoCswYtCBaOlH6ChWILq9s9Q1mq XZhZddyogofuN88zoPIlFpsMEI+RR91GU0g5R7HIm+SGafeCB19J93boyxlZcHizD5us EsC1JcHVn1Qn51elQtWS2Lvw72dpE2pvo5GrejOZZYogq3FVSFeaYI7bch5Vy1VQviP3 /jLOllTDNwixu0l49qln28fS4Uu949raobyCE8LoH3WPaDbw5SLfKRtgFU8Ztoy/JVHA Ih8mF572e8vTDTQqnEbDI4xCDb1XVaxGi4nlzpDQvguckUW2QUcLOHwaf+bHC73JTr0r hEVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=F8KmHfDV6ISGjnmWH8Yf3Cv+WlIGIG6n+5ETsKdMSPc=; b=w4199vsl6/XFTuj81YMZPgkoxm58+BjeT7J6P8iD0/E7sM5CNPGrzbODJEsnv1av6/ 1zvsBenrM15672KgMpgsWN6NYsxcbZfsYrxV2RSzQedMcRFP3LlqptOjbZJup9JMEryi iW0uYYn7cHO6cIXvSU+qcIJRFXo0h6yByFbt/0gTkcjuPx35TF2b//sCP5IW5Eyuiniy PNVU0sVHifLRXlJq7e0v2t7V/Rhu+5STQaG1VQ6COcoznvqB96CXjpb8pAizM9uHelra fiFP/3wHQPwjNaYGXGRgnx1D2TLYZg9Ofy7u8+4ZhqGb5nIVMYAUmmofKOCQJVhu8gHm 9E2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Lib5BiB7; 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=pass (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 t12si922774ybl.34.2022.02.08.05.20.05 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:20:05 -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=pass header.i=@linaro.org header.s=google header.b=Lib5BiB7; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39390 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQPc-0003Ua-NK for patch@linaro.org; Tue, 08 Feb 2022 08:20:04 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35128) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-000167-4H for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:44 -0500 Received: from [2a00:1450:4864:20::32a] (port=52219 helo=mail-wm1-x32a.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOr2-0002Nj-1r for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:23 -0500 Received: by mail-wm1-x32a.google.com with SMTP id r131so6389188wma.1 for ; Tue, 08 Feb 2022 03:40:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=F8KmHfDV6ISGjnmWH8Yf3Cv+WlIGIG6n+5ETsKdMSPc=; b=Lib5BiB7MViK2iEssWJCvEguDuJSMwzQNrrTCP38aKqT7SJzHaT8ZNo4OdKUcw7vOA H6BS98e+VagHow1EEOv0F2OfrBHyUNOGGqh2Iu0YKnjJ+gvNGkALV5Pf6NjZtmuCdJPV WifZHJHNP6ShQS54NQZgzEEOA1P8wqcdgqGD643NH6hIw5D8wizJu3vwOvqvar9SmhGL jMRCtaNsBtq7CHF45TsnTr7CGDE2MwLIy8yyF/7NpWpZgA/AxYUofAGqHV5jIglaWrD4 iXMjC8BNjdrYOFjqJPVw9wObkmTl1e5pdp3Scfh5RaoLNyuSNS+vtJz0jklEjW8f3fpt shJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=F8KmHfDV6ISGjnmWH8Yf3Cv+WlIGIG6n+5ETsKdMSPc=; b=kMOx4e0DsjpkdeOOMrLuYH6M49REWXdRL+yJ2N6APZdBJq/XhGaPlIuCfZXZdgh0Q7 Sd76KOJTgym5Uuf2P+RgBc1H66346PAk3RsqmoDDsnJ5hW70Fazz1bOraKpe+G7OLpUX jx0q3UuoBYlNgY0ZSVR6nkpY2cyF3J2Zb0RuCi+ekLcS1k749nUKDCGDg4sRQQM4tHs4 3bjsc4LykzjiJT2xLem+W2yfxC39ulXJmGMUkEyEZvuqF0RMr7/f7FTx04esHHQetA1L rKgqkVH3fyy8FfIRZgQPVhYfvGeOQPbH5YDCRGe6n05tGpDwzrzuwarouDUleAUa9tMi itCw== X-Gm-Message-State: AOAM532PAANlgh0j9OpXkbCgZjIit32DgAu+AW/cRxZcvMfsVocBAccU XJRShOP6pr5J70BBKjjknmnnrhzmVsWEgA== X-Received: by 2002:a05:600c:a4c:: with SMTP id c12mr774280wmq.48.1644320414744; Tue, 08 Feb 2022 03:40:14 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:14 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 37/39] hw/intc/arm_gicv3_its: Don't allow intid 1023 in MAPI/MAPTI Date: Tue, 8 Feb 2022 11:39:46 +0000 Message-Id: <20220208113948.3217356-38-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32a (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32a; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32a.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" When handling MAPI/MAPTI, we allow the supplied interrupt ID to be either 1023 or something in the valid LPI range. This is a mistake: only a real valid LPI is allowed. (The general behaviour of the ITS is that most interrupt ID fields require a value in the LPI range; the exception is that fields specifying a doorbell value, which are all in GICv4 commands, allow also 1023 to mean "no doorbell".) Remove the condition that incorrectly allows 1023 here. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-13-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 069991f7f36..8dade9440ac 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -406,8 +406,7 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, if ((icid >= s->ct.num_entries) || !dte.valid || (eventid >= num_eventids) || - (((pIntid < GICV3_LPI_INTID_START) || (pIntid >= num_intids)) && - (pIntid != INTID_SPURIOUS))) { + (((pIntid < GICV3_LPI_INTID_START) || (pIntid >= num_intids)))) { qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid command attributes " "icid %d or eventid %d or pIntid %d or" From patchwork Tue Feb 8 11:39:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540772 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp473490imo; Tue, 8 Feb 2022 05:06:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwf0yLTaI0QpxRAPTibOqfeosn2JCybt84XYGHrH2VgeOyWyJRyjVMPRcJh5h+SQM/Vfo11 X-Received: by 2002:a25:2606:: with SMTP id m6mr4829139ybm.753.1644325581382; Tue, 08 Feb 2022 05:06:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644325581; cv=none; d=google.com; s=arc-20160816; b=ZVeN1FKA+YfqVQgBEnlDvooH6HxKuMp9JD6eDvg5Hs1Pn0yhAmpt/Q4wlHlsVrEeze UzVeL/U+6YYya4nUD96lRm3J5xyNI8XTQSmjupwDVCiwbizs8nNMiCtVmtyLMY1kJ/aV OWngTtmfmY/HesDS/wf7kI4U7+b/rAhYWUf7Pi/JiQSNvYtwuv2Qy9KYS/2AItHGmJA7 697uFOFCERWVeiuuFikfpFpW/XqAcefztERfA4wSEezh6iZrPsYsaQ7o1ML5FZmXMR14 66eHJ6V8YhkTFTCXOr929tIJo51hSVLkc2hrjcID6J0cEhU/Huu4VwgDQO07qWgw6MnM XNlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=9dw3Bqc9gNOZYBlhUw891b5p3LngTxqnCKTzWHfYZ8A=; b=B1X5nqPLOo4O9ixTsyq9apszfIdq/fDSDVjddBYpBmUaph+H/Qh33J7eM4ZYjzuEF2 kCZLsFaUhM7BHgxbzOGTipHDX7fXDH0dUkhN5vho6MhkY03lTonOKKqVV425aH8X+lBe Nu3wUQihhRYh4+EenWNf4yNTWyaQjN6g9QrCTDAR76lW3Cpe3vt9ZnLC14lewMzfS4Bh g+H2L5IHW/ext58jmZaGAjyRMqjRAYJlo3CzblaXeOBjLpVsxsu9QVFRYoc5uKjd8ru3 1PrRsfSbNAGVJFS2yudLOqi2ro9D93nijRYGnVX2gq/xTWgrVn1R/Jla7F+wOTwNdVit 8qNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="kniUN/ug"; 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=pass (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 b20si9974159ywb.313.2022.02.08.05.06.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:06:21 -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=pass header.i=@linaro.org header.s=google header.b="kniUN/ug"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQCK-0006DV-Jr for patch@linaro.org; Tue, 08 Feb 2022 08:06:20 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrT-00016B-4f for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:45 -0500 Received: from [2a00:1450:4864:20::32f] (port=34754 helo=mail-wm1-x32f.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOr2-0002O2-Jr for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:32 -0500 Received: by mail-wm1-x32f.google.com with SMTP id bg19-20020a05600c3c9300b0034565e837b6so720660wmb.1 for ; Tue, 08 Feb 2022 03:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9dw3Bqc9gNOZYBlhUw891b5p3LngTxqnCKTzWHfYZ8A=; b=kniUN/ugRfQJXfQCvFtnfLC/C0dWt0YtVPWI64g4xjt9NVF7iLXUGVV8/8Hj6Ve4om Hz4rqRw7UKAsPyVdCyqAYvS1Y1Lacxe+jyB3GdaPolhmOfFaPAphPNP3mV4f9xSDAiYV BY1Q6zBgcnInyNq7F2BZQQrz/epRQRrV6pXAwnxBZ76G4N4MMRtugR7o22iUPdZRaJxn DPLRhSjcjdNC8p06FZCdDmX1KD3gbnGNAfR8bKCafJ+5S8R1FbR5vSNtFDHC7pTfMadX WQZWo6XtY6dBLFW208aPQ6LHys0jC2Tb+K/vGspdjmUD2K0NaIbywIcscrlhdRjmQ3qx XAdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9dw3Bqc9gNOZYBlhUw891b5p3LngTxqnCKTzWHfYZ8A=; b=QsOCJxm4DGNSWeSIrMrQE7zK4TUUGpxzfuoufOCtFPpT4EPfdr1YKRhA+9fcrEpjBw D6RwEGcZ2eFS63SWxq0hoy/kikFtGe+BixXBYhnV0Gh45SFLgoZmxa5ZF4tJ/3TZNn3w mnP3cITlqj3UXj/WntvxIGnyBfb7Ca6CVozoTgp6OzMh7Wcpz02T2HBSKDfezIN53vr+ QYjAvyGKA/OYcHLWxYNH8hgiDlLuz8OYLHT4zP9Gh3HfpfdYIC+b5Cb4y4pW3H+DiGLf q3RJFMswGoHAd07TFRY1NcpQnL1dD9odDLBeu9a3hbkyPe4F/BLH+AJJxAOyvtx1bPqr khqA== X-Gm-Message-State: AOAM533emDfc6JLe4TilgXDSLpsvO1I2xPV7eLV/62DR5ayrJckdCYYd EDTWqZMUBfIlKE9N3AX5urnZdd6T1G+aJw== X-Received: by 2002:a1c:7c0b:: with SMTP id x11mr789318wmc.192.1644320415325; Tue, 08 Feb 2022 03:40:15 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:15 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 38/39] hw/intc/arm_gicv3_its: Split error checks Date: Tue, 8 Feb 2022 11:39:47 +0000 Message-Id: <20220208113948.3217356-39-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::32f (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::32f; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x32f.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" In most of the ITS command processing, we check different error possibilities one at a time and log them appropriately. In process_mapti() and process_mapd() we have code which checks multiple error cases at once, which means the logging is less specific than it could be. Split those cases up. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Message-id: 20220201193207.2771604-14-peter.maydell@linaro.org --- hw/intc/arm_gicv3_its.c | 52 ++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/hw/intc/arm_gicv3_its.c b/hw/intc/arm_gicv3_its.c index 8dade9440ac..4f598d3c14f 100644 --- a/hw/intc/arm_gicv3_its.c +++ b/hw/intc/arm_gicv3_its.c @@ -404,19 +404,29 @@ static ItsCmdResult process_mapti(GICv3ITSState *s, const uint64_t *cmdpkt, num_eventids = 1ULL << (dte.size + 1); num_intids = 1ULL << (GICD_TYPER_IDBITS + 1); - if ((icid >= s->ct.num_entries) - || !dte.valid || (eventid >= num_eventids) || - (((pIntid < GICV3_LPI_INTID_START) || (pIntid >= num_intids)))) { + if (icid >= s->ct.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, - "%s: invalid command attributes " - "icid %d or eventid %d or pIntid %d or" - "unmapped dte %d\n", __func__, icid, eventid, - pIntid, dte.valid); - /* - * in this implementation, in case of error - * we ignore this command and move onto the next - * command in the queue - */ + "%s: invalid ICID 0x%x >= 0x%x\n", + __func__, icid, s->ct.num_entries); + return CMD_CONTINUE; + } + + if (!dte.valid) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: no valid DTE for devid 0x%x\n", __func__, devid); + return CMD_CONTINUE; + } + + if (eventid >= num_eventids) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid event ID 0x%x >= 0x%" PRIx64 "\n", + __func__, eventid, num_eventids); + return CMD_CONTINUE; + } + + if (pIntid < GICV3_LPI_INTID_START || pIntid >= num_intids) { + qemu_log_mask(LOG_GUEST_ERROR, + "%s: invalid interrupt ID 0x%x\n", __func__, pIntid); return CMD_CONTINUE; } @@ -529,16 +539,16 @@ static ItsCmdResult process_mapd(GICv3ITSState *s, const uint64_t *cmdpkt) dte.ittaddr = (cmdpkt[2] & ITTADDR_MASK) >> ITTADDR_SHIFT; dte.valid = cmdpkt[2] & CMD_FIELD_VALID_MASK; - if ((devid >= s->dt.num_entries) || - (dte.size > FIELD_EX64(s->typer, GITS_TYPER, IDBITS))) { + if (devid >= s->dt.num_entries) { qemu_log_mask(LOG_GUEST_ERROR, - "ITS MAPD: invalid device table attributes " - "devid %d or size %d\n", devid, dte.size); - /* - * in this implementation, in case of error - * we ignore this command and move onto the next - * command in the queue - */ + "ITS MAPD: invalid device ID field 0x%x >= 0x%x\n", + devid, s->dt.num_entries); + return CMD_CONTINUE; + } + + if (dte.size > FIELD_EX64(s->typer, GITS_TYPER, IDBITS)) { + qemu_log_mask(LOG_GUEST_ERROR, + "ITS MAPD: invalid size %d\n", dte.size); return CMD_CONTINUE; } From patchwork Tue Feb 8 11:39:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 540784 Delivered-To: patch@linaro.org Received: by 2002:ad5:420f:0:0:0:0:0 with SMTP id e15csp503042imo; Tue, 8 Feb 2022 05:49:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJy5gpl93/OT9Hb7xLBE/kbngUpupH8erjzS+FiaKQIMBe0mV1pRUEt8N31Li+c7oAT2LtXT X-Received: by 2002:a25:b950:: with SMTP id s16mr4186471ybm.748.1644328156708; Tue, 08 Feb 2022 05:49:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644328156; cv=none; d=google.com; s=arc-20160816; b=O5W1mI+aU1Ep0vfsmeKMExsEHIIf0dneN0k1pD3I1e3yfnL3MVGnIZVilUe0X0I8Qc bnXLf4atexI9wYbTTBt2YBQHf1MPKstqlpS6W0WqXmF8jEcDSlU19/Zb+TKa8Ue6iazg e4a8C2d4fCi36r7LjzfzhgdKFPW2+pr1TiFLGPoSH1TdfU+tvkstzqmZ1L5oanf96RXj BA5zgI1NZoxbKUkesJB3xKi5BoVYYwPg1VXz62QnLNxVbqmOen41s++s+mm3d44IqLsd WJsyqi2Wgyy2X9fQ17Qn5DW5vuCdNQuhgGS0/h7uCbakyDvzg2cVnNbv0Lt6SbzN9eyu A5DA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=v5ET0+1LLIbrX35KZYaVVD6fsBg0+EloAODPuKcK44U=; b=ana0M5V4oqs81lAuMrtUIu71u13jRJopToT4Lu1ZgN/uk1QYoM8ak9tLRNaTvIFYFh z9RIC+qYe5zRhRXAB+dkBIpA1DWPNgt76UL1MITR9nrYnBv9h1ygRteMcVmvhTG5jmFX ZH/lI8tK89wHQPuA5zVzuwwXvQMYRINRj7A2d4zwEqt+C1ixD93LoJ9f9wvkQAqBW/Qh vBcZh3mr6OJTqLG7tGpnifmcjtjHzCccoG8zG3tJegvlSHIK94WOS8B4pJtjfeYbaT0p 7fEa3dh/qlPZJ12cdIFV+CmRdnUVOssQqltwxZb2ZWw+xIECQ4tAwlxmIBHPs8kfqDI9 b/Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="qE8Y9nm/"; 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=pass (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 q128si9682531ywd.419.2022.02.08.05.49.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Feb 2022 05:49:16 -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=pass header.i=@linaro.org header.s=google header.b="qE8Y9nm/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34178 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nHQrq-0003MN-QG for patch@linaro.org; Tue, 08 Feb 2022 08:49:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:35162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nHOrW-00016p-58 for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:46 -0500 Received: from [2a00:1450:4864:20::432] (port=37443 helo=mail-wr1-x432.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nHOr6-0002Oc-FG for qemu-devel@nongnu.org; Tue, 08 Feb 2022 06:40:45 -0500 Received: by mail-wr1-x432.google.com with SMTP id w11so30205534wra.4 for ; Tue, 08 Feb 2022 03:40:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=v5ET0+1LLIbrX35KZYaVVD6fsBg0+EloAODPuKcK44U=; b=qE8Y9nm/XaFllt0ssasppopfpTj448pXn+1qgdMH3oBkPQlAv0BQBzJeSpi18tP0km DiKJzeNtGWDPnnlsZgqw7RxnFZECvCd1OxhzikOoRO6mgIMHkHImLMNmrK+DcSWZRMwe raHWH4vogFP66TmwQG5lDwxCBJ9Hgqy1JKiIfHIqmqqULU6Dd8+wgROi1paNThMygaHL b5bJeF7jRI8T4OR69PC5LGMPY0R07sOPxgCTMZZplJXP4jGJbaYFNY9sbSfKDt8673s2 omJwYLoNllEVbqnLC0E3TWotFL41hhyLUsIWxfx6J3MFrPgxELDf61o5vxCannD+irnV ogTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v5ET0+1LLIbrX35KZYaVVD6fsBg0+EloAODPuKcK44U=; b=cgzKqr+fnWnfUrPFNs7tfF5K+WVzzawhw1mmeuo66pQx4qycGt0IwR1cwVVHKXBqYr sjnICOf8yq/91Q1LZscegl0yuYqPSa4olep9vFLcMENANLNsrNpRZUZEnTKLayB08x+Z TGrrpz1JdO4SxQ0bwnVkezNmSN0oRRSbb1eddodz076n5BDUkwQM8svtkgyYe1t2eEgj f6sf42uaAC9gR72eo8kqjBCoqDOgh/GcskIpyb1VATmBDaskveTYBKEwMQweyz+Kxd3r ycWWLR4sTf2BpSic+AH5E2ahiDgDvn4tCSPyT0m7tPxGhJzE248kAnzLt8KoAgOvxmMo iDgw== X-Gm-Message-State: AOAM5315nR3CKtIyijlPoS8gcL6466dIr8YkZp7Sc2PPkZoUoPnkkViX bbgZYM9BRBccVtRSpF36ILlpQ6UhHl6AdQ== X-Received: by 2002:adf:d4cb:: with SMTP id w11mr1463352wrk.221.1644320416301; Tue, 08 Feb 2022 03:40:16 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id r11sm4245199wrt.28.2022.02.08.03.40.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Feb 2022 03:40:15 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 39/39] hw/sensor: Add lsm303dlhc magnetometer device Date: Tue, 8 Feb 2022 11:39:48 +0000 Message-Id: <20220208113948.3217356-40-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208113948.3217356-1-peter.maydell@linaro.org> References: <20220208113948.3217356-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-Host-Lookup-Failed: Reverse DNS lookup failed for 2a00:1450:4864:20::432 (failed) Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=peter.maydell@linaro.org; helo=mail-wr1-x432.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" From: Kevin Townsend This commit adds emulation of the magnetometer on the LSM303DLHC. It allows the magnetometer's X, Y and Z outputs to be set via the mag-x, mag-y and mag-z properties, as well as the 12-bit temperature output via the temperature property. Sensor can be enabled with 'CONFIG_LSM303DLHC_MAG=y'. Signed-off-by: Kevin Townsend Message-id: 20220130095032.35392-1-kevin.townsend@linaro.org Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- hw/sensor/lsm303dlhc_mag.c | 556 ++++++++++++++++++++++++++++++ tests/qtest/lsm303dlhc-mag-test.c | 148 ++++++++ hw/sensor/Kconfig | 4 + hw/sensor/meson.build | 1 + tests/qtest/meson.build | 1 + 5 files changed, 710 insertions(+) create mode 100644 hw/sensor/lsm303dlhc_mag.c create mode 100644 tests/qtest/lsm303dlhc-mag-test.c diff --git a/hw/sensor/lsm303dlhc_mag.c b/hw/sensor/lsm303dlhc_mag.c new file mode 100644 index 00000000000..4c98ddbf207 --- /dev/null +++ b/hw/sensor/lsm303dlhc_mag.c @@ -0,0 +1,556 @@ +/* + * LSM303DLHC I2C magnetometer. + * + * Copyright (C) 2021 Linaro Ltd. + * Written by Kevin Townsend + * + * Based on: https://www.st.com/resource/en/datasheet/lsm303dlhc.pdf + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +/* + * The I2C address associated with this device is set on the command-line when + * initialising the machine, but the following address is standard: 0x1E. + * + * Get and set functions for 'mag-x', 'mag-y' and 'mag-z' assume that + * 1 = 0.001 uT. (NOTE the 1 gauss = 100 uT, so setting a value of 100,000 + * would be equal to 1 gauss or 100 uT.) + * + * Get and set functions for 'temperature' assume that 1 = 0.001 C, so 23.6 C + * would be equal to 23600. + */ + +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "qemu/module.h" +#include "qemu/log.h" +#include "qemu/bswap.h" + +enum LSM303DLHCMagReg { + LSM303DLHC_MAG_REG_CRA = 0x00, + LSM303DLHC_MAG_REG_CRB = 0x01, + LSM303DLHC_MAG_REG_MR = 0x02, + LSM303DLHC_MAG_REG_OUT_X_H = 0x03, + LSM303DLHC_MAG_REG_OUT_X_L = 0x04, + LSM303DLHC_MAG_REG_OUT_Z_H = 0x05, + LSM303DLHC_MAG_REG_OUT_Z_L = 0x06, + LSM303DLHC_MAG_REG_OUT_Y_H = 0x07, + LSM303DLHC_MAG_REG_OUT_Y_L = 0x08, + LSM303DLHC_MAG_REG_SR = 0x09, + LSM303DLHC_MAG_REG_IRA = 0x0A, + LSM303DLHC_MAG_REG_IRB = 0x0B, + LSM303DLHC_MAG_REG_IRC = 0x0C, + LSM303DLHC_MAG_REG_TEMP_OUT_H = 0x31, + LSM303DLHC_MAG_REG_TEMP_OUT_L = 0x32 +}; + +typedef struct LSM303DLHCMagState { + I2CSlave parent_obj; + uint8_t cra; + uint8_t crb; + uint8_t mr; + int16_t x; + int16_t z; + int16_t y; + int16_t x_lock; + int16_t z_lock; + int16_t y_lock; + uint8_t sr; + uint8_t ira; + uint8_t irb; + uint8_t irc; + int16_t temperature; + int16_t temperature_lock; + uint8_t len; + uint8_t buf; + uint8_t pointer; +} LSM303DLHCMagState; + +#define TYPE_LSM303DLHC_MAG "lsm303dlhc_mag" +OBJECT_DECLARE_SIMPLE_TYPE(LSM303DLHCMagState, LSM303DLHC_MAG) + +/* + * Conversion factor from Gauss to sensor values for each GN gain setting, + * in units "lsb per Gauss" (see data sheet table 3). There is no documented + * behaviour if the GN setting in CRB is incorrectly set to 0b000; + * we arbitrarily make it the same as 0b001. + */ +uint32_t xy_gain[] = { 1100, 1100, 855, 670, 450, 400, 330, 230 }; +uint32_t z_gain[] = { 980, 980, 760, 600, 400, 355, 295, 205 }; + +static void lsm303dlhc_mag_get_x(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(obj); + int gm = extract32(s->crb, 5, 3); + + /* Convert to uT where 1000 = 1 uT. Conversion factor depends on gain. */ + int64_t value = muldiv64(s->x, 100000, xy_gain[gm]); + visit_type_int(v, name, &value, errp); +} + +static void lsm303dlhc_mag_get_y(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(obj); + int gm = extract32(s->crb, 5, 3); + + /* Convert to uT where 1000 = 1 uT. Conversion factor depends on gain. */ + int64_t value = muldiv64(s->y, 100000, xy_gain[gm]); + visit_type_int(v, name, &value, errp); +} + +static void lsm303dlhc_mag_get_z(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(obj); + int gm = extract32(s->crb, 5, 3); + + /* Convert to uT where 1000 = 1 uT. Conversion factor depends on gain. */ + int64_t value = muldiv64(s->z, 100000, z_gain[gm]); + visit_type_int(v, name, &value, errp); +} + +static void lsm303dlhc_mag_set_x(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(obj); + int64_t value; + int64_t reg; + int gm = extract32(s->crb, 5, 3); + + if (!visit_type_int(v, name, &value, errp)) { + return; + } + + reg = muldiv64(value, xy_gain[gm], 100000); + + /* Make sure we are within a 12-bit limit. */ + if (reg > 2047 || reg < -2048) { + error_setg(errp, "value %" PRId64 " out of register's range", value); + return; + } + + s->x = (int16_t)reg; +} + +static void lsm303dlhc_mag_set_y(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(obj); + int64_t value; + int64_t reg; + int gm = extract32(s->crb, 5, 3); + + if (!visit_type_int(v, name, &value, errp)) { + return; + } + + reg = muldiv64(value, xy_gain[gm], 100000); + + /* Make sure we are within a 12-bit limit. */ + if (reg > 2047 || reg < -2048) { + error_setg(errp, "value %" PRId64 " out of register's range", value); + return; + } + + s->y = (int16_t)reg; +} + +static void lsm303dlhc_mag_set_z(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(obj); + int64_t value; + int64_t reg; + int gm = extract32(s->crb, 5, 3); + + if (!visit_type_int(v, name, &value, errp)) { + return; + } + + reg = muldiv64(value, z_gain[gm], 100000); + + /* Make sure we are within a 12-bit limit. */ + if (reg > 2047 || reg < -2048) { + error_setg(errp, "value %" PRId64 " out of register's range", value); + return; + } + + s->z = (int16_t)reg; +} + +/* + * Get handler for the temperature property. + */ +static void lsm303dlhc_mag_get_temperature(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(obj); + int64_t value; + + /* Convert to 1 lsb = 0.125 C to 1 = 0.001 C for 'temperature' property. */ + value = s->temperature * 125; + + visit_type_int(v, name, &value, errp); +} + +/* + * Set handler for the temperature property. + */ +static void lsm303dlhc_mag_set_temperature(Object *obj, Visitor *v, + const char *name, void *opaque, + Error **errp) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(obj); + int64_t value; + + if (!visit_type_int(v, name, &value, errp)) { + return; + } + + /* Input temperature is in 0.001 C units. Convert to 1 lsb = 0.125 C. */ + value /= 125; + + if (value > 2047 || value < -2048) { + error_setg(errp, "value %" PRId64 " lsb is out of range", value); + return; + } + + s->temperature = (int16_t)value; +} + +/* + * Callback handler whenever a 'I2C_START_RECV' (read) event is received. + */ +static void lsm303dlhc_mag_read(LSM303DLHCMagState *s) +{ + /* + * Set the LOCK bit whenever a new read attempt is made. This will be + * cleared in I2C_FINISH. Note that DRDY is always set to 1 in this driver. + */ + s->sr = 0x3; + + /* + * Copy the current X/Y/Z and temp. values into the locked registers so + * that 'mag-x', 'mag-y', 'mag-z' and 'temperature' can continue to be + * updated via QOM, etc., without corrupting the current read event. + */ + s->x_lock = s->x; + s->z_lock = s->z; + s->y_lock = s->y; + s->temperature_lock = s->temperature; +} + +/* + * Callback handler whenever a 'I2C_FINISH' event is received. + */ +static void lsm303dlhc_mag_finish(LSM303DLHCMagState *s) +{ + /* + * Clear the LOCK bit when the read attempt terminates. + * This bit is initially set in the I2C_START_RECV handler. + */ + s->sr = 0x1; +} + +/* + * Callback handler when a device attempts to write to a register. + */ +static void lsm303dlhc_mag_write(LSM303DLHCMagState *s) +{ + switch (s->pointer) { + case LSM303DLHC_MAG_REG_CRA: + s->cra = s->buf; + break; + case LSM303DLHC_MAG_REG_CRB: + /* Make sure gain is at least 1, falling back to 1 on an error. */ + if (s->buf >> 5 == 0) { + s->buf = 1 << 5; + } + s->crb = s->buf; + break; + case LSM303DLHC_MAG_REG_MR: + s->mr = s->buf; + break; + case LSM303DLHC_MAG_REG_SR: + s->sr = s->buf; + break; + case LSM303DLHC_MAG_REG_IRA: + s->ira = s->buf; + break; + case LSM303DLHC_MAG_REG_IRB: + s->irb = s->buf; + break; + case LSM303DLHC_MAG_REG_IRC: + s->irc = s->buf; + break; + default: + qemu_log_mask(LOG_GUEST_ERROR, "reg is read-only: 0x%02X", s->buf); + break; + } +} + +/* + * Low-level master-to-slave transaction handler. + */ +static int lsm303dlhc_mag_send(I2CSlave *i2c, uint8_t data) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(i2c); + + if (s->len == 0) { + /* First byte is the reg pointer */ + s->pointer = data; + s->len++; + } else if (s->len == 1) { + /* Second byte is the new register value. */ + s->buf = data; + lsm303dlhc_mag_write(s); + } else { + g_assert_not_reached(); + } + + return 0; +} + +/* + * Low-level slave-to-master transaction handler (read attempts). + */ +static uint8_t lsm303dlhc_mag_recv(I2CSlave *i2c) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(i2c); + uint8_t resp; + + switch (s->pointer) { + case LSM303DLHC_MAG_REG_CRA: + resp = s->cra; + break; + case LSM303DLHC_MAG_REG_CRB: + resp = s->crb; + break; + case LSM303DLHC_MAG_REG_MR: + resp = s->mr; + break; + case LSM303DLHC_MAG_REG_OUT_X_H: + resp = (uint8_t)(s->x_lock >> 8); + break; + case LSM303DLHC_MAG_REG_OUT_X_L: + resp = (uint8_t)(s->x_lock); + break; + case LSM303DLHC_MAG_REG_OUT_Z_H: + resp = (uint8_t)(s->z_lock >> 8); + break; + case LSM303DLHC_MAG_REG_OUT_Z_L: + resp = (uint8_t)(s->z_lock); + break; + case LSM303DLHC_MAG_REG_OUT_Y_H: + resp = (uint8_t)(s->y_lock >> 8); + break; + case LSM303DLHC_MAG_REG_OUT_Y_L: + resp = (uint8_t)(s->y_lock); + break; + case LSM303DLHC_MAG_REG_SR: + resp = s->sr; + break; + case LSM303DLHC_MAG_REG_IRA: + resp = s->ira; + break; + case LSM303DLHC_MAG_REG_IRB: + resp = s->irb; + break; + case LSM303DLHC_MAG_REG_IRC: + resp = s->irc; + break; + case LSM303DLHC_MAG_REG_TEMP_OUT_H: + /* Check if the temperature sensor is enabled or not (CRA & 0x80). */ + if (s->cra & 0x80) { + resp = (uint8_t)(s->temperature_lock >> 8); + } else { + resp = 0; + } + break; + case LSM303DLHC_MAG_REG_TEMP_OUT_L: + if (s->cra & 0x80) { + resp = (uint8_t)(s->temperature_lock & 0xff); + } else { + resp = 0; + } + break; + default: + resp = 0; + break; + } + + /* + * The address pointer on the LSM303DLHC auto-increments whenever a byte + * is read, without the master device having to request the next address. + * + * The auto-increment process has the following logic: + * + * - if (s->pointer == 8) then s->pointer = 3 + * - else: if (s->pointer == 12) then s->pointer = 0 + * - else: s->pointer += 1 + * + * Reading an invalid address return 0. + */ + if (s->pointer == LSM303DLHC_MAG_REG_OUT_Y_L) { + s->pointer = LSM303DLHC_MAG_REG_OUT_X_H; + } else if (s->pointer == LSM303DLHC_MAG_REG_IRC) { + s->pointer = LSM303DLHC_MAG_REG_CRA; + } else { + s->pointer++; + } + + return resp; +} + +/* + * Bus state change handler. + */ +static int lsm303dlhc_mag_event(I2CSlave *i2c, enum i2c_event event) +{ + LSM303DLHCMagState *s = LSM303DLHC_MAG(i2c); + + switch (event) { + case I2C_START_SEND: + break; + case I2C_START_RECV: + lsm303dlhc_mag_read(s); + break; + case I2C_FINISH: + lsm303dlhc_mag_finish(s); + break; + case I2C_NACK: + break; + } + + s->len = 0; + return 0; +} + +/* + * Device data description using VMSTATE macros. + */ +static const VMStateDescription vmstate_lsm303dlhc_mag = { + .name = "LSM303DLHC_MAG", + .version_id = 0, + .minimum_version_id = 0, + .fields = (VMStateField[]) { + + VMSTATE_I2C_SLAVE(parent_obj, LSM303DLHCMagState), + VMSTATE_UINT8(len, LSM303DLHCMagState), + VMSTATE_UINT8(buf, LSM303DLHCMagState), + VMSTATE_UINT8(pointer, LSM303DLHCMagState), + VMSTATE_UINT8(cra, LSM303DLHCMagState), + VMSTATE_UINT8(crb, LSM303DLHCMagState), + VMSTATE_UINT8(mr, LSM303DLHCMagState), + VMSTATE_INT16(x, LSM303DLHCMagState), + VMSTATE_INT16(z, LSM303DLHCMagState), + VMSTATE_INT16(y, LSM303DLHCMagState), + VMSTATE_INT16(x_lock, LSM303DLHCMagState), + VMSTATE_INT16(z_lock, LSM303DLHCMagState), + VMSTATE_INT16(y_lock, LSM303DLHCMagState), + VMSTATE_UINT8(sr, LSM303DLHCMagState), + VMSTATE_UINT8(ira, LSM303DLHCMagState), + VMSTATE_UINT8(irb, LSM303DLHCMagState), + VMSTATE_UINT8(irc, LSM303DLHCMagState), + VMSTATE_INT16(temperature, LSM303DLHCMagState), + VMSTATE_INT16(temperature_lock, LSM303DLHCMagState), + VMSTATE_END_OF_LIST() + } +}; + +/* + * Put the device into post-reset default state. + */ +static void lsm303dlhc_mag_default_cfg(LSM303DLHCMagState *s) +{ + /* Set the device into is default reset state. */ + s->len = 0; + s->pointer = 0; /* Current register. */ + s->buf = 0; /* Shared buffer. */ + s->cra = 0x10; /* Temp Enabled = 0, Data Rate = 15.0 Hz. */ + s->crb = 0x20; /* Gain = +/- 1.3 Gauss. */ + s->mr = 0x3; /* Operating Mode = Sleep. */ + s->x = 0; + s->z = 0; + s->y = 0; + s->x_lock = 0; + s->z_lock = 0; + s->y_lock = 0; + s->sr = 0x1; /* DRDY = 1. */ + s->ira = 0x48; + s->irb = 0x34; + s->irc = 0x33; + s->temperature = 0; /* Default to 0 degrees C (0/8 lsb = 0 C). */ + s->temperature_lock = 0; +} + +/* + * Callback handler when DeviceState 'reset' is set to true. + */ +static void lsm303dlhc_mag_reset(DeviceState *dev) +{ + I2CSlave *i2c = I2C_SLAVE(dev); + LSM303DLHCMagState *s = LSM303DLHC_MAG(i2c); + + /* Set the device into its default reset state. */ + lsm303dlhc_mag_default_cfg(s); +} + +/* + * Initialisation of any public properties. + */ +static void lsm303dlhc_mag_initfn(Object *obj) +{ + object_property_add(obj, "mag-x", "int", + lsm303dlhc_mag_get_x, + lsm303dlhc_mag_set_x, NULL, NULL); + + object_property_add(obj, "mag-y", "int", + lsm303dlhc_mag_get_y, + lsm303dlhc_mag_set_y, NULL, NULL); + + object_property_add(obj, "mag-z", "int", + lsm303dlhc_mag_get_z, + lsm303dlhc_mag_set_z, NULL, NULL); + + object_property_add(obj, "temperature", "int", + lsm303dlhc_mag_get_temperature, + lsm303dlhc_mag_set_temperature, NULL, NULL); +} + +/* + * Set the virtual method pointers (bus state change, tx/rx, etc.). + */ +static void lsm303dlhc_mag_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + I2CSlaveClass *k = I2C_SLAVE_CLASS(klass); + + dc->reset = lsm303dlhc_mag_reset; + dc->vmsd = &vmstate_lsm303dlhc_mag; + k->event = lsm303dlhc_mag_event; + k->recv = lsm303dlhc_mag_recv; + k->send = lsm303dlhc_mag_send; +} + +static const TypeInfo lsm303dlhc_mag_info = { + .name = TYPE_LSM303DLHC_MAG, + .parent = TYPE_I2C_SLAVE, + .instance_size = sizeof(LSM303DLHCMagState), + .instance_init = lsm303dlhc_mag_initfn, + .class_init = lsm303dlhc_mag_class_init, +}; + +static void lsm303dlhc_mag_register_types(void) +{ + type_register_static(&lsm303dlhc_mag_info); +} + +type_init(lsm303dlhc_mag_register_types) diff --git a/tests/qtest/lsm303dlhc-mag-test.c b/tests/qtest/lsm303dlhc-mag-test.c new file mode 100644 index 00000000000..0f64e7fc67d --- /dev/null +++ b/tests/qtest/lsm303dlhc-mag-test.c @@ -0,0 +1,148 @@ +/* + * QTest testcase for the LSM303DLHC I2C magnetometer + * + * Copyright (C) 2021 Linaro Ltd. + * Written by Kevin Townsend + * + * Based on: https://www.st.com/resource/en/datasheet/lsm303dlhc.pdf + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "libqtest-single.h" +#include "libqos/qgraph.h" +#include "libqos/i2c.h" +#include "qapi/qmp/qdict.h" + +#define LSM303DLHC_MAG_TEST_ID "lsm303dlhc_mag-test" +#define LSM303DLHC_MAG_REG_CRA 0x00 +#define LSM303DLHC_MAG_REG_CRB 0x01 +#define LSM303DLHC_MAG_REG_OUT_X_H 0x03 +#define LSM303DLHC_MAG_REG_OUT_Z_H 0x05 +#define LSM303DLHC_MAG_REG_OUT_Y_H 0x07 +#define LSM303DLHC_MAG_REG_IRC 0x0C +#define LSM303DLHC_MAG_REG_TEMP_OUT_H 0x31 + +static int qmp_lsm303dlhc_mag_get_property(const char *id, const char *prop) +{ + QDict *response; + int ret; + + response = qmp("{ 'execute': 'qom-get', 'arguments': { 'path': %s, " + "'property': %s } }", id, prop); + g_assert(qdict_haskey(response, "return")); + ret = qdict_get_int(response, "return"); + qobject_unref(response); + return ret; +} + +static void qmp_lsm303dlhc_mag_set_property(const char *id, const char *prop, + int value) +{ + QDict *response; + + response = qmp("{ 'execute': 'qom-set', 'arguments': { 'path': %s, " + "'property': %s, 'value': %d } }", id, prop, value); + g_assert(qdict_haskey(response, "return")); + qobject_unref(response); +} + +static void send_and_receive(void *obj, void *data, QGuestAllocator *alloc) +{ + int64_t value; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + /* Check default value for CRB */ + g_assert_cmphex(i2c_get8(i2cdev, LSM303DLHC_MAG_REG_CRB), ==, 0x20); + + /* Set x to 1.0 gauss and verify the value */ + qmp_lsm303dlhc_mag_set_property(LSM303DLHC_MAG_TEST_ID, "mag-x", 100000); + value = qmp_lsm303dlhc_mag_get_property( + LSM303DLHC_MAG_TEST_ID, "mag-x"); + g_assert_cmpint(value, ==, 100000); + + /* Set y to 1.5 gauss and verify the value */ + qmp_lsm303dlhc_mag_set_property(LSM303DLHC_MAG_TEST_ID, "mag-y", 150000); + value = qmp_lsm303dlhc_mag_get_property( + LSM303DLHC_MAG_TEST_ID, "mag-y"); + g_assert_cmpint(value, ==, 150000); + + /* Set z to 0.5 gauss and verify the value */ + qmp_lsm303dlhc_mag_set_property(LSM303DLHC_MAG_TEST_ID, "mag-z", 50000); + value = qmp_lsm303dlhc_mag_get_property( + LSM303DLHC_MAG_TEST_ID, "mag-z"); + g_assert_cmpint(value, ==, 50000); + + /* Set temperature to 23.6 C and verify the value */ + qmp_lsm303dlhc_mag_set_property(LSM303DLHC_MAG_TEST_ID, + "temperature", 23600); + value = qmp_lsm303dlhc_mag_get_property( + LSM303DLHC_MAG_TEST_ID, "temperature"); + /* Should return 23.5 C due to 0.125°C steps. */ + g_assert_cmpint(value, ==, 23500); + + /* Read raw x axis registers (1 gauss = 1100 at +/-1.3 g gain) */ + value = i2c_get16(i2cdev, LSM303DLHC_MAG_REG_OUT_X_H); + g_assert_cmphex(value, ==, 1100); + + /* Read raw y axis registers (1.5 gauss = 1650 at +/- 1.3 g gain = ) */ + value = i2c_get16(i2cdev, LSM303DLHC_MAG_REG_OUT_Y_H); + g_assert_cmphex(value, ==, 1650); + + /* Read raw z axis registers (0.5 gauss = 490 at +/- 1.3 g gain = ) */ + value = i2c_get16(i2cdev, LSM303DLHC_MAG_REG_OUT_Z_H); + g_assert_cmphex(value, ==, 490); + + /* Read raw temperature registers with temp disabled (CRA = 0x10) */ + value = i2c_get16(i2cdev, LSM303DLHC_MAG_REG_TEMP_OUT_H); + g_assert_cmphex(value, ==, 0); + + /* Enable temperature reads (CRA = 0x90) */ + i2c_set8(i2cdev, LSM303DLHC_MAG_REG_CRA, 0x90); + + /* Read raw temp registers (23.5 C = 188 at 1 lsb = 0.125 C) */ + value = i2c_get16(i2cdev, LSM303DLHC_MAG_REG_TEMP_OUT_H); + g_assert_cmphex(value, ==, 188); +} + +static void reg_wraparound(void *obj, void *data, QGuestAllocator *alloc) +{ + uint8_t value[4]; + QI2CDevice *i2cdev = (QI2CDevice *)obj; + + /* Set x to 1.0 gauss, and y to 1.5 gauss for known test values */ + qmp_lsm303dlhc_mag_set_property(LSM303DLHC_MAG_TEST_ID, "mag-x", 100000); + qmp_lsm303dlhc_mag_set_property(LSM303DLHC_MAG_TEST_ID, "mag-y", 150000); + + /* Check that requesting 4 bytes starting at Y_H wraps around to X_L */ + i2c_read_block(i2cdev, LSM303DLHC_MAG_REG_OUT_Y_H, value, 4); + /* 1.5 gauss = 1650 lsb = 0x672 */ + g_assert_cmphex(value[0], ==, 0x06); + g_assert_cmphex(value[1], ==, 0x72); + /* 1.0 gauss = 1100 lsb = 0x44C */ + g_assert_cmphex(value[2], ==, 0x04); + g_assert_cmphex(value[3], ==, 0x4C); + + /* Check that requesting LSM303DLHC_MAG_REG_IRC wraps around to CRA */ + i2c_read_block(i2cdev, LSM303DLHC_MAG_REG_IRC, value, 2); + /* Default value for IRC = 0x33 */ + g_assert_cmphex(value[0], ==, 0x33); + /* Default value for CRA = 0x10 */ + g_assert_cmphex(value[1], ==, 0x10); +} + +static void lsm303dlhc_mag_register_nodes(void) +{ + QOSGraphEdgeOptions opts = { + .extra_device_opts = "id=" LSM303DLHC_MAG_TEST_ID ",address=0x1e" + }; + add_qi2c_address(&opts, &(QI2CAddress) { 0x1E }); + + qos_node_create_driver("lsm303dlhc_mag", i2c_device_create); + qos_node_consumes("lsm303dlhc_mag", "i2c-bus", &opts); + + qos_add_test("tx-rx", "lsm303dlhc_mag", send_and_receive, NULL); + qos_add_test("regwrap", "lsm303dlhc_mag", reg_wraparound, NULL); +} +libqos_init(lsm303dlhc_mag_register_nodes); diff --git a/hw/sensor/Kconfig b/hw/sensor/Kconfig index 9c8a049b068..b317f91b7b4 100644 --- a/hw/sensor/Kconfig +++ b/hw/sensor/Kconfig @@ -21,3 +21,7 @@ config ADM1272 config MAX34451 bool depends on I2C + +config LSM303DLHC_MAG + bool + depends on I2C diff --git a/hw/sensor/meson.build b/hw/sensor/meson.build index 059c4ca935b..d1bba290dad 100644 --- a/hw/sensor/meson.build +++ b/hw/sensor/meson.build @@ -4,3 +4,4 @@ softmmu_ss.add(when: 'CONFIG_DPS310', if_true: files('dps310.c')) softmmu_ss.add(when: 'CONFIG_EMC141X', if_true: files('emc141x.c')) softmmu_ss.add(when: 'CONFIG_ADM1272', if_true: files('adm1272.c')) softmmu_ss.add(when: 'CONFIG_MAX34451', if_true: files('max34451.c')) +softmmu_ss.add(when: 'CONFIG_LSM303DLHC_MAG', if_true: files('lsm303dlhc_mag.c')) diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 762f6adcd5e..f33d84d19bc 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -243,6 +243,7 @@ qos_test_ss.add( 'eepro100-test.c', 'es1370-test.c', 'ipoctal232-test.c', + 'lsm303dlhc-mag-test.c', 'max34451-test.c', 'megasas-test.c', 'ne2000-test.c',