From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web11.10224.1688729173060371756 for ; Fri, 07 Jul 2023 04:26:13 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hCFuiJ+x; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688729171; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=DJNS7ofRyyI8JyV30Xe+Jn/aEAVbmSm9BCW6Xr2keoY=; b=hCFuiJ+x9ZcjFKNDYnwkcxS2yZe4e14C+SMhuZP9cexAl0wkMmQncA+7srh5QhnYRy2ql4 MUlFmXWSkFJ/rWDvmhI+Z/Q1ea23PcaTLo3h95QWk4E8ZAzDBoxeRaZxRY8uYxMh4htY5K kjQn4lCQ4wdbTzDCThjCDwIwg/nJd9U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-596-lNkyHfDeNSicjMkZidYp7A-1; Fri, 07 Jul 2023 07:26:10 -0400 X-MC-Unique: lNkyHfDeNSicjMkZidYp7A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6E5BB80123E; Fri, 7 Jul 2023 11:26:10 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.253]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2562B2166B25; Fri, 7 Jul 2023 11:26:10 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C84B21800626; Fri, 7 Jul 2023 13:26:08 +0200 (CEST) Date: Fri, 7 Jul 2023 13:26:08 +0200 From: "Gerd Hoffmann" To: "Ni, Ray" Cc: "devel@edk2.groups.io" Subject: Re: [edk2-devel] [PATCH 0/4] Sync BSP's APIC mode to APs in MP init flow Message-ID: References: <20230707052901.869-1-ray.ni@intel.com> <4nerjr3hcwfepwzllcsrm3vurwzdyvr7qz6b4lqfualkngt7he@vjtw4v2ixksc> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Jul 07, 2023 at 09:25:39AM +0000, Ni, Ray wrote: > Gerd, > No. I don't plan to add PCD. > I thought that initially but in the end I figured out: > * PCD is a way to let platform configure the common logic behavior. > * Why not treat "X2 APIC status in BSP" as a "hardware" PCD? A PCD has the advantage that most configuration knobs use that, so people are used to use PCDs to configure their platform builds. Using hardware status as pseudo PCD technically works too, and it isn't the first case in edk2 either, 5-level paging works the same way for example. ovmf test patch (enabling x2mode unconditionally) below. Tested-by: Gerd Hoffmann Acked-by: Gerd Hoffmann take care, Gerd ------------------------------ cut here ----------------------------- >>From 46a2d9128c42f62547f76afbdb8eef9cf5d0a8a1 Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Fri, 7 Jul 2023 12:44:21 +0200 Subject: [PATCH 1/1] OvmfPkg/PlatformPei: enable x2apic mode if supported Switch the BSP local apic into x2apic mode if supported by the CPU. CpuMpPei will switch the APs into x2apic mode, see commit FIXME. Signed-off-by: Gerd Hoffmann --- OvmfPkg/PlatformPei/PlatformPei.inf | 1 + OvmfPkg/PlatformPei/Platform.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index 3934aeed9514..b670e1ba6745 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -52,6 +52,7 @@ [LibraryClasses] DebugLib HobLib IoLib + LocalApicLib PciLib ResourcePublicationLib PeiServicesLib diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index f5dc41c3a8c4..fd34fceafa31 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -271,6 +272,29 @@ MaxCpuCountInitialization ( ASSERT_RETURN_ERROR (PcdStatus); } +STATIC +VOID +PlatformApicInit ( + IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob + ) +{ + UINT32 RegEax, RegEbx, RegEcx, RegEdx; + + AsmCpuid (1, &RegEax, &RegEbx, &RegEcx, &RegEdx); + if (!(RegEcx & (1 << 21))) { + DEBUG ((DEBUG_INFO, "%a: x2apic mode not supported\n", __func__)); + return; + } + + SetApicMode(LOCAL_APIC_MODE_X2APIC); + if (!(GetApicMode() == LOCAL_APIC_MODE_X2APIC)) { + DEBUG ((DEBUG_WARN, "%a: enabling x2apic mode failed\n", __func__)); + return; + } + + DEBUG ((DEBUG_INFO, "%a: x2apic mode enabled\n", __func__)); +} + /** * @brief Builds PlatformInfo Hob */ @@ -368,5 +392,7 @@ InitializePlatform ( IntelTdxInitialize (); InstallFeatureControlCallback (PlatformInfoHob); + PlatformApicInit(PlatformInfoHob); + return EFI_SUCCESS; } -- 2.41.0