]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CorebootModulePkg/Library/CbParseLib/CbParseLib.c
CorebootModulePkg: Fix memmap issue
[mirror_edk2.git] / CorebootModulePkg / Library / CbParseLib / CbParseLib.c
index 7c81a51054298c213ccb981e9547c78d406b2da5..305e38fa47473028be96692a7de1d1ba2f322629 100644 (file)
@@ -2,7 +2,7 @@
   This library will parse the coreboot table in memory and extract those required\r
   information.\r
 \r
-  Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2016, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -33,7 +33,7 @@
   @return          the UNIT64 value after convertion.\r
 \r
 **/\r
-UINT64
+UINT64\r
 cb_unpack64 (\r
   IN struct cbuint64 val\r
   )\r
@@ -216,8 +216,8 @@ FindCbMemTable (
         *pMemTableSize = Entries[Idx].size;\r
       }\r
 \r
-      DEBUG ((EFI_D_INFO, "Find CbMemTable Id 0x%x, base %p, size 0x%x\n",
-        TableId, *pMemTable, Entries[Idx].size));
+      DEBUG ((EFI_D_INFO, "Find CbMemTable Id 0x%x, base %p, size 0x%x\n",\r
+        TableId, *pMemTable, Entries[Idx].size));\r
       return RETURN_SUCCESS;\r
     }\r
   }\r
@@ -229,18 +229,17 @@ FindCbMemTable (
 /**\r
   Acquire the memory information from the coreboot table in memory.\r
 \r
-  @param  pLowMemorySize     Pointer to the variable of low memory size\r
-  @param  pHighMemorySize    Pointer to the variable of high memory size\r
+  @param  MemInfoCallback     The callback routine\r
+  @param  pParam              Pointer to the callback routine parameter\r
 \r
   @retval RETURN_SUCCESS     Successfully find out the memory information.\r
-  @retval RETURN_INVALID_PARAMETER    Invalid input parameters.\r
   @retval RETURN_NOT_FOUND   Failed to find the memory information.\r
 \r
 **/\r
 RETURN_STATUS\r
 CbParseMemoryInfo (\r
-  OUT UINT64     *pLowMemorySize,\r
-  OUT UINT64     *pHighMemorySize\r
+  IN  CB_MEM_INFO_CALLBACK  MemInfoCallback,\r
+  IN  VOID                  *pParam\r
   )\r
 {\r
   struct cb_memory         *rec;\r
@@ -249,10 +248,6 @@ CbParseMemoryInfo (
   UINT64                   Size;\r
   UINTN                    Index;\r
 \r
-  if ((pLowMemorySize == NULL) || (pHighMemorySize == NULL)) {\r
-    return RETURN_INVALID_PARAMETER;\r
-  }\r
-\r
   //\r
   // Get the coreboot memory table\r
   //\r
@@ -265,9 +260,6 @@ CbParseMemoryInfo (
     return RETURN_NOT_FOUND;\r
   }\r
 \r
-  *pLowMemorySize = 0;\r
-  *pHighMemorySize = 0;\r
-\r
   for (Index = 0; Index < MEM_RANGE_COUNT(rec); Index++) {\r
     Range = MEM_RANGE_PTR(rec, Index);\r
     Start = cb_unpack64(Range->start);\r
@@ -275,19 +267,9 @@ CbParseMemoryInfo (
     DEBUG ((EFI_D_INFO, "%d. %016lx - %016lx [%02x]\n",\r
             Index, Start, Start + Size - 1, Range->type));\r
 \r
-    if (Range->type != CB_MEM_RAM) {\r
-      continue;\r
-    }\r
-\r
-    if (Start + Size < 0x100000000ULL) {\r
-      *pLowMemorySize = Start + Size;\r
-    } else {\r
-      *pHighMemorySize = Start + Size - 0x100000000ULL;\r
-    }\r
+    MemInfoCallback (Start, Size, Range->type, pParam);\r
   }\r
 \r
-  DEBUG ((EFI_D_INFO, "Low memory 0x%lx, High Memory 0x%lx\n", *pLowMemorySize, *pHighMemorySize));\r
-\r
   return RETURN_SUCCESS;\r
 }\r
 \r
@@ -469,25 +451,25 @@ CbParseFadtInfo (
         }\r
         DEBUG ((EFI_D_INFO, "Reset Value 0x%x\n", Fadt->ResetValue));\r
 \r
-        if (pPmEvtReg != NULL) {
+        if (pPmEvtReg != NULL) {\r
           *pPmEvtReg = Fadt->Pm1aEvtBlk;\r
           DEBUG ((EFI_D_INFO, "PmEvt Reg 0x%x\n", Fadt->Pm1aEvtBlk));\r
         }\r
 \r
-        if (pPmGpeEnReg != NULL) {
+        if (pPmGpeEnReg != NULL) {\r
           *pPmGpeEnReg = Fadt->Gpe0Blk + Fadt->Gpe0BlkLen / 2;\r
           DEBUG ((EFI_D_INFO, "PmGpeEn Reg 0x%x\n", *pPmGpeEnReg));\r
         }\r
 \r
-        //
-        // Verify values for proper operation
-        //
-        ASSERT(Fadt->Pm1aCntBlk != 0);
-        ASSERT(Fadt->PmTmrBlk != 0);
-        ASSERT(Fadt->ResetReg.Address != 0);
-        ASSERT(Fadt->Pm1aEvtBlk != 0);
-        ASSERT(Fadt->Gpe0Blk != 0);
-
+        //\r
+        // Verify values for proper operation\r
+        //\r
+        ASSERT(Fadt->Pm1aCntBlk != 0);\r
+        ASSERT(Fadt->PmTmrBlk != 0);\r
+        ASSERT(Fadt->ResetReg.Address != 0);\r
+        ASSERT(Fadt->Pm1aEvtBlk != 0);\r
+        ASSERT(Fadt->Gpe0Blk != 0);\r
+\r
         return RETURN_SUCCESS;\r
       }\r
     }\r
@@ -519,15 +501,15 @@ CbParseFadtInfo (
           *pResetValue = Fadt->ResetValue;\r
         DEBUG ((EFI_D_ERROR, "Reset Value 0x%x\n", Fadt->ResetValue));\r
 \r
-        if (pPmEvtReg != NULL) {
+        if (pPmEvtReg != NULL) {\r
           *pPmEvtReg = Fadt->Pm1aEvtBlk;\r
            DEBUG ((EFI_D_INFO, "PmEvt Reg 0x%x\n", Fadt->Pm1aEvtBlk));\r
         }\r
 \r
-        if (pPmGpeEnReg != NULL) {
+        if (pPmGpeEnReg != NULL) {\r
           *pPmGpeEnReg = Fadt->Gpe0Blk + Fadt->Gpe0BlkLen / 2;\r
           DEBUG ((EFI_D_INFO, "PmGpeEn Reg 0x%x\n", *pPmGpeEnReg));\r
-        }
+        }\r
         return RETURN_SUCCESS;\r
       }\r
     }\r
@@ -541,10 +523,10 @@ CbParseFadtInfo (
 \r
   @param  pRegBase           Pointer to the base address of serial port registers\r
   @param  pRegAccessType     Pointer to the access type of serial port registers\r
-  @param  pRegWidth          Pointer to the register width in bytes
+  @param  pRegWidth          Pointer to the register width in bytes\r
   @param  pBaudrate          Pointer to the serial port baudrate\r
-  @param  pInputHertz        Pointer to the input clock frequency
-  @param  pUartPciAddr       Pointer to the UART PCI bus, dev and func address
+  @param  pInputHertz        Pointer to the input clock frequency\r
+  @param  pUartPciAddr       Pointer to the UART PCI bus, dev and func address\r
 \r
   @retval RETURN_SUCCESS     Successfully find the serial port information.\r
   @retval RETURN_NOT_FOUND   Failed to find the serial port information .\r
@@ -554,10 +536,10 @@ RETURN_STATUS
 CbParseSerialInfo (\r
   OUT UINT32      *pRegBase,\r
   OUT UINT32      *pRegAccessType,\r
-  OUT UINT32      *pRegWidth,
-  OUT UINT32      *pBaudrate,
-  OUT UINT32      *pInputHertz,
-  OUT UINT32      *pUartPciAddr
+  OUT UINT32      *pRegWidth,\r
+  OUT UINT32      *pBaudrate,\r
+  OUT UINT32      *pInputHertz,\r
+  OUT UINT32      *pUartPciAddr\r
   )\r
 {\r
   struct cb_serial    *CbSerial;\r
@@ -575,10 +557,10 @@ CbParseSerialInfo (
     *pRegBase = CbSerial->baseaddr;\r
   }\r
 \r
-  if (pRegWidth != NULL) {
-    *pRegWidth = CbSerial->regwidth;
-  }
-
+  if (pRegWidth != NULL) {\r
+    *pRegWidth = CbSerial->regwidth;\r
+  }\r
+\r
   if (pRegAccessType != NULL) {\r
     *pRegAccessType = CbSerial->type;\r
   }\r
@@ -587,14 +569,14 @@ CbParseSerialInfo (
     *pBaudrate = CbSerial->baud;\r
   }\r
 \r
-  if (pInputHertz != NULL) {
-    *pInputHertz = CbSerial->input_hertz;
-  }
-
-  if (pUartPciAddr != NULL) {
-    *pUartPciAddr = CbSerial->uart_pci_addr;
-  }
-
+  if (pInputHertz != NULL) {\r
+    *pInputHertz = CbSerial->input_hertz;\r
+  }\r
+\r
+  if (pUartPciAddr != NULL) {\r
+    *pUartPciAddr = CbSerial->uart_pci_addr;\r
+  }\r
+\r
   return RETURN_SUCCESS;\r
 }\r
 \r