summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>2008-06-30 05:08:49 +0000
committereric_tian <eric_tian@6f19259b-4bc3-4df7-8a09-765794883524>2008-06-30 05:08:49 +0000
commit804405e7d10525e41720216137b2551f62a0663f (patch)
treea615301e36e63aba81adcb0a963e4d3aa7830863
parent27d55a2d56320e6e7a1dda2b02089721540d6bc3 (diff)
downloadedk2-platforms-804405e7d10525e41720216137b2551f62a0663f.tar.xz
Port EdkUnixPkg to UnixPkg. The changes are listed as follows:
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
-rw-r--r--UnixPkg/BootModePei/BootModePei.c101
-rw-r--r--UnixPkg/BootModePei/BootModePei.inf57
-rw-r--r--UnixPkg/BootModePei/BootModePei.msa65
-rw-r--r--UnixPkg/CpuRuntimeDxe/Cpu.c536
-rw-r--r--UnixPkg/CpuRuntimeDxe/Cpu.inf73
-rw-r--r--UnixPkg/CpuRuntimeDxe/Cpu.msa108
-rw-r--r--UnixPkg/CpuRuntimeDxe/CpuDriver.h163
-rw-r--r--UnixPkg/CpuRuntimeDxe/CpuIo.c350
-rw-r--r--UnixPkg/CpuRuntimeDxe/Strings.unibin0 -> 2036 bytes
-rw-r--r--UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c1553
-rw-r--r--UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c156
-rw-r--r--UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h238
-rw-r--r--UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf90
-rw-r--r--UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa99
-rw-r--r--UnixPkg/Include/Common/UnixInclude.h32
-rw-r--r--UnixPkg/Include/FlashLayout.h64
-rw-r--r--UnixPkg/Include/Library/UnixLib.h27
-rw-r--r--UnixPkg/Include/Ppi/UnixAutoScan.h66
-rw-r--r--UnixPkg/Include/Ppi/UnixFwh.h62
-rw-r--r--UnixPkg/Include/Ppi/UnixPeiLoadFile.h65
-rw-r--r--UnixPkg/Include/Ppi/UnixThunk.h56
-rw-r--r--UnixPkg/Include/Protocol/UnixIo.h142
-rw-r--r--UnixPkg/Include/Protocol/UnixThunk.h244
-rw-r--r--UnixPkg/Include/Protocol/UnixUgaIo.h72
-rw-r--r--UnixPkg/Include/UnixDxe.h36
-rw-r--r--UnixPkg/Include/UnixPeim.h30
-rw-r--r--UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf50
-rw-r--r--UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa55
-rw-r--r--UnixPkg/Library/DxeUnixLib/UnixLib.c51
-rw-r--r--UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf61
-rw-r--r--UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa68
-rw-r--r--UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c238
-rw-r--r--UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c225
-rw-r--r--UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf50
-rw-r--r--UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf50
-rw-r--r--UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa48
-rw-r--r--UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c266
-rw-r--r--UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c262
-rw-r--r--UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf49
-rw-r--r--UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf61
-rw-r--r--UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa68
-rw-r--r--UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c246
-rw-r--r--UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.c255
-rw-r--r--UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf50
-rw-r--r--UnixPkg/Library/UnixBdsLib/BdsPlatform.c514
-rw-r--r--UnixPkg/Library/UnixBdsLib/BdsPlatform.h165
-rw-r--r--UnixPkg/Library/UnixBdsLib/PlatformBds.inf80
-rw-r--r--UnixPkg/Library/UnixBdsLib/PlatformBds.msa206
-rw-r--r--UnixPkg/Library/UnixBdsLib/PlatformData.c120
-rw-r--r--UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoader.c54
-rw-r--r--UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.inf41
-rw-r--r--UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.msa49
-rw-r--r--UnixPkg/MetronomeDxe/Metronome.c140
-rw-r--r--UnixPkg/MetronomeDxe/Metronome.h84
-rw-r--r--UnixPkg/MetronomeDxe/Metronome.inf60
-rw-r--r--UnixPkg/MetronomeDxe/Metronome.msa71
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.unibin0 -> 2896 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c57
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendor.unibin0 -> 2260 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c88
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c33
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.unibin0 -> 2460 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c45
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscDevicePath.h175
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c37
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscOemString.unibin0 -> 1996 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscOemStringData.c32
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.unibin0 -> 9426 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c99
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c266
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c42
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h119
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf100
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.msa170
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.unibin0 -> 2778 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c99
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c334
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.unibin0 -> 2014 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c33
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.unibin0 -> 2456 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c57
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c122
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.unibin0 -> 2004 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c32
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.unibin0 -> 2030 bytes
-rw-r--r--UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c52
-rw-r--r--UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c356
-rw-r--r--UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf58
-rw-r--r--UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.msa70
-rw-r--r--UnixPkg/ResetRuntimeDxe/Reset.c131
-rw-r--r--UnixPkg/ResetRuntimeDxe/Reset.inf58
-rw-r--r--UnixPkg/ResetRuntimeDxe/Reset.msa70
-rw-r--r--UnixPkg/Sec/FwVol.c314
-rw-r--r--UnixPkg/Sec/SecMain.c1048
-rw-r--r--UnixPkg/Sec/SecMain.h548
-rw-r--r--UnixPkg/Sec/SecMain.inf76
-rw-r--r--UnixPkg/Sec/SecMain.msa113
-rw-r--r--UnixPkg/Sec/Stack.S92
-rw-r--r--UnixPkg/Sec/UgaX11.c595
-rw-r--r--UnixPkg/Sec/UnixThunk.c197
-rw-r--r--UnixPkg/TimerDxe/Timer.c374
-rw-r--r--UnixPkg/TimerDxe/Timer.h162
-rw-r--r--UnixPkg/TimerDxe/Timer.inf63
-rw-r--r--UnixPkg/TimerDxe/Timer.msa76
-rw-r--r--UnixPkg/UnixAutoScanPei/UnixAutoScan.c145
-rw-r--r--UnixPkg/UnixAutoScanPei/UnixAutoScan.inf60
-rw-r--r--UnixPkg/UnixAutoScanPei/UnixAutoScan.msa74
-rw-r--r--UnixPkg/UnixBlockIoDxe/ComponentName.c197
-rw-r--r--UnixPkg/UnixBlockIoDxe/DriverConfiguration.c338
-rw-r--r--UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c187
-rw-r--r--UnixPkg/UnixBlockIoDxe/EntryPoint.c51
-rw-r--r--UnixPkg/UnixBlockIoDxe/UnixBlockIo.c1307
-rw-r--r--UnixPkg/UnixBlockIoDxe/UnixBlockIo.h219
-rw-r--r--UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf71
-rw-r--r--UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa91
-rw-r--r--UnixPkg/UnixBusDriverDxe/ComponentName.c208
-rw-r--r--UnixPkg/UnixBusDriverDxe/EntryPoint.c51
-rw-r--r--UnixPkg/UnixBusDriverDxe/UnixBusDriver.c716
-rw-r--r--UnixPkg/UnixBusDriverDxe/UnixBusDriver.h312
-rw-r--r--UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf92
-rw-r--r--UnixPkg/UnixBusDriverDxe/UnixBusDriver.msa177
-rw-r--r--UnixPkg/UnixConsoleDxe/ComponentName.c197
-rw-r--r--UnixPkg/UnixConsoleDxe/Console.c310
-rw-r--r--UnixPkg/UnixConsoleDxe/Console.h530
-rw-r--r--UnixPkg/UnixConsoleDxe/ConsoleIn.c246
-rw-r--r--UnixPkg/UnixConsoleDxe/ConsoleOut.c635
-rw-r--r--UnixPkg/UnixConsoleDxe/EntryPoint.c51
-rw-r--r--UnixPkg/UnixConsoleDxe/UnixConsole.inf65
-rw-r--r--UnixPkg/UnixConsoleDxe/UnixConsole.msa86
-rw-r--r--UnixPkg/UnixFirmwareVolumePei/UnixFwh.c137
-rw-r--r--UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf68
-rw-r--r--UnixPkg/UnixFirmwareVolumePei/UnixFwh.msa63
-rw-r--r--UnixPkg/UnixFlashMapPei/FlashMap.c91
-rw-r--r--UnixPkg/UnixFlashMapPei/FlashMap.inf82
-rw-r--r--UnixPkg/UnixFlashMapPei/FlashMap.msa126
-rw-r--r--UnixPkg/UnixPkg.dec97
-rw-r--r--UnixPkg/UnixPkg.dsc496
-rw-r--r--UnixPkg/UnixPkg.fdf376
-rw-r--r--UnixPkg/UnixSerialIoDxe/ComponentName.c208
-rw-r--r--UnixPkg/UnixSerialIoDxe/EntryPoint.c49
-rw-r--r--UnixPkg/UnixSerialIoDxe/UnixSerialIo.c1487
-rw-r--r--UnixPkg/UnixSerialIoDxe/UnixSerialIo.h572
-rw-r--r--UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf69
-rw-r--r--UnixPkg/UnixSerialIoDxe/UnixSerialIo.msa87
-rw-r--r--UnixPkg/UnixSimpleFileSystemDxe/ComponentName.c204
-rw-r--r--UnixPkg/UnixSimpleFileSystemDxe/EntryPoint.c51
-rw-r--r--UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c2186
-rw-r--r--UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h599
-rw-r--r--UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf71
-rw-r--r--UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.msa94
-rw-r--r--UnixPkg/UnixThunkDxe/UnixThunk.c102
-rw-r--r--UnixPkg/UnixThunkDxe/UnixThunk.h30
-rw-r--r--UnixPkg/UnixThunkDxe/UnixThunk.inf60
-rw-r--r--UnixPkg/UnixThunkDxe/UnixThunk.msa69
-rw-r--r--UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.c79
-rw-r--r--UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf63
-rw-r--r--UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.msa69
-rw-r--r--UnixPkg/UnixUgaDxe/ComponentName.c198
-rw-r--r--UnixPkg/UnixUgaDxe/EntryPoint.c49
-rw-r--r--UnixPkg/UnixUgaDxe/UnixUga.h304
-rw-r--r--UnixPkg/UnixUgaDxe/UnixUga.inf74
-rw-r--r--UnixPkg/UnixUgaDxe/UnixUga.msa101
-rw-r--r--UnixPkg/UnixUgaDxe/UnixUgaDriver.c296
-rw-r--r--UnixPkg/UnixUgaDxe/UnixUgaInput.c221
-rw-r--r--UnixPkg/UnixUgaDxe/UnixUgaScreen.c446
165 files changed, 30405 insertions, 0 deletions
diff --git a/UnixPkg/BootModePei/BootModePei.c b/UnixPkg/BootModePei/BootModePei.c
new file mode 100644
index 0000000000..b7f3ad0598
--- /dev/null
+++ b/UnixPkg/BootModePei/BootModePei.c
@@ -0,0 +1,101 @@
+/**@file
+
+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:
+
+ BootMode.c
+
+Abstract:
+
+ Tiano PEIM to provide the platform support functionality within Unix
+
+**/
+
+
+
+//
+// The package level header files this module uses
+//
+#include <PiPei.h>
+//
+// The protocols, PPI and GUID defintions for this module
+//
+#include <Ppi/MasterBootMode.h>
+#include <Ppi/BootInRecoveryMode.h>
+//
+// The Library classes this module consumes
+//
+#include <Library/DebugLib.h>
+#include <Library/PeimEntryPoint.h>
+
+
+//
+// Module globals
+//
+EFI_PEI_PPI_DESCRIPTOR mPpiListBootMode = {
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+ &gEfiPeiMasterBootModePpiGuid,
+ NULL
+};
+
+EFI_PEI_PPI_DESCRIPTOR mPpiListRecoveryBootMode = {
+ (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
+ &gEfiPeiBootInRecoveryModePpiGuid,
+ NULL
+};
+
+EFI_STATUS
+EFIAPI
+InitializeBootMode (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices
+ )
+/*++
+
+Routine Description:
+
+ Peform the boot mode determination logic
+
+Arguments:
+
+ PeiServices - General purpose services available to every PEIM.
+
+Returns:
+
+ Status - EFI_SUCCESS if the boot mode could be set
+
+--*/
+// TODO: FfsHeader - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ UINTN BootMode;
+
+ DEBUG ((EFI_D_ERROR, "Unix Boot Mode PEIM Loaded\n"));
+
+ //
+ // Let's assume things are OK if not told otherwise
+ // Should we read an environment variable in order to easily change this?
+ //
+ BootMode = BOOT_WITH_FULL_CONFIGURATION;
+
+ Status = (**PeiServices).SetBootMode (PeiServices, (UINT8) BootMode);
+ ASSERT_EFI_ERROR (Status);
+
+ Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListBootMode);
+ ASSERT_EFI_ERROR (Status);
+
+ if (BootMode == BOOT_IN_RECOVERY_MODE) {
+ Status = (**PeiServices).InstallPpi (PeiServices, &mPpiListRecoveryBootMode);
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ return Status;
+}
diff --git a/UnixPkg/BootModePei/BootModePei.inf b/UnixPkg/BootModePei/BootModePei.inf
new file mode 100644
index 0000000000..d99150761f
--- /dev/null
+++ b/UnixPkg/BootModePei/BootModePei.inf
@@ -0,0 +1,57 @@
+#/** @file
+# Component description file for BootMode module
+#
+# This module provides platform specific function to detect boot mode.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BootModePei
+ FILE_GUID = f3ff9aee-8985-11db-b133-0040d02b1835
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeBootMode
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ BootModePei.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+
+
+[LibraryClasses]
+ PeiServicesTablePointerLib
+ PeiServicesLib
+ BaseLib
+ PeimEntryPoint
+ DebugLib
+
+
+[Ppis]
+ gEfiPeiMasterBootModePpiGuid # PPI ALWAYS_PRODUCED
+ gEfiPeiBootInRecoveryModePpiGuid # PPI SOMETIMES_PRODUCED
+
+
+[Depex]
+ TRUE
+
diff --git a/UnixPkg/BootModePei/BootModePei.msa b/UnixPkg/BootModePei/BootModePei.msa
new file mode 100644
index 0000000000..5b2c8d843c
--- /dev/null
+++ b/UnixPkg/BootModePei/BootModePei.msa
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>BootMode</ModuleName>
+ <ModuleType>PEIM</ModuleType>
+ <GuidValue>f3ff9aee-8985-11db-b133-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Component description file for BootMode module</Abstract>
+ <Description>This module provides platform specific function to detect boot mode.</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>BootMode</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>PeiServicesLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PeiServicesTablePointerLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>BootMode.c</Filename>
+ <Filename>BootMode.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="SOMETIMES_PRODUCED">
+ <PpiCName>gEfiPeiBootInRecoveryModePpiGuid</PpiCName>
+ </Ppi>
+ <Ppi Usage="ALWAYS_PRODUCED">
+ <PpiCName>gEfiPeiMasterBootModePpiGuid</PpiCName>
+ </Ppi>
+ </PPIs>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>InitializeBootMode</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/CpuRuntimeDxe/Cpu.c b/UnixPkg/CpuRuntimeDxe/Cpu.c
new file mode 100644
index 0000000000..aef2c30ccd
--- /dev/null
+++ b/UnixPkg/CpuRuntimeDxe/Cpu.c
@@ -0,0 +1,536 @@
+/*++
+
+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:
+
+ Cpu.c
+
+Abstract:
+
+ Unix Emulation Architectural Protocol Driver as defined in Tiano.
+ This CPU module abstracts the interrupt subsystem of a platform and
+ the CPU-specific setjump/long pair. Other services are not implemented
+ in this driver.
+
+--*/
+#include "PiDxe.h"
+#include <Protocol/Cpu.h>
+#include <Protocol/DataHub.h>
+#include <Guid/DataHubRecords.h>
+#include <Protocol/CpuIo.h>
+#include <Protocol/FrameworkHii.h>
+#include <Guid/DataHubProducer.h>
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HiiLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Framework/DataHubRecords.h>
+#include "CpuDriver.h"
+#include "UnixDxe.h"
+#include <Protocol/UnixIo.h>
+
+#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100
+
+CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = {
+ CPU_ARCH_PROT_PRIVATE_SIGNATURE,
+ NULL,
+ {
+ UnixFlushCpuDataCache,
+ UnixEnableInterrupt,
+ UnixDisableInterrupt,
+ UnixGetInterruptState,
+ UnixInit,
+ UnixRegisterInterruptHandler,
+ UnixGetTimerValue,
+ UnixSetMemoryAttributes,
+ 0,
+ 4
+ },
+ {
+ CpuMemoryServiceRead,
+ CpuMemoryServiceWrite,
+ CpuIoServiceRead,
+ CpuIoServiceWrite
+ },
+ 0,
+ TRUE
+};
+
+typedef union {
+ EFI_CPU_DATA_RECORD *DataRecord;
+ UINT8 *Raw;
+} EFI_CPU_DATA_RECORD_BUFFER;
+
+EFI_SUBCLASS_TYPE1_HEADER mCpuDataRecordHeader = {
+ EFI_PROCESSOR_SUBCLASS_VERSION, // Version
+ sizeof (EFI_SUBCLASS_TYPE1_HEADER), // Header Size
+ 0, // Instance, Initialize later
+ EFI_SUBCLASS_INSTANCE_NON_APPLICABLE, // SubInstance
+ 0 // RecordType, Initialize later
+};
+
+//
+// Service routines for the driver
+//
+EFI_STATUS
+EFIAPI
+UnixFlushCpuDataCache (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS Start,
+ IN UINT64 Length,
+ IN EFI_CPU_FLUSH_TYPE FlushType
+ )
+/*++
+
+Routine Description:
+
+ This routine would provide support for flushing the CPU data cache.
+ In the case of UNIX emulation environment, this flushing is not necessary and
+ is thus not implemented.
+
+Arguments:
+
+ Pointer to CPU Architectural Protocol interface
+ Start adddress in memory to flush
+ Length of memory to flush
+ Flush type
+
+Returns:
+
+ Status
+ EFI_SUCCESS
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: FlushType - add argument and description to function comment
+// TODO: EFI_UNSUPPORTED - add return value to function comment
+{
+ if (FlushType == EfiCpuFlushTypeWriteBackInvalidate) {
+ //
+ // Only WB flush is supported. We actually need do nothing on UNIX emulator
+ // environment. Classify this to follow EFI spec
+ //
+ return EFI_SUCCESS;
+ }
+ //
+ // Other flush types are not supported by UNIX emulator
+ //
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI
+UnixEnableInterrupt (
+ IN EFI_CPU_ARCH_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ This routine provides support for emulation of the interrupt enable of the
+ the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
+ Architectural Protocol observes in order to defer behaviour while in its
+ emulated interrupt, or timer tick.
+
+Arguments:
+
+ Pointer to CPU Architectural Protocol interface
+
+Returns:
+
+ Status
+ EFI_SUCCESS
+
+--*/
+// TODO: This - add argument and description to function comment
+{
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;
+
+ Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
+ Private->InterruptState = TRUE;
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixDisableInterrupt (
+ IN EFI_CPU_ARCH_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ This routine provides support for emulation of the interrupt disable of the
+ the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
+ Architectural Protocol observes in order to defer behaviour while in its
+ emulated interrupt, or timer tick.
+
+Arguments:
+
+ Pointer to CPU Architectural Protocol interface
+
+Returns:
+
+ Status
+ EFI_SUCCESS
+
+--*/
+// TODO: This - add argument and description to function comment
+{
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;
+
+ Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
+ Private->InterruptState = FALSE;
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixGetInterruptState (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ OUT BOOLEAN *State
+ )
+/*++
+
+Routine Description:
+
+ This routine provides support for emulation of the interrupt disable of the
+ the system. For our purposes, CPU enable is just a BOOLEAN that the Timer
+ Architectural Protocol observes in order to defer behaviour while in its
+ emulated interrupt, or timer tick.
+
+Arguments:
+
+ Pointer to CPU Architectural Protocol interface
+
+Returns:
+
+ Status
+ EFI_SUCCESS
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: State - add argument and description to function comment
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;
+
+ if (State == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
+ *State = Private->InterruptState;
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixInit (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN EFI_CPU_INIT_TYPE InitType
+ )
+/*++
+
+Routine Description:
+
+ This routine would support generation of a CPU INIT. At
+ present, this code does not provide emulation.
+
+Arguments:
+
+ Pointer to CPU Architectural Protocol interface
+ INIT Type
+
+Returns:
+
+ Status
+ EFI_UNSUPPORTED - not yet implemented
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: InitType - add argument and description to function comment
+{
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;
+
+ Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI
+UnixRegisterInterruptHandler (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN EFI_EXCEPTION_TYPE InterruptType,
+ IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
+ )
+/*++
+
+Routine Description:
+
+ This routine would support registration of an interrupt handler. At
+ present, this code does not provide emulation.
+
+Arguments:
+
+ Pointer to CPU Architectural Protocol interface
+ Pointer to interrupt handlers
+ Interrupt type
+
+Returns:
+
+ Status
+ EFI_UNSUPPORTED - not yet implemented
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: InterruptType - add argument and description to function comment
+// TODO: InterruptHandler - add argument and description to function comment
+{
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;
+
+ //
+ // Do parameter checking for EFI spec conformance
+ //
+ if (InterruptType < 0 || InterruptType > 0xff) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Do nothing for Nt32 emulation
+ //
+ Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI
+UnixGetTimerValue (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN UINT32 TimerIndex,
+ OUT UINT64 *TimerValue,
+ OUT UINT64 *TimerPeriod OPTIONAL
+ )
+/*++
+
+Routine Description:
+
+ This routine would support querying of an on-CPU timer. At present,
+ this code does not provide timer emulation.
+
+Arguments:
+
+ This - Pointer to CPU Architectural Protocol interface
+ TimerIndex - Index of given CPU timer
+ TimerValue - Output of the timer
+ TimerPeriod - Output of the timer period
+
+Returns:
+
+ EFI_UNSUPPORTED - not yet implemented
+ EFI_INVALID_PARAMETER - TimeValue is NULL
+
+--*/
+{
+ if (TimerValue == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // No timer supported
+ //
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSetMemoryAttributes (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN UINT64 Attributes
+ )
+/*++
+
+Routine Description:
+
+ This routine would support querying of an on-CPU timer. At present,
+ this code does not provide timer emulation.
+
+Arguments:
+
+ Pointer to CPU Architectural Protocol interface
+ Start address of memory region
+ The size in bytes of the memory region
+ The bit mask of attributes to set for the memory region
+
+Returns:
+
+ Status
+ EFI_UNSUPPORTED - not yet implemented
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: BaseAddress - add argument and description to function comment
+// TODO: Length - add argument and description to function comment
+// TODO: Attributes - add argument and description to function comment
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ CPU_ARCH_PROTOCOL_PRIVATE *Private;
+
+ //
+ // Check for invalid parameter for Spec conformance
+ //
+ if (Length == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Do nothing for Nt32 emulation
+ //
+ Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This);
+ return EFI_UNSUPPORTED;
+}
+
+VOID
+CpuUpdateDataHub (
+ VOID
+ )
+/*++
+
+Routine Description:
+ This function will log processor version and frequency data to data hub.
+
+Arguments:
+ Event - Event whose notification function is being invoked.
+ Context - Pointer to the notification function's context.
+
+Returns:
+ None.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_CPU_DATA_RECORD_BUFFER RecordBuffer;
+ UINT32 HeaderSize;
+ UINT32 TotalSize;
+ EFI_DATA_HUB_PROTOCOL *DataHub;
+ EFI_HII_HANDLE HiiHandle;
+
+ //
+ // Locate DataHub protocol.
+ //
+ Status = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, &DataHub);
+ if (EFI_ERROR (Status)) {
+ return;
+ }
+
+ //
+ // Initialize data record header
+ //
+ mCpuDataRecordHeader.Instance = 1;
+ HeaderSize = sizeof (EFI_SUBCLASS_TYPE1_HEADER);
+
+ RecordBuffer.Raw = AllocatePool (HeaderSize + EFI_CPU_DATA_MAXIMUM_LENGTH);
+ if (RecordBuffer.Raw == NULL) {
+ return ;
+ }
+
+ //
+ // Initialize strings to HII database
+ //
+ HiiLibAddPackages (1, &gEfiProcessorProducerGuid, NULL, &HiiHandle, CpuStrings);
+
+
+ CopyMem (RecordBuffer.Raw, &mCpuDataRecordHeader, HeaderSize);
+
+
+ RecordBuffer.DataRecord->DataRecordHeader.RecordType = ProcessorVersionRecordType;
+ RecordBuffer.DataRecord->VariableRecord.ProcessorVersion = STRING_TOKEN (STR_INTEL_GENUINE_PROCESSOR);
+ TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_VERSION_DATA);
+
+ Status = DataHub->LogData (
+ DataHub,
+ &gEfiProcessorSubClassGuid,
+ &gEfiProcessorProducerGuid,
+ EFI_DATA_RECORD_CLASS_DATA,
+ RecordBuffer.Raw,
+ TotalSize
+ );
+
+ //
+ // Store CPU frequency data record to data hub - It's an emulator so make up a value
+ //
+ RecordBuffer.DataRecord->DataRecordHeader.RecordType = ProcessorCoreFrequencyRecordType;
+ RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Value = 1234;
+ RecordBuffer.DataRecord->VariableRecord.ProcessorCoreFrequency.Exponent = 6;
+ TotalSize = HeaderSize + sizeof (EFI_PROCESSOR_CORE_FREQUENCY_DATA);
+
+ Status = DataHub->LogData (
+ DataHub,
+ &gEfiProcessorSubClassGuid,
+ &gEfiProcessorProducerGuid,
+ EFI_DATA_RECORD_CLASS_DATA,
+ RecordBuffer.Raw,
+ TotalSize
+ );
+
+ FreePool (RecordBuffer.Raw);
+}
+
+EFI_STATUS
+EFIAPI
+InitializeCpu (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+/*++
+
+Routine Description:
+
+ Initialize the state information for the CPU Architectural Protocol
+
+Arguments:
+
+ ImageHandle of the loaded driver
+ Pointer to the System Table
+
+Returns:
+
+ Status
+
+ EFI_SUCCESS - protocol instance can be published
+ EFI_OUT_OF_RESOURCES - cannot allocate protocol data structure
+ EFI_DEVICE_ERROR - cannot create the thread
+
+--*/
+// TODO: SystemTable - add argument and description to function comment
+{
+ EFI_STATUS Status;
+
+ CpuUpdateDataHub ();
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &mCpuTemplate.Handle,
+ &gEfiCpuArchProtocolGuid, &mCpuTemplate.Cpu,
+ &gEfiCpuIoProtocolGuid, &mCpuTemplate.CpuIo,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ DEBUG ((EFI_D_ERROR, "CPU Architectural Protocol Loaded\n"));
+
+ return Status;
+}
diff --git a/UnixPkg/CpuRuntimeDxe/Cpu.inf b/UnixPkg/CpuRuntimeDxe/Cpu.inf
new file mode 100644
index 0000000000..a8613ff7b2
--- /dev/null
+++ b/UnixPkg/CpuRuntimeDxe/Cpu.inf
@@ -0,0 +1,73 @@
+#/** @file
+# Component description file for Cpu module.
+#
+# This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = Cpu
+ FILE_GUID = f3794b60-8985-11db-8e53-0040d02b1835
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeCpu
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ CpuIo.c
+ Cpu.c
+ CpuDriver.h
+ Strings.uni
+
+
+[Packages]
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
+ UnixPkg/UnixPkg.dec
+ MdePkg/MdePkg.dec
+
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ UefiDriverEntryPoint
+ UefiLib
+ HiiLib
+ DebugLib
+ BaseLib
+
+
+[Guids]
+ gEfiProcessorSubClassGuid # SOMETIMES_CONSUMED
+ gEfiProcessorProducerGuid # SOMETIMES_CONSUMED
+
+
+[Protocols]
+ gEfiUnixIoProtocolGuid # PROTOCOL_NOTIFY SOMETIMES_CONSUMED
+ gEfiDataHubProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
+ gEfiHiiProtocolGuid # PROTOCOL SOMETIMES_CONSUMED
+ gEfiCpuIoProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+ gEfiCpuArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+
+
+[Depex]
+ gEfiDataHubProtocolGuid \ No newline at end of file
diff --git a/UnixPkg/CpuRuntimeDxe/Cpu.msa b/UnixPkg/CpuRuntimeDxe/Cpu.msa
new file mode 100644
index 0000000000..b6be83fcb2
--- /dev/null
+++ b/UnixPkg/CpuRuntimeDxe/Cpu.msa
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>Cpu</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>f3794b60-8985-11db-8e53-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Component description file for Cpu module.</Abstract>
+ <Description>This CPU module abstracts the interrupt subsystem of a platform and the CPU-specific setjump-long pair.</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>Cpu</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>HiiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>Strings.uni</Filename>
+ <Filename>CpuDriver.h</Filename>
+ <Filename>Cpu.c</Filename>
+ <Filename>CpuIo.c</Filename>
+ <Filename>Cpu.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>gEfiCpuArchProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_PRODUCED">
+ <ProtocolCName>gEfiCpuIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="SOMETIMES_CONSUMED">
+ <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="SOMETIMES_CONSUMED">
+ <ProtocolCName>gEfiDataHubProtocolGuid</ProtocolCName>
+ </Protocol>
+ <ProtocolNotify Usage="SOMETIMES_CONSUMED">
+ <ProtocolNotifyCName>gEfiUnixIoProtocolGuid</ProtocolNotifyCName>
+ </ProtocolNotify>
+ </Protocols>
+ <DataHubs>
+ <DataHubRecord Usage="SOMETIMES_PRODUCED">
+ <DataHubCName>ProcessorVersion</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="SOMETIMES_PRODUCED">
+ <DataHubCName>ProcessorCoreFrequency</DataHubCName>
+ </DataHubRecord>
+ </DataHubs>
+ <Guids>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiProcessorProducerGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiProcessorSubClassGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiUnixCPUModelGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiUnixCPUSpeedGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>InitializeCpu</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/CpuRuntimeDxe/CpuDriver.h b/UnixPkg/CpuRuntimeDxe/CpuDriver.h
new file mode 100644
index 0000000000..8898143cfc
--- /dev/null
+++ b/UnixPkg/CpuRuntimeDxe/CpuDriver.h
@@ -0,0 +1,163 @@
+/*++
+
+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:
+
+ CpuDriver.h
+
+Abstract:
+
+ UNIX Emulation Architectural Protocol Driver as defined in Tiano.
+
+--*/
+
+#ifndef _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
+#define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_
+
+
+
+extern UINT8 CpuStrings[];
+
+//
+// Internal Data Structures
+//
+#define CPU_ARCH_PROT_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('c', 'a', 'p', 'd')
+
+typedef struct {
+ UINTN Signature;
+ EFI_HANDLE Handle;
+
+ EFI_CPU_ARCH_PROTOCOL Cpu;
+ EFI_CPU_IO_PROTOCOL CpuIo;
+
+ //
+ // Local Data for CPU interface goes here
+ //
+ BOOLEAN InterruptState;
+
+} CPU_ARCH_PROTOCOL_PRIVATE;
+
+#define CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS(a) \
+ CR (a, \
+ CPU_ARCH_PROTOCOL_PRIVATE, \
+ Cpu, \
+ CPU_ARCH_PROT_PRIVATE_SIGNATURE \
+ )
+
+EFI_STATUS
+EFIAPI
+CpuMemoryServiceRead (
+ IN EFI_CPU_IO_PROTOCOL *This,
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 Address,
+ IN UINTN Count,
+ IN OUT VOID *Buffer
+ );
+
+EFI_STATUS
+EFIAPI
+CpuMemoryServiceWrite (
+ IN EFI_CPU_IO_PROTOCOL *This,
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 Address,
+ IN UINTN Count,
+ IN OUT VOID *Buffer
+ );
+
+EFI_STATUS
+EFIAPI
+CpuIoServiceRead (
+ IN EFI_CPU_IO_PROTOCOL *This,
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 UserAddress,
+ IN UINTN Count,
+ IN OUT VOID *UserBuffer
+ );
+
+EFI_STATUS
+EFIAPI
+CpuIoServiceWrite (
+ IN EFI_CPU_IO_PROTOCOL *This,
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 UserAddress,
+ IN UINTN Count,
+ IN OUT VOID *UserBuffer
+ );
+
+EFI_STATUS
+EFIAPI
+InitializeCpu (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+EFI_STATUS
+EFIAPI
+UnixFlushCpuDataCache (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS Start,
+ IN UINT64 Length,
+ IN EFI_CPU_FLUSH_TYPE FlushType
+ );
+
+EFI_STATUS
+EFIAPI
+UnixEnableInterrupt (
+ IN EFI_CPU_ARCH_PROTOCOL *This
+ );
+
+EFI_STATUS
+EFIAPI
+UnixDisableInterrupt (
+ IN EFI_CPU_ARCH_PROTOCOL *This
+ );
+
+EFI_STATUS
+EFIAPI
+UnixGetInterruptState (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ OUT BOOLEAN *State
+ );
+
+EFI_STATUS
+EFIAPI
+UnixInit (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN EFI_CPU_INIT_TYPE InitType
+ );
+
+EFI_STATUS
+EFIAPI
+UnixRegisterInterruptHandler (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN EFI_EXCEPTION_TYPE InterruptType,
+ IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler
+ );
+
+EFI_STATUS
+EFIAPI
+UnixGetTimerValue (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN UINT32 TimerIndex,
+ OUT UINT64 *TimerValue,
+ OUT UINT64 *TimerPeriod OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+UnixSetMemoryAttributes (
+ IN EFI_CPU_ARCH_PROTOCOL *This,
+ IN EFI_PHYSICAL_ADDRESS BaseAddress,
+ IN UINT64 Length,
+ IN UINT64 Attributes
+ );
+
+#endif
diff --git a/UnixPkg/CpuRuntimeDxe/CpuIo.c b/UnixPkg/CpuRuntimeDxe/CpuIo.c
new file mode 100644
index 0000000000..2360fff5fc
--- /dev/null
+++ b/UnixPkg/CpuRuntimeDxe/CpuIo.c
@@ -0,0 +1,350 @@
+/*++
+
+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:
+
+ CpuIo.c
+
+Abstract:
+
+ This is the code that publishes the CPU I/O Protocol.
+ The intent herein is to have a single I/O service that can load
+ as early as possible, extend into runtime, and be layered upon by
+ the implementations of architectural protocols and the PCI Root
+ Bridge I/O Protocol.
+
+--*/
+#include "PiDxe.h"
+#include <Protocol/Cpu.h>
+#include <Protocol/DataHub.h>
+#include <Guid/DataHubRecords.h>
+#include <Protocol/CpuIo.h>
+#include <Protocol/FrameworkHii.h>
+#include <Guid/DataHubProducer.h>
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HiiLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <CpuDriver.h>
+
+#define IA32_MAX_IO_ADDRESS 0xFFFF
+#define IA32_MAX_MEM_ADDRESS 0xFFFFFFFF
+
+EFI_CPU_IO_PROTOCOL mCpuIoProtocol;
+
+EFI_STATUS
+CpuIoCheckAddressRange (
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 Address,
+ IN UINTN Count,
+ IN VOID *Buffer,
+ IN UINT64 Limit
+ );
+
+EFI_STATUS
+EFIAPI
+CpuMemoryServiceRead (
+ IN EFI_CPU_IO_PROTOCOL *This,
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 Address,
+ IN UINTN Count,
+ IN OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Perform the Memory Access Read service for the CPU I/O Protocol
+
+Arguments:
+
+ Pointer to an instance of the CPU I/O Protocol
+ Width of the Memory Access
+ Address of the Memory access
+ Count of the number of accesses to perform
+ Pointer to the buffer to read or write from memory
+
+Returns:
+
+ Status
+
+ EFI_SUCCESS - The data was read from or written to the EFI
+ System.
+ EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
+ EFI_INVALID_PARAMETER - Buffer is NULL.
+ EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
+ EFI_UNSUPPORTED - The address range specified by Address, Width,
+ and Count is not valid for this EFI System.
+
+--*/
+// TODO: This - add argument and description to function comment
+{
+ EFI_STATUS Status;
+
+ if (!Buffer) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Do nothing for Nt32 version
+ //
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+CpuMemoryServiceWrite (
+ IN EFI_CPU_IO_PROTOCOL *This,
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 Address,
+ IN UINTN Count,
+ IN OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Perform the Memory Access Read service for the CPU I/O Protocol
+
+Arguments:
+
+ Pointer to an instance of the CPU I/O Protocol
+ Width of the Memory Access
+ Address of the Memory access
+ Count of the number of accesses to perform
+ Pointer to the buffer to read or write from memory
+
+Returns:
+
+ Status
+
+ EFI_SUCCESS - The data was read from or written to the EFI System.
+ EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
+ EFI_INVALID_PARAMETER - Buffer is NULL.
+ EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
+ EFI_UNSUPPORTED - The address range specified by Address, Width, and
+ Count is not valid for this EFI System.
+
+--*/
+// TODO: This - add argument and description to function comment
+{
+ EFI_STATUS Status;
+
+ if (!Buffer) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = CpuIoCheckAddressRange (Width, Address, Count, Buffer, IA32_MAX_MEM_ADDRESS);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Do nothing for Nt32 version
+ //
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+CpuIoServiceRead (
+ IN EFI_CPU_IO_PROTOCOL *This,
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 UserAddress,
+ IN UINTN Count,
+ IN OUT VOID *UserBuffer
+ )
+/*++
+
+Routine Description:
+
+ This is the service that implements the I/O read
+
+Arguments:
+
+ Pointer to an instance of the CPU I/O Protocol
+ Width of the Memory Access
+ Address of the I/O access
+ Count of the number of accesses to perform
+ Pointer to the buffer to read or write from I/O space
+
+Returns:
+
+ Status
+ EFI_SUCCESS - The data was read from or written to the EFI System.
+ EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
+ EFI_INVALID_PARAMETER - Buffer is NULL.
+ EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
+ EFI_UNSUPPORTED - The address range specified by Address, Width, and
+ Count is not valid for this EFI System.
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: UserAddress - add argument and description to function comment
+// TODO: UserBuffer - add argument and description to function comment
+{
+ UINTN Address;
+ EFI_STATUS Status;
+
+ if (!UserBuffer) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Address = (UINTN) UserAddress;
+
+ if (Width >= EfiCpuIoWidthMaximum) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Do nothing for Nt32 version
+ //
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+CpuIoServiceWrite (
+ IN EFI_CPU_IO_PROTOCOL *This,
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 UserAddress,
+ IN UINTN Count,
+ IN OUT VOID *UserBuffer
+ )
+/*++
+
+Routine Description:
+
+
+ This is the service that implements the I/O Write
+
+Arguments:
+
+ Pointer to an instance of the CPU I/O Protocol
+ Width of the Memory Access
+ Address of the I/O access
+ Count of the number of accesses to perform
+ Pointer to the buffer to read or write from I/O space
+
+Returns:
+
+ Status
+
+ Status
+ EFI_SUCCESS - The data was read from or written to the EFI System.
+ EFI_INVALID_PARAMETER - Width is invalid for this EFI System.
+ EFI_INVALID_PARAMETER - Buffer is NULL.
+ EFI_UNSUPPORTED - The Buffer is not aligned for the given Width.
+ EFI_UNSUPPORTED - The address range specified by Address, Width, and
+ Count is not valid for this EFI System.
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: UserAddress - add argument and description to function comment
+// TODO: UserBuffer - add argument and description to function comment
+{
+ UINTN Address;
+ EFI_STATUS Status;
+
+ if (!UserBuffer) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Address = (UINTN) UserAddress;
+
+ if (Width >= EfiCpuIoWidthMaximum) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = CpuIoCheckAddressRange (Width, Address, Count, UserBuffer, IA32_MAX_IO_ADDRESS);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Do nothing for Nt32 version
+ //
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+CpuIoCheckAddressRange (
+ IN EFI_CPU_IO_PROTOCOL_WIDTH Width,
+ IN UINT64 Address,
+ IN UINTN Count,
+ IN VOID *Buffer,
+ IN UINT64 Limit
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Width - TODO: add argument description
+ Address - TODO: add argument description
+ Count - TODO: add argument description
+ Buffer - TODO: add argument description
+ Limit - TODO: add argument description
+
+Returns:
+
+ EFI_UNSUPPORTED - TODO: Add description for return value
+ EFI_UNSUPPORTED - TODO: Add description for return value
+ EFI_UNSUPPORTED - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UINTN AlignMask;
+
+ if (Address > Limit) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // For FiFo type, the target address won't increase during the access, so treat count as 1
+ //
+ if (Width >= EfiCpuIoWidthFifoUint8 && Width <= EfiCpuIoWidthFifoUint64) {
+ Count = 1;
+ }
+
+ Width = Width & 0x03;
+ if (Address - 1 + (1 << Width) * Count > Limit) {
+ return EFI_UNSUPPORTED;
+ }
+
+ AlignMask = (1 << Width) - 1;
+ if ((UINTN) Buffer & AlignMask) {
+ return EFI_UNSUPPORTED;
+ }
+
+ return EFI_SUCCESS;
+}
+
+
diff --git a/UnixPkg/CpuRuntimeDxe/Strings.uni b/UnixPkg/CpuRuntimeDxe/Strings.uni
new file mode 100644
index 0000000000..fd70fb9068
--- /dev/null
+++ b/UnixPkg/CpuRuntimeDxe/Strings.uni
Binary files differ
diff --git a/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c b/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c
new file mode 100644
index 0000000000..5889586cee
--- /dev/null
+++ b/UnixPkg/FvbServicesRuntimeDxe/FWBlockService.c
@@ -0,0 +1,1553 @@
+/*++
+
+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:
+
+ FWBlockService.c
+
+Abstract:
+
+Revision History
+
+--*/
+
+#include "PiDxe.h"
+#include <Guid/EventGroup.h>
+#include <Protocol/FvbExtension.h>
+#include <Protocol/FirmwareVolumeBlock.h>
+#include <Guid/AlternateFvBlock.h>
+#include <Protocol/DevicePath.h>
+
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/BaseLib.h>
+#include <Library/DxeServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include "FwBlockService.h"
+
+ESAL_FWB_GLOBAL *mFvbModuleGlobal;
+
+#define EFI_FVB2_STATUS (EFI_FVB2_READ_STATUS | EFI_FVB2_WRITE_STATUS | EFI_FVB2_LOCK_STATUS)
+
+EFI_FW_VOL_BLOCK_DEVICE mFvbDeviceTemplate = {
+ FVB_DEVICE_SIGNATURE,
+ {
+ {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_MEMMAP_DP,
+ {
+ sizeof (MEMMAP_DEVICE_PATH),
+ 0
+ }
+ },
+ EfiMemoryMappedIO,
+ 0,
+ 0,
+ },
+ {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ sizeof (EFI_DEVICE_PATH_PROTOCOL),
+ 0
+ }
+ }
+ },
+ 0,
+ {
+ FvbProtocolGetAttributes,
+ FvbProtocolSetAttributes,
+ FvbProtocolGetPhysicalAddress,
+ FvbProtocolGetBlockSize,
+ FvbProtocolRead,
+ FvbProtocolWrite,
+ FvbProtocolEraseBlocks,
+ NULL
+ },
+ {
+ FvbExtendProtocolEraseCustomBlockRange
+ }
+};
+
+
+
+VOID
+EFIAPI
+FvbVirtualddressChangeEvent (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+/*++
+
+Routine Description:
+
+ Fixup internal data so that EFI and SAL can be call in virtual mode.
+ Call the passed in Child Notify event and convert the mFvbModuleGlobal
+ date items to there virtual address.
+
+ mFvbModuleGlobal->FvInstance[FVB_PHYSICAL] - Physical copy of instance data
+ mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] - Virtual pointer to common
+ instance data.
+
+Arguments:
+
+ (Standard EFI notify event - EFI_EVENT_NOTIFY)
+
+Returns:
+
+ None
+
+--*/
+{
+ EFI_FW_VOL_INSTANCE *FwhInstance;
+ UINTN Index;
+
+ EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvInstance[FVB_VIRTUAL]);
+
+ //
+ // Convert the base address of all the instances
+ //
+ Index = 0;
+ FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];
+ while (Index < mFvbModuleGlobal->NumFv) {
+ EfiConvertPointer (0x0, (VOID **) &FwhInstance->FvBase[FVB_VIRTUAL]);
+ FwhInstance = (EFI_FW_VOL_INSTANCE *)
+ (
+ (UINTN) ((UINT8 *) FwhInstance) + FwhInstance->VolumeHeader.HeaderLength +
+ (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))
+ );
+ Index++;
+ }
+
+ EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL]);
+ EfiConvertPointer (0x0, (VOID **) &mFvbModuleGlobal);
+}
+
+EFI_STATUS
+GetFvbInstance (
+ IN UINTN Instance,
+ IN ESAL_FWB_GLOBAL *Global,
+ OUT EFI_FW_VOL_INSTANCE **FwhInstance,
+ IN BOOLEAN Virtual
+ )
+/*++
+
+Routine Description:
+ Retrieves the physical address of a memory mapped FV
+
+Arguments:
+ Instance - The FV instance whose base address is going to be
+ returned
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all
+ instance data
+ FwhInstance - The EFI_FW_VOL_INSTANCE fimrware instance structure
+ Virtual - Whether CPU is in virtual or physical mode
+
+Returns:
+ EFI_SUCCESS - Successfully returns
+ EFI_INVALID_PARAMETER - Instance not found
+
+--*/
+{
+ EFI_FW_VOL_INSTANCE *FwhRecord;
+
+ if (Instance >= Global->NumFv) {
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Find the right instance of the FVB private data
+ //
+ FwhRecord = Global->FvInstance[Virtual];
+ while (Instance > 0) {
+ FwhRecord = (EFI_FW_VOL_INSTANCE *)
+ (
+ (UINTN) ((UINT8 *) FwhRecord) + FwhRecord->VolumeHeader.HeaderLength +
+ (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))
+ );
+ Instance--;
+ }
+
+ *FwhInstance = FwhRecord;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+FvbGetPhysicalAddress (
+ IN UINTN Instance,
+ OUT EFI_PHYSICAL_ADDRESS *Address,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+/*++
+
+Routine Description:
+ Retrieves the physical address of a memory mapped FV
+
+Arguments:
+ Instance - The FV instance whose base address is going to be
+ returned
+ Address - Pointer to a caller allocated EFI_PHYSICAL_ADDRESS
+ that on successful return, contains the base address
+ of the firmware volume.
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all
+ instance data
+ Virtual - Whether CPU is in virtual or physical mode
+
+Returns:
+ EFI_SUCCESS - Successfully returns
+ EFI_INVALID_PARAMETER - Instance not found
+
+--*/
+{
+ EFI_FW_VOL_INSTANCE *FwhInstance;
+ EFI_STATUS Status;
+
+ //
+ // Find the right instance of the FVB private data
+ //
+ Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);
+ ASSERT_EFI_ERROR (Status);
+ *Address = FwhInstance->FvBase[Virtual];
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+FvbGetVolumeAttributes (
+ IN UINTN Instance,
+ OUT EFI_FVB_ATTRIBUTES *Attributes,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+/*++
+
+Routine Description:
+ Retrieves attributes, insures positive polarity of attribute bits, returns
+ resulting attributes in output parameter
+
+Arguments:
+ Instance - The FV instance whose attributes is going to be
+ returned
+ Attributes - Output buffer which contains attributes
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all
+ instance data
+ Virtual - Whether CPU is in virtual or physical mode
+
+Returns:
+ EFI_SUCCESS - Successfully returns
+ EFI_INVALID_PARAMETER - Instance not found
+
+--*/
+{
+ EFI_FW_VOL_INSTANCE *FwhInstance;
+ EFI_STATUS Status;
+
+ //
+ // Find the right instance of the FVB private data
+ //
+ Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);
+ ASSERT_EFI_ERROR (Status);
+ *Attributes = FwhInstance->VolumeHeader.Attributes;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+FvbGetLbaAddress (
+ IN UINTN Instance,
+ IN EFI_LBA Lba,
+ OUT UINTN *LbaAddress,
+ OUT UINTN *LbaLength,
+ OUT UINTN *NumOfBlocks,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+/*++
+
+Routine Description:
+ Retrieves the starting address of an LBA in an FV
+
+Arguments:
+ Instance - The FV instance which the Lba belongs to
+ Lba - The logical block address
+ LbaAddress - On output, contains the physical starting address
+ of the Lba
+ LbaLength - On output, contains the length of the block
+ NumOfBlocks - A pointer to a caller allocated UINTN in which the
+ number of consecutive blocks starting with Lba is
+ returned. All blocks in this range have a size of
+ BlockSize
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all
+ instance data
+ Virtual - Whether CPU is in virtual or physical mode
+
+Returns:
+ EFI_SUCCESS - Successfully returns
+ EFI_INVALID_PARAMETER - Instance not found
+
+--*/
+{
+ UINT32 NumBlocks;
+ UINT32 BlockLength;
+ UINTN Offset;
+ EFI_LBA StartLba;
+ EFI_LBA NextLba;
+ EFI_FW_VOL_INSTANCE *FwhInstance;
+ EFI_FV_BLOCK_MAP_ENTRY *BlockMap;
+ EFI_STATUS Status;
+
+ //
+ // Find the right instance of the FVB private data
+ //
+ Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);
+ ASSERT_EFI_ERROR (Status);
+
+ StartLba = 0;
+ Offset = 0;
+ BlockMap = &(FwhInstance->VolumeHeader.BlockMap[0]);
+
+ //
+ // Parse the blockmap of the FV to find which map entry the Lba belongs to
+ //
+ while (TRUE) {
+ NumBlocks = BlockMap->NumBlocks;
+ BlockLength = BlockMap->Length;
+
+ if (NumBlocks == 0 || BlockLength == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ NextLba = StartLba + NumBlocks;
+
+ //
+ // The map entry found
+ //
+ if (Lba >= StartLba && Lba < NextLba) {
+ Offset = Offset + (UINTN) MultU64x32 ((Lba - StartLba), BlockLength);
+ if (LbaAddress != NULL) {
+ *LbaAddress = FwhInstance->FvBase[Virtual] + Offset;
+ }
+
+ if (LbaLength != NULL) {
+ *LbaLength = BlockLength;
+ }
+
+ if (NumOfBlocks != NULL) {
+ *NumOfBlocks = (UINTN) (NextLba - Lba);
+ }
+
+ return EFI_SUCCESS;
+ }
+
+ StartLba = NextLba;
+ Offset = Offset + NumBlocks * BlockLength;
+ BlockMap++;
+ }
+}
+
+EFI_STATUS
+FvbReadBlock (
+ IN UINTN Instance,
+ IN EFI_LBA Lba,
+ IN UINTN BlockOffset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+/*++
+
+Routine Description:
+ Reads specified number of bytes into a buffer from the specified block
+
+Arguments:
+ Instance - The FV instance to be read from
+ Lba - The logical block address to be read from
+ BlockOffset - Offset into the block at which to begin reading
+ NumBytes - Pointer that on input contains the total size of
+ the buffer. On output, it contains the total number
+ of bytes read
+ Buffer - Pointer to a caller allocated buffer that will be
+ used to hold the data read
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all
+ instance data
+ Virtual - Whether CPU is in virtual or physical mode
+
+Returns:
+ EFI_SUCCESS - The firmware volume was read successfully and
+ contents are in Buffer
+ EFI_BAD_BUFFER_SIZE - Read attempted across a LBA boundary. On output,
+ NumBytes contains the total number of bytes returned
+ in Buffer
+ EFI_ACCESS_DENIED - The firmware volume is in the ReadDisabled state
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and
+ could not be read
+ EFI_INVALID_PARAMETER - Instance not found, or NumBytes, Buffer are NULL
+
+--*/
+{
+ EFI_FVB_ATTRIBUTES Attributes;
+ UINTN LbaAddress;
+ UINTN LbaLength;
+ EFI_STATUS Status;
+
+ //
+ // Check for invalid conditions
+ //
+ if ((NumBytes == NULL) || (Buffer == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (*NumBytes == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = FvbGetLbaAddress (Instance, Lba, &LbaAddress, &LbaLength, NULL, Global, Virtual);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ //
+ // Check if the FV is read enabled
+ //
+ FvbGetVolumeAttributes (Instance, &Attributes, Global, Virtual);
+
+ if ((Attributes & EFI_FVB2_READ_STATUS) == 0) {
+ return EFI_ACCESS_DENIED;
+ }
+ //
+ // Perform boundary checks and adjust NumBytes
+ //
+ if (BlockOffset > LbaLength) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (LbaLength < (*NumBytes + BlockOffset)) {
+ *NumBytes = (UINT32) (LbaLength - BlockOffset);
+ Status = EFI_BAD_BUFFER_SIZE;
+ }
+
+ CopyMem (Buffer, (UINT8 *) (LbaAddress + BlockOffset), (UINTN) (*NumBytes));
+
+ return Status;
+}
+
+EFI_STATUS
+FvbWriteBlock (
+ IN UINTN Instance,
+ IN EFI_LBA Lba,
+ IN UINTN BlockOffset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+/*++
+
+Routine Description:
+ Writes specified number of bytes from the input buffer to the block
+
+Arguments:
+ Instance - The FV instance to be written to
+ Lba - The starting logical block index to write to
+ BlockOffset - Offset into the block at which to begin writing
+ NumBytes - Pointer that on input contains the total size of
+ the buffer. On output, it contains the total number
+ of bytes actually written
+ Buffer - Pointer to a caller allocated buffer that contains
+ the source for the write
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all
+ instance data
+ Virtual - Whether CPU is in virtual or physical mode
+
+Returns:
+ EFI_SUCCESS - The firmware volume was written successfully
+ EFI_BAD_BUFFER_SIZE - Write attempted across a LBA boundary. On output,
+ NumBytes contains the total number of bytes
+ actually written
+ EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and
+ could not be written
+ EFI_INVALID_PARAMETER - Instance not found, or NumBytes, Buffer are NULL
+
+--*/
+{
+ EFI_FVB_ATTRIBUTES Attributes;
+ UINTN LbaAddress;
+ UINTN LbaLength;
+ EFI_STATUS Status;
+
+ //
+ // Check for invalid conditions
+ //
+ if ((NumBytes == NULL) || (Buffer == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (*NumBytes == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = FvbGetLbaAddress (Instance, Lba, &LbaAddress, &LbaLength, NULL, Global, Virtual);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ //
+ // Check if the FV is write enabled
+ //
+ FvbGetVolumeAttributes (Instance, &Attributes, Global, Virtual);
+
+ if ((Attributes & EFI_FVB2_WRITE_STATUS) == 0) {
+ return EFI_ACCESS_DENIED;
+ }
+ //
+ // Perform boundary checks and adjust NumBytes
+ //
+ if (BlockOffset > LbaLength) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (LbaLength < (*NumBytes + BlockOffset)) {
+ *NumBytes = (UINT32) (LbaLength - BlockOffset);
+ Status = EFI_BAD_BUFFER_SIZE;
+ }
+ //
+ // Write data
+ //
+ CopyMem ((UINT8 *) (LbaAddress + BlockOffset), Buffer, (UINTN) (*NumBytes));
+
+ return Status;
+}
+
+EFI_STATUS
+FvbEraseBlock (
+ IN UINTN Instance,
+ IN EFI_LBA Lba,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+/*++
+
+Routine Description:
+ Erases and initializes a firmware volume block
+
+Arguments:
+ Instance - The FV instance to be erased
+ Lba - The logical block index to be erased
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all
+ instance data
+ Virtual - Whether CPU is in virtual or physical mode
+
+Returns:
+ EFI_SUCCESS - The erase request was successfully completed
+ EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and
+ could not be written. Firmware device may have been
+ partially erased
+ EFI_INVALID_PARAMETER - Instance not found
+
+--*/
+{
+
+ EFI_FVB_ATTRIBUTES Attributes;
+ UINTN LbaAddress;
+ UINTN LbaLength;
+ EFI_STATUS Status;
+ UINT8 Data;
+
+ //
+ // Check if the FV is write enabled
+ //
+ FvbGetVolumeAttributes (Instance, &Attributes, Global, Virtual);
+
+ if ((Attributes & EFI_FVB2_WRITE_STATUS) == 0) {
+ return EFI_ACCESS_DENIED;
+ }
+ //
+ // Get the starting address of the block for erase.
+ //
+ Status = FvbGetLbaAddress (Instance, Lba, &LbaAddress, &LbaLength, NULL, Global, Virtual);
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if ((Attributes & EFI_FVB2_ERASE_POLARITY) != 0) {
+ Data = 0xFF;
+ } else {
+ Data = 0x0;
+ }
+
+ SetMem ((UINT8 *) LbaAddress, LbaLength, Data);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+FvbEraseCustomBlockRange (
+ IN UINTN Instance,
+ IN EFI_LBA StartLba,
+ IN UINTN OffsetStartLba,
+ IN EFI_LBA LastLba,
+ IN UINTN OffsetLastLba,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+/*++
+
+Routine Description:
+ Erases and initializes a specified range of a firmware volume
+
+Arguments:
+ Instance - The FV instance to be erased
+ StartLba - The starting logical block index to be erased
+ OffsetStartLba - Offset into the starting block at which to
+ begin erasing
+ LastLba - The last logical block index to be erased
+ OffsetStartLba - Offset into the last block at which to end erasing
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all
+ instance data
+ Virtual - Whether CPU is in virtual or physical mode
+
+Returns:
+ EFI_SUCCESS - The firmware volume was erased successfully
+ EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and
+ could not be written. Firmware device may have been
+ partially erased
+ EFI_INVALID_PARAMETER - Instance not found
+
+--*/
+{
+ EFI_LBA Index;
+ UINTN LbaSize;
+ UINTN ScratchLbaSizeData;
+ EFI_STATUS Status;
+
+ //
+ // First LBA
+ //
+ Status = FvbGetLbaAddress (Instance, StartLba, NULL, &LbaSize, NULL, Global, Virtual);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Use the scratch space as the intermediate buffer to transfer data
+ // Back up the first LBA in scratch space.
+ //
+ FvbReadBlock (Instance, StartLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual);
+
+ //
+ // erase now
+ //
+ FvbEraseBlock (Instance, StartLba, Global, Virtual);
+ ScratchLbaSizeData = OffsetStartLba;
+
+ //
+ // write the data back to the first block
+ //
+ if (ScratchLbaSizeData > 0) {
+ Status = FvbWriteBlock (Instance, StartLba, 0, &ScratchLbaSizeData, Global->FvbScratchSpace[Virtual], Global, Virtual);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+ //
+ // Middle LBAs
+ //
+ if (LastLba > (StartLba + 1)) {
+ for (Index = (StartLba + 1); Index <= (LastLba - 1); Index++) {
+ FvbEraseBlock (Instance, Index, Global, Virtual);
+ }
+ }
+ //
+ // Last LBAs, the same as first LBAs
+ //
+ if (LastLba > StartLba) {
+ Status = FvbGetLbaAddress (Instance, LastLba, NULL, &LbaSize, NULL, Global, Virtual);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ FvbReadBlock (Instance, LastLba, 0, &LbaSize, Global->FvbScratchSpace[Virtual], Global, Virtual);
+ FvbEraseBlock (Instance, LastLba, Global, Virtual);
+ }
+
+ ScratchLbaSizeData = LbaSize - (OffsetLastLba + 1);
+
+ if (ScratchLbaSizeData > 0) {
+ Status = FvbWriteBlock (
+ Instance,
+ LastLba,
+ (OffsetLastLba + 1),
+ &ScratchLbaSizeData,
+ Global->FvbScratchSpace[Virtual] + OffsetLastLba + 1,
+ Global,
+ Virtual
+ );
+ }
+
+ return Status;
+}
+
+EFI_STATUS
+FvbSetVolumeAttributes (
+ IN UINTN Instance,
+ IN OUT EFI_FVB_ATTRIBUTES *Attributes,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+/*++
+
+Routine Description:
+ Modifies the current settings of the firmware volume according to the
+ input parameter, and returns the new setting of the volume
+
+Arguments:
+ Instance - The FV instance whose attributes is going to be
+ modified
+ Attributes - On input, it is a pointer to EFI_FVB_ATTRIBUTES
+ containing the desired firmware volume settings.
+ On successful return, it contains the new settings
+ of the firmware volume
+ Global - Pointer to ESAL_FWB_GLOBAL that contains all
+ instance data
+ Virtual - Whether CPU is in virtual or physical mode
+
+Returns:
+ EFI_SUCCESS - Successfully returns
+ EFI_ACCESS_DENIED - The volume setting is locked and cannot be modified
+ EFI_INVALID_PARAMETER - Instance not found, or The attributes requested are
+ in conflict with the capabilities as declared in the
+ firmware volume header
+
+--*/
+{
+ EFI_FW_VOL_INSTANCE *FwhInstance;
+ EFI_FVB_ATTRIBUTES OldAttributes;
+ EFI_FVB_ATTRIBUTES *AttribPtr;
+ UINT32 Capabilities;
+ UINT32 OldStatus;
+ UINT32 NewStatus;
+ EFI_STATUS Status;
+ EFI_FVB_ATTRIBUTES UnchangedAttributes;
+
+
+ //
+ // Find the right instance of the FVB private data
+ //
+ Status = GetFvbInstance (Instance, Global, &FwhInstance, Virtual);
+ ASSERT_EFI_ERROR (Status);
+
+ AttribPtr = (EFI_FVB_ATTRIBUTES *) &(FwhInstance->VolumeHeader.Attributes);
+ OldAttributes = *AttribPtr;
+ Capabilities = OldAttributes & (EFI_FVB2_READ_DISABLED_CAP | \
+ EFI_FVB2_READ_ENABLED_CAP | \
+ EFI_FVB2_WRITE_DISABLED_CAP | \
+ EFI_FVB2_WRITE_ENABLED_CAP | \
+ EFI_FVB2_LOCK_CAP \
+ );
+
+ OldStatus = OldAttributes & EFI_FVB2_STATUS;
+ NewStatus = *Attributes & EFI_FVB2_STATUS;
+ UnchangedAttributes = EFI_FVB2_READ_DISABLED_CAP | \
+ EFI_FVB2_READ_ENABLED_CAP | \
+ EFI_FVB2_WRITE_DISABLED_CAP | \
+ EFI_FVB2_WRITE_ENABLED_CAP | \
+ EFI_FVB2_LOCK_CAP | \
+ EFI_FVB2_STICKY_WRITE | \
+ EFI_FVB2_MEMORY_MAPPED | \
+ EFI_FVB2_ERASE_POLARITY | \
+ EFI_FVB2_READ_LOCK_CAP | \
+ EFI_FVB2_WRITE_LOCK_CAP | \
+ EFI_FVB2_ALIGNMENT;
+
+ //
+ // Some attributes of FV is read only can *not* be set
+ //
+ if ((OldAttributes & UnchangedAttributes) ^ (*Attributes & UnchangedAttributes)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // If firmware volume is locked, no status bit can be updated
+ //
+ if (OldAttributes & EFI_FVB2_LOCK_STATUS) {
+ if (OldStatus ^ NewStatus) {
+ return EFI_ACCESS_DENIED;
+ }
+ }
+ //
+ // Test read disable
+ //
+ if ((Capabilities & EFI_FVB2_READ_DISABLED_CAP) == 0) {
+ if ((NewStatus & EFI_FVB2_READ_STATUS) == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+ //
+ // Test read enable
+ //
+ if ((Capabilities & EFI_FVB2_READ_ENABLED_CAP) == 0) {
+ if (NewStatus & EFI_FVB2_READ_STATUS) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+ //
+ // Test write disable
+ //
+ if ((Capabilities & EFI_FVB2_WRITE_DISABLED_CAP) == 0) {
+ if ((NewStatus & EFI_FVB2_WRITE_STATUS) == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+ //
+ // Test write enable
+ //
+ if ((Capabilities & EFI_FVB2_WRITE_ENABLED_CAP) == 0) {
+ if (NewStatus & EFI_FVB2_WRITE_STATUS) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+ //
+ // Test lock
+ //
+ if ((Capabilities & EFI_FVB2_LOCK_CAP) == 0) {
+ if (NewStatus & EFI_FVB2_LOCK_STATUS) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
+ *AttribPtr = (*AttribPtr) & (0xFFFFFFFF & (~EFI_FVB2_STATUS));
+ *AttribPtr = (*AttribPtr) | NewStatus;
+ *Attributes = *AttribPtr;
+
+ return EFI_SUCCESS;
+}
+//
+// FVB protocol APIs
+//
+EFI_STATUS
+EFIAPI
+FvbProtocolGetPhysicalAddress (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ OUT EFI_PHYSICAL_ADDRESS *Address
+ )
+/*++
+
+Routine Description:
+
+ Retrieves the physical address of the device.
+
+Arguments:
+
+ This - Calling context
+ Address - Output buffer containing the address.
+
+Returns:
+
+Returns:
+ EFI_SUCCESS - Successfully returns
+
+--*/
+{
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+
+ FvbDevice = FVB_DEVICE_FROM_THIS (This);
+
+ return FvbGetPhysicalAddress (FvbDevice->Instance, Address, mFvbModuleGlobal, EfiGoneVirtual ());
+}
+
+EFI_STATUS
+EFIAPI
+FvbProtocolGetBlockSize (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ OUT UINTN *BlockSize,
+ OUT UINTN *NumOfBlocks
+ )
+/*++
+
+Routine Description:
+ Retrieve the size of a logical block
+
+Arguments:
+ This - Calling context
+ Lba - Indicates which block to return the size for.
+ BlockSize - A pointer to a caller allocated UINTN in which
+ the size of the block is returned
+ NumOfBlocks - a pointer to a caller allocated UINTN in which the
+ number of consecutive blocks starting with Lba is
+ returned. All blocks in this range have a size of
+ BlockSize
+
+Returns:
+ EFI_SUCCESS - The firmware volume was read successfully and
+ contents are in Buffer
+
+--*/
+{
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+
+ FvbDevice = FVB_DEVICE_FROM_THIS (This);
+
+ return FvbGetLbaAddress (
+ FvbDevice->Instance,
+ Lba,
+ NULL,
+ BlockSize,
+ NumOfBlocks,
+ mFvbModuleGlobal,
+ EfiGoneVirtual ()
+ );
+}
+
+EFI_STATUS
+EFIAPI
+FvbProtocolGetAttributes (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ OUT EFI_FVB_ATTRIBUTES *Attributes
+ )
+/*++
+
+Routine Description:
+ Retrieves Volume attributes. No polarity translations are done.
+
+Arguments:
+ This - Calling context
+ Attributes - output buffer which contains attributes
+
+Returns:
+ EFI_SUCCESS - Successfully returns
+
+--*/
+{
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+
+ FvbDevice = FVB_DEVICE_FROM_THIS (This);
+
+ return FvbGetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ());
+}
+
+EFI_STATUS
+EFIAPI
+FvbProtocolSetAttributes (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN OUT EFI_FVB_ATTRIBUTES *Attributes
+ )
+/*++
+
+Routine Description:
+ Sets Volume attributes. No polarity translations are done.
+
+Arguments:
+ This - Calling context
+ Attributes - output buffer which contains attributes
+
+Returns:
+ EFI_SUCCESS - Successfully returns
+
+--*/
+{
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+
+ FvbDevice = FVB_DEVICE_FROM_THIS (This);
+
+ return FvbSetVolumeAttributes (FvbDevice->Instance, Attributes, mFvbModuleGlobal, EfiGoneVirtual ());
+}
+
+EFI_STATUS
+EFIAPI
+FvbProtocolEraseBlocks (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ ...
+ )
+/*++
+
+Routine Description:
+
+ The EraseBlock() function erases one or more blocks as denoted by the
+ variable argument list. The entire parameter list of blocks must be verified
+ prior to erasing any blocks. If a block is requested that does not exist
+ within the associated firmware volume (it has a larger index than the last
+ block of the firmware volume), the EraseBlock() function must return
+ EFI_INVALID_PARAMETER without modifying the contents of the firmware volume.
+
+Arguments:
+ This - Calling context
+ ... - Starting LBA followed by Number of Lba to erase.
+ a -1 to terminate the list.
+
+Returns:
+ EFI_SUCCESS - The erase request was successfully completed
+ EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and
+ could not be written. Firmware device may have been
+ partially erased
+
+--*/
+{
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+ EFI_FW_VOL_INSTANCE *FwhInstance;
+ UINTN NumOfBlocks;
+ VA_LIST args;
+ EFI_LBA StartingLba;
+ UINTN NumOfLba;
+ EFI_STATUS Status;
+
+ FvbDevice = FVB_DEVICE_FROM_THIS (This);
+
+ Status = GetFvbInstance (FvbDevice->Instance, mFvbModuleGlobal, &FwhInstance, EfiGoneVirtual ());
+ ASSERT_EFI_ERROR (Status);
+
+ NumOfBlocks = FwhInstance->NumOfBlocks;
+
+ VA_START (args, This);
+
+ do {
+ StartingLba = VA_ARG (args, EFI_LBA);
+ if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
+ break;
+ }
+
+ NumOfLba = VA_ARG (args, UINT32);
+
+ //
+ // Check input parameters
+ //
+ if (NumOfLba == 0) {
+ VA_END (args);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((StartingLba + NumOfLba) > NumOfBlocks) {
+ return EFI_INVALID_PARAMETER;
+ }
+ } while (1);
+
+ VA_END (args);
+
+ VA_START (args, This);
+ do {
+ StartingLba = VA_ARG (args, EFI_LBA);
+ if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
+ break;
+ }
+
+ NumOfLba = VA_ARG (args, UINT32);
+
+ while (NumOfLba > 0) {
+ Status = FvbEraseBlock (FvbDevice->Instance, StartingLba, mFvbModuleGlobal, EfiGoneVirtual ());
+ if (EFI_ERROR (Status)) {
+ VA_END (args);
+ return Status;
+ }
+
+ StartingLba++;
+ NumOfLba--;
+ }
+
+ } while (1);
+
+ VA_END (args);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+FvbProtocolWrite (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Writes data beginning at Lba:Offset from FV. The write terminates either
+ when *NumBytes of data have been written, or when a block boundary is
+ reached. *NumBytes is updated to reflect the actual number of bytes
+ written. The write opertion does not include erase. This routine will
+ attempt to write only the specified bytes. If the writes do not stick,
+ it will return an error.
+
+Arguments:
+ This - Calling context
+ Lba - Block in which to begin write
+ Offset - Offset in the block at which to begin write
+ NumBytes - On input, indicates the requested write size. On
+ output, indicates the actual number of bytes written
+ Buffer - Buffer containing source data for the write.
+
+Returns:
+ EFI_SUCCESS - The firmware volume was written successfully
+ EFI_BAD_BUFFER_SIZE - Write attempted across a LBA boundary. On output,
+ NumBytes contains the total number of bytes
+ actually written
+ EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and
+ could not be written
+ EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL
+
+--*/
+{
+
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+
+ FvbDevice = FVB_DEVICE_FROM_THIS (This);
+
+ return FvbWriteBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer, mFvbModuleGlobal, EfiGoneVirtual ());
+}
+
+EFI_STATUS
+EFIAPI
+FvbProtocolRead (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Reads data beginning at Lba:Offset from FV. The Read terminates either
+ when *NumBytes of data have been read, or when a block boundary is
+ reached. *NumBytes is updated to reflect the actual number of bytes
+ written. The write opertion does not include erase. This routine will
+ attempt to write only the specified bytes. If the writes do not stick,
+ it will return an error.
+
+Arguments:
+ This - Calling context
+ Lba - Block in which to begin Read
+ Offset - Offset in the block at which to begin Read
+ NumBytes - On input, indicates the requested write size. On
+ output, indicates the actual number of bytes Read
+ Buffer - Buffer containing source data for the Read.
+
+Returns:
+ EFI_SUCCESS - The firmware volume was read successfully and
+ contents are in Buffer
+ EFI_BAD_BUFFER_SIZE - Read attempted across a LBA boundary. On output,
+ NumBytes contains the total number of bytes returned
+ in Buffer
+ EFI_ACCESS_DENIED - The firmware volume is in the ReadDisabled state
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and
+ could not be read
+ EFI_INVALID_PARAMETER - NumBytes or Buffer are NULL
+
+--*/
+{
+
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+
+ FvbDevice = FVB_DEVICE_FROM_THIS (This);
+
+ return FvbReadBlock (FvbDevice->Instance, Lba, Offset, NumBytes, Buffer, mFvbModuleGlobal, EfiGoneVirtual ());
+}
+//
+// FVB Extension Protocols
+//
+EFI_STATUS
+EFIAPI
+FvbExtendProtocolEraseCustomBlockRange (
+ IN EFI_FVB_EXTENSION_PROTOCOL *This,
+ IN EFI_LBA StartLba,
+ IN UINTN OffsetStartLba,
+ IN EFI_LBA LastLba,
+ IN UINTN OffsetLastLba
+ )
+/*++
+
+Routine Description:
+ Erases and initializes a specified range of a firmware volume
+
+Arguments:
+ This - Calling context
+ StartLba - The starting logical block index to be erased
+ OffsetStartLba - Offset into the starting block at which to
+ begin erasing
+ LastLba - The last logical block index to be erased
+ OffsetStartLba - Offset into the last block at which to end erasing
+
+Returns:
+ EFI_SUCCESS - The firmware volume was erased successfully
+ EFI_ACCESS_DENIED - The firmware volume is in the WriteDisabled state
+ EFI_DEVICE_ERROR - The block device is not functioning correctly and
+ could not be written. Firmware device may have been
+ partially erased
+
+--*/
+{
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+
+ FvbDevice = FVB_EXTEND_DEVICE_FROM_THIS (This);
+
+ return FvbEraseCustomBlockRange (
+ FvbDevice->Instance,
+ StartLba,
+ OffsetStartLba,
+ LastLba,
+ OffsetLastLba,
+ mFvbModuleGlobal,
+ EfiGoneVirtual ()
+ );
+}
+
+STATIC
+EFI_STATUS
+ValidateFvHeader (
+ EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader
+ )
+/*++
+
+Routine Description:
+ Check the integrity of firmware volume header
+
+Arguments:
+ FwVolHeader - A pointer to a firmware volume header
+
+Returns:
+ EFI_SUCCESS - The firmware volume is consistent
+ EFI_NOT_FOUND - The firmware volume has corrupted. So it is not an FV
+
+--*/
+{
+ UINT16 *Ptr;
+ UINT16 HeaderLength;
+ UINT16 Checksum;
+
+ //
+ // Verify the header revision, header signature, length
+ // Length of FvBlock cannot be 2**64-1
+ // HeaderLength cannot be an odd number
+ //
+ if ((FwVolHeader->Revision != EFI_FVH_REVISION) ||
+ (FwVolHeader->Signature != EFI_FVH_SIGNATURE) ||
+ (FwVolHeader->FvLength == ((UINTN) -1)) ||
+ ((FwVolHeader->HeaderLength & 0x01) != 0)
+ ) {
+ return EFI_NOT_FOUND;
+ }
+ //
+ // Verify the header checksum
+ //
+ HeaderLength = (UINT16) (FwVolHeader->HeaderLength / 2);
+ Ptr = (UINT16 *) FwVolHeader;
+ Checksum = 0;
+ while (HeaderLength > 0) {
+ Checksum = Checksum + (*Ptr);
+ HeaderLength--;
+ Ptr++;
+ }
+
+ if (Checksum != 0) {
+ return EFI_NOT_FOUND;
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+FvbInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+/*++
+
+Routine Description:
+ This function does common initialization for FVB services
+
+Arguments:
+
+Returns:
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_FW_VOL_INSTANCE *FwhInstance;
+ EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader;
+ EFI_DXE_SERVICES *DxeServices;
+ EFI_GCD_MEMORY_SPACE_DESCRIPTOR Descriptor;
+ UINT32 BufferSize;
+ EFI_FV_BLOCK_MAP_ENTRY *PtrBlockMapEntry;
+ EFI_HANDLE FwbHandle;
+ EFI_FW_VOL_BLOCK_DEVICE *FvbDevice;
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *OldFwbInterface;
+ EFI_DEVICE_PATH_PROTOCOL *TempFwbDevicePath;
+ FV_DEVICE_PATH TempFvbDevicePathData;
+ UINT32 MaxLbaSize;
+ EFI_PHYSICAL_ADDRESS BaseAddress;
+ UINT64 Length;
+ UINTN NumOfBlocks;
+ EFI_PEI_HOB_POINTERS FvHob;
+
+ //
+ // Get the DXE services table
+ //
+ DxeServices = gDS;
+
+ //
+ // Allocate runtime services data for global variable, which contains
+ // the private data of all firmware volume block instances
+ //
+ Status = gBS->AllocatePool (
+ EfiRuntimeServicesData,
+ sizeof (ESAL_FWB_GLOBAL),
+ (VOID**) &mFvbModuleGlobal
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Calculate the total size for all firmware volume block instances
+ //
+ BufferSize = 0;
+
+ FvHob.Raw = GetHobList ();
+ while ((FvHob.Raw = GetNextHob (EFI_HOB_TYPE_FV, FvHob.Raw)) != NULL) {
+ BaseAddress = FvHob.FirmwareVolume->BaseAddress;
+ Length = FvHob.FirmwareVolume->Length;
+ //
+ // Check if it is a "real" flash
+ //
+ Status = DxeServices->GetMemorySpaceDescriptor (
+ BaseAddress,
+ &Descriptor
+ );
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) {
+ FvHob.Raw = GET_NEXT_HOB (FvHob);
+ continue;
+ }
+
+ FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;
+ Status = ValidateFvHeader (FwVolHeader);
+ if (EFI_ERROR (Status)) {
+ //
+ // Get FvbInfo
+ //
+ Status = GetFvbInfo (Length, &FwVolHeader);
+ if (EFI_ERROR (Status)) {
+ FvHob.Raw = GET_NEXT_HOB (FvHob);
+ continue;
+ }
+ }
+
+ BufferSize += (sizeof (EFI_FW_VOL_INSTANCE) + FwVolHeader->HeaderLength - sizeof (EFI_FIRMWARE_VOLUME_HEADER));
+ FvHob.Raw = GET_NEXT_HOB (FvHob);
+ }
+
+ //
+ // Only need to allocate once. There is only one copy of physical memory for
+ // the private data of each FV instance. But in virtual mode or in physical
+ // mode, the address of the the physical memory may be different.
+ //
+ Status = gBS->AllocatePool (
+ EfiRuntimeServicesData,
+ BufferSize,
+ (VOID**) &mFvbModuleGlobal->FvInstance[FVB_PHYSICAL]
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Make a virtual copy of the FvInstance pointer.
+ //
+ FwhInstance = mFvbModuleGlobal->FvInstance[FVB_PHYSICAL];
+ mFvbModuleGlobal->FvInstance[FVB_VIRTUAL] = FwhInstance;
+
+ mFvbModuleGlobal->NumFv = 0;
+ MaxLbaSize = 0;
+
+ FvHob.Raw = GetHobList ();
+ while (NULL != (FvHob.Raw = GetNextHob (EFI_HOB_TYPE_FV, FvHob.Raw))) {
+ BaseAddress = FvHob.FirmwareVolume->BaseAddress;
+ Length = FvHob.FirmwareVolume->Length;
+ //
+ // Check if it is a "real" flash
+ //
+ Status = DxeServices->GetMemorySpaceDescriptor (
+ BaseAddress,
+ &Descriptor
+ );
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ if (Descriptor.GcdMemoryType != EfiGcdMemoryTypeMemoryMappedIo) {
+ FvHob.Raw = GET_NEXT_HOB (FvHob);
+ continue;
+ }
+
+ FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) BaseAddress;
+ Status = ValidateFvHeader (FwVolHeader);
+ if (EFI_ERROR (Status)) {
+ //
+ // Get FvbInfo to provide in FwhInstance.
+ //
+ Status = GetFvbInfo (Length, &FwVolHeader);
+ if (EFI_ERROR (Status)) {
+ FvHob.Raw = GET_NEXT_HOB (FvHob);
+ continue;
+ }
+ //
+ // Write healthy FV header back.
+ //
+ CopyMem (
+ (VOID *) (UINTN) BaseAddress,
+ (VOID *) FwVolHeader,
+ FwVolHeader->HeaderLength
+ );
+ }
+
+ FwhInstance->FvBase[FVB_PHYSICAL] = (UINTN) BaseAddress;
+ FwhInstance->FvBase[FVB_VIRTUAL] = (UINTN) BaseAddress;
+
+ CopyMem ((UINTN *) &(FwhInstance->VolumeHeader), (UINTN *) FwVolHeader, FwVolHeader->HeaderLength);
+ FwVolHeader = &(FwhInstance->VolumeHeader);
+ EfiInitializeLock (&(FwhInstance->FvbDevLock), TPL_HIGH_LEVEL);
+
+ NumOfBlocks = 0;
+
+ for (PtrBlockMapEntry = FwVolHeader->BlockMap; PtrBlockMapEntry->NumBlocks != 0; PtrBlockMapEntry++) {
+ //
+ // Get the maximum size of a block. The size will be used to allocate
+ // buffer for Scratch space, the intermediate buffer for FVB extension
+ // protocol
+ //
+ if (MaxLbaSize < PtrBlockMapEntry->Length) {
+ MaxLbaSize = PtrBlockMapEntry->Length;
+ }
+
+ NumOfBlocks = NumOfBlocks + PtrBlockMapEntry->NumBlocks;
+ }
+ //
+ // The total number of blocks in the FV.
+ //
+ FwhInstance->NumOfBlocks = NumOfBlocks;
+
+ //
+ // Add a FVB Protocol Instance
+ //
+ Status = gBS->AllocatePool (
+ EfiRuntimeServicesData,
+ sizeof (EFI_FW_VOL_BLOCK_DEVICE),
+ (VOID**) &FvbDevice
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ CopyMem (FvbDevice, &mFvbDeviceTemplate, sizeof (EFI_FW_VOL_BLOCK_DEVICE));
+
+ FvbDevice->Instance = mFvbModuleGlobal->NumFv;
+ mFvbModuleGlobal->NumFv++;
+
+ //
+ // Set up the devicepath
+ //
+ FvbDevice->DevicePath.MemMapDevPath.StartingAddress = BaseAddress;
+ FvbDevice->DevicePath.MemMapDevPath.EndingAddress = BaseAddress + (FwVolHeader->FvLength - 1);
+
+ //
+ // Find a handle with a matching device path that has supports FW Block protocol
+ //
+ TempFwbDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) &TempFvbDevicePathData;
+ CopyMem (TempFwbDevicePath, &FvbDevice->DevicePath, sizeof (FV_DEVICE_PATH));
+ Status = gBS->LocateDevicePath (&gEfiFirmwareVolumeBlockProtocolGuid, &TempFwbDevicePath, &FwbHandle);
+ if (EFI_ERROR (Status)) {
+ //
+ // LocateDevicePath fails so install a new interface and device path
+ //
+ FwbHandle = NULL;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &FwbHandle,
+ &gEfiFirmwareVolumeBlockProtocolGuid,
+ &FvbDevice->FwVolBlockInstance,
+ &gEfiDevicePathProtocolGuid,
+ &FvbDevice->DevicePath,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+ } else if (EfiIsDevicePathEnd (TempFwbDevicePath)) {
+ //
+ // Device allready exists, so reinstall the FVB protocol
+ //
+ Status = gBS->HandleProtocol (
+ FwbHandle,
+ &gEfiFirmwareVolumeBlockProtocolGuid,
+ (VOID**)&OldFwbInterface
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Status = gBS->ReinstallProtocolInterface (
+ FwbHandle,
+ &gEfiFirmwareVolumeBlockProtocolGuid,
+ OldFwbInterface,
+ &FvbDevice->FwVolBlockInstance
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ } else {
+ //
+ // There was a FVB protocol on an End Device Path node
+ //
+ ASSERT (FALSE);
+ }
+ //
+ // Install FVB Extension Protocol on the same handle
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &FwbHandle,
+ &gEfiFvbExtensionProtocolGuid,
+ &FvbDevice->FvbExtension,
+ &gEfiAlternateFvBlockGuid,
+ NULL,
+ NULL
+ );
+
+ ASSERT_EFI_ERROR (Status);
+
+ FwhInstance = (EFI_FW_VOL_INSTANCE *)
+ (
+ (UINTN) ((UINT8 *) FwhInstance) + FwVolHeader->HeaderLength +
+ (sizeof (EFI_FW_VOL_INSTANCE) - sizeof (EFI_FIRMWARE_VOLUME_HEADER))
+ );
+
+ FvHob.Raw = GET_NEXT_HOB (FvHob);
+ }
+
+ //
+ // Allocate for scratch space, an intermediate buffer for FVB extention
+ //
+ Status = gBS->AllocatePool (
+ EfiRuntimeServicesData,
+ MaxLbaSize,
+ (VOID**)&mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL]
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ mFvbModuleGlobal->FvbScratchSpace[FVB_VIRTUAL] = mFvbModuleGlobal->FvbScratchSpace[FVB_PHYSICAL];
+
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c b/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c
new file mode 100644
index 0000000000..6670359099
--- /dev/null
+++ b/UnixPkg/FvbServicesRuntimeDxe/FvbInfo.c
@@ -0,0 +1,156 @@
+/*++
+
+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:
+
+ FvbInfo.c
+
+Abstract:
+
+ Defines data structure that is the volume header found.These data is intent
+ to decouple FVB driver with FV header.
+
+--*/
+#include "PiDxe.h"
+#include <Guid/EventGroup.h>
+#include <Protocol/FvbExtension.h>
+#include <Protocol/FirmwareVolumeBlock.h>
+#include <Guid/AlternateFvBlock.h>
+#include <Protocol/DevicePath.h>
+
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/BaseLib.h>
+#include <Library/DxeServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/PcdLib.h>
+#include <Guid/FirmwareFileSystem2.h>
+#include <Guid/SystemNvDataGuid.h>
+
+typedef struct {
+ UINT64 FvLength;
+ EFI_FIRMWARE_VOLUME_HEADER FvbInfo;
+ //
+ // EFI_FV_BLOCK_MAP_ENTRY ExtraBlockMap[n];//n=0
+ //
+ EFI_FV_BLOCK_MAP_ENTRY End[1];
+} EFI_FVB_MEDIA_INFO;
+
+EFI_FVB_MEDIA_INFO mPlatformFvbMediaInfo[] = {
+ //
+ // Recovery BOIS FVB
+ //
+ {
+ FixedPcdGet32 (PcdUnixFlashFvRecoverySize),
+ {
+ {
+ 0,
+ }, // ZeroVector[16]
+ EFI_FIRMWARE_FILE_SYSTEM2_GUID,
+ FixedPcdGet32 (PcdUnixFlashFvRecoverySize),
+ EFI_FVH_SIGNATURE,
+ EFI_FVB2_READ_ENABLED_CAP |
+ EFI_FVB2_READ_STATUS |
+ EFI_FVB2_WRITE_ENABLED_CAP |
+ EFI_FVB2_WRITE_STATUS |
+ EFI_FVB2_ERASE_POLARITY,
+ sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
+ 0, // CheckSum
+ 0, // ExtHeaderOffset
+ {
+ 0,
+ }, // Reserved[1]
+ 1, // Revision
+ {
+ {
+ FixedPcdGet32 (PcdUnixFlashFvRecoverySize)/FixedPcdGet32 (PcdUnixFirmwareBlockSize),
+ FixedPcdGet32 (PcdUnixFirmwareBlockSize),
+ }
+ }
+ },
+ {
+ {
+ 0,
+ 0
+ }
+ }
+ },
+ //
+ // Systen NvStorage FVB
+ //
+ {
+ FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
+ FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
+ FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
+ FixedPcdGet32 (PcdUnixFlashNvStorageEventLogSize),
+ {
+ {
+ 0,
+ }, // ZeroVector[16]
+ EFI_SYSTEM_NV_DATA_HOB_GUID,
+ FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
+ FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
+ FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
+ FixedPcdGet32 (PcdUnixFlashNvStorageEventLogSize),
+ EFI_FVH_SIGNATURE,
+ EFI_FVB2_READ_ENABLED_CAP |
+ EFI_FVB2_READ_STATUS |
+ EFI_FVB2_WRITE_ENABLED_CAP |
+ EFI_FVB2_WRITE_STATUS |
+ EFI_FVB2_ERASE_POLARITY,
+ sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY),
+ 0, // CheckSum
+ 0, // ExtHeaderOffset
+ {
+ 0,
+ }, // Reserved[1]
+ 1, // Revision
+ {
+ {
+ (FixedPcdGet32 (PcdFlashNvStorageVariableSize) + \
+ FixedPcdGet32 (PcdFlashNvStorageFtwWorkingSize) + \
+ FixedPcdGet32 (PcdFlashNvStorageFtwSpareSize) + \
+ FixedPcdGet32 (PcdUnixFlashNvStorageEventLogSize)) / FixedPcdGet32 (PcdUnixFirmwareBlockSize),
+ FixedPcdGet32 (PcdUnixFirmwareBlockSize),
+ }
+ }
+ },
+ {
+ {
+ 0,
+ 0
+ }
+ }
+ }
+};
+
+EFI_STATUS
+GetFvbInfo (
+ IN UINT64 FvLength,
+ OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
+ )
+{
+ UINTN Index;
+
+ for (Index = 0; Index < sizeof (mPlatformFvbMediaInfo) / sizeof (EFI_FVB_MEDIA_INFO); Index += 1) {
+ if (mPlatformFvbMediaInfo[Index].FvLength == FvLength) {
+ *FvbInfo = &mPlatformFvbMediaInfo[Index].FvbInfo;
+ return EFI_SUCCESS;
+ }
+ }
+
+ return EFI_NOT_FOUND;
+}
diff --git a/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h b/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h
new file mode 100644
index 0000000000..6f949d37ec
--- /dev/null
+++ b/UnixPkg/FvbServicesRuntimeDxe/FwBlockService.h
@@ -0,0 +1,238 @@
+/*++
+
+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:
+
+ FwBlockService.h
+
+Abstract:
+
+ Firmware volume block driver for Intel Firmware Hub (FWH) device
+
+--*/
+
+#ifndef _FW_BLOCK_SERVICE_H
+#define _FW_BLOCK_SERVICE_H
+
+//
+// BugBug: Add documentation here for data structure!!!!
+//
+#define FVB_PHYSICAL 0
+#define FVB_VIRTUAL 1
+
+typedef struct {
+ EFI_LOCK FvbDevLock;
+ UINTN FvBase[2];
+ UINTN NumOfBlocks;
+ EFI_FIRMWARE_VOLUME_HEADER VolumeHeader;
+} EFI_FW_VOL_INSTANCE;
+
+typedef struct {
+ UINT32 NumFv;
+ EFI_FW_VOL_INSTANCE *FvInstance[2];
+ UINT8 *FvbScratchSpace[2];
+} ESAL_FWB_GLOBAL;
+
+//
+// Fvb Protocol instance data
+//
+#define FVB_DEVICE_FROM_THIS(a) CR (a, EFI_FW_VOL_BLOCK_DEVICE, FwVolBlockInstance, FVB_DEVICE_SIGNATURE)
+#define FVB_EXTEND_DEVICE_FROM_THIS(a) CR (a, EFI_FW_VOL_BLOCK_DEVICE, FvbExtension, FVB_DEVICE_SIGNATURE)
+#define FVB_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('F', 'V', 'B', 'N')
+
+typedef struct {
+ MEMMAP_DEVICE_PATH MemMapDevPath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevPath;
+} FV_DEVICE_PATH;
+
+typedef struct {
+ UINTN Signature;
+ FV_DEVICE_PATH DevicePath;
+ UINTN Instance;
+ EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL FwVolBlockInstance;
+ EFI_FVB_EXTENSION_PROTOCOL FvbExtension;
+} EFI_FW_VOL_BLOCK_DEVICE;
+
+EFI_STATUS
+GetFvbInfo (
+ IN UINT64 FvLength,
+ OUT EFI_FIRMWARE_VOLUME_HEADER **FvbInfo
+ )
+;
+
+EFI_STATUS
+FvbReadBlock (
+ IN UINTN Instance,
+ IN EFI_LBA Lba,
+ IN UINTN BlockOffset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+;
+
+EFI_STATUS
+FvbWriteBlock (
+ IN UINTN Instance,
+ IN EFI_LBA Lba,
+ IN UINTN BlockOffset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+;
+
+EFI_STATUS
+FvbEraseBlock (
+ IN UINTN Instance,
+ IN EFI_LBA Lba,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+;
+
+EFI_STATUS
+FvbSetVolumeAttributes (
+ IN UINTN Instance,
+ IN OUT EFI_FVB_ATTRIBUTES *Attributes,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+;
+
+EFI_STATUS
+FvbGetVolumeAttributes (
+ IN UINTN Instance,
+ OUT EFI_FVB_ATTRIBUTES *Attributes,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+;
+
+EFI_STATUS
+FvbGetPhysicalAddress (
+ IN UINTN Instance,
+ OUT EFI_PHYSICAL_ADDRESS *Address,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+;
+
+EFI_STATUS
+EFIAPI
+FvbInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+;
+
+
+VOID
+EFIAPI
+FvbClassAddressChangeEvent (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+;
+
+EFI_STATUS
+FvbGetLbaAddress (
+ IN UINTN Instance,
+ IN EFI_LBA Lba,
+ OUT UINTN *LbaAddress,
+ OUT UINTN *LbaLength,
+ OUT UINTN *NumOfBlocks,
+ IN ESAL_FWB_GLOBAL *Global,
+ IN BOOLEAN Virtual
+ )
+;
+
+//
+// Protocol APIs
+//
+EFI_STATUS
+EFIAPI
+FvbProtocolGetAttributes (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ OUT EFI_FVB_ATTRIBUTES *Attributes
+ )
+;
+
+EFI_STATUS
+EFIAPI
+FvbProtocolSetAttributes (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN OUT EFI_FVB_ATTRIBUTES *Attributes
+ )
+;
+
+EFI_STATUS
+EFIAPI
+FvbProtocolGetPhysicalAddress (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ OUT EFI_PHYSICAL_ADDRESS *Address
+ )
+;
+
+EFI_STATUS
+EFIAPI
+FvbProtocolGetBlockSize (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ OUT UINTN *BlockSize,
+ OUT UINTN *NumOfBlocks
+ )
+;
+
+EFI_STATUS
+EFIAPI
+FvbProtocolRead (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer
+ )
+;
+
+EFI_STATUS
+EFIAPI
+FvbProtocolWrite (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ IN EFI_LBA Lba,
+ IN UINTN Offset,
+ IN OUT UINTN *NumBytes,
+ IN UINT8 *Buffer
+ )
+;
+
+EFI_STATUS
+EFIAPI
+FvbProtocolEraseBlocks (
+ IN EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *This,
+ ...
+ )
+;
+
+EFI_STATUS
+EFIAPI
+FvbExtendProtocolEraseCustomBlockRange (
+ IN EFI_FVB_EXTENSION_PROTOCOL *This,
+ IN EFI_LBA StartLba,
+ IN UINTN OffsetStartLba,
+ IN EFI_LBA LastLba,
+ IN UINTN OffsetLastLba
+ )
+;
+
+#endif
diff --git a/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf b/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf
new file mode 100644
index 0000000000..52cc62e50d
--- /dev/null
+++ b/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf
@@ -0,0 +1,90 @@
+#/** @file
+# Component description file for Unix Fimware Volume Block DXE driver module.
+#
+# This DXE runtime driver implements and produces the Fimware Volue Block Protocol on
+# Unix emulator.
+# Copyright (c) 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = FwBlockService
+ FILE_GUID = f42fd042-8985-11db-a7db-0040d02b1835
+ MODULE_TYPE = DXE_RUNTIME_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = FvbInitialize
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.Ia32]
+ FvbInfo.c
+ FWBlockService.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ HobLib
+ DebugLib
+ UefiRuntimeLib
+ DxeServicesTableLib
+ BaseLib
+ UefiDriverEntryPoint
+ UefiLib
+
+
+[Guids]
+ gEfiEventVirtualAddressChangeGuid # ALWAYS_CONSUMED Create Event: EVENT_GROUP_GUID
+ gEfiAlternateFvBlockGuid # ALWAYS_PRODUCED
+
+
+[Protocols]
+ gEfiFvbExtensionProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+ gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+ gEfiDevicePathProtocolGuid # PROTOCOL SOMETIMES_PRODUCED
+
+
+[FixedPcd.common]
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareBlockSize
+
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoveryBase
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoverySize
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogBase
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize
+
+[Pcd.common]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
+
+
+[Depex]
+ TRUE
+
diff --git a/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa b/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa
new file mode 100644
index 0000000000..3792a0035a
--- /dev/null
+++ b/UnixPkg/FvbServicesRuntimeDxe/UnixFwh.msa
@@ -0,0 +1,99 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>FwBlockService</ModuleName>
+ <ModuleType>DXE_RUNTIME_DRIVER</ModuleType>
+ <GuidValue>f42fd042-8985-11db-a7db-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Component description file for Unix Fimware Volume Block DXE driver module.</Abstract>
+ <Description>This DXE runtime driver implements and produces the Fimware Volue Block Protocol on
+ Unix emulator.
+ </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>FwBlockService</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <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>DxeServicesTableLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiRuntimeLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>HobLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixFwh.dxs</Filename>
+ <Filename SupArchList="IA32">FWBlockService.c</Filename>
+ <Filename SupArchList="IA32">FwBlockService.h</Filename>
+ <Filename SupArchList="IA32">FvbInfo.c</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="SOMETIMES_PRODUCED">
+ <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_PRODUCED">
+ <ProtocolCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_PRODUCED">
+ <ProtocolCName>gEfiFvbExtensionProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Events>
+ <CreateEvents>
+ <EventTypes EventGuidCName="gEfiEventVirtualAddressChangeGuid" Usage="ALWAYS_CONSUMED">
+ <EventType>EVENT_GROUP_GUID</EventType>
+ </EventTypes>
+ </CreateEvents>
+ </Events>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_PRODUCED">
+ <GuidCName>gEfiAlternateFvBlockGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>FvbInitialize</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Include/Common/UnixInclude.h b/UnixPkg/Include/Common/UnixInclude.h
new file mode 100644
index 0000000000..922964672c
--- /dev/null
+++ b/UnixPkg/Include/Common/UnixInclude.h
@@ -0,0 +1,32 @@
+/*++
+
+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:
+ UnixInclude.h
+
+Abstract:
+ Public include file for the Unix Library
+
+--*/
+
+#ifndef __UNIX_INCLUDE_H__
+#define __UNIX_INCLUDE_H__
+#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
diff --git a/UnixPkg/Include/FlashLayout.h b/UnixPkg/Include/FlashLayout.h
new file mode 100644
index 0000000000..1a13f16c50
--- /dev/null
+++ b/UnixPkg/Include/FlashLayout.h
@@ -0,0 +1,64 @@
+/*++
+
+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:
+
+ FlashLayout.h
+
+Abstract:
+
+ Platform specific flash layout
+
+ BugBug: We need a better way
+
+--*/
+
+#ifndef __EFI_FLASH_LAYOUT__
+#define __EFI_FLASH_LAYOUT__
+
+//
+// Firmware Volume Information for Nt32
+// adding one working block before FFS FV,
+// and another one for spare block behind FFS FV
+//
+//
+// Note: When block number is changed in .dsc file,
+// this value should be changed accordingly!!!
+//
+#define FIRMWARE_BLOCK_NUMBER 0x28
+
+#define EFI_WINNT_FIRMWARE_OFFSET 0x0
+#define EFI_WINNT_FIRMWARE_LENGTH (0x10000 * FIRMWARE_BLOCK_NUMBER)
+
+#define EFI_WINNT_RUNTIME_UPDATABLE_OFFSET (EFI_WINNT_FIRMWARE_OFFSET + EFI_WINNT_FIRMWARE_LENGTH)
+
+#define EFI_WINNT_RUNTIME_UPDATABLE_LENGTH 0x10000
+
+#define EFI_WINNT_FTW_SPARE_BLOCK_OFFSET (EFI_WINNT_RUNTIME_UPDATABLE_OFFSET + EFI_WINNT_RUNTIME_UPDATABLE_LENGTH)
+
+#define EFI_WINNT_FTW_SPARE_BLOCK_LENGTH 0x10000
+
+#define EFI_WINNT_RUNTIME_UPDATABLE_FV_HEADER_LENGTH 0x48
+
+#define EFI_VARIABLE_STORE_OFFSET EFI_WINNT_RUNTIME_UPDATABLE_OFFSET
+
+#define EFI_VARIABLE_STORE_LENGTH 0x00C000
+
+#define EFI_EVENT_LOG_OFFSET (EFI_VARIABLE_STORE_OFFSET + EFI_VARIABLE_STORE_LENGTH)
+
+#define EFI_EVENT_LOG_LENGTH 0x002000
+
+#define EFI_FTW_WORKING_OFFSET (EFI_EVENT_LOG_OFFSET + EFI_EVENT_LOG_LENGTH)
+
+#define EFI_FTW_WORKING_LENGTH 0x002000
+
+#endif
+
diff --git a/UnixPkg/Include/Library/UnixLib.h b/UnixPkg/Include/Library/UnixLib.h
new file mode 100644
index 0000000000..9797093b91
--- /dev/null
+++ b/UnixPkg/Include/Library/UnixLib.h
@@ -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
index 0000000000..0c04d8202e
--- /dev/null
+++ b/UnixPkg/Include/Ppi/UnixAutoScan.h
@@ -0,0 +1,66 @@
+/*++
+
+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:
+
+ UnixAutoscan.h
+
+Abstract:
+
+Unix Autoscan PPI
+
+--*/
+
+#ifndef __UNIX_PEI_AUTOSCAN_H__
+#define __UNIX_PEI_AUTOSCAN_H__
+
+#include <UnixDxe.h>
+
+#define PEI_UNIX_AUTOSCAN_PPI_GUID \
+ { \
+ 0xf2ed3d14, 0x8985, 0x11db, {0xb0, 0x57, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+typedef
+EFI_STATUS
+(EFIAPI *PEI_UNIX_AUTOSCAN) (
+ 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
+
+--*/
+typedef struct {
+ PEI_UNIX_AUTOSCAN UnixAutoScan;
+} PEI_UNIX_AUTOSCAN_PPI;
+
+extern EFI_GUID gPeiUnixAutoScanPpiGuid;
+
+#endif
diff --git a/UnixPkg/Include/Ppi/UnixFwh.h b/UnixPkg/Include/Ppi/UnixFwh.h
new file mode 100644
index 0000000000..a9885a57bf
--- /dev/null
+++ b/UnixPkg/Include/Ppi/UnixFwh.h
@@ -0,0 +1,62 @@
+/*++
+
+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:
+
+ UnixFwh.h
+
+Abstract:
+
+ Unix FWH PPI as defined in Tiano
+
+--*/
+
+#ifndef __UNIX_PEI_FWH_H__
+#define __UNIX_PEI_FWH_H__
+
+#include <UnixDxe.h>
+
+#define UNIX_FWH_PPI_GUID \
+ { \
+ 0xf2f0dc30, 0x8985, 0x11db, {0xa1, 0x5b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+typedef
+EFI_STATUS
+(EFIAPI *UNIX_FWH_INFORMATION) (
+ 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
+
+--*/
+typedef struct {
+ UNIX_FWH_INFORMATION UnixFwh;
+} UNIX_FWH_PPI;
+
+extern EFI_GUID gUnixFwhPpiGuid;
+
+#endif
diff --git a/UnixPkg/Include/Ppi/UnixPeiLoadFile.h b/UnixPkg/Include/Ppi/UnixPeiLoadFile.h
new file mode 100644
index 0000000000..b91c630b5a
--- /dev/null
+++ b/UnixPkg/Include/Ppi/UnixPeiLoadFile.h
@@ -0,0 +1,65 @@
+/*++
+
+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:
+
+ UnixPeiLoadFile.h
+
+Abstract:
+
+ Unix Load File PPI.
+
+ When the PEI core is done it calls the DXE IPL via PPI
+
+--*/
+
+#ifndef __UNIX_PEI_LOAD_FILE_H__
+#define __UNIX_PEI_LOAD_FILE_H__
+
+#include <UnixDxe.h>
+
+#define UNIX_PEI_LOAD_FILE_GUID \
+ { \
+ 0xf2f48768, 0x8985, 0x11db, {0xb8, 0xda, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+typedef
+EFI_STATUS
+(EFIAPI *UNIX_PEI_LOAD_FILE) (
+ VOID *Pe32Data,
+ EFI_PHYSICAL_ADDRESS *ImageAddress,
+ UINT64 *ImageSize,
+ 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
+
+--*/
+typedef struct {
+ UNIX_PEI_LOAD_FILE PeiLoadFileService;
+} UNIX_PEI_LOAD_FILE_PPI;
+
+extern EFI_GUID gUnixPeiLoadFilePpiGuid;
+
+#endif
diff --git a/UnixPkg/Include/Ppi/UnixThunk.h b/UnixPkg/Include/Ppi/UnixThunk.h
new file mode 100644
index 0000000000..866bd61398
--- /dev/null
+++ b/UnixPkg/Include/Ppi/UnixThunk.h
@@ -0,0 +1,56 @@
+/*++
+
+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:
+
+ UnixThunk.h
+
+Abstract:
+
+ Unix Thunk interface PPI
+
+--*/
+
+#ifndef __UNIX_PEI_UNIX_THUNK_H__
+#define __UNIX_PEI_UNIX_THUNK_H__
+
+#include <UnixDxe.h>
+
+#define PEI_UNIX_THUNK_PPI_GUID \
+ { \
+ 0xf2f830f2, 0x8985, 0x11db, {0x80, 0x6b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+typedef
+VOID *
+(EFIAPI *PEI_UNIX_THUNK_INTERFACE) (
+ VOID
+ );
+
+/*++
+
+Routine Description:
+ Export of EFI_UNIX_THUNK_PROTOCOL from the Unix SEC.
+
+Arguments:
+ InterfaceBase - Address of the EFI_UNIX_THUNK_PROTOCOL
+
+Returns:
+ EFI_SUCCESS - Data returned
+
+--*/
+typedef struct {
+ PEI_UNIX_THUNK_INTERFACE UnixThunk;
+} PEI_UNIX_THUNK_PPI;
+
+extern EFI_GUID gPeiUnixThunkPpiGuid;
+
+#endif
diff --git a/UnixPkg/Include/Protocol/UnixIo.h b/UnixPkg/Include/Protocol/UnixIo.h
new file mode 100644
index 0000000000..1758ecb7c4
--- /dev/null
+++ b/UnixPkg/Include/Protocol/UnixIo.h
@@ -0,0 +1,142 @@
+/*++
+
+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:
+
+ UnixIo.h
+
+Abstract:
+
+--*/
+
+#ifndef _UNIX_IO_H_
+#define _UNIX_IO_H_
+
+#define EFI_UNIX_IO_PROTOCOL_GUID \
+ { \
+ 0xf2e23f54, 0x8985, 0x11db, {0xac, 0x79, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+typedef struct {
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+ EFI_GUID *TypeGuid;
+ UINT16 *EnvString;
+ UINT16 InstanceNumber;
+} EFI_UNIX_IO_PROTOCOL;
+
+extern EFI_GUID gEfiUnixIoProtocolGuid;
+
+//
+// The following GUIDs are used in EFI_UNIX_IO_PROTOCOL_GUID
+// Device paths. They map 1:1 with UNIX envirnment variables. The variables
+// define what virtual hardware the emulator/UnixBusDriver will produce.
+//
+//
+// EFI_UNIX_VIRTUAL_DISKS
+//
+#define EFI_UNIX_VIRTUAL_DISKS_GUID \
+ { \
+ 0xf2ba331a, 0x8985, 0x11db, {0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+extern EFI_GUID gEfiUnixVirtualDisksGuid;
+
+//
+// EFI_UNIX_PHYSICAL_DISKS
+//
+#define EFI_UNIX_PHYSICAL_DISKS_GUID \
+ { \
+ 0xf2bdcc96, 0x8985, 0x11db, {0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+extern EFI_GUID gEfiUnixPhysicalDisksGuid;
+
+//
+// EFI_UNIX_FILE_SYSTEM
+//
+#define EFI_UNIX_FILE_SYSTEM_GUID \
+ { \
+ 0xf2c16b9e, 0x8985, 0x11db, {0x92, 0xc8, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+extern EFI_GUID gEfiUnixFileSystemGuid;
+
+//
+// EFI_WIN_NT_SERIAL_PORT
+//
+#define EFI_UNIX_SERIAL_PORT_GUID \
+ { \
+ 0x6d3a727d, 0x66c8, 0x4d19, {0x87, 0xe6, 0x2, 0x15, 0x86, 0x14, 0x90, 0xf3} \
+ }
+
+extern EFI_GUID gEfiUnixSerialPortGuid;
+
+//
+// EFI_UNIX_UGA
+//
+#define EFI_UNIX_UGA_GUID \
+ { \
+ 0xf2c8b80e, 0x8985, 0x11db, {0x93, 0xf1, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+extern EFI_GUID gEfiUnixUgaGuid;
+
+//
+// EFI_UNIX_GOP
+//
+#define EFI_UNIX_GOP_GUID \
+ { \
+ 0xbace07c2, 0x8987, 0x11db, {0xa5, 0x9a, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+extern EFI_GUID gEfiUnixGopGuid;
+
+//
+// EFI_UNIX_CONSOLE
+//
+#define EFI_UNIX_CONSOLE_GUID \
+ { \
+ 0xf2cc5d06, 0x8985, 0x11db, {0xbb, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+extern EFI_GUID gEfiUnixConsoleGuid;
+
+//
+// EFI_UNIX_MEMORY
+//
+#define EFI_UNIX_MEMORY_GUID \
+ { \
+ 0xf2d006cc, 0x8985, 0x11db, {0xa4, 0x72, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+extern EFI_GUID gEfiUnixMemoryGuid;
+
+//
+// EFI_UNIX_CPU_MODEL
+//
+#define EFI_UNIX_CPU_MODEL_GUID \
+ { \
+ 0xf2d3b330, 0x8985, 0x11db, {0x8a, 0xa3, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+extern EFI_GUID gEfiUnixCPUModelGuid;
+
+//
+// EFI_UNIX_CPU_SPEED
+//
+#define EFI_UNIX_CPU_SPEED_GUID \
+ { \
+ 0xf2d74e5a, 0x8985, 0x11db, {0x97, 0x05, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
+ }
+
+extern EFI_GUID gEfiUnixCPUSpeedGuid;
+
+#endif
diff --git a/UnixPkg/Include/Protocol/UnixThunk.h b/UnixPkg/Include/Protocol/UnixThunk.h
new file mode 100644
index 0000000000..a0908a0c45
--- /dev/null
+++ b/UnixPkg/Include/Protocol/UnixThunk.h
@@ -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
index 0000000000..63e80bea32
--- /dev/null
+++ b/UnixPkg/Include/Protocol/UnixUgaIo.h
@@ -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
index 0000000000..29a0c16e0f
--- /dev/null
+++ b/UnixPkg/Include/UnixDxe.h
@@ -0,0 +1,36 @@
+/*++
+
+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:
+ UnixDxe.h
+
+Abstract:
+ Public include file for the Unix Library
+
+--*/
+
+#ifndef __UNIX_DXE_H__
+#define __UNIX_DXE_H__
+
+#include <Ppi/UnixPeiLoadFile.h>
+#include <Ppi/UnixAutoScan.h>
+#include <Ppi/UnixThunk.h>
+#include <Ppi/UnixFwh.h>
+
+//
+// UnixIo.h depends on UnixThunk.h
+//
+
+#include <Common/UnixInclude.h>
+#include <Protocol/UnixThunk.h>
+#include <Protocol/UnixIo.h>
+
+#endif
diff --git a/UnixPkg/Include/UnixPeim.h b/UnixPkg/Include/UnixPeim.h
new file mode 100644
index 0000000000..4ddda91cbd
--- /dev/null
+++ b/UnixPkg/Include/UnixPeim.h
@@ -0,0 +1,30 @@
+/*++
+
+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:
+ UnixPeim.h
+
+Abstract:
+ Public include file for the Unix Library
+
+--*/
+
+#ifndef __UNIX_PEIM_H__
+#define __UNIX_PEIM_H__
+
+#include <Ppi/UnixPeiLoadFile.h>
+#include <Ppi/UnixAutoScan.h>
+#include <Ppi/UnixThunk.h>
+#include <Ppi/UnixFwh.h>
+
+#include <Protocol/UnixThunk.h>
+
+#endif
diff --git a/UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf b/UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf
new file mode 100644
index 0000000000..01c9f1a722
--- /dev/null
+++ b/UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf
@@ -0,0 +1,50 @@
+#/** @file
+# A library to produce the global variable 'gUnix'
+#
+# This library contains a single global variable 'gUnix' along with a constructor to initialize that global.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DxeUnixLib
+ FILE_GUID = f39efc84-8985-11db-ad67-0040d02b1835
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = UnixLib
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ CONSTRUCTOR = UnixLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ UnixLib.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ HobLib
+ DebugLib
+
+
+[Protocols]
+ gEfiUnixThunkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+
diff --git a/UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa b/UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa
new file mode 100644
index 0000000000..d77a86eb95
--- /dev/null
+++ b/UnixPkg/Library/DxeUnixLib/DxeUnixLib.msa
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>DxeUnixLib</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>f39efc84-8985-11db-ad67-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>A library to produce the global variable 'gUnix'</Abstract>
+ <Description>This library contains a single global variable 'gUnix' along with a constructor to initialize that global.</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>DxeUnixLib</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_PRODUCED">
+ <Keyword>UnixLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>HobLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixLib.c</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_CONSUMED">
+ <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <Constructor>UnixLibConstructor</Constructor>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Library/DxeUnixLib/UnixLib.c b/UnixPkg/Library/DxeUnixLib/UnixLib.c
new file mode 100644
index 0000000000..98bf0442ce
--- /dev/null
+++ b/UnixPkg/Library/DxeUnixLib/UnixLib.c
@@ -0,0 +1,51 @@
+/*++
+
+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:
+
+ UnixLib.c
+
+Abstract:
+
+ Unix Library
+
+--*/
+#include "PiDxe.h"
+#include "UnixDxe.h"
+#include <Library/UnixLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+
+EFI_UNIX_THUNK_PROTOCOL *gUnix;
+
+EFI_STATUS
+UnixLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+--*/
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);
+ ASSERT (GuidHob != NULL);
+ gUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
+ ASSERT (gUnix != NULL);
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf b/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf
new file mode 100644
index 0000000000..b9aee9e135
--- /dev/null
+++ b/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf
@@ -0,0 +1,61 @@
+#/** @file
+# Memory Status Code Library for UEFI drivers
+#
+# Lib to provide memory journal status code reporting Routines
+# Copyright (c) 2007, Intel Corporation.
+#
+# All rights reserved.
+# This software and associated documentation (if any) is furnished
+# under a license and may only be used or copied in accordance
+# with the terms of the license. Except as permitted by such
+# license, no part of this software or documentation may be
+# reproduced, stored in a retrieval system, or transmitted in any
+# form or by any means without the express written consent of
+# Intel Corporation.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DxeUnixOemHookStatusCodeLib
+ FILE_GUID = 0BB6F68A-2FC5-4394-9375-2B43F1C34B59
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = OemHookStatusCodeLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32
+#
+
+[Sources.common]
+ UnixOemHookStatusCodeLib.c
+
+
+[Packages]
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
+ UnixPkg/UnixPkg.dec
+ MdePkg/MdePkg.dec
+
+
+[LibraryClasses]
+ ReportStatusCodeLib
+ BaseMemoryLib
+ PrintLib
+ HobLib
+ DebugLib
+
+
+[Guids]
+ gEfiStatusCodeSpecificDataGuid # ALWAYS_CONSUMED
+
+
+[Protocols]
+ gEfiUnixThunkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+
diff --git a/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa b/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa
new file mode 100644
index 0000000000..7e9aeebd85
--- /dev/null
+++ b/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.msa
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>DxeUnixOemHookStatusCodeLib</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>0BB6F68A-2FC5-4394-9375-2B43F1C34B59</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Memory Status Code Library for UEFI drivers</Abstract>
+ <Description>Lib to provide memory journal status code reporting Routines</Description>
+ <Copyright>Copyright (c) 2007, Intel Corporation.</Copyright>
+ <License>All rights reserved.
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.</License>
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
+ </MsaHeader>
+ <ModuleDefinitions>
+ <SupportedArchitectures>IA32</SupportedArchitectures>
+ <BinaryModule>false</BinaryModule>
+ <OutputFileBasename>DxeUnixOemHookStatusCodeLib</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">
+ <Keyword>OemHookStatusCodeLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>HobLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PrintLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>ReportStatusCodeLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixOemHookStatusCodeLib.c</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_CONSUMED">
+ <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiStatusCodeSpecificDataGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c b/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
new file mode 100644
index 0000000000..4435d16a8d
--- /dev/null
+++ b/UnixPkg/Library/DxeUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
@@ -0,0 +1,238 @@
+/** @file
+ OEM hook status code library functions with no library constructor/destructor
+
+ 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: UnixOemHookStatusCodeLib.c
+
+**/
+#include "PiDxe.h"
+#include <Guid/StatusCodeDataTypeId.h>
+#include "UnixDxe.h"
+#include <Library/OemHookStatusCodeLib.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/PrintLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/ReportStatusCodeLib.h>
+#include <FrameworkModuleBase.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
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ //
+ // Retrieve UnixThunkProtocol from GUID'ed HOB
+ //
+ GuidHob = GetFirstGuidHob (&gEfiUnixThunkProtocolGuid);
+ ASSERT (GuidHob != NULL);
+ mUnix = (EFI_UNIX_THUNK_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
+ ASSERT (mUnix != NULL);
+
+ //
+ // 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/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c b/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c
new file mode 100644
index 0000000000..48a62549be
--- /dev/null
+++ b/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.c
@@ -0,0 +1,225 @@
+/**@file
+
+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:
+
+ DxeUnixPeCoffLib.c
+
+Abstract:
+
+ Wrap the Unix PE/COFF loader with the PE COFF LOADER guid structure
+ to produce PeCoff library class.
+
+
+**/
+
+#include <PiDxe.h>
+#include <Guid/PeiPeCoffLoader.h>
+#include <Library/DebugLib.h>
+#include <Library/PeCoffLib.h>
+#include <Library/HobLib.h>
+
+EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader;
+
+/**
+ The constructor function gets the pointer to PeCofferLoader guid structure
+ from the guid data hob.
+
+ It will ASSERT() if the guid hob of PeCofferLoader guid structure doesn't exist.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+DxeUnixPeCoffLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ //
+ // Find guid data hob that contains PeCoffLoader guid structure.
+ //
+ GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);
+ ASSERT (GuidHob != NULL);
+
+ //
+ // Get PeCofferLoader guid structure from guid hob data.
+ //
+ mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Retrieves information about a PE/COFF image.
+
+ Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
+ PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
+ fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
+ If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not
+ a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while
+ computing the fields of ImageContext, then the error status is returned in the ImageError field of
+ ImageContext.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that needs to be examined by this function.
+
+ @retval RETURN_SUCCESS The information on the PE/COFF image was collected.
+ @retval RETURN_INVALID_PARAMETER ImageContext is NULL.
+ @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.
+
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderGetImageInfo (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
+
+/**
+ Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
+
+ If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
+ ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
+ of ImageContext as the relocation base address. The caller must allocate the relocation
+ fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being relocated.
+
+ @retval RETURN_SUCCESS The PE/COFF image was relocated.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_UNSUPPORTED A relocation record type is not supported.
+ Extended status information is in the ImageError field of ImageContext.
+
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderRelocateImage (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
+
+/**
+ Loads a PE/COFF image into memory.
+
+ Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
+ specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
+ the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
+ The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being loaded.
+
+ @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
+ the ImageAddress and ImageSize fields of ImageContext.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_INVALID_PARAMETER The image address is invalid.
+ Extended status information is in the ImageError field of ImageContext.
+
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderLoadImage (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
+
+/**
+ ImageRead function that operates on a memory buffer whos base is passed into
+ FileHandle.
+
+ @param FileHandle Ponter to baes of the input stream
+ @param FileOffset Offset to the start of the buffer
+ @param ReadSize Number of bytes to copy into the buffer
+ @param Buffer Location to place results of read
+
+ @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
+ the buffer.
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderImageReadFromMemory (
+ IN VOID *FileHandle,
+ IN UINTN FileOffset,
+ IN OUT UINTN *ReadSize,
+ OUT VOID *Buffer
+ )
+{
+ return RETURN_UNSUPPORTED;
+}
+
+
+/**
+ Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
+ runtime.
+
+ PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply
+ the fixups with a virtual mapping.
+
+
+ @param ImageBase Base address of relocated image
+ @param VirtImageBase Virtual mapping for ImageBase
+ @param ImageSize Size of the image to relocate
+ @param RelocationData Location to place results of read
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderRelocateImageForRuntime (
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN PHYSICAL_ADDRESS VirtImageBase,
+ IN UINTN ImageSize,
+ IN VOID *RelocationData
+ )
+{
+}
+
+/**
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.
+
+ For Unix emulator, the PE/COFF image loaded by system needs to release.
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
+ this function can simply return RETURN_SUCCESS.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image to be unloaded.
+
+ @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderUnloadImage (
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
diff --git a/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf b/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf
new file mode 100644
index 0000000000..b5fd4732cb
--- /dev/null
+++ b/UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf
@@ -0,0 +1,50 @@
+#/** @file
+# PeCoff libary for Dxe modules that run Unix emulator.
+#
+# Lib to provide memory journal status code reporting Routines
+# Copyright (c) 2007 - 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.
+
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = DxeUnixPeCoffLib
+ FILE_GUID = 624571b0-4b69-40e3-bd13-78fae0e84270
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PeCoffLib|DXE_CORE DXE_DRIVER
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ CONSTRUCTOR = DxeUnixPeCoffLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32
+#
+
+[Sources.common]
+ DxeUnixPeCoffLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ HobLib
+
+[Guids]
+ gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED
+
diff --git a/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf
new file mode 100644
index 0000000000..5128c3a429
--- /dev/null
+++ b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf
@@ -0,0 +1,50 @@
+#/** @file
+# Component description file for the EdkNt32PeiPeCoffGetEntryPointLib library.
+#
+# PeCoffGetEntryPointLib library class for NT32 instance implemented by use NTPeiLoadFile PPI.
+# Copyright (c) 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = EdkUnixPeiPeCoffGetEntryPointLib
+ FILE_GUID = f3b702e8-8985-11db-9558-0040d02b1835
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PeCoffGetEntryPointLib
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ PeCoffGetEntryPoint.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ PeiServicesLib
+ DebugLib
+
+
+[Ppis]
+ gUnixPeiLoadFilePpiGuid # PPI ALWAYS_CONSUMED
+
diff --git a/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa
new file mode 100644
index 0000000000..1c4490047a
--- /dev/null
+++ b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.msa
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>EdkUnixPeiPeCoffGetEntryPointLib</ModuleName>
+ <ModuleType>PEIM</ModuleType>
+ <GuidValue>f3b702e8-8985-11db-9558-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Component description file for the EdkNt32PeiPeCoffGetEntryPointLib library.</Abstract>
+ <Description>PeCoffGetEntryPointLib library class for NT32 instance implemented by use NTPeiLoadFile PPI.</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>EdkUnixPeiPeCoffGetEntryPointLib</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_PRODUCED">
+ <Keyword>PeCoffGetEntryPointLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PeiServicesLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>PeCoffGetEntryPoint.c</Filename>
+ </SourceFiles>
+ <PackageDependencies>
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
+ <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>
+ </PackageDependencies>
+ <PPIs>
+ <Ppi Usage="ALWAYS_CONSUMED">
+ <PpiCName>gUnixPeiLoadFilePpiGuid</PpiCName>
+ </Ppi>
+ </PPIs>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
new file mode 100644
index 0000000000..758ce9d1a7
--- /dev/null
+++ b/UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/PeCoffGetEntryPoint.c
@@ -0,0 +1,266 @@
+/*++
+
+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:
+
+ PeCoffGetEntryPoint.c
+
+Abstract:
+
+ Tiano PE/COFF loader
+
+Revision History
+
+--*/
+#include "PiPei.h"
+#include <Library/PeCoffGetEntryPointLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Ppi/UnixPeiLoadFile.h>
+#include <IndustryStandard/PeImage.h>
+#include <Library/DebugLib.h>
+
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderGetEntryPoint (
+ IN VOID *Pe32Data,
+ IN OUT VOID **EntryPoint
+ )
+/*++
+
+Routine Description:
+
+ Loads a PE/COFF image into memory, this is not follow the original purpose of
+ PeCoffGetEntryPoint library class. But it's ok that Unix package not run on a real
+ platform and this is for source level debug.
+
+Arguments:
+
+ Pe32Data - Pointer to a PE/COFF Image
+
+ EntryPoint - Pointer to the entry point of the PE/COFF image
+
+Returns:
+
+ EFI_SUCCESS if the EntryPoint was returned
+ EFI_INVALID_PARAMETER if the EntryPoint could not be found from Pe32Data
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
+ UNIX_PEI_LOAD_FILE_PPI *PeiUnixService;
+ EFI_PHYSICAL_ADDRESS ImageAddress;
+ UINT64 ImageSize;
+ EFI_PHYSICAL_ADDRESS ImageEntryPoint;
+
+ ASSERT (Pe32Data != NULL);
+ ASSERT (EntryPoint != NULL);
+
+ Status = PeiServicesLocatePpi (
+ &gUnixPeiLoadFilePpiGuid,
+ 0,
+ &PpiDescriptor,
+ (void **)&PeiUnixService
+ );
+
+ ASSERT_EFI_ERROR (Status);
+
+ Status = PeiUnixService->PeiLoadFileService (
+ Pe32Data,
+ &ImageAddress,
+ &ImageSize,
+ &ImageEntryPoint
+ );
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ *EntryPoint = (VOID*)(UINTN)ImageEntryPoint;
+ return Status;
+}
+
+/**
+ Returns the machine type of PE/COFF image.
+ This is copied from MDE BasePeCoffGetEntryPointLib, the code should be sync with it.
+ The reason is Unix package needs to load the image to memory to support source
+ level debug.
+
+
+ @param Pe32Data Pointer to a PE/COFF header
+
+ @return Machine type or zero if not a valid iamge
+
+**/
+UINT16
+EFIAPI
+PeCoffLoaderGetMachineType (
+ IN VOID *Pe32Data
+ )
+{
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
+ EFI_IMAGE_DOS_HEADER *DosHdr;
+
+ ASSERT (Pe32Data != NULL);
+
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
+ if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
+
+ } else {
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)(Pe32Data);
+ }
+
+ if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
+ return Hdr.Te->Machine;
+ } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
+ return Hdr.Pe32->FileHeader.Machine;
+ }
+
+ return 0x0000;
+}
+
+/**
+ Returns a pointer to the PDB file name for a PE/COFF image that has been
+ loaded into system memory with the PE/COFF Loader Library functions.
+
+ Returns the PDB file name for the PE/COFF image specified by Pe32Data. If
+ the PE/COFF image specified by Pe32Data is not a valid, then NULL is
+ returned. If the PE/COFF image specified by Pe32Data does not contain a
+ debug directory entry, then NULL is returned. If the debug directory entry
+ in the PE/COFF image specified by Pe32Data does not contain a PDB file name,
+ then NULL is returned.
+ If Pe32Data is NULL, then ASSERT().
+
+ @param Pe32Data Pointer to the PE/COFF image that is loaded in system
+ memory.
+
+ @return The PDB file name for the PE/COFF image specified by Pe32Data or NULL
+ if it cannot be retrieved.
+
+**/
+VOID *
+EFIAPI
+PeCoffLoaderGetPdbPointer (
+ IN VOID *Pe32Data
+ )
+{
+ EFI_IMAGE_DOS_HEADER *DosHdr;
+ EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr;
+ EFI_IMAGE_DATA_DIRECTORY *DirectoryEntry;
+ EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *DebugEntry;
+ UINTN DirCount;
+ VOID *CodeViewEntryPointer;
+ INTN TEImageAdjust;
+ UINT32 NumberOfRvaAndSizes;
+ UINT16 Magic;
+
+ ASSERT (Pe32Data != NULL);
+
+ TEImageAdjust = 0;
+ DirectoryEntry = NULL;
+ DebugEntry = NULL;
+ NumberOfRvaAndSizes = 0;
+
+ DosHdr = (EFI_IMAGE_DOS_HEADER *)Pe32Data;
+ if (DosHdr->e_magic == EFI_IMAGE_DOS_SIGNATURE) {
+ //
+ // DOS image header is present, so read the PE header after the DOS image header.
+ //
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)((UINTN) Pe32Data + (UINTN) ((DosHdr->e_lfanew) & 0x0ffff));
+ } else {
+ //
+ // DOS image header is not present, so PE header is at the image base.
+ //
+ Hdr.Pe32 = (EFI_IMAGE_NT_HEADERS32 *)Pe32Data;
+ }
+
+ if (Hdr.Te->Signature == EFI_TE_IMAGE_HEADER_SIGNATURE) {
+ if (Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress != 0) {
+ DirectoryEntry = &Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG];
+ TEImageAdjust = sizeof (EFI_TE_IMAGE_HEADER) - Hdr.Te->StrippedSize;
+ DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *)((UINTN) Hdr.Te +
+ Hdr.Te->DataDirectory[EFI_TE_IMAGE_DIRECTORY_ENTRY_DEBUG].VirtualAddress +
+ TEImageAdjust);
+ }
+ } else if (Hdr.Pe32->Signature == EFI_IMAGE_NT_SIGNATURE) {
+ //
+ // NOTE: We use Machine field to identify PE32/PE32+, instead of Magic.
+ // It is due to backward-compatibility, for some system might
+ // generate PE32+ image with PE32 Magic.
+ //
+ switch (Hdr.Pe32->FileHeader.Machine) {
+ case EFI_IMAGE_MACHINE_IA32:
+ //
+ // Assume PE32 image with IA32 Machine field.
+ //
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC;
+ break;
+ case EFI_IMAGE_MACHINE_X64:
+ case EFI_IMAGE_MACHINE_IPF:
+ //
+ // Assume PE32+ image with X64 or IPF Machine field
+ //
+ Magic = EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC;
+ break;
+ default:
+ //
+ // For unknow Machine field, use Magic in optional Header
+ //
+ Magic = Hdr.Pe32->OptionalHeader.Magic;
+ }
+
+ if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC) {
+ //
+ // Use PE32 offset get Debug Directory Entry
+ //
+ NumberOfRvaAndSizes = Hdr.Pe32->OptionalHeader.NumberOfRvaAndSizes;
+ DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
+ DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
+ } else if (Magic == EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {
+ //
+ // Use PE32+ offset get Debug Directory Entry
+ //
+ NumberOfRvaAndSizes = Hdr.Pe32Plus->OptionalHeader.NumberOfRvaAndSizes;
+ DirectoryEntry = (EFI_IMAGE_DATA_DIRECTORY *)&(Hdr.Pe32Plus->OptionalHeader.DataDirectory[EFI_IMAGE_DIRECTORY_ENTRY_DEBUG]);
+ DebugEntry = (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY *) ((UINTN) Pe32Data + DirectoryEntry->VirtualAddress);
+ }
+
+ if (NumberOfRvaAndSizes <= EFI_IMAGE_DIRECTORY_ENTRY_DEBUG) {
+ DirectoryEntry = NULL;
+ DebugEntry = NULL;
+ }
+ } else {
+ return NULL;
+ }
+
+ if (DebugEntry == NULL || DirectoryEntry == NULL) {
+ return NULL;
+ }
+
+ for (DirCount = 0; DirCount < DirectoryEntry->Size; DirCount += sizeof (EFI_IMAGE_DEBUG_DIRECTORY_ENTRY), DebugEntry++) {
+ if (DebugEntry->Type == EFI_IMAGE_DEBUG_TYPE_CODEVIEW) {
+ if (DebugEntry->SizeOfData > 0) {
+ CodeViewEntryPointer = (VOID *) ((UINTN) DebugEntry->RVA + ((UINTN)Pe32Data) + (UINTN)TEImageAdjust);
+ switch (* (UINT32 *) CodeViewEntryPointer) {
+ case CODEVIEW_SIGNATURE_NB10:
+ return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_NB10_ENTRY));
+ case CODEVIEW_SIGNATURE_RSDS:
+ return (VOID *) ((CHAR8 *)CodeViewEntryPointer + sizeof (EFI_IMAGE_DEBUG_CODEVIEW_RSDS_ENTRY));
+ default:
+ break;
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
diff --git a/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c b/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c
new file mode 100644
index 0000000000..2c2441779c
--- /dev/null
+++ b/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.c
@@ -0,0 +1,262 @@
+/**@file
+
+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:
+
+ PeiCoreUnixPeCoffLib.c
+
+Abstract:
+
+ Wrap the Unix PE/COFF loader with the PE COFF LOADER guid structure
+ to produce PeCoff library class.
+
+
+**/
+
+#include <PiPei.h>
+#include <Guid/PeiPeCoffLoader.h>
+#include <Library/DebugLib.h>
+#include <Library/PeCoffLib.h>
+#include <Library/HobLib.h>
+#include <Library/PeiServicesLib.h>
+
+EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader = NULL;
+
+/**
+ The function caches the pointer of PeCofferLoader guid structure
+ into the guid data hob.
+
+ The funtion must be called after PeCofferLoader guid structure is installed.
+ It will ASSERT() if PeCofferLoader guid structure is not installed.
+
+ @retval EFI_SUCCESS PeCofferLoader guid structure is found.
+
+**/
+EFI_STATUS
+EFIAPI
+GetPeCoffLoaderStucture (
+ )
+{
+ EFI_STATUS Status;
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ Status = EFI_NOT_FOUND;
+
+ //
+ // Try to get guid data hob that contains PeCoffLoader guid structure.
+ //
+ GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);
+
+ if (GuidHob == NULL) {
+ //
+ // GuidHob is not ready, try to locate PeCoffLoader guid structure.
+ //
+ Status = PeiServicesLocatePpi (
+ &gEfiPeiPeCoffLoaderGuid,
+ 0,
+ NULL,
+ &mPeiEfiPeiPeCoffLoader
+ );
+
+ //
+ // PeCofferLoader guid structure must be installed before this library runs.
+ //
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Build guid data hob of PeCofferLoader guid structure for DXE module use.
+ //
+ BuildGuidDataHob (
+ &gEfiPeiPeCoffLoaderGuid,
+ (VOID *) &mPeiEfiPeiPeCoffLoader,
+ sizeof (VOID *)
+ );
+ } else {
+ //
+ // Get PeCofferLoader guid structure directly from guid hob data.
+ //
+ mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Retrieves information about a PE/COFF image.
+
+ Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
+ PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
+ fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
+ If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not
+ a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while
+ computing the fields of ImageContext, then the error status is returned in the ImageError field of
+ ImageContext.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that needs to be examined by this function.
+
+ @retval RETURN_SUCCESS The information on the PE/COFF image was collected.
+ @retval RETURN_INVALID_PARAMETER ImageContext is NULL.
+ @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.
+
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderGetImageInfo (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ if (mPeiEfiPeiPeCoffLoader == NULL) {
+ GetPeCoffLoaderStucture ();
+ }
+ return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
+
+/**
+ Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
+
+ If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
+ ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
+ of ImageContext as the relocation base address. The caller must allocate the relocation
+ fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being relocated.
+
+ @retval RETURN_SUCCESS The PE/COFF image was relocated.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_UNSUPPORTED A relocation record type is not supported.
+ Extended status information is in the ImageError field of ImageContext.
+
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderRelocateImage (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ if (mPeiEfiPeiPeCoffLoader == NULL) {
+ GetPeCoffLoaderStucture ();
+ }
+ return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
+
+/**
+ Loads a PE/COFF image into memory.
+
+ Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
+ specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
+ the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
+ The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being loaded.
+
+ @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
+ the ImageAddress and ImageSize fields of ImageContext.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_INVALID_PARAMETER The image address is invalid.
+ Extended status information is in the ImageError field of ImageContext.
+
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderLoadImage (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ if (mPeiEfiPeiPeCoffLoader == NULL) {
+ GetPeCoffLoaderStucture ();
+ }
+ return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
+
+/**
+ ImageRead function that operates on a memory buffer whos base is passed into
+ FileHandle.
+
+ @param FileHandle Ponter to baes of the input stream
+ @param FileOffset Offset to the start of the buffer
+ @param ReadSize Number of bytes to copy into the buffer
+ @param Buffer Location to place results of read
+
+ @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
+ the buffer.
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderImageReadFromMemory (
+ IN VOID *FileHandle,
+ IN UINTN FileOffset,
+ IN OUT UINTN *ReadSize,
+ OUT VOID *Buffer
+ )
+{
+ return RETURN_UNSUPPORTED;
+}
+
+
+/**
+ Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
+ runtime.
+
+ PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply
+ the fixups with a virtual mapping.
+
+
+ @param ImageBase Base address of relocated image
+ @param VirtImageBase Virtual mapping for ImageBase
+ @param ImageSize Size of the image to relocate
+ @param RelocationData Location to place results of read
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderRelocateImageForRuntime (
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN PHYSICAL_ADDRESS VirtImageBase,
+ IN UINTN ImageSize,
+ IN VOID *RelocationData
+ )
+{
+}
+
+/**
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.
+
+ For Unix emulator, the PE/COFF image loaded by system needs to release.
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
+ this function can simply return RETURN_SUCCESS.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image to be unloaded.
+
+ @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderUnloadImage (
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ if (mPeiEfiPeiPeCoffLoader == NULL) {
+ GetPeCoffLoaderStucture ();
+ }
+ return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
diff --git a/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf b/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf
new file mode 100644
index 0000000000..12b2188685
--- /dev/null
+++ b/UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf
@@ -0,0 +1,49 @@
+#/** @file
+# PeCoff libary for PeiCore modules that run Unix emulator.
+#
+# Lib to provide memory journal status code reporting Routines
+# Copyright (c) 2007 - 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.
+
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PeiCoreUnixPeCoffLib
+ FILE_GUID = ef9fd7ee-3181-4b16-adc1-8615f88b58b8
+ MODULE_TYPE = PEI_CORE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PeCoffLib|PEI_CORE
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32
+#
+
+[Sources.common]
+ PeiCoreUnixPeCoffLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ PeiServicesLib
+ DebugLib
+ HobLib
+
+[Guids]
+ gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED
+
diff --git a/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf b/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf
new file mode 100644
index 0000000000..0d4c7f6390
--- /dev/null
+++ b/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf
@@ -0,0 +1,61 @@
+#/** @file
+# Memory Status Code Library for UEFI drivers
+#
+# Lib to provide memory journal status code reporting Routines
+# Copyright (c) 2007, Intel Corporation.
+#
+# All rights reserved.
+# This software and associated documentation (if any) is furnished
+# under a license and may only be used or copied in accordance
+# with the terms of the license. Except as permitted by such
+# license, no part of this software or documentation may be
+# reproduced, stored in a retrieval system, or transmitted in any
+# form or by any means without the express written consent of
+# Intel Corporation.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PeiUnixOemHookStatusCodeLib
+ FILE_GUID = 23E378C1-B199-49ad-9F14-DAF5D3C7EC28
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = OemHookStatusCodeLib|PEIM
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32
+#
+
+[Sources.common]
+ UnixOemHookStatusCodeLib.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
+
+
+[LibraryClasses]
+ PeiServicesLib
+ ReportStatusCodeLib
+ BaseMemoryLib
+ PrintLib
+ DebugLib
+
+
+[Guids]
+ gEfiStatusCodeSpecificDataGuid # ALWAYS_CONSUMED
+
+
+[Ppis]
+ gPeiUnixThunkPpiGuid # PPI ALWAYS_CONSUMED
+
diff --git a/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa b/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa
new file mode 100644
index 0000000000..f80a105736
--- /dev/null
+++ b/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.msa
@@ -0,0 +1,68 @@
+<?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>PeiUnixOemHookStatusCodeLib</ModuleName>
+ <ModuleType>PEIM</ModuleType>
+ <GuidValue>23E378C1-B199-49ad-9F14-DAF5D3C7EC28</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Memory Status Code Library for UEFI drivers</Abstract>
+ <Description>Lib to provide memory journal status code reporting Routines</Description>
+ <Copyright>Copyright (c) 2007, Intel Corporation.</Copyright>
+ <License>All rights reserved.
+ This software and associated documentation (if any) is furnished
+ under a license and may only be used or copied in accordance
+ with the terms of the license. Except as permitted by such
+ license, no part of this software or documentation may be
+ reproduced, stored in a retrieval system, or transmitted in any
+ form or by any means without the express written consent of
+ Intel Corporation.</License>
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
+ </MsaHeader>
+ <ModuleDefinitions>
+ <SupportedArchitectures>IA32</SupportedArchitectures>
+ <BinaryModule>false</BinaryModule>
+ <OutputFileBasename>PeiUnixOemHookStatusCodeLib</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="PEIM">
+ <Keyword>OemHookStatusCodeLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PrintLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>ReportStatusCodeLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PeiServicesLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixOemHookStatusCodeLib.c</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>gPeiUnixThunkPpiGuid</PpiCName>
+ </Ppi>
+ </PPIs>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiStatusCodeSpecificDataGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c b/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
new file mode 100644
index 0000000000..8d661bcfca
--- /dev/null
+++ b/UnixPkg/Library/PeiUnixOemHookStatusCodeLib/UnixOemHookStatusCodeLib.c
@@ -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
index 0000000000..18a25515a3
--- /dev/null
+++ b/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.c
@@ -0,0 +1,255 @@
+/**@file
+
+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:
+
+ PeiUnixPeCoffLib.c
+
+Abstract:
+
+ Wrap the Unix PE/COFF loader with the PE COFF LOADER guid structure
+ to produce PeCoff library class.
+
+
+**/
+
+#include <PiPei.h>
+#include <Guid/PeiPeCoffLoader.h>
+#include <Library/DebugLib.h>
+#include <Library/PeCoffLib.h>
+#include <Library/HobLib.h>
+
+EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader;
+
+/**
+ The constructor function caches the pointer of PeCofferLoader guid structure
+ into the guid data hob.
+
+ The constructor must be called after PeCofferLoader guid structure is installed.
+ It will ASSERT() if PeCofferLoader guid structure is not installed.
+
+ @param FfsHeader Pointer to FFS header the loaded driver.
+ @param PeiServices Pointer to the PEI services.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+PeiUnixPeCoffLibConstructor (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices
+ )
+{
+ EFI_STATUS Status;
+ EFI_HOB_GUID_TYPE *GuidHob;
+
+ Status = EFI_NOT_FOUND;
+
+ //
+ // Try to get guid data hob that contains PeCoffLoader guid structure.
+ //
+ GuidHob = GetFirstGuidHob (&gEfiPeiPeCoffLoaderGuid);
+
+ if (GuidHob == NULL) {
+ //
+ // GuidHob is not ready, try to locate PeCoffLoader guid structure.
+ //
+ Status = (*PeiServices)->LocatePpi (
+ PeiServices,
+ &gEfiPeiPeCoffLoaderGuid,
+ 0,
+ NULL,
+ &mPeiEfiPeiPeCoffLoader
+ );
+
+ //
+ // PeCofferLoader guid structure must be installed before this library runs.
+ //
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Build guid data hob of PeCofferLoader guid structure for DXE module use.
+ //
+ BuildGuidDataHob (
+ &gEfiPeiPeCoffLoaderGuid,
+ (VOID *) &mPeiEfiPeiPeCoffLoader,
+ sizeof (VOID *)
+ );
+ } else {
+ //
+ // Get PeCofferLoader guid structure directly from guid hob data.
+ //
+ mPeiEfiPeiPeCoffLoader = (EFI_PEI_PE_COFF_LOADER_PROTOCOL *)(*(UINTN *)(GET_GUID_HOB_DATA (GuidHob)));
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Retrieves information about a PE/COFF image.
+
+ Computes the PeCoffHeaderOffset, ImageAddress, ImageSize, DestinationAddress, CodeView,
+ PdbPointer, RelocationsStripped, SectionAlignment, SizeOfHeaders, and DebugDirectoryEntryRva
+ fields of the ImageContext structure. If ImageContext is NULL, then return RETURN_INVALID_PARAMETER.
+ If the PE/COFF image accessed through the ImageRead service in the ImageContext structure is not
+ a supported PE/COFF image type, then return RETURN_UNSUPPORTED. If any errors occur while
+ computing the fields of ImageContext, then the error status is returned in the ImageError field of
+ ImageContext.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that needs to be examined by this function.
+
+ @retval RETURN_SUCCESS The information on the PE/COFF image was collected.
+ @retval RETURN_INVALID_PARAMETER ImageContext is NULL.
+ @retval RETURN_UNSUPPORTED The PE/COFF image is not supported.
+
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderGetImageInfo (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ return mPeiEfiPeiPeCoffLoader->GetImageInfo (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
+
+/**
+ Applies relocation fixups to a PE/COFF image that was loaded with PeCoffLoaderLoadImage().
+
+ If the DestinationAddress field of ImageContext is 0, then use the ImageAddress field of
+ ImageContext as the relocation base address. Otherwise, use the DestinationAddress field
+ of ImageContext as the relocation base address. The caller must allocate the relocation
+ fixup log buffer and fill in the FixupData field of ImageContext prior to calling this function.
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being relocated.
+
+ @retval RETURN_SUCCESS The PE/COFF image was relocated.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_LOAD_ERROR The image in not a valid PE/COFF image.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_UNSUPPORTED A relocation record type is not supported.
+ Extended status information is in the ImageError field of ImageContext.
+
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderRelocateImage (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ return mPeiEfiPeiPeCoffLoader->RelocateImage (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
+
+/**
+ Loads a PE/COFF image into memory.
+
+ Loads the PE/COFF image accessed through the ImageRead service of ImageContext into the buffer
+ specified by the ImageAddress and ImageSize fields of ImageContext. The caller must allocate
+ the load buffer and fill in the ImageAddress and ImageSize fields prior to calling this function.
+ The EntryPoint, FixupDataSize, CodeView, and PdbPointer fields of ImageContext are computed.
+ If ImageContext is NULL, then ASSERT().
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image that is being loaded.
+
+ @retval RETURN_SUCCESS The PE/COFF image was loaded into the buffer specified by
+ the ImageAddress and ImageSize fields of ImageContext.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_BUFFER_TOO_SMALL The caller did not provide a large enough buffer.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_LOAD_ERROR The PE/COFF image is an EFI Runtime image with no relocations.
+ Extended status information is in the ImageError field of ImageContext.
+ @retval RETURN_INVALID_PARAMETER The image address is invalid.
+ Extended status information is in the ImageError field of ImageContext.
+
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderLoadImage (
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ return mPeiEfiPeiPeCoffLoader->LoadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
+
+/**
+ ImageRead function that operates on a memory buffer whos base is passed into
+ FileHandle.
+
+ @param FileHandle Ponter to baes of the input stream
+ @param FileOffset Offset to the start of the buffer
+ @param ReadSize Number of bytes to copy into the buffer
+ @param Buffer Location to place results of read
+
+ @retval RETURN_SUCCESS Data is read from FileOffset from the Handle into
+ the buffer.
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderImageReadFromMemory (
+ IN VOID *FileHandle,
+ IN UINTN FileOffset,
+ IN OUT UINTN *ReadSize,
+ OUT VOID *Buffer
+ )
+{
+ return RETURN_UNSUPPORTED;
+}
+
+
+/**
+ Reapply fixups on a fixed up PE32/PE32+ image to allow virutal calling at EFI
+ runtime.
+
+ PE_COFF_LOADER_IMAGE_CONTEXT.FixupData stores information needed to reapply
+ the fixups with a virtual mapping.
+
+
+ @param ImageBase Base address of relocated image
+ @param VirtImageBase Virtual mapping for ImageBase
+ @param ImageSize Size of the image to relocate
+ @param RelocationData Location to place results of read
+
+**/
+VOID
+EFIAPI
+PeCoffLoaderRelocateImageForRuntime (
+ IN PHYSICAL_ADDRESS ImageBase,
+ IN PHYSICAL_ADDRESS VirtImageBase,
+ IN UINTN ImageSize,
+ IN VOID *RelocationData
+ )
+{
+}
+
+/**
+ Unloads a loaded PE/COFF image from memory and releases its taken resource.
+
+ For Unix emulator, the PE/COFF image loaded by system needs to release.
+ For real platform, the PE/COFF image loaded by Core doesn't needs to be unloaded,
+ this function can simply return RETURN_SUCCESS.
+
+ @param ImageContext Pointer to the image context structure that describes the PE/COFF
+ image to be unloaded.
+
+ @retval RETURN_SUCCESS The PE/COFF image was unloaded successfully.
+**/
+RETURN_STATUS
+EFIAPI
+PeCoffLoaderUnloadImage (
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ )
+{
+ return mPeiEfiPeiPeCoffLoader->UnloadImage (mPeiEfiPeiPeCoffLoader, ImageContext);
+}
diff --git a/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf b/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf
new file mode 100644
index 0000000000..7be9c26192
--- /dev/null
+++ b/UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf
@@ -0,0 +1,50 @@
+#/** @file
+# PeCoff libary for PEIM modules that run Unix emulator.
+#
+# Lib to provide memory journal status code reporting Routines
+# Copyright (c) 2007 - 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.
+
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PeiUnixPeCoffLib
+ FILE_GUID = 91404129-c58a-40bb-8a2b-f05bc05a961c
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PeCoffLib|PEIM
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ CONSTRUCTOR = PeiUnixPeCoffLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32
+#
+
+[Sources.common]
+ PeiUnixPeCoffLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ HobLib
+
+[Guids]
+ gEfiPeiPeCoffLoaderGuid # ALWAYS_CONSUMED
+
diff --git a/UnixPkg/Library/UnixBdsLib/BdsPlatform.c b/UnixPkg/Library/UnixBdsLib/BdsPlatform.c
new file mode 100644
index 0000000000..7e02767035
--- /dev/null
+++ b/UnixPkg/Library/UnixBdsLib/BdsPlatform.c
@@ -0,0 +1,514 @@
+/*++
+
+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:
+
+ BdsPlatform.c
+
+Abstract:
+
+ This file include all platform action which can be customized
+ by IBV/OEM.
+
+--*/
+
+#include "BdsPlatform.h"
+
+CHAR16 mFirmwareVendor[] = L"TianoCore.org";
+
+//
+// BDS Platform Functions
+//
+VOID
+PlatformBdsInit (
+ IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData
+ )
+/*++
+
+Routine Description:
+
+ Platform Bds init. Incude the platform firmware vendor, revision
+ and so crc check.
+
+Arguments:
+
+ PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance
+
+Returns:
+
+ None.
+
+--*/
+{
+ //
+ // set firmwarevendor, here can be IBV/OEM customize
+ //
+ gST->FirmwareVendor = AllocateRuntimeCopyPool (
+ sizeof (mFirmwareVendor),
+ &mFirmwareVendor
+ );
+ ASSERT (gST->FirmwareVendor != NULL);
+
+ gST->FirmwareRevision = 0;
+
+ //
+ // Fixup Tasble CRC after we updated Firmware Vendor and Revision
+ //
+ gBS->CalculateCrc32 ((VOID *) gST, sizeof (EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);
+
+}
+
+EFI_STATUS
+PlatformBdsConnectConsole (
+ IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
+ )
+/*++
+
+Routine Description:
+
+ Connect the predefined platform default console device. Always try to find
+ and enable the vga device if have.
+
+Arguments:
+
+ PlatformConsole - Predfined platform default console device array.
+
+Returns:
+
+ EFI_SUCCESS - Success connect at least one ConIn and ConOut
+ device, there must have one ConOut device is
+ active vga device.
+
+ EFI_STATUS - Return the status of
+ BdsLibConnectAllDefaultConsoles ()
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN Index;
+
+ Index = 0;
+ Status = EFI_SUCCESS;
+
+ //
+ // Have chance to connect the platform default console,
+ // the platform default console is the minimue device group
+ // the platform should support
+ //
+ while (PlatformConsole[Index].DevicePath != NULL) {
+ //
+ // Update the console variable with the connect type
+ //
+ if ((PlatformConsole[Index].ConnectType & CONSOLE_IN) == CONSOLE_IN) {
+ BdsLibUpdateConsoleVariable (L"ConIn", PlatformConsole[Index].DevicePath, NULL);
+ }
+
+ if ((PlatformConsole[Index].ConnectType & CONSOLE_OUT) == CONSOLE_OUT) {
+ BdsLibUpdateConsoleVariable (L"ConOut", PlatformConsole[Index].DevicePath, NULL);
+ }
+
+ if ((PlatformConsole[Index].ConnectType & STD_ERROR) == STD_ERROR) {
+ BdsLibUpdateConsoleVariable (L"ErrOut", PlatformConsole[Index].DevicePath, NULL);
+ }
+
+ Index++;
+ }
+ //
+ // Connect the all the default console with current cosole variable
+ //
+ Status = BdsLibConnectAllDefaultConsoles ();
+ return Status;
+}
+
+VOID
+PlatformBdsConnectSequence (
+ VOID
+ )
+/*++
+
+Routine Description:
+
+ Connect with predeined platform connect sequence,
+ the OEM/IBV can customize with their own connect sequence.
+
+Arguments:
+
+ None.
+
+Returns:
+
+ None.
+
+--*/
+{
+ UINTN Index;
+
+ Index = 0;
+
+ //
+ // Here we can get the customized platform connect sequence
+ // Notes: we can connect with new variable which record the
+ // last time boots connect device path sequence
+ //
+ while (gPlatformConnectSequence[Index] != NULL) {
+ //
+ // Build the platform boot option
+ //
+ BdsLibConnectDevicePath (gPlatformConnectSequence[Index]);
+ Index++;
+ }
+
+ //
+ // Just use the simple policy to connect all devices
+ //
+ BdsLibConnectAll ();
+}
+
+VOID
+PlatformBdsGetDriverOption (
+ IN OUT LIST_ENTRY *BdsDriverLists
+ )
+/*++
+
+Routine Description:
+
+ Load the predefined driver option, OEM/IBV can customize this
+ to load their own drivers
+
+Arguments:
+
+ BdsDriverLists - The header of the driver option link list.
+
+Returns:
+
+ None.
+
+--*/
+{
+ UINTN Index;
+
+ Index = 0;
+
+ //
+ // Here we can get the customized platform driver option
+ //
+ while (gPlatformDriverOption[Index] != NULL) {
+ //
+ // Build the platform boot option
+ //
+ BdsLibRegisterNewOption (BdsDriverLists, gPlatformDriverOption[Index], NULL, L"DriverOrder");
+ Index++;
+ }
+
+}
+
+VOID
+PlatformBdsDiagnostics (
+ IN EXTENDMEM_COVERAGE_LEVEL MemoryTestLevel,
+ IN BOOLEAN QuietBoot
+ )
+/*++
+
+Routine Description:
+
+ Perform the platform diagnostic, such like test memory. OEM/IBV also
+ can customize this fuction to support specific platform diagnostic.
+
+Arguments:
+
+ MemoryTestLevel - The memory test intensive level
+
+ QuietBoot - Indicate if need to enable the quiet boot
+
+Returns:
+
+ None.
+
+--*/
+{
+ EFI_STATUS Status;
+
+ //
+ // Here we can decide if we need to show
+ // the diagnostics screen
+ // Notes: this quiet boot code should be remove
+ // from the graphic lib
+ //
+ if (QuietBoot) {
+ EnableQuietBootEx (&gEfiDefaultBmpLogoGuid, mBdsImageHandle);
+ //
+ // Perform system diagnostic
+ //
+ Status = BdsMemoryTest (MemoryTestLevel);
+ if (EFI_ERROR (Status)) {
+ DisableQuietBoot ();
+ }
+
+ return ;
+ }
+ //
+ // Perform system diagnostic
+ //
+ Status = BdsMemoryTest (MemoryTestLevel);
+}
+
+VOID
+PlatformBdsPolicyBehavior (
+ IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData,
+ IN OUT LIST_ENTRY *DriverOptionList,
+ IN OUT LIST_ENTRY *BootOptionList
+ )
+/*++
+
+Routine Description:
+
+ The function will excute with as the platform policy, current policy
+ is driven by boot mode. IBV/OEM can customize this code for their specific
+ policy action.
+
+Arguments:
+
+ PrivateData - The EFI_BDS_ARCH_PROTOCOL_INSTANCE instance
+
+ DriverOptionList - The header of the driver option link list
+
+ BootOptionList - The header of the boot option link list
+
+Returns:
+
+ None.
+
+--*/
+{
+ EFI_STATUS Status;
+ UINT16 Timeout;
+
+ //
+ // Init the time out value
+ //
+ Timeout = BdsLibGetTimeout ();
+
+ //
+ // Load the driver option as the driver option list
+ //
+ PlatformBdsGetDriverOption (DriverOptionList);
+
+ //
+ // Get current Boot Mode
+ //
+ Status = BdsLibGetBootMode (&PrivateData->BootMode);
+
+ //
+ // Go the different platform policy with different boot mode
+ // Notes: this part code can be change with the table policy
+ //
+ switch (PrivateData->BootMode) {
+
+ case BOOT_ASSUMING_NO_CONFIGURATION_CHANGES:
+ case BOOT_WITH_MINIMAL_CONFIGURATION:
+ //
+ // In no-configuration boot mode, we can connect the
+ // console directly.
+ //
+ BdsLibConnectAllDefaultConsoles ();
+ PlatformBdsDiagnostics (IGNORE, TRUE);
+
+ //
+ // Perform some platform specific connect sequence
+ //
+ PlatformBdsConnectSequence ();
+
+ //
+ // Notes: current time out = 0 can not enter the
+ // front page
+ //
+ PlatformBdsEnterFrontPage (Timeout, FALSE);
+
+ //
+ // Check the boot option with the boot option list
+ //
+ BdsLibBuildOptionFromVar (BootOptionList, L"BootOrder");
+ break;
+
+ case BOOT_ON_FLASH_UPDATE:
+ //
+ // Boot with the specific configuration
+ //
+ PlatformBdsConnectConsole (gPlatformConsole);
+ PlatformBdsDiagnostics (EXTENSIVE, FALSE);
+ BdsLibConnectAll ();
+ ProcessCapsules (BOOT_ON_FLASH_UPDATE);
+ break;
+
+ case BOOT_IN_RECOVERY_MODE:
+ //
+ // In recovery mode, just connect platform console
+ // and show up the front page
+ //
+ PlatformBdsConnectConsole (gPlatformConsole);
+ PlatformBdsDiagnostics (EXTENSIVE, FALSE);
+
+ //
+ // In recovery boot mode, we still enter to the
+ // frong page now
+ //
+ PlatformBdsEnterFrontPage (Timeout, FALSE);
+ break;
+
+ case BOOT_WITH_FULL_CONFIGURATION:
+ case BOOT_WITH_FULL_CONFIGURATION_PLUS_DIAGNOSTICS:
+ case BOOT_WITH_DEFAULT_SETTINGS:
+ default:
+ //
+ // Connect platform console
+ //
+ Status = PlatformBdsConnectConsole (gPlatformConsole);
+ if (EFI_ERROR (Status)) {
+ //
+ // Here OEM/IBV can customize with defined action
+ //
+ PlatformBdsNoConsoleAction ();
+ }
+
+ PlatformBdsDiagnostics (IGNORE, TRUE);
+
+ //
+ // Perform some platform specific connect sequence
+ //
+ PlatformBdsConnectSequence ();
+
+ //
+ // Give one chance to enter the setup if we
+ // have the time out
+ //
+ PlatformBdsEnterFrontPage (Timeout, FALSE);
+
+ //
+ // Here we have enough time to do the enumeration of boot device
+ //
+ BdsLibEnumerateAllBootOption (BootOptionList);
+ break;
+ }
+
+ return ;
+
+}
+
+VOID
+PlatformBdsBootSuccess (
+ IN BDS_COMMON_OPTION *Option
+ )
+/*++
+
+Routine Description:
+
+ Hook point after a boot attempt succeeds. We don't expect a boot option to
+ return, so the EFI 1.0 specification defines that you will default to an
+ interactive mode and stop processing the BootOrder list in this case. This
+ is alos a platform implementation and can be customized by IBV/OEM.
+
+Arguments:
+
+ Option - Pointer to Boot Option that succeeded to boot.
+
+Returns:
+
+ None.
+
+--*/
+{
+ CHAR16 *TmpStr;
+
+ //
+ // If Boot returned with EFI_SUCCESS and there is not in the boot device
+ // select loop then we need to pop up a UI and wait for user input.
+ //
+ TmpStr = Option->StatusString;
+ if (TmpStr != NULL) {
+ BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
+ FreePool (TmpStr);
+ }
+}
+
+VOID
+PlatformBdsBootFail (
+ IN BDS_COMMON_OPTION *Option,
+ IN EFI_STATUS Status,
+ IN CHAR16 *ExitData,
+ IN UINTN ExitDataSize
+ )
+/*++
+
+Routine Description:
+
+ Hook point after a boot attempt fails.
+
+Arguments:
+
+ Option - Pointer to Boot Option that failed to boot.
+
+ Status - Status returned from failed boot.
+
+ ExitData - Exit data returned from failed boot.
+
+ ExitDataSize - Exit data size returned from failed boot.
+
+Returns:
+
+ None.
+
+--*/
+{
+ CHAR16 *TmpStr;
+
+ //
+ // If Boot returned with failed status then we need to pop up a UI and wait
+ // for user input.
+ //
+ TmpStr = Option->StatusString;
+ if (TmpStr != NULL) {
+ BdsLibOutputStrings (gST->ConOut, TmpStr, Option->Description, L"\n\r", NULL);
+ FreePool (TmpStr);
+ }
+}
+
+EFI_STATUS
+PlatformBdsNoConsoleAction (
+ VOID
+ )
+/*++
+
+Routine Description:
+
+ This function is remained for IBV/OEM to do some platform action,
+ if there no console device can be connected.
+
+Arguments:
+
+ None.
+
+Returns:
+
+ EFI_SUCCESS - Direct return success now.
+
+--*/
+{
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+PlatformBdsLockNonUpdatableFlash (
+ VOID
+ )
+{
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/Library/UnixBdsLib/BdsPlatform.h b/UnixPkg/Library/UnixBdsLib/BdsPlatform.h
new file mode 100644
index 0000000000..32587b6a26
--- /dev/null
+++ b/UnixPkg/Library/UnixBdsLib/BdsPlatform.h
@@ -0,0 +1,165 @@
+/*++
+
+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:
+
+ BdsPlatform.h
+
+Abstract:
+
+ Head file for BDS Platform specific code
+
+--*/
+
+#ifndef _BDS_PLATFORM_H
+#define _BDS_PLATFORM_H
+
+#include <PiDxe.h>
+
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/BaseLib.h>
+#include <Library/PcdLib.h>
+#include <Library/GenericBdsLib.h>
+#include <Library/PlatformBdsLib.h>
+#include <Library/GraphicsLib.h>
+
+#include <Protocol/UnixThunk.h>
+#include <Protocol/UnixIo.h>
+#include <Guid/Bmp.h>
+
+extern BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[];
+extern EFI_DEVICE_PATH_PROTOCOL *gPlatformConnectSequence[];
+extern EFI_DEVICE_PATH_PROTOCOL *gPlatformDriverOption[];
+
+#define gEndEntire \
+ { \
+ END_DEVICE_PATH_TYPE,\
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,\
+ END_DEVICE_PATH_LENGTH,\
+ 0\
+ }
+
+typedef struct {
+ VENDOR_DEVICE_PATH VendorDevicePath;
+ UINT32 Instance;
+} UNIX_VENDOR_DEVICE_PATH_NODE;
+
+//
+// Below is the platform console device path
+//
+typedef struct {
+ VENDOR_DEVICE_PATH UnixBus;
+ UNIX_VENDOR_DEVICE_PATH_NODE SerialDevice;
+ UART_DEVICE_PATH Uart;
+ VENDOR_DEVICE_PATH TerminalType;
+ EFI_DEVICE_PATH_PROTOCOL End;
+} UNIX_ISA_SERIAL_DEVICE_PATH;
+
+typedef struct {
+ VENDOR_DEVICE_PATH UnixBus;
+ UNIX_VENDOR_DEVICE_PATH_NODE UnixUgaDevice;
+ EFI_DEVICE_PATH_PROTOCOL End;
+} UNIX_PLATFORM_UGA_DEVICE_PATH;
+
+typedef struct {
+ VENDOR_DEVICE_PATH UnixBus;
+ UNIX_VENDOR_DEVICE_PATH_NODE ConsoleDevice;
+ EFI_DEVICE_PATH_PROTOCOL End;
+} UNIX_CONSOLE_DEVICE_PATH;
+//
+// Platform BDS Functions
+//
+VOID
+PlatformBdsInit (
+ IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData
+ )
+;
+
+VOID
+PlatformBdsPolicyBehavior (
+ IN EFI_BDS_ARCH_PROTOCOL_INSTANCE *PrivateData,
+ IN LIST_ENTRY *DriverOptionList,
+ IN LIST_ENTRY *BootOptionList
+ )
+;
+
+VOID
+PlatformBdsGetDriverOption (
+ IN LIST_ENTRY *BdsDriverLists
+ )
+;
+
+EFI_STATUS
+BdsMemoryTest (
+ EXTENDMEM_COVERAGE_LEVEL Level
+ )
+;
+
+EFI_STATUS
+PlatformBdsShowProgress (
+ EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleForeground,
+ EFI_GRAPHICS_OUTPUT_BLT_PIXEL TitleBackground,
+ CHAR16 *Title,
+ EFI_GRAPHICS_OUTPUT_BLT_PIXEL ProgressColor,
+ UINTN Progress,
+ UINTN PreviousValue
+ )
+;
+
+VOID
+PlatformBdsConnectSequence (
+ VOID
+ )
+;
+
+VOID
+PlatformBdsBootFail (
+ IN BDS_COMMON_OPTION *Option,
+ IN EFI_STATUS Status,
+ IN CHAR16 *ExitData,
+ IN UINTN ExitDataSize
+ )
+;
+
+VOID
+PlatformBdsBootSuccess (
+ IN BDS_COMMON_OPTION *Option
+ )
+;
+
+EFI_STATUS
+ProcessCapsules (
+ EFI_BOOT_MODE BootMode
+ )
+;
+
+EFI_STATUS
+PlatformBdsConnectConsole (
+ IN BDS_CONSOLE_CONNECT_ENTRY *PlatformConsole
+ )
+;
+
+EFI_STATUS
+PlatformBdsNoConsoleAction (
+ VOID
+ )
+;
+
+VOID
+PlatformBdsEnterFrontPage (
+ IN UINT16 TimeoutDefault,
+ IN BOOLEAN ConnectAllHappened
+ );
+
+#endif // _BDS_PLATFORM_H
diff --git a/UnixPkg/Library/UnixBdsLib/PlatformBds.inf b/UnixPkg/Library/UnixBdsLib/PlatformBds.inf
new file mode 100644
index 0000000000..3ce8ff605b
--- /dev/null
+++ b/UnixPkg/Library/UnixBdsLib/PlatformBds.inf
@@ -0,0 +1,80 @@
+#/** @file
+# Platfrom BDS driver
+#
+# Do platform action customized by IBV/OEM.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PlatformBdsLib
+ FILE_GUID = f392b762-8985-11db-be87-0040d02b1835
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PlatformBdsLib|DXE_DRIVER
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = BdsInitialize
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ BdsPlatform.c
+ BdsPlatform.h
+ PlatformData.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+# EdkGenericPlatformBdsLib
+# HiiLib
+# DevicePathLib
+# UefiRuntimeServicesTableLib
+# UefiBootServicesTableLib
+# BaseMemoryLib
+# MemoryAllocationLib
+# EdkGenericBdsLib
+# HobLib
+# ReportStatusCodeLib
+# EdkIfrSupportLib
+# PrintLib
+# PerformanceLib
+# DxeServicesTableLib
+# EdkGraphicsLib
+# BaseLib
+# UefiDriverEntryPoint
+# UefiLib
+# DebugLib
+
+
+ BaseLib
+ MemoryAllocationLib
+ UefiBootServicesTableLib
+ BaseMemoryLib
+ DebugLib
+ PcdLib
+ GraphicsLib
+ GenericBdsLib
+
+
+[Guids]
+ 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
index 0000000000..989117590f
--- /dev/null
+++ b/UnixPkg/Library/UnixBdsLib/PlatformBds.msa
@@ -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">
+ <GuidCName>gEfiDefaultBmpLogoGuid</GuidCName>
+ </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
index 0000000000..cf1b55ce30
--- /dev/null
+++ b/UnixPkg/Library/UnixBdsLib/PlatformData.c
@@ -0,0 +1,120 @@
+/*++
+
+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:
+
+ PlatformData.c
+
+Abstract:
+
+ Defined the platform specific device path which will be used by
+ platform Bbd to perform the platform policy connect.
+
+--*/
+
+#include "BdsPlatform.h"
+
+//
+// Predefined platform default time out value
+//
+UINT16 gPlatformBootTimeOutDefault = 10;
+
+//
+// Platform specific keyboard device path
+//
+UNIX_PLATFORM_UGA_DEVICE_PATH gUgaDevicePath0 =
+{
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
+ (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8),
+ EFI_UNIX_THUNK_PROTOCOL_GUID
+ },
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ (UINT8) (sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)),
+ (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8),
+ EFI_UNIX_UGA_GUID,
+ 0
+ },
+ gEndEntire
+};
+
+UNIX_PLATFORM_UGA_DEVICE_PATH gUgaDevicePath1 = {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
+ (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8),
+ EFI_UNIX_THUNK_PROTOCOL_GUID
+ },
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ (UINT8) (sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)),
+ (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8),
+ EFI_UNIX_UGA_GUID,
+ 1
+ },
+ gEndEntire
+};
+
+UNIX_CONSOLE_DEVICE_PATH gUnixConsoleDevicePath = {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
+ (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8),
+ EFI_UNIX_THUNK_PROTOCOL_GUID
+ },
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ (UINT8) (sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)),
+ (UINT8) ((sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)) >> 8),
+ EFI_UNIX_CONSOLE_GUID,
+ 0
+ },
+ gEndEntire
+};
+//
+// Predefined platform default console device path
+//
+BDS_CONSOLE_CONNECT_ENTRY gPlatformConsole[] = {
+ {
+ (EFI_DEVICE_PATH_PROTOCOL *) &gUnixConsoleDevicePath,
+ (CONSOLE_OUT | CONSOLE_IN)
+ },
+ {
+ (EFI_DEVICE_PATH_PROTOCOL *) &gUgaDevicePath0,
+ (CONSOLE_OUT | CONSOLE_IN)
+ },
+ {
+ (EFI_DEVICE_PATH_PROTOCOL *) &gUgaDevicePath1,
+ (CONSOLE_OUT | CONSOLE_IN)
+ },
+ {
+ NULL,
+ 0
+ }
+};
+
+//
+// Predefined platform specific driver option
+//
+EFI_DEVICE_PATH_PROTOCOL *gPlatformDriverOption[] = { NULL };
+
+//
+// Predefined platform connect sequence
+//
+EFI_DEVICE_PATH_PROTOCOL *gPlatformConnectSequence[] = { NULL };
diff --git a/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoader.c b/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoader.c
new file mode 100644
index 0000000000..28ce4ef76f
--- /dev/null
+++ b/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoader.c
@@ -0,0 +1,54 @@
+/*++
+
+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:
+
+ TianoPeCoffLoader.c
+
+Abstract:
+
+ Wrap the Base PE/COFF loader with the PE COFF Protocol
+
+
+--*/
+
+#include <Guid/PeiPeCoffLoader.h>
+
+#include <Library/EdkPeCoffLoaderLib.h>
+
+EFI_PEI_PE_COFF_LOADER_PROTOCOL *mPeiEfiPeiPeCoffLoader;
+
+EFI_STATUS
+EFIAPI
+PeCoffLoaderConstructor (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices
+ )
+{
+ EFI_STATUS Status;
+
+ Status = (*PeiServices)->LocatePpi (
+ PeiServices,
+ &gEfiPeiPeCoffLoaderGuid,
+ 0,
+ NULL,
+ (VOID **)&mPeiEfiPeiPeCoffLoader
+ );
+ return Status;
+}
+
+EFI_PEI_PE_COFF_LOADER_PROTOCOL *
+EFIAPI
+GetPeCoffLoaderProtocol (
+ )
+{
+ return mPeiEfiPeiPeCoffLoader;
+}
diff --git a/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.inf b/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.inf
new file mode 100644
index 0000000000..fcb78396e5
--- /dev/null
+++ b/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.inf
@@ -0,0 +1,41 @@
+#/** @file
+# Component description file for the Nt32PeCoffLoaderLib library.
+#
+# EdkPeCoffLoaderLib library class for NT32 instance implemented by PeiPeCoffLoader PPI.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixPeCoffLoaderLib
+ FILE_GUID = f3cf597e-8985-11db-95f6-0040d02b1835
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = EdkPeCoffLoaderLib
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ CONSTRUCTOR = PeCoffLoaderConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ UnixPeCoffLoader.c
+
+
+[Guids]
+ gEfiPeiPeCoffLoaderGuid # SOMETIMES_CONSUMED
+
diff --git a/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.msa b/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.msa
new file mode 100644
index 0000000000..60f5e24109
--- /dev/null
+++ b/UnixPkg/Library/UnixPeCoffLoaderLib/UnixPeCoffLoaderLib.msa
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>UnixPeCoffLoaderLib</ModuleName>
+ <ModuleType>PEIM</ModuleType>
+ <GuidValue>f3cf597e-8985-11db-95f6-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Component description file for the Nt32PeCoffLoaderLib library.</Abstract>
+ <Description>EdkPeCoffLoaderLib library class for NT32 instance implemented by PeiPeCoffLoader PPI.</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>UnixPeCoffLoaderLib</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_PRODUCED">
+ <Keyword>EdkPeCoffLoaderLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixPeCoffLoader.c</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>
+ <Guids>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiPeiPeCoffLoaderGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <Constructor>PeCoffLoaderConstructor</Constructor>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/MetronomeDxe/Metronome.c b/UnixPkg/MetronomeDxe/Metronome.c
new file mode 100644
index 0000000000..f018e7f409
--- /dev/null
+++ b/UnixPkg/MetronomeDxe/Metronome.c
@@ -0,0 +1,140 @@
+/*++
+
+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:
+
+ Metronome.c
+
+Abstract:
+
+ UNIX Emulation Metronome Architectural Protocol Driver as defined in DXE CIS
+
+--*/
+#include "PiDxe.h"
+#include "UnixDxe.h"
+#include <Protocol/Metronome.h>
+#include "Metronome.h"
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UnixLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+//
+// Global Variables
+//
+EFI_METRONOME_ARCH_PROTOCOL mMetronome = {
+ UnixMetronomeDriverWaitForTick,
+ TICK_PERIOD
+};
+
+//
+// Worker Functions
+//
+
+EFI_STATUS
+EFIAPI
+UnixMetronomeDriverWaitForTick (
+ IN EFI_METRONOME_ARCH_PROTOCOL *This,
+ IN UINT32 TickNumber
+ )
+/*++
+
+Routine Description:
+
+ The WaitForTick() function waits for the number of ticks specified by
+ TickNumber from a known time source in the platform. If TickNumber of
+ ticks are detected, then EFI_SUCCESS is returned. The actual time passed
+ between entry of this function and the first tick is between 0 and
+ TickPeriod 100 nS units. If you want to guarantee that at least TickPeriod
+ time has elapsed, wait for two ticks. This function waits for a hardware
+ event to determine when a tick occurs. It is possible for interrupt
+ processing, or exception processing to interrupt the execution of the
+ WaitForTick() function. Depending on the hardware source for the ticks, it
+ is possible for a tick to be missed. This function cannot guarantee that
+ ticks will not be missed. If a timeout occurs waiting for the specified
+ number of ticks, then EFI_TIMEOUT is returned.
+
+Arguments:
+
+ This - The EFI_METRONOME_ARCH_PROTOCOL instance.
+ TickNumber - Number of ticks to wait.
+
+Returns:
+
+ EFI_SUCCESS - The wait for the number of ticks specified by TickNumber
+ succeeded.
+
+--*/
+{
+ UINT64 SleepTime;
+
+ //
+ // Calculate the time to sleep. Win API smallest unit to sleep is 1 millisec
+ // Tick Period is in 100ns units, divide by 10000 to convert to ms
+ //
+ SleepTime = DivU64x32 (MultU64x32 ((UINT64) TickNumber, TICK_PERIOD) + 9999, 10000);
+ gUnix->Sleep ((UINT32) SleepTime);
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+UnixMetronomeDriverInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+/*++
+
+Routine Description:
+
+ Initialize the Metronome Architectural Protocol driver
+
+Arguments:
+
+ ImageHandle - ImageHandle of the loaded driver
+
+
+ SystemTable - Pointer to the System Table
+
+Returns:
+
+ EFI_SUCCESS - Metronome Architectural Protocol created
+
+ EFI_OUT_OF_RESOURCES - Not enough resources available to initialize driver.
+
+ EFI_DEVICE_ERROR - A device error occured attempting to initialize the driver.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+
+
+ //
+ // Install the Metronome Architectural Protocol onto a new handle
+ //
+ Handle = NULL;
+ DEBUG ((EFI_D_ERROR, "*******************file %d line %d\n", __FUNCTION__, __LINE__));
+ Status = gBS->InstallProtocolInterface (
+ &Handle,
+ &gEfiMetronomeArchProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mMetronome
+ );
+
+ return Status;
+}
diff --git a/UnixPkg/MetronomeDxe/Metronome.h b/UnixPkg/MetronomeDxe/Metronome.h
new file mode 100644
index 0000000000..10e6dc9b8a
--- /dev/null
+++ b/UnixPkg/MetronomeDxe/Metronome.h
@@ -0,0 +1,84 @@
+/*++
+
+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:
+
+ Metronome.h
+
+Abstract:
+
+ UNIX Emulation Metronome Architectural Protocol Driver as defined in DXE CIS
+
+--*/
+
+#ifndef _UNIX_THUNK_METRONOME_H_
+#define _UNIX_THUNK_METRONOME_H_
+
+
+
+//
+// Period of on tick in 100 nanosecond units
+//
+#define TICK_PERIOD 2000
+
+//
+// Function Prototypes
+//
+
+EFI_STATUS
+EFIAPI
+UnixMetronomeDriverInitialize (
+ 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
+UnixMetronomeDriverWaitForTick (
+ IN EFI_METRONOME_ARCH_PROTOCOL *This,
+ IN UINT32 TickNumber
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ TickNumber - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+#endif
diff --git a/UnixPkg/MetronomeDxe/Metronome.inf b/UnixPkg/MetronomeDxe/Metronome.inf
new file mode 100644
index 0000000000..8b1c58dcaf
--- /dev/null
+++ b/UnixPkg/MetronomeDxe/Metronome.inf
@@ -0,0 +1,60 @@
+#/** @file
+# Unix Emulation Metronome Architectural Protocol Driver as defined in DXE CIS
+#
+# This metronome module simulates metronome by Sleep WinAPI.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = Metronome
+ FILE_GUID = f348f6fe-8985-11db-b4c3-0040d02b1835
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = UnixMetronomeDriverInitialize
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ Metronome.h
+ Metronome.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ UnixLib
+ UefiDriverEntryPoint
+ UefiLib
+ DebugLib
+ BaseLib
+
+
+[Protocols]
+ gEfiMetronomeArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+
+
+[Depex]
+ TRUE
+
diff --git a/UnixPkg/MetronomeDxe/Metronome.msa b/UnixPkg/MetronomeDxe/Metronome.msa
new file mode 100644
index 0000000000..a64f1ea479
--- /dev/null
+++ b/UnixPkg/MetronomeDxe/Metronome.msa
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>Metronome</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>f348f6fe-8985-11db-b4c3-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Unix Emulation Metronome Architectural Protocol Driver as defined in DXE CIS</Abstract>
+ <Description>
+ This metronome module simulates metronome by Sleep WinAPI.
+ </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>Metronome</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <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>UnixLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>Metronome.c</Filename>
+ <Filename>Metronome.h</Filename>
+ <Filename>Metronome.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>gEfiMetronomeArchProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>UnixMetronomeDriverInitialize</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni
new file mode 100644
index 0000000000..14a68936ef
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturer.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c
new file mode 100644
index 0000000000..14c7ef0d4d
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscBaseBoardManufacturerData.c
@@ -0,0 +1,57 @@
+/*++
+
+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:
+
+ MiscBaseBoardManufacturerData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_BASE_BOARD_MANUFACTURER_DATA, MiscBaseBoardManufacturer) = {
+ STRING_TOKEN(STR_MISC_BASE_BOARD_MANUFACTURER),
+ STRING_TOKEN(STR_MISC_BASE_BOARD_PRODUCT_NAME),
+ STRING_TOKEN(STR_MISC_BASE_BOARD_VERSION),
+ STRING_TOKEN(STR_MISC_BASE_BOARD_SERIAL_NUMBER),
+ STRING_TOKEN(STR_MISC_BASE_BOARD_ASSET_TAG),
+ STRING_TOKEN(STR_MISC_BASE_BOARD_CHASSIS_LOCATION),
+ { // BaseBoardFeatureFlags
+ 1, // Motherboard
+ 0, // RequiresDaughterCard
+ 0, // Removable
+ 1, // Replaceable,
+ 0, // HotSwappable
+ 0, // Reserved
+ },
+ EfiBaseBoardTypeUnknown, // BaseBoardType
+ { // BaseBoardChassisLink
+ EFI_MISC_SUBCLASS_GUID, // ProducerName
+ 1, // Instance
+ 1, // SubInstance
+ },
+ 0, // BaseBoardNumberLinks
+ { // LinkN
+ EFI_MISC_SUBCLASS_GUID, // ProducerName
+ 1, // Instance
+ 1, // SubInstance
+ },
+};
+
+/* eof - MiscBaseBoardManufacturerData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni
new file mode 100644
index 0000000000..b1e7e520fc
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendor.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c
new file mode 100644
index 0000000000..61d60e2b1c
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscBiosVendorData.c
@@ -0,0 +1,88 @@
+/*++
+
+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:
+
+ MiscBiosVendorData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_BIOS_VENDOR_DATA, MiscBiosVendor) = {
+ STRING_TOKEN(STR_MISC_BIOS_VENDOR), // BiosVendor
+ STRING_TOKEN(STR_MISC_BIOS_VERSION), // BiosVersion
+ STRING_TOKEN(STR_MISC_BIOS_RELEASE_DATE), // BiosReleaseDate
+ 0xBABE, // BiosStartingAddress
+ { // BiosPhysicalDeviceSize
+ 2, // Value
+ 3, // Exponent
+ },
+ { // BiosCharacteristics1
+ 0, // Reserved1 :2
+ 0, // Unknown :1
+ 1, // BiosCharacteristicsNotSupported :1
+ 0, // IsaIsSupported :1
+ 0, // McaIsSupported :1
+ 0, // EisaIsSupported :1
+ 0, // PciIsSupported :1
+ 0, // PcmciaIsSupported :1
+ 0, // PlugAndPlayIsSupported :1
+ 0, // ApmIsSupported :1
+ 0, // BiosIsUpgradable :1
+ 0, // BiosShadowingAllowed :1
+ 0, // VlVesaIsSupported :1
+ 0, // EscdSupportIsAvailable :1
+ 0, // BootFromCdIsSupported :1
+ 0, // SelectableBootIsSupported :1
+ 0, // RomBiosIsSocketed :1
+ 0, // BootFromPcmciaIsSupported :1
+ 0, // EDDSpecificationIsSupported :1
+ 0, // JapaneseNecFloppyIsSupported :1
+ 0, // JapaneseToshibaFloppyIsSupported :1
+ 0, // Floppy525_360IsSupported :1
+ 0, // Floppy525_12IsSupported :1
+ 0, // Floppy35_720IsSupported :1
+ 0, // Floppy35_288IsSupported :1
+ 0, // PrintScreenIsSupported :1
+ 0, // Keyboard8042IsSupported :1
+ 0, // SerialIsSupported :1
+ 0, // PrinterIsSupported :1
+ 0, // CgaMonoIsSupported :1
+ 0, // NecPc98 :1
+ 0, // AcpiIsSupported :1
+ 0, // UsbLegacyIsSupported :1
+ 0, // AgpIsSupported :1
+ 0, // I20BootIsSupported :1
+ 0, // Ls120BootIsSupported :1
+ 0, // AtapiZipDriveBootIsSupported :1
+ 0, // Boot1394IsSupported :1
+ 0, // SmartBatteryIsSupported :1
+ 0, // BiosBootSpecIsSupported :1
+ 0, // FunctionKeyNetworkBootIsSupported :1
+ 0 // Reserved :22
+ },
+ { // BiosCharacteristics2
+ 0, // BiosReserved :16
+ 0, // SystemReserved :16
+ 0 // Reserved :32
+ },
+};
+
+/* eof - MiscBiosVendorData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c
new file mode 100644
index 0000000000..0a9cffa02a
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscBootInformationData.c
@@ -0,0 +1,33 @@
+/*++
+
+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:
+
+ MiscBootInformationData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_BOOT_INFORMATION_STATUS_DATA, BootInformationStatus) = {
+ EfiBootInformationStatusNoError, // BootInformationStatus
+ {0} // BootInformationData
+};
+
+/* eof - MiscBootInformationData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni
new file mode 100644
index 0000000000..67bee85037
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturer.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c
new file mode 100644
index 0000000000..6a3986fa27
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscChassisManufacturerData.c
@@ -0,0 +1,45 @@
+/*++
+
+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:
+
+ MiscChassisManufacturerData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Chassis Manufacturer data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_CHASSIS_MANUFACTURER_DATA, MiscChassisManufacturer) = {
+ STRING_TOKEN(STR_MISC_CHASSIS_MANUFACTURER), // ChassisManufactrurer
+ STRING_TOKEN(STR_MISC_CHASSIS_VERSION), // ChassisVersion
+ STRING_TOKEN(STR_MISC_CHASSIS_SERIAL_NUMBER), // ChassisSerialNumber
+ STRING_TOKEN(STR_MISC_CHASSIS_ASSET_TAG), // ChassisAssetTag
+ { // ChassisTypeStatus
+ EfiMiscChassisTypeOther, // ChassisType
+ 0, // ChassisLockPresent
+ 0 // Reserved
+ },
+ EfiChassisStateOther, // ChassisBootupState
+ EfiChassisStateOther, // ChassisPowerSupplyState
+ EfiChassisStateOther, // ChassisThermalState
+ EfiChassisSecurityStatusOther, // ChassisSecurityState
+ 0 // ChassisOemDefined
+};
+
+/* eof - MiscChassisManufacaturerData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscDevicePath.h b/UnixPkg/MiscSubClassPlatformDxe/MiscDevicePath.h
new file mode 100644
index 0000000000..ae0e6337f6
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscDevicePath.h
@@ -0,0 +1,175 @@
+/*++
+
+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:
+
+ MiscDevicePath.h
+
+Abstract:
+
+ Misc class required EFI Device Path definitions (Ports, slots &
+ onboard devices)
+
+--*/
+
+#ifndef _MISC_DEVICE_PATH_H
+#define _MISC_DEVICE_PATH_H
+
+
+#pragma pack(1)
+//
+// USB
+//
+
+/* For reference:
+#define USB1_1_STR "ACPI(PNP0A03,0)/PCI(1D,0)."
+#define USB1_2_STR "ACPI(PNP0A03,0)/PCI(1D,1)."
+#define USB1_3_STR "ACPI(PNP0A03,0)/PCI(1D,2)."
+#define USB2_1_STR "ACPI(PNP0A03,0)/PCI(1D,7)."
+*/
+
+//
+// #define acpi { 0x02, 0x01, 0x00, 0x0C, 0x0a0341d0, 0x00000000 }
+// #define pci( device,function) { 0x01, 0x01, 0x00, 0x06, device, function }
+// #define end { 0xFF, 0xFF, 0x00, 0x04 }
+//
+#define DP_ACPI \
+ { \
+ {ACPI_DEVICE_PATH, ACPI_DP, {(UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), (UINT8) \
+ ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)}}, EISA_PNP_ID (0x0A03), 0 \
+ }
+#define DP_PCI(device, function) \
+ { \
+ {HARDWARE_DEVICE_PATH, HW_PCI_DP, {(UINT8) (sizeof (PCI_DEVICE_PATH)), (UINT8) \
+ ((sizeof (PCI_DEVICE_PATH)) >> 8)}}, function, device \
+ }
+#define DP_END \
+ { \
+ END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, {END_DEVICE_PATH_LENGTH, 0} \
+ }
+
+#define DP_LPC(eisaid, function) \
+ { \
+ {ACPI_DEVICE_PATH, ACPI_DP, {(UINT8) (sizeof (ACPI_HID_DEVICE_PATH)), (UINT8) \
+ ((sizeof (ACPI_HID_DEVICE_PATH)) >> 8)}}, EISA_PNP_ID (eisaid), function \
+ }
+
+//
+// Shanmu >> moved to TianoDevicePath.h
+//
+
+/*
+typedef struct _USB_PORT_DEVICE_PATH
+{
+ ACPI_HID_DEVICE_PATH PciRootBridgeDevicePath;
+ PCI_DEVICE_PATH PciBusDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} USB_PORT_DEVICE_PATH;
+
+
+//IDE ??I am not sure. Should this be ATAPI_DEVICE_PATH
+typedef struct _IDE_DEVICE_PATH
+{
+ ACPI_HID_DEVICE_PATH PciRootBridgeDevicePath;
+ PCI_DEVICE_PATH PciBusDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} IDE_DEVICE_PATH;
+
+//RMC Connector
+typedef struct _RMC_CONN_DEVICE_PATH
+{
+ ACPI_HID_DEVICE_PATH PciRootBridgeDevicePath;
+ PCI_DEVICE_PATH PciBridgeDevicePath;
+ PCI_DEVICE_PATH PciBusDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} RMC_CONN_DEVICE_PATH;
+
+//static RMC_CONN_DEVICE_PATH mRmcConnDevicePath = { acpi, pci( 0x1E,0x00 ),pci( 0x0A,0x00 ), end };
+
+//RIDE
+typedef struct _RIDE_DEVICE_PATH
+{
+ ACPI_HID_DEVICE_PATH PciRootBridgeDevicePath;
+ PCI_DEVICE_PATH PciBridgeDevicePath;
+ PCI_DEVICE_PATH PciBusDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} RIDE_DEVICE_PATH;
+
+//static RIDE_DEVICE_PATH mRideDevicePath = { acpi, pci( 0x1E,0x00 ),pci( 0x02,0x00 ), end };
+
+//Gigabit NIC
+//typedef struct _GB_NIC_DEVICE_PATH
+//{
+// ACPI_HID_DEVICE_PATH PciRootBridgeDevicePath;
+// PCI_DEVICE_PATH PciBridgeDevicePath;
+// PCI_DEVICE_PATH PciXBridgeDevicePath;
+// PCI_DEVICE_PATH PciXBusDevicePath;
+// EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+//} GB_NIC_DEVICE_PATH;
+
+//static GB_NIC_DEVICE_PATH mGbNicDevicePath = { acpi, pci( 0x03,0x00 ),pci( 0x1F,0x00 ),pci( 0x07,0x00 ), end };
+
+
+//P/S2 Connector
+typedef struct _PS2_CONN_DEVICE_PATH
+{
+ ACPI_HID_DEVICE_PATH PciRootBridgeDevicePath;
+ PCI_DEVICE_PATH LpcBridgeDevicePath;
+ ACPI_HID_DEVICE_PATH LpcBusDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} PS2_CONN_DEVICE_PATH;
+
+//static PS2_CONN_DEVICE_PATH mPs2KeyboardDevicePath = { acpi, pci( 0x1F,0x00 ),lpc( 0x0303,0 ), end };
+//static PS2_CONN_DEVICE_PATH mPs2MouseDevicePath = { acpi, pci( 0x1F,0x00 ),lpc( 0x0303,1 ), end };
+
+//Serial Port Connector
+typedef struct _SERIAL_CONN_DEVICE_PATH
+{
+ ACPI_HID_DEVICE_PATH PciRootBridgeDevicePath;
+ PCI_DEVICE_PATH LpcBridgeDevicePath;
+ ACPI_HID_DEVICE_PATH LpcBusDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} SERIAL_CONN_DEVICE_PATH;
+
+//static SERIAL_CONN_DEVICE_PATH mCom1DevicePath = { acpi, pci( 0x1F,0x00 ),lpc( 0x0501,0 ), end };
+//static SERIAL_CONN_DEVICE_PATH mCom2DevicePath = { acpi, pci( 0x1F,0x00 ),lpc( 0x0501,1 ), end };
+
+//Parallel Port Connector
+typedef struct _PARALLEL_CONN_DEVICE_PATH
+{
+ ACPI_HID_DEVICE_PATH PciRootBridgeDevicePath;
+ PCI_DEVICE_PATH LpcBridgeDevicePath;
+ ACPI_HID_DEVICE_PATH LpcBusDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} PARALLEL_CONN_DEVICE_PATH;
+
+//static PARALLEL_CONN_DEVICE_PATH mLpt1DevicePath = { acpi, pci( 0x1F,0x00 ),lpc( 0x0401,0 ), end };
+
+//Floopy Connector
+typedef struct _FLOOPY_CONN_DEVICE_PATH
+{
+ ACPI_HID_DEVICE_PATH PciRootBridgeDevicePath;
+ PCI_DEVICE_PATH LpcBridgeDevicePath;
+ ACPI_HID_DEVICE_PATH LpcBusDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} FLOOPY_CONN_DEVICE_PATH;
+
+//static FLOOPY_CONN_DEVICE_PATH mFloopyADevicePath = { acpi, pci( 0x1F,0x00 ),lpc( 0x0604,0 ), end };
+//static FLOOPY_CONN_DEVICE_PATH mFloopyBDevicePath = { acpi, pci( 0x1F,0x00 ),lpc( 0x0604,1 ), end };
+
+*/
+
+//
+// End Shanmu
+//
+#pragma pack()
+
+#endif
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c
new file mode 100644
index 0000000000..48d865194f
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscNumberOfInstallableLanguagesData.c
@@ -0,0 +1,37 @@
+/*++
+
+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:
+
+ MiscNumberOfInstallableLanguagesData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_NUMBER_OF_INSTALLABLE_LANGUAGES_DATA, NumberOfInstallableLanguages) = {
+ 1, // NumberOfInstallableLanguages
+ { // LanguageFlags
+ 0, // AbbreviatedLanguageFormat
+ 0 // Reserved
+ },
+ 0, // CurrentLanguageNumber
+};
+
+/* eof - MiscNumberOfInstallableLanguagesData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscOemString.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscOemString.uni
new file mode 100644
index 0000000000..fb79bdbde1
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscOemString.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscOemStringData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscOemStringData.c
new file mode 100644
index 0000000000..170d6dcd44
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscOemStringData.c
@@ -0,0 +1,32 @@
+/*++
+
+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:
+
+ MiscOemStringData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_OEM_STRING_DATA, OemString) = {
+ { STRING_TOKEN(STR_MISC_OEM_STRING) }
+};
+
+/* eof - MiscOemStringData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni
new file mode 100644
index 0000000000..b6a617b75e
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignator.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c
new file mode 100644
index 0000000000..ac3abcc26c
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorData.c
@@ -0,0 +1,99 @@
+/*++
+
+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:
+
+ MiscPortInternalConnectorDesignatorData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortInternalConnectorDesignator) = {
+ STRING_TOKEN(STR_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR), // PortInternalConnectorDesignator
+ STRING_TOKEN(STR_MISC_PORT_EXTERNAL_CONNECTOR_DESIGNATOR), // PortExternalConnectorDesignator
+ EfiPortConnectorTypeOther, // PortInternalConnectorType
+ EfiPortConnectorTypeOther, // PortExternalConnectorType
+ EfiPortTypeNone, // PortType
+ {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath
+};
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortKeyboard) = {
+ STRING_TOKEN (STR_MISC_PORT_INTERNAL_KEYBOARD), // PortInternalConnectorDesignator
+ STRING_TOKEN (STR_MISC_PORT_EXTERNAL_KEYBOARD), // PortExternalConnectorDesignator
+ EfiPortConnectorTypeNone, // PortInternalConnectorType
+ EfiPortConnectorTypePS2, // PortExternalConnectorType
+ EfiPortTypeKeyboard, // PortType
+ // mPs2KbyboardDevicePath // PortPath
+ //
+ {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath
+};
+
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortMouse) = {
+ STRING_TOKEN (STR_MISC_PORT_INTERNAL_MOUSE), // PortInternalConnectorDesignator
+ STRING_TOKEN (STR_MISC_PORT_EXTERNAL_MOUSE), // PortExternalConnectorDesignator
+ EfiPortConnectorTypeNone, // PortInternalConnectorType
+ EfiPortConnectorTypePS2, // PortExternalConnectorType
+ EfiPortTypeMouse, // PortType
+ // mPs2MouseDevicePath // PortPath
+ //
+ {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath
+};
+
+
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortCom1) = {
+ STRING_TOKEN(STR_MISC_PORT_INTERNAL_COM1),
+ STRING_TOKEN(STR_MISC_PORT_EXTERNAL_COM1),
+ EfiPortConnectorTypeNone,
+ EfiPortConnectorTypeDB9Female,
+ EfiPortTypeSerial16550ACompatible,
+ {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath
+};
+
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortCom2) = {
+ STRING_TOKEN(STR_MISC_PORT_INTERNAL_COM2),
+ STRING_TOKEN(STR_MISC_PORT_EXTERNAL_COM2),
+ EfiPortConnectorTypeNone,
+ EfiPortConnectorTypeDB9Female,
+ EfiPortTypeSerial16550ACompatible,
+ {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath
+};
+
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortExtensionPower) = {
+ STRING_TOKEN(STR_MISC_PORT_INTERNAL_EXTENSION_POWER),
+ STRING_TOKEN(STR_MISC_PORT_EXTERNAL_EXTENSION_POWER),
+ EfiPortConnectorTypeOther,
+ EfiPortConnectorTypeNone,
+ EfiPortTypeOther,
+ {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath
+};
+
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA, MiscPortFloppy) = {
+ STRING_TOKEN(STR_MISC_PORT_INTERNAL_FLOPPY),
+ STRING_TOKEN(STR_MISC_PORT_EXTERNAL_FLOPPY),
+ EfiPortConnectorTypeOnboardFloppy,
+ EfiPortConnectorTypeNone,
+ EfiPortTypeOther,
+ {{{{0, 0, {0, 0}}, 0, 0}, {{0, 0, {0, 0}}, 0, 0}, {0, 0, {0, 0}}}} // PortPath
+};
+
+/* eof - MiscPortInternalConnectorDesignatorData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c
new file mode 100644
index 0000000000..bc3e549938
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscPortInternalConnectorDesignatorFunction.c
@@ -0,0 +1,266 @@
+/*++
+
+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:
+
+ MiscPortInternalConnectorDesignatorFunction.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+//
+//
+MISC_SUBCLASS_TABLE_FUNCTION (
+ MiscPortInternalConnectorDesignator
+ )
+/*++
+Description:
+
+ This function makes boot time changes to the contents of the
+ MiscPortConnectorInformation (Type 8).
+
+Parameters:
+
+ RecordType
+ Type of record to be processed from the Data Table.
+ mMiscSubclassDataTable[].RecordType
+
+ RecordLen
+ Size of static RecordData from the Data Table.
+ mMiscSubclassDataTable[].RecordLen
+
+ RecordData
+ Pointer to copy of RecordData from the Data Table. Changes made
+ to this copy will be written to the Data Hub but will not alter
+ the contents of the static Data Table.
+
+ LogRecordData
+ Set *LogRecordData to TRUE to log RecordData to Data Hub.
+ Set *LogRecordData to FALSE when there is no more data to log.
+
+Returns:
+
+ EFI_SUCCESS
+ All parameters were valid and *RecordData and *LogRecordData have
+ been set.
+
+ EFI_UNSUPPORTED
+ Unexpected RecordType value.
+
+ EFI_INVALID_PARAMETER
+ One of the following parameter conditions was true:
+ RecordLen was zero.
+ RecordData was NULL.
+ LogRecordData was NULL.
+--*/
+{
+ STATIC BOOLEAN Done = FALSE;
+ STATIC PS2_CONN_DEVICE_PATH mPs2KeyboardDevicePath = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0303, 0), DP_END };
+ STATIC PS2_CONN_DEVICE_PATH mPs2MouseDevicePath = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0303, 1), DP_END };
+ STATIC SERIAL_CONN_DEVICE_PATH mCom1DevicePath = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0501, 0), DP_END };
+ STATIC SERIAL_CONN_DEVICE_PATH mCom2DevicePath = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0501, 1), DP_END };
+ //STATIC PARALLEL_CONN_DEVICE_PATH mLpt1DevicePath = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0401, 0), DP_END };
+ STATIC FLOOPY_CONN_DEVICE_PATH mFloopyADevicePath = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0604, 0), DP_END };
+ //STATIC FLOOPY_CONN_DEVICE_PATH mFloopyBDevicePath = { DP_ACPI, DP_PCI (0x1F, 0x00), DP_LPC (0x0604, 1), DP_END };
+ //STATIC USB_PORT_DEVICE_PATH mUsb0DevicePath = { DP_ACPI, DP_PCI (0x1d, 0x00), DP_END };
+ //STATIC USB_PORT_DEVICE_PATH mUsb1DevicePath = { DP_ACPI, DP_PCI (0x1d, 0x01), DP_END };
+ //STATIC USB_PORT_DEVICE_PATH mUsb2DevicePath = { DP_ACPI, DP_PCI (0x1d, 0x02), DP_END };
+ //STATIC USB_PORT_DEVICE_PATH mUsb3DevicePath = { DP_ACPI, DP_PCI (0x1d, 0x07), DP_END };
+ //STATIC IDE_DEVICE_PATH mIdeDevicePath = { DP_ACPI, DP_PCI (0x1F, 0x01), DP_END };
+ //STATIC GB_NIC_DEVICE_PATH mGbNicDevicePath = { DP_ACPI, DP_PCI( 0x03,0x00 ),DP_PCI( 0x1F,0x00 ),DP_PCI( 0x07,0x00 ), DP_END };
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath = DP_END;
+
+ //
+ // First check for invalid parameters.
+ //
+ // Shanmu >> to fix the Device Path Issue...
+ // if (RecordLen == 0 || RecordData == NULL || LogRecordData == NULL) {
+ //
+ if (*RecordLen == 0 || RecordData == NULL || LogRecordData == NULL) {
+ //
+ // End Shanmu
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Then check for unsupported RecordType.
+ //
+ if (RecordType != EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_RECORD_NUMBER) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Is this the first time through this function?
+ //
+ if (!Done) {
+ //
+ // Yes, this is the first time. Inspect/Change the contents of the
+ // RecordData structure.
+ //
+ //
+ // Device path is only updated here as it was not taking that in static data
+ //
+ // Shanmu >> to fix the Device Path Issue...
+ //
+
+ /*
+ switch (((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortInternalConnectorDesignator)
+ {
+ case STR_MISC_PORT_INTERNAL_MOUSE:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mPs2MouseDevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_KEYBOARD:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mPs2KeyboardDevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_COM1:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mCom1DevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_COM2:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mCom2DevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_LPT1:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mLpt1DevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_USB1:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mUsb0DevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_USB2:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mUsb1DevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_USB3:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mUsb2DevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_NETWORK:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mGbNicDevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_FLOPPY:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mFloopyADevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_IDE1:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mIdeDevicePath);
+ }break;
+ case STR_MISC_PORT_INTERNAL_IDE2:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = *((EFI_DEVICE_PATH_PROTOCOL*)&mIdeDevicePath);
+ }break;
+ default:
+ {
+ (EFI_DEVICE_PATH_PROTOCOL)((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *)RecordData)->PortPath = EndDevicePath;
+ }break;
+ }
+ */
+ switch (((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortInternalConnectorDesignator) {
+ case STR_MISC_PORT_INTERNAL_MOUSE:
+ {
+ CopyMem (
+ &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,
+ &mPs2MouseDevicePath,
+ GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mPs2MouseDevicePath)
+ );
+ *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mPs2MouseDevicePath);
+ }
+ break;
+
+ case STR_MISC_PORT_INTERNAL_KEYBOARD:
+ {
+ CopyMem (
+ &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,
+ &mPs2KeyboardDevicePath,
+ GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mPs2KeyboardDevicePath)
+ );
+ *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mPs2KeyboardDevicePath);
+ }
+ break;
+
+ case STR_MISC_PORT_INTERNAL_COM1:
+ {
+ CopyMem (
+ &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,
+ &mCom1DevicePath,
+ GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mCom1DevicePath)
+ );
+ *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mCom1DevicePath);
+ }
+ break;
+
+ case STR_MISC_PORT_INTERNAL_COM2:
+ {
+ CopyMem (
+ &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,
+ &mCom2DevicePath,
+ GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mCom2DevicePath)
+ );
+ *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mCom2DevicePath);
+ }
+ break;
+
+ case STR_MISC_PORT_INTERNAL_FLOPPY:
+ {
+ CopyMem (
+ &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,
+ &mFloopyADevicePath,
+ GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mFloopyADevicePath)
+ );
+ *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &mFloopyADevicePath);
+ }
+ break;
+
+ default:
+ {
+ CopyMem (
+ &((EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA *) RecordData)->PortPath,
+ &EndDevicePath,
+ GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &EndDevicePath)
+ );
+ *RecordLen = *RecordLen - sizeof (EFI_MISC_PORT_DEVICE_PATH) + GetDevicePathSize ((EFI_DEVICE_PATH_PROTOCOL *) &EndDevicePath);
+ }
+ break;
+ }
+ //
+ // End Shanmu
+ //
+ // Set Done flag to TRUE for next pass through this function.
+ // Set *LogRecordData to TRUE so data will get logged to Data Hub.
+ //
+ Done = TRUE;
+ *LogRecordData = TRUE;
+ } else {
+ //
+ // No, this is the second time. Reset the state of the Done flag
+ // to FALSE and tell the data logger that there is no more data
+ // to be logged for this record type. If any memory allocations
+ // were made by earlier passes, they must be released now.
+ //
+ Done = FALSE;
+ *LogRecordData = FALSE;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/* eof - MiscSystemManufacturerFunction.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c
new file mode 100644
index 0000000000..c075ffd7b0
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscResetCapabilitiesData.c
@@ -0,0 +1,42 @@
+/*++
+
+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:
+
+ MiscResetCapabilitiesData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_RESET_CAPABILITIES, MiscResetCapabilities) = {
+ { // ResetCapabilities
+ 0, // Status
+ 0, // BootOption
+ 0, // BootOptionOnLimit
+ 0, // WatchdogTimerPresent
+ 0 // Reserved
+ },
+ 0, // ResetCount
+ 0, // ResetLimit
+ 0, // ResetTimerInterval
+ 0 // ResetTimeout
+};
+
+/* eof - MiscResetCapabilities.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h
new file mode 100644
index 0000000000..4105266768
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.h
@@ -0,0 +1,119 @@
+/*++
+
+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:
+
+ MiscSubclassDriver.h
+
+Abstract:
+
+ Header file for MiscSubclass Driver.
+
+--*/
+
+#ifndef _MISC_SUBCLASS_DRIVER_H
+#define _MISC_SUBCLASS_DRIVER_H
+
+#include <FrameworkDxe.h>
+#include <UnixDxe.h>
+#include <Guid/DataHubRecords.h>
+#include <Guid/DataHubProducer.h>
+#include <Protocol/DataHub.h>
+#include <Protocol/UnixIo.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/FrameworkHiiLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/PcdLib.h>
+
+
+#include <MiscDevicePath.h>
+#include <Protocol/DataHub.h>
+#include <Protocol/FrameworkHii.h>
+#include <Library/HiiLib.h>
+
+//
+// Data table entry update function.
+//
+typedef
+EFI_STATUS
+(EFIAPI EFI_MISC_SUBCLASS_DATA_FUNCTION) (
+ IN UINT16 RecordType,
+ IN UINT32 *RecordLen,
+ IN OUT EFI_MISC_SUBCLASS_RECORDS *RecordData,
+ OUT BOOLEAN *LogRecordData
+ );
+
+//
+// Data table entry definition.
+//
+typedef struct {
+ UINT16 RecordType;
+ UINT32 RecordLen;
+ VOID *RecordData;
+ EFI_MISC_SUBCLASS_DATA_FUNCTION *Function;
+} EFI_MISC_SUBCLASS_DATA_TABLE;
+
+//
+// Data Table extern definitions.
+//
+#define MISC_SUBCLASS_TABLE_EXTERNS(NAME1, NAME2) \
+ extern NAME1 NAME2 ## Data; \
+ extern EFI_MISC_SUBCLASS_DATA_FUNCTION NAME2 ## Function
+
+//
+// Data Table entries
+//
+#define MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(NAME1, NAME2) { \
+ NAME1 ## _RECORD_NUMBER, sizeof (NAME1 ## _DATA), &NAME2 ## Data, NULL \
+ }
+
+#define MISC_SUBCLASS_TABLE_ENTRY_FUNCTION_ONLY(NAME1, NAME2) \
+ { \
+ NAME1 ## _RECORD_NUMBER, 0, NULL, &NAME2 ## Function \
+ }
+
+#define MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(NAME1, NAME2, NAME3) \
+ { \
+ NAME1 ## _RECORD_NUMBER, sizeof (NAME1 ## _DATA), &NAME2 ## Data, &NAME3 ## Function \
+ }
+
+//
+// Global definition macros.
+//
+#define MISC_SUBCLASS_TABLE_DATA(NAME1, NAME2) NAME1 NAME2 ## Data
+
+#define MISC_SUBCLASS_TABLE_FUNCTION(NAME2) \
+ EFI_STATUS EFIAPI NAME2 ## Function ( \
+ IN UINT16 RecordType, \
+ IN UINT32 *RecordLen, \
+ IN OUT EFI_MISC_SUBCLASS_RECORDS * RecordData, \
+ OUT BOOLEAN *LogRecordData \
+ )
+
+//
+// Data Table Array
+//
+extern EFI_MISC_SUBCLASS_DATA_TABLE mMiscSubclassDataTable[];
+
+//
+// Data Table Array Entries
+//
+extern UINTN mMiscSubclassDataTableEntries;
+
+#endif /* _MISC_SUBCLASS_DRIVER_H */
+
+/* eof - MiscSubclassDriver.h */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf
new file mode 100644
index 0000000000..daa3ae2dae
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf
@@ -0,0 +1,100 @@
+#/** @file
+# Misc Sub class driver
+#
+# Parses the MiscSubclassDataTable and reports any generated data to the DataHub.
+# All .uni file who tagged with "ToolCode="DUMMY"" in following file list is included by
+# MiscSubclassDriver.uni file, the StrGather tool will expand MiscSubclassDriver.uni file
+# and parse all .uni file.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = MiscSubclass
+ FILE_GUID = f2fbd108-8985-11db-b06a-0040d02b1835
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = MiscSubclassDriverEntryPoint
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ MiscPortInternalConnectorDesignatorFunction.c
+ MiscSystemSlotDesignationData.c
+ MiscSystemOptionStringData.c
+ MiscSystemManufacturerFunction.c
+ MiscSystemManufacturerData.c
+ MiscSystemLanguageStringData.c
+ MiscResetCapabilitiesData.c
+ MiscPortInternalConnectorDesignatorData.c
+ MiscOemStringData.c
+ MiscNumberOfInstallableLanguagesData.c
+ MiscChassisManufacturerData.c
+ MiscBootInformationData.c
+ MiscBiosVendorData.c
+ MiscBaseBoardManufacturerData.c
+ MiscSubclassDriverDataTable.c
+ MiscSubclassDriverEntryPoint.c
+ MiscSubClassDriver.uni
+ MiscSystemSlotDesignation.uni
+ MiscSystemOptionString.uni
+ MiscSystemManufacturer.uni
+ MiscSystemLanguageString.uni
+ MiscPortInternalConnectorDesignator.uni
+ MiscOemString.uni
+ MiscChassisManufacturer.uni
+ MiscBiosVendor.uni
+ MiscBaseBoardManufacturer.uni
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+ IntelFrameworkModulePkg/IntelFrameworkModulePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ DevicePathLib
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ UefiDriverEntryPoint
+ UefiLib
+ HiiLib
+ DebugLib
+ BaseLib
+
+
+[Guids]
+ gEfiMemorySubClassGuid # SOMETIMES_CONSUMED
+ gEfiMemoryProducerGuid # SOMETIMES_CONSUMED
+ gEfiProcessorSubClassGuid # SOMETIMES_CONSUMED
+ gEfiMiscSubClassGuid # ALWAYS_CONSUMED
+
+
+[Protocols]
+ gEfiUnixIoProtocolGuid # PROTOCOL_NOTIFY SOMETIMES_CONSUMED
+ gEfiDataHubProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+
+[Pcd.common]
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySize
+
+[Depex]
+ gEfiDataHubProtocolGuid
+
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.msa b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.msa
new file mode 100644
index 0000000000..b9f0992035
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.msa
@@ -0,0 +1,170 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>MiscSubclass</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>f2fbd108-8985-11db-b06a-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Misc Sub class driver</Abstract>
+ <Description>
+ Parses the MiscSubclassDataTable and reports any generated data to the DataHub.
+ All .uni file who tagged with "ToolCode="DUMMY"" in following file list is included by
+ MiscSubclassDriver.uni file, the StrGather tool will expand MiscSubclassDriver.uni file
+ and parse all .uni file.
+ </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>MiscSubclass</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>HiiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DevicePathLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename ToolCode="DUMMY">MiscBaseBoardManufacturer.uni</Filename>
+ <Filename ToolCode="DUMMY">MiscBiosVendor.uni</Filename>
+ <Filename ToolCode="DUMMY">MiscChassisManufacturer.uni</Filename>
+ <Filename ToolCode="DUMMY">MiscOemString.uni</Filename>
+ <Filename ToolCode="DUMMY">MiscPortInternalConnectorDesignator.uni</Filename>
+ <Filename ToolCode="DUMMY">MiscSystemLanguageString.uni</Filename>
+ <Filename ToolCode="DUMMY">MiscSystemManufacturer.uni</Filename>
+ <Filename ToolCode="DUMMY">MiscSystemOptionString.uni</Filename>
+ <Filename ToolCode="DUMMY">MiscSystemSlotDesignation.uni</Filename>
+ <Filename>MiscSubclassDriver.uni</Filename>
+ <Filename>MiscDevicePath.h</Filename>
+ <Filename>MiscSubclassDriver.h</Filename>
+ <Filename>MiscSubclassDriverEntryPoint.c</Filename>
+ <Filename>MiscSubclassDriverDataTable.c</Filename>
+ <Filename>MiscBaseBoardManufacturerData.c</Filename>
+ <Filename>MiscBiosVendorData.c</Filename>
+ <Filename>MiscBootInformationData.c</Filename>
+ <Filename>MiscChassisManufacturerData.c</Filename>
+ <Filename>MiscNumberOfInstallableLanguagesData.c</Filename>
+ <Filename>MiscOemStringData.c</Filename>
+ <Filename>MiscPortInternalConnectorDesignatorData.c</Filename>
+ <Filename>MiscResetCapabilitiesData.c</Filename>
+ <Filename>MiscSystemLanguageStringData.c</Filename>
+ <Filename>MiscSystemManufacturerData.c</Filename>
+ <Filename>MiscSystemManufacturerFunction.c</Filename>
+ <Filename>MiscSystemOptionStringData.c</Filename>
+ <Filename>MiscSystemSlotDesignationData.c</Filename>
+ <Filename>MiscPortInternalConnectorDesignatorFunction.c</Filename>
+ <Filename>MiscSubclassDriver.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_CONSUMED">
+ <ProtocolCName>gEfiDataHubProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>
+ </Protocol>
+ <ProtocolNotify Usage="SOMETIMES_CONSUMED">
+ <ProtocolNotifyCName>gEfiUnixIoProtocolGuid</ProtocolNotifyCName>
+ </ProtocolNotify>
+ </Protocols>
+ <DataHubs>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>MiscPortKeyboard</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>MiscPortMouse</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>MiscPortCom1</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>MiscPortCom2</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>MiscBiosVendor</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>MiscSystemManufacturer</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>MiscBaseBoardManufacturer</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>MiscChassisManufacturer</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>MiscSystemSlotDesignation</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>OemString</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="ALWAYS_PRODUCED">
+ <DataHubCName>SystemOptionString</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="SOMETIMES_CONSUMED">
+ <DataHubCName>ProcessorSubClassData</DataHubCName>
+ </DataHubRecord>
+ <DataHubRecord Usage="SOMETIMES_PRODUCED">
+ <DataHubCName>MemorySubClassData</DataHubCName>
+ </DataHubRecord>
+ </DataHubs>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiMiscSubClassGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiProcessorSubClassGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiMemoryProducerGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiMemorySubClassGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiUnixMemoryGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>MiscSubclassDriverEntryPoint</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni
new file mode 100644
index 0000000000..bae6862210
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c
new file mode 100644
index 0000000000..06e2a80f1a
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverDataTable.c
@@ -0,0 +1,99 @@
+/*++
+
+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:
+
+ MiscSubclassDriverDataTable.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// External definitions referenced by Data Table entries.
+//
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_CHASSIS_MANUFACTURER_DATA,
+ MiscChassisManufacturer
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_BIOS_VENDOR_DATA,
+ MiscBiosVendor
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_SYSTEM_MANUFACTURER_DATA,
+ MiscSystemManufacturer
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_BASE_BOARD_MANUFACTURER_DATA,
+ MiscBaseBoardManufacturer
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,
+ MiscPortInternalConnectorDesignator
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,
+ MiscPortKeyboard
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,
+ MiscPortMouse
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,
+ MiscPortCom1
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR_DATA,
+ MiscPortCom2
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_SYSTEM_SLOT_DESIGNATION_DATA,
+ MiscSystemSlotDesignation
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_OEM_STRING_DATA,
+ OemString
+ );
+MISC_SUBCLASS_TABLE_EXTERNS (
+ EFI_MISC_SYSTEM_OPTION_STRING_DATA,
+ SystemOptionString
+ );
+
+//
+// Data Table.
+//
+EFI_MISC_SUBCLASS_DATA_TABLE mMiscSubclassDataTable[] = {
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR, MiscPortKeyboard, MiscPortInternalConnectorDesignator),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR, MiscPortMouse, MiscPortInternalConnectorDesignator),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR, MiscPortCom1, MiscPortInternalConnectorDesignator),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_AND_FUNCTION(EFI_MISC_PORT_INTERNAL_CONNECTOR_DESIGNATOR, MiscPortCom2, MiscPortInternalConnectorDesignator),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_BIOS_VENDOR, MiscBiosVendor),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_SYSTEM_MANUFACTURER, MiscSystemManufacturer),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_BASE_BOARD_MANUFACTURER, MiscBaseBoardManufacturer),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_CHASSIS_MANUFACTURER, MiscChassisManufacturer),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_SYSTEM_SLOT_DESIGNATION, MiscSystemSlotDesignation),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_OEM_STRING, OemString),
+ MISC_SUBCLASS_TABLE_ENTRY_DATA_ONLY(EFI_MISC_SYSTEM_OPTION_STRING, SystemOptionString),
+};
+
+//
+// Number of Data Table entries.
+//
+UINTN mMiscSubclassDataTableEntries = (sizeof mMiscSubclassDataTable) / sizeof (EFI_MISC_SUBCLASS_DATA_TABLE);
+
+/* eof - MiscSubclassDriverDataTable.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
new file mode 100644
index 0000000000..de8d8ef6f0
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSubclassDriverEntryPoint.c
@@ -0,0 +1,334 @@
+/*++
+
+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:
+
+ MiscSubclassDriverEntryPoint.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+
+extern UINT8 MiscSubClassStrings[];
+
+//
+//
+//
+EFI_STATUS
+LogRecordDataToDataHub (
+ EFI_DATA_HUB_PROTOCOL *DataHub,
+ UINT32 RecordType,
+ UINT32 RecordLen,
+ VOID *RecordData
+ )
+/*++
+Description:
+
+Parameters:
+
+ DataHub
+ %%TBD
+
+ RecordType
+ %%TBD
+
+ RecordLen
+ %%TBD
+
+ RecordData
+ %%TBD
+
+Returns:
+
+ EFI_INVALID_PARAMETER
+
+ EFI_SUCCESS
+
+ Other Data Hub errors
+
+--*/
+{
+ EFI_MISC_SUBCLASS_DRIVER_DATA MiscSubclass;
+ EFI_STATUS EfiStatus;
+
+ //
+ // Do nothing if data parameters are not valid.
+ //
+ if (RecordLen == 0 || RecordData == NULL) {
+ DEBUG (
+ (EFI_D_ERROR,
+ "RecordLen == %d RecordData == %xh\n",
+ RecordLen,
+ RecordData)
+ );
+
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Assemble Data Hub record.
+ //
+ MiscSubclass.Header.Version = EFI_MISC_SUBCLASS_VERSION;
+ MiscSubclass.Header.HeaderSize = sizeof (EFI_SUBCLASS_TYPE1_HEADER);
+ MiscSubclass.Header.Instance = 1;
+ MiscSubclass.Header.SubInstance = 1;
+ MiscSubclass.Header.RecordType = RecordType;
+
+ CopyMem (
+ &MiscSubclass.Record,
+ RecordData,
+ RecordLen
+ );
+
+ //
+ // Log Data Hub record.
+ //
+ EfiStatus = DataHub->LogData (
+ DataHub,
+ &gEfiMiscSubClassGuid,
+ &gEfiMiscSubClassGuid,
+ EFI_DATA_RECORD_CLASS_DATA,
+ &MiscSubclass,
+ sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen
+ );
+
+ if (EFI_ERROR (EfiStatus)) {
+ DEBUG (
+ (EFI_D_ERROR,
+ "LogData(%d bytes) == %r\n",
+ sizeof (EFI_SUBCLASS_TYPE1_HEADER) + RecordLen,
+ EfiStatus)
+ );
+ }
+
+ return EfiStatus;
+}
+
+
+EFI_STATUS
+EFIAPI
+MiscSubclassDriverEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+/*++
+Description:
+
+ Standard EFI driver point. This driver parses the mMiscSubclassDataTable
+ structure and reports any generated data to the DataHub.
+
+Arguments:
+
+ ImageHandle
+ Handle for the image of this driver
+
+ SystemTable
+ Pointer to the EFI System Table
+
+Returns:
+
+ EFI_SUCCESS
+ The data was successfully reported to the Data Hub.
+
+--*/
+{
+ EFI_MISC_SUBCLASS_DRIVER_DATA RecordData;
+ EFI_DATA_HUB_PROTOCOL *DataHub;
+ EFI_HII_HANDLE HiiHandle;
+ EFI_STATUS EfiStatus;
+ UINTN Index;
+ BOOLEAN LogRecordData;
+ EFI_MEMORY_SUBCLASS_DRIVER_DATA MemorySubClassData;
+ UINT64 TotalMemorySize;
+ CHAR16 *UnixMemString;
+
+
+
+ //
+ // Initialize constant portion of subclass header.
+ //
+ RecordData.Header.Version = EFI_MISC_SUBCLASS_VERSION;
+ RecordData.Header.HeaderSize = sizeof (EFI_SUBCLASS_TYPE1_HEADER);
+ RecordData.Header.Instance = 1;
+ RecordData.Header.SubInstance = 1;
+
+ //
+ // Locate data hub protocol.
+ //
+ EfiStatus = gBS->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**) &DataHub);
+
+ if (EFI_ERROR (EfiStatus)) {
+ DEBUG ((EFI_D_ERROR, "Could not locate DataHub protocol. %r\n", EfiStatus));
+ return EfiStatus;
+ } else if (DataHub == NULL) {
+ DEBUG ((EFI_D_ERROR, "LocateProtocol(DataHub) returned NULL pointer!\n"));
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Add our default strings to the HII database. They will be modified later.
+ //
+ HiiLibAddPackages (1, &gEfiMiscSubClassGuid, NULL, &HiiHandle, MiscSubclassStrings);
+
+ if (EFI_ERROR (EfiStatus)) {
+ DEBUG ((EFI_D_ERROR, "Could not log default strings to Hii. %r\n", EfiStatus));
+ return EfiStatus;
+ }
+ //
+ //
+ //
+ for (Index = 0; Index < mMiscSubclassDataTableEntries; ++Index) {
+ //
+ // Stupidity check! Do nothing if RecordLen is zero.
+ // %%TBD - Should this be an error or a mechanism for ignoring
+ // records in the Data Table?
+ //
+ if (mMiscSubclassDataTable[Index].RecordLen == 0) {
+ DEBUG (
+ (EFI_D_ERROR,
+ "mMiscSubclassDataTable[%d].RecordLen == 0\n",
+ Index)
+ );
+
+ continue;
+ }
+ //
+ // Initialize per-record portion of subclass header and
+ // copy static data into data portion of subclass record.
+ //
+ RecordData.Header.RecordType = mMiscSubclassDataTable[Index].RecordType;
+
+ if (mMiscSubclassDataTable[Index].RecordData == NULL) {
+ ZeroMem (
+ &RecordData.Record,
+ mMiscSubclassDataTable[Index].RecordLen
+ );
+ } else {
+ CopyMem (
+ &RecordData.Record,
+ mMiscSubclassDataTable[Index].RecordData,
+ mMiscSubclassDataTable[Index].RecordLen
+ );
+ }
+ //
+ // If the entry does not have a function pointer, just log the data.
+ //
+ if (mMiscSubclassDataTable[Index].Function == NULL) {
+ //
+ // Log RecordData to Data Hub.
+ //
+ EfiStatus = DataHub->LogData (
+ DataHub,
+ &gEfiMiscSubClassGuid,
+ &gEfiMiscSubClassGuid,
+ EFI_DATA_RECORD_CLASS_DATA,
+ &RecordData,
+ sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen
+ );
+
+ if (EFI_ERROR (EfiStatus)) {
+ DEBUG (
+ (EFI_D_ERROR,
+ "LogData(%d bytes) == %r\n",
+ sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,
+ EfiStatus)
+ );
+ }
+
+ continue;
+ }
+ //
+ // The entry has a valid function pointer.
+ // Keep calling the function and logging data until there
+ // is no more data to log.
+ //
+ for (;;) {
+ EfiStatus = (*mMiscSubclassDataTable[Index].Function)(mMiscSubclassDataTable[Index].RecordType, &mMiscSubclassDataTable[Index].RecordLen, &RecordData.Record, &LogRecordData);
+
+ if (EFI_ERROR (EfiStatus)) {
+ break;
+ }
+
+ if (!LogRecordData) {
+ break;
+ }
+ //
+ //
+ //
+ EfiStatus = DataHub->LogData (
+ DataHub,
+ &gEfiMiscSubClassGuid,
+ &gEfiMiscSubClassGuid,
+ EFI_DATA_RECORD_CLASS_DATA,
+ &RecordData,
+ sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen
+ );
+
+ if (EFI_ERROR (EfiStatus)) {
+ DEBUG (
+ (EFI_D_ERROR,
+ "LogData(%d bytes) == %r\n",
+ sizeof (EFI_SUBCLASS_TYPE1_HEADER) + mMiscSubclassDataTable[Index].RecordLen,
+ EfiStatus)
+ );
+ }
+ }
+ }
+
+ //
+ // Log Memory Size info based on PCD setting.
+ //
+ MemorySubClassData.Header.Instance = 1;
+ MemorySubClassData.Header.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;
+ MemorySubClassData.Header.RecordType = EFI_MEMORY_ARRAY_START_ADDRESS_RECORD_NUMBER;
+
+ //
+ // Process Memory String in form size!size ...
+ // So 64!64 is 128 MB
+ //
+ UnixMemString = PcdGetPtr (PcdUnixMemorySize);
+ for (TotalMemorySize = 0; *UnixMemString != '\0';) {
+ TotalMemorySize += StrDecimalToUint64 (UnixMemString);
+ while (*UnixMemString != '\0') {
+ if (*UnixMemString == '!') {
+ UnixMemString++;
+ break;
+ }
+ UnixMemString++;
+ }
+ }
+
+ MemorySubClassData.Record.ArrayStartAddress.MemoryArrayStartAddress = 0;
+ MemorySubClassData.Record.ArrayStartAddress.MemoryArrayEndAddress = LShiftU64 (TotalMemorySize, 20) - 1;
+ MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.ProducerName = gEfiMemoryProducerGuid;
+ MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.Instance = 1;
+ MemorySubClassData.Record.ArrayStartAddress.PhysicalMemoryArrayLink.SubInstance = EFI_SUBCLASS_INSTANCE_NON_APPLICABLE;
+ MemorySubClassData.Record.ArrayStartAddress.MemoryArrayPartitionWidth = 0;
+
+ //
+ // Store memory size data record to data hub.
+ //
+ EfiStatus = DataHub->LogData (
+ DataHub,
+ &gEfiMemorySubClassGuid,
+ &gEfiMemoryProducerGuid,
+ EFI_DATA_RECORD_CLASS_DATA,
+ &MemorySubClassData,
+ sizeof (EFI_SUBCLASS_TYPE1_HEADER) + sizeof (EFI_MEMORY_ARRAY_START_ADDRESS_DATA)
+ );
+
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni
new file mode 100644
index 0000000000..36dacf066a
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageString.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c
new file mode 100644
index 0000000000..f904623f1d
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemLanguageStringData.c
@@ -0,0 +1,33 @@
+/*++
+
+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:
+
+ MiscSystemLanguageStringData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_SYSTEM_LANGUAGE_STRING_DATA, SystemLanguageString) = {
+ 0,
+ STRING_TOKEN(STR_MISC_SYSTEM_LANGUAGE_STRING)
+};
+
+/* eof - MiscSystemLanguageStringData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni
new file mode 100644
index 0000000000..204588ef8c
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturer.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c
new file mode 100644
index 0000000000..0a9bfab57e
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerData.c
@@ -0,0 +1,57 @@
+/*++
+
+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:
+
+ MiscSystemManufacturerData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) System Manufacturer data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_SYSTEM_MANUFACTURER_DATA, MiscSystemManufacturer)
+= {
+ STRING_TOKEN(STR_MISC_SYSTEM_MANUFACTURER),
+ // SystemManufactrurer
+ STRING_TOKEN(STR_MISC_SYSTEM_PRODUCT_NAME),
+ // SystemProductName
+ STRING_TOKEN(STR_MISC_SYSTEM_VERSION),
+ // SystemVersion
+ STRING_TOKEN(STR_MISC_SYSTEM_SERIAL_NUMBER),
+ // SystemSerialNumber
+ {
+ 0xbadfaced,
+ 0xdead,
+ 0xbeef,
+ {
+ 0x13,
+ 0x13,
+ 0x13,
+ 0x13,
+ 0x13,
+ 0x13,
+ 0x13,
+ 0x13
+ }
+ },
+ // SystemUuid
+ EfiSystemWakeupTypePowerSwitch // SystemWakeupType
+};
+
+/* eof - MiscSystemManufacturerData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c
new file mode 100644
index 0000000000..2cfbf61c17
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemManufacturerFunction.c
@@ -0,0 +1,122 @@
+/*++
+
+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:
+
+ MiscSystemManufacturerFunction.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+//
+//
+MISC_SUBCLASS_TABLE_FUNCTION (
+ MiscSystemManufacturer
+ )
+/*++
+Description:
+
+ This function makes boot time changes to the contents of the
+ MiscSystemManufacturer (Type 13).
+
+Parameters:
+
+ RecordType
+ Type of record to be processed from the Data Table.
+ mMiscSubclassDataTable[].RecordType
+
+ RecordLen
+ Size of static RecordData from the Data Table.
+ mMiscSubclassDataTable[].RecordLen
+
+ RecordData
+ Pointer to copy of RecordData from the Data Table. Changes made
+ to this copy will be written to the Data Hub but will not alter
+ the contents of the static Data Table.
+
+ LogRecordData
+ Set *LogRecordData to TRUE to log RecordData to Data Hub.
+ Set *LogRecordData to FALSE when there is no more data to log.
+
+Returns:
+
+ EFI_SUCCESS
+ All parameters were valid and *RecordData and *LogRecordData have
+ been set.
+
+ EFI_UNSUPPORTED
+ Unexpected RecordType value.
+
+ EFI_INVALID_PARAMETER
+ One of the following parameter conditions was true:
+ RecordLen was zero.
+ RecordData was NULL.
+ LogRecordData was NULL.
+--*/
+{
+ STATIC BOOLEAN Done = FALSE;
+
+ //
+ // First check for invalid parameters.
+ //
+ if (*RecordLen == 0 || RecordData == NULL || LogRecordData == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Then check for unsupported RecordType.
+ //
+ if (RecordType != EFI_MISC_SYSTEM_MANUFACTURER_RECORD_NUMBER) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Is this the first time through this function?
+ //
+ if (!Done) {
+ //
+ // Yes, this is the first time. Inspect/Change the contents of the
+ // RecordData structure.
+ //
+ //
+ // Set system GUID.
+ //
+ // ((EFI_MISC_SYSTEM_MANUFACTURER_DATA *)RecordData)->SystemUuid = %%TBD
+ //
+ // Set power-on type.
+ //
+ // ((EFI_MISC_SYSTEM_MANUFACTURER_DATA *)RecordData)->SystemWakeupType = %%TBD
+ //
+ // Set Done flag to TRUE for next pass through this function.
+ // Set *LogRecordData to TRUE so data will get logged to Data Hub.
+ //
+ Done = TRUE;
+ *LogRecordData = TRUE;
+ } else {
+ //
+ // No, this is the second time. Reset the state of the Done flag
+ // to FALSE and tell the data logger that there is no more data
+ // to be logged for this record type. If any memory allocations
+ // were made by earlier passes, they must be released now.
+ //
+ Done = FALSE;
+ *LogRecordData = FALSE;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/* eof - MiscSystemManufacturerFunction.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni
new file mode 100644
index 0000000000..617578d6a3
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionString.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c
new file mode 100644
index 0000000000..bc777cee0a
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemOptionStringData.c
@@ -0,0 +1,32 @@
+/*++
+
+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:
+
+ MiscSystemOptionStringData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_SYSTEM_OPTION_STRING_DATA, SystemOptionString) = {
+ {STRING_TOKEN(STR_MISC_SYSTEM_OPTION_STRING)}
+};
+
+/* eof - MiscSystemOptionStringData.c */
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni
new file mode 100644
index 0000000000..f279ff960d
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignation.uni
Binary files differ
diff --git a/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c
new file mode 100644
index 0000000000..d076034831
--- /dev/null
+++ b/UnixPkg/MiscSubClassPlatformDxe/MiscSystemSlotDesignationData.c
@@ -0,0 +1,52 @@
+/*++
+
+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:
+
+ MiscSystemSlotDesignationData.c
+
+Abstract:
+
+ This driver parses the mMiscSubclassDataTable structure and reports
+ any generated data to the DataHub.
+
+--*/
+
+#include "MiscSubClassDriver.h"
+
+//
+// Static (possibly build generated) Bios Vendor data.
+//
+MISC_SUBCLASS_TABLE_DATA(EFI_MISC_SYSTEM_SLOT_DESIGNATION_DATA, MiscSystemSlotDesignation) = {
+ STRING_TOKEN(STR_MISC_SYSTEM_SLOT_DESIGNATION), // SlotDesignation
+ EfiSlotTypeOther, // SlotType
+ EfiSlotDataBusWidthOther, // SlotDataBusWidth
+ EfiSlotUsageOther, // SlotUsage
+ EfiSlotLengthOther, // SlotLength
+ 0, // SlotId
+ { // SlotCharacteristics
+ 0, // CharacteristicsUnknown :1;
+ 0, // Provides50Volts :1;
+ 0, // Provides33Volts :1;
+ 0, // SharedSlot :1;
+ 0, // PcCard16Supported :1;
+ 0, // CardBusSupported :1;
+ 0, // ZoomVideoSupported :1;
+ 0, // ModemRingResumeSupported:1;
+ 0, // PmeSignalSupported :1;
+ 0, // HotPlugDevicesSupported :1;
+ 0, // SmbusSignalSupported :1;
+ 0 // Reserved :21;
+ },
+ {0, 0, {0, 0}} // SlotDevicePath
+};
+
+/* eof - MiscSystemSlotsData.c */
diff --git a/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
new file mode 100644
index 0000000000..672d9b210a
--- /dev/null
+++ b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.c
@@ -0,0 +1,356 @@
+/*++
+
+Copyright (c) 2004 - 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:
+
+ RealTimeClock.c
+
+Abstract:
+
+ UNIX Emulation Architectural Protocol Driver as defined in Tiano
+
+--*/
+#include "PiDxe.h"
+#include "UnixDxe.h"
+#include <Protocol/RealTimeClock.h>
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UnixLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+BOOLEAN
+DayValid (
+ IN EFI_TIME *Time
+ );
+
+BOOLEAN
+IsLeapYear (
+ IN EFI_TIME *Time
+ );
+
+EFI_STATUS
+RtcTimeFieldsValid (
+ IN EFI_TIME *Time
+ );
+
+EFI_STATUS
+EFIAPI
+InitializeRealTimeClock (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixGetTime (
+ OUT EFI_TIME * Time,
+ OUT EFI_TIME_CAPABILITIES * Capabilities OPTIONAL
+ )
+/*++
+
+Routine Description:
+ Service routine for RealTimeClockInstance->GetTime
+
+Arguments:
+
+ Time - A pointer to storage that will receive a snapshot of the current time.
+
+ Capabilities - A pointer to storage that will receive the capabilities of the real time clock
+ in the platform. This includes the real time clock's resolution and accuracy.
+ All reported device capabilities are rounded up. This is an OPTIONAL argument.
+
+Returns:
+
+ EFI_SUCEESS - The underlying GetSystemTime call occurred and returned
+ Note that in the NT32 emulation, the GetSystemTime call has no return value
+ thus you will always receive a EFI_SUCCESS on this.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+
+ //
+ // Check parameter for null pointer
+ //
+ if (Time == NULL) {
+ return EFI_INVALID_PARAMETER;
+
+ }
+
+ gUnix->GetLocalTime (Time);
+
+ if (Capabilities != NULL) {
+ Capabilities->Resolution = 1;
+ Capabilities->Accuracy = 50000000;
+ Capabilities->SetsToZero = FALSE;
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSetTime (
+ IN EFI_TIME *Time
+ )
+/*++
+
+Routine Description:
+ Service routine for RealTimeClockInstance->SetTime
+
+Arguments:
+
+ Time - A pointer to storage containing the time and date information to
+ program into the real time clock.
+
+Returns:
+
+ EFI_SUCEESS - The operation completed successfully.
+
+ EFI_INVALID_PARAMETER - One of the fields in Time is out of range.
+
+ EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
+
+--*/
+// TODO: EFI_SUCCESS - add return value to function comment
+{
+ EFI_STATUS Status;
+
+ if (Time == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Make sure that the time fields are valid
+ //
+ Status = RtcTimeFieldsValid (Time);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixGetWakeupTime (
+ OUT BOOLEAN *Enabled,
+ OUT BOOLEAN *Pending,
+ OUT EFI_TIME *Time
+ )
+/*++
+
+Routine Description:
+ Service routine for RealTimeClockInstance->GetWakeupTime
+
+Arguments:
+ This - Indicates the protocol instance structure.
+
+ Enabled - Indicates if the alarm is currently enabled or disabled.
+
+ Pending - Indicates if the alarm signal is pending and requires
+ acknowledgement.
+
+ Time - The current alarm setting.
+
+Returns:
+
+ EFI_SUCEESS - The operation completed successfully.
+
+ EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
+
+ EFI_UNSUPPORTED - The operation is not supported on this platform.
+
+--*/
+{
+ return EFI_UNSUPPORTED;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSetWakeupTime (
+ IN BOOLEAN Enable,
+ OUT EFI_TIME *Time
+ )
+/*++
+
+Routine Description:
+ Service routine for RealTimeClockInstance->SetWakeupTime
+
+Arguments:
+
+ Enabled - Enable or disable the wakeup alarm.
+
+ Time - If enable is TRUE, the time to set the wakup alarm for.
+ If enable is FALSE, then this parameter is optional, and
+ may be NULL.
+
+Returns:
+
+ EFI_SUCEESS - The operation completed successfully.
+
+ EFI_DEVICE_ERROR - The operation could not be complete due to a device error.
+
+ EFI_INVALID_PARAMETER - A field in Time is out of range.
+
+ EFI_UNSUPPORTED - The operation is not supported on this platform.
+
+--*/
+{
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI
+InitializeRealTimeClock (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+/*++
+
+Routine Description:
+ Install Real Time Clock Protocol
+
+Arguments:
+ ImageHandle - Image Handle
+ SystemTable - Pointer to system table
+
+Returns:
+
+ EFI_SUCEESS - Real Time Clock Services are installed into the Runtime Services Table
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+
+ SystemTable->RuntimeServices->GetTime = UnixGetTime;
+ SystemTable->RuntimeServices->SetTime = UnixSetTime;
+ SystemTable->RuntimeServices->GetWakeupTime = UnixGetWakeupTime;
+ SystemTable->RuntimeServices->SetWakeupTime = UnixSetWakeupTime;
+
+ Handle = NULL;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Handle,
+ &gEfiRealTimeClockArchProtocolGuid,
+ NULL,
+ NULL
+ );
+ return Status;
+}
+
+EFI_STATUS
+RtcTimeFieldsValid (
+ IN EFI_TIME *Time
+ )
+/*++
+
+Routine Description:
+
+ Arguments:
+
+ Returns:
+--*/
+// TODO: Time - add argument and description to function comment
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+// TODO: EFI_SUCCESS - add return value to function comment
+{
+ if (Time->Year < 1998 ||
+ Time->Year > 2099 ||
+ Time->Month < 1 ||
+ Time->Month > 12 ||
+ (!DayValid (Time)) ||
+ Time->Hour > 23 ||
+ Time->Minute > 59 ||
+ Time->Second > 59 ||
+ Time->Nanosecond > 999999999 ||
+ (!(Time->TimeZone == EFI_UNSPECIFIED_TIMEZONE || (Time->TimeZone >= -1440 && Time->TimeZone <= 1440))) ||
+ (Time->Daylight & (~(EFI_TIME_ADJUST_DAYLIGHT | EFI_TIME_IN_DAYLIGHT)))
+ ) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return EFI_SUCCESS;
+}
+
+BOOLEAN
+DayValid (
+ IN EFI_TIME *Time
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Time - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+
+ static const INTN DayOfMonth[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+ if (Time->Day < 1 ||
+ Time->Day > DayOfMonth[Time->Month - 1] ||
+ (Time->Month == 2 && (!IsLeapYear (Time) && Time->Day > 28))
+ ) {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+BOOLEAN
+IsLeapYear (
+ IN EFI_TIME *Time
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Time - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ if (Time->Year % 4 == 0) {
+ if (Time->Year % 100 == 0) {
+ if (Time->Year % 400 == 0) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+ } else {
+ return TRUE;
+ }
+ } else {
+ return FALSE;
+ }
+}
diff --git a/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf
new file mode 100644
index 0000000000..e90e5290be
--- /dev/null
+++ b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf
@@ -0,0 +1,58 @@
+#/** @file
+# Unix Emulation Real time clock Architectural Protocol Driver as defined in TIANO
+#
+# This real time clock module simulates virtual device by time WinAPI.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = RealTimeClock
+ FILE_GUID = f3552032-8985-11db-8429-0040d02b1835
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeRealTimeClock
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ RealTimeClock.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ UnixLib
+ UefiDriverEntryPoint
+ UefiLib
+ DebugLib
+ BaseLib
+
+
+[Protocols]
+ gEfiRealTimeClockArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+
+
+[Depex]
+ TRUE
+
diff --git a/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.msa b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.msa
new file mode 100644
index 0000000000..d9a7166971
--- /dev/null
+++ b/UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.msa
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>RealTimeClock</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>f3552032-8985-11db-8429-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Unix Emulation Real time clock Architectural Protocol Driver as defined in TIANO</Abstract>
+ <Description>
+ This real time clock module simulates virtual device by time WinAPI.
+ </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>RealTimeClock</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <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>UnixLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>RealTimeClock.c</Filename>
+ <Filename>RealTimeClock.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>gEfiRealTimeClockArchProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>InitializeRealTimeClock</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/ResetRuntimeDxe/Reset.c b/UnixPkg/ResetRuntimeDxe/Reset.c
new file mode 100644
index 0000000000..ddec272c0d
--- /dev/null
+++ b/UnixPkg/ResetRuntimeDxe/Reset.c
@@ -0,0 +1,131 @@
+/*++
+
+Copyright (c) 2004 - 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:
+
+ Reset.c
+
+Abstract:
+
+ Reset Architectural Protocol as defined in Tiano under UNIX Emulation
+
+--*/
+
+#include "PiDxe.h"
+#include "UnixDxe.h"
+#include <Protocol/Reset.h>
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UnixLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+EFI_STATUS
+EFIAPI
+InitializeUnixReset (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+STATIC
+VOID
+EFIAPI
+UnixResetSystem (
+ IN EFI_RESET_TYPE ResetType,
+ IN EFI_STATUS ResetStatus,
+ IN UINTN DataSize,
+ IN CHAR16 *ResetData OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+InitializeUnixReset (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+/*++
+
+Routine Description:
+
+
+Arguments:
+
+ ImageHandle of the loaded driver
+ Pointer to the System Table
+
+Returns:
+
+ Status
+--*/
+// TODO: SystemTable - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+
+ SystemTable->RuntimeServices->ResetSystem = UnixResetSystem;
+
+ Handle = NULL;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Handle,
+ &gEfiResetArchProtocolGuid,
+ NULL,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return Status;
+}
+
+STATIC
+VOID
+EFIAPI
+UnixResetSystem (
+ IN EFI_RESET_TYPE ResetType,
+ IN EFI_STATUS ResetStatus,
+ IN UINTN DataSize,
+ IN CHAR16 *ResetData OPTIONAL
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ ResetType - TODO: add argument description
+ ResetStatus - TODO: add argument description
+ DataSize - TODO: add argument description
+ ResetData - TODO: add argument description
+
+Returns:
+
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ //
+ // BUGBUG Need to kill all console windows later
+ //
+ //
+ // Discard ResetType, always return 0 as exit code
+ //
+ gUnix->Exit (0);
+
+ //
+ // Should never go here
+ //
+ while (1)
+ ;
+}
diff --git a/UnixPkg/ResetRuntimeDxe/Reset.inf b/UnixPkg/ResetRuntimeDxe/Reset.inf
new file mode 100644
index 0000000000..5eb621ac1c
--- /dev/null
+++ b/UnixPkg/ResetRuntimeDxe/Reset.inf
@@ -0,0 +1,58 @@
+#/** @file
+# Unix Emulation Reset Architectural Protocol Driver as defined in TIANO
+#
+# This Reset module simulates system reset by process exit on NT.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = Reset
+ FILE_GUID = f3613084-8985-11db-8c26-0040d02b1835
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeUnixReset
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ Reset.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ UnixLib
+ UefiDriverEntryPoint
+ UefiLib
+ DebugLib
+ BaseLib
+
+
+[Protocols]
+ gEfiResetArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+
+
+[Depex]
+ TRUE
+
diff --git a/UnixPkg/ResetRuntimeDxe/Reset.msa b/UnixPkg/ResetRuntimeDxe/Reset.msa
new file mode 100644
index 0000000000..133a901333
--- /dev/null
+++ b/UnixPkg/ResetRuntimeDxe/Reset.msa
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>Reset</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>f3613084-8985-11db-8c26-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Unix Emulation Reset Architectural Protocol Driver as defined in TIANO</Abstract>
+ <Description>
+ This Reset module simulates system reset by process exit on NT.
+ </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>Reset</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <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>UnixLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>Reset.c</Filename>
+ <Filename>Reset.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>gEfiResetArchProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>InitializeUnixReset</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Sec/FwVol.c b/UnixPkg/Sec/FwVol.c
new file mode 100644
index 0000000000..7206e00fbe
--- /dev/null
+++ b/UnixPkg/Sec/FwVol.c
@@ -0,0 +1,314 @@
+/*++
+
+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:
+ FwVol.c
+
+Abstract:
+ A simple FV stack so the SEC can extract the SEC Core from an
+ FV.
+
+--*/
+
+#include "SecMain.h"
+
+#define GET_OCCUPIED_SIZE(ActualSize, Alignment) \
+ (ActualSize) + (((Alignment) - ((ActualSize) & ((Alignment) - 1))) & ((Alignment) - 1))
+
+EFI_FFS_FILE_STATE
+GetFileState (
+ IN UINT8 ErasePolarity,
+ IN EFI_FFS_FILE_HEADER *FfsHeader
+ )
+/*++
+
+Routine Description:
+ Returns the highest bit set of the State field
+
+Arguments:
+ ErasePolarity - Erase Polarity as defined by EFI_FVB2_ERASE_POLARITY
+ in the Attributes field.
+ FfsHeader - Pointer to FFS File Header.
+
+Returns:
+ Returns the highest bit in the State field
+
+--*/
+{
+ EFI_FFS_FILE_STATE FileState;
+ EFI_FFS_FILE_STATE HighestBit;
+
+ FileState = FfsHeader->State;
+
+ if (ErasePolarity != 0) {
+ FileState = (EFI_FFS_FILE_STATE)~FileState;
+ }
+
+ HighestBit = 0x80;
+ while (HighestBit != 0 && (HighestBit & FileState) == 0) {
+ HighestBit >>= 1;
+ }
+
+ return HighestBit;
+}
+
+UINT8
+CalculateHeaderChecksum (
+ IN EFI_FFS_FILE_HEADER *FileHeader
+ )
+/*++
+
+Routine Description:
+ Calculates the checksum of the header of a file.
+
+Arguments:
+ FileHeader - Pointer to FFS File Header.
+
+Returns:
+ Checksum of the header.
+
+--*/
+{
+ UINT8 *ptr;
+ UINTN Index;
+ UINT8 Sum;
+
+ Sum = 0;
+ ptr = (UINT8 *) FileHeader;
+
+ for (Index = 0; Index < sizeof (EFI_FFS_FILE_HEADER) - 3; Index += 4) {
+ Sum = (UINT8) (Sum + ptr[Index]);
+ Sum = (UINT8) (Sum + ptr[Index + 1]);
+ Sum = (UINT8) (Sum + ptr[Index + 2]);
+ Sum = (UINT8) (Sum + ptr[Index + 3]);
+ }
+
+ for (; Index < sizeof (EFI_FFS_FILE_HEADER); Index++) {
+ Sum = (UINT8) (Sum + ptr[Index]);
+ }
+ //
+ // State field (since this indicates the different state of file).
+ //
+ Sum = (UINT8) (Sum - FileHeader->State);
+ //
+ // Checksum field of the file is not part of the header checksum.
+ //
+ Sum = (UINT8) (Sum - FileHeader->IntegrityCheck.Checksum.File);
+
+ return Sum;
+}
+
+EFI_STATUS
+SecFfsFindNextFile (
+ IN EFI_FV_FILETYPE SearchType,
+ IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
+ IN OUT EFI_FFS_FILE_HEADER **FileHeader
+ )
+/*++
+
+Routine Description:
+ Given the input file pointer, search for the next matching file in the
+ FFS volume as defined by SearchType. The search starts from FileHeader inside
+ the Firmware Volume defined by FwVolHeader.
+
+Arguments:
+ SearchType - Filter to find only files of this type.
+ Type EFI_FV_FILETYPE_ALL causes no filtering to be done.
+ FwVolHeader - Pointer to the FV header of the volume to search.
+ This parameter must point to a valid FFS volume.
+ FileHeader - Pointer to the current file from which to begin searching.
+ This pointer will be updated upon return to reflect the file
+ found.
+
+Returns:
+ EFI_NOT_FOUND - No files matching the search criteria were found
+ EFI_SUCCESS
+
+--*/
+{
+ EFI_FFS_FILE_HEADER *FfsFileHeader;
+ UINT32 FileLength;
+ UINT32 FileOccupiedSize;
+ UINT32 FileOffset;
+ UINT64 FvLength;
+ UINT8 ErasePolarity;
+ UINT8 FileState;
+
+ FvLength = FwVolHeader->FvLength;
+ if (FwVolHeader->Attributes & EFI_FVB2_ERASE_POLARITY) {
+ ErasePolarity = 1;
+ } else {
+ ErasePolarity = 0;
+ }
+ //
+ // If FileHeader is not specified (NULL) start with the first file in the
+ // firmware volume. Otherwise, start from the FileHeader.
+ //
+ if (*FileHeader == NULL) {
+ FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FwVolHeader + FwVolHeader->HeaderLength);
+ } else {
+ //
+ // Length is 24 bits wide so mask upper 8 bits
+ // FileLength is adjusted to FileOccupiedSize as it is 8 byte aligned.
+ //
+ FileLength = *(UINT32 *) (*FileHeader)->Size & 0x00FFFFFF;
+ FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
+ FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) *FileHeader + FileOccupiedSize);
+ }
+
+ FileOffset = (UINT32) ((UINT8 *) FfsFileHeader - (UINT8 *) FwVolHeader);
+
+ while (FileOffset < (FvLength - sizeof (EFI_FFS_FILE_HEADER))) {
+ //
+ // Get FileState which is the highest bit of the State
+ //
+ FileState = GetFileState (ErasePolarity, FfsFileHeader);
+
+ switch (FileState) {
+
+ case EFI_FILE_HEADER_INVALID:
+ FileOffset += sizeof (EFI_FFS_FILE_HEADER);
+ FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + sizeof (EFI_FFS_FILE_HEADER));
+ break;
+
+ case EFI_FILE_DATA_VALID:
+ case EFI_FILE_MARKED_FOR_UPDATE:
+ if (CalculateHeaderChecksum (FfsFileHeader) == 0) {
+ FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;
+ FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
+
+ if ((SearchType == FfsFileHeader->Type) || (SearchType == EFI_FV_FILETYPE_ALL)) {
+
+ *FileHeader = FfsFileHeader;
+
+ return EFI_SUCCESS;
+ }
+
+ FileOffset += FileOccupiedSize;
+ FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);
+ } else {
+ return EFI_NOT_FOUND;
+ }
+ break;
+
+ case EFI_FILE_DELETED:
+ FileLength = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;
+ FileOccupiedSize = GET_OCCUPIED_SIZE (FileLength, 8);
+ FileOffset += FileOccupiedSize;
+ FfsFileHeader = (EFI_FFS_FILE_HEADER *) ((UINT8 *) FfsFileHeader + FileOccupiedSize);
+ break;
+
+ default:
+ return EFI_NOT_FOUND;
+
+ }
+ }
+
+ return EFI_NOT_FOUND;
+}
+
+EFI_STATUS
+SecFfsFindSectionData (
+ IN EFI_SECTION_TYPE SectionType,
+ IN EFI_FFS_FILE_HEADER *FfsFileHeader,
+ IN OUT VOID **SectionData
+ )
+/*++
+
+Routine Description:
+ Given the input file pointer, search for the next matching section in the
+ FFS volume.
+
+Arguments:
+ SearchType - Filter to find only sections of this type.
+ FfsFileHeader - Pointer to the current file to search.
+ SectionData - Pointer to the Section matching SectionType in FfsFileHeader.
+ NULL if section not found
+
+Returns:
+ EFI_NOT_FOUND - No files matching the search criteria were found
+ EFI_SUCCESS
+
+--*/
+{
+ UINT32 FileSize;
+ EFI_COMMON_SECTION_HEADER *Section;
+ UINT32 SectionLength;
+ UINT32 ParsedLength;
+
+ //
+ // Size is 24 bits wide so mask upper 8 bits.
+ // Does not include FfsFileHeader header size
+ // FileSize is adjusted to FileOccupiedSize as it is 8 byte aligned.
+ //
+ Section = (EFI_COMMON_SECTION_HEADER *) (FfsFileHeader + 1);
+ FileSize = *(UINT32 *) (FfsFileHeader->Size) & 0x00FFFFFF;
+ FileSize -= sizeof (EFI_FFS_FILE_HEADER);
+
+ *SectionData = NULL;
+ ParsedLength = 0;
+ while (ParsedLength < FileSize) {
+ if (Section->Type == SectionType) {
+ *SectionData = (VOID *) (Section + 1);
+ return EFI_SUCCESS;
+ }
+ //
+ // Size is 24 bits wide so mask upper 8 bits.
+ // SectionLength is adjusted it is 4 byte aligned.
+ // Go to the next section
+ //
+ SectionLength = *(UINT32 *) Section->Size & 0x00FFFFFF;
+ SectionLength = GET_OCCUPIED_SIZE (SectionLength, 4);
+
+ ParsedLength += SectionLength;
+ Section = (EFI_COMMON_SECTION_HEADER *) ((UINT8 *) Section + SectionLength);
+ }
+
+ return EFI_NOT_FOUND;
+}
+
+EFI_STATUS
+SecFfsFindPeiCore (
+ IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
+ OUT VOID **Pe32Data
+ )
+/*++
+
+Routine Description:
+ Given the pointer to the Firmware Volume Header find the SEC
+ core and return it's PE32 image.
+
+Arguments:
+ FwVolHeader - Pointer to memory mapped FV
+ Pe32Data - Pointer to SEC PE32 iamge.
+
+Returns:
+ EFI_SUCCESS - Pe32Data is valid
+ other - Failure
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_FFS_FILE_HEADER *FileHeader;
+ EFI_FV_FILETYPE SearchType;
+
+ SearchType = EFI_FV_FILETYPE_PEI_CORE;
+ FileHeader = NULL;
+ do {
+ Status = SecFfsFindNextFile (SearchType, FwVolHeader, &FileHeader);
+ if (!EFI_ERROR (Status)) {
+ Status = SecFfsFindSectionData (EFI_SECTION_PE32, FileHeader, Pe32Data);
+ return Status;
+ }
+ } while (!EFI_ERROR (Status));
+
+ return Status;
+}
diff --git a/UnixPkg/Sec/SecMain.c b/UnixPkg/Sec/SecMain.c
new file mode 100644
index 0000000000..a6da20b135
--- /dev/null
+++ b/UnixPkg/Sec/SecMain.c
@@ -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
index 0000000000..9714b5a4b9
--- /dev/null
+++ b/UnixPkg/Sec/SecMain.h
@@ -0,0 +1,548 @@
+/*++
+
+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:
+ SecMain.h
+
+Abstract:
+ Include file for host API based SEC
+
+--*/
+#include "PiPei.h"
+#include "Uefi/UefiSpec.h"
+
+#include <Protocol/UnixThunk.h>
+#include <Pi/PiFirmwareVolume.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>
+
+#define STACK_SIZE 0x20000
+
+typedef struct {
+ EFI_PHYSICAL_ADDRESS Address;
+ UINT64 Size;
+} UNIX_FD_INFO;
+
+typedef struct {
+ EFI_PHYSICAL_ADDRESS Memory;
+ UINT64 Size;
+} UNIX_SYSTEM_MEMORY;
+
+
+
+EFI_STATUS
+EFIAPI
+SecWinNtPeiLoadFile (
+ VOID *Pe32Data, // TODO: add IN/OUT modifier to Pe32Data
+ EFI_PHYSICAL_ADDRESS *ImageAddress, // TODO: add IN/OUT modifier to ImageAddress
+ UINT64 *ImageSize, // TODO: add IN/OUT modifier to ImageSize
+ EFI_PHYSICAL_ADDRESS *EntryPoint // TODO: add IN/OUT modifier to EntryPoint
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Pe32Data - TODO: add argument description
+ ImageAddress - TODO: add argument description
+ ImageSize - TODO: add argument description
+ EntryPoint - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+SecWinNtPeiAutoScan (
+ IN UINTN Index,
+ OUT EFI_PHYSICAL_ADDRESS *MemoryBase,
+ OUT UINT64 *MemorySize
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Index - TODO: add argument description
+ MemoryBase - TODO: add argument description
+ MemorySize - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+VOID *
+EFIAPI
+SecWinNtWinNtThunkAddress (
+ VOID
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ InterfaceSize - TODO: add argument description
+ InterfaceBase - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+SecWinNtWinNtFwhAddress (
+ IN OUT UINT64 *FwhSize,
+ IN OUT EFI_PHYSICAL_ADDRESS *FwhBase
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ FwhSize - TODO: add argument description
+ FwhBase - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+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:
+
+ TODO: Add function description
+
+Arguments:
+
+ PeiServices - TODO: add argument description
+ CodeType - TODO: add argument description
+ Value - TODO: add argument description
+ Instance - TODO: add argument description
+ CallerId - TODO: add argument description
+ Data - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+INTN
+EFIAPI
+main (
+ IN INTN Argc,
+ IN CHAR8 **Argv,
+ IN CHAR8 **Envp
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Argc - TODO: add argument description
+ Argv - TODO: add argument description
+ Envp - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+VOID
+SecLoadFromCore (
+ IN UINTN LargestRegion,
+ IN UINTN LargestRegionSize,
+ IN UINTN BootFirmwareVolumeBase,
+ IN VOID *PeiCoreFile
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ LargestRegion - TODO: add argument description
+ LargestRegionSize - TODO: add argument description
+ BootFirmwareVolumeBase - TODO: add argument description
+ PeiCoreFile - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+SecLoadFile (
+ IN VOID *Pe32Data,
+ IN EFI_PHYSICAL_ADDRESS *ImageAddress,
+ IN UINT64 *ImageSize,
+ IN EFI_PHYSICAL_ADDRESS *EntryPoint
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Pe32Data - TODO: add argument description
+ ImageAddress - TODO: add argument description
+ ImageSize - TODO: add argument description
+ EntryPoint - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+SecFfsFindPeiCore (
+ IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
+ OUT VOID **Pe32Data
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ FwVolHeader - TODO: add argument description
+ Pe32Data - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+SecFfsFindNextFile (
+ IN EFI_FV_FILETYPE SearchType,
+ IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
+ IN OUT EFI_FFS_FILE_HEADER **FileHeader
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ SearchType - TODO: add argument description
+ FwVolHeader - TODO: add argument description
+ FileHeader - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+SecFfsFindSectionData (
+ IN EFI_SECTION_TYPE SectionType,
+ IN EFI_FFS_FILE_HEADER *FfsFileHeader,
+ IN OUT VOID **SectionData
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ SectionType - TODO: add argument description
+ FfsFileHeader - TODO: add argument description
+ SectionData - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+SecWinNtPeCoffLoaderLoadAsDll (
+ IN CHAR8 *PdbFileName,
+ IN VOID **ImageEntryPoint,
+ OUT VOID **ModHandle
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ PdbFileName - TODO: add argument description
+ ImageEntryPoint - TODO: add argument description
+ ModHandle - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+SecWinNtPeCoffLoaderFreeLibrary (
+ OUT VOID *ModHandle
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ ModHandle - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+SecWinNtFdAddress (
+ IN UINTN Index,
+ IN OUT EFI_PHYSICAL_ADDRESS *FdBase,
+ IN OUT UINT64 *FdSize
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Index - TODO: add argument description
+ FdBase - TODO: add argument description
+ FdSize - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+GetImageReadFunction (
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
+ IN EFI_PHYSICAL_ADDRESS *TopOfMemory
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ ImageContext - TODO: add argument description
+ TopOfMemory - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+SecImageRead (
+ IN VOID *FileHandle,
+ IN UINTN FileOffset,
+ IN OUT UINTN *ReadSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ FileHandle - TODO: add argument description
+ FileOffset - TODO: add argument description
+ ReadSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+CHAR16 *
+AsciiToUnicode (
+ IN CHAR8 *Ascii,
+ IN UINTN *StrLen OPTIONAL
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Ascii - TODO: add argument description
+ StrLen - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+UINTN
+CountSeperatorsInString (
+ IN const CHAR16 *String,
+ IN CHAR16 Seperator
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ String - TODO: add argument description
+ Seperator - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffGetImageInfo (
+ IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ );
+
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffLoadImage (
+ IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ );
+
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffRelocateImage (
+ IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
+ IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ );
+
+EFI_STATUS
+EFIAPI
+SecNt32PeCoffUnloadimage (
+ IN EFI_PEI_PE_COFF_LOADER_PROTOCOL *This,
+ IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
+ );
+
+EFI_STATUS
+EFIAPI
+SecTemporaryRamSupport (
+ IN CONST EFI_PEI_SERVICES **PeiServices,
+ IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
+ IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
+ IN UINTN CopySize
+ );
+
+typedef struct {
+ EFI_PEI_PE_COFF_LOADER_PROTOCOL PeCoff;
+ VOID *ModHandle;
+} EFI_PEI_PE_COFF_LOADER_PROTOCOL_INSTANCE;
+
+extern EFI_UNIX_THUNK_PROTOCOL *gUnix;
diff --git a/UnixPkg/Sec/SecMain.inf b/UnixPkg/Sec/SecMain.inf
new file mode 100644
index 0000000000..37152b08e7
--- /dev/null
+++ b/UnixPkg/Sec/SecMain.inf
@@ -0,0 +1,76 @@
+#/** @file
+# Entry Point of Unix Emulator
+#
+# Main executable file of Unix Emulator that loads PEI core after initialization finished.
+# Copyright (c) 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = SecMain
+ FILE_GUID = f43be88c-8985-11db-8f78-0040d02b1835
+ MODULE_TYPE = SEC
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+ ENTRY_POINT = main
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ UgaX11.c
+ UnixThunk.c
+ FwVol.c
+ SecMain.c
+ Stack.S
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ DebugLib
+ PcdLib
+ PrintLib
+ BaseMemoryLib
+ BaseLib
+ PeCoffLib
+ ReportStatusCodeLib
+
+
+[Guids]
+ gEfiPeiPeCoffLoaderGuid # ALWAYS_PRODUCED
+
+
+[Ppis]
+ gUnixPeiLoadFilePpiGuid # PPI ALWAYS_PRODUCED
+ gEfiPeiStatusCodePpiGuid # PPI ALWAYS_PRODUCED
+ gUnixFwhPpiGuid # PPI ALWAYS_PRODUCED
+ gPeiUnixAutoScanPpiGuid # PPI ALWAYS_PRODUCED
+ gPeiUnixThunkPpiGuid # PPI ALWAYS_PRODUCED
+ gEfiTemporaryRamSupportPpiGuid
+
+
+[Pcd.common]
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixBootMode
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareVolume
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySizeForSecMain
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize
+
+[BuildOptions.common]
+ GCC:*_*_IA32_DLINK_FLAGS =
diff --git a/UnixPkg/Sec/SecMain.msa b/UnixPkg/Sec/SecMain.msa
new file mode 100644
index 0000000000..2629982571
--- /dev/null
+++ b/UnixPkg/Sec/SecMain.msa
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>SecMain</ModuleName>
+ <ModuleType>SEC</ModuleType>
+ <GuidValue>f43be88c-8985-11db-8f78-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Entry Point of Unix Emulator</Abstract>
+ <Description>Main executable file of Unix Emulator that loads PEI core after initialization finished.</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>SecMain</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PeCoffLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PrintLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PcdLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename ToolCode="DUMMY">SecMain_build.xml</Filename>
+ <Filename>SecMain.c</Filename>
+ <Filename>FwVol.c</Filename>
+ <Filename>UnixThunk.c</Filename>
+ <Filename>UgaX11.c</Filename>
+ <Filename>SecMain.h</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_PRODUCED">
+ <PpiCName>gPeiUnixThunkPpiGuid</PpiCName>
+ </Ppi>
+ <Ppi Usage="ALWAYS_PRODUCED">
+ <PpiCName>gPeiUnixAutoScanPpiGuid</PpiCName>
+ </Ppi>
+ <Ppi Usage="ALWAYS_PRODUCED">
+ <PpiCName>gUnixFwhPpiGuid</PpiCName>
+ </Ppi>
+ <Ppi Usage="ALWAYS_PRODUCED">
+ <PpiCName>gEfiPeiStatusCodePpiGuid</PpiCName>
+ </Ppi>
+ <Ppi Usage="ALWAYS_PRODUCED">
+ <PpiCName>gUnixPeiLoadFilePpiGuid</PpiCName>
+ </Ppi>
+ </PPIs>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_PRODUCED">
+ <GuidCName>gEfiPeiPeCoffLoaderGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ </Externs>
+ <PcdCoded>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixMemorySizeForSecMain</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>This PCD defines the memory size of simulated machine. Simulator will allocate
+ the size of PcdUnixMemorySizeForSecMain in host platform.</HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixFirmwareVolume</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>This PCD defines the FD file windows path string. Simulator will load the FD file and execute.</HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixBootMode</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>This PCD defines the boot mode for simualtor.
+ The boot mode can be set as following value:
+ 0x0: Boot with full configuration.
+ 0x1: Boot with minimal configuration.
+ 0x2: Boot assume no configuration changes.
+ 0x3: Boot with full configuration plus diagnostics.
+ 0x4: Boot with default settings.
+ 0x5: Boot on S4 resume.
+ 0x6: Boot on S5 resume.
+ 0x10: Boot on S2 resume.
+ 0x11: Boot on S3 resume.
+ 0x12: Boot on flash update.
+ 0x20: Boot in reovery mode.</HelpText>
+ </PcdEntry>
+ </PcdCoded>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/Sec/Stack.S b/UnixPkg/Sec/Stack.S
new file mode 100644
index 0000000000..50f07b0894
--- /dev/null
+++ b/UnixPkg/Sec/Stack.S
@@ -0,0 +1,92 @@
+#------------------------------------------------------------------------------
+#
+# Copyright (c) 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:
+#
+# Stack.asm
+#
+# Abstract:
+#
+# Switch the stack from temporary memory to permenent memory.
+#
+#------------------------------------------------------------------------------
+
+#------------------------------------------------------------------------------
+# VOID
+# EFIAPI
+# SecSwitchStack (
+# UINT32 TemporaryMemoryBase,
+# UINT32 PermenentMemoryBase
+# );
+#------------------------------------------------------------------------------
+
+#include <ProcessorBind.h>
+
+.globl ASM_PFX(SecSwitchStack)
+ASM_PFX(SecSwitchStack):
+#
+# Save three register: eax, ebx, ecx
+#
+ push %eax
+ push %ebx
+ push %ecx
+ push %edx
+
+#
+# !!CAUTION!! this function address's is pushed into stack after
+# migration of whole temporary memory, so need save it to permenent
+# memory at first!
+#
+
+ movl 20(%esp), %ebx # Save the first parameter
+ movl 24(%esp), %ecx # Save the second parameter
+
+#
+# Save this function's return address into permenent memory at first.
+# Then, Fixup the esp point to permenent memory
+#
+
+ movl %esp, %eax
+ subl %ebx, %eax
+ addl %ecx, %eax
+ movl (%esp), %edx # copy pushed register's value to permenent memory
+ movl %edx, (%eax)
+ movl 4(%esp), %edx
+ movl %edx, 4(%eax)
+ movl 8(%esp), %edx
+ movl %edx, 8(%eax)
+ movl 12(%esp), %edx
+ movl %edx, 12(%eax)
+ movl 16(%esp), %edx
+ movl %edx, 16(%eax)
+ movl %eax, %esp # From now, esp is pointed to permenent memory
+
+#
+# Fixup the ebp point to permenent memory
+#
+ movl %ebp, %eax
+ subl %ebx, %eax
+ addl %ecx, %eax
+ movl %eax, %ebp # From now, ebp is pointed to permenent memory
+
+#
+# Fixup callee's ebp point for PeiDispatch
+#
+ movl (%ebp), %eax
+ subl %ebx, %eax
+ addl %ecx, %eax
+ movl %eax, (%ebp) # From now, Temporary's PPI caller's stack is in permenent memory
+
+ pop %edx
+ pop %ecx
+ pop %ebx
+ pop %eax
+ ret
diff --git a/UnixPkg/Sec/UgaX11.c b/UnixPkg/Sec/UgaX11.c
new file mode 100644
index 0000000000..b096dc660d
--- /dev/null
+++ b/UnixPkg/Sec/UgaX11.c
@@ -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;
+ Key.UnicodeChar = 0;
+ switch (keysym) {
+ case XK_Home: Key.ScanCode = SCAN_HOME; break;
+ case XK_End: Key.ScanCode = SCAN_END; break;
+ case XK_Left: Key.ScanCode = SCAN_LEFT; break;
+ case XK_Right: Key.ScanCode = SCAN_RIGHT; break;
+ case XK_Up: Key.ScanCode = SCAN_UP; break;
+ case XK_Down: Key.ScanCode = SCAN_DOWN; break;
+ case XK_Delete: Key.ScanCode = SCAN_DELETE; break;
+ case XK_Insert: Key.ScanCode = SCAN_INSERT; break;
+ case XK_Page_Up: Key.ScanCode = SCAN_PAGE_UP; break;
+ case XK_Page_Down: Key.ScanCode = SCAN_PAGE_DOWN; break;
+ case XK_Escape: Key.ScanCode = SCAN_ESC; break;
+
+ case XK_F1: Key.ScanCode = SCAN_F1; break;
+ case XK_F2: Key.ScanCode = SCAN_F2; break;
+ case XK_F3: Key.ScanCode = SCAN_F3; break;
+ case XK_F4: Key.ScanCode = SCAN_F4; break;
+ case XK_F5: Key.ScanCode = SCAN_F5; break;
+ case XK_F6: Key.ScanCode = SCAN_F6; break;
+ case XK_F7: Key.ScanCode = SCAN_F7; break;
+ case XK_F8: Key.ScanCode = SCAN_F8; break;
+ case XK_F9: Key.ScanCode = SCAN_F9; break;
+
+ default:
+ if (res == 1) {
+ Key.UnicodeChar = str[0];
+ } else {
+ return;
+ }
+ }
+
+ 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
+UgaBlt(EFI_UNIX_UGA_IO_PROTOCOL *UgaIo,
+ 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
+ )
+{
+ UGA_IO_PRIVATE *Private = (UGA_IO_PRIVATE *)UgaIo;
+ UINTN DstY;
+ UINTN SrcY;
+ UINTN DstX;
+ UINTN SrcX;
+ UINTN Index;
+ EFI_UGA_PIXEL *Blt;
+ UINT8 *Dst;
+ UINT8 *Src;
+ UINTN Nbr;
+ unsigned long Color;
+
+ //
+ // Check bounds
+ //
+ if (BltOperation == EfiUgaVideoToBltBuffer
+ || BltOperation == EfiUgaVideoToVideo) {
+ //
+ // Source is Video.
+ //
+ if (SourceY + Height > Private->height) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (SourceX + Width > Private->width) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
+ if (BltOperation == EfiUgaBltBufferToVideo
+ || BltOperation == EfiUgaVideoToVideo
+ || BltOperation == EfiUgaVideoFill) {
+ //
+ // Destination is Video
+ //
+ if (DestinationY + Height > Private->height) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (DestinationX + Width > Private->width) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
+ switch (BltOperation) {
+ case EfiUgaVideoToBltBuffer:
+ Blt = BltBuffer;
+ Delta -= Width * sizeof (EFI_UGA_PIXEL);
+ for (SrcY = SourceY; SrcY < (Height + SourceY); SrcY++) {
+ for (SrcX = SourceX; SrcX < (Width + SourceX); SrcX++) {
+ *Blt++ = UgaColorToPixel(Private,
+ XGetPixel(Private->image, SrcX, SrcY));
+ }
+ Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Delta);
+ }
+ break;
+ case EfiUgaBltBufferToVideo:
+ Blt = BltBuffer;
+ Delta -= Width * sizeof (EFI_UGA_PIXEL);
+ for (DstY = DestinationY; DstY < (Height + DestinationY); DstY++) {
+ for (DstX = DestinationX; DstX < (Width + DestinationX); DstX++) {
+ XPutPixel(Private->image, DstX, DstY, UgaPixelToColor(Private, *Blt));
+ Blt++;
+ }
+ Blt = (EFI_UGA_PIXEL *) ((UINT8 *) Blt + Delta);
+ }
+ break;
+ case EfiUgaVideoToVideo:
+ 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) {
+ 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++) {
+ for (DstX = DestinationX; DstX < (Width + DestinationX); DstX++) {
+ XPutPixel(Private->image, DstX, DstY, Color);
+ }
+ }
+ break;
+ default:
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Refresh screen.
+ //
+ switch (BltOperation) {
+ case EfiUgaVideoToVideo:
+ 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:
+ 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
index 0000000000..500568ad52
--- /dev/null
+++ b/UnixPkg/Sec/UnixThunk.c
@@ -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
index 0000000000..53b5656f7c
--- /dev/null
+++ b/UnixPkg/TimerDxe/Timer.c
@@ -0,0 +1,374 @@
+/*++
+
+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:
+
+ Timer.c
+
+Abstract:
+
+ UNIX Emulation Timer Architectural Protocol Driver as defined in DXE CIS
+
+ This Timer module uses an UNIX Thread to simulate the timer-tick driven
+ timer service. In the future, the Thread creation should possibly be
+ abstracted by the CPU architectural protocol
+
+--*/
+#include "PiDxe.h"
+#include <Protocol/Timer.h>
+#include <Protocol/Cpu.h>
+#include "Timer.h"
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include "UnixDxe.h"
+#include <Library/UnixLib.h>
+
+//
+// Pointer to the CPU Architectural Protocol instance
+//
+EFI_CPU_ARCH_PROTOCOL *mCpu;
+
+//
+// The Timer Architectural Protocol that this driver produces
+//
+EFI_TIMER_ARCH_PROTOCOL mTimer = {
+ UnixTimerDriverRegisterHandler,
+ UnixTimerDriverSetTimerPeriod,
+ UnixTimerDriverGetTimerPeriod,
+ UnixTimerDriverGenerateSoftInterrupt
+};
+
+//
+// The notification function to call on every timer interrupt
+//
+EFI_TIMER_NOTIFY mTimerNotifyFunction = NULL;
+
+//
+// The current period of the timer interrupt
+//
+UINT64 mTimerPeriodMs;
+
+
+VOID
+TimerCallback (UINT64 DeltaMs)
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ wTimerID - TODO: add argument description
+ msg - TODO: add argument description
+ dwUser - TODO: add argument description
+ dw1 - TODO: add argument description
+ dw2 - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ EFI_TPL OriginalTPL;
+ EFI_TIMER_NOTIFY CallbackFunction;
+
+
+ OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
+
+ if (OriginalTPL < TPL_HIGH_LEVEL) {
+ CallbackFunction = mTimerNotifyFunction;
+
+ //
+ // Only invoke the callback function if a Non-NULL handler has been
+ // registered. Assume all other handlers are legal.
+ //
+ if (CallbackFunction != NULL) {
+ CallbackFunction ((UINT64) (DeltaMs * 10000));
+ }
+ }
+
+ gBS->RestoreTPL (OriginalTPL);
+
+}
+
+EFI_STATUS
+EFIAPI
+UnixTimerDriverRegisterHandler (
+ IN EFI_TIMER_ARCH_PROTOCOL *This,
+ IN EFI_TIMER_NOTIFY NotifyFunction
+ )
+/*++
+
+Routine Description:
+
+ This function registers the handler NotifyFunction so it is called every time
+ the timer interrupt fires. It also passes the amount of time since the last
+ handler call to the NotifyFunction. If NotifyFunction is NULL, then the
+ handler is unregistered. If the handler is registered, then EFI_SUCCESS is
+ returned. If the CPU does not support registering a timer interrupt handler,
+ then EFI_UNSUPPORTED is returned. If an attempt is made to register a handler
+ when a handler is already registered, then EFI_ALREADY_STARTED is returned.
+ If an attempt is made to unregister a handler when a handler is not registered,
+ then EFI_INVALID_PARAMETER is returned. If an error occurs attempting to
+ register the NotifyFunction with the timer interrupt, then EFI_DEVICE_ERROR
+ is returned.
+
+Arguments:
+
+ This - The EFI_TIMER_ARCH_PROTOCOL instance.
+
+ NotifyFunction - The function to call when a timer interrupt fires. This
+ function executes at TPL_HIGH_LEVEL. The DXE Core will
+ register a handler for the timer interrupt, so it can know
+ how much time has passed. This information is used to
+ signal timer based events. NULL will unregister the handler.
+
+Returns:
+
+ EFI_SUCCESS - The timer handler was registered.
+
+ EFI_UNSUPPORTED - The platform does not support timer interrupts.
+
+ EFI_ALREADY_STARTED - NotifyFunction is not NULL, and a handler is already
+ registered.
+
+ EFI_INVALID_PARAMETER - NotifyFunction is NULL, and a handler was not
+ previously registered.
+
+ EFI_DEVICE_ERROR - The timer handler could not be registered.
+
+--*/
+{
+ //
+ // Check for invalid parameters
+ //
+ if (NotifyFunction == NULL && mTimerNotifyFunction == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (NotifyFunction != NULL && mTimerNotifyFunction != NULL) {
+ return EFI_ALREADY_STARTED;
+ }
+
+ if (NotifyFunction == NULL) {
+ /* Disable timer. */
+ gUnix->SetTimer (0, TimerCallback);
+ } else if (mTimerNotifyFunction == NULL) {
+ /* Enable Timer. */
+ gUnix->SetTimer (mTimerPeriodMs, TimerCallback);
+ }
+ mTimerNotifyFunction = NotifyFunction;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixTimerDriverSetTimerPeriod (
+ IN EFI_TIMER_ARCH_PROTOCOL *This,
+ IN UINT64 TimerPeriod
+ )
+/*++
+
+Routine Description:
+
+ This function adjusts the period of timer interrupts to the value specified
+ by TimerPeriod. If the timer period is updated, then the selected timer
+ period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If
+ the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
+ If an error occurs while attempting to update the timer period, then the
+ timer hardware will be put back in its state prior to this call, and
+ EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt
+ is disabled. This is not the same as disabling the CPU's interrupts.
+ Instead, it must either turn off the timer hardware, or it must adjust the
+ interrupt controller so that a CPU interrupt is not generated when the timer
+ interrupt fires.
+
+Arguments:
+
+ This - The EFI_TIMER_ARCH_PROTOCOL instance.
+
+ TimerPeriod - The rate to program the timer interrupt in 100 nS units. If
+ the timer hardware is not programmable, then EFI_UNSUPPORTED is
+ returned. If the timer is programmable, then the timer period
+ will be rounded up to the nearest timer period that is supported
+ by the timer hardware. If TimerPeriod is set to 0, then the
+ timer interrupts will be disabled.
+
+Returns:
+
+ EFI_SUCCESS - The timer period was changed.
+
+ EFI_UNSUPPORTED - The platform cannot change the period of the timer interrupt.
+
+ EFI_DEVICE_ERROR - The timer period could not be changed due to a device error.
+
+--*/
+{
+
+ //
+ // If TimerPeriod is 0, then the timer thread should be canceled
+ // If the TimerPeriod is valid, then create and/or adjust the period of the timer thread
+ //
+ if (TimerPeriod == 0
+ || ((TimerPeriod > TIMER_MINIMUM_VALUE)
+ && (TimerPeriod < TIMER_MAXIMUM_VALUE))) {
+ mTimerPeriodMs = DivU64x32 (TimerPeriod + 5000, 10000);
+
+ gUnix->SetTimer (mTimerPeriodMs, TimerCallback);
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixTimerDriverGetTimerPeriod (
+ IN EFI_TIMER_ARCH_PROTOCOL *This,
+ OUT UINT64 *TimerPeriod
+ )
+/*++
+
+Routine Description:
+
+ This function retrieves the period of timer interrupts in 100 ns units,
+ returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod
+ is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is
+ returned, then the timer is currently disabled.
+
+Arguments:
+
+ This - The EFI_TIMER_ARCH_PROTOCOL instance.
+
+ TimerPeriod - A pointer to the timer period to retrieve in 100 ns units. If
+ 0 is returned, then the timer is currently disabled.
+
+Returns:
+
+ EFI_SUCCESS - The timer period was returned in TimerPeriod.
+
+ EFI_INVALID_PARAMETER - TimerPeriod is NULL.
+
+--*/
+{
+ if (TimerPeriod == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *TimerPeriod = mTimerPeriodMs * 10000;
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixTimerDriverGenerateSoftInterrupt (
+ IN EFI_TIMER_ARCH_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ This function generates a soft timer interrupt. If the platform does not support soft
+ timer interrupts, then EFI_UNSUPPORTED is returned. Otherwise, EFI_SUCCESS is returned.
+ If a handler has been registered through the EFI_TIMER_ARCH_PROTOCOL.RegisterHandler()
+ service, then a soft timer interrupt will be generated. If the timer interrupt is
+ enabled when this service is called, then the registered handler will be invoked. The
+ registered handler should not be able to distinguish a hardware-generated timer
+ interrupt from a software-generated timer interrupt.
+
+Arguments:
+
+ This - The EFI_TIMER_ARCH_PROTOCOL instance.
+
+Returns:
+
+ EFI_SUCCESS - The soft timer interrupt was generated.
+
+ EFI_UNSUPPORTEDT - The platform does not support the generation of soft timer interrupts.
+
+--*/
+{
+ return EFI_UNSUPPORTED;
+}
+
+EFI_STATUS
+EFIAPI
+UnixTimerDriverInitialize (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+/*++
+
+Routine Description:
+
+ Initialize the Timer Architectural Protocol driver
+
+Arguments:
+
+ ImageHandle - ImageHandle of the loaded driver
+
+ SystemTable - Pointer to the System Table
+
+Returns:
+
+ EFI_SUCCESS - Timer Architectural Protocol created
+
+ EFI_OUT_OF_RESOURCES - Not enough resources available to initialize driver.
+
+ EFI_DEVICE_ERROR - A device error occured attempting to initialize the driver.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_HANDLE Handle;
+
+ //
+ // Make sure the Timer Architectural Protocol is not already installed in the system
+ //
+ ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiTimerArchProtocolGuid);
+
+ //
+ // Get the CPU Architectural Protocol instance
+ //
+ Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (void *)&mCpu);
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Install the Timer Architectural Protocol onto a new handle
+ //
+ Handle = NULL;
+ Status = gBS->InstallProtocolInterface (
+ &Handle,
+ &gEfiTimerArchProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mTimer
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Start the timer thread at the default timer period
+ //
+ Status = mTimer.SetTimerPeriod (&mTimer, DEFAULT_TIMER_TICK_DURATION);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/TimerDxe/Timer.h b/UnixPkg/TimerDxe/Timer.h
new file mode 100644
index 0000000000..230fead608
--- /dev/null
+++ b/UnixPkg/TimerDxe/Timer.h
@@ -0,0 +1,162 @@
+/*++
+
+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:
+
+ Timer.h
+
+Abstract:
+
+ UNIX Emulation Architectural Protocol Driver as defined in Tiano.
+ This Timer module uses an UNIX Thread to simulate the timer-tick driven
+ timer service.
+
+--*/
+
+#ifndef _TIMER_H_
+#define _TIMER_H_
+
+
+
+
+//
+// Legal timer value range in 100 ns units
+//
+#define TIMER_MINIMUM_VALUE 0
+#define TIMER_MAXIMUM_VALUE (0x100000000ULL - 1)
+
+//
+// Default timer value in 100 ns units (50 ms)
+//
+#define DEFAULT_TIMER_TICK_DURATION 500000
+
+//
+// Function Prototypes
+//
+EFI_STATUS
+EFIAPI
+UnixTimerDriverInitialize (
+ 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
+UnixTimerDriverRegisterHandler (
+ IN EFI_TIMER_ARCH_PROTOCOL *This,
+ IN EFI_TIMER_NOTIFY NotifyFunction
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ NotifyFunction - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixTimerDriverSetTimerPeriod (
+ IN EFI_TIMER_ARCH_PROTOCOL *This,
+ IN UINT64 TimerPeriod
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ TimerPeriod - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixTimerDriverGetTimerPeriod (
+ IN EFI_TIMER_ARCH_PROTOCOL *This,
+ OUT UINT64 *TimerPeriod
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ TimerPeriod - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixTimerDriverGenerateSoftInterrupt (
+ IN EFI_TIMER_ARCH_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+#endif
diff --git a/UnixPkg/TimerDxe/Timer.inf b/UnixPkg/TimerDxe/Timer.inf
new file mode 100644
index 0000000000..39ee61d62d
--- /dev/null
+++ b/UnixPkg/TimerDxe/Timer.inf
@@ -0,0 +1,63 @@
+#/** @file
+# Unix Emulation Timer Architectural Protocol Driver as defined in DXE CIS
+#
+# This Timer module uses an NT Thread to simulate the timer-tick driven
+# timer service. In the future, the Thread creation should possibly be
+# abstracted by the CPU architectural protocol
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = Timer
+ FILE_GUID = f36d49b4-8985-11db-809b-0040d02b1835
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = UnixTimerDriverInitialize
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ Timer.c
+ Timer.h
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ UnixLib
+ UefiDriverEntryPoint
+ UefiLib
+ DebugLib
+ BaseLib
+
+
+[Protocols]
+ gEfiCpuArchProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiTimerArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+
+
+[Depex]
+ gEfiCpuArchProtocolGuid
+
diff --git a/UnixPkg/TimerDxe/Timer.msa b/UnixPkg/TimerDxe/Timer.msa
new file mode 100644
index 0000000000..f240f3280d
--- /dev/null
+++ b/UnixPkg/TimerDxe/Timer.msa
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>Timer</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>f36d49b4-8985-11db-809b-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Unix Emulation Timer Architectural Protocol Driver as defined in DXE CIS</Abstract>
+ <Description>
+ This Timer module uses an NT Thread to simulate the timer-tick driven
+ timer service. In the future, the Thread creation should possibly be
+ abstracted by the CPU architectural protocol
+ </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>Timer</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <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>UnixLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>Timer.h</Filename>
+ <Filename>Timer.c</Filename>
+ <Filename>Timer.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>gEfiTimerArchProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gEfiCpuArchProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>UnixTimerDriverInitialize</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixAutoScanPei/UnixAutoScan.c b/UnixPkg/UnixAutoScanPei/UnixAutoScan.c
new file mode 100644
index 0000000000..34f50986ad
--- /dev/null
+++ b/UnixPkg/UnixAutoScanPei/UnixAutoScan.c
@@ -0,0 +1,145 @@
+/*++
+
+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:
+ UnixAutoscan.c
+
+Abstract:
+ This PEIM to abstract memory auto-scan in an Unix environment.
+
+Revision History
+
+--*/
+
+#include "PiPei.h"
+#include <Ppi/UnixAutoScan.h>
+#include <Ppi/BaseMemoryTest.h>
+#include <Ppi/MemoryDiscovered.h>
+
+#include <Library/DebugLib.h>
+#include <Library/PeimEntryPoint.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/HobLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/PeiServicesTablePointerLib.h>
+
+EFI_STATUS
+EFIAPI
+PeimInitializeUnixAutoScan (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices
+ )
+/*++
+
+Routine Description:
+ Perform a call-back into the SEC simulator to get a memory value
+
+Arguments:
+ FfsHeader - General purpose data available to every PEIM
+ PeiServices - General purpose services available to every PEIM.
+
+Returns:
+ None
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
+ PEI_UNIX_AUTOSCAN_PPI *PeiUnixService;
+ UINT64 MemorySize;
+ EFI_PHYSICAL_ADDRESS MemoryBase;
+ PEI_BASE_MEMORY_TEST_PPI *MemoryTestPpi;
+ EFI_PHYSICAL_ADDRESS ErrorAddress;
+ UINTN Index;
+ EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
+
+
+ DEBUG ((EFI_D_ERROR, "Unix Autoscan PEIM Loaded\n"));
+
+ //
+ // Get the PEI UNIX Autoscan PPI
+ //
+ Status = (**PeiServices).LocatePpi (
+ PeiServices,
+ &gPeiUnixAutoScanPpiGuid, // GUID
+ 0, // INSTANCE
+ &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
+ (VOID **)&PeiUnixService // PPI
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Get the Memory Test PPI
+ //
+ Status = (**PeiServices).LocatePpi (
+ PeiServices,
+ &gPeiBaseMemoryTestPpiGuid,
+ 0,
+ NULL,
+ (VOID **)&MemoryTestPpi
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Index = 0;
+ do {
+ Status = PeiUnixService->UnixAutoScan (Index, &MemoryBase, &MemorySize);
+ if (!EFI_ERROR (Status)) {
+ Attributes =
+ (
+ EFI_RESOURCE_ATTRIBUTE_PRESENT |
+ EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
+ EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
+ EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
+ EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
+ EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
+ );
+
+ if (Index == 0) {
+ //
+ // For the first area register it as PEI tested memory
+ //
+ Status = MemoryTestPpi->BaseMemoryTest (
+ PeiServices,
+ MemoryTestPpi,
+ MemoryBase,
+ MemorySize,
+ Quick,
+ &ErrorAddress
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Register the "tested" memory with the PEI Core
+ //
+ Status = (**PeiServices).InstallPeiMemory (PeiServices, MemoryBase, MemorySize);
+ ASSERT_EFI_ERROR (Status);
+
+ Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;
+ }
+
+ BuildResourceDescriptorHob (
+ EFI_RESOURCE_SYSTEM_MEMORY,
+ Attributes,
+ MemoryBase,
+ MemorySize
+ );
+ }
+ Index++;
+ } while (!EFI_ERROR (Status));
+
+ //
+ // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
+ //
+ BuildCpuHob (36, 16);
+
+ return Status;
+}
diff --git a/UnixPkg/UnixAutoScanPei/UnixAutoScan.inf b/UnixPkg/UnixAutoScanPei/UnixAutoScan.inf
new file mode 100644
index 0000000000..2b02e41aa8
--- /dev/null
+++ b/UnixPkg/UnixAutoScanPei/UnixAutoScan.inf
@@ -0,0 +1,60 @@
+#/** @file
+# Component description file for UnixAutoScan module
+#
+# This module abstracts memory auto-scan in a Unix environment.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixAutoScan
+ FILE_GUID = f3f36cb0-8985-11db-b195-0040d02b1835
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = PeimInitializeUnixAutoScan
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ UnixAutoScan.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ PeiServicesTablePointerLib
+ PeiServicesLib
+ HobLib
+ BaseMemoryLib
+ BaseLib
+ PeimEntryPoint
+ DebugLib
+
+
+[Ppis]
+ gEfiPeiMemoryDiscoveredPpiGuid # PPI ALWAYS_PRODUCED
+ gPeiBaseMemoryTestPpiGuid # PPI ALWAYS_CONSUMED
+ gPeiUnixAutoScanPpiGuid # PPI ALWAYS_CONSUMED
+
+
+[Depex]
+ gPeiUnixAutoScanPpiGuid AND gEfiPeiMasterBootModePpiGuid AND gPeiBaseMemoryTestPpiGuid
+
diff --git a/UnixPkg/UnixAutoScanPei/UnixAutoScan.msa b/UnixPkg/UnixAutoScanPei/UnixAutoScan.msa
new file mode 100644
index 0000000000..60830b613c
--- /dev/null
+++ b/UnixPkg/UnixAutoScanPei/UnixAutoScan.msa
@@ -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
index 0000000000..19085fd88a
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/ComponentName.c
@@ -0,0 +1,197 @@
+/*++
+
+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:
+
+ ComponentName.c
+
+Abstract:
+
+--*/
+
+#include "UnixBlockIo.h"
+
+//
+// EFI Component Name Functions
+//
+EFI_STATUS
+EFIAPI
+UnixBlockIoComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ );
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ );
+
+//
+// EFI Component Name Protocol
+//
+EFI_COMPONENT_NAME_PROTOCOL gUnixBlockIoComponentName = {
+ UnixBlockIoComponentNameGetDriverName,
+ UnixBlockIoComponentNameGetControllerName,
+ "eng"
+};
+
+static EFI_UNICODE_STRING_TABLE mUnixBlockIoDriverNameTable[] = {
+ { "eng", L"Unix Block I/O Driver" },
+ { NULL , NULL }
+};
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the driver name that that the caller
+ is requesting, and it must match one of the languages specified
+ in SupportedLanguages. The number of languages supported by a
+ driver is up to the driver writer.
+ DriverName - A pointer to the Unicode string to return. This Unicode string
+ is the name of the driver specified by This in the language
+ specified by Language.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the Driver specified by This
+ and the language specified by Language was returned
+ in DriverName.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - DriverName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ return LookupUnicodeString (
+ Language,
+ gUnixBlockIoComponentName.SupportedLanguages,
+ mUnixBlockIoDriverNameTable,
+ DriverName
+ );
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by an EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ ControllerHandle - The handle of a controller that the driver specified by
+ This is managing. This handle specifies the controller
+ whose name is to be returned.
+ ChildHandle - The handle of the child controller to retrieve the name
+ of. 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 retrieve the name of the
+ bus controller. It will not be NULL for a bus driver
+ that wishes to retrieve the name of a child controller.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language of the controller name
+ that that the caller is requesting, and it must match one
+ of the languages specified in SupportedLanguages. The
+ number of languages supported by a driver is up to the
+ driver writer.
+ ControllerName - A pointer to the Unicode string to return. This Unicode
+ string is the name of the controller specified by
+ ControllerHandle and ChildHandle in the language specified
+ by Language from the point of view of the driver specified
+ by This.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the user readable name in the
+ language specified by Language for the driver
+ specified by This was returned in DriverName.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ControllerName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This is not currently managing
+ the controller specified by ControllerHandle and
+ ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ UNIX_BLOCK_IO_PRIVATE *Private;
+
+ //
+ // This is a device driver, so ChildHandle must be NULL.
+ //
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Make sure this driver is currently managing ControllerHandle
+ //
+ Status = EfiTestManagedDevice (
+ ControllerHandle,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ &gEfiUnixIoProtocolGuid
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Get our context back
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiBlockIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);
+
+ return LookupUnicodeString (
+ Language,
+ gUnixBlockIoComponentName.SupportedLanguages,
+ Private->ControllerNameTable,
+ ControllerName
+ );
+}
diff --git a/UnixPkg/UnixBlockIoDxe/DriverConfiguration.c b/UnixPkg/UnixBlockIoDxe/DriverConfiguration.c
new file mode 100644
index 0000000000..d06b5fba4d
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/DriverConfiguration.c
@@ -0,0 +1,338 @@
+/*++
+
+Copyright (c) 2004 - 2005, 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:
+
+ DriverConfiguration.c
+
+Abstract:
+
+--*/
+
+#include "UnixBlockIo.h"
+
+//
+// EFI Driver Configuration Functions
+//
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationSetOptions (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
+ );
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationOptionsValid (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL
+ );
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationForceDefaults (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN UINT32 DefaultType,
+ OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
+ );
+
+//
+// EFI Driver Configuration Protocol
+//
+EFI_DRIVER_CONFIGURATION_PROTOCOL gUnixBlockIoDriverConfiguration = {
+ UnixBlockIoDriverConfigurationSetOptions,
+ UnixBlockIoDriverConfigurationOptionsValid,
+ UnixBlockIoDriverConfigurationForceDefaults,
+ LANGUAGESUPPORTED
+};
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationSetOptions (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
+ )
+/*++
+
+ Routine Description:
+ Allows the user to set controller specific options for a controller that a
+ driver is currently managing.
+
+ Arguments:
+ This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
+ ControllerHandle - The handle of the controller to set options on.
+ ChildHandle - The handle of the child controller to set options on. This
+ is an optional parameter that may be NULL. It will be NULL
+ for device drivers, and for a bus drivers that wish to set
+ options for the bus controller. It will not be NULL for a
+ bus driver that wishes to set options for one of its child
+ controllers.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the user interface that should be
+ presented to the user, and it must match one of the languages
+ specified in SupportedLanguages. The number of languages
+ supported by a driver is up to the driver writer.
+ ActionRequired - A pointer to the action that the calling agent is required
+ to perform when this function returns. See "Related
+ Definitions" for a list of the actions that the calling
+ agent is required to perform prior to accessing
+ ControllerHandle again.
+
+ Returns:
+ EFI_SUCCESS - The driver specified by This successfully set the
+ configuration options for the controller specified
+ by ControllerHandle..
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ActionRequired is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support setting
+ configuration options for the controller specified by
+ ControllerHandle and ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+ EFI_DEVICE_ERROR - A device error occurred while attempt to set the
+ configuration options for the controller specified
+ by ControllerHandle and ChildHandle.
+ EFI_OUT_RESOURCES - There are not enough resources available to set the
+ configuration options for the controller specified
+ by ControllerHandle and ChildHandle.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ CHAR8 *SupportedLanguage;
+
+ SupportedLanguage = This->SupportedLanguages;
+
+ Status = EFI_UNSUPPORTED;
+ while (*SupportedLanguage != 0) {
+ if (AsciiStrnCmp (Language, SupportedLanguage, 3)) {
+ Status = EFI_SUCCESS;
+ }
+
+ SupportedLanguage += 3;
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (ActionRequired == NULL || ControllerHandle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Validate controller handle
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (!EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Status == EFI_UNSUPPORTED) {
+ return Status;
+ } else if (Status != EFI_ALREADY_STARTED) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *ActionRequired = EfiDriverConfigurationActionNone;
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationOptionsValid (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL
+ )
+/*++
+
+ Routine Description:
+ Tests to see if a controller's current configuration options are valid.
+
+ Arguments:
+ This - A pointer to the EFI_DRIVER_CONFIGURATION_PROTOCOL instance.
+ ControllerHandle - The handle of the controller to test if it's current
+ configuration options are valid.
+ ChildHandle - The handle of the child controller to test if it's current
+ configuration options are valid. 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 test the configuration options for the bus controller.
+ It will not be NULL for a bus driver that wishes to test
+ configuration options for one of its child controllers.
+
+ Returns:
+ EFI_SUCCESS - The controller specified by ControllerHandle and
+ ChildHandle that is being managed by the driver
+ specified by This has a valid set of configuration
+ options.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_UNSUPPORTED - The driver specified by This is not currently
+ managing the controller specified by ControllerHandle
+ and ChildHandle.
+ EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
+ ChildHandle that is being managed by the driver
+ specified by This has an invalid set of configuration
+ options.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if (ControllerHandle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Validate controller handle
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (!EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Status == EFI_UNSUPPORTED) {
+ return Status;
+ } else if (Status != EFI_ALREADY_STARTED) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverConfigurationForceDefaults (
+ IN EFI_DRIVER_CONFIGURATION_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN UINT32 DefaultType,
+ OUT EFI_DRIVER_CONFIGURATION_ACTION_REQUIRED *ActionRequired
+ )
+/*++
+
+ Routine Description:
+ Forces a driver to set the default configuration options for a controller.
+
+ Arguments:
+ This - A pointer to the EFI_DRIVER_CONFIGURATION_ PROTOCOL instance.
+ ControllerHandle - The handle of the controller to force default configuration options on.
+ 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.
+ 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.
+ 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.
+
+ Returns:
+ EFI_SUCCESS - The driver specified by This successfully forced the default configuration options on the controller specified by ControllerHandle and ChildHandle.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ActionRequired is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support forcing the default configuration options on the controller specified by ControllerHandle and ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the configuration type specified by DefaultType.
+ EFI_DEVICE_ERROR - A device error occurred while attempt to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
+ EFI_OUT_RESOURCES - There are not enough resources available to force the default configuration options on the controller specified by ControllerHandle and ChildHandle.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if (ActionRequired == NULL || ControllerHandle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Validate controller handle
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (!EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Status == EFI_UNSUPPORTED) {
+ return Status;
+ } else if (Status != EFI_ALREADY_STARTED) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *ActionRequired = EfiDriverConfigurationActionNone;
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c b/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c
new file mode 100644
index 0000000000..0e9a32c66a
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/DriverDiagnostics.c
@@ -0,0 +1,187 @@
+/*++
+
+Copyright (c) 2004 - 2005, 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:
+
+ DriverDiagnostics.c
+
+Abstract:
+
+--*/
+
+#include "UnixBlockIo.h"
+
+//
+// EFI Driver Diagnostics Functions
+//
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverDiagnosticsRunDiagnostics (
+ IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,
+ IN CHAR8 *Language,
+ OUT EFI_GUID **ErrorType,
+ OUT UINTN *BufferSize,
+ OUT CHAR16 **Buffer
+ );
+
+//
+// EFI Driver Diagnostics Protocol
+//
+EFI_DRIVER_DIAGNOSTICS_PROTOCOL gUnixBlockIoDriverDiagnostics = {
+ UnixBlockIoDriverDiagnosticsRunDiagnostics,
+ LANGUAGESUPPORTED
+};
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverDiagnosticsRunDiagnostics (
+ IN EFI_DRIVER_DIAGNOSTICS_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN EFI_DRIVER_DIAGNOSTIC_TYPE DiagnosticType,
+ IN CHAR8 *Language,
+ OUT EFI_GUID **ErrorType,
+ OUT UINTN *BufferSize,
+ OUT CHAR16 **Buffer
+ )
+/*++
+
+ Routine Description:
+ Runs diagnostics on a controller.
+
+ Arguments:
+ This - A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL instance.
+ ControllerHandle - The handle of the controller to run diagnostics on.
+ ChildHandle - The handle of the child controller to run diagnostics 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 run diagnostics on the bus
+ controller. It will not be NULL for a bus driver that
+ wishes to run diagnostics on one of its child controllers.
+ DiagnosticType - Indicates type of diagnostics to perform on the controller
+ specified by ControllerHandle and ChildHandle. See
+ "Related Definitions" for the list of supported types.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language in which the optional
+ error message should be returned in Buffer, and it must
+ match one of the languages specified in SupportedLanguages.
+ The number of languages supported by a driver is up to
+ the driver writer.
+ ErrorType - A GUID that defines the format of the data returned in
+ Buffer.
+ BufferSize - The size, in bytes, of the data returned in Buffer.
+ Buffer - A buffer that contains a Null-terminated Unicode string
+ plus some additional data whose format is defined by
+ ErrorType. Buffer is allocated by this function with
+ AllocatePool(), and it is the caller's responsibility
+ to free it with a call to FreePool().
+
+ Returns:
+ EFI_SUCCESS - The controller specified by ControllerHandle and
+ ChildHandle passed the diagnostic.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid
+ EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ErrorType is NULL.
+ EFI_INVALID_PARAMETER - BufferType is NULL.
+ EFI_INVALID_PARAMETER - Buffer is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support
+ running diagnostics for the controller specified
+ by ControllerHandle and ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ type of diagnostic specified by DiagnosticType.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+ EFI_OUT_OF_RESOURCES - There are not enough resources available to complete
+ the diagnostics.
+ EFI_OUT_OF_RESOURCES - There are not enough resources available to return
+ the status information in ErrorType, BufferSize,
+ and Buffer.
+ EFI_DEVICE_ERROR - The controller specified by ControllerHandle and
+ ChildHandle did not pass the diagnostic.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ CHAR8 *SupportedLanguage;
+
+ if (Language == NULL ||
+ ErrorType == NULL ||
+ Buffer == NULL ||
+ ControllerHandle == NULL ||
+ BufferSize == NULL) {
+
+ return EFI_INVALID_PARAMETER;
+ }
+
+ SupportedLanguage = This->SupportedLanguages;
+
+ Status = EFI_UNSUPPORTED;
+ while (*SupportedLanguage != 0) {
+ if (AsciiStrnCmp (Language, SupportedLanguage, 3)) {
+ Status = EFI_SUCCESS;
+ break;
+ }
+
+ SupportedLanguage += 3;
+ }
+
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ *ErrorType = NULL;
+ *BufferSize = 0;
+ if (DiagnosticType != EfiDriverDiagnosticTypeStandard) {
+ *ErrorType = &gEfiBlockIoProtocolGuid;
+ *BufferSize = 0x60;
+ gBS->AllocatePool (EfiBootServicesData, (UINTN) (*BufferSize),
+ (void *)Buffer);
+ CopyMem (*Buffer, L"Unix Block I/O Driver Diagnostics Failed\n", *BufferSize);
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Validate controller handle
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&BlockIo,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+
+ if (!EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ gUnixBlockIoDriverBinding.DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return EFI_UNSUPPORTED;
+ }
+
+ if (Status == EFI_UNSUPPORTED) {
+ return Status;
+ } else if (Status != EFI_ALREADY_STARTED) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/UnixBlockIoDxe/EntryPoint.c b/UnixPkg/UnixBlockIoDxe/EntryPoint.c
new file mode 100644
index 0000000000..dae3687906
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/EntryPoint.c
@@ -0,0 +1,51 @@
+/**@file
+ Entry Point Source file.
+
+ This file contains the user entry point
+
+ 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.
+**/
+
+
+
+#include "UnixBlockIo.h"
+
+/**
+ The user Entry Point for module UnixBlockIo. The user code starts with this function.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeUnixBlockIo(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = EfiLibInstallAllDriverProtocols (
+ ImageHandle,
+ SystemTable,
+ &gUnixBlockIoDriverBinding,
+ ImageHandle,
+ &gUnixBlockIoComponentName,
+ NULL,
+ &gUnixBlockIoDriverDiagnostics
+ );
+ ASSERT_EFI_ERROR (Status);
+
+
+ return Status;
+}
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c
new file mode 100644
index 0000000000..d92ab7251c
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.c
@@ -0,0 +1,1307 @@
+/*++
+
+Copyright (c) 2004 - 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:
+
+ UnixBlockIo.c
+
+Abstract:
+
+ Produce block IO abstractions for real devices on your PC using Posix APIs.
+ The configuration of what devices to mount or emulate comes from UNIX
+ environment variables. The variables must be visible to the Microsoft*
+ Developer Studio for them to work.
+
+ <F>ixed - Fixed disk like a hard drive.
+ <R>emovable - Removable media like a floppy or CD-ROM.
+ Read <O>nly - Write protected device.
+ Read <W>rite - Read write device.
+ <block count> - Decimal number of blocks a device supports.
+ <block size> - Decimal number of bytes per block.
+
+ UNIX envirnonment variable contents. '<' and '>' are not part of the variable,
+ they are just used to make this help more readable. There should be no
+ spaces between the ';'. Extra spaces will break the variable. A '!' is
+ used to seperate multiple devices in a variable.
+
+ EFI_UNIX_VIRTUAL_DISKS =
+ <F | R><O | W>;<block count>;<block size>[!...]
+
+ EFI_UNIX_PHYSICAL_DISKS =
+ <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]
+
+ Virtual Disks: These devices use a file to emulate a hard disk or removable
+ media device.
+
+ Thus a 20 MB emulated hard drive would look like:
+ EFI_UNIX_VIRTUAL_DISKS=FW;40960;512
+
+ A 1.44MB emulated floppy with a block size of 1024 would look like:
+ EFI_UNIX_VIRTUAL_DISKS=RW;1440;1024
+
+ Physical Disks: These devices use UNIX to open a real device in your system
+
+ Thus a 120 MB floppy would look like:
+ EFI_UNIX_PHYSICAL_DISKS=B:RW;245760;512
+
+ Thus a standard CD-ROM floppy would look like:
+ EFI_UNIX_PHYSICAL_DISKS=Z:RO;307200;2048
+
+
+ * Other names and brands may be claimed as the property of others.
+
+--*/
+
+#include <fcntl.h>
+#include <unistd.h>
+#include "UnixBlockIo.h"
+
+//
+// Block IO protocol member functions
+//
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoReadBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ MediaId - TODO: add argument description
+ Lba - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoWriteBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ MediaId - TODO: add argument description
+ Lba - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoFlushBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoResetBlock (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ ExtendedVerification - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+//
+// Private Worker functions
+//
+STATIC
+EFI_STATUS
+UnixBlockIoCreateMapping (
+ IN EFI_UNIX_IO_PROTOCOL *UnixIo,
+ IN EFI_HANDLE EfiDeviceHandle,
+ IN CHAR16 *Filename,
+ IN BOOLEAN ReadOnly,
+ IN BOOLEAN RemovableMedia,
+ IN UINTN NumberOfBlocks,
+ IN UINTN BlockSize
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ UnixIo - TODO: add argument description
+ EfiDeviceHandle - TODO: add argument description
+ Filename - TODO: add argument description
+ ReadOnly - TODO: add argument description
+ RemovableMedia - TODO: add argument description
+ NumberOfBlocks - TODO: add argument description
+ BlockSize - TODO: add argument description
+ DeviceType - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+UnixBlockIoReadWriteCommon (
+ IN UNIX_BLOCK_IO_PRIVATE *Private,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer,
+ IN CHAR8 *CallerName
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+ MediaId - TODO: add argument description
+ Lba - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+ CallerName - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+UnixBlockIoError (
+ IN UNIX_BLOCK_IO_PRIVATE *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+UnixBlockIoOpenDevice (
+ UNIX_BLOCK_IO_PRIVATE *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+CHAR16 *
+GetNextElementPastTerminator (
+ IN CHAR16 *EnvironmentVariable,
+ IN CHAR16 Terminator
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ EnvironmentVariable - TODO: add argument description
+ Terminator - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+EFI_DRIVER_BINDING_PROTOCOL gUnixBlockIoDriverBinding = {
+ UnixBlockIoDriverBindingSupported,
+ UnixBlockIoDriverBindingStart,
+ UnixBlockIoDriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: Handle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+
+ //
+ // Open the IO Abstraction(s) needed to perform the supported test
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID **)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Make sure the UnixThunkProtocol is valid
+ //
+ Status = EFI_UNSUPPORTED;
+ if (UnixIo->UnixThunk->Signature == EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {
+
+ //
+ // Check the GUID to see if this is a handle type the driver supports
+ //
+ if (CompareGuid (UnixIo->TypeGuid, &gEfiUnixVirtualDisksGuid) ) {
+ Status = EFI_SUCCESS;
+ }
+ }
+
+ //
+ // Close the I/O Abstraction(s) used to perform the supported test
+ //
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: Handle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ CHAR16 Buffer[FILENAME_BUFFER_SIZE];
+ CHAR16 *Str;
+ BOOLEAN RemovableMedia;
+ BOOLEAN WriteProtected;
+ UINTN NumberOfBlocks;
+ UINTN BlockSize;
+ INTN i;
+
+ //
+ // Grab the protocols we need
+ //
+
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ //
+ // Set DiskType
+ //
+ if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixVirtualDisksGuid)) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ Status = EFI_NOT_FOUND;
+ // Extract filename.
+ Str = UnixIo->EnvString;
+ i = 0;
+ while (*Str && *Str != ':')
+ Buffer[i++] = *Str++;
+ Buffer[i] = 0;
+ if (*Str != ':') {
+ goto Done;
+ }
+
+ Str++;
+
+ RemovableMedia = FALSE;
+ WriteProtected = TRUE;
+ NumberOfBlocks = 0;
+ BlockSize = 512;
+ do {
+ if (*Str == 'R' || *Str == 'F') {
+ RemovableMedia = (BOOLEAN) (*Str == 'R');
+ Str++;
+ }
+ if (*Str == 'O' || *Str == 'W') {
+ WriteProtected = (BOOLEAN) (*Str == 'O');
+ Str++;
+ }
+ if (*Str == 0)
+ break;
+ if (*Str != ';')
+ goto Done;
+ Str++;
+
+ NumberOfBlocks = Atoi (Str);
+ Str = GetNextElementPastTerminator (Str, ';');
+ if (NumberOfBlocks == 0)
+ break;
+
+ BlockSize = Atoi (Str);
+ if (BlockSize != 0)
+ Str = GetNextElementPastTerminator (Str, ';');
+ } while (0);
+
+ //
+ // If we get here the variable is valid so do the work.
+ //
+ Status = UnixBlockIoCreateMapping (
+ UnixIo,
+ Handle,
+ Buffer,
+ WriteProtected,
+ RemovableMedia,
+ NumberOfBlocks,
+ BlockSize
+ );
+
+Done:
+ if (EFI_ERROR (Status)) {
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+ }
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingStop (
+ 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:
+
+ EFI_UNSUPPORTED - TODO: Add description for return value
+
+--*/
+{
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_STATUS Status;
+ UNIX_BLOCK_IO_PRIVATE *Private;
+
+ //
+ // Get our context back
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiBlockIoProtocolGuid,
+ (void *)&BlockIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (BlockIo);
+
+ //
+ // BugBug: If we need to kick people off, we need to make Uninstall Close the handles.
+ // We could pass in our image handle or FLAG our open to be closed via
+ // Unistall (== to saying any CloseProtocol will close our open)
+ //
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ Private->EfiHandle,
+ &gEfiBlockIoProtocolGuid,
+ &Private->BlockIo,
+ NULL
+ );
+ if (!EFI_ERROR (Status)) {
+
+ Status = gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+
+ //
+ // Shut down our device
+ //
+ Private->UnixThunk->Close (Private->fd);
+
+ //
+ // Free our instance data
+ //
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+
+ gBS->FreePool (Private);
+ }
+
+ return Status;
+}
+
+STATIC
+CHAR16 *
+GetNextElementPastTerminator (
+ IN CHAR16 *EnvironmentVariable,
+ IN CHAR16 Terminator
+ )
+/*++
+
+Routine Description:
+
+ Worker function to parse environment variables.
+
+Arguments:
+ EnvironmentVariable - Envirnment variable to parse.
+
+ Terminator - Terminator to parse for.
+
+Returns:
+
+ Pointer to next eliment past the first occurence of Terminator or the '\0'
+ at the end of the string.
+
+--*/
+{
+ CHAR16 *Ptr;
+
+ for (Ptr = EnvironmentVariable; *Ptr != '\0'; Ptr++) {
+ if (*Ptr == Terminator) {
+ Ptr++;
+ break;
+ }
+ }
+
+ return Ptr;
+}
+
+STATIC
+EFI_STATUS
+UnixBlockIoCreateMapping (
+ IN EFI_UNIX_IO_PROTOCOL *UnixIo,
+ IN EFI_HANDLE EfiDeviceHandle,
+ IN CHAR16 *Filename,
+ IN BOOLEAN ReadOnly,
+ IN BOOLEAN RemovableMedia,
+ IN UINTN NumberOfBlocks,
+ IN UINTN BlockSize
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ UnixIo - TODO: add argument description
+ EfiDeviceHandle - TODO: add argument description
+ Filename - TODO: add argument description
+ ReadOnly - TODO: add argument description
+ RemovableMedia - TODO: add argument description
+ NumberOfBlocks - TODO: add argument description
+ BlockSize - TODO: add argument description
+ DeviceType - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ UNIX_BLOCK_IO_PRIVATE *Private;
+ UINTN Index;
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ sizeof (UNIX_BLOCK_IO_PRIVATE),
+ (void *)&Private
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ EfiInitializeLock (&Private->Lock, TPL_NOTIFY);
+
+ Private->UnixThunk = UnixIo->UnixThunk;
+
+ Private->Signature = UNIX_BLOCK_IO_PRIVATE_SIGNATURE;
+ Private->LastBlock = NumberOfBlocks - 1;
+ Private->BlockSize = BlockSize;
+
+ for (Index = 0; Filename[Index] != 0; Index++) {
+ Private->Filename[Index] = Filename[Index];
+ }
+
+ Private->Filename[Index] = 0;
+
+ Private->Mode = (ReadOnly ? O_RDONLY : O_RDWR);
+
+ Private->NumberOfBlocks = NumberOfBlocks;
+ Private->fd = -1;
+
+ Private->ControllerNameTable = NULL;
+
+ AddUnicodeString (
+ "eng",
+ gUnixBlockIoComponentName.SupportedLanguages,
+ &Private->ControllerNameTable,
+ Filename
+ );
+
+ BlockIo = &Private->BlockIo;
+ BlockIo->Revision = EFI_BLOCK_IO_PROTOCOL_REVISION;
+ BlockIo->Media = &Private->Media;
+ BlockIo->Media->BlockSize = Private->BlockSize;
+ BlockIo->Media->LastBlock = Private->NumberOfBlocks - 1;
+ BlockIo->Media->MediaId = 0;;
+
+ BlockIo->Reset = UnixBlockIoResetBlock;
+ BlockIo->ReadBlocks = UnixBlockIoReadBlocks;
+ BlockIo->WriteBlocks = UnixBlockIoWriteBlocks;
+ BlockIo->FlushBlocks = UnixBlockIoFlushBlocks;
+
+ BlockIo->Media->ReadOnly = ReadOnly;
+ BlockIo->Media->RemovableMedia = RemovableMedia;
+ BlockIo->Media->LogicalPartition = FALSE;
+ BlockIo->Media->MediaPresent = TRUE;
+ BlockIo->Media->WriteCaching = FALSE;
+
+ BlockIo->Media->IoAlign = 1;
+
+ Private->EfiHandle = EfiDeviceHandle;
+ Status = UnixBlockIoOpenDevice (Private);
+ if (!EFI_ERROR (Status)) {
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Private->EfiHandle,
+ &gEfiBlockIoProtocolGuid,
+ &Private->BlockIo,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+ gBS->FreePool (Private);
+ }
+
+ DEBUG ((EFI_D_ERROR, "BlockDevice added: %s\n", Filename));
+ }
+
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+UnixBlockIoOpenDevice (
+ UNIX_BLOCK_IO_PRIVATE *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ EFI_STATUS Status;
+ UINT64 FileSize;
+ UINT64 EndOfFile;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+
+ BlockIo = &Private->BlockIo;
+ EfiAcquireLock (&Private->Lock);
+
+ //
+ // If the device is already opened, close it
+ //
+ if (Private->fd >= 0) {
+ BlockIo->Reset (BlockIo, FALSE);
+ }
+
+ //
+ // Open the device
+ //
+ Private->fd = Private->UnixThunk->Open
+ (Private->Filename, Private->Mode, 0644);
+
+ if (Private->fd < 0) {
+ DEBUG ((EFI_D_INFO, "PlOpenBlock: Could not open %s\n",
+ Private->Filename));
+ BlockIo->Media->MediaPresent = FALSE;
+ Status = EFI_NO_MEDIA;
+ goto Done;
+ }
+
+ if (!BlockIo->Media->MediaPresent) {
+ //
+ // BugBug: try to emulate if a CD appears - notify drivers to check it out
+ //
+ BlockIo->Media->MediaPresent = TRUE;
+ EfiReleaseLock (&Private->Lock);
+ EfiAcquireLock (&Private->Lock);
+ }
+
+ //
+ // get the size of the file
+ //
+ Status = SetFilePointer64 (Private, 0, &FileSize, SEEK_END);
+
+ if (EFI_ERROR (Status)) {
+ FileSize = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);
+ DEBUG ((EFI_D_ERROR, "PlOpenBlock: Could not get filesize of %s\n", Private->Filename));
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ if (Private->NumberOfBlocks == 0) {
+ Private->NumberOfBlocks = DivU64x32 (FileSize, Private->BlockSize);
+ }
+
+ EndOfFile = MultU64x32 (Private->NumberOfBlocks, Private->BlockSize);
+
+ if (FileSize != EndOfFile) {
+ //
+ // file is not the proper size, change it
+ //
+ DEBUG ((EFI_D_INIT, "PlOpenBlock: Initializing block device: %a\n", Private->Filename));
+
+ //
+ // first set it to 0
+ //
+ Private->UnixThunk->FTruncate (Private->fd, 0);
+
+ //
+ // then set it to the needed file size (OS will zero fill it)
+ //
+ Private->UnixThunk->FTruncate (Private->fd, EndOfFile);
+ }
+
+ DEBUG ((EFI_D_INIT, "%HPlOpenBlock: opened %s%N\n", Private->Filename));
+ Status = EFI_SUCCESS;
+
+Done:
+ if (EFI_ERROR (Status)) {
+ if (Private->fd >= 0) {
+ BlockIo->Reset (BlockIo, FALSE);
+ }
+ }
+
+ EfiReleaseLock (&Private->Lock);
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+UnixBlockIoError (
+ IN UNIX_BLOCK_IO_PRIVATE *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ return EFI_DEVICE_ERROR;
+
+#if 0
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_STATUS Status;
+ BOOLEAN ReinstallBlockIoFlag;
+
+
+ BlockIo = &Private->BlockIo;
+
+ switch (Private->UnixThunk->GetLastError ()) {
+
+ case ERROR_NOT_READY:
+ Status = EFI_NO_MEDIA;
+ BlockIo->Media->ReadOnly = FALSE;
+ BlockIo->Media->MediaPresent = FALSE;
+ ReinstallBlockIoFlag = FALSE;
+ break;
+
+ case ERROR_WRONG_DISK:
+ BlockIo->Media->ReadOnly = FALSE;
+ BlockIo->Media->MediaPresent = TRUE;
+ BlockIo->Media->MediaId += 1;
+ ReinstallBlockIoFlag = TRUE;
+ Status = EFI_MEDIA_CHANGED;
+ break;
+
+ case ERROR_WRITE_PROTECT:
+ BlockIo->Media->ReadOnly = TRUE;
+ ReinstallBlockIoFlag = FALSE;
+ Status = EFI_WRITE_PROTECTED;
+ break;
+
+ default:
+ ReinstallBlockIoFlag = FALSE;
+ Status = EFI_DEVICE_ERROR;
+ break;
+ }
+
+ if (ReinstallBlockIoFlag) {
+ BlockIo->Reset (BlockIo, FALSE);
+
+ gBS->ReinstallProtocolInterface (
+ Private->EfiHandle,
+ &gEfiBlockIoProtocolGuid,
+ BlockIo,
+ BlockIo
+ );
+ }
+
+ return Status;
+#endif
+}
+
+STATIC
+EFI_STATUS
+UnixBlockIoReadWriteCommon (
+ IN UNIX_BLOCK_IO_PRIVATE *Private,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer,
+ IN CHAR8 *CallerName
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+ MediaId - TODO: add argument description
+ Lba - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+ CallerName - TODO: add argument description
+
+Returns:
+
+ EFI_NO_MEDIA - TODO: Add description for return value
+ EFI_MEDIA_CHANGED - TODO: Add description for return value
+ EFI_INVALID_PARAMETER - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+ EFI_BAD_BUFFER_SIZE - TODO: Add description for return value
+ EFI_INVALID_PARAMETER - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN BlockSize;
+ UINT64 LastBlock;
+ INT64 DistanceToMove;
+ UINT64 DistanceMoved;
+
+ if (Private->fd < 0) {
+ Status = UnixBlockIoOpenDevice (Private);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+ }
+
+ if (!Private->Media.MediaPresent) {
+ DEBUG ((EFI_D_INIT, "%s: No Media\n", CallerName));
+ return EFI_NO_MEDIA;
+ }
+
+ if (Private->Media.MediaId != MediaId) {
+ return EFI_MEDIA_CHANGED;
+ }
+
+ if ((UINT32) Buffer % Private->Media.IoAlign != 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Verify buffer size
+ //
+ BlockSize = Private->BlockSize;
+ if (BufferSize == 0) {
+ DEBUG ((EFI_D_INIT, "%s: Zero length read\n", CallerName));
+ return EFI_SUCCESS;
+ }
+
+ if ((BufferSize % BlockSize) != 0) {
+ DEBUG ((EFI_D_INIT, "%s: Invalid read size\n", CallerName));
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ LastBlock = Lba + (BufferSize / BlockSize) - 1;
+ if (LastBlock > Private->LastBlock) {
+ DEBUG ((EFI_D_INIT, "ReadBlocks: Attempted to read off end of device\n"));
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Seek to End of File
+ //
+ DistanceToMove = MultU64x32 (Lba, BlockSize);
+ Status = SetFilePointer64 (Private, DistanceToMove, &DistanceMoved, SEEK_SET);
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_INIT, "WriteBlocks: SetFilePointer failed\n"));
+ return UnixBlockIoError (Private);
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoReadBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+ Routine Description:
+ Read BufferSize bytes from Lba into Buffer.
+
+ Arguments:
+ This - Protocol instance pointer.
+ MediaId - Id of the media, changes every time the media is replaced.
+ Lba - The starting Logical Block Address to read from
+ BufferSize - Size of Buffer, must be a multiple of device block size.
+ Buffer - Buffer containing read data
+
+ Returns:
+ EFI_SUCCESS - The data was read correctly from the device.
+ EFI_DEVICE_ERROR - The device reported an error while performing the read.
+ EFI_NO_MEDIA - There is no media in the device.
+ EFI_MEDIA_CHANGED - The MediaId does not matched the current device.
+ EFI_BAD_BUFFER_SIZE - The Buffer was not a multiple of the block size of the
+ device.
+ EFI_INVALID_PARAMETER - The read request contains device addresses that are not
+ valid for the device.
+
+--*/
+{
+ UNIX_BLOCK_IO_PRIVATE *Private;
+ ssize_t len;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ Status = UnixBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "UnixReadBlocks");
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ len = Private->UnixThunk->Read (Private->fd, Buffer, BufferSize);
+ if (len != BufferSize) {
+ DEBUG ((EFI_D_INIT, "ReadBlocks: ReadFile failed.\n"));
+ Status = UnixBlockIoError (Private);
+ goto Done;
+ }
+
+ //
+ // If we wrote then media is present.
+ //
+ This->Media->MediaPresent = TRUE;
+ Status = EFI_SUCCESS;
+
+Done:
+ gBS->RestoreTPL (OldTpl);
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoWriteBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN UINT32 MediaId,
+ IN EFI_LBA Lba,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+ Routine Description:
+ Write BufferSize bytes from Lba into Buffer.
+
+ Arguments:
+ This - Protocol instance pointer.
+ MediaId - Id of the media, changes every time the media is replaced.
+ Lba - The starting Logical Block Address to read from
+ BufferSize - Size of Buffer, must be a multiple of device block size.
+ Buffer - Buffer containing read data
+
+ Returns:
+ EFI_SUCCESS - The data was written correctly to the device.
+ EFI_WRITE_PROTECTED - The device can not be written to.
+ EFI_DEVICE_ERROR - The device reported an error while performing the write.
+ EFI_NO_MEDIA - There is no media in the device.
+ EFI_MEDIA_CHNAGED - The MediaId does not matched the current device.
+ EFI_BAD_BUFFER_SIZE - The Buffer was not a multiple of the block size of the
+ device.
+ EFI_INVALID_PARAMETER - The write request contains a LBA that is not
+ valid for the device.
+
+--*/
+{
+ UNIX_BLOCK_IO_PRIVATE *Private;
+ ssize_t len;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ Status = UnixBlockIoReadWriteCommon (Private, MediaId, Lba, BufferSize, Buffer, "UnixWriteBlocks");
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ len = Private->UnixThunk->Write (Private->fd, Buffer, BufferSize);
+ if (len != BufferSize) {
+ DEBUG ((EFI_D_INIT, "ReadBlocks: WriteFile failed.\n"));
+ Status = UnixBlockIoError (Private);
+ goto Done;
+ }
+
+ //
+ // If the write succeeded, we are not write protected and media is present.
+ //
+ This->Media->MediaPresent = TRUE;
+ This->Media->ReadOnly = FALSE;
+ Status = EFI_SUCCESS;
+
+Done:
+ gBS->RestoreTPL (OldTpl);
+ return Status;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoFlushBlocks (
+ IN EFI_BLOCK_IO_PROTOCOL *This
+ )
+/*++
+
+ Routine Description:
+ Flush the Block Device.
+
+ Arguments:
+ This - Protocol instance pointer.
+
+ Returns:
+ EFI_SUCCESS - All outstanding data was written to the device
+ EFI_DEVICE_ERROR - The device reported an error while writting back the data
+ EFI_NO_MEDIA - There is no media in the device.
+
+--*/
+{
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixBlockIoResetBlock (
+ IN EFI_BLOCK_IO_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ )
+/*++
+
+ Routine Description:
+ Reset the Block Device.
+
+ Arguments:
+ This - Protocol instance pointer.
+ ExtendedVerification - Driver may perform diagnostics on reset.
+
+ Returns:
+ EFI_SUCCESS - The device was reset.
+ EFI_DEVICE_ERROR - The device is not functioning properly and could
+ not be reset.
+
+--*/
+{
+ UNIX_BLOCK_IO_PRIVATE *Private;
+ EFI_TPL OldTpl;
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ Private = UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ if (Private->fd >= 0) {
+ Private->UnixThunk->Close (Private->fd);
+ Private->fd = -1;
+ }
+
+ gBS->RestoreTPL (OldTpl);
+
+ return EFI_SUCCESS;
+}
+
+UINTN
+Atoi (
+ CHAR16 *String
+ )
+/*++
+
+Routine Description:
+
+ Convert a unicode string to a UINTN
+
+Arguments:
+
+ String - Unicode string.
+
+Returns:
+
+ UINTN of the number represented by String.
+
+--*/
+{
+ UINTN Number;
+ CHAR16 *Str;
+
+ //
+ // skip preceeding white space
+ //
+ Str = String;
+ while ((*Str) && (*Str == ' ')) {
+ Str++;
+ }
+ //
+ // Convert ot a Number
+ //
+ Number = 0;
+ while (*Str != '\0') {
+ if ((*Str >= '0') && (*Str <= '9')) {
+ Number = (Number * 10) +*Str - '0';
+ } else {
+ break;
+ }
+
+ Str++;
+ }
+
+ return Number;
+}
+
+EFI_STATUS
+SetFilePointer64 (
+ IN UNIX_BLOCK_IO_PRIVATE *Private,
+ IN INT64 DistanceToMove,
+ OUT UINT64 *NewFilePointer,
+ IN INTN MoveMethod
+ )
+/*++
+
+This function extends the capability of SetFilePointer to accept 64 bit parameters
+
+--*/
+// TODO: function comment is missing 'Routine Description:'
+// TODO: function comment is missing 'Arguments:'
+// TODO: function comment is missing 'Returns:'
+// TODO: Private - add argument and description to function comment
+// TODO: DistanceToMove - add argument and description to function comment
+// TODO: NewFilePointer - add argument and description to function comment
+// TODO: MoveMethod - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ off_t res;
+
+ res = Private->UnixThunk->Lseek(Private->fd, DistanceToMove, MoveMethod);
+ if (res == -1) {
+ Status = EFI_INVALID_PARAMETER;
+ }
+
+ if (NewFilePointer != NULL) {
+ *NewFilePointer = res;
+ }
+
+ return Status;
+}
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h
new file mode 100644
index 0000000000..c446f31d95
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.h
@@ -0,0 +1,219 @@
+/*++
+
+Copyright (c) 2004 - 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:
+
+ UnixBlockIo.h
+
+Abstract:
+
+ Produce block IO abstractions for real devices on your PC using Posix APIs.
+ The configuration of what devices to mount or emulate comes from UNIX
+ environment variables. The variables must be visible to the Microsoft*
+ Developer Studio for them to work.
+
+ * Other names and brands may be claimed as the property of others.
+
+--*/
+
+#ifndef _UNIX_BLOCK_IO_H_
+#define _UNIX_BLOCK_IO_H_
+
+#include "PiDxe.h"
+#include <Protocol/BlockIo.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"
+
+#define FILENAME_BUFFER_SIZE 80
+
+//
+// Language supported for driverconfiguration protocol
+//
+#define LANGUAGESUPPORTED "eng"
+
+#define UNIX_BLOCK_IO_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('L', 'X', 'b', 'k')
+typedef struct {
+ UINTN Signature;
+
+ EFI_LOCK Lock;
+
+ char Filename[FILENAME_BUFFER_SIZE];
+ UINTN ReadMode;
+ UINTN Mode;
+
+ int fd;
+
+ UINT64 LastBlock;
+ UINTN BlockSize;
+ UINT64 NumberOfBlocks;
+
+ EFI_HANDLE EfiHandle;
+ EFI_BLOCK_IO_PROTOCOL BlockIo;
+ EFI_BLOCK_IO_MEDIA Media;
+
+ EFI_UNICODE_STRING_TABLE *ControllerNameTable;
+
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+
+} UNIX_BLOCK_IO_PRIVATE;
+
+#define UNIX_BLOCK_IO_PRIVATE_DATA_FROM_THIS(a) \
+ CR(a, UNIX_BLOCK_IO_PRIVATE, BlockIo, UNIX_BLOCK_IO_PRIVATE_SIGNATURE)
+
+#define LIST_BUFFER_SIZE 512
+
+//
+// Block I/O Global Variables
+//
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixBlockIoDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixBlockIoComponentName;
+extern EFI_DRIVER_CONFIGURATION_PROTOCOL gUnixBlockIoDriverConfiguration;
+extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL gUnixBlockIoDriverDiagnostics;
+
+//
+// EFI Driver Binding Functions
+//
+EFI_STATUS
+EFIAPI
+UnixBlockIoDriverBindingSupported (
+ 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
+UnixBlockIoDriverBindingStart (
+ 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
+UnixBlockIoDriverBindingStop (
+ 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
+SetFilePointer64 (
+ IN UNIX_BLOCK_IO_PRIVATE *Private,
+ IN INT64 DistanceToMove,
+ OUT UINT64 *NewFilePointer,
+ IN INT32 MoveMethod
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+ DistanceToMove - TODO: add argument description
+ NewFilePointer - TODO: add argument description
+ MoveMethod - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+UINTN
+Atoi (
+ CHAR16 *String
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ String - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+#endif
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf
new file mode 100644
index 0000000000..00371add9d
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf
@@ -0,0 +1,71 @@
+#/** @file
+# Block Io driver
+#
+# Produce block IO abstractions for real devices on your PC using Unix APIs.
+# The configuration of what devices to mount or emulate comes from
+# environment variables.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixBlockIo
+ FILE_GUID = f3085888-8985-11db-9c93-0040d02b1835
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeUnixBlockIo
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+# DRIVER_BINDING = gUnixBlockIoDriverBinding
+# COMPONENT_NAME = gUnixBlockIoComponentName
+# DRIVER_DIAG = gUnixBlockIoDriverDiagnostics
+#
+
+[Sources.common]
+ DriverDiagnostics.c
+ DriverConfiguration.c
+ ComponentName.c
+ UnixBlockIo.c
+ UnixBlockIo.h
+ EntryPoint.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ UefiLib
+ UefiDriverEntryPoint
+ BaseLib
+ DebugLib
+
+
+[Guids]
+ gEfiUnixPhysicalDisksGuid # SOMETIMES_CONSUMED
+ gEfiUnixVirtualDisksGuid # ALWAYS_CONSUMED
+
+
+[Protocols]
+ gEfiBlockIoProtocolGuid # PROTOCOL BY_START
+ gEfiUnixIoProtocolGuid # PROTOCOL TO_START
+
diff --git a/UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa
new file mode 100644
index 0000000000..49334904b0
--- /dev/null
+++ b/UnixPkg/UnixBlockIoDxe/UnixBlockIo.msa
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>UnixBlockIo</ModuleName>
+ <ModuleType>UEFI_DRIVER</ModuleType>
+ <GuidValue>f3085888-8985-11db-9c93-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Block Io driver</Abstract>
+ <Description>
+ Produce block IO abstractions for real devices on your PC using Unix APIs.
+ The configuration of what devices to mount or emulate comes from
+ environment variables.
+ </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>UnixBlockIo</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverModelLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixBlockIo.h</Filename>
+ <Filename>UnixBlockIo.c</Filename>
+ <Filename>ComponentName.c</Filename>
+ <Filename>DriverConfiguration.c</Filename>
+ <Filename>DriverDiagnostics.c</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="TO_START">
+ <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="BY_START">
+ <ProtocolCName>gEfiBlockIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixVirtualDisksGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiUnixPhysicalDisksGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <DriverBinding>gUnixBlockIoDriverBinding</DriverBinding>
+ <ComponentName>gUnixBlockIoComponentName</ComponentName>
+ <DriverDiag>gUnixBlockIoDriverDiagnostics</DriverDiag>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixBusDriverDxe/ComponentName.c b/UnixPkg/UnixBusDriverDxe/ComponentName.c
new file mode 100644
index 0000000000..7ea1eacc1a
--- /dev/null
+++ b/UnixPkg/UnixBusDriverDxe/ComponentName.c
@@ -0,0 +1,208 @@
+/*++
+
+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:
+
+ ComponentName.c
+
+Abstract:
+
+--*/
+
+#include "UnixBusDriver.h"
+
+//
+// EFI Component Name Functions
+//
+EFI_STATUS
+EFIAPI
+UnixBusDriverComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ );
+
+EFI_STATUS
+EFIAPI
+UnixBusDriverComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ );
+
+//
+// EFI Component Name Protocol
+//
+EFI_COMPONENT_NAME_PROTOCOL gUnixBusDriverComponentName = {
+ UnixBusDriverComponentNameGetDriverName,
+ UnixBusDriverComponentNameGetControllerName,
+ "eng"
+};
+
+static EFI_UNICODE_STRING_TABLE mUnixBusDriverNameTable[] = {
+ { "eng", L"Unix Bus Driver" },
+ { NULL , NULL }
+};
+
+EFI_STATUS
+EFIAPI
+UnixBusDriverComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the driver name that that the caller
+ is requesting, and it must match one of the languages specified
+ in SupportedLanguages. The number of languages supported by a
+ driver is up to the driver writer.
+ DriverName - A pointer to the Unicode string to return. This Unicode string
+ is the name of the driver specified by This in the language
+ specified by Language.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the Driver specified by This
+ and the language specified by Language was returned
+ in DriverName.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - DriverName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ return LookupUnicodeString (
+ Language,
+ gUnixBusDriverComponentName.SupportedLanguages,
+ mUnixBusDriverNameTable,
+ DriverName
+ );
+}
+
+EFI_STATUS
+EFIAPI
+UnixBusDriverComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by an EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ ControllerHandle - The handle of a controller that the driver specified by
+ This is managing. This handle specifies the controller
+ whose name is to be returned.
+ ChildHandle - The handle of the child controller to retrieve the name
+ of. 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 retrieve the name of the
+ bus controller. It will not be NULL for a bus driver
+ that wishes to retrieve the name of a child controller.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language of the controller name
+ that that the caller is requesting, and it must match one
+ of the languages specified in SupportedLanguages. The
+ number of languages supported by a driver is up to the
+ driver writer.
+ ControllerName - A pointer to the Unicode string to return. This Unicode
+ string is the name of the controller specified by
+ ControllerHandle and ChildHandle in the language specified
+ by Language from the point of view of the driver specified
+ by This.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the user readable name in the
+ language specified by Language for the driver
+ specified by This was returned in DriverName.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ControllerName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This is not currently managing
+ the controller specified by ControllerHandle and
+ ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ UNIX_IO_DEVICE *Private;
+
+ //
+ // Make sure this driver is currently managing ControllHandle
+ //
+ Status = EfiTestManagedDevice (
+ ControllerHandle,
+ gUnixBusDriverBinding.DriverBindingHandle,
+ &gEfiUnixThunkProtocolGuid
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // This is a bus driver, so ChildHandle can not be NULL.
+ //
+ if (ChildHandle == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = EfiTestChildHandle (
+ ControllerHandle,
+ ChildHandle,
+ &gEfiUnixThunkProtocolGuid
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Get our context back
+ //
+ Status = gBS->OpenProtocol (
+ ChildHandle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID**)&UnixIo,
+ gUnixBusDriverBinding.DriverBindingHandle,
+ ChildHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_IO_DEVICE_FROM_THIS (UnixIo);
+
+ return LookupUnicodeString (
+ Language,
+ gUnixBusDriverComponentName.SupportedLanguages,
+ Private->ControllerNameTable,
+ ControllerName
+ );
+}
diff --git a/UnixPkg/UnixBusDriverDxe/EntryPoint.c b/UnixPkg/UnixBusDriverDxe/EntryPoint.c
new file mode 100644
index 0000000000..71a5bdaaec
--- /dev/null
+++ b/UnixPkg/UnixBusDriverDxe/EntryPoint.c
@@ -0,0 +1,51 @@
+/**@file
+ Entry Point Source file.
+
+ This file contains the user entry point
+
+ 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.
+**/
+
+
+
+#include "UnixBusDriver.h"
+
+/**
+ The user Entry Point for module UnixBusDriver. The user code starts with this function.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeUnixBusDriver(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = EfiLibInstallAllDriverProtocols (
+ ImageHandle,
+ SystemTable,
+ &gUnixBusDriverBinding,
+ ImageHandle,
+ &gUnixBusDriverComponentName,
+ NULL,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+
+
+ return Status;
+}
diff --git a/UnixPkg/UnixBusDriverDxe/UnixBusDriver.c b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.c
new file mode 100644
index 0000000000..b6b2ac6b77
--- /dev/null
+++ b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.c
@@ -0,0 +1,716 @@
+/*+++
+
+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:
+
+ UnixBusDriver.c
+
+Abstract:
+
+This following section documents the envirnoment variables for the Win UNIX
+build. These variables are used to define the (virtual) hardware
+configuration of the UNIX environment
+
+A ! can be used to seperate multiple instances in a variable. Each
+instance represents a seperate hardware device.
+
+EFI_UNIX_PHYSICAL_DISKS - maps to drives on your system
+EFI_UNIX_VIRTUAL_DISKS - maps to a device emulated by a file
+EFI_UNIX_FILE_SYSTEM - mouts a directory as a file system
+EFI_UNIX_CONSOLE - make a logical comand line window (only one!)
+EFI_UNIX_UGA - Builds UGA Windows of Width and Height
+
+ <F>ixed - Fixed disk like a hard drive.
+ <R>emovable - Removable media like a floppy or CD-ROM.
+ Read <O>nly - Write protected device.
+ Read <W>rite - Read write device.
+ <block count> - Decimal number of blocks a device supports.
+ <block size> - Decimal number of bytes per block.
+
+ UNIX envirnonment variable contents. '<' and '>' are not part of the variable,
+ they are just used to make this help more readable. There should be no
+ spaces between the ';'. Extra spaces will break the variable. A '!' is
+ used to seperate multiple devices in a variable.
+
+ EFI_UNIX_VIRTUAL_DISKS =
+ <F | R><O | W>;<block count>;<block size>[!...]
+
+ EFI_UNIX_PHYSICAL_DISKS =
+ <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]
+
+ Virtual Disks: These devices use a file to emulate a hard disk or removable
+ media device.
+
+ Thus a 20 MB emulated hard drive would look like:
+ EFI_UNIX_VIRTUAL_DISKS=FW;40960;512
+
+ A 1.44MB emulated floppy with a block size of 1024 would look like:
+ EFI_UNIX_VIRTUAL_DISKS=RW;1440;1024
+
+ Physical Disks: These devices use UNIX to open a real device in your system
+
+ Thus a 120 MB floppy would look like:
+ EFI_UNIX_PHYSICAL_DISKS=B:RW;245760;512
+
+ Thus a standard CD-ROM floppy would look like:
+ EFI_UNIX_PHYSICAL_DISKS=Z:RO;307200;2048
+
+ EFI_UNIX_FILE_SYSTEM =
+ <directory path>[!...]
+
+ Mounting the two directories C:\FOO and C:\BAR would look like:
+ EFI_UNIX_FILE_SYSTEM=c:\foo!c:\bar
+
+ EFI_UNIX_CONSOLE =
+ <window title>
+
+ Declaring a text console window with the title "My EFI Console" woild look like:
+ EFI_UNIX_CONSOLE=My EFI Console
+
+ EFI_UNIX_UGA =
+ <width> <height>[!...]
+
+ Declaring a two UGA windows with resolutions of 800x600 and 1024x768 would look like:
+ Example : EFI_UNIX_UGA=800 600!1024 768
+
+ EFI_UNIX_PASS_THROUGH =
+ <BaseAddress>;<Bus#>;<Device#>;<Function#>
+
+ Declaring a base address of 0xE0000000 (used for PCI Express devices)
+ and having NT32 talk to a device located at bus 0, device 1, function 0:
+ Example : EFI_UNIX_PASS_THROUGH=E000000;0;1;0
+
+---*/
+
+#include "UnixBusDriver.h"
+
+//
+// Define GUID for the Unix Bus Driver
+//
+static EFI_GUID gUnixBusDriverGuid = {
+ 0x419f582, 0x625, 0x4531, {0x8a, 0x33, 0x85, 0xa9, 0x96, 0x5c, 0x95, 0xbc}
+};
+
+//
+// DriverBinding protocol global
+//
+EFI_DRIVER_BINDING_PROTOCOL gUnixBusDriverBinding = {
+ UnixBusDriverBindingSupported,
+ UnixBusDriverBindingStart,
+ UnixBusDriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+#define UNIX_PCD_ARRAY_SIZE (sizeof(mPcdEnvironment)/sizeof(UNIX_PCD_ENTRY))
+
+//
+// Table to map UNIX Environment variable to the GUID that should be in
+// device path.
+//
+static UNIX_PCD_ENTRY mPcdEnvironment[] = {
+ {PcdToken(PcdUnixConsole), &gEfiUnixConsoleGuid},
+ {PcdToken(PcdUnixUga), &gEfiUnixUgaGuid},
+ {PcdToken(PcdUnixFileSystem), &gEfiUnixFileSystemGuid},
+ {PcdToken(PcdUnixSerialPort), &gEfiUnixSerialPortGuid},
+ {PcdToken(PcdUnixVirtualDisk), &gEfiUnixVirtualDisksGuid},
+ {PcdToken(PcdUnixPhysicalDisk), &gEfiUnixPhysicalDisksGuid},
+ {PcdToken(PcdUnixCpuModel), &gEfiUnixCPUModelGuid},
+ {PcdToken(PcdUnixCpuSpeed), &gEfiUnixCPUSpeedGuid},
+ {PcdToken(PcdUnixMemorySize), &gEfiUnixMemoryGuid}
+};
+
+VOID *
+AllocateMemory (
+ IN UINTN Size
+ )
+{
+ EFI_STATUS Status;
+ VOID *Buffer;
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ Size,
+ (VOID *)&Buffer
+ );
+ if (EFI_ERROR (Status)) {
+ ASSERT (FALSE);
+ return NULL;
+ }
+ return Buffer;
+}
+
+
+EFI_STATUS
+EFIAPI
+UnixBusDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: ControllerHandle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+// TODO: EFI_UNSUPPORTED - add return value to function comment
+// TODO: EFI_UNSUPPORTED - add return value to function comment
+// TODO: EFI_SUCCESS - add return value to function comment
+// TODO: EFI_SUCCESS - add return value to function comment
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+ UINTN Index;
+
+ //
+ // Check the contents of the first Device Path Node of RemainingDevicePath to make sure
+ // it is a legal Device Path Node for this bus driver's children.
+ //
+ if (RemainingDevicePath != NULL) {
+ if (RemainingDevicePath->Type != HARDWARE_DEVICE_PATH ||
+ RemainingDevicePath->SubType != HW_VENDOR_DP ||
+ DevicePathNodeLength(RemainingDevicePath) != sizeof(UNIX_VENDOR_DEVICE_PATH_NODE)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ for (Index = 0; Index < UNIX_PCD_ARRAY_SIZE; Index++) {
+ if (CompareGuid (&((VENDOR_DEVICE_PATH *) RemainingDevicePath)->Guid, mPcdEnvironment[Index].DevicePathGuid)) {
+ break;
+ }
+ }
+
+ if (Index >= UNIX_PCD_ARRAY_SIZE) {
+ return EFI_UNSUPPORTED;
+ }
+ }
+
+ //
+ // Open the IO Abstraction(s) needed to perform the supported test
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ (VOID **)&ParentDevicePath,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (Status == EFI_ALREADY_STARTED) {
+ return EFI_SUCCESS;
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixThunkProtocolGuid,
+ (VOID **)&UnixThunk,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (Status == EFI_ALREADY_STARTED) {
+ return EFI_SUCCESS;
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Since we call through UnixThunk we need to make sure it's valid
+ //
+ Status = EFI_SUCCESS;
+ if (UnixThunk->Signature != EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {
+ Status = EFI_UNSUPPORTED;
+ }
+
+ //
+ // Close the I/O Abstraction(s) used to perform the supported test
+ //
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixThunkProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixBusDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: ControllerHandle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
+// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
+// TODO: EFI_SUCCESS - add return value to function comment
+{
+ EFI_STATUS Status;
+ EFI_STATUS InstallStatus;
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
+ UNIX_BUS_DEVICE *UnixBusDevice;
+ UNIX_IO_DEVICE *UnixDevice;
+ UINTN Index;
+ CHAR16 *StartString;
+ CHAR16 *SubString;
+ UINT16 Count;
+ UINTN StringSize;
+ UINT16 ComponentName[MAX_UNIX_ENVIRNMENT_VARIABLE_LENGTH];
+ UNIX_VENDOR_DEVICE_PATH_NODE *Node;
+ BOOLEAN CreateDevice;
+ CHAR16 *TempStr;
+ CHAR16 *PcdTempStr;
+ UINTN TempStrSize;
+
+ Status = EFI_UNSUPPORTED;
+
+ //
+ // Grab the protocols we need
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ (VOID **)&ParentDevicePath,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
+ return Status;
+ }
+
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixThunkProtocolGuid,
+ (VOID **)&UnixThunk,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
+ return Status;
+ }
+
+ if (Status != EFI_ALREADY_STARTED) {
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ sizeof (UNIX_BUS_DEVICE),
+ (VOID *) &UnixBusDevice
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ UnixBusDevice->Signature = UNIX_BUS_DEVICE_SIGNATURE;
+ UnixBusDevice->ControllerNameTable = NULL;
+
+ AddUnicodeString (
+ "eng",
+ gUnixBusDriverComponentName.SupportedLanguages,
+ &UnixBusDevice->ControllerNameTable,
+ L"Unix Bus Controller"
+ );
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &ControllerHandle,
+ &gUnixBusDriverGuid,
+ UnixBusDevice,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ FreeUnicodeStringTable (UnixBusDevice->ControllerNameTable);
+ gBS->FreePool (UnixBusDevice);
+ return Status;
+ }
+ }
+
+ //
+ // Loop on the Variable list. Parse each variable to produce a set of handles that
+ // represent virtual hardware devices.
+ //
+ InstallStatus = EFI_NOT_FOUND;
+ for (Index = 0; Index < UNIX_PCD_ARRAY_SIZE; Index++) {
+ PcdTempStr = (VOID *)LibPcdGetPtr (mPcdEnvironment[Index].Token);
+ ASSERT (PcdTempStr != NULL);
+
+ TempStrSize = StrLen (PcdTempStr);
+ TempStr = AllocateMemory ((TempStrSize * sizeof (CHAR16)) + 1);
+ StrCpy (TempStr, PcdTempStr);
+
+ StartString = TempStr;
+
+ //
+ // Parse the envirnment variable into sub strings using '!' as a delimator.
+ // Each substring needs it's own handle to be added to the system. This code
+ // does not understand the sub string. Thats the device drivers job.
+ //
+ Count = 0;
+ while (*StartString != '\0') {
+
+ //
+ // Find the end of the sub string
+ //
+ SubString = StartString;
+ while (*SubString != '\0' && *SubString != '!') {
+ SubString++;
+ }
+
+ if (*SubString == '!') {
+ //
+ // Replace token with '\0' to make sub strings. If this is the end
+ // of the string SubString will already point to NULL.
+ //
+ *SubString = '\0';
+ SubString++;
+ }
+
+ CreateDevice = TRUE;
+ if (RemainingDevicePath != NULL) {
+ CreateDevice = FALSE;
+ Node = (UNIX_VENDOR_DEVICE_PATH_NODE *) RemainingDevicePath;
+ if (Node->VendorDevicePath.Header.Type == HARDWARE_DEVICE_PATH &&
+ Node->VendorDevicePath.Header.SubType == HW_VENDOR_DP &&
+ DevicePathNodeLength (&Node->VendorDevicePath.Header) == sizeof (UNIX_VENDOR_DEVICE_PATH_NODE)
+ ) {
+ if (CompareGuid (&Node->VendorDevicePath.Guid, mPcdEnvironment[Index].DevicePathGuid) &&
+ Node->Instance == Count
+ ) {
+ CreateDevice = TRUE;
+ }
+ }
+ }
+
+ if (CreateDevice) {
+ //
+ // Allocate instance structure, and fill in parent information.
+ //
+ UnixDevice = AllocateMemory (sizeof (UNIX_IO_DEVICE));
+ if (UnixDevice == NULL) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ UnixDevice->Handle = NULL;
+ UnixDevice->ControllerHandle = ControllerHandle;
+ UnixDevice->ParentDevicePath = ParentDevicePath;
+
+ UnixDevice->UnixIo.UnixThunk = UnixThunk;
+
+ //
+ // Plus 2 to account for the NULL at the end of the Unicode string
+ //
+ StringSize = (UINTN) ((UINT8 *) SubString - (UINT8 *) StartString) + sizeof (CHAR16);
+ UnixDevice->UnixIo.EnvString = AllocateMemory (StringSize);
+ if (UnixDevice->UnixIo.EnvString != NULL) {
+ CopyMem (UnixDevice->UnixIo.EnvString, StartString, StringSize);
+ }
+
+ UnixDevice->ControllerNameTable = NULL;
+
+ // FIXME: check size
+ StrCpy(ComponentName, UnixDevice->UnixIo.EnvString);
+
+ UnixDevice->DevicePath = UnixBusCreateDevicePath (
+ ParentDevicePath,
+ mPcdEnvironment[Index].DevicePathGuid,
+ Count
+ );
+ if (UnixDevice->DevicePath == NULL) {
+ gBS->FreePool (UnixDevice);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ AddUnicodeString (
+ "eng",
+ gUnixBusDriverComponentName.SupportedLanguages,
+ &UnixDevice->ControllerNameTable,
+ ComponentName
+ );
+
+ UnixDevice->UnixIo.TypeGuid = mPcdEnvironment[Index].DevicePathGuid;
+ UnixDevice->UnixIo.InstanceNumber = Count;
+
+ UnixDevice->Signature = UNIX_IO_DEVICE_SIGNATURE;
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &UnixDevice->Handle,
+ &gEfiDevicePathProtocolGuid,
+ UnixDevice->DevicePath,
+ &gEfiUnixIoProtocolGuid,
+ &UnixDevice->UnixIo,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ FreeUnicodeStringTable (UnixDevice->ControllerNameTable);
+ gBS->FreePool (UnixDevice);
+ } else {
+ //
+ // Open For Child Device
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixThunkProtocolGuid,
+ (VOID **)&UnixThunk,
+ This->DriverBindingHandle,
+ UnixDevice->Handle,
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
+ );
+ if (!EFI_ERROR (Status)) {
+ InstallStatus = EFI_SUCCESS;
+ }
+ }
+ }
+
+ //
+ // Parse Next sub string. This will point to '\0' if we are at the end.
+ //
+ Count++;
+ StartString = SubString;
+ }
+
+ gBS->FreePool (TempStr);
+ }
+
+ return EFI_SUCCESS;
+}
+
+
+EFI_STATUS
+EFIAPI
+UnixBusDriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: ControllerHandle - add argument and description to function comment
+// TODO: NumberOfChildren - add argument and description to function comment
+// TODO: ChildHandleBuffer - add argument and description to function comment
+// TODO: EFI_SUCCESS - add return value to function comment
+// TODO: EFI_DEVICE_ERROR - add return value to function comment
+// TODO: EFI_SUCCESS - add return value to function comment
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ BOOLEAN AllChildrenStopped;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ UNIX_BUS_DEVICE *UnixBusDevice;
+ UNIX_IO_DEVICE *UnixDevice;
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+
+ //
+ // Complete all outstanding transactions to Controller.
+ // Don't allow any new transaction to Controller to be started.
+ //
+
+ if (NumberOfChildren == 0) {
+ //
+ // Close the bus driver
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gUnixBusDriverGuid,
+ (VOID **)&UnixBusDevice,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ gBS->UninstallMultipleProtocolInterfaces (
+ ControllerHandle,
+ &gUnixBusDriverGuid,
+ UnixBusDevice,
+ NULL
+ );
+
+ FreeUnicodeStringTable (UnixBusDevice->ControllerNameTable);
+
+ gBS->FreePool (UnixBusDevice);
+
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixThunkProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiDevicePathProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+ return EFI_SUCCESS;
+ }
+
+ AllChildrenStopped = TRUE;
+
+ for (Index = 0; Index < NumberOfChildren; Index++) {
+
+ Status = gBS->OpenProtocol (
+ ChildHandleBuffer[Index],
+ &gEfiUnixIoProtocolGuid,
+ (VOID **)&UnixIo,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (!EFI_ERROR (Status)) {
+
+ UnixDevice = UNIX_IO_DEVICE_FROM_THIS (UnixIo);
+
+ Status = gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixThunkProtocolGuid,
+ This->DriverBindingHandle,
+ UnixDevice->Handle
+ );
+
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ UnixDevice->Handle,
+ &gEfiDevicePathProtocolGuid,
+ UnixDevice->DevicePath,
+ &gEfiUnixIoProtocolGuid,
+ &UnixDevice->UnixIo,
+ NULL
+ );
+
+ if (EFI_ERROR (Status)) {
+ gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixThunkProtocolGuid,
+ (VOID **) &UnixThunk,
+ This->DriverBindingHandle,
+ UnixDevice->Handle,
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
+ );
+ } else {
+ //
+ // Close the child handle
+ //
+ FreeUnicodeStringTable (UnixDevice->ControllerNameTable);
+ gBS->FreePool (UnixDevice);
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ AllChildrenStopped = FALSE;
+ }
+ }
+
+ if (!AllChildrenStopped) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_DEVICE_PATH_PROTOCOL *
+UnixBusCreateDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath,
+ IN EFI_GUID *Guid,
+ IN UINT16 InstanceNumber
+ )
+/*++
+
+Routine Description:
+ Create a device path node using Guid and InstanceNumber and append it to
+ the passed in RootDevicePath
+
+Arguments:
+ RootDevicePath - Root of the device path to return.
+
+ Guid - GUID to use in vendor device path node.
+
+ InstanceNumber - Instance number to use in the vendor device path. This
+ argument is needed to make sure each device path is unique.
+
+Returns:
+
+ EFI_DEVICE_PATH_PROTOCOL
+
+--*/
+{
+ UNIX_VENDOR_DEVICE_PATH_NODE DevicePath;
+
+ DevicePath.VendorDevicePath.Header.Type = HARDWARE_DEVICE_PATH;
+ DevicePath.VendorDevicePath.Header.SubType = HW_VENDOR_DP;
+ SetDevicePathNodeLength (&DevicePath.VendorDevicePath.Header, sizeof (UNIX_VENDOR_DEVICE_PATH_NODE));
+
+ //
+ // The GUID defines the Class
+ //
+ CopyMem (&DevicePath.VendorDevicePath.Guid, Guid, sizeof (EFI_GUID));
+
+ //
+ // Add an instance number so we can make sure there are no Device Path
+ // duplication.
+ //
+ DevicePath.Instance = InstanceNumber;
+
+ return AppendDevicePathNode (
+ RootDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *) &DevicePath
+ );
+}
diff --git a/UnixPkg/UnixBusDriverDxe/UnixBusDriver.h b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.h
new file mode 100644
index 0000000000..ffc3881544
--- /dev/null
+++ b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.h
@@ -0,0 +1,312 @@
+/*++
+
+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:
+
+ UnixBusDriver.h
+
+Abstract:
+
+This following section documents the PCD for the Unix
+build. These variables are used to define the (virtual) hardware
+configuration of the Unix environment
+
+A ! can be used to seperate multiple instances in a variable. Each
+instance represents a seperate hardware device.
+
+EFI_UNIX_PHYSICAL_DISKS - maps to drives on your system
+EFI_UNIX_VIRTUAL_DISKS - maps to a device emulated by a file
+EFI_UNIX_FILE_SYSTEM - mouts a directory as a file system
+EFI_UNIX_CONSOLE - make a logical comand line window (only one!)
+EFI_UNIX_UGA - Builds UGA Windows of Width and Height
+EFI_UNIX_SERIAL_PORT - maps physical serial ports
+EFI_UNIX_PASS_THRU - associates a device with our PCI support
+
+ <F>ixed - Fixed disk like a hard drive.
+ <R>emovable - Removable media like a floppy or CD-ROM.
+ Read <O>nly - Write protected device.
+ Read <W>rite - Read write device.
+ <block count> - Decimal number of blocks a device supports.
+ <block size> - Decimal number of bytes per block.
+
+ UNIX envirnonment variable contents. '<' and '>' are not part of the variable,
+ they are just used to make this help more readable. There should be no
+ spaces between the ';'. Extra spaces will break the variable. A '!' is
+ used to seperate multiple devices in a variable.
+
+ EFI_UNIX_VIRTUAL_DISKS =
+ <F | R><O | W>;<block count>;<block size>[!...]
+
+ EFI_UNIX_PHYSICAL_DISKS =
+ <drive letter>:<F | R><O | W>;<block count>;<block size>[!...]
+
+ Virtual Disks: These devices use a file to emulate a hard disk or removable
+ media device.
+
+ Thus a 20 MB emulated hard drive would look like:
+ EFI_UNIX_VIRTUAL_DISKS=FW;40960;512
+
+ A 1.44MB emulated floppy with a block size of 1024 would look like:
+ EFI_UNIX_VIRTUAL_DISKS=RW;1440;1024
+
+ Physical Disks: These devices use UNIX to open a real device in your system
+
+ Thus a 120 MB floppy would look like:
+ EFI_UNIX_PHYSICAL_DISKS=B:RW;245760;512
+
+ Thus a standard CD-ROM floppy would look like:
+ EFI_UNIX_PHYSICAL_DISKS=Z:RO;307200;2048
+
+ EFI_UNIX_FILE_SYSTEM =
+ <directory path>[!...]
+
+ Mounting the two directories C:\FOO and C:\BAR would look like:
+ EFI_UNIX_FILE_SYSTEM=c:\foo!c:\bar
+
+ EFI_UNIX_CONSOLE =
+ <window title>
+
+ Declaring a text console window with the title "My EFI Console" woild look like:
+ EFI_UNIX_CONSOLE=My EFI Console
+
+ EFI_UNIX_UGA =
+ <width> <height>[!...]
+
+ Declaring a two UGA windows with resolutions of 800x600 and 1024x768 would look like:
+ Example : EFI_UNIX_UGA=800 600!1024 768
+
+ EFI_UNIX_SERIAL_PORT =
+ <port name>[!...]
+
+ Declaring two serial ports on COM1 and COM2 would look like:
+ Example : EFI_UNIX_SERIAL_PORT=COM1!COM2
+
+ EFI_UNIX_PASS_THROUGH =
+ <BaseAddress>;<Bus#>;<Device#>;<Function#>
+
+ Declaring a base address of 0xE0000000 (used for PCI Express devices)
+ and having NT32 talk to a device located at bus 0, device 1, function 0:
+ Example : EFI_UNIX_PASS_THROUGH=E000000;0;1;0
+
+---*/
+
+#ifndef __UNIX_BUS_DRIVER_H__
+#define __UNIX_BUS_DRIVER_H__
+#include "PiDxe.h"
+#include "UnixDxe.h"
+#include <Protocol/Pcd.h>
+#include <Protocol/DevicePath.h>
+
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiLib.h>
+#include <Library/PcdLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DevicePathLib.h>
+
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixBusDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixBusDriverComponentName;
+
+//
+// Unix Bus Driver Global Variables
+//
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixBusDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixBusDriverComponentName;
+
+//
+// Unix Bus Controller Structure
+//
+#define UNIX_BUS_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('L', 'X', 'B', 'D')
+
+typedef struct {
+ UINT64 Signature;
+ EFI_UNICODE_STRING_TABLE *ControllerNameTable;
+} UNIX_BUS_DEVICE;
+
+//
+// Unix Child Device Controller Structure
+//
+#define UNIX_IO_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('L', 'X', 'V', 'D')
+
+typedef struct {
+ UINT64 Signature;
+ EFI_HANDLE Handle;
+ EFI_UNIX_IO_PROTOCOL UnixIo;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+
+ //
+ // Private data about the parent
+ //
+ EFI_HANDLE ControllerHandle;
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
+
+ EFI_UNICODE_STRING_TABLE *ControllerNameTable;
+
+} UNIX_IO_DEVICE;
+
+#define UNIX_IO_DEVICE_FROM_THIS(a) \
+ CR(a, UNIX_IO_DEVICE, UnixIo, UNIX_IO_DEVICE_SIGNATURE)
+
+//
+// This is the largest env variable we can parse
+//
+#define MAX_UNIX_ENVIRNMENT_VARIABLE_LENGTH 512
+
+typedef struct {
+ UINTN Token;
+ EFI_GUID *DevicePathGuid;
+} UNIX_PCD_ENTRY;
+
+typedef struct {
+ VENDOR_DEVICE_PATH VendorDevicePath;
+ UINT32 Instance;
+} UNIX_VENDOR_DEVICE_PATH_NODE;
+
+EFI_STATUS
+EFIAPI
+CpuIoInitialize (
+ 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
+
+--*/
+;
+
+//
+// Driver Binding Protocol function prototypes
+//
+EFI_STATUS
+EFIAPI
+UnixBusDriverBindingSupported (
+ 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
+UnixBusDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ParentHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ ParentHandle - TODO: add argument description
+ RemainingDevicePath - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixBusDriverBindingStop (
+ 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
+
+--*/
+;
+
+//
+// Unix Bus Driver private worker functions
+//
+EFI_DEVICE_PATH_PROTOCOL *
+UnixBusCreateDevicePath (
+ IN EFI_DEVICE_PATH_PROTOCOL *RootDevicePath,
+ IN EFI_GUID *Guid,
+ IN UINT16 InstanceNumber
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ RootDevicePath - TODO: add argument description
+ Guid - TODO: add argument description
+ InstanceNumber - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+
+#endif
diff --git a/UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf
new file mode 100644
index 0000000000..d3b0f4c19c
--- /dev/null
+++ b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf
@@ -0,0 +1,92 @@
+#/** @file
+# Unix Bus driver
+#
+# 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
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixBusDriver
+ FILE_GUID = f320d656-8985-11db-90e0-0040d02b1835
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeUnixBusDriver
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+# DRIVER_BINDING = gUnixBusDriverBinding
+# COMPONENT_NAME = gUnixBusDriverComponentName
+#
+
+[Sources.common]
+ ComponentName.c
+ UnixBusDriver.c
+ UnixBusDriver.h
+ EntryPoint.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ DevicePathLib
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ PcdLib
+ UefiLib
+ UefiDriverEntryPoint
+ BaseLib
+ DebugLib
+
+
+[Guids]
+ gEfiUnixConsoleGuid # ALWAYS_CONSUMED
+ gEfiUnixUgaGuid # ALWAYS_CONSUMED
+ gEfiUnixSerialPortGuid # ALWAYS_CONSUMED
+ gEfiUnixFileSystemGuid # ALWAYS_CONSUMED
+ gEfiUnixPhysicalDisksGuid # ALWAYS_CONSUMED
+ gEfiUnixVirtualDisksGuid # ALWAYS_CONSUMED
+ gEfiUnixCPUModelGuid
+ gEfiUnixCPUSpeedGuid
+ gEfiUnixMemoryGuid
+
+
+[Protocols]
+ gPcdProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+ gEfiDevicePathProtocolGuid # PROTOCOL TO_START
+ gEfiUnixThunkProtocolGuid # PROTOCOL TO_START
+ gEfiUnixIoProtocolGuid # PROTOCOL BY_START
+
+
+[Pcd.common]
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixSerialPort
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySize
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuSpeed
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuModel
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixPhysicalDisk
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixVirtualDisk
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFileSystem
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixUga
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixConsole
+
diff --git a/UnixPkg/UnixBusDriverDxe/UnixBusDriver.msa b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.msa
new file mode 100644
index 0000000000..6422c062f5
--- /dev/null
+++ b/UnixPkg/UnixBusDriverDxe/UnixBusDriver.msa
@@ -0,0 +1,177 @@
+<?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>UnixBusDriver</ModuleName>
+ <ModuleType>UEFI_DRIVER</ModuleType>
+ <GuidValue>f320d656-8985-11db-90e0-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Unix Bus driver</Abstract>
+ <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>
+ <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>UnixBusDriver</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverModelLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PcdLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DevicePathLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixBusDriver.h</Filename>
+ <Filename>UnixBusDriver.c</Filename>
+ <Filename>ComponentName.c</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="BY_START">
+ <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="TO_START">
+ <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="TO_START">
+ <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_CONSUMED">
+ <ProtocolCName>gPcdProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixVirtualDisksGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixPhysicalDisksGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixFileSystemGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixUgaGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixConsoleGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixMemoryGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixCPUModelGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixCPUSpeedGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixSerialPortGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <DriverBinding>gUnixBusDriverBinding</DriverBinding>
+ <ComponentName>gUnixBusDriverComponentName</ComponentName>
+ </Extern>
+ </Externs>
+ <PcdCoded>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixConsole</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <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>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixUga</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>This PCD declares the resolutions for the UGA windows.
+ The item type of this PCD can only be "DYNAMIC".</HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixFileSystem</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <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>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixVirtualDisk</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <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>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixPhysicalDisk</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <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>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixCpuModel</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>This PCD defines simulated CPU model string.
+ The item type of this PCD can only be "DYNAMIC".</HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixCpuSpeed</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>This PCD defines simulated CPU speed string.</HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdUnixMemorySize</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>This PCD defines the size of simulated memory size.
+ The item type of this PCD can only be "DYNAMIC".</HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">
+ <C_Name>PcdUnixSerialPort</C_Name>
+ <TokenSpaceGuidCName>gEfiEdkUnixPkgTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>Simulation serial IO port</HelpText>
+ </PcdEntry>
+ </PcdCoded>
+</ModuleSurfaceArea> \ No newline at end of file
diff --git a/UnixPkg/UnixConsoleDxe/ComponentName.c b/UnixPkg/UnixConsoleDxe/ComponentName.c
new file mode 100644
index 0000000000..e73ba7bed0
--- /dev/null
+++ b/UnixPkg/UnixConsoleDxe/ComponentName.c
@@ -0,0 +1,197 @@
+/*++
+
+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:
+
+ ComponentName.c
+
+Abstract:
+
+--*/
+
+#include "Console.h"
+
+//
+// EFI Component Name Functions
+//
+EFI_STATUS
+EFIAPI
+UnixConsoleComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ );
+
+EFI_STATUS
+EFIAPI
+UnixConsoleComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ );
+
+//
+// EFI Component Name Protocol
+//
+EFI_COMPONENT_NAME_PROTOCOL gUnixConsoleComponentName = {
+ UnixConsoleComponentNameGetDriverName,
+ UnixConsoleComponentNameGetControllerName,
+ "eng"
+};
+
+static EFI_UNICODE_STRING_TABLE mUnixConsoleDriverNameTable[] = {
+ { "eng", L"Unix Text Console Driver" },
+ { NULL , NULL }
+};
+
+EFI_STATUS
+EFIAPI
+UnixConsoleComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the driver name that that the caller
+ is requesting, and it must match one of the languages specified
+ in SupportedLanguages. The number of languages supported by a
+ driver is up to the driver writer.
+ DriverName - A pointer to the Unicode string to return. This Unicode string
+ is the name of the driver specified by This in the language
+ specified by Language.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the Driver specified by This
+ and the language specified by Language was returned
+ in DriverName.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - DriverName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ return LookupUnicodeString (
+ Language,
+ gUnixConsoleComponentName.SupportedLanguages,
+ mUnixConsoleDriverNameTable,
+ DriverName
+ );
+}
+
+EFI_STATUS
+EFIAPI
+UnixConsoleComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by an EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ ControllerHandle - The handle of a controller that the driver specified by
+ This is managing. This handle specifies the controller
+ whose name is to be returned.
+ ChildHandle - The handle of the child controller to retrieve the name
+ of. 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 retrieve the name of the
+ bus controller. It will not be NULL for a bus driver
+ that wishes to retrieve the name of a child controller.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language of the controller name
+ that that the caller is requesting, and it must match one
+ of the languages specified in SupportedLanguages. The
+ number of languages supported by a driver is up to the
+ driver writer.
+ ControllerName - A pointer to the Unicode string to return. This Unicode
+ string is the name of the controller specified by
+ ControllerHandle and ChildHandle in the language specified
+ by Language from the point of view of the driver specified
+ by This.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the user readable name in the
+ language specified by Language for the driver
+ specified by This was returned in DriverName.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ControllerName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This is not currently managing
+ the controller specified by ControllerHandle and
+ ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ //
+ // This is a device driver, so ChildHandle must be NULL.
+ //
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Make sure this driver is currently managing ControllerHandle
+ //
+ Status = EfiTestManagedDevice (
+ ControllerHandle,
+ gUnixConsoleDriverBinding.DriverBindingHandle,
+ &gEfiUnixIoProtocolGuid
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Get out context back
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiSimpleTextOutProtocolGuid,
+ (void *)&SimpleTextOut,
+ gUnixConsoleDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);
+
+ return LookupUnicodeString (
+ Language,
+ gUnixConsoleComponentName.SupportedLanguages,
+ Private->ControllerNameTable,
+ ControllerName
+ );
+}
diff --git a/UnixPkg/UnixConsoleDxe/Console.c b/UnixPkg/UnixConsoleDxe/Console.c
new file mode 100644
index 0000000000..314da93a33
--- /dev/null
+++ b/UnixPkg/UnixConsoleDxe/Console.c
@@ -0,0 +1,310 @@
+/*++
+
+Copyright (c) 2004 - 2005, 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:
+
+ Console.c
+
+Abstract:
+
+ Console based on Posix APIs.
+
+--*/
+
+#include "Console.h"
+
+EFI_STATUS
+EFIAPI
+UnixConsoleDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ );
+
+EFI_STATUS
+EFIAPI
+UnixConsoleDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ );
+
+EFI_STATUS
+EFIAPI
+UnixConsoleDriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ );
+
+EFI_DRIVER_BINDING_PROTOCOL gUnixConsoleDriverBinding = {
+ UnixConsoleDriverBindingSupported,
+ UnixConsoleDriverBindingStart,
+ UnixConsoleDriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+EFI_STATUS
+EFIAPI
+UnixConsoleDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: Handle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+
+ //
+ // Open the IO Abstraction(s) needed to perform the supported test
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Make sure that the Unix Thunk Protocol is valid
+ //
+ Status = EFI_UNSUPPORTED;
+ if (UnixIo->UnixThunk->Signature == EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {
+
+ //
+ // Check the GUID to see if this is a handle type the driver supports
+ //
+ if (CompareGuid (UnixIo->TypeGuid, &gEfiUnixConsoleGuid)) {
+ Status = EFI_SUCCESS;
+ }
+ }
+
+ //
+ // Close the I/O Abstraction(s) used to perform the supported test
+ //
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixConsoleDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: Handle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ //
+ // Grab the IO abstraction we need to get any work done
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (void *)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ sizeof (UNIX_SIMPLE_TEXT_PRIVATE_DATA),
+ (void *)&Private
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ ZeroMem (Private, sizeof (UNIX_SIMPLE_TEXT_PRIVATE_DATA));
+
+ Private->Signature = UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE;
+ Private->Handle = Handle;
+ Private->UnixIo = UnixIo;
+ Private->UnixThunk = UnixIo->UnixThunk;
+
+ UnixSimpleTextOutOpenWindow (Private);
+ UnixSimpleTextInAttachToWindow (Private);
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Handle,
+ &gEfiSimpleTextOutProtocolGuid,
+ &Private->SimpleTextOut,
+ &gEfiSimpleTextInProtocolGuid,
+ &Private->SimpleTextIn,
+ NULL
+ );
+ if (!EFI_ERROR (Status)) {
+ return Status;
+ }
+
+Done:
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+ if (Private != NULL) {
+
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+
+#if 0
+ if (Private->NtOutHandle != NULL) {
+ Private->UnixThunk->CloseHandle (Private->NtOutHandle);
+ }
+#endif
+
+ if (Private->SimpleTextIn.WaitForKey != NULL) {
+ gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
+ }
+
+ gBS->FreePool (Private);
+ }
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixConsoleDriverBindingStop (
+ 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:
+
+ EFI_UNSUPPORTED - TODO: Add description for return value
+
+--*/
+{
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
+ EFI_STATUS Status;
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ //
+ // Kick people off our interface???
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiSimpleTextOutProtocolGuid,
+ (void *)&SimpleTextOut,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (SimpleTextOut);
+
+ ASSERT (Private->Handle == Handle);
+
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ Handle,
+ &gEfiSimpleTextOutProtocolGuid,
+ &Private->SimpleTextOut,
+ &gEfiSimpleTextInProtocolGuid,
+ &Private->SimpleTextIn,
+ NULL
+ );
+ if (!EFI_ERROR (Status)) {
+
+ //
+ // Shut down our device
+ //
+ Status = gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+
+ Status = gBS->CloseEvent (Private->SimpleTextIn.WaitForKey);
+ ASSERT_EFI_ERROR (Status);
+
+#if 0
+ Private->UnixThunk->CloseHandle (Private->NtOutHandle);
+#endif
+ //
+ // DO NOT close Private->NtInHandle. It points to StdIn and not
+ // the Private->NtOutHandle is StdIn and should not be closed!
+ //
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+
+ gBS->FreePool (Private);
+ }
+
+ return Status;
+}
diff --git a/UnixPkg/UnixConsoleDxe/Console.h b/UnixPkg/UnixConsoleDxe/Console.h
new file mode 100644
index 0000000000..f673c0b642
--- /dev/null
+++ b/UnixPkg/UnixConsoleDxe/Console.h
@@ -0,0 +1,530 @@
+/*++
+
+Copyright (c) 2004 - 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:
+
+ Console.h
+
+Abstract:
+
+ Console based on Posix APIs.
+
+ This file attaches a SimpleTextIn protocol to a previously open window.
+
+ The constructor for this protocol depends on an open window. Currently
+ the SimpleTextOut protocol creates a window when it's constructor is called.
+ Thus this code must run after the constructor for the SimpleTextOut
+ protocol
+
+--*/
+
+#ifndef _CONSOLE_H_
+#define _CONSOLE_H_
+
+#include "PiDxe.h"
+#include "UnixDxe.h"
+#include <Protocol/UnixIo.h>
+#include <Protocol/SimpleTextIn.h>
+#include <Protocol/SimpleTextOut.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>
+
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixConsoleDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixConsoleComponentName;
+
+#define UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE \
+ EFI_SIGNATURE_32('U','X','s','c')
+
+typedef struct {
+ UINT64 Signature;
+
+ EFI_HANDLE Handle;
+
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL SimpleTextOut;
+ EFI_SIMPLE_TEXT_OUTPUT_MODE SimpleTextOutMode;
+
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+
+ //
+ // SimpleTextOut Private Data including Posix types.
+ //
+ // HANDLE NtOutHandle;
+ // HANDLE NtInHandle;
+
+ //COORD MaxScreenSize;
+ //COORD Position;
+ //WORD Attribute;
+ BOOLEAN CursorEnable;
+
+ EFI_SIMPLE_TEXT_INPUT_PROTOCOL SimpleTextIn;
+
+ EFI_UNICODE_STRING_TABLE *ControllerNameTable;
+
+} UNIX_SIMPLE_TEXT_PRIVATE_DATA;
+
+#define UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS(a) \
+ CR(a, UNIX_SIMPLE_TEXT_PRIVATE_DATA, SimpleTextOut, UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE)
+
+#define UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS(a) \
+ CR(a, UNIX_SIMPLE_TEXT_PRIVATE_DATA, SimpleTextIn, UNIX_SIMPLE_TEXT_PRIVATE_DATA_SIGNATURE)
+
+//
+// Console Globale Variables
+//
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixConsoleDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixConsoleComponentName;
+
+typedef struct {
+ UINTN ColumnsX;
+ UINTN RowsY;
+} UNIX_SIMPLE_TEXT_OUT_MODE;
+
+#if 0
+//
+// Simple Text Out protocol member functions
+//
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutReset (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN BOOLEAN ExtendedVerification
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ ExtendedVerification - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutOutputString (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN CHAR16 *String
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ String - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutTestString (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN CHAR16 *String
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ String - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutQueryMode (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN ModeNumber,
+ OUT UINTN *Columns,
+ OUT UINTN *Rows
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ ModeNumber - TODO: add argument description
+ Columns - TODO: add argument description
+ Rows - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutSetMode (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN ModeNumber
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ ModeNumber - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutSetAttribute (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN Attribute
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Attribute - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutClearScreen (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutSetCursorPosition (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN Column,
+ IN UINTN Row
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Column - TODO: add argument description
+ Row - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutEnableCursor (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN BOOLEAN Enable
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Enable - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+#endif
+//
+// Simple Text Out constructor and destructor.
+//
+EFI_STATUS
+UnixSimpleTextOutOpenWindow (
+ IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+UnixSimpleTextOutCloseWindow (
+ IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Console - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+#if 0
+//
+// Simple Text In protocol member functions.
+//
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextInReset (
+ 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:
+
+ TODO: add return values
+
+--*/
+;
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextInReadKeyStroke (
+ 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
+
+--*/
+;
+
+STATIC
+VOID
+EFIAPI
+UnixSimpleTextInWaitForKey (
+ 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
+
+--*/
+;
+
+#endif
+//
+// Simple Text In constructor
+//
+EFI_STATUS
+UnixSimpleTextInAttachToWindow (
+ IN UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+//
+// Main Entry Point
+//
+EFI_STATUS
+EFIAPI
+InitializeUnixConsole (
+ 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
+AppendDevicePathInstanceToVar (
+ IN CHAR16 *VariableName,
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ VariableName - TODO: add argument description
+ DevicePathInstance - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+#endif
diff --git a/UnixPkg/UnixConsoleDxe/ConsoleIn.c b/UnixPkg/UnixConsoleDxe/ConsoleIn.c
new file mode 100644
index 0000000000..f315eaabf1
--- /dev/null
+++ b/UnixPkg/UnixConsoleDxe/ConsoleIn.c
@@ -0,0 +1,246 @@
+/*++
+
+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:
+
+ ConsoleIn.c
+
+Abstract:
+
+ Console based on Posix APIs.
+
+ This file attaches a SimpleTextIn protocol to a previously open window.
+
+ The constructor for this protocol depends on an open window. Currently
+ the SimpleTextOut protocol creates a window when it's constructor is called.
+ Thus this code must run after the constructor for the SimpleTextOut
+ protocol
+
+--*/
+
+#include "Console.h"
+#include <sys/poll.h>
+
+//
+// Private worker functions
+//
+STATIC
+EFI_STATUS
+UnixSimpleTextInCheckKey (
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
+ );
+
+EFI_STATUS
+EFIAPI
+UnixSimpleTextInReset (
+ 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
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+UnixConvertInputRecordToEfiKey (
+ IN char c,
+ OUT EFI_INPUT_KEY *Key
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ InputRecord - TODO: add argument description
+ Key - TODO: add argument description
+
+Returns:
+
+ EFI_NOT_READY - TODO: Add description for return value
+ EFI_NOT_READY - TODO: Add description for return value
+ EFI_NOT_READY - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ Key->ScanCode = 0;
+ if (c == '\n')
+ c = '\r';
+ Key->UnicodeChar = c;
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextInReadKeyStroke (
+ 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:
+
+ EFI_DEVICE_ERROR - TODO: Add description for return value
+ EFI_NOT_READY - TODO: Add description for return value
+
+--*/
+{
+ EFI_STATUS Status;
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+ char c;
+
+ Private = UNIX_SIMPLE_TEXT_IN_PRIVATE_DATA_FROM_THIS (This);
+
+ Status = UnixSimpleTextInCheckKey (Private);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ if (Private->UnixThunk->Read (0, &c, 1) != 1)
+ return EFI_NOT_READY;
+ Status = UnixConvertInputRecordToEfiKey (c, Key);
+
+ return Status;
+}
+
+STATIC
+VOID
+EFIAPI
+UnixSimpleTextInWaitForKey (
+ 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
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+ EFI_STATUS Status;
+
+ Private = (UNIX_SIMPLE_TEXT_PRIVATE_DATA *) Context;
+ Status = UnixSimpleTextInCheckKey (Private);
+ if (!EFI_ERROR (Status)) {
+ gBS->SignalEvent (Event);
+ }
+}
+
+STATIC
+EFI_STATUS
+UnixSimpleTextInCheckKey (
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ struct pollfd pfd;
+
+ pfd.fd = 0;
+ pfd.events = POLLIN;
+ if (Private->UnixThunk->Poll (&pfd, 1, 0) <= 0) {
+ return EFI_NOT_READY;
+ }
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+UnixSimpleTextInAttachToWindow (
+ IN UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ EFI_STATUS Status;
+
+ Private->SimpleTextIn.Reset = UnixSimpleTextInReset;
+ Private->SimpleTextIn.ReadKeyStroke = UnixSimpleTextInReadKeyStroke;
+
+ Status = gBS->CreateEvent (
+ EVT_NOTIFY_WAIT,
+ TPL_NOTIFY,
+ UnixSimpleTextInWaitForKey,
+ Private,
+ &Private->SimpleTextIn.WaitForKey
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return Status;
+}
diff --git a/UnixPkg/UnixConsoleDxe/ConsoleOut.c b/UnixPkg/UnixConsoleDxe/ConsoleOut.c
new file mode 100644
index 0000000000..416db945aa
--- /dev/null
+++ b/UnixPkg/UnixConsoleDxe/ConsoleOut.c
@@ -0,0 +1,635 @@
+/*++
+
+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:
+
+ ConsoleOut.c
+
+Abstract:
+
+ Console based on Posix APIs.
+
+ This file creates an Posix window and attaches a SimpleTextOut protocol.
+
+--*/
+
+#include "Console.h"
+//
+// Private worker functions.
+//
+
+#if 0
+STATIC
+VOID
+UnixSimpleTextOutScrollScreen (
+ IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console
+ );
+
+#endif
+STATIC
+VOID
+UnixSimpleTextOutPutChar (
+ IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console,
+ IN CHAR16 Char
+ );
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutSetAttribute (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN Attribute
+ );
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutSetMode (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN ModeNumber
+ );
+
+//
+// Modeule Global for Simple Text Out Mode.
+//
+#define MAX_SIMPLE_TEXT_OUT_MODE \
+ (sizeof(mUnixSimpleTextOutSupportedModes)/sizeof(UNIX_SIMPLE_TEXT_OUT_MODE))
+
+STATIC UNIX_SIMPLE_TEXT_OUT_MODE mUnixSimpleTextOutSupportedModes[] = {
+ { 80, 25 },
+#if 0
+ { 80, 50 },
+ { 80, 43 },
+ { 100, 100 },
+ { 100, 999 }
+#endif
+};
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutReset (
+ IN EFI_SIMPLE_TEXT_OUTPUT_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
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
+
+ UnixSimpleTextOutSetAttribute (This, EFI_TEXT_ATTR (This->Mode->Attribute & 0x0F, EFI_BACKGROUND_BLACK));
+
+ UnixSimpleTextOutSetMode (This, 0);
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutOutputString (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN CHAR16 *String
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ String - TODO: add argument description
+
+Returns:
+
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+ CHAR16 *Str;
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
+
+ for (Str = String; *Str != '\0'; Str++) {
+ switch (*Str) {
+#if 0
+ case '\n':
+ if (Private->Position.Y == (Private->MaxScreenSize.Y - 1)) {
+ UnixSimpleTextOutScrollScreen (Private);
+ }
+
+ if (Private->Position.Y < (Private->MaxScreenSize.Y - 1)) {
+ Private->Position.Y++;
+ This->Mode->CursorRow++;
+ }
+ break;
+
+ case '\r':
+ Private->Position.X = 0;
+ This->Mode->CursorColumn = 0;
+ break;
+
+ case '\b':
+ if (Private->Position.X > 0) {
+ Private->Position.X--;
+ This->Mode->CursorColumn--;
+ }
+ break;
+
+#endif
+ default:
+ UnixSimpleTextOutPutChar (Private, *Str);
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+VOID
+UnixSimpleTextOutPutChar (
+ IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console,
+ IN CHAR16 Char
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Console - TODO: add argument description
+ Char - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ char c = Char;
+ Console->UnixThunk->Write (1, &c, 1);
+}
+
+#if 0
+STATIC
+VOID
+UnixSimpleTextOutScrollScreen (
+ IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Console - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+}
+#endif
+
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutTestString (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN CHAR16 *String
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ String - TODO: add argument description
+
+Returns:
+
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
+
+ //
+ // BugBug: The correct answer would be a function of what code pages
+ // are currently loaded? For now we will just return success.
+ //
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutQueryMode (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN ModeNumber,
+ OUT UINTN *Columns,
+ OUT UINTN *Rows
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ ModeNumber - TODO: add argument description
+ Columns - TODO: add argument description
+ Rows - TODO: add argument description
+
+Returns:
+
+ EFI_INVALID_PARAMETER - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
+
+ if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *Columns = mUnixSimpleTextOutSupportedModes[ModeNumber].ColumnsX;
+ *Rows = mUnixSimpleTextOutSupportedModes[ModeNumber].RowsY;
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutSetMode (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN ModeNumber
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ ModeNumber - TODO: add argument description
+
+Returns:
+
+ EFI_INVALID_PARAMETER - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
+
+ if (ModeNumber > MAX_SIMPLE_TEXT_OUT_MODE) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+
+ This->Mode->Mode = (INT32) ModeNumber;
+
+ This->EnableCursor (This, TRUE);
+ This->ClearScreen (This);
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutSetAttribute (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN Attribute
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Attribute - TODO: add argument description
+
+Returns:
+
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
+
+#if 0
+ Private->Attribute = (WORD) Attribute;
+#endif
+ This->Mode->Attribute = (INT32) Attribute;
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutClearScreen (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+
+Returns:
+
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+ // DWORD ConsoleWindow;
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
+
+ This->SetCursorPosition (This, 0, 0);
+ Private->UnixThunk->Write (1, "\e[2J", 4);
+
+
+#if 0
+ Private->UnixThunk->FillConsoleOutputCharacter (
+ Private->NtOutHandle,
+ ' ',
+ Private->MaxScreenSize.X * Private->MaxScreenSize.Y,
+ Private->Possition,
+ &ConsoleWindow
+ );
+ Private->UnixThunk->FillConsoleOutputAttribute (
+ Private->NtOutHandle,
+ Private->Attribute,
+ Private->MaxScreenSize.X * Private->MaxScreenSize.Y,
+ Private->Possition,
+ &ConsoleWindow
+ );
+#endif
+
+ return EFI_SUCCESS;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutSetCursorPosition (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN UINTN Column,
+ IN UINTN Row
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Column - TODO: add argument description
+ Row - TODO: add argument description
+
+Returns:
+
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ char buf[12];
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
+
+#if 0
+ Private->Position.X = (WORD) Column;
+#endif
+ This->Mode->CursorColumn = (INT32) Column;
+
+#if 0
+ Private->Position.Y = (WORD) Row;
+#endif
+ This->Mode->CursorRow = (INT32) Row;
+#if 0
+ Private->UnixThunk->SetConsoleCursorPosition (Private->NtOutHandle, Private->Possition);
+#endif
+
+ 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;
+}
+
+STATIC
+EFI_STATUS
+EFIAPI
+UnixSimpleTextOutEnableCursor (
+ IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This,
+ IN BOOLEAN Enable
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Enable - TODO: add argument description
+
+Returns:
+
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private;
+#if 0
+ CONSOLE_CURSOR_INFO Info;
+#endif
+
+ Private = UNIX_SIMPLE_TEXT_OUT_PRIVATE_DATA_FROM_THIS (This);
+ Private->CursorEnable = Enable;
+ This->Mode->CursorVisible = Enable;
+
+#if 0
+ Private->UnixThunk->GetConsoleCursorInfo (Private->NtOutHandle, &Info);
+ Info.bVisible = Enable;
+ Private->UnixThunk->SetConsoleCursorInfo (Private->NtOutHandle, &Info);
+#endif
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+UnixSimpleTextOutOpenWindow (
+ IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Private
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Private - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *SimpleTextOut;
+ CHAR16 *WindowName;
+
+ //WindowName = Private->UnixIo->EnvString;
+#if 0
+ Private->Attribute = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
+ if (*WindowName == '?') {
+ Private->Attribute = BACKGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;
+ WindowName = L"EFI Emulator Error Console";
+ }
+#endif
+ WindowName = L"EFI Emulator Error Console";
+
+ AddUnicodeString (
+ "eng",
+ gUnixConsoleComponentName.SupportedLanguages,
+ &Private->ControllerNameTable,
+ WindowName
+ );
+
+ //
+ // Fill in protocol member functions
+ //
+ SimpleTextOut = &Private->SimpleTextOut;
+ SimpleTextOut->Reset = UnixSimpleTextOutReset;
+ SimpleTextOut->OutputString = UnixSimpleTextOutOutputString;
+ SimpleTextOut->TestString = UnixSimpleTextOutTestString;
+ SimpleTextOut->QueryMode = UnixSimpleTextOutQueryMode;
+ SimpleTextOut->SetMode = UnixSimpleTextOutSetMode;
+ SimpleTextOut->SetAttribute = UnixSimpleTextOutSetAttribute;
+ SimpleTextOut->ClearScreen = UnixSimpleTextOutClearScreen;
+ SimpleTextOut->SetCursorPosition = UnixSimpleTextOutSetCursorPosition;
+ SimpleTextOut->EnableCursor = UnixSimpleTextOutEnableCursor;
+
+ //
+ // Initialize SimpleTextOut protocol mode structure
+ //
+ SimpleTextOut->Mode = &Private->SimpleTextOutMode;
+ SimpleTextOut->Mode->MaxMode = MAX_SIMPLE_TEXT_OUT_MODE;
+ SimpleTextOut->Mode->Attribute = 0; //FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY;
+
+#if 0
+ //
+ // Open the window an initialize it!
+ //
+ Private->NtOutHandle = Private->UnixThunk->CreateConsoleScreenBuffer (
+ GENERIC_WRITE | GENERIC_READ,
+ FILE_SHARE_WRITE | FILE_SHARE_READ,
+ NULL,
+ CONSOLE_TEXTMODE_BUFFER,
+ NULL
+ );
+ Private->UnixThunk->SetConsoleTitle (WindowName);
+#endif
+
+ return SimpleTextOut->SetMode (SimpleTextOut, 0);
+}
+
+EFI_STATUS
+UnixSimpleTextOutCloseWindow (
+ IN OUT UNIX_SIMPLE_TEXT_PRIVATE_DATA *Console
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Console - TODO: add argument description
+
+Returns:
+
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+#if 0
+ Console->UnixThunk->CloseHandle (Console->NtOutHandle);
+#endif
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/UnixConsoleDxe/EntryPoint.c b/UnixPkg/UnixConsoleDxe/EntryPoint.c
new file mode 100644
index 0000000000..47f4258883
--- /dev/null
+++ b/UnixPkg/UnixConsoleDxe/EntryPoint.c
@@ -0,0 +1,51 @@
+/**@file
+ Entry Point Source file.
+
+ This file contains the user entry point
+
+ 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.
+**/
+
+
+
+#include "Console.h"
+
+/**
+ The user Entry Point for module UnixConsole. The user code starts with this function.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeUnixConsole(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = EfiLibInstallAllDriverProtocols (
+ ImageHandle,
+ SystemTable,
+ &gUnixConsoleDriverBinding,
+ ImageHandle,
+ &gUnixConsoleComponentName,
+ NULL,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+
+
+ return Status;
+}
diff --git a/UnixPkg/UnixConsoleDxe/UnixConsole.inf b/UnixPkg/UnixConsoleDxe/UnixConsole.inf
new file mode 100644
index 0000000000..d5c1ed2277
--- /dev/null
+++ b/UnixPkg/UnixConsoleDxe/UnixConsole.inf
@@ -0,0 +1,65 @@
+#/** @file
+# Console Dxe driver
+#
+# Simulate console with Unix API
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixConsole
+ FILE_GUID = f314a8cc-8985-11db-9f69-0040d02b1835
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeUnixConsole
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+# DRIVER_BINDING = gUnixConsoleDriverBinding
+# COMPONENT_NAME = gUnixConsoleComponentName
+#
+
+[Sources.common]
+ ComponentName.c
+ ConsoleOut.c
+ ConsoleIn.c
+ Console.c
+ Console.h
+ EntryPoint.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ UefiLib
+ UefiDriverEntryPoint
+ BaseLib
+ DebugLib
+
+
+[Protocols]
+ gEfiSimpleTextInProtocolGuid # PROTOCOL BY_START
+ gEfiSimpleTextOutProtocolGuid # PROTOCOL BY_START
+ gEfiUnixIoProtocolGuid # PROTOCOL TO_START
+ gEfiUnixConsoleGuid
diff --git a/UnixPkg/UnixConsoleDxe/UnixConsole.msa b/UnixPkg/UnixConsoleDxe/UnixConsole.msa
new file mode 100644
index 0000000000..839eed7d13
--- /dev/null
+++ b/UnixPkg/UnixConsoleDxe/UnixConsole.msa
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>UnixConsole</ModuleName>
+ <ModuleType>UEFI_DRIVER</ModuleType>
+ <GuidValue>f314a8cc-8985-11db-9f69-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Console Dxe driver</Abstract>
+ <Description>Simulate console with Unix API</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>UnixConsole</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverModelLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>Console.h</Filename>
+ <Filename>Console.c</Filename>
+ <Filename>ConsoleIn.c</Filename>
+ <Filename>ConsoleOut.c</Filename>
+ <Filename>ComponentName.c</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="TO_START">
+ <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="BY_START">
+ <ProtocolCName>gEfiSimpleTextOutProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="BY_START">
+ <ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixConsoleGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <DriverBinding>gUnixConsoleDriverBinding</DriverBinding>
+ <ComponentName>gUnixConsoleComponentName</ComponentName>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixFirmwareVolumePei/UnixFwh.c b/UnixPkg/UnixFirmwareVolumePei/UnixFwh.c
new file mode 100644
index 0000000000..2d3c6a380e
--- /dev/null
+++ b/UnixPkg/UnixFirmwareVolumePei/UnixFwh.c
@@ -0,0 +1,137 @@
+/*++
+
+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:
+ UnixFwh.c
+
+Abstract:
+ PEIM to abstract construction of firmware volume in an Unix environment.
+
+Revision History
+
+--*/
+
+#include "PiPei.h"
+#include <Ppi/UnixFwh.h>
+#include <Library/DebugLib.h>
+#include <Library/PeimEntryPoint.h>
+#include <Library/HobLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/PeiServicesTablePointerLib.h>
+#include <Library/PcdLib.h>
+
+EFI_STATUS
+EFIAPI
+PeimInitializeUnixFwh (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices
+ )
+/*++
+
+Routine Description:
+ Perform a call-back into the SEC simulator to get address of the Firmware Hub
+
+Arguments:
+ FfsHeader - Ffs Header availible to every PEIM
+ PeiServices - General purpose services available to every PEIM.
+
+Returns:
+ None
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
+ UNIX_FWH_PPI *FwhPpi;
+ EFI_PHYSICAL_ADDRESS FdBase;
+ EFI_FIRMWARE_VOLUME_HEADER *FvHeader;
+ UINT64 FdSize;
+ UINTN Index;
+
+ DEBUG ((EFI_D_ERROR, "Unix Firmware Volume PEIM Loaded\n"));
+
+ //
+ // Get the Fwh Information PPI
+ //
+ Status = (**PeiServices).LocatePpi (
+ PeiServices,
+ &gUnixFwhPpiGuid, // GUID
+ 0, // INSTANCE
+ &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
+ (VOID **)&FwhPpi // PPI
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Index = 0;
+ do {
+ //
+ // Get information about all the FD's in the system
+ //
+ Status = FwhPpi->UnixFwh (Index, &FdBase, &FdSize);
+ if (!EFI_ERROR (Status)) {
+ //
+ // Assume the FD starts with an FV header
+ //
+ FvHeader = (EFI_FIRMWARE_VOLUME_HEADER *) (UINTN) FdBase;
+
+ //
+ // Make an FV Hob for the first FV in the FD
+ //
+ BuildFvHob (FdBase, FvHeader->FvLength);
+
+ if (Index == 0) {
+ //
+ // Assume the first FD was produced by the NT32.DSC
+ // All these strange offests are needed to keep in
+ // sync with the FlashMap and NT32.dsc file
+ //
+ BuildResourceDescriptorHob (
+ EFI_RESOURCE_FIRMWARE_DEVICE,
+ (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
+ FdBase,
+ (
+ FvHeader->FvLength +
+ PcdGet32 (PcdFlashNvStorageVariableSize) +
+ PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
+ PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
+ PcdGet32 (PcdUnixFlashNvStorageEventLogSize)
+ )
+ );
+
+ //
+ // Hard code the address of the spare block and variable services.
+ // Assume it's a hard coded offset from FV0 in FD0.
+ //
+ FdSize =
+ PcdGet32 (PcdFlashNvStorageVariableSize) +
+ PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
+ PcdGet32 (PcdFlashNvStorageFtwSpareSize) +
+ PcdGet32 (PcdUnixFlashNvStorageEventLogSize);
+
+ BuildFvHob (FdBase + PcdGet32 (PcdUnixFlashNvStorageVariableBase), FdSize);
+ } else {
+ //
+ // For other FD's just map them in.
+ //
+ BuildResourceDescriptorHob (
+ EFI_RESOURCE_FIRMWARE_DEVICE,
+ (EFI_RESOURCE_ATTRIBUTE_PRESENT | EFI_RESOURCE_ATTRIBUTE_INITIALIZED | EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE),
+ FdBase,
+ FdSize
+ );
+ }
+ }
+
+ Index++;
+ } while (!EFI_ERROR (Status));
+
+ return Status;
+}
diff --git a/UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf b/UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf
new file mode 100644
index 0000000000..126e8935ea
--- /dev/null
+++ b/UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf
@@ -0,0 +1,68 @@
+#/** @file
+# Component description file for WinNtFwh module
+#
+# This PEIM will produce the HOB to describe Firmware Volume, Firmware Devices
+# on the NT32 emulator.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixFwh
+ FILE_GUID = f40b7864-8985-11db-af21-0040d02b1835
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = PeimInitializeUnixFwh
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ UnixFwh.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ PeiServicesTablePointerLib
+ PeiServicesLib
+ HobLib
+ PeimEntryPoint
+ DebugLib
+
+
+[FixedPcd.common]
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase
+
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
+
+
+[Ppis]
+ gUnixFwhPpiGuid # PPI ALWAYS_CONSUMED
+
+
+[Depex]
+ gUnixFwhPpiGuid AND gEfiPeiMemoryDiscoveredPpiGuid
+
diff --git a/UnixPkg/UnixFirmwareVolumePei/UnixFwh.msa b/UnixPkg/UnixFirmwareVolumePei/UnixFwh.msa
new file mode 100644
index 0000000000..f46801a622
--- /dev/null
+++ b/UnixPkg/UnixFirmwareVolumePei/UnixFwh.msa
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>UnixFwh</ModuleName>
+ <ModuleType>PEIM</ModuleType>
+ <GuidValue>f40b7864-8985-11db-af21-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Component description file for WinNtFwh module</Abstract>
+ <Description>This PEIM will produce the HOB to describe Firmware Volume, Firmware Devices
+ on the NT32 emulator.</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>UnixFwh</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PeimEntryPoint</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>UnixFwh.c</Filename>
+ <Filename>UnixFwh.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>gUnixFwhPpiGuid</PpiCName>
+ </Ppi>
+ </PPIs>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>PeimInitializeUnixFwh</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixFlashMapPei/FlashMap.c b/UnixPkg/UnixFlashMapPei/FlashMap.c
new file mode 100644
index 0000000000..9e96ac2425
--- /dev/null
+++ b/UnixPkg/UnixFlashMapPei/FlashMap.c
@@ -0,0 +1,91 @@
+/*++
+
+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:
+
+ FlashMap.c
+
+Abstract:
+
+ PEIM to build GUIDed HOBs for platform specific flash map
+
+--*/
+
+
+#include "PiPei.h"
+
+#include <Guid/SystemNvDataGuid.h>
+#include <Guid/FirmwareFileSystem.h>
+#include <Ppi/UnixFwh.h>
+#include <Protocol/FirmwareVolumeBlock.h>
+
+#include <Library/DebugLib.h>
+#include <Library/PeimEntryPoint.h>
+#include <Library/HobLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/PeiServicesTablePointerLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/PcdLib.h>
+
+EFI_STATUS
+EFIAPI
+PeimInitializeFlashMap (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices
+ )
+/*++
+
+Routine Description:
+ Build GUIDed HOBs for platform specific flash map
+
+Arguments:
+ FfsHeader - A pointer to the EFI_FFS_FILE_HEADER structure.
+ PeiServices - General purpose services available to every PEIM.
+
+Returns:
+ EFI_STATUS
+
+--*/
+// TODO: EFI_SUCCESS - add return value to function comment
+{
+ EFI_STATUS Status;
+ UNIX_FWH_PPI *UnixFwhPpi;
+ EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
+ EFI_PHYSICAL_ADDRESS FdBase;
+ UINT64 FdSize;
+
+ DEBUG ((EFI_D_ERROR, "NT 32 Flash Map PEIM Loaded\n"));
+
+ //
+ // Get the Fwh Information PPI
+ //
+ Status = PeiServicesLocatePpi (
+ &gUnixFwhPpiGuid, // GUID
+ 0, // INSTANCE
+ &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
+ (VOID **)&UnixFwhPpi // PPI
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Assume that FD0 contains the Flash map.
+ //
+ Status = UnixFwhPpi->UnixFwh (0, &FdBase, &FdSize);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ PcdSet32 (PcdFlashNvStorageVariableBase, PcdGet32 (PcdUnixFlashNvStorageVariableBase) + (UINT32) FdBase);
+ PcdSet32 (PcdFlashNvStorageFtwWorkingBase, PcdGet32 (PcdUnixFlashNvStorageFtwWorkingBase) + (UINT32) FdBase);
+ PcdSet32 (PcdFlashNvStorageFtwSpareBase, PcdGet32 (PcdUnixFlashNvStorageFtwSpareBase) + (UINT32) FdBase);
+
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/UnixFlashMapPei/FlashMap.inf b/UnixPkg/UnixFlashMapPei/FlashMap.inf
new file mode 100644
index 0000000000..56c91968cb
--- /dev/null
+++ b/UnixPkg/UnixFlashMapPei/FlashMap.inf
@@ -0,0 +1,82 @@
+#/** @file
+# Component description file for FlashMap PEI module
+#
+# This module installs FlashMap PPI which is used to get flash layout information.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PeiFlashMap
+ FILE_GUID = f417814a-8985-11db-8983-0040d02b1835
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = PeimInitializeFlashMap
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ FlashMap.c
+
+[Packages]
+ MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+ IntelFrameworkPkg/IntelFrameworkPkg.dec
+ UnixPkg/UnixPkg.dec
+
+[LibraryClasses]
+ PcdLib
+ BaseMemoryLib
+ PeiServicesTablePointerLib
+ PeiServicesLib
+ HobLib
+ PeimEntryPoint
+ DebugLib
+
+
+[Guids]
+ gEfiSystemNvDataHobGuid # ALWAYS_CONSUMED
+ gEfiFirmwareFileSystemGuid # ALWAYS_CONSUMED
+ gEfiFlashMapHobGuid # ALWAYS_CONSUMED
+
+
+[Protocols]
+ gEfiFirmwareVolumeBlockProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+
+
+[Ppis]
+ gUnixFwhPpiGuid # PPI ALWAYS_CONSUMED
+ gPeiFlashMapPpiGuid # PPI ALWAYS_PRODUCED
+
+
+[Pcd.common]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase
+
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwWorkingBase
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwSpareBase
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase
+
+[Depex]
+ gPcdPpiGuid
+
diff --git a/UnixPkg/UnixFlashMapPei/FlashMap.msa b/UnixPkg/UnixFlashMapPei/FlashMap.msa
new file mode 100644
index 0000000000..7576795143
--- /dev/null
+++ b/UnixPkg/UnixFlashMapPei/FlashMap.msa
@@ -0,0 +1,126 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>PeiFlashMap</ModuleName>
+ <ModuleType>PEIM</ModuleType>
+ <GuidValue>f417814a-8985-11db-8983-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Component description file for FlashMap PEI module</Abstract>
+ <Description>This module installs FlashMap PPI which is used to get flash layout information.</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>PeiFlashMap</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PeimEntryPoint</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>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PcdLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>FlashMap.c</Filename>
+ <Filename>FlashMap.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_CONSUMED">
+ <ProtocolCName>gEfiFirmwareVolumeBlockProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <PPIs>
+ <Ppi Usage="ALWAYS_PRODUCED">
+ <PpiCName>gPeiFlashMapPpiGuid</PpiCName>
+ </Ppi>
+ <Ppi Usage="ALWAYS_CONSUMED">
+ <PpiCName>gUnixFwhPpiGuid</PpiCName>
+ </Ppi>
+ </PPIs>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiFlashMapHobGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiFirmwareFileSystemGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiSystemNvDataHobGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>PeimInitializeFlashMap</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+ <PcdCoded>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdFlashNvStorageVariableBase</C_Name>
+ <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>The driver sets the NV Storage FV base address defined by this PCD.
+ This base address point to an EFI_FIRMWARE_VOLUMN_HEADER struct. Variable PEIM
+ will get the base address from this PCD. In NT emulator, this PCD is a DYNAMIC
+ type, as FD is mapped to process space by WinNT OS. On real platform, it is
+ normally a FIXED_AT_BUILD type as system memory map is fixed to BIOS.
+ </HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC">
+ <C_Name>PcdFlashNvStorageVariableSize</C_Name>
+ <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>
+ To get the NvStorage Variable size from this PCD.
+ </HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">
+ <C_Name>PcdFlashNvStorageFtwSpareBase</C_Name>
+ <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>To get base address of the FTW spare block section in NV firmware volume.</HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">
+ <C_Name>PcdFlashNvStorageFtwSpareSize</C_Name>
+ <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>To get size of the FTW spare block section in NV firmware volume.</HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">
+ <C_Name>PcdFlashNvStorageFtwWorkingBase</C_Name>
+ <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>To get base address of the FTW working block section in NV firmware volume.</HelpText>
+ </PcdEntry>
+ <PcdEntry PcdItemType="DYNAMIC" Usage="ALWAYS_CONSUMED">
+ <C_Name>PcdFlashNvStorageFtwWorkingSize</C_Name>
+ <TokenSpaceGuidCName>gEfiGenericPlatformTokenSpaceGuid</TokenSpaceGuidCName>
+ <HelpText>To get size of the FTW working block section in NV firmware volume.</HelpText>
+ </PcdEntry>
+ </PcdCoded>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixPkg.dec b/UnixPkg/UnixPkg.dec
new file mode 100644
index 0000000000..f351e94954
--- /dev/null
+++ b/UnixPkg/UnixPkg.dec
@@ -0,0 +1,97 @@
+#/** @file
+#
+# This is the Unix Emulation Environment Platform
+#
+# Reference platform implementation using an emulator.
+# Copyright (c) 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.
+#
+#**/
+
+[Defines]
+ DEC_VERSION = 0x00010005
+ PACKAGE_NAME = EdkUnixPkg
+ PACKAGE_GUID = f2805c44-8985-11db-9e98-0040d02b1835
+ PACKAGE_VERSION = 0.1
+
+
+[Includes.common]
+ Include
+
+
+[LibraryClasses.common]
+ UnixLib|Include/Library/UnixLib.h
+
+
+[Protocols.common]
+ gEfiUnixIoProtocolGuid = {0xf2e23f54, 0x8985, 0x11db, {0xac, 0x79, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixUgaIoProtocolGuid = {0xf2e5e2c6, 0x8985, 0x11db, {0xa1, 0x91, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixThunkProtocolGuid = {0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+
+
+[Ppis.common]
+ gPeiUnixAutoScanPpiGuid = {0xf2ed3d14, 0x8985, 0x11db, {0xb0, 0x57, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gUnixFwhPpiGuid = {0xf2f0dc30, 0x8985, 0x11db, {0xa1, 0x5b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gUnixPeiLoadFilePpiGuid = {0xf2f48768, 0x8985, 0x11db, {0xb8, 0xda, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gPeiUnixThunkPpiGuid = {0xf2f830f2, 0x8985, 0x11db, {0x80, 0x6b, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+
+
+[Guids.common]
+ gEfiUnixPkgTokenSpaceGuid = {0xf2b6838c, 0x8985, 0x11db, {0x9d, 0x1c, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixVirtualDisksGuid = {0xf2ba331a, 0x8985, 0x11db, {0xa4, 0x06, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixPhysicalDisksGuid = {0xf2bdcc96, 0x8985, 0x11db, {0x87, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixFileSystemGuid = {0xf2c16b9e, 0x8985, 0x11db, {0x92, 0xc8, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixUgaGuid = {0xf2c8b80e, 0x8985, 0x11db, {0x93, 0xf1, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixConsoleGuid = {0xf2cc5d06, 0x8985, 0x11db, {0xbb, 0x19, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixMemoryGuid = {0xf2d006cc, 0x8985, 0x11db, {0xa4, 0x72, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixCPUModelGuid = {0xf2d3b330, 0x8985, 0x11db, {0x8a, 0xa3, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixCPUSpeedGuid = {0xf2d74e5a, 0x8985, 0x11db, {0x97, 0x05, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35}}
+ gEfiUnixSerialPortGuid = {0x6d3a727d, 0x66c8, 0x4d19, {0x87, 0xe6, 0x02, 0x15, 0x86, 0x14, 0x90, 0xf3}}
+ gEfiFlashMapHobGuid = {0xb091e7d2, 0x05a0, 0x4198, {0x94, 0xf0, 0x74, 0xb7, 0xb8, 0xc5, 0x54, 0x59}}
+
+
+[PcdsFixedAtBuild.common]
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixBootMode|1|UINT32|0x00001006
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareVolume|L"..\\Fv\\Fv_Recovery.fd"|VOID*|0x00001009
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySizeForSecMain|L"64!64"|VOID*|0x0000100c
+
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase|0x0|UINT32|0x00001014
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwSpareBase|0x0|UINT32|0x00001015
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwWorkingBase|0x0|UINT32|0x00001016
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFdBaseAddress|0x0|UINT32|0x00001017
+
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogBase|0x0|UINT32|0x0000100e
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize|0x0|UINT32|0x0000100f
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoveryBase|0x0|UINT32|0x00001010
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoverySize|0x0|UINT32|0x00001011
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize|0x0|UINT32|0x00001012
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareBlockSize|0|UINT32|0x00001013
+
+
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize|0x0|UINT32|0x0000100f
+
+
+[PcdsDynamic.common]
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixPhysicalDisk|L"E:RW;245760;512"|VOID*|0x00001000
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixVirtualDisk|L"FW;40960;512"|VOID*|0x00001001
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixUga|L"UGA Window"|VOID*|0x00001003
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFileSystem|L".!..\\..\\..\\..\\..\\EdkShellBinPkg\\bin\\ia32\\Apps"|VOID*|0x00001004
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySize|L"64!64"|VOID*|0x00001005
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuModel|L"Intel(R) Processor Model"|VOID*|0x00001007
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuSpeed|L"3000"|VOID*|0x00001008
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixConsole|L"Bus Driver Console Window"|VOID*|0x0000100a
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixSerialPort|L"/dev/ttyS0"|VOID*|0x00001002
+
+
+[PcdsPatchableInModule.common]
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixBootMode|1|UINT32|0x00001006
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareVolume|L"..\\Fv\\Fv_Recovery.fd"|VOID*|0x00001009
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySizeForSecMain|L"64!64"|VOID*|0x0000100c
+
+
diff --git a/UnixPkg/UnixPkg.dsc b/UnixPkg/UnixPkg.dsc
new file mode 100644
index 0000000000..2ff9efca2b
--- /dev/null
+++ b/UnixPkg/UnixPkg.dsc
@@ -0,0 +1,496 @@
+#/** @file
+#
+# EFI/Framework Emulation Platform with UEFI HII interface supported.
+#
+# The Emulation Platform can be used to debug individual modules, prior to creating
+# a real platform. This also provides an example for how an FPD is created.
+# 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.
+#
+#**/
+
+################################################################################
+#
+# Defines Section - statements that will be processed to create a Makefile.
+#
+################################################################################
+[Defines]
+ PLATFORM_NAME = Unix
+ PLATFORM_GUID = 7b3c1fb4-8986-11db-b5b2-0040d02b1835
+ PLATFORM_VERSION = 0.3
+ DSC_ SPECIFICATION = 0x00010005
+ OUTPUT_DIRECTORY = Build/Unix
+ SUPPORTED_ARCHITECTURES = IA32
+ BUILD_TARGETS = DEBUG|RELEASE
+ SKUID_IDENTIFIER = DEFAULT
+ FLASH_DEFINITION = UnixPkg/UnixPkg.fdf
+
+################################################################################
+#
+# SKU Identification section - list of all SKU IDs supported by this Platform.
+#
+################################################################################
+[SkuIds]
+ 0|DEFAULT
+
+################################################################################
+#
+# Library Class section - list of all Library Classes needed by this Platform.
+#
+################################################################################
+[LibraryClasses.common]
+ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
+ PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
+ SerialPortLib|MdePkg/Library/SerialPortLibNull/SerialPortLibNull.inf
+ BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+ BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
+ CpuLib|MdePkg/Library/CpuLib/CpuLib.inf
+ PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
+ PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+ PciIncompatibleDeviceSupportLib|IntelFrameworkModulePkg/Library/PciIncompatibleDeviceSupportLib/PciIncompatibleDeviceSupportLib.inf
+ CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLib/BaseCacheMaintenanceLib.inf
+ GraphicsLib|MdeModulePkg/Library/GraphicsLib/GraphicsLib.inf
+ FvbServiceLib|MdeModulePkg/Library/EdkFvbServiceLib/EdkFvbServiceLib.inf
+ IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
+ UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf
+ HiiLib|MdePkg/Library/HiiLib/HiiLib.inf
+ ExtendedHiiLib|MdeModulePkg/Library/ExtendedHiiLib/ExtendedHiiLib.inf
+ S3Lib|MdeModulePkg/Library/PeiS3LibNull/PeiS3LibNull.inf
+ RecoveryLib|MdeModulePkg/Library/PeiRecoveryLibNull/PeiRecoveryLibNull.inf
+ IfrSupportLib|MdePkg/Library/IfrSupportLib/IfrSupportLib.inf
+ ExtendedIfrSupportLib|MdeModulePkg/Library/ExtendedIfrSupportLib/ExtendedIfrSupportLib.inf
+ GenericBdsLib|MdeModulePkg/Library/GenericBdsLib/GenericBdsLib.inf
+ PlatformBdsLib|UnixPkg/Library/UnixBdsLib/PlatformBds.inf
+ CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
+ DxePiLib|MdePkg/Library/DxePiLib/DxePiLib.inf
+ PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
+
+[LibraryClasses.common.BASE]
+ DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/BaseReportStatusCodeLib/BaseReportStatusCodeLib.inf
+
+[LibraryClasses.common.USER_DEFINED]
+ DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/BaseReportStatusCodeLib/BaseReportStatusCodeLib.inf
+
+[LibraryClasses.common.SEC]
+ BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+ DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/BaseReportStatusCodeLib/BaseReportStatusCodeLib.inf
+ PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
+
+[LibraryClasses.common.DXE_CORE]
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+ HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
+ DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
+ MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf
+ UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
+ UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+ DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ PeCoffLib|UnixPkg/Library/DxeUnixPeCoffLib/DxeUnixPeCoffLib.inf
+ ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
+
+[LibraryClasses.common.DXE_SMM_DRIVER]
+ DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
+ ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
+ UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
+ MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf
+ UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
+ UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+ OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
+ DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+
+[LibraryClasses.common.PEIM]
+ BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+ HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
+ PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
+ IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
+ PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf
+ PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf
+ MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
+ PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
+ OemHookStatusCodeLib|UnixPkg/Library/PeiUnixOemHookStatusCodeLib/PeiUnixOemHookStatusCodeLib.inf
+ PeCoffGetEntryPointLib|UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf
+ DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+ PeCoffLib|UnixPkg/Library/PeiUnixPeCoffLib/PeiUnixPeCoffLib.inf
+ PeiPiLib|MdePkg/Library/PeiPiLib/PeiPiLib.inf
+ ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf
+
+[LibraryClasses.common.PEI_CORE]
+ BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
+ HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf
+ PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf
+ IoLib|MdePkg/Library/PeiIoLibCpuIo/PeiIoLibCpuIo.inf
+ PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf
+ MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf
+ PeiCoreEntryPoint|MdePkg/Library/PeiCoreEntryPoint/PeiCoreEntryPoint.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
+ OemHookStatusCodeLib|IntelFrameworkModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf
+ PeCoffGetEntryPointLib|UnixPkg/Library/EdkUnixPeiPeCoffGetEntryPointLib/EdkUnixPeiPeCoffGetEntryPointLib.inf
+ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+ PeCoffLib|UnixPkg/Library/PeiCoreUnixPeCoffLib/PeiCoreUnixPeCoffLib.inf
+ PeiPiLib|MdePkg/Library/PeiPiLib/PeiPiLib.inf
+
+[LibraryClasses.common.DXE_RUNTIME_DRIVER]
+ UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
+ MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf
+ UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+ UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
+ DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
+ UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
+ ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
+ UnixLib|UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf
+ OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf
+ DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+
+[LibraryClasses.common.UEFI_DRIVER]
+ UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
+ MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf
+ UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+ UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
+ DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
+ UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
+ UnixLib|UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf
+ OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf
+ DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+
+[LibraryClasses.common.DXE_DRIVER]
+ UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
+ MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf
+ UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+ UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
+ DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
+ UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
+ UnixLib|UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf
+ OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf
+ DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+ NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
+ IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf
+ UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf
+ DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf
+
+[LibraryClasses.common.UEFI_APPLICATION]
+ DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
+ ScsiLib|MdePkg/Library/UefiScsiLib/UefiScsiLib.inf
+ UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
+ UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+ HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
+ MemoryAllocationLib|MdePkg/Library/DxeMemoryAllocationLib/DxeMemoryAllocationLib.inf
+ UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+ ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
+ UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+ UnixLib|UnixPkg/Library/DxeUnixLib/DxeUnixLib.inf
+ OemHookStatusCodeLib|UnixPkg/Library/DxeUnixOemHookStatusCodeLib/DxeUnixOemHookStatusCodeLib.inf
+ DebugLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+ PrintLib|MdeModulePkg/Library/EdkDxePrintLib/EdkDxePrintLib.inf
+
+################################################################################
+#
+# Pcd Section - list of all EDK II PCD Entries defined by this Platform.
+#
+################################################################################
+[PcdsFixedAtBuild.IA32]
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeMemorySize|1
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeRuntimeMemorySize|128
+
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase|0x280000
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwSpareBase|0x290000
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwWorkingBase|0x28e000
+
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixBootMode|1
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareFdSize|0x2a0000
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareBlockSize|0x10000
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogBase|0x28c000
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize|0x2000
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoveryBase|0x0
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoverySize|0x280000
+
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySizeForSecMain|L"64!64"|VOID*|10
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFirmwareVolume|L"../FV/FV_RECOVERY.fd"|VOID*|52
+
+ gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000
+ gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000
+ gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000
+ gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000
+ gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|1000000
+ gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000
+ gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000
+ gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x0f
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x1f
+ gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF
+ gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000040
+ gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdMaxPeiPcdCallBackNumberPerPcdEntry|0x08
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVpdBaseAddress|0x0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizeNonPopulateCapsule|0x0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdMaxSizePopulateCapsule|0x0
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciIncompatibleDeviceSupportMask|0
+ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueUncorrectableMemoryError|0x0005100 # EFI_COMPUTING_UNIT_MEMORY | EFI_CU_MEMORY_EC_UNCORRECTABLE3
+ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueRemoteConsoleError|0x01040006 # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_CONTROLLER_ERROR
+ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueRemoteConsoleReset|0x01040001 # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_PC_RESET
+ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueRemoteConsoleInputError|0x01040007 # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_INPUT_ERROR
+ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueRemoteConsoleOutputError|0x01040008 # EFI_PERIPHERAL_REMOTE_CONSOLE | EFI_P_EC_OUTPUT_ERROR
+ gEfiMdePkgTokenSpaceGuid.PcdUefiVariableDefaultTimeout|0x0008
+ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueEfiWatchDogTimerExpired|0x00011003
+ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueMemoryTestStarted|0x00051006
+ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueSetVirtualAddressMap|0x03101004
+ gEfiMdePkgTokenSpaceGuid.PcdStatusCodeValueUncorrectableMemoryError|0x00051003
+ gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320
+ gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200
+ gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits|8
+ gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity|1
+ gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits|1
+ gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|0
+
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x10000
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x2000
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x00c000
+ gEfiMdePkgTokenSpaceGuid.PcdMaximumGuidedExtractHandler|0x10
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxFvSupported|6
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreMaxPeimPerFv|32
+ gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x400
+ gEfiMdeModulePkgTokenSpaceGuid.PcdMaxHardwareErrorVariableSize|0x8000
+ gEfiMdeModulePkgTokenSpaceGuid.PcdVariableStoreSize|0x10000
+
+[PcdsFeatureFlag.common]
+ gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseTraverseEnabled|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseCallbackOnSetEnabled|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseExEnabled|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseGetSizeEnabled|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseSetEnabled|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseOEM|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplSupportEfiDecompress|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplSupportTianoDecompress|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplSupportCustomDecompress|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdDxeIplBuildShareCodeHobs|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdDxePcdDatabaseTraverseEnabled|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseHardSerial|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseEfiSerial|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseRuntimeMemory|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeUseDataHub|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInSerial|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInDataHub|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInRuntimeMemory|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInOEM|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleRest|FALSE
+ gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|FALSE
+ gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdNtEmulatorEnable|FALSE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText|TRUE
+ gEfiEdkModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText|TRUE
+ gEfiGenericPlatformTokenSpaceGuid.PcdPciIsaEnable|FALSE
+ gEfiGenericPlatformTokenSpaceGuid.PcdPciVgaEnable|FALSE
+ gEfiGenericPlatformTokenSpaceGuid.PcdPciBusHotplugDeviceSupport|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE
+ #gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|FALSE
+
+[PcdsFeatureFlag.IA32]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseTraverseEnabled|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseCallbackOnSetEnabled|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseExEnabled|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseGetSizeEnabled|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiPcdDatabaseSetEnabled|TRUE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseSerial|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseOEM|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|FALSE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplEnableIdt|FALSE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportEfiDecompress|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportTianoDecompress|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSupportCustomDecompress|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplBuildShareCodeHobs|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDxePcdDatabaseTraverseEnabled|TRUE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseHardSerial|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseEfiSerial|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseRuntimeMemory|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseDataHub|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeUseOEM|TRUE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInSerial|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInDataHub|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInRuntimeMemory|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdStatusCodeReplayInOEM|FALSE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleRest|FALSE
+ gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|FALSE
+ gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|FALSE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdNtEmulatorEnable|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathToText|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdDevicePathSupportDevicePathFromText|TRUE
+ gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|FALSE
+ gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|FALSE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdSupportUpdateCapsuleRest|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciIsaEnable|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciVgaEnable|FALSE
+ gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdPciBusHotplugDeviceSupport|TRUE
+ gEfiMdeModulePkgTokenSpaceGuid.PcdPeiCoreImageLoaderSearchTeSectionFirst|FALSE
+
+################################################################################
+#
+# Pcd Dynamic Section - list of all EDK II PCD Entries defined by this Platform
+#
+################################################################################
+
+[PcdsDynamicDefault.common.DEFAULT]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0
+ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableBase|0
+ gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageVariableBase|0x0|UINT32|4
+ gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageVariableSize|0x0|UINT32|4
+ gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0x0|UINT32|4
+ gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize|0x0|UINT32|4
+ gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0x0|UINT32|4
+ gEfiGenericPlatformTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize|0x0|UINT32|4
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixConsole|L"Bus Driver Console Window"|VOID*|50
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixUga|L"UGA Window"|VOID*|50
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixFileSystem|L".!../../../../EdkShellBinPkg/bin/ia32/Apps"|VOID*|106
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixVirtualDisk|L"disk1.img:FW"|VOID*|24
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixPhysicalDisk|L"E:RW;245760;512"|VOID*|30
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuModel|L"Intel(R) Processor Model"|VOID*|48
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixCpuSpeed|L"3000"|VOID*|8
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixMemorySize|L"64!64"|VOID*|10
+ gEfiUnixPkgTokenSpaceGuid.PcdUnixSerialPort|L"/dev/ttyS0!/dev/ttyS1"|VOID*|20
+
+################################################################################
+#
+# Components Section - list of all EDK II Modules needed by this Platform.
+#
+################################################################################
+[Components.IA32]
+ ##
+ # SEC Phase modules
+ ##
+ UnixPkg/Sec/SecMain.inf
+
+ ##
+ # PEI Phase modules
+ ##
+ MdeModulePkg/Core/Pei/PeiMain.inf
+ MdeModulePkg/Universal/PCD/Pei/Pcd.inf {
+ <LibraryClasses>
+ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ }
+ IntelFrameworkModulePkg/Universal/StatusCode/Pei/PeiStatusCode.inf
+ UnixPkg/BootModePei/BootModePei.inf
+ UnixPkg/UnixFlashMapPei/FlashMap.inf
+ MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTestPei.inf
+ MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
+ UnixPkg/UnixAutoScanPei/UnixAutoScan.inf
+ UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf
+ UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf
+ MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
+
+ ##
+ # DXE Phase modules
+ ##
+ MdeModulePkg/Core/Dxe/DxeMain.inf {
+ <LibraryClasses>
+ NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf
+ }
+ MdeModulePkg/Universal/PCD/Dxe/Pcd.inf {
+ <LibraryClasses>
+ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ }
+
+ UnixPkg/MetronomeDxe/Metronome.inf
+ UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf
+ UnixPkg/ResetRuntimeDxe/Reset.inf
+ MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
+ UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf
+ MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
+ IntelFrameworkModulePkg/Universal/DataHubDxe/DataHubDxe.inf
+ MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
+ MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf
+ UnixPkg/UnixThunkDxe/UnixThunk.inf
+ UnixPkg/CpuRuntimeDxe/Cpu.inf
+ MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.inf
+ IntelFrameworkModulePkg/Universal/DataHubStdErrDxe/DataHubStdErrDxe.inf
+ UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf
+ UnixPkg/TimerDxe/Timer.inf
+ IntelFrameworkModulePkg/Universal/StatusCode/Dxe/DxeStatusCode.inf
+ MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
+ MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+ MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
+ MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+ MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+ MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
+ MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
+ MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+ MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+ MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
+ MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
+ MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
+ MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
+ IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
+ MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
+ MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
+ IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf
+ UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf
+
+ UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf
+ UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf
+ UnixPkg/UnixUgaDxe/UnixUga.inf
+ UnixPkg/UnixConsoleDxe/UnixConsole.inf
+ UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf
+ MdeModulePkg/Application/HelloWorld/HelloWorld.inf
+
+ #
+ # Network stack drivers
+ # To test network drivers, need network Io driver(SnpNt32Io.dll), please refer to NETWORK-IO Subproject.
+ #
+ MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf
+ MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf
+ MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf
+ MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
+ MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf
+ MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf
+ MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
+ MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
+ MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
+
+ MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+ MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
+ MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf {
+ <LibraryClasses>
+ PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+ }
+
+[BuildOptions]
+ #DEBUG_*_IA32_DLINK_FLAGS = --shared
+ *_*_IA32_CC_FLAGS = -idirafter/usr/include
diff --git a/UnixPkg/UnixPkg.fdf b/UnixPkg/UnixPkg.fdf
new file mode 100644
index 0000000000..945c7ef210
--- /dev/null
+++ b/UnixPkg/UnixPkg.fdf
@@ -0,0 +1,376 @@
+# This is Unix FDF file with UEFI HII features enabled
+#
+# Copyright (c) 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.
+#
+
+################################################################################
+#
+# FD Section
+# The [FD] Section is made up of the definition statements and a
+# description of what goes into the Flash Device Image. Each FD section
+# defines one flash "device" image. A flash device image may be one of
+# the following: Removable media bootable image (like a boot floppy
+# image,) an Option ROM image (that would be "flashed" into an add-in
+# card,) a System "Flash" image (that would be burned into a system's
+# flash) or an Update ("Capsule") image that will be used to update and
+# existing system flash.
+#
+################################################################################
+[FD.Fv_Recovery]
+BaseAddress = 0x0|gEfiUnixPkgTokenSpaceGuid.PcdUnixFdBaseAddress #The base address of the FLASH Device.
+Size = 0x002a0000 #The size in bytes of the FLASH Device
+ErasePolarity = 1
+BlockSize = 0x10000
+NumBlocks = 0x2a
+
+################################################################################
+#
+# Following are lists of FD Region layout which correspond to the locations of different
+# images within the flash device.
+#
+# Regions must be defined in ascending order and may not overlap.
+#
+# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by
+# the pipe "|" character, followed by the size of the region, also in hex with the leading
+# "0x" characters. Like:
+# Offset|Size
+# PcdOffsetCName|PcdSizeCName
+# RegionType <FV, DATA, or FILE>
+#
+################################################################################
+0x00000000|0x00280000
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoveryBase|gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashFvRecoverySize
+FV = FvRecovery
+
+0x00280000|0x0000c000
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageVariableBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize
+#NV_VARIABLE_STORE
+DATA = {
+ ## This is the EFI_FIRMWARE_VOLUME_HEADER
+ # ZeroVector []
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ # FileSystemGuid: gEfiSystemNvDataFvGuid =
+ # { 0xFFF12B8D, 0x7696, 0x4C8B, { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }}
+ 0x8D, 0x2B, 0xF1, 0xFF, 0x96, 0x76, 0x8B, 0x4C,
+ 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50,
+ # FvLength: 0x20000
+ 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
+ # Signature "_FVH" #Attributes
+ 0x5f, 0x46, 0x56, 0x48, 0xff, 0xfe, 0x04, 0x00,
+ # HeaderLength #CheckSum #ExtHeaderOffset #Reserved #Revision
+ 0x48, 0x00, 0x36, 0x09, 0x00, 0x00, 0x00, 0x02,
+ # Blockmap[0]: 2 Blocks * 0x10000 Bytes / Block
+ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
+ # Blockmap[1]: End
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ ## This is the VARIABLE_STORE_HEADER
+ #Signature: "$VSS" #Size: 0xc000 (gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize) - 0x48 (HeaderLength) = 0xBFB8
+ # This can speed up the Variable Dispatch a bit.
+ 0x24, 0x56, 0x53, 0x53, 0xB8, 0xBF, 0x00, 0x00,
+ #FORMATTED: 0x5A #HEALTHY: 0xFE #Reserved: UINT16 #Reserved1: UINT32
+ 0x5A, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+}
+
+0x0028c000|0x00002000
+#NV_EVENT_LOG
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogBase|gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageEventLogSize
+
+0x0028e000|0x00002000
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwWorkingBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize
+#NV_FTW_WORKING
+DATA = {
+ # EFI_FAULT_TOLERANT_WORKING_BLOCK_HEADER->Signature = gEfiSystemNvDataFvGuid =
+ # { 0xFFF12B8D, 0x7696, 0x4C8B, { 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50 }}
+ 0x8D, 0x2B, 0xF1, 0xFF, 0x96, 0x76, 0x8B, 0x4C,
+ 0xA9, 0x85, 0x27, 0x47, 0x07, 0x5B, 0x4F, 0x50,
+ # Crc:UINT32 #WorkingBlockValid:1, WorkingBlockInvalid:1, Reserved
+ 0x85, 0xae, 0x2d, 0xbf, 0xFE, 0xFF, 0xFF, 0xFF,
+ # WriteQueueSize: UINT32
+ 0xE4, 0x1F, 0x00, 0x00
+}
+
+0x00290000|0x00010000
+#NV_FTW_SPARE
+gEfiUnixPkgTokenSpaceGuid.PcdUnixFlashNvStorageFtwSpareBase|gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize
+
+################################################################################
+#
+# FV Section
+#
+# [FV] section is used to define what components or modules are placed within a flash
+# device file. This section also defines order the components and modules are positioned
+# within the image. The [FV] section consists of define statements, set statements and
+# module statements.
+#
+################################################################################
+[FV.FvRecovery]
+FvAlignment = 16 #FV alignment and FV attributes setting.
+ERASE_POLARITY = 1
+MEMORY_MAPPED = TRUE
+STICKY_WRITE = TRUE
+LOCK_CAP = TRUE
+LOCK_STATUS = TRUE
+WRITE_DISABLED_CAP = TRUE
+WRITE_ENABLED_CAP = TRUE
+WRITE_STATUS = TRUE
+WRITE_LOCK_CAP = TRUE
+WRITE_LOCK_STATUS = TRUE
+READ_DISABLED_CAP = TRUE
+READ_ENABLED_CAP = TRUE
+READ_STATUS = TRUE
+READ_LOCK_CAP = TRUE
+READ_LOCK_STATUS = TRUE
+
+################################################################################
+#
+# The INF statements point to EDK component and EDK II module INF files, which will be placed into this FV image.
+# Parsing tools will scan the INF file to determine the type of component or module.
+# The component or module type is used to reference the standard rules
+# defined elsewhere in the FDF file.
+#
+# The format for INF statements is:
+# INF $(PathAndInfFileName)
+#
+################################################################################
+##
+# PEI Phase modules
+##
+##
+# PEI Apriori file example, more PEIM module added later.
+##
+APRIORI PEI {
+ INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
+ INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/PeiStatusCode.inf
+ }
+APRIORI DXE {
+ INF IntelFrameworkModulePkg/Universal/StatusCode/Dxe/DxeStatusCode.inf
+ INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
+ INF UnixPkg/MetronomeDxe/Metronome.inf
+ }
+INF MdeModulePkg/Core/Pei/PeiMain.inf
+INF MdeModulePkg/Universal/PCD/Pei/Pcd.inf
+INF IntelFrameworkModulePkg/Universal/StatusCode/Pei/PeiStatusCode.inf
+INF UnixPkg/BootModePei/BootModePei.inf
+INF UnixPkg/UnixFlashMapPei/FlashMap.inf
+INF MdeModulePkg/Universal/MemoryTest/BaseMemoryTestPei/BaseMemoryTestPei.inf
+INF UnixPkg/UnixAutoScanPei/UnixAutoScan.inf
+INF UnixPkg/UnixFirmwareVolumePei/UnixFwh.inf
+INF MdeModulePkg/Universal/Variable/Pei/VariablePei.inf
+INF UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf
+INF MdeModulePkg/Core/DxeIplPeim/DxeIpl.inf
+
+##
+# DXE Phase modules
+##
+INF MdeModulePkg/Core/Dxe/DxeMain.inf
+INF IntelFrameworkModulePkg/Universal/StatusCode/Dxe/DxeStatusCode.inf
+INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
+INF UnixPkg/MetronomeDxe/Metronome.inf
+INF UnixPkg/RealTimeClockRuntimeDxe/RealTimeClock.inf
+INF UnixPkg/ResetRuntimeDxe/Reset.inf
+INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
+INF UnixPkg/FvbServicesRuntimeDxe/UnixFwh.inf
+INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
+INF IntelFrameworkModulePkg/Universal/DataHubDxe/DataHubDxe.inf
+INF MdeModulePkg/Universal/EbcDxe/EbcDxe.inf
+INF MdeModulePkg/Universal/MemoryTest/NullMemoryTestDxe/NullMemoryTestDxe.inf
+INF UnixPkg/UnixThunkDxe/UnixThunk.inf
+INF UnixPkg/CpuRuntimeDxe/Cpu.inf
+INF MdeModulePkg/Universal/FirmwareVolume/FaultTolerantWriteDxe/FtwLite.inf
+INF IntelFrameworkModulePkg/Universal/DataHubStdErrDxe/DataHubStdErrDxe.inf
+INF UnixPkg/MiscSubClassPlatformDxe/MiscSubClassDriver.inf
+INF UnixPkg/TimerDxe/Timer.inf
+INF MdeModulePkg/Universal/Variable/RuntimeDxe/VariableRuntimeDxe.inf
+INF MdeModulePkg/Universal/WatchdogTimerDxe/WatchdogTimer.inf
+INF MdeModulePkg/Universal/MonotonicCounterRuntimeDxe/MonotonicCounterRuntimeDxe.inf
+INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
+INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
+INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
+INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
+INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
+INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
+INF MdeModulePkg/Universal/Disk/DiskIoDxe/DiskIoDxe.inf
+INF MdeModulePkg/Universal/Disk/PartitionDxe/PartitionDxe.inf
+INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
+INF IntelFrameworkModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
+INF MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBusDxe.inf
+INF MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDiskDxe.inf
+INF IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/IdeBusDxe.inf
+INF UnixPkg/UnixBusDriverDxe/UnixBusDriver.inf
+
+INF UnixPkg/UnixBlockIoDxe/UnixBlockIo.inf
+INF UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf
+INF UnixPkg/UnixUgaDxe/UnixUga.inf
+INF UnixPkg/UnixConsoleDxe/UnixConsole.inf
+INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
+INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
+INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
+INF UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf
+INF MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf
+INF MdeModulePkg/Application/HelloWorld/HelloWorld.inf
+
+#
+# Network stack drivers
+# To test network drivers, need network Io driver(SnpNt32Io.dll), please refer to NETWORK-IO Subproject.
+#
+#INF MdeModulePkg/Universal/Network/DpcDxe/DpcDxe.inf
+#INF MdeModulePkg/Universal/Network/ArpDxe/ArpDxe.inf
+#INF MdeModulePkg/Universal/Network/Dhcp4Dxe/Dhcp4Dxe.inf
+#INF MdeModulePkg/Universal/Network/Ip4ConfigDxe/Ip4ConfigDxe.inf
+#INF MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Dxe.inf
+#INF MdeModulePkg/Universal/Network/MnpDxe/MnpDxe.inf
+#INF MdeModulePkg/Universal/Network/Mtftp4Dxe/Mtftp4Dxe.inf
+#INF MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Dxe.inf
+#INF MdeModulePkg/Universal/Network/Udp4Dxe/Udp4Dxe.inf
+#INF UnixPkg/SnpUnixDxe/SnpUnixDxe.inf
+
+
+
+################################################################################
+#
+# FILE statements are provided so that a platform integrator can include
+# complete EFI FFS files, as well as a method for constructing FFS files
+# using curly "{}" brace scoping. The following three FILEs are
+# for binary shell, binary fat and logo module.
+#
+################################################################################
+FILE APPLICATION = c57ad6b7-0515-40a8-9d21-551652854e37 {
+ SECTION COMPRESS PI_STD {
+ SECTION GUIDED {
+ SECTION PE32 = EdkShellBinPkg/FullShell/ia32/Shell_Full.efi
+ }
+ }
+ }
+FILE DRIVER = 961578FE-B6B7-44c3-AF35-6BC705CD2B1F {
+ SECTION COMPRESS PI_STD {
+ SECTION GUIDED {
+ SECTION PE32 = FatBinPkg/EnhancedFatDxe/Ia32/Fat.efi
+ }
+ }
+ }
+FILE FREEFORM = 7BB28B99-61BB-11D5-9A5D-0090273FC14D {
+ SECTION COMPRESS PI_STD {
+ SECTION GUIDED {
+ SECTION RAW = MdeModulePkg/Logo/Logo.bmp
+ }
+ }
+ }
+
+
+################################################################################
+#
+# Rules are use with the [FV] section's module INF type to define
+# how an FFS file is created for a given INF file. The following Rule are the default
+# rules for the different module type. User can add the customized rules to define the
+# content of the FFS file.
+#
+################################################################################
+
+
+############################################################################
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section #
+############################################################################
+#
+#[Rule.Common.DXE_DRIVER]
+# FILE DRIVER = $(NAMED_GUID) {
+# DXE_DEPEX DXE_DEPEX Optional |.depex
+# COMPRESS PI_STD {
+# GUIDED {
+# PE32 PE32 |.efi
+# UI STRING="$(MODULE_NAME)" Optional
+# VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+# }
+# }
+# }
+#
+############################################################################
+
+[Rule.Common.PEI_CORE]
+ FILE PEI_CORE = $(NAMED_GUID) {
+ PE32 PE32 |.efi
+ UI STRING ="$(MODULE_NAME)" Optional
+ VERSION STRING ="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
+
+[Rule.Common.PEIM]
+ FILE PEIM = $(NAMED_GUID) {
+ PEI_DEPEX PEI_DEPEX Optional |.depex
+ PE32 PE32 |.efi
+ UI STRING="$(MODULE_NAME)" Optional
+ VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
+
+[Rule.Common.PEIM.TIANOCOMPRESSED]
+ FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
+ PEI_DEPEX PEI_DEPEX Optional |.depex
+ GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {
+ PE32 PE32 |.efi
+ UI STRING="$(MODULE_NAME)" Optional
+ VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
+ }
+
+[Rule.Common.DXE_CORE]
+ FILE DXE_CORE = $(NAMED_GUID) {
+ COMPRESS PI_STD {
+ PE32 PE32 |.efi
+ UI STRING="$(MODULE_NAME)" Optional
+ VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
+ }
+
+[Rule.Common.UEFI_DRIVER]
+ FILE DRIVER = $(NAMED_GUID) {
+ DXE_DEPEX DXE_DEPEX Optional |.depex
+ COMPRESS PI_STD {
+ GUIDED {
+ PE32 PE32 |.efi
+ UI STRING="$(MODULE_NAME)" Optional
+ VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
+ }
+ }
+
+[Rule.Common.DXE_DRIVER]
+ FILE DRIVER = $(NAMED_GUID) {
+ DXE_DEPEX DXE_DEPEX Optional |.depex
+ COMPRESS PI_STD {
+ GUIDED {
+ PE32 PE32 |.efi
+ UI STRING="$(MODULE_NAME)" Optional
+ VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
+ }
+ }
+
+[Rule.Common.DXE_RUNTIME_DRIVER]
+ FILE DRIVER = $(NAMED_GUID) {
+ DXE_DEPEX DXE_DEPEX Optional |.depex
+ COMPRESS PI_STD {
+ GUIDED {
+ PE32 PE32 |.efi
+ UI STRING="$(MODULE_NAME)" Optional
+ VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
+ }
+ }
+
+[Rule.Common.UEFI_APPLICATION]
+ FILE APPLICATION = $(NAMED_GUID) {
+ COMPRESS PI_STD {
+ GUIDED {
+ PE32 PE32 |.efi
+ UI STRING="$(MODULE_NAME)" Optional
+ VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
+ }
+ }
+ }
diff --git a/UnixPkg/UnixSerialIoDxe/ComponentName.c b/UnixPkg/UnixSerialIoDxe/ComponentName.c
new file mode 100644
index 0000000000..2b7cb92c64
--- /dev/null
+++ b/UnixPkg/UnixSerialIoDxe/ComponentName.c
@@ -0,0 +1,208 @@
+/*++
+
+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:
+
+ ComponentName.c
+
+Abstract:
+
+--*/
+
+#include "UnixSerialIo.h"
+
+//
+// EFI Component Name Functions
+//
+EFI_STATUS
+EFIAPI
+UnixSerialIoComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ );
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ );
+
+//
+// EFI Component Name Protocol
+//
+EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName = {
+ UnixSerialIoComponentNameGetDriverName,
+ UnixSerialIoComponentNameGetControllerName,
+ "eng"
+};
+
+static EFI_UNICODE_STRING_TABLE mUnixSerialIoDriverNameTable[] = {
+ { "eng", L"Unix Serial I/O Driver" },
+ { NULL , NULL }
+};
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the driver name that that the caller
+ is requesting, and it must match one of the languages specified
+ in SupportedLanguages. The number of languages supported by a
+ driver is up to the driver writer.
+ DriverName - A pointer to the Unicode string to return. This Unicode string
+ is the name of the driver specified by This in the language
+ specified by Language.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the Driver specified by This
+ and the language specified by Language was returned
+ in DriverName.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - DriverName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ return LookupUnicodeString (
+ Language,
+ gUnixSerialIoComponentName.SupportedLanguages,
+ mUnixSerialIoDriverNameTable,
+ DriverName
+ );
+}
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by an EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ ControllerHandle - The handle of a controller that the driver specified by
+ This is managing. This handle specifies the controller
+ whose name is to be returned.
+ ChildHandle - The handle of the child controller to retrieve the name
+ of. 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 retrieve the name of the
+ bus controller. It will not be NULL for a bus driver
+ that wishes to retrieve the name of a child controller.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language of the controller name
+ that that the caller is requesting, and it must match one
+ of the languages specified in SupportedLanguages. The
+ number of languages supported by a driver is up to the
+ driver writer.
+ ControllerName - A pointer to the Unicode string to return. This Unicode
+ string is the name of the controller specified by
+ ControllerHandle and ChildHandle in the language specified
+ by Language from the point of view of the driver specified
+ by This.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the user readable name in the
+ language specified by Language for the driver
+ specified by This was returned in DriverName.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ControllerName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This is not currently managing
+ the controller specified by ControllerHandle and
+ ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_SERIAL_IO_PROTOCOL *SerialIo;
+ UNIX_SERIAL_IO_PRIVATE_DATA *Private;
+
+ //
+ // Make sure this driver is currently managing ControllHandle
+ //
+ Status = EfiTestManagedDevice (
+ ControllerHandle,
+ gUnixSerialIoDriverBinding.DriverBindingHandle,
+ &gEfiUnixIoProtocolGuid
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // This is a bus driver, so ChildHandle must not be NULL.
+ //
+ if (ChildHandle == NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Status = EfiTestChildHandle (
+ ControllerHandle,
+ ChildHandle,
+ &gEfiUnixIoProtocolGuid
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Get our context back
+ //
+ Status = gBS->OpenProtocol (
+ ChildHandle,
+ &gEfiSerialIoProtocolGuid,
+ (VOID**)&SerialIo,
+ gUnixSerialIoDriverBinding.DriverBindingHandle,
+ ChildHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (SerialIo);
+
+ return LookupUnicodeString (
+ Language,
+ gUnixSerialIoComponentName.SupportedLanguages,
+ Private->ControllerNameTable,
+ ControllerName
+ );
+}
diff --git a/UnixPkg/UnixSerialIoDxe/EntryPoint.c b/UnixPkg/UnixSerialIoDxe/EntryPoint.c
new file mode 100644
index 0000000000..8f2b575786
--- /dev/null
+++ b/UnixPkg/UnixSerialIoDxe/EntryPoint.c
@@ -0,0 +1,49 @@
+/**@file
+ Entry Point Source file.
+
+ This file contains the user entry point
+
+ 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.
+**/
+
+#include "UnixSerialIo.h"
+
+/**
+ The user Entry Point for module UnixSerialIo. The user code starts with this function.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeUnixSerialIo(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = EfiLibInstallAllDriverProtocols (
+ ImageHandle,
+ SystemTable,
+ &gUnixSerialIoDriverBinding,
+ ImageHandle,
+ &gUnixSerialIoComponentName,
+ NULL,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+
+
+ return Status;
+}
diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c
new file mode 100644
index 0000000000..9f550f25c0
--- /dev/null
+++ b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.c
@@ -0,0 +1,1487 @@
+/*++
+
+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:
+
+ UnixSerialIo.c
+
+Abstract:
+
+ Our DriverBinding member functions operate on the handles
+ created by the NT Bus driver.
+
+ Handle(1) - UnixIo - DevicePath(1)
+
+ If a serial port is added to the system this driver creates a new handle.
+ The new handle is required, since the serial device must add an UART device
+ pathnode.
+
+ Handle(2) - SerialIo - DevicePath(1)\UART
+
+ The driver then adds a gEfiUnixSerialPortGuid as a protocol to Handle(1).
+ The instance data for this protocol is the private data used to create
+ Handle(2).
+
+ Handle(1) - UnixIo - DevicePath(1) - UnixSerialPort
+
+ If the driver is unloaded Handle(2) is removed from the system and
+ gEfiUnixSerialPortGuid is removed from Handle(1).
+
+ Note: Handle(1) is any handle created by the Win NT Bus driver that is passed
+ into the DriverBinding member functions of this driver. This driver requires
+ a Handle(1) to contain a UnixIo protocol, a DevicePath protocol, and
+ the TypeGuid in the UnixIo must be gEfiUnixSerialPortGuid.
+
+ If Handle(1) contains a gEfiUnixSerialPortGuid protocol then the driver is
+ loaded on the device.
+
+--*/
+
+#include "UnixSerialIo.h"
+#include <termio.h>
+
+EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding = {
+ UnixSerialIoDriverBindingSupported,
+ UnixSerialIoDriverBindingStart,
+ UnixSerialIoDriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+STATIC
+UINTN
+ConvertBaud2Unix (
+ UINT64 BaudRate
+ )
+{
+ switch (BaudRate) {
+ case 0:
+ return B0;
+ case 50:
+ return B50;
+ case 75:
+ return B75;
+ case 110:
+ return B110;
+ case 134:
+ return B134;
+ case 150:
+ return B150;
+ case 200:
+ return B200;
+ case 300:
+ return B300;
+ case 600:
+ return B600;
+ case 1200:
+ return B1200;
+ case 1800:
+ return B1800;
+ case 2400:
+ return B2400;
+ case 4800:
+ return B4800;
+ case 9600:
+ return B9600;
+ case 19200:
+ return B19200;
+ case 38400:
+ return B38400;
+ case 57600:
+ return B57600;
+ case 115200:
+ return B115200;
+ case 230400:
+ return B230400;
+ case 460800:
+ return B460800;
+ case 500000:
+ return B500000;
+ case 576000:
+ return B576000;
+ case 921600:
+ return B921600;
+ case 1000000:
+ return B1000000;
+ case 1152000:
+ return B1152000;
+ case 1500000:
+ return B1500000;
+ case 2000000:
+ return B2000000;
+ case 2500000:
+ return B2500000;
+ case 3000000:
+ return B3000000;
+ case 3500000:
+ return B3500000;
+ case 4000000:
+ return B4000000;
+ case __MAX_BAUD:
+ default:
+ DEBUG ((EFI_D_ERROR, "Invalid Baud Rate Parameter!\r\n"));
+ }
+ return -1;
+}
+
+STATIC
+UINTN
+ConvertByteSize2Unix (
+ UINT8 DataBit
+ )
+{
+ switch (DataBit) {
+ case 5:
+ return CS5;
+ case 6:
+ return CS6;
+ case 7:
+ return CS7;
+ case 8:
+ return CS8;
+ default:
+ DEBUG ((EFI_D_ERROR, "Invalid Data Size Parameter!\r\n"));
+ }
+ return -1;
+}
+
+STATIC
+VOID
+ConvertParity2Unix (
+ struct termios *Options,
+ EFI_PARITY_TYPE Parity
+ )
+{
+ switch (Parity) {
+ case NoParity:
+ Options->c_cflag &= ~PARENB;
+ break;
+ case EvenParity:
+ Options->c_cflag |= PARENB;
+ break;
+ case OddParity:
+ Options->c_cflag |= PARENB;
+ Options->c_cflag |= PARODD;
+ break;
+ case MarkParity:
+ Options->c_cflag = PARENB | CMSPAR | PARODD;
+ break;
+ case SpaceParity:
+ Options->c_cflag |= PARENB | CMSPAR;
+ Options->c_cflag &= ~PARODD;
+ break;
+ default:
+ DEBUG ((EFI_D_ERROR, "Invalid Parity Parameter!\r\n"));
+ }
+}
+
+STATIC
+VOID
+ConvertStopBit2Unix (
+ struct termios *Options,
+ EFI_STOP_BITS_TYPE StopBits
+ )
+{
+ switch (StopBits) {
+ case TwoStopBits:
+ Options->c_cflag |= CSTOPB;
+ break;
+ case OneStopBit:
+ case OneFiveStopBits:
+ case DefaultStopBits:
+ Options->c_cflag &= ~CSTOPB;
+ }
+}
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+ The implementation of EFI_DRIVER_BINDING_PROTOCOL.EFI_DRIVER_BINDING_SUPPORTED.
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ UART_DEVICE_PATH *UartNode;
+
+ //
+ // Open the IO Abstraction(s) needed to perform the supported test
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiDevicePathProtocolGuid,
+ (VOID**)&ParentDevicePath,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (Status == EFI_ALREADY_STARTED) {
+ return EFI_SUCCESS;
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiDevicePathProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID**)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (Status == EFI_ALREADY_STARTED) {
+ return EFI_SUCCESS;
+ }
+
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Make sure that the Unix Thunk Protocol is valid
+ //
+ if (UnixIo->UnixThunk->Signature != EFI_UNIX_THUNK_PROTOCOL_SIGNATURE) {
+ Status = EFI_UNSUPPORTED;
+ goto Error;
+ }
+
+ //
+ // Check the GUID to see if this is a handle type the driver supports
+ //
+ if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixSerialPortGuid)) {
+ Status = EFI_UNSUPPORTED;
+ goto Error;
+ }
+
+ if (RemainingDevicePath != NULL) {
+ Status = EFI_UNSUPPORTED;
+ UartNode = (UART_DEVICE_PATH *) RemainingDevicePath;
+ if (UartNode->Header.Type != MESSAGING_DEVICE_PATH ||
+ UartNode->Header.SubType != MSG_UART_DP ||
+ DevicePathNodeLength((EFI_DEVICE_PATH_PROTOCOL *)UartNode) != sizeof(UART_DEVICE_PATH)) {
+ goto Error;
+ }
+ if (UartNode->BaudRate < 0 || UartNode->BaudRate > SERIAL_PORT_MAX_BAUD_RATE) {
+ goto Error;
+ }
+ if (UartNode->Parity < NoParity || UartNode->Parity > SpaceParity) {
+ goto Error;
+ }
+ if (UartNode->DataBits < 5 || UartNode->DataBits > 8) {
+ goto Error;
+ }
+ if (UartNode->StopBits < OneStopBit || UartNode->StopBits > TwoStopBits) {
+ goto Error;
+ }
+ if ((UartNode->DataBits == 5) && (UartNode->StopBits == TwoStopBits)) {
+ goto Error;
+ }
+ if ((UartNode->DataBits >= 6) && (UartNode->DataBits <= 8) && (UartNode->StopBits == OneFiveStopBits)) {
+ goto Error;
+ }
+ Status = EFI_SUCCESS;
+ }
+
+Error:
+ //
+ // Close the I/O Abstraction(s) used to perform the supported test
+ //
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ UNIX_SERIAL_IO_PRIVATE_DATA *Private;
+ UINTN UnixHandle;
+ UART_DEVICE_PATH Node;
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
+ EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenInfoBuffer;
+ UINTN EntryCount;
+ UINTN Index;
+ EFI_SERIAL_IO_PROTOCOL *SerialIo;
+ CHAR8 AsciiDevName[1024];
+
+ DEBUG ((EFI_D_INFO, "SerialIo drive binding start!\r\n"));
+ Private = NULL;
+ UnixHandle = -1;
+
+ //
+ // Grab the protocols we need
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiDevicePathProtocolGuid,
+ (VOID**)&ParentDevicePath,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
+ return Status;
+ }
+
+ //
+ // Grab the IO abstraction we need to get any work done
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID**)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status) && Status != EFI_ALREADY_STARTED) {
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiDevicePathProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+ return Status;
+ }
+
+ if (Status == EFI_ALREADY_STARTED) {
+
+ if (RemainingDevicePath == NULL) {
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Make sure a child handle does not already exist. This driver can only
+ // produce one child per serial port.
+ //
+ Status = gBS->OpenProtocolInformation (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ &OpenInfoBuffer,
+ &EntryCount
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = EFI_ALREADY_STARTED;
+ for (Index = 0; Index < EntryCount; Index++) {
+ if (OpenInfoBuffer[Index].Attributes & EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER) {
+ Status = gBS->OpenProtocol (
+ OpenInfoBuffer[Index].ControllerHandle,
+ &gEfiSerialIoProtocolGuid,
+ (VOID**)&SerialIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (!EFI_ERROR (Status)) {
+ CopyMem (&Node, RemainingDevicePath, sizeof (UART_DEVICE_PATH));
+ Status = SerialIo->SetAttributes (
+ SerialIo,
+ Node.BaudRate,
+ SerialIo->Mode->ReceiveFifoDepth,
+ SerialIo->Mode->Timeout,
+ Node.Parity,
+ Node.DataBits,
+ Node.StopBits
+ );
+ }
+ break;
+ }
+ }
+
+ FreePool (OpenInfoBuffer);
+ return Status;
+ }
+
+ //
+ // Check to see if we can access the hardware device. If it's Open in Unix we
+ // will not get access.
+ //
+ UnicodeStrToAsciiStr(UnixIo->EnvString, AsciiDevName);
+ UnixHandle = UnixIo->UnixThunk->Open (AsciiDevName, O_RDWR | O_NOCTTY, 0);
+
+ if (UnixHandle == -1) {
+ DEBUG ((EFI_D_INFO, "Faile to open serial device, %s!\r\n", UnixIo->EnvString ));
+ UnixIo->UnixThunk->Perror (AsciiDevName);
+ Status = EFI_DEVICE_ERROR;
+ goto Error;
+ }
+ DEBUG ((EFI_D_INFO, "Success to open serial device %s, Hanle = 0x%x \r\n", UnixIo->EnvString, UnixHandle));
+
+ //
+ // Construct Private data
+ //
+ Private = AllocatePool (sizeof (UNIX_SERIAL_IO_PRIVATE_DATA));
+ if (Private == NULL) {
+ goto Error;
+ }
+
+ //
+ // This signature must be valid before any member function is called
+ //
+ Private->Signature = UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE;
+ Private->UnixHandle = UnixHandle;
+ Private->ControllerHandle = Handle;
+ Private->Handle = NULL;
+ Private->UnixThunk = UnixIo->UnixThunk;
+ Private->ParentDevicePath = ParentDevicePath;
+ Private->ControllerNameTable = NULL;
+
+ Private->SoftwareLoopbackEnable = FALSE;
+ Private->HardwareLoopbackEnable = FALSE;
+ Private->HardwareFlowControl = FALSE;
+ Private->Fifo.First = 0;
+ Private->Fifo.Last = 0;
+ Private->Fifo.Surplus = SERIAL_MAX_BUFFER_SIZE;
+
+ AddUnicodeString (
+ "eng",
+ gUnixSerialIoComponentName.SupportedLanguages,
+ &Private->ControllerNameTable,
+ UnixIo->EnvString
+ );
+
+ Private->SerialIo.Revision = SERIAL_IO_INTERFACE_REVISION;
+ Private->SerialIo.Reset = UnixSerialIoReset;
+ Private->SerialIo.SetAttributes = UnixSerialIoSetAttributes;
+ Private->SerialIo.SetControl = UnixSerialIoSetControl;
+ Private->SerialIo.GetControl = UnixSerialIoGetControl;
+ Private->SerialIo.Write = UnixSerialIoWrite;
+ Private->SerialIo.Read = UnixSerialIoRead;
+ Private->SerialIo.Mode = &Private->SerialIoMode;
+
+ if (RemainingDevicePath != NULL) {
+ //
+ // Match the configuration of the RemainingDevicePath. IsHandleSupported()
+ // already checked to make sure the RemainingDevicePath contains settings
+ // that we can support.
+ //
+ CopyMem (&Private->UartDevicePath, RemainingDevicePath, sizeof (UART_DEVICE_PATH));
+ } else {
+ //
+ // Build the device path by appending the UART node to the ParentDevicePath
+ // from the UnixIo handle. The Uart setings are zero here, since
+ // SetAttribute() will update them to match the default setings.
+ //
+ ZeroMem (&Private->UartDevicePath, sizeof (UART_DEVICE_PATH));
+ Private->UartDevicePath.Header.Type = MESSAGING_DEVICE_PATH;
+ Private->UartDevicePath.Header.SubType = MSG_UART_DP;
+ SetDevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath, sizeof (UART_DEVICE_PATH));
+ }
+
+ //
+ // Build the device path by appending the UART node to the ParentDevicePath
+ // from the UnixIo handle. The Uart setings are zero here, since
+ // SetAttribute() will update them to match the current setings.
+ //
+ Private->DevicePath = AppendDevicePathNode (
+ ParentDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath
+ );
+ if (Private->DevicePath == NULL) {
+ Status = EFI_OUT_OF_RESOURCES;
+ goto Error;
+ }
+
+ //
+ // Fill in Serial I/O Mode structure based on either the RemainingDevicePath or defaults.
+ //
+ Private->SerialIoMode.ControlMask = SERIAL_CONTROL_MASK;
+ Private->SerialIoMode.Timeout = SERIAL_TIMEOUT_DEFAULT;
+ Private->SerialIoMode.BaudRate = Private->UartDevicePath.BaudRate;
+ Private->SerialIoMode.ReceiveFifoDepth = SERIAL_FIFO_DEFAULT;
+ Private->SerialIoMode.DataBits = Private->UartDevicePath.DataBits;
+ Private->SerialIoMode.Parity = Private->UartDevicePath.Parity;
+ Private->SerialIoMode.StopBits = Private->UartDevicePath.StopBits;
+
+ //
+ // Issue a reset to initialize the COM port
+ //
+ Status = Private->SerialIo.Reset (&Private->SerialIo);
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+
+ //
+ // Create new child handle
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Private->Handle,
+ &gEfiSerialIoProtocolGuid,
+ &Private->SerialIo,
+ &gEfiDevicePathProtocolGuid,
+ Private->DevicePath,
+ NULL
+ );
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+
+ //
+ // Open For Child Device
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID**)&UnixIo,
+ This->DriverBindingHandle,
+ Private->Handle,
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
+ );
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+
+ return EFI_SUCCESS;
+
+Error:
+ //
+ // Use the Stop() function to free all resources allocated in Start()
+ //
+ if (Private != NULL) {
+ if (Private->Handle != NULL) {
+ This->Stop (This, Handle, 1, &Private->Handle);
+ } else {
+ if (UnixHandle != -1) {
+ Private->UnixThunk->Close (UnixHandle);
+ }
+
+ if (Private->DevicePath != NULL) {
+ FreePool (Private->DevicePath);
+ }
+
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+
+ FreePool (Private);
+ }
+ }
+
+ This->Stop (This, Handle, 0, NULL);
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoDriverBindingStop (
+ 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:
+
+ EFI_DEVICE_ERROR - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN Index;
+ BOOLEAN AllChildrenStopped;
+ EFI_SERIAL_IO_PROTOCOL *SerialIo;
+ UNIX_SERIAL_IO_PRIVATE_DATA *Private;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+
+ //
+ // Complete all outstanding transactions to Controller.
+ // Don't allow any new transaction to Controller to be started.
+ //
+
+ if (NumberOfChildren == 0) {
+ //
+ // Close the bus driver
+ //
+ Status = gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+ Status = gBS->CloseProtocol (
+ Handle,
+ &gEfiDevicePathProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+ return Status;
+ }
+
+ AllChildrenStopped = TRUE;
+
+ for (Index = 0; Index < NumberOfChildren; Index++) {
+ Status = gBS->OpenProtocol (
+ ChildHandleBuffer[Index],
+ &gEfiSerialIoProtocolGuid,
+ (VOID**)&SerialIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (!EFI_ERROR (Status)) {
+ Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (SerialIo);
+
+ ASSERT (Private->Handle == ChildHandleBuffer[Index]);
+
+ Status = gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ ChildHandleBuffer[Index]
+ );
+
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ChildHandleBuffer[Index],
+ &gEfiSerialIoProtocolGuid,
+ &Private->SerialIo,
+ &gEfiDevicePathProtocolGuid,
+ Private->DevicePath,
+ NULL
+ );
+
+ if (EFI_ERROR (Status)) {
+ gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID **) &UnixIo,
+ This->DriverBindingHandle,
+ ChildHandleBuffer[Index],
+ EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER
+ );
+ } else {
+ Private->UnixThunk->Close (Private->UnixHandle);
+
+ FreePool (Private->DevicePath);
+
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+
+ FreePool (Private);
+ }
+ }
+
+ if (EFI_ERROR (Status)) {
+ AllChildrenStopped = FALSE;
+ }
+ }
+
+ if (!AllChildrenStopped) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ return EFI_SUCCESS;
+}
+
+//
+// Serial IO Protocol member functions
+//
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoReset (
+ IN EFI_SERIAL_IO_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ UNIX_SERIAL_IO_PRIVATE_DATA *Private;
+ EFI_TPL Tpl;
+ UINTN UnixStatus;
+
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+ Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ UnixStatus = Private->UnixThunk->Tcflush (
+ Private->UnixHandle,
+ TCIOFLUSH
+ );
+ switch (UnixStatus) {
+ case EBADF:
+ DEBUG ((EFI_D_ERROR, "Invalid handle of serial device!\r\n"));
+ return EFI_DEVICE_ERROR;
+ case EINVAL:
+ DEBUG ((EFI_D_ERROR, "Invalid queue selector!\r\n"));
+ return EFI_DEVICE_ERROR;
+ case ENOTTY:
+ DEBUG ((EFI_D_ERROR, "The file associated with serial's handle is not a terminal!\r\n"));
+ return EFI_DEVICE_ERROR;
+ default:
+ DEBUG ((EFI_D_ERROR, "The serial IO device is reset successfully!\r\n"));
+ }
+
+ gBS->RestoreTPL (Tpl);
+
+ return This->SetAttributes (
+ This,
+ This->Mode->BaudRate,
+ This->Mode->ReceiveFifoDepth,
+ This->Mode->Timeout,
+ This->Mode->Parity,
+ (UINT8) This->Mode->DataBits,
+ This->Mode->StopBits
+ );
+}
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoSetAttributes (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ IN UINT64 BaudRate,
+ IN UINT32 ReceiveFifoDepth,
+ IN UINT32 Timeout,
+ IN EFI_PARITY_TYPE Parity,
+ IN UINT8 DataBits,
+ IN EFI_STOP_BITS_TYPE StopBits
+ )
+/*++
+
+Routine Description:
+
+ This function is used to set the attributes.
+
+Arguments:
+
+ This - A pointer to the EFI_SERIAL_IO_PROTOCOL structrue.
+ BaudRate - The Baud rate of the serial device.
+ ReceiveFifoDepth - The request depth of fifo on receive side.
+ Timeout - the request timeout for a single charact.
+ Parity - The type of parity used in serial device.
+ DataBits - Number of deata bits used in serial device.
+ StopBits - Number of stop bits used in serial device.
+
+Returns:
+ Status code
+
+ None
+
+--*/
+{
+ EFI_STATUS Status;
+ UNIX_SERIAL_IO_PRIVATE_DATA *Private;
+ EFI_TPL Tpl;
+ EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;
+
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);
+ Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ //
+ // Some of our arguments have defaults if a null value is passed in, and
+ // we must set the default values if a null argument is passed in.
+ //
+ if (BaudRate == 0) {
+ BaudRate = SERIAL_BAUD_DEFAULT;
+ }
+
+ if (ReceiveFifoDepth == 0) {
+ ReceiveFifoDepth = SERIAL_FIFO_DEFAULT;
+ }
+
+ if (Timeout == 0) {
+ Timeout = SERIAL_TIMEOUT_DEFAULT;
+ }
+
+ if (Parity == DefaultParity) {
+ Parity = NoParity;
+ }
+
+ if (DataBits == 0) {
+ DataBits = SERIAL_DATABITS_DEFAULT;
+ }
+
+ if (StopBits == DefaultStopBits) {
+ StopBits = OneStopBit;
+ }
+
+ //
+ // See if the new attributes already match the current attributes
+ //
+ if (Private->UartDevicePath.BaudRate == BaudRate &&
+ Private->UartDevicePath.DataBits == DataBits &&
+ Private->UartDevicePath.Parity == Parity &&
+ Private->UartDevicePath.StopBits == StopBits &&
+ Private->SerialIoMode.ReceiveFifoDepth == ReceiveFifoDepth &&
+ Private->SerialIoMode.Timeout == Timeout ) {
+ gBS->RestoreTPL(Tpl);
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Try to get options from serial device.
+ //
+ if (Private->UnixThunk->Tcgetattr (Private->UnixHandle, &Private->UnixTermios) == -1) {
+ Private->UnixThunk->Perror ("IoSetAttributes");
+ gBS->RestoreTPL (Tpl);
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Setting Baud Rate
+ //
+ Private->UnixThunk->Cfsetispeed (&Private->UnixTermios, ConvertBaud2Unix(BaudRate));
+ Private->UnixThunk->Cfsetospeed (&Private->UnixTermios, ConvertBaud2Unix(BaudRate));
+ //
+ // Setting DataBits
+ //
+ Private->UnixTermios.c_cflag &= ~CSIZE;
+ Private->UnixTermios.c_cflag |= ConvertByteSize2Unix (DataBits);
+ //
+ // Setting Parity
+ //
+ ConvertParity2Unix (&Private->UnixTermios, Parity);
+ //
+ // Setting StopBits
+ //
+ ConvertStopBit2Unix (&Private->UnixTermios, StopBits);
+ //
+ // Raw input
+ //
+ Private->UnixTermios.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
+ //
+ // Raw output
+ //
+ Private->UnixTermios.c_oflag &= ~OPOST;
+ //
+ // Support hardware flow control
+ //
+ Private->UnixTermios.c_cflag &= ~CRTSCTS;;
+ //
+ // Time out
+ //
+ Private->UnixTermios.c_cc[VMIN] = 0;
+ Private->UnixTermios.c_cc[VTIME] = (Timeout/1000000) * 10;
+
+ //
+ // Set the options
+ //
+ if (-1 == Private->UnixThunk->Tcsetattr (
+ Private->UnixHandle,
+ TCSANOW,
+ &Private->UnixTermios
+ )) {
+ DEBUG ((EFI_D_INFO, "Fail to set options for serial device!\r\n"));
+ return EFI_DEVICE_ERROR;
+ }
+
+ //
+ // Update mode
+ //
+ Private->SerialIoMode.BaudRate = BaudRate;
+ Private->SerialIoMode.ReceiveFifoDepth = ReceiveFifoDepth;
+ Private->SerialIoMode.Timeout = Timeout;
+ Private->SerialIoMode.Parity = Parity;
+ Private->SerialIoMode.DataBits = DataBits;
+ Private->SerialIoMode.StopBits = StopBits;
+ //
+ // See if Device Path Node has actually changed
+ //
+ if (Private->UartDevicePath.BaudRate == BaudRate &&
+ Private->UartDevicePath.DataBits == DataBits &&
+ Private->UartDevicePath.Parity == Parity &&
+ Private->UartDevicePath.StopBits == StopBits ) {
+ gBS->RestoreTPL(Tpl);
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Update the device path
+ //
+ Private->UartDevicePath.BaudRate = BaudRate;
+ Private->UartDevicePath.DataBits = DataBits;
+ Private->UartDevicePath.Parity = (UINT8) Parity;
+ Private->UartDevicePath.StopBits = (UINT8) StopBits;
+
+ NewDevicePath = AppendDevicePathNode (
+ Private->ParentDevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *) &Private->UartDevicePath
+ );
+ if (NewDevicePath == NULL) {
+ gBS->RestoreTPL (Tpl);
+ return EFI_DEVICE_ERROR;
+ }
+
+ if (Private->Handle != NULL) {
+ Status = gBS->ReinstallProtocolInterface (
+ Private->Handle,
+ &gEfiDevicePathProtocolGuid,
+ Private->DevicePath,
+ NewDevicePath
+ );
+ if (EFI_ERROR (Status)) {
+ gBS->RestoreTPL (Tpl);
+ return Status;
+ }
+ }
+
+ if (Private->DevicePath != NULL) {
+ FreePool (Private->DevicePath);
+ }
+
+ Private->DevicePath = NewDevicePath;
+
+ gBS->RestoreTPL (Tpl);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoSetControl (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ IN UINT32 Control
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Control - TODO: add argument description
+
+Returns:
+
+ EFI_DEVICE_ERROR - TODO: Add description for return value
+ EFI_DEVICE_ERROR - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SERIAL_IO_PRIVATE_DATA *Private;
+ UINTN Result;
+ UINTN Status;
+ struct termios Options;
+ EFI_TPL Tpl;
+
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+ Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ Result = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMGET, &Status);
+
+ if (Result == -1) {
+ Private->UnixThunk->Perror ("SerialSetControl");
+ gBS->RestoreTPL (Tpl);
+ return EFI_DEVICE_ERROR;
+ }
+
+ Private->HardwareFlowControl = FALSE;
+ Private->SoftwareLoopbackEnable = FALSE;
+ Private->HardwareLoopbackEnable = FALSE;
+
+ if (Control & EFI_SERIAL_REQUEST_TO_SEND) {
+ Options.c_cflag |= TIOCM_RTS;
+ }
+
+ if (Control & EFI_SERIAL_DATA_TERMINAL_READY) {
+ Options.c_cflag |= TIOCM_DTR;
+ }
+
+ if (Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) {
+ Private->HardwareFlowControl = TRUE;
+ }
+
+ if (Control & EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE) {
+ Private->SoftwareLoopbackEnable = TRUE;
+ }
+
+ if (Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) {
+ Private->HardwareLoopbackEnable = TRUE;
+ }
+
+ Result = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMSET, &Status);
+
+ if (Result == -1) {
+ Private->UnixThunk->Perror ("SerialSetControl");
+ gBS->RestoreTPL (Tpl);
+ return EFI_DEVICE_ERROR;
+ }
+
+ gBS->RestoreTPL (Tpl);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoGetControl (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ OUT UINT32 *Control
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Control - TODO: add argument description
+
+Returns:
+
+ EFI_DEVICE_ERROR - TODO: Add description for return value
+ EFI_DEVICE_ERROR - TODO: Add description for return value
+ EFI_DEVICE_ERROR - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SERIAL_IO_PRIVATE_DATA *Private;
+ UINTN Result;
+ UINTN Status;
+ UINT32 Bits;
+ EFI_TPL Tpl;
+ UINTN Bytes;
+
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+ Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);
+ Result = Private->UnixThunk->IoCtl (Private->UnixHandle, TIOCMGET, &Status);
+ if (Result == -1) {
+ Private->UnixThunk->Perror ("SerialGetControl");
+ gBS->RestoreTPL (Tpl);
+ return EFI_DEVICE_ERROR;
+ }
+
+ if ((Status & TIOCM_CTS) == TIOCM_CTS) {
+ Bits |= EFI_SERIAL_CLEAR_TO_SEND;
+ }
+
+ if ((Status & TIOCM_DSR) == TIOCM_DSR) {
+ Bits |= EFI_SERIAL_DATA_SET_READY;
+ }
+
+ if ((Status & TIOCM_DTR) == TIOCM_DTR) {
+ Bits |= EFI_SERIAL_DATA_TERMINAL_READY;
+ }
+
+ if ((Status & TIOCM_RTS) == TIOCM_RTS) {
+ Bits |= EFI_SERIAL_REQUEST_TO_SEND;
+ }
+
+ if ((Status & TIOCM_RNG) == TIOCM_RNG) {
+ Bits |= EFI_SERIAL_RING_INDICATE;
+ }
+
+ if ((Status & TIOCM_CAR) == TIOCM_CAR) {
+ Bits |= EFI_SERIAL_CARRIER_DETECT;
+ }
+
+ if (Private->HardwareFlowControl) {
+ Bits |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
+ }
+
+ if (Private->SoftwareLoopbackEnable) {
+ Bits |= EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE;
+ }
+
+ if (Private->HardwareLoopbackEnable) {
+ Bits |= EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE;
+ }
+
+ Result = Private->UnixThunk->IoCtl (Private->UnixHandle, FIONREAD, &Bytes);
+ if (Result == -1) {
+ Private->UnixThunk->Perror ("SerialGetControl");
+ gBS->RestoreTPL (Tpl);
+ return EFI_DEVICE_ERROR;
+ }
+
+ if (Bytes == 0) {
+ Bits |= EFI_SERIAL_INPUT_BUFFER_EMPTY;
+ }
+
+ *Control = Bits;
+
+ gBS->RestoreTPL (Tpl);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoWrite (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ EFI_DEVICE_ERROR - TODO: Add description for return value
+ EFI_SUCCESS - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SERIAL_IO_PRIVATE_DATA *Private;
+ UINT8 *ByteBuffer;
+ UINT32 TotalBytesWritten;
+ UINT32 BytesToGo;
+ UINT32 BytesWritten;
+ UINT32 Index;
+ UINT32 Control;
+ EFI_TPL Tpl;
+
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+ Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ ByteBuffer = (UINT8 *) Buffer;
+ TotalBytesWritten = 0;
+
+ if (Private->SoftwareLoopbackEnable || Private->HardwareLoopbackEnable) {
+ for (Index = 0; Index < *BufferSize; Index++) {
+ if (IsaSerialFifoAdd (&Private->Fifo, ByteBuffer[Index]) == EFI_SUCCESS) {
+ TotalBytesWritten++;
+ } else {
+ break;
+ }
+ }
+ } else {
+ BytesToGo = (*BufferSize);
+
+ do {
+ if (Private->HardwareFlowControl) {
+ //
+ // Send RTS
+ //
+ UnixSerialIoGetControl (&Private->SerialIo, &Control);
+ Control |= EFI_SERIAL_REQUEST_TO_SEND;
+ UnixSerialIoSetControl (&Private->SerialIo, Control);
+ }
+
+ //
+ // Do the write
+ //
+ BytesWritten = Private->UnixThunk->Write (
+ Private->UnixHandle,
+ &ByteBuffer[TotalBytesWritten],
+ BytesToGo
+ );
+
+ if (Private->HardwareFlowControl) {
+ //
+ // Assert RTS
+ //
+ UnixSerialIoGetControl (&Private->SerialIo, &Control);
+ Control &= ~ (UINT32) EFI_SERIAL_REQUEST_TO_SEND;
+ UnixSerialIoSetControl (&Private->SerialIo, Control);
+ }
+
+ TotalBytesWritten += BytesWritten;
+ BytesToGo -= BytesWritten;
+ } while (BytesToGo > 0);
+ }
+
+ *BufferSize = TotalBytesWritten;
+
+ gBS->RestoreTPL (Tpl);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoRead (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ EFI_DEVICE_ERROR - TODO: Add description for return value
+
+--*/
+{
+ UNIX_SERIAL_IO_PRIVATE_DATA *Private;
+ UINT32 BytesRead;
+ EFI_STATUS Status;
+ UINT32 Index;
+ UINT8 Data;
+ UINT32 Control;
+ EFI_TPL Tpl;
+
+ Tpl = gBS->RaiseTPL (TPL_NOTIFY);
+
+ Private = UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS (This);
+
+ //
+ // Do the read
+ //
+ if (Private->SoftwareLoopbackEnable || Private->HardwareLoopbackEnable) {
+ for (Index = 0, BytesRead = 0; Index < *BufferSize; Index++) {
+ if (IsaSerialFifoRemove (&Private->Fifo, &Data) == EFI_SUCCESS) {
+ ((UINT8 *) Buffer)[Index] = Data;
+ BytesRead++;
+ } else {
+ break;
+ }
+ }
+ } else {
+ if (Private->HardwareFlowControl) {
+ UnixSerialIoGetControl (&Private->SerialIo, &Control);
+ Control |= EFI_SERIAL_DATA_TERMINAL_READY;
+ UnixSerialIoSetControl (&Private->SerialIo, Control);
+ }
+
+ BytesRead = Private->UnixThunk->Read (Private->UnixHandle, Buffer, *BufferSize);
+ if (Private->HardwareFlowControl) {
+ UnixSerialIoGetControl (&Private->SerialIo, &Control);
+ Control &= ~ (UINT32) EFI_SERIAL_DATA_TERMINAL_READY;
+ UnixSerialIoSetControl (&Private->SerialIo, Control);
+ }
+
+ }
+
+ if (BytesRead != *BufferSize) {
+ Status = EFI_TIMEOUT;
+ } else {
+ Status = EFI_SUCCESS;
+ }
+
+ *BufferSize = (UINTN) BytesRead;
+
+ gBS->RestoreTPL (Tpl);
+
+ return Status;
+}
+
+BOOLEAN
+IsaSerialFifoFull (
+ IN SERIAL_DEV_FIFO *Fifo
+ )
+/*++
+
+ Routine Description:
+ Detect whether specific FIFO is full or not
+
+ Arguments:
+ Fifo SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO
+
+ Returns:
+ TRUE: the FIFO is full
+ FALSE: the FIFO is not full
+
+--*/
+{
+ if (Fifo->Surplus == 0) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+BOOLEAN
+IsaSerialFifoEmpty (
+ IN SERIAL_DEV_FIFO *Fifo
+ )
+/*++
+
+ Routine Description:
+ Detect whether specific FIFO is empty or not
+
+ Arguments:
+ Fifo SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO
+
+ Returns:
+ TRUE: the FIFO is empty
+ FALSE: the FIFO is not empty
+
+--*/
+{
+ if (Fifo->Surplus == SERIAL_MAX_BUFFER_SIZE) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+EFI_STATUS
+IsaSerialFifoAdd (
+ IN SERIAL_DEV_FIFO *Fifo,
+ IN UINT8 Data
+ )
+/*++
+
+ Routine Description:
+ Add data to specific FIFO
+
+ Arguments:
+ Fifo SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO
+ Data UINT8: the data added to FIFO
+
+ Returns:
+ EFI_SUCCESS: Add data to specific FIFO successfully
+ EFI_OUT_RESOURCE: Failed to add data because FIFO is already full
+
+--*/
+// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
+{
+ //
+ // if FIFO full can not add data
+ //
+ if (IsaSerialFifoFull (Fifo)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // FIFO is not full can add data
+ //
+ Fifo->Data[Fifo->Last] = Data;
+ Fifo->Surplus--;
+ Fifo->Last++;
+ if (Fifo->Last >= SERIAL_MAX_BUFFER_SIZE) {
+ Fifo->Last = 0;
+ }
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+IsaSerialFifoRemove (
+ IN SERIAL_DEV_FIFO *Fifo,
+ OUT UINT8 *Data
+ )
+/*++
+
+ Routine Description:
+ Remove data from specific FIFO
+
+ Arguments:
+ Fifo SERIAL_DEV_FIFO *: A pointer to the Data Structure SERIAL_DEV_FIFO
+ Data UINT8*: the data removed from FIFO
+
+ Returns:
+ EFI_SUCCESS: Remove data from specific FIFO successfully
+ EFI_OUT_RESOURCE: Failed to remove data because FIFO is empty
+
+--*/
+// TODO: EFI_OUT_OF_RESOURCES - add return value to function comment
+{
+ //
+ // if FIFO is empty, no data can remove
+ //
+ if (IsaSerialFifoEmpty (Fifo)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ //
+ // FIFO is not empty, can remove data
+ //
+ *Data = Fifo->Data[Fifo->First];
+ Fifo->Surplus++;
+ Fifo->First++;
+ if (Fifo->First >= SERIAL_MAX_BUFFER_SIZE) {
+ Fifo->First = 0;
+ }
+
+ return EFI_SUCCESS;
+}
diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h
new file mode 100644
index 0000000000..023ff48eb8
--- /dev/null
+++ b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.h
@@ -0,0 +1,572 @@
+/*++
+
+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:
+
+ UnixSerialIo.h
+
+Abstract:
+
+
+--*/
+
+#ifndef _UNIXPKG_SERIAL_IO_
+#define _UNIXPKG_SERIAL_IO_
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <termio.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "PiDxe.h"
+#include <Protocol/SerialIo.h>
+#include <Protocol/DevicePath.h>
+
+#include <Library/DebugLib.h>
+#include <Library/BaseLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UefiLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include "UnixDxe.h"
+
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName;
+
+#define SERIAL_MAX_BUFFER_SIZE 256
+#define TIMEOUT_STALL_INTERVAL 10
+
+typedef struct {
+ UINT32 First;
+ UINT32 Last;
+ UINT32 Surplus;
+ UINT8 Data[SERIAL_MAX_BUFFER_SIZE];
+} SERIAL_DEV_FIFO;
+
+#define UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE EFI_SIGNATURE_32 ('U', 'N', 's', 'i')
+typedef struct {
+ UINT64 Signature;
+
+ //
+ // Protocol data for the new handle we are going to add
+ //
+ EFI_HANDLE Handle;
+ EFI_SERIAL_IO_PROTOCOL SerialIo;
+ EFI_SERIAL_IO_MODE SerialIoMode;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+
+ //
+ // Private Data
+ //
+ EFI_HANDLE ControllerHandle;
+ EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
+ UART_DEVICE_PATH UartDevicePath;
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+
+ EFI_UNICODE_STRING_TABLE *ControllerNameTable;
+
+ //
+ // Private NT type Data;
+ //
+ UINTN UnixHandle;
+ struct termios UnixTermios;
+
+ BOOLEAN SoftwareLoopbackEnable;
+ BOOLEAN HardwareFlowControl;
+ BOOLEAN HardwareLoopbackEnable;
+
+ SERIAL_DEV_FIFO Fifo;
+
+} UNIX_SERIAL_IO_PRIVATE_DATA;
+
+#define UNIX_SERIAL_IO_PRIVATE_DATA_FROM_THIS(a) \
+ CR(a, UNIX_SERIAL_IO_PRIVATE_DATA, SerialIo, UNIX_SERIAL_IO_PRIVATE_DATA_SIGNATURE)
+
+//
+// Global Protocol Variables
+//
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixSerialIoDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixSerialIoComponentName;
+
+//
+// Macros to convert EFI serial types to NT serial types.
+//
+
+//
+// one second
+//
+#define SERIAL_TIMEOUT_DEFAULT (1000 * 1000)
+#define SERIAL_BAUD_DEFAULT 115200
+#define SERIAL_FIFO_DEFAULT 14
+#define SERIAL_DATABITS_DEFAULT 8
+#define SERIAL_PARITY_DEFAULT DefaultParity
+#define SERIAL_STOPBITS_DEFAULT DefaultStopBits
+
+#define SERIAL_CONTROL_MASK (EFI_SERIAL_CLEAR_TO_SEND | \
+ EFI_SERIAL_DATA_SET_READY | \
+ EFI_SERIAL_RING_INDICATE | \
+ EFI_SERIAL_CARRIER_DETECT | \
+ EFI_SERIAL_REQUEST_TO_SEND | \
+ EFI_SERIAL_DATA_TERMINAL_READY | \
+ EFI_SERIAL_INPUT_BUFFER_EMPTY)
+
+#define ConvertBaud2Nt(x) (DWORD) x
+#define ConvertData2Nt(x) (BYTE) x
+
+#define ConvertParity2Nt(x) \
+ (BYTE) ( \
+ x == DefaultParity ? NOPARITY : \
+ x == NoParity ? NOPARITY : \
+ x == EvenParity ? EVENPARITY : \
+ x == OddParity ? ODDPARITY : \
+ x == MarkParity ? MARKPARITY : \
+ x == SpaceParity ? SPACEPARITY : 0 \
+ )
+
+#define ConvertStop2Nt(x) \
+ (BYTE) ( \
+ x == DefaultParity ? ONESTOPBIT : \
+ x == OneFiveStopBits ? ONE5STOPBITS : \
+ x == TwoStopBits ? TWOSTOPBITS : 0 \
+ )
+
+#define ConvertTime2Nt(x) ((x) / 1000)
+
+//
+// 115400 baud with rounding errors
+//
+#define SERIAL_PORT_MAX_BAUD_RATE 115400
+
+//
+// Fix the differences issue of linux header files termios.h
+//
+#ifndef B460800
+#define B460800 0010004
+#endif
+#ifndef B500000
+#define B500000 0010005
+#endif
+#ifndef B576000
+#define B576000 0010006
+#endif
+#ifndef B921600
+#define B921600 0010007
+#endif
+#ifndef B1000000
+#define B1000000 0010010
+#endif
+#ifndef B1152000
+#define B1152000 0010011
+#endif
+#ifndef B1500000
+#define B1500000 0010012
+#endif
+#ifndef B2000000
+#define B2000000 0010013
+#endif
+#ifndef B2500000
+#define B2500000 0010014
+#endif
+#ifndef B3000000
+#define B3000000 0010015
+#endif
+#ifndef B3500000
+#define B3500000 0010016
+#endif
+#ifndef B4000000
+#define B4000000 0010017
+#endif
+#ifndef __MAX_BAUD
+#define __MAX_BAUD B4000000
+#endif
+#ifndef CMSPAR
+#define CMSPAR 010000000000 /* mark or space (stick) parity */
+#endif
+#ifndef FIONREAD
+#define FIONREAD 0x541B
+#endif
+//
+// Function Prototypes
+//
+EFI_STATUS
+EFIAPI
+InitializeUnixSerialIo (
+ 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
+UnixSerialIoDriverBindingSupported (
+ 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
+UnixSerialIoDriverBindingStart (
+ 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
+UnixSerialIoDriverBindingStop (
+ 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
+EFIAPI
+UnixSerialIoReset (
+ IN EFI_SERIAL_IO_PROTOCOL *This
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoSetAttributes (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ IN UINT64 BaudRate,
+ IN UINT32 ReceiveFifoDepth,
+ IN UINT32 Timeout,
+ IN EFI_PARITY_TYPE Parity,
+ IN UINT8 DataBits,
+ IN EFI_STOP_BITS_TYPE StopBits
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ BaudRate - TODO: add argument description
+ ReceiveFifoDepth - TODO: add argument description
+ Timeout - TODO: add argument description
+ Parity - TODO: add argument description
+ DataBits - TODO: add argument description
+ StopBits - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoSetControl (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ IN UINT32 Control
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Control - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoGetControl (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ OUT UINT32 *Control
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ Control - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoWrite (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSerialIoRead (
+ IN EFI_SERIAL_IO_PROTOCOL *This,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+BOOLEAN
+IsaSerialFifoFull (
+ IN SERIAL_DEV_FIFO *Fifo
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Fifo - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+BOOLEAN
+IsaSerialFifoEmpty (
+ IN SERIAL_DEV_FIFO *Fifo
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Fifo - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+IsaSerialFifoAdd (
+ IN SERIAL_DEV_FIFO *Fifo,
+ IN UINT8 Data
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Fifo - TODO: add argument description
+ Data - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+IsaSerialFifoRemove (
+ IN SERIAL_DEV_FIFO *Fifo,
+ OUT UINT8 *Data
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Fifo - TODO: add argument description
+ Data - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+;
+
+EFI_STATUS
+IsaSerialReceiveTransmit (
+ UNIX_SERIAL_IO_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/UnixSerialIoDxe/UnixSerialIo.inf b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf
new file mode 100644
index 0000000000..0f74f2699e
--- /dev/null
+++ b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.inf
@@ -0,0 +1,69 @@
+#/** @file
+# Serial I/O driver
+#
+# Our DriverBinding member functions operate on the handles
+# created by the Unix Bus driver
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixSerialIo
+ FILE_GUID = 600F2BF2-63A7-48ca-9FD0-A3450B87EE05
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeUnixSerialIo
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32
+#
+# DRIVER_BINDING = gUnixSerialIoDriverBinding
+# COMPONENT_NAME = gUnixSerialIoComponentName
+#
+
+[Sources.common]
+ ComponentName.c
+ UnixSerialIo.c
+ UnixSerialIo.h
+ EntryPoint.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ MemoryAllocationLib
+ DevicePathLib
+ UefiBootServicesTableLib
+ BaseMemoryLib
+ UefiLib
+ UefiDriverEntryPoint
+ BaseLib
+ DebugLib
+
+
+[Guids]
+ gEfiUnixSerialPortGuid # ALWAYS_CONSUMED
+
+
+[Protocols]
+ gEfiSerialIoProtocolGuid # PROTOCOL BY_START
+ gEfiDevicePathProtocolGuid # PROTOCOL TO_START
+ gEfiUnixIoProtocolGuid # PROTOCOL TO_START
+
diff --git a/UnixPkg/UnixSerialIoDxe/UnixSerialIo.msa b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.msa
new file mode 100644
index 0000000000..793d24a3f3
--- /dev/null
+++ b/UnixPkg/UnixSerialIoDxe/UnixSerialIo.msa
@@ -0,0 +1,87 @@
+<?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>UnixSerialIo</ModuleName>
+ <ModuleType>UEFI_DRIVER</ModuleType>
+ <GuidValue>600F2BF2-63A7-48ca-9FD0-A3450B87EE05</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Serial I/O driver</Abstract>
+ <Description>Our DriverBinding member functions operate on the handles
+ created by the Unix Bus driver</Description>
+ <Copyright>Copyright (c) 2006 - 2007, 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</SupportedArchitectures>
+ <BinaryModule>false</BinaryModule>
+ <OutputFileBasename>UnixSerialIo</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverModelLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DevicePathLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixSerialIo.h</Filename>
+ <Filename>UnixSerialIo.c</Filename>
+ <Filename>ComponentName.c</Filename>
+ </SourceFiles>
+ <PackageDependencies>
+ <Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
+ <Package PackageGuid="f2805c44-8985-11db-9e98-0040d02b1835"/>
+ </PackageDependencies>
+ <Protocols>
+ <Protocol Usage="TO_START">
+ <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="TO_START">
+ <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="BY_START">
+ <ProtocolCName>gEfiSerialIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixSerialPortGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <DriverBinding>gUnixSerialIoDriverBinding</DriverBinding>
+ <ComponentName>gUnixSerialIoComponentName</ComponentName>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea> \ No newline at end of file
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/ComponentName.c b/UnixPkg/UnixSimpleFileSystemDxe/ComponentName.c
new file mode 100644
index 0000000000..347326dcb8
--- /dev/null
+++ b/UnixPkg/UnixSimpleFileSystemDxe/ComponentName.c
@@ -0,0 +1,204 @@
+/*++
+
+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:
+
+ ComponentName.c
+
+Abstract:
+
+--*/
+
+#include "UnixSimpleFileSystem.h"
+
+//
+// EFI Component Name Functions
+//
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ );
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ );
+
+//
+// EFI Component Name Protocol
+//
+EFI_COMPONENT_NAME_PROTOCOL gUnixSimpleFileSystemComponentName = {
+ UnixSimpleFileSystemComponentNameGetDriverName,
+ UnixSimpleFileSystemComponentNameGetControllerName,
+ "eng"
+};
+
+static EFI_UNICODE_STRING_TABLE mUnixSimpleFileSystemDriverNameTable[] = {
+ {
+ "eng",
+ L"Unix Simple File System Driver"
+ },
+ {
+ NULL,
+ NULL
+ }
+};
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the driver name that that the caller
+ is requesting, and it must match one of the languages specified
+ in SupportedLanguages. The number of languages supported by a
+ driver is up to the driver writer.
+ DriverName - A pointer to the Unicode string to return. This Unicode string
+ is the name of the driver specified by This in the language
+ specified by Language.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the Driver specified by This
+ and the language specified by Language was returned
+ in DriverName.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - DriverName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ return LookupUnicodeString (
+ Language,
+ gUnixSimpleFileSystemComponentName.SupportedLanguages,
+ mUnixSimpleFileSystemDriverNameTable,
+ DriverName
+ );
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by an EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ ControllerHandle - The handle of a controller that the driver specified by
+ This is managing. This handle specifies the controller
+ whose name is to be returned.
+ ChildHandle - The handle of the child controller to retrieve the name
+ of. 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 retrieve the name of the
+ bus controller. It will not be NULL for a bus driver
+ that wishes to retrieve the name of a child controller.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language of the controller name
+ that that the caller is requesting, and it must match one
+ of the languages specified in SupportedLanguages. The
+ number of languages supported by a driver is up to the
+ driver writer.
+ ControllerName - A pointer to the Unicode string to return. This Unicode
+ string is the name of the controller specified by
+ ControllerHandle and ChildHandle in the language specified
+ by Language from the point of view of the driver specified
+ by This.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the user readable name in the
+ language specified by Language for the driver
+ specified by This was returned in DriverName.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ControllerName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This is not currently managing
+ the controller specified by ControllerHandle and
+ ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
+ UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
+
+ //
+ // This is a device driver, so ChildHandle must be NULL.
+ //
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Make sure this driver is currently managing ControllerHandle
+ //
+ Status = EfiTestManagedDevice (
+ ControllerHandle,
+ gUnixSimpleFileSystemDriverBinding.DriverBindingHandle,
+ &gEfiUnixIoProtocolGuid
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Get our context back
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiSimpleFileSystemProtocolGuid,
+ (VOID**)&SimpleFileSystem,
+ gUnixSimpleFileSystemDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);
+
+ return LookupUnicodeString (
+ Language,
+ gUnixSimpleFileSystemComponentName.SupportedLanguages,
+ Private->ControllerNameTable,
+ ControllerName
+ );
+}
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/EntryPoint.c b/UnixPkg/UnixSimpleFileSystemDxe/EntryPoint.c
new file mode 100644
index 0000000000..44e271bc19
--- /dev/null
+++ b/UnixPkg/UnixSimpleFileSystemDxe/EntryPoint.c
@@ -0,0 +1,51 @@
+/**@file
+ Entry Point Source file.
+
+ This file contains the user entry point
+
+ 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.
+**/
+
+
+
+#include "UnixSimpleFileSystem.h"
+
+/**
+ The user Entry Point for module UnixSimpleFileSystem. The user code starts with this function.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeUnixSimpleFileSystem(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = EfiLibInstallAllDriverProtocols (
+ ImageHandle,
+ SystemTable,
+ &gUnixSimpleFileSystemDriverBinding,
+ ImageHandle,
+ &gUnixSimpleFileSystemComponentName,
+ NULL,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+
+
+ return Status;
+}
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c
new file mode 100644
index 0000000000..84ba962739
--- /dev/null
+++ b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.c
@@ -0,0 +1,2186 @@
+/*++
+
+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:
+
+ UnixSimpleFileSystem.c
+
+Abstract:
+
+ Produce Simple File System abstractions for directories on your PC using Posix APIs.
+ The configuration of what devices to mount or emulate comes from UNIX
+ environment variables. The variables must be visible to the Microsoft*
+ Developer Studio for them to work.
+
+ * Other names and brands may be claimed as the property of others.
+
+--*/
+
+#include "UnixSimpleFileSystem.h"
+
+EFI_DRIVER_BINDING_PROTOCOL gUnixSimpleFileSystemDriverBinding = {
+ UnixSimpleFileSystemDriverBindingSupported,
+ UnixSimpleFileSystemDriverBindingStart,
+ UnixSimpleFileSystemDriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+
+CHAR16 *
+EfiStrChr (
+ IN CHAR16 *Str,
+ IN CHAR16 Chr
+ )
+/*++
+
+Routine Description:
+
+ Locate the first occurance of a character in a string.
+
+Arguments:
+
+ Str - Pointer to NULL terminated unicode string.
+ Chr - Character to locate.
+
+Returns:
+
+ If Str is NULL, then NULL is returned.
+ If Chr is not contained in Str, then NULL is returned.
+ If Chr is contained in Str, then a pointer to the first occurance of Chr in Str is returned.
+
+--*/
+{
+ if (Str == NULL) {
+ return Str;
+ }
+
+ while (*Str != '\0' && *Str != Chr) {
+ ++Str;
+ }
+
+ return (*Str == Chr) ? Str : NULL;
+}
+
+BOOLEAN
+IsZero (
+ IN VOID *Buffer,
+ IN UINTN Length
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Buffer - TODO: add argument description
+ Length - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ if (Buffer == NULL || Length == 0) {
+ return FALSE;
+ }
+
+ if (*(UINT8 *) Buffer != 0) {
+ return FALSE;
+ }
+
+ if (Length > 1) {
+ if (!CompareMem (Buffer, (UINT8 *) Buffer + 1, Length - 1)) {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+VOID
+CutPrefix (
+ IN CHAR8 *Str,
+ IN UINTN Count
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ Str - TODO: add argument description
+ Count - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ CHAR8 *Pointer;
+
+ if (AsciiStrLen (Str) < Count) {
+ ASSERT (0);
+ }
+
+ for (Pointer = Str; *(Pointer + Count); Pointer++) {
+ *Pointer = *(Pointer + Count);
+ }
+
+ *Pointer = *(Pointer + Count);
+}
+
+
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+ Check to see if the driver supports a given controller.
+
+Arguments:
+
+ This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
+
+ ControllerHandle - EFI handle of the controller to test.
+
+ RemainingDevicePath - Pointer to remaining portion of a device path.
+
+Returns:
+
+ EFI_SUCCESS - The device specified by ControllerHandle and RemainingDevicePath is supported by the driver
+ specified by This.
+
+ EFI_ALREADY_STARTED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by
+ the driver specified by This.
+
+ EFI_ACCESS_DENIED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by
+ a different driver or an application that requires exclusive access.
+
+ EFI_UNSUPPORTED - The device specified by ControllerHandle and RemainingDevicePath is not supported by the
+ driver specified by This.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+
+ //
+ // Open the IO Abstraction(s) needed to perform the supported test
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID **)&UnixIo,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Make sure GUID is for a File System handle.
+ //
+ Status = EFI_UNSUPPORTED;
+ if (CompareGuid (UnixIo->TypeGuid, &gEfiUnixFileSystemGuid)) {
+ Status = EFI_SUCCESS;
+ }
+
+ //
+ // Close the I/O Abstraction(s) used to perform the supported test
+ //
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+ Starts a device controller or a bus controller.
+
+Arguments:
+
+ This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
+
+ ControllerHandle - EFI handle of the controller to start.
+
+ RemainingDevicePath - Pointer to remaining portion of a device path.
+
+Returns:
+
+ EFI_SUCCESS - The device or bus controller has been started.
+
+ EFI_DEVICE_ERROR - The device could not be started due to a device failure.
+
+ EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
+ INTN i;
+
+ Private = NULL;
+
+ //
+ // Open the IO Abstraction(s) needed
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID **)&UnixIo,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Validate GUID
+ //
+ if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixFileSystemGuid)) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ sizeof (UNIX_SIMPLE_FILE_SYSTEM_PRIVATE),
+ (VOID **)&Private
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ Private->Signature = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;
+ Private->UnixThunk = UnixIo->UnixThunk;
+ Private->FilePath = NULL;
+ Private->VolumeLabel = NULL;
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ StrLen (UnixIo->EnvString) + 1,
+ (VOID **)&Private->FilePath
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ for (i = 0; UnixIo->EnvString[i] != 0; i++)
+ Private->FilePath[i] = UnixIo->EnvString[i];
+ Private->FilePath[i] = 0;
+
+ Private->VolumeLabel = NULL;
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ StrSize (L"EFI_EMULATED"),
+ (VOID **)&Private->VolumeLabel
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ StrCpy (Private->VolumeLabel, L"EFI_EMULATED");
+
+ Private->SimpleFileSystem.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
+ Private->SimpleFileSystem.OpenVolume = UnixSimpleFileSystemOpenVolume;
+
+ Private->ControllerNameTable = NULL;
+
+ AddUnicodeString (
+ "eng",
+ gUnixSimpleFileSystemComponentName.SupportedLanguages,
+ &Private->ControllerNameTable,
+ UnixIo->EnvString
+ );
+
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &ControllerHandle,
+ &gEfiSimpleFileSystemProtocolGuid,
+ &Private->SimpleFileSystem,
+ NULL
+ );
+
+Done:
+ if (EFI_ERROR (Status)) {
+
+ if (Private != NULL) {
+
+ if (Private->VolumeLabel != NULL)
+ gBS->FreePool (Private->VolumeLabel);
+ if (Private->FilePath != NULL)
+ gBS->FreePool (Private->FilePath);
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+
+ gBS->FreePool (Private);
+ }
+
+ gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+ }
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemDriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
+
+ ControllerHandle - A handle to the device to be stopped.
+
+ NumberOfChildren - The number of child device handles in ChildHandleBuffer.
+
+ ChildHandleBuffer - An array of child device handles to be freed.
+
+Returns:
+
+ EFI_SUCCESS - The device has been stopped.
+
+ EFI_DEVICE_ERROR - The device could not be stopped due to a device failure.
+
+--*/
+// TODO: EFI_UNSUPPORTED - add return value to function comment
+{
+ EFI_STATUS Status;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
+ UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
+
+ //
+ // Get our context back
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiSimpleFileSystemProtocolGuid,
+ (VOID **)&SimpleFileSystem,
+ This->DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);
+
+ //
+ // Uninstall the Simple File System Protocol from ControllerHandle
+ //
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ ControllerHandle,
+ &gEfiSimpleFileSystemProtocolGuid,
+ &Private->SimpleFileSystem,
+ NULL
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = gBS->CloseProtocol (
+ ControllerHandle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ ControllerHandle
+ );
+ }
+
+ if (!EFI_ERROR (Status)) {
+ //
+ // Free our instance data
+ //
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+
+ gBS->FreePool (Private);
+ }
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemOpenVolume (
+ IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
+ OUT EFI_FILE **Root
+ )
+/*++
+
+Routine Description:
+
+ Open the root directory on a volume.
+
+Arguments:
+
+ This - A pointer to the volume to open.
+
+ Root - A pointer to storage for the returned opened file handle of the root directory.
+
+Returns:
+
+ EFI_SUCCESS - The volume was opened.
+
+ EFI_UNSUPPORTED - The volume does not support the requested file system type.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
+
+ EFI_ACCESS_DENIED - The service denied access to the file.
+
+ EFI_OUT_OF_RESOURCES - The file volume could not be opened due to lack of resources.
+
+ EFI_MEDIA_CHANGED - The device has new media or the media is no longer supported.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ EFI_STATUS Status;
+ UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *Private;
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ EFI_TPL OldTpl;
+
+ if (This == NULL || Root == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ Private = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);
+
+ PrivateFile = NULL;
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ sizeof (UNIX_EFI_FILE_PRIVATE),
+ (VOID **)&PrivateFile
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ PrivateFile->FileName = NULL;
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ AsciiStrSize (Private->FilePath),
+ (VOID **)&PrivateFile->FileName
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ AsciiStrCpy (PrivateFile->FileName, Private->FilePath);
+ PrivateFile->Signature = UNIX_EFI_FILE_PRIVATE_SIGNATURE;
+ PrivateFile->UnixThunk = Private->UnixThunk;
+ PrivateFile->SimpleFileSystem = This;
+ PrivateFile->IsRootDirectory = TRUE;
+ PrivateFile->IsDirectoryPath = TRUE;
+ PrivateFile->IsOpenedByRead = TRUE;
+ PrivateFile->EfiFile.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;
+ PrivateFile->EfiFile.Open = UnixSimpleFileSystemOpen;
+ PrivateFile->EfiFile.Close = UnixSimpleFileSystemClose;
+ PrivateFile->EfiFile.Delete = UnixSimpleFileSystemDelete;
+ PrivateFile->EfiFile.Read = UnixSimpleFileSystemRead;
+ PrivateFile->EfiFile.Write = UnixSimpleFileSystemWrite;
+ PrivateFile->EfiFile.GetPosition = UnixSimpleFileSystemGetPosition;
+ PrivateFile->EfiFile.SetPosition = UnixSimpleFileSystemSetPosition;
+ PrivateFile->EfiFile.GetInfo = UnixSimpleFileSystemGetInfo;
+ PrivateFile->EfiFile.SetInfo = UnixSimpleFileSystemSetInfo;
+ PrivateFile->EfiFile.Flush = UnixSimpleFileSystemFlush;
+ PrivateFile->fd = -1;
+ PrivateFile->Dir = NULL;
+ PrivateFile->Dirent = NULL;
+
+ *Root = &PrivateFile->EfiFile;
+
+ PrivateFile->Dir = PrivateFile->UnixThunk->OpenDir(PrivateFile->FileName);
+
+ if (PrivateFile->Dir == NULL) {
+ Status = EFI_ACCESS_DENIED;
+ }
+ else {
+ Status = EFI_SUCCESS;
+ }
+
+Done:
+ if (EFI_ERROR (Status)) {
+ if (PrivateFile) {
+ if (PrivateFile->FileName) {
+ gBS->FreePool (PrivateFile->FileName);
+ }
+
+ gBS->FreePool (PrivateFile);
+ }
+ }
+
+ gBS->RestoreTPL (OldTpl);
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemOpen (
+ IN EFI_FILE *This,
+ OUT EFI_FILE **NewHandle,
+ IN CHAR16 *FileName,
+ IN UINT64 OpenMode,
+ IN UINT64 Attributes
+ )
+/*++
+
+Routine Description:
+
+ Open a file relative to the source file location.
+
+Arguments:
+
+ This - A pointer to the source file location.
+
+ NewHandle - Pointer to storage for the new file handle.
+
+ FileName - Pointer to the file name to be opened.
+
+ OpenMode - File open mode information.
+
+ Attributes - File creation attributes.
+
+Returns:
+
+ EFI_SUCCESS - The file was opened.
+
+ EFI_NOT_FOUND - The file could not be found in the volume.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_MEDIA_CHANGED - The device has new media or the media is no longer supported.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
+
+ EFI_WRITE_PROTECTED - The volume or file is write protected.
+
+ EFI_ACCESS_DENIED - The service denied access to the file.
+
+ EFI_OUT_OF_RESOURCES - Not enough resources were available to open the file.
+
+ EFI_VOLUME_FULL - There is not enough space left to create the new file.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ EFI_FILE *Root;
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ UNIX_EFI_FILE_PRIVATE *NewPrivateFile;
+ UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;
+ EFI_STATUS Status;
+ CHAR16 *Src;
+ char *Dst;
+ CHAR8 *RealFileName;
+ char *ParseFileName;
+ char *GuardPointer;
+ CHAR8 TempChar;
+ UINTN Count;
+ BOOLEAN TrailingDash;
+ BOOLEAN LoopFinish;
+ UINTN InfoSize;
+ EFI_FILE_INFO *Info;
+
+ TrailingDash = FALSE;
+
+ //
+ // Check for obvious invalid parameters.
+ //
+ if (This == NULL || NewHandle == NULL || FileName == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ switch (OpenMode) {
+ case EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
+ if (Attributes &~EFI_FILE_VALID_ATTR) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Attributes & EFI_FILE_READ_ONLY) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // fall through
+ //
+ case EFI_FILE_MODE_READ:
+ case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:
+ break;
+
+ default:
+ return EFI_INVALID_PARAMETER;
+ }
+
+
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+ PrivateRoot = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
+ NewPrivateFile = NULL;
+
+ //
+ // BUGBUG: assume an open of root
+ // if current location, return current data
+ //
+ if (StrCmp (FileName, L"\\") == 0
+ || (StrCmp (FileName, L".") == 0 && PrivateFile->IsRootDirectory)) {
+ //
+ // BUGBUG: assume an open root
+ //
+OpenRoot:
+ Status = UnixSimpleFileSystemOpenVolume (PrivateFile->SimpleFileSystem, &Root);
+ NewPrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (Root);
+ goto Done;
+ }
+
+ if (FileName[StrLen (FileName) - 1] == L'\\') {
+ TrailingDash = TRUE;
+ FileName[StrLen (FileName) - 1] = 0;
+ }
+
+ //
+ // Attempt to open the file
+ //
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ sizeof (UNIX_EFI_FILE_PRIVATE),
+ (VOID **)&NewPrivateFile
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ CopyMem (NewPrivateFile, PrivateFile, sizeof (UNIX_EFI_FILE_PRIVATE));
+
+ NewPrivateFile->FileName = NULL;
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ AsciiStrSize (PrivateFile->FileName) + 1 + StrLen (FileName) + 1,
+ (VOID **)&NewPrivateFile->FileName
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ if (*FileName == L'\\') {
+ AsciiStrCpy (NewPrivateFile->FileName, PrivateRoot->FilePath);
+ // Skip first '\'.
+ Src = FileName + 1;
+ } else {
+ AsciiStrCpy (NewPrivateFile->FileName, PrivateFile->FileName);
+ Src = FileName;
+ }
+ Dst = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName);
+ GuardPointer = NewPrivateFile->FileName + AsciiStrLen(PrivateRoot->FilePath);
+ *Dst++ = '/';
+ // Convert unicode to ascii and '\' to '/'
+ while (*Src) {
+ if (*Src == '\\')
+ *Dst++ = '/';
+ else
+ *Dst++ = *Src;
+ Src++;
+ }
+ *Dst = 0;
+
+
+ //
+ // Get rid of . and .., except leading . or ..
+ //
+
+ //
+ // GuardPointer protect simplefilesystem root path not be destroyed
+ //
+
+ LoopFinish = FALSE;
+
+ while (!LoopFinish) {
+
+ LoopFinish = TRUE;
+
+ for (ParseFileName = GuardPointer; *ParseFileName; ParseFileName++) {
+ if (*ParseFileName == '.' &&
+ (*(ParseFileName + 1) == 0 || *(ParseFileName + 1) == '/') &&
+ *(ParseFileName - 1) == '/'
+ ) {
+
+ //
+ // cut /.
+ //
+ CutPrefix (ParseFileName - 1, 2);
+ LoopFinish = FALSE;
+ break;
+ }
+
+ if (*ParseFileName == '.' &&
+ *(ParseFileName + 1) == '.' &&
+ (*(ParseFileName + 2) == 0 || *(ParseFileName + 2) == '/') &&
+ *(ParseFileName - 1) == '/'
+ ) {
+
+ ParseFileName--;
+ Count = 3;
+
+ while (ParseFileName != GuardPointer) {
+ ParseFileName--;
+ Count++;
+ if (*ParseFileName == '/') {
+ break;
+ }
+ }
+
+ //
+ // cut /.. and its left directory
+ //
+ CutPrefix (ParseFileName, Count);
+ LoopFinish = FALSE;
+ break;
+ }
+ }
+ }
+
+ if (AsciiStrCmp (NewPrivateFile->FileName, PrivateRoot->FilePath) == 0) {
+ NewPrivateFile->IsRootDirectory = TRUE;
+ gBS->FreePool (NewPrivateFile->FileName);
+ gBS->FreePool (NewPrivateFile);
+ goto OpenRoot;
+ }
+
+ RealFileName = NewPrivateFile->FileName + AsciiStrLen(NewPrivateFile->FileName) - 1;
+ while (RealFileName > NewPrivateFile->FileName && *RealFileName != '/')
+ RealFileName--;
+
+ TempChar = *(RealFileName - 1);
+ *(RealFileName - 1) = 0;
+
+ *(RealFileName - 1) = TempChar;
+
+
+
+ //
+ // Test whether file or directory
+ //
+ NewPrivateFile->IsRootDirectory = FALSE;
+ NewPrivateFile->fd = -1;
+ NewPrivateFile->Dir = NULL;
+ if (OpenMode & EFI_FILE_MODE_CREATE) {
+ if (Attributes & EFI_FILE_DIRECTORY) {
+ NewPrivateFile->IsDirectoryPath = TRUE;
+ } else {
+ NewPrivateFile->IsDirectoryPath = FALSE;
+ }
+ } else {
+ struct stat finfo;
+ int res = NewPrivateFile->UnixThunk->Stat (NewPrivateFile->FileName, &finfo);
+ if (res == 0 && S_ISDIR(finfo.st_mode))
+ NewPrivateFile->IsDirectoryPath = TRUE;
+ else
+ NewPrivateFile->IsDirectoryPath = FALSE;
+ }
+
+ if (OpenMode & EFI_FILE_MODE_WRITE) {
+ NewPrivateFile->IsOpenedByRead = FALSE;
+ } else {
+ NewPrivateFile->IsOpenedByRead = TRUE;
+ }
+
+ Status = EFI_SUCCESS;
+
+ //
+ // deal with directory
+ //
+ if (NewPrivateFile->IsDirectoryPath) {
+
+ if ((OpenMode & EFI_FILE_MODE_CREATE)) {
+ //
+ // Create a directory
+ //
+ if (NewPrivateFile->UnixThunk->MkDir (NewPrivateFile->FileName, 0777) != 0) {
+ INTN LastError;
+
+ LastError = PrivateFile->UnixThunk->GetErrno ();
+ if (LastError != EEXIST) {
+ //gBS->FreePool (TempFileName);
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+ }
+ }
+
+ NewPrivateFile->Dir = NewPrivateFile->UnixThunk->OpenDir
+ (NewPrivateFile->FileName);
+
+ if (NewPrivateFile->Dir == NULL) {
+ if (PrivateFile->UnixThunk->GetErrno () == EACCES) {
+ Status = EFI_ACCESS_DENIED;
+ } else {
+ Status = EFI_NOT_FOUND;
+ }
+
+ goto Done;
+ }
+
+ } else {
+ //
+ // deal with file
+ //
+ NewPrivateFile->fd = NewPrivateFile->UnixThunk->Open
+ (NewPrivateFile->FileName,
+ ((OpenMode & EFI_FILE_MODE_CREATE) ? O_CREAT : 0)
+ | (NewPrivateFile->IsOpenedByRead ? O_RDONLY : O_RDWR),
+ 0666);
+ if (NewPrivateFile->fd < 0) {
+ if (PrivateFile->UnixThunk->GetErrno () == ENOENT) {
+ Status = EFI_NOT_FOUND;
+ } else {
+ Status = EFI_ACCESS_DENIED;
+ }
+ }
+ }
+
+ if ((OpenMode & EFI_FILE_MODE_CREATE) && Status == EFI_SUCCESS) {
+ //
+ // Set the attribute
+ //
+ InfoSize = 0;
+ Info = NULL;
+
+ Status = UnixSimpleFileSystemGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
+
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ InfoSize,
+ (VOID **)&Info
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ Status = UnixSimpleFileSystemGetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, &InfoSize, Info);
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ Info->Attribute = Attributes;
+
+ UnixSimpleFileSystemSetInfo (&NewPrivateFile->EfiFile, &gEfiFileInfoGuid, InfoSize, Info);
+ }
+
+Done: ;
+ if (TrailingDash) {
+ FileName[StrLen (FileName) + 1] = 0;
+ FileName[StrLen (FileName)] = L'\\';
+ }
+
+ if (EFI_ERROR (Status)) {
+ if (NewPrivateFile) {
+ if (NewPrivateFile->FileName) {
+ gBS->FreePool (NewPrivateFile->FileName);
+ }
+
+ gBS->FreePool (NewPrivateFile);
+ }
+ } else {
+ *NewHandle = &NewPrivateFile->EfiFile;
+ }
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemClose (
+ IN EFI_FILE *This
+ )
+/*++
+
+Routine Description:
+
+ Close the specified file handle.
+
+Arguments:
+
+ This - Pointer to a returned opened file handle.
+
+Returns:
+
+ EFI_SUCCESS - The file handle has been closed.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ EFI_TPL OldTpl;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ if (PrivateFile->fd >= 0) {
+ PrivateFile->UnixThunk->Close (PrivateFile->fd);
+ }
+ if (PrivateFile->Dir != NULL) {
+ PrivateFile->UnixThunk->CloseDir (PrivateFile->Dir);
+ }
+
+ PrivateFile->fd = -1;
+ PrivateFile->Dir = NULL;
+
+ if (PrivateFile->FileName) {
+ gBS->FreePool (PrivateFile->FileName);
+ }
+
+ gBS->FreePool (PrivateFile);
+
+ gBS->RestoreTPL (OldTpl);
+
+ return EFI_SUCCESS;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemDelete (
+ IN EFI_FILE *This
+ )
+/*++
+
+Routine Description:
+
+ Close and delete a file.
+
+Arguments:
+
+ This - Pointer to a returned opened file handle.
+
+Returns:
+
+ EFI_SUCCESS - The file handle was closed and deleted.
+
+ EFI_WARN_DELETE_FAILURE - The handle was closed but could not be deleted.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ EFI_STATUS Status;
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ EFI_TPL OldTpl;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+ Status = EFI_WARN_DELETE_FAILURE;
+
+ if (PrivateFile->IsDirectoryPath) {
+ if (PrivateFile->Dir != NULL) {
+ PrivateFile->UnixThunk->CloseDir (PrivateFile->Dir);
+ PrivateFile->Dir = NULL;
+ }
+
+ if (PrivateFile->UnixThunk->RmDir (PrivateFile->FileName) == 0) {
+ Status = EFI_SUCCESS;
+ }
+ } else {
+ PrivateFile->UnixThunk->Close (PrivateFile->fd);
+ PrivateFile->fd = -1;
+
+ if (!PrivateFile->IsOpenedByRead) {
+ if (!PrivateFile->UnixThunk->UnLink (PrivateFile->FileName)) {
+ Status = EFI_SUCCESS;
+ }
+ }
+ }
+
+ gBS->FreePool (PrivateFile->FileName);
+ gBS->FreePool (PrivateFile);
+
+ gBS->RestoreTPL (OldTpl);
+
+ return Status;
+}
+
+STATIC
+VOID
+UnixSystemTimeToEfiTime (
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk,
+ IN time_t SystemTime,
+ OUT EFI_TIME *Time
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ SystemTime - TODO: add argument description
+ TimeZone - TODO: add argument description
+ Time - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ struct tm *tm;
+ tm = UnixThunk->GmTime (&SystemTime);
+ Time->Year = 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 = UnixThunk->GetTimeZone ();
+
+ if (UnixThunk->GetDayLight ()) {
+ Time->Daylight = EFI_TIME_ADJUST_DAYLIGHT;
+ }
+}
+
+STATIC
+EFI_STATUS
+UnixSimpleFileSystemFileInfo (
+ UNIX_EFI_FILE_PRIVATE *PrivateFile,
+ IN CHAR8 *FileName,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ PrivateFile - TODO: add argument description
+ BufferSize - TODO: add argument description
+ Buffer - TODO: add argument description
+
+Returns:
+
+ TODO: add return values
+
+--*/
+{
+ EFI_STATUS Status;
+ UINTN Size;
+ UINTN NameSize;
+ UINTN ResultSize;
+ EFI_FILE_INFO *Info;
+ CHAR8 *RealFileName;
+ CHAR8 *TempPointer;
+ CHAR16 *BufferFileName;
+ struct stat buf;
+
+ if (FileName != NULL) {
+ RealFileName = FileName;
+ }
+ else if (PrivateFile->IsRootDirectory) {
+ RealFileName = "";
+ } else {
+ RealFileName = PrivateFile->FileName;
+ }
+
+ TempPointer = RealFileName;
+ while (*TempPointer) {
+ if (*TempPointer == '/') {
+ RealFileName = TempPointer + 1;
+ }
+
+ TempPointer++;
+ }
+
+ Size = SIZE_OF_EFI_FILE_INFO;
+ NameSize = AsciiStrSize (RealFileName) * 2;
+ ResultSize = Size + NameSize;
+
+ if (*BufferSize < ResultSize) {
+ *BufferSize = ResultSize;
+ return EFI_BUFFER_TOO_SMALL;
+ }
+ if (PrivateFile->UnixThunk->Stat (
+ FileName == NULL ? PrivateFile->FileName : FileName,
+ &buf) < 0)
+ return EFI_DEVICE_ERROR;
+
+ Status = EFI_SUCCESS;
+
+ Info = Buffer;
+ ZeroMem (Info, ResultSize);
+
+ Info->Size = ResultSize;
+ Info->FileSize = buf.st_size;
+ Info->PhysicalSize = MultU64x32 (buf.st_blocks, buf.st_blksize);
+
+ UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_ctime, &Info->CreateTime);
+ UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_atime, &Info->LastAccessTime);
+ UnixSystemTimeToEfiTime (PrivateFile->UnixThunk, buf.st_mtime, &Info->ModificationTime);
+
+ if (!(buf.st_mode & S_IWUSR)) {
+ Info->Attribute |= EFI_FILE_READ_ONLY;
+ }
+
+ if (S_ISDIR(buf.st_mode)) {
+ Info->Attribute |= EFI_FILE_DIRECTORY;
+ }
+
+
+ BufferFileName = (CHAR16 *)((CHAR8 *) Buffer + Size);
+ while (*RealFileName)
+ *BufferFileName++ = *RealFileName++;
+ *BufferFileName = 0;
+
+ *BufferSize = ResultSize;
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemRead (
+ IN EFI_FILE *This,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Read data from a file.
+
+Arguments:
+
+ This - Pointer to a returned open file handle.
+
+ BufferSize - On input, the size of the Buffer. On output, the number of bytes stored in the Buffer.
+
+ Buffer - Pointer to the first byte of the read Buffer.
+
+Returns:
+
+ EFI_SUCCESS - The data was read.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
+
+ EFI_BUFFER_TOO_SMALL - The supplied buffer size was too small to store the current directory entry.
+ *BufferSize has been updated with the size needed to complete the request.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ EFI_STATUS Status;
+ INTN Res;
+ UINTN Size;
+ UINTN NameSize;
+ UINTN ResultSize;
+ CHAR8 *FullFileName;
+ EFI_TPL OldTpl;
+
+ if (This == NULL || BufferSize == NULL || Buffer == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+ if (!PrivateFile->IsDirectoryPath) {
+
+ if (PrivateFile->fd < 0) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+
+ Res = PrivateFile->UnixThunk->Read (
+ PrivateFile->fd,
+ Buffer,
+ *BufferSize);
+ if (Res < 0) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+ *BufferSize = Res;
+ Status = EFI_SUCCESS;
+ goto Done;
+ }
+
+ //
+ // Read on a directory.
+ //
+ if (PrivateFile->Dir == NULL) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+
+ if (PrivateFile->Dirent == NULL) {
+ PrivateFile->Dirent = PrivateFile->UnixThunk->ReadDir (PrivateFile->Dir);
+ if (PrivateFile->Dirent == NULL) {
+ *BufferSize = 0;
+ Status = EFI_SUCCESS;
+ goto Done;
+ }
+ }
+
+ Size = SIZE_OF_EFI_FILE_INFO;
+ NameSize = AsciiStrLen (PrivateFile->Dirent->d_name) + 1;
+ ResultSize = Size + 2 * NameSize;
+
+ if (*BufferSize < ResultSize) {
+ *BufferSize = ResultSize;
+ Status = EFI_BUFFER_TOO_SMALL;
+ goto Done;
+ }
+ Status = EFI_SUCCESS;
+
+ *BufferSize = ResultSize;
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ AsciiStrLen(PrivateFile->FileName) + 1 + NameSize,
+ (VOID **)&FullFileName
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ AsciiStrCpy(FullFileName, PrivateFile->FileName);
+ AsciiStrCat(FullFileName, "/");
+ AsciiStrCat(FullFileName, PrivateFile->Dirent->d_name);
+ Status = UnixSimpleFileSystemFileInfo (PrivateFile,
+ FullFileName,
+ BufferSize,
+ Buffer);
+ gBS->FreePool (FullFileName);
+
+ PrivateFile->Dirent = NULL;
+
+Done:
+ gBS->RestoreTPL (OldTpl);
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemWrite (
+ IN EFI_FILE *This,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Write data to a file.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ BufferSize - On input, the number of bytes in the Buffer to write to the file. On output, the number of bytes
+ of data written to the file.
+
+ Buffer - Pointer to the first by of data in the buffer to write to the file.
+
+Returns:
+
+ EFI_SUCCESS - The data was written to the file.
+
+ EFI_UNSUPPORTED - Writes to an open directory are not supported.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
+
+ EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
+
+ EFI_ACCESS_DENIED - The file was opened read-only.
+
+ EFI_VOLUME_FULL - The volume is full.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ UINTN Res;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+
+ if (This == NULL || BufferSize == NULL || Buffer == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+ if (PrivateFile->fd < 0) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ if (PrivateFile->IsDirectoryPath) {
+ return EFI_UNSUPPORTED;
+ }
+
+ if (PrivateFile->IsOpenedByRead) {
+ return EFI_ACCESS_DENIED;
+ }
+
+ Res = PrivateFile->UnixThunk->Write (
+ PrivateFile->fd,
+ Buffer,
+ *BufferSize);
+ if (Res == (UINTN)-1) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+ *BufferSize = Res;
+ Status = EFI_SUCCESS;
+
+Done:
+ gBS->RestoreTPL (OldTpl);
+ return Status;
+
+ //
+ // bugbug: need to access unix error reporting
+ //
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemSetPosition (
+ IN EFI_FILE *This,
+ IN UINT64 Position
+ )
+/*++
+
+Routine Description:
+
+ Set a file's current position.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ Position - The byte position from the start of the file to set.
+
+Returns:
+
+ EFI_SUCCESS - The file position has been changed.
+
+ EFI_UNSUPPORTED - The seek request for non-zero is not supported for directories.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ EFI_STATUS Status;
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ UINT64 Pos;
+ EFI_TPL OldTpl;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+ if (PrivateFile->IsDirectoryPath) {
+ if (Position != 0) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ if (PrivateFile->Dir == NULL) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+ PrivateFile->UnixThunk->RewindDir (PrivateFile->Dir);
+ Status = EFI_SUCCESS;
+ goto Done;
+ } else {
+ if (Position == (UINT64) -1) {
+ Pos = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, 0, SEEK_END);
+ } else {
+ Pos = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, Position, SEEK_SET);
+ }
+ Status = (Pos == (UINT64) -1) ? EFI_DEVICE_ERROR : EFI_SUCCESS;
+ }
+
+Done:
+ gBS->RestoreTPL (OldTpl);
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemGetPosition (
+ IN EFI_FILE *This,
+ OUT UINT64 *Position
+ )
+/*++
+
+Routine Description:
+
+ Get a file's current position.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ Position - Pointer to storage for the current position.
+
+Returns:
+
+ EFI_SUCCESS - The file position has been reported.
+
+ EFI_UNSUPPORTED - Not valid for directories.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ EFI_STATUS Status;
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ EFI_TPL OldTpl;
+
+ if (This == NULL || Position == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+ if (PrivateFile->IsDirectoryPath) {
+ Status = EFI_UNSUPPORTED;
+ } else {
+ *Position = PrivateFile->UnixThunk->Lseek (PrivateFile->fd, 0, SEEK_CUR);
+ Status = (*Position == (UINT64) -1) ? EFI_DEVICE_ERROR : EFI_SUCCESS;
+ }
+
+ gBS->RestoreTPL (OldTpl);
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemGetInfo (
+ IN EFI_FILE *This,
+ IN EFI_GUID *InformationType,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Return information about a file or volume.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ InformationType - GUID describing the type of information to be returned.
+
+ BufferSize - On input, the size of the information buffer. On output, the number of bytes written to the
+ information buffer.
+
+ Buffer - Pointer to the first byte of the information buffer.
+
+Returns:
+
+ EFI_SUCCESS - The requested information has been written into the buffer.
+
+ EFI_UNSUPPORTED - The InformationType is not known.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
+
+ EFI_BUFFER_TOO_SMALL - The buffer size was too small to contain the requested information. The buffer size has
+ been updated with the size needed to complete the requested operation.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ EFI_STATUS Status;
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ EFI_FILE_SYSTEM_INFO *FileSystemInfoBuffer;
+ INTN UnixStatus;
+ UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;
+ struct statfs buf;
+ EFI_TPL OldTpl;
+
+ if (This == NULL || InformationType == NULL || BufferSize == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+ PrivateRoot = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
+
+ Status = EFI_UNSUPPORTED;
+
+ if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {
+ Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, BufferSize, Buffer);
+ } else if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
+ if (*BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {
+ *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
+ Status = EFI_BUFFER_TOO_SMALL;
+ goto Done;
+ }
+
+ UnixStatus = PrivateFile->UnixThunk->StatFs (PrivateFile->FileName, &buf);
+ if (UnixStatus < 0) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+
+ FileSystemInfoBuffer = (EFI_FILE_SYSTEM_INFO *) Buffer;
+ FileSystemInfoBuffer->Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
+ FileSystemInfoBuffer->ReadOnly = FALSE;
+
+ //
+ // Succeeded
+ //
+ FileSystemInfoBuffer->VolumeSize = MultU64x32 (buf.f_blocks, buf.f_bsize);
+ FileSystemInfoBuffer->FreeSpace = MultU64x32 (buf.f_bavail, buf.f_bsize);
+ FileSystemInfoBuffer->BlockSize = buf.f_bsize;
+
+
+ StrCpy ((CHAR16 *) FileSystemInfoBuffer->VolumeLabel, PrivateRoot->VolumeLabel);
+ *BufferSize = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel);
+ Status = EFI_SUCCESS;
+ } else if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
+ if (*BufferSize < StrSize (PrivateRoot->VolumeLabel)) {
+ *BufferSize = StrSize (PrivateRoot->VolumeLabel);
+ Status = EFI_BUFFER_TOO_SMALL;
+ goto Done;
+ }
+
+ StrCpy ((CHAR16 *) Buffer, PrivateRoot->VolumeLabel);
+ *BufferSize = StrSize (PrivateRoot->VolumeLabel);
+ Status = EFI_SUCCESS;
+ }
+
+Done:
+ gBS->RestoreTPL (OldTpl);
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemSetInfo (
+ IN EFI_FILE *This,
+ IN EFI_GUID *InformationType,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Set information about a file or volume.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ InformationType - GUID identifying the type of information to set.
+
+ BufferSize - Number of bytes of data in the information buffer.
+
+ Buffer - Pointer to the first byte of data in the information buffer.
+
+Returns:
+
+ EFI_SUCCESS - The file or volume information has been updated.
+
+ EFI_UNSUPPORTED - The information identifier is not recognised.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
+
+ EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
+
+ EFI_ACCESS_DENIED - The file was opened read-only.
+
+ EFI_VOLUME_FULL - The volume is full.
+
+ EFI_BAD_BUFFER_SIZE - The buffer size is smaller than the type indicated by InformationType.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ UNIX_SIMPLE_FILE_SYSTEM_PRIVATE *PrivateRoot;
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ EFI_FILE_INFO *OldFileInfo;
+ EFI_FILE_INFO *NewFileInfo;
+ EFI_STATUS Status;
+ UINTN OldInfoSize;
+ EFI_TPL OldTpl;
+ mode_t NewAttr;
+ struct stat OldAttr;
+ CHAR8 *OldFileName;
+ CHAR8 *NewFileName;
+ CHAR8 *CharPointer;
+ BOOLEAN AttrChangeFlag;
+ BOOLEAN NameChangeFlag;
+ BOOLEAN SizeChangeFlag;
+ BOOLEAN TimeChangeFlag;
+ struct tm NewLastAccessSystemTime;
+ struct tm NewLastWriteSystemTime;
+ EFI_FILE_SYSTEM_INFO *NewFileSystemInfo;
+ CHAR8 *AsciiFilePtr;
+ CHAR16 *UnicodeFilePtr;
+ INTN UnixStatus;
+
+ //
+ // Check for invalid parameters.
+ //
+ if (This == NULL || InformationType == NULL || BufferSize == 0 || Buffer == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ //
+ // Initialise locals.
+ //
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+ PrivateRoot = UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (PrivateFile->SimpleFileSystem);
+
+ Status = EFI_UNSUPPORTED;
+ OldFileInfo = NewFileInfo = NULL;
+ OldFileName = NewFileName = NULL;
+ AttrChangeFlag = NameChangeFlag = SizeChangeFlag = TimeChangeFlag = FALSE;
+
+ //
+ // Set file system information.
+ //
+ if (CompareGuid (InformationType, &gEfiFileSystemInfoGuid)) {
+ if (BufferSize < SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize (PrivateRoot->VolumeLabel)) {
+ Status = EFI_BAD_BUFFER_SIZE;
+ goto Done;
+ }
+
+ NewFileSystemInfo = (EFI_FILE_SYSTEM_INFO *) Buffer;
+
+ gBS->FreePool (PrivateRoot->VolumeLabel);
+
+ PrivateRoot->VolumeLabel = NULL;
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ StrSize (NewFileSystemInfo->VolumeLabel),
+ (VOID **)&PrivateRoot->VolumeLabel
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ StrCpy (PrivateRoot->VolumeLabel, NewFileSystemInfo->VolumeLabel);
+
+ Status = EFI_SUCCESS;
+ goto Done;
+ }
+
+ //
+ // Set volume label information.
+ //
+ if (CompareGuid (InformationType, &gEfiFileSystemVolumeLabelInfoIdGuid)) {
+ if (BufferSize < StrSize (PrivateRoot->VolumeLabel)) {
+ Status = EFI_BAD_BUFFER_SIZE;
+ goto Done;
+ }
+
+ StrCpy (PrivateRoot->VolumeLabel, (CHAR16 *) Buffer);
+
+ Status = EFI_SUCCESS;
+ goto Done;
+ }
+
+ if (!CompareGuid (InformationType, &gEfiFileInfoGuid)) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ if (BufferSize < SIZE_OF_EFI_FILE_INFO) {
+ Status = EFI_BAD_BUFFER_SIZE;
+ goto Done;
+ }
+
+ //
+ // Set file/directory information.
+ //
+
+ //
+ // Check for invalid set file information parameters.
+ //
+ NewFileInfo = (EFI_FILE_INFO *) Buffer;
+
+ if (NewFileInfo->Size <= sizeof (EFI_FILE_INFO) ||
+ (NewFileInfo->Attribute &~(EFI_FILE_VALID_ATTR)) ||
+ (sizeof (UINTN) == 4 && NewFileInfo->Size > 0xFFFFFFFF)
+ ) {
+ Status = EFI_INVALID_PARAMETER;
+ goto Done;
+ }
+
+ //
+ // bugbug: - This is not safe. We need something like EfiStrMaxSize()
+ // that would have an additional parameter that would be the size
+ // of the string array just in case there are no NULL characters in
+ // the string array.
+ //
+ //
+ // Get current file information so we can determine what kind
+ // of change request this is.
+ //
+ OldInfoSize = 0;
+ Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, &OldInfoSize, NULL);
+
+ if (Status != EFI_BUFFER_TOO_SMALL) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+
+ Status = gBS->AllocatePool (EfiBootServicesData, OldInfoSize,
+ (VOID **)&OldFileInfo);
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ Status = UnixSimpleFileSystemFileInfo (PrivateFile, NULL, &OldInfoSize, OldFileInfo);
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ AsciiStrSize (PrivateFile->FileName),
+ (VOID **)&OldFileName
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ AsciiStrCpy (OldFileName, PrivateFile->FileName);
+
+ //
+ // Make full pathname from new filename and rootpath.
+ //
+ if (NewFileInfo->FileName[0] == '\\') {
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ AsciiStrLen (PrivateRoot->FilePath) + 1 + StrLen (NewFileInfo->FileName) + 1,
+ (VOID **)&NewFileName
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ AsciiStrCpy (NewFileName, PrivateRoot->FilePath);
+ AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);
+ UnicodeFilePtr = NewFileInfo->FileName + 1;
+ *AsciiFilePtr++ ='/';
+ } else {
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ AsciiStrLen (PrivateFile->FileName) + 1 + StrLen (NewFileInfo->FileName) + 1,
+ (VOID **)&NewFileName
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ AsciiStrCpy (NewFileName, PrivateRoot->FilePath);
+ AsciiFilePtr = NewFileName + AsciiStrLen(NewFileName);
+ while (AsciiFilePtr > NewFileName && AsciiFilePtr[-1] != '/') {
+ AsciiFilePtr--;
+ }
+ UnicodeFilePtr = NewFileInfo->FileName;
+ }
+ // Convert to ascii.
+ while (*UnicodeFilePtr) {
+ *AsciiFilePtr++ = *UnicodeFilePtr++;
+ }
+ *AsciiFilePtr = 0;
+
+
+ //
+ // Is there an attribute change request?
+ //
+ if (NewFileInfo->Attribute != OldFileInfo->Attribute) {
+ if ((NewFileInfo->Attribute & EFI_FILE_DIRECTORY) != (OldFileInfo->Attribute & EFI_FILE_DIRECTORY)) {
+ Status = EFI_INVALID_PARAMETER;
+ goto Done;
+ }
+
+ AttrChangeFlag = TRUE;
+ }
+
+ //
+ // Is there a name change request?
+ // bugbug: - Need EfiStrCaseCmp()
+ //
+ if (StrCmp (NewFileInfo->FileName, OldFileInfo->FileName)) {
+ NameChangeFlag = TRUE;
+ }
+
+ //
+ // Is there a size change request?
+ //
+ if (NewFileInfo->FileSize != OldFileInfo->FileSize) {
+ SizeChangeFlag = TRUE;
+ }
+
+ //
+ // Is there a time stamp change request?
+ //
+ if (!IsZero (&NewFileInfo->CreateTime, sizeof (EFI_TIME)) &&
+ CompareMem (&NewFileInfo->CreateTime, &OldFileInfo->CreateTime, sizeof (EFI_TIME))
+ ) {
+ TimeChangeFlag = TRUE;
+ } else if (!IsZero (&NewFileInfo->LastAccessTime, sizeof (EFI_TIME)) &&
+ CompareMem (&NewFileInfo->LastAccessTime, &OldFileInfo->LastAccessTime, sizeof (EFI_TIME))
+ ) {
+ TimeChangeFlag = TRUE;
+ } else if (!IsZero (&NewFileInfo->ModificationTime, sizeof (EFI_TIME)) &&
+ CompareMem (&NewFileInfo->ModificationTime, &OldFileInfo->ModificationTime, sizeof (EFI_TIME))
+ ) {
+ TimeChangeFlag = TRUE;
+ }
+
+ //
+ // All done if there are no change requests being made.
+ //
+ if (!(AttrChangeFlag || NameChangeFlag || SizeChangeFlag || TimeChangeFlag)) {
+ Status = EFI_SUCCESS;
+ goto Done;
+ }
+
+ //
+ // Set file or directory information.
+ //
+ if (PrivateFile->UnixThunk->Stat (OldFileName, &OldAttr) != 0) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+
+ //
+ // Name change.
+ //
+ if (NameChangeFlag) {
+ //
+ // Close the handles first
+ //
+ if (PrivateFile->IsOpenedByRead) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ for (CharPointer = NewFileName; *CharPointer != 0 && *CharPointer != L'/'; CharPointer++) {
+ }
+
+ if (*CharPointer != 0) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ UnixStatus = PrivateFile->UnixThunk->Rename (OldFileName, NewFileName);
+
+ if (UnixStatus == 0) {
+ //
+ // modify file name
+ //
+ gBS->FreePool (PrivateFile->FileName);
+
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ AsciiStrSize (NewFileName),
+ (VOID **)&PrivateFile->FileName
+ );
+
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+
+ AsciiStrCpy (PrivateFile->FileName, NewFileName);
+ } else {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+ }
+
+ //
+ // Size change
+ //
+ if (SizeChangeFlag) {
+ if (PrivateFile->IsDirectoryPath) {
+ Status = EFI_UNSUPPORTED;
+ goto Done;
+ }
+
+ if (PrivateFile->IsOpenedByRead || OldFileInfo->Attribute & EFI_FILE_READ_ONLY) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ if (PrivateFile->UnixThunk->FTruncate (PrivateFile->fd, NewFileInfo->FileSize) != 0) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+
+ }
+
+ //
+ // Time change
+ //
+ if (TimeChangeFlag) {
+ struct utimbuf utime;
+
+ NewLastAccessSystemTime.tm_year = NewFileInfo->LastAccessTime.Year;
+ NewLastAccessSystemTime.tm_mon = NewFileInfo->LastAccessTime.Month;
+ NewLastAccessSystemTime.tm_mday = NewFileInfo->LastAccessTime.Day;
+ NewLastAccessSystemTime.tm_hour = NewFileInfo->LastAccessTime.Hour;
+ NewLastAccessSystemTime.tm_min = NewFileInfo->LastAccessTime.Minute;
+ NewLastAccessSystemTime.tm_sec = NewFileInfo->LastAccessTime.Second;
+ NewLastAccessSystemTime.tm_isdst = 0;
+
+ utime.actime = PrivateFile->UnixThunk->MkTime (&NewLastAccessSystemTime);
+
+ NewLastWriteSystemTime.tm_year = NewFileInfo->ModificationTime.Year;
+ NewLastWriteSystemTime.tm_mon = NewFileInfo->ModificationTime.Month;
+ NewLastWriteSystemTime.tm_mday = NewFileInfo->ModificationTime.Day;
+ NewLastWriteSystemTime.tm_hour = NewFileInfo->ModificationTime.Hour;
+ NewLastWriteSystemTime.tm_min = NewFileInfo->ModificationTime.Minute;
+ NewLastWriteSystemTime.tm_sec = NewFileInfo->ModificationTime.Second;
+ NewLastWriteSystemTime.tm_isdst = 0;
+
+ utime.modtime = PrivateFile->UnixThunk->MkTime (&NewLastWriteSystemTime);
+
+ if (utime.actime == (time_t)-1 || utime.modtime == (time_t)-1) {
+ goto Done;
+ }
+
+ if (PrivateFile->UnixThunk->UTime (PrivateFile->FileName, &utime) == -1) {
+ goto Done;
+ }
+ }
+
+ //
+ // No matter about AttrChangeFlag, Attribute must be set.
+ // Because operation before may cause attribute change.
+ //
+ NewAttr = OldAttr.st_mode;
+
+ if (NewFileInfo->Attribute & EFI_FILE_READ_ONLY) {
+ NewAttr &= ~(S_IRUSR | S_IRGRP | S_IROTH);
+ } else {
+ NewAttr |= S_IRUSR;
+ }
+
+ UnixStatus = PrivateFile->UnixThunk->Chmod (NewFileName, NewAttr);
+
+ if (UnixStatus != 0) {
+ Status = EFI_DEVICE_ERROR;
+ }
+
+Done:
+ if (OldFileInfo != NULL) {
+ gBS->FreePool (OldFileInfo);
+ }
+
+ if (OldFileName != NULL) {
+ gBS->FreePool (OldFileName);
+ }
+
+ if (NewFileName != NULL) {
+ gBS->FreePool (NewFileName);
+ }
+
+ gBS->RestoreTPL (OldTpl);
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemFlush (
+ IN EFI_FILE *This
+ )
+/*++
+
+Routine Description:
+
+ Flush all modified data to the media.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+Returns:
+
+ EFI_SUCCESS - The data has been flushed.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures have been corrupted.
+
+ EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
+
+ EFI_ACCESS_DENIED - The file was opened read-only.
+
+ EFI_VOLUME_FULL - The volume is full.
+
+--*/
+// TODO: EFI_INVALID_PARAMETER - add return value to function comment
+{
+ UNIX_EFI_FILE_PRIVATE *PrivateFile;
+ EFI_STATUS Status;
+ EFI_TPL OldTpl;
+
+ if (This == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = EFI_SUCCESS;
+ OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
+
+ PrivateFile = UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);
+
+
+ if (PrivateFile->IsDirectoryPath) {
+ goto Done;
+ }
+
+ if (PrivateFile->IsOpenedByRead) {
+ Status = EFI_ACCESS_DENIED;
+ goto Done;
+ }
+
+ if (PrivateFile->fd < 0) {
+ Status = EFI_DEVICE_ERROR;
+ goto Done;
+ }
+
+ PrivateFile->UnixThunk->FSync (PrivateFile->fd) == 0 ? EFI_SUCCESS : EFI_DEVICE_ERROR;
+
+Done:
+ gBS->RestoreTPL (OldTpl);
+
+ return Status;
+
+ //
+ // bugbug: - Use Unix error reporting.
+ //
+}
+
+
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h
new file mode 100644
index 0000000000..51dce83a91
--- /dev/null
+++ b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.h
@@ -0,0 +1,599 @@
+/*++
+
+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:
+
+ UnixSimpleFileSystem.h
+
+Abstract:
+
+ Produce Simple File System abstractions for a directory on your PC using Unix APIs.
+ The configuration of what devices to mount or emulate comes from
+ environment variables.
+
+--*/
+
+#ifndef _UNIX_SIMPLE_FILE_SYSTEM_H_
+#define _UNIX_SIMPLE_FILE_SYSTEM_H_
+
+#include "PiDxe.h"
+#include <Guid/FileSystemInfo.h>
+#include <Guid/FileInfo.h>
+#include <Guid/FileSystemVolumeLabelInfo.h>
+#include <Protocol/SimpleFileSystem.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 gUnixSimpleFileSystemDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixSimpleFileSystemComponentName;
+
+
+#define UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('L', 'X', 'f', 's')
+
+typedef struct {
+ UINTN Signature;
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFileSystem;
+ CHAR8 *FilePath;
+ CHAR16 *VolumeLabel;
+ EFI_UNICODE_STRING_TABLE *ControllerNameTable;
+} UNIX_SIMPLE_FILE_SYSTEM_PRIVATE;
+
+#define UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS(a) \
+ CR (a, \
+ UNIX_SIMPLE_FILE_SYSTEM_PRIVATE, \
+ SimpleFileSystem, \
+ UNIX_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE \
+ )
+
+#define UNIX_EFI_FILE_PRIVATE_SIGNATURE EFI_SIGNATURE_32 ('l', 'o', 'f', 's')
+
+typedef struct {
+ UINTN Signature;
+ EFI_UNIX_THUNK_PROTOCOL *UnixThunk;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
+ EFI_FILE EfiFile;
+ INTN fd;
+ DIR *Dir;
+ BOOLEAN IsRootDirectory;
+ BOOLEAN IsDirectoryPath;
+ BOOLEAN IsOpenedByRead;
+ char *FileName;
+ struct dirent *Dirent;
+} UNIX_EFI_FILE_PRIVATE;
+
+#define UNIX_EFI_FILE_PRIVATE_DATA_FROM_THIS(a) \
+ CR (a, \
+ UNIX_EFI_FILE_PRIVATE, \
+ EfiFile, \
+ UNIX_EFI_FILE_PRIVATE_SIGNATURE \
+ )
+
+//
+// Global Protocol Variables
+//
+extern EFI_DRIVER_BINDING_PROTOCOL gUnixSimpleFileSystemDriverBinding;
+extern EFI_COMPONENT_NAME_PROTOCOL gUnixSimpleFileSystemComponentName;
+
+//
+// Driver Binding protocol member functions
+//
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
+ )
+/*++
+
+Routine Description:
+
+ Check to see if the driver supports a given controller.
+
+Arguments:
+
+ This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
+
+ ControllerHandle - EFI handle of the controller to test.
+
+ RemainingDevicePath - Pointer to remaining portion of a device path.
+
+Returns:
+
+ EFI_SUCCESS - The device specified by ControllerHandle and RemainingDevicePath is supported by the driver
+ specified by This.
+
+ EFI_ALREADY_STARTED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by
+ the driver specified by This.
+
+ EFI_ACCESS_DENIED - The device specified by ControllerHandle and RemainingDevicePath is already being managed by
+ a different driver or an application that requires exclusive access.
+
+ EFI_UNSUPPORTED - The device specified by ControllerHandle and RemainingDevicePath is not supported by the
+ driver specified by This.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
+ )
+/*++
+
+Routine Description:
+
+ Starts a device controller or a bus controller.
+
+Arguments:
+
+ This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
+
+ ControllerHandle - EFI handle of the controller to start.
+
+ RemainingDevicePath - Pointer to remaining portion of a device path.
+
+Returns:
+
+ EFI_SUCCESS - The device or bus controller has been started.
+
+ EFI_DEVICE_ERROR - The device could not be started due to a device failure.
+
+ EFI_OUT_OF_RESOURCES - The request could not be completed due to lack of resources.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemDriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
+ )
+/*++
+
+Routine Description:
+
+ TODO: Add function description
+
+Arguments:
+
+ This - A pointer to an instance of the EFI_DRIVER_BINDING_PROTOCOL.
+
+ ControllerHandle - A handle to the device to be stopped.
+
+ NumberOfChildren - The number of child device handles in ChildHandleBuffer.
+
+ ChildHandleBuffer - An array of child device handles to be freed.
+
+Returns:
+
+ EFI_SUCCESS - The device has been stopped.
+
+ EFI_DEVICE_ERROR - The device could not be stopped due to a device failure.
+
+--*/
+;
+
+//
+// Simple File System protocol member functions
+//
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemOpenVolume (
+ IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
+ OUT EFI_FILE **Root
+ )
+/*++
+
+Routine Description:
+
+ Open the root directory on a volume.
+
+Arguments:
+
+ This - A pointer to the volume to open.
+
+ Root - A pointer to storage for the returned opened file handle of the root directory.
+
+Returns:
+
+ EFI_SUCCESS - The volume was opened.
+
+ EFI_UNSUPPORTED - The volume does not support the requested file system type.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
+
+ EFI_ACCESS_DENIED - The service denied access to the file.
+
+ EFI_OUT_OF_RESOURCES - The file volume could not be opened due to lack of resources.
+
+ EFI_MEDIA_CHANGED - The device has new media or the media is no longer supported.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemOpen (
+ IN EFI_FILE *This,
+ OUT EFI_FILE **NewHandle,
+ IN CHAR16 *FileName,
+ IN UINT64 OpenMode,
+ IN UINT64 Attributes
+ )
+/*++
+
+Routine Description:
+
+ Open a file relative to the source file location.
+
+Arguments:
+
+ This - A pointer to the source file location.
+
+ NewHandle - Pointer to storage for the new file handle.
+
+ FileName - Pointer to the file name to be opened.
+
+ OpenMode - File open mode information.
+
+ Attributes - File creation attributes.
+
+Returns:
+
+ EFI_SUCCESS - The file was opened.
+
+ EFI_NOT_FOUND - The file could not be found in the volume.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_MEDIA_CHANGED - The device has new media or the media is no longer supported.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
+
+ EFI_WRITE_PROTECTED - The volume or file is write protected.
+
+ EFI_ACCESS_DENIED - The service denied access to the file.
+
+ EFI_OUT_OF_RESOURCES - Not enough resources were available to open the file.
+
+ EFI_VOLUME_FULL - There is not enough space left to create the new file.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemClose (
+ IN EFI_FILE *This
+ )
+/*++
+
+Routine Description:
+
+ Close the specified file handle.
+
+Arguments:
+
+ This - Pointer to a returned opened file handle.
+
+Returns:
+
+ EFI_SUCCESS - The file handle has been closed.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemDelete (
+ IN EFI_FILE *This
+ )
+/*++
+
+Routine Description:
+
+ Close and delete a file.
+
+Arguments:
+
+ This - Pointer to a returned opened file handle.
+
+Returns:
+
+ EFI_SUCCESS - The file handle was closed and deleted.
+
+ EFI_WARN_DELETE_FAILURE - The handle was closed but could not be deleted.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemRead (
+ IN EFI_FILE *This,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Read data from a file.
+
+Arguments:
+
+ This - Pointer to a returned open file handle.
+
+ BufferSize - On input, the size of the Buffer. On output, the number of bytes stored in the Buffer.
+
+ Buffer - Pointer to the first byte of the read Buffer.
+
+Returns:
+
+ EFI_SUCCESS - The data was read.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupted.
+
+ EFI_BUFFER_TOO_SMALL - The supplied buffer size was too small to store the current directory entry.
+ *BufferSize has been updated with the size needed to complete the request.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemWrite (
+ IN EFI_FILE *This,
+ IN OUT UINTN *BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Write data to a file.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ BufferSize - On input, the number of bytes in the Buffer to write to the file. On output, the number of bytes
+ of data written to the file.
+
+ Buffer - Pointer to the first by of data in the buffer to write to the file.
+
+Returns:
+
+ EFI_SUCCESS - The data was written to the file.
+
+ EFI_UNSUPPORTED - Writes to an open directory are not supported.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
+
+ EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
+
+ EFI_ACCESS_DENIED - The file was opened read-only.
+
+ EFI_VOLUME_FULL - The volume is full.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemSetPosition (
+ IN EFI_FILE *This,
+ IN UINT64 Position
+ )
+/*++
+
+Routine Description:
+
+ Set a file's current position.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ Position - The byte position from the start of the file to set.
+
+Returns:
+
+ EFI_SUCCESS - The file position has been changed.
+
+ EFI_UNSUPPORTED - The seek request for non-zero is not supported for directories.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemGetPosition (
+ IN EFI_FILE *This,
+ OUT UINT64 *Position
+ )
+/*++
+
+Routine Description:
+
+ Get a file's current position.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ Position - Pointer to storage for the current position.
+
+Returns:
+
+ EFI_SUCCESS - The file position has been reported.
+
+ EFI_UNSUPPORTED - Not valid for directories.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemGetInfo (
+ IN EFI_FILE *This,
+ IN EFI_GUID *InformationType,
+ IN OUT UINTN *BufferSize,
+ OUT VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Return information about a file or volume.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ InformationType - GUID describing the type of information to be returned.
+
+ BufferSize - On input, the size of the information buffer. On output, the number of bytes written to the
+ information buffer.
+
+ Buffer - Pointer to the first byte of the information buffer.
+
+Returns:
+
+ EFI_SUCCESS - The requested information has been written into the buffer.
+
+ EFI_UNSUPPORTED - The InformationType is not known.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
+
+ EFI_BUFFER_TOO_SMALL - The buffer size was too small to contain the requested information. The buffer size has
+ been updated with the size needed to complete the requested operation.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemSetInfo (
+ IN EFI_FILE *This,
+ IN EFI_GUID *InformationType,
+ IN UINTN BufferSize,
+ IN VOID *Buffer
+ )
+/*++
+
+Routine Description:
+
+ Set information about a file or volume.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+ InformationType - GUID identifying the type of information to set.
+
+ BufferSize - Number of bytes of data in the information buffer.
+
+ Buffer - Pointer to the first byte of data in the information buffer.
+
+Returns:
+
+ EFI_SUCCESS - The file or volume information has been updated.
+
+ EFI_UNSUPPORTED - The information identifier is not recognised.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures are corrupt.
+
+ EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
+
+ EFI_ACCESS_DENIED - The file was opened read-only.
+
+ EFI_VOLUME_FULL - The volume is full.
+
+ EFI_BAD_BUFFER_SIZE - The buffer size is smaller than the type indicated by InformationType.
+
+--*/
+;
+
+EFI_STATUS
+EFIAPI
+UnixSimpleFileSystemFlush (
+ IN EFI_FILE *This
+ )
+/*++
+
+Routine Description:
+
+ Flush all modified data to the media.
+
+Arguments:
+
+ This - Pointer to an opened file handle.
+
+Returns:
+
+ EFI_SUCCESS - The data has been flushed.
+
+ EFI_NO_MEDIA - The device has no media.
+
+ EFI_DEVICE_ERROR - The device reported an error.
+
+ EFI_VOLUME_CORRUPTED - The file system structures have been corrupted.
+
+ EFI_WRITE_PROTECTED - The file, directory, volume, or device is write protected.
+
+ EFI_ACCESS_DENIED - The file was opened read-only.
+
+ EFI_VOLUME_FULL - The volume is full.
+
+--*/
+;
+
+#endif /* _UNIX_SIMPLE_FILE_SYSTEM_H_ */
+
+/* eof - UnixSimpleFileSystem.h */
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf
new file mode 100644
index 0000000000..f3cce016df
--- /dev/null
+++ b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.inf
@@ -0,0 +1,71 @@
+#/** @file
+# Simple filesystem driver
+#
+# Produce Simple File System abstractions for directories on your PC using Unix APIs.
+# The configuration of what devices to mount or emulate comes from
+# environment variables.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixSimpleFileSystem
+ FILE_GUID = f330834e-8985-11db-a295-0040d02b1835
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeUnixSimpleFileSystem
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+# DRIVER_BINDING = gUnixSimpleFileSystemDriverBinding
+# COMPONENT_NAME = gUnixSimpleFileSystemComponentName
+#
+
+[Sources.common]
+ ComponentName.c
+ UnixSimpleFileSystem.c
+ UnixSimpleFileSystem.h
+ EntryPoint.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ UefiLib
+ UefiDriverEntryPoint
+ BaseLib
+ DebugLib
+
+
+[Guids]
+ gEfiFileSystemVolumeLabelInfoIdGuid # SOMETIMES_CONSUMED
+ gEfiFileInfoGuid # SOMETIMES_CONSUMED
+ gEfiFileSystemInfoGuid # SOMETIMES_CONSUMED
+ gEfiUnixFileSystemGuid # ALWAYS_CONSUMED
+
+
+[Protocols]
+ gEfiSimpleFileSystemProtocolGuid # PROTOCOL BY_START
+ gEfiUnixIoProtocolGuid # PROTOCOL TO_START
+
diff --git a/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.msa b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.msa
new file mode 100644
index 0000000000..c57aa7165e
--- /dev/null
+++ b/UnixPkg/UnixSimpleFileSystemDxe/UnixSimpleFileSystem.msa
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>UnixSimpleFileSystem</ModuleName>
+ <ModuleType>UEFI_DRIVER</ModuleType>
+ <GuidValue>f330834e-8985-11db-a295-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Simple filesystem driver</Abstract>
+ <Description>
+ Produce Simple File System abstractions for directories on your PC using Unix APIs.
+ The configuration of what devices to mount or emulate comes from
+ environment variables.
+ </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>UnixSimpleFileSystem</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverModelLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixSimpleFileSystem.h</Filename>
+ <Filename>UnixSimpleFileSystem.c</Filename>
+ <Filename>ComponentName.c</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="TO_START">
+ <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="BY_START">
+ <ProtocolCName>gEfiSimpleFileSystemProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixFileSystemGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiFileSystemInfoGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiFileInfoGuid</GuidCName>
+ </GuidCNames>
+ <GuidCNames Usage="SOMETIMES_CONSUMED">
+ <GuidCName>gEfiFileSystemVolumeLabelInfoIdGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <DriverBinding>gUnixSimpleFileSystemDriverBinding</DriverBinding>
+ <ComponentName>gUnixSimpleFileSystemComponentName</ComponentName>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.c b/UnixPkg/UnixThunkDxe/UnixThunk.c
new file mode 100644
index 0000000000..df3512ca45
--- /dev/null
+++ b/UnixPkg/UnixThunkDxe/UnixThunk.c
@@ -0,0 +1,102 @@
+/*++
+
+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:
+
+ UnixThunk.c
+
+Abstract:
+
+ Produce UnixThunk protocol and it's associated device path and controller
+ state protocols. UnixThunk is to the emulation environment as
+ PCI_ROOT_BRIGE is to real hardware. The UnixBusDriver is the child of this
+ driver.
+
+ Since we are a root hardware abstraction we do not install a Driver Binding
+ protocol on this handle. This driver can only support one one UnixThunk protocol
+ in the system, since the device path is hard coded.
+
+--*/
+#include "PiDxe.h"
+#include "UnixDxe.h"
+#include "UnixThunk.h"
+#include <Protocol/DevicePath.h>
+
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/UnixLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+//
+// WinNtThunk Device Path Protocol Instance
+//
+static UNIX_THUNK_DEVICE_PATH mUnixThunkDevicePath = {
+ {
+ {
+ HARDWARE_DEVICE_PATH,
+ HW_VENDOR_DP,
+ {
+ (UINT8) (sizeof (VENDOR_DEVICE_PATH)),
+ (UINT8) ((sizeof (VENDOR_DEVICE_PATH)) >> 8)
+ }
+ },
+ EFI_UNIX_THUNK_PROTOCOL_GUID,
+ },
+ {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ END_DEVICE_PATH_LENGTH,
+ 0
+ }
+ }
+};
+
+
+EFI_STATUS
+EFIAPI
+InitializeUnixThunk (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+/*++
+
+Routine Description:
+ Install UnixThunk Protocol and it's associated Device Path protocol
+
+Arguments:
+ (Standard EFI Image entry - EFI_IMAGE_ENTRY_POINT)
+
+Returns:
+ EFI_SUCEESS - UnixThunk protocol is added or error status from
+ gBS->InstallMultiProtocolInterfaces().
+
+--*/
+// TODO: ImageHandle - add argument and description to function comment
+// TODO: SystemTable - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_HANDLE ControllerHandle;
+
+ ControllerHandle = NULL;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &ControllerHandle,
+ &gEfiUnixThunkProtocolGuid,
+ gUnix,
+ &gEfiDevicePathProtocolGuid,
+ &mUnixThunkDevicePath,
+ NULL
+ );
+
+ return Status;
+}
diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.h b/UnixPkg/UnixThunkDxe/UnixThunk.h
new file mode 100644
index 0000000000..ce9a2f45d8
--- /dev/null
+++ b/UnixPkg/UnixThunkDxe/UnixThunk.h
@@ -0,0 +1,30 @@
+/*++
+
+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:
+
+ UnixThunk.h
+
+Abstract:
+
+--*/
+
+// TODO: add protective #ifndef
+
+
+//
+// WinNtThunk Device Path Protocol Instance Type
+//
+typedef struct {
+ VENDOR_DEVICE_PATH Vendor;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} UNIX_THUNK_DEVICE_PATH;
+
diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.inf b/UnixPkg/UnixThunkDxe/UnixThunk.inf
new file mode 100644
index 0000000000..58bade962f
--- /dev/null
+++ b/UnixPkg/UnixThunkDxe/UnixThunk.inf
@@ -0,0 +1,60 @@
+#/** @file
+# A DXE driver to produce EFI_UNIX_THUNK_PROTOCOL
+#
+# 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.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixThunk
+ FILE_GUID = f38610fc-8985-11db-82d4-0040d02b1835
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeUnixThunk
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ UnixThunk.c
+ UnixThunk.h
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ UnixLib
+ UefiDriverEntryPoint
+ UefiLib
+ DebugLib
+
+
+[Protocols]
+ gEfiDevicePathProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+ gEfiUnixThunkProtocolGuid # PROTOCOL ALWAYS_PRODUCED
+
+
+[Depex]
+ TRUE
+
diff --git a/UnixPkg/UnixThunkDxe/UnixThunk.msa b/UnixPkg/UnixThunkDxe/UnixThunk.msa
new file mode 100644
index 0000000000..e1f262ac64
--- /dev/null
+++ b/UnixPkg/UnixThunkDxe/UnixThunk.msa
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>UnixThunk</ModuleName>
+ <ModuleType>DXE_DRIVER</ModuleType>
+ <GuidValue>f38610fc-8985-11db-82d4-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>A DXE driver to produce EFI_UNIX_THUNK_PROTOCOL</Abstract>
+ <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>
+ <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>UnixThunk</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>UnixLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixThunk.h</Filename>
+ <Filename>UnixThunk.c</Filename>
+ <Filename>UnixThunk.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>gEfiUnixThunkProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="ALWAYS_PRODUCED">
+ <ProtocolCName>gEfiDevicePathProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>InitializeUnixThunk</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.c b/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.c
new file mode 100644
index 0000000000..4cf6c0b042
--- /dev/null
+++ b/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.c
@@ -0,0 +1,79 @@
+/*++
+
+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:
+
+ UnixStuff.c
+
+Abstract:
+
+ Tiano PEIM to abstract construction of firmware volume in a Unix environment.
+
+Revision History
+
+--*/
+
+#include "PiPei.h"
+#include <Ppi/UnixThunk.h>
+#include <Library/DebugLib.h>
+#include <Library/PeimEntryPoint.h>
+#include <Library/HobLib.h>
+#include <Library/PeiServicesLib.h>
+#include <Library/PeiServicesTablePointerLib.h>
+
+EFI_STATUS
+EFIAPI
+PeimInitializeUnixStuff (
+ IN EFI_FFS_FILE_HEADER *FfsHeader,
+ IN EFI_PEI_SERVICES **PeiServices
+ )
+/*++
+
+Routine Description:
+
+ Perform a call-back into the SEC simulator to get Unix Stuff
+
+Arguments:
+
+ PeiServices - General purpose services available to every PEIM.
+
+Returns:
+
+ None
+
+--*/
+// TODO: FfsHeader - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
+ PEI_UNIX_THUNK_PPI *PeiUnixService;
+ VOID *Ptr;
+
+ DEBUG ((EFI_D_ERROR, "Unix Stuff PEIM Loaded\n"));
+
+ Status = (**PeiServices).LocatePpi (
+ PeiServices,
+ &gPeiUnixThunkPpiGuid, // GUID
+ 0, // INSTANCE
+ &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
+ (VOID **)&PeiUnixService // PPI
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ Ptr = PeiUnixService->UnixThunk ();
+
+ BuildGuidDataHob (
+ &gEfiUnixThunkProtocolGuid, // Guid
+ &Ptr, // Buffer
+ sizeof (VOID *) // Sizeof Buffer
+ );
+ return Status;
+}
diff --git a/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf b/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf
new file mode 100644
index 0000000000..d19fa2a5a3
--- /dev/null
+++ b/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.inf
@@ -0,0 +1,63 @@
+#/** @file
+# Stuff driver
+#
+# Tiano PEIM to abstract construction of firmware volume in a Unix environment.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixThunkPpiToProtocol
+ FILE_GUID = f4239aa2-8985-11db-af82-0040d02b1835
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = PeimInitializeUnixStuff
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+
+[Sources.common]
+ UnixThunkPpiToProtocol.c
+
+
+[Packages]
+# MdeModulePkg/MdeModulePkg.dec
+ MdePkg/MdePkg.dec
+# IntelFrameworkPkg/IntelFrameworkPkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ PeiServicesTablePointerLib
+ PeiServicesLib
+ HobLib
+ PeimEntryPoint
+ DebugLib
+
+
+[Protocols]
+ gEfiUnixThunkProtocolGuid # PROTOCOL ALWAYS_CONSUMED
+
+
+[Ppis]
+ gPeiUnixThunkPpiGuid # PPI ALWAYS_CONSUMED
+
+
+[Depex]
+ gPeiUnixThunkPpiGuid AND gEfiPeiMemoryDiscoveredPpiGuid
+
diff --git a/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.msa b/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.msa
new file mode 100644
index 0000000000..889d98d8ec
--- /dev/null
+++ b/UnixPkg/UnixThunkPpiToProtocolPei/UnixThunkPpiToProtocol.msa
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>UnixStuff</ModuleName>
+ <ModuleType>PEIM</ModuleType>
+ <GuidValue>f4239aa2-8985-11db-af82-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Stuff driver</Abstract>
+ <Description>
+ Tiano PEIM to abstract construction of firmware volume 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>UnixStuff</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>PeimEntryPoint</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>UnixStuff.c</Filename>
+ <Filename>UnixStuff.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_CONSUMED">
+ <ProtocolCName>gEfiUnixThunkProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <PPIs>
+ <Ppi Usage="ALWAYS_CONSUMED">
+ <PpiCName>gPeiUnixThunkPpiGuid</PpiCName>
+ </Ppi>
+ </PPIs>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <ModuleEntryPoint>PeimInitializeUnixStuff</ModuleEntryPoint>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixUgaDxe/ComponentName.c b/UnixPkg/UnixUgaDxe/ComponentName.c
new file mode 100644
index 0000000000..5c50d5689c
--- /dev/null
+++ b/UnixPkg/UnixUgaDxe/ComponentName.c
@@ -0,0 +1,198 @@
+/*++
+
+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:
+
+ ComponentName.c
+
+Abstract:
+
+--*/
+
+#include "UnixUga.h"
+
+//
+// EFI Component Name Functions
+//
+EFI_STATUS
+EFIAPI
+UnixUgaComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ );
+
+EFI_STATUS
+EFIAPI
+UnixUgaComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ );
+
+//
+// EFI Component Name Protocol
+//
+EFI_COMPONENT_NAME_PROTOCOL gUnixUgaComponentName = {
+ UnixUgaComponentNameGetDriverName,
+ UnixUgaComponentNameGetControllerName,
+ "eng"
+};
+
+static EFI_UNICODE_STRING_TABLE mUnixUgaDriverNameTable[] = {
+ { "eng", L"Unix Universal Graphics Adapter Driver" },
+ { NULL , NULL }
+};
+
+EFI_STATUS
+EFIAPI
+UnixUgaComponentNameGetDriverName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN CHAR8 *Language,
+ OUT CHAR16 **DriverName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ Language - A pointer to a three character ISO 639-2 language identifier.
+ This is the language of the driver name that that the caller
+ is requesting, and it must match one of the languages specified
+ in SupportedLanguages. The number of languages supported by a
+ driver is up to the driver writer.
+ DriverName - A pointer to the Unicode string to return. This Unicode string
+ is the name of the driver specified by This in the language
+ specified by Language.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the Driver specified by This
+ and the language specified by Language was returned
+ in DriverName.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - DriverName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ return LookupUnicodeString (
+ Language,
+ gUnixUgaComponentName.SupportedLanguages,
+ mUnixUgaDriverNameTable,
+ DriverName
+ );
+}
+
+EFI_STATUS
+EFIAPI
+UnixUgaComponentNameGetControllerName (
+ IN EFI_COMPONENT_NAME_PROTOCOL *This,
+ IN EFI_HANDLE ControllerHandle,
+ IN EFI_HANDLE ChildHandle OPTIONAL,
+ IN CHAR8 *Language,
+ OUT CHAR16 **ControllerName
+ )
+/*++
+
+ Routine Description:
+ Retrieves a Unicode string that is the user readable name of the controller
+ that is being managed by an EFI Driver.
+
+ Arguments:
+ This - A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.
+ ControllerHandle - The handle of a controller that the driver specified by
+ This is managing. This handle specifies the controller
+ whose name is to be returned.
+ ChildHandle - The handle of the child controller to retrieve the name
+ of. 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 retrieve the name of the
+ bus controller. It will not be NULL for a bus driver
+ that wishes to retrieve the name of a child controller.
+ Language - A pointer to a three character ISO 639-2 language
+ identifier. This is the language of the controller name
+ that that the caller is requesting, and it must match one
+ of the languages specified in SupportedLanguages. The
+ number of languages supported by a driver is up to the
+ driver writer.
+ ControllerName - A pointer to the Unicode string to return. This Unicode
+ string is the name of the controller specified by
+ ControllerHandle and ChildHandle in the language specified
+ by Language from the point of view of the driver specified
+ by This.
+
+ Returns:
+ EFI_SUCCESS - The Unicode string for the user readable name in the
+ language specified by Language for the driver
+ specified by This was returned in DriverName.
+ EFI_INVALID_PARAMETER - ControllerHandle is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - ChildHandle is not NULL and it is not a valid EFI_HANDLE.
+ EFI_INVALID_PARAMETER - Language is NULL.
+ EFI_INVALID_PARAMETER - ControllerName is NULL.
+ EFI_UNSUPPORTED - The driver specified by This is not currently managing
+ the controller specified by ControllerHandle and
+ ChildHandle.
+ EFI_UNSUPPORTED - The driver specified by This does not support the
+ language specified by Language.
+
+--*/
+{
+ EFI_STATUS Status;
+ EFI_UGA_DRAW_PROTOCOL *UgaDraw;
+ UGA_PRIVATE_DATA *Private;
+
+ //
+ // This is a device driver, so ChildHandle must be NULL.
+ //
+ if (ChildHandle != NULL) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Make sure this driver is currently managing ControllerHandle
+ //
+ Status = EfiTestManagedDevice (
+ ControllerHandle,
+ gUnixUgaDriverBinding.DriverBindingHandle,
+ &gEfiUnixIoProtocolGuid
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+ //
+ // Get our context back
+ //
+ Status = gBS->OpenProtocol (
+ ControllerHandle,
+ &gEfiUgaDrawProtocolGuid,
+ (VOID **)&UgaDraw,
+ gUnixUgaDriverBinding.DriverBindingHandle,
+ ControllerHandle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (UgaDraw);
+
+ return LookupUnicodeString (
+ Language,
+ gUnixUgaComponentName.SupportedLanguages,
+ Private->ControllerNameTable,
+ ControllerName
+ );
+}
diff --git a/UnixPkg/UnixUgaDxe/EntryPoint.c b/UnixPkg/UnixUgaDxe/EntryPoint.c
new file mode 100644
index 0000000000..a2ed2414d6
--- /dev/null
+++ b/UnixPkg/UnixUgaDxe/EntryPoint.c
@@ -0,0 +1,49 @@
+/**@file
+ Entry Point Source file.
+
+ This file contains the user entry point
+
+ 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.
+**/
+
+#include "UnixUga.h"
+
+/**
+ The user Entry Point for module UnixUga. The user code starts with this function.
+
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The entry point is executed successfully.
+ @retval other Some error occurs when executing this entry point.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeUnixUga(
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+
+ Status = EfiLibInstallAllDriverProtocols (
+ ImageHandle,
+ SystemTable,
+ &gUnixUgaDriverBinding,
+ ImageHandle,
+ &gUnixUgaComponentName,
+ NULL,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+
+
+ return Status;
+}
diff --git a/UnixPkg/UnixUgaDxe/UnixUga.h b/UnixPkg/UnixUgaDxe/UnixUga.h
new file mode 100644
index 0000000000..8401029af7
--- /dev/null
+++ b/UnixPkg/UnixUgaDxe/UnixUga.h
@@ -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
index 0000000000..787f193771
--- /dev/null
+++ b/UnixPkg/UnixUgaDxe/UnixUga.inf
@@ -0,0 +1,74 @@
+#/** @file
+# Uga driver
+#
+# UGA is short hand for Universal Graphics Abstraction protocol.
+# This file is a verision of UgaIo the uses UnixThunk system calls as an IO
+# abstraction. For a PCI device UnixIo would be replaced with
+# a PCI IO abstraction that abstracted a specific PCI device.
+# 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.
+#
+#
+#**/
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = UnixUga
+ FILE_GUID = f33cad86-8985-11db-8040-0040d02b1835
+ MODULE_TYPE = UEFI_DRIVER
+ VERSION_STRING = 1.0
+ EDK_RELEASE_VERSION = 0x00020000
+ EFI_SPECIFICATION_VERSION = 0x00020000
+
+ ENTRY_POINT = InitializeUnixUga
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 IPF EBC
+#
+# DRIVER_BINDING = gUnixUgaDriverBinding
+# COMPONENT_NAME = gUnixUgaComponentName
+#
+
+[Sources.common]
+ ComponentName.c
+ UnixUgaScreen.c
+ UnixUgaDriver.c
+ UnixUgaInput.c
+ UnixUga.h
+ EntryPoint.c
+
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnixPkg/UnixPkg.dec
+
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ BaseMemoryLib
+ UefiLib
+ UefiDriverEntryPoint
+ BaseLib
+ DebugLib
+
+
+[Guids]
+ gEfiEventExitBootServicesGuid # SOMETIMES_CONSUMED Create Event: EVENT_GROUP_GUID
+ gEfiUnixUgaGuid # ALWAYS_CONSUMED
+
+
+[Protocols]
+ gEfiSimpleTextInProtocolGuid # PROTOCOL BY_START
+ gEfiUnixUgaIoProtocolGuid # PROTOCOL BY_START
+ gEfiUgaDrawProtocolGuid # PROTOCOL BY_START
+ gEfiUnixIoProtocolGuid # PROTOCOL TO_START
+
diff --git a/UnixPkg/UnixUgaDxe/UnixUga.msa b/UnixPkg/UnixUgaDxe/UnixUga.msa
new file mode 100644
index 0000000000..864576f6ac
--- /dev/null
+++ b/UnixPkg/UnixUgaDxe/UnixUga.msa
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0">
+ <MsaHeader>
+ <ModuleName>UnixUga</ModuleName>
+ <ModuleType>UEFI_DRIVER</ModuleType>
+ <GuidValue>f33cad86-8985-11db-8040-0040d02b1835</GuidValue>
+ <Version>1.0</Version>
+ <Abstract>Uga driver</Abstract>
+ <Description>
+ UGA is short hand for Universal Graphics Abstraction protocol.
+ This file is a verision of UgaIo the uses UnixThunk system calls as an IO
+ abstraction. For a PCI device UnixIo would be replaced with
+ a PCI IO abstraction that abstracted a specific PCI device.
+ </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>UnixUga</OutputFileBasename>
+ </ModuleDefinitions>
+ <LibraryClassDefinitions>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>DebugLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverModelLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiDriverEntryPoint</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>BaseMemoryLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>MemoryAllocationLib</Keyword>
+ </LibraryClass>
+ <LibraryClass Usage="ALWAYS_CONSUMED">
+ <Keyword>UefiBootServicesTableLib</Keyword>
+ </LibraryClass>
+ </LibraryClassDefinitions>
+ <SourceFiles>
+ <Filename>UnixUga.h</Filename>
+ <Filename>UnixUgaInput.c</Filename>
+ <Filename>UnixUgaDriver.c</Filename>
+ <Filename>UnixUgaScreen.c</Filename>
+ <Filename>ComponentName.c</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="TO_START">
+ <ProtocolCName>gEfiUnixIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="BY_START">
+ <ProtocolCName>gEfiUgaDrawProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="BY_START">
+ <ProtocolCName>gEfiUnixUgaIoProtocolGuid</ProtocolCName>
+ </Protocol>
+ <Protocol Usage="BY_START">
+ <ProtocolCName>gEfiSimpleTextInProtocolGuid</ProtocolCName>
+ </Protocol>
+ </Protocols>
+ <Events>
+ <CreateEvents>
+ <EventTypes EventGuidCName="gEfiEventExitBootServicesGuid" Usage="SOMETIMES_CONSUMED">
+ <EventType>EVENT_GROUP_GUID</EventType>
+ </EventTypes>
+ </CreateEvents>
+ </Events>
+ <Guids>
+ <GuidCNames Usage="ALWAYS_CONSUMED">
+ <GuidCName>gEfiUnixUgaGuid</GuidCName>
+ </GuidCNames>
+ </Guids>
+ <Externs>
+ <Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
+ <Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
+ <Extern>
+ <DriverBinding>gUnixUgaDriverBinding</DriverBinding>
+ <ComponentName>gUnixUgaComponentName</ComponentName>
+ </Extern>
+ </Externs>
+</ModuleSurfaceArea>
diff --git a/UnixPkg/UnixUgaDxe/UnixUgaDriver.c b/UnixPkg/UnixUgaDxe/UnixUgaDriver.c
new file mode 100644
index 0000000000..6073202bd7
--- /dev/null
+++ b/UnixPkg/UnixUgaDxe/UnixUgaDriver.c
@@ -0,0 +1,296 @@
+/*++
+
+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:
+
+ UnixUgaDriver.c
+
+Abstract:
+
+ This file implements the EFI 1.1 Device Driver model requirements for UGA
+
+ UGA is short hand for Universal Graphics Abstraction protocol.
+
+ This file is a verision of UgaIo the uses UnixThunk system calls as an IO
+ abstraction. For a PCI device UnixIo would be replaced with
+ a PCI IO abstraction that abstracted a specific PCI device.
+
+--*/
+
+#include "UnixUga.h"
+
+EFI_DRIVER_BINDING_PROTOCOL gUnixUgaDriverBinding = {
+ UnixUgaDriverBindingSupported,
+ UnixUgaDriverBindingStart,
+ UnixUgaDriverBindingStop,
+ 0xa,
+ NULL,
+ NULL
+};
+
+
+EFI_STATUS
+EFIAPI
+UnixUgaDriverBindingSupported (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: Handle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+{
+ EFI_STATUS Status;
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+
+ //
+ // Open the IO Abstraction(s) needed to perform the supported test
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID **)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = UnixUgaSupported (UnixIo);
+
+ //
+ // Close the I/O Abstraction(s) used to perform the supported test
+ //
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixUgaDriverBindingStart (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: Handle - add argument and description to function comment
+// TODO: RemainingDevicePath - add argument and description to function comment
+// TODO: EFI_UNSUPPORTED - add return value to function comment
+{
+ EFI_UNIX_IO_PROTOCOL *UnixIo;
+ EFI_STATUS Status;
+ UGA_PRIVATE_DATA *Private;
+
+ //
+ // Grab the protocols we need
+ //
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ (VOID **)&UnixIo,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_BY_DRIVER
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_UNSUPPORTED;
+ }
+
+ //
+ // Allocate Private context data for SGO inteface.
+ //
+ Private = NULL;
+ Status = gBS->AllocatePool (
+ EfiBootServicesData,
+ sizeof (UGA_PRIVATE_DATA),
+ (VOID **)&Private
+ );
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+ //
+ // Set up context record
+ //
+ Private->Signature = UGA_PRIVATE_DATA_SIGNATURE;
+ Private->Handle = Handle;
+ Private->UnixThunk = UnixIo->UnixThunk;
+
+ Private->ControllerNameTable = NULL;
+
+ AddUnicodeString (
+ "eng",
+ gUnixUgaComponentName.SupportedLanguages,
+ &Private->ControllerNameTable,
+ UnixIo->EnvString
+ );
+
+ Private->WindowName = UnixIo->EnvString;
+
+ Status = UnixUgaConstructor (Private);
+ if (EFI_ERROR (Status)) {
+ goto Done;
+ }
+ //
+ // Publish the Uga interface to the world
+ //
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &Private->Handle,
+ &gEfiUgaDrawProtocolGuid,
+ &Private->UgaDraw,
+ &gEfiSimpleTextInProtocolGuid,
+ &Private->SimpleTextIn,
+ NULL
+ );
+
+Done:
+ if (EFI_ERROR (Status)) {
+
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+
+ if (Private != NULL) {
+ //
+ // On Error Free back private data
+ //
+ if (Private->ControllerNameTable != NULL) {
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+ }
+
+ gBS->FreePool (Private);
+ }
+ }
+
+ return Status;
+}
+
+EFI_STATUS
+EFIAPI
+UnixUgaDriverBindingStop (
+ IN EFI_DRIVER_BINDING_PROTOCOL *This,
+ IN EFI_HANDLE Handle,
+ IN UINTN NumberOfChildren,
+ IN EFI_HANDLE *ChildHandleBuffer
+ )
+/*++
+
+Routine Description:
+
+Arguments:
+
+Returns:
+
+ None
+
+--*/
+// TODO: This - add argument and description to function comment
+// TODO: Handle - add argument and description to function comment
+// TODO: NumberOfChildren - add argument and description to function comment
+// TODO: ChildHandleBuffer - add argument and description to function comment
+// TODO: EFI_NOT_STARTED - add return value to function comment
+// TODO: EFI_DEVICE_ERROR - add return value to function comment
+{
+ EFI_UGA_DRAW_PROTOCOL *UgaDraw;
+ EFI_STATUS Status;
+ UGA_PRIVATE_DATA *Private;
+
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiUgaDrawProtocolGuid,
+ (VOID **)&UgaDraw,
+ This->DriverBindingHandle,
+ Handle,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ //
+ // If the UGA interface does not exist the driver is not started
+ //
+ return EFI_NOT_STARTED;
+ }
+
+ //
+ // Get our private context information
+ //
+ Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (UgaDraw);
+
+ //
+ // Remove the SGO interface from the system
+ //
+ Status = gBS->UninstallMultipleProtocolInterfaces (
+ Private->Handle,
+ &gEfiUgaDrawProtocolGuid,
+ &Private->UgaDraw,
+ &gEfiSimpleTextInProtocolGuid,
+ &Private->SimpleTextIn,
+ NULL
+ );
+ if (!EFI_ERROR (Status)) {
+ //
+ // Shutdown the hardware
+ //
+ Status = UnixUgaDestructor (Private);
+ if (EFI_ERROR (Status)) {
+ return EFI_DEVICE_ERROR;
+ }
+
+ gBS->CloseProtocol (
+ Handle,
+ &gEfiUnixIoProtocolGuid,
+ This->DriverBindingHandle,
+ Handle
+ );
+
+ //
+ // Free our instance data
+ //
+ FreeUnicodeStringTable (Private->ControllerNameTable);
+
+ gBS->FreePool (Private);
+
+ }
+
+ return Status;
+}
+
diff --git a/UnixPkg/UnixUgaDxe/UnixUgaInput.c b/UnixPkg/UnixUgaDxe/UnixUgaInput.c
new file mode 100644
index 0000000000..29e605c16f
--- /dev/null
+++ b/UnixPkg/UnixUgaDxe/UnixUgaInput.c
@@ -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
index 0000000000..d9118aa00f
--- /dev/null
+++ b/UnixPkg/UnixUgaDxe/UnixUgaScreen.c
@@ -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);
+}