From patchwork Thu Dec 8 15:33:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 9466605 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1A221607D3 for ; Thu, 8 Dec 2016 15:55:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B40A28499 for ; Thu, 8 Dec 2016 15:55:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3660285B2; Thu, 8 Dec 2016 15:55:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A0E9028499 for ; Thu, 8 Dec 2016 15:55:42 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cF10k-0002md-Gp; Thu, 08 Dec 2016 15:53:30 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cF10j-0002mW-Ab for xen-devel@lists.xenproject.org; Thu, 08 Dec 2016 15:53:29 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id 9C/DD-29519-8F189485; Thu, 08 Dec 2016 15:53:28 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRWlGSWpSXmKPExsXitHRDpO6PRs8 IgzUL+Cy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozPp9awF+wVr3j+aApzA+NS4S5GTg4JAX+J RQc3MoLYbAIGEiumXwWzRQTsJWZ/7GMHsZkF9CTOLVrICmILCyRKnDy1DsxmEVCReDvjL3MXI wcHr4CdxIluXoiR8hILzx9hArE5gcLHN39mA7GFBGwlHt/8zQhhq0ncWLiMBcTmFRCUODnzCQ vEKgmJgy9eME9g5J2FJDULSWoBI9MqRo3i1KKy1CJdYwO9pKLM9IyS3MTMHF1DAzO93NTi4sT 01JzEpGK95PzcTYzA0GEAgh2Mf9cGHmKU5GBSEuXdNcE9QogvKT+lMiOxOCO+qDQntfgQowwH h5IErx8wFIUEi1LTUyvSMnOAQQyTluDgURLhvVMPlOYtLkjMLc5Mh0idYtTlWDBh5VMmIZa8/ LxUKXHeBw1ARQIgRRmleXAjYBF1iVFWSpiXEegoIZ6C1KLczBJU+VeM4hyMSsK850Cm8GTmlc BtegV0BBPQEfNuuIMcUZKIkJJqYMxLVLNY6t2+eIfaE/dNooZHlu/7OzPeNtTM/v/vnDWx1y+ uuL7qX3jytfXJl5485F/WcMfYS/rtjMhH1wPzQ3d67g7dP4k5JSJ1X/rUtyKzxJye7fVYpWIX MWn68rUp8m7VPDsD1kY+THs1//GPlSccTgpb7zlq2bPPaebN6svPldnUpZNPfp+pxFKckWiox VxUnAgAoSW8vqMCAAA= X-Env-Sender: prvs=143a4c3ea=anthony.perard@citrix.com X-Msg-Ref: server-3.tower-27.messagelabs.com!1481212406!76124734!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 58423 invoked from network); 8 Dec 2016 15:53:28 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-3.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 8 Dec 2016 15:53:28 -0000 X-IronPort-AV: E=Sophos;i="5.33,320,1477958400"; d="scan'208";a="393762211" From: Anthony PERARD To: , Date: Thu, 8 Dec 2016 15:33:36 +0000 Message-ID: <20161208153340.2285-11-anthony.perard@citrix.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161208153340.2285-1-anthony.perard@citrix.com> References: <20161208153340.2285-1-anthony.perard@citrix.com> MIME-Version: 1.0 Cc: Anthony PERARD Subject: [Xen-devel] [PATCH RFC 10/14] UefiCpuPkg/BaseXApicX2ApicLib: Fix initialisation on my system and ... X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP declare more exported function, ReadLocalApicReg and WriteLocalApicReg. On my system (running OVMF inside a Xen PVH guest), writing the interrupt information (to XAPIC_LVT_TIMER_OFFSET) would also reset the init-count register, thus disabling the timer. --- UefiCpuPkg/Include/Library/LocalApicLib.h | 40 ++++++++++++++++++++++ .../BaseXApicX2ApicLib/BaseXApicX2ApicLib.c | 10 +++--- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/UefiCpuPkg/Include/Library/LocalApicLib.h b/UefiCpuPkg/Include/Library/LocalApicLib.h index fc980bc..ab621f2 100644 --- a/UefiCpuPkg/Include/Library/LocalApicLib.h +++ b/UefiCpuPkg/Include/Library/LocalApicLib.h @@ -48,6 +48,46 @@ SetLocalApicBaseAddress ( ); /** + Read from a local APIC register. + + This function reads from a local APIC register either in xAPIC or x2APIC mode. + It is required that in xAPIC mode wider registers (64-bit or 256-bit) must be + accessed using multiple 32-bit loads or stores, so this function only performs + 32-bit read. + + @param MmioOffset The MMIO offset of the local APIC register in xAPIC mode. + It must be 16-byte aligned. + + @return 32-bit Value read from the register. +**/ +UINT32 +EFIAPI +ReadLocalApicReg ( + IN UINTN MmioOffset + ); + +/** + Write to a local APIC register. + + This function writes to a local APIC register either in xAPIC or x2APIC mode. + It is required that in xAPIC mode wider registers (64-bit or 256-bit) must be + accessed using multiple 32-bit loads or stores, so this function only performs + 32-bit write. + + if the register index is invalid or unsupported in current APIC mode, then ASSERT. + + @param MmioOffset The MMIO offset of the local APIC register in xAPIC mode. + It must be 16-byte aligned. + @param Value Value to be written to the register. +**/ +VOID +EFIAPI +WriteLocalApicReg ( + IN UINTN MmioOffset, + IN UINT32 Value + ); + +/** Get the current local APIC mode. If local APIC is disabled, then ASSERT. diff --git a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c index e690d2a..f84a40a 100644 --- a/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c +++ b/UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c @@ -820,11 +820,6 @@ InitializeApicTimer ( // InitializeLocalApicSoftwareEnable (TRUE); - // - // Program init-count register. - // - WriteLocalApicReg (XAPIC_TIMER_INIT_COUNT_OFFSET, InitCount); - if (DivideValue != 0) { ASSERT (DivideValue <= 128); ASSERT (DivideValue == GetPowerOfTwo32((UINT32)DivideValue)); @@ -848,6 +843,11 @@ InitializeApicTimer ( LvtTimer.Bits.Mask = 0; LvtTimer.Bits.Vector = Vector; WriteLocalApicReg (XAPIC_LVT_TIMER_OFFSET, LvtTimer.Uint32); + + // + // Program init-count register. + // + WriteLocalApicReg (XAPIC_TIMER_INIT_COUNT_OFFSET, InitCount); } /**