From nobody Fri Apr 26 23:27:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1616785234; cv=none; d=zohomail.com; s=zohoarc; b=DP8NaQTvyvUDx9fd4lW1LoXt85/8eGrDJINMCpKbglU0O9+rQn78li7bsCYC9r4xiFUjppCcX2Ii91UnT4S7cTmLFRhYw4xCq8Jh84bUAYeJypVPncK/pg5OdHo0CbKZlut7xIa9Wbxc/uMU7i7FOPQjaXHNOQW1rx311Jq9pUI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616785234; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=qc6NSYmqn+QiFr9P3aUTLcRb5Ek47J9cBID1f2kDbn0=; b=jX2bt6+3J61mOxbTHXSt3XuRExzzKDptbVrT5sJJ1tYrpeQdyFPt90/NtLxPiBFE1pUGDekKTrdSVrgOXASAWSM00LXlgNntgwEBGGlt/P3QHe+e+gq6vnA5VfEk6il2gtYG2tY9LPqHUnNBtA2z5bJxVd6cZsF0mFllC6Tn2G4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 161678523470963.20262275279606; Fri, 26 Mar 2021 12:00:34 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.102056.195511 (Exim 4.92) (envelope-from ) id 1lPrgv-0007ZY-Ad; Fri, 26 Mar 2021 19:00:17 +0000 Received: by outflank-mailman (output) from mailman id 102056.195511; Fri, 26 Mar 2021 19:00:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPrgv-0007ZM-7K; Fri, 26 Mar 2021 19:00:17 +0000 Received: by outflank-mailman (input) for mailman id 102056; Fri, 26 Mar 2021 19:00:15 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPrgt-0007YF-Dl for xen-devel@lists.xenproject.org; Fri, 26 Mar 2021 19:00:15 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 921b78e8-fa6d-4e3d-b97b-20b3fe291f33; Fri, 26 Mar 2021 19:00:14 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 921b78e8-fa6d-4e3d-b97b-20b3fe291f33 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616785214; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Owj/a0DofXQQ1pbrqHaoX4QZh8e96kJPF3mOvOw79JI=; b=dg2HOhy4dwC0tN4caOKSHYpERJEpLPzx41zc7pSGGrsjguP/q3+X9d8J Ic5loMKRwuWZ/JS6lClpGWe6EmnQ8JuYJEAqFHjj8XW9ZVh4m/tsJTDY5 dhkSrxOk4P7liK+7fooezSeDtrGWgqBpzrYFBPUnm/pUgiuORsIyNmSFE 4=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: iUTJQ4F+iFWnnIvdcpZl+54dk/M1KanUpRnRglrSjSC1p6miXqPe5wm4dYwxZNJqdCJ1554XmY 1ugTvLbKpAUFXax6CUsXSq7D7UseF5dkqKv7OQ40jqdPDazoO8ACduyvkfmkibfyzOD1GpaCYb 47uQtuBqUkxvgFQlgwZiRdtOdYZiO1OJoqLAQ+tGf+B0kgOBx6PhnwznToxmpzOyfCraZXXyxu SySCEUqpqHDkjgVYg3vE9jjRGBOO7OVshs1VyJWMu47PkzNYoeKTuPgQ64o8cbx5eGpGn4hMFy iCU= X-SBRS: 4.0 X-MesageID: 40605116 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:0hFm9qqWi6uyRAbsXIigvGMaV5uTKtV00zAX/kB9WHVpW+SivY SHgOkb2RjoiDwYRXEnnpS6NLOdRG7HnKQa3aA4Bp3neAX9omOnIMVZ7YXkyyD9ACGWzIFg/I 9aWexFBNX0ZGIXse/T6gO1Cstl5dGB/ryhi+u29QYRcShBbaZ84wBlTiOSFUNrTAdLbKBJaK a0zMxBujamZDArft22b0N1E9Triv/qsNbdYRAADwM68wXmt1KVwZPzDhTw5GZmbxph2rEnmF K18TDRxqLmiP2jzw+Z6mm71eUtpPLE6v9uQPOBkdIULDKEsHfmWK1EV6eZtD445MGDgWxa6O XkmBsrM8Rt5365RAjcynGBu3iC7B8U53Dv0lOei3f4yPaJPw4SMMZdmZlfNiLQ9ktIhqAk7I tww2mbu5BLZCmw+BjV2tnSWxlm0mqyrHYy+NRj6UB3bIoEZLdd6bEY5UNeea1wex7S1YZPKp gKMOjsoNJtNX+KZXHQuWdihPa2WG4oIxuASk8e/uSIzjl/hhlCvgUl7f1auk1F2IM2SpFC6e iBGL9vjqt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ak/KbnXPyU3+ncEwWio 1OaFwIYslCgjckipcr0iLacN2Dnms1111E4T9mkVbx2o+ppGfDdHs2QTHkvg== X-IronPort-AV: E=Sophos;i="5.81,281,1610427600"; d="scan'208";a="40605116" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Ian Jackson , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret?= Subject: [PATCH v2 1/3] x86/hpet: Factor hpet_enable_legacy_replacement_mode() out of hpet_setup() Date: Fri, 26 Mar 2021 18:59:45 +0000 Message-ID: <20210326185947.23243-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210326185947.23243-1-andrew.cooper3@citrix.com> References: <20210326185947.23243-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) ... in preparation to introduce a second caller. No functional change. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Ian Jackson CC: Marek Marczykowski-G=C3=B3recki CC: Fr=C3=A9d=C3=A9ric Pierret For 4.15. Pre-req for trying to unbreak AMD Ryzen 1800X systems. v2: * s/u64/uint64_t/ * Drop id local variable --- xen/arch/x86/hpet.c | 116 ++++++++++++++++++++++++-----------------= ---- xen/include/asm-x86/hpet.h | 6 +++ 2 files changed, 68 insertions(+), 54 deletions(-) diff --git a/xen/arch/x86/hpet.c b/xen/arch/x86/hpet.c index 1ff005fb4a..c1d04f184f 100644 --- a/xen/arch/x86/hpet.c +++ b/xen/arch/x86/hpet.c @@ -754,11 +754,70 @@ int hpet_legacy_irq_tick(void) } =20 static u32 *hpet_boot_cfg; +static uint64_t __initdata hpet_rate; + +bool __init hpet_enable_legacy_replacement_mode(void) +{ + unsigned int cfg, c0_cfg, ticks, count; + + if ( !hpet_rate || + !(hpet_read32(HPET_ID) & HPET_ID_LEGSUP) || + ((cfg =3D hpet_read32(HPET_CFG)) & HPET_CFG_LEGACY) ) + return false; + + /* Stop the main counter. */ + hpet_write32(cfg & ~HPET_CFG_ENABLE, HPET_CFG); + + /* Reconfigure channel 0 to be 32bit periodic. */ + c0_cfg =3D hpet_read32(HPET_Tn_CFG(0)); + c0_cfg |=3D (HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_SETVAL | + HPET_TN_32BIT); + hpet_write32(c0_cfg, HPET_Tn_CFG(0)); + + /* + * The exact period doesn't have to match a legacy PIT. All we need + * is an interrupt queued up via the IO-APIC to check routing. + * + * Use HZ as the frequency. + */ + ticks =3D ((SECONDS(1) / HZ) * div_sc(hpet_rate, SECONDS(1), 32)) >> 3= 2; + + count =3D hpet_read32(HPET_COUNTER); + + /* + * HPET_TN_SETVAL above is atrociously documented in the spec. + * + * Periodic HPET channels have a main comparator register, and + * separate "accumulator" register. Despite being named accumulator + * in the spec, this is not an accurate description of its behaviour + * or purpose. + * + * Each time an interrupt is generated, the "accumulator" register is + * re-added to the comparator set up the new period. + * + * Normally, writes to the CMP register update both registers. + * However, under these semantics, it is impossible to set up a + * periodic timer correctly without the main HPET counter being at 0. + * + * Instead, HPET_TN_SETVAL is a self-clearing control bit which we can + * use for periodic timers to mean that the second write to CMP + * updates the accumulator only, and not the absolute comparator + * value. + * + * This lets us set a period when the main counter isn't at 0. + */ + hpet_write32(count + ticks, HPET_Tn_CMP(0)); + hpet_write32(ticks, HPET_Tn_CMP(0)); + + /* Restart the main counter, and legacy mode. */ + hpet_write32(cfg | HPET_CFG_ENABLE | HPET_CFG_LEGACY, HPET_CFG); + + return true; +} =20 u64 __init hpet_setup(void) { - static u64 __initdata hpet_rate; - unsigned int hpet_id, hpet_period, hpet_cfg; + unsigned int hpet_id, hpet_period; unsigned int last, rem; =20 if ( hpet_rate ) @@ -805,58 +864,7 @@ u64 __init hpet_setup(void) * Reconfigure the HPET into legacy mode to re-establish the timer * interrupt. */ - if ( hpet_id & HPET_ID_LEGSUP && - !((hpet_cfg =3D hpet_read32(HPET_CFG)) & HPET_CFG_LEGACY) ) - { - unsigned int c0_cfg, ticks, count; - - /* Stop the main counter. */ - hpet_write32(hpet_cfg & ~HPET_CFG_ENABLE, HPET_CFG); - - /* Reconfigure channel 0 to be 32bit periodic. */ - c0_cfg =3D hpet_read32(HPET_Tn_CFG(0)); - c0_cfg |=3D (HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_SETVAL | - HPET_TN_32BIT); - hpet_write32(c0_cfg, HPET_Tn_CFG(0)); - - /* - * The exact period doesn't have to match a legacy PIT. All we ne= ed - * is an interrupt queued up via the IO-APIC to check routing. - * - * Use HZ as the frequency. - */ - ticks =3D ((SECONDS(1) / HZ) * div_sc(hpet_rate, SECONDS(1), 32)) = >> 32; - - count =3D hpet_read32(HPET_COUNTER); - - /* - * HPET_TN_SETVAL above is atrociously documented in the spec. - * - * Periodic HPET channels have a main comparator register, and - * separate "accumulator" register. Despite being named accumulat= or - * in the spec, this is not an accurate description of its behavio= ur - * or purpose. - * - * Each time an interrupt is generated, the "accumulator" register= is - * re-added to the comparator set up the new period. - * - * Normally, writes to the CMP register update both registers. - * However, under these semantics, it is impossible to set up a - * periodic timer correctly without the main HPET counter being at= 0. - * - * Instead, HPET_TN_SETVAL is a self-clearing control bit which we= can - * use for periodic timers to mean that the second write to CMP - * updates the accumulator only, and not the absolute comparator - * value. - * - * This lets us set a period when the main counter isn't at 0. - */ - hpet_write32(count + ticks, HPET_Tn_CMP(0)); - hpet_write32(ticks, HPET_Tn_CMP(0)); - - /* Restart the main counter, and legacy mode. */ - hpet_write32(hpet_cfg | HPET_CFG_ENABLE | HPET_CFG_LEGACY, HPET_CF= G); - } + hpet_enable_legacy_replacement_mode(); =20 return hpet_rate; } diff --git a/xen/include/asm-x86/hpet.h b/xen/include/asm-x86/hpet.h index fb6bf05065..50176de3d2 100644 --- a/xen/include/asm-x86/hpet.h +++ b/xen/include/asm-x86/hpet.h @@ -73,6 +73,12 @@ void hpet_disable(void); int hpet_legacy_irq_tick(void); =20 /* + * Try to enable HPET Legacy Replacement mode. Returns a boolean indicati= ng + * whether the HPET configuration was changed. + */ +bool hpet_enable_legacy_replacement_mode(void); + +/* * Temporarily use an HPET event counter for timer interrupt handling, * rather than using the LAPIC timer. Used for Cx state entry. */ --=20 2.11.0 From nobody Fri Apr 26 23:27:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1616785236; cv=none; d=zohomail.com; s=zohoarc; b=jt1g2NZl9aMLUrrmcM5AIMaAZYq0etn/TBsmLhm5QTddE6/V2jAFHfR+cuX5TNNRV9J4DYyoRIFzLORGhyPgKPKu3v2do1u4zBXPpwJ6xjICqR+RD7SCsACNY6czBpNu6T1kOx5KkGjIYI72ff/aBR+ExWMJKMbqHCiwTywXefk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616785236; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=zsZGWgLuxcsE6B0AtLVZzDMAzggiZu60pK5xtpAUmNs=; b=Z6M3J4xj1Yid4sE8IMIe9pnaHYLOBqzqPUh5pjgKW7iqCahSKP9InZb9DeUPqRZM/eLPTZgHiDEiObY7bjvLOtpWO8K5bpsIca+w2J1HdIw9aC3++2uBjZ31jTeHjl6Ka60mYQtBqfZLjpHcsmoO5MHTvZ31xiVNV0p3vRiQL4c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1616785236718514.2183683557772; Fri, 26 Mar 2021 12:00:36 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.102057.195518 (Exim 4.92) (envelope-from ) id 1lPrgv-0007aT-QQ; Fri, 26 Mar 2021 19:00:17 +0000 Received: by outflank-mailman (output) from mailman id 102057.195518; Fri, 26 Mar 2021 19:00:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPrgv-0007aC-JR; Fri, 26 Mar 2021 19:00:17 +0000 Received: by outflank-mailman (input) for mailman id 102057; Fri, 26 Mar 2021 19:00:15 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPrgt-0007Ut-FD for xen-devel@lists.xenproject.org; Fri, 26 Mar 2021 19:00:15 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id edcdd280-ad82-411d-99ca-a5063ee47bef; Fri, 26 Mar 2021 19:00:13 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: edcdd280-ad82-411d-99ca-a5063ee47bef DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616785212; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pijmjnEufbImw81FhWbQec2beyZXgtBlQJQHB0Itw7E=; b=cUfm3dTQLCK7Ki/P5z68NDZxziXY/cto28/gLqs5+agNY5KDtycCYPiV 9iA9OSPLltIpbqtWe0Kvd1eEE5q2oC7torGfSFUf67eXE3oWERuZdO6wu b+MGf41H+z8XtlKGNfjeSkpxtxaaVUq97ZfJHRumjCKCpIBD/x8AxAfG8 g=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: znjSmlvOe8c1BcBVKXTS8nqurRRZ9FyXKDFF9VBpV/8TYKpGQMXM94k1moU9xUUImDXT86RAd3 afYVdG0L8cHK3Z066JpBRqeqy3rsRxoc3xId80Y5oLqxE4ONvnfExGRfDLMZkYgHvYhRyXfSfV 54KrbBkuWQd54/PjwSk0VFYRzQl//KXYgXW0TcA6DgAti5XUUOnpPYTs3zKZLcskCHbS6hrKYR tvK+PCyMpf64RM0wVZWAhHI6FlRB96jfz0UEw8cxhWuAbZtHWm/zI7ClImQqm5/mmY9q3DKC4s JmY= X-SBRS: 4.0 X-MesageID: 40605113 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:sR1ph6t38leYn8dlD/9y/ylP7skCzoYji2hD6mlwRA09T+WxrO rrtOgH1BPylTYaUGwhn9fFA6WbXXbA7/dOj7U5FYyJGC3ronGhIo0n14vtxDX8Bzbzn9Qz6Y 5JSII7MtH5CDFB4frSyAOzH888hPyO9661jenTpk0dMD1CQadm8gt/F0K/Gkp5WAFJCfMCZe ahz+BAoCetfmlSU9SjChA+LqT+jvDotLajWx4JABY79BKD5AnI1JfWGwWVty1uKg9n7qwl9Q H+4m7Ez4Wl98q20xrNk1LUhq4m4ufJ7vt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4+eO2L2Xqc9aDjaXadSRKJB/fqXO/JttY46x8rOY3rv9+DpPbWTzH2DVc0BIyINz9mU keTK54iYqxTLNHbogXYWZU71ApnNOAIA83qQTwGPY5ZkxogHnBPd+FioC45IYHEwmEvk/3Nl ae+SEGoKuAUCuHyLIAC6U/ZW5Rc1Mx7Xx+/OWEM43cYT/aBd1r7R6/KDu6drQYVa2OXbMXpR x+68uTn+CWezHjsTqgygdTM+ZL6SK/Xci2AAiQAuZG/NyxJESUjsKRkb2OpSayTSH+dl8Rio JEf1EBd8hPijEti4sszyi5I5aH134Ngh9Z+jFollnkx4ig7iPaBCh9QH3kvqk= X-IronPort-AV: E=Sophos;i="5.81,281,1610427600"; d="scan'208";a="40605113" From: Andrew Cooper To: Xen-devel CC: Jan Beulich , Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Ian Jackson , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret?= Subject: [PATCH v2 2/3] x86/hpet: Don't enable legacy replacement mode unconditionally Date: Fri, 26 Mar 2021 18:59:46 +0000 Message-ID: <20210326185947.23243-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210326185947.23243-1-andrew.cooper3@citrix.com> References: <20210326185947.23243-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Jan Beulich Commit e1de4c196a2e ("x86/timer: Fix boot on Intel systems using ITSSPRC static PIT clock gating") was reported to cause boot failures on certain AMD Ryzen systems. Refine the fix to do nothing in the default case, and only attempt to configure legacy replacement mode if IRQ0 is found to not be working. In addition, introduce a "hpet" command line option so this heuristic can be overridden. Since it makes little sense to introduce just "hpet=3Dlegacy-replacement", also allow for a boolean argument as well as "broadcast" to replace the separate "hpetbroadcast" option. Signed-off-by: Jan Beulich Signed-off-by: Andrew Cooper Reviewed-by: Roger Pau Monn=C3=A9 --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Ian Jackson CC: Marek Marczykowski-G=C3=B3recki CC: Fr=C3=A9d=C3=A9ric Pierret v2: * Reinstate missing hunk from Jan's original patch. * Fix up "8254 PIT". * Drop "goto retry". For 4.15: Attempt to unbreak AMD Ryzen 1800X systems. --- docs/misc/xen-command-line.pandoc | 33 +++++++++++++++++++++++++++ xen/arch/x86/hpet.c | 48 +++++++++++++++++++++++++----------= ---- xen/arch/x86/io_apic.c | 27 ++++++++++++++++++++++ xen/include/asm-x86/hpet.h | 1 + 4 files changed, 92 insertions(+), 17 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index a0601ff838..a4bd3f12c5 100644 --- a/docs/misc/xen-command-line.pandoc +++ b/docs/misc/xen-command-line.pandoc @@ -1274,9 +1274,42 @@ supported. See docs/misc/arm/big.LITTLE.txt for more= information. When the hmp-unsafe option is disabled (default), CPUs that are not identical to the boot CPU will be parked and not used by Xen. =20 +### hpet + =3D List of [ | broadcast=3D | legacy-replacement=3D ] + + Applicability: x86 + +Controls Xen's use of the system's High Precision Event Timer. By default, +Xen will use an HPET when available and not subject to errata. Use of the +HPET can be disabled by specifying `hpet=3D0`. + + * The `broadcast` boolean is disabled by default, but forces Xen to keep + using the broadcast for CPUs in deep C-states even when an RTC interrup= t is + enabled. This then also affects raising of the RTC interrupt. + + * The `legacy-replacement` boolean allows for control over whether Legacy + Replacement mode is enabled. + + Legacy Replacement mode is intended for hardware which does not have an + 8254 PIT, and allows the HPET to be configured into a compatible mode. + Intel chipsets from Skylake/ApolloLake onwards can turn the PIT off for + power saving reasons, and there is no platform-agnostic mechanism for + discovering this. + + By default, Xen will not change hardware configuration, unless the PIT + appears to be absent, at which point Xen will try to enable Legacy + Replacement mode before falling back to pre-IO-APIC interrupt routing + options. + + This behaviour can be inhibited by specifying `legacy-replacement=3D0`. + Alternatively, this mode can be enabled unconditionally (if available) = by + specifying `legacy-replacement=3D1`. + ### hpetbroadcast (x86) > `=3D ` =20 +Deprecated alternative of `hpet=3Dbroadcast`. + ### hvm_debug (x86) > `=3D ` =20 diff --git a/xen/arch/x86/hpet.c b/xen/arch/x86/hpet.c index c1d04f184f..bfa75f135a 100644 --- a/xen/arch/x86/hpet.c +++ b/xen/arch/x86/hpet.c @@ -52,6 +52,8 @@ static unsigned int __read_mostly num_hpets_used; DEFINE_PER_CPU(struct hpet_event_channel *, cpu_bc_channel); =20 unsigned long __initdata hpet_address; +int8_t __initdata opt_hpet_legacy_replacement =3D -1; +static bool __initdata opt_hpet =3D true; u8 __initdata hpet_blockid; u8 __initdata hpet_flags; =20 @@ -63,6 +65,32 @@ u8 __initdata hpet_flags; static bool __initdata force_hpet_broadcast; boolean_param("hpetbroadcast", force_hpet_broadcast); =20 +static int __init parse_hpet_param(const char *s) +{ + const char *ss; + int val, rc =3D 0; + + do { + ss =3D strchr(s, ','); + if ( !ss ) + ss =3D strchr(s, '\0'); + + if ( (val =3D parse_bool(s, ss)) >=3D 0 ) + opt_hpet =3D val; + else if ( (val =3D parse_boolean("broadcast", s, ss)) >=3D 0 ) + force_hpet_broadcast =3D val; + else if ( (val =3D parse_boolean("legacy-replacement", s, ss)) >= =3D 0 ) + opt_hpet_legacy_replacement =3D val; + else + rc =3D -EINVAL; + + s =3D ss + 1; + } while ( *ss ); + + return rc; +} +custom_param("hpet", parse_hpet_param); + /* * Calculate a multiplication factor for scaled math, which is used to con= vert * nanoseconds based values to clock ticks: @@ -820,12 +848,9 @@ u64 __init hpet_setup(void) unsigned int hpet_id, hpet_period; unsigned int last, rem; =20 - if ( hpet_rate ) + if ( hpet_rate || !hpet_address || !opt_hpet ) return hpet_rate; =20 - if ( hpet_address =3D=3D 0 ) - return 0; - set_fixmap_nocache(FIX_HPET_BASE, hpet_address); =20 hpet_id =3D hpet_read32(HPET_ID); @@ -852,19 +877,8 @@ u64 __init hpet_setup(void) if ( (rem * 2) > hpet_period ) hpet_rate++; =20 - /* - * Intel chipsets from Skylake/ApolloLake onwards can statically clock - * gate the 8259 PIT. This option is enabled by default in slightly l= ater - * systems, as turning the PIT off is a prerequisite to entering the C= 11 - * power saving state. - * - * Xen currently depends on the legacy timer interrupt being active wh= ile - * IRQ routing is configured. - * - * Reconfigure the HPET into legacy mode to re-establish the timer - * interrupt. - */ - hpet_enable_legacy_replacement_mode(); + if ( opt_hpet_legacy_replacement > 0 ) + hpet_enable_legacy_replacement_mode(); =20 return hpet_rate; } diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c index e93265f379..3f131a81fb 100644 --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -29,6 +29,8 @@ #include #include #include + +#include #include #include #include @@ -1930,6 +1932,31 @@ static void __init check_timer(void) local_irq_restore(flags); return; } + + /* + * Intel chipsets from Skylake/ApolloLake onwards can statically c= lock + * gate the 8254 PIT. This option is enabled by default in slight= ly + * later systems, as turning the PIT off is a prerequisite to ente= ring + * the C11 power saving state. + * + * Xen currently depends on the legacy timer interrupt being active + * while IRQ routing is configured. + * + * If the user hasn't made an explicit choice, attempt to reconfig= ure + * the HPET into legacy mode to re-establish the timer interrupt. + */ + if ( opt_hpet_legacy_replacement < 0 && + hpet_enable_legacy_replacement_mode() ) + { + printk(XENLOG_ERR "..no 8254 timer found - trying HPET Legacy = Replacement Mode\n"); + + if ( timer_irq_works() ) + { + local_irq_restore(flags); + return; + } + } + clear_IO_APIC_pin(apic1, pin1); printk(KERN_ERR "..MP-BIOS bug: 8254 timer not connected to " "IO-APIC\n"); diff --git a/xen/include/asm-x86/hpet.h b/xen/include/asm-x86/hpet.h index 50176de3d2..07bc8d6079 100644 --- a/xen/include/asm-x86/hpet.h +++ b/xen/include/asm-x86/hpet.h @@ -53,6 +53,7 @@ extern unsigned long hpet_address; extern u8 hpet_blockid; extern u8 hpet_flags; +extern int8_t opt_hpet_legacy_replacement; =20 /* * Detect and initialise HPET hardware: return counter update frequency. --=20 2.11.0 From nobody Fri Apr 26 23:27:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=reject dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1616785235; cv=none; d=zohomail.com; s=zohoarc; b=lcFjNzL9vMtstN1KzKoXTCU6Iwgj0VuBjgtmUL2mjroKKxrZ/nyf6AqRHWZUJee7L75n0FPxkt91HondKvDPfYgnI6gH3aMC1sprk8R5cQ//ACyJjmIFZEKFbQykl2SF7gRVfKkY8LRUjfiNQO0CR0o7MEcTEdDbBhKk8XQgWnA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616785235; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=t2VsIMRwuN7sCHs+iEof5DRjt+rmVnV/BroJZjmUpgQ=; b=gRDL9XXP/u7dzRf9YFDFkPtLmsvI8S8/7HjcPsFqhFQ1RDn1QkCTCWvdUXsTL6QrBV+J7U9WUo+1T7naVej8fEuZwgsz/dfpqpot4HzLdQED3E8MZzzlvUU9eeVzrjEsdk3U6unrysMVrcfnU4Fp0Zb/bTqiAp+hbbylDASyANc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=reject dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1616785235848896.9950089714117; Fri, 26 Mar 2021 12:00:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.102055.195499 (Exim 4.92) (envelope-from ) id 1lPrgp-0007VO-Sp; Fri, 26 Mar 2021 19:00:11 +0000 Received: by outflank-mailman (output) from mailman id 102055.195499; Fri, 26 Mar 2021 19:00:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPrgp-0007VF-Pk; Fri, 26 Mar 2021 19:00:11 +0000 Received: by outflank-mailman (input) for mailman id 102055; Fri, 26 Mar 2021 19:00:10 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPrgo-0007Ut-NB for xen-devel@lists.xenproject.org; Fri, 26 Mar 2021 19:00:10 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 36518861-707e-490e-81d4-4a6817d0faed; Fri, 26 Mar 2021 19:00:08 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 36518861-707e-490e-81d4-4a6817d0faed DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616785208; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hoKdN8csoqaelamoWrWzTqNBSKLs0axyRHUC7J8rEEM=; b=gx1r9eI73xNbKuUiua2I/lygw/wRiyTVDbC+8peT8iR7g3rzW4LAQYMm CUBVwtkvakv0/XhDtupEEExCVj+6UpV1s6+0jAeQ6eobtALPIYtPfmkLD D2xuxWWNllX6/vgbVasPvR6VQvf/ZOxGc6NpvQrErMZw9RLMQVJY5L0EH c=; Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: zsK55gemVstwCTyRH4LtBkpgWq9VD3bgys0Wg2m345eRf9KH+ZOWQsUCzxvlpCQPx6z3eNtMRS u7T24eJQzpBkY42Covx4PExdpw+9NwYbNoO3rWzSrUz2fLYS34+n3g+RP1buqJZ2qv6JwcZFV+ OGmCxPiGC2QaT/ExROJqUGkf/3X2ot9zS1Tmx16i7HVpZnoZ6Jk/s+QcsQuUbrINkchvV0OiF9 2Y4CC/qWPy8FFXWPLGlPUDj0y2NavoMscCXumMKBsxmFQ+BMSmGmjfTyZZvyHXxa9XsbhybYdw nhA= X-SBRS: 4.0 X-MesageID: 40605106 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:m83dP606WrBnf0xHY/R78gqjBal2eYIsi2QD101hICF9Wvez0+ izgfUW0gL1gj4NWHcm3euNIrWEXGm0z/FIyKErF/OHUBP9sGWlaLtj44zr3iH6F0TFmtJ1/Z xLN5JzANiYNzVHpO7x6gWgDpIEyN6I7KiniY7lvg1QZCthApsQtTtRIACdD0FwWU1iDZ02CJ KT6qN81kedUF4Qadm2AWRAYvjbq7Tw5d7bSDMlJzpi0gmBiju09KX3eiL34j4yWy5CqI1Sl1 TtvBf+4syYwpKG4z/ak1Te9pFH3Obmo+Ezf/CkrugwBnHShh2zZIJnMofy8wwdhO208l4lnJ 3tjn4bTr1OwkjcdG20vhfhsjOIuF1Fih/f4GSVjnf5rcvySChSMbs4uatibhDb50A81esMtZ 5j4mODu5JbSTPGkSjtjuK4MC1Cq0uurXIu1dMUlnxUOLFuDIN5kIp3xjI2LL4wWAbBrKw3Gu hnC8/RoNxMd0mBUnzftm5zhPSx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bhW9X27Bcy1GwCBFIdzgpGHEEXJhrHv5sG9jD36E2TmL0sZgJ BIbkwWYIBIjCI4gIg+zyi1Tej2ryse4ihjyCAikkSo3I6spHrfFwVBNwbSh51NRzldMnSSl6 3+gJ+l/WW45CIAwIXJEUdbY8pHFNcRRJXmNisGE7lhgJe4u640xjlZaBggD2QgmCnw0uNv07 C+wujTUYTZeAXVEENE/yVECI5yljEqrm8Fc9HW1+PNXjkq X-IronPort-AV: E=Sophos;i="5.81,281,1610427600"; d="scan'208";a="40605106" From: Andrew Cooper To: Xen-devel CC: Andrew Cooper , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , Ian Jackson , =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= , =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Pierret?= Subject: [PATCH v2 3/3] x86/hpet: Restore old configuration if Legacy Replacement mode doesn't help Date: Fri, 26 Mar 2021 18:59:47 +0000 Message-ID: <20210326185947.23243-4-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210326185947.23243-1-andrew.cooper3@citrix.com> References: <20210326185947.23243-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) If Legacy Replacement mode doesn't help in check_timer(), restore the old configuration before falling back to other workarounds. Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich Reviewed-by: Roger Pau Monn=C3=A9 --- CC: Jan Beulich CC: Roger Pau Monn=C3=A9 CC: Wei Liu CC: Ian Jackson CC: Marek Marczykowski-G=C3=B3recki CC: Fr=C3=A9d=C3=A9ric Pierret v2: * New. For 4.15: Attempt to unbreak AMD Ryzen 1800X systems. I'm tempted to fold this into the previous patch, but its presented here in isolation for ease of review. Tested by repositioning the timer_irq_works() calls on a system with a work= ing PIT. (XEN) ENABLING IO-APIC IRQs (XEN) -> Using old ACK method (XEN) ..TIMER: vector=3D0xF0 apic1=3D0 pin1=3D2 apic2=3D0 pin2=3D0 (XEN) ..no 8254 timer found - trying HPET Legacy Replacement Mode (XEN) ..no HPET timer found - reverting Legacy Replacement Mode (XEN) TSC deadline timer enabled --- xen/arch/x86/hpet.c | 27 ++++++++++++++++++++++++++- xen/arch/x86/io_apic.c | 4 ++++ xen/include/asm-x86/hpet.h | 6 ++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hpet.c b/xen/arch/x86/hpet.c index bfa75f135a..afe104dc93 100644 --- a/xen/arch/x86/hpet.c +++ b/xen/arch/x86/hpet.c @@ -783,6 +783,9 @@ int hpet_legacy_irq_tick(void) =20 static u32 *hpet_boot_cfg; static uint64_t __initdata hpet_rate; +static __initdata struct { + uint32_t cmp, cfg; +} pre_legacy_c0; =20 bool __init hpet_enable_legacy_replacement_mode(void) { @@ -796,8 +799,11 @@ bool __init hpet_enable_legacy_replacement_mode(void) /* Stop the main counter. */ hpet_write32(cfg & ~HPET_CFG_ENABLE, HPET_CFG); =20 + /* Stash channel 0's old CFG/CMP incase we need to undo. */ + pre_legacy_c0.cfg =3D c0_cfg =3D hpet_read32(HPET_Tn_CFG(0)); + pre_legacy_c0.cmp =3D hpet_read32(HPET_Tn_CMP(0)); + /* Reconfigure channel 0 to be 32bit periodic. */ - c0_cfg =3D hpet_read32(HPET_Tn_CFG(0)); c0_cfg |=3D (HPET_TN_ENABLE | HPET_TN_PERIODIC | HPET_TN_SETVAL | HPET_TN_32BIT); hpet_write32(c0_cfg, HPET_Tn_CFG(0)); @@ -843,6 +849,25 @@ bool __init hpet_enable_legacy_replacement_mode(void) return true; } =20 +void __init hpet_disable_legacy_replacement_mode(void) +{ + unsigned int cfg =3D hpet_read32(HPET_CFG); + + ASSERT(hpet_rate); + + cfg &=3D ~(HPET_CFG_LEGACY | HPET_CFG_ENABLE); + + /* Stop the main counter and disable legacy mode. */ + hpet_write32(cfg, HPET_CFG); + + /* Restore pre-Legacy Replacement Mode settings. */ + hpet_write32(pre_legacy_c0.cfg, HPET_Tn_CFG(0)); + hpet_write32(pre_legacy_c0.cmp, HPET_Tn_CMP(0)); + + /* Restart the main counter. */ + hpet_write32(cfg | HPET_CFG_ENABLE, HPET_CFG); +} + u64 __init hpet_setup(void) { unsigned int hpet_id, hpet_period; diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c index 3f131a81fb..58b26d962c 100644 --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -1955,6 +1955,10 @@ static void __init check_timer(void) local_irq_restore(flags); return; } + + /* Legacy Replacement mode hasn't helped. Undo it. */ + printk(XENLOG_ERR "..no HPET timer found - reverting Legacy Re= placement Mode\n"); + hpet_disable_legacy_replacement_mode(); } =20 clear_IO_APIC_pin(apic1, pin1); diff --git a/xen/include/asm-x86/hpet.h b/xen/include/asm-x86/hpet.h index 07bc8d6079..8f9725a95e 100644 --- a/xen/include/asm-x86/hpet.h +++ b/xen/include/asm-x86/hpet.h @@ -80,6 +80,12 @@ int hpet_legacy_irq_tick(void); bool hpet_enable_legacy_replacement_mode(void); =20 /* + * Undo the effects of hpet_disable_legacy_replacement_mode(). Must not be + * called unless enable() returned true. + */ +void hpet_disable_legacy_replacement_mode(void); + +/* * Temporarily use an HPET event counter for timer interrupt handling, * rather than using the LAPIC timer. Used for Cx state entry. */ --=20 2.11.0