]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Nt32Pkg/WinNtFirmwareVolumePei/WinntFwh.c
Porting WinNtFwhPei and WinNtFlashMapPei to produce FvHob.
[mirror_edk2.git] / Nt32Pkg / WinNtFirmwareVolumePei / WinntFwh.c
diff --git a/Nt32Pkg/WinNtFirmwareVolumePei/WinntFwh.c b/Nt32Pkg/WinNtFirmwareVolumePei/WinntFwh.c
new file mode 100644 (file)
index 0000000..2431133
--- /dev/null
@@ -0,0 +1,138 @@
+/*++\r
+\r
+Copyright (c) 2006, Intel Corporation                                                         \r
+All rights reserved. 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
+http://opensource.org/licenses/bsd-license.php                                            \r
+                                                                                          \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+\r
+Module Name:\r
+  WinNtFwh.c\r
+    \r
+Abstract:\r
+  PEIM to abstract construction of firmware volume in a Windows NT environment.\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+#include <WinNtPeim.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Ppi/NtFwh.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/HobLib.h>\r
+\r
+#include <FlashLayout.h>\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeWinNtFwh (\r
+  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
+  IN EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Perform a call-back into the SEC simulator to get address of the Firmware Hub\r
+\r
+Arguments:\r
+  FfsHeader   - Ffs Header availible to every PEIM\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_PEI_PPI_DESCRIPTOR      *PpiDescriptor;\r
+  NT_FWH_PPI                  *FwhPpi;\r
+  EFI_PHYSICAL_ADDRESS        FdBase;\r
+  EFI_FIRMWARE_VOLUME_HEADER  *FvHeader;\r
+  UINT64                      FdSize;\r
+  UINTN                       Index;\r
+\r
+  DEBUG ((EFI_D_ERROR, "NT 32 Firmware Volume PEIM Loaded\n"));\r
+\r
+  //\r
+  // Get the Fwh Information PPI\r
+  //\r
+  Status = (**PeiServices).LocatePpi (\r
+                            PeiServices,\r
+                            &gNtFwhPpiGuid, // GUID\r
+                            0,              // INSTANCE\r
+                            &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
+                            &FwhPpi         // PPI\r
+                            );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Index = 0;\r
+  do {\r
+    //\r
+    // Get information about all the FD's in the system\r
+    //\r
+    Status = FwhPpi->NtFwh (Index, &FdBase, &FdSize);\r
+    if (!EFI_ERROR (Status)) {\r
+      //\r
+      // Assume the FD starts with an FV header\r
+      //\r
+      FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;\r
+\r
+      //\r
+      // Make an FV Hob for the first FV in the FD\r
+      //\r
+      BuildFvHob (FdBase, FvHeader->FvLength);\r
+\r
+      if (Index == 0) {\r
+        //\r
+        // Assume the first FD was produced by the NT32.DSC\r
+        //  All these strange offests are needed to keep in\r
+        //  sync with the FlashMap and NT32.dsc file\r
+        //\r
+        BuildResourceDescriptorHob (\r
+          EFI_RESOURCE_FIRMWARE_DEVICE,\r
+          (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),\r
+          FdBase,\r
+          (FvHeader->FvLength + EFI_WINNT_RUNTIME_UPDATABLE_LENGTH + EFI_WINNT_FTW_SPARE_BLOCK_LENGTH)\r
+          );\r
+\r
+        //\r
+        // Hard code the address of the spare block and variable services.\r
+        //  Assume it's a hard coded offset from FV0 in FD0.\r
+        //\r
+        FdBase  = FdBase + EFI_WINNT_RUNTIME_UPDATABLE_OFFSET;\r
+        FdSize  = EFI_WINNT_RUNTIME_UPDATABLE_LENGTH + EFI_WINNT_FTW_SPARE_BLOCK_LENGTH;\r
+\r
+        BuildFvHob (FdBase, FdSize);\r
+      } else {\r
+        //\r
+        // For other FD's just map them in.\r
+        //\r
+        BuildResourceDescriptorHob (\r
+          EFI_RESOURCE_FIRMWARE_DEVICE,\r
+          (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),\r
+          FdBase,\r
+          FdSize\r
+          );\r
+      }\r
+    }\r
+\r
+    Index++;\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  return Status;\r
+}\r