]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmVirtPkg/FdtClientDxe/FdtClientDxe.c
MdeModulePkg/BmpSupportLib: Refine type cast for pointer subtraction
[mirror_edk2.git] / ArmVirtPkg / FdtClientDxe / FdtClientDxe.c
index 4cf79f70cb2ae857797fb0452c8bd7427078b231..fb6e0aeb9215e122ece6f8074715c7ad7a0aae2f 100644 (file)
@@ -20,9 +20,9 @@
 #include <Library/HobLib.h>\r
 #include <libfdt.h>\r
 \r
-#include <Guid/EventGroup.h>\r
 #include <Guid/Fdt.h>\r
 #include <Guid/FdtHob.h>\r
+#include <Guid/PlatformHasDeviceTree.h>\r
 \r
 #include <Protocol/FdtClient.h>\r
 \r
@@ -210,6 +210,7 @@ FindNextMemoryNodeReg (
 {\r
   INT32          Prev, Next;\r
   CONST CHAR8    *DeviceType;\r
+  CONST CHAR8    *NodeStatus;\r
   INT32          Len;\r
   EFI_STATUS     Status;\r
 \r
@@ -222,6 +223,13 @@ FindNextMemoryNodeReg (
       break;\r
     }\r
 \r
+    NodeStatus = fdt_getprop (mDeviceTreeBase, Next, "status", &Len);\r
+    if (NodeStatus != NULL && AsciiStrCmp (NodeStatus, "okay") != 0) {\r
+      DEBUG ((DEBUG_WARN, "%a: ignoring memory node with status \"%a\"\n",\r
+        __FUNCTION__, NodeStatus));\r
+      continue;\r
+    }\r
+\r
     DeviceType = fdt_getprop (mDeviceTreeBase, Next, "device_type", &Len);\r
     if (DeviceType != NULL && AsciiStrCmp (DeviceType, "memory") == 0) {\r
       //\r
@@ -310,27 +318,37 @@ STATIC FDT_CLIENT_PROTOCOL mFdtClientProtocol = {
 STATIC\r
 VOID\r
 EFIAPI\r
-OnReadyToBoot (\r
-  EFI_EVENT       Event,\r
-  VOID            *Context\r
+OnPlatformHasDeviceTree (\r
+  IN EFI_EVENT Event,\r
+  IN VOID      *Context\r
   )\r
 {\r
-  EFI_STATUS      Status;\r
+  EFI_STATUS Status;\r
+  VOID       *Interface;\r
+  VOID       *DeviceTreeBase;\r
 \r
-  if (!FeaturePcdGet (PcdPureAcpiBoot)) {\r
-    //\r
-    // Only install the FDT as a configuration table if we want to leave it up\r
-    // to the OS to decide whether it prefers ACPI over DT.\r
-    //\r
-    Status = gBS->InstallConfigurationTable (&gFdtTableGuid, mDeviceTreeBase);\r
-    ASSERT_EFI_ERROR (Status);\r
+  Status = gBS->LocateProtocol (\r
+                  &gEdkiiPlatformHasDeviceTreeGuid,\r
+                  NULL,                             // Registration\r
+                  &Interface\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
   }\r
 \r
+  DeviceTreeBase = Context;\r
+  DEBUG ((\r
+    DEBUG_INFO,\r
+    "%a: exposing DTB @ 0x%p to OS\n",\r
+    __FUNCTION__,\r
+    DeviceTreeBase\r
+    ));\r
+  Status = gBS->InstallConfigurationTable (&gFdtTableGuid, DeviceTreeBase);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
   gBS->CloseEvent (Event);\r
 }\r
 \r
-STATIC EFI_EVENT         mReadyToBootEvent;\r
-\r
 EFI_STATUS\r
 EFIAPI\r
 InitializeFdtClientDxe (\r
@@ -341,6 +359,8 @@ InitializeFdtClientDxe (
   VOID              *Hob;\r
   VOID              *DeviceTreeBase;\r
   EFI_STATUS        Status;\r
+  EFI_EVENT         PlatformHasDeviceTreeEvent;\r
+  VOID              *Registration;\r
 \r
   Hob = GetFirstGuidHob (&gFdtHobGuid);\r
   if (Hob == NULL || GET_GUID_HOB_DATA_SIZE (Hob) != sizeof (UINT64)) {\r
@@ -358,21 +378,65 @@ InitializeFdtClientDxe (
 \r
   DEBUG ((EFI_D_INFO, "%a: DTB @ 0x%p\n", __FUNCTION__, mDeviceTreeBase));\r
 \r
-  Status = gBS->InstallProtocolInterface (&ImageHandle, &gFdtClientProtocolGuid,\r
-                  EFI_NATIVE_INTERFACE, &mFdtClientProtocol);\r
+  //\r
+  // Register a protocol notify for the EDKII Platform Has Device Tree\r
+  // Protocol.\r
+  //\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_SIGNAL,\r
+                  TPL_CALLBACK,\r
+                  OnPlatformHasDeviceTree,\r
+                  DeviceTreeBase,             // Context\r
+                  &PlatformHasDeviceTreeEvent\r
+                  );\r
   if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "%a: CreateEvent(): %r\n", __FUNCTION__, Status));\r
     return Status;\r
   }\r
 \r
-  Status = gBS->CreateEventEx (\r
-                  EVT_NOTIFY_SIGNAL,\r
-                  TPL_CALLBACK,\r
-                  OnReadyToBoot,\r
-                  NULL,\r
-                  &gEfiEventReadyToBootGuid,\r
-                  &mReadyToBootEvent\r
+  Status = gBS->RegisterProtocolNotify (\r
+                  &gEdkiiPlatformHasDeviceTreeGuid,\r
+                  PlatformHasDeviceTreeEvent,\r
+                  &Registration\r
                   );\r
-  ASSERT_EFI_ERROR (Status);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "%a: RegisterProtocolNotify(): %r\n",\r
+      __FUNCTION__,\r
+      Status\r
+      ));\r
+    goto CloseEvent;\r
+  }\r
 \r
-  return EFI_SUCCESS;\r
+  //\r
+  // Kick the event; the protocol could be available already.\r
+  //\r
+  Status = gBS->SignalEvent (PlatformHasDeviceTreeEvent);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "%a: SignalEvent(): %r\n", __FUNCTION__, Status));\r
+    goto CloseEvent;\r
+  }\r
+\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &ImageHandle,\r
+                  &gFdtClientProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mFdtClientProtocol\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((\r
+      DEBUG_ERROR,\r
+      "%a: InstallProtocolInterface(): %r\n",\r
+      __FUNCTION__,\r
+      Status\r
+      ));\r
+    goto CloseEvent;\r
+  }\r
+\r
+  return Status;\r
+\r
+CloseEvent:\r
+  gBS->CloseEvent (PlatformHasDeviceTreeEvent);\r
+  return Status;\r
 }\r