From nobody Fri Apr 26 00:06:32 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=1616691179; cv=none; d=zohomail.com; s=zohoarc; b=nNGlo7t9Tmtxhm/LCla2YnhlhzCJ53ZQZVBLjR1KxvJHrgYV4WDqzg6MJSHXZvBt9OaxdAsxQjGCxpYEXLa2vhglEyb1EPPYlgB7XVgI24OaSlaBHkvWGliDbJVUWx7UZ1PkTgH5yQQ5VO4Pu8+stq1jvhZGAnllrypasu21ACw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616691179; 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=OA6nC7SY7kOe4uaLffD0cs8EwRSpVeL4NI83RRpLtk8=; b=ZzETjkWX11uAjPjik/oLJLZw7Exzq+KuuO8nKFSuLG6yLxbLl77sqlq3gIu1QmhWuLQ8HS/lpqDzgkhInNA6B3Lc5yV45ue1Ph7lwyT2cYyiKb59YMUtR1K+3IKPBeQyzkTUpc1NSTFDngAzqMm3hsqHgCdA+PqzU4CEimmcZMg= 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 16166911791981007.68836966226; Thu, 25 Mar 2021 09:52:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.101471.194157 (Exim 4.92) (envelope-from ) id 1lPTDw-00089s-5Q; Thu, 25 Mar 2021 16:52:44 +0000 Received: by outflank-mailman (output) from mailman id 101471.194157; Thu, 25 Mar 2021 16:52:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPTDw-00089j-1P; Thu, 25 Mar 2021 16:52:44 +0000 Received: by outflank-mailman (input) for mailman id 101471; Thu, 25 Mar 2021 16:52:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPTDu-00086s-8e for xen-devel@lists.xenproject.org; Thu, 25 Mar 2021 16:52:42 +0000 Received: from esa2.hc3370-68.iphmx.com (unknown [216.71.145.153]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e47308dd-7b06-4e4a-843d-dac0c04026ed; Thu, 25 Mar 2021 16:52:37 +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: e47308dd-7b06-4e4a-843d-dac0c04026ed DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616691155; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LF+lVlyKXExW6Io/IYUvBnZgXV3D7BVJSGsgMrjUOUs=; b=YHFLKxJKVx870MMzJ9EdWJauFtoOfUtV4BMe5sZa4y/O11Oz3qJ9ssat pLR0q8mOEuz6YcHvX8IVXIRc7l0RxitN2ztaKS4d8MwTgSQM+43/Llcwi yT8+n1jvMmE8liPTBGAWl5lKNGogLRgleDhOtkbFAQ+qzD9AqTBECa20D Y=; Authentication-Results: esa2.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: bmaiUR7yfJ8R/GUMREX9NrRJ3FNleS1FK8wrw7uP7vcOwjdf38dLKs2dKsdtryATOcOR42Dtxd egzIL1EYDR/v3bbaxkTW2FT7oW5ZdN4H36o6JrRLlRCqCM8g/ldjIgk1nqpMG7fF8AFgKPnyTP tAf9vYOjlD7wdi7nfOAXbsiPxXX4uubMpbAvJXCkqlBd9381O2OA7ibyd/sPSL81D9WQ/6FzuE pKlin/tTdVp06HLPidV8DDD2LZTewcPtrvmc8c6MLxDhoNFJbvH3HHYUn1Buenqx0eBsLGcd7o Zkw= X-SBRS: 5.1 X-MesageID: 40150746 X-Ironport-Server: esa2.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:1/9vfaGHtPdr4ZzmpLqFMpHXdLJzesId70hD6mlYVQFVfsuEl8 qngfQc0lvOhCwMXWw78OrsBICrR3TA+ZlppbQAJLvKZniChEKEDqFHqbHjzTrpBjHk+odmv5 tIXqBiBLTLYmRSot395GCDfeoI5Pmi3OSWifzFz3FrJDsaCZ1IywtiEA6UHglXaWB9ZaYRL5 aX6spZqzfIQx1+AviTPXUZQ/PF4+TCiZOOW3U7LiQ64wqDhy7A0s+YLzGk2H4lMg9n8PMZ3k Xu1yf44aiitP/T8G6n60bjq654tfGk5t9KBMmngtUYJDP2mm+TFflccozHhh8ZiqWC70srjc ntrn4bTrhOwkKURE6Zi1/M3BTtyzkn4XOK8y7mvVLT5fbXaRh/Lugpv/M8TjLpr3AOkfs57Y dwm0WejJZTBQOoplWE2/H4EytEu2DxnWAvioco/htieLpbUpB9h6oF8nhYFZ8RdRiKk7wPIa 1VAMbQ6O0+SyL9U1np+m1mwNmbVn8uBBuxQk8bpsyP0zRN9UoJtncl+A== X-IronPort-AV: E=Sophos;i="5.81,278,1610427600"; d="scan'208";a="40150746" 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 1/2] x86/hpet: Factor hpet_enable_legacy_replacement_mode() out of hpet_setup() Date: Thu, 25 Mar 2021 16:52:23 +0000 Message-ID: <20210325165224.10306-2-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210325165224.10306-1-andrew.cooper3@citrix.com> References: <20210325165224.10306-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. --- 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..c73135bb15 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 u64 __initdata hpet_rate; + +bool __init hpet_enable_legacy_replacement_mode(void) +{ + unsigned int id, cfg, c0_cfg, ticks, count; + + if ( !hpet_rate || + !((id =3D 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 00:06:32 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=1616691181; cv=none; d=zohomail.com; s=zohoarc; b=l//0JLNhxJpnC5jGdTfez8diso1U4FLCUkKQAGSPSZFJeUuwFuiPutPfr0c5QIUALHYanw2OmNGFw/Y8/FbwM723K34ypOLEjgR34kRNwgBevFyssUHjapBjua08FmpnAZACYSW97Z0z5d5K6AbBBC5ke2TxGDNNndZvblIsQ8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616691181; 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=qdsDs25FaQwshbYkMSEs1P/jGXBingpLm53DwdCjV7I=; b=bIxBKMijePStneVrHmNFAWuBvd6IPd20rygqUuAkRFqLr9zjutaY2dCTO0XJw4Sw2zuoE373FAfg2cA80Gf9wcoLCEDrNUp+iyfxe8bJQAlASZ84IIxarGkKVi8VuQxXScKwTiogUqDoTAUJZbXQj3iuWmycOl8JFiUy6v9Zg4E= 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 1616691181513182.1852573890991; Thu, 25 Mar 2021 09:53:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.101472.194163 (Exim 4.92) (envelope-from ) id 1lPTDw-0008Aa-Hr; Thu, 25 Mar 2021 16:52:44 +0000 Received: by outflank-mailman (output) from mailman id 101472.194163; Thu, 25 Mar 2021 16:52:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lPTDw-0008AG-AO; Thu, 25 Mar 2021 16:52:44 +0000 Received: by outflank-mailman (input) for mailman id 101472; Thu, 25 Mar 2021 16:52:42 +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 1lPTDu-00089F-MZ for xen-devel@lists.xenproject.org; Thu, 25 Mar 2021 16:52:42 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id c614e899-3e75-4f93-9eda-704564dac97a; Thu, 25 Mar 2021 16:52:41 +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: c614e899-3e75-4f93-9eda-704564dac97a DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1616691161; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UmOB2jpI/LNrB0BQxya0yK8puikk3iTXwPa1pCoadQg=; b=MtzR9I0JgDMdaQNLPvFAoJiOpc/i+Ka+uS+vI9nSq9MlDfXgWbBib68Y 3IMTWRwfW5vQzD9Oq7Ss3K/BdE8vNKFQwRmxhi0qjOIhBJR/ZcrwLzG1p IOH6pm0FasRgLtXiRYESs88tUUTDBxCEBKp9j83Zg71hNwaAzgcOtLoLD o=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: ZF5JUZj0PBnumeYqkxjXpDB5Z2DdwGuyRJDmERprCcJ4u4Ga1RzxYMvyBth5h0f0+GNast+IvF JXKM0sch9PNPhAFhVwVXcD/kH+pgBJ35h4pFyqqXgt9anXVbodmJHDl9g3RWEsPVwxf8rRKYoy 49suzN2HEGxPsq8A4P2LjHLJi/DfkM1Dzwrw8XTudMDuWE5oErW2Jgbnb1/A+8jkrGzdLjRZ/X 4q5DVrAogqBjRkmVtkyoqLYqRAumKEb/xVIwxL78doOQiV5wTHN8OymPWXmnebnkhhUURm/ILb 55c= X-SBRS: 5.1 X-MesageID: 40024416 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED IronPort-HdrOrdr: A9a23:Iy04eK0FOg1DhiKEDkc51QqjBWByeYIsi2QD101hICF9WtCEls yogfQQ3QL1jjFUY307hdWcIsC7LE/035Qd2+ksFJ2lWxTrv3btEZF64eLZslndMgDd1soY76 dvdKBiFMb9ZGIRse/W6BS1euxO/PCp66at7N2x815IbSVHL55t9B14DAHzKDwSeCBjCYAiHJ SRouprzgDQGkg/VciwCnkbU+WrnbSi+K7OWhIaGwUhrDCHkDLA0tXHOiKF1RQTWS4n+8ZBzU H5lWXCh5mLgrWA5TL3k0TS6JlXn9WJ8Ko/OOW8zvI7Bx+ppgKhZIFKU6CPsjYvsIiUmSoXue iJmTgMFYBe7G7QY3GUrHLWqnbd+Qdr0VDO4xu5hmbuusPwTj5SMbs+uatpNiH3xmBlmfMU6t Mt40up86B5IDmFoQHGo//PbB1unlrcmwtYrccjy0ZxfKFbVKVctuUkjSVoOaZFJg3WwqY9Ht JjCcnNjcwmC2+yXjTism5jzMfEZAVLIj62BkwLusmi2zNLhnxOz0wB2MwFnnsbnahNM6V52w == X-IronPort-AV: E=Sophos;i="5.81,278,1610427600"; d="scan'208";a="40024416" 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 2/2] x86/hpet: Don't enable legacy replacement mode unconditionally Date: Thu, 25 Mar 2021 16:52:24 +0000 Message-ID: <20210325165224.10306-3-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210325165224.10306-1-andrew.cooper3@citrix.com> References: <20210325165224.10306-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 --- 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: Attempt to unbreak AMD Ryzen 1800X systems. --- docs/misc/xen-command-line.pandoc | 33 ++++++++++++++++++++++++++++++ xen/arch/x86/hpet.c | 43 +++++++++++++++++++++++++++--------= ---- xen/arch/x86/io_apic.c | 26 +++++++++++++++++++++++ xen/include/asm-x86/hpet.h | 1 + 4 files changed, 90 insertions(+), 13 deletions(-) diff --git a/docs/misc/xen-command-line.pandoc b/docs/misc/xen-command-line= .pandoc index a0601ff838..4d020d4ad7 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 (x86) + =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 + 8025 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 c73135bb15..270fef38c3 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: @@ -852,19 +880,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..f08c60d71f 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 @@ -1922,14 +1924,38 @@ static void __init check_timer(void) vector, apic1, pin1, apic2, pin2); =20 if (pin1 !=3D -1) { + bool hpet_changed =3D false; + /* * Ok, does IRQ0 through the IOAPIC work? */ unmask_IO_APIC_irq(irq_to_desc(0)); + retry_ioapic_pin: if (timer_irq_works()) { local_irq_restore(flags); return; } + + /* + * Intel chipsets from Skylake/ApolloLake onwards can statically c= lock + * gate the 8259 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 option, attempt to reconfig= ure + * the HPET into legacy mode to re-establish the timer interrupt. + */ + if ( opt_hpet_legacy_replacement < 0 && + !hpet_changed && hpet_enable_legacy_replacement_mode() ) + { + printk(XENLOG_ERR "..no 8254 timer found - trying HPET Legacy = Replacement Mode\n"); + hpet_changed =3D true; + goto retry_ioapic_pin; + } + 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