]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Port EdkUnixPkg to UnixPkg. The changes are listed as follows:
authoreric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 30 Jun 2008 05:08:49 +0000 (05:08 +0000)
committereric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 30 Jun 2008 05:08:49 +0000 (05:08 +0000)
1. change *.msa to *.inf, and create platform configuration files .dec&.dsc&.fdf to comply with Edk2 build process
2. using PCD mechanism to replace macro.
3. change Sec code to cowork with PI1.0 Pei Core and produce temparory memory ppi.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@5380 6f19259b-4bc3-4df7-8a09-765794883524

165 files changed:
UnixPkg/BootModePei/BootModePei.c [new file with mode: 0644]
UnixPkg/BootModePei/BootModePei.inf [new file with mode: 0644]
UnixPkg/BootModePei/BootModePei.msa [new file with mode: 0644]
UnixPkg/CpuRuntimeDxe/Cpu.c [new file with mode: 0644]
UnixPkg/CpuRuntimeDxe/Cpu.inf [new file with mode: 0644]
UnixPkg/CpuRuntimeDxe/Cpu.msa [new file with mode: 0644]
UnixPkg/CpuRuntimeDxe/CpuDriver.h [new file with mode: 0644]
UnixPkg/CpuRuntimeDxe/CpuIo.c [new file with mode: 0644]
UnixPkg/CpuRuntimeDxe/Strings.uni [new file with mode: 0644]
UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c [new file with mode: 0644]
UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c [new file with mode: 0644]
UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h [new file with mode: 0644]
UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf [new file with mode: 0644]
UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa [new file with mode: 0644]
UnixPkg/Include/Common/UnixInclude.h [new file with mode: 0644]
UnixPkg/Include/FlashLayout.h [new file with mode: 0644]
UnixPkg/Include/Library/UnixLib.h [new file with mode: 0644]
UnixPkg/Include/Ppi/UnixAutoScan.h [new file with mode: 0644]
UnixPkg/Include/Ppi/UnixFwh.h [new file with mode: 0644]
UnixPkg/Include/Ppi/UnixPeiLoadFile.h [new file with mode: 0644]
UnixPkg/Include/Ppi/UnixThunk.h [new file with mode: 0644]
UnixPkg/Include/Protocol/UnixIo.h [new file with mode: 0644]
UnixPkg/Include/Protocol/UnixThunk.h [new file with mode: 0644]
UnixPkg/Include/Protocol/UnixUgaIo.h [new file with mode: 0644]
UnixPkg/Include/UnixDxe.h [new file with mode: 0644]
UnixPkg/Include/UnixPeim.h [new file with mode: 0644]
UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf [new file with mode: 0644]
UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa [new file with mode: 0644]
UnixPkg/Library/DxeUnixLib/UnixLib.c [new file with mode: 0644]
UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf [new file with mode: 0644]
UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa [new file with mode: 0644]
UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c [new file with mode: 0644]
UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c [new file with mode: 0644]
UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf [new file with mode: 0644]
UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf [new file with mode: 0644]
UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa [new file with mode: 0644]
UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c [new file with mode: 0644]
UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c [new file with mode: 0644]
UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf [new file with mode: 0644]
UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf [new file with mode: 0644]
UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa [new file with mode: 0644]
UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c [new file with mode: 0644]
UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.c [new file with mode: 0644]
UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf [new file with mode: 0644]
UnixPkg/Library/UnixBdsLib/BdsPlatform.c [new file with mode: 0644]
UnixPkg/Library/UnixBdsLib/BdsPlatform.h [new file with mode: 0644]
UnixPkg/Library/UnixBdsLib/PlatformBds.inf [new file with mode: 0644]
UnixPkg/Library/UnixBdsLib/PlatformBds.msa [new file with mode: 0644]
UnixPkg/Library/UnixBdsLib/PlatformData.c [new file with mode: 0644]
UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoader.c [new file with mode: 0644]
UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.inf [new file with mode: 0644]
UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.msa [new file with mode: 0644]
UnixPkg/MetronomeDxe/Metronome.c [new file with mode: 0644]
UnixPkg/MetronomeDxe/Metronome.h [new file with mode: 0644]
UnixPkg/MetronomeDxe/Metronome.inf [new file with mode: 0644]
UnixPkg/MetronomeDxe/Metronome.msa [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscDevicePath.h [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscOemString.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscOemStringData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.msa [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni [new file with mode: 0644]
UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c [new file with mode: 0644]
UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c [new file with mode: 0644]
UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf [new file with mode: 0644]
UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.msa [new file with mode: 0644]
UnixPkg/ResetRuntimeDxe/Reset.c [new file with mode: 0644]
UnixPkg/ResetRuntimeDxe/Reset.inf [new file with mode: 0644]
UnixPkg/ResetRuntimeDxe/Reset.msa [new file with mode: 0644]
UnixPkg/Sec/FwVol.c [new file with mode: 0644]
UnixPkg/Sec/SecMain.c [new file with mode: 0644]
UnixPkg/Sec/SecMain.h [new file with mode: 0644]
UnixPkg/Sec/SecMain.inf [new file with mode: 0644]
UnixPkg/Sec/SecMain.msa [new file with mode: 0644]
UnixPkg/Sec/Stack.S [new file with mode: 0644]
UnixPkg/Sec/UgaX11.c [new file with mode: 0644]
UnixPkg/Sec/UnixThunk.c [new file with mode: 0644]
UnixPkg/TimerDxe/Timer.c [new file with mode: 0644]
UnixPkg/TimerDxe/Timer.h [new file with mode: 0644]
UnixPkg/TimerDxe/Timer.inf [new file with mode: 0644]
UnixPkg/TimerDxe/Timer.msa [new file with mode: 0644]
UnixPkg/UnixAutoScanPei/UnixAutoScan.c [new file with mode: 0644]
UnixPkg/UnixAutoScanPei/UnixAutoScan.inf [new file with mode: 0644]
UnixPkg/UnixAutoScanPei/UnixAutoScan.msa [new file with mode: 0644]
UnixPkg/UnixBlockIoDxe/ComponentName.c [new file with mode: 0644]
UnixPkg/UnixBlockIoDxe/DriverConfiguration.c [new file with mode: 0644]
UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c [new file with mode: 0644]
UnixPkg/UnixBlockIoDxe/EntryPoint.c [new file with mode: 0644]
UnixPkg/UnixBlockIoDxe/UnixBlockIo.c [new file with mode: 0644]
UnixPkg/UnixBlockIoDxe/UnixBlockIo.h [new file with mode: 0644]
UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf [new file with mode: 0644]
UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa [new file with mode: 0644]
UnixPkg/UnixBusDriverDxe/ComponentName.c [new file with mode: 0644]
UnixPkg/UnixBusDriverDxe/EntryPoint.c [new file with mode: 0644]
UnixPkg/UnixBusDriverDxe/UnixBusDriver.c [new file with mode: 0644]
UnixPkg/UnixBusDriverDxe/UnixBusDriver.h [new file with mode: 0644]
UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf [new file with mode: 0644]
UnixPkg/UnixBusDriverDxe/UnixBusDriver.msa [new file with mode: 0644]
UnixPkg/UnixConsoleDxe/ComponentName.c [new file with mode: 0644]
UnixPkg/UnixConsoleDxe/Console.c [new file with mode: 0644]
UnixPkg/UnixConsoleDxe/Console.h [new file with mode: 0644]
UnixPkg/UnixConsoleDxe/ConsoleIn.c [new file with mode: 0644]
UnixPkg/UnixConsoleDxe/ConsoleOut.c [new file with mode: 0644]
UnixPkg/UnixConsoleDxe/EntryPoint.c [new file with mode: 0644]
UnixPkg/UnixConsoleDxe/UnixConsole.inf [new file with mode: 0644]
UnixPkg/UnixConsoleDxe/UnixConsole.msa [new file with mode: 0644]
UnixPkg/UnixFirmwareVolumePei/UnixFwh.c [new file with mode: 0644]
UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf [new file with mode: 0644]
UnixPkg/UnixFirmwareVolumePei/UnixFwh.msa [new file with mode: 0644]
UnixPkg/UnixFlashMapPei/FlashMap.c [new file with mode: 0644]
UnixPkg/UnixFlashMapPei/FlashMap.inf [new file with mode: 0644]
UnixPkg/UnixFlashMapPei/FlashMap.msa [new file with mode: 0644]
UnixPkg/UnixPkg.dec [new file with mode: 0644]
UnixPkg/UnixPkg.dsc [new file with mode: 0644]
UnixPkg/UnixPkg.fdf [new file with mode: 0644]
UnixPkg/UnixSerialIoDxe/ComponentName.c [new file with mode: 0644]
UnixPkg/UnixSerialIoDxe/EntryPoint.c [new file with mode: 0644]
UnixPkg/UnixSerialIoDxe/UnixSerialIo.c [new file with mode: 0644]
UnixPkg/UnixSerialIoDxe/UnixSerialIo.h [new file with mode: 0644]
UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf [new file with mode: 0644]
UnixPkg/UnixSerialIoDxe/UnixSerialIo.msa [new file with mode: 0644]
UnixPkg/UnixSimpleFileSystemDxe/ComponentName.c [new file with mode: 0644]
UnixPkg/UnixSimpleFileSystemDxe/EntryPoint.c [new file with mode: 0644]
UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c [new file with mode: 0644]
UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h [new file with mode: 0644]
UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf [new file with mode: 0644]
UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.msa [new file with mode: 0644]
UnixPkg/UnixThunkDxe/UnixThunk.c [new file with mode: 0644]
UnixPkg/UnixThunkDxe/UnixThunk.h [new file with mode: 0644]
UnixPkg/UnixThunkDxe/UnixThunk.inf [new file with mode: 0644]
UnixPkg/UnixThunkDxe/UnixThunk.msa [new file with mode: 0644]
UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.c [new file with mode: 0644]
UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf [new file with mode: 0644]
UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.msa [new file with mode: 0644]
UnixPkg/UnixUgaDxe/ComponentName.c [new file with mode: 0644]
UnixPkg/UnixUgaDxe/EntryPoint.c [new file with mode: 0644]
UnixPkg/UnixUgaDxe/UnixUga.h [new file with mode: 0644]
UnixPkg/UnixUgaDxe/UnixUga.inf [new file with mode: 0644]
UnixPkg/UnixUgaDxe/UnixUga.msa [new file with mode: 0644]
UnixPkg/UnixUgaDxe/UnixUgaDriver.c [new file with mode: 0644]
UnixPkg/UnixUgaDxe/UnixUgaInput.c [new file with mode: 0644]
UnixPkg/UnixUgaDxe/UnixUgaScreen.c [new file with mode: 0644]

diff --git a/UnixPkg/BootModePei/BootModePei.c b/UnixPkg/BootModePei/BootModePei.c
new file mode 100644 (file)
index 0000000..b7f3ad0
--- /dev/null
@@ -0,0 +1,101 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  BootMode.c\r
+   \r
+Abstract:\r
+\r
+  Tiano PEIM to provide the platform support functionality within Unix\r
+\r
+**/\r
+\r
+\r
+\r
+//\r
+// The package level header files this module uses\r
+//\r
+#include <PiPei.h>\r
+//\r
+// The protocols, PPI and GUID defintions for this module\r
+//\r
+#include <Ppi/MasterBootMode.h>\r
+#include <Ppi/BootInRecoveryMode.h>\r
+//\r
+// The Library classes this module consumes\r
+//\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+\r
+\r
+//\r
+// Module globals\r
+//\r
+EFI_PEI_PPI_DESCRIPTOR  mPpiListBootMode = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiPeiMasterBootModePpiGuid,\r
+  NULL\r
+};\r
+\r
+EFI_PEI_PPI_DESCRIPTOR  mPpiListRecoveryBootMode = {\r
+  (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),\r
+  &gEfiPeiBootInRecoveryModePpiGuid,\r
+  NULL\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeBootMode (\r
+  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
+  IN EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Peform the boot mode determination logic\r
+\r
+Arguments:\r
+\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+\r
+  Status -  EFI_SUCCESS if the boot mode could be set\r
+\r
+--*/\r
+// TODO:    FfsHeader - add argument and description to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       BootMode;\r
+\r
+  DEBUG ((EFI_D_ERROR, "Unix Boot Mode PEIM Loaded\n"));\r
+\r
+  //\r
+  // Let's assume things are OK if not told otherwise\r
+  // Should we read an environment variable in order to easily change this?\r
+  //\r
+  BootMode  = BOOT_WITH_FULL_CONFIGURATION;\r
+\r
+  Status    = (**PeiServices).SetBootMode (PeiServices, (UINT8) BootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListBootMode);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  if (BootMode == BOOT_IN_RECOVERY_MODE) {\r
+    Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListRecoveryBootMode);\r
+    ASSERT_EFI_ERROR (Status);\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/BootModePei/BootModePei.inf b/UnixPkg/BootModePei/BootModePei.inf
new file mode 100644 (file)
index 0000000..d991507
--- /dev/null
@@ -0,0 +1,57 @@
+#/** @file\r
+# Component description file for BootMode module\r
+#\r
+# This module provides platform specific function to detect boot mode.\r
+# Copyright (c) 2006 - 2008, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = BootModePei\r
+  FILE_GUID                      = f3ff9aee-8985-11db-b133-0040d02b1835\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeBootMode\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  BootModePei.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  BaseLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gEfiPeiMasterBootModePpiGuid                  # PPI ALWAYS_PRODUCED\r
+  gEfiPeiBootInRecoveryModePpiGuid              # PPI SOMETIMES_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/UnixPkg/BootModePei/BootModePei.msa b/UnixPkg/BootModePei/BootModePei.msa
new file mode 100644 (file)
index 0000000..5b2c8d8
--- /dev/null
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>BootMode</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>f3ff9aee-8985-11db-b133-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for BootMode module</Abstract>\r
+    <Description>This module provides platform specific function to detect boot mode.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>BootMode</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeimEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesTablePointerLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>BootMode.c</Filename>\r
+    <Filename>BootMode.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="SOMETIMES_PRODUCED">\r
+      <PpiCName>gEfiPeiBootInRecoveryModePpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gEfiPeiMasterBootModePpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeBootMode</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/CpuRuntimeDxe/Cpu.c b/UnixPkg/CpuRuntimeDxe/Cpu.c
new file mode 100644 (file)
index 0000000..aef2c30
--- /dev/null
@@ -0,0 +1,536 @@
+/*++\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
+\r
+  Cpu.c\r
+\r
+Abstract:\r
+\r
+  Unix Emulation Architectural Protocol Driver as defined in Tiano.\r
+  This CPU module abstracts the interrupt subsystem of a platform and\r
+  the CPU-specific setjump/long pair.  Other services are not implemented\r
+  in this driver.\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/DataHub.h>\r
+#include <Guid/DataHubRecords.h>\r
+#include <Protocol/CpuIo.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Guid/DataHubProducer.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Framework/DataHubRecords.h>\r
+#include "CpuDriver.h"\r
+#include "UnixDxe.h"\r
+#include <Protocol/UnixIo.h>\r
+\r
+#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100\r
+\r
+CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = {\r
+  CPU_ARCH_PROT_PRIVATE_SIGNATURE,\r
+  NULL,\r
+  {\r
+    UnixFlushCpuDataCache,\r
+    UnixEnableInterrupt,\r
+    UnixDisableInterrupt,\r
+    UnixGetInterruptState,\r
+    UnixInit,\r
+    UnixRegisterInterruptHandler,\r
+    UnixGetTimerValue,\r
+    UnixSetMemoryAttributes,\r
+    0,\r
+    4\r
+  },\r
+  {\r
+    CpuMemoryServiceRead,\r
+    CpuMemoryServiceWrite,\r
+    CpuIoServiceRead,\r
+    CpuIoServiceWrite\r
+  },\r
+  0,\r
+  TRUE\r
+};\r
+\r
+typedef union {\r
+  EFI_CPU_DATA_RECORD *DataRecord;\r
+  UINT8               *Raw;\r
+} EFI_CPU_DATA_RECORD_BUFFER;\r
+\r
+EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader = {\r
+  EFI_PROCESSOR_SUBCLASS_VERSION,       // Version\r
+  sizeof (EFI_SUBCLASS_TYPE1_HEADER),   // Header Size\r
+  0,                                    // Instance, Initialize later\r
+  EFI_SUBCLASS_INSTANCE_NON_APPLICABLE, // SubInstance\r
+  0                                     // RecordType, Initialize later\r
+};\r
+\r
+//\r
+// Service routines for the driver\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixFlushCpuDataCache (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   Start,\r
+  IN UINT64                 Length,\r
+  IN EFI_CPU_FLUSH_TYPE     FlushType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would provide support for flushing the CPU data cache.\r
+  In the case of UNIX emulation environment, this flushing is not necessary and\r
+  is thus not implemented.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+  Start adddress in memory to flush\r
+  Length of memory to flush\r
+  Flush type\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    FlushType - add argument and description to function comment\r
+// TODO:    EFI_UNSUPPORTED - add return value to function comment\r
+{\r
+  if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {\r
+    //\r
+    // Only WB flush is supported. We actually need do nothing on UNIX emulator\r
+    // environment. Classify this to follow EFI spec\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+  //\r
+  // Other flush types are not supported by UNIX emulator\r
+  //\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixEnableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine provides support for emulation of the interrupt enable of the\r
+  the system.  For our purposes, CPU enable is just a BOOLEAN that the Timer\r
+  Architectural Protocol observes in order to defer behaviour while in its\r
+  emulated interrupt, or timer tick.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private                 = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  Private->InterruptState = TRUE;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixDisableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine provides support for emulation of the interrupt disable of the\r
+  the system.  For our purposes, CPU enable is just a BOOLEAN that the Timer\r
+  Architectural Protocol observes in order to defer behaviour while in its\r
+  emulated interrupt, or timer tick.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private                 = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  Private->InterruptState = FALSE;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetInterruptState (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  OUT BOOLEAN               *State\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine provides support for emulation of the interrupt disable of the\r
+  the system.  For our purposes, CPU enable is just a BOOLEAN that the Timer\r
+  Architectural Protocol observes in order to defer behaviour while in its\r
+  emulated interrupt, or timer tick.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    State - add argument and description to function comment\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  if (State == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  *State  = Private->InterruptState;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixInit (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_CPU_INIT_TYPE      InitType\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would support generation of a CPU INIT.  At\r
+  present, this code does not provide emulation.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+  INIT Type\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_UNSUPPORTED - not yet implemented\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    InitType - add argument and description to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixRegisterInterruptHandler (\r
+  IN EFI_CPU_ARCH_PROTOCOL      *This,\r
+  IN EFI_EXCEPTION_TYPE         InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would support registration of an interrupt handler.  At\r
+  present, this code does not provide emulation.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+  Pointer to interrupt handlers\r
+  Interrupt type\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_UNSUPPORTED - not yet implemented\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    InterruptType - add argument and description to function comment\r
+// TODO:    InterruptHandler - add argument and description to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  //\r
+  // Do parameter checking for EFI spec conformance\r
+  //\r
+  if (InterruptType < 0 || InterruptType > 0xff) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Do nothing for Nt32 emulation\r
+  //\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetTimerValue (\r
+  IN  EFI_CPU_ARCH_PROTOCOL *This,\r
+  IN  UINT32                TimerIndex,\r
+  OUT UINT64                *TimerValue,\r
+  OUT UINT64                *TimerPeriod OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would support querying of an on-CPU timer.  At present,\r
+  this code does not provide timer emulation.\r
+\r
+Arguments:\r
+\r
+  This        - Pointer to CPU Architectural Protocol interface\r
+  TimerIndex  - Index of given CPU timer\r
+  TimerValue  - Output of the timer\r
+  TimerPeriod - Output of the timer period\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED       - not yet implemented\r
+  EFI_INVALID_PARAMETER - TimeValue is NULL\r
+\r
+--*/\r
+{\r
+  if (TimerValue == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // No timer supported\r
+  //\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSetMemoryAttributes (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 Attributes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This routine would support querying of an on-CPU timer.  At present,\r
+  this code does not provide timer emulation.\r
+\r
+Arguments:\r
+\r
+  Pointer to CPU Architectural Protocol interface\r
+  Start address of memory region\r
+  The size in bytes of the memory region\r
+  The bit mask of attributes to set for the memory region\r
+\r
+Returns:\r
+\r
+  Status\r
+    EFI_UNSUPPORTED - not yet implemented\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    BaseAddress - add argument and description to function comment\r
+// TODO:    Length - add argument and description to function comment\r
+// TODO:    Attributes - add argument and description to function comment\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  CPU_ARCH_PROTOCOL_PRIVATE *Private;\r
+\r
+  //\r
+  // Check for invalid parameter for Spec conformance\r
+  //\r
+  if (Length == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 emulation\r
+  //\r
+  Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+VOID\r
+CpuUpdateDataHub (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This function will log processor version and frequency data to data hub.\r
+\r
+Arguments:\r
+  Event        - Event whose notification function is being invoked.\r
+  Context      - Pointer to the notification function's context.\r
+\r
+Returns:\r
+  None.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_CPU_DATA_RECORD_BUFFER  RecordBuffer;\r
+  UINT32                      HeaderSize;\r
+  UINT32                      TotalSize;\r
+  EFI_DATA_HUB_PROTOCOL       *DataHub;\r
+  EFI_HII_HANDLE              HiiHandle;\r
+\r
+  //\r
+  // Locate DataHub protocol.\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, &DataHub);\r
+  if (EFI_ERROR (Status)) {\r
+    return;\r
+  }\r
+\r
+  //\r
+  // Initialize data record header\r
+  //\r
+  mCpuDataRecordHeader.Instance = 1;\r
+  HeaderSize                    = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r
+\r
+  RecordBuffer.Raw              = AllocatePool (HeaderSize + EFI_CPU_DATA_MAXIMUM_LENGTH);\r
+  if (RecordBuffer.Raw == NULL) {\r
+    return ;\r
+  }\r
+\r
+  //\r
+  // Initialize strings to HII database\r
+  //\r
+  HiiLibAddPackages (1, &gEfiProcessorProducerGuid, NULL, &HiiHandle, CpuStrings);\r
+  \r
+\r
+  CopyMem (RecordBuffer.Raw, &mCpuDataRecordHeader, HeaderSize);\r
+\r
+\r
+  RecordBuffer.DataRecord->DataRecordHeader.RecordType      = ProcessorVersionRecordType;\r
+  RecordBuffer.DataRecord->VariableRecord.ProcessorVersion  = STRING_TOKEN (STR_INTEL_GENUINE_PROCESSOR);\r
+  TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_VERSION_DATA);\r
+\r
+  Status = DataHub->LogData (\r
+                      DataHub,\r
+                      &gEfiProcessorSubClassGuid,\r
+                      &gEfiProcessorProducerGuid,\r
+                      EFI_DATA_RECORD_CLASS_DATA,\r
+                      RecordBuffer.Raw,\r
+                      TotalSize\r
+                      );\r
+\r
+  //\r
+  // Store CPU frequency data record to data hub - It's an emulator so make up a value\r
+  //\r
+  RecordBuffer.DataRecord->DataRecordHeader.RecordType                    = ProcessorCoreFrequencyRecordType;\r
+  RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Value    = 1234;\r
+  RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Exponent = 6;\r
+  TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_CORE_FREQUENCY_DATA);\r
+\r
+  Status = DataHub->LogData (\r
+                      DataHub,\r
+                      &gEfiProcessorSubClassGuid,\r
+                      &gEfiProcessorProducerGuid,\r
+                      EFI_DATA_RECORD_CLASS_DATA,\r
+                      RecordBuffer.Raw,\r
+                      TotalSize\r
+                      );\r
+\r
+  FreePool (RecordBuffer.Raw);\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpu (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialize the state information for the CPU Architectural Protocol\r
+\r
+Arguments:\r
+\r
+  ImageHandle of the loaded driver\r
+  Pointer to the System Table\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  EFI_SUCCESS           - protocol instance can be published\r
+  EFI_OUT_OF_RESOURCES  - cannot allocate protocol data structure\r
+  EFI_DEVICE_ERROR      - cannot create the thread\r
+\r
+--*/\r
+// TODO:    SystemTable - add argument and description to function comment\r
+{\r
+  EFI_STATUS                Status;\r
+\r
+  CpuUpdateDataHub ();\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &mCpuTemplate.Handle,\r
+                  &gEfiCpuArchProtocolGuid,   &mCpuTemplate.Cpu,\r
+                  &gEfiCpuIoProtocolGuid,     &mCpuTemplate.CpuIo,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  DEBUG ((EFI_D_ERROR, "CPU Architectural Protocol Loaded\n"));\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/CpuRuntimeDxe/Cpu.inf b/UnixPkg/CpuRuntimeDxe/Cpu.inf
new file mode 100644 (file)
index 0000000..a8613ff
--- /dev/null
@@ -0,0 +1,73 @@
+#/** @file\r
+# Component description file for Cpu module.\r
+#\r
+# This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.\r
+# Copyright (c) 2006 - 2008, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Cpu\r
+  FILE_GUID                      = f3794b60-8985-11db-8e53-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeCpu\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  CpuIo.c\r
+  Cpu.c\r
+  CpuDriver.h\r
+  Strings.uni\r
+\r
+\r
+[Packages]\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  HiiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Guids]\r
+  gEfiProcessorSubClassGuid                     # SOMETIMES_CONSUMED\r
+  gEfiProcessorProducerGuid                     # SOMETIMES_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiUnixIoProtocolGuid                        # PROTOCOL_NOTIFY SOMETIMES_CONSUMED\r
+  gEfiDataHubProtocolGuid                       # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiHiiProtocolGuid                           # PROTOCOL SOMETIMES_CONSUMED\r
+  gEfiCpuIoProtocolGuid                         # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiCpuArchProtocolGuid                       # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  gEfiDataHubProtocolGuid
\ No newline at end of file
diff --git a/UnixPkg/CpuRuntimeDxe/Cpu.msa b/UnixPkg/CpuRuntimeDxe/Cpu.msa
new file mode 100644 (file)
index 0000000..b6be83f
--- /dev/null
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>Cpu</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f3794b60-8985-11db-8e53-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Cpu module.</Abstract>\r
+    <Description>This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>Cpu</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HiiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Strings.uni</Filename>\r
+    <Filename>CpuDriver.h</Filename>\r
+    <Filename>Cpu.c</Filename>\r
+    <Filename>CpuIo.c</Filename>\r
+    <Filename>Cpu.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiCpuArchProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiCpuIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolCName>gEfiDataHubProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <ProtocolNotify Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolNotifyCName>gEfiUnixIoProtocolGuid</ProtocolNotifyCName>\r
+    </ProtocolNotify>\r
+  </Protocols>\r
+  <DataHubs>\r
+    <DataHubRecord Usage="SOMETIMES_PRODUCED">\r
+      <DataHubCName>ProcessorVersion</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="SOMETIMES_PRODUCED">\r
+      <DataHubCName>ProcessorCoreFrequency</DataHubCName>\r
+    </DataHubRecord>\r
+  </DataHubs>\r
+  <Guids>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiProcessorProducerGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiProcessorSubClassGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiUnixCPUModelGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiUnixCPUSpeedGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeCpu</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/CpuRuntimeDxe/CpuDriver.h b/UnixPkg/CpuRuntimeDxe/CpuDriver.h
new file mode 100644 (file)
index 0000000..8898143
--- /dev/null
@@ -0,0 +1,163 @@
+/*++\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
+\r
+  CpuDriver.h\r
+\r
+Abstract:\r
+\r
+  UNIX Emulation Architectural Protocol Driver as defined in Tiano.\r
+\r
+--*/\r
+\r
+#ifndef _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+#define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_\r
+\r
+\r
+\r
+extern UINT8  CpuStrings[];\r
+\r
+//\r
+// Internal Data Structures\r
+//\r
+#define CPU_ARCH_PROT_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('c', 'a', 'p', 'd')\r
+\r
+typedef struct {\r
+  UINTN                 Signature;\r
+  EFI_HANDLE            Handle;\r
+\r
+  EFI_CPU_ARCH_PROTOCOL Cpu;\r
+  EFI_CPU_IO_PROTOCOL   CpuIo;\r
+\r
+  //\r
+  // Local Data for CPU interface goes here\r
+  //\r
+  BOOLEAN               InterruptState;\r
+\r
+} CPU_ARCH_PROTOCOL_PRIVATE;\r
+\r
+#define CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \\r
+  CR (a, \\r
+      CPU_ARCH_PROTOCOL_PRIVATE, \\r
+      Cpu, \\r
+      CPU_ARCH_PROT_PRIVATE_SIGNATURE \\r
+      )\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+  IN  EFI_CPU_IO_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeCpu (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixFlushCpuDataCache (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   Start,\r
+  IN UINT64                 Length,\r
+  IN EFI_CPU_FLUSH_TYPE     FlushType\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixEnableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixDisableInterrupt (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetInterruptState (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  OUT BOOLEAN               *State\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixInit (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_CPU_INIT_TYPE      InitType\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixRegisterInterruptHandler (\r
+  IN EFI_CPU_ARCH_PROTOCOL      *This,\r
+  IN EFI_EXCEPTION_TYPE         InterruptType,\r
+  IN EFI_CPU_INTERRUPT_HANDLER  InterruptHandler\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetTimerValue (\r
+  IN  EFI_CPU_ARCH_PROTOCOL *This,\r
+  IN  UINT32                TimerIndex,\r
+  OUT UINT64                *TimerValue,\r
+  OUT UINT64                *TimerPeriod OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSetMemoryAttributes (\r
+  IN EFI_CPU_ARCH_PROTOCOL  *This,\r
+  IN EFI_PHYSICAL_ADDRESS   BaseAddress,\r
+  IN UINT64                 Length,\r
+  IN UINT64                 Attributes\r
+  );\r
+\r
+#endif\r
diff --git a/UnixPkg/CpuRuntimeDxe/CpuIo.c b/UnixPkg/CpuRuntimeDxe/CpuIo.c
new file mode 100644 (file)
index 0000000..2360fff
--- /dev/null
@@ -0,0 +1,350 @@
+/*++\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
+\r
+  CpuIo.c\r
+\r
+Abstract:\r
+\r
+  This is the code that publishes the CPU I/O Protocol.\r
+  The intent herein is to have a single I/O service that can load\r
+  as early as possible, extend into runtime, and be layered upon by \r
+  the implementations of architectural protocols and the PCI Root\r
+  Bridge I/O Protocol.\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include <Protocol/Cpu.h>\r
+#include <Protocol/DataHub.h>\r
+#include <Guid/DataHubRecords.h>\r
+#include <Protocol/CpuIo.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Guid/DataHubProducer.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HiiLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <CpuDriver.h>\r
+\r
+#define IA32_MAX_IO_ADDRESS   0xFFFF\r
+#define IA32_MAX_MEM_ADDRESS  0xFFFFFFFF\r
+\r
+EFI_CPU_IO_PROTOCOL mCpuIoProtocol;\r
+\r
+EFI_STATUS\r
+CpuIoCheckAddressRange (\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  VOID                              *Buffer,\r
+  IN  UINT64                            Limit\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceRead (\r
+  IN  EFI_CPU_IO_PROTOCOL               *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform the Memory Access Read service for the CPU I/O Protocol\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the Memory access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from memory\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  EFI_SUCCESS             - The data was read from or written to the EFI \r
+                            System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, \r
+                            and Count is not valid for this EFI System.\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (!Buffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuMemoryServiceWrite (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform the Memory Access Read service for the CPU I/O Protocol\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the Memory access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from memory\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  EFI_SUCCESS             - The data was read from or written to the EFI System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, and \r
+                            Count is not valid for this EFI System.\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  if (!Buffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceRead (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  This is the service that implements the I/O read\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the I/O access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from I/O space\r
+\r
+Returns:\r
+\r
+  Status\r
+  EFI_SUCCESS             - The data was read from or written to the EFI System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, and \r
+                            Count is not valid for this EFI System.\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    UserAddress - add argument and description to function comment\r
+// TODO:    UserBuffer - add argument and description to function comment\r
+{\r
+  UINTN       Address;\r
+  EFI_STATUS  Status;\r
+\r
+  if (!UserBuffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Address = (UINTN) UserAddress;\r
+\r
+  if (Width >= EfiCpuIoWidthMaximum) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoServiceWrite (\r
+  IN EFI_CPU_IO_PROTOCOL                *This,\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            UserAddress,\r
+  IN  UINTN                             Count,\r
+  IN  OUT VOID                          *UserBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  \r
+  This is the service that implements the I/O Write\r
+\r
+Arguments:\r
+\r
+  Pointer to an instance of the CPU I/O Protocol\r
+  Width of the Memory Access\r
+  Address of the I/O access\r
+  Count of the number of accesses to perform\r
+  Pointer to the buffer to read or write from I/O space\r
+\r
+Returns:\r
+\r
+  Status\r
+\r
+  Status\r
+  EFI_SUCCESS             - The data was read from or written to the EFI System.\r
+  EFI_INVALID_PARAMETER   - Width is invalid for this EFI System.\r
+  EFI_INVALID_PARAMETER   - Buffer is NULL.\r
+  EFI_UNSUPPORTED         - The Buffer is not aligned for the given Width.\r
+  EFI_UNSUPPORTED         - The address range specified by Address, Width, and \r
+                            Count is not valid for this EFI System.\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    UserAddress - add argument and description to function comment\r
+// TODO:    UserBuffer - add argument and description to function comment\r
+{\r
+  UINTN       Address;\r
+  EFI_STATUS  Status;\r
+\r
+  if (!UserBuffer) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Address = (UINTN) UserAddress;\r
+\r
+  if (Width >= EfiCpuIoWidthMaximum) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Do nothing for Nt32 version\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+CpuIoCheckAddressRange (\r
+  IN  EFI_CPU_IO_PROTOCOL_WIDTH         Width,\r
+  IN  UINT64                            Address,\r
+  IN  UINTN                             Count,\r
+  IN  VOID                              *Buffer,\r
+  IN  UINT64                            Limit\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Width   - TODO: add argument description\r
+  Address - TODO: add argument description\r
+  Count   - TODO: add argument description\r
+  Buffer  - TODO: add argument description\r
+  Limit   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UINTN AlignMask;\r
+\r
+  if (Address > Limit) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // For FiFo type, the target address won't increase during the access, so treat count as 1\r
+  //\r
+  if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {\r
+    Count = 1;\r
+  }\r
+\r
+  Width = Width & 0x03;\r
+  if (Address - 1 + (1 << Width) * Count > Limit) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  AlignMask = (1 << Width) - 1;\r
+  if ((UINTN) Buffer & AlignMask) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
diff --git a/UnixPkg/CpuRuntimeDxe/Strings.uni b/UnixPkg/CpuRuntimeDxe/Strings.uni
new file mode 100644 (file)
index 0000000..fd70fb9
Binary files /dev/null and b/UnixPkg/CpuRuntimeDxe/Strings.uni differ
diff --git a/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c b/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c
new file mode 100644 (file)
index 0000000..5889586
--- /dev/null
@@ -0,0 +1,1553 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  FWBlockService.c\r
+    \r
+Abstract:\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#include "PiDxe.h"\r
+#include <Guid/EventGroup.h>\r
+#include <Protocol/FvbExtension.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+#include <Guid/AlternateFvBlock.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/UefiRuntimeLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include "FwBlockService.h"\r
+\r
+ESAL_FWB_GLOBAL         *mFvbModuleGlobal;\r
+\r
+#define EFI_FVB2_STATUS (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS)\r
+\r
+EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = {\r
+  FVB_DEVICE_SIGNATURE,\r
+  {\r
+    {\r
+      {\r
+        HARDWARE_DEVICE_PATH,\r
+        HW_MEMMAP_DP,\r
+        {\r
+          sizeof (MEMMAP_DEVICE_PATH),\r
+          0\r
+        }\r
+      },\r
+      EfiMemoryMappedIO,\r
+      0,\r
+      0,\r
+    },\r
+    {\r
+      END_DEVICE_PATH_TYPE,\r
+      END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+      {\r
+        sizeof (EFI_DEVICE_PATH_PROTOCOL),\r
+        0\r
+      }\r
+    }\r
+  },\r
+  0,\r
+  {\r
+    FvbProtocolGetAttributes,\r
+    FvbProtocolSetAttributes,\r
+    FvbProtocolGetPhysicalAddress,\r
+    FvbProtocolGetBlockSize,\r
+    FvbProtocolRead,\r
+    FvbProtocolWrite,\r
+    FvbProtocolEraseBlocks,\r
+    NULL\r
+  },\r
+  {\r
+    FvbExtendProtocolEraseCustomBlockRange\r
+  }\r
+};\r
+\r
+\r
+\r
+VOID\r
+EFIAPI\r
+FvbVirtualddressChangeEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Fixup internal data so that EFI and SAL can be call in virtual mode.\r
+  Call the passed in Child Notify event and convert the mFvbModuleGlobal\r
+  date items to there virtual address.\r
+\r
+  mFvbModuleGlobal->FvInstance[FVB_PHYSICAL]  - Physical copy of instance data\r
+  mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]   - Virtual pointer to common \r
+                                                instance data.\r
+\r
+Arguments:\r
+\r
+  (Standard EFI notify event - EFI_EVENT_NOTIFY)\r
+\r
+Returns: \r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhInstance;\r
+  UINTN               Index;\r
+\r
+  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]);\r
+\r
+  //\r
+  // Convert the base address of all the instances\r
+  //\r
+  Index       = 0;\r
+  FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
+  while (Index < mFvbModuleGlobal->NumFv) {\r
+    EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase[FVB_VIRTUAL]);\r
+    FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
+      (\r
+        (UINTN) ((UINT8 *) FwhInstance) + FwhInstance->VolumeHeader.HeaderLength +\r
+          (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
+      );\r
+    Index++;\r
+  }\r
+\r
+  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL]);\r
+  EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal);\r
+}\r
+\r
+EFI_STATUS\r
+GetFvbInstance (\r
+  IN  UINTN                               Instance,\r
+  IN  ESAL_FWB_GLOBAL                     *Global,\r
+  OUT EFI_FW_VOL_INSTANCE                 **FwhInstance,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieves the physical address of a memory mapped FV\r
+\r
+Arguments:\r
+  Instance              - The FV instance whose base address is going to be\r
+                          returned\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  FwhInstance           - The EFI_FW_VOL_INSTANCE fimrware instance structure\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhRecord;\r
+\r
+  if (Instance >= Global->NumFv) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  FwhRecord = Global->FvInstance[Virtual];\r
+  while (Instance > 0) {\r
+    FwhRecord = (EFI_FW_VOL_INSTANCE *)\r
+      (\r
+        (UINTN) ((UINT8 *) FwhRecord) + FwhRecord->VolumeHeader.HeaderLength +\r
+          (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
+      );\r
+    Instance--;\r
+  }\r
+\r
+  *FwhInstance = FwhRecord;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+FvbGetPhysicalAddress (\r
+  IN UINTN                                Instance,\r
+  OUT EFI_PHYSICAL_ADDRESS                *Address,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieves the physical address of a memory mapped FV\r
+\r
+Arguments:\r
+  Instance              - The FV instance whose base address is going to be\r
+                          returned\r
+  Address               - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS \r
+                          that on successful return, contains the base address\r
+                          of the firmware volume. \r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhInstance;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  ASSERT_EFI_ERROR (Status);\r
+  *Address = FwhInstance->FvBase[Virtual];\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+FvbGetVolumeAttributes (\r
+  IN UINTN                                Instance,\r
+  OUT EFI_FVB_ATTRIBUTES                  *Attributes,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieves attributes, insures positive polarity of attribute bits, returns\r
+  resulting attributes in output parameter\r
+\r
+Arguments:\r
+  Instance              - The FV instance whose attributes is going to be \r
+                          returned\r
+  Attributes            - Output buffer which contains attributes\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhInstance;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  ASSERT_EFI_ERROR (Status);\r
+  *Attributes = FwhInstance->VolumeHeader.Attributes;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+FvbGetLbaAddress (\r
+  IN  UINTN                               Instance,\r
+  IN  EFI_LBA                             Lba,\r
+  OUT UINTN                               *LbaAddress,\r
+  OUT UINTN                               *LbaLength,\r
+  OUT UINTN                               *NumOfBlocks,\r
+  IN  ESAL_FWB_GLOBAL                     *Global,\r
+  IN  BOOLEAN                             Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieves the starting address of an LBA in an FV\r
+\r
+Arguments:\r
+  Instance              - The FV instance which the Lba belongs to\r
+  Lba                   - The logical block address\r
+  LbaAddress            - On output, contains the physical starting address \r
+                          of the Lba\r
+  LbaLength             - On output, contains the length of the block\r
+  NumOfBlocks           - A pointer to a caller allocated UINTN in which the\r
+                          number of consecutive blocks starting with Lba is\r
+                          returned. All blocks in this range have a size of\r
+                          BlockSize\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  UINT32                  NumBlocks;\r
+  UINT32                  BlockLength;\r
+  UINTN                   Offset;\r
+  EFI_LBA                 StartLba;\r
+  EFI_LBA                 NextLba;\r
+  EFI_FW_VOL_INSTANCE     *FwhInstance;\r
+  EFI_FV_BLOCK_MAP_ENTRY  *BlockMap;\r
+  EFI_STATUS              Status;\r
+\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  StartLba  = 0;\r
+  Offset    = 0;\r
+  BlockMap  = &(FwhInstance->VolumeHeader.BlockMap[0]);\r
+\r
+  //\r
+  // Parse the blockmap of the FV to find which map entry the Lba belongs to\r
+  //\r
+  while (TRUE) {\r
+    NumBlocks   = BlockMap->NumBlocks;\r
+    BlockLength = BlockMap->Length;\r
+\r
+    if (NumBlocks == 0 || BlockLength == 0) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    NextLba = StartLba + NumBlocks;\r
+\r
+    //\r
+    // The map entry found\r
+    //\r
+    if (Lba >= StartLba && Lba < NextLba) {\r
+      Offset = Offset + (UINTN) MultU64x32 ((Lba - StartLba), BlockLength);\r
+      if (LbaAddress != NULL) {\r
+        *LbaAddress = FwhInstance->FvBase[Virtual] + Offset;\r
+      }\r
+\r
+      if (LbaLength != NULL) {\r
+        *LbaLength = BlockLength;\r
+      }\r
+\r
+      if (NumOfBlocks != NULL) {\r
+        *NumOfBlocks = (UINTN) (NextLba - Lba);\r
+      }\r
+\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    StartLba  = NextLba;\r
+    Offset    = Offset + NumBlocks * BlockLength;\r
+    BlockMap++;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+FvbReadBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN UINTN                                BlockOffset,\r
+  IN OUT UINTN                            *NumBytes,\r
+  IN UINT8                                *Buffer,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Reads specified number of bytes into a buffer from the specified block\r
+\r
+Arguments:\r
+  Instance              - The FV instance to be read from\r
+  Lba                   - The logical block address to be read from\r
+  BlockOffset           - Offset into the block at which to begin reading\r
+  NumBytes              - Pointer that on input contains the total size of\r
+                          the buffer. On output, it contains the total number\r
+                          of bytes read\r
+  Buffer                - Pointer to a caller allocated buffer that will be\r
+                          used to hold the data read\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was read successfully and \r
+                          contents are in Buffer\r
+  EFI_BAD_BUFFER_SIZE   - Read attempted across a LBA boundary. On output,\r
+                          NumBytes contains the total number of bytes returned\r
+                          in Buffer\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the ReadDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be read\r
+  EFI_INVALID_PARAMETER - Instance not found, or NumBytes, Buffer are NULL\r
+\r
+--*/\r
+{\r
+  EFI_FVB_ATTRIBUTES  Attributes;\r
+  UINTN               LbaAddress;\r
+  UINTN               LbaLength;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Check for invalid conditions\r
+  //\r
+  if ((NumBytes == NULL) || (Buffer == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (*NumBytes == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = FvbGetLbaAddress (Instance, Lba, &LbaAddress, &LbaLength, NULL, Global, Virtual);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Check if the FV is read enabled\r
+  //\r
+  FvbGetVolumeAttributes (Instance, &Attributes, Global, Virtual);\r
+\r
+  if ((Attributes & EFI_FVB2_READ_STATUS) == 0) {\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+  //\r
+  // Perform boundary checks and adjust NumBytes\r
+  //\r
+  if (BlockOffset > LbaLength) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (LbaLength < (*NumBytes + BlockOffset)) {\r
+    *NumBytes = (UINT32) (LbaLength - BlockOffset);\r
+    Status    = EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  CopyMem (Buffer, (UINT8 *) (LbaAddress + BlockOffset), (UINTN) (*NumBytes));\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+FvbWriteBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN UINTN                                BlockOffset,\r
+  IN OUT UINTN                            *NumBytes,\r
+  IN UINT8                                *Buffer,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Writes specified number of bytes from the input buffer to the block\r
+\r
+Arguments:\r
+  Instance              - The FV instance to be written to\r
+  Lba                   - The starting logical block index to write to\r
+  BlockOffset           - Offset into the block at which to begin writing\r
+  NumBytes              - Pointer that on input contains the total size of\r
+                          the buffer. On output, it contains the total number\r
+                          of bytes actually written\r
+  Buffer                - Pointer to a caller allocated buffer that contains\r
+                          the source for the write\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was written successfully\r
+  EFI_BAD_BUFFER_SIZE   - Write attempted across a LBA boundary. On output,\r
+                          NumBytes contains the total number of bytes\r
+                          actually written\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written\r
+  EFI_INVALID_PARAMETER - Instance not found, or NumBytes, Buffer are NULL\r
+\r
+--*/\r
+{\r
+  EFI_FVB_ATTRIBUTES  Attributes;\r
+  UINTN               LbaAddress;\r
+  UINTN               LbaLength;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Check for invalid conditions\r
+  //\r
+  if ((NumBytes == NULL) || (Buffer == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (*NumBytes == 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = FvbGetLbaAddress (Instance, Lba, &LbaAddress, &LbaLength, NULL, Global, Virtual);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Check if the FV is write enabled\r
+  //\r
+  FvbGetVolumeAttributes (Instance, &Attributes, Global, Virtual);\r
+\r
+  if ((Attributes & EFI_FVB2_WRITE_STATUS) == 0) {\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+  //\r
+  // Perform boundary checks and adjust NumBytes\r
+  //\r
+  if (BlockOffset > LbaLength) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (LbaLength < (*NumBytes + BlockOffset)) {\r
+    *NumBytes = (UINT32) (LbaLength - BlockOffset);\r
+    Status    = EFI_BAD_BUFFER_SIZE;\r
+  }\r
+  //\r
+  // Write data\r
+  //\r
+  CopyMem ((UINT8 *) (LbaAddress + BlockOffset), Buffer, (UINTN) (*NumBytes));\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+FvbEraseBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Erases and initializes a firmware volume block\r
+\r
+Arguments:\r
+  Instance              - The FV instance to be erased\r
+  Lba                   - The logical block index to be erased\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The erase request was successfully completed\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written. Firmware device may have been\r
+                          partially erased\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+\r
+  EFI_FVB_ATTRIBUTES  Attributes;\r
+  UINTN               LbaAddress;\r
+  UINTN               LbaLength;\r
+  EFI_STATUS          Status;\r
+  UINT8               Data;\r
+\r
+  //\r
+  // Check if the FV is write enabled\r
+  //\r
+  FvbGetVolumeAttributes (Instance, &Attributes, Global, Virtual);\r
+\r
+  if ((Attributes & EFI_FVB2_WRITE_STATUS) == 0) {\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+  //\r
+  // Get the starting address of the block for erase.\r
+  //\r
+  Status = FvbGetLbaAddress (Instance, Lba, &LbaAddress, &LbaLength, NULL, Global, Virtual);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if ((Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {\r
+    Data = 0xFF;\r
+  } else {\r
+    Data = 0x0;\r
+  }\r
+\r
+  SetMem ((UINT8 *) LbaAddress, LbaLength, Data);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+FvbEraseCustomBlockRange (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              StartLba,\r
+  IN UINTN                                OffsetStartLba,\r
+  IN EFI_LBA                              LastLba,\r
+  IN UINTN                                OffsetLastLba,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Erases and initializes a specified range of a firmware volume\r
+\r
+Arguments:\r
+  Instance              - The FV instance to be erased\r
+  StartLba              - The starting logical block index to be erased\r
+  OffsetStartLba        - Offset into the starting block at which to \r
+                          begin erasing\r
+  LastLba               - The last logical block index to be erased\r
+  OffsetStartLba        - Offset into the last block at which to end erasing\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was erased successfully\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written. Firmware device may have been\r
+                          partially erased\r
+  EFI_INVALID_PARAMETER - Instance not found\r
+\r
+--*/\r
+{\r
+  EFI_LBA Index;\r
+  UINTN   LbaSize;\r
+  UINTN   ScratchLbaSizeData;\r
+  EFI_STATUS Status;\r
+\r
+  //\r
+  // First LBA\r
+  //\r
+  Status = FvbGetLbaAddress (Instance, StartLba, NULL, &LbaSize, NULL, Global, Virtual);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Use the scratch space as the intermediate buffer to transfer data\r
+  // Back up the first LBA in scratch space.\r
+  //\r
+  FvbReadBlock (Instance, StartLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
+\r
+  //\r
+  // erase now\r
+  //\r
+  FvbEraseBlock (Instance, StartLba, Global, Virtual);\r
+  ScratchLbaSizeData = OffsetStartLba;\r
+\r
+  //\r
+  // write the data back to the first block\r
+  //\r
+  if (ScratchLbaSizeData > 0) {\r
+    Status = FvbWriteBlock (Instance, StartLba, 0, &ScratchLbaSizeData, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+  //\r
+  // Middle LBAs\r
+  //\r
+  if (LastLba > (StartLba + 1)) {\r
+    for (Index = (StartLba + 1); Index <= (LastLba - 1); Index++) {\r
+      FvbEraseBlock (Instance, Index, Global, Virtual);\r
+    }\r
+  }\r
+  //\r
+  // Last LBAs, the same as first LBAs\r
+  //\r
+  if (LastLba > StartLba) {\r
+    Status = FvbGetLbaAddress (Instance, LastLba, NULL, &LbaSize, NULL, Global, Virtual);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+    FvbReadBlock (Instance, LastLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual);\r
+    FvbEraseBlock (Instance, LastLba, Global, Virtual);\r
+  }\r
+\r
+  ScratchLbaSizeData = LbaSize - (OffsetLastLba + 1);\r
+\r
+  if (ScratchLbaSizeData > 0) {\r
+    Status = FvbWriteBlock (\r
+              Instance,\r
+              LastLba,\r
+              (OffsetLastLba + 1),\r
+              &ScratchLbaSizeData,\r
+              Global->FvbScratchSpace[Virtual] + OffsetLastLba + 1,\r
+              Global,\r
+              Virtual\r
+              );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+FvbSetVolumeAttributes (\r
+  IN UINTN                                Instance,\r
+  IN OUT EFI_FVB_ATTRIBUTES               *Attributes,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Modifies the current settings of the firmware volume according to the \r
+  input parameter, and returns the new setting of the volume\r
+\r
+Arguments:\r
+  Instance              - The FV instance whose attributes is going to be \r
+                          modified\r
+  Attributes            - On input, it is a pointer to EFI_FVB_ATTRIBUTES \r
+                          containing the desired firmware volume settings.\r
+                          On successful return, it contains the new settings\r
+                          of the firmware volume\r
+  Global                - Pointer to ESAL_FWB_GLOBAL that contains all\r
+                          instance data\r
+  Virtual               - Whether CPU is in virtual or physical mode\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+  EFI_ACCESS_DENIED     - The volume setting is locked and cannot be modified\r
+  EFI_INVALID_PARAMETER - Instance not found, or The attributes requested are\r
+                          in conflict with the capabilities as declared in the\r
+                          firmware volume header\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_INSTANCE *FwhInstance;\r
+  EFI_FVB_ATTRIBUTES  OldAttributes;\r
+  EFI_FVB_ATTRIBUTES  *AttribPtr;\r
+  UINT32              Capabilities;\r
+  UINT32              OldStatus;\r
+  UINT32              NewStatus;\r
+  EFI_STATUS          Status;\r
+  EFI_FVB_ATTRIBUTES  UnchangedAttributes;\r
+\r
+\r
+  //\r
+  // Find the right instance of the FVB private data\r
+  //\r
+  Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  AttribPtr     = (EFI_FVB_ATTRIBUTES *) &(FwhInstance->VolumeHeader.Attributes);\r
+  OldAttributes = *AttribPtr;\r
+  Capabilities  = OldAttributes & (EFI_FVB2_READ_DISABLED_CAP | \\r
+                                   EFI_FVB2_READ_ENABLED_CAP | \\r
+                                   EFI_FVB2_WRITE_DISABLED_CAP | \\r
+                                   EFI_FVB2_WRITE_ENABLED_CAP | \\r
+                                   EFI_FVB2_LOCK_CAP \\r
+                                   );\r
+\r
+  OldStatus     = OldAttributes & EFI_FVB2_STATUS;\r
+  NewStatus     = *Attributes & EFI_FVB2_STATUS;\r
+  UnchangedAttributes = EFI_FVB2_READ_DISABLED_CAP  | \\r
+                        EFI_FVB2_READ_ENABLED_CAP   | \\r
+                        EFI_FVB2_WRITE_DISABLED_CAP | \\r
+                        EFI_FVB2_WRITE_ENABLED_CAP  | \\r
+                        EFI_FVB2_LOCK_CAP           | \\r
+                        EFI_FVB2_STICKY_WRITE       | \\r
+                        EFI_FVB2_MEMORY_MAPPED      | \\r
+                        EFI_FVB2_ERASE_POLARITY     | \\r
+                        EFI_FVB2_READ_LOCK_CAP      | \\r
+                        EFI_FVB2_WRITE_LOCK_CAP     | \\r
+                        EFI_FVB2_ALIGNMENT;\r
+\r
+  //\r
+  // Some attributes of FV is read only can *not* be set\r
+  //\r
+  if ((OldAttributes & UnchangedAttributes) ^ (*Attributes & UnchangedAttributes)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // If firmware volume is locked, no status bit can be updated\r
+  //\r
+  if (OldAttributes & EFI_FVB2_LOCK_STATUS) {\r
+    if (OldStatus ^ NewStatus) {\r
+      return EFI_ACCESS_DENIED;\r
+    }\r
+  }\r
+  //\r
+  // Test read disable\r
+  //\r
+  if ((Capabilities & EFI_FVB2_READ_DISABLED_CAP) == 0) {\r
+    if ((NewStatus & EFI_FVB2_READ_STATUS) == 0) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // Test read enable\r
+  //\r
+  if ((Capabilities & EFI_FVB2_READ_ENABLED_CAP) == 0) {\r
+    if (NewStatus & EFI_FVB2_READ_STATUS) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // Test write disable\r
+  //\r
+  if ((Capabilities & EFI_FVB2_WRITE_DISABLED_CAP) == 0) {\r
+    if ((NewStatus & EFI_FVB2_WRITE_STATUS) == 0) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // Test write enable\r
+  //\r
+  if ((Capabilities & EFI_FVB2_WRITE_ENABLED_CAP) == 0) {\r
+    if (NewStatus & EFI_FVB2_WRITE_STATUS) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+  //\r
+  // Test lock\r
+  //\r
+  if ((Capabilities & EFI_FVB2_LOCK_CAP) == 0) {\r
+    if (NewStatus & EFI_FVB2_LOCK_STATUS) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+\r
+  *AttribPtr  = (*AttribPtr) & (0xFFFFFFFF & (~EFI_FVB2_STATUS));\r
+  *AttribPtr  = (*AttribPtr) | NewStatus;\r
+  *Attributes = *AttribPtr;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+//\r
+// FVB protocol APIs\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetPhysicalAddress (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT EFI_PHYSICAL_ADDRESS                        *Address\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Retrieves the physical address of the device.\r
+\r
+Arguments:\r
+\r
+  This                  - Calling context\r
+  Address               - Output buffer containing the address.\r
+\r
+Returns:\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbGetPhysicalAddress (FvbDevice->Instance, Address, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetBlockSize (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN  EFI_LBA                                     Lba,\r
+  OUT UINTN                                       *BlockSize,\r
+  OUT UINTN                                       *NumOfBlocks\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Retrieve the size of a logical block\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  Lba                   - Indicates which block to return the size for.\r
+  BlockSize             - A pointer to a caller allocated UINTN in which\r
+                          the size of the block is returned\r
+  NumOfBlocks           - a pointer to a caller allocated UINTN in which the\r
+                          number of consecutive blocks starting with Lba is\r
+                          returned. All blocks in this range have a size of\r
+                          BlockSize\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was read successfully and \r
+                          contents are in Buffer\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbGetLbaAddress (\r
+          FvbDevice->Instance,\r
+          Lba,\r
+          NULL,\r
+          BlockSize,\r
+          NumOfBlocks,\r
+          mFvbModuleGlobal,\r
+          EfiGoneVirtual ()\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetAttributes (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT EFI_FVB_ATTRIBUTES                          *Attributes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Retrieves Volume attributes.  No polarity translations are done.\r
+\r
+Arguments:\r
+    This                - Calling context\r
+    Attributes          - output buffer which contains attributes\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbGetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolSetAttributes (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN OUT EFI_FVB_ATTRIBUTES                       *Attributes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Sets Volume attributes. No polarity translations are done.\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  Attributes            - output buffer which contains attributes\r
+\r
+Returns: \r
+  EFI_SUCCESS           - Successfully returns\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbSetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolEraseBlocks (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *This,\r
+  ...  \r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The EraseBlock() function erases one or more blocks as denoted by the \r
+  variable argument list. The entire parameter list of blocks must be verified\r
+  prior to erasing any blocks.  If a block is requested that does not exist \r
+  within the associated firmware volume (it has a larger index than the last \r
+  block of the firmware volume), the EraseBlock() function must return\r
+  EFI_INVALID_PARAMETER without modifying the contents of the firmware volume.\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  ...                   - Starting LBA followed by Number of Lba to erase. \r
+                          a -1 to terminate the list.\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The erase request was successfully completed\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written. Firmware device may have been\r
+                          partially erased\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+  EFI_FW_VOL_INSTANCE     *FwhInstance;\r
+  UINTN                   NumOfBlocks;\r
+  VA_LIST                 args;\r
+  EFI_LBA                 StartingLba;\r
+  UINTN                   NumOfLba;\r
+  EFI_STATUS              Status;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  Status    = GetFvbInstance (FvbDevice->Instance, mFvbModuleGlobal, &FwhInstance, EfiGoneVirtual ());\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  NumOfBlocks = FwhInstance->NumOfBlocks;\r
+\r
+  VA_START (args, This);\r
+\r
+  do {\r
+    StartingLba = VA_ARG (args, EFI_LBA);\r
+    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {\r
+      break;\r
+    }\r
+\r
+    NumOfLba = VA_ARG (args, UINT32);\r
+\r
+    //\r
+    // Check input parameters\r
+    //\r
+    if (NumOfLba == 0) {\r
+      VA_END (args);\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if ((StartingLba + NumOfLba) > NumOfBlocks) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  } while (1);\r
+\r
+  VA_END (args);\r
+\r
+  VA_START (args, This);\r
+  do {\r
+    StartingLba = VA_ARG (args, EFI_LBA);\r
+    if (StartingLba == EFI_LBA_LIST_TERMINATOR) {\r
+      break;\r
+    }\r
+\r
+    NumOfLba = VA_ARG (args, UINT32);\r
+\r
+    while (NumOfLba > 0) {\r
+      Status = FvbEraseBlock (FvbDevice->Instance, StartingLba, mFvbModuleGlobal, EfiGoneVirtual ());\r
+      if (EFI_ERROR (Status)) {\r
+        VA_END (args);\r
+        return Status;\r
+      }\r
+\r
+      StartingLba++;\r
+      NumOfLba--;\r
+    }\r
+\r
+  } while (1);\r
+\r
+  VA_END (args);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolWrite (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN EFI_LBA                                      Lba,\r
+  IN UINTN                                        Offset,\r
+  IN OUT UINTN                                    *NumBytes,\r
+  IN UINT8                                        *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Writes data beginning at Lba:Offset from FV. The write terminates either\r
+  when *NumBytes of data have been written, or when a block boundary is\r
+  reached.  *NumBytes is updated to reflect the actual number of bytes\r
+  written. The write opertion does not include erase. This routine will\r
+  attempt to write only the specified bytes. If the writes do not stick,\r
+  it will return an error.\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  Lba                   - Block in which to begin write\r
+  Offset                - Offset in the block at which to begin write\r
+  NumBytes              - On input, indicates the requested write size. On\r
+                          output, indicates the actual number of bytes written\r
+  Buffer                - Buffer containing source data for the write.\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was written successfully\r
+  EFI_BAD_BUFFER_SIZE   - Write attempted across a LBA boundary. On output,\r
+                          NumBytes contains the total number of bytes\r
+                          actually written\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written\r
+  EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL\r
+\r
+--*/\r
+{\r
+\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbWriteBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolRead (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN EFI_LBA                                      Lba,\r
+  IN UINTN                                        Offset,\r
+  IN OUT UINTN                                    *NumBytes,\r
+  IN UINT8                                        *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Reads data beginning at Lba:Offset from FV. The Read terminates either\r
+  when *NumBytes of data have been read, or when a block boundary is\r
+  reached.  *NumBytes is updated to reflect the actual number of bytes\r
+  written. The write opertion does not include erase. This routine will\r
+  attempt to write only the specified bytes. If the writes do not stick,\r
+  it will return an error.\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  Lba                   - Block in which to begin Read\r
+  Offset                - Offset in the block at which to begin Read\r
+  NumBytes              - On input, indicates the requested write size. On\r
+                          output, indicates the actual number of bytes Read\r
+  Buffer                - Buffer containing source data for the Read.\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was read successfully and \r
+                          contents are in Buffer\r
+  EFI_BAD_BUFFER_SIZE   - Read attempted across a LBA boundary. On output,\r
+                          NumBytes contains the total number of bytes returned\r
+                          in Buffer\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the ReadDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be read\r
+  EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL\r
+\r
+--*/\r
+{\r
+\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbReadBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer, mFvbModuleGlobal, EfiGoneVirtual ());\r
+}\r
+//\r
+// FVB Extension Protocols\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+FvbExtendProtocolEraseCustomBlockRange (\r
+  IN EFI_FVB_EXTENSION_PROTOCOL           *This,\r
+  IN EFI_LBA                              StartLba,\r
+  IN UINTN                                OffsetStartLba,\r
+  IN EFI_LBA                              LastLba,\r
+  IN UINTN                                OffsetLastLba\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Erases and initializes a specified range of a firmware volume\r
+\r
+Arguments:\r
+  This                  - Calling context\r
+  StartLba              - The starting logical block index to be erased\r
+  OffsetStartLba        - Offset into the starting block at which to \r
+                          begin erasing\r
+  LastLba               - The last logical block index to be erased\r
+  OffsetStartLba        - Offset into the last block at which to end erasing\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume was erased successfully\r
+  EFI_ACCESS_DENIED     - The firmware volume is in the WriteDisabled state\r
+  EFI_DEVICE_ERROR      - The block device is not functioning correctly and \r
+                          could not be written. Firmware device may have been\r
+                          partially erased\r
+\r
+--*/\r
+{\r
+  EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;\r
+\r
+  FvbDevice = FVB_EXTEND_DEVICE_FROM_THIS (This);\r
+\r
+  return FvbEraseCustomBlockRange (\r
+          FvbDevice->Instance,\r
+          StartLba,\r
+          OffsetStartLba,\r
+          LastLba,\r
+          OffsetLastLba,\r
+          mFvbModuleGlobal,\r
+          EfiGoneVirtual ()\r
+          );\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+ValidateFvHeader (\r
+  EFI_FIRMWARE_VOLUME_HEADER            *FwVolHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Check the integrity of firmware volume header\r
+\r
+Arguments:\r
+  FwVolHeader           - A pointer to a firmware volume header\r
+\r
+Returns: \r
+  EFI_SUCCESS           - The firmware volume is consistent\r
+  EFI_NOT_FOUND         - The firmware volume has corrupted. So it is not an FV\r
+\r
+--*/\r
+{\r
+  UINT16  *Ptr;\r
+  UINT16  HeaderLength;\r
+  UINT16  Checksum;\r
+\r
+  //\r
+  // Verify the header revision, header signature, length\r
+  // Length of FvBlock cannot be 2**64-1\r
+  // HeaderLength cannot be an odd number\r
+  //\r
+  if ((FwVolHeader->Revision != EFI_FVH_REVISION) ||\r
+      (FwVolHeader->Signature != EFI_FVH_SIGNATURE) ||\r
+      (FwVolHeader->FvLength == ((UINTN) -1)) ||\r
+      ((FwVolHeader->HeaderLength & 0x01) != 0)\r
+      ) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+  //\r
+  // Verify the header checksum\r
+  //\r
+  HeaderLength  = (UINT16) (FwVolHeader->HeaderLength / 2);\r
+  Ptr           = (UINT16 *) FwVolHeader;\r
+  Checksum      = 0;\r
+  while (HeaderLength > 0) {\r
+    Checksum = Checksum + (*Ptr);\r
+    HeaderLength--;\r
+    Ptr++;\r
+  }\r
+\r
+  if (Checksum != 0) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  This function does common initialization for FVB services\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_FW_VOL_INSTANCE                 *FwhInstance;\r
+  EFI_FIRMWARE_VOLUME_HEADER          *FwVolHeader;\r
+  EFI_DXE_SERVICES                    *DxeServices;\r
+  EFI_GCD_MEMORY_SPACE_DESCRIPTOR     Descriptor;\r
+  UINT32                              BufferSize;\r
+  EFI_FV_BLOCK_MAP_ENTRY              *PtrBlockMapEntry;\r
+  EFI_HANDLE                          FwbHandle;\r
+  EFI_FW_VOL_BLOCK_DEVICE             *FvbDevice;\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  *OldFwbInterface;\r
+  EFI_DEVICE_PATH_PROTOCOL            *TempFwbDevicePath;\r
+  FV_DEVICE_PATH                      TempFvbDevicePathData;\r
+  UINT32                              MaxLbaSize;\r
+  EFI_PHYSICAL_ADDRESS                BaseAddress;\r
+  UINT64                              Length;\r
+  UINTN                               NumOfBlocks;\r
+  EFI_PEI_HOB_POINTERS                FvHob;\r
+\r
+   //\r
+  // Get the DXE services table\r
+  //\r
+  DxeServices = gDS;\r
+\r
+  //\r
+  // Allocate runtime services data for global variable, which contains\r
+  // the private data of all firmware volume block instances\r
+  //\r
+  Status = gBS->AllocatePool (\r
+                  EfiRuntimeServicesData,\r
+                  sizeof (ESAL_FWB_GLOBAL),\r
+                  (VOID**) &mFvbModuleGlobal\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Calculate the total size for all firmware volume block instances\r
+  //\r
+  BufferSize            = 0;\r
+\r
+  FvHob.Raw = GetHobList ();\r
+  while ((FvHob.Raw = GetNextHob (EFI_HOB_TYPE_FV, FvHob.Raw)) != NULL) {\r
+    BaseAddress = FvHob.FirmwareVolume->BaseAddress;\r
+    Length      = FvHob.FirmwareVolume->Length;\r
+    //\r
+    // Check if it is a "real" flash\r
+    //\r
+    Status = DxeServices->GetMemorySpaceDescriptor (\r
+                            BaseAddress,\r
+                            &Descriptor\r
+                            );\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) {\r
+      FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+      continue;\r
+    }\r
+\r
+    FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;\r
+    Status      = ValidateFvHeader (FwVolHeader);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Get FvbInfo\r
+      //\r
+      Status = GetFvbInfo (Length, &FwVolHeader);\r
+      if (EFI_ERROR (Status)) {\r
+        FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+        continue;\r
+      }\r
+    }\r
+\r
+    BufferSize += (sizeof (EFI_FW_VOL_INSTANCE) + FwVolHeader->HeaderLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER));\r
+    FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+  }\r
+\r
+  //\r
+  // Only need to allocate once. There is only one copy of physical memory for\r
+  // the private data of each FV instance. But in virtual mode or in physical\r
+  // mode, the address of the the physical memory may be different.\r
+  //\r
+  Status = gBS->AllocatePool (\r
+                  EfiRuntimeServicesData,\r
+                  BufferSize,\r
+                  (VOID**) &mFvbModuleGlobal->FvInstance[FVB_PHYSICAL]\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Make a virtual copy of the FvInstance pointer.\r
+  //\r
+  FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];\r
+  mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] = FwhInstance;\r
+\r
+  mFvbModuleGlobal->NumFv                   = 0;\r
+  MaxLbaSize = 0;\r
+\r
+  FvHob.Raw = GetHobList ();\r
+  while (NULL != (FvHob.Raw = GetNextHob (EFI_HOB_TYPE_FV, FvHob.Raw))) {\r
+    BaseAddress = FvHob.FirmwareVolume->BaseAddress;\r
+    Length      = FvHob.FirmwareVolume->Length;\r
+    //\r
+    // Check if it is a "real" flash\r
+    //\r
+    Status = DxeServices->GetMemorySpaceDescriptor (\r
+                            BaseAddress,\r
+                            &Descriptor\r
+                            );\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) {\r
+      FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+      continue;\r
+    }\r
+\r
+    FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;\r
+    Status      = ValidateFvHeader (FwVolHeader);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Get FvbInfo to provide in FwhInstance.\r
+      //\r
+      Status = GetFvbInfo (Length, &FwVolHeader);\r
+      if (EFI_ERROR (Status)) {\r
+        FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+        continue;\r
+      }\r
+      //\r
+      //  Write healthy FV header back.\r
+      //\r
+      CopyMem (\r
+        (VOID *) (UINTN) BaseAddress,\r
+        (VOID *) FwVolHeader,\r
+        FwVolHeader->HeaderLength\r
+        );\r
+    }\r
+\r
+    FwhInstance->FvBase[FVB_PHYSICAL] = (UINTN) BaseAddress;\r
+    FwhInstance->FvBase[FVB_VIRTUAL]  = (UINTN) BaseAddress;\r
+\r
+    CopyMem ((UINTN *) &(FwhInstance->VolumeHeader), (UINTN *) FwVolHeader, FwVolHeader->HeaderLength);\r
+    FwVolHeader = &(FwhInstance->VolumeHeader);\r
+    EfiInitializeLock (&(FwhInstance->FvbDevLock), TPL_HIGH_LEVEL);\r
+\r
+    NumOfBlocks = 0;\r
+\r
+    for (PtrBlockMapEntry = FwVolHeader->BlockMap; PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {\r
+      //\r
+      // Get the maximum size of a block. The size will be used to allocate\r
+      // buffer for Scratch space, the intermediate buffer for FVB extension\r
+      // protocol\r
+      //\r
+      if (MaxLbaSize < PtrBlockMapEntry->Length) {\r
+        MaxLbaSize = PtrBlockMapEntry->Length;\r
+      }\r
+\r
+      NumOfBlocks = NumOfBlocks + PtrBlockMapEntry->NumBlocks;\r
+    }\r
+    //\r
+    // The total number of blocks in the FV.\r
+    //\r
+    FwhInstance->NumOfBlocks = NumOfBlocks;\r
+\r
+    //\r
+    // Add a FVB Protocol Instance\r
+    //\r
+    Status = gBS->AllocatePool (\r
+                    EfiRuntimeServicesData,\r
+                    sizeof (EFI_FW_VOL_BLOCK_DEVICE),\r
+                    (VOID**) &FvbDevice\r
+                    );\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    CopyMem (FvbDevice, &mFvbDeviceTemplate, sizeof (EFI_FW_VOL_BLOCK_DEVICE));\r
+\r
+    FvbDevice->Instance = mFvbModuleGlobal->NumFv;\r
+    mFvbModuleGlobal->NumFv++;\r
+\r
+    //\r
+    // Set up the devicepath\r
+    //\r
+    FvbDevice->DevicePath.MemMapDevPath.StartingAddress = BaseAddress;\r
+    FvbDevice->DevicePath.MemMapDevPath.EndingAddress   = BaseAddress + (FwVolHeader->FvLength - 1);\r
+\r
+    //\r
+    // Find a handle with a matching device path that has supports FW Block protocol\r
+    //\r
+    TempFwbDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) &TempFvbDevicePathData;\r
+    CopyMem (TempFwbDevicePath, &FvbDevice->DevicePath, sizeof (FV_DEVICE_PATH));\r
+    Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, &TempFwbDevicePath, &FwbHandle);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // LocateDevicePath fails so install a new interface and device path\r
+      //\r
+      FwbHandle = NULL;\r
+      Status = gBS->InstallMultipleProtocolInterfaces (\r
+                      &FwbHandle,\r
+                      &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                      &FvbDevice->FwVolBlockInstance,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      &FvbDevice->DevicePath,\r
+                      NULL\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+    } else if (EfiIsDevicePathEnd (TempFwbDevicePath)) {\r
+      //\r
+      // Device allready exists, so reinstall the FVB protocol\r
+      //\r
+      Status = gBS->HandleProtocol (\r
+                      FwbHandle,\r
+                      &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                      (VOID**)&OldFwbInterface\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+\r
+      Status = gBS->ReinstallProtocolInterface (\r
+                      FwbHandle,\r
+                      &gEfiFirmwareVolumeBlockProtocolGuid,\r
+                      OldFwbInterface,\r
+                      &FvbDevice->FwVolBlockInstance\r
+                      );\r
+      ASSERT_EFI_ERROR (Status);\r
+\r
+    } else {\r
+      //\r
+      // There was a FVB protocol on an End Device Path node\r
+      //\r
+      ASSERT (FALSE);\r
+    }\r
+    //\r
+    // Install FVB Extension Protocol on the same handle\r
+    //\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &FwbHandle,\r
+                    &gEfiFvbExtensionProtocolGuid,\r
+                    &FvbDevice->FvbExtension,\r
+                    &gEfiAlternateFvBlockGuid,\r
+                    NULL,\r
+                    NULL\r
+                    );\r
+\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+    FwhInstance = (EFI_FW_VOL_INSTANCE *)\r
+      (\r
+        (UINTN) ((UINT8 *) FwhInstance) + FwVolHeader->HeaderLength +\r
+          (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))\r
+      );\r
+\r
+    FvHob.Raw = GET_NEXT_HOB (FvHob);\r
+  }\r
+\r
+  //\r
+  // Allocate for scratch space, an intermediate buffer for FVB extention\r
+  //\r
+  Status = gBS->AllocatePool (\r
+                  EfiRuntimeServicesData,\r
+                  MaxLbaSize,\r
+                  (VOID**)&mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL]\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL] = mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL];\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c b/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c
new file mode 100644 (file)
index 0000000..6670359
--- /dev/null
@@ -0,0 +1,156 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  FvbInfo.c\r
+\r
+Abstract:\r
+\r
+  Defines data structure that is the volume header found.These data is intent\r
+  to decouple FVB driver with FV header.\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include <Guid/EventGroup.h>\r
+#include <Protocol/FvbExtension.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+#include <Guid/AlternateFvBlock.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DxeServicesTableLib.h>\r
+#include <Library/UefiRuntimeLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Guid/FirmwareFileSystem2.h>\r
+#include <Guid/SystemNvDataGuid.h>\r
+\r
+typedef struct {\r
+  UINT64                      FvLength;\r
+  EFI_FIRMWARE_VOLUME_HEADER  FvbInfo;\r
+  //\r
+  // EFI_FV_BLOCK_MAP_ENTRY    ExtraBlockMap[n];//n=0\r
+  //\r
+  EFI_FV_BLOCK_MAP_ENTRY      End[1];\r
+} EFI_FVB_MEDIA_INFO;\r
+\r
+EFI_FVB_MEDIA_INFO  mPlatformFvbMediaInfo[] = {\r
+  //\r
+  // Recovery BOIS FVB\r
+  //\r
+  {\r
+    FixedPcdGet32 (PcdUnixFlashFvRecoverySize),\r
+    {\r
+      {\r
+        0,\r
+      },  // ZeroVector[16]\r
+      EFI_FIRMWARE_FILE_SYSTEM2_GUID,\r
+      FixedPcdGet32 (PcdUnixFlashFvRecoverySize),\r
+      EFI_FVH_SIGNATURE,\r
+      EFI_FVB2_READ_ENABLED_CAP |\r
+        EFI_FVB2_READ_STATUS |\r
+        EFI_FVB2_WRITE_ENABLED_CAP |\r
+        EFI_FVB2_WRITE_STATUS |\r
+        EFI_FVB2_ERASE_POLARITY,\r
+      sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),\r
+      0,  // CheckSum\r
+      0,  // ExtHeaderOffset\r
+      {\r
+        0,\r
+      },  // Reserved[1]\r
+      1,  // Revision\r
+      {\r
+        {\r
+          FixedPcdGet32 (PcdUnixFlashFvRecoverySize)/FixedPcdGet32 (PcdUnixFirmwareBlockSize),\r
+          FixedPcdGet32 (PcdUnixFirmwareBlockSize),\r
+        }\r
+      }\r
+    },\r
+    {\r
+      {\r
+        0,\r
+        0\r
+      }\r
+    }\r
+  },\r
+  //\r
+  // Systen NvStorage FVB\r
+  //\r
+  {\r
+    FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \\r
+    FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \\r
+    FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \\r
+    FixedPcdGet32 (PcdUnixFlashNvStorageEventLogSize),\r
+    {\r
+      {\r
+        0,\r
+      },  // ZeroVector[16]\r
+      EFI_SYSTEM_NV_DATA_HOB_GUID,\r
+      FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \\r
+      FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \\r
+      FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \\r
+      FixedPcdGet32 (PcdUnixFlashNvStorageEventLogSize),\r
+      EFI_FVH_SIGNATURE,\r
+      EFI_FVB2_READ_ENABLED_CAP |\r
+        EFI_FVB2_READ_STATUS |\r
+        EFI_FVB2_WRITE_ENABLED_CAP |\r
+        EFI_FVB2_WRITE_STATUS |\r
+        EFI_FVB2_ERASE_POLARITY,\r
+      sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),\r
+      0,  // CheckSum\r
+      0,  // ExtHeaderOffset\r
+      {\r
+        0,\r
+      },  // Reserved[1]\r
+      1,  // Revision\r
+      {\r
+        {\r
+          (FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \\r
+          FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \\r
+          FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \\r
+          FixedPcdGet32 (PcdUnixFlashNvStorageEventLogSize)) / FixedPcdGet32 (PcdUnixFirmwareBlockSize),\r
+          FixedPcdGet32 (PcdUnixFirmwareBlockSize),\r
+        }\r
+      }\r
+    },\r
+    {\r
+      {\r
+        0,\r
+        0\r
+      }\r
+    }\r
+  }\r
+};\r
+\r
+EFI_STATUS\r
+GetFvbInfo (\r
+  IN  UINT64                        FvLength,\r
+  OUT EFI_FIRMWARE_VOLUME_HEADER    **FvbInfo\r
+  )\r
+{\r
+  UINTN Index;\r
+\r
+  for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {\r
+    if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {\r
+      *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;\r
+      return EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
diff --git a/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h b/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h
new file mode 100644 (file)
index 0000000..6f949d3
--- /dev/null
@@ -0,0 +1,238 @@
+/*++\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
+\r
+  FwBlockService.h\r
+  \r
+Abstract:\r
+\r
+  Firmware volume block driver for Intel Firmware Hub (FWH) device\r
+\r
+--*/\r
+\r
+#ifndef _FW_BLOCK_SERVICE_H\r
+#define _FW_BLOCK_SERVICE_H\r
+\r
+//\r
+// BugBug: Add documentation here for data structure!!!!\r
+//\r
+#define FVB_PHYSICAL  0\r
+#define FVB_VIRTUAL   1\r
+\r
+typedef struct {\r
+  EFI_LOCK                    FvbDevLock;\r
+  UINTN                       FvBase[2];\r
+  UINTN                       NumOfBlocks;\r
+  EFI_FIRMWARE_VOLUME_HEADER  VolumeHeader;\r
+} EFI_FW_VOL_INSTANCE;\r
+\r
+typedef struct {\r
+  UINT32              NumFv;\r
+  EFI_FW_VOL_INSTANCE *FvInstance[2];\r
+  UINT8               *FvbScratchSpace[2];\r
+} ESAL_FWB_GLOBAL;\r
+\r
+//\r
+// Fvb Protocol instance data\r
+//\r
+#define FVB_DEVICE_FROM_THIS(a)         CR (a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)\r
+#define FVB_EXTEND_DEVICE_FROM_THIS(a)  CR (a, EFI_FW_VOL_BLOCK_DEVICE, FvbExtension, FVB_DEVICE_SIGNATURE)\r
+#define FVB_DEVICE_SIGNATURE            EFI_SIGNATURE_32 ('F', 'V', 'B', 'N')\r
+\r
+typedef struct {\r
+  MEMMAP_DEVICE_PATH        MemMapDevPath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevPath;\r
+} FV_DEVICE_PATH;\r
+\r
+typedef struct {\r
+  UINTN                               Signature;\r
+  FV_DEVICE_PATH                      DevicePath;\r
+  UINTN                               Instance;\r
+  EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL  FwVolBlockInstance;\r
+  EFI_FVB_EXTENSION_PROTOCOL          FvbExtension;\r
+} EFI_FW_VOL_BLOCK_DEVICE;\r
+\r
+EFI_STATUS\r
+GetFvbInfo (\r
+  IN  UINT64                            FvLength,\r
+  OUT EFI_FIRMWARE_VOLUME_HEADER        **FvbInfo\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbReadBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN UINTN                                BlockOffset,\r
+  IN OUT UINTN                            *NumBytes,\r
+  IN UINT8                                *Buffer,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbWriteBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN UINTN                                BlockOffset,\r
+  IN OUT UINTN                            *NumBytes,\r
+  IN UINT8                                *Buffer,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbEraseBlock (\r
+  IN UINTN                                Instance,\r
+  IN EFI_LBA                              Lba,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbSetVolumeAttributes (\r
+  IN UINTN                                Instance,\r
+  IN OUT EFI_FVB_ATTRIBUTES               *Attributes,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbGetVolumeAttributes (\r
+  IN UINTN                                Instance,\r
+  OUT EFI_FVB_ATTRIBUTES                  *Attributes,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbGetPhysicalAddress (\r
+  IN UINTN                                Instance,\r
+  OUT EFI_PHYSICAL_ADDRESS                *Address,\r
+  IN ESAL_FWB_GLOBAL                      *Global,\r
+  IN BOOLEAN                              Virtual\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbInitialize (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+;\r
+\r
+\r
+VOID\r
+EFIAPI\r
+FvbClassAddressChangeEvent (\r
+  IN EFI_EVENT        Event,\r
+  IN VOID             *Context\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+FvbGetLbaAddress (\r
+  IN  UINTN                               Instance,\r
+  IN  EFI_LBA                             Lba,\r
+  OUT UINTN                               *LbaAddress,\r
+  OUT UINTN                               *LbaLength,\r
+  OUT UINTN                               *NumOfBlocks,\r
+  IN  ESAL_FWB_GLOBAL                     *Global,\r
+  IN  BOOLEAN                             Virtual\r
+  )\r
+;\r
+\r
+//\r
+// Protocol APIs\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetAttributes (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT EFI_FVB_ATTRIBUTES                          *Attributes\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolSetAttributes (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN OUT EFI_FVB_ATTRIBUTES                       *Attributes\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetPhysicalAddress (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  OUT EFI_PHYSICAL_ADDRESS                        *Address\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolGetBlockSize (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN  EFI_LBA                                     Lba,\r
+  OUT UINTN                                       *BlockSize,\r
+  OUT UINTN                                       *NumOfBlocks\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolRead (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN EFI_LBA                                      Lba,\r
+  IN UINTN                                        Offset,\r
+  IN OUT UINTN                                    *NumBytes,\r
+  IN UINT8                                        *Buffer\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolWrite (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL           *This,\r
+  IN EFI_LBA                                      Lba,\r
+  IN UINTN                                        Offset,\r
+  IN OUT UINTN                                    *NumBytes,\r
+  IN UINT8                                        *Buffer\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbProtocolEraseBlocks (\r
+  IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL    *This,\r
+  ...\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+FvbExtendProtocolEraseCustomBlockRange (\r
+  IN EFI_FVB_EXTENSION_PROTOCOL           *This,\r
+  IN EFI_LBA                              StartLba,\r
+  IN UINTN                                OffsetStartLba,\r
+  IN EFI_LBA                              LastLba,\r
+  IN UINTN                                OffsetLastLba\r
+  )\r
+;\r
+\r
+#endif\r
diff --git a/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf b/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf
new file mode 100644 (file)
index 0000000..52cc62e
--- /dev/null
@@ -0,0 +1,90 @@
+#/** @file\r
+# Component description file for Unix Fimware Volume Block DXE driver module.\r
+#\r
+# This DXE runtime driver implements and produces the Fimware Volue Block Protocol on \r
+#  Unix emulator.\r
+# Copyright (c) 2008, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = FwBlockService\r
+  FILE_GUID                      = f42fd042-8985-11db-a7db-0040d02b1835\r
+  MODULE_TYPE                    = DXE_RUNTIME_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = FvbInitialize\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.Ia32]\r
+  FvbInfo.c\r
+  FWBlockService.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  HobLib\r
+  DebugLib\r
+  UefiRuntimeLib\r
+  DxeServicesTableLib\r
+  BaseLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+\r
+\r
+[Guids]\r
+  gEfiEventVirtualAddressChangeGuid             # ALWAYS_CONSUMED  Create Event: EVENT_GROUP_GUID\r
+  gEfiAlternateFvBlockGuid                      # ALWAYS_PRODUCED\r
+\r
+\r
+[Protocols]\r
+  gEfiFvbExtensionProtocolGuid                  # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL SOMETIMES_PRODUCED\r
+\r
+\r
+[FixedPcd.common]\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareBlockSize\r
+\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoveryBase\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoverySize\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogBase\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize\r
+\r
+[Pcd.common]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa b/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa
new file mode 100644 (file)
index 0000000..3792a00
--- /dev/null
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>FwBlockService</ModuleName>\r
+    <ModuleType>DXE_RUNTIME_DRIVER</ModuleType>\r
+    <GuidValue>f42fd042-8985-11db-a7db-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for Unix Fimware Volume Block DXE driver module.</Abstract>\r
+    <Description>This DXE runtime driver implements and produces the Fimware Volue Block Protocol on \r
+    Unix emulator.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>FwBlockService</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DxeServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiRuntimeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixFwh.dxs</Filename>\r
+    <Filename SupArchList="IA32">FWBlockService.c</Filename>\r
+    <Filename SupArchList="IA32">FwBlockService.h</Filename>\r
+    <Filename SupArchList="IA32">FvbInfo.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="SOMETIMES_PRODUCED">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiFvbExtensionProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Events>\r
+    <CreateEvents>\r
+      <EventTypes EventGuidCName="gEfiEventVirtualAddressChangeGuid" Usage="ALWAYS_CONSUMED">\r
+        <EventType>EVENT_GROUP_GUID</EventType>\r
+      </EventTypes>\r
+    </CreateEvents>\r
+  </Events>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_PRODUCED">\r
+      <GuidCName>gEfiAlternateFvBlockGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>FvbInitialize</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Include/Common/UnixInclude.h b/UnixPkg/Include/Common/UnixInclude.h
new file mode 100644 (file)
index 0000000..9229646
--- /dev/null
@@ -0,0 +1,32 @@
+/*++\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
+  UnixInclude.h\r
+\r
+Abstract:\r
+  Public include file for the Unix Library\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_INCLUDE_H__\r
+#define __UNIX_INCLUDE_H__\r
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/vfs.h>
+#include <sys/poll.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <time.h>
+#include <utime.h>
+#include <unistd.h>
+#endif\r
diff --git a/UnixPkg/Include/FlashLayout.h b/UnixPkg/Include/FlashLayout.h
new file mode 100644 (file)
index 0000000..1a13f16
--- /dev/null
@@ -0,0 +1,64 @@
+/*++\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
+\r
+  FlashLayout.h\r
+   \r
+Abstract:\r
+\r
+  Platform specific flash layout\r
+\r
+  BugBug: We need a better way\r
+\r
+--*/\r
+\r
+#ifndef __EFI_FLASH_LAYOUT__\r
+#define __EFI_FLASH_LAYOUT__\r
+\r
+//\r
+// Firmware Volume Information for Nt32\r
+// adding one working block before FFS FV,\r
+// and another one for spare block behind FFS FV\r
+//\r
+//\r
+// Note: When block number is changed in .dsc file,\r
+//       this value should be changed accordingly!!!\r
+//\r
+#define FIRMWARE_BLOCK_NUMBER                         0x28\r
+\r
+#define EFI_WINNT_FIRMWARE_OFFSET                     0x0\r
+#define EFI_WINNT_FIRMWARE_LENGTH                     (0x10000 * FIRMWARE_BLOCK_NUMBER)\r
+\r
+#define EFI_WINNT_RUNTIME_UPDATABLE_OFFSET            (EFI_WINNT_FIRMWARE_OFFSET + EFI_WINNT_FIRMWARE_LENGTH)\r
+\r
+#define EFI_WINNT_RUNTIME_UPDATABLE_LENGTH            0x10000\r
+\r
+#define EFI_WINNT_FTW_SPARE_BLOCK_OFFSET              (EFI_WINNT_RUNTIME_UPDATABLE_OFFSET + EFI_WINNT_RUNTIME_UPDATABLE_LENGTH)\r
+\r
+#define EFI_WINNT_FTW_SPARE_BLOCK_LENGTH              0x10000\r
+\r
+#define EFI_WINNT_RUNTIME_UPDATABLE_FV_HEADER_LENGTH  0x48\r
+\r
+#define EFI_VARIABLE_STORE_OFFSET                     EFI_WINNT_RUNTIME_UPDATABLE_OFFSET\r
+\r
+#define EFI_VARIABLE_STORE_LENGTH                     0x00C000\r
+\r
+#define EFI_EVENT_LOG_OFFSET                          (EFI_VARIABLE_STORE_OFFSET + EFI_VARIABLE_STORE_LENGTH)\r
+\r
+#define EFI_EVENT_LOG_LENGTH                          0x002000\r
+\r
+#define EFI_FTW_WORKING_OFFSET                        (EFI_EVENT_LOG_OFFSET + EFI_EVENT_LOG_LENGTH)\r
+\r
+#define EFI_FTW_WORKING_LENGTH                        0x002000\r
+\r
+#endif\r
+\r
diff --git a/UnixPkg/Include/Library/UnixLib.h b/UnixPkg/Include/Library/UnixLib.h
new file mode 100644 (file)
index 0000000..9797093
--- /dev/null
@@ -0,0 +1,27 @@
+/*++
+
+Copyright (c) 2006, Intel Corporation                                                         
+All rights reserved. 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        
+http://opensource.org/licenses/bsd-license.php                                            
+                                                                                          
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+
+Module Name:
+
+  UnixLib.h
+
+Abstract:
+
+  Public include file for the Unix Library
+
+--*/
+
+#ifndef __UNIX_LIB_H__
+#define __UNIX_LIB_H__
+
+extern EFI_UNIX_THUNK_PROTOCOL  *gUnix;
+
+#endif
diff --git a/UnixPkg/Include/Ppi/UnixAutoScan.h b/UnixPkg/Include/Ppi/UnixAutoScan.h
new file mode 100644 (file)
index 0000000..0c04d82
--- /dev/null
@@ -0,0 +1,66 @@
+/*++\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
+\r
+  UnixAutoscan.h\r
+\r
+Abstract:\r
+\r
+Unix Autoscan PPI\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEI_AUTOSCAN_H__\r
+#define __UNIX_PEI_AUTOSCAN_H__\r
+\r
+#include <UnixDxe.h>\r
+\r
+#define PEI_UNIX_AUTOSCAN_PPI_GUID \\r
+  { \\r
+    0xf2ed3d14, 0x8985, 0x11db, {0xb0, 0x57, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *PEI_UNIX_AUTOSCAN) (\r
+  IN  UINTN                 Index,\r
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,\r
+  OUT UINT64                *MemorySize\r
+  );\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  This service is called from Index == 0 until it returns EFI_UNSUPPORTED.\r
+  It allows discontiguous memory regions to be supported by the emulator.\r
+  It uses gSystemMemory[] and gSystemMemoryCount that were created by\r
+  parsing the host environment variable EFI_MEMORY_SIZE.\r
+  The size comes from the varaible and the address comes from the call to\r
+  WinNtOpenFile. \r
+\r
+Arguments:\r
+  Index      - Which memory region to use\r
+  MemoryBase - Return Base address of memory region\r
+  MemorySize - Return size in bytes of the memory region\r
+\r
+Returns:\r
+  EFI_SUCCESS - If memory region was mapped\r
+  EFI_UNSUPPORTED - If Index is not supported\r
+\r
+--*/\r
+typedef struct {\r
+  PEI_UNIX_AUTOSCAN UnixAutoScan;\r
+} PEI_UNIX_AUTOSCAN_PPI;\r
+\r
+extern EFI_GUID gPeiUnixAutoScanPpiGuid;\r
+\r
+#endif\r
diff --git a/UnixPkg/Include/Ppi/UnixFwh.h b/UnixPkg/Include/Ppi/UnixFwh.h
new file mode 100644 (file)
index 0000000..a9885a5
--- /dev/null
@@ -0,0 +1,62 @@
+/*++\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
+\r
+  UnixFwh.h\r
+\r
+Abstract:\r
+\r
+  Unix FWH PPI as defined in Tiano\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEI_FWH_H__\r
+#define __UNIX_PEI_FWH_H__\r
+\r
+#include <UnixDxe.h>\r
+\r
+#define UNIX_FWH_PPI_GUID \\r
+  { \\r
+    0xf2f0dc30, 0x8985, 0x11db, {0xa1, 0x5b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *UNIX_FWH_INFORMATION) (\r
+  IN     UINTN                  Index,\r
+  IN OUT EFI_PHYSICAL_ADDRESS   *FdBase,\r
+  IN OUT UINT64                 *FdSize\r
+  );\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  Return the FD Size and base address. Since the FD is loaded from a \r
+  file into host memory only the SEC will know it's address.\r
+\r
+Arguments:\r
+  Index  - Which FD, starts at zero.\r
+  FdSize - Size of the FD in bytes\r
+  FdBase - Start address of the FD. Assume it points to an FV Header\r
+\r
+Returns:\r
+  EFI_SUCCESS     - Return the Base address and size of the FV\r
+  EFI_UNSUPPORTED - Index does nto map to an FD in the system\r
+\r
+--*/\r
+typedef struct {\r
+  UNIX_FWH_INFORMATION  UnixFwh;\r
+} UNIX_FWH_PPI;\r
+\r
+extern EFI_GUID gUnixFwhPpiGuid;\r
+\r
+#endif\r
diff --git a/UnixPkg/Include/Ppi/UnixPeiLoadFile.h b/UnixPkg/Include/Ppi/UnixPeiLoadFile.h
new file mode 100644 (file)
index 0000000..b91c630
--- /dev/null
@@ -0,0 +1,65 @@
+/*++\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
+\r
+ UnixPeiLoadFile.h\r
+\r
+Abstract:\r
+\r
+  Unix Load File PPI.\r
+\r
+  When the PEI core is done it calls the DXE IPL via PPI\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEI_LOAD_FILE_H__\r
+#define __UNIX_PEI_LOAD_FILE_H__\r
+\r
+#include <UnixDxe.h>\r
+\r
+#define UNIX_PEI_LOAD_FILE_GUID \\r
+  { \\r
+    0xf2f48768, 0x8985, 0x11db, {0xb8, 0xda, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef\r
+EFI_STATUS\r
+(EFIAPI *UNIX_PEI_LOAD_FILE) (\r
+  VOID                  *Pe32Data,\r
+  EFI_PHYSICAL_ADDRESS  *ImageAddress,\r
+  UINT64                *ImageSize,\r
+  EFI_PHYSICAL_ADDRESS  *EntryPoint\r
+  );\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  Loads and relocates a PE/COFF image into memory.\r
+\r
+Arguments:\r
+  Pe32Data         - The base address of the PE/COFF file that is to be loaded and relocated\r
+  ImageAddress     - The base address of the relocated PE/COFF image\r
+  ImageSize        - The size of the relocated PE/COFF image\r
+  EntryPoint       - The entry point of the relocated PE/COFF image\r
+\r
+Returns:\r
+  EFI_SUCCESS   - The file was loaded and relocated\r
+  EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file\r
+\r
+--*/\r
+typedef struct {\r
+  UNIX_PEI_LOAD_FILE  PeiLoadFileService;\r
+} UNIX_PEI_LOAD_FILE_PPI;\r
+\r
+extern EFI_GUID gUnixPeiLoadFilePpiGuid;\r
+\r
+#endif\r
diff --git a/UnixPkg/Include/Ppi/UnixThunk.h b/UnixPkg/Include/Ppi/UnixThunk.h
new file mode 100644 (file)
index 0000000..866bd61
--- /dev/null
@@ -0,0 +1,56 @@
+/*++\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
+\r
+  UnixThunk.h\r
+\r
+Abstract:\r
+\r
+  Unix Thunk interface PPI\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEI_UNIX_THUNK_H__\r
+#define __UNIX_PEI_UNIX_THUNK_H__\r
+\r
+#include <UnixDxe.h>\r
+\r
+#define PEI_UNIX_THUNK_PPI_GUID \\r
+  { \\r
+    0xf2f830f2, 0x8985, 0x11db, {0x80, 0x6b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef\r
+VOID *\r
+(EFIAPI *PEI_UNIX_THUNK_INTERFACE) (\r
+  VOID\r
+  );\r
+\r
+/*++\r
+\r
+Routine Description:\r
+  Export of EFI_UNIX_THUNK_PROTOCOL from the Unix SEC.\r
+\r
+Arguments:\r
+  InterfaceBase - Address of the EFI_UNIX_THUNK_PROTOCOL\r
+\r
+Returns:\r
+  EFI_SUCCESS - Data returned\r
+\r
+--*/\r
+typedef struct {\r
+  PEI_UNIX_THUNK_INTERFACE  UnixThunk;\r
+} PEI_UNIX_THUNK_PPI;\r
+\r
+extern EFI_GUID gPeiUnixThunkPpiGuid;\r
+\r
+#endif\r
diff --git a/UnixPkg/Include/Protocol/UnixIo.h b/UnixPkg/Include/Protocol/UnixIo.h
new file mode 100644 (file)
index 0000000..1758ecb
--- /dev/null
@@ -0,0 +1,142 @@
+/*++\r
+\r
+Copyright (c) 2004 - 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
+\r
+  UnixIo.h\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#ifndef _UNIX_IO_H_\r
+#define _UNIX_IO_H_\r
+\r
+#define EFI_UNIX_IO_PROTOCOL_GUID \\r
+  { \\r
+    0xf2e23f54, 0x8985, 0x11db, {0xac, 0x79, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+typedef struct {\r
+  EFI_UNIX_THUNK_PROTOCOL  *UnixThunk;\r
+  EFI_GUID                  *TypeGuid;\r
+  UINT16                    *EnvString;\r
+  UINT16                    InstanceNumber;\r
+} EFI_UNIX_IO_PROTOCOL;\r
+\r
+extern EFI_GUID gEfiUnixIoProtocolGuid;\r
+\r
+//\r
+// The following GUIDs are used in EFI_UNIX_IO_PROTOCOL_GUID\r
+// Device paths. They map 1:1 with UNIX envirnment variables. The variables\r
+// define what virtual hardware the emulator/UnixBusDriver will produce.\r
+//\r
+//\r
+// EFI_UNIX_VIRTUAL_DISKS\r
+//\r
+#define EFI_UNIX_VIRTUAL_DISKS_GUID \\r
+  { \\r
+    0xf2ba331a, 0x8985, 0x11db, {0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixVirtualDisksGuid;\r
+\r
+//\r
+// EFI_UNIX_PHYSICAL_DISKS\r
+//\r
+#define EFI_UNIX_PHYSICAL_DISKS_GUID \\r
+  { \\r
+    0xf2bdcc96, 0x8985, 0x11db, {0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixPhysicalDisksGuid;\r
+\r
+//\r
+// EFI_UNIX_FILE_SYSTEM\r
+//\r
+#define EFI_UNIX_FILE_SYSTEM_GUID \\r
+  { \\r
+    0xf2c16b9e, 0x8985, 0x11db, {0x92, 0xc8, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixFileSystemGuid;\r
+\r
+//\r
+// EFI_WIN_NT_SERIAL_PORT\r
+//\r
+#define EFI_UNIX_SERIAL_PORT_GUID \\r
+  { \\r
+    0x6d3a727d, 0x66c8, 0x4d19, {0x87, 0xe6, 0x2, 0x15, 0x86, 0x14, 0x90, 0xf3} \\r
+  }\r
+\r
+extern EFI_GUID gEfiUnixSerialPortGuid;\r
+\r
+//\r
+// EFI_UNIX_UGA\r
+//\r
+#define EFI_UNIX_UGA_GUID \\r
+  { \\r
+    0xf2c8b80e, 0x8985, 0x11db, {0x93, 0xf1, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixUgaGuid;\r
+\r
+//\r
+// EFI_UNIX_GOP\r
+//\r
+#define EFI_UNIX_GOP_GUID \\r
+  { \\r
+    0xbace07c2, 0x8987, 0x11db, {0xa5, 0x9a, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixGopGuid;\r
+\r
+//\r
+// EFI_UNIX_CONSOLE\r
+//\r
+#define EFI_UNIX_CONSOLE_GUID \\r
+  { \\r
+    0xf2cc5d06, 0x8985, 0x11db, {0xbb, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixConsoleGuid;\r
+\r
+//\r
+// EFI_UNIX_MEMORY\r
+//\r
+#define EFI_UNIX_MEMORY_GUID \\r
+  { \\r
+    0xf2d006cc, 0x8985, 0x11db, {0xa4, 0x72, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixMemoryGuid;\r
+\r
+//\r
+// EFI_UNIX_CPU_MODEL\r
+//\r
+#define EFI_UNIX_CPU_MODEL_GUID \\r
+  { \\r
+    0xf2d3b330, 0x8985, 0x11db, {0x8a, 0xa3, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixCPUModelGuid;\r
+\r
+//\r
+// EFI_UNIX_CPU_SPEED\r
+//\r
+#define EFI_UNIX_CPU_SPEED_GUID \\r
+  { \\r
+    0xf2d74e5a, 0x8985, 0x11db, {0x97, 0x05, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }\r
+\r
+extern EFI_GUID gEfiUnixCPUSpeedGuid;\r
+\r
+#endif\r
diff --git a/UnixPkg/Include/Protocol/UnixThunk.h b/UnixPkg/Include/Protocol/UnixThunk.h
new file mode 100644 (file)
index 0000000..a0908a0
--- /dev/null
@@ -0,0 +1,244 @@
+/*++
+
+Copyright (c) 2004, Intel Corporation                                                         
+All rights reserved. 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        
+http://opensource.org/licenses/bsd-license.php                                            
+                                                                                          
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+
+Module Name:
+
+  UnixThunk.h
+
+Abstract:
+
+  This protocol allows an EFI driver in the Unix emulation environment
+  to make Posix calls.
+
+  NEVER make an Unix call directly, always make the call via this protocol.
+
+  There are no This pointers on the protocol member functions as they map
+  exactly into Unix system calls.
+
+--*/
+
+#ifndef _UNIX_THUNK_H_
+#define _UNIX_THUNK_H_
+
+#include <sys/termios.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/dir.h>
+#include <unistd.h>
+#include <poll.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <time.h>
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <termio.h>
+#include <sys/ioctl.h>
+#include <sys/vfs.h>
+#include <utime.h>
+
+#define EFI_UNIX_THUNK_PROTOCOL_GUID \
+  { \
+    0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }
+
+typedef
+VOID
+(*UnixSleep) (
+  unsigned long Milliseconds
+  );
+
+typedef
+VOID
+(*UnixExit) (
+  int status  // exit code for all threads
+  );
+
+typedef
+VOID
+(*UnixSetTimer) (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs));
+typedef
+VOID
+(*UnixGetLocalTime) (EFI_TIME *Time);
+typedef
+struct tm *
+(*UnixGmTime)(const time_t *timep);
+typedef
+long
+(*UnixGetTimeZone)(void);
+typedef
+int
+(*UnixGetDayLight)(void);
+typedef
+int
+(*UnixPoll)(struct pollfd *pfd, int nfds, int timeout);
+typedef
+int
+(*UnixRead) (int fd, void *buf, int count);
+typedef
+int
+(*UnixWrite) (int fd, const void *buf, int count);
+typedef
+char *
+(*UnixGetenv) (const char *var);
+typedef
+int
+(*UnixOpen) (const char *name, int flags, int mode);
+typedef
+long int
+(*UnixSeek) (int fd, long int off, int whence);
+typedef
+int
+(*UnixFtruncate) (int fd, long int len);
+typedef
+int
+(*UnixClose) (int fd);
+
+typedef
+int
+(*UnixMkdir)(const char *pathname, mode_t mode);
+typedef
+int
+(*UnixRmDir)(const char *pathname);
+typedef
+int
+(*UnixUnLink)(const char *pathname);
+typedef
+int
+(*UnixGetErrno)(VOID);
+typedef
+DIR *
+(*UnixOpenDir)(const char *pathname);
+typedef
+void
+(*UnixRewindDir)(DIR *dir);
+typedef
+struct dirent *
+(*UnixReadDir)(DIR *dir);
+typedef
+int
+(*UnixCloseDir)(DIR *dir);
+typedef
+int
+(*UnixStat)(const char *path, struct stat *buf);
+typedef
+int
+(*UnixStatFs)(const char *path, struct statfs *buf);
+typedef
+int
+(*UnixRename)(const char *oldpath, const char *newpath);
+typedef
+time_t
+(*UnixMkTime)(struct tm *tm);
+typedef
+int
+(*UnixFSync)(int fd);
+typedef
+int
+(*UnixChmod)(const char *path, mode_t mode);
+typedef
+int
+(*UnixUTime)(const char *filename, const struct utimbuf *buf);
+
+struct _EFI_UNIX_UGA_IO_PROTOCOL;
+typedef
+EFI_STATUS
+(*UnixUgaCreate)(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo,
+                CONST CHAR16 *Title);
+
+typedef
+int
+(*UnixTcflush) (int fildes, int queue_selector);
+
+typedef
+void
+(*UnixPerror) (__const char *__s);
+
+typedef 
+int 
+(*UnixIoCtl) (int fd, unsigned long int __request, ...);
+
+typedef 
+int 
+(*UnixFcntl) (int __fd, int __cmd, ...);
+
+typedef
+int 
+(*UnixCfsetispeed) (struct termios *__termios_p, speed_t __speed);
+
+typedef 
+int 
+(*UnixCfsetospeed) (struct termios *__termios_p, speed_t __speed);
+
+typedef
+int 
+(*UnixTcgetattr) (int __fd, struct termios *__termios_p);
+
+typedef 
+int 
+(*UnixTcsetattr) (int __fd, int __optional_actions,
+                     __const struct termios *__termios_p);
+
+//
+//
+//
+
+#define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE EFI_SIGNATURE_32 ('L', 'N', 'X', 'T')
+
+typedef struct _EFI_UNIX_THUNK_PROTOCOL {
+  UINT64                              Signature;
+
+  UnixSleep                           Sleep;
+  UnixExit                           Exit;
+  UnixSetTimer                        SetTimer;
+  UnixGetLocalTime                             GetLocalTime;
+  UnixGmTime                          GmTime;
+  UnixGetTimeZone                     GetTimeZone;
+  UnixGetDayLight                     GetDayLight;
+  UnixPoll                               Poll;
+  UnixRead                           Read;
+  UnixWrite                          Write;
+  UnixGetenv                         Getenv;
+  UnixOpen                           Open;
+  UnixSeek                           Lseek;
+  UnixFtruncate                      FTruncate;
+  UnixClose                          Close;
+  UnixMkdir                           MkDir;
+  UnixRmDir                           RmDir;
+  UnixUnLink                          UnLink;
+  UnixGetErrno                        GetErrno;
+  UnixOpenDir                         OpenDir;
+  UnixRewindDir                       RewindDir;
+  UnixReadDir                         ReadDir;
+  UnixCloseDir                        CloseDir;
+  UnixStat                            Stat;
+  UnixStatFs                          StatFs;
+  UnixRename                          Rename;
+  UnixMkTime                          MkTime;
+  UnixFSync                           FSync;
+  UnixChmod                           Chmod;
+  UnixUTime                           UTime;
+  UnixTcflush                         Tcflush;
+  UnixUgaCreate                                          UgaCreate;
+  UnixPerror                          Perror;
+  UnixIoCtl                           IoCtl;
+  UnixFcntl                           Fcntl;
+  UnixCfsetispeed                     Cfsetispeed;
+  UnixCfsetospeed                     Cfsetospeed;
+  UnixTcgetattr                       Tcgetattr;
+  UnixTcsetattr                       Tcsetattr;
+} EFI_UNIX_THUNK_PROTOCOL;
+
+extern EFI_GUID gEfiUnixThunkProtocolGuid;
+
+#endif
diff --git a/UnixPkg/Include/Protocol/UnixUgaIo.h b/UnixPkg/Include/Protocol/UnixUgaIo.h
new file mode 100644 (file)
index 0000000..63e80be
--- /dev/null
@@ -0,0 +1,72 @@
+/*++
+
+Copyright (c) 2006, Tristan Gingold
+All rights reserved. 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 http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+  UnixUgaIo.h
+
+Abstract:
+
+--*/
+
+#ifndef _UNIX_UGA_IO_H_
+#define _UNIX_UGA_IO_H_
+
+#define EFI_UNIX_UGA_IO_PROTOCOL_GUID \
+  { \
+    0xf2e5e2c6, 0x8985, 0x11db, {0xa1, 0x91, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+  }
+
+struct _EFI_UNIX_UGA_IO_PROTOCOL;
+typedef struct _EFI_UNIX_UGA_IO_PROTOCOL EFI_UNIX_UGA_IO_PROTOCOL;
+
+typedef
+EFI_STATUS
+(*UGAClose)(EFI_UNIX_UGA_IO_PROTOCOL *Uga);
+
+typedef
+EFI_STATUS
+(*UGASize)(EFI_UNIX_UGA_IO_PROTOCOL *Uga, UINT32 Width, UINT32 Height);
+
+typedef
+EFI_STATUS
+(*UGACheckKey)(EFI_UNIX_UGA_IO_PROTOCOL *Uga);
+
+typedef
+EFI_STATUS
+(*UGAGetKey)(EFI_UNIX_UGA_IO_PROTOCOL *Uga, EFI_INPUT_KEY *key);
+
+typedef
+EFI_STATUS
+(*UGABlt)(EFI_UNIX_UGA_IO_PROTOCOL *Uga,
+         IN  EFI_UGA_PIXEL                           *BltBuffer OPTIONAL,
+         IN  EFI_UGA_BLT_OPERATION                   BltOperation,
+         IN  UINTN                                   SourceX,
+         IN  UINTN                                   SourceY,
+         IN  UINTN                                   DestinationX,
+         IN  UINTN                                   DestinationY,
+         IN  UINTN                                   Width,
+         IN  UINTN                                   Height,
+         IN  UINTN                                   Delta OPTIONAL);
+
+struct _EFI_UNIX_UGA_IO_PROTOCOL {
+  VOID                                *Private;
+  UGAClose                            UgaClose;
+  UGASize                             UgaSize;
+  UGACheckKey                         UgaCheckKey;
+  UGAGetKey                           UgaGetKey;
+  UGABlt                              UgaBlt;
+};
+
+
+extern EFI_GUID gEfiUnixUgaIoProtocolGuid;
+
+#endif
diff --git a/UnixPkg/Include/UnixDxe.h b/UnixPkg/Include/UnixDxe.h
new file mode 100644 (file)
index 0000000..29a0c16
--- /dev/null
@@ -0,0 +1,36 @@
+/*++\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
+  UnixDxe.h\r
+\r
+Abstract:\r
+  Public include file for the Unix Library\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_DXE_H__\r
+#define __UNIX_DXE_H__\r
+\r
+#include <Ppi/UnixPeiLoadFile.h>\r
+#include <Ppi/UnixAutoScan.h>\r
+#include <Ppi/UnixThunk.h>\r
+#include <Ppi/UnixFwh.h>\r
+\r
+//\r
+//  UnixIo.h depends on UnixThunk.h\r
+//\r
+\r
+#include <Common/UnixInclude.h>
+#include <Protocol/UnixThunk.h>\r
+#include <Protocol/UnixIo.h>\r
+\r
+#endif\r
diff --git a/UnixPkg/Include/UnixPeim.h b/UnixPkg/Include/UnixPeim.h
new file mode 100644 (file)
index 0000000..4ddda91
--- /dev/null
@@ -0,0 +1,30 @@
+/*++\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
+  UnixPeim.h\r
+\r
+Abstract:\r
+  Public include file for the Unix Library\r
+\r
+--*/\r
+\r
+#ifndef __UNIX_PEIM_H__\r
+#define __UNIX_PEIM_H__\r
+\r
+#include <Ppi/UnixPeiLoadFile.h>\r
+#include <Ppi/UnixAutoScan.h>\r
+#include <Ppi/UnixThunk.h>\r
+#include <Ppi/UnixFwh.h>\r
+\r
+#include <Protocol/UnixThunk.h>\r
+\r
+#endif\r
diff --git a/UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf b/UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf
new file mode 100644 (file)
index 0000000..01c9f1a
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# A library to produce the global variable 'gUnix'\r
+#\r
+# This library contains a single global variable 'gUnix' along with a constructor to initialize that global.\r
+# Copyright (c) 2006 - 2008, Intel Corporation.\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeUnixLib\r
+  FILE_GUID                      = f39efc84-8985-11db-ad67-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = UnixLib \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = UnixLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  UnixLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  HobLib\r
+  DebugLib\r
+\r
+\r
+[Protocols]\r
+  gEfiUnixThunkProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa b/UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa
new file mode 100644 (file)
index 0000000..d77a86e
--- /dev/null
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>DxeUnixLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f39efc84-8985-11db-ad67-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>A library to produce the global variable 'gUnix'</Abstract>\r
+    <Description>This library contains a single global variable 'gUnix' along with a constructor to initialize that global.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation.</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>DxeUnixLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED">\r
+      <Keyword>UnixLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>UnixLibConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Library/DxeUnixLib/UnixLib.c b/UnixPkg/Library/DxeUnixLib/UnixLib.c
new file mode 100644 (file)
index 0000000..98bf044
--- /dev/null
@@ -0,0 +1,51 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  UnixLib.c\r
+\r
+Abstract:\r
+\r
+  Unix Library \r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include "UnixDxe.h"\r
+#include <Library/UnixLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_UNIX_THUNK_PROTOCOL *gUnix;\r
+\r
+EFI_STATUS\r
+UnixLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+  EFI_HOB_GUID_TYPE        *GuidHob;\r
+\r
+  GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);\r
+  ASSERT (GuidHob != NULL);\r
+  gUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  ASSERT (gUnix != NULL);\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf b/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf
new file mode 100644 (file)
index 0000000..b9aee9e
--- /dev/null
@@ -0,0 +1,61 @@
+#/** @file\r
+# Memory Status Code Library for UEFI drivers\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved.\r
+#  This software and associated documentation (if any) is furnished\r
+#  under a license and may only be used or copied in accordance\r
+#  with the terms of the license. Except as permitted by such\r
+#  license, no part of this software or documentation may be\r
+#  reproduced, stored in a retrieval system, or transmitted in any\r
+#  form or by any means without the express written consent of\r
+#  Intel Corporation.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeUnixOemHookStatusCodeLib\r
+  FILE_GUID                      = 0BB6F68A-2FC5-4394-9375-2B43F1C34B59\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = OemHookStatusCodeLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  UnixOemHookStatusCodeLib.c\r
+\r
+\r
+[Packages]\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+  MdePkg/MdePkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  ReportStatusCodeLib\r
+  BaseMemoryLib\r
+  PrintLib\r
+  HobLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiStatusCodeSpecificDataGuid                # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiUnixThunkProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
+\r
diff --git a/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa b/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa
new file mode 100644 (file)
index 0000000..7e9aeeb
--- /dev/null
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>DxeUnixOemHookStatusCodeLib</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>0BB6F68A-2FC5-4394-9375-2B43F1C34B59</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Memory Status Code Library for UEFI drivers</Abstract>\r
+    <Description>Lib to provide memory journal status code reporting Routines</Description>\r
+    <Copyright>Copyright (c) 2007, Intel Corporation.</Copyright>\r
+    <License>All rights reserved.\r
+      This software and associated documentation (if any) is furnished\r
+      under a license and may only be used or copied in accordance\r
+      with the terms of the license. Except as permitted by such\r
+      license, no part of this software or documentation may be\r
+      reproduced, stored in a retrieval system, or transmitted in any\r
+      form or by any means without the express written consent of\r
+      Intel Corporation.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>DxeUnixOemHookStatusCodeLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">\r
+      <Keyword>OemHookStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>ReportStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixOemHookStatusCodeLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiStatusCodeSpecificDataGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c b/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
new file mode 100644 (file)
index 0000000..4435d16
--- /dev/null
@@ -0,0 +1,238 @@
+/** @file\r
+  OEM hook status code library functions with no library constructor/destructor\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:  UnixOemHookStatusCodeLib.c\r
+\r
+**/\r
+#include "PiDxe.h"\r
+#include <Guid/StatusCodeDataTypeId.h>\r
+#include "UnixDxe.h"\r
+#include <Library/OemHookStatusCodeLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/ReportStatusCodeLib.h>\r
+#include <FrameworkModuleBase.h>\r
+#include <DebugInfo.h>\r
+\r
+//\r
+// Cache of UnixThunk protocol \r
+//\r
+STATIC\r
+EFI_UNIX_THUNK_PROTOCOL   *mUnix;\r
+\r
+//\r
+// Cache of standard output handle . \r
+//\r
+STATIC\r
+int                      mStdOut;\r
+\r
+/**\r
+\r
+  Initialize OEM status code device .\r
+\r
+  @return    Always return EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+OemHookStatusCodeInitialize (\r
+  VOID\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE        *GuidHob;\r
+\r
+  //\r
+  // Retrieve UnixThunkProtocol from GUID'ed HOB\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);\r
+  ASSERT (GuidHob != NULL);\r
+  mUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  ASSERT (mUnix != NULL);\r
+\r
+  //\r
+  // Cache standard output handle.\r
+  //\r
+  mStdOut = 1;
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Report status code to OEM device.\r
\r
+  @param  CodeType      Indicates the type of status code being reported.  Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.\r
\r
+  @param  Value         Describes the current status of a hardware or software entity.  \r
+                        This included information about the class and subclass that is used to classify the entity \r
+                        as well as an operation.  For progress codes, the operation is the current activity. \r
+                        For error codes, it is the exception.  For debug codes, it is not defined at this time. \r
+                        Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.  \r
+                        Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.\r
\r
+  @param  Instance      The enumeration of a hardware or software entity within the system.  \r
+                        A system may contain multiple entities that match a class/subclass pairing. \r
+                        The instance differentiates between them.  An instance of 0 indicates that instance information is unavailable, \r
+                        not meaningful, or not relevant.  Valid instance numbers start with 1.\r
+\r
+\r
+  @param  CallerId      This optional parameter may be used to identify the caller. \r
+                        This parameter allows the status code driver to apply different rules to different callers. \r
+                        Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.\r
+\r
+\r
+  @param  Data          This optional parameter may be used to pass additional data\r
\r
+  @return               The function always return EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+OemHookStatusCodeReport (\r
+  IN EFI_STATUS_CODE_TYPE     CodeType,\r
+  IN EFI_STATUS_CODE_VALUE    Value,\r
+  IN UINT32                   Instance,\r
+  IN EFI_GUID                 *CallerId, OPTIONAL\r
+  IN EFI_STATUS_CODE_DATA     *Data      OPTIONAL\r
+  )\r
+{\r
+  CHAR8           *Filename;\r
+  CHAR8           *Description;\r
+  CHAR8           *Format;\r
+  CHAR8           Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];\r
+  UINT32          ErrorLevel;\r
+  UINT32          LineNumber;\r
+  UINTN           CharCount;\r
+  VA_LIST         Marker;\r
+  EFI_DEBUG_INFO  *DebugInfo;\r
+\r
+  Buffer[0] = '\0';\r
+\r
+  if (Data != NULL &&\r
+      ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {\r
+    //\r
+    // Print ASSERT() information into output buffer.\r
+    //\r
+    CharCount = AsciiSPrint (\r
+                  Buffer,\r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE,\r
+                  "\n\rASSERT!: %a (%d): %a\n\r",\r
+                  Filename,\r
+                  LineNumber,\r
+                  Description\r
+                  );\r
+\r
+    //\r
+    // Callout to standard output.\r
+    //\r
+    mUnix->Write (\r
+              mStdOut,\r
+              Buffer,\r
+              CharCount\r
+             );
+\r
+    return EFI_SUCCESS;\r
+\r
+  } else if (Data != NULL &&\r
+             ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {\r
+    //\r
+    // Print DEBUG() information into output buffer.\r
+    //\r
+    CharCount = AsciiVSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  Format, \r
+                  Marker\r
+                  );\r
+  } else if (Data != NULL && \r
+             CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&\r
+             (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {\r
+    //\r
+    // Print specific data into output buffer.\r
+    //\r
+    DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);\r
+    Marker    = (VA_LIST) (DebugInfo + 1);\r
+    Format    = (CHAR8 *) (((UINT64 *) Marker) + 12);\r
+\r
+    CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);\r
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {\r
+    //\r
+    // Print ERROR information into output buffer.\r
+    //\r
+    CharCount = AsciiSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  "ERROR: C%x:V%x I%x", \r
+                  CodeType, \r
+                  Value, \r
+                  Instance\r
+                  );\r
+\r
+    //\r
+    // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.\r
+    //\r
+    \r
+    if (CallerId != NULL) {\r
+      CharCount += AsciiSPrint (\r
+                     &Buffer[CharCount - 1],\r
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
+                     " %g",\r
+                     CallerId\r
+                     );\r
+    }\r
+\r
+    if (Data != NULL) {\r
+      CharCount += AsciiSPrint (\r
+                     &Buffer[CharCount - 1],\r
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
+                     " %x",\r
+                     Data\r
+                     );\r
+    }\r
+\r
+    CharCount += AsciiSPrint (\r
+                   &Buffer[CharCount - 1],\r
+                   (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),\r
+                   "\n\r"\r
+                   );\r
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {\r
+    CharCount = AsciiSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  "PROGRESS CODE: V%x I%x\n\r", \r
+                  Value, \r
+                  Instance\r
+                  );\r
+  } else {\r
+    CharCount = AsciiSPrint (\r
+                  Buffer, \r
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, \r
+                  "Undefined: C%x:V%x I%x\n\r", \r
+                  CodeType, \r
+                  Value, \r
+                  Instance\r
+                  );\r
+  }\r
+\r
+  //\r
+  // Callout to standard output.\r
+  //\r
+  mUnix->Write (\r
+            mStdOut,\r
+            Buffer,\r
+            CharCount\r
+            );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
diff --git a/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c b/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c
new file mode 100644 (file)
index 0000000..48a6254
--- /dev/null
@@ -0,0 +1,225 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  DxeUnixPeCoffLib.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Unix PE/COFF loader with the PE COFF LOADER guid structure\r
+  to produce PeCoff library class.\r
+\r
+\r
+**/\r
+\r
+#include <PiDxe.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader;\r
+\r
+/**\r
+  The constructor function gets the pointer to PeCofferLoader guid structure\r
+  from the guid data hob.\r
+\r
+  It will ASSERT() if the guid hob of PeCofferLoader guid structure doesn't exist.\r
+\r
+  @param  ImageHandle   The firmware allocated handle for the EFI image.\r
+  @param  SystemTable   A pointer to the EFI System Table.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+DxeUnixPeCoffLibConstructor (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+  \r
+  //\r
+  // Find guid data hob that contains PeCoffLoader guid structure.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+  ASSERT (GuidHob != NULL);\r
+\r
+  //\r
+  // Get PeCofferLoader guid structure from guid hob data.\r
+  //\r
+  mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves information about a PE/COFF image.\r
+\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+  a supported PE/COFF image type, then return RETURN_UNSUPPORTED.  If any errors occur while\r
+  computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+  ImageContext. \r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that needs to be examined by this function.\r
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+    return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+  ImageContext as the relocation base address.  Otherwise, use the DestinationAddress field\r
+  of ImageContext as the relocation base address.  The caller must allocate the relocation\r
+  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.  \r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
+\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Loads a PE/COFF image into memory.\r
+\r
+  Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+  specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
+  the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+  The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  ImageRead function that operates on a memory buffer whos base is passed into\r
+  FileHandle. \r
+\r
+  @param  FileHandle        Ponter to baes of the input stream\r
+  @param  FileOffset        Offset to the start of the buffer\r
+  @param  ReadSize          Number of bytes to copy into the buffer\r
+  @param  Buffer            Location to place results of read\r
+\r
+  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into \r
+                            the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+  runtime. \r
+  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+  the fixups with a virtual mapping.\r
+\r
+\r
+  @param  ImageBase          Base address of relocated image\r
+  @param  VirtImageBase      Virtual mapping for ImageBase\r
+  @param  ImageSize          Size of the image to relocate\r
+  @param  RelocationData     Location to place results of read\r
+  \r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+  IN  PHYSICAL_ADDRESS        ImageBase,\r
+  IN  PHYSICAL_ADDRESS        VirtImageBase,\r
+  IN  UINTN                   ImageSize,\r
+  IN  VOID                    *RelocationData\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For Unix emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
diff --git a/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf b/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf
new file mode 100644 (file)
index 0000000..b5fd473
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# PeCoff libary for Dxe modules that run Unix emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007 - 2008, 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
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = DxeUnixPeCoffLib\r
+  FILE_GUID                      = 624571b0-4b69-40e3-bd13-78fae0e84270\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffLib|DXE_CORE DXE_DRIVER\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = DxeUnixPeCoffLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  DxeUnixPeCoffLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                # ALWAYS_CONSUMED\r
+\r
diff --git a/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf
new file mode 100644 (file)
index 0000000..5128c3a
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# Component description file for the EdkNt32PeiPeCoffGetEntryPointLib library.\r
+#\r
+# PeCoffGetEntryPointLib library class for NT32 instance implemented by use NTPeiLoadFile PPI.\r
+# Copyright (c) 2008, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = EdkUnixPeiPeCoffGetEntryPointLib\r
+  FILE_GUID                      = f3b702e8-8985-11db-9558-0040d02b1835\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffGetEntryPointLib \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  PeCoffGetEntryPoint.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesLib\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gUnixPeiLoadFilePpiGuid                       # PPI ALWAYS_CONSUMED\r
+\r
diff --git a/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa
new file mode 100644 (file)
index 0000000..1c44900
--- /dev/null
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>EdkUnixPeiPeCoffGetEntryPointLib</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>f3b702e8-8985-11db-9558-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for the EdkNt32PeiPeCoffGetEntryPointLib library.</Abstract>\r
+    <Description>PeCoffGetEntryPointLib library class for NT32 instance implemented by use NTPeiLoadFile PPI.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>EdkUnixPeiPeCoffGetEntryPointLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED">\r
+      <Keyword>PeCoffGetEntryPointLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>PeCoffGetEntryPoint.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_CONSUMED">\r
+      <PpiCName>gUnixPeiLoadFilePpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
new file mode 100644 (file)
index 0000000..758ce9d
--- /dev/null
@@ -0,0 +1,266 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  PeCoffGetEntryPoint.c\r
+\r
+Abstract:\r
+\r
+  Tiano PE/COFF loader\r
+\r
+Revision History\r
+\r
+--*/\r
+#include "PiPei.h"\r
+#include <Library/PeCoffGetEntryPointLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Ppi/UnixPeiLoadFile.h>\r
+#include <IndustryStandard/PeImage.h>\r
+#include <Library/DebugLib.h>\r
+\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetEntryPoint (\r
+  IN     VOID  *Pe32Data,\r
+  IN OUT VOID  **EntryPoint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Loads a PE/COFF image into memory, this is not follow the original purpose of \r
+  PeCoffGetEntryPoint library class.  But it's ok that Unix package not run on a real \r
+  platform and this is for source level debug.\r
+\r
+Arguments:\r
+\r
+  Pe32Data   - Pointer to a PE/COFF Image\r
+\r
+  EntryPoint - Pointer to the entry point of the PE/COFF image\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS            if the EntryPoint was returned\r
+  EFI_INVALID_PARAMETER  if the EntryPoint could not be found from Pe32Data\r
+\r
+--*/\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_PEI_PPI_DESCRIPTOR  *PpiDescriptor;\r
+  UNIX_PEI_LOAD_FILE_PPI *PeiUnixService;\r
+  EFI_PHYSICAL_ADDRESS    ImageAddress;\r
+  UINT64                  ImageSize;\r
+  EFI_PHYSICAL_ADDRESS    ImageEntryPoint;\r
+\r
+  ASSERT (Pe32Data   != NULL);\r
+  ASSERT (EntryPoint != NULL);\r
+\r
+  Status = PeiServicesLocatePpi (\r
+             &gUnixPeiLoadFilePpiGuid,\r
+             0,\r
+             &PpiDescriptor,\r
+             (void **)&PeiUnixService\r
+             );\r
+\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Status = PeiUnixService->PeiLoadFileService (\r
+                           Pe32Data,\r
+                           &ImageAddress,\r
+                           &ImageSize,\r
+                           &ImageEntryPoint\r
+                           );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  *EntryPoint = (VOID*)(UINTN)ImageEntryPoint;\r
+  return Status;\r
+}\r
+\r
+/**\r
+  Returns the machine type of PE/COFF image. \r
+  This is copied from MDE BasePeCoffGetEntryPointLib, the code should be sync with it.\r
+  The reason is Unix package needs to load the image to memory to support source\r
+  level debug.\r
+   \r
+\r
+  @param  Pe32Data   Pointer to a PE/COFF header\r
+\r
+  @return            Machine type or zero if not a valid iamge\r
+\r
+**/\r
+UINT16\r
+EFIAPI\r
+PeCoffLoaderGetMachineType (\r
+  IN  VOID  *Pe32Data\r
+  )\r
+{  \r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION  Hdr;\r
+  EFI_IMAGE_DOS_HEADER                 *DosHdr;\r
+\r
+  ASSERT (Pe32Data   != NULL);\r
+\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER  *)Pe32Data;\r
+  if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+\r
+  } else {\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data);\r
+  }\r
+\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    return Hdr.Te->Machine;\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE)  {\r
+    return Hdr.Pe32->FileHeader.Machine;\r
+  }\r
+\r
+  return 0x0000;\r
+}\r
+\r
+/**\r
+  Returns a pointer to the PDB file name for a PE/COFF image that has been\r
+  loaded into system memory with the PE/COFF Loader Library functions.\r
+\r
+  Returns the PDB file name for the PE/COFF image specified by Pe32Data.  If\r
+  the PE/COFF image specified by Pe32Data is not a valid, then NULL is\r
+  returned.  If the PE/COFF image specified by Pe32Data does not contain a\r
+  debug directory entry, then NULL is returned.  If the debug directory entry\r
+  in the PE/COFF image specified by Pe32Data does not contain a PDB file name,\r
+  then NULL is returned.\r
+  If Pe32Data is NULL, then ASSERT().\r
+\r
+  @param  Pe32Data   Pointer to the PE/COFF image that is loaded in system\r
+                     memory.\r
+\r
+  @return The PDB file name for the PE/COFF image specified by Pe32Data or NULL\r
+          if it cannot be retrieved.\r
+\r
+**/\r
+VOID *\r
+EFIAPI\r
+PeCoffLoaderGetPdbPointer (\r
+  IN VOID  *Pe32Data\r
+  )\r
+{\r
+  EFI_IMAGE_DOS_HEADER                  *DosHdr;\r
+  EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION   Hdr;\r
+  EFI_IMAGE_DATA_DIRECTORY              *DirectoryEntry;\r
+  EFI_IMAGE_DEBUG_DIRECTORY_ENTRY       *DebugEntry;\r
+  UINTN                                 DirCount;\r
+  VOID                                  *CodeViewEntryPointer;\r
+  INTN                                  TEImageAdjust;\r
+  UINT32                                NumberOfRvaAndSizes;\r
+  UINT16                                Magic;\r
+\r
+  ASSERT (Pe32Data   != NULL);\r
+\r
+  TEImageAdjust       = 0;\r
+  DirectoryEntry      = NULL;\r
+  DebugEntry          = NULL;\r
+  NumberOfRvaAndSizes = 0;\r
+\r
+  DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;\r
+  if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {\r
+    //\r
+    // DOS image header is present, so read the PE header after the DOS image header.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));\r
+  } else {\r
+    //\r
+    // DOS image header is not present, so PE header is at the image base.\r
+    //\r
+    Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;\r
+  }\r
+\r
+  if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {\r
+    if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {\r
+      DirectoryEntry  = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];\r
+      TEImageAdjust   = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;\r
+      DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +\r
+                    Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +\r
+                    TEImageAdjust);\r
+    }\r
+  } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {\r
+    //\r
+    // NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.\r
+    //       It is due to backward-compatibility, for some system might\r
+    //       generate PE32+ image with PE32 Magic.\r
+    //\r
+    switch (Hdr.Pe32->FileHeader.Machine) {\r
+    case EFI_IMAGE_MACHINE_IA32:\r
+      //\r
+      // Assume PE32 image with IA32 Machine field.\r
+      //\r
+      Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;\r
+      break;\r
+    case EFI_IMAGE_MACHINE_X64:\r
+    case EFI_IMAGE_MACHINE_IPF:\r
+      //\r
+      // Assume PE32+ image with X64 or IPF Machine field\r
+      //\r
+      Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;\r
+      break;\r
+    default:\r
+      //\r
+      // For unknow Machine field, use Magic in optional Header\r
+      //\r
+      Magic = Hdr.Pe32->OptionalHeader.Magic;\r
+    }\r
+\r
+    if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {\r
+      //\r
+      // Use PE32 offset get Debug Directory Entry\r
+      //\r
+      NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+    } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
+      //\r
+      // Use PE32+ offset get Debug Directory Entry\r
+      //\r
+      NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;\r
+      DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);\r
+      DebugEntry     = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);\r
+    }\r
+\r
+    if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {\r
+      DirectoryEntry = NULL;\r
+      DebugEntry = NULL;\r
+    }\r
+  } else {\r
+    return NULL;\r
+  }\r
+\r
+  if (DebugEntry == NULL || DirectoryEntry == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {\r
+    if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {\r
+      if (DebugEntry->SizeOfData > 0) {\r
+        CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);\r
+        switch (* (UINT32 *) CodeViewEntryPointer) {\r
+        case CODEVIEW_SIGNATURE_NB10:\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));\r
+        case CODEVIEW_SIGNATURE_RSDS:\r
+          return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));\r
+        default:\r
+          break;\r
+        }\r
+      }\r
+    }\r
+  }\r
+\r
+  return NULL;\r
+}\r
diff --git a/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c b/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c
new file mode 100644 (file)
index 0000000..2c24417
--- /dev/null
@@ -0,0 +1,262 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  PeiCoreUnixPeCoffLib.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Unix PE/COFF loader with the PE COFF LOADER guid structure\r
+  to produce PeCoff library class.\r
+\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader = NULL;\r
+\r
+/**\r
+  The function caches the pointer of PeCofferLoader guid structure\r
+  into the guid data hob.\r
+\r
+  The funtion must be called after PeCofferLoader guid structure is installed.\r
+  It will ASSERT() if PeCofferLoader guid structure is not installed.\r
+\r
+  @retval EFI_SUCCESS   PeCofferLoader guid structure is found.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetPeCoffLoaderStucture (\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+\r
+  Status = EFI_NOT_FOUND;\r
+  \r
+  //\r
+  // Try to get guid data hob that contains PeCoffLoader guid structure.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+\r
+  if (GuidHob == NULL) {\r
+    //\r
+    // GuidHob is not ready, try to locate PeCoffLoader guid structure.\r
+    //\r
+    Status = PeiServicesLocatePpi (\r
+                &gEfiPeiPeCoffLoaderGuid,\r
+                0,\r
+                NULL,\r
+                &mPeiEfiPeiPeCoffLoader\r
+                );\r
+    \r
+    //\r
+    // PeCofferLoader guid structure must be installed before this library runs.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    //\r
+    // Build guid data hob of PeCofferLoader guid structure for DXE module use. \r
+    //\r
+    BuildGuidDataHob (\r
+      &gEfiPeiPeCoffLoaderGuid,\r
+      (VOID *) &mPeiEfiPeiPeCoffLoader,\r
+      sizeof (VOID *)\r
+      );\r
+  } else {\r
+    //\r
+    // Get PeCofferLoader guid structure directly from guid hob data.\r
+    //\r
+    mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves information about a PE/COFF image.\r
+\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+  a supported PE/COFF image type, then return RETURN_UNSUPPORTED.  If any errors occur while\r
+  computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+  ImageContext. \r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that needs to be examined by this function.\r
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+  ImageContext as the relocation base address.  Otherwise, use the DestinationAddress field\r
+  of ImageContext as the relocation base address.  The caller must allocate the relocation\r
+  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.  \r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
+\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Loads a PE/COFF image into memory.\r
+\r
+  Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+  specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
+  the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+  The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  ImageRead function that operates on a memory buffer whos base is passed into\r
+  FileHandle. \r
+\r
+  @param  FileHandle        Ponter to baes of the input stream\r
+  @param  FileOffset        Offset to the start of the buffer\r
+  @param  ReadSize          Number of bytes to copy into the buffer\r
+  @param  Buffer            Location to place results of read\r
+\r
+  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into \r
+                            the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+  runtime. \r
+  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+  the fixups with a virtual mapping.\r
+\r
+\r
+  @param  ImageBase          Base address of relocated image\r
+  @param  VirtImageBase      Virtual mapping for ImageBase\r
+  @param  ImageSize          Size of the image to relocate\r
+  @param  RelocationData     Location to place results of read\r
+  \r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+  IN  PHYSICAL_ADDRESS        ImageBase,\r
+  IN  PHYSICAL_ADDRESS        VirtImageBase,\r
+  IN  UINTN                   ImageSize,\r
+  IN  VOID                    *RelocationData\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For Unix emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  if (mPeiEfiPeiPeCoffLoader == NULL) {\r
+    GetPeCoffLoaderStucture ();\r
+  }\r
+  return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
diff --git a/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf b/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf
new file mode 100644 (file)
index 0000000..12b2188
--- /dev/null
@@ -0,0 +1,49 @@
+#/** @file\r
+# PeCoff libary for PeiCore modules that run Unix emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007 - 2008, 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
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiCoreUnixPeCoffLib\r
+  FILE_GUID                      = ef9fd7ee-3181-4b16-adc1-8615f88b58b8\r
+  MODULE_TYPE                    = PEI_CORE\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffLib|PEI_CORE\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  PeiCoreUnixPeCoffLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  PeiServicesLib\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                # ALWAYS_CONSUMED\r
+\r
diff --git a/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf b/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf
new file mode 100644 (file)
index 0000000..0d4c7f6
--- /dev/null
@@ -0,0 +1,61 @@
+#/** @file\r
+# Memory Status Code Library for UEFI drivers\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007, Intel Corporation.\r
+#\r
+#  All rights reserved.\r
+#  This software and associated documentation (if any) is furnished\r
+#  under a license and may only be used or copied in accordance\r
+#  with the terms of the license. Except as permitted by such\r
+#  license, no part of this software or documentation may be\r
+#  reproduced, stored in a retrieval system, or transmitted in any\r
+#  form or by any means without the express written consent of\r
+#  Intel Corporation.\r
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiUnixOemHookStatusCodeLib\r
+  FILE_GUID                      = 23E378C1-B199-49ad-9F14-DAF5D3C7EC28\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = OemHookStatusCodeLib|PEIM \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  UnixOemHookStatusCodeLib.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesLib\r
+  ReportStatusCodeLib\r
+  BaseMemoryLib\r
+  PrintLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiStatusCodeSpecificDataGuid                # ALWAYS_CONSUMED\r
+\r
+\r
+[Ppis]\r
+  gPeiUnixThunkPpiGuid                          # PPI ALWAYS_CONSUMED\r
+\r
diff --git a/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa b/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa
new file mode 100644 (file)
index 0000000..f80a105
--- /dev/null
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>PeiUnixOemHookStatusCodeLib</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>23E378C1-B199-49ad-9F14-DAF5D3C7EC28</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Memory Status Code Library for UEFI drivers</Abstract>\r
+    <Description>Lib to provide memory journal status code reporting Routines</Description>\r
+    <Copyright>Copyright (c) 2007, Intel Corporation.</Copyright>\r
+    <License>All rights reserved.\r
+      This software and associated documentation (if any) is furnished\r
+      under a license and may only be used or copied in accordance\r
+      with the terms of the license. Except as permitted by such\r
+      license, no part of this software or documentation may be\r
+      reproduced, stored in a retrieval system, or transmitted in any\r
+      form or by any means without the express written consent of\r
+      Intel Corporation.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>PeiUnixOemHookStatusCodeLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="PEIM">\r
+      <Keyword>OemHookStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>ReportStatusCodeLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixOemHookStatusCodeLib.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_CONSUMED">\r
+      <PpiCName>gPeiUnixThunkPpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiStatusCodeSpecificDataGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c b/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
new file mode 100644 (file)
index 0000000..8d661bc
--- /dev/null
@@ -0,0 +1,246 @@
+/** @file
+  OEM hook status code library functions with no library constructor/destructor
+
+  Copyright (c) 2006 - 2008, Intel Corporation
+  All rights reserved. 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
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+  Module Name:  UnixOemHookStatusCodeLib.c
+
+**/
+#include "PiPei.h"
+#include <Guid/StatusCodeDataTypeId.h>
+#include <Ppi/UnixThunk.h>
+#include <FrameworkModuleBase.h>
+#include <Library/OemHookStatusCodeLib.h>
+#include <Library/DebugLib.h>
+#include <Library/PrintLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/ReportStatusCodeLib.h>
+#include <Library/PeiServicesLib.h>
+#include <DebugInfo.h>
+
+//
+// Cache of UnixThunk protocol 
+//
+STATIC
+EFI_UNIX_THUNK_PROTOCOL   *mUnix;
+
+//
+// Cache of standard output handle . 
+//
+STATIC
+int                      mStdOut;
+
+/**
+
+  Initialize OEM status code device .
+
+  @return    Always return EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+OemHookStatusCodeInitialize (
+  VOID
+  )
+{
+  PEI_UNIX_THUNK_PPI  *UnixThunkPpi;
+  EFI_STATUS        Status;
+
+  
+  //
+  // Locate Unix ThunkPpi for retrieving standard output handle
+  //
+  Status = PeiServicesLocatePpi (
+              &gPeiUnixThunkPpiGuid,
+              0,
+              NULL,
+              (VOID **) &UnixThunkPpi
+              );
+
+  ASSERT_EFI_ERROR (Status);
+
+  mUnix  = (EFI_UNIX_THUNK_PROTOCOL *) UnixThunkPpi->UnixThunk ();
+  
+  //
+  // Cache standard output handle.
+  //
+  mStdOut = 1;
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Report status code to OEM device.
+  @param  CodeType      Indicates the type of status code being reported.  Type EFI_STATUS_CODE_TYPE is defined in "Related Definitions" below.
+  @param  Value         Describes the current status of a hardware or software entity.  
+                        This included information about the class and subclass that is used to classify the entity 
+                        as well as an operation.  For progress codes, the operation is the current activity. 
+                        For error codes, it is the exception.  For debug codes, it is not defined at this time. 
+                        Type EFI_STATUS_CODE_VALUE is defined in "Related Definitions" below.  
+                        Specific values are discussed in the Intel? Platform Innovation Framework for EFI Status Code Specification.
+  @param  Instance      The enumeration of a hardware or software entity within the system.  
+                        A system may contain multiple entities that match a class/subclass pairing. 
+                        The instance differentiates between them.  An instance of 0 indicates that instance information is unavailable, 
+                        not meaningful, or not relevant.  Valid instance numbers start with 1.
+
+
+  @param  CallerId      This optional parameter may be used to identify the caller. 
+                        This parameter allows the status code driver to apply different rules to different callers. 
+                        Type EFI_GUID is defined in InstallProtocolInterface() in the EFI 1.10 Specification.
+
+
+  @param  Data          This optional parameter may be used to pass additional data
+  @return               The function always return EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+OemHookStatusCodeReport (
+  IN EFI_STATUS_CODE_TYPE     CodeType,
+  IN EFI_STATUS_CODE_VALUE    Value,
+  IN UINT32                   Instance,
+  IN EFI_GUID                 *CallerId, OPTIONAL
+  IN EFI_STATUS_CODE_DATA     *Data      OPTIONAL
+  )
+{
+  CHAR8           *Filename;
+  CHAR8           *Description;
+  CHAR8           *Format;
+  CHAR8           Buffer[EFI_STATUS_CODE_DATA_MAX_SIZE];
+  UINT32          ErrorLevel;
+  UINT32          LineNumber;
+  UINTN           CharCount;
+  VA_LIST         Marker;
+  EFI_DEBUG_INFO  *DebugInfo;
+
+  Buffer[0] = '\0';
+
+  if (Data != NULL &&
+      ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
+    //
+    // Print ASSERT() information into output buffer.
+    //
+    CharCount = AsciiSPrint (
+                  Buffer,
+                  EFI_STATUS_CODE_DATA_MAX_SIZE,
+                  "\n\rASSERT!: %a (%d): %a\n\r",
+                  Filename,
+                  LineNumber,
+                  Description
+                  );
+
+    //
+    // Callout to standard output.
+    //
+    mUnix->Write (
+              mStdOut,
+              Buffer,
+              CharCount
+             );
+
+    return EFI_SUCCESS;
+
+  } else if (Data != NULL &&
+             ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
+    //
+    // Print DEBUG() information into output buffer.
+    //
+    CharCount = AsciiVSPrint (
+                  Buffer, 
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, 
+                  Format, 
+                  Marker
+                  );
+  } else if (Data != NULL && 
+             CompareGuid (&Data->Type, &gEfiStatusCodeSpecificDataGuid) &&
+             (CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_DEBUG_CODE) {
+    //
+    // Print specific data into output buffer.
+    //
+    DebugInfo = (EFI_DEBUG_INFO *) (Data + 1);
+    Marker    = (VA_LIST) (DebugInfo + 1);
+    Format    = (CHAR8 *) (((UINT64 *) Marker) + 12);
+
+    CharCount = AsciiVSPrint (Buffer, EFI_STATUS_CODE_DATA_MAX_SIZE, Format, Marker);
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_ERROR_CODE) {
+    //
+    // Print ERROR information into output buffer.
+    //
+    CharCount = AsciiSPrint (
+                  Buffer, 
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, 
+                  "ERROR: C%x:V%x I%x", 
+                  CodeType, 
+                  Value, 
+                  Instance
+                  );
+
+    //
+    // Make sure we don't try to print values that weren't intended to be printed, especially NULL GUID pointers.
+    //
+    
+    if (CallerId != NULL) {
+      CharCount += AsciiSPrint (
+                     &Buffer[CharCount - 1],
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
+                     " %g",
+                     CallerId
+                     );
+    }
+
+    if (Data != NULL) {
+      CharCount += AsciiSPrint (
+                     &Buffer[CharCount - 1],
+                     (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
+                     " %x",
+                     Data
+                     );
+    }
+
+    CharCount += AsciiSPrint (
+                   &Buffer[CharCount - 1],
+                   (EFI_STATUS_CODE_DATA_MAX_SIZE - (sizeof (Buffer[0]) * CharCount)),
+                   "\n\r"
+                   );
+  } else if ((CodeType & EFI_STATUS_CODE_TYPE_MASK) == EFI_PROGRESS_CODE) {
+    CharCount = AsciiSPrint (
+                  Buffer, 
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, 
+                  "PROGRESS CODE: V%x I%x\n\r", 
+                  Value, 
+                  Instance
+                  );
+  } else {
+    CharCount = AsciiSPrint (
+                  Buffer, 
+                  EFI_STATUS_CODE_DATA_MAX_SIZE, 
+                  "Undefined: C%x:V%x I%x\n\r", 
+                  CodeType, 
+                  Value, 
+                  Instance
+                  );
+  }
+
+  //
+  // Callout to standard output.
+  //
+  mUnix->Write (
+            mStdOut,
+            Buffer,
+            CharCount
+            );
+
+  return EFI_SUCCESS;
+}
+
diff --git a/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.c b/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.c
new file mode 100644 (file)
index 0000000..18a2551
--- /dev/null
@@ -0,0 +1,255 @@
+/**@file\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  PeiUnixPeCoffLib.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Unix PE/COFF loader with the PE COFF LOADER guid structure\r
+  to produce PeCoff library class.\r
+\r
+\r
+**/\r
+\r
+#include <PiPei.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/HobLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader;\r
+\r
+/**\r
+  The constructor function caches the pointer of PeCofferLoader guid structure\r
+  into the guid data hob.\r
+\r
+  The constructor must be called after PeCofferLoader guid structure is installed.\r
+  It will ASSERT() if PeCofferLoader guid structure is not installed.\r
+\r
+  @param  FfsHeader   Pointer to FFS header the loaded driver.\r
+  @param  PeiServices Pointer to the PEI services.\r
+\r
+  @retval EFI_SUCCESS   The constructor always returns EFI_SUCCESS.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+PeiUnixPeCoffLibConstructor (\r
+  IN EFI_FFS_FILE_HEADER      *FfsHeader,\r
+  IN EFI_PEI_SERVICES         **PeiServices\r
+  )\r
+{\r
+  EFI_STATUS           Status;\r
+  EFI_HOB_GUID_TYPE    *GuidHob;\r
+\r
+  Status = EFI_NOT_FOUND;\r
+  \r
+  //\r
+  // Try to get guid data hob that contains PeCoffLoader guid structure.\r
+  //\r
+  GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);\r
+\r
+  if (GuidHob == NULL) {\r
+    //\r
+    // GuidHob is not ready, try to locate PeCoffLoader guid structure.\r
+    //\r
+    Status = (*PeiServices)->LocatePpi (\r
+                              PeiServices,\r
+                              &gEfiPeiPeCoffLoaderGuid,\r
+                              0,\r
+                              NULL,\r
+                              &mPeiEfiPeiPeCoffLoader\r
+                              );\r
+    \r
+    //\r
+    // PeCofferLoader guid structure must be installed before this library runs.\r
+    //\r
+    ASSERT_EFI_ERROR (Status);\r
+    \r
+    //\r
+    // Build guid data hob of PeCofferLoader guid structure for DXE module use. \r
+    //\r
+    BuildGuidDataHob (\r
+      &gEfiPeiPeCoffLoaderGuid,\r
+      (VOID *) &mPeiEfiPeiPeCoffLoader,\r
+      sizeof (VOID *)\r
+      );\r
+  } else {\r
+    //\r
+    // Get PeCofferLoader guid structure directly from guid hob data.\r
+    //\r
+    mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieves information about a PE/COFF image.\r
+\r
+  Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,\r
+  PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva\r
+  fields of the ImageContext structure.  If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.\r
+  If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not\r
+  a supported PE/COFF image type, then return RETURN_UNSUPPORTED.  If any errors occur while\r
+  computing the fields of ImageContext, then the error status is returned in the ImageError field of\r
+  ImageContext. \r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that needs to be examined by this function.\r
+\r
+  @retval RETURN_SUCCESS            The information on the PE/COFF image was collected.\r
+  @retval RETURN_INVALID_PARAMETER  ImageContext is NULL.\r
+  @retval RETURN_UNSUPPORTED        The PE/COFF image is not supported.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderGetImageInfo (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+    return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().\r
+\r
+  If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of\r
+  ImageContext as the relocation base address.  Otherwise, use the DestinationAddress field\r
+  of ImageContext as the relocation base address.  The caller must allocate the relocation\r
+  fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.  \r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext        Pointer to the image context structure that describes the PE/COFF\r
+                              image that is being relocated.\r
+\r
+  @retval RETURN_SUCCESS      The PE/COFF image was relocated.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR   The image in not a valid PE/COFF image.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_UNSUPPORTED  A relocation record type is not supported.\r
+                              Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderRelocateImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  Loads a PE/COFF image into memory.\r
+\r
+  Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer\r
+  specified by the ImageAddress and ImageSize fields of ImageContext.  The caller must allocate\r
+  the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.\r
+  The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.\r
+  If ImageContext is NULL, then ASSERT().\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image that is being loaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was loaded into the buffer specified by\r
+                                    the ImageAddress and ImageSize fields of ImageContext.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_BUFFER_TOO_SMALL   The caller did not provide a large enough buffer.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_LOAD_ERROR         The PE/COFF image is an EFI Runtime image with no relocations.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+  @retval RETURN_INVALID_PARAMETER  The image address is invalid.\r
+                                    Extended status information is in the ImageError field of ImageContext.\r
+\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderLoadImage (\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT  *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
+\r
+/**\r
+  ImageRead function that operates on a memory buffer whos base is passed into\r
+  FileHandle. \r
+\r
+  @param  FileHandle        Ponter to baes of the input stream\r
+  @param  FileOffset        Offset to the start of the buffer\r
+  @param  ReadSize          Number of bytes to copy into the buffer\r
+  @param  Buffer            Location to place results of read\r
+\r
+  @retval RETURN_SUCCESS    Data is read from FileOffset from the Handle into \r
+                            the buffer.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderImageReadFromMemory (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+{\r
+  return RETURN_UNSUPPORTED;\r
+}\r
+\r
+\r
+/**\r
+  Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI\r
+  runtime. \r
+  \r
+  PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply\r
+  the fixups with a virtual mapping.\r
+\r
+\r
+  @param  ImageBase          Base address of relocated image\r
+  @param  VirtImageBase      Virtual mapping for ImageBase\r
+  @param  ImageSize          Size of the image to relocate\r
+  @param  RelocationData     Location to place results of read\r
+  \r
+**/\r
+VOID\r
+EFIAPI\r
+PeCoffLoaderRelocateImageForRuntime (\r
+  IN  PHYSICAL_ADDRESS        ImageBase,\r
+  IN  PHYSICAL_ADDRESS        VirtImageBase,\r
+  IN  UINTN                   ImageSize,\r
+  IN  VOID                    *RelocationData\r
+  )\r
+{\r
+}\r
+\r
+/**\r
+  Unloads a loaded PE/COFF image from memory and releases its taken resource.\r
+   \r
+  For Unix emulator, the PE/COFF image loaded by system needs to release.\r
+  For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded, \r
+  this function can simply return RETURN_SUCCESS.\r
+\r
+  @param  ImageContext              Pointer to the image context structure that describes the PE/COFF\r
+                                    image to be unloaded.\r
+\r
+  @retval RETURN_SUCCESS            The PE/COFF image was unloaded successfully.\r
+**/\r
+RETURN_STATUS\r
+EFIAPI\r
+PeCoffLoaderUnloadImage (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);\r
+}\r
diff --git a/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf b/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf
new file mode 100644 (file)
index 0000000..7be9c26
--- /dev/null
@@ -0,0 +1,50 @@
+#/** @file\r
+# PeCoff libary for PEIM modules that run Unix emulator.\r
+#\r
+# Lib to provide memory journal status code reporting Routines\r
+# Copyright (c) 2007 - 2008, 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
+#\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiUnixPeCoffLib\r
+  FILE_GUID                      = 91404129-c58a-40bb-8a2b-f05bc05a961c\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PeCoffLib|PEIM\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = PeiUnixPeCoffLibConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+\r
+[Sources.common]\r
+  PeiUnixPeCoffLib.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  HobLib\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                # ALWAYS_CONSUMED\r
+\r
diff --git a/UnixPkg/Library/UnixBdsLib/BdsPlatform.c b/UnixPkg/Library/UnixBdsLib/BdsPlatform.c
new file mode 100644 (file)
index 0000000..7e02767
--- /dev/null
@@ -0,0 +1,514 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, 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
+\r
+  BdsPlatform.c\r
+\r
+Abstract:\r
+\r
+  This file include all platform action which can be customized\r
+  by IBV/OEM.\r
+\r
+--*/\r
+\r
+#include "BdsPlatform.h"\r
+\r
+CHAR16  mFirmwareVendor[] = L"TianoCore.org";\r
+\r
+//\r
+// BDS Platform Functions\r
+//\r
+VOID\r
+PlatformBdsInit (\r
+  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Platform Bds init. Incude the platform firmware vendor, revision\r
+  and so crc check.\r
+\r
+Arguments:\r
+\r
+  PrivateData  - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
+\r
+Returns:\r
+\r
+  None.\r
+\r
+--*/\r
+{\r
+  //\r
+  // set firmwarevendor, here can be IBV/OEM customize\r
+  //\r
+  gST->FirmwareVendor = AllocateRuntimeCopyPool (\r
+                          sizeof (mFirmwareVendor),\r
+                          &mFirmwareVendor\r
+                          );\r
+  ASSERT (gST->FirmwareVendor != NULL);\r
+\r
+  gST->FirmwareRevision = 0;\r
+\r
+  //\r
+  // Fixup Tasble CRC after we updated Firmware Vendor and Revision\r
+  //\r
+  gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);\r
+\r
+}\r
+\r
+EFI_STATUS\r
+PlatformBdsConnectConsole (\r
+  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Connect the predefined platform default console device. Always try to find\r
+  and enable the vga device if have.\r
+\r
+Arguments:\r
+\r
+  PlatformConsole         - Predfined platform default console device array.\r
\r
+Returns:\r
+\r
+  EFI_SUCCESS             - Success connect at least one ConIn and ConOut \r
+                            device, there must have one ConOut device is \r
+                            active vga device.\r
+  \r
+  EFI_STATUS              - Return the status of \r
+                            BdsLibConnectAllDefaultConsoles ()\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       Index;\r
+\r
+  Index   = 0;\r
+  Status  = EFI_SUCCESS;\r
+\r
+  //\r
+  // Have chance to connect the platform default console,\r
+  // the platform default console is the minimue device group\r
+  // the platform should support\r
+  //\r
+  while (PlatformConsole[Index].DevicePath != NULL) {\r
+    //\r
+    // Update the console variable with the connect type\r
+    //\r
+    if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {\r
+      BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);\r
+    }\r
+\r
+    if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {\r
+      BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);\r
+    }\r
+\r
+    if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {\r
+      BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);\r
+    }\r
+\r
+    Index++;\r
+  }\r
+  //\r
+  // Connect the all the default console with current cosole variable\r
+  //\r
+  Status = BdsLibConnectAllDefaultConsoles ();\r
+  return Status;\r
+}\r
+\r
+VOID\r
+PlatformBdsConnectSequence (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Connect with predeined platform connect sequence, \r
+  the OEM/IBV can customize with their own connect sequence.\r
+  \r
+Arguments:\r
+\r
+  None.\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  Index = 0;\r
+\r
+  //\r
+  // Here we can get the customized platform connect sequence\r
+  // Notes: we can connect with new variable which record the\r
+  // last time boots connect device path sequence\r
+  //\r
+  while (gPlatformConnectSequence[Index] != NULL) {\r
+    //\r
+    // Build the platform boot option\r
+    //\r
+    BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);\r
+    Index++;\r
+  }\r
+\r
+  //\r
+  // Just use the simple policy to connect all devices\r
+  //\r
+  BdsLibConnectAll ();\r
+}\r
+\r
+VOID\r
+PlatformBdsGetDriverOption (\r
+  IN OUT LIST_ENTRY              *BdsDriverLists\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Load the predefined driver option, OEM/IBV can customize this\r
+  to load their own drivers\r
+  \r
+Arguments:\r
+\r
+  BdsDriverLists  - The header of the driver option link list.\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  UINTN Index;\r
+\r
+  Index = 0;\r
+\r
+  //\r
+  // Here we can get the customized platform driver option\r
+  //\r
+  while (gPlatformDriverOption[Index] != NULL) {\r
+    //\r
+    // Build the platform boot option\r
+    //\r
+    BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");\r
+    Index++;\r
+  }\r
+\r
+}\r
+\r
+VOID\r
+PlatformBdsDiagnostics (\r
+  IN EXTENDMEM_COVERAGE_LEVEL    MemoryTestLevel,\r
+  IN BOOLEAN                     QuietBoot\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform the platform diagnostic, such like test memory. OEM/IBV also\r
+  can customize this fuction to support specific platform diagnostic.\r
+  \r
+Arguments:\r
+\r
+  MemoryTestLevel  - The memory test intensive level\r
+  \r
+  QuietBoot        - Indicate if need to enable the quiet boot\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  //\r
+  // Here we can decide if we need to show\r
+  // the diagnostics screen\r
+  // Notes: this quiet boot code should be remove\r
+  // from the graphic lib\r
+  //\r
+  if (QuietBoot) {\r
+    EnableQuietBootEx (&gEfiDefaultBmpLogoGuid, mBdsImageHandle);\r
+    //\r
+    // Perform system diagnostic\r
+    //\r
+    Status = BdsMemoryTest (MemoryTestLevel);\r
+    if (EFI_ERROR (Status)) {\r
+      DisableQuietBoot ();\r
+    }\r
+\r
+    return ;\r
+  }\r
+  //\r
+  // Perform system diagnostic\r
+  //\r
+  Status = BdsMemoryTest (MemoryTestLevel);\r
+}\r
+\r
+VOID\r
+PlatformBdsPolicyBehavior (\r
+  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData,\r
+  IN OUT LIST_ENTRY                  *DriverOptionList,\r
+  IN OUT LIST_ENTRY                  *BootOptionList\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The function will excute with as the platform policy, current policy\r
+  is driven by boot mode. IBV/OEM can customize this code for their specific\r
+  policy action.\r
+  \r
+Arguments:\r
+\r
+  PrivateData      - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance\r
+  \r
+  DriverOptionList - The header of the driver option link list\r
+  \r
+  BootOptionList   - The header of the boot option link list\r
\r
+Returns:\r
+\r
+  None.\r
+  \r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINT16      Timeout;\r
+\r
+  //\r
+  // Init the time out value\r
+  //\r
+  Timeout = BdsLibGetTimeout ();\r
+\r
+  //\r
+  // Load the driver option as the driver option list\r
+  //\r
+  PlatformBdsGetDriverOption (DriverOptionList);\r
+\r
+  //\r
+  // Get current Boot Mode\r
+  //\r
+  Status = BdsLibGetBootMode (&PrivateData->BootMode);\r
+\r
+  //\r
+  // Go the different platform policy with different boot mode\r
+  // Notes: this part code can be change with the table policy\r
+  //\r
+  switch (PrivateData->BootMode) {\r
+\r
+  case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:\r
+  case BOOT_WITH_MINIMAL_CONFIGURATION:\r
+    //\r
+    // In no-configuration boot mode, we can connect the\r
+    // console directly.\r
+    //\r
+    BdsLibConnectAllDefaultConsoles ();\r
+    PlatformBdsDiagnostics (IGNORE, TRUE);\r
+\r
+    //\r
+    // Perform some platform specific connect sequence\r
+    //\r
+    PlatformBdsConnectSequence ();\r
+\r
+    //\r
+    // Notes: current time out = 0 can not enter the\r
+    // front page\r
+    //\r
+    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
+\r
+    //\r
+    // Check the boot option with the boot option list\r
+    //\r
+    BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");\r
+    break;\r
+\r
+  case BOOT_ON_FLASH_UPDATE:\r
+    //\r
+    // Boot with the specific configuration\r
+    //\r
+    PlatformBdsConnectConsole (gPlatformConsole);\r
+    PlatformBdsDiagnostics (EXTENSIVE, FALSE);\r
+    BdsLibConnectAll ();\r
+    ProcessCapsules (BOOT_ON_FLASH_UPDATE);\r
+    break;\r
+\r
+  case BOOT_IN_RECOVERY_MODE:\r
+    //\r
+    // In recovery mode, just connect platform console\r
+    // and show up the front page\r
+    //\r
+    PlatformBdsConnectConsole (gPlatformConsole);\r
+    PlatformBdsDiagnostics (EXTENSIVE, FALSE);\r
+\r
+    //\r
+    // In recovery boot mode, we still enter to the\r
+    // frong page now\r
+    //\r
+    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
+    break;\r
+\r
+  case BOOT_WITH_FULL_CONFIGURATION:\r
+  case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:\r
+  case BOOT_WITH_DEFAULT_SETTINGS:\r
+  default:\r
+    //\r
+    // Connect platform console\r
+    //\r
+    Status = PlatformBdsConnectConsole (gPlatformConsole);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Here OEM/IBV can customize with defined action\r
+      //\r
+      PlatformBdsNoConsoleAction ();\r
+    }\r
+\r
+    PlatformBdsDiagnostics (IGNORE, TRUE);\r
+\r
+    //\r
+    // Perform some platform specific connect sequence\r
+    //\r
+    PlatformBdsConnectSequence ();\r
+\r
+    //\r
+    // Give one chance to enter the setup if we\r
+    // have the time out\r
+    //\r
+    PlatformBdsEnterFrontPage (Timeout, FALSE);\r
+\r
+    //\r
+    // Here we have enough time to do the enumeration of boot device\r
+    //\r
+    BdsLibEnumerateAllBootOption (BootOptionList);\r
+    break;\r
+  }\r
+\r
+  return ;\r
+\r
+}\r
+\r
+VOID\r
+PlatformBdsBootSuccess (\r
+  IN  BDS_COMMON_OPTION   *Option\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  Hook point after a boot attempt succeeds. We don't expect a boot option to\r
+  return, so the EFI 1.0 specification defines that you will default to an\r
+  interactive mode and stop processing the BootOrder list in this case. This\r
+  is alos a platform implementation and can be customized by IBV/OEM.\r
+\r
+Arguments:\r
+\r
+  Option - Pointer to Boot Option that succeeded to boot.\r
+\r
+Returns:\r
+  \r
+  None.\r
+\r
+--*/\r
+{\r
+  CHAR16  *TmpStr;\r
+\r
+  //\r
+  // If Boot returned with EFI_SUCCESS and there is not in the boot device\r
+  // select loop then we need to pop up a UI and wait for user input.\r
+  //\r
+  TmpStr = Option->StatusString;\r
+  if (TmpStr != NULL) {\r
+    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
+    FreePool (TmpStr);\r
+  }\r
+}\r
+\r
+VOID\r
+PlatformBdsBootFail (\r
+  IN  BDS_COMMON_OPTION  *Option,\r
+  IN  EFI_STATUS         Status,\r
+  IN  CHAR16             *ExitData,\r
+  IN  UINTN              ExitDataSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  Hook point after a boot attempt fails.\r
+\r
+Arguments:\r
+  \r
+  Option - Pointer to Boot Option that failed to boot.\r
+\r
+  Status - Status returned from failed boot.\r
+\r
+  ExitData - Exit data returned from failed boot.\r
+\r
+  ExitDataSize - Exit data size returned from failed boot.\r
+\r
+Returns:\r
+  \r
+  None.\r
+\r
+--*/\r
+{\r
+  CHAR16  *TmpStr;\r
+\r
+  //\r
+  // If Boot returned with failed status then we need to pop up a UI and wait\r
+  // for user input.\r
+  //\r
+  TmpStr = Option->StatusString;\r
+  if (TmpStr != NULL) {\r
+    BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);\r
+    FreePool (TmpStr);\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+PlatformBdsNoConsoleAction (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  \r
+  This function is remained for IBV/OEM to do some platform action,\r
+  if there no console device can be connected.\r
+\r
+Arguments:\r
+  \r
+  None.\r
+  \r
+Returns:\r
+  \r
+  EFI_SUCCESS      - Direct return success now.\r
+\r
+--*/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PlatformBdsLockNonUpdatableFlash (\r
+  VOID\r
+  )\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/Library/UnixBdsLib/BdsPlatform.h b/UnixPkg/Library/UnixBdsLib/BdsPlatform.h
new file mode 100644 (file)
index 0000000..32587b6
--- /dev/null
@@ -0,0 +1,165 @@
+/*++\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
+\r
+  BdsPlatform.h\r
+\r
+Abstract:\r
+\r
+  Head file for BDS Platform specific code\r
+\r
+--*/\r
+\r
+#ifndef _BDS_PLATFORM_H\r
+#define _BDS_PLATFORM_H\r
+\r
+#include <PiDxe.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/GenericBdsLib.h>\r
+#include <Library/PlatformBdsLib.h>\r
+#include <Library/GraphicsLib.h>\r
+\r
+#include <Protocol/UnixThunk.h>\r
+#include <Protocol/UnixIo.h>\r
+#include <Guid/Bmp.h>\r
+\r
+extern BDS_CONSOLE_CONNECT_ENTRY  gPlatformConsole[];\r
+extern EFI_DEVICE_PATH_PROTOCOL   *gPlatformConnectSequence[];\r
+extern EFI_DEVICE_PATH_PROTOCOL   *gPlatformDriverOption[];\r
+\r
+#define gEndEntire \\r
+  { \\r
+    END_DEVICE_PATH_TYPE,\\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\\r
+    END_DEVICE_PATH_LENGTH,\\r
+    0\\r
+  }\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH  VendorDevicePath;\r
+  UINT32              Instance;\r
+} UNIX_VENDOR_DEVICE_PATH_NODE;\r
+\r
+//\r
+// Below is the platform console device path\r
+//\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH              UnixBus;\r
+  UNIX_VENDOR_DEVICE_PATH_NODE  SerialDevice;\r
+  UART_DEVICE_PATH                Uart;\r
+  VENDOR_DEVICE_PATH              TerminalType;\r
+  EFI_DEVICE_PATH_PROTOCOL        End;\r
+} UNIX_ISA_SERIAL_DEVICE_PATH;\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH              UnixBus;\r
+  UNIX_VENDOR_DEVICE_PATH_NODE  UnixUgaDevice;\r
+  EFI_DEVICE_PATH_PROTOCOL        End;\r
+} UNIX_PLATFORM_UGA_DEVICE_PATH;\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH              UnixBus;\r
+  UNIX_VENDOR_DEVICE_PATH_NODE   ConsoleDevice;\r
+  EFI_DEVICE_PATH_PROTOCOL        End;\r
+} UNIX_CONSOLE_DEVICE_PATH;\r
+//\r
+// Platform BDS Functions\r
+//\r
+VOID\r
+PlatformBdsInit (\r
+  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData\r
+  )\r
+;\r
+\r
+VOID\r
+PlatformBdsPolicyBehavior (\r
+  IN EFI_BDS_ARCH_PROTOCOL_INSTANCE  *PrivateData,\r
+  IN LIST_ENTRY                      *DriverOptionList,\r
+  IN LIST_ENTRY                      *BootOptionList\r
+  )\r
+;\r
+\r
+VOID\r
+PlatformBdsGetDriverOption (\r
+  IN LIST_ENTRY               *BdsDriverLists\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+BdsMemoryTest (\r
+  EXTENDMEM_COVERAGE_LEVEL Level\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+PlatformBdsShowProgress (\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground,\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground,\r
+  CHAR16                        *Title,\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor,\r
+  UINTN                         Progress,\r
+  UINTN                         PreviousValue\r
+  )\r
+;\r
+\r
+VOID\r
+PlatformBdsConnectSequence (\r
+  VOID\r
+  )\r
+;\r
+\r
+VOID\r
+PlatformBdsBootFail (\r
+  IN  BDS_COMMON_OPTION  *Option,\r
+  IN  EFI_STATUS         Status,\r
+  IN  CHAR16             *ExitData,\r
+  IN  UINTN              ExitDataSize\r
+  )\r
+;\r
+\r
+VOID\r
+PlatformBdsBootSuccess (\r
+  IN  BDS_COMMON_OPTION *Option\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+ProcessCapsules (\r
+  EFI_BOOT_MODE BootMode\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+PlatformBdsConnectConsole (\r
+  IN BDS_CONSOLE_CONNECT_ENTRY   *PlatformConsole\r
+  )\r
+;\r
+\r
+EFI_STATUS\r
+PlatformBdsNoConsoleAction (\r
+  VOID\r
+  )\r
+;\r
+\r
+VOID\r
+PlatformBdsEnterFrontPage (\r
+  IN UINT16                 TimeoutDefault,\r
+  IN BOOLEAN                ConnectAllHappened\r
+  );\r
+\r
+#endif // _BDS_PLATFORM_H\r
diff --git a/UnixPkg/Library/UnixBdsLib/PlatformBds.inf b/UnixPkg/Library/UnixBdsLib/PlatformBds.inf
new file mode 100644 (file)
index 0000000..3ce8ff6
--- /dev/null
@@ -0,0 +1,80 @@
+#/** @file\r
+# Platfrom BDS driver\r
+#\r
+# Do platform action customized by IBV/OEM.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PlatformBdsLib\r
+  FILE_GUID                      = f392b762-8985-11db-be87-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = PlatformBdsLib|DXE_DRIVER   \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = BdsInitialize\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  BdsPlatform.c\r
+  BdsPlatform.h\r
+  PlatformData.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+#  EdkGenericPlatformBdsLib\r
+#  HiiLib\r
+#  DevicePathLib\r
+#  UefiRuntimeServicesTableLib\r
+#  UefiBootServicesTableLib\r
+#  BaseMemoryLib\r
+#  MemoryAllocationLib\r
+#  EdkGenericBdsLib\r
+#  HobLib\r
+#  ReportStatusCodeLib\r
+#  EdkIfrSupportLib\r
+#  PrintLib\r
+#  PerformanceLib\r
+#  DxeServicesTableLib\r
+#  EdkGraphicsLib\r
+#  BaseLib\r
+#  UefiDriverEntryPoint\r
+#  UefiLib\r
+#  DebugLib\r
+\r
+\r
+  BaseLib\r
+  MemoryAllocationLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  DebugLib\r
+  PcdLib\r
+  GraphicsLib\r
+  GenericBdsLib\r
+\r
+\r
+[Guids]\r
+  gEfiDefaultBmpLogoGuid                        # ALWAYS_CONSUMED
\ No newline at end of file
diff --git a/UnixPkg/Library/UnixBdsLib/PlatformBds.msa b/UnixPkg/Library/UnixBdsLib/PlatformBds.msa
new file mode 100644 (file)
index 0000000..9891175
--- /dev/null
@@ -0,0 +1,206 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <MsaHeader>
+    <ModuleName>Bds</ModuleName>
+    <ModuleType>DXE_DRIVER</ModuleType>
+    <GuidValue>f392b762-8985-11db-be87-0040d02b1835</GuidValue>
+    <Version>1.0</Version>
+    <Abstract>Platfrom BDS driver</Abstract>
+    <Description>Do platform action customized by IBV/OEM.</Description>
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>
+    <License>All rights reserved. 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
+      http://opensource.org/licenses/bsd-license.php
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>
+  </MsaHeader>
+  <ModuleDefinitions>
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
+    <BinaryModule>false</BinaryModule>
+    <OutputFileBasename>Bds</OutputFileBasename>
+  </ModuleDefinitions>
+  <LibraryClassDefinitions>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>DebugLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>UefiLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>UefiDriverEntryPoint</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>BaseLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>EdkGraphicsLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>DxeServicesTableLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>PerformanceLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>PrintLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>EdkIfrSupportLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>ReportStatusCodeLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>HobLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>EdkGenericBdsLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>MemoryAllocationLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>BaseMemoryLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>UefiBootServicesTableLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>UefiRuntimeServicesTableLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>DevicePathLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>HiiLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>EdkGenericPlatformBdsLib</Keyword>
+    </LibraryClass>
+  </LibraryClassDefinitions>
+  <SourceFiles>
+    <Filename>PlatformData.c</Filename>
+    <Filename>BdsPlatform.h</Filename>
+    <Filename>BdsPlatform.c</Filename>
+    <Filename>Bds.dxs</Filename>
+  </SourceFiles>
+  <PackageDependencies>
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>
+  </PackageDependencies>
+  <Protocols>
+    <Protocol Usage="ALWAYS_PRODUCED">
+      <ProtocolCName>gEfiBdsArchProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiLegacyBiosProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiFormCallbackProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiDataHubProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiFormBrowserProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiConsoleControlProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiCpuIoProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiUgaDrawProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiLoadFileProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiSimpleFileSystemProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiSerialIoProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiGenericMemTestProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="SOMETIMES_CONSUMED">
+      <ProtocolCName>gEfiCpuArchProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="SOMETIMES_CONSUMED">
+      <ProtocolCName>gEfiDriverBindingProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>
+    </Protocol>
+    <Protocol Usage="ALWAYS_CONSUMED">
+      <ProtocolCName>gEfiUnixUgaIoProtocolGuid</ProtocolCName>
+    </Protocol>
+  </Protocols>
+  <DataHubs>
+    <DataHubRecord Usage="SOMETIMES_CONSUMED">
+      <DataHubCName>BiosVendor</DataHubCName>
+    </DataHubRecord>
+    <DataHubRecord Usage="SOMETIMES_CONSUMED">
+      <DataHubCName>SystemManufacturer</DataHubCName>
+    </DataHubRecord>
+    <DataHubRecord Usage="SOMETIMES_CONSUMED">
+      <DataHubCName>ProcessorVersion</DataHubCName>
+    </DataHubRecord>
+    <DataHubRecord Usage="SOMETIMES_CONSUMED">
+      <DataHubCName>ProcessorFrequency</DataHubCName>
+    </DataHubRecord>
+    <DataHubRecord Usage="SOMETIMES_CONSUMED">
+      <DataHubCName>MemoryArray</DataHubCName>
+    </DataHubRecord>
+    <DataHubRecord Usage="SOMETIMES_CONSUMED">
+      <DataHubCName>SerialIoDevice</DataHubCName>
+    </DataHubRecord>
+    <DataHubRecord Usage="SOMETIMES_CONSUMED">
+      <DataHubCName>SerialIoPort</DataHubCName>
+    </DataHubRecord>
+  </DataHubs>
+  <Guids>
+    <GuidCNames Usage="ALWAYS_CONSUMED">
+      <GuidCName>gEfiBootStateGuid</GuidCName>
+    </GuidCNames>
+    <GuidCNames Usage="ALWAYS_CONSUMED">
+      <GuidCName>gEfiGlobalVariableGuid</GuidCName>
+    </GuidCNames>
+    <GuidCNames Usage="ALWAYS_CONSUMED">
+      <GuidCName>gEfiFlashMapHobGuid</GuidCName>
+    </GuidCNames>
+    <GuidCNames Usage="ALWAYS_CONSUMED">
+      <GuidCName>gEfiFileSystemVolumeLabelInfoIdGuid</GuidCName>
+    </GuidCNames>
+    <GuidCNames Usage="ALWAYS_CONSUMED">
+      <GuidCName>gEfiFileInfoGuid</GuidCName>
+    </GuidCNames>
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiDefaultBmpLogoGuid</GuidCName>\r
+    </GuidCNames>
+  </Guids>
+  <Externs>
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+    <Extern>
+      <ModuleEntryPoint>BdsInitialize</ModuleEntryPoint>
+    </Extern>
+  </Externs>
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/UnixPkg/Library/UnixBdsLib/PlatformData.c b/UnixPkg/Library/UnixBdsLib/PlatformData.c
new file mode 100644 (file)
index 0000000..cf1b55c
--- /dev/null
@@ -0,0 +1,120 @@
+/*++\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
+\r
+  PlatformData.c\r
+\r
+Abstract:\r
+  \r
+  Defined the platform specific device path which will be used by\r
+  platform Bbd to perform the platform policy connect.\r
+\r
+--*/\r
+\r
+#include "BdsPlatform.h"\r
+\r
+//\r
+// Predefined platform default time out value\r
+//\r
+UINT16                      gPlatformBootTimeOutDefault = 10;\r
+\r
+//\r
+// Platform specific keyboard device path\r
+//\r
+UNIX_PLATFORM_UGA_DEVICE_PATH gUgaDevicePath0 = \r
+{\r
+  {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
+      (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8),\r
+      EFI_UNIX_THUNK_PROTOCOL_GUID\r
+  },\r
+  {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      (UINT8) (sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)),\r
+      (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8),\r
+      EFI_UNIX_UGA_GUID,\r
+      0\r
+  },\r
+  gEndEntire\r
+};\r
+\r
+UNIX_PLATFORM_UGA_DEVICE_PATH gUgaDevicePath1 = {\r
+  {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
+      (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8),\r
+      EFI_UNIX_THUNK_PROTOCOL_GUID\r
+  },\r
+  {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      (UINT8) (sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)),\r
+      (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8),\r
+      EFI_UNIX_UGA_GUID,\r
+      1\r
+  },\r
+  gEndEntire\r
+};\r
+\r
+UNIX_CONSOLE_DEVICE_PATH   gUnixConsoleDevicePath = {\r
+  {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
+      (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8),\r
+      EFI_UNIX_THUNK_PROTOCOL_GUID\r
+  },\r
+  {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      (UINT8) (sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)),\r
+      (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8),\r
+      EFI_UNIX_CONSOLE_GUID,\r
+      0  \r
+  },   \r
+  gEndEntire\r
+};\r
+//\r
+// Predefined platform default console device path\r
+//\r
+BDS_CONSOLE_CONNECT_ENTRY   gPlatformConsole[] = {\r
+  {\r
+    (EFI_DEVICE_PATH_PROTOCOL *) &gUnixConsoleDevicePath,\r
+    (CONSOLE_OUT | CONSOLE_IN)\r
+  },\r
+  {\r
+    (EFI_DEVICE_PATH_PROTOCOL *) &gUgaDevicePath0,\r
+    (CONSOLE_OUT | CONSOLE_IN)\r
+  },\r
+  {\r
+    (EFI_DEVICE_PATH_PROTOCOL *) &gUgaDevicePath1,\r
+    (CONSOLE_OUT | CONSOLE_IN)\r
+  },\r
+  {\r
+    NULL,\r
+    0\r
+  }\r
+};\r
+\r
+//\r
+// Predefined platform specific driver option\r
+//\r
+EFI_DEVICE_PATH_PROTOCOL    *gPlatformDriverOption[] = { NULL };\r
+\r
+//\r
+// Predefined platform connect sequence\r
+//\r
+EFI_DEVICE_PATH_PROTOCOL    *gPlatformConnectSequence[] = { NULL };\r
diff --git a/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoader.c b/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoader.c
new file mode 100644 (file)
index 0000000..28ce4ef
--- /dev/null
@@ -0,0 +1,54 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  TianoPeCoffLoader.c\r
+\r
+Abstract:\r
+\r
+  Wrap the Base PE/COFF loader with the PE COFF Protocol\r
+\r
+\r
+--*/\r
+\r
+#include <Guid/PeiPeCoffLoader.h>\r
+\r
+#include <Library/EdkPeCoffLoaderLib.h>\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL  *mPeiEfiPeiPeCoffLoader;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeCoffLoaderConstructor (\r
+  IN EFI_FFS_FILE_HEADER      *FfsHeader,\r
+  IN EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Status = (*PeiServices)->LocatePpi (\r
+                            PeiServices,\r
+                            &gEfiPeiPeCoffLoaderGuid,\r
+                            0,\r
+                            NULL,\r
+                            (VOID **)&mPeiEfiPeiPeCoffLoader\r
+                            );\r
+  return Status;\r
+}\r
+\r
+EFI_PEI_PE_COFF_LOADER_PROTOCOL *\r
+EFIAPI\r
+GetPeCoffLoaderProtocol (\r
+  )\r
+{\r
+  return mPeiEfiPeiPeCoffLoader;\r
+}\r
diff --git a/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.inf b/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.inf
new file mode 100644 (file)
index 0000000..fcb7839
--- /dev/null
@@ -0,0 +1,41 @@
+#/** @file\r
+# Component description file for the Nt32PeCoffLoaderLib library.\r
+#\r
+# EdkPeCoffLoaderLib library class for NT32 instance implemented by PeiPeCoffLoader PPI.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixPeCoffLoaderLib\r
+  FILE_GUID                      = f3cf597e-8985-11db-95f6-0040d02b1835\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  LIBRARY_CLASS                  = EdkPeCoffLoaderLib \r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  CONSTRUCTOR                    = PeCoffLoaderConstructor\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  UnixPeCoffLoader.c\r
+\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                       # SOMETIMES_CONSUMED\r
+\r
diff --git a/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.msa b/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.msa
new file mode 100644 (file)
index 0000000..60f5e24
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>UnixPeCoffLoaderLib</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>f3cf597e-8985-11db-95f6-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for the Nt32PeCoffLoaderLib library.</Abstract>\r
+    <Description>EdkPeCoffLoaderLib library class for NT32 instance implemented by PeiPeCoffLoader PPI.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixPeCoffLoaderLib</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_PRODUCED">\r
+      <Keyword>EdkPeCoffLoaderLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixPeCoffLoader.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Guids>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiPeiPeCoffLoaderGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <Constructor>PeCoffLoaderConstructor</Constructor>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/MetronomeDxe/Metronome.c b/UnixPkg/MetronomeDxe/Metronome.c
new file mode 100644 (file)
index 0000000..f018e7f
--- /dev/null
@@ -0,0 +1,140 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  Metronome.c\r
+\r
+Abstract:\r
+\r
+  UNIX Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include "UnixDxe.h"\r
+#include <Protocol/Metronome.h>\r
+#include "Metronome.h"\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UnixLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+//\r
+// Global Variables\r
+//\r
+EFI_METRONOME_ARCH_PROTOCOL mMetronome = {\r
+  UnixMetronomeDriverWaitForTick,\r
+  TICK_PERIOD\r
+};\r
+\r
+//\r
+// Worker Functions\r
+//\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixMetronomeDriverWaitForTick (\r
+  IN EFI_METRONOME_ARCH_PROTOCOL  *This,\r
+  IN UINT32                       TickNumber\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  The WaitForTick() function waits for the number of ticks specified by\r
+  TickNumber from a known time source in the platform.  If TickNumber of\r
+  ticks are detected, then EFI_SUCCESS is returned.  The actual time passed\r
+  between entry of this function and the first tick is between 0 and\r
+  TickPeriod 100 nS units.  If you want to guarantee that at least TickPeriod\r
+  time has elapsed, wait for two ticks.  This function waits for a hardware\r
+  event to determine when a tick occurs.  It is possible for interrupt\r
+  processing, or exception processing to interrupt the execution of the\r
+  WaitForTick() function.  Depending on the hardware source for the ticks, it\r
+  is possible for a tick to be missed.  This function cannot guarantee that\r
+  ticks will not be missed.  If a timeout occurs waiting for the specified\r
+  number of ticks, then EFI_TIMEOUT is returned.\r
+\r
+Arguments:\r
+\r
+  This       - The EFI_METRONOME_ARCH_PROTOCOL instance.\r
+  TickNumber - Number of ticks to wait.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - The wait for the number of ticks specified by TickNumber\r
+                succeeded.\r
+\r
+--*/\r
+{\r
+  UINT64  SleepTime;\r
+\r
+  //\r
+  // Calculate the time to sleep.  Win API smallest unit to sleep is 1 millisec\r
+  // Tick Period is in 100ns units, divide by 10000 to convert to ms\r
+  //\r
+  SleepTime = DivU64x32 (MultU64x32 ((UINT64) TickNumber, TICK_PERIOD) + 9999, 10000);\r
+  gUnix->Sleep ((UINT32) SleepTime);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixMetronomeDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialize the Metronome Architectural Protocol driver\r
+\r
+Arguments:\r
+\r
+  ImageHandle - ImageHandle of the loaded driver\r
+\r
+\r
+  SystemTable - Pointer to the System Table\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Metronome Architectural Protocol created\r
+\r
+  EFI_OUT_OF_RESOURCES  - Not enough resources available to initialize driver.\r
+\r
+  EFI_DEVICE_ERROR      - A device error occured attempting to initialize the driver.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+\r
+  //\r
+  // Install the Metronome Architectural Protocol onto a new handle\r
+  //\r
+  Handle = NULL;\r
+  DEBUG ((EFI_D_ERROR, "*******************file %d line %d\n", __FUNCTION__, __LINE__));\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiMetronomeArchProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mMetronome\r
+                  );\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/MetronomeDxe/Metronome.h b/UnixPkg/MetronomeDxe/Metronome.h
new file mode 100644 (file)
index 0000000..10e6dc9
--- /dev/null
@@ -0,0 +1,84 @@
+/*++\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
+\r
+  Metronome.h\r
+\r
+Abstract:\r
+\r
+  UNIX Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
+\r
+--*/\r
+\r
+#ifndef _UNIX_THUNK_METRONOME_H_\r
+#define _UNIX_THUNK_METRONOME_H_\r
+\r
+\r
+\r
+//\r
+// Period of on tick in 100 nanosecond units\r
+//\r
+#define TICK_PERIOD 2000\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixMetronomeDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ImageHandle - TODO: add argument description\r
+  SystemTable - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixMetronomeDriverWaitForTick (\r
+  IN EFI_METRONOME_ARCH_PROTOCOL  *This,\r
+  IN UINT32                       TickNumber\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  TickNumber  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/UnixPkg/MetronomeDxe/Metronome.inf b/UnixPkg/MetronomeDxe/Metronome.inf
new file mode 100644 (file)
index 0000000..8b1c58d
--- /dev/null
@@ -0,0 +1,60 @@
+#/** @file\r
+# Unix Emulation Metronome Architectural Protocol Driver as defined in DXE CIS\r
+#\r
+# This metronome module simulates metronome by Sleep WinAPI.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Metronome\r
+  FILE_GUID                      = f348f6fe-8985-11db-b4c3-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = UnixMetronomeDriverInitialize\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  Metronome.h\r
+  Metronome.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+  \r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  UnixLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Protocols]\r
+  gEfiMetronomeArchProtocolGuid                 # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/UnixPkg/MetronomeDxe/Metronome.msa b/UnixPkg/MetronomeDxe/Metronome.msa
new file mode 100644 (file)
index 0000000..a64f1ea
--- /dev/null
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>Metronome</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f348f6fe-8985-11db-b4c3-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Unix Emulation Metronome Architectural Protocol Driver as defined in DXE CIS</Abstract>\r
+    <Description>\r
+      This metronome module simulates metronome by Sleep WinAPI.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>Metronome</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UnixLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Metronome.c</Filename>\r
+    <Filename>Metronome.h</Filename>\r
+    <Filename>Metronome.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiMetronomeArchProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>UnixMetronomeDriverInitialize</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni
new file mode 100644 (file)
index 0000000..14a6893
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c
new file mode 100644 (file)
index 0000000..14c7ef0
--- /dev/null
@@ -0,0 +1,57 @@
+/*++\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
+\r
+  MiscBaseBoardManufacturerData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_BASE_BOARD_MANUFACTURER_DATA, MiscBaseBoardManufacturer) = {\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_MANUFACTURER),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_PRODUCT_NAME),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_VERSION),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_SERIAL_NUMBER),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_ASSET_TAG),\r
+  STRING_TOKEN(STR_MISC_BASE_BOARD_CHASSIS_LOCATION),\r
+  {                         // BaseBoardFeatureFlags\r
+    1,                      // Motherboard\r
+    0,                      // RequiresDaughterCard\r
+    0,                      // Removable\r
+    1,                      // Replaceable,\r
+    0,                      // HotSwappable\r
+    0,                      // Reserved\r
+  },\r
+  EfiBaseBoardTypeUnknown,  // BaseBoardType\r
+  {                         // BaseBoardChassisLink\r
+    EFI_MISC_SUBCLASS_GUID, // ProducerName\r
+    1,                      // Instance\r
+    1,                      // SubInstance\r
+  },\r
+  0,                        // BaseBoardNumberLinks\r
+  {                         // LinkN\r
+    EFI_MISC_SUBCLASS_GUID, // ProducerName\r
+    1,                      // Instance\r
+    1,                      // SubInstance\r
+  },\r
+};\r
+\r
+/* eof - MiscBaseBoardManufacturerData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni
new file mode 100644 (file)
index 0000000..b1e7e52
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c
new file mode 100644 (file)
index 0000000..61d60e2
--- /dev/null
@@ -0,0 +1,88 @@
+/*++\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
+\r
+  MiscBiosVendorData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_BIOS_VENDOR_DATA, MiscBiosVendor) = {\r
+  STRING_TOKEN(STR_MISC_BIOS_VENDOR),       // BiosVendor\r
+  STRING_TOKEN(STR_MISC_BIOS_VERSION),      // BiosVersion\r
+  STRING_TOKEN(STR_MISC_BIOS_RELEASE_DATE), // BiosReleaseDate\r
+  0xBABE, // BiosStartingAddress\r
+  {       // BiosPhysicalDeviceSize\r
+    2,    // Value\r
+    3,    // Exponent\r
+  },\r
+  {       // BiosCharacteristics1\r
+    0,    // Reserved1                         :2\r
+    0,    // Unknown                           :1\r
+    1,    // BiosCharacteristicsNotSupported   :1\r
+    0,    // IsaIsSupported                    :1\r
+    0,    // McaIsSupported                    :1\r
+    0,    // EisaIsSupported                   :1\r
+    0,    // PciIsSupported                    :1\r
+    0,    // PcmciaIsSupported                 :1\r
+    0,    // PlugAndPlayIsSupported            :1\r
+    0,    // ApmIsSupported                    :1\r
+    0,    // BiosIsUpgradable                  :1\r
+    0,    // BiosShadowingAllowed              :1\r
+    0,    // VlVesaIsSupported                 :1\r
+    0,    // EscdSupportIsAvailable            :1\r
+    0,    // BootFromCdIsSupported             :1\r
+    0,    // SelectableBootIsSupported         :1\r
+    0,    // RomBiosIsSocketed                 :1\r
+    0,    // BootFromPcmciaIsSupported         :1\r
+    0,    // EDDSpecificationIsSupported       :1\r
+    0,    // JapaneseNecFloppyIsSupported      :1\r
+    0,    // JapaneseToshibaFloppyIsSupported  :1\r
+    0,    // Floppy525_360IsSupported          :1\r
+    0,    // Floppy525_12IsSupported           :1\r
+    0,    // Floppy35_720IsSupported           :1\r
+    0,    // Floppy35_288IsSupported           :1\r
+    0,    // PrintScreenIsSupported            :1\r
+    0,    // Keyboard8042IsSupported           :1\r
+    0,    // SerialIsSupported                 :1\r
+    0,    // PrinterIsSupported                :1\r
+    0,    // CgaMonoIsSupported                :1\r
+    0,    // NecPc98                           :1\r
+    0,    // AcpiIsSupported                   :1\r
+    0,    // UsbLegacyIsSupported              :1\r
+    0,    // AgpIsSupported                    :1\r
+    0,    // I20BootIsSupported                :1\r
+    0,    // Ls120BootIsSupported              :1\r
+    0,    // AtapiZipDriveBootIsSupported      :1\r
+    0,    // Boot1394IsSupported               :1\r
+    0,    // SmartBatteryIsSupported           :1\r
+    0,    // BiosBootSpecIsSupported           :1\r
+    0,    // FunctionKeyNetworkBootIsSupported :1\r
+    0     // Reserved                          :22\r
+  },\r
+  {       // BiosCharacteristics2\r
+    0,    // BiosReserved                      :16\r
+    0,    // SystemReserved                    :16\r
+    0     // Reserved                          :32\r
+  },\r
+};\r
+\r
+/* eof - MiscBiosVendorData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c
new file mode 100644 (file)
index 0000000..0a9cffa
--- /dev/null
@@ -0,0 +1,33 @@
+/*++\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
+\r
+  MiscBootInformationData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_BOOT_INFORMATION_STATUS_DATA, BootInformationStatus) = {\r
+  EfiBootInformationStatusNoError,  // BootInformationStatus\r
+  {0}                                 // BootInformationData\r
+};\r
+\r
+/* eof - MiscBootInformationData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni
new file mode 100644 (file)
index 0000000..67bee85
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c
new file mode 100644 (file)
index 0000000..6a3986f
--- /dev/null
@@ -0,0 +1,45 @@
+/*++\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
+\r
+  MiscChassisManufacturerData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Chassis Manufacturer data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_CHASSIS_MANUFACTURER_DATA, MiscChassisManufacturer) = {\r
+  STRING_TOKEN(STR_MISC_CHASSIS_MANUFACTURER),  // ChassisManufactrurer\r
+  STRING_TOKEN(STR_MISC_CHASSIS_VERSION),       // ChassisVersion\r
+  STRING_TOKEN(STR_MISC_CHASSIS_SERIAL_NUMBER), // ChassisSerialNumber\r
+  STRING_TOKEN(STR_MISC_CHASSIS_ASSET_TAG),     // ChassisAssetTag\r
+  {                               // ChassisTypeStatus\r
+    EfiMiscChassisTypeOther,      // ChassisType\r
+    0,                            // ChassisLockPresent\r
+    0                             // Reserved\r
+  },\r
+  EfiChassisStateOther,           // ChassisBootupState\r
+  EfiChassisStateOther,           // ChassisPowerSupplyState\r
+  EfiChassisStateOther,           // ChassisThermalState\r
+  EfiChassisSecurityStatusOther,  // ChassisSecurityState\r
+  0                               // ChassisOemDefined\r
+};\r
+\r
+/* eof - MiscChassisManufacaturerData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscDevicePath.h b/UnixPkg/MiscSubClassPlatformDxe/MiscDevicePath.h
new file mode 100644 (file)
index 0000000..ae0e633
--- /dev/null
@@ -0,0 +1,175 @@
+/*++\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
+\r
+  MiscDevicePath.h\r
+\r
+Abstract:\r
+\r
+  Misc class required EFI Device Path definitions (Ports, slots & \r
+  onboard devices)\r
+\r
+--*/\r
+\r
+#ifndef _MISC_DEVICE_PATH_H\r
+#define _MISC_DEVICE_PATH_H\r
+\r
+\r
+#pragma pack(1)\r
+//\r
+// USB\r
+//\r
+\r
+/* For reference:\r
+#define USB1_1_STR  "ACPI(PNP0A03,0)/PCI(1D,0)."\r
+#define USB1_2_STR  "ACPI(PNP0A03,0)/PCI(1D,1)."\r
+#define USB1_3_STR  "ACPI(PNP0A03,0)/PCI(1D,2)."\r
+#define USB2_1_STR  "ACPI(PNP0A03,0)/PCI(1D,7)." \r
+*/\r
+\r
+//\r
+// #define acpi { 0x02, 0x01, 0x00, 0x0C, 0x0a0341d0, 0x00000000 }\r
+// #define pci( device,function)  { 0x01, 0x01, 0x00, 0x06, device, function }\r
+// #define end  { 0xFF, 0xFF, 0x00, 0x04 }\r
+//\r
+#define DP_ACPI \\r
+  { \\r
+      {ACPI_DEVICE_PATH, ACPI_DP, {(UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), (UINT8) \\r
+      ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)}}, EISA_PNP_ID (0x0A03), 0 \\r
+  }\r
+#define DP_PCI(device, function) \\r
+  { \\r
+      {HARDWARE_DEVICE_PATH, HW_PCI_DP, {(UINT8) (sizeof (PCI_DEVICE_PATH)), (UINT8) \\r
+       ((sizeof (PCI_DEVICE_PATH)) >> 8)}}, function, device \\r
+  }\r
+#define DP_END \\r
+  { \\r
+    END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, {END_DEVICE_PATH_LENGTH, 0} \\r
+  }\r
+\r
+#define DP_LPC(eisaid, function) \\r
+  { \\r
+    {ACPI_DEVICE_PATH, ACPI_DP, {(UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), (UINT8) \\r
+     ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)}}, EISA_PNP_ID (eisaid), function \\r
+  }\r
+\r
+//\r
+// Shanmu >> moved to TianoDevicePath.h\r
+//\r
+\r
+/*\r
+typedef struct _USB_PORT_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} USB_PORT_DEVICE_PATH;\r
+\r
+\r
+//IDE ??I am not sure. Should this be ATAPI_DEVICE_PATH\r
+typedef struct _IDE_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} IDE_DEVICE_PATH;\r
+\r
+//RMC Connector\r
+typedef struct _RMC_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} RMC_CONN_DEVICE_PATH;\r
+\r
+//static RMC_CONN_DEVICE_PATH mRmcConnDevicePath = { acpi, pci( 0x1E,0x00 ),pci( 0x0A,0x00 ), end };\r
+\r
+//RIDE\r
+typedef struct _RIDE_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBridgeDevicePath;\r
+  PCI_DEVICE_PATH      PciBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} RIDE_DEVICE_PATH;\r
+\r
+//static RIDE_DEVICE_PATH mRideDevicePath = { acpi, pci( 0x1E,0x00 ),pci( 0x02,0x00 ), end };\r
+\r
+//Gigabit NIC\r
+//typedef struct _GB_NIC_DEVICE_PATH\r
+//{\r
+//  ACPI_HID_DEVICE_PATH      PciRootBridgeDevicePath;\r
+//  PCI_DEVICE_PATH            PciBridgeDevicePath;\r
+//  PCI_DEVICE_PATH            PciXBridgeDevicePath;\r
+//  PCI_DEVICE_PATH            PciXBusDevicePath;\r
+//  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+//} GB_NIC_DEVICE_PATH;\r
+\r
+//static GB_NIC_DEVICE_PATH mGbNicDevicePath = { acpi, pci( 0x03,0x00 ),pci( 0x1F,0x00 ),pci( 0x07,0x00 ), end };\r
+\r
+\r
+//P/S2 Connector\r
+typedef struct _PS2_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      LpcBridgeDevicePath;\r
+  ACPI_HID_DEVICE_PATH    LpcBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} PS2_CONN_DEVICE_PATH;\r
+\r
+//static PS2_CONN_DEVICE_PATH mPs2KeyboardDevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0303,0 ), end };\r
+//static PS2_CONN_DEVICE_PATH mPs2MouseDevicePath      = { acpi, pci( 0x1F,0x00 ),lpc( 0x0303,1 ), end };\r
+\r
+//Serial Port Connector\r
+typedef struct _SERIAL_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      LpcBridgeDevicePath;\r
+  ACPI_HID_DEVICE_PATH    LpcBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} SERIAL_CONN_DEVICE_PATH;\r
+\r
+//static SERIAL_CONN_DEVICE_PATH mCom1DevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0501,0 ), end };\r
+//static SERIAL_CONN_DEVICE_PATH mCom2DevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0501,1 ), end };\r
+\r
+//Parallel Port Connector\r
+typedef struct _PARALLEL_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      LpcBridgeDevicePath;\r
+  ACPI_HID_DEVICE_PATH    LpcBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} PARALLEL_CONN_DEVICE_PATH;\r
+\r
+//static PARALLEL_CONN_DEVICE_PATH mLpt1DevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0401,0 ), end };\r
+\r
+//Floopy Connector\r
+typedef struct _FLOOPY_CONN_DEVICE_PATH\r
+{\r
+  ACPI_HID_DEVICE_PATH    PciRootBridgeDevicePath;\r
+  PCI_DEVICE_PATH      LpcBridgeDevicePath;\r
+  ACPI_HID_DEVICE_PATH    LpcBusDevicePath;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} FLOOPY_CONN_DEVICE_PATH;\r
+\r
+//static FLOOPY_CONN_DEVICE_PATH mFloopyADevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0604,0 ), end };\r
+//static FLOOPY_CONN_DEVICE_PATH mFloopyBDevicePath   = { acpi, pci( 0x1F,0x00 ),lpc( 0x0604,1 ), end };\r
+\r
+*/\r
+\r
+//\r
+// End Shanmu\r
+//\r
+#pragma pack()\r
+\r
+#endif\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c
new file mode 100644 (file)
index 0000000..48d8651
--- /dev/null
@@ -0,0 +1,37 @@
+/*++\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
+\r
+  MiscNumberOfInstallableLanguagesData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES_DATA, NumberOfInstallableLanguages) = {\r
+  1,    // NumberOfInstallableLanguages\r
+  {     // LanguageFlags\r
+    0,  // AbbreviatedLanguageFormat\r
+    0   // Reserved\r
+  },\r
+  0,    // CurrentLanguageNumber\r
+};\r
+\r
+/* eof - MiscNumberOfInstallableLanguagesData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscOemString.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscOemString.uni
new file mode 100644 (file)
index 0000000..fb79bdb
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscOemString.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscOemStringData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscOemStringData.c
new file mode 100644 (file)
index 0000000..170d6dc
--- /dev/null
@@ -0,0 +1,32 @@
+/*++\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
+  \r
+    MiscOemStringData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_OEM_STRING_DATA, OemString) = {\r
+  { STRING_TOKEN(STR_MISC_OEM_STRING) }\r
+};\r
+\r
+/* eof - MiscOemStringData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni
new file mode 100644 (file)
index 0000000..b6a617b
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c
new file mode 100644 (file)
index 0000000..ac3abcc
--- /dev/null
@@ -0,0 +1,99 @@
+/*++\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
+\r
+  MiscPortInternalConnectorDesignatorData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortInternalConnectorDesignator) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR),  // PortInternalConnectorDesignator\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_CONNECTOR_DESIGNATOR),  // PortExternalConnectorDesignator\r
+  EfiPortConnectorTypeOther,  // PortInternalConnectorType\r
+  EfiPortConnectorTypeOther,  // PortExternalConnectorType\r
+  EfiPortTypeNone,            // PortType\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortKeyboard) = {\r
+  STRING_TOKEN (STR_MISC_PORT_INTERNAL_KEYBOARD),   // PortInternalConnectorDesignator\r
+  STRING_TOKEN (STR_MISC_PORT_EXTERNAL_KEYBOARD),   // PortExternalConnectorDesignator\r
+  EfiPortConnectorTypeNone, // PortInternalConnectorType\r
+  EfiPortConnectorTypePS2,  // PortExternalConnectorType\r
+  EfiPortTypeKeyboard,      // PortType\r
+  // mPs2KbyboardDevicePath                          // PortPath\r
+  //\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortMouse) = {\r
+  STRING_TOKEN (STR_MISC_PORT_INTERNAL_MOUSE),      // PortInternalConnectorDesignator\r
+  STRING_TOKEN (STR_MISC_PORT_EXTERNAL_MOUSE),      // PortExternalConnectorDesignator\r
+  EfiPortConnectorTypeNone, // PortInternalConnectorType\r
+  EfiPortConnectorTypePS2,  // PortExternalConnectorType\r
+  EfiPortTypeMouse,         // PortType\r
+  // mPs2MouseDevicePath                // PortPath\r
+  //\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortCom1) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_COM1),\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_COM1),\r
+  EfiPortConnectorTypeNone,\r
+  EfiPortConnectorTypeDB9Female,\r
+  EfiPortTypeSerial16550ACompatible,\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortCom2) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_COM2),\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_COM2),\r
+  EfiPortConnectorTypeNone,\r
+  EfiPortConnectorTypeDB9Female,\r
+  EfiPortTypeSerial16550ACompatible,\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortExtensionPower) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_EXTENSION_POWER),\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_EXTENSION_POWER),\r
+  EfiPortConnectorTypeOther,\r
+  EfiPortConnectorTypeNone,\r
+  EfiPortTypeOther,\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortFloppy) = {\r
+  STRING_TOKEN(STR_MISC_PORT_INTERNAL_FLOPPY),\r
+  STRING_TOKEN(STR_MISC_PORT_EXTERNAL_FLOPPY),\r
+  EfiPortConnectorTypeOnboardFloppy,\r
+  EfiPortConnectorTypeNone,\r
+  EfiPortTypeOther,\r
+  {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath\r
+};\r
+\r
+/* eof - MiscPortInternalConnectorDesignatorData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c
new file mode 100644 (file)
index 0000000..bc3e549
--- /dev/null
@@ -0,0 +1,266 @@
+/*++\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
+\r
+  MiscPortInternalConnectorDesignatorFunction.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+//\r
+//\r
+MISC_SUBCLASS_TABLE_FUNCTION (\r
+  MiscPortInternalConnectorDesignator\r
+  )\r
+/*++\r
+Description:\r
+\r
+  This function makes boot time changes to the contents of the\r
+  MiscPortConnectorInformation (Type 8).\r
+\r
+Parameters:\r
+\r
+  RecordType\r
+    Type of record to be processed from the Data Table.\r
+    mMiscSubclassDataTable[].RecordType\r
+\r
+  RecordLen\r
+    Size of static RecordData from the Data Table.\r
+    mMiscSubclassDataTable[].RecordLen\r
+\r
+  RecordData\r
+    Pointer to copy of RecordData from the Data Table.  Changes made\r
+    to this copy will be written to the Data Hub but will not alter\r
+    the contents of the static Data Table.\r
+\r
+  LogRecordData\r
+    Set *LogRecordData to TRUE to log RecordData to Data Hub.\r
+    Set *LogRecordData to FALSE when there is no more data to log.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+    All parameters were valid and *RecordData and *LogRecordData have\r
+    been set.\r
+\r
+  EFI_UNSUPPORTED\r
+    Unexpected RecordType value.\r
+\r
+  EFI_INVALID_PARAMETER\r
+    One of the following parameter conditions was true:\r
+      RecordLen was zero.\r
+      RecordData was NULL.\r
+      LogRecordData was NULL.\r
+--*/\r
+{\r
+  STATIC BOOLEAN                    Done                    = FALSE;\r
+  STATIC PS2_CONN_DEVICE_PATH       mPs2KeyboardDevicePath  = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0303, 0), DP_END };\r
+  STATIC PS2_CONN_DEVICE_PATH       mPs2MouseDevicePath     = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0303, 1), DP_END };\r
+  STATIC SERIAL_CONN_DEVICE_PATH    mCom1DevicePath         = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0501, 0), DP_END };\r
+  STATIC SERIAL_CONN_DEVICE_PATH    mCom2DevicePath         = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0501, 1), DP_END };\r
+  //STATIC PARALLEL_CONN_DEVICE_PATH  mLpt1DevicePath         = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0401, 0), DP_END };\r
+  STATIC FLOOPY_CONN_DEVICE_PATH    mFloopyADevicePath      = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0604, 0), DP_END };\r
+  //STATIC FLOOPY_CONN_DEVICE_PATH    mFloopyBDevicePath      = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0604, 1), DP_END };\r
+  //STATIC USB_PORT_DEVICE_PATH       mUsb0DevicePath         = { DP_ACPI, DP_PCI (0x1d, 0x00), DP_END };\r
+  //STATIC USB_PORT_DEVICE_PATH       mUsb1DevicePath         = { DP_ACPI, DP_PCI (0x1d, 0x01), DP_END };\r
+  //STATIC USB_PORT_DEVICE_PATH       mUsb2DevicePath         = { DP_ACPI, DP_PCI (0x1d, 0x02), DP_END };\r
+  //STATIC USB_PORT_DEVICE_PATH       mUsb3DevicePath         = { DP_ACPI, DP_PCI (0x1d, 0x07), DP_END };\r
+  //STATIC IDE_DEVICE_PATH            mIdeDevicePath          = { DP_ACPI, DP_PCI (0x1F, 0x01), DP_END };\r
+  //STATIC GB_NIC_DEVICE_PATH         mGbNicDevicePath        = { DP_ACPI, DP_PCI( 0x03,0x00 ),DP_PCI( 0x1F,0x00 ),DP_PCI( 0x07,0x00 ), DP_END };\r
+  EFI_DEVICE_PATH_PROTOCOL          EndDevicePath           = DP_END;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  // Shanmu >> to fix the Device Path Issue...\r
+  // if (RecordLen == 0 || RecordData == NULL || LogRecordData == NULL) {\r
+  //\r
+  if (*RecordLen == 0 || RecordData == NULL || LogRecordData == NULL) {\r
+    //\r
+    // End Shanmu\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Then check for unsupported RecordType.\r
+  //\r
+  if (RecordType != EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_RECORD_NUMBER) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Is this the first time through this function?\r
+  //\r
+  if (!Done) {\r
+    //\r
+    // Yes, this is the first time.  Inspect/Change the contents of the\r
+    // RecordData structure.\r
+    //\r
+    //\r
+    // Device path is only updated here as it was not taking that in static data\r
+    //\r
+    // Shanmu >> to fix the Device Path Issue...\r
+    //\r
+\r
+    /*\r
+    switch (((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortInternalConnectorDesignator) \r
+    {\r
+      case STR_MISC_PORT_INTERNAL_MOUSE:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mPs2MouseDevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_KEYBOARD:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mPs2KeyboardDevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_COM1:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mCom1DevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_COM2:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mCom2DevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_LPT1:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mLpt1DevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_USB1:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mUsb0DevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_USB2:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mUsb1DevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_USB3:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mUsb2DevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_NETWORK:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mGbNicDevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_FLOPPY:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mFloopyADevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_IDE1:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mIdeDevicePath);          \r
+        }break;\r
+      case STR_MISC_PORT_INTERNAL_IDE2:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mIdeDevicePath);          \r
+        }break;\r
+      default:\r
+        {\r
+          (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = EndDevicePath;\r
+        }break;    \r
+    }\r
+    */\r
+    switch (((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortInternalConnectorDesignator) {\r
+    case STR_MISC_PORT_INTERNAL_MOUSE:\r
+      {\r
+        CopyMem (\r
+          &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,\r
+          &mPs2MouseDevicePath,\r
+          GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mPs2MouseDevicePath)\r
+          );\r
+        *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mPs2MouseDevicePath);\r
+      }\r
+      break;\r
+\r
+    case STR_MISC_PORT_INTERNAL_KEYBOARD:\r
+      {\r
+        CopyMem (\r
+          &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,\r
+          &mPs2KeyboardDevicePath,\r
+          GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mPs2KeyboardDevicePath)\r
+          );\r
+        *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mPs2KeyboardDevicePath);\r
+      }\r
+      break;\r
+\r
+    case STR_MISC_PORT_INTERNAL_COM1:\r
+      {\r
+        CopyMem (\r
+          &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,\r
+          &mCom1DevicePath,\r
+          GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mCom1DevicePath)\r
+          );\r
+        *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mCom1DevicePath);\r
+      }\r
+      break;\r
+\r
+    case STR_MISC_PORT_INTERNAL_COM2:\r
+      {\r
+        CopyMem (\r
+          &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,\r
+          &mCom2DevicePath,\r
+          GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mCom2DevicePath)\r
+          );\r
+        *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mCom2DevicePath);\r
+      }\r
+      break;\r
+\r
+    case STR_MISC_PORT_INTERNAL_FLOPPY:\r
+      {\r
+        CopyMem (\r
+          &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,\r
+          &mFloopyADevicePath,\r
+          GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mFloopyADevicePath)\r
+          );\r
+        *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mFloopyADevicePath);\r
+      }\r
+      break;\r
+\r
+    default:\r
+      {\r
+        CopyMem (\r
+          &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,\r
+          &EndDevicePath,\r
+          GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &EndDevicePath)\r
+          );\r
+        *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &EndDevicePath);\r
+      }\r
+      break;\r
+    }\r
+    //\r
+    // End Shanmu\r
+    //\r
+    // Set Done flag to TRUE for next pass through this function.\r
+    // Set *LogRecordData to TRUE so data will get logged to Data Hub.\r
+    //\r
+    Done            = TRUE;\r
+    *LogRecordData  = TRUE;\r
+  } else {\r
+    //\r
+    // No, this is the second time.  Reset the state of the Done flag\r
+    // to FALSE and tell the data logger that there is no more data\r
+    // to be logged for this record type.  If any memory allocations\r
+    // were made by earlier passes, they must be released now.\r
+    //\r
+    Done            = FALSE;\r
+    *LogRecordData  = FALSE;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/* eof - MiscSystemManufacturerFunction.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c
new file mode 100644 (file)
index 0000000..c075ffd
--- /dev/null
@@ -0,0 +1,42 @@
+/*++\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
+  \r
+    MiscResetCapabilitiesData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_RESET_CAPABILITIES, MiscResetCapabilities) = {\r
+  {     // ResetCapabilities\r
+    0,  // Status\r
+    0,  // BootOption\r
+    0,  // BootOptionOnLimit\r
+    0,  // WatchdogTimerPresent\r
+    0   // Reserved\r
+  },\r
+  0,    // ResetCount\r
+  0,    // ResetLimit\r
+  0,    // ResetTimerInterval\r
+  0     // ResetTimeout\r
+};\r
+\r
+/* eof - MiscResetCapabilities.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h
new file mode 100644 (file)
index 0000000..4105266
--- /dev/null
@@ -0,0 +1,119 @@
+/*++\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
+\r
+  MiscSubclassDriver.h\r
+\r
+Abstract:\r
+\r
+  Header file for MiscSubclass Driver.\r
+\r
+--*/\r
+\r
+#ifndef _MISC_SUBCLASS_DRIVER_H\r
+#define _MISC_SUBCLASS_DRIVER_H\r
+\r
+#include <FrameworkDxe.h>\r
+#include <UnixDxe.h>\r
+#include <Guid/DataHubRecords.h>\r
+#include <Guid/DataHubProducer.h>\r
+#include <Protocol/DataHub.h>\r
+#include <Protocol/UnixIo.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/FrameworkHiiLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+\r
+#include <MiscDevicePath.h>\r
+#include <Protocol/DataHub.h>\r
+#include <Protocol/FrameworkHii.h>\r
+#include <Library/HiiLib.h>\r
+\r
+//\r
+// Data table entry update function.\r
+//\r
+typedef \r
+EFI_STATUS \r
+(EFIAPI EFI_MISC_SUBCLASS_DATA_FUNCTION) (\r
+  IN UINT16                         RecordType,\r
+  IN UINT32                         *RecordLen,\r
+  IN OUT EFI_MISC_SUBCLASS_RECORDS  *RecordData,\r
+  OUT BOOLEAN                       *LogRecordData\r
+  );\r
+\r
+//\r
+// Data table entry definition.\r
+//\r
+typedef struct {\r
+  UINT16                          RecordType;\r
+  UINT32                          RecordLen;\r
+  VOID                            *RecordData;\r
+  EFI_MISC_SUBCLASS_DATA_FUNCTION *Function;\r
+} EFI_MISC_SUBCLASS_DATA_TABLE;\r
+\r
+//\r
+// Data Table extern definitions.\r
+//\r
+#define MISC_SUBCLASS_TABLE_EXTERNS(NAME1, NAME2) \\r
+  extern NAME1 NAME2 ## Data; \\r
+  extern EFI_MISC_SUBCLASS_DATA_FUNCTION NAME2 ## Function\r
+\r
+//\r
+// Data Table entries\r
+//\r
+#define MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(NAME1, NAME2) { \\r
+         NAME1 ##  _RECORD_NUMBER, sizeof (NAME1 ## _DATA), &NAME2 ## Data, NULL \\r
+  }\r
+\r
+#define MISC_SUBCLASS_TABLE_ENTRY_FUNCTION_ONLY(NAME1, NAME2) \\r
+  { \\r
+    NAME1 ##  _RECORD_NUMBER, 0, NULL, &NAME2 ## Function \\r
+  }\r
+\r
+#define MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(NAME1, NAME2, NAME3) \\r
+  { \\r
+    NAME1 ##  _RECORD_NUMBER, sizeof (NAME1 ## _DATA), &NAME2 ## Data, &NAME3 ## Function \\r
+  }\r
+\r
+//\r
+// Global definition macros.\r
+//\r
+#define MISC_SUBCLASS_TABLE_DATA(NAME1, NAME2)  NAME1 NAME2 ## Data\r
+\r
+#define MISC_SUBCLASS_TABLE_FUNCTION(NAME2) \\r
+  EFI_STATUS EFIAPI NAME2 ## Function ( \\r
+  IN UINT16 RecordType, \\r
+  IN UINT32 *RecordLen, \\r
+  IN OUT EFI_MISC_SUBCLASS_RECORDS * RecordData, \\r
+  OUT BOOLEAN *LogRecordData \\r
+  )\r
+\r
+//\r
+// Data Table Array\r
+//\r
+extern EFI_MISC_SUBCLASS_DATA_TABLE mMiscSubclassDataTable[];\r
+\r
+//\r
+// Data Table Array Entries\r
+//\r
+extern UINTN  mMiscSubclassDataTableEntries;\r
+\r
+#endif /* _MISC_SUBCLASS_DRIVER_H */\r
+\r
+/* eof - MiscSubclassDriver.h */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf
new file mode 100644 (file)
index 0000000..daa3ae2
--- /dev/null
@@ -0,0 +1,100 @@
+#/** @file\r
+# Misc Sub class driver\r
+#\r
+# Parses the MiscSubclassDataTable and reports any generated data to the DataHub.\r
+#  All .uni file who tagged with "ToolCode="DUMMY"" in following file list is included by\r
+#  MiscSubclassDriver.uni file, the StrGather tool will expand MiscSubclassDriver.uni file \r
+#  and parse all .uni file.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = MiscSubclass\r
+  FILE_GUID                      = f2fbd108-8985-11db-b06a-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = MiscSubclassDriverEntryPoint\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  MiscPortInternalConnectorDesignatorFunction.c\r
+  MiscSystemSlotDesignationData.c\r
+  MiscSystemOptionStringData.c\r
+  MiscSystemManufacturerFunction.c\r
+  MiscSystemManufacturerData.c\r
+  MiscSystemLanguageStringData.c\r
+  MiscResetCapabilitiesData.c\r
+  MiscPortInternalConnectorDesignatorData.c\r
+  MiscOemStringData.c\r
+  MiscNumberOfInstallableLanguagesData.c\r
+  MiscChassisManufacturerData.c\r
+  MiscBootInformationData.c\r
+  MiscBiosVendorData.c\r
+  MiscBaseBoardManufacturerData.c\r
+  MiscSubclassDriverDataTable.c\r
+  MiscSubclassDriverEntryPoint.c\r
+  MiscSubClassDriver.uni\r
+  MiscSystemSlotDesignation.uni\r
+  MiscSystemOptionString.uni\r
+  MiscSystemManufacturer.uni\r
+  MiscSystemLanguageString.uni\r
+  MiscPortInternalConnectorDesignator.uni\r
+  MiscOemString.uni\r
+  MiscChassisManufacturer.uni\r
+  MiscBiosVendor.uni\r
+  MiscBaseBoardManufacturer.uni\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  DevicePathLib\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  HiiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Guids]\r
+  gEfiMemorySubClassGuid                        # SOMETIMES_CONSUMED\r
+  gEfiMemoryProducerGuid                        # SOMETIMES_CONSUMED\r
+  gEfiProcessorSubClassGuid                     # SOMETIMES_CONSUMED\r
+  gEfiMiscSubClassGuid                          # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiUnixIoProtocolGuid                        # PROTOCOL_NOTIFY SOMETIMES_CONSUMED\r
+  gEfiDataHubProtocolGuid                       # PROTOCOL ALWAYS_CONSUMED\r
+\r
+[Pcd.common]\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySize\r
+\r
+[Depex]\r
+  gEfiDataHubProtocolGuid\r
+\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.msa b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.msa
new file mode 100644 (file)
index 0000000..b9f0992
--- /dev/null
@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>MiscSubclass</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f2fbd108-8985-11db-b06a-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Misc Sub class driver</Abstract>\r
+    <Description>\r
+      Parses the MiscSubclassDataTable and reports any generated data to the DataHub.\r
+      All .uni file who tagged with "ToolCode="DUMMY"" in following file list is included by\r
+      MiscSubclassDriver.uni file, the StrGather tool will expand MiscSubclassDriver.uni file \r
+      and parse all .uni file.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>MiscSubclass</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HiiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DevicePathLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename ToolCode="DUMMY">MiscBaseBoardManufacturer.uni</Filename>\r
+    <Filename ToolCode="DUMMY">MiscBiosVendor.uni</Filename>\r
+    <Filename ToolCode="DUMMY">MiscChassisManufacturer.uni</Filename>\r
+    <Filename ToolCode="DUMMY">MiscOemString.uni</Filename>\r
+    <Filename ToolCode="DUMMY">MiscPortInternalConnectorDesignator.uni</Filename>\r
+    <Filename ToolCode="DUMMY">MiscSystemLanguageString.uni</Filename>\r
+    <Filename ToolCode="DUMMY">MiscSystemManufacturer.uni</Filename>\r
+    <Filename ToolCode="DUMMY">MiscSystemOptionString.uni</Filename>\r
+    <Filename ToolCode="DUMMY">MiscSystemSlotDesignation.uni</Filename>\r
+    <Filename>MiscSubclassDriver.uni</Filename>\r
+    <Filename>MiscDevicePath.h</Filename>\r
+    <Filename>MiscSubclassDriver.h</Filename>\r
+    <Filename>MiscSubclassDriverEntryPoint.c</Filename>\r
+    <Filename>MiscSubclassDriverDataTable.c</Filename>\r
+    <Filename>MiscBaseBoardManufacturerData.c</Filename>\r
+    <Filename>MiscBiosVendorData.c</Filename>\r
+    <Filename>MiscBootInformationData.c</Filename>\r
+    <Filename>MiscChassisManufacturerData.c</Filename>\r
+    <Filename>MiscNumberOfInstallableLanguagesData.c</Filename>\r
+    <Filename>MiscOemStringData.c</Filename>\r
+    <Filename>MiscPortInternalConnectorDesignatorData.c</Filename>\r
+    <Filename>MiscResetCapabilitiesData.c</Filename>\r
+    <Filename>MiscSystemLanguageStringData.c</Filename>\r
+    <Filename>MiscSystemManufacturerData.c</Filename>\r
+    <Filename>MiscSystemManufacturerFunction.c</Filename>\r
+    <Filename>MiscSystemOptionStringData.c</Filename>\r
+    <Filename>MiscSystemSlotDesignationData.c</Filename>\r
+    <Filename>MiscPortInternalConnectorDesignatorFunction.c</Filename>\r
+    <Filename>MiscSubclassDriver.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiDataHubProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <ProtocolNotify Usage="SOMETIMES_CONSUMED">\r
+      <ProtocolNotifyCName>gEfiUnixIoProtocolGuid</ProtocolNotifyCName>\r
+    </ProtocolNotify>\r
+  </Protocols>\r
+  <DataHubs>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>MiscPortKeyboard</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>MiscPortMouse</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>MiscPortCom1</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>MiscPortCom2</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>MiscBiosVendor</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>MiscSystemManufacturer</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>MiscBaseBoardManufacturer</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>MiscChassisManufacturer</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>MiscSystemSlotDesignation</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>OemString</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="ALWAYS_PRODUCED">\r
+      <DataHubCName>SystemOptionString</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="SOMETIMES_CONSUMED">\r
+      <DataHubCName>ProcessorSubClassData</DataHubCName>\r
+    </DataHubRecord>\r
+    <DataHubRecord Usage="SOMETIMES_PRODUCED">\r
+      <DataHubCName>MemorySubClassData</DataHubCName>\r
+    </DataHubRecord>\r
+  </DataHubs>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiMiscSubClassGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiProcessorSubClassGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiMemoryProducerGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiMemorySubClassGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiUnixMemoryGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>MiscSubclassDriverEntryPoint</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni
new file mode 100644 (file)
index 0000000..bae6862
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c
new file mode 100644 (file)
index 0000000..06e2a80
--- /dev/null
@@ -0,0 +1,99 @@
+/*++\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
+\r
+  MiscSubclassDriverDataTable.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// External definitions referenced by Data Table entries.\r
+//\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_CHASSIS_MANUFACTURER_DATA,\r
+  MiscChassisManufacturer\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_BIOS_VENDOR_DATA,\r
+  MiscBiosVendor\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_SYSTEM_MANUFACTURER_DATA,\r
+  MiscSystemManufacturer\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_BASE_BOARD_MANUFACTURER_DATA,\r
+  MiscBaseBoardManufacturer\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,\r
+  MiscPortInternalConnectorDesignator\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,\r
+  MiscPortKeyboard\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,\r
+  MiscPortMouse\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,\r
+  MiscPortCom1\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,\r
+  MiscPortCom2\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_SYSTEM_SLOT_DESIGNATION_DATA,\r
+  MiscSystemSlotDesignation\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_OEM_STRING_DATA,\r
+  OemString\r
+  );\r
+MISC_SUBCLASS_TABLE_EXTERNS (\r
+  EFI_MISC_SYSTEM_OPTION_STRING_DATA,\r
+  SystemOptionString\r
+  );\r
+\r
+//\r
+// Data Table.\r
+//\r
+EFI_MISC_SUBCLASS_DATA_TABLE  mMiscSubclassDataTable[] = {\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR, MiscPortKeyboard, MiscPortInternalConnectorDesignator),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR, MiscPortMouse, MiscPortInternalConnectorDesignator),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR, MiscPortCom1, MiscPortInternalConnectorDesignator),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR, MiscPortCom2, MiscPortInternalConnectorDesignator),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_BIOS_VENDOR, MiscBiosVendor),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_SYSTEM_MANUFACTURER, MiscSystemManufacturer),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_BASE_BOARD_MANUFACTURER, MiscBaseBoardManufacturer),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_CHASSIS_MANUFACTURER, MiscChassisManufacturer),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_SYSTEM_SLOT_DESIGNATION, MiscSystemSlotDesignation),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_OEM_STRING, OemString),\r
+  MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_SYSTEM_OPTION_STRING, SystemOptionString),\r
+};\r
+\r
+//\r
+// Number of Data Table entries.\r
+//\r
+UINTN mMiscSubclassDataTableEntries = (sizeof mMiscSubclassDataTable) / sizeof (EFI_MISC_SUBCLASS_DATA_TABLE);\r
+\r
+/* eof - MiscSubclassDriverDataTable.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
new file mode 100644 (file)
index 0000000..de8d8ef
--- /dev/null
@@ -0,0 +1,334 @@
+/*++\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
+\r
+  MiscSubclassDriverEntryPoint.c\r
+\r
+Abstract:\r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+\r
+extern UINT8  MiscSubClassStrings[];\r
+\r
+//\r
+//\r
+//\r
+EFI_STATUS\r
+LogRecordDataToDataHub (\r
+  EFI_DATA_HUB_PROTOCOL *DataHub,\r
+  UINT32                RecordType,\r
+  UINT32                RecordLen,\r
+  VOID                  *RecordData\r
+  )\r
+/*++\r
+Description:\r
+\r
+Parameters:\r
+\r
+  DataHub\r
+    %%TBD\r
+\r
+  RecordType\r
+    %%TBD\r
+\r
+  RecordLen\r
+    %%TBD\r
+\r
+  RecordData\r
+    %%TBD\r
+\r
+Returns:\r
+\r
+  EFI_INVALID_PARAMETER\r
+\r
+  EFI_SUCCESS\r
+\r
+  Other Data Hub errors\r
+\r
+--*/\r
+{\r
+  EFI_MISC_SUBCLASS_DRIVER_DATA MiscSubclass;\r
+  EFI_STATUS                    EfiStatus;\r
+\r
+  //\r
+  // Do nothing if data parameters are not valid.\r
+  //\r
+  if (RecordLen == 0 || RecordData == NULL) {\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "RecordLen == %d  RecordData == %xh\n",\r
+      RecordLen,\r
+      RecordData)\r
+      );\r
+\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Assemble Data Hub record.\r
+  //\r
+  MiscSubclass.Header.Version     = EFI_MISC_SUBCLASS_VERSION;\r
+  MiscSubclass.Header.HeaderSize  = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r
+  MiscSubclass.Header.Instance    = 1;\r
+  MiscSubclass.Header.SubInstance = 1;\r
+  MiscSubclass.Header.RecordType  = RecordType;\r
+\r
+  CopyMem (\r
+    &MiscSubclass.Record,\r
+    RecordData,\r
+    RecordLen\r
+    );\r
+\r
+  //\r
+  // Log Data Hub record.\r
+  //\r
+  EfiStatus = DataHub->LogData (\r
+                        DataHub,\r
+                        &gEfiMiscSubClassGuid,\r
+                        &gEfiMiscSubClassGuid,\r
+                        EFI_DATA_RECORD_CLASS_DATA,\r
+                        &MiscSubclass,\r
+                        sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen\r
+                        );\r
+\r
+  if (EFI_ERROR (EfiStatus)) {\r
+    DEBUG (\r
+      (EFI_D_ERROR,\r
+      "LogData(%d bytes) == %r\n",\r
+      sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen,\r
+      EfiStatus)\r
+      );\r
+  }\r
+\r
+  return EfiStatus;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+MiscSubclassDriverEntryPoint (\r
+  IN EFI_HANDLE         ImageHandle,\r
+  IN EFI_SYSTEM_TABLE   *SystemTable\r
+  )\r
+/*++\r
+Description:\r
+\r
+  Standard EFI driver point.  This driver parses the mMiscSubclassDataTable\r
+  structure and reports any generated data to the DataHub.\r
+\r
+Arguments:\r
+\r
+  ImageHandle\r
+    Handle for the image of this driver\r
+\r
+  SystemTable\r
+    Pointer to the EFI System Table\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+    The data was successfully reported to the Data Hub.\r
+\r
+--*/\r
+{\r
+  EFI_MISC_SUBCLASS_DRIVER_DATA     RecordData;\r
+  EFI_DATA_HUB_PROTOCOL             *DataHub;\r
+  EFI_HII_HANDLE                    HiiHandle;\r
+  EFI_STATUS                        EfiStatus;\r
+  UINTN                             Index;\r
+  BOOLEAN                           LogRecordData;\r
+  EFI_MEMORY_SUBCLASS_DRIVER_DATA   MemorySubClassData; \r
+  UINT64                            TotalMemorySize;\r
+  CHAR16                            *UnixMemString;\r
+\r
+\r
+\r
+  //\r
+  // Initialize constant portion of subclass header.\r
+  //\r
+  RecordData.Header.Version     = EFI_MISC_SUBCLASS_VERSION;\r
+  RecordData.Header.HeaderSize  = sizeof (EFI_SUBCLASS_TYPE1_HEADER);\r
+  RecordData.Header.Instance    = 1;\r
+  RecordData.Header.SubInstance = 1;\r
+\r
+  //\r
+  // Locate data hub protocol.\r
+  //\r
+  EfiStatus = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**) &DataHub);\r
+\r
+  if (EFI_ERROR (EfiStatus)) {\r
+    DEBUG ((EFI_D_ERROR, "Could not locate DataHub protocol.  %r\n", EfiStatus));\r
+    return EfiStatus;\r
+  } else if (DataHub == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "LocateProtocol(DataHub) returned NULL pointer!\n"));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // Add our default strings to the HII database. They will be modified later.\r
+  //\r
+  HiiLibAddPackages (1, &gEfiMiscSubClassGuid, NULL, &HiiHandle, MiscSubclassStrings);\r
+\r
+  if (EFI_ERROR (EfiStatus)) {\r
+    DEBUG ((EFI_D_ERROR, "Could not log default strings to Hii.  %r\n", EfiStatus));\r
+    return EfiStatus;\r
+  }\r
+  //\r
+  //\r
+  //\r
+  for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {\r
+    //\r
+    // Stupidity check!  Do nothing if RecordLen is zero.\r
+    // %%TBD - Should this be an error or a mechanism for ignoring\r
+    // records in the Data Table?\r
+    //\r
+    if (mMiscSubclassDataTable[Index].RecordLen == 0) {\r
+      DEBUG (\r
+        (EFI_D_ERROR,\r
+        "mMiscSubclassDataTable[%d].RecordLen == 0\n",\r
+        Index)\r
+        );\r
+\r
+      continue;\r
+    }\r
+    //\r
+    // Initialize per-record portion of subclass header and\r
+    // copy static data into data portion of subclass record.\r
+    //\r
+    RecordData.Header.RecordType = mMiscSubclassDataTable[Index].RecordType;\r
+\r
+    if (mMiscSubclassDataTable[Index].RecordData == NULL) {\r
+      ZeroMem (\r
+        &RecordData.Record,\r
+        mMiscSubclassDataTable[Index].RecordLen\r
+        );\r
+    } else {\r
+      CopyMem (\r
+        &RecordData.Record,\r
+        mMiscSubclassDataTable[Index].RecordData,\r
+        mMiscSubclassDataTable[Index].RecordLen\r
+        );\r
+    }\r
+    //\r
+    // If the entry does not have a function pointer, just log the data.\r
+    //\r
+    if (mMiscSubclassDataTable[Index].Function == NULL) {\r
+      //\r
+      // Log RecordData to Data Hub.\r
+      //\r
+      EfiStatus = DataHub->LogData (\r
+                            DataHub,\r
+                            &gEfiMiscSubClassGuid,\r
+                            &gEfiMiscSubClassGuid,\r
+                            EFI_DATA_RECORD_CLASS_DATA,\r
+                            &RecordData,\r
+                            sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen\r
+                            );\r
+\r
+      if (EFI_ERROR (EfiStatus)) {\r
+        DEBUG (\r
+          (EFI_D_ERROR,\r
+          "LogData(%d bytes) == %r\n",\r
+          sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r
+          EfiStatus)\r
+          );\r
+      }\r
+\r
+      continue;\r
+    }\r
+    //\r
+    // The entry has a valid function pointer.\r
+    // Keep calling the function and logging data until there\r
+    // is no more data to log.\r
+    //\r
+    for (;;) {\r
+      EfiStatus = (*mMiscSubclassDataTable[Index].Function)(mMiscSubclassDataTable[Index].RecordType, &mMiscSubclassDataTable[Index].RecordLen, &RecordData.Record, &LogRecordData);\r
+\r
+      if (EFI_ERROR (EfiStatus)) {\r
+        break;\r
+      }\r
+\r
+      if (!LogRecordData) {\r
+        break;\r
+      }\r
+      //\r
+      //\r
+      //\r
+      EfiStatus = DataHub->LogData (\r
+                            DataHub,\r
+                            &gEfiMiscSubClassGuid,\r
+                            &gEfiMiscSubClassGuid,\r
+                            EFI_DATA_RECORD_CLASS_DATA,\r
+                            &RecordData,\r
+                            sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen\r
+                            );\r
+\r
+      if (EFI_ERROR (EfiStatus)) {\r
+        DEBUG (\r
+          (EFI_D_ERROR,\r
+          "LogData(%d bytes) == %r\n",\r
+          sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,\r
+          EfiStatus)\r
+          );\r
+      }\r
+    }\r
+  }\r
+  \r
+  //\r
+  // Log Memory Size info based on PCD setting.\r
+  //\r
+  MemorySubClassData.Header.Instance    = 1;\r
+  MemorySubClassData.Header.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;\r
+  MemorySubClassData.Header.RecordType  = EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER;\r
+\r
+  //\r
+  // Process Memory String in form size!size ...\r
+  // So 64!64 is 128 MB\r
+  //\r
+  UnixMemString   = PcdGetPtr (PcdUnixMemorySize);\r
+  for (TotalMemorySize = 0; *UnixMemString != '\0';) {\r
+    TotalMemorySize += StrDecimalToUint64 (UnixMemString);\r
+    while (*UnixMemString != '\0') {\r
+      if (*UnixMemString == '!') {\r
+        UnixMemString++;       \r
+        break;\r
+      }\r
+      UnixMemString++;\r
+    }\r
+  }\r
+\r
+  MemorySubClassData.Record.ArrayStartAddress.MemoryArrayStartAddress               = 0;\r
+  MemorySubClassData.Record.ArrayStartAddress.MemoryArrayEndAddress                 = LShiftU64 (TotalMemorySize, 20) - 1;\r
+  MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.ProducerName  = gEfiMemoryProducerGuid;\r
+  MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.Instance      = 1;\r
+  MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.SubInstance   = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;\r
+  MemorySubClassData.Record.ArrayStartAddress.MemoryArrayPartitionWidth             = 0;\r
+\r
+  //\r
+  // Store memory size data record to data hub.\r
+  //\r
+  EfiStatus = DataHub->LogData (\r
+                      DataHub,\r
+                      &gEfiMemorySubClassGuid,\r
+                      &gEfiMemoryProducerGuid,\r
+                      EFI_DATA_RECORD_CLASS_DATA,\r
+                      &MemorySubClassData,\r
+                      sizeof (EFI_SUBCLASS_TYPE1_HEADER) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA)\r
+                      );\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni
new file mode 100644 (file)
index 0000000..36dacf0
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c
new file mode 100644 (file)
index 0000000..f904623
--- /dev/null
@@ -0,0 +1,33 @@
+/*++\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
+\r
+  MiscSystemLanguageStringData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_SYSTEM_LANGUAGE_STRING_DATA, SystemLanguageString) = {\r
+  0,\r
+  STRING_TOKEN(STR_MISC_SYSTEM_LANGUAGE_STRING)\r
+};\r
+\r
+/* eof - MiscSystemLanguageStringData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni
new file mode 100644 (file)
index 0000000..204588e
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c
new file mode 100644 (file)
index 0000000..0a9bfab
--- /dev/null
@@ -0,0 +1,57 @@
+/*++\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
+\r
+  MiscSystemManufacturerData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) System Manufacturer data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_SYSTEM_MANUFACTURER_DATA, MiscSystemManufacturer)\r
+= {\r
+  STRING_TOKEN(STR_MISC_SYSTEM_MANUFACTURER),\r
+  // SystemManufactrurer\r
+  STRING_TOKEN(STR_MISC_SYSTEM_PRODUCT_NAME),\r
+  // SystemProductName\r
+  STRING_TOKEN(STR_MISC_SYSTEM_VERSION),\r
+  // SystemVersion\r
+  STRING_TOKEN(STR_MISC_SYSTEM_SERIAL_NUMBER),\r
+  // SystemSerialNumber\r
+  {\r
+    0xbadfaced,\r
+    0xdead,\r
+    0xbeef,\r
+    {\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13,\r
+      0x13\r
+    }\r
+  },\r
+  // SystemUuid\r
+  EfiSystemWakeupTypePowerSwitch  // SystemWakeupType\r
+};\r
+\r
+/* eof - MiscSystemManufacturerData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c
new file mode 100644 (file)
index 0000000..2cfbf61
--- /dev/null
@@ -0,0 +1,122 @@
+/*++\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
+\r
+  MiscSystemManufacturerFunction.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+//\r
+//\r
+MISC_SUBCLASS_TABLE_FUNCTION (\r
+  MiscSystemManufacturer\r
+  )\r
+/*++\r
+Description:\r
+\r
+  This function makes boot time changes to the contents of the\r
+  MiscSystemManufacturer (Type 13).\r
+\r
+Parameters:\r
+\r
+  RecordType\r
+    Type of record to be processed from the Data Table.\r
+    mMiscSubclassDataTable[].RecordType\r
+\r
+  RecordLen\r
+    Size of static RecordData from the Data Table.\r
+    mMiscSubclassDataTable[].RecordLen\r
+\r
+  RecordData\r
+    Pointer to copy of RecordData from the Data Table.  Changes made\r
+    to this copy will be written to the Data Hub but will not alter\r
+    the contents of the static Data Table.\r
+\r
+  LogRecordData\r
+    Set *LogRecordData to TRUE to log RecordData to Data Hub.\r
+    Set *LogRecordData to FALSE when there is no more data to log.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS\r
+    All parameters were valid and *RecordData and *LogRecordData have\r
+    been set.\r
+\r
+  EFI_UNSUPPORTED\r
+    Unexpected RecordType value.\r
+\r
+  EFI_INVALID_PARAMETER\r
+    One of the following parameter conditions was true:\r
+      RecordLen was zero.\r
+      RecordData was NULL.\r
+      LogRecordData was NULL.\r
+--*/\r
+{\r
+  STATIC BOOLEAN  Done = FALSE;\r
+\r
+  //\r
+  // First check for invalid parameters.\r
+  //\r
+  if (*RecordLen == 0 || RecordData == NULL || LogRecordData == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Then check for unsupported RecordType.\r
+  //\r
+  if (RecordType != EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Is this the first time through this function?\r
+  //\r
+  if (!Done) {\r
+    //\r
+    // Yes, this is the first time.  Inspect/Change the contents of the\r
+    // RecordData structure.\r
+    //\r
+    //\r
+    // Set system GUID.\r
+    //\r
+    // ((EFI_MISC_SYSTEM_MANUFACTURER_DATA *)RecordData)->SystemUuid = %%TBD\r
+    //\r
+    // Set power-on type.\r
+    //\r
+    // ((EFI_MISC_SYSTEM_MANUFACTURER_DATA *)RecordData)->SystemWakeupType = %%TBD\r
+    //\r
+    // Set Done flag to TRUE for next pass through this function.\r
+    // Set *LogRecordData to TRUE so data will get logged to Data Hub.\r
+    //\r
+    Done            = TRUE;\r
+    *LogRecordData  = TRUE;\r
+  } else {\r
+    //\r
+    // No, this is the second time.  Reset the state of the Done flag\r
+    // to FALSE and tell the data logger that there is no more data\r
+    // to be logged for this record type.  If any memory allocations\r
+    // were made by earlier passes, they must be released now.\r
+    //\r
+    Done            = FALSE;\r
+    *LogRecordData  = FALSE;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/* eof - MiscSystemManufacturerFunction.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni
new file mode 100644 (file)
index 0000000..617578d
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c
new file mode 100644 (file)
index 0000000..bc777ce
--- /dev/null
@@ -0,0 +1,32 @@
+/*++\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
+\r
+  MiscSystemOptionStringData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_SYSTEM_OPTION_STRING_DATA, SystemOptionString) = {\r
+  {STRING_TOKEN(STR_MISC_SYSTEM_OPTION_STRING)}\r
+};\r
+\r
+/* eof - MiscSystemOptionStringData.c */\r
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni
new file mode 100644 (file)
index 0000000..f279ff9
Binary files /dev/null and b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c
new file mode 100644 (file)
index 0000000..d076034
--- /dev/null
@@ -0,0 +1,52 @@
+/*++\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
+  \r
+    MiscSystemSlotDesignationData.c\r
+  \r
+Abstract: \r
+\r
+  This driver parses the mMiscSubclassDataTable structure and reports\r
+  any generated data to the DataHub.\r
+\r
+--*/\r
+\r
+#include "MiscSubClassDriver.h"\r
+\r
+//\r
+// Static (possibly build generated) Bios Vendor data.\r
+//\r
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_SYSTEM_SLOT_DESIGNATION_DATA, MiscSystemSlotDesignation) = {\r
+  STRING_TOKEN(STR_MISC_SYSTEM_SLOT_DESIGNATION),   // SlotDesignation\r
+  EfiSlotTypeOther,         // SlotType\r
+  EfiSlotDataBusWidthOther, // SlotDataBusWidth\r
+  EfiSlotUsageOther,        // SlotUsage\r
+  EfiSlotLengthOther,       // SlotLength\r
+  0,                        // SlotId\r
+  {                         // SlotCharacteristics\r
+    0,                      // CharacteristicsUnknown  :1;\r
+    0,                      // Provides50Volts         :1;\r
+    0,                      // Provides33Volts         :1;\r
+    0,                      // SharedSlot              :1;\r
+    0,                      // PcCard16Supported       :1;\r
+    0,                      // CardBusSupported        :1;\r
+    0,                      // ZoomVideoSupported      :1;\r
+    0,                      // ModemRingResumeSupported:1;\r
+    0,                      // PmeSignalSupported      :1;\r
+    0,                      // HotPlugDevicesSupported :1;\r
+    0,                      // SmbusSignalSupported    :1;\r
+    0                       // Reserved                :21;\r
+  },\r
+  {0, 0, {0, 0}}            // SlotDevicePath\r
+};\r
+\r
+/* eof - MiscSystemSlotsData.c */\r
diff --git a/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
new file mode 100644 (file)
index 0000000..672d9b2
--- /dev/null
@@ -0,0 +1,356 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2008, 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
+\r
+  RealTimeClock.c\r
+\r
+Abstract:\r
+\r
+  UNIX Emulation Architectural Protocol Driver as defined in Tiano\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include "UnixDxe.h"\r
+#include <Protocol/RealTimeClock.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UnixLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+BOOLEAN\r
+DayValid (\r
+  IN  EFI_TIME  *Time\r
+  );\r
+\r
+BOOLEAN\r
+IsLeapYear (\r
+  IN EFI_TIME   *Time\r
+  );\r
+\r
+EFI_STATUS\r
+RtcTimeFieldsValid (\r
+  IN EFI_TIME *Time\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeRealTimeClock (\r
+  IN EFI_HANDLE                          ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                    *SystemTable\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetTime (\r
+  OUT EFI_TIME                                 * Time,\r
+  OUT EFI_TIME_CAPABILITIES                    * Capabilities OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Service routine for RealTimeClockInstance->GetTime \r
+\r
+Arguments:\r
+\r
+  Time          - A pointer to storage that will receive a snapshot of the current time.\r
+\r
+  Capabilities  - A pointer to storage that will receive the capabilities of the real time clock\r
+                  in the platform. This includes the real time clock's resolution and accuracy.  \r
+                  All reported device capabilities are rounded up.  This is an OPTIONAL argument.\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS   - The underlying GetSystemTime call occurred and returned\r
+                  Note that in the NT32 emulation, the GetSystemTime call has no return value\r
+                  thus you will always receive a EFI_SUCCESS on this.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+\r
+  //\r
+  // Check parameter for null pointer\r
+  //\r
+  if (Time == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+\r
+  }\r
+\r
+  gUnix->GetLocalTime (Time);
+\r
+  if (Capabilities != NULL) {\r
+    Capabilities->Resolution  = 1;\r
+    Capabilities->Accuracy    = 50000000;\r
+    Capabilities->SetsToZero  = FALSE;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSetTime (\r
+  IN EFI_TIME   *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Service routine for RealTimeClockInstance->SetTime \r
+\r
+Arguments:\r
+\r
+  Time          - A pointer to storage containing the time and date information to\r
+                  program into the real time clock.\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS           - The operation completed successfully.\r
+                  \r
+  EFI_INVALID_PARAMETER - One of the fields in Time is out of range.\r
+\r
+  EFI_DEVICE_ERROR      - The operation could not be complete due to a device error.\r
+\r
+--*/\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS            Status;\r
+\r
+  if (Time == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Make sure that the time fields are valid\r
+  //\r
+  Status = RtcTimeFieldsValid (Time);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixGetWakeupTime (\r
+  OUT BOOLEAN        *Enabled,\r
+  OUT BOOLEAN        *Pending,\r
+  OUT EFI_TIME       *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Service routine for RealTimeClockInstance->GetWakeupTime\r
+\r
+Arguments:\r
+  This          - Indicates the protocol instance structure.\r
+\r
+  Enabled       - Indicates if the alarm is currently enabled or disabled.\r
+\r
+  Pending       - Indicates if the alarm signal is pending and requires\r
+                  acknowledgement.\r
+\r
+  Time          - The current alarm setting.\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS           - The operation completed successfully.\r
+                  \r
+  EFI_DEVICE_ERROR      - The operation could not be complete due to a device error.\r
+\r
+  EFI_UNSUPPORTED       - The operation is not supported on this platform.\r
+\r
+--*/\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSetWakeupTime (\r
+  IN BOOLEAN      Enable,\r
+  OUT EFI_TIME    *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Service routine for RealTimeClockInstance->SetWakeupTime\r
+\r
+Arguments:\r
+\r
+  Enabled       - Enable or disable the wakeup alarm.\r
+\r
+  Time          - If enable is TRUE, the time to set the wakup alarm for.\r
+                  If enable is FALSE, then this parameter is optional, and\r
+                  may be NULL.\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS           - The operation completed successfully.\r
+                  \r
+  EFI_DEVICE_ERROR      - The operation could not be complete due to a device error.\r
+\r
+  EFI_INVALID_PARAMETER - A field in Time is out of range.\r
+\r
+  EFI_UNSUPPORTED       - The operation is not supported on this platform.\r
+\r
+--*/\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeRealTimeClock (\r
+  IN EFI_HANDLE                            ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Install Real Time Clock Protocol \r
+\r
+Arguments:\r
+  ImageHandle - Image Handle\r
+  SystemTable - Pointer to system table\r
+\r
+Returns:\r
+\r
+  EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  SystemTable->RuntimeServices->GetTime       = UnixGetTime;\r
+  SystemTable->RuntimeServices->SetTime       = UnixSetTime;\r
+  SystemTable->RuntimeServices->GetWakeupTime = UnixGetWakeupTime;\r
+  SystemTable->RuntimeServices->SetWakeupTime = UnixSetWakeupTime;\r
+\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiRealTimeClockArchProtocolGuid,\r
+                  NULL,\r
+                  NULL\r
+                  );\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+RtcTimeFieldsValid (\r
+  IN EFI_TIME *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Arguments:\r
\r
+  Returns: \r
+--*/\r
+// TODO:    Time - add argument and description to function comment\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  if (Time->Year < 1998 ||\r
+      Time->Year > 2099 ||\r
+      Time->Month < 1 ||\r
+      Time->Month > 12 ||\r
+      (!DayValid (Time)) ||\r
+      Time->Hour > 23 ||\r
+      Time->Minute > 59 ||\r
+      Time->Second > 59 ||\r
+      Time->Nanosecond > 999999999 ||\r
+      (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||\r
+      (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))\r
+      ) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+BOOLEAN\r
+DayValid (\r
+  IN  EFI_TIME  *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Time  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+\r
+  static const INTN  DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };\r
+\r
+  if (Time->Day < 1 ||\r
+      Time->Day > DayOfMonth[Time->Month - 1] ||\r
+      (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))\r
+      ) {\r
+    return FALSE;\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+BOOLEAN\r
+IsLeapYear (\r
+  IN EFI_TIME   *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Time  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  if (Time->Year % 4 == 0) {\r
+    if (Time->Year % 100 == 0) {\r
+      if (Time->Year % 400 == 0) {\r
+        return TRUE;\r
+      } else {\r
+        return FALSE;\r
+      }\r
+    } else {\r
+      return TRUE;\r
+    }\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
diff --git a/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf
new file mode 100644 (file)
index 0000000..e90e529
--- /dev/null
@@ -0,0 +1,58 @@
+#/** @file\r
+# Unix Emulation Real time clock Architectural Protocol Driver as defined in TIANO\r
+#\r
+# This real time clock module simulates virtual device by time WinAPI.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = RealTimeClock\r
+  FILE_GUID                      = f3552032-8985-11db-8429-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeRealTimeClock\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  RealTimeClock.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  UnixLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Protocols]\r
+  gEfiRealTimeClockArchProtocolGuid             # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.msa b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.msa
new file mode 100644 (file)
index 0000000..d9a7166
--- /dev/null
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>RealTimeClock</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f3552032-8985-11db-8429-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Unix Emulation Real time clock Architectural Protocol Driver as defined in TIANO</Abstract>\r
+    <Description>\r
+      This real time clock module simulates virtual device by time WinAPI.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>RealTimeClock</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UnixLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>RealTimeClock.c</Filename>\r
+    <Filename>RealTimeClock.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiRealTimeClockArchProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeRealTimeClock</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/ResetRuntimeDxe/Reset.c b/UnixPkg/ResetRuntimeDxe/Reset.c
new file mode 100644 (file)
index 0000000..ddec272
--- /dev/null
@@ -0,0 +1,131 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2008, 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
+\r
+ Reset.c\r
+\r
+Abstract:\r
+\r
+  Reset Architectural Protocol as defined in Tiano under UNIX Emulation\r
+\r
+--*/\r
+\r
+#include "PiDxe.h"\r
+#include "UnixDxe.h"\r
+#include <Protocol/Reset.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UnixLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixReset (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  );\r
+\r
+STATIC\r
+VOID
+EFIAPI\r
+UnixResetSystem (\r
+  IN EFI_RESET_TYPE   ResetType,\r
+  IN EFI_STATUS       ResetStatus,\r
+  IN UINTN            DataSize,\r
+  IN CHAR16           *ResetData OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixReset (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+\r
+Arguments:\r
+\r
+  ImageHandle of the loaded driver\r
+  Pointer to the System Table\r
+\r
+Returns:\r
+\r
+  Status\r
+--*/\r
+// TODO:    SystemTable - add argument and description to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  SystemTable->RuntimeServices->ResetSystem = UnixResetSystem;\r
+\r
+  Handle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiResetArchProtocolGuid,\r
+                  NULL,\r
+                  NULL\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+VOID
+EFIAPI\r
+UnixResetSystem (\r
+  IN EFI_RESET_TYPE   ResetType,\r
+  IN EFI_STATUS       ResetStatus,\r
+  IN UINTN            DataSize,\r
+  IN CHAR16           *ResetData OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ResetType   - TODO: add argument description\r
+  ResetStatus - TODO: add argument description\r
+  DataSize    - TODO: add argument description\r
+  ResetData   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  //\r
+  // BUGBUG Need to kill all console windows later\r
+  //\r
+  //\r
+  // Discard ResetType, always return 0 as exit code\r
+  //\r
+  gUnix->Exit (0);\r
+\r
+  //\r
+  // Should never go here\r
+  //\r
+  while (1)
+    ;
+}\r
diff --git a/UnixPkg/ResetRuntimeDxe/Reset.inf b/UnixPkg/ResetRuntimeDxe/Reset.inf
new file mode 100644 (file)
index 0000000..5eb621a
--- /dev/null
@@ -0,0 +1,58 @@
+#/** @file\r
+# Unix Emulation Reset Architectural Protocol Driver as defined in TIANO\r
+#\r
+# This Reset module simulates system reset by process exit on NT.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Reset\r
+  FILE_GUID                      = f3613084-8985-11db-8c26-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnixReset\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  Reset.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  UnixLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Protocols]\r
+  gEfiResetArchProtocolGuid                     # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/UnixPkg/ResetRuntimeDxe/Reset.msa b/UnixPkg/ResetRuntimeDxe/Reset.msa
new file mode 100644 (file)
index 0000000..133a901
--- /dev/null
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>Reset</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f3613084-8985-11db-8c26-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Unix Emulation Reset Architectural Protocol Driver as defined in TIANO</Abstract>\r
+    <Description>\r
+      This Reset module simulates system reset by process exit on NT.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>Reset</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UnixLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Reset.c</Filename>\r
+    <Filename>Reset.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiResetArchProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeUnixReset</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Sec/FwVol.c b/UnixPkg/Sec/FwVol.c
new file mode 100644 (file)
index 0000000..7206e00
--- /dev/null
@@ -0,0 +1,314 @@
+/*++\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
+  FwVol.c\r
+\r
+Abstract:\r
+  A simple FV stack so the SEC can extract the SEC Core from an\r
+  FV.\r
+\r
+--*/\r
+\r
+#include "SecMain.h"\r
+\r
+#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \\r
+  (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))\r
+\r
+EFI_FFS_FILE_STATE\r
+GetFileState (\r
+  IN UINT8                ErasePolarity,\r
+  IN EFI_FFS_FILE_HEADER  *FfsHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Returns the highest bit set of the State field\r
+\r
+Arguments:\r
+  ErasePolarity   - Erase Polarity  as defined by EFI_FVB2_ERASE_POLARITY\r
+                    in the Attributes field.\r
+  FfsHeader       - Pointer to FFS File Header.\r
+\r
+Returns:\r
+  Returns the highest bit in the State field\r
+\r
+--*/\r
+{\r
+  EFI_FFS_FILE_STATE  FileState;\r
+  EFI_FFS_FILE_STATE  HighestBit;\r
+\r
+  FileState = FfsHeader->State;\r
+\r
+  if (ErasePolarity != 0) {\r
+    FileState = (EFI_FFS_FILE_STATE)~FileState;\r
+  }\r
+\r
+  HighestBit = 0x80;\r
+  while (HighestBit != 0 && (HighestBit & FileState) == 0) {\r
+    HighestBit >>= 1;\r
+  }\r
+\r
+  return HighestBit;\r
+}\r
+\r
+UINT8\r
+CalculateHeaderChecksum (\r
+  IN EFI_FFS_FILE_HEADER  *FileHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Calculates the checksum of the header of a file.\r
+\r
+Arguments:\r
+  FileHeader       - Pointer to FFS File Header.\r
+\r
+Returns:\r
+  Checksum of the header.\r
+  \r
+--*/\r
+{\r
+  UINT8 *ptr;\r
+  UINTN Index;\r
+  UINT8 Sum;\r
+\r
+  Sum = 0;\r
+  ptr = (UINT8 *) FileHeader;\r
+\r
+  for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) {\r
+    Sum = (UINT8) (Sum + ptr[Index]);\r
+    Sum = (UINT8) (Sum + ptr[Index + 1]);\r
+    Sum = (UINT8) (Sum + ptr[Index + 2]);\r
+    Sum = (UINT8) (Sum + ptr[Index + 3]);\r
+  }\r
+\r
+  for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) {\r
+    Sum = (UINT8) (Sum + ptr[Index]);\r
+  }\r
+  //\r
+  // State field (since this indicates the different state of file).\r
+  //\r
+  Sum = (UINT8) (Sum - FileHeader->State);\r
+  //\r
+  // Checksum field of the file is not part of the header checksum.\r
+  //\r
+  Sum = (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File);\r
+\r
+  return Sum;\r
+}\r
+\r
+EFI_STATUS\r
+SecFfsFindNextFile (\r
+  IN EFI_FV_FILETYPE             SearchType,\r
+  IN EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  IN OUT EFI_FFS_FILE_HEADER     **FileHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Given the input file pointer, search for the next matching file in the\r
+    FFS volume as defined by SearchType. The search starts from FileHeader inside\r
+    the Firmware Volume defined by FwVolHeader.\r
+\r
+Arguments:\r
+    SearchType - Filter to find only files of this type.\r
+                 Type EFI_FV_FILETYPE_ALL causes no filtering to be done.\r
+    FwVolHeader - Pointer to the FV header of the volume to search.\r
+                  This parameter must point to a valid FFS volume.\r
+    FileHeader  - Pointer to the current file from which to begin searching.\r
+                  This pointer will be updated upon return to reflect the file\r
+                  found.\r
+\r
+Returns:\r
+    EFI_NOT_FOUND - No files matching the search criteria were found\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+{\r
+  EFI_FFS_FILE_HEADER *FfsFileHeader;\r
+  UINT32              FileLength;\r
+  UINT32              FileOccupiedSize;\r
+  UINT32              FileOffset;\r
+  UINT64              FvLength;\r
+  UINT8               ErasePolarity;\r
+  UINT8               FileState;\r
+\r
+  FvLength = FwVolHeader->FvLength;\r
+  if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {\r
+    ErasePolarity = 1;\r
+  } else {\r
+    ErasePolarity = 0;\r
+  }\r
+  //\r
+  // If FileHeader is not specified (NULL) start with the first file in the\r
+  // firmware volume.  Otherwise, start from the FileHeader.\r
+  //\r
+  if (*FileHeader == NULL) {\r
+    FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength);\r
+  } else {\r
+    //\r
+    // Length is 24 bits wide so mask upper 8 bits\r
+    // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
+    //\r
+    FileLength        = *(UINT32 *) (*FileHeader)->Size & 0x00FFFFFF;\r
+    FileOccupiedSize  = GET_OCCUPIED_SIZE (FileLength, 8);\r
+    FfsFileHeader     = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize);\r
+  }\r
+\r
+  FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader);\r
+\r
+  while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {\r
+    //\r
+    // Get FileState which is the highest bit of the State\r
+    //\r
+    FileState = GetFileState (ErasePolarity, FfsFileHeader);\r
+\r
+    switch (FileState) {\r
+\r
+    case EFI_FILE_HEADER_INVALID:\r
+      FileOffset += sizeof (EFI_FFS_FILE_HEADER);\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));\r
+      break;\r
+\r
+    case EFI_FILE_DATA_VALID:\r
+    case EFI_FILE_MARKED_FOR_UPDATE:\r
+      if (CalculateHeaderChecksum (FfsFileHeader) == 0) {\r
+        FileLength        = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;\r
+        FileOccupiedSize  = GET_OCCUPIED_SIZE (FileLength, 8);\r
+\r
+        if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) {\r
+\r
+          *FileHeader = FfsFileHeader;\r
+\r
+          return EFI_SUCCESS;\r
+        }\r
+\r
+        FileOffset += FileOccupiedSize;\r
+        FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);\r
+      } else {\r
+        return EFI_NOT_FOUND;\r
+      }\r
+      break;\r
+\r
+    case EFI_FILE_DELETED:\r
+      FileLength        = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;\r
+      FileOccupiedSize  = GET_OCCUPIED_SIZE (FileLength, 8);\r
+      FileOffset += FileOccupiedSize;\r
+      FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);\r
+      break;\r
+\r
+    default:\r
+      return EFI_NOT_FOUND;\r
+\r
+    }\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+SecFfsFindSectionData (\r
+  IN EFI_SECTION_TYPE      SectionType,\r
+  IN EFI_FFS_FILE_HEADER   *FfsFileHeader,\r
+  IN OUT VOID              **SectionData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+    Given the input file pointer, search for the next matching section in the\r
+    FFS volume.\r
+\r
+Arguments:\r
+    SearchType    - Filter to find only sections of this type.\r
+    FfsFileHeader - Pointer to the current file to search.\r
+    SectionData   - Pointer to the Section matching SectionType in FfsFileHeader.\r
+                     NULL if section not found\r
+\r
+Returns:\r
+    EFI_NOT_FOUND - No files matching the search criteria were found\r
+    EFI_SUCCESS\r
+\r
+--*/\r
+{\r
+  UINT32                    FileSize;\r
+  EFI_COMMON_SECTION_HEADER *Section;\r
+  UINT32                    SectionLength;\r
+  UINT32                    ParsedLength;\r
+\r
+  //\r
+  // Size is 24 bits wide so mask upper 8 bits.\r
+  //    Does not include FfsFileHeader header size\r
+  // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.\r
+  //\r
+  Section   = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1);\r
+  FileSize  = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;\r
+  FileSize -= sizeof (EFI_FFS_FILE_HEADER);\r
+\r
+  *SectionData  = NULL;\r
+  ParsedLength  = 0;\r
+  while (ParsedLength < FileSize) {\r
+    if (Section->Type == SectionType) {\r
+      *SectionData = (VOID *) (Section + 1);\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // Size is 24 bits wide so mask upper 8 bits.\r
+    // SectionLength is adjusted it is 4 byte aligned.\r
+    // Go to the next section\r
+    //\r
+    SectionLength = *(UINT32 *) Section->Size & 0x00FFFFFF;\r
+    SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);\r
+\r
+    ParsedLength += SectionLength;\r
+    Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength);\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
+EFI_STATUS\r
+SecFfsFindPeiCore (\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  OUT VOID                        **Pe32Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Given the pointer to the Firmware Volume Header find the SEC\r
+  core and return it's PE32 image.\r
+\r
+Arguments:\r
+  FwVolHeader - Pointer to memory mapped FV\r
+  Pe32Data - Pointer to SEC PE32 iamge.\r
\r
+Returns:  \r
+  EFI_SUCCESS - Pe32Data is valid\r
+  other       - Failure\r
+\r
+--*/\r
+{\r
+  EFI_STATUS          Status;\r
+  EFI_FFS_FILE_HEADER *FileHeader;\r
+  EFI_FV_FILETYPE     SearchType;\r
+\r
+  SearchType  = EFI_FV_FILETYPE_PEI_CORE;\r
+  FileHeader  = NULL;\r
+  do {\r
+    Status = SecFfsFindNextFile (SearchType, FwVolHeader, &FileHeader);\r
+    if (!EFI_ERROR (Status)) {\r
+      Status = SecFfsFindSectionData (EFI_SECTION_PE32, FileHeader, Pe32Data);\r
+      return Status;\r
+    }\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/Sec/SecMain.c b/UnixPkg/Sec/SecMain.c
new file mode 100644 (file)
index 0000000..a6da20b
--- /dev/null
@@ -0,0 +1,1048 @@
+/*++
+
+Copyright (c) 2006 - 2007 Intel Corporation.
+All rights reserved. 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
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+  SecMain.c
+
+Abstract:
+  WinNt emulator of SEC phase. It's really a Posix application, but this is
+  Ok since all the other modules for NT32 are NOT Posix applications.
+
+  This program processes host environment variables and figures out
+  what the memory layout will be, how may FD's will be loaded and also
+  what the boot mode is.
+
+  The SEC registers a set of services with the SEC core. gPrivateDispatchTable
+  is a list of PPI's produced by the SEC that are availble for usage in PEI.
+
+  This code produces 128 K of temporary memory for the PEI stack by opening a
+  host file and mapping it directly to memory addresses.
+
+  The system.cmd script is used to set host environment variables that drive
+  the configuration opitons of the SEC.
+
+--*/
+
+#include "SecMain.h"
+#include <sys/mman.h>
+#include <Ppi/UnixPeiLoadFile.h>
+#include <Framework/StatusCode.h>
+#include <Ppi/TemporaryRamSupport.h>
+#include <dlfcn.h>
+//
+// Globals
+//
+EFI_PEI_PE_COFF_LOADER_PROTOCOL_INSTANCE  mPeiEfiPeiPeCoffLoaderInstance = {
+  {
+    SecNt32PeCoffGetImageInfo,
+    SecNt32PeCoffLoadImage,
+    SecNt32PeCoffRelocateImage,
+    SecNt32PeCoffUnloadimage
+  },
+  NULL
+};
+
+
+
+EFI_PEI_PE_COFF_LOADER_PROTOCOL           *gPeiEfiPeiPeCoffLoader = &mPeiEfiPeiPeCoffLoaderInstance.PeCoff;
+
+UNIX_PEI_LOAD_FILE_PPI                      mSecNtLoadFilePpi     = { SecWinNtPeiLoadFile };
+
+PEI_UNIX_AUTOSCAN_PPI                       mSecNtAutoScanPpi     = { SecWinNtPeiAutoScan };
+
+PEI_UNIX_THUNK_PPI                          mSecWinNtThunkPpi     = { SecWinNtWinNtThunkAddress };
+
+EFI_PEI_PROGRESS_CODE_PPI                 mSecStatusCodePpi     = { SecPeiReportStatusCode };
+
+UNIX_FWH_PPI                                mSecFwhInformationPpi = { SecWinNtFdAddress };
+
+TEMPORARY_RAM_SUPPORT_PPI                 mSecTemporaryRamSupportPpi = {SecTemporaryRamSupport};
+
+EFI_PEI_PPI_DESCRIPTOR  gPrivateDispatchTable[] = {
+  {
+    EFI_PEI_PPI_DESCRIPTOR_PPI,
+    &gEfiPeiPeCoffLoaderGuid,
+    NULL
+  },
+  {
+    EFI_PEI_PPI_DESCRIPTOR_PPI,
+    &gUnixPeiLoadFilePpiGuid,
+    &mSecNtLoadFilePpi
+  },
+  {
+    EFI_PEI_PPI_DESCRIPTOR_PPI,
+    &gPeiUnixAutoScanPpiGuid,
+    &mSecNtAutoScanPpi
+  },
+  {
+    EFI_PEI_PPI_DESCRIPTOR_PPI,
+    &gPeiUnixThunkPpiGuid,
+    &mSecWinNtThunkPpi
+  },
+  {
+    EFI_PEI_PPI_DESCRIPTOR_PPI,
+    &gEfiPeiStatusCodePpiGuid,
+    &mSecStatusCodePpi
+  },
+  {
+    EFI_PEI_PPI_DESCRIPTOR_PPI,
+    &gEfiTemporaryRamSupportPpiGuid,
+    &mSecTemporaryRamSupportPpi
+  },
+  {
+
+    EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST,
+    &gUnixFwhPpiGuid,
+    &mSecFwhInformationPpi
+  }
+};
+
+
+//
+// Default information about where the FD is located.
+//  This array gets filled in with information from EFI_FIRMWARE_VOLUMES
+//  EFI_FIRMWARE_VOLUMES is a host environment variable set by system.cmd.
+//  The number of array elements is allocated base on parsing
+//  EFI_FIRMWARE_VOLUMES and the memory is never freed.
+//
+UINTN                                     gFdInfoCount = 0;
+UNIX_FD_INFO                                *gFdInfo;
+
+//
+// Array that supports seperate memory rantes.
+//  The memory ranges are set in system.cmd via the EFI_MEMORY_SIZE variable.
+//  The number of array elements is allocated base on parsing
+//  EFI_MEMORY_SIZE and the memory is never freed.
+//
+UINTN                                     gSystemMemoryCount = 0;
+UNIX_SYSTEM_MEMORY                       *gSystemMemory;
+
+VOID
+EFIAPI
+SecSwitchStack (
+  UINT32   TemporaryMemoryBase,
+  UINT32   PermenentMemoryBase
+  );
+
+STATIC
+EFI_PHYSICAL_ADDRESS *
+MapMemory (
+  INTN fd,
+  UINT64 length,
+  INTN   prot,
+  INTN   flags);
+
+STATIC
+EFI_STATUS
+MapFile (
+  IN  CHAR8                     *FileName,
+  IN OUT  EFI_PHYSICAL_ADDRESS  *BaseAddress,
+  OUT UINT64                    *Length
+  );
+
+
+INTN
+EFIAPI
+main (
+  IN  INTN  Argc,
+  IN  CHAR8 **Argv,
+  IN  CHAR8 **Envp
+  )
+/*++
+
+Routine Description:
+  Main entry point to SEC for WinNt. This is a unix program
+
+Arguments:
+  Argc - Number of command line arguments
+  Argv - Array of command line argument strings
+  Envp - Array of environmemt variable strings
+
+Returns:
+  0 - Normal exit
+  1 - Abnormal exit
+
+--*/
+{
+  EFI_STATUS            Status;
+  EFI_PHYSICAL_ADDRESS  InitialStackMemory;
+  UINT64                InitialStackMemorySize;
+  UINTN                 Index;
+  UINTN                 Index1;
+  UINTN                 Index2;
+  UINTN                 PeiIndex;
+  CHAR8                 *FileName;
+  BOOLEAN               Done;
+  VOID                  *PeiCoreFile;
+  CHAR16                *MemorySizeStr;
+  CHAR16                *FirmwareVolumesStr;
+  UINTN                 *StackPointer;
+
+  setbuf(stdout, 0);
+  setbuf(stderr, 0);
+
+  MemorySizeStr      = (CHAR16 *) FixedPcdGetPtr (PcdUnixMemorySizeForSecMain);
+  FirmwareVolumesStr = (CHAR16 *) FixedPcdGetPtr (PcdUnixFirmwareVolume);
+
+  printf ("\nEDK SEC Main UNIX Emulation Environment from www.TianoCore.org\n");
+
+  //
+  // Allocate space for gSystemMemory Array
+  //
+  gSystemMemoryCount  = CountSeperatorsInString (MemorySizeStr, '!') + 1;
+  gSystemMemory       = calloc (gSystemMemoryCount, sizeof (UNIX_SYSTEM_MEMORY));
+  if (gSystemMemory == NULL) {
+    printf ("ERROR : Can not allocate memory for system.  Exiting.\n");
+    exit (1);
+  }
+  //
+  // Allocate space for gSystemMemory Array
+  //
+  gFdInfoCount  = CountSeperatorsInString (FirmwareVolumesStr, '!') + 1;
+  gFdInfo       = calloc (gFdInfoCount, sizeof (UNIX_FD_INFO));
+  if (gFdInfo == NULL) {
+    printf ("ERROR : Can not allocate memory for fd info.  Exiting.\n");
+    exit (1);
+  }
+  //
+  // Setup Boot Mode. If BootModeStr == "" then BootMode = 0 (BOOT_WITH_FULL_CONFIGURATION)
+  //
+  printf ("  BootMode 0x%02x\n", FixedPcdGet32 (PcdUnixBootMode));
+
+  //
+  // Open up a 128K file to emulate temp memory for PEI.
+  //  on a real platform this would be SRAM, or using the cache as RAM.
+  //  Set InitialStackMemory to zero so WinNtOpenFile will allocate a new mapping
+  //
+  InitialStackMemorySize  = STACK_SIZE;
+  InitialStackMemory = (UINTN)MapMemory(0, 
+          (UINT32) InitialStackMemorySize,
+          PROT_READ | PROT_WRITE,
+          MAP_ANONYMOUS | MAP_PRIVATE);
+  if (InitialStackMemory == 0) {
+    printf ("ERROR : Can not open SecStack Exiting\n");
+    exit (1);
+  }
+
+  printf ("  SEC passing in %u KB of temp RAM at 0x%08lx to PEI\n",
+    (UINTN)(InitialStackMemorySize / 1024),
+    (unsigned long)InitialStackMemory);
+    
+  for (StackPointer = (UINTN*) (UINTN) InitialStackMemory;
+     StackPointer < (UINTN*) ((UINTN) InitialStackMemory + (UINT64) InitialStackMemorySize);
+     StackPointer ++) {
+    *StackPointer = 0x5AA55AA5;
+  }
+
+  //
+  // Open All the firmware volumes and remember the info in the gFdInfo global
+  //
+  FileName = (CHAR8 *)malloc (StrLen (FirmwareVolumesStr) + 1);
+  if (FileName == NULL) {
+    printf ("ERROR : Can not allocate memory for firmware volume string\n");
+    exit (1);
+  }
+
+  Index2 = 0;
+  for (Done = FALSE, Index = 0, PeiIndex = 0, PeiCoreFile = NULL;
+       FirmwareVolumesStr[Index2] != 0;
+       Index++) {
+    for (Index1 = 0; (FirmwareVolumesStr[Index2] != '!') && (FirmwareVolumesStr[Index2] != 0); Index2++)
+      FileName[Index1++] = FirmwareVolumesStr[Index2];
+    if (FirmwareVolumesStr[Index2] == '!')
+      Index2++;
+    FileName[Index1]  = '\0';
+
+    //
+    // Open the FD and remmeber where it got mapped into our processes address space
+    //
+    Status = MapFile (
+                     FileName,
+                     &gFdInfo[Index].Address,
+                     &gFdInfo[Index].Size
+                     );
+    if (EFI_ERROR (Status)) {
+      printf ("ERROR : Can not open Firmware Device File %s (%x).  Exiting.\n", FileName, Status);
+      exit (1);
+    }
+
+    printf ("  FD loaded from %s at 0x%08lx",
+           FileName, (unsigned long)gFdInfo[Index].Address);
+
+    if (PeiCoreFile == NULL) {
+      //
+      // Assume the beginning of the FD is an FV and look for the PEI Core.
+      // Load the first one we find.
+      //
+      Status = SecFfsFindPeiCore ((EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) gFdInfo[Index].Address, &PeiCoreFile);
+      if (!EFI_ERROR (Status)) {
+        PeiIndex = Index;
+        printf (" contains SEC Core");
+      }
+    }
+
+    printf ("\n");
+  }
+  //
+  // Calculate memory regions and store the information in the gSystemMemory
+  //  global for later use. The autosizing code will use this data to
+  //  map this memory into the SEC process memory space.
+  //
+  Index1 = 0;
+  Index = 0;
+  while (1) {
+    UINTN val = 0;
+    //
+    // Save the size of the memory.
+    //
+    while (MemorySizeStr[Index1] >= '0' && MemorySizeStr[Index1] <= '9') {
+      val = val * 10 + MemorySizeStr[Index1] - '0';
+      Index1++;
+    }
+    gSystemMemory[Index++].Size = val * 0x100000;
+    if (MemorySizeStr[Index1] == 0)
+      break;
+    Index1++;
+  }
+
+  printf ("\n");
+
+  //
+  // Hand off to PEI Core
+  //
+  SecLoadFromCore ((UINTN) InitialStackMemory, (UINTN) InitialStackMemorySize, (UINTN) gFdInfo[0].Address, PeiCoreFile);
+
+  //
+  // If we get here, then the PEI Core returned. This is an error as PEI should
+  //  always hand off to DXE.
+  //
+  printf ("ERROR : PEI Core returned\n");
+  exit (1);
+}
+
+EFI_PHYSICAL_ADDRESS *
+MapMemory (
+  INTN fd,
+  UINT64 length,
+  INTN   prot,
+  INTN   flags)
+{
+  STATIC UINTN base  = 0x40000000;
+  CONST UINTN  align = (1 << 24);
+  VOID         *res  = NULL;
+  BOOLEAN      isAligned = 0;
+
+  //
+  // Try to get an aligned block somewhere in the address space of this
+  // process.
+  //
+  while((!isAligned) && (base != 0)) {
+    res = mmap ((void *)base, length, prot, flags, fd, 0);
+    if (res == MAP_FAILED) {
+      return NULL;
+    }
+    if ((((UINTN)res) & ~(align-1)) == (UINTN)res) {
+      isAligned=1;
+    }
+    else {
+      munmap(res, length);
+      base += align;
+    }
+  }
+  return res;
+}
+
+EFI_STATUS
+MapFile (
+  IN  CHAR8                     *FileName,
+  IN OUT  EFI_PHYSICAL_ADDRESS  *BaseAddress,
+  OUT UINT64                    *Length
+  )
+/*++
+
+Routine Description:
+  Opens and memory maps a file using WinNt services. If BaseAddress is non zero
+  the process will try and allocate the memory starting at BaseAddress.
+
+Arguments:
+  FileName            - The name of the file to open and map
+  MapSize             - The amount of the file to map in bytes
+  CreationDisposition - The flags to pass to CreateFile().  Use to create new files for
+                        memory emulation, and exiting files for firmware volume emulation
+  BaseAddress         - The base address of the mapped file in the user address space.
+                         If passed in as NULL the a new memory region is used.
+                         If passed in as non NULL the request memory region is used for
+                          the mapping of the file into the process space.
+  Length              - The size of the mapped region in bytes
+
+Returns:
+  EFI_SUCCESS      - The file was opened and mapped.
+  EFI_NOT_FOUND    - FileName was not found in the current directory
+  EFI_DEVICE_ERROR - An error occured attempting to map the opened file
+
+--*/
+{
+  int fd;
+  VOID    *res;
+  UINTN   FileSize;
+
+  fd = open (FileName, O_RDONLY);
+  if (fd < 0)
+    return EFI_NOT_FOUND;
+  FileSize = lseek (fd, 0, SEEK_END);
+
+#if 0
+  if (IsMain)
+    {
+      /* Read entry address.  */
+      lseek (fd, FileSize - 0x20, SEEK_SET);
+      if (read (fd, &EntryAddress, 4) != 4)
+       {
+         close (fd);
+         return EFI_DEVICE_ERROR;
+       }      
+    }
+#endif
+
+  res = MapMemory(fd, FileSize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE);
+  
+  close (fd);
+
+  if (res == MAP_FAILED)
+    return EFI_DEVICE_ERROR;
+
+  *Length = (UINT64) FileSize;
+  *BaseAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) res;
+
+  return EFI_SUCCESS;
+}
+
+#define BYTES_PER_RECORD  512
+
+EFI_STATUS
+EFIAPI
+SecPeiReportStatusCode (
+  IN EFI_PEI_SERVICES           **PeiServices,
+  IN EFI_STATUS_CODE_TYPE       CodeType,
+  IN EFI_STATUS_CODE_VALUE      Value,
+  IN UINT32                     Instance,
+  IN EFI_GUID                   * CallerId,
+  IN EFI_STATUS_CODE_DATA       * Data OPTIONAL
+  )
+/*++
+
+Routine Description:
+
+  This routine produces the ReportStatusCode PEI service. It's passed
+  up to the PEI Core via a PPI. T
+
+  This code currently uses the UNIX clib printf. This does not work the same way
+  as the EFI Print (), as %t, %g, %s as Unicode are not supported.
+
+Arguments:
+  (see EFI_PEI_REPORT_STATUS_CODE)
+
+Returns:
+  EFI_SUCCESS - Always return success
+
+--*/
+// TODO:    PeiServices - add argument and description to function comment
+// TODO:    CodeType - add argument and description to function comment
+// TODO:    Value - add argument and description to function comment
+// TODO:    Instance - add argument and description to function comment
+// TODO:    CallerId - add argument and description to function comment
+// TODO:    Data - add argument and description to function comment
+{
+  CHAR8           *Format;
+  VA_LIST         Marker;
+  CHAR8           PrintBuffer[BYTES_PER_RECORD * 2];
+  CHAR8           *Filename;
+  CHAR8           *Description;
+  UINT32          LineNumber;
+  UINT32          ErrorLevel;
+
+
+  if (Data == NULL) {
+  } else if (ReportStatusCodeExtractAssertInfo (CodeType, Value, Data, &Filename, &Description, &LineNumber)) {
+    //
+    // Processes ASSERT ()
+    //
+    printf ("ASSERT %s(%d): %s\n", Filename, LineNumber, Description);
+
+  } else if (ReportStatusCodeExtractDebugInfo (Data, &ErrorLevel, &Marker, &Format)) {
+    //
+    // Process DEBUG () macro 
+    //
+    AsciiVSPrint (PrintBuffer, BYTES_PER_RECORD, Format, Marker);
+    printf (PrintBuffer);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+  Transfers control to a function starting with a new stack.
+
+  Transfers control to the function specified by EntryPoint using the new stack
+  specified by NewStack and passing in the parameters specified by Context1 and
+  Context2. Context1 and Context2 are optional and may be NULL. The function
+  EntryPoint must never return.
+
+  If EntryPoint is NULL, then ASSERT().
+  If NewStack is NULL, then ASSERT().
+
+  @param  EntryPoint  A pointer to function to call with the new stack.
+  @param  Context1    A pointer to the context to pass into the EntryPoint
+                      function.
+  @param  Context2    A pointer to the context to pass into the EntryPoint
+                      function.
+  @param  NewStack    A pointer to the new stack to use for the EntryPoint
+                      function.
+  @param  NewBsp      A pointer to the new BSP for the EntryPoint on IPF. It's
+                      Reserved on other architectures.
+
+**/
+VOID
+EFIAPI
+PeiSwitchStacks (
+  IN      SWITCH_STACK_ENTRY_POINT  EntryPoint,
+  IN      VOID                      *Context1,  OPTIONAL
+  IN      VOID                      *Context2,  OPTIONAL
+  IN      VOID                      *Context3,  OPTIONAL
+  IN      VOID                      *NewStack
+  )
+{
+  BASE_LIBRARY_JUMP_BUFFER  JumpBuffer;
+  
+  ASSERT (EntryPoint != NULL);
+  ASSERT (NewStack != NULL);
+
+  //
+  // Stack should be aligned with CPU_STACK_ALIGNMENT
+  //
+  ASSERT (((UINTN)NewStack & (CPU_STACK_ALIGNMENT - 1)) == 0);
+
+  JumpBuffer.Eip = (UINTN)EntryPoint;
+  JumpBuffer.Esp = (UINTN)NewStack - sizeof (VOID*);
+  JumpBuffer.Esp -= sizeof (Context1) + sizeof (Context2) + sizeof(Context3);
+  ((VOID**)JumpBuffer.Esp)[1] = Context1;
+  ((VOID**)JumpBuffer.Esp)[2] = Context2;
+  ((VOID**)JumpBuffer.Esp)[3] = Context3;
+
+  LongJump (&JumpBuffer, (UINTN)-1);
+  
+
+  //
+  // InternalSwitchStack () will never return
+  //
+  ASSERT (FALSE);  
+}
+
+VOID
+SecLoadFromCore (
+  IN  UINTN   LargestRegion,
+  IN  UINTN   LargestRegionSize,
+  IN  UINTN   BootFirmwareVolumeBase,
+  IN  VOID    *PeiCorePe32File
+  )
+/*++
+
+Routine Description:
+  This is the service to load the PEI Core from the Firmware Volume
+
+Arguments:
+  LargestRegion           - Memory to use for PEI.
+  LargestRegionSize       - Size of Memory to use for PEI
+  BootFirmwareVolumeBase  - Start of the Boot FV
+  PeiCorePe32File         - PEI Core PE32
+
+Returns:
+  Success means control is transfered and thus we should never return
+
+--*/
+{
+  EFI_STATUS                  Status;
+  EFI_PHYSICAL_ADDRESS        TopOfMemory;
+  VOID                        *TopOfStack;
+  UINT64                      PeiCoreSize;
+  EFI_PHYSICAL_ADDRESS        PeiCoreEntryPoint;
+  EFI_PHYSICAL_ADDRESS        PeiImageAddress;
+  EFI_SEC_PEI_HAND_OFF        *SecCoreData;
+  UINTN                       PeiStackSize;
+
+  //
+  // Compute Top Of Memory for Stack and PEI Core Allocations
+  //
+  TopOfMemory  = LargestRegion + LargestRegionSize;
+  PeiStackSize = (UINTN)RShiftU64((UINT64)STACK_SIZE,1);
+
+  //
+  // |-----------| <---- TemporaryRamBase + TemporaryRamSize
+  // |   Heap    |
+  // |           |
+  // |-----------| <---- StackBase / PeiTemporaryMemoryBase
+  // |           |
+  // |  Stack    |
+  // |-----------| <---- TemporaryRamBase
+  // 
+  TopOfStack  = (VOID *)(LargestRegion + PeiStackSize);
+  TopOfMemory = LargestRegion + PeiStackSize;
+
+  //
+  // Reservet space for storing PeiCore's parament in stack.
+  // 
+  TopOfStack  = (VOID *)((UINTN)TopOfStack - sizeof (EFI_SEC_PEI_HAND_OFF) - CPU_STACK_ALIGNMENT);
+  TopOfStack  = ALIGN_POINTER (TopOfStack, CPU_STACK_ALIGNMENT);
+
+  //
+  // Patch value in dispatch table values
+  //
+  gPrivateDispatchTable[0].Ppi = gPeiEfiPeiPeCoffLoader;
+
+  //
+  // Bind this information into the SEC hand-off state
+  //
+  SecCoreData                        = (EFI_SEC_PEI_HAND_OFF*)(UINTN) TopOfStack;
+  SecCoreData->DataSize               = sizeof(EFI_SEC_PEI_HAND_OFF);
+  SecCoreData->BootFirmwareVolumeBase = (VOID*)BootFirmwareVolumeBase;
+  SecCoreData->BootFirmwareVolumeSize = FixedPcdGet32(PcdUnixFirmwareFdSize);
+  SecCoreData->TemporaryRamBase       = (VOID*)(UINTN)LargestRegion; 
+  SecCoreData->TemporaryRamSize       = STACK_SIZE;
+  SecCoreData->StackBase              = SecCoreData->TemporaryRamBase;
+  SecCoreData->StackSize              = PeiStackSize;
+  SecCoreData->PeiTemporaryRamBase    = (VOID*) ((UINTN) SecCoreData->TemporaryRamBase + PeiStackSize);
+  SecCoreData->PeiTemporaryRamSize    = STACK_SIZE - PeiStackSize;
+
+  //
+  // Load the PEI Core from a Firmware Volume
+  //
+  Status = SecWinNtPeiLoadFile (
+            PeiCorePe32File,
+            &PeiImageAddress,
+            &PeiCoreSize,
+            &PeiCoreEntryPoint
+            );
+  if (EFI_ERROR (Status)) {
+    return ;
+  }
+  
+  //
+  // Transfer control to the PEI Core
+  //
+  PeiSwitchStacks (
+    (SWITCH_STACK_ENTRY_POINT) (UINTN) PeiCoreEntryPoint,
+    SecCoreData,
+    (VOID *) (UINTN) ((EFI_PEI_PPI_DESCRIPTOR *) &gPrivateDispatchTable),
+    NULL,
+    TopOfStack
+    );
+  //
+  // If we get here, then the PEI Core returned.  This is an error
+  //
+  return ;
+}
+
+EFI_STATUS
+EFIAPI
+SecWinNtPeiAutoScan (
+  IN  UINTN                 Index,
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,
+  OUT UINT64                *MemorySize
+  )
+/*++
+
+Routine Description:
+  This service is called from Index == 0 until it returns EFI_UNSUPPORTED.
+  It allows discontiguous memory regions to be supported by the emulator.
+  It uses gSystemMemory[] and gSystemMemoryCount that were created by
+  parsing the host environment variable EFI_MEMORY_SIZE.
+  The size comes from the varaible and the address comes from the call to
+  WinNtOpenFile.
+
+Arguments:
+  Index      - Which memory region to use
+  MemoryBase - Return Base address of memory region
+  MemorySize - Return size in bytes of the memory region
+
+Returns:
+  EFI_SUCCESS - If memory region was mapped
+  EFI_UNSUPPORTED - If Index is not supported
+
+--*/
+{
+  void *res;
+
+  if (Index >= gSystemMemoryCount) {
+    return EFI_UNSUPPORTED;
+  }
+
+  *MemoryBase = 0;
+  res = MapMemory(0, gSystemMemory[Index].Size,
+                 PROT_READ | PROT_WRITE | PROT_EXEC,
+                 MAP_PRIVATE | MAP_ANONYMOUS);
+  if (res == MAP_FAILED)
+    return EFI_DEVICE_ERROR;
+  *MemorySize = gSystemMemory[Index].Size;
+  *MemoryBase = (UINTN)res;
+  gSystemMemory[Index].Memory = *MemoryBase;
+
+  return EFI_SUCCESS;
+}
+
+VOID *
+EFIAPI
+SecWinNtWinNtThunkAddress (
+  VOID
+  )
+/*++
+
+Routine Description:
+  Since the SEC is the only Unix program in stack it must export
+  an interface to do Win API calls. That's what the WinNtThunk address
+  is for. gWinNt is initailized in WinNtThunk.c.
+
+Arguments:
+  InterfaceSize - sizeof (EFI_WIN_NT_THUNK_PROTOCOL);
+  InterfaceBase - Address of the gWinNt global
+
+Returns:
+  EFI_SUCCESS - Data returned
+
+--*/
+{
+  return gUnix;
+}
+
+
+EFI_STATUS
+EFIAPI
+SecWinNtPeiLoadFile (
+  IN  VOID                    *Pe32Data,
+  IN  EFI_PHYSICAL_ADDRESS    *ImageAddress,
+  IN  UINT64                  *ImageSize,
+  IN  EFI_PHYSICAL_ADDRESS    *EntryPoint
+  )
+/*++
+
+Routine Description:
+  Loads and relocates a PE/COFF image into memory.
+
+Arguments:
+  Pe32Data         - The base address of the PE/COFF file that is to be loaded and relocated
+  ImageAddress     - The base address of the relocated PE/COFF image
+  ImageSize        - The size of the relocated PE/COFF image
+  EntryPoint       - The entry point of the relocated PE/COFF image
+
+Returns:
+  EFI_SUCCESS   - The file was loaded and relocated
+  EFI_OUT_OF_RESOURCES - There was not enough memory to load and relocate the PE/COFF file
+
+--*/
+{
+  EFI_STATUS                            Status;
+  PE_COFF_LOADER_IMAGE_CONTEXT          ImageContext;
+
+  ZeroMem (&ImageContext, sizeof (ImageContext));
+  ImageContext.Handle     = Pe32Data;
+
+  ImageContext.ImageRead  = (PE_COFF_LOADER_READ_FILE) SecImageRead;
+
+  Status                  = gPeiEfiPeiPeCoffLoader->GetImageInfo (gPeiEfiPeiPeCoffLoader, &ImageContext);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+  //
+  // Allocate space in UNIX (not emulator) memory. Extra space is for alignment
+  //
+  ImageContext.ImageAddress = (EFI_PHYSICAL_ADDRESS) (UINTN) malloc ((UINTN) (ImageContext.ImageSize + (ImageContext.SectionAlignment * 2)));
+  if (ImageContext.ImageAddress == 0) {
+    return EFI_OUT_OF_RESOURCES;
+  }
+  //
+  // Align buffer on section boundry
+  //
+  ImageContext.ImageAddress += ImageContext.SectionAlignment;
+  ImageContext.ImageAddress &= ~(ImageContext.SectionAlignment - 1);
+
+
+  Status = gPeiEfiPeiPeCoffLoader->LoadImage (gPeiEfiPeiPeCoffLoader, &ImageContext);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = gPeiEfiPeiPeCoffLoader->RelocateImage (gPeiEfiPeiPeCoffLoader, &ImageContext);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  //
+  // BugBug: Flush Instruction Cache Here when CPU Lib is ready
+  //
+
+  *ImageAddress = ImageContext.ImageAddress;
+  *ImageSize    = ImageContext.ImageSize;
+  *EntryPoint   = ImageContext.EntryPoint;
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+SecWinNtFdAddress (
+  IN     UINTN                 Index,
+  IN OUT EFI_PHYSICAL_ADDRESS  *FdBase,
+  IN OUT UINT64                *FdSize
+  )
+/*++
+
+Routine Description:
+  Return the FD Size and base address. Since the FD is loaded from a
+  file into host memory only the SEC will know it's address.
+
+Arguments:
+  Index  - Which FD, starts at zero.
+  FdSize - Size of the FD in bytes
+  FdBase - Start address of the FD. Assume it points to an FV Header
+
+Returns:
+  EFI_SUCCESS     - Return the Base address and size of the FV
+  EFI_UNSUPPORTED - Index does nto map to an FD in the system
+
+--*/
+{
+  if (Index >= gFdInfoCount) {
+    return EFI_UNSUPPORTED;
+  }
+
+  *FdBase = gFdInfo[Index].Address;
+  *FdSize = gFdInfo[Index].Size;
+
+  if (*FdBase == 0 && *FdSize == 0) {
+    return EFI_UNSUPPORTED;
+  }
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+SecImageRead (
+  IN     VOID    *FileHandle,
+  IN     UINTN   FileOffset,
+  IN OUT UINTN   *ReadSize,
+  OUT    VOID    *Buffer
+  )
+/*++
+
+Routine Description:
+  Support routine for the PE/COFF Loader that reads a buffer from a PE/COFF file
+
+Arguments:
+  FileHandle - The handle to the PE/COFF file
+  FileOffset - The offset, in bytes, into the file to read
+  ReadSize   - The number of bytes to read from the file starting at FileOffset
+  Buffer     - A pointer to the buffer to read the data into.
+
+Returns:
+  EFI_SUCCESS - ReadSize bytes of data were read into Buffer from the PE/COFF file starting at FileOffset
+
+--*/
+{
+  CHAR8 *Destination8;
+  CHAR8 *Source8;
+  UINTN Length;
+
+  Destination8  = Buffer;
+  Source8       = (CHAR8 *) ((UINTN) FileHandle + FileOffset);
+  Length        = *ReadSize;
+  while (Length--) {
+    *(Destination8++) = *(Source8++);
+  }
+
+  return EFI_SUCCESS;
+}
+
+UINTN
+CountSeperatorsInString (
+  IN  const CHAR16   *String,
+  IN  CHAR16         Seperator
+  )
+/*++
+
+Routine Description:
+  Count the number of seperators in String
+
+Arguments:
+  String    - String to process
+  Seperator - Item to count
+
+Returns:
+  Number of Seperator in String
+
+--*/
+{
+  UINTN Count;
+
+  for (Count = 0; *String != '\0'; String++) {
+    if (*String == Seperator) {
+      Count++;
+    }
+  }
+
+  return Count;
+}
+
+
+
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffGetImageInfo (
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = PeCoffLoaderGetImageInfo (ImageContext);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  switch (ImageContext->ImageType) {
+
+  case EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION:
+    ImageContext->ImageCodeMemoryType = EfiLoaderCode;
+    ImageContext->ImageDataMemoryType = EfiLoaderData;
+    break;
+
+  case EFI_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER:
+    ImageContext->ImageCodeMemoryType = EfiBootServicesCode;
+    ImageContext->ImageDataMemoryType = EfiBootServicesData;
+    break;
+
+  case EFI_IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER:
+  case EFI_IMAGE_SUBSYSTEM_SAL_RUNTIME_DRIVER:
+    ImageContext->ImageCodeMemoryType = EfiRuntimeServicesCode;
+    ImageContext->ImageDataMemoryType = EfiRuntimeServicesData;
+    break;
+
+  default:
+    ImageContext->ImageError = IMAGE_ERROR_INVALID_SUBSYSTEM;
+    return RETURN_UNSUPPORTED;
+  }
+
+  return Status;
+}
+
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffLoadImage (
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = PeCoffLoaderLoadImage (ImageContext);
+  return Status;
+}
+
+VOID
+SecUnixLoaderBreak (
+  VOID
+  )
+{
+}
+
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffRelocateImage (
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext
+  )
+{
+  void * Handle;
+  void * Entry;
+  EFI_STATUS Status;
+
+  Handle = NULL;
+  Entry  = NULL;
+  Status = PeCoffLoaderRelocateImage (ImageContext);
+  fprintf (stderr, 
+     "Loading %s 0x%08lx - entry point 0x%08lx\n",
+     ImageContext->PdbPointer,
+     (unsigned long)ImageContext->ImageAddress,
+     (unsigned long)ImageContext->EntryPoint);
+
+  SecUnixLoaderBreak ();
+
+  return Status;
+}
+
+
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffUnloadimage (
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL      *This,
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext
+  )
+{
+  return EFI_SUCCESS;
+}
+
+VOID
+ModuleEntryPoint (
+  VOID
+  )
+{
+}
+
+EFI_STATUS
+EFIAPI
+SecTemporaryRamSupport (
+  IN CONST EFI_PEI_SERVICES   **PeiServices,
+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,
+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,
+  IN UINTN                    CopySize
+  )
+{
+  //
+  // Migrate the whole temporary memory to permenent memory.
+  // 
+  CopyMem (
+    (VOID*)(UINTN)PermanentMemoryBase, 
+    (VOID*)(UINTN)TemporaryMemoryBase, 
+    CopySize
+    );
+
+  //
+  // SecSwitchStack function must be invoked after the memory migration
+  // immediatly, also we need fixup the stack change caused by new call into 
+  // permenent memory.
+  // 
+  SecSwitchStack (
+    (UINT32) TemporaryMemoryBase,
+    (UINT32) PermanentMemoryBase
+    );
+
+  //
+  // We need *not* fix the return address because currently, 
+  // The PeiCore is excuted in flash.
+  //
+
+  //
+  // Simulate to invalid CAR, terminate CAR
+  // 
+  //ZeroMem ((VOID*)(UINTN)TemporaryMemoryBase, CopySize);
+  
+  return EFI_SUCCESS;
+}
diff --git a/UnixPkg/Sec/SecMain.h b/UnixPkg/Sec/SecMain.h
new file mode 100644 (file)
index 0000000..9714b5a
--- /dev/null
@@ -0,0 +1,548 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+Module Name:\r
+  SecMain.h\r
+\r
+Abstract:\r
+  Include file for host API based SEC\r
+\r
+--*/\r
+#include "PiPei.h"\r
+#include "Uefi/UefiSpec.h"\r
+\r
+#include <Protocol/UnixThunk.h>\r
+#include <Pi/PiFirmwareVolume.h>\r
+#include <Guid/PeiPeCoffLoader.h>\r
+#include <Ppi/StatusCode.h>\r
+\r
+#include <Library/PeCoffLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PrintLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+\r
+#define STACK_SIZE                0x20000      \r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS  Address;\r
+  UINT64                Size;\r
+} UNIX_FD_INFO;\r
+\r
+typedef struct {\r
+  EFI_PHYSICAL_ADDRESS  Memory;\r
+  UINT64                Size;\r
+} UNIX_SYSTEM_MEMORY;\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeiLoadFile (\r
+  VOID                  *Pe32Data,  // TODO: add IN/OUT modifier to Pe32Data\r
+  EFI_PHYSICAL_ADDRESS  *ImageAddress,  // TODO: add IN/OUT modifier to ImageAddress\r
+  UINT64                *ImageSize,  // TODO: add IN/OUT modifier to ImageSize\r
+  EFI_PHYSICAL_ADDRESS  *EntryPoint  // TODO: add IN/OUT modifier to EntryPoint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Pe32Data      - TODO: add argument description\r
+  ImageAddress  - TODO: add argument description\r
+  ImageSize     - TODO: add argument description\r
+  EntryPoint    - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeiAutoScan (\r
+  IN  UINTN                 Index,\r
+  OUT EFI_PHYSICAL_ADDRESS  *MemoryBase,\r
+  OUT UINT64                *MemorySize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Index       - TODO: add argument description\r
+  MemoryBase  - TODO: add argument description\r
+  MemorySize  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID *\r
+EFIAPI\r
+SecWinNtWinNtThunkAddress (\r
+  VOID\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  InterfaceSize - TODO: add argument description\r
+  InterfaceBase - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtWinNtFwhAddress (\r
+  IN OUT UINT64                *FwhSize,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FwhBase\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  FwhSize - TODO: add argument description\r
+  FwhBase - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecPeiReportStatusCode (\r
+  IN EFI_PEI_SERVICES         **PeiServices,\r
+  IN EFI_STATUS_CODE_TYPE     CodeType,\r
+  IN EFI_STATUS_CODE_VALUE    Value,\r
+  IN UINT32                   Instance,\r
+  IN EFI_GUID                 * CallerId,\r
+  IN EFI_STATUS_CODE_DATA     * Data OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  PeiServices - TODO: add argument description\r
+  CodeType    - TODO: add argument description\r
+  Value       - TODO: add argument description\r
+  Instance    - TODO: add argument description\r
+  CallerId    - TODO: add argument description\r
+  Data        - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+INTN\r
+EFIAPI\r
+main (\r
+  IN  INTN  Argc,\r
+  IN  CHAR8 **Argv,\r
+  IN  CHAR8 **Envp\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Argc  - TODO: add argument description\r
+  Argv  - TODO: add argument description\r
+  Envp  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+VOID\r
+SecLoadFromCore (\r
+  IN  UINTN   LargestRegion,\r
+  IN  UINTN   LargestRegionSize,\r
+  IN  UINTN   BootFirmwareVolumeBase,\r
+  IN  VOID    *PeiCoreFile\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  LargestRegion           - TODO: add argument description\r
+  LargestRegionSize       - TODO: add argument description\r
+  BootFirmwareVolumeBase  - TODO: add argument description\r
+  PeiCoreFile             - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+SecLoadFile (\r
+  IN  VOID                    *Pe32Data,\r
+  IN  EFI_PHYSICAL_ADDRESS    *ImageAddress,\r
+  IN  UINT64                  *ImageSize,\r
+  IN  EFI_PHYSICAL_ADDRESS    *EntryPoint\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Pe32Data      - TODO: add argument description\r
+  ImageAddress  - TODO: add argument description\r
+  ImageSize     - TODO: add argument description\r
+  EntryPoint    - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+SecFfsFindPeiCore (\r
+  IN  EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  OUT VOID                        **Pe32Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  FwVolHeader - TODO: add argument description\r
+  Pe32Data    - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+SecFfsFindNextFile (\r
+  IN EFI_FV_FILETYPE             SearchType,\r
+  IN EFI_FIRMWARE_VOLUME_HEADER  *FwVolHeader,\r
+  IN OUT EFI_FFS_FILE_HEADER     **FileHeader\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  SearchType  - TODO: add argument description\r
+  FwVolHeader - TODO: add argument description\r
+  FileHeader  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+SecFfsFindSectionData (\r
+  IN EFI_SECTION_TYPE      SectionType,\r
+  IN EFI_FFS_FILE_HEADER   *FfsFileHeader,\r
+  IN OUT VOID              **SectionData\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  SectionType   - TODO: add argument description\r
+  FfsFileHeader - TODO: add argument description\r
+  SectionData   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeCoffLoaderLoadAsDll (\r
+  IN CHAR8    *PdbFileName,\r
+  IN VOID     **ImageEntryPoint,\r
+  OUT VOID    **ModHandle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  PdbFileName     - TODO: add argument description\r
+  ImageEntryPoint - TODO: add argument description\r
+  ModHandle       - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtPeCoffLoaderFreeLibrary (\r
+  OUT VOID    *ModHandle\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ModHandle - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecWinNtFdAddress (\r
+  IN     UINTN                 Index,\r
+  IN OUT EFI_PHYSICAL_ADDRESS  *FdBase,\r
+  IN OUT UINT64                *FdSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Index   - TODO: add argument description\r
+  FdBase  - TODO: add argument description\r
+  FdSize  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+GetImageReadFunction (\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT          *ImageContext,\r
+  IN EFI_PHYSICAL_ADDRESS                  *TopOfMemory\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ImageContext  - TODO: add argument description\r
+  TopOfMemory   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecImageRead (\r
+  IN     VOID    *FileHandle,\r
+  IN     UINTN   FileOffset,\r
+  IN OUT UINTN   *ReadSize,\r
+  OUT    VOID    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  FileHandle  - TODO: add argument description\r
+  FileOffset  - TODO: add argument description\r
+  ReadSize    - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+CHAR16                            *\r
+AsciiToUnicode (\r
+  IN  CHAR8   *Ascii,\r
+  IN  UINTN   *StrLen OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Ascii   - TODO: add argument description\r
+  StrLen  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+UINTN\r
+CountSeperatorsInString (\r
+  IN  const CHAR16   *String,\r
+  IN  CHAR16   Seperator\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  String    - TODO: add argument description\r
+  Seperator - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffGetImageInfo (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffLoadImage (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffRelocateImage (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL          *This,\r
+  IN OUT PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecNt32PeCoffUnloadimage (\r
+  IN EFI_PEI_PE_COFF_LOADER_PROTOCOL      *This,\r
+  IN PE_COFF_LOADER_IMAGE_CONTEXT         *ImageContext\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+SecTemporaryRamSupport (\r
+  IN CONST EFI_PEI_SERVICES   **PeiServices,\r
+  IN EFI_PHYSICAL_ADDRESS     TemporaryMemoryBase,\r
+  IN EFI_PHYSICAL_ADDRESS     PermanentMemoryBase,\r
+  IN UINTN                    CopySize\r
+  );\r
+\r
+typedef struct {\r
+  EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff;\r
+  VOID                            *ModHandle;\r
+} EFI_PEI_PE_COFF_LOADER_PROTOCOL_INSTANCE;\r
+\r
+extern EFI_UNIX_THUNK_PROTOCOL  *gUnix;\r
diff --git a/UnixPkg/Sec/SecMain.inf b/UnixPkg/Sec/SecMain.inf
new file mode 100644 (file)
index 0000000..37152b0
--- /dev/null
@@ -0,0 +1,76 @@
+#/** @file\r
+# Entry Point of Unix Emulator\r
+#\r
+# Main executable file of Unix Emulator that loads PEI core after initialization finished.\r
+# Copyright (c) 2008, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = SecMain\r
+  FILE_GUID                      = f43be88c-8985-11db-8f78-0040d02b1835\r
+  MODULE_TYPE                    = SEC\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+  ENTRY_POINT                    = main\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  UgaX11.c\r
+  UnixThunk.c\r
+  FwVol.c\r
+  SecMain.c\r
+  Stack.S\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  DebugLib\r
+  PcdLib\r
+  PrintLib\r
+  BaseMemoryLib\r
+  BaseLib\r
+  PeCoffLib\r
+  ReportStatusCodeLib\r
+\r
+\r
+[Guids]\r
+  gEfiPeiPeCoffLoaderGuid                       # ALWAYS_PRODUCED\r
+\r
+\r
+[Ppis]\r
+  gUnixPeiLoadFilePpiGuid                       # PPI ALWAYS_PRODUCED\r
+  gEfiPeiStatusCodePpiGuid                      # PPI ALWAYS_PRODUCED\r
+  gUnixFwhPpiGuid                               # PPI ALWAYS_PRODUCED\r
+  gPeiUnixAutoScanPpiGuid                       # PPI ALWAYS_PRODUCED\r
+  gPeiUnixThunkPpiGuid                          # PPI ALWAYS_PRODUCED\r
+  gEfiTemporaryRamSupportPpiGuid\r
+\r
+\r
+[Pcd.common]\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixBootMode\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareVolume\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySizeForSecMain\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize\r
+\r
+[BuildOptions.common]\r
+  GCC:*_*_IA32_DLINK_FLAGS =\r
diff --git a/UnixPkg/Sec/SecMain.msa b/UnixPkg/Sec/SecMain.msa
new file mode 100644 (file)
index 0000000..2629982
--- /dev/null
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>SecMain</ModuleName>\r
+    <ModuleType>SEC</ModuleType>\r
+    <GuidValue>f43be88c-8985-11db-8f78-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Entry Point of Unix Emulator</Abstract>\r
+    <Description>Main executable file of Unix Emulator that loads PEI core after initialization finished.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>SecMain</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeCoffLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PrintLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename ToolCode="DUMMY">SecMain_build.xml</Filename>\r
+    <Filename>SecMain.c</Filename>\r
+    <Filename>FwVol.c</Filename>\r
+    <Filename>UnixThunk.c</Filename>\r
+    <Filename>UgaX11.c</Filename>\r
+    <Filename>SecMain.h</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gPeiUnixThunkPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gPeiUnixAutoScanPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gUnixFwhPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gEfiPeiStatusCodePpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gUnixPeiLoadFilePpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_PRODUCED">\r
+      <GuidCName>gEfiPeiPeCoffLoaderGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixMemorySizeForSecMain</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines the memory size of simulated machine. Simulator will allocate\r
+        the size of PcdUnixMemorySizeForSecMain in host platform.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixFirmwareVolume</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines the FD file windows path string. Simulator will load the FD file and execute.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixBootMode</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines the boot mode for simualtor. \r
+        The boot mode can be set as following value:\r
+          0x0: Boot with full configuration.\r
+          0x1: Boot with minimal configuration.\r
+          0x2: Boot assume no configuration changes.\r
+          0x3: Boot with full configuration plus diagnostics.\r
+          0x4: Boot with default settings.\r
+          0x5: Boot on S4 resume.\r
+          0x6: Boot on S5 resume.\r
+          0x10: Boot on S2 resume. \r
+          0x11: Boot on S3 resume.\r
+          0x12: Boot on flash update.\r
+          0x20: Boot in reovery mode.</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>\r
diff --git a/UnixPkg/Sec/Stack.S b/UnixPkg/Sec/Stack.S
new file mode 100644 (file)
index 0000000..50f07b0
--- /dev/null
@@ -0,0 +1,92 @@
+#------------------------------------------------------------------------------\r
+#\r
+# Copyright (c) 2008, 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
+#\r
+#   Stack.asm\r
+#\r
+# Abstract:\r
+#\r
+#   Switch the stack from temporary memory to permenent memory.\r
+#\r
+#------------------------------------------------------------------------------\r
+\r
+#------------------------------------------------------------------------------\r
+# VOID\r
+# EFIAPI\r
+# SecSwitchStack (\r
+#   UINT32   TemporaryMemoryBase,\r
+#   UINT32   PermenentMemoryBase\r
+#   );\r
+#------------------------------------------------------------------------------    \r
+\r
+#include <ProcessorBind.h>\r
+\r
+.globl ASM_PFX(SecSwitchStack)\r
+ASM_PFX(SecSwitchStack):\r
+#\r
+# Save three register: eax, ebx, ecx\r
+#    \r
+    push  %eax\r
+    push  %ebx\r
+    push  %ecx\r
+    push  %edx\r
+    \r
+#\r
+# !!CAUTION!! this function address's is pushed into stack after\r
+# migration of whole temporary memory, so need save it to permenent\r
+# memory at first!\r
+#    \r
+    \r
+    movl  20(%esp), %ebx            # Save the first parameter\r
+    movl  24(%esp), %ecx            # Save the second parameter\r
+    \r
+#\r
+# Save this function's return address into permenent memory at first.\r
+# Then, Fixup the esp point to permenent memory\r
+#\r
+\r
+    movl  %esp, %eax\r
+    subl  %ebx, %eax\r
+    addl  %ecx, %eax\r
+    movl  (%esp), %edx                 # copy pushed register's value to permenent memory\r
+    movl  %edx, (%eax)\r
+    movl  4(%esp), %edx\r
+    movl  %edx, 4(%eax)\r
+    movl  8(%esp), %edx\r
+    movl  %edx, 8(%eax)\r
+    movl  12(%esp), %edx\r
+    movl  %edx, 12(%eax)\r
+    movl  16(%esp), %edx\r
+    movl  %edx, 16(%eax)\r
+    movl  %eax, %esp                   # From now, esp is pointed to permenent memory\r
+\r
+#\r
+# Fixup the ebp point to permenent memory\r
+#\r
+    movl   %ebp, %eax\r
+    subl   %ebx, %eax\r
+    addl   %ecx, %eax\r
+    movl   %eax, %ebp                  # From now, ebp is pointed to permenent memory\r
+    \r
+#\r
+# Fixup callee's ebp point for PeiDispatch\r
+#    \r
+    movl   (%ebp), %eax\r
+    subl   %ebx, %eax\r
+    addl   %ecx, %eax\r
+    movl   %eax, (%ebp)                # From now, Temporary's PPI caller's stack is in permenent memory\r
+    \r
+    pop   %edx\r
+    pop   %ecx\r
+    pop   %ebx\r
+    pop   %eax\r
+    ret\r
diff --git a/UnixPkg/Sec/UgaX11.c b/UnixPkg/Sec/UgaX11.c
new file mode 100644 (file)
index 0000000..b096dc6
--- /dev/null
@@ -0,0 +1,595 @@
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/dir.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "PiPei.h"
+#include "Protocol/UnixThunk.h"
+#include "Protocol/SimpleTextIn.h"
+#include "Protocol/UgaDraw.h"
+#include "Protocol/UnixUgaIo.h"
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#include <X11/extensions/XShm.h>
+#include <X11/keysym.h>
+
+#include <Guid/PeiPeCoffLoader.h>
+#include <Ppi/StatusCode.h>
+
+#include <Library/PeCoffLib.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PrintLib.h>
+#include <Library/PcdLib.h>
+#include <Library/DebugLib.h>
+
+extern void msSleep (unsigned long Milliseconds);
+
+/* XQueryPointer  */
+
+struct uga_drv_shift_mask
+{
+  unsigned char shift;
+  unsigned char size;
+  unsigned char csize;
+};
+
+#define NBR_KEYS 32
+typedef struct
+{
+  EFI_UNIX_UGA_IO_PROTOCOL UgaIo;
+
+  Display *display;
+  int screen;                  /* values for window_size in main */
+  Window win;
+  GC gc;
+  Visual *visual;
+
+  int depth;
+  unsigned int width;
+  unsigned int height;
+  unsigned int line_bytes;
+  unsigned int pixel_shift;
+  unsigned char *image_data;
+
+  struct uga_drv_shift_mask r, g, b;
+
+  int use_shm;
+  XShmSegmentInfo xshm_info;
+  XImage *image;
+
+  unsigned int key_rd;
+  unsigned int key_wr;
+  unsigned int key_count;
+  EFI_INPUT_KEY keys[NBR_KEYS];
+} UGA_IO_PRIVATE;
+
+static void
+HandleEvents(UGA_IO_PRIVATE *drv);
+
+static void
+fill_shift_mask (struct uga_drv_shift_mask *sm, unsigned long mask)
+{
+  sm->shift = 0;
+  sm->size = 0;
+  while ((mask & 1) == 0)
+    {
+      mask >>= 1;
+      sm->shift++;
+    }
+  while (mask & 1)
+    {
+      sm->size++;
+      mask >>= 1;
+    }
+  sm->csize = 8 - sm->size;
+}
+
+static int
+TryCreateShmImage(UGA_IO_PRIVATE *drv)
+{
+  drv->image = XShmCreateImage (drv->display, drv->visual,
+                               drv->depth, ZPixmap, NULL, &drv->xshm_info,
+                               drv->width, drv->height);
+  if (drv->image == NULL)
+    return 0;
+
+  switch (drv->image->bitmap_unit) {
+  case 32:
+    drv->pixel_shift = 2;
+    break;
+  case 16:
+    drv->pixel_shift = 1;
+    break;
+  case 8:
+    drv->pixel_shift = 0;
+    break;
+  }
+
+  drv->xshm_info.shmid = shmget
+       (IPC_PRIVATE, drv->image->bytes_per_line * drv->image->height,
+        IPC_CREAT | 0777);
+  if (drv->xshm_info.shmid < 0)
+    {
+      XDestroyImage(drv->image);
+      return 0;
+    }
+      
+  drv->image_data = shmat (drv->xshm_info.shmid, NULL, 0);
+  if(!drv->image_data)
+    {
+      shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
+      XDestroyImage(drv->image);
+      return 0;
+    }
+  /* Can this fail ?  */
+  shmctl (drv->xshm_info.shmid, IPC_RMID, NULL);
+
+  drv->xshm_info.shmaddr = (char*)drv->image_data;
+  drv->image->data = (char*)drv->image_data;
+         
+  if (!XShmAttach (drv->display, &drv->xshm_info))
+    {
+      shmdt (drv->image_data);
+      XDestroyImage(drv->image);
+      return 0;
+    }
+  return 1;
+}
+
+static
+EFI_STATUS
+UgaClose (EFI_UNIX_UGA_IO_PROTOCOL *UgaIo)
+{
+  UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo;
+
+  if (drv == NULL)
+    return EFI_SUCCESS;
+  if (drv->image != NULL)
+    {
+      XDestroyImage(drv->image);
+
+      if (drv->use_shm)
+       shmdt (drv->image_data);
+
+      drv->image_data = NULL;
+      drv->image = NULL;
+    }
+  XDestroyWindow(drv->display, drv->win);
+  XCloseDisplay(drv->display);
+  free(drv);
+  return EFI_SUCCESS;
+}
+
+static
+EFI_STATUS
+UgaSize(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, UINT32 Width, UINT32 Height)
+{
+  UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo;
+  XSizeHints size_hints;
+
+  /* Destroy current buffer if created.  */
+  if (drv->image != NULL)
+    {
+      XDestroyImage(drv->image);
+
+      if (drv->use_shm)
+       shmdt (drv->image_data);
+
+      drv->image_data = NULL;
+      drv->image = NULL;
+    }
+
+  drv->width = Width;
+  drv->height = Height;
+  XResizeWindow (drv->display, drv->win, Width, Height);
+
+  /* Allocate image.  */
+  if (XShmQueryExtension(drv->display) && TryCreateShmImage(drv))
+    {
+      drv->use_shm = 1;
+    }  
+  else 
+    {
+      drv->use_shm = 0;
+      if (drv->depth > 16)
+       drv->pixel_shift = 2;
+      else if (drv->depth > 8)
+       drv->pixel_shift = 1;
+      else
+       drv->pixel_shift = 0;
+      
+      drv->image_data = malloc((drv->width * drv->height) << drv->pixel_shift);
+      drv->image = XCreateImage (drv->display, drv->visual, drv->depth,
+                                ZPixmap, 0, (char *)drv->image_data,
+                                drv->width, drv->height,
+                                8 << drv->pixel_shift, 0);
+    }
+  drv->line_bytes = drv->image->bytes_per_line;
+  fill_shift_mask (&drv->r, drv->image->red_mask);
+  fill_shift_mask (&drv->g, drv->image->green_mask);
+  fill_shift_mask (&drv->b, drv->image->blue_mask);
+
+  /* Set WM hints.  */
+  size_hints.flags = PSize | PMinSize | PMaxSize;
+  size_hints.min_width = size_hints.max_width = size_hints.base_width = Width;
+  size_hints.min_height = size_hints.max_height = size_hints.base_height = Height;
+  XSetWMNormalHints (drv->display, drv->win, &size_hints);
+
+  XMapWindow (drv->display, drv->win);
+  HandleEvents(drv);
+  return EFI_SUCCESS;
+}
+
+static void
+handleKeyEvent(UGA_IO_PRIVATE *drv, XEvent *ev)
+{
+  KeySym keysym;
+  char str[4];
+  EFI_INPUT_KEY Key;
+  int res;
+
+  if (drv->key_count == NBR_KEYS)
+    return;
+
+  res = XLookupString(&ev->xkey, str, sizeof(str), &keysym, NULL);
+  Key.ScanCode = 0;\r
+  Key.UnicodeChar = 0;
+  switch (keysym) {\r
+  case XK_Home:       Key.ScanCode = SCAN_HOME;       break;\r
+  case XK_End:        Key.ScanCode = SCAN_END;        break;\r
+  case XK_Left:       Key.ScanCode = SCAN_LEFT;       break;\r
+  case XK_Right:      Key.ScanCode = SCAN_RIGHT;      break;\r
+  case XK_Up:         Key.ScanCode = SCAN_UP;         break;\r
+  case XK_Down:       Key.ScanCode = SCAN_DOWN;       break;\r
+  case XK_Delete:     Key.ScanCode = SCAN_DELETE;     break;\r
+  case XK_Insert:     Key.ScanCode = SCAN_INSERT;     break;\r
+  case XK_Page_Up:    Key.ScanCode = SCAN_PAGE_UP;    break;\r
+  case XK_Page_Down:  Key.ScanCode = SCAN_PAGE_DOWN;  break;\r
+  case XK_Escape:     Key.ScanCode = SCAN_ESC;        break;\r
+\r
+  case XK_F1:   Key.ScanCode = SCAN_F1;   break;\r
+  case XK_F2:   Key.ScanCode = SCAN_F2;   break;\r
+  case XK_F3:   Key.ScanCode = SCAN_F3;   break;\r
+  case XK_F4:   Key.ScanCode = SCAN_F4;   break;\r
+  case XK_F5:   Key.ScanCode = SCAN_F5;   break;\r
+  case XK_F6:   Key.ScanCode = SCAN_F6;   break;\r
+  case XK_F7:   Key.ScanCode = SCAN_F7;   break;\r
+  case XK_F8:   Key.ScanCode = SCAN_F8;   break;\r
+  case XK_F9:   Key.ScanCode = SCAN_F9;   break;\r
+
+  default:
+    if (res == 1) {
+      Key.UnicodeChar = str[0];
+    } else {
+      return;
+    }
+  }\r
+\r
+  drv->keys[drv->key_wr] = Key;
+  drv->key_wr = (drv->key_wr + 1) % NBR_KEYS;
+  drv->key_count++;
+}
+
+static void
+Redraw(UGA_IO_PRIVATE *drv, UINTN X, UINTN Y, UINTN Width, UINTN Height)
+{
+  if (drv->use_shm)
+    XShmPutImage (drv->display, drv->win, drv->gc, drv->image,
+                 X, Y, X, Y, Width, Height, False);
+  else
+    XPutImage (drv->display, drv->win, drv->gc, drv->image,
+                 X, Y, X, Y, Width, Height);
+}
+
+static void
+HandleEvent(UGA_IO_PRIVATE *drv, XEvent *ev)
+{
+  switch (ev->type)
+    {
+    case Expose:
+      Redraw(drv, ev->xexpose.x, ev->xexpose.y,
+            ev->xexpose.width, ev->xexpose.height);
+      break;
+    case GraphicsExpose:
+      Redraw(drv, ev->xgraphicsexpose.x, ev->xgraphicsexpose.y,
+            ev->xgraphicsexpose.width, ev->xgraphicsexpose.height);
+      break;
+    case KeyPress:
+      handleKeyEvent(drv, ev);
+      break;
+    case MappingNotify:
+      XRefreshKeyboardMapping(&ev->xmapping);
+      break;
+#if 0
+    case DestroyNotify:
+      XCloseDisplay (drv->display);
+      exit (1);
+      break;
+#endif
+    case NoExpose:
+    default:
+      break;
+    }
+}
+
+static void
+HandleEvents(UGA_IO_PRIVATE *drv)
+{
+  while (XPending(drv->display) != 0)
+    {
+      XEvent ev;
+         
+      XNextEvent (drv->display, &ev);
+      HandleEvent(drv, &ev);
+    }
+}
+
+static
+unsigned long
+UgaPixelToColor (UGA_IO_PRIVATE *drv, EFI_UGA_PIXEL pixel)
+{
+  return ((pixel.Red >> drv->r.csize) << drv->r.shift)
+    | ((pixel.Green >> drv->g.csize) << drv->g.shift)
+    | ((pixel.Blue >> drv->b.csize) << drv->b.shift);
+}
+
+static
+EFI_UGA_PIXEL
+UgaColorToPixel (UGA_IO_PRIVATE *drv, unsigned long val)
+{
+  EFI_UGA_PIXEL res;
+
+  memset (&res, 0, sizeof (EFI_UGA_PIXEL));
+  /* FIXME: should round instead of truncate.  */
+  res.Red = (val >> drv->r.shift) << drv->r.csize;
+  res.Green = (val >> drv->g.shift) << drv->g.csize;
+  res.Blue = (val >> drv->b.shift) << drv->b.csize;
+
+  return res;
+}
+
+static
+EFI_STATUS
+UgaCheckKey(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo)
+{
+  UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo;
+  HandleEvents(drv);
+  if (drv->key_count != 0)
+    return EFI_SUCCESS;
+  else {
+    /* EFI is certainly polling.  Be CPU-friendly.  */
+    msSleep (20);
+    return EFI_NOT_READY;
+  }
+}
+
+static
+EFI_STATUS
+UgaGetKey(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo, EFI_INPUT_KEY *key)
+{
+  UGA_IO_PRIVATE *drv = (UGA_IO_PRIVATE *)UgaIo;
+  EFI_STATUS status;
+
+  status = UgaCheckKey(UgaIo);
+  if (status != EFI_SUCCESS)
+    return status;
+
+  *key = drv->keys[drv->key_rd];
+  drv->key_rd = (drv->key_rd + 1) % NBR_KEYS;
+  drv->key_count--;
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS\r
+UgaBlt(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
+       IN  EFI_UGA_PIXEL                           *BltBuffer OPTIONAL,\r
+       IN  EFI_UGA_BLT_OPERATION                   BltOperation,\r
+       IN  UINTN                                   SourceX,\r
+       IN  UINTN                                   SourceY,\r
+       IN  UINTN                                   DestinationX,\r
+       IN  UINTN                                   DestinationY,\r
+       IN  UINTN                                   Width,\r
+       IN  UINTN                                   Height,\r
+       IN  UINTN                                   Delta OPTIONAL\r
+  )\r
+{
+  UGA_IO_PRIVATE *Private = (UGA_IO_PRIVATE *)UgaIo;
+  UINTN             DstY;\r
+  UINTN             SrcY;\r
+  UINTN             DstX;
+  UINTN             SrcX;
+  UINTN             Index;
+  EFI_UGA_PIXEL     *Blt;\r
+  UINT8             *Dst;
+  UINT8             *Src;
+  UINTN             Nbr;
+  unsigned long     Color;
+
+  //
+  //  Check bounds
+  //
+  if (BltOperation == EfiUgaVideoToBltBuffer
+      || BltOperation == EfiUgaVideoToVideo) {\r
+    //\r
+    // Source is Video.
+    //\r
+    if (SourceY + Height > Private->height) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if (SourceX + Width > Private->width) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }
+
+  if (BltOperation == EfiUgaBltBufferToVideo
+      || BltOperation == EfiUgaVideoToVideo
+      || BltOperation == EfiUgaVideoFill) {\r
+    //\r
+    // Destination is Video\r
+    //\r
+    if (DestinationY + Height > Private->height) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if (DestinationX + Width > Private->width) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }
+
+  switch (BltOperation) {\r
+  case EfiUgaVideoToBltBuffer:
+    Blt = BltBuffer;
+    Delta -= Width * sizeof (EFI_UGA_PIXEL);
+    for (SrcY = SourceY; SrcY < (Height + SourceY); SrcY++) {\r
+      for (SrcX = SourceX; SrcX < (Width + SourceX); SrcX++) {
+       *Blt++ = UgaColorToPixel(Private,
+                                XGetPixel(Private->image, SrcX, SrcY));
+      }
+      Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Delta);
+    }\r
+    break;
+  case EfiUgaBltBufferToVideo:\r
+    Blt = BltBuffer;
+    Delta -= Width * sizeof (EFI_UGA_PIXEL);
+    for (DstY = DestinationY; DstY < (Height + DestinationY); DstY++) {\r
+      for (DstX = DestinationX; DstX < (Width + DestinationX); DstX++) {\r
+       XPutPixel(Private->image, DstX, DstY, UgaPixelToColor(Private, *Blt));
+       Blt++;
+      }
+      Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Delta);
+    }
+    break;
+  case EfiUgaVideoToVideo:\r
+    Dst = Private->image_data + (DestinationX << Private->pixel_shift)
+      + DestinationY * Private->line_bytes;
+    Src = Private->image_data + (SourceX << Private->pixel_shift)
+      + SourceY * Private->line_bytes;
+    Nbr = Width << Private->pixel_shift;
+    if (DestinationY < SourceY) {\r
+      for (Index = 0; Index < Height; Index++) {
+       memcpy (Dst, Src, Nbr);
+       Dst += Private->line_bytes;
+       Src += Private->line_bytes;
+      }
+    }
+    else {
+      Dst += (Height - 1) * Private->line_bytes;
+      Src += (Height - 1) * Private->line_bytes;
+      for (Index = 0; Index < Height; Index++) {
+       //
+       // Source and Destination Y may be equal, therefore Dst and Src may
+       // overlap.
+       //
+       memmove (Dst, Src, Nbr);
+       Dst -= Private->line_bytes;
+       Src -= Private->line_bytes;
+      }
+    }
+    break;
+  case EfiUgaVideoFill:
+    Color = UgaPixelToColor(Private, *BltBuffer);
+    for (DstY = DestinationY; DstY < (Height + DestinationY); DstY++) {\r
+      for (DstX = DestinationX; DstX < (Width + DestinationX); DstX++) {
+       XPutPixel(Private->image, DstX, DstY, Color);
+      }
+    }\r
+    break;
+  default:
+      return EFI_INVALID_PARAMETER;\r
+  }
+
+  //
+  //  Refresh screen.
+  //
+  switch (BltOperation) {\r
+  case EfiUgaVideoToVideo:\r
+    XCopyArea(Private->display, Private->win, Private->win, Private->gc,
+             SourceX, SourceY, Width, Height, DestinationX, DestinationY);
+    while (1) {
+      XEvent ev;
+         
+      XNextEvent (Private->display, &ev);
+      HandleEvent(Private, &ev);
+      if (ev.type == NoExpose || ev.type == GraphicsExpose)
+       break;
+    }
+    break;
+  case EfiUgaVideoFill:
+    Color = UgaPixelToColor(Private, *BltBuffer);
+    XSetForeground(Private->display, Private->gc, Color);
+    XFillRectangle(Private->display, Private->win, Private->gc,
+                  DestinationX, DestinationY, Width, Height);
+    break;
+  case EfiUgaBltBufferToVideo:\r
+    Redraw(Private, DestinationX, DestinationY, Width, Height);
+    break;
+  default:
+    break;
+  }
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+UgaCreate (EFI_UNIX_UGA_IO_PROTOCOL **Uga, CONST CHAR16 *Title)
+{
+  UGA_IO_PRIVATE *drv;
+  unsigned int border_width = 0;
+  char *display_name = NULL;
+  int title_len;
+
+  drv = (UGA_IO_PRIVATE *)
+    calloc (1, sizeof (UGA_IO_PRIVATE));
+  if (drv == NULL)
+    return EFI_OUT_OF_RESOURCES;
+
+  drv->UgaIo.UgaClose = UgaClose;
+  drv->UgaIo.UgaSize = UgaSize;
+  drv->UgaIo.UgaCheckKey = UgaCheckKey;
+  drv->UgaIo.UgaGetKey = UgaGetKey;
+  drv->UgaIo.UgaBlt = UgaBlt;
+
+  drv->key_count = 0;
+  drv->key_rd = 0;
+  drv->key_wr = 0;
+  drv->display = XOpenDisplay (display_name);
+  if (drv->display == NULL)
+    {
+      fprintf (stderr, "uga: cannot connect to X server %s\n",
+              XDisplayName (display_name));
+      free (drv);
+      return EFI_DEVICE_ERROR;
+    }
+  drv->screen = DefaultScreen (drv->display);
+  drv->visual = DefaultVisual (drv->display, drv->screen);
+  drv->win = XCreateSimpleWindow
+       (drv->display, RootWindow (drv->display, drv->screen),
+        0, 0, 4, 4, border_width,
+        BlackPixel (drv->display, drv->screen),
+        WhitePixel (drv->display, drv->screen));
+
+  drv->depth = DefaultDepth (drv->display, drv->screen);
+
+  /* Compute title len and convert to Ascii.  */
+  for (title_len = 0; Title[title_len] != 0; title_len++)
+    ;
+  {
+    char title[title_len + 1];
+    int i;
+    for (i = 0; i < title_len; i++)
+      title[i] = Title[i];
+    title[i] = 0;
+    
+    XStoreName (drv->display, drv->win, title);
+  }
+
+  XSelectInput (drv->display, drv->win,
+               ExposureMask | KeyPressMask);
+  drv->gc = DefaultGC (drv->display, drv->screen);
+
+  *Uga = (EFI_UNIX_UGA_IO_PROTOCOL *)drv;
+  return EFI_SUCCESS;
+}
diff --git a/UnixPkg/Sec/UnixThunk.c b/UnixPkg/Sec/UnixThunk.c
new file mode 100644 (file)
index 0000000..500568a
--- /dev/null
@@ -0,0 +1,197 @@
+/*++
+
+Copyright (c) 2004 - 2006, Intel Corporation                                                         
+All rights reserved. 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        
+http://opensource.org/licenses/bsd-license.php                                            
+                                                                                          
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+
+Module Name:
+
+  UnixThunk.c
+
+Abstract:
+
+  Since the SEC is the only program in our emulation we 
+  must use a Tiano mechanism to export APIs to other modules.
+  This is the role of the EFI_UNIX_THUNK_PROTOCOL.
+
+  The mUnixThunkTable exists so that a change to EFI_UNIX_THUNK_PROTOCOL
+  will cause an error in initializing the array if all the member functions
+  are not added. It looks like adding a element to end and not initializing
+  it may cause the table to be initaliized with the members at the end being
+  set to zero. This is bad as jumping to zero will crash.
+  
+
+  gUnix is a a public exported global that contains the initialized
+  data.
+
+--*/
+
+#include "SecMain.h"
+#include "Library/UnixLib.h"
+
+static int settimer_initialized;
+static struct timeval settimer_timeval;
+static void (*settimer_callback)(UINT64 delta);
+
+static void
+settimer_handler (int sig)
+{
+  struct timeval timeval;
+  UINT64 delta;
+
+  gettimeofday (&timeval, NULL);
+  delta = ((UINT64)timeval.tv_sec * 1000) + (timeval.tv_usec / 1000)
+    - ((UINT64)settimer_timeval.tv_sec * 1000) 
+    - (settimer_timeval.tv_usec / 1000);
+  settimer_timeval = timeval;
+  if (settimer_callback)
+    (*settimer_callback)(delta);
+}
+
+static
+VOID
+SetTimer (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs))
+{
+  struct itimerval timerval;
+
+  if (!settimer_initialized) {
+    struct sigaction act;
+
+    settimer_initialized = 1;
+    act.sa_handler = settimer_handler;
+    act.sa_flags = 0;
+    sigemptyset (&act.sa_mask);
+    if (sigaction (SIGALRM, &act, NULL) != 0) {
+      printf ("SetTimer: sigaction error %s\n", strerror (errno));
+    }
+    if (gettimeofday (&settimer_timeval, NULL) != 0) {
+      printf ("SetTimer: gettimeofday error %s\n", strerror (errno));
+    }
+  }
+  timerval.it_value.tv_sec = PeriodMs / 1000;
+  timerval.it_value.tv_usec = (PeriodMs % 1000) * 1000;
+  timerval.it_value.tv_sec = PeriodMs / 1000;
+  timerval.it_interval = timerval.it_value;
+  
+  if (setitimer (ITIMER_REAL, &timerval, NULL) != 0) {
+    printf ("SetTimer: setitimer error %s\n", strerror (errno));
+  }
+  settimer_callback = CallBack;
+}
+
+void
+msSleep (unsigned long Milliseconds)
+{
+  struct timespec ts;
+
+  ts.tv_sec = Milliseconds / 1000;
+  ts.tv_nsec = (Milliseconds % 1000) * 1000000;
+
+  while (nanosleep (&ts, &ts) != 0 && errno == EINTR)
+    ;
+}
+
+void
+GetLocalTime (EFI_TIME *Time)
+{
+  struct tm *tm;
+  time_t t;
+
+  t = time (NULL);
+  tm = localtime (&t);
+
+  Time->Year = 1900 + tm->tm_year;
+  Time->Month = tm->tm_mon;
+  Time->Day = tm->tm_mday;
+  Time->Hour = tm->tm_hour;
+  Time->Minute = tm->tm_min;
+  Time->Second = tm->tm_sec;
+  Time->Nanosecond = 0;
+  Time->TimeZone = timezone;
+  Time->Daylight = (daylight ? EFI_TIME_ADJUST_DAYLIGHT : 0)
+    | (tm->tm_isdst > 0 ? EFI_TIME_IN_DAYLIGHT : 0);
+}
+
+static void
+TzSet (void)
+{
+  static int done = 0;
+  if (!done) {
+    tzset ();
+    done = 1;
+  }
+}
+
+long
+GetTimeZone(void)
+{
+  TzSet ();
+  return timezone;
+}
+
+int
+GetDayLight(void)
+{
+  TzSet ();
+  return daylight;
+}
+
+int
+GetErrno(void)
+{
+  return errno;
+}
+
+extern EFI_STATUS
+UgaCreate(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, CONST CHAR16 *Title);
+
+EFI_UNIX_THUNK_PROTOCOL mUnixThunkTable = {
+  EFI_UNIX_THUNK_PROTOCOL_SIGNATURE,
+  msSleep, /* Sleep */
+  exit, /* Exit */
+  SetTimer,
+  GetLocalTime,
+  gmtime,
+  GetTimeZone,
+  GetDayLight,
+  (UnixPoll)poll,
+  (UnixRead)read,
+  (UnixWrite)write,
+  getenv,
+  (UnixOpen)open,
+  lseek,
+  ftruncate,
+  close,
+  mkdir,
+  rmdir,
+  unlink,
+  GetErrno,
+  opendir,
+  rewinddir,
+  readdir,
+  closedir,
+  stat,
+  statfs,
+  rename,
+  mktime,
+  fsync,
+  chmod,
+  utime,
+  tcflush,
+  UgaCreate,
+  perror,
+  ioctl,
+  fcntl,
+  cfsetispeed,
+  cfsetospeed,
+  tcgetattr,
+  tcsetattr
+};
+
+
+EFI_UNIX_THUNK_PROTOCOL *gUnix = &mUnixThunkTable;
diff --git a/UnixPkg/TimerDxe/Timer.c b/UnixPkg/TimerDxe/Timer.c
new file mode 100644 (file)
index 0000000..53b5656
--- /dev/null
@@ -0,0 +1,374 @@
+/*++\r
+\r
+Copyright (c) 2004, 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
+\r
+  Timer.c\r
+\r
+Abstract:\r
+\r
+  UNIX Emulation Timer Architectural Protocol Driver as defined in DXE CIS\r
+\r
+  This Timer module uses an UNIX Thread to simulate the timer-tick driven\r
+  timer service.  In the future, the Thread creation should possibly be \r
+  abstracted by the CPU architectural protocol\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include <Protocol/Timer.h>\r
+#include <Protocol/Cpu.h>\r
+#include "Timer.h"\r
+#include <Library/BaseLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include "UnixDxe.h"\r
+#include <Library/UnixLib.h>\r
+\r
+//\r
+// Pointer to the CPU Architectural Protocol instance\r
+//\r
+EFI_CPU_ARCH_PROTOCOL   *mCpu;\r
+\r
+//\r
+// The Timer Architectural Protocol that this driver produces\r
+//\r
+EFI_TIMER_ARCH_PROTOCOL mTimer = {\r
+  UnixTimerDriverRegisterHandler,\r
+  UnixTimerDriverSetTimerPeriod,\r
+  UnixTimerDriverGetTimerPeriod,\r
+  UnixTimerDriverGenerateSoftInterrupt\r
+};\r
+\r
+//\r
+// The notification function to call on every timer interrupt\r
+//\r
+EFI_TIMER_NOTIFY        mTimerNotifyFunction = NULL;\r
+\r
+//\r
+// The current period of the timer interrupt\r
+//\r
+UINT64                  mTimerPeriodMs;\r
+\r
+\r
+VOID\r
+TimerCallback (UINT64 DeltaMs)
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  wTimerID  - TODO: add argument description\r
+  msg       - TODO: add argument description\r
+  dwUser    - TODO: add argument description\r
+  dw1       - TODO: add argument description\r
+  dw2       - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_TPL           OriginalTPL;\r
+  EFI_TIMER_NOTIFY  CallbackFunction;
+
+\r
+  OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+\r
+  if (OriginalTPL < TPL_HIGH_LEVEL) {
+    CallbackFunction = mTimerNotifyFunction;\r
+\r
+    //\r
+    // Only invoke the callback function if a Non-NULL handler has been\r
+    // registered. Assume all other handlers are legal.\r
+    //\r
+    if (CallbackFunction != NULL) {\r
+      CallbackFunction ((UINT64) (DeltaMs * 10000));\r
+    }\r
+  }
+\r
+  gBS->RestoreTPL (OriginalTPL);\r
+\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverRegisterHandler (\r
+  IN EFI_TIMER_ARCH_PROTOCOL           *This,\r
+  IN EFI_TIMER_NOTIFY                  NotifyFunction\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function registers the handler NotifyFunction so it is called every time \r
+  the timer interrupt fires.  It also passes the amount of time since the last \r
+  handler call to the NotifyFunction.  If NotifyFunction is NULL, then the \r
+  handler is unregistered.  If the handler is registered, then EFI_SUCCESS is \r
+  returned.  If the CPU does not support registering a timer interrupt handler, \r
+  then EFI_UNSUPPORTED is returned.  If an attempt is made to register a handler \r
+  when a handler is already registered, then EFI_ALREADY_STARTED is returned.  \r
+  If an attempt is made to unregister a handler when a handler is not registered, \r
+  then EFI_INVALID_PARAMETER is returned.  If an error occurs attempting to \r
+  register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR \r
+  is returned.\r
+\r
+Arguments:\r
+\r
+  This           - The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  NotifyFunction - The function to call when a timer interrupt fires.  This \r
+                   function executes at TPL_HIGH_LEVEL.  The DXE Core will \r
+                   register a handler for the timer interrupt, so it can know \r
+                   how much time has passed.  This information is used to \r
+                   signal timer based events.  NULL will unregister the handler.\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS           - The timer handler was registered.\r
+\r
+  EFI_UNSUPPORTED       - The platform does not support timer interrupts.\r
+\r
+  EFI_ALREADY_STARTED   - NotifyFunction is not NULL, and a handler is already \r
+                          registered.\r
+\r
+  EFI_INVALID_PARAMETER - NotifyFunction is NULL, and a handler was not \r
+                          previously registered.\r
+\r
+  EFI_DEVICE_ERROR      - The timer handler could not be registered.\r
+\r
+--*/\r
+{\r
+  //\r
+  // Check for invalid parameters\r
+  //\r
+  if (NotifyFunction == NULL && mTimerNotifyFunction == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (NotifyFunction != NULL && mTimerNotifyFunction != NULL) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  if (NotifyFunction == NULL) {
+    /* Disable timer.  */
+    gUnix->SetTimer (0, TimerCallback);
+  } else if (mTimerNotifyFunction == NULL) {
+    /* Enable Timer.  */
+    gUnix->SetTimer (mTimerPeriodMs, TimerCallback);
+  }
+  mTimerNotifyFunction = NotifyFunction;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverSetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN UINT64                   TimerPeriod\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function adjusts the period of timer interrupts to the value specified \r
+  by TimerPeriod.  If the timer period is updated, then the selected timer \r
+  period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned.  If \r
+  the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.  \r
+  If an error occurs while attempting to update the timer period, then the \r
+  timer hardware will be put back in its state prior to this call, and \r
+  EFI_DEVICE_ERROR is returned.  If TimerPeriod is 0, then the timer interrupt \r
+  is disabled.  This is not the same as disabling the CPU's interrupts.  \r
+  Instead, it must either turn off the timer hardware, or it must adjust the \r
+  interrupt controller so that a CPU interrupt is not generated when the timer \r
+  interrupt fires. \r
+\r
+Arguments:\r
+\r
+  This        - The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  TimerPeriod - The rate to program the timer interrupt in 100 nS units.  If \r
+                the timer hardware is not programmable, then EFI_UNSUPPORTED is \r
+                returned.  If the timer is programmable, then the timer period \r
+                will be rounded up to the nearest timer period that is supported \r
+                by the timer hardware.  If TimerPeriod is set to 0, then the \r
+                timer interrupts will be disabled.\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS      - The timer period was changed.\r
+\r
+  EFI_UNSUPPORTED  - The platform cannot change the period of the timer interrupt.\r
+\r
+  EFI_DEVICE_ERROR - The timer period could not be changed due to a device error.\r
+\r
+--*/\r
+{\r
+\r
+  //\r
+  // If TimerPeriod is 0, then the timer thread should be canceled\r
+  // If the TimerPeriod is valid, then create and/or adjust the period of the timer thread\r
+  //\r
+  if (TimerPeriod == 0
+      || ((TimerPeriod > TIMER_MINIMUM_VALUE)
+         && (TimerPeriod < TIMER_MAXIMUM_VALUE))) {\r
+    mTimerPeriodMs = DivU64x32 (TimerPeriod + 5000, 10000);\r
+
+    gUnix->SetTimer (mTimerPeriodMs, TimerCallback);
+  }
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverGetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL            *This,\r
+  OUT UINT64                            *TimerPeriod\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function retrieves the period of timer interrupts in 100 ns units, \r
+  returns that value in TimerPeriod, and returns EFI_SUCCESS.  If TimerPeriod \r
+  is NULL, then EFI_INVALID_PARAMETER is returned.  If a TimerPeriod of 0 is \r
+  returned, then the timer is currently disabled.\r
+\r
+Arguments:\r
+\r
+  This        - The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+  TimerPeriod - A pointer to the timer period to retrieve in 100 ns units.  If \r
+                0 is returned, then the timer is currently disabled.\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS           - The timer period was returned in TimerPeriod.\r
+\r
+  EFI_INVALID_PARAMETER - TimerPeriod is NULL.\r
+\r
+--*/\r
+{\r
+  if (TimerPeriod == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *TimerPeriod = mTimerPeriodMs * 10000;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverGenerateSoftInterrupt (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function generates a soft timer interrupt. If the platform does not support soft \r
+  timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned. \r
+  If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler() \r
+  service, then a soft timer interrupt will be generated. If the timer interrupt is \r
+  enabled when this service is called, then the registered handler will be invoked. The \r
+  registered handler should not be able to distinguish a hardware-generated timer \r
+  interrupt from a software-generated timer interrupt.\r
+\r
+Arguments:\r
+\r
+  This  -  The EFI_TIMER_ARCH_PROTOCOL instance.\r
+\r
+Returns: \r
+\r
+  EFI_SUCCESS       - The soft timer interrupt was generated.\r
+\r
+  EFI_UNSUPPORTEDT  - The platform does not support the generation of soft timer interrupts.\r
+\r
+--*/\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Initialize the Timer Architectural Protocol driver\r
+\r
+Arguments:\r
+\r
+  ImageHandle - ImageHandle of the loaded driver\r
+\r
+  SystemTable - Pointer to the System Table\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - Timer Architectural Protocol created\r
+\r
+  EFI_OUT_OF_RESOURCES  - Not enough resources available to initialize driver.\r
+  \r
+  EFI_DEVICE_ERROR      - A device error occured attempting to initialize the driver.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  Handle;\r
+\r
+  //\r
+  // Make sure the Timer Architectural Protocol is not already installed in the system\r
+  //\r
+  ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiTimerArchProtocolGuid);\r
+\r
+  //\r
+  // Get the CPU Architectural Protocol instance\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (void *)&mCpu);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Install the Timer Architectural Protocol onto a new handle\r
+  //\r
+  Handle = NULL;\r
+  Status = gBS->InstallProtocolInterface (\r
+                  &Handle,\r
+                  &gEfiTimerArchProtocolGuid,\r
+                  EFI_NATIVE_INTERFACE,\r
+                  &mTimer\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Start the timer thread at the default timer period\r
+  //\r
+  Status = mTimer.SetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATION);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/TimerDxe/Timer.h b/UnixPkg/TimerDxe/Timer.h
new file mode 100644 (file)
index 0000000..230fead
--- /dev/null
@@ -0,0 +1,162 @@
+/*++\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
+\r
+  Timer.h\r
+\r
+Abstract:\r
+\r
+  UNIX Emulation Architectural Protocol Driver as defined in Tiano.\r
+  This Timer module uses an UNIX Thread to simulate the timer-tick driven\r
+  timer service.\r
+\r
+--*/\r
+\r
+#ifndef _TIMER_H_\r
+#define _TIMER_H_\r
+\r
+\r
+\r
+\r
+//\r
+// Legal timer value range in 100 ns units\r
+//\r
+#define TIMER_MINIMUM_VALUE 0\r
+#define TIMER_MAXIMUM_VALUE (0x100000000ULL - 1)\r
+\r
+//\r
+// Default timer value in 100 ns units (50 ms)\r
+//\r
+#define DEFAULT_TIMER_TICK_DURATION 500000\r
+\r
+//\r
+// Function Prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverInitialize (\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ImageHandle - TODO: add argument description\r
+  SystemTable - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverRegisterHandler (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN EFI_TIMER_NOTIFY         NotifyFunction\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This            - TODO: add argument description\r
+  NotifyFunction  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverSetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This,\r
+  IN UINT64                   TimerPeriod\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  TimerPeriod - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverGetTimerPeriod (\r
+  IN EFI_TIMER_ARCH_PROTOCOL   *This,\r
+  OUT UINT64                   *TimerPeriod\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  TimerPeriod - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixTimerDriverGenerateSoftInterrupt (\r
+  IN EFI_TIMER_ARCH_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/UnixPkg/TimerDxe/Timer.inf b/UnixPkg/TimerDxe/Timer.inf
new file mode 100644 (file)
index 0000000..39ee61d
--- /dev/null
@@ -0,0 +1,63 @@
+#/** @file\r
+# Unix Emulation Timer Architectural Protocol Driver as defined in DXE CIS\r
+#\r
+# This Timer module uses an NT Thread to simulate the timer-tick driven\r
+#  timer service. In the future, the Thread creation should possibly be \r
+#  abstracted by the CPU architectural protocol\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Timer\r
+  FILE_GUID                      = f36d49b4-8985-11db-809b-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = UnixTimerDriverInitialize\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  Timer.c\r
+  Timer.h\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  UnixLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+  BaseLib\r
+\r
+\r
+[Protocols]\r
+  gEfiCpuArchProtocolGuid                       # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiTimerArchProtocolGuid                     # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  gEfiCpuArchProtocolGuid\r
+\r
diff --git a/UnixPkg/TimerDxe/Timer.msa b/UnixPkg/TimerDxe/Timer.msa
new file mode 100644 (file)
index 0000000..f240f32
--- /dev/null
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>Timer</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f36d49b4-8985-11db-809b-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Unix Emulation Timer Architectural Protocol Driver as defined in DXE CIS</Abstract>\r
+    <Description>\r
+      This Timer module uses an NT Thread to simulate the timer-tick driven\r
+      timer service.  In the future, the Thread creation should possibly be \r
+      abstracted by the CPU architectural protocol\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>Timer</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UnixLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Timer.h</Filename>\r
+    <Filename>Timer.c</Filename>\r
+    <Filename>Timer.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiTimerArchProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiCpuArchProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>UnixTimerDriverInitialize</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixAutoScanPei/UnixAutoScan.c b/UnixPkg/UnixAutoScanPei/UnixAutoScan.c
new file mode 100644 (file)
index 0000000..34f5098
--- /dev/null
@@ -0,0 +1,145 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+  UnixAutoscan.c\r
+\r
+Abstract:\r
+  This PEIM to abstract memory auto-scan in an Unix environment.\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#include "PiPei.h"\r
+#include <Ppi/UnixAutoScan.h>\r
+#include <Ppi/BaseMemoryTest.h>\r
+#include <Ppi/MemoryDiscovered.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeUnixAutoScan (\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 a memory value\r
+\r
+Arguments:\r
+  FfsHeader   - General purpose data available 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
+  PEI_UNIX_AUTOSCAN_PPI      *PeiUnixService;\r
+  UINT64                      MemorySize;\r
+  EFI_PHYSICAL_ADDRESS        MemoryBase;\r
+  PEI_BASE_MEMORY_TEST_PPI    *MemoryTestPpi;\r
+  EFI_PHYSICAL_ADDRESS        ErrorAddress;\r
+  UINTN                       Index;\r
+  EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;\r
+\r
+\r
+  DEBUG ((EFI_D_ERROR, "Unix Autoscan PEIM Loaded\n"));\r
+\r
+  //\r
+  // Get the PEI UNIX Autoscan PPI\r
+  //\r
+  Status = (**PeiServices).LocatePpi (\r
+                            PeiServices,\r
+                            &gPeiUnixAutoScanPpiGuid, // GUID\r
+                            0,                      // INSTANCE\r
+                            &PpiDescriptor,         // EFI_PEI_PPI_DESCRIPTOR\r
+                            (VOID **)&PeiUnixService           // PPI\r
+                            );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Get the Memory Test PPI\r
+  //\r
+  Status = (**PeiServices).LocatePpi (\r
+                            PeiServices,\r
+                            &gPeiBaseMemoryTestPpiGuid,\r
+                            0,\r
+                            NULL,\r
+                            (VOID **)&MemoryTestPpi\r
+                            );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Index = 0;\r
+  do {\r
+    Status = PeiUnixService->UnixAutoScan (Index, &MemoryBase, &MemorySize);\r
+    if (!EFI_ERROR (Status)) {\r
+      Attributes =\r
+        (\r
+          EFI_RESOURCE_ATTRIBUTE_PRESENT |\r
+          EFI_RESOURCE_ATTRIBUTE_INITIALIZED |\r
+          EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |\r
+          EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |\r
+          EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |\r
+          EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE\r
+        );\r
+\r
+      if (Index == 0) {\r
+        //\r
+        // For the first area register it as PEI tested memory\r
+        //\r
+        Status = MemoryTestPpi->BaseMemoryTest (\r
+                                  PeiServices,\r
+                                  MemoryTestPpi,\r
+                                  MemoryBase,\r
+                                  MemorySize,\r
+                                  Quick,\r
+                                  &ErrorAddress\r
+                                  );\r
+        ASSERT_EFI_ERROR (Status);\r
+\r
+        //\r
+        // Register the "tested" memory with the PEI Core\r
+        //\r
+        Status = (**PeiServices).InstallPeiMemory (PeiServices, MemoryBase, MemorySize);\r
+        ASSERT_EFI_ERROR (Status);\r
+\r
+        Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;\r
+      }\r
+      \r
+      BuildResourceDescriptorHob (\r
+        EFI_RESOURCE_SYSTEM_MEMORY,\r
+        Attributes,\r
+        MemoryBase,\r
+        MemorySize\r
+        );\r
+    }\r
+    Index++;\r
+  } while (!EFI_ERROR (Status));\r
+\r
+  //\r
+  // Build the CPU hob with 36-bit addressing and 16-bits of IO space.\r
+  //\r
+  BuildCpuHob (36, 16);\r
+  \r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixAutoScanPei/UnixAutoScan.inf b/UnixPkg/UnixAutoScanPei/UnixAutoScan.inf
new file mode 100644 (file)
index 0000000..2b02e41
--- /dev/null
@@ -0,0 +1,60 @@
+#/** @file\r
+# Component description file for UnixAutoScan module\r
+#\r
+# This module abstracts memory auto-scan in a Unix environment.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixAutoScan\r
+  FILE_GUID                      = f3f36cb0-8985-11db-b195-0040d02b1835\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = PeimInitializeUnixAutoScan\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  UnixAutoScan.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  HobLib\r
+  BaseMemoryLib\r
+  BaseLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Ppis]\r
+  gEfiPeiMemoryDiscoveredPpiGuid                # PPI ALWAYS_PRODUCED\r
+  gPeiBaseMemoryTestPpiGuid                     # PPI ALWAYS_CONSUMED\r
+  gPeiUnixAutoScanPpiGuid                       # PPI ALWAYS_CONSUMED\r
+\r
+\r
+[Depex]\r
+  gPeiUnixAutoScanPpiGuid AND gEfiPeiMasterBootModePpiGuid AND gPeiBaseMemoryTestPpiGuid\r
+\r
diff --git a/UnixPkg/UnixAutoScanPei/UnixAutoScan.msa b/UnixPkg/UnixAutoScanPei/UnixAutoScan.msa
new file mode 100644 (file)
index 0000000..60830b6
--- /dev/null
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <MsaHeader>
+    <ModuleName>UnixAutoScan</ModuleName>
+    <ModuleType>PEIM</ModuleType>
+    <GuidValue>f3f36cb0-8985-11db-b195-0040d02b1835</GuidValue>
+    <Version>1.0</Version>
+    <Abstract>Component description file for UnixAutoScan module</Abstract>
+    <Description>This module abstracts memory auto-scan in a Unix environment.</Description>
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>
+    <License>All rights reserved. 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
+      http://opensource.org/licenses/bsd-license.php
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>
+  </MsaHeader>
+  <ModuleDefinitions>
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
+    <BinaryModule>false</BinaryModule>
+    <OutputFileBasename>UnixAutoScan</OutputFileBasename>
+  </ModuleDefinitions>
+  <LibraryClassDefinitions>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>DebugLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>PeimEntryPoint</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>BaseLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>BaseMemoryLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>HobLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>PeiServicesLib</Keyword>
+    </LibraryClass>
+    <LibraryClass Usage="ALWAYS_CONSUMED">
+      <Keyword>PeiServicesTablePointerLib</Keyword>
+    </LibraryClass>
+  </LibraryClassDefinitions>
+  <SourceFiles>
+    <Filename>UnixAutoScan.c</Filename>
+    <Filename>UnixAutoScan.dxs</Filename>
+  </SourceFiles>
+  <PackageDependencies>
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>
+  </PackageDependencies>
+  <PPIs>
+    <Ppi Usage="ALWAYS_CONSUMED">
+      <PpiCName>gPeiUnixAutoScanPpiGuid</PpiCName>
+    </Ppi>
+    <Ppi Usage="ALWAYS_CONSUMED">
+      <PpiCName>gPeiBaseMemoryTestPpiGuid</PpiCName>
+    </Ppi>
+    <Ppi Usage="ALWAYS_PRODUCED">
+      <PpiCName>gEfiPeiMemoryDiscoveredPpiGuid</PpiCName>
+    </Ppi>
+  </PPIs>
+  <Externs>
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+    <Extern>
+      <ModuleEntryPoint>PeimInitializeUnixAutoScan</ModuleEntryPoint>
+    </Extern>
+  </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixBlockIoDxe/ComponentName.c b/UnixPkg/UnixBlockIoDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..19085fd
--- /dev/null
@@ -0,0 +1,197 @@
+/*++\r
+\r
+Copyright (c) 2004, 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
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include "UnixBlockIo.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gUnixBlockIoComponentName = {\r
+  UnixBlockIoComponentNameGetDriverName,\r
+  UnixBlockIoComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mUnixBlockIoDriverNameTable[] = {\r
+  { "eng", L"Unix Block I/O Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixBlockIoComponentName.SupportedLanguages,\r
+          mUnixBlockIoDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the \r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing \r
+                            the controller specified by ControllerHandle and \r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  UNIX_BLOCK_IO_PRIVATE *Private;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Make sure this driver is currently managing ControllerHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+             &gEfiUnixIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (void *)&BlockIo,\r
+                  gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixBlockIoComponentName.SupportedLanguages,\r
+          Private->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
diff --git a/UnixPkg/UnixBlockIoDxe/DriverConfiguration.c b/UnixPkg/UnixBlockIoDxe/DriverConfiguration.c
new file mode 100644 (file)
index 0000000..d06b5fb
--- /dev/null
@@ -0,0 +1,338 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2005, 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
+\r
+  DriverConfiguration.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include "UnixBlockIo.h"\r
+\r
+//\r
+// EFI Driver Configuration Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverConfigurationSetOptions (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  CHAR8                                                  *Language,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverConfigurationOptionsValid (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle  OPTIONAL\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverConfigurationForceDefaults (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  UINT32                                                 DefaultType,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  );\r
+\r
+//\r
+// EFI Driver Configuration Protocol\r
+//\r
+EFI_DRIVER_CONFIGURATION_PROTOCOL gUnixBlockIoDriverConfiguration = {\r
+  UnixBlockIoDriverConfigurationSetOptions,\r
+  UnixBlockIoDriverConfigurationOptionsValid,\r
+  UnixBlockIoDriverConfigurationForceDefaults,\r
+  LANGUAGESUPPORTED\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverConfigurationSetOptions (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  CHAR8                                                  *Language,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Allows the user to set controller specific options for a controller that a \r
+    driver is currently managing.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to set options on.\r
+    ChildHandle      - The handle of the child controller to set options on.  This\r
+                       is an optional parameter that may be NULL.  It will be NULL \r
+                       for device drivers, and for a bus drivers that wish to set \r
+                       options for the bus controller.  It will not be NULL for a \r
+                       bus driver that wishes to set options for one of its child \r
+                       controllers.\r
+    Language         - A pointer to a three character ISO 639-2 language identifier.\r
+                       This is the language of the user interface that should be \r
+                       presented to the user, and it must match one of the languages \r
+                       specified in SupportedLanguages.  The number of languages \r
+                       supported by a driver is up to the driver writer.\r
+    ActionRequired   - A pointer to the action that the calling agent is required \r
+                       to perform when this function returns.  See "Related \r
+                       Definitions" for a list of the actions that the calling \r
+                       agent is required to perform prior to accessing \r
+                       ControllerHandle again.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The driver specified by This successfully set the \r
+                            configuration options for the controller specified \r
+                            by ControllerHandle..\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ActionRequired is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support setting \r
+                            configuration options for the controller specified by \r
+                            ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+    EFI_DEVICE_ERROR      - A device error occurred while attempt to set the \r
+                            configuration options for the controller specified \r
+                            by ControllerHandle and ChildHandle.\r
+    EFI_OUT_RESOURCES     - There are not enough resources available to set the \r
+                            configuration options for the controller specified \r
+                            by ControllerHandle and ChildHandle.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  CHAR8                 *SupportedLanguage;\r
+\r
+  SupportedLanguage = This->SupportedLanguages;\r
+\r
+  Status            = EFI_UNSUPPORTED;\r
+  while (*SupportedLanguage != 0) {\r
+    if (AsciiStrnCmp (Language, SupportedLanguage, 3)) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
+\r
+    SupportedLanguage += 3;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (ActionRequired == NULL || ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (void *)&BlockIo,\r
+                  gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiUnixIoProtocolGuid,\r
+          gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ActionRequired = EfiDriverConfigurationActionNone;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverConfigurationOptionsValid (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle  OPTIONAL\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Tests to see if a controller's current configuration options are valid.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to test if it's current \r
+                       configuration options are valid.\r
+    ChildHandle      - The handle of the child controller to test if it's current\r
+                       configuration options are valid.  This is an optional \r
+                       parameter that may be NULL.  It will be NULL for device \r
+                       drivers.  It will also be NULL for a bus drivers that wish\r
+                       to test the configuration options for the bus controller.\r
+                       It will not be NULL for a bus driver that wishes to test \r
+                       configuration options for one of its child controllers.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The controller specified by ControllerHandle and \r
+                            ChildHandle that is being managed by the driver \r
+                            specified by This has a valid set of  configuration\r
+                            options.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently \r
+                            managing the controller specified by ControllerHandle \r
+                            and ChildHandle.\r
+    EFI_DEVICE_ERROR      - The controller specified by ControllerHandle and \r
+                            ChildHandle that is being managed by the driver \r
+                            specified by This has an invalid set of configuration \r
+                            options.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (void *)&BlockIo,\r
+                  gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiUnixIoProtocolGuid,\r
+          gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverConfigurationForceDefaults (\r
+  IN  EFI_DRIVER_CONFIGURATION_PROTOCOL                      *This,\r
+  IN  EFI_HANDLE                                             ControllerHandle,\r
+  IN  EFI_HANDLE                                             ChildHandle  OPTIONAL,\r
+  IN  UINT32                                                 DefaultType,\r
+  OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED               *ActionRequired\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Forces a driver to set the default configuration options for a controller.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to force default configuration options on.\r
+    ChildHandle      - The handle of the child controller to force default configuration options on  This is an optional parameter that may be NULL.  It will be NULL for device drivers.  It will also be NULL for a bus drivers that wish to force default configuration options for the bus controller.  It will not be NULL for a bus driver that wishes to force default configuration options for one of its child controllers.\r
+    DefaultType      - The type of default configuration options to force on the controller specified by ControllerHandle and ChildHandle.  See Table 9-1 for legal values.  A DefaultType of 0x00000000 must be supported by this protocol.\r
+    ActionRequired   - A pointer to the action that the calling agent is required to perform when this function returns.  See "Related Definitions" in Section 9.1for a list of the actions that the calling agent is required to perform prior to accessing ControllerHandle again.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The driver specified by This successfully forced the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ActionRequired is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support forcing the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the configuration type specified by DefaultType.\r
+    EFI_DEVICE_ERROR      - A device error occurred while attempt to force the default configuration options on the controller specified by  ControllerHandle and ChildHandle.\r
+    EFI_OUT_RESOURCES     - There are not enough resources available to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (ActionRequired == NULL || ControllerHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (void *)&BlockIo,\r
+                  gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiUnixIoProtocolGuid,\r
+          gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *ActionRequired = EfiDriverConfigurationActionNone;\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c b/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c
new file mode 100644 (file)
index 0000000..0e9a32c
--- /dev/null
@@ -0,0 +1,187 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2005, 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
+\r
+  DriverDiagnostics.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include "UnixBlockIo.h"\r
+\r
+//\r
+// EFI Driver Diagnostics Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverDiagnosticsRunDiagnostics (\r
+  IN  EFI_DRIVER_DIAGNOSTICS_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                    ControllerHandle,\r
+  IN  EFI_HANDLE                                    ChildHandle  OPTIONAL,\r
+  IN  EFI_DRIVER_DIAGNOSTIC_TYPE                    DiagnosticType,\r
+  IN  CHAR8                                         *Language,\r
+  OUT EFI_GUID                                      **ErrorType,\r
+  OUT UINTN                                         *BufferSize,\r
+  OUT CHAR16                                        **Buffer\r
+  );\r
+\r
+//\r
+// EFI Driver Diagnostics Protocol\r
+//\r
+EFI_DRIVER_DIAGNOSTICS_PROTOCOL gUnixBlockIoDriverDiagnostics = {\r
+  UnixBlockIoDriverDiagnosticsRunDiagnostics,\r
+  LANGUAGESUPPORTED\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverDiagnosticsRunDiagnostics (\r
+  IN  EFI_DRIVER_DIAGNOSTICS_PROTOCOL               *This,\r
+  IN  EFI_HANDLE                                    ControllerHandle,\r
+  IN  EFI_HANDLE                                    ChildHandle  OPTIONAL,\r
+  IN  EFI_DRIVER_DIAGNOSTIC_TYPE                    DiagnosticType,\r
+  IN  CHAR8                                         *Language,\r
+  OUT EFI_GUID                                      **ErrorType,\r
+  OUT UINTN                                         *BufferSize,\r
+  OUT CHAR16                                        **Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Runs diagnostics on a controller.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.\r
+    ControllerHandle - The handle of the controller to run diagnostics on.\r
+    ChildHandle      - The handle of the child controller to run diagnostics on  \r
+                       This is an optional parameter that may be NULL.  It will \r
+                       be NULL for device drivers.  It will also be NULL for a \r
+                       bus drivers that wish to run diagnostics on the bus \r
+                       controller.  It will not be NULL for a bus driver that \r
+                       wishes to run diagnostics on one of its child controllers.\r
+    DiagnosticType   - Indicates type of diagnostics to perform on the controller \r
+                       specified by ControllerHandle and ChildHandle.   See \r
+                       "Related Definitions" for the list of supported types.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language in which the optional \r
+                       error message should be returned in Buffer, and it must \r
+                       match one of the languages specified in SupportedLanguages.\r
+                       The number of languages supported by a driver is up to \r
+                       the driver writer.  \r
+    ErrorType        - A GUID that defines the format of the data returned in \r
+                       Buffer.  \r
+    BufferSize       - The size, in bytes, of the data returned in Buffer.  \r
+    Buffer           - A buffer that contains a Null-terminated Unicode string \r
+                       plus some additional data whose format is defined by \r
+                       ErrorType.  Buffer is allocated by this function with \r
+                       AllocatePool(), and it is the caller's responsibility \r
+                       to free it with a call to FreePool().  \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The controller specified by ControllerHandle and \r
+                            ChildHandle passed the diagnostic.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid \r
+                            EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ErrorType is NULL.\r
+    EFI_INVALID_PARAMETER - BufferType is NULL.\r
+    EFI_INVALID_PARAMETER - Buffer is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support \r
+                            running diagnostics for the controller specified \r
+                            by ControllerHandle and ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            type of diagnostic specified by DiagnosticType.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+    EFI_OUT_OF_RESOURCES  - There are not enough resources available to complete\r
+                            the diagnostics.\r
+    EFI_OUT_OF_RESOURCES  - There are not enough resources available to return\r
+                            the status information in ErrorType, BufferSize, \r
+                            and Buffer.\r
+    EFI_DEVICE_ERROR      - The controller specified by ControllerHandle and \r
+                            ChildHandle did not pass the diagnostic.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  CHAR8                 *SupportedLanguage;\r
+\r
+  if (Language         == NULL ||\r
+      ErrorType        == NULL ||\r
+      Buffer           == NULL ||\r
+      ControllerHandle == NULL ||\r
+      BufferSize       == NULL) {\r
+\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SupportedLanguage = This->SupportedLanguages;\r
+\r
+  Status            = EFI_UNSUPPORTED;\r
+  while (*SupportedLanguage != 0) {\r
+    if (AsciiStrnCmp (Language, SupportedLanguage, 3)) {\r
+      Status = EFI_SUCCESS;\r
+      break;\r
+    }\r
+\r
+    SupportedLanguage += 3;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  *ErrorType  = NULL;\r
+  *BufferSize = 0;\r
+  if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {\r
+    *ErrorType  = &gEfiBlockIoProtocolGuid;\r
+    *BufferSize = 0x60;\r
+    gBS->AllocatePool (EfiBootServicesData, (UINTN) (*BufferSize),
+                      (void *)Buffer);\r
+    CopyMem (*Buffer, L"Unix Block I/O Driver Diagnostics Failed\n", *BufferSize);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // Validate controller handle\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (void *)&BlockIo,\r
+                  gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiUnixIoProtocolGuid,\r
+          gUnixBlockIoDriverBinding.DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (Status == EFI_UNSUPPORTED) {\r
+    return Status;\r
+  } else if (Status != EFI_ALREADY_STARTED) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/UnixBlockIoDxe/EntryPoint.c b/UnixPkg/UnixBlockIoDxe/EntryPoint.c
new file mode 100644 (file)
index 0000000..dae3687
--- /dev/null
@@ -0,0 +1,51 @@
+/**@file\r
+  Entry Point Source file.\r
+\r
+  This file contains the user entry point \r
+\r
+  Copyright (c) 2006 - 2008, 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
+   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
+\r
+\r
+\r
+#include "UnixBlockIo.h"\r
+\r
+/**\r
+  The user Entry Point for module UnixBlockIo. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixBlockIo(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gUnixBlockIoDriverBinding,\r
+             ImageHandle,\r
+             &gUnixBlockIoComponentName,\r
+             NULL,\r
+             &gUnixBlockIoDriverDiagnostics\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c
new file mode 100644 (file)
index 0000000..d92ab72
--- /dev/null
@@ -0,0 +1,1307 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2007, 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
+\r
+  UnixBlockIo.c\r
+\r
+Abstract:\r
+\r
+  Produce block IO abstractions for real devices on your PC using Posix APIs.\r
+  The configuration of what devices to mount or emulate comes from UNIX \r
+  environment variables. The variables must be visible to the Microsoft* \r
+  Developer Studio for them to work.\r
+\r
+  <F>ixed       - Fixed disk like a hard drive.\r
+  <R>emovable   - Removable media like a floppy or CD-ROM.\r
+  Read <O>nly   - Write protected device.\r
+  Read <W>rite  - Read write device.\r
+  <block count> - Decimal number of blocks a device supports.\r
+  <block size>  - Decimal number of bytes per block.\r
+\r
+  UNIX envirnonment variable contents. '<' and '>' are not part of the variable, \r
+  they are just used to make this help more readable. There should be no \r
+  spaces between the ';'. Extra spaces will break the variable. A '!' is \r
+  used to seperate multiple devices in a variable.\r
+\r
+  EFI_UNIX_VIRTUAL_DISKS = \r
+    <F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+  EFI_UNIX_PHYSICAL_DISKS =\r
+    <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+  Virtual Disks: These devices use a file to emulate a hard disk or removable\r
+                 media device. \r
+                 \r
+    Thus a 20 MB emulated hard drive would look like:\r
+    EFI_UNIX_VIRTUAL_DISKS=FW;40960;512\r
+\r
+    A 1.44MB emulated floppy with a block size of 1024 would look like:\r
+    EFI_UNIX_VIRTUAL_DISKS=RW;1440;1024\r
+\r
+  Physical Disks: These devices use UNIX to open a real device in your system\r
+\r
+    Thus a 120 MB floppy would look like:\r
+    EFI_UNIX_PHYSICAL_DISKS=B:RW;245760;512\r
+\r
+    Thus a standard CD-ROM floppy would look like:\r
+    EFI_UNIX_PHYSICAL_DISKS=Z:RO;307200;2048\r
+\r
+\r
+  * Other names and brands may be claimed as the property of others.\r
+\r
+--*/\r
+\r
+#include <fcntl.h>\r
+#include <unistd.h>\r
+#include "UnixBlockIo.h"\r
+\r
+//\r
+// Block IO protocol member functions\r
+//\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoReadBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  OUT VOID                  *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  MediaId     - TODO: add argument description\r
+  Lba         - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  IN VOID                   *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  MediaId     - TODO: add argument description\r
+  Lba         - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoResetBlock (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN BOOLEAN                ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                  - TODO: add argument description\r
+  ExtendedVerification  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// Private Worker functions\r
+//\r
+STATIC\r
+EFI_STATUS\r
+UnixBlockIoCreateMapping (\r
+  IN EFI_UNIX_IO_PROTOCOL             *UnixIo,\r
+  IN EFI_HANDLE                         EfiDeviceHandle,\r
+  IN CHAR16                             *Filename,\r
+  IN BOOLEAN                            ReadOnly,\r
+  IN BOOLEAN                            RemovableMedia,\r
+  IN UINTN                              NumberOfBlocks,\r
+  IN UINTN                              BlockSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  UnixIo         - TODO: add argument description\r
+  EfiDeviceHandle - TODO: add argument description\r
+  Filename        - TODO: add argument description\r
+  ReadOnly        - TODO: add argument description\r
+  RemovableMedia  - TODO: add argument description\r
+  NumberOfBlocks  - TODO: add argument description\r
+  BlockSize       - TODO: add argument description\r
+  DeviceType      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixBlockIoReadWriteCommon (\r
+  IN  UNIX_BLOCK_IO_PRIVATE *Private,\r
+  IN UINT32                   MediaId,\r
+  IN EFI_LBA                  Lba,\r
+  IN UINTN                    BufferSize,\r
+  IN VOID                     *Buffer,\r
+  IN CHAR8                    *CallerName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private     - TODO: add argument description\r
+  MediaId     - TODO: add argument description\r
+  Lba         - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+  CallerName  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixBlockIoError (\r
+  IN UNIX_BLOCK_IO_PRIVATE      *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixBlockIoOpenDevice (\r
+  UNIX_BLOCK_IO_PRIVATE         *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+CHAR16                                    *\r
+GetNextElementPastTerminator (\r
+  IN  CHAR16  *EnvironmentVariable,\r
+  IN  CHAR16  Terminator\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  EnvironmentVariable - TODO: add argument description\r
+  Terminator          - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+EFI_DRIVER_BINDING_PROTOCOL gUnixBlockIoDriverBinding = {\r
+  UnixBlockIoDriverBindingSupported,\r
+  UnixBlockIoDriverBindingStart,\r
+  UnixBlockIoDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_UNIX_IO_PROTOCOL  *UnixIo;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID **)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure the UnixThunkProtocol is valid\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  if (UnixIo->UnixThunk->Signature == EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {\r
+\r
+    //\r
+    // Check the GUID to see if this is a handle type the driver supports\r
+    //\r
+    if (CompareGuid (UnixIo->TypeGuid, &gEfiUnixVirtualDisksGuid) ) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiUnixIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+{\r
+  EFI_STATUS                  Status;\r
+  EFI_UNIX_IO_PROTOCOL       *UnixIo;\r
+  CHAR16                      Buffer[FILENAME_BUFFER_SIZE];\r
+  CHAR16                      *Str;\r
+  BOOLEAN                     RemovableMedia;\r
+  BOOLEAN                     WriteProtected;\r
+  UINTN                       NumberOfBlocks;\r
+  UINTN                       BlockSize;\r
+  INTN                       i;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  \r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (void *)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  //\r
+  // Set DiskType\r
+  //\r
+  if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixVirtualDisksGuid)) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  Status  = EFI_NOT_FOUND;\r
+  //  Extract filename.\r
+  Str     = UnixIo->EnvString;\r
+  i = 0;\r
+  while (*Str && *Str != ':')\r
+    Buffer[i++] = *Str++;\r
+  Buffer[i] = 0;\r
+  if (*Str != ':') {\r
+    goto Done;\r
+  }\r
+\r
+  Str++;\r
+\r
+  RemovableMedia = FALSE;\r
+  WriteProtected = TRUE;\r
+  NumberOfBlocks = 0;\r
+  BlockSize = 512;\r
+  do {\r
+    if (*Str == 'R' || *Str == 'F') {\r
+      RemovableMedia = (BOOLEAN) (*Str == 'R');\r
+      Str++;\r
+    }\r
+    if (*Str == 'O' || *Str == 'W') {\r
+      WriteProtected  = (BOOLEAN) (*Str == 'O');\r
+      Str++;\r
+    }\r
+    if (*Str == 0)\r
+      break;\r
+    if (*Str != ';')\r
+      goto Done;\r
+    Str++;\r
+\r
+    NumberOfBlocks  = Atoi (Str);\r
+    Str       = GetNextElementPastTerminator (Str, ';');\r
+    if (NumberOfBlocks == 0)\r
+      break;\r
+\r
+    BlockSize = Atoi (Str);\r
+    if (BlockSize != 0)\r
+      Str       = GetNextElementPastTerminator (Str, ';');\r
+  } while (0);\r
+\r
+  //\r
+  // If we get here the variable is valid so do the work.\r
+  //\r
+  Status = UnixBlockIoCreateMapping (\r
+              UnixIo,\r
+              Handle,\r
+              Buffer,\r
+              WriteProtected,\r
+              RemovableMedia,\r
+              NumberOfBlocks,\r
+              BlockSize\r
+              );\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEfiUnixIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  EFI_STATUS              Status;\r
+  UNIX_BLOCK_IO_PRIVATE *Private;\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  (void *)&BlockIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);\r
+\r
+  //\r
+  // BugBug: If we need to kick people off, we need to make Uninstall Close the handles.\r
+  //         We could pass in our image handle or FLAG our open to be closed via\r
+  //         Unistall (== to saying any CloseProtocol will close our open)\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Private->EfiHandle,\r
+                  &gEfiBlockIoProtocolGuid,\r
+                  &Private->BlockIo,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEfiUnixIoProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+\r
+    //\r
+    // Shut down our device\r
+    //\r
+    Private->UnixThunk->Close (Private->fd);\r
+\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+    gBS->FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+CHAR16 *\r
+GetNextElementPastTerminator (\r
+  IN  CHAR16  *EnvironmentVariable,\r
+  IN  CHAR16  Terminator\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Worker function to parse environment variables.\r
+\r
+Arguments:\r
+  EnvironmentVariable - Envirnment variable to parse.\r
+\r
+  Terminator          - Terminator to parse for.\r
+\r
+Returns: \r
+\r
+  Pointer to next eliment past the first occurence of Terminator or the '\0'\r
+  at the end of the string.\r
+\r
+--*/\r
+{\r
+  CHAR16  *Ptr;\r
+\r
+  for (Ptr = EnvironmentVariable; *Ptr != '\0'; Ptr++) {\r
+    if (*Ptr == Terminator) {\r
+      Ptr++;\r
+      break;\r
+    }\r
+  }\r
+\r
+  return Ptr;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixBlockIoCreateMapping (\r
+  IN EFI_UNIX_IO_PROTOCOL             *UnixIo,\r
+  IN EFI_HANDLE                         EfiDeviceHandle,\r
+  IN CHAR16                             *Filename,\r
+  IN BOOLEAN                            ReadOnly,\r
+  IN BOOLEAN                            RemovableMedia,\r
+  IN UINTN                              NumberOfBlocks,\r
+  IN UINTN                              BlockSize\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  UnixIo         - TODO: add argument description\r
+  EfiDeviceHandle - TODO: add argument description\r
+  Filename        - TODO: add argument description\r
+  ReadOnly        - TODO: add argument description\r
+  RemovableMedia  - TODO: add argument description\r
+  NumberOfBlocks  - TODO: add argument description\r
+  BlockSize       - TODO: add argument description\r
+  DeviceType      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_BLOCK_IO_PROTOCOL   *BlockIo;\r
+  UNIX_BLOCK_IO_PRIVATE *Private;\r
+  UINTN                   Index;\r
+\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (UNIX_BLOCK_IO_PRIVATE),\r
+                  (void *)&Private\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  EfiInitializeLock (&Private->Lock, TPL_NOTIFY);\r
+\r
+  Private->UnixThunk = UnixIo->UnixThunk;\r
+\r
+  Private->Signature  = UNIX_BLOCK_IO_PRIVATE_SIGNATURE;\r
+  Private->LastBlock  = NumberOfBlocks - 1;\r
+  Private->BlockSize  = BlockSize;\r
+\r
+  for (Index = 0; Filename[Index] != 0; Index++) {\r
+    Private->Filename[Index] = Filename[Index];\r
+  }\r
+\r
+  Private->Filename[Index]      = 0;\r
+\r
+  Private->Mode                 = (ReadOnly ? O_RDONLY : O_RDWR);\r
+\r
+  Private->NumberOfBlocks       = NumberOfBlocks;\r
+  Private->fd                   = -1;\r
+\r
+  Private->ControllerNameTable  = NULL;\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gUnixBlockIoComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    Filename\r
+    );\r
+\r
+  BlockIo = &Private->BlockIo;\r
+  BlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;\r
+  BlockIo->Media = &Private->Media;\r
+  BlockIo->Media->BlockSize = Private->BlockSize;\r
+  BlockIo->Media->LastBlock = Private->NumberOfBlocks - 1;\r
+  BlockIo->Media->MediaId = 0;;\r
+\r
+  BlockIo->Reset = UnixBlockIoResetBlock;\r
+  BlockIo->ReadBlocks = UnixBlockIoReadBlocks;\r
+  BlockIo->WriteBlocks = UnixBlockIoWriteBlocks;\r
+  BlockIo->FlushBlocks = UnixBlockIoFlushBlocks;\r
+\r
+  BlockIo->Media->ReadOnly = ReadOnly;\r
+  BlockIo->Media->RemovableMedia = RemovableMedia;\r
+  BlockIo->Media->LogicalPartition = FALSE;\r
+  BlockIo->Media->MediaPresent = TRUE;\r
+  BlockIo->Media->WriteCaching = FALSE;\r
+\r
+  BlockIo->Media->IoAlign = 1;\r
+\r
+  Private->EfiHandle  = EfiDeviceHandle;\r
+  Status              = UnixBlockIoOpenDevice (Private);\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &Private->EfiHandle,\r
+                    &gEfiBlockIoProtocolGuid,\r
+                    &Private->BlockIo,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      FreeUnicodeStringTable (Private->ControllerNameTable);\r
+      gBS->FreePool (Private);\r
+    }\r
+\r
+    DEBUG ((EFI_D_ERROR, "BlockDevice added: %s\n", Filename));\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixBlockIoOpenDevice (\r
+  UNIX_BLOCK_IO_PRIVATE                 *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  UINT64                FileSize;\r
+  UINT64                EndOfFile;\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+\r
+  BlockIo = &Private->BlockIo;\r
+  EfiAcquireLock (&Private->Lock);\r
+\r
+  //\r
+  // If the device is already opened, close it\r
+  //\r
+  if (Private->fd >= 0) {\r
+    BlockIo->Reset (BlockIo, FALSE);\r
+  }\r
+\r
+  //\r
+  // Open the device\r
+  //\r
+  Private->fd = Private->UnixThunk->Open\r
+    (Private->Filename, Private->Mode, 0644);\r
+\r
+  if (Private->fd < 0) {\r
+    DEBUG ((EFI_D_INFO, "PlOpenBlock: Could not open %s\n",\r
+           Private->Filename));\r
+    BlockIo->Media->MediaPresent  = FALSE;\r
+    Status                        = EFI_NO_MEDIA;\r
+    goto Done;\r
+  }\r
+\r
+  if (!BlockIo->Media->MediaPresent) {\r
+    //\r
+    // BugBug: try to emulate if a CD appears - notify drivers to check it out\r
+    //\r
+    BlockIo->Media->MediaPresent = TRUE;\r
+    EfiReleaseLock (&Private->Lock);\r
+    EfiAcquireLock (&Private->Lock);\r
+  }\r
+\r
+  //\r
+  // get the size of the file\r
+  //\r
+  Status = SetFilePointer64 (Private, 0, &FileSize, SEEK_END);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    FileSize = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);\r
+    DEBUG ((EFI_D_ERROR, "PlOpenBlock: Could not get filesize of %s\n", Private->Filename));\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  if (Private->NumberOfBlocks == 0) {\r
+    Private->NumberOfBlocks = DivU64x32 (FileSize, Private->BlockSize);\r
+  }\r
+\r
+  EndOfFile = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);\r
+\r
+  if (FileSize != EndOfFile) {\r
+    //\r
+    // file is not the proper size, change it\r
+    //\r
+    DEBUG ((EFI_D_INIT, "PlOpenBlock: Initializing block device: %a\n", Private->Filename));\r
+\r
+    //\r
+    // first set it to 0\r
+    //\r
+    Private->UnixThunk->FTruncate (Private->fd, 0);\r
+\r
+    //\r
+    // then set it to the needed file size (OS will zero fill it)\r
+    //\r
+    Private->UnixThunk->FTruncate (Private->fd, EndOfFile);\r
+  }\r
+\r
+  DEBUG ((EFI_D_INIT, "%HPlOpenBlock: opened %s%N\n", Private->Filename));\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    if (Private->fd >= 0) {\r
+      BlockIo->Reset (BlockIo, FALSE);\r
+    }\r
+  }\r
+\r
+  EfiReleaseLock (&Private->Lock);\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixBlockIoError (\r
+  IN UNIX_BLOCK_IO_PRIVATE      *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  return EFI_DEVICE_ERROR;\r
+\r
+#if 0\r
+  EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
+  EFI_STATUS            Status;\r
+  BOOLEAN               ReinstallBlockIoFlag;\r
+\r
+\r
+  BlockIo = &Private->BlockIo;\r
+\r
+  switch (Private->UnixThunk->GetLastError ()) {\r
+\r
+  case ERROR_NOT_READY:\r
+    Status                        = EFI_NO_MEDIA;\r
+    BlockIo->Media->ReadOnly      = FALSE;\r
+    BlockIo->Media->MediaPresent  = FALSE;\r
+    ReinstallBlockIoFlag          = FALSE;\r
+    break;\r
+\r
+  case ERROR_WRONG_DISK:\r
+    BlockIo->Media->ReadOnly      = FALSE;\r
+    BlockIo->Media->MediaPresent  = TRUE;\r
+    BlockIo->Media->MediaId += 1;\r
+    ReinstallBlockIoFlag  = TRUE;\r
+    Status                = EFI_MEDIA_CHANGED;\r
+    break;\r
+\r
+  case ERROR_WRITE_PROTECT:\r
+    BlockIo->Media->ReadOnly  = TRUE;\r
+    ReinstallBlockIoFlag      = FALSE;\r
+    Status                    = EFI_WRITE_PROTECTED;\r
+    break;\r
+\r
+  default:\r
+    ReinstallBlockIoFlag  = FALSE;\r
+    Status                = EFI_DEVICE_ERROR;\r
+    break;\r
+  }\r
+\r
+  if (ReinstallBlockIoFlag) {\r
+    BlockIo->Reset (BlockIo, FALSE);\r
+\r
+    gBS->ReinstallProtocolInterface (\r
+          Private->EfiHandle,\r
+          &gEfiBlockIoProtocolGuid,\r
+          BlockIo,\r
+          BlockIo\r
+          );\r
+  }\r
+\r
+  return Status;\r
+#endif\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixBlockIoReadWriteCommon (\r
+  IN  UNIX_BLOCK_IO_PRIVATE     *Private,\r
+  IN UINT32                       MediaId,\r
+  IN EFI_LBA                      Lba,\r
+  IN UINTN                        BufferSize,\r
+  IN VOID                         *Buffer,\r
+  IN CHAR8                        *CallerName\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private     - TODO: add argument description\r
+  MediaId     - TODO: add argument description\r
+  Lba         - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+  CallerName  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_NO_MEDIA - TODO: Add description for return value\r
+  EFI_MEDIA_CHANGED - TODO: Add description for return value\r
+  EFI_INVALID_PARAMETER - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+  EFI_BAD_BUFFER_SIZE - TODO: Add description for return value\r
+  EFI_INVALID_PARAMETER - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+  UINTN       BlockSize;\r
+  UINT64      LastBlock;\r
+  INT64       DistanceToMove;\r
+  UINT64      DistanceMoved;\r
+\r
+  if (Private->fd < 0) {\r
+    Status = UnixBlockIoOpenDevice (Private);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  if (!Private->Media.MediaPresent) {\r
+    DEBUG ((EFI_D_INIT, "%s: No Media\n", CallerName));\r
+    return EFI_NO_MEDIA;\r
+  }\r
+\r
+  if (Private->Media.MediaId != MediaId) {\r
+    return EFI_MEDIA_CHANGED;\r
+  }\r
+\r
+  if ((UINT32) Buffer % Private->Media.IoAlign != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  \r
+  //\r
+  // Verify buffer size\r
+  //\r
+  BlockSize = Private->BlockSize;\r
+  if (BufferSize == 0) {\r
+    DEBUG ((EFI_D_INIT, "%s: Zero length read\n", CallerName));\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if ((BufferSize % BlockSize) != 0) {\r
+    DEBUG ((EFI_D_INIT, "%s: Invalid read size\n", CallerName));\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  LastBlock = Lba + (BufferSize / BlockSize) - 1;\r
+  if (LastBlock > Private->LastBlock) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: Attempted to read off end of device\n"));\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  //\r
+  // Seek to End of File\r
+  //\r
+  DistanceToMove = MultU64x32 (Lba, BlockSize);\r
+  Status = SetFilePointer64 (Private, DistanceToMove, &DistanceMoved, SEEK_SET);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((EFI_D_INIT, "WriteBlocks: SetFilePointer failed\n"));\r
+    return UnixBlockIoError (Private);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoReadBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  OUT VOID                  *Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Read BufferSize bytes from Lba into Buffer.\r
+\r
+  Arguments:\r
+    This       - Protocol instance pointer.\r
+    MediaId    - Id of the media, changes every time the media is replaced.\r
+    Lba        - The starting Logical Block Address to read from\r
+    BufferSize - Size of Buffer, must be a multiple of device block size.\r
+    Buffer     - Buffer containing read data\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The data was read correctly from the device.\r
+    EFI_DEVICE_ERROR      - The device reported an error while performing the read.\r
+    EFI_NO_MEDIA          - There is no media in the device.\r
+    EFI_MEDIA_CHANGED     - The MediaId does not matched the current device.\r
+    EFI_BAD_BUFFER_SIZE   - The Buffer was not a multiple of the block size of the \r
+                            device.\r
+    EFI_INVALID_PARAMETER - The read request contains device addresses that are not \r
+                            valid for the device.\r
+\r
+--*/\r
+{\r
+  UNIX_BLOCK_IO_PRIVATE *Private;\r
+  ssize_t                 len;\r
+  EFI_STATUS              Status;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status  = UnixBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "UnixReadBlocks");\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  len = Private->UnixThunk->Read (Private->fd, Buffer, BufferSize);\r
+  if (len != BufferSize) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: ReadFile failed.\n"));\r
+    Status = UnixBlockIoError (Private);\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // If we wrote then media is present.\r
+  //\r
+  This->Media->MediaPresent = TRUE;\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoWriteBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN UINT32                 MediaId,\r
+  IN EFI_LBA                Lba,\r
+  IN UINTN                  BufferSize,\r
+  IN VOID                   *Buffer\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Write BufferSize bytes from Lba into Buffer.\r
+\r
+  Arguments:\r
+    This       - Protocol instance pointer.\r
+    MediaId    - Id of the media, changes every time the media is replaced.\r
+    Lba        - The starting Logical Block Address to read from\r
+    BufferSize - Size of Buffer, must be a multiple of device block size.\r
+    Buffer     - Buffer containing read data\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The data was written correctly to the device.\r
+    EFI_WRITE_PROTECTED   - The device can not be written to.\r
+    EFI_DEVICE_ERROR      - The device reported an error while performing the write.\r
+    EFI_NO_MEDIA          - There is no media in the device.\r
+    EFI_MEDIA_CHNAGED     - The MediaId does not matched the current device.\r
+    EFI_BAD_BUFFER_SIZE   - The Buffer was not a multiple of the block size of the \r
+                            device.\r
+    EFI_INVALID_PARAMETER - The write request contains a LBA that is not \r
+                            valid for the device.\r
+\r
+--*/\r
+{\r
+  UNIX_BLOCK_IO_PRIVATE *Private;\r
+  ssize_t                 len;\r
+  EFI_STATUS              Status;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status  = UnixBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "UnixWriteBlocks");\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  len = Private->UnixThunk->Write (Private->fd, Buffer, BufferSize);\r
+  if (len != BufferSize) {\r
+    DEBUG ((EFI_D_INIT, "ReadBlocks: WriteFile failed.\n"));\r
+    Status = UnixBlockIoError (Private);\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // If the write succeeded, we are not write protected and media is present.\r
+  //\r
+  This->Media->MediaPresent = TRUE;\r
+  This->Media->ReadOnly     = FALSE;\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoFlushBlocks (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Flush the Block Device.\r
+\r
+  Arguments:\r
+    This             - Protocol instance pointer.\r
+\r
+  Returns:\r
+    EFI_SUCCESS      - All outstanding data was written to the device\r
+    EFI_DEVICE_ERROR - The device reported an error while writting back the data\r
+    EFI_NO_MEDIA     - There is no media in the device.\r
+\r
+--*/\r
+{\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoResetBlock (\r
+  IN EFI_BLOCK_IO_PROTOCOL  *This,\r
+  IN BOOLEAN                ExtendedVerification\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Reset the Block Device.\r
+\r
+  Arguments:\r
+    This                 - Protocol instance pointer.\r
+    ExtendedVerification - Driver may perform diagnostics on reset.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The device was reset.\r
+    EFI_DEVICE_ERROR      - The device is not functioning properly and could \r
+                            not be reset.\r
+\r
+--*/\r
+{\r
+  UNIX_BLOCK_IO_PRIVATE *Private;\r
+  EFI_TPL               OldTpl;\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (Private->fd >= 0) {\r
+    Private->UnixThunk->Close (Private->fd);\r
+    Private->fd = -1;\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+UINTN\r
+Atoi (\r
+  CHAR16  *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Convert a unicode string to a UINTN\r
+\r
+Arguments:\r
+\r
+  String - Unicode string.\r
+\r
+Returns: \r
+\r
+  UINTN of the number represented by String.  \r
+\r
+--*/\r
+{\r
+  UINTN   Number;\r
+  CHAR16  *Str;\r
+\r
+  //\r
+  // skip preceeding white space\r
+  //\r
+  Str = String;\r
+  while ((*Str) && (*Str == ' ')) {\r
+    Str++;\r
+  }\r
+  //\r
+  // Convert ot a Number\r
+  //\r
+  Number = 0;\r
+  while (*Str != '\0') {\r
+    if ((*Str >= '0') && (*Str <= '9')) {\r
+      Number = (Number * 10) +*Str - '0';\r
+    } else {\r
+      break;\r
+    }\r
+\r
+    Str++;\r
+  }\r
+\r
+  return Number;\r
+}\r
+\r
+EFI_STATUS\r
+SetFilePointer64 (\r
+  IN  UNIX_BLOCK_IO_PRIVATE    *Private,\r
+  IN  INT64                      DistanceToMove,\r
+  OUT UINT64                     *NewFilePointer,\r
+  IN  INTN                      MoveMethod\r
+  )\r
+/*++\r
+\r
+This function extends the capability of SetFilePointer to accept 64 bit parameters\r
+\r
+--*/\r
+// TODO: function comment is missing 'Routine Description:'\r
+// TODO: function comment is missing 'Arguments:'\r
+// TODO: function comment is missing 'Returns:'\r
+// TODO:    Private - add argument and description to function comment\r
+// TODO:    DistanceToMove - add argument and description to function comment\r
+// TODO:    NewFilePointer - add argument and description to function comment\r
+// TODO:    MoveMethod - add argument and description to function comment\r
+{\r
+  EFI_STATUS    Status;\r
+  off_t         res;\r
+\r
+  res = Private->UnixThunk->Lseek(Private->fd, DistanceToMove, MoveMethod);\r
+  if (res == -1) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (NewFilePointer != NULL) {\r
+    *NewFilePointer = res;\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h
new file mode 100644 (file)
index 0000000..c446f31
--- /dev/null
@@ -0,0 +1,219 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2008, 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
+\r
+  UnixBlockIo.h\r
+\r
+Abstract:\r
+\r
+  Produce block IO abstractions for real devices on your PC using Posix APIs.\r
+  The configuration of what devices to mount or emulate comes from UNIX \r
+  environment variables. The variables must be visible to the Microsoft* \r
+  Developer Studio for them to work.\r
+\r
+  * Other names and brands may be claimed as the property of others.\r
+\r
+--*/\r
+\r
+#ifndef _UNIX_BLOCK_IO_H_\r
+#define _UNIX_BLOCK_IO_H_\r
+\r
+#include "PiDxe.h"\r
+#include <Protocol/BlockIo.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include "UnixDxe.h"\r
+\r
+#define FILENAME_BUFFER_SIZE  80\r
+\r
+//\r
+// Language supported for driverconfiguration protocol\r
+//\r
+#define LANGUAGESUPPORTED "eng"\r
+\r
+#define UNIX_BLOCK_IO_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('L', 'X', 'b', 'k')\r
+typedef struct {\r
+  UINTN                       Signature;\r
+\r
+  EFI_LOCK                    Lock;\r
+\r
+  char                        Filename[FILENAME_BUFFER_SIZE];\r
+  UINTN                       ReadMode;\r
+  UINTN                       Mode;\r
+\r
+  int                         fd;
+\r
+  UINT64                      LastBlock;\r
+  UINTN                       BlockSize;\r
+  UINT64                      NumberOfBlocks;\r
+\r
+  EFI_HANDLE                  EfiHandle;\r
+  EFI_BLOCK_IO_PROTOCOL       BlockIo;\r
+  EFI_BLOCK_IO_MEDIA          Media;\r
+\r
+  EFI_UNICODE_STRING_TABLE    *ControllerNameTable;\r
+\r
+  EFI_UNIX_THUNK_PROTOCOL   *UnixThunk;\r
+\r
+} UNIX_BLOCK_IO_PRIVATE;\r
+\r
+#define UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, UNIX_BLOCK_IO_PRIVATE, BlockIo, UNIX_BLOCK_IO_PRIVATE_SIGNATURE)\r
+\r
+#define LIST_BUFFER_SIZE  512\r
+\r
+//\r
+// Block I/O Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL        gUnixBlockIoDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL        gUnixBlockIoComponentName;\r
+extern EFI_DRIVER_CONFIGURATION_PROTOCOL  gUnixBlockIoDriverConfiguration;\r
+extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL    gUnixBlockIoDriverDiagnostics;\r
+\r
+//\r
+// EFI Driver Binding Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  Handle              - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  Handle              - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBlockIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  UINTN                         NumberOfChildren,\r
+  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+SetFilePointer64 (\r
+  IN  UNIX_BLOCK_IO_PRIVATE    *Private,\r
+  IN  INT64                      DistanceToMove,\r
+  OUT UINT64                     *NewFilePointer,\r
+  IN  INT32                      MoveMethod\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private         - TODO: add argument description\r
+  DistanceToMove  - TODO: add argument description\r
+  NewFilePointer  - TODO: add argument description\r
+  MoveMethod      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+UINTN\r
+Atoi (\r
+  CHAR16  *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  String  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf
new file mode 100644 (file)
index 0000000..00371ad
--- /dev/null
@@ -0,0 +1,71 @@
+#/** @file\r
+# Block Io driver\r
+#\r
+# Produce block IO abstractions for real devices on your PC using Unix APIs.\r
+#  The configuration of what devices to mount or emulate comes from\r
+#  environment variables.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixBlockIo\r
+  FILE_GUID                      = f3085888-8985-11db-9c93-0040d02b1835\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnixBlockIo\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gUnixBlockIoDriverBinding                    \r
+#  COMPONENT_NAME                =  gUnixBlockIoComponentName                    \r
+#  DRIVER_DIAG                   =  gUnixBlockIoDriverDiagnostics                \r
+#\r
+\r
+[Sources.common]\r
+  DriverDiagnostics.c\r
+  DriverConfiguration.c\r
+  ComponentName.c\r
+  UnixBlockIo.c\r
+  UnixBlockIo.h\r
+  EntryPoint.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiUnixPhysicalDisksGuid                    # SOMETIMES_CONSUMED\r
+  gEfiUnixVirtualDisksGuid                     # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiBlockIoProtocolGuid                       # PROTOCOL BY_START\r
+  gEfiUnixIoProtocolGuid                        # PROTOCOL TO_START\r
+\r
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa
new file mode 100644 (file)
index 0000000..4933490
--- /dev/null
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>UnixBlockIo</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>f3085888-8985-11db-9c93-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Block Io driver</Abstract>\r
+    <Description>\r
+      Produce block IO abstractions for real devices on your PC using Unix APIs.\r
+      The configuration of what devices to mount or emulate comes from\r
+      environment variables.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixBlockIo</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixBlockIo.h</Filename>\r
+    <Filename>UnixBlockIo.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+    <Filename>DriverConfiguration.c</Filename>\r
+    <Filename>DriverDiagnostics.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixVirtualDisksGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiUnixPhysicalDisksGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gUnixBlockIoDriverBinding</DriverBinding>\r
+      <ComponentName>gUnixBlockIoComponentName</ComponentName>\r
+      <DriverDiag>gUnixBlockIoDriverDiagnostics</DriverDiag>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixBusDriverDxe/ComponentName.c b/UnixPkg/UnixBusDriverDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..7ea1eac
--- /dev/null
@@ -0,0 +1,208 @@
+/*++\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
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include "UnixBusDriver.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gUnixBusDriverComponentName = {\r
+  UnixBusDriverComponentNameGetDriverName,\r
+  UnixBusDriverComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mUnixBusDriverNameTable[] = {\r
+  { "eng", L"Unix Bus Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixBusDriverComponentName.SupportedLanguages,\r
+          mUnixBusDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the \r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing \r
+                            the controller specified by ControllerHandle and \r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_UNIX_IO_PROTOCOL  *UnixIo;\r
+  UNIX_IO_DEVICE        *Private;\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gUnixBusDriverBinding.DriverBindingHandle,\r
+             &gEfiUnixThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // This is a bus driver, so ChildHandle can not be NULL.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = EfiTestChildHandle (\r
+             ControllerHandle,\r
+             ChildHandle,\r
+             &gEfiUnixThunkProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ChildHandle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID**)&UnixIo,\r
+                  gUnixBusDriverBinding.DriverBindingHandle,\r
+                  ChildHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = UNIX_IO_DEVICE_FROM_THIS (UnixIo);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixBusDriverComponentName.SupportedLanguages,\r
+          Private->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
diff --git a/UnixPkg/UnixBusDriverDxe/EntryPoint.c b/UnixPkg/UnixBusDriverDxe/EntryPoint.c
new file mode 100644 (file)
index 0000000..71a5bda
--- /dev/null
@@ -0,0 +1,51 @@
+/**@file\r
+  Entry Point Source file.\r
+\r
+  This file contains the user entry point \r
+\r
+  Copyright (c) 2006 - 2008, 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
+   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
+\r
+\r
+\r
+#include "UnixBusDriver.h"\r
+\r
+/**\r
+  The user Entry Point for module UnixBusDriver. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixBusDriver(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gUnixBusDriverBinding,\r
+             ImageHandle,\r
+             &gUnixBusDriverComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixBusDriverDxe/UnixBusDriver.c b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.c
new file mode 100644 (file)
index 0000000..b6b2ac6
--- /dev/null
@@ -0,0 +1,716 @@
+/*+++\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
+\r
+  UnixBusDriver.c\r
+\r
+Abstract:\r
+\r
+This following section documents the envirnoment variables for the Win UNIX \r
+build.  These variables are used to define the (virtual) hardware \r
+configuration of the UNIX environment\r
+\r
+A ! can be used to seperate multiple instances in a variable. Each \r
+instance represents a seperate hardware device. \r
+\r
+EFI_UNIX_PHYSICAL_DISKS - maps to drives on your system\r
+EFI_UNIX_VIRTUAL_DISKS  - maps to a device emulated by a file\r
+EFI_UNIX_FILE_SYSTEM    - mouts a directory as a file system\r
+EFI_UNIX_CONSOLE        - make a logical comand line window (only one!)\r
+EFI_UNIX_UGA            - Builds UGA Windows of Width and Height\r
+\r
+ <F>ixed       - Fixed disk like a hard drive.\r
+ <R>emovable   - Removable media like a floppy or CD-ROM.\r
+ Read <O>nly   - Write protected device.\r
+ Read <W>rite  - Read write device.\r
+ <block count> - Decimal number of blocks a device supports.\r
+ <block size>  - Decimal number of bytes per block.\r
+\r
+ UNIX envirnonment variable contents. '<' and '>' are not part of the variable, \r
+ they are just used to make this help more readable. There should be no \r
+ spaces between the ';'. Extra spaces will break the variable. A '!' is  \r
+ used to seperate multiple devices in a variable.\r
+\r
+ EFI_UNIX_VIRTUAL_DISKS = \r
+   <F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+ EFI_UNIX_PHYSICAL_DISKS =\r
+   <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+ Virtual Disks: These devices use a file to emulate a hard disk or removable\r
+                media device. \r
+                \r
+   Thus a 20 MB emulated hard drive would look like:\r
+   EFI_UNIX_VIRTUAL_DISKS=FW;40960;512\r
+\r
+   A 1.44MB emulated floppy with a block size of 1024 would look like:\r
+   EFI_UNIX_VIRTUAL_DISKS=RW;1440;1024\r
+\r
+ Physical Disks: These devices use UNIX to open a real device in your system\r
+\r
+   Thus a 120 MB floppy would look like:\r
+   EFI_UNIX_PHYSICAL_DISKS=B:RW;245760;512\r
+\r
+   Thus a standard CD-ROM floppy would look like:\r
+   EFI_UNIX_PHYSICAL_DISKS=Z:RO;307200;2048\r
+\r
+ EFI_UNIX_FILE_SYSTEM = \r
+   <directory path>[!...]\r
+\r
+   Mounting the two directories C:\FOO and C:\BAR would look like:\r
+   EFI_UNIX_FILE_SYSTEM=c:\foo!c:\bar\r
+\r
+ EFI_UNIX_CONSOLE = \r
+   <window title>\r
+\r
+   Declaring a text console window with the title "My EFI Console" woild look like:\r
+   EFI_UNIX_CONSOLE=My EFI Console\r
+\r
+ EFI_UNIX_UGA = \r
+   <width> <height>[!...]\r
+\r
+   Declaring a two UGA windows with resolutions of 800x600 and 1024x768 would look like:\r
+   Example : EFI_UNIX_UGA=800 600!1024 768\r
+\r
+ EFI_UNIX_PASS_THROUGH =\r
+   <BaseAddress>;<Bus#>;<Device#>;<Function#>\r
+\r
+   Declaring a base address of 0xE0000000 (used for PCI Express devices)\r
+   and having NT32 talk to a device located at bus 0, device 1, function 0:\r
+   Example : EFI_UNIX_PASS_THROUGH=E000000;0;1;0\r
+\r
+---*/\r
+\r
+#include "UnixBusDriver.h"\r
+\r
+//\r
+// Define GUID for the Unix Bus Driver\r
+//\r
+static EFI_GUID gUnixBusDriverGuid = {\r
+  0x419f582, 0x625, 0x4531, {0x8a, 0x33, 0x85, 0xa9, 0x96, 0x5c, 0x95, 0xbc}\r
+};\r
+\r
+//\r
+// DriverBinding protocol global\r
+//\r
+EFI_DRIVER_BINDING_PROTOCOL           gUnixBusDriverBinding = {\r
+  UnixBusDriverBindingSupported,\r
+  UnixBusDriverBindingStart,\r
+  UnixBusDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+#define UNIX_PCD_ARRAY_SIZE (sizeof(mPcdEnvironment)/sizeof(UNIX_PCD_ENTRY))\r
+\r
+//\r
+// Table to map UNIX Environment variable to the GUID that should be in\r
+// device path.\r
+//\r
+static UNIX_PCD_ENTRY  mPcdEnvironment[] = {\r
+  {PcdToken(PcdUnixConsole),       &gEfiUnixConsoleGuid},\r
+  {PcdToken(PcdUnixUga),           &gEfiUnixUgaGuid},\r
+  {PcdToken(PcdUnixFileSystem),    &gEfiUnixFileSystemGuid},\r
+  {PcdToken(PcdUnixSerialPort),    &gEfiUnixSerialPortGuid},\r
+  {PcdToken(PcdUnixVirtualDisk),   &gEfiUnixVirtualDisksGuid},\r
+  {PcdToken(PcdUnixPhysicalDisk),  &gEfiUnixPhysicalDisksGuid},\r
+  {PcdToken(PcdUnixCpuModel),      &gEfiUnixCPUModelGuid},\r
+  {PcdToken(PcdUnixCpuSpeed),      &gEfiUnixCPUSpeedGuid},\r
+  {PcdToken(PcdUnixMemorySize),    &gEfiUnixMemoryGuid}\r
+};\r
+\r
+VOID *\r
+AllocateMemory (\r
+  IN  UINTN   Size\r
+  )\r
+{\r
+  EFI_STATUS  Status;\r
+  VOID        *Buffer;\r
+\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  Size,\r
+                  (VOID *)&Buffer\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    ASSERT (FALSE);\r
+    return NULL;\r
+  }\r
+  return Buffer;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    ControllerHandle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+// TODO:    EFI_UNSUPPORTED - add return value to function comment\r
+// TODO:    EFI_UNSUPPORTED - add return value to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EFI_UNIX_THUNK_PROTOCOL *UnixThunk;\r
+  UINTN                     Index;\r
+\r
+  //\r
+  // Check the contents of the first Device Path Node of RemainingDevicePath to make sure\r
+  // it is a legal Device Path Node for this bus driver's children.\r
+  //\r
+  if (RemainingDevicePath != NULL) {\r
+    if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||\r
+        RemainingDevicePath->SubType != HW_VENDOR_DP ||\r
+        DevicePathNodeLength(RemainingDevicePath) != sizeof(UNIX_VENDOR_DEVICE_PATH_NODE)) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+\r
+    for (Index = 0; Index < UNIX_PCD_ARRAY_SIZE; Index++) {\r
+      if (CompareGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid, mPcdEnvironment[Index].DevicePathGuid)) {\r
+        break;\r
+      }\r
+    }\r
+\r
+    if (Index >= UNIX_PCD_ARRAY_SIZE) {\r
+      return EFI_UNSUPPORTED;\r
+    }\r
+  }\r
+  \r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **)&ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiDevicePathProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUnixThunkProtocolGuid,\r
+                  (VOID **)&UnixThunk,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Since we call through UnixThunk we need to make sure it's valid\r
+  //\r
+  Status = EFI_SUCCESS;\r
+  if (UnixThunk->Signature != EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {\r
+    Status = EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiUnixThunkProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    ControllerHandle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+// TODO:    EFI_OUT_OF_RESOURCES - add return value to function comment\r
+// TODO:    EFI_OUT_OF_RESOURCES - add return value to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_STATUS                      InstallStatus;\r
+  EFI_UNIX_THUNK_PROTOCOL         *UnixThunk;\r
+  EFI_DEVICE_PATH_PROTOCOL        *ParentDevicePath;\r
+  UNIX_BUS_DEVICE                 *UnixBusDevice;\r
+  UNIX_IO_DEVICE                  *UnixDevice;\r
+  UINTN                           Index;\r
+  CHAR16                          *StartString;\r
+  CHAR16                          *SubString;\r
+  UINT16                          Count;\r
+  UINTN                           StringSize;\r
+  UINT16                          ComponentName[MAX_UNIX_ENVIRNMENT_VARIABLE_LENGTH];\r
+  UNIX_VENDOR_DEVICE_PATH_NODE  *Node;\r
+  BOOLEAN                         CreateDevice;\r
+  CHAR16                          *TempStr;\r
+  CHAR16                          *PcdTempStr;\r
+  UINTN                           TempStrSize;\r
+\r
+  Status = EFI_UNSUPPORTED;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID **)&ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUnixThunkProtocolGuid,\r
+                  (VOID **)&UnixThunk,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    return Status;\r
+  }\r
+\r
+  if (Status != EFI_ALREADY_STARTED) {\r
+    Status = gBS->AllocatePool (\r
+                    EfiBootServicesData,\r
+                    sizeof (UNIX_BUS_DEVICE),\r
+                    (VOID *) &UnixBusDevice\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    UnixBusDevice->Signature           = UNIX_BUS_DEVICE_SIGNATURE;\r
+    UnixBusDevice->ControllerNameTable = NULL;\r
+\r
+    AddUnicodeString (\r
+      "eng",\r
+      gUnixBusDriverComponentName.SupportedLanguages,\r
+      &UnixBusDevice->ControllerNameTable,\r
+      L"Unix Bus Controller"\r
+      );\r
+\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &ControllerHandle,\r
+                    &gUnixBusDriverGuid,\r
+                    UnixBusDevice,\r
+                    NULL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      FreeUnicodeStringTable (UnixBusDevice->ControllerNameTable);\r
+      gBS->FreePool (UnixBusDevice);\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Loop on the Variable list. Parse each variable to produce a set of handles that\r
+  // represent virtual hardware devices.\r
+  //\r
+  InstallStatus   = EFI_NOT_FOUND;\r
+  for (Index = 0; Index < UNIX_PCD_ARRAY_SIZE; Index++) {\r
+    PcdTempStr = (VOID *)LibPcdGetPtr (mPcdEnvironment[Index].Token);\r
+    ASSERT (PcdTempStr != NULL);\r
+\r
+    TempStrSize = StrLen (PcdTempStr);\r
+    TempStr = AllocateMemory ((TempStrSize * sizeof (CHAR16)) + 1);\r
+    StrCpy (TempStr, PcdTempStr);\r
+\r
+    StartString = TempStr;\r
+\r
+    //\r
+    // Parse the envirnment variable into sub strings using '!' as a delimator.\r
+    // Each substring needs it's own handle to be added to the system. This code\r
+    // does not understand the sub string. Thats the device drivers job.\r
+    //\r
+    Count = 0;\r
+    while (*StartString != '\0') {\r
+\r
+      //\r
+      // Find the end of the sub string\r
+      //\r
+      SubString = StartString;\r
+      while (*SubString != '\0' && *SubString != '!') {\r
+        SubString++;\r
+      }\r
+\r
+      if (*SubString == '!') {\r
+        //\r
+        // Replace token with '\0' to make sub strings. If this is the end\r
+        //  of the string SubString will already point to NULL.\r
+        //\r
+        *SubString = '\0';\r
+        SubString++;\r
+      }\r
+\r
+      CreateDevice = TRUE;\r
+      if (RemainingDevicePath != NULL) {\r
+        CreateDevice  = FALSE;\r
+        Node          = (UNIX_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;\r
+        if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&\r
+            Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&\r
+            DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)\r
+            ) {\r
+          if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&\r
+              Node->Instance == Count\r
+              ) {\r
+            CreateDevice = TRUE;\r
+          }\r
+        }\r
+      }\r
+\r
+      if (CreateDevice) {\r
+        //\r
+        // Allocate instance structure, and fill in parent information.\r
+        //\r
+        UnixDevice = AllocateMemory (sizeof (UNIX_IO_DEVICE));\r
+        if (UnixDevice == NULL) {\r
+          return EFI_OUT_OF_RESOURCES;\r
+        }\r
+\r
+        UnixDevice->Handle             = NULL;\r
+        UnixDevice->ControllerHandle   = ControllerHandle;\r
+        UnixDevice->ParentDevicePath   = ParentDevicePath;\r
+\r
+        UnixDevice->UnixIo.UnixThunk   = UnixThunk;\r
+\r
+        //\r
+        // Plus 2 to account for the NULL at the end of the Unicode string\r
+        //\r
+        StringSize = (UINTN) ((UINT8 *) SubString - (UINT8 *) StartString) + sizeof (CHAR16);\r
+        UnixDevice->UnixIo.EnvString = AllocateMemory (StringSize);\r
+        if (UnixDevice->UnixIo.EnvString != NULL) {\r
+          CopyMem (UnixDevice->UnixIo.EnvString, StartString, StringSize);\r
+        }\r
+\r
+        UnixDevice->ControllerNameTable = NULL;\r
+\r
+       //  FIXME: check size\r
+        StrCpy(ComponentName, UnixDevice->UnixIo.EnvString);\r
+\r
+        UnixDevice->DevicePath = UnixBusCreateDevicePath (\r
+                                    ParentDevicePath,\r
+                                    mPcdEnvironment[Index].DevicePathGuid,\r
+                                    Count\r
+                                    );\r
+        if (UnixDevice->DevicePath == NULL) {\r
+          gBS->FreePool (UnixDevice);\r
+          return EFI_OUT_OF_RESOURCES;\r
+        }\r
+\r
+        AddUnicodeString (\r
+          "eng",\r
+          gUnixBusDriverComponentName.SupportedLanguages,\r
+          &UnixDevice->ControllerNameTable,\r
+          ComponentName\r
+          );\r
+\r
+        UnixDevice->UnixIo.TypeGuid       = mPcdEnvironment[Index].DevicePathGuid;\r
+        UnixDevice->UnixIo.InstanceNumber = Count;\r
+\r
+        UnixDevice->Signature              = UNIX_IO_DEVICE_SIGNATURE;\r
+\r
+        Status = gBS->InstallMultipleProtocolInterfaces (\r
+                        &UnixDevice->Handle,\r
+                        &gEfiDevicePathProtocolGuid,\r
+                        UnixDevice->DevicePath,\r
+                        &gEfiUnixIoProtocolGuid,\r
+                        &UnixDevice->UnixIo,\r
+                        NULL\r
+                        );\r
+        if (EFI_ERROR (Status)) {\r
+          FreeUnicodeStringTable (UnixDevice->ControllerNameTable);\r
+          gBS->FreePool (UnixDevice);\r
+        } else {\r
+          //\r
+          // Open For Child Device\r
+          //\r
+          Status = gBS->OpenProtocol (\r
+                          ControllerHandle,\r
+                          &gEfiUnixThunkProtocolGuid,\r
+                          (VOID **)&UnixThunk,\r
+                          This->DriverBindingHandle,\r
+                          UnixDevice->Handle,\r
+                          EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                          );\r
+          if (!EFI_ERROR (Status)) {\r
+            InstallStatus = EFI_SUCCESS;\r
+          }\r
+        }\r
+      }\r
+\r
+      //\r
+      // Parse Next sub string. This will point to '\0' if we are at the end.\r
+      //\r
+      Count++;\r
+      StartString = SubString;\r
+    }\r
+\r
+    gBS->FreePool (TempStr);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+    None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    ControllerHandle - add argument and description to function comment\r
+// TODO:    NumberOfChildren - add argument and description to function comment\r
+// TODO:    ChildHandleBuffer - add argument and description to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+// TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS                Status;\r
+  UINTN                     Index;\r
+  BOOLEAN                   AllChildrenStopped;\r
+  EFI_UNIX_IO_PROTOCOL    *UnixIo;\r
+  UNIX_BUS_DEVICE         *UnixBusDevice;\r
+  UNIX_IO_DEVICE          *UnixDevice;\r
+  EFI_UNIX_THUNK_PROTOCOL *UnixThunk;\r
+\r
+  //\r
+  // Complete all outstanding transactions to Controller.\r
+  // Don't allow any new transaction to Controller to be started.\r
+  //\r
+\r
+  if (NumberOfChildren == 0) {\r
+    //\r
+    // Close the bus driver\r
+    //\r
+    Status = gBS->OpenProtocol (\r
+                    ControllerHandle,\r
+                    &gUnixBusDriverGuid,\r
+                    (VOID **)&UnixBusDevice,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    gBS->UninstallMultipleProtocolInterfaces (\r
+          ControllerHandle,\r
+          &gUnixBusDriverGuid,\r
+          UnixBusDevice,\r
+          NULL\r
+          );\r
+\r
+    FreeUnicodeStringTable (UnixBusDevice->ControllerNameTable);\r
+\r
+    gBS->FreePool (UnixBusDevice);\r
+\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiUnixThunkProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiDevicePathProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  AllChildrenStopped = TRUE;\r
+\r
+  for (Index = 0; Index < NumberOfChildren; Index++) {\r
+\r
+    Status = gBS->OpenProtocol (\r
+                    ChildHandleBuffer[Index],\r
+                    &gEfiUnixIoProtocolGuid,\r
+                    (VOID **)&UnixIo,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+\r
+      UnixDevice = UNIX_IO_DEVICE_FROM_THIS (UnixIo);\r
+\r
+      Status = gBS->CloseProtocol (\r
+                      ControllerHandle,\r
+                      &gEfiUnixThunkProtocolGuid,\r
+                      This->DriverBindingHandle,\r
+                      UnixDevice->Handle\r
+                      );\r
+\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      UnixDevice->Handle,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      UnixDevice->DevicePath,\r
+                      &gEfiUnixIoProtocolGuid,\r
+                      &UnixDevice->UnixIo,\r
+                      NULL\r
+                      );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        gBS->OpenProtocol (\r
+              ControllerHandle,\r
+              &gEfiUnixThunkProtocolGuid,\r
+              (VOID **) &UnixThunk,\r
+              This->DriverBindingHandle,\r
+              UnixDevice->Handle,\r
+              EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+              );\r
+      } else {\r
+        //\r
+        // Close the child handle\r
+        //\r
+        FreeUnicodeStringTable (UnixDevice->ControllerNameTable);\r
+        gBS->FreePool (UnixDevice);\r
+      }\r
+    }\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      AllChildrenStopped = FALSE;\r
+    }\r
+  }\r
+\r
+  if (!AllChildrenStopped) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_DEVICE_PATH_PROTOCOL *\r
+UnixBusCreateDevicePath (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  *RootDevicePath,\r
+  IN  EFI_GUID                  *Guid,\r
+  IN  UINT16                    InstanceNumber\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Create a device path node using Guid and InstanceNumber and append it to\r
+  the passed in RootDevicePath\r
+\r
+Arguments:\r
+  RootDevicePath - Root of the device path to return.\r
+\r
+  Guid           - GUID to use in vendor device path node.\r
+\r
+  InstanceNumber - Instance number to use in the vendor device path. This\r
+                    argument is needed to make sure each device path is unique.\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_PATH_PROTOCOL \r
+\r
+--*/\r
+{\r
+  UNIX_VENDOR_DEVICE_PATH_NODE  DevicePath;\r
+\r
+  DevicePath.VendorDevicePath.Header.Type     = HARDWARE_DEVICE_PATH;\r
+  DevicePath.VendorDevicePath.Header.SubType  = HW_VENDOR_DP;\r
+  SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (UNIX_VENDOR_DEVICE_PATH_NODE));\r
+\r
+  //\r
+  // The GUID defines the Class\r
+  //\r
+  CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID));\r
+\r
+  //\r
+  // Add an instance number so we can make sure there are no Device Path\r
+  // duplication.\r
+  //\r
+  DevicePath.Instance = InstanceNumber;\r
+\r
+  return AppendDevicePathNode (\r
+          RootDevicePath,\r
+          (EFI_DEVICE_PATH_PROTOCOL *) &DevicePath\r
+          );\r
+}\r
diff --git a/UnixPkg/UnixBusDriverDxe/UnixBusDriver.h b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.h
new file mode 100644 (file)
index 0000000..ffc3881
--- /dev/null
@@ -0,0 +1,312 @@
+/*++\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
+\r
+  UnixBusDriver.h\r
+\r
+Abstract:\r
+\r
+This following section documents the PCD for the Unix \r
+build.  These variables are used to define the (virtual) hardware \r
+configuration of the Unix environment\r
+\r
+A ! can be used to seperate multiple instances in a variable. Each \r
+instance represents a seperate hardware device. \r
+\r
+EFI_UNIX_PHYSICAL_DISKS - maps to drives on your system\r
+EFI_UNIX_VIRTUAL_DISKS  - maps to a device emulated by a file\r
+EFI_UNIX_FILE_SYSTEM    - mouts a directory as a file system\r
+EFI_UNIX_CONSOLE        - make a logical comand line window (only one!)\r
+EFI_UNIX_UGA            - Builds UGA Windows of Width and Height\r
+EFI_UNIX_SERIAL_PORT    - maps physical serial ports\r
+EFI_UNIX_PASS_THRU      - associates a device with our PCI support\r
+\r
+ <F>ixed       - Fixed disk like a hard drive.\r
+ <R>emovable   - Removable media like a floppy or CD-ROM.\r
+ Read <O>nly   - Write protected device.\r
+ Read <W>rite  - Read write device.\r
+ <block count> - Decimal number of blocks a device supports.\r
+ <block size>  - Decimal number of bytes per block.\r
+\r
+ UNIX envirnonment variable contents. '<' and '>' are not part of the variable, \r
+ they are just used to make this help more readable. There should be no \r
+ spaces between the ';'. Extra spaces will break the variable. A '!' is  \r
+ used to seperate multiple devices in a variable.\r
+\r
+ EFI_UNIX_VIRTUAL_DISKS = \r
+   <F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+ EFI_UNIX_PHYSICAL_DISKS =\r
+   <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]\r
+\r
+ Virtual Disks: These devices use a file to emulate a hard disk or removable\r
+                media device. \r
+                \r
+   Thus a 20 MB emulated hard drive would look like:\r
+   EFI_UNIX_VIRTUAL_DISKS=FW;40960;512\r
+\r
+   A 1.44MB emulated floppy with a block size of 1024 would look like:\r
+   EFI_UNIX_VIRTUAL_DISKS=RW;1440;1024\r
+\r
+ Physical Disks: These devices use UNIX to open a real device in your system\r
+\r
+   Thus a 120 MB floppy would look like:\r
+   EFI_UNIX_PHYSICAL_DISKS=B:RW;245760;512\r
+\r
+   Thus a standard CD-ROM floppy would look like:\r
+   EFI_UNIX_PHYSICAL_DISKS=Z:RO;307200;2048\r
+\r
+ EFI_UNIX_FILE_SYSTEM = \r
+   <directory path>[!...]\r
+\r
+   Mounting the two directories C:\FOO and C:\BAR would look like:\r
+   EFI_UNIX_FILE_SYSTEM=c:\foo!c:\bar\r
+\r
+ EFI_UNIX_CONSOLE = \r
+   <window title>\r
+\r
+   Declaring a text console window with the title "My EFI Console" woild look like:\r
+   EFI_UNIX_CONSOLE=My EFI Console\r
+\r
+ EFI_UNIX_UGA = \r
+   <width> <height>[!...]\r
+\r
+   Declaring a two UGA windows with resolutions of 800x600 and 1024x768 would look like:\r
+   Example : EFI_UNIX_UGA=800 600!1024 768\r
+\r
+ EFI_UNIX_SERIAL_PORT = \r
+   <port name>[!...]\r
+\r
+   Declaring two serial ports on COM1 and COM2 would look like:\r
+   Example : EFI_UNIX_SERIAL_PORT=COM1!COM2\r
+\r
+ EFI_UNIX_PASS_THROUGH =\r
+   <BaseAddress>;<Bus#>;<Device#>;<Function#>\r
+\r
+   Declaring a base address of 0xE0000000 (used for PCI Express devices)\r
+   and having NT32 talk to a device located at bus 0, device 1, function 0:\r
+   Example : EFI_UNIX_PASS_THROUGH=E000000;0;1;0\r
+\r
+---*/\r
+\r
+#ifndef __UNIX_BUS_DRIVER_H__\r
+#define __UNIX_BUS_DRIVER_H__\r
+#include "PiDxe.h"\r
+#include "UnixDxe.h"\r
+#include <Protocol/Pcd.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+\r
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixBusDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixBusDriverComponentName;\r
+\r
+//\r
+// Unix Bus Driver Global Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gUnixBusDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gUnixBusDriverComponentName;\r
+\r
+//\r
+// Unix Bus Controller Structure\r
+//\r
+#define UNIX_BUS_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('L', 'X', 'B', 'D')\r
+\r
+typedef struct {\r
+  UINT64                    Signature;\r
+  EFI_UNICODE_STRING_TABLE  *ControllerNameTable;\r
+} UNIX_BUS_DEVICE;\r
+\r
+//\r
+// Unix Child Device Controller Structure\r
+//\r
+#define UNIX_IO_DEVICE_SIGNATURE  EFI_SIGNATURE_32 ('L', 'X', 'V', 'D')\r
+\r
+typedef struct {\r
+  UINT64                    Signature;\r
+  EFI_HANDLE                Handle;\r
+  EFI_UNIX_IO_PROTOCOL     UnixIo;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+\r
+  //\r
+  // Private data about the parent\r
+  //\r
+  EFI_HANDLE                ControllerHandle;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+\r
+  EFI_UNICODE_STRING_TABLE  *ControllerNameTable;\r
+\r
+} UNIX_IO_DEVICE;\r
+\r
+#define UNIX_IO_DEVICE_FROM_THIS(a) \\r
+  CR(a, UNIX_IO_DEVICE, UnixIo, UNIX_IO_DEVICE_SIGNATURE)\r
+\r
+//\r
+// This is the largest env variable we can parse\r
+//\r
+#define MAX_UNIX_ENVIRNMENT_VARIABLE_LENGTH 512\r
+\r
+typedef struct {\r
+  UINTN               Token;\r
+  EFI_GUID            *DevicePathGuid;\r
+} UNIX_PCD_ENTRY;\r
+\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH  VendorDevicePath;\r
+  UINT32              Instance;\r
+} UNIX_VENDOR_DEVICE_PATH_NODE;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+CpuIoInitialize (\r
+  IN EFI_HANDLE                            ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ImageHandle - TODO: add argument description\r
+  SystemTable - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// Driver Binding Protocol function prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverBindingSupported (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     Handle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  Handle              - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverBindingStart (\r
+  IN EFI_DRIVER_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                     ParentHandle,\r
+  IN EFI_DEVICE_PATH_PROTOCOL       *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  ParentHandle        - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixBusDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// Unix Bus Driver private worker functions\r
+//\r
+EFI_DEVICE_PATH_PROTOCOL  *\r
+UnixBusCreateDevicePath (\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  *RootDevicePath,\r
+  IN  EFI_GUID                  *Guid,\r
+  IN  UINT16                    InstanceNumber\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  RootDevicePath  - TODO: add argument description\r
+  Guid            - TODO: add argument description\r
+  InstanceNumber  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+\r
+#endif\r
diff --git a/UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf
new file mode 100644 (file)
index 0000000..d3b0f4c
--- /dev/null
@@ -0,0 +1,92 @@
+#/** @file\r
+# Unix Bus driver\r
+#\r
+# This following section documents the envirnoment variables for the Win NT\r
+#  build. These variables are used to define the (virtual) hardware\r
+#  configuration of the NT environment\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixBusDriver\r
+  FILE_GUID                      = f320d656-8985-11db-90e0-0040d02b1835\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnixBusDriver\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gUnixBusDriverBinding                        \r
+#  COMPONENT_NAME                =  gUnixBusDriverComponentName                  \r
+#\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  UnixBusDriver.c\r
+  UnixBusDriver.h\r
+  EntryPoint.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  DevicePathLib\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  PcdLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiUnixConsoleGuid                          # ALWAYS_CONSUMED\r
+  gEfiUnixUgaGuid                              # ALWAYS_CONSUMED\r
+  gEfiUnixSerialPortGuid                       # ALWAYS_CONSUMED\r
+  gEfiUnixFileSystemGuid                       # ALWAYS_CONSUMED\r
+  gEfiUnixPhysicalDisksGuid                    # ALWAYS_CONSUMED\r
+  gEfiUnixVirtualDisksGuid                     # ALWAYS_CONSUMED\r
+  gEfiUnixCPUModelGuid\r
+  gEfiUnixCPUSpeedGuid\r
+  gEfiUnixMemoryGuid\r
+\r
+\r
+[Protocols]\r
+  gPcdProtocolGuid                              # PROTOCOL ALWAYS_CONSUMED\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+  gEfiUnixThunkProtocolGuid                     # PROTOCOL TO_START\r
+  gEfiUnixIoProtocolGuid                        # PROTOCOL BY_START\r
+\r
+\r
+[Pcd.common]\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixSerialPort\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySize\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuSpeed\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuModel\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixPhysicalDisk\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixVirtualDisk\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFileSystem\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixUga\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixConsole\r
+\r
diff --git a/UnixPkg/UnixBusDriverDxe/UnixBusDriver.msa b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.msa
new file mode 100644 (file)
index 0000000..6422c06
--- /dev/null
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UnixBusDriver</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>f320d656-8985-11db-90e0-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Unix Bus driver</Abstract>\r
+    <Description>This following section documents the envirnoment variables for the Win NT
+      build.  These variables are used to define the (virtual) hardware
+      configuration of the NT environment</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>All rights reserved. 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
+      http://opensource.org/licenses/bsd-license.php
+      THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+      WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixBusDriver</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DevicePathLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixBusDriver.h</Filename>\r
+    <Filename>UnixBusDriver.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gPcdProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixVirtualDisksGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixPhysicalDisksGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixFileSystemGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixUgaGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixConsoleGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixMemoryGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixCPUModelGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixCPUSpeedGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixSerialPortGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gUnixBusDriverBinding</DriverBinding>\r
+      <ComponentName>gUnixBusDriverComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixConsole</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD declares the title string of the text console window.
+        such as "My EFI Console".
+        The item type of this PCD can only be "DYNAMIC".</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixUga</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD declares the resolutions for the UGA windows.
+        The item type of this PCD can only be "DYNAMIC".</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixFileSystem</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines the unix directory who will be mounted as
+        harddisk in simulator.
+        The item type of this PCD can only be "DYNAMIC".</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixVirtualDisk</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines the devices which use a file to emulate a hard disk or
+        removable media device
+        The item type if this PCD can only be "DYNAMIC".</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixPhysicalDisk</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines physical disk which will be simualted as a
+        harddisk in simulator.
+        The item type of this PCD can only be "DYNAMIC".</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixCpuModel</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines simulated CPU model string.
+        The item type of this PCD can only be "DYNAMIC".</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixCpuSpeed</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines simulated CPU speed string.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdUnixMemorySize</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>This PCD defines the size of simulated memory size.
+        The item type of this PCD can only be "DYNAMIC".</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdUnixSerialPort</C_Name>\r
+      <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>Simulation serial IO port</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/UnixPkg/UnixConsoleDxe/ComponentName.c b/UnixPkg/UnixConsoleDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..e73ba7b
--- /dev/null
@@ -0,0 +1,197 @@
+/*++\r
+\r
+Copyright (c) 2004, 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
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include "Console.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gUnixConsoleComponentName = {\r
+  UnixConsoleComponentNameGetDriverName,\r
+  UnixConsoleComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mUnixConsoleDriverNameTable[] = {\r
+  { "eng", L"Unix Text Console Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixConsoleComponentName.SupportedLanguages,\r
+          mUnixConsoleDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the \r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing \r
+                            the controller specified by ControllerHandle and \r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *SimpleTextOut;\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Make sure this driver is currently managing ControllerHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gUnixConsoleDriverBinding.DriverBindingHandle,\r
+             &gEfiUnixIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get out context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  (void *)&SimpleTextOut,\r
+                  gUnixConsoleDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixConsoleComponentName.SupportedLanguages,\r
+          Private->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
diff --git a/UnixPkg/UnixConsoleDxe/Console.c b/UnixPkg/UnixConsoleDxe/Console.c
new file mode 100644 (file)
index 0000000..314da93
--- /dev/null
@@ -0,0 +1,310 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2005, 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
+\r
+  Console.c\r
+\r
+Abstract:\r
+\r
+  Console based on Posix APIs. \r
+\r
+--*/\r
+\r
+#include "Console.h"\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  );\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gUnixConsoleDriverBinding = {\r
+  UnixConsoleDriverBindingSupported,\r
+  UnixConsoleDriverBindingStart,\r
+  UnixConsoleDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_UNIX_IO_PROTOCOL  *UnixIo;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (void *)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure that the Unix Thunk Protocol is valid\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  if (UnixIo->UnixThunk->Signature == EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {\r
+\r
+    //\r
+    // Check the GUID to see if this is a handle type the driver supports\r
+    //\r
+    if (CompareGuid (UnixIo->TypeGuid, &gEfiUnixConsoleGuid)) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiUnixIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+{\r
+  EFI_STATUS                      Status;\r
+  EFI_UNIX_IO_PROTOCOL          *UnixIo;\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  //\r
+  // Grab the IO abstraction we need to get any work done\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (void *)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (UNIX_SIMPLE_TEXT_PRIVATE_DATA),\r
+                  (void *)&Private\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  ZeroMem (Private, sizeof (UNIX_SIMPLE_TEXT_PRIVATE_DATA));\r
+\r
+  Private->Signature  = UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE;\r
+  Private->Handle     = Handle;\r
+  Private->UnixIo    = UnixIo;\r
+  Private->UnixThunk = UnixIo->UnixThunk;\r
+\r
+  UnixSimpleTextOutOpenWindow (Private);\r
+  UnixSimpleTextInAttachToWindow (Private);\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Handle,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  &Private->SimpleTextOut,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &Private->SimpleTextIn,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+Done:\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiUnixIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+  if (Private != NULL) {\r
+\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+#if 0\r
+    if (Private->NtOutHandle != NULL) {\r
+      Private->UnixThunk->CloseHandle (Private->NtOutHandle);\r
+    }\r
+#endif\r
+\r
+    if (Private->SimpleTextIn.WaitForKey != NULL) {\r
+      gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);\r
+    }\r
+\r
+    gBS->FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixConsoleDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_UNSUPPORTED - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL    *SimpleTextOut;\r
+  EFI_STATUS                      Status;\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  //\r
+  // Kick people off our interface???\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  (void *)&SimpleTextOut,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);\r
+\r
+  ASSERT (Private->Handle == Handle);\r
+\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Handle,\r
+                  &gEfiSimpleTextOutProtocolGuid,\r
+                  &Private->SimpleTextOut,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &Private->SimpleTextIn,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+\r
+    //\r
+    // Shut down our device\r
+    //\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEfiUnixIoProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+\r
+    Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);\r
+    ASSERT_EFI_ERROR (Status);\r
+\r
+#if 0\r
+    Private->UnixThunk->CloseHandle (Private->NtOutHandle);\r
+#endif\r
+    //\r
+    // DO NOT close Private->NtInHandle. It points to StdIn and not\r
+    //  the Private->NtOutHandle is StdIn and should not be closed!\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+    gBS->FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixConsoleDxe/Console.h b/UnixPkg/UnixConsoleDxe/Console.h
new file mode 100644 (file)
index 0000000..f673c0b
--- /dev/null
@@ -0,0 +1,530 @@
+/*++\r
+\r
+Copyright (c) 2004 - 2008, 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
+\r
+  Console.h\r
+\r
+Abstract:\r
+\r
+  Console based on Posix APIs.\r
+\r
+  This file attaches a SimpleTextIn protocol to a previously open window.\r
+  \r
+  The constructor for this protocol depends on an open window. Currently\r
+  the SimpleTextOut protocol creates a window when it's constructor is called.\r
+  Thus this code must run after the constructor for the SimpleTextOut \r
+  protocol\r
+  \r
+--*/\r
+\r
+#ifndef _CONSOLE_H_\r
+#define _CONSOLE_H_\r
+\r
+#include "PiDxe.h"\r
+#include "UnixDxe.h"\r
+#include <Protocol/UnixIo.h>\r
+#include <Protocol/SimpleTextIn.h>\r
+#include <Protocol/SimpleTextOut.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixConsoleDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixConsoleComponentName;\r
+\r
+#define UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE \\r
+          EFI_SIGNATURE_32('U','X','s','c')\r
+\r
+typedef struct {\r
+  UINT64                        Signature;\r
+\r
+  EFI_HANDLE                    Handle;\r
+\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  SimpleTextOut;\r
+  EFI_SIMPLE_TEXT_OUTPUT_MODE   SimpleTextOutMode;\r
+\r
+  EFI_UNIX_IO_PROTOCOL        *UnixIo;\r
+  EFI_UNIX_THUNK_PROTOCOL     *UnixThunk;\r
+\r
+  //\r
+  // SimpleTextOut Private Data including Posix types.\r
+  //\r
+  //  HANDLE                        NtOutHandle;\r
+  //  HANDLE                        NtInHandle;\r
+\r
+  //COORD                         MaxScreenSize;\r
+  //COORD                         Position;\r
+  //WORD                          Attribute;\r
+  BOOLEAN                       CursorEnable;\r
+\r
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL   SimpleTextIn;\r
+\r
+  EFI_UNICODE_STRING_TABLE      *ControllerNameTable;\r
+\r
+} UNIX_SIMPLE_TEXT_PRIVATE_DATA;\r
+\r
+#define UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, UNIX_SIMPLE_TEXT_PRIVATE_DATA, SimpleTextOut, UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE)\r
+\r
+#define UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, UNIX_SIMPLE_TEXT_PRIVATE_DATA, SimpleTextIn, UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE)\r
+\r
+//\r
+// Console Globale Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gUnixConsoleDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gUnixConsoleComponentName;\r
+\r
+typedef struct {\r
+  UINTN ColumnsX;\r
+  UINTN RowsY;\r
+} UNIX_SIMPLE_TEXT_OUT_MODE;\r
+\r
+#if 0
+//\r
+// Simple Text Out protocol member functions\r
+//\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutReset (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL     *This,\r
+  IN BOOLEAN                          ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                  - TODO: add argument description\r
+  ExtendedVerification  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutOutputString (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN CHAR16                         *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  String  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutTestString (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN CHAR16                         *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  String  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutQueryMode (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN UINTN                          ModeNumber,\r
+  OUT UINTN                         *Columns,\r
+  OUT UINTN                         *Rows\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  ModeNumber  - TODO: add argument description\r
+  Columns     - TODO: add argument description\r
+  Rows        - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutSetMode (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN UINTN                          ModeNumber\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  ModeNumber  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutSetAttribute (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN UINTN                          Attribute\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This      - TODO: add argument description\r
+  Attribute - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutClearScreen (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutSetCursorPosition (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN UINTN                          Column,\r
+  IN UINTN                          Row\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Column  - TODO: add argument description\r
+  Row     - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutEnableCursor (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN BOOLEAN                        Enable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Enable  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif
+//\r
+// Simple Text Out constructor and destructor.\r
+//\r
+EFI_STATUS\r
+UnixSimpleTextOutOpenWindow (\r
+  IN OUT  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+UnixSimpleTextOutCloseWindow (\r
+  IN OUT  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Console - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#if 0
+//\r
+// Simple Text In protocol member functions.\r
+//\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextInReset (\r
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL          *This,\r
+  IN BOOLEAN                              ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                  - TODO: add argument description\r
+  ExtendedVerification  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextInReadKeyStroke (\r
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL          *This,\r
+  OUT EFI_INPUT_KEY                       *Key\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+  Key   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+STATIC\r
+VOID\r
+EFIAPI\r
+UnixSimpleTextInWaitForKey (\r
+  IN EFI_EVENT          Event,\r
+  IN VOID               *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Event   - TODO: add argument description\r
+  Context - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif
+//\r
+// Simple Text In constructor\r
+//\r
+EFI_STATUS\r
+UnixSimpleTextInAttachToWindow (\r
+  IN  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// Main Entry Point\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixConsole (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ImageHandle - TODO: add argument description\r
+  SystemTable - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+AppendDevicePathInstanceToVar (\r
+  IN  CHAR16                    *VariableName,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL  *DevicePathInstance\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  VariableName        - TODO: add argument description\r
+  DevicePathInstance  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/UnixPkg/UnixConsoleDxe/ConsoleIn.c b/UnixPkg/UnixConsoleDxe/ConsoleIn.c
new file mode 100644 (file)
index 0000000..f315eaa
--- /dev/null
@@ -0,0 +1,246 @@
+/*++\r
+\r
+Copyright (c) 2004, 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
+\r
+  ConsoleIn.c\r
+\r
+Abstract:\r
+\r
+  Console based on Posix APIs.\r
+\r
+  This file attaches a SimpleTextIn protocol to a previously open window.\r
+\r
+  The constructor for this protocol depends on an open window. Currently\r
+  the SimpleTextOut protocol creates a window when it's constructor is called.\r
+  Thus this code must run after the constructor for the SimpleTextOut\r
+  protocol\r
+\r
+--*/\r
+\r
+#include "Console.h"\r
+#include <sys/poll.h>
+\r
+//\r
+// Private worker functions\r
+//\r
+STATIC\r
+EFI_STATUS\r
+UnixSimpleTextInCheckKey (\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA  *Private\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextInReset (\r
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL          *This,\r
+  IN BOOLEAN                              ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                  - TODO: add argument description\r
+  ExtendedVerification  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixConvertInputRecordToEfiKey (\r
+  IN  char c,
+  OUT EFI_INPUT_KEY   *Key\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  InputRecord - TODO: add argument description\r
+  Key         - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_NOT_READY - TODO: Add description for return value\r
+  EFI_NOT_READY - TODO: Add description for return value\r
+  EFI_NOT_READY - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  Key->ScanCode     = 0;\r
+  if (c == '\n')
+    c = '\r';
+  Key->UnicodeChar  = c;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextInReadKeyStroke (\r
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL          *This,\r
+  OUT EFI_INPUT_KEY                       *Key\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+  Key   - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_NOT_READY - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                      Status;\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+  char c;
+\r
+  Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status  = UnixSimpleTextInCheckKey (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  if (Private->UnixThunk->Read (0, &c, 1) != 1)
+    return EFI_NOT_READY;\r
+  Status = UnixConvertInputRecordToEfiKey (c, Key);\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+VOID\r
+EFIAPI\r
+UnixSimpleTextInWaitForKey (\r
+  IN EFI_EVENT          Event,\r
+  IN VOID               *Context\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Event   - TODO: add argument description\r
+  Context - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+  EFI_STATUS                      Status;\r
+\r
+  Private = (UNIX_SIMPLE_TEXT_PRIVATE_DATA *) Context;\r
+  Status  = UnixSimpleTextInCheckKey (Private);\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->SignalEvent (Event);\r
+  }\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixSimpleTextInCheckKey (\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA   *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  struct pollfd pfd;
+\r
+  pfd.fd = 0;
+  pfd.events = POLLIN;
+  if (Private->UnixThunk->Poll (&pfd, 1, 0) <= 0) {
+    return EFI_NOT_READY;\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+UnixSimpleTextInAttachToWindow (\r
+  IN  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_STATUS  Status;\r
+\r
+  Private->SimpleTextIn.Reset         = UnixSimpleTextInReset;\r
+  Private->SimpleTextIn.ReadKeyStroke = UnixSimpleTextInReadKeyStroke;\r
+\r
+  Status = gBS->CreateEvent (\r
+                  EVT_NOTIFY_WAIT,\r
+                  TPL_NOTIFY,\r
+                  UnixSimpleTextInWaitForKey,\r
+                  Private,\r
+                  &Private->SimpleTextIn.WaitForKey\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixConsoleDxe/ConsoleOut.c b/UnixPkg/UnixConsoleDxe/ConsoleOut.c
new file mode 100644 (file)
index 0000000..416db94
--- /dev/null
@@ -0,0 +1,635 @@
+/*++\r
+\r
+Copyright (c) 2004, 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
+\r
+  ConsoleOut.c\r
+\r
+Abstract:\r
+\r
+  Console based on Posix APIs. \r
+\r
+  This file creates an Posix window and attaches a SimpleTextOut protocol.\r
+\r
+--*/\r
+\r
+#include "Console.h"\r
+//\r
+// Private worker functions.\r
+//\r
+\r
+#if 0
+STATIC\r
+VOID\r
+UnixSimpleTextOutScrollScreen (\r
+  IN OUT  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console\r
+  );\r
+\r
+#endif
+STATIC\r
+VOID\r
+UnixSimpleTextOutPutChar (\r
+  IN OUT  UNIX_SIMPLE_TEXT_PRIVATE_DATA     *Console,\r
+  IN      CHAR16                              Char\r
+  );\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutSetAttribute (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN UINTN                          Attribute\r
+  );\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutSetMode (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL           *This,\r
+  IN UINTN                                  ModeNumber\r
+  );\r
+
+//\r
+// Modeule Global for Simple Text Out Mode.\r
+//\r
+#define MAX_SIMPLE_TEXT_OUT_MODE  \\r
+        (sizeof(mUnixSimpleTextOutSupportedModes)/sizeof(UNIX_SIMPLE_TEXT_OUT_MODE))\r
+\r
+STATIC UNIX_SIMPLE_TEXT_OUT_MODE  mUnixSimpleTextOutSupportedModes[] = {\r
+  { 80, 25 },         \r
+#if 0
+  { 80, 50 },         \r
+  { 80, 43 },         \r
+  { 100, 100 },       \r
+  { 100, 999 }         \r
+#endif
+};\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutReset (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL         *This,\r
+  IN BOOLEAN                              ExtendedVerification\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                  - TODO: add argument description\r
+  ExtendedVerification  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  UnixSimpleTextOutSetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));\r
+\r
+  UnixSimpleTextOutSetMode (This, 0);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutOutputString (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL           *This,\r
+  IN CHAR16                                 *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  String  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+  CHAR16                          *Str;\r
+\r
+  Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  for (Str = String; *Str != '\0'; Str++) {\r
+    switch (*Str) {\r
+#if 0
+    case '\n':\r
+      if (Private->Position.Y == (Private->MaxScreenSize.Y - 1)) {\r
+        UnixSimpleTextOutScrollScreen (Private);\r
+      }\r
+\r
+      if (Private->Position.Y < (Private->MaxScreenSize.Y - 1)) {\r
+        Private->Position.Y++;\r
+        This->Mode->CursorRow++;\r
+      }\r
+      break;\r
+\r
+    case '\r':\r
+      Private->Position.X      = 0;\r
+      This->Mode->CursorColumn  = 0;\r
+      break;\r
+\r
+    case '\b':\r
+      if (Private->Position.X > 0) {\r
+        Private->Position.X--;\r
+        This->Mode->CursorColumn--;\r
+      }\r
+      break;\r
+\r
+#endif
+    default:\r
+      UnixSimpleTextOutPutChar (Private, *Str);\r
+    }\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+VOID\r
+UnixSimpleTextOutPutChar (\r
+  IN OUT  UNIX_SIMPLE_TEXT_PRIVATE_DATA   *Console,\r
+  IN      CHAR16                            Char\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Console - TODO: add argument description\r
+  Char    - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  char c = Char;
+  Console->UnixThunk->Write (1, &c, 1);
+}\r
+\r
+#if 0
+STATIC\r
+VOID\r
+UnixSimpleTextOutScrollScreen (\r
+  IN OUT  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Console - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+}\r
+#endif
+
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutTestString (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL           *This,\r
+  IN CHAR16                                 *String\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  String  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  // BugBug: The correct answer would be a function of what code pages\r
+  //         are currently loaded? For now we will just return success.\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutQueryMode (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL           *This,\r
+  IN UINTN                                  ModeNumber,\r
+  OUT UINTN                                 *Columns,\r
+  OUT UINTN                                 *Rows\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  ModeNumber  - TODO: add argument description\r
+  Columns     - TODO: add argument description\r
+  Rows        - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_INVALID_PARAMETER - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *Columns  = mUnixSimpleTextOutSupportedModes[ModeNumber].ColumnsX;\r
+  *Rows     = mUnixSimpleTextOutSupportedModes[ModeNumber].RowsY;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutSetMode (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL           *This,\r
+  IN UINTN                                  ModeNumber\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  ModeNumber  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_INVALID_PARAMETER - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+\r
+  This->Mode->Mode = (INT32) ModeNumber;\r
+\r
+  This->EnableCursor (This, TRUE);\r
+  This->ClearScreen (This);\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutSetAttribute (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN UINTN                          Attribute\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This      - TODO: add argument description\r
+  Attribute - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  Private               = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+#if 0
+  Private->Attribute    = (WORD) Attribute;\r
+#endif
+  This->Mode->Attribute = (INT32) Attribute;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutClearScreen (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+  //  DWORD                           ConsoleWindow;\r
+\r
+  Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  This->SetCursorPosition (This, 0, 0);\r
+  Private->UnixThunk->Write (1, "\e[2J", 4);
+
+\r
+#if 0
+  Private->UnixThunk->FillConsoleOutputCharacter (\r
+                        Private->NtOutHandle,\r
+                        ' ',\r
+                        Private->MaxScreenSize.X * Private->MaxScreenSize.Y,\r
+                        Private->Possition,\r
+                        &ConsoleWindow\r
+                        );\r
+  Private->UnixThunk->FillConsoleOutputAttribute (\r
+                        Private->NtOutHandle,\r
+                        Private->Attribute,\r
+                        Private->MaxScreenSize.X * Private->MaxScreenSize.Y,\r
+                        Private->Possition,\r
+                        &ConsoleWindow\r
+                        );\r
+#endif
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutSetCursorPosition (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL           *This,\r
+  IN UINTN                                  Column,\r
+  IN UINTN                                  Row\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Column  - TODO: add argument description\r
+  Row     - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  char buf[12];
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+\r
+  Private                   = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+#if 0
+  Private->Position.X      = (WORD) Column;\r
+#endif
+  This->Mode->CursorColumn  = (INT32) Column;\r
+\r
+#if 0
+  Private->Position.Y      = (WORD) Row;\r
+#endif
+  This->Mode->CursorRow     = (INT32) Row;\r
+#if 0
+  Private->UnixThunk->SetConsoleCursorPosition (Private->NtOutHandle, Private->Possition);\r
+#endif
+\r
+  buf[0] = '\e';
+  buf[1] = '[';
+  buf[2] = '0' + ((Row / 100) % 10);
+  buf[3] = '0' + ((Row / 10) % 10);
+  buf[4] = '0' + ((Row / 1) % 10);
+  buf[5] = ';';
+  buf[6] = '0' + ((Column / 100) % 10);
+  buf[7] = '0' + ((Column / 10) % 10);
+  buf[8] = '0' + ((Column / 1) % 10);
+  buf[9] = 'H';
+  Private->UnixThunk->Write (1, buf, 10);
+
+  return EFI_SUCCESS;\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleTextOutEnableCursor (\r
+  IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL   *This,\r
+  IN BOOLEAN                        Enable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Enable  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;\r
+#if 0
+  CONSOLE_CURSOR_INFO             Info;\r
+#endif
+\r
+  Private                   = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);\r
+  Private->CursorEnable     = Enable;\r
+  This->Mode->CursorVisible = Enable;\r
+\r
+#if 0
+  Private->UnixThunk->GetConsoleCursorInfo (Private->NtOutHandle, &Info);\r
+  Info.bVisible = Enable;\r
+  Private->UnixThunk->SetConsoleCursorInfo (Private->NtOutHandle, &Info);\r
+#endif
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+UnixSimpleTextOutOpenWindow (\r
+  IN OUT  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL  *SimpleTextOut;\r
+  CHAR16                        *WindowName;\r
+\r
+  //WindowName          = Private->UnixIo->EnvString;\r
+#if 0
+  Private->Attribute  = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;\r
+  if (*WindowName == '?') {\r
+    Private->Attribute  = BACKGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;\r
+    WindowName          = L"EFI Emulator Error Console";\r
+  }\r
+#endif
+    WindowName          = L"EFI Emulator Error Console";\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gUnixConsoleComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    WindowName\r
+    );\r
+\r
+  //\r
+  // Fill in protocol member functions\r
+  //\r
+  SimpleTextOut                     = &Private->SimpleTextOut;\r
+  SimpleTextOut->Reset              = UnixSimpleTextOutReset;\r
+  SimpleTextOut->OutputString       = UnixSimpleTextOutOutputString;\r
+  SimpleTextOut->TestString         = UnixSimpleTextOutTestString;\r
+  SimpleTextOut->QueryMode          = UnixSimpleTextOutQueryMode;\r
+  SimpleTextOut->SetMode            = UnixSimpleTextOutSetMode;\r
+  SimpleTextOut->SetAttribute       = UnixSimpleTextOutSetAttribute;\r
+  SimpleTextOut->ClearScreen        = UnixSimpleTextOutClearScreen;\r
+  SimpleTextOut->SetCursorPosition  = UnixSimpleTextOutSetCursorPosition;\r
+  SimpleTextOut->EnableCursor       = UnixSimpleTextOutEnableCursor;\r
+\r
+  //\r
+  // Initialize SimpleTextOut protocol mode structure\r
+  //\r
+  SimpleTextOut->Mode             = &Private->SimpleTextOutMode;\r
+  SimpleTextOut->Mode->MaxMode    = MAX_SIMPLE_TEXT_OUT_MODE;\r
+  SimpleTextOut->Mode->Attribute  = 0; //FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;\r
+\r
+#if 0
+  //\r
+  // Open the window an initialize it!\r
+  //\r
+  Private->NtOutHandle = Private->UnixThunk->CreateConsoleScreenBuffer (\r
+                                                GENERIC_WRITE | GENERIC_READ,\r
+                                                FILE_SHARE_WRITE | FILE_SHARE_READ,\r
+                                                NULL,\r
+                                                CONSOLE_TEXTMODE_BUFFER,\r
+                                                NULL\r
+                                                );\r
+  Private->UnixThunk->SetConsoleTitle (WindowName);\r
+#endif
+\r
+  return SimpleTextOut->SetMode (SimpleTextOut, 0);\r
+}\r
+\r
+EFI_STATUS\r
+UnixSimpleTextOutCloseWindow (\r
+  IN OUT  UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Console - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+#if 0
+  Console->UnixThunk->CloseHandle (Console->NtOutHandle);\r
+#endif
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/UnixConsoleDxe/EntryPoint.c b/UnixPkg/UnixConsoleDxe/EntryPoint.c
new file mode 100644 (file)
index 0000000..47f4258
--- /dev/null
@@ -0,0 +1,51 @@
+/**@file\r
+  Entry Point Source file.\r
+\r
+  This file contains the user entry point \r
+\r
+  Copyright (c) 2006 - 2008, 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
+   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
+\r
+\r
+\r
+#include "Console.h"\r
+\r
+/**\r
+  The user Entry Point for module UnixConsole. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixConsole(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gUnixConsoleDriverBinding,\r
+             ImageHandle,\r
+             &gUnixConsoleComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixConsoleDxe/UnixConsole.inf b/UnixPkg/UnixConsoleDxe/UnixConsole.inf
new file mode 100644 (file)
index 0000000..d5c1ed2
--- /dev/null
@@ -0,0 +1,65 @@
+#/** @file\r
+# Console Dxe driver\r
+#\r
+# Simulate console with Unix API\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixConsole\r
+  FILE_GUID                      = f314a8cc-8985-11db-9f69-0040d02b1835\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnixConsole\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gUnixConsoleDriverBinding                    \r
+#  COMPONENT_NAME                =  gUnixConsoleComponentName                    \r
+#\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  ConsoleOut.c\r
+  ConsoleIn.c\r
+  Console.c\r
+  Console.h\r
+  EntryPoint.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Protocols]\r
+  gEfiSimpleTextInProtocolGuid                  # PROTOCOL BY_START\r
+  gEfiSimpleTextOutProtocolGuid                 # PROTOCOL BY_START\r
+  gEfiUnixIoProtocolGuid                        # PROTOCOL TO_START\r
+  gEfiUnixConsoleGuid\r
diff --git a/UnixPkg/UnixConsoleDxe/UnixConsole.msa b/UnixPkg/UnixConsoleDxe/UnixConsole.msa
new file mode 100644 (file)
index 0000000..839eed7
--- /dev/null
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>UnixConsole</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>f314a8cc-8985-11db-9f69-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Console Dxe driver</Abstract>\r
+    <Description>Simulate console with Unix API</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixConsole</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>Console.h</Filename>\r
+    <Filename>Console.c</Filename>\r
+    <Filename>ConsoleIn.c</Filename>\r
+    <Filename>ConsoleOut.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiSimpleTextOutProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixConsoleGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gUnixConsoleDriverBinding</DriverBinding>\r
+      <ComponentName>gUnixConsoleComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixFirmwareVolumePei/UnixFwh.c b/UnixPkg/UnixFirmwareVolumePei/UnixFwh.c
new file mode 100644 (file)
index 0000000..2d3c6a3
--- /dev/null
@@ -0,0 +1,137 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+  UnixFwh.c\r
+    \r
+Abstract:\r
+  PEIM to abstract construction of firmware volume in an Unix environment.\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#include "PiPei.h"\r
+#include <Ppi/UnixFwh.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeUnixFwh (\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
+  UNIX_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, "Unix Firmware Volume PEIM Loaded\n"));\r
+\r
+  //\r
+  // Get the Fwh Information PPI\r
+  //\r
+  Status = (**PeiServices).LocatePpi (\r
+                            PeiServices,\r
+                            &gUnixFwhPpiGuid, // GUID\r
+                            0,              // INSTANCE\r
+                            &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
+                            (VOID **)&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->UnixFwh (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
+          ( \r
+            FvHeader->FvLength + \r
+            PcdGet32 (PcdFlashNvStorageVariableSize) +\r
+            PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +\r
+            PcdGet32 (PcdFlashNvStorageFtwSpareSize) +\r
+            PcdGet32 (PcdUnixFlashNvStorageEventLogSize)\r
+          )\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
+        FdSize  = \r
+          PcdGet32 (PcdFlashNvStorageVariableSize) +\r
+          PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +\r
+          PcdGet32 (PcdFlashNvStorageFtwSpareSize) +\r
+          PcdGet32 (PcdUnixFlashNvStorageEventLogSize);\r
+\r
+        BuildFvHob (FdBase + PcdGet32 (PcdUnixFlashNvStorageVariableBase), 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
diff --git a/UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf b/UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf
new file mode 100644 (file)
index 0000000..126e893
--- /dev/null
@@ -0,0 +1,68 @@
+#/** @file\r
+# Component description file for WinNtFwh module\r
+#\r
+# This PEIM will produce the HOB to describe Firmware Volume, Firmware Devices\r
+#  on the NT32 emulator.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixFwh\r
+  FILE_GUID                      = f40b7864-8985-11db-af21-0040d02b1835\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = PeimInitializeUnixFwh\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  UnixFwh.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  HobLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[FixedPcd.common]\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase\r
+\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+\r
+\r
+[Ppis]\r
+  gUnixFwhPpiGuid                               # PPI ALWAYS_CONSUMED\r
+\r
+\r
+[Depex]\r
+  gUnixFwhPpiGuid AND gEfiPeiMemoryDiscoveredPpiGuid\r
+\r
diff --git a/UnixPkg/UnixFirmwareVolumePei/UnixFwh.msa b/UnixPkg/UnixFirmwareVolumePei/UnixFwh.msa
new file mode 100644 (file)
index 0000000..f46801a
--- /dev/null
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>UnixFwh</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>f40b7864-8985-11db-af21-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for WinNtFwh module</Abstract>\r
+    <Description>This PEIM will produce the HOB to describe Firmware Volume, Firmware Devices\r
+    on the NT32 emulator.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixFwh</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeimEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesTablePointerLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixFwh.c</Filename>\r
+    <Filename>UnixFwh.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_CONSUMED">\r
+      <PpiCName>gUnixFwhPpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>PeimInitializeUnixFwh</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixFlashMapPei/FlashMap.c b/UnixPkg/UnixFlashMapPei/FlashMap.c
new file mode 100644 (file)
index 0000000..9e96ac2
--- /dev/null
@@ -0,0 +1,91 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  FlashMap.c\r
+   \r
+Abstract:\r
+\r
+  PEIM to build GUIDed HOBs for platform specific flash map\r
+\r
+--*/\r
+\r
+\r
+#include "PiPei.h"\r
+\r
+#include <Guid/SystemNvDataGuid.h>\r
+#include <Guid/FirmwareFileSystem.h>\r
+#include <Ppi/UnixFwh.h>\r
+#include <Protocol/FirmwareVolumeBlock.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/PcdLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeFlashMap (\r
+  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
+  IN EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Build GUIDed HOBs for platform specific flash map\r
+  \r
+Arguments:\r
+  FfsHeader   - A pointer to the EFI_FFS_FILE_HEADER structure.\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+  EFI_STATUS\r
+\r
+--*/\r
+// TODO:    EFI_SUCCESS - add return value to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  UNIX_FWH_PPI           *UnixFwhPpi;\r
+  EFI_PEI_PPI_DESCRIPTOR  *PpiDescriptor;\r
+  EFI_PHYSICAL_ADDRESS    FdBase;\r
+  UINT64                  FdSize;\r
+\r
+  DEBUG ((EFI_D_ERROR, "NT 32 Flash Map PEIM Loaded\n"));\r
+\r
+  //\r
+  // Get the Fwh Information PPI\r
+  //\r
+  Status = PeiServicesLocatePpi (\r
+            &gUnixFwhPpiGuid, // GUID\r
+            0,              // INSTANCE\r
+            &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR\r
+            (VOID **)&UnixFwhPpi       // PPI\r
+            );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Assume that FD0 contains the Flash map.\r
+  //\r
+  Status = UnixFwhPpi->UnixFwh (0, &FdBase, &FdSize);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  \r
+  PcdSet32 (PcdFlashNvStorageVariableBase, PcdGet32 (PcdUnixFlashNvStorageVariableBase) + (UINT32) FdBase);\r
+  PcdSet32 (PcdFlashNvStorageFtwWorkingBase, PcdGet32 (PcdUnixFlashNvStorageFtwWorkingBase) + (UINT32) FdBase);\r
+  PcdSet32 (PcdFlashNvStorageFtwSpareBase, PcdGet32 (PcdUnixFlashNvStorageFtwSpareBase) + (UINT32) FdBase);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/UnixFlashMapPei/FlashMap.inf b/UnixPkg/UnixFlashMapPei/FlashMap.inf
new file mode 100644 (file)
index 0000000..56c9196
--- /dev/null
@@ -0,0 +1,82 @@
+#/** @file\r
+# Component description file for FlashMap PEI module\r
+#\r
+# This module installs FlashMap PPI which is used to get flash layout information.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = PeiFlashMap\r
+  FILE_GUID                      = f417814a-8985-11db-8983-0040d02b1835\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = PeimInitializeFlashMap\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  FlashMap.c\r
+\r
+[Packages]\r
+  MdeModulePkg/MdeModulePkg.dec\r
+  MdePkg/MdePkg.dec\r
+  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+[LibraryClasses]\r
+  PcdLib\r
+  BaseMemoryLib\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  HobLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiSystemNvDataHobGuid                       # ALWAYS_CONSUMED\r
+  gEfiFirmwareFileSystemGuid                    # ALWAYS_CONSUMED\r
+  gEfiFlashMapHobGuid                           # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiFirmwareVolumeBlockProtocolGuid           # PROTOCOL ALWAYS_CONSUMED\r
+\r
+\r
+[Ppis]\r
+  gUnixFwhPpiGuid                               # PPI ALWAYS_CONSUMED\r
+  gPeiFlashMapPpiGuid                           # PPI ALWAYS_PRODUCED\r
+\r
+\r
+[Pcd.common]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase\r
+\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwWorkingBase\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwSpareBase\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase\r
+\r
+[Depex]\r
+  gPcdPpiGuid\r
+\r
diff --git a/UnixPkg/UnixFlashMapPei/FlashMap.msa b/UnixPkg/UnixFlashMapPei/FlashMap.msa
new file mode 100644 (file)
index 0000000..7576795
--- /dev/null
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>PeiFlashMap</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>f417814a-8985-11db-8983-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Component description file for FlashMap PEI module</Abstract>\r
+    <Description>This module installs FlashMap PPI which is used to get flash layout information.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>PeiFlashMap</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeimEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesTablePointerLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PcdLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>FlashMap.c</Filename>\r
+    <Filename>FlashMap.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_PRODUCED">\r
+      <PpiCName>gPeiFlashMapPpiGuid</PpiCName>\r
+    </Ppi>\r
+    <Ppi Usage="ALWAYS_CONSUMED">\r
+      <PpiCName>gUnixFwhPpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiFlashMapHobGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiFirmwareFileSystemGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiSystemNvDataHobGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>PeimInitializeFlashMap</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+  <PcdCoded>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdFlashNvStorageVariableBase</C_Name>\r
+      <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>The driver sets the NV Storage FV base address defined by this PCD.  \r
+        This base address point to an EFI_FIRMWARE_VOLUMN_HEADER struct. Variable PEIM\r
+        will get the base address from this PCD. In NT emulator, this PCD is a DYNAMIC\r
+        type, as FD is mapped to process space by WinNT OS. On real platform, it is \r
+        normally a FIXED_AT_BUILD type as system memory map is fixed to BIOS.\r
+      </HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC">\r
+      <C_Name>PcdFlashNvStorageVariableSize</C_Name>\r
+      <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>\r
+        To get the NvStorage Variable size from this PCD.\r
+      </HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdFlashNvStorageFtwSpareBase</C_Name>\r
+      <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>To get base address of the FTW spare block section in NV firmware volume.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdFlashNvStorageFtwSpareSize</C_Name>\r
+      <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>To get size of the FTW spare block section in NV firmware volume.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdFlashNvStorageFtwWorkingBase</C_Name>\r
+      <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>To get base address of the FTW working block section in NV firmware volume.</HelpText>\r
+    </PcdEntry>\r
+    <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">\r
+      <C_Name>PcdFlashNvStorageFtwWorkingSize</C_Name>\r
+      <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>\r
+      <HelpText>To get size of the FTW working block section in NV firmware volume.</HelpText>\r
+    </PcdEntry>\r
+  </PcdCoded>\r
+</ModuleSurfaceArea>\r
diff --git a/UnixPkg/UnixPkg.dec b/UnixPkg/UnixPkg.dec
new file mode 100644 (file)
index 0000000..f351e94
--- /dev/null
@@ -0,0 +1,97 @@
+#/** @file\r
+#\r
+# This is the Unix Emulation Environment Platform\r
+#\r
+# Reference platform implementation using an emulator.\r
+# Copyright (c) 2008, Intel Corporation.\r
+#\r
+#  All rights reserved.\r
+#    This program and the accompanying materials are licensed and made available \r
+#    under the terms and conditions of the BSD License which accompanies this distribution.\r
+#    The full text of the license may be found at http://opensource.org/licenses/bsd-license.php\r
+#    THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES\r
+#    OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+#**/\r
+\r
+[Defines]\r
+  DEC_VERSION                    = 0x00010005\r
+  PACKAGE_NAME                   = EdkUnixPkg\r
+  PACKAGE_GUID                   = f2805c44-8985-11db-9e98-0040d02b1835\r
+  PACKAGE_VERSION                = 0.1\r
+\r
+\r
+[Includes.common]\r
+  Include\r
+\r
+\r
+[LibraryClasses.common]\r
+  UnixLib|Include/Library/UnixLib.h\r
+\r
+\r
+[Protocols.common]\r
+  gEfiUnixIoProtocolGuid         = {0xf2e23f54, 0x8985, 0x11db, {0xac, 0x79, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixUgaIoProtocolGuid      = {0xf2e5e2c6, 0x8985, 0x11db, {0xa1, 0x91, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixThunkProtocolGuid      = {0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+\r
+\r
+[Ppis.common]\r
+  gPeiUnixAutoScanPpiGuid        = {0xf2ed3d14, 0x8985, 0x11db, {0xb0, 0x57, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gUnixFwhPpiGuid                = {0xf2f0dc30, 0x8985, 0x11db, {0xa1, 0x5b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gUnixPeiLoadFilePpiGuid        = {0xf2f48768, 0x8985, 0x11db, {0xb8, 0xda, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gPeiUnixThunkPpiGuid           = {0xf2f830f2, 0x8985, 0x11db, {0x80, 0x6b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+\r
+\r
+[Guids.common]\r
+  gEfiUnixPkgTokenSpaceGuid      = {0xf2b6838c, 0x8985, 0x11db, {0x9d, 0x1c, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixVirtualDisksGuid       = {0xf2ba331a, 0x8985, 0x11db, {0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixPhysicalDisksGuid      = {0xf2bdcc96, 0x8985, 0x11db, {0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixFileSystemGuid         = {0xf2c16b9e, 0x8985, 0x11db, {0x92, 0xc8, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixUgaGuid                = {0xf2c8b80e, 0x8985, 0x11db, {0x93, 0xf1, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixConsoleGuid            = {0xf2cc5d06, 0x8985, 0x11db, {0xbb, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixMemoryGuid             = {0xf2d006cc, 0x8985, 0x11db, {0xa4, 0x72, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixCPUModelGuid           = {0xf2d3b330, 0x8985, 0x11db, {0x8a, 0xa3, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixCPUSpeedGuid           = {0xf2d74e5a, 0x8985, 0x11db, {0x97, 0x05, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}\r
+  gEfiUnixSerialPortGuid         = {0x6d3a727d, 0x66c8, 0x4d19, {0x87, 0xe6, 0x02, 0x15, 0x86, 0x14, 0x90, 0xf3}}\r
+  gEfiFlashMapHobGuid            = {0xb091e7d2, 0x05a0, 0x4198, {0x94, 0xf0, 0x74, 0xb7, 0xb8, 0xc5, 0x54, 0x59}}\r
+\r
+\r
+[PcdsFixedAtBuild.common]\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixBootMode|1|UINT32|0x00001006\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareVolume|L"..\\Fv\\Fv_Recovery.fd"|VOID*|0x00001009\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySizeForSecMain|L"64!64"|VOID*|0x0000100c\r
+  \r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase|0x0|UINT32|0x00001014\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwSpareBase|0x0|UINT32|0x00001015\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwWorkingBase|0x0|UINT32|0x00001016\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFdBaseAddress|0x0|UINT32|0x00001017\r
+\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogBase|0x0|UINT32|0x0000100e\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize|0x0|UINT32|0x0000100f\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoveryBase|0x0|UINT32|0x00001010\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoverySize|0x0|UINT32|0x00001011\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize|0x0|UINT32|0x00001012\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareBlockSize|0|UINT32|0x00001013\r
+\r
+\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize|0x0|UINT32|0x0000100f\r
+\r
+\r
+[PcdsDynamic.common]\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixPhysicalDisk|L"E:RW;245760;512"|VOID*|0x00001000\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixVirtualDisk|L"FW;40960;512"|VOID*|0x00001001\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixUga|L"UGA Window"|VOID*|0x00001003\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFileSystem|L".!..\\..\\..\\..\\..\\EdkShellBinPkg\\bin\\ia32\\Apps"|VOID*|0x00001004\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySize|L"64!64"|VOID*|0x00001005\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuModel|L"Intel(R) Processor Model"|VOID*|0x00001007\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuSpeed|L"3000"|VOID*|0x00001008\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixConsole|L"Bus Driver Console Window"|VOID*|0x0000100a\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixSerialPort|L"/dev/ttyS0"|VOID*|0x00001002\r
+\r
+\r
+[PcdsPatchableInModule.common]\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixBootMode|1|UINT32|0x00001006\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareVolume|L"..\\Fv\\Fv_Recovery.fd"|VOID*|0x00001009\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySizeForSecMain|L"64!64"|VOID*|0x0000100c\r
+\r
+\r
diff --git a/UnixPkg/UnixPkg.dsc b/UnixPkg/UnixPkg.dsc
new file mode 100644 (file)
index 0000000..2ff9efc
--- /dev/null
@@ -0,0 +1,496 @@
+#/** @file\r
+#\r
+# EFI/Framework Emulation Platform with UEFI HII interface supported.\r
+#\r
+# The Emulation Platform can be used to debug individual modules, prior to creating\r
+#       a real platform. This also provides an example for how an FPD is created.\r
+# Copyright (c) 2006 - 2008, Intel Corporation\r
+#\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
+#**/\r
+\r
+################################################################################\r
+#\r
+# Defines Section - statements that will be processed to create a Makefile.\r
+#\r
+################################################################################\r
+[Defines]\r
+  PLATFORM_NAME                  = Unix\r
+  PLATFORM_GUID                  = 7b3c1fb4-8986-11db-b5b2-0040d02b1835\r
+  PLATFORM_VERSION               = 0.3\r
+  DSC_ SPECIFICATION             = 0x00010005\r
+  OUTPUT_DIRECTORY               = Build/Unix\r
+  SUPPORTED_ARCHITECTURES        = IA32\r
+  BUILD_TARGETS                  = DEBUG|RELEASE\r
+  SKUID_IDENTIFIER               = DEFAULT\r
+  FLASH_DEFINITION               = UnixPkg/UnixPkg.fdf\r
+\r
+################################################################################\r
+#\r
+# SKU Identification section - list of all SKU IDs supported by this Platform.\r
+#\r
+################################################################################\r
+[SkuIds]\r
+  0|DEFAULT\r
+\r
+################################################################################\r
+#\r
+# Library Class section - list of all Library Classes needed by this Platform.\r
+#\r
+################################################################################\r
+[LibraryClasses.common]\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf\r
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf\r
+  SerialPortLib|MdePkg/Library/SerialPortLibNull/SerialPortLibNull.inf\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf\r
+  CpuLib|MdePkg/Library/CpuLib/CpuLib.inf\r
+  PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf\r
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
+  PciIncompatibleDeviceSupportLib|IntelFrameworkModulePkg/Library/PciIncompatibleDeviceSupportLib/PciIncompatibleDeviceSupportLib.inf\r
+  CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf\r
+  GraphicsLib|MdeModulePkg/Library/GraphicsLib/GraphicsLib.inf\r
+  FvbServiceLib|MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf\r
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf\r
+  UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf\r
+  HiiLib|MdePkg/Library/HiiLib/HiiLib.inf\r
+  ExtendedHiiLib|MdeModulePkg/Library/ExtendedHiiLib/ExtendedHiiLib.inf\r
+  S3Lib|MdeModulePkg/Library/PeiS3LibNull/PeiS3LibNull.inf\r
+  RecoveryLib|MdeModulePkg/Library/PeiRecoveryLibNull/PeiRecoveryLibNull.inf\r
+  IfrSupportLib|MdePkg/Library/IfrSupportLib/IfrSupportLib.inf\r
+  ExtendedIfrSupportLib|MdeModulePkg/Library/ExtendedIfrSupportLib/ExtendedIfrSupportLib.inf\r
+  GenericBdsLib|MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf\r
+  PlatformBdsLib|UnixPkg/Library/UnixBdsLib/PlatformBds.inf\r
+  CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf\r
+  DxePiLib|MdePkg/Library/DxePiLib/DxePiLib.inf\r
+  PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf\r
+\r
+[LibraryClasses.common.BASE]\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/BaseReportStatusCodeLib/BaseReportStatusCodeLib.inf\r
+\r
+[LibraryClasses.common.USER_DEFINED]\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/BaseReportStatusCodeLib/BaseReportStatusCodeLib.inf\r
+\r
+[LibraryClasses.common.SEC]\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/BaseReportStatusCodeLib/BaseReportStatusCodeLib.inf\r
+  PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf\r
+\r
+[LibraryClasses.common.DXE_CORE]\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf\r
+  DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf\r
+  MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  PeCoffLib|UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf\r
+  ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf\r
+\r
+[LibraryClasses.common.DXE_SMM_DRIVER]\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf\r
+\r
+[LibraryClasses.common.PEIM]\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
+  PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf\r
+  IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf\r
+  PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf\r
+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
+  PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
+  OemHookStatusCodeLib|UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf\r
+  PeCoffGetEntryPointLib|UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf\r
+  DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+  PeCoffLib|UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf\r
+  PeiPiLib|MdePkg/Library/PeiPiLib/PeiPiLib.inf\r
+  ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf\r
+\r
+[LibraryClasses.common.PEI_CORE]\r
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf\r
+  HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf\r
+  PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf\r
+  IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf\r
+  PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf\r
+  PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf\r
+  OemHookStatusCodeLib|IntelFrameworkModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf\r
+  PeCoffGetEntryPointLib|UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf\r
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+  PeCoffLib|UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf\r
+  PeiPiLib|MdePkg/Library/PeiPiLib/PeiPiLib.inf\r
+\r
+[LibraryClasses.common.DXE_RUNTIME_DRIVER]\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf\r
+  ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
+  UnixLib|UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf\r
+  OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf\r
+  DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+\r
+[LibraryClasses.common.UEFI_DRIVER]\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
+  UnixLib|UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf\r
+  OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf\r
+  DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+\r
+[LibraryClasses.common.DXE_DRIVER]\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
+  UnixLib|UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf\r
+  OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf\r
+  DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+  NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf\r
+  IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf\r
+  UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf\r
+  DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf\r
+\r
+[LibraryClasses.common.UEFI_APPLICATION]\r
+  DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf\r
+  ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf\r
+  UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf\r
+  UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf\r
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf\r
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf\r
+  PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf\r
+  MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf\r
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf\r
+  ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf\r
+  UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf\r
+  UnixLib|UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf\r
+  OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf\r
+  DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf\r
+  PrintLib|MdeModulePkg/Library/EdkDxePrintLib/EdkDxePrintLib.inf\r
+\r
+################################################################################\r
+#\r
+# Pcd Section - list of all EDK II PCD Entries defined by this Platform.\r
+#\r
+################################################################################\r
+[PcdsFixedAtBuild.IA32]\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeRuntimeMemorySize|128\r
+\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase|0x280000\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwSpareBase|0x290000\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwWorkingBase|0x28e000\r
+\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixBootMode|1\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize|0x2a0000\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareBlockSize|0x10000\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogBase|0x28c000\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize|0x2000\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoveryBase|0x0\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoverySize|0x280000\r
+  \r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySizeForSecMain|L"64!64"|VOID*|10\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareVolume|L"../FV/FV_RECOVERY.fd"|VOID*|52\r
+\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000\r
+  gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x0f\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x1f\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF\r
+  gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000040\r
+  gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPcdCallBackNumberPerPcdEntry|0x08\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizeNonPopulateCapsule|0x0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizePopulateCapsule|0x0\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciIncompatibleDeviceSupportMask|0\r
+  gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueUncorrectableMemoryError|0x0005100   # EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE3\r
+  gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueRemoteConsoleError|0x01040006        # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_CONTROLLER_ERROR\r
+  gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueRemoteConsoleReset|0x01040001        # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_PC_RESET\r
+  gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueRemoteConsoleInputError|0x01040007   # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_INPUT_ERROR\r
+  gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueRemoteConsoleOutputError|0x01040008  # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_OUTPUT_ERROR\r
+  gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultTimeout|0x0008\r
+  gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueEfiWatchDogTimerExpired|0x00011003\r
+  gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueMemoryTestStarted|0x00051006\r
+  gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueSetVirtualAddressMap|0x03101004\r
+  gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueUncorrectableMemoryError|0x00051003\r
+  gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits|8\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity|1\r
+  gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits|1\r
+  gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|0\r
+\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x10000\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x2000\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00c000\r
+  gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x10\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize|0x8000\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x10000\r
+\r
+[PcdsFeatureFlag.common]\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseTraverseEnabled|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseCallbackOnSetEnabled|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseExEnabled|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseGetSizeEnabled|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseSetEnabled|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseOEM|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplSupportEfiDecompress|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplSupportTianoDecompress|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplSupportCustomDecompress|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplBuildShareCodeHobs|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdDxePcdDatabaseTraverseEnabled|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseHardSerial|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseEfiSerial|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseRuntimeMemory|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseDataHub|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInSerial|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInDataHub|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInRuntimeMemory|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInOEM|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleRest|FALSE\r
+  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|FALSE\r
+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdNtEmulatorEnable|FALSE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText|TRUE\r
+  gEfiEdkModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText|TRUE\r
+  gEfiGenericPlatformTokenSpaceGuid.PcdPciIsaEnable|FALSE\r
+  gEfiGenericPlatformTokenSpaceGuid.PcdPciVgaEnable|FALSE\r
+  gEfiGenericPlatformTokenSpaceGuid.PcdPciBusHotplugDeviceSupport|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE\r
+  #gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|FALSE\r
+  \r
+[PcdsFeatureFlag.IA32]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseTraverseEnabled|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseCallbackOnSetEnabled|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseExEnabled|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseGetSizeEnabled|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseSetEnabled|TRUE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseOEM|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|FALSE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplEnableIdt|FALSE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportEfiDecompress|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportTianoDecompress|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportCustomDecompress|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildShareCodeHobs|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDxePcdDatabaseTraverseEnabled|TRUE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseHardSerial|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseEfiSerial|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseRuntimeMemory|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseDataHub|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseOEM|TRUE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInSerial|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInDataHub|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInRuntimeMemory|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInOEM|FALSE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleRest|FALSE\r
+  gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|FALSE\r
+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|FALSE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdNtEmulatorEnable|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText|TRUE\r
+  gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|FALSE\r
+  gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|FALSE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleRest|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciIsaEnable|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciVgaEnable|FALSE\r
+  gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciBusHotplugDeviceSupport|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst|FALSE\r
+\r
+################################################################################\r
+#\r
+# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform\r
+#\r
+################################################################################\r
+\r
+[PcdsDynamicDefault.common.DEFAULT]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0\r
+  gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0|UINT32|4\r
+  gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x0|UINT32|4\r
+  gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0|UINT32|4\r
+  gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x0|UINT32|4\r
+  gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0|UINT32|4\r
+  gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x0|UINT32|4\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixConsole|L"Bus Driver Console Window"|VOID*|50\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixUga|L"UGA Window"|VOID*|50\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixFileSystem|L".!../../../../EdkShellBinPkg/bin/ia32/Apps"|VOID*|106\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixVirtualDisk|L"disk1.img:FW"|VOID*|24\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixPhysicalDisk|L"E:RW;245760;512"|VOID*|30\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuModel|L"Intel(R) Processor Model"|VOID*|48\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuSpeed|L"3000"|VOID*|8\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySize|L"64!64"|VOID*|10\r
+  gEfiUnixPkgTokenSpaceGuid.PcdUnixSerialPort|L"/dev/ttyS0!/dev/ttyS1"|VOID*|20\r
+\r
+################################################################################\r
+#\r
+# Components Section - list of all EDK II Modules needed by this Platform.\r
+#\r
+################################################################################\r
+[Components.IA32]\r
+  ##\r
+  #  SEC Phase modules\r
+  ##\r
+  UnixPkg/Sec/SecMain.inf\r
+\r
+  ##\r
+  #  PEI Phase modules\r
+  ##\r
+  MdeModulePkg/Core/Pei/PeiMain.inf\r
+  MdeModulePkg/Universal/PCD/Pei/Pcd.inf  {\r
+   <LibraryClasses>\r
+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  }\r
+  IntelFrameworkModulePkg/Universal/StatusCode/Pei/PeiStatusCode.inf\r
+  UnixPkg/BootModePei/BootModePei.inf\r
+  UnixPkg/UnixFlashMapPei/FlashMap.inf\r
+  MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTestPei.inf\r
+  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
+  UnixPkg/UnixAutoScanPei/UnixAutoScan.inf\r
+  UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf\r
+  UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf\r
+  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
+  \r
+  ##\r
+  #  DXE Phase modules\r
+  ##\r
+  MdeModulePkg/Core/Dxe/DxeMain.inf {\r
+    <LibraryClasses>\r
+      NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf\r
+  }\r
+  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf {\r
+    <LibraryClasses>\r
+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  }\r
+\r
+  UnixPkg/MetronomeDxe/Metronome.inf\r
+  UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf\r
+  UnixPkg/ResetRuntimeDxe/Reset.inf\r
+  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+  UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf\r
+  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+  IntelFrameworkModulePkg/Universal/DataHubDxe/DataHubDxe.inf\r
+  MdeModulePkg/Universal/EbcDxe/EbcDxe.inf\r
+  MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf\r
+  UnixPkg/UnixThunkDxe/UnixThunk.inf\r
+  UnixPkg/CpuRuntimeDxe/Cpu.inf\r
+  MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.inf\r
+  IntelFrameworkModulePkg/Universal/DataHubStdErrDxe/DataHubStdErrDxe.inf\r
+  UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf\r
+  UnixPkg/TimerDxe/Timer.inf\r
+  IntelFrameworkModulePkg/Universal/StatusCode/Dxe/DxeStatusCode.inf\r
+  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf\r
+  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf\r
+  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf\r
+  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf\r
+  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf\r
+  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf\r
+  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf\r
+  MdeModulePkg/Universal/BdsDxe/BdsDxe.inf\r
+  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+  IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf\r
+  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf\r
+  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf\r
+  IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf\r
+  UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf\r
\r
+  UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf\r
+  UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf\r
+  UnixPkg/UnixUgaDxe/UnixUga.inf\r
+  UnixPkg/UnixConsoleDxe/UnixConsole.inf\r
+  UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf\r
+  MdeModulePkg/Application/HelloWorld/HelloWorld.inf\r
+\r
+  #\r
+  # Network stack drivers\r
+  # To test network drivers, need network Io driver(SnpNt32Io.dll), please refer to NETWORK-IO Subproject.\r
+  #\r
+  MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf\r
+  MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf\r
+  MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf\r
+  MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf\r
+  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf\r
+  MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf\r
+  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf\r
+  MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf\r
+  MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf\r
+\r
+  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf\r
+  MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf\r
+  MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf {\r
+    <LibraryClasses>\r
+      PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf\r
+  }\r
+\r
+[BuildOptions]\r
+  #DEBUG_*_IA32_DLINK_FLAGS = --shared\r
+  *_*_IA32_CC_FLAGS = -idirafter/usr/include\r
diff --git a/UnixPkg/UnixPkg.fdf b/UnixPkg/UnixPkg.fdf
new file mode 100644 (file)
index 0000000..945c7ef
--- /dev/null
@@ -0,0 +1,376 @@
+# This is Unix FDF file with UEFI HII features enabled\r
+#\r
+# Copyright (c) 2008, Intel Corporation\r
+#\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
+\r
+################################################################################\r
+#\r
+# FD Section\r
+# The [FD] Section is made up of the definition statements and a\r
+# description of what goes into  the Flash Device Image.  Each FD section\r
+# defines one flash "device" image.  A flash device image may be one of\r
+# the following: Removable media bootable image (like a boot floppy\r
+# image,) an Option ROM image (that would be "flashed" into an add-in\r
+# card,) a System "Flash"  image (that would be burned into a system's\r
+# flash) or an Update ("Capsule") image that will be used to update and\r
+# existing system flash.\r
+#\r
+################################################################################\r
+[FD.Fv_Recovery]\r
+BaseAddress   = 0x0|gEfiUnixPkgTokenSpaceGuid.PcdUnixFdBaseAddress  #The base address of the FLASH Device.\r
+Size          = 0x002a0000                                           #The size in bytes of the FLASH Device\r
+ErasePolarity = 1\r
+BlockSize     = 0x10000\r
+NumBlocks     = 0x2a\r
+\r
+################################################################################\r
+#\r
+# Following are lists of FD Region layout which correspond to the locations of different\r
+# images within the flash device.\r
+#\r
+# Regions must be defined in ascending order and may not overlap.\r
+#\r
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by\r
+# the pipe "|" character, followed by the size of the region, also in hex with the leading\r
+# "0x" characters. Like:\r
+# Offset|Size\r
+# PcdOffsetCName|PcdSizeCName\r
+# RegionType <FV, DATA, or FILE>\r
+#\r
+################################################################################\r
+0x00000000|0x00280000\r
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoveryBase|gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoverySize\r
+FV = FvRecovery\r
+\r
+0x00280000|0x0000c000\r
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize\r
+#NV_VARIABLE_STORE\r
+DATA = {\r
+  ## This is the EFI_FIRMWARE_VOLUME_HEADER\r
+  # ZeroVector []\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  # FileSystemGuid: gEfiSystemNvDataFvGuid         =\r
+  #  { 0xFFF12B8D, 0x7696, 0x4C8B, { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }}\r
+  0x8D, 0x2B, 0xF1, 0xFF, 0x96, 0x76, 0x8B, 0x4C,\r
+  0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50,\r
+  # FvLength: 0x20000\r
+  0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  # Signature "_FVH"       #Attributes\r
+  0x5f, 0x46, 0x56, 0x48, 0xff, 0xfe, 0x04, 0x00,\r
+  # HeaderLength #CheckSum #ExtHeaderOffset #Reserved #Revision\r
+  0x48, 0x00, 0x36, 0x09, 0x00, 0x00, 0x00, 0x02,\r
+  # Blockmap[0]: 2 Blocks * 0x10000 Bytes / Block\r
+  0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,\r
+  # Blockmap[1]: End\r
+  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
+  ## This is the VARIABLE_STORE_HEADER\r
+  #Signature: "$VSS"      #Size: 0xc000 (gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize) - 0x48 (HeaderLength) = 0xBFB8\r
+                          # This can speed up the Variable Dispatch a bit.\r
+  0x24, 0x56, 0x53, 0x53, 0xB8, 0xBF, 0x00, 0x00,\r
+  #FORMATTED: 0x5A #HEALTHY: 0xFE #Reserved: UINT16 #Reserved1: UINT32\r
+  0x5A, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00\r
+}\r
+\r
+0x0028c000|0x00002000\r
+#NV_EVENT_LOG\r
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogBase|gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize\r
+\r
+0x0028e000|0x00002000\r
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwWorkingBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize\r
+#NV_FTW_WORKING\r
+DATA = {\r
+  # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature = gEfiSystemNvDataFvGuid         =\r
+  #  { 0xFFF12B8D, 0x7696, 0x4C8B, { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }}\r
+  0x8D, 0x2B, 0xF1, 0xFF, 0x96, 0x76, 0x8B, 0x4C,\r
+  0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50,\r
+  # Crc:UINT32            #WorkingBlockValid:1, WorkingBlockInvalid:1, Reserved\r
+  0x85, 0xae, 0x2d, 0xbf, 0xFE, 0xFF, 0xFF, 0xFF,\r
+  # WriteQueueSize: UINT32\r
+  0xE4, 0x1F, 0x00, 0x00\r
+}\r
+\r
+0x00290000|0x00010000\r
+#NV_FTW_SPARE\r
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwSpareBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize\r
+\r
+################################################################################\r
+#\r
+# FV Section\r
+#\r
+# [FV] section is used to define what components or modules are placed within a flash\r
+# device file.  This section also defines order the components and modules are positioned\r
+# within the image.  The [FV] section consists of define statements, set statements and\r
+# module statements.\r
+#\r
+################################################################################\r
+[FV.FvRecovery]\r
+FvAlignment        = 16         #FV alignment and FV attributes setting.\r
+ERASE_POLARITY     = 1\r
+MEMORY_MAPPED      = TRUE\r
+STICKY_WRITE       = TRUE\r
+LOCK_CAP           = TRUE\r
+LOCK_STATUS        = TRUE\r
+WRITE_DISABLED_CAP = TRUE\r
+WRITE_ENABLED_CAP  = TRUE\r
+WRITE_STATUS       = TRUE\r
+WRITE_LOCK_CAP     = TRUE\r
+WRITE_LOCK_STATUS  = TRUE\r
+READ_DISABLED_CAP  = TRUE\r
+READ_ENABLED_CAP   = TRUE\r
+READ_STATUS        = TRUE\r
+READ_LOCK_CAP      = TRUE\r
+READ_LOCK_STATUS   = TRUE\r
+\r
+################################################################################\r
+#\r
+# The INF statements point to EDK component and EDK II module INF files, which will be placed into this FV image.\r
+# Parsing tools will scan the INF file to determine the type of component or module.\r
+# The component or module type is used to reference the standard rules\r
+# defined elsewhere in the FDF file.\r
+#\r
+# The format for INF statements is:\r
+# INF $(PathAndInfFileName)\r
+#\r
+################################################################################\r
+##\r
+#  PEI Phase modules\r
+##\r
+##\r
+#  PEI Apriori file example, more PEIM module added later.\r
+##\r
+APRIORI PEI {\r
+  INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf\r
+  INF  IntelFrameworkModulePkg/Universal/StatusCode/Pei/PeiStatusCode.inf\r
+  }\r
+APRIORI DXE {\r
+  INF  IntelFrameworkModulePkg/Universal/StatusCode/Dxe/DxeStatusCode.inf\r
+  INF  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf\r
+  INF  UnixPkg/MetronomeDxe/Metronome.inf\r
+  }\r
+INF  MdeModulePkg/Core/Pei/PeiMain.inf\r
+INF  MdeModulePkg/Universal/PCD/Pei/Pcd.inf\r
+INF  IntelFrameworkModulePkg/Universal/StatusCode/Pei/PeiStatusCode.inf\r
+INF  UnixPkg/BootModePei/BootModePei.inf\r
+INF  UnixPkg/UnixFlashMapPei/FlashMap.inf\r
+INF  MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTestPei.inf\r
+INF  UnixPkg/UnixAutoScanPei/UnixAutoScan.inf\r
+INF  UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf\r
+INF  MdeModulePkg/Universal/Variable/Pei/VariablePei.inf\r
+INF  UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf\r
+INF  MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf\r
+\r
+##\r
+#  DXE Phase modules\r
+##\r
+INF  MdeModulePkg/Core/Dxe/DxeMain.inf\r
+INF  IntelFrameworkModulePkg/Universal/StatusCode/Dxe/DxeStatusCode.inf\r
+INF  MdeModulePkg/Universal/PCD/Dxe/Pcd.inf\r
+INF  UnixPkg/MetronomeDxe/Metronome.inf\r
+INF  UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf\r
+INF  UnixPkg/ResetRuntimeDxe/Reset.inf\r
+INF  MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf\r
+INF  UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf\r
+INF  MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf\r
+INF  IntelFrameworkModulePkg/Universal/DataHubDxe/DataHubDxe.inf\r
+INF  MdeModulePkg/Universal/EbcDxe/EbcDxe.inf\r
+INF  MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf\r
+INF  UnixPkg/UnixThunkDxe/UnixThunk.inf\r
+INF  UnixPkg/CpuRuntimeDxe/Cpu.inf\r
+INF  MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.inf\r
+INF  IntelFrameworkModulePkg/Universal/DataHubStdErrDxe/DataHubStdErrDxe.inf\r
+INF  UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf\r
+INF  UnixPkg/TimerDxe/Timer.inf\r
+INF  MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf\r
+INF  MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf\r
+INF  MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf\r
+INF  MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf\r
+INF  MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf\r
+INF  MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf\r
+INF  MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf\r
+INF  MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf\r
+INF  MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf\r
+INF  MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf\r
+INF  MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf\r
+INF  MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf\r
+INF  IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf\r
+INF  MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf\r
+INF  MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf\r
+INF  IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf\r
+INF  UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf\r
\r
+INF  UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf\r
+INF  UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf\r
+INF  UnixPkg/UnixUgaDxe/UnixUga.inf\r
+INF  UnixPkg/UnixConsoleDxe/UnixConsole.inf\r
+INF  MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf\r
+INF  MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf  \r
+INF  MdeModulePkg/Universal/BdsDxe/BdsDxe.inf \r
+INF  UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf\r
+INF  MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf\r
+INF  MdeModulePkg/Application/HelloWorld/HelloWorld.inf\r
+\r
+#\r
+# Network stack drivers\r
+# To test network drivers, need network Io driver(SnpNt32Io.dll), please refer to NETWORK-IO Subproject.\r
+#\r
+#INF  MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf\r
+#INF  MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf\r
+#INF  MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf\r
+#INF  MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf\r
+#INF  MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf\r
+#INF  MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf\r
+#INF  MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf\r
+#INF  MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf\r
+#INF  MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf\r
+#INF  UnixPkg/SnpUnixDxe/SnpUnixDxe.inf\r
+\r
+\r
+   \r
+################################################################################\r
+#  \r
+# FILE statements are provided so that a platform integrator can include\r
+# complete EFI FFS files, as well as a method for constructing FFS files\r
+# using curly "{}" brace scoping. The following three FILEs are\r
+# for binary shell, binary fat and logo module.\r
+#  \r
+################################################################################\r
+FILE APPLICATION = c57ad6b7-0515-40a8-9d21-551652854e37 {\r
+    SECTION COMPRESS PI_STD {\r
+      SECTION GUIDED {\r
+        SECTION PE32 = EdkShellBinPkg/FullShell/ia32/Shell_Full.efi\r
+      }\r
+    }\r
+  }\r
+FILE DRIVER = 961578FE-B6B7-44c3-AF35-6BC705CD2B1F {\r
+    SECTION COMPRESS PI_STD {\r
+      SECTION GUIDED {\r
+        SECTION PE32 = FatBinPkg/EnhancedFatDxe/Ia32/Fat.efi\r
+      }\r
+    }\r
+  }\r
+FILE FREEFORM = 7BB28B99-61BB-11D5-9A5D-0090273FC14D {\r
+    SECTION COMPRESS PI_STD {\r
+      SECTION GUIDED {\r
+        SECTION RAW = MdeModulePkg/Logo/Logo.bmp\r
+      }\r
+    }\r
+  }\r
+   \r
+   \r
+################################################################################\r
+#  \r
+# Rules are use with the [FV] section's module INF type to define\r
+# how an FFS file is created for a given INF file. The following Rule are the default\r
+# rules for the different module type. User can add the customized rules to define the\r
+# content of the FFS file.\r
+#  \r
+################################################################################\r
+   \r
+   \r
+############################################################################\r
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section   # \r
+############################################################################\r
+#  \r
+#[Rule.Common.DXE_DRIVER]\r
+#  FILE DRIVER = $(NAMED_GUID) {\r
+#    DXE_DEPEX    DXE_DEPEX Optional      |.depex\r
+#    COMPRESS PI_STD {\r
+#      GUIDED {\r
+#        PE32     PE32                    |.efi\r
+#        UI       STRING="$(MODULE_NAME)" Optional\r
+#        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+#      }\r
+#    }\r
+#  }\r
+#\r
+############################################################################\r
+\r
+[Rule.Common.PEI_CORE]\r
+  FILE PEI_CORE = $(NAMED_GUID) {\r
+    PE32     PE32           |.efi\r
+    UI       STRING ="$(MODULE_NAME)" Optional         \r
+    VERSION  STRING ="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)    \r
+  }\r
+\r
+[Rule.Common.PEIM]\r
+  FILE PEIM = $(NAMED_GUID) {\r
+     PEI_DEPEX PEI_DEPEX Optional        |.depex\r
+     PE32      PE32                      |.efi\r
+     UI       STRING="$(MODULE_NAME)" Optional         \r
+     VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)   \r
+  }\r
+\r
+[Rule.Common.PEIM.TIANOCOMPRESSED]\r
+  FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {\r
+    PEI_DEPEX PEI_DEPEX Optional         |.depex\r
+    GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {\r
+      PE32      PE32                     |.efi\r
+      UI        STRING="$(MODULE_NAME)" Optional\r
+      VERSION   STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_CORE]\r
+  FILE DXE_CORE = $(NAMED_GUID) {\r
+    COMPRESS PI_STD {\r
+      PE32     PE32           |.efi\r
+      UI       STRING="$(MODULE_NAME)" Optional\r
+      VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+    }\r
+  }\r
+\r
+[Rule.Common.UEFI_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX Optional      |.depex\r
+    COMPRESS PI_STD {\r
+      GUIDED {\r
+        PE32     PE32                    |.efi\r
+        UI       STRING="$(MODULE_NAME)" Optional\r
+        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+      }\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX Optional      |.depex\r
+    COMPRESS PI_STD {\r
+      GUIDED {\r
+        PE32     PE32                    |.efi\r
+        UI       STRING="$(MODULE_NAME)" Optional\r
+        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+      }\r
+    }\r
+  }\r
+\r
+[Rule.Common.DXE_RUNTIME_DRIVER]\r
+  FILE DRIVER = $(NAMED_GUID) {\r
+    DXE_DEPEX    DXE_DEPEX Optional      |.depex\r
+    COMPRESS PI_STD {\r
+      GUIDED {\r
+        PE32     PE32                    |.efi\r
+        UI       STRING="$(MODULE_NAME)" Optional\r
+        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+      }\r
+    }\r
+  }\r
+\r
+[Rule.Common.UEFI_APPLICATION]\r
+  FILE APPLICATION = $(NAMED_GUID) {\r
+    COMPRESS PI_STD {\r
+      GUIDED {\r
+        PE32     PE32                    |.efi\r
+        UI       STRING="$(MODULE_NAME)" Optional\r
+        VERSION  STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)\r
+      }\r
+    }\r
+  }\r
diff --git a/UnixPkg/UnixSerialIoDxe/ComponentName.c b/UnixPkg/UnixSerialIoDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..2b7cb92
--- /dev/null
@@ -0,0 +1,208 @@
+/*++\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
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include "UnixSerialIo.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gUnixSerialIoComponentName = {\r
+  UnixSerialIoComponentNameGetDriverName,\r
+  UnixSerialIoComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mUnixSerialIoDriverNameTable[] = {\r
+  { "eng", L"Unix Serial I/O Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixSerialIoComponentName.SupportedLanguages,\r
+          mUnixSerialIoDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the \r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing \r
+                            the controller specified by ControllerHandle and \r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  EFI_SERIAL_IO_PROTOCOL        *SerialIo;\r
+  UNIX_SERIAL_IO_PRIVATE_DATA *Private;\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gUnixSerialIoDriverBinding.DriverBindingHandle,\r
+             &gEfiUnixIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // This is a bus driver, so ChildHandle must not be NULL.\r
+  //\r
+  if (ChildHandle == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Status = EfiTestChildHandle (\r
+             ControllerHandle,\r
+             ChildHandle,\r
+             &gEfiUnixIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ChildHandle,\r
+                  &gEfiSerialIoProtocolGuid,\r
+                  (VOID**)&SerialIo,\r
+                  gUnixSerialIoDriverBinding.DriverBindingHandle,\r
+                  ChildHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (SerialIo);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixSerialIoComponentName.SupportedLanguages,\r
+          Private->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
diff --git a/UnixPkg/UnixSerialIoDxe/EntryPoint.c b/UnixPkg/UnixSerialIoDxe/EntryPoint.c
new file mode 100644 (file)
index 0000000..8f2b575
--- /dev/null
@@ -0,0 +1,49 @@
+/**@file\r
+  Entry Point Source file.\r
+\r
+  This file contains the user entry point \r
+\r
+  Copyright (c) 2006 - 2008, 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
+   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
+\r
+#include "UnixSerialIo.h"\r
+\r
+/**\r
+  The user Entry Point for module UnixSerialIo. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixSerialIo(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gUnixSerialIoDriverBinding,\r
+             ImageHandle,\r
+             &gUnixSerialIoComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c
new file mode 100644 (file)
index 0000000..9f550f2
--- /dev/null
@@ -0,0 +1,1487 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, 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
+\r
+  UnixSerialIo.c\r
+\r
+Abstract:\r
+\r
+  Our DriverBinding member functions operate on the handles\r
+  created by the NT Bus driver.\r
+\r
+  Handle(1) - UnixIo - DevicePath(1)\r
+\r
+  If a serial port is added to the system this driver creates a new handle.\r
+  The new handle is required, since the serial device must add an UART device\r
+  pathnode.\r
+\r
+  Handle(2) - SerialIo - DevicePath(1)\UART\r
+\r
+  The driver then adds a gEfiUnixSerialPortGuid as a protocol to Handle(1).\r
+  The instance data for this protocol is the private data used to create\r
+  Handle(2).\r
+\r
+  Handle(1) - UnixIo - DevicePath(1) - UnixSerialPort\r
+\r
+  If the driver is unloaded Handle(2) is removed from the system and\r
+  gEfiUnixSerialPortGuid is removed from Handle(1).\r
+\r
+  Note: Handle(1) is any handle created by the Win NT Bus driver that is passed\r
+  into the DriverBinding member functions of this driver. This driver requires\r
+  a Handle(1) to contain a UnixIo protocol, a DevicePath protocol, and\r
+  the TypeGuid in the UnixIo must be gEfiUnixSerialPortGuid.\r
+\r
+  If Handle(1) contains a gEfiUnixSerialPortGuid protocol then the driver is\r
+  loaded on the device.\r
+\r
+--*/\r
+\r
+#include "UnixSerialIo.h"\r
+#include <termio.h>\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding = {\r
+  UnixSerialIoDriverBindingSupported,\r
+  UnixSerialIoDriverBindingStart,\r
+  UnixSerialIoDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+STATIC\r
+UINTN\r
+ConvertBaud2Unix (\r
+  UINT64 BaudRate\r
+  )\r
+{\r
+  switch (BaudRate) {\r
+  case 0:\r
+    return B0;\r
+  case 50:\r
+    return B50;\r
+  case 75:\r
+    return B75;\r
+  case 110:\r
+    return B110;\r
+  case 134:\r
+    return B134;\r
+  case 150:\r
+    return B150;\r
+  case 200:\r
+    return B200;\r
+  case 300:\r
+    return B300;\r
+  case 600:\r
+    return B600;\r
+  case 1200:\r
+    return B1200;\r
+  case 1800:\r
+    return B1800;\r
+  case 2400:\r
+    return B2400;\r
+  case 4800:\r
+    return B4800;\r
+  case 9600:\r
+    return B9600;\r
+  case 19200:\r
+    return B19200;\r
+  case 38400:\r
+    return B38400;\r
+  case 57600:\r
+    return B57600;\r
+  case 115200:\r
+    return B115200;\r
+  case 230400:\r
+    return B230400;\r
+  case 460800:\r
+    return B460800;\r
+  case 500000:\r
+    return B500000;\r
+  case 576000:\r
+    return B576000;\r
+  case 921600:\r
+    return B921600;\r
+  case 1000000:\r
+    return B1000000;\r
+  case 1152000:\r
+    return B1152000;\r
+  case 1500000:\r
+    return B1500000;\r
+  case 2000000:\r
+    return B2000000;\r
+  case 2500000:\r
+    return B2500000;\r
+  case 3000000:\r
+    return B3000000;\r
+  case 3500000:\r
+    return B3500000;\r
+  case 4000000:\r
+    return B4000000;\r
+  case __MAX_BAUD:\r
+  default:\r
+    DEBUG ((EFI_D_ERROR, "Invalid Baud Rate Parameter!\r\n"));\r
+  }\r
+  return -1;\r
+}\r
+\r
+STATIC\r
+UINTN\r
+ConvertByteSize2Unix (\r
+  UINT8 DataBit\r
+  )\r
+{\r
+  switch (DataBit) {\r
+  case 5:\r
+    return CS5;\r
+  case 6:\r
+    return CS6;\r
+  case 7:\r
+    return CS7;\r
+  case 8:\r
+    return CS8;\r
+  default:\r
+    DEBUG ((EFI_D_ERROR, "Invalid Data Size Parameter!\r\n"));\r
+  }\r
+  return -1;\r
+}\r
+\r
+STATIC\r
+VOID\r
+ConvertParity2Unix (\r
+  struct termios    *Options,\r
+  EFI_PARITY_TYPE   Parity\r
+  )\r
+{\r
+  switch (Parity) {\r
+  case NoParity:\r
+    Options->c_cflag &= ~PARENB;\r
+    break;\r
+  case EvenParity:\r
+    Options->c_cflag |= PARENB;\r
+    break;\r
+  case OddParity:\r
+    Options->c_cflag |= PARENB;\r
+    Options->c_cflag |= PARODD;\r
+    break;\r
+  case MarkParity:\r
+    Options->c_cflag = PARENB | CMSPAR | PARODD;\r
+    break;\r
+  case SpaceParity:\r
+    Options->c_cflag |= PARENB | CMSPAR;\r
+    Options->c_cflag &= ~PARODD;\r
+    break;\r
+  default:\r
+    DEBUG ((EFI_D_ERROR, "Invalid Parity Parameter!\r\n"));\r
+  }\r
+}\r
+\r
+STATIC \r
+VOID\r
+ConvertStopBit2Unix (\r
+  struct termios      *Options,\r
+  EFI_STOP_BITS_TYPE  StopBits\r
+  )\r
+{\r
+  switch (StopBits) {\r
+  case TwoStopBits:\r
+    Options->c_cflag |= CSTOPB;\r
+    break;\r
+  case OneStopBit:\r
+  case OneFiveStopBits:\r
+  case DefaultStopBits:\r
+    Options->c_cflag &= ~CSTOPB;\r
+  }\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  The implementation of EFI_DRIVER_BINDING_PROTOCOL.EFI_DRIVER_BINDING_SUPPORTED.\r
+\r
+Arguments:\r
+  \r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  EFI_UNIX_IO_PROTOCOL      *UnixIo;\r
+  UART_DEVICE_PATH          *UartNode;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID**)&ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiDevicePathProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID**)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure that the Unix Thunk Protocol is valid\r
+  //\r
+  if (UnixIo->UnixThunk->Signature != EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // Check the GUID to see if this is a handle type the driver supports\r
+  //\r
+  if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixSerialPortGuid)) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Error;\r
+  }\r
+\r
+  if (RemainingDevicePath != NULL) {\r
+    Status    = EFI_UNSUPPORTED;\r
+    UartNode  = (UART_DEVICE_PATH *) RemainingDevicePath;\r
+    if (UartNode->Header.Type != MESSAGING_DEVICE_PATH ||\r
+        UartNode->Header.SubType != MSG_UART_DP ||\r
+        DevicePathNodeLength((EFI_DEVICE_PATH_PROTOCOL *)UartNode) != sizeof(UART_DEVICE_PATH)) {\r
+      goto Error;\r
+    }\r
+    if (UartNode->BaudRate < 0 || UartNode->BaudRate > SERIAL_PORT_MAX_BAUD_RATE) {\r
+      goto Error;\r
+    }\r
+    if (UartNode->Parity < NoParity || UartNode->Parity > SpaceParity) {\r
+      goto Error;\r
+    }\r
+    if (UartNode->DataBits < 5 || UartNode->DataBits > 8) {\r
+      goto Error;\r
+    }\r
+    if (UartNode->StopBits < OneStopBit || UartNode->StopBits > TwoStopBits) {\r
+      goto Error;\r
+    }\r
+    if ((UartNode->DataBits == 5) && (UartNode->StopBits == TwoStopBits)) {\r
+      goto Error;\r
+    }\r
+    if ((UartNode->DataBits >= 6) && (UartNode->DataBits <= 8) && (UartNode->StopBits == OneFiveStopBits)) {\r
+      goto Error;\r
+    }\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+Error:\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiUnixIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                          Status;\r
+  EFI_UNIX_IO_PROTOCOL                *UnixIo;\r
+  UNIX_SERIAL_IO_PRIVATE_DATA         *Private;\r
+  UINTN                               UnixHandle;\r
+  UART_DEVICE_PATH                    Node;\r
+  EFI_DEVICE_PATH_PROTOCOL            *ParentDevicePath;\r
+  EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;\r
+  UINTN                               EntryCount;\r
+  UINTN                               Index;\r
+  EFI_SERIAL_IO_PROTOCOL              *SerialIo;\r
+  CHAR8                               AsciiDevName[1024];\r
+\r
+  DEBUG ((EFI_D_INFO, "SerialIo drive binding start!\r\n"));\r
+  Private   = NULL;\r
+  UnixHandle  = -1;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  (VOID**)&ParentDevicePath,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Grab the IO abstraction we need to get any work done\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID**)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEfiDevicePathProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+    return Status;\r
+  }\r
+\r
+  if (Status == EFI_ALREADY_STARTED) {\r
+\r
+    if (RemainingDevicePath == NULL) {\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    //\r
+    // Make sure a child handle does not already exist.  This driver can only\r
+    // produce one child per serial port.\r
+    //\r
+    Status = gBS->OpenProtocolInformation (\r
+                    Handle,\r
+                    &gEfiUnixIoProtocolGuid,\r
+                    &OpenInfoBuffer,\r
+                    &EntryCount\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
+\r
+    Status = EFI_ALREADY_STARTED;\r
+    for (Index = 0; Index < EntryCount; Index++) {\r
+      if (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {\r
+        Status = gBS->OpenProtocol (\r
+                        OpenInfoBuffer[Index].ControllerHandle,\r
+                        &gEfiSerialIoProtocolGuid,\r
+                        (VOID**)&SerialIo,\r
+                        This->DriverBindingHandle,\r
+                        Handle,\r
+                        EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                        );\r
+        if (!EFI_ERROR (Status)) {\r
+          CopyMem (&Node, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
+          Status = SerialIo->SetAttributes (\r
+                              SerialIo,\r
+                              Node.BaudRate,\r
+                              SerialIo->Mode->ReceiveFifoDepth,\r
+                              SerialIo->Mode->Timeout,\r
+                              Node.Parity,\r
+                              Node.DataBits,\r
+                              Node.StopBits\r
+                              );\r
+        }\r
+        break;\r
+      }\r
+    }\r
+\r
+    FreePool (OpenInfoBuffer);\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Check to see if we can access the hardware device. If it's Open in Unix we\r
+  // will not get access.\r
+  //\r
+  UnicodeStrToAsciiStr(UnixIo->EnvString, AsciiDevName);\r
+  UnixHandle = UnixIo->UnixThunk->Open (AsciiDevName, O_RDWR | O_NOCTTY, 0);\r
+  \r
+  if (UnixHandle == -1) {\r
+    DEBUG ((EFI_D_INFO, "Faile to open serial device, %s!\r\n", UnixIo->EnvString ));\r
+    UnixIo->UnixThunk->Perror (AsciiDevName);\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto Error;\r
+  }\r
+  DEBUG ((EFI_D_INFO, "Success to open serial device %s, Hanle = 0x%x \r\n", UnixIo->EnvString, UnixHandle));\r
+\r
+  //\r
+  // Construct Private data\r
+  //\r
+  Private = AllocatePool (sizeof (UNIX_SERIAL_IO_PRIVATE_DATA));\r
+  if (Private == NULL) {\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // This signature must be valid before any member function is called\r
+  //\r
+  Private->Signature              = UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE;\r
+  Private->UnixHandle             = UnixHandle;\r
+  Private->ControllerHandle       = Handle;\r
+  Private->Handle                 = NULL;\r
+  Private->UnixThunk              = UnixIo->UnixThunk;\r
+  Private->ParentDevicePath       = ParentDevicePath;\r
+  Private->ControllerNameTable    = NULL;\r
+\r
+  Private->SoftwareLoopbackEnable = FALSE;\r
+  Private->HardwareLoopbackEnable = FALSE;\r
+  Private->HardwareFlowControl    = FALSE;\r
+  Private->Fifo.First             = 0;\r
+  Private->Fifo.Last              = 0;\r
+  Private->Fifo.Surplus           = SERIAL_MAX_BUFFER_SIZE;\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gUnixSerialIoComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    UnixIo->EnvString\r
+    );\r
+\r
+  Private->SerialIo.Revision      = SERIAL_IO_INTERFACE_REVISION;\r
+  Private->SerialIo.Reset         = UnixSerialIoReset;\r
+  Private->SerialIo.SetAttributes = UnixSerialIoSetAttributes;\r
+  Private->SerialIo.SetControl    = UnixSerialIoSetControl;\r
+  Private->SerialIo.GetControl    = UnixSerialIoGetControl;\r
+  Private->SerialIo.Write         = UnixSerialIoWrite;\r
+  Private->SerialIo.Read          = UnixSerialIoRead;\r
+  Private->SerialIo.Mode          = &Private->SerialIoMode;\r
+\r
+  if (RemainingDevicePath != NULL) {\r
+    //\r
+    // Match the configuration of the RemainingDevicePath. IsHandleSupported()\r
+    // already checked to make sure the RemainingDevicePath contains settings\r
+    // that we can support.\r
+    //\r
+    CopyMem (&Private->UartDevicePath, RemainingDevicePath, sizeof (UART_DEVICE_PATH));\r
+  } else {\r
+    //\r
+    // Build the device path by appending the UART node to the ParentDevicePath\r
+    // from the UnixIo handle. The Uart setings are zero here, since\r
+    // SetAttribute() will update them to match the default setings.\r
+    //\r
+    ZeroMem (&Private->UartDevicePath, sizeof (UART_DEVICE_PATH));\r
+    Private->UartDevicePath.Header.Type     = MESSAGING_DEVICE_PATH;\r
+    Private->UartDevicePath.Header.SubType  = MSG_UART_DP;\r
+    SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath, sizeof (UART_DEVICE_PATH));\r
+  }\r
+\r
+  //\r
+  // Build the device path by appending the UART node to the ParentDevicePath\r
+  // from the UnixIo handle. The Uart setings are zero here, since\r
+  // SetAttribute() will update them to match the current setings.\r
+  //\r
+  Private->DevicePath = AppendDevicePathNode (\r
+                          ParentDevicePath,\r
+                          (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath\r
+                          );\r
+  if (Private->DevicePath == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // Fill in Serial I/O Mode structure based on either the RemainingDevicePath or defaults.\r
+  //\r
+  Private->SerialIoMode.ControlMask       = SERIAL_CONTROL_MASK;\r
+  Private->SerialIoMode.Timeout           = SERIAL_TIMEOUT_DEFAULT;\r
+  Private->SerialIoMode.BaudRate          = Private->UartDevicePath.BaudRate;\r
+  Private->SerialIoMode.ReceiveFifoDepth  = SERIAL_FIFO_DEFAULT;\r
+  Private->SerialIoMode.DataBits          = Private->UartDevicePath.DataBits;\r
+  Private->SerialIoMode.Parity            = Private->UartDevicePath.Parity;\r
+  Private->SerialIoMode.StopBits          = Private->UartDevicePath.StopBits;\r
+\r
+  //\r
+  // Issue a reset to initialize the COM port\r
+  //\r
+  Status = Private->SerialIo.Reset (&Private->SerialIo);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // Create new child handle\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Private->Handle,\r
+                  &gEfiSerialIoProtocolGuid,\r
+                  &Private->SerialIo,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  Private->DevicePath,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
+\r
+  //\r
+  // Open For Child Device\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID**)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  Private->Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Error;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+\r
+Error:\r
+  //\r
+  // Use the Stop() function to free all resources allocated in Start()\r
+  //\r
+  if (Private != NULL) {\r
+    if (Private->Handle != NULL) {\r
+      This->Stop (This, Handle, 1, &Private->Handle);\r
+    } else {\r
+      if (UnixHandle != -1) {\r
+        Private->UnixThunk->Close (UnixHandle);\r
+      }\r
+\r
+      if (Private->DevicePath != NULL) {\r
+        FreePool (Private->DevicePath);\r
+      }\r
+\r
+      FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+      FreePool (Private);\r
+    }\r
+  }\r
+\r
+  This->Stop (This, Handle, 0, NULL);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  UINTN                         NumberOfChildren,\r
+  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  UINTN                         Index;\r
+  BOOLEAN                       AllChildrenStopped;\r
+  EFI_SERIAL_IO_PROTOCOL        *SerialIo;\r
+  UNIX_SERIAL_IO_PRIVATE_DATA   *Private;\r
+  EFI_UNIX_IO_PROTOCOL          *UnixIo;\r
+\r
+  //\r
+  // Complete all outstanding transactions to Controller.\r
+  // Don't allow any new transaction to Controller to be started.\r
+  //\r
+\r
+  if (NumberOfChildren == 0) {\r
+    //\r
+    // Close the bus driver\r
+    //\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEfiUnixIoProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+    Status = gBS->CloseProtocol (\r
+                    Handle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    Handle\r
+                    );\r
+    return Status;\r
+  }\r
+\r
+  AllChildrenStopped = TRUE;\r
+\r
+  for (Index = 0; Index < NumberOfChildren; Index++) {\r
+    Status = gBS->OpenProtocol (\r
+                    ChildHandleBuffer[Index],\r
+                    &gEfiSerialIoProtocolGuid,\r
+                    (VOID**)&SerialIo,\r
+                    This->DriverBindingHandle,\r
+                    Handle,\r
+                    EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                    );\r
+    if (!EFI_ERROR (Status)) {\r
+      Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (SerialIo);\r
+\r
+      ASSERT (Private->Handle == ChildHandleBuffer[Index]);\r
+\r
+      Status = gBS->CloseProtocol (\r
+                      Handle,\r
+                      &gEfiUnixIoProtocolGuid,\r
+                      This->DriverBindingHandle,\r
+                      ChildHandleBuffer[Index]\r
+                      );\r
+\r
+      Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                      ChildHandleBuffer[Index],\r
+                      &gEfiSerialIoProtocolGuid,\r
+                      &Private->SerialIo,\r
+                      &gEfiDevicePathProtocolGuid,\r
+                      Private->DevicePath,\r
+                      NULL\r
+                      );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        gBS->OpenProtocol (\r
+              Handle,\r
+              &gEfiUnixIoProtocolGuid,\r
+              (VOID **) &UnixIo,\r
+              This->DriverBindingHandle,\r
+              ChildHandleBuffer[Index],\r
+              EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER\r
+              );\r
+      } else {\r
+        Private->UnixThunk->Close (Private->UnixHandle);\r
+\r
+        FreePool (Private->DevicePath);\r
+\r
+        FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+        FreePool (Private);\r
+      }\r
+    }\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      AllChildrenStopped = FALSE;\r
+    }\r
+  }\r
+\r
+  if (!AllChildrenStopped) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+//\r
+// Serial IO Protocol member functions\r
+//\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoReset (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  UNIX_SERIAL_IO_PRIVATE_DATA *Private;\r
+  EFI_TPL                      Tpl;\r
+  UINTN                        UnixStatus;\r
+\r
+  Tpl         = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private     = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  UnixStatus  = Private->UnixThunk->Tcflush (\r
+                                    Private->UnixHandle, \r
+                                    TCIOFLUSH\r
+                                    );\r
+  switch (UnixStatus) {\r
+  case EBADF:\r
+    DEBUG ((EFI_D_ERROR, "Invalid handle of serial device!\r\n"));\r
+    return EFI_DEVICE_ERROR;\r
+  case EINVAL:\r
+    DEBUG ((EFI_D_ERROR, "Invalid queue selector!\r\n"));\r
+    return EFI_DEVICE_ERROR;\r
+  case ENOTTY:\r
+    DEBUG ((EFI_D_ERROR, "The file associated with serial's handle is not a terminal!\r\n"));\r
+    return EFI_DEVICE_ERROR;\r
+  default:\r
+    DEBUG ((EFI_D_ERROR, "The serial IO device is reset successfully!\r\n"));\r
+  }\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return This->SetAttributes (\r
+                This,\r
+                This->Mode->BaudRate,\r
+                This->Mode->ReceiveFifoDepth,\r
+                This->Mode->Timeout,\r
+                This->Mode->Parity,\r
+                (UINT8) This->Mode->DataBits,\r
+                This->Mode->StopBits\r
+                );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoSetAttributes (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This,\r
+  IN UINT64                 BaudRate,\r
+  IN UINT32                 ReceiveFifoDepth,\r
+  IN UINT32                 Timeout,\r
+  IN EFI_PARITY_TYPE        Parity,\r
+  IN UINT8                  DataBits,\r
+  IN EFI_STOP_BITS_TYPE     StopBits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  This function is used to set the attributes.\r
+\r
+Arguments:\r
+\r
+  This              - A pointer to the EFI_SERIAL_IO_PROTOCOL structrue.\r
+  BaudRate          - The Baud rate of the serial device.\r
+  ReceiveFifoDepth  - The request depth of fifo on receive side.\r
+  Timeout           - the request timeout for a single charact.\r
+  Parity            - The type of parity used in serial device.\r
+  DataBits          - Number of deata bits used in serial device.\r
+  StopBits          - Number of stop bits used in serial device.\r
+\r
+Returns:\r
+  Status code\r
+\r
+  None\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                    Status;\r
+  UNIX_SERIAL_IO_PRIVATE_DATA   *Private;\r
+  EFI_TPL                       Tpl;\r
+  EFI_DEVICE_PATH_PROTOCOL      *NewDevicePath;\r
+\r
+  Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
+  Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  //  Some of our arguments have defaults if a null value is passed in, and\r
+  //   we must set the default values if a null argument is passed in.\r
+  //\r
+  if (BaudRate == 0) {\r
+    BaudRate = SERIAL_BAUD_DEFAULT;\r
+  }\r
+\r
+  if (ReceiveFifoDepth == 0) {\r
+    ReceiveFifoDepth = SERIAL_FIFO_DEFAULT;\r
+  }\r
+\r
+  if (Timeout == 0) {\r
+    Timeout = SERIAL_TIMEOUT_DEFAULT;\r
+  }\r
+\r
+  if (Parity == DefaultParity) {\r
+    Parity = NoParity;\r
+  }\r
+\r
+  if (DataBits == 0) {\r
+    DataBits = SERIAL_DATABITS_DEFAULT;\r
+  }\r
+\r
+  if (StopBits == DefaultStopBits) {\r
+    StopBits = OneStopBit;\r
+  }\r
+\r
+  //\r
+  // See if the new attributes already match the current attributes\r
+  //\r
+  if (Private->UartDevicePath.BaudRate       == BaudRate         &&\r
+      Private->UartDevicePath.DataBits       == DataBits         &&\r
+      Private->UartDevicePath.Parity         == Parity           &&\r
+      Private->UartDevicePath.StopBits       == StopBits         &&\r
+      Private->SerialIoMode.ReceiveFifoDepth == ReceiveFifoDepth &&\r
+      Private->SerialIoMode.Timeout          == Timeout             ) {\r
+    gBS->RestoreTPL(Tpl);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Try to get options from serial device.\r
+  // \r
+  if (Private->UnixThunk->Tcgetattr (Private->UnixHandle, &Private->UnixTermios) == -1) {\r
+    Private->UnixThunk->Perror ("IoSetAttributes");\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  //\r
+  // Setting Baud Rate\r
+  // \r
+  Private->UnixThunk->Cfsetispeed (&Private->UnixTermios, ConvertBaud2Unix(BaudRate));\r
+  Private->UnixThunk->Cfsetospeed (&Private->UnixTermios, ConvertBaud2Unix(BaudRate));\r
+  //\r
+  // Setting DataBits \r
+  // \r
+  Private->UnixTermios.c_cflag &= ~CSIZE;\r
+  Private->UnixTermios.c_cflag |= ConvertByteSize2Unix (DataBits);\r
+  //\r
+  // Setting Parity\r
+  // \r
+  ConvertParity2Unix (&Private->UnixTermios, Parity);\r
+  //\r
+  // Setting StopBits\r
+  // \r
+  ConvertStopBit2Unix (&Private->UnixTermios, StopBits);\r
+  //\r
+  // Raw input\r
+  // \r
+  Private->UnixTermios.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);\r
+  //\r
+  // Raw output\r
+  // \r
+  Private->UnixTermios.c_oflag &= ~OPOST;\r
+  //\r
+  // Support hardware flow control \r
+  // \r
+  Private->UnixTermios.c_cflag &= ~CRTSCTS;;\r
+  //\r
+  // Time out\r
+  // \r
+  Private->UnixTermios.c_cc[VMIN]  = 0;\r
+  Private->UnixTermios.c_cc[VTIME] = (Timeout/1000000) * 10;\r
+\r
+  //\r
+  // Set the options\r
+  // \r
+  if (-1 == Private->UnixThunk->Tcsetattr (\r
+                        Private->UnixHandle, \r
+                        TCSANOW, \r
+                        &Private->UnixTermios\r
+                        )) {\r
+    DEBUG ((EFI_D_INFO, "Fail to set options for serial device!\r\n"));\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+  \r
+  //\r
+  //  Update mode\r
+  //\r
+  Private->SerialIoMode.BaudRate          = BaudRate;\r
+  Private->SerialIoMode.ReceiveFifoDepth  = ReceiveFifoDepth;\r
+  Private->SerialIoMode.Timeout           = Timeout;\r
+  Private->SerialIoMode.Parity            = Parity;\r
+  Private->SerialIoMode.DataBits          = DataBits;\r
+  Private->SerialIoMode.StopBits          = StopBits;\r
+  //\r
+  // See if Device Path Node has actually changed\r
+  //\r
+  if (Private->UartDevicePath.BaudRate     == BaudRate &&\r
+      Private->UartDevicePath.DataBits     == DataBits &&\r
+      Private->UartDevicePath.Parity       == Parity   &&\r
+      Private->UartDevicePath.StopBits     == StopBits    ) {\r
+    gBS->RestoreTPL(Tpl);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Update the device path\r
+  //\r
+  Private->UartDevicePath.BaudRate  = BaudRate;\r
+  Private->UartDevicePath.DataBits  = DataBits;\r
+  Private->UartDevicePath.Parity    = (UINT8) Parity;\r
+  Private->UartDevicePath.StopBits  = (UINT8) StopBits;\r
+\r
+  NewDevicePath = AppendDevicePathNode (\r
+                    Private->ParentDevicePath,\r
+                    (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath\r
+                    );\r
+  if (NewDevicePath == NULL) {\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (Private->Handle != NULL) {\r
+    Status = gBS->ReinstallProtocolInterface (\r
+                    Private->Handle,\r
+                    &gEfiDevicePathProtocolGuid,\r
+                    Private->DevicePath,\r
+                    NewDevicePath\r
+                    );\r
+    if (EFI_ERROR (Status)) {\r
+      gBS->RestoreTPL (Tpl);\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  if (Private->DevicePath != NULL) {\r
+    FreePool (Private->DevicePath);\r
+  }\r
+\r
+  Private->DevicePath = NewDevicePath;\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoSetControl (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This,\r
+  IN UINT32                 Control\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Control - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SERIAL_IO_PRIVATE_DATA *Private;\r
+  UINTN                       Result;\r
+  UINTN                       Status;\r
+  struct termios              Options;\r
+  EFI_TPL                     Tpl;\r
+\r
+  Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Result  = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMGET, &Status);\r
+\r
+  if (Result == -1) {\r
+    Private->UnixThunk->Perror ("SerialSetControl");\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  Private->HardwareFlowControl    = FALSE;\r
+  Private->SoftwareLoopbackEnable = FALSE;\r
+  Private->HardwareLoopbackEnable = FALSE;\r
+\r
+  if (Control & EFI_SERIAL_REQUEST_TO_SEND) {\r
+    Options.c_cflag |= TIOCM_RTS;\r
+  }\r
+\r
+  if (Control & EFI_SERIAL_DATA_TERMINAL_READY) {\r
+    Options.c_cflag |= TIOCM_DTR;\r
+  }\r
+\r
+  if (Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) {\r
+    Private->HardwareFlowControl = TRUE;\r
+  }\r
+\r
+  if (Control & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) {\r
+    Private->SoftwareLoopbackEnable = TRUE;\r
+  }\r
+\r
+  if (Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) {\r
+    Private->HardwareLoopbackEnable = TRUE;\r
+  }\r
+\r
+  Result  = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMSET, &Status);\r
+\r
+  if (Result == -1) {\r
+    Private->UnixThunk->Perror ("SerialSetControl");\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoGetControl (\r
+  IN  EFI_SERIAL_IO_PROTOCOL  *This,\r
+  OUT UINT32                  *Control\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Control - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SERIAL_IO_PRIVATE_DATA *Private;\r
+  UINTN                       Result;\r
+  UINTN                       Status;\r
+  UINT32                      Bits;\r
+  EFI_TPL                     Tpl;\r
+  UINTN                       Bytes;\r
+\r
+  Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+  Result  = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMGET, &Status);\r
+  if (Result == -1) {\r
+    Private->UnixThunk->Perror ("SerialGetControl");\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if ((Status & TIOCM_CTS) == TIOCM_CTS) {\r
+    Bits |= EFI_SERIAL_CLEAR_TO_SEND;\r
+  }\r
+\r
+  if ((Status & TIOCM_DSR) == TIOCM_DSR) {\r
+    Bits |= EFI_SERIAL_DATA_SET_READY;\r
+  }\r
+\r
+  if ((Status & TIOCM_DTR) == TIOCM_DTR) {\r
+    Bits |= EFI_SERIAL_DATA_TERMINAL_READY;\r
+  }\r
+\r
+  if ((Status & TIOCM_RTS) == TIOCM_RTS) {\r
+    Bits |= EFI_SERIAL_REQUEST_TO_SEND;\r
+  }\r
+\r
+  if ((Status & TIOCM_RNG) == TIOCM_RNG) {\r
+    Bits |= EFI_SERIAL_RING_INDICATE;\r
+  }\r
+\r
+  if ((Status & TIOCM_CAR) == TIOCM_CAR) {\r
+    Bits |= EFI_SERIAL_CARRIER_DETECT;\r
+  }\r
+\r
+  if (Private->HardwareFlowControl) {\r
+    Bits |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;\r
+  }\r
+\r
+  if (Private->SoftwareLoopbackEnable) {\r
+    Bits |= EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE;\r
+  }\r
+\r
+  if (Private->HardwareLoopbackEnable) {\r
+    Bits |= EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE;\r
+  }\r
+\r
+  Result = Private->UnixThunk->IoCtl (Private->UnixHandle, FIONREAD, &Bytes);\r
+  if (Result == -1) {\r
+    Private->UnixThunk->Perror ("SerialGetControl");\r
+    gBS->RestoreTPL (Tpl);\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (Bytes == 0) {\r
+    Bits |= EFI_SERIAL_INPUT_BUFFER_EMPTY;\r
+  }\r
+\r
+  *Control = Bits;\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoWrite (\r
+  IN EFI_SERIAL_IO_PROTOCOL   *This,\r
+  IN OUT UINTN                *BufferSize,\r
+  IN VOID                     *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+  EFI_SUCCESS - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SERIAL_IO_PRIVATE_DATA   *Private;\r
+  UINT8                         *ByteBuffer;\r
+  UINT32                        TotalBytesWritten;\r
+  UINT32                        BytesToGo;\r
+  UINT32                        BytesWritten;\r
+  UINT32                        Index;\r
+  UINT32                        Control;\r
+  EFI_TPL                       Tpl;\r
+\r
+  Tpl               = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private           = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This); \r
+\r
+  ByteBuffer        = (UINT8 *) Buffer;\r
+  TotalBytesWritten = 0;\r
+\r
+  if (Private->SoftwareLoopbackEnable || Private->HardwareLoopbackEnable) {\r
+    for (Index = 0; Index < *BufferSize; Index++) {\r
+      if (IsaSerialFifoAdd (&Private->Fifo, ByteBuffer[Index]) == EFI_SUCCESS) {\r
+        TotalBytesWritten++;\r
+      } else {\r
+        break;\r
+      }\r
+    }\r
+  } else {\r
+    BytesToGo = (*BufferSize);\r
+\r
+    do {\r
+      if (Private->HardwareFlowControl) {\r
+        //\r
+        // Send RTS\r
+        //\r
+        UnixSerialIoGetControl (&Private->SerialIo, &Control);\r
+        Control |= EFI_SERIAL_REQUEST_TO_SEND;\r
+        UnixSerialIoSetControl (&Private->SerialIo, Control);\r
+      }\r
+\r
+      //\r
+      //  Do the write\r
+      //\r
+      BytesWritten = Private->UnixThunk->Write ( \r
+                                           Private->UnixHandle,\r
+                                           &ByteBuffer[TotalBytesWritten],\r
+                                           BytesToGo\r
+                                           );\r
+\r
+      if (Private->HardwareFlowControl) {\r
+        //\r
+        // Assert RTS\r
+        //\r
+        UnixSerialIoGetControl (&Private->SerialIo, &Control);\r
+        Control &= ~ (UINT32) EFI_SERIAL_REQUEST_TO_SEND;\r
+        UnixSerialIoSetControl (&Private->SerialIo, Control);\r
+      }\r
+\r
+      TotalBytesWritten += BytesWritten;\r
+      BytesToGo -= BytesWritten;\r
+    } while (BytesToGo > 0);\r
+  }\r
+\r
+  *BufferSize = TotalBytesWritten;\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoRead (\r
+  IN  EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN  OUT UINTN               *BufferSize,\r
+  OUT VOID                    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  EFI_DEVICE_ERROR - TODO: Add description for return value\r
+\r
+--*/\r
+{\r
+  UNIX_SERIAL_IO_PRIVATE_DATA   *Private;\r
+  UINT32                        BytesRead;\r
+  EFI_STATUS                    Status;\r
+  UINT32                        Index;\r
+  UINT8                         Data;\r
+  UINT32                        Control;\r
+  EFI_TPL                       Tpl;\r
+\r
+  Tpl     = gBS->RaiseTPL (TPL_NOTIFY);\r
+\r
+  Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  //  Do the read\r
+  //\r
+  if (Private->SoftwareLoopbackEnable || Private->HardwareLoopbackEnable) {\r
+    for (Index = 0, BytesRead = 0; Index < *BufferSize; Index++) {\r
+      if (IsaSerialFifoRemove (&Private->Fifo, &Data) == EFI_SUCCESS) {\r
+        ((UINT8 *) Buffer)[Index] = Data;\r
+        BytesRead++;\r
+      } else {\r
+        break;\r
+      }\r
+    }\r
+  } else {\r
+    if (Private->HardwareFlowControl) {\r
+      UnixSerialIoGetControl (&Private->SerialIo, &Control);\r
+      Control |= EFI_SERIAL_DATA_TERMINAL_READY;\r
+      UnixSerialIoSetControl (&Private->SerialIo, Control);\r
+    }\r
+\r
+    BytesRead = Private->UnixThunk->Read (Private->UnixHandle, Buffer, *BufferSize);\r
+    if (Private->HardwareFlowControl) {\r
+      UnixSerialIoGetControl (&Private->SerialIo, &Control);\r
+      Control &= ~ (UINT32) EFI_SERIAL_DATA_TERMINAL_READY;\r
+      UnixSerialIoSetControl (&Private->SerialIo, Control);\r
+    }\r
+\r
+  }\r
+\r
+  if (BytesRead != *BufferSize) {\r
+    Status = EFI_TIMEOUT;\r
+  } else {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  *BufferSize = (UINTN) BytesRead;\r
+\r
+  gBS->RestoreTPL (Tpl);\r
+\r
+  return Status;\r
+}\r
+\r
+BOOLEAN\r
+IsaSerialFifoFull (\r
+  IN SERIAL_DEV_FIFO *Fifo\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  Detect whether specific FIFO is full or not\r
+\r
+  Arguments:\r
+  Fifo  SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO\r
+\r
+  Returns:\r
+  TRUE:  the FIFO is full\r
+  FALSE: the FIFO is not full\r
+\r
+--*/\r
+{\r
+  if (Fifo->Surplus == 0) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+BOOLEAN\r
+IsaSerialFifoEmpty (\r
+  IN SERIAL_DEV_FIFO *Fifo\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  Detect whether specific FIFO is empty or not\r
+\r
+  Arguments:\r
+    Fifo  SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO\r
+\r
+  Returns:\r
+    TRUE:  the FIFO is empty\r
+    FALSE: the FIFO is not empty\r
+\r
+--*/\r
+{\r
+  if (Fifo->Surplus == SERIAL_MAX_BUFFER_SIZE) {\r
+    return TRUE;\r
+  }\r
+\r
+  return FALSE;\r
+}\r
+\r
+EFI_STATUS\r
+IsaSerialFifoAdd (\r
+  IN SERIAL_DEV_FIFO *Fifo,\r
+  IN UINT8           Data\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  Add data to specific FIFO\r
+\r
+  Arguments:\r
+    Fifo  SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO\r
+    Data  UINT8: the data added to FIFO\r
+\r
+  Returns:\r
+    EFI_SUCCESS:  Add data to specific FIFO successfully\r
+    EFI_OUT_RESOURCE: Failed to add data because FIFO is already full\r
+\r
+--*/\r
+// TODO:    EFI_OUT_OF_RESOURCES - add return value to function comment\r
+{\r
+  //\r
+  // if FIFO full can not add data\r
+  //\r
+  if (IsaSerialFifoFull (Fifo)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // FIFO is not full can add data\r
+  //\r
+  Fifo->Data[Fifo->Last] = Data;\r
+  Fifo->Surplus--;\r
+  Fifo->Last++;\r
+  if (Fifo->Last >= SERIAL_MAX_BUFFER_SIZE) {\r
+    Fifo->Last = 0;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+IsaSerialFifoRemove (\r
+  IN  SERIAL_DEV_FIFO *Fifo,\r
+  OUT UINT8           *Data\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+  Remove data from specific FIFO\r
+\r
+  Arguments:\r
+    Fifo  SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO\r
+    Data  UINT8*: the data removed from FIFO\r
+\r
+  Returns:\r
+    EFI_SUCCESS:  Remove data from specific FIFO successfully\r
+    EFI_OUT_RESOURCE: Failed to remove data because FIFO is empty\r
+\r
+--*/\r
+// TODO:    EFI_OUT_OF_RESOURCES - add return value to function comment\r
+{\r
+  //\r
+  // if FIFO is empty, no data can remove\r
+  //\r
+  if (IsaSerialFifoEmpty (Fifo)) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // FIFO is not empty, can remove data\r
+  //\r
+  *Data = Fifo->Data[Fifo->First];\r
+  Fifo->Surplus++;\r
+  Fifo->First++;\r
+  if (Fifo->First >= SERIAL_MAX_BUFFER_SIZE) {\r
+    Fifo->First = 0;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h
new file mode 100644 (file)
index 0000000..023ff48
--- /dev/null
@@ -0,0 +1,572 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  UnixSerialIo.h\r
+\r
+Abstract:\r
+\r
+\r
+--*/\r
+\r
+#ifndef _UNIXPKG_SERIAL_IO_\r
+#define _UNIXPKG_SERIAL_IO_\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+#include <stdio.h>\r
+#include <stdlib.h>\r
+#include <termio.h>\r
+#include <fcntl.h>\r
+#include <errno.h>\r
+\r
+#include "PiDxe.h"\r
+#include <Protocol/SerialIo.h>\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include "UnixDxe.h"\r
+\r
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName;\r
+\r
+#define SERIAL_MAX_BUFFER_SIZE  256\r
+#define TIMEOUT_STALL_INTERVAL  10\r
+\r
+typedef struct {\r
+  UINT32  First;\r
+  UINT32  Last;\r
+  UINT32  Surplus;\r
+  UINT8   Data[SERIAL_MAX_BUFFER_SIZE];\r
+} SERIAL_DEV_FIFO;\r
+\r
+#define UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('U', 'N', 's', 'i')\r
+typedef struct {\r
+  UINT64                    Signature;\r
+\r
+  //\r
+  // Protocol data for the new handle we are going to add\r
+  //\r
+  EFI_HANDLE                Handle;\r
+  EFI_SERIAL_IO_PROTOCOL    SerialIo;\r
+  EFI_SERIAL_IO_MODE        SerialIoMode;\r
+  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;\r
+\r
+  //\r
+  // Private Data\r
+  //\r
+  EFI_HANDLE                ControllerHandle;\r
+  EFI_DEVICE_PATH_PROTOCOL  *ParentDevicePath;\r
+  UART_DEVICE_PATH          UartDevicePath;\r
+  EFI_UNIX_THUNK_PROTOCOL   *UnixThunk;\r
+\r
+  EFI_UNICODE_STRING_TABLE  *ControllerNameTable;\r
+\r
+  //\r
+  // Private NT type Data;\r
+  //\r
+  UINTN                       UnixHandle;\r
+  struct termios              UnixTermios;\r
+\r
+  BOOLEAN                   SoftwareLoopbackEnable;\r
+  BOOLEAN                   HardwareFlowControl;\r
+  BOOLEAN                   HardwareLoopbackEnable;\r
+\r
+  SERIAL_DEV_FIFO           Fifo;\r
+\r
+} UNIX_SERIAL_IO_PRIVATE_DATA;\r
+\r
+#define UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS(a) \\r
+         CR(a, UNIX_SERIAL_IO_PRIVATE_DATA, SerialIo, UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE)\r
+\r
+//\r
+// Global Protocol Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gUnixSerialIoDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gUnixSerialIoComponentName;\r
+\r
+//\r
+// Macros to convert EFI serial types to NT serial types.\r
+//\r
+\r
+//\r
+// one second\r
+//\r
+#define SERIAL_TIMEOUT_DEFAULT  (1000 * 1000) \r
+#define SERIAL_BAUD_DEFAULT     115200\r
+#define SERIAL_FIFO_DEFAULT     14\r
+#define SERIAL_DATABITS_DEFAULT 8\r
+#define SERIAL_PARITY_DEFAULT   DefaultParity\r
+#define SERIAL_STOPBITS_DEFAULT DefaultStopBits\r
+\r
+#define SERIAL_CONTROL_MASK     (EFI_SERIAL_CLEAR_TO_SEND       | \\r
+                                 EFI_SERIAL_DATA_SET_READY      | \\r
+                                 EFI_SERIAL_RING_INDICATE       | \\r
+                                 EFI_SERIAL_CARRIER_DETECT      | \\r
+                                 EFI_SERIAL_REQUEST_TO_SEND     | \\r
+                                 EFI_SERIAL_DATA_TERMINAL_READY | \\r
+                                 EFI_SERIAL_INPUT_BUFFER_EMPTY)\r
+\r
+#define ConvertBaud2Nt(x)       (DWORD) x\r
+#define ConvertData2Nt(x)       (BYTE) x\r
+\r
+#define ConvertParity2Nt(x)              \\r
+    (BYTE) (                             \\r
+    x == DefaultParity ? NOPARITY    :   \\r
+    x == NoParity      ? NOPARITY    :   \\r
+    x == EvenParity    ? EVENPARITY  :   \\r
+    x == OddParity     ? ODDPARITY   :   \\r
+    x == MarkParity    ? MARKPARITY  :   \\r
+    x == SpaceParity   ? SPACEPARITY : 0 \\r
+    )\r
+\r
+#define ConvertStop2Nt(x)                 \\r
+    (BYTE) (                                \\r
+    x == DefaultParity   ? ONESTOPBIT   :   \\r
+    x == OneFiveStopBits ? ONE5STOPBITS :   \\r
+    x == TwoStopBits     ? TWOSTOPBITS  : 0 \\r
+    )\r
+\r
+#define ConvertTime2Nt(x) ((x) / 1000)\r
+\r
+//\r
+// 115400 baud with rounding errors\r
+//\r
+#define SERIAL_PORT_MAX_BAUD_RATE 115400  \r
+\r
+//\r
+// Fix the differences issue of linux header files termios.h \r
+// \r
+#ifndef B460800\r
+#define B460800 0010004\r
+#endif\r
+#ifndef B500000\r
+#define   B500000 0010005\r
+#endif\r
+#ifndef B576000\r
+#define   B576000 0010006\r
+#endif\r
+#ifndef B921600\r
+#define   B921600 0010007\r
+#endif\r
+#ifndef B1000000\r
+#define  B1000000 0010010\r
+#endif\r
+#ifndef B1152000\r
+#define  B1152000 0010011\r
+#endif\r
+#ifndef B1500000\r
+#define  B1500000 0010012\r
+#endif\r
+#ifndef B2000000\r
+#define  B2000000 0010013\r
+#endif\r
+#ifndef B2500000\r
+#define  B2500000 0010014\r
+#endif\r
+#ifndef B3000000\r
+#define  B3000000 0010015\r
+#endif\r
+#ifndef B3500000\r
+#define  B3500000 0010016\r
+#endif\r
+#ifndef B4000000\r
+#define  B4000000 0010017\r
+#endif\r
+#ifndef __MAX_BAUD\r
+#define __MAX_BAUD B4000000\r
+#endif\r
+#ifndef CMSPAR\r
+#define CMSPAR   010000000000          /* mark or space (stick) parity */\r
+#endif\r
+#ifndef FIONREAD\r
+#define FIONREAD       0x541B\r
+#endif\r
+//\r
+// Function Prototypes\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixSerialIo (\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  ImageHandle - TODO: add argument description\r
+  SystemTable - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  Handle              - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This                - TODO: add argument description\r
+  Handle              - TODO: add argument description\r
+  RemainingDevicePath - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    Handle,\r
+  IN  UINTN                         NumberOfChildren,\r
+  IN  EFI_HANDLE                    *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  Handle            - TODO: add argument description\r
+  NumberOfChildren  - TODO: add argument description\r
+  ChildHandleBuffer - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoReset (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoSetAttributes (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This,\r
+  IN UINT64                 BaudRate,\r
+  IN UINT32                 ReceiveFifoDepth,\r
+  IN UINT32                 Timeout,\r
+  IN EFI_PARITY_TYPE        Parity,\r
+  IN UINT8                  DataBits,\r
+  IN EFI_STOP_BITS_TYPE     StopBits\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - TODO: add argument description\r
+  BaudRate          - TODO: add argument description\r
+  ReceiveFifoDepth  - TODO: add argument description\r
+  Timeout           - TODO: add argument description\r
+  Parity            - TODO: add argument description\r
+  DataBits          - TODO: add argument description\r
+  StopBits          - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoSetControl (\r
+  IN EFI_SERIAL_IO_PROTOCOL *This,\r
+  IN UINT32                 Control\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Control - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoGetControl (\r
+  IN  EFI_SERIAL_IO_PROTOCOL  *This,\r
+  OUT UINT32                  *Control\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This    - TODO: add argument description\r
+  Control - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoWrite (\r
+  IN EFI_SERIAL_IO_PROTOCOL   *This,\r
+  IN OUT UINTN                *BufferSize,\r
+  IN VOID                     *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSerialIoRead (\r
+  IN  EFI_SERIAL_IO_PROTOCOL  *This,\r
+  IN  OUT UINTN               *BufferSize,\r
+  OUT VOID                    *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This        - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+BOOLEAN\r
+IsaSerialFifoFull (\r
+  IN SERIAL_DEV_FIFO *Fifo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Fifo  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+BOOLEAN\r
+IsaSerialFifoEmpty (\r
+  IN SERIAL_DEV_FIFO *Fifo\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Fifo  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+IsaSerialFifoAdd (\r
+  IN SERIAL_DEV_FIFO *Fifo,\r
+  IN UINT8           Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Fifo  - TODO: add argument description\r
+  Data  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+IsaSerialFifoRemove (\r
+  IN  SERIAL_DEV_FIFO *Fifo,\r
+  OUT UINT8           *Data\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Fifo  - TODO: add argument description\r
+  Data  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+IsaSerialReceiveTransmit (\r
+  UNIX_SERIAL_IO_PRIVATE_DATA     *Private\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Private - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+;\r
+\r
+#endif\r
diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf
new file mode 100644 (file)
index 0000000..0f74f26
--- /dev/null
@@ -0,0 +1,69 @@
+#/** @file\r
+# Serial I/O driver\r
+#\r
+# Our DriverBinding member functions operate on the handles\r
+#  created by the Unix Bus driver\r
+# Copyright (c) 2006 - 2007, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixSerialIo\r
+  FILE_GUID                      = 600F2BF2-63A7-48ca-9FD0-A3450B87EE05\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnixSerialIo\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32\r
+#\r
+#  DRIVER_BINDING                =  gUnixSerialIoDriverBinding                   \r
+#  COMPONENT_NAME                =  gUnixSerialIoComponentName                   \r
+#\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  UnixSerialIo.c\r
+  UnixSerialIo.h\r
+  EntryPoint.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  MemoryAllocationLib\r
+  DevicePathLib\r
+  UefiBootServicesTableLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiUnixSerialPortGuid                       # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiSerialIoProtocolGuid                      # PROTOCOL BY_START\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL TO_START\r
+  gEfiUnixIoProtocolGuid                        # PROTOCOL TO_START\r
+\r
diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.msa b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.msa
new file mode 100644 (file)
index 0000000..793d24a
--- /dev/null
@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">\r
+  <MsaHeader>\r
+    <ModuleName>UnixSerialIo</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>600F2BF2-63A7-48ca-9FD0-A3450B87EE05</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Serial I/O driver</Abstract>\r
+    <Description>Our DriverBinding member functions operate on the handles\r
+      created by the Unix Bus driver</Description>\r
+    <Copyright>Copyright (c) 2006 - 2007, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixSerialIo</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DevicePathLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixSerialIo.h</Filename>\r
+    <Filename>UnixSerialIo.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiSerialIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixSerialPortGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gUnixSerialIoDriverBinding</DriverBinding>\r
+      <ComponentName>gUnixSerialIoComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
\ No newline at end of file
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/ComponentName.c b/UnixPkg/UnixSimpleFileSystemDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..347326d
--- /dev/null
@@ -0,0 +1,204 @@
+/*++\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
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include "UnixSimpleFileSystem.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                                        *This,\r
+  IN  EFI_HANDLE                                                         ControllerHandle,\r
+  IN  EFI_HANDLE                                                         ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                                              *Language,\r
+  OUT CHAR16                                                             **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gUnixSimpleFileSystemComponentName = {\r
+  UnixSimpleFileSystemComponentNameGetDriverName,\r
+  UnixSimpleFileSystemComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mUnixSimpleFileSystemDriverNameTable[] = {\r
+  {\r
+    "eng",\r
+    L"Unix Simple File System Driver"\r
+  },\r
+  {\r
+    NULL,\r
+    NULL\r
+  }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixSimpleFileSystemComponentName.SupportedLanguages,\r
+          mUnixSimpleFileSystemDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                                        *This,\r
+  IN  EFI_HANDLE                                                         ControllerHandle,\r
+  IN  EFI_HANDLE                                                         ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                                              *Language,\r
+  OUT CHAR16                                                             **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the \r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing \r
+                            the controller specified by ControllerHandle and \r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *SimpleFileSystem;\r
+  UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllerHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gUnixSimpleFileSystemDriverBinding.DriverBindingHandle,\r
+             &gEfiUnixIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleFileSystemProtocolGuid,\r
+                  (VOID**)&SimpleFileSystem,\r
+                  gUnixSimpleFileSystemDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixSimpleFileSystemComponentName.SupportedLanguages,\r
+          Private->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/EntryPoint.c b/UnixPkg/UnixSimpleFileSystemDxe/EntryPoint.c
new file mode 100644 (file)
index 0000000..44e271b
--- /dev/null
@@ -0,0 +1,51 @@
+/**@file\r
+  Entry Point Source file.\r
+\r
+  This file contains the user entry point \r
+\r
+  Copyright (c) 2006 - 2008, 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
+   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
+\r
+\r
+\r
+#include "UnixSimpleFileSystem.h"\r
+\r
+/**\r
+  The user Entry Point for module UnixSimpleFileSystem. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixSimpleFileSystem(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gUnixSimpleFileSystemDriverBinding,\r
+             ImageHandle,\r
+             &gUnixSimpleFileSystemComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c
new file mode 100644 (file)
index 0000000..84ba962
--- /dev/null
@@ -0,0 +1,2186 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2007, 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
+\r
+  UnixSimpleFileSystem.c\r
+\r
+Abstract:\r
+\r
+  Produce Simple File System abstractions for directories on your PC using Posix APIs.\r
+  The configuration of what devices to mount or emulate comes from UNIX \r
+  environment variables. The variables must be visible to the Microsoft* \r
+  Developer Studio for them to work.\r
+\r
+  * Other names and brands may be claimed as the property of others.\r
+\r
+--*/\r
+\r
+#include "UnixSimpleFileSystem.h"\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gUnixSimpleFileSystemDriverBinding = {\r
+  UnixSimpleFileSystemDriverBindingSupported,\r
+  UnixSimpleFileSystemDriverBindingStart,\r
+  UnixSimpleFileSystemDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
+CHAR16 *\r
+EfiStrChr (\r
+  IN CHAR16   *Str,\r
+  IN CHAR16   Chr\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Locate the first occurance of a character in a string.\r
+\r
+Arguments:\r
+\r
+  Str - Pointer to NULL terminated unicode string.\r
+  Chr - Character to locate.\r
+\r
+Returns:\r
+\r
+  If Str is NULL, then NULL is returned.\r
+  If Chr is not contained in Str, then NULL is returned.\r
+  If Chr is contained in Str, then a pointer to the first occurance of Chr in Str is returned.\r
+\r
+--*/\r
+{\r
+  if (Str == NULL) {\r
+    return Str;\r
+  }\r
+\r
+  while (*Str != '\0' && *Str != Chr) {\r
+    ++Str;\r
+  }\r
+\r
+  return (*Str == Chr) ? Str : NULL;\r
+}\r
+\r
+BOOLEAN\r
+IsZero (\r
+  IN VOID   *Buffer,\r
+  IN UINTN  Length\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Buffer  - TODO: add argument description\r
+  Length  - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  if (Buffer == NULL || Length == 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (*(UINT8 *) Buffer != 0) {\r
+    return FALSE;\r
+  }\r
+\r
+  if (Length > 1) {\r
+    if (!CompareMem (Buffer, (UINT8 *) Buffer + 1, Length - 1)) {\r
+      return FALSE;\r
+    }\r
+  }\r
+\r
+  return TRUE;\r
+}\r
+\r
+VOID\r
+CutPrefix (\r
+  IN  CHAR8  *Str,\r
+  IN  UINTN   Count\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  Str   - TODO: add argument description\r
+  Count - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  CHAR8  *Pointer;\r
+\r
+  if (AsciiStrLen (Str) < Count) {\r
+    ASSERT (0);\r
+  }\r
+\r
+  for (Pointer = Str; *(Pointer + Count); Pointer++) {\r
+    *Pointer = *(Pointer + Count);\r
+  }\r
+\r
+  *Pointer = *(Pointer + Count);\r
+}\r
+\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check to see if the driver supports a given controller.\r
+\r
+Arguments:\r
+\r
+  This                - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.\r
+\r
+  ControllerHandle    - EFI handle of the controller to test.\r
+\r
+  RemainingDevicePath - Pointer to remaining portion of a device path.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS         - The device specified by ControllerHandle and RemainingDevicePath is supported by the driver\r
+                        specified by This.\r
+\r
+  EFI_ALREADY_STARTED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by\r
+                        the driver specified by This.\r
+\r
+  EFI_ACCESS_DENIED   - The device specified by ControllerHandle and RemainingDevicePath is already being managed by\r
+                        a different driver or an application that requires exclusive access.\r
+\r
+  EFI_UNSUPPORTED     - The device specified by ControllerHandle and RemainingDevicePath is not supported by the\r
+                        driver specified by This.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_UNIX_IO_PROTOCOL  *UnixIo;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID **)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Make sure GUID is for a File System handle.\r
+  //\r
+  Status = EFI_UNSUPPORTED;\r
+  if (CompareGuid (UnixIo->TypeGuid, &gEfiUnixFileSystemGuid)) {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        ControllerHandle,\r
+        &gEfiUnixIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        ControllerHandle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Starts a device controller or a bus controller.\r
+\r
+Arguments:\r
+\r
+  This                - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.\r
+\r
+  ControllerHandle    - EFI handle of the controller to start.\r
+\r
+  RemainingDevicePath - Pointer to remaining portion of a device path.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The device or bus controller has been started.\r
+\r
+  EFI_DEVICE_ERROR      - The device could not be started due to a device failure.\r
+\r
+  EFI_OUT_OF_RESOURCES  - The request could not be completed due to lack of resources.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_UNIX_IO_PROTOCOL            *UnixIo;\r
+  UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
+  INTN i;\r
+\r
+  Private = NULL;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID **)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Validate GUID\r
+  //\r
+  if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixFileSystemGuid)) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (UNIX_SIMPLE_FILE_SYSTEM_PRIVATE),\r
+                  (VOID **)&Private\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Private->Signature  = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;\r
+  Private->UnixThunk = UnixIo->UnixThunk;\r
+  Private->FilePath   = NULL;\r
+  Private->VolumeLabel = NULL;\r
+\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  StrLen (UnixIo->EnvString) + 1,\r
+                  (VOID **)&Private->FilePath\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  for (i = 0; UnixIo->EnvString[i] != 0; i++)\r
+    Private->FilePath[i] = UnixIo->EnvString[i];\r
+  Private->FilePath[i] = 0;\r
+\r
+  Private->VolumeLabel      = NULL;\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  StrSize (L"EFI_EMULATED"),\r
+                  (VOID **)&Private->VolumeLabel\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  StrCpy (Private->VolumeLabel, L"EFI_EMULATED");\r
+\r
+  Private->SimpleFileSystem.Revision    = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
+  Private->SimpleFileSystem.OpenVolume  = UnixSimpleFileSystemOpenVolume;\r
+\r
+  Private->ControllerNameTable = NULL;\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gUnixSimpleFileSystemComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    UnixIo->EnvString\r
+    );\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &ControllerHandle,\r
+                  &gEfiSimpleFileSystemProtocolGuid,\r
+                  &Private->SimpleFileSystem,\r
+                  NULL\r
+                  );\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    if (Private != NULL) {\r
+\r
+      if (Private->VolumeLabel != NULL)\r
+       gBS->FreePool (Private->VolumeLabel);\r
+      if (Private->FilePath != NULL)\r
+       gBS->FreePool (Private->FilePath);\r
+      FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+      gBS->FreePool (Private);\r
+    }\r
+\r
+    gBS->CloseProtocol (\r
+          ControllerHandle,\r
+          &gEfiUnixIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          ControllerHandle\r
+          );\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.\r
+\r
+  ControllerHandle  - A handle to the device to be stopped.\r
+\r
+  NumberOfChildren  - The number of child device handles in ChildHandleBuffer.\r
+\r
+  ChildHandleBuffer - An array of child device handles to be freed.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS       - The device has been stopped.\r
+\r
+  EFI_DEVICE_ERROR  - The device could not be stopped due to a device failure.\r
+\r
+--*/\r
+// TODO:    EFI_UNSUPPORTED - add return value to function comment\r
+{\r
+  EFI_STATUS                        Status;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL   *SimpleFileSystem;\r
+  UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
+\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleFileSystemProtocolGuid,\r
+                  (VOID **)&SimpleFileSystem,\r
+                  This->DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);\r
+\r
+  //\r
+  // Uninstall the Simple File System Protocol from ControllerHandle\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  ControllerHandle,\r
+                  &gEfiSimpleFileSystemProtocolGuid,\r
+                  &Private->SimpleFileSystem,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    Status = gBS->CloseProtocol (\r
+                    ControllerHandle,\r
+                    &gEfiUnixIoProtocolGuid,\r
+                    This->DriverBindingHandle,\r
+                    ControllerHandle\r
+                    );\r
+  }\r
+\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+    gBS->FreePool (Private);\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemOpenVolume (\r
+  IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL  *This,\r
+  OUT EFI_FILE                        **Root\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Open the root directory on a volume.\r
+\r
+Arguments:\r
+\r
+  This  - A pointer to the volume to open.\r
+\r
+  Root  - A pointer to storage for the returned opened file handle of the root directory.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The volume was opened.\r
+\r
+  EFI_UNSUPPORTED       - The volume does not support the requested file system type.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupted.\r
+\r
+  EFI_ACCESS_DENIED     - The service denied access to the file.\r
+\r
+  EFI_OUT_OF_RESOURCES  - The file volume could not be opened due to lack of resources.\r
+\r
+  EFI_MEDIA_CHANGED     - The device has new media or the media is no longer supported.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  EFI_STATUS                        Status;\r
+  UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
+  UNIX_EFI_FILE_PRIVATE           *PrivateFile;\r
+  EFI_TPL                           OldTpl;\r
+\r
+  if (This == NULL || Root == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  Private     = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  PrivateFile = NULL;\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (UNIX_EFI_FILE_PRIVATE),\r
+                  (VOID **)&PrivateFile\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  PrivateFile->FileName = NULL;\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  AsciiStrSize (Private->FilePath),\r
+                  (VOID **)&PrivateFile->FileName\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  AsciiStrCpy (PrivateFile->FileName, Private->FilePath);\r
+  PrivateFile->Signature            = UNIX_EFI_FILE_PRIVATE_SIGNATURE;\r
+  PrivateFile->UnixThunk           = Private->UnixThunk;\r
+  PrivateFile->SimpleFileSystem     = This;\r
+  PrivateFile->IsRootDirectory      = TRUE;\r
+  PrivateFile->IsDirectoryPath      = TRUE;\r
+  PrivateFile->IsOpenedByRead       = TRUE;\r
+  PrivateFile->EfiFile.Revision     = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
+  PrivateFile->EfiFile.Open         = UnixSimpleFileSystemOpen;\r
+  PrivateFile->EfiFile.Close        = UnixSimpleFileSystemClose;\r
+  PrivateFile->EfiFile.Delete       = UnixSimpleFileSystemDelete;\r
+  PrivateFile->EfiFile.Read         = UnixSimpleFileSystemRead;\r
+  PrivateFile->EfiFile.Write        = UnixSimpleFileSystemWrite;\r
+  PrivateFile->EfiFile.GetPosition  = UnixSimpleFileSystemGetPosition;\r
+  PrivateFile->EfiFile.SetPosition  = UnixSimpleFileSystemSetPosition;\r
+  PrivateFile->EfiFile.GetInfo      = UnixSimpleFileSystemGetInfo;\r
+  PrivateFile->EfiFile.SetInfo      = UnixSimpleFileSystemSetInfo;\r
+  PrivateFile->EfiFile.Flush        = UnixSimpleFileSystemFlush;\r
+  PrivateFile->fd                   = -1;\r
+  PrivateFile->Dir                  = NULL;\r
+  PrivateFile->Dirent               = NULL;\r
+  \r
+  *Root = &PrivateFile->EfiFile;\r
+\r
+  PrivateFile->Dir = PrivateFile->UnixThunk->OpenDir(PrivateFile->FileName);\r
+\r
+  if (PrivateFile->Dir == NULL) {\r
+    Status = EFI_ACCESS_DENIED;\r
+  }\r
+  else {\r
+    Status = EFI_SUCCESS;\r
+  }\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+    if (PrivateFile) {\r
+      if (PrivateFile->FileName) {\r
+        gBS->FreePool (PrivateFile->FileName);\r
+      }\r
+\r
+      gBS->FreePool (PrivateFile);\r
+    }\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemOpen (\r
+  IN  EFI_FILE  *This,\r
+  OUT EFI_FILE  **NewHandle,\r
+  IN  CHAR16    *FileName,\r
+  IN  UINT64    OpenMode,\r
+  IN  UINT64    Attributes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Open a file relative to the source file location.\r
+\r
+Arguments:\r
+\r
+  This        - A pointer to the source file location.\r
+\r
+  NewHandle   - Pointer to storage for the new file handle.\r
+\r
+  FileName    - Pointer to the file name to be opened.\r
+\r
+  OpenMode    - File open mode information.\r
+\r
+  Attributes  - File creation attributes.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The file was opened.\r
+\r
+  EFI_NOT_FOUND         - The file could not be found in the volume.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_MEDIA_CHANGED     - The device has new media or the media is no longer supported.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupted.\r
+\r
+  EFI_WRITE_PROTECTED   - The volume or file is write protected.\r
+\r
+  EFI_ACCESS_DENIED     - The service denied access to the file.\r
+\r
+  EFI_OUT_OF_RESOURCES  - Not enough resources were available to open the file.\r
+\r
+  EFI_VOLUME_FULL       - There is not enough space left to create the new file.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  EFI_FILE                          *Root;\r
+  UNIX_EFI_FILE_PRIVATE           *PrivateFile;\r
+  UNIX_EFI_FILE_PRIVATE           *NewPrivateFile;\r
+  UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;\r
+  EFI_STATUS                        Status;\r
+  CHAR16                            *Src;\r
+  char                              *Dst;\r
+  CHAR8                             *RealFileName;\r
+  char                              *ParseFileName;\r
+  char                              *GuardPointer;\r
+  CHAR8                             TempChar;\r
+  UINTN                             Count;\r
+  BOOLEAN                           TrailingDash;\r
+  BOOLEAN                           LoopFinish;\r
+  UINTN                             InfoSize;\r
+  EFI_FILE_INFO                     *Info;\r
+\r
+  TrailingDash = FALSE;\r
+\r
+  //\r
+  // Check for obvious invalid parameters.\r
+  //\r
+  if (This == NULL || NewHandle == NULL || FileName == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  switch (OpenMode) {\r
+  case EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:\r
+    if (Attributes &~EFI_FILE_VALID_ATTR) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if (Attributes & EFI_FILE_READ_ONLY) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+  //\r
+  // fall through\r
+  //\r
+  case EFI_FILE_MODE_READ:\r
+  case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:\r
+    break;\r
+\r
+  default:\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+\r
+  PrivateFile     = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+  PrivateRoot     = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);\r
+  NewPrivateFile  = NULL;\r
+\r
+  //\r
+  // BUGBUG: assume an open of root\r
+  // if current location, return current data\r
+  //\r
+  if (StrCmp (FileName, L"\\") == 0\r
+      || (StrCmp (FileName, L".") == 0 && PrivateFile->IsRootDirectory)) {\r
+    //\r
+    // BUGBUG: assume an open root\r
+    //\r
+OpenRoot:\r
+    Status          = UnixSimpleFileSystemOpenVolume (PrivateFile->SimpleFileSystem, &Root);\r
+    NewPrivateFile  = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (Root);\r
+    goto Done;\r
+  }\r
+\r
+  if (FileName[StrLen (FileName) - 1] == L'\\') {\r
+    TrailingDash                        = TRUE;\r
+    FileName[StrLen (FileName) - 1]  = 0;\r
+  }\r
+\r
+  //\r
+  // Attempt to open the file\r
+  //\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (UNIX_EFI_FILE_PRIVATE),\r
+                  (VOID **)&NewPrivateFile\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  CopyMem (NewPrivateFile, PrivateFile, sizeof (UNIX_EFI_FILE_PRIVATE));\r
+\r
+  NewPrivateFile->FileName = NULL;\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  AsciiStrSize (PrivateFile->FileName) + 1 + StrLen (FileName) + 1,\r
+                  (VOID **)&NewPrivateFile->FileName\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  if (*FileName == L'\\') {\r
+    AsciiStrCpy (NewPrivateFile->FileName, PrivateRoot->FilePath);\r
+    // Skip first '\'.\r
+    Src = FileName + 1;\r
+  } else {\r
+    AsciiStrCpy (NewPrivateFile->FileName, PrivateFile->FileName);\r
+    Src = FileName;\r
+  }\r
+  Dst = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName);\r
+  GuardPointer = NewPrivateFile->FileName + AsciiStrLen(PrivateRoot->FilePath);\r
+  *Dst++ = '/';\r
+  // Convert unicode to ascii and '\' to '/'\r
+  while (*Src) {\r
+    if (*Src == '\\')\r
+      *Dst++ = '/';\r
+    else\r
+      *Dst++ = *Src;\r
+    Src++;\r
+  }\r
+  *Dst = 0;\r
+      \r
+\r
+  //\r
+  // Get rid of . and .., except leading . or ..\r
+  //\r
+\r
+  //\r
+  // GuardPointer protect simplefilesystem root path not be destroyed\r
+  //\r
+\r
+  LoopFinish    = FALSE;\r
+\r
+  while (!LoopFinish) {\r
+\r
+    LoopFinish = TRUE;\r
+\r
+    for (ParseFileName = GuardPointer; *ParseFileName; ParseFileName++) {\r
+      if (*ParseFileName == '.' &&\r
+          (*(ParseFileName + 1) == 0 || *(ParseFileName + 1) == '/') &&\r
+          *(ParseFileName - 1) == '/'\r
+          ) {\r
+\r
+        //\r
+        // cut /.\r
+        //\r
+        CutPrefix (ParseFileName - 1, 2);\r
+        LoopFinish = FALSE;\r
+        break;\r
+      }\r
+\r
+      if (*ParseFileName == '.' &&\r
+          *(ParseFileName + 1) == '.' &&\r
+          (*(ParseFileName + 2) == 0 || *(ParseFileName + 2) == '/') &&\r
+          *(ParseFileName - 1) == '/'\r
+          ) {\r
+\r
+        ParseFileName--;\r
+        Count = 3;\r
+\r
+        while (ParseFileName != GuardPointer) {\r
+          ParseFileName--;\r
+          Count++;\r
+          if (*ParseFileName == '/') {\r
+            break;\r
+          }\r
+        }\r
+\r
+        //\r
+        // cut /.. and its left directory\r
+        //\r
+        CutPrefix (ParseFileName, Count);\r
+        LoopFinish = FALSE;\r
+        break;\r
+      }\r
+    }\r
+  }\r
+\r
+  if (AsciiStrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) {\r
+    NewPrivateFile->IsRootDirectory = TRUE;\r
+    gBS->FreePool (NewPrivateFile->FileName);\r
+    gBS->FreePool (NewPrivateFile);\r
+    goto OpenRoot;\r
+  }\r
+\r
+  RealFileName = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName) - 1;\r
+  while (RealFileName > NewPrivateFile->FileName && *RealFileName != '/')\r
+    RealFileName--;\r
+\r
+  TempChar            = *(RealFileName - 1);\r
+  *(RealFileName - 1) = 0;\r
+\r
+  *(RealFileName - 1)             = TempChar;\r
+\r
+\r
+\r
+  //\r
+  // Test whether file or directory\r
+  //\r
+  NewPrivateFile->IsRootDirectory = FALSE;\r
+  NewPrivateFile->fd = -1;\r
+  NewPrivateFile->Dir = NULL;\r
+  if (OpenMode & EFI_FILE_MODE_CREATE) {\r
+    if (Attributes & EFI_FILE_DIRECTORY) {\r
+      NewPrivateFile->IsDirectoryPath = TRUE;\r
+    } else {\r
+      NewPrivateFile->IsDirectoryPath = FALSE;\r
+    }\r
+  } else {\r
+    struct stat finfo;\r
+    int res = NewPrivateFile->UnixThunk->Stat (NewPrivateFile->FileName, &finfo);\r
+    if (res == 0 && S_ISDIR(finfo.st_mode))\r
+      NewPrivateFile->IsDirectoryPath = TRUE;\r
+    else\r
+      NewPrivateFile->IsDirectoryPath = FALSE;\r
+  }\r
+\r
+  if (OpenMode & EFI_FILE_MODE_WRITE) {\r
+    NewPrivateFile->IsOpenedByRead = FALSE;\r
+  } else {\r
+    NewPrivateFile->IsOpenedByRead = TRUE;\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  //\r
+  // deal with directory\r
+  //\r
+  if (NewPrivateFile->IsDirectoryPath) {\r
+\r
+    if ((OpenMode & EFI_FILE_MODE_CREATE)) {\r
+      //\r
+      // Create a directory\r
+      //\r
+      if (NewPrivateFile->UnixThunk->MkDir (NewPrivateFile->FileName, 0777) != 0) {\r
+       INTN LastError;\r
+\r
+        LastError = PrivateFile->UnixThunk->GetErrno ();\r
+        if (LastError != EEXIST) {\r
+          //gBS->FreePool (TempFileName);\r
+          Status = EFI_ACCESS_DENIED;\r
+          goto Done;\r
+        }\r
+      }\r
+    }\r
+\r
+    NewPrivateFile->Dir = NewPrivateFile->UnixThunk->OpenDir\r
+      (NewPrivateFile->FileName);\r
+\r
+    if (NewPrivateFile->Dir == NULL) {\r
+      if (PrivateFile->UnixThunk->GetErrno () == EACCES) {\r
+        Status                    = EFI_ACCESS_DENIED;\r
+      } else {\r
+        Status = EFI_NOT_FOUND;\r
+      }\r
+\r
+      goto Done;\r
+    }\r
+\r
+  } else {\r
+    //\r
+    // deal with file\r
+    //\r
+    NewPrivateFile->fd = NewPrivateFile->UnixThunk->Open\r
+      (NewPrivateFile->FileName,\r
+       ((OpenMode & EFI_FILE_MODE_CREATE) ? O_CREAT : 0)\r
+       | (NewPrivateFile->IsOpenedByRead ? O_RDONLY : O_RDWR),\r
+       0666);\r
+    if (NewPrivateFile->fd < 0) {\r
+      if (PrivateFile->UnixThunk->GetErrno () == ENOENT) {\r
+       Status = EFI_NOT_FOUND;\r
+      } else {\r
+       Status = EFI_ACCESS_DENIED;\r
+      }\r
+    }\r
+  }\r
+\r
+  if ((OpenMode & EFI_FILE_MODE_CREATE) && Status == EFI_SUCCESS) {\r
+    //\r
+    // Set the attribute\r
+    //\r
+    InfoSize  = 0;\r
+    Info      = NULL;\r
+\r
+    Status    = UnixSimpleFileSystemGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);\r
+\r
+    if (Status != EFI_BUFFER_TOO_SMALL) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Done;\r
+    }\r
+\r
+    Status = gBS->AllocatePool (\r
+                    EfiBootServicesData,\r
+                    InfoSize,\r
+                    (VOID **)&Info\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+\r
+    Status = UnixSimpleFileSystemGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+\r
+    Info->Attribute = Attributes;\r
+\r
+    UnixSimpleFileSystemSetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, InfoSize, Info);\r
+  }\r
+\r
+Done: ;\r
+  if (TrailingDash) {\r
+    FileName[StrLen (FileName) + 1]  = 0;\r
+    FileName[StrLen (FileName)]      = L'\\';\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    if (NewPrivateFile) {\r
+      if (NewPrivateFile->FileName) {\r
+        gBS->FreePool (NewPrivateFile->FileName);\r
+      }\r
+\r
+      gBS->FreePool (NewPrivateFile);\r
+    }\r
+  } else {\r
+    *NewHandle = &NewPrivateFile->EfiFile;\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemClose (\r
+  IN EFI_FILE  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Close the specified file handle.\r
+\r
+Arguments:\r
+\r
+  This  - Pointer to a returned opened file handle.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - The file handle has been closed.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  UNIX_EFI_FILE_PRIVATE *PrivateFile;\r
+  EFI_TPL                OldTpl;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  if (PrivateFile->fd >= 0) {\r
+    PrivateFile->UnixThunk->Close (PrivateFile->fd);\r
+  }\r
+  if (PrivateFile->Dir != NULL) {\r
+    PrivateFile->UnixThunk->CloseDir (PrivateFile->Dir);\r
+  }\r
+\r
+  PrivateFile->fd = -1;\r
+  PrivateFile->Dir = NULL;\r
+\r
+  if (PrivateFile->FileName) {\r
+    gBS->FreePool (PrivateFile->FileName);\r
+  }\r
+\r
+  gBS->FreePool (PrivateFile);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  \r
+  return EFI_SUCCESS;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemDelete (\r
+  IN EFI_FILE  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Close and delete a file.\r
+\r
+Arguments:\r
+\r
+  This  - Pointer to a returned opened file handle.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             - The file handle was closed and deleted.\r
+\r
+  EFI_WARN_DELETE_FAILURE - The handle was closed but could not be deleted.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  UNIX_EFI_FILE_PRIVATE   *PrivateFile;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  Status      = EFI_WARN_DELETE_FAILURE;\r
+\r
+  if (PrivateFile->IsDirectoryPath) {\r
+    if (PrivateFile->Dir != NULL) {\r
+      PrivateFile->UnixThunk->CloseDir (PrivateFile->Dir);\r
+      PrivateFile->Dir = NULL;\r
+    }\r
+\r
+    if (PrivateFile->UnixThunk->RmDir (PrivateFile->FileName) == 0) {\r
+      Status = EFI_SUCCESS;\r
+    }\r
+  } else {\r
+    PrivateFile->UnixThunk->Close (PrivateFile->fd);\r
+    PrivateFile->fd = -1;\r
+\r
+    if (!PrivateFile->IsOpenedByRead) {\r
+      if (!PrivateFile->UnixThunk->UnLink (PrivateFile->FileName)) {\r
+        Status = EFI_SUCCESS;\r
+      }\r
+    }\r
+  }\r
+\r
+  gBS->FreePool (PrivateFile->FileName);\r
+  gBS->FreePool (PrivateFile);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+STATIC\r
+VOID\r
+UnixSystemTimeToEfiTime (\r
+  EFI_UNIX_THUNK_PROTOCOL        *UnixThunk,\r
+  IN time_t                 SystemTime,\r
+  OUT EFI_TIME              *Time\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  SystemTime  - TODO: add argument description\r
+  TimeZone    - TODO: add argument description\r
+  Time        - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  struct tm *tm;\r
+  tm = UnixThunk->GmTime (&SystemTime);\r
+  Time->Year   = tm->tm_year;\r
+  Time->Month  = tm->tm_mon;\r
+  Time->Day    = tm->tm_mday;\r
+  Time->Hour   = tm->tm_hour;\r
+  Time->Minute = tm->tm_min;\r
+  Time->Second = tm->tm_sec;\r
+  Time->Nanosecond  = 0;\r
+\r
+  Time->TimeZone    = UnixThunk->GetTimeZone ();\r
+\r
+  if (UnixThunk->GetDayLight ()) {\r
+    Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT;\r
+  }\r
+}\r
+\r
+STATIC\r
+EFI_STATUS\r
+UnixSimpleFileSystemFileInfo (\r
+  UNIX_EFI_FILE_PRIVATE          *PrivateFile,\r
+  IN     CHAR8                    *FileName,\r
+  IN OUT UINTN                    *BufferSize,\r
+  OUT    VOID                     *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  PrivateFile - TODO: add argument description\r
+  BufferSize  - TODO: add argument description\r
+  Buffer      - TODO: add argument description\r
+\r
+Returns:\r
+\r
+  TODO: add return values\r
+\r
+--*/\r
+{\r
+  EFI_STATUS                  Status;\r
+  UINTN                       Size;\r
+  UINTN                       NameSize;\r
+  UINTN                       ResultSize;\r
+  EFI_FILE_INFO               *Info;\r
+  CHAR8                      *RealFileName;\r
+  CHAR8                      *TempPointer;\r
+  CHAR16                      *BufferFileName;\r
+  struct stat                 buf;\r
+\r
+  if (FileName != NULL) {\r
+    RealFileName = FileName;\r
+  }\r
+  else if (PrivateFile->IsRootDirectory) {\r
+    RealFileName = "";\r
+  } else {\r
+    RealFileName  = PrivateFile->FileName;\r
+  }\r
+\r
+  TempPointer   = RealFileName;\r
+  while (*TempPointer) {\r
+    if (*TempPointer == '/') {\r
+      RealFileName = TempPointer + 1;\r
+    }\r
+\r
+    TempPointer++;\r
+  }\r
+\r
+  Size        = SIZE_OF_EFI_FILE_INFO;\r
+  NameSize    = AsciiStrSize (RealFileName) * 2;\r
+  ResultSize  = Size + NameSize;\r
+\r
+  if (*BufferSize < ResultSize) {\r
+    *BufferSize = ResultSize;\r
+    return EFI_BUFFER_TOO_SMALL;\r
+  }\r
+  if (PrivateFile->UnixThunk->Stat (\r
+          FileName == NULL ? PrivateFile->FileName : FileName,\r
+         &buf) < 0)\r
+    return EFI_DEVICE_ERROR;\r
+\r
+  Status  = EFI_SUCCESS;\r
+\r
+  Info    = Buffer;\r
+  ZeroMem (Info, ResultSize);\r
+\r
+  Info->Size = ResultSize;\r
+  Info->FileSize      = buf.st_size;\r
+  Info->PhysicalSize  = MultU64x32 (buf.st_blocks, buf.st_blksize);\r
+\r
+  UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_ctime, &Info->CreateTime);\r
+  UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_atime, &Info->LastAccessTime);\r
+  UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_mtime, &Info->ModificationTime);\r
+\r
+  if (!(buf.st_mode & S_IWUSR)) {\r
+    Info->Attribute |= EFI_FILE_READ_ONLY;\r
+  }\r
+\r
+  if (S_ISDIR(buf.st_mode)) {\r
+    Info->Attribute |= EFI_FILE_DIRECTORY;\r
+  }\r
+\r
+\r
+  BufferFileName = (CHAR16 *)((CHAR8 *) Buffer + Size);\r
+  while (*RealFileName)\r
+    *BufferFileName++ = *RealFileName++;\r
+  *BufferFileName = 0;\r
+\r
+  *BufferSize = ResultSize;\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemRead (\r
+  IN     EFI_FILE  *This,\r
+  IN OUT UINTN     *BufferSize,\r
+  OUT    VOID      *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Read data from a file.\r
+\r
+Arguments:\r
+\r
+  This        - Pointer to a returned open file handle.\r
+\r
+  BufferSize  - On input, the size of the Buffer.  On output, the number of bytes stored in the Buffer.\r
+\r
+  Buffer      - Pointer to the first byte of the read Buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The data was read.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupted.\r
+\r
+  EFI_BUFFER_TOO_SMALL  - The supplied buffer size was too small to store the current directory entry.\r
+                          *BufferSize has been updated with the size needed to complete the request.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  UNIX_EFI_FILE_PRIVATE *PrivateFile;\r
+  EFI_STATUS              Status;\r
+  INTN                    Res;\r
+  UINTN                   Size;\r
+  UINTN                   NameSize;\r
+  UINTN                   ResultSize;\r
+  CHAR8                   *FullFileName;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  if (This == NULL || BufferSize == NULL || Buffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (!PrivateFile->IsDirectoryPath) {\r
+\r
+    if (PrivateFile->fd < 0) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Done;\r
+    }\r
+\r
+    Res = PrivateFile->UnixThunk->Read (\r
+                                        PrivateFile->fd,\r
+                                        Buffer,\r
+                                        *BufferSize);\r
+    if (Res < 0) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Done;\r
+    }\r
+    *BufferSize = Res;\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Read on a directory.\r
+  //\r
+  if (PrivateFile->Dir == NULL) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto Done;\r
+  }\r
+\r
+  if (PrivateFile->Dirent == NULL) {\r
+    PrivateFile->Dirent = PrivateFile->UnixThunk->ReadDir (PrivateFile->Dir);\r
+    if (PrivateFile->Dirent == NULL) {\r
+      *BufferSize = 0;\r
+      Status = EFI_SUCCESS;\r
+      goto Done;\r
+    }\r
+  }\r
+\r
+  Size        = SIZE_OF_EFI_FILE_INFO;\r
+  NameSize    = AsciiStrLen (PrivateFile->Dirent->d_name) + 1;\r
+  ResultSize  = Size + 2 * NameSize;\r
+\r
+  if (*BufferSize < ResultSize) {\r
+    *BufferSize = ResultSize;\r
+    Status = EFI_BUFFER_TOO_SMALL;\r
+    goto Done;\r
+  }\r
+  Status  = EFI_SUCCESS;\r
+\r
+  *BufferSize = ResultSize;\r
+\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  AsciiStrLen(PrivateFile->FileName) + 1 + NameSize,\r
+                  (VOID **)&FullFileName\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+                 \r
+  AsciiStrCpy(FullFileName, PrivateFile->FileName);\r
+  AsciiStrCat(FullFileName, "/");\r
+  AsciiStrCat(FullFileName, PrivateFile->Dirent->d_name);\r
+  Status = UnixSimpleFileSystemFileInfo (PrivateFile,\r
+                                         FullFileName,\r
+                                         BufferSize,\r
+                                         Buffer);\r
+  gBS->FreePool (FullFileName);\r
+\r
+  PrivateFile->Dirent = NULL;\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemWrite (\r
+  IN     EFI_FILE  *This,\r
+  IN OUT UINTN     *BufferSize,\r
+  IN     VOID      *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Write data to a file.\r
+\r
+Arguments:\r
+\r
+  This        - Pointer to an opened file handle.\r
+\r
+  BufferSize  - On input, the number of bytes in the Buffer to write to the file.  On output, the number of bytes\r
+                of data written to the file.\r
+\r
+  Buffer      - Pointer to the first by of data in the buffer to write to the file.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The data was written to the file.\r
+\r
+  EFI_UNSUPPORTED       - Writes to an open directory are not supported.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupt.\r
+\r
+  EFI_WRITE_PROTECTED   - The file, directory, volume, or device is write protected.\r
+\r
+  EFI_ACCESS_DENIED     - The file was opened read-only.\r
+\r
+  EFI_VOLUME_FULL       - The volume is full.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  UNIX_EFI_FILE_PRIVATE *PrivateFile;\r
+  UINTN                 Res;\r
+  EFI_STATUS            Status;\r
+  EFI_TPL               OldTpl;\r
+\r
+  if (This == NULL || BufferSize == NULL || Buffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (PrivateFile->fd < 0) {\r
+    return EFI_DEVICE_ERROR;\r
+  }\r
+\r
+  if (PrivateFile->IsDirectoryPath) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  if (PrivateFile->IsOpenedByRead) {\r
+    return EFI_ACCESS_DENIED;\r
+  }\r
+\r
+  Res = PrivateFile->UnixThunk->Write (\r
+                                       PrivateFile->fd,\r
+                                       Buffer,\r
+                                       *BufferSize);\r
+  if (Res == (UINTN)-1) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto Done;\r
+  }\r
+  *BufferSize = Res;\r
+  Status = EFI_SUCCESS;\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+\r
+  //\r
+  // bugbug: need to access unix error reporting\r
+  //\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemSetPosition (\r
+  IN EFI_FILE  *This,\r
+  IN UINT64    Position\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Set a file's current position.\r
+\r
+Arguments:\r
+\r
+  This      - Pointer to an opened file handle.\r
+\r
+  Position  - The byte position from the start of the file to set.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS     - The file position has been changed.\r
+\r
+  EFI_UNSUPPORTED - The seek request for non-zero is not supported for directories.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  UNIX_EFI_FILE_PRIVATE *PrivateFile;\r
+  UINT64                  Pos;\r
+  EFI_TPL                 OldTpl;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (PrivateFile->IsDirectoryPath) {\r
+    if (Position != 0) {\r
+      Status = EFI_UNSUPPORTED;\r
+      goto Done;\r
+    }\r
+\r
+    if (PrivateFile->Dir == NULL) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Done;\r
+    }\r
+    PrivateFile->UnixThunk->RewindDir (PrivateFile->Dir);\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  } else {\r
+    if (Position == (UINT64) -1) {\r
+      Pos = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, 0, SEEK_END);\r
+    } else {\r
+      Pos = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, Position, SEEK_SET);\r
+    }\r
+    Status = (Pos == (UINT64) -1) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
+  }\r
+\r
+Done:\r
+    gBS->RestoreTPL (OldTpl);\r
+    return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemGetPosition (\r
+  IN  EFI_FILE  *This,\r
+  OUT UINT64    *Position\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get a file's current position.\r
+\r
+Arguments:\r
+\r
+  This      - Pointer to an opened file handle.\r
+\r
+  Position  - Pointer to storage for the current position.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS     - The file position has been reported.\r
+\r
+  EFI_UNSUPPORTED - Not valid for directories.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  EFI_STATUS            Status;\r
+  UNIX_EFI_FILE_PRIVATE *PrivateFile;\r
+  EFI_TPL               OldTpl;\r
+\r
+  if (This == NULL || Position == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile   = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+  if (PrivateFile->IsDirectoryPath) {\r
+    Status = EFI_UNSUPPORTED;\r
+  } else {\r
+    *Position = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, 0, SEEK_CUR);\r
+    Status = (*Position == (UINT64) -1) ? EFI_DEVICE_ERROR : EFI_SUCCESS;\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemGetInfo (\r
+  IN     EFI_FILE  *This,\r
+  IN     EFI_GUID  *InformationType,\r
+  IN OUT UINTN     *BufferSize,\r
+  OUT    VOID      *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Return information about a file or volume.\r
+\r
+Arguments:\r
+\r
+  This            - Pointer to an opened file handle.\r
+\r
+  InformationType - GUID describing the type of information to be returned.\r
+\r
+  BufferSize      - On input, the size of the information buffer.  On output, the number of bytes written to the\r
+                    information buffer.\r
+\r
+  Buffer          - Pointer to the first byte of the information buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The requested information has been written into the buffer.\r
+\r
+  EFI_UNSUPPORTED       - The InformationType is not known.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupt.\r
+\r
+  EFI_BUFFER_TOO_SMALL  - The buffer size was too small to contain the requested information.  The buffer size has\r
+                          been updated with the size needed to complete the requested operation.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  EFI_STATUS                        Status;\r
+  UNIX_EFI_FILE_PRIVATE           *PrivateFile;\r
+  EFI_FILE_SYSTEM_INFO              *FileSystemInfoBuffer;\r
+  INTN                              UnixStatus;\r
+  UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;\r
+  struct statfs                     buf;\r
+  EFI_TPL                           OldTpl;\r
+\r
+  if (This == NULL || InformationType == NULL || BufferSize == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+    \r
+  PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+  PrivateRoot = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);\r
+\r
+  Status      = EFI_UNSUPPORTED;\r
+\r
+  if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {\r
+    Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, BufferSize, Buffer);\r
+  } else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {\r
+    if (*BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {\r
+      *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);\r
+      Status = EFI_BUFFER_TOO_SMALL;\r
+      goto Done;\r
+    }\r
+\r
+    UnixStatus = PrivateFile->UnixThunk->StatFs (PrivateFile->FileName, &buf);\r
+    if (UnixStatus < 0) {\r
+        Status = EFI_DEVICE_ERROR;\r
+        goto Done;\r
+    }\r
+\r
+    FileSystemInfoBuffer            = (EFI_FILE_SYSTEM_INFO *) Buffer;\r
+    FileSystemInfoBuffer->Size      = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);\r
+    FileSystemInfoBuffer->ReadOnly  = FALSE;\r
+\r
+    //\r
+    // Succeeded\r
+    //\r
+    FileSystemInfoBuffer->VolumeSize  = MultU64x32 (buf.f_blocks, buf.f_bsize);\r
+    FileSystemInfoBuffer->FreeSpace   = MultU64x32 (buf.f_bavail, buf.f_bsize);\r
+    FileSystemInfoBuffer->BlockSize   = buf.f_bsize;\r
+\r
+\r
+    StrCpy ((CHAR16 *) FileSystemInfoBuffer->VolumeLabel, PrivateRoot->VolumeLabel);\r
+    *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);\r
+    Status      = EFI_SUCCESS;\r
+  } else if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {\r
+    if (*BufferSize < StrSize (PrivateRoot->VolumeLabel)) {\r
+      *BufferSize = StrSize (PrivateRoot->VolumeLabel);\r
+      Status = EFI_BUFFER_TOO_SMALL;\r
+      goto Done;\r
+    }\r
+\r
+    StrCpy ((CHAR16 *) Buffer, PrivateRoot->VolumeLabel);\r
+    *BufferSize = StrSize (PrivateRoot->VolumeLabel);\r
+    Status      = EFI_SUCCESS;\r
+  }\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemSetInfo (\r
+  IN EFI_FILE         *This,\r
+  IN EFI_GUID         *InformationType,\r
+  IN UINTN            BufferSize,\r
+  IN VOID             *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Set information about a file or volume.\r
+\r
+Arguments:\r
+\r
+  This            - Pointer to an opened file handle.\r
+\r
+  InformationType - GUID identifying the type of information to set.\r
+\r
+  BufferSize      - Number of bytes of data in the information buffer.\r
+\r
+  Buffer          - Pointer to the first byte of data in the information buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The file or volume information has been updated.\r
+\r
+  EFI_UNSUPPORTED       - The information identifier is not recognised.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupt.\r
+\r
+  EFI_WRITE_PROTECTED   - The file, directory, volume, or device is write protected.\r
+\r
+  EFI_ACCESS_DENIED     - The file was opened read-only.\r
+\r
+  EFI_VOLUME_FULL       - The volume is full.\r
+\r
+  EFI_BAD_BUFFER_SIZE   - The buffer size is smaller than the type indicated by InformationType.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;\r
+  UNIX_EFI_FILE_PRIVATE           *PrivateFile;\r
+  EFI_FILE_INFO                     *OldFileInfo;\r
+  EFI_FILE_INFO                     *NewFileInfo;\r
+  EFI_STATUS                        Status;\r
+  UINTN                             OldInfoSize;\r
+  EFI_TPL                           OldTpl;\r
+  mode_t                            NewAttr;\r
+  struct stat                       OldAttr;\r
+  CHAR8                             *OldFileName;\r
+  CHAR8                             *NewFileName;\r
+  CHAR8                             *CharPointer;\r
+  BOOLEAN                           AttrChangeFlag;\r
+  BOOLEAN                           NameChangeFlag;\r
+  BOOLEAN                           SizeChangeFlag;\r
+  BOOLEAN                           TimeChangeFlag;\r
+  struct tm                         NewLastAccessSystemTime;\r
+  struct tm                         NewLastWriteSystemTime;\r
+  EFI_FILE_SYSTEM_INFO              *NewFileSystemInfo;\r
+  CHAR8                             *AsciiFilePtr;\r
+  CHAR16                            *UnicodeFilePtr;\r
+  INTN                              UnixStatus;\r
+\r
+  //\r
+  // Check for invalid parameters.\r
+  //\r
+  if (This == NULL || InformationType == NULL || BufferSize == 0 || Buffer == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  //\r
+  // Initialise locals.\r
+  //\r
+  PrivateFile               = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+  PrivateRoot               = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);\r
+\r
+  Status                    = EFI_UNSUPPORTED;\r
+  OldFileInfo               = NewFileInfo = NULL;\r
+  OldFileName               = NewFileName = NULL;\r
+  AttrChangeFlag = NameChangeFlag = SizeChangeFlag = TimeChangeFlag = FALSE;\r
+\r
+  //\r
+  // Set file system information.\r
+  //\r
+  if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {\r
+    if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {\r
+      Status = EFI_BAD_BUFFER_SIZE;\r
+      goto Done;\r
+    }\r
+\r
+    NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer;\r
+\r
+    gBS->FreePool (PrivateRoot->VolumeLabel);\r
+\r
+    PrivateRoot->VolumeLabel = NULL;\r
+    Status = gBS->AllocatePool (\r
+                    EfiBootServicesData,\r
+                    StrSize (NewFileSystemInfo->VolumeLabel),\r
+                    (VOID **)&PrivateRoot->VolumeLabel\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+\r
+    StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel);\r
+\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Set volume label information.\r
+  //\r
+  if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {\r
+    if (BufferSize < StrSize (PrivateRoot->VolumeLabel)) {\r
+      Status = EFI_BAD_BUFFER_SIZE;\r
+      goto Done;\r
+    }\r
+\r
+    StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *) Buffer);\r
+\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  }\r
+\r
+  if (!CompareGuid (InformationType, &gEfiFileInfoGuid)) {\r
+    Status = EFI_UNSUPPORTED;\r
+    goto Done;\r
+  }\r
+\r
+  if (BufferSize < SIZE_OF_EFI_FILE_INFO) {\r
+    Status = EFI_BAD_BUFFER_SIZE;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Set file/directory information.\r
+  //\r
+\r
+  //\r
+  // Check for invalid set file information parameters.\r
+  //\r
+  NewFileInfo = (EFI_FILE_INFO *) Buffer;\r
+\r
+  if (NewFileInfo->Size <= sizeof (EFI_FILE_INFO) ||\r
+      (NewFileInfo->Attribute &~(EFI_FILE_VALID_ATTR)) ||\r
+      (sizeof (UINTN) == 4 && NewFileInfo->Size > 0xFFFFFFFF)\r
+      ) {\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // bugbug: - This is not safe.  We need something like EfiStrMaxSize()\r
+  // that would have an additional parameter that would be the size\r
+  // of the string array just in case there are no NULL characters in\r
+  // the string array.\r
+  //\r
+  //\r
+  // Get current file information so we can determine what kind\r
+  // of change request this is.\r
+  //\r
+  OldInfoSize = 0;\r
+  Status      = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, &OldInfoSize, NULL);\r
+\r
+  if (Status != EFI_BUFFER_TOO_SMALL) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto Done;\r
+  }\r
+\r
+  Status = gBS->AllocatePool (EfiBootServicesData, OldInfoSize,\r
+                             (VOID **)&OldFileInfo);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, &OldInfoSize, OldFileInfo);\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  AsciiStrSize (PrivateFile->FileName),\r
+                  (VOID **)&OldFileName\r
+                  );\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+\r
+  AsciiStrCpy (OldFileName, PrivateFile->FileName);\r
+\r
+  //\r
+  // Make full pathname from new filename and rootpath.\r
+  //\r
+  if (NewFileInfo->FileName[0] == '\\') {\r
+    Status = gBS->AllocatePool (\r
+                    EfiBootServicesData,\r
+                    AsciiStrLen (PrivateRoot->FilePath) + 1 + StrLen (NewFileInfo->FileName) + 1,\r
+                    (VOID **)&NewFileName\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+\r
+    AsciiStrCpy (NewFileName, PrivateRoot->FilePath);\r
+    AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);\r
+    UnicodeFilePtr = NewFileInfo->FileName + 1;\r
+    *AsciiFilePtr++ ='/';\r
+  } else {\r
+    Status = gBS->AllocatePool (\r
+                    EfiBootServicesData,\r
+                    AsciiStrLen (PrivateFile->FileName) + 1 + StrLen (NewFileInfo->FileName) + 1,\r
+                    (VOID **)&NewFileName\r
+                    );\r
+\r
+    if (EFI_ERROR (Status)) {\r
+      goto Done;\r
+    }\r
+\r
+    AsciiStrCpy (NewFileName, PrivateRoot->FilePath);\r
+    AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);\r
+    while (AsciiFilePtr > NewFileName && AsciiFilePtr[-1] != '/') {\r
+      AsciiFilePtr--;\r
+    }\r
+    UnicodeFilePtr = NewFileInfo->FileName;\r
+  }\r
+  // Convert to ascii.\r
+  while (*UnicodeFilePtr) {\r
+    *AsciiFilePtr++ = *UnicodeFilePtr++;\r
+  }\r
+  *AsciiFilePtr = 0;\r
+\r
+\r
+  //\r
+  // Is there an attribute change request?\r
+  //\r
+  if (NewFileInfo->Attribute != OldFileInfo->Attribute) {\r
+    if ((NewFileInfo->Attribute & EFI_FILE_DIRECTORY) != (OldFileInfo->Attribute & EFI_FILE_DIRECTORY)) {\r
+      Status = EFI_INVALID_PARAMETER;\r
+      goto Done;\r
+    }\r
+\r
+    AttrChangeFlag = TRUE;\r
+  }\r
+\r
+  //\r
+  // Is there a name change request?\r
+  // bugbug: - Need EfiStrCaseCmp()\r
+  //\r
+  if (StrCmp (NewFileInfo->FileName, OldFileInfo->FileName)) {\r
+    NameChangeFlag = TRUE;\r
+  }\r
+\r
+  //\r
+  // Is there a size change request?\r
+  //\r
+  if (NewFileInfo->FileSize != OldFileInfo->FileSize) {\r
+    SizeChangeFlag = TRUE;\r
+  }\r
+\r
+  //\r
+  // Is there a time stamp change request?\r
+  //\r
+  if (!IsZero (&NewFileInfo->CreateTime, sizeof (EFI_TIME)) &&\r
+      CompareMem (&NewFileInfo->CreateTime, &OldFileInfo->CreateTime, sizeof (EFI_TIME))\r
+        ) {\r
+    TimeChangeFlag = TRUE;\r
+  } else if (!IsZero (&NewFileInfo->LastAccessTime, sizeof (EFI_TIME)) &&\r
+           CompareMem (&NewFileInfo->LastAccessTime, &OldFileInfo->LastAccessTime, sizeof (EFI_TIME))\r
+            ) {\r
+    TimeChangeFlag = TRUE;\r
+  } else if (!IsZero (&NewFileInfo->ModificationTime, sizeof (EFI_TIME)) &&\r
+           CompareMem (&NewFileInfo->ModificationTime, &OldFileInfo->ModificationTime, sizeof (EFI_TIME))\r
+            ) {\r
+    TimeChangeFlag = TRUE;\r
+  }\r
+\r
+  //\r
+  // All done if there are no change requests being made.\r
+  //\r
+  if (!(AttrChangeFlag || NameChangeFlag || SizeChangeFlag || TimeChangeFlag)) {\r
+    Status = EFI_SUCCESS;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Set file or directory information.\r
+  //\r
+  if (PrivateFile->UnixThunk->Stat (OldFileName, &OldAttr) != 0) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto Done;\r
+  }\r
+\r
+  //\r
+  // Name change.\r
+  //\r
+  if (NameChangeFlag) {\r
+    //\r
+    // Close the handles first\r
+    //\r
+    if (PrivateFile->IsOpenedByRead) {\r
+      Status = EFI_ACCESS_DENIED;\r
+      goto Done;\r
+    }\r
+\r
+    for (CharPointer = NewFileName; *CharPointer != 0 && *CharPointer != L'/'; CharPointer++) {\r
+    }\r
+\r
+    if (*CharPointer != 0) {\r
+      Status = EFI_ACCESS_DENIED;\r
+      goto Done;\r
+    }\r
+\r
+    UnixStatus = PrivateFile->UnixThunk->Rename (OldFileName, NewFileName);\r
+\r
+    if (UnixStatus == 0) {\r
+      //\r
+      // modify file name\r
+      //\r
+      gBS->FreePool (PrivateFile->FileName);\r
+\r
+      Status = gBS->AllocatePool (\r
+                      EfiBootServicesData,\r
+                      AsciiStrSize (NewFileName),\r
+                      (VOID **)&PrivateFile->FileName\r
+                      );\r
+\r
+      if (EFI_ERROR (Status)) {\r
+        goto Done;\r
+      }\r
+\r
+      AsciiStrCpy (PrivateFile->FileName, NewFileName);\r
+    } else {\r
+      Status    = EFI_DEVICE_ERROR;\r
+      goto Done;\r
+    }\r
+  }\r
+\r
+  //\r
+  //  Size change\r
+  //\r
+  if (SizeChangeFlag) {\r
+    if (PrivateFile->IsDirectoryPath) {\r
+      Status = EFI_UNSUPPORTED;\r
+      goto Done;\r
+    }\r
+\r
+    if (PrivateFile->IsOpenedByRead || OldFileInfo->Attribute & EFI_FILE_READ_ONLY) {\r
+      Status = EFI_ACCESS_DENIED;\r
+      goto Done;\r
+    }\r
+\r
+    if (PrivateFile->UnixThunk->FTruncate (PrivateFile->fd, NewFileInfo->FileSize) != 0) {\r
+      Status = EFI_DEVICE_ERROR;\r
+      goto Done;\r
+    }\r
+\r
+  }\r
+\r
+  //\r
+  // Time change\r
+  //\r
+  if (TimeChangeFlag) {\r
+    struct utimbuf utime;\r
+\r
+    NewLastAccessSystemTime.tm_year    = NewFileInfo->LastAccessTime.Year;\r
+    NewLastAccessSystemTime.tm_mon     = NewFileInfo->LastAccessTime.Month;\r
+    NewLastAccessSystemTime.tm_mday    = NewFileInfo->LastAccessTime.Day;\r
+    NewLastAccessSystemTime.tm_hour    = NewFileInfo->LastAccessTime.Hour;\r
+    NewLastAccessSystemTime.tm_min     = NewFileInfo->LastAccessTime.Minute;\r
+    NewLastAccessSystemTime.tm_sec     = NewFileInfo->LastAccessTime.Second;\r
+    NewLastAccessSystemTime.tm_isdst   = 0;\r
+\r
+    utime.actime = PrivateFile->UnixThunk->MkTime (&NewLastAccessSystemTime);\r
+\r
+    NewLastWriteSystemTime.tm_year    = NewFileInfo->ModificationTime.Year;\r
+    NewLastWriteSystemTime.tm_mon     = NewFileInfo->ModificationTime.Month;\r
+    NewLastWriteSystemTime.tm_mday    = NewFileInfo->ModificationTime.Day;\r
+    NewLastWriteSystemTime.tm_hour    = NewFileInfo->ModificationTime.Hour;\r
+    NewLastWriteSystemTime.tm_min     = NewFileInfo->ModificationTime.Minute;\r
+    NewLastWriteSystemTime.tm_sec     = NewFileInfo->ModificationTime.Second;\r
+    NewLastWriteSystemTime.tm_isdst   = 0;\r
+\r
+    utime.modtime = PrivateFile->UnixThunk->MkTime (&NewLastWriteSystemTime);\r
+\r
+    if (utime.actime == (time_t)-1 || utime.modtime == (time_t)-1) {\r
+      goto Done;\r
+    }\r
+\r
+    if (PrivateFile->UnixThunk->UTime (PrivateFile->FileName, &utime) == -1) {\r
+      goto Done;\r
+    }\r
+  }\r
+\r
+  //\r
+  // No matter about AttrChangeFlag, Attribute must be set.\r
+  // Because operation before may cause attribute change.\r
+  //\r
+  NewAttr = OldAttr.st_mode;\r
+\r
+  if (NewFileInfo->Attribute & EFI_FILE_READ_ONLY) {\r
+    NewAttr &= ~(S_IRUSR | S_IRGRP | S_IROTH);\r
+  } else {\r
+    NewAttr |= S_IRUSR;\r
+  }\r
+\r
+  UnixStatus = PrivateFile->UnixThunk->Chmod (NewFileName, NewAttr);\r
+\r
+  if (UnixStatus != 0) {\r
+    Status    = EFI_DEVICE_ERROR;\r
+  }\r
+\r
+Done:\r
+  if (OldFileInfo != NULL) {\r
+    gBS->FreePool (OldFileInfo);\r
+  }\r
+\r
+  if (OldFileName != NULL) {\r
+    gBS->FreePool (OldFileName);\r
+  }\r
+\r
+  if (NewFileName != NULL) {\r
+    gBS->FreePool (NewFileName);\r
+  }\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+  \r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemFlush (\r
+  IN EFI_FILE  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Flush all modified data to the media.\r
+\r
+Arguments:\r
+\r
+  This  - Pointer to an opened file handle.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The data has been flushed.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures have been corrupted.\r
+\r
+  EFI_WRITE_PROTECTED   - The file, directory, volume, or device is write protected.\r
+\r
+  EFI_ACCESS_DENIED     - The file was opened read-only.\r
+\r
+  EFI_VOLUME_FULL       - The volume is full.\r
+\r
+--*/\r
+// TODO:    EFI_INVALID_PARAMETER - add return value to function comment\r
+{\r
+  UNIX_EFI_FILE_PRIVATE     *PrivateFile;\r
+  EFI_STATUS                Status;\r
+  EFI_TPL                   OldTpl;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = EFI_SUCCESS;\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+  \r
+  PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
+\r
+\r
+  if (PrivateFile->IsDirectoryPath) {\r
+    goto Done;\r
+  }\r
+\r
+  if (PrivateFile->IsOpenedByRead) {\r
+    Status = EFI_ACCESS_DENIED;\r
+    goto Done;\r
+  }\r
+\r
+  if (PrivateFile->fd < 0) {\r
+    Status = EFI_DEVICE_ERROR;\r
+    goto Done;\r
+  }\r
+\r
+  PrivateFile->UnixThunk->FSync (PrivateFile->fd) == 0 ? EFI_SUCCESS : EFI_DEVICE_ERROR;\r
+\r
+Done:\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+\r
+  //\r
+  // bugbug: - Use Unix error reporting.\r
+  //\r
+}\r
+\r
+\r
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h
new file mode 100644 (file)
index 0000000..51dce83
--- /dev/null
@@ -0,0 +1,599 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+  UnixSimpleFileSystem.h\r
+\r
+Abstract:\r
+\r
+  Produce Simple File System abstractions for a directory on your PC using Unix APIs.\r
+  The configuration of what devices to mount or emulate comes from  \r
+  environment variables.\r
+\r
+--*/\r
+\r
+#ifndef _UNIX_SIMPLE_FILE_SYSTEM_H_\r
+#define _UNIX_SIMPLE_FILE_SYSTEM_H_\r
+\r
+#include "PiDxe.h"\r
+#include <Guid/FileSystemInfo.h>\r
+#include <Guid/FileInfo.h>\r
+#include <Guid/FileSystemVolumeLabelInfo.h>\r
+#include <Protocol/SimpleFileSystem.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include "UnixDxe.h"\r
+\r
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixSimpleFileSystemDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixSimpleFileSystemComponentName;\r
+\r
+\r
+#define UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('L', 'X', 'f', 's')\r
+\r
+typedef struct {\r
+  UINTN                           Signature;\r
+  EFI_UNIX_THUNK_PROTOCOL        *UnixThunk;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFileSystem;\r
+  CHAR8                           *FilePath;\r
+  CHAR16                          *VolumeLabel;\r
+  EFI_UNICODE_STRING_TABLE        *ControllerNameTable;\r
+} UNIX_SIMPLE_FILE_SYSTEM_PRIVATE;\r
+\r
+#define UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS(a) \\r
+  CR (a, \\r
+      UNIX_SIMPLE_FILE_SYSTEM_PRIVATE, \\r
+      SimpleFileSystem, \\r
+      UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE \\r
+      )\r
+\r
+#define UNIX_EFI_FILE_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('l', 'o', 'f', 's')\r
+\r
+typedef struct {\r
+  UINTN                           Signature;\r
+  EFI_UNIX_THUNK_PROTOCOL        *UnixThunk;\r
+  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;\r
+  EFI_FILE                        EfiFile;\r
+  INTN                            fd;
+  DIR                             *Dir;
+  BOOLEAN                         IsRootDirectory;\r
+  BOOLEAN                         IsDirectoryPath;\r
+  BOOLEAN                         IsOpenedByRead;\r
+  char                            *FileName;\r
+  struct dirent                   *Dirent;
+} UNIX_EFI_FILE_PRIVATE;\r
+\r
+#define UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS(a) \\r
+  CR (a, \\r
+      UNIX_EFI_FILE_PRIVATE, \\r
+      EfiFile, \\r
+      UNIX_EFI_FILE_PRIVATE_SIGNATURE \\r
+      )\r
+\r
+//\r
+// Global Protocol Variables\r
+//\r
+extern EFI_DRIVER_BINDING_PROTOCOL  gUnixSimpleFileSystemDriverBinding;\r
+extern EFI_COMPONENT_NAME_PROTOCOL  gUnixSimpleFileSystemComponentName;\r
+\r
+//\r
+// Driver Binding protocol member functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL     *RemainingDevicePath  OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Check to see if the driver supports a given controller.\r
+\r
+Arguments:\r
+\r
+  This                - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.\r
+\r
+  ControllerHandle    - EFI handle of the controller to test.\r
+\r
+  RemainingDevicePath - Pointer to remaining portion of a device path.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS         - The device specified by ControllerHandle and RemainingDevicePath is supported by the driver\r
+                        specified by This.\r
+\r
+  EFI_ALREADY_STARTED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by\r
+                        the driver specified by This.\r
+\r
+  EFI_ACCESS_DENIED   - The device specified by ControllerHandle and RemainingDevicePath is already being managed by\r
+                        a different driver or an application that requires exclusive access.\r
+\r
+  EFI_UNSUPPORTED     - The device specified by ControllerHandle and RemainingDevicePath is not supported by the\r
+                        driver specified by This.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL   *This,\r
+  IN  EFI_HANDLE                    ControllerHandle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL      *RemainingDevicePath  OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Starts a device controller or a bus controller.\r
+\r
+Arguments:\r
+\r
+  This                - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.\r
+\r
+  ControllerHandle    - EFI handle of the controller to start.\r
+\r
+  RemainingDevicePath - Pointer to remaining portion of a device path.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The device or bus controller has been started.\r
+\r
+  EFI_DEVICE_ERROR      - The device could not be started due to a device failure.\r
+\r
+  EFI_OUT_OF_RESOURCES  - The request could not be completed due to lack of resources.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   ControllerHandle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer  OPTIONAL\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  TODO: Add function description\r
+\r
+Arguments:\r
+\r
+  This              - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.\r
+\r
+  ControllerHandle  - A handle to the device to be stopped.\r
+\r
+  NumberOfChildren  - The number of child device handles in ChildHandleBuffer.\r
+\r
+  ChildHandleBuffer - An array of child device handles to be freed.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS       - The device has been stopped.\r
+\r
+  EFI_DEVICE_ERROR  - The device could not be stopped due to a device failure.\r
+\r
+--*/\r
+;\r
+\r
+//\r
+// Simple File System protocol member functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemOpenVolume (\r
+  IN  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r
+  OUT EFI_FILE                        **Root\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Open the root directory on a volume.\r
+\r
+Arguments:\r
+\r
+  This  - A pointer to the volume to open.\r
+\r
+  Root  - A pointer to storage for the returned opened file handle of the root directory.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The volume was opened.\r
+\r
+  EFI_UNSUPPORTED       - The volume does not support the requested file system type.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupted.\r
+\r
+  EFI_ACCESS_DENIED     - The service denied access to the file.\r
+\r
+  EFI_OUT_OF_RESOURCES  - The file volume could not be opened due to lack of resources.\r
+\r
+  EFI_MEDIA_CHANGED     - The device has new media or the media is no longer supported.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemOpen (\r
+  IN  EFI_FILE  *This,\r
+  OUT EFI_FILE  **NewHandle,\r
+  IN  CHAR16    *FileName,\r
+  IN  UINT64    OpenMode,\r
+  IN  UINT64    Attributes\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Open a file relative to the source file location.\r
+\r
+Arguments:\r
+\r
+  This        - A pointer to the source file location.\r
+\r
+  NewHandle   - Pointer to storage for the new file handle.\r
+\r
+  FileName    - Pointer to the file name to be opened.\r
+\r
+  OpenMode    - File open mode information.\r
+\r
+  Attributes  - File creation attributes.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The file was opened.\r
+\r
+  EFI_NOT_FOUND         - The file could not be found in the volume.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_MEDIA_CHANGED     - The device has new media or the media is no longer supported.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupted.\r
+\r
+  EFI_WRITE_PROTECTED   - The volume or file is write protected.\r
+\r
+  EFI_ACCESS_DENIED     - The service denied access to the file.\r
+\r
+  EFI_OUT_OF_RESOURCES  - Not enough resources were available to open the file.\r
+\r
+  EFI_VOLUME_FULL       - There is not enough space left to create the new file.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemClose (\r
+  IN EFI_FILE  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Close the specified file handle.\r
+\r
+Arguments:\r
+\r
+  This  - Pointer to a returned opened file handle.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS - The file handle has been closed.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemDelete (\r
+  IN EFI_FILE  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Close and delete a file.\r
+\r
+Arguments:\r
+\r
+  This  - Pointer to a returned opened file handle.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS             - The file handle was closed and deleted.\r
+\r
+  EFI_WARN_DELETE_FAILURE - The handle was closed but could not be deleted.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemRead (\r
+  IN     EFI_FILE  *This,\r
+  IN OUT UINTN     *BufferSize,\r
+  OUT    VOID      *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Read data from a file.\r
+\r
+Arguments:\r
+\r
+  This        - Pointer to a returned open file handle.\r
+\r
+  BufferSize  - On input, the size of the Buffer.  On output, the number of bytes stored in the Buffer.\r
+\r
+  Buffer      - Pointer to the first byte of the read Buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The data was read.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupted.\r
+\r
+  EFI_BUFFER_TOO_SMALL  - The supplied buffer size was too small to store the current directory entry.\r
+                          *BufferSize has been updated with the size needed to complete the request.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemWrite (\r
+  IN     EFI_FILE  *This,\r
+  IN OUT UINTN     *BufferSize,\r
+  IN     VOID      *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Write data to a file.\r
+\r
+Arguments:\r
+\r
+  This        - Pointer to an opened file handle.\r
+\r
+  BufferSize  - On input, the number of bytes in the Buffer to write to the file.  On output, the number of bytes\r
+                of data written to the file.\r
+\r
+  Buffer      - Pointer to the first by of data in the buffer to write to the file.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The data was written to the file.\r
+\r
+  EFI_UNSUPPORTED       - Writes to an open directory are not supported.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupt.\r
+\r
+  EFI_WRITE_PROTECTED   - The file, directory, volume, or device is write protected.\r
+\r
+  EFI_ACCESS_DENIED     - The file was opened read-only.\r
+\r
+  EFI_VOLUME_FULL       - The volume is full.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemSetPosition (\r
+  IN EFI_FILE  *This,\r
+  IN UINT64    Position\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Set a file's current position.\r
+\r
+Arguments:\r
+\r
+  This      - Pointer to an opened file handle.\r
+\r
+  Position  - The byte position from the start of the file to set.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS     - The file position has been changed.\r
+\r
+  EFI_UNSUPPORTED - The seek request for non-zero is not supported for directories.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemGetPosition (\r
+  IN  EFI_FILE  *This,\r
+  OUT UINT64    *Position\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Get a file's current position.\r
+\r
+Arguments:\r
+\r
+  This      - Pointer to an opened file handle.\r
+\r
+  Position  - Pointer to storage for the current position.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS     - The file position has been reported.\r
+\r
+  EFI_UNSUPPORTED - Not valid for directories.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemGetInfo (\r
+  IN     EFI_FILE  *This,\r
+  IN     EFI_GUID  *InformationType,\r
+  IN OUT UINTN     *BufferSize,\r
+  OUT    VOID      *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Return information about a file or volume.\r
+\r
+Arguments:\r
+\r
+  This            - Pointer to an opened file handle.\r
+\r
+  InformationType - GUID describing the type of information to be returned.\r
+\r
+  BufferSize      - On input, the size of the information buffer.  On output, the number of bytes written to the\r
+                    information buffer.\r
+\r
+  Buffer          - Pointer to the first byte of the information buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The requested information has been written into the buffer.\r
+\r
+  EFI_UNSUPPORTED       - The InformationType is not known.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupt.\r
+\r
+  EFI_BUFFER_TOO_SMALL  - The buffer size was too small to contain the requested information.  The buffer size has\r
+                          been updated with the size needed to complete the requested operation.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemSetInfo (\r
+  IN EFI_FILE  *This,\r
+  IN EFI_GUID  *InformationType,\r
+  IN UINTN     BufferSize,\r
+  IN VOID      *Buffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Set information about a file or volume.\r
+\r
+Arguments:\r
+\r
+  This            - Pointer to an opened file handle.\r
+\r
+  InformationType - GUID identifying the type of information to set.\r
+\r
+  BufferSize      - Number of bytes of data in the information buffer.\r
+\r
+  Buffer          - Pointer to the first byte of data in the information buffer.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The file or volume information has been updated.\r
+\r
+  EFI_UNSUPPORTED       - The information identifier is not recognised.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures are corrupt.\r
+\r
+  EFI_WRITE_PROTECTED   - The file, directory, volume, or device is write protected.\r
+\r
+  EFI_ACCESS_DENIED     - The file was opened read-only.\r
+\r
+  EFI_VOLUME_FULL       - The volume is full.\r
+\r
+  EFI_BAD_BUFFER_SIZE   - The buffer size is smaller than the type indicated by InformationType.\r
+\r
+--*/\r
+;\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixSimpleFileSystemFlush (\r
+  IN EFI_FILE  *This\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Flush all modified data to the media.\r
+\r
+Arguments:\r
+\r
+  This  - Pointer to an opened file handle.\r
+\r
+Returns:\r
+\r
+  EFI_SUCCESS           - The data has been flushed.\r
+\r
+  EFI_NO_MEDIA          - The device has no media.\r
+\r
+  EFI_DEVICE_ERROR      - The device reported an error.\r
+\r
+  EFI_VOLUME_CORRUPTED  - The file system structures have been corrupted.\r
+\r
+  EFI_WRITE_PROTECTED   - The file, directory, volume, or device is write protected.\r
+\r
+  EFI_ACCESS_DENIED     - The file was opened read-only.\r
+\r
+  EFI_VOLUME_FULL       - The volume is full.\r
+\r
+--*/\r
+;\r
+\r
+#endif /* _UNIX_SIMPLE_FILE_SYSTEM_H_ */\r
+\r
+/* eof - UnixSimpleFileSystem.h */\r
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf
new file mode 100644 (file)
index 0000000..f3cce01
--- /dev/null
@@ -0,0 +1,71 @@
+#/** @file\r
+# Simple filesystem driver\r
+#\r
+# Produce Simple File System abstractions for directories on your PC using Unix APIs.\r
+#  The configuration of what devices to mount or emulate comes from\r
+#  environment variables.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixSimpleFileSystem\r
+  FILE_GUID                      = f330834e-8985-11db-a295-0040d02b1835\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnixSimpleFileSystem\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gUnixSimpleFileSystemDriverBinding           \r
+#  COMPONENT_NAME                =  gUnixSimpleFileSystemComponentName           \r
+#\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  UnixSimpleFileSystem.c\r
+  UnixSimpleFileSystem.h\r
+  EntryPoint.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiFileSystemVolumeLabelInfoIdGuid           # SOMETIMES_CONSUMED\r
+  gEfiFileInfoGuid                              # SOMETIMES_CONSUMED\r
+  gEfiFileSystemInfoGuid                        # SOMETIMES_CONSUMED\r
+  gEfiUnixFileSystemGuid                       # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiSimpleFileSystemProtocolGuid              # PROTOCOL BY_START\r
+  gEfiUnixIoProtocolGuid                        # PROTOCOL TO_START\r
+\r
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.msa b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.msa
new file mode 100644 (file)
index 0000000..c57aa71
--- /dev/null
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>UnixSimpleFileSystem</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>f330834e-8985-11db-a295-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Simple filesystem driver</Abstract>\r
+    <Description>\r
+      Produce Simple File System abstractions for directories on your PC using Unix APIs.\r
+      The configuration of what devices to mount or emulate comes from\r
+      environment variables.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixSimpleFileSystem</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixSimpleFileSystem.h</Filename>\r
+    <Filename>UnixSimpleFileSystem.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiSimpleFileSystemProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixFileSystemGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiFileSystemInfoGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiFileInfoGuid</GuidCName>\r
+    </GuidCNames>\r
+    <GuidCNames Usage="SOMETIMES_CONSUMED">\r
+      <GuidCName>gEfiFileSystemVolumeLabelInfoIdGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gUnixSimpleFileSystemDriverBinding</DriverBinding>\r
+      <ComponentName>gUnixSimpleFileSystemComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.c b/UnixPkg/UnixThunkDxe/UnixThunk.c
new file mode 100644 (file)
index 0000000..df3512c
--- /dev/null
@@ -0,0 +1,102 @@
+/*++\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
+\r
+  UnixThunk.c\r
+\r
+Abstract:\r
+\r
+  Produce UnixThunk protocol and it's associated device path and controller \r
+  state protocols. UnixThunk is to the emulation environment as \r
+  PCI_ROOT_BRIGE is to real hardware. The UnixBusDriver is the child of this\r
+  driver.\r
+\r
+  Since we are a root hardware abstraction we do not install a Driver Binding\r
+  protocol on this handle. This driver can only support one one UnixThunk protocol\r
+  in the system, since the device path is hard coded.\r
+\r
+--*/\r
+#include "PiDxe.h"\r
+#include "UnixDxe.h"\r
+#include "UnixThunk.h"\r
+#include <Protocol/DevicePath.h>\r
+\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiLib.h>\r
+#include <Library/UefiDriverEntryPoint.h>\r
+#include <Library/UnixLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+\r
+//\r
+// WinNtThunk Device Path Protocol Instance\r
+//\r
+static UNIX_THUNK_DEVICE_PATH mUnixThunkDevicePath = {\r
+  {\r
+    {\r
+      HARDWARE_DEVICE_PATH,\r
+      HW_VENDOR_DP,\r
+      {\r
+        (UINT8) (sizeof (VENDOR_DEVICE_PATH)),\r
+        (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
+      }\r
+    },\r
+    EFI_UNIX_THUNK_PROTOCOL_GUID,\r
+  },\r
+  {\r
+    END_DEVICE_PATH_TYPE,\r
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
+    {\r
+      END_DEVICE_PATH_LENGTH,\r
+      0\r
+    }\r
+  }\r
+};\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixThunk (\r
+  IN EFI_HANDLE                            ImageHandle,\r
+  IN EFI_SYSTEM_TABLE                      *SystemTable\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+  Install UnixThunk Protocol and it's associated Device Path protocol\r
+\r
+Arguments:\r
+  (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)\r
+\r
+Returns:\r
+  EFI_SUCEESS - UnixThunk protocol is added or error status from \r
+                gBS->InstallMultiProtocolInterfaces().\r
+\r
+--*/\r
+// TODO:    ImageHandle - add argument and description to function comment\r
+// TODO:    SystemTable - add argument and description to function comment\r
+{\r
+  EFI_STATUS  Status;\r
+  EFI_HANDLE  ControllerHandle;\r
+\r
+  ControllerHandle = NULL;\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &ControllerHandle,\r
+                  &gEfiUnixThunkProtocolGuid,\r
+                  gUnix,\r
+                  &gEfiDevicePathProtocolGuid,\r
+                  &mUnixThunkDevicePath,\r
+                  NULL\r
+                  );\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.h b/UnixPkg/UnixThunkDxe/UnixThunk.h
new file mode 100644 (file)
index 0000000..ce9a2f4
--- /dev/null
@@ -0,0 +1,30 @@
+/*++\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
+\r
+  UnixThunk.h\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+// TODO: add protective #ifndef\r
+\r
+\r
+//\r
+// WinNtThunk Device Path Protocol Instance Type\r
+//\r
+typedef struct {\r
+  VENDOR_DEVICE_PATH        Vendor;\r
+  EFI_DEVICE_PATH_PROTOCOL  EndDevicePath;\r
+} UNIX_THUNK_DEVICE_PATH;\r
+\r
diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.inf b/UnixPkg/UnixThunkDxe/UnixThunk.inf
new file mode 100644 (file)
index 0000000..58bade9
--- /dev/null
@@ -0,0 +1,60 @@
+#/** @file\r
+# A DXE driver to produce EFI_UNIX_THUNK_PROTOCOL\r
+#\r
+# EFI_UNIX_THUNK_PROTOCOL is a table of pointers to various Unix APIs used by various drivers to accomplish certain task in a Unix emulator.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixThunk\r
+  FILE_GUID                      = f38610fc-8985-11db-82d4-0040d02b1835\r
+  MODULE_TYPE                    = DXE_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnixThunk\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  UnixThunk.c\r
+  UnixThunk.h\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  UnixLib\r
+  UefiDriverEntryPoint\r
+  UefiLib\r
+  DebugLib\r
+\r
+\r
+[Protocols]\r
+  gEfiDevicePathProtocolGuid                    # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiUnixThunkProtocolGuid                     # PROTOCOL ALWAYS_PRODUCED\r
+\r
+\r
+[Depex]\r
+  TRUE\r
+\r
diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.msa b/UnixPkg/UnixThunkDxe/UnixThunk.msa
new file mode 100644 (file)
index 0000000..e1f262a
--- /dev/null
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>UnixThunk</ModuleName>\r
+    <ModuleType>DXE_DRIVER</ModuleType>\r
+    <GuidValue>f38610fc-8985-11db-82d4-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>A DXE driver to produce EFI_UNIX_THUNK_PROTOCOL</Abstract>\r
+    <Description>EFI_UNIX_THUNK_PROTOCOL is a table of pointers to various Unix APIs used by various drivers to accomplish certain task in a Unix emulator.</Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixThunk</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UnixLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixThunk.h</Filename>\r
+    <Filename>UnixThunk.c</Filename>\r
+    <Filename>UnixThunk.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="ALWAYS_PRODUCED">\r
+      <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>InitializeUnixThunk</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.c b/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.c
new file mode 100644 (file)
index 0000000..4cf6c0b
--- /dev/null
@@ -0,0 +1,79 @@
+/*++\r
+\r
+Copyright (c) 2006 - 2008, 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
+\r
+    UnixStuff.c\r
+    \r
+Abstract:\r
+\r
+    Tiano PEIM to abstract construction of firmware volume in a Unix environment.\r
+\r
+Revision History\r
+\r
+--*/\r
+\r
+#include "PiPei.h"\r
+#include <Ppi/UnixThunk.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/PeimEntryPoint.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PeiServicesLib.h>\r
+#include <Library/PeiServicesTablePointerLib.h>\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+PeimInitializeUnixStuff (\r
+  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r
+  IN EFI_PEI_SERVICES          **PeiServices\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+  Perform a call-back into the SEC simulator to get Unix Stuff\r
+\r
+Arguments:\r
+\r
+  PeiServices - General purpose services available to every PEIM.\r
+    \r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    FfsHeader - add argument and description to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_PEI_PPI_DESCRIPTOR  *PpiDescriptor;\r
+  PEI_UNIX_THUNK_PPI     *PeiUnixService;\r
+  VOID                    *Ptr;\r
+\r
+  DEBUG ((EFI_D_ERROR, "Unix Stuff PEIM Loaded\n"));\r
+\r
+  Status = (**PeiServices).LocatePpi (\r
+                            PeiServices,\r
+                            &gPeiUnixThunkPpiGuid,  // GUID\r
+                            0,                    // INSTANCE\r
+                            &PpiDescriptor,       // EFI_PEI_PPI_DESCRIPTOR\r
+                            (VOID **)&PeiUnixService         // PPI\r
+                            );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  Ptr = PeiUnixService->UnixThunk ();\r
+\r
+  BuildGuidDataHob (\r
+    &gEfiUnixThunkProtocolGuid,         // Guid\r
+    &Ptr,                                // Buffer\r
+    sizeof (VOID *)                      // Sizeof Buffer\r
+    );\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf b/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf
new file mode 100644 (file)
index 0000000..d19fa2a
--- /dev/null
@@ -0,0 +1,63 @@
+#/** @file\r
+# Stuff driver\r
+#\r
+# Tiano PEIM to abstract construction of firmware volume in a Unix environment.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixThunkPpiToProtocol\r
+  FILE_GUID                      = f4239aa2-8985-11db-af82-0040d02b1835\r
+  MODULE_TYPE                    = PEIM\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = PeimInitializeUnixStuff\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+\r
+[Sources.common]\r
+  UnixThunkPpiToProtocol.c\r
+\r
+\r
+[Packages]\r
+#  MdeModulePkg/MdeModulePkg.dec\r
+  MdePkg/MdePkg.dec\r
+#  IntelFrameworkPkg/IntelFrameworkPkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  PeiServicesTablePointerLib\r
+  PeiServicesLib\r
+  HobLib\r
+  PeimEntryPoint\r
+  DebugLib\r
+\r
+\r
+[Protocols]\r
+  gEfiUnixThunkProtocolGuid                     # PROTOCOL ALWAYS_CONSUMED\r
+\r
+\r
+[Ppis]\r
+  gPeiUnixThunkPpiGuid                          # PPI ALWAYS_CONSUMED\r
+\r
+\r
+[Depex]\r
+  gPeiUnixThunkPpiGuid AND gEfiPeiMemoryDiscoveredPpiGuid\r
+\r
diff --git a/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.msa b/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.msa
new file mode 100644 (file)
index 0000000..889d98d
--- /dev/null
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>UnixStuff</ModuleName>\r
+    <ModuleType>PEIM</ModuleType>\r
+    <GuidValue>f4239aa2-8985-11db-af82-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Stuff driver</Abstract>\r
+    <Description>\r
+      Tiano PEIM to abstract construction of firmware volume in a Unix environment.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixStuff</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeimEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>HobLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>PeiServicesTablePointerLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixStuff.c</Filename>\r
+    <Filename>UnixStuff.dxs</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="ALWAYS_CONSUMED">\r
+      <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <PPIs>\r
+    <Ppi Usage="ALWAYS_CONSUMED">\r
+      <PpiCName>gPeiUnixThunkPpiGuid</PpiCName>\r
+    </Ppi>\r
+  </PPIs>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <ModuleEntryPoint>PeimInitializeUnixStuff</ModuleEntryPoint>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixUgaDxe/ComponentName.c b/UnixPkg/UnixUgaDxe/ComponentName.c
new file mode 100644 (file)
index 0000000..5c50d56
--- /dev/null
@@ -0,0 +1,198 @@
+/*++\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
+\r
+  ComponentName.c\r
+\r
+Abstract:\r
+\r
+--*/\r
+\r
+#include "UnixUga.h"\r
+\r
+//\r
+// EFI Component Name Functions\r
+//\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  );\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  );\r
+\r
+//\r
+// EFI Component Name Protocol\r
+//\r
+EFI_COMPONENT_NAME_PROTOCOL     gUnixUgaComponentName = {\r
+  UnixUgaComponentNameGetDriverName,\r
+  UnixUgaComponentNameGetControllerName,\r
+  "eng"\r
+};\r
+\r
+static EFI_UNICODE_STRING_TABLE mUnixUgaDriverNameTable[] = {\r
+  { "eng", L"Unix Universal Graphics Adapter Driver" },\r
+  { NULL , NULL }\r
+};\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaComponentNameGetDriverName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL  *This,\r
+  IN  CHAR8                        *Language,\r
+  OUT CHAR16                       **DriverName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the EFI Driver.\r
+\r
+  Arguments:\r
+    This       - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    Language   - A pointer to a three character ISO 639-2 language identifier.\r
+                 This is the language of the driver name that that the caller \r
+                 is requesting, and it must match one of the languages specified\r
+                 in SupportedLanguages.  The number of languages supported by a \r
+                 driver is up to the driver writer.\r
+    DriverName - A pointer to the Unicode string to return.  This Unicode string\r
+                 is the name of the driver specified by This in the language \r
+                 specified by Language.\r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the Driver specified by This\r
+                            and the language specified by Language was returned \r
+                            in DriverName.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - DriverName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixUgaComponentName.SupportedLanguages,\r
+          mUnixUgaDriverNameTable,\r
+          DriverName\r
+          );\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaComponentNameGetControllerName (\r
+  IN  EFI_COMPONENT_NAME_PROTOCOL                     *This,\r
+  IN  EFI_HANDLE                                      ControllerHandle,\r
+  IN  EFI_HANDLE                                      ChildHandle        OPTIONAL,\r
+  IN  CHAR8                                           *Language,\r
+  OUT CHAR16                                          **ControllerName\r
+  )\r
+/*++\r
+\r
+  Routine Description:\r
+    Retrieves a Unicode string that is the user readable name of the controller\r
+    that is being managed by an EFI Driver.\r
+\r
+  Arguments:\r
+    This             - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
+    ControllerHandle - The handle of a controller that the driver specified by \r
+                       This is managing.  This handle specifies the controller \r
+                       whose name is to be returned.\r
+    ChildHandle      - The handle of the child controller to retrieve the name \r
+                       of.  This is an optional parameter that may be NULL.  It \r
+                       will be NULL for device drivers.  It will also be NULL \r
+                       for a bus drivers that wish to retrieve the name of the \r
+                       bus controller.  It will not be NULL for a bus driver \r
+                       that wishes to retrieve the name of a child controller.\r
+    Language         - A pointer to a three character ISO 639-2 language \r
+                       identifier.  This is the language of the controller name \r
+                       that that the caller is requesting, and it must match one\r
+                       of the languages specified in SupportedLanguages.  The \r
+                       number of languages supported by a driver is up to the \r
+                       driver writer.\r
+    ControllerName   - A pointer to the Unicode string to return.  This Unicode\r
+                       string is the name of the controller specified by \r
+                       ControllerHandle and ChildHandle in the language specified\r
+                       by Language from the point of view of the driver specified\r
+                       by This. \r
+\r
+  Returns:\r
+    EFI_SUCCESS           - The Unicode string for the user readable name in the \r
+                            language specified by Language for the driver \r
+                            specified by This was returned in DriverName.\r
+    EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
+    EFI_INVALID_PARAMETER - Language is NULL.\r
+    EFI_INVALID_PARAMETER - ControllerName is NULL.\r
+    EFI_UNSUPPORTED       - The driver specified by This is not currently managing \r
+                            the controller specified by ControllerHandle and \r
+                            ChildHandle.\r
+    EFI_UNSUPPORTED       - The driver specified by This does not support the \r
+                            language specified by Language.\r
+\r
+--*/\r
+{\r
+  EFI_STATUS            Status;\r
+  EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
+  UGA_PRIVATE_DATA      *Private;\r
+\r
+  //\r
+  // This is a device driver, so ChildHandle must be NULL.\r
+  //\r
+  if (ChildHandle != NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Make sure this driver is currently managing ControllerHandle\r
+  //\r
+  Status = EfiTestManagedDevice (\r
+             ControllerHandle,\r
+             gUnixUgaDriverBinding.DriverBindingHandle,\r
+             &gEfiUnixIoProtocolGuid\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  //\r
+  // Get our context back\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  ControllerHandle,\r
+                  &gEfiUgaDrawProtocolGuid,\r
+                  (VOID **)&UgaDraw,\r
+                  gUnixUgaDriverBinding.DriverBindingHandle,\r
+                  ControllerHandle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (UgaDraw);\r
+\r
+  return LookupUnicodeString (\r
+          Language,\r
+          gUnixUgaComponentName.SupportedLanguages,\r
+          Private->ControllerNameTable,\r
+          ControllerName\r
+          );\r
+}\r
diff --git a/UnixPkg/UnixUgaDxe/EntryPoint.c b/UnixPkg/UnixUgaDxe/EntryPoint.c
new file mode 100644 (file)
index 0000000..a2ed241
--- /dev/null
@@ -0,0 +1,49 @@
+/**@file\r
+  Entry Point Source file.\r
+\r
+  This file contains the user entry point \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
+   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
+\r
+#include "UnixUga.h"\r
+\r
+/**\r
+  The user Entry Point for module UnixUga. The user code starts with this function.\r
+\r
+  @param[in] ImageHandle    The firmware allocated handle for the EFI image.  \r
+  @param[in] SystemTable    A pointer to the EFI System Table.\r
+  \r
+  @retval EFI_SUCCESS       The entry point is executed successfully.\r
+  @retval other             Some error occurs when executing this entry point.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+InitializeUnixUga(\r
+  IN EFI_HANDLE           ImageHandle,\r
+  IN EFI_SYSTEM_TABLE     *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+\r
+  Status = EfiLibInstallAllDriverProtocols (\r
+             ImageHandle,\r
+             SystemTable,\r
+             &gUnixUgaDriverBinding,\r
+             ImageHandle,\r
+             &gUnixUgaComponentName,\r
+             NULL,\r
+             NULL\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+\r
+  return Status;\r
+}\r
diff --git a/UnixPkg/UnixUgaDxe/UnixUga.h b/UnixPkg/UnixUgaDxe/UnixUga.h
new file mode 100644 (file)
index 0000000..8401029
--- /dev/null
@@ -0,0 +1,304 @@
+/*++
+
+Copyright (c) 2006 - 2008, Intel Corporation                                                         
+All rights reserved. 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        
+http://opensource.org/licenses/bsd-license.php                                            
+                                                                                          
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             
+
+Module Name:
+
+  UnixUga.h
+
+Abstract:
+
+  Private data for the Uga driver that is bound to the Unix Thunk protocol 
+
+--*/
+
+#ifndef _UNIX_UGA_H_
+#define _UNIX_UGA_H_
+
+#include "PiDxe.h"
+#include <Guid/EventGroup.h>
+#include <Protocol/SimpleTextIn.h>
+#include <Protocol/UgaDraw.h>
+#include "Protocol/UnixUgaIo.h"
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include "UnixDxe.h"
+
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixUgaDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixUgaComponentName;
+
+#define UNIX_UGA_CLASS_NAME       L"UnixUgaWindow"
+
+#define UGA_PRIVATE_DATA_SIGNATURE  EFI_SIGNATURE_32 ('S', 'g', 'o', 'N')
+typedef struct {
+  UINT64                      Signature;
+
+  EFI_HANDLE                  Handle;
+  EFI_UGA_DRAW_PROTOCOL       UgaDraw;
+  EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;
+
+  EFI_UNIX_THUNK_PROTOCOL   *UnixThunk;
+
+  EFI_UNICODE_STRING_TABLE    *ControllerNameTable;
+
+  //
+  // UGA Private Data for GetMode ()
+  //
+  UINT32                      HorizontalResolution;
+  UINT32                      VerticalResolution;
+  UINT32                      ColorDepth;
+  UINT32                      RefreshRate;
+
+  //
+  // UGA Private Data knowing when to start hardware
+  //
+  BOOLEAN                     HardwareNeedsStarting;
+
+  CHAR16                      *WindowName;
+
+  EFI_UNIX_UGA_IO_PROTOCOL    *UgaIo;
+
+} UGA_PRIVATE_DATA;
+
+#define UGA_DRAW_PRIVATE_DATA_FROM_THIS(a)  \
+         CR(a, UGA_PRIVATE_DATA, UgaDraw, UGA_PRIVATE_DATA_SIGNATURE)
+
+#define UGA_PRIVATE_DATA_FROM_TEXT_IN_THIS(a)  \
+         CR(a, UGA_PRIVATE_DATA, SimpleTextIn, UGA_PRIVATE_DATA_SIGNATURE)
+
+//
+// Global Protocol Variables
+//
+extern EFI_DRIVER_BINDING_PROTOCOL  gUnixUgaDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL  gUnixUgaComponentName;
+
+//
+// Uga Hardware abstraction internal worker functions
+//
+EFI_STATUS
+UnixUgaSupported (
+  IN  EFI_UNIX_IO_PROTOCOL  *UnixIo
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  UnixIo - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+UnixUgaConstructor (
+  IN  UGA_PRIVATE_DATA    *Private
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  Private - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+UnixUgaDestructor (
+  IN  UGA_PRIVATE_DATA    *Private
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  Private - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+;
+
+//
+// EFI 1.1 driver model prototypes for Win UNIX UGA
+//
+
+EFI_STATUS
+EFIAPI
+UnixUgaInitialize (
+  IN EFI_HANDLE            ImageHandle,
+  IN EFI_SYSTEM_TABLE      *SystemTable
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  ImageHandle - TODO: add argument description
+  SystemTable - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixUgaDriverBindingSupported (
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,
+  IN  EFI_HANDLE                      Handle,
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  This                - TODO: add argument description
+  Handle              - TODO: add argument description
+  RemainingDevicePath - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixUgaDriverBindingStart (
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,
+  IN  EFI_HANDLE                      Handle,
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  This                - TODO: add argument description
+  Handle              - TODO: add argument description
+  RemainingDevicePath - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixUgaDriverBindingStop (
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,
+  IN  EFI_HANDLE                   Handle,
+  IN  UINTN                        NumberOfChildren,
+  IN  EFI_HANDLE                   *ChildHandleBuffer
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  This              - TODO: add argument description
+  Handle            - TODO: add argument description
+  NumberOfChildren  - TODO: add argument description
+  ChildHandleBuffer - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+UgaPrivateAddQ (
+  IN  UGA_PRIVATE_DATA    *Private,
+  IN  EFI_INPUT_KEY       Key
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  Private - TODO: add argument description
+  Key     - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+UnixUgaInitializeSimpleTextInForWindow (
+  IN  UGA_PRIVATE_DATA    *Private
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  Private - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+;
+#endif
diff --git a/UnixPkg/UnixUgaDxe/UnixUga.inf b/UnixPkg/UnixUgaDxe/UnixUga.inf
new file mode 100644 (file)
index 0000000..787f193
--- /dev/null
@@ -0,0 +1,74 @@
+#/** @file\r
+# Uga driver\r
+#\r
+# UGA is short hand for Universal Graphics Abstraction protocol.\r
+#  This file is a verision of UgaIo the uses UnixThunk system calls as an IO\r
+#  abstraction. For a PCI device UnixIo would be replaced with\r
+#  a PCI IO abstraction that abstracted a specific PCI device.\r
+# Copyright (c) 2006, Intel Corporation\r
+#\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
+#  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
+#\r
+#**/\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = UnixUga\r
+  FILE_GUID                      = f33cad86-8985-11db-8040-0040d02b1835\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  EDK_RELEASE_VERSION            = 0x00020000\r
+  EFI_SPECIFICATION_VERSION      = 0x00020000\r
+\r
+  ENTRY_POINT                    = InitializeUnixUga\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#\r
+#  DRIVER_BINDING                =  gUnixUgaDriverBinding                        \r
+#  COMPONENT_NAME                =  gUnixUgaComponentName                        \r
+#\r
+\r
+[Sources.common]\r
+  ComponentName.c\r
+  UnixUgaScreen.c\r
+  UnixUgaDriver.c\r
+  UnixUgaInput.c\r
+  UnixUga.h\r
+  EntryPoint.c\r
+\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  UnixPkg/UnixPkg.dec\r
+\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  MemoryAllocationLib\r
+  BaseMemoryLib\r
+  UefiLib\r
+  UefiDriverEntryPoint\r
+  BaseLib\r
+  DebugLib\r
+\r
+\r
+[Guids]\r
+  gEfiEventExitBootServicesGuid                 # SOMETIMES_CONSUMED  Create Event: EVENT_GROUP_GUID\r
+  gEfiUnixUgaGuid                              # ALWAYS_CONSUMED\r
+\r
+\r
+[Protocols]\r
+  gEfiSimpleTextInProtocolGuid                  # PROTOCOL BY_START\r
+  gEfiUnixUgaIoProtocolGuid                     # PROTOCOL BY_START\r
+  gEfiUgaDrawProtocolGuid                       # PROTOCOL BY_START\r
+  gEfiUnixIoProtocolGuid                        # PROTOCOL TO_START\r
+\r
diff --git a/UnixPkg/UnixUgaDxe/UnixUga.msa b/UnixPkg/UnixUgaDxe/UnixUga.msa
new file mode 100644 (file)
index 0000000..864576f
--- /dev/null
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">\r
+  <MsaHeader>\r
+    <ModuleName>UnixUga</ModuleName>\r
+    <ModuleType>UEFI_DRIVER</ModuleType>\r
+    <GuidValue>f33cad86-8985-11db-8040-0040d02b1835</GuidValue>\r
+    <Version>1.0</Version>\r
+    <Abstract>Uga driver</Abstract>\r
+    <Description>\r
+      UGA is short hand for Universal Graphics Abstraction protocol.\r
+      This file is a verision of UgaIo the uses UnixThunk system calls as an IO\r
+      abstraction. For a PCI device UnixIo would be replaced with\r
+      a PCI IO abstraction that abstracted a specific PCI device.\r
+    </Description>\r
+    <Copyright>Copyright (c) 2006, Intel Corporation</Copyright>\r
+    <License>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
+      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.</License>\r
+    <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION   0x00000052</Specification>\r
+  </MsaHeader>\r
+  <ModuleDefinitions>\r
+    <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+    <BinaryModule>false</BinaryModule>\r
+    <OutputFileBasename>UnixUga</OutputFileBasename>\r
+  </ModuleDefinitions>\r
+  <LibraryClassDefinitions>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>DebugLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverModelLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiDriverEntryPoint</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>BaseMemoryLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>MemoryAllocationLib</Keyword>\r
+    </LibraryClass>\r
+    <LibraryClass Usage="ALWAYS_CONSUMED">\r
+      <Keyword>UefiBootServicesTableLib</Keyword>\r
+    </LibraryClass>\r
+  </LibraryClassDefinitions>\r
+  <SourceFiles>\r
+    <Filename>UnixUga.h</Filename>\r
+    <Filename>UnixUgaInput.c</Filename>\r
+    <Filename>UnixUgaDriver.c</Filename>\r
+    <Filename>UnixUgaScreen.c</Filename>\r
+    <Filename>ComponentName.c</Filename>\r
+  </SourceFiles>\r
+  <PackageDependencies>\r
+    <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>\r
+    <Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>\r
+    <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>\r
+  </PackageDependencies>\r
+  <Protocols>\r
+    <Protocol Usage="TO_START">\r
+      <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiUgaDrawProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiUnixUgaIoProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+    <Protocol Usage="BY_START">\r
+      <ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>\r
+    </Protocol>\r
+  </Protocols>\r
+  <Events>\r
+    <CreateEvents>\r
+      <EventTypes EventGuidCName="gEfiEventExitBootServicesGuid" Usage="SOMETIMES_CONSUMED">\r
+        <EventType>EVENT_GROUP_GUID</EventType>\r
+      </EventTypes>\r
+    </CreateEvents>\r
+  </Events>\r
+  <Guids>\r
+    <GuidCNames Usage="ALWAYS_CONSUMED">\r
+      <GuidCName>gEfiUnixUgaGuid</GuidCName>\r
+    </GuidCNames>\r
+  </Guids>\r
+  <Externs>\r
+    <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>\r
+    <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>\r
+    <Extern>\r
+      <DriverBinding>gUnixUgaDriverBinding</DriverBinding>\r
+      <ComponentName>gUnixUgaComponentName</ComponentName>\r
+    </Extern>\r
+  </Externs>\r
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixUgaDxe/UnixUgaDriver.c b/UnixPkg/UnixUgaDxe/UnixUgaDriver.c
new file mode 100644 (file)
index 0000000..6073202
--- /dev/null
@@ -0,0 +1,296 @@
+/*++\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
+\r
+  UnixUgaDriver.c\r
+\r
+Abstract:\r
+\r
+  This file implements the EFI 1.1 Device Driver model requirements for UGA\r
+\r
+  UGA is short hand for Universal Graphics Abstraction protocol.\r
+\r
+  This file is a verision of UgaIo the uses UnixThunk system calls as an IO \r
+  abstraction. For a PCI device UnixIo would be replaced with\r
+  a PCI IO abstraction that abstracted a specific PCI device. \r
+\r
+--*/\r
+\r
+#include "UnixUga.h"\r
+\r
+EFI_DRIVER_BINDING_PROTOCOL gUnixUgaDriverBinding = {\r
+  UnixUgaDriverBindingSupported,\r
+  UnixUgaDriverBindingStart,\r
+  UnixUgaDriverBindingStop,\r
+  0xa,\r
+  NULL,\r
+  NULL\r
+};\r
+\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaDriverBindingSupported (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_UNIX_IO_PROTOCOL  *UnixIo;\r
+\r
+  //\r
+  // Open the IO Abstraction(s) needed to perform the supported test\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID **)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  Status = UnixUgaSupported (UnixIo);\r
+\r
+  //\r
+  // Close the I/O Abstraction(s) used to perform the supported test\r
+  //\r
+  gBS->CloseProtocol (\r
+        Handle,\r
+        &gEfiUnixIoProtocolGuid,\r
+        This->DriverBindingHandle,\r
+        Handle\r
+        );\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaDriverBindingStart (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL     *This,\r
+  IN  EFI_HANDLE                      Handle,\r
+  IN  EFI_DEVICE_PATH_PROTOCOL        *RemainingDevicePath\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    RemainingDevicePath - add argument and description to function comment\r
+// TODO:    EFI_UNSUPPORTED - add return value to function comment\r
+{\r
+  EFI_UNIX_IO_PROTOCOL  *UnixIo;\r
+  EFI_STATUS              Status;\r
+  UGA_PRIVATE_DATA        *Private;\r
+\r
+  //\r
+  // Grab the protocols we need\r
+  //\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUnixIoProtocolGuid,\r
+                  (VOID **)&UnixIo,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_BY_DRIVER\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Allocate Private context data for SGO inteface.\r
+  //\r
+  Private = NULL;\r
+  Status = gBS->AllocatePool (\r
+                  EfiBootServicesData,\r
+                  sizeof (UGA_PRIVATE_DATA),\r
+                  (VOID **)&Private\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+  //\r
+  // Set up context record\r
+  //\r
+  Private->Signature            = UGA_PRIVATE_DATA_SIGNATURE;\r
+  Private->Handle               = Handle;\r
+  Private->UnixThunk           = UnixIo->UnixThunk;\r
+\r
+  Private->ControllerNameTable  = NULL;\r
+\r
+  AddUnicodeString (\r
+    "eng",\r
+    gUnixUgaComponentName.SupportedLanguages,\r
+    &Private->ControllerNameTable,\r
+    UnixIo->EnvString\r
+    );\r
+\r
+  Private->WindowName = UnixIo->EnvString;\r
+\r
+  Status              = UnixUgaConstructor (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    goto Done;\r
+  }\r
+  //\r
+  // Publish the Uga interface to the world\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Private->Handle,\r
+                  &gEfiUgaDrawProtocolGuid,\r
+                  &Private->UgaDraw,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &Private->SimpleTextIn,\r
+                  NULL\r
+                  );\r
+\r
+Done:\r
+  if (EFI_ERROR (Status)) {\r
+\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEfiUnixIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+\r
+    if (Private != NULL) {\r
+      //\r
+      // On Error Free back private data\r
+      //\r
+      if (Private->ControllerNameTable != NULL) {\r
+        FreeUnicodeStringTable (Private->ControllerNameTable);\r
+      }\r
+\r
+      gBS->FreePool (Private);\r
+    }\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
+EFI_STATUS\r
+EFIAPI\r
+UnixUgaDriverBindingStop (\r
+  IN  EFI_DRIVER_BINDING_PROTOCOL  *This,\r
+  IN  EFI_HANDLE                   Handle,\r
+  IN  UINTN                        NumberOfChildren,\r
+  IN  EFI_HANDLE                   *ChildHandleBuffer\r
+  )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+Arguments:\r
+\r
+Returns:\r
+\r
+  None\r
+\r
+--*/\r
+// TODO:    This - add argument and description to function comment\r
+// TODO:    Handle - add argument and description to function comment\r
+// TODO:    NumberOfChildren - add argument and description to function comment\r
+// TODO:    ChildHandleBuffer - add argument and description to function comment\r
+// TODO:    EFI_NOT_STARTED - add return value to function comment\r
+// TODO:    EFI_DEVICE_ERROR - add return value to function comment\r
+{\r
+  EFI_UGA_DRAW_PROTOCOL *UgaDraw;\r
+  EFI_STATUS            Status;\r
+  UGA_PRIVATE_DATA      *Private;\r
+\r
+  Status = gBS->OpenProtocol (\r
+                  Handle,\r
+                  &gEfiUgaDrawProtocolGuid,\r
+                  (VOID **)&UgaDraw,\r
+                  This->DriverBindingHandle,\r
+                  Handle,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    //\r
+    // If the UGA interface does not exist the driver is not started\r
+    //\r
+    return EFI_NOT_STARTED;\r
+  }\r
+\r
+  //\r
+  // Get our private context information\r
+  //\r
+  Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (UgaDraw);\r
+\r
+  //\r
+  // Remove the SGO interface from the system\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  Private->Handle,\r
+                  &gEfiUgaDrawProtocolGuid,\r
+                  &Private->UgaDraw,\r
+                  &gEfiSimpleTextInProtocolGuid,\r
+                  &Private->SimpleTextIn,\r
+                  NULL\r
+                  );\r
+  if (!EFI_ERROR (Status)) {\r
+    //\r
+    // Shutdown the hardware\r
+    //\r
+    Status = UnixUgaDestructor (Private);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_DEVICE_ERROR;\r
+    }\r
+\r
+    gBS->CloseProtocol (\r
+          Handle,\r
+          &gEfiUnixIoProtocolGuid,\r
+          This->DriverBindingHandle,\r
+          Handle\r
+          );\r
+\r
+    //\r
+    // Free our instance data\r
+    //\r
+    FreeUnicodeStringTable (Private->ControllerNameTable);\r
+\r
+    gBS->FreePool (Private);\r
+\r
+  }\r
+\r
+  return Status;\r
+}\r
+\r
diff --git a/UnixPkg/UnixUgaDxe/UnixUgaInput.c b/UnixPkg/UnixUgaDxe/UnixUgaInput.c
new file mode 100644 (file)
index 0000000..29e605c
--- /dev/null
@@ -0,0 +1,221 @@
+/*++
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. 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
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+  UnixUgaInput.c
+
+Abstract:
+
+  This file produces the Simple Text In for an Uga window.
+
+  This stuff is linked at the hip to the Window, since the window
+  processing is done in a thread kicked off in UnixUgaImplementation.c
+
+  Since the window information is processed in an other thread we need
+  a keyboard Queue to pass data about. The Simple Text In code just
+  takes data off the Queue. The WinProc message loop takes keyboard input
+  and places it in the Queue.
+
+--*/
+
+#include "UnixUga.h"
+
+//
+// Simple Text In implementation.
+//
+
+EFI_STATUS
+EFIAPI
+UnixUgaSimpleTextInReset (
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL          *This,
+  IN BOOLEAN                              ExtendedVerification
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  This                  - TODO: add argument description
+  ExtendedVerification  - TODO: add argument description
+
+Returns:
+
+  EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+  UGA_PRIVATE_DATA  *Private;
+  EFI_INPUT_KEY     Key;
+  EFI_TPL           OldTpl;
+
+  Private = UGA_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
+  if (Private->UgaIo == NULL) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+  //
+  // A reset is draining the Queue
+  //
+  while (Private->UgaIo->UgaGetKey(Private->UgaIo, &Key) == EFI_SUCCESS)
+    ;
+
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+  return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixUgaSimpleTextInReadKeyStroke (
+  IN EFI_SIMPLE_TEXT_INPUT_PROTOCOL          *This,
+  OUT EFI_INPUT_KEY                       *Key
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  This  - TODO: add argument description
+  Key   - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+{
+  UGA_PRIVATE_DATA  *Private;
+  EFI_STATUS        Status;
+  EFI_TPL           OldTpl;
+
+  Private = UGA_PRIVATE_DATA_FROM_TEXT_IN_THIS (This);
+  if (Private->UgaIo == NULL) {
+    return EFI_NOT_READY;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);
+
+  Status  = Private->UgaIo->UgaGetKey(Private->UgaIo, Key);
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+
+  return Status;
+}
+
+STATIC
+VOID
+EFIAPI
+UnixUgaSimpleTextInWaitForKey (
+  IN EFI_EVENT          Event,
+  IN VOID               *Context
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  Event   - TODO: add argument description
+  Context - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+{
+  UGA_PRIVATE_DATA  *Private;
+  EFI_STATUS        Status;
+  EFI_TPL           OldTpl;
+
+  Private = (UGA_PRIVATE_DATA *) Context;
+  if (Private->UgaIo == NULL) {
+    return;
+  }
+
+  //
+  // Enter critical section
+  //
+  OldTpl  = gBS->RaiseTPL (TPL_NOTIFY);
+
+  Status  = Private->UgaIo->UgaCheckKey(Private->UgaIo);
+  if (!EFI_ERROR (Status)) {
+    //
+    // If a there is a key in the queue signal our event.
+    //
+    gBS->SignalEvent (Event);
+  }
+  //
+  // Leave critical section and return
+  //
+  gBS->RestoreTPL (OldTpl);
+}
+
+EFI_STATUS
+UnixUgaInitializeSimpleTextInForWindow (
+  IN  UGA_PRIVATE_DATA    *Private
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  Private - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+{
+  EFI_STATUS  Status;
+
+  //
+  // Initialize Simple Text In protoocol
+  //
+  Private->SimpleTextIn.Reset         = UnixUgaSimpleTextInReset;
+  Private->SimpleTextIn.ReadKeyStroke = UnixUgaSimpleTextInReadKeyStroke;
+
+  Status = gBS->CreateEvent (
+                  EVT_NOTIFY_WAIT,
+                  TPL_NOTIFY,
+                  UnixUgaSimpleTextInWaitForKey,
+                  Private,
+                  &Private->SimpleTextIn.WaitForKey
+                  );
+
+  return Status;
+}
diff --git a/UnixPkg/UnixUgaDxe/UnixUgaScreen.c b/UnixPkg/UnixUgaDxe/UnixUgaScreen.c
new file mode 100644 (file)
index 0000000..d9118aa
--- /dev/null
@@ -0,0 +1,446 @@
+/*++
+
+Copyright (c) 2006, Intel Corporation
+All rights reserved. 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
+http://opensource.org/licenses/bsd-license.php
+
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+Module Name:
+
+    UnixUgaScreen.c
+
+Abstract:
+
+  This file produces the graphics abstration of UGA. It is called by
+  UnixUgaDriver.c file which deals with the EFI 1.1 driver model.
+  This file just does graphics.
+
+--*/
+
+#include "UnixUga.h"
+
+EFI_UNIX_THUNK_PROTOCOL *mUnix;
+static EFI_EVENT          mUgaScreenExitBootServicesEvent;
+
+STATIC
+EFI_STATUS
+UnixUgaStartWindow (
+  IN  UGA_PRIVATE_DATA    *Private,
+  IN  UINT32              HorizontalResolution,
+  IN  UINT32              VerticalResolution,
+  IN  UINT32              ColorDepth,
+  IN  UINT32              RefreshRate
+  );
+
+STATIC
+VOID
+EFIAPI
+KillNtUgaThread (
+  IN EFI_EVENT  Event,
+  IN VOID       *Context
+  );
+
+//
+// UGA Protocol Member Functions
+//
+
+EFI_STATUS
+EFIAPI
+UnixUgaGetMode (
+  EFI_UGA_DRAW_PROTOCOL *This,
+  UINT32                *HorizontalResolution,
+  UINT32                *VerticalResolution,
+  UINT32                *ColorDepth,
+  UINT32                *RefreshRate
+  )
+/*++
+
+  Routine Description:
+    Return the current video mode information.
+
+  Arguments:
+    This                  - Protocol instance pointer.
+    HorizontalResolution  - Current video horizontal resolution in pixels
+    VerticalResolution    - Current video Vertical resolution in pixels
+    ColorDepth            - Current video color depth in bits per pixel
+    RefreshRate           - Current video refresh rate in Hz.
+
+  Returns:
+    EFI_SUCCESS     - Mode information returned.
+    EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
+    EFI_INVALID_PARAMETER - One of the input args was NULL.
+
+--*/
+// TODO:    ADD IN/OUT description here
+{
+  UGA_PRIVATE_DATA  *Private;
+
+  Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This);
+
+  if (Private->HardwareNeedsStarting) {
+    return EFI_NOT_STARTED;
+  }
+
+  if ((HorizontalResolution == NULL) ||
+      (VerticalResolution   == NULL) ||
+      (ColorDepth           == NULL) ||
+      (RefreshRate          == NULL)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  *HorizontalResolution = Private->HorizontalResolution;
+  *VerticalResolution   = Private->VerticalResolution;
+  *ColorDepth           = Private->ColorDepth;
+  *RefreshRate          = Private->RefreshRate;
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixUgaSetMode (
+  EFI_UGA_DRAW_PROTOCOL *This,
+  UINT32                HorizontalResolution,
+  UINT32                VerticalResolution,
+  UINT32                ColorDepth,
+  UINT32                RefreshRate
+  )
+/*++
+
+  Routine Description:
+    Return the current video mode information.
+
+  Arguments:
+    This                  - Protocol instance pointer.
+    HorizontalResolution  - Current video horizontal resolution in pixels
+    VerticalResolution    - Current video Vertical resolution in pixels
+    ColorDepth            - Current video color depth in bits per pixel
+    RefreshRate           - Current video refresh rate in Hz.
+
+  Returns:
+    EFI_SUCCESS     - Mode information returned.
+    EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
+    EFI_INVALID_PARAMETER - One of the input args was NULL.
+
+--*/
+// TODO:    EFI_DEVICE_ERROR - add return value to function comment
+// TODO:    EFI_DEVICE_ERROR - add return value to function comment
+// TODO:    ADD IN/OUT description here
+{
+  EFI_STATUS        Status;
+  UGA_PRIVATE_DATA  *Private;
+  EFI_UGA_PIXEL     Fill;
+
+  Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This);
+
+  if (Private->HardwareNeedsStarting) {
+    Status = UnixUgaStartWindow (
+              Private,
+              HorizontalResolution,
+              VerticalResolution,
+              ColorDepth,
+              RefreshRate
+              );
+    if (EFI_ERROR (Status)) {
+      return EFI_DEVICE_ERROR;
+    }
+
+    Private->HardwareNeedsStarting = FALSE;
+  }
+  Status = Private->UgaIo->UgaSize(Private->UgaIo,
+             HorizontalResolution,
+             VerticalResolution);
+
+  Private->HorizontalResolution = HorizontalResolution;
+  Private->VerticalResolution   = VerticalResolution;
+  Private->ColorDepth           = ColorDepth;
+  Private->RefreshRate          = RefreshRate;
+
+  Fill.Red                      = 0x7f;
+  Fill.Green                    = 0x7F;
+  Fill.Blue                     = 0x7f;
+  This->Blt (
+          This,
+          &Fill,
+          EfiUgaVideoFill,
+          0,
+          0,
+          0,
+          0,
+          HorizontalResolution,
+          VerticalResolution,
+          HorizontalResolution * sizeof (EFI_UGA_PIXEL)
+          );
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixUgaBlt (
+  IN  EFI_UGA_DRAW_PROTOCOL                   *This,
+  IN  EFI_UGA_PIXEL                           *BltBuffer, OPTIONAL
+  IN  EFI_UGA_BLT_OPERATION                   BltOperation,
+  IN  UINTN                                   SourceX,
+  IN  UINTN                                   SourceY,
+  IN  UINTN                                   DestinationX,
+  IN  UINTN                                   DestinationY,
+  IN  UINTN                                   Width,
+  IN  UINTN                                   Height,
+  IN  UINTN                                   Delta         OPTIONAL
+  )
+/*++
+
+  Routine Description:
+    Blt pixels from the rectangle (Width X Height) formed by the BltBuffer
+    onto the graphics screen starting a location (X, Y). (0, 0) is defined as
+    the upper left hand side of the screen. (X, Y) can be outside of the
+    current screen geometry and the BltBuffer will be cliped when it is
+    displayed. X and Y can be negative or positive. If Width or Height is
+    bigger than the current video screen the image will be clipped.
+
+  Arguments:
+    This          - Protocol instance pointer.
+    X             - X location on graphics screen.
+    Y             - Y location on the graphics screen.
+    Width         - Width of BltBuffer.
+    Height        - Hight of BltBuffer
+    BltOperation  - Operation to perform on BltBuffer and video memory
+    BltBuffer     - Buffer containing data to blt into video buffer. This
+                    buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL)
+    SourceX       - If the BltOperation is a EfiCopyBlt this is the source
+                    of the copy. For other BLT operations this argument is not
+                    used.
+    SourceX       - If the BltOperation is a EfiCopyBlt this is the source
+                    of the copy. For other BLT operations this argument is not
+                    used.
+
+  Returns:
+    EFI_SUCCESS           - The palette is updated with PaletteArray.
+    EFI_INVALID_PARAMETER - BltOperation is not valid.
+    EFI_DEVICE_ERROR      - A hardware error occured writting to the video
+                             buffer.
+
+--*/
+// TODO:    SourceY - add argument and description to function comment
+// TODO:    DestinationX - add argument and description to function comment
+// TODO:    DestinationY - add argument and description to function comment
+// TODO:    Delta - add argument and description to function comment
+{
+  UGA_PRIVATE_DATA  *Private;
+  EFI_TPL           OriginalTPL;
+  EFI_STATUS        Status;
+
+  Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This);
+
+  if ((BltOperation < 0) || (BltOperation >= EfiUgaBltMax)) {
+    return EFI_INVALID_PARAMETER;
+  }
+
+  if (Width == 0 || Height == 0) {
+    return EFI_INVALID_PARAMETER;
+  }
+  //
+  // If Delta is zero, then the entire BltBuffer is being used, so Delta
+  // is the number of bytes in each row of BltBuffer.  Since BltBuffer is Width pixels size,
+  // the number of bytes in each row can be computed.
+  //
+  if (Delta == 0) {
+    Delta = Width * sizeof (EFI_UGA_PIXEL);
+  }
+
+  //
+  // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
+  // We would not want a timer based event (Cursor, ...) to come in while we are
+  // doing this operation.
+  //
+  OriginalTPL = gBS->RaiseTPL (TPL_NOTIFY);
+
+  Status = Private->UgaIo->UgaBlt (Private->UgaIo,
+             BltBuffer,
+             BltOperation,
+             SourceX, SourceY,
+             DestinationX, DestinationY,
+             Width, Height,
+             Delta);
+
+  gBS->RestoreTPL (OriginalTPL);
+
+  return Status;
+}
+
+
+//
+// Construction and Destruction functions
+//
+
+EFI_STATUS
+UnixUgaSupported (
+  IN  EFI_UNIX_IO_PROTOCOL  *UnixIo
+  )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+  None
+
+--*/
+// TODO:    UnixIo - add argument and description to function comment
+// TODO:    EFI_UNSUPPORTED - add return value to function comment
+// TODO:    EFI_SUCCESS - add return value to function comment
+{
+  //
+  // Check to see if the IO abstraction represents a device type we support.
+  //
+  // This would be replaced a check of PCI subsystem ID, etc.
+  //
+  if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixUgaGuid)) {
+    return EFI_UNSUPPORTED;
+  }
+
+  return EFI_SUCCESS;
+}
+
+
+STATIC
+EFI_STATUS
+UnixUgaStartWindow (
+  IN  UGA_PRIVATE_DATA    *Private,
+  IN  UINT32              HorizontalResolution,
+  IN  UINT32              VerticalResolution,
+  IN  UINT32              ColorDepth,
+  IN  UINT32              RefreshRate
+  )
+/*++
+
+Routine Description:
+
+  TODO: Add function description
+
+Arguments:
+
+  Private               - TODO: add argument description
+  HorizontalResolution  - TODO: add argument description
+  VerticalResolution    - TODO: add argument description
+  ColorDepth            - TODO: add argument description
+  RefreshRate           - TODO: add argument description
+
+Returns:
+
+  TODO: add return values
+
+--*/
+{
+  EFI_STATUS          Status;
+
+  mUnix  = Private->UnixThunk;
+
+  Private->HorizontalResolution = HorizontalResolution;
+  Private->VerticalResolution   = VerticalResolution;
+
+  //
+  // Register to be notified on exit boot services so we can destroy the window.
+  //
+  Status = gBS->CreateEvent (
+                  EVT_SIGNAL_EXIT_BOOT_SERVICES,
+                  TPL_CALLBACK,
+                  KillNtUgaThread,
+                  Private,
+                  &mUgaScreenExitBootServicesEvent
+                  );
+
+  Status = Private->UnixThunk->UgaCreate(&Private->UgaIo, Private->WindowName);
+  return Status;
+}
+
+EFI_STATUS
+UnixUgaConstructor (
+  UGA_PRIVATE_DATA    *Private
+  )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+  None
+
+--*/
+// TODO:    Private - add argument and description to function comment
+// TODO:    EFI_SUCCESS - add return value to function comment
+{
+
+  Private->UgaDraw.GetMode        = UnixUgaGetMode;
+  Private->UgaDraw.SetMode        = UnixUgaSetMode;
+  Private->UgaDraw.Blt            = UnixUgaBlt;
+
+  Private->HardwareNeedsStarting  = TRUE;
+  Private->UgaIo = NULL;
+
+  UnixUgaInitializeSimpleTextInForWindow (Private);
+
+  return EFI_SUCCESS;
+}
+
+EFI_STATUS
+UnixUgaDestructor (
+  UGA_PRIVATE_DATA     *Private
+  )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+  None
+
+--*/
+// TODO:    Private - add argument and description to function comment
+// TODO:    EFI_SUCCESS - add return value to function comment
+{
+  if (!Private->HardwareNeedsStarting) {
+    Private->UgaIo->UgaClose(Private->UgaIo);
+    Private->UgaIo = NULL;
+  }
+
+  return EFI_SUCCESS;
+}
+
+STATIC
+VOID
+EFIAPI
+KillNtUgaThread (
+  IN EFI_EVENT  Event,
+  IN VOID       *Context
+  )
+/*++
+
+Routine Description:
+
+  This is the UGA screen's callback notification function for exit-boot-services.
+  All we do here is call UnixUgaDestructor().
+
+Arguments:
+
+  Event   - not used
+  Context - pointer to the Private structure.
+
+Returns:
+
+  None.
+
+--*/
+{
+  EFI_STATUS  Status;
+  Status = UnixUgaDestructor (Context);
+}