public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ma, Maurice" <maurice.ma@intel.com>
To: "Dong, Guo" <guo.dong@intel.com>
Cc: "Agyeman, Prince" <prince.agyeman@intel.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Subject: Re: [PATCH] CorebootModulePkg: Fix memmap issue
Date: Thu, 27 Oct 2016 00:10:03 +0000	[thread overview]
Message-ID: <7AAC936950815649B5F88FAE785306C284176A6A@ORSMSX113.amr.corp.intel.com> (raw)
In-Reply-To: <d7daac23297b7a15d04df22f5ff080aa43de24ca.1476817636.git.guo.dong@intel.com>

Reviewed-by: Maurice Ma <maurice.ma@intel.com>

-----Original Message-----
From: Dong, Guo 
Sent: Tuesday, October 18, 2016 12:11 PM
To: edk2-devel@lists.01.org
Cc: Ma, Maurice; Agyeman, Prince; Dong, Guo
Subject: [edk2] [PATCH] CorebootModulePkg: Fix memmap issue

Some reserved memory (e.g. CSE reserved memory) might be in the middle of usable physical memory. The current memory map caculation could not handle this case. This patch fixed this issue.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: gdong1 <guo.dong@intel.com>
---
 CorebootModulePkg/CbSupportPei/CbSupportPei.c     | 126 ++++++++++++++--------
 CorebootModulePkg/CbSupportPei/CbSupportPei.h     |   8 +-
 CorebootModulePkg/Include/Library/CbParseLib.h    |  13 ++-
 CorebootModulePkg/Library/CbParseLib/CbParseLib.c |  27 +----
 4 files changed, 100 insertions(+), 74 deletions(-)

diff --git a/CorebootModulePkg/CbSupportPei/CbSupportPei.c b/CorebootModulePkg/CbSupportPei/CbSupportPei.c
index 366682b..004d1e9 100755
--- a/CorebootModulePkg/CbSupportPei/CbSupportPei.c
+++ b/CorebootModulePkg/CbSupportPei/CbSupportPei.c
@@ -141,6 +141,72 @@ CbPeiReportRemainedFvs (  }
 
 /**
+  Based on memory base, size and type, build resource descripter HOB.
+
+  @param  Base    Memory base address.
+  @param  Size    Memory size.
+  @param  Type    Memory type.
+  @param  Param   A pointer to CB_MEM_INFO.
+
+  @retval EFI_SUCCESS if it completed successfully.
+**/
+EFI_STATUS
+CbMemInfoCallback (
+  UINT64                  Base,
+  UINT64                  Size,
+  UINT32                  Type,
+  VOID                    *Param
+  )
+{
+  CB_MEM_INFO             *MemInfo;
+  UINTN                   Attribue;
+
+  Attribue = EFI_RESOURCE_ATTRIBUTE_PRESENT |
+             EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
+             EFI_RESOURCE_ATTRIBUTE_TESTED |
+             EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
+             EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
+             EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
+             EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE;
+
+  MemInfo = (CB_MEM_INFO *)Param;
+  if (Base >= 0x100000) {
+    if (Type == CB_MEM_RAM) {
+      if (Base < 0x100000000ULL) {
+        MemInfo->UsableLowMemTop = (UINT32)(Base + Size);
+      } else {
+        Attribue &= ~EFI_RESOURCE_ATTRIBUTE_TESTED;
+      }
+      BuildResourceDescriptorHob (
+        EFI_RESOURCE_SYSTEM_MEMORY,
+        Attribue,
+        (EFI_PHYSICAL_ADDRESS)Base,
+        Size
+        );
+    } else if (Type == CB_MEM_TABLE) {
+      BuildResourceDescriptorHob (
+        EFI_RESOURCE_MEMORY_RESERVED,
+        Attribue,
+        (EFI_PHYSICAL_ADDRESS)Base,
+        Size
+        );
+      MemInfo->SystemLowMemTop = ((UINT32)(Base + Size) + 0x0FFFFFFF) & 0xF0000000;
+    } else if (Type == CB_MEM_RESERVED) {
+      if ((MemInfo->SystemLowMemTop == 0) || (Base < MemInfo->SystemLowMemTop)) {
+        BuildResourceDescriptorHob (
+          EFI_RESOURCE_MEMORY_RESERVED,
+          Attribue,
+          (EFI_PHYSICAL_ADDRESS)Base,
+          Size
+          ); 
+      }
+    }
+  }
+  
+  return EFI_SUCCESS;
+}
+
+/**
   This is the entrypoint of PEIM
 
   @param  FileHandle  Handle of the file being invoked.
@@ -155,9 +221,9 @@ CbPeiEntryPoint (
   IN CONST EFI_PEI_SERVICES     **PeiServices
   )
 {
-  EFI_STATUS Status;
-  UINT64 LowMemorySize, HighMemorySize;
-  UINT64 PeiMemSize = SIZE_64MB;   // 64 MB
+  EFI_STATUS           Status;
+  UINT64               LowMemorySize;
+  UINT64               PeiMemSize = SIZE_64MB;   // 64 MB
   EFI_PHYSICAL_ADDRESS PeiMemBase = 0;
   UINT32               RegEax;
   UINT8                PhysicalAddressBits;
@@ -173,23 +239,12 @@ CbPeiEntryPoint (
   UINTN                PmCtrlRegBase, PmTimerRegBase, ResetRegAddress, ResetValue;
   UINTN                PmEvtBase;
   UINTN                PmGpeEnBase;
-
-  LowMemorySize = 0;
-  HighMemorySize = 0;
-
-  Status = CbParseMemoryInfo (&LowMemorySize, &HighMemorySize);
-  if (EFI_ERROR(Status))
-    return Status;
-
-  DEBUG((EFI_D_ERROR, "LowMemorySize: 0x%lx.\n", LowMemorySize));
-  DEBUG((EFI_D_ERROR, "HighMemorySize: 0x%lx.\n", HighMemorySize));
-
-  ASSERT (LowMemorySize > 0);
+  CB_MEM_INFO          CbMemInfo;
 
   //
   // Report lower 640KB of RAM. Attribute EFI_RESOURCE_ATTRIBUTE_TESTED
- // is intentionally omitted to prevent erasing of the coreboot header
- // record before it is processed by CbParseMemoryInfo.
+  // is intentionally omitted to prevent erasing of the coreboot header  
+ // record before it is processed by CbParseMemoryInfo.
   //
   BuildResourceDescriptorHob (
     EFI_RESOURCE_SYSTEM_MEMORY,
@@ -221,37 +276,16 @@ CbPeiEntryPoint (
     (UINT64)(0x60000)
     );
 
-   BuildResourceDescriptorHob (
-    EFI_RESOURCE_SYSTEM_MEMORY,
-    (
-       EFI_RESOURCE_ATTRIBUTE_PRESENT |
-       EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
-       EFI_RESOURCE_ATTRIBUTE_TESTED |
-       EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
-       EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
-       EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
-       EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
-    ),
-    (EFI_PHYSICAL_ADDRESS)(0x100000),
-    (UINT64) (LowMemorySize - 0x100000)
-    );
-
-  if (HighMemorySize > 0) {
-    BuildResourceDescriptorHob (
-    EFI_RESOURCE_SYSTEM_MEMORY,
-    (
-       EFI_RESOURCE_ATTRIBUTE_PRESENT |
-       EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
-       EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
-       EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
-       EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
-       EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
-    ),
-    (EFI_PHYSICAL_ADDRESS)(0x100000000ULL),
-    HighMemorySize
-    );
+  ZeroMem (&CbMemInfo, sizeof(CbMemInfo));  Status = CbParseMemoryInfo 
+ (CbMemInfoCallback, (VOID *)&CbMemInfo);  if (EFI_ERROR(Status)) {
+    return Status;
   }
 
+  LowMemorySize = CbMemInfo.UsableLowMemTop;  DEBUG ((EFI_D_INFO, "Low 
+ memory 0x%lx\n", LowMemorySize));  DEBUG ((EFI_D_INFO, 
+ "SystemLowMemTop 0x%x\n", CbMemInfo.SystemLowMemTop));
+
   //
   // Should be 64k aligned
   //
diff --git a/CorebootModulePkg/CbSupportPei/CbSupportPei.h b/CorebootModulePkg/CbSupportPei/CbSupportPei.h
index 3c9a3fe..d3166aa 100644
--- a/CorebootModulePkg/CbSupportPei/CbSupportPei.h
+++ b/CorebootModulePkg/CbSupportPei/CbSupportPei.h
@@ -1,7 +1,7 @@
 /** @file
   The header file of Coreboot Support PEIM.
 
-Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials  are licensed and made available under the terms and conditions of the BSD License  which accompanies this distribution.  The full text of the license may be found at @@ -37,5 +37,11 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <Guid/AcpiBoardInfoGuid.h>
 
 #include <Ppi/MasterBootMode.h>
+#include "Coreboot.h"
+
+typedef struct {
+  UINT32  UsableLowMemTop;
+  UINT32  SystemLowMemTop;
+} CB_MEM_INFO;
 
 #endif
diff --git a/CorebootModulePkg/Include/Library/CbParseLib.h b/CorebootModulePkg/Include/Library/CbParseLib.h
index a023246..7304715 100644
--- a/CorebootModulePkg/Include/Library/CbParseLib.h
+++ b/CorebootModulePkg/Include/Library/CbParseLib.h
@@ -14,22 +14,25 @@
 **/
 #include <Guid/FrameBufferInfoGuid.h>
 
+typedef RETURN_STATUS \
+        (*CB_MEM_INFO_CALLBACK) (UINT64 Base, UINT64 Size, UINT32 Type, 
+VOID *Param);
+
 /**
   Acquire the memory information from the coreboot table in memory.
 
-  @param  pLowMemorySize     Pointer to the variable of low memory size
-  @param  pHighMemorySize    Pointer to the variable of high memory size
+  @param  MemInfoCallback     The callback routine
+  @param  pParam              Pointer to the callback routine parameter
 
   @retval RETURN_SUCCESS     Successfully find out the memory information.
-  @retval RETURN_INVALID_PARAMETER    Invalid input parameters.
   @retval RETURN_NOT_FOUND   Failed to find the memory information.
 
 **/
 RETURN_STATUS
 CbParseMemoryInfo (
-  IN UINT64*    pLowMemorySize,
-  IN UINT64*    pHighMemorySize
+  IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
+  IN  VOID                  *pParam
   );
+
 
 /**
   Acquire the coreboot memory table with the given table id diff --git a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
index 7c81a51..a72d048 100644
--- a/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
+++ b/CorebootModulePkg/Library/CbParseLib/CbParseLib.c
@@ -229,18 +229,17 @@ FindCbMemTable (
 /**
   Acquire the memory information from the coreboot table in memory.
 
-  @param  pLowMemorySize     Pointer to the variable of low memory size
-  @param  pHighMemorySize    Pointer to the variable of high memory size
+  @param  MemInfoCallback     The callback routine
+  @param  pParam              Pointer to the callback routine parameter
 
   @retval RETURN_SUCCESS     Successfully find out the memory information.
-  @retval RETURN_INVALID_PARAMETER    Invalid input parameters.
   @retval RETURN_NOT_FOUND   Failed to find the memory information.
 
 **/
 RETURN_STATUS
 CbParseMemoryInfo (
-  OUT UINT64     *pLowMemorySize,
-  OUT UINT64     *pHighMemorySize
+  IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,
+  IN  VOID                  *pParam
   )
 {
   struct cb_memory         *rec;
@@ -249,9 +248,6 @@ CbParseMemoryInfo (
   UINT64                   Size;
   UINTN                    Index;
 
-  if ((pLowMemorySize == NULL) || (pHighMemorySize == NULL)) {
-    return RETURN_INVALID_PARAMETER;
-  }
 
   //
   // Get the coreboot memory table
@@ -265,9 +261,6 @@ CbParseMemoryInfo (
     return RETURN_NOT_FOUND;
   }
 
-  *pLowMemorySize = 0;
-  *pHighMemorySize = 0;
-
   for (Index = 0; Index < MEM_RANGE_COUNT(rec); Index++) {
     Range = MEM_RANGE_PTR(rec, Index);
     Start = cb_unpack64(Range->start);
@@ -275,18 +268,8 @@ CbParseMemoryInfo (
     DEBUG ((EFI_D_INFO, "%d. %016lx - %016lx [%02x]\n",
             Index, Start, Start + Size - 1, Range->type));
 
-    if (Range->type != CB_MEM_RAM) {
-      continue;
-    }
-
-    if (Start + Size < 0x100000000ULL) {
-      *pLowMemorySize = Start + Size;
-    } else {
-      *pHighMemorySize = Start + Size - 0x100000000ULL;
+    MemInfoCallback (Start, Size, Range->type, pParam);
     }
-  }
-
-  DEBUG ((EFI_D_INFO, "Low memory 0x%lx, High Memory 0x%lx\n", *pLowMemorySize, *pHighMemorySize));
 
   return RETURN_SUCCESS;
 }
--
2.7.0.windows.1



           reply	other threads:[~2016-10-27  0:10 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <d7daac23297b7a15d04df22f5ff080aa43de24ca.1476817636.git.guo.dong@intel.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7AAC936950815649B5F88FAE785306C284176A6A@ORSMSX113.amr.corp.intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox