From patchwork Thu Dec 8 15:33:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony PERARD X-Patchwork-Id: 9466539 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 7417F607D4 for ; Thu, 8 Dec 2016 15:37:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67D10284FE for ; Thu, 8 Dec 2016 15:37:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C7CC2853F; Thu, 8 Dec 2016 15:37:55 +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 E2E0F28501 for ; Thu, 8 Dec 2016 15:37:54 +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 1cF0jm-0007sa-0t; Thu, 08 Dec 2016 15:35:58 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cF0jk-0007ox-7t for xen-devel@lists.xenproject.org; Thu, 08 Dec 2016 15:35:56 +0000 Received: from [193.109.254.147] by server-9.bemta-6.messagelabs.com id 07/A4-28694-CDD79485; Thu, 08 Dec 2016 15:35:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIIsWRWlGSWpSXmKPExsXitHSDve7tWs8 Ig88zlSy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owXW1vZCqYoVuxv3sncwDhDqouRk0NCwF/i wcljrCA2m4CBxIrpVxlBbBEBe4nZH/vYQWxmAT2Jc4sWgtUIC/hI7O/5xgRiswioSCy6uJ0Zx OYVsJWY2NvMCjFTXmLh+SNgNZwCdhLHN39mA7GFgGoe3/zNCGGrSdxYuIwFoldQ4uTMJywQuy QkDr54wTyBkXcWktQsJKkFjEyrGDWKU4vKUot0jUz0kooy0zNKchMzc3QNDcz0clOLixPTU3M Sk4r1kvNzNzECg4cBCHYwrlwXeIhRkoNJSZR31wT3CCG+pPyUyozE4oz4otKc1OJDjDIcHEoS vLNqPCOEBItS01Mr0jJzgGEMk5bg4FES4XUChrIQb3FBYm5xZjpE6hSjLseCCSufMgmx5OXnp UqJ83KCFAmAFGWU5sGNgMXUJUZZKWFeRqCjhHgKUotyM0tQ5V8xinMwKgnzyoNcwpOZVwK36R XQEUxAR8y74Q5yREkiQkqqgTGIL+S8fh1PqUiHgqjQ5smP/l8V3nptSuOWHM2KkK6QN2Hd7kc 3c6RMvh3ms4BfYNYdia03funs8BbqfM8//89XG/XmufbTEg/o5O109Wqd45XjaXT3U9qx/W+m upzsqJ7v8VHz0ZM7Su/ue/SKi+kWXvLo9GN6mNEYsGh50MOyI+u6cno/hSixFGckGmoxFxUnA gB0e81SpAIAAA== X-Env-Sender: prvs=143a4c3ea=anthony.perard@citrix.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1481211353!71811006!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32105 invoked from network); 8 Dec 2016 15:35:55 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-7.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 8 Dec 2016 15:35:55 -0000 X-IronPort-AV: E=Sophos;i="5.33,320,1477958400"; d="scan'208";a="402564141" From: Anthony PERARD To: , Date: Thu, 8 Dec 2016 15:33:32 +0000 Message-ID: <20161208153340.2285-7-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 06/14] OvmfPkg/XenPlatformPei: Add xen PVH specific code 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 - learn about memory size from the E820 - ignore error if host bridge devid is 0xffff, PVH does not have PCI and reading from unexisting device return -1. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Anthony PERARD --- OvmfPkg/XenPlatformPei/MemDetect.c | 71 ++++++++++++++++++++++++++++++++++++++ OvmfPkg/XenPlatformPei/Platform.c | 5 +++ OvmfPkg/XenPlatformPei/Platform.h | 10 ++++++ 3 files changed, 86 insertions(+) diff --git a/OvmfPkg/XenPlatformPei/MemDetect.c b/OvmfPkg/XenPlatformPei/MemDetect.c index 4ecdf5e..0d80775 100644 --- a/OvmfPkg/XenPlatformPei/MemDetect.c +++ b/OvmfPkg/XenPlatformPei/MemDetect.c @@ -42,6 +42,70 @@ UINT8 mPhysMemAddressWidth; STATIC UINT32 mS3AcpiReservedMemoryBase; STATIC UINT32 mS3AcpiReservedMemorySize; +STATIC UINT32 mXenLowerMemorySize = 0; +STATIC UINT64 mXenHighMemorySize = 0; + +VOID +XenReadMemorySizes ( + VOID + ) +{ + EFI_E820_ENTRY64 *E820Map; + UINT32 E820EntriesCount; + EFI_STATUS Status; + + Status = XenGetE820Map (&E820Map, &E820EntriesCount); + ASSERT_EFI_ERROR (Status); + + mXenLowerMemorySize = 0; + mXenHighMemorySize = 0; + + if (E820EntriesCount > 0) { + EFI_E820_ENTRY64 *Entry; + UINT32 Loop; + + for (Loop = 0; Loop < E820EntriesCount; Loop++) { + Entry = E820Map + Loop; + + // + // Only care about RAM + // + if (Entry->Type != EfiAcpiAddressRangeMemory) { + continue; + } + + if ((Entry->BaseAddr + Entry->Length) <= SIZE_16MB) { + continue; + } + + if (Entry->BaseAddr < SIZE_16MB) { + UINT64 bottom = Entry->BaseAddr; + UINT64 size = Entry->Length; + size -= SIZE_16MB - bottom; + bottom = SIZE_16MB; + mXenLowerMemorySize += size; + continue; + } + if (Entry->BaseAddr <= SIZE_4GB) { + UINT64 size = Entry->Length; + mXenLowerMemorySize += size; + continue; + } + + if (Entry->BaseAddr == SIZE_4GB) { + mXenHighMemorySize = Entry->Length; + continue; + } + + DEBUG ((EFI_D_INFO, "%a: ignored XenE820 entry (0x%llx, 0x%llx)\n", + __FUNCTION__, + Entry->BaseAddr, + Entry->Length)); + } + mXenLowerMemorySize += SIZE_16MB; + } +} + UINT32 GetSystemMemorySizeBelow4gb ( VOID @@ -50,6 +114,9 @@ GetSystemMemorySizeBelow4gb ( UINT8 Cmos0x34; UINT8 Cmos0x35; + if (mXen && mXenLowerMemorySize) + return mXenLowerMemorySize; + // // CMOS 0x34/0x35 specifies the system memory above 16 MB. // * CMOS(0x35) is the high byte @@ -74,6 +141,10 @@ GetSystemMemorySizeAbove4gb ( UINT32 Size; UINTN CmosIndex; + // if lower memory is specified that way, return also high memory + if (mXen && mXenLowerMemorySize) + return mXenHighMemorySize; + // // CMOS 0x5b-0x5d specifies the system memory above 4GB MB. // * CMOS(0x5d) is the most significant size byte diff --git a/OvmfPkg/XenPlatformPei/Platform.c b/OvmfPkg/XenPlatformPei/Platform.c index bf78878..9fc713c 100644 --- a/OvmfPkg/XenPlatformPei/Platform.c +++ b/OvmfPkg/XenPlatformPei/Platform.c @@ -362,6 +362,10 @@ MiscInitialization ( AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL); AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN; break; + case 0xffff: + // xen PVH, ignore + PcdStatus = PcdSet16S (PcdOvmfHostBridgePciDevId, mHostBridgeDevId); + return; default: DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n", __FUNCTION__, mHostBridgeDevId)); @@ -503,6 +507,7 @@ InitializeXenPlatform ( DebugDumpCmos (); XenDetect (); + XenReadMemorySizes (); BootModeInitialization (); AddressWidthInitialization (); diff --git a/OvmfPkg/XenPlatformPei/Platform.h b/OvmfPkg/XenPlatformPei/Platform.h index eda765b..2948853 100644 --- a/OvmfPkg/XenPlatformPei/Platform.h +++ b/OvmfPkg/XenPlatformPei/Platform.h @@ -101,4 +101,14 @@ extern BOOLEAN mS3Supported; extern UINT8 mPhysMemAddressWidth; +EFI_STATUS +XenGetE820Map ( + EFI_E820_ENTRY64 **Entries, + UINT32 *Count + ); +VOID +XenReadMemorySizes ( + VOID + ); + #endif // _PLATFORM_PEI_H_INCLUDED_