Revision: 16958
          http://sourceforge.net/p/edk2/code/16958
Author:   lersek
Date:     2015-02-28 20:25:48 +0000 (Sat, 28 Feb 2015)
Log Message:
-----------
ArmVirtualizationPkg: move early UART discovery to PlatformPeim

This is partially motivated by the desire to use PrePi in a virt
environment, and in that configuration, ArmPlatformInitializeSystemMemory()
is never called. But actually, this is a more suitable place anyway.

Contributed-under: TianoCore Contribution Agreement 1.0
Reviewed-by: Laszlo Ersek <[email protected]>
Reviewed-by: Olivier Martin <[email protected]>
Signed-off-by: Ard Biesheuvel <[email protected]>
Signed-off-by: Laszlo Ersek <[email protected]>

Modified Paths:
--------------
    
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf
    
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c
    
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c
    
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf

Modified: 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf
===================================================================
--- 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf
        2015-02-28 20:25:38 UTC (rev 16957)
+++ 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/ArmVirtualizationPlatformLib.inf
        2015-02-28 20:25:48 UTC (rev 16958)
@@ -62,6 +62,3 @@
   gArmTokenSpaceGuid.PcdArmPrimaryCore
   gArmTokenSpaceGuid.PcdFdBaseAddress
   gArmTokenSpaceGuid.PcdFdSize
-
-[Guids]
-  gEarlyPL011BaseAddressGuid

Modified: 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c
===================================================================
--- 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c
  2015-02-28 20:25:38 UTC (rev 16957)
+++ 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/ArmVirtualizationPlatformLib/Virt.c
  2015-02-28 20:25:48 UTC (rev 16958)
@@ -24,9 +24,6 @@
 #include <Pi/PiBootMode.h>
 #include <Uefi/UefiBaseType.h>
 #include <Uefi/UefiMultiPhase.h>
-#include <Pi/PiHob.h>
-#include <Library/HobLib.h>
-#include <Guid/EarlyPL011BaseAddress.h>
 
 /**
   Return the current Boot Mode
@@ -77,25 +74,13 @@
   INT32        Node, Prev;
   UINT64       NewBase;
   UINT64       NewSize;
-  BOOLEAN      HaveMemory, HaveUART;
-  UINT64       *HobData;
   CONST CHAR8  *Type;
-  CONST CHAR8  *Compatible;
-  CONST CHAR8  *CompItem;
   INT32        Len;
   CONST UINT64 *RegProp;
-  UINT64       UartBase;
 
   NewBase = 0;
   NewSize = 0;
 
-  HaveMemory = FALSE;
-  HaveUART   = FALSE;
-
-  HobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof *HobData);
-  ASSERT (HobData != NULL);
-  *HobData = 0;
-
   DeviceTreeBase = (VOID *)(UINTN)PcdGet64 (PcdDeviceTreeInitialBaseAddress);
   ASSERT (DeviceTreeBase != NULL);
 
@@ -107,7 +92,7 @@
   //
   // Look for a memory node
   //
-  for (Prev = 0; !(HaveMemory && HaveUART); Prev = Node) {
+  for (Prev = 0;; Prev = Node) {
     Node = fdt_next_node (DeviceTreeBase, Prev, NULL);
     if (Node < 0) {
       break;
@@ -140,35 +125,8 @@
         DEBUG ((EFI_D_ERROR, "%a: Failed to parse FDT memory node\n",
                __FUNCTION__));
       }
-      HaveMemory = TRUE;
-      continue;
+      break;
     }
-
-    //
-    // Check for UART node
-    //
-    Compatible = fdt_getprop (DeviceTreeBase, Node, "compatible", &Len);
-
-    //
-    // Iterate over the NULL-separated items in the compatible string
-    //
-    for (CompItem = Compatible; CompItem != NULL && CompItem < Compatible + 
Len;
-      CompItem += 1 + AsciiStrLen (CompItem)) {
-
-      if (AsciiStrCmp (CompItem, "arm,pl011") == 0) {
-        RegProp = fdt_getprop (DeviceTreeBase, Node, "reg", &Len);
-        ASSERT (Len == 16);
-
-        UartBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));
-
-        DEBUG ((EFI_D_INFO, "%a: PL011 UART @ 0x%lx\n", __FUNCTION__, 
UartBase));
-
-        *HobData = UartBase;
-
-        HaveUART = TRUE;
-        continue;
-      }
-    }
   }
 
   //

Modified: 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c
===================================================================
--- 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c
      2015-02-28 20:25:38 UTC (rev 16957)
+++ 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.c
      2015-02-28 20:25:48 UTC (rev 16958)
@@ -21,6 +21,8 @@
 #include <Library/PcdLib.h>
 #include <libfdt.h>
 
+#include <Guid/EarlyPL011BaseAddress.h>
+
 EFI_STATUS
 EFIAPI
 PlatformPeim (
@@ -30,7 +32,15 @@
   VOID               *Base;
   VOID               *NewBase;
   UINTN              FdtSize;
+  UINT64             *UartHobData;
+  INT32              Node, Prev;
+  CONST CHAR8        *Compatible;
+  CONST CHAR8        *CompItem;
+  INT32              Len;
+  CONST UINT64       *RegProp;
+  UINT64             UartBase;
 
+
   Base = (VOID*)(UINTN)FixedPcdGet64 (PcdDeviceTreeInitialBaseAddress);
   ASSERT (fdt_check_header (Base) == 0);
 
@@ -41,6 +51,44 @@
   CopyMem (NewBase, Base, FdtSize);
   PcdSet64 (PcdDeviceTreeBaseAddress, (UINT64)(UINTN)NewBase);
 
+  UartHobData = BuildGuidHob (&gEarlyPL011BaseAddressGuid, sizeof 
*UartHobData);
+  ASSERT (UartHobData != NULL);
+  *UartHobData = 0;
+
+  //
+  // Look for a UART node
+  //
+  for (Prev = 0;; Prev = Node) {
+    Node = fdt_next_node (Base, Prev, NULL);
+    if (Node < 0) {
+      break;
+    }
+
+    //
+    // Check for UART node
+    //
+    Compatible = fdt_getprop (Base, Node, "compatible", &Len);
+
+    //
+    // Iterate over the NULL-separated items in the compatible string
+    //
+    for (CompItem = Compatible; CompItem != NULL && CompItem < Compatible + 
Len;
+      CompItem += 1 + AsciiStrLen (CompItem)) {
+
+      if (AsciiStrCmp (CompItem, "arm,pl011") == 0) {
+        RegProp = fdt_getprop (Base, Node, "reg", &Len);
+        ASSERT (Len == 16);
+
+        UartBase = fdt64_to_cpu (ReadUnaligned64 (RegProp));
+
+        DEBUG ((EFI_D_INFO, "%a: PL011 UART @ 0x%lx\n", __FUNCTION__, 
UartBase));
+
+        *UartHobData = UartBase;
+        break;
+      }
+    }
+  }
+
   BuildFvHob (PcdGet64 (PcdFvBaseAddress), PcdGet32 (PcdFvSize));
 
   return EFI_SUCCESS;

Modified: 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
===================================================================
--- 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
    2015-02-28 20:25:38 UTC (rev 16957)
+++ 
trunk/edk2/ArmPlatformPkg/ArmVirtualizationPkg/Library/PlatformPeiLib/PlatformPeiLib.inf
    2015-02-28 20:25:48 UTC (rev 16958)
@@ -44,5 +44,8 @@
 [Pcd]
   gArmVirtualizationTokenSpaceGuid.PcdDeviceTreeBaseAddress
 
+[Guids]
+  gEarlyPL011BaseAddressGuid
+
 [Depex]
   gEfiPeiMemoryDiscoveredPpiGuid


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to